Skip to content

Commit

Permalink
Handle CPU exceptions (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuozasVainauskas authored Dec 3, 2023
1 parent c70798d commit dc4e6ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/interrupts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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);
}

#[test_case]
fn test_breakpoint_exceptions() {
x86_64::instructions::interrupts::int3();
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
#![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 serial;
pub mod vga_buffer;
pub mod interrupts;

pub fn init() {
interrupts::init_idt();
}

pub trait Testable {
fn run(&self) -> ();
Expand Down Expand Up @@ -59,6 +65,7 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
#[cfg(test)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
init();
test_main();
loop {}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub extern "C" fn _start() -> ! {

println!("System booted successfully");

os::init();

x86_64::instructions::interrupts::int3();

#[cfg(test)]
test_main();
Expand Down

0 comments on commit dc4e6ff

Please sign in to comment.