finish unifying thread register handling in preparation for porting
authorRich Felker <dalias@aerifal.cx>
Tue, 15 Feb 2011 08:56:52 +0000 (03:56 -0500)
committerRich Felker <dalias@aerifal.cx>
Tue, 15 Feb 2011 08:56:52 +0000 (03:56 -0500)
Makefile
arch/i386/pthread_arch.h [new file with mode: 0644]
src/internal/pthread_impl.h
src/thread/__set_thread_area.c
src/thread/clone.c
src/thread/i386/__set_thread_area.s [new file with mode: 0644]
src/thread/pthread_self.c

index d0f16dfcac2096c37a366336a45779cba6ddb5ad..13a24e3c1e506d9f107bfa45ed7a192f74a6a0bd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ GENH = include/bits/alltypes.h
 
 CFLAGS  = -Os -nostdinc -ffreestanding -std=c99 -D_XOPEN_SOURCE=700 -pipe
 LDFLAGS = -nostdlib -shared -Wl,-Bsymbolic
-INC     = -I./include -I./src/internal
+INC     = -I./include -I./src/internal -I./arch/$(ARCH)
 PIC     = -fPIC
 AR      = $(CROSS_COMPILE)ar
 RANLIB  = $(CROSS_COMPILE)ranlib
diff --git a/arch/i386/pthread_arch.h b/arch/i386/pthread_arch.h
new file mode 100644 (file)
index 0000000..155b484
--- /dev/null
@@ -0,0 +1,6 @@
+static inline struct pthread *__pthread_self()
+{
+       struct pthread *self;
+       __asm__ ("movl %%gs:0,%0" : "=r" (self) );
+       return self;
+}
index d751f197fde08a22e323bb5a52ddbee1ec6ed1fd..e481ab5aa928d74abbe6f84f4c74aeabecb47da6 100644 (file)
@@ -38,19 +38,13 @@ struct pthread {
        pthread_attr_t attr;
 };
 
-static inline struct pthread *__pthread_self()
-{
-       struct pthread *self;
-       __asm__ ("movl %%gs:0,%0" : "=r" (self) );
-       return self;
-}
+#include "pthread_arch.h"
 
 #define SIGCANCEL 32
 #define SIGSYSCALL 33
 #define SIGTIMER  32 /* ?? */
 
-int __set_thread_area(unsigned long *);
-int __set_pthread_self(void *);
+int __set_thread_area(void *);
 int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
 int __libc_sigprocmask(int, const sigset_t *, sigset_t *);
 void __lock(volatile int *);
index 576d8b40049399b48a7f4b264c8e47edb25af1f0..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,9 +0,0 @@
-#include "syscall.h"
-
-int __set_thread_area(unsigned long *desc)
-{
-       if (syscall1(__NR_set_thread_area, (long)desc) < 0)
-               return -1;
-       __asm__ __volatile__ ( "movw %w0,%%gs" : : "r"(desc[0]*8+3) );
-       return 0;
-}
index 971bfeed3b29d62a28bf05607dbfe03bb71a3a38..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,26 +0,0 @@
-#if 0
-
-int clone(int (*start)(void *), void *stack, int flags, void *arg,
-       pid_t *ptid, struct user_desc *tls, pid_t *ctid)
-{
-       int ret;
-       __asm__(
-               "andl $-16,%%ecx     \n\t"
-               "xchgl %%ebx,%2      \n\t"
-               "movl %%ebx,(%%ecx)  \n\t"
-               "int $0x80           \n\t"
-               "testl %%eax,%%eax   \n\t"
-               "jnz 1f              \n\t"
-               "xorl %%ebp,%%ebp    \n\t"
-               "call *%%ebx         \n\t"
-               "\n1:                \n\t"
-               "xchgl %%ebx,%2      \n\t"
-               : "=a" (ret)
-               : "a" (__NR_clone), "m" (flags), "c"(stack), "d"(ptid),
-                 "S" (tls), "D" (ctid)
-               : "memory"
-       );
-       return __syscall_ret(ret);
-}
-
-#endif
diff --git a/src/thread/i386/__set_thread_area.s b/src/thread/i386/__set_thread_area.s
new file mode 100644 (file)
index 0000000..9bf698b
--- /dev/null
@@ -0,0 +1,22 @@
+.text
+.global __set_thread_area
+.type   __set_thread_area,%function
+__set_thread_area:
+       pushl %ebx
+       movl 8(%esp),%ecx
+       movl $-1,4(%ecx)
+       movl %ecx,8(%ecx)
+       movl $0xfffff,12(%ecx)
+       movl $0x51,16(%ecx)
+       leal 4(%ecx),%ebx
+       movl $243,%eax
+       int $128
+       popl %ebx
+       testl %eax,%eax
+       jnz 1f
+       movl 4(%ecx),%ecx
+       leal 3(,%ecx,8),%ecx
+       movw %cx,%gs
+1:
+       ret
+.size __set_thread_area,.-__set_thread_area
index 686d73d598faa52b4c63507dd16221c79f6ba574..3a4d4c581267e9f669ede16476cb69244ca21cae 100644 (file)
@@ -5,27 +5,21 @@ static struct pthread main_thread;
 #undef errno
 static int *errno_location()
 {
-       return pthread_self()->errno_ptr;
+       return __pthread_self()->errno_ptr;
 }
 
 static int init_main_thread()
 {
-       main_thread.tlsdesc[0] = -1;
-       main_thread.tlsdesc[1] = (long)&main_thread;
-       main_thread.tlsdesc[2] = SIZE_MAX/PAGE_SIZE;
-       main_thread.tlsdesc[3] = 0x51;
        main_thread.self = &main_thread;
-       main_thread.errno_ptr = __errno_location();
-       if (__set_thread_area(main_thread.tlsdesc) < 0)
+       if (__set_thread_area(&main_thread) < 0)
                return -1;
        syscall1(__NR_set_tid_address, (long)&main_thread.tid);
+       main_thread.errno_ptr = __errno_location();
        libc.errno_location = errno_location;
        main_thread.tid = main_thread.pid = getpid();
        return 0;
 }
 
-#undef pthread_self
-
 pthread_t pthread_self()
 {
        static int init, failed;