Skip to content

Commit 06d8e5e

Browse files
Samuel OrtizSamuel Ortiz
authored andcommitted
do-core1: Add a routine for dumping a do-core1 CPU state
Now that we have a complete set of registers, it is more convenient to be able to print all of them. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent b643bcc commit 06d8e5e

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/main.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,19 @@ fn xor(op0: u32, op1: u32) -> u32 {
8080
op0 ^ op1
8181
}
8282

83+
fn dump_cpu_state(preamble: &str, registers: &[u32; MAX_REGISTER_INDEX as usize + 1]) {
84+
println!("do-core1: {}:", preamble);
85+
for (index, register) in registers.iter().enumerate() {
86+
println!("\tR{}: {:#x?}", index, *register);
87+
}
88+
}
89+
8390
fn main() -> Result<(), Error> {
8491
let opts: DoCoreOpts = DoCoreOpts::parse();
8592
let insn = u32::from_str_radix(opts.insn.trim_start_matches("0x"), 16).unwrap();
86-
let mut registers = [0; MAX_REGISTER_INDEX as usize + 1];
93+
let mut registers = [0u32; MAX_REGISTER_INDEX as usize + 1];
8794

88-
println!(
89-
"do-core-1: instruction {:#x?} Initial CPU state {:#x?}",
90-
insn, registers
91-
);
95+
dump_cpu_state("Initial CPU state", &registers);
9296

9397
let decoded_instruction = Instruction::disassemble(insn)?;
9498
println!(
@@ -105,10 +109,7 @@ fn main() -> Result<(), Error> {
105109
_ => panic!("Unknown opcode {:?}", decoded_instruction.opcode),
106110
}
107111

108-
println!(
109-
"do-core-1: instruction {:#x?} Final CPU state {:#x?}",
110-
insn, registers
111-
);
112+
dump_cpu_state("Final CPU state", &registers);
112113

113114
Ok(())
114115
}

0 commit comments

Comments
 (0)