Skip to content

Commit 14153a3

Browse files
nemecadjdupak
authored andcommitted
GUI: add "As CPU (VMA)" memory access view
Introduce an "As CPU (VMA)" access option in the cached access selector to render memory contents as observed by the CPU through the frontend interface.
1 parent 3980283 commit 14153a3

File tree

5 files changed

+67
-27
lines changed

5 files changed

+67
-27
lines changed

src/gui/windows/memory/memorydock.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : Super(parent) {
2424
auto *cached_access = new QComboBox();
2525
cached_access->addItem("Direct", 0);
2626
cached_access->addItem("Cached", 1);
27+
cached_access->addItem("As CPU (VMA)", 2);
2728

2829
auto *memory_content = new MemoryTableView(nullptr, settings);
2930
// memory_content->setSizePolicy();
@@ -37,7 +38,6 @@ MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : Super(parent) {
3738
auto *layout_top = new QHBoxLayout;
3839
layout_top->addWidget(cell_size);
3940
layout_top->addWidget(cached_access);
40-
4141
auto *layout = new QVBoxLayout;
4242
layout->addLayout(layout_top);
4343
layout->addWidget(memory_content);
@@ -47,27 +47,23 @@ MemoryDock::MemoryDock(QWidget *parent, QSettings *settings) : Super(parent) {
4747

4848
setWidget(content);
4949

50+
connect(this, &MemoryDock::machine_setup, memory_model, &MemoryModel::setup);
51+
connect(this, &MemoryDock::machine_setup, memory_model, &MemoryModel::setup);
5052
connect(
51-
this, &MemoryDock::machine_setup, memory_model, &MemoryModel::setup);
52-
connect(
53-
cell_size, QOverload<int>::of(&QComboBox::currentIndexChanged),
54-
memory_content, &MemoryTableView::set_cell_size);
53+
cell_size, QOverload<int>::of(&QComboBox::currentIndexChanged), memory_content,
54+
&MemoryTableView::set_cell_size);
5555
connect(
56-
cached_access, QOverload<int>::of(&QComboBox::currentIndexChanged),
57-
memory_model, &MemoryModel::cached_access);
56+
cached_access, QOverload<int>::of(&QComboBox::currentIndexChanged), memory_model,
57+
&MemoryModel::cached_access);
5858
connect(
5959
go_edit, &HexLineEdit::value_edit_finished, memory_content,
6060
[memory_content](uint32_t value) {
6161
memory_content->go_to_address(machine::Address(value));
6262
});
6363
connect(
6464
memory_content, &MemoryTableView::address_changed, go_edit,
65-
[go_edit](machine::Address addr) {
66-
go_edit->set_value(addr.get_raw());
67-
});
68-
connect(
69-
this, &MemoryDock::focus_addr, memory_content,
70-
&MemoryTableView::focus_address);
65+
[go_edit](machine::Address addr) { go_edit->set_value(addr.get_raw()); });
66+
connect(this, &MemoryDock::focus_addr, memory_content, &MemoryTableView::focus_address);
7167
connect(
7268
memory_model, &MemoryModel::setup_done, memory_content,
7369
&MemoryTableView::recompute_columns);

src/gui/windows/memory/memorydock.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
#include "machine/machine.h"
55
#include "machine/memory/address.h"
6-
76
#include <QComboBox>
87
#include <QDockWidget>
9-
#include <QLabel>
108

119
class MemoryDock : public QDockWidget {
1210
Q_OBJECT
@@ -18,11 +16,12 @@ class MemoryDock : public QDockWidget {
1816

1917
void setup(machine::Machine *machine);
2018

21-
signals:
22-
void machine_setup(machine::Machine *machine);
19+
signals:
20+
void machine_setup(machine::Machine *machine);
2321
void focus_addr(machine::Address);
2422

2523
private:
24+
machine::Machine *machinePtr;
2625
};
2726

28-
#endif // MEMORYDOCK_H
27+
#endif // MEMORYDOCK_H

src/gui/windows/memory/memorymodel.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,28 @@ QVariant MemoryModel::data(const QModelIndex &index, int role) const {
5959
QString s, t;
6060
machine::Address address;
6161
uint32_t data;
62-
const machine::FrontendMemory *mem;
62+
const machine::FrontendMemory *mem = nullptr;
6363
if (!get_row_address(address, index.row())) { return QString(""); }
6464
if (index.column() == 0) {
6565
t = QString::number(address.get_raw(), 16);
6666
s.fill('0', 8 - t.count());
6767
return { QString("0x") + s + t };
6868
}
6969
if (machine == nullptr) { return QString(""); }
70-
mem = mem_access();
71-
if (mem == nullptr) { return QString(""); }
72-
if ((access_through_cache > 0) && (machine->cache_data() != nullptr)) {
73-
mem = machine->cache_data();
70+
bool vm_enabled = machine->config().get_vm_enabled();
71+
if (!vm_enabled) {
72+
mem = mem_access();
73+
if ((access_through_cache > 0) && (machine->cache_data() != nullptr)) {
74+
mem = machine->cache_data();
75+
}
76+
} else {
77+
if (access_through_cache == 2) {
78+
mem = machine->get_tlb_data();
79+
} else {
80+
mem = mem_access_phys();
81+
}
7482
}
83+
if (mem == nullptr) { return QString(""); }
7584
address += cellSizeBytes() * (index.column() - 1);
7685
if (address < index0_offset) { return QString(""); }
7786
switch (cell_size) {
@@ -192,12 +201,10 @@ bool MemoryModel::adjustRowAndOffset(int &row, machine::Address address) {
192201
}
193202
return get_row_for_address(row, address);
194203
}
195-
196204
void MemoryModel::cached_access(int cached) {
197205
access_through_cache = cached;
198206
update_all();
199207
}
200-
201208
Qt::ItemFlags MemoryModel::flags(const QModelIndex &index) const {
202209
if (index.column() == 0) {
203210
return QAbstractTableModel::flags(index);
@@ -215,7 +222,18 @@ bool MemoryModel::setData(const QModelIndex &index, const QVariant &value, int r
215222
if (!ok) { return false; }
216223
if (!get_row_address(address, index.row())) { return false; }
217224
if (index.column() == 0 || machine == nullptr) { return false; }
218-
mem = mem_access_rw();
225+
if (machine->config().get_vm_enabled()) {
226+
if (access_through_cache == 2) {
227+
mem = machine->get_tlb_data_rw();
228+
} else {
229+
mem = mem_access_phys_rw();
230+
}
231+
} else {
232+
mem = mem_access_rw();
233+
if (access_through_cache > 0 && machine->cache_data_rw()) {
234+
mem = machine->cache_data_rw();
235+
}
236+
}
219237
if (mem == nullptr) { return false; }
220238
if ((access_through_cache > 0) && (machine->cache_data_rw() != nullptr)) {
221239
mem = machine->cache_data_rw();
@@ -230,3 +248,21 @@ bool MemoryModel::setData(const QModelIndex &index, const QVariant &value, int r
230248
}
231249
return true;
232250
}
251+
252+
const machine::FrontendMemory *MemoryModel::mem_access_phys() const {
253+
if (!machine) return nullptr;
254+
if (access_through_cache > 0 && machine->cache_data()) {
255+
return machine->cache_data();
256+
} else {
257+
return machine->memory_data_bus();
258+
}
259+
}
260+
261+
machine::FrontendMemory *MemoryModel::mem_access_phys_rw() const {
262+
if (!machine) return nullptr;
263+
if (access_through_cache > 0 && machine->cache_data_rw()) {
264+
return machine->cache_data_rw();
265+
} else {
266+
return machine->memory_data_bus_rw();
267+
}
268+
}

src/gui/windows/memory/memorymodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class MemoryModel : public QAbstractTableModel {
6969
}
7070
return true;
7171
}
72-
7372
public slots:
7473
void setup(machine::Machine *machine);
7574
void set_cell_size(int index);
@@ -83,6 +82,8 @@ public slots:
8382
private:
8483
[[nodiscard]] const machine::FrontendMemory *mem_access() const;
8584
[[nodiscard]] machine::FrontendMemory *mem_access_rw() const;
85+
[[nodiscard]] const machine::FrontendMemory *mem_access_phys() const;
86+
[[nodiscard]] machine::FrontendMemory *mem_access_phys_rw() const;
8687
enum MemoryCellSize cell_size;
8788
unsigned int cells_per_row;
8889
machine::Address index0_offset;

src/machine/machine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ class Machine : public QObject {
9292
bool get_step_over_exception(enum ExceptionCause excause) const;
9393
enum ExceptionCause get_exception_cause() const;
9494

95+
Address virtual_to_physical(Address v) {
96+
if (tlb_data) {
97+
return tlb_data->translate_virtual_to_physical(v);
98+
} else {
99+
return v;
100+
}
101+
}
102+
95103
public slots:
96104
void play();
97105
void pause();

0 commit comments

Comments
 (0)