我正在尝试在简单的操作系统中使用中断。我已经成功设置了IDT,并在汇编中设置了一个C函数来设置一个门(下图),但现在我遇到了一个问题:如何在C中编写一个以iret
结尾的中断处理程序?
这是我的代码:
setGate: ;the first argument is the gate number
;the second the address to the function
push ebp
mov ebp, esp
push eax
push ebx
mov eax, [ebp+12]
mov ebx, idtStart
add ebx, [ebp+8]
mov [ebx*8], ax
mov word [ebx*8+2], 0x8
mov word [ebx*8+4], 0x8E00
shr eax, 16
mov [ebx*8+6], ax
pop ebx
pop eax
pop ebp
ret
我的C代码是:
void handler(void)
{
print("The interrupt has been handled", 15, 0);
}
void main(void)
{
loadIDT();
setGate(32, (unsigned long)&handler);
__asm__("int $32");
}
此代码导致操作系统崩溃,但是当我使用程序集时iret
它没有。
我正在使用GCC和Nasm编译,并在32位保护模式下模拟Qemu。