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 DecodeBitpOperand(MCInst &Inst, unsigned Val,
93 uint64_t Address, const void *Decoder);
95 static DecodeStatus DecodeMEMiiOperand(MCInst &Inst, unsigned Val,
96 uint64_t Address, const void *Decoder);
98 static DecodeStatus Decode2RInstruction(MCInst &Inst,
101 const void *Decoder);
103 static DecodeStatus Decode2RImmInstruction(MCInst &Inst,
106 const void *Decoder);
108 static DecodeStatus DecodeR2RInstruction(MCInst &Inst,
111 const void *Decoder);
113 static DecodeStatus Decode2RSrcDstInstruction(MCInst &Inst,
116 const void *Decoder);
118 static DecodeStatus DecodeRUSInstruction(MCInst &Inst,
121 const void *Decoder);
123 static DecodeStatus DecodeRUSBitpInstruction(MCInst &Inst,
126 const void *Decoder);
128 static DecodeStatus DecodeRUSSrcDstBitpInstruction(MCInst &Inst,
131 const void *Decoder);
133 static DecodeStatus DecodeL2RInstruction(MCInst &Inst,
136 const void *Decoder);
138 static DecodeStatus DecodeLR2RInstruction(MCInst &Inst,
141 const void *Decoder);
143 static DecodeStatus Decode3RInstruction(MCInst &Inst,
146 const void *Decoder);
148 static DecodeStatus Decode3RImmInstruction(MCInst &Inst,
151 const void *Decoder);
153 static DecodeStatus Decode2RUSInstruction(MCInst &Inst,
156 const void *Decoder);
158 static DecodeStatus Decode2RUSBitpInstruction(MCInst &Inst,
161 const void *Decoder);
163 static DecodeStatus DecodeL3RInstruction(MCInst &Inst,
166 const void *Decoder);
168 static DecodeStatus DecodeL3RSrcDstInstruction(MCInst &Inst,
171 const void *Decoder);
173 static DecodeStatus DecodeL2RUSInstruction(MCInst &Inst,
176 const void *Decoder);
178 static DecodeStatus DecodeL2RUSBitpInstruction(MCInst &Inst,
181 const void *Decoder);
183 static DecodeStatus DecodeL6RInstruction(MCInst &Inst,
186 const void *Decoder);
188 static DecodeStatus DecodeL5RInstruction(MCInst &Inst,
191 const void *Decoder);
193 static DecodeStatus DecodeL4RSrcDstInstruction(MCInst &Inst,
196 const void *Decoder);
198 static DecodeStatus DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst,
201 const void *Decoder);
203 #include "XCoreGenDisassemblerTables.inc"
205 static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst,
211 return MCDisassembler::Fail;
212 unsigned Reg = getReg(Decoder, XCore::GRRegsRegClassID, RegNo);
213 Inst.addOperand(MCOperand::CreateReg(Reg));
214 return MCDisassembler::Success;
217 static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val,
218 uint64_t Address, const void *Decoder) {
220 return MCDisassembler::Fail;
221 static unsigned Values[] = {
222 32 /*bpw*/, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32
224 Inst.addOperand(MCOperand::CreateImm(Values[Val]));
225 return MCDisassembler::Success;
228 static DecodeStatus DecodeMEMiiOperand(MCInst &Inst, unsigned Val,
229 uint64_t Address, const void *Decoder) {
230 Inst.addOperand(MCOperand::CreateImm(Val));
231 Inst.addOperand(MCOperand::CreateImm(0));
232 return MCDisassembler::Success;
236 Decode2OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2) {
237 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
239 return MCDisassembler::Fail;
240 if (fieldFromInstruction(Insn, 5, 1)) {
242 return MCDisassembler::Fail;
246 unsigned Op1High = Combined % 3;
247 unsigned Op2High = Combined / 3;
248 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 2, 2);
249 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 0, 2);
250 return MCDisassembler::Success;
254 Decode3OpInstruction(unsigned Insn, unsigned &Op1, unsigned &Op2,
256 unsigned Combined = fieldFromInstruction(Insn, 6, 5);
258 return MCDisassembler::Fail;
260 unsigned Op1High = Combined % 3;
261 unsigned Op2High = (Combined / 3) % 3;
262 unsigned Op3High = Combined / 9;
263 Op1 = (Op1High << 2) | fieldFromInstruction(Insn, 4, 2);
264 Op2 = (Op2High << 2) | fieldFromInstruction(Insn, 2, 2);
265 Op3 = (Op3High << 2) | fieldFromInstruction(Insn, 0, 2);
266 return MCDisassembler::Success;
270 Decode2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
271 const void *Decoder) {
272 // Try and decode as a 3R instruction.
273 unsigned Opcode = fieldFromInstruction(Insn, 11, 5);
276 Inst.setOpcode(XCore::STW_2rus);
277 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
279 Inst.setOpcode(XCore::LDW_2rus);
280 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
282 Inst.setOpcode(XCore::ADD_3r);
283 return Decode3RInstruction(Inst, Insn, Address, Decoder);
285 Inst.setOpcode(XCore::SUB_3r);
286 return Decode3RInstruction(Inst, Insn, Address, Decoder);
288 Inst.setOpcode(XCore::SHL_3r);
289 return Decode3RInstruction(Inst, Insn, Address, Decoder);
291 Inst.setOpcode(XCore::SHR_3r);
292 return Decode3RInstruction(Inst, Insn, Address, Decoder);
294 Inst.setOpcode(XCore::EQ_3r);
295 return Decode3RInstruction(Inst, Insn, Address, Decoder);
297 Inst.setOpcode(XCore::AND_3r);
298 return Decode3RInstruction(Inst, Insn, Address, Decoder);
300 Inst.setOpcode(XCore::OR_3r);
301 return Decode3RInstruction(Inst, Insn, Address, Decoder);
303 Inst.setOpcode(XCore::LDW_3r);
304 return Decode3RInstruction(Inst, Insn, Address, Decoder);
306 Inst.setOpcode(XCore::LD16S_3r);
307 return Decode3RInstruction(Inst, Insn, Address, Decoder);
309 Inst.setOpcode(XCore::LD8U_3r);
310 return Decode3RInstruction(Inst, Insn, Address, Decoder);
312 Inst.setOpcode(XCore::ADD_2rus);
313 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
315 Inst.setOpcode(XCore::SUB_2rus);
316 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
318 Inst.setOpcode(XCore::SHL_2rus);
319 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
321 Inst.setOpcode(XCore::SHR_2rus);
322 return Decode2RUSBitpInstruction(Inst, Insn, Address, Decoder);
324 Inst.setOpcode(XCore::EQ_2rus);
325 return Decode2RUSInstruction(Inst, Insn, Address, Decoder);
327 Inst.setOpcode(XCore::TSETR_3r);
328 return Decode3RImmInstruction(Inst, Insn, Address, Decoder);
330 Inst.setOpcode(XCore::LSS_3r);
331 return Decode3RInstruction(Inst, Insn, Address, Decoder);
333 Inst.setOpcode(XCore::LSU_3r);
334 return Decode3RInstruction(Inst, Insn, Address, Decoder);
336 return MCDisassembler::Fail;
340 Decode2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
341 const void *Decoder) {
343 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
344 if (S != MCDisassembler::Success)
345 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
347 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
348 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
353 Decode2RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
354 const void *Decoder) {
356 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
357 if (S != MCDisassembler::Success)
358 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
360 Inst.addOperand(MCOperand::CreateImm(Op1));
361 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
366 DecodeR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
367 const void *Decoder) {
369 DecodeStatus S = Decode2OpInstruction(Insn, Op2, Op1);
370 if (S != MCDisassembler::Success)
371 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
373 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
374 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
379 Decode2RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
380 const void *Decoder) {
382 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
383 if (S != MCDisassembler::Success)
384 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
386 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
387 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
388 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
393 DecodeRUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
394 const void *Decoder) {
396 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
397 if (S != MCDisassembler::Success)
398 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
400 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
401 Inst.addOperand(MCOperand::CreateImm(Op2));
406 DecodeRUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
407 const void *Decoder) {
409 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
410 if (S != MCDisassembler::Success)
411 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
413 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
414 DecodeBitpOperand(Inst, Op2, Address, Decoder);
419 DecodeRUSSrcDstBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
420 const void *Decoder) {
422 DecodeStatus S = Decode2OpInstruction(Insn, Op1, Op2);
423 if (S != MCDisassembler::Success)
424 return Decode2OpInstructionFail(Inst, Insn, Address, Decoder);
426 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
427 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
428 DecodeBitpOperand(Inst, Op2, Address, Decoder);
433 DecodeL2OpInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
434 const void *Decoder) {
435 // Try and decode as a L3R / L2RUS instruction.
436 unsigned Opcode = fieldFromInstruction(Insn, 16, 4) |
437 fieldFromInstruction(Insn, 27, 5) << 4;
440 Inst.setOpcode(XCore::STW_l3r);
441 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
443 Inst.setOpcode(XCore::XOR_l3r);
444 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
446 Inst.setOpcode(XCore::ASHR_l3r);
447 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
449 Inst.setOpcode(XCore::LDAWF_l3r);
450 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
452 Inst.setOpcode(XCore::LDAWB_l3r);
453 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
455 Inst.setOpcode(XCore::LDA16F_l3r);
456 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
458 Inst.setOpcode(XCore::LDA16B_l3r);
459 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
461 Inst.setOpcode(XCore::MUL_l3r);
462 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
464 Inst.setOpcode(XCore::DIVS_l3r);
465 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
467 Inst.setOpcode(XCore::DIVU_l3r);
468 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
470 Inst.setOpcode(XCore::ST16_l3r);
471 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
473 Inst.setOpcode(XCore::ST8_l3r);
474 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
476 Inst.setOpcode(XCore::ASHR_l2rus);
477 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
479 Inst.setOpcode(XCore::OUTPW_l2rus);
480 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
482 Inst.setOpcode(XCore::INPW_l2rus);
483 return DecodeL2RUSBitpInstruction(Inst, Insn, Address, Decoder);
485 Inst.setOpcode(XCore::LDAWF_l2rus);
486 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
488 Inst.setOpcode(XCore::LDAWB_l2rus);
489 return DecodeL2RUSInstruction(Inst, Insn, Address, Decoder);
491 Inst.setOpcode(XCore::CRC_l3r);
492 return DecodeL3RSrcDstInstruction(Inst, Insn, Address, Decoder);
494 Inst.setOpcode(XCore::REMS_l3r);
495 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
497 Inst.setOpcode(XCore::REMU_l3r);
498 return DecodeL3RInstruction(Inst, Insn, Address, Decoder);
500 return MCDisassembler::Fail;
504 DecodeL2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
505 const void *Decoder) {
507 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
509 if (S != MCDisassembler::Success)
510 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
512 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
513 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
518 DecodeLR2RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
519 const void *Decoder) {
521 DecodeStatus S = Decode2OpInstruction(fieldFromInstruction(Insn, 0, 16),
523 if (S != MCDisassembler::Success)
524 return DecodeL2OpInstructionFail(Inst, Insn, Address, Decoder);
526 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
527 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
532 Decode3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
533 const void *Decoder) {
534 unsigned Op1, Op2, Op3;
535 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
536 if (S == MCDisassembler::Success) {
537 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
538 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
539 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
545 Decode3RImmInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
546 const void *Decoder) {
547 unsigned Op1, Op2, Op3;
548 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
549 if (S == MCDisassembler::Success) {
550 Inst.addOperand(MCOperand::CreateImm(Op1));
551 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
552 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
558 Decode2RUSInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
559 const void *Decoder) {
560 unsigned Op1, Op2, Op3;
561 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
562 if (S == MCDisassembler::Success) {
563 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
564 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
565 Inst.addOperand(MCOperand::CreateImm(Op3));
571 Decode2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
572 const void *Decoder) {
573 unsigned Op1, Op2, Op3;
574 DecodeStatus S = Decode3OpInstruction(Insn, Op1, Op2, Op3);
575 if (S == MCDisassembler::Success) {
576 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
577 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
578 DecodeBitpOperand(Inst, Op3, Address, Decoder);
584 DecodeL3RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
585 const void *Decoder) {
586 unsigned Op1, Op2, Op3;
588 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
589 if (S == MCDisassembler::Success) {
590 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
591 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
592 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
598 DecodeL3RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
599 const void *Decoder) {
600 unsigned Op1, Op2, Op3;
602 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
603 if (S == MCDisassembler::Success) {
604 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
605 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
606 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
607 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
613 DecodeL2RUSInstruction(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, Op2, Address, Decoder);
621 Inst.addOperand(MCOperand::CreateImm(Op3));
627 DecodeL2RUSBitpInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
628 const void *Decoder) {
629 unsigned Op1, Op2, Op3;
631 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
632 if (S == MCDisassembler::Success) {
633 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
634 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
635 DecodeBitpOperand(Inst, Op3, Address, Decoder);
641 DecodeL6RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
642 const void *Decoder) {
643 unsigned Op1, Op2, Op3, Op4, Op5, Op6;
645 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
646 if (S != MCDisassembler::Success)
648 S = Decode3OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5, Op6);
649 if (S != MCDisassembler::Success)
651 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
652 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
653 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
654 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
655 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
656 DecodeGRRegsRegisterClass(Inst, Op6, Address, Decoder);
661 DecodeL5RInstructionFail(MCInst &Inst, unsigned Insn, uint64_t Address,
662 const void *Decoder) {
663 // Try and decode as a L6R instruction.
665 unsigned Opcode = fieldFromInstruction(Insn, 27, 5);
668 Inst.setOpcode(XCore::LMUL_l6r);
669 return DecodeL6RInstruction(Inst, Insn, Address, Decoder);
671 return MCDisassembler::Fail;
675 DecodeL5RInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
676 const void *Decoder) {
677 unsigned Op1, Op2, Op3, Op4, Op5;
679 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
680 if (S != MCDisassembler::Success)
681 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
682 S = Decode2OpInstruction(fieldFromInstruction(Insn, 16, 16), Op4, Op5);
683 if (S != MCDisassembler::Success)
684 return DecodeL5RInstructionFail(Inst, Insn, Address, Decoder);
686 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
687 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
688 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
689 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
690 DecodeGRRegsRegisterClass(Inst, Op5, Address, Decoder);
695 DecodeL4RSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
696 const void *Decoder) {
697 unsigned Op1, Op2, Op3;
698 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
700 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
701 if (S == MCDisassembler::Success) {
702 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
703 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
705 if (S == MCDisassembler::Success) {
706 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
707 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
708 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
714 DecodeL4RSrcDstSrcDstInstruction(MCInst &Inst, unsigned Insn, uint64_t Address,
715 const void *Decoder) {
716 unsigned Op1, Op2, Op3;
717 unsigned Op4 = fieldFromInstruction(Insn, 16, 4);
719 Decode3OpInstruction(fieldFromInstruction(Insn, 0, 16), Op1, Op2, Op3);
720 if (S == MCDisassembler::Success) {
721 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
722 S = DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
724 if (S == MCDisassembler::Success) {
725 DecodeGRRegsRegisterClass(Inst, Op1, Address, Decoder);
726 DecodeGRRegsRegisterClass(Inst, Op4, Address, Decoder);
727 DecodeGRRegsRegisterClass(Inst, Op2, Address, Decoder);
728 DecodeGRRegsRegisterClass(Inst, Op3, Address, Decoder);
733 MCDisassembler::DecodeStatus
734 XCoreDisassembler::getInstruction(MCInst &instr,
736 const MemoryObject &Region,
738 raw_ostream &vStream,
739 raw_ostream &cStream) const {
742 if (!readInstruction16(Region, Address, Size, insn16)) {
746 // Calling the auto-generated decoder function.
747 DecodeStatus Result = decodeInstruction(DecoderTable16, instr, insn16,
749 if (Result != Fail) {
756 if (!readInstruction32(Region, Address, Size, insn32)) {
760 // Calling the auto-generated decoder function.
761 Result = decodeInstruction(DecoderTable32, instr, insn32, Address, this, STI);
762 if (Result != Fail) {
771 extern Target TheXCoreTarget;
774 static MCDisassembler *createXCoreDisassembler(const Target &T,
775 const MCSubtargetInfo &STI) {
776 return new XCoreDisassembler(STI, T.createMCRegInfo(""));
779 extern "C" void LLVMInitializeXCoreDisassembler() {
780 // Register the disassembler.
781 TargetRegistry::RegisterMCDisassembler(TheXCoreTarget,
782 createXCoreDisassembler);