summaryrefslogtreecommitdiff
path: root/kernel/src
diff options
context:
space:
mode:
authornatrixaeria <upezu@student.kit.edu>2019-11-08 17:08:56 +0100
committernatrixaeria <upezu@student.kit.edu>2019-11-08 17:08:56 +0100
commit3cdbf67de47e033110ad1250398c51e611daa1c4 (patch)
treeeae32faa05e40f8cf46fdc6858afba3d2ad40cff /kernel/src
parentbfdafd91058b91d5d4e8ab36076e05ae29355f7b (diff)
Add centered mode to vga compatible text mode
Diffstat (limited to 'kernel/src')
-rw-r--r--kernel/src/io/vga_text.rs21
-rw-r--r--kernel/src/lib.rs15
2 files changed, 26 insertions, 10 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index 620aa32..281a40a 100644
--- a/kernel/src/io/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -58,6 +58,7 @@ pub struct OStream {
pos: (usize, usize),
cursor: *mut VgaChar,
state: CharState,
+ centered_mode: bool
}
impl OStream {
@@ -66,6 +67,7 @@ impl OStream {
pos: (0, 0),
cursor: Self::at(0),
state: CharState::from_colors(Color::White, Color::Black),
+ centered_mode: false,
}
}
@@ -122,6 +124,10 @@ impl OStream {
}
}
+ pub fn set_centered(&mut self, b: bool) {
+ self.centered_mode = b
+ }
+
pub fn new_line(&mut self) {
if self.pos.1 >= HEIGHT - 1 {
self.set_col(0);
@@ -137,20 +143,29 @@ impl OStream {
self.state = state
}
- pub fn print(&mut self, s: &[u8]) {
+ pub fn put_bytes(&mut self, s: &[u8]) {
for &b in s {
self.put_byte(b)
}
}
+ pub fn print(&mut self, s: &[u8]) {
+ if self.centered_mode {
+ self.print_centered(s)
+ } else {
+ self.put_bytes(s)
+ }
+ }
+
pub fn print_centered(&mut self, s: &[u8]) {
let mut line = &s[..];
let mut n = 0;
+ if s.len() == 0 { return; }
let slast = s.len() - 1;
for (i, &b) in s.iter().enumerate() {
if n >= WIDTH {
self.set_col(0);
- self.print(&line[..WIDTH]);
+ self.put_bytes(&line[..WIDTH]);
line = &line[WIDTH..];
n = 0;
}
@@ -159,7 +174,7 @@ impl OStream {
n += 1
}
self.set_col(((WIDTH - n) / 2) as usize);
- self.print(&line[..n]);
+ self.put_bytes(&line[..n]);
self.new_line();
if i == slast {
return;
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index d5a3e9e..cbc9915 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -1,6 +1,7 @@
#![no_main]
#![feature(compiler_builtins_lib)]
#![feature(custom_test_frameworks)]
+#![feature(panic_info_message)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![no_std]
@@ -33,7 +34,7 @@ pub extern "C" fn _start() -> ! {
let mut stdout = OStream::new();
stdout.clear();
- panic!("panic!");
+ panic!("panic! at the disco");
core::iter::successors(Some(0), |n| Some(n + 1))
.for_each(|n| write!(&mut stdout, "hello world {}!", n).unwrap());
@@ -43,7 +44,7 @@ pub extern "C" fn _start() -> ! {
#[panic_handler]
#[no_mangle]
-pub extern "C" fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
+pub extern "C" fn panic_handler(info: &core::panic::PanicInfo) -> ! {
let mut stderr = OStream::new();
stderr.set_state(vga_text::CharState::from_colors(
vga_text::Color::LightRed,
@@ -58,15 +59,15 @@ pub extern "C" fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
));
stderr.print_centered(b"<kernel panic>");
stderr.set_row(14);
- let text = _info
- .payload()
- .downcast_ref::<&str>()
- .unwrap_or(&"no panic information is obtainable");
stderr.set_state(vga_text::CharState::from_colors(
vga_text::Color::Cyan,
vga_text::Color::Red,
));
- stderr.print_centered(text.as_bytes());
+ stderr.set_centered(true);
+ write!(&mut stderr, "{:?}", info.message()
+ .unwrap_or(&format_args!("no panic information obtainable")));
+ //loop{}
+ stderr.set_centered(false);
if cfg!(test) {
write!(serial::SerialStream::new(), "Testing failed\n").unwrap();
qemu::exit_qemu(qemu::QemuExitCode::Failed);