diff options
author | bd <bdunahu@operationnull.com> | 2025-03-05 14:17:45 -0500 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-05 14:17:45 -0500 |
commit | db158de830e4fd4ab20ef5d357e24147c7a9281d (patch) | |
tree | a00ae7890a5b8eba91f81ac84d20a5ee0c5be0d6 /inc | |
parent | b4d1e8248400015f2fd0c4b0f04cf33dc867e9cd (diff) |
constructors + method declarations for cache, dram, reponse, storage
Diffstat (limited to 'inc')
-rw-r--r-- | inc/cache.h | 25 | ||||
-rw-r--r-- | inc/dram.h | 17 | ||||
-rw-r--r-- | inc/logger.h | 31 | ||||
-rw-r--r-- | inc/response.h | 16 | ||||
-rw-r--r-- | inc/storage.h | 50 |
5 files changed, 123 insertions, 16 deletions
diff --git a/inc/cache.h b/inc/cache.h new file mode 100644 index 0000000..e808727 --- /dev/null +++ b/inc/cache.h @@ -0,0 +1,25 @@ +#ifndef CACHE_H +#define CACHE_H +#include <storage.h> + +class Cache : public Storage +{ + public: + /** + * Constructor. + * @param The number of `lines` contained in memory. The total number of + * words is this number multiplied by 4. + * @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. + * @return A new cache object. + */ + 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; +}; + +#endif /* CACHE_H_INCLUDED */ @@ -5,12 +5,19 @@ class Dram : public Storage { public: - Dram(); - ~Dram(); + /** + * Constructor. + * @param The number of `lines` contained in memory. The total number of + * words is this number multiplied by 4. + * @param The number of clock cycles each access takes. + * @return A new memory object. + */ + Dram(int lines, int delay); + ~Dram(); - int *load_line(int); - - private: + Response *write(Accessor accessor, signed int data, int address) override; + Response *read(Accessor accessor, int address) override; + int **view(int base, int lines) override; }; #endif /* DRAM_H_INCLUDED */ diff --git a/inc/logger.h b/inc/logger.h index 5ecdc7e..005e518 100644 --- a/inc/logger.h +++ b/inc/logger.h @@ -9,17 +9,32 @@ enum LogLevel { DEBUG, INFO, WARNING, ERROR, CRITICAL }; class Logger { public: - Logger(const string &); - ~Logger(); + /** + * Constructor. + * @param The file name to log to. + * @return A new logger object. + */ + Logger(const string &); + ~Logger(); - void setLevel(LogLevel); - void log(LogLevel, const string &); + /** + * Set the log level. + * @param the log level to set to. + */ + void setLevel(LogLevel); + /** + * Log a message at a certain log level. + * @param The level to log this message. If the level is lower than the + * level set by `setLevel`, then the message is not logged. + * @param The message to log. + */ + void log(LogLevel, const string &); private: - LogLevel level = INFO; - ofstream logFile; - string levelToString(LogLevel); - int levelToInt(LogLevel); + LogLevel level = INFO; + ofstream logFile; + string levelToString(LogLevel); + int levelToInt(LogLevel); }; #endif /* LOGGER_H_INCLUDED */ diff --git a/inc/response.h b/inc/response.h new file mode 100644 index 0000000..d190953 --- /dev/null +++ b/inc/response.h @@ -0,0 +1,16 @@ +#ifndef RESPONSE_H +#define RESPONSE_H + +enum Status { + 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 8973016..bad9d10 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -1,15 +1,59 @@ #ifndef STORAGE_H #define STORAGE_H +#include "response.h" #include <array> #include <vector> +enum Accessor { + MEMORY, + FETCH, + L1CACHE, +}; + class Storage { public: - int **view(int base) { return nullptr; } - virtual bool store(); + /** + * Write `data` into `address`. + * @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. + */ + 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 + * data being returned. + */ + 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. + * @param The amount of lines to fetch. + * @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, 4>> address_space; + protected: + /** + * The data currently stored in this level of storage. + */ + std::vector<std::array<unsigned int, 4>> *data; + /** + * A pointer to the next lowest level of storage. + * Used in case of cache misses. + */ + Storage *lower; + /** + * The number of clock cycles this level of storage takes to complete + * requests. + */ + int delay; }; #endif /* STORAGE_H_INCLUDED */ |