stack printed, but is it really the stack ?
This commit is contained in:
parent
063cab66f2
commit
7d08ddf53c
3 changed files with 24 additions and 63 deletions
|
|
@ -35,11 +35,11 @@ pub fn shutdown() -> ! {
|
|||
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;
|
||||
while address <= 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -48,72 +48,28 @@ fn is_control(c: char) -> bool {
|
|||
!(c >= ' ' && c <= '~')
|
||||
}
|
||||
|
||||
fn print_line(line: &[u8], address: usize, display: char, bytes: usize) {
|
||||
// print address
|
||||
fn print_line(line: &[u8], address: usize) {
|
||||
print!("\n{:08x}: ", address);
|
||||
let words = match (line.len() % bytes) == 0 {
|
||||
true => line.len() / bytes,
|
||||
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),
|
||||
for byte in line {
|
||||
print!("{:02x} ", *byte);
|
||||
}
|
||||
}
|
||||
|
||||
if display != 'c' {
|
||||
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) {
|
||||
print!("|");
|
||||
for byte in line {
|
||||
match is_control(*byte as char) {
|
||||
true => print!("."),
|
||||
false => print!("{}", (*c as char)),
|
||||
}
|
||||
}
|
||||
false => print!("{}", *byte as char),
|
||||
};
|
||||
}
|
||||
print!("|");
|
||||
}
|
||||
|
||||
/// Print the kernel stack
|
||||
///
|
||||
pub fn print_kernel_stack() {
|
||||
let esp: usize;
|
||||
let ebp: usize;
|
||||
unsafe { asm!("" : "={esp}"(esp), "={ebp}"(ebp):::) };
|
||||
println!("{:#x} -> {:#x} (size={} bytes)", ebp, esp, 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!("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ pub mod console;
|
|||
pub mod cpuio;
|
||||
|
||||
use context::CONTEXT;
|
||||
use vga::{Color, ColorCode};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn kmain(multiboot_information_address: usize) -> ! {
|
||||
// use vga::{Color, ColorCode};
|
||||
// unsafe { CONTEXT.current_term().color_code = ColorCode::new(Color::White, Color::Cyan); }
|
||||
// print!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
|
||||
// format_args!("{: ^80}", r#" ,--, "#),
|
||||
|
|
|
|||
|
|
@ -25,10 +25,13 @@ macro_rules! println {
|
|||
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
||||
}
|
||||
|
||||
macro_rules! flush {
|
||||
() => (unsafe { CONTEXT.current_term().flush() });
|
||||
}
|
||||
|
||||
pub fn print(args: fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
unsafe { CONTEXT.current_term().write_fmt(args).unwrap() };
|
||||
unsafe { CONTEXT.current_term().flush() };
|
||||
}
|
||||
|
||||
extern crate core;
|
||||
|
|
@ -59,6 +62,8 @@ impl Writer {
|
|||
self.color_code = ColorCode::new(Color::Blue, Color::Black);
|
||||
self.write_str("> ");
|
||||
self.color_code = color_code_save;
|
||||
// self.flush();
|
||||
flush!();
|
||||
}
|
||||
|
||||
pub fn backspace(&mut self) {
|
||||
|
|
@ -67,7 +72,6 @@ impl Writer {
|
|||
self.erase_byte();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keypress(&mut self, ascii: u8) {
|
||||
match ascii {
|
||||
b'\n' => {
|
||||
|
|
@ -106,6 +110,7 @@ impl Writer {
|
|||
self.buffer[i] = b' ';
|
||||
self.buffer[i + 1] = 0;
|
||||
self.flush();
|
||||
// flush!();
|
||||
}
|
||||
|
||||
pub fn write_byte(&mut self, byte: u8) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue