mirror of
https://github.com/golang/go
synced 2024-11-21 14:54:40 -07:00
8l, runtime: place G and M pointers relative to _tos on Plan 9, instead of hardcoded values for USTKTOP.
This should allow executing both on native Plan 9 and inside 9vx. R=rsc CC=golang-dev https://golang.org/cl/3993044
This commit is contained in:
parent
bbfad5f1cc
commit
7e77623120
@ -188,6 +188,7 @@ main(int argc, char *argv[])
|
||||
INITRND = 0;
|
||||
break;
|
||||
case 2: /* plan 9 */
|
||||
tlsoffset = -8;
|
||||
HEADR = 32L;
|
||||
if(INITTEXT == -1)
|
||||
INITTEXT = 4096+32;
|
||||
|
@ -250,6 +250,7 @@ patch(void)
|
||||
Prog *p, *q;
|
||||
Sym *s;
|
||||
int32 vexit;
|
||||
Sym *plan9_tos;
|
||||
|
||||
if(debug['v'])
|
||||
Bprint(&bso, "%5.2f mkfwd\n", cputime());
|
||||
@ -260,6 +261,10 @@ patch(void)
|
||||
Bflush(&bso);
|
||||
s = lookup("exit", 0);
|
||||
vexit = s->value;
|
||||
|
||||
if(HEADTYPE == 2)
|
||||
plan9_tos = lookup("_tos", 0);
|
||||
|
||||
for(cursym = textp; cursym != nil; cursym = cursym->next) {
|
||||
for(p = cursym->text; p != P; p = p->link) {
|
||||
if(HEADTYPE == 10) { // Windows
|
||||
@ -303,9 +308,15 @@ patch(void)
|
||||
if(HEADTYPE == 2) { // Plan 9
|
||||
if(p->from.type == D_INDIR+D_GS
|
||||
&& p->to.type >= D_AX && p->to.type <= D_DI) {
|
||||
q = appendp(p);
|
||||
q->from = p->from;
|
||||
q->from.type = D_INDIR + p->to.type;
|
||||
q->to = p->to;
|
||||
q->as = p->as;
|
||||
p->as = AMOVL;
|
||||
p->from.type = D_ADDR+D_STATIC;
|
||||
p->from.offset += 0xdfffefc0;
|
||||
p->from.type = D_EXTERN;
|
||||
p->from.sym = plan9_tos;
|
||||
p->from.offset = 0;
|
||||
}
|
||||
}
|
||||
if(p->as == ACALL || (p->as == AJMP && p->to.type != D_BRANCH)) {
|
||||
@ -389,6 +400,7 @@ dostkoff(void)
|
||||
int a;
|
||||
Prog *pmorestack;
|
||||
Sym *symmorestack;
|
||||
Sym *plan9_tos;
|
||||
|
||||
pmorestack = P;
|
||||
symmorestack = lookup("runtime.morestack", 0);
|
||||
@ -399,6 +411,9 @@ dostkoff(void)
|
||||
pmorestack = symmorestack->text;
|
||||
symmorestack->text->from.scale |= NOSPLIT;
|
||||
}
|
||||
|
||||
if(HEADTYPE == 2)
|
||||
plan9_tos = lookup("_tos", 0);
|
||||
|
||||
for(cursym = textp; cursym != nil; cursym = cursym->next) {
|
||||
if(cursym->text == nil || cursym->text->link == nil)
|
||||
@ -443,9 +458,15 @@ dostkoff(void)
|
||||
|
||||
case 2: // Plan 9
|
||||
p->as = AMOVL;
|
||||
p->from.type = D_ADDR+D_STATIC;
|
||||
p->from.offset = 0xdfffefc0;
|
||||
p->from.type = D_EXTERN;
|
||||
p->from.sym = plan9_tos;
|
||||
p->to.type = D_CX;
|
||||
|
||||
p = appendp(p);
|
||||
p->as = AMOVL;
|
||||
p->from.type = D_INDIR+D_CX;
|
||||
p->from.offset = tlsoffset + 0;
|
||||
p->to.type = D_CX;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -25,9 +25,9 @@ case "$GOARCH" in
|
||||
echo '#define m(r) 4(r)'
|
||||
;;
|
||||
plan9)
|
||||
echo '#define get_tls(r)'
|
||||
echo '#define g(r) 0xdfffefc0'
|
||||
echo '#define m(r) 0xdfffefc4'
|
||||
echo '#define get_tls(r) MOVL _tos(SB), r '
|
||||
echo '#define g(r) -8(r)'
|
||||
echo '#define m(r) -4(r)'
|
||||
;;
|
||||
linux)
|
||||
# On Linux systems, what we call 0(GS) and 4(GS) for g and m
|
||||
|
@ -1 +1,2 @@
|
||||
// nothing to see here
|
||||
#define tos_pid 48
|
||||
|
@ -58,9 +58,10 @@ TEXT runtime·rfork(SB),7,$0
|
||||
MOVL BX, m(AX)
|
||||
|
||||
// Initialize AX from _tos->pid
|
||||
MOVL 0xdfffeff8, AX
|
||||
MOVL _tos(SB), AX
|
||||
MOVL tos_pid(AX), AX
|
||||
MOVL AX, m_procid(BX) // save pid as m->procid
|
||||
|
||||
|
||||
CALL runtime·stackcheck(SB) // smashes AX, CX
|
||||
|
||||
MOVL 0(DX), DX // paranoia; check they are not nil
|
||||
|
@ -10,40 +10,47 @@ static byte *bloc = { end };
|
||||
|
||||
enum
|
||||
{
|
||||
Round = 7
|
||||
Round = 4095
|
||||
};
|
||||
|
||||
void*
|
||||
runtime·SysAlloc(uintptr ask)
|
||||
runtime·SysAlloc(uintptr nbytes)
|
||||
{
|
||||
uintptr bl;
|
||||
|
||||
// Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
|
||||
bl = ((uintptr)bloc + Round) & ~Round;
|
||||
if(runtime·brk_((void*)(bl + ask)) < 0)
|
||||
if(runtime·brk_((void*)(bl + nbytes)) < 0)
|
||||
return (void*)-1;
|
||||
bloc = (byte*)bl + ask;
|
||||
bloc = (byte*)bl + nbytes;
|
||||
return (void*)bl;
|
||||
}
|
||||
|
||||
void
|
||||
runtime·SysFree(void *v, uintptr n)
|
||||
runtime·SysFree(void *v, uintptr nbytes)
|
||||
{
|
||||
// from tiny/mem.c
|
||||
// Push pointer back if this is a free
|
||||
// of the most recent SysAlloc.
|
||||
n += (n + Round) & ~Round;
|
||||
if(bloc == (byte*)v+n)
|
||||
bloc -= n;
|
||||
nbytes += (nbytes + Round) & ~Round;
|
||||
if(bloc == (byte*)v+nbytes)
|
||||
bloc -= nbytes;
|
||||
}
|
||||
|
||||
void
|
||||
runtime·SysUnused(void *v, uintptr n)
|
||||
runtime·SysUnused(void *v, uintptr nbytes)
|
||||
{
|
||||
USED(v, n);
|
||||
USED(v, nbytes);
|
||||
}
|
||||
|
||||
void
|
||||
runtime·SysMemInit(void)
|
||||
runtime·SysMap(void *v, uintptr nbytes)
|
||||
{
|
||||
USED(v, nbytes);
|
||||
}
|
||||
|
||||
void*
|
||||
runtime·SysReserve(void *v, uintptr nbytes)
|
||||
{
|
||||
return runtime·SysAlloc(nbytes);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user