Add option to peek to read from physical memory

This commit is contained in:
pjht 2023-03-27 15:28:16 -05:00
parent 303c07138b
commit 9be3153a7b
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E

View File

@ -268,6 +268,13 @@ fn main() -> Result<(), anyhow::Error> {
.help("The format to print the values in (<fmt><size>)"), .help("The format to print the values in (<fmt><size>)"),
) )
.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)) .arg(Arg::new("addr").required(true))
.about("Peek a memory address"), .about("Peek a memory address"),
|args, state| { |args, state| {
@ -291,14 +298,27 @@ fn main() -> Result<(), anyhow::Error> {
} }
let mut data = Vec::new(); let mut data = Vec::new();
let bus = state.cpu.bus_mut(); let bus = state.cpu.bus_mut();
for i in 0..count { if args.get_flag("phys") {
match size { for i in 0..count {
peek::Size::Byte => data.push(bus.read_byte(addr + i)? as u32), match size {
peek::Size::Word => data.push(bus.read_word(addr + (i * 2))? as u32), peek::Size::Byte => data.push(bus.read_byte_phys(addr + i)? as u32),
peek::Size::LongWord => data.push( peek::Size::Word => data.push(bus.read_word_phys(addr + (i * 2))? as u32),
(bus.read_word(addr + (i * 4))? as u32) << 16 peek::Size::LongWord => data.push(
| (bus.read_word(addr + (i * 4) + 2)? as u32), (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( Ok(Some(