Enable runtime dynarec enable/disable

Added a more thorough cache cleanup for reset/mode-change too.
Fixed the mmap initialization that ends up leaking memory.
Minor x86 asm fixes for Android.
This commit is contained in:
David Guillen Fandos 2021-03-17 21:05:49 +01:00
parent fb7ca09b01
commit eab44b9e0b
8 changed files with 43 additions and 58 deletions

View File

@ -31,6 +31,7 @@
#define PATH_SEPARATOR_CHAR '/'
#endif
/* On x86 we pass arguments via registers instead of stack */
#ifdef X86_ARCH
#define function_cc __attribute__((regparm(2)))
#else
@ -55,8 +56,6 @@
// functions on PSP for vastly improved memstick performance.
#ifdef PSP
#define fastcall
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
@ -64,13 +63,8 @@
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psprtc.h>
#define convert_palette(value) \
value = ((value & 0x7FE0) << 1) | (value & 0x1F)
#include <time.h>
#else
typedef unsigned char u8;
typedef signed char s8;
typedef unsigned short int u16;
@ -79,10 +73,14 @@
typedef signed int s32;
typedef unsigned long long int u64;
typedef signed long long int s64;
#endif
#ifdef USE_BGR_FORMAT
#define convert_palette(value) \
value = ((value & 0x7FE0) << 1) | (value & 0x1F)
#else
#define convert_palette(value) \
value = ((value & 0x1F) << 11) | ((value & 0x03E0) << 1) | (value >> 10)
#endif
#define GBA_SCREEN_WIDTH (240)

1
cpu.h
View File

@ -174,6 +174,7 @@ extern u32 *rom_branch_hash[ROM_BRANCH_HASH_SIZE];
void flush_translation_cache_rom(void);
void flush_translation_cache_ram(void);
void dump_translation_cache(void);
void wipe_caches(void);
extern u32 reg_mode[7][7];
extern u32 spsr[6];

View File

@ -3686,6 +3686,17 @@ void flush_translation_cache_rom(void)
memset(rom_branch_hash, 0, sizeof(rom_branch_hash));
}
void wipe_caches(void)
{
/* Ensure we wipe everything including the SMC mirrors */
flush_translation_cache_rom();
ewram_code_min = 0;
ewram_code_max = 0x3FFFF;
iwram_code_min = 0;
iwram_code_max = 0x7FFF;
flush_translation_cache_ram();
}
#define cache_dump_prefix ""
void dump_translation_cache(void)

View File

@ -3394,10 +3394,7 @@ void gba_load_state(const void* src)
#ifdef HAVE_DYNAREC
if (dynarec_enable)
{
flush_translation_cache_ram();
flush_translation_cache_rom();
}
wipe_caches();
#endif
oam_update = 1;

View File

@ -408,7 +408,13 @@ void retro_get_system_av_info(struct retro_system_av_info* info)
void retro_init(void)
{
#if defined(_3DS) && defined(HAVE_DYNAREC)
#if defined(HAVE_DYNAREC)
#if defined(HAVE_MMAP)
rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
#elif defined(_3DS)
if (__ctr_svchax && !translation_caches_inited)
{
uint32_t currentHandle;
@ -430,10 +436,8 @@ void retro_init(void)
ctr_flush_invalidate_cache();
translation_caches_inited = 1;
}
#endif
#if defined(VITA) && defined(HAVE_DYNAREC)
if(!translation_caches_inited){
#elif defined(VITA)
if(!translation_caches_inited){
void* currentHandle;
sceBlock = getVMBlock();
@ -456,8 +460,8 @@ void retro_init(void)
ram_translation_ptr = ram_translation_cache;
sceKernelOpenVMDomain();
translation_caches_inited = 1;
}
}
#endif
#endif
if (!gamepak_rom)
@ -641,16 +645,19 @@ static void check_variables(int started_from_load)
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (started_from_load)
{
if (strcmp(var.value, "disabled") == 0)
dynarec_enable = 0;
else if (strcmp(var.value, "enabled") == 0)
dynarec_enable = 1;
}
int prevvalue = dynarec_enable;
if (strcmp(var.value, "disabled") == 0)
dynarec_enable = 0;
else if (strcmp(var.value, "enabled") == 0)
dynarec_enable = 1;
if (dynarec_enable != prevvalue)
wipe_caches();
}
else
dynarec_enable = 1;
#else
dynarec_enable = 0;
#endif
var.key = "gpsp_frameskip";
@ -779,34 +786,6 @@ bool retro_load_game(const struct retro_game_info* info)
check_variables(1);
set_input_descriptors();
#if defined(HAVE_DYNAREC)
if (dynarec_enable)
{
#if defined(HAVE_MMAP)
rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE,
PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
#elif defined(_3DS)
dynarec_enable = __ctr_svchax;
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
#elif defined(PSP) || defined(VITA)
dynarec_enable = 1;
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
#endif
}
else
dynarec_enable = 0;
#else
dynarec_enable = 0;
#endif
char filename_bios[MAX_PATH];
const char* dir = NULL;

View File

@ -147,7 +147,7 @@ struct retro_core_option_definition option_defs_us[] = {
#if defined(HAVE_DYNAREC)
{
"gpsp_drc",
"Dynamic Recompiler (Restart)",
"Dynamic Recompiler",
"Dynamically recompile CPU instructions to native instructions. Greatly improves performance, but may reduce accuracy.",
{
{ "enabled", NULL },

3
main.c
View File

@ -114,8 +114,7 @@ void init_main(void)
video_count = 960;
#ifdef HAVE_DYNAREC
flush_translation_cache_rom();
flush_translation_cache_ram();
wipe_caches();
init_emitter();
#endif
}

View File

@ -538,7 +538,7 @@ _execute_arm_translate:
# (if the CPU is halted, do not start executing but
# loop in the alert loop until it wakes up)
cmp $0, CPU_HALT_STATE(%ebx)
cmpl $0, CPU_HALT_STATE(%ebx)
je 1f
call alert_loop # Need to push something to the stack