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 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
40 const MemoryObject &Region, uint64_t Address,
42 raw_ostream &CStream) const override;
46 static bool readInstruction16(const MemoryObject &Region, uint64_t Address,
47 uint64_t &Size, uint16_t &Insn) {
50 // We want to read exactly 2 Bytes of data.
51 if (Region.readBytes(Address, 2, Bytes) == -1) {
55 // Encoded as a little-endian 16-bit word in the stream.
56 Insn = (Bytes[0] << 0) | (Bytes[1] << 8);
60 static bool readInstruction32(const MemoryObject &Region, uint64_t Address,
61 uint64_t &Size, uint32_t &Insn) {
64 // We want to read exactly 4 Bytes of data.
65 if (Region.readBytes(Address, 4, Bytes) == -1) {
69 // Encoded as a little-endian 32-bit word in the stream.
71 (Bytes[0] << 0) | (Bytes[1] << 8) | (Bytes[2] << 16) | (Bytes[3] << 24);
75 static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) {
76 const XCoreDisassembler *Dis = static_cast<const XCoreDisassembler*>(D);
77 const MCRegisterInfo *RegInfo = Dis->getContext().getRegisterInfo();
78 return *(RegInfo->getRegClass(RC).begin() + RegNo);
81 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
86 static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst,
91 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
92 uint64_t Address, const void *Decoder);
94 static DecodeStatus DecodeNegImmOperand(MCInst &Inst, unsigned Val,
95 uint64_t Address, const void *Decoder);
97 static DecodeStatus Decode2RInstruction(MCInst &Inst,
100 const void *Decoder);
102 static DecodeStatus Decode2RImmInstruction(MCInst &Inst,
105 const void *Decoder);
107 static DecodeStatus DecodeR2RInstruction(MCInst &Inst,
110 const void *Decoder);
112 static DecodeStatus Decode2RSrcDstInstruction(MCInst &Inst,
115 const void *Decoder);
117 static DecodeStatus DecodeRUSInstruction(MCInst &Inst,
120 const void *Decoder);
122 static DecodeStatus DecodeRUSBitpInstruction(MCInst &Inst,
125 const void *Decoder);
127 static DecodeStatus DecodeRUSSrcDstBitpInstruction(MCInst &Inst,
130 const void *Decoder);
132 static DecodeStatus DecodeL2RInstruction(MCInst &Inst,
135 const void *Decoder);
137 static DecodeStatus DecodeLR2RInstruction(MCInst &Inst,
140 const void *Decoder);
142 static DecodeStatus Decode3RInstruction(MCInst &Inst,
145 const void *Decoder);
147 static DecodeStatus Decode3RImmInstruction(MCInst &Inst,
150 const void *Decoder);
152 static DecodeStatus Decode2RUSInstruction(MCInst &Inst,
155 const void *Decoder);
157 static DecodeStatus Decode2RUSBitpInstruction(MCInst &Inst,
160 const void *Decoder);
162 static DecodeStatus DecodeL3RInstruction(MCInst &Inst,
165 const void *Decoder);
167 static DecodeStatus DecodeL3RSrcDstInstruction(MCInst &Inst,
170 const void *Decoder);
172 static DecodeStatus DecodeL2RUSInstruction(MCInst &Inst,
175 const void *Decoder);
177 static DecodeStatus DecodeL2RUSBitpInstruction(MCInst &Inst,
180 const void *Decoder);
182 static DecodeStatus DecodeL6RInstruction(MCInst &Inst,
185 const void *Decoder);
187 static DecodeStatus DecodeL5RInstruction(MCInst &Inst,
190 const void *Decoder);
192 static DecodeStatus DecodeL4RSrcDstInstruction(MCInst &Inst,
195 const void *Decoder);
197 static DecodeStatus DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst,
200 const void *Decoder);
202 #include "XCoreGenDisassemblerTables.inc"
204 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
210 return MCDisassembler::Fail;
211 unsigned Reg = getReg(Decoder, XCore::GRRegsRegClassID, RegNo);
212 Inst.addOperand(MCOperand::CreateReg(Reg));
213 return MCDisassembler::Success;
216 static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst,
222 return MCDisassembler::Fail;
223 unsigned Reg = getReg(Decoder, XCore::RRegsRegClassID, RegNo);
224 Inst.addOperand(MCOperand::CreateReg(Reg));
225 return MCDisassembler::Success;
228 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
229 uint64_t Address, const void *Decoder) {
231 return MCDisassembler::Fail;
232 static unsigned Values[] = {
233 32 /*bpw*/, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32
235 Inst.addOperand(MCOperand::CreateImm(Values[Val]));
236 return MCDisassembler::Success;
239 static DecodeStatus DecodeNegImmOperand(MCInst &Inst, unsigned Val,
240 uint64_t Address, const void *Decoder) {
241 Inst.addOperand(MCOperand::CreateImm(-(int64_t)Val));
242 return MCDisassembler::Success;
246 Decode2OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2) {
247 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
249 return MCDisassembler::Fail;
250 if (fieldFromInstruction(Insn, 5, 1)) {
252 return MCDisassembler::Fail;
256 unsigned Op1High = Combined % 3;
257 unsigned Op2High = Combined / 3;
258 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 2, 2);
259 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 0, 2);
260 return MCDisassembler::Success;
264 Decode3OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2,
266 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
268 return MCDisassembler::Fail;
270 unsigned Op1High = Combined % 3;
271 unsigned Op2High = (Combined / 3) % 3;
272 unsigned Op3High = Combined / 9;
273 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 4, 2);
274 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 2, 2);
275 Op3 = (Op3High << 2) | fieldFromInstruction(Insn, 0, 2);
276 return MCDisassembler::Success;
280 Decode2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
281 const void *Decoder) {
282 // Try and decode as a 3R instruction.
283 unsigned Opcode = fieldFromInstruction(Insn, 11, 5);
286 Inst.setOpcode(XCore::STW_2rus);
287 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
289 Inst.setOpcode(XCore::LDW_2rus);
290 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
292 Inst.setOpcode(XCore::ADD_3r);
293 return Decode3RInstruction(Inst, Insn, Address, Decoder);
295 Inst.setOpcode(XCore::SUB_3r);
296 return Decode3RInstruction(Inst, Insn, Address, Decoder);
298 Inst.setOpcode(XCore::SHL_3r);
299 return Decode3RInstruction(Inst, Insn, Address, Decoder);
301 Inst.setOpcode(XCore::SHR_3r);
302 return Decode3RInstruction(Inst, Insn, Address, Decoder);
304 Inst.setOpcode(XCore::EQ_3r);
305 return Decode3RInstruction(Inst, Insn, Address, Decoder);
307 Inst.setOpcode(XCore::AND_3r);
308 return Decode3RInstruction(Inst, Insn, Address, Decoder);
310 Inst.setOpcode(XCore::OR_3r);
311 return Decode3RInstruction(Inst, Insn, Address, Decoder);
313 Inst.setOpcode(XCore::LDW_3r);
314 return Decode3RInstruction(Inst, Insn, Address, Decoder);
316 Inst.setOpcode(XCore::LD16S_3r);
317 return Decode3RInstruction(Inst, Insn, Address, Decoder);
319 Inst.setOpcode(XCore::LD8U_3r);
320 return Decode3RInstruction(Inst, Insn, Address, Decoder);
322 Inst.setOpcode(XCore::ADD_2rus);
323 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
325 Inst.setOpcode(XCore::SUB_2rus);
326 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
328 Inst.setOpcode(XCore::SHL_2rus);
329 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
331 Inst.setOpcode(XCore::SHR_2rus);
332 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
334 Inst.setOpcode(XCore::EQ_2rus);
335 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
337 Inst.setOpcode(XCore::TSETR_3r);
338 return Decode3RImmInstruction(Inst, Insn, Address, Decoder);
340 Inst.setOpcode(XCore::LSS_3r);
341 return Decode3RInstruction(Inst, Insn, Address, Decoder);
343 Inst.setOpcode(XCore::LSU_3r);
344 return Decode3RInstruction(Inst, Insn, Address, Decoder);
346 return MCDisassembler::Fail;
350 Decode2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
351 const void *Decoder) {
353 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
354 if (S != MCDisassembler::Success)
355 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
357 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
358 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
363 Decode2RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
364 const void *Decoder) {
366 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
367 if (S != MCDisassembler::Success)
368 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
370 Inst.addOperand(MCOperand::CreateImm(Op1));
371 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
376 DecodeR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
377 const void *Decoder) {
379 DecodeStatus S = Decode2OpInstruction(Insn, Op2, Op1);
380 if (S != MCDisassembler::Success)
381 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
383 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
384 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
389 Decode2RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
390 const void *Decoder) {
392 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
393 if (S != MCDisassembler::Success)
394 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
396 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
397 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
398 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
403 DecodeRUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
404 const void *Decoder) {
406 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
407 if (S != MCDisassembler::Success)
408 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
410 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
411 Inst.addOperand(MCOperand::CreateImm(Op2));
416 DecodeRUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
417 const void *Decoder) {
419 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
420 if (S != MCDisassembler::Success)
421 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
423 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
424 DecodeBitpOperand(Inst, Op2, Address, Decoder);
429 DecodeRUSSrcDstBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
430 const void *Decoder) {
432 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
433 if (S != MCDisassembler::Success)
434 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
436 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
437 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
438 DecodeBitpOperand(Inst, Op2, Address, Decoder);
443 DecodeL2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
444 const void *Decoder) {
445 // Try and decode as a L3R / L2RUS instruction.
446 unsigned Opcode = fieldFromInstruction(Insn, 16, 4) |
447 fieldFromInstruction(Insn, 27, 5) << 4;
450 Inst.setOpcode(XCore::STW_l3r);
451 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
453 Inst.setOpcode(XCore::XOR_l3r);
454 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
456 Inst.setOpcode(XCore::ASHR_l3r);
457 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
459 Inst.setOpcode(XCore::LDAWF_l3r);
460 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
462 Inst.setOpcode(XCore::LDAWB_l3r);
463 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
465 Inst.setOpcode(XCore::LDA16F_l3r);
466 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
468 Inst.setOpcode(XCore::LDA16B_l3r);
469 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
471 Inst.setOpcode(XCore::MUL_l3r);
472 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
474 Inst.setOpcode(XCore::DIVS_l3r);
475 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
477 Inst.setOpcode(XCore::DIVU_l3r);
478 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
480 Inst.setOpcode(XCore::ST16_l3r);
481 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
483 Inst.setOpcode(XCore::ST8_l3r);
484 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
486 Inst.setOpcode(XCore::ASHR_l2rus);
487 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
489 Inst.setOpcode(XCore::OUTPW_l2rus);
490 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
492 Inst.setOpcode(XCore::INPW_l2rus);
493 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
495 Inst.setOpcode(XCore::LDAWF_l2rus);
496 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
498 Inst.setOpcode(XCore::LDAWB_l2rus);
499 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
501 Inst.setOpcode(XCore::CRC_l3r);
502 return DecodeL3RSrcDstInstruction(Inst, Insn, Address, Decoder);
504 Inst.setOpcode(XCore::REMS_l3r);
505 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
507 Inst.setOpcode(XCore::REMU_l3r);
508 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
510 return MCDisassembler::Fail;
514 DecodeL2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
515 const void *Decoder) {
517 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
519 if (S != MCDisassembler::Success)
520 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
522 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
523 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
528 DecodeLR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
529 const void *Decoder) {
531 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
533 if (S != MCDisassembler::Success)
534 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
536 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
537 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
542 Decode3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
543 const void *Decoder) {
544 unsigned Op1, Op2, Op3;
545 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
546 if (S == MCDisassembler::Success) {
547 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
548 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
549 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
555 Decode3RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
556 const void *Decoder) {
557 unsigned Op1, Op2, Op3;
558 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
559 if (S == MCDisassembler::Success) {
560 Inst.addOperand(MCOperand::CreateImm(Op1));
561 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
562 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
568 Decode2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
569 const void *Decoder) {
570 unsigned Op1, Op2, Op3;
571 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
572 if (S == MCDisassembler::Success) {
573 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
574 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
575 Inst.addOperand(MCOperand::CreateImm(Op3));
581 Decode2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
582 const void *Decoder) {
583 unsigned Op1, Op2, Op3;
584 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
585 if (S == MCDisassembler::Success) {
586 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
587 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
588 DecodeBitpOperand(Inst, Op3, Address, Decoder);
594 DecodeL3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
595 const void *Decoder) {
596 unsigned Op1, Op2, Op3;
598 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
599 if (S == MCDisassembler::Success) {
600 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
601 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
602 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
608 DecodeL3RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
609 const void *Decoder) {
610 unsigned Op1, Op2, Op3;
612 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
613 if (S == MCDisassembler::Success) {
614 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
615 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
616 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
617 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
623 DecodeL2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
624 const void *Decoder) {
625 unsigned Op1, Op2, Op3;
627 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
628 if (S == MCDisassembler::Success) {
629 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
630 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
631 Inst.addOperand(MCOperand::CreateImm(Op3));
637 DecodeL2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
638 const void *Decoder) {
639 unsigned Op1, Op2, Op3;
641 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
642 if (S == MCDisassembler::Success) {
643 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
644 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
645 DecodeBitpOperand(Inst, Op3, Address, Decoder);
651 DecodeL6RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
652 const void *Decoder) {
653 unsigned Op1, Op2, Op3, Op4, Op5, Op6;
655 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
656 if (S != MCDisassembler::Success)
658 S = Decode3OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5, Op6);
659 if (S != MCDisassembler::Success)
661 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
662 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
663 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
664 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
665 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
666 DecodeGRRegsRegisterClass(Inst, Op6, Address, Decoder);
671 DecodeL5RInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
672 const void *Decoder) {
673 // Try and decode as a L6R instruction.
675 unsigned Opcode = fieldFromInstruction(Insn, 27, 5);
678 Inst.setOpcode(XCore::LMUL_l6r);
679 return DecodeL6RInstruction(Inst, Insn, Address, Decoder);
681 return MCDisassembler::Fail;
685 DecodeL5RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
686 const void *Decoder) {
687 unsigned Op1, Op2, Op3, Op4, Op5;
689 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
690 if (S != MCDisassembler::Success)
691 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
692 S = Decode2OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5);
693 if (S != MCDisassembler::Success)
694 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
696 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
697 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
698 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
699 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
700 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
705 DecodeL4RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
706 const void *Decoder) {
707 unsigned Op1, Op2, Op3;
708 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
710 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
711 if (S == MCDisassembler::Success) {
712 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
713 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
715 if (S == MCDisassembler::Success) {
716 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
717 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
718 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
724 DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
725 const void *Decoder) {
726 unsigned Op1, Op2, Op3;
727 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
729 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
730 if (S == MCDisassembler::Success) {
731 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
732 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
734 if (S == MCDisassembler::Success) {
735 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
736 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
737 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
738 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
743 MCDisassembler::DecodeStatus XCoreDisassembler::getInstruction(
744 MCInst &instr, uint64_t &Size, const MemoryObject &Region, uint64_t Address,
745 raw_ostream &vStream, raw_ostream &cStream) const {
748 if (!readInstruction16(Region, Address, Size, insn16)) {
752 // Calling the auto-generated decoder function.
753 DecodeStatus Result = decodeInstruction(DecoderTable16, instr, insn16,
755 if (Result != Fail) {
762 if (!readInstruction32(Region, Address, Size, insn32)) {
766 // Calling the auto-generated decoder function.
767 Result = decodeInstruction(DecoderTable32, instr, insn32, Address, this, STI);
768 if (Result != Fail) {
777 extern Target TheXCoreTarget;
780 static MCDisassembler *createXCoreDisassembler(const Target &T,
781 const MCSubtargetInfo &STI,
783 return new XCoreDisassembler(STI, Ctx);
786 extern "C" void LLVMInitializeXCoreDisassembler() {
787 // Register the disassembler.
788 TargetRegistry::RegisterMCDisassembler(TheXCoreTarget,
789 createXCoreDisassembler);