我正在研究中断hendling。我的中断描述符表如下:
[EXTERN _isr_handler]
[extern _irq_handler]
%macro ISR_NOERRCODE 1
_isr%1:
cli
push byte 0
push byte %1
jmp isr_common_stub
%endmacro
%macro ISR_ERRCODE 1
_isr%1:
cli
push byte %1
jmp isr_common_stub
%endmacro
%macro IRQ 2
irq%1:
cli
push byte 0
push byte %2
jmp irq_common_stub
%endmacro
%macro IDT_ENTRY 1
dw _isr%1
dw 0x08
db 0x0
db 0x8E
dw 0x0000;
%endmacro
%macro IDT_IRQ_ENTRY 1
dw irq%1
dw 0x08
db 0x0
db 0x8E
dw 0x0000
%endmacro
ISR_NOERRCODE 0
ISR_NOERRCODE 1
...
ISR_NOERRCODE 31
IRQ 0, 32
IRQ 1, 33
...
IRQ 15, 47
idt_start:
IDT_ENTRY 0
IDT_ENTRY 1
...
IDT_ENTRY 31
IDT_IRQ_ENTRY 0
IDT_IRQ_ENTRY 1
...
IDT_IRQ_ENTRY 15
idt_end:
idt_descriptor:
dw idt_end - idt_start - 1
dd idt_start
isr_common_stub:
pusha
mov ax, ds
push eax
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call _isr_handler
pop eax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa
add esp, 8
sti
iret
irq_common_stub:
pusha
mov ax, ds
push eax
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call _irq_handler
pop ebx
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
popa
add esp, 8
sti
iret
idt加载程序如下:
mov al, 0x11
out 0x20, al
out 0xA0, al
mov al, 0x20
out 0x21, al
mov al, 0x28
out 0xA1, al
mov al, 0x04
out 0x21, al
mov al, 0x02
out 0xA1, al
mov al, 0x01
out 0x21, al
out 0xA1, al
mov al, 0x00
out 0x21, al
out 0xA1, al
lidt [idt_descriptor]
我的isr_handler C函数被调用。但是,irq_handler C函数永远不会被调用。我不明白为什么只有irq处理部分不起作用。请帮忙。
答案 0 :(得分:1)
我发现了问题:在lidt命令之前的idt加载部分,我忘记了sti命令。