mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add a print_error function, which works for exceptions inside println
This commit is contained in:
@@ -14,7 +14,9 @@ pub fn init() {
|
||||
IDT.load();
|
||||
}
|
||||
|
||||
use vga_buffer::print_error;
|
||||
|
||||
extern "C" fn page_fault_handler() -> ! {
|
||||
println!("EXCEPTION: PAGE FAULT");
|
||||
unsafe { print_error(format_args!("EXCEPTION: PAGE FAULT")) };
|
||||
loop {}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
||||
// initialize our IDT
|
||||
interrupts::init();
|
||||
|
||||
// provoke a page fault by writing to some random address
|
||||
unsafe{ *(0xdeadbeaf as *mut u64) = 42 };
|
||||
// provoke a page fault inside println
|
||||
println!("{:?}", unsafe{ *(0xdeadbeaf as *mut u64) = 42 });
|
||||
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
|
||||
@@ -38,6 +38,19 @@ pub fn clear_screen() {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn print_error(fmt: fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
|
||||
let mut writer = Writer {
|
||||
column_position: 0,
|
||||
color_code: ColorCode::new(Color::Red, Color::Black),
|
||||
buffer: Unique::new(0xb8000 as *mut _),
|
||||
};
|
||||
writer.new_line();
|
||||
writer.write_fmt(fmt);
|
||||
}
|
||||
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[repr(u8)]
|
||||
pub enum Color {
|
||||
|
||||
Reference in New Issue
Block a user