aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcomex2015-02-09 00:06:05 -0500
committercomex2015-02-09 00:06:05 -0500
commitd819360f9e619ddadde2bbae3cc1ec389a43a8e9 (patch)
tree00507e57c247abede74efcdde24c1bc7e9f7b1bd /lib
parentFix other architectures compiling - haven't tried *running* anything.. (diff)
downloadsubstitute-d819360f9e619ddadde2bbae3cc1ec389a43a8e9.tar.gz
more
Diffstat (limited to '')
-rw-r--r--lib/arm/arch-dis.h2
-rw-r--r--lib/arm/arch-transform-dis.inc.h58
-rw-r--r--lib/arm64/arch-dis.h2
-rw-r--r--lib/arm64/arch-transform-dis.inc.h26
-rw-r--r--lib/transform-dis.c3
5 files changed, 51 insertions, 40 deletions
diff --git a/lib/arm/arch-dis.h b/lib/arm/arch-dis.h
index c64ff2e..bc98cb9 100644
--- a/lib/arm/arch-dis.h
+++ b/lib/arm/arch-dis.h
@@ -19,7 +19,7 @@
struct arch_pcrel_info {
unsigned reg;
- enum pcrel_load_mode lm;
+ enum pcrel_load_mode load_mode;
};
struct arch_dis_ctx {
diff --git a/lib/arm/arch-transform-dis.inc.h b/lib/arm/arch-transform-dis.inc.h
index 6e91ff5..7cd8561 100644
--- a/lib/arm/arch-transform-dis.inc.h
+++ b/lib/arm/arch-transform-dis.inc.h
@@ -4,7 +4,7 @@
static struct assemble_ctx tdctx_to_actx(const struct transform_dis_ctx *ctx) {
int cond;
if (ctx->arch.pc_low_bit) {
- cond = ctx->op >> 28;
+ cond = ctx->base.op >> 28;
if (cond == 0xf)
cond = 0xe;
} else {
@@ -24,16 +24,18 @@ static int invert_arm_cond(int cc) {
return cc ^ 1;
}
-static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
- unsigned o0, unsigned o1, unsigned o2, unsigned o3, unsigned out_mask) {
+static NOINLINE UNUSED
+void transform_dis_data(struct transform_dis_ctx *ctx, unsigned o0, unsigned o1,
+ unsigned o2, unsigned o3, unsigned out_mask) {
#ifdef TRANSFORM_DIS_VERBOSE
- printf("transform_dis_data: (%p) %x %x %x %x out_mask=%x\n", (void *) ctx->pc,
+ printf("transform_dis_data: (0x%llx) %x %x %x %x out_mask=%x\n",
+ (unsigned long long) ctx->base.pc,
o0, o1, o2, o3, out_mask);
#endif
- /* We only care if at least one op is PC, so quickly test that. */
+ /* We only care if at least one op is PC, so quickly test that. XXX */
if (((o0 | o1 | o2 | o3) & 15) != 15)
return;
- unsigned *newval = ctx->newval;
+ unsigned *newval = ctx->base.newval;
newval[0] = o0;
newval[1] = o1;
newval[2] = o2;
@@ -67,7 +69,7 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
}
if (out_mask & DFLAG_IS_LDRD_STRD)
in_regs |= 1 << (newval[0] + 1);
- uint32_t pc = ctx->pc + (ctx->arch.pc_low_bit ? 4 : 8);
+ uint32_t pc = ctx->base.pc + (ctx->arch.pc_low_bit ? 4 : 8);
int scratch = __builtin_ctz(~(in_regs | (1 << out_reg)));
#ifdef TRANSFORM_DIS_VERBOSE
@@ -85,7 +87,7 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
for (int i = 0; i < 4; i++)
if (newval[i] == 15)
newval[i] = scratch;
- ctx->write_newop_here = *codep; *codep += ctx->op_size;
+ ctx->write_newop_here = *codep; *codep += ctx->base.op_size;
STRri(actx, scratch, 13, 4);
POPmulti(actx, 1 << scratch | 1 << 15);
if (actx.cond != 0xe)
@@ -97,7 +99,7 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
for (int i = 0; i < 4; i++)
if (newval[i] == 15)
newval[i] = out_reg;
- ctx->write_newop_here = *codep; *codep += ctx->op_size;
+ ctx->write_newop_here = *codep; *codep += ctx->base.op_size;
} else {
/* case 4 */
PUSHone(actx, scratch);
@@ -105,7 +107,7 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
for (int i = 0; i < 4; i++)
if (newval[i] == 15)
newval[i] = scratch;
- ctx->write_newop_here = *codep; *codep += ctx->op_size;
+ ctx->write_newop_here = *codep; *codep += ctx->base.op_size;
POPone(actx, scratch);
}
}
@@ -116,35 +118,41 @@ static NOINLINE UNUSED void transform_dis_data(struct transform_dis_ctx *ctx,
#endif
}
-static NOINLINE UNUSED void transform_dis_pcrel(struct transform_dis_ctx *ctx,
- uintptr_t dpc, unsigned reg, enum pcrel_load_mode load_mode) {
+static NOINLINE UNUSED
+void transform_dis_pcrel(struct transform_dis_ctx *ctx, uintptr_t dpc,
+ struct arch_pcrel_info info) {
#ifdef TRANSFORM_DIS_VERBOSE
- printf("transform_dis_pcrel: (%p) dpc=%p reg=%x mode=%d\n", (void *) ctx->pc,
- (void *) dpc, reg, load_mode);
+ printf("transform_dis_pcrel: (0x%llx) dpc=0x%llx reg=%x mode=%d\n",
+ (unsigned long long) ctx->base.pc,
+ (unsigned long long) dpc,
+ info.reg, info.load_mode);
#endif
ctx->write_newop_here = NULL;
struct assemble_ctx actx = tdctx_to_actx(ctx);
- if (reg == 15) {
+ if (info.reg == 15) {
int scratch = 0;
PUSHone(actx, scratch);
PUSHone(actx, scratch);
MOVW_MOVT(actx, scratch, dpc);
- if (load_mode != PLM_ADR)
- LDRxi(actx, scratch, scratch, 0, load_mode);
+ if (info.load_mode != PLM_ADR)
+ LDRxi(actx, scratch, scratch, 0, info.load_mode);
STRri(actx, scratch, 13, 4);
POPmulti(actx, 1 << scratch | 1 << 15);
transform_dis_ret(ctx);
} else {
- MOVW_MOVT(actx, reg, dpc);
- if (load_mode != PLM_ADR)
- LDRxi(actx, reg, reg, 0, load_mode);
+ MOVW_MOVT(actx, info.reg, dpc);
+ if (info.load_mode != PLM_ADR)
+ LDRxi(actx, info.reg, info.reg, 0, info.load_mode);
}
}
-static NOINLINE UNUSED void transform_dis_branch(struct transform_dis_ctx *ctx,
+static NOINLINE UNUSED
+void transform_dis_branch(struct transform_dis_ctx *ctx,
uintptr_t dpc, int cc) {
#ifdef TRANSFORM_DIS_VERBOSE
- printf("transform_dis (%p): branch => %p\n", (void *) ctx->pc, (void *) dpc);
+ printf("transform_dis (0x%llx): branch => 0x%llx\n",
+ (unsigned long long) ctx->base.pc,
+ (unsigned long long) dpc);
#endif
if (dpc >= ctx->pc_patch_start && dpc < ctx->pc_patch_end) {
/* don't support this for now */
@@ -162,9 +170,9 @@ static NOINLINE UNUSED void transform_dis_branch(struct transform_dis_ctx *ctx,
actx.cond = invert_arm_cond(cc & 0xf);
Bccrel(actx, 2+8);
} else if ((cc & CC_CBXZ) == CC_CBXZ) {
- ctx->modify = true;
- ctx->newval[0] = ctx->pc + 2+8;
- ctx->newval[1] = 1; /* do invert */
+ ctx->base.modify = true;
+ ctx->base.newval[0] = ctx->base.pc + 2+8;
+ ctx->base.newval[1] = 1; /* do invert */
void **codep = ctx->rewritten_ptr_ptr;
ctx->write_newop_here = *codep; *codep += 2;
}
diff --git a/lib/arm64/arch-dis.h b/lib/arm64/arch-dis.h
index f91328b..2990f5a 100644
--- a/lib/arm64/arch-dis.h
+++ b/lib/arm64/arch-dis.h
@@ -4,7 +4,7 @@
struct arch_pcrel_info {
unsigned reg;
- enum pcrel_load_mode lm;
+ enum pcrel_load_mode load_mode;
};
struct arch_dis_ctx {
diff --git a/lib/arm64/arch-transform-dis.inc.h b/lib/arm64/arch-transform-dis.inc.h
index d8f831d..ac11e45 100644
--- a/lib/arm64/arch-transform-dis.inc.h
+++ b/lib/arm64/arch-transform-dis.inc.h
@@ -1,17 +1,17 @@
#include "arm64/assemble.h"
static NOINLINE UNUSED
-void transform_dis_pcrel(struct transform_dis_ctx *ctx, uint_tptr dpc, unsigned reg,
- enum pcrel_load_mode load_mode) {
+void transform_dis_pcrel(struct transform_dis_ctx *ctx, uint_tptr dpc,
+ struct arch_pcrel_info info) {
ctx->write_newop_here = NULL;
void **codep = ctx->rewritten_ptr_ptr;
- if (load_mode >= PLM_U32_SIMD) {
- int reg = arm64_get_unwritten_temp_reg(&ctx->arch);
+ if (info.load_mode >= PLM_U32_SIMD) {
+ int temp = arm64_get_unwritten_temp_reg(&ctx->arch);
MOVi64(codep, 0, dpc);
- LDRxi(codep, reg, 0, 0, true, load_mode);
+ LDRxi(codep, temp, 0, 0, true, info.load_mode);
} else {
- MOVi64(codep, reg, dpc);
- LDRxi(codep, reg, reg, 0, true, load_mode);
+ MOVi64(codep, info.reg, dpc);
+ LDRxi(codep, info.reg, info.reg, 0, true, info.load_mode);
}
}
@@ -19,7 +19,9 @@ static NOINLINE UNUSED
void transform_dis_branch(struct transform_dis_ctx *ctx, uint_tptr dpc, int cc) {
/* TODO fix BL */
#ifdef TRANSFORM_DIS_VERBOSE
- printf("transform_dis (%p): branch => %p\n", (void *) ctx->pc, (void *) dpc);
+ printf("transform_dis (0x%llx): branch => 0x%llx\n",
+ (unsigned long long) ctx->base.pc,
+ (unsigned long long) dpc);
#endif
if (dpc >= ctx->pc_patch_start && dpc < ctx->pc_patch_end) {
ctx->err = SUBSTITUTE_ERR_FUNC_BAD_INSN_AT_START;
@@ -33,9 +35,9 @@ void transform_dis_branch(struct transform_dis_ctx *ctx, uint_tptr dpc, int cc)
int icc = (cc & 0xf) ^ 1;
Bccrel(codep, icc, 4 + mov_br_size);
} else if ((cc & CC_XBXZ) == CC_XBXZ) {
- ctx->modify = true;
- ctx->newval[0] = ctx->pc + 4 + mov_br_size;
- ctx->newval[1] = 1; /* do invert */
+ ctx->base.modify = true;
+ ctx->base.newval[0] = ctx->base.pc + 4 + mov_br_size;
+ ctx->base.newval[1] = 1; /* do invert */
ctx->write_newop_here = *codep; *codep += 4;
}
int reg = arm64_get_unwritten_temp_reg(&ctx->arch);
@@ -45,7 +47,7 @@ void transform_dis_branch(struct transform_dis_ctx *ctx, uint_tptr dpc, int cc)
static void transform_dis_pre_dis(UNUSED struct transform_dis_ctx *ctx) {}
static void transform_dis_post_dis(struct transform_dis_ctx *ctx) {
- uint32_t op = ctx->op;
+ uint32_t op = ctx->base.op;
ctx->arch.regs_possibly_written |= op & 31;
ctx->arch.regs_possibly_written |= op >> 10 & 31;
ctx->arch.regs_possibly_written |= op >> 16 & 31;
diff --git a/lib/transform-dis.c b/lib/transform-dis.c
index 8f89fb3..fe7482d 100644
--- a/lib/transform-dis.c
+++ b/lib/transform-dis.c
@@ -44,7 +44,8 @@ void transform_dis_ret(struct transform_dis_ctx *ctx) {
static INLINE UNUSED
void transform_dis_unidentified(UNUSED struct transform_dis_ctx *ctx) {
#ifdef TRANSFORM_DIS_VERBOSE
- printf("transform_dis (%p): unidentified\n", (void *) ctx->base.pc);
+ printf("transform_dis (0x%llx): unidentified\n",
+ (unsigned long long) ctx->base.pc);
#endif
/* this isn't exhaustive, so unidentified is fine */
}