Skip to content

Commit

Permalink
[emulator] refactor debug info handling in emulator.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed May 11, 2024
1 parent 0697f60 commit 149cd00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/dut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Dut {
SramRequest::new(self.top.inst_sram_en() != 0, self.top.inst_sram_addr()),
SramRequest::new(self.top.data_sram_en() != 0, self.top.data_sram_addr()),
DebugInfo::new(
self.top.debug_commit() != 0 && self.top.debug_reg_wnum() != 0,
self.top.debug_commit() != 0,
self.top.debug_pc(),
self.top.debug_reg_wnum(),
self.top.debug_wdata(),
Expand Down
43 changes: 17 additions & 26 deletions src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl fmt::Display for DebugInfo {

impl PartialEq for DebugInfo {
fn eq(&self, other: &Self) -> bool {
self.commit == other.commit && self.pc == other.pc && self.wnum == other.wnum && self.wdata == other.wdata
self.pc == other.pc && (self.wnum == 0 || (self.wnum == other.wnum && self.wdata == other.wdata))
}
}

Expand Down Expand Up @@ -164,31 +164,23 @@ impl Emulator {
let mut last_diff = DebugInfo::default();
loop {
// ================ cpu ====================
let cpu_diff;
loop {
let pc = self.cpu.pc;
let trap = self.execute();

match trap {
Trap::Fatal => {
info!("[cpu] fatal pc: {:#x}, trap {:#?}", self.cpu.pc, trap);
return;
}
_ => {}
}
let pc = self.cpu.pc;
let trap = self.execute();
let cpu_diff = match self.cpu.gpr.record {
Some((wnum, wdata)) => DebugInfo::new(true, pc, wnum, wdata),
None => DebugInfo::new(true, pc, 0, 0),
};

match self.cpu.gpr.record {
Some((wnum, wdata)) => {
cpu_diff = DebugInfo::new(true, pc, wnum, wdata);
info!("[cpu] record: true, pc: {:#x}, inst: {}", pc, self.cpu.inst);
break;
}
None => {
info!("[cpu] record: false, pc: {:#x}, inst: {}", pc, self.cpu.inst);
}
match trap {
Trap::Fatal => {
info!("[cpu] fatal pc: {:#x}, trap {:#?}", self.cpu.pc, trap);
return;
}
_ => {}
}

info!("[cpu] pc: {:#x}, inst: {}", pc, self.cpu.inst);

let dut_diff;
let dut = self.dut.as_mut().unwrap();

Expand Down Expand Up @@ -236,12 +228,11 @@ impl Emulator {
}
}
info!(
"[dut] ticks: {} commit: {} pc: {:#010x} wnum: {} wdata: {:#018x}",
dut.ticks,
dut.top.debug_commit(),
"[dut] pc: {:#010x}, wnum: {} wdata: {:#018x} ticks: {}",
dut.top.debug_pc(),
dut.top.debug_reg_wnum(),
dut.top.debug_wdata()
dut.top.debug_wdata(),
dut.ticks
);

// ==================== diff ====================
Expand Down

0 comments on commit 149cd00

Please sign in to comment.