CPU Exception
This commit is contained in:
14
src/lib.rs
14
src/lib.rs
@@ -3,10 +3,12 @@
|
||||
#![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 trait Testable {
|
||||
fn run(&self) -> ();
|
||||
@@ -41,6 +43,7 @@ pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
||||
#[cfg(test)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
init();
|
||||
test_main();
|
||||
loop {}
|
||||
}
|
||||
@@ -51,6 +54,14 @@ fn panic(info: &PanicInfo) -> ! {
|
||||
test_panic_handler(info)
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_breakpoint_exception() {
|
||||
x86_64::instructions::interrupts::int3();
|
||||
// 如果程序继续运行则说明测试成功
|
||||
// 用 cargo test 运行全部测试
|
||||
// 或 cargo test --lib 仅运行库测试
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum QemuExitCode {
|
||||
@@ -67,3 +78,6 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
interrupts::init_idt();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user