post-05
This commit is contained in:
parent
76b022be69
commit
d061368f18
33
src/interrupts.rs
Normal file
33
src/interrupts.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
use lazy_static::lazy_static;
|
||||||
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
|
|
||||||
|
use crate::println;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use crate::{serial_print, serial_println};
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_breakpoint_exception() {
|
||||||
|
serial_print!("test_breakpoint_exception...");
|
||||||
|
// invoke a breakpoint exception
|
||||||
|
x86_64::instructions::interrupts::int3();
|
||||||
|
serial_println!("[ok]");
|
||||||
|
}
|
@ -1,11 +1,13 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(test, no_main)]
|
#![cfg_attr(test, no_main)]
|
||||||
#![feature(custom_test_frameworks)]
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![feature(abi_x86_interrupt)]
|
||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
pub mod interrupts;
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
pub mod macros;
|
pub mod macros;
|
||||||
pub mod vga_buffer;
|
pub mod vga_buffer;
|
||||||
@ -29,6 +31,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
|
init();
|
||||||
test_main();
|
test_main();
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
@ -53,4 +56,8 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
|
|||||||
let mut port = Port::new(0xf4);
|
let mut port = Port::new(0xf4);
|
||||||
port.write(exit_code as u32);
|
port.write(exit_code as u32);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
interrupts::init_idt();
|
||||||
}
|
}
|
@ -26,6 +26,10 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
println!("Hello World{}", "!");
|
println!("Hello World{}", "!");
|
||||||
|
|
||||||
|
blog_os::init();
|
||||||
|
|
||||||
|
x86_64::instructions::interrupts::int3();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user