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-18 03:28:55 -07:00
|
|
|
use pic8259_simple::ChainedPics;
|
|
|
|
use spin;
|
2019-07-18 03:01:57 -07:00
|
|
|
use crate::gdt;
|
|
|
|
|
2019-07-18 03:28:55 -07:00
|
|
|
const PIC_1_OFFSET: u8 = 32;
|
|
|
|
const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
|
|
|
static PICS: spin::Mutex<ChainedPics> =
|
|
|
|
spin::Mutex::new(unsafe { ChainedPics::new(PIC_1_OFFSET, PIC_2_OFFSET) });
|
|
|
|
|
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-18 03:01:57 -07:00
|
|
|
unsafe {
|
|
|
|
idt.double_fault.set_handler_fn(double_fault_handler)
|
|
|
|
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2019-07-18 03:28:55 -07:00
|
|
|
pub fn initalize_pics() {
|
|
|
|
unsafe {
|
|
|
|
PICS.lock().initialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 02:35:02 -07:00
|
|
|
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);
|
|
|
|
}
|