summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/cache.h84
-rw-r--r--inc/cli.h97
-rw-r--r--inc/dram.h62
-rw-r--r--inc/pipe_spec.h (renamed from inc/definitions.h)38
-rw-r--r--inc/stage.h2
-rw-r--r--inc/storage.h95
-rw-r--r--inc/utils.h39
7 files changed, 3 insertions, 414 deletions
diff --git a/inc/cache.h b/inc/cache.h
deleted file mode 100644
index 88fd352..0000000
--- a/inc/cache.h
+++ /dev/null
@@ -1,84 +0,0 @@
-#ifndef CACHE_H
-#define CACHE_H
-#include "definitions.h"
-#include "storage.h"
-#include <array>
-#include <ostream>
-#include <functional>
-
-class Cache : public Storage
-{
- public:
- /**
- * Constructor.
- * @param The number of `lines` contained in memory. The total number of
- * 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.
- * @return A new cache object.
- */
- 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;
-
- /**
- * 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;
-
- 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.
- * @param the address that must be present in cache.
- */
- void handle_miss(int address);
- /**
- * An array of metadata about elements in `data`.
- * If the first value of an element is negative, the corresponding
- * element in `data` is invalid. If the most second value of an element
- * is nonzero, the corresponding element in `data` is dirty.
- */
- 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/dram.h b/inc/dram.h
deleted file mode 100644
index 102ec0f..0000000
--- a/inc/dram.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef DRAM_H
-#define DRAM_H
-#include "definitions.h"
-#include "storage.h"
-#include <ostream>
-#include <functional>
-
-class Dram : public Storage
-{
- public:
- /**
- * Constructor.
- * @param The number of clock cycles each access takes.
- * @return A new memory object.
- */
- 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;
-
- /**
- * TODO This will accept a file at a later date.
- */
- void load(std::vector<signed int> program);
-
- 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 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
- * 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);
-};
-
-std::ostream &operator<<(std::ostream &os, const Dram &d);
-
-#endif /* DRAM_H_INCLUDED */
diff --git a/inc/definitions.h b/inc/pipe_spec.h
index c81c4e3..772314e 100644
--- a/inc/definitions.h
+++ b/inc/pipe_spec.h
@@ -1,5 +1,5 @@
-#ifndef DEFINITIONS_H
-#define DEFINITIONS_H
+#ifndef PIPE_SPEC_H
+#define PIPE_SPEC_H
#include "logger.h"
#include <cmath>
@@ -11,40 +11,6 @@
* The total number of words in a line
*/
#define LINE_SIZE static_cast<int>(pow(2, 2))
-/**
- * Number of bits in a word
- */
-#define WORD_SPEC 32
-
-/**
- * The number of bits to specify a memory word
- * The number of bits to specify a memory line
- * The total number of lines in memory
- */
-#define MEM_WORD_SPEC 10
-#define MEM_LINE_SPEC static_cast<unsigned int>(MEM_WORD_SPEC - LINE_SPEC)
-#define MEM_WORDS static_cast<int>(pow(2, MEM_WORD_SPEC))
-#define MEM_LINES static_cast<int>(pow(2, MEM_LINE_SPEC))
-
-/**
- * The number of bits to specify a l1 cache word
- * The number of bits to specify a l1 cache line
- * The total number of lines in l1 cache
- */
-#define L1_CACHE_WORD_SPEC 7
-#define L1_CACHE_LINE_SPEC \
- static_cast<unsigned int>(L1_CACHE_WORD_SPEC - LINE_SPEC)
-#define L1_CACHE_LINES static_cast<int>(pow(2, L1_CACHE_LINE_SPEC))
-
-/**
- * The total number of cycles a memory access takes
- */
-#define MEM_DELAY 3
-
-/**
- * The total number of cycles a level one cache access takes
- */
-#define L1_CACHE_DELAY 0
/**
* The number of general purpose registers
diff --git a/inc/stage.h b/inc/stage.h
index 51ab667..da33075 100644
--- a/inc/stage.h
+++ b/inc/stage.h
@@ -1,8 +1,8 @@
#ifndef STAGE_H
#define STAGE_H
#include "accessor.h"
-#include "definitions.h"
#include "instrDTO.h"
+#include "pipe_spec.h"
#include "response.h"
#include "storage.h"
#include <array>
diff --git a/inc/storage.h b/inc/storage.h
deleted file mode 100644
index d6fa094..0000000
--- a/inc/storage.h
+++ /dev/null
@@ -1,95 +0,0 @@
-#ifndef STORAGE_H
-#define STORAGE_H
-#include "accessor.h"
-#include "definitions.h"
-#include "response.h"
-#include <algorithm>
-#include <array>
-#include <map>
-#include <vector>
-
-class Storage
-{
- public:
- virtual ~Storage() = default;
-
- /**
- * Write `data` word 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 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
- */
- virtual Response write_line(Accessor accessor, 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.
- */
- virtual Response read_line(
- Accessor accessor,
- int address,
- std::array<signed int, LINE_SIZE> &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.
- * @return A matrix of data values, where each row is a line and each column
- * is a word.
- */
- 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.
- */
- std::vector<std::array<signed int, LINE_SIZE>> *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;
- /**
- * 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 */
diff --git a/inc/utils.h b/inc/utils.h
deleted file mode 100644
index a375b68..0000000
--- a/inc/utils.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef UTILS_H
-#define UTILS_H
-#include <string>
-
-/**
- * Parse an address into a tag, index into the cache table, and a line
- * offset.
- * @param the address to be parsed
- * @param the resulting tag
- * @param the resulting index
- * @param the resulting offset
- */
-void get_cache_fields(int address, int *tag, int *index, int *offset);
-
-/**
- * Formats a string using snprintf.
- * @param an object that represents the format string
- * @param arguments to be formatted
- * @return a string object holding the formatted result
- */
-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 */