diff options
author | NatrixAeria <upezu@student.kit.edu> | 2021-04-15 22:52:47 +0200 |
---|---|---|
committer | NatrixAeria <upezu@student.kit.edu> | 2021-04-15 22:52:47 +0200 |
commit | 9fcfcbbf16d05d294aadb9b88db0f004ba802bea (patch) | |
tree | 789c83f75e3391ecd3722e94e9a275229ec065e3 /kernel/src/io/panic_screen.rs | |
parent | 8b810a009f8d29ba61a3c377fdeac06a3bbb151d (diff) |
Rewrite a memory safe vga text buffer
Diffstat (limited to 'kernel/src/io/panic_screen.rs')
-rw-r--r-- | kernel/src/io/panic_screen.rs | 46 |
1 files changed, 27 insertions, 19 deletions
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"<kernel panic>"); - 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$}", + "<kernel panic>", + 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(()) } |