mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-17 06:47:49 +00:00
Port cpu exceptions post to second edition
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user