diff options
author | natrixaeria <upezu@student.kit.edu> | 2019-10-26 00:54:05 +0200 |
---|---|---|
committer | natrixaeria <upezu@student.kit.edu> | 2019-10-26 00:54:05 +0200 |
commit | 62cce51eff15b648179a3ad8c77a0885e9394a10 (patch) | |
tree | 88664619fe5c4aea983f0cdad2c8a8ce68407e92 | |
parent | 983fd463b11ec1a64083f35fb09e06fb0a6e3255 (diff) |
Create a kernel panic screen
-rwxr-xr-x | kernel/build.sh | 4 | ||||
-rw-r--r-- | kernel/src/lib.rs | 18 | ||||
-rw-r--r-- | kernel/src/vga_text.rs | 35 |
3 files changed, 52 insertions, 5 deletions
diff --git a/kernel/build.sh b/kernel/build.sh index a162d57..d8086b6 100755 --- a/kernel/build.sh +++ b/kernel/build.sh @@ -69,8 +69,10 @@ build_clean() { } build_build() { - build_clean cargo xbuild + rm -rf $TARGET_PATH/sysroot + rm -rf $TARGET_PATH/kernel.bin + rm -rf $TARGET_PATH/uff.iso build_run } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 48cb93d..8d2eee2 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -16,6 +16,8 @@ pub extern "C" fn _start() -> ! { write!(&mut stdout, "hello world!"); + panic!("i has panicing"); + core::iter::successors(Some(0), |n| Some(n + 1)) .for_each(|n| write!(&mut stdout, "hello world {}!", n).unwrap() @@ -27,5 +29,21 @@ pub extern "C" fn _start() -> ! { #[panic_handler] #[no_mangle] pub extern "C" fn panic_handler(_info: &core::panic::PanicInfo) -> ! { + let mut stderr = vga_text::OStream::new(); + stderr.set_state(vga_text::CharState::from_colors( + vga_text::Color::LightRed, vga_text::Color::Red)); + stderr.clear(); + stderr.print(b"uff-os"); + stderr.set_row(10); + stderr.set_state(vga_text::CharState::from_colors( + vga_text::Color::White, vga_text::Color::Red)); + stderr.print_centered(b"<kernel panic>"); + stderr.set_row(14); + let text = _info.payload() + .downcast_ref::<&str>() + .unwrap_or(&"no panic informations are obtainable"); + stderr.set_state(vga_text::CharState::from_colors( + vga_text::Color::Cyan, vga_text::Color::Red)); + stderr.print_centered(text.as_bytes()); loop {} } diff --git a/kernel/src/vga_text.rs b/kernel/src/vga_text.rs index 5298da7..a292c8c 100644 --- a/kernel/src/vga_text.rs +++ b/kernel/src/vga_text.rs @@ -128,13 +128,40 @@ impl OStream { pub fn set_state(&mut self, state: CharState) { self.state = state } + + pub fn print(&mut self, s: &[u8]) { + for &b in s { + self.put_byte(b) + } + } + + pub fn print_centered(&mut self, s: &[u8]) { + let mut line = &s[..]; + let mut n = 0; + let slast = s.len() - 1; + for (i, &b) in s.iter().enumerate() { + if n >= 80 { + self.set_col(0); + self.print(&line[..80]); + line = &line[80..]; + n = 0; + } + if b == b'\n' || i == slast { + if b != b'\n' { n += 1 } + self.set_col(((80 - n) / 2) as u8); + self.print(&line[..n]); + self.new_line(); + if i == slast { return; } + line = &line[(n+1)..]; + n = 0; + } + n += 1; + } + } } impl core::fmt::Write for OStream { fn write_str(&mut self, s: &str) -> core::fmt::Result { - for &b in s.as_bytes() { - self.put_byte(b) - } - Ok(()) + Ok(self.print(s.as_bytes())) } } |