13 #ifdef CAPSTONE_HAS_XCORE
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"
44 *insn = (
code[0] << 0) | (
code[1] << 8);
60 static unsigned getReg(
const MCRegisterInfo *MRI,
unsigned RC,
unsigned RegNo)
67 uint64_t Address,
const void *Decoder);
70 uint64_t Address,
const void *Decoder);
73 uint64_t Address,
const void *Decoder);
76 uint64_t Address,
const void *Decoder);
79 uint64_t Address,
const void *Decoder);
82 uint64_t Address,
const void *Decoder);
85 uint64_t Address,
const void *Decoder);
88 uint64_t Address,
const void *Decoder);
91 uint64_t Address,
const void *Decoder);
94 uint64_t Address,
const void *Decoder);
97 uint64_t Address,
const void *Decoder);
100 uint64_t Address,
const void *Decoder);
103 uint64_t Address,
const void *Decoder);
106 uint64_t Address,
const void *Decoder);
109 uint64_t Address,
const void *Decoder);
112 uint64_t Address,
const void *Decoder);
115 uint64_t Address,
const void *Decoder);
118 uint64_t Address,
const void *Decoder);
121 uint64_t Address,
const void *Decoder);
124 uint64_t Address,
const void *Decoder);
127 uint64_t Address,
const void *Decoder);
130 uint64_t Address,
const void *Decoder);
133 uint64_t Address,
const void *Decoder);
136 uint64_t Address,
const void *Decoder);
139 uint64_t Address,
const void *Decoder);
143 #define GET_REGINFO_ENUM
144 #define GET_REGINFO_MC_DESC
148 uint64_t Address,
const void *Decoder)
155 Reg = getReg(Decoder, XCore_GRRegsRegClassID, RegNo);
162 uint64_t Address,
const void *Decoder)
168 Reg = getReg(Decoder, XCore_RRegsRegClassID, RegNo);
175 uint64_t Address,
const void *Decoder)
177 static const unsigned Values[] = {
178 32 , 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32
189 uint64_t Address,
const void *Decoder)
195 static DecodeStatus Decode2OpInstruction(
unsigned Insn,
unsigned *Op1,
unsigned *Op2)
197 unsigned Op1High, Op2High;
198 unsigned Combined = fieldFromInstruction_4(Insn, 6, 5);
203 if (fieldFromInstruction_4(Insn, 5, 1)) {
210 Op1High = Combined % 3;
211 Op2High = Combined / 3;
212 *Op1 = (Op1High << 2) | fieldFromInstruction_4(Insn, 2, 2);
213 *Op2 = (Op2High << 2) | fieldFromInstruction_4(Insn, 0, 2);
219 unsigned *Op1,
unsigned *Op2,
unsigned *Op3)
221 unsigned Op1High, Op2High, Op3High;
222 unsigned Combined = fieldFromInstruction_4(Insn, 6, 5);
226 Op1High = Combined % 3;
227 Op2High = (Combined / 3) % 3;
228 Op3High = Combined / 9;
229 *Op1 = (Op1High << 2) | fieldFromInstruction_4(Insn, 4, 2);
230 *Op2 = (Op2High << 2) | fieldFromInstruction_4(Insn, 2, 2);
231 *Op3 = (Op3High << 2) | fieldFromInstruction_4(Insn, 0, 2);
236 #define GET_INSTRINFO_ENUM
242 unsigned Opcode = fieldFromInstruction_4(Insn, 11, 5);
246 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
249 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
252 return Decode3RInstruction(Inst, Insn, Address, Decoder);
255 return Decode3RInstruction(Inst, Insn, Address, Decoder);
258 return Decode3RInstruction(Inst, Insn, Address, Decoder);
261 return Decode3RInstruction(Inst, Insn, Address, Decoder);
264 return Decode3RInstruction(Inst, Insn, Address, Decoder);
267 return Decode3RInstruction(Inst, Insn, Address, Decoder);
270 return Decode3RInstruction(Inst, Insn, Address, Decoder);
273 return Decode3RInstruction(Inst, Insn, Address, Decoder);
276 return Decode3RInstruction(Inst, Insn, Address, Decoder);
279 return Decode3RInstruction(Inst, Insn, Address, Decoder);
282 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
285 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
288 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
291 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
294 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
297 return Decode3RImmInstruction(Inst, Insn, Address, Decoder);
300 return Decode3RInstruction(Inst, Insn, Address, Decoder);
303 return Decode3RInstruction(Inst, Insn, Address, Decoder);
315 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
317 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
318 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
329 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
332 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
343 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
345 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
346 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
357 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
359 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
360 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
361 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
372 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
374 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
386 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
388 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
389 DecodeBitpOperand(Inst, Op2, Address, Decoder);
400 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
402 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
403 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
404 DecodeBitpOperand(Inst, Op2, Address, Decoder);
413 unsigned Opcode = fieldFromInstruction_4(Insn, 16, 4) |
414 fieldFromInstruction_4(Insn, 27, 5) << 4;
418 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
421 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
424 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
427 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
430 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
433 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
436 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
439 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
442 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
445 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
448 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
451 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
454 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
457 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
460 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
463 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
466 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
469 return DecodeL3RSrcDstInstruction(Inst, Insn, Address, Decoder);
472 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
475 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
485 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2);
487 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
489 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
490 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
499 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2);
501 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
503 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
504 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
512 unsigned Op1, Op2, Op3;
513 DecodeStatus S = Decode3OpInstruction(Insn, &Op1, &Op2, &Op3);
515 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
516 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
517 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
526 unsigned Op1, Op2, Op3;
527 DecodeStatus S = Decode3OpInstruction(Insn, &Op1, &Op2, &Op3);
530 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
531 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
540 unsigned Op1, Op2, Op3;
541 DecodeStatus S = Decode3OpInstruction(Insn, &Op1, &Op2, &Op3);
543 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
544 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
554 unsigned Op1, Op2, Op3;
555 DecodeStatus S = Decode3OpInstruction(Insn, &Op1, &Op2, &Op3);
557 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
558 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
559 DecodeBitpOperand(Inst, Op3, Address, Decoder);
568 unsigned Op1, Op2, Op3;
570 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
572 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
573 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
574 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
583 unsigned Op1, Op2, Op3;
585 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
587 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
588 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
589 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
590 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
599 unsigned Op1, Op2, Op3;
601 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
603 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
604 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
614 unsigned Op1, Op2, Op3;
616 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
618 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
619 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
620 DecodeBitpOperand(Inst, Op3, Address, Decoder);
629 unsigned Op1, Op2, Op3, Op4, Op5, Op6;
631 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
635 S = Decode3OpInstruction(fieldFromInstruction_4(Insn, 16, 16), &Op4, &Op5, &Op6);
639 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
640 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
641 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
642 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
643 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
644 DecodeGRRegsRegisterClass(Inst, Op6, Address, Decoder);
655 Opcode = fieldFromInstruction_4(Insn, 27, 5);
661 return DecodeL6RInstruction(Inst, Insn, Address, Decoder);
670 unsigned Op1, Op2, Op3, Op4, Op5;
672 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
674 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
676 S = Decode2OpInstruction(fieldFromInstruction_4(Insn, 16, 16), &Op4, &Op5);
678 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
680 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
681 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
682 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
683 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
684 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
691 unsigned Op1, Op2, Op3;
692 unsigned Op4 = fieldFromInstruction_4(Insn, 16, 4);
694 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
696 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
697 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
701 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
702 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
703 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
711 unsigned Op1, Op2, Op3;
712 unsigned Op4 = fieldFromInstruction_4(Insn, 16, 4);
714 Decode3OpInstruction(fieldFromInstruction_4(Insn, 0, 16), &Op1, &Op2, &Op3);
716 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
717 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
721 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
722 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
723 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
724 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
730 #define GET_SUBTARGETINFO_ENUM
739 if (!readInstruction16(
code, code_len, &insn16)) {
748 Result = decodeInstruction_2(DecoderTable16, MI, insn16, address,
info, 0);
754 if (!readInstruction32(
code, code_len, &insn32)) {
759 Result = decodeInstruction_4(DecoderTable32, MI, insn32, address,
info, 0);
786 XCoreMCRegisterClasses, 2,
790 XCoreSubRegIdxLists, 1,
void MCInst_clear(MCInst *inst)
void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
void MCInst_setOpcode(MCInst *inst, unsigned Op)
void MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)
const MCRegisterClass * MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i)
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 XCore_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr, uint16_t *size, uint64_t address, void *info)
void XCore_init(MCRegisterInfo *MRI)
RzBinInfo * info(RzBinFile *bf)
#define offsetof(type, member)
return memset(p, 0, total)