From 37f5058de01345a6f0efbf5cb72c8d0c3643f12d Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 9 May 2015 17:07:26 -0700 Subject: [PATCH] GBA Memory: Fix jumping to invalid memory when switching from Thumb to ARM --- CHANGES | 1 + src/gba/memory.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index be9f5a0f4..f08a29dce 100644 --- a/CHANGES +++ b/CHANGES @@ -52,6 +52,7 @@ Bugfixes: - 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 diff --git a/src/gba/memory.c b/src/gba/memory.c index 41df2bf15..96115616a 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -231,13 +231,7 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) { } 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 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) { 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");