From 9d102f63b25e98f98fe2b0bb4f34f8dd8dadc457 Mon Sep 17 00:00:00 2001 From: Clo91eaf Date: Tue, 30 Apr 2024 22:33:45 +0800 Subject: [PATCH] [dut] add step for dut --- src/cpu.rs | 12 ++++++------ src/dut.rs | 14 +++++++------- src/emulator.rs | 11 ++++++----- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/cpu.rs b/src/cpu.rs index da9ffe7..6049f01 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -1004,12 +1004,12 @@ impl Cpu { /// Execute a general-purpose instruction. Raises an exception if something is wrong, /// otherwise, returns a fetched instruction. It also increments the program counter by 4 bytes. fn execute_general(&mut self, inst: u64) -> Result<(), Exception> { - // match self.inst.set_bits(inst as u32) { - // Ok(_) => {} - // Err(_) => { - // panic!("unknown inst, pc: {:x}, inst: {:x}", self.pc, self.inst.bits); - // } - // } + match self.inst.set_bits(inst as u32) { + Ok(_) => {} + Err(_) => { + panic!("unknown inst, pc: {:x}, inst: {:x}", self.pc, self.inst.bits); + } + } // 2. Decode. let opcode = inst & 0x0000007f; // let rd = self.inst.rd as u64; diff --git a/src/dut.rs b/src/dut.rs index 75e9600..cb2644b 100644 --- a/src/dut.rs +++ b/src/dut.rs @@ -6,7 +6,7 @@ use top::Top; // sram interface pub struct Dut { top: Top, - clocks: u64, + pub clocks: u64, } impl Dut { @@ -15,16 +15,18 @@ impl Dut { top.eval(); top.eval(); - top.open_trace("counter.vcd", 99).unwrap(); - Dut { top, clocks: 0 } } - fn trace(&mut self) { - self.top.trace_at(Duration::from_nanos(20 * self.clocks)); + pub fn exec(&mut self) -> anyhow::Result<()> { + + Ok(()) } pub fn step(&mut self) -> anyhow::Result<()> { + // clocks:|0|1|2|3|45678 + // reset: |-|-|_|_|_____ + // clock: |-|_|-|_|-_-_- if self.clocks == 0 { self.top.reset_toggle(); } else if self.clocks == 2 { @@ -33,11 +35,9 @@ impl Dut { self.top.clock_toggle(); self.top.eval(); - self.trace(); self.top.clock_toggle(); self.top.eval(); - self.trace(); self.clocks += 1; diff --git a/src/emulator.rs b/src/emulator.rs index 9a0e2af..b34873d 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -63,12 +63,13 @@ impl Emulator { /// Start executing the emulator. pub fn start(&mut self) { loop { - // let pc = self.cpu.pc; + // ================ cpu ==================== + let pc = self.cpu.pc; let trap = self.execute(); - // println!("================================="); - // println!("pc: {:#x}, inst: {}", pc, self.cpu.inst.disassemble(pc)); - // println!("{}", self.cpu.gpr.to_string()); - // println!("{}", self.cpu.csr.to_string()); + println!("pc: {:#x}, inst: {}", pc, self.cpu.inst); + + // ================ dut ==================== + self.dut.step().unwrap(); match trap { Trap::Fatal => {