diff --git a/.gitignore b/.gitignore index d977ab76..e56df643 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build/ +wave/ obj/ .vscode/ out/ diff --git a/Makefile b/Makefile index 625ac260..861f3a94 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/README.md b/README.md index f1d13f18..1e772881 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/emu/emu.cpp b/emu/emu.cpp index 2da5ddbb..63277c8a 100644 --- a/emu/emu.cpp +++ b/emu/emu.cpp @@ -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 contextp{new VerilatedContext}; +#endif static REF_NAME* ref; void ref_init(REF_NAME *ref) { @@ -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) { @@ -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; } @@ -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 @@ -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 }