Added CPU exceptions

This commit is contained in:
2026-03-30 14:28:26 +03:00
parent 96078a5523
commit 6e3528f5f5
3 changed files with 37 additions and 0 deletions

25
src/interrupts.rs Normal file
View 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();
}

View File

@@ -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();
}

View File

@@ -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 {}
}