Rizin
unix-like reverse engineering framework and cli tools
analysis_sparc_cs.c File Reference
#include <rz_analysis.h>
#include <rz_lib.h>
#include <capstone/capstone.h>
#include <capstone/sparc.h>

Go to the source code of this file.

Macros

#define INSOP(n)   insn->detail->sparc.operands[n]
 
#define INSCC   insn->detail->sparc.cc
 

Functions

static void opex (RzStrBuf *buf, csh handle, cs_insn *insn)
 
static int parse_reg_name (RzRegItem *reg, csh handle, cs_insn *insn, int reg_num)
 
static void op_fillval (RzAnalysisOp *op, csh handle, cs_insn *insn)
 
static int analop (RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 
static char * get_reg_profile (RzAnalysis *analysis)
 
static int archinfo (RzAnalysis *analysis, int q)
 

Variables

RzAnalysisPlugin rz_analysis_plugin_sparc_cs
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ INSCC

#define INSCC   insn->detail->sparc.cc

Definition at line 14 of file analysis_sparc_cs.c.

◆ INSOP

#define INSOP (   n)    insn->detail->sparc.operands[n]

Definition at line 13 of file analysis_sparc_cs.c.

Function Documentation

◆ analop()

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

Definition at line 103 of file analysis_sparc_cs.c.

103  {
104  static csh handle = 0;
105  static int omode;
106  cs_insn *insn;
107  int mode, n, ret;
108 
109  if (!a->big_endian) {
110  return -1;
111  }
112 
114  if (!strcmp(a->cpu, "v9")) {
115  mode |= CS_MODE_V9;
116  }
117  if (mode != omode) {
118  cs_close(&handle);
119  handle = 0;
120  omode = mode;
121  }
122  if (handle == 0) {
123  ret = cs_open(CS_ARCH_SPARC, mode, &handle);
124  if (ret != CS_ERR_OK) {
125  return -1;
126  }
128  }
129  // capstone-next
130  n = cs_disasm(handle, (const ut8 *)buf, len, addr, 1, &insn);
131  if (n < 1) {
132  op->type = RZ_ANALYSIS_OP_TYPE_ILL;
133  } else {
135  opex(&op->opex, handle, insn);
136  }
137  op->size = insn->size;
138  op->id = insn->id;
139  switch (insn->id) {
140  case SPARC_INS_INVALID:
141  op->type = RZ_ANALYSIS_OP_TYPE_ILL;
142  break;
143  case SPARC_INS_MOV:
144  op->type = RZ_ANALYSIS_OP_TYPE_MOV;
145  break;
146  case SPARC_INS_RETT:
147  case SPARC_INS_RET:
148  case SPARC_INS_RETL:
149  op->type = RZ_ANALYSIS_OP_TYPE_RET;
150  op->delay = 1;
151  break;
152  case SPARC_INS_UNIMP:
153  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
154  break;
155  case SPARC_INS_CALL:
156  switch (INSOP(0).type) {
157  case SPARC_OP_MEM:
158  // TODO
159  break;
160  case SPARC_OP_REG:
162  op->delay = 1;
163  break;
164  default:
166  op->delay = 1;
167  op->jump = INSOP(0).imm;
168  break;
169  }
170  break;
171  case SPARC_INS_NOP:
172  op->type = RZ_ANALYSIS_OP_TYPE_NOP;
173  break;
174  case SPARC_INS_CMP:
175  op->type = RZ_ANALYSIS_OP_TYPE_CMP;
176  break;
177  case SPARC_INS_JMP:
178  case SPARC_INS_JMPL:
179  op->type = RZ_ANALYSIS_OP_TYPE_JMP;
180  op->delay = 1;
181  op->jump = INSOP(0).imm;
182  break;
183  case SPARC_INS_LDD:
184  case SPARC_INS_LD:
185  case SPARC_INS_LDQ:
186  case SPARC_INS_LDSB:
187  case SPARC_INS_LDSH:
188  case SPARC_INS_LDSW:
189  case SPARC_INS_LDUB:
190  case SPARC_INS_LDUH:
191  case SPARC_INS_LDX:
193  break;
194  case SPARC_INS_STBAR:
195  case SPARC_INS_STB:
196  case SPARC_INS_STD:
197  case SPARC_INS_ST:
198  case SPARC_INS_STH:
199  case SPARC_INS_STQ:
200  case SPARC_INS_STX:
202  break;
203  case SPARC_INS_ORCC:
204  case SPARC_INS_ORNCC:
205  case SPARC_INS_ORN:
206  case SPARC_INS_OR:
207  op->type = RZ_ANALYSIS_OP_TYPE_OR;
208  break;
209  case SPARC_INS_B:
210  case SPARC_INS_BMASK:
211  case SPARC_INS_BRGEZ:
212  case SPARC_INS_BRGZ:
213  case SPARC_INS_BRLEZ:
214  case SPARC_INS_BRLZ:
215  case SPARC_INS_BRNZ:
216  case SPARC_INS_BRZ:
217  case SPARC_INS_FB:
218  switch (INSOP(0).type) {
219  case SPARC_OP_REG:
221  op->delay = 1;
222  if (INSCC != SPARC_CC_ICC_N) { // never
223  op->jump = INSOP(1).imm;
224  }
225  if (INSCC != SPARC_CC_ICC_A) { // always
226  op->fail = addr + 8;
227  }
228  break;
229  case SPARC_OP_IMM:
231  op->delay = 1;
232  if (INSCC != SPARC_CC_ICC_N) { // never
233  op->jump = INSOP(0).imm;
234  }
235  if (INSCC != SPARC_CC_ICC_A) { // always
236  op->fail = addr + 8;
237  }
238  break;
239  default:
240  // MEM?
241  break;
242  }
243  break;
244  case SPARC_INS_FHSUBD:
245  case SPARC_INS_FHSUBS:
246  case SPARC_INS_FPSUB16:
247  case SPARC_INS_FPSUB16S:
248  case SPARC_INS_FPSUB32:
249  case SPARC_INS_FPSUB32S:
250  case SPARC_INS_FSUBD:
251  case SPARC_INS_FSUBQ:
252  case SPARC_INS_FSUBS:
253  case SPARC_INS_SUBCC:
254  case SPARC_INS_SUBX:
255  case SPARC_INS_SUBXCC:
256  case SPARC_INS_SUB:
257  case SPARC_INS_TSUBCCTV:
258  case SPARC_INS_TSUBCC:
259  op->type = RZ_ANALYSIS_OP_TYPE_SUB;
260  break;
261  case SPARC_INS_ADDCC:
262  case SPARC_INS_ADDX:
263  case SPARC_INS_ADDXCC:
264  case SPARC_INS_ADDXC:
265  case SPARC_INS_ADDXCCC:
266  case SPARC_INS_ADD:
267  case SPARC_INS_FADDD:
268  case SPARC_INS_FADDQ:
269  case SPARC_INS_FADDS:
270  case SPARC_INS_FHADDD:
271  case SPARC_INS_FHADDS:
272  case SPARC_INS_FNADDD:
273  case SPARC_INS_FNADDS:
274  case SPARC_INS_FNHADDD:
275  case SPARC_INS_FNHADDS:
276  case SPARC_INS_FPADD16:
277  case SPARC_INS_FPADD16S:
278  case SPARC_INS_FPADD32:
279  case SPARC_INS_FPADD32S:
280  case SPARC_INS_FPADD64:
281  case SPARC_INS_TADDCCTV:
282  case SPARC_INS_TADDCC:
283  op->type = RZ_ANALYSIS_OP_TYPE_ADD;
284  break;
285  case SPARC_INS_FDMULQ:
288  case SPARC_INS_FMUL8X16:
291  case SPARC_INS_FMULD:
294  case SPARC_INS_FMULQ:
295  case SPARC_INS_FMULS:
296  case SPARC_INS_FSMULD:
297  case SPARC_INS_MULX:
298  case SPARC_INS_SMULCC:
299  case SPARC_INS_SMUL:
300  case SPARC_INS_UMULCC:
301  case SPARC_INS_UMULXHI:
302  case SPARC_INS_UMUL:
303  case SPARC_INS_XMULX:
304  case SPARC_INS_XMULXHI:
305  op->type = RZ_ANALYSIS_OP_TYPE_MUL;
306  break;
307  case SPARC_INS_FDIVD:
308  case SPARC_INS_FDIVQ:
309  case SPARC_INS_FDIVS:
310  case SPARC_INS_SDIVCC:
311  case SPARC_INS_SDIVX:
312  case SPARC_INS_SDIV:
313  case SPARC_INS_UDIVCC:
314  case SPARC_INS_UDIVX:
315  case SPARC_INS_UDIV:
316  op->type = RZ_ANALYSIS_OP_TYPE_DIV;
317  break;
318  }
320  op_fillval(op, handle, insn);
321  }
322  cs_free(insn, n);
323  }
324  return op->size;
325 }
size_t len
Definition: 6502dis.c:15
#define mask()
#define INSOP(n)
static void opex(RzStrBuf *buf, csh handle, cs_insn *insn)
#define INSCC
static void op_fillval(RzAnalysisOp *op, csh handle, cs_insn *insn)
static mcore_handle handle
Definition: asm_mcore.c:8
@ CS_ARCH_SPARC
Sparc architecture.
Definition: capstone.h:80
@ CS_MODE_V9
SparcV9 mode (Sparc)
Definition: capstone.h:115
@ CS_MODE_LITTLE_ENDIAN
little-endian mode (default mode)
Definition: capstone.h:103
@ CS_OPT_DETAIL
Break down instruction structure into details.
Definition: capstone.h:171
size_t csh
Definition: capstone.h:71
@ CS_OPT_ON
Turn ON an option (CS_OPT_DETAIL, CS_OPT_SKIPDATA).
Definition: capstone.h:183
CAPSTONE_EXPORT size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64_t offset, size_t count, cs_insn **insn)
Definition: cs.c:798
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
Definition: cs.c:453
CAPSTONE_EXPORT void CAPSTONE_API cs_free(cs_insn *insn, size_t count)
Definition: cs.c:1017
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_close(csh *handle)
Definition: cs.c:501
CAPSTONE_EXPORT cs_err CAPSTONE_API cs_option(csh ud, cs_opt_type type, size_t value)
Definition: cs.c:646
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
int n
Definition: mipsasm.c:19
int type
Definition: mipsasm.c:17
int CS_ERR_OK
Definition: __init__.py:235
@ RZ_ANALYSIS_OP_MASK_VAL
Definition: rz_analysis.h:442
@ RZ_ANALYSIS_OP_MASK_OPEX
Definition: rz_analysis.h:444
@ 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_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_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_ILL
Definition: rz_analysis.h:387
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_NOP
Definition: rz_analysis.h:389
#define a(i)
Definition: sha256.c:41
@ SPARC_OP_MEM
= CS_OP_MEM (Memory operand).
Definition: sparc.h:74
@ SPARC_OP_IMM
= CS_OP_IMM (Immediate operand).
Definition: sparc.h:73
@ SPARC_OP_REG
= CS_OP_REG (Register operand).
Definition: sparc.h:72
@ SPARC_CC_ICC_N
Never.
Definition: sparc.h:26
@ SPARC_CC_ICC_A
Always.
Definition: sparc.h:25
@ SPARC_INS_BMASK
Definition: sparc.h:229
@ SPARC_INS_UNIMP
Definition: sparc.h:477
@ SPARC_INS_FSUBQ
Definition: sparc.h:394
@ SPARC_INS_NOP
Definition: sparc.h:428
@ SPARC_INS_FPADD32S
Definition: sparc.h:362
@ SPARC_INS_FSMULD
Definition: sparc.h:377
@ SPARC_INS_FPSUB16S
Definition: sparc.h:366
@ SPARC_INS_FADDD
Definition: sparc.h:260
@ SPARC_INS_UDIV
Definition: sparc.h:473
@ SPARC_INS_BRLZ
Definition: sparc.h:234
@ SPARC_INS_STQ
Definition: sparc.h:459
@ SPARC_INS_FMUL8ULX16
Definition: sparc.h:324
@ SPARC_INS_RETL
Definition: sparc.h:491
@ SPARC_INS_SUBCC
Definition: sparc.h:461
@ SPARC_INS_FMULQ
Definition: sparc.h:331
@ SPARC_INS_FMULD8SUX16
Definition: sparc.h:329
@ SPARC_INS_SMUL
Definition: sparc.h:449
@ SPARC_INS_ADDXC
Definition: sparc.h:215
@ SPARC_INS_XMULX
Definition: sparc.h:482
@ SPARC_INS_BRGEZ
Definition: sparc.h:231
@ SPARC_INS_B
Definition: sparc.h:227
@ SPARC_INS_TADDCCTV
Definition: sparc.h:466
@ SPARC_INS_FSUBD
Definition: sparc.h:393
@ SPARC_INS_LDSW
Definition: sparc.h:411
@ SPARC_INS_FMULS
Definition: sparc.h:332
@ SPARC_INS_SDIV
Definition: sparc.h:442
@ SPARC_INS_STD
Definition: sparc.h:456
@ SPARC_INS_JMP
Definition: sparc.h:228
@ SPARC_INS_FDIVQ
Definition: sparc.h:283
@ SPARC_INS_UMULCC
Definition: sparc.h:474
@ SPARC_INS_CALL
Definition: sparc.h:238
@ SPARC_INS_ORNCC
Definition: sparc.h:430
@ SPARC_INS_BRZ
Definition: sparc.h:236
@ SPARC_INS_ADDCC
Definition: sparc.h:212
@ SPARC_INS_LDSB
Definition: sparc.h:409
@ SPARC_INS_XMULXHI
Definition: sparc.h:483
@ SPARC_INS_FPSUB32
Definition: sparc.h:367
@ SPARC_INS_UMULXHI
Definition: sparc.h:475
@ SPARC_INS_FHSUBD
Definition: sparc.h:293
@ SPARC_INS_ORN
Definition: sparc.h:431
@ SPARC_INS_FMUL8X16
Definition: sparc.h:325
@ SPARC_INS_STB
Definition: sparc.h:455
@ SPARC_INS_MOV
Definition: sparc.h:418
@ SPARC_INS_BRNZ
Definition: sparc.h:235
@ SPARC_INS_UDIVCC
Definition: sparc.h:471
@ SPARC_INS_FNHADDD
Definition: sparc.h:340
@ SPARC_INS_ST
Definition: sparc.h:457
@ SPARC_INS_MULX
Definition: sparc.h:427
@ SPARC_INS_ADDXCC
Definition: sparc.h:214
@ SPARC_INS_BRLEZ
Definition: sparc.h:233
@ SPARC_INS_FDIVD
Definition: sparc.h:282
@ SPARC_INS_SUBXCC
Definition: sparc.h:463
@ SPARC_INS_FHSUBS
Definition: sparc.h:294
@ SPARC_INS_OR
Definition: sparc.h:432
@ SPARC_INS_STBAR
Definition: sparc.h:454
@ SPARC_INS_INVALID
Definition: sparc.h:210
@ SPARC_INS_SMULCC
Definition: sparc.h:448
@ SPARC_INS_FADDS
Definition: sparc.h:262
@ SPARC_INS_ORCC
Definition: sparc.h:429
@ SPARC_INS_JMPL
Definition: sparc.h:405
@ SPARC_INS_FHADDS
Definition: sparc.h:292
@ SPARC_INS_SDIVCC
Definition: sparc.h:440
@ SPARC_INS_FNADDD
Definition: sparc.h:333
@ SPARC_INS_FMUL8X16AL
Definition: sparc.h:326
@ SPARC_INS_FADDQ
Definition: sparc.h:261
@ SPARC_INS_RETT
Definition: sparc.h:438
@ SPARC_INS_ADDXCCC
Definition: sparc.h:216
@ SPARC_INS_FSUBS
Definition: sparc.h:395
@ SPARC_INS_LDQ
Definition: sparc.h:408
@ SPARC_INS_SDIVX
Definition: sparc.h:441
@ SPARC_INS_FDIVS
Definition: sparc.h:284
@ SPARC_INS_FPSUB16
Definition: sparc.h:365
@ SPARC_INS_RET
Definition: sparc.h:490
@ SPARC_INS_UMUL
Definition: sparc.h:476
@ SPARC_INS_FPSUB32S
Definition: sparc.h:368
@ SPARC_INS_LDUB
Definition: sparc.h:412
@ SPARC_INS_STX
Definition: sparc.h:460
@ SPARC_INS_FDMULQ
Definition: sparc.h:285
@ SPARC_INS_TSUBCCTV
Definition: sparc.h:469
@ SPARC_INS_FMULD
Definition: sparc.h:328
@ SPARC_INS_FMUL8X16AU
Definition: sparc.h:327
@ SPARC_INS_CMP
Definition: sparc.h:244
@ SPARC_INS_LDUH
Definition: sparc.h:413
@ SPARC_INS_FMUL8SUX16
Definition: sparc.h:323
@ SPARC_INS_SUBX
Definition: sparc.h:462
@ SPARC_INS_FPADD32
Definition: sparc.h:361
@ SPARC_INS_STH
Definition: sparc.h:458
@ SPARC_INS_FB
Definition: sparc.h:230
@ SPARC_INS_FHADDD
Definition: sparc.h:291
@ SPARC_INS_LDX
Definition: sparc.h:414
@ SPARC_INS_LDD
Definition: sparc.h:406
@ SPARC_INS_FNADDS
Definition: sparc.h:334
@ SPARC_INS_BRGZ
Definition: sparc.h:232
@ SPARC_INS_TSUBCC
Definition: sparc.h:470
@ SPARC_INS_FPADD64
Definition: sparc.h:363
@ SPARC_INS_LD
Definition: sparc.h:407
@ SPARC_INS_ADDX
Definition: sparc.h:213
@ SPARC_INS_UDIVX
Definition: sparc.h:472
@ SPARC_INS_ADD
Definition: sparc.h:217
@ SPARC_INS_TADDCC
Definition: sparc.h:467
@ SPARC_INS_FPADD16S
Definition: sparc.h:360
@ SPARC_INS_FMULD8ULX16
Definition: sparc.h:330
@ SPARC_INS_FNHADDS
Definition: sparc.h:341
@ SPARC_INS_LDSH
Definition: sparc.h:410
@ SPARC_INS_FPADD16
Definition: sparc.h:359
@ SPARC_INS_SUB
Definition: sparc.h:464
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References a, addr, CS_ARCH_SPARC, cs_close(), cs_disasm(), capstone::CS_ERR_OK, cs_free(), CS_MODE_LITTLE_ENDIAN, CS_MODE_V9, cs_open(), CS_OPT_DETAIL, CS_OPT_ON, cs_option(), handle, INSCC, INSOP, len, mask, n, op_fillval(), opex(), RZ_ANALYSIS_OP_MASK_OPEX, RZ_ANALYSIS_OP_MASK_VAL, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_DIV, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_MUL, RZ_ANALYSIS_OP_TYPE_NOP, RZ_ANALYSIS_OP_TYPE_OR, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_UCALL, RZ_ANALYSIS_OP_TYPE_UNK, SPARC_CC_ICC_A, SPARC_CC_ICC_N, SPARC_INS_ADD, SPARC_INS_ADDCC, SPARC_INS_ADDX, SPARC_INS_ADDXC, SPARC_INS_ADDXCC, SPARC_INS_ADDXCCC, SPARC_INS_B, SPARC_INS_BMASK, SPARC_INS_BRGEZ, SPARC_INS_BRGZ, SPARC_INS_BRLEZ, SPARC_INS_BRLZ, SPARC_INS_BRNZ, SPARC_INS_BRZ, SPARC_INS_CALL, SPARC_INS_CMP, SPARC_INS_FADDD, SPARC_INS_FADDQ, SPARC_INS_FADDS, SPARC_INS_FB, SPARC_INS_FDIVD, SPARC_INS_FDIVQ, SPARC_INS_FDIVS, SPARC_INS_FDMULQ, SPARC_INS_FHADDD, SPARC_INS_FHADDS, SPARC_INS_FHSUBD, SPARC_INS_FHSUBS, SPARC_INS_FMUL8SUX16, SPARC_INS_FMUL8ULX16, SPARC_INS_FMUL8X16, SPARC_INS_FMUL8X16AL, SPARC_INS_FMUL8X16AU, SPARC_INS_FMULD, SPARC_INS_FMULD8SUX16, SPARC_INS_FMULD8ULX16, SPARC_INS_FMULQ, SPARC_INS_FMULS, SPARC_INS_FNADDD, SPARC_INS_FNADDS, SPARC_INS_FNHADDD, SPARC_INS_FNHADDS, SPARC_INS_FPADD16, SPARC_INS_FPADD16S, SPARC_INS_FPADD32, SPARC_INS_FPADD32S, SPARC_INS_FPADD64, SPARC_INS_FPSUB16, SPARC_INS_FPSUB16S, SPARC_INS_FPSUB32, SPARC_INS_FPSUB32S, SPARC_INS_FSMULD, SPARC_INS_FSUBD, SPARC_INS_FSUBQ, SPARC_INS_FSUBS, SPARC_INS_INVALID, SPARC_INS_JMP, SPARC_INS_JMPL, SPARC_INS_LD, SPARC_INS_LDD, SPARC_INS_LDQ, SPARC_INS_LDSB, SPARC_INS_LDSH, SPARC_INS_LDSW, SPARC_INS_LDUB, SPARC_INS_LDUH, SPARC_INS_LDX, SPARC_INS_MOV, SPARC_INS_MULX, SPARC_INS_NOP, SPARC_INS_OR, SPARC_INS_ORCC, SPARC_INS_ORN, SPARC_INS_ORNCC, SPARC_INS_RET, SPARC_INS_RETL, SPARC_INS_RETT, SPARC_INS_SDIV, SPARC_INS_SDIVCC, SPARC_INS_SDIVX, SPARC_INS_SMUL, SPARC_INS_SMULCC, SPARC_INS_ST, SPARC_INS_STB, SPARC_INS_STBAR, SPARC_INS_STD, SPARC_INS_STH, SPARC_INS_STQ, SPARC_INS_STX, SPARC_INS_SUB, SPARC_INS_SUBCC, SPARC_INS_SUBX, SPARC_INS_SUBXCC, SPARC_INS_TADDCC, SPARC_INS_TADDCCTV, SPARC_INS_TSUBCC, SPARC_INS_TSUBCCTV, SPARC_INS_UDIV, SPARC_INS_UDIVCC, SPARC_INS_UDIVX, SPARC_INS_UMUL, SPARC_INS_UMULCC, SPARC_INS_UMULXHI, SPARC_INS_UNIMP, SPARC_INS_XMULX, SPARC_INS_XMULXHI, SPARC_OP_IMM, SPARC_OP_MEM, SPARC_OP_REG, and type.

◆ archinfo()

static int archinfo ( RzAnalysis analysis,
int  q 
)
static

Definition at line 384 of file analysis_sparc_cs.c.

384  {
385  return 4; /* :D */
386 }

◆ get_reg_profile()

static char* get_reg_profile ( RzAnalysis analysis)
static

Definition at line 327 of file analysis_sparc_cs.c.

327  {
328  const char *p =
329  "=PC pc\n"
330  "=SP sp\n"
331  "=BP fp\n"
332  "=A0 i0\n"
333  "=A1 i1\n"
334  "=A2 i2\n"
335  "=A3 i3\n"
336  "=A4 i4\n"
337  "=A5 i5\n"
338  "=R0 i7\n"
339  "gpr psr .32 0 0\n"
340  "gpr pc .32 4 0\n"
341  "gpr npc .32 8 0\n"
342  "gpr y .32 12 0\n"
343  /* r0-r7 are global aka g0-g7 */
344  "gpr g0 .32 16 0\n"
345  "gpr g1 .32 20 0\n"
346  "gpr g2 .32 24 0\n"
347  "gpr g3 .32 28 0\n"
348  "gpr g4 .32 32 0\n"
349  "gpr g5 .32 36 0\n"
350  "gpr g6 .32 40 0\n"
351  "gpr g7 .32 44 0\n"
352  /* r8-15 are out (o0-o7) */
353  "gpr o0 .32 48 0\n"
354  "gpr o1 .32 52 0\n"
355  "gpr o2 .32 56 0\n"
356  "gpr o3 .32 60 0\n"
357  "gpr o4 .32 64 0\n"
358  "gpr o5 .32 68 0\n"
359  "gpr o6 .32 72 0\n"
360  "gpr sp .32 72 0\n"
361  "gpr o7 .32 76 0\n"
362  /* r16-23 are local (l0-l7) */
363  "gpr l0 .32 80 0\n"
364  "gpr l1 .32 84 0\n"
365  "gpr l2 .32 88 0\n"
366  "gpr l3 .32 92 0\n"
367  "gpr l4 .32 96 0\n"
368  "gpr l5 .32 100 0\n"
369  "gpr l6 .32 104 0\n"
370  "gpr l7 .32 108 0\n"
371  /* r24-31 are in (i0-i7) */
372  "gpr i0 .32 112 0\n"
373  "gpr i1 .32 116 0\n"
374  "gpr i2 .32 120 0\n"
375  "gpr i3 .32 124 0\n"
376  "gpr i4 .32 128 0\n"
377  "gpr i5 .32 132 0\n"
378  "gpr i6 .32 136 0\n"
379  "gpr fp .32 136 0\n"
380  "gpr i7 .32 140 0\n";
381  return strdup(p);
382 }
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().

◆ op_fillval()

static void op_fillval ( RzAnalysisOp op,
csh  handle,
cs_insn *  insn 
)
static

Definition at line 77 of file analysis_sparc_cs.c.

77  {
78  static RzRegItem reg;
79  switch (op->type & RZ_ANALYSIS_OP_TYPE_MASK) {
81  if (INSOP(0).type == SPARC_OP_MEM) {
82  ZERO_FILL(reg);
83  op->src[0] = rz_analysis_value_new();
84  op->src[0]->type = RZ_ANALYSIS_VAL_MEM;
85  op->src[0]->reg = &reg;
86  parse_reg_name(op->src[0]->reg, handle, insn, 0);
87  op->src[0]->delta = INSOP(0).mem.disp;
88  }
89  break;
91  if (INSOP(1).type == SPARC_OP_MEM) {
92  ZERO_FILL(reg);
93  op->dst = rz_analysis_value_new();
94  op->dst->type = RZ_ANALYSIS_VAL_MEM;
95  op->dst->reg = &reg;
96  parse_reg_name(op->dst->reg, handle, insn, 1);
97  op->dst->delta = INSOP(1).mem.disp;
98  }
99  break;
100  }
101 }
RZ_API RzAnalysisValue * rz_analysis_value_new(void)
Definition: value.c:6
static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num)
#define reg(n)
@ RZ_ANALYSIS_VAL_MEM
Definition: rz_analysis.h:769
#define RZ_ANALYSIS_OP_TYPE_MASK
Definition: rz_analysis.h:358
#define ZERO_FILL(x)
Definition: rz_types.h:281

References handle, INSOP, parse_reg_name(), reg, RZ_ANALYSIS_OP_TYPE_LOAD, RZ_ANALYSIS_OP_TYPE_MASK, RZ_ANALYSIS_OP_TYPE_STORE, RZ_ANALYSIS_VAL_MEM, rz_analysis_value_new(), SPARC_OP_MEM, type, and ZERO_FILL.

Referenced by analop().

◆ opex()

static void opex ( RzStrBuf buf,
csh  handle,
cs_insn *  insn 
)
static

Definition at line 16 of file analysis_sparc_cs.c.

16  {
17  int i;
18  PJ *pj = pj_new();
19  if (!pj) {
20  return;
21  }
22  pj_o(pj);
23  pj_ka(pj, "operands");
24  cs_sparc *x = &insn->detail->sparc;
25  for (i = 0; i < x->op_count; i++) {
26  cs_sparc_op *op = x->operands + i;
27  pj_o(pj);
28  switch (op->type) {
29  case SPARC_OP_REG:
30  pj_ks(pj, "type", "reg");
31  pj_ks(pj, "value", cs_reg_name(handle, op->reg));
32  break;
33  case SPARC_OP_IMM:
34  pj_ks(pj, "type", "imm");
35  pj_kN(pj, "value", op->imm);
36  break;
37  case SPARC_OP_MEM:
38  pj_ks(pj, "type", "mem");
39  if (op->mem.base != SPARC_REG_INVALID) {
40  pj_ks(pj, "base", cs_reg_name(handle, op->mem.base));
41  }
42  pj_ki(pj, "disp", op->mem.disp);
43  break;
44  default:
45  pj_ks(pj, "type", "invalid");
46  break;
47  }
48  pj_end(pj); /* o operand */
49  }
50  pj_end(pj); /* a operands */
51  pj_end(pj);
52 
55  pj_free(pj);
56 }
lzma_index ** i
Definition: index.h:629
CAPSTONE_EXPORT const char *CAPSTONE_API cs_reg_name(csh ud, unsigned int reg)
Definition: cs.c:1154
int x
Definition: mipsasm.c:20
RZ_API PJ * pj_ka(PJ *j, const char *k)
Definition: pj.c:163
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
Instruction operand.
Definition: sparc.h:189
Instruction structure.
Definition: sparc.h:199
Definition: rz_pj.h:12
@ SPARC_REG_INVALID
Definition: sparc.h:79

References cs_reg_name(), handle, i, pj_end(), pj_free(), pj_ka(), pj_ki(), pj_kN(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_strbuf_append(), rz_strbuf_init(), SPARC_OP_IMM, SPARC_OP_MEM, SPARC_OP_REG, SPARC_REG_INVALID, and x.

Referenced by analop().

◆ parse_reg_name()

static int parse_reg_name ( RzRegItem reg,
csh  handle,
cs_insn *  insn,
int  reg_num 
)
static

Definition at line 58 of file analysis_sparc_cs.c.

58  {
59  if (!reg) {
60  return -1;
61  }
62  switch (INSOP(reg_num).type) {
63  case SPARC_OP_REG:
64  reg->name = (char *)cs_reg_name(handle, INSOP(reg_num).reg);
65  break;
66  case SPARC_OP_MEM:
67  if (INSOP(reg_num).mem.base != SPARC_REG_INVALID) {
68  reg->name = (char *)cs_reg_name(handle, INSOP(reg_num).mem.base);
69  break;
70  }
71  default:
72  break;
73  }
74  return 0;
75 }

References cs_reg_name(), handle, INSOP, reg, SPARC_OP_MEM, SPARC_OP_REG, SPARC_REG_INVALID, and type.

Referenced by op_fillval().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
}
RzAnalysisPlugin rz_analysis_plugin_sparc_cs
@ 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 401 of file analysis_sparc_cs.c.

◆ rz_analysis_plugin_sparc_cs

RzAnalysisPlugin rz_analysis_plugin_sparc_cs
Initial value:
= {
.name = "sparc",
.desc = "Capstone SPARC analysis",
.esil = false,
.license = "BSD",
.arch = "sparc",
.bits = 32 | 64,
.archinfo = archinfo,
.op = &analop,
.get_reg_profile = &get_reg_profile,
}
static char * get_reg_profile(RzAnalysis *analysis)
static int analop(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
static int archinfo(RzAnalysis *analysis, int q)

Definition at line 388 of file analysis_sparc_cs.c.