1e4fc6ee7SEugene Zelenko //===- HexagonDisassembler.cpp - Disassembler for Hexagon ISA -------------===//
288ebb9e2SColin LeMahieu //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
688ebb9e2SColin LeMahieu //
788ebb9e2SColin LeMahieu //===----------------------------------------------------------------------===//
888ebb9e2SColin LeMahieu
988ebb9e2SColin LeMahieu #include "MCTargetDesc/HexagonBaseInfo.h"
107cd08927SColin LeMahieu #include "MCTargetDesc/HexagonMCChecker.h"
117cd08927SColin LeMahieu #include "MCTargetDesc/HexagonMCInstrInfo.h"
126bda14b3SChandler Carruth #include "MCTargetDesc/HexagonMCTargetDesc.h"
137ef17299SRichard Trieu #include "TargetInfo/HexagonTargetInfo.h"
1482085927SEugene Zelenko #include "llvm/ADT/ArrayRef.h"
1582085927SEugene Zelenko #include "llvm/ADT/STLExtras.h"
167cd08927SColin LeMahieu #include "llvm/MC/MCContext.h"
17c644488aSSheng #include "llvm/MC/MCDecoderOps.h"
186bda14b3SChandler Carruth #include "llvm/MC/MCDisassembler/MCDisassembler.h"
1988ebb9e2SColin LeMahieu #include "llvm/MC/MCExpr.h"
2088ebb9e2SColin LeMahieu #include "llvm/MC/MCInst.h"
217cd08927SColin LeMahieu #include "llvm/MC/MCInstrInfo.h"
2282085927SEugene Zelenko #include "llvm/MC/MCRegisterInfo.h"
2388ebb9e2SColin LeMahieu #include "llvm/MC/MCSubtargetInfo.h"
2489b57061SReid Kleckner #include "llvm/MC/TargetRegistry.h"
25e4fc6ee7SEugene Zelenko #include "llvm/Support/Endian.h"
2682085927SEugene Zelenko #include "llvm/Support/MathExtras.h"
276bda14b3SChandler Carruth #include "llvm/Support/raw_ostream.h"
2882085927SEugene Zelenko #include <cassert>
2982085927SEugene Zelenko #include <cstddef>
3082085927SEugene Zelenko #include <cstdint>
3182085927SEugene Zelenko #include <memory>
3288ebb9e2SColin LeMahieu
3371acce68SMindong Chen #define DEBUG_TYPE "hexagon-disassembler"
3471acce68SMindong Chen
3588ebb9e2SColin LeMahieu using namespace llvm;
3668d967d9SColin LeMahieu using namespace Hexagon;
3788ebb9e2SColin LeMahieu
38e4fc6ee7SEugene Zelenko using DecodeStatus = MCDisassembler::DecodeStatus;
3988ebb9e2SColin LeMahieu
4088ebb9e2SColin LeMahieu namespace {
4182085927SEugene Zelenko
425f8f34e4SAdrian Prantl /// Hexagon disassembler for all Hexagon platforms.
4388ebb9e2SColin LeMahieu class HexagonDisassembler : public MCDisassembler {
4488ebb9e2SColin LeMahieu public:
457cd08927SColin LeMahieu std::unique_ptr<MCInstrInfo const> const MCII;
4668d967d9SColin LeMahieu std::unique_ptr<MCInst *> CurrentBundle;
47a8ab1b75SKrzysztof Parzyszek mutable MCInst const *CurrentExtender;
4882085927SEugene Zelenko
HexagonDisassembler(const MCSubtargetInfo & STI,MCContext & Ctx,MCInstrInfo const * MCII)497cd08927SColin LeMahieu HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
507cd08927SColin LeMahieu MCInstrInfo const *MCII)
51a8ab1b75SKrzysztof Parzyszek : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *),
52a8ab1b75SKrzysztof Parzyszek CurrentExtender(nullptr) {}
5388ebb9e2SColin LeMahieu
5468d967d9SColin LeMahieu DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB,
5568d967d9SColin LeMahieu ArrayRef<uint8_t> Bytes, uint64_t Address,
566fdd6a7bSFangrui Song raw_ostream &CStream, bool &Complete) const;
574aa6bea7SRafael Espindola DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
587fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes, uint64_t Address,
594aa6bea7SRafael Espindola raw_ostream &CStream) const override;
60a8ab1b75SKrzysztof Parzyszek void remapInstruction(MCInst &Instr) const;
6188ebb9e2SColin LeMahieu };
6282085927SEugene Zelenko
fullValue(HexagonDisassembler const & Disassembler,MCInst & MI,int64_t Value)63a8ab1b75SKrzysztof Parzyszek static uint64_t fullValue(HexagonDisassembler const &Disassembler, MCInst &MI,
64a72fad98SKrzysztof Parzyszek int64_t Value) {
65a8ab1b75SKrzysztof Parzyszek MCInstrInfo MCII = *Disassembler.MCII;
66a8ab1b75SKrzysztof Parzyszek if (!Disassembler.CurrentExtender ||
67a8ab1b75SKrzysztof Parzyszek MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI))
68a72fad98SKrzysztof Parzyszek return Value;
69a72fad98SKrzysztof Parzyszek unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI);
70a72fad98SKrzysztof Parzyszek uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f;
71a72fad98SKrzysztof Parzyszek int64_t Bits;
72a8ab1b75SKrzysztof Parzyszek bool Success =
73a8ab1b75SKrzysztof Parzyszek Disassembler.CurrentExtender->getOperand(0).getExpr()->evaluateAsAbsolute(
74a8ab1b75SKrzysztof Parzyszek Bits);
75a8ab1b75SKrzysztof Parzyszek assert(Success);
76a8ab1b75SKrzysztof Parzyszek (void)Success;
77a8ab1b75SKrzysztof Parzyszek uint64_t Upper26 = static_cast<uint64_t>(Bits);
78a8ab1b75SKrzysztof Parzyszek uint64_t Operand = Upper26 | Lower6;
79a72fad98SKrzysztof Parzyszek return Operand;
80a72fad98SKrzysztof Parzyszek }
disassembler(const MCDisassembler * Decoder)814ae9745aSMaksim Panchenko static HexagonDisassembler const &disassembler(const MCDisassembler *Decoder) {
82a72fad98SKrzysztof Parzyszek return *static_cast<HexagonDisassembler const *>(Decoder);
83a72fad98SKrzysztof Parzyszek }
84a72fad98SKrzysztof Parzyszek template <size_t T>
signedDecoder(MCInst & MI,unsigned tmp,const MCDisassembler * Decoder)854ae9745aSMaksim Panchenko static void signedDecoder(MCInst &MI, unsigned tmp,
864ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
87a72fad98SKrzysztof Parzyszek HexagonDisassembler const &Disassembler = disassembler(Decoder);
88a8ab1b75SKrzysztof Parzyszek int64_t FullValue = fullValue(Disassembler, MI, SignExtend64<T>(tmp));
89a72fad98SKrzysztof Parzyszek int64_t Extended = SignExtend64<32>(FullValue);
90a72fad98SKrzysztof Parzyszek HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext());
91a72fad98SKrzysztof Parzyszek }
92a8ab1b75SKrzysztof Parzyszek }
9388ebb9e2SColin LeMahieu
947cd08927SColin LeMahieu // Forward declare these because the auto-generated code will reference them.
957cd08927SColin LeMahieu // Definitions are further down.
967cd08927SColin LeMahieu
977cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
98be8c453dSColin LeMahieu uint64_t Address,
994ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1004ae9745aSMaksim Panchenko static DecodeStatus
1014ae9745aSMaksim Panchenko DecodeGeneralSubRegsRegisterClass(MCInst &Inst, unsigned RegNo,
102a72fad98SKrzysztof Parzyszek uint64_t Address,
1034ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1044ae9745aSMaksim Panchenko static DecodeStatus
1054ae9745aSMaksim Panchenko DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
1064ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
10755772976SKrzysztof Parzyszek static DecodeStatus DecodeHvxVRRegisterClass(MCInst &Inst, unsigned RegNo,
1087c958713SColin LeMahieu uint64_t Address,
1094ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1104ae9745aSMaksim Panchenko static DecodeStatus
1114ae9745aSMaksim Panchenko DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
1124ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
113a72fad98SKrzysztof Parzyszek static DecodeStatus
114a72fad98SKrzysztof Parzyszek DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo,
1154ae9745aSMaksim Panchenko uint64_t Address,
1164ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
11755772976SKrzysztof Parzyszek static DecodeStatus DecodeHvxWRRegisterClass(MCInst &Inst, unsigned RegNo,
1187c958713SColin LeMahieu uint64_t Address,
1194ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1204ae9745aSMaksim Panchenko static DecodeStatus DecodeHvxVQRRegisterClass(MCInst &Inst, unsigned RegNo,
12113a9cf28SKrzysztof Parzyszek uint64_t Address,
1224ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1237cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
1247cd08927SColin LeMahieu uint64_t Address,
1254ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
12655772976SKrzysztof Parzyszek static DecodeStatus DecodeHvxQRRegisterClass(MCInst &Inst, unsigned RegNo,
1277c958713SColin LeMahieu uint64_t Address,
1284ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
129f3db884eSColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
130be8c453dSColin LeMahieu uint64_t Address,
1314ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
13222a21d4cSKrzysztof Parzyszek static DecodeStatus DecodeGuestRegsRegisterClass(MCInst &Inst, unsigned RegNo,
13322a21d4cSKrzysztof Parzyszek uint64_t Address,
1344ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
135743e263eSBrian Cain static DecodeStatus DecodeSysRegsRegisterClass(MCInst &Inst, unsigned RegNo,
136743e263eSBrian Cain uint64_t Address,
1374ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1387cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
1397cd08927SColin LeMahieu uint64_t Address,
1404ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
141404d5b24SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
142be8c453dSColin LeMahieu uint64_t Address,
1434ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1444ae9745aSMaksim Panchenko static DecodeStatus
1454ae9745aSMaksim Panchenko DecodeGuestRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
1464ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
147743e263eSBrian Cain static DecodeStatus DecodeSysRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
148743e263eSBrian Cain uint64_t Address,
1494ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1507cd08927SColin LeMahieu
1517cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
1524ae9745aSMaksim Panchenko uint64_t Address,
1534ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
154a72fad98SKrzysztof Parzyszek static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp,
1554ae9745aSMaksim Panchenko uint64_t /*Address*/,
1564ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1577cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
1584ae9745aSMaksim Panchenko const MCDisassembler *Decoder);
1598f6182f7SRichard Trieu #include "HexagonDepDecoders.inc"
16088ebb9e2SColin LeMahieu #include "HexagonGenDisassemblerTables.inc"
16188ebb9e2SColin LeMahieu
createHexagonDisassembler(const Target & T,const MCSubtargetInfo & STI,MCContext & Ctx)1627cd08927SColin LeMahieu static MCDisassembler *createHexagonDisassembler(const Target &T,
1637cd08927SColin LeMahieu const MCSubtargetInfo &STI,
16488ebb9e2SColin LeMahieu MCContext &Ctx) {
1657cd08927SColin LeMahieu return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo());
16688ebb9e2SColin LeMahieu }
16788ebb9e2SColin LeMahieu
LLVMInitializeHexagonDisassembler()1680dbcb363STom Stellard extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeHexagonDisassembler() {
169f42454b9SMehdi Amini TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(),
17088ebb9e2SColin LeMahieu createHexagonDisassembler);
17188ebb9e2SColin LeMahieu }
17288ebb9e2SColin LeMahieu
getInstruction(MCInst & MI,uint64_t & Size,ArrayRef<uint8_t> Bytes,uint64_t Address,raw_ostream & cs) const17388ebb9e2SColin LeMahieu DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
1747fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes,
17588ebb9e2SColin LeMahieu uint64_t Address,
17688ebb9e2SColin LeMahieu raw_ostream &cs) const {
17768d967d9SColin LeMahieu DecodeStatus Result = DecodeStatus::Success;
17868d967d9SColin LeMahieu bool Complete = false;
17968d967d9SColin LeMahieu Size = 0;
1804aa6bea7SRafael Espindola
18168d967d9SColin LeMahieu *CurrentBundle = &MI;
182a8ab1b75SKrzysztof Parzyszek MI.setOpcode(Hexagon::BUNDLE);
183a8ab1b75SKrzysztof Parzyszek MI.addOperand(MCOperand::createImm(0));
18482085927SEugene Zelenko while (Result == Success && !Complete) {
18568d967d9SColin LeMahieu if (Bytes.size() < HEXAGON_INSTR_SIZE)
18668d967d9SColin LeMahieu return MCDisassembler::Fail;
187509f5c4eShgreving MCInst *Inst = getContext().createMCInst();
1886fdd6a7bSFangrui Song Result = getSingleInstruction(*Inst, MI, Bytes, Address, cs, Complete);
18968d967d9SColin LeMahieu MI.addOperand(MCOperand::createInst(Inst));
19068d967d9SColin LeMahieu Size += HEXAGON_INSTR_SIZE;
19168d967d9SColin LeMahieu Bytes = Bytes.slice(HEXAGON_INSTR_SIZE);
19268d967d9SColin LeMahieu }
1937cd08927SColin LeMahieu if (Result == MCDisassembler::Fail)
19468d967d9SColin LeMahieu return Result;
195a72fad98SKrzysztof Parzyszek if (Size > HEXAGON_MAX_PACKET_SIZE)
196a72fad98SKrzysztof Parzyszek return MCDisassembler::Fail;
197305bf5b2SKrzysztof Parzyszek
198305bf5b2SKrzysztof Parzyszek const auto ArchSTI = Hexagon_MC::getArchSubtarget(&STI);
199305bf5b2SKrzysztof Parzyszek const auto STI_ = (ArchSTI != nullptr) ? *ArchSTI : STI;
200305bf5b2SKrzysztof Parzyszek HexagonMCChecker Checker(getContext(), *MCII, STI_, MI,
201e12d1e70SKrzysztof Parzyszek *getContext().getRegisterInfo(), false);
2027cd08927SColin LeMahieu if (!Checker.check())
2037cd08927SColin LeMahieu return MCDisassembler::Fail;
204a8ab1b75SKrzysztof Parzyszek remapInstruction(MI);
2057cd08927SColin LeMahieu return MCDisassembler::Success;
2067cd08927SColin LeMahieu }
2077cd08927SColin LeMahieu
remapInstruction(MCInst & Instr) const208a8ab1b75SKrzysztof Parzyszek void HexagonDisassembler::remapInstruction(MCInst &Instr) const {
209a8ab1b75SKrzysztof Parzyszek for (auto I: HexagonMCInstrInfo::bundleInstructions(Instr)) {
210a8ab1b75SKrzysztof Parzyszek auto &MI = const_cast<MCInst &>(*I.getInst());
211a8ab1b75SKrzysztof Parzyszek switch (MI.getOpcode()) {
212a8ab1b75SKrzysztof Parzyszek case Hexagon::S2_allocframe:
213a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::R29) {
214a8ab1b75SKrzysztof Parzyszek MI.setOpcode(Hexagon::S6_allocframe_to_raw);
215a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 1);
216a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
217a8ab1b75SKrzysztof Parzyszek }
218a8ab1b75SKrzysztof Parzyszek break;
219a8ab1b75SKrzysztof Parzyszek case Hexagon::L2_deallocframe:
220a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
221a8ab1b75SKrzysztof Parzyszek MI.getOperand(1).getReg() == Hexagon::R30) {
222a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L6_deallocframe_map_to_raw);
223a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 1);
224a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
225a8ab1b75SKrzysztof Parzyszek }
226a8ab1b75SKrzysztof Parzyszek break;
227a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return:
228a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
229a8ab1b75SKrzysztof Parzyszek MI.getOperand(1).getReg() == Hexagon::R30) {
230a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L6_return_map_to_raw);
231a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 1);
232a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
233a8ab1b75SKrzysztof Parzyszek }
234a8ab1b75SKrzysztof Parzyszek break;
235a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return_t:
236a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
237a8ab1b75SKrzysztof Parzyszek MI.getOperand(2).getReg() == Hexagon::R30) {
238a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L4_return_map_to_raw_t);
239a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 2);
240a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
241a8ab1b75SKrzysztof Parzyszek }
242a8ab1b75SKrzysztof Parzyszek break;
243a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return_f:
244a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
245a8ab1b75SKrzysztof Parzyszek MI.getOperand(2).getReg() == Hexagon::R30) {
246a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L4_return_map_to_raw_f);
247a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 2);
248a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
249a8ab1b75SKrzysztof Parzyszek }
250a8ab1b75SKrzysztof Parzyszek break;
251a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return_tnew_pt:
252a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
253a8ab1b75SKrzysztof Parzyszek MI.getOperand(2).getReg() == Hexagon::R30) {
254a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L4_return_map_to_raw_tnew_pt);
255a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 2);
256a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
257a8ab1b75SKrzysztof Parzyszek }
258a8ab1b75SKrzysztof Parzyszek break;
259a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return_fnew_pt:
260a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
261a8ab1b75SKrzysztof Parzyszek MI.getOperand(2).getReg() == Hexagon::R30) {
262a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L4_return_map_to_raw_fnew_pt);
263a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 2);
264a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
265a8ab1b75SKrzysztof Parzyszek }
266a8ab1b75SKrzysztof Parzyszek break;
267a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return_tnew_pnt:
268a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
269a8ab1b75SKrzysztof Parzyszek MI.getOperand(2).getReg() == Hexagon::R30) {
270a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L4_return_map_to_raw_tnew_pnt);
271a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 2);
272a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
273a8ab1b75SKrzysztof Parzyszek }
274a8ab1b75SKrzysztof Parzyszek break;
275a8ab1b75SKrzysztof Parzyszek case Hexagon::L4_return_fnew_pnt:
276a8ab1b75SKrzysztof Parzyszek if (MI.getOperand(0).getReg() == Hexagon::D15 &&
277a8ab1b75SKrzysztof Parzyszek MI.getOperand(2).getReg() == Hexagon::R30) {
278a8ab1b75SKrzysztof Parzyszek MI.setOpcode(L4_return_map_to_raw_fnew_pnt);
279a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin () + 2);
280a8ab1b75SKrzysztof Parzyszek MI.erase(MI.begin ());
281a8ab1b75SKrzysztof Parzyszek }
282a8ab1b75SKrzysztof Parzyszek break;
283a8ab1b75SKrzysztof Parzyszek }
284a8ab1b75SKrzysztof Parzyszek }
285a8ab1b75SKrzysztof Parzyszek }
286a8ab1b75SKrzysztof Parzyszek
adjustDuplex(MCInst & MI,MCContext & Context)287e4fc6ee7SEugene Zelenko static void adjustDuplex(MCInst &MI, MCContext &Context) {
288a72fad98SKrzysztof Parzyszek switch (MI.getOpcode()) {
289a72fad98SKrzysztof Parzyszek case Hexagon::SA1_setin1:
290a72fad98SKrzysztof Parzyszek MI.insert(MI.begin() + 1,
291a72fad98SKrzysztof Parzyszek MCOperand::createExpr(MCConstantExpr::create(-1, Context)));
292a72fad98SKrzysztof Parzyszek break;
293a72fad98SKrzysztof Parzyszek case Hexagon::SA1_dec:
294a72fad98SKrzysztof Parzyszek MI.insert(MI.begin() + 2,
295a72fad98SKrzysztof Parzyszek MCOperand::createExpr(MCConstantExpr::create(-1, Context)));
296a72fad98SKrzysztof Parzyszek break;
297a72fad98SKrzysztof Parzyszek default:
298a72fad98SKrzysztof Parzyszek break;
2997cd08927SColin LeMahieu }
300a72fad98SKrzysztof Parzyszek }
30168d967d9SColin LeMahieu
getSingleInstruction(MCInst & MI,MCInst & MCB,ArrayRef<uint8_t> Bytes,uint64_t Address,raw_ostream & cs,bool & Complete) const3026fdd6a7bSFangrui Song DecodeStatus HexagonDisassembler::getSingleInstruction(MCInst &MI, MCInst &MCB,
3036fdd6a7bSFangrui Song ArrayRef<uint8_t> Bytes,
3046fdd6a7bSFangrui Song uint64_t Address,
3056fdd6a7bSFangrui Song raw_ostream &cs,
3066fdd6a7bSFangrui Song bool &Complete) const {
30768d967d9SColin LeMahieu assert(Bytes.size() >= HEXAGON_INSTR_SIZE);
30868d967d9SColin LeMahieu
309a72fad98SKrzysztof Parzyszek uint32_t Instruction = support::endian::read32le(Bytes.data());
31088ebb9e2SColin LeMahieu
31168d967d9SColin LeMahieu auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB);
31268d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) ==
31368d967d9SColin LeMahieu HexagonII::INST_PARSE_LOOP_END) {
31468d967d9SColin LeMahieu if (BundleSize == 0)
31568d967d9SColin LeMahieu HexagonMCInstrInfo::setInnerLoop(MCB);
31668d967d9SColin LeMahieu else if (BundleSize == 1)
31768d967d9SColin LeMahieu HexagonMCInstrInfo::setOuterLoop(MCB);
31868d967d9SColin LeMahieu else
31968d967d9SColin LeMahieu return DecodeStatus::Fail;
32068d967d9SColin LeMahieu }
32168d967d9SColin LeMahieu
322a8ab1b75SKrzysztof Parzyszek CurrentExtender = HexagonMCInstrInfo::extenderForIndex(
323a72fad98SKrzysztof Parzyszek MCB, HexagonMCInstrInfo::bundleSize(MCB));
324a72fad98SKrzysztof Parzyszek
325a72fad98SKrzysztof Parzyszek DecodeStatus Result = DecodeStatus::Fail;
32668d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) ==
327be8c453dSColin LeMahieu HexagonII::INST_PARSE_DUPLEX) {
328a72fad98SKrzysztof Parzyszek unsigned duplexIClass;
329a72fad98SKrzysztof Parzyszek uint8_t const *DecodeLow, *DecodeHigh;
330be8c453dSColin LeMahieu duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1);
331be8c453dSColin LeMahieu switch (duplexIClass) {
332be8c453dSColin LeMahieu default:
333be8c453dSColin LeMahieu return MCDisassembler::Fail;
334be8c453dSColin LeMahieu case 0:
335a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L132;
336a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132;
337be8c453dSColin LeMahieu break;
338be8c453dSColin LeMahieu case 1:
339a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L232;
340a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132;
341be8c453dSColin LeMahieu break;
342be8c453dSColin LeMahieu case 2:
343a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L232;
344a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L232;
345be8c453dSColin LeMahieu break;
346be8c453dSColin LeMahieu case 3:
347a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_A32;
348a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32;
349be8c453dSColin LeMahieu break;
350be8c453dSColin LeMahieu case 4:
351a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L132;
352a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32;
353be8c453dSColin LeMahieu break;
354be8c453dSColin LeMahieu case 5:
355a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L232;
356a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32;
357be8c453dSColin LeMahieu break;
358be8c453dSColin LeMahieu case 6:
359a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132;
360a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32;
361be8c453dSColin LeMahieu break;
362be8c453dSColin LeMahieu case 7:
363a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232;
364a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32;
365be8c453dSColin LeMahieu break;
366be8c453dSColin LeMahieu case 8:
367a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132;
368a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132;
369be8c453dSColin LeMahieu break;
370be8c453dSColin LeMahieu case 9:
371a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132;
372a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L232;
373be8c453dSColin LeMahieu break;
374be8c453dSColin LeMahieu case 10:
375a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132;
376a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_S132;
377be8c453dSColin LeMahieu break;
378be8c453dSColin LeMahieu case 11:
379a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232;
380a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_S132;
381be8c453dSColin LeMahieu break;
382be8c453dSColin LeMahieu case 12:
383a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232;
384a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132;
385be8c453dSColin LeMahieu break;
386be8c453dSColin LeMahieu case 13:
387a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232;
388a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L232;
389be8c453dSColin LeMahieu break;
390be8c453dSColin LeMahieu case 14:
391a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232;
392a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_S232;
393be8c453dSColin LeMahieu break;
394be8c453dSColin LeMahieu }
395a72fad98SKrzysztof Parzyszek MI.setOpcode(Hexagon::DuplexIClass0 + duplexIClass);
396509f5c4eShgreving MCInst *MILow = getContext().createMCInst();
397509f5c4eShgreving MCInst *MIHigh = getContext().createMCInst();
398a8ab1b75SKrzysztof Parzyszek auto TmpExtender = CurrentExtender;
399a8ab1b75SKrzysztof Parzyszek CurrentExtender =
400a8ab1b75SKrzysztof Parzyszek nullptr; // constant extenders in duplex must always be in slot 1
401a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecodeLow, *MILow, Instruction & 0x1fff, Address,
402a72fad98SKrzysztof Parzyszek this, STI);
403a8ab1b75SKrzysztof Parzyszek CurrentExtender = TmpExtender;
404a72fad98SKrzysztof Parzyszek if (Result != DecodeStatus::Success)
405a72fad98SKrzysztof Parzyszek return DecodeStatus::Fail;
406a72fad98SKrzysztof Parzyszek adjustDuplex(*MILow, getContext());
407a72fad98SKrzysztof Parzyszek Result = decodeInstruction(
408a72fad98SKrzysztof Parzyszek DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff, Address, this, STI);
409a72fad98SKrzysztof Parzyszek if (Result != DecodeStatus::Success)
410a72fad98SKrzysztof Parzyszek return DecodeStatus::Fail;
411a72fad98SKrzysztof Parzyszek adjustDuplex(*MIHigh, getContext());
412be8c453dSColin LeMahieu MCOperand OPLow = MCOperand::createInst(MILow);
413be8c453dSColin LeMahieu MCOperand OPHigh = MCOperand::createInst(MIHigh);
414be8c453dSColin LeMahieu MI.addOperand(OPLow);
415be8c453dSColin LeMahieu MI.addOperand(OPHigh);
416be8c453dSColin LeMahieu Complete = true;
417be8c453dSColin LeMahieu } else {
418be8c453dSColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) ==
41968d967d9SColin LeMahieu HexagonII::INST_PARSE_PACKET_END)
42068d967d9SColin LeMahieu Complete = true;
4217cd08927SColin LeMahieu
422a8ab1b75SKrzysztof Parzyszek if (CurrentExtender != nullptr)
423a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecoderTableMustExtend32, MI, Instruction,
424a72fad98SKrzysztof Parzyszek Address, this, STI);
425a72fad98SKrzysztof Parzyszek
426a72fad98SKrzysztof Parzyszek if (Result != MCDisassembler::Success)
427a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecoderTable32, MI, Instruction, Address, this,
428a72fad98SKrzysztof Parzyszek STI);
429a72fad98SKrzysztof Parzyszek
430a72fad98SKrzysztof Parzyszek if (Result != MCDisassembler::Success &&
431a72fad98SKrzysztof Parzyszek STI.getFeatureBits()[Hexagon::ExtensionHVX])
432a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecoderTableEXT_mmvec32, MI, Instruction,
433a72fad98SKrzysztof Parzyszek Address, this, STI);
434a72fad98SKrzysztof Parzyszek
435be8c453dSColin LeMahieu }
43668d967d9SColin LeMahieu
43781707549SColin LeMahieu switch (MI.getOpcode()) {
43881707549SColin LeMahieu case Hexagon::J4_cmpeqn1_f_jumpnv_nt:
43981707549SColin LeMahieu case Hexagon::J4_cmpeqn1_f_jumpnv_t:
44081707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp0_jump_nt:
44181707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp0_jump_t:
44281707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp1_jump_nt:
44381707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp1_jump_t:
44481707549SColin LeMahieu case Hexagon::J4_cmpeqn1_t_jumpnv_nt:
44581707549SColin LeMahieu case Hexagon::J4_cmpeqn1_t_jumpnv_t:
44681707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp0_jump_nt:
44781707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp0_jump_t:
44881707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp1_jump_nt:
44981707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp1_jump_t:
45081707549SColin LeMahieu case Hexagon::J4_cmpgtn1_f_jumpnv_nt:
45181707549SColin LeMahieu case Hexagon::J4_cmpgtn1_f_jumpnv_t:
45281707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp0_jump_nt:
45381707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp0_jump_t:
45481707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp1_jump_nt:
45581707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp1_jump_t:
45681707549SColin LeMahieu case Hexagon::J4_cmpgtn1_t_jumpnv_nt:
45781707549SColin LeMahieu case Hexagon::J4_cmpgtn1_t_jumpnv_t:
45881707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp0_jump_nt:
45981707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp0_jump_t:
46081707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp1_jump_nt:
46181707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp1_jump_t:
462a72fad98SKrzysztof Parzyszek MI.insert(MI.begin() + 1,
463a72fad98SKrzysztof Parzyszek MCOperand::createExpr(MCConstantExpr::create(-1, getContext())));
46481707549SColin LeMahieu break;
46581707549SColin LeMahieu default:
46681707549SColin LeMahieu break;
46781707549SColin LeMahieu }
46881707549SColin LeMahieu
4697cd08927SColin LeMahieu if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) {
4707cd08927SColin LeMahieu unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI);
4717cd08927SColin LeMahieu MCOperand &MCO = MI.getOperand(OpIndex);
4727cd08927SColin LeMahieu assert(MCO.isReg() && "New value consumers must be registers");
4737cd08927SColin LeMahieu unsigned Register =
4747cd08927SColin LeMahieu getContext().getRegisterInfo()->getEncodingValue(MCO.getReg());
4757cd08927SColin LeMahieu if ((Register & 0x6) == 0)
4767cd08927SColin LeMahieu // HexagonPRM 10.11 Bit 1-2 == 0 is reserved
4777cd08927SColin LeMahieu return MCDisassembler::Fail;
4787cd08927SColin LeMahieu unsigned Lookback = (Register & 0x6) >> 1;
4797cd08927SColin LeMahieu unsigned Offset = 1;
4807cd08927SColin LeMahieu bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI);
481a8ab1b75SKrzysztof Parzyszek bool PrevVector = false;
4827cd08927SColin LeMahieu auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle);
4837cd08927SColin LeMahieu auto i = Instructions.end() - 1;
4847cd08927SColin LeMahieu for (auto n = Instructions.begin() - 1;; --i, ++Offset) {
4857cd08927SColin LeMahieu if (i == n)
4867cd08927SColin LeMahieu // Couldn't find producer
4877cd08927SColin LeMahieu return MCDisassembler::Fail;
488a8ab1b75SKrzysztof Parzyszek bool CurrentVector = HexagonMCInstrInfo::isVector(*MCII, *i->getInst());
489a8ab1b75SKrzysztof Parzyszek if (Vector && !CurrentVector)
4907cd08927SColin LeMahieu // Skip scalars when calculating distances for vectors
4917cd08927SColin LeMahieu ++Lookback;
492a8ab1b75SKrzysztof Parzyszek if (HexagonMCInstrInfo::isImmext(*i->getInst()) && (Vector == PrevVector))
4937cd08927SColin LeMahieu ++Lookback;
494a8ab1b75SKrzysztof Parzyszek PrevVector = CurrentVector;
4957cd08927SColin LeMahieu if (Offset == Lookback)
4967cd08927SColin LeMahieu break;
4977cd08927SColin LeMahieu }
4987cd08927SColin LeMahieu auto const &Inst = *i->getInst();
4997cd08927SColin LeMahieu bool SubregBit = (Register & 0x1) != 0;
500a8ab1b75SKrzysztof Parzyszek if (HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) {
5017cd08927SColin LeMahieu // If subreg bit is set we're selecting the second produced newvalue
502a8ab1b75SKrzysztof Parzyszek unsigned Producer = SubregBit ?
503a8ab1b75SKrzysztof Parzyszek HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg() :
5047cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg();
5057cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister);
5067cd08927SColin LeMahieu MCO.setReg(Producer);
5077cd08927SColin LeMahieu } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) {
5087cd08927SColin LeMahieu unsigned Producer =
5097cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg();
510bf3b86bcSBrian Cain
511bf3b86bcSBrian Cain if (HexagonMCInstrInfo::IsVecRegPair(Producer)) {
512bf3b86bcSBrian Cain const bool Rev = HexagonMCInstrInfo::IsReverseVecRegPair(Producer);
513bf3b86bcSBrian Cain const unsigned ProdPairIndex =
514bf3b86bcSBrian Cain Rev ? Producer - Hexagon::WR0 : Producer - Hexagon::W0;
515bf3b86bcSBrian Cain Producer = (ProdPairIndex << 1) + SubregBit + Hexagon::V0;
516bf3b86bcSBrian Cain } else if (SubregBit)
5176fdfa3dcSColin LeMahieu // Hexagon PRM 10.11 New-value operands
5186fdfa3dcSColin LeMahieu // Nt[0] is reserved and should always be encoded as zero.
5197cd08927SColin LeMahieu return MCDisassembler::Fail;
5207cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister);
5217cd08927SColin LeMahieu MCO.setReg(Producer);
5227cd08927SColin LeMahieu } else
5237cd08927SColin LeMahieu return MCDisassembler::Fail;
5247cd08927SColin LeMahieu }
5257cd08927SColin LeMahieu
526a8ab1b75SKrzysztof Parzyszek if (CurrentExtender != nullptr) {
527a72fad98SKrzysztof Parzyszek MCInst const &Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI)
528a72fad98SKrzysztof Parzyszek ? *MI.getOperand(1).getInst()
529a72fad98SKrzysztof Parzyszek : MI;
5307cd08927SColin LeMahieu if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) &&
5317cd08927SColin LeMahieu !HexagonMCInstrInfo::isExtended(*MCII, Inst))
5327cd08927SColin LeMahieu return MCDisassembler::Fail;
5337cd08927SColin LeMahieu }
5345d6f03bdSColin LeMahieu return Result;
53588ebb9e2SColin LeMahieu }
5367cd08927SColin LeMahieu
DecodeRegisterClass(MCInst & Inst,unsigned RegNo,ArrayRef<MCPhysReg> Table)5377cd08927SColin LeMahieu static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
538e5e035a3SCraig Topper ArrayRef<MCPhysReg> Table) {
5393da000c0SCraig Topper if (RegNo < Table.size()) {
5407cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Table[RegNo]));
5417cd08927SColin LeMahieu return MCDisassembler::Success;
5423da000c0SCraig Topper }
5433da000c0SCraig Topper
5447cd08927SColin LeMahieu return MCDisassembler::Fail;
5457cd08927SColin LeMahieu }
5467cd08927SColin LeMahieu
5474ae9745aSMaksim Panchenko static DecodeStatus
DecodeIntRegsLow8RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)5484ae9745aSMaksim Panchenko DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
5494ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
5507c958713SColin LeMahieu return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
5517c958713SColin LeMahieu }
5527c958713SColin LeMahieu
DecodeIntRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)5537cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
5547cd08927SColin LeMahieu uint64_t Address,
5554ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
556e5e035a3SCraig Topper static const MCPhysReg IntRegDecoderTable[] = {
5577cd08927SColin LeMahieu Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
5587cd08927SColin LeMahieu Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
5597cd08927SColin LeMahieu Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
5607cd08927SColin LeMahieu Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
5617cd08927SColin LeMahieu Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
5627cd08927SColin LeMahieu Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
5637cd08927SColin LeMahieu Hexagon::R30, Hexagon::R31};
5647cd08927SColin LeMahieu
565e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable);
5667cd08927SColin LeMahieu }
5677c958713SColin LeMahieu
5684ae9745aSMaksim Panchenko static DecodeStatus
DecodeGeneralSubRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)5694ae9745aSMaksim Panchenko DecodeGeneralSubRegsRegisterClass(MCInst &Inst, unsigned RegNo,
570a72fad98SKrzysztof Parzyszek uint64_t Address,
5714ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
572a72fad98SKrzysztof Parzyszek static const MCPhysReg GeneralSubRegDecoderTable[] = {
573a72fad98SKrzysztof Parzyszek Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3,
574a72fad98SKrzysztof Parzyszek Hexagon::R4, Hexagon::R5, Hexagon::R6, Hexagon::R7,
575a72fad98SKrzysztof Parzyszek Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
576a72fad98SKrzysztof Parzyszek Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23,
577a72fad98SKrzysztof Parzyszek };
578a72fad98SKrzysztof Parzyszek
579a72fad98SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo, GeneralSubRegDecoderTable);
580a72fad98SKrzysztof Parzyszek }
581a72fad98SKrzysztof Parzyszek
DecodeHvxVRRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)58255772976SKrzysztof Parzyszek static DecodeStatus DecodeHvxVRRegisterClass(MCInst &Inst, unsigned RegNo,
5837c958713SColin LeMahieu uint64_t /*Address*/,
5844ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
58555772976SKrzysztof Parzyszek static const MCPhysReg HvxVRDecoderTable[] = {
5867c958713SColin LeMahieu Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4,
5877c958713SColin LeMahieu Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
5887c958713SColin LeMahieu Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
5897c958713SColin LeMahieu Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
5907c958713SColin LeMahieu Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
5917c958713SColin LeMahieu Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
5927c958713SColin LeMahieu Hexagon::V30, Hexagon::V31};
5937c958713SColin LeMahieu
59455772976SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo, HvxVRDecoderTable);
5957c958713SColin LeMahieu }
5967c958713SColin LeMahieu
5974ae9745aSMaksim Panchenko static DecodeStatus
DecodeDoubleRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)5984ae9745aSMaksim Panchenko DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo,
5997cd08927SColin LeMahieu uint64_t /*Address*/,
6004ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
601e5e035a3SCraig Topper static const MCPhysReg DoubleRegDecoderTable[] = {
6027cd08927SColin LeMahieu Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
6037cd08927SColin LeMahieu Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
6047cd08927SColin LeMahieu Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
6057cd08927SColin LeMahieu Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
6067cd08927SColin LeMahieu
607e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable);
6087cd08927SColin LeMahieu }
6097cd08927SColin LeMahieu
6104ae9745aSMaksim Panchenko static DecodeStatus
DecodeGeneralDoubleLow8RegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)6114ae9745aSMaksim Panchenko DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo,
6124ae9745aSMaksim Panchenko uint64_t /*Address*/,
6134ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
614a72fad98SKrzysztof Parzyszek static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = {
615a72fad98SKrzysztof Parzyszek Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
616a72fad98SKrzysztof Parzyszek Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11};
617a72fad98SKrzysztof Parzyszek
618a72fad98SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo, GeneralDoubleLow8RegDecoderTable);
619a72fad98SKrzysztof Parzyszek }
620a72fad98SKrzysztof Parzyszek
DecodeHvxWRRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)62155772976SKrzysztof Parzyszek static DecodeStatus DecodeHvxWRRegisterClass(MCInst &Inst, unsigned RegNo,
6227c958713SColin LeMahieu uint64_t /*Address*/,
6234ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
62455772976SKrzysztof Parzyszek static const MCPhysReg HvxWRDecoderTable[] = {
625bf3b86bcSBrian Cain Hexagon::W0, Hexagon::WR0, Hexagon::W1, Hexagon::WR1, Hexagon::W2,
626bf3b86bcSBrian Cain Hexagon::WR2, Hexagon::W3, Hexagon::WR3, Hexagon::W4, Hexagon::WR4,
627bf3b86bcSBrian Cain Hexagon::W5, Hexagon::WR5, Hexagon::W6, Hexagon::WR6, Hexagon::W7,
628bf3b86bcSBrian Cain Hexagon::WR7, Hexagon::W8, Hexagon::WR8, Hexagon::W9, Hexagon::WR9,
629bf3b86bcSBrian Cain Hexagon::W10, Hexagon::WR10, Hexagon::W11, Hexagon::WR11, Hexagon::W12,
630bf3b86bcSBrian Cain Hexagon::WR12, Hexagon::W13, Hexagon::WR13, Hexagon::W14, Hexagon::WR14,
631bf3b86bcSBrian Cain Hexagon::W15, Hexagon::WR15,
632bf3b86bcSBrian Cain };
6337c958713SColin LeMahieu
634bf3b86bcSBrian Cain return DecodeRegisterClass(Inst, RegNo, HvxWRDecoderTable);
6357c958713SColin LeMahieu }
6367c958713SColin LeMahieu
63713a9cf28SKrzysztof Parzyszek LLVM_ATTRIBUTE_UNUSED // Suppress warning temporarily.
6384ae9745aSMaksim Panchenko static DecodeStatus
DecodeHvxVQRRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)6394ae9745aSMaksim Panchenko DecodeHvxVQRRegisterClass(MCInst &Inst, unsigned RegNo,
64013a9cf28SKrzysztof Parzyszek uint64_t /*Address*/,
6414ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
64213a9cf28SKrzysztof Parzyszek static const MCPhysReg HvxVQRDecoderTable[] = {
64313a9cf28SKrzysztof Parzyszek Hexagon::VQ0, Hexagon::VQ1, Hexagon::VQ2, Hexagon::VQ3,
64413a9cf28SKrzysztof Parzyszek Hexagon::VQ4, Hexagon::VQ5, Hexagon::VQ6, Hexagon::VQ7};
64513a9cf28SKrzysztof Parzyszek
64613a9cf28SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo >> 2, HvxVQRDecoderTable);
64713a9cf28SKrzysztof Parzyszek }
64813a9cf28SKrzysztof Parzyszek
DecodePredRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)6497cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
6507cd08927SColin LeMahieu uint64_t /*Address*/,
6514ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
652e5e035a3SCraig Topper static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
6537cd08927SColin LeMahieu Hexagon::P2, Hexagon::P3};
6547cd08927SColin LeMahieu
655e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable);
6567cd08927SColin LeMahieu }
6577cd08927SColin LeMahieu
DecodeHvxQRRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)65855772976SKrzysztof Parzyszek static DecodeStatus DecodeHvxQRRegisterClass(MCInst &Inst, unsigned RegNo,
6597c958713SColin LeMahieu uint64_t /*Address*/,
6604ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
66155772976SKrzysztof Parzyszek static const MCPhysReg HvxQRDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
6627c958713SColin LeMahieu Hexagon::Q2, Hexagon::Q3};
6637c958713SColin LeMahieu
66455772976SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo, HvxQRDecoderTable);
6657c958713SColin LeMahieu }
666be8c453dSColin LeMahieu
DecodeCtrRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)6677cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
6687cd08927SColin LeMahieu uint64_t /*Address*/,
6694ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
670f9015e62SKrzysztof Parzyszek using namespace Hexagon;
671e4fc6ee7SEugene Zelenko
672e5e035a3SCraig Topper static const MCPhysReg CtrlRegDecoderTable[] = {
673f9015e62SKrzysztof Parzyszek /* 0 */ SA0, LC0, SA1, LC1,
674e2603328SKrzysztof Parzyszek /* 4 */ P3_0, C5, M0, M1,
675f9015e62SKrzysztof Parzyszek /* 8 */ USR, PC, UGP, GP,
676ab57c2baSKrzysztof Parzyszek /* 12 */ CS0, CS1, UPCYCLELO, UPCYCLEHI,
677f9015e62SKrzysztof Parzyszek /* 16 */ FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI,
678f9015e62SKrzysztof Parzyszek /* 20 */ 0, 0, 0, 0,
679f9015e62SKrzysztof Parzyszek /* 24 */ 0, 0, 0, 0,
680f9015e62SKrzysztof Parzyszek /* 28 */ 0, 0, UTIMERLO, UTIMERHI
6817cd08927SColin LeMahieu };
6827cd08927SColin LeMahieu
683f15014ffSBenjamin Kramer if (RegNo >= array_lengthof(CtrlRegDecoderTable))
6847cd08927SColin LeMahieu return MCDisassembler::Fail;
6857cd08927SColin LeMahieu
686f9015e62SKrzysztof Parzyszek static_assert(NoRegister == 0, "Expecting NoRegister to be 0");
687f9015e62SKrzysztof Parzyszek if (CtrlRegDecoderTable[RegNo] == NoRegister)
6887cd08927SColin LeMahieu return MCDisassembler::Fail;
6897cd08927SColin LeMahieu
6907cd08927SColin LeMahieu unsigned Register = CtrlRegDecoderTable[RegNo];
6917cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register));
6927cd08927SColin LeMahieu return MCDisassembler::Success;
6937cd08927SColin LeMahieu }
6947cd08927SColin LeMahieu
6954ae9745aSMaksim Panchenko static DecodeStatus
DecodeCtrRegs64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)6964ae9745aSMaksim Panchenko DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t /*Address*/,
6974ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
698f9015e62SKrzysztof Parzyszek using namespace Hexagon;
699e4fc6ee7SEugene Zelenko
700e5e035a3SCraig Topper static const MCPhysReg CtrlReg64DecoderTable[] = {
701f9015e62SKrzysztof Parzyszek /* 0 */ C1_0, 0, C3_2, 0,
702f9015e62SKrzysztof Parzyszek /* 4 */ C5_4, 0, C7_6, 0,
703f9015e62SKrzysztof Parzyszek /* 8 */ C9_8, 0, C11_10, 0,
704ab57c2baSKrzysztof Parzyszek /* 12 */ CS, 0, UPCYCLE, 0,
705f9015e62SKrzysztof Parzyszek /* 16 */ C17_16, 0, PKTCOUNT, 0,
706f9015e62SKrzysztof Parzyszek /* 20 */ 0, 0, 0, 0,
707f9015e62SKrzysztof Parzyszek /* 24 */ 0, 0, 0, 0,
708f9015e62SKrzysztof Parzyszek /* 28 */ 0, 0, UTIMER, 0
7097cd08927SColin LeMahieu };
7107cd08927SColin LeMahieu
711f15014ffSBenjamin Kramer if (RegNo >= array_lengthof(CtrlReg64DecoderTable))
7127cd08927SColin LeMahieu return MCDisassembler::Fail;
7137cd08927SColin LeMahieu
714f9015e62SKrzysztof Parzyszek static_assert(NoRegister == 0, "Expecting NoRegister to be 0");
715f9015e62SKrzysztof Parzyszek if (CtrlReg64DecoderTable[RegNo] == NoRegister)
7167cd08927SColin LeMahieu return MCDisassembler::Fail;
7177cd08927SColin LeMahieu
7187cd08927SColin LeMahieu unsigned Register = CtrlReg64DecoderTable[RegNo];
7197cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register));
7207cd08927SColin LeMahieu return MCDisassembler::Success;
7217cd08927SColin LeMahieu }
7227cd08927SColin LeMahieu
DecodeModRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)7237cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
7247cd08927SColin LeMahieu uint64_t /*Address*/,
7254ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
7267cd08927SColin LeMahieu unsigned Register = 0;
7277cd08927SColin LeMahieu switch (RegNo) {
7287cd08927SColin LeMahieu case 0:
7297cd08927SColin LeMahieu Register = Hexagon::M0;
7307cd08927SColin LeMahieu break;
7317cd08927SColin LeMahieu case 1:
7327cd08927SColin LeMahieu Register = Hexagon::M1;
7337cd08927SColin LeMahieu break;
7347cd08927SColin LeMahieu default:
7357cd08927SColin LeMahieu return MCDisassembler::Fail;
7367cd08927SColin LeMahieu }
7377cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register));
7387cd08927SColin LeMahieu return MCDisassembler::Success;
7397cd08927SColin LeMahieu }
7407cd08927SColin LeMahieu
unsignedImmDecoder(MCInst & MI,unsigned tmp,uint64_t,const MCDisassembler * Decoder)7417cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
7427cd08927SColin LeMahieu uint64_t /*Address*/,
7434ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
7447cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder);
745a8ab1b75SKrzysztof Parzyszek int64_t FullValue = fullValue(Disassembler, MI, tmp);
7467cd08927SColin LeMahieu assert(FullValue >= 0 && "Negative in unsigned decoder");
7477cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext());
7487cd08927SColin LeMahieu return MCDisassembler::Success;
7497cd08927SColin LeMahieu }
7507cd08927SColin LeMahieu
s32_0ImmDecoder(MCInst & MI,unsigned tmp,uint64_t,const MCDisassembler * Decoder)751a72fad98SKrzysztof Parzyszek static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp,
7524ae9745aSMaksim Panchenko uint64_t /*Address*/,
7534ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
754a72fad98SKrzysztof Parzyszek HexagonDisassembler const &Disassembler = disassembler(Decoder);
755a72fad98SKrzysztof Parzyszek unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI);
756a72fad98SKrzysztof Parzyszek tmp = SignExtend64(tmp, Bits);
757a72fad98SKrzysztof Parzyszek signedDecoder<32>(MI, tmp, Decoder);
758a72fad98SKrzysztof Parzyszek return MCDisassembler::Success;
759a72fad98SKrzysztof Parzyszek }
760a72fad98SKrzysztof Parzyszek
7617cd08927SColin LeMahieu // custom decoder for various jump/call immediates
brtargetDecoder(MCInst & MI,unsigned tmp,uint64_t Address,const MCDisassembler * Decoder)7627cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
7634ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
7647cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder);
7657cd08927SColin LeMahieu unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI);
7667cd08927SColin LeMahieu // r13_2 is not extendable, so if there are no extent bits, it's r13_2
7677cd08927SColin LeMahieu if (Bits == 0)
7687cd08927SColin LeMahieu Bits = 15;
769a8ab1b75SKrzysztof Parzyszek uint64_t FullValue = fullValue(Disassembler, MI, SignExtend64(tmp, Bits));
770a8ab1b75SKrzysztof Parzyszek uint32_t Extended = FullValue + Address;
771*bed9efedSMaksim Panchenko if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 0, 0,
772*bed9efedSMaksim Panchenko 4))
7737cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext());
7747cd08927SColin LeMahieu return MCDisassembler::Success;
7757cd08927SColin LeMahieu }
77622a21d4cSKrzysztof Parzyszek
777743e263eSBrian Cain static const uint16_t SysRegDecoderTable[] = {
778743e263eSBrian Cain Hexagon::SGP0, Hexagon::SGP1, Hexagon::STID,
779743e263eSBrian Cain Hexagon::ELR, Hexagon::BADVA0, Hexagon::BADVA1,
780743e263eSBrian Cain Hexagon::SSR, Hexagon::CCR, Hexagon::HTID,
781743e263eSBrian Cain Hexagon::BADVA, Hexagon::IMASK, Hexagon::S11,
782743e263eSBrian Cain Hexagon::S12, Hexagon::S13, Hexagon::S14,
783743e263eSBrian Cain Hexagon::S15, Hexagon::EVB, Hexagon::MODECTL,
784743e263eSBrian Cain Hexagon::SYSCFG, Hexagon::S19, Hexagon::S20,
785743e263eSBrian Cain Hexagon::VID, Hexagon::S22, Hexagon::S23,
786743e263eSBrian Cain Hexagon::S24, Hexagon::S25, Hexagon::S26,
787743e263eSBrian Cain Hexagon::CFGBASE, Hexagon::DIAG, Hexagon::REV,
788743e263eSBrian Cain Hexagon::PCYCLELO, Hexagon::PCYCLEHI, Hexagon::ISDBST,
789743e263eSBrian Cain Hexagon::ISDBCFG0, Hexagon::ISDBCFG1, Hexagon::S35,
790743e263eSBrian Cain Hexagon::BRKPTPC0, Hexagon::BRKPTCFG0, Hexagon::BRKPTPC1,
791743e263eSBrian Cain Hexagon::BRKPTCFG1, Hexagon::ISDBMBXIN, Hexagon::ISDBMBXOUT,
792743e263eSBrian Cain Hexagon::ISDBEN, Hexagon::ISDBGPR, Hexagon::S44,
793743e263eSBrian Cain Hexagon::S45, Hexagon::S46, Hexagon::S47,
794743e263eSBrian Cain Hexagon::PMUCNT0, Hexagon::PMUCNT1, Hexagon::PMUCNT2,
795743e263eSBrian Cain Hexagon::PMUCNT3, Hexagon::PMUEVTCFG, Hexagon::PMUCFG,
796743e263eSBrian Cain Hexagon::S54, Hexagon::S55, Hexagon::S56,
797743e263eSBrian Cain Hexagon::S57, Hexagon::S58, Hexagon::S59,
798743e263eSBrian Cain Hexagon::S60, Hexagon::S61, Hexagon::S62,
799743e263eSBrian Cain Hexagon::S63, Hexagon::S64, Hexagon::S65,
800743e263eSBrian Cain Hexagon::S66, Hexagon::S67, Hexagon::S68,
801743e263eSBrian Cain Hexagon::S69, Hexagon::S70, Hexagon::S71,
802743e263eSBrian Cain Hexagon::S72, Hexagon::S73, Hexagon::S74,
803743e263eSBrian Cain Hexagon::S75, Hexagon::S76, Hexagon::S77,
804743e263eSBrian Cain Hexagon::S78, Hexagon::S79, Hexagon::S80,
805743e263eSBrian Cain };
806743e263eSBrian Cain
DecodeSysRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)807743e263eSBrian Cain static DecodeStatus DecodeSysRegsRegisterClass(MCInst &Inst, unsigned RegNo,
808743e263eSBrian Cain uint64_t /*Address*/,
8094ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
810743e263eSBrian Cain if (RegNo >= sizeof(SysRegDecoderTable) / sizeof(SysRegDecoderTable[0]))
811743e263eSBrian Cain return MCDisassembler::Fail;
812743e263eSBrian Cain
813743e263eSBrian Cain if (SysRegDecoderTable[RegNo] == Hexagon::NoRegister)
814743e263eSBrian Cain return MCDisassembler::Fail;
815743e263eSBrian Cain
816743e263eSBrian Cain unsigned Register = SysRegDecoderTable[RegNo];
817743e263eSBrian Cain Inst.addOperand(MCOperand::createReg(Register));
818743e263eSBrian Cain return MCDisassembler::Success;
819743e263eSBrian Cain }
820743e263eSBrian Cain
821743e263eSBrian Cain static const uint16_t SysReg64DecoderTable[] = {
822743e263eSBrian Cain Hexagon::SGP1_0, Hexagon::S3_2, Hexagon::S5_4, Hexagon::S7_6,
823743e263eSBrian Cain Hexagon::S9_8, Hexagon::S11_10, Hexagon::S13_12, Hexagon::S15_14,
824743e263eSBrian Cain Hexagon::S17_16, Hexagon::S19_18, Hexagon::S21_20, Hexagon::S23_22,
825743e263eSBrian Cain Hexagon::S25_24, Hexagon::S27_26, Hexagon::S29_28, Hexagon::S31_30,
826743e263eSBrian Cain Hexagon::S33_32, Hexagon::S35_34, Hexagon::S37_36, Hexagon::S39_38,
827743e263eSBrian Cain Hexagon::S41_40, Hexagon::S43_42, Hexagon::S45_44, Hexagon::S47_46,
828743e263eSBrian Cain Hexagon::S49_48, Hexagon::S51_50, Hexagon::S53_52, Hexagon::S55_54,
829743e263eSBrian Cain Hexagon::S57_56, Hexagon::S59_58, Hexagon::S61_60, Hexagon::S63_62,
830743e263eSBrian Cain Hexagon::S65_64, Hexagon::S67_66, Hexagon::S69_68, Hexagon::S71_70,
831743e263eSBrian Cain Hexagon::S73_72, Hexagon::S75_74, Hexagon::S77_76, Hexagon::S79_78,
832743e263eSBrian Cain };
833743e263eSBrian Cain
8344ae9745aSMaksim Panchenko static DecodeStatus
DecodeSysRegs64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)8354ae9745aSMaksim Panchenko DecodeSysRegs64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t /*Address*/,
8364ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
837743e263eSBrian Cain RegNo = RegNo >> 1;
838743e263eSBrian Cain if (RegNo >= sizeof(SysReg64DecoderTable) / sizeof(SysReg64DecoderTable[0]))
839743e263eSBrian Cain return MCDisassembler::Fail;
840743e263eSBrian Cain
841743e263eSBrian Cain if (SysReg64DecoderTable[RegNo] == Hexagon::NoRegister)
842743e263eSBrian Cain return MCDisassembler::Fail;
843743e263eSBrian Cain
844743e263eSBrian Cain unsigned Register = SysReg64DecoderTable[RegNo];
845743e263eSBrian Cain Inst.addOperand(MCOperand::createReg(Register));
846743e263eSBrian Cain return MCDisassembler::Success;
847743e263eSBrian Cain }
848743e263eSBrian Cain
8494ae9745aSMaksim Panchenko static DecodeStatus
DecodeGuestRegsRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)8504ae9745aSMaksim Panchenko DecodeGuestRegsRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t /*Address*/,
8514ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
85222a21d4cSKrzysztof Parzyszek using namespace Hexagon;
85322a21d4cSKrzysztof Parzyszek
85422a21d4cSKrzysztof Parzyszek static const MCPhysReg GuestRegDecoderTable[] = {
85522a21d4cSKrzysztof Parzyszek /* 0 */ GELR, GSR, GOSP, G3,
85622a21d4cSKrzysztof Parzyszek /* 4 */ G4, G5, G6, G7,
85722a21d4cSKrzysztof Parzyszek /* 8 */ G8, G9, G10, G11,
85822a21d4cSKrzysztof Parzyszek /* 12 */ G12, G13, G14, G15,
85922a21d4cSKrzysztof Parzyszek /* 16 */ GPMUCNT4, GPMUCNT5, GPMUCNT6, GPMUCNT7,
86022a21d4cSKrzysztof Parzyszek /* 20 */ G20, G21, G22, G23,
86122a21d4cSKrzysztof Parzyszek /* 24 */ GPCYCLELO, GPCYCLEHI, GPMUCNT0, GPMUCNT1,
86222a21d4cSKrzysztof Parzyszek /* 28 */ GPMUCNT2, GPMUCNT3, G30, G31
86322a21d4cSKrzysztof Parzyszek };
86422a21d4cSKrzysztof Parzyszek
865f15014ffSBenjamin Kramer if (RegNo >= array_lengthof(GuestRegDecoderTable))
86622a21d4cSKrzysztof Parzyszek return MCDisassembler::Fail;
86722a21d4cSKrzysztof Parzyszek if (GuestRegDecoderTable[RegNo] == Hexagon::NoRegister)
86822a21d4cSKrzysztof Parzyszek return MCDisassembler::Fail;
86922a21d4cSKrzysztof Parzyszek
87022a21d4cSKrzysztof Parzyszek unsigned Register = GuestRegDecoderTable[RegNo];
87122a21d4cSKrzysztof Parzyszek Inst.addOperand(MCOperand::createReg(Register));
87222a21d4cSKrzysztof Parzyszek return MCDisassembler::Success;
87322a21d4cSKrzysztof Parzyszek }
87422a21d4cSKrzysztof Parzyszek
8754ae9745aSMaksim Panchenko static DecodeStatus
DecodeGuestRegs64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t,const MCDisassembler * Decoder)8764ae9745aSMaksim Panchenko DecodeGuestRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
87722a21d4cSKrzysztof Parzyszek uint64_t /*Address*/,
8784ae9745aSMaksim Panchenko const MCDisassembler *Decoder) {
87922a21d4cSKrzysztof Parzyszek using namespace Hexagon;
88022a21d4cSKrzysztof Parzyszek
88122a21d4cSKrzysztof Parzyszek static const MCPhysReg GuestReg64DecoderTable[] = {
88222a21d4cSKrzysztof Parzyszek /* 0 */ G1_0, 0, G3_2, 0,
88322a21d4cSKrzysztof Parzyszek /* 4 */ G5_4, 0, G7_6, 0,
88422a21d4cSKrzysztof Parzyszek /* 8 */ G9_8, 0, G11_10, 0,
88522a21d4cSKrzysztof Parzyszek /* 12 */ G13_12, 0, G15_14, 0,
88622a21d4cSKrzysztof Parzyszek /* 16 */ G17_16, 0, G19_18, 0,
88722a21d4cSKrzysztof Parzyszek /* 20 */ G21_20, 0, G23_22, 0,
88822a21d4cSKrzysztof Parzyszek /* 24 */ G25_24, 0, G27_26, 0,
88922a21d4cSKrzysztof Parzyszek /* 28 */ G29_28, 0, G31_30, 0
89022a21d4cSKrzysztof Parzyszek };
89122a21d4cSKrzysztof Parzyszek
892f15014ffSBenjamin Kramer if (RegNo >= array_lengthof(GuestReg64DecoderTable))
89322a21d4cSKrzysztof Parzyszek return MCDisassembler::Fail;
89422a21d4cSKrzysztof Parzyszek if (GuestReg64DecoderTable[RegNo] == Hexagon::NoRegister)
89522a21d4cSKrzysztof Parzyszek return MCDisassembler::Fail;
89622a21d4cSKrzysztof Parzyszek
89722a21d4cSKrzysztof Parzyszek unsigned Register = GuestReg64DecoderTable[RegNo];
89822a21d4cSKrzysztof Parzyszek Inst.addOperand(MCOperand::createReg(Register));
89922a21d4cSKrzysztof Parzyszek return MCDisassembler::Success;
90022a21d4cSKrzysztof Parzyszek }
901