Commit 7e776231 authored by Yuval Pavel Zholkover's avatar Yuval Pavel Zholkover Committed by Russ Cox

8l, runtime: place G and M pointers relative to _tos on Plan 9, instead of…

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
parent bbfad5f1
...@@ -188,6 +188,7 @@ main(int argc, char *argv[]) ...@@ -188,6 +188,7 @@ main(int argc, char *argv[])
INITRND = 0; INITRND = 0;
break; break;
case 2: /* plan 9 */ case 2: /* plan 9 */
tlsoffset = -8;
HEADR = 32L; HEADR = 32L;
if(INITTEXT == -1) if(INITTEXT == -1)
INITTEXT = 4096+32; INITTEXT = 4096+32;
......
...@@ -250,6 +250,7 @@ patch(void) ...@@ -250,6 +250,7 @@ patch(void)
Prog *p, *q; Prog *p, *q;
Sym *s; Sym *s;
int32 vexit; int32 vexit;
Sym *plan9_tos;
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f mkfwd\n", cputime()); Bprint(&bso, "%5.2f mkfwd\n", cputime());
...@@ -260,6 +261,10 @@ patch(void) ...@@ -260,6 +261,10 @@ patch(void)
Bflush(&bso); Bflush(&bso);
s = lookup("exit", 0); s = lookup("exit", 0);
vexit = s->value; vexit = s->value;
if(HEADTYPE == 2)
plan9_tos = lookup("_tos", 0);
for(cursym = textp; cursym != nil; cursym = cursym->next) { for(cursym = textp; cursym != nil; cursym = cursym->next) {
for(p = cursym->text; p != P; p = p->link) { for(p = cursym->text; p != P; p = p->link) {
if(HEADTYPE == 10) { // Windows if(HEADTYPE == 10) { // Windows
...@@ -303,9 +308,15 @@ patch(void) ...@@ -303,9 +308,15 @@ patch(void)
if(HEADTYPE == 2) { // Plan 9 if(HEADTYPE == 2) { // Plan 9
if(p->from.type == D_INDIR+D_GS if(p->from.type == D_INDIR+D_GS
&& p->to.type >= D_AX && p->to.type <= D_DI) { && 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->as = AMOVL;
p->from.type = D_ADDR+D_STATIC; p->from.type = D_EXTERN;
p->from.offset += 0xdfffefc0; p->from.sym = plan9_tos;
p->from.offset = 0;
} }
} }
if(p->as == ACALL || (p->as == AJMP && p->to.type != D_BRANCH)) { if(p->as == ACALL || (p->as == AJMP && p->to.type != D_BRANCH)) {
...@@ -389,6 +400,7 @@ dostkoff(void) ...@@ -389,6 +400,7 @@ dostkoff(void)
int a; int a;
Prog *pmorestack; Prog *pmorestack;
Sym *symmorestack; Sym *symmorestack;
Sym *plan9_tos;
pmorestack = P; pmorestack = P;
symmorestack = lookup("runtime.morestack", 0); symmorestack = lookup("runtime.morestack", 0);
...@@ -399,6 +411,9 @@ dostkoff(void) ...@@ -399,6 +411,9 @@ dostkoff(void)
pmorestack = symmorestack->text; pmorestack = symmorestack->text;
symmorestack->text->from.scale |= NOSPLIT; symmorestack->text->from.scale |= NOSPLIT;
} }
if(HEADTYPE == 2)
plan9_tos = lookup("_tos", 0);
for(cursym = textp; cursym != nil; cursym = cursym->next) { for(cursym = textp; cursym != nil; cursym = cursym->next) {
if(cursym->text == nil || cursym->text->link == nil) if(cursym->text == nil || cursym->text->link == nil)
...@@ -443,9 +458,15 @@ dostkoff(void) ...@@ -443,9 +458,15 @@ dostkoff(void)
case 2: // Plan 9 case 2: // Plan 9
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_ADDR+D_STATIC; p->from.type = D_EXTERN;
p->from.offset = 0xdfffefc0; p->from.sym = plan9_tos;
p->to.type = D_CX; 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; break;
default: default:
......
...@@ -25,9 +25,9 @@ case "$GOARCH" in ...@@ -25,9 +25,9 @@ case "$GOARCH" in
echo '#define m(r) 4(r)' echo '#define m(r) 4(r)'
;; ;;
plan9) plan9)
echo '#define get_tls(r)' echo '#define get_tls(r) MOVL _tos(SB), r '
echo '#define g(r) 0xdfffefc0' echo '#define g(r) -8(r)'
echo '#define m(r) 0xdfffefc4' echo '#define m(r) -4(r)'
;; ;;
linux) linux)
# On Linux systems, what we call 0(GS) and 4(GS) for g and m # On Linux systems, what we call 0(GS) and 4(GS) for g and m
......
// nothing to see here // nothing to see here
#define tos_pid 48
...@@ -58,9 +58,10 @@ TEXT runtime·rfork(SB),7,$0 ...@@ -58,9 +58,10 @@ TEXT runtime·rfork(SB),7,$0
MOVL BX, m(AX) MOVL BX, m(AX)
// Initialize AX from _tos->pid // 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 MOVL AX, m_procid(BX) // save pid as m->procid
CALL runtime·stackcheck(SB) // smashes AX, CX CALL runtime·stackcheck(SB) // smashes AX, CX
MOVL 0(DX), DX // paranoia; check they are not nil MOVL 0(DX), DX // paranoia; check they are not nil
......
...@@ -10,40 +10,47 @@ static byte *bloc = { end }; ...@@ -10,40 +10,47 @@ static byte *bloc = { end };
enum enum
{ {
Round = 7 Round = 4095
}; };
void* void*
runtime·SysAlloc(uintptr ask) runtime·SysAlloc(uintptr nbytes)
{ {
uintptr bl; uintptr bl;
// Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c // Plan 9 sbrk from /sys/src/libc/9sys/sbrk.c
bl = ((uintptr)bloc + Round) & ~Round; bl = ((uintptr)bloc + Round) & ~Round;
if(runtime·brk_((void*)(bl + ask)) < 0) if(runtime·brk_((void*)(bl + nbytes)) < 0)
return (void*)-1; return (void*)-1;
bloc = (byte*)bl + ask; bloc = (byte*)bl + nbytes;
return (void*)bl; return (void*)bl;
} }
void void
runtime·SysFree(void *v, uintptr n) runtime·SysFree(void *v, uintptr nbytes)
{ {
// from tiny/mem.c // from tiny/mem.c
// Push pointer back if this is a free // Push pointer back if this is a free
// of the most recent SysAlloc. // of the most recent SysAlloc.
n += (n + Round) & ~Round; nbytes += (nbytes + Round) & ~Round;
if(bloc == (byte*)v+n) if(bloc == (byte*)v+nbytes)
bloc -= n; bloc -= nbytes;
} }
void void
runtime·SysUnused(void *v, uintptr n) runtime·SysUnused(void *v, uintptr nbytes)
{ {
USED(v, n); USED(v, nbytes);
} }
void void
runtime·SysMemInit(void) runtime·SysMap(void *v, uintptr nbytes)
{ {
USED(v, nbytes);
}
void*
runtime·SysReserve(void *v, uintptr nbytes)
{
return runtime·SysAlloc(nbytes);
} }
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