summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTwinaphex2016-08-08 00:53:54 +0200
committerGitHub2016-08-08 00:53:54 +0200
commitbeeee745ab0961a246f3413f3fbd7d65ad75c4ba (patch)
treea1033bb0339d2b52656a494b00c6418539f20e17
parent70fff8152ff39b6a781c4331c20963ef1fc4f8a2 (diff)
parent6ab0992ecfe714cb31f67038c4d5c92ab23204a9 (diff)
downloadpicogpsp-beeee745ab0961a246f3413f3fbd7d65ad75c4ba.tar.gz
picogpsp-beeee745ab0961a246f3413f3fbd7d65ad75c4ba.tar.bz2
picogpsp-beeee745ab0961a246f3413f3fbd7d65ad75c4ba.zip
Merge pull request #26 from frangarcj/master
(VITA) Dynarec WIP
-rw-r--r--arm/arm_emit.h21
-rw-r--r--cpu.h5
-rw-r--r--cpu_threaded.c33
-rw-r--r--libretro.c45
4 files changed, 92 insertions, 12 deletions
diff --git a/arm/arm_emit.h b/arm/arm_emit.h
index db894d1..bfd1c49 100644
--- a/arm/arm_emit.h
+++ b/arm/arm_emit.h
@@ -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
-
diff --git a/cpu.h b/cpu.h
index d292621..3ed9f07 100644
--- a/cpu.h
+++ b/cpu.h
@@ -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];
diff --git a/cpu_threaded.c b/cpu_threaded.c
index 44f5d84..e3e1a14 100644
--- a/cpu_threaded.c
+++ b/cpu_threaded.c
@@ -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);
}
-
diff --git a/libretro.c b/libretro.c
index 983a826..0de5075 100644
--- a/libretro.c
+++ b/libretro.c
@@ -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)
{
@@ -145,6 +152,35 @@ void retro_init(void)
}
#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)
init_gamepak_buffer();
init_sound(1);
@@ -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