diff options
author | Yifan Lu | 2016-11-23 14:34:33 -0600 |
---|---|---|
committer | Yifan Lu | 2016-11-23 14:34:33 -0600 |
commit | bd5ebb7a0a4e102731de72832f3e12e9f54d541a (patch) | |
tree | bef4f637a270d3f7d2551ac74a89e6b4bad8adec /lib/arm/assemble.h | |
parent | Fixed proper encoding of PUSH (STMDB) as ARM manual was wrong... (diff) | |
parent | avoid UB (diff) | |
download | substitute-bd5ebb7a0a4e102731de72832f3e12e9f54d541a.tar.gz |
Merge branch 'master' of https://github.com/comex/substitute
Diffstat (limited to 'lib/arm/assemble.h')
-rw-r--r-- | lib/arm/assemble.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/arm/assemble.h b/lib/arm/assemble.h index 1baeb0f..3066802 100644 --- a/lib/arm/assemble.h +++ b/lib/arm/assemble.h @@ -3,11 +3,16 @@ struct assemble_ctx { void **codep; - uint_tptr pc; + void *code_base; + uint_tptr pc_of_code_base; bool thumb; int cond; }; +static inline uint_tptr actx_pc(struct assemble_ctx ctx) { + return ctx.pc_of_code_base + (*ctx.codep - ctx.code_base); +} + static inline void PUSHone(struct assemble_ctx ctx, int Rt) { if (ctx.thumb) op32(ctx.codep, 0x0d04f84d | Rt << 28); @@ -70,7 +75,7 @@ static inline void LDRxi(struct assemble_ctx ctx, int Rt, int Rn, uint32_t off, case PLM_U16: subop = 1; sign = 0; break; case PLM_S16: subop = 1; sign = 1; break; case PLM_U32: subop = 2; sign = 0; break; - default: __builtin_abort(); + default: substitute_assert(false); } op32(ctx.codep, 0x0000f890 | Rn | Rt << 28 | subop << 5 | sign << 8 | off << 16); @@ -92,11 +97,18 @@ static inline void LDRxi(struct assemble_ctx ctx, int Rt, int Rn, uint32_t off, ctx.cond << 28); break; default: - __builtin_abort(); + substitute_assert(false); } } } +static inline void BLXr(struct assemble_ctx ctx, int Rm) { + if (ctx.thumb) + op16(ctx.codep, 0x4780 | Rm << 3); + else + op32(ctx.codep, 0xe12fff30 | Rm | ctx.cond << 28); +} + static inline void Bccrel(struct assemble_ctx ctx, int offset) { if (ctx.thumb) { offset = (offset - 4) / 2; @@ -108,7 +120,7 @@ static inline void Bccrel(struct assemble_ctx ctx, int offset) { } static inline void LDR_PC(struct assemble_ctx ctx, uint32_t dpc) { - if (ctx.pc & 2) + if (actx_pc(ctx) & 2) op16(ctx.codep, 0xbf00); if (ctx.thumb) op32(ctx.codep, 0xf000f8df); |