Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
wave/
obj/
.vscode/
out/
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ VERI_LDFLAGS = -O1
VERI_VFLAGS = --top $(NAME) -Wno-lint -j 8 --cc --exe +define+RANDOMIZE_GARBAGE_ASSIGN --max-num-width 1048576 --compiler clang
VERI_VFLAGS += -Mdir $(VERI_BUILD_DIR) -CFLAGS "$(VERI_CFLAGS)" -LDFLAGS "$(VERI_LDFLAGS)"
VERI_VFLAGS += $(VERI_THREADS)
#VERI_VFLAGS += --trace-fst
ifeq ($(V_WAVE),1)
VERI_VFLAGS += --trace-fst
VERI_CFLAGS += -DV_WAVE
endif

VERI_VSRCS = ready-to-run/difftest/$(TEST_FILE).sv
VERI_CSRCS-2 = $(EMU_GEN_SRCS)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GSIM accepts chirrtl, and compiles it to C++
```
$ make init
$ make run dutName=core
$ make diff dutName=core # add V_WAVE=1 to generate waveform from verilated model
```
+ Set core to `ysyx3`, `rocket`, `small-boom`, `large-boom`, `minimal-xiangshan` or `default-xiangshan`

Expand Down
33 changes: 33 additions & 0 deletions emu/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ void dut_hook(DUT_NAME *dut) {
#if defined(VERILATOR)
#include "verilated.h"
#include REF_HEADER
#if defined (V_WAVE)
#include "verilated_fst_c.h"
VerilatedFstC *tfp;
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
#endif
static REF_NAME* ref;

void ref_init(REF_NAME *ref) {
Expand All @@ -128,6 +133,16 @@ void ref_init(REF_NAME *ref) {
ref->difftest_uart_in_ch = -1;
ref->difftest_uart_in_valid = 0;
#endif
#if defined(V_WAVE)
Verilated::traceEverOn(true);
tfp = new VerilatedFstC;
ref->trace(tfp, 10);
Verilated::mkdir("wave/");
tfp->open("wave/V_wave.fst");
if(tfp->isOpen() == false){
printf("Fail to open wave file!\n");
}
#endif
}

void ref_hook(REF_NAME *ref) {
Expand Down Expand Up @@ -198,8 +213,18 @@ void dut_reset() { dut->set_reset(1); dut_cycle(10); dut->set_reset(0); }
#ifdef VERILATOR
void ref_cycle(int n) {
while (n --) {
#ifdef V_WAVE
contextp->timeInc(1);
#endif
ref->clock = 0; ref->eval();
#ifdef V_WAVE
tfp->dump(contextp->time());
contextp->timeInc(1);
#endif
ref->clock = 1; ref->eval();
#ifdef V_WAVE
tfp->dump(contextp->time());
#endif
}
}
void ref_reset() { ref->reset = 1; ref_cycle(10); ref->reset = 0; }
Expand Down Expand Up @@ -267,6 +292,10 @@ int main(int argc, char** argv) {
printf("ALL diffs: dut -- ref\n");
printf("Failed after %ld cycles\n", cycles);
checkSignals(false);
#ifdef V_WAVE
tfp->flush();
tfp->close();
#endif
return -1;
}
#endif
Expand Down Expand Up @@ -309,4 +338,8 @@ int main(int argc, char** argv) {
if (cycles == CYCLE_MAX_SIM) return 0;
}
}
#ifdef V_WAVE
tfp->flush();
tfp->close();
#endif
}