Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions common/MemoryInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "MemoryInterface.h"

#include <bit>

template <MemoryAccessType Value>
Value MemoryInterface::Read(u32 address, bool* valid)
{
Expand All @@ -24,6 +26,10 @@ Value MemoryInterface::Read(u32 address, bool* valid)
.hi = static_cast<s64>(value.hi),
};
}
else if constexpr (std::is_same_v<Value, float>)
return std::bit_cast<float>(Read32(address, valid));
else if constexpr (std::is_same_v<Value, double>)
return std::bit_cast<double>(Read64(address, valid));
else
return Value(0);
}
Expand All @@ -48,6 +54,10 @@ bool MemoryInterface::Write(u32 address, Value value)
unsigned_value.hi = static_cast<u64>(value.hi);
return Write128(address, unsigned_value);
}
else if constexpr (std::is_same_v<Value, float>)
return Write32(address, std::bit_cast<u32>(value));
else if constexpr (std::is_same_v<Value, double>)
return Write64(address, std::bit_cast<u64>(value));
else
return false;
}
Expand Down Expand Up @@ -135,4 +145,6 @@ EXPLICITLY_INSTANTIATE_TEMPLATES(u64)
EXPLICITLY_INSTANTIATE_TEMPLATES(s64)
EXPLICITLY_INSTANTIATE_TEMPLATES(u128)
EXPLICITLY_INSTANTIATE_TEMPLATES(s128)
EXPLICITLY_INSTANTIATE_TEMPLATES(float)
EXPLICITLY_INSTANTIATE_TEMPLATES(double)
#undef EXPLICITLY_INSTANTIATE_TEMPLATES
5 changes: 4 additions & 1 deletion common/MemoryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ concept MemoryAccessType = std::is_same_v<Value, u8> || std::is_same_v<Value, s8
std::is_same_v<Value, u16> || std::is_same_v<Value, s16> ||
std::is_same_v<Value, u32> || std::is_same_v<Value, s32> ||
std::is_same_v<Value, u64> || std::is_same_v<Value, s64> ||
std::is_same_v<Value, u128> || std::is_same_v<Value, s128>;
std::is_same_v<Value, u128> || std::is_same_v<Value, s128> ||
std::is_same_v<Value, float> || std::is_same_v<Value, double>;

/// Interface for reading/writing guest memory.
class MemoryInterface
{
public:
virtual ~MemoryInterface() {}

virtual u8 Read8(u32 address, bool* valid = nullptr) = 0;
virtual u16 Read16(u32 address, bool* valid = nullptr) = 0;
virtual u32 Read32(u32 address, bool* valid = nullptr) = 0;
Expand Down
22 changes: 11 additions & 11 deletions pcsx2-qt/Debugger/DisassemblyView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void DisassemblyView::contextRestoreInstruction()
{
u32 address = start + i * 4;
if (original_instructions[i].has_value())
cpu->write32(address, *original_instructions[i]);
cpu->Write32(address, *original_instructions[i]);
}
DebuggerView::broadcastEvent(DebuggerEvents::VMUpdate());
});
Expand Down Expand Up @@ -332,11 +332,11 @@ void DisassemblyView::contextStubFunction()

const QPointer<DisassemblyView> view(this);
Host::RunOnCPUThread([view, address, cpu = &cpu()] {
const u32 first_instruction = cpu->read32(address);
const u32 second_instruction = cpu->read32(address + 4);
const u32 first_instruction = cpu->Read32(address);
const u32 second_instruction = cpu->Read32(address + 4);

cpu->write32(address, 0x03E00008); // jr ra
cpu->write32(address + 4, 0x00000000); // nop
cpu->Write32(address, 0x03E00008); // jr ra
cpu->Write32(address + 4, 0x00000000); // nop

QtHost::RunOnUIThread([view, address, first_instruction, second_instruction]() {
if (!view)
Expand Down Expand Up @@ -364,8 +364,8 @@ void DisassemblyView::contextRestoreFunction()
m_stubbedFunctions.erase(stub);

Host::RunOnCPUThread([address, cpu = &cpu(), first_instruction, second_instruction] {
cpu->write32(address, first_instruction);
cpu->write32(address + 4, second_instruction);
cpu->Write32(address, first_instruction);
cpu->Write32(address + 4, second_instruction);
DebuggerView::broadcastEvent(DebuggerEvents::VMUpdate());
});
}
Expand Down Expand Up @@ -919,7 +919,7 @@ inline QString DisassemblyView::DisassemblyStringFromAddress(u32 address, QFont

if (showOpcode)
{
const u32 opcode = cpu().read32(address);
const u32 opcode = cpu().Read32(address);
lineString = lineString.arg(QtUtils::FilledQStringFromValue(opcode, 16));
}

Expand Down Expand Up @@ -989,7 +989,7 @@ QString DisassemblyView::FetchSelectionInfo(SelectionInfo selInfo)
}
else // INSTRUCTIONHEX
{
infoBlock += FilledQStringFromValue(cpu().read32(i), 16);
infoBlock += FilledQStringFromValue(cpu().Read32(i), 16);
}
}
return infoBlock;
Expand Down Expand Up @@ -1050,8 +1050,8 @@ void DisassemblyView::setInstructions(u32 start, u32 end, u32 value)
for (u32 i = 0; i < count; i++)
{
const u32 address = start + i * 4;
original_instructions.emplace_back(cpu->read32(address));
cpu->write32(address, value);
original_instructions.emplace_back(cpu->Read32(address));
cpu->Write32(address, value);
}

QtHost::RunOnUIThread([view, start, count, original_instructions = std::move(original_instructions)]() {
Expand Down
48 changes: 4 additions & 44 deletions pcsx2-qt/Debugger/Memory/MemorySearchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,46 +112,6 @@ void MemorySearchView::onListSearchResultsContextMenu(QPoint pos)
menu->popup(m_ui.listSearchResults->viewport()->mapToGlobal(pos));
}

template <typename T>
T readValueAtAddress(DebugInterface* cpu, u32 addr);
template <>
float readValueAtAddress<float>(DebugInterface* cpu, u32 addr)
{
return std::bit_cast<float>(cpu->read32(addr));
}

template <>
double readValueAtAddress<double>(DebugInterface* cpu, u32 addr)
{
return std::bit_cast<double>(cpu->read64(addr));
}

template <typename T>
T readValueAtAddress(DebugInterface* cpu, u32 addr)
{
T val = 0;
switch (sizeof(T))
{
case sizeof(u8):
val = cpu->read8(addr);
break;
case sizeof(u16):
val = cpu->read16(addr);
break;
case sizeof(u32):
{
val = cpu->read32(addr);
break;
}
case sizeof(u64):
{
val = cpu->read64(addr);
break;
}
}
return val;
}

template <typename T>
static bool memoryValueComparator(SearchComparison searchComparison, T searchValue, T readValue)
{
Expand Down Expand Up @@ -294,7 +254,7 @@ void searchWorker(DebugInterface* cpu, std::vector<SearchResult>& searchResults,
if (!cpu->isValidAddress(addr))
continue;

T readValue = readValueAtAddress<T>(cpu, addr);
T readValue = cpu->Read<T>(addr);
if (handleSearchComparison(searchComparison, addr, nullptr, searchValue, readValue))
{
searchResults.push_back(MemorySearchView::SearchResult(addr, QVariant::fromValue(readValue), searchType));
Expand All @@ -308,7 +268,7 @@ void searchWorker(DebugInterface* cpu, std::vector<SearchResult>& searchResults,
if (!cpu->isValidAddress(addr))
return true;

const auto readValue = readValueAtAddress<T>(cpu, addr);
const auto readValue = cpu->Read<T>(addr);

const bool doesMatch = handleSearchComparison(searchComparison, addr, &searchResult, searchValue, readValue);
if (doesMatch)
Expand All @@ -325,7 +285,7 @@ static bool compareByteArrayAtAddress(DebugInterface* cpu, SearchComparison sear
const bool isNotOperator = searchComparison == SearchComparison::NotEquals;
for (qsizetype i = 0; i < value.length(); i++)
{
const char nextByte = cpu->read8(addr + i);
const char nextByte = cpu->Read8(addr + i);
switch (searchComparison)
{
case SearchComparison::Equals:
Expand Down Expand Up @@ -383,7 +343,7 @@ static QByteArray readArrayAtAddress(DebugInterface* cpu, u32 address, u32 lengt
QByteArray readArray;
for (u32 i = address; i < address + length; i++)
{
readArray.append(cpu->read8(i));
readArray.append(cpu->Read8(i));
}
return readArray;
}
Expand Down
42 changes: 21 additions & 21 deletions pcsx2-qt/Debugger/Memory/MemoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,39 +119,39 @@ void MemoryViewTable::DrawTable(QPainter& painter, const QPalette& palette, s32
{
case MemoryViewType::BYTE:
{
const u8 val = static_cast<u8>(cpu.read8(thisSegmentsStart, valid));
const u8 val = cpu.Read8(thisSegmentsStart, &valid);
if (penDefault && val == 0)
painter.setPen(QColor::fromRgb(145, 145, 155)); // ZERO BYTE COLOUR
painter.drawText(valX, y + (rowHeight * i), valid ? FilledQStringFromValue(val, 16) : "??");
break;
}
case MemoryViewType::BYTEHW:
{
const u16 val = convertEndian<u16>(static_cast<u16>(cpu.read16(thisSegmentsStart, valid)));
const u16 val = convertEndian<u16>(cpu.Read16(thisSegmentsStart, &valid));
if (penDefault && val == 0)
painter.setPen(QColor::fromRgb(145, 145, 155)); // ZERO BYTE COLOUR
painter.drawText(valX, y + (rowHeight * i), valid ? FilledQStringFromValue(val, 16) : "????");
break;
}
case MemoryViewType::WORD:
{
const u32 val = convertEndian<u32>(cpu.read32(thisSegmentsStart, valid));
const u32 val = convertEndian<u32>(cpu.Read32(thisSegmentsStart, &valid));
if (penDefault && val == 0)
painter.setPen(QColor::fromRgb(145, 145, 155)); // ZERO BYTE COLOUR
painter.drawText(valX, y + (rowHeight * i), valid ? FilledQStringFromValue(val, 16) : "????????");
break;
}
case MemoryViewType::DWORD:
{
const u64 val = convertEndian<u64>(cpu.read64(thisSegmentsStart, valid));
const u64 val = convertEndian<u64>(cpu.Read64(thisSegmentsStart, &valid));
if (penDefault && val == 0)
painter.setPen(QColor::fromRgb(145, 145, 155)); // ZERO BYTE COLOUR
painter.drawText(valX, y + (rowHeight * i), valid ? FilledQStringFromValue(val, 16) : "????????????????");
break;
}
case MemoryViewType::FLOAT:
{
const u32 intVal = convertEndian<u32>(cpu.read32(thisSegmentsStart, valid));
const u32 intVal = convertEndian<u32>(cpu.Read32(thisSegmentsStart, &valid));
float val = 0.0;
std::memcpy(&val, &intVal, sizeof(val));
if (penDefault && val == 0.0)
Expand All @@ -177,7 +177,7 @@ void MemoryViewTable::DrawTable(QPainter& painter, const QPalette& palette, s32
painter.setPen(palette.text().color());

bool valid;
const u8 value = cpu.read8(currentRowAddress + j, valid);
const u8 value = cpu.Read8(currentRowAddress + j, &valid);
if (valid)
{
QChar curChar = QChar::fromLatin1(value);
Expand Down Expand Up @@ -258,19 +258,19 @@ u128 MemoryViewTable::GetSelectedSegment(DebugInterface& cpu)
switch (displayType)
{
case MemoryViewType::BYTE:
val.lo = cpu.read8(selectedAddress);
val.lo = cpu.Read8(selectedAddress);
break;
case MemoryViewType::BYTEHW:
val.lo = convertEndian(static_cast<u16>(cpu.read16(selectedAddress & ~1)));
val.lo = convertEndian(static_cast<u16>(cpu.Read16(selectedAddress & ~1)));
break;
case MemoryViewType::WORD:
val.lo = convertEndian(cpu.read32(selectedAddress & ~3));
val.lo = convertEndian(cpu.Read32(selectedAddress & ~3));
break;
case MemoryViewType::DWORD:
val._u64[0] = convertEndian(cpu.read64(selectedAddress & ~7));
val._u64[0] = convertEndian(cpu.Read64(selectedAddress & ~7));
break;
case MemoryViewType::FLOAT:
val.lo = convertEndian(cpu.read32(selectedAddress & ~3));
val.lo = convertEndian(cpu.Read32(selectedAddress & ~3));
break;
}
return val;
Expand All @@ -279,13 +279,13 @@ u128 MemoryViewTable::GetSelectedSegment(DebugInterface& cpu)
void MemoryViewTable::InsertIntoSelectedHexView(u8 value, DebugInterface& cpu)
{
const u8 mask = selectedNibbleHI ? 0x0f : 0xf0;
u8 curVal = cpu.read8(selectedAddress) & mask;
u8 curVal = cpu.Read8(selectedAddress) & mask;
u8 newVal = value << (selectedNibbleHI ? 4 : 0);
curVal |= newVal;

const QPointer<MemoryViewTable> table(this);
Host::RunOnCPUThread([table, address = selectedAddress, &cpu, val = curVal] {
cpu.write8(address, val);
cpu.Write8(address, val);

QtHost::RunOnUIThread([table] {
if (!table)
Expand Down Expand Up @@ -323,7 +323,7 @@ bool MemoryViewTable::InsertFloatIntoSelectedHexView(DebugInterface& cpu)

const QPointer<MemoryViewTable> table(this);
Host::RunOnCPUThread([table, address = selectedAddress, &cpu, val = newIntVal] {
cpu.write32(address, val);
cpu.Write32(address, val);

QtHost::RunOnUIThread([table] {
if (!table)
Expand Down Expand Up @@ -360,7 +360,7 @@ void MemoryViewTable::InsertAtCurrentSelection(const QString& text, DebugInterfa

const QPointer<MemoryViewTable> table(this);
Host::RunOnCPUThread([table, address = selectedAddress, &cpu, val = newIntVal] {
cpu.write32(address, val);
cpu.Write32(address, val);

QtHost::RunOnUIThread([table] {
if (!table)
Expand All @@ -384,7 +384,7 @@ void MemoryViewTable::InsertAtCurrentSelection(const QString& text, DebugInterfa
u32 currAddr = address;
for (int i = 0; i < input.size(); i++)
{
cpu.write8(currAddr, input[i]);
cpu.Write8(currAddr, input[i]);
currAddr = nextAddress(currAddr, address, display_type, little_endian);
}

Expand Down Expand Up @@ -552,7 +552,7 @@ bool MemoryViewTable::KeyPress(int key, QChar keychar, DebugInterface& cpu)
{
const QPointer<MemoryViewTable> table(this);
Host::RunOnCPUThread([table, address = selectedAddress, &cpu, val = keychar.toLatin1()] {
cpu.write8(address, val);
cpu.Write8(address, val);

QtHost::RunOnUIThread([table, address]() {
if (!table)
Expand All @@ -572,7 +572,7 @@ bool MemoryViewTable::KeyPress(int key, QChar keychar, DebugInterface& cpu)
{
const QPointer<MemoryViewTable> table(this);
Host::RunOnCPUThread([table, address = selectedAddress, &cpu] {
cpu.write8(address, 0);
cpu.Write8(address, 0);

QtHost::RunOnUIThread([table] {
if (!table)
Expand Down Expand Up @@ -865,7 +865,7 @@ void MemoryView::openContextMenu(QPoint pos)

void MemoryView::contextCopyByte()
{
QApplication::clipboard()->setText(QString::number(cpu().read8(m_table.selectedAddress), 16).toUpper());
QApplication::clipboard()->setText(QString::number(cpu().Read8(m_table.selectedAddress), 16).toUpper());
}

void MemoryView::contextCopySegment()
Expand All @@ -885,7 +885,7 @@ void MemoryView::contextCopySegment()

void MemoryView::contextCopyCharacter()
{
QApplication::clipboard()->setText(QChar::fromLatin1(cpu().read8(m_table.selectedAddress)).toUpper());
QApplication::clipboard()->setText(QChar::fromLatin1(cpu().Read8(m_table.selectedAddress)).toUpper());
}

void MemoryView::contextPaste()
Expand Down Expand Up @@ -913,7 +913,7 @@ void MemoryView::contextGoToAddress()
void MemoryView::contextFollowAddress()
{
bool valid;
u32 address = cpu().read32(m_table.selectedAddress & ~3, valid);
u32 address = cpu().Read32(m_table.selectedAddress & ~3, &valid);
if (!valid)
return;

Expand Down
Loading
Loading