diff options
author | frangarcj | 2016-09-06 13:49:55 +0200 |
---|---|---|
committer | frangarcj | 2016-09-06 13:49:55 +0200 |
commit | 1a5fd79401ac52789fad34c6b852b947200a6334 (patch) | |
tree | 6284e07ed78f659bd87c7e75c0db54d52fa784eb /frontend | |
parent | 1cc8c854f8161cd0251a9b92929ad01584031ed3 (diff) | |
download | pcsx_rearmed-1a5fd79401ac52789fad34c6b852b947200a6334.tar.gz pcsx_rearmed-1a5fd79401ac52789fad34c6b852b947200a6334.tar.bz2 pcsx_rearmed-1a5fd79401ac52789fad34c6b852b947200a6334.zip |
(VITA) Some dynarec
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/libretro.c | 83 | ||||
-rw-r--r-- | frontend/vita/pthread.h | 156 | ||||
-rw-r--r-- | frontend/vita/sys/mman.h | 29 |
3 files changed, 236 insertions, 32 deletions
diff --git a/frontend/libretro.c b/frontend/libretro.c index 5bf737f..75f9b98 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -256,6 +256,85 @@ void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) } #endif +#ifdef VITA +typedef struct +{ + void* buffer; + uint32_t target_map; + size_t size; + enum psxMapTag tag; +}psx_map_t; + +psx_map_t custom_psx_maps[] = { + {NULL, NULL, 0x210000, MAP_TAG_RAM}, // 0x80000000 + {NULL, NULL, 0x010000, MAP_TAG_OTHER}, // 0x1f800000 + {NULL, NULL, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000 + {NULL, NULL, 0x800000, MAP_TAG_LUTS}, // 0x08000000 + {NULL, NULL, 0x200000, MAP_TAG_VRAM}, // 0x00000000 +}; + +void* pl_vita_mmap(unsigned long addr, size_t size, int is_fixed, + enum psxMapTag tag) +{ + (void)is_fixed; + (void)addr; + + + psx_map_t* custom_map = custom_psx_maps; + + for (; custom_map->size; custom_map++) + { + if ((custom_map->size == size) && (custom_map->tag == tag)) + { + int block, ret; + char blockname[32]; + sprintf(blockname, "CODE 0x%08X",tag); + + block = sceKernelAllocMemBlockForVM(blockname, size); + if(block<=0){ + sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, tag); + exit(1); + } + + // get base address + ret = sceKernelGetMemBlockBase(block, &custom_map->buffer); + if (ret < 0) + { + sceClibPrintf("could get address @0x%08X 0x%08X 0x%08X \n", block, ret, tag); + exit(1); + } + + custom_map->target_map = block; + + return custom_map->buffer; + } + } + + + return malloc(size); +} + +void pl_vita_munmap(void *ptr, size_t size, enum psxMapTag tag) +{ + (void)tag; + + psx_map_t* custom_map = custom_psx_maps; + + for (; custom_map->size; custom_map++) + { + if ((custom_map->buffer == ptr)) + { + sceKernelFreeMemBlock(custom_map->target_map); + custom_map->buffer = NULL; + custom_map->target_map = NULL; + return; + } + } + + free(ptr); +} +#endif + static void *pl_mmap(unsigned int size) { return psxMap(0, size, 0, MAP_TAG_VRAM); @@ -1475,6 +1554,10 @@ void retro_init(void) psxMapHook = pl_3ds_mmap; psxUnmapHook = pl_3ds_munmap; #endif +#ifdef VITA + psxMapHook = pl_vita_mmap; + psxUnmapHook = pl_vita_munmap; +#endif ret = emu_core_preinit(); #ifdef _3DS /* emu_core_preinit sets the cpu to dynarec */ diff --git a/frontend/vita/pthread.h b/frontend/vita/pthread.h index c18b20b..e1afdc5 100644 --- a/frontend/vita/pthread.h +++ b/frontend/vita/pthread.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 The RetroArch team +/* Copyright (C) 2010-2016 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (psp_pthread.h). @@ -26,6 +26,7 @@ #ifdef VITA #include <psp2/kernel/threadmgr.h> +#include <sys/time.h> #else #include <pspkernel.h> #include <pspthreadman.h> @@ -34,13 +35,20 @@ #include <stdio.h> #include <retro_inline.h> -#define STACKSIZE (64 * 1024) +#define STACKSIZE (8 * 1024) typedef SceUID pthread_t; typedef SceUID pthread_mutex_t; typedef void* pthread_mutexattr_t; typedef int pthread_attr_t; -typedef SceUID pthread_cond_t; + +typedef struct +{ + SceUID mutex; + SceUID sema; + int waiting; +} pthread_cond_t; + typedef SceUID pthread_condattr_t; /* Use pointer values to create unique names for threads/mutexes */ @@ -65,14 +73,15 @@ static int psp_thread_wrap(SceSize args, void *argp) static INLINE int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) { - sprintf(name_buffer, "0x%08X", (uint32_t) thread); + sprintf(name_buffer, "0x%08X", (unsigned int) thread); - *thread = sceKernelCreateThread(name_buffer, - psp_thread_wrap, 0x20, STACKSIZE, 0, #ifdef VITA - 0, + *thread = sceKernelCreateThread(name_buffer, psp_thread_wrap, + 0x10000100, 0x10000, 0, 0, NULL); +#else + *thread = sceKernelCreateThread(name_buffer, + psp_thread_wrap, 0x20, STACKSIZE, 0, NULL); #endif - NULL); sthread_args_struct sthread_args; sthread_args.arg = arg; @@ -84,10 +93,13 @@ static INLINE int pthread_create(pthread_t *thread, static INLINE int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { - sprintf(name_buffer, "0x%08X", (uint32_t) mutex); + sprintf(name_buffer, "0x%08X", (unsigned int) mutex); #ifdef VITA - return *mutex = sceKernelCreateMutex(name_buffer, 0, 0, 0); + *mutex = sceKernelCreateMutex(name_buffer, 0, 0, 0); + if(*mutex<0) + return *mutex; + return 0; #else return *mutex = sceKernelCreateSema(name_buffer, 0, 1, 1, NULL); #endif @@ -105,7 +117,9 @@ static INLINE int pthread_mutex_destroy(pthread_mutex_t *mutex) static INLINE int pthread_mutex_lock(pthread_mutex_t *mutex) { #ifdef VITA - return sceKernelLockMutex(*mutex, 1, 0); + int ret = sceKernelLockMutex(*mutex, 1, 0); + return ret; + #else /* FIXME: stub */ return 1; @@ -115,7 +129,8 @@ static INLINE int pthread_mutex_lock(pthread_mutex_t *mutex) static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex) { #ifdef VITA - return sceKernelUnlockMutex(*mutex, 1); + int ret = sceKernelUnlockMutex(*mutex, 1); + return ret; #else /* FIXME: stub */ return 1; @@ -125,16 +140,18 @@ static INLINE int pthread_mutex_unlock(pthread_mutex_t *mutex) static INLINE int pthread_join(pthread_t thread, void **retval) { - int exit_status; - SceUInt timeout = (SceUInt)-1; #ifdef VITA - sceKernelWaitThreadEnd(thread, &exit_status, &timeout); + int res = sceKernelWaitThreadEnd(thread, 0, 0); + if (res < 0) + return res; + return sceKernelDeleteThread(thread); #else + SceUInt timeout = (SceUInt)-1; sceKernelWaitThreadEnd(thread, &timeout); exit_status = sceKernelGetThreadExitStatus(thread); -#endif sceKernelDeleteThread(thread); return exit_status; +#endif } static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex) @@ -150,51 +167,142 @@ static INLINE int pthread_mutex_trylock(pthread_mutex_t *mutex) static INLINE int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { +#ifdef VITA + int ret = pthread_mutex_lock(&cond->mutex); + if (ret < 0) + return ret; + ++cond->waiting; + pthread_mutex_unlock(mutex); + pthread_mutex_unlock(&cond->mutex); + + ret = sceKernelWaitSema(cond->sema, 1, 0); + if (ret < 0) + sceClibPrintf("Premature wakeup: %08X", ret); + pthread_mutex_lock(mutex); + return ret; +#else + /* FIXME: stub */ sceKernelDelayThread(10000); return 1; +#endif } static INLINE int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) { - //FIXME: stub +#ifdef VITA + int ret = pthread_mutex_lock(&cond->mutex); + if (ret < 0) + return ret; + ++cond->waiting; + pthread_mutex_unlock(mutex); + pthread_mutex_unlock(&cond->mutex); + + SceUInt timeout = 0; + + timeout = abstime->tv_sec; + timeout += abstime->tv_nsec / 1.0e6; + + ret = sceKernelWaitSema(cond->sema, 1, &timeout); + if (ret < 0) + sceClibPrintf("Premature wakeup: %08X", ret); + pthread_mutex_lock(mutex); + return ret; + +#else + /* FIXME: stub */ return 1; +#endif } static INLINE int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { - //FIXME: stub +#ifdef VITA + + pthread_mutex_init(&cond->mutex,NULL); + if(cond->mutex<0){ + return cond->mutex; + } + sprintf(name_buffer, "0x%08X", (unsigned int) cond); + //cond->sema = sceKernelCreateCond(name_buffer, 0, cond->mutex, 0); + cond->sema = sceKernelCreateSema(name_buffer, 0, 0, 1, 0); + if(cond->sema<0){ + pthread_mutex_destroy(&cond->mutex); + return cond->sema; + } + + cond->waiting = 0; + + + return 0; + + +#else + /* FIXME: stub */ return 1; +#endif } static INLINE int pthread_cond_signal(pthread_cond_t *cond) { - //FIXME: stub +#ifdef VITA + pthread_mutex_lock(&cond->mutex); + if (cond->waiting) + { + --cond->waiting; + sceKernelSignalSema(cond->sema, 1); + } + pthread_mutex_unlock(&cond->mutex); + return 0; +#else + /* FIXME: stub */ return 1; +#endif } static INLINE int pthread_cond_broadcast(pthread_cond_t *cond) { - //FIXME: stub + /* FIXME: stub */ return 1; } static INLINE int pthread_cond_destroy(pthread_cond_t *cond) { - //FIXME: stub - return 1; +#ifdef VITA + int ret = sceKernelDeleteSema(cond->sema); + if(ret < 0) + return ret; + + return sceKernelDeleteMutex(cond->mutex); +#else + /* FIXME: stub */ + return 1; +#endif } static INLINE int pthread_detach(pthread_t thread) { - return 1; + return 0; } static INLINE void pthread_exit(void *retval) { - (void)retval; +#ifdef VITA + sceKernelExitDeleteThread(sceKernelGetThreadId()); +#endif +} + +static INLINE pthread_t pthread_self(void) +{ + /* zero 20-mar-2016: untested */ + return sceKernelGetThreadId(); +} + +static INLINE int pthread_equal(pthread_t t1, pthread_t t2) +{ + return t1 == t2; } #endif //_PSP_PTHREAD_WRAP__ diff --git a/frontend/vita/sys/mman.h b/frontend/vita/sys/mman.h index 66467f4..89da513 100644 --- a/frontend/vita/sys/mman.h +++ b/frontend/vita/sys/mman.h @@ -18,19 +18,32 @@ extern "C" { static inline void* mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { - (void)addr; (void)prot; (void)flags; (void)fd; (void)offset; - void* addr_out; + int block, ret; + + block = sceKernelAllocMemBlockForVM("code", len); + if(block<=0){ + sceClibPrintf("could not alloc mem block @0x%08X 0x%08X \n", block, len); + exit(1); + } + + // get base address + ret = sceKernelGetMemBlockBase(block, &addr); + if (ret < 0) + { + sceClibPrintf("could get address @0x%08X 0x%08X \n", block, addr); + exit(1); + } + - addr_out = malloc(len); - if(!addr_out) + if(!addr) return MAP_FAILED; - return addr_out; + return addr; } static inline int mprotect(void *addr, size_t len, int prot) @@ -43,8 +56,9 @@ static inline int mprotect(void *addr, size_t len, int prot) static inline int munmap(void *addr, size_t len) { - free(addr); - return 0; + int uid = sceKernelFindMemBlockByAddr(addr, len); + + return sceKernelFreeMemBlock(uid); } @@ -53,4 +67,3 @@ static inline int munmap(void *addr, size_t len) #endif #endif // MMAN_H - |