diff options
author | bd <bdunahu@operationnull.com> | 2025-03-31 23:51:08 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-31 23:51:08 -0400 |
commit | a4e0e5ff6208205f6ebd980f9ed1eca91dcc4311 (patch) | |
tree | b9530876cabcb9041b925d795778237757bc797f | |
parent | 2235e18ad81be4ed7097cd9cab93e35a990ec327 (diff) | |
parent | 574212dafcf1c4bdb7d5e6aaa577b74345988d67 (diff) |
Merge remote-tracking branch 'origin/dev-sid' into bdunahu
-rw-r--r-- | gui/gui.cc | 35 | ||||
-rw-r--r-- | gui/gui.h | 27 | ||||
-rw-r--r-- | gui/gui.ui | 440 | ||||
-rw-r--r-- | gui/main.cc | 6 | ||||
-rw-r--r-- | inc/id.h | 3 | ||||
-rw-r--r-- | inc/instr.h | 7 | ||||
-rw-r--r-- | inc/instrDTO.h | 14 | ||||
-rw-r--r-- | inc/stage.h | 9 | ||||
-rw-r--r-- | src/sim/controller.cc | 5 | ||||
-rw-r--r-- | src/sim/ex.cc | 8 | ||||
-rw-r--r-- | src/sim/id.cc | 13 | ||||
-rw-r--r-- | src/sim/instrDTO.cc | 7 | ||||
-rw-r--r-- | src/sim/mm.cc | 22 | ||||
-rw-r--r-- | src/sim/stage.cc | 10 | ||||
-rw-r--r-- | src/sim/wb.cc | 32 |
15 files changed, 541 insertions, 97 deletions
@@ -1,39 +1,14 @@ #include "gui.h" -#include "ui_gui.h" -#include <QFile> -#include <QTextStream> +#include "./ui_gui.h" -Gui::Gui(QWidget *parent) - : QWidget(parent) - , ui(new Ui::gui) +GUI::GUI(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::GUI) { ui->setupUi(this); - loadTxtFile(); } -Gui::~Gui() +GUI::~GUI() { delete ui; } - -void Gui::loadTxtFile(){ - QFile inputFile(":/resources/input.txt"); - inputFile.open(QIODevice::ReadOnly); - - QTextStream in(&inputFile); - QString line = in.readAll(); - inputFile.close(); - - ui->textEdit->setPlainText(line); - QTextCursor cursor = ui->textEdit->textCursor(); - cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); -} - -void Gui::on_pushButton_clicked() -{ - QString searchString = ui->lineEdit->text(); - ui->textEdit->find(searchString, QTextDocument::FindWholeWords); -} - - - @@ -1,26 +1,23 @@ #ifndef GUI_H #define GUI_H -#include <QWidget> -namespace Ui -{ -class gui; +#include <QMainWindow> + +QT_BEGIN_NAMESPACE +namespace Ui { +class GUI; } QT_END_NAMESPACE -class Gui : public QWidget +class GUI : public QMainWindow { - Q_OBJECT - - public: - Gui(QWidget *parent = nullptr); - ~Gui(); + Q_OBJECT - private slots: - void on_pushButton_clicked(); +public: + GUI(QWidget *parent = nullptr); + ~GUI(); - private: - Ui::gui *ui; - void loadTxtFile(); +private: + Ui::GUI *ui; }; #endif // GUI_H @@ -1,55 +1,435 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>gui</class> - <widget class="QWidget" name="gui"> + <class>GUI</class> + <widget class="QMainWindow" name="GUI"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>800</width> - <height>600</height> + <width>1359</width> + <height>606</height> </rect> </property> <property name="windowTitle"> - <string>gui</string> + <string>RISC V[ECTOR]</string> </property> - <widget class="QWidget" name=""> - <property name="geometry"> - <rect> - <x>60</x> - <y>30</y> - <width>317</width> - <height>232</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_14"> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>keyword</string> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="6" rowspan="2"> + <widget class="Line" name="line_14"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> </widget> </item> - <item> - <widget class="QLineEdit" name="lineEdit"/> + <item row="1" column="1" rowspan="2"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Instructions</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QTextEdit" name="textEdit"/> + </item> + </layout> </item> - <item> - <widget class="QPushButton" name="pushButton"> - <property name="text"> - <string>find</string> + <item row="1" column="3" rowspan="2"> + <layout class="QVBoxLayout" name="verticalLayout_13"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QLabel" name="label_2"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Registers</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QTextEdit" name="textEdit_2"/> + </item> + </layout> + </item> + <item> + <widget class="Line" name="line_13"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="label_4"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Cache</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QTextEdit" name="textEdit_4"/> + </item> + </layout> + </item> + <item> + <widget class="Line" name="line_19"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QLabel" name="label_3"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>DRAM</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QTextEdit" name="textEdit_3"/> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </item> + <item row="1" column="2" rowspan="2"> + <widget class="Line" name="line_17"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item row="0" column="1" colspan="5"> + <widget class="Line" name="line_10"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="3" column="1" colspan="5"> + <widget class="Line" name="line_11"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="1" column="5" rowspan="2"> + <layout class="QVBoxLayout" name="verticalLayout_12"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> + <widget class="QLabel" name="label_7"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Upload Files</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_6"> + <item> + <widget class="QPushButton" name="pushButton_5"> + <property name="text"> + <string>Upload Instruction File</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QPushButton" name="pushButton_6"> + <property name="text"> + <string>Upload Program State File</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="Line" name="line_7"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_9"> + <item> + <widget class="QLabel" name="label_8"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Controls</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_8"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QPushButton" name="pushButton_4"> + <property name="text"> + <string>Refresh DRAM</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_2"> + <property name="text"> + <string>Refresh Cache</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Refresh Registers</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>Enable Pipeline</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox_2"> + <property name="text"> + <string>Enable Cache</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_10"> + <item> + <widget class="Line" name="line_15"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_9"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Run</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_9"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_7"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <widget class="QLineEdit" name="lineEdit"> + <property name="placeholderText"> + <string># Steps</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_7"> + <property name="text"> + <string>Run Steps</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="pushButton_8"> + <property name="text"> + <string>Step</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item> + <widget class="Line" name="line_16"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_11"> + <item> + <widget class="QLabel" name="label_11"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Program State</string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line_6"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Clock Cycles</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton_3"> + <property name="text"> + <string>Save Current Program State</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </item> + <item row="0" column="0" rowspan="3"> + <widget class="Line" name="line_12"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + </widget> + </item> + <item row="1" column="4" rowspan="2"> + <widget class="Line" name="line_18"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> </widget> </item> </layout> </item> - <item> - <widget class="QTextEdit" name="textEdit"/> - </item> </layout> </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>1359</width> + <height>26</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> </widget> - <resources/> +<resources/> <connections/> </ui> diff --git a/gui/main.cc b/gui/main.cc index 8f9d06b..ce47d10 100644 --- a/gui/main.cc +++ b/gui/main.cc @@ -80,9 +80,9 @@ int main(int argc, char **argv) } else { global_log->log(INFO, "Starting QT..."); QApplication a(argc, argv); - Gui w; - w.show(); - a.exec(); + GUI w; + w.show(); + return a.exec(); } global_log->log(INFO, "Cleaning up..."); @@ -64,8 +64,7 @@ class ID : public Stage * @param the resulting third field, which varies per type. * @param the resulting mnemonic. */ - void get_instr_fields( - signed int &s1, signed int &s2, signed int &s3, Mnemonic &m); + 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); void decode_I_type(signed int &s1, signed int &s2, signed int &s3); void decode_J_type(signed int &s1, signed int &s2); diff --git a/inc/instr.h b/inc/instr.h index 7fbb42b..d17613d 100644 --- a/inc/instr.h +++ b/inc/instr.h @@ -45,6 +45,13 @@ enum Mnemonic { NOP, }; +enum Type { + R, + I, + J, + INV +}; + namespace instr { // clang-format off diff --git a/inc/instrDTO.h b/inc/instrDTO.h index 77a223e..8249122 100644 --- a/inc/instrDTO.h +++ b/inc/instrDTO.h @@ -43,6 +43,10 @@ class InstrDTO * @return the mnemonic of the instruction */ Mnemonic get_mnemonic(); + /** + * @return the type of the instruction + */ + Type get_type(); /** * @param set hist key @@ -68,6 +72,11 @@ class InstrDTO * @param the mnemonic of the instruction */ void set_mnemonic(Mnemonic); + + /** + * @param the type of the instruction + */ + void set_type(Type); private: /** @@ -91,6 +100,11 @@ class InstrDTO * The mnemonic of the operation. */ Mnemonic mnemonic; + + /** + * Type of the instruction + */ + Type type; }; #endif /* INSTRDTO_H_INCLUDED */ diff --git a/inc/stage.h b/inc/stage.h index 84d2a7b..03048b0 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -30,11 +30,9 @@ class Stage * Advances this stage by a single clock cycle. * A boilerplate version is provided in stage.cc. * - * @param a DTO object containing the next instruction to be processed. * @param a response, indicating whether or not the parent pipe stage is * ready to accept a new instruction object next cycle. - * @return a response, indicating whether this pipeline stage is stalling, - * busy, or done. + * @return a DTO object containing the next instruction to be processed. * * Must set the status to STALLED when an operation completes. */ @@ -55,6 +53,11 @@ class Stage */ void set_pc(unsigned int pc); + /** + * Squashes the pipeline. + */ + void squash(); + protected: /** * The function expected to do the majority of the work. diff --git a/src/sim/controller.cc b/src/sim/controller.cc index 06591af..89ff4e7 100644 --- a/src/sim/controller.cc +++ b/src/sim/controller.cc @@ -31,10 +31,11 @@ int Controller::get_pc() { return this->pc; } InstrDTO *Controller::advance(Response p) { InstrDTO *r; - r = this->next->advance(p); ++this->clock_cycle; return r; } -void Controller::advance_helper() {} +void Controller::advance_helper() { + // TODO: check halt condition and call UI to refresh +} diff --git a/src/sim/ex.cc b/src/sim/ex.cc index 83c72d5..3d95917 100644 --- a/src/sim/ex.cc +++ b/src/sim/ex.cc @@ -282,28 +282,28 @@ EX::EX(Stage *stage) : Stage(stage) INIT_INSTRUCTION( BEQ, { - s1 = this->pc + s2; + (this->get_condition(EQ)) ? s1 = this->pc + s2 : s1 = this->pc; (void)s3; }), INIT_INSTRUCTION( BGT, { - s1 = this->pc + s2; + (this->get_condition(GT)) ? s1 = this->pc + s2 : s1 = this->pc; (void)s3; }), INIT_INSTRUCTION( BUF, { - s1 = this->pc + s2; + (this->get_condition(UF)) ? s1 = this->pc + s2 : s1 = this->pc; (void)s3; }), INIT_INSTRUCTION( BOF, { - s1 = this->pc + s2; + (this->get_condition(OF)) ? s1 = this->pc + s2 : s1 = this->pc; (void)s3; }), diff --git a/src/sim/id.cc b/src/sim/id.cc index edf74e2..0b75b64 100644 --- a/src/sim/id.cc +++ b/src/sim/id.cc @@ -46,38 +46,43 @@ void ID::advance_helper() { signed int s1, s2, s3; Mnemonic m; + Type t; // it may be good to ensure we are not doing // work that has already been done - if (this->curr_instr) { + if (this->curr_instr && this->curr_instr->get_mnemonic() == NONE) { s1 = curr_instr->get_instr_bits(); - get_instr_fields(s1, s2, s3, m); + get_instr_fields(s1, s2, s3, m ,t); if (this->status == OK) { curr_instr->set_s1(s1); curr_instr->set_s2(s2); curr_instr->set_s3(s3); curr_instr->set_mnemonic(m); + curr_instr->set_type(t); } } } -void ID::get_instr_fields( - signed int &s1, signed int &s2, signed int &s3, Mnemonic &m) +void ID::get_instr_fields(signed int &s1, signed int &s2, signed int &s3, Mnemonic &m, Type &t) { unsigned int type; this->split_instr(s1, type, m); switch (type) { case 0b00: + t = R; this->decode_R_type(s1, s2, s3); break; case 0b01: + t = I; this->decode_I_type(s1, s2, s3); break; case 0b10: + t = J; this->decode_J_type(s1, s2); break; case 0b11: + t = INV; this->status = OK; } } diff --git a/src/sim/instrDTO.cc b/src/sim/instrDTO.cc index 5a7fe3b..b33c26b 100644 --- a/src/sim/instrDTO.cc +++ b/src/sim/instrDTO.cc @@ -7,7 +7,8 @@ InstrDTO::InstrDTO() this->s1 = 0; this->s2 = 0; this->s3 = 0; - this->mnemonic = NOP; + this->mnemonic = NONE; + this->type = INV; } int InstrDTO::get_time_of(Accessor a) { return this->hist[a]; } @@ -22,6 +23,8 @@ signed int InstrDTO::get_s3() { return this->s3; } Mnemonic InstrDTO::get_mnemonic() { return this->mnemonic; } +Type InstrDTO::get_type() { return this->type; } + void InstrDTO::set_time_of(Accessor a, int i) { this->hist[a] = i; } void InstrDTO::set_instr_bits(signed int instr) { this->instr_bits = instr; } @@ -33,3 +36,5 @@ void InstrDTO::set_s2(signed int s) { this->s2 = s; } void InstrDTO::set_s3(signed int s) { this->s3 = s; } void InstrDTO::set_mnemonic(Mnemonic m) { this->mnemonic = m; } + +void InstrDTO::set_type(Type t) { this->type = t; } diff --git a/src/sim/mm.cc b/src/sim/mm.cc index 2b73207..cd85056 100644 --- a/src/sim/mm.cc +++ b/src/sim/mm.cc @@ -6,4 +6,24 @@ MM::MM(Stage *stage) : Stage(stage) { this->id = MEM; } -void MM::advance_helper() {} +void MM::advance_helper() { + Response r; + signed int data; + if(this->curr_instr){ + if (this->curr_instr->get_mnemonic() == LOAD) { + r = this->storage->read_word(this->id, this->curr_instr->get_s1(), data); + if(r == OK){ + this->status = OK; + this->curr_instr->set_s2(data); + } + } else if (this->curr_instr->get_mnemonic() == STORE) { + r = this->storage->write_word(this->id, this->curr_instr->get_s2(), this->curr_instr->get_s1()); + if(r == OK){ + this->status = OK; + } + } else { + // Mem has no work so just forward the instruction to WB + this->status = OK; + } + } +} diff --git a/src/sim/stage.cc b/src/sim/stage.cc index 11eb822..0f13d65 100644 --- a/src/sim/stage.cc +++ b/src/sim/stage.cc @@ -36,7 +36,7 @@ InstrDTO *Stage::advance(Response p) if (this->curr_instr && this->status != OK) this->advance_helper(); - if (this->curr_instr && p == OK) { + if (this->status == OK && p == OK && this->curr_instr) { // mutual consent this->curr_instr->set_time_of(this->id, this->clock_cycle); r = new InstrDTO(*this->curr_instr); @@ -79,3 +79,11 @@ bool Stage::is_checked_out(signed int r) return std::find(this->checked_out.begin(), this->checked_out.end(), r) != this->checked_out.end(); } + +void Stage::squash(){ + this->curr_instr->set_mnemonic(NOP); + this->status = OK; + if(this->next){ + this->next->squash(); + } +} diff --git a/src/sim/wb.cc b/src/sim/wb.cc index 9337aa0..ac47f25 100644 --- a/src/sim/wb.cc +++ b/src/sim/wb.cc @@ -6,4 +6,34 @@ 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 { + if(this->curr_instr->get_mnemonic() != STORE && this->curr_instr->get_mnemonic() != STOREV){ + 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; +} |