]> Cypherpunks repositories - gostls13.git/commitdiff
More FreeBSD-touchups. Thundercats are GOOOOO!
authorDevon H. O'Dell <devon.odell@gmail.com>
Thu, 19 Nov 2009 00:51:59 +0000 (16:51 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 19 Nov 2009 00:51:59 +0000 (16:51 -0800)
R=rsc
CC=golang-dev
https://golang.org/cl/157074

misc/cgo/stdio/test.bash
src/cmd/6l/obj.c
src/cmd/8l/obj.c
src/libcgo/freebsd_386.c
src/libcgo/freebsd_amd64.c
src/pkg/runtime/freebsd/386/sys.s
src/pkg/runtime/proc.c

index 8918aab92c8d18a715c8ad3c6488a2a6c684babd..82e3f7b45bf6ece426723d9904ce7fcd7d52441b 100755 (executable)
@@ -3,8 +3,6 @@
 # Use of this source code is governed by a BSD-style
 # license that can be found in the LICENSE file.
 
-if [ "$(uname)" = "FreeBSD" ]; then exit 0; fi
-
 set -e
 gomake hello fib chain
 echo '*' hello >run.out
index 63e2f95269811d1b1d3503a7f2f71a3da7b13cac..9ecdf6ee81a384315d83eb7f9d7c8429a75574a7 100644 (file)
@@ -150,10 +150,9 @@ main(int argc, char *argv[])
                if(strcmp(goos, "darwin") == 0)
                        HEADTYPE = 6;
                else
-               if(strcmp(goos, "freebsd") == 0) {
-                       debug['d'] = 1; /* no dynamic syms for now */
+               if(strcmp(goos, "freebsd") == 0)
                        HEADTYPE = 9;
-               else
+               else
                        print("goos is not known: %s\n", goos);
        }
 
index 1bfeff5bc2a9ad540d67e412b766a291923c7b2f..dc66e6ee3f05056ba0a0f81510f61c635ef0607e 100644 (file)
@@ -158,10 +158,9 @@ main(int argc, char *argv[])
                if(strcmp(goos, "nacl") == 0)
                        HEADTYPE = 8;
                else
-               if(strcmp(goos, "freebsd") == 0) {
-                       debug['d'] = 1; /* no dynamic syms for now */
+               if(strcmp(goos, "freebsd") == 0)
                        HEADTYPE = 9;
-               else
+               else
                        print("goos is not known: %sn", goos);
        }
 
@@ -241,10 +240,7 @@ main(int argc, char *argv[])
                 * Also known to ../../pkg/runtime/linux/386/sys.s
                 * and ../../libcgo/linux_386.c.
                 */
-               if (HEADTYPE == 7)
-                       tlsoffset = -8;
-               else
-                       tlsoffset = 0;
+               tlsoffset = -8;
                elfinit();
                HEADR = ELFRESERVE;
                if(INITTEXT == -1)
index 1f596f861b258adcab8821cd212d8f997c747317..b445b940ad6d33da2c91622892af21d4a32d5a04 100644 (file)
@@ -6,15 +6,13 @@
 #include "libcgo.h"
 
 static void* threadentry(void*);
-static pthread_key_t k1, k2;
 
-/* gccism: arrange for inittls to be called at dynamic load time */
-static void inittls(void) __attribute__((constructor));
+char *environ[] = { 0 };
+char *__progname;
 
 static void
 inittls(void)
 {
-       /* unimplemented for now */
 }
 
 void
@@ -51,8 +49,16 @@ threadentry(void *v)
         */
        ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
 
-       pthread_setspecific(k1, (void*)ts.g);
-       pthread_setspecific(k2, (void*)ts.m);
+       /*
+        * Set specific keys.  On FreeBSD/ELF, the thread local storage
+        * is just before %gs:0.  Our dynamic 8.out's reserve 8 bytes
+        * for the two words g and m at %gs:-8 and %gs:-4.
+        */
+       asm volatile (
+               "movl %0, %%gs:-8\n"    // MOVL g, -8(GS)
+               "movl %1, %%gs:-4\n"    // MOVL m, -4(GS)
+               :: "r"(ts.g), "r"(ts.m)
+       );
 
        crosscall_386(ts.fn);
        return nil;
index 14a409f5ebbaa7900d9e07f9cc79393e75b95ad4..4eb0e1ee59f303d62bd5af82e55c3a59fdbdbc46 100644 (file)
@@ -7,6 +7,9 @@
 
 static void* threadentry(void*);
 
+char *environ[] = { 0 };
+char *__progname;
+
 void
 initcgo(void)
 {
index 1048fea14e0c7c7bb55e541b3ed1a763e9decb08..1c0eaead5b08e9763bdaadcbe5d3d77ab5108d43 100644 (file)
@@ -19,8 +19,8 @@ TEXT thr_new(SB),7,$-4
        RET
 
 TEXT thr_start(SB),7,$0
-       MOVL mm+0(FP), AX
-       MOVL m_g0(AX), BX
+       MOVL    mm+0(FP), AX
+       MOVL    m_g0(AX), BX
        LEAL    m_tls(AX), BP
        MOVL    0(BP), DI
        ADDL    $7, DI
@@ -132,7 +132,8 @@ int i386_set_ldt(int, const union ldt_entry *, int);
 // setldt(int entry, int address, int limit)
 TEXT setldt(SB),7,$32
        MOVL    address+4(FP), BX       // aka base
-       MOVL    limit+8(FP), CX
+       // see comment in linux/386/sys.s; freebsd is similar
+       ADDL    $0x8, BX
 
        // set up data_desc
        LEAL    16(SP), AX      // struct data_desc
@@ -145,11 +146,8 @@ TEXT setldt(SB),7,$32
        SHRL    $8, BX
        MOVB    BX, 7(AX)
 
-       MOVW    CX, 0(AX)
-       SHRL    $16, CX
-       ANDL    $0x0F, CX
-       ORL     $0x40, CX               // 32-bit operand size
-       MOVB    CX, 6(AX)
+       MOVW    $0xffff, 0(AX)
+       MOVB    $0xCF, 6(AX)    // 32-bit operand, 4k limit unit, 4 more bits of limit
 
        MOVB    $0xF2, 5(AX)    // r/w data descriptor, dpl=3, present
 
index e6e811c5c38910a59e792da17618893666e55cb9..2f36868f5f88de49c7134fbf97802b902f71a48c 100644 (file)
@@ -385,6 +385,8 @@ starttheworld(void)
 void
 mstart(void)
 {
+       if(g != m->g0)
+               throw("bad mstart");
        if(m->mcache == nil)
                m->mcache = allocmcache();
        minit();