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/MCContext.h"
18 #include "llvm/MC/MCDisassembler.h"
19 #include "llvm/MC/MCFixedLenDisassembler.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/Support/MemoryObject.h"
23 #include "llvm/Support/TargetRegistry.h"
27 #define DEBUG_TYPE "xcore-disassembler"
29 typedef MCDisassembler::DecodeStatus DecodeStatus;
33 /// \brief A disassembler class for XCore.
34 class XCoreDisassembler : public MCDisassembler {
36 XCoreDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) :
37 MCDisassembler(STI, Ctx) {}
39 /// \brief See MCDisassembler.
40 DecodeStatus getInstruction(MCInst &instr, uint64_t &size,
41 const MemoryObject ®ion, uint64_t address,
43 raw_ostream &cStream) const override;
47 static bool readInstruction16(const MemoryObject ®ion,
53 // We want to read exactly 2 Bytes of data.
54 if (region.readBytes(address, 2, Bytes) == -1) {
58 // Encoded as a little-endian 16-bit word in the stream.
59 insn = (Bytes[0] << 0) | (Bytes[1] << 8);
63 static bool readInstruction32(const MemoryObject ®ion,
69 // We want to read exactly 4 Bytes of data.
70 if (region.readBytes(address, 4, Bytes) == -1) {
74 // Encoded as a little-endian 32-bit word in the stream.
75 insn = (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) |
80 static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) {
81 const XCoreDisassembler *Dis = static_cast<const XCoreDisassembler*>(D);
82 const MCRegisterInfo *RegInfo = Dis->getContext().getRegisterInfo();
83 return *(RegInfo->getRegClass(RC).begin() + RegNo);
86 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
91 static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst,
96 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
97 uint64_t Address, const void *Decoder);
99 static DecodeStatus DecodeNegImmOperand(MCInst &Inst, unsigned Val,
100 uint64_t Address, const void *Decoder);
102 static DecodeStatus Decode2RInstruction(MCInst &Inst,
105 const void *Decoder);
107 static DecodeStatus Decode2RImmInstruction(MCInst &Inst,
110 const void *Decoder);
112 static DecodeStatus DecodeR2RInstruction(MCInst &Inst,
115 const void *Decoder);
117 static DecodeStatus Decode2RSrcDstInstruction(MCInst &Inst,
120 const void *Decoder);
122 static DecodeStatus DecodeRUSInstruction(MCInst &Inst,
125 const void *Decoder);
127 static DecodeStatus DecodeRUSBitpInstruction(MCInst &Inst,
130 const void *Decoder);
132 static DecodeStatus DecodeRUSSrcDstBitpInstruction(MCInst &Inst,
135 const void *Decoder);
137 static DecodeStatus DecodeL2RInstruction(MCInst &Inst,
140 const void *Decoder);
142 static DecodeStatus DecodeLR2RInstruction(MCInst &Inst,
145 const void *Decoder);
147 static DecodeStatus Decode3RInstruction(MCInst &Inst,
150 const void *Decoder);
152 static DecodeStatus Decode3RImmInstruction(MCInst &Inst,
155 const void *Decoder);
157 static DecodeStatus Decode2RUSInstruction(MCInst &Inst,
160 const void *Decoder);
162 static DecodeStatus Decode2RUSBitpInstruction(MCInst &Inst,
165 const void *Decoder);
167 static DecodeStatus DecodeL3RInstruction(MCInst &Inst,
170 const void *Decoder);
172 static DecodeStatus DecodeL3RSrcDstInstruction(MCInst &Inst,
175 const void *Decoder);
177 static DecodeStatus DecodeL2RUSInstruction(MCInst &Inst,
180 const void *Decoder);
182 static DecodeStatus DecodeL2RUSBitpInstruction(MCInst &Inst,
185 const void *Decoder);
187 static DecodeStatus DecodeL6RInstruction(MCInst &Inst,
190 const void *Decoder);
192 static DecodeStatus DecodeL5RInstruction(MCInst &Inst,
195 const void *Decoder);
197 static DecodeStatus DecodeL4RSrcDstInstruction(MCInst &Inst,
200 const void *Decoder);
202 static DecodeStatus DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst,
205 const void *Decoder);
207 #include "XCoreGenDisassemblerTables.inc"
209 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
215 return MCDisassembler::Fail;
216 unsigned Reg = getReg(Decoder, XCore::GRRegsRegClassID, RegNo);
217 Inst.addOperand(MCOperand::CreateReg(Reg));
218 return MCDisassembler::Success;
221 static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst,
227 return MCDisassembler::Fail;
228 unsigned Reg = getReg(Decoder, XCore::RRegsRegClassID, RegNo);
229 Inst.addOperand(MCOperand::CreateReg(Reg));
230 return MCDisassembler::Success;
233 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
234 uint64_t Address, const void *Decoder) {
236 return MCDisassembler::Fail;
237 static unsigned Values[] = {
238 32 /*bpw*/, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32
240 Inst.addOperand(MCOperand::CreateImm(Values[Val]));
241 return MCDisassembler::Success;
244 static DecodeStatus DecodeNegImmOperand(MCInst &Inst, unsigned Val,
245 uint64_t Address, const void *Decoder) {
246 Inst.addOperand(MCOperand::CreateImm(-(int64_t)Val));
247 return MCDisassembler::Success;
251 Decode2OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2) {
252 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
254 return MCDisassembler::Fail;
255 if (fieldFromInstruction(Insn, 5, 1)) {
257 return MCDisassembler::Fail;
261 unsigned Op1High = Combined % 3;
262 unsigned Op2High = Combined / 3;
263 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 2, 2);
264 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 0, 2);
265 return MCDisassembler::Success;
269 Decode3OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2,
271 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
273 return MCDisassembler::Fail;
275 unsigned Op1High = Combined % 3;
276 unsigned Op2High = (Combined / 3) % 3;
277 unsigned Op3High = Combined / 9;
278 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 4, 2);
279 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 2, 2);
280 Op3 = (Op3High << 2) | fieldFromInstruction(Insn, 0, 2);
281 return MCDisassembler::Success;
285 Decode2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
286 const void *Decoder) {
287 // Try and decode as a 3R instruction.
288 unsigned Opcode = fieldFromInstruction(Insn, 11, 5);
291 Inst.setOpcode(XCore::STW_2rus);
292 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
294 Inst.setOpcode(XCore::LDW_2rus);
295 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
297 Inst.setOpcode(XCore::ADD_3r);
298 return Decode3RInstruction(Inst, Insn, Address, Decoder);
300 Inst.setOpcode(XCore::SUB_3r);
301 return Decode3RInstruction(Inst, Insn, Address, Decoder);
303 Inst.setOpcode(XCore::SHL_3r);
304 return Decode3RInstruction(Inst, Insn, Address, Decoder);
306 Inst.setOpcode(XCore::SHR_3r);
307 return Decode3RInstruction(Inst, Insn, Address, Decoder);
309 Inst.setOpcode(XCore::EQ_3r);
310 return Decode3RInstruction(Inst, Insn, Address, Decoder);
312 Inst.setOpcode(XCore::AND_3r);
313 return Decode3RInstruction(Inst, Insn, Address, Decoder);
315 Inst.setOpcode(XCore::OR_3r);
316 return Decode3RInstruction(Inst, Insn, Address, Decoder);
318 Inst.setOpcode(XCore::LDW_3r);
319 return Decode3RInstruction(Inst, Insn, Address, Decoder);
321 Inst.setOpcode(XCore::LD16S_3r);
322 return Decode3RInstruction(Inst, Insn, Address, Decoder);
324 Inst.setOpcode(XCore::LD8U_3r);
325 return Decode3RInstruction(Inst, Insn, Address, Decoder);
327 Inst.setOpcode(XCore::ADD_2rus);
328 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
330 Inst.setOpcode(XCore::SUB_2rus);
331 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
333 Inst.setOpcode(XCore::SHL_2rus);
334 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
336 Inst.setOpcode(XCore::SHR_2rus);
337 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
339 Inst.setOpcode(XCore::EQ_2rus);
340 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
342 Inst.setOpcode(XCore::TSETR_3r);
343 return Decode3RImmInstruction(Inst, Insn, Address, Decoder);
345 Inst.setOpcode(XCore::LSS_3r);
346 return Decode3RInstruction(Inst, Insn, Address, Decoder);
348 Inst.setOpcode(XCore::LSU_3r);
349 return Decode3RInstruction(Inst, Insn, Address, Decoder);
351 return MCDisassembler::Fail;
355 Decode2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
356 const void *Decoder) {
358 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
359 if (S != MCDisassembler::Success)
360 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
362 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
363 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
368 Decode2RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
369 const void *Decoder) {
371 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
372 if (S != MCDisassembler::Success)
373 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
375 Inst.addOperand(MCOperand::CreateImm(Op1));
376 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
381 DecodeR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
382 const void *Decoder) {
384 DecodeStatus S = Decode2OpInstruction(Insn, Op2, Op1);
385 if (S != MCDisassembler::Success)
386 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
388 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
389 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
394 Decode2RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
395 const void *Decoder) {
397 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
398 if (S != MCDisassembler::Success)
399 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
401 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
402 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
403 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
408 DecodeRUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
409 const void *Decoder) {
411 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
412 if (S != MCDisassembler::Success)
413 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
415 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
416 Inst.addOperand(MCOperand::CreateImm(Op2));
421 DecodeRUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
422 const void *Decoder) {
424 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
425 if (S != MCDisassembler::Success)
426 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
428 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
429 DecodeBitpOperand(Inst, Op2, Address, Decoder);
434 DecodeRUSSrcDstBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
435 const void *Decoder) {
437 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
438 if (S != MCDisassembler::Success)
439 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
441 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
442 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
443 DecodeBitpOperand(Inst, Op2, Address, Decoder);
448 DecodeL2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
449 const void *Decoder) {
450 // Try and decode as a L3R / L2RUS instruction.
451 unsigned Opcode = fieldFromInstruction(Insn, 16, 4) |
452 fieldFromInstruction(Insn, 27, 5) << 4;
455 Inst.setOpcode(XCore::STW_l3r);
456 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
458 Inst.setOpcode(XCore::XOR_l3r);
459 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
461 Inst.setOpcode(XCore::ASHR_l3r);
462 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
464 Inst.setOpcode(XCore::LDAWF_l3r);
465 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
467 Inst.setOpcode(XCore::LDAWB_l3r);
468 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
470 Inst.setOpcode(XCore::LDA16F_l3r);
471 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
473 Inst.setOpcode(XCore::LDA16B_l3r);
474 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
476 Inst.setOpcode(XCore::MUL_l3r);
477 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
479 Inst.setOpcode(XCore::DIVS_l3r);
480 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
482 Inst.setOpcode(XCore::DIVU_l3r);
483 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
485 Inst.setOpcode(XCore::ST16_l3r);
486 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
488 Inst.setOpcode(XCore::ST8_l3r);
489 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
491 Inst.setOpcode(XCore::ASHR_l2rus);
492 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
494 Inst.setOpcode(XCore::OUTPW_l2rus);
495 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
497 Inst.setOpcode(XCore::INPW_l2rus);
498 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
500 Inst.setOpcode(XCore::LDAWF_l2rus);
501 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
503 Inst.setOpcode(XCore::LDAWB_l2rus);
504 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
506 Inst.setOpcode(XCore::CRC_l3r);
507 return DecodeL3RSrcDstInstruction(Inst, Insn, Address, Decoder);
509 Inst.setOpcode(XCore::REMS_l3r);
510 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
512 Inst.setOpcode(XCore::REMU_l3r);
513 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
515 return MCDisassembler::Fail;
519 DecodeL2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
520 const void *Decoder) {
522 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
524 if (S != MCDisassembler::Success)
525 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
527 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
528 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
533 DecodeLR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
534 const void *Decoder) {
536 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
538 if (S != MCDisassembler::Success)
539 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
541 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
542 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
547 Decode3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
548 const void *Decoder) {
549 unsigned Op1, Op2, Op3;
550 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
551 if (S == MCDisassembler::Success) {
552 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
553 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
554 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
560 Decode3RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
561 const void *Decoder) {
562 unsigned Op1, Op2, Op3;
563 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
564 if (S == MCDisassembler::Success) {
565 Inst.addOperand(MCOperand::CreateImm(Op1));
566 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
567 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
573 Decode2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
574 const void *Decoder) {
575 unsigned Op1, Op2, Op3;
576 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
577 if (S == MCDisassembler::Success) {
578 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
579 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
580 Inst.addOperand(MCOperand::CreateImm(Op3));
586 Decode2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
587 const void *Decoder) {
588 unsigned Op1, Op2, Op3;
589 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
590 if (S == MCDisassembler::Success) {
591 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
592 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
593 DecodeBitpOperand(Inst, Op3, Address, Decoder);
599 DecodeL3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
600 const void *Decoder) {
601 unsigned Op1, Op2, Op3;
603 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
604 if (S == MCDisassembler::Success) {
605 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
606 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
607 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
613 DecodeL3RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
614 const void *Decoder) {
615 unsigned Op1, Op2, Op3;
617 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
618 if (S == MCDisassembler::Success) {
619 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
620 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
621 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
622 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
628 DecodeL2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
629 const void *Decoder) {
630 unsigned Op1, Op2, Op3;
632 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
633 if (S == MCDisassembler::Success) {
634 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
635 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
636 Inst.addOperand(MCOperand::CreateImm(Op3));
642 DecodeL2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
643 const void *Decoder) {
644 unsigned Op1, Op2, Op3;
646 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
647 if (S == MCDisassembler::Success) {
648 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
649 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
650 DecodeBitpOperand(Inst, Op3, Address, Decoder);
656 DecodeL6RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
657 const void *Decoder) {
658 unsigned Op1, Op2, Op3, Op4, Op5, Op6;
660 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
661 if (S != MCDisassembler::Success)
663 S = Decode3OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5, Op6);
664 if (S != MCDisassembler::Success)
666 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
667 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
668 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
669 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
670 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
671 DecodeGRRegsRegisterClass(Inst, Op6, Address, Decoder);
676 DecodeL5RInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
677 const void *Decoder) {
678 // Try and decode as a L6R instruction.
680 unsigned Opcode = fieldFromInstruction(Insn, 27, 5);
683 Inst.setOpcode(XCore::LMUL_l6r);
684 return DecodeL6RInstruction(Inst, Insn, Address, Decoder);
686 return MCDisassembler::Fail;
690 DecodeL5RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
691 const void *Decoder) {
692 unsigned Op1, Op2, Op3, Op4, Op5;
694 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
695 if (S != MCDisassembler::Success)
696 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
697 S = Decode2OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5);
698 if (S != MCDisassembler::Success)
699 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
701 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
702 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
703 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
704 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
705 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
710 DecodeL4RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
711 const void *Decoder) {
712 unsigned Op1, Op2, Op3;
713 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
715 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
716 if (S == MCDisassembler::Success) {
717 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
718 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
720 if (S == MCDisassembler::Success) {
721 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
722 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
723 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
729 DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
730 const void *Decoder) {
731 unsigned Op1, Op2, Op3;
732 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
734 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
735 if (S == MCDisassembler::Success) {
736 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
737 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
739 if (S == MCDisassembler::Success) {
740 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
741 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
742 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
743 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
748 MCDisassembler::DecodeStatus
749 XCoreDisassembler::getInstruction(MCInst &instr,
751 const MemoryObject &Region,
753 raw_ostream &vStream,
754 raw_ostream &cStream) const {
757 if (!readInstruction16(Region, Address, Size, insn16)) {
761 // Calling the auto-generated decoder function.
762 DecodeStatus Result = decodeInstruction(DecoderTable16, instr, insn16,
764 if (Result != Fail) {
771 if (!readInstruction32(Region, Address, Size, insn32)) {
775 // Calling the auto-generated decoder function.
776 Result = decodeInstruction(DecoderTable32, instr, insn32, Address, this, STI);
777 if (Result != Fail) {
786 extern Target TheXCoreTarget;
789 static MCDisassembler *createXCoreDisassembler(const Target &T,
790 const MCSubtargetInfo &STI,
792 return new XCoreDisassembler(STI, Ctx);
795 extern "C" void LLVMInitializeXCoreDisassembler() {
796 // Register the disassembler.
797 TargetRegistry::RegisterMCDisassembler(TheXCoreTarget,
798 createXCoreDisassembler);