Commit 7390aa01 authored by Russ Cox's avatar Russ Cox

nacl:

	add jmp to constant pc.
	generate HLT for INT $3
	do not insert NOPs between REP/REPN and subsequent instruction.
	allow very long time for convergence.

R=ken
OCL=34879
CL=34879
parent ce46cbe8
...@@ -201,6 +201,7 @@ enum ...@@ -201,6 +201,7 @@ enum
Zil_rp, Zil_rp,
Zilo_m, Zilo_m,
Zjmp, Zjmp,
Zjmpcon,
Zloop, Zloop,
Zm_o, Zm_o,
Zm_r, Zm_r,
......
...@@ -267,7 +267,8 @@ uchar ycall[] = ...@@ -267,7 +267,8 @@ uchar ycall[] =
uchar yjmp[] = uchar yjmp[] =
{ {
Ynone, Yml, Zo_m, 2, Ynone, Yml, Zo_m, 2,
Ynone, Ybr, Zjmp, 1, Ynone, Ybr, Zjmp, 0,
Ynone, Yi32, Zjmpcon, 1,
0 0
}; };
......
...@@ -464,7 +464,6 @@ dostkoff(void) ...@@ -464,7 +464,6 @@ dostkoff(void)
int a, f, curframe, curbecome, maxbecome; int a, f, curframe, curbecome, maxbecome;
Prog *pmorestack; Prog *pmorestack;
Sym *symmorestack; Sym *symmorestack;
static int fsreg;
pmorestack = P; pmorestack = P;
symmorestack = lookup("sys·morestack", 0); symmorestack = lookup("sys·morestack", 0);
......
...@@ -72,8 +72,9 @@ start: ...@@ -72,8 +72,9 @@ start:
if(debug['v']) if(debug['v'])
Bprint(&bso, "%5.2f span %d\n", cputime(), n); Bprint(&bso, "%5.2f span %d\n", cputime(), n);
Bflush(&bso); Bflush(&bso);
if(n > 50) { if(n > 500) {
print("span must be looping\n"); // TODO(rsc): figure out why nacl takes so long to converge.
print("span must be looping - %d\n", textsize);
errorexit(); errorexit();
} }
c = INITTEXT; c = INITTEXT;
...@@ -1045,6 +1046,12 @@ found: ...@@ -1045,6 +1046,12 @@ found:
case Z_ib: case Z_ib:
v = vaddr(&p->to); v = vaddr(&p->to);
case Zib_: case Zib_:
if(HEADTYPE == 8 && p->as == AINT && v == 3) {
// native client disallows all INT instructions.
// translate INT $3 to HLT.
*andptr++ = 0xf4;
break;
}
*andptr++ = op; *andptr++ = op;
*andptr++ = v; *andptr++ = v;
break; break;
...@@ -1194,6 +1201,15 @@ found: ...@@ -1194,6 +1201,15 @@ found:
} }
break; break;
case Zjmpcon:
v = p->to.offset - p->pc - 5;
*andptr++ = o->op[z+1];
*andptr++ = v;
*andptr++ = v>>8;
*andptr++ = v>>16;
*andptr++ = v>>24;
break;
case Zloop: case Zloop:
q = p->pcond; q = p->pcond;
if(q) { if(q) {
...@@ -1371,6 +1387,7 @@ asmins(Prog *p) ...@@ -1371,6 +1387,7 @@ asmins(Prog *p)
{ {
if(HEADTYPE == 8) { if(HEADTYPE == 8) {
ulong npc; ulong npc;
static Prog *prefix;
// native client // native client
// - pad indirect jump targets (aka ATEXT) to 32-byte boundary // - pad indirect jump targets (aka ATEXT) to 32-byte boundary
...@@ -1386,15 +1403,27 @@ asmins(Prog *p) ...@@ -1386,15 +1403,27 @@ asmins(Prog *p)
npc = p->pc + (andptr - and); npc = p->pc + (andptr - and);
p->pc += 31 & -npc; p->pc += 31 & -npc;
} }
if(p->as == AREP || p->as == AREPN) {
// save prefix for next instruction,
// so that inserted NOPs do not split (e.g.) REP / MOVSL sequence.
prefix = p;
andptr = and;
return;
}
andptr = and; andptr = and;
if(prefix)
doasm(prefix);
doasm(p); doasm(p);
npc = p->pc + (andptr - and); npc = p->pc + (andptr - and);
if((p->pc&~31) != ((npc-1)&~31)) { if(andptr > and && (p->pc&~31) != ((npc-1)&~31)) {
// crossed 32-byte boundary; pad to boundary and try again // crossed 32-byte boundary; pad to boundary and try again
p->pc += 31 & -p->pc; p->pc += 31 & -p->pc;
andptr = and; andptr = and;
if(prefix)
doasm(prefix);
doasm(p); doasm(p);
} }
prefix = nil;
} else { } else {
andptr = and; andptr = and;
doasm(p); doasm(p);
......
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