diff --git a/src/interrupts.rs b/src/interrupts.rs new file mode 100644 index 0000000..1e3f168 --- /dev/null +++ b/src/interrupts.rs @@ -0,0 +1,20 @@ +use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; +use crate::println; +use lazy_static::lazy_static; +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); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index c2297b9..a3bea39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,15 @@ #![feature(custom_test_frameworks)] #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"] +#![feature(abi_x86_interrupt)] + +pub fn init() { + interrupts::init_idt(); +} pub mod serial; pub mod vga_buffer; +pub mod interrupts; use core::panic::PanicInfo; diff --git a/src/main.rs b/src/main.rs index 6f32daf..f794e6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,14 @@ use donald::println; pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); + donald::init(); + + x86_64::instructions::interrupts::int3(); + #[cfg(test)] test_main(); + println!("It did not crash!"); loop {} }