summaryrefslogtreecommitdiff
path: root/DRAM.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'DRAM.cpp')
-rw-r--r--DRAM.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/DRAM.cpp b/DRAM.cpp
new file mode 100644
index 0000000..5a0faac
--- /dev/null
+++ b/DRAM.cpp
@@ -0,0 +1,59 @@
+#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)
+ );
+ }
+} \ No newline at end of file