From 9bc338ad181fa65588bda2aa752cbd4828e62eec Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Fri, 20 Dec 2019 11:33:09 +0000 Subject: [PATCH] added memory viewer/editor to the debugger --- WindCore/emu.cpp | 13 +++ WindCore/emu.h | 2 + WindQt/mainwindow.cpp | 79 +++++++++++++ WindQt/mainwindow.h | 16 +++ WindQt/mainwindow.ui | 260 ++++++++++++++++++++++++++++++++---------- 5 files changed, 308 insertions(+), 62 deletions(-) diff --git a/WindCore/emu.cpp b/WindCore/emu.cpp index 848f08a..dd861cf 100644 --- a/WindCore/emu.cpp +++ b/WindCore/emu.cpp @@ -182,6 +182,19 @@ void Emu::writeReg32(uint32_t reg, uint32_t value) { } } +bool Emu::isPhysAddressValid(uint32_t physAddress) const { + uint8_t region = (physAddress >> 24) & 0xF1; + switch (region) { + case 0: return true; + case 0x80: return (physAddress <= 0x80000FFF); + case 0xC0: return true; + case 0xC1: return true; + case 0xD0: return true; + case 0xD1: return true; + default: return false; + } +} + uint32_t Emu::readPhys8(uint32_t physAddress) { uint32_t result = 0xFF; uint8_t region = (physAddress >> 24) & 0xF1; diff --git a/WindCore/emu.h b/WindCore/emu.h index 05ae799..5a96df6 100644 --- a/WindCore/emu.h +++ b/WindCore/emu.h @@ -45,6 +45,8 @@ class Emu { void writeReg32(uint32_t reg, uint32_t value); public: + bool isPhysAddressValid(uint32_t physAddress) const; + uint32_t readPhys8(uint32_t physAddress); uint32_t readPhys16(uint32_t physAddress); uint32_t readPhys32(uint32_t physAddress); diff --git a/WindQt/mainwindow.cpp b/WindQt/mainwindow.cpp index e0227d4..95168c0 100644 --- a/WindQt/mainwindow.cpp +++ b/WindQt/mainwindow.cpp @@ -30,6 +30,8 @@ void MainWindow::updateScreen() { ui->cycleCounter->setText(QString("Cycles: %1").arg(emu->currentCycles())); + updateMemory(); + ui->regsLabel->setText( QString("R0: %1 / R1: %2 / R2: %3 / R3: %4 / R4: %5 / R5: %6 / R6: %7 / R7: %8\nR8: %9 / R9: %10 / R10:%11 / R11:%12 / R12:%13 / SP: %14 / LR: %15 / PC: %16") .arg(emu->getGPR(0), 8, 16) @@ -260,3 +262,80 @@ void MainWindow::updateBreakpointsList() ui->breakpointsList->addItem(QString::number(addr, 16)); } } + +void MainWindow::on_memoryViewAddress_textEdited(const QString &) +{ + updateMemory(); +} + +void MainWindow::updateMemory() +{ + uint32_t virtBase = ui->memoryViewAddress->text().toUInt(nullptr, 16) & ~0xFF; + uint32_t physBase = emu->virtToPhys(virtBase); + bool ok = (physBase != 0xFFFFFFFF) && emu->isPhysAddressValid(physBase); + + uint8_t block[0x100]; + if (ok) { + for (int i = 0; i < 0x100; i++) { + block[i] = emu->readPhys8(physBase + i); + } + } + + QStringList output; + for (int row = 0; row < 16; row++) { + QString outLine; + outLine.reserve(8 + 2 + (2 * 16) + 3 + 16); + outLine.append(QStringLiteral("%1 |").arg(virtBase + (row * 16), 8, 16)); + for (int col = 0; col < 16; col++) { + if (ok) + outLine.append(QStringLiteral(" %1").arg(block[row*16+col], 2, 16, QLatin1Char('0'))); + else + outLine.append(QStringLiteral(" ??")); + } + outLine.append(QStringLiteral(" | ")); + for (int col = 0; col < 16; col++) { + uint8_t byte = block[row*16+col]; + if (!ok) + outLine.append('?'); + else if (byte >= 0x20 && byte <= 0x7E) + outLine.append(byte); + else + outLine.append('.'); + } + output.append(outLine); + } + + ui->memoryViewLabel->setText(output.join('\n')); +} + +void MainWindow::on_memoryAdd1_clicked() { adjustMemoryAddress(1); } +void MainWindow::on_memoryAdd4_clicked() { adjustMemoryAddress(4); } +void MainWindow::on_memoryAdd10_clicked() { adjustMemoryAddress(0x10); } +void MainWindow::on_memoryAdd100_clicked() { adjustMemoryAddress(0x100); } +void MainWindow::on_memorySub1_clicked() { adjustMemoryAddress(-1); } +void MainWindow::on_memorySub4_clicked() { adjustMemoryAddress(-4); } +void MainWindow::on_memorySub10_clicked() { adjustMemoryAddress(-0x10); } +void MainWindow::on_memorySub100_clicked() { adjustMemoryAddress(-0x100); } + +void MainWindow::adjustMemoryAddress(int offset) { + uint32_t address = ui->memoryViewAddress->text().toUInt(nullptr, 16); + address += offset; + ui->memoryViewAddress->setText(QString("%1").arg(address, 8, 16, QLatin1Char('0'))); + updateMemory(); +} + +void MainWindow::on_writeByteButton_clicked() +{ + uint32_t address = ui->memoryViewAddress->text().toUInt(nullptr, 16); + uint8_t value = (uint8_t)ui->memoryWriteValue->text().toUInt(nullptr, 16); + emu->writeVirt8(address, value); + updateMemory(); +} + +void MainWindow::on_writeDwordButton_clicked() +{ + uint32_t address = ui->memoryViewAddress->text().toUInt(nullptr, 16); + uint32_t value = ui->memoryWriteValue->text().toUInt(nullptr, 16); + emu->writeVirt32(address, value); + updateMemory(); +} diff --git a/WindQt/mainwindow.h b/WindQt/mainwindow.h index e7ea7a8..a127ade 100644 --- a/WindQt/mainwindow.h +++ b/WindQt/mainwindow.h @@ -28,12 +28,28 @@ private slots: void on_removeBreakButton_clicked(); + void on_memoryViewAddress_textEdited(const QString &arg1); + void on_memoryAdd1_clicked(); + void on_memoryAdd4_clicked(); + void on_memoryAdd10_clicked(); + void on_memoryAdd100_clicked(); + void on_memorySub1_clicked(); + void on_memorySub4_clicked(); + void on_memorySub10_clicked(); + void on_memorySub100_clicked(); + + void on_writeByteButton_clicked(); + + void on_writeDwordButton_clicked(); + private: Ui::MainWindow *ui; Emu *emu; QTimer *timer; void updateScreen(); void updateBreakpointsList(); + void updateMemory(); + void adjustMemoryAddress(int offset); protected: void keyPressEvent(QKeyEvent *event) override; diff --git a/WindQt/mainwindow.ui b/WindQt/mainwindow.ui index 337d05c..402a0aa 100644 --- a/WindQt/mainwindow.ui +++ b/WindQt/mainwindow.ui @@ -15,13 +15,46 @@ - - - - false + + + + Cycles + + + + + + + + Courier New + - Stop + + + + + + + + Start + + + + + + + Step (Tick) + + + + + + + Qt::ClickFocus + + + @@ -32,15 +65,174 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Stop + + + - 2 + 0 Memory + + + + + -1 + + + + + + + -100 + + + + + + + +4 + + + + + + + 00000000 + + + + + + + -10 + + + + + + + -4 + + + + + + + +10 + + + + + + + Address: + + + + + + + +1 + + + + + + + +100 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Write + + + + + + Dword + + + + + + + Byte + + + + + + + + + + + + + + Courier New + + + + TextLabel + + + + @@ -116,62 +308,6 @@ - - - - Qt::ClickFocus - - - - - - - - - - Start - - - - - - - Cycles - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Step (Tick) - - - - - - - - Courier New - - - - - - -