Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions src/tty/basic_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
}

Expand Down Expand Up @@ -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!("==============");
Expand All @@ -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
Expand All @@ -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 <address>: print 256 bytes of memory at address (0 if not specified)");
crate::println!(" pb <address>: |-------------- same in binary");
crate::println!(" ps: print stack");
crate::println!(" pt: print current tty buffer to serial");
crate::println!(" panic: trigger a rust panic");
}
22 changes: 21 additions & 1 deletion src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down