From 149cd00cb6c2e1e114f58b8021812a2a4e83d9e3 Mon Sep 17 00:00:00 2001 From: Clo91eaf Date: Sat, 11 May 2024 11:14:21 +0800 Subject: [PATCH] [emulator] refactor debug info handling in emulator.rs --- src/dut.rs | 2 +- src/emulator.rs | 43 +++++++++++++++++-------------------------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/dut.rs b/src/dut.rs index fbc2fca..5f6cd5b 100644 --- a/src/dut.rs +++ b/src/dut.rs @@ -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(), diff --git a/src/emulator.rs b/src/emulator.rs index 83ebf8f..bdda9e0 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -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)) } } @@ -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(); @@ -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 ====================