refactor exception code into interrupts.rs

This commit is contained in:
acheronfail
2018-10-18 08:21:58 +11:00
parent a198de6d1f
commit 206fb7cc8a
5 changed files with 84 additions and 53 deletions

View File

@@ -1,4 +1,3 @@
#![feature(abi_x86_interrupt)]
#![no_std] // don't link the Rust standard library
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
@@ -19,7 +18,7 @@ pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
blog_os::gdt::init();
init_idt();
blog_os::interrupts::init_idt();
fn stack_overflow() {
stack_overflow(); // for each recursion, the return address is pushed
@@ -39,35 +38,3 @@ fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
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);
unsafe {
idt.double_fault
.set_handler_fn(double_fault_handler)
.set_stack_index(blog_os::gdt::DOUBLE_FAULT_IST_INDEX);
}
idt
};
}
pub fn init_idt() {
IDT.load();
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut ExceptionStackFrame) {
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn double_fault_handler(
stack_frame: &mut ExceptionStackFrame,
_error_code: u64,
) {
println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
loop {}
}