aboutsummaryrefslogtreecommitdiff
path: root/lib/transform-dis.inc.h
diff options
context:
space:
mode:
authorcomex2015-01-12 01:21:43 -0500
committercomex2015-01-12 01:22:20 -0500
commit21277f290a705c6382453f348e4a224cd7695320 (patch)
treeb3eac4e66f7aec0dede880e7405171c413497a68 /lib/transform-dis.inc.h
parentminor improvements (diff)
downloadsubstitute-21277f290a705c6382453f348e4a224cd7695320.tar.gz
these functions are actually pointless, since it's easier to change the *offset* for actual pc-rel loads (and the rest are accounted for, albeit implicitly in the case of add pc)
i might end up using the stack :/
Diffstat (limited to '')
-rw-r--r--lib/transform-dis.inc.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/transform-dis.inc.h b/lib/transform-dis.inc.h
new file mode 100644
index 0000000..6889127
--- /dev/null
+++ b/lib/transform-dis.inc.h
@@ -0,0 +1,55 @@
+typedef struct {
+ bool modify;
+} tdis_ret;
+typedef struct tc {
+ uintptr_t pc;
+ int op_size;
+ uint32_t op;
+ uint32_t newop;
+ uint32_t newval[4];
+ uintptr_t pc_patch_start;
+ uintptr_t pc_patch_end;
+ bool got_bad;
+
+} *tdis_ctx;
+
+NOINLINE UNUSED
+static tdis_ret P_data(struct tc *ctx, unsigned o0, unsigned o1, unsigned o2, unsigned o3, unsigned out_mask) {
+ __builtin_abort();
+}
+
+NOINLINE UNUSED
+static tdis_ret P_pcrel(struct tc *ctx, uintptr_t dpc, unsigned reg, bool is_load) {
+ __builtin_abort();
+}
+
+NOINLINE UNUSED
+static tdis_ret P_ret(struct tc *ctx) {
+ /* ret is okay if it's at the end of the patch */
+ if (ctx->pc + op_size < ctx->pc_patch_end)
+ ctx->got_bad = true;
+ printf("ret: %08x\n", ctx->op);
+ return (tdis_ret) {false};
+}
+
+NOINLINE UNUSED
+static tdis_ret P_branch(struct tc *ctx, uintptr_t dpc) {
+ if (dpc >= ctx->pc_patch_start && dpc < ctx->pc_patch_end) {
+ /* don't support this for now */
+ ctx->got_bad = true;
+ }
+ return (tdis_ret) {false};
+}
+
+NOINLINE UNUSED
+static tdis_ret P_unidentified(struct tc *ctx) {
+ return (tdis_ret) {false};
+}
+
+NOINLINE UNUSED
+static tdis_ret P_bad(struct tc *ctx) {
+ ctx->got_bad = true;
+ return (tdis_ret) {false};
+}
+
+#define P(x) transform_dis_##x