From 08be5f1dab402a1ec3eaac119f52a8b258c0f216 Mon Sep 17 00:00:00 2001 From: OsirizX Date: Wed, 11 Jan 2023 09:46:50 -0800 Subject: [PATCH] Add dynarec support for PS3 --- Makefile.libretro | 4 ---- cpu/drc/emit_ppc.c | 18 ++++++++++++++++++ platform/libretro/libretro.c | 13 +++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Makefile.libretro b/Makefile.libretro index 0a859684..0d1dc08f 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -188,13 +188,9 @@ else ifneq (,$(filter $(platform), ps3 psl1ght)) CFLAGS += -DFAMEC_NO_GOTOS -D__PS3__ STATIC_LINKING = 1 STATIC_LINKING_LINK = 1 - NO_MMAP = 1 ifeq ($(platform), psl1ght) FLAGS += -D__PSL1GHT__ endif - # PS3 has memory mapped in a way not suitable for DRC - use_sh2drc = 0 - use_svpdrc = 0 # PSP else ifeq ($(platform), psp1) diff --git a/cpu/drc/emit_ppc.c b/cpu/drc/emit_ppc.c index f9fe9b49..7d4dfeab 100644 --- a/cpu/drc/emit_ppc.c +++ b/cpu/drc/emit_ppc.c @@ -40,6 +40,7 @@ // reserved: r0(zero), r1(stack), r2(TOC), r13(TID) // additionally reserved on OSX: r31(PIC), r30(frame), r11(parentframe) // for OSX PIC code, on function calls r12 must contain the called address +#define TOC_REG 2 #define RET_REG 3 #define PARAM_REGS { 3, 4, 5, 6, 7, 8, 9, 10 } #define PRESERVED_REGS { 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 } @@ -1506,19 +1507,36 @@ static int emith_cond_check(int cond) #define emith_call_cond(cond, target) \ emith_call(target) +#ifdef __PS3__ #define emith_call_reg(r) do { \ + emith_read_r_r_offs_ptr(TOC_REG, r, 8); \ + emith_read_r_r_offs_ptr(r, r, 0); \ EMIT(PPC_MTSP_REG(r, CTR)); \ EMIT(PPC_BLCTRCOND(BXX)); \ } while(0) +#else +#define emith_call_reg(r) do { \ + EMIT(PPC_MTSP_REG(r, CTR)); \ + EMIT(PPC_BLCTRCOND(BXX)); \ +} while(0) +#endif #define emith_abicall_ctx(offs) do { \ emith_ctx_read_ptr(CR, offs); \ emith_call_reg(CR); \ } while (0) +#ifdef __PS3__ #define emith_abijump_reg(r) \ if ((r) != CR) emith_move_r_r(CR, r); \ + emith_read_r_r_offs_ptr(TOC_REG, CR, 8); \ + emith_read_r_r_offs_ptr(CR, CR, 0); \ emith_jump_reg(CR) +#else +#define emith_abijump_reg(r) \ + if ((r) != CR) emith_move_r_r(CR, r); \ + emith_jump_reg(CR) +#endif #define emith_abijump_reg_c(cond, r) \ emith_abijump_reg(r) #define emith_abicall(target) \ diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index f20cf861..a0d36d4e 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -62,6 +62,12 @@ static int ctr_svchack_successful = 0; static int sceBlock; int getVMBlock(); int _newlib_vm_size_user = 1 << TARGET_SIZE_2; + +#elif defined(__PS3__) +#include +#include + +static uint64_t page_table[2] = {0, 0}; #endif #include "libretro_core_options.h" @@ -471,6 +477,9 @@ void *plat_mem_get_for_drc(size_t size) // For WiiU, a slice of RWX memory left from the exploit is used, see: // https://github.com/embercold/pcsx_rearmed/commit/af0453223 mem = (void *)(0x01000000 - size); +#elif defined __PS3__ + ps3mapi_process_page_allocate(sysProcessGetPid(), size, PAGE_SIZE_AUTO, 0x2F, 1, page_table); + mem = (void *)page_table[0]; #endif return mem; } @@ -2374,6 +2383,10 @@ void retro_deinit(void) free(vout_buf); free(retro_palette); ps2 = NULL; +#elif defined(__PS3__) + free(vout_buf); + if (page_table[0] > 0 && page_table[1] > 0) + ps3mapi_process_page_free(sysProcessGetPid(), 0x2F, page_table); #else free(vout_buf); #endif -- 2.39.5