From 79efbdc5a0304dc8ba4d76f690ff236c855ba984 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 3 Apr 2022 23:38:56 -0700 Subject: [PATCH] Starting to add interrupt handling --- src/interrupts.rs | 17 +++++++++++++++++ src/main.rs | 13 ++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/interrupts.rs 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(); +}