From fab8cb529772dee9a3e28d471cf82796f0ce257d Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 18 Jul 2019 00:30:35 +0200 Subject: Add config option to reset machine before internal assembler starts. Signed-off-by: Pavel Pisa --- qtmips_gui/NewDialog.ui | 9 ++++++++- qtmips_gui/mainwindow.cpp | 16 +++++++++++----- qtmips_gui/mainwindow.h | 5 +++-- qtmips_gui/newdialog.cpp | 10 ++++++++-- qtmips_gui/newdialog.h | 1 + qtmips_machine/machineconfig.cpp | 12 ++++++++++++ qtmips_machine/machineconfig.h | 4 ++++ 7 files changed, 47 insertions(+), 10 deletions(-) diff --git a/qtmips_gui/NewDialog.ui b/qtmips_gui/NewDialog.ui index e3423a4..ee30fc2 100644 --- a/qtmips_gui/NewDialog.ui +++ b/qtmips_gui/NewDialog.ui @@ -7,7 +7,7 @@ 0 0 558 - 316 + 323 @@ -80,6 +80,13 @@ + + + + Reset at compile time (reload after make) + + + diff --git a/qtmips_gui/mainwindow.cpp b/qtmips_gui/mainwindow.cpp index 210b8de..3af5e47 100644 --- a/qtmips_gui/mainwindow.cpp +++ b/qtmips_gui/mainwindow.cpp @@ -224,11 +224,12 @@ void MainWindow::show_hide_coreview(bool show) { coreview->setScene(corescene); } -void MainWindow::create_core(const machine::MachineConfig &config, bool load_executable) { +void MainWindow::create_core(const machine::MachineConfig &config, bool load_executable, + bool keep_memory) { // Create machine machine::QtMipsMachine *new_machine = new machine::QtMipsMachine(&config, true, load_executable); - if (!load_executable && (machine != nullptr)) { + if (keep_memory && (machine != nullptr)) { new_machine->memory_rw()->reset(*machine->memory()); } @@ -309,13 +310,13 @@ void MainWindow::new_machine() { ndialog->show(); } -void MainWindow::machine_reload() { +void MainWindow::machine_reload(bool force_memory_reset) { if (machine == nullptr) return new_machine(); bool load_executable = machine->executable_loaded(); machine::MachineConfig cnf(&machine->config()); // We have to make local copy as create_core will delete current machine try { - create_core(cnf, load_executable); + create_core(cnf, load_executable, !load_executable && !force_memory_reset); } catch (const machine::QtMipsExceptionInput &e) { QMessageBox msg(this); msg.setText(e.msg(false)); @@ -714,20 +715,25 @@ void MainWindow::message_selected(messagetype::Type type, QString file, int line } void MainWindow::compile_source() { - SymbolTableDb symtab(machine->symbol_table_rw(true)); bool error_occured = false; if (current_srceditor == nullptr) return; + if (machine != nullptr) { + if (machine->config().reset_at_compile()) + machine_reload(true); + } if (machine == nullptr) { QMessageBox::critical(this, "QtMips Error", tr("No machine to store program.")); return; } + SymbolTableDb symtab(machine->symbol_table_rw(true)); machine::MemoryAccess *mem = machine->physical_address_space_rw(); if (mem == nullptr) { QMessageBox::critical(this, "QtMips Error", tr("No physical addresspace to store program.")); return; } QString filename = current_srceditor->filename(); + machine->cache_sync(); SrcEditor *editor = current_srceditor; QTextDocument *doc = editor->document(); diff --git a/qtmips_gui/mainwindow.h b/qtmips_gui/mainwindow.h index 95b3b59..d48ccda 100644 --- a/qtmips_gui/mainwindow.h +++ b/qtmips_gui/mainwindow.h @@ -64,7 +64,8 @@ public: ~MainWindow(); void start(); - void create_core(const machine::MachineConfig &config, bool load_executable = true); + void create_core(const machine::MachineConfig &config, bool load_executable = true, + bool keep_memory = false); bool configured(); @@ -76,7 +77,7 @@ signals: public slots: // Actions signals void new_machine(); - void machine_reload(); + void machine_reload(bool force_memory_reset = false); void print_action(); void new_source(); void open_source(); diff --git a/qtmips_gui/newdialog.cpp b/qtmips_gui/newdialog.cpp index ef9dac3..def95fb 100644 --- a/qtmips_gui/newdialog.cpp +++ b/qtmips_gui/newdialog.cpp @@ -66,6 +66,7 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) { connect(ui->preset_no_pipeline_cache, SIGNAL(toggled(bool)), this, SLOT(set_preset())); connect(ui->preset_pipelined_bare, SIGNAL(toggled(bool)), this, SLOT(set_preset())); connect(ui->preset_pipelined, SIGNAL(toggled(bool)), this, SLOT(set_preset())); + connect(ui->reset_at_compile, SIGNAL(clicked(bool)), this, SLOT(reset_at_compile_change(bool))); connect(ui->pipelined, SIGNAL(clicked(bool)), this, SLOT(pipelined_change(bool))); connect(ui->delay_slot, SIGNAL(clicked(bool)), this, SLOT(delay_slot_change(bool))); @@ -126,7 +127,7 @@ void NewDialog::create() { MainWindow *prnt = (MainWindow*)parent(); try { - prnt->create_core(*config); + prnt->create_core(*config, true, false); } catch (const machine::QtMipsExceptionInput &e) { QMessageBox msg(this); msg.setText(e.msg(false)); @@ -144,7 +145,7 @@ void NewDialog::create() { void NewDialog::create_empty() { MainWindow *prnt = (MainWindow*)parent(); - prnt->create_core(*config, false); + prnt->create_core(*config, false, true); store_settings(); // Save to settings this->close(); } @@ -270,9 +271,14 @@ void NewDialog::osemu_fs_root_change(QString val) { config->set_osemu_fs_root(val); } +void NewDialog::reset_at_compile_change(bool v) { + config->set_reset_at_compile(v); +} + void NewDialog::config_gui() { // Basic ui->elf_file->setText(config->elf()); + ui->reset_at_compile->setChecked(config->reset_at_compile()); // Core ui->pipelined->setChecked(config->pipelined()); ui->delay_slot->setChecked(config->delay_slot()); diff --git a/qtmips_gui/newdialog.h b/qtmips_gui/newdialog.h index 077b1ab..532f253 100644 --- a/qtmips_gui/newdialog.h +++ b/qtmips_gui/newdialog.h @@ -79,6 +79,7 @@ private slots: void osemu_exception_stop_change(bool); void browse_osemu_fs_root(); void osemu_fs_root_change(QString val); + void reset_at_compile_change(bool); private: Ui::NewDialog *ui; diff --git a/qtmips_machine/machineconfig.cpp b/qtmips_machine/machineconfig.cpp index c926348..2e0cf78 100644 --- a/qtmips_machine/machineconfig.cpp +++ b/qtmips_machine/machineconfig.cpp @@ -193,6 +193,7 @@ MachineConfig::MachineConfig() { osem_interrupt_stop = true; osem_exception_stop = true; osem_fs_root = ""; + res_at_compile = true; elf_path = DF_ELF; cch_program = MachineConfigCache(); cch_data = MachineConfigCache(); @@ -213,6 +214,7 @@ MachineConfig::MachineConfig(const MachineConfig *cc) { osem_interrupt_stop = cc->osemu_interrupt_stop(); osem_exception_stop = cc->osemu_exception_stop(); osem_fs_root = cc->osemu_fs_root(); + res_at_compile = cc->reset_at_compile(); elf_path = cc->elf(); cch_program = cc->cache_program(); cch_data = cc->cache_data(); @@ -235,6 +237,7 @@ MachineConfig::MachineConfig(const QSettings *sts, const QString &prefix) { osem_interrupt_stop = sts->value(N("OsemuInterruptStop"), true).toBool(); osem_exception_stop = sts->value(N("OsemuExceptionStop"), true).toBool(); osem_fs_root = sts->value(N("OsemuFilesystemRoot"), "").toString(); + res_at_compile = sts->value(N("ResetAtCompile"), true).toBool(); elf_path = sts->value(N("Elf"), DF_ELF).toString(); cch_program = MachineConfigCache(sts, N("ProgramCache_")); cch_data = MachineConfigCache(sts, N("DataCache_")); @@ -253,6 +256,7 @@ void MachineConfig::store(QSettings *sts, const QString &prefix) { sts->setValue(N("OsemuInterruptStop"), osemu_interrupt_stop()); sts->setValue(N("OsemuExceptionStop"), osemu_exception_stop()); sts->setValue(N("OsemuFilesystemRoot"), osemu_fs_root()); + sts->setValue(N("ResetAtCompile"), reset_at_compile()); sts->setValue(N("Elf"), elf_path); cch_program.store(sts, N("ProgramCache_")); cch_data.store(sts, N("DataCache_")); @@ -344,6 +348,10 @@ void MachineConfig::set_osemu_fs_root(QString v) { osem_fs_root = v; } +void MachineConfig::set_reset_at_compile(bool v) { + res_at_compile = v; +} + void MachineConfig::set_elf(QString path) { elf_path = path; } @@ -410,6 +418,10 @@ QString MachineConfig::osemu_fs_root() const { return osem_fs_root; } +bool MachineConfig::reset_at_compile() const { + return res_at_compile; +} + QString MachineConfig::elf() const { return elf_path; } diff --git a/qtmips_machine/machineconfig.h b/qtmips_machine/machineconfig.h index 987f3aa..bcd5b76 100644 --- a/qtmips_machine/machineconfig.h +++ b/qtmips_machine/machineconfig.h @@ -134,6 +134,8 @@ public: void set_osemu_interrupt_stop(bool); void set_osemu_exception_stop(bool); void set_osemu_fs_root(QString v); + // reset machine befor internal compile/reload after external make + void set_reset_at_compile(bool); // Set path to source elf file. This has to be set before core is initialized. void set_elf(QString path); // Configure cache @@ -154,6 +156,7 @@ public: bool osemu_interrupt_stop() const; bool osemu_exception_stop() const; QString osemu_fs_root() const; + bool reset_at_compile() const; QString elf() const; const MachineConfigCache &cache_program() const; const MachineConfigCache &cache_data() const; @@ -171,6 +174,7 @@ private: unsigned mem_acc_read, mem_acc_write, mem_acc_burst; bool osem_enable, osem_known_syscall_stop, osem_unknown_syscall_stop; bool osem_interrupt_stop, osem_exception_stop; + bool res_at_compile; QString osem_fs_root; QString elf_path; MachineConfigCache cch_program, cch_data; -- cgit v1.2.3