mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Catch divide error instead of page fault
The divide error pushes no error code. Thus we avoid stack misalignment (see #184).
This commit is contained in:
@@ -4,7 +4,7 @@ lazy_static! {
|
|||||||
static ref IDT: idt::Idt = {
|
static ref IDT: idt::Idt = {
|
||||||
let mut idt = idt::Idt::new();
|
let mut idt = idt::Idt::new();
|
||||||
|
|
||||||
idt.set_handler(14, page_fault_handler);
|
idt.set_handler(0, divide_by_zero_handler);
|
||||||
|
|
||||||
idt
|
idt
|
||||||
};
|
};
|
||||||
@@ -16,7 +16,7 @@ pub fn init() {
|
|||||||
|
|
||||||
use vga_buffer::print_error;
|
use vga_buffer::print_error;
|
||||||
|
|
||||||
extern "C" fn page_fault_handler() -> ! {
|
extern "C" fn divide_by_zero_handler() -> ! {
|
||||||
unsafe { print_error(format_args!("EXCEPTION: PAGE FAULT")) };
|
unsafe { print_error(format_args!("EXCEPTION: DIVIDE BY ZERO")) };
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
#![feature(const_fn, unique)]
|
#![feature(const_fn, unique)]
|
||||||
#![feature(alloc, collections)]
|
#![feature(alloc, collections)]
|
||||||
|
#![feature(asm)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
extern crate rlibc;
|
extern crate rlibc;
|
||||||
@@ -49,8 +50,12 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
|||||||
// initialize our IDT
|
// initialize our IDT
|
||||||
interrupts::init();
|
interrupts::init();
|
||||||
|
|
||||||
// provoke a page fault inside println
|
fn divide_by_zero() {
|
||||||
println!("{:?}", unsafe{ *(0xdeadbeaf as *mut u64) = 42 });
|
unsafe { asm!("mov dx, 0; div dx" ::: "ax", "dx" : "volatile", "intel") }
|
||||||
|
}
|
||||||
|
|
||||||
|
// provoke a divide by zero fault inside println
|
||||||
|
println!("{:?}", divide_by_zero());
|
||||||
|
|
||||||
println!("It did not crash!");
|
println!("It did not crash!");
|
||||||
loop {}
|
loop {}
|
||||||
|
|||||||
Reference in New Issue
Block a user