1*e4fc6ee7SEugene Zelenko //===- HexagonDisassembler.cpp - Disassembler for Hexagon ISA -------------===// 288ebb9e2SColin LeMahieu // 388ebb9e2SColin LeMahieu // The LLVM Compiler Infrastructure 488ebb9e2SColin LeMahieu // 588ebb9e2SColin LeMahieu // This file is distributed under the University of Illinois Open Source 688ebb9e2SColin LeMahieu // License. See LICENSE.TXT for details. 788ebb9e2SColin LeMahieu // 888ebb9e2SColin LeMahieu //===----------------------------------------------------------------------===// 988ebb9e2SColin LeMahieu 107cd08927SColin LeMahieu #define DEBUG_TYPE "hexagon-disassembler" 117cd08927SColin LeMahieu 1268d967d9SColin LeMahieu #include "Hexagon.h" 1388ebb9e2SColin LeMahieu #include "MCTargetDesc/HexagonBaseInfo.h" 147cd08927SColin LeMahieu #include "MCTargetDesc/HexagonMCChecker.h" 157cd08927SColin LeMahieu #include "MCTargetDesc/HexagonMCInstrInfo.h" 166bda14b3SChandler Carruth #include "MCTargetDesc/HexagonMCTargetDesc.h" 1782085927SEugene Zelenko #include "llvm/ADT/ArrayRef.h" 1882085927SEugene Zelenko #include "llvm/ADT/STLExtras.h" 197cd08927SColin LeMahieu #include "llvm/MC/MCContext.h" 206bda14b3SChandler Carruth #include "llvm/MC/MCDisassembler/MCDisassembler.h" 2188ebb9e2SColin LeMahieu #include "llvm/MC/MCExpr.h" 2288ebb9e2SColin LeMahieu #include "llvm/MC/MCFixedLenDisassembler.h" 2388ebb9e2SColin LeMahieu #include "llvm/MC/MCInst.h" 247cd08927SColin LeMahieu #include "llvm/MC/MCInstrInfo.h" 2582085927SEugene Zelenko #include "llvm/MC/MCRegisterInfo.h" 2688ebb9e2SColin LeMahieu #include "llvm/MC/MCSubtargetInfo.h" 27*e4fc6ee7SEugene Zelenko #include "llvm/Support/Endian.h" 2882085927SEugene Zelenko #include "llvm/Support/MathExtras.h" 297cd08927SColin LeMahieu #include "llvm/Support/TargetRegistry.h" 306bda14b3SChandler Carruth #include "llvm/Support/raw_ostream.h" 3182085927SEugene Zelenko #include <cassert> 3282085927SEugene Zelenko #include <cstddef> 3382085927SEugene Zelenko #include <cstdint> 3482085927SEugene Zelenko #include <memory> 3588ebb9e2SColin LeMahieu 3688ebb9e2SColin LeMahieu using namespace llvm; 3768d967d9SColin LeMahieu using namespace Hexagon; 3888ebb9e2SColin LeMahieu 39*e4fc6ee7SEugene Zelenko using DecodeStatus = MCDisassembler::DecodeStatus; 4088ebb9e2SColin LeMahieu 4188ebb9e2SColin LeMahieu namespace { 4282085927SEugene Zelenko 4388ebb9e2SColin LeMahieu /// \brief Hexagon disassembler for all Hexagon platforms. 4488ebb9e2SColin LeMahieu class HexagonDisassembler : public MCDisassembler { 4588ebb9e2SColin LeMahieu public: 467cd08927SColin LeMahieu std::unique_ptr<MCInstrInfo const> const MCII; 4768d967d9SColin LeMahieu std::unique_ptr<MCInst *> CurrentBundle; 4882085927SEugene Zelenko 497cd08927SColin LeMahieu HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, 507cd08927SColin LeMahieu MCInstrInfo const *MCII) 517cd08927SColin LeMahieu : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *) {} 5288ebb9e2SColin LeMahieu 5368d967d9SColin LeMahieu DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB, 5468d967d9SColin LeMahieu ArrayRef<uint8_t> Bytes, uint64_t Address, 5568d967d9SColin LeMahieu raw_ostream &VStream, raw_ostream &CStream, 5668d967d9SColin LeMahieu 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 &VStream, 604aa6bea7SRafael Espindola raw_ostream &CStream) const override; 617cd08927SColin LeMahieu void addSubinstOperands(MCInst *MI, unsigned opcode, unsigned inst) const; 6288ebb9e2SColin LeMahieu }; 6382085927SEugene Zelenko 64*e4fc6ee7SEugene Zelenko } // end anonymous namespace 65*e4fc6ee7SEugene Zelenko 66*e4fc6ee7SEugene Zelenko static uint32_t fullValue(MCInstrInfo const &MCII, MCInst &MCB, MCInst &MI, 67a72fad98SKrzysztof Parzyszek int64_t Value) { 68a72fad98SKrzysztof Parzyszek MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( 69a72fad98SKrzysztof Parzyszek MCB, HexagonMCInstrInfo::bundleSize(MCB)); 70a72fad98SKrzysztof Parzyszek if (!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI)) 71a72fad98SKrzysztof Parzyszek return Value; 72a72fad98SKrzysztof Parzyszek unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI); 73a72fad98SKrzysztof Parzyszek uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f; 74a72fad98SKrzysztof Parzyszek int64_t Bits; 75a72fad98SKrzysztof Parzyszek bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits); 76a72fad98SKrzysztof Parzyszek assert(Success); (void)Success; 77a72fad98SKrzysztof Parzyszek uint32_t Upper26 = static_cast<uint32_t>(Bits); 78a72fad98SKrzysztof Parzyszek uint32_t Operand = Upper26 | Lower6; 79a72fad98SKrzysztof Parzyszek return Operand; 80a72fad98SKrzysztof Parzyszek } 81*e4fc6ee7SEugene Zelenko 82*e4fc6ee7SEugene Zelenko static HexagonDisassembler const &disassembler(void const *Decoder) { 83a72fad98SKrzysztof Parzyszek return *static_cast<HexagonDisassembler const *>(Decoder); 84a72fad98SKrzysztof Parzyszek } 85*e4fc6ee7SEugene Zelenko 86a72fad98SKrzysztof Parzyszek template <size_t T> 87*e4fc6ee7SEugene Zelenko static void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) { 88a72fad98SKrzysztof Parzyszek HexagonDisassembler const &Disassembler = disassembler(Decoder); 89a72fad98SKrzysztof Parzyszek int64_t FullValue = 90a72fad98SKrzysztof Parzyszek fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, 91a72fad98SKrzysztof Parzyszek SignExtend64<T>(tmp)); 92a72fad98SKrzysztof Parzyszek int64_t Extended = SignExtend64<32>(FullValue); 93a72fad98SKrzysztof Parzyszek HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); 94a72fad98SKrzysztof Parzyszek } 9588ebb9e2SColin LeMahieu 967cd08927SColin LeMahieu // Forward declare these because the auto-generated code will reference them. 977cd08927SColin LeMahieu // Definitions are further down. 987cd08927SColin LeMahieu 997cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 100be8c453dSColin LeMahieu uint64_t Address, 101be8c453dSColin LeMahieu const void *Decoder); 102a72fad98SKrzysztof Parzyszek static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, 103a72fad98SKrzysztof Parzyszek unsigned RegNo, 104a72fad98SKrzysztof Parzyszek uint64_t Address, 105a72fad98SKrzysztof Parzyszek const void *Decoder); 1067c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 1077c958713SColin LeMahieu uint64_t Address, 1087c958713SColin LeMahieu const void *Decoder); 1097c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 1107c958713SColin LeMahieu uint64_t Address, 1117c958713SColin LeMahieu const void *Decoder); 1127cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 1137cd08927SColin LeMahieu uint64_t Address, 1147cd08927SColin LeMahieu const void *Decoder); 115a72fad98SKrzysztof Parzyszek static DecodeStatus 116a72fad98SKrzysztof Parzyszek DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo, 117a72fad98SKrzysztof Parzyszek uint64_t Address, const void *Decoder); 1187c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 1197c958713SColin LeMahieu uint64_t Address, 1207c958713SColin LeMahieu const void *Decoder); 1217cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 1227cd08927SColin LeMahieu uint64_t Address, 1237cd08927SColin LeMahieu const void *Decoder); 1247c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 1257c958713SColin LeMahieu uint64_t Address, 1267c958713SColin LeMahieu const void *Decoder); 127f3db884eSColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 128be8c453dSColin LeMahieu uint64_t Address, 129be8c453dSColin LeMahieu const void *Decoder); 1307cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, 1317cd08927SColin LeMahieu uint64_t Address, 1327cd08927SColin LeMahieu const void *Decoder); 133404d5b24SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 134be8c453dSColin LeMahieu uint64_t Address, 1357cd08927SColin LeMahieu const void *Decoder); 1367cd08927SColin LeMahieu 1377cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 1387cd08927SColin LeMahieu uint64_t Address, const void *Decoder); 139a72fad98SKrzysztof Parzyszek static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, 140a72fad98SKrzysztof Parzyszek uint64_t /*Address*/, const void *Decoder); 141654dc11bSKrzysztof Parzyszek static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1421e9d1d76SColin LeMahieu const void *Decoder); 1431e9d1d76SColin LeMahieu static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1441e9d1d76SColin LeMahieu const void *Decoder); 1451e9d1d76SColin LeMahieu static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1461e9d1d76SColin LeMahieu const void *Decoder); 1471e9d1d76SColin LeMahieu static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1481e9d1d76SColin LeMahieu const void *Decoder); 1491e9d1d76SColin LeMahieu static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1501e9d1d76SColin LeMahieu const void *Decoder); 1511e9d1d76SColin LeMahieu static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1521e9d1d76SColin LeMahieu const void *Decoder); 153058abf1aSKrzysztof Parzyszek static DecodeStatus s3_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1547c958713SColin LeMahieu const void *Decoder); 1557cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1567cd08927SColin LeMahieu const void *Decoder); 157efa74e02SColin LeMahieu 158a72fad98SKrzysztof Parzyszek #include "HexagonDepDecoders.h" 15988ebb9e2SColin LeMahieu #include "HexagonGenDisassemblerTables.inc" 16088ebb9e2SColin LeMahieu 1617cd08927SColin LeMahieu static MCDisassembler *createHexagonDisassembler(const Target &T, 1627cd08927SColin LeMahieu const MCSubtargetInfo &STI, 16388ebb9e2SColin LeMahieu MCContext &Ctx) { 1647cd08927SColin LeMahieu return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo()); 16588ebb9e2SColin LeMahieu } 16688ebb9e2SColin LeMahieu 16788ebb9e2SColin LeMahieu extern "C" void LLVMInitializeHexagonDisassembler() { 168f42454b9SMehdi Amini TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(), 16988ebb9e2SColin LeMahieu createHexagonDisassembler); 17088ebb9e2SColin LeMahieu } 17188ebb9e2SColin LeMahieu 17288ebb9e2SColin LeMahieu DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size, 1737fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes, 17488ebb9e2SColin LeMahieu uint64_t Address, 17588ebb9e2SColin LeMahieu raw_ostream &os, 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; 182f0af6e52SColin LeMahieu MI = HexagonMCInstrInfo::createBundle(); 18382085927SEugene Zelenko while (Result == Success && !Complete) { 18468d967d9SColin LeMahieu if (Bytes.size() < HEXAGON_INSTR_SIZE) 18568d967d9SColin LeMahieu return MCDisassembler::Fail; 18668d967d9SColin LeMahieu MCInst *Inst = new (getContext()) MCInst; 18768d967d9SColin LeMahieu Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete); 18868d967d9SColin LeMahieu MI.addOperand(MCOperand::createInst(Inst)); 18968d967d9SColin LeMahieu Size += HEXAGON_INSTR_SIZE; 19068d967d9SColin LeMahieu Bytes = Bytes.slice(HEXAGON_INSTR_SIZE); 19168d967d9SColin LeMahieu } 1927cd08927SColin LeMahieu if (Result == MCDisassembler::Fail) 19368d967d9SColin LeMahieu return Result; 194a72fad98SKrzysztof Parzyszek if (Size > HEXAGON_MAX_PACKET_SIZE) 195a72fad98SKrzysztof Parzyszek return MCDisassembler::Fail; 196e12d1e70SKrzysztof Parzyszek HexagonMCChecker Checker(getContext(), *MCII, STI, MI, 197e12d1e70SKrzysztof Parzyszek *getContext().getRegisterInfo(), false); 1987cd08927SColin LeMahieu if (!Checker.check()) 1997cd08927SColin LeMahieu return MCDisassembler::Fail; 2007cd08927SColin LeMahieu return MCDisassembler::Success; 2017cd08927SColin LeMahieu } 2027cd08927SColin LeMahieu 203*e4fc6ee7SEugene Zelenko static void adjustDuplex(MCInst &MI, MCContext &Context) { 204a72fad98SKrzysztof Parzyszek switch (MI.getOpcode()) { 205a72fad98SKrzysztof Parzyszek case Hexagon::SA1_setin1: 206a72fad98SKrzysztof Parzyszek MI.insert(MI.begin() + 1, 207a72fad98SKrzysztof Parzyszek MCOperand::createExpr(MCConstantExpr::create(-1, Context))); 208a72fad98SKrzysztof Parzyszek break; 209a72fad98SKrzysztof Parzyszek case Hexagon::SA1_dec: 210a72fad98SKrzysztof Parzyszek MI.insert(MI.begin() + 2, 211a72fad98SKrzysztof Parzyszek MCOperand::createExpr(MCConstantExpr::create(-1, Context))); 212a72fad98SKrzysztof Parzyszek break; 213a72fad98SKrzysztof Parzyszek default: 214a72fad98SKrzysztof Parzyszek break; 2157cd08927SColin LeMahieu } 216a72fad98SKrzysztof Parzyszek } 21768d967d9SColin LeMahieu 21868d967d9SColin LeMahieu DecodeStatus HexagonDisassembler::getSingleInstruction( 21968d967d9SColin LeMahieu MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address, 22068d967d9SColin LeMahieu raw_ostream &os, raw_ostream &cs, bool &Complete) const { 22168d967d9SColin LeMahieu assert(Bytes.size() >= HEXAGON_INSTR_SIZE); 22268d967d9SColin LeMahieu 223a72fad98SKrzysztof Parzyszek uint32_t Instruction = support::endian::read32le(Bytes.data()); 22488ebb9e2SColin LeMahieu 22568d967d9SColin LeMahieu auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB); 22668d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 22768d967d9SColin LeMahieu HexagonII::INST_PARSE_LOOP_END) { 22868d967d9SColin LeMahieu if (BundleSize == 0) 22968d967d9SColin LeMahieu HexagonMCInstrInfo::setInnerLoop(MCB); 23068d967d9SColin LeMahieu else if (BundleSize == 1) 23168d967d9SColin LeMahieu HexagonMCInstrInfo::setOuterLoop(MCB); 23268d967d9SColin LeMahieu else 23368d967d9SColin LeMahieu return DecodeStatus::Fail; 23468d967d9SColin LeMahieu } 23568d967d9SColin LeMahieu 236a72fad98SKrzysztof Parzyszek MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( 237a72fad98SKrzysztof Parzyszek MCB, HexagonMCInstrInfo::bundleSize(MCB)); 238a72fad98SKrzysztof Parzyszek 239a72fad98SKrzysztof Parzyszek DecodeStatus Result = DecodeStatus::Fail; 24068d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 241be8c453dSColin LeMahieu HexagonII::INST_PARSE_DUPLEX) { 242a72fad98SKrzysztof Parzyszek unsigned duplexIClass; 243a72fad98SKrzysztof Parzyszek uint8_t const *DecodeLow, *DecodeHigh; 244be8c453dSColin LeMahieu duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1); 245be8c453dSColin LeMahieu switch (duplexIClass) { 246be8c453dSColin LeMahieu default: 247be8c453dSColin LeMahieu return MCDisassembler::Fail; 248be8c453dSColin LeMahieu case 0: 249a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L132; 250a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132; 251be8c453dSColin LeMahieu break; 252be8c453dSColin LeMahieu case 1: 253a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L232; 254a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132; 255be8c453dSColin LeMahieu break; 256be8c453dSColin LeMahieu case 2: 257a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L232; 258a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L232; 259be8c453dSColin LeMahieu break; 260be8c453dSColin LeMahieu case 3: 261a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_A32; 262a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32; 263be8c453dSColin LeMahieu break; 264be8c453dSColin LeMahieu case 4: 265a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L132; 266a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32; 267be8c453dSColin LeMahieu break; 268be8c453dSColin LeMahieu case 5: 269a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_L232; 270a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32; 271be8c453dSColin LeMahieu break; 272be8c453dSColin LeMahieu case 6: 273a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132; 274a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32; 275be8c453dSColin LeMahieu break; 276be8c453dSColin LeMahieu case 7: 277a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232; 278a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_A32; 279be8c453dSColin LeMahieu break; 280be8c453dSColin LeMahieu case 8: 281a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132; 282a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132; 283be8c453dSColin LeMahieu break; 284be8c453dSColin LeMahieu case 9: 285a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132; 286a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L232; 287be8c453dSColin LeMahieu break; 288be8c453dSColin LeMahieu case 10: 289a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S132; 290a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_S132; 291be8c453dSColin LeMahieu break; 292be8c453dSColin LeMahieu case 11: 293a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232; 294a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_S132; 295be8c453dSColin LeMahieu break; 296be8c453dSColin LeMahieu case 12: 297a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232; 298a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L132; 299be8c453dSColin LeMahieu break; 300be8c453dSColin LeMahieu case 13: 301a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232; 302a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_L232; 303be8c453dSColin LeMahieu break; 304be8c453dSColin LeMahieu case 14: 305a72fad98SKrzysztof Parzyszek DecodeLow = DecoderTableSUBINSN_S232; 306a72fad98SKrzysztof Parzyszek DecodeHigh = DecoderTableSUBINSN_S232; 307be8c453dSColin LeMahieu break; 308be8c453dSColin LeMahieu } 309a72fad98SKrzysztof Parzyszek MI.setOpcode(Hexagon::DuplexIClass0 + duplexIClass); 310be8c453dSColin LeMahieu MCInst *MILow = new (getContext()) MCInst; 311be8c453dSColin LeMahieu MCInst *MIHigh = new (getContext()) MCInst; 312a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecodeLow, *MILow, Instruction & 0x1fff, Address, 313a72fad98SKrzysztof Parzyszek this, STI); 314a72fad98SKrzysztof Parzyszek if (Result != DecodeStatus::Success) 315a72fad98SKrzysztof Parzyszek return DecodeStatus::Fail; 316a72fad98SKrzysztof Parzyszek adjustDuplex(*MILow, getContext()); 317a72fad98SKrzysztof Parzyszek Result = decodeInstruction( 318a72fad98SKrzysztof Parzyszek DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff, Address, this, STI); 319a72fad98SKrzysztof Parzyszek if (Result != DecodeStatus::Success) 320a72fad98SKrzysztof Parzyszek return DecodeStatus::Fail; 321a72fad98SKrzysztof Parzyszek adjustDuplex(*MIHigh, getContext()); 322be8c453dSColin LeMahieu MCOperand OPLow = MCOperand::createInst(MILow); 323be8c453dSColin LeMahieu MCOperand OPHigh = MCOperand::createInst(MIHigh); 324be8c453dSColin LeMahieu MI.addOperand(OPLow); 325be8c453dSColin LeMahieu MI.addOperand(OPHigh); 326be8c453dSColin LeMahieu Complete = true; 327be8c453dSColin LeMahieu } else { 328be8c453dSColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 32968d967d9SColin LeMahieu HexagonII::INST_PARSE_PACKET_END) 33068d967d9SColin LeMahieu Complete = true; 3317cd08927SColin LeMahieu 332a72fad98SKrzysztof Parzyszek if (Extender != nullptr) 333a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecoderTableMustExtend32, MI, Instruction, 334a72fad98SKrzysztof Parzyszek Address, this, STI); 335a72fad98SKrzysztof Parzyszek 336a72fad98SKrzysztof Parzyszek if (Result != MCDisassembler::Success) 337a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecoderTable32, MI, Instruction, Address, this, 338a72fad98SKrzysztof Parzyszek STI); 339a72fad98SKrzysztof Parzyszek 340a72fad98SKrzysztof Parzyszek if (Result != MCDisassembler::Success && 341a72fad98SKrzysztof Parzyszek STI.getFeatureBits()[Hexagon::ExtensionHVX]) 342a72fad98SKrzysztof Parzyszek Result = decodeInstruction(DecoderTableEXT_mmvec32, MI, Instruction, 343a72fad98SKrzysztof Parzyszek Address, this, STI); 344a72fad98SKrzysztof Parzyszek 345be8c453dSColin LeMahieu } 34668d967d9SColin LeMahieu 34781707549SColin LeMahieu switch (MI.getOpcode()) { 34881707549SColin LeMahieu case Hexagon::J4_cmpeqn1_f_jumpnv_nt: 34981707549SColin LeMahieu case Hexagon::J4_cmpeqn1_f_jumpnv_t: 35081707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp0_jump_nt: 35181707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp0_jump_t: 35281707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp1_jump_nt: 35381707549SColin LeMahieu case Hexagon::J4_cmpeqn1_fp1_jump_t: 35481707549SColin LeMahieu case Hexagon::J4_cmpeqn1_t_jumpnv_nt: 35581707549SColin LeMahieu case Hexagon::J4_cmpeqn1_t_jumpnv_t: 35681707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp0_jump_nt: 35781707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp0_jump_t: 35881707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp1_jump_nt: 35981707549SColin LeMahieu case Hexagon::J4_cmpeqn1_tp1_jump_t: 36081707549SColin LeMahieu case Hexagon::J4_cmpgtn1_f_jumpnv_nt: 36181707549SColin LeMahieu case Hexagon::J4_cmpgtn1_f_jumpnv_t: 36281707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp0_jump_nt: 36381707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp0_jump_t: 36481707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp1_jump_nt: 36581707549SColin LeMahieu case Hexagon::J4_cmpgtn1_fp1_jump_t: 36681707549SColin LeMahieu case Hexagon::J4_cmpgtn1_t_jumpnv_nt: 36781707549SColin LeMahieu case Hexagon::J4_cmpgtn1_t_jumpnv_t: 36881707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp0_jump_nt: 36981707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp0_jump_t: 37081707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp1_jump_nt: 37181707549SColin LeMahieu case Hexagon::J4_cmpgtn1_tp1_jump_t: 372a72fad98SKrzysztof Parzyszek MI.insert(MI.begin() + 1, 373a72fad98SKrzysztof Parzyszek MCOperand::createExpr(MCConstantExpr::create(-1, getContext()))); 37481707549SColin LeMahieu break; 37581707549SColin LeMahieu default: 37681707549SColin LeMahieu break; 37781707549SColin LeMahieu } 37881707549SColin LeMahieu 3797cd08927SColin LeMahieu if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) { 3807cd08927SColin LeMahieu unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI); 3817cd08927SColin LeMahieu MCOperand &MCO = MI.getOperand(OpIndex); 3827cd08927SColin LeMahieu assert(MCO.isReg() && "New value consumers must be registers"); 3837cd08927SColin LeMahieu unsigned Register = 3847cd08927SColin LeMahieu getContext().getRegisterInfo()->getEncodingValue(MCO.getReg()); 3857cd08927SColin LeMahieu if ((Register & 0x6) == 0) 3867cd08927SColin LeMahieu // HexagonPRM 10.11 Bit 1-2 == 0 is reserved 3877cd08927SColin LeMahieu return MCDisassembler::Fail; 3887cd08927SColin LeMahieu unsigned Lookback = (Register & 0x6) >> 1; 3897cd08927SColin LeMahieu unsigned Offset = 1; 3907cd08927SColin LeMahieu bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI); 3917cd08927SColin LeMahieu auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); 3927cd08927SColin LeMahieu auto i = Instructions.end() - 1; 3937cd08927SColin LeMahieu for (auto n = Instructions.begin() - 1;; --i, ++Offset) { 3947cd08927SColin LeMahieu if (i == n) 3957cd08927SColin LeMahieu // Couldn't find producer 3967cd08927SColin LeMahieu return MCDisassembler::Fail; 3977cd08927SColin LeMahieu if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst())) 3987cd08927SColin LeMahieu // Skip scalars when calculating distances for vectors 3997cd08927SColin LeMahieu ++Lookback; 4007cd08927SColin LeMahieu if (HexagonMCInstrInfo::isImmext(*i->getInst())) 4017cd08927SColin LeMahieu ++Lookback; 4027cd08927SColin LeMahieu if (Offset == Lookback) 4037cd08927SColin LeMahieu break; 4047cd08927SColin LeMahieu } 4057cd08927SColin LeMahieu auto const &Inst = *i->getInst(); 4067cd08927SColin LeMahieu bool SubregBit = (Register & 0x1) != 0; 4077cd08927SColin LeMahieu if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) { 4087cd08927SColin LeMahieu // If subreg bit is set we're selecting the second produced newvalue 4097cd08927SColin LeMahieu unsigned Producer = 4107cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg(); 4117cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 4127cd08927SColin LeMahieu MCO.setReg(Producer); 4137cd08927SColin LeMahieu } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) { 4147cd08927SColin LeMahieu unsigned Producer = 4157cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg(); 4167cd08927SColin LeMahieu if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15) 4177cd08927SColin LeMahieu Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0; 4187cd08927SColin LeMahieu else if (SubregBit) 4196fdfa3dcSColin LeMahieu // Hexagon PRM 10.11 New-value operands 4206fdfa3dcSColin LeMahieu // Nt[0] is reserved and should always be encoded as zero. 4217cd08927SColin LeMahieu return MCDisassembler::Fail; 4227cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 4237cd08927SColin LeMahieu MCO.setReg(Producer); 4247cd08927SColin LeMahieu } else 4257cd08927SColin LeMahieu return MCDisassembler::Fail; 4267cd08927SColin LeMahieu } 4277cd08927SColin LeMahieu 4287cd08927SColin LeMahieu if (Extender != nullptr) { 429a72fad98SKrzysztof Parzyszek MCInst const &Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) 430a72fad98SKrzysztof Parzyszek ? *MI.getOperand(1).getInst() 431a72fad98SKrzysztof Parzyszek : MI; 4327cd08927SColin LeMahieu if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) && 4337cd08927SColin LeMahieu !HexagonMCInstrInfo::isExtended(*MCII, Inst)) 4347cd08927SColin LeMahieu return MCDisassembler::Fail; 4357cd08927SColin LeMahieu } 4365d6f03bdSColin LeMahieu return Result; 43788ebb9e2SColin LeMahieu } 4387cd08927SColin LeMahieu 4397cd08927SColin LeMahieu static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, 440e5e035a3SCraig Topper ArrayRef<MCPhysReg> Table) { 4413da000c0SCraig Topper if (RegNo < Table.size()) { 4427cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Table[RegNo])); 4437cd08927SColin LeMahieu return MCDisassembler::Success; 4443da000c0SCraig Topper } 4453da000c0SCraig Topper 4467cd08927SColin LeMahieu return MCDisassembler::Fail; 4477cd08927SColin LeMahieu } 4487cd08927SColin LeMahieu 4497c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 4507c958713SColin LeMahieu uint64_t Address, 4517c958713SColin LeMahieu const void *Decoder) { 4527c958713SColin LeMahieu return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder); 4537c958713SColin LeMahieu } 4547c958713SColin LeMahieu 4557cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 4567cd08927SColin LeMahieu uint64_t Address, 4577cd08927SColin LeMahieu const void *Decoder) { 458e5e035a3SCraig Topper static const MCPhysReg IntRegDecoderTable[] = { 4597cd08927SColin LeMahieu Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, 4607cd08927SColin LeMahieu Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9, 4617cd08927SColin LeMahieu Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14, 4627cd08927SColin LeMahieu Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 4637cd08927SColin LeMahieu Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24, 4647cd08927SColin LeMahieu Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29, 4657cd08927SColin LeMahieu Hexagon::R30, Hexagon::R31}; 4667cd08927SColin LeMahieu 467e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable); 4687cd08927SColin LeMahieu } 4697c958713SColin LeMahieu 470a72fad98SKrzysztof Parzyszek static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, 471a72fad98SKrzysztof Parzyszek unsigned RegNo, 472a72fad98SKrzysztof Parzyszek uint64_t Address, 473a72fad98SKrzysztof Parzyszek const void *Decoder) { 474a72fad98SKrzysztof Parzyszek static const MCPhysReg GeneralSubRegDecoderTable[] = { 475a72fad98SKrzysztof Parzyszek Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, 476a72fad98SKrzysztof Parzyszek Hexagon::R4, Hexagon::R5, Hexagon::R6, Hexagon::R7, 477a72fad98SKrzysztof Parzyszek Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 478a72fad98SKrzysztof Parzyszek Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, 479a72fad98SKrzysztof Parzyszek }; 480a72fad98SKrzysztof Parzyszek 481a72fad98SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo, GeneralSubRegDecoderTable); 482a72fad98SKrzysztof Parzyszek } 483a72fad98SKrzysztof Parzyszek 4847c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 4857c958713SColin LeMahieu uint64_t /*Address*/, 4867c958713SColin LeMahieu const void *Decoder) { 487e5e035a3SCraig Topper static const MCPhysReg VecRegDecoderTable[] = { 4887c958713SColin LeMahieu Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, 4897c958713SColin LeMahieu Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, 4907c958713SColin LeMahieu Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, 4917c958713SColin LeMahieu Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19, 4927c958713SColin LeMahieu Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24, 4937c958713SColin LeMahieu Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29, 4947c958713SColin LeMahieu Hexagon::V30, Hexagon::V31}; 4957c958713SColin LeMahieu 496e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable); 4977c958713SColin LeMahieu } 4987c958713SColin LeMahieu 4997cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5007cd08927SColin LeMahieu uint64_t /*Address*/, 5017cd08927SColin LeMahieu const void *Decoder) { 502e5e035a3SCraig Topper static const MCPhysReg DoubleRegDecoderTable[] = { 5037cd08927SColin LeMahieu Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, 5047cd08927SColin LeMahieu Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7, 5057cd08927SColin LeMahieu Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11, 5067cd08927SColin LeMahieu Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15}; 5077cd08927SColin LeMahieu 508e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable); 5097cd08927SColin LeMahieu } 5107cd08927SColin LeMahieu 511a72fad98SKrzysztof Parzyszek static DecodeStatus DecodeGeneralDoubleLow8RegsRegisterClass( 512a72fad98SKrzysztof Parzyszek MCInst &Inst, unsigned RegNo, uint64_t /*Address*/, const void *Decoder) { 513a72fad98SKrzysztof Parzyszek static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = { 514a72fad98SKrzysztof Parzyszek Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, 515a72fad98SKrzysztof Parzyszek Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11}; 516a72fad98SKrzysztof Parzyszek 517a72fad98SKrzysztof Parzyszek return DecodeRegisterClass(Inst, RegNo, GeneralDoubleLow8RegDecoderTable); 518a72fad98SKrzysztof Parzyszek } 519a72fad98SKrzysztof Parzyszek 5207c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5217c958713SColin LeMahieu uint64_t /*Address*/, 5227c958713SColin LeMahieu const void *Decoder) { 523e5e035a3SCraig Topper static const MCPhysReg VecDblRegDecoderTable[] = { 5247c958713SColin LeMahieu Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, 5257c958713SColin LeMahieu Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7, 5267c958713SColin LeMahieu Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11, 5277c958713SColin LeMahieu Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15}; 5287c958713SColin LeMahieu 5293da000c0SCraig Topper return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable)); 5307c958713SColin LeMahieu } 5317c958713SColin LeMahieu 5327cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5337cd08927SColin LeMahieu uint64_t /*Address*/, 5347cd08927SColin LeMahieu const void *Decoder) { 535e5e035a3SCraig Topper static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1, 5367cd08927SColin LeMahieu Hexagon::P2, Hexagon::P3}; 5377cd08927SColin LeMahieu 538e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable); 5397cd08927SColin LeMahieu } 5407cd08927SColin LeMahieu 5417c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5427c958713SColin LeMahieu uint64_t /*Address*/, 5437c958713SColin LeMahieu const void *Decoder) { 544e5e035a3SCraig Topper static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1, 5457c958713SColin LeMahieu Hexagon::Q2, Hexagon::Q3}; 5467c958713SColin LeMahieu 547e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable); 5487c958713SColin LeMahieu } 549be8c453dSColin LeMahieu 5507cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5517cd08927SColin LeMahieu uint64_t /*Address*/, 5527cd08927SColin LeMahieu const void *Decoder) { 553f9015e62SKrzysztof Parzyszek using namespace Hexagon; 554*e4fc6ee7SEugene Zelenko 555e5e035a3SCraig Topper static const MCPhysReg CtrlRegDecoderTable[] = { 556f9015e62SKrzysztof Parzyszek /* 0 */ SA0, LC0, SA1, LC1, 557e2603328SKrzysztof Parzyszek /* 4 */ P3_0, C5, M0, M1, 558f9015e62SKrzysztof Parzyszek /* 8 */ USR, PC, UGP, GP, 559ab57c2baSKrzysztof Parzyszek /* 12 */ CS0, CS1, UPCYCLELO, UPCYCLEHI, 560f9015e62SKrzysztof Parzyszek /* 16 */ FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI, 561f9015e62SKrzysztof Parzyszek /* 20 */ 0, 0, 0, 0, 562f9015e62SKrzysztof Parzyszek /* 24 */ 0, 0, 0, 0, 563f9015e62SKrzysztof Parzyszek /* 28 */ 0, 0, UTIMERLO, UTIMERHI 5647cd08927SColin LeMahieu }; 5657cd08927SColin LeMahieu 5666261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlRegDecoderTable)) 5677cd08927SColin LeMahieu return MCDisassembler::Fail; 5687cd08927SColin LeMahieu 569f9015e62SKrzysztof Parzyszek static_assert(NoRegister == 0, "Expecting NoRegister to be 0"); 570f9015e62SKrzysztof Parzyszek if (CtrlRegDecoderTable[RegNo] == NoRegister) 5717cd08927SColin LeMahieu return MCDisassembler::Fail; 5727cd08927SColin LeMahieu 5737cd08927SColin LeMahieu unsigned Register = CtrlRegDecoderTable[RegNo]; 5747cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 5757cd08927SColin LeMahieu return MCDisassembler::Success; 5767cd08927SColin LeMahieu } 5777cd08927SColin LeMahieu 5787cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 5797cd08927SColin LeMahieu uint64_t /*Address*/, 5807cd08927SColin LeMahieu const void *Decoder) { 581f9015e62SKrzysztof Parzyszek using namespace Hexagon; 582*e4fc6ee7SEugene Zelenko 583e5e035a3SCraig Topper static const MCPhysReg CtrlReg64DecoderTable[] = { 584f9015e62SKrzysztof Parzyszek /* 0 */ C1_0, 0, C3_2, 0, 585f9015e62SKrzysztof Parzyszek /* 4 */ C5_4, 0, C7_6, 0, 586f9015e62SKrzysztof Parzyszek /* 8 */ C9_8, 0, C11_10, 0, 587ab57c2baSKrzysztof Parzyszek /* 12 */ CS, 0, UPCYCLE, 0, 588f9015e62SKrzysztof Parzyszek /* 16 */ C17_16, 0, PKTCOUNT, 0, 589f9015e62SKrzysztof Parzyszek /* 20 */ 0, 0, 0, 0, 590f9015e62SKrzysztof Parzyszek /* 24 */ 0, 0, 0, 0, 591f9015e62SKrzysztof Parzyszek /* 28 */ 0, 0, UTIMER, 0 5927cd08927SColin LeMahieu }; 5937cd08927SColin LeMahieu 5946261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlReg64DecoderTable)) 5957cd08927SColin LeMahieu return MCDisassembler::Fail; 5967cd08927SColin LeMahieu 597f9015e62SKrzysztof Parzyszek static_assert(NoRegister == 0, "Expecting NoRegister to be 0"); 598f9015e62SKrzysztof Parzyszek if (CtrlReg64DecoderTable[RegNo] == NoRegister) 5997cd08927SColin LeMahieu return MCDisassembler::Fail; 6007cd08927SColin LeMahieu 6017cd08927SColin LeMahieu unsigned Register = CtrlReg64DecoderTable[RegNo]; 6027cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 6037cd08927SColin LeMahieu return MCDisassembler::Success; 6047cd08927SColin LeMahieu } 6057cd08927SColin LeMahieu 6067cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, 6077cd08927SColin LeMahieu uint64_t /*Address*/, 6087cd08927SColin LeMahieu const void *Decoder) { 6097cd08927SColin LeMahieu unsigned Register = 0; 6107cd08927SColin LeMahieu switch (RegNo) { 6117cd08927SColin LeMahieu case 0: 6127cd08927SColin LeMahieu Register = Hexagon::M0; 6137cd08927SColin LeMahieu break; 6147cd08927SColin LeMahieu case 1: 6157cd08927SColin LeMahieu Register = Hexagon::M1; 6167cd08927SColin LeMahieu break; 6177cd08927SColin LeMahieu default: 6187cd08927SColin LeMahieu return MCDisassembler::Fail; 6197cd08927SColin LeMahieu } 6207cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 6217cd08927SColin LeMahieu return MCDisassembler::Success; 6227cd08927SColin LeMahieu } 6237cd08927SColin LeMahieu 6247cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 6257cd08927SColin LeMahieu uint64_t /*Address*/, 6267cd08927SColin LeMahieu const void *Decoder) { 6277cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 628a72fad98SKrzysztof Parzyszek int64_t FullValue = 629a72fad98SKrzysztof Parzyszek fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, tmp); 6307cd08927SColin LeMahieu assert(FullValue >= 0 && "Negative in unsigned decoder"); 6317cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext()); 6327cd08927SColin LeMahieu return MCDisassembler::Success; 6337cd08927SColin LeMahieu } 6347cd08927SColin LeMahieu 635a72fad98SKrzysztof Parzyszek static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, 636a72fad98SKrzysztof Parzyszek uint64_t /*Address*/, const void *Decoder) { 637a72fad98SKrzysztof Parzyszek HexagonDisassembler const &Disassembler = disassembler(Decoder); 638a72fad98SKrzysztof Parzyszek unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); 639a72fad98SKrzysztof Parzyszek tmp = SignExtend64(tmp, Bits); 640a72fad98SKrzysztof Parzyszek signedDecoder<32>(MI, tmp, Decoder); 641a72fad98SKrzysztof Parzyszek return MCDisassembler::Success; 642a72fad98SKrzysztof Parzyszek } 643a72fad98SKrzysztof Parzyszek 6447cd08927SColin LeMahieu // custom decoder for various jump/call immediates 6457cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 6467cd08927SColin LeMahieu const void *Decoder) { 6477cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6487cd08927SColin LeMahieu unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); 6497cd08927SColin LeMahieu // r13_2 is not extendable, so if there are no extent bits, it's r13_2 6507cd08927SColin LeMahieu if (Bits == 0) 6517cd08927SColin LeMahieu Bits = 15; 652a72fad98SKrzysztof Parzyszek uint32_t FullValue = 653a72fad98SKrzysztof Parzyszek fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, 654a72fad98SKrzysztof Parzyszek SignExtend64(tmp, Bits)); 6557cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue) + Address; 656a72fad98SKrzysztof Parzyszek if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 0, 4)) 6577cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); 6587cd08927SColin LeMahieu return MCDisassembler::Success; 6597cd08927SColin LeMahieu } 660