int32 l, fl, j;
vlong o;
int i, c;
+ Adr *a;
memset(buf.dbuf, 0, n+Dbufslop);
for(p = datap; p != P; p = p->link) {
- curp = p;
- if(!p->from.sym->reachable)
- diag("unreachable symbol in datblk - %s", p->from.sym->name);
- if(p->from.sym->type == SMACHO)
+ a = &p->from;
+
+ l = a->sym->value + a->offset - s;
+ if(l >= n)
continue;
- l = p->from.sym->value + p->from.offset - s;
- c = p->from.scale;
+
+ c = a->scale;
i = 0;
if(l < 0) {
if(l+c <= 0)
i = -l;
l = 0;
}
- if(l >= n)
+
+ curp = p;
+ if(!a->sym->reachable)
+ diag("unreachable symbol in datblk - %s", a->sym->name);
+ if(a->sym->type == SMACHO)
continue;
+
if(p->as != AINIT && p->as != ADYNT) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
case 4:
fl = ieeedtof(&p->to.ieee);
cast = (uchar*)&fl;
- if(debug['a'] && i == 0)
- outa(c, cast, fnuxi4, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = cast[fnuxi4[i]];
l++;
break;
case 8:
cast = (uchar*)&p->to.ieee;
- if(debug['a'] && i == 0)
- outa(c, cast, fnuxi8, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = cast[fnuxi8[i]];
l++;
break;
case D_SCONST:
- if(debug['a'] && i == 0)
- outa(c, (uchar*)p->to.scon, nil, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = p->to.scon[i];
l++;
diag("bad nuxi %d %d\n%P", c, i, curp);
break;
case 1:
- if(debug['a'] && i == 0)
- outa(c, cast, inuxi1, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi1[i]];
l++;
}
break;
case 2:
- if(debug['a'] && i == 0)
- outa(c, cast, inuxi2, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi2[i]];
l++;
}
break;
case 4:
- if(debug['a'] && i == 0)
- outa(c, cast, inuxi4, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi4[i]];
l++;
break;
case 8:
cast = (uchar*)&o;
- if(debug['a'] && i == 0)
- outa(c, cast, inuxi8, l+s+INITDAT);
for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi8[i]];
l++;
break;
}
}
+
write(cout, buf.dbuf, n);
+ if(!debug['a'])
+ return;
+
+ /*
+ * a second pass just to print the asm
+ */
+ for(p = datap; p != P; p = p->link) {
+ a = &p->from;
+
+ l = a->sym->value + a->offset - s;
+ if(l >= n)
+ continue;
+
+ c = a->scale;
+ i = 0;
+ if(l < 0)
+ continue;
+
+ if(a->sym->type == SMACHO)
+ continue;
+
+ switch(p->to.type) {
+ case D_FCONST:
+ switch(c) {
+ default:
+ case 4:
+ fl = ieeedtof(&p->to.ieee);
+ cast = (uchar*)&fl;
+ outa(c, cast, fnuxi4, l+s+INITDAT);
+ break;
+ case 8:
+ cast = (uchar*)&p->to.ieee;
+ outa(c, cast, fnuxi8, l+s+INITDAT);
+ break;
+ }
+ break;
+
+ case D_SCONST:
+ outa(c, (uchar*)p->to.scon, nil, l+s+INITDAT);
+ break;
+
+ default:
+ o = p->to.offset;
+ if(p->to.type == D_SIZE)
+ o += p->to.sym->size;
+ if(p->to.type == D_ADDR) {
+ if(p->to.sym) {
+ o += p->to.sym->value;
+ if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
+ o += INITDAT;
+ }
+ }
+ fl = o;
+ cast = (uchar*)&fl;
+ switch(c) {
+ case 1:
+ outa(c, cast, inuxi1, l+s+INITDAT);
+ break;
+ case 2:
+ outa(c, cast, inuxi2, l+s+INITDAT);
+ break;
+ case 4:
+ outa(c, cast, inuxi4, l+s+INITDAT);
+ break;
+ case 8:
+ cast = (uchar*)&o;
+ outa(c, cast, inuxi8, l+s+INITDAT);
+ break;
+ }
+ break;
+ }
+ }
}
vlong
Auto *u;
t = Bgetc(f);
+ a->index = D_NONE;
+ a->scale = 0;
if(t & T_INDEX) {
a->index = Bgetc(f);
a->scale = Bgetc(f);
- } else {
- a->index = D_NONE;
- a->scale = 0;
}
a->offset = 0;
if(t & T_OFFSET) {
}
if(t & T_TYPE)
a->type = Bgetc(f);
+ adrgotype = S;
if(t & T_GOTYPE)
- a->gotype = h[Bgetc(f)];
+ adrgotype = h[Bgetc(f)];
s = a->sym;
if(s == S)
return;
t = a->type;
if(t != D_AUTO && t != D_PARAM) {
- if(a->gotype)
- s->gotype = a->gotype;
+ if(adrgotype)
+ s->gotype = adrgotype;
return;
}
l = a->offset;
if(u->type == t) {
if(u->aoffset > l)
u->aoffset = l;
- if(a->gotype)
- u->gotype = a->gotype;
+ if(adrgotype)
+ u->gotype = adrgotype;
return;
}
}
u->asym = s;
u->aoffset = l;
u->type = t;
- u->gotype = a->gotype;
+ u->gotype = adrgotype;
}
void
p->line = Bget4(f);
p->back = 2;
p->mode = mode;
+ p->ft = 0;
+ p->tt = 0;
zaddr(f, &p->from, h);
+ fromgotype = adrgotype;
zaddr(f, &p->to, h);
if(debug['W'])
// redefinitions.
s = p->from.sym;
if(s != S && s->dupok) {
- if(debug['v'])
- Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
+// if(debug['v'])
+// Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
goto loop;
}
if(s != S) {
}
diag("%s: redefinition: %s\n%P", pn, s->name, p);
}
- if(p->from.gotype) {
- if(s->gotype && s->gotype != p->from.gotype)
+ if(fromgotype) {
+ if(s->gotype && s->gotype != fromgotype)
diag("%s: type mismatch for %s", pn, s->name);
- s->gotype = p->from.gotype;
+ s->gotype = fromgotype;
}
newtext(p, s);
goto loop;
}
static void
-bytereg(Adr *a)
+bytereg(Adr *a, char *t)
{
- if(a->index == D_NONE && (a->type >= D_AX && a->type <= D_R15))
+ if(a->index == D_NONE && (a->type >= D_AX && a->type <= D_R15)) {
a->type = D_AL + (a->type-D_AX);
+ *t = 0;
+ }
}
#define E 0xff
diag("asmins: missing op %P", p);
return;
}
- ft = oclass(&p->from) * Ymax;
- tt = oclass(&p->to) * Ymax;
+
+ if(p->ft == 0)
+ p->ft = oclass(&p->from);
+ if(p->tt == 0)
+ p->tt = oclass(&p->to);
+
+ ft = p->ft * Ymax;
+ tt = p->tt * Ymax;
+
t = o->ytab;
if(t == 0) {
diag("asmins: noproto %P", p);
break;
case Pb: /* botch */
- bytereg(&p->from);
- bytereg(&p->to);
+ bytereg(&p->from, &p->ft);
+ bytereg(&p->to, &p->tt);
break;
case P32: /* 32 bit but illegal if 64-bit mode */
break;
case Zmb_r:
- bytereg(&p->from);
+ bytereg(&p->from, &p->ft);
/* fall through */
case Zm_r:
*andptr++ = op;