diff --git a/src/tty/basic_commands.rs b/src/tty/basic_commands.rs index f54ce5c..b9a3696 100644 --- a/src/tty/basic_commands.rs +++ b/src/tty/basic_commands.rs @@ -11,11 +11,44 @@ pub fn execute(command: &str) "halt" | "exit" => halt(), "reboot" => reboot(), "scheen" => scheen(), - "pm" |"printmem" => printmem(), - "ps" |"printstack" => print_stack(), + "pm" => printmem_at(0 as *const u8, false), + "pb" => printmem_at(0 as *const u8, true), + "ps" => print_stack(), + "pt" => printtty(), "panic" => panic(), "" => {}, - _ => crate::println!("{}: unknown command. Use help for more", command) + _ => + { + if let Some(command_end) = command.find(' ') + { + let arg = &command[command_end + 1..]; + let command = &command[..command_end]; + match command + { + "pm" | "pb" => + { + let address = u32::from_str_radix(arg, 16) + .unwrap_or_else(|_| + { + crate::println!("invalid argument for {}: {}", + command, arg); + 0 + }); + match command + { + "pm" => printmem_at(address as *const u8, false), + "pb" => printmem_at(address as *const u8, true), + _ => {} + }; + } + _ => crate::println!("{}: unknown or invalid command. Use help for more", command) + } + } + else + { + crate::println!("{}: unknown or invalid command. Use help for more", command); + } + } }; } @@ -46,7 +79,7 @@ fn scheen() crate::println!("yo yo des esch d'becht OS eh ?"); } -fn printmem() +fn printtty() { crate::println!("ok"); crate::serial_println!("=============="); @@ -57,6 +90,21 @@ fn printmem() crate::serial_println!("=============="); } +fn printmem_at(address: *const u8, binary: bool) +{ + unsafe + { + if binary + { + utilities::print_memory_bin(address, 256); + } + else + { + utilities::print_memory(address, 256); + } + } +} + fn print_stack() { unsafe @@ -78,6 +126,9 @@ fn help() crate::println!(" halt | exit: stop the virtual machine (qemu only)"); crate::println!(" reboot: reboot the machine"); crate::println!("Debug commands:"); - crate::println!(" printmem | pm: print current tty buffer to serial"); - crate::println!(" panic : trigger a rust panic"); + crate::println!(" pm
: print 256 bytes of memory at address (0 if not specified)"); + crate::println!(" pb
: |-------------- same in binary"); + crate::println!(" ps: print stack"); + crate::println!(" pt: print current tty buffer to serial"); + crate::println!(" panic: trigger a rust panic"); } diff --git a/src/utilities.rs b/src/utilities.rs index 49e1152..b0ed081 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -72,7 +72,7 @@ pub unsafe fn print_memory(ptr: *const u8, n: usize) { if i % 16 == 0 { - crate::log!("{:0x}: ", ptr.add(i) as u32); + crate::log!("{:08x}: ", ptr.add(i) as u32); } crate::log!("{:02x?} ", *ptr.add(i)); i += 1; @@ -95,6 +95,26 @@ pub unsafe fn print_memory(ptr: *const u8, n: usize) crate::logln!(); } +pub unsafe fn print_memory_bin(ptr: *const u8, n: usize) +{ + let mut i: usize = 0; + + while i < n + { + if i % 4 == 0 + { + crate::log!("{:08x}: ", ptr.add(i) as u32); + } + crate::log!("{:08b} ", *ptr.add(i)); + i += 1; + if i % 4 == 0 + { + crate::logln!(); + } + } + crate::logln!(); +} + #[macro_export] macro_rules! get_reg {