diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/accessor.h | 18 | ||||
-rw-r--r-- | inc/cache.h | 55 | ||||
-rw-r--r-- | inc/cli.h | 97 | ||||
-rw-r--r-- | inc/definitions.h | 1 | ||||
-rw-r--r-- | inc/dram.h | 47 | ||||
-rw-r--r-- | inc/logger.h | 42 | ||||
-rw-r--r-- | inc/response.h | 14 | ||||
-rw-r--r-- | inc/storage.h | 58 |
8 files changed, 67 insertions, 265 deletions
diff --git a/inc/accessor.h b/inc/accessor.h deleted file mode 100644 index eb56785..0000000 --- a/inc/accessor.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ACCESSOR_H -#define ACCESSOR_H -#include <iostream> - -enum Accessor { - IDLE, - WRITE, - MEM, - EXEC, - DCDE, - FETCH, - L1CACHE, - SIDE, -}; - -std::ostream &operator<<(std::ostream &os, Accessor a); - -#endif /* ACCESSOR_H_INCLUDED */ diff --git a/inc/cache.h b/inc/cache.h index 88fd352..0f15536 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -3,8 +3,8 @@ #include "definitions.h" #include "storage.h" #include <array> -#include <ostream> #include <functional> +#include <ostream> class Cache : public Storage { @@ -21,55 +21,52 @@ class Cache : public Storage Cache(Storage *lower, int delay); ~Cache(); - Response - write_word(Accessor accessor, signed int data, int address) override; - Response write_line( - Accessor accessor, - std::array<signed int, LINE_SIZE> data_line, - int address) override; - Response read_line( - Accessor accessor, - int address, - std::array<signed int, LINE_SIZE> &data_line) override; - Response - read_word(Accessor accessor, int address, signed int &data) override; + int + write_word(void *, signed int, int) override; + int + write_line(void *, std::array<signed int, LINE_SIZE>, int) override; + int + read_line(void *, int, std::array<signed int, LINE_SIZE> &) override; + int + read_word(void *, int, signed int &) override; /** * Getter for the meta attribute. * TODO this doesn't seem like good object-oriented practice. * @return this->meta */ - std::array<std::array<int, 2>, L1_CACHE_LINES> get_meta() const; + std::array<std::array<int, 2>, L1_CACHE_LINES> + get_meta() const; private: /** * Helper for all access methods. - * Calls `request_handler` when `accessor` is allowed to complete its + * Calls `request_handler` when `id` 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); + int + process(void *id, 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 + * Returns OK if `id` is allowed to complete its request this cycle. + * Handles cache misses, wait times, and setting the current id this * storage is serving. - * @param the accessor asking for a resource - * @return whether or not the access can be carried out this function call. + * @param the id asking for a resource + * @return 1 if the access can be carried out this function call, 0 otherwise. */ - Response is_access_cleared(Accessor accessor, int address); + int + is_access_cleared(void *id, int address); /** - * Helper for access_cleared. + * Helper for is_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. + * present. The victim line is chosen/written back. * @param the address that must be present in cache. + * @param 0 if the address is currently in cache, 1 if it is being fetched. */ - void handle_miss(int address); + int + is_address_missing(int address); /** * An array of metadata about elements in `data`. * If the first value of an element is negative, the corresponding @@ -79,6 +76,4 @@ class Cache : public Storage std::array<std::array<int, 2>, L1_CACHE_LINES> meta; }; -std::ostream &operator<<(std::ostream &os, const Cache &c); - #endif /* CACHE_H_INCLUDED */ diff --git a/inc/cli.h b/inc/cli.h deleted file mode 100644 index a0c698a..0000000 --- a/inc/cli.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef CLI_H -#define CLI_H -#include "cache.h" -#include <functional> -#include <string> -#include <unordered_map> - -class Cli -{ - public: - /** - * Constructor. - * @return A newly allocated CLI object. - */ - Cli(); - ~Cli(); - - /** - * Prints all available commands to the console. - */ - void help(); - - /** - * Loads data from memory from the specified memory address. - * @param memory_address address of the memory where data needs to be loaded - * from - */ - void load(Accessor accessor, int memory_address); - - /** - * Stores data into memory at the specified address. - * @param accessor the pipline stage that is making this request - * @param data data value to be written to the memory - * @param address address of the memory where data needs to be stored - * @return the response from the storage device - */ - void store(Accessor accessor, int data, int address); - - /** - * Resets the memory configuration and cycles to their initial state. - * This function provides a side door reset interface to the memory system, - * allowing the user to reset the memory configuration directly. - */ - void reset(); - - /** - * Advance the clock one cycle, refreshing the storage devices. - */ - void clock(); - - /** - * Displays `lines` lines of the data in `level`, starting from `base`. - * - * - * This function provides a side door view into the storage system, showing - * its current state and configuration. - * @param level the level specifying the storage device. The first level - * one cache is level zero, with descending levels incrementing by a factor - * of one. - */ - void peek(int level); - - /** - * Runs the command line interface - * This function is the main entry point for the command line interface. - */ - void run(); - - private: - /** - * Initializes the cache object. - */ - void initialize(); - /** - * Attempts to match string to either fetch or mem, or throws - * std::invalid_argument otherwise. - * @param the string to be converted accessor - * @return the corresponding accessor - * @throws invalid_argument if the string is not fetch or mem - */ - Accessor match_accessor_or_die(std::string s); - /** Map of commands and their corresponding functions. - * This map is used to store the commands and their corresponding functions. - */ - std::unordered_map<char, std::function<void(std::vector<std::string>)>> - commands; - /** - * The cache object to interface with. - */ - Cache *cache; - /** - * The current cycle. - */ - int cycle; -}; - -#endif /* CLI_H_INCLUDED */ diff --git a/inc/definitions.h b/inc/definitions.h index c81c4e3..6fa29ee 100644 --- a/inc/definitions.h +++ b/inc/definitions.h @@ -1,6 +1,5 @@ #ifndef DEFINITIONS_H #define DEFINITIONS_H -#include "logger.h" #include <cmath> /** @@ -2,8 +2,8 @@ #define DRAM_H #include "definitions.h" #include "storage.h" -#include <ostream> #include <functional> +#include <ostream> class Dram : public Storage { @@ -16,47 +16,42 @@ class Dram : public Storage Dram(int delay); ~Dram(); - Response - write_word(Accessor accessor, signed int data, int address) override; - Response read_line( - Accessor accessor, - int address, - std::array<signed int, LINE_SIZE> &data_line) override; - Response write_line( - Accessor accessor, - std::array<signed int, LINE_SIZE> data_line, - int address) override; - Response - read_word(Accessor accessor, int address, signed int &data) override; + int + write_word(void *, signed int, int) override; + int + write_line(void *, std::array<signed int, LINE_SIZE>, int) override; + int + read_word(void *, int, signed int &) override; + int + read_line(void *, int, std::array<signed int, LINE_SIZE> &) override; /** * TODO This will accept a file at a later date. */ - void load(std::vector<signed int> program); + void + load(std::vector<signed int> program); private: /** * Helper for all access methods. - * Calls `request_handler` when `accessor` is allowed to complete its + * Calls `request_handler` when `id` 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 + * @return 1 if the access completed successfully, 0 otherwise */ - Response process( - Accessor accessor, - int address, - std::function<void(int line, int word)> request_handler); + int + process(void *id, int address, std::function<void(int line, int word)> request_handler); /** - * Returns OK if `accessor` is allowed to complete its request this cycle. - * Handles wait times, side door, and setting the current accessor this + * Returns OK if `id` is allowed to complete its request this cycle. + * Handles wait times, side door, and setting the current id this * storage is serving. - * @param the accessor asking for a resource - * @return whether or not the access can be carried out this function call. + * @param the source making the request + * @return 1 if the access can be completed this function call, 0 otherwise */ - Response is_access_cleared(Accessor accessor); + int + is_access_cleared(void *id); }; -std::ostream &operator<<(std::ostream &os, const Dram &d); - #endif /* DRAM_H_INCLUDED */ diff --git a/inc/logger.h b/inc/logger.h deleted file mode 100644 index 88f9e30..0000000 --- a/inc/logger.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef LOGGER_H -#define LOGGER_H -#include <fstream> -#include <sstream> -using namespace std; - -enum LogLevel { DEBUG, INFO, WARNING, ERROR, CRITICAL }; - -class Logger -{ - public: - static Logger* getInstance(); - - ~Logger() = default; - - /** - * Do not allow copies. - */ - Logger(const Logger& obj) = delete; - - /** - * 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: - Logger() = default; - static Logger* logger_instance; - static LogLevel level; - static string level_to_string(LogLevel); - static int level_to_int(LogLevel); -}; - -#endif /* LOGGER_H_INCLUDED */ diff --git a/inc/response.h b/inc/response.h deleted file mode 100644 index 05e9352..0000000 --- a/inc/response.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef RESPONSE_H -#define RESPONSE_H -#include <iostream> - -enum Response { - OK, - WAIT, - BLOCKED, - STALLED, -}; - -std::ostream &operator<<(std::ostream &os, Response r); - -#endif /* RESPONSE_H_INCLUDED */ diff --git a/inc/storage.h b/inc/storage.h index d6fa094..81194da 100644 --- a/inc/storage.h +++ b/inc/storage.h @@ -1,8 +1,6 @@ #ifndef STORAGE_H #define STORAGE_H -#include "accessor.h" #include "definitions.h" -#include "response.h" #include <algorithm> #include <array> #include <map> @@ -11,6 +9,12 @@ class Storage { public: + /** + * Constructor. + * @param The time an access to this storage device takes. + * @return A newly allocated storage object. + */ + Storage(int delay); virtual ~Storage() = default; /** @@ -18,34 +22,26 @@ 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 request. - */ - virtual Response write_word(Accessor accessor, signed int data, int address) = 0; - - /** - * Write a data line to given address in this level of storage + * @return 1 if the request was completed, 0 otherwise. */ - virtual Response write_line(Accessor accessor, std::array<signed int, LINE_SIZE> data_line, int address) = 0; + virtual int + write_word(void *id, signed int data, int address) = 0; + virtual int + write_line(void *id, std::array<signed int, LINE_SIZE> data_line, int address) = 0; - /** * Get the data line at `address`. * @param the source making the request. * @param the address being accessed. - * @return a status code reflecting the state of the request, and the - * data being returned. + * @param the data being returned + * @return 1 if the request was completed, 0 otherwise */ - virtual Response read_line( - Accessor accessor, - int address, - std::array<signed int, LINE_SIZE> &data) = 0; + virtual int + read_line(void *id, int address, std::array<signed int, LINE_SIZE> &data) = 0; + virtual int + read_word(void *id, int address, signed int &data) = 0; /** - * Read a word from given address in this level of storage - */ - virtual Response read_word(Accessor accessor, int address, signed int &data) = 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. @@ -55,13 +51,6 @@ class Storage std::vector<std::array<signed int, LINE_SIZE>> view(int base, int lines) const; - /** - * Getter for lower attribute. - * TODO this doesn't seem like good object-oriented practice. - * @return this->lower - */ - Storage *get_lower(); - protected: /** * The data currently stored in this level of storage. @@ -73,23 +62,18 @@ class Storage */ Storage *lower; /** + * The id currently being serviced. + */ + void *current_request; + /** * The number of clock cycles this level of storage takes to complete * requests. */ int delay; /** - * The accessor currently being serviced. - */ - Accessor requester; - /** * The number of cycles until the current request is completed. */ int wait_time; - /** - * A flag indicating whether this level of storage is currently waiting for - * a lower level. - */ - int is_waiting; }; #endif /* STORAGE_H_INCLUDED */ |