core 68k, fix cyclone code execution from overlaid rom (sram/megasd)
authorkub <derkub@gmail.com>
Mon, 23 Dec 2024 11:17:51 +0000 (12:17 +0100)
committerkub <derkub@gmail.com>
Mon, 23 Dec 2024 11:18:29 +0000 (12:18 +0100)
pico/cart.c
pico/m68kif_cyclone.s
pico/memory.c

index 2d4ea6f..aaf91ff 100644 (file)
@@ -828,7 +828,7 @@ int PicoCartInsert(unsigned char *rom, unsigned int romsize, const char *carthw_
   // This will hang the emu, but will prevent nasty crashes.\r
   // note: 4 bytes are padded to every ROM\r
   if (rom != NULL)\r
-    *(u32 *)(rom+romsize) = CPU_BE2(0x4EFAFFFE);\r
+    *(u32 *)(rom+romsize) = CPU_BE2(0x6000FFFE);\r
 \r
   Pico.rom=rom;\r
   Pico.romsize=romsize;\r
index 55e996a..c321391 100644 (file)
@@ -44,7 +44,6 @@ crashed:
     stmfd   sp!,{lr}
     mov     r1, r7
     bl      cyclone_crashed
-    ldr     r0, [r7, #0x40]  @ reload PC + membase
     ldmfd   sp!,{pc}
 
 
index c79018d..5c3600c 100644 (file)
@@ -294,12 +294,22 @@ void log_io(unsigned int addr, int bits, int rw);
 #endif\r
 \r
 #if defined(EMU_C68K)\r
-void cyclone_crashed(u32 pc, struct Cyclone *context)\r
+u32 cyclone_crashed(u32 pc, struct Cyclone *context)\r
 {\r
-    elprintf(EL_STATUS|EL_ANOMALY, "%c68k crash detected @ %06x",\r
-      context == &PicoCpuCM68k ? 'm' : 's', pc);\r
+    // check for underlying ROM, in case of on-cart hw overlaying part of ROM\r
+    // NB assumes code isn't executed from the overlay, but I've never seen this\r
+    u32 pc24 = pc & 0xffffff;\r
+    if (pc24 >= Pico.romsize) {\r
+      // no ROM, so it's probably an illegal access\r
+      pc24 = Pico.romsize;\r
+      elprintf(EL_STATUS|EL_ANOMALY, "%c68k crash detected @ %06x",\r
+        context == &PicoCpuCM68k ? 'm' : 's', pc);\r
+    }\r
+\r
     context->membase = (u32)Pico.rom;\r
-    context->pc = (u32)Pico.rom + Pico.romsize;\r
+    context->pc = (u32)Pico.rom + pc24;\r
+\r
+    return context->pc;\r
 }\r
 #endif\r
 \r