diff options
author | bd <bdunahu@operationnull.com> | 2025-04-17 15:30:26 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-17 15:30:26 -0400 |
commit | 2c94ea91b1c5a0d7c0ebb0ab229950f7c849909a (patch) | |
tree | c1fe016db8127633f9d14aac696ef9040967228d | |
parent | 430986b4b1ee1013db070991ce289176f48fa8e8 (diff) |
The pipeline says some things and there are numbers
-rw-r--r-- | gui/worker.cc | 66 | ||||
-rw-r--r-- | inc/id.h | 2 | ||||
-rw-r--r-- | src/sim/controller.cc | 1 | ||||
-rw-r--r-- | src/sim/ex.cc | 8 | ||||
-rw-r--r-- | src/sim/id.cc | 36 | ||||
-rw-r--r-- | src/sim/mm.cc | 11 | ||||
-rw-r--r-- | src/sim/wb.cc | 7 |
7 files changed, 93 insertions, 38 deletions
diff --git a/gui/worker.cc b/gui/worker.cc index 9202b89..061e0da 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -19,35 +19,43 @@ void Worker::doWork() emit cache_storage(this->c->view(0, 7)); emit register_storage(this->ct->get_gprs()); - signed int b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, - b15, b16, b17, b18, b19, b20; std::vector<signed int> p; - // I-TYPE / / / / - b0 = 0b00000010000000000001000000001101; - b1 = 0b00000000000000010010100000001101; - b2 = 0b00000000000000000010100010101001; - b3 = 0b00000000000000100010100000001101; - b4 = 0b00000000000000010010100010101001; - b5 = 0b00000000000000110010100000001101; - b6 = 0b00000000000000100010100010101001; - b7 = 0b00000000000001000010100000001101; - b8 = 0b00000000000000110010100010101001; - b9 = 0b00000000000000000010100000001101; - b10 = 0b00000000000000110011000000001101; - b11 = 0b00000000000000000011100000001010; - b12 = 0b00000000000100100101000100000100; - b13 = 0b00000000000000000100100111000101; - b14 = 0b00000000000000010100101000000101; - b15 = 0b00000000000011101000001110000100; - b16 = 0b00000000000000000011101001101001; - b17 = 0b00000000000000010010100101001101; - b18 = 0b00000000000000000101001101000000; - b19 = 0b11111111111111111100100000010110; - // b20 = 0b00000000000000000000000000010000; - - p = {b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, - b11, b12, b13, b14, b15, b16, b17, b18, b19}; + p.push_back(0b00000000000000000010100010001101); + p.push_back(0b11111111111101010011000000001101); + p.push_back(0b00000000000000000000000110100010); + p.push_back(0b00000000000000000011000000001110); + p.push_back(0b00000000000000000000000110100110); + p.push_back(0b00000000001000100011000000101001); + p.push_back(0b00000000000000000000000101100010); + p.push_back(0b00000000000000000010100010001101); + p.push_back(0b00000000000001000001000010010001); + p.push_back(0b11111111111010010011000000001101); + p.push_back(0b11111111111111000011000101101001); + p.push_back(0b00000000000001000010100111000101); + p.push_back(0b11111111111111000010100110000101); + p.push_back(0b00000000000011000111001100000100); + p.push_back(0b00000000000000000000000110100010); + p.push_back(0b00000000000000001010100000001110); + p.push_back(0b00000000000000000000000110100110); + p.push_back(0b00000000000001000011000101101001); + p.push_back(0b00000000000000000001000101001101); + p.push_back(0b00000000000000000000000101100110); + p.push_back(0b00000000000000000000000000101010); + p.push_back(0b00000000000000000000000101100010); + p.push_back(0b00000000000000000010100010001101); + p.push_back(0b00000000000001000001000010010001); + p.push_back(0b00000000010011000011000000001101); + p.push_back(0b11111111111111000011000101101001); + p.push_back(0b00000000000001000010100111000101); + p.push_back(0b11111111111111000010100110000101); + p.push_back(0b00000000000011000111001100000100); + p.push_back(0b00000000000001000011000101101001); + p.push_back(0b00000000000000000001000101001101); + p.push_back(0b00000000000000000000000101100110); + p.push_back(0b00000000000000000000000000101010); + p.push_back(0b00000000000000000000000000010000); + p.push_back(0b00000000000000000000000000000000); this->d->load(p); } @@ -69,7 +77,7 @@ void Worker::refreshDram() void Worker::refreshCache() { qDebug() << "Refreshing Dram"; - emit cache_storage(this->c->view(0, 7)); + emit cache_storage(this->c->view(24, 31)); } void Worker::refreshRegisters() @@ -98,7 +106,7 @@ void Worker::runStep() qDebug() << "Running for 1 step "; this->ct->advance(WAIT); emit dram_storage(this->d->view(0, 256)); - emit cache_storage(this->c->view(0, 7)); + emit cache_storage(this->c->view(24, 8)); emit register_storage(this->ct->get_gprs()); emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc()); emit if_info(this->if_stage->stage_info()); @@ -69,7 +69,7 @@ class ID : public Stage void get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t); void decode_R_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); void decode_I_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); - void decode_J_type(signed int &s1, signed int &s2, signed int &s3); + void decode_J_type(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); /** * Helper for `get_instr_fields`. * Given a raw instruction, returns the mnemonic and type. diff --git a/src/sim/controller.cc b/src/sim/controller.cc index 65e5676..9256151 100644 --- a/src/sim/controller.cc +++ b/src/sim/controller.cc @@ -11,6 +11,7 @@ Controller::Controller(Stage *stage, Storage *storage, bool is_pipelined) this->pc = 0x0; this->checked_out = {}; this->gprs = {0}; + this->gprs.at(2) = MEM_WORDS; // set the stack pointer // grant side-door access this->id = SIDE; } diff --git a/src/sim/ex.cc b/src/sim/ex.cc index d20d15f..c676781 100644 --- a/src/sim/ex.cc +++ b/src/sim/ex.cc @@ -340,20 +340,20 @@ EX::EX(Stage *stage) : Stage(stage) INIT_INSTRUCTION( PUSH, { + std::cout << "adding " << s1 << " and " << s3; + s1 = s1 + s3; + std::cout << " for " << s1 << std::endl; (void)pc; - (void)s3; (void)s2; - (void)s1; (void)this; }), INIT_INSTRUCTION( POP, { + s1 = s1 + s3; (void)pc; - (void)s3; (void)s2; - (void)s1; (void)this; }), diff --git a/src/sim/id.cc b/src/sim/id.cc index 37c6773..de412d4 100644 --- a/src/sim/id.cc +++ b/src/sim/id.cc @@ -86,7 +86,7 @@ void ID::get_instr_fields( break; case 0b10: t = J; - this->decode_J_type(s1, s2, s3); + this->decode_J_type(s1, s2, s3, m); break; case 0b11: t = INV; @@ -159,8 +159,10 @@ void ID::decode_I_type( this->status = r1; } -void ID::decode_J_type(signed int &s1, signed int &s2, signed int &s3) +void ID::decode_J_type( + signed int &s1, signed int &s2, signed int &s3, Mnemonic &m) { + Response r1, r2; unsigned int s0b, s1b; s0b = REG_SIZE; @@ -169,7 +171,35 @@ void ID::decode_J_type(signed int &s1, signed int &s2, signed int &s3) s2 = GET_BITS_SIGN_EXTEND(s1, s0b, s1b); s1 = GET_LS_BITS(s1, s0b); - this->status = this->read_guard(*&s1); + switch (m) { + case PUSH: + s2 = s1; // source + s3 = 2; // stack pointer + s1 = -1; // increment amount + r1 = this->read_guard(s2); + r2 = (this->is_checked_out(s3)) ? STALLED : OK; // we read the stack pointer + if (r1 == OK && r2 == OK) { + this->write_guard(s3); // we write the stack pointer + } + this->status = (r1 == OK && r2 == OK) ? OK : STALLED; + break; + case POP: + s2 = s1; // destination + s3 = 2; // stack pointer + s1 = 1; // increment amount + r1 = (this->is_checked_out(s3)) ? STALLED : OK; // we read the stack pointer + if (r1 == OK) { + this->write_guard(s2); + this->write_guard(s3); // we write the stack pointer + } + this->status = r1; + break; + default: + this->status = this->read_guard(*&s1); + } + + std::cout << m << ":" << this->status << std::endl; + } std::vector<int> ID::stage_info() diff --git a/src/sim/mm.cc b/src/sim/mm.cc index a9a60c2..a02ca83 100644 --- a/src/sim/mm.cc +++ b/src/sim/mm.cc @@ -21,8 +21,8 @@ void MM::advance_helper() this->status = STALLED; break; + case PUSH: case STORE: - // TODO signed issues, we aren't wrapping addresses i = this->storage->write_word( this, this->curr_instr->get_s2(), this->curr_instr->get_s1()); this->status = i ? OK : STALLED; @@ -31,6 +31,15 @@ void MM::advance_helper() } break; + case POP: + i = this->storage->read_word(this, this->curr_instr->get_s3(), data); + this->status = i ? OK : STALLED; + if (this->status == OK) { + this->curr_instr->set_s3(data); + } else + this->status = STALLED; + break; + default: this->status = OK; } diff --git a/src/sim/wb.cc b/src/sim/wb.cc index 4e6b2b0..08e5ed3 100644 --- a/src/sim/wb.cc +++ b/src/sim/wb.cc @@ -31,6 +31,13 @@ void WB::write_handler() this->checked_out.pop_front(); reg = this->curr_instr->get_checked_out(); this->store_register(reg, this->curr_instr->get_s1()); + + if (this->curr_instr->get_mnemonic() == POP) { + // POP performs a second register write + reg = this->checked_out.front(); + this->checked_out.pop_front(); + this->store_register(reg, this->curr_instr->get_s3()); + } } void WB::jump_handler() |