diff options
| author | Natasha Moongrave <natasha@256phi.eu> | 2026-02-18 19:55:52 +0100 |
|---|---|---|
| committer | Natasha Moongrave <natasha@256phi.eu> | 2026-02-18 19:55:52 +0100 |
| commit | 8b5879660db9f5897800b46d8bc30444c0b17f16 (patch) | |
| tree | 5b62d5811bda6797f199e741aa31fa236553a77d | |
| parent | cc3f06848d521f1602dfb7603ee205b8e549016b (diff) | |
added handling for breakpoint exception + incorporated it into the test infrastructure
| -rw-r--r-- | StrixKernel/src/interrupts.rs | 31 | ||||
| -rw-r--r-- | StrixKernel/src/lib.rs | 7 | ||||
| -rw-r--r-- | StrixKernel/src/main.rs | 5 |
3 files changed, 42 insertions, 1 deletions
diff --git a/StrixKernel/src/interrupts.rs b/StrixKernel/src/interrupts.rs new file mode 100644 index 0000000..6c44f59 --- /dev/null +++ b/StrixKernel/src/interrupts.rs @@ -0,0 +1,31 @@ +// interrupts.rs + +use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; +use crate::println; +use lazy_static::lazy_static; + +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); +} + + +// TESTS // +#[test_case] +fn test_breakpoint_exception() { + // invoke a breakpoint exception + x86_64::instructions::interrupts::int3(); +}
\ No newline at end of file diff --git a/StrixKernel/src/lib.rs b/StrixKernel/src/lib.rs index fd3630d..a1c4553 100644 --- a/StrixKernel/src/lib.rs +++ b/StrixKernel/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #![cfg_attr(test, no_main)] #![feature(custom_test_frameworks)] +#![feature(abi_x86_interrupt)] #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"] @@ -8,11 +9,16 @@ use core::panic::PanicInfo; pub mod serial; pub mod vga_buffer; +pub mod interrupts; pub trait Testable { fn run(&self) -> (); } +pub fn init() { + interrupts::init_idt(); +} + impl<T> Testable for T where T: Fn(), @@ -59,6 +65,7 @@ pub fn exit_qemu(exit_code: QemuExitCode) { #[cfg(test)] #[unsafe(no_mangle)] pub extern "C" fn _start() -> ! { + init(); test_main(); loop {} } diff --git a/StrixKernel/src/main.rs b/StrixKernel/src/main.rs index ce5f1a8..3fa7149 100644 --- a/StrixKernel/src/main.rs +++ b/StrixKernel/src/main.rs @@ -12,9 +12,12 @@ pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); println!("The Strix OS kernel is now online"); + strix_os::init(); // Call the init function as declared in ./lib.rs + + // Continue as normal #[cfg(test)] test_main(); - + loop {} } |
