stack printed, but is it really the stack ?

This commit is contained in:
Jack Halford 2018-02-26 16:14:59 +01:00
parent 063cab66f2
commit 7d08ddf53c
3 changed files with 24 additions and 63 deletions

View file

@ -35,11 +35,11 @@ pub fn shutdown() -> ! {
cpuio::halt(); cpuio::halt();
} }
pub fn print_hexdump(data: &[u8], offset: usize, display: char, bytes: usize) { pub fn print_hexdump(data: &[u8], offset: usize) {
let mut address = 0; let mut address = 0;
while address <= data.len() { while address <= data.len() {
let end = core::cmp::min(address + 16, data.len()); let end = core::cmp::min(address + 16, data.len());
print_line(&data[address..end], address + offset, display, bytes); print_line(&data[address..end], address + offset);
address = address + 16; address = address + 16;
} }
} }
@ -48,72 +48,28 @@ fn is_control(c: char) -> bool {
!(c >= ' ' && c <= '~') !(c >= ' ' && c <= '~')
} }
fn print_line(line: &[u8], address: usize, display: char, bytes: usize) { fn print_line(line: &[u8], address: usize) {
// print address
print!("\n{:08x}: ", address); print!("\n{:08x}: ", address);
let words = match (line.len() % bytes) == 0 { for byte in line {
true => line.len() / bytes, print!("{:02x} ", *byte);
false => (line.len() / bytes) + 1,
};
for b in 0..words {
let word = match bytes {
1 => line[b] as u16,
_ => match line.len() == bytes*b + 1 {
true => u16::from_be(((line[bytes * b] as u16) << 8) + 0),
false => u16::from_be(((line[bytes * b] as u16) << 8) + (line[bytes * b + 1] as u16)),
},
};
match display {
'b' => print!(" {:03o}", word),
'c' => match is_control((word as u8) as char) {
true => print!(" "),
false => print!(" {:03}", (word as u8) as char),
},
'C' => print!(" {:02x}", word),
'x' => print!(" {:04x}", word),
'o' => print!(" {:06o} ", word),
'd' => print!(" {:05} ", word),
_ => print!(" {:04x}", word),
} }
} print!("|");
for byte in line {
if display != 'c' { match is_control(*byte as char) {
if (line.len() % 16) > 0 {
// align
let words_left = (16 - line.len()) / bytes;
let word_size = match display {
'b' => 4,
'c' => 4,
'C' => 3,
'x' => 5,
'o' => 8,
'd' => 8,
_ => 5,
};
for _ in 0..word_size * words_left {
print!(" ");
}
}
print!(" ");
for c in line {
// replace all control chars with dots
match is_control(*c as char) {
true => print!("."), true => print!("."),
false => print!("{}", (*c as char)), false => print!("{}", *byte as char),
} };
}
} }
print!("|");
} }
/// Print the kernel stack /// Print the kernel stack
///
pub fn print_kernel_stack() { pub fn print_kernel_stack() {
let esp: usize; let esp: usize;
let ebp: usize; let ebp: usize;
unsafe { asm!("" : "={esp}"(esp), "={ebp}"(ebp):::) }; unsafe { asm!("" : "={esp}"(esp), "={ebp}"(ebp):::) };
println!("{:#x} -> {:#x} (size={} bytes)", ebp, esp, ebp - esp); println!("{:#x} -> {:#x} (size={} bytes)", ebp, esp, ebp - esp);
let slice = unsafe { core::slice::from_raw_parts_mut(ebp as *mut u8, ebp - esp) }; let slice = unsafe { core::slice::from_raw_parts_mut(ebp as *mut u8, ebp - esp) };
print_hexdump(slice, 0, 'x', ebp - esp); print_hexdump(slice, ebp);
println!(""); println!("");
} }

View file

@ -21,10 +21,10 @@ pub mod console;
pub mod cpuio; pub mod cpuio;
use context::CONTEXT; use context::CONTEXT;
use vga::{Color, ColorCode};
#[no_mangle] #[no_mangle]
pub extern fn kmain(multiboot_information_address: usize) -> ! { pub extern fn kmain(multiboot_information_address: usize) -> ! {
// use vga::{Color, ColorCode};
// unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); } // unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
// print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}", // print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
// format_args!("{: ^80}", r#" ,--, "#), // format_args!("{: ^80}", r#" ,--, "#),

View file

@ -25,10 +25,13 @@ macro_rules! println {
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
} }
macro_rules! flush {
() => (unsafe { CONTEXT.current_term().flush() });
}
pub fn print(args: fmt::Arguments) { pub fn print(args: fmt::Arguments) {
use core::fmt::Write; use core::fmt::Write;
unsafe { CONTEXT.current_term().write_fmt(args).unwrap() }; unsafe { CONTEXT.current_term().write_fmt(args).unwrap() };
unsafe { CONTEXT.current_term().flush() };
} }
extern crate core; extern crate core;
@ -59,6 +62,8 @@ impl Writer {
self.color_code = ColorCode::new(Color::Blue, Color::Black); self.color_code = ColorCode::new(Color::Blue, Color::Black);
self.write_str("> "); self.write_str("> ");
self.color_code = color_code_save; self.color_code = color_code_save;
// self.flush();
flush!();
} }
pub fn backspace(&mut self) { pub fn backspace(&mut self) {
@ -67,7 +72,6 @@ impl Writer {
self.erase_byte(); self.erase_byte();
} }
} }
pub fn keypress(&mut self, ascii: u8) { pub fn keypress(&mut self, ascii: u8) {
match ascii { match ascii {
b'\n' => { b'\n' => {
@ -106,6 +110,7 @@ impl Writer {
self.buffer[i] = b' '; self.buffer[i] = b' ';
self.buffer[i + 1] = 0; self.buffer[i + 1] = 0;
self.flush(); self.flush();
// flush!();
} }
pub fn write_byte(&mut self, byte: u8) { pub fn write_byte(&mut self, byte: u8) {