Starting to add interrupt handling

This commit is contained in:
Greg Shuflin 2022-04-03 23:38:56 -07:00
parent 7cac67b0fc
commit 79efbdc5a0
2 changed files with 29 additions and 1 deletions

17
src/interrupts.rs Normal file
View File

@ -0,0 +1,17 @@
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);
}

View File

@ -1,4 +1,4 @@
// #![feature(abi_x86_interrupt, asm)]
#![feature(abi_x86_interrupt)]
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
@ -9,6 +9,7 @@
mod vga_buffer;
#[macro_use]
mod serial;
mod interrupts;
mod test_utils;
#[cfg(not(test))]
@ -24,6 +25,12 @@ pub extern "C" fn _start() -> ! {
test_main();
println!("Gamarjoba, munde!");
init();
// Deliberate breakpoint exception
x86_64::instructions::interrupts::int3();
println!("We're here now");
loop {}
}
@ -36,3 +43,7 @@ fn basic_test() {
fn basic_test2() {
assert_eq!(4, 4);
}
pub fn init() {
interrupts::init_idt();
}