我正在开发一个操作系统。我的 GDT 有三个条目。我创建了 IDT 并实现了 ISR 和 IQR。我还重新映射了图片。问题是在每个中断处理程序都遵循一般保护错误之后。这是调用中断的汇编代码:
.extern fault_handler
isr_common_stub:
pusha
push %ds
push %es
push %fs
push %gs
movw $0x10,%ax # Load the Kernel Data Segment descriptor!
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
movl %esp,%eax # Push us the stack
pushl %eax
movl $fault_handler, %eax
call *%eax # A special call, preserves the 'eip' register
popl %eax
popl %gs # I discovered that the error occures on this line
popl %fs
popl %es
popl %ds
popa
addl $8,%esp # Cleans up the pushed error code and pushed ISR number
iret # pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
.extern irq_handler
irq_common_stub:
pusha
push %ds
push %es
push %fs
push %gs
movw $0x10,%ax
movw %ax,%ds
movw %ax,%es
movw %ax,%fs
movw %ax,%gs
movl %esp,%eax
pushl %eax
movl $irq_handler, %eax
call *%eax
popl %eax
popl %gs # I discovered that the error occures on this line
popl %fs
popl %es
popl %ds
popa
addl $8,%esp
iret
我发现了一些奇怪的东西。当我使用 QEMU 作为磁盘映像运行操作系统时.iso
,它不起作用。但是当我通过指定选项将其称为内核时-kernel
,它按预期工作。我决定更改以下代码:
popl %gs # I discovered that the error occures on this line
popl %fs
popl %es
popl %ds
我将上面的代码更改为:
pop %gs
pop %fs
pop %es
pop %ds
我仍然得到GPF。难道我做错了什么?有什么建议么?