void uart_tx(unsigned char tx);
unsigned char uart_rx(void);
+// pretty-print dumped data in ASCII (to help identify strings)
+static void ascii_dump(unsigned char *data, int len, FILE *dump)
+{
+ for (int i = 0; i < len; i++) {
+ if (isalnum(data[i]))
+ putc(data[i], dump);
+ else
+ putc('.', dump);
+ }
+ putc('\n', dump);
+}
+
int main(int argc, char **argv)
{
Verilated::commandArgs(argc, argv);
tfp->open("microwatt-verilator.vcd");
#endif
+ // dump file for memory read/write traces [uart takes over stdin/stdout]
+ FILE *dump = fopen("bram.dump", "w");
+
+ // read data is one clock cycle delayed
+ bool next_read = false;
+
// Reset
top->ext_rst = 0;
for (unsigned long i = 0; i < 5; i++)
uart_tx(top->uart0_txd);
top->uart0_rxd = uart_rx();
+
if (top->bram_we) {
- printf("bram wr addr %x dout %x sel %x\n",
+ 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);
+ fflush(dump);
}
- if (top->bram_re) {
- printf("bram rd addr %x din %x sel %x\n",
+ if (next_read) { // read on one clock delay
+ fprintf(dump, "bram rd addr %08x din %16lx sel %x ",
top->bram_addr, top->bram_do, top->bram_sel);
+ ascii_dump((unsigned char*)&top->bram_do, 8, dump);
+ fflush(dump);
}
+ next_read = top->bram_re;
}
+ fclose(dump);
+
#if VM_TRACE
tfp->close();
delete tfp;