Skip to content

Commit

Permalink
Interrupt handler for INT3
Browse files Browse the repository at this point in the history
  • Loading branch information
Blindspot22 committed May 18, 2024
1 parent 38d131c commit 1ac470f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/interrupts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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:#?}");
}
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![feature(abi_x86_interrupt)]

pub mod serial;
pub mod vga_buffer;
pub mod interrupts;

use core::panic::PanicInfo;

Expand Down Expand Up @@ -39,14 +41,17 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
loop {}
}

/// Entry point for `cargo test`
#[cfg(test)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
test_main();
loop {}
}

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

#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ pub trait Testable {
#[no_mangle]
pub extern "C" fn _start() -> ! {
println!("Hello, Welcome to the ORUST Operating System{}", "!");

orust_os::init();

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

#[cfg(test)]
test_main();

println!("It did not crash!");

#[allow(clippy::empty_loop)]
loop {}
}
Expand Down

0 comments on commit 1ac470f

Please sign in to comment.