use crate::io::vga_text::Color; use core::fmt::Write; const PANIC_SCREEN_MESSAGE_BUFFER_SIZE: usize = 2048; struct TextBuffer<'a> { dst: &'a mut [u8], len: usize, } impl<'a> TextBuffer<'a> { fn new(dst: &'a mut [u8]) -> Self { Self { dst, len: 0 } } fn get(&self) -> &[u8] { &self.dst[..self.len] } } impl<'a> core::fmt::Write for TextBuffer<'a> { fn write_str(&mut self, s: &str) -> core::fmt::Result { if s.len() + self.len > self.dst.len() { Err(core::fmt::Error) } else { let s = s.as_bytes(); (&mut self.dst[self.len..self.len + s.len()]).clone_from_slice(s); Ok(self.len += s.len()) } } } pub fn show(args: Option<&core::fmt::Arguments>) -> core::fmt::Result { use Color::*; let mut vga = crate::vga_lock!(); vga.set_color_state(LightRed, Red); vga.clear(); vga.put_const_byte_str(*b"uff-os"); vga.new_lines(10); vga.set_color_state(White, Red); vga.put_arguments(format_args!( "{:^width$}", "", width = vga.width() )); vga.new_lines(2); vga.set_color_state(Cyan, Red); let buffer = &mut [0u8; PANIC_SCREEN_MESSAGE_BUFFER_SIZE]; let mut tbuffer = TextBuffer::new(buffer); core::fmt::write( &mut tbuffer, *args.unwrap_or(&format_args!("no panic information obtainable")), )?; for line in tbuffer.get().chunks(vga.width()) { vga.put_byte_str(line); } Ok(()) }