summaryrefslogtreecommitdiff
path: root/src/storage/dram.cc
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-10 10:28:28 -0400
committerGitHub <noreply@github.com>2025-03-10 10:28:28 -0400
commit357e7fb37caf58cdfcdf85f7553db9378ff16e0c (patch)
treea0b0df4fff6f7d680901cd6007df67b15b3df3b6 /src/storage/dram.cc
parent57faaa064046824fec72e81a7e0973c495263395 (diff)
parentd0ec568e4f063fd1c85087582283f3511e0a12ec (diff)
Merge pull request #19 from bdunahu/bdunahu
cache store, handle load requests to memory, write allocate policy -- changes look good
Diffstat (limited to 'src/storage/dram.cc')
-rw-r--r--src/storage/dram.cc25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/storage/dram.cc b/src/storage/dram.cc
index 0db4c35..441f10b 100644
--- a/src/storage/dram.cc
+++ b/src/storage/dram.cc
@@ -8,13 +8,22 @@ Dram::Dram(int lines, int delay)
this->data = new std::vector<std::array<signed int, LINE_SIZE>>;
this->data->resize(lines);
this->delay = delay;
- this->wait_time = this->delay;
+ this->is_waiting = false;
this->lower = nullptr;
this->requester = IDLE;
+ this->wait_time = this->delay;
}
Dram::~Dram() { delete this->data; }
+void Dram::do_write(signed data, int address)
+{
+ int line = address / LINE_SIZE;
+ int word = address % LINE_SIZE;
+
+ this->data->at(line).at(word) = data;
+}
+
Response Dram::write(Accessor accessor, signed int data, int address)
{
Response r = WAIT;
@@ -38,20 +47,26 @@ Response Dram::write(Accessor accessor, signed int data, int address)
return r;
}
-void Dram::do_read(std::array<signed int, LINE_SIZE>& data_line, int address){
+void Dram::do_read(std::array<signed int, LINE_SIZE> &data_line, int address)
+{
int line = address / LINE_SIZE;
data_line = this->data->at(line);
}
-Response Dram::read(Accessor accessor, int address, std::array<signed int, LINE_SIZE>& data) {
+Response Dram::read(
+ Accessor accessor, int address, std::array<signed int, LINE_SIZE> &data)
+{
Response r = WAIT;
+
if (this->requester == IDLE)
this->requester = accessor;
+
if (this->requester == accessor) {
if (this->wait_time == 0) {
this->do_read(data, address);
r = OK;
}
}
- return r;
- }
+
+ return r;
+}