Skip to content

Commit

Permalink
[dut] add step for dut
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Apr 30, 2024
1 parent 0b4317b commit 9d102f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/dut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use top::Top;
// sram interface
pub struct Dut {
top: Top,
clocks: u64,
pub clocks: u64,
}

impl Dut {
Expand All @@ -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 {
Expand All @@ -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;

Expand Down
11 changes: 6 additions & 5 deletions src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 9d102f6

Please sign in to comment.