Skip to content

Commit

Permalink
n64: implement all known sysad freezes
Browse files Browse the repository at this point in the history
  • Loading branch information
rasky committed Dec 3, 2023
1 parent ba956a6 commit 2b63c5c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
38 changes: 25 additions & 13 deletions ares/n64/memory/bus.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
template<u32 Size>
inline auto Bus::read(u32 address, Thread& thread, const char *peripheral) -> u64 {
static constexpr u64 unmapped = 0;
static_assert(Size == Byte || Size == Half || Size == Word || Size == Dual);

if(address <= 0x03ef'ffff) return rdram.ram.read<Size>(address, peripheral);
if(address <= 0x03ff'ffff) return rdram.read<Size>(address, thread);
if(Size == Dual) return freezeDualRead(address), 0;
if(address <= 0x0407'ffff) return rsp.read<Size>(address, thread);
if(address <= 0x040f'ffff) return rsp.status.read<Size>(address, thread);
if(address <= 0x040b'ffff) return rsp.status.read<Size>(address, thread);
if(address <= 0x040f'ffff) return freezeUnmapped(address), 0;
if(address <= 0x041f'ffff) return rdp.read<Size>(address, thread);
if(address <= 0x042f'ffff) return rdp.io.read<Size>(address, thread);
if(address <= 0x043f'ffff) return mi.read<Size>(address, thread);
Expand All @@ -15,13 +16,11 @@ inline auto Bus::read(u32 address, Thread& thread, const char *peripheral) -> u6
if(address <= 0x046f'ffff) return pi.read<Size>(address, thread);
if(address <= 0x047f'ffff) return ri.read<Size>(address, thread);
if(address <= 0x048f'ffff) return si.read<Size>(address, thread);
if(address <= 0x04ff'ffff) return unmapped;
if(address <= 0x04ff'ffff) return freezeUnmapped(address), 0;
if(address <= 0x1fbf'ffff) return pi.read<Size>(address, thread);
if(address <= 0x1fcf'ffff) return si.read<Size>(address, thread);
if(address <= 0x7fff'ffff) return pi.read<Size>(address, thread);
debug(unusual, "[Bus::write] CPU frozen because of read from physical address ", hex(address, 8L), " outside of RCP mapped range");
cpu.scc.sysadFrozen = true;
return unmapped;
return freezeUnmapped(address), 0;
}

template<u32 Size>
Expand All @@ -44,8 +43,7 @@ inline auto Bus::readBurst(u32 address, u32 *data, Thread& thread) -> void {
return;
}

debug(unusual, "[Bus::readBurst] CPU frozen because of cached read to non-RDRAM area: 0x", hex(address, 8L));
cpu.scc.sysadFrozen = true;
return freezeUncached(address);
}

template<u32 Size>
Expand All @@ -59,7 +57,8 @@ inline auto Bus::write(u32 address, u64 data, Thread& thread, const char *periph
if(address <= 0x03ef'ffff) return rdram.ram.write<Size>(address, data, peripheral);
if(address <= 0x03ff'ffff) return rdram.write<Size>(address, data, thread);
if(address <= 0x0407'ffff) return rsp.write<Size>(address, data, thread);
if(address <= 0x040f'ffff) return rsp.status.write<Size>(address, data, thread);
if(address <= 0x040b'ffff) return rsp.status.write<Size>(address, data, thread);
if(address <= 0x040f'ffff) return freezeUnmapped(address);
if(address <= 0x041f'ffff) return rdp.write<Size>(address, data, thread);
if(address <= 0x042f'ffff) return rdp.io.write<Size>(address, data, thread);
if(address <= 0x043f'ffff) return mi.write<Size>(address, data, thread);
Expand All @@ -68,12 +67,11 @@ inline auto Bus::write(u32 address, u64 data, Thread& thread, const char *periph
if(address <= 0x046f'ffff) return pi.write<Size>(address, data, thread);
if(address <= 0x047f'ffff) return ri.write<Size>(address, data, thread);
if(address <= 0x048f'ffff) return si.write<Size>(address, data, thread);
if(address <= 0x04ff'ffff) return;
if(address <= 0x04ff'ffff) return freezeUnmapped(address);
if(address <= 0x1fbf'ffff) return pi.write<Size>(address, data, thread);
if(address <= 0x1fcf'ffff) return si.write<Size>(address, data, thread);
if(address <= 0x7fff'ffff) return pi.write<Size>(address, data, thread);
debug(unusual, "[Bus::write] CPU frozen because of write to physical address ", hex(address, 8L), " outside of RCP mapped range");
cpu.scc.sysadFrozen = true;
return freezeUnmapped(address);
}

template<u32 Size>
Expand All @@ -90,6 +88,20 @@ inline auto Bus::writeBurst(u32 address, u32 *data, Thread& thread) -> void {
return;
}

debug(unusual, "[Bus::writeBurst] CPU frozen because of cached write to non-RDRAM area: 0x", hex(address, 8L));
return freezeUncached(address);
}

inline auto Bus::freezeUnmapped(u32 address) -> void {
debug(unusual, "[Bus::freezeUnmapped] CPU frozen because of access to RCP unmapped area: 0x", hex(address, 8L));
cpu.scc.sysadFrozen = true;
}

inline auto Bus::freezeUncached(u32 address) -> void {
debug(unusual, "[Bus::freezeUncached] CPU frozen because of cached access to non-RDRAM area: 0x", hex(address, 8L));
cpu.scc.sysadFrozen = true;
}

inline auto Bus::freezeDualRead(u32 address) -> void {
debug(unusual, "[Bus::freezeDualRead] CPU frozen because of 64-bit read from non-RDRAM area: 0x ", hex(address, 8L));
cpu.scc.sysadFrozen = true;
}
4 changes: 4 additions & 0 deletions ares/n64/memory/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ struct Bus {

template<u32 Size> auto readBurst(u32 address, u32* data, Thread& thread) -> void;
template<u32 Size> auto writeBurst(u32 address, u32* data, Thread& thread) -> void;

auto freezeUnmapped(u32 address) -> void;
auto freezeUncached(u32 address) -> void;
auto freezeDualRead(u32 address) -> void;
};

extern Bus bus;

0 comments on commit 2b63c5c

Please sign in to comment.