use x86_64::structures::idt::{InterruptStackFrame, PageFaultErrorCode}; macro_rules! exception_default { ($stack_frame: expr) => { format_args!("instruction addr: 0x{:08x}\nstack addr: 0x{:08x}\nflags: 0x{:x}", $stack_frame.instruction_pointer.as_u64(), $stack_frame.cpu_flags, $stack_frame.stack_pointer.as_u64() ) } } pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) { panic!( "BREAKPOINT exception thrown\n\n{}", exception_default!(stack_frame) ); } pub extern "x86-interrupt" fn page_fault_handler( stack_frame: &mut InterruptStackFrame, error_code: PageFaultErrorCode, ) { use x86_64::registers::control::Cr2; panic!( "PAGE FAULT while accessing address: 0x{:08x}\nerror code: {:?}(0x{:x})\n{}", Cr2::read().as_u64(), error_code, error_code.bits(), exception_default!(stack_frame) ); } pub extern "x86-interrupt" fn segment_not_present_handler( stack_frame: &mut InterruptStackFrame, error_code: u64, ) { panic!( "SEGMENT NOT PRESENT exception\nerror code: 0x{:x}\n{}", error_code, exception_default!(stack_frame) ); } pub extern "x86-interrupt" fn double_fault_handler( stack_frame: &mut InterruptStackFrame, _error_code: u64, // code is always zero ) { panic!( "DOUBLE FAULT\nthis is a fatal exception\n{}", exception_default!(stack_frame) ); }