From c73c794235ef9ba516768e742b21197dd899b5e2 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Fri, 14 Apr 2017 21:53:44 -0400 Subject: [PATCH] Fix #253 The solution here is to only write to the stack if it is in a writable area of the address space. --- genplus-gx32/core/m68k/m68kcpu.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/genplus-gx32/core/m68k/m68kcpu.h b/genplus-gx32/core/m68k/m68kcpu.h index 3af87b6b8b..a7d27d64e9 100644 --- a/genplus-gx32/core/m68k/m68kcpu.h +++ b/genplus-gx32/core/m68k/m68kcpu.h @@ -14,6 +14,7 @@ #endif /* M68K_EMULATE_ADDRESS_ERROR */ #include "m68k.h" +#include "mem68k.h" #include "../cinterface/callbacks.h" void CDLog68k(uint addr, uint flags); @@ -1106,15 +1107,21 @@ INLINE void m68ki_push_16(uint value) { REG_SP = MASK_OUT_ABOVE_32(REG_SP - 2); /*m68ki_write_16(REG_SP, value);*/ - *(uint16 *)(m68ki_cpu.memory_map[(REG_SP>>16)&0xff].base + (REG_SP & 0xffff)) = value; + if (m68ki_cpu.memory_map[(REG_SP >> 16) & 0xff].write16 != m68k_unused_16_w) + { + *(uint16 *)(m68ki_cpu.memory_map[(REG_SP >> 16) & 0xff].base + (REG_SP & 0xffff)) = value; + } } INLINE void m68ki_push_32(uint value) { REG_SP = MASK_OUT_ABOVE_32(REG_SP - 4); /*m68ki_write_32(REG_SP, value);*/ - *(uint16 *)(m68ki_cpu.memory_map[(REG_SP>>16)&0xff].base + (REG_SP & 0xffff)) = value >> 16; - *(uint16 *)(m68ki_cpu.memory_map[((REG_SP + 2)>>16)&0xff].base + ((REG_SP + 2) & 0xffff)) = value & 0xffff; + if (m68ki_cpu.memory_map[(REG_SP >> 16) & 0xff].write16 != m68k_unused_16_w) + { + *(uint16 *)(m68ki_cpu.memory_map[(REG_SP >> 16) & 0xff].base + (REG_SP & 0xffff)) = value >> 16; + *(uint16 *)(m68ki_cpu.memory_map[((REG_SP + 2) >> 16) & 0xff].base + ((REG_SP + 2) & 0xffff)) = value & 0xffff; + } } INLINE uint m68ki_pull_16(void)