Merge pull request #4260 from lioncash/debugger

RegisterView: Minor changes
This commit is contained in:
shuffle2 2016-10-02 20:34:10 -07:00 committed by GitHub
commit 53cb04f07e
2 changed files with 212 additions and 213 deletions

View File

@ -23,6 +23,8 @@
// F-zero 80005e60 wtf?? // F-zero 80005e60 wtf??
namespace
{
enum enum
{ {
IDM_WATCHADDRESS, IDM_WATCHADDRESS,
@ -36,168 +38,32 @@ enum
IDM_VIEW_INT IDM_VIEW_INT
}; };
enum class FormatSpecifier
{
Hex8,
Hex16,
Float,
Double,
UInt,
Int
};
constexpr const char* special_reg_names[] = {"PC", "LR", "CTR", "CR", "FPSCR", constexpr const char* special_reg_names[] = {"PC", "LR", "CTR", "CR", "FPSCR",
"MSR", "SRR0", "SRR1", "Exceptions", "Int Mask", "MSR", "SRR0", "SRR1", "Exceptions", "Int Mask",
"Int Cause", "DSISR", "DAR", "PT hashmask"}; "Int Cause", "DSISR", "DAR", "PT hashmask"};
CRegTable::CRegTable() wxString GetFormatString(CRegTable::FormatSpecifier specifier)
{
m_formatRegs.fill(FormatSpecifier::Hex8);
for (auto& entry : m_formatFRegs)
entry.fill(FormatSpecifier::Hex16);
memset(m_CachedRegs, 0, sizeof(m_CachedRegs));
memset(m_CachedSpecialRegs, 0, sizeof(m_CachedSpecialRegs));
memset(m_CachedFRegs, 0, sizeof(m_CachedFRegs));
memset(m_CachedRegHasChanged, 0, sizeof(m_CachedRegHasChanged));
memset(m_CachedSpecialRegHasChanged, 0, sizeof(m_CachedSpecialRegHasChanged));
memset(m_CachedFRegHasChanged, 0, sizeof(m_CachedFRegHasChanged));
}
wxString CRegTable::GetFormatString(FormatSpecifier specifier)
{ {
switch (specifier) switch (specifier)
{ {
case FormatSpecifier::Hex8: case CRegTable::FormatSpecifier::Hex8:
return wxString("%08x"); return wxString("%08x");
case FormatSpecifier::Hex16: case CRegTable::FormatSpecifier::Hex16:
return wxString("%016llx"); return wxString("%016llx");
case FormatSpecifier::Float: case CRegTable::FormatSpecifier::Float:
return wxString("%g"); return wxString("%g");
case FormatSpecifier::Double: case CRegTable::FormatSpecifier::Double:
return wxString("%g"); return wxString("%g");
case FormatSpecifier::UInt: case CRegTable::FormatSpecifier::UInt:
return wxString("%u"); return wxString("%u");
case FormatSpecifier::Int: case CRegTable::FormatSpecifier::Int:
return wxString("%i"); return wxString("%i");
default: default:
return wxString(""); return wxString("");
} }
} }
wxString CRegTable::FormatGPR(int reg_index) u32 GetSpecialRegValue(int reg)
{
if (m_formatRegs[reg_index] == FormatSpecifier::Int)
{
return wxString::Format(GetFormatString(m_formatRegs[reg_index]),
static_cast<s32>(GPR(reg_index)));
}
if (m_formatRegs[reg_index] == FormatSpecifier::Float)
{
float value;
std::memcpy(&value, &GPR(reg_index), sizeof(float));
return wxString::Format(GetFormatString(m_formatRegs[reg_index]), value);
}
return wxString::Format(GetFormatString(m_formatRegs[reg_index]), GPR(reg_index));
}
wxString CRegTable::FormatFPR(int reg_index, int reg_part)
{
if (m_formatFRegs[reg_index][reg_part] == FormatSpecifier::Double)
{
double reg = (reg_part == 0) ? rPS0(reg_index) : rPS1(reg_index);
return wxString::Format(GetFormatString(m_formatFRegs[reg_index][reg_part]), reg);
}
u64 reg = (reg_part == 0) ? riPS0(reg_index) : riPS1(reg_index);
return wxString::Format(GetFormatString(m_formatFRegs[reg_index][reg_part]), reg);
}
bool CRegTable::TryParseGPR(wxString str, FormatSpecifier format, u32* value)
{
if (format == FormatSpecifier::Hex8)
{
unsigned long val;
if (str.ToCULong(&val, 16))
{
*value = static_cast<u32>(val);
return true;
}
return false;
}
if (format == FormatSpecifier::Int)
{
long signed_val;
if (str.ToCLong(&signed_val))
{
*value = static_cast<u32>(signed_val);
return true;
}
return false;
}
if (format == FormatSpecifier::UInt)
{
unsigned long val;
if (str.ToCULong(&val))
{
*value = static_cast<u32>(val);
return true;
}
return false;
}
if (format == FormatSpecifier::Float)
{
double double_val;
if (str.ToCDouble(&double_val))
{
float float_val = static_cast<float>(double_val);
std::memcpy(value, &float_val, sizeof(float));
return true;
}
return false;
}
return false;
}
bool CRegTable::TryParseFPR(wxString str, FormatSpecifier format, unsigned long long* value)
{
if (format == FormatSpecifier::Hex16)
{
return str.ToULongLong(value, 16);
}
if (format == FormatSpecifier::Double)
{
double double_val;
if (str.ToCDouble(&double_val))
{
std::memcpy(value, &double_val, sizeof(u64));
return true;
}
return false;
}
return false;
}
void CRegTable::SetRegisterFormat(int col, int row, FormatSpecifier specifier)
{
if (row >= 32)
return;
switch (col)
{
case 1:
m_formatRegs[row] = specifier;
return;
case 3:
m_formatFRegs[row][0] = specifier;
return;
case 4:
m_formatFRegs[row][1] = specifier;
return;
}
}
u32 CRegTable::GetSpecialRegValue(int reg)
{ {
switch (reg) switch (reg)
{ {
@ -234,6 +100,176 @@ u32 CRegTable::GetSpecialRegValue(int reg)
} }
} }
void SetSpecialRegValue(int reg, u32 value)
{
switch (reg)
{
case 0:
PowerPC::ppcState.pc = value;
break;
case 1:
PowerPC::ppcState.spr[SPR_LR] = value;
break;
case 2:
PowerPC::ppcState.spr[SPR_CTR] = value;
break;
case 3:
SetCR(value);
break;
case 4:
PowerPC::ppcState.fpscr = value;
break;
case 5:
PowerPC::ppcState.msr = value;
break;
case 6:
PowerPC::ppcState.spr[SPR_SRR0] = value;
break;
case 7:
PowerPC::ppcState.spr[SPR_SRR1] = value;
break;
case 8:
PowerPC::ppcState.Exceptions = value;
break;
// Should we just change the value, or use ProcessorInterface::SetInterrupt() to make the system
// aware?
// case 9: return ProcessorInterface::GetMask();
// case 10: return ProcessorInterface::GetCause();
case 11:
PowerPC::ppcState.spr[SPR_DSISR] = value;
break;
case 12:
PowerPC::ppcState.spr[SPR_DAR] = value;
break;
// case 13: (PowerPC::ppcState.pagetable_hashmask << 6) | PowerPC::ppcState.pagetable_base;
default:
return;
}
}
bool TryParseFPR(wxString str, CRegTable::FormatSpecifier format, unsigned long long* value)
{
if (format == CRegTable::FormatSpecifier::Hex16)
return str.ToULongLong(value, 16);
if (format == CRegTable::FormatSpecifier::Double)
{
double double_val;
if (str.ToCDouble(&double_val))
{
std::memcpy(value, &double_val, sizeof(u64));
return true;
}
return false;
}
return false;
}
bool TryParseGPR(wxString str, CRegTable::FormatSpecifier format, u32* value)
{
if (format == CRegTable::FormatSpecifier::Hex8)
{
unsigned long val;
if (str.ToCULong(&val, 16))
{
*value = static_cast<u32>(val);
return true;
}
return false;
}
if (format == CRegTable::FormatSpecifier::Int)
{
long signed_val;
if (str.ToCLong(&signed_val))
{
*value = static_cast<u32>(signed_val);
return true;
}
return false;
}
if (format == CRegTable::FormatSpecifier::UInt)
{
unsigned long val;
if (str.ToCULong(&val))
{
*value = static_cast<u32>(val);
return true;
}
return false;
}
if (format == CRegTable::FormatSpecifier::Float)
{
double double_val;
if (str.ToCDouble(&double_val))
{
float float_val = static_cast<float>(double_val);
std::memcpy(value, &float_val, sizeof(float));
return true;
}
return false;
}
return false;
}
} // Anonymous namespace
CRegTable::CRegTable()
{
for (auto& entry : m_formatFRegs)
entry.fill(FormatSpecifier::Hex16);
}
wxString CRegTable::FormatGPR(int reg_index)
{
if (m_formatRegs[reg_index] == FormatSpecifier::Int)
{
return wxString::Format(GetFormatString(m_formatRegs[reg_index]),
static_cast<s32>(GPR(reg_index)));
}
if (m_formatRegs[reg_index] == FormatSpecifier::Float)
{
float value;
std::memcpy(&value, &GPR(reg_index), sizeof(float));
return wxString::Format(GetFormatString(m_formatRegs[reg_index]), value);
}
return wxString::Format(GetFormatString(m_formatRegs[reg_index]), GPR(reg_index));
}
wxString CRegTable::FormatFPR(int reg_index, int reg_part)
{
if (m_formatFRegs[reg_index][reg_part] == FormatSpecifier::Double)
{
double reg = (reg_part == 0) ? rPS0(reg_index) : rPS1(reg_index);
return wxString::Format(GetFormatString(m_formatFRegs[reg_index][reg_part]), reg);
}
u64 reg = (reg_part == 0) ? riPS0(reg_index) : riPS1(reg_index);
return wxString::Format(GetFormatString(m_formatFRegs[reg_index][reg_part]), reg);
}
void CRegTable::SetRegisterFormat(int col, int row, FormatSpecifier specifier)
{
if (row >= 32)
return;
switch (col)
{
case 1:
m_formatRegs[row] = specifier;
return;
case 3:
m_formatFRegs[row][0] = specifier;
return;
case 4:
m_formatFRegs[row][1] = specifier;
return;
}
}
wxString CRegTable::GetValue(int row, int col) wxString CRegTable::GetValue(int row, int col)
{ {
if (row < 32) if (row < 32)
@ -325,53 +361,6 @@ wxString CRegTable::GetValue(int row, int col)
return wxEmptyString; return wxEmptyString;
} }
void CRegTable::SetSpecialRegValue(int reg, u32 value)
{
switch (reg)
{
case 0:
PowerPC::ppcState.pc = value;
break;
case 1:
PowerPC::ppcState.spr[SPR_LR] = value;
break;
case 2:
PowerPC::ppcState.spr[SPR_CTR] = value;
break;
case 3:
SetCR(value);
break;
case 4:
PowerPC::ppcState.fpscr = value;
break;
case 5:
PowerPC::ppcState.msr = value;
break;
case 6:
PowerPC::ppcState.spr[SPR_SRR0] = value;
break;
case 7:
PowerPC::ppcState.spr[SPR_SRR1] = value;
break;
case 8:
PowerPC::ppcState.Exceptions = value;
break;
// Should we just change the value, or use ProcessorInterface::SetInterrupt() to make the system
// aware?
// case 9: return ProcessorInterface::GetMask();
// case 10: return ProcessorInterface::GetCause();
case 11:
PowerPC::ppcState.spr[SPR_DSISR] = value;
break;
case 12:
PowerPC::ppcState.spr[SPR_DAR] = value;
break;
// case 13: (PowerPC::ppcState.pagetable_hashmask << 6) | PowerPC::ppcState.pagetable_base;
default:
return;
}
}
void CRegTable::SetValue(int row, int col, const wxString& strNewVal) void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
{ {
if (row < 32) if (row < 32)
@ -541,27 +530,33 @@ void CRegisterView::OnPopupMenu(wxCommandEvent& event)
Refresh(); Refresh();
break; break;
case IDM_VIEW_HEX8: case IDM_VIEW_HEX8:
m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow, FormatSpecifier::Hex8); m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow,
CRegTable::FormatSpecifier::Hex8);
Refresh(); Refresh();
break; break;
case IDM_VIEW_HEX16: case IDM_VIEW_HEX16:
m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow, FormatSpecifier::Hex16); m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow,
CRegTable::FormatSpecifier::Hex16);
Refresh(); Refresh();
break; break;
case IDM_VIEW_INT: case IDM_VIEW_INT:
m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow, FormatSpecifier::Int); m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow,
CRegTable::FormatSpecifier::Int);
Refresh(); Refresh();
break; break;
case IDM_VIEW_UINT: case IDM_VIEW_UINT:
m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow, FormatSpecifier::UInt); m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow,
CRegTable::FormatSpecifier::UInt);
Refresh(); Refresh();
break; break;
case IDM_VIEW_FLOAT: case IDM_VIEW_FLOAT:
m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow, FormatSpecifier::Float); m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow,
CRegTable::FormatSpecifier::Float);
Refresh(); Refresh();
break; break;
case IDM_VIEW_DOUBLE: case IDM_VIEW_DOUBLE:
m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow, FormatSpecifier::Double); m_register_table->SetRegisterFormat(m_selectedColumn, m_selectedRow,
CRegTable::FormatSpecifier::Double);
Refresh(); Refresh();
break; break;
} }

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <cstddef>
#include <cstring> #include <cstring>
#include <wx/grid.h> #include <wx/grid.h>
@ -26,13 +27,19 @@
// Interrupt Mask (PI) // Interrupt Mask (PI)
// Interrupt Cause(PI) // Interrupt Cause(PI)
#define NUM_SPECIALS 14
enum class FormatSpecifier;
class CRegTable : public wxGridTableBase class CRegTable : public wxGridTableBase
{ {
public: public:
enum class FormatSpecifier
{
Hex8,
Hex16,
Float,
Double,
UInt,
Int
};
CRegTable(); CRegTable();
int GetNumberCols() override { return 9; } int GetNumberCols() override { return 9; }
int GetNumberRows() override { return 32 + NUM_SPECIALS; } int GetNumberRows() override { return 32 + NUM_SPECIALS; }
@ -44,22 +51,19 @@ public:
void UpdateCachedRegs(); void UpdateCachedRegs();
private: private:
u32 m_CachedRegs[32]; static constexpr size_t NUM_SPECIALS = 14;
u32 m_CachedSpecialRegs[NUM_SPECIALS];
u64 m_CachedFRegs[32][2]; std::array<u32, 32> m_CachedRegs{};
bool m_CachedRegHasChanged[32]; std::array<u32, NUM_SPECIALS> m_CachedSpecialRegs{};
bool m_CachedSpecialRegHasChanged[NUM_SPECIALS]; std::array<std::array<u64, 2>, 32> m_CachedFRegs{};
bool m_CachedFRegHasChanged[32][2]; std::array<bool, 32> m_CachedRegHasChanged{};
std::array<FormatSpecifier, 32> m_formatRegs; std::array<bool, NUM_SPECIALS> m_CachedSpecialRegHasChanged{};
std::array<std::array<bool, 2>, 32> m_CachedFRegHasChanged{};
std::array<FormatSpecifier, 32> m_formatRegs{};
std::array<std::array<FormatSpecifier, 2>, 32> m_formatFRegs; std::array<std::array<FormatSpecifier, 2>, 32> m_formatFRegs;
u32 GetSpecialRegValue(int reg);
void SetSpecialRegValue(int reg, u32 value);
wxString GetFormatString(FormatSpecifier specifier);
wxString FormatGPR(int reg_index); wxString FormatGPR(int reg_index);
wxString FormatFPR(int reg_index, int reg_part); wxString FormatFPR(int reg_index, int reg_part);
bool TryParseGPR(wxString str, FormatSpecifier format, u32* value);
bool TryParseFPR(wxString str, FormatSpecifier format, unsigned long long int* value);
DECLARE_NO_COPY_CLASS(CRegTable); DECLARE_NO_COPY_CLASS(CRegTable);
}; };