Rizin
unix-like reverse engineering framework and cli tools
analysis_v850.c File Reference
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include <rz_analysis.h>
#include <rz_util.h>
#include <rz_endian.h>
#include <v850_disas.h>

Go to the source code of this file.

Macros

#define F1_REG1(instr)   ((instr)&0x1F)
 
#define F1_REG2(instr)   (((instr)&0xF800) >> 11)
 
#define F1_RN1(instr)   (V850_REG_NAMES[F1_REG1(instr)])
 
#define F1_RN2(instr)   (V850_REG_NAMES[F1_REG2(instr)])
 
#define F2_IMM(instr)   F1_REG1(instr)
 
#define F2_REG2(instr)   F1_REG2(instr)
 
#define F2_RN2(instr)   (V850_REG_NAMES[F2_REG2(instr)])
 
#define F3_COND(instr)   ((instr)&0xF)
 
#define F3_DISP(instr)   (((instr)&0x70) >> 4) | (((instr)&0xF800) >> 7)
 
#define F4_DISP(instr)   ((instr)&0x3F)
 
#define F4_REG2(instr)   F1_REG2(instr)
 
#define F4_RN2(instr)   (V850_REG_NAMES[F4_REG2(instr)])
 
#define F5_REG2(instr)   F1_REG2(instr)
 
#define F5_DISP(instr)   ((((ut32)(instr)&0xffff) << 31) | (((ut32)(instr)&0xffff0000) << 1))
 
#define F5_RN2(instr)   (V850_REG_NAMES[F5_REG2(instr)])
 
#define F6_REG1(instr)   F1_REG1(instr)
 
#define F6_REG2(instr)   F1_REG2(instr)
 
#define F6_IMM(instr)   (((instr)&0xFFFF0000) >> 16)
 
#define F6_RN1(instr)   (V850_REG_NAMES[F6_REG1(instr)])
 
#define F6_RN2(instr)   (V850_REG_NAMES[F6_REG2(instr)])
 
#define F7_REG1(instr)   F1_REG1(instr)
 
#define F7_REG2(instr)   F1_REG2(instr)
 
#define F7_DISP(instr)   F6_IMM(instr)
 
#define F7_RN1(instr)   (V850_REG_NAMES[F7_REG1(instr)])
 
#define F7_RN2(instr)   (V850_REG_NAMES[F7_REG2(instr)])
 
#define F8_REG1(instr)   F1_REG1(instr)
 
#define F8_DISP(instr)   F6_IMM(instr)
 
#define F8_BIT(instr)   (((instr)&0x3800) >> 11)
 
#define F8_SUB(instr)   (((instr)&0xC000) >> 14)
 
#define F8_RN1(instr)   (V850_REG_NAMES[F8_REG1(instr)])
 
#define F8_RN2(instr)   (V850_REG_NAMES[F8_REG2(instr)])
 
#define F9_REG1(instr)   F1_REG1(instr)
 
#define F9_REG2(instr)   F1_REG2(instr)
 
#define F9_SUB(instr)   (((instr)&0x7E00000) >> 21)
 
#define F9_RN1(instr)   (V850_REG_NAMES[F9_REG1(instr)])
 
#define F9_RN2(instr)   (V850_REG_NAMES[F9_REG2(instr)])
 
#define F11_REG1(instr)   F1_REG1(instr)
 
#define F11_REG2(instr)   F1_REG2(instr)
 
#define F11_REG3(instr)   (((instr)&0xF8000000) >> 27)
 
#define F11_SUB(instr)   ((((instr)&0x7E00000) >> 20) | (((instr)&2) >> 1))
 
#define F11_RN1(instr)   (V850_REG_NAMES[F11_REG1(instr)])
 
#define F11_RN2(instr)   (V850_REG_NAMES[F11_REG2(instr)])
 
#define F12_IMM(instr)   (F1_REG1(instr) | (((instr)&0x7C0000) >> 13))
 
#define F12_REG2(instr)   F1_REG2(instr)
 
#define F12_REG3(instr)   (((instr)&0xF8000000) >> 27)
 
#define F12_SUB(instr)   ((((instr)&0x7800001) >> 22) | (((instr)&2) >> 1))
 
#define F12_RN2(instr)   (V850_REG_NAMES[F12_REG2(instr)])
 
#define F12_RN3(instr)   (V850_REG_NAMES[F12_REG3(instr)])
 
#define F13_IMM(instr)   (((instr)&0x3E) >> 1)
 
#define F13_REG2(instr)   (((instr)&0x1F0000) >> 16)
 
#define F13_LIST(instr)   (((instr) && 0xFFE00000) >> 21)
 
#define F13_RN2(instr)   (V850_REG_NAMES[F13_REG2(instr)])
 
#define KW(d, ds, m, ms)   rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))
 

Functions

static void update_flags (RzAnalysisOp *op, int flags)
 
static void clear_flags (RzAnalysisOp *op, int flags)
 
static int v850_op (RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 
static char * get_reg_profile (RzAnalysis *analysis)
 
static RzListanalysis_preludes (RzAnalysis *analysis)
 
static int archinfo (RzAnalysis *analysis, int q)
 

Variables

static const char * V850_REG_NAMES []
 
RzAnalysisPlugin rz_analysis_plugin_v850
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ F11_REG1

#define F11_REG1 (   instr)    F1_REG1(instr)

Definition at line 79 of file analysis_v850.c.

◆ F11_REG2

#define F11_REG2 (   instr)    F1_REG2(instr)

Definition at line 80 of file analysis_v850.c.

◆ F11_REG3

#define F11_REG3 (   instr)    (((instr)&0xF8000000) >> 27)

Definition at line 81 of file analysis_v850.c.

◆ F11_RN1

#define F11_RN1 (   instr)    (V850_REG_NAMES[F11_REG1(instr)])

Definition at line 84 of file analysis_v850.c.

◆ F11_RN2

#define F11_RN2 (   instr)    (V850_REG_NAMES[F11_REG2(instr)])

Definition at line 85 of file analysis_v850.c.

◆ F11_SUB

#define F11_SUB (   instr)    ((((instr)&0x7E00000) >> 20) | (((instr)&2) >> 1))

Definition at line 82 of file analysis_v850.c.

◆ F12_IMM

#define F12_IMM (   instr)    (F1_REG1(instr) | (((instr)&0x7C0000) >> 13))

Definition at line 87 of file analysis_v850.c.

◆ F12_REG2

#define F12_REG2 (   instr)    F1_REG2(instr)

Definition at line 88 of file analysis_v850.c.

◆ F12_REG3

#define F12_REG3 (   instr)    (((instr)&0xF8000000) >> 27)

Definition at line 89 of file analysis_v850.c.

◆ F12_RN2

#define F12_RN2 (   instr)    (V850_REG_NAMES[F12_REG2(instr)])

Definition at line 92 of file analysis_v850.c.

◆ F12_RN3

#define F12_RN3 (   instr)    (V850_REG_NAMES[F12_REG3(instr)])

Definition at line 93 of file analysis_v850.c.

◆ F12_SUB

#define F12_SUB (   instr)    ((((instr)&0x7800001) >> 22) | (((instr)&2) >> 1))

Definition at line 90 of file analysis_v850.c.

◆ F13_IMM

#define F13_IMM (   instr)    (((instr)&0x3E) >> 1)

Definition at line 96 of file analysis_v850.c.

◆ F13_LIST

#define F13_LIST (   instr)    (((instr) && 0xFFE00000) >> 21)

Definition at line 99 of file analysis_v850.c.

◆ F13_REG2

#define F13_REG2 (   instr)    (((instr)&0x1F0000) >> 16)

Definition at line 98 of file analysis_v850.c.

◆ F13_RN2

#define F13_RN2 (   instr)    (V850_REG_NAMES[F13_REG2(instr)])

Definition at line 101 of file analysis_v850.c.

◆ F1_REG1

#define F1_REG1 (   instr)    ((instr)&0x1F)

Definition at line 16 of file analysis_v850.c.

◆ F1_REG2

#define F1_REG2 (   instr)    (((instr)&0xF800) >> 11)

Definition at line 17 of file analysis_v850.c.

◆ F1_RN1

#define F1_RN1 (   instr)    (V850_REG_NAMES[F1_REG1(instr)])

Definition at line 19 of file analysis_v850.c.

◆ F1_RN2

#define F1_RN2 (   instr)    (V850_REG_NAMES[F1_REG2(instr)])

Definition at line 20 of file analysis_v850.c.

◆ F2_IMM

#define F2_IMM (   instr)    F1_REG1(instr)

Definition at line 23 of file analysis_v850.c.

◆ F2_REG2

#define F2_REG2 (   instr)    F1_REG2(instr)

Definition at line 24 of file analysis_v850.c.

◆ F2_RN2

#define F2_RN2 (   instr)    (V850_REG_NAMES[F2_REG2(instr)])

Definition at line 26 of file analysis_v850.c.

◆ F3_COND

#define F3_COND (   instr)    ((instr)&0xF)

Definition at line 29 of file analysis_v850.c.

◆ F3_DISP

#define F3_DISP (   instr)    (((instr)&0x70) >> 4) | (((instr)&0xF800) >> 7)

Definition at line 30 of file analysis_v850.c.

◆ F4_DISP

#define F4_DISP (   instr)    ((instr)&0x3F)

Definition at line 33 of file analysis_v850.c.

◆ F4_REG2

#define F4_REG2 (   instr)    F1_REG2(instr)

Definition at line 34 of file analysis_v850.c.

◆ F4_RN2

#define F4_RN2 (   instr)    (V850_REG_NAMES[F4_REG2(instr)])

Definition at line 36 of file analysis_v850.c.

◆ F5_DISP

#define F5_DISP (   instr)    ((((ut32)(instr)&0xffff) << 31) | (((ut32)(instr)&0xffff0000) << 1))

Definition at line 40 of file analysis_v850.c.

◆ F5_REG2

#define F5_REG2 (   instr)    F1_REG2(instr)

Definition at line 39 of file analysis_v850.c.

◆ F5_RN2

#define F5_RN2 (   instr)    (V850_REG_NAMES[F5_REG2(instr)])

Definition at line 41 of file analysis_v850.c.

◆ F6_IMM

#define F6_IMM (   instr)    (((instr)&0xFFFF0000) >> 16)

Definition at line 46 of file analysis_v850.c.

◆ F6_REG1

#define F6_REG1 (   instr)    F1_REG1(instr)

Definition at line 44 of file analysis_v850.c.

◆ F6_REG2

#define F6_REG2 (   instr)    F1_REG2(instr)

Definition at line 45 of file analysis_v850.c.

◆ F6_RN1

#define F6_RN1 (   instr)    (V850_REG_NAMES[F6_REG1(instr)])

Definition at line 48 of file analysis_v850.c.

◆ F6_RN2

#define F6_RN2 (   instr)    (V850_REG_NAMES[F6_REG2(instr)])

Definition at line 49 of file analysis_v850.c.

◆ F7_DISP

#define F7_DISP (   instr)    F6_IMM(instr)

Definition at line 54 of file analysis_v850.c.

◆ F7_REG1

#define F7_REG1 (   instr)    F1_REG1(instr)

Definition at line 52 of file analysis_v850.c.

◆ F7_REG2

#define F7_REG2 (   instr)    F1_REG2(instr)

Definition at line 53 of file analysis_v850.c.

◆ F7_RN1

#define F7_RN1 (   instr)    (V850_REG_NAMES[F7_REG1(instr)])

Definition at line 56 of file analysis_v850.c.

◆ F7_RN2

#define F7_RN2 (   instr)    (V850_REG_NAMES[F7_REG2(instr)])

Definition at line 57 of file analysis_v850.c.

◆ F8_BIT

#define F8_BIT (   instr)    (((instr)&0x3800) >> 11)

Definition at line 62 of file analysis_v850.c.

◆ F8_DISP

#define F8_DISP (   instr)    F6_IMM(instr)

Definition at line 61 of file analysis_v850.c.

◆ F8_REG1

#define F8_REG1 (   instr)    F1_REG1(instr)

Definition at line 60 of file analysis_v850.c.

◆ F8_RN1

#define F8_RN1 (   instr)    (V850_REG_NAMES[F8_REG1(instr)])

Definition at line 65 of file analysis_v850.c.

◆ F8_RN2

#define F8_RN2 (   instr)    (V850_REG_NAMES[F8_REG2(instr)])

Definition at line 66 of file analysis_v850.c.

◆ F8_SUB

#define F8_SUB (   instr)    (((instr)&0xC000) >> 14)

Definition at line 63 of file analysis_v850.c.

◆ F9_REG1

#define F9_REG1 (   instr)    F1_REG1(instr)

Definition at line 70 of file analysis_v850.c.

◆ F9_REG2

#define F9_REG2 (   instr)    F1_REG2(instr)

Definition at line 71 of file analysis_v850.c.

◆ F9_RN1

#define F9_RN1 (   instr)    (V850_REG_NAMES[F9_REG1(instr)])

Definition at line 74 of file analysis_v850.c.

◆ F9_RN2

#define F9_RN2 (   instr)    (V850_REG_NAMES[F9_REG2(instr)])

Definition at line 75 of file analysis_v850.c.

◆ F9_SUB

#define F9_SUB (   instr)    (((instr)&0x7E00000) >> 21)

Definition at line 72 of file analysis_v850.c.

◆ KW

#define KW (   d,
  ds,
  m,
  ms 
)    rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))

Function Documentation

◆ analysis_preludes()

static RzList* analysis_preludes ( RzAnalysis analysis)
static

Definition at line 558 of file analysis_v850.c.

558  {
559 #define KW(d, ds, m, ms) rz_list_append(l, rz_search_keyword_new((const ut8 *)d, ds, (const ut8 *)m, ms, NULL))
561  KW("\x80\x07", 2, "\xf0\xff", 2);
562  KW("\x50\x1a\x63\x0f", 4, "\xf0\xff\xff\x0f", 4);
563  return l;
564 }
#define KW(d, ds, m, ms)
RZ_API void rz_search_keyword_free(RzSearchKeyword *kw)
Definition: keyword.c:49
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11

References KW, rz_list_newf(), and rz_search_keyword_free().

◆ archinfo()

static int archinfo ( RzAnalysis analysis,
int  q 
)
static

Definition at line 566 of file analysis_v850.c.

566  {
567  switch (q) {
569  return 2;
571  return 8;
573  return 2;
574  }
575  return 0;
576 }
#define RZ_ANALYSIS_ARCHINFO_ALIGN
Definition: rz_analysis.h:100
#define RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE
Definition: rz_analysis.h:99
#define RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE
Definition: rz_analysis.h:98

References RZ_ANALYSIS_ARCHINFO_ALIGN, RZ_ANALYSIS_ARCHINFO_MAX_OP_SIZE, and RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE.

◆ clear_flags()

static void clear_flags ( RzAnalysisOp op,
int  flags 
)
static

Definition at line 153 of file analysis_v850.c.

153  {
154  if (flags & V850_FLAG_CY) {
155  rz_strbuf_append(&op->esil, ",0,cy,=");
156  }
157  if (flags & V850_FLAG_OV) {
158  rz_strbuf_append(&op->esil, ",0,ov,=");
159  }
160  if (flags & V850_FLAG_S) {
161  rz_strbuf_append(&op->esil, ",0,s,=");
162  }
163  if (flags & V850_FLAG_Z) {
164  rz_strbuf_append(&op->esil, ",0,z,=");
165  }
166 }
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: dis.c:32
@ V850_FLAG_CY
Definition: v850_disas.h:166
@ V850_FLAG_OV
Definition: v850_disas.h:167
@ V850_FLAG_S
Definition: v850_disas.h:168
@ V850_FLAG_Z
Definition: v850_disas.h:169

References flags, rz_strbuf_append(), V850_FLAG_CY, V850_FLAG_OV, V850_FLAG_S, and V850_FLAG_Z.

Referenced by v850_op().

◆ get_reg_profile()

static char* get_reg_profile ( RzAnalysis analysis)
static

Definition at line 491 of file analysis_v850.c.

491  {
492  const char *p =
493  "=PC pc\n"
494  "=SP r3\n"
495  "=ZF z\n"
496  "=A0 r1\n"
497  "=A1 r5\n"
498  "=A2 r6\n"
499  "=A3 r7\n"
500  "=A4 r8\n"
501  "=SF s\n"
502  "=OF ov\n"
503  "=CF cy\n"
504 
505  "gpr zero .32 ? 0\n"
506  "gpr r0 .32 0 0\n"
507  "gpr r1 .32 4 0\n"
508  "gpr r2 .32 8 0\n"
509  "gpr r3 .32 12 0\n"
510  "gpr sp .32 12 0\n"
511  "gpr r4 .32 16 0\n"
512  "gpr gp .32 16 0\n"
513  "gpr r5 .32 20 0\n"
514  "gpr tp .32 20 0\n"
515  "gpr r6 .32 24 0\n"
516  "gpr r7 .32 28 0\n"
517  "gpr r8 .32 32 0\n"
518  "gpr r9 .32 36 0\n"
519  "gpr r10 .32 40 0\n"
520  "gpr r11 .32 44 0\n"
521  "gpr r12 .32 48 0\n"
522  "gpr r13 .32 52 0\n"
523  "gpr r14 .32 56 0\n"
524  "gpr r15 .32 60 0\n"
525  "gpr r16 .32 64 0\n"
526  "gpr r17 .32 68 0\n"
527  "gpr r18 .32 72 0\n"
528  "gpr r19 .32 76 0\n"
529  "gpr r20 .32 80 0\n"
530  "gpr r21 .32 84 0\n"
531  "gpr r22 .32 88 0\n"
532  "gpr r23 .32 92 0\n"
533  "gpr r24 .32 96 0\n"
534  "gpr r25 .32 100 0\n"
535  "gpr r26 .32 104 0\n"
536  "gpr r27 .32 108 0\n"
537  "gpr r28 .32 112 0\n"
538  "gpr r29 .32 116 0\n"
539  "gpr r30 .32 120 0\n"
540  "gpr ep .32 120 0\n"
541  "gpr r31 .32 124 0\n"
542  "gpr lp .32 124 0\n"
543  "gpr pc .32 128 0\n"
544 
545  // 32bit [ RFU ][NP EP ID SAT CY OV S Z]
546  "gpr psw .32 132 0\n" // program status word
547  "gpr npi .1 132.16 0\n" // non maskerable interrupt (NMI)
548  "gpr epi .1 132.17 0\n" // exception processing interrupt
549  "gpr id .1 132.18 0\n" // :? should be id
550  "gpr sat .1 132.19 0\n" // saturation detection
551  "flg cy .1 132.28 0\n" // carry or borrow
552  "flg ov .1 132.29 0\n" // overflow
553  "flg s .1 132.30 0\n" // signed result
554  "flg z .1 132.31 0\n"; // zero result
555  return strdup(p);
556 }
void * p
Definition: libc.cpp:67
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")

References p, and strdup().

◆ update_flags()

static void update_flags ( RzAnalysisOp op,
int  flags 
)
static

Definition at line 138 of file analysis_v850.c.

138  {
139  if (flags & V850_FLAG_CY) {
140  rz_strbuf_append(&op->esil, "31,$c,cy,:=");
141  }
142  if (flags & V850_FLAG_OV) {
143  rz_strbuf_append(&op->esil, ",31,$o,ov,:=");
144  }
145  if (flags & V850_FLAG_S) {
146  rz_strbuf_append(&op->esil, ",31,$s,s,:=");
147  }
148  if (flags & V850_FLAG_Z) {
149  rz_strbuf_append(&op->esil, ",$z,z,:=");
150  }
151 }

References flags, rz_strbuf_append(), V850_FLAG_CY, V850_FLAG_OV, V850_FLAG_S, and V850_FLAG_Z.

Referenced by v850_op().

◆ v850_op()

static int v850_op ( RzAnalysis analysis,
RzAnalysisOp op,
ut64  addr,
const ut8 buf,
int  len,
RzAnalysisOpMask  mask 
)
static

Definition at line 168 of file analysis_v850.c.

168  {
169  int ret = 0;
170  ut8 opcode = 0;
171  const char *reg1 = NULL;
172  const char *reg2 = NULL;
173  ut32 bitmask = 0;
174  ut16 destaddr = 0;
175  st16 destaddrs = 0;
176  ut16 word1 = 0, word2 = 0;
177  struct v850_cmd cmd;
178 
179  if (len < 1 || (len > 0 && !memcmp(buf, "\xff\xff\xff\xff\xff\xff", RZ_MIN(len, 6)))) {
180  return -1;
181  }
182 
183  memset(&cmd, 0, sizeof(cmd));
184 
185  ret = op->size = v850_decode_command(buf, len, &cmd);
186 
187  if (ret < 1) {
188  return ret;
189  }
190 
191  op->addr = addr;
192 
193  word1 = rz_read_le16(buf);
194  if (ret == 4) {
195  word2 = rz_read_le16(buf + 2);
196  }
197  opcode = get_opcode(word1);
198 
199  switch (opcode) {
200  case V850_MOV_IMM5:
201  case V850_MOV:
202  // 2 formats
203  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
204  if (opcode != V850_MOV_IMM5) { // Format I
205  rz_strbuf_appendf(&op->esil, "%s,%s,=", F1_RN1(word1), F1_RN2(word1));
206  } else { // Format II
207  rz_strbuf_appendf(&op->esil, "%" PFMT64d ",%s,=", (st64)(F2_IMM(word1)), F2_RN2(word1));
208  }
209  break;
210  case V850_MOVEA:
211  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
212  // FIXME: to decide about reading 16/32 bit and use only macros to access
213  rz_strbuf_appendf(&op->esil, "%s,0xffff,&,%u,+,%s,=", F6_RN1(word1), word2, F6_RN2(word1));
214  break;
215  case V850_SLDB:
216  case V850_SLDH:
217  case V850_SLDW:
219  if (F4_REG2(word1) == V850_SP) {
220  op->stackop = RZ_ANALYSIS_STACK_GET;
221  op->stackptr = 0;
222  op->ptr = 0;
223  }
224  break;
225  case V850_SSTB:
226  case V850_SSTH:
227  case V850_SSTW:
229  if (F4_REG2(word1) == V850_SP) {
230  op->stackop = RZ_ANALYSIS_STACK_SET;
231  op->stackptr = 0;
232  op->ptr = 0;
233  }
234  break;
235  case V850_NOT:
236  op->type = RZ_ANALYSIS_OP_TYPE_NOT;
237  rz_strbuf_appendf(&op->esil, "%s,0xffffffff,^,%s,=", F1_RN1(word1), F1_RN2(word1));
240  break;
241  case V850_DIVH:
242  op->type = RZ_ANALYSIS_OP_TYPE_DIV;
243  rz_strbuf_appendf(&op->esil, "%s,%s,0xffff,&,/,%s,=",
244  F1_RN1(word1), F1_RN2(word1), F1_RN2(word1));
246  break;
247  case V850_JMP:
248  if (F1_REG1(word1) == 31) {
249  op->type = RZ_ANALYSIS_OP_TYPE_RET;
250  } else {
252  }
253  op->jump = word1; // UT64_MAX; // this is n RJMP instruction .. F1_RN1 (word1);
254  op->fail = addr + 2;
255  rz_strbuf_appendf(&op->esil, "%s,pc,=", F1_RN1(word1));
256  break;
257  case V850_JARL2:
258  // TODO: fix displacement reading
259  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
260  op->jump = addr + F5_DISP(((ut32)word2 << 16) | word1);
261  op->fail = addr + 4;
262  rz_strbuf_appendf(&op->esil, "pc,%s,=,pc,%u,+=", F5_RN2(word1), F5_DISP(((ut32)word2 << 16) | word1));
263  break;
264 #if 0 // same opcode as JARL?
265  case V850_JR:
266  jumpdisp = DISP26(word1, word2);
267  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
268  rz_strbuf_appendf (&op->esil, "$$,%d,+,pc,=", jumpdisp);
269  break;
270 #endif
271  case V850_OR:
272  op->type = RZ_ANALYSIS_OP_TYPE_OR;
273  rz_strbuf_appendf(&op->esil, "%s,%s,|=", F1_RN1(word1), F1_RN2(word1));
276  break;
277  case V850_ORI:
278  op->type = RZ_ANALYSIS_OP_TYPE_OR;
279  rz_strbuf_appendf(&op->esil, "%hu,%s,|,%s,=",
280  word2, F6_RN1(word1), F6_RN2(word1));
283  break;
284  case V850_MULH:
285  case V850_MULH_IMM5:
286  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
287  break;
288  case V850_XOR:
289  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
290  rz_strbuf_appendf(&op->esil, "%s,%s,^=", F1_RN1(word1), F1_RN2(word1));
293  break;
294  case V850_XORI:
295  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
296  rz_strbuf_appendf(&op->esil, "%hu,%s,^,%s,=", word2, F6_RN1(word1), F6_RN2(word1));
299  break;
300  case V850_AND:
301  op->type = RZ_ANALYSIS_OP_TYPE_AND;
302  rz_strbuf_appendf(&op->esil, "%s,%s,&=", F1_RN1(word1), F1_RN2(word1));
305  break;
306  case V850_ANDI:
307  op->type = RZ_ANALYSIS_OP_TYPE_AND;
308  rz_strbuf_appendf(&op->esil, "%hu,%s,&,%s,=", word2, F6_RN1(word1), F6_RN2(word1));
311  break;
312  case V850_CMP:
313  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
314  rz_strbuf_appendf(&op->esil, "%s,%s,==", F1_RN1(word1), F1_RN2(word1));
315  update_flags(op, -1);
316  break;
317  case V850_CMP_IMM5:
318  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
319  rz_strbuf_appendf(&op->esil, "%d,%s,==", (st8)SIGN_EXT_T5(F2_IMM(word1)), F2_RN2(word1));
320  update_flags(op, -1);
321  break;
322  case V850_TST:
323  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
324  rz_strbuf_appendf(&op->esil, "%s,%s,&", F1_RN1(word1), F1_RN2(word1));
327  break;
328  case V850_SUB:
329  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
330  rz_strbuf_appendf(&op->esil, "%s,%s,-=", F1_RN1(word1), F1_RN2(word1));
331  update_flags(op, -1);
332  break;
333  case V850_SUBR:
334  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
335  rz_strbuf_appendf(&op->esil, "%s,%s,-,%s=", F1_RN2(word1), F1_RN1(word1), F1_RN2(word1));
336  update_flags(op, -1);
337  break;
338  case V850_ADD:
339  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
340  rz_strbuf_appendf(&op->esil, "%s,%s,+=", F1_RN1(word1), F1_RN2(word1));
341  update_flags(op, -1);
342  break;
343  case V850_ADD_IMM5:
344  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
345  if (F2_REG2(word1) == V850_SP) {
346  op->stackop = RZ_ANALYSIS_STACK_INC;
347  op->stackptr = F2_IMM(word1);
348  op->val = op->stackptr;
349  }
350  rz_strbuf_appendf(&op->esil, "%d,%s,+=", (st8)SIGN_EXT_T5(F2_IMM(word1)), F2_RN2(word1));
351  update_flags(op, -1);
352  break;
353  case V850_ADDI:
354  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
355  if (F6_REG2(word1) == V850_SP) {
356  op->stackop = RZ_ANALYSIS_STACK_INC;
357  op->stackptr = (st64)word2;
358  op->val = op->stackptr;
359  }
360  rz_strbuf_appendf(&op->esil, "%d,%s,+,%s,=", (st32)word2, F6_RN1(word1), F6_RN2(word1));
361  update_flags(op, -1);
362  break;
363  case V850_SHR_IMM5:
364  op->type = RZ_ANALYSIS_OP_TYPE_SHR;
365  rz_strbuf_appendf(&op->esil, "%u,%s,>>=", (ut8)F2_IMM(word1), F2_RN2(word1));
368  break;
369  case V850_SAR_IMM5:
370  op->type = RZ_ANALYSIS_OP_TYPE_SAR;
371  ut16 imm5 = F2_IMM(word1);
372  reg2 = F2_RN2(word1);
373  rz_strbuf_appendf(&op->esil, "31,%s,>>,?{,%u,32,-,%u,1,<<,--,<<,}{,0,},%u,%s,>>,|,%s,=", reg2, (ut8)imm5, (ut8)imm5, (ut8)imm5, reg2, reg2);
376  break;
377  case V850_SHL_IMM5:
378  op->type = RZ_ANALYSIS_OP_TYPE_SHL;
379  rz_strbuf_appendf(&op->esil, "%u,%s,<<=", (ut8)F2_IMM(word1), F2_RN2(word1));
382  break;
383  case V850_BCOND:
384  case V850_BCOND2:
385  case V850_BCOND3:
386  case V850_BCOND4:
387  destaddr = ((((word1 >> 4) & 0x7) |
388  ((word1 >> 11) << 3))
389  << 1);
390  if (destaddr & 0x100) {
391  destaddrs = destaddr | 0xFE00;
392  } else {
393  destaddrs = destaddr;
394  }
395  op->jump = addr + destaddrs;
396  op->fail = addr + 2;
398  switch (F3_COND(word1)) {
399  case V850_COND_V:
400  rz_strbuf_appendf(&op->esil, "ov");
401  break;
402  case V850_COND_CL:
403  rz_strbuf_appendf(&op->esil, "cy");
404  break;
405  case V850_COND_ZE:
406  rz_strbuf_appendf(&op->esil, "z");
407  break;
408  case V850_COND_NH:
409  rz_strbuf_appendf(&op->esil, "cy,z,|");
410  break;
411  case V850_COND_N:
412  rz_strbuf_appendf(&op->esil, "s");
413  break;
414  case V850_COND_AL: // Always
415  rz_strbuf_appendf(&op->esil, "1");
416  break;
417  case V850_COND_LT:
418  rz_strbuf_appendf(&op->esil, "s,ov,^");
419  break;
420  case V850_COND_LE:
421  rz_strbuf_appendf(&op->esil, "s,ov,^,z,|");
422  break;
423  case V850_COND_NV:
424  rz_strbuf_appendf(&op->esil, "ov,!");
425  break;
426  case V850_COND_NL:
427  rz_strbuf_appendf(&op->esil, "cy,!");
428  break;
429  case V850_COND_NE:
430  rz_strbuf_appendf(&op->esil, "z,!");
431  break;
432  case V850_COND_H:
433  rz_strbuf_appendf(&op->esil, "cy,z,|,!");
434  break;
435  case V850_COND_P:
436  rz_strbuf_appendf(&op->esil, "s,!");
437  break;
438  case V850_COND_GE:
439  rz_strbuf_appendf(&op->esil, "s,ov,^,!");
440  break;
441  case V850_COND_GT:
442  rz_strbuf_appendf(&op->esil, "s,ov,^,z,|,!");
443  break;
444  }
445  rz_strbuf_appendf(&op->esil, ",?{,$$,%d,+,pc,=,}", destaddrs);
446  break;
447  case V850_BIT_MANIP: {
448  ut8 bitop = word1 >> 14;
449  switch (bitop) {
450  case V850_BIT_CLR1:
451  bitmask = (1 << F8_BIT(word1));
452  rz_strbuf_appendf(&op->esil, "%hu,%s,+,[1],%u,&,%hu,%s,+,=[1]", word2, F8_RN1(word1), bitmask, word2, F8_RN1(word1));
453  // TODO: Read the value of the memory byte and set zero flag accordingly!
454  break;
455  case V850_BIT_NOT1:
456  bitmask = (1 << F8_BIT(word1));
457  rz_strbuf_appendf(&op->esil, "%hu,%s,+,[1],%u,^,%hu,%s,+,=[1]", word2, F8_RN1(word1), bitmask, word2, F8_RN1(word1));
458  // TODO: Read the value of the memory byte and set zero flag accordingly!
459  break;
460  }
461  } break;
462  case V850_EXT1:
463  switch (get_subopcode(word1 | (ut32)word2 << 16)) {
464  case V850_EXT_SHL:
465  op->type = RZ_ANALYSIS_OP_TYPE_SHL;
466  rz_strbuf_appendf(&op->esil, "%s,%s,<<=", F9_RN1(word1), F9_RN2(word1));
469  break;
470  case V850_EXT_SHR:
471  op->type = RZ_ANALYSIS_OP_TYPE_SHR;
472  rz_strbuf_appendf(&op->esil, "%s,%s,>>=", F9_RN1(word1), F9_RN2(word1));
475  break;
476  case V850_EXT_SAR:
477  op->type = RZ_ANALYSIS_OP_TYPE_SAR;
478  reg1 = F9_RN1(word1);
479  reg2 = F9_RN2(word1);
480  rz_strbuf_appendf(&op->esil, "31,%s,>>,?{,%s,32,-,%s,1,<<,--,<<,}{,0,},%s,%s,>>,|,%s,=", reg2, reg1, reg1, reg1, reg2, reg2);
483  break;
484  }
485  break;
486  }
487 
488  return ret;
489 }
size_t len
Definition: 6502dis.c:15
#define F5_DISP(instr)
Definition: analysis_v850.c:40
#define F8_BIT(instr)
Definition: analysis_v850.c:62
static void update_flags(RzAnalysisOp *op, int flags)
#define F1_REG1(instr)
Definition: analysis_v850.c:16
#define F2_REG2(instr)
Definition: analysis_v850.c:24
#define F6_REG2(instr)
Definition: analysis_v850.c:45
#define F3_COND(instr)
Definition: analysis_v850.c:29
#define F2_RN2(instr)
Definition: analysis_v850.c:26
#define F9_RN2(instr)
Definition: analysis_v850.c:75
#define F6_RN1(instr)
Definition: analysis_v850.c:48
#define F5_RN2(instr)
Definition: analysis_v850.c:41
static void clear_flags(RzAnalysisOp *op, int flags)
#define F1_RN1(instr)
Definition: analysis_v850.c:19
#define F9_RN1(instr)
Definition: analysis_v850.c:74
#define F4_REG2(instr)
Definition: analysis_v850.c:34
#define F8_RN1(instr)
Definition: analysis_v850.c:65
#define F1_RN2(instr)
Definition: analysis_v850.c:20
#define F2_IMM(instr)
Definition: analysis_v850.c:23
#define F6_RN2(instr)
Definition: analysis_v850.c:49
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
uint16_t ut16
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
#define get_opcode(insn)
Definition: libhppa.h:348
@ RZ_ANALYSIS_STACK_SET
Definition: rz_analysis.h:459
@ RZ_ANALYSIS_STACK_GET
Definition: rz_analysis.h:458
@ RZ_ANALYSIS_STACK_INC
Definition: rz_analysis.h:457
@ RZ_ANALYSIS_OP_TYPE_CMP
Definition: rz_analysis.h:399
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_LOAD
Definition: rz_analysis.h:416
@ RZ_ANALYSIS_OP_TYPE_MUL
Definition: rz_analysis.h:404
@ RZ_ANALYSIS_OP_TYPE_JMP
Definition: rz_analysis.h:368
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_SAR
Definition: rz_analysis.h:409
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_OR
Definition: rz_analysis.h:410
@ RZ_ANALYSIS_OP_TYPE_STORE
Definition: rz_analysis.h:415
@ RZ_ANALYSIS_OP_TYPE_SHR
Definition: rz_analysis.h:406
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_DIV
Definition: rz_analysis.h:405
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_SHL
Definition: rz_analysis.h:407
@ RZ_ANALYSIS_OP_TYPE_NOT
Definition: rz_analysis.h:414
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define PFMT64d
Definition: rz_types.h:394
#define st8
Definition: rz_types_base.h:16
#define RZ_MIN(x, y)
#define st64
Definition: rz_types_base.h:10
#define st16
Definition: rz_types_base.h:14
#define st32
Definition: rz_types_base.h:12
#define SIGN_EXT_T5(imm)
Definition: v810_disas.h:15
#define DISP26(word1, word2)
Definition: v810_disas.h:20
int v850_decode_command(const ut8 *instr, int len, struct v850_cmd *cmd)
Definition: v850_disas.c:301
@ V850_SP
Definition: v850_disas.h:119
@ V850_EXT_SHL
Definition: v850_disas.h:102
@ V850_EXT_SHR
Definition: v850_disas.h:100
@ V850_EXT_SAR
Definition: v850_disas.h:101
@ V850_BIT_NOT1
Definition: v850_disas.h:90
@ V850_BIT_CLR1
Definition: v850_disas.h:91
@ V850_COND_H
Definition: v850_disas.h:80
@ V850_COND_ZE
Definition: v850_disas.h:69
@ V850_COND_LT
Definition: v850_disas.h:73
@ V850_COND_N
Definition: v850_disas.h:71
@ V850_COND_V
Definition: v850_disas.h:67
@ V850_COND_CL
Definition: v850_disas.h:68
@ V850_COND_NL
Definition: v850_disas.h:76
@ V850_COND_P
Definition: v850_disas.h:81
@ V850_COND_NE
Definition: v850_disas.h:78
@ V850_COND_GE
Definition: v850_disas.h:84
@ V850_COND_NV
Definition: v850_disas.h:75
@ V850_COND_GT
Definition: v850_disas.h:85
@ V850_COND_AL
Definition: v850_disas.h:72
@ V850_COND_LE
Definition: v850_disas.h:74
@ V850_COND_NH
Definition: v850_disas.h:70
static ut8 get_subopcode(const ut16 instr)
Definition: v850_disas.h:184
@ V850_MULH_IMM5
Definition: v850_disas.h:37
@ V850_SAR_IMM5
Definition: v850_disas.h:35
@ V850_SLDB
Definition: v850_disas.h:38
@ V850_BIT_MANIP
Definition: v850_disas.h:62
@ V850_AND
Definition: v850_disas.h:24
@ V850_TST
Definition: v850_disas.h:25
@ V850_ADDI
Definition: v850_disas.h:48
@ V850_SLDH
Definition: v850_disas.h:40
@ V850_SUBR
Definition: v850_disas.h:26
@ V850_ADD
Definition: v850_disas.h:28
@ V850_CMP_IMM5
Definition: v850_disas.h:33
@ V850_EXT1
Definition: v850_disas.h:63
@ V850_XORI
Definition: v850_disas.h:53
@ V850_JMP
Definition: v850_disas.h:17
@ V850_SHR_IMM5
Definition: v850_disas.h:34
@ V850_OR
Definition: v850_disas.h:22
@ V850_SUB
Definition: v850_disas.h:27
@ V850_DIVH
Definition: v850_disas.h:16
@ V850_BCOND4
Definition: v850_disas.h:47
@ V850_ORI
Definition: v850_disas.h:52
@ V850_MOV_IMM5
Definition: v850_disas.h:30
@ V850_NOT
Definition: v850_disas.h:15
@ V850_MOVEA
Definition: v850_disas.h:49
@ V850_MOV
Definition: v850_disas.h:14
@ V850_SLDW
Definition: v850_disas.h:42
@ V850_SSTH
Definition: v850_disas.h:41
@ V850_BCOND3
Definition: v850_disas.h:46
@ V850_MULH
Definition: v850_disas.h:21
@ V850_SHL_IMM5
Definition: v850_disas.h:36
@ V850_ADD_IMM5
Definition: v850_disas.h:32
@ V850_SSTW
Definition: v850_disas.h:43
@ V850_XOR
Definition: v850_disas.h:23
@ V850_SSTB
Definition: v850_disas.h:39
@ V850_CMP
Definition: v850_disas.h:29
@ V850_BCOND2
Definition: v850_disas.h:45
@ V850_ANDI
Definition: v850_disas.h:54
@ V850_JARL2
Definition: v850_disas.h:61
@ V850_BCOND
Definition: v850_disas.h:44
static int addr
Definition: z80asm.c:58

References addr, clear_flags(), cmd, DISP26, F1_REG1, F1_RN1, F1_RN2, F2_IMM, F2_REG2, F2_RN2, F3_COND, F4_REG2, F5_DISP, F5_RN2, F6_REG2, F6_RN1, F6_RN2, F8_BIT, F8_RN1, F9_RN1, F9_RN2, get_opcode, get_subopcode(), len, memset(), NULL, PFMT64d, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_DIV, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_NOT, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_SAR, RZ_ANALYSIS_OP_TYPE_SHL, RZ_ANALYSIS_OP_TYPE_SHR, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_UJMP, RZ_ANALYSIS_OP_TYPE_XOR, RZ_ANALYSIS_STACK_GET, RZ_ANALYSIS_STACK_INC, RZ_ANALYSIS_STACK_SET, RZ_MIN, rz_read_le16(), rz_strbuf_appendf(), SIGN_EXT_T5, st16, st32, st64, st8, update_flags(), V850_ADD, V850_ADD_IMM5, V850_ADDI, V850_AND, V850_ANDI, V850_BCOND, V850_BCOND2, V850_BCOND3, V850_BCOND4, V850_BIT_CLR1, V850_BIT_MANIP, V850_BIT_NOT1, V850_CMP, V850_CMP_IMM5, V850_COND_AL, V850_COND_CL, V850_COND_GE, V850_COND_GT, V850_COND_H, V850_COND_LE, V850_COND_LT, V850_COND_N, V850_COND_NE, V850_COND_NH, V850_COND_NL, V850_COND_NV, V850_COND_P, V850_COND_V, V850_COND_ZE, v850_decode_command(), V850_DIVH, V850_EXT1, V850_EXT_SAR, V850_EXT_SHL, V850_EXT_SHR, V850_FLAG_CY, V850_FLAG_OV, V850_FLAG_S, V850_FLAG_Z, V850_JARL2, V850_JMP, V850_MOV, V850_MOV_IMM5, V850_MOVEA, V850_MULH, V850_MULH_IMM5, V850_NOT, V850_OR, V850_ORI, V850_SAR_IMM5, V850_SHL_IMM5, V850_SHR_IMM5, V850_SLDB, V850_SLDH, V850_SLDW, V850_SP, V850_SSTB, V850_SSTH, V850_SSTW, V850_SUB, V850_SUBR, V850_TST, V850_XOR, and V850_XORI.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
}
RzAnalysisPlugin rz_analysis_plugin_v850
@ RZ_LIB_TYPE_ANALYSIS
Definition: rz_lib.h:73
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_analysis.h:1239

Definition at line 592 of file analysis_v850.c.

◆ rz_analysis_plugin_v850

RzAnalysisPlugin rz_analysis_plugin_v850
Initial value:
= {
.name = "v850",
.desc = "V850 code analysis plugin",
.license = "LGPL3",
.preludes = analysis_preludes,
.arch = "v850",
.bits = 32,
.op = v850_op,
.esil = true,
.archinfo = archinfo,
.get_reg_profile = get_reg_profile,
}
static char * get_reg_profile(RzAnalysis *analysis)
static int archinfo(RzAnalysis *analysis, int q)
static RzList * analysis_preludes(RzAnalysis *analysis)
static int v850_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)

Definition at line 578 of file analysis_v850.c.

◆ V850_REG_NAMES

const char* V850_REG_NAMES[]
static

Definition at line 103 of file analysis_v850.c.