add microwatt-verilator.cpp local-memory-writer which seems to work
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 31 Dec 2021 21:22:33 +0000 (21:22 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 31 Dec 2021 21:22:33 +0000 (21:22 +0000)
discrepancies which used to show up after bram reads are no longer there

verilator/microwatt-verilator.cpp

index 46df43a9e7538c67d72ac46328f268bb1467bedd..e62962f1cb33880afe285ef6c70d87ca5d15b40d 100644 (file)
@@ -63,6 +63,20 @@ static void ascii_dump(unsigned char *data, int len, FILE *dump)
     putc('\n', dump);
 }
 
+// write (masked by sel) to internal mem offset by bram_addr line
+static void mem_write(unsigned char *mem,
+                      unsigned long bram_addr, unsigned long long bram_di,
+                      int bram_sel)
+{
+    unsigned char *mat = &(mem[bram_addr*8]);          // 64-bit (8 byte) wide
+    unsigned char *data_in = (unsigned char*)&bram_di; // treat as bytes
+    for (int i = 0; i < 8; i++) {
+        if (bram_sel & (1<<i)) {  // for each selected byte
+            mat[i] = data_in[i];  // write it to memory
+        }
+    }
+}
+
 int main(int argc, char **argv)
 {
        Verilated::commandArgs(argc, argv);
@@ -136,6 +150,7 @@ int main(int argc, char **argv)
                top->uart0_rxd = uart_rx();
 
         if (top->bram_we) {
+            mem_write(mem, top->bram_addr, top->bram_di, top->bram_sel);
             fprintf(dump, "bram wr addr %08x dout %16lx sel %x ",
                     top->bram_addr, top->bram_di, top->bram_sel);
             ascii_dump((unsigned char*)&top->bram_di, 8, dump);