summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-09 18:28:08 -0400
committerbd <bdunahu@operationnull.com>2025-03-09 18:28:08 -0400
commit6bfae0ef7c7583cfd8a9771332db74ee6eb77a68 (patch)
treef79d3f7c3edde913dadb739fe3d88ffba5e76641
parent56c92e4785fa6952e390fd249cd654f0e5b2d83e (diff)
Move do_write to dram.h, is_blocked flag
-rw-r--r--inc/cache.h7
-rw-r--r--inc/dram.h8
-rw-r--r--inc/storage.h14
-rw-r--r--src/storage/cache.cc7
-rw-r--r--src/storage/dram.cc8
-rw-r--r--src/storage/storage.cc10
6 files changed, 39 insertions, 15 deletions
diff --git a/inc/cache.h b/inc/cache.h
index 4e4b48d..a317f5d 100644
--- a/inc/cache.h
+++ b/inc/cache.h
@@ -28,6 +28,13 @@ class Cache : public Storage
private:
/**
+ * Fetches `address` from a lower level of storage if it is not already
+ * present. If it is not, temporarily sets the is_blocked attribute of this
+ * cache level to true.
+ * @param the address that must be present in cache.
+ */
+ void fetch_resource(int address);
+ /**
* An array of paired bits.
* If the least significant bit of an element is set, the corresponding
* element in `data` is invalid. If the most significant bit of an element
diff --git a/inc/dram.h b/inc/dram.h
index 1061d6b..20221b7 100644
--- a/inc/dram.h
+++ b/inc/dram.h
@@ -19,7 +19,15 @@ class Dram : public Storage
Response read(Accessor accessor, int address, std::array<signed int, LINE_SIZE>& data) override;
private:
+ /**
+ * Helper for `write`.
+ */
+ void do_write(signed int, int);
+ /**
+ * Helper for `read`.
+ */
void do_read(std::array<signed int, LINE_SIZE>& data_line, int address);
};
#endif /* DRAM_H_INCLUDED */
+
diff --git a/inc/storage.h b/inc/storage.h
index 1fb41b0..9707041 100644
--- a/inc/storage.h
+++ b/inc/storage.h
@@ -32,7 +32,10 @@ class Storage
* @return a status code reflecting the state of the request, and the
* data being returned.
*/
- virtual Response read(Accessor accessor, int address, std::array<signed int, LINE_SIZE>& data) = 0;
+ virtual Response read(
+ Accessor accessor,
+ int address,
+ std::array<signed int, LINE_SIZE> &data) = 0;
/**
* Sidedoor view of `lines` of memory starting at `base`.
* @param The base line to start getting memory from.
@@ -48,10 +51,6 @@ class Storage
protected:
/**
- * Helper for `write`.
- */
- void do_write(signed int, int);
- /**
* The data currently stored in this level of storage.
*/
std::vector<std::array<signed int, LINE_SIZE>> *data;
@@ -73,6 +72,11 @@ class Storage
* The number of cycles until the current request is completed.
*/
int wait_time;
+ /**
+ * A flag indicating whether this level of storage is currently blocked by a
+ * lower level.
+ */
+ int is_blocked;
};
#endif /* STORAGE_H_INCLUDED */
diff --git a/src/storage/cache.cc b/src/storage/cache.cc
index cf954b0..e0eaf58 100644
--- a/src/storage/cache.cc
+++ b/src/storage/cache.cc
@@ -24,8 +24,9 @@ Response Cache::write(Accessor accessor, signed int data, int address)
this->requester = accessor;
if (this->requester == accessor) {
+ fetch_resource(address);
if (this->wait_time == 0) {
- this->do_write(data, address);
+ // this->do_write(data, address);
r = OK;
}
}
@@ -34,3 +35,7 @@ Response Cache::write(Accessor accessor, signed int data, int address)
}
Response Cache::read(Accessor accessor, int address, std::array<signed int, LINE_SIZE>& data) { return WAIT; }
+
+void Cache::fetch_resource(int address) {
+
+}
diff --git a/src/storage/dram.cc b/src/storage/dram.cc
index 0db4c35..e3f3c9a 100644
--- a/src/storage/dram.cc
+++ b/src/storage/dram.cc
@@ -15,6 +15,14 @@ Dram::Dram(int lines, int 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;
diff --git a/src/storage/storage.cc b/src/storage/storage.cc
index e3067a2..f382b3e 100644
--- a/src/storage/storage.cc
+++ b/src/storage/storage.cc
@@ -13,20 +13,12 @@ Storage::view(int base, int lines)
return ret;
}
-void Storage::do_write(signed data, int address)
-{
- int line = address / LINE_SIZE;
- int word = address % LINE_SIZE;
-
- this->data->at(line).at(word) = data;
-}
-
void Storage::resolve()
{
if (this->wait_time == 0) {
this->requester = IDLE;
this->wait_time = delay;
- } else if (this->requester != IDLE) {
+ } else if (this->requester != IDLE && !this->is_blocked) {
--this->wait_time;
}
}