Rizin
unix-like reverse engineering framework and cli tools
rsp_idec.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016 bobby.smiles32 <bobby.smiles32@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include "rsp_idec.h"
5 
6 const char *rsp_gp_reg_soft_names[] = {
7  "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
8  "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
9  "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
10  "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
11 };
12 
13 const char *rsp_c0_reg_soft_names[] = {
14  "SP_MEM_ADDR", "SP_DRAM_ADDR", "SP_RD_LEN", "SP_WR_LEN",
15  "SP_STATUS", "SP_DMA_FULL", "SP_DMA_BUSY", "SP_SEMAPHORE",
16  "DPC_START", "DPC_END", "DPC_CURRENT", "DPC_STATUS",
17  "DPC_CLOCK", "DPC_BUF_BUSY", "DPC_PIPE_BUSY", "DPC_TMEM_BUSY"
18 };
19 
20 const char *rsp_gp_reg_names[] = {
21  "$0",
22  "$1",
23  "$2",
24  "$3",
25  "$4",
26  "$5",
27  "$6",
28  "$7",
29  "$8",
30  "$9",
31  "$10",
32  "$11",
33  "$12",
34  "$13",
35  "$14",
36  "$15",
37  "$16",
38  "$17",
39  "$18",
40  "$19",
41  "$20",
42  "$21",
43  "$22",
44  "$23",
45  "$24",
46  "$25",
47  "$26",
48  "$27",
49  "$28",
50  "$29",
51  "$30",
52  "$31",
53 };
54 
55 const char *rsp_c0_reg_names[] = {
56  "$c0", "$c1", "$c2", "$c3", "$c4", "$c5", "$c6", "$c7",
57  "$c8", "$c9", "$c10", "$c11", "$c12", "$c13", "$c14", "$c15"
58 };
59 
60 const char *rsp_c2_creg_names[] = {
61  "$vco", "$vcc", "$vce", "???"
62 };
63 
64 const char *rsp_c2_accu_names[] = {
65  "ACC_H", "ACC_M", "ACC_L", "???"
66 };
67 
68 const char *rsp_c2_vreg_names[] = {
69  "$v0", "$v1", "$v2", "$v3", "$v4", "$v5", "$v6", "$v7",
70  "$v8", "$v9", "$v10", "$v11", "$v12", "$v13", "$v14", "$v15",
71  "$v16", "$v17", "$v18", "$v19", "$v20", "$v21", "$v22", "$v23",
72  "$v24", "$v25", "$v26", "$v27", "$v28", "$v29", "$v30", "$v31"
73 };
74 
75 const char *rsp_c2_vreg_element_names[] = {
76  "", "[?]", "[0q]", "[1q]", "[0h]", "[1h]", "[2h]", "[3h]",
77  "[0]", "[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]"
78 };
79 
80 /* Operand decoders description */
81 #define RS_DECODER \
82  { RSP_OPND_GP_REG, 21, 0x1f, 0, 0, 0, 0, 0 }
83 #define RT_DECODER \
84  { RSP_OPND_GP_REG, 16, 0x1f, 0, 0, 0, 0, 0 }
85 #define RD_DECODER \
86  { RSP_OPND_GP_REG, 11, 0x1f, 0, 0, 0, 0, 0 }
87 #define SA_DECODER \
88  { RSP_OPND_SHIFT_AMOUNT, 6, 0x1f, 0, 0, 0, 0, 0 }
89 #define LUI_DECODER \
90  { RSP_OPND_ZIMM, 0, 0xffff, 16, 0, 0, 0, 0 }
91 #define ZIMM_DECODER \
92  { RSP_OPND_ZIMM, 0, 0xffff, 0, 0, 0, 0, 0 }
93 #define SIMM_DECODER \
94  { RSP_OPND_SIMM, 0, 0, 0, 0, 0xffff, 0x8000, 0 }
95 #define OFFSET_DECODER \
96  { RSP_OPND_OFFSET, 0, 0, 0, 0, 0xffff, 0x8000, 2 }
97 #define BASE_OFFSET_DECODER \
98  { RSP_OPND_BASE_OFFSET, 21, 0x1f, 0, 0, 0xffff, 0x8000, 0 }
99 #define TARGET_DECODER \
100  { RSP_OPND_TARGET, 0, 0x03ff, 2, 0, 0, 0, 0 }
101 #define C0_REG_DECODER \
102  { RSP_OPND_C0_REG, 11, 0x0f, 0, 0, 0, 0, 0 }
103 #define C2_CREG_DECODER \
104  { RSP_OPND_C2_CREG, 11, 0x03, 0, 0, 0, 0, 0 }
105 #define C2_ACCU_DECODER \
106  { RSP_OPND_C2_ACCU, 21, 0x03, 0, 0, 0, 0, 0 }
107 #define VS_DECODER \
108  { RSP_OPND_C2_VREG, 11, 0x1f, 0, 0, 0, 0, 0 }
109 #define VD_DECODER \
110  { RSP_OPND_C2_VREG, 6, 0x1f, 0, 0, 0, 0, 0 }
111 #define VT_BYTE_DECODER \
112  { RSP_OPND_C2_VREG_BYTE, 16, 0x1f, 0, 7, 0xf, 0, 0 }
113 #define VS_BYTE_DECODER \
114  { RSP_OPND_C2_VREG_BYTE, 11, 0x1f, 0, 7, 0xf, 0, 0 }
115 #define VT_SCALAR_DECODER \
116  { RSP_OPND_C2_VREG_SCALAR, 16, 0x1f, 0, 21, 0x7, 0, 0 }
117 #define VD_SCALAR_DECODER \
118  { RSP_OPND_C2_VREG_SCALAR, 6, 0x1f, 0, 11, 0x7, 0, 0 }
119 #define VT_ELEMENT_DECODER \
120  { RSP_OPND_C2_VREG_ELEMENT, 16, 0x1f, 0, 21, 0xf, 0, 0 }
121 #define BASE_VOFFSET1_DECODER \
122  { RSP_OPND_BASE_OFFSET, 21, 0x1f, 0, 0, 0x7f, 0x40, 0 }
123 #define BASE_VOFFSET2_DECODER \
124  { RSP_OPND_BASE_OFFSET, 21, 0x1f, 0, 0, 0x7f, 0x40, 1 }
125 #define BASE_VOFFSET4_DECODER \
126  { RSP_OPND_BASE_OFFSET, 21, 0x1f, 0, 0, 0x7f, 0x40, 2 }
127 #define BASE_VOFFSET8_DECODER \
128  { RSP_OPND_BASE_OFFSET, 21, 0x1f, 0, 0, 0x7f, 0x40, 3 }
129 #define BASE_VOFFSET16_DECODER \
130  { RSP_OPND_BASE_OFFSET, 21, 0x1f, 0, 0, 0x7f, 0x40, 4 }
131 
132 /* Operands description */
133 #define OPNDS_NONE 0,
134 #define OPNDS_TARGET \
135  1, { TARGET_DECODER }
136 #define OPNDS_RS_OFFSET \
137  2, { RS_DECODER, OFFSET_DECODER }
138 #define OPNDS_RS_RT_OFFSET \
139  3, { RS_DECODER, RT_DECODER, OFFSET_DECODER }
140 #define OPNDS_RT_BASE_OFFSET \
141  2, { RT_DECODER, BASE_OFFSET_DECODER }
142 #define OPNDS_RS \
143  1, { RS_DECODER }
144 #define OPNDS_RT_LUI \
145  2, { RT_DECODER, LUI_DECODER }
146 #define OPNDS_RT_RS_SIMM \
147  3, { RT_DECODER, RS_DECODER, SIMM_DECODER }
148 #define OPNDS_RT_RS_ZIMM \
149  3, { RT_DECODER, RS_DECODER, ZIMM_DECODER }
150 #define OPNDS_RD_RT_SA \
151  3, { RD_DECODER, RT_DECODER, SA_DECODER }
152 #define OPNDS_RD_RT_RS \
153  3, { RD_DECODER, RT_DECODER, RS_DECODER }
154 #define OPNDS_RD_RS_RT \
155  3, { RD_DECODER, RS_DECODER, RT_DECODER }
156 #define OPNDS_RT_C0_REG \
157  2, { RT_DECODER, C0_REG_DECODER }
158 #define OPNDS_RT_C2_CREG \
159  2, { RT_DECODER, C2_CREG_DECODER }
160 #define OPNDS_RT_VSB \
161  2, { RT_DECODER, VS_BYTE_DECODER }
162 #define OPNDS_VDS_VTS \
163  2, { VD_SCALAR_DECODER, VT_SCALAR_DECODER }
164 #define OPNDS_VTB_BASE_OFFSET1 \
165  2, { VT_BYTE_DECODER, BASE_VOFFSET1_DECODER }
166 #define OPNDS_VTB_BASE_OFFSET2 \
167  2, { VT_BYTE_DECODER, BASE_VOFFSET2_DECODER }
168 #define OPNDS_VTB_BASE_OFFSET4 \
169  2, { VT_BYTE_DECODER, BASE_VOFFSET4_DECODER }
170 #define OPNDS_VTB_BASE_OFFSET8 \
171  2, { VT_BYTE_DECODER, BASE_VOFFSET8_DECODER }
172 #define OPNDS_VTB_BASE_OFFSET16 \
173  2, { VT_BYTE_DECODER, BASE_VOFFSET16_DECODER }
174 #define OPNDS_VD_VS_C2_ACCU \
175  3, { VD_DECODER, VS_DECODER, C2_ACCU_DECODER }
176 #define OPNDS_VD_VS_VTE \
177  3, { VD_DECODER, VS_DECODER, VT_ELEMENT_DECODER }
178 
179 /* Instructions description */
180 #define INVALID \
181  { "invalid", RSP_OP_INVALID, OPNDS_NONE }
182 #define NOP \
183  { "nop", RSP_OP_NOP, OPNDS_NONE }
184 #define SLL \
185  { "sll", RSP_OP_SLL, OPNDS_RD_RT_SA }
186 #define SRL \
187  { "srl", RSP_OP_SRL, OPNDS_RD_RT_SA }
188 #define SRA \
189  { "sra", RSP_OP_SRA, OPNDS_RD_RT_SA }
190 #define SLLV \
191  { "sllv", RSP_OP_SLLV, OPNDS_RD_RT_RS }
192 #define SRLV \
193  { "srlv", RSP_OP_SRLV, OPNDS_RD_RT_RS }
194 #define SRAV \
195  { "srav", RSP_OP_SRAV, OPNDS_RD_RT_RS }
196 #define JR \
197  { "jr", RSP_OP_JR, OPNDS_RS }
198 #define BREAK \
199  { "break", RSP_OP_BREAK, OPNDS_NONE }
200 #define ADD \
201  { "add", RSP_OP_ADD, OPNDS_RD_RS_RT }
202 #define ADDU \
203  { "addu", RSP_OP_ADDU, OPNDS_RD_RS_RT }
204 #define SUB \
205  { "sub", RSP_OP_SUB, OPNDS_RD_RS_RT }
206 #define SUBU \
207  { "subu", RSP_OP_SUBU, OPNDS_RD_RS_RT }
208 #define AND \
209  { "and", RSP_OP_AND, OPNDS_RD_RS_RT }
210 #define OR \
211  { "or", RSP_OP_OR, OPNDS_RD_RS_RT }
212 #define XOR \
213  { "xor", RSP_OP_XOR, OPNDS_RD_RS_RT }
214 #define NOR \
215  { "nor", RSP_OP_NOR, OPNDS_RD_RS_RT }
216 #define SLT \
217  { "slt", RSP_OP_SLT, OPNDS_RD_RS_RT }
218 #define SLTU \
219  { "sltu", RSP_OP_SLTU, OPNDS_RD_RS_RT }
220 #define BLTZ \
221  { "bltz", RSP_OP_BLTZ, OPNDS_RS_OFFSET }
222 #define BGEZ \
223  { "bgez", RSP_OP_BGEZ, OPNDS_RS_OFFSET }
224 #define BLTZAL \
225  { "bltzal", RSP_OP_BLTZAL, OPNDS_RS_OFFSET }
226 #define BGEZAL \
227  { "bgezal", RSP_OP_BGEZAL, OPNDS_RS_OFFSET }
228 #define MFC0 \
229  { "mfc0", RSP_OP_MFC0, OPNDS_RT_C0_REG }
230 #define MTC0 \
231  { "mtc0", RSP_OP_MTC0, OPNDS_RT_C0_REG }
232 #define MFC2 \
233  { "mfc2", RSP_OP_MFC2, OPNDS_RT_VSB }
234 #define MTC2 \
235  { "mtc2", RSP_OP_MTC2, OPNDS_RT_VSB }
236 #define CFC2 \
237  { "cfc2", RSP_OP_CFC2, OPNDS_RT_C2_CREG }
238 #define CTC2 \
239  { "ctc2", RSP_OP_CTC2, OPNDS_RT_C2_CREG }
240 #define VMULF \
241  { "vmulf", RSP_OP_VMULF, OPNDS_VD_VS_VTE }
242 #define VMULU \
243  { "vmulu", RSP_OP_VMULU, OPNDS_VD_VS_VTE }
244 #define VMUDL \
245  { "vmudl", RSP_OP_VMUDL, OPNDS_VD_VS_VTE }
246 #define VMUDM \
247  { "vmudm", RSP_OP_VMUDM, OPNDS_VD_VS_VTE }
248 #define VMUDN \
249  { "vmudn", RSP_OP_VMUDN, OPNDS_VD_VS_VTE }
250 #define VMUDH \
251  { "vmudh", RSP_OP_VMUDH, OPNDS_VD_VS_VTE }
252 #define VMACF \
253  { "vmacf", RSP_OP_VMACF, OPNDS_VD_VS_VTE }
254 #define VMACU \
255  { "vmacu", RSP_OP_VMACU, OPNDS_VD_VS_VTE }
256 #define VMADL \
257  { "vmadl", RSP_OP_VMADL, OPNDS_VD_VS_VTE }
258 #define VMADM \
259  { "vmadm", RSP_OP_VMADM, OPNDS_VD_VS_VTE }
260 #define VMADN \
261  { "vmadn", RSP_OP_VMADN, OPNDS_VD_VS_VTE }
262 #define VMADH \
263  { "vmadh", RSP_OP_VMADH, OPNDS_VD_VS_VTE }
264 #define VADD \
265  { "vadd", RSP_OP_VADD, OPNDS_VD_VS_VTE }
266 #define VSUB \
267  { "vsub", RSP_OP_VSUB, OPNDS_VD_VS_VTE }
268 #define VABS \
269  { "vabs", RSP_OP_VABS, OPNDS_VD_VS_VTE }
270 #define VADDC \
271  { "vaddc", RSP_OP_VADDC, OPNDS_VD_VS_VTE }
272 #define VSUBC \
273  { "vsubc", RSP_OP_VSUBC, OPNDS_VD_VS_VTE }
274 #define VSAR \
275  { "vsar", RSP_OP_VSAR, OPNDS_VD_VS_C2_ACCU }
276 #define VLT \
277  { "vlt", RSP_OP_VLT, OPNDS_VD_VS_VTE }
278 #define VEQ \
279  { "veq", RSP_OP_VEQ, OPNDS_VD_VS_VTE }
280 #define VNE \
281  { "vne", RSP_OP_VNE, OPNDS_VD_VS_VTE }
282 #define VGE \
283  { "vge", RSP_OP_VGE, OPNDS_VD_VS_VTE }
284 #define VCL \
285  { "vcl", RSP_OP_VCL, OPNDS_VD_VS_VTE }
286 #define VCH \
287  { "vch", RSP_OP_VCH, OPNDS_VD_VS_VTE }
288 #define VCR \
289  { "vcr", RSP_OP_VCR, OPNDS_VD_VS_VTE }
290 #define VMRG \
291  { "vmrg", RSP_OP_VMRG, OPNDS_VD_VS_VTE }
292 #define VAND \
293  { "vand", RSP_OP_VAND, OPNDS_VD_VS_VTE }
294 #define VNAND \
295  { "vnand", RSP_OP_VNAND, OPNDS_VD_VS_VTE }
296 #define VOR \
297  { "vor", RSP_OP_VOR, OPNDS_VD_VS_VTE }
298 #define VNOR \
299  { "vnor", RSP_OP_VNOR, OPNDS_VD_VS_VTE }
300 #define VXOR \
301  { "vxor", RSP_OP_VXOR, OPNDS_VD_VS_VTE }
302 #define VNXOR \
303  { "vnxor", RSP_OP_VNXOR, OPNDS_VD_VS_VTE }
304 #define VRCP \
305  { "vrcp", RSP_OP_VRCP, OPNDS_VDS_VTS }
306 #define VRCPL \
307  { "vrcpl", RSP_OP_VRCPL, OPNDS_VDS_VTS }
308 #define VRCPH \
309  { "vrcph", RSP_OP_VRCPH, OPNDS_VDS_VTS }
310 #define VMOV \
311  { "vmov", RSP_OP_VMOV, OPNDS_VDS_VTS }
312 #define VRSQ \
313  { "vrsq", RSP_OP_VRSQ, OPNDS_VDS_VTS }
314 #define VRSQL \
315  { "vrsql", RSP_OP_VRSQL, OPNDS_VDS_VTS }
316 #define VRSQH \
317  { "vrsqh", RSP_OP_VRSQH, OPNDS_VDS_VTS }
318 #define VNOP \
319  { "vnop", RSP_OP_VNOP, OPNDS_NONE }
320 #define LBV \
321  { "lbv", RSP_OP_LBV, OPNDS_VTB_BASE_OFFSET1 }
322 #define LSV \
323  { "lsv", RSP_OP_LSV, OPNDS_VTB_BASE_OFFSET2 }
324 #define LLV \
325  { "llv", RSP_OP_LLV, OPNDS_VTB_BASE_OFFSET4 }
326 #define LDV \
327  { "ldv", RSP_OP_LDV, OPNDS_VTB_BASE_OFFSET8 }
328 #define LQV \
329  { "lqv", RSP_OP_LQV, OPNDS_VTB_BASE_OFFSET16 }
330 #define LRV \
331  { "lrv", RSP_OP_LRV, OPNDS_VTB_BASE_OFFSET16 }
332 #define LPV \
333  { "lpv", RSP_OP_LPV, OPNDS_VTB_BASE_OFFSET8 }
334 #define LUV \
335  { "luv", RSP_OP_LUV, OPNDS_VTB_BASE_OFFSET8 }
336 #define LHV \
337  { "lhv", RSP_OP_LHV, OPNDS_VTB_BASE_OFFSET16 }
338 #define LFV \
339  { "lfv", RSP_OP_LFV, OPNDS_VTB_BASE_OFFSET16 }
340 #define LTV \
341  { "ltv", RSP_OP_LTV, OPNDS_VTB_BASE_OFFSET16 }
342 #define SBV \
343  { "sbv", RSP_OP_SBV, OPNDS_VTB_BASE_OFFSET1 }
344 #define SSV \
345  { "ssv", RSP_OP_SSV, OPNDS_VTB_BASE_OFFSET2 }
346 #define SLV \
347  { "slv", RSP_OP_SLV, OPNDS_VTB_BASE_OFFSET4 }
348 #define SDV \
349  { "sdv", RSP_OP_SDV, OPNDS_VTB_BASE_OFFSET8 }
350 #define SQV \
351  { "sqv", RSP_OP_SQV, OPNDS_VTB_BASE_OFFSET16 }
352 #define SRV \
353  { "srv", RSP_OP_SRV, OPNDS_VTB_BASE_OFFSET8 }
354 #define SPV \
355  { "spv", RSP_OP_SPV, OPNDS_VTB_BASE_OFFSET8 }
356 #define SUV \
357  { "suv", RSP_OP_SUV, OPNDS_VTB_BASE_OFFSET16 }
358 #define SHV \
359  { "shv", RSP_OP_SHV, OPNDS_VTB_BASE_OFFSET16 }
360 #define SFV \
361  { "sfv", RSP_OP_SFV, OPNDS_VTB_BASE_OFFSET16 }
362 #define SWV \
363  { "swv", RSP_OP_SWV, OPNDS_VTB_BASE_OFFSET16 }
364 #define STV \
365  { "stv", RSP_OP_STV, OPNDS_VTB_BASE_OFFSET16 }
366 #define J \
367  { "j", RSP_OP_J, OPNDS_TARGET }
368 #define JAL \
369  { "jal", RSP_OP_JAL, OPNDS_TARGET }
370 #define BEQ \
371  { "beq", RSP_OP_BEQ, OPNDS_RS_RT_OFFSET }
372 #define BNE \
373  { "bne", RSP_OP_BNE, OPNDS_RS_RT_OFFSET }
374 #define BLEZ \
375  { "blez", RSP_OP_BLEZ, OPNDS_RS_RT_OFFSET }
376 #define BGTZ \
377  { "bgtz", RSP_OP_BGTZ, OPNDS_RS_RT_OFFSET }
378 #define ADDI \
379  { "addi", RSP_OP_ADDI, OPNDS_RT_RS_SIMM }
380 #define ADDIU \
381  { "addiu", RSP_OP_ADDIU, OPNDS_RT_RS_SIMM }
382 #define SLTI \
383  { "slti", RSP_OP_SLTI, OPNDS_RT_RS_SIMM }
384 #define SLTIU \
385  { "sltiu", RSP_OP_SLTIU, OPNDS_RT_RS_SIMM }
386 #define ANDI \
387  { "andi", RSP_OP_ANDI, OPNDS_RT_RS_ZIMM }
388 #define ORI \
389  { "ori", RSP_OP_ORI, OPNDS_RT_RS_ZIMM }
390 #define XORI \
391  { "xori", RSP_OP_XORI, OPNDS_RT_RS_ZIMM }
392 #define LUI \
393  { "lui", RSP_OP_LUI, OPNDS_RT_LUI }
394 #define LB \
395  { "lb", RSP_OP_LB, OPNDS_RT_BASE_OFFSET }
396 #define LH \
397  { "lh", RSP_OP_LH, OPNDS_RT_BASE_OFFSET }
398 #define LW \
399  { "lw", RSP_OP_LW, OPNDS_RT_BASE_OFFSET }
400 #define LBU \
401  { "lbu", RSP_OP_LBU, OPNDS_RT_BASE_OFFSET }
402 #define LHU \
403  { "lhu", RSP_OP_LHU, OPNDS_RT_BASE_OFFSET }
404 #define SB \
405  { "sb", RSP_OP_SB, OPNDS_RT_BASE_OFFSET }
406 #define SH \
407  { "sh", RSP_OP_SH, OPNDS_RT_BASE_OFFSET }
408 #define SW \
409  { "sw", RSP_OP_SW, OPNDS_RT_BASE_OFFSET }
410 
411 typedef struct {
413  unsigned int u_shift;
415  unsigned int u_lshift;
416  unsigned int s_shift;
419  unsigned int s_lshift;
421 
422 typedef struct {
423  const char *mnemonic;
428 
430  /* SPECIAL opcodes table
431  * 0-63
432  */
437  ADD, ADDU, SUB, SUBU, AND, OR, XOR, NOR,
441  /* REGIMM opcodes table
442  * 64-95
443  */
448  /* COP0 opcodes table
449  * 96-127
450  */
455  /* COP2/1 opcodes table
456  * 128-159
457  */
462  /* COP2/2 opcodes table
463  * 160-223
464  */
469  VLT, VEQ, VNE, VGE, VCL, VCH, VCR, VMRG,
473  /* LWC2 opcodes table
474  * 224-255
475  */
476  LBV, LSV, LLV, LDV, LQV, LRV, LPV, LUV,
480  /* SWC2 opcodes table
481  * 256-287
482  */
483  SBV, SSV, SLV, SDV, SQV, SRV, SPV, SUV,
487  /* Main opcodes table
488  * 288-351
489  */
490  INVALID, INVALID, J, JAL, BEQ, BNE, BLEZ, BGTZ,
491  ADDI, ADDIU, SLTI, SLTIU, ANDI, ORI, XORI, LUI,
494  LB, LH, INVALID, LW, LBU, LHU, INVALID, INVALID,
498  /* Pseudo opcodes
499  * 352 - ???
500  */
501  NOP
502 };
503 
504 #define SPECIAL \
505  { 0, 0, 0x3f }
506 #define REGIMM \
507  { 64, 16, 0x1f }
508 #define COP0 \
509  { 96, 21, 0x1f }
510 #define COP2 \
511  { 128, 21, 0x1f }
512 #define VECTOP \
513  { 160, 0, 0x3f }
514 #define LWC2 \
515  { 224, 11, 0x1f }
516 #define SWC2 \
517  { 256, 11, 0x1f }
518 #define MAIN \
519  { 288, 26, 0x3f }
520 
521 typedef struct {
525 } rsp_op_escape;
526 
529  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
530  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
531  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
533  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
534  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
535  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
536  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
537  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
538  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
539  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
540  MAIN, MAIN, MAIN, MAIN, LWC2, LWC2, MAIN, MAIN,
541  MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN, MAIN,
542  MAIN, MAIN, MAIN, MAIN, SWC2, SWC2, MAIN, MAIN,
544 };
545 
547  const rsp_op_escape *escape;
548 
549  /* handle NOP pseudo instruction */
550  if (iw == 0) {
551  return &rsp_op_table[352];
552  }
553 
554  escape = &rsp_escapes_table[(iw >> 25)];
555  return &rsp_op_table[escape->offset + ((iw >> escape->shift) & escape->mask)];
556 }
557 
558 static inline st32 rsp_sign_extend(st32 x, st32 m) {
559  /* assume that bits of x above the m are already zeros
560  * which is the case when called from rsp_operand_decode
561  */
562  return (x ^ m) - m;
563 }
564 
566  rsp_operand opnd;
567 
568  opnd.type = odec->type;
569  opnd.u = ((iw >> odec->u_shift) & odec->u_mask) << odec->u_lshift;
570  opnd.s = rsp_sign_extend((iw >> odec->s_shift) & odec->s_mask, odec->s_smask) << odec->s_lshift;
571 
572  /* handle targets/offsets IMEM addresses */
573  switch (opnd.type) {
574  case RSP_OPND_TARGET:
575  opnd.u = rsp_mem_addr(opnd.u, RSP_IMEM_OFFSET);
576  break;
577  case RSP_OPND_OFFSET:
578  /* +4 for delay slot */
579  opnd.u = rsp_mem_addr(pc + 4 + opnd.s, RSP_IMEM_OFFSET);
580  break;
581  default: /* do nothing */ break;
582  }
583 
584  return opnd;
585 }
586 
588  int opnd;
589  const rsp_instruction_priv *priv = rsp_decode_priv(iw);
590 
591  rsp_instruction rz_instr;
592 
593  rz_instr.mnemonic = priv->mnemonic;
594  rz_instr.opcode = priv->opcode;
595  rz_instr.noperands = priv->noperands;
596  for (opnd = 0; opnd < rz_instr.noperands; opnd++) {
597  rz_instr.operands[opnd] = rsp_operand_decode(pc, iw, &priv->odecs[opnd]);
598  }
599 
600  return rz_instr;
601 }
uint16_t ut16
uint32_t ut32
uint8_t ut8
Definition: lh5801.h:11
int x
Definition: mipsasm.c:20
#define VMUDH
Definition: rsp_idec.c:250
#define LH
Definition: rsp_idec.c:396
#define VAND
Definition: rsp_idec.c:292
#define VMULF
Definition: rsp_idec.c:240
#define SLT
Definition: rsp_idec.c:216
#define NOR
Definition: rsp_idec.c:214
#define XORI
Definition: rsp_idec.c:390
#define VMOV
Definition: rsp_idec.c:310
#define VNAND
Definition: rsp_idec.c:294
#define MFC0
Definition: rsp_idec.c:228
static const rsp_instruction_priv * rsp_decode_priv(ut32 iw)
Definition: rsp_idec.c:546
#define SLL
Definition: rsp_idec.c:184
#define VXOR
Definition: rsp_idec.c:300
#define SLV
Definition: rsp_idec.c:346
#define ADDIU
Definition: rsp_idec.c:380
#define ADDI
Definition: rsp_idec.c:378
#define COP2
Definition: rsp_idec.c:510
#define VRCP
Definition: rsp_idec.c:304
#define SRV
Definition: rsp_idec.c:352
#define JR
Definition: rsp_idec.c:196
#define LUV
Definition: rsp_idec.c:334
#define LBU
Definition: rsp_idec.c:400
rsp_instruction rsp_instruction_decode(ut64 pc, ut32 iw)
Definition: rsp_idec.c:587
#define SUV
Definition: rsp_idec.c:356
#define SBV
Definition: rsp_idec.c:342
#define VMADM
Definition: rsp_idec.c:258
#define OR
Definition: rsp_idec.c:210
#define MAIN
Definition: rsp_idec.c:518
#define SWC2
Definition: rsp_idec.c:516
#define BGEZAL
Definition: rsp_idec.c:226
#define SRL
Definition: rsp_idec.c:186
const char * rsp_c0_reg_soft_names[]
Definition: rsp_idec.c:13
#define CTC2
Definition: rsp_idec.c:238
#define VNOP
Definition: rsp_idec.c:318
#define VMADN
Definition: rsp_idec.c:260
#define SH
Definition: rsp_idec.c:406
#define SLTI
Definition: rsp_idec.c:382
#define XOR
Definition: rsp_idec.c:212
#define SDV
Definition: rsp_idec.c:348
#define STV
Definition: rsp_idec.c:364
#define SW
Definition: rsp_idec.c:408
#define BNE
Definition: rsp_idec.c:372
#define LBV
Definition: rsp_idec.c:320
const char * rsp_gp_reg_soft_names[]
Definition: rsp_idec.c:6
#define VCL
Definition: rsp_idec.c:284
static st32 rsp_sign_extend(st32 x, st32 m)
Definition: rsp_idec.c:558
#define SB
Definition: rsp_idec.c:404
#define LFV
Definition: rsp_idec.c:338
#define BLTZ
Definition: rsp_idec.c:220
#define VMUDM
Definition: rsp_idec.c:246
#define SUB
Definition: rsp_idec.c:204
const char * rsp_c0_reg_names[]
Definition: rsp_idec.c:55
#define SPV
Definition: rsp_idec.c:354
#define ANDI
Definition: rsp_idec.c:386
#define SRA
Definition: rsp_idec.c:188
#define VMADH
Definition: rsp_idec.c:262
#define VMUDL
Definition: rsp_idec.c:244
#define ADDU
Definition: rsp_idec.c:202
#define NOP
Definition: rsp_idec.c:182
#define LQV
Definition: rsp_idec.c:328
#define VEQ
Definition: rsp_idec.c:278
#define LPV
Definition: rsp_idec.c:332
#define VABS
Definition: rsp_idec.c:268
#define VMUDN
Definition: rsp_idec.c:248
const char * rsp_c2_vreg_names[]
Definition: rsp_idec.c:68
#define SPECIAL
Definition: rsp_idec.c:504
#define REGIMM
Definition: rsp_idec.c:506
#define VSAR
Definition: rsp_idec.c:274
#define CFC2
Definition: rsp_idec.c:236
const char * rsp_c2_accu_names[]
Definition: rsp_idec.c:64
#define LWC2
Definition: rsp_idec.c:514
#define SLLV
Definition: rsp_idec.c:190
#define LLV
Definition: rsp_idec.c:324
#define VGE
Definition: rsp_idec.c:282
const char * rsp_gp_reg_names[]
Definition: rsp_idec.c:20
static const rsp_instruction_priv rsp_op_table[]
Definition: rsp_idec.c:429
#define VMACU
Definition: rsp_idec.c:254
#define VNXOR
Definition: rsp_idec.c:302
#define SUBU
Definition: rsp_idec.c:206
#define MTC2
Definition: rsp_idec.c:234
#define ADD
Definition: rsp_idec.c:200
#define VMULU
Definition: rsp_idec.c:242
#define SQV
Definition: rsp_idec.c:350
const char * rsp_c2_creg_names[]
Definition: rsp_idec.c:60
#define BEQ
Definition: rsp_idec.c:370
#define JAL
Definition: rsp_idec.c:368
const char * rsp_c2_vreg_element_names[]
Definition: rsp_idec.c:75
#define SFV
Definition: rsp_idec.c:360
#define VMACF
Definition: rsp_idec.c:252
#define VMRG
Definition: rsp_idec.c:290
#define VCR
Definition: rsp_idec.c:288
#define VRSQL
Definition: rsp_idec.c:314
#define VMADL
Definition: rsp_idec.c:256
#define COP0
Definition: rsp_idec.c:508
#define BGEZ
Definition: rsp_idec.c:222
#define SHV
Definition: rsp_idec.c:358
#define VRSQ
Definition: rsp_idec.c:312
#define BLTZAL
Definition: rsp_idec.c:224
#define MTC0
Definition: rsp_idec.c:230
#define LRV
Definition: rsp_idec.c:330
#define VOR
Definition: rsp_idec.c:296
#define BREAK
Definition: rsp_idec.c:198
#define SSV
Definition: rsp_idec.c:344
#define VLT
Definition: rsp_idec.c:276
#define SLTIU
Definition: rsp_idec.c:384
#define BLEZ
Definition: rsp_idec.c:374
#define LB
Definition: rsp_idec.c:394
#define SRLV
Definition: rsp_idec.c:192
#define AND
Definition: rsp_idec.c:208
#define VADD
Definition: rsp_idec.c:264
#define VSUB
Definition: rsp_idec.c:266
#define VNE
Definition: rsp_idec.c:280
#define LW
Definition: rsp_idec.c:398
#define J
Definition: rsp_idec.c:366
#define LDV
Definition: rsp_idec.c:326
#define LTV
Definition: rsp_idec.c:340
#define ORI
Definition: rsp_idec.c:388
#define VADDC
Definition: rsp_idec.c:270
#define INVALID
Definition: rsp_idec.c:180
#define SWV
Definition: rsp_idec.c:362
#define VECTOP
Definition: rsp_idec.c:512
#define LUI
Definition: rsp_idec.c:392
#define LHU
Definition: rsp_idec.c:402
#define MFC2
Definition: rsp_idec.c:232
#define SRAV
Definition: rsp_idec.c:194
static rsp_operand rsp_operand_decode(ut64 pc, ut32 iw, const rsp_operand_decoder *odec)
Definition: rsp_idec.c:565
#define BGTZ
Definition: rsp_idec.c:376
static const rsp_op_escape rsp_escapes_table[]
Definition: rsp_idec.c:527
#define LSV
Definition: rsp_idec.c:322
#define VRCPL
Definition: rsp_idec.c:306
#define VCH
Definition: rsp_idec.c:286
#define VNOR
Definition: rsp_idec.c:298
#define VRCPH
Definition: rsp_idec.c:308
#define LHV
Definition: rsp_idec.c:336
#define SLTU
Definition: rsp_idec.c:218
#define VRSQH
Definition: rsp_idec.c:316
#define VSUBC
Definition: rsp_idec.c:272
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_operand_type
Definition: rsp_idec.h:147
@ RSP_OPND_OFFSET
Definition: rsp_idec.h:150
@ RSP_OPND_TARGET
Definition: rsp_idec.h:149
rsp_opcode
Definition: rsp_idec.h:29
#define st32
Definition: rz_types_base.h:12
rsp_opcode opcode
Definition: rsp_idec.c:424
rsp_operand_decoder odecs[RSP_MAX_OPNDS]
Definition: rsp_idec.c:426
const char * mnemonic
Definition: rsp_idec.c:423
rsp_opcode opcode
Definition: rsp_idec.h:174
rsp_operand operands[RSP_MAX_OPNDS]
Definition: rsp_idec.h:176
const char * mnemonic
Definition: rsp_idec.h:173
rsp_operand_type type
Definition: rsp_idec.c:412
unsigned int u_shift
Definition: rsp_idec.c:413
unsigned int u_lshift
Definition: rsp_idec.c:415
unsigned int s_lshift
Definition: rsp_idec.c:419
unsigned int s_shift
Definition: rsp_idec.c:416
rsp_operand_type type
Definition: rsp_idec.h:165
ut64(WINAPI *w32_GetEnabledXStateFeatures)()