#include "DRAM.h" DRAM::DRAM() { buf = new uint8_t[16*1024]; } DRAM::~DRAM() { delete[] buf; } void DRAM::apply( CData clk, CData we, uint64_t claddr, VlWide<4>* cldata) { this->prev_clk = this->clk; this->clk = clk; this->we = we; this->claddr = claddr; this->cldata = cldata; } void DRAM::eval() { if (!prev_clk && clk) posedge_clk(); } void DRAM::posedge_clk() { // Align address on cache line address boundary claddr &= ~0xF; // Get a word based pointer to the memory uint32_t *base = (uint32_t*)(buf + claddr); if (we) { printf("DRAM: write at %llx: %x%x%x%x\n", claddr, cldata->at(3), cldata->at(2), cldata->at(1), cldata->at(0) ); // Write the memory from the bus for (int i = 0; i < 4; i++) base[i] = cldata->at(i); } else { // Write the bus from the memory for (int i = 0; i < 4; i++) cldata->at(i) = base[i]; printf("DRAM: read at %llx: %x%x%x%x\n", claddr, cldata->at(3), cldata->at(2), cldata->at(1), cldata->at(0) ); } }