diff options
author | bd <bdunaisky@umass.edu> | 2025-03-11 21:16:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-11 21:16:25 +0000 |
commit | 92e8c2583695a3bf652e0e8dedb79e7a99922f5f (patch) | |
tree | 0574ee516499001244d33785a5fc380801c557c9 /src/storage/dram.cc | |
parent | 33c7c78b1c65c375d0291fd435e02ddc9d35681b (diff) | |
parent | 5f13f583e373bb02b7bf20cbcc9298dc1480a697 (diff) |
Merge pull request #25 from bdunahu/dev-sid
support for read word, write line in all levels of storage, cache load, dirty cache eviction, memory address wrapping
Diffstat (limited to 'src/storage/dram.cc')
-rw-r--r-- | src/storage/dram.cc | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/src/storage/dram.cc b/src/storage/dram.cc index e755c2a..f375a76 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -20,7 +20,7 @@ Dram::Dram(int lines, int delay) Dram::~Dram() { delete this->data; } -void Dram::do_write(signed data, int address) +void Dram::do_write(signed int data, int address) { int line = address / LINE_SIZE; int word = address % LINE_SIZE; @@ -28,7 +28,50 @@ void Dram::do_write(signed data, int address) this->data->at(line).at(word) = data; } -Response Dram::write(Accessor accessor, signed int data, int address) +void Dram::do_write_line( + std::array<signed int, LINE_SIZE> data_line, int address) +{ + int line = address / LINE_SIZE; + this->data->at(line) = data_line; +} + +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); +} + +void Dram::do_read_word(signed int &data, int address) +{ + int line = address / LINE_SIZE; + int word = address % LINE_SIZE; + data = this->data->at(line).at(word); +} + +Response Dram::write_line( + Accessor accessor, std::array<signed int, LINE_SIZE> data_line, int address) +{ + Response r = WAIT; + + if (accessor == SIDE) { + this->do_write_line(data_line, address); + r = OK; + } else { + /* Do this first--then process the first cycle immediately. */ + if (this->requester == IDLE) + this->requester = accessor; + + if (this->requester == accessor) { + if (this->wait_time == 0) { + this->do_write_line(data_line, address); + r = OK; + } + } + } + return r; +} + +Response Dram::write_word(Accessor accessor, signed int data, int address) { Response r = WAIT; @@ -51,14 +94,27 @@ 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) +Response Dram::read_line( + Accessor accessor, + int address, + std::array<signed int, LINE_SIZE> &data_line) { - int line = address / LINE_SIZE; - data_line = this->data->at(line); + Response r = WAIT; + + if (this->requester == IDLE) + this->requester = accessor; + + if (this->requester == accessor) { + if (this->wait_time == 0) { + this->do_read(data_line, address); + r = OK; + } + } + + return r; } -Response Dram::read( - Accessor accessor, int address, std::array<signed int, LINE_SIZE> &data) +Response Dram::read_word(Accessor accessor, int address, signed int &data) { Response r = WAIT; @@ -67,7 +123,7 @@ Response Dram::read( if (this->requester == accessor) { if (this->wait_time == 0) { - this->do_read(data, address); + this->do_read_word(data, address); r = OK; } } |