summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-30 14:28:45 -0400
committerbd <bdunahu@operationnull.com>2025-03-30 14:28:45 -0400
commit8c46ba4f216aec9f512cd398317f891be9b07e84 (patch)
treecb502366f721c6bca60becc309fd9de288769d87 /src/sim
parent916949133a5797772dcd6966e469c12230ffc3fa (diff)
Add mock stage, proper decode tests
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/controller.cc2
-rw-r--r--src/sim/dum.cc41
-rw-r--r--src/sim/ex.cc2
-rw-r--r--src/sim/id.cc25
-rw-r--r--src/sim/if.cc4
-rw-r--r--src/sim/mm.cc5
-rw-r--r--src/sim/stage.cc23
-rw-r--r--src/sim/wb.cc2
8 files changed, 73 insertions, 31 deletions
diff --git a/src/sim/controller.cc b/src/sim/controller.cc
index 622f1dc..06591af 100644
--- a/src/sim/controller.cc
+++ b/src/sim/controller.cc
@@ -36,3 +36,5 @@ InstrDTO *Controller::advance(Response p)
++this->clock_cycle;
return r;
}
+
+void Controller::advance_helper() {}
diff --git a/src/sim/dum.cc b/src/sim/dum.cc
new file mode 100644
index 0000000..f14c89a
--- /dev/null
+++ b/src/sim/dum.cc
@@ -0,0 +1,41 @@
+#include "dum.h"
+#include "accessor.h"
+#include "instrDTO.h"
+#include "response.h"
+#include "stage.h"
+#include "utils.h"
+
+static Logger *global_log = Logger::getInstance();
+
+DUM::DUM(Stage *stage) : Stage(stage) { this->id = IDLE; }
+
+InstrDTO *DUM::advance(Response p)
+{
+ InstrDTO *r = curr_instr;
+
+ this->advance_helper();
+ if (this->status == OK && p == OK) {
+ this->curr_instr->set_time_of(this->id, this->clock_cycle);
+ r = new InstrDTO(*this->curr_instr);
+ delete curr_instr;
+ curr_instr = nullptr;
+ }
+
+ return r;
+}
+
+void DUM::advance_helper()
+{
+ if (this->curr_instr)
+ global_log->log(
+ DEBUG, string_format(
+ "Using bits: %i ", this->curr_instr->get_instr_bits()));
+ else
+ global_log->log(DEBUG, "curr_instr is null");
+}
+
+void DUM::set_curr_instr(InstrDTO *d)
+{
+ this->curr_instr = d;
+ this->status = OK;
+}
diff --git a/src/sim/ex.cc b/src/sim/ex.cc
index 292337b..50882d2 100644
--- a/src/sim/ex.cc
+++ b/src/sim/ex.cc
@@ -199,4 +199,4 @@ EX::EX(Stage *stage) : Stage(stage)
};
}
-InstrDTO *EX::advance(Response p) { return nullptr; }
+void EX::advance_helper() {}
diff --git a/src/sim/id.cc b/src/sim/id.cc
index 969cb9d..36addbb 100644
--- a/src/sim/id.cc
+++ b/src/sim/id.cc
@@ -8,26 +8,6 @@
ID::ID(Stage *stage) : Stage(stage) { this->id = DCDE; }
-InstrDTO *ID::advance(Response p)
-{
- InstrDTO *r = nullptr;
- Response n;
-
- this->advance_helper();
- if (this->status == OK && p == OK) {
- // mutual consent
- this->curr_instr->set_time_of(this->id, this->clock_cycle);
- r = new InstrDTO(*this->curr_instr);
- delete curr_instr;
- curr_instr = nullptr;
- }
-
- n = (p != OK || this->status != OK) ? BLOCKED : OK;
- // the power of consent
- this->curr_instr = this->next->advance(n);
- return r;
-}
-
void ID::get_instr_fields(
signed int &s1, signed int &s2, signed int &s3, Mnemonic &m)
{
@@ -67,7 +47,7 @@ Response ID::read_guard(signed int &v)
{
Response r;
if (this->is_checked_out(v))
- r = BLOCKED;
+ r = STALLED;
else {
r = OK;
v = this->dereference_register(v);
@@ -116,8 +96,9 @@ void ID::decode_R_type(signed int &s1, signed int &s2, signed int &s3)
r2 = this->read_guard(s2);
this->write_guard(s3);
- this->status = (r1 == BLOCKED || r2 == BLOCKED) ? BLOCKED : OK;
+ this->status = (r1 == OK && r2 == OK) ? OK : STALLED;
}
+
void ID::decode_I_type(signed int &s1, signed int &s2, signed int &s3)
{
unsigned int s0b, s1b, s2b;
diff --git a/src/sim/if.cc b/src/sim/if.cc
index 43132ed..77a2704 100644
--- a/src/sim/if.cc
+++ b/src/sim/if.cc
@@ -18,6 +18,7 @@ InstrDTO *IF::advance(Response p)
r = new InstrDTO(*this->curr_instr);
delete curr_instr;
curr_instr = nullptr;
+ this->status = STALLED;
}
return r;
@@ -34,7 +35,6 @@ void IF::advance_helper()
this->status = r;
this->curr_instr = new InstrDTO();
this->curr_instr->set_instr_bits(bits);
- } else
- this->status = STALLED;
+ }
}
}
diff --git a/src/sim/mm.cc b/src/sim/mm.cc
index 5bc5836..2b73207 100644
--- a/src/sim/mm.cc
+++ b/src/sim/mm.cc
@@ -6,7 +6,4 @@
MM::MM(Stage *stage) : Stage(stage) { this->id = MEM; }
-InstrDTO *MM::advance(Response p)
-{
- return nullptr;
-}
+void MM::advance_helper() {}
diff --git a/src/sim/stage.cc b/src/sim/stage.cc
index d8c882a..929a4b9 100644
--- a/src/sim/stage.cc
+++ b/src/sim/stage.cc
@@ -7,7 +7,7 @@ Stage::Stage(Stage *next)
{
this->next = next;
this->curr_instr = nullptr;
- this->status = OK;
+ this->status = STALLED;
this->checked_out = {};
}
@@ -21,6 +21,27 @@ Storage *Stage::storage;
bool Stage::is_pipelined;
int Stage::clock_cycle;
+InstrDTO *Stage::advance(Response p)
+{
+ InstrDTO *r = nullptr;
+ Response n;
+
+ this->advance_helper();
+ if (this->status == OK && p == OK) {
+ // mutual consent
+ this->curr_instr->set_time_of(this->id, this->clock_cycle);
+ r = new InstrDTO(*this->curr_instr);
+ delete curr_instr;
+ curr_instr = nullptr;
+ this->status = STALLED;
+ }
+
+ n = (p != OK || this->status != OK) ? STALLED : OK;
+ // the power of consent
+ this->curr_instr = this->next->advance(n);
+ return r;
+}
+
void Stage::set_condition(CC c, bool v)
{
if (v)
diff --git a/src/sim/wb.cc b/src/sim/wb.cc
index 7a8d64c..9337aa0 100644
--- a/src/sim/wb.cc
+++ b/src/sim/wb.cc
@@ -6,4 +6,4 @@
WB::WB(Stage *stage) : Stage(stage) { this->id = WRITE; }
-InstrDTO *WB::advance(Response p) { return nullptr; }
+void WB::advance_helper() {}