summaryrefslogtreecommitdiff
path: root/src/sim/if.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/if.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/if.cc')
-rw-r--r--src/sim/if.cc33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/sim/if.cc b/src/sim/if.cc
index deed8e1..7d3291b 100644
--- a/src/sim/if.cc
+++ b/src/sim/if.cc
@@ -2,18 +2,35 @@
#include "accessor.h"
#include "instrDTO.h"
#include "response.h"
+#include "stage.h"
-Response IF::advance(InstrDTO &i)
+IF::IF(Stage *stage) : Stage(stage) { this->id = FETCH; }
+
+Response IF::advance(InstrDTO &next_instr, Response p)
+{
+ this->advance_helper();
+ if (this->status == OK && p == OK) {
+ // mutual consent
+ ++this->pc;
+ this->curr_instr->set_time_of(this->id, this->clock_cycle);
+ next_instr = *this->curr_instr;
+ curr_instr = nullptr;
+ }
+ return this->status;
+}
+
+void IF::advance_helper()
{
Response r;
signed int bits;
- r = this->storage->read_word(this->id, this->pc, bits);
- if (r == OK) {
- ++this->pc;
- i.set_if_cycle(this->clock_cycle);
- i.set_instr_bits(bits);
+ if (this->curr_instr == nullptr) {
+ r = this->storage->read_word(this->id, this->pc, bits);
+ if (r == OK) {
+ this->status = r;
+ this->curr_instr = std::make_unique<InstrDTO>();
+ this->curr_instr->set_instr_bits(bits);
+ } else
+ this->status = STALLED;
}
-
- return r;
}