#define NSNAME 8
#define NOPROF (1<<0)
#define DUPOK (1<<1)
-#define SOFmark (11)
+#define SOFmark "\xa7\xf1\xd9\x2a\x82\xc8\xd8\xfe"
/*
* amd64
for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT)
curtext = p;
- if(p->pc != pc)
- if(p->as != ATEXT || p->pc != pc+SOFmark) {
+ if(p->pc != pc) {
if(!debug['a'])
print("%P\n", curp);
diag("phase error %llux sb %llux in %s", p->pc, pc, TNAME);
Zaut_r,
Zo_m,
Zo_m64,
- Ztext,
Zpseudo,
Zr_m,
Zr_m_xm,
int find1(long, int);
int find2(long, int);
void follow(void);
+void addstachmark(void);
void gethunk(void);
void histtoauto(void);
double ieeedtod(Ieee*);
doprof1();
else
doprof2();
+ addstackmark();
span();
doinit();
asmb();
sig = 1729;
if(sig != 0){
if(s->sig != 0 && s->sig != sig)
- diag("incompatible type signatures %lux(%s)"
- "and %lux(%s) for %s", s->sig,
- filen[s->file], sig, pn, s->name);
+ diag("incompatible type signatures"
+ "%lux(%s) and %lux(%s) for %s",
+ s->sig, filen[s->file], sig, pn, s->name);
s->sig = sig;
s->file = files-1;
}
};
uchar ytext[] =
{
- Ymb, Yi32, Ztext, 1,
+ Ymb, Yi32, Zpseudo,1,
0
};
uchar ynop[] =
goto loop;
}
+Prog*
+byteq(int v)
+{
+ Prog *p;
+
+ p = prg();
+ p->as = ABYTE;
+ p->from.type = D_CONST;
+ p->from.offset = v&0xff;
+ return p;
+}
+
+void
+markstk(Prog *l)
+{
+ Prog *p0, *p, *q, *r;
+ long i, n, line;
+ Sym *s;
+
+ version++;
+ s = lookup(l->from.sym->name, version);
+ s->type = STEXT;
+ line = l->line;
+
+ // start with fake copy of ATEXT
+ p0 = prg();
+ p = p0;
+ *p = *l; // note this gets p->pcond and p->line
+
+ p->from.type = D_STATIC;
+ p->from.sym = s;
+ p->to.offset = 0;
+
+ // put out magic sequence
+ n = strlen(SOFmark);
+ for(i=0; i<n; i++) {
+ q = byteq(SOFmark[i]);
+ q->line = line;
+ p->link = q;
+ p = q;
+ }
+
+ // put out stack offset
+ n = l->to.offset;
+ if(n < 0)
+ n = 0;
+ for(i=0; i<3; i++) {
+ q = byteq(n);
+ q->line = line;
+ p->link = q;
+ p = q;
+ n = n>>8;
+ }
+
+ // put out null terminated name
+ for(i=0;; i++) {
+ n = s->name[i];
+ q = byteq(n);
+ q->line = line;
+ p->link = q;
+ p = q;
+ if(n == 0)
+ break;
+ }
+
+ // put out return instruction
+ q = prg();
+ q->as = ARET;
+ q->line = line;
+ p->link = q;
+ p = q;
+
+ r = l->pcond;
+ l->pcond = p0;
+ p->link = r;
+ p0->pcond = r;
+
+ // hard part is linking end of
+ // the text body to my fake ATEXT
+ for(p=l;; p=q) {
+ q = p->link;
+ if(q == r) {
+ p->link = p0;
+ return;
+ }
+ }
+}
+
+void
+addstackmark(void)
+{
+ Prog *p;
+
+ if(debug['v'])
+ Bprint(&bso, "%5.2f stkmark\n", cputime());
+ Bflush(&bso);
+
+ for(p=textp; p!=P; p=p->pcond) {
+ markstk(p); // splice in new body
+ p = p->pcond; // skip the one we just put in
+ }
+
+// for(p=textp; p!=P; p=p->pcond)
+// print("%P\n", p);
+}
+
int
relinv(int a)
{
if(debug['v'])
Bprint(&bso, "%5.2f patch\n", cputime());
Bflush(&bso);
+
s = lookup("exit", 0);
vexit = s->value;
for(p = firstp; p != P; p = p->link) {
p->pc = c;
asmins(p);
p->pc = c;
- if(p->as == ATEXT)
- p->pc += SOFmark; // skip the stack marker
m = andptr-and;
p->mark = m;
c += m;
}
}
p->pc = c;
- if(p->as == ATEXT)
- p->pc += SOFmark; // skip the stack marker
c += p->mark;
}
if(again) {
Prog *p;
long oldlc, v, s;
- oldpc = INITTEXT+SOFmark;
+ oldpc = INITTEXT;
oldlc = 0;
for(p = firstp; p != P; p = p->link) {
if(p->line == oldlc || p->as == ATEXT || p->as == ANOP) {
diag("asmins: unknown z %d %P", t[2], p);
return;
- case Ztext:
- v = p->to.offset;
- if(v < 0)
- v = 0;
-
- // eleven bytes of buried stack offset
- *andptr++ = v>>3;
- *andptr++ = v>>11;
- *andptr++ = v>>19;
- for(v=0; v<SOFmark-3; v++)
- *andptr++ = "\xa7\xf1\xd9\x2a\x82\xc8\xd8\xfe"[v];
- break;
-
case Zpseudo:
break;