问题描述
我认为 BIOS 中断 8(计时器)应该每秒出现 18.2 次,但在 qemu 上没有。请参见以下示例:
$ cat c.asm
init:
.segments:
mov ax,0x07C0
mov ds,ax
mov ax,0
mov fs,ax
.interrupt:
mov [fs:0x08*4],word timer
mov [fs:0x08*4+2],ds
main:
hlt
jmp main
timer:
mov ah,0x0e
mov al,0x41
int 0x10
iret
times 510-($-$$) db 0
dw 0xaa55
$ nasm -f bin c.asm -o c.bin && qemu-system-x86_64 c.bin
我的代码有什么问题,如果我希望中断8一次又一次的到来。
我使用 nasm 1.14.02、qemu 4.2.1 和 ubuntu 20.04。
解决方法
使其重复显示“A”的关键更改是在端口 20h 上向 PIC 发送中断结束信号。如果您使用中断 1Ch 或链接到另一个中断 08h 处理程序,则您的代码中不需要它。如果你完全替换中断 08h 处理程序,它是。 PIC 不会发送另一个 IRQ #0,直到前一个收到 EOI。因此,我能够重现您的问题。
我所做的其他更改是确保在进入 main
循环之前设置中断标志(使用 sti
指令),并保留中断 08h 处理程序中的所有寄存器(这是可选的)如果您的代码是机器上唯一运行的东西)。
init:
.segments:
mov ax,0x07C0
mov ds,ax
mov ax,0
mov fs,ax
.interrupt:
mov [fs:0x08*4],word timer
mov [fs:0x08*4+2],ds
sti
main:
hlt
jmp main
timer:
push ax
push bx
push bp
mov ah,0x0e
mov al,0x41
int 0x10
mov al,20h
out 20h,al
pop bp
pop bx
pop ax
iret
times 510-($-$$) db 0
dw 0xaa55
像这样运行:
$ nasm test.asm
$ timeout 10 qemu-system-x86_64 test -curses