diff options
author | comex | 2015-01-10 22:44:55 -0500 |
---|---|---|
committer | comex | 2015-01-10 22:44:55 -0500 |
commit | 102a7371f0a19ee5569d1cd2e8761d7ab3fec75b (patch) | |
tree | 6e0f718543fde994a8f727b08a6cabfcb7122fae /lib | |
parent | add licensing (diff) | |
download | substitute-102a7371f0a19ee5569d1cd2e8761d7ab3fec75b.tar.gz |
...
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dis-arm.inc | 36 | ||||
-rw-r--r-- | lib/dis.h | 47 |
2 files changed, 83 insertions, 0 deletions
diff --git a/lib/dis-arm.inc b/lib/dis-arm.inc new file mode 100644 index 0000000..37581a3 --- /dev/null +++ b/lib/dis-arm.inc @@ -0,0 +1,36 @@ +static inline tdis_ret P(addr_offset_none_addr_33_STC2L_OPTION)(tdis_ctx ctx, struct bitslice addr) {} +static inline tdis_ret P(GPR_Rn_GPR_Rm_1_ADDrr)(tdis_ctx ctx, struct bitslice Rm, struct bitslice Rn) { + + return P(regs)(ctx, Rm, 0, 4, Rn, 0, 4); +} +static inline tdis_ret P(GPR_Rn_3_ADDri)(tdis_ctx ctx, struct bitslice Rn) { + return P(regs)(ctx, Rn, 0, 4, Rn, 0, 0); +} +static inline tdis_ret P(addrmode3_addr_2_STRD)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 9, 4, addr, 0, 4); +} +static inline tdis_ret P(addrmode3_pre_addr_2_STRD_PRE)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 9, 4, addr, 0, 4); +} +static inline tdis_ret P(addrmode_imm12_addr_2_STRBi12)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 13, 4, addr, 0, 0); +} +static inline tdis_ret P(addrmode_imm12_pre_addr_2_STRB_PRE_IMM)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 13, 4, addr, 0, 0); +} +static inline tdis_ret P(addrmode5_addr_8_STC2L_OFFSET)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 9, 4, addr, 0, 0); +} +static inline tdis_ret P(addrmode5_pre_addr_4_STC2L_PRE)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 9, 4, addr, 0, 0); +} +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 inline tdis_ret P(br_target_target_1_Bcc)(tdis_ctx ctx, struct bitslice target) { + return P(branch)(ctx, ctx->pc + 8 + sext(bs_get(target, ctx->op), 24)); +} +static inline tdis_ret P(ldst_so_reg_addr_2_STRB_PRE_REG)(tdis_ctx ctx, struct bitslice addr) { + return P(regs)(ctx, addr, 13, 4, addr, 0, 4); +} + diff --git a/lib/dis.h b/lib/dis.h new file mode 100644 index 0000000..8063235 --- /dev/null +++ b/lib/dis.h @@ -0,0 +1,47 @@ +#pragma once + +static inline int sext(unsigned val, int bits) { + return val & (1 << (bits - 1)) ? ((int)val - (1 << bits)) : (int)val; +} + +struct bitslice_run { + int inpos, outpos, len; +}; + +struct bitslice { + int nruns; + const struct bitslice_run *runs; +}; + +__attribute__((always_inline)) +static inline unsigned bs_get(struct bitslice bs, unsigned op) { + unsigned ret = 0; + for(int i = 0; i < bs.nruns; i++) { + const struct bitslice_run *run = &bs.runs[i]; + unsigned masked = op & ((1 << run->len) - 1); + if (run->outpos < run->inpos) + masked >>= run->inpos - run->outpos; + else if (run->outpos > run->inpos) + masked <<= run->outpos - run->inpos; + ret |= masked; + } + return ret; +} + +__attribute__((always_inline)) +static inline unsigned bs_set(struct bitslice bs, unsigned val, unsigned op) { + for(int i = 0; i < bs.nruns; i++) { + const struct bitslice_run *run = &bs.runs[i]; + unsigned mask = (1 << run->len) - 1; + unsigned masked = val & mask; + if (run->outpos < run->inpos) { + masked <<= run->inpos - run->outpos; + mask <<= run->inpos - run->outpos; + } else if (run->outpos > run->inpos) { + masked >>= run->outpos - run->inpos; + mask >>= run->outpos - run->inpos; + } + op = (op & ~mask) | masked; + } + return op; +} |