Rizin
unix-like reverse engineering framework and cli tools
analysis_rsp.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016-2017 bobby.smiles32 <bobby.smiles32@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 /*
4  * TODO: finish esil support of the non vector instructions
5  * TODO: implement vector instruction using custom esil commands
6  * (will be easier than pure esil approach)
7  * TODO: refactor code to simplify per opcode analysis
8  */
9 
10 #include <string.h>
11 #include <rz_types.h>
12 #include <rz_lib.h>
13 #include <rz_asm.h>
14 #include <rz_analysis.h>
15 #include "../../asm/arch/rsp/rsp_idec.h"
16 
17 static int rsp_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *b, int len, RzAnalysisOpMask mask) {
18  int i;
19  typedef struct {
21  char esil[32];
22  } ParsedOperands;
23 
24  ParsedOperands parsed_operands[RSP_MAX_OPNDS];
25  memset(parsed_operands, 0, sizeof(ParsedOperands) * RSP_MAX_OPNDS);
26  ut32 iw;
27  rsp_instruction rz_instr;
28 
29  if (!op) {
30  return 4;
31  }
32 
34  op->size = 4;
35  op->addr = addr;
36  rz_strbuf_set(&op->esil, "TODO");
37 
38  iw = rz_read_ble32(b, analysis->big_endian);
39  rz_instr = rsp_instruction_decode(addr, iw);
40 
41  /* parse operands */
42  for (i = 0; i < rz_instr.noperands; i++) {
43  parsed_operands[i].value = rz_analysis_value_new();
44  parsed_operands[i].esil[0] = '\0';
45 
46  switch (rz_instr.operands[i].type) {
47  case RSP_OPND_GP_REG:
48  snprintf(parsed_operands[i].esil, sizeof(parsed_operands[i].esil), "%s", rsp_gp_reg_soft_names[rz_instr.operands[i].u]);
49  parsed_operands[i].value->reg = rz_reg_get(analysis->reg, rsp_gp_reg_soft_names[rz_instr.operands[i].u], RZ_REG_TYPE_GPR);
50  break;
51  case RSP_OPND_ZIMM:
53  snprintf(parsed_operands[i].esil, sizeof(parsed_operands[i].esil), "%" PFMT64d, rz_instr.operands[i].u);
54  parsed_operands[i].value->imm = op->val = rz_instr.operands[i].u;
55  break;
56  case RSP_OPND_SIMM:
57  snprintf(parsed_operands[i].esil, sizeof(parsed_operands[i].esil), "%" PFMT64d, rz_instr.operands[i].s);
58  parsed_operands[i].value->imm = op->val = rz_instr.operands[i].s;
59  break;
61  snprintf(parsed_operands[i].esil, sizeof(parsed_operands[i].esil),
62  "%" PFMT64d ",%s,+", rz_instr.operands[i].s, rsp_gp_reg_soft_names[rz_instr.operands[i].u]);
63  parsed_operands[i].value->reg = rz_reg_get(analysis->reg, rsp_gp_reg_soft_names[rz_instr.operands[i].u], RZ_REG_TYPE_GPR);
64  parsed_operands[i].value->imm = rz_instr.operands[i].s;
65  break;
66  case RSP_OPND_OFFSET:
67  case RSP_OPND_TARGET:
68  op->delay = 1;
69  op->jump = rz_instr.operands[i].u;
70  op->fail = rsp_mem_addr(addr + 8, RSP_IMEM_OFFSET);
71  op->eob = 1;
72  snprintf(parsed_operands[i].esil, sizeof(parsed_operands[i].esil), "%" PFMT64d, rz_instr.operands[i].u);
73  parsed_operands[i].value->imm = rz_instr.operands[i].u;
74  parsed_operands[i].value->memref = 4;
75  break;
76  case RSP_OPND_C0_REG:
77  snprintf(parsed_operands[i].esil, sizeof(parsed_operands[i].esil), "%s", rsp_c0_reg_names[rz_instr.operands[i].u]);
78  parsed_operands[i].value->reg = rz_reg_get(analysis->reg, rsp_c0_reg_names[rz_instr.operands[i].u], RZ_REG_TYPE_GPR);
79  break;
80  case RSP_OPND_C2_CREG:
81  case RSP_OPND_C2_ACCU:
82  case RSP_OPND_C2_VREG:
86  /* TODO */
87  break;
88  }
89  }
90 
91  switch (rz_instr.opcode) {
92  case RSP_OP_INVALID:
94  break;
95  case RSP_OP_NOP:
97  rz_strbuf_set(&op->esil, ",");
98  break;
99  case RSP_OP_BREAK:
101  // TODO
102  break;
103  case RSP_OP_LUI:
104  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
105  op->dst = parsed_operands[0].value;
106  op->src[0] = parsed_operands[1].value;
107  rz_strbuf_setf(&op->esil, "%s,%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
108  break;
109  case RSP_OP_ADD:
110  case RSP_OP_ADDU:
111  case RSP_OP_ADDI:
112  case RSP_OP_ADDIU:
113  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
114  op->dst = parsed_operands[0].value;
115  op->src[0] = parsed_operands[1].value;
116  op->src[1] = parsed_operands[2].value;
117  rz_strbuf_setf(&op->esil, "%s,%s,+,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
118  break;
119  case RSP_OP_SUB:
120  case RSP_OP_SUBU:
121  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
122  op->dst = parsed_operands[0].value;
123  op->src[0] = parsed_operands[1].value;
124  op->src[1] = parsed_operands[2].value;
125  rz_strbuf_setf(&op->esil, "%s,%s,-,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
126  break;
127  case RSP_OP_AND:
128  case RSP_OP_ANDI:
129  op->type = RZ_ANALYSIS_OP_TYPE_AND;
130  op->dst = parsed_operands[0].value;
131  op->src[0] = parsed_operands[1].value;
132  op->src[1] = parsed_operands[2].value;
133  rz_strbuf_setf(&op->esil, "%s,%s,&,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
134  break;
135  case RSP_OP_OR:
136  case RSP_OP_ORI:
137  op->type = RZ_ANALYSIS_OP_TYPE_OR;
138  op->dst = parsed_operands[0].value;
139  op->src[0] = parsed_operands[1].value;
140  op->src[1] = parsed_operands[2].value;
141  rz_strbuf_setf(&op->esil, "%s,%s,|,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
142  break;
143  case RSP_OP_XOR:
144  case RSP_OP_XORI:
145  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
146  op->dst = parsed_operands[0].value;
147  op->src[0] = parsed_operands[1].value;
148  op->src[1] = parsed_operands[2].value;
149  rz_strbuf_setf(&op->esil, "%s,%s,^,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
150  break;
151  case RSP_OP_NOR:
152  op->type = RZ_ANALYSIS_OP_TYPE_NOR;
153  op->dst = parsed_operands[0].value;
154  op->src[0] = parsed_operands[1].value;
155  op->src[1] = parsed_operands[2].value;
156  // TODO
157  break;
158  case RSP_OP_SLL:
159  case RSP_OP_SLLV:
160  op->type = RZ_ANALYSIS_OP_TYPE_SHL;
161  op->dst = parsed_operands[0].value;
162  op->src[0] = parsed_operands[1].value;
163  op->src[1] = parsed_operands[2].value;
164  rz_strbuf_setf(&op->esil, "%s,%s,<<,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
165  break;
166  case RSP_OP_SRL:
167  case RSP_OP_SRLV:
168  op->type = RZ_ANALYSIS_OP_TYPE_SHR;
169  op->dst = parsed_operands[0].value;
170  op->src[0] = parsed_operands[1].value;
171  op->src[1] = parsed_operands[2].value;
172  rz_strbuf_setf(&op->esil, "%s,%s,>>,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil);
173  break;
174  case RSP_OP_SRA:
175  case RSP_OP_SRAV:
176  op->type = RZ_ANALYSIS_OP_TYPE_SAR;
177  op->dst = parsed_operands[0].value;
178  op->src[0] = parsed_operands[1].value;
179  op->src[1] = parsed_operands[2].value;
180  // TODO
181  break;
182  case RSP_OP_SLT:
183  case RSP_OP_SLTU:
184  case RSP_OP_SLTI:
185  case RSP_OP_SLTIU:
187  op->cond = RZ_TYPE_COND_LT;
188  op->dst = parsed_operands[0].value;
189  op->src[0] = parsed_operands[1].value;
190  op->src[1] = parsed_operands[2].value;
191  rz_strbuf_setf(&op->esil, "%s,%s,<,$z,?{,1,%s,=,}{,0,%s,=,}", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil, parsed_operands[0].esil);
192  break;
193  case RSP_OP_J:
194  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
195  op->dst = rz_analysis_value_new();
196  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
197  op->src[0] = parsed_operands[0].value;
198  rz_strbuf_setf(&op->esil, "%s,PC,=", parsed_operands[0].esil);
199  break;
200  case RSP_OP_JAL:
202  op->dst = rz_analysis_value_new();
203  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
204  op->src[0] = parsed_operands[0].value;
205  rz_strbuf_setf(&op->esil, "%s,PC,=,0x%08" PFMT64x ",RA,=", parsed_operands[0].esil, op->fail);
206  break;
207  case RSP_OP_JR:
208  /* if register is RA, this is a return */
209  op->type = (rz_instr.operands[0].u == 29)
212  op->delay = 1;
213  op->eob = 1;
214  op->fail = rsp_mem_addr(addr + 8, RSP_IMEM_OFFSET);
215  op->dst = rz_analysis_value_new();
216  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
217  op->src[0] = parsed_operands[0].value;
218  rz_strbuf_setf(&op->esil, "%s,PC,=", parsed_operands[0].esil);
219  break;
220  case RSP_OP_BEQ:
222  op->cond = RZ_TYPE_COND_EQ;
223  op->dst = rz_analysis_value_new();
224  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
225  op->src[0] = parsed_operands[0].value;
226  op->src[1] = parsed_operands[1].value;
227  rz_strbuf_setf(&op->esil, "%s,%s,==,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil, parsed_operands[2].esil);
228  break;
229  case RSP_OP_BNE:
231  op->cond = RZ_TYPE_COND_NE;
232  op->dst = rz_analysis_value_new();
233  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
234  op->src[0] = parsed_operands[0].value;
235  op->src[1] = parsed_operands[1].value;
236  rz_strbuf_setf(&op->esil, "%s,%s,==,$z,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil, parsed_operands[2].esil);
237  break;
238  case RSP_OP_BLEZ:
240  op->cond = RZ_TYPE_COND_LE;
241  op->dst = rz_analysis_value_new();
242  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
243  op->src[0] = parsed_operands[0].value;
244  op->src[1] = parsed_operands[1].value;
245  rz_strbuf_setf(&op->esil, "%s,!,%s,0x80000000,&,!,!,|,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[0].esil, parsed_operands[1].esil);
246  // rz_strbuf_setf (&op->esil, "0,%s,<=,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil);
247  break;
248  case RSP_OP_BGTZ:
250  op->cond = RZ_TYPE_COND_GT;
251  op->dst = rz_analysis_value_new();
252  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
253  op->src[0] = parsed_operands[0].value;
254  op->src[1] = parsed_operands[1].value;
255  rz_strbuf_setf(&op->esil, "%s,0x80000000,&,!,%s,!,!,&,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[0].esil, parsed_operands[1].esil);
256  // rz_strbuf_setf (&op->esil, "0,%s,>,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil);
257  break;
258  case RSP_OP_BLTZ:
260  op->cond = RZ_TYPE_COND_LT;
261  op->dst = rz_analysis_value_new();
262  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
263  op->src[0] = parsed_operands[0].value;
264  op->src[1] = parsed_operands[1].value;
265  rz_strbuf_setf(&op->esil, "%s,0x80000000,&,!,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil);
266  // rz_strbuf_setf (&op->esil, "0,%s,<,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil);
267  break;
268  case RSP_OP_BGEZ:
270  op->cond = RZ_TYPE_COND_GE;
271  op->dst = rz_analysis_value_new();
272  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
273  op->src[0] = parsed_operands[0].value;
274  op->src[1] = parsed_operands[1].value;
275  rz_strbuf_setf(&op->esil, "%s,0x80000000,&,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil);
276  // rz_strbuf_setf (&op->esil, "0,%s,>=,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil);
277  break;
278  case RSP_OP_BLTZAL:
280  op->cond = RZ_TYPE_COND_LT;
281  op->dst = rz_analysis_value_new();
282  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
283  op->src[0] = parsed_operands[0].value;
284  op->src[1] = parsed_operands[1].value;
285  // TODO
286  break;
287  case RSP_OP_BGEZAL:
289  op->cond = RZ_TYPE_COND_GE;
290  op->dst = rz_analysis_value_new();
291  op->dst->reg = rz_reg_get(analysis->reg, "PC", RZ_REG_TYPE_GPR);
292  op->src[0] = parsed_operands[0].value;
293  op->src[1] = parsed_operands[1].value;
294  // TODO
295  break;
296  case RSP_OP_LB:
298  op->dst = parsed_operands[0].value;
299  op->src[0] = parsed_operands[1].value;
300  op->src[0]->memref = op->refptr = 1;
301  // FIXME: sign extend
302  rz_strbuf_setf(&op->esil, "%s,[1],%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
303  break;
304  case RSP_OP_LH:
306  op->dst = parsed_operands[0].value;
307  op->src[0] = parsed_operands[1].value;
308  op->src[0]->memref = op->refptr = 2;
309  // FIXME: sign extend
310  rz_strbuf_setf(&op->esil, "%s,[2],%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
311  break;
312  case RSP_OP_LW:
314  op->dst = parsed_operands[0].value;
315  op->src[0] = parsed_operands[1].value;
316  op->src[0]->memref = op->refptr = 4;
317  rz_strbuf_setf(&op->esil, "%s,[4],%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
318  break;
319  case RSP_OP_LBU:
321  op->dst = parsed_operands[0].value;
322  op->src[0] = parsed_operands[1].value;
323  op->src[0]->memref = op->refptr = 1;
324  rz_strbuf_setf(&op->esil, "%s,[1],%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
325  break;
326  case RSP_OP_LHU:
328  op->dst = parsed_operands[0].value;
329  op->src[0] = parsed_operands[1].value;
330  op->src[0]->memref = op->refptr = 2;
331  rz_strbuf_setf(&op->esil, "%s,[2],%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
332  break;
333  case RSP_OP_SB:
335  op->src[0] = parsed_operands[0].value;
336  op->dst = parsed_operands[1].value;
337  op->dst->memref = op->refptr = 1;
338  rz_strbuf_setf(&op->esil, "%s,%s,=[1]", parsed_operands[0].esil, parsed_operands[1].esil);
339  break;
340  case RSP_OP_SH:
342  op->src[0] = parsed_operands[0].value;
343  op->dst = parsed_operands[1].value;
344  op->dst->memref = op->refptr = 2;
345  rz_strbuf_setf(&op->esil, "%s,%s,=[2]", parsed_operands[0].esil, parsed_operands[1].esil);
346  break;
347  case RSP_OP_SW:
349  op->src[0] = parsed_operands[0].value;
350  op->dst = parsed_operands[1].value;
351  op->dst->memref = op->refptr = 4;
352  rz_strbuf_setf(&op->esil, "%s,%s,=[4]", parsed_operands[0].esil, parsed_operands[1].esil);
353  break;
354  case RSP_OP_MFC0:
355  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
356  op->dst = parsed_operands[0].value;
357  op->src[0] = parsed_operands[1].value;
358  rz_strbuf_setf(&op->esil, "%s,%s,=", parsed_operands[1].esil, parsed_operands[0].esil);
359  break;
360  case RSP_OP_MTC0:
361  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
362  op->src[0] = parsed_operands[0].value;
363  op->dst = parsed_operands[1].value;
364  rz_strbuf_setf(&op->esil, "%s,%s,=", parsed_operands[0].esil, parsed_operands[1].esil);
365  break;
366  case RSP_OP_MFC2:
367  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
368  op->dst = parsed_operands[0].value;
369  // op->src[0] = parsed_operands[1].value;
370  break;
371  case RSP_OP_MTC2:
372  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
373  op->src[0] = parsed_operands[0].value;
374  // op->dst = parsed_operands[1].value;
375  break;
376  case RSP_OP_CFC2:
377  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
378  break;
379  case RSP_OP_CTC2:
380  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
381  break;
382  case RSP_OP_VMULF:
383  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
384  break;
385  case RSP_OP_VMULU:
386  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
387  break;
388  case RSP_OP_VMUDL:
389  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
390  break;
391  case RSP_OP_VMUDM:
392  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
393  break;
394  case RSP_OP_VMUDN:
395  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
396  break;
397  case RSP_OP_VMUDH:
398  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
399  break;
400  case RSP_OP_VMACF:
401  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
402  break;
403  case RSP_OP_VMACU:
404  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
405  break;
406  case RSP_OP_VMADL:
407  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
408  break;
409  case RSP_OP_VMADM:
410  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
411  break;
412  case RSP_OP_VMADN:
413  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
414  break;
415  case RSP_OP_VMADH:
416  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
417  break;
418  case RSP_OP_VADD:
419  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
420  break;
421  case RSP_OP_VSUB:
422  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
423  break;
424  case RSP_OP_VABS:
425  op->type = RZ_ANALYSIS_OP_TYPE_ABS;
426  break;
427  case RSP_OP_VADDC:
428  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
429  break;
430  case RSP_OP_VSUBC:
431  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
432  break;
433  case RSP_OP_VSAR:
434  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
435  break;
436  case RSP_OP_VLT:
437  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
438  op->cond = RZ_TYPE_COND_LT;
439  break;
440  case RSP_OP_VEQ:
441  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
442  op->cond = RZ_TYPE_COND_EQ;
443  break;
444  case RSP_OP_VNE:
445  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
446  op->cond = RZ_TYPE_COND_NE;
447  break;
448  case RSP_OP_VGE:
449  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
450  op->cond = RZ_TYPE_COND_GE;
451  break;
452  case RSP_OP_VCL:
453  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
454  break;
455  case RSP_OP_VCH:
456  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
457  break;
458  case RSP_OP_VCR:
459  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
460  break;
461  case RSP_OP_VMRG:
462  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
463  break;
464  case RSP_OP_VAND:
465  op->type = RZ_ANALYSIS_OP_TYPE_AND;
466  break;
467  case RSP_OP_VNAND:
468  op->type = RZ_ANALYSIS_OP_TYPE_AND;
469  break;
470  case RSP_OP_VOR:
471  op->type = RZ_ANALYSIS_OP_TYPE_OR;
472  break;
473  case RSP_OP_VNOR:
474  op->type = RZ_ANALYSIS_OP_TYPE_NOR;
475  break;
476  case RSP_OP_VXOR:
477  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
478  break;
479  case RSP_OP_VNXOR:
480  op->type = RZ_ANALYSIS_OP_TYPE_XOR;
481  break;
482  case RSP_OP_VRCP:
483  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
484  break;
485  case RSP_OP_VRCPL:
486  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
487  break;
488  case RSP_OP_VRCPH:
489  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
490  break;
491  case RSP_OP_VMOV:
492  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
493  break;
494  case RSP_OP_VRSQ:
495  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
496  break;
497  case RSP_OP_VRSQL:
498  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
499  break;
500  case RSP_OP_VRSQH:
501  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
502  break;
503  case RSP_OP_VNOP:
504  op->type = RZ_ANALYSIS_OP_TYPE_NOP;
505  break;
506  case RSP_OP_LBV:
508  break;
509  case RSP_OP_LSV:
511  break;
512  case RSP_OP_LLV:
514  break;
515  case RSP_OP_LDV:
517  break;
518  case RSP_OP_LQV:
520  break;
521  case RSP_OP_LRV:
523  break;
524  case RSP_OP_LPV:
526  break;
527  case RSP_OP_LUV:
529  break;
530  case RSP_OP_LHV:
532  break;
533  case RSP_OP_LFV:
535  break;
536  case RSP_OP_LTV:
538  break;
539  case RSP_OP_SBV:
541  break;
542  case RSP_OP_SSV:
544  break;
545  case RSP_OP_SLV:
547  break;
548  case RSP_OP_SDV:
550  break;
551  case RSP_OP_SQV:
553  break;
554  case RSP_OP_SRV:
556  break;
557  case RSP_OP_SPV:
559  break;
560  case RSP_OP_SUV:
562  break;
563  case RSP_OP_SHV:
565  break;
566  case RSP_OP_SFV:
568  break;
569  case RSP_OP_SWV:
571  break;
572  case RSP_OP_STV:
574  break;
575  default: break;
576  }
577 
578  return op->size;
579 }
580 
581 static char *get_reg_profile(RzAnalysis *analysis) {
582  static const char *p =
583  "=PC pc\n"
584  "=SP sp\n"
585  "=A0 a0\n"
586  "=A1 a1\n"
587  "=A2 a2\n"
588  "=A3 a3\n"
589  "=R0 v0\n"
590  "=R1 v1\n"
591  /* GP registers */
592  "gpr zero .32 0 0\n"
593  "gpr at .32 4 0\n"
594  "gpr v0 .32 8 0\n"
595  "gpr v1 .32 12 0\n"
596  "gpr a0 .32 16 0\n"
597  "gpr a1 .32 20 0\n"
598  "gpr a2 .32 24 0\n"
599  "gpr a3 .32 28 0\n"
600  "gpr t0 .32 32 0\n"
601  "gpr t1 .32 36 0\n"
602  "gpr t2 .32 40 0\n"
603  "gpr t3 .32 44 0\n"
604  "gpr t4 .32 48 0\n"
605  "gpr t5 .32 52 0\n"
606  "gpr t6 .32 56 0\n"
607  "gpr t7 .32 60 0\n"
608  "gpr s0 .32 64 0\n"
609  "gpr s1 .32 68 0\n"
610  "gpr s2 .32 72 0\n"
611  "gpr s3 .32 76 0\n"
612  "gpr s4 .32 80 0\n"
613  "gpr s5 .32 84 0\n"
614  "gpr s6 .32 88 0\n"
615  "gpr s7 .32 92 0\n"
616  "gpr t8 .32 96 0\n"
617  "gpr t9 .32 100 0\n"
618  "gpr k0 .32 104 0\n"
619  "gpr k1 .32 108 0\n"
620  "gpr gp .32 112 0\n"
621  "gpr sp .32 116 0\n"
622  "gpr s8 .32 120 0\n"
623  "gpr ra .32 124 0\n"
624  /* PC register */
625  "gpr pc .32 128 0\n"
626  /* C0 registers */
627  "gpr $c0 .32 132 0\n"
628  "gpr $c1 .32 136 0\n"
629  "gpr $c2 .32 140 0\n"
630  "gpr $c3 .32 144 0\n"
631  "gpr $c4 .32 148 0\n"
632  "gpr $c5 .32 152 0\n"
633  "gpr $c6 .32 156 0\n"
634  "gpr $c7 .32 160 0\n"
635  "gpr $c8 .32 164 0\n"
636  "gpr $c9 .32 168 0\n"
637  "gpr $c10 .32 172 0\n"
638  "gpr $c11 .32 176 0\n"
639  "gpr $c12 .32 180 0\n"
640  "gpr $c13 .32 184 0\n"
641  "gpr $c14 .32 188 0\n"
642  "gpr $c15 .32 192 0\n"
643  /* C2 vector registers - (32 x 128 bit) */
644  "gpr $v0 .128 196 0\n"
645  "gpr $v1 .128 212 0\n"
646  "gpr $v2 .128 228 0\n"
647  "gpr $v3 .128 244 0\n"
648  "gpr $v4 .128 260 0\n"
649  "gpr $v5 .128 276 0\n"
650  "gpr $v6 .128 292 0\n"
651  "gpr $v7 .128 308 0\n"
652  "gpr $v8 .128 324 0\n"
653  "gpr $v9 .128 340 0\n"
654  "gpr $v10 .128 356 0\n"
655  "gpr $v11 .128 372 0\n"
656  "gpr $v12 .128 388 0\n"
657  "gpr $v13 .128 404 0\n"
658  "gpr $v14 .128 420 0\n"
659  "gpr $v15 .128 436 0\n"
660  "gpr $v16 .128 452 0\n"
661  "gpr $v17 .128 468 0\n"
662  "gpr $v18 .128 484 0\n"
663  "gpr $v19 .128 500 0\n"
664  "gpr $v20 .128 516 0\n"
665  "gpr $v21 .128 532 0\n"
666  "gpr $v22 .128 548 0\n"
667  "gpr $v23 .128 564 0\n"
668  "gpr $v24 .128 580 0\n"
669  "gpr $v25 .128 596 0\n"
670  "gpr $v26 .128 612 0\n"
671  "gpr $v27 .128 628 0\n"
672  "gpr $v28 .128 644 0\n"
673  "gpr $v29 .128 660 0\n"
674  "gpr $v30 .128 676 0\n"
675  "gpr $v31 .128 692 0\n"
676  /* C2 control registers - (vco, vcc, vce) */
677  "gpr $vco .128 708 0\n"
678  "gpr $vcc .128 724 0\n"
679  "gpr $vce .128 740 0\n";
680 
681  return strdup(p);
682 }
683 
684 static int archinfo(RzAnalysis *analysis, int q) {
685  return 4;
686 }
687 
689  .name = "rsp",
690  .desc = "RSP code analysis plugin",
691  .license = "LGPL3",
692  .arch = "rsp",
693  .esil = true,
694  .bits = 32,
695  .op = &rsp_op,
696  .archinfo = &archinfo,
697  .get_reg_profile = &get_reg_profile,
698 };
699 
700 #ifndef RZ_PLUGIN_INCORE
703  .data = &rz_analysis_plugin_rsp,
705 };
706 #endif
size_t len
Definition: 6502dis.c:15
RZ_API RzAnalysisValue * rz_analysis_value_new(void)
Definition: value.c:6
#define mask()
RzAnalysisPlugin rz_analysis_plugin_rsp
Definition: analysis_rsp.c:688
static char * get_reg_profile(RzAnalysis *analysis)
Definition: analysis_rsp.c:581
RZ_API RzLibStruct rizin_plugin
Definition: analysis_rsp.c:701
static int rsp_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *b, int len, RzAnalysisOpMask mask)
Definition: analysis_rsp.c:17
static int archinfo(RzAnalysis *analysis, int q)
Definition: analysis_rsp.c:684
lzma_index ** i
Definition: index.h:629
static int value
Definition: cmd_api.c:93
#define RZ_API
uint32_t ut32
snprintf
Definition: kernel.h:364
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
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")
RZ_API RzRegItem * rz_reg_get(RzReg *reg, const char *name, int type)
Definition: reg.c:344
rsp_instruction rsp_instruction_decode(ut64 pc, ut32 iw)
Definition: rsp_idec.c:587
const char * rsp_gp_reg_soft_names[]
Definition: rsp_idec.c:6
const char * rsp_c0_reg_names[]
Definition: rsp_idec.c:55
static ut64 rsp_mem_addr(ut64 addr, ut64 base)
Definition: rsp_idec.h:23
@ RSP_MAX_OPNDS
Definition: rsp_idec.h:170
@ RSP_IMEM_OFFSET
Definition: rsp_idec.h:19
@ RSP_OPND_OFFSET
Definition: rsp_idec.h:150
@ RSP_OPND_BASE_OFFSET
Definition: rsp_idec.h:154
@ RSP_OPND_C2_ACCU
Definition: rsp_idec.h:157
@ RSP_OPND_C2_CREG
Definition: rsp_idec.h:156
@ RSP_OPND_SIMM
Definition: rsp_idec.h:152
@ RSP_OPND_C0_REG
Definition: rsp_idec.h:155
@ RSP_OPND_SHIFT_AMOUNT
Definition: rsp_idec.h:153
@ RSP_OPND_ZIMM
Definition: rsp_idec.h:151
@ RSP_OPND_C2_VREG_ELEMENT
Definition: rsp_idec.h:161
@ RSP_OPND_C2_VREG
Definition: rsp_idec.h:158
@ RSP_OPND_C2_VREG_BYTE
Definition: rsp_idec.h:159
@ RSP_OPND_C2_VREG_SCALAR
Definition: rsp_idec.h:160
@ RSP_OPND_TARGET
Definition: rsp_idec.h:149
@ RSP_OPND_GP_REG
Definition: rsp_idec.h:148
@ RSP_OP_VMUDM
Definition: rsp_idec.h:63
@ RSP_OP_LPV
Definition: rsp_idec.h:106
@ RSP_OP_STV
Definition: rsp_idec.h:122
@ RSP_OP_SUV
Definition: rsp_idec.h:118
@ RSP_OP_VMADN
Definition: rsp_idec.h:70
@ RSP_OP_LB
Definition: rsp_idec.h:137
@ RSP_OP_JR
Definition: rsp_idec.h:38
@ RSP_OP_VCR
Definition: rsp_idec.h:84
@ RSP_OP_XORI
Definition: rsp_idec.h:135
@ RSP_OP_SUB
Definition: rsp_idec.h:42
@ RSP_OP_LHU
Definition: rsp_idec.h:141
@ RSP_OP_VRSQH
Definition: rsp_idec.h:98
@ RSP_OP_VOR
Definition: rsp_idec.h:88
@ RSP_OP_SDV
Definition: rsp_idec.h:114
@ RSP_OP_VNXOR
Definition: rsp_idec.h:91
@ RSP_OP_ADDIU
Definition: rsp_idec.h:130
@ RSP_OP_LBU
Definition: rsp_idec.h:140
@ RSP_OP_SRLV
Definition: rsp_idec.h:36
@ RSP_OP_VNOP
Definition: rsp_idec.h:99
@ RSP_OP_VMRG
Definition: rsp_idec.h:85
@ RSP_OP_LBV
Definition: rsp_idec.h:100
@ RSP_OP_VAND
Definition: rsp_idec.h:86
@ RSP_OP_MFC2
Definition: rsp_idec.h:56
@ RSP_OP_INVALID
Definition: rsp_idec.h:30
@ RSP_OP_SPV
Definition: rsp_idec.h:117
@ RSP_OP_OR
Definition: rsp_idec.h:45
@ RSP_OP_LH
Definition: rsp_idec.h:138
@ RSP_OP_VRSQL
Definition: rsp_idec.h:97
@ RSP_OP_VADD
Definition: rsp_idec.h:72
@ RSP_OP_LLV
Definition: rsp_idec.h:102
@ RSP_OP_VRSQ
Definition: rsp_idec.h:96
@ RSP_OP_LSV
Definition: rsp_idec.h:101
@ RSP_OP_BLTZAL
Definition: rsp_idec.h:52
@ RSP_OP_BEQ
Definition: rsp_idec.h:125
@ RSP_OP_VMADH
Definition: rsp_idec.h:71
@ RSP_OP_VRCPH
Definition: rsp_idec.h:94
@ RSP_OP_SUBU
Definition: rsp_idec.h:43
@ RSP_OP_VGE
Definition: rsp_idec.h:81
@ RSP_OP_SFV
Definition: rsp_idec.h:120
@ RSP_OP_SB
Definition: rsp_idec.h:142
@ RSP_OP_BLEZ
Definition: rsp_idec.h:127
@ RSP_OP_BGEZAL
Definition: rsp_idec.h:53
@ RSP_OP_SRA
Definition: rsp_idec.h:34
@ RSP_OP_LUV
Definition: rsp_idec.h:107
@ RSP_OP_VMADL
Definition: rsp_idec.h:68
@ RSP_OP_SLTI
Definition: rsp_idec.h:131
@ RSP_OP_LHV
Definition: rsp_idec.h:108
@ RSP_OP_BGEZ
Definition: rsp_idec.h:51
@ RSP_OP_BNE
Definition: rsp_idec.h:126
@ RSP_OP_VABS
Definition: rsp_idec.h:74
@ RSP_OP_ADDU
Definition: rsp_idec.h:41
@ RSP_OP_J
Definition: rsp_idec.h:123
@ RSP_OP_SLL
Definition: rsp_idec.h:32
@ RSP_OP_VMACF
Definition: rsp_idec.h:66
@ RSP_OP_LUI
Definition: rsp_idec.h:136
@ RSP_OP_MFC0
Definition: rsp_idec.h:54
@ RSP_OP_VMOV
Definition: rsp_idec.h:95
@ RSP_OP_VMULU
Definition: rsp_idec.h:61
@ RSP_OP_VMUDL
Definition: rsp_idec.h:62
@ RSP_OP_SRAV
Definition: rsp_idec.h:37
@ RSP_OP_SLV
Definition: rsp_idec.h:113
@ RSP_OP_LQV
Definition: rsp_idec.h:104
@ RSP_OP_MTC0
Definition: rsp_idec.h:55
@ RSP_OP_SLTU
Definition: rsp_idec.h:49
@ RSP_OP_CTC2
Definition: rsp_idec.h:59
@ RSP_OP_VCL
Definition: rsp_idec.h:82
@ RSP_OP_XOR
Definition: rsp_idec.h:46
@ RSP_OP_ADDI
Definition: rsp_idec.h:129
@ RSP_OP_MTC2
Definition: rsp_idec.h:57
@ RSP_OP_SWV
Definition: rsp_idec.h:121
@ RSP_OP_ANDI
Definition: rsp_idec.h:133
@ RSP_OP_BREAK
Definition: rsp_idec.h:39
@ RSP_OP_LW
Definition: rsp_idec.h:139
@ RSP_OP_SBV
Definition: rsp_idec.h:111
@ RSP_OP_SSV
Definition: rsp_idec.h:112
@ RSP_OP_VNAND
Definition: rsp_idec.h:87
@ RSP_OP_VRCP
Definition: rsp_idec.h:92
@ RSP_OP_JAL
Definition: rsp_idec.h:124
@ RSP_OP_SLTIU
Definition: rsp_idec.h:132
@ RSP_OP_VCH
Definition: rsp_idec.h:83
@ RSP_OP_NOR
Definition: rsp_idec.h:47
@ RSP_OP_VMUDN
Definition: rsp_idec.h:64
@ RSP_OP_VMACU
Definition: rsp_idec.h:67
@ RSP_OP_VSUB
Definition: rsp_idec.h:73
@ RSP_OP_VSAR
Definition: rsp_idec.h:77
@ RSP_OP_VXOR
Definition: rsp_idec.h:90
@ RSP_OP_SW
Definition: rsp_idec.h:144
@ RSP_OP_SLLV
Definition: rsp_idec.h:35
@ RSP_OP_BGTZ
Definition: rsp_idec.h:128
@ RSP_OP_VLT
Definition: rsp_idec.h:78
@ RSP_OP_SQV
Definition: rsp_idec.h:115
@ RSP_OP_ORI
Definition: rsp_idec.h:134
@ RSP_OP_VNOR
Definition: rsp_idec.h:89
@ RSP_OP_NOP
Definition: rsp_idec.h:31
@ RSP_OP_SLT
Definition: rsp_idec.h:48
@ RSP_OP_SHV
Definition: rsp_idec.h:119
@ RSP_OP_ADD
Definition: rsp_idec.h:40
@ RSP_OP_VMADM
Definition: rsp_idec.h:69
@ RSP_OP_AND
Definition: rsp_idec.h:44
@ RSP_OP_VSUBC
Definition: rsp_idec.h:76
@ RSP_OP_CFC2
Definition: rsp_idec.h:58
@ RSP_OP_VRCPL
Definition: rsp_idec.h:93
@ RSP_OP_VMUDH
Definition: rsp_idec.h:65
@ RSP_OP_BLTZ
Definition: rsp_idec.h:50
@ RSP_OP_VMULF
Definition: rsp_idec.h:60
@ RSP_OP_SRL
Definition: rsp_idec.h:33
@ RSP_OP_VADDC
Definition: rsp_idec.h:75
@ RSP_OP_VEQ
Definition: rsp_idec.h:79
@ RSP_OP_SH
Definition: rsp_idec.h:143
@ RSP_OP_LRV
Definition: rsp_idec.h:105
@ RSP_OP_LTV
Definition: rsp_idec.h:110
@ RSP_OP_LFV
Definition: rsp_idec.h:109
@ RSP_OP_VNE
Definition: rsp_idec.h:80
@ RSP_OP_LDV
Definition: rsp_idec.h:103
@ RSP_OP_SRV
Definition: rsp_idec.h:116
RzAnalysisOpMask
Definition: rz_analysis.h:439
@ 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_UNK
Definition: rz_analysis.h:388
@ 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_NOR
Definition: rz_analysis.h:413
@ RZ_ANALYSIS_OP_TYPE_SAR
Definition: rz_analysis.h:409
@ RZ_ANALYSIS_OP_TYPE_ABS
Definition: rz_analysis.h:428
@ RZ_ANALYSIS_OP_TYPE_CMOV
Definition: rz_analysis.h:391
@ RZ_ANALYSIS_OP_TYPE_TRAP
Definition: rz_analysis.h:392
@ RZ_ANALYSIS_OP_TYPE_CCALL
Definition: rz_analysis.h:383
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ 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_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_SHL
Definition: rz_analysis.h:407
@ RZ_ANALYSIS_OP_TYPE_ILL
Definition: rz_analysis.h:387
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
@ RZ_LIB_TYPE_ANALYSIS
Definition: rz_lib.h:73
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
@ RZ_TYPE_COND_LE
Less or equal.
Definition: rz_type.h:188
@ RZ_TYPE_COND_GE
Greater or equal.
Definition: rz_type.h:186
@ RZ_TYPE_COND_EQ
Equal.
Definition: rz_type.h:184
@ RZ_TYPE_COND_NE
Not equal.
Definition: rz_type.h:185
@ RZ_TYPE_COND_GT
Greater than.
Definition: rz_type.h:187
@ RZ_TYPE_COND_LT
Less than.
Definition: rz_type.h:189
#define PFMT64d
Definition: rz_types.h:394
#define PFMT64x
Definition: rz_types.h:393
#define RZ_VERSION
Definition: rz_version.h:8
#define b(i)
Definition: sha256.c:42
rsp_opcode opcode
Definition: rsp_idec.h:174
rsp_operand operands[RSP_MAX_OPNDS]
Definition: rsp_idec.h:176
rsp_operand_type type
Definition: rsp_idec.h:165
const char * version
Definition: rz_analysis.h:1239
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58