diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/cache.h | 7 | ||||
-rw-r--r-- | inc/definitions.h | 10 | ||||
-rw-r--r-- | inc/dram.h | 7 | ||||
-rw-r--r-- | inc/response.h | 8 | ||||
-rw-r--r-- | inc/storage.h | 35 |
5 files changed, 44 insertions, 23 deletions
diff --git a/inc/cache.h b/inc/cache.h index 101cd6e..f1fb942 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -8,7 +8,7 @@ class Cache : public Storage /** * Constructor. * @param The number of `lines` contained in memory. The total number of - * words is this number multiplied by 4. + * words is this number multiplied by LINE_SIZE. * @param The next lowest level in storage. Methods from this object are * called in case of a cache miss. * @param The number of clock cycles each access takes. @@ -17,9 +17,8 @@ class Cache : public Storage Cache(int lines, Storage *lower, int delay); ~Cache(); - Response *write(Accessor accessor, signed int data, int address) override; - Response *read(Accessor accessor, int address) override; - int **view(int base, int lines) override; + Response write(Accessor accessor, signed int data, int address) override; + Response read(Accessor accessor, int address) override; }; #endif /* CACHE_H_INCLUDED */ diff --git a/inc/definitions.h b/inc/definitions.h new file mode 100644 index 0000000..1593162 --- /dev/null +++ b/inc/definitions.h @@ -0,0 +1,10 @@ +#ifndef DEFINITIONS_H +#define DEFINITIONS_H + +/** + * Defines common macros. + */ + +#define LINE_SIZE 4 + +#endif /* DEFINITIONS_H_INCLUDED */ @@ -8,16 +8,15 @@ class Dram : public Storage /** * Constructor. * @param The number of `lines` contained in memory. The total number of - * words is this number multiplied by 4. + * words is this number multiplied by LINE_SIZE. * @param The number of clock cycles each access takes. * @return A new memory object. */ Dram(int lines, int delay); ~Dram(); - Response *write(Accessor accessor, signed int data, int address) override; - Response *read(Accessor accessor, int address) override; - int **view(int base, int lines) override; + Response write(Accessor accessor, signed int data, int address) override; + Response read(Accessor accessor, int address) override; }; #endif /* DRAM_H_INCLUDED */ diff --git a/inc/response.h b/inc/response.h index c8141fd..d945e0f 100644 --- a/inc/response.h +++ b/inc/response.h @@ -1,16 +1,10 @@ #ifndef RESPONSE_H #define RESPONSE_H -enum Status { +enum Response { OK, WAIT, BLOCKED, }; -struct Response { - Status status; - int *line; - int val; -}; - #endif /* RESPONSE_H_INCLUDED */ diff --git a/inc/storage.h b/inc/storage.h index 1e512e2..4bf4591 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -1,13 +1,17 @@ #ifndef STORAGE_H #define STORAGE_H +#include "definitions.h" #include "response.h" +#include <algorithm> #include <array> #include <vector> enum Accessor { - MEMORY, + IDLE, + MEM, FETCH, L1CACHE, + SIDE, }; class Storage @@ -18,18 +22,17 @@ class Storage * @param the source making the request. * @param the data (hexadecimal) to write. * @param the address to write to. - * @return a status code reflecting the state of the storage level. + * @return a status code reflecting the state of the request. */ - virtual Response * - write(Accessor accessor, signed int data, int address) = 0; + virtual Response write(Accessor accessor, signed int data, int address) = 0; /** * Get the data at `address`. * @param the source making the request. * @param the address being accessed. - * @return a status code reflecting the state of the storage level, and the + * @return a status code reflecting the state of the request, and the * data being returned. */ - virtual Response *read(Accessor accessor, int address) = 0; + virtual Response read(Accessor accessor, int address) = 0; /** * Sidedoor view of `lines` of memory starting at `base`. * @param The base line to start getting memory from. @@ -37,13 +40,21 @@ class Storage * @return A matrix of data values, where each row is a line and each column * is a word. */ - virtual int **view(int base, int lines) = 0; + std::vector<std::array<signed int, LINE_SIZE>> view(int base, int lines); + /** + * Advances to the next job if the current job is completed. + */ + void resolve(); protected: /** + * Helper for `write`. + */ + void do_write(signed int, int); + /** * The data currently stored in this level of storage. */ - std::vector<std::array<unsigned int, 4>> *data; + std::vector<std::array<signed int, LINE_SIZE>> *data; /** * A pointer to the next lowest level of storage. * Used in case of cache misses. @@ -54,6 +65,14 @@ class Storage * requests. */ int delay; + /** + * The accessor currently being serviced. + */ + enum Accessor requester; + /** + * The number of cycles until the current request is completed. + */ + int wait_time; }; #endif /* STORAGE_H_INCLUDED */ |