summaryrefslogtreecommitdiff
path: root/src/sim/controller.cc
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-26 22:05:46 -0400
committerGitHub <noreply@github.com>2025-03-26 22:05:46 -0400
commit7abc8926670c1701db8011cacc9c5e2e2ca95be8 (patch)
treefd3263d2754d662fdad6d69851f14a84f44db4d1 /src/sim/controller.cc
parent9eeea1ab8bf4eb17e5da46d57a6c1d455a0a262e (diff)
parent8d37d15ebd1221e3b1698abb3b051d9d0c044c93 (diff)
Merge pull request #36 from bdunahu/bdunahu
Add fetch stage implementation, tests, program loading, DTO object Base classes plus base tests for Instruction Fetch stage with a default program
Diffstat (limited to 'src/sim/controller.cc')
-rw-r--r--src/sim/controller.cc29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/sim/controller.cc b/src/sim/controller.cc
index 93fd0e0..6d46dc4 100644
--- a/src/sim/controller.cc
+++ b/src/sim/controller.cc
@@ -1,34 +1,23 @@
#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)
+Controller::Controller(Stage *stage, Storage *storage, bool is_pipelined)
+ : Stage(stage)
{
- this->clock_cycle = 0;
+ this->clock_cycle = 1;
this->storage = storage;
this->is_pipelined = is_pipelined;
this->pc = 0x0;
this->gprs = {0};
-
- 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;
}
void Controller::run_for(int number)
{
+ InstrDTO instr;
int i;
for (i = 0; i < number; ++i) {
- this->advance();
+ this->advance(instr);
}
}
@@ -38,9 +27,11 @@ std::array<int, GPR_NUM> Controller::get_gprs() { return this->gprs; }
int Controller::get_pc() { return this->pc; }
-Response Controller::advance()
+Response Controller::advance(InstrDTO &i)
{
- this->next->advance();
+ Response r;
+
+ r = this->next->advance(i);
++this->clock_cycle;
- return OK;
+ return r;
}