First commit
This commit is contained in:
31
src/panic_handler.rs
Normal file
31
src/panic_handler.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use core::arch::asm;
|
||||
|
||||
use alloc::{
|
||||
format,
|
||||
string::{String, ToString},
|
||||
};
|
||||
use log::error;
|
||||
|
||||
use crate::vga::{Color, FONT_HEIGHT, Vga};
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(panic_info: &core::panic::PanicInfo) -> ! {
|
||||
error!("PANIC !");
|
||||
let mut panic_message = if let Some(message) = panic_info.message().as_str() {
|
||||
message.to_string()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
if let Some(location) = panic_info.location() {
|
||||
panic_message = format!("{panic_message} at {}:{}", location.file(), location.line());
|
||||
}
|
||||
error!("{panic_message}");
|
||||
|
||||
Vga::clear_screen(Color::WHITE);
|
||||
unsafe { Vga::draw_string(0, 0, "PANIC !", Color::BLACK) };
|
||||
unsafe { Vga::draw_string(0, FONT_HEIGHT as u16, panic_message, Color::BLACK) };
|
||||
|
||||
loop {
|
||||
unsafe { asm!("wfi") }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user