GBA Memory: Fix jumping to invalid memory when switching from Thumb to ARM
Jeffrey Pfau jeffrey@endrift.com
Sat, 09 May 2015 17:07:26 -0700
2 files changed,
7 insertions(+),
8 deletions(-)
M
CHANGES
→
CHANGES
@@ -52,6 +52,7 @@ - ARM7: Make illegal instruction decoding consistent between ARM and Thumb
- GBA BIOS: Initialize a variable that may be uninitialized in very rare cases - ARM7: Fix ARM multiply instructions when PC is a destination register - SDL: Fix potential build issues when Qt and SDL2 are in use + - GBA Memory: Fix jumping to invalid memory when switching from Thumb to ARM Misc: - Qt: Show multiplayer numbers in window title - Qt: Handle saving input settings better
M
src/gba/memory.c
→
src/gba/memory.c
@@ -231,13 +231,7 @@ }
} gba->lastJump = address; - if (newRegion >= REGION_CART0 && (address & (SIZE_CART0 - 1)) >= memory->romSize) { - cpu->memory.activeRegion = _deadbeef; - cpu->memory.activeMask = 0; - GBALog(gba, GBA_LOG_FATAL, "Jumped past end of ROM"); - return; - } - if (newRegion == memory->activeRegion) { + if (newRegion == memory->activeRegion && (newRegion < REGION_CART0 || (address & (SIZE_CART0 - 1)) < memory->romSize)) { return; }@@ -270,8 +264,12 @@ case REGION_CART2:
case REGION_CART2_EX: cpu->memory.activeRegion = memory->rom; cpu->memory.activeMask = SIZE_CART0 - 1; - break; + if ((address & (SIZE_CART0 - 1)) < memory->romSize) { + break; + } + // Fall through default: + memory->activeRegion = 0; cpu->memory.activeRegion = _deadbeef; cpu->memory.activeMask = 0; GBALog(gba, GBA_LOG_FATAL, "Jumped to invalid address");