From cd63cf1e82c933be0109ea7e75f21b0ee6aa11ae Mon Sep 17 00:00:00 2001 From: Jonathan Chambers Date: Thu, 1 Feb 2018 11:17:24 +0300 Subject: [PATCH] Initial support of Sony PlayStation Portable 2 (part of commit 9379c66 from Unity-Technologies/bdwgc) Issue #173 (bdwgc). * alloc.c [!MACOS && !MSWINCE && !SN_TARGET_ORBIS && !__CC_ARM]: Do not include sys/types.h if SN_TARGET_PSP2. * dyn_load.c [!MACOS && !_WIN32_WCE && !SN_TARGET_ORBIS && !__CC_ARM]: Likewise. * os_dep.c [!OS2 && !PCR && !AMIGA && !MACOS && !MSWINCE && !SN_TARGET_ORBIS && !__CC_ARM]: Likewise. * include/gc_config_macros.h [SN_TARGET_PSP2] (GC_THREADS): Define macro. * include/private/gcconfig.h [SN_TARGET_PSP2] (mach_type_known): Likewise. * include/private/gcconfig.h [ARM32 && SN_TARGET_PSP2] (NO_HANDLE_FORK, DATASTART, DATAEND, STACKBOTTOM): Likewise. * include/private/gcconfig.h [SN_TARGET_PSP2] (THREADS, GET_MEM): Likewise. * include/private/gc_locks.h [GC_PTHREADS && !GC_WIN32_THREADS && !SN_TARGET_ORBIS]: Do not include gc_atomic_ops.h if SN_TARGET_PSP2. * include/private/gc_locks.h [SN_TARGET_PSP2]: Include psp2-support.h. * include/private/gc_locks.h [SN_TARGET_PSP2] (GC_allocate_ml_PSP2): Declare GC_EXTERN variable. * include/private/gc_locks.h [SN_TARGET_PSP2] (UNCOND_LOCK, UNCOND_UNLOCK): Define (using GC_allocate_ml_PSP2 instead of GC_allocate_ml). * include/private/gc_priv.h [!HBLKSIZE && (LARGE_CONFIG || !SMALL_CONFIG) && SN_TARGET_PSP2] (CPP_LOG_HBLKSIZE): Define to 16 (instead of 12). * include/private/gcconfig.h [ARM32] (NOSYS): Do not define if SN_TARGET_PSP2. * os_dep.c (SBRK_ARG_T, OPT_MAP_ANON, GC_unix_mmap_get_mem, GC_unix_sbrk_get_mem, GC_unix_get_mem): Likewise. * pthread_support.c (GC_pthread_join, GC_pthread_detach, GC_pthread_create): Likewise. * include/private/gcconfig.h [ARM32 && SN_TARGET_PSP2] (psp2_get_stack_bottom): Declare external function. * include/private/gcconfig.h [SN_TARGET_PSP2] (psp2_get_mem): Likewise. * include/private/gcconfig.h [USE_MUNMAP && !MUNMAP_THRESHOLD && SN_TARGET_PSP2] (MUNMAP_THRESHOLD): Define to 2. * mach_dep.c: Skip everything in this file if SN_TARGET_PSP2. * pthread_stop_world.c: Likewise. * misc.c [SN_TARGET_PSP2] (GC_allocate_ml_PSP2): Define global varible (instead of GC_allocate_ml). * misc.c [!MSWIN32 && !MSWINCE && !OS2 && !MACOS && !GC_ANDROID_LOG && !NN_PLATFORM_CTR && !NINTENDO_SWITCH && !AMIGA && !SN_TARGET_ORBIS && !__CC_ARM]: Do not include unistd.h if SN_TARGET_PSP2. * misc.c [SN_TARGET_PSP2] (GC_write): Define to no-op. * pthread_support.c: Do not include sys/mman.h if SN_TARGET_PSP2. --- alloc.c | 3 ++- dyn_load.c | 4 ++-- include/gc_config_macros.h | 2 +- include/private/gc_locks.h | 18 +++++++++++++++--- include/private/gc_priv.h | 2 +- include/private/gcconfig.h | 22 +++++++++++++++++++--- mach_dep.c | 4 ++-- misc.c | 7 +++++-- os_dep.c | 5 +++-- pthread_stop_world.c | 3 ++- pthread_support.c | 10 +++++----- 11 files changed, 57 insertions(+), 23 deletions(-) diff --git a/alloc.c b/alloc.c index 83d7fb35..7247336c 100644 --- a/alloc.c +++ b/alloc.c @@ -20,7 +20,8 @@ #include #if !defined(MACOS) && !defined(MSWINCE) # include -# if !defined(__CC_ARM) && !defined(SN_TARGET_ORBIS) +# if !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) \ + && !defined(__CC_ARM) # include # endif #endif diff --git a/dyn_load.c b/dyn_load.c index 2047fa3a..a5051d44 100644 --- a/dyn_load.c +++ b/dyn_load.c @@ -26,8 +26,8 @@ * But then not much of anything is safe in the presence of dlclose. */ -#if !defined(MACOS) && !defined(SN_TARGET_ORBIS) && !defined(_WIN32_WCE) \ - && !defined(__CC_ARM) +#if !defined(MACOS) && !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) \ + && !defined(_WIN32_WCE) && !defined(__CC_ARM) # include #endif diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index bc0e2e6c..7e4f9a58 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -77,7 +77,7 @@ || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS) \ || defined(GC_OSF1_THREADS) || defined(GC_SOLARIS_THREADS) \ || defined(GC_WIN32_THREADS) || defined(GC_RTEMS_PTHREADS) \ - || defined(SN_TARGET_ORBIS) + || defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PSP2) # ifndef GC_THREADS # define GC_THREADS # endif diff --git a/include/private/gc_locks.h b/include/private/gc_locks.h index b7ff8b96..82bb2522 100644 --- a/include/private/gc_locks.h +++ b/include/private/gc_locks.h @@ -29,7 +29,7 @@ # ifdef THREADS # if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) \ - && !defined(SN_TARGET_ORBIS) + && !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) # include "gc_atomic_ops.h" # endif @@ -122,8 +122,20 @@ # define NO_THREAD ((unsigned long)(-1l)) /* != NUMERIC_THREAD_ID(pthread_self()) for any thread */ -# if (!defined(THREAD_LOCAL_ALLOC) || defined(USE_SPIN_LOCK)) \ - && !defined(USE_PTHREAD_LOCKS) +# ifdef SN_TARGET_PSP2 +# include "psp2-support.h" + GC_EXTERN WapiMutex GC_allocate_ml_PSP2; +# define UNCOND_LOCK() { int res; GC_ASSERT(I_DONT_HOLD_LOCK()); \ + res = PSP2_MutexLock(&GC_allocate_ml_PSP2); \ + GC_ASSERT(0 == res); (void)res; \ + SET_LOCK_HOLDER(); } +# define UNCOND_UNLOCK() { int res; GC_ASSERT(I_HOLD_LOCK()); \ + UNSET_LOCK_HOLDER(); \ + res = PSP2_MutexUnlock(&GC_allocate_ml_PSP2); \ + GC_ASSERT(0 == res); (void)res; } + +# elif (!defined(THREAD_LOCAL_ALLOC) || defined(USE_SPIN_LOCK)) \ + && !defined(USE_PTHREAD_LOCKS) /* In the THREAD_LOCAL_ALLOC case, the allocation lock tends to */ /* be held for long periods, if it is held at all. Thus spinning */ /* and sleeping for fixed periods are likely to result in */ diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 14a4926f..333969f6 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -805,7 +805,7 @@ GC_EXTERN GC_warn_proc GC_current_warn_proc; # if defined(LARGE_CONFIG) || !defined(SMALL_CONFIG) # ifdef ALPHA # define CPP_LOG_HBLKSIZE 13 -# elif defined(SN_TARGET_ORBIS) +# elif defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PSP2) # define CPP_LOG_HBLKSIZE 16 /* page size is set to 64K */ # else # define CPP_LOG_HBLKSIZE 12 diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 40c870b1..b69a420f 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -146,7 +146,8 @@ && !defined(OPENBSD) && !defined(DARWIN) && !defined(_WIN32) \ && !defined(__CEGCC__) && !defined(NN_PLATFORM_CTR) \ && !defined(NN_BUILD_TARGET_PLATFORM_NX) \ - && !defined(SN_TARGET_ORBIS) && !defined(SYMBIAN) + && !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) \ + && !defined(SYMBIAN) # define NOSYS # define mach_type_known # endif @@ -625,6 +626,10 @@ # define mach_type_known # endif +# if defined(SN_TARGET_PSP2) +# define mach_type_known +# endif + # if defined(NN_PLATFORM_CTR) # define mach_type_known # endif @@ -2329,6 +2334,13 @@ # define DATAEND ((ptr_t)(&_end)) # define DYNAMIC_LOADING # endif +# ifdef SN_TARGET_PSP2 +# define NO_HANDLE_FORK +# define DATASTART (ptr_t)ALIGNMENT +# define DATAEND (ptr_t)ALIGNMENT + void *psp2_get_stack_bottom(void); +# define STACKBOTTOM ((ptr_t)psp2_get_stack_bottom()) +# endif # ifdef NN_PLATFORM_CTR extern unsigned char Image$$ZI$$ZI$$Base[]; # define DATASTART (ptr_t)(Image$$ZI$$ZI$$Base) @@ -2934,7 +2946,7 @@ /* have a large virtual address space that a standard x64 platform has. */ #if defined(USE_MUNMAP) && !defined(MUNMAP_THRESHOLD) \ && (defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PS3) \ - || defined(MSWIN_XBOX1)) + || defined(SN_TARGET_PSP2) || defined(MSWIN_XBOX1)) # define MUNMAP_THRESHOLD 2 #endif @@ -3099,7 +3111,8 @@ #if defined(PCR) || defined(GC_WIN32_THREADS) || defined(GC_PTHREADS) \ || defined(NN_PLATFORM_CTR) || defined(NINTENDO_SWITCH) \ - || defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PS3) + || defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PS3) \ + || defined(SN_TARGET_PSP2) # define THREADS #endif @@ -3427,6 +3440,9 @@ # elif defined(SN_TARGET_PS3) void *ps3_get_mem(size_t bytes); # define GET_MEM(bytes) (struct hblk*)ps3_get_mem(bytes) +# elif defined(SN_TARGET_PSP2) + void *psp2_get_mem(size_t bytes); +# define GET_MEM(bytes) (struct hblk*)psp2_get_mem(bytes) # elif defined(NINTENDO_SWITCH) void *switch_get_mem(size_t bytes); # define GET_MEM(bytes) (struct hblk*)switch_get_mem(bytes) diff --git a/mach_dep.c b/mach_dep.c index 48f19eb0..2c62cc63 100644 --- a/mach_dep.c +++ b/mach_dep.c @@ -14,7 +14,7 @@ #include "private/gc_priv.h" -#if !defined(SN_TARGET_ORBIS) +#if !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) #include @@ -328,4 +328,4 @@ GC_INNER void GC_with_callee_saves_pushed(void (*fn)(ptr_t, void *), GC_noop1((word)(&dummy)); } -#endif /* !SN_TARGET_ORBIS */ +#endif /* !SN_TARGET_ORBIS && !SN_TARGET_PSP2 */ diff --git a/misc.c b/misc.c index 66f1d97a..11275acd 100644 --- a/misc.c +++ b/misc.c @@ -50,6 +50,8 @@ # ifdef PCR # include "il/PCR_IL.h" GC_INNER PCR_Th_ML GC_allocate_ml; +# elif defined(SN_TARGET_PSP2) + GC_INNER WapiMutex GC_allocate_ml_PSP2 = { 0, NULL }; # elif defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PS3) # include GC_INNER pthread_mutex_t GC_allocate_ml; @@ -1565,13 +1567,14 @@ GC_API void GC_CALL GC_enable_incremental(void) #else # if !defined(AMIGA) && !defined(MSWIN_XBOX1) && !defined(SN_TARGET_ORBIS) \ - && !defined(__CC_ARM) + && !defined(SN_TARGET_PSP2) && !defined(__CC_ARM) # include # endif STATIC int GC_write(int fd, const char *buf, size_t len) { -# if defined(ECOS) || defined(SN_TARGET_ORBIS) || defined(NOSYS) +# if defined(ECOS) || defined(SN_TARGET_ORBIS) || defined(SN_TARGET_PSP2) \ + || defined(NOSYS) # ifdef ECOS /* FIXME: This seems to be defined nowhere at present. */ /* _Jv_diag_write(buf, len); */ diff --git a/os_dep.c b/os_dep.c index dda1abe6..cd089c7a 100644 --- a/os_dep.c +++ b/os_dep.c @@ -17,7 +17,8 @@ #include "private/gc_priv.h" #if !defined(OS2) && !defined(PCR) && !defined(AMIGA) && !defined(MACOS) \ - && !defined(MSWINCE) && !defined(SN_TARGET_ORBIS) && !defined(__CC_ARM) + && !defined(MSWINCE) && !defined(SN_TARGET_ORBIS) \ + && !defined(SN_TARGET_PSP2) && !defined(__CC_ARM) # include # if !defined(MSWIN32) && !defined(MSWIN_XBOX1) # include @@ -2084,7 +2085,7 @@ void GC_register_data_segments(void) && !defined(USE_WINALLOC) && !defined(MACOS) && !defined(DOS4GW) \ && !defined(NINTENDO_SWITCH) && !defined(NONSTOP) \ && !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PS3) \ - && !defined(RTEMS) && !defined(__CC_ARM) + && !defined(SN_TARGET_PSP2) && !defined(RTEMS) && !defined(__CC_ARM) # define SBRK_ARG_T ptrdiff_t diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 5ee6ce8d..a6ca776d 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -18,7 +18,8 @@ #include "private/pthread_support.h" #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) && \ - !defined(GC_DARWIN_THREADS) && !defined(SN_TARGET_ORBIS) + !defined(GC_DARWIN_THREADS) && !defined(SN_TARGET_ORBIS) \ + && !defined(SN_TARGET_PSP2) #ifdef NACL diff --git a/pthread_support.c b/pthread_support.c index dec53b3d..59d6732d 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -35,7 +35,7 @@ # include # include # include -# if !defined(SN_TARGET_ORBIS) +# if !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) # if !defined(GC_RTEMS_PTHREADS) # include # endif @@ -1539,7 +1539,7 @@ GC_INNER_PTHRSTART void GC_thread_exit_proc(void *arg) UNLOCK(); } -#if !defined(SN_TARGET_ORBIS) +#if !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) GC_API int WRAP_FUNC(pthread_join)(pthread_t thread, void **retval) { int result; @@ -1598,7 +1598,7 @@ GC_INNER_PTHRSTART void GC_thread_exit_proc(void *arg) } return result; } -#endif /* !SN_TARGET_ORBIS */ +#endif /* !SN_TARGET_ORBIS && !SN_TARGET_PSP2 */ #ifndef GC_NO_PTHREAD_CANCEL /* We should deal with the fact that apparently on Solaris and, */ @@ -1813,7 +1813,7 @@ STATIC void * GC_start_routine(void * arg) # endif } -#if !defined(SN_TARGET_ORBIS) +#if !defined(SN_TARGET_ORBIS) && !defined(SN_TARGET_PSP2) GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread, GC_PTHREAD_CREATE_CONST pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) @@ -1919,7 +1919,7 @@ STATIC void * GC_start_routine(void * arg) return(result); } -#endif /* !SN_TARGET_ORBIS */ +#endif /* !SN_TARGET_ORBIS && !SN_TARGET_PSP2 */ #if defined(USE_SPIN_LOCK) || !defined(NO_PTHREAD_TRYLOCK) /* Spend a few cycles in a way that can't introduce contention with */ -- 2.40.0