Skip to content

Commit

Permalink
Start handling interrupts, handle breakpoint exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
keawade committed Oct 18, 2020
1 parent a0ff7c5 commit 94e5979
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/interrupts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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: &mut InterruptStackFrame) {
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
}
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
#![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;

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

pub trait Testable {
fn run(&self) -> ();
}
Expand Down Expand Up @@ -41,10 +47,12 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
exit_qemu(QemuExitCode::Failed);
loop {}
}

/// Entry point for `cargo test`
#[cfg(test)]
#[no_mangle]
pub extern "C" fn _start() -> ! {
init();
test_main();
loop {}
}
Expand All @@ -70,3 +78,9 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
port.write(exit_code as u32);
}
}

#[test_case]
fn test_breakpoint_exception() {
// invoke a breakpoint exception
x86_64::instructions::interrupts::int3();
}
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ pub extern "C" fn _start() -> ! {

println!("k_os minimal kernel successfully boot loaded!");

k_os::init();

// invoke a breakpoint exception
x86_64::instructions::interrupts::int3(); // new

#[cfg(test)]
test_main();

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

loop {}
}

Expand Down

0 comments on commit 94e5979

Please sign in to comment.