From df9251536deed37b18d10b8bc3502ee39006a320 Mon Sep 17 00:00:00 2001 From: notaz Date: Fri, 13 Oct 2017 23:36:51 +0300 Subject: [PATCH] libretro: satisfy vita's dynarec needs in a cleaner way --- cpu/drc/cmn.c | 14 ++++++++++---- cpu/drc/cmn.h | 2 +- pico/pico.h | 3 +++ platform/libretro/libretro.c | 24 +++++++++++++++++++----- platform/linux/emu.c | 4 ++++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/cpu/drc/cmn.c b/cpu/drc/cmn.c index acff42c8..27ff9812 100644 --- a/cpu/drc/cmn.c +++ b/cpu/drc/cmn.c @@ -10,14 +10,20 @@ #include #include "cmn.h" -u8 ALIGNED(4096) tcache[DRC_TCACHE_SIZE]; - +u8 ALIGNED(4096) tcache_default[DRC_TCACHE_SIZE]; +u8 *tcache; void drc_cmn_init(void) { - int ret = plat_mem_set_exec(tcache, sizeof(tcache)); + int ret; + + tcache = plat_mem_get_for_drc(DRC_TCACHE_SIZE); + if (tcache == NULL) + tcache = tcache_default; + + ret = plat_mem_set_exec(tcache, DRC_TCACHE_SIZE); elprintf(EL_STATUS, "drc_cmn_init: %p, %zd bytes: %d", - tcache, sizeof(tcache), ret); + tcache, DRC_TCACHE_SIZE, ret); #ifdef __arm__ if (PicoOpt & POPT_EN_DRC) diff --git a/cpu/drc/cmn.h b/cpu/drc/cmn.h index 4737b74d..8953edd1 100644 --- a/cpu/drc/cmn.h +++ b/cpu/drc/cmn.h @@ -5,7 +5,7 @@ typedef unsigned int u32; #define DRC_TCACHE_SIZE (2*1024*1024) -extern u8 tcache[DRC_TCACHE_SIZE]; +extern u8 *tcache; void drc_cmn_init(void); void drc_cmn_cleanup(void); diff --git a/pico/pico.h b/pico/pico.h index 527498ee..f1687f51 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -34,6 +34,9 @@ extern void cache_flush_d_inval_i(void *start_addr, void *end_addr); extern void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed); extern void *plat_mremap(void *ptr, size_t oldsize, size_t newsize); extern void plat_munmap(void *ptr, size_t size); + +// memory for the dynarec; plat_mem_get_for_drc() can just return NULL +extern void *plat_mem_get_for_drc(size_t size); extern int plat_mem_set_exec(void *ptr, size_t size); // this one should handle display mode changes diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index b6833741..e7f588a1 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -98,6 +98,7 @@ void cache_flush_d_inval_i(void *start, void *end) { #ifdef __arm__ size_t len = (char *)end - (char *)start; + (void)len; #if defined(__BLACKBERRY_QNX__) msync(start, end - start, MS_SYNC | MS_CACHE_ONLY | MS_INVALIDATE_ICACHE); #elif defined(__MACH__) @@ -435,14 +436,25 @@ void plat_munmap(void *ptr, size_t size) } #endif +// if NULL is returned, static buffer is used +void *plat_mem_get_for_drc(size_t size) +{ + void *mem = NULL; +#ifdef VITA + sceKernelGetMemBlockBase(sceBlock, &mem); +#endif + return mem; +} + int plat_mem_set_exec(void *ptr, size_t size) { + int ret = -1; #ifdef _WIN32 - int ret = VirtualProtect(ptr,size,PAGE_EXECUTE_READWRITE,0); + ret = VirtualProtect(ptr, size, PAGE_EXECUTE_READWRITE, 0); if (ret == 0 && log_cb) - log_cb(RETRO_LOG_ERROR, "mprotect(%p, %zd) failed: %d\n", ptr, size, 0); + log_cb(RETRO_LOG_ERROR, "VirtualProtect(%p, %d) failed: %d\n", ptr, (int)size, + GetLastError()); #elif defined(_3DS) - int ret = -1; if (ctr_svchack_successful) { unsigned int currentHandle; @@ -461,9 +473,9 @@ int plat_mem_set_exec(void *ptr, size_t size) } #elif defined(VITA) - int ret = sceKernelOpenVMDomain(); + ret = sceKernelOpenVMDomain(); #else - int ret = mprotect(ptr, size, PROT_READ | PROT_WRITE | PROT_EXEC); + ret = mprotect(ptr, size, PROT_READ | PROT_WRITE | PROT_EXEC); if (ret != 0 && log_cb) log_cb(RETRO_LOG_ERROR, "mprotect(%p, %zd) failed: %d\n", ptr, size, errno); #endif @@ -1380,3 +1392,5 @@ void retro_deinit(void) vout_buf = NULL; PicoExit(); } + +// vim:shiftwidth=3:ts=3:expandtab diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 5a97959b..aee8d44c 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -203,3 +203,7 @@ void plat_wait_till_us(unsigned int us_to) } } +void *plat_mem_get_for_drc(size_t size) +{ + return NULL; +} -- 2.39.5