rust-operating-system/src/interrupts.rs

26 lines
732 B
Rust
Raw Normal View History

2019-07-11 02:35:02 -07:00
use lazy_static::lazy_static;
use x86_64::structures::idt::{InterruptStackFrame, InterruptDescriptorTable};
use crate::println;
2019-07-11 02:27:58 -07:00
2019-07-11 02:35:02 -07:00
lazy_static! {
static ref IDT: InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
2019-07-11 02:51:00 -07:00
idt.double_fault.set_handler_fn(double_fault_handler);
2019-07-11 02:35:02 -07:00
idt
};
}
2019-07-11 02:27:58 -07:00
pub fn init_idt() {
2019-07-11 02:35:02 -07:00
IDT.load();
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) {
println!("EXCEPTION - BREAKPOINT\n{:#?}", stack_frame);
2019-07-11 02:27:58 -07:00
}
2019-07-11 02:51:00 -07:00
extern "x86-interrupt" fn double_fault_handler(stack_frame: &mut InterruptStackFrame, code: u64) {
panic!("EXCEPTION - DOUBLE FAULT (code {})\n{:#?}", code, stack_frame);
}