为什么 BIOS 中断 8(计时器)在 qemu-system-x86_64 上不起作用
Why BIOS interrupt 8 (timer) not working on qemu-system-x86_64
我想 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
Qemu window出现,只显示一个'A',不连续
我的代码有什么问题,如果我希望中断 8 一次又一次。
我使用 nasm 1.14.02,qemu 4.2.1 和 ubuntu 20.04.
使其重复显示 'A' 的关键变化是向端口 20h 上的 PIC 发送中断结束信号。如果您使用中断 1Ch 或链接到另一个中断 08h 处理程序,则您的代码中不需要这样做。如果你完全替换中断 08h 处理程序,它是。在前一个获得 EOI 之前,PIC 不会发送另一个 IRQ #0。因此,我能够重现您的问题。
我所做的其他更改是确保在进入 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
我想 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
Qemu window出现,只显示一个'A',不连续
我的代码有什么问题,如果我希望中断 8 一次又一次。
我使用 nasm 1.14.02,qemu 4.2.1 和 ubuntu 20.04.
使其重复显示 'A' 的关键变化是向端口 20h 上的 PIC 发送中断结束信号。如果您使用中断 1Ch 或链接到另一个中断 08h 处理程序,则您的代码中不需要这样做。如果你完全替换中断 08h 处理程序,它是。在前一个获得 EOI 之前,PIC 不会发送另一个 IRQ #0。因此,我能够重现您的问题。
我所做的其他更改是确保在进入 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