diff options
author | bd <bdunahu@operationnull.com> | 2025-03-29 12:30:54 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-29 12:30:54 -0400 |
commit | 9793bf119cc6314e264bdfc9e98bc27c81db0adb (patch) | |
tree | 2c8159f9b9ae655cc810e705834a45938a63c624 /src/sim/stage.cc | |
parent | bc47d9131869b1f072e21d9cb61746d14bf30751 (diff) |
Add implementation functions for checking out a register.
Diffstat (limited to 'src/sim/stage.cc')
-rw-r--r-- | src/sim/stage.cc | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 560cc41..8d9dfc0 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -1,12 +1,59 @@ #include "stage.h" +#include "utils.h" +#include <array> +#include <set> -Stage::Stage(Stage *next) { - this->next = next; -} +static Logger *global_log = Logger::getInstance(); + +Stage::Stage(Stage *next) { this->next = next; } std::array<int, GPR_NUM> Stage::gprs; std::array<int, V_NUM> Stage::vrs; +std::set<unsigned int> Stage::checked_out; unsigned int Stage::pc; Storage *Stage::storage; bool Stage::is_pipelined; int Stage::clock_cycle; + +Response Stage::check_out(unsigned int &v) +{ + Response r; + if (this->is_checked_out(v)) + r = STALLED; + else { + r = OK; + v = this->check_out_register(v); + } + return r; +} + +bool Stage::is_checked_out(unsigned int r) +{ + return this->checked_out.find(r) != this->checked_out.end(); +} + +signed int Stage::check_out_register(unsigned int v) +{ + signed int r; + this->checked_out.insert(v); + + r = this->dereference_register(v); + return r; +} + +signed int Stage::dereference_register(unsigned int v) +{ + signed int r; + + if (v >= GPR_NUM + V_NUM) { + global_log->log( + ERROR, string_format( + "instruction tried to access register %d, which does " + "not exist", + v)); + exit(EXIT_FAILURE); + } + + r = (v >= GPR_NUM) ? this->vrs[v % GPR_NUM] : this->gprs[v]; + return r; +} |