From c6bd48e812a81d0501572db54d6b2078a44263d0 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 25 Jan 2019 13:50:33 +0100 Subject: [PATCH] Load and test our new IDT --- src/interrupts.rs | 12 ++++++++++-- src/main.rs | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/interrupts.rs b/src/interrupts.rs index 0be9ec40..1a7de0df 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -1,9 +1,17 @@ use crate::println; +use lazy_static::lazy_static; use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable}; +lazy_static! { + static ref IDT: InterruptDescriptorTable = { + let mut idt = InterruptDescriptorTable::new(); + idt.breakpoint.set_handler_fn(breakpoint_handler); + idt + }; +} + pub fn init_idt() { - let mut idt = InterruptDescriptorTable::new(); - idt.breakpoint.set_handler_fn(breakpoint_handler); + IDT.load(); } extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut ExceptionStackFrame) { diff --git a/src/main.rs b/src/main.rs index 9a14d932..ad1e2f7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,12 @@ use core::panic::PanicInfo; pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); + blog_os::interrupts::init_idt(); + + // invoke a breakpoint exception + x86_64::instructions::int3(); + + println!("It did not crash!"); loop {} }