From 9fcfcbbf16d05d294aadb9b88db0f004ba802bea Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Thu, 15 Apr 2021 22:52:47 +0200 Subject: Rewrite a memory safe vga text buffer --- kernel/src/io/panic_screen.rs | 46 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'kernel/src/io/panic_screen.rs') diff --git a/kernel/src/io/panic_screen.rs b/kernel/src/io/panic_screen.rs index 7b81676..dddf8f5 100644 --- a/kernel/src/io/panic_screen.rs +++ b/kernel/src/io/panic_screen.rs @@ -1,4 +1,5 @@ -use crate::io::vga_text::{CharState, Color, OStream}; +use crate::io::vga_text::Color; +use core::fmt::Write; const PANIC_SCREEN_MESSAGE_BUFFER_SIZE: usize = 2048; @@ -11,8 +12,8 @@ impl<'a> TextBuffer<'a> { fn new(dst: &'a mut [u8]) -> Self { Self { dst, len: 0 } } - fn get(&'a mut self) -> &'a mut [u8] { - &mut self.dst[..self.len] + fn get(&self) -> &[u8] { + &self.dst[..self.len] } } @@ -28,23 +29,30 @@ impl<'a> core::fmt::Write for TextBuffer<'a> { } } -pub fn show(args: Option<&core::fmt::Arguments>) { - let mut stderr = OStream::new(); - stderr.set_state(CharState::from_colors(Color::LightRed, Color::Red)); - stderr.clear(); - stderr.print(b"uff-os"); - stderr.set_row(10); - stderr.set_state(CharState::from_colors(Color::White, Color::Red)); - stderr.print_centered(b""); - stderr.set_row(14); - stderr.set_state(CharState::from_colors(Color::Cyan, Color::Red)); - stderr.set_centered(true); - let buffer: &mut [u8] = &mut [b' '; PANIC_SCREEN_MESSAGE_BUFFER_SIZE]; +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); - let _ = core::fmt::write( + core::fmt::write( &mut tbuffer, *args.unwrap_or(&format_args!("no panic information obtainable")), - ); - stderr.print(tbuffer.get()); - stderr.set_centered(false); + )?; + for line in tbuffer.get().chunks(vga.width()) { + vga.put_byte_str(line); + } + Ok(()) } -- cgit v1.2.3-54-g00ecf