Add the scratchpad's missing kernel-mode mirrors, fix a mask bug hiding them

The scratchpad (PSP's repurposed-cache scratch RAM, 0x00010000+) was only
mirrored for user-mode access (cached 0x00010000, uncached 0x40010000) -
kernel-mode code sees it at 0x80010000/0xC0010000 (the kernel bit,
0x80000000, is independent of and combinable with the uncached bit,
0x40000000 - not "the uncached bit" as an earlier doc note in this branch
mistakenly called it). Missing entirely from MemMap.cpp's views[] table,
causing a real SIGSEGV the first time kernel-mode code (flash0:/reboot.bin)
touched it.

Adding the two missing views wasn't sufficient: the scratchpad range check
is duplicated eight times (IsValidAddress/IsValid2AlignedAddress/
IsValid4AlignedAddress/MaxSizeAtAddress in MemMap.h, and four more in
MemMapFunctions.cpp), and all eight used a mask (0xBFFFC000) that cleared
the uncached bit but kept the kernel bit, rejecting 0x80010000 as invalid
before ever reaching the now-mapped memory. Fixed all eight to 0x3FFFC000,
matching Memory::MEMVIEW32_MASK (which the JIT backends already used
correctly for the equivalent runtime check).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
This commit is contained in:
Henrik Rydgård
2026-08-13 11:36:42 +02:00
co-authored by Claude Sonnet 5
parent 75174af77b
commit 28cbb3a967
3 changed files with 19 additions and 9 deletions
+7 -5
View File
@@ -30,7 +30,7 @@ namespace Memory {
u8 *GetPointerWriteOrException(const u32 address) {
if ((address & 0x3E000000) == 0x08000000 || // RAM
(address & 0xBF800000) == 0x04000000 || // VRAM
(address & 0xBFFFC000) == 0x00010000 || // Scratchpad
(address & 0x3FFFC000) == 0x00010000 || // Scratchpad
((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.)
return GetPointerWriteUnchecked(address);
} else {
@@ -43,7 +43,7 @@ u8 *GetPointerWriteOrException(const u32 address) {
const u8 *GetPointerOrException(const u32 address) {
if ((address & 0x3E000000) == 0x08000000 || // RAM
(address & 0xBF800000) == 0x04000000 || // VRAM
(address & 0xBFFFC000) == 0x00010000 || // Scratchpad
(address & 0x3FFFC000) == 0x00010000 || // Scratchpad
((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.)
return GetPointerUnchecked(address);
} else {
@@ -89,7 +89,7 @@ template <typename T>
inline void ReadMemoryOrException(T &var, const u32 address) {
if ((address & 0x3E000000) == 0x08000000 || // RAM
(address & 0xBF800000) == 0x04000000 || // VRAM
(address & 0xBFFFC000) == 0x00010000 || // Scratchpad
(address & 0x3FFFC000) == 0x00010000 || // Scratchpad
((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.)
var = *((const T*)GetPointerUnchecked(address));
} else {
@@ -102,7 +102,7 @@ template <typename T>
inline void WriteMemoryOrException(u32 address, const T data) {
if ((address & 0x3E000000) == 0x08000000 || // RAM
(address & 0xBF800000) == 0x04000000 || // VRAM
(address & 0xBFFFC000) == 0x00010000 || // Scratchpad
(address & 0x3FFFC000) == 0x00010000 || // Scratchpad
((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize)) { // More RAM (remasters, etc.)
*(T*)GetPointerUnchecked(address) = data;
} else {
@@ -121,7 +121,9 @@ bool IsRAMAddress(const u32 address) {
}
bool IsScratchpadAddress(const u32 address) {
return (address & 0xBFFFC000) == 0x00010000;
// Ignore both the kernel bit (0x80000000) and the uncached bit (0x40000000) - the
// scratchpad is mirrored across all four combinations, same as RAM (see MemMap.cpp).
return (address & ~(0xC0000000 | (SCRATCHPAD_SIZE - 1))) == 0x00010000;
}
u8 ReadOrException_U8(const u32 address) {