Commit 3b2de803 authored by Russ Cox's avatar Russ Cox

[dev.cc] liblink: arrange for Prog* argument in vaddr

The argument is unused in the C code but will be used in the Go translation,
because the Prog holds information needed to invoke the right meaning
of %A in the ctxt->diag calls in vaddr.

Change-Id: I501830f8ea0e909aafd8ec9ef5d7338e109d9548
Reviewed-on: https://go-review.googlesource.com/3041Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 68b78b8a
This diff is collapsed.
...@@ -1169,7 +1169,7 @@ static Optab optab[] = ...@@ -1169,7 +1169,7 @@ static Optab optab[] =
{0} {0}
}; };
static int32 vaddr(Link*, Addr*, Reloc*); static int32 vaddr(Link*, Prog*, Addr*, Reloc*);
// single-instruction no-ops of various lengths. // single-instruction no-ops of various lengths.
// constructed by hand and disassembled with gdb to verify. // constructed by hand and disassembled with gdb to verify.
...@@ -1711,7 +1711,7 @@ relput4(Link *ctxt, Prog *p, Addr *a) ...@@ -1711,7 +1711,7 @@ relput4(Link *ctxt, Prog *p, Addr *a)
vlong v; vlong v;
Reloc rel, *r; Reloc rel, *r;
v = vaddr(ctxt, a, &rel); v = vaddr(ctxt, p, a, &rel);
if(rel.siz != 0) { if(rel.siz != 0) {
if(rel.siz != 4) if(rel.siz != 4)
ctxt->diag("bad reloc"); ctxt->diag("bad reloc");
...@@ -1723,12 +1723,14 @@ relput4(Link *ctxt, Prog *p, Addr *a) ...@@ -1723,12 +1723,14 @@ relput4(Link *ctxt, Prog *p, Addr *a)
} }
static int32 static int32
vaddr(Link *ctxt, Addr *a, Reloc *r) vaddr(Link *ctxt, Prog *p, Addr *a, Reloc *r)
{ {
int t; int t;
int32 v; int32 v;
LSym *s; LSym *s;
USED(p);
if(r != nil) if(r != nil)
memset(r, 0, sizeof *r); memset(r, 0, sizeof *r);
...@@ -1770,11 +1772,13 @@ vaddr(Link *ctxt, Addr *a, Reloc *r) ...@@ -1770,11 +1772,13 @@ vaddr(Link *ctxt, Addr *a, Reloc *r)
} }
static void static void
asmand(Link *ctxt, Addr *a, int r) asmand(Link *ctxt, Prog *p, Addr *a, int r)
{ {
int32 v; int32 v;
int t, scale; int t, scale;
Reloc rel; Reloc rel;
USED(p);
v = a->offset; v = a->offset;
t = a->type; t = a->type;
...@@ -1787,7 +1791,7 @@ asmand(Link *ctxt, Addr *a, int r) ...@@ -1787,7 +1791,7 @@ asmand(Link *ctxt, Addr *a, int r)
case D_STATIC: case D_STATIC:
case D_EXTERN: case D_EXTERN:
t = D_NONE; t = D_NONE;
v = vaddr(ctxt, a, &rel); v = vaddr(ctxt, p, a, &rel);
break; break;
case D_AUTO: case D_AUTO:
case D_PARAM: case D_PARAM:
...@@ -1832,7 +1836,7 @@ asmand(Link *ctxt, Addr *a, int r) ...@@ -1832,7 +1836,7 @@ asmand(Link *ctxt, Addr *a, int r)
case D_STATIC: case D_STATIC:
case D_EXTERN: case D_EXTERN:
t = D_NONE; t = D_NONE;
v = vaddr(ctxt, a, &rel); v = vaddr(ctxt, p, a, &rel);
break; break;
case D_AUTO: case D_AUTO:
case D_PARAM: case D_PARAM:
...@@ -1843,7 +1847,7 @@ asmand(Link *ctxt, Addr *a, int r) ...@@ -1843,7 +1847,7 @@ asmand(Link *ctxt, Addr *a, int r)
} else } else
t -= D_INDIR; t -= D_INDIR;
if(t == D_TLS) if(t == D_TLS)
v = vaddr(ctxt, a, &rel); v = vaddr(ctxt, p, a, &rel);
if(t == D_NONE || (D_CS <= t && t <= D_GS) || t == D_TLS) { if(t == D_NONE || (D_CS <= t && t <= D_GS) || t == D_TLS) {
*ctxt->andptr++ = (0 << 6) | (5 << 0) | (r << 3); *ctxt->andptr++ = (0 << 6) | (5 << 0) | (r << 3);
...@@ -2235,35 +2239,35 @@ found: ...@@ -2235,35 +2239,35 @@ found:
case Zlitm_r: case Zlitm_r:
for(; op = o->op[z]; z++) for(; op = o->op[z]; z++)
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
break; break;
case Zm_r: case Zm_r:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
break; break;
case Zm2_r: case Zm2_r:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
*ctxt->andptr++ = o->op[z+1]; *ctxt->andptr++ = o->op[z+1];
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
break; break;
case Zm_r_xm: case Zm_r_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
break; break;
case Zm_r_i_xm: case Zm_r_i_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
*ctxt->andptr++ = p->to.offset; *ctxt->andptr++ = p->to.offset;
break; break;
case Zibm_r: case Zibm_r:
while ((op = o->op[z++]) != 0) while ((op = o->op[z++]) != 0)
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
*ctxt->andptr++ = p->to.offset; *ctxt->andptr++ = p->to.offset;
break; break;
...@@ -2274,7 +2278,7 @@ found: ...@@ -2274,7 +2278,7 @@ found:
p->from.type = p->from.index; p->from.type = p->from.index;
p->from.index = D_NONE; p->from.index = D_NONE;
p->ft = 0; p->ft = 0;
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
p->from.index = p->from.type; p->from.index = p->from.type;
p->from.type = D_ADDR; p->from.type = D_ADDR;
p->ft = 0; p->ft = 0;
...@@ -2282,22 +2286,22 @@ found: ...@@ -2282,22 +2286,22 @@ found:
case Zm_o: case Zm_o:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->from, o->op[z+1]); asmand(ctxt, p, &p->from, o->op[z+1]);
break; break;
case Zr_m: case Zr_m:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->to, reg[p->from.type]); asmand(ctxt, p, &p->to, reg[p->from.type]);
break; break;
case Zr_m_xm: case Zr_m_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, &p->to, reg[p->from.type]); asmand(ctxt, p, &p->to, reg[p->from.type]);
break; break;
case Zr_m_i_xm: case Zr_m_i_xm:
mediaop(ctxt, o, op, t[3], z); mediaop(ctxt, o, op, t[3], z);
asmand(ctxt, &p->to, reg[p->from.type]); asmand(ctxt, p, &p->to, reg[p->from.type]);
*ctxt->andptr++ = p->from.offset; *ctxt->andptr++ = p->from.offset;
break; break;
...@@ -2309,19 +2313,19 @@ found: ...@@ -2309,19 +2313,19 @@ found:
// fallthrough // fallthrough
case Zo_m: case Zo_m:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->to, o->op[z+1]); asmand(ctxt, p, &p->to, o->op[z+1]);
break; break;
case Zm_ibo: case Zm_ibo:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->from, o->op[z+1]); asmand(ctxt, p, &p->from, o->op[z+1]);
*ctxt->andptr++ = vaddr(ctxt, &p->to, nil); *ctxt->andptr++ = vaddr(ctxt, p, &p->to, nil);
break; break;
case Zibo_m: case Zibo_m:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->to, o->op[z+1]); asmand(ctxt, p, &p->to, o->op[z+1]);
*ctxt->andptr++ = vaddr(ctxt, &p->from, nil); *ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil);
break; break;
case Z_ib: case Z_ib:
...@@ -2330,20 +2334,20 @@ found: ...@@ -2330,20 +2334,20 @@ found:
a = &p->from; a = &p->from;
else else
a = &p->to; a = &p->to;
v = vaddr(ctxt, a, nil); v = vaddr(ctxt, p, a, nil);
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
break; break;
case Zib_rp: case Zib_rp:
*ctxt->andptr++ = op + reg[p->to.type]; *ctxt->andptr++ = op + reg[p->to.type];
*ctxt->andptr++ = vaddr(ctxt, &p->from, nil); *ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil);
break; break;
case Zil_rp: case Zil_rp:
*ctxt->andptr++ = op + reg[p->to.type]; *ctxt->andptr++ = op + reg[p->to.type];
if(o->prefix == Pe) { if(o->prefix == Pe) {
v = vaddr(ctxt, &p->from, nil); v = vaddr(ctxt, p, &p->from, nil);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
*ctxt->andptr++ = v>>8; *ctxt->andptr++ = v>>8;
} }
...@@ -2353,8 +2357,8 @@ found: ...@@ -2353,8 +2357,8 @@ found:
case Zib_rr: case Zib_rr:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->to, reg[p->to.type]); asmand(ctxt, p, &p->to, reg[p->to.type]);
*ctxt->andptr++ = vaddr(ctxt, &p->from, nil); *ctxt->andptr++ = vaddr(ctxt, p, &p->from, nil);
break; break;
case Z_il: case Z_il:
...@@ -2365,7 +2369,7 @@ found: ...@@ -2365,7 +2369,7 @@ found:
a = &p->to; a = &p->to;
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
if(o->prefix == Pe) { if(o->prefix == Pe) {
v = vaddr(ctxt, a, nil); v = vaddr(ctxt, p, a, nil);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
*ctxt->andptr++ = v>>8; *ctxt->andptr++ = v>>8;
} }
...@@ -2378,13 +2382,13 @@ found: ...@@ -2378,13 +2382,13 @@ found:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
if(t[2] == Zilo_m) { if(t[2] == Zilo_m) {
a = &p->from; a = &p->from;
asmand(ctxt, &p->to, o->op[z+1]); asmand(ctxt, p, &p->to, o->op[z+1]);
} else { } else {
a = &p->to; a = &p->to;
asmand(ctxt, &p->from, o->op[z+1]); asmand(ctxt, p, &p->from, o->op[z+1]);
} }
if(o->prefix == Pe) { if(o->prefix == Pe) {
v = vaddr(ctxt, a, nil); v = vaddr(ctxt, p, a, nil);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
*ctxt->andptr++ = v>>8; *ctxt->andptr++ = v>>8;
} }
...@@ -2394,9 +2398,9 @@ found: ...@@ -2394,9 +2398,9 @@ found:
case Zil_rr: case Zil_rr:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->to, reg[p->to.type]); asmand(ctxt, p, &p->to, reg[p->to.type]);
if(o->prefix == Pe) { if(o->prefix == Pe) {
v = vaddr(ctxt, &p->from, nil); v = vaddr(ctxt, p, &p->from, nil);
*ctxt->andptr++ = v; *ctxt->andptr++ = v;
*ctxt->andptr++ = v>>8; *ctxt->andptr++ = v>>8;
} }
...@@ -2414,7 +2418,7 @@ found: ...@@ -2414,7 +2418,7 @@ found:
case Zclr: case Zclr:
*ctxt->andptr++ = op; *ctxt->andptr++ = op;
asmand(ctxt, &p->to, reg[p->to.type]); asmand(ctxt, p, &p->to, reg[p->to.type]);
break; break;
case Zcall: case Zcall:
...@@ -2529,7 +2533,7 @@ found: ...@@ -2529,7 +2533,7 @@ found:
break; break;
case Zbyte: case Zbyte:
v = vaddr(ctxt, &p->from, &rel); v = vaddr(ctxt, p, &p->from, &rel);
if(rel.siz != 0) { if(rel.siz != 0) {
rel.siz = op; rel.siz = op;
r = addrel(ctxt->cursym); r = addrel(ctxt->cursym);
...@@ -2570,11 +2574,11 @@ bad: ...@@ -2570,11 +2574,11 @@ bad:
if(z >= D_BP && z <= D_DI) { if(z >= D_BP && z <= D_DI) {
if((breg = byteswapreg(ctxt, &p->to)) != D_AX) { if((breg = byteswapreg(ctxt, &p->to)) != D_AX) {
*ctxt->andptr++ = 0x87; /* xchg lhs,bx */ *ctxt->andptr++ = 0x87; /* xchg lhs,bx */
asmand(ctxt, &p->from, reg[breg]); asmand(ctxt, p, &p->from, reg[breg]);
subreg(&pp, z, breg); subreg(&pp, z, breg);
doasm(ctxt, &pp); doasm(ctxt, &pp);
*ctxt->andptr++ = 0x87; /* xchg lhs,bx */ *ctxt->andptr++ = 0x87; /* xchg lhs,bx */
asmand(ctxt, &p->from, reg[breg]); asmand(ctxt, p, &p->from, reg[breg]);
} else { } else {
*ctxt->andptr++ = 0x90 + reg[z]; /* xchg lsh,ax */ *ctxt->andptr++ = 0x90 + reg[z]; /* xchg lsh,ax */
subreg(&pp, z, D_AX); subreg(&pp, z, D_AX);
...@@ -2587,11 +2591,11 @@ bad: ...@@ -2587,11 +2591,11 @@ bad:
if(z >= D_BP && z <= D_DI) { if(z >= D_BP && z <= D_DI) {
if((breg = byteswapreg(ctxt, &p->from)) != D_AX) { if((breg = byteswapreg(ctxt, &p->from)) != D_AX) {
*ctxt->andptr++ = 0x87; /* xchg rhs,bx */ *ctxt->andptr++ = 0x87; /* xchg rhs,bx */
asmand(ctxt, &p->to, reg[breg]); asmand(ctxt, p, &p->to, reg[breg]);
subreg(&pp, z, breg); subreg(&pp, z, breg);
doasm(ctxt, &pp); doasm(ctxt, &pp);
*ctxt->andptr++ = 0x87; /* xchg rhs,bx */ *ctxt->andptr++ = 0x87; /* xchg rhs,bx */
asmand(ctxt, &p->to, reg[breg]); asmand(ctxt, p, &p->to, reg[breg]);
} else { } else {
*ctxt->andptr++ = 0x90 + reg[z]; /* xchg rsh,ax */ *ctxt->andptr++ = 0x90 + reg[z]; /* xchg rsh,ax */
subreg(&pp, z, D_AX); subreg(&pp, z, D_AX);
...@@ -2616,24 +2620,24 @@ mfound: ...@@ -2616,24 +2620,24 @@ mfound:
case 1: /* r,m */ case 1: /* r,m */
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
asmand(ctxt, &p->to, t[5]); asmand(ctxt, p, &p->to, t[5]);
break; break;
case 2: /* m,r */ case 2: /* m,r */
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
asmand(ctxt, &p->from, t[5]); asmand(ctxt, p, &p->from, t[5]);
break; break;
case 3: /* r,m - 2op */ case 3: /* r,m - 2op */
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
*ctxt->andptr++ = t[5]; *ctxt->andptr++ = t[5];
asmand(ctxt, &p->to, t[6]); asmand(ctxt, p, &p->to, t[6]);
break; break;
case 4: /* m,r - 2op */ case 4: /* m,r - 2op */
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
*ctxt->andptr++ = t[5]; *ctxt->andptr++ = t[5];
asmand(ctxt, &p->from, t[6]); asmand(ctxt, p, &p->from, t[6]);
break; break;
case 5: /* load full pointer, trash heap */ case 5: /* load full pointer, trash heap */
...@@ -2661,7 +2665,7 @@ mfound: ...@@ -2661,7 +2665,7 @@ mfound:
*ctxt->andptr++ = 0xb5; *ctxt->andptr++ = 0xb5;
break; break;
} }
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
break; break;
case 6: /* double shift */ case 6: /* double shift */
...@@ -2672,14 +2676,14 @@ mfound: ...@@ -2672,14 +2676,14 @@ mfound:
case D_CONST: case D_CONST:
*ctxt->andptr++ = 0x0f; *ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
asmand(ctxt, &p->to, reg[p->from.index]); asmand(ctxt, p, &p->to, reg[p->from.index]);
*ctxt->andptr++ = p->from.offset; *ctxt->andptr++ = p->from.offset;
break; break;
case D_CL: case D_CL:
case D_CX: case D_CX:
*ctxt->andptr++ = 0x0f; *ctxt->andptr++ = 0x0f;
*ctxt->andptr++ = t[5]; *ctxt->andptr++ = t[5];
asmand(ctxt, &p->to, reg[p->from.index]); asmand(ctxt, p, &p->to, reg[p->from.index]);
break; break;
} }
break; break;
...@@ -2691,7 +2695,7 @@ mfound: ...@@ -2691,7 +2695,7 @@ mfound:
} else } else
*ctxt->andptr++ = t[4]; *ctxt->andptr++ = t[4];
*ctxt->andptr++ = t[5]; *ctxt->andptr++ = t[5];
asmand(ctxt, &p->from, reg[p->to.type]); asmand(ctxt, p, &p->from, reg[p->to.type]);
break; break;
case 8: /* mov tls, r */ case 8: /* mov tls, r */
...@@ -2713,7 +2717,7 @@ mfound: ...@@ -2713,7 +2717,7 @@ mfound:
pp.from.scale = 0; pp.from.scale = 0;
*ctxt->andptr++ = 0x65; // GS *ctxt->andptr++ = 0x65; // GS
*ctxt->andptr++ = 0x8B; *ctxt->andptr++ = 0x8B;
asmand(ctxt, &pp.from, reg[p->to.type]); asmand(ctxt, p, &pp.from, reg[p->to.type]);
break; break;
case Hplan9: case Hplan9:
...@@ -2725,7 +2729,7 @@ mfound: ...@@ -2725,7 +2729,7 @@ mfound:
pp.from.offset = 0; pp.from.offset = 0;
pp.from.index = D_NONE; pp.from.index = D_NONE;
*ctxt->andptr++ = 0x8B; *ctxt->andptr++ = 0x8B;
asmand(ctxt, &pp.from, reg[p->to.type]); asmand(ctxt, p, &pp.from, reg[p->to.type]);
break; break;
case Hwindows: case Hwindows:
...@@ -2737,7 +2741,7 @@ mfound: ...@@ -2737,7 +2741,7 @@ mfound:
pp.from.scale = 0; pp.from.scale = 0;
*ctxt->andptr++ = 0x64; // FS *ctxt->andptr++ = 0x64; // FS
*ctxt->andptr++ = 0x8B; *ctxt->andptr++ = 0x8B;
asmand(ctxt, &pp.from, reg[p->to.type]); asmand(ctxt, p, &pp.from, reg[p->to.type]);
break; break;
} }
break; break;
......
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