diff --git a/src/interrupts.rs b/src/interrupts.rs new file mode 100644 index 0000000..6cf20cd --- /dev/null +++ b/src/interrupts.rs @@ -0,0 +1,17 @@ +use lazy_static::lazy_static; +use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; + +lazy_static! { + static ref IDT: InterruptDescriptorTable = { + let mut idt = InterruptDescriptorTable::new(); + idt.breakpoint.set_handler_fn(breakpoint_handler); + idt + }; +} +pub fn init_idt() { + IDT.load(); +} + +extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) { + println!("EXCEPTION: Breakpoint\n{:#?}", stack_frame); +} diff --git a/src/main.rs b/src/main.rs index 0b6f0bb..28e0323 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// #![feature(abi_x86_interrupt, asm)] +#![feature(abi_x86_interrupt)] #![no_std] #![no_main] #![feature(custom_test_frameworks)] @@ -9,6 +9,7 @@ mod vga_buffer; #[macro_use] mod serial; +mod interrupts; mod test_utils; #[cfg(not(test))] @@ -24,6 +25,12 @@ pub extern "C" fn _start() -> ! { test_main(); println!("Gamarjoba, munde!"); + init(); + + // Deliberate breakpoint exception + x86_64::instructions::interrupts::int3(); + + println!("We're here now"); loop {} } @@ -36,3 +43,7 @@ fn basic_test() { fn basic_test2() { assert_eq!(4, 4); } + +pub fn init() { + interrupts::init_idt(); +}