From eeb449278c0ad4d378232c322dc3becfbb4cef1b Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 27 Nov 2014 11:43:45 +0800 Subject: [PATCH] Usermode - Adding hacky pthreads support --- Externals/cross-compiler/Makefile | 4 +- .../patches/gcc/gcc/config.gcc.patch | 4 +- .../patches/gcc/gcc/config/acess2.h | 3 +- .../patches/gcc/gcc/config/acess2.opt | 6 ++ Usermode/Libraries/libpthread.so_src/Makefile | 12 +++ .../libpthread.so_src/include_exp/pthread.h | 95 +++++++++++++++++++ .../libpthread.so_src/include_exp/sched.h | 15 +++ Usermode/Libraries/libpthread.so_src/main.c | 0 8 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 Externals/cross-compiler/patches/gcc/gcc/config/acess2.opt create mode 100644 Usermode/Libraries/libpthread.so_src/Makefile create mode 100644 Usermode/Libraries/libpthread.so_src/include_exp/pthread.h create mode 100644 Usermode/Libraries/libpthread.so_src/include_exp/sched.h create mode 100644 Usermode/Libraries/libpthread.so_src/main.c diff --git a/Externals/cross-compiler/Makefile b/Externals/cross-compiler/Makefile index 3867d4c9..dbb6ad3f 100644 --- a/Externals/cross-compiler/Makefile +++ b/Externals/cross-compiler/Makefile @@ -17,7 +17,7 @@ ifeq ($(BINUTILS_ARCHIVE),) endif BINUTILS_CHANGES := config.sub bfd/config.bfd gas/configure.tgt ld/configure.tgt ld/emulparams/acess2_i386.sh ld/emulparams/acess2_amd64.sh ld/Makefile.in -GCC_CHANGES := config.sub gcc/config.gcc gcc/config/acess2.h libgcc/config.host +GCC_CHANGES := config.sub gcc/config.gcc gcc/config/acess2.h libgcc/config.host gcc/config/acess2.opt # libstdc++-v3/crossconfig.m4 config/override.m4 TARGET=$(HOST) @@ -78,7 +78,7 @@ $(PREFIX)/bin/$(TARGET)-ld: $(BDIR_BINUTILS)/Makefile $(BDIR_GCC)/Makefile: Makefile $(addprefix $(GCC_DIR)/,$(GCC_CHANGES)) $(GCC_DIR)/libstdc++-v3/configure @mkdir -p $(BDIR_GCC) - @cd $(BDIR_GCC) && PATH=$(PREFIX)/bin:$$PATH ../../$(GCC_DIR)/configure --target=$(TARGET) --prefix=$(PREFIX) --disable-nls --enable-langs=c,c++ --includedir=$(ACESSDIR)/Usermode/include "--with-sysroot=$(SYSROOT)" --without-docdir + @cd $(BDIR_GCC) && PATH=$(PREFIX)/bin:$$PATH ../../$(GCC_DIR)/configure --target=$(TARGET) --prefix=$(PREFIX) --disable-nls --enable-langs=c,c++ --includedir=$(ACESSDIR)/Usermode/include "--with-sysroot=$(SYSROOT)" --without-docdir --enable-threads=posix @echo "MAKEINFO = :" >> $(BDIR_GCC)/Makefile $(PREFIX)/bin/$(TARGET)-gcc: $(BDIR_GCC)/Makefile diff --git a/Externals/cross-compiler/patches/gcc/gcc/config.gcc.patch b/Externals/cross-compiler/patches/gcc/gcc/config.gcc.patch index 8f65ac69..9c7087ab 100644 --- a/Externals/cross-compiler/patches/gcc/gcc/config.gcc.patch +++ b/Externals/cross-compiler/patches/gcc/gcc/config.gcc.patch @@ -1,14 +1,16 @@ --- gcc/config.gcc +++ gcc/config.gcc -@@ -519,3 +519,10 @@ +@@ -519,3 +519,12 @@ # Common parts for widely ported systems. case ${target} in +*-*-acess2*) ++ extra_options="${extra_options} acess2.opt" + extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o crtendT.o" + gas=yes + gnu_ld=yes + default_use_cxa_atexit=yes + use_gcc_stdint=provide ++ thread_file=posix + ;; *-*-darwin*) diff --git a/Externals/cross-compiler/patches/gcc/gcc/config/acess2.h b/Externals/cross-compiler/patches/gcc/gcc/config/acess2.h index 44a4e037..a22c5356 100644 --- a/Externals/cross-compiler/patches/gcc/gcc/config/acess2.h +++ b/Externals/cross-compiler/patches/gcc/gcc/config/acess2.h @@ -5,9 +5,10 @@ builtin_define_std ("unix"); \ builtin_assert ("system=acess2"); \ builtin_assert ("system=unix"); \ + builtin_assert ("system=posix"); \ } while(0); -#define LIB_SPEC "-lc -lld-acess -lposix" +#define LIB_SPEC "-lc -lld-acess -lposix %{pthread:-lpthread}" #define LIBSTDCXX "c++" #undef STARTFILE_SPEC #undef ENDFILE_SPEC diff --git a/Externals/cross-compiler/patches/gcc/gcc/config/acess2.opt b/Externals/cross-compiler/patches/gcc/gcc/config/acess2.opt new file mode 100644 index 00000000..e9db7e5c --- /dev/null +++ b/Externals/cross-compiler/patches/gcc/gcc/config/acess2.opt @@ -0,0 +1,6 @@ +; Options for acess2 + +pthread +Driver + +; diff --git a/Usermode/Libraries/libpthread.so_src/Makefile b/Usermode/Libraries/libpthread.so_src/Makefile new file mode 100644 index 00000000..fe3fc8c2 --- /dev/null +++ b/Usermode/Libraries/libpthread.so_src/Makefile @@ -0,0 +1,12 @@ +# Acess 2 - POSIX Threads + +include ../Makefile.cfg + +CPPFLAGS += +CFLAGS += -Wall +LDFLAGS += -lc -soname libpthread.so + +OBJ = main.o +BIN = libpthread.so + +include ../Makefile.tpl diff --git a/Usermode/Libraries/libpthread.so_src/include_exp/pthread.h b/Usermode/Libraries/libpthread.so_src/include_exp/pthread.h new file mode 100644 index 00000000..8f4f779e --- /dev/null +++ b/Usermode/Libraries/libpthread.so_src/include_exp/pthread.h @@ -0,0 +1,95 @@ +/* + * Acess2 libpthread + * - By John Hodge (thePowersGang) + * + * pthread.h + * - Core POSIX threads header + */ +#ifndef _LIBPTHREAT_PTHREAD_H_ +#define _LIBPTHREAT_PTHREAD_H_ + +// XXX: Hack - libgcc doesn't seem to be auto-detecting the presence of this header +#include "sched.h" + +//! \name pthread core +//! \{ +typedef struct pthread_attr_s pthread_attr_t; + +struct pthread_s +{ + void* retval; + unsigned int kernel_handle; +}; +typedef struct pthread_s pthread_t; + +extern int pthread_create(pthread_t *threadptr, const pthread_attr_t * attrs, void* (*fcn)(void*), void* arg); +extern int pthread_detach(pthread_t thread); +extern int pthread_join(pthread_t thread, void **retvalptr); +extern int pthread_cancel(pthread_t thread); +extern int pthread_equal(pthread_t t1, pthread_t t2); +extern pthread_t pthread_self(void); +extern void pthread_exit(void* retval); +//! } + + +//! \name pthread_once +//! \{ +struct pthread_once_s +{ + int flag; +}; +#define PTHREAD_ONCE_INIT ((struct pthread_once_s){.flag=0}) +typedef struct pthread_once_s pthread_once_t; +extern int pthread_once(pthread_once_t *once_contol, void (*init_routine)(void)); +//! \} + +//! \name pthread mutexes +//! \{ +#define PTHREAD_MUTEX_NORMAL 0 +#define PTHREAD_MUTEX_RECURSIVE 1 +struct pthread_mutexattr_s +{ + int type; +}; +typedef struct pthread_mutexattr_s pthread_mutexattr_t; +extern int pthread_mutexattr_init(pthread_mutexattr_t *attrs); +extern int pthread_mutexattr_settype(pthread_mutexattr_t *attrs, int type); +extern int pthread_mutexattr_destroy(pthread_mutexattr_t *attrs); + +struct pthread_mutex_s +{ + void* futex; +}; +#define PTHREAD_MUTEX_INITIALIZER ((struct pthread_mutex_s){NULL}) +typedef struct pthread_mutex_s pthread_mutex_t; +extern int pthread_mutex_init(pthread_mutex_t * mutex, const pthread_mutexattr_t *attrs); +extern int pthread_mutex_lock(pthread_mutex_t *lock); +extern int pthread_mutex_trylock(pthread_mutex_t *lock); +extern int pthread_mutex_unlock(pthread_mutex_t *lock); +extern int pthread_mutex_destroy(pthread_mutex_t *lock); +//! \} + +//! \name pthread TLS keys +//! \{ +//typedef struct pthread_key_s pthread_key_t; +typedef unsigned int pthread_key_t; +extern int pthread_key_create(pthread_key_t *keyptr, void (*fcn)(void*)); +extern int pthread_key_delete(pthread_key_t key); +extern int pthread_setspecific(pthread_key_t key, const void* data); +extern void* pthread_getspecific(pthread_key_t key); +//! \} + +//! \name pthread condvars +//! \{ +typedef struct pthread_cond_s pthread_cond_t; +typedef struct pthread_condattr_s pthread_condattr_t; +extern int pthread_cond_init(pthread_cond_t *condptr, const pthread_condattr_t* attrs); +extern int pthread_cond_wait(pthread_cond_t *condptr, pthread_mutex_t *mutex); +extern int pthread_cond_timedwait(pthread_cond_t *condptr, pthread_mutex_t *mutex, const struct timespec *timeout); +extern int pthread_cond_signal(pthread_cond_t *condptr); +extern int pthread_cond_broadcast(pthread_cond_t *condptr); +extern int pthread_cond_destroy(pthread_cond_t *condptr); +//! \} + +#endif + diff --git a/Usermode/Libraries/libpthread.so_src/include_exp/sched.h b/Usermode/Libraries/libpthread.so_src/include_exp/sched.h new file mode 100644 index 00000000..8366ba22 --- /dev/null +++ b/Usermode/Libraries/libpthread.so_src/include_exp/sched.h @@ -0,0 +1,15 @@ +/* + * Acess2 libpthread + * - By John Hodge (thePowersGang) + * + * sched.h + * - Execution Scheduling (POSIX Realtime Extensions) + */ +#ifndef _LIBPTHREAT_SCHED_H_ +#define _LIBPTHREAT_SCHED_H_ + +// *grumble* libgcc wants a yield +extern int sched_yield(void); + +#endif + diff --git a/Usermode/Libraries/libpthread.so_src/main.c b/Usermode/Libraries/libpthread.so_src/main.c new file mode 100644 index 00000000..e69de29b -- 2.20.1