Commit 3f982aea authored by Ken Thompson's avatar Ken Thompson

morestack magic number

automatically generated in 6g and 6c,
manually set in 6a. format is
	TEXT	a(SB),, $a-b
where a is auto size and b is parameter size

SVN=126946
parent 439b0c40
...@@ -46,15 +46,16 @@ ...@@ -46,15 +46,16 @@
%left '+' '-' %left '+' '-'
%left '*' '/' '%' %left '*' '/' '%'
%token <lval> LTYPE0 LTYPE1 LTYPE2 LTYPE3 LTYPE4 %token <lval> LTYPE0 LTYPE1 LTYPE2 LTYPE3 LTYPE4
%token <lval> LTYPEC LTYPED LTYPEN LTYPER LTYPET LTYPES LTYPEM LTYPEI LTYPEXC LTYPEX LTYPERT %token <lval> LTYPEC LTYPED LTYPEN LTYPER LTYPET LTYPEG
%token <lval> LTYPES LTYPEM LTYPEI LTYPEXC LTYPEX LTYPERT
%token <lval> LCONST LFP LPC LSB %token <lval> LCONST LFP LPC LSB
%token <lval> LBREG LLREG LSREG LFREG LMREG LXREG %token <lval> LBREG LLREG LSREG LFREG LMREG LXREG
%token <dval> LFCONST %token <dval> LFCONST
%token <sval> LSCONST LSP %token <sval> LSCONST LSP
%token <sym> LNAME LLAB LVAR %token <sym> LNAME LLAB LVAR
%type <lval> con con3 expr pointer offset %type <lval> con con2 expr pointer offset
%type <gen> mem imm imm3 reg nam rel rem rim rom omem nmem %type <gen> mem imm imm2 reg nam rel rem rim rom omem nmem
%type <gen2> nonnon nonrel nonrem rimnon rimrem remrim spec10 %type <gen2> nonnon nonrel nonrem rimnon rimrem remrim spec10 spec11
%type <gen2> spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 %type <gen2> spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9
%% %%
prog: prog:
...@@ -106,6 +107,7 @@ inst: ...@@ -106,6 +107,7 @@ inst:
| LTYPEXC spec8 { outcode($1, &$2); } | LTYPEXC spec8 { outcode($1, &$2); }
| LTYPEX spec9 { outcode($1, &$2); } | LTYPEX spec9 { outcode($1, &$2); }
| LTYPERT spec10 { outcode($1, &$2); } | LTYPERT spec10 { outcode($1, &$2); }
| LTYPEG spec11 { outcode($1, &$2); }
nonnon: nonnon:
{ {
...@@ -177,12 +179,12 @@ spec1: /* DATA */ ...@@ -177,12 +179,12 @@ spec1: /* DATA */
} }
spec2: /* TEXT */ spec2: /* TEXT */
mem ',' imm3 mem ',' imm2
{ {
$$.from = $1; $$.from = $1;
$$.to = $3; $$.to = $3;
} }
| mem ',' con ',' imm3 | mem ',' con ',' imm2
{ {
$$.from = $1; $$.from = $1;
$$.from.scale = $3; $$.from.scale = $3;
...@@ -281,6 +283,19 @@ spec10: /* RET/RETF */ ...@@ -281,6 +283,19 @@ spec10: /* RET/RETF */
$$.to = nullgen; $$.to = nullgen;
} }
spec11: /* GLOBL */
mem ',' imm
{
$$.from = $1;
$$.to = $3;
}
| mem ',' con ',' imm
{
$$.from = $1;
$$.from.scale = $3;
$$.to = $5;
}
rem: rem:
reg reg
| mem | mem
...@@ -363,9 +378,8 @@ reg: ...@@ -363,9 +378,8 @@ reg:
$$ = nullgen; $$ = nullgen;
$$.type = $1; $$.type = $1;
} }
imm2:
imm3: '$' con2
'$' con3
{ {
$$ = nullgen; $$ = nullgen;
$$.type = D_CONST; $$.type = D_CONST;
...@@ -556,23 +570,24 @@ con: ...@@ -556,23 +570,24 @@ con:
$$ = $2; $$ = $2;
} }
con3: con2:
LCONST LCONST
{
$$ = $1 & 0xffffffffLL;
}
| '-' LCONST | '-' LCONST
{ {
$$ = -$2; $$ = -$2 & 0xffffffffLL;
} }
| LCONST '-' LCONST '-' LCONST | LCONST '-' LCONST
{ {
$$ = ($1 & 0xffffffffLL) + $$ = ($1 & 0xffffffffLL) +
(($3 & 0xffffLL) << 32) + (($3 & 0xffffLL) << 32);
(($5 & 0xffffLL) << 48);
} }
| '-' LCONST '-' LCONST '-' LCONST | '-' LCONST '-' LCONST
{ {
$$ = (-$2 & 0xffffffffLL) + $$ = (-$2 & 0xffffffffLL) +
(($4 & 0xffffLL) << 32) + (($4 & 0xffffLL) << 32);
(($6 & 0xffffLL) << 48);
} }
expr: expr:
......
...@@ -398,7 +398,7 @@ struct ...@@ -398,7 +398,7 @@ struct
"EMMS", LTYPE0, AEMMS, "EMMS", LTYPE0, AEMMS,
"END", LTYPE0, AEND, "END", LTYPE0, AEND,
"ENTER", LTYPE2, AENTER, "ENTER", LTYPE2, AENTER,
"GLOBL", LTYPET, AGLOBL, "GLOBL", LTYPEG, AGLOBL,
"HLT", LTYPE0, AHLT, "HLT", LTYPE0, AHLT,
"IDIVB", LTYPE2, AIDIVB, "IDIVB", LTYPE2, AIDIVB,
"IDIVL", LTYPE2, AIDIVL, "IDIVL", LTYPE2, AIDIVL,
......
...@@ -76,15 +76,26 @@ Pconv(Fmt *fp) ...@@ -76,15 +76,26 @@ Pconv(Fmt *fp)
Prog *p; Prog *p;
p = va_arg(fp->args, Prog*); p = va_arg(fp->args, Prog*);
if(p->as == ADATA) switch(p->as) {
case ADATA:
sprint(str, " %A %D/%d,%D", sprint(str, " %A %D/%d,%D",
p->as, &p->from, p->from.scale, &p->to); p->as, &p->from, p->from.scale, &p->to);
else if(p->as == ATEXT) break;
sprint(str, " %A %D,%d,%D",
p->as, &p->from, p->from.scale, &p->to); case ATEXT:
else if(p->from.scale) {
sprint(str, " %A %D,%D", sprint(str, " %A %D,%d,%lD",
p->as, &p->from, p->from.scale, &p->to);
break;
}
sprint(str, " %A %D,%lD",
p->as, &p->from, &p->to); p->as, &p->from, &p->to);
break;
defaul:
sprint(str, " %A %D,%lD", p->as, &p->from, &p->to);
break;
}
return fmtstrcpy(fp, str); return fmtstrcpy(fp, str);
} }
...@@ -106,6 +117,18 @@ Dconv(Fmt *fp) ...@@ -106,6 +117,18 @@ Dconv(Fmt *fp)
a = va_arg(fp->args, Adr*); a = va_arg(fp->args, Adr*);
i = a->type; i = a->type;
if(fp->flags & FmtLong) {
if(i != D_CONST) {
// ATEXT dst is not constant
sprint(str, "!!%D", a);
goto brk;
}
sprint(str, "$%lld-%lld", a->offset&0xffffffffLL,
(a->offset>>32)&0xffffffffLL);
goto brk;
}
if(i >= D_INDIR) { if(i >= D_INDIR) {
if(a->offset) if(a->offset)
sprint(str, "%lld(%R)", a->offset, i-D_INDIR); sprint(str, "%lld(%R)", a->offset, i-D_INDIR);
......
...@@ -30,11 +30,37 @@ ...@@ -30,11 +30,37 @@
#include "gc.h" #include "gc.h"
vlong
argsize(void)
{
Type *t;
long s;
//print("t=%T\n", thisfn);
s = 0;
for(t=thisfn->down; t!=T; t=t->down) {
switch(t->etype) {
case TVOID:
break;
case TDOT:
s += 64;
break;
default:
s = align(s, t, Aarg1);
s = align(s, t, Aarg2);
break;
}
//print(" %d %T\n", s, t);
}
return (s+7) & ~7;
}
void void
codgen(Node *n, Node *nn) codgen(Node *n, Node *nn)
{ {
Prog *sp; Prog *sp;
Node *n1, nod, nod1; Node *n1, nod, nod1;
vlong v;
cursafe = 0; cursafe = 0;
curarg = 0; curarg = 0;
...@@ -52,7 +78,11 @@ codgen(Node *n, Node *nn) ...@@ -52,7 +78,11 @@ codgen(Node *n, Node *nn)
break; break;
} }
nearln = nn->lineno; nearln = nn->lineno;
gpseudo(ATEXT, n1->sym, nodconst(stkoff));
v = argsize() << 32;
v |= stkoff & 0xffffffff;
gpseudo(ATEXT, n1->sym, nodgconst(v, types[TVLONG]));
sp = p; sp = p;
/* /*
......
...@@ -175,6 +175,7 @@ dowidth(Type *t) ...@@ -175,6 +175,7 @@ dowidth(Type *t)
w = widstruct(*getthis(t), 0, 0); w = widstruct(*getthis(t), 0, 0);
w = widstruct(*getinarg(t), w, 0); w = widstruct(*getinarg(t), w, 0);
w = widstruct(*getoutarg(t), w, 1); w = widstruct(*getoutarg(t), w, 1);
t->argwid = w;
w = 0; w = 0;
break; break;
} }
......
...@@ -22,7 +22,7 @@ compile(Node *fn) ...@@ -22,7 +22,7 @@ compile(Node *fn)
Plist *pl; Plist *pl;
Node nod1; Node nod1;
Prog *ptxt; Prog *ptxt;
long lno, argsiz; long lno;
if(newproc == N) { if(newproc == N) {
newproc = nod(ONAME, N, N); newproc = nod(ONAME, N, N);
...@@ -70,10 +70,7 @@ if(newproc == N) { ...@@ -70,10 +70,7 @@ if(newproc == N) {
pc->lineno = lineno; pc->lineno = lineno;
// fill in argument size // fill in argument size
argsiz = getthisx(curfn->type) -> width; ptxt->to.offset = rnd(curfn->type->argwid, maxround);
argsiz += getinargx(curfn->type) -> width;
argsiz += getoutargx(curfn->type) -> width;
ptxt->to.offset = rnd(argsiz, maxround);
// fill in final stack size // fill in final stack size
ptxt->to.offset <<= 32; ptxt->to.offset <<= 32;
......
...@@ -425,12 +425,5 @@ parsetextconst(vlong arg) ...@@ -425,12 +425,5 @@ parsetextconst(vlong arg)
textarg = (arg >> 32) & 0xffffffffLL; textarg = (arg >> 32) & 0xffffffffLL;
if(textarg & 0x80000000LL) if(textarg & 0x80000000LL)
textarg = 0; textarg = 0;
if(textarg <= 0)
textarg = 100;
if(textarg > textstksiz) {
textarg = textstksiz;
if(textarg <= 0)
textarg = 0;
}
textarg = (textarg+7) & ~7LL; textarg = (textarg+7) & ~7LL;
} }
...@@ -37,7 +37,7 @@ uchar ynone[] = ...@@ -37,7 +37,7 @@ uchar ynone[] =
}; };
uchar ytext[] = uchar ytext[] =
{ {
Ymb, Yi32, Zpseudo,1, Ymb, Yi64, Zpseudo,1,
0 0
}; };
uchar ynop[] = uchar ynop[] =
......
...@@ -96,10 +96,8 @@ struct Type ...@@ -96,10 +96,8 @@ struct Type
Type* nforw; Type* nforw;
// TFUNCT // TFUNCT
// Type* this;
// Type* argout;
// Type* argin;
Node* nname; Node* nname;
vlong argwid;
// TARRAY // TARRAY
long bound; long bound;
......
...@@ -46,11 +46,11 @@ TEXT _rt0_amd64(SB),7,$-8 ...@@ -46,11 +46,11 @@ TEXT _rt0_amd64(SB),7,$-8
CALL notok(SB) // never returns CALL notok(SB) // never returns
RET RET
TEXT sys·breakpoint(SB),7,$-8 TEXT sys·breakpoint(SB),7,$0
BYTE $0xcc BYTE $0xcc
RET RET
TEXT FLUSH(SB),7,$-8 TEXT FLUSH(SB),7,$0
RET RET
/* /*
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
// System calls and other sys.stuff for AMD64, Linux // System calls and other sys.stuff for AMD64, Linux
// //
TEXT sys·exit(SB),1,$-8 TEXT sys·exit(SB),1,$0-8
MOVL 8(SP), DI MOVL 8(SP), DI
MOVL $60, AX MOVL $60, AX
SYSCALL SYSCALL
RET RET
TEXT sys·write(SB),1,$-8 TEXT sys·write(SB),1,$0-24
MOVL 8(SP), DI MOVL 8(SP), DI
MOVQ 16(SP), SI MOVQ 16(SP), SI
MOVL 24(SP), DX MOVL 24(SP), DX
...@@ -20,27 +20,27 @@ TEXT sys·write(SB),1,$-8 ...@@ -20,27 +20,27 @@ TEXT sys·write(SB),1,$-8
SYSCALL SYSCALL
RET RET
TEXT open(SB),1,$-8 TEXT open(SB),1,$0-16
MOVQ 8(SP), DI MOVQ 8(SP), DI
MOVL 16(SP), SI MOVL 16(SP), SI
MOVL $2, AX // syscall entry MOVL $2, AX // syscall entry
SYSCALL SYSCALL
RET RET
TEXT close(SB),1,$-8 TEXT close(SB),1,$0-8
MOVL 8(SP), DI MOVL 8(SP), DI
MOVL $3, AX // syscall entry MOVL $3, AX // syscall entry
SYSCALL SYSCALL
RET RET
TEXT fstat(SB),1,$-8 TEXT fstat(SB),1,$0-16
MOVL 8(SP), DI MOVL 8(SP), DI
MOVQ 16(SP), SI MOVQ 16(SP), SI
MOVL $5, AX // syscall entry MOVL $5, AX // syscall entry
SYSCALL SYSCALL
RET RET
TEXT read(SB),1,$-8 TEXT read(SB),1,$0-24
MOVL 8(SP), DI MOVL 8(SP), DI
MOVQ 16(SP), SI MOVQ 16(SP), SI
MOVL 24(SP), DX MOVL 24(SP), DX
...@@ -48,7 +48,7 @@ TEXT read(SB),1,$-8 ...@@ -48,7 +48,7 @@ TEXT read(SB),1,$-8
SYSCALL SYSCALL
RET RET
TEXT sys·rt_sigaction(SB),1,$-8 TEXT sys·rt_sigaction(SB),1,$0-32
MOVL 8(SP), DI MOVL 8(SP), DI
MOVQ 16(SP), SI MOVQ 16(SP), SI
MOVQ 24(SP), DX MOVQ 24(SP), DX
...@@ -58,14 +58,14 @@ TEXT sys·rt_sigaction(SB),1,$-8 ...@@ -58,14 +58,14 @@ TEXT sys·rt_sigaction(SB),1,$-8
SYSCALL SYSCALL
RET RET
TEXT sigtramp(SB),1,$24 TEXT sigtramp(SB),1,$24-16
MOVQ DI,0(SP) MOVQ DI,0(SP)
MOVQ SI,8(SP) MOVQ SI,8(SP)
MOVQ DX,16(SP) MOVQ DX,16(SP)
CALL sighandler(SB) CALL sighandler(SB)
RET RET
TEXT sys·mmap(SB),1,$-8 TEXT sys·mmap(SB),1,$0-32
MOVQ 8(SP), DI MOVQ 8(SP), DI
MOVL 16(SP), SI MOVL 16(SP), SI
MOVL 20(SP), DX MOVL 20(SP), DX
...@@ -88,12 +88,12 @@ TEXT sys·mmap(SB),1,$-8 ...@@ -88,12 +88,12 @@ TEXT sys·mmap(SB),1,$-8
CALL notok(SB) CALL notok(SB)
RET RET
TEXT notok(SB),1,$-8 TEXT notok(SB),7,$0
MOVL $0xf1, BP MOVL $0xf1, BP
MOVQ BP, (BP) MOVQ BP, (BP)
RET RET
TEXT sys·memclr(SB),1,$-8 TEXT sys·memclr(SB),1,$0-16
MOVQ 8(SP), DI // arg 1 addr MOVQ 8(SP), DI // arg 1 addr
MOVL 16(SP), CX // arg 2 count (cannot be zero) MOVL 16(SP), CX // arg 2 count (cannot be zero)
ADDL $7, CX ADDL $7, CX
......
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