(VITA) Dynarec WIP

This commit is contained in:
Francisco José García García 2016-08-08 00:31:21 +02:00
parent 70fff8152f
commit 6ab0992ecf
4 changed files with 92 additions and 12 deletions

View File

@ -21,7 +21,10 @@
#define ARM_EMIT_H
#include "arm_codegen.h"
#if defined(VITA)
#define VITA_RW_INIT sceKernelOpenVMDomain
#define VITA_RW_END sceKernelCloseVMDomain
#endif
u32 arm_update_gba_arm(u32 pc);
u32 arm_update_gba_thumb(u32 pc);
u32 arm_update_gba_idle_arm(u32 pc);
@ -46,9 +49,11 @@ void execute_swi_thumb(u32 pc);
void execute_store_u32_safe(u32 address, u32 source);
#define write32(value) \
VITA_RW_INIT(); \
*((u32 *)translation_ptr) = value; \
translation_ptr += 4 \
translation_ptr += 4; \
VITA_RW_END() \
#define arm_relative_offset(source, offset) \
(((((u32)offset - (u32)source) - 8) >> 2) & 0xFFFFFF) \
@ -404,12 +409,17 @@ u32 arm_disect_imm_32bit(u32 imm, u32 *stores, u32 *rotations)
cycle_count = 0 \
#define generate_branch_patch_conditional(dest, offset) \
VITA_RW_INIT(); \
*((u32 *)(dest)) = (*((u32 *)dest) & 0xFF000000) | \
arm_relative_offset(dest, offset) \
arm_relative_offset(dest, offset); \
VITA_RW_END(); \
#define generate_branch_patch_unconditional(dest, offset) \
VITA_RW_INIT(); \
*((u32 *)(dest)) = (*((u32 *)dest) & 0xFF000000) | \
arm_relative_offset(dest, offset) \
arm_relative_offset(dest, offset); \
VITA_RW_END(); \
// A different function is called for idle updates because of the relative
// location of the embedded PC. The idle version could be optimized to put
@ -1931,4 +1941,3 @@ void execute_swi_hle_div_c()
generate_indirect_branch_no_cycle_update(type) \
#endif

5
cpu.h
View File

@ -146,6 +146,11 @@ extern u8* bios_translation_cache;
extern u8* rom_translation_cache_ptr;
extern u8* ram_translation_cache_ptr;
extern u8* bios_translation_cache_ptr;
#elif defined(VITA)
extern u8* rom_translation_cache;
extern u8* ram_translation_cache;
extern u8* bios_translation_cache;
extern int sceBlock;
#else
extern u8 rom_translation_cache[ROM_TRANSLATION_CACHE_SIZE];
extern u8 ram_translation_cache[RAM_TRANSLATION_CACHE_SIZE];

View File

@ -22,6 +22,9 @@
// - block memory needs psr swapping and user mode reg swapping
#include "common.h"
#if defined(VITA)
#include <psp2/kernel/sysmem.h>
#endif
u8 *last_rom_translation_ptr = NULL;
u8 *last_ram_translation_ptr = NULL;
@ -34,7 +37,15 @@ u8* bios_translation_cache;
u8 *rom_translation_ptr;
u8 *ram_translation_ptr;
u8 *bios_translation_ptr;
#elif defined(_3DS)
#elif defined(VITA)
u8* rom_translation_cache;
u8* ram_translation_cache;
u8* bios_translation_cache;
u8 *rom_translation_ptr;
u8 *ram_translation_ptr;
u8 *bios_translation_ptr;
int sceBlock;
#elif defined(_3DS)
u8* rom_translation_cache_ptr;
u8* ram_translation_cache_ptr;
u8* bios_translation_cache_ptr;
@ -233,6 +244,16 @@ extern u8 bit_count[256];
#if defined(PSP_BUILD)
#define translate_invalidate_dcache() sceKernelDcacheWritebackAll()
#elif defined(VITA)
#define RW_INIT sceKernelOpenVMDomain
#define RW_END sceKernelCloseVMDomain
#define translate_invalidate_dcache() (void)0
#define invalidate_icache_region(addr, size) \
{ \
sceKernelSyncVMDomain(sceBlock, addr, size); \
}
#elif defined(_3DS)
#include "3ds/3ds_utils.h"
#define translate_invalidate_dcache() ctr_flush_invalidate_cache()
@ -2850,7 +2871,7 @@ u8 *block_lookup_address_##type(u32 pc) \
(ROM_BRANCH_HASH_SIZE - 1); \
u32 *block_ptr = rom_branch_hash[hash_target]; \
u32 **block_ptr_address = rom_branch_hash + hash_target; \
\
RW_INIT(); \
while(block_ptr) \
{ \
if(block_ptr[0] == pc) \
@ -2858,11 +2879,10 @@ u8 *block_lookup_address_##type(u32 pc) \
block_address = (u8 *)(block_ptr + 2) + block_prologue_size; \
break; \
} \
\
block_ptr_address = (u32 **)(block_ptr + 1); \
block_ptr = (u32 *)block_ptr[1]; \
} \
\
RW_END(); \
if(!block_ptr) \
{ \
__label__ redo; \
@ -2870,12 +2890,14 @@ u8 *block_lookup_address_##type(u32 pc) \
\
redo: \
\
translation_recursion_level++; \
translation_recursion_level++; \
RW_INIT(); \
((u32 *)rom_translation_ptr)[0] = pc; \
((u32 **)rom_translation_ptr)[1] = NULL; \
*block_ptr_address = (u32 *)rom_translation_ptr; \
rom_translation_ptr += 8; \
block_address = rom_translation_ptr + block_prologue_size; \
RW_END(); \
block_lookup_translate_##type(rom, 0); \
translation_recursion_level--; \
\
@ -3776,4 +3798,3 @@ void dump_translation_cache(void)
bios_translation_ptr - bios_translation_cache);
file_close(bios_cache);
}

View File

@ -8,6 +8,12 @@
#include "libretro.h"
#include "memmap.h"
#if defined(VITA)
#include <psp2/kernel/sysmem.h>
static int translation_caches_inited = 0;
#endif
#if defined(_3DS)
void* linearMemAlign(size_t size, size_t alignment);
void linearFree(void* mem);
@ -118,6 +124,7 @@ void retro_get_system_av_info(struct retro_system_av_info* info)
void retro_init(void)
{
#if defined(_3DS) && defined(HAVE_DYNAREC)
if (__ctr_svchax && !translation_caches_inited)
{
@ -143,6 +150,35 @@ void retro_init(void)
ctr_flush_invalidate_cache();
translation_caches_inited = 1;
}
#endif
#if defined(VITA)
if(!translation_caches_inited){
void* currentHandle;
sceBlock = sceKernelAllocMemBlockForVM("code", ROM_TRANSLATION_CACHE_SIZE +
RAM_TRANSLATION_CACHE_SIZE +
BIOS_TRANSLATION_CACHE_SIZE);
if (sceBlock < 0)
{
return sceBlock;
}
// get base address
int ret = sceKernelGetMemBlockBase(sceBlock, &currentHandle);
if (ret < 0)
{
return ret;
}
rom_translation_cache = (u8*)currentHandle;
ram_translation_cache = rom_translation_cache + ROM_TRANSLATION_CACHE_SIZE;
bios_translation_cache = ram_translation_cache + RAM_TRANSLATION_CACHE_SIZE;
rom_translation_ptr = rom_translation_cache;
ram_translation_ptr = ram_translation_cache;
bios_translation_ptr = bios_translation_cache;
translation_caches_inited = 1;
}
#endif
if (!gamepak_rom)
@ -190,6 +226,15 @@ void retro_deinit(void)
translation_caches_inited = 0;
}
#endif
#if defined(VITA)
if(translation_caches_inited){
sceKernelFreeMemBlock(sceBlock);
translation_caches_inited = 0;
}
#endif
#ifdef _3DS
linearFree(gba_screen_pixels);
#else