diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 46dd45b..d7d97c9 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -18,5 +18,6 @@ log = "0.4.22" [lints.clippy] missing_safety_doc = "allow" needless_range_loop = "allow" +too_many_arguments = "allow" type_complexity = "allow" upper_case_acronyms = "allow" diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 1f92d59..9999802 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -23,7 +23,7 @@ use kernel_common::{ paging::{KERNEL_HEAP_INITIAL_SIZE, KERNEL_HEAP_START}, }; use log::{error, info}; -use misc::display::{setup_display, DISPLAY}; +use misc::display::{setup_display, PANIC_DISPLAY}; use sys::{ acpica_osl::AE_OK, early_acpi::EarlyACPIHandler, @@ -115,8 +115,9 @@ fn panic(info: &PanicInfo) -> ! { } error!("{}", info); let str = format!("{}", info); - let mut display = DISPLAY.lock(); + let mut display = PANIC_DISPLAY.lock(); if let Some(display) = display.as_mut() { + display.clear(); display.print(&str); } } diff --git a/kernel/src/misc/display.rs b/kernel/src/misc/display.rs index 3562c79..3617aef 100644 --- a/kernel/src/misc/display.rs +++ b/kernel/src/misc/display.rs @@ -18,7 +18,9 @@ pub struct Display { current_y: usize, } +//TODO: Change to mutex pub static DISPLAY: Spinlock> = Spinlock::new(None); +pub static PANIC_DISPLAY: Spinlock> = Spinlock::new(None); impl Display { fn write_char(&mut self, x: usize, y: usize, c: char) { @@ -28,6 +30,12 @@ impl Display { let text = Text::new(&str, pos, style); text.draw(&mut self.framebuffer).unwrap(); } + pub fn clear(&mut self) { + self.framebuffer.clear(Bgr888::BLACK).unwrap(); + self.current_x = 0; + self.current_y = 0; + self.copy_to_fb(); + } fn scroll(&mut self) { let line_size = self.framebuffer.stride * 20 * 4; self.framebuffer.framebuffer.copy_within(line_size..line_size * self.height, 0); @@ -78,5 +86,20 @@ pub fn setup_display(info: FramebufferInfo) { current_x: 0, current_y: 0, }; + *PANIC_DISPLAY.lock() = Some(display); + let fb = vec![0; info.height as usize * info.stride as usize * 4]; + let display = Display { + framebuffer: FramebufferTarget { + framebuffer: fb, + width: info.width as usize, + height: info.height as usize, + stride: info.stride as usize, + }, + framebuffer_addr: addr, + width: info.width as usize / 10 - 1, + height: info.height as usize / 20 - 1, + current_x: 0, + current_y: 0, + }; *DISPLAY.lock() = Some(display); } diff --git a/kernel/src/sys/locks.rs b/kernel/src/sys/locks.rs index 7c59187..bfbe81a 100644 --- a/kernel/src/sys/locks.rs +++ b/kernel/src/sys/locks.rs @@ -15,11 +15,9 @@ unsafe impl RawMutex for RawSpinlock { fn lock(&self) { self.raw_lock(); } - fn try_lock(&self) -> bool { unimplemented!(); } - unsafe fn unlock(&self) { self.raw_unlock(); }