mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Test the two-stage exception handler in code
This commit is contained in:
@@ -22,19 +22,20 @@ use vga_buffer::print_error;
|
||||
#[naked]
|
||||
extern "C" fn divide_by_zero_handler() -> ! {
|
||||
unsafe {
|
||||
asm!(/* load excepiton fram pointer and call main_handler*/);
|
||||
}
|
||||
asm!("mov rdi, rsp; call $0" ::
|
||||
"i"(main_handler as extern "C" fn(_) -> !) : "rdi" : "intel");
|
||||
::core::intrinsics::unreachable();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn main_handler(stack_frame: *const ExceptionStackFrameErrorCode) -> ! {
|
||||
extern "C" fn main_handler(stack_frame: *const ExceptionStackFrame) -> ! {
|
||||
unsafe {
|
||||
print_error(format_args!("EXCEPTION: DIVIDE BY ZERO\n{:#?}", *stack_frame));
|
||||
}
|
||||
loop {}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn divide_by_zero_handler() -> ! {
|
||||
extern "C" fn divide_by_zero_handler_() -> ! {
|
||||
let stack_frame: *const ExceptionStackFrame;
|
||||
unsafe {
|
||||
asm!("mov $0, rsp" : "=r"(stack_frame) ::: "intel");
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#![feature(alloc, collections)]
|
||||
#![feature(asm)]
|
||||
#![feature(naked_functions)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![no_std]
|
||||
|
||||
extern crate rlibc;
|
||||
@@ -56,7 +57,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
unsafe { asm!("mov dx, 0; div dx" ::: "ax", "dx" : "volatile", "intel") }
|
||||
}
|
||||
|
||||
//println!("{:?}", divide_by_zero());
|
||||
println!("{:?}", divide_by_zero());
|
||||
|
||||
// provoke a page fault inside println
|
||||
println!("{:?}", unsafe { *(0xdeadbeaf as *mut u64) = 42 });
|
||||
|
||||
Reference in New Issue
Block a user