From 7dd4d2052711d757a5421eea7f84849d56950647 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Wed, 22 Nov 2023 01:26:50 +0500 Subject: [PATCH] entry: use IMR to try detect GPF [fixes #237] Using ISR is unsafe because programs can legally chain to the prev inthandler after EOI. We can rely on the fact that IRQ5 is masked in IMR by default. If this is the case, then its most certainly a GPF, so we can terminate the process. But if its not masked, always pass to prev inthandler. --- kernel/entry.asm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/entry.asm b/kernel/entry.asm index df624359..8d330aa6 100644 --- a/kernel/entry.asm +++ b/kernel/entry.asm @@ -221,12 +221,10 @@ rst0d: retf hdlr0d: push ax - mov al, 0Bh ; request In-Service Register (ISR) - out 20h, al ; from primary PIC - in al, 20h ; read the ISR - test al, 10_0000b ; IRQ #5 occurred ? + in al, 21h ; read the IMR + test al, 10_0000b ; IRQ #5 masked ? pop ax - jnz @2 ; yes, (likely) not a GPF + jz @2 ; no, (likely) not a GPF mov si,gpf_message jmp zero_message_loop @2: