summaryrefslogtreecommitdiff
path: root/src/sim/stage.cc
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-29 22:14:42 -0400
committerGitHub <noreply@github.com>2025-03-29 22:14:42 -0400
commitd20623d031cf909d8892c2db38cf2e2e02bc6a9b (patch)
tree56ef4ae4325a5b803c484a3e5c8d87b89572cedf /src/sim/stage.cc
parentcaeff52f029920e027d18bc01149425560801f82 (diff)
parent1250c3765f59801d060152d5f6eed0a9faa11b50 (diff)
Merge pull request #37 from bdunahu/bdunahu
Instr, InstrDTO gets/sets, other structures required for decode -- tests as we move forward -- base classes -- decode stage implemented
Diffstat (limited to 'src/sim/stage.cc')
-rw-r--r--src/sim/stage.cc36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/sim/stage.cc b/src/sim/stage.cc
index 0d48774..62a7fd6 100644
--- a/src/sim/stage.cc
+++ b/src/sim/stage.cc
@@ -1,11 +1,43 @@
#include "stage.h"
+#include "utils.h"
+#include <array>
+#include <deque>
-Stage::Stage(Stage *next) {
+Stage::Stage(Stage *next)
+{
this->next = next;
+ this->curr_instr = nullptr;
+ this->status = OK;
+ this->checked_out = {};
}
+Stage::~Stage() { delete this->next; };
+
std::array<int, GPR_NUM> Stage::gprs;
-int Stage::pc;
+std::array<int, V_NUM> Stage::vrs;
+std::deque<signed int> Stage::checked_out;
+unsigned int Stage::pc;
Storage *Stage::storage;
bool Stage::is_pipelined;
int Stage::clock_cycle;
+
+signed int Stage::dereference_register(signed int v)
+{
+ signed int r;
+
+ if (v < 0 || v >= GPR_NUM + V_NUM) {
+ throw std::out_of_range(string_format(
+ "instruction tried to access register %d, which does "
+ "not exist",
+ v));
+ }
+
+ r = (v >= GPR_NUM) ? this->vrs[v % GPR_NUM] : this->gprs[v];
+ return r;
+}
+
+bool Stage::is_checked_out(signed int r)
+{
+ return std::find(this->checked_out.begin(), this->checked_out.end(), r) !=
+ this->checked_out.end();
+}