Rizin
unix-like reverse engineering framework and cli tools
sh_il.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 Dhruv Maroo <dhruvmaru007@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include "sh_il.h"
6 #include "../../../asm/arch/sh/regs.h"
7 
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)
32 
33 #define sh_il_get_pure_param(x) \
34  sh_il_get_param(op->param[x], op->scaling).pure
35 
36 #define sh_il_set_pure_param(x, val) \
37  sh_il_set_param(op->param[x], val, op->scaling)
38 
39 #define sh_il_get_effective_addr_param(x) \
40  sh_il_get_effective_addr(op->param[x], op->scaling)
41 
42 /* Utilities */
43 
44 static bool sh_valid_gpr(ut16 reg) {
45  return reg < SH_GPR_COUNT;
46 }
47 
48 static bool sh_banked_reg(ut16 reg) {
49  return reg < SH_BANKED_REG_COUNT;
50 }
51 
55 static const char *sh_global_registers[] = {
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",
60  "gbr", "ssr", "spc", "sgr", "dbr", "vbr", "mach", "macl", "pr"
61 };
62 
82 RzILOpEffect *sh_il_signed(unsigned int len, RZ_OWN RzILOpPure *val, const char *cast_var, const char *temp_var) {
83  RzILOpEffect *init = SETL(temp_var, val);
84  RzILOpPure *cast = rz_il_op_new_cast(len, MSB(VARL(temp_var)), VARL(temp_var));
85  RzILOpEffect *set = SETL(cast_var, cast);
86 
87  return SEQ2(init, set);
88 }
89 
97 static const char *sh_get_banked_reg(ut16 reg, ut8 bank) {
98  if (!sh_banked_reg(reg) || bank > 1) {
99  return NULL;
100  }
102 }
103 
111  return ITE(b, SH_TRUE, SH_FALSE);
112 }
113 
123  return sh_il_bool_to_bv(VARG(bit));
124 }
125 
132  RzILOpPure *val = SH_U_REG(0);
134  val = SHIFTL0(val, SH_U_REG(1));
136  val = SHIFTL0(val, SH_U_REG(1));
138  val = SHIFTL0(val, SH_U_REG(13));
140  val = SHIFTL0(val, SH_U_REG(6));
142  val = SHIFTL0(val, SH_U_REG(1));
144  val = SHIFTL0(val, SH_U_REG(4));
145  // VARG(SH_SR_I) is of 4 bits
147  val = SHIFTL0(val, SH_U_REG(3));
149  val = SHIFTL0(val, SH_U_REG(1));
151 
152  return val;
153 }
154 
162  RzILOpEffect *sreg = SETL("_sreg", val);
163  RzILOpEffect *eff = SETG(SH_SR_T, LSB(VARL("_sreg")));
164 
165  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(1))));
166  eff = SEQ2(eff, SETG(SH_SR_S, LSB(VARL("_sreg"))));
167  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(3))));
168  eff = SEQ2(eff, SETG(SH_SR_I, LOGAND(UN(4, 0xf), UNSIGNED(4, VARL("_sreg")))));
169  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(4))));
170  eff = SEQ2(eff, SETG(SH_SR_Q, LSB(VARL("_sreg"))));
171  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(1))));
172  eff = SEQ2(eff, SETG(SH_SR_M, LSB(VARL("_sreg"))));
173  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(6))));
174  eff = SEQ2(eff, SETG(SH_SR_F, LSB(VARL("_sreg"))));
175  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(13))));
176  eff = SEQ2(eff, SETG(SH_SR_B, LSB(VARL("_sreg"))));
177  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(1))));
178  eff = SEQ2(eff, SETG(SH_SR_R, LSB(VARL("_sreg"))));
179  eff = SEQ2(eff, SETL("_sreg", SHIFTR0(VARL("_sreg"), SH_U_REG(1))));
180  eff = SEQ2(eff, SETG(SH_SR_D, LSB(VARL("_sreg"))));
181 
182  return SEQ2(sreg, eff);
183 }
184 
193  return SETL("_priv", AND(VARG(SH_SR_D), VARG(SH_SR_R)));
194 }
195 
206  if (ctx) {
207  ctx->privilege_check = true;
208  }
209  return VARL("_priv");
210 }
211 
212 #define sh_il_get_privilege() sh_il_get_privilege_ctx(ctx)
213 
223  if (!sh_banked_reg(reg) || !ctx->use_banked) {
224  if (reg == SH_REG_IND_SR) {
225  return sh_il_get_status_reg();
226  }
227  return VARG(sh_registers[reg]);
228  }
229 
230  // check if both SR.MD = 1 and SR.RB = 1
232 }
233 
234 #define sh_il_get_reg(reg) sh_il_get_reg_ctx(reg, ctx)
235 
246  if (!sh_banked_reg(reg) || !ctx->use_banked) {
247  if (reg == SH_REG_IND_SR) {
248  return sh_il_set_status_reg(val);
249  }
250  return SETG(sh_registers[reg], val);
251  }
252 
253  return SEQ2(SETL("_regv", val), BRANCH(sh_il_get_privilege(), SETG(sh_get_banked_reg(reg, 1), VARL("_regv")), SETG(sh_get_banked_reg(reg, 0), VARL("_regv"))));
254 }
255 
256 #define sh_il_set_reg(reg, val) sh_il_set_reg_ctx(reg, val, ctx)
257 
261 typedef struct sh_param_helper_t {
266 
277  return (num << 4) >> 4;
278 }
279 
290  switch (param.mode) {
291  case SH_REG_INDIRECT:
292  case SH_REG_INDIRECT_I:
293  case SH_REG_INDIRECT_D:
294  return sh_il_get_reg(param.param[0]);
296  return ADD(sh_il_get_reg(param.param[0]), MUL(SH_U_ADDR(param.param[1]), SH_U_ADDR(sh_scaling_size[scaling])));
298  return ADD(sh_il_get_reg(SH_REG_IND_R0), sh_il_get_reg(param.param[0]));
300  return ADD(VARG("gbr"), MUL(SH_U_ADDR(param.param[0]), SH_U_ADDR(sh_scaling_size[scaling])));
302  return ADD(VARG("gbr"), sh_il_get_reg(SH_REG_IND_R0));
303  case SH_PC_RELATIVE_DISP: {
304  RzILOpBitVector *pcbv = SH_U_ADDR(pc);
305  // mask lower 2 bits if long word
306  if (scaling == SH_SCALING_L) {
307  pcbv = LOGAND(pcbv, SH_U_ADDR(0xfffffffc));
308  }
309  pcbv = ADD(pcbv, SH_U_ADDR(4));
310  return ADD(pcbv, MUL(SH_U_ADDR(param.param[0]), SH_U_ADDR(sh_scaling_size[scaling])));
311  }
312  case SH_PC_RELATIVE8: {
313  // sign-extended for 8 bits and shifted left by 1 (i.e. multiplied by 2)
314  RzILOpBitVector *relative = SHIFTL0(SH_S_ADDR((st8)param.param[0]), U32(1));
315  return ADD(ADD(SH_U_ADDR(pc), SH_U_ADDR(4)), relative);
316  }
317  case SH_PC_RELATIVE12: {
318  // sign-extended for 12 bits and shifted left by 1 (i.e. multiplied by 2)
319  RzILOpBitVector *relative = SHIFTL0(SH_S_ADDR(convert_to_st12(param.param[0])), U32(1));
320  return ADD(ADD(SH_U_ADDR(pc), SH_U_ADDR(4)), relative);
321  }
322  case SH_PC_RELATIVE_REG:
323  return ADD(ADD(SH_U_ADDR(pc), SH_U_ADDR(4)), sh_il_get_reg(param.param[0]));
324  default:
325  RZ_LOG_WARN("RzIL: SuperH: No effective address for this mode: %u\n", param.mode);
326  }
327 
328  return NULL;
329 }
330 
331 #define sh_il_get_effective_addr(x, y) sh_il_get_effective_addr_pc_ctx(x, y, pc, ctx)
332 
343  SHParamHelper ret = {
344  .pre = NULL,
345  .pure = NULL,
346  .post = NULL
347  };
348 
349  /* In case of invalid scaling, just default to `SH_SCALING_L`, and assume param width of 32 bits (4 bytes)
350  This makes the param calculation process simpler and doesn't lead to any functional difference */
351  if (scaling == SH_SCALING_INVALID) {
352  scaling = SH_SCALING_L;
353  }
354 
355  switch (param.mode) {
356  case SH_REG_DIRECT:
357  if (scaling == SH_SCALING_L) {
358  ret.pure = sh_il_get_reg(param.param[0]);
359  } else {
360  ret.pure = UNSIGNED(BITS_PER_BYTE * sh_scaling_size[scaling], sh_il_get_reg(param.param[0]));
361  }
362  break;
363  case SH_REG_INDIRECT_I:
364  ret.post = sh_il_set_reg(param.param[0], ADD(sh_il_get_reg(param.param[0]), SH_U_ADDR(sh_scaling_size[scaling])));
365  goto set_pure;
366  case SH_REG_INDIRECT_D:
367  ret.pre = sh_il_set_reg(param.param[0], SUB(sh_il_get_reg(param.param[0]), SH_U_ADDR(sh_scaling_size[scaling])));
368  goto set_pure;
369  case SH_REG_INDIRECT:
374  case SH_PC_RELATIVE_DISP:
375  case SH_PC_RELATIVE8:
376  case SH_PC_RELATIVE12:
377  case SH_PC_RELATIVE_REG:
378  set_pure:
379  ret.pure = LOADW(BITS_PER_BYTE * sh_scaling_size[scaling], sh_il_get_effective_addr(param, scaling));
380  break;
381  case SH_IMM_U:
382  ret.pure = UN(sh_scaling_size[scaling] * BITS_PER_BYTE, param.param[0]);
383  break;
384  case SH_IMM_S:
385  ret.pure = SN(sh_scaling_size[scaling] * BITS_PER_BYTE, param.param[0]);
386  break;
387  default:
388  RZ_LOG_ERROR("RzIL: SuperH: Invalid addressing mode\n");
389  }
390 
391  return ret;
392 }
393 
394 #define sh_il_get_param(x, y) sh_il_get_param_pc_ctx(x, y, pc, ctx)
395 
408  if (!target) {
409  if (pre) {
410  target = pre;
411  goto append;
412  } else if (post) {
413  return post;
414  }
415  return NULL;
416  }
417 
418  if (pre) {
419  target = SEQ2(pre, target);
420  }
421 append:
422  if (post) {
423  target = SEQ2(target, post);
424  }
425 
426  return target;
427 }
428 
441  RzILOpEffect *ret = NULL, *pre = NULL, *post = NULL;
442  switch (param.mode) {
443  case SH_REG_DIRECT:
444  if (scaling == SH_SCALING_INVALID || scaling == SH_SCALING_L) {
445  ret = sh_il_set_reg(param.param[0], val);
446  } else {
447  /* We don't need to worry about sizes not matching up when calling `sh_il_signed` two times in an effect.
448  This is because within an effect, the scaling will stay the same, so all the time `sh_il_signed` is called,
449  it will be setting the local variables "_sign" and "_temp" to the same bitvector size.
450  Thus, there will be no IL validation errors. */
451  RzILOpEffect *cast = sh_il_signed(SH_REG_SIZE, val, "_sign", "_temp");
452  ret = SEQ2(cast, sh_il_set_reg(param.param[0], VARL("_sign")));
453  }
454  break;
455  case SH_REG_INDIRECT:
456  case SH_REG_INDIRECT_I:
457  case SH_REG_INDIRECT_D:
462  case SH_PC_RELATIVE_DISP:
463  case SH_PC_RELATIVE8:
464  case SH_PC_RELATIVE12:
465  case SH_PC_RELATIVE_REG:
466  break;
467  case SH_IMM_U:
468  case SH_IMM_S:
469  default:
470  RZ_LOG_ERROR("RzIL: SuperH: Cannot set value for addressing mode: %u\n", param.mode);
471  return NULL;
472  }
473 
474  if (!ret) {
475  SHParamHelper ret_h = sh_il_get_param(param, scaling);
476  RZ_FREE(ret_h.pure);
477  RzILOpPure *eff_addr = sh_il_get_effective_addr(param, scaling);
478  ret = STOREW(eff_addr, val);
479  pre = ret_h.pre;
480  post = ret_h.post;
481  }
482 
483  return sh_apply_effects(ret, pre, post);
484 }
485 
486 #define sh_il_set_param(x, y, z) sh_il_set_param_pc_ctx(x, y, z, pc, ctx)
487 
502  // res = x + y
503  RzILOpBool *xmsb = MSB(x);
504  RzILOpBool *ymsb = MSB(y);
505  RzILOpBool *resmsb = MSB(res);
506 
507  // x & y
508  RzILOpBool *xy = AND(xmsb, ymsb);
509  RzILOpBool *nres = INV(resmsb);
510 
511  // !res & y
512  RzILOpBool *ry = AND(nres, DUP(ymsb));
513  // x & !res
514  RzILOpBool *xr = AND(DUP(xmsb), DUP(nres));
515 
516  // bit = xy | ry | xr
517  RzILOpBool * or = OR(xy, ry);
518  or = OR(or, xr);
519 
520  return or ;
521 }
522 
537  // res = x - y
538  RzILOpBool *xmsb = MSB(x);
539  RzILOpBool *ymsb = MSB(y);
540  RzILOpBool *resmsb = MSB(res);
541 
542  // !x & y
543  RzILOpBool *nx = INV(xmsb);
544  RzILOpBool *nxy = AND(nx, ymsb);
545 
546  // y & res
547  RzILOpBool *rny = AND(DUP(ymsb), resmsb);
548  // res & !x
549  RzILOpBool *rnx = AND(DUP(resmsb), DUP(nx));
550 
551  // bit = nxy | rny | rnx
552  RzILOpBool * or = OR(nxy, rny);
553  or = OR(or, rnx);
554 
555  return or ;
556 }
557 
571  // res = x + y
572  RzILOpBool *xmsb = MSB(x);
573  RzILOpBool *ymsb = MSB(y);
574  RzILOpBool *resmsb = MSB(res);
575 
576  // !res & x & y
577  RzILOpBool *nrxy = AND(AND(INV(resmsb), xmsb), ymsb);
578  // res & !x & !y
579  RzILOpBool *rnxny = AND(AND(DUP(resmsb), INV(DUP(xmsb))), INV(DUP(ymsb)));
580  // or = nrxy | rnxny
581  RzILOpBool * or = OR(nrxy, rnxny);
582 
583  return or ;
584 }
585 
599  // res = x - y
600  RzILOpBool *xmsb = MSB(x);
601  RzILOpBool *ymsb = MSB(y);
602  RzILOpBool *resmsb = MSB(res);
603 
604  // !res & x & !y
605  RzILOpBool *nrxny = AND(AND(INV(resmsb), xmsb), INV(ymsb));
606  // res & !x & y
607  RzILOpBool *rnxy = AND(AND(DUP(resmsb), INV(DUP(xmsb))), DUP(ymsb));
608  // or = nrxny | rnxy
609  RzILOpBool * or = OR(nrxny, rnxy);
610 
611  return or ;
612 }
613 
614 /* Instruction implementations */
615 
620  return NULL;
621 }
622 
626 static RzILOpEffect *sh_il_mov(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
627  SHParamHelper shp = sh_il_get_param(op->param[0], op->scaling);
628  return sh_apply_effects(sh_il_set_pure_param(1, shp.pure), shp.pre, shp.post);
629 }
630 
636 static RzILOpEffect *sh_il_movt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
638 }
639 
649 static RzILOpEffect *sh_il_swap(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
650  /* We won't be using `sh_il_{get,set}_param_pure`, because it will cast the pure value to the scaling size,
651  but we want the whole register, which is why we need to call `sh_il_{get,set}_param directly` */
652  if (op->scaling == SH_SCALING_B) {
653  // swap lower two bytes
654  RzILOpPure *lower_byte = LOGAND(sh_il_get_param(op->param[0], SH_SCALING_L).pure, SH_U_REG(0xff));
655  RzILOpPure *new_lower_byte = LOGAND(SHIFTR0(sh_il_get_param(op->param[0], SH_SCALING_L).pure, SH_U_REG(BITS_PER_BYTE)), SH_U_REG(0xff));
656  RzILOpPure *new_upper_byte = SHIFTL0(lower_byte, SH_U_REG(BITS_PER_BYTE));
657  RzILOpPure *upper_word = LOGAND(sh_il_get_param(op->param[0], SH_SCALING_L).pure, SH_U_REG(0xffff0000));
658  return sh_il_set_param(op->param[1], LOGOR(upper_word, LOGOR(new_upper_byte, new_lower_byte)), SH_SCALING_L);
659  } else if (op->scaling == SH_SCALING_W) {
660  // swap upper and lower words and store in dst
661  RzILOpPure *high = SHIFTL0(sh_il_get_param(op->param[0], SH_SCALING_L).pure, SH_U_REG(BITS_PER_BYTE * 2));
662  RzILOpPure *low = SHIFTR0(sh_il_get_param(op->param[0], SH_SCALING_L).pure, SH_U_REG(BITS_PER_BYTE * 2));
663  return sh_il_set_param(op->param[1], LOGOR(high, low), SH_SCALING_L);
664  }
665 
666  return NULL;
667 }
668 
674 static RzILOpEffect *sh_il_xtrct(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
677  return sh_il_set_pure_param(1, LOGOR(high, low));
678 }
679 
689 static RzILOpEffect *sh_il_add(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
691 }
692 
699 static RzILOpEffect *sh_il_addc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
702 
704  RzILOpEffect *ret = sh_il_set_pure_param(1, VARL("sum"));
705  return SEQ3(local_sum, tbit, ret);
706 }
707 
714 static RzILOpEffect *sh_il_addv(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
716  RzILOpEffect *local_sum = SETL("sum", sum);
717 
719  RzILOpEffect *ret = sh_il_set_pure_param(1, VARL("sum"));
720  return SEQ3(local_sum, tbit, ret);
721 }
722 
734 }
735 
743 }
744 
752 }
753 
761 }
762 
770 }
771 
778  return SETG(SH_SR_T, SGE(sh_il_get_pure_param(0), SH_S_REG(0)));
779 }
780 
787  return SETG(SH_SR_T, SGT(sh_il_get_pure_param(0), SH_S_REG(0)));
788 }
789 
797  RzILOpEffect *eff = SETL("xor", full_xor);
798 
799  eff = SEQ2(eff, SETL("eq", EQ(LOGAND(VARL("xor"), SH_U_REG(0xff)), SH_U_REG(0x0))));
800  eff = SEQ2(eff, SETL("xor", SHIFTR0(VARL("xor"), SH_U_REG(BITS_PER_BYTE))));
801  eff = SEQ2(eff, SETL("eq", OR(VARL("eq"), EQ(LOGAND(VARL("xor"), SH_U_REG(0xff)), SH_U_REG(0x0)))));
802  eff = SEQ2(eff, SETL("xor", SHIFTR0(VARL("xor"), SH_U_REG(BITS_PER_BYTE))));
803  eff = SEQ2(eff, SETL("eq", OR(VARL("eq"), EQ(LOGAND(VARL("xor"), SH_U_REG(0xff)), SH_U_REG(0x0)))));
804  eff = SEQ2(eff, SETL("xor", SHIFTR0(VARL("xor"), SH_U_REG(BITS_PER_BYTE))));
805  eff = SEQ2(eff, SETL("eq", OR(VARL("eq"), EQ(LOGAND(VARL("xor"), SH_U_REG(0xff)), SH_U_REG(0x0)))));
806 
807  return SEQ2(eff, SETG(SH_SR_T, VARL("eq")));
808 }
809 
815 static RzILOpEffect *sh_il_div1(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
816  RzILOpEffect *ret = NULL;
817  RzILOpEffect *q = SETL("q", VARG(SH_SR_Q));
818  RzILOpEffect *m = SETL("m", VARG(SH_SR_M));
819  RzILOpEffect *t = SETL("t", VARG(SH_SR_T));
820  ret = SEQ3(q, m, t);
821 
822  RzILOpEffect *op1 = SETL("op1", sh_il_get_pure_param(0));
823  RzILOpEffect *op2 = SETL("op2", sh_il_get_pure_param(1));
824  RzILOpEffect *old_q = SETL("old_q", VARL("q"));
825  ret = SEQ4(ret, op1, op2, old_q);
826 
827  // Get 31st bit of var q
828  q = SETL("q", NON_ZERO(LOGAND(VARL("op2"), SH_U_REG(0x80000000))));
829  op2 = SETL("op2", LOGOR(SHIFTL0(VARL("op2"), SH_U_REG(1)), sh_il_bool_to_bv(VARL("t"))));
830  ret = SEQ3(ret, q, op2);
831 
832  RzILOpEffect *true_eff = SETL("op2", SUB(VARL("op2"), VARL("op1")));
833  RzILOpEffect *false_eff = SETL("op2", ADD(VARL("op2"), VARL("op1")));
834  RzILOpEffect *cond = BRANCH(EQ(sh_il_bool_to_bv(VARL("old_q")), sh_il_bool_to_bv(VARL("m"))), true_eff, false_eff);
835  ret = SEQ2(ret, cond);
836 
837  // q = q ^ m ^ msb(op2)
838  q = SETL("q", XOR(XOR(VARL("q"), VARL("m")), MSB(VARL("op2"))));
839  t = SETL("t", NON_ZERO(SUB(SH_U_REG(1), LOGXOR(sh_il_bool_to_bv(VARL("q")), sh_il_bool_to_bv(VARL("m"))))));
840  ret = SEQ3(ret, q, t);
841 
842  RzILOpEffect *rn = sh_il_set_pure_param(1, VARL("op2"));
843  q = SETG(SH_SR_Q, VARL("q"));
844  t = SETG(SH_SR_T, VARL("t"));
845  ret = SEQ4(ret, rn, q, t);
846 
847  return ret;
848 }
849 
855 static RzILOpEffect *sh_il_div0s(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
859 
860  return SEQ3(setq, setm, sett);
861 }
862 
868 static RzILOpEffect *sh_il_div0u(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
870 }
871 
877 static RzILOpEffect *sh_il_dmuls(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
879  RzILOpPure *lower_bits = UNSIGNED(SH_REG_SIZE, LOGAND(VARL("res_wide"), UN(2 * SH_REG_SIZE, 0xffffffff)));
880  RzILOpPure *higher_bits = UNSIGNED(SH_REG_SIZE, SHIFTR0(VARL("res_wide"), SH_U_REG(SH_REG_SIZE)));
881  return SEQ3(eff, SETG("macl", lower_bits), SETG("mach", higher_bits));
882 }
883 
889 static RzILOpEffect *sh_il_dmulu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
891  RzILOpPure *lower_bits = UNSIGNED(SH_REG_SIZE, LOGAND(VARL("res_wide"), UN(2 * SH_REG_SIZE, 0xffffffff)));
892  RzILOpPure *higher_bits = UNSIGNED(SH_REG_SIZE, SHIFTR0(VARL("res_wide"), SH_U_REG(SH_REG_SIZE)));
893  return SEQ3(eff, SETG("macl", lower_bits), SETG("mach", higher_bits));
894 }
895 
901 static RzILOpEffect *sh_il_dt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
903 }
904 
914 static RzILOpEffect *sh_il_exts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
916 }
917 
927 static RzILOpEffect *sh_il_extu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
928  /* Do not use `sh_il_set_pure_param` here since that will sign extend the Rn value, but we want
929  it extend it unsigned, which is why we need to directly call `sh_il_set_reg` */
930  return sh_il_set_reg(op->param[1].param[0], UNSIGNED(SH_REG_SIZE, sh_il_get_pure_param(0)));
931 }
932 
950 static RzILOpEffect *sh_il_mac(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
951  SHParamHelper shp_rm = sh_il_get_param(op->param[0], op->scaling);
952  SHParamHelper shp_rn = sh_il_get_param(op->param[1], op->scaling);
953  RzILOpEffect *eff = NULL;
954 
955  if (op->scaling == SH_SCALING_L) {
956  RzILOpEffect *mac = SETL("mac", LOGOR(SHIFTL0((UNSIGNED(2 * SH_REG_SIZE, VARG("mach"))), SH_U_REG(SH_REG_SIZE)), UNSIGNED(2 * SH_REG_SIZE, VARG("macl"))));
957  RzILOpEffect *rm = SETL("rm", shp_rm.pure);
958  RzILOpEffect *rn = SETL("rn", shp_rn.pure);
959  eff = SEQ2(rm, rn);
960 
961  RzILOpEffect *mul = SETL("mul", MUL(SIGNED(2 * SH_REG_SIZE, VARL("rm")), SIGNED(2 * SH_REG_SIZE, VARL("rn"))));
962  RzILOpEffect *add = SETL("add", ADD(VARL("mul"), VARL("mac")));
963  RzILOpPure *lower_bits = UNSIGNED(SH_REG_SIZE, LOGAND(VARL("add"), UN(2 * SH_REG_SIZE, 0xffffffff)));
964  RzILOpEffect *higher_bits = SETL("high", UNSIGNED(SH_REG_SIZE, SHIFTR0(VARL("add"), SH_U_REG(SH_REG_SIZE))));
965 
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"))));
967  } else if (op->scaling == SH_SCALING_W) {
968  RzILOpEffect *mac = SETL("mac", LOGOR(SHIFTL0((UNSIGNED(2 * SH_REG_SIZE, VARG("mach"))), SH_U_REG(SH_REG_SIZE)), UNSIGNED(2 * SH_REG_SIZE, VARG("macl"))));
969  RzILOpEffect *rm = SETL("rm", shp_rm.pure);
970  RzILOpEffect *rn = SETL("rn", shp_rn.pure);
971  eff = SEQ2(rm, rn);
972 
974  RzILOpEffect *add = SETL("add", ADD(VARL("mul"), VARL("mac")));
975  RzILOpEffect *lower_bits = SETL("low", UNSIGNED(SH_REG_SIZE, LOGAND(VARL("add"), UN(2 * SH_REG_SIZE, 0xffffffff))));
976  RzILOpPure *higher_bits = UNSIGNED(SH_REG_SIZE, SHIFTR0(VARL("add"), SH_U_REG(SH_REG_SIZE)));
977 
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))));
979  }
980 
981  eff = SEQ3(eff, shp_rn.post, shp_rm.post);
982  return eff;
983 }
984 
990 static RzILOpEffect *sh_il_mul(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
991  return SETG("macl", MUL(sh_il_get_pure_param(0), sh_il_get_pure_param(1)));
992 }
993 
999 static RzILOpEffect *sh_il_muls(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1000  RzILOpEffect *rm = SETL("rm", sh_il_get_pure_param(0));
1001  RzILOpEffect *rn = SETL("rn", sh_il_get_pure_param(1));
1002  RzILOpPure *m = SIGNED(SH_REG_SIZE, VARL("rm"));
1003  RzILOpPure *n = SIGNED(SH_REG_SIZE, VARL("rn"));
1004  return SEQ3(rm, rn, SETG("macl", MUL(m, n)));
1005 }
1006 
1012 static RzILOpEffect *sh_il_mulu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1015  return SETG("macl", MUL(m, n));
1016 }
1017 
1023 static RzILOpEffect *sh_il_neg(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1025  return sh_il_set_pure_param(1, sub);
1026 }
1027 
1033 static RzILOpEffect *sh_il_negc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1037 }
1038 
1044 static RzILOpEffect *sh_il_sub(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1046 }
1047 
1053 static RzILOpEffect *sh_il_subc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1055  dif = SUB(dif, sh_il_get_status_reg_bit(SH_SR_T));
1056  RzILOpEffect *local_dif = SETL("dif", dif);
1057 
1058  RzILOpEffect *ret = sh_il_set_pure_param(1, VARL("dif"));
1060  return SEQ3(local_dif, ret, tbit);
1061 }
1062 
1068 static RzILOpEffect *sh_il_subv(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1070  RzILOpEffect *local_dif = SETL("dif", dif);
1071 
1072  RzILOpEffect *ret = sh_il_set_pure_param(1, VARL("dif"));
1074  return SEQ3(local_dif, ret, tbit);
1075 }
1076 
1090 static RzILOpEffect *sh_il_and(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1092 }
1093 
1099 static RzILOpEffect *sh_il_not(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1101 }
1102 
1116 static RzILOpEffect *sh_il_or(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1118 }
1119 
1126 static RzILOpEffect *sh_il_tas(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1128  RzILOpEffect *tbit = SETG(SH_SR_T, IS_ZERO(mem));
1129  return SEQ2(tbit, sh_il_set_pure_param(0, LOGOR(DUP(mem), UN(8, 0x80))));
1130 }
1131 
1145 static RzILOpEffect *sh_il_tst(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1147 }
1148 
1162 static RzILOpEffect *sh_il_xor(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1164 }
1165 
1171 static RzILOpEffect *sh_il_rotl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1172  RzILOpEffect *msb = SETL("msb_", MSB(sh_il_get_pure_param(0)));
1173  RzILOpEffect *tbit = SETG(SH_SR_T, VARL("msb_"));
1174  RzILOpEffect *shl = SETL("shl_", SHIFTL0(sh_il_get_pure_param(0), SH_U_REG(1)));
1175  RzILOpPure *lsb = ITE(VARL("msb_"), LOGOR(VARL("shl_"), SH_U_REG(1)), VARL("shl_"));
1176  return SEQ4(msb, tbit, shl, sh_il_set_pure_param(0, lsb));
1177 }
1178 
1184 static RzILOpEffect *sh_il_rotr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1185  RzILOpEffect *lsb = SETL("lsb_", LSB(sh_il_get_pure_param(0)));
1186  RzILOpEffect *tbit = SETG(SH_SR_T, VARL("lsb_"));
1187  RzILOpEffect *shr = SETL("shr_", SHIFTR0(sh_il_get_pure_param(0), SH_U_REG(1)));
1188  RzILOpPure *msb = ITE(VARL("lsb_"), LOGOR(VARL("shr_"), SH_U_REG(0x80000000)), VARL("shr_"));
1189  return SEQ4(lsb, tbit, shr, sh_il_set_pure_param(0, msb));
1190 }
1191 
1198  RzILOpEffect *msb = SETL("msb_", MSB(sh_il_get_pure_param(0)));
1199  RzILOpEffect *shl = SETL("shl_", SHIFTL0(sh_il_get_pure_param(0), SH_U_REG(1)));
1200  RzILOpPure *lsb = ITE(VARG(SH_SR_T), LOGOR(VARL("shl_"), SH_U_REG(1)), VARL("shl_"));
1201  RzILOpEffect *tbit = SETG(SH_SR_T, VARL("msb_"));
1202  return SEQ4(msb, shl, sh_il_set_pure_param(0, lsb), tbit);
1203 }
1204 
1211  RzILOpEffect *lsb = SETL("lsb_", LSB(sh_il_get_pure_param(0)));
1212  RzILOpEffect *shr = SETL("shr_", SHIFTR0(sh_il_get_pure_param(0), SH_U_REG(1)));
1213  RzILOpPure *msb = ITE(VARG(SH_SR_T), LOGOR(VARL("shr_"), SH_U_REG(0x80000000)), VARL("shr_"));
1214  RzILOpEffect *tbit = SETG(SH_SR_T, VARL("lsb_"));
1215  return SEQ4(lsb, shr, sh_il_set_pure_param(0, msb), tbit);
1216 }
1217 
1225 static RzILOpEffect *sh_il_shad(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1226  RzILOpEffect *shift_amount = SETL("shift_", UNSIGNED(5, sh_il_get_pure_param(0)));
1227 
1228  RzILOpPure *shl = SHIFTL0(sh_il_get_pure_param(1), VARL("shift_"));
1229  RzILOpPure *shr = SHIFTRA(sh_il_get_pure_param(1), NEG(VARL("shift_")));
1230 
1231  return SEQ2(shift_amount, BRANCH(SGE(sh_il_get_pure_param(0), SN(32, 0)), sh_il_set_pure_param(1, shl), sh_il_set_pure_param(1, shr)));
1232 }
1233 
1239 static RzILOpEffect *sh_il_shal(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1240  RzILOpPure *msb = MSB(sh_il_get_pure_param(0));
1242  return SEQ2(SETG(SH_SR_T, msb), sh_il_set_pure_param(0, shl));
1243 }
1244 
1250 static RzILOpEffect *sh_il_shar(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1251  RzILOpPure *lsb = LSB(sh_il_get_pure_param(0));
1253  return SEQ2(SETG(SH_SR_T, lsb), sh_il_set_pure_param(0, shl));
1254 }
1255 
1263 static RzILOpEffect *sh_il_shld(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1264  RzILOpEffect *shift_amount = SETL("shift_", UNSIGNED(5, sh_il_get_pure_param(0)));
1265 
1266  RzILOpPure *shl = SHIFTL0(sh_il_get_pure_param(1), VARL("shift_"));
1267  RzILOpPure *shr = SHIFTR0(sh_il_get_pure_param(1), NEG(VARL("shift_")));
1268 
1269  return SEQ2(shift_amount, BRANCH(SGE(sh_il_get_pure_param(0), SN(32, 0)), sh_il_set_pure_param(1, shl), sh_il_set_pure_param(1, shr)));
1270  ;
1271 }
1272 
1278 static RzILOpEffect *sh_il_shll(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1279  RzILOpPure *msb = MSB(sh_il_get_pure_param(0));
1281  return SEQ2(SETG(SH_SR_T, msb), sh_il_set_pure_param(0, shl));
1282 }
1283 
1289 static RzILOpEffect *sh_il_shlr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1290  RzILOpPure *lsb = LSB(sh_il_get_pure_param(0));
1292  return SEQ2(SETG(SH_SR_T, lsb), sh_il_set_pure_param(0, shr));
1293 }
1294 
1302 }
1303 
1311 }
1312 
1320 }
1321 
1329 }
1330 
1338 }
1339 
1347 }
1348 
1354 static RzILOpEffect *sh_il_bf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1356  return BRANCH(VARG(SH_SR_T), JMP(new_pc), NOP());
1357 }
1358 
1365 static RzILOpEffect *sh_il_bfs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1367  return BRANCH(VARG(SH_SR_T), JMP(new_pc), NOP());
1368 }
1369 
1375 static RzILOpEffect *sh_il_bt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1377  return BRANCH(VARG(SH_SR_T), JMP(new_pc), NOP());
1378 }
1379 
1386 static RzILOpEffect *sh_il_bts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1388  return BRANCH(VARG(SH_SR_T), JMP(new_pc), NOP());
1389 }
1390 
1397 static RzILOpEffect *sh_il_bra(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1399 }
1400 
1407 static RzILOpEffect *sh_il_braf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1409 }
1410 
1417 static RzILOpEffect *sh_il_bsr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1419 }
1420 
1427 static RzILOpEffect *sh_il_bsrf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1429 }
1430 
1437 static RzILOpEffect *sh_il_jmp(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1439 }
1440 
1447 static RzILOpEffect *sh_il_jsr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1449 }
1450 
1457 static RzILOpEffect *sh_il_rts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1458  return JMP(VARG("pr"));
1459 }
1460 
1467  return SEQ2(SETG("mach", UN(SH_REG_SIZE, 0)), SETG("macl", UN(SH_REG_SIZE, 0)));
1468 }
1469 
1475 static RzILOpEffect *sh_il_clrs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1476  return SETG(SH_SR_S, IL_FALSE);
1477 }
1478 
1484 static RzILOpEffect *sh_il_clrt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1485  return SETG(SH_SR_T, IL_FALSE);
1486 }
1487 
1499 static RzILOpEffect *sh_il_ldc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1500  /* We won't be using banked registers for these instructions (except for unprivileged GBR) */
1501  // TODO: Check what the correct implementation is
1502  ctx->use_banked = false;
1503  if (op->param[1].param[0] == SH_REG_IND_GBR) {
1504  ctx->use_banked = true;
1505  }
1506 
1507  RzILOpEffect *eff = NULL;
1508  if (op->scaling == SH_SCALING_INVALID) {
1509  if (sh_valid_gpr(op->param[1].param[0])) {
1510  eff = SETG(sh_get_banked_reg(op->param[1].param[0], 1), sh_il_get_pure_param(0));
1511  } else {
1513  }
1514  } else if (op->scaling == SH_SCALING_L) {
1515  SHParamHelper rm = sh_il_get_param(op->param[0], op->scaling);
1516  if (sh_valid_gpr(op->param[1].param[0])) {
1517  eff = SEQ2(SETG(sh_get_banked_reg(op->param[1].param[0], 1), rm.pure), rm.post);
1518  } else {
1519  eff = SEQ2(sh_il_set_pure_param(1, rm.pure), rm.post);
1520  }
1521  }
1522 
1523  if (op->param[1].param[0] != SH_REG_IND_GBR) {
1524  eff = BRANCH(sh_il_get_privilege(), eff, EMPTY());
1525  }
1526  return eff;
1527 }
1528 
1538 static RzILOpEffect *sh_il_lds(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1539  if (op->scaling == SH_SCALING_INVALID) {
1541  } else if (op->scaling == SH_SCALING_L) {
1542  SHParamHelper rm = sh_il_get_param(op->param[0], op->scaling);
1543  return SEQ2(sh_il_set_pure_param(1, rm.pure), rm.post);
1544  }
1545  return NOP();
1546 }
1547 
1555 }
1556 
1562 static RzILOpEffect *sh_il_nop(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1563  return NOP();
1564 }
1565 
1573 static RzILOpEffect *sh_il_rte(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1574  return BRANCH(sh_il_get_privilege(), SEQ2(sh_il_set_status_reg(VARG("ssr")), JMP(VARG("spc"))), EMPTY());
1575 }
1576 
1582 static RzILOpEffect *sh_il_sets(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1583  return SETG(SH_SR_S, IL_TRUE);
1584 }
1585 
1591 static RzILOpEffect *sh_il_sett(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1592  return SETG(SH_SR_T, IL_TRUE);
1593 }
1594 
1602  return BRANCH(sh_il_get_privilege(), NOP(), EMPTY());
1603 }
1604 
1616 static RzILOpEffect *sh_il_stc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1617  /* We won't be using banked registers for these instructions (except for unprivileged GBR) */
1618  // TODO: Check what the correct implementation is
1619  ctx->use_banked = false;
1620  if (op->param[0].param[0] == SH_REG_IND_GBR) {
1621  ctx->use_banked = true;
1622  }
1623 
1624  RzILOpEffect *eff = NULL;
1625  if (sh_valid_gpr(op->param[0].param[0])) { // REG = Rn_BANK
1626  eff = sh_il_set_pure_param(1, VARG(sh_get_banked_reg(op->param[0].param[0], 1)));
1627  } else {
1629  }
1630  if (op->param[0].param[0] != SH_REG_IND_GBR) {
1631  eff = BRANCH(sh_il_get_privilege(), eff, EMPTY());
1632  }
1633  return eff;
1634 }
1635 
1645 static RzILOpEffect *sh_il_sts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx) {
1647 }
1648 
1654  RZ_LOG_WARN("SuperH: Instruction with opcode 0x%04x is unimplemented\n", op->opcode);
1655  return EMPTY();
1656 }
1657 
1658 #include <rz_il/rz_il_opbuilder_end.h>
1659 
1660 typedef RzILOpEffect *(*sh_il_op)(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx);
1661 
1665 static const sh_il_op sh_ops[SH_OP_SIZE] = {
1667  [SH_OP_MOV] = sh_il_mov,
1668  [SH_OP_MOVT] = sh_il_movt,
1669  [SH_OP_SWAP] = sh_il_swap,
1671  [SH_OP_ADD] = sh_il_add,
1672  [SH_OP_ADDC] = sh_il_addc,
1673  [SH_OP_ADDV] = sh_il_addv,
1682  [SH_OP_DIV1] = sh_il_div1,
1687  [SH_OP_DT] = sh_il_dt,
1688  [SH_OP_EXTS] = sh_il_exts,
1689  [SH_OP_EXTU] = sh_il_extu,
1690  [SH_OP_MAC] = sh_il_mac,
1691  [SH_OP_MUL] = sh_il_mul,
1692  [SH_OP_MULS] = sh_il_muls,
1693  [SH_OP_MULU] = sh_il_mulu,
1694  [SH_OP_NEG] = sh_il_neg,
1695  [SH_OP_NEGC] = sh_il_negc,
1696  [SH_OP_SUB] = sh_il_sub,
1697  [SH_OP_SUBC] = sh_il_subc,
1698  [SH_OP_SUBV] = sh_il_subv,
1699  [SH_OP_AND] = sh_il_and,
1700  [SH_OP_NOT] = sh_il_not,
1701  [SH_OP_OR] = sh_il_or,
1702  [SH_OP_TAS] = sh_il_tas,
1703  [SH_OP_TST] = sh_il_tst,
1704  [SH_OP_XOR] = sh_il_xor,
1705  [SH_OP_ROTL] = sh_il_rotl,
1706  [SH_OP_ROTR] = sh_il_rotr,
1709  [SH_OP_SHAD] = sh_il_shad,
1710  [SH_OP_SHAL] = sh_il_shal,
1711  [SH_OP_SHAR] = sh_il_shar,
1712  [SH_OP_SHLD] = sh_il_shld,
1713  [SH_OP_SHLL] = sh_il_shll,
1714  [SH_OP_SHLR] = sh_il_shlr,
1721  [SH_OP_BF] = sh_il_bf,
1722  [SH_OP_BFS] = sh_il_bfs,
1723  [SH_OP_BT] = sh_il_bt,
1724  [SH_OP_BTS] = sh_il_bts,
1725  [SH_OP_BRA] = sh_il_bra,
1726  [SH_OP_BRAF] = sh_il_braf,
1727  [SH_OP_BSR] = sh_il_bsr,
1728  [SH_OP_BSRF] = sh_il_bsrf,
1729  [SH_OP_JMP] = sh_il_jmp,
1730  [SH_OP_JSR] = sh_il_jsr,
1731  [SH_OP_RTS] = sh_il_rts,
1733  [SH_OP_CLRS] = sh_il_clrs,
1734  [SH_OP_CLRT] = sh_il_clrt,
1735  [SH_OP_LDC] = sh_il_ldc,
1736  [SH_OP_LDS] = sh_il_lds,
1738  [SH_OP_NOP] = sh_il_nop,
1739  [SH_OP_RTE] = sh_il_rte,
1740  [SH_OP_SETS] = sh_il_sets,
1741  [SH_OP_SETT] = sh_il_sett,
1743  [SH_OP_STC] = sh_il_stc,
1744  [SH_OP_STS] = sh_il_sts,
1746 };
1747 
1760  rz_return_val_if_fail(analysis && aop && op, false);
1761  if (op->mnemonic >= SH_OP_SIZE) {
1762  RZ_LOG_ERROR("RzIL: SuperH: out of bounds op\n");
1763  return false;
1764  }
1765 
1766  sh_il_op create_op = sh_ops[op->mnemonic];
1767  RzILOpEffect *lifted = create_op(op, pc, analysis, ctx);
1768 
1769  // If the privilege was checked, then we need to set the local variable before the IL lifting
1770  if (ctx && ctx->privilege_check) {
1771  lifted = sh_apply_effects(lifted, sh_il_initialize_privilege(), NULL);
1772  }
1773 
1774  aop->il_op = lifted;
1775  return true;
1776 }
1777 
1785  rz_return_val_if_fail(analysis, NULL);
1786 
1788  return r;
1789 }
size_t len
Definition: 6502dis.c:15
ut8 op
Definition: 6502dis.c:13
#define xr(subject)
RZ_API RZ_OWN RzAnalysisILConfig * rz_analysis_il_config_new(ut32 pc_size, bool big_endian, ut32 mem_key_size)
Definition: analysis_il.c:53
#define RZ_IPI
Definition: analysis_wasm.c:11
#define BRANCH
#define cast(x, y)
Definition: arch_53.h:166
static RzILOpEffect * mul(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:539
ut16 val
Definition: armass64_const.h:6
#define append(x, y)
Definition: cmd_print.c:1740
#define NULL
Definition: cris-opc.c:27
RzCryptoSelector bit
Definition: crypto.c:16
#define r
Definition: crypto_rc6.c:12
uint16_t ut16
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
Definition: il_opcodes.c:341
#define reg(n)
uint8_t ut8
Definition: lh5801.h:11
void * mem
Definition: libc.cpp:91
#define SIGNED
Definition: ansidecl.h:248
#define AND
Definition: ansidecl.h:254
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
Definition: sflib.h:126
unsigned int U32
Definition: lz4.c:288
int x
Definition: mipsasm.c:20
int n
Definition: mipsasm.c:19
static bool subvar(RzParse *p, RzAnalysisFunction *f, RzAnalysisOp *op, char *data, char *str, int len)
static const char * sh_registers[]
Definition: regs.h:10
#define OR
Definition: rsp_idec.c:210
#define XOR
Definition: rsp_idec.c:212
#define NOP
Definition: rsp_idec.c:182
#define ADD
Definition: rsp_idec.c:200
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
Syntax Macros for RzIL Lifting.
#define LOGOR(x, y)
#define UGT(x, y)
#define LOGNOT(x)
#define IS_ZERO(x)
#define SHIFTR0(v, dist)
#define LOADW(n, addr)
#define MUL(x, y)
#define LSB(x)
#define UN(l, val)
#define EMPTY()
#define IL_FALSE
#define EQ(x, y)
#define SEQ3(e0, e1, e2)
#define STOREW(addr, val)
#define SETL(name, v)
#define SEQ4(e0, e1, e2, e3)
#define IL_TRUE
#define INV(x)
#define SEQ2(e0, e1)
#define ITE(c, t, f)
#define LOGXOR(x, y)
#define NON_ZERO(x)
#define NEG(x)
#define UNSIGNED(n, x)
#define SEQ7(e0, e1, e2, e3, e4, e5, e6)
#define SN(l, val)
#define SEQ6(e0, e1, e2, e3, e4, e5)
#define SHIFTL0(v, dist)
#define SHIFTRA(v, dist)
#define VARL(name)
#define SGE(x, y)
#define SGT(x, y)
#define MSB(x)
#define LOGAND(x, y)
#define VARG(name)
#define JMP(tgt)
#define UGE(x, y)
#define SETG(name, v)
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_FREE(x)
Definition: rz_types.h:369
#define RZ_BORROW
Definition: rz_types.h:63
#define st8
Definition: rz_types_base.h:16
#define st16
Definition: rz_types_base.h:14
@ DUP
Definition: packet.c:12
#define SUB(ns, call)
#define SH_SR_R
SR.RB: General register bank specifier in privileged mode (set to 1 by a reset, exception or interrup...
Definition: disassembler.h:63
#define SH_ADDR_SIZE
Definition: disassembler.h:11
#define SH_GPR_COUNT
Definition: disassembler.h:13
enum sh_scaling_t SHScaling
#define BITS_PER_BYTE
Definition: disassembler.h:9
#define SH_SR_M
SR.M: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions)
Definition: disassembler.h:57
#define SH_SR_B
SR.BL: Exception/interrupt block bit (set to 1 by a reset, exception, or interrupt)
Definition: disassembler.h:61
@ SH_SCALING_L
long word
Definition: disassembler.h:39
@ SH_SCALING_INVALID
Definition: disassembler.h:36
@ SH_SCALING_W
word
Definition: disassembler.h:38
@ SH_SCALING_B
byte
Definition: disassembler.h:37
#define SH_SR_T
SR.T: True/False condition or carry/borrow bit.
Definition: disassembler.h:49
#define SH_SR_D
SR.MD: Processor mode.
Definition: disassembler.h:65
@ SH_OP_DIV0S
Definition: disassembler.h:170
@ SH_OP_CMP_PL
Definition: disassembler.h:167
@ SH_OP_SHLL8
Definition: disassembler.h:204
@ SH_OP_LDS
Definition: disassembler.h:223
@ SH_OP_MOV
Definition: disassembler.h:154
@ SH_OP_BRA
Definition: disassembler.h:212
@ SH_OP_ADDV
Definition: disassembler.h:160
@ SH_OP_CMP_STR
Definition: disassembler.h:168
@ SH_OP_SHLL2
Definition: disassembler.h:202
@ SH_OP_UNIMPL
Definition: disassembler.h:232
@ SH_OP_AND
Definition: disassembler.h:186
@ SH_OP_TST
Definition: disassembler.h:190
@ SH_OP_SHLL
Definition: disassembler.h:200
@ SH_OP_BT
Definition: disassembler.h:210
@ SH_OP_CMP_GT
Definition: disassembler.h:165
@ SH_OP_XOR
Definition: disassembler.h:191
@ SH_OP_ROTR
Definition: disassembler.h:193
@ SH_OP_BTS
Definition: disassembler.h:211
@ SH_OP_BSRF
Definition: disassembler.h:215
@ SH_OP_CMP_HI
Definition: disassembler.h:164
@ SH_OP_NOP
Definition: disassembler.h:225
@ SH_OP_OR
Definition: disassembler.h:188
@ SH_OP_XTRCT
Definition: disassembler.h:157
@ SH_OP_MULU
Definition: disassembler.h:180
@ SH_OP_EXTU
Definition: disassembler.h:176
@ SH_OP_BRAF
Definition: disassembler.h:213
@ SH_OP_MULS
Definition: disassembler.h:179
@ SH_OP_ADDC
Definition: disassembler.h:159
@ SH_OP_TAS
Definition: disassembler.h:189
@ SH_OP_INVALID
Definition: disassembler.h:153
@ SH_OP_SETS
Definition: disassembler.h:227
@ SH_OP_SHLR16
Definition: disassembler.h:207
@ SH_OP_NEGC
Definition: disassembler.h:182
@ SH_OP_SWAP
Definition: disassembler.h:156
@ SH_OP_SETT
Definition: disassembler.h:228
@ SH_OP_SLEEP
Definition: disassembler.h:229
@ SH_OP_SHLR
Definition: disassembler.h:201
@ SH_OP_SHLL16
Definition: disassembler.h:206
@ SH_OP_STS
Definition: disassembler.h:231
@ SH_OP_ADD
Definition: disassembler.h:158
@ SH_OP_SUB
Definition: disassembler.h:183
@ SH_OP_NEG
Definition: disassembler.h:181
@ SH_OP_CLRS
Definition: disassembler.h:220
@ SH_OP_DIV0U
Definition: disassembler.h:171
@ SH_OP_ROTL
Definition: disassembler.h:192
@ SH_OP_STC
Definition: disassembler.h:230
@ SH_OP_BFS
Definition: disassembler.h:209
@ SH_OP_DMULS
Definition: disassembler.h:172
@ SH_OP_CMP_GE
Definition: disassembler.h:163
@ SH_OP_CLRT
Definition: disassembler.h:221
@ SH_OP_MUL
Definition: disassembler.h:178
@ SH_OP_MAC
Definition: disassembler.h:177
@ SH_OP_SHLD
Definition: disassembler.h:199
@ SH_OP_ROTCR
Definition: disassembler.h:195
@ SH_OP_DT
Definition: disassembler.h:174
@ SH_OP_NOT
Definition: disassembler.h:187
@ SH_OP_DMULU
Definition: disassembler.h:173
@ SH_OP_BF
Definition: disassembler.h:208
@ SH_OP_SHAR
Definition: disassembler.h:198
@ SH_OP_DIV1
Definition: disassembler.h:169
@ SH_OP_MOVT
Definition: disassembler.h:155
@ SH_OP_ROTCL
Definition: disassembler.h:194
@ SH_OP_CMP_PZ
Definition: disassembler.h:166
@ SH_OP_SIZE
Definition: disassembler.h:234
@ SH_OP_SUBC
Definition: disassembler.h:184
@ SH_OP_RTE
Definition: disassembler.h:226
@ SH_OP_CLRMAC
Definition: disassembler.h:219
@ SH_OP_EXTS
Definition: disassembler.h:175
@ SH_OP_RTS
Definition: disassembler.h:218
@ SH_OP_LDC
Definition: disassembler.h:222
@ SH_OP_CMP_EQ
Definition: disassembler.h:161
@ SH_OP_SHLR8
Definition: disassembler.h:205
@ SH_OP_BSR
Definition: disassembler.h:214
@ SH_OP_JMP
Definition: disassembler.h:216
@ SH_OP_MOVCA
Definition: disassembler.h:224
@ SH_OP_SHAD
Definition: disassembler.h:196
@ SH_OP_JSR
Definition: disassembler.h:217
@ SH_OP_SUBV
Definition: disassembler.h:185
@ SH_OP_CMP_HS
Definition: disassembler.h:162
@ SH_OP_SHAL
Definition: disassembler.h:197
@ SH_OP_SHLR2
Definition: disassembler.h:203
static const ut8 sh_scaling_size[]
Definition: disassembler.h:43
#define SH_BANKED_REG_COUNT
Definition: disassembler.h:14
#define SH_SR_I
SR.I: Interrupt mask level: External interrupts of a lower level than IMASK are masked.
Definition: disassembler.h:53
#define SH_SR_Q
SR.Q: State for divide step (Used by the DIV0S, DIV0U and DIV1 instructions)
Definition: disassembler.h:55
@ SH_REG_IND_GBR
Definition: disassembler.h:92
@ SH_REG_IND_SR
Definition: disassembler.h:91
@ SH_REG_IND_R0
Definition: disassembler.h:72
#define SH_SR_F
SR.FD: FPU disable bit (cleared to 0 by a reset)
Definition: disassembler.h:59
#define SH_SR_S
SR.S: Specifies a saturation operation for a MAC instruction.
Definition: disassembler.h:51
#define SH_REG_SIZE
Definition: disassembler.h:10
@ SH_PC_RELATIVE8
Definition: disassembler.h:28
@ SH_IMM_S
8-bit immediate value (sign-extended)
Definition: disassembler.h:32
@ SH_REG_INDIRECT_DISP
register indirect with displacement
Definition: disassembler.h:23
@ SH_PC_RELATIVE_DISP
Definition: disassembler.h:27
@ SH_REG_DIRECT
Definition: disassembler.h:19
@ SH_PC_RELATIVE_REG
Definition: disassembler.h:30
@ SH_PC_RELATIVE12
Definition: disassembler.h:29
@ SH_REG_INDIRECT_INDEXED
indexed register indirect
Definition: disassembler.h:24
@ SH_REG_INDIRECT_I
register indirect with post-increment
Definition: disassembler.h:21
@ SH_REG_INDIRECT
Definition: disassembler.h:20
@ SH_IMM_U
8-bit immediate value (zero-extended)
Definition: disassembler.h:31
@ SH_REG_INDIRECT_D
register indirect with pre-decrement
Definition: disassembler.h:22
@ SH_GBR_INDIRECT_DISP
Definition: disassembler.h:25
@ SH_GBR_INDIRECT_INDEXED
Definition: disassembler.h:26
#define sh_il_get_privilege()
Definition: sh_il.c:212
static RzILOpEffect * sh_il_rotr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1184
static RzILOpEffect * sh_il_invalid(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:619
#define SH_S_ADDR(x)
Definition: sh_il.c:26
static RzILOpEffect * sh_il_sleep(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1601
static RzILOpPure * sh_il_get_status_reg()
Return the status register (sr), calculated by shifting all the status register bits at the correct o...
Definition: sh_il.c:131
static bool sh_valid_gpr(ut16 reg)
Definition: sh_il.c:44
static RzILOpEffect * sh_il_addc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:699
static RzILOpEffect * sh_il_shad(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1225
static RzILOpEffect * sh_il_movt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:636
static RzILOpEffect * sh_il_shar(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1250
static RzILOpEffect * sh_il_add(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:689
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.
Definition: sh_il.c:289
static RzILOpEffect * sh_il_mov(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:626
static RzILOpEffect * sh_il_movca(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1553
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...
Definition: sh_il.c:122
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...
Definition: sh_il.c:1759
static RzILOpEffect * sh_il_div0u(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:868
static RzILOpEffect * sh_il_bra(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1397
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...
Definition: sh_il.c:82
static RzILOpEffect * sh_il_shll16(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1336
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.
Definition: sh_il.c:570
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...
Definition: sh_il.c:245
static RzILOpEffect * sh_il_subc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1053
static RzILOpEffect * sh_il_jsr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1447
static RzILOpEffect * sh_il_ldc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1499
static RzILOpEffect * sh_il_extu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:927
#define SH_TRUE
Definition: sh_il.c:30
static RzILOpEffect * sh_il_mac(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:950
static RzILOpEffect * sh_il_addv(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:714
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,...
Definition: sh_il.c:536
static RzILOpEffect * sh_il_div1(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:815
static RzILOpEffect * sh_il_sets(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1582
static RzILOpEffect * sh_il_bfs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1365
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...
Definition: sh_il.c:1653
#define SH_FALSE
Definition: sh_il.c:31
static RzILOpEffect * sh_il_cmp_gt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:768
static RzILOpEffect * sh_il_cmp_pz(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:777
static RzILOpEffect * sh_il_negc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1033
static RzILOpEffect * sh_il_cmp_eq(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:732
static RzILOpEffect * sh_il_clrmac(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1466
static RzILOpEffect * sh_il_cmp_pl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:786
#define sh_il_get_reg(reg)
Definition: sh_il.c:234
static RzILOpEffect * sh_il_lds(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1538
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...
Definition: sh_il.c:205
static RzILOpEffect * sh_il_dt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:901
static RzILOpEffect * sh_il_tst(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1145
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...
Definition: sh_il.c:161
static RzILOpEffect * sh_il_clrs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1475
static const sh_il_op sh_ops[SH_OP_SIZE]
Lookup table for the IL lifting handlers for the various instructions.
Definition: sh_il.c:1665
static RzILOpEffect * sh_il_sts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1645
static RzILOpEffect * sh_il_mulu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1012
static RzILOpEffect * sh_il_sub(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1044
static RzILOpBitVector * sh_il_bool_to_bv(RzILOpBool *b)
Convert b to SH_TRUE or SH_FALSE (bool zero-extended to SH_REG_SIZE)
Definition: sh_il.c:110
#define SH_U_ADDR(x)
Definition: sh_il.c:25
static RzILOpEffect * sh_il_sett(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1591
static const char * sh_global_registers[]
Definition: sh_il.c:55
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...
Definition: sh_il.c:222
static bool sh_banked_reg(ut16 reg)
Definition: sh_il.c:48
RzILOpEffect *(* sh_il_op)(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1660
#define sh_il_get_effective_addr(x, y)
Definition: sh_il.c:331
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...
Definition: sh_il.c:276
static RzILOpEffect * sh_il_stc(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1616
static RzILOpEffect * sh_il_cmp_hi(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:759
static RzILOpEffect * sh_il_tas(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1126
static RzILOpEffect * sh_il_shlr16(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1345
static RzILOpEffect * sh_il_cmp_hs(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:741
static RzILOpEffect * sh_il_bf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1354
static RzILOpEffect * sh_il_exts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:914
static RzILOpEffect * sh_il_shll8(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1318
static RzILOpEffect * sh_il_dmulu(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:889
static RzILOpEffect * sh_il_muls(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:999
static RzILOpEffect * sh_il_xtrct(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:674
static RzILOpEffect * sh_il_shal(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1239
static RzILOpEffect * sh_il_swap(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:649
static RzILOpEffect * sh_il_shlr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1289
static RzILOpEffect * sh_il_bsr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1417
static RzILOpEffect * sh_il_rotcr(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1210
static RzILOpEffect * sh_il_rotcl(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1197
static RzILOpEffect * sh_il_mul(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:990
#define SH_U_REG(x)
Definition: sh_il.c:27
static RzILOpEffect * sh_il_cmp_str(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:795
static RzILOpEffect * sh_il_or(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1116
static RzILOpEffect * sh_il_not(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1099
static RzILOpEffect * sh_il_shll2(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1300
static RzILOpEffect * sh_il_cmp_ge(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:750
static RzILOpEffect * sh_il_shld(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1263
static RzILOpEffect * sh_il_bt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1375
static RzILOpEffect * sh_il_shll(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1278
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...
Definition: sh_il.c:192
static RzILOpEffect * sh_il_xor(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1162
#define sh_il_get_effective_addr_param(x)
Definition: sh_il.c:39
#define sh_il_get_pure_param(x)
Definition: sh_il.c:33
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,...
Definition: sh_il.c:501
static RzILOpEffect * sh_il_shlr8(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1327
static RzILOpEffect * sh_il_div0s(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:855
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...
Definition: sh_il.c:407
static RzILOpEffect * sh_il_rts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1457
#define sh_il_get_param(x, y)
Definition: sh_il.c:394
static RzILOpEffect * sh_il_subv(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1068
static const char * sh_get_banked_reg(ut16 reg, ut8 bank)
Get the register name for reg in bank bank.
Definition: sh_il.c:97
#define sh_il_set_param(x, y, z)
Definition: sh_il.c:486
RZ_IPI RzAnalysisILConfig * rz_sh_il_config(RZ_NONNULL RzAnalysis *analysis)
Initialize new config for the SuperH IL.
Definition: sh_il.c:1784
static RzILOpEffect * sh_il_nop(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1562
static RzILOpEffect * sh_il_neg(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1023
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.
Definition: sh_il.c:598
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)
Definition: sh_il.c:1171
#define SH_S_REG(x)
Definition: sh_il.c:28
static RzILOpEffect * sh_il_bts(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1386
static RzILOpEffect * sh_il_shlr2(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1309
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 ...
Definition: sh_il.c:440
static RzILOpEffect * sh_il_and(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1090
#define sh_il_set_pure_param(x, val)
Definition: sh_il.c:36
static RzILOpEffect * sh_il_clrt(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1484
#define sh_il_set_reg(reg, val)
Definition: sh_il.c:256
static RzILOpEffect * sh_il_braf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1407
static RzILOpEffect * sh_il_dmuls(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:877
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.
Definition: sh_il.c:342
static RzILOpEffect * sh_il_rte(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1573
static RzILOpEffect * sh_il_bsrf(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1427
static RzILOpEffect * sh_il_jmp(const SHOp *op, ut64 pc, RzAnalysis *analysis, SHILContext *ctx)
Definition: sh_il.c:1437
#define b(i)
Definition: sha256.c:42
#define cond(bop, top, mask, flags)
Description of the global context of an RzAnalysisILVM.
Definition: rz_analysis.h:1134
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...
Definition: sh_il.h:14
Helper struct to take care of converting operands to IL.
Definition: sh_il.c:261
RzILOpEffect * post
post effect for the operand
Definition: sh_il.c:264
RzILOpPure * pure
pure effect for the operand
Definition: sh_il.c:263
RzILOpEffect * pre
pre effect for the operand
Definition: sh_il.c:262
ut16 param[2]
Definition: disassembler.h:238
SHAddrMode mode
Definition: disassembler.h:239
bool init
Definition: core.c:77
static void post(QUEUE *q, enum uv__work_kind kind)
Definition: threadpool.c:142
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int add(char *argv[])
Definition: ziptool.c:84