summaryrefslogtreecommitdiff
path: root/src/sim/wb.cc
diff options
context:
space:
mode:
authorSiddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com>2025-03-31 13:45:56 -0400
committerSiddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com>2025-03-31 13:45:56 -0400
commit598da346f59503442ba0b4badfd9ac8b58af4a89 (patch)
tree6f850061b9e89a93c30c8a6d7a699ffdc291e2ab /src/sim/wb.cc
parent44cb9d396b909c84ef7ad3338e0a12cfcc082748 (diff)
MEM WB stage
Diffstat (limited to 'src/sim/wb.cc')
-rw-r--r--src/sim/wb.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/sim/wb.cc b/src/sim/wb.cc
index 9337aa0..480af05 100644
--- a/src/sim/wb.cc
+++ b/src/sim/wb.cc
@@ -6,4 +6,32 @@
WB::WB(Stage *stage) : Stage(stage) { this->id = WRITE; }
-void WB::advance_helper() {}
+void WB::advance_helper() {
+ if(this -> curr_instr) {
+ if(this->curr_instr->get_type() == R || this->curr_instr->get_type() == I){
+ if(this->checked_out.size() > 0) {
+ signed int reg = this->checked_out.front();
+ this->checked_out.pop_front();
+ if(reg >= GPR_NUM){
+ // TODO: handle vector instructions
+ } else {
+ this->gprs[reg] = this->curr_instr->get_s1();
+ }
+ }
+ } else if (this->curr_instr->get_type() == J) {
+ // TODO:handle push pop
+ // branch taken
+ if(this->pc != this->curr_instr->get_s1()) {
+ if(this->curr_instr->get_mnemonic() == JAL){
+ // set link register to next instruction
+ this->gprs[1] = this->pc + 1;
+ }
+ this->pc = this->curr_instr->get_s1();
+ //clear pending registers and squash pipeline
+ this->checked_out = {};
+ this->next->squash();
+ }
+ }
+ }
+ this->status = OK;
+}