Commit 60b1a17b authored by Devon H. O'Dell's avatar Devon H. O'Dell Committed by Russ Cox

More FreeBSD-touchups. Thundercats are GOOOOO!

R=rsc
CC=golang-dev
https://golang.org/cl/157074
parent eac41e7e
......@@ -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
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -7,6 +7,9 @@
static void* threadentry(void*);
char *environ[] = { 0 };
char *__progname;
void
initcgo(void)
{
......
......@@ -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
......
......@@ -385,6 +385,8 @@ starttheworld(void)
void
mstart(void)
{
if(g != m->g0)
throw("bad mstart");
if(m->mcache == nil)
m->mcache = allocmcache();
minit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment