add trigger occurrences option in microwatt-verilator. useful for tracing
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 21 Jan 2022 13:03:41 +0000 (13:03 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 21 Jan 2022 13:03:41 +0000 (13:03 +0000)
loops or just when something goes wrong only on the 3rd, 4th or Nth call

verilator/microwatt-verilator.cpp

index f714d4d702d73bd316b1b2b48f9b8e8401cf4c13..ed6661ac3944e3f2ef1236c7691199fc6940106d 100644 (file)
@@ -79,9 +79,21 @@ static void mem_write(unsigned char *mem,
 
 #define BRAM_DEBUG
 #define TRIGGER_ENABLE
-#define TRIGGER_NIA 0xa580
-#define TRIGGER_INSN 0xe8628008
-#define TRIGGER_COUNTDOWN 200000
+#define TRIGGER_OCCURENCES 1
+#define TRIGGER_COUNTDOWN 10000
+//#define TERMINATE_AT_COUNTDOWN
+//#define TRIGGER_NIA 0xa580
+//#define TRIGGER_INSN 0xe8628008
+//#define TRIGGER_NIA 0x900
+//#define TRIGGER_INSN 0x7db243a6
+//define TRIGGER_NIA 0x603348
+//#define TRIGGER_INSN 0x7c842a14
+#define TRIGGER_NIA 0xc00000000042f788
+#define TRIGGER_INSN 0x7c0802a6
+//#define TRIGGER_NIA 0xc000000000077b90
+//#define TRIGGER_NIA 0xc0000000000cf600
+//#define TRIGGER_INSN 0x38210040
+//#define TRIGGER_INSN 0xb3be000a
 //#define TRIGGER_NIA 0x335c
 //#define TRIGGER_INSN 0x3c400001
 
@@ -186,6 +198,7 @@ int main(int argc, char **argv)
     // trace conditions
     bool traceme = true;
     int trigger_countdown = TRIGGER_COUNTDOWN;
+    int trigger_occurrences = TRIGGER_OCCURENCES;
 #ifdef TRIGGER_ENABLE
     traceme = false;
 #endif
@@ -212,23 +225,31 @@ int main(int argc, char **argv)
         if (top->nia_req) {
 #ifdef TRIGGER_ENABLE
             if ((top->nia == TRIGGER_NIA) && (top->insn == TRIGGER_INSN)) {
-                traceme = true;
-                fprintf(dump, "trace trigger enabled\n");
+                if (trigger_occurrences == 1) {
+                    traceme = true;
+                    fprintf(dump, "trace trigger enabled\n");
+                } 
+                if (trigger_occurrences != 0) {
+                    --trigger_occurrences;
+                }
             }
             // tracing active for only TRIGGER_COUNTDOWN cycles
             if (traceme) {
-                trigger_countdown--;
+                --trigger_countdown;
                 if (trigger_countdown == 0) {
                     traceme = false;
+#ifdef TERMINATE_AT_COUNTDOWN
+                    break;
+#endif
                 }
             }
 #endif
-            fprintf(dump, "pc %8x insn %8x msr %16lx",
+            fprintf(dump, "pc %16lx insn %8x msr %16lx",
                                 top->nia, top->insn, top->msr_o);
         }
         if (top->ldst_req) {
             if (!top->nia_req) {
-                fprintf(dump, "pc %-8s insn %-8s msr %-16s", "", "", "");
+                fprintf(dump, "pc %-16s insn %-8s msr %-16s", "", "", "");
             }
             fprintf(dump, "    ldst %16lx", top->ldst_addr);
         }