diff options
Diffstat (limited to 'kernel/src/interrupts/exceptions.rs')
-rw-r--r-- | kernel/src/interrupts/exceptions.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/kernel/src/interrupts/exceptions.rs b/kernel/src/interrupts/exceptions.rs index f6d5176..a3ecf9d 100644 --- a/kernel/src/interrupts/exceptions.rs +++ b/kernel/src/interrupts/exceptions.rs @@ -13,10 +13,10 @@ macro_rules! exception_default { }; } -static mut expected_fault: Interrupts = Interrupts::NONE; +static mut expected_fault: Interrupts = Interrupts::None; pub unsafe fn expect_fault(int: Interrupts) { - if expected_fault == Interrupts::NONE { + if expected_fault == Interrupts::None { expected_fault = int; } } @@ -27,7 +27,7 @@ fn get_expected_fault() -> Interrupts { pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) { match get_expected_fault() { - Interrupts::BREAKPOINT => qemu::exit_qemu(qemu::QemuExitCode::Success), + Interrupts::Breakpoint => qemu::exit_qemu(qemu::QemuExitCode::Success), _ => panic!( "BREAKPOINT exception thrown\n\n{}", exception_default!(stack_frame) @@ -35,6 +35,20 @@ pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStac } } +pub extern "x86-interrupt" fn general_protection_fault_handler( + stack_frame: &mut InterruptStackFrame, + error_code: u64, +) { + match get_expected_fault() { + Interrupts::GeneralProtectionFault => qemu::exit_qemu(qemu::QemuExitCode::Success), + _ => panic!( + "GENERAL PROTECTION exception thrown\nerror code: {:x}\n{}", + error_code, + exception_default!(stack_frame) + ), + } +} + pub extern "x86-interrupt" fn page_fault_handler( stack_frame: &mut InterruptStackFrame, error_code: PageFaultErrorCode, @@ -42,7 +56,7 @@ pub extern "x86-interrupt" fn page_fault_handler( use x86_64::registers::control::Cr2; match get_expected_fault() { - Interrupts::PAGE_FAULT => qemu::exit_qemu(qemu::QemuExitCode::Success), + Interrupts::PageFault => qemu::exit_qemu(qemu::QemuExitCode::Success), _ => panic!( "PAGE FAULT while accessing address: 0x{:08x}\nerror code: {:?}(0x{:x})\n{}", Cr2::read().as_u64(), @@ -58,7 +72,7 @@ pub extern "x86-interrupt" fn segment_not_present_handler( error_code: u64, ) { match get_expected_fault() { - Interrupts::NOT_PRESENT => qemu::exit_qemu(qemu::QemuExitCode::Success), + Interrupts::NotPresent => qemu::exit_qemu(qemu::QemuExitCode::Success), _ => panic!( "SEGMENT NOT PRESENT exception\nerror code: 0x{:x}\n{}", error_code, @@ -72,7 +86,7 @@ pub extern "x86-interrupt" fn double_fault_handler( _error_code: u64, // code is always zero ) { match get_expected_fault() { - Interrupts::NOT_PRESENT => qemu::exit_qemu(qemu::QemuExitCode::Success), + Interrupts::DoubleFault => qemu::exit_qemu(qemu::QemuExitCode::Success), _ => panic!( "DOUBLE FAULT\nthis is a fatal exception\n{}", exception_default!(stack_frame) |