aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dis-arm.inc.h99
-rw-r--r--lib/dis.h37
2 files changed, 78 insertions, 58 deletions
diff --git a/lib/dis-arm.inc.h b/lib/dis-arm.inc.h
index fe5c45b..2785725 100644
--- a/lib/dis-arm.inc.h
+++ b/lib/dis-arm.inc.h
@@ -1,151 +1,144 @@
#include "dis.h"
-#define r(nn) {.n = nn, .out = false}
-#define rs(nn, l, s) {.n = bs_slice(nn, l, s), .out = false}
-#define rout(nn) {.n = nn, .out = true}
-#define rsout(nn, l, s) {.n = bs_slice(nn, l, s), .out = true}
-#define data(...) \
- struct dis_data_operand ops[] = {__VA_ARGS__}; \
- return P(data)(ctx, ops, sizeof(ops)/sizeof(*ops));
-
-static tdis_ret P(GPRPairOp_Rt_addr_offset_none_addr_S_2_STLEXD)(tdis_ctx ctx, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(GPRPairOp_Rt_addr_offset_none_addr_S_2_STLEXD)(tdis_ctx ctx, struct bitslice Rt, struct bitslice addr) {
data(r(Rt), r(addr));
}
-static tdis_ret P(GPR_Rm_unk_Rd_1_MOVr)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rd) {
+static INLINE tdis_ret P(GPR_Rm_unk_Rd_1_MOVr)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rd) {
data(rout(Rd), r(Rm));
}
-static tdis_ret P(GPR_Rn_GPR_Rm_unk_Rd_1_ADDrr)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rd, struct bitslice Rn) {
+static INLINE tdis_ret P(GPR_Rn_GPR_Rm_unk_Rd_1_ADDrr)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rd, struct bitslice Rn) {
data(rout(Rd), r(Rm), r(Rn));
}
-static tdis_ret P(GPR_Rn_so_reg_imm_shift_unk_Rd_1_ADDrsi)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rd, struct bitslice Rn) {
+static INLINE tdis_ret P(GPR_Rn_so_reg_imm_shift_unk_Rd_1_ADDrsi)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rd, struct bitslice Rn) {
data(rs(shift, 0, 4), r(Rn), rout(Rd));
}
-static tdis_ret P(GPR_Rn_so_reg_reg_shift_unk_Rd_1_ADDrsr)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rd, struct bitslice Rn) {
+static INLINE tdis_ret P(GPR_Rn_so_reg_reg_shift_unk_Rd_1_ADDrsr)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rd, struct bitslice Rn) {
data(rs(shift, 0, 4), rs(shift, 8, 4), r(Rn), rout(Rd));
}
-static tdis_ret P(GPR_Rn_unk_Rd_1_ADDri)(tdis_ctx ctx, struct bitslice Rd, struct bitslice Rn) {
+static INLINE tdis_ret P(GPR_Rn_unk_Rd_1_ADDri)(tdis_ctx ctx, struct bitslice Rd, struct bitslice Rn) {
data(rout(Rd), r(Rn));
}
-static tdis_ret P(GPR_Rt_4_MCR)(tdis_ctx ctx, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_4_MCR)(tdis_ctx ctx, struct bitslice Rt) {
data(r(Rt));
}
-static tdis_ret P(GPR_Rt_addr_offset_none_addr_S_10_STL)(tdis_ctx ctx, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(GPR_Rt_addr_offset_none_addr_S_10_STL)(tdis_ctx ctx, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rout(Rt));
}
-static tdis_ret P(GPR_Rt_addr_offset_none_addr_am2offset_imm_offset_S_4_STRBT_POST_IMM)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(GPR_Rt_addr_offset_none_addr_am2offset_imm_offset_S_4_STRBT_POST_IMM)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), r(Rt));
}
-static tdis_ret P(GPR_Rt_addr_offset_none_addr_am2offset_reg_offset_S_4_STRBT_POST_REG)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(GPR_Rt_addr_offset_none_addr_am2offset_reg_offset_S_4_STRBT_POST_REG)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rs(offset, 0, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_addr_offset_none_addr_am3offset_offset_S_2_STRD_POST)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(GPR_Rt_addr_offset_none_addr_am3offset_offset_S_2_STRD_POST)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rs(offset, 0, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_addr_offset_none_addr_postidx_imm8_offset_S_1_STRHTi)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(GPR_Rt_addr_offset_none_addr_postidx_imm8_offset_S_1_STRHTi)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), r(Rt));
}
-static tdis_ret P(GPR_Rt_addrmode3_addr_S_2_STRD)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_addrmode3_addr_S_2_STRD)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 9, 4), rs(addr, 0, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_addrmode3_pre_addr_S_2_STRD_PRE)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_addrmode3_pre_addr_S_2_STRD_PRE)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 9, 4), rs(addr, 0, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_addrmode_imm12_addr_S_1_STRi12)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_addrmode_imm12_addr_S_1_STRi12)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 13, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_addrmode_imm12_pre_addr_S_2_STRB_PRE_IMM)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_addrmode_imm12_pre_addr_S_2_STRB_PRE_IMM)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 13, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_ldst_so_reg_addr_S_2_STRB_PRE_REG)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_ldst_so_reg_addr_S_2_STRB_PRE_REG)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 0, 4), rs(addr, 13, 4), r(Rt));
}
-static tdis_ret P(GPR_Rt_ldst_so_reg_shift_S_1_STRrs)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rt) {
+static INLINE tdis_ret P(GPR_Rt_ldst_so_reg_shift_S_1_STRrs)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rt) {
data(rs(shift, 0, 4), rs(shift, 13, 4), r(Rt));
}
-static tdis_ret P(GPRnopc_Rt_4_MCRR)(tdis_ctx ctx, UNUSED struct bitslice Rt) {
+static INLINE tdis_ret P(GPRnopc_Rt_4_MCRR)(tdis_ctx ctx, UNUSED struct bitslice Rt) {
// need Rt2 but whatever
return P(unidentified)(ctx);
}
-static tdis_ret P(GPRnopc_Rt_addrmode_imm12_addr_S_1_STRBi12)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(GPRnopc_Rt_addrmode_imm12_addr_S_1_STRBi12)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 13, 4), r(Rt));
}
-static tdis_ret P(GPRnopc_Rt_ldst_so_reg_shift_S_1_STRBrs)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rt) {
+static INLINE tdis_ret P(GPRnopc_Rt_ldst_so_reg_shift_S_1_STRBrs)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rt) {
data(rs(shift, 13, 4), rs(shift, 0, 4), r(Rt));
}
-static tdis_ret P(addr_offset_none_addr_4_LDC2L_OPTION)(tdis_ctx ctx, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_4_LDC2L_OPTION)(tdis_ctx ctx, struct bitslice addr) {
data(r(addr));
}
-static tdis_ret P(addr_offset_none_addr_S_4_STC2L_OPTION)(tdis_ctx ctx, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_S_4_STC2L_OPTION)(tdis_ctx ctx, struct bitslice addr) {
data(r(addr));
}
-static tdis_ret P(addr_offset_none_addr_am2offset_imm_offset_unk_Rt_4_LDRBT_POST_IMM)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_am2offset_imm_offset_unk_Rt_4_LDRBT_POST_IMM)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rout(Rt));
}
-static tdis_ret P(addr_offset_none_addr_am2offset_reg_offset_unk_Rt_4_LDRBT_POST_REG)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_am2offset_reg_offset_unk_Rt_4_LDRBT_POST_REG)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rs(offset, 0, 4), rout(Rt));
}
-static tdis_ret P(addr_offset_none_addr_am3offset_offset_unk_Rt_4_LDRD_POST)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_am3offset_offset_unk_Rt_4_LDRD_POST)(tdis_ctx ctx, struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rs(offset, 0, 4), rout(Rt));
}
-static tdis_ret P(addr_offset_none_addr_postidx_imm8_offset_unk_Rt_3_LDRHTi)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_postidx_imm8_offset_unk_Rt_3_LDRHTi)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rout(Rt));
}
-static tdis_ret P(addr_offset_none_addr_postidx_imm8s4_offset_4_LDC2L_POST)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_postidx_imm8s4_offset_4_LDC2L_POST)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice addr) {
data(r(addr));
}
-static tdis_ret P(addr_offset_none_addr_postidx_imm8s4_offset_S_4_STC2L_POST)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_postidx_imm8s4_offset_S_4_STC2L_POST)(tdis_ctx ctx, UNUSED struct bitslice offset, struct bitslice addr) {
data(r(addr));
}
-static tdis_ret P(addr_offset_none_addr_unk_Rt_16_LDA)(tdis_ctx ctx, struct bitslice Rt, struct bitslice addr) {
+static INLINE tdis_ret P(addr_offset_none_addr_unk_Rt_16_LDA)(tdis_ctx ctx, struct bitslice Rt, struct bitslice addr) {
data(r(addr), rout(Rt));
}
-static tdis_ret P(addrmode3_addr_unk_Rt_4_LDRD)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(addrmode3_addr_unk_Rt_4_LDRD)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rsout(addr, 9, 4), rs(addr, 0, 4), r(Rt));
}
-static tdis_ret P(addrmode3_pre_addr_unk_Rt_4_LDRD_PRE)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(addrmode3_pre_addr_unk_Rt_4_LDRD_PRE)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rsout(addr, 9, 4), rs(addr, 0, 4), r(Rt));
}
-static tdis_ret P(addrmode5_addr_8_LDC2L_OFFSET)(tdis_ctx ctx, struct bitslice addr) {
+static INLINE tdis_ret P(addrmode5_addr_8_LDC2L_OFFSET)(tdis_ctx ctx, struct bitslice addr) {
data(rsout(addr, 9, 4));
}
-static tdis_ret P(addrmode5_addr_S_4_STC2L_OFFSET)(tdis_ctx ctx, struct bitslice addr) {
+static INLINE tdis_ret P(addrmode5_addr_S_4_STC2L_OFFSET)(tdis_ctx ctx, struct bitslice addr) {
data(rs(addr, 9, 4));
}
-static tdis_ret P(addrmode5_pre_addr_4_LDC2L_PRE)(tdis_ctx ctx, struct bitslice addr) {
+static INLINE tdis_ret P(addrmode5_pre_addr_4_LDC2L_PRE)(tdis_ctx ctx, struct bitslice addr) {
data(rs(addr, 9, 4));
}
-static tdis_ret P(addrmode5_pre_addr_S_4_STC2L_PRE)(tdis_ctx ctx, struct bitslice addr) {
+static INLINE tdis_ret P(addrmode5_pre_addr_S_4_STC2L_PRE)(tdis_ctx ctx, struct bitslice addr) {
data(rs(addr, 9, 4));
}
-static tdis_ret P(addrmode_imm12_addr_unk_Rt_2_LDRBi12)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(addrmode_imm12_addr_unk_Rt_2_LDRBi12)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 13, 4), rout(Rt));
}
-static tdis_ret P(addrmode_imm12_pre_addr_unk_Rt_2_LDRB_PRE_IMM)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(addrmode_imm12_pre_addr_unk_Rt_2_LDRB_PRE_IMM)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 13, 4), rout(Rt));
}
-static tdis_ret P(adrlabel_label_1_ADR)(tdis_ctx ctx, struct bitslice label) {
+static INLINE tdis_ret P(adrlabel_label_1_ADR)(tdis_ctx ctx, struct bitslice label) {
return P(adr)(ctx, ctx->pc + 8 + bs_get(label, ctx->op));
}
-static tdis_ret P(br_target_target_B_1_Bcc)(tdis_ctx ctx, struct bitslice target) {
+static INLINE tdis_ret P(br_target_target_B_1_Bcc)(tdis_ctx ctx, struct bitslice target) {
return P(branch)(ctx, ctx->pc + 8 + sext(bs_get(target, ctx->op), 24));
}
-static tdis_ret P(ldst_so_reg_addr_unk_Rt_2_LDRB_PRE_REG)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
+static INLINE tdis_ret P(ldst_so_reg_addr_unk_Rt_2_LDRB_PRE_REG)(tdis_ctx ctx, struct bitslice addr, struct bitslice Rt) {
data(rs(addr, 0, 4), rs(addr, 13, 4), rout(Rt));
}
-static tdis_ret P(ldst_so_reg_shift_unk_Rt_2_LDRBrs)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rt) {
+static INLINE tdis_ret P(ldst_so_reg_shift_unk_Rt_2_LDRBrs)(tdis_ctx ctx, struct bitslice shift, struct bitslice Rt) {
data(rs(shift, 0, 4), rs(shift, 13, 4), rout(Rt));
}
-static tdis_ret P(tcGPR_Rm_unk_Rd_1_MOVr_TC)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rd) {
+static INLINE tdis_ret P(tcGPR_Rm_unk_Rd_1_MOVr_TC)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rd) {
data(rout(Rd), r(Rm));
}
-static tdis_ret P(unk_Rd_5_MOVTi16)(tdis_ctx ctx, struct bitslice Rd) {
+static INLINE tdis_ret P(unk_Rd_5_MOVTi16)(tdis_ctx ctx, struct bitslice Rd) {
data(rout(Rd));
}
-static inline tdis_ret P(unk_Rt_13_MRC)(tdis_ctx ctx, struct bitslice Rt) {
+static INLINE tdis_ret P(unk_Rt_13_MRC)(tdis_ctx ctx, struct bitslice Rt) {
data(rout(Rt));
}
static tdis_ret P(dis_arm)(tdis_ctx ctx) {
unsigned op = ctx->op;
#include "../generated/transform-dis-arm.inc.h"
+ __builtin_abort();
}
diff --git a/lib/dis.h b/lib/dis.h
index a45e5d0..fc7e71b 100644
--- a/lib/dis.h
+++ b/lib/dis.h
@@ -2,6 +2,7 @@
#include <stdbool.h>
#define UNUSED __attribute__((unused))
+#define INLINE inline __attribute__((always_inline))
struct bitslice_run {
int inpos, outpos, len;
@@ -12,11 +13,6 @@ struct bitslice {
const struct bitslice_run *runs;
};
-struct dis_data_operand {
- struct bitslice n;
- bool out;
-};
-
static inline int sext(unsigned val, int bits) {
return val & (1 << (bits - 1)) ? ((int)val - (1 << bits)) : (int)val;
}
@@ -61,3 +57,34 @@ static inline struct bitslice bs_slice_(struct bitslice bs, struct bitslice_run
#define bs_slice(bs, lo, size) \
bs_slice_(bs, alloca((bs).nruns * sizeof(struct bitslice_run)), lo, size)
+struct operand_internal {
+ struct bitslice n;
+ bool out;
+ bool valid;
+};
+
+#define r(nn) {.n = nn, .out = false, .valid = true}
+#define rs(nn, l, s) {.n = bs_slice(nn, l, s), .out = false, .valid = true}
+#define rout(nn) {.n = nn, .out = true, .valid = true}
+#define rsout(nn, l, s) {.n = bs_slice(nn, l, s), .out = true, .valid = true}
+#define data(...) \
+ struct operand_internal ops[4] = {__VA_ARGS__}; \
+ tdis_ret ret = P(data)(ctx, \
+ ops[0].valid ? bs_get(ops[0].n, ctx->op) : -1u, \
+ ops[1].valid ? bs_get(ops[1].n, ctx->op) : -1u, \
+ ops[2].valid ? bs_get(ops[2].n, ctx->op) : -1u, \
+ ops[3].valid ? bs_get(ops[3].n, ctx->op) : -1u, \
+ (ops[0].valid << 0) | \
+ (ops[1].valid << 1) | \
+ (ops[2].valid << 2) | \
+ (ops[3].valid << 3)); \
+ if(ret.modify) { \
+ unsigned new = ctx->op; \
+ new = bs_set(ops[0].n, ctx->newval[0], new); \
+ new = bs_set(ops[1].n, ctx->newval[1], new); \
+ new = bs_set(ops[2].n, ctx->newval[2], new); \
+ new = bs_set(ops[3].n, ctx->newval[3], new); \
+ ctx->newop = new; \
+ } \
+ return ret;
+