1 //===- XCoreDisassembler.cpp - Disassembler for XCore -----------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file is part of the XCore Disassembler.
12 //===----------------------------------------------------------------------===//
14 #include "TargetInfo/XCoreTargetInfo.h"
16 #include "XCoreRegisterInfo.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCDecoderOps.h"
19 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCSubtargetInfo.h"
22 #include "llvm/MC/TargetRegistry.h"
26 #define DEBUG_TYPE "xcore-disassembler"
28 typedef MCDisassembler::DecodeStatus DecodeStatus
;
32 /// A disassembler class for XCore.
33 class XCoreDisassembler
: public MCDisassembler
{
35 XCoreDisassembler(const MCSubtargetInfo
&STI
, MCContext
&Ctx
) :
36 MCDisassembler(STI
, Ctx
) {}
38 DecodeStatus
getInstruction(MCInst
&Instr
, uint64_t &Size
,
39 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
40 raw_ostream
&CStream
) const override
;
44 static bool readInstruction16(ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
45 uint64_t &Size
, uint16_t &Insn
) {
46 // We want to read exactly 2 Bytes of data.
47 if (Bytes
.size() < 2) {
51 // Encoded as a little-endian 16-bit word in the stream.
52 Insn
= (Bytes
[0] << 0) | (Bytes
[1] << 8);
56 static bool readInstruction32(ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
57 uint64_t &Size
, uint32_t &Insn
) {
58 // We want to read exactly 4 Bytes of data.
59 if (Bytes
.size() < 4) {
63 // Encoded as a little-endian 32-bit word in the stream.
65 (Bytes
[0] << 0) | (Bytes
[1] << 8) | (Bytes
[2] << 16) | (Bytes
[3] << 24);
69 static unsigned getReg(const MCDisassembler
*D
, unsigned RC
, unsigned RegNo
) {
70 const MCRegisterInfo
*RegInfo
= D
->getContext().getRegisterInfo();
71 return *(RegInfo
->getRegClass(RC
).begin() + RegNo
);
74 static DecodeStatus
DecodeGRRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
76 const MCDisassembler
*Decoder
);
78 static DecodeStatus
DecodeRRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
80 const MCDisassembler
*Decoder
);
82 static DecodeStatus
DecodeBitpOperand(MCInst
&Inst
, unsigned Val
,
84 const MCDisassembler
*Decoder
);
86 static DecodeStatus
DecodeNegImmOperand(MCInst
&Inst
, unsigned Val
,
88 const MCDisassembler
*Decoder
);
90 static DecodeStatus
Decode2RInstruction(MCInst
&Inst
, unsigned Insn
,
92 const MCDisassembler
*Decoder
);
94 static DecodeStatus
Decode2RImmInstruction(MCInst
&Inst
, unsigned Insn
,
96 const MCDisassembler
*Decoder
);
98 static DecodeStatus
DecodeR2RInstruction(MCInst
&Inst
, unsigned Insn
,
100 const MCDisassembler
*Decoder
);
102 static DecodeStatus
Decode2RSrcDstInstruction(MCInst
&Inst
, unsigned Insn
,
104 const MCDisassembler
*Decoder
);
106 static DecodeStatus
DecodeRUSInstruction(MCInst
&Inst
, unsigned Insn
,
108 const MCDisassembler
*Decoder
);
110 static DecodeStatus
DecodeRUSBitpInstruction(MCInst
&Inst
, unsigned Insn
,
112 const MCDisassembler
*Decoder
);
115 DecodeRUSSrcDstBitpInstruction(MCInst
&Inst
, unsigned Insn
, uint64_t Address
,
116 const MCDisassembler
*Decoder
);
118 static DecodeStatus
DecodeL2RInstruction(MCInst
&Inst
, unsigned Insn
,
120 const MCDisassembler
*Decoder
);
122 static DecodeStatus
DecodeLR2RInstruction(MCInst
&Inst
, unsigned Insn
,
124 const MCDisassembler
*Decoder
);
126 static DecodeStatus
Decode3RInstruction(MCInst
&Inst
, unsigned Insn
,
128 const MCDisassembler
*Decoder
);
130 static DecodeStatus
Decode3RImmInstruction(MCInst
&Inst
, unsigned Insn
,
132 const MCDisassembler
*Decoder
);
134 static DecodeStatus
Decode2RUSInstruction(MCInst
&Inst
, unsigned Insn
,
136 const MCDisassembler
*Decoder
);
138 static DecodeStatus
Decode2RUSBitpInstruction(MCInst
&Inst
, unsigned Insn
,
140 const MCDisassembler
*Decoder
);
142 static DecodeStatus
DecodeL3RInstruction(MCInst
&Inst
, unsigned Insn
,
144 const MCDisassembler
*Decoder
);
146 static DecodeStatus
DecodeL3RSrcDstInstruction(MCInst
&Inst
, unsigned Insn
,
148 const MCDisassembler
*Decoder
);
150 static DecodeStatus
DecodeL2RUSInstruction(MCInst
&Inst
, unsigned Insn
,
152 const MCDisassembler
*Decoder
);
154 static DecodeStatus
DecodeL2RUSBitpInstruction(MCInst
&Inst
, unsigned Insn
,
156 const MCDisassembler
*Decoder
);
158 static DecodeStatus
DecodeL6RInstruction(MCInst
&Inst
, unsigned Insn
,
160 const MCDisassembler
*Decoder
);
162 static DecodeStatus
DecodeL5RInstruction(MCInst
&Inst
, unsigned Insn
,
164 const MCDisassembler
*Decoder
);
166 static DecodeStatus
DecodeL4RSrcDstInstruction(MCInst
&Inst
, unsigned Insn
,
168 const MCDisassembler
*Decoder
);
171 DecodeL4RSrcDstSrcDstInstruction(MCInst
&Inst
, unsigned Insn
, uint64_t Address
,
172 const MCDisassembler
*Decoder
);
174 #include "XCoreGenDisassemblerTables.inc"
176 static DecodeStatus
DecodeGRRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
178 const MCDisassembler
*Decoder
) {
180 return MCDisassembler::Fail
;
181 unsigned Reg
= getReg(Decoder
, XCore::GRRegsRegClassID
, RegNo
);
182 Inst
.addOperand(MCOperand::createReg(Reg
));
183 return MCDisassembler::Success
;
186 static DecodeStatus
DecodeRRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
188 const MCDisassembler
*Decoder
) {
190 return MCDisassembler::Fail
;
191 unsigned Reg
= getReg(Decoder
, XCore::RRegsRegClassID
, RegNo
);
192 Inst
.addOperand(MCOperand::createReg(Reg
));
193 return MCDisassembler::Success
;
196 static DecodeStatus
DecodeBitpOperand(MCInst
&Inst
, unsigned Val
,
198 const MCDisassembler
*Decoder
) {
200 return MCDisassembler::Fail
;
201 static const unsigned Values
[] = {
202 32 /*bpw*/, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32
204 Inst
.addOperand(MCOperand::createImm(Values
[Val
]));
205 return MCDisassembler::Success
;
208 static DecodeStatus
DecodeNegImmOperand(MCInst
&Inst
, unsigned Val
,
210 const MCDisassembler
*Decoder
) {
211 Inst
.addOperand(MCOperand::createImm(-(int64_t)Val
));
212 return MCDisassembler::Success
;
216 Decode2OpInstruction(unsigned Insn
, unsigned &Op1
, unsigned &Op2
) {
217 unsigned Combined
= fieldFromInstruction(Insn
, 6, 5);
219 return MCDisassembler::Fail
;
220 if (fieldFromInstruction(Insn
, 5, 1)) {
222 return MCDisassembler::Fail
;
226 unsigned Op1High
= Combined
% 3;
227 unsigned Op2High
= Combined
/ 3;
228 Op1
= (Op1High
<< 2) | fieldFromInstruction(Insn
, 2, 2);
229 Op2
= (Op2High
<< 2) | fieldFromInstruction(Insn
, 0, 2);
230 return MCDisassembler::Success
;
234 Decode3OpInstruction(unsigned Insn
, unsigned &Op1
, unsigned &Op2
,
236 unsigned Combined
= fieldFromInstruction(Insn
, 6, 5);
238 return MCDisassembler::Fail
;
240 unsigned Op1High
= Combined
% 3;
241 unsigned Op2High
= (Combined
/ 3) % 3;
242 unsigned Op3High
= Combined
/ 9;
243 Op1
= (Op1High
<< 2) | fieldFromInstruction(Insn
, 4, 2);
244 Op2
= (Op2High
<< 2) | fieldFromInstruction(Insn
, 2, 2);
245 Op3
= (Op3High
<< 2) | fieldFromInstruction(Insn
, 0, 2);
246 return MCDisassembler::Success
;
249 static DecodeStatus
Decode2OpInstructionFail(MCInst
&Inst
, unsigned Insn
,
251 const MCDisassembler
*Decoder
) {
252 // Try and decode as a 3R instruction.
253 unsigned Opcode
= fieldFromInstruction(Insn
, 11, 5);
256 Inst
.setOpcode(XCore::STW_2rus
);
257 return Decode2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
259 Inst
.setOpcode(XCore::LDW_2rus
);
260 return Decode2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
262 Inst
.setOpcode(XCore::ADD_3r
);
263 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
265 Inst
.setOpcode(XCore::SUB_3r
);
266 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
268 Inst
.setOpcode(XCore::SHL_3r
);
269 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
271 Inst
.setOpcode(XCore::SHR_3r
);
272 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
274 Inst
.setOpcode(XCore::EQ_3r
);
275 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
277 Inst
.setOpcode(XCore::AND_3r
);
278 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
280 Inst
.setOpcode(XCore::OR_3r
);
281 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
283 Inst
.setOpcode(XCore::LDW_3r
);
284 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
286 Inst
.setOpcode(XCore::LD16S_3r
);
287 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
289 Inst
.setOpcode(XCore::LD8U_3r
);
290 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
292 Inst
.setOpcode(XCore::ADD_2rus
);
293 return Decode2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
295 Inst
.setOpcode(XCore::SUB_2rus
);
296 return Decode2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
298 Inst
.setOpcode(XCore::SHL_2rus
);
299 return Decode2RUSBitpInstruction(Inst
, Insn
, Address
, Decoder
);
301 Inst
.setOpcode(XCore::SHR_2rus
);
302 return Decode2RUSBitpInstruction(Inst
, Insn
, Address
, Decoder
);
304 Inst
.setOpcode(XCore::EQ_2rus
);
305 return Decode2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
307 Inst
.setOpcode(XCore::TSETR_3r
);
308 return Decode3RImmInstruction(Inst
, Insn
, Address
, Decoder
);
310 Inst
.setOpcode(XCore::LSS_3r
);
311 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
313 Inst
.setOpcode(XCore::LSU_3r
);
314 return Decode3RInstruction(Inst
, Insn
, Address
, Decoder
);
316 return MCDisassembler::Fail
;
319 static DecodeStatus
Decode2RInstruction(MCInst
&Inst
, unsigned Insn
,
321 const MCDisassembler
*Decoder
) {
323 DecodeStatus S
= Decode2OpInstruction(Insn
, Op1
, Op2
);
324 if (S
!= MCDisassembler::Success
)
325 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
327 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
328 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
332 static DecodeStatus
Decode2RImmInstruction(MCInst
&Inst
, unsigned Insn
,
334 const MCDisassembler
*Decoder
) {
336 DecodeStatus S
= Decode2OpInstruction(Insn
, Op1
, Op2
);
337 if (S
!= MCDisassembler::Success
)
338 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
340 Inst
.addOperand(MCOperand::createImm(Op1
));
341 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
345 static DecodeStatus
DecodeR2RInstruction(MCInst
&Inst
, unsigned Insn
,
347 const MCDisassembler
*Decoder
) {
349 DecodeStatus S
= Decode2OpInstruction(Insn
, Op2
, Op1
);
350 if (S
!= MCDisassembler::Success
)
351 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
353 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
354 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
358 static DecodeStatus
Decode2RSrcDstInstruction(MCInst
&Inst
, unsigned Insn
,
360 const MCDisassembler
*Decoder
) {
362 DecodeStatus S
= Decode2OpInstruction(Insn
, Op1
, Op2
);
363 if (S
!= MCDisassembler::Success
)
364 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
366 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
367 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
368 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
372 static DecodeStatus
DecodeRUSInstruction(MCInst
&Inst
, unsigned Insn
,
374 const MCDisassembler
*Decoder
) {
376 DecodeStatus S
= Decode2OpInstruction(Insn
, Op1
, Op2
);
377 if (S
!= MCDisassembler::Success
)
378 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
380 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
381 Inst
.addOperand(MCOperand::createImm(Op2
));
385 static DecodeStatus
DecodeRUSBitpInstruction(MCInst
&Inst
, unsigned Insn
,
387 const MCDisassembler
*Decoder
) {
389 DecodeStatus S
= Decode2OpInstruction(Insn
, Op1
, Op2
);
390 if (S
!= MCDisassembler::Success
)
391 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
393 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
394 DecodeBitpOperand(Inst
, Op2
, Address
, Decoder
);
399 DecodeRUSSrcDstBitpInstruction(MCInst
&Inst
, unsigned Insn
, uint64_t Address
,
400 const MCDisassembler
*Decoder
) {
402 DecodeStatus S
= Decode2OpInstruction(Insn
, Op1
, Op2
);
403 if (S
!= MCDisassembler::Success
)
404 return Decode2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
406 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
407 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
408 DecodeBitpOperand(Inst
, Op2
, Address
, Decoder
);
412 static DecodeStatus
DecodeL2OpInstructionFail(MCInst
&Inst
, unsigned Insn
,
414 const MCDisassembler
*Decoder
) {
415 // Try and decode as a L3R / L2RUS instruction.
416 unsigned Opcode
= fieldFromInstruction(Insn
, 16, 4) |
417 fieldFromInstruction(Insn
, 27, 5) << 4;
420 Inst
.setOpcode(XCore::STW_l3r
);
421 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
423 Inst
.setOpcode(XCore::XOR_l3r
);
424 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
426 Inst
.setOpcode(XCore::ASHR_l3r
);
427 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
429 Inst
.setOpcode(XCore::LDAWF_l3r
);
430 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
432 Inst
.setOpcode(XCore::LDAWB_l3r
);
433 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
435 Inst
.setOpcode(XCore::LDA16F_l3r
);
436 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
438 Inst
.setOpcode(XCore::LDA16B_l3r
);
439 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
441 Inst
.setOpcode(XCore::MUL_l3r
);
442 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
444 Inst
.setOpcode(XCore::DIVS_l3r
);
445 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
447 Inst
.setOpcode(XCore::DIVU_l3r
);
448 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
450 Inst
.setOpcode(XCore::ST16_l3r
);
451 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
453 Inst
.setOpcode(XCore::ST8_l3r
);
454 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
456 Inst
.setOpcode(XCore::ASHR_l2rus
);
457 return DecodeL2RUSBitpInstruction(Inst
, Insn
, Address
, Decoder
);
459 Inst
.setOpcode(XCore::OUTPW_l2rus
);
460 return DecodeL2RUSBitpInstruction(Inst
, Insn
, Address
, Decoder
);
462 Inst
.setOpcode(XCore::INPW_l2rus
);
463 return DecodeL2RUSBitpInstruction(Inst
, Insn
, Address
, Decoder
);
465 Inst
.setOpcode(XCore::LDAWF_l2rus
);
466 return DecodeL2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
468 Inst
.setOpcode(XCore::LDAWB_l2rus
);
469 return DecodeL2RUSInstruction(Inst
, Insn
, Address
, Decoder
);
471 Inst
.setOpcode(XCore::CRC_l3r
);
472 return DecodeL3RSrcDstInstruction(Inst
, Insn
, Address
, Decoder
);
474 Inst
.setOpcode(XCore::REMS_l3r
);
475 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
477 Inst
.setOpcode(XCore::REMU_l3r
);
478 return DecodeL3RInstruction(Inst
, Insn
, Address
, Decoder
);
480 return MCDisassembler::Fail
;
483 static DecodeStatus
DecodeL2RInstruction(MCInst
&Inst
, unsigned Insn
,
485 const MCDisassembler
*Decoder
) {
487 DecodeStatus S
= Decode2OpInstruction(fieldFromInstruction(Insn
, 0, 16),
489 if (S
!= MCDisassembler::Success
)
490 return DecodeL2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
492 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
493 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
497 static DecodeStatus
DecodeLR2RInstruction(MCInst
&Inst
, unsigned Insn
,
499 const MCDisassembler
*Decoder
) {
501 DecodeStatus S
= Decode2OpInstruction(fieldFromInstruction(Insn
, 0, 16),
503 if (S
!= MCDisassembler::Success
)
504 return DecodeL2OpInstructionFail(Inst
, Insn
, Address
, Decoder
);
506 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
507 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
511 static DecodeStatus
Decode3RInstruction(MCInst
&Inst
, unsigned Insn
,
513 const MCDisassembler
*Decoder
) {
514 unsigned Op1
, Op2
, Op3
;
515 DecodeStatus S
= Decode3OpInstruction(Insn
, Op1
, Op2
, Op3
);
516 if (S
== MCDisassembler::Success
) {
517 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
518 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
519 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
524 static DecodeStatus
Decode3RImmInstruction(MCInst
&Inst
, unsigned Insn
,
526 const MCDisassembler
*Decoder
) {
527 unsigned Op1
, Op2
, Op3
;
528 DecodeStatus S
= Decode3OpInstruction(Insn
, Op1
, Op2
, Op3
);
529 if (S
== MCDisassembler::Success
) {
530 Inst
.addOperand(MCOperand::createImm(Op1
));
531 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
532 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
537 static DecodeStatus
Decode2RUSInstruction(MCInst
&Inst
, unsigned Insn
,
539 const MCDisassembler
*Decoder
) {
540 unsigned Op1
, Op2
, Op3
;
541 DecodeStatus S
= Decode3OpInstruction(Insn
, Op1
, Op2
, Op3
);
542 if (S
== MCDisassembler::Success
) {
543 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
544 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
545 Inst
.addOperand(MCOperand::createImm(Op3
));
550 static DecodeStatus
Decode2RUSBitpInstruction(MCInst
&Inst
, unsigned Insn
,
552 const MCDisassembler
*Decoder
) {
553 unsigned Op1
, Op2
, Op3
;
554 DecodeStatus S
= Decode3OpInstruction(Insn
, Op1
, Op2
, Op3
);
555 if (S
== MCDisassembler::Success
) {
556 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
557 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
558 DecodeBitpOperand(Inst
, Op3
, Address
, Decoder
);
563 static DecodeStatus
DecodeL3RInstruction(MCInst
&Inst
, unsigned Insn
,
565 const MCDisassembler
*Decoder
) {
566 unsigned Op1
, Op2
, Op3
;
568 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
569 if (S
== MCDisassembler::Success
) {
570 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
571 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
572 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
577 static DecodeStatus
DecodeL3RSrcDstInstruction(MCInst
&Inst
, unsigned Insn
,
579 const MCDisassembler
*Decoder
) {
580 unsigned Op1
, Op2
, Op3
;
582 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
583 if (S
== MCDisassembler::Success
) {
584 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
585 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
586 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
587 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
592 static DecodeStatus
DecodeL2RUSInstruction(MCInst
&Inst
, unsigned Insn
,
594 const MCDisassembler
*Decoder
) {
595 unsigned Op1
, Op2
, Op3
;
597 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
598 if (S
== MCDisassembler::Success
) {
599 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
600 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
601 Inst
.addOperand(MCOperand::createImm(Op3
));
606 static DecodeStatus
DecodeL2RUSBitpInstruction(MCInst
&Inst
, unsigned Insn
,
608 const MCDisassembler
*Decoder
) {
609 unsigned Op1
, Op2
, Op3
;
611 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
612 if (S
== MCDisassembler::Success
) {
613 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
614 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
615 DecodeBitpOperand(Inst
, Op3
, Address
, Decoder
);
620 static DecodeStatus
DecodeL6RInstruction(MCInst
&Inst
, unsigned Insn
,
622 const MCDisassembler
*Decoder
) {
623 unsigned Op1
, Op2
, Op3
, Op4
, Op5
, Op6
;
625 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
626 if (S
!= MCDisassembler::Success
)
628 S
= Decode3OpInstruction(fieldFromInstruction(Insn
, 16, 16), Op4
, Op5
, Op6
);
629 if (S
!= MCDisassembler::Success
)
631 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
632 DecodeGRRegsRegisterClass(Inst
, Op4
, Address
, Decoder
);
633 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
634 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
635 DecodeGRRegsRegisterClass(Inst
, Op5
, Address
, Decoder
);
636 DecodeGRRegsRegisterClass(Inst
, Op6
, Address
, Decoder
);
640 static DecodeStatus
DecodeL5RInstructionFail(MCInst
&Inst
, unsigned Insn
,
642 const MCDisassembler
*Decoder
) {
643 // Try and decode as a L6R instruction.
645 unsigned Opcode
= fieldFromInstruction(Insn
, 27, 5);
648 Inst
.setOpcode(XCore::LMUL_l6r
);
649 return DecodeL6RInstruction(Inst
, Insn
, Address
, Decoder
);
651 return MCDisassembler::Fail
;
654 static DecodeStatus
DecodeL5RInstruction(MCInst
&Inst
, unsigned Insn
,
656 const MCDisassembler
*Decoder
) {
657 unsigned Op1
, Op2
, Op3
, Op4
, Op5
;
659 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
660 if (S
!= MCDisassembler::Success
)
661 return DecodeL5RInstructionFail(Inst
, Insn
, Address
, Decoder
);
662 S
= Decode2OpInstruction(fieldFromInstruction(Insn
, 16, 16), Op4
, Op5
);
663 if (S
!= MCDisassembler::Success
)
664 return DecodeL5RInstructionFail(Inst
, Insn
, Address
, Decoder
);
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
);
674 static DecodeStatus
DecodeL4RSrcDstInstruction(MCInst
&Inst
, unsigned Insn
,
676 const MCDisassembler
*Decoder
) {
677 unsigned Op1
, Op2
, Op3
;
678 unsigned Op4
= fieldFromInstruction(Insn
, 16, 4);
680 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
681 if (S
== MCDisassembler::Success
) {
682 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
683 S
= DecodeGRRegsRegisterClass(Inst
, Op4
, Address
, Decoder
);
685 if (S
== MCDisassembler::Success
) {
686 DecodeGRRegsRegisterClass(Inst
, Op4
, Address
, Decoder
);
687 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
688 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
694 DecodeL4RSrcDstSrcDstInstruction(MCInst
&Inst
, unsigned Insn
, uint64_t Address
,
695 const MCDisassembler
*Decoder
) {
696 unsigned Op1
, Op2
, Op3
;
697 unsigned Op4
= fieldFromInstruction(Insn
, 16, 4);
699 Decode3OpInstruction(fieldFromInstruction(Insn
, 0, 16), Op1
, Op2
, Op3
);
700 if (S
== MCDisassembler::Success
) {
701 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
702 S
= DecodeGRRegsRegisterClass(Inst
, Op4
, Address
, Decoder
);
704 if (S
== MCDisassembler::Success
) {
705 DecodeGRRegsRegisterClass(Inst
, Op1
, Address
, Decoder
);
706 DecodeGRRegsRegisterClass(Inst
, Op4
, Address
, Decoder
);
707 DecodeGRRegsRegisterClass(Inst
, Op2
, Address
, Decoder
);
708 DecodeGRRegsRegisterClass(Inst
, Op3
, Address
, Decoder
);
713 MCDisassembler::DecodeStatus
714 XCoreDisassembler::getInstruction(MCInst
&instr
, uint64_t &Size
,
715 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
716 raw_ostream
&cStream
) const {
719 if (!readInstruction16(Bytes
, Address
, Size
, insn16
)) {
723 // Calling the auto-generated decoder function.
724 DecodeStatus Result
= decodeInstruction(DecoderTable16
, instr
, insn16
,
726 if (Result
!= Fail
) {
733 if (!readInstruction32(Bytes
, Address
, Size
, insn32
)) {
737 // Calling the auto-generated decoder function.
738 Result
= decodeInstruction(DecoderTable32
, instr
, insn32
, Address
, this, STI
);
739 if (Result
!= Fail
) {
747 static MCDisassembler
*createXCoreDisassembler(const Target
&T
,
748 const MCSubtargetInfo
&STI
,
750 return new XCoreDisassembler(STI
, Ctx
);
753 extern "C" LLVM_EXTERNAL_VISIBILITY
void LLVMInitializeXCoreDisassembler() {
754 // Register the disassembler.
755 TargetRegistry::RegisterMCDisassembler(getTheXCoreTarget(),
756 createXCoreDisassembler
);