Port cpu exceptions post to second edition

This commit is contained in:
Philipp Oppermann
2018-06-17 20:08:51 +02:00
parent c39835e61e
commit 97a87728f7
9 changed files with 576 additions and 2 deletions

View File

@@ -1,10 +1,14 @@
#![feature(panic_implementation)] // required for defining the panic handler
#![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))]
#[macro_use]
extern crate blog_os;
extern crate x86_64;
#[macro_use]
extern crate lazy_static;
use core::panic::PanicInfo;
@@ -15,6 +19,12 @@ use core::panic::PanicInfo;
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
init_idt();
// invoke a breakpoint exception
x86_64::instructions::int3();
println!("It did not crash!");
loop {}
}
@@ -26,3 +36,21 @@ pub fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
use x86_64::structures::idt::{ExceptionStackFrame, Idt};
lazy_static! {
static ref IDT: Idt = {
let mut idt = Idt::new();
idt.breakpoint.set_handler_fn(breakpoint_handler);
idt
};
}
pub fn init_idt() {
IDT.load();
}
extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut ExceptionStackFrame) {
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
}