diff options
author | bd <bdunahu@operationnull.com> | 2025-03-24 14:41:13 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-24 14:41:13 -0400 |
commit | 9a0b9ed3d77bde99b1f1ba341850117c188f0156 (patch) | |
tree | e8546d59859b3723744e901b51e5448f2b190d7f | |
parent | 877aa98855fad77ef93a8c9f5a5e8191fbb9e699 (diff) |
Add skeleton classes for 5 major pipeline stages
-rw-r--r-- | inc/controller.h | 8 | ||||
-rw-r--r-- | inc/ex.h | 14 | ||||
-rw-r--r-- | inc/id.h | 14 | ||||
-rw-r--r-- | inc/if.h | 14 | ||||
-rw-r--r-- | inc/mm.h | 14 | ||||
-rw-r--r-- | inc/stage.h | 8 | ||||
-rw-r--r-- | inc/wb.h | 14 | ||||
-rw-r--r-- | src/sim/controller.cc | 28 | ||||
-rw-r--r-- | src/sim/ex.cc | 11 | ||||
-rw-r--r-- | src/sim/id.cc | 11 | ||||
-rw-r--r-- | src/sim/if.cc | 15 | ||||
-rw-r--r-- | src/sim/mm.cc | 11 | ||||
-rw-r--r-- | src/sim/stage.cc | 4 | ||||
-rw-r--r-- | src/sim/wb.cc | 11 |
14 files changed, 161 insertions, 16 deletions
diff --git a/inc/controller.h b/inc/controller.h index 0cafe10..56f3836 100644 --- a/inc/controller.h +++ b/inc/controller.h @@ -1,5 +1,6 @@ #ifndef CONTROLLER_H #define CONTROLLER_H +#include "response.h" #include "stage.h" /** @@ -15,7 +16,6 @@ class Controller : public Stage * @return A newly allocated controller object. */ Controller(Storage *storage, bool is_pipelined); - ~Controller(); /** * Direct the simulator to run for `number` clock cycles. @@ -34,14 +34,10 @@ class Controller : public Stage * @return the pc. */ int get_pc(); + Response advance(); private: /** - * Helper for run_for. - * Advances the simulation by a single cycle. - */ - void advance(); - /** * The current clock cycle. */ int clock_cycle; diff --git a/inc/ex.h b/inc/ex.h new file mode 100644 index 0000000..c560eda --- /dev/null +++ b/inc/ex.h @@ -0,0 +1,14 @@ +#ifndef EX_H +#define EX_H +#include "response.h" +#include "stage.h" + +class EX : public Stage +{ + public: + using Stage::Stage; + + Response advance(); +}; + +#endif /* EX_H_INCLUDED */ diff --git a/inc/id.h b/inc/id.h new file mode 100644 index 0000000..dcfda82 --- /dev/null +++ b/inc/id.h @@ -0,0 +1,14 @@ +#ifndef ID_H +#define ID_H +#include "response.h" +#include "stage.h" + +class ID : public Stage +{ + public: + using Stage::Stage; + + Response advance(); +}; + +#endif /* ID_D_INCLUDED */ diff --git a/inc/if.h b/inc/if.h new file mode 100644 index 0000000..d9599dd --- /dev/null +++ b/inc/if.h @@ -0,0 +1,14 @@ +#ifndef IF_H +#define IF_H +#include "response.h" +#include "stage.h" + +class IF : public Stage +{ + public: + using Stage::Stage; + + Response advance(); +}; + +#endif /* IF_H_INCLUDED */ diff --git a/inc/mm.h b/inc/mm.h new file mode 100644 index 0000000..e9d04d5 --- /dev/null +++ b/inc/mm.h @@ -0,0 +1,14 @@ +#ifndef MM_H +#define MM_H +#include "response.h" +#include "stage.h" + +class MM : public Stage +{ + public: + using Stage::Stage; + + Response advance(); +}; + +#endif /* MM_H_INCLUDED */ diff --git a/inc/stage.h b/inc/stage.h index 769818c..494f3d3 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -1,13 +1,21 @@ #ifndef STAGE_H #define STAGE_H #include "definitions.h" +#include "response.h" #include "storage.h" #include <array> class Stage { public: + Stage(Stage *next); virtual ~Stage() = default; + /** + * Advances this stage by a single clock cycle. + * @return a response, indicating whether this pipeline stage is stalled, + * busy, or done. + */ + virtual Response advance() = 0; protected: /** diff --git a/inc/wb.h b/inc/wb.h new file mode 100644 index 0000000..031bf20 --- /dev/null +++ b/inc/wb.h @@ -0,0 +1,14 @@ +#ifndef WB_H +#define WB_H +#include "response.h" +#include "stage.h" + +class WB : public Stage +{ + public: + using Stage::Stage; + + Response advance(); +}; + +#endif /* WB_H_INCLUDED */ diff --git a/src/sim/controller.cc b/src/sim/controller.cc index 8d48dc9..93fd0e0 100644 --- a/src/sim/controller.cc +++ b/src/sim/controller.cc @@ -1,7 +1,14 @@ #include "controller.h" +#include "ex.h" +#include "id.h" +#include "if.h" +#include "mm.h" +#include "response.h" #include "storage.h" +#include "wb.h" Controller::Controller(Storage *storage, bool is_pipelined) + : Stage(nullptr) { this->clock_cycle = 0; this->storage = storage; @@ -9,12 +16,14 @@ Controller::Controller(Storage *storage, bool is_pipelined) this->pc = 0x0; this->gprs = {0}; - // setup the other pipeline stages - this->next = nullptr; + IF *f = new IF(nullptr); + ID *d = new ID(f); + EX *e = new EX(d); + MM *m = new MM(e); + WB *w = new WB(m); + this->next = w; } -Controller::~Controller() { ; } - void Controller::run_for(int number) { int i; @@ -25,14 +34,13 @@ void Controller::run_for(int number) int Controller::get_clock_cycle() { return this->clock_cycle; } -std::array<int, GPR_NUM> Controller::get_gprs() { - return this->gprs; -} +std::array<int, GPR_NUM> Controller::get_gprs() { return this->gprs; } int Controller::get_pc() { return this->pc; } -void Controller::advance() { - ; - // this->next->advance() +Response Controller::advance() +{ + this->next->advance(); ++this->clock_cycle; + return OK; } diff --git a/src/sim/ex.cc b/src/sim/ex.cc new file mode 100644 index 0000000..f286713 --- /dev/null +++ b/src/sim/ex.cc @@ -0,0 +1,11 @@ +#include "ex.h" +#include "logger.h" +#include "response.h" + +static Logger *global_log = Logger::getInstance(); + +Response EX::advance() +{ + global_log->log(INFO, "hello from execute!"); + return OK; +} diff --git a/src/sim/id.cc b/src/sim/id.cc new file mode 100644 index 0000000..56d9549 --- /dev/null +++ b/src/sim/id.cc @@ -0,0 +1,11 @@ +#include "id.h" +#include "logger.h" +#include "response.h" + +static Logger *global_log = Logger::getInstance(); + +Response ID::advance() +{ + global_log->log(INFO, "hello from decode!"); + return OK; +} diff --git a/src/sim/if.cc b/src/sim/if.cc new file mode 100644 index 0000000..1026072 --- /dev/null +++ b/src/sim/if.cc @@ -0,0 +1,15 @@ +#include "if.h" +#include "logger.h" +#include "response.h" + +static Logger *global_log = Logger::getInstance(); + +Response IF::advance() +{ + global_log->log(INFO, "hello from fetch!"); + return OK; +} + + + + diff --git a/src/sim/mm.cc b/src/sim/mm.cc new file mode 100644 index 0000000..be774ad --- /dev/null +++ b/src/sim/mm.cc @@ -0,0 +1,11 @@ +#include "mm.h" +#include "logger.h" +#include "response.h" + +static Logger *global_log = Logger::getInstance(); + +Response MM::advance() +{ + global_log->log(INFO, "hello from memory!"); + return OK; +} diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 7d3a678..399743a 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -1,5 +1,9 @@ #include "stage.h" +Stage::Stage(Stage *next) { + this->next = next; +} + std::array<int, GPR_NUM> Stage::gprs; int Stage::pc; Storage *Stage::storage; diff --git a/src/sim/wb.cc b/src/sim/wb.cc new file mode 100644 index 0000000..83b1c3c --- /dev/null +++ b/src/sim/wb.cc @@ -0,0 +1,11 @@ +#include "wb.h" +#include "logger.h" +#include "response.h" + +static Logger *global_log = Logger::getInstance(); + +Response WB::advance() +{ + global_log->log(INFO, "hello from write back!"); + return OK; +} |