Usermode - Adding hacky pthreads support
authorJohn Hodge <[email protected]>
Thu, 27 Nov 2014 03:43:45 +0000 (11:43 +0800)
committerJohn Hodge <[email protected]>
Thu, 27 Nov 2014 03:43:45 +0000 (11:43 +0800)
Externals/cross-compiler/Makefile
Externals/cross-compiler/patches/gcc/gcc/config.gcc.patch
Externals/cross-compiler/patches/gcc/gcc/config/acess2.h
Externals/cross-compiler/patches/gcc/gcc/config/acess2.opt [new file with mode: 0644]
Usermode/Libraries/libpthread.so_src/Makefile [new file with mode: 0644]
Usermode/Libraries/libpthread.so_src/include_exp/pthread.h [new file with mode: 0644]
Usermode/Libraries/libpthread.so_src/include_exp/sched.h [new file with mode: 0644]
Usermode/Libraries/libpthread.so_src/main.c [new file with mode: 0644]

index 3867d4c..dbb6ad3 100644 (file)
@@ -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
index 8f65ac6..9c7087a 100644 (file)
@@ -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*)
 
index 44a4e03..a22c535 100644 (file)
@@ -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 (file)
index 0000000..e9db7e5
--- /dev/null
@@ -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 (file)
index 0000000..fe3fc8c
--- /dev/null
@@ -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 (file)
index 0000000..8f4f779
--- /dev/null
@@ -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 (file)
index 0000000..8366ba2
--- /dev/null
@@ -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 (file)
index 0000000..e69de29

UCC git Repository :: git.ucc.asn.au