2017-09-13 11:33:45 -06:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/Debugger/RegisterWidget.h"
|
2017-09-13 11:33:45 -06:00
|
|
|
|
2018-06-19 11:36:52 -06:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2017-09-13 11:33:45 -06:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/HW/ProcessorInterface.h"
|
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2018-07-06 16:40:15 -06:00
|
|
|
#include "DolphinQt/Host.h"
|
|
|
|
#include "DolphinQt/Settings.h"
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
RegisterWidget::RegisterWidget(QWidget* parent) : QDockWidget(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Registers"));
|
2018-04-19 03:32:00 -06:00
|
|
|
setObjectName(QStringLiteral("registers"));
|
2017-09-13 11:33:45 -06:00
|
|
|
setAllowedAreas(Qt::AllDockWidgetAreas);
|
|
|
|
|
2018-03-23 05:10:53 -06:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
restoreGeometry(settings.value(QStringLiteral("registerwidget/geometry")).toByteArray());
|
|
|
|
setFloating(settings.value(QStringLiteral("registerwidget/floating")).toBool());
|
|
|
|
|
|
|
|
CreateWidgets();
|
|
|
|
PopulateTable();
|
|
|
|
ConnectWidgets();
|
|
|
|
|
2018-05-11 02:26:18 -06:00
|
|
|
connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, [this] {
|
2017-09-13 11:33:45 -06:00
|
|
|
if (Settings::Instance().IsDebugModeEnabled() && Core::GetState() == Core::State::Paused)
|
2018-05-11 02:26:18 -06:00
|
|
|
{
|
|
|
|
m_updating = true;
|
|
|
|
emit UpdateTable();
|
|
|
|
m_updating = false;
|
|
|
|
}
|
2017-09-13 11:33:45 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::RegistersVisibilityChanged,
|
|
|
|
[this](bool visible) { setHidden(!visible); });
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::DebugModeToggled, [this](bool enabled) {
|
|
|
|
setHidden(!enabled || !Settings::Instance().IsRegistersVisible());
|
|
|
|
});
|
|
|
|
|
|
|
|
setHidden(!Settings::Instance().IsRegistersVisible() ||
|
|
|
|
!Settings::Instance().IsDebugModeEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterWidget::~RegisterWidget()
|
|
|
|
{
|
2018-03-23 05:10:53 -06:00
|
|
|
auto& settings = Settings::GetQSettings();
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
settings.setValue(QStringLiteral("registerwidget/geometry"), saveGeometry());
|
|
|
|
settings.setValue(QStringLiteral("registerwidget/floating"), isFloating());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::closeEvent(QCloseEvent*)
|
|
|
|
{
|
|
|
|
Settings::Instance().SetRegistersVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::CreateWidgets()
|
|
|
|
{
|
|
|
|
m_table = new QTableWidget;
|
|
|
|
|
|
|
|
m_table->setColumnCount(9);
|
|
|
|
|
|
|
|
m_table->verticalHeader()->setVisible(false);
|
2018-04-22 09:52:31 -06:00
|
|
|
m_table->verticalHeader()->setDefaultSectionSize(24);
|
2017-09-13 11:33:45 -06:00
|
|
|
m_table->setContextMenuPolicy(Qt::CustomContextMenu);
|
2018-05-04 21:48:18 -06:00
|
|
|
m_table->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
m_table->setFont(Settings::Instance().GetDebugFont());
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
QStringList empty_list;
|
|
|
|
|
|
|
|
for (auto i = 0; i < 9; i++)
|
|
|
|
empty_list << QStringLiteral("");
|
|
|
|
|
|
|
|
m_table->setHorizontalHeaderLabels(empty_list);
|
|
|
|
|
|
|
|
QWidget* widget = new QWidget;
|
|
|
|
auto* layout = new QVBoxLayout;
|
|
|
|
layout->addWidget(m_table);
|
2018-08-02 13:50:23 -06:00
|
|
|
layout->setContentsMargins(2, 2, 2, 2);
|
2017-09-13 11:33:45 -06:00
|
|
|
widget->setLayout(layout);
|
|
|
|
|
|
|
|
setWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::ConnectWidgets()
|
|
|
|
{
|
|
|
|
connect(m_table, &QTableWidget::customContextMenuRequested, this,
|
|
|
|
&RegisterWidget::ShowContextMenu);
|
|
|
|
connect(m_table, &QTableWidget::itemChanged, this, &RegisterWidget::OnItemChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::OnItemChanged(QTableWidgetItem* item)
|
|
|
|
{
|
|
|
|
if (!item->data(DATA_TYPE).isNull() && !m_updating)
|
|
|
|
static_cast<RegisterColumn*>(item)->SetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::ShowContextMenu()
|
|
|
|
{
|
|
|
|
QMenu* menu = new QMenu(this);
|
|
|
|
|
2018-05-04 21:38:13 -06:00
|
|
|
auto variant = m_table->currentItem()->data(DATA_TYPE);
|
|
|
|
|
|
|
|
if (!variant.isNull())
|
2017-09-13 11:33:45 -06:00
|
|
|
{
|
2018-05-04 21:38:13 -06:00
|
|
|
auto* item = static_cast<RegisterColumn*>(m_table->currentItem());
|
|
|
|
auto type = static_cast<RegisterType>(item->data(DATA_TYPE).toInt());
|
|
|
|
auto display = item->GetDisplay();
|
|
|
|
|
2018-09-08 07:58:15 -06:00
|
|
|
// i18n: This kind of "watch" is used for watching emulated memory.
|
|
|
|
// It's not related to timekeeping devices.
|
2018-07-09 02:02:10 -06:00
|
|
|
menu->addAction(tr("Add to &watch"), this,
|
|
|
|
[this, item] { emit RequestMemoryBreakpoint(item->GetValue()); });
|
2018-05-04 21:38:13 -06:00
|
|
|
menu->addAction(tr("View &memory"));
|
|
|
|
menu->addAction(tr("View &code"));
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
QActionGroup* group = new QActionGroup(menu);
|
|
|
|
group->setExclusive(true);
|
|
|
|
|
|
|
|
auto* view_hex = menu->addAction(tr("Hexadecimal"));
|
|
|
|
auto* view_int = menu->addAction(tr("Signed Integer"));
|
|
|
|
auto* view_uint = menu->addAction(tr("Unsigned Integer"));
|
|
|
|
// i18n: A floating point number
|
|
|
|
auto* view_float = menu->addAction(tr("Float"));
|
|
|
|
// i18n: A double precision floating point number
|
|
|
|
auto* view_double = menu->addAction(tr("Double"));
|
|
|
|
|
|
|
|
for (auto* action : {view_hex, view_int, view_uint, view_float, view_double})
|
|
|
|
{
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setVisible(false);
|
|
|
|
action->setActionGroup(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (display)
|
|
|
|
{
|
|
|
|
case RegisterDisplay::Hex:
|
|
|
|
view_hex->setChecked(true);
|
|
|
|
break;
|
|
|
|
case RegisterDisplay::SInt32:
|
|
|
|
view_int->setChecked(true);
|
|
|
|
break;
|
|
|
|
case RegisterDisplay::UInt32:
|
|
|
|
view_uint->setChecked(true);
|
|
|
|
break;
|
|
|
|
case RegisterDisplay::Float:
|
|
|
|
view_float->setChecked(true);
|
|
|
|
break;
|
|
|
|
case RegisterDisplay::Double:
|
|
|
|
view_double->setChecked(true);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-13 11:33:45 -06:00
|
|
|
|
2018-05-04 21:38:13 -06:00
|
|
|
switch (type)
|
2017-09-13 11:33:45 -06:00
|
|
|
{
|
2018-05-04 21:38:13 -06:00
|
|
|
case RegisterType::gpr:
|
|
|
|
view_hex->setVisible(true);
|
|
|
|
view_int->setVisible(true);
|
|
|
|
view_uint->setVisible(true);
|
|
|
|
view_float->setVisible(true);
|
|
|
|
break;
|
|
|
|
case RegisterType::fpr:
|
|
|
|
view_hex->setVisible(true);
|
|
|
|
view_double->setVisible(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-09-13 11:33:45 -06:00
|
|
|
}
|
2018-05-04 21:38:13 -06:00
|
|
|
|
|
|
|
connect(view_hex, &QAction::triggered, [this, item] {
|
|
|
|
m_updating = true;
|
|
|
|
item->SetDisplay(RegisterDisplay::Hex);
|
|
|
|
m_updating = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(view_int, &QAction::triggered, [this, item] {
|
|
|
|
m_updating = true;
|
|
|
|
item->SetDisplay(RegisterDisplay::SInt32);
|
|
|
|
m_updating = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(view_uint, &QAction::triggered, [this, item] {
|
|
|
|
m_updating = true;
|
|
|
|
item->SetDisplay(RegisterDisplay::UInt32);
|
|
|
|
m_updating = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(view_float, &QAction::triggered, [this, item] {
|
|
|
|
m_updating = true;
|
|
|
|
item->SetDisplay(RegisterDisplay::Float);
|
|
|
|
m_updating = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(view_double, &QAction::triggered, [this, item] {
|
|
|
|
m_updating = true;
|
|
|
|
item->SetDisplay(RegisterDisplay::Double);
|
|
|
|
m_updating = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
menu->addSeparator();
|
2017-09-13 11:33:45 -06:00
|
|
|
}
|
|
|
|
|
2018-07-09 02:02:10 -06:00
|
|
|
menu->addAction(tr("Update"), this, [this] { emit RequestTableUpdate(); });
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
menu->exec(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::PopulateTable()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
// General purpose registers (int)
|
|
|
|
AddRegister(i, 0, RegisterType::gpr, "r" + std::to_string(i), [i] { return GPR(i); },
|
|
|
|
[i](u64 value) { GPR(i) = value; });
|
|
|
|
|
2018-01-13 00:46:44 -07:00
|
|
|
// Floating point registers (double)
|
2018-12-14 11:23:12 -07:00
|
|
|
AddRegister(i, 2, RegisterType::fpr, "f" + std::to_string(i), [i] { return rPS(i).PS0AsU64(); },
|
|
|
|
[i](u64 value) { rPS(i).SetPS0(value); });
|
2017-09-13 11:33:45 -06:00
|
|
|
|
2018-12-14 11:23:12 -07:00
|
|
|
AddRegister(i, 4, RegisterType::fpr, "", [i] { return rPS(i).PS1AsU64(); },
|
|
|
|
[i](u64 value) { rPS(i).SetPS1(value); });
|
2017-09-13 11:33:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
// IBAT registers
|
|
|
|
AddRegister(i, 5, RegisterType::ibat, "IBAT" + std::to_string(i),
|
|
|
|
[i] {
|
|
|
|
return (static_cast<u64>(PowerPC::ppcState.spr[SPR_IBAT0U + i * 2]) << 32) +
|
|
|
|
PowerPC::ppcState.spr[SPR_IBAT0L + i * 2];
|
|
|
|
},
|
|
|
|
nullptr);
|
|
|
|
// DBAT registers
|
|
|
|
AddRegister(i + 8, 5, RegisterType::dbat, "DBAT" + std::to_string(i),
|
|
|
|
[i] {
|
|
|
|
return (static_cast<u64>(PowerPC::ppcState.spr[SPR_DBAT0U + i * 2]) << 32) +
|
|
|
|
PowerPC::ppcState.spr[SPR_DBAT0L + i * 2];
|
|
|
|
},
|
|
|
|
nullptr);
|
2018-01-07 03:26:55 -07:00
|
|
|
// Graphics quantization registers
|
|
|
|
AddRegister(i + 16, 7, RegisterType::gqr, "GQR" + std::to_string(i),
|
|
|
|
[i] { return PowerPC::ppcState.spr[SPR_GQR0 + i]; }, nullptr);
|
2017-09-13 11:33:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
// SR registers
|
|
|
|
AddRegister(i, 7, RegisterType::sr, "SR" + std::to_string(i),
|
|
|
|
[i] { return PowerPC::ppcState.sr[i]; },
|
|
|
|
[i](u64 value) { PowerPC::ppcState.sr[i] = value; });
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special registers
|
2018-01-07 03:26:55 -07:00
|
|
|
// TB
|
2018-06-19 11:06:37 -06:00
|
|
|
AddRegister(16, 5, RegisterType::tb, "TB", PowerPC::ReadFullTimeBaseValue, nullptr);
|
2018-01-07 03:26:55 -07:00
|
|
|
|
2017-09-13 11:33:45 -06:00
|
|
|
// PC
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(17, 5, RegisterType::pc, "PC", [] { return PowerPC::ppcState.pc; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.pc = value; });
|
|
|
|
|
|
|
|
// LR
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(18, 5, RegisterType::lr, "LR", [] { return PowerPC::ppcState.spr[SPR_LR]; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.spr[SPR_LR] = value; });
|
|
|
|
|
|
|
|
// CTR
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(19, 5, RegisterType::ctr, "CTR", [] { return PowerPC::ppcState.spr[SPR_CTR]; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.spr[SPR_CTR] = value; });
|
|
|
|
|
|
|
|
// CR
|
2018-12-22 08:09:44 -07:00
|
|
|
AddRegister(20, 5, RegisterType::cr, "CR", [] { return PowerPC::ppcState.cr.Get(); },
|
|
|
|
[](u64 value) { PowerPC::ppcState.cr.Set(value); });
|
2017-09-13 11:33:45 -06:00
|
|
|
|
2018-01-07 03:26:55 -07:00
|
|
|
// XER
|
2018-03-22 16:24:04 -06:00
|
|
|
AddRegister(21, 5, RegisterType::xer, "XER", [] { return PowerPC::GetXER().Hex; },
|
|
|
|
[](u64 value) { PowerPC::SetXER(UReg_XER(value)); });
|
2018-01-07 03:26:55 -07:00
|
|
|
|
2017-09-13 11:33:45 -06:00
|
|
|
// FPSCR
|
2018-05-06 16:22:19 -06:00
|
|
|
AddRegister(22, 5, RegisterType::fpscr, "FPSCR", [] { return PowerPC::ppcState.fpscr.Hex; },
|
2018-06-12 11:22:49 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.fpscr = static_cast<u32>(value); });
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
// MSR
|
2018-05-05 15:02:58 -06:00
|
|
|
AddRegister(23, 5, RegisterType::msr, "MSR", [] { return PowerPC::ppcState.msr.Hex; },
|
|
|
|
[](u64 value) { PowerPC::ppcState.msr.Hex = value; });
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
// SRR 0-1
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(24, 5, RegisterType::srr, "SRR0", [] { return PowerPC::ppcState.spr[SPR_SRR0]; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.spr[SPR_SRR0] = value; });
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(25, 5, RegisterType::srr, "SRR1", [] { return PowerPC::ppcState.spr[SPR_SRR1]; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.spr[SPR_SRR1] = value; });
|
|
|
|
|
|
|
|
// Exceptions
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(26, 5, RegisterType::exceptions, "Exceptions",
|
2017-09-13 11:33:45 -06:00
|
|
|
[] { return PowerPC::ppcState.Exceptions; },
|
|
|
|
[](u64 value) { PowerPC::ppcState.Exceptions = value; });
|
|
|
|
|
|
|
|
// Int Mask
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(27, 5, RegisterType::int_mask, "Int Mask",
|
2017-09-13 11:33:45 -06:00
|
|
|
[] { return ProcessorInterface::GetMask(); }, nullptr);
|
|
|
|
|
|
|
|
// Int Cause
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(28, 5, RegisterType::int_cause, "Int Cause",
|
2017-09-13 11:33:45 -06:00
|
|
|
[] { return ProcessorInterface::GetCause(); }, nullptr);
|
|
|
|
|
|
|
|
// DSISR
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(29, 5, RegisterType::dsisr, "DSISR", [] { return PowerPC::ppcState.spr[SPR_DSISR]; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.spr[SPR_DSISR] = value; });
|
|
|
|
// DAR
|
2018-01-07 03:26:55 -07:00
|
|
|
AddRegister(30, 5, RegisterType::dar, "DAR", [] { return PowerPC::ppcState.spr[SPR_DAR]; },
|
2017-09-13 11:33:45 -06:00
|
|
|
[](u64 value) { PowerPC::ppcState.spr[SPR_DAR] = value; });
|
|
|
|
|
|
|
|
// Hash Mask
|
|
|
|
AddRegister(
|
2018-01-07 03:26:55 -07:00
|
|
|
31, 5, RegisterType::pt_hashmask, "Hash Mask",
|
2017-09-13 11:33:45 -06:00
|
|
|
[] { return (PowerPC::ppcState.pagetable_hashmask << 6) | PowerPC::ppcState.pagetable_base; },
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
emit RequestTableUpdate();
|
|
|
|
m_table->resizeColumnsToContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterWidget::AddRegister(int row, int column, RegisterType type, std::string register_name,
|
2018-01-13 00:21:32 -07:00
|
|
|
std::function<u64()> get_reg, std::function<void(u64)> set_reg)
|
2017-09-13 11:33:45 -06:00
|
|
|
{
|
2018-06-19 11:36:52 -06:00
|
|
|
auto* value = new RegisterColumn(type, std::move(get_reg), std::move(set_reg));
|
2017-09-13 11:33:45 -06:00
|
|
|
|
|
|
|
if (m_table->rowCount() <= row)
|
|
|
|
m_table->setRowCount(row + 1);
|
|
|
|
|
|
|
|
bool has_label = !register_name.empty();
|
|
|
|
|
|
|
|
if (has_label)
|
|
|
|
{
|
|
|
|
auto* label = new QTableWidgetItem(QString::fromStdString(register_name));
|
|
|
|
label->setFlags(Qt::ItemIsEnabled);
|
|
|
|
|
|
|
|
QFont label_font = label->font();
|
|
|
|
label_font.setBold(true);
|
|
|
|
label->setFont(label_font);
|
|
|
|
|
|
|
|
m_table->setItem(row, column, label);
|
|
|
|
m_table->setItem(row, column + 1, value);
|
2018-05-04 21:48:18 -06:00
|
|
|
m_table->item(row, column + 1)->setTextAlignment(Qt::AlignRight);
|
2017-09-13 11:33:45 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_table->setItem(row, column, value);
|
2018-05-04 21:48:18 -06:00
|
|
|
m_table->item(row, column)->setTextAlignment(Qt::AlignRight);
|
2017-09-13 11:33:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
connect(this, &RegisterWidget::UpdateTable, [value] { value->RefreshValue(); });
|
|
|
|
}
|