Added CPU exceptions
This commit is contained in:
25
src/interrupts.rs
Normal file
25
src/interrupts.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use crate::println;
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
|
||||
lazy_static! {
|
||||
static ref IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_idt() {
|
||||
IDT.load();
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
|
||||
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_breakpoint_exception() {
|
||||
// invoke a breakpoint exception
|
||||
x86_64::instructions::interrupts::int3();
|
||||
}
|
||||
@@ -3,9 +3,11 @@
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![test_runner(crate::test_runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
pub mod interrupts;
|
||||
pub mod serial;
|
||||
pub mod vga_buffer;
|
||||
|
||||
@@ -43,6 +45,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
||||
#[cfg(test)]
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
init();
|
||||
test_main();
|
||||
loop {}
|
||||
}
|
||||
@@ -68,3 +71,7 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
|
||||
port.write(exit_code as u32);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
interrupts::init_idt();
|
||||
}
|
||||
|
||||
@@ -11,9 +11,14 @@ use core::panic::PanicInfo;
|
||||
pub extern "C" fn _start() -> ! {
|
||||
println!("Welcome to Amix{}", "!");
|
||||
|
||||
amix::init();
|
||||
|
||||
x86_64::instructions::interrupts::int3();
|
||||
|
||||
#[cfg(test)]
|
||||
test_main();
|
||||
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user