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>)"),
)
.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,6 +298,18 @@ fn main() -> Result<(), anyhow::Error> {
}
let mut data = Vec::new();
let bus = state.cpu.bus_mut();
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),
@ -301,6 +320,7 @@ fn main() -> Result<(), anyhow::Error> {
),
}
}
}
Ok(Some(
data.chunks(size.chunk_size())
.enumerate()