Skip to content

Commit

Permalink
n64: add support for RSP unaligned reads/writes to cache coherency ch…
Browse files Browse the repository at this point in the history
…ecks
  • Loading branch information
rasky committed Dec 4, 2023
1 parent 53348a8 commit a600f6b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
28 changes: 28 additions & 0 deletions ares/n64/rsp/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,39 @@ auto RSP::Debugger::dmemReadWord(u12 address, int size, const char *peripheral)
}
}

auto RSP::Debugger::dmemReadUnalignedWord(u12 address, int size, const char *peripheral) -> void {
if (system.homebrewMode) {
u32 addressAlignedStart = address & ~7;
u32 addressAlignedEnd = address + size - 1 & ~7;
if(addressAlignedStart == addressAlignedEnd) {
dmemReadWord(address, size, "RSP");
} else {
int sizeStart = addressAlignedEnd - address;
dmemReadWord(address, sizeStart, "RSP");
dmemReadWord(address + sizeStart, size - sizeStart, "RSP");
}
}
}

auto RSP::Debugger::dmemWriteWord(u12 address, int size, u64 value) -> void {
if (system.homebrewMode) {
auto& taintWord = taintMask.dmem[address >> 3];
taintWord.dirty &= ~(((1 << size) - 1) << (address & 0x7));
}
}

auto RSP::Debugger::dmemWriteUnalignedWord(u12 address, int size, u64 value) -> void {
if (system.homebrewMode) {
u32 addressAlignedStart = address & ~7;
u32 addressAlignedEnd = address + size - 1 & ~7;
if(addressAlignedStart == addressAlignedEnd) {
dmemWriteWord(address, size, value);
} else {
int sizeStart = addressAlignedEnd - address;
dmemWriteWord(address, sizeStart, value);
dmemWriteWord(address + sizeStart, size - sizeStart, value);
}
}
}

#undef rsp
22 changes: 16 additions & 6 deletions ares/n64/rsp/rsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@ struct RSP : Thread, Memory::RCP<RSP> {

template<u32 Size>
auto read(u32 address) -> u64 {
if (system.homebrewMode) {
self.debugger.dmemReadWord(address, Size, "RSP");
}
if (system.homebrewMode) self.debugger.dmemReadWord(address, Size, "RSP");
return Memory::Writable::read<Size>(address);
}

template<u32 Size>
auto readUnaligned(u32 address) -> u64 {
if (system.homebrewMode) self.debugger.dmemReadUnalignedWord(address, Size, "RSP");
return Memory::Writable::readUnaligned<Size>(address);
}

template<u32 Size>
auto write(u32 address, u64 value) -> void {
if (system.homebrewMode) {
self.debugger.dmemWriteWord(address, Size, value);
}
if (system.homebrewMode) self.debugger.dmemWriteWord(address, Size, value);
Memory::Writable::write<Size>(address, value);
}

template<u32 Size>
auto writeUnaligned(u32 address, u64 value) -> void {
if (system.homebrewMode) self.debugger.dmemWriteUnalignedWord(address, Size, value);
Memory::Writable::writeUnaligned<Size>(address, value);
}

} dmem{*this};
Memory::Writable imem;

Expand All @@ -38,6 +46,8 @@ struct RSP : Thread, Memory::RCP<RSP> {
auto dmaReadWord(u32 rdramAddress, u32 pbusRegion, u32 pbusAddress) -> void;
auto dmemReadWord(u12 address, int size, const char *peripheral) -> void;
auto dmemWriteWord(u12 address, int size, u64 value) -> void;
auto dmemReadUnalignedWord(u12 address, int size, const char *peripheral) -> void;
auto dmemWriteUnalignedWord(u12 address, int size, u64 value) -> void;

struct TaintMask {
struct TaintWord {
Expand Down

0 comments on commit a600f6b

Please sign in to comment.