From 6b67b6aa13d4b8db12d7824582662f3976803ead Mon Sep 17 00:00:00 2001 From: kub Date: Wed, 8 Jul 2020 20:46:46 +0200 Subject: [PATCH] libretro, more fixes and cleanups for windows and osx --- Makefile.libretro | 90 ++++++++++++---------------------------------- cpu/drc/emit_x86.c | 4 +-- cpu/sh2/compiler.c | 35 +++++++++--------- cpu/sh2/compiler.h | 2 +- cpu/sh2/sh2.h | 4 +++ tools/mkoffsets.sh | 22 ++++++++---- 6 files changed, 61 insertions(+), 96 deletions(-) diff --git a/Makefile.libretro b/Makefile.libretro index 179223e4..309d3f72 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -37,6 +37,8 @@ asm_ym2612 = 0 asm_misc = 0 asm_cdmemory = 0 asm_mix = 0 +asm_32xdraw = 0 +asm_32xmemory = 0 fpic := @@ -48,7 +50,7 @@ endif ifeq ($(platform), unix) EXT ?= so TARGET := $(TARGET_NAME)_libretro.$(EXT) - fpic := -fPIC + fpic := -fPIC SHARED := -shared DONT_COMPILE_IN_ZLIB = 1 CFLAGS += -DFAMEC_NO_GOTOS @@ -59,7 +61,7 @@ else ifeq ($(platform), linux-portable) EXT ?= so TARGET := $(TARGET_NAME)_libretro.$(EXT) SHARED := -shared -nostdlib - fpic := -fPIC + fpic := -fPIC LIBM := DONT_COMPILE_IN_ZLIB = 1 CFLAGS += -DFAMEC_NO_GOTOS @@ -70,7 +72,7 @@ else ifeq ($(platform), osx) EXT ?= dylib TARGET := $(TARGET_NAME)_libretro.$(EXT) SHARED := -dynamiclib - fpic := -fPIC + fpic := -fPIC APPLE := 1 arch = intel ifeq ($(shell uname -p),powerpc) @@ -78,6 +80,8 @@ else ifeq ($(platform), osx) endif ifeq ($(arch),ppc) CFLAGS += -DBLARGG_BIG_ENDIAN=1 -D__ppc__ -DFAMEC_NO_GOTOS + else + use_sh2drc = 1 endif OSXVER = `sw_vers -productVersion | cut -d. -f 2` OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"` @@ -99,21 +103,21 @@ else ifeq ($(platform), staticios) CXX += -miphoneos-version-min=8.0 CC_AS += -miphoneos-version-min=8.0 CFLAGS += -miphoneos-version-min=8.0 - ARCH := arm + ARCH := aarch64 STATIC_LINKING = 1 use_cyclone = 0 use_fame = 1 use_drz80 = 0 use_cz80 = 1 - use_sh2drc = 0 + use_sh2drc = 1 use_svpdrc = 0 # iOS else ifneq (,$(findstring ios,$(platform))) TARGET := $(TARGET_NAME)_libretro_ios.dylib SHARED := -dynamiclib - fpic := -fPIC + fpic := -fPIC APPLE := 1 ifeq ($(IOSSDK),) IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path) @@ -155,17 +159,11 @@ else ifeq ($(platform), ps3) NO_MMAP = 1 DONT_COMPILE_IN_ZLIB = 1 - asm_memory = 0 - asm_render = 0 - asm_ym2612 = 0 - asm_misc = 0 - asm_cdpico = 0 - asm_cdmemory = 0 - asm_mix = 0 use_cyclone = 0 use_fame = 1 use_drz80 = 0 use_cz80 = 1 + use_sh2drc = 1 # sncps3 else ifeq ($(platform), sncps3) @@ -177,17 +175,11 @@ else ifeq ($(platform), sncps3) NO_MMAP = 1 DONT_COMPILE_IN_ZLIB = 1 - asm_memory = 0 - asm_render = 0 - asm_ym2612 = 0 - asm_misc = 0 - asm_cdpico = 0 - asm_cdmemory = 0 - asm_mix = 0 use_cyclone = 0 use_fame = 1 use_drz80 = 0 use_cz80 = 1 + use_sh2drc = 1 # Lightweight PS3 Homebrew SDK else ifeq ($(platform), psl1ght) @@ -199,17 +191,11 @@ else ifeq ($(platform), psl1ght) NO_MMAP = 1 DONT_COMPILE_IN_ZLIB = 1 - asm_memory = 0 - asm_render = 0 - asm_ym2612 = 0 - asm_misc = 0 - asm_cdpico = 0 - asm_cdmemory = 0 - asm_mix = 0 use_cyclone = 0 use_fame = 1 use_drz80 = 0 use_cz80 = 1 + use_sh2drc = 1 # PSP else ifeq ($(platform), psp1) @@ -222,17 +208,12 @@ else ifeq ($(platform), psp1) NO_MMAP = 1 DONT_COMPILE_IN_ZLIB = 1 - asm_memory = 0 asm_render = 1 - asm_ym2612 = 0 - asm_misc = 0 - asm_cdpico = 0 - asm_cdmemory = 0 - asm_mix = 0 use_cyclone = 0 use_fame = 1 use_drz80 = 0 use_cz80 = 1 + use_sh2drc = 1 # CTR (3DS) else ifeq ($(platform), ctr) @@ -250,14 +231,6 @@ else ifeq ($(platform), ctr) ARCH = arm ARM_ASM = 1 - asm_memory = 1 - asm_render = 1 - asm_ym2612 = 1 - asm_misc = 1 - asm_cdpico = 1 - asm_cdmemory = 1 - asm_mix = 1 - use_cyclone = 1 use_fame = 0 use_drz80 = 1 @@ -280,14 +253,6 @@ else ifeq ($(platform), raspberrypi) fpic := -fPIC DONT_COMPILE_IN_ZLIB = 1 - asm_memory = 1 - asm_render = 1 - asm_ym2612 = 1 - asm_misc = 1 - asm_cdpico = 1 - asm_cdmemory = 1 - asm_mix = 1 - use_cyclone = 1 use_fame = 0 use_drz80 = 1 @@ -309,14 +274,8 @@ else ifeq ($(platform), vita) NO_MMAP = 1 DONT_COMPILE_IN_ZLIB = 1 ARCH = arm + ARM_ASM = 1 - asm_memory = 1 - asm_render = 1 - asm_ym2612 = 1 - asm_misc = 1 - asm_cdpico = 1 - asm_cdmemory = 1 - asm_mix = 1 use_cyclone = 1 use_fame = 0 use_drz80 = 1 @@ -348,7 +307,7 @@ else ifeq ($(platform), wii) # QNX else ifeq ($(platform), qnx) TARGET := $(TARGET_NAME)_libretro_$(platform).so - fpic := -fPIC + fpic := -fPIC CC = qcc -Vgcc_ntoarmv7le CC_AS = $(CC) CFLAGS += -DBASE_ADDR_FIXED=0 -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp @@ -367,7 +326,7 @@ else ifeq ($(platform), qnx) else ifneq (,$(findstring armv,$(platform))) TARGET := $(TARGET_NAME)_libretro.so SHARED := -shared -Wl,--no-undefined,-Bsymbolic - fpic := -fPIC + fpic := -fPIC ifneq (,$(findstring cortexa5,$(platform))) CFLAGS += -marm -mcpu=cortex-a5 ASFLAGS += -mcpu=cortex-a5 @@ -408,21 +367,14 @@ else ifeq ($(platform), emscripten) # GCW0 else ifeq ($(platform), gcw0) TARGET := $(TARGET_NAME)_libretro.so - CC = /opt/gcw0-toolchain/usr/bin/mipsel-linux-gcc - AR = /opt/gcw0-toolchain/usr/bin/mipsel-linux-ar + CC = mipsel-linux-gcc + AR = mipsel-linux-ar SHARED := -shared -nostdlib - fpic := -fPIC + fpic := -fPIC LIBM := DONT_COMPILE_IN_ZLIB = 1 CFLAGS += -ffast-math -march=mips32 -mtune=mips32r2 -mhard-float - asm_memory = 0 - asm_render = 0 - asm_ym2612 = 0 - asm_misc = 0 - asm_cdpico = 0 - asm_cdmemory = 0 - asm_mix = 0 use_cyclone = 0 use_fame = 1 use_drz80 = 0 @@ -452,6 +404,8 @@ asm_ym2612 = 1 asm_misc = 1 asm_cdmemory = 1 asm_mix = 1 +asm_32xdraw = 1 +asm_32xmemory = 1 endif CFLAGS += $(fpic) diff --git a/cpu/drc/emit_x86.c b/cpu/drc/emit_x86.c index c836e159..7006beff 100644 --- a/cpu/drc/emit_x86.c +++ b/cpu/drc/emit_x86.c @@ -733,7 +733,7 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI, // x86-64,i386 common /* mov r <-> [ebp+#offs] */ \ if ((offs) == 0) { \ emith_deref_modrm(op, 0, r, rs); \ - } else if (abs(offs) >= 0x80) { \ + } else if ((s32)(offs) < -0x80 || (s32)(offs) >= 0x80) { \ emith_deref_modrm(op, 2, r, rs); \ EMIT(offs, u32); \ } else { \ @@ -1075,7 +1075,7 @@ enum { xAX = 0, xCX, xDX, xBX, xSP, xBP, xSI, xDI, // x86-64,i386 common #define PARAM_REGS { xCX, xDX, xR8, xR9 } #define PRESERVED_REGS { xSI, xDI, xR12, xR13, xR14, xR15, xBX, xBP } #define TEMPORARY_REGS { xAX, xR10, xR11 } -#define STATIC_SH2_REGS { SHR_SR,xBX , SHR_R(0),xR15 , SH2_R(1),xR14 } +#define STATIC_SH2_REGS { SHR_SR,xBX , SHR_R(0),xR15 , SHR_R(1),xR14 } #define host_arg2reg(rd, arg) \ switch (arg) { \ diff --git a/cpu/sh2/compiler.c b/cpu/sh2/compiler.c index cba97e2b..c8940432 100644 --- a/cpu/sh2/compiler.c +++ b/cpu/sh2/compiler.c @@ -1273,24 +1273,23 @@ static void dr_flush_tcache(int tcid) blink_free[tcid] = NULL; memset(unresolved_links[tcid], 0, sizeof(*unresolved_links[0]) * HASH_TABLE_SIZE(tcid)); memset(hash_tables[tcid], 0, sizeof(*hash_tables[0]) * HASH_TABLE_SIZE(tcid)); - if (Pico32xMem->sdram != NULL) { - if (tcid == 0) { // ROM, RAM - memset(Pico32xMem->drcblk_ram, 0, sizeof(Pico32xMem->drcblk_ram)); - memset(Pico32xMem->drclit_ram, 0, sizeof(Pico32xMem->drclit_ram)); - memset(sh2s[0].branch_cache, -1, sizeof(sh2s[0].branch_cache)); - memset(sh2s[1].branch_cache, -1, sizeof(sh2s[1].branch_cache)); - memset(sh2s[0].rts_cache, -1, sizeof(sh2s[0].rts_cache)); - memset(sh2s[1].rts_cache, -1, sizeof(sh2s[1].rts_cache)); - sh2s[0].rts_cache_idx = sh2s[1].rts_cache_idx = 0; - } else { - memset(Pico32xMem->drcblk_ram, 0, sizeof(Pico32xMem->drcblk_ram)); - memset(Pico32xMem->drclit_ram, 0, sizeof(Pico32xMem->drclit_ram)); - memset(Pico32xMem->drcblk_da[tcid - 1], 0, sizeof(Pico32xMem->drcblk_da[tcid - 1])); - memset(Pico32xMem->drclit_da[tcid - 1], 0, sizeof(Pico32xMem->drclit_da[tcid - 1])); - memset(sh2s[tcid - 1].branch_cache, -1, sizeof(sh2s[0].branch_cache)); - memset(sh2s[tcid - 1].rts_cache, -1, sizeof(sh2s[0].rts_cache)); - sh2s[tcid - 1].rts_cache_idx = 0; - } + + if (tcid == 0) { // ROM, RAM + memset(Pico32xMem->drcblk_ram, 0, sizeof(Pico32xMem->drcblk_ram)); + memset(Pico32xMem->drclit_ram, 0, sizeof(Pico32xMem->drclit_ram)); + memset(sh2s[0].branch_cache, -1, sizeof(sh2s[0].branch_cache)); + memset(sh2s[1].branch_cache, -1, sizeof(sh2s[1].branch_cache)); + memset(sh2s[0].rts_cache, -1, sizeof(sh2s[0].rts_cache)); + memset(sh2s[1].rts_cache, -1, sizeof(sh2s[1].rts_cache)); + sh2s[0].rts_cache_idx = sh2s[1].rts_cache_idx = 0; + } else { + memset(Pico32xMem->drcblk_ram, 0, sizeof(Pico32xMem->drcblk_ram)); + memset(Pico32xMem->drclit_ram, 0, sizeof(Pico32xMem->drclit_ram)); + memset(Pico32xMem->drcblk_da[tcid - 1], 0, sizeof(Pico32xMem->drcblk_da[tcid - 1])); + memset(Pico32xMem->drclit_da[tcid - 1], 0, sizeof(Pico32xMem->drclit_da[tcid - 1])); + memset(sh2s[tcid - 1].branch_cache, -1, sizeof(sh2s[0].branch_cache)); + memset(sh2s[tcid - 1].rts_cache, -1, sizeof(sh2s[0].rts_cache)); + sh2s[tcid - 1].rts_cache_idx = 0; } #if (DRC_DEBUG & 4) tcache_dsm_ptrs[tcid] = tcache_ring[tcid].base; diff --git a/cpu/sh2/compiler.h b/cpu/sh2/compiler.h index b1b7487f..76b44552 100644 --- a/cpu/sh2/compiler.h +++ b/cpu/sh2/compiler.h @@ -31,7 +31,7 @@ unsigned short scan_block(uint32_t base_pc, int is_slave, unsigned char *op_flags, uint32_t *end_pc, uint32_t *base_literals, uint32_t *end_literals); -#if defined(DRC_SH2) && defined(__GNUC__) +#if defined(DRC_SH2) && defined(__GNUC__) && !defined(__clang__) // direct access to some host CPU registers used by the DRC if gcc is used. // XXX MUST match SHR_SR definitions in cpu/drc/emit_*.c; should be moved there // XXX yuck, there's no portable way to determine register size. Use long long diff --git a/cpu/sh2/sh2.h b/cpu/sh2/sh2.h index b0054c05..4b0b3384 100644 --- a/cpu/sh2/sh2.h +++ b/cpu/sh2/sh2.h @@ -106,7 +106,11 @@ int sh2_execute_interpreter(SH2 *sh2c, int cycles); static __inline void sh2_execute_prepare(SH2 *sh2, int use_drc) { +#ifdef DRC_SH2 sh2->run = use_drc ? sh2_execute_drc : sh2_execute_interpreter; +#else + sh2->run = sh2_execute_interpreter; +#endif } static __inline int sh2_execute(SH2 *sh2, int cycles) diff --git a/tools/mkoffsets.sh b/tools/mkoffsets.sh index d890fc0f..6b086a93 100755 --- a/tools/mkoffsets.sh +++ b/tools/mkoffsets.sh @@ -8,6 +8,20 @@ CC=${CC:-gcc} # endianess of target (automagically determined below) ENDIAN= +# don't do this if ELF format isn't used. it doesn't matter since offsets are +# only needed for the asm parts (currently mips/arm32) and those have ELF +check_elf () +{ + echo '#include ' >/tmp/getoffs.c + echo "const int32_t val = 1;" >>/tmp/getoffs.c + $CC $CFLAGS -I .. -c /tmp/getoffs.c -o /tmp/getoffs.o || exit 1 + if ! command -v readelf >/dev/null || ! file /tmp/getoffs.o | grep -q ELF; then + echo "/* mkoffset.sh: no readelf or not ELF, offset table not created */" >$fn + echo "WARNING: no readelf or not ELF, offset table not created" + exit + fi +} + # compile with target C compiler and extract value from .rodata section compile_rodata () { @@ -49,13 +63,7 @@ get_define () # prefix struct member member... fn="${1:-.}/pico_int_offs.h" if echo $CFLAGS | grep -qe -flto; then CFLAGS="$CFLAGS -fno-lto"; fi -# don't do this if readelf isn't available. it doesn't matter since offsets are -# only needed for the asm parts (currently mips/arm32) and those have readelf -if ! command -v readelf >/dev/null; then - echo "/* mkoffset.sh: readelf not found, offset table not created */" >$fn - echo "WARNING: readelf not found, offset table not created" - exit -fi +check_elf # determine endianess echo '#include ' >/tmp/getoffs.c echo "const int32_t val = 1;" >>/tmp/getoffs.c -- 2.39.5