mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Add and test an invalid opcode handler function
This commit is contained in:
@@ -23,6 +23,7 @@ lazy_static! {
|
||||
let mut idt = idt::Idt::new();
|
||||
|
||||
idt.set_handler(0, handler!(divide_by_zero_handler));
|
||||
idt.set_handler(6, handler!(invalid_opcode_handler));
|
||||
|
||||
idt
|
||||
};
|
||||
@@ -53,3 +54,13 @@ extern "C" fn divide_by_zero_handler(stack_frame: *const ExceptionStackFrame)
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
|
||||
extern "C" fn invalid_opcode_handler(stack_frame: *const ExceptionStackFrame)
|
||||
-> !
|
||||
{
|
||||
unsafe {
|
||||
print_error(format_args!("EXCEPTION: INVALID OPCODE at {:#x}\n{:#?}",
|
||||
(*stack_frame).instruction_pointer, *stack_frame));
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
|
||||
@@ -52,12 +52,8 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
// initialize our IDT
|
||||
interrupts::init();
|
||||
|
||||
fn divide_by_zero() {
|
||||
unsafe { asm!("mov dx, 0; div dx" ::: "ax", "dx" : "volatile", "intel") }
|
||||
}
|
||||
|
||||
// provoke a divide by zero fault inside println
|
||||
println!("{:?}", divide_by_zero());
|
||||
// provoke a invalid opcode exception
|
||||
unsafe { asm!("ud2") };
|
||||
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
|
||||
Reference in New Issue
Block a user