From 049834434967f33d137fdc91d2d36641379cf252 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 31 May 2020 22:26:30 +0200 Subject: [PATCH] periodic check of SH3 compatibility --- include/gint/hardware.h | 5 +++-- src/core/exch.c | 14 ++++++++++++-- src/core/exch.s | 22 ++++++++++++++++++++-- src/core/hardware.c | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/gint/hardware.h b/include/gint/hardware.h index 18d1d1f..f77ee4c 100644 --- a/include/gint/hardware.h +++ b/include/gint/hardware.h @@ -24,7 +24,8 @@ extern uint32_t gint[HW_KEYS]; /* MPU detection macros, with a faster version on fx-CG 50 and a generic - dual-platform version for libraries. */ + dual-platform version for libraries. + Warning: this macro is also used hardcoded in exch.s. */ #if defined(FX9860G) || (!defined(FX9860G) && !defined(FXCG50)) #define isSH3() (gint[HWMPU] & 1) @@ -75,7 +76,7 @@ void hw_detect(void); #define HWMPU_UNKNOWN 0 /* Used on original fx-9860G, SH-3-based */ #define HWMPU_SH7337 1 -/* Used on recent fx-9860G derivates such as the fx-9750G II, and also on the +/* Used on recent fx-9860G derivatives such as the fx-9750G II, and also on the fx-CG 10/20/50. SH-4A-based */ #define HWMPU_SH7305 2 /* Used on the fx-9860G II, SH-3-based */ diff --git a/src/core/exch.c b/src/core/exch.c index 54d044c..a1e9871 100644 --- a/src/core/exch.c +++ b/src/core/exch.c @@ -11,8 +11,18 @@ /* gint_panic_default(): Default panic handler */ GNORETURN static void gint_default_panic(GUNUSED uint32_t code) { - uint32_t TEA = *(volatile uint32_t *)0xff00000c; - uint32_t TRA = *(volatile uint32_t *)0xff000020 >> 2; + uint32_t TEA, TRA; + + if(isSH3()) + { + TEA = *(volatile uint32_t *)0xfffffffc; + TRA = *(volatile uint32_t *)0xffffffd0 >> 2; + } + else + { + TEA = *(volatile uint32_t *)0xff00000c; + TRA = *(volatile uint32_t *)0xff000020 >> 2; + } uint32_t PC; __asm__("stc spc, %0" : "=r"(PC)); diff --git a/src/core/exch.s b/src/core/exch.s index a2f8105..c5539db 100644 --- a/src/core/exch.s +++ b/src/core/exch.s @@ -4,10 +4,21 @@ _gint_exch_tlbh: sts.l pr, @-r15 + stc.l gbr, @-r15 + sts.l mach, @-r15 + sts.l macl, @-r15 mov.l r8, @-r15 - mov.l .expevt, r8 + /* Get the first word of the gint hardware array (HWMPU). If it has the + last bit set, we're SH3 */ + mov.l .gint, r0 + mov.l @r0, r0 + tst #1, r0 + mov.l .expevt_sh4, r8 + bt catch + mov.l .expevt_sh3, r8 +catch: /* Panic if the catcher is NULL */ mov.l .catcher, r0 mov.l @r0, r0 @@ -39,14 +50,21 @@ panic: end: mov.l @r15+, r8 + lds.l @r15+, macl + lds.l @r15+, mach + ldc.l @r15+, gbr lds.l @r15+, pr rte nop .align 4 -.expevt: +.gint: + .long _gint +.expevt_sh4: .long 0xff000024 +.expevt_sh3: + .long 0xffffffd4 .catcher: .long _gint_exc_catcher .panic: diff --git a/src/core/hardware.c b/src/core/hardware.c index 1e75a39..6457a9e 100644 --- a/src/core/hardware.c +++ b/src/core/hardware.c @@ -101,7 +101,7 @@ void hw_detect(void) /* Will be detected later on */ gint[HWURAM] = -1; /* Traditionally 4 MiB, Graph 35+E II has 8 MiB */ - gint[HWROM] = (gint[HWCALC] == HWCALC_G35PE2) ? (4 << 20) : (8 << 20); + gint[HWROM] = (gint[HWCALC] == HWCALC_G35PE2) ? (8 << 20) : (4 << 20); } #endif /* FX9860G and platform-agnostic */