summaryrefslogtreecommitdiff
path: root/kernel/src
diff options
context:
space:
mode:
authorDennis Kobert <dennis@kobert.dev>2019-11-08 17:13:12 +0100
committerDennis Kobert <dennis@kobert.dev>2019-11-08 17:13:12 +0100
commit1f4468ba19b1db099a42fecef7bde8b2072db82c (patch)
tree0949a90450e4dde0df58bf91bd612ee25ca12fca /kernel/src
parentd261a0f15a350d81430d3937d3c02118c395d27c (diff)
parent3cdbf67de47e033110ad1250398c51e611daa1c4 (diff)
Merge branch 'master' into exceptions
Diffstat (limited to 'kernel/src')
-rw-r--r--kernel/src/io/vga_text.rs23
-rw-r--r--kernel/src/lib.rs19
2 files changed, 32 insertions, 10 deletions
diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs
index fddb3e1..281a40a 100644
--- a/kernel/src/io/vga_text.rs
+++ b/kernel/src/io/vga_text.rs
@@ -23,6 +23,7 @@ pub const WIDTH: usize = 80;
pub const HEIGHT: usize = 25;
#[derive(Clone, Copy)]
+#[repr(C)]
pub struct CharState(pub u8);
impl CharState {
@@ -41,6 +42,7 @@ impl CharState {
#[no_mangle]
#[derive(Clone, Copy)]
+#[repr(C)]
pub struct VgaChar {
pub byte: u8,
pub state: CharState,
@@ -56,6 +58,7 @@ pub struct OStream {
pos: (usize, usize),
cursor: *mut VgaChar,
state: CharState,
+ centered_mode: bool
}
impl OStream {
@@ -64,6 +67,7 @@ impl OStream {
pos: (0, 0),
cursor: Self::at(0),
state: CharState::from_colors(Color::White, Color::Black),
+ centered_mode: false,
}
}
@@ -120,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);
@@ -135,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;
}
@@ -157,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 b36d731..8ec68e5 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -2,6 +2,7 @@
#![feature(compiler_builtins_lib)]
#![feature(custom_test_frameworks)]
#![feature(abi_x86_interrupt)]
+#![feature(panic_info_message)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![no_std]
@@ -34,7 +35,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());
@@ -45,7 +46,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,
@@ -60,15 +61,19 @@ 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);