summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-22 11:00:14 -0400
committerGitHub <noreply@github.com>2025-03-22 11:00:14 -0400
commit4bad9ab29a5fa6c442a257974beb7daeaf91f046 (patch)
tree9386aa3ccd2302fceb9750858d74ab56f156b4e2 /inc
parent82096f8cea42d78505b49d9f8ba22573daa2cc12 (diff)
parente73294467108f914debda39db2204c1f1493f8bf (diff)
Merge pull request #29 from bdunahu/bdunahu
Small cleanups to up a lot of implementation details
Diffstat (limited to 'inc')
-rw-r--r--inc/cache.h21
-rw-r--r--inc/dram.h29
-rw-r--r--inc/utils.h14
3 files changed, 51 insertions, 13 deletions
diff --git a/inc/cache.h b/inc/cache.h
index 3b16ca1..ef9c9e4 100644
--- a/inc/cache.h
+++ b/inc/cache.h
@@ -42,6 +42,27 @@ class Cache : public Storage
private:
/**
+ * Helper for all access methods.
+ * Calls `request_handler` when `accessor` is allowed to complete its
+ * request cycle.
+ * @param the source making the request
+ * @param the address to write to
+ * @param the function to call when an access should be completed
+ */
+ Response process(
+ Accessor accessor,
+ int address,
+ std::function<void(int index, int offset)> request_handler);
+ /**
+ * Returns OK if `accessor` is allowed to complete its request this cycle.
+ * Handles cache misses, wait times, and setting the current accessor this
+ * storage is serving.
+ * @param the accessor asking for a resource
+ * @return whether or not the access can be carried out this function call.
+ */
+ Response is_access_cleared(Accessor accessor, int address);
+ /**
+ * Helper for access_cleared.
* 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, and the victim line is chosen/written back.
diff --git a/inc/dram.h b/inc/dram.h
index c7f927a..e6db633 100644
--- a/inc/dram.h
+++ b/inc/dram.h
@@ -32,22 +32,25 @@ class Dram : public Storage
private:
/**
- * Helper for `write` a word
+ * Helper for all access methods.
+ * Calls `request_handler` when `accessor` is allowed to complete its
+ * request cycle.
+ * @param the source making the request
+ * @param the address to write to
+ * @param the function to call when an access should be completed
*/
- void do_write(signed int, int);
- /**
- * Helper for writing a line.
- */
- void
- do_write_line(std::array<signed int, LINE_SIZE> data_line, int address);
- /**
- * Helper for `read` a line
- */
- void do_read(std::array<signed int, LINE_SIZE> &data_line, int address);
+ Response process(
+ Accessor accessor,
+ int address,
+ std::function<void(int line, int word)> request_handler);
/**
- * Helper for reading a word.
+ * Returns OK if `accessor` is allowed to complete its request this cycle.
+ * Handles wait times, side door, and setting the current accessor this
+ * storage is serving.
+ * @param the accessor asking for a resource
+ * @return whether or not the access can be carried out this function call.
*/
- void do_read_word(signed int &data, int address);
+ Response is_access_cleared(Accessor accessor);
};
std::ostream &operator<<(std::ostream &os, const Dram &d);
diff --git a/inc/utils.h b/inc/utils.h
index aa8831b..df8d374 100644
--- a/inc/utils.h
+++ b/inc/utils.h
@@ -20,6 +20,20 @@ void get_bit_fields(int address, int *tag, int *index, int *offset);
*/
const std::string string_format(const char *const zcFormat, ...);
+/**
+ * Given `address`, returns an address that is within the current memory size
+ * using a clean wrap.
+ * @param an address
+ * @return an address guaranteed to be within range.
+ */
int wrap_address(int address);
+/**
+ * Given `address`, returns the line and word it is in.
+ * @param an address
+ * @param the line (row) `address` is in
+ * @param the word (column) `address` corresponds to
+ */
+void get_memory_index(int address, int &line, int &word);
+
#endif /* UTILS_H_INCLUDED */