IDT を介してカーネル割り込みを処理しようとしています。Linux で Intel x86 を使用しています。
IDT と割り込みエントリを設定し、いくつかのテストを開始して割り込みハンドラを表示しました。
試してみるとint $0x0
、完全に機能します。ハンドラーが呼び出されますが、エラーコードがプッシュされた状態で例外を試すと、無限ループに入ります。
スキーマは次のとおりです。
例外が到着すると、ハンドラーの最初の部分は ASM にあり、共通の C 部分を呼び出します。
my_handler.c
void handler(int i)
{
printf("Exception %d caught\n", i);
}
my_handlers.S
common:
pushal
pushl %ds
pushl %es
pushl %fs
pushl %gs
addl $48, %esp // 4 4-bytes segments pushed
// + 8 4-bytes registers (pushal)
` // esp points on exception code
call handler // call the C handler with exception code
subl $48, %esp
popl %gs
popl %fs
popl %es
popl %ds
popal
addl $8, %esp // 4-byte error code + 4-byte exception number
iret
exception_de_handler:
pushl $0 // Fake error code
pushl $0 // interrupt number
jmp common
exception_gp_handler:
// error code is pushed by µproc.
pushl $13 // interrupt number
jmp common
exception_pf_handler:
// error code is pushed by µproc.
pushl $14 // interrupt number
jmp common
次のコードを実行しようとすると:
int* a = 0x0;
*a = 42;
動作し、実行が再開されます*a = 42;
しかし、私が試してみると:
int* a = 0x0;
*a = 42;
*a = 1337;
それは無限ループに入ります:
Exception 14 caught
Exception 13 caught
Exception 13 caught
Exception 13 caught
Exception 13 caught
.....
Exception 13 caught
Exception 13 caught
Exception 13 caught
.....
最初の例外 Page Fault(14) が処理され、次に General Protection(13) でループされるのはなぜですか?
回答ありがとうございます。