1 //===- HexagonDisassembler.cpp - Disassembler for Hexagon ISA -------------===//
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 //===----------------------------------------------------------------------===//
9 #define DEBUG_TYPE "hexagon-disassembler"
11 #include "MCTargetDesc/HexagonBaseInfo.h"
12 #include "MCTargetDesc/HexagonMCChecker.h"
13 #include "MCTargetDesc/HexagonMCInstrInfo.h"
14 #include "MCTargetDesc/HexagonMCTargetDesc.h"
15 #include "TargetInfo/HexagonTargetInfo.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/MC/MCFixedLenDisassembler.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstrInfo.h"
24 #include "llvm/MC/MCRegisterInfo.h"
25 #include "llvm/MC/MCSubtargetInfo.h"
26 #include "llvm/Support/Endian.h"
27 #include "llvm/Support/MathExtras.h"
28 #include "llvm/Support/TargetRegistry.h"
29 #include "llvm/Support/raw_ostream.h"
36 using namespace Hexagon
;
38 using DecodeStatus
= MCDisassembler::DecodeStatus
;
42 /// Hexagon disassembler for all Hexagon platforms.
43 class HexagonDisassembler
: public MCDisassembler
{
45 std::unique_ptr
<MCInstrInfo
const> const MCII
;
46 std::unique_ptr
<MCInst
*> CurrentBundle
;
47 mutable MCInst
const *CurrentExtender
;
49 HexagonDisassembler(const MCSubtargetInfo
&STI
, MCContext
&Ctx
,
50 MCInstrInfo
const *MCII
)
51 : MCDisassembler(STI
, Ctx
), MCII(MCII
), CurrentBundle(new MCInst
*),
52 CurrentExtender(nullptr) {}
54 DecodeStatus
getSingleInstruction(MCInst
&Instr
, MCInst
&MCB
,
55 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
56 raw_ostream
&VStream
, raw_ostream
&CStream
,
57 bool &Complete
) const;
58 DecodeStatus
getInstruction(MCInst
&Instr
, uint64_t &Size
,
59 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
61 raw_ostream
&CStream
) const override
;
62 void remapInstruction(MCInst
&Instr
) const;
65 static uint64_t fullValue(HexagonDisassembler
const &Disassembler
, MCInst
&MI
,
67 MCInstrInfo MCII
= *Disassembler
.MCII
;
68 if (!Disassembler
.CurrentExtender
||
69 MI
.size() != HexagonMCInstrInfo::getExtendableOp(MCII
, MI
))
71 unsigned Alignment
= HexagonMCInstrInfo::getExtentAlignment(MCII
, MI
);
72 uint32_t Lower6
= static_cast<uint32_t>(Value
>> Alignment
) & 0x3f;
75 Disassembler
.CurrentExtender
->getOperand(0).getExpr()->evaluateAsAbsolute(
79 uint64_t Upper26
= static_cast<uint64_t>(Bits
);
80 uint64_t Operand
= Upper26
| Lower6
;
83 static HexagonDisassembler
const &disassembler(void const *Decoder
) {
84 return *static_cast<HexagonDisassembler
const *>(Decoder
);
87 static void signedDecoder(MCInst
&MI
, unsigned tmp
, const void *Decoder
) {
88 HexagonDisassembler
const &Disassembler
= disassembler(Decoder
);
89 int64_t FullValue
= fullValue(Disassembler
, MI
, SignExtend64
<T
>(tmp
));
90 int64_t Extended
= SignExtend64
<32>(FullValue
);
91 HexagonMCInstrInfo::addConstant(MI
, Extended
, Disassembler
.getContext());
95 // Forward declare these because the auto-generated code will reference them.
96 // Definitions are further down.
98 static DecodeStatus
DecodeIntRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
100 const void *Decoder
);
101 static DecodeStatus
DecodeGeneralSubRegsRegisterClass(MCInst
&Inst
,
104 const void *Decoder
);
105 static DecodeStatus
DecodeIntRegsLow8RegisterClass(MCInst
&Inst
, unsigned RegNo
,
107 const void *Decoder
);
108 static DecodeStatus
DecodeHvxVRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
110 const void *Decoder
);
111 static DecodeStatus
DecodeDoubleRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
113 const void *Decoder
);
115 DecodeGeneralDoubleLow8RegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
116 uint64_t Address
, const void *Decoder
);
117 static DecodeStatus
DecodeHvxWRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
119 const void *Decoder
);
120 static DecodeStatus
DecodeHvxVQRRegisterClass(MCInst
&Inst
,
123 const void *Decoder
);
124 static DecodeStatus
DecodePredRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
126 const void *Decoder
);
127 static DecodeStatus
DecodeHvxQRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
129 const void *Decoder
);
130 static DecodeStatus
DecodeCtrRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
132 const void *Decoder
);
133 static DecodeStatus
DecodeGuestRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
135 const void *Decoder
);
136 static DecodeStatus
DecodeModRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
138 const void *Decoder
);
139 static DecodeStatus
DecodeCtrRegs64RegisterClass(MCInst
&Inst
, unsigned RegNo
,
141 const void *Decoder
);
142 static DecodeStatus
DecodeGuestRegs64RegisterClass(MCInst
&Inst
, unsigned RegNo
,
144 const void *Decoder
);
146 static DecodeStatus
unsignedImmDecoder(MCInst
&MI
, unsigned tmp
,
147 uint64_t Address
, const void *Decoder
);
148 static DecodeStatus
s32_0ImmDecoder(MCInst
&MI
, unsigned tmp
,
149 uint64_t /*Address*/, const void *Decoder
);
150 static DecodeStatus
brtargetDecoder(MCInst
&MI
, unsigned tmp
, uint64_t Address
,
151 const void *Decoder
);
152 #include "HexagonDepDecoders.inc"
153 #include "HexagonGenDisassemblerTables.inc"
155 static MCDisassembler
*createHexagonDisassembler(const Target
&T
,
156 const MCSubtargetInfo
&STI
,
158 return new HexagonDisassembler(STI
, Ctx
, T
.createMCInstrInfo());
161 extern "C" void LLVMInitializeHexagonDisassembler() {
162 TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(),
163 createHexagonDisassembler
);
166 DecodeStatus
HexagonDisassembler::getInstruction(MCInst
&MI
, uint64_t &Size
,
167 ArrayRef
<uint8_t> Bytes
,
170 raw_ostream
&cs
) const {
171 DecodeStatus Result
= DecodeStatus::Success
;
172 bool Complete
= false;
175 *CurrentBundle
= &MI
;
176 MI
.setOpcode(Hexagon::BUNDLE
);
177 MI
.addOperand(MCOperand::createImm(0));
178 while (Result
== Success
&& !Complete
) {
179 if (Bytes
.size() < HEXAGON_INSTR_SIZE
)
180 return MCDisassembler::Fail
;
181 MCInst
*Inst
= new (getContext()) MCInst
;
182 Result
= getSingleInstruction(*Inst
, MI
, Bytes
, Address
, os
, cs
, Complete
);
183 MI
.addOperand(MCOperand::createInst(Inst
));
184 Size
+= HEXAGON_INSTR_SIZE
;
185 Bytes
= Bytes
.slice(HEXAGON_INSTR_SIZE
);
187 if (Result
== MCDisassembler::Fail
)
189 if (Size
> HEXAGON_MAX_PACKET_SIZE
)
190 return MCDisassembler::Fail
;
191 HexagonMCChecker
Checker(getContext(), *MCII
, STI
, MI
,
192 *getContext().getRegisterInfo(), false);
193 if (!Checker
.check())
194 return MCDisassembler::Fail
;
195 remapInstruction(MI
);
196 return MCDisassembler::Success
;
199 void HexagonDisassembler::remapInstruction(MCInst
&Instr
) const {
200 for (auto I
: HexagonMCInstrInfo::bundleInstructions(Instr
)) {
201 auto &MI
= const_cast<MCInst
&>(*I
.getInst());
202 switch (MI
.getOpcode()) {
203 case Hexagon::S2_allocframe
:
204 if (MI
.getOperand(0).getReg() == Hexagon::R29
) {
205 MI
.setOpcode(Hexagon::S6_allocframe_to_raw
);
206 MI
.erase(MI
.begin () + 1);
207 MI
.erase(MI
.begin ());
210 case Hexagon::L2_deallocframe
:
211 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
212 MI
.getOperand(1).getReg() == Hexagon::R30
) {
213 MI
.setOpcode(L6_deallocframe_map_to_raw
);
214 MI
.erase(MI
.begin () + 1);
215 MI
.erase(MI
.begin ());
218 case Hexagon::L4_return
:
219 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
220 MI
.getOperand(1).getReg() == Hexagon::R30
) {
221 MI
.setOpcode(L6_return_map_to_raw
);
222 MI
.erase(MI
.begin () + 1);
223 MI
.erase(MI
.begin ());
226 case Hexagon::L4_return_t
:
227 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
228 MI
.getOperand(2).getReg() == Hexagon::R30
) {
229 MI
.setOpcode(L4_return_map_to_raw_t
);
230 MI
.erase(MI
.begin () + 2);
231 MI
.erase(MI
.begin ());
234 case Hexagon::L4_return_f
:
235 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
236 MI
.getOperand(2).getReg() == Hexagon::R30
) {
237 MI
.setOpcode(L4_return_map_to_raw_f
);
238 MI
.erase(MI
.begin () + 2);
239 MI
.erase(MI
.begin ());
242 case Hexagon::L4_return_tnew_pt
:
243 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
244 MI
.getOperand(2).getReg() == Hexagon::R30
) {
245 MI
.setOpcode(L4_return_map_to_raw_tnew_pt
);
246 MI
.erase(MI
.begin () + 2);
247 MI
.erase(MI
.begin ());
250 case Hexagon::L4_return_fnew_pt
:
251 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
252 MI
.getOperand(2).getReg() == Hexagon::R30
) {
253 MI
.setOpcode(L4_return_map_to_raw_fnew_pt
);
254 MI
.erase(MI
.begin () + 2);
255 MI
.erase(MI
.begin ());
258 case Hexagon::L4_return_tnew_pnt
:
259 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
260 MI
.getOperand(2).getReg() == Hexagon::R30
) {
261 MI
.setOpcode(L4_return_map_to_raw_tnew_pnt
);
262 MI
.erase(MI
.begin () + 2);
263 MI
.erase(MI
.begin ());
266 case Hexagon::L4_return_fnew_pnt
:
267 if (MI
.getOperand(0).getReg() == Hexagon::D15
&&
268 MI
.getOperand(2).getReg() == Hexagon::R30
) {
269 MI
.setOpcode(L4_return_map_to_raw_fnew_pnt
);
270 MI
.erase(MI
.begin () + 2);
271 MI
.erase(MI
.begin ());
278 static void adjustDuplex(MCInst
&MI
, MCContext
&Context
) {
279 switch (MI
.getOpcode()) {
280 case Hexagon::SA1_setin1
:
281 MI
.insert(MI
.begin() + 1,
282 MCOperand::createExpr(MCConstantExpr::create(-1, Context
)));
284 case Hexagon::SA1_dec
:
285 MI
.insert(MI
.begin() + 2,
286 MCOperand::createExpr(MCConstantExpr::create(-1, Context
)));
293 DecodeStatus
HexagonDisassembler::getSingleInstruction(
294 MCInst
&MI
, MCInst
&MCB
, ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
295 raw_ostream
&os
, raw_ostream
&cs
, bool &Complete
) const {
296 assert(Bytes
.size() >= HEXAGON_INSTR_SIZE
);
298 uint32_t Instruction
= support::endian::read32le(Bytes
.data());
300 auto BundleSize
= HexagonMCInstrInfo::bundleSize(MCB
);
301 if ((Instruction
& HexagonII::INST_PARSE_MASK
) ==
302 HexagonII::INST_PARSE_LOOP_END
) {
304 HexagonMCInstrInfo::setInnerLoop(MCB
);
305 else if (BundleSize
== 1)
306 HexagonMCInstrInfo::setOuterLoop(MCB
);
308 return DecodeStatus::Fail
;
311 CurrentExtender
= HexagonMCInstrInfo::extenderForIndex(
312 MCB
, HexagonMCInstrInfo::bundleSize(MCB
));
314 DecodeStatus Result
= DecodeStatus::Fail
;
315 if ((Instruction
& HexagonII::INST_PARSE_MASK
) ==
316 HexagonII::INST_PARSE_DUPLEX
) {
317 unsigned duplexIClass
;
318 uint8_t const *DecodeLow
, *DecodeHigh
;
319 duplexIClass
= ((Instruction
>> 28) & 0xe) | ((Instruction
>> 13) & 0x1);
320 switch (duplexIClass
) {
322 return MCDisassembler::Fail
;
324 DecodeLow
= DecoderTableSUBINSN_L132
;
325 DecodeHigh
= DecoderTableSUBINSN_L132
;
328 DecodeLow
= DecoderTableSUBINSN_L232
;
329 DecodeHigh
= DecoderTableSUBINSN_L132
;
332 DecodeLow
= DecoderTableSUBINSN_L232
;
333 DecodeHigh
= DecoderTableSUBINSN_L232
;
336 DecodeLow
= DecoderTableSUBINSN_A32
;
337 DecodeHigh
= DecoderTableSUBINSN_A32
;
340 DecodeLow
= DecoderTableSUBINSN_L132
;
341 DecodeHigh
= DecoderTableSUBINSN_A32
;
344 DecodeLow
= DecoderTableSUBINSN_L232
;
345 DecodeHigh
= DecoderTableSUBINSN_A32
;
348 DecodeLow
= DecoderTableSUBINSN_S132
;
349 DecodeHigh
= DecoderTableSUBINSN_A32
;
352 DecodeLow
= DecoderTableSUBINSN_S232
;
353 DecodeHigh
= DecoderTableSUBINSN_A32
;
356 DecodeLow
= DecoderTableSUBINSN_S132
;
357 DecodeHigh
= DecoderTableSUBINSN_L132
;
360 DecodeLow
= DecoderTableSUBINSN_S132
;
361 DecodeHigh
= DecoderTableSUBINSN_L232
;
364 DecodeLow
= DecoderTableSUBINSN_S132
;
365 DecodeHigh
= DecoderTableSUBINSN_S132
;
368 DecodeLow
= DecoderTableSUBINSN_S232
;
369 DecodeHigh
= DecoderTableSUBINSN_S132
;
372 DecodeLow
= DecoderTableSUBINSN_S232
;
373 DecodeHigh
= DecoderTableSUBINSN_L132
;
376 DecodeLow
= DecoderTableSUBINSN_S232
;
377 DecodeHigh
= DecoderTableSUBINSN_L232
;
380 DecodeLow
= DecoderTableSUBINSN_S232
;
381 DecodeHigh
= DecoderTableSUBINSN_S232
;
384 MI
.setOpcode(Hexagon::DuplexIClass0
+ duplexIClass
);
385 MCInst
*MILow
= new (getContext()) MCInst
;
386 MCInst
*MIHigh
= new (getContext()) MCInst
;
387 auto TmpExtender
= CurrentExtender
;
389 nullptr; // constant extenders in duplex must always be in slot 1
390 Result
= decodeInstruction(DecodeLow
, *MILow
, Instruction
& 0x1fff, Address
,
392 CurrentExtender
= TmpExtender
;
393 if (Result
!= DecodeStatus::Success
)
394 return DecodeStatus::Fail
;
395 adjustDuplex(*MILow
, getContext());
396 Result
= decodeInstruction(
397 DecodeHigh
, *MIHigh
, (Instruction
>> 16) & 0x1fff, Address
, this, STI
);
398 if (Result
!= DecodeStatus::Success
)
399 return DecodeStatus::Fail
;
400 adjustDuplex(*MIHigh
, getContext());
401 MCOperand OPLow
= MCOperand::createInst(MILow
);
402 MCOperand OPHigh
= MCOperand::createInst(MIHigh
);
403 MI
.addOperand(OPLow
);
404 MI
.addOperand(OPHigh
);
407 if ((Instruction
& HexagonII::INST_PARSE_MASK
) ==
408 HexagonII::INST_PARSE_PACKET_END
)
411 if (CurrentExtender
!= nullptr)
412 Result
= decodeInstruction(DecoderTableMustExtend32
, MI
, Instruction
,
415 if (Result
!= MCDisassembler::Success
)
416 Result
= decodeInstruction(DecoderTable32
, MI
, Instruction
, Address
, this,
419 if (Result
!= MCDisassembler::Success
&&
420 STI
.getFeatureBits()[Hexagon::ExtensionHVX
])
421 Result
= decodeInstruction(DecoderTableEXT_mmvec32
, MI
, Instruction
,
426 switch (MI
.getOpcode()) {
427 case Hexagon::J4_cmpeqn1_f_jumpnv_nt
:
428 case Hexagon::J4_cmpeqn1_f_jumpnv_t
:
429 case Hexagon::J4_cmpeqn1_fp0_jump_nt
:
430 case Hexagon::J4_cmpeqn1_fp0_jump_t
:
431 case Hexagon::J4_cmpeqn1_fp1_jump_nt
:
432 case Hexagon::J4_cmpeqn1_fp1_jump_t
:
433 case Hexagon::J4_cmpeqn1_t_jumpnv_nt
:
434 case Hexagon::J4_cmpeqn1_t_jumpnv_t
:
435 case Hexagon::J4_cmpeqn1_tp0_jump_nt
:
436 case Hexagon::J4_cmpeqn1_tp0_jump_t
:
437 case Hexagon::J4_cmpeqn1_tp1_jump_nt
:
438 case Hexagon::J4_cmpeqn1_tp1_jump_t
:
439 case Hexagon::J4_cmpgtn1_f_jumpnv_nt
:
440 case Hexagon::J4_cmpgtn1_f_jumpnv_t
:
441 case Hexagon::J4_cmpgtn1_fp0_jump_nt
:
442 case Hexagon::J4_cmpgtn1_fp0_jump_t
:
443 case Hexagon::J4_cmpgtn1_fp1_jump_nt
:
444 case Hexagon::J4_cmpgtn1_fp1_jump_t
:
445 case Hexagon::J4_cmpgtn1_t_jumpnv_nt
:
446 case Hexagon::J4_cmpgtn1_t_jumpnv_t
:
447 case Hexagon::J4_cmpgtn1_tp0_jump_nt
:
448 case Hexagon::J4_cmpgtn1_tp0_jump_t
:
449 case Hexagon::J4_cmpgtn1_tp1_jump_nt
:
450 case Hexagon::J4_cmpgtn1_tp1_jump_t
:
451 MI
.insert(MI
.begin() + 1,
452 MCOperand::createExpr(MCConstantExpr::create(-1, getContext())));
458 if (HexagonMCInstrInfo::isNewValue(*MCII
, MI
)) {
459 unsigned OpIndex
= HexagonMCInstrInfo::getNewValueOp(*MCII
, MI
);
460 MCOperand
&MCO
= MI
.getOperand(OpIndex
);
461 assert(MCO
.isReg() && "New value consumers must be registers");
463 getContext().getRegisterInfo()->getEncodingValue(MCO
.getReg());
464 if ((Register
& 0x6) == 0)
465 // HexagonPRM 10.11 Bit 1-2 == 0 is reserved
466 return MCDisassembler::Fail
;
467 unsigned Lookback
= (Register
& 0x6) >> 1;
469 bool Vector
= HexagonMCInstrInfo::isVector(*MCII
, MI
);
470 bool PrevVector
= false;
471 auto Instructions
= HexagonMCInstrInfo::bundleInstructions(**CurrentBundle
);
472 auto i
= Instructions
.end() - 1;
473 for (auto n
= Instructions
.begin() - 1;; --i
, ++Offset
) {
475 // Couldn't find producer
476 return MCDisassembler::Fail
;
477 bool CurrentVector
= HexagonMCInstrInfo::isVector(*MCII
, *i
->getInst());
478 if (Vector
&& !CurrentVector
)
479 // Skip scalars when calculating distances for vectors
481 if (HexagonMCInstrInfo::isImmext(*i
->getInst()) && (Vector
== PrevVector
))
483 PrevVector
= CurrentVector
;
484 if (Offset
== Lookback
)
487 auto const &Inst
= *i
->getInst();
488 bool SubregBit
= (Register
& 0x1) != 0;
489 if (HexagonMCInstrInfo::hasNewValue2(*MCII
, Inst
)) {
490 // If subreg bit is set we're selecting the second produced newvalue
491 unsigned Producer
= SubregBit
?
492 HexagonMCInstrInfo::getNewValueOperand(*MCII
, Inst
).getReg() :
493 HexagonMCInstrInfo::getNewValueOperand2(*MCII
, Inst
).getReg();
494 assert(Producer
!= Hexagon::NoRegister
);
495 MCO
.setReg(Producer
);
496 } else if (HexagonMCInstrInfo::hasNewValue(*MCII
, Inst
)) {
498 HexagonMCInstrInfo::getNewValueOperand(*MCII
, Inst
).getReg();
499 if (Producer
>= Hexagon::W0
&& Producer
<= Hexagon::W15
)
500 Producer
= ((Producer
- Hexagon::W0
) << 1) + SubregBit
+ Hexagon::V0
;
502 // Hexagon PRM 10.11 New-value operands
503 // Nt[0] is reserved and should always be encoded as zero.
504 return MCDisassembler::Fail
;
505 assert(Producer
!= Hexagon::NoRegister
);
506 MCO
.setReg(Producer
);
508 return MCDisassembler::Fail
;
511 if (CurrentExtender
!= nullptr) {
512 MCInst
const &Inst
= HexagonMCInstrInfo::isDuplex(*MCII
, MI
)
513 ? *MI
.getOperand(1).getInst()
515 if (!HexagonMCInstrInfo::isExtendable(*MCII
, Inst
) &&
516 !HexagonMCInstrInfo::isExtended(*MCII
, Inst
))
517 return MCDisassembler::Fail
;
522 static DecodeStatus
DecodeRegisterClass(MCInst
&Inst
, unsigned RegNo
,
523 ArrayRef
<MCPhysReg
> Table
) {
524 if (RegNo
< Table
.size()) {
525 Inst
.addOperand(MCOperand::createReg(Table
[RegNo
]));
526 return MCDisassembler::Success
;
529 return MCDisassembler::Fail
;
532 static DecodeStatus
DecodeIntRegsLow8RegisterClass(MCInst
&Inst
, unsigned RegNo
,
534 const void *Decoder
) {
535 return DecodeIntRegsRegisterClass(Inst
, RegNo
, Address
, Decoder
);
538 static DecodeStatus
DecodeIntRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
540 const void *Decoder
) {
541 static const MCPhysReg IntRegDecoderTable
[] = {
542 Hexagon::R0
, Hexagon::R1
, Hexagon::R2
, Hexagon::R3
, Hexagon::R4
,
543 Hexagon::R5
, Hexagon::R6
, Hexagon::R7
, Hexagon::R8
, Hexagon::R9
,
544 Hexagon::R10
, Hexagon::R11
, Hexagon::R12
, Hexagon::R13
, Hexagon::R14
,
545 Hexagon::R15
, Hexagon::R16
, Hexagon::R17
, Hexagon::R18
, Hexagon::R19
,
546 Hexagon::R20
, Hexagon::R21
, Hexagon::R22
, Hexagon::R23
, Hexagon::R24
,
547 Hexagon::R25
, Hexagon::R26
, Hexagon::R27
, Hexagon::R28
, Hexagon::R29
,
548 Hexagon::R30
, Hexagon::R31
};
550 return DecodeRegisterClass(Inst
, RegNo
, IntRegDecoderTable
);
553 static DecodeStatus
DecodeGeneralSubRegsRegisterClass(MCInst
&Inst
,
556 const void *Decoder
) {
557 static const MCPhysReg GeneralSubRegDecoderTable
[] = {
558 Hexagon::R0
, Hexagon::R1
, Hexagon::R2
, Hexagon::R3
,
559 Hexagon::R4
, Hexagon::R5
, Hexagon::R6
, Hexagon::R7
,
560 Hexagon::R16
, Hexagon::R17
, Hexagon::R18
, Hexagon::R19
,
561 Hexagon::R20
, Hexagon::R21
, Hexagon::R22
, Hexagon::R23
,
564 return DecodeRegisterClass(Inst
, RegNo
, GeneralSubRegDecoderTable
);
567 static DecodeStatus
DecodeHvxVRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
568 uint64_t /*Address*/,
569 const void *Decoder
) {
570 static const MCPhysReg HvxVRDecoderTable
[] = {
571 Hexagon::V0
, Hexagon::V1
, Hexagon::V2
, Hexagon::V3
, Hexagon::V4
,
572 Hexagon::V5
, Hexagon::V6
, Hexagon::V7
, Hexagon::V8
, Hexagon::V9
,
573 Hexagon::V10
, Hexagon::V11
, Hexagon::V12
, Hexagon::V13
, Hexagon::V14
,
574 Hexagon::V15
, Hexagon::V16
, Hexagon::V17
, Hexagon::V18
, Hexagon::V19
,
575 Hexagon::V20
, Hexagon::V21
, Hexagon::V22
, Hexagon::V23
, Hexagon::V24
,
576 Hexagon::V25
, Hexagon::V26
, Hexagon::V27
, Hexagon::V28
, Hexagon::V29
,
577 Hexagon::V30
, Hexagon::V31
};
579 return DecodeRegisterClass(Inst
, RegNo
, HvxVRDecoderTable
);
582 static DecodeStatus
DecodeDoubleRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
583 uint64_t /*Address*/,
584 const void *Decoder
) {
585 static const MCPhysReg DoubleRegDecoderTable
[] = {
586 Hexagon::D0
, Hexagon::D1
, Hexagon::D2
, Hexagon::D3
,
587 Hexagon::D4
, Hexagon::D5
, Hexagon::D6
, Hexagon::D7
,
588 Hexagon::D8
, Hexagon::D9
, Hexagon::D10
, Hexagon::D11
,
589 Hexagon::D12
, Hexagon::D13
, Hexagon::D14
, Hexagon::D15
};
591 return DecodeRegisterClass(Inst
, RegNo
>> 1, DoubleRegDecoderTable
);
594 static DecodeStatus
DecodeGeneralDoubleLow8RegsRegisterClass(
595 MCInst
&Inst
, unsigned RegNo
, uint64_t /*Address*/, const void *Decoder
) {
596 static const MCPhysReg GeneralDoubleLow8RegDecoderTable
[] = {
597 Hexagon::D0
, Hexagon::D1
, Hexagon::D2
, Hexagon::D3
,
598 Hexagon::D8
, Hexagon::D9
, Hexagon::D10
, Hexagon::D11
};
600 return DecodeRegisterClass(Inst
, RegNo
, GeneralDoubleLow8RegDecoderTable
);
603 static DecodeStatus
DecodeHvxWRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
604 uint64_t /*Address*/,
605 const void *Decoder
) {
606 static const MCPhysReg HvxWRDecoderTable
[] = {
607 Hexagon::W0
, Hexagon::W1
, Hexagon::W2
, Hexagon::W3
,
608 Hexagon::W4
, Hexagon::W5
, Hexagon::W6
, Hexagon::W7
,
609 Hexagon::W8
, Hexagon::W9
, Hexagon::W10
, Hexagon::W11
,
610 Hexagon::W12
, Hexagon::W13
, Hexagon::W14
, Hexagon::W15
};
612 return (DecodeRegisterClass(Inst
, RegNo
>> 1, HvxWRDecoderTable
));
615 LLVM_ATTRIBUTE_UNUSED
// Suppress warning temporarily.
616 static DecodeStatus
DecodeHvxVQRRegisterClass(MCInst
&Inst
,
618 uint64_t /*Address*/,
619 const void *Decoder
) {
620 static const MCPhysReg HvxVQRDecoderTable
[] = {
621 Hexagon::VQ0
, Hexagon::VQ1
, Hexagon::VQ2
, Hexagon::VQ3
,
622 Hexagon::VQ4
, Hexagon::VQ5
, Hexagon::VQ6
, Hexagon::VQ7
};
624 return DecodeRegisterClass(Inst
, RegNo
>> 2, HvxVQRDecoderTable
);
627 static DecodeStatus
DecodePredRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
628 uint64_t /*Address*/,
629 const void *Decoder
) {
630 static const MCPhysReg PredRegDecoderTable
[] = {Hexagon::P0
, Hexagon::P1
,
631 Hexagon::P2
, Hexagon::P3
};
633 return DecodeRegisterClass(Inst
, RegNo
, PredRegDecoderTable
);
636 static DecodeStatus
DecodeHvxQRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
637 uint64_t /*Address*/,
638 const void *Decoder
) {
639 static const MCPhysReg HvxQRDecoderTable
[] = {Hexagon::Q0
, Hexagon::Q1
,
640 Hexagon::Q2
, Hexagon::Q3
};
642 return DecodeRegisterClass(Inst
, RegNo
, HvxQRDecoderTable
);
645 static DecodeStatus
DecodeCtrRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
646 uint64_t /*Address*/,
647 const void *Decoder
) {
648 using namespace Hexagon
;
650 static const MCPhysReg CtrlRegDecoderTable
[] = {
651 /* 0 */ SA0
, LC0
, SA1
, LC1
,
652 /* 4 */ P3_0
, C5
, M0
, M1
,
653 /* 8 */ USR
, PC
, UGP
, GP
,
654 /* 12 */ CS0
, CS1
, UPCYCLELO
, UPCYCLEHI
,
655 /* 16 */ FRAMELIMIT
, FRAMEKEY
, PKTCOUNTLO
, PKTCOUNTHI
,
658 /* 28 */ 0, 0, UTIMERLO
, UTIMERHI
661 if (RegNo
>= array_lengthof(CtrlRegDecoderTable
))
662 return MCDisassembler::Fail
;
664 static_assert(NoRegister
== 0, "Expecting NoRegister to be 0");
665 if (CtrlRegDecoderTable
[RegNo
] == NoRegister
)
666 return MCDisassembler::Fail
;
668 unsigned Register
= CtrlRegDecoderTable
[RegNo
];
669 Inst
.addOperand(MCOperand::createReg(Register
));
670 return MCDisassembler::Success
;
673 static DecodeStatus
DecodeCtrRegs64RegisterClass(MCInst
&Inst
, unsigned RegNo
,
674 uint64_t /*Address*/,
675 const void *Decoder
) {
676 using namespace Hexagon
;
678 static const MCPhysReg CtrlReg64DecoderTable
[] = {
679 /* 0 */ C1_0
, 0, C3_2
, 0,
680 /* 4 */ C5_4
, 0, C7_6
, 0,
681 /* 8 */ C9_8
, 0, C11_10
, 0,
682 /* 12 */ CS
, 0, UPCYCLE
, 0,
683 /* 16 */ C17_16
, 0, PKTCOUNT
, 0,
686 /* 28 */ 0, 0, UTIMER
, 0
689 if (RegNo
>= array_lengthof(CtrlReg64DecoderTable
))
690 return MCDisassembler::Fail
;
692 static_assert(NoRegister
== 0, "Expecting NoRegister to be 0");
693 if (CtrlReg64DecoderTable
[RegNo
] == NoRegister
)
694 return MCDisassembler::Fail
;
696 unsigned Register
= CtrlReg64DecoderTable
[RegNo
];
697 Inst
.addOperand(MCOperand::createReg(Register
));
698 return MCDisassembler::Success
;
701 static DecodeStatus
DecodeModRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
702 uint64_t /*Address*/,
703 const void *Decoder
) {
704 unsigned Register
= 0;
707 Register
= Hexagon::M0
;
710 Register
= Hexagon::M1
;
713 return MCDisassembler::Fail
;
715 Inst
.addOperand(MCOperand::createReg(Register
));
716 return MCDisassembler::Success
;
719 static DecodeStatus
unsignedImmDecoder(MCInst
&MI
, unsigned tmp
,
720 uint64_t /*Address*/,
721 const void *Decoder
) {
722 HexagonDisassembler
const &Disassembler
= disassembler(Decoder
);
723 int64_t FullValue
= fullValue(Disassembler
, MI
, tmp
);
724 assert(FullValue
>= 0 && "Negative in unsigned decoder");
725 HexagonMCInstrInfo::addConstant(MI
, FullValue
, Disassembler
.getContext());
726 return MCDisassembler::Success
;
729 static DecodeStatus
s32_0ImmDecoder(MCInst
&MI
, unsigned tmp
,
730 uint64_t /*Address*/, const void *Decoder
) {
731 HexagonDisassembler
const &Disassembler
= disassembler(Decoder
);
732 unsigned Bits
= HexagonMCInstrInfo::getExtentBits(*Disassembler
.MCII
, MI
);
733 tmp
= SignExtend64(tmp
, Bits
);
734 signedDecoder
<32>(MI
, tmp
, Decoder
);
735 return MCDisassembler::Success
;
738 // custom decoder for various jump/call immediates
739 static DecodeStatus
brtargetDecoder(MCInst
&MI
, unsigned tmp
, uint64_t Address
,
740 const void *Decoder
) {
741 HexagonDisassembler
const &Disassembler
= disassembler(Decoder
);
742 unsigned Bits
= HexagonMCInstrInfo::getExtentBits(*Disassembler
.MCII
, MI
);
743 // r13_2 is not extendable, so if there are no extent bits, it's r13_2
746 uint64_t FullValue
= fullValue(Disassembler
, MI
, SignExtend64(tmp
, Bits
));
747 uint32_t Extended
= FullValue
+ Address
;
748 if (!Disassembler
.tryAddingSymbolicOperand(MI
, Extended
, Address
, true, 0, 4))
749 HexagonMCInstrInfo::addConstant(MI
, Extended
, Disassembler
.getContext());
750 return MCDisassembler::Success
;
753 static DecodeStatus
DecodeGuestRegsRegisterClass(MCInst
&Inst
, unsigned RegNo
,
754 uint64_t /*Address*/,
755 const void *Decoder
) {
756 using namespace Hexagon
;
758 static const MCPhysReg GuestRegDecoderTable
[] = {
759 /* 0 */ GELR
, GSR
, GOSP
, G3
,
760 /* 4 */ G4
, G5
, G6
, G7
,
761 /* 8 */ G8
, G9
, G10
, G11
,
762 /* 12 */ G12
, G13
, G14
, G15
,
763 /* 16 */ GPMUCNT4
, GPMUCNT5
, GPMUCNT6
, GPMUCNT7
,
764 /* 20 */ G20
, G21
, G22
, G23
,
765 /* 24 */ GPCYCLELO
, GPCYCLEHI
, GPMUCNT0
, GPMUCNT1
,
766 /* 28 */ GPMUCNT2
, GPMUCNT3
, G30
, G31
769 if (RegNo
>= array_lengthof(GuestRegDecoderTable
))
770 return MCDisassembler::Fail
;
771 if (GuestRegDecoderTable
[RegNo
] == Hexagon::NoRegister
)
772 return MCDisassembler::Fail
;
774 unsigned Register
= GuestRegDecoderTable
[RegNo
];
775 Inst
.addOperand(MCOperand::createReg(Register
));
776 return MCDisassembler::Success
;
779 static DecodeStatus
DecodeGuestRegs64RegisterClass(MCInst
&Inst
, unsigned RegNo
,
780 uint64_t /*Address*/,
781 const void *Decoder
) {
782 using namespace Hexagon
;
784 static const MCPhysReg GuestReg64DecoderTable
[] = {
785 /* 0 */ G1_0
, 0, G3_2
, 0,
786 /* 4 */ G5_4
, 0, G7_6
, 0,
787 /* 8 */ G9_8
, 0, G11_10
, 0,
788 /* 12 */ G13_12
, 0, G15_14
, 0,
789 /* 16 */ G17_16
, 0, G19_18
, 0,
790 /* 20 */ G21_20
, 0, G23_22
, 0,
791 /* 24 */ G25_24
, 0, G27_26
, 0,
792 /* 28 */ G29_28
, 0, G31_30
, 0
795 if (RegNo
>= array_lengthof(GuestReg64DecoderTable
))
796 return MCDisassembler::Fail
;
797 if (GuestReg64DecoderTable
[RegNo
] == Hexagon::NoRegister
)
798 return MCDisassembler::Fail
;
800 unsigned Register
= GuestReg64DecoderTable
[RegNo
];
801 Inst
.addOperand(MCOperand::createReg(Register
));
802 return MCDisassembler::Success
;