6 #include "../../../asm/arch/sh/regs.h"
25 #define SH_U_ADDR(x) UN(SH_ADDR_SIZE, x)
26 #define SH_S_ADDR(x) SN(SH_ADDR_SIZE, x)
27 #define SH_U_REG(x) UN(SH_REG_SIZE, (x))
28 #define SH_S_REG(x) SN(SH_REG_SIZE, (x))
29 #define SH_BIT(x) UN(1, x)
30 #define SH_TRUE SH_U_REG(1)
31 #define SH_FALSE SH_U_REG(0)
33 #define sh_il_get_pure_param(x) \
34 sh_il_get_param(op->param[x], op->scaling).pure
36 #define sh_il_set_pure_param(x, val) \
37 sh_il_set_param(op->param[x], val, op->scaling)
39 #define sh_il_get_effective_addr_param(x) \
40 sh_il_get_effective_addr(op->param[x], op->scaling)
56 "r0",
"r1",
"r2",
"r3",
"r4",
"r5",
"r6",
"r7",
57 "r0b",
"r1b",
"r2b",
"r3b",
"r4b",
"r5b",
"r6b",
"r7b",
58 "r8",
"r9",
"r10",
"r11",
"r12",
"r13",
"r14",
"r15",
"sr",
59 SH_SR_T,
SH_SR_S,
SH_SR_I,
SH_SR_I,
SH_SR_Q,
SH_SR_M,
SH_SR_F,
SH_SR_B,
SH_SR_R,
SH_SR_D,
60 "gbr",
"ssr",
"spc",
"sgr",
"dbr",
"vbr",
"mach",
"macl",
"pr"
182 return SEQ2(sreg, eff);
207 ctx->privilege_check =
true;
209 return VARL(
"_priv");
212 #define sh_il_get_privilege() sh_il_get_privilege_ctx(ctx)
234 #define sh_il_get_reg(reg) sh_il_get_reg_ctx(reg, ctx)
256 #define sh_il_set_reg(reg, val) sh_il_set_reg_ctx(reg, val, ctx)
277 return (
num << 4) >> 4;
290 switch (param.
mode) {
325 RZ_LOG_WARN(
"RzIL: SuperH: No effective address for this mode: %u\n", param.
mode);
331 #define sh_il_get_effective_addr(x, y) sh_il_get_effective_addr_pc_ctx(x, y, pc, ctx)
355 switch (param.
mode) {
388 RZ_LOG_ERROR(
"RzIL: SuperH: Invalid addressing mode\n");
394 #define sh_il_get_param(x, y) sh_il_get_param_pc_ctx(x, y, pc, ctx)
419 target =
SEQ2(pre, target);
442 switch (param.
mode) {
470 RZ_LOG_ERROR(
"RzIL: SuperH: Cannot set value for addressing mode: %u\n", param.
mode);
486 #define sh_il_set_param(x, y, z) sh_il_set_param_pc_ctx(x, y, z, pc, ctx)
705 return SEQ3(local_sum, tbit, ret);
720 return SEQ3(local_sum, tbit, ret);
825 ret =
SEQ4(ret, op1, op2, old_q);
830 ret =
SEQ3(ret, q, op2);
840 ret =
SEQ3(ret, q, t);
845 ret =
SEQ4(ret, rn, q, t);
860 return SEQ3(setq, setm, sett);
881 return SEQ3(eff,
SETG(
"macl", lower_bits),
SETG(
"mach", higher_bits));
893 return SEQ3(eff,
SETG(
"macl", lower_bits),
SETG(
"mach", higher_bits));
966 eff =
SEQ7(eff, mac,
mul,
add,
SETG(
"macl", lower_bits), higher_bits,
BRANCH(
VARG(
SH_SR_S),
SETG(
"mach",
LOGAND(
VARL(
"high"),
SH_U_REG(0xffff))),
SETG(
"mach",
VARL(
"high"))));
978 eff =
SEQ6(eff, mac,
mul,
add, lower_bits,
BRANCH(
VARG(
SH_SR_S),
SETG(
"macl",
VARL(
"low")),
SEQ2(
SETG(
"macl",
VARL(
"low")),
SETG(
"mach", higher_bits))));
1060 return SEQ3(local_dif, ret, tbit);
1074 return SEQ3(local_dif, ret, tbit);
1502 ctx->use_banked =
false;
1504 ctx->use_banked =
true;
1619 ctx->use_banked =
false;
1621 ctx->use_banked =
true;
1654 RZ_LOG_WARN(
"SuperH: Instruction with opcode 0x%04x is unimplemented\n",
op->opcode);
1770 if (
ctx &&
ctx->privilege_check) {
1774 aop->il_op = lifted;
RZ_API RZ_OWN RzAnalysisILConfig * rz_analysis_il_config_new(ut32 pc_size, bool big_endian, ut32 mem_key_size)
static RzILOpEffect * mul(cs_insn *insn, bool is_thumb)
RZ_API RZ_OWN RzILOpBitVector * rz_il_op_new_cast(ut32 length, RZ_NONNULL RzILOpBool *fill, RZ_NONNULL RzILOpBitVector *val)
op structure for casting bitv
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *data, char *str, int len)
static const char * sh_registers[]
#define rz_return_val_if_fail(expr, val)
Syntax Macros for RzIL Lifting.
#define STOREW(addr, val)
#define SEQ4(e0, e1, e2, e3)
#define SEQ7(e0, e1, e2, e3, e4, e5, e6)
#define SEQ6(e0, e1, e2, e3, e4, e5)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
#define SH_SR_R
SR.RB: General register bank specifier in privileged mode (set to 1 by a reset, exception or interrup...
enum sh_scaling_t SHScaling
#define SH_SR_M
SR.M: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions)
#define SH_SR_B
SR.BL: Exception/interrupt block bit (set to 1 by a reset, exception, or interrupt)
#define SH_SR_T
SR.T: True/False condition or carry/borrow bit.
#define SH_SR_D
SR.MD: Processor mode.
static const ut8 sh_scaling_size[]
#define SH_BANKED_REG_COUNT
#define SH_SR_I
SR.I: Interrupt mask level: External interrupts of a lower level than IMASK are masked.
#define SH_SR_Q
SR.Q: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions)
#define SH_SR_F
SR.FD: FPU disable bit (cleared to 0 by a reset)
#define SH_SR_S
SR.S: Specifies a saturation operation for a MAC instruction.
@ SH_IMM_S
8-bit immediate value (sign-extended)
@ SH_REG_INDIRECT_DISP
register indirect with displacement
@ SH_REG_INDIRECT_INDEXED
indexed register indirect
@ SH_REG_INDIRECT_I
register indirect with post-increment
@ SH_IMM_U
8-bit immediate value (zero-extended)
@ SH_REG_INDIRECT_D
register indirect with pre-decrement
@ SH_GBR_INDIRECT_INDEXED
#define sh_il_get_privilege()
static RzILOpEffect * sh_il_rotr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_invalid(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_sleep(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpPure * sh_il_get_status_reg()
Return the status register (sr), calculated by shifting all the status register bits at the correct o...
static bool sh_valid_gpr(ut16 reg)
static RzILOpEffect * sh_il_addc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shad(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_movt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shar(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_add(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpPure * sh_il_get_effective_addr_pc_ctx(SHParam param, SHScaling scaling, ut64 pc, SHILContext *ctx)
Get the effective address obtained from the given param and scaling.
static RzILOpEffect * sh_il_mov(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_movca(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpBitVector * sh_il_get_status_reg_bit(const char *bit)
We need this because sometimes we would want an RzILOpBitvector back when we ask for a status reg bit...
RZ_IPI bool rz_sh_il_opcode(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisOp *aop, ut64 pc, RZ_BORROW RZ_NONNULL const SHOp *op, RZ_NULLABLE SHILContext *ctx)
Store the lifted IL for op in aop This function also takes care of initializing and adding the privil...
static RzILOpEffect * sh_il_div0u(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bra(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
RzILOpEffect * sh_il_signed(unsigned int len, RZ_OWN RzILOpPure *val, const char *cast_var, const char *temp_var)
Cast val to len bits This uses a local temp variable temp_var to store the value val and then casts t...
static RzILOpEffect * sh_il_shll16(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpBool * sh_il_is_add_overflow(RZ_OWN RzILOpPure *res, RZ_OWN RzILOpPure *x, RZ_OWN RzILOpPure *y)
Check if there was a overflow in the addition of x and y to get res Here res = x + y.
static RzILOpEffect * sh_il_set_reg_ctx(ut16 reg, RZ_OWN RzILOpPure *val, SHILContext *ctx)
Set the value of the register corresponding to index reg to value val This function is smart enough t...
static RzILOpEffect * sh_il_subc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_jsr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_ldc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_extu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_mac(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_addv(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpBool * sh_il_is_sub_borrow(RZ_OWN RzILOpPure *res, RZ_OWN RzILOpPure *x, RZ_OWN RzILOpPure *y)
Check if there was a borrow in the subtraction of x and y to get res Here res = x - y (- 1,...
static RzILOpEffect * sh_il_div1(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_sets(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bfs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_unimpl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Unimplemented instruction/opcode To be used for valid SuperH-4 instruction which yet haven't been lif...
static RzILOpEffect * sh_il_cmp_gt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_pz(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_negc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_eq(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_clrmac(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_pl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define sh_il_get_reg(reg)
static RzILOpEffect * sh_il_lds(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpPure * sh_il_get_privilege_ctx(SHILContext *ctx)
Get the privilege mode Do NOT call this before initializing privilege through sh_il_initialize_privil...
static RzILOpEffect * sh_il_dt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_tst(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_set_status_reg(RZ_OWN RzILOpPure *val)
Set the value of the status register (sr) to val by setting the values of the individual status regis...
static RzILOpEffect * sh_il_clrs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static const sh_il_op sh_ops[SH_OP_SIZE]
Lookup table for the IL lifting handlers for the various instructions.
static RzILOpEffect * sh_il_sts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_mulu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_sub(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpBitVector * sh_il_bool_to_bv(RzILOpBool *b)
Convert b to SH_TRUE or SH_FALSE (bool zero-extended to SH_REG_SIZE)
static RzILOpEffect * sh_il_sett(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static const char * sh_global_registers[]
static RzILOpPure * sh_il_get_reg_ctx(ut16 reg, SHILContext *ctx)
Get register corresponding to reg index This function is smart enough to give the correct register in...
static bool sh_banked_reg(ut16 reg)
RzILOpEffect *(* sh_il_op)(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define sh_il_get_effective_addr(x, y)
st16 convert_to_st12(ut16 num)
Convert an unsigned 12 bit num to signed 12 bit num I have used 16 bits to represent the numbers invo...
static RzILOpEffect * sh_il_stc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_hi(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_tas(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shlr16(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_hs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_exts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shll8(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_dmulu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_muls(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_xtrct(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shal(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_swap(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shlr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bsr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_rotcr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_rotcl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_mul(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_str(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_or(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_not(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shll2(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_cmp_ge(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shld(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shll(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_initialize_privilege()
Set the value of the local variable "_priv" This exists so that the privilege mode IL doesn't have to...
static RzILOpEffect * sh_il_xor(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define sh_il_get_effective_addr_param(x)
#define sh_il_get_pure_param(x)
static RzILOpBool * sh_il_is_add_carry(RZ_OWN RzILOpPure *res, RZ_OWN RzILOpPure *x, RZ_OWN RzILOpPure *y)
Check if there was a carry in the addition of x and y to get res Here res = x + y (+ 1,...
static RzILOpEffect * sh_il_shlr8(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_div0s(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_apply_effects(RZ_NULLABLE RzILOpEffect *target, RZ_NULLABLE RzILOpEffect *pre, RZ_NULLABLE RzILOpEffect *post)
Apply the effects in order: pre, target, post The good thing about this function is that any of the a...
static RzILOpEffect * sh_il_rts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define sh_il_get_param(x, y)
static RzILOpEffect * sh_il_subv(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static const char * sh_get_banked_reg(ut16 reg, ut8 bank)
Get the register name for reg in bank bank.
#define sh_il_set_param(x, y, z)
RZ_IPI RzAnalysisILConfig * rz_sh_il_config(RZ_NONNULL RzAnalysis *analysis)
Initialize new config for the SuperH IL.
static RzILOpEffect * sh_il_nop(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_neg(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpBool * sh_il_is_sub_underflow(RZ_OWN RzILOpPure *res, RZ_OWN RzILOpPure *x, RZ_OWN RzILOpPure *y)
Check if there was a underflow in the subtraction of x and y to get res Here res = x - y.
struct sh_param_helper_t SHParamHelper
Helper struct to take care of converting operands to IL.
static RzILOpEffect * sh_il_rotl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_shlr2(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_set_param_pc_ctx(SHParam param, RZ_OWN RzILOpPure *val, SHScaling scaling, ut64 pc, SHILContext *ctx)
Set the value of the param at scaling to val This function is smart enough to also apply any effects ...
static RzILOpEffect * sh_il_and(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define sh_il_set_pure_param(x, val)
static RzILOpEffect * sh_il_clrt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define sh_il_set_reg(reg, val)
static RzILOpEffect * sh_il_braf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_dmuls(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static SHParamHelper sh_il_get_param_pc_ctx(SHParam param, SHScaling scaling, ut64 pc, SHILContext *ctx)
Convert the param with scaling to it's IL representation.
static RzILOpEffect * sh_il_rte(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_bsrf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
static RzILOpEffect * sh_il_jmp(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
#define cond(bop, top, mask, flags)
Description of the global context of an RzAnalysisILVM.
An IL op performing a pure computation, 'a pure.
To store the context of the IL lifter ; Used to pass around information outside effects Other context...
Helper struct to take care of converting operands to IL.
RzILOpEffect * post
post effect for the operand
RzILOpPure * pure
pure effect for the operand
RzILOpEffect * pre
pre effect for the operand
static void post(QUEUE *q, enum uv__work_kind kind)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()