summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-04-01 23:22:12 -0400
committerbd <bdunahu@operationnull.com>2025-04-01 23:22:12 -0400
commit9e30d0054e7b3eb10e4e464b12ae3cc1eecc9585 (patch)
tree5f49ef6a4e6f7529ac0d92fa7c5f3326d4140066
parent05a873027d01cdf6318d67b77a4eaad120b05527 (diff)
Fix bug with decode pushing checked_out when delayed with RAW
-rw-r--r--gui/gui.cc6
-rw-r--r--gui/worker.cc132
-rw-r--r--src/sim/controller.cc4
-rw-r--r--src/sim/id.cc8
-rw-r--r--src/sim/stage.cc6
-rw-r--r--tests/controller.cc71
6 files changed, 172 insertions, 55 deletions
diff --git a/gui/gui.cc b/gui/gui.cc
index b96d65d..3d3c56f 100644
--- a/gui/gui.cc
+++ b/gui/gui.cc
@@ -63,7 +63,7 @@ void displayArrayHTML(QTextEdit *textEdit, const std::array<int, GPR_NUM> &data)
QString tableText = "<table border='1' cellspacing='0' cellpadding='8' style='border-collapse: collapse; width: 100%; border: 2px solid black;'>";
tableText += "<tr>";
- int index = 1;
+ int index = 0;
for (int value : data) {
tableText += QString("<td align='center' style='border: 2px solid black; min-width: 60px; padding: 10px;'>"
"%1 <sup style='font-size: 10px; font-weight: bold; color: black;'>%2</sup>"
@@ -83,7 +83,7 @@ void displayTableHTML(QTextEdit *textEdit, const std::vector<std::array<signed i
textEdit->setReadOnly(false);
QString tableText = "<table border='1' cellspacing='0' cellpadding='8' style='border-collapse: collapse; width: 100%; border: 2px solid black;'>";
- int index = 1;
+ int index = 0;
for (const auto &row : data) {
tableText += "<tr>";
for (signed int value : row) {
@@ -118,7 +118,7 @@ void browseAndUploadFile(QTextEdit *textEdit) {
QTextStream in(&file);
QString content;
- int lineNumber = 1;
+ int lineNumber = 0;
while (!in.atEnd()) {
QString line = in.readLine();
diff --git a/gui/worker.cc b/gui/worker.cc
index ca3ec4b..2df4e17 100644
--- a/gui/worker.cc
+++ b/gui/worker.cc
@@ -2,66 +2,104 @@
Worker::Worker(QObject *parent) : QObject(parent) {}
-void Worker::doWork() {
- qDebug() << "Initializing...";
- this->d = new Dram(0);
+void Worker::doWork()
+{
+ qDebug() << "Initializing...";
+ this->d = new Dram(0);
this->c = new Cache(this->d, 0);
- this->if_stage = new IF(nullptr);
+ this->if_stage = new IF(nullptr);
this->id_stage = new ID(if_stage);
this->ex_stage = new EX(id_stage);
- this->mm_stage = new MM(ex_stage);
- this->wb_stage = new WB(mm_stage);
- this->ct = new Controller(wb_stage, this->c, true);
-
- emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
- emit dram_storage(this->d->view(0,32));
- emit cache_storage(this->c->view(0,8));
- emit register_storage(this->ct->get_gprs());
-
- signed int w;
- w = 0x11223344;
- this->d->write_word(MEM, w, 0x0);
- this->c->write_word(MEM, w, 0x0);
- this->ct->set_gprs(0, w);
+ this->mm_stage = new MM(ex_stage);
+ this->wb_stage = new WB(mm_stage);
+ this->ct = new Controller(wb_stage, this->c, true);
+
+ emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
+ emit dram_storage(this->d->view(0, 32));
+ emit cache_storage(this->c->view(0, 8));
+ 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;
+ std::vector<signed int> p;
+
+ // I-TYPE / / / /
+ b0 = 0b00000010000000000001000000001101; // ADDI $2 $0 0x200;
+ b1 = 0b00000000000000010010100000001101; // ADDI $5 $0 0x1;
+ b2 = 0b00000000000000000010100010101101; // STORE $5 0($2); (RAW HAZARD)!
+ // I-TYPE / / / /
+ b3 = 0b00000000000000100010100000001101; // ADDI $5 $0 0x2; (RAW HAZARD)!
+ b4 = 0b00000000000000010010100010101101; // STORE $5 1($2); (RAW HAZARD)!
+ // // I-TYPE / / / /
+ b5 = 0b00000000000000000010100000001101; // ADDI $5 $0 0x0;
+ // // I-TYPE / / / /
+ b6 = 0b00000000000000010011000000001101; // ADDI $6 $0 0x1;
+ // // J-TYPE / / /
+ b7 = 0b00000000000000000011100000001010; // JRL CHECK
+ // // R-TYPE / / / / /
+ b8 = 0b00000000000100100101000100000100; // ADD $9 $2 $5;
+ // // I-TYPE / / / /
+ b9 = 0b00000000000000000011101001000101; // LOAD $7 0($9); (RAW HAZARD)!
+ // // I-TYPE / / / /
+ b10 = 0b00000000000000010100001001000101; // LOAD $8 1($9);
+ // // R-TYPE / / / / /
+ b11 = 0b00000000000011101000001110000100; // ADD $7 $7 $8;
+ // I-TYPE / / / /
+ b12 = 0b00000000000000000011101001101101; // STORE $7 0($9);
+ b13 = 0b00000010000000010010100101001101; // ADDI $5 $5 0x1;
+ // // R-TYPE / / / / /
+ b14 = 0b00000000000111100101001101000000; // CMP $6 $5
+ // // J-TYPE / / /
+ b15 = 0b11111111111111111100100000010110; // bgt LOOP
+
+ p = {b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15};
+ this->d->load(p);
}
-Worker::~Worker() {
- emit finished();
- qDebug() << "Worker destructor called in thread:" << QThread::currentThread();
- delete this->ct;
+Worker::~Worker()
+{
+ emit finished();
+ qDebug() << "Worker destructor called in thread:"
+ << QThread::currentThread();
+ delete this->ct;
delete this->c;
}
-
-void Worker::refreshDram() {
- qDebug() << "Refreshing Dram";
- emit dram_storage(this->d->view(0,32));
+void Worker::refreshDram()
+{
+ qDebug() << "Refreshing Dram";
+ emit dram_storage(this->d->view(0, 32));
}
-void Worker::refreshCache() {
- qDebug() << "Refreshing Dram";
- emit cache_storage(this->c->view(0,8));
+void Worker::refreshCache()
+{
+ qDebug() << "Refreshing Dram";
+ emit cache_storage(this->c->view(0, 8));
}
-void Worker::refreshRegisters() {
- qDebug() << "Refreshing Registers";
- emit register_storage(this->ct->get_gprs());
+void Worker::refreshRegisters()
+{
+ qDebug() << "Refreshing Registers";
+ emit register_storage(this->ct->get_gprs());
}
-void Worker::runSteps(int steps) {
- qDebug() << "Running for steps: " << steps;
- this->ct->run_for(steps);
- emit dram_storage(this->d->view(0,32));
- emit cache_storage(this->c->view(0,8));
- emit register_storage(this->ct->get_gprs());
- emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
+void Worker::runSteps(int steps)
+{
+ qDebug() << "Running for steps: " << steps;
+ this->ct->run_for(steps);
+ emit dram_storage(this->d->view(0, 256));
+ emit cache_storage(this->c->view(0, 8));
+ emit register_storage(this->ct->get_gprs());
+ emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
}
-void Worker::runStep() {
- qDebug() << "Running for 1 step " ;
- this->ct->advance(OK);
- emit dram_storage(this->d->view(0,32));
- emit cache_storage(this->c->view(0,8));
- emit register_storage(this->ct->get_gprs());
- emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
-} \ No newline at end of file
+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, 8));
+ emit register_storage(this->ct->get_gprs());
+ qDebug() << "PC " << this->ct->get_pc();
+ emit clock_cycles(this->ct->get_clock_cycle(), this->ct->get_pc());
+}
diff --git a/src/sim/controller.cc b/src/sim/controller.cc
index cf8d02d..65e5676 100644
--- a/src/sim/controller.cc
+++ b/src/sim/controller.cc
@@ -19,7 +19,7 @@ void Controller::run_for(int number)
{
int i;
for (i = 0; i < number; ++i) {
- this->advance(OK);
+ this->advance(WAIT);
}
}
@@ -38,7 +38,7 @@ InstrDTO *Controller::advance(Response p)
InstrDTO *r;
r = this->next->advance(p);
++this->clock_cycle;
-
+
return r;
}
diff --git a/src/sim/id.cc b/src/sim/id.cc
index 0df26f4..0c0be91 100644
--- a/src/sim/id.cc
+++ b/src/sim/id.cc
@@ -102,9 +102,10 @@ void ID::decode_R_type(signed int &s1, signed int &s2, signed int &s3)
r1 = this->read_guard(s1);
r2 = this->read_guard(s2);
- this->write_guard(s3);
-
this->status = (r1 == OK && r2 == OK) ? OK : STALLED;
+
+ if (this->status == OK)
+ this->write_guard(s3);
}
void ID::decode_I_type(
@@ -123,7 +124,8 @@ void ID::decode_I_type(
r1 = this->read_guard(s1);
if (m != STORE && m != STOREV) {
this->status = r1;
- this->write_guard(s2);
+ if (r1 == OK)
+ this->write_guard(s2);
} else
this->status = (this->read_guard(s2) == OK && r1 == OK) ? OK : STALLED;
}
diff --git a/src/sim/stage.cc b/src/sim/stage.cc
index 24bdf75..2857e1f 100644
--- a/src/sim/stage.cc
+++ b/src/sim/stage.cc
@@ -28,6 +28,12 @@ InstrDTO *Stage::advance(Response p)
InstrDTO *s = nullptr;
Response n;
+ // std::cout << "advance: " << this->id << ": " << this->curr_instr << "?: " << p << ": " << this->checked_out.size() << ": ";
+ // if (curr_instr)
+ // std::cout << curr_instr->get_mnemonic();
+ // for (long unsigned int i = 0; i < this->checked_out.size(); ++i)
+ // std::cout << this->checked_out[i] << " ";
+ // std::cout << std::endl;
if (this->curr_instr && this->status != OK) {
this->advance_helper();
}
diff --git a/tests/controller.cc b/tests/controller.cc
index c7e3c93..a009a70 100644
--- a/tests/controller.cc
+++ b/tests/controller.cc
@@ -350,6 +350,7 @@ TEST_CASE_METHOD(ControllerPipeFixture, "two num adder", "[full pipe]")
CHECK(this->ct->get_pc() == 0xB);
CHECK(i->get_mnemonic() == ADD);
CHECK(i->get_instr_bits() == b8);
+ CHECK(this->ct->checked_out.front() == 0x7);
delete i;
i = this->ct->advance(WAIT); // RAW
@@ -373,6 +374,76 @@ TEST_CASE_METHOD(ControllerPipeFixture, "two num adder", "[full pipe]")
CHECK(this->ct->get_gprs().at(9) == 0x200);
CHECK(i->get_mnemonic() == LOAD);
CHECK(i->get_instr_bits() == b9);
+ CHECK(this->ct->checked_out.front() == 0x8);
+
+ delete i;
+ i = this->ct->advance(WAIT);
+ REQUIRE(i != nullptr);
+
+ CHECK(i->get_time_of(FETCH) == 33);
+ CHECK(i->get_time_of(DCDE) == 34);
+ CHECK(i->get_time_of(EXEC) == 35);
+ CHECK(i->get_time_of(MEM) == 36);
+ CHECK(i->get_time_of(WRITE) == 37);
+ CHECK(i->get_s1() == 0x2);
+ CHECK(i->get_s2() == 0x0);
+ CHECK(i->get_s3() == 0x1);
+ CHECK(this->ct->get_gprs().at(2) == 0x200);
+ CHECK(this->ct->get_gprs().at(6) == 0x1);
+ CHECK(this->ct->get_gprs().at(7) == 0x1);
+ CHECK(this->ct->get_gprs().at(8) == 0x2);
+ CHECK(this->ct->get_gprs().at(9) == 0x200);
+ CHECK(i->get_mnemonic() == LOAD);
+ CHECK(i->get_instr_bits() == b10);
+ CHECK(this->ct->checked_out.front() == 0x7);
+
+ delete i;
+ i = this->ct->advance(WAIT);
+ REQUIRE(i == nullptr);
+ i = this->ct->advance(WAIT);
+ REQUIRE(i == nullptr);
+ i = this->ct->advance(WAIT);
+ REQUIRE(i != nullptr);
+
+ CHECK(i->get_time_of(FETCH) == 34);
+ CHECK(i->get_time_of(DCDE) == 37);
+ CHECK(i->get_time_of(EXEC) == 38);
+ CHECK(i->get_time_of(MEM) == 39);
+ CHECK(i->get_time_of(WRITE) == 40);
+ CHECK(i->get_s1() == 0x3);
+ CHECK(i->get_s2() == 0x2);
+ CHECK(i->get_s3() == 0x1);
+ CHECK(this->ct->get_gprs().at(2) == 0x200);
+ CHECK(this->ct->get_gprs().at(6) == 0x1);
+ CHECK(this->ct->get_gprs().at(7) == 0x3);
+ CHECK(this->ct->get_gprs().at(8) == 0x2);
+ CHECK(this->ct->get_gprs().at(9) == 0x200);
+ CHECK(i->get_mnemonic() == ADD);
+ CHECK(i->get_instr_bits() == b11);
+
+ delete i;
+ i = this->ct->advance(WAIT);
+ REQUIRE(i == nullptr);
+ i = this->ct->advance(WAIT);
+ REQUIRE(i == nullptr);
+ i = this->ct->advance(WAIT);
+ REQUIRE(i != nullptr);
+
+ CHECK(i->get_time_of(FETCH) == 37);
+ CHECK(i->get_time_of(DCDE) == 40);
+ CHECK(i->get_time_of(EXEC) == 41);
+ CHECK(i->get_time_of(MEM) == 42);
+ CHECK(i->get_time_of(WRITE) == 43);
+ CHECK(i->get_s1() == 0x200);
+ CHECK(i->get_s2() == 0x3);
+ CHECK(i->get_s3() == 0x0);
+ CHECK(this->ct->get_gprs().at(2) == 0x200);
+ CHECK(this->ct->get_gprs().at(6) == 0x1);
+ CHECK(this->ct->get_gprs().at(7) == 0x3);
+ CHECK(this->ct->get_gprs().at(8) == 0x2);
+ CHECK(this->ct->get_gprs().at(9) == 0x200);
+ CHECK(i->get_mnemonic() == STORE);
+ CHECK(i->get_instr_bits() == b12);
delete i;
}