From 084945688b0bea5d35b6cccb99d14c4f86398847 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 4 Apr 2022 00:24:20 -0700 Subject: [PATCH] Interrupts: Handle double fault --- src/interrupts.rs | 9 +++++++++ src/main.rs | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/interrupts.rs b/src/interrupts.rs index 6cf20cd..d4d0fca 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -5,6 +5,7 @@ lazy_static! { static ref IDT: InterruptDescriptorTable = { let mut idt = InterruptDescriptorTable::new(); idt.breakpoint.set_handler_fn(breakpoint_handler); + idt.double_fault.set_handler_fn(double_fault_handler); idt }; } @@ -15,3 +16,11 @@ pub fn init_idt() { extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { println!("EXCEPTION: Breakpoint\n{:#?}", stack_frame); } + +// The error code of the double-fault handler is always 0 +extern "x86-interrupt" fn double_fault_handler( + stack_frame: InterruptStackFrame, + _error_code: u64, +) -> ! { + panic!("Exception: Double fault\n{:#?}", stack_frame) +} diff --git a/src/main.rs b/src/main.rs index 28e0323..87c4092 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,9 @@ pub extern "C" fn _start() -> ! { x86_64::instructions::interrupts::int3(); println!("We're here now"); + unsafe { + *(0xff00ff00 as *mut u64) = 44; + } loop {} }