From 9be3153a7bea00b88af5918752f7134e39594d4f Mon Sep 17 00:00:00 2001 From: pjht Date: Mon, 27 Mar 2023 15:28:16 -0500 Subject: [PATCH] Add option to peek to read from physical memory --- src/main.rs | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3e67949..545ff9e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -268,6 +268,13 @@ fn main() -> Result<(), anyhow::Error> { .help("The format to print the values in ()"), ) + .arg( + Arg::new("phys") + .long("phys") + .short('p') + .action(ArgAction::SetTrue) + .help("Peek physical memory instead of virtual memory"), + ) .arg(Arg::new("addr").required(true)) .about("Peek a memory address"), |args, state| { @@ -291,14 +298,27 @@ fn main() -> Result<(), anyhow::Error> { } let mut data = Vec::new(); let bus = state.cpu.bus_mut(); - for i in 0..count { - match size { - peek::Size::Byte => data.push(bus.read_byte(addr + i)? as u32), - peek::Size::Word => data.push(bus.read_word(addr + (i * 2))? as u32), - peek::Size::LongWord => data.push( - (bus.read_word(addr + (i * 4))? as u32) << 16 - | (bus.read_word(addr + (i * 4) + 2)? as u32), - ), + if args.get_flag("phys") { + for i in 0..count { + match size { + peek::Size::Byte => data.push(bus.read_byte_phys(addr + i)? as u32), + peek::Size::Word => data.push(bus.read_word_phys(addr + (i * 2))? as u32), + peek::Size::LongWord => data.push( + (bus.read_word_phys(addr + (i * 4))? as u32) << 16 + | (bus.read_word_phys(addr + (i * 4) + 2)? as u32), + ), + } + } + } else { + for i in 0..count { + match size { + peek::Size::Byte => data.push(bus.read_byte(addr + i)? as u32), + peek::Size::Word => data.push(bus.read_word(addr + (i * 2))? as u32), + peek::Size::LongWord => data.push( + (bus.read_word(addr + (i * 4))? as u32) << 16 + | (bus.read_word(addr + (i * 4) + 2)? as u32), + ), + } } } Ok(Some(