1 //===- XCoreDisassembler.cpp - Disassembler for XCore -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file is part of the XCore Disassembler.
13 //===----------------------------------------------------------------------===//
16 #include "XCoreRegisterInfo.h"
17 #include "llvm/MC/MCDisassembler.h"
18 #include "llvm/MC/MCFixedLenDisassembler.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/MemoryObject.h"
22 #include "llvm/Support/TargetRegistry.h"
26 typedef MCDisassembler::DecodeStatus DecodeStatus;
30 /// \brief A disassembler class for XCore.
31 class XCoreDisassembler : public MCDisassembler {
32 const MCRegisterInfo *RegInfo;
34 XCoreDisassembler(const MCSubtargetInfo &STI, const MCRegisterInfo *Info) :
35 MCDisassembler(STI), RegInfo(Info) {}
37 /// \brief See MCDisassembler.
38 virtual DecodeStatus getInstruction(MCInst &instr,
40 const MemoryObject ®ion,
43 raw_ostream &cStream) const;
45 const MCRegisterInfo *getRegInfo() const { return RegInfo; }
49 static bool readInstruction16(const MemoryObject ®ion,
55 // We want to read exactly 2 Bytes of data.
56 if (region.readBytes(address, 2, Bytes, NULL) == -1) {
60 // Encoded as a little-endian 16-bit word in the stream.
61 insn = (Bytes[0] << 0) | (Bytes[1] << 8);
65 static bool readInstruction32(const MemoryObject ®ion,
71 // We want to read exactly 4 Bytes of data.
72 if (region.readBytes(address, 4, Bytes, NULL) == -1) {
76 // Encoded as a little-endian 32-bit word in the stream.
77 insn = (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) |
82 static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) {
83 const XCoreDisassembler *Dis = static_cast<const XCoreDisassembler*>(D);
84 return *(Dis->getRegInfo()->getRegClass(RC).begin() + RegNo);
87 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
92 static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst,
97 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
98 uint64_t Address, const void *Decoder);
100 static DecodeStatus DecodeMEMiiOperand(MCInst &Inst, unsigned Val,
101 uint64_t Address, const void *Decoder);
103 static DecodeStatus Decode2RInstruction(MCInst &Inst,
106 const void *Decoder);
108 static DecodeStatus Decode2RImmInstruction(MCInst &Inst,
111 const void *Decoder);
113 static DecodeStatus DecodeR2RInstruction(MCInst &Inst,
116 const void *Decoder);
118 static DecodeStatus Decode2RSrcDstInstruction(MCInst &Inst,
121 const void *Decoder);
123 static DecodeStatus DecodeRUSInstruction(MCInst &Inst,
126 const void *Decoder);
128 static DecodeStatus DecodeRUSBitpInstruction(MCInst &Inst,
131 const void *Decoder);
133 static DecodeStatus DecodeRUSSrcDstBitpInstruction(MCInst &Inst,
136 const void *Decoder);
138 static DecodeStatus DecodeL2RInstruction(MCInst &Inst,
141 const void *Decoder);
143 static DecodeStatus DecodeLR2RInstruction(MCInst &Inst,
146 const void *Decoder);
148 static DecodeStatus Decode3RInstruction(MCInst &Inst,
151 const void *Decoder);
153 static DecodeStatus Decode3RImmInstruction(MCInst &Inst,
156 const void *Decoder);
158 static DecodeStatus Decode2RUSInstruction(MCInst &Inst,
161 const void *Decoder);
163 static DecodeStatus Decode2RUSBitpInstruction(MCInst &Inst,
166 const void *Decoder);
168 static DecodeStatus DecodeL3RInstruction(MCInst &Inst,
171 const void *Decoder);
173 static DecodeStatus DecodeL3RSrcDstInstruction(MCInst &Inst,
176 const void *Decoder);
178 static DecodeStatus DecodeL2RUSInstruction(MCInst &Inst,
181 const void *Decoder);
183 static DecodeStatus DecodeL2RUSBitpInstruction(MCInst &Inst,
186 const void *Decoder);
188 static DecodeStatus DecodeL6RInstruction(MCInst &Inst,
191 const void *Decoder);
193 static DecodeStatus DecodeL5RInstruction(MCInst &Inst,
196 const void *Decoder);
198 static DecodeStatus DecodeL4RSrcDstInstruction(MCInst &Inst,
201 const void *Decoder);
203 static DecodeStatus DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst,
206 const void *Decoder);
208 #include "XCoreGenDisassemblerTables.inc"
210 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
216 return MCDisassembler::Fail;
217 unsigned Reg = getReg(Decoder, XCore::GRRegsRegClassID, RegNo);
218 Inst.addOperand(MCOperand::CreateReg(Reg));
219 return MCDisassembler::Success;
222 static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst,
228 return MCDisassembler::Fail;
229 unsigned Reg = getReg(Decoder, XCore::RRegsRegClassID, RegNo);
230 Inst.addOperand(MCOperand::CreateReg(Reg));
231 return MCDisassembler::Success;
234 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
235 uint64_t Address, const void *Decoder) {
237 return MCDisassembler::Fail;
238 static unsigned Values[] = {
239 32 /*bpw*/, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32
241 Inst.addOperand(MCOperand::CreateImm(Values[Val]));
242 return MCDisassembler::Success;
245 static DecodeStatus DecodeMEMiiOperand(MCInst &Inst, unsigned Val,
246 uint64_t Address, const void *Decoder) {
247 Inst.addOperand(MCOperand::CreateImm(Val));
248 Inst.addOperand(MCOperand::CreateImm(0));
249 return MCDisassembler::Success;
253 Decode2OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2) {
254 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
256 return MCDisassembler::Fail;
257 if (fieldFromInstruction(Insn, 5, 1)) {
259 return MCDisassembler::Fail;
263 unsigned Op1High = Combined % 3;
264 unsigned Op2High = Combined / 3;
265 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 2, 2);
266 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 0, 2);
267 return MCDisassembler::Success;
271 Decode3OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2,
273 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
275 return MCDisassembler::Fail;
277 unsigned Op1High = Combined % 3;
278 unsigned Op2High = (Combined / 3) % 3;
279 unsigned Op3High = Combined / 9;
280 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 4, 2);
281 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 2, 2);
282 Op3 = (Op3High << 2) | fieldFromInstruction(Insn, 0, 2);
283 return MCDisassembler::Success;
287 Decode2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
288 const void *Decoder) {
289 // Try and decode as a 3R instruction.
290 unsigned Opcode = fieldFromInstruction(Insn, 11, 5);
293 Inst.setOpcode(XCore::STW_2rus);
294 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
296 Inst.setOpcode(XCore::LDW_2rus);
297 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
299 Inst.setOpcode(XCore::ADD_3r);
300 return Decode3RInstruction(Inst, Insn, Address, Decoder);
302 Inst.setOpcode(XCore::SUB_3r);
303 return Decode3RInstruction(Inst, Insn, Address, Decoder);
305 Inst.setOpcode(XCore::SHL_3r);
306 return Decode3RInstruction(Inst, Insn, Address, Decoder);
308 Inst.setOpcode(XCore::SHR_3r);
309 return Decode3RInstruction(Inst, Insn, Address, Decoder);
311 Inst.setOpcode(XCore::EQ_3r);
312 return Decode3RInstruction(Inst, Insn, Address, Decoder);
314 Inst.setOpcode(XCore::AND_3r);
315 return Decode3RInstruction(Inst, Insn, Address, Decoder);
317 Inst.setOpcode(XCore::OR_3r);
318 return Decode3RInstruction(Inst, Insn, Address, Decoder);
320 Inst.setOpcode(XCore::LDW_3r);
321 return Decode3RInstruction(Inst, Insn, Address, Decoder);
323 Inst.setOpcode(XCore::LD16S_3r);
324 return Decode3RInstruction(Inst, Insn, Address, Decoder);
326 Inst.setOpcode(XCore::LD8U_3r);
327 return Decode3RInstruction(Inst, Insn, Address, Decoder);
329 Inst.setOpcode(XCore::ADD_2rus);
330 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
332 Inst.setOpcode(XCore::SUB_2rus);
333 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
335 Inst.setOpcode(XCore::SHL_2rus);
336 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
338 Inst.setOpcode(XCore::SHR_2rus);
339 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
341 Inst.setOpcode(XCore::EQ_2rus);
342 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
344 Inst.setOpcode(XCore::TSETR_3r);
345 return Decode3RImmInstruction(Inst, Insn, Address, Decoder);
347 Inst.setOpcode(XCore::LSS_3r);
348 return Decode3RInstruction(Inst, Insn, Address, Decoder);
350 Inst.setOpcode(XCore::LSU_3r);
351 return Decode3RInstruction(Inst, Insn, Address, Decoder);
353 return MCDisassembler::Fail;
357 Decode2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
358 const void *Decoder) {
360 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
361 if (S != MCDisassembler::Success)
362 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
364 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
365 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
370 Decode2RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
371 const void *Decoder) {
373 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
374 if (S != MCDisassembler::Success)
375 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
377 Inst.addOperand(MCOperand::CreateImm(Op1));
378 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
383 DecodeR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
384 const void *Decoder) {
386 DecodeStatus S = Decode2OpInstruction(Insn, Op2, Op1);
387 if (S != MCDisassembler::Success)
388 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
390 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
391 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
396 Decode2RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
397 const void *Decoder) {
399 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
400 if (S != MCDisassembler::Success)
401 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
403 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
404 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
405 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
410 DecodeRUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
411 const void *Decoder) {
413 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
414 if (S != MCDisassembler::Success)
415 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
417 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
418 Inst.addOperand(MCOperand::CreateImm(Op2));
423 DecodeRUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
424 const void *Decoder) {
426 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
427 if (S != MCDisassembler::Success)
428 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
430 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
431 DecodeBitpOperand(Inst, Op2, Address, Decoder);
436 DecodeRUSSrcDstBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
437 const void *Decoder) {
439 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
440 if (S != MCDisassembler::Success)
441 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
443 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
444 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
445 DecodeBitpOperand(Inst, Op2, Address, Decoder);
450 DecodeL2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
451 const void *Decoder) {
452 // Try and decode as a L3R / L2RUS instruction.
453 unsigned Opcode = fieldFromInstruction(Insn, 16, 4) |
454 fieldFromInstruction(Insn, 27, 5) << 4;
457 Inst.setOpcode(XCore::STW_l3r);
458 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
460 Inst.setOpcode(XCore::XOR_l3r);
461 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
463 Inst.setOpcode(XCore::ASHR_l3r);
464 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
466 Inst.setOpcode(XCore::LDAWF_l3r);
467 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
469 Inst.setOpcode(XCore::LDAWB_l3r);
470 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
472 Inst.setOpcode(XCore::LDA16F_l3r);
473 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
475 Inst.setOpcode(XCore::LDA16B_l3r);
476 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
478 Inst.setOpcode(XCore::MUL_l3r);
479 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
481 Inst.setOpcode(XCore::DIVS_l3r);
482 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
484 Inst.setOpcode(XCore::DIVU_l3r);
485 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
487 Inst.setOpcode(XCore::ST16_l3r);
488 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
490 Inst.setOpcode(XCore::ST8_l3r);
491 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
493 Inst.setOpcode(XCore::ASHR_l2rus);
494 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
496 Inst.setOpcode(XCore::OUTPW_l2rus);
497 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
499 Inst.setOpcode(XCore::INPW_l2rus);
500 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
502 Inst.setOpcode(XCore::LDAWF_l2rus);
503 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
505 Inst.setOpcode(XCore::LDAWB_l2rus);
506 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
508 Inst.setOpcode(XCore::CRC_l3r);
509 return DecodeL3RSrcDstInstruction(Inst, Insn, Address, Decoder);
511 Inst.setOpcode(XCore::REMS_l3r);
512 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
514 Inst.setOpcode(XCore::REMU_l3r);
515 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
517 return MCDisassembler::Fail;
521 DecodeL2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
522 const void *Decoder) {
524 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
526 if (S != MCDisassembler::Success)
527 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
529 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
530 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
535 DecodeLR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
536 const void *Decoder) {
538 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
540 if (S != MCDisassembler::Success)
541 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
543 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
544 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
549 Decode3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
550 const void *Decoder) {
551 unsigned Op1, Op2, Op3;
552 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
553 if (S == MCDisassembler::Success) {
554 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
555 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
556 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
562 Decode3RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
563 const void *Decoder) {
564 unsigned Op1, Op2, Op3;
565 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
566 if (S == MCDisassembler::Success) {
567 Inst.addOperand(MCOperand::CreateImm(Op1));
568 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
569 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
575 Decode2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
576 const void *Decoder) {
577 unsigned Op1, Op2, Op3;
578 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
579 if (S == MCDisassembler::Success) {
580 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
581 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
582 Inst.addOperand(MCOperand::CreateImm(Op3));
588 Decode2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
589 const void *Decoder) {
590 unsigned Op1, Op2, Op3;
591 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
592 if (S == MCDisassembler::Success) {
593 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
594 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
595 DecodeBitpOperand(Inst, Op3, Address, Decoder);
601 DecodeL3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
602 const void *Decoder) {
603 unsigned Op1, Op2, Op3;
605 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
606 if (S == MCDisassembler::Success) {
607 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
608 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
609 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
615 DecodeL3RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
616 const void *Decoder) {
617 unsigned Op1, Op2, Op3;
619 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
620 if (S == MCDisassembler::Success) {
621 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
622 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
623 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
624 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
630 DecodeL2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
631 const void *Decoder) {
632 unsigned Op1, Op2, Op3;
634 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
635 if (S == MCDisassembler::Success) {
636 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
637 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
638 Inst.addOperand(MCOperand::CreateImm(Op3));
644 DecodeL2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
645 const void *Decoder) {
646 unsigned Op1, Op2, Op3;
648 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
649 if (S == MCDisassembler::Success) {
650 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
651 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
652 DecodeBitpOperand(Inst, Op3, Address, Decoder);
658 DecodeL6RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
659 const void *Decoder) {
660 unsigned Op1, Op2, Op3, Op4, Op5, Op6;
662 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
663 if (S != MCDisassembler::Success)
665 S = Decode3OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5, Op6);
666 if (S != MCDisassembler::Success)
668 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
669 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
670 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
671 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
672 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
673 DecodeGRRegsRegisterClass(Inst, Op6, Address, Decoder);
678 DecodeL5RInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
679 const void *Decoder) {
680 // Try and decode as a L6R instruction.
682 unsigned Opcode = fieldFromInstruction(Insn, 27, 5);
685 Inst.setOpcode(XCore::LMUL_l6r);
686 return DecodeL6RInstruction(Inst, Insn, Address, Decoder);
688 return MCDisassembler::Fail;
692 DecodeL5RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
693 const void *Decoder) {
694 unsigned Op1, Op2, Op3, Op4, Op5;
696 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
697 if (S != MCDisassembler::Success)
698 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
699 S = Decode2OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5);
700 if (S != MCDisassembler::Success)
701 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
703 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
704 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
705 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
706 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
707 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
712 DecodeL4RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
713 const void *Decoder) {
714 unsigned Op1, Op2, Op3;
715 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
717 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
718 if (S == MCDisassembler::Success) {
719 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
720 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
722 if (S == MCDisassembler::Success) {
723 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
724 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
725 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
731 DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
732 const void *Decoder) {
733 unsigned Op1, Op2, Op3;
734 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
736 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
737 if (S == MCDisassembler::Success) {
738 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
739 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
741 if (S == MCDisassembler::Success) {
742 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
743 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
744 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
745 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
750 MCDisassembler::DecodeStatus
751 XCoreDisassembler::getInstruction(MCInst &instr,
753 const MemoryObject &Region,
755 raw_ostream &vStream,
756 raw_ostream &cStream) const {
759 if (!readInstruction16(Region, Address, Size, insn16)) {
763 // Calling the auto-generated decoder function.
764 DecodeStatus Result = decodeInstruction(DecoderTable16, instr, insn16,
766 if (Result != Fail) {
773 if (!readInstruction32(Region, Address, Size, insn32)) {
777 // Calling the auto-generated decoder function.
778 Result = decodeInstruction(DecoderTable32, instr, insn32, Address, this, STI);
779 if (Result != Fail) {
788 extern Target TheXCoreTarget;
791 static MCDisassembler *createXCoreDisassembler(const Target &T,
792 const MCSubtargetInfo &STI) {
793 return new XCoreDisassembler(STI, T.createMCRegInfo(""));
796 extern "C" void LLVMInitializeXCoreDisassembler() {
797 // Register the disassembler.
798 TargetRegistry::RegisterMCDisassembler(TheXCoreTarget,
799 createXCoreDisassembler);