13 #ifdef CAPSTONE_HAS_SPARC
19 #include "../../cs_priv.h"
20 #include "../../utils.h"
24 #include "../../MCInst.h"
25 #include "../../MCInstrDesc.h"
26 #include "../../MCFixedLenDisassembler.h"
27 #include "../../MCRegisterInfo.h"
28 #include "../../MCDisassembler.h"
29 #include "../../MathExtras.h"
32 #define GET_REGINFO_MC_DESC
33 #define GET_REGINFO_ENUM
35 static const unsigned IntRegDecoderTable[] = {
36 SP_G0, SP_G1, SP_G2, SP_G3,
37 SP_G4, SP_G5, SP_G6, SP_G7,
38 SP_O0, SP_O1, SP_O2, SP_O3,
39 SP_O4, SP_O5, SP_O6, SP_O7,
40 SP_L0, SP_L1, SP_L2, SP_L3,
41 SP_L4, SP_L5, SP_L6, SP_L7,
42 SP_I0, SP_I1, SP_I2, SP_I3,
43 SP_I4, SP_I5, SP_I6, SP_I7
46 static const unsigned FPRegDecoderTable[] = {
47 SP_F0, SP_F1, SP_F2, SP_F3,
48 SP_F4, SP_F5, SP_F6, SP_F7,
49 SP_F8, SP_F9, SP_F10, SP_F11,
50 SP_F12, SP_F13, SP_F14, SP_F15,
51 SP_F16, SP_F17, SP_F18, SP_F19,
52 SP_F20, SP_F21, SP_F22, SP_F23,
53 SP_F24, SP_F25, SP_F26, SP_F27,
54 SP_F28, SP_F29, SP_F30, SP_F31
57 static const unsigned DFPRegDecoderTable[] = {
58 SP_D0, SP_D16, SP_D1, SP_D17,
59 SP_D2, SP_D18, SP_D3, SP_D19,
60 SP_D4, SP_D20, SP_D5, SP_D21,
61 SP_D6, SP_D22, SP_D7, SP_D23,
62 SP_D8, SP_D24, SP_D9, SP_D25,
63 SP_D10, SP_D26, SP_D11, SP_D27,
64 SP_D12, SP_D28, SP_D13, SP_D29,
65 SP_D14, SP_D30, SP_D15, SP_D31
68 static const unsigned QFPRegDecoderTable[] = {
69 SP_Q0, SP_Q8, ~0U, ~0U,
70 SP_Q1, SP_Q9, ~0U, ~0U,
71 SP_Q2, SP_Q10, ~0U, ~0U,
72 SP_Q3, SP_Q11, ~0U, ~0U,
73 SP_Q4, SP_Q12, ~0U, ~0U,
74 SP_Q5, SP_Q13, ~0U, ~0U,
75 SP_Q6, SP_Q14, ~0U, ~0U,
76 SP_Q7, SP_Q15, ~0U, ~0U
79 static const unsigned FCCRegDecoderTable[] = {
80 SP_FCC0, SP_FCC1, SP_FCC2, SP_FCC3
90 uint64_t Address,
const void *Decoder)
97 Reg = IntRegDecoderTable[RegNo];
104 uint64_t Address,
const void *Decoder)
111 Reg = IntRegDecoderTable[RegNo];
118 uint64_t Address,
const void *Decoder)
125 Reg = FPRegDecoderTable[RegNo];
132 uint64_t Address,
const void *Decoder)
139 Reg = DFPRegDecoderTable[RegNo];
146 uint64_t Address,
const void *Decoder)
153 Reg = QFPRegDecoderTable[RegNo];
163 uint64_t Address,
const void *Decoder)
175 const void *Decoder);
177 const void *Decoder);
179 const void *Decoder);
181 const void *Decoder);
183 uint64_t Address,
const void *Decoder);
185 uint64_t Address,
const void *Decoder);
187 uint64_t Address,
const void *Decoder);
189 uint64_t Address,
const void *Decoder);
191 uint64_t Address,
const void *Decoder);
193 uint64_t Address,
const void *Decoder);
195 const void *Decoder);
197 const void *Decoder);
199 const void *Decoder);
202 #define GET_SUBTARGETINFO_ENUM
214 *Insn = (
code[3] << 0) |
228 Result = readInstruction32(
code, code_len, &Insn);
236 Result = decodeInstruction_4(DecoderTableSparc32, MI, Insn, address,
247 const void *Decoder);
251 bool isLoad, DecodeFunc DecodeRD)
254 unsigned rd = fieldFromInstruction_4(insn, 25, 5);
255 unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);
256 bool isImm = fieldFromInstruction_4(insn, 13, 1) != 0;
261 simm13 =
SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);
263 rs2 = fieldFromInstruction_4(insn, 0, 5);
266 status = DecodeRD(MI,
rd, Address, Decoder);
272 status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
280 status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
286 status = DecodeRD(MI,
rd, Address, Decoder);
297 return DecodeMem(Inst, insn, Address, Decoder,
true,
298 DecodeIntRegsRegisterClass);
304 return DecodeMem(Inst, insn, Address, Decoder,
true,
305 DecodeFPRegsRegisterClass);
311 return DecodeMem(Inst, insn, Address, Decoder,
true,
312 DecodeDFPRegsRegisterClass);
318 return DecodeMem(Inst, insn, Address, Decoder,
true,
319 DecodeQFPRegsRegisterClass);
323 uint64_t Address,
const void *Decoder)
325 return DecodeMem(Inst, insn, Address, Decoder,
false,
326 DecodeIntRegsRegisterClass);
332 return DecodeMem(Inst, insn, Address, Decoder,
false,
333 DecodeFPRegsRegisterClass);
337 uint64_t Address,
const void *Decoder)
339 return DecodeMem(Inst, insn, Address, Decoder,
false,
340 DecodeDFPRegsRegisterClass);
344 uint64_t Address,
const void *Decoder)
346 return DecodeMem(Inst, insn, Address, Decoder,
false,
347 DecodeQFPRegsRegisterClass);
351 uint64_t Address,
const void *Decoder)
353 unsigned tgt = fieldFromInstruction_4(insn, 0, 30);
362 uint64_t Address,
const void *Decoder)
364 unsigned tgt =
SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);
375 unsigned rd = fieldFromInstruction_4(insn, 25, 5);
376 unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);
377 unsigned isImm = fieldFromInstruction_4(insn, 13, 1);
382 simm13 =
SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);
384 rs2 = fieldFromInstruction_4(insn, 0, 5);
387 status = DecodeIntRegsRegisterClass(MI,
rd, Address, Decoder);
392 status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
400 status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
412 unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);
413 unsigned isImm = fieldFromInstruction_4(insn, 13, 1);
417 simm13 =
SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);
419 rs2 = fieldFromInstruction_4(insn, 0, 5);
422 status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
430 status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
442 unsigned rd = fieldFromInstruction_4(insn, 25, 5);
443 unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);
444 unsigned isImm = fieldFromInstruction_4(insn, 13, 1);
449 simm13 =
SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);
451 rs2 = fieldFromInstruction_4(insn, 0, 5);
454 status = DecodeIntRegsRegisterClass(MI,
rd, Address, Decoder);
459 status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
467 status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
492 SparcMCRegisterClasses, 8,
496 SparcSubRegIdxLists, 7,
void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
void MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)
void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, const MCRegisterDesc *D, unsigned NR, unsigned RA, unsigned PC, const MCRegisterClass *C, unsigned NC, uint16_t(*RURoots)[2], unsigned NRU, const MCPhysReg *DL, const char *Strings, const uint16_t *SubIndices, unsigned NumIndices, const uint16_t *RET)
bool Sparc_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info)
void Sparc_init(MCRegisterInfo *MRI)
RzBinInfo * info(RzBinFile *bf)
#define offsetof(type, member)
return memset(p, 0, total)
static const char struct stat static buf struct stat static buf static vhangup int status