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);
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);