From fe69e31b91a31d2befff7b7200fe40799b5eda0b Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Sat, 20 Aug 2022 09:26:59 +0300 Subject: [PATCH] interrupts: page fault handler --- ableos/src/arch/x86_64/interrupts.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ableos/src/arch/x86_64/interrupts.rs b/ableos/src/arch/x86_64/interrupts.rs index 803af1a3..12f35e97 100644 --- a/ableos/src/arch/x86_64/interrupts.rs +++ b/ableos/src/arch/x86_64/interrupts.rs @@ -12,7 +12,7 @@ use pic8259::ChainedPics; use qrcode::QrCode; use seq_macro::seq; use spin::Lazy; -use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; +use x86_64::{structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode}, registers::control::Cr2}; use super::sloop; @@ -56,6 +56,7 @@ static IDT: Lazy = Lazy::new(|| { }); idt.breakpoint.set_handler_fn(breakpoint_handler); + idt.page_fault.set_handler_fn(page_fault_handler); unsafe { idt.double_fault .set_handler_fn(double_fault_handler) @@ -93,13 +94,22 @@ extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { trace!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame); } +extern "x86-interrupt" fn page_fault_handler( + stack_frame: InterruptStackFrame, + error_code: PageFaultErrorCode +) { + error!("EXCEPTION: PAGE FAULT {error_code:?}\n{:#?}", stack_frame); + trace!("CR2: {:x}", Cr2::read_raw()); + loop {} +} + extern "x86-interrupt" fn double_fault_handler( stack_frame: InterruptStackFrame, // NOTE(able): ignore this always is 0 _error_code: u64, ) -> ! { - bsod(BSODSource::DoubleFault(&stack_frame)); - // panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); + // bsod(BSODSource::DoubleFault(&stack_frame)); + panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); } /* SAFETY