Test the two-stage exception handler in code

This commit is contained in:
Philipp Oppermann
2016-07-17 17:06:22 +02:00
parent 9e45cf65bc
commit 9113a63f5e
2 changed files with 13 additions and 11 deletions

View File

@@ -22,19 +22,20 @@ use vga_buffer::print_error;
#[naked] #[naked]
extern "C" fn divide_by_zero_handler() -> ! { extern "C" fn divide_by_zero_handler() -> ! {
unsafe { 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(); ::core::intrinsics::unreachable();
extern "C" fn main_handler(stack_frame: *const ExceptionStackFrameErrorCode) -> ! {
unsafe {
print_error(format_args!("EXCEPTION: DIVIDE BY ZERO\n{:#?}", *stack_frame));
}
loop {}
} }
} }
extern "C" fn divide_by_zero_handler() -> ! { 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_() -> ! {
let stack_frame: *const ExceptionStackFrame; let stack_frame: *const ExceptionStackFrame;
unsafe { unsafe {
asm!("mov $0, rsp" : "=r"(stack_frame) ::: "intel"); asm!("mov $0, rsp" : "=r"(stack_frame) ::: "intel");

View File

@@ -12,6 +12,7 @@
#![feature(alloc, collections)] #![feature(alloc, collections)]
#![feature(asm)] #![feature(asm)]
#![feature(naked_functions)] #![feature(naked_functions)]
#![feature(core_intrinsics)]
#![no_std] #![no_std]
extern crate rlibc; 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") } 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 // provoke a page fault inside println
println!("{:?}", unsafe { *(0xdeadbeaf as *mut u64) = 42 }); println!("{:?}", unsafe { *(0xdeadbeaf as *mut u64) = 42 });