From 3b6f55e3f4bd5e77c7856c9d459ba4161488af20 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Mon, 10 Jan 2022 13:29:19 +0000 Subject: [PATCH] add means to trigger vcd trace from inside microwatt-verilator under #defined program control. TODO: command-line enable --- verilator/microwatt-verilator.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/verilator/microwatt-verilator.cpp b/verilator/microwatt-verilator.cpp index 8ef758d..836540c 100644 --- a/verilator/microwatt-verilator.cpp +++ b/verilator/microwatt-verilator.cpp @@ -29,12 +29,12 @@ double sc_time_stamp(void) VerilatedVcdC *tfp; #endif -void tick(Vmicrowatt *top) +void tick(Vmicrowatt *top, bool dump) { top->ext_clk = 1; top->eval(); #if VM_TRACE - if (tfp) + if (tfp && dump) tfp->dump((double) main_time); #endif main_time++; @@ -42,7 +42,7 @@ void tick(Vmicrowatt *top) top->ext_clk = 0; top->eval(); #if VM_TRACE - if (tfp) + if (tfp && dump) tfp->dump((double) main_time); #endif main_time++; @@ -78,6 +78,11 @@ static void mem_write(unsigned char *mem, } #define BRAM_DEBUG +#define TRIGGER_ENABLE +#define TRIGGER_NIA 0xa580 +#define TRIGGER_INSN 0xe8628008 +//#define TRIGGER_NIA 0x335c +//#define TRIGGER_INSN 0x3c400001 int main(int argc, char **argv) { @@ -172,14 +177,20 @@ int main(int argc, char **argv) // Reset top->ext_rst = 0; for (unsigned long i = 0; i < 5; i++) - tick(top); + tick(top, true); top->ext_rst = 1; unsigned long long bram_do = 0; + // trace conditions + bool traceme = true; +#ifdef TRIGGER_ENABLE + traceme = false; +#endif + while(!Verilated::gotFinish()) { - tick(top); + tick(top, traceme); // read/write the memory to/from the mmap'd file (if given) if (mem != NULL) { @@ -197,6 +208,12 @@ int main(int argc, char **argv) #ifdef BRAM_DEBUG if (top->nia_req) { +#ifdef TRIGGER_ENABLE + if ((top->nia == TRIGGER_NIA) && (top->insn == TRIGGER_INSN)) { + traceme = true; + fprintf(dump, "trace trigger enabled\n"); + } +#endif fprintf(dump, "pc %8x insn %8x msr %16lx", top->nia, top->insn, top->msr_o); } -- 2.30.2