add means to trigger vcd trace from inside microwatt-verilator
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 10 Jan 2022 13:29:19 +0000 (13:29 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 10 Jan 2022 13:29:19 +0000 (13:29 +0000)
under #defined program control. TODO: command-line enable

verilator/microwatt-verilator.cpp

index 8ef758dc5e94c24ffc520bbbd6513900f29073bd..836540c497f07a9f624dc55e344f9fb74c48e6e1 100644 (file)
@@ -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);
         }