From 0bcc0e4e2dfe9073df3837a0ba5b7ff1d1fa9fbc Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Thu, 17 Apr 2025 19:57:48 -0400 Subject: Loading binary program into dram --- gui/gui.cc | 56 ++++++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'gui/gui.cc') diff --git a/gui/gui.cc b/gui/gui.cc index 3c091e1..50c8155 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -41,6 +41,9 @@ GUI::GUI(QWidget *parent) // Refresh DRAM from worker thread connect(this, &GUI::sendRefreshDram, worker, &Worker::refreshDram, Qt::QueuedConnection); + // Load program from worker thread + connect(this, &GUI::sendLoadProgram, worker, &Worker::loadProgram, Qt::QueuedConnection); + // Refresh Cache from worker thread connect(this, &GUI::sendRefreshCache, worker, &Worker::refreshCache, Qt::QueuedConnection); @@ -113,45 +116,28 @@ void displayTableHTML(QTextEdit *textEdit, const std::vectorsetReadOnly(true); } -void browseAndUploadFile(QWidget* parent) { - QString filePath = QFileDialog::getOpenFileName(nullptr, "Open File", QDir::homePath(), "Text Files (*.txt);;All Files (*.*)"); +std::vector browseAndRetrieveFile(QWidget* parent) { + QString filePath = QFileDialog::getOpenFileName(parent, "Open Binary File", QDir::homePath(), "Binary Files (*.bin *.rv);;All Files (*.*)"); + std::vector program; - if (filePath.isEmpty()) { - return; - } + if (filePath.isEmpty()) return program; QFile file(filePath); - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - // textEdit->setPlainText("Error: Unable to open file!"); - QMessageBox::critical(parent, "File Upload", "Unable to open file!"); - return; + if (!file.open(QIODevice::ReadOnly)) { + QMessageBox::critical(parent, "File Upload", "Unable to open file!"); + return program; } - QTextStream in(&file); - QString content; - int lineNumber = 0; - - while (!in.atEnd()) { - QString line = in.readLine(); - - content += QString("
" - "%1." - "%2" - "

") - .arg(lineNumber) - .arg(line); - - lineNumber++; + while (!file.atEnd()) { + int32_t word = 0; + if (file.read(reinterpret_cast(&word), sizeof(int32_t)) == sizeof(int32_t)) { + program.push_back(static_cast(word)); + } } file.close(); - - QMessageBox::information(parent, "File Upload", "Instructions loaded successfully!"); - - // textEdit->setReadOnly(false); - // textEdit->setHtml(content); - // textEdit->setReadOnly(true); + return program; } void GUI::onWorkerClockCycles(int cycles, int pc) { @@ -257,8 +243,14 @@ void GUI::onWorkerFinished() { void GUI::on_upload_intructions_btn_clicked() { qDebug() << "Upload intructions button clicked."; - browseAndUploadFile(ui->register_table); - + std::vector program; + program = browseAndRetrieveFile(ui->register_table); + if(program.empty()){ + QMessageBox::critical(ui->register_table, "File Upload", "Invalid Program File!"); + } + emit sendLoadProgram(program); + emit sendRefreshDram(); + QMessageBox::information(ui->register_table, "File Upload", "Instructions loaded successfully!"); } -- cgit v1.2.3 From 087e0de152a00e7995b53cfac246b7b28d575c3f Mon Sep 17 00:00:00 2001 From: bd Date: Thu, 17 Apr 2025 20:57:13 -0400 Subject: Fix byte order --- gui/gui.cc | 18 +++++++-------- gui/worker.cc | 73 ++++++++--------------------------------------------------- 2 files changed, 18 insertions(+), 73 deletions(-) (limited to 'gui/gui.cc') diff --git a/gui/gui.cc b/gui/gui.cc index 50c8155..1acd17a 100644 --- a/gui/gui.cc +++ b/gui/gui.cc @@ -1,5 +1,6 @@ #include "gui.h" #include "./ui_gui.h" +#include "byteswap.h" GUI::GUI(QWidget *parent) : QMainWindow(parent) @@ -37,7 +38,7 @@ GUI::GUI(QWidget *parent) // Display registers connect(worker, &Worker::register_storage, this, &GUI::onWorkerShowRegisters); - + // Refresh DRAM from worker thread connect(this, &GUI::sendRefreshDram, worker, &Worker::refreshDram, Qt::QueuedConnection); @@ -85,7 +86,7 @@ void displayArrayHTML(QTextEdit *textEdit, const std::array &data) .arg(index); index++; } - tableText += ""; + tableText += ""; tableText += ""; textEdit->setHtml(tableText); @@ -119,7 +120,7 @@ void displayTableHTML(QTextEdit *textEdit, const std::vector browseAndRetrieveFile(QWidget* parent) { QString filePath = QFileDialog::getOpenFileName(parent, "Open Binary File", QDir::homePath(), "Binary Files (*.bin *.rv);;All Files (*.*)"); std::vector program; - + if (filePath.isEmpty()) return program; QFile file(filePath); @@ -131,7 +132,7 @@ std::vector browseAndRetrieveFile(QWidget* parent) { while (!file.atEnd()) { int32_t word = 0; if (file.read(reinterpret_cast(&word), sizeof(int32_t)) == sizeof(int32_t)) { - program.push_back(static_cast(word)); + program.push_back(static_cast(bswap_32(word))); } } @@ -141,10 +142,10 @@ std::vector browseAndRetrieveFile(QWidget* parent) { } void GUI::onWorkerClockCycles(int cycles, int pc) { - QFont font = ui->cycles_label->font(); + QFont font = ui->cycles_label->font(); font.setBold(true); font.setItalic(true); - font.setPointSize(14); + font.setPointSize(14); ui->cycles_label->setFont(font); ui->cycles_label->setText("Clock Cycles: " + QString::number(cycles) + "\t\t" + "PC: " + QString::number(pc)); } @@ -297,10 +298,10 @@ void GUI::on_enable_pipeline_checkbox_checkStateChanged(const Qt::CheckState &ar void GUI::on_enabl_cache_checkbox_checkStateChanged(const Qt::CheckState &arg1) { //TODO: handle cache enabling - if(arg1 == Qt::CheckState::Checked) { + if(arg1 == Qt::CheckState::Checked) { qDebug() << "enable cache checkbox checked."; } else { - qDebug() << "enable cache checkbox unchecked."; + qDebug() << "enable cache checkbox unchecked."; } } @@ -325,4 +326,3 @@ void GUI::on_save_program_state_btn_clicked() //TODO: save program state qDebug() << "save program state button is clicked."; } - diff --git a/gui/worker.cc b/gui/worker.cc index df6ebd2..e4e3bdf 100644 --- a/gui/worker.cc +++ b/gui/worker.cc @@ -12,67 +12,12 @@ void Worker::doWork() 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, false); + 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, 256)); + emit dram_storage(this->d->view(0, 255)); + emit cache_storage(this->c->view(0, 255)); emit register_storage(this->ct->get_gprs()); - - std::vector p; - - p.push_back(0b00000000000000010010100000001101); - p.push_back(0b00000000000000000000000101100010); - p.push_back(0b00000000000000010010100101001101); - p.push_back(0b00000000000000000000000101100010); - p.push_back(0b00000000000000010010100101001101); - p.push_back(0b00000000000000000000000101100010); - p.push_back(0b00000000000000010010100101001101); - p.push_back(0b00000000000000000000000101100010); - p.push_back(0b00000000000000000000000101100110); - p.push_back(0b00000000000000000000000110100110); - p.push_back(0b00000000000000000000000111100110); - p.push_back(0b00000000000000000000001000100110); - p.push_back(0b00000000000000000000000000101110); - p.push_back(0b00000000000000000000000000101110); - p.push_back(0b00000000000000000000000000010000); - - // 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(0b00000000000000010001000010010001); - // 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(0b00000000000000010001000010010001); - // 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); } Worker::~Worker() @@ -91,13 +36,13 @@ void Worker::loadProgram(std::vector p) { void Worker::refreshDram() { qDebug() << "Refreshing Dram"; - emit dram_storage(this->d->view(0, 32)); + emit dram_storage(this->d->view(0, 31)); } void Worker::refreshCache() { qDebug() << "Refreshing Dram"; - emit cache_storage(this->c->view(0, 256)); + emit cache_storage(this->c->view(0, 255)); } void Worker::refreshRegisters() @@ -110,8 +55,8 @@ 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, 256)); + emit dram_storage(this->d->view(0, 255)); + emit cache_storage(this->c->view(0, 255)); 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()); @@ -125,8 +70,8 @@ void Worker::runStep() { qDebug() << "Running for 1 step "; this->ct->run_for(1); - emit dram_storage(this->d->view(0, 256)); - emit cache_storage(this->c->view(0, 256)); + emit dram_storage(this->d->view(0, 255)); + emit cache_storage(this->c->view(0, 255)); 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()); -- cgit v1.2.3