1
0
mirror of https://github.com/golang/go synced 2024-10-03 08:11:27 -06:00

5l, 6l, 8l: indent, outdent

This is entirely adding and removing tabs.
It looks weird but will make the diffs for the
next change easier to read.

R=ken2
CC=golang-dev
https://golang.org/cl/2490041
This commit is contained in:
Russ Cox 2010-10-13 15:19:53 -04:00
parent dd8afb800b
commit d42903119b
12 changed files with 1679 additions and 1679 deletions

View File

@ -421,25 +421,25 @@ asmb(void)
seek(cout, OFFSET, 0); seek(cout, OFFSET, 0);
pc = INITTEXT; pc = INITTEXT;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
setarch(p); setarch(p);
if(p->as == ATEXT) { if(p->as == ATEXT) {
curtext = p; curtext = p;
autosize = p->to.offset + 4; autosize = p->to.offset + 4;
} }
if(p->pc != pc) { if(p->pc != pc) {
diag("phase error %lux sb %lux", diag("phase error %lux sb %lux",
p->pc, pc); p->pc, pc);
if(!debug['a']) if(!debug['a'])
prasm(curp); prasm(curp);
pc = p->pc; pc = p->pc;
} }
curp = p; curp = p;
o = oplook(p); /* could probably avoid this call */ o = oplook(p); /* could probably avoid this call */
if(thumb) if(thumb)
thumbasmout(p, o); thumbasmout(p, o);
else else
asmout(p, o); asmout(p, o);
pc += o->size; pc += o->size;
} }
while(pc-INITTEXT < textsize) { while(pc-INITTEXT < textsize) {
cput(0); cput(0);
@ -1148,29 +1148,29 @@ asmthumbmap(void)
for(p = firstp; p != P; p = p->link){ for(p = firstp; p != P; p = p->link){
pc = p->pc - INITTEXT; pc = p->pc - INITTEXT;
if(p->as == ATEXT){ if(p->as == ATEXT){
setarch(p); setarch(p);
if(thumb){ if(thumb){
if(p->from.sym->foreign){ // 8 bytes of ARM first if(p->from.sym->foreign){ // 8 bytes of ARM first
if(lastt >= 0){
outt(lastt, pc-1);
lastt = -1;
}
pc += 8;
}
if(lastt < 0)
lastt = pc;
}
else{
if(p->from.sym->foreign){ // 4 bytes of THUMB first
if(lastt < 0)
lastt = pc;
pc += 4;
}
if(lastt >= 0){ if(lastt >= 0){
outt(lastt, pc-1); outt(lastt, pc-1);
lastt = -1; lastt = -1;
} }
pc += 8;
} }
if(lastt < 0)
lastt = pc;
}
else{
if(p->from.sym->foreign){ // 4 bytes of THUMB first
if(lastt < 0)
lastt = pc;
pc += 4;
}
if(lastt >= 0){
outt(lastt, pc-1);
lastt = -1;
}
}
} }
} }
if(lastt >= 0) if(lastt >= 0)

File diff suppressed because it is too large Load Diff

View File

@ -359,80 +359,80 @@ patch(void)
s = lookup("exit", 0); s = lookup("exit", 0);
vexit = s->value; vexit = s->value;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
setarch(p); setarch(p);
a = p->as; a = p->as;
if(a == ATEXT) if(a == ATEXT)
curtext = p; curtext = p;
if(seenthumb && a == ABL){ if(seenthumb && a == ABL){
// if((s = p->to.sym) != S && (s1 = curtext->from.sym) != S) // if((s = p->to.sym) != S && (s1 = curtext->from.sym) != S)
// print("%s calls %s\n", s1->name, s->name); // print("%s calls %s\n", s1->name, s->name);
if((s = p->to.sym) != S && (s1 = curtext->from.sym) != S && s->thumb != s1->thumb) if((s = p->to.sym) != S && (s1 = curtext->from.sym) != S && s->thumb != s1->thumb)
s->foreign = 1; s->foreign = 1;
}
if((a == ABL || a == ABX || a == AB || a == ARET) &&
p->to.type != D_BRANCH && p->to.sym != S) {
s = p->to.sym;
switch(s->type) {
default:
diag("undefined: %s", s->name);
s->type = STEXT;
s->value = vexit;
continue; // avoid more error messages
case STEXT:
p->to.offset = s->value;
p->to.type = D_BRANCH;
break;
case SUNDEF:
if(p->as != ABL)
diag("help: SUNDEF in AB || ARET");
p->to.offset = 0;
p->to.type = D_BRANCH;
p->cond = UP;
break;
} }
} if((a == ABL || a == ABX || a == AB || a == ARET) &&
if(p->to.type != D_BRANCH || p->cond == UP) p->to.type != D_BRANCH && p->to.sym != S) {
continue; s = p->to.sym;
c = p->to.offset; switch(s->type) {
for(q = firstp; q != P;) { default:
if(q->forwd != P) diag("undefined: %s", s->name);
if(c >= q->forwd->pc) { s->type = STEXT;
q = q->forwd; s->value = vexit;
continue; // avoid more error messages
case STEXT:
p->to.offset = s->value;
p->to.type = D_BRANCH;
break;
case SUNDEF:
if(p->as != ABL)
diag("help: SUNDEF in AB || ARET");
p->to.offset = 0;
p->to.type = D_BRANCH;
p->cond = UP;
break;
}
}
if(p->to.type != D_BRANCH || p->cond == UP)
continue; continue;
c = p->to.offset;
for(q = firstp; q != P;) {
if(q->forwd != P)
if(c >= q->forwd->pc) {
q = q->forwd;
continue;
}
if(c == q->pc)
break;
q = q->link;
} }
if(c == q->pc) if(q == P) {
break; diag("branch out of range %ld\n%P", c, p);
q = q->link; p->to.type = D_NONE;
} }
if(q == P) { p->cond = q;
diag("branch out of range %ld\n%P", c, p);
p->to.type = D_NONE;
}
p->cond = q;
} }
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
setarch(p); setarch(p);
a = p->as; a = p->as;
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
if(seenthumb && a == ABL) { if(seenthumb && a == ABL) {
#ifdef CALLEEBX #ifdef CALLEEBX
if(0) if(0)
{} {}
#else #else
if((s = p->to.sym) != S && (s->foreign || s->fnptr)) if((s = p->to.sym) != S && (s->foreign || s->fnptr))
p->as = ABX; p->as = ABX;
#endif #endif
else if(p->to.type == D_OREG) else if(p->to.type == D_OREG)
p->as = ABX; p->as = ABX;
} }
if(p->cond != P && p->cond != UP) { if(p->cond != P && p->cond != UP) {
p->cond = brloop(p->cond); p->cond = brloop(p->cond);
if(p->cond != P) if(p->cond != P)
if(p->to.type == D_BRANCH) if(p->to.type == D_BRANCH)
p->to.offset = p->cond->pc; p->to.offset = p->cond->pc;
} }
} }
} }

View File

@ -27,45 +27,45 @@ softfloat()
wasfloat = 0; wasfloat = 0;
p = firstp; p = firstp;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
switch(p->as) { switch(p->as) {
case AMOVWD: case AMOVWD:
case AMOVWF: case AMOVWF:
case AMOVDW: case AMOVDW:
case AMOVFW: case AMOVFW:
case AMOVFD: case AMOVFD:
case AMOVDF: case AMOVDF:
case AMOVF: case AMOVF:
case AMOVD: case AMOVD:
case ACMPF: case ACMPF:
case ACMPD: case ACMPD:
case AADDF: case AADDF:
case AADDD: case AADDD:
case ASUBF: case ASUBF:
case ASUBD: case ASUBD:
case AMULF: case AMULF:
case AMULD: case AMULD:
case ADIVF: case ADIVF:
case ADIVD: case ADIVD:
if (psfloat == P) if (psfloat == P)
diag("floats used with _sfloat not defined"); diag("floats used with _sfloat not defined");
if (!wasfloat) { if (!wasfloat) {
next = prg(); next = prg();
*next = *p; *next = *p;
// BL _sfloat(SB) // BL _sfloat(SB)
*p = zprg; *p = zprg;
p->link = next; p->link = next;
p->as = ABL; p->as = ABL;
p->to.type = D_BRANCH; p->to.type = D_BRANCH;
p->to.sym = symsfloat; p->to.sym = symsfloat;
p->cond = psfloat; p->cond = psfloat;
p = next; p = next;
wasfloat = 1; wasfloat = 1;
}
break;
default:
wasfloat = 0;
} }
break;
default:
wasfloat = 0;
}
} }
} }

View File

@ -178,59 +178,59 @@ span(void)
op = nil; op = nil;
otxt = c; otxt = c;
for(p = firstp; p != P; op = p, p = p->link) { for(p = firstp; p != P; op = p, p = p->link) {
setarch(p); setarch(p);
p->pc = c; p->pc = c;
o = oplook(p); o = oplook(p);
m = o->size; m = o->size;
// must check literal pool here in case p generates many instructions // must check literal pool here in case p generates many instructions
if(blitrl){ if(blitrl){
if(thumb && isbranch(p)) if(thumb && isbranch(p))
pool.extra += brextra(p);
if(checkpool(op, p->as == ACASE ? casesz(p) : m))
c = p->pc = scan(op, p, c);
}
if(m == 0) {
if(p->as == ATEXT) {
if(blitrl && lastthumb != -1 && lastthumb != thumb){ // flush literal pool
if(flushpool(op, 0, 1))
c = p->pc = scan(op, p, c);
}
lastthumb = thumb;
curtext = p;
autosize = p->to.offset + 4;
if(p->from.sym != S)
p->from.sym->value = c;
/* need passes to resolve branches */
if(c-otxt >= 1L<<17)
bflag = 1;
otxt = c;
if(thumb && blitrl)
pool.extra += brextra(p); pool.extra += brextra(p);
if(checkpool(op, p->as == ACASE ? casesz(p) : m))
c = p->pc = scan(op, p, c);
}
if(m == 0) {
if(p->as == ATEXT) {
if(blitrl && lastthumb != -1 && lastthumb != thumb){ // flush literal pool
if(flushpool(op, 0, 1))
c = p->pc = scan(op, p, c);
}
lastthumb = thumb;
curtext = p;
autosize = p->to.offset + 4;
if(p->from.sym != S)
p->from.sym->value = c;
/* need passes to resolve branches */
if(c-otxt >= 1L<<17)
bflag = 1;
otxt = c;
if(thumb && blitrl)
pool.extra += brextra(p);
continue;
}
diag("zero-width instruction\n%P", p);
continue; continue;
} }
diag("zero-width instruction\n%P", p); switch(o->flag & (LFROM|LTO|LPOOL)) {
continue; case LFROM:
} addpool(p, &p->from);
switch(o->flag & (LFROM|LTO|LPOOL)) { break;
case LFROM: case LTO:
addpool(p, &p->from); addpool(p, &p->to);
break; break;
case LTO: case LPOOL:
addpool(p, &p->to); if ((p->scond&C_SCOND) == 14)
break; flushpool(p, 0, 0);
case LPOOL: break;
if ((p->scond&C_SCOND) == 14) }
if(p->as==AMOVW && p->to.type==D_REG && p->to.reg==REGPC && (p->scond&C_SCOND) == 14)
flushpool(p, 0, 0); flushpool(p, 0, 0);
break; c += m;
} if(blitrl && p->link == P){
if(p->as==AMOVW && p->to.type==D_REG && p->to.reg==REGPC && (p->scond&C_SCOND) == 14) if(thumb && isbranch(p))
flushpool(p, 0, 0); pool.extra += brextra(p);
c += m; checkpool(p, 0);
if(blitrl && p->link == P){ }
if(thumb && isbranch(p))
pool.extra += brextra(p);
checkpool(p, 0);
}
} }
/* /*
@ -245,47 +245,47 @@ span(void)
bflag = 0; bflag = 0;
c = INITTEXT; c = INITTEXT;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
setarch(p); setarch(p);
p->pc = c; p->pc = c;
if(thumb && isbranch(p)) if(thumb && isbranch(p))
nocache(p); nocache(p);
o = oplook(p); o = oplook(p);
/* very larg branches /* very larg branches
if(o->type == 6 && p->cond) { if(o->type == 6 && p->cond) {
otxt = p->cond->pc - c; otxt = p->cond->pc - c;
if(otxt < 0) if(otxt < 0)
otxt = -otxt; otxt = -otxt;
if(otxt >= (1L<<17) - 10) { if(otxt >= (1L<<17) - 10) {
q = prg(); q = prg();
q->link = p->link; q->link = p->link;
p->link = q; p->link = q;
q->as = AB; q->as = AB;
q->to.type = D_BRANCH; q->to.type = D_BRANCH;
q->cond = p->cond; q->cond = p->cond;
p->cond = q; p->cond = q;
q = prg(); q = prg();
q->link = p->link; q->link = p->link;
p->link = q; p->link = q;
q->as = AB; q->as = AB;
q->to.type = D_BRANCH; q->to.type = D_BRANCH;
q->cond = q->link->link; q->cond = q->link->link;
bflag = 1; bflag = 1;
}
} }
}
*/ */
m = o->size; m = o->size;
if(m == 0) { if(m == 0) {
if(p->as == ATEXT) { if(p->as == ATEXT) {
curtext = p; curtext = p;
autosize = p->to.offset + 4; autosize = p->to.offset + 4;
if(p->from.sym != S) if(p->from.sym != S)
p->from.sym->value = c; p->from.sym->value = c;
continue;
}
diag("zero-width instruction\n%P", p);
continue; continue;
} }
diag("zero-width instruction\n%P", p); c += m;
continue;
}
c += m;
} }
} }
@ -305,48 +305,48 @@ span(void)
oop = op = nil; oop = op = nil;
again = 0; again = 0;
for(p = firstp; p != P; oop = op, op = p, p = p->link){ for(p = firstp; p != P; oop = op, op = p, p = p->link){
setarch(p); setarch(p);
if(p->pc != c) if(p->pc != c)
again = 1;
p->pc = c;
if(thumb && isbranch(p))
nocache(p);
o = oplook(p);
m = o->size;
if(passes == 1 && thumb && isbranch(p)){ // start conservative so unneeded alignment is not added
if(p->as == ABL)
m = 4;
else
m = 2;
p->align = 0;
}
if(p->align){
if((p->align == 4 && (c&3)) || (p->align == 2 && !(c&3))){
if(ispad(op)){
oop->link = p;
op = oop;
c -= 2;
p->pc = c;
}
else{
op->link = pad(op, c);
op = op->link;
c += 2;
p->pc = c;
}
again = 1; again = 1;
p->pc = c;
if(thumb && isbranch(p))
nocache(p);
o = oplook(p);
m = o->size;
if(passes == 1 && thumb && isbranch(p)){ // start conservative so unneeded alignment is not added
if(p->as == ABL)
m = 4;
else
m = 2;
p->align = 0;
} }
} if(p->align){
if(m == 0) { if((p->align == 4 && (c&3)) || (p->align == 2 && !(c&3))){
if(p->as == ATEXT) { if(ispad(op)){
curtext = p; oop->link = p;
autosize = p->to.offset + 4; op = oop;
if(p->from.sym != S) c -= 2;
p->from.sym->value = c; p->pc = c;
continue; }
else{
op->link = pad(op, c);
op = op->link;
c += 2;
p->pc = c;
}
again = 1;
}
} }
} if(m == 0) {
c += m; if(p->as == ATEXT) {
curtext = p;
autosize = p->to.offset + 4;
if(p->from.sym != S)
p->from.sym->value = c;
continue;
}
}
c += m;
} }
if(c != lastc || again){ if(c != lastc || again){
lastc = c; lastc = c;

View File

@ -490,37 +490,37 @@ asmb(void)
pc = INITTEXT; pc = INITTEXT;
curp = firstp; curp = firstp;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT)
curtext = p;
if(p->pc != pc) {
if(!debug['a'])
print("%P\n", curp);
diag("phase error %llux sb %llux in %s", p->pc, pc, TNAME);
pc = p->pc;
}
curp = p;
asmins(p);
a = (andptr - and);
if(cbc < a)
cflush();
if(debug['a']) {
Bprint(&bso, pcstr, pc);
for(op1 = and; op1 < andptr; op1++)
Bprint(&bso, "%.2ux", *op1);
for(; op1 < and+Maxand; op1++)
Bprint(&bso, " ");
Bprint(&bso, "%P\n", curp);
}
if(dlm) {
if(p->as == ATEXT) if(p->as == ATEXT)
reloca = nil; curtext = p;
else if(reloca != nil) if(p->pc != pc) {
diag("reloc failure: %P", curp); if(!debug['a'])
} print("%P\n", curp);
memmove(cbp, and, a); diag("phase error %llux sb %llux in %s", p->pc, pc, TNAME);
cbp += a; pc = p->pc;
pc += a; }
cbc -= a; curp = p;
asmins(p);
a = (andptr - and);
if(cbc < a)
cflush();
if(debug['a']) {
Bprint(&bso, pcstr, pc);
for(op1 = and; op1 < andptr; op1++)
Bprint(&bso, "%.2ux", *op1);
for(; op1 < and+Maxand; op1++)
Bprint(&bso, " ");
Bprint(&bso, "%P\n", curp);
}
if(dlm) {
if(p->as == ATEXT)
reloca = nil;
else if(reloca != nil)
diag("reloc failure: %P", curp);
}
memmove(cbp, and, a);
cbp += a;
pc += a;
cbc -= a;
} }
cflush(); cflush();

View File

@ -672,184 +672,44 @@ dostkoff(void)
deltasp = 0; deltasp = 0;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) { if(p->as == ATEXT) {
curtext = p; curtext = p;
parsetextconst(p->to.offset); parsetextconst(p->to.offset);
autoffset = textstksiz; autoffset = textstksiz;
if(autoffset < 0) if(autoffset < 0)
autoffset = 0; autoffset = 0;
q = P; q = P;
q1 = P; q1 = P;
if((p->from.scale & NOSPLIT) && autoffset >= StackSmall) if((p->from.scale & NOSPLIT) && autoffset >= StackSmall)
diag("nosplit func likely to overflow stack"); diag("nosplit func likely to overflow stack");
if(!(p->from.scale & NOSPLIT)) { if(!(p->from.scale & NOSPLIT)) {
p = appendp(p); // load g into CX p = appendp(p); // load g into CX
p->as = AMOVQ; p->as = AMOVQ;
if(HEADTYPE == 7 || HEADTYPE == 9) // ELF uses FS if(HEADTYPE == 7 || HEADTYPE == 9) // ELF uses FS
p->from.type = D_INDIR+D_FS; p->from.type = D_INDIR+D_FS;
else else
p->from.type = D_INDIR+D_GS; p->from.type = D_INDIR+D_GS;
p->from.offset = tlsoffset+0; p->from.offset = tlsoffset+0;
p->to.type = D_CX; p->to.type = D_CX;
if(debug['K']) { if(debug['K']) {
// 6l -K means check not only for stack // 6l -K means check not only for stack
// overflow but stack underflow. // overflow but stack underflow.
// On underflow, INT 3 (breakpoint). // On underflow, INT 3 (breakpoint).
// Underflow itself is rare but this also // Underflow itself is rare but this also
// catches out-of-sync stack guard info // catches out-of-sync stack guard info
p = appendp(p);
p->as = ACMPQ;
p->from.type = D_INDIR+D_CX;
p->from.offset = 8;
p->to.type = D_SP;
p = appendp(p);
p->as = AJHI;
p->to.type = D_BRANCH;
p->to.offset = 4;
q1 = p;
p = appendp(p);
p->as = AINT;
p->from.type = D_CONST;
p->from.offset = 3;
p = appendp(p);
p->as = ANOP;
q1->pcond = p;
q1 = P;
}
if(autoffset < StackBig) { // do we need to call morestack?
if(autoffset <= StackSmall) {
// small stack
p = appendp(p);
p->as = ACMPQ;
p->from.type = D_SP;
p->to.type = D_INDIR+D_CX;
} else {
// large stack
p = appendp(p);
p->as = ALEAQ;
p->from.type = D_INDIR+D_SP;
p->from.offset = -(autoffset-StackSmall);
p->to.type = D_AX;
p = appendp(p);
p->as = ACMPQ;
p->from.type = D_AX;
p->to.type = D_INDIR+D_CX;
}
// common
p = appendp(p);
p->as = AJHI;
p->to.type = D_BRANCH;
p->to.offset = 4;
q = p;
}
/* 160 comes from 3 calls (3*8) 4 safes (4*8) and 104 guard */
moreconst1 = 0;
if(autoffset+160 > 4096)
moreconst1 = (autoffset+160) & ~7LL;
moreconst2 = textarg;
// 4 varieties varieties (const1==0 cross const2==0)
// and 6 subvarieties of (const1==0 and const2!=0)
p = appendp(p);
if(moreconst1 == 0 && moreconst2 == 0) {
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[0];
p->to.sym = symmorestack[0];
} else
if(moreconst1 != 0 && moreconst2 == 0) {
p->as = AMOVL;
p->from.type = D_CONST;
p->from.offset = moreconst1;
p->to.type = D_AX;
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[1];
p->to.sym = symmorestack[1];
} else
if(moreconst1 == 0 && moreconst2 <= 48 && moreconst2%8 == 0) {
i = moreconst2/8 + 3;
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[i];
p->to.sym = symmorestack[i];
} else
if(moreconst1 == 0 && moreconst2 != 0) {
p->as = AMOVL;
p->from.type = D_CONST;
p->from.offset = moreconst2;
p->to.type = D_AX;
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[2];
p->to.sym = symmorestack[2];
} else {
p->as = AMOVQ;
p->from.type = D_CONST;
p->from.offset = (uint64)moreconst2 << 32;
p->from.offset |= moreconst1;
p->to.type = D_AX;
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[3];
p->to.sym = symmorestack[3];
}
}
if(q != P)
q->pcond = p->link;
if(autoffset) {
p = appendp(p);
p->as = AADJSP;
p->from.type = D_CONST;
p->from.offset = autoffset;
p->spadj = autoffset;
if(q != P)
q->pcond = p;
}
deltasp = autoffset;
if(debug['K'] > 1 && autoffset) {
// 6l -KK means double-check for stack overflow
// even after calling morestack and even if the
// function is marked as nosplit.
p = appendp(p);
p->as = AMOVQ;
p->from.type = D_INDIR+D_CX;
p->from.offset = 0;
p->to.type = D_BX;
p = appendp(p);
p->as = ASUBQ;
p->from.type = D_CONST;
p->from.offset = StackSmall+32;
p->to.type = D_BX;
p = appendp(p); p = appendp(p);
p->as = ACMPQ; p->as = ACMPQ;
p->from.type = D_SP; p->from.type = D_INDIR+D_CX;
p->to.type = D_BX; p->from.offset = 8;
p->to.type = D_SP;
p = appendp(p); p = appendp(p);
p->as = AJHI; p->as = AJHI;
p->to.type = D_BRANCH; p->to.type = D_BRANCH;
p->to.offset = 4;
q1 = p; q1 = p;
p = appendp(p); p = appendp(p);
@ -862,70 +722,210 @@ dostkoff(void)
q1->pcond = p; q1->pcond = p;
q1 = P; q1 = P;
} }
}
pcsize = p->mode/8;
a = p->from.type;
if(a == D_AUTO)
p->from.offset += deltasp;
if(a == D_PARAM)
p->from.offset += deltasp + pcsize;
a = p->to.type;
if(a == D_AUTO)
p->to.offset += deltasp;
if(a == D_PARAM)
p->to.offset += deltasp + pcsize;
switch(p->as) { if(autoffset < StackBig) { // do we need to call morestack?
default: if(autoffset <= StackSmall) {
continue; // small stack
case APUSHL: p = appendp(p);
case APUSHFL: p->as = ACMPQ;
deltasp += 4; p->from.type = D_SP;
p->spadj = 4; p->to.type = D_INDIR+D_CX;
continue; } else {
case APUSHQ: // large stack
case APUSHFQ: p = appendp(p);
deltasp += 8; p->as = ALEAQ;
p->spadj = 8; p->from.type = D_INDIR+D_SP;
continue; p->from.offset = -(autoffset-StackSmall);
case APUSHW: p->to.type = D_AX;
case APUSHFW:
deltasp += 2; p = appendp(p);
p->spadj = 2; p->as = ACMPQ;
continue; p->from.type = D_AX;
case APOPL: p->to.type = D_INDIR+D_CX;
case APOPFL: }
deltasp -= 4;
p->spadj = -4; // common
continue; p = appendp(p);
case APOPQ: p->as = AJHI;
case APOPFQ: p->to.type = D_BRANCH;
deltasp -= 8; p->to.offset = 4;
p->spadj = -8; q = p;
continue; }
case APOPW:
case APOPFW: /* 160 comes from 3 calls (3*8) 4 safes (4*8) and 104 guard */
deltasp -= 2; moreconst1 = 0;
p->spadj = -2; if(autoffset+160 > 4096)
continue; moreconst1 = (autoffset+160) & ~7LL;
case ARET: moreconst2 = textarg;
break;
// 4 varieties varieties (const1==0 cross const2==0)
// and 6 subvarieties of (const1==0 and const2!=0)
p = appendp(p);
if(moreconst1 == 0 && moreconst2 == 0) {
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[0];
p->to.sym = symmorestack[0];
} else
if(moreconst1 != 0 && moreconst2 == 0) {
p->as = AMOVL;
p->from.type = D_CONST;
p->from.offset = moreconst1;
p->to.type = D_AX;
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[1];
p->to.sym = symmorestack[1];
} else
if(moreconst1 == 0 && moreconst2 <= 48 && moreconst2%8 == 0) {
i = moreconst2/8 + 3;
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[i];
p->to.sym = symmorestack[i];
} else
if(moreconst1 == 0 && moreconst2 != 0) {
p->as = AMOVL;
p->from.type = D_CONST;
p->from.offset = moreconst2;
p->to.type = D_AX;
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[2];
p->to.sym = symmorestack[2];
} else {
p->as = AMOVQ;
p->from.type = D_CONST;
p->from.offset = (uint64)moreconst2 << 32;
p->from.offset |= moreconst1;
p->to.type = D_AX;
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack[3];
p->to.sym = symmorestack[3];
}
} }
if(autoffset != deltasp) if(q != P)
diag("unbalanced PUSH/POP"); q->pcond = p->link;
if(p->from.type == D_CONST)
goto become;
if(autoffset) { if(autoffset) {
p = appendp(p);
p->as = AADJSP; p->as = AADJSP;
p->from.type = D_CONST; p->from.type = D_CONST;
p->from.offset = -autoffset; p->from.offset = autoffset;
p->spadj = -autoffset; p->spadj = autoffset;
p = appendp(p); if(q != P)
p->as = ARET; q->pcond = p;
} }
continue; deltasp = autoffset;
if(debug['K'] > 1 && autoffset) {
// 6l -KK means double-check for stack overflow
// even after calling morestack and even if the
// function is marked as nosplit.
p = appendp(p);
p->as = AMOVQ;
p->from.type = D_INDIR+D_CX;
p->from.offset = 0;
p->to.type = D_BX;
p = appendp(p);
p->as = ASUBQ;
p->from.type = D_CONST;
p->from.offset = StackSmall+32;
p->to.type = D_BX;
p = appendp(p);
p->as = ACMPQ;
p->from.type = D_SP;
p->to.type = D_BX;
p = appendp(p);
p->as = AJHI;
p->to.type = D_BRANCH;
q1 = p;
p = appendp(p);
p->as = AINT;
p->from.type = D_CONST;
p->from.offset = 3;
p = appendp(p);
p->as = ANOP;
q1->pcond = p;
q1 = P;
}
}
pcsize = p->mode/8;
a = p->from.type;
if(a == D_AUTO)
p->from.offset += deltasp;
if(a == D_PARAM)
p->from.offset += deltasp + pcsize;
a = p->to.type;
if(a == D_AUTO)
p->to.offset += deltasp;
if(a == D_PARAM)
p->to.offset += deltasp + pcsize;
switch(p->as) {
default:
continue;
case APUSHL:
case APUSHFL:
deltasp += 4;
p->spadj = 4;
continue;
case APUSHQ:
case APUSHFQ:
deltasp += 8;
p->spadj = 8;
continue;
case APUSHW:
case APUSHFW:
deltasp += 2;
p->spadj = 2;
continue;
case APOPL:
case APOPFL:
deltasp -= 4;
p->spadj = -4;
continue;
case APOPQ:
case APOPFQ:
deltasp -= 8;
p->spadj = -8;
continue;
case APOPW:
case APOPFW:
deltasp -= 2;
p->spadj = -2;
continue;
case ARET:
break;
}
if(autoffset != deltasp)
diag("unbalanced PUSH/POP");
if(p->from.type == D_CONST)
goto become;
if(autoffset) {
p->as = AADJSP;
p->from.type = D_CONST;
p->from.offset = -autoffset;
p->spadj = -autoffset;
p = appendp(p);
p->as = ARET;
}
continue;
become: become:
q = p; q = p;

View File

@ -51,29 +51,29 @@ span(void)
idat = INITDAT; idat = INITDAT;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
n = 0; n = 0;
if(p->to.type == D_BRANCH) if(p->to.type == D_BRANCH)
if(p->pcond == P) if(p->pcond == P)
p->pcond = p; p->pcond = p;
if((q = p->pcond) != P) if((q = p->pcond) != P)
if(q->back != 2) if(q->back != 2)
n = 1; n = 1;
p->back = n; p->back = n;
if(p->as == AADJSP) { if(p->as == AADJSP) {
p->to.type = D_SP; p->to.type = D_SP;
v = -p->from.offset; v = -p->from.offset;
p->from.offset = v;
p->as = p->mode != 64? AADDL: AADDQ;
if(v < 0) {
p->as = p->mode != 64? ASUBL: ASUBQ;
v = -v;
p->from.offset = v; p->from.offset = v;
p->as = p->mode != 64? AADDL: AADDQ;
if(v < 0) {
p->as = p->mode != 64? ASUBL: ASUBQ;
v = -v;
p->from.offset = v;
}
if(v == 0)
p->as = ANOP;
} }
if(v == 0)
p->as = ANOP;
}
} }
n = 0; n = 0;
@ -83,16 +83,16 @@ start:
Bflush(&bso); Bflush(&bso);
c = INITTEXT; c = INITTEXT;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
if(p->to.type == D_BRANCH) if(p->to.type == D_BRANCH)
if(p->back) if(p->back)
p->pc = c; p->pc = c;
asmins(p); asmins(p);
p->pc = c; p->pc = c;
m = andptr-and; m = andptr-and;
p->mark = m; p->mark = m;
c += m; c += m;
} }
loop: loop:
@ -107,20 +107,20 @@ loop:
again = 0; again = 0;
c = INITTEXT; c = INITTEXT;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
if(p->to.type == D_BRANCH || p->back & 0100) { if(p->to.type == D_BRANCH || p->back & 0100) {
if(p->back) if(p->back)
p->pc = c; p->pc = c;
asmins(p); asmins(p);
m = andptr-and; m = andptr-and;
if(m != p->mark) { if(m != p->mark) {
p->mark = m; p->mark = m;
again++; again++;
}
} }
} p->pc = c;
p->pc = c; c += p->mark;
c += p->mark;
} }
if(again) { if(again) {
textsize = c; textsize = c;

View File

@ -473,58 +473,58 @@ asmb(void)
seek(cout, HEADR, 0); seek(cout, HEADR, 0);
pc = INITTEXT; pc = INITTEXT;
curp = firstp; curp = firstp;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT)
curtext = p;
curp = p;
if(HEADTYPE == 8) {
// native client
expectpc = p->pc;
p->pc = pc;
asmins(p);
if(p->pc != expectpc) {
Bflush(&bso);
diag("phase error %lux sb %lux in %s", p->pc, expectpc, TNAME);
}
while(pc < p->pc) {
cput(0x90); // nop
pc++;
}
}
if(p->pc != pc) {
Bflush(&bso);
if(!debug['a'])
print("%P\n", curp);
diag("phase error %lux sb %lux in %s", p->pc, pc, TNAME);
pc = p->pc;
}
if(HEADTYPE != 8) {
asmins(p);
if(pc != p->pc) {
Bflush(&bso);
diag("asmins changed pc %lux sb %lux in %s", p->pc, pc, TNAME);
}
}
if(cbc < sizeof(and))
cflush();
a = (andptr - and);
if(debug['a']) {
Bprint(&bso, pcstr, pc);
for(op1 = and; op1 < andptr; op1++)
Bprint(&bso, "%.2ux", *op1 & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
if(dlm) {
if(p->as == ATEXT) if(p->as == ATEXT)
reloca = nil; curtext = p;
else if(reloca != nil) curp = p;
diag("reloc failure: %P", curp); if(HEADTYPE == 8) {
} // native client
memmove(cbp, and, a); expectpc = p->pc;
cbp += a; p->pc = pc;
pc += a; asmins(p);
cbc -= a; if(p->pc != expectpc) {
Bflush(&bso);
diag("phase error %lux sb %lux in %s", p->pc, expectpc, TNAME);
}
while(pc < p->pc) {
cput(0x90); // nop
pc++;
}
}
if(p->pc != pc) {
Bflush(&bso);
if(!debug['a'])
print("%P\n", curp);
diag("phase error %lux sb %lux in %s", p->pc, pc, TNAME);
pc = p->pc;
}
if(HEADTYPE != 8) {
asmins(p);
if(pc != p->pc) {
Bflush(&bso);
diag("asmins changed pc %lux sb %lux in %s", p->pc, pc, TNAME);
}
}
if(cbc < sizeof(and))
cflush();
a = (andptr - and);
if(debug['a']) {
Bprint(&bso, pcstr, pc);
for(op1 = and; op1 < andptr; op1++)
Bprint(&bso, "%.2ux", *op1 & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
if(dlm) {
if(p->as == ATEXT)
reloca = nil;
else if(reloca != nil)
diag("reloc failure: %P", curp);
}
memmove(cbp, and, a);
cbp += a;
pc += a;
cbc -= a;
} }
if(HEADTYPE == 8) { if(HEADTYPE == 8) {
int32 etext; int32 etext;

View File

@ -390,99 +390,99 @@ patch(void)
s = lookup("exit", 0); s = lookup("exit", 0);
vexit = s->value; vexit = s->value;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(HEADTYPE == 10) { // Windows if(HEADTYPE == 10) { // Windows
// Convert // Convert
// op n(GS), reg // op n(GS), reg
// to // to
// MOVL 0x2C(FS), reg // MOVL 0x2C(FS), reg
// op n(reg), reg // op n(reg), reg
// The purpose of this patch is to fix some accesses // The purpose of this patch is to fix some accesses
// to extern register variables (TLS) on Windows, as // to extern register variables (TLS) on Windows, as
// a different method is used to access them. // a different method is used to access them.
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 = appendp(p);
q->from = p->from; q->from = p->from;
q->from.type = D_INDIR + p->to.type; q->from.type = D_INDIR + p->to.type;
q->to = p->to; q->to = p->to;
q->as = p->as; q->as = p->as;
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_INDIR+D_FS; p->from.type = D_INDIR+D_FS;
p->from.offset = 0x2C; p->from.offset = 0x2C;
}
}
if(HEADTYPE == 7) { // Linux
// Running binaries under Xen requires using
// MOVL 0(GS), reg
// and then off(reg) instead of saying off(GS) directly
// when the offset is negative.
if(p->from.type == D_INDIR+D_GS && p->from.offset < 0
&& 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_INDIR+D_GS;
p->from.offset = 0;
}
}
if(p->as == ATEXT)
curtext = p;
if(p->as == ACALL || (p->as == AJMP && p->to.type != D_BRANCH)) {
s = p->to.sym;
if(s) {
if(debug['c'])
Bprint(&bso, "%s calls %s\n", TNAME, s->name);
switch(s->type) {
default:
/* diag prints TNAME first */
diag("undefined: %s", s->name);
s->type = STEXT;
s->value = vexit;
continue; // avoid more error messages
case STEXT:
p->to.offset = s->value;
break;
case SUNDEF:
p->pcond = UP;
p->to.offset = 0;
break;
} }
p->to.type = D_BRANCH;
} }
} if(HEADTYPE == 7) { // Linux
if(p->to.type != D_BRANCH || p->pcond == UP) // Running binaries under Xen requires using
continue; // MOVL 0(GS), reg
c = p->to.offset; // and then off(reg) instead of saying off(GS) directly
for(q = firstp; q != P;) { // when the offset is negative.
if(q->forwd != P) if(p->from.type == D_INDIR+D_GS && p->from.offset < 0
if(c >= q->forwd->pc) { && p->to.type >= D_AX && p->to.type <= D_DI) {
q = q->forwd; 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_INDIR+D_GS;
p->from.offset = 0;
}
}
if(p->as == ATEXT)
curtext = p;
if(p->as == ACALL || (p->as == AJMP && p->to.type != D_BRANCH)) {
s = p->to.sym;
if(s) {
if(debug['c'])
Bprint(&bso, "%s calls %s\n", TNAME, s->name);
switch(s->type) {
default:
/* diag prints TNAME first */
diag("undefined: %s", s->name);
s->type = STEXT;
s->value = vexit;
continue; // avoid more error messages
case STEXT:
p->to.offset = s->value;
break;
case SUNDEF:
p->pcond = UP;
p->to.offset = 0;
break;
}
p->to.type = D_BRANCH;
}
}
if(p->to.type != D_BRANCH || p->pcond == UP)
continue; continue;
c = p->to.offset;
for(q = firstp; q != P;) {
if(q->forwd != P)
if(c >= q->forwd->pc) {
q = q->forwd;
continue;
}
if(c == q->pc)
break;
q = q->link;
} }
if(c == q->pc) if(q == P) {
break; diag("branch out of range in %s\n%P", TNAME, p);
q = q->link; p->to.type = D_NONE;
} }
if(q == P) { p->pcond = q;
diag("branch out of range in %s\n%P", TNAME, p);
p->to.type = D_NONE;
}
p->pcond = q;
} }
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
p->mark = 0; /* initialization for follow */ p->mark = 0; /* initialization for follow */
if(p->pcond != P && p->pcond != UP) { if(p->pcond != P && p->pcond != UP) {
p->pcond = brloop(p->pcond); p->pcond = brloop(p->pcond);
if(p->pcond != P) if(p->pcond != P)
if(p->to.type == D_BRANCH) if(p->to.type == D_BRANCH)
p->to.offset = p->pcond->pc; p->to.offset = p->pcond->pc;
} }
} }
} }
@ -635,212 +635,212 @@ dostkoff(void)
deltasp = 0; deltasp = 0;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) { if(p->as == ATEXT) {
curtext = p; curtext = p;
autoffset = p->to.offset; autoffset = p->to.offset;
if(autoffset < 0) if(autoffset < 0)
autoffset = 0; autoffset = 0;
q = P; q = P;
q1 = P; q1 = P;
if(pmorestack != P) if(pmorestack != P)
if(!(p->from.scale & NOSPLIT)) { if(!(p->from.scale & NOSPLIT)) {
p = appendp(p); // load g into CX p = appendp(p); // load g into CX
switch(HEADTYPE) { switch(HEADTYPE) {
case 10: // Windows case 10: // Windows
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_INDIR+D_FS; p->from.type = D_INDIR+D_FS;
p->from.offset = 0x2c; p->from.offset = 0x2c;
p->to.type = D_CX; p->to.type = D_CX;
p = appendp(p); p = appendp(p);
p->as = AMOVL; p->as = AMOVL;
p->from.type = D_INDIR+D_CX; p->from.type = D_INDIR+D_CX;
p->from.offset = 0; p->from.offset = 0;
p->to.type = D_CX; p->to.type = D_CX;
break; break;
case 7: // Linux
p->as = AMOVL;
p->from.type = D_INDIR+D_GS;
p->from.offset = 0;
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:
p->as = AMOVL;
p->from.type = D_INDIR+D_GS;
p->from.offset = tlsoffset + 0;
p->to.type = D_CX;
}
if(debug['K']) {
// 8l -K means check not only for stack
// overflow but stack underflow.
// On underflow, INT 3 (breakpoint).
// Underflow itself is rare but this also
// catches out-of-sync stack guard info.
p = appendp(p);
p->as = ACMPL;
p->from.type = D_INDIR+D_CX;
p->from.offset = 4;
p->to.type = D_SP;
p = appendp(p);
p->as = AJCC;
p->to.type = D_BRANCH;
p->to.offset = 4;
q1 = p;
p = appendp(p);
p->as = AINT;
p->from.type = D_CONST;
p->from.offset = 3;
case 7: // Linux p = appendp(p);
p->as = AMOVL; p->as = ANOP;
p->from.type = D_INDIR+D_GS; q1->pcond = p;
p->from.offset = 0; }
p->to.type = D_CX;
p = appendp(p); if(autoffset < StackBig) { // do we need to call morestack
p->as = AMOVL; if(autoffset <= StackSmall) {
p->from.type = D_INDIR+D_CX; // small stack
p->from.offset = tlsoffset + 0;
p->to.type = D_CX;
break;
default:
p->as = AMOVL;
p->from.type = D_INDIR+D_GS;
p->from.offset = tlsoffset + 0;
p->to.type = D_CX;
}
if(debug['K']) {
// 8l -K means check not only for stack
// overflow but stack underflow.
// On underflow, INT 3 (breakpoint).
// Underflow itself is rare but this also
// catches out-of-sync stack guard info.
p = appendp(p); p = appendp(p);
p->as = ACMPL; p->as = ACMPL;
p->from.type = D_INDIR+D_CX; p->from.type = D_SP;
p->from.offset = 4; p->to.type = D_INDIR+D_CX;
p->to.type = D_SP; } else {
// large stack
p = appendp(p);
p->as = ALEAL;
p->from.type = D_INDIR+D_SP;
p->from.offset = -(autoffset-StackSmall);
p->to.type = D_AX;
p = appendp(p); p = appendp(p);
p->as = AJCC; p->as = ACMPL;
p->to.type = D_BRANCH; p->from.type = D_AX;
p->to.offset = 4; p->to.type = D_INDIR+D_CX;
q1 = p;
p = appendp(p);
p->as = AINT;
p->from.type = D_CONST;
p->from.offset = 3;
p = appendp(p);
p->as = ANOP;
q1->pcond = p;
} }
if(autoffset < StackBig) { // do we need to call morestack // common
if(autoffset <= StackSmall) {
// small stack
p = appendp(p);
p->as = ACMPL;
p->from.type = D_SP;
p->to.type = D_INDIR+D_CX;
} else {
// large stack
p = appendp(p);
p->as = ALEAL;
p->from.type = D_INDIR+D_SP;
p->from.offset = -(autoffset-StackSmall);
p->to.type = D_AX;
p = appendp(p);
p->as = ACMPL;
p->from.type = D_AX;
p->to.type = D_INDIR+D_CX;
}
// common
p = appendp(p);
p->as = AJHI;
p->to.type = D_BRANCH;
p->to.offset = 4;
q = p;
}
p = appendp(p); // save frame size in DX
p->as = AMOVL;
p->to.type = D_DX;
/* 160 comes from 3 calls (3*8) 4 safes (4*8) and 104 guard */
p->from.type = D_CONST;
if(autoffset+160 > 4096)
p->from.offset = (autoffset+160) & ~7LL;
p = appendp(p); // save arg size in AX
p->as = AMOVL;
p->to.type = D_AX;
p->from.type = D_CONST;
p->from.offset = curtext->to.offset2;
p = appendp(p); p = appendp(p);
p->as = ACALL; p->as = AJHI;
p->to.type = D_BRANCH; p->to.type = D_BRANCH;
p->pcond = pmorestack; p->to.offset = 4;
p->to.sym = symmorestack; q = p;
} }
if(q != P) p = appendp(p); // save frame size in DX
q->pcond = p->link; p->as = AMOVL;
p->to.type = D_DX;
/* 160 comes from 3 calls (3*8) 4 safes (4*8) and 104 guard */
p->from.type = D_CONST;
if(autoffset+160 > 4096)
p->from.offset = (autoffset+160) & ~7LL;
if(autoffset) { p = appendp(p); // save arg size in AX
p = appendp(p); p->as = AMOVL;
p->as = AADJSP; p->to.type = D_AX;
p->from.type = D_CONST; p->from.type = D_CONST;
p->from.offset = autoffset; p->from.offset = curtext->to.offset2;
p->spadj = autoffset;
if(q != P) p = appendp(p);
q->pcond = p; p->as = ACALL;
} p->to.type = D_BRANCH;
deltasp = autoffset; p->pcond = pmorestack;
} p->to.sym = symmorestack;
a = p->from.type;
if(a == D_AUTO)
p->from.offset += deltasp;
if(a == D_PARAM)
p->from.offset += deltasp + 4;
a = p->to.type;
if(a == D_AUTO)
p->to.offset += deltasp;
if(a == D_PARAM)
p->to.offset += deltasp + 4;
switch(p->as) {
default:
continue;
case APUSHL:
case APUSHFL:
deltasp += 4;
p->spadj = 4;
continue;
case APUSHW:
case APUSHFW:
deltasp += 2;
p->spadj = 2;
continue;
case APOPL:
case APOPFL:
deltasp -= 4;
p->spadj = -4;
continue;
case APOPW:
case APOPFW:
deltasp -= 2;
p->spadj = -2;
continue;
case ARET:
break;
} }
if(autoffset != deltasp) if(q != P)
diag("unbalanced PUSH/POP"); q->pcond = p->link;
if(p->from.type == D_CONST)
goto become;
if(autoffset) { if(autoffset) {
p = appendp(p);
p->as = AADJSP;
p->from.type = D_CONST;
p->from.offset = autoffset;
p->spadj = autoffset;
if(q != P)
q->pcond = p;
}
deltasp = autoffset;
}
a = p->from.type;
if(a == D_AUTO)
p->from.offset += deltasp;
if(a == D_PARAM)
p->from.offset += deltasp + 4;
a = p->to.type;
if(a == D_AUTO)
p->to.offset += deltasp;
if(a == D_PARAM)
p->to.offset += deltasp + 4;
switch(p->as) {
default:
continue;
case APUSHL:
case APUSHFL:
deltasp += 4;
p->spadj = 4;
continue;
case APUSHW:
case APUSHFW:
deltasp += 2;
p->spadj = 2;
continue;
case APOPL:
case APOPFL:
deltasp -= 4;
p->spadj = -4;
continue;
case APOPW:
case APOPFW:
deltasp -= 2;
p->spadj = -2;
continue;
case ARET:
break;
}
if(autoffset != deltasp)
diag("unbalanced PUSH/POP");
if(p->from.type == D_CONST)
goto become;
if(autoffset) {
q = p;
p = appendp(p);
p->as = ARET;
q->as = AADJSP;
q->from.type = D_CONST;
q->from.offset = -autoffset;
p->spadj = -autoffset;
}
continue;
become:
q = p; q = p;
p = appendp(p); p = appendp(p);
p->as = ARET; p->as = AJMP;
p->to = q->to;
p->pcond = q->pcond;
q->as = AADJSP; q->as = AADJSP;
q->from = zprg.from;
q->from.type = D_CONST; q->from.type = D_CONST;
q->from.offset = -autoffset; q->from.offset = -autoffset;
p->spadj = -autoffset; p->spadj = -autoffset;
} q->to = zprg.to;
continue; continue;
become:
q = p;
p = appendp(p);
p->as = AJMP;
p->to = q->to;
p->pcond = q->pcond;
q->as = AADJSP;
q->from = zprg.from;
q->from.type = D_CONST;
q->from.offset = -autoffset;
p->spadj = -autoffset;
q->to = zprg.to;
continue;
} }
} }

View File

@ -46,29 +46,29 @@ span(void)
idat = INITDAT; idat = INITDAT;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
n = 0; n = 0;
if(p->to.type == D_BRANCH) if(p->to.type == D_BRANCH)
if(p->pcond == P) if(p->pcond == P)
p->pcond = p; p->pcond = p;
if((q = p->pcond) != P) if((q = p->pcond) != P)
if(q->back != 2) if(q->back != 2)
n = 1; n = 1;
p->back = n; p->back = n;
if(p->as == AADJSP) { if(p->as == AADJSP) {
p->to.type = D_SP; p->to.type = D_SP;
v = -p->from.offset; v = -p->from.offset;
p->from.offset = v;
p->as = AADDL;
if(v < 0) {
p->as = ASUBL;
v = -v;
p->from.offset = v; p->from.offset = v;
p->as = AADDL;
if(v < 0) {
p->as = ASUBL;
v = -v;
p->from.offset = v;
}
if(v == 0)
p->as = ANOP;
} }
if(v == 0)
p->as = ANOP;
}
} }
n = 0; n = 0;
@ -89,24 +89,24 @@ start:
if(HEADTYPE == 8) if(HEADTYPE == 8)
c = (c+31)&~31; c = (c+31)&~31;
} }
if(p->to.type == D_BRANCH) if(p->to.type == D_BRANCH)
if(p->back) if(p->back)
p->pc = c;
if(n == 0 || HEADTYPE == 8 || p->to.type == D_BRANCH) {
if(HEADTYPE == 8)
p->pc = c;
asmins(p);
m = andptr-and;
if(p->mark != m)
again = 1;
p->mark = m;
}
if(HEADTYPE == 8) {
c = p->pc + p->mark;
} else {
p->pc = c; p->pc = c;
if(n == 0 || HEADTYPE == 8 || p->to.type == D_BRANCH) { c += p->mark;
if(HEADTYPE == 8) }
p->pc = c;
asmins(p);
m = andptr-and;
if(p->mark != m)
again = 1;
p->mark = m;
}
if(HEADTYPE == 8) {
c = p->pc + p->mark;
} else {
p->pc = c;
c += p->mark;
}
} }
textsize = c; textsize = c;
n++; n++;

View File

@ -945,65 +945,65 @@ asmlc(void)
oldpc = INITTEXT; oldpc = INITTEXT;
oldlc = 0; oldlc = 0;
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) { if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
if(p->as == ATEXT) if(p->as == ATEXT)
curtext = p; curtext = p;
if(debug['O'])
Bprint(&bso, "%6llux %P\n",
p->pc, p);
continue;
}
if(debug['O']) if(debug['O'])
Bprint(&bso, "%6llux %P\n", Bprint(&bso, "\t\t%6ld", lcsize);
p->pc, p); v = (p->pc - oldpc) / MINLC;
continue; while(v) {
} s = 127;
if(debug['O']) if(v < 127)
Bprint(&bso, "\t\t%6ld", lcsize); s = v;
v = (p->pc - oldpc) / MINLC; cput(s+128); /* 129-255 +pc */
while(v) { if(debug['O'])
s = 127; Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128);
if(v < 127) v -= s;
s = v; lcsize++;
cput(s+128); /* 129-255 +pc */ }
if(debug['O']) s = p->line - oldlc;
Bprint(&bso, " pc+%ld*%d(%ld)", s, MINLC, s+128); oldlc = p->line;
v -= s; oldpc = p->pc + MINLC;
if(s > 64 || s < -64) {
cput(0); /* 0 vv +lc */
cput(s>>24);
cput(s>>16);
cput(s>>8);
cput(s);
if(debug['O']) {
if(s > 0)
Bprint(&bso, " lc+%ld(%d,%ld)\n",
s, 0, s);
else
Bprint(&bso, " lc%ld(%d,%ld)\n",
s, 0, s);
Bprint(&bso, "%6llux %P\n",
p->pc, p);
}
lcsize += 5;
continue;
}
if(s > 0) {
cput(0+s); /* 1-64 +lc */
if(debug['O']) {
Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
Bprint(&bso, "%6llux %P\n",
p->pc, p);
}
} else {
cput(64-s); /* 65-128 -lc */
if(debug['O']) {
Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
Bprint(&bso, "%6llux %P\n",
p->pc, p);
}
}
lcsize++; lcsize++;
}
s = p->line - oldlc;
oldlc = p->line;
oldpc = p->pc + MINLC;
if(s > 64 || s < -64) {
cput(0); /* 0 vv +lc */
cput(s>>24);
cput(s>>16);
cput(s>>8);
cput(s);
if(debug['O']) {
if(s > 0)
Bprint(&bso, " lc+%ld(%d,%ld)\n",
s, 0, s);
else
Bprint(&bso, " lc%ld(%d,%ld)\n",
s, 0, s);
Bprint(&bso, "%6llux %P\n",
p->pc, p);
}
lcsize += 5;
continue;
}
if(s > 0) {
cput(0+s); /* 1-64 +lc */
if(debug['O']) {
Bprint(&bso, " lc+%ld(%ld)\n", s, 0+s);
Bprint(&bso, "%6llux %P\n",
p->pc, p);
}
} else {
cput(64-s); /* 65-128 -lc */
if(debug['O']) {
Bprint(&bso, " lc%ld(%ld)\n", s, 64-s);
Bprint(&bso, "%6llux %P\n",
p->pc, p);
}
}
lcsize++;
} }
while(lcsize & 1) { while(lcsize & 1) {
s = 129; s = 129;