188ebb9e2SColin LeMahieu //===-- 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" 1588ebb9e2SColin LeMahieu #include "MCTargetDesc/HexagonMCTargetDesc.h" 167cd08927SColin LeMahieu #include "MCTargetDesc/HexagonMCInstrInfo.h" 177cd08927SColin LeMahieu #include "MCTargetDesc/HexagonInstPrinter.h" 187cd08927SColin LeMahieu #include "llvm/ADT/StringExtras.h" 19f57c1977SBenjamin Kramer #include "llvm/MC/MCDisassembler/MCDisassembler.h" 207cd08927SColin LeMahieu #include "llvm/MC/MCContext.h" 2188ebb9e2SColin LeMahieu #include "llvm/MC/MCExpr.h" 2288ebb9e2SColin LeMahieu #include "llvm/MC/MCFixedLenDisassembler.h" 2388ebb9e2SColin LeMahieu #include "llvm/MC/MCInst.h" 2488ebb9e2SColin LeMahieu #include "llvm/MC/MCInstrDesc.h" 257cd08927SColin LeMahieu #include "llvm/MC/MCInstrInfo.h" 2688ebb9e2SColin LeMahieu #include "llvm/MC/MCSubtargetInfo.h" 2788ebb9e2SColin LeMahieu #include "llvm/Support/Debug.h" 2888ebb9e2SColin LeMahieu #include "llvm/Support/ErrorHandling.h" 2988ebb9e2SColin LeMahieu #include "llvm/Support/LEB128.h" 307cd08927SColin LeMahieu #include "llvm/Support/MemoryObject.h" 31d9903888SChandler Carruth #include "llvm/Support/raw_ostream.h" 327cd08927SColin LeMahieu #include "llvm/Support/TargetRegistry.h" 3388ebb9e2SColin LeMahieu 3488ebb9e2SColin LeMahieu using namespace llvm; 3568d967d9SColin LeMahieu using namespace Hexagon; 3688ebb9e2SColin LeMahieu 377cd08927SColin LeMahieu typedef MCDisassembler::DecodeStatus DecodeStatus; 3888ebb9e2SColin LeMahieu 3988ebb9e2SColin LeMahieu namespace { 4088ebb9e2SColin LeMahieu /// \brief Hexagon disassembler for all Hexagon platforms. 4188ebb9e2SColin LeMahieu class HexagonDisassembler : public MCDisassembler { 4288ebb9e2SColin LeMahieu public: 437cd08927SColin LeMahieu std::unique_ptr<MCInstrInfo const> const MCII; 4468d967d9SColin LeMahieu std::unique_ptr<MCInst *> CurrentBundle; 457cd08927SColin LeMahieu HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, 467cd08927SColin LeMahieu MCInstrInfo const *MCII) 477cd08927SColin LeMahieu : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *) {} 4888ebb9e2SColin LeMahieu 4968d967d9SColin LeMahieu DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB, 5068d967d9SColin LeMahieu ArrayRef<uint8_t> Bytes, uint64_t Address, 5168d967d9SColin LeMahieu raw_ostream &VStream, raw_ostream &CStream, 5268d967d9SColin LeMahieu bool &Complete) const; 534aa6bea7SRafael Espindola DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, 547fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes, uint64_t Address, 554aa6bea7SRafael Espindola raw_ostream &VStream, 564aa6bea7SRafael Espindola raw_ostream &CStream) const override; 577cd08927SColin LeMahieu 587cd08927SColin LeMahieu void adjustExtendedInstructions(MCInst &MCI, MCInst const &MCB) const; 597cd08927SColin LeMahieu void addSubinstOperands(MCInst *MI, unsigned opcode, unsigned inst) const; 6088ebb9e2SColin LeMahieu }; 61f00654e3SAlexander Kornienko } 6288ebb9e2SColin LeMahieu 637cd08927SColin LeMahieu // Forward declare these because the auto-generated code will reference them. 647cd08927SColin LeMahieu // Definitions are further down. 657cd08927SColin LeMahieu 667cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 67be8c453dSColin LeMahieu uint64_t Address, 68be8c453dSColin LeMahieu const void *Decoder); 697c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 707c958713SColin LeMahieu uint64_t Address, 717c958713SColin LeMahieu const void *Decoder); 727c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 737c958713SColin LeMahieu uint64_t Address, 747c958713SColin LeMahieu const void *Decoder); 757cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 767cd08927SColin LeMahieu uint64_t Address, 777cd08927SColin LeMahieu const void *Decoder); 787c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 797c958713SColin LeMahieu uint64_t Address, 807c958713SColin LeMahieu const void *Decoder); 817cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 827cd08927SColin LeMahieu uint64_t Address, 837cd08927SColin LeMahieu const void *Decoder); 847c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 857c958713SColin LeMahieu uint64_t Address, 867c958713SColin LeMahieu const void *Decoder); 87f3db884eSColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 88be8c453dSColin LeMahieu uint64_t Address, 89be8c453dSColin LeMahieu const void *Decoder); 907cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, 917cd08927SColin LeMahieu uint64_t Address, 927cd08927SColin LeMahieu const void *Decoder); 93404d5b24SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 94be8c453dSColin LeMahieu uint64_t Address, 957cd08927SColin LeMahieu const void *Decoder); 967cd08927SColin LeMahieu 977cd08927SColin LeMahieu static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn); 987cd08927SColin LeMahieu static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn, 99be8c453dSColin LeMahieu void const *Decoder); 100be8c453dSColin LeMahieu 101be8c453dSColin LeMahieu static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op, 102be8c453dSColin LeMahieu raw_ostream &os); 103f3db884eSColin LeMahieu 1047cd08927SColin LeMahieu static unsigned getRegFromSubinstEncoding(unsigned encoded_reg); 1057cd08927SColin LeMahieu 1067cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 1077cd08927SColin LeMahieu uint64_t Address, const void *Decoder); 1081e9d1d76SColin LeMahieu static DecodeStatus s16ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1091e9d1d76SColin LeMahieu const void *Decoder); 1101e9d1d76SColin LeMahieu static DecodeStatus s12ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1111e9d1d76SColin LeMahieu const void *Decoder); 1121e9d1d76SColin LeMahieu static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1131e9d1d76SColin LeMahieu const void *Decoder); 1141e9d1d76SColin LeMahieu static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1151e9d1d76SColin LeMahieu const void *Decoder); 1161e9d1d76SColin LeMahieu static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1171e9d1d76SColin LeMahieu const void *Decoder); 1181e9d1d76SColin LeMahieu static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1191e9d1d76SColin LeMahieu const void *Decoder); 1201e9d1d76SColin LeMahieu static DecodeStatus s10ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1211e9d1d76SColin LeMahieu const void *Decoder); 1221e9d1d76SColin LeMahieu static DecodeStatus s8ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1231e9d1d76SColin LeMahieu const void *Decoder); 1241e9d1d76SColin LeMahieu static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1251e9d1d76SColin LeMahieu const void *Decoder); 1261e9d1d76SColin LeMahieu static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1271e9d1d76SColin LeMahieu const void *Decoder); 1281e9d1d76SColin LeMahieu static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1291e9d1d76SColin LeMahieu const void *Decoder); 1301e9d1d76SColin LeMahieu static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1311e9d1d76SColin LeMahieu const void *Decoder); 1321e9d1d76SColin LeMahieu static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1331e9d1d76SColin LeMahieu const void *Decoder); 1347c958713SColin LeMahieu static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1357c958713SColin LeMahieu const void *Decoder); 1367c958713SColin LeMahieu static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1377c958713SColin LeMahieu const void *Decoder); 1387cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1397cd08927SColin LeMahieu const void *Decoder); 140efa74e02SColin LeMahieu 14188ebb9e2SColin LeMahieu #include "HexagonGenDisassemblerTables.inc" 14288ebb9e2SColin LeMahieu 1437cd08927SColin LeMahieu static MCDisassembler *createHexagonDisassembler(const Target &T, 1447cd08927SColin LeMahieu const MCSubtargetInfo &STI, 14588ebb9e2SColin LeMahieu MCContext &Ctx) { 1467cd08927SColin LeMahieu return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo()); 14788ebb9e2SColin LeMahieu } 14888ebb9e2SColin LeMahieu 14988ebb9e2SColin LeMahieu extern "C" void LLVMInitializeHexagonDisassembler() { 15088ebb9e2SColin LeMahieu TargetRegistry::RegisterMCDisassembler(TheHexagonTarget, 15188ebb9e2SColin LeMahieu createHexagonDisassembler); 15288ebb9e2SColin LeMahieu } 15388ebb9e2SColin LeMahieu 15488ebb9e2SColin LeMahieu DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size, 1557fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes, 15688ebb9e2SColin LeMahieu uint64_t Address, 15788ebb9e2SColin LeMahieu raw_ostream &os, 15888ebb9e2SColin LeMahieu raw_ostream &cs) const { 15968d967d9SColin LeMahieu DecodeStatus Result = DecodeStatus::Success; 16068d967d9SColin LeMahieu bool Complete = false; 16168d967d9SColin LeMahieu Size = 0; 1624aa6bea7SRafael Espindola 16368d967d9SColin LeMahieu *CurrentBundle = &MI; 164f0af6e52SColin LeMahieu MI = HexagonMCInstrInfo::createBundle(); 165be8c453dSColin LeMahieu while (Result == Success && Complete == false) { 16668d967d9SColin LeMahieu if (Bytes.size() < HEXAGON_INSTR_SIZE) 16768d967d9SColin LeMahieu return MCDisassembler::Fail; 16868d967d9SColin LeMahieu MCInst *Inst = new (getContext()) MCInst; 16968d967d9SColin LeMahieu Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete); 17068d967d9SColin LeMahieu MI.addOperand(MCOperand::createInst(Inst)); 17168d967d9SColin LeMahieu Size += HEXAGON_INSTR_SIZE; 17268d967d9SColin LeMahieu Bytes = Bytes.slice(HEXAGON_INSTR_SIZE); 17368d967d9SColin LeMahieu } 1747cd08927SColin LeMahieu if(Result == MCDisassembler::Fail) 17568d967d9SColin LeMahieu return Result; 1767cd08927SColin LeMahieu HexagonMCChecker Checker (*MCII, STI, MI, MI, *getContext().getRegisterInfo()); 1777cd08927SColin LeMahieu if(!Checker.check()) 1787cd08927SColin LeMahieu return MCDisassembler::Fail; 1797cd08927SColin LeMahieu return MCDisassembler::Success; 1807cd08927SColin LeMahieu } 1817cd08927SColin LeMahieu 1827cd08927SColin LeMahieu namespace { 1837cd08927SColin LeMahieu HexagonDisassembler const &disassembler(void const *Decoder) { 1847cd08927SColin LeMahieu return *static_cast<HexagonDisassembler const *>(Decoder); 1857cd08927SColin LeMahieu } 1867cd08927SColin LeMahieu MCContext &contextFromDecoder(void const *Decoder) { 1877cd08927SColin LeMahieu return disassembler(Decoder).getContext(); 1887cd08927SColin LeMahieu } 18968d967d9SColin LeMahieu } 19068d967d9SColin LeMahieu 19168d967d9SColin LeMahieu DecodeStatus HexagonDisassembler::getSingleInstruction( 19268d967d9SColin LeMahieu MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address, 19368d967d9SColin LeMahieu raw_ostream &os, raw_ostream &cs, bool &Complete) const { 19468d967d9SColin LeMahieu assert(Bytes.size() >= HEXAGON_INSTR_SIZE); 19568d967d9SColin LeMahieu 19668d967d9SColin LeMahieu uint32_t Instruction = 1977cd08927SColin LeMahieu (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0); 19888ebb9e2SColin LeMahieu 19968d967d9SColin LeMahieu auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB); 20068d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 20168d967d9SColin LeMahieu HexagonII::INST_PARSE_LOOP_END) { 20268d967d9SColin LeMahieu if (BundleSize == 0) 20368d967d9SColin LeMahieu HexagonMCInstrInfo::setInnerLoop(MCB); 20468d967d9SColin LeMahieu else if (BundleSize == 1) 20568d967d9SColin LeMahieu HexagonMCInstrInfo::setOuterLoop(MCB); 20668d967d9SColin LeMahieu else 20768d967d9SColin LeMahieu return DecodeStatus::Fail; 20868d967d9SColin LeMahieu } 20968d967d9SColin LeMahieu 21068d967d9SColin LeMahieu DecodeStatus Result = DecodeStatus::Success; 21168d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 212be8c453dSColin LeMahieu HexagonII::INST_PARSE_DUPLEX) { 213be8c453dSColin LeMahieu // Determine the instruction class of each instruction in the duplex. 214be8c453dSColin LeMahieu unsigned duplexIClass, IClassLow, IClassHigh; 215be8c453dSColin LeMahieu 216be8c453dSColin LeMahieu duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1); 217be8c453dSColin LeMahieu switch (duplexIClass) { 218be8c453dSColin LeMahieu default: 219be8c453dSColin LeMahieu return MCDisassembler::Fail; 220be8c453dSColin LeMahieu case 0: 221be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L1; 222be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 223be8c453dSColin LeMahieu break; 224be8c453dSColin LeMahieu case 1: 225be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L2; 226be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 227be8c453dSColin LeMahieu break; 228be8c453dSColin LeMahieu case 2: 229be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L2; 230be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L2; 231be8c453dSColin LeMahieu break; 232be8c453dSColin LeMahieu case 3: 233be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_A; 234be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 235be8c453dSColin LeMahieu break; 236be8c453dSColin LeMahieu case 4: 237be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L1; 238be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 239be8c453dSColin LeMahieu break; 240be8c453dSColin LeMahieu case 5: 241be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L2; 242be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 243be8c453dSColin LeMahieu break; 244be8c453dSColin LeMahieu case 6: 245be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 246be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 247be8c453dSColin LeMahieu break; 248be8c453dSColin LeMahieu case 7: 249be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 250be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 251be8c453dSColin LeMahieu break; 252be8c453dSColin LeMahieu case 8: 253be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 254be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 255be8c453dSColin LeMahieu break; 256be8c453dSColin LeMahieu case 9: 257be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 258be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L2; 259be8c453dSColin LeMahieu break; 260be8c453dSColin LeMahieu case 10: 261be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 262be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_S1; 263be8c453dSColin LeMahieu break; 264be8c453dSColin LeMahieu case 11: 265be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 266be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_S1; 267be8c453dSColin LeMahieu break; 268be8c453dSColin LeMahieu case 12: 269be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 270be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 271be8c453dSColin LeMahieu break; 272be8c453dSColin LeMahieu case 13: 273be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 274be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L2; 275be8c453dSColin LeMahieu break; 276be8c453dSColin LeMahieu case 14: 277be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 278be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_S2; 279be8c453dSColin LeMahieu break; 280be8c453dSColin LeMahieu } 281be8c453dSColin LeMahieu 282be8c453dSColin LeMahieu // Set the MCInst to be a duplex instruction. Which one doesn't matter. 283be8c453dSColin LeMahieu MI.setOpcode(Hexagon::DuplexIClass0); 284be8c453dSColin LeMahieu 285be8c453dSColin LeMahieu // Decode each instruction in the duplex. 286be8c453dSColin LeMahieu // Create an MCInst for each instruction. 287be8c453dSColin LeMahieu unsigned instLow = Instruction & 0x1fff; 288be8c453dSColin LeMahieu unsigned instHigh = (Instruction >> 16) & 0x1fff; 289be8c453dSColin LeMahieu unsigned opLow; 290be8c453dSColin LeMahieu if (GetSubinstOpcode(IClassLow, instLow, opLow, os) != 291be8c453dSColin LeMahieu MCDisassembler::Success) 292be8c453dSColin LeMahieu return MCDisassembler::Fail; 293be8c453dSColin LeMahieu unsigned opHigh; 294be8c453dSColin LeMahieu if (GetSubinstOpcode(IClassHigh, instHigh, opHigh, os) != 295be8c453dSColin LeMahieu MCDisassembler::Success) 296be8c453dSColin LeMahieu return MCDisassembler::Fail; 297be8c453dSColin LeMahieu MCInst *MILow = new (getContext()) MCInst; 298be8c453dSColin LeMahieu MILow->setOpcode(opLow); 299be8c453dSColin LeMahieu MCInst *MIHigh = new (getContext()) MCInst; 300be8c453dSColin LeMahieu MIHigh->setOpcode(opHigh); 3017cd08927SColin LeMahieu addSubinstOperands(MILow, opLow, instLow); 3027cd08927SColin LeMahieu addSubinstOperands(MIHigh, opHigh, instHigh); 303be8c453dSColin LeMahieu // see ConvertToSubInst() in 304be8c453dSColin LeMahieu // lib/Target/Hexagon/MCTargetDesc/HexagonMCDuplexInfo.cpp 305be8c453dSColin LeMahieu 306be8c453dSColin LeMahieu // Add the duplex instruction MCInsts as operands to the passed in MCInst. 307be8c453dSColin LeMahieu MCOperand OPLow = MCOperand::createInst(MILow); 308be8c453dSColin LeMahieu MCOperand OPHigh = MCOperand::createInst(MIHigh); 309be8c453dSColin LeMahieu MI.addOperand(OPLow); 310be8c453dSColin LeMahieu MI.addOperand(OPHigh); 311be8c453dSColin LeMahieu Complete = true; 312be8c453dSColin LeMahieu } else { 313be8c453dSColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 31468d967d9SColin LeMahieu HexagonII::INST_PARSE_PACKET_END) 31568d967d9SColin LeMahieu Complete = true; 31668d967d9SColin LeMahieu // Calling the auto-generated decoder function. 31768d967d9SColin LeMahieu Result = 31868d967d9SColin LeMahieu decodeInstruction(DecoderTable32, MI, Instruction, Address, this, STI); 3197cd08927SColin LeMahieu 3207cd08927SColin LeMahieu // If a, "standard" insn isn't found check special cases. 3217cd08927SColin LeMahieu if (MCDisassembler::Success != Result || 3227cd08927SColin LeMahieu MI.getOpcode() == Hexagon::A4_ext) { 3237cd08927SColin LeMahieu Result = decodeImmext(MI, Instruction, this); 3247cd08927SColin LeMahieu if (MCDisassembler::Success != Result) { 3257cd08927SColin LeMahieu Result = decodeSpecial(MI, Instruction); 3267cd08927SColin LeMahieu } 3277cd08927SColin LeMahieu } else { 3287cd08927SColin LeMahieu // If the instruction is a compound instruction, register values will 3297cd08927SColin LeMahieu // follow the duplex model, so the register values in the MCInst are 3307cd08927SColin LeMahieu // incorrect. If the instruction is a compound, loop through the 3317cd08927SColin LeMahieu // operands and change registers appropriately. 3327cd08927SColin LeMahieu if (llvm::HexagonMCInstrInfo::getType(*MCII, MI) == 3337cd08927SColin LeMahieu HexagonII::TypeCOMPOUND) { 3347cd08927SColin LeMahieu for (MCInst::iterator i = MI.begin(), last = MI.end(); i < last; ++i) { 3357cd08927SColin LeMahieu if (i->isReg()) { 3367cd08927SColin LeMahieu unsigned reg = i->getReg() - Hexagon::R0; 3377cd08927SColin LeMahieu i->setReg(getRegFromSubinstEncoding(reg)); 3387cd08927SColin LeMahieu } 3397cd08927SColin LeMahieu } 3407cd08927SColin LeMahieu } 3417cd08927SColin LeMahieu } 342be8c453dSColin LeMahieu } 34368d967d9SColin LeMahieu 3447cd08927SColin LeMahieu if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) { 3457cd08927SColin LeMahieu unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI); 3467cd08927SColin LeMahieu MCOperand &MCO = MI.getOperand(OpIndex); 3477cd08927SColin LeMahieu assert(MCO.isReg() && "New value consumers must be registers"); 3487cd08927SColin LeMahieu unsigned Register = 3497cd08927SColin LeMahieu getContext().getRegisterInfo()->getEncodingValue(MCO.getReg()); 3507cd08927SColin LeMahieu if ((Register & 0x6) == 0) 3517cd08927SColin LeMahieu // HexagonPRM 10.11 Bit 1-2 == 0 is reserved 3527cd08927SColin LeMahieu return MCDisassembler::Fail; 3537cd08927SColin LeMahieu unsigned Lookback = (Register & 0x6) >> 1; 3547cd08927SColin LeMahieu unsigned Offset = 1; 3557cd08927SColin LeMahieu bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI); 3567cd08927SColin LeMahieu auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); 3577cd08927SColin LeMahieu auto i = Instructions.end() - 1; 3587cd08927SColin LeMahieu for (auto n = Instructions.begin() - 1;; --i, ++Offset) { 3597cd08927SColin LeMahieu if (i == n) 3607cd08927SColin LeMahieu // Couldn't find producer 3617cd08927SColin LeMahieu return MCDisassembler::Fail; 3627cd08927SColin LeMahieu if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst())) 3637cd08927SColin LeMahieu // Skip scalars when calculating distances for vectors 3647cd08927SColin LeMahieu ++Lookback; 3657cd08927SColin LeMahieu if (HexagonMCInstrInfo::isImmext(*i->getInst())) 3667cd08927SColin LeMahieu ++Lookback; 3677cd08927SColin LeMahieu if (Offset == Lookback) 3687cd08927SColin LeMahieu break; 3697cd08927SColin LeMahieu } 3707cd08927SColin LeMahieu auto const &Inst = *i->getInst(); 3717cd08927SColin LeMahieu bool SubregBit = (Register & 0x1) != 0; 3727cd08927SColin LeMahieu if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) { 3737cd08927SColin LeMahieu // If subreg bit is set we're selecting the second produced newvalue 3747cd08927SColin LeMahieu unsigned Producer = 3757cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg(); 3767cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 3777cd08927SColin LeMahieu MCO.setReg(Producer); 3787cd08927SColin LeMahieu } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) { 3797cd08927SColin LeMahieu unsigned Producer = 3807cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg(); 3817cd08927SColin LeMahieu if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15) 3827cd08927SColin LeMahieu Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0; 3837cd08927SColin LeMahieu else if (SubregBit) 3846fdfa3dcSColin LeMahieu // Hexagon PRM 10.11 New-value operands 3856fdfa3dcSColin LeMahieu // Nt[0] is reserved and should always be encoded as zero. 3867cd08927SColin LeMahieu return MCDisassembler::Fail; 3877cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 3887cd08927SColin LeMahieu MCO.setReg(Producer); 3897cd08927SColin LeMahieu } else 3907cd08927SColin LeMahieu return MCDisassembler::Fail; 3917cd08927SColin LeMahieu } 3927cd08927SColin LeMahieu 3937cd08927SColin LeMahieu adjustExtendedInstructions(MI, MCB); 3947cd08927SColin LeMahieu MCInst const *Extender = 3957cd08927SColin LeMahieu HexagonMCInstrInfo::extenderForIndex(MCB, 3967cd08927SColin LeMahieu HexagonMCInstrInfo::bundleSize(MCB)); 3977cd08927SColin LeMahieu if(Extender != nullptr) { 3987cd08927SColin LeMahieu MCInst const & Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) ? 3997cd08927SColin LeMahieu *MI.getOperand(1).getInst() : MI; 4007cd08927SColin LeMahieu if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) && 4017cd08927SColin LeMahieu !HexagonMCInstrInfo::isExtended(*MCII, Inst)) 4027cd08927SColin LeMahieu return MCDisassembler::Fail; 4037cd08927SColin LeMahieu } 4045d6f03bdSColin LeMahieu return Result; 40588ebb9e2SColin LeMahieu } 4067cd08927SColin LeMahieu 4077cd08927SColin LeMahieu void HexagonDisassembler::adjustExtendedInstructions(MCInst &MCI, 4087cd08927SColin LeMahieu MCInst const &MCB) const { 4097cd08927SColin LeMahieu if (!HexagonMCInstrInfo::hasExtenderForIndex( 4107cd08927SColin LeMahieu MCB, HexagonMCInstrInfo::bundleSize(MCB))) { 4117cd08927SColin LeMahieu unsigned opcode; 4127cd08927SColin LeMahieu // This code is used by the disassembler to disambiguate between GP 4137cd08927SColin LeMahieu // relative and absolute addressing instructions since they both have 4147cd08927SColin LeMahieu // same encoding bits. However, an absolute addressing instruction must 4157cd08927SColin LeMahieu // follow an immediate extender. Disassembler alwaus select absolute 4167cd08927SColin LeMahieu // addressing instructions first and uses this code to change them into 4177cd08927SColin LeMahieu // GP relative instruction in the absence of the corresponding immediate 4187cd08927SColin LeMahieu // extender. 4197cd08927SColin LeMahieu switch (MCI.getOpcode()) { 4209675de5bSColin LeMahieu case Hexagon::PS_storerbabs: 4217cd08927SColin LeMahieu opcode = Hexagon::S2_storerbgp; 4227cd08927SColin LeMahieu break; 4239675de5bSColin LeMahieu case Hexagon::PS_storerhabs: 4247cd08927SColin LeMahieu opcode = Hexagon::S2_storerhgp; 4257cd08927SColin LeMahieu break; 4269675de5bSColin LeMahieu case Hexagon::PS_storerfabs: 4277cd08927SColin LeMahieu opcode = Hexagon::S2_storerfgp; 4287cd08927SColin LeMahieu break; 4299675de5bSColin LeMahieu case Hexagon::PS_storeriabs: 4307cd08927SColin LeMahieu opcode = Hexagon::S2_storerigp; 4317cd08927SColin LeMahieu break; 4329675de5bSColin LeMahieu case Hexagon::PS_storerbnewabs: 4337cd08927SColin LeMahieu opcode = Hexagon::S2_storerbnewgp; 4347cd08927SColin LeMahieu break; 4359675de5bSColin LeMahieu case Hexagon::PS_storerhnewabs: 4367cd08927SColin LeMahieu opcode = Hexagon::S2_storerhnewgp; 4377cd08927SColin LeMahieu break; 4389675de5bSColin LeMahieu case Hexagon::PS_storerinewabs: 4397cd08927SColin LeMahieu opcode = Hexagon::S2_storerinewgp; 4407cd08927SColin LeMahieu break; 4419675de5bSColin LeMahieu case Hexagon::PS_storerdabs: 4427cd08927SColin LeMahieu opcode = Hexagon::S2_storerdgp; 4437cd08927SColin LeMahieu break; 4449675de5bSColin LeMahieu case Hexagon::PS_loadrbabs: 4457cd08927SColin LeMahieu opcode = Hexagon::L2_loadrbgp; 4467cd08927SColin LeMahieu break; 4479675de5bSColin LeMahieu case Hexagon::PS_loadrubabs: 4487cd08927SColin LeMahieu opcode = Hexagon::L2_loadrubgp; 4497cd08927SColin LeMahieu break; 4509675de5bSColin LeMahieu case Hexagon::PS_loadrhabs: 4517cd08927SColin LeMahieu opcode = Hexagon::L2_loadrhgp; 4527cd08927SColin LeMahieu break; 4539675de5bSColin LeMahieu case Hexagon::PS_loadruhabs: 4547cd08927SColin LeMahieu opcode = Hexagon::L2_loadruhgp; 4557cd08927SColin LeMahieu break; 4569675de5bSColin LeMahieu case Hexagon::PS_loadriabs: 4577cd08927SColin LeMahieu opcode = Hexagon::L2_loadrigp; 4587cd08927SColin LeMahieu break; 4599675de5bSColin LeMahieu case Hexagon::PS_loadrdabs: 4607cd08927SColin LeMahieu opcode = Hexagon::L2_loadrdgp; 4617cd08927SColin LeMahieu break; 4627cd08927SColin LeMahieu default: 4637cd08927SColin LeMahieu opcode = MCI.getOpcode(); 4647cd08927SColin LeMahieu } 4657cd08927SColin LeMahieu MCI.setOpcode(opcode); 4667cd08927SColin LeMahieu } 4677cd08927SColin LeMahieu } 4687cd08927SColin LeMahieu 4697cd08927SColin LeMahieu namespace llvm { 4707cd08927SColin LeMahieu extern const MCInstrDesc HexagonInsts[]; 4717cd08927SColin LeMahieu } 4727cd08927SColin LeMahieu 4737cd08927SColin LeMahieu static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, 474e5e035a3SCraig Topper ArrayRef<MCPhysReg> Table) { 4753da000c0SCraig Topper if (RegNo < Table.size()) { 4767cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Table[RegNo])); 4777cd08927SColin LeMahieu return MCDisassembler::Success; 4783da000c0SCraig Topper } 4793da000c0SCraig Topper 4807cd08927SColin LeMahieu return MCDisassembler::Fail; 4817cd08927SColin LeMahieu } 4827cd08927SColin LeMahieu 4837c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 4847c958713SColin LeMahieu uint64_t Address, 4857c958713SColin LeMahieu const void *Decoder) { 4867c958713SColin LeMahieu return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder); 4877c958713SColin LeMahieu } 4887c958713SColin LeMahieu 4897cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 4907cd08927SColin LeMahieu uint64_t Address, 4917cd08927SColin LeMahieu const void *Decoder) { 492e5e035a3SCraig Topper static const MCPhysReg IntRegDecoderTable[] = { 4937cd08927SColin LeMahieu Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, 4947cd08927SColin LeMahieu Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9, 4957cd08927SColin LeMahieu Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14, 4967cd08927SColin LeMahieu Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 4977cd08927SColin LeMahieu Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24, 4987cd08927SColin LeMahieu Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29, 4997cd08927SColin LeMahieu Hexagon::R30, Hexagon::R31}; 5007cd08927SColin LeMahieu 501e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable); 5027cd08927SColin LeMahieu } 5037c958713SColin LeMahieu 5047c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5057c958713SColin LeMahieu uint64_t /*Address*/, 5067c958713SColin LeMahieu const void *Decoder) { 507e5e035a3SCraig Topper static const MCPhysReg VecRegDecoderTable[] = { 5087c958713SColin LeMahieu Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, 5097c958713SColin LeMahieu Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, 5107c958713SColin LeMahieu Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, 5117c958713SColin LeMahieu Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19, 5127c958713SColin LeMahieu Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24, 5137c958713SColin LeMahieu Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29, 5147c958713SColin LeMahieu Hexagon::V30, Hexagon::V31}; 5157c958713SColin LeMahieu 516e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable); 5177c958713SColin LeMahieu } 5187c958713SColin LeMahieu 5197cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5207cd08927SColin LeMahieu uint64_t /*Address*/, 5217cd08927SColin LeMahieu const void *Decoder) { 522e5e035a3SCraig Topper static const MCPhysReg DoubleRegDecoderTable[] = { 5237cd08927SColin LeMahieu Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, 5247cd08927SColin LeMahieu Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7, 5257cd08927SColin LeMahieu Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11, 5267cd08927SColin LeMahieu Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15}; 5277cd08927SColin LeMahieu 528e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable); 5297cd08927SColin LeMahieu } 5307cd08927SColin LeMahieu 5317c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5327c958713SColin LeMahieu uint64_t /*Address*/, 5337c958713SColin LeMahieu const void *Decoder) { 534e5e035a3SCraig Topper static const MCPhysReg VecDblRegDecoderTable[] = { 5357c958713SColin LeMahieu Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, 5367c958713SColin LeMahieu Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7, 5377c958713SColin LeMahieu Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11, 5387c958713SColin LeMahieu Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15}; 5397c958713SColin LeMahieu 5403da000c0SCraig Topper return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable)); 5417c958713SColin LeMahieu } 5427c958713SColin LeMahieu 5437cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5447cd08927SColin LeMahieu uint64_t /*Address*/, 5457cd08927SColin LeMahieu const void *Decoder) { 546e5e035a3SCraig Topper static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1, 5477cd08927SColin LeMahieu Hexagon::P2, Hexagon::P3}; 5487cd08927SColin LeMahieu 549e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable); 5507cd08927SColin LeMahieu } 5517cd08927SColin LeMahieu 5527c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5537c958713SColin LeMahieu uint64_t /*Address*/, 5547c958713SColin LeMahieu const void *Decoder) { 555e5e035a3SCraig Topper static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1, 5567c958713SColin LeMahieu Hexagon::Q2, Hexagon::Q3}; 5577c958713SColin LeMahieu 558e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable); 5597c958713SColin LeMahieu } 560be8c453dSColin LeMahieu 5617cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5627cd08927SColin LeMahieu uint64_t /*Address*/, 5637cd08927SColin LeMahieu const void *Decoder) { 564e5e035a3SCraig Topper static const MCPhysReg CtrlRegDecoderTable[] = { 5657cd08927SColin LeMahieu Hexagon::SA0, Hexagon::LC0, Hexagon::SA1, Hexagon::LC1, 5667cd08927SColin LeMahieu Hexagon::P3_0, Hexagon::C5, Hexagon::C6, Hexagon::C7, 5677cd08927SColin LeMahieu Hexagon::USR, Hexagon::PC, Hexagon::UGP, Hexagon::GP, 5687cd08927SColin LeMahieu Hexagon::CS0, Hexagon::CS1, Hexagon::UPCL, Hexagon::UPC 5697cd08927SColin LeMahieu }; 5707cd08927SColin LeMahieu 5716261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlRegDecoderTable)) 5727cd08927SColin LeMahieu return MCDisassembler::Fail; 5737cd08927SColin LeMahieu 5747cd08927SColin LeMahieu if (CtrlRegDecoderTable[RegNo] == Hexagon::NoRegister) 5757cd08927SColin LeMahieu return MCDisassembler::Fail; 5767cd08927SColin LeMahieu 5777cd08927SColin LeMahieu unsigned Register = CtrlRegDecoderTable[RegNo]; 5787cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 5797cd08927SColin LeMahieu return MCDisassembler::Success; 5807cd08927SColin LeMahieu } 5817cd08927SColin LeMahieu 5827cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 5837cd08927SColin LeMahieu uint64_t /*Address*/, 5847cd08927SColin LeMahieu const void *Decoder) { 585e5e035a3SCraig Topper static const MCPhysReg CtrlReg64DecoderTable[] = { 5867cd08927SColin LeMahieu Hexagon::C1_0, Hexagon::NoRegister, 5877cd08927SColin LeMahieu Hexagon::C3_2, Hexagon::NoRegister, 5887cd08927SColin LeMahieu Hexagon::C7_6, Hexagon::NoRegister, 5897cd08927SColin LeMahieu Hexagon::C9_8, Hexagon::NoRegister, 5907cd08927SColin LeMahieu Hexagon::C11_10, Hexagon::NoRegister, 5917cd08927SColin LeMahieu Hexagon::CS, Hexagon::NoRegister, 5927cd08927SColin LeMahieu Hexagon::UPC, Hexagon::NoRegister 5937cd08927SColin LeMahieu }; 5947cd08927SColin LeMahieu 5956261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlReg64DecoderTable)) 5967cd08927SColin LeMahieu return MCDisassembler::Fail; 5977cd08927SColin LeMahieu 5987cd08927SColin LeMahieu if (CtrlReg64DecoderTable[RegNo] == Hexagon::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 namespace { 6257cd08927SColin LeMahieu uint32_t fullValue(MCInstrInfo const &MCII, 6267cd08927SColin LeMahieu MCInst &MCB, 6277cd08927SColin LeMahieu MCInst &MI, 6287cd08927SColin LeMahieu int64_t Value) { 6297cd08927SColin LeMahieu MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( 6307cd08927SColin LeMahieu MCB, HexagonMCInstrInfo::bundleSize(MCB)); 6317cd08927SColin LeMahieu if(!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI)) 6327cd08927SColin LeMahieu return Value; 6337cd08927SColin LeMahieu unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI); 6347cd08927SColin LeMahieu uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f; 6357cd08927SColin LeMahieu int64_t Bits; 6367cd08927SColin LeMahieu bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits); 6377cd08927SColin LeMahieu assert(Success);(void)Success; 6387cd08927SColin LeMahieu uint32_t Upper26 = static_cast<uint32_t>(Bits); 6397cd08927SColin LeMahieu uint32_t Operand = Upper26 | Lower6; 6407cd08927SColin LeMahieu return Operand; 6417cd08927SColin LeMahieu } 6427cd08927SColin LeMahieu template <size_t T> 6437cd08927SColin LeMahieu void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) { 6447cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6457cd08927SColin LeMahieu int64_t FullValue = fullValue(*Disassembler.MCII, 6467cd08927SColin LeMahieu **Disassembler.CurrentBundle, 6477cd08927SColin LeMahieu MI, SignExtend64<T>(tmp)); 6487cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue); 6497cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, 6507cd08927SColin LeMahieu Disassembler.getContext()); 6517cd08927SColin LeMahieu } 6527cd08927SColin LeMahieu } 6537cd08927SColin LeMahieu 6547cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 6557cd08927SColin LeMahieu uint64_t /*Address*/, 6567cd08927SColin LeMahieu const void *Decoder) { 6577cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6587cd08927SColin LeMahieu int64_t FullValue = fullValue(*Disassembler.MCII, 6597cd08927SColin LeMahieu **Disassembler.CurrentBundle, 6607cd08927SColin LeMahieu MI, tmp); 6617cd08927SColin LeMahieu assert(FullValue >= 0 && "Negative in unsigned decoder"); 6627cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext()); 6637cd08927SColin LeMahieu return MCDisassembler::Success; 6647cd08927SColin LeMahieu } 6657cd08927SColin LeMahieu 6661e9d1d76SColin LeMahieu static DecodeStatus s16ImmDecoder(MCInst &MI, unsigned tmp, 6671e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6687cd08927SColin LeMahieu signedDecoder<16>(MI, tmp, Decoder); 6691e9d1d76SColin LeMahieu return MCDisassembler::Success; 6701e9d1d76SColin LeMahieu } 6711e9d1d76SColin LeMahieu 6721e9d1d76SColin LeMahieu static DecodeStatus s12ImmDecoder(MCInst &MI, unsigned tmp, 6731e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6747cd08927SColin LeMahieu signedDecoder<12>(MI, tmp, Decoder); 6751e9d1d76SColin LeMahieu return MCDisassembler::Success; 6761e9d1d76SColin LeMahieu } 6771e9d1d76SColin LeMahieu 6781e9d1d76SColin LeMahieu static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, 6791e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6807cd08927SColin LeMahieu signedDecoder<11>(MI, tmp, Decoder); 6811e9d1d76SColin LeMahieu return MCDisassembler::Success; 6821e9d1d76SColin LeMahieu } 6831e9d1d76SColin LeMahieu 6841e9d1d76SColin LeMahieu static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, 6851e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6867cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, SignExtend64<12>(tmp), contextFromDecoder(Decoder)); 6871e9d1d76SColin LeMahieu return MCDisassembler::Success; 6881e9d1d76SColin LeMahieu } 6891e9d1d76SColin LeMahieu 6901e9d1d76SColin LeMahieu static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, 6911e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6927cd08927SColin LeMahieu signedDecoder<13>(MI, tmp, Decoder); 6931e9d1d76SColin LeMahieu return MCDisassembler::Success; 6941e9d1d76SColin LeMahieu } 6951e9d1d76SColin LeMahieu 6961e9d1d76SColin LeMahieu static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, 6971e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6987cd08927SColin LeMahieu signedDecoder<14>(MI, tmp, Decoder); 6991e9d1d76SColin LeMahieu return MCDisassembler::Success; 7001e9d1d76SColin LeMahieu } 7011e9d1d76SColin LeMahieu 7021e9d1d76SColin LeMahieu static DecodeStatus s10ImmDecoder(MCInst &MI, unsigned tmp, 7031e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7047cd08927SColin LeMahieu signedDecoder<10>(MI, tmp, Decoder); 7051e9d1d76SColin LeMahieu return MCDisassembler::Success; 7061e9d1d76SColin LeMahieu } 7071e9d1d76SColin LeMahieu 7081e9d1d76SColin LeMahieu static DecodeStatus s8ImmDecoder(MCInst &MI, unsigned tmp, uint64_t /*Address*/, 7091e9d1d76SColin LeMahieu const void *Decoder) { 7107cd08927SColin LeMahieu signedDecoder<8>(MI, tmp, Decoder); 7111e9d1d76SColin LeMahieu return MCDisassembler::Success; 7121e9d1d76SColin LeMahieu } 7131e9d1d76SColin LeMahieu 7141e9d1d76SColin LeMahieu static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, 7151e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7167cd08927SColin LeMahieu signedDecoder<6>(MI, tmp, Decoder); 7171e9d1d76SColin LeMahieu return MCDisassembler::Success; 7181e9d1d76SColin LeMahieu } 7191e9d1d76SColin LeMahieu 7201e9d1d76SColin LeMahieu static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, 7211e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7227cd08927SColin LeMahieu signedDecoder<4>(MI, tmp, Decoder); 7231e9d1d76SColin LeMahieu return MCDisassembler::Success; 7241e9d1d76SColin LeMahieu } 7251e9d1d76SColin LeMahieu 7261e9d1d76SColin LeMahieu static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, 7271e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7287cd08927SColin LeMahieu signedDecoder<5>(MI, tmp, Decoder); 7291e9d1d76SColin LeMahieu return MCDisassembler::Success; 7301e9d1d76SColin LeMahieu } 7311e9d1d76SColin LeMahieu 7321e9d1d76SColin LeMahieu static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, 7331e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7347cd08927SColin LeMahieu signedDecoder<6>(MI, tmp, Decoder); 7351e9d1d76SColin LeMahieu return MCDisassembler::Success; 7361e9d1d76SColin LeMahieu } 7371e9d1d76SColin LeMahieu 7381e9d1d76SColin LeMahieu static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, 7391e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7407cd08927SColin LeMahieu signedDecoder<7>(MI, tmp, Decoder); 7411e9d1d76SColin LeMahieu return MCDisassembler::Success; 7421e9d1d76SColin LeMahieu } 7431e9d1d76SColin LeMahieu 7447c958713SColin LeMahieu static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, 7457c958713SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7467cd08927SColin LeMahieu signedDecoder<10>(MI, tmp, Decoder); 7477c958713SColin LeMahieu return MCDisassembler::Success; 7487c958713SColin LeMahieu } 7497c958713SColin LeMahieu 7507c958713SColin LeMahieu static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, 7517c958713SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7527cd08927SColin LeMahieu signedDecoder<19>(MI, tmp, Decoder); 7537c958713SColin LeMahieu return MCDisassembler::Success; 7547c958713SColin LeMahieu } 7557c958713SColin LeMahieu 7567cd08927SColin LeMahieu // custom decoder for various jump/call immediates 7577cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 7587cd08927SColin LeMahieu const void *Decoder) { 7597cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 7607cd08927SColin LeMahieu unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); 7617cd08927SColin LeMahieu // r13_2 is not extendable, so if there are no extent bits, it's r13_2 7627cd08927SColin LeMahieu if (Bits == 0) 7637cd08927SColin LeMahieu Bits = 15; 7647cd08927SColin LeMahieu uint32_t FullValue = fullValue(*Disassembler.MCII, 7657cd08927SColin LeMahieu **Disassembler.CurrentBundle, 7667cd08927SColin LeMahieu MI, SignExtend64(tmp, Bits)); 7677cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue) + Address; 7687cd08927SColin LeMahieu if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 7697cd08927SColin LeMahieu 0, 4)) 7707cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); 7717cd08927SColin LeMahieu return MCDisassembler::Success; 7727cd08927SColin LeMahieu } 7737cd08927SColin LeMahieu 7747cd08927SColin LeMahieu // Addressing mode dependent load store opcode map. 7757cd08927SColin LeMahieu // - If an insn is preceded by an extender the address is absolute. 7767cd08927SColin LeMahieu // - memw(##symbol) = r0 7777cd08927SColin LeMahieu // - If an insn is not preceded by an extender the address is GP relative. 7787cd08927SColin LeMahieu // - memw(gp + #symbol) = r0 7797cd08927SColin LeMahieu // Please note that the instructions must be ordered in the descending order 7807cd08927SColin LeMahieu // of their opcode. 7817cd08927SColin LeMahieu // HexagonII::INST_ICLASS_ST 782d824f5f0SCraig Topper static const unsigned int StoreConditionalOpcodeData[][2] = { 7837cd08927SColin LeMahieu {S4_pstorerdfnew_abs, 0xafc02084}, 7847cd08927SColin LeMahieu {S4_pstorerdtnew_abs, 0xafc02080}, 7857cd08927SColin LeMahieu {S4_pstorerdf_abs, 0xafc00084}, 7867cd08927SColin LeMahieu {S4_pstorerdt_abs, 0xafc00080}, 7877cd08927SColin LeMahieu {S4_pstorerinewfnew_abs, 0xafa03084}, 7887cd08927SColin LeMahieu {S4_pstorerinewtnew_abs, 0xafa03080}, 7897cd08927SColin LeMahieu {S4_pstorerhnewfnew_abs, 0xafa02884}, 7907cd08927SColin LeMahieu {S4_pstorerhnewtnew_abs, 0xafa02880}, 7917cd08927SColin LeMahieu {S4_pstorerbnewfnew_abs, 0xafa02084}, 7927cd08927SColin LeMahieu {S4_pstorerbnewtnew_abs, 0xafa02080}, 7937cd08927SColin LeMahieu {S4_pstorerinewf_abs, 0xafa01084}, 7947cd08927SColin LeMahieu {S4_pstorerinewt_abs, 0xafa01080}, 7957cd08927SColin LeMahieu {S4_pstorerhnewf_abs, 0xafa00884}, 7967cd08927SColin LeMahieu {S4_pstorerhnewt_abs, 0xafa00880}, 7977cd08927SColin LeMahieu {S4_pstorerbnewf_abs, 0xafa00084}, 7987cd08927SColin LeMahieu {S4_pstorerbnewt_abs, 0xafa00080}, 7997cd08927SColin LeMahieu {S4_pstorerifnew_abs, 0xaf802084}, 8007cd08927SColin LeMahieu {S4_pstoreritnew_abs, 0xaf802080}, 8017cd08927SColin LeMahieu {S4_pstorerif_abs, 0xaf800084}, 8027cd08927SColin LeMahieu {S4_pstorerit_abs, 0xaf800080}, 8037cd08927SColin LeMahieu {S4_pstorerhfnew_abs, 0xaf402084}, 8047cd08927SColin LeMahieu {S4_pstorerhtnew_abs, 0xaf402080}, 8057cd08927SColin LeMahieu {S4_pstorerhf_abs, 0xaf400084}, 8067cd08927SColin LeMahieu {S4_pstorerht_abs, 0xaf400080}, 8077cd08927SColin LeMahieu {S4_pstorerbfnew_abs, 0xaf002084}, 8087cd08927SColin LeMahieu {S4_pstorerbtnew_abs, 0xaf002080}, 8097cd08927SColin LeMahieu {S4_pstorerbf_abs, 0xaf000084}, 8107cd08927SColin LeMahieu {S4_pstorerbt_abs, 0xaf000080}}; 8117cd08927SColin LeMahieu // HexagonII::INST_ICLASS_LD 8127cd08927SColin LeMahieu 8137cd08927SColin LeMahieu // HexagonII::INST_ICLASS_LD_ST_2 8149675de5bSColin LeMahieu static unsigned int LoadStoreOpcodeData[][2] = {{PS_loadrdabs, 0x49c00000}, 8159675de5bSColin LeMahieu {PS_loadriabs, 0x49800000}, 8169675de5bSColin LeMahieu {PS_loadruhabs, 0x49600000}, 8179675de5bSColin LeMahieu {PS_loadrhabs, 0x49400000}, 8189675de5bSColin LeMahieu {PS_loadrubabs, 0x49200000}, 8199675de5bSColin LeMahieu {PS_loadrbabs, 0x49000000}, 8209675de5bSColin LeMahieu {PS_storerdabs, 0x48c00000}, 8219675de5bSColin LeMahieu {PS_storerinewabs, 0x48a01000}, 8229675de5bSColin LeMahieu {PS_storerhnewabs, 0x48a00800}, 8239675de5bSColin LeMahieu {PS_storerbnewabs, 0x48a00000}, 8249675de5bSColin LeMahieu {PS_storeriabs, 0x48800000}, 8259675de5bSColin LeMahieu {PS_storerfabs, 0x48600000}, 8269675de5bSColin LeMahieu {PS_storerhabs, 0x48400000}, 8279675de5bSColin LeMahieu {PS_storerbabs, 0x48000000}}; 828d824f5f0SCraig Topper static const size_t NumCondS = array_lengthof(StoreConditionalOpcodeData); 829d824f5f0SCraig Topper static const size_t NumLS = array_lengthof(LoadStoreOpcodeData); 8307cd08927SColin LeMahieu 8317cd08927SColin LeMahieu static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn) { 8327cd08927SColin LeMahieu 8337cd08927SColin LeMahieu unsigned MachineOpcode = 0; 8347cd08927SColin LeMahieu unsigned LLVMOpcode = 0; 8357cd08927SColin LeMahieu 8367cd08927SColin LeMahieu if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_ST) { 837d824f5f0SCraig Topper for (size_t i = 0; i < NumCondS; ++i) { 8387cd08927SColin LeMahieu if ((insn & StoreConditionalOpcodeData[i][1]) == 8397cd08927SColin LeMahieu StoreConditionalOpcodeData[i][1]) { 8407cd08927SColin LeMahieu MachineOpcode = StoreConditionalOpcodeData[i][1]; 8417cd08927SColin LeMahieu LLVMOpcode = StoreConditionalOpcodeData[i][0]; 8427cd08927SColin LeMahieu break; 8437cd08927SColin LeMahieu } 8447cd08927SColin LeMahieu } 8457cd08927SColin LeMahieu } 8467cd08927SColin LeMahieu if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_LD_ST_2) { 847d824f5f0SCraig Topper for (size_t i = 0; i < NumLS; ++i) { 8487cd08927SColin LeMahieu if ((insn & LoadStoreOpcodeData[i][1]) == LoadStoreOpcodeData[i][1]) { 8497cd08927SColin LeMahieu MachineOpcode = LoadStoreOpcodeData[i][1]; 8507cd08927SColin LeMahieu LLVMOpcode = LoadStoreOpcodeData[i][0]; 8517cd08927SColin LeMahieu break; 8527cd08927SColin LeMahieu } 8537cd08927SColin LeMahieu } 8547cd08927SColin LeMahieu } 8557cd08927SColin LeMahieu 8567cd08927SColin LeMahieu if (MachineOpcode) { 8577cd08927SColin LeMahieu unsigned Value = 0; 8587cd08927SColin LeMahieu unsigned shift = 0; 8597cd08927SColin LeMahieu MI.setOpcode(LLVMOpcode); 8607cd08927SColin LeMahieu // Remove the parse bits from the insn. 8617cd08927SColin LeMahieu insn &= ~HexagonII::INST_PARSE_MASK; 8627cd08927SColin LeMahieu 8637cd08927SColin LeMahieu switch (LLVMOpcode) { 8647cd08927SColin LeMahieu default: 8657cd08927SColin LeMahieu return MCDisassembler::Fail; 8667cd08927SColin LeMahieu break; 8677cd08927SColin LeMahieu 8687cd08927SColin LeMahieu case Hexagon::S4_pstorerdf_abs: 8697cd08927SColin LeMahieu case Hexagon::S4_pstorerdt_abs: 8707cd08927SColin LeMahieu case Hexagon::S4_pstorerdfnew_abs: 8717cd08927SColin LeMahieu case Hexagon::S4_pstorerdtnew_abs: { 8727cd08927SColin LeMahieu // op: Pv 8737cd08927SColin LeMahieu Value = insn & UINT64_C(3); 8747cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 8757cd08927SColin LeMahieu // op: u6 8767cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 8777cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 8787cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 8797cd08927SColin LeMahieu // op: Rtt 8807cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 8817cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 8827cd08927SColin LeMahieu break; 8837cd08927SColin LeMahieu } 8847cd08927SColin LeMahieu 8857cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewf_abs: 8867cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewt_abs: 8877cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewfnew_abs: 8887cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewtnew_abs: 8897cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewf_abs: 8907cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewt_abs: 8917cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewfnew_abs: 8927cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewtnew_abs: 8937cd08927SColin LeMahieu case Hexagon::S4_pstorerinewf_abs: 8947cd08927SColin LeMahieu case Hexagon::S4_pstorerinewt_abs: 8957cd08927SColin LeMahieu case Hexagon::S4_pstorerinewfnew_abs: 8967cd08927SColin LeMahieu case Hexagon::S4_pstorerinewtnew_abs: { 8977cd08927SColin LeMahieu // op: Pv 8987cd08927SColin LeMahieu Value = insn & UINT64_C(3); 8997cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9007cd08927SColin LeMahieu // op: u6 9017cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 9027cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 9037cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9047cd08927SColin LeMahieu // op: Nt 9057cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(7); 9067cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9077cd08927SColin LeMahieu break; 9087cd08927SColin LeMahieu } 9097cd08927SColin LeMahieu 9107cd08927SColin LeMahieu case Hexagon::S4_pstorerbf_abs: 9117cd08927SColin LeMahieu case Hexagon::S4_pstorerbt_abs: 9127cd08927SColin LeMahieu case Hexagon::S4_pstorerbfnew_abs: 9137cd08927SColin LeMahieu case Hexagon::S4_pstorerbtnew_abs: 9147cd08927SColin LeMahieu case Hexagon::S4_pstorerhf_abs: 9157cd08927SColin LeMahieu case Hexagon::S4_pstorerht_abs: 9167cd08927SColin LeMahieu case Hexagon::S4_pstorerhfnew_abs: 9177cd08927SColin LeMahieu case Hexagon::S4_pstorerhtnew_abs: 9187cd08927SColin LeMahieu case Hexagon::S4_pstorerif_abs: 9197cd08927SColin LeMahieu case Hexagon::S4_pstorerit_abs: 9207cd08927SColin LeMahieu case Hexagon::S4_pstorerifnew_abs: 9217cd08927SColin LeMahieu case Hexagon::S4_pstoreritnew_abs: { 9227cd08927SColin LeMahieu // op: Pv 9237cd08927SColin LeMahieu Value = insn & UINT64_C(3); 9247cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9257cd08927SColin LeMahieu // op: u6 9267cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 9277cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 9287cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9297cd08927SColin LeMahieu // op: Rt 9307cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 9317cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9327cd08927SColin LeMahieu break; 9337cd08927SColin LeMahieu } 9347cd08927SColin LeMahieu 9357cd08927SColin LeMahieu case Hexagon::L4_ploadrdf_abs: 9367cd08927SColin LeMahieu case Hexagon::L4_ploadrdt_abs: 9377cd08927SColin LeMahieu case Hexagon::L4_ploadrdfnew_abs: 9387cd08927SColin LeMahieu case Hexagon::L4_ploadrdtnew_abs: { 9397cd08927SColin LeMahieu // op: Rdd 9407cd08927SColin LeMahieu Value = insn & UINT64_C(31); 9417cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 9427cd08927SColin LeMahieu // op: Pt 9437cd08927SColin LeMahieu Value = ((insn >> 9) & UINT64_C(3)); 9447cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9457cd08927SColin LeMahieu // op: u6 9467cd08927SColin LeMahieu Value = ((insn >> 15) & UINT64_C(62)); 9477cd08927SColin LeMahieu Value |= ((insn >> 8) & UINT64_C(1)); 9487cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9497cd08927SColin LeMahieu break; 9507cd08927SColin LeMahieu } 9517cd08927SColin LeMahieu 9527cd08927SColin LeMahieu case Hexagon::L4_ploadrbf_abs: 9537cd08927SColin LeMahieu case Hexagon::L4_ploadrbt_abs: 9547cd08927SColin LeMahieu case Hexagon::L4_ploadrbfnew_abs: 9557cd08927SColin LeMahieu case Hexagon::L4_ploadrbtnew_abs: 9567cd08927SColin LeMahieu case Hexagon::L4_ploadrhf_abs: 9577cd08927SColin LeMahieu case Hexagon::L4_ploadrht_abs: 9587cd08927SColin LeMahieu case Hexagon::L4_ploadrhfnew_abs: 9597cd08927SColin LeMahieu case Hexagon::L4_ploadrhtnew_abs: 9607cd08927SColin LeMahieu case Hexagon::L4_ploadrubf_abs: 9617cd08927SColin LeMahieu case Hexagon::L4_ploadrubt_abs: 9627cd08927SColin LeMahieu case Hexagon::L4_ploadrubfnew_abs: 9637cd08927SColin LeMahieu case Hexagon::L4_ploadrubtnew_abs: 9647cd08927SColin LeMahieu case Hexagon::L4_ploadruhf_abs: 9657cd08927SColin LeMahieu case Hexagon::L4_ploadruht_abs: 9667cd08927SColin LeMahieu case Hexagon::L4_ploadruhfnew_abs: 9677cd08927SColin LeMahieu case Hexagon::L4_ploadruhtnew_abs: 9687cd08927SColin LeMahieu case Hexagon::L4_ploadrif_abs: 9697cd08927SColin LeMahieu case Hexagon::L4_ploadrit_abs: 9707cd08927SColin LeMahieu case Hexagon::L4_ploadrifnew_abs: 9717cd08927SColin LeMahieu case Hexagon::L4_ploadritnew_abs: 9727cd08927SColin LeMahieu // op: Rd 9737cd08927SColin LeMahieu Value = insn & UINT64_C(31); 9747cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9757cd08927SColin LeMahieu // op: Pt 9767cd08927SColin LeMahieu Value = (insn >> 9) & UINT64_C(3); 9777cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9787cd08927SColin LeMahieu // op: u6 9797cd08927SColin LeMahieu Value = (insn >> 15) & UINT64_C(62); 9807cd08927SColin LeMahieu Value |= (insn >> 8) & UINT64_C(1); 9817cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9827cd08927SColin LeMahieu break; 9837cd08927SColin LeMahieu 9847cd08927SColin LeMahieu // op: g16_2 9859675de5bSColin LeMahieu case (Hexagon::PS_loadriabs): 9867cd08927SColin LeMahieu ++shift; 9877cd08927SColin LeMahieu // op: g16_1 9889675de5bSColin LeMahieu case Hexagon::PS_loadrhabs: 9899675de5bSColin LeMahieu case Hexagon::PS_loadruhabs: 9907cd08927SColin LeMahieu ++shift; 9917cd08927SColin LeMahieu // op: g16_0 9929675de5bSColin LeMahieu case Hexagon::PS_loadrbabs: 9939675de5bSColin LeMahieu case Hexagon::PS_loadrubabs: { 9947cd08927SColin LeMahieu // op: Rd 9957cd08927SColin LeMahieu Value |= insn & UINT64_C(31); 9967cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9977cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 9987cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 9997cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(511); 10007cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10017cd08927SColin LeMahieu break; 10027cd08927SColin LeMahieu } 10037cd08927SColin LeMahieu 10049675de5bSColin LeMahieu case Hexagon::PS_loadrdabs: { 10057cd08927SColin LeMahieu Value = insn & UINT64_C(31); 10067cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 10077cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10087cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10097cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(511); 10107cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << 3)); 10117cd08927SColin LeMahieu break; 10127cd08927SColin LeMahieu } 10137cd08927SColin LeMahieu 10149675de5bSColin LeMahieu case Hexagon::PS_storerdabs: { 10157cd08927SColin LeMahieu // op: g16_3 10167cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10177cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10187cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10197cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10207cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << 3)); 10217cd08927SColin LeMahieu // op: Rtt 10227cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 10237cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 10247cd08927SColin LeMahieu break; 10257cd08927SColin LeMahieu } 10267cd08927SColin LeMahieu 10277cd08927SColin LeMahieu // op: g16_2 10289675de5bSColin LeMahieu case Hexagon::PS_storerinewabs: 10297cd08927SColin LeMahieu ++shift; 10307cd08927SColin LeMahieu // op: g16_1 10319675de5bSColin LeMahieu case Hexagon::PS_storerhnewabs: 10327cd08927SColin LeMahieu ++shift; 10337cd08927SColin LeMahieu // op: g16_0 10349675de5bSColin LeMahieu case Hexagon::PS_storerbnewabs: { 10357cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10367cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10377cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10387cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10397cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10407cd08927SColin LeMahieu // op: Nt 10417cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(7); 10427cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 10437cd08927SColin LeMahieu break; 10447cd08927SColin LeMahieu } 10457cd08927SColin LeMahieu 10467cd08927SColin LeMahieu // op: g16_2 10479675de5bSColin LeMahieu case Hexagon::PS_storeriabs: 10487cd08927SColin LeMahieu ++shift; 10497cd08927SColin LeMahieu // op: g16_1 10509675de5bSColin LeMahieu case Hexagon::PS_storerhabs: 10519675de5bSColin LeMahieu case Hexagon::PS_storerfabs: 10527cd08927SColin LeMahieu ++shift; 10537cd08927SColin LeMahieu // op: g16_0 10549675de5bSColin LeMahieu case Hexagon::PS_storerbabs: { 10557cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10567cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10577cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10587cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10597cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10607cd08927SColin LeMahieu // op: Rt 10617cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 10627cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 10637cd08927SColin LeMahieu break; 10647cd08927SColin LeMahieu } 10657cd08927SColin LeMahieu } 10667cd08927SColin LeMahieu return MCDisassembler::Success; 10677cd08927SColin LeMahieu } 10687cd08927SColin LeMahieu return MCDisassembler::Fail; 10697cd08927SColin LeMahieu } 10707cd08927SColin LeMahieu 10717cd08927SColin LeMahieu static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn, 10727cd08927SColin LeMahieu void const *Decoder) { 10737cd08927SColin LeMahieu 10747cd08927SColin LeMahieu // Instruction Class for a constant a extender: bits 31:28 = 0x0000 10757cd08927SColin LeMahieu if ((~insn & 0xf0000000) == 0xf0000000) { 10767cd08927SColin LeMahieu unsigned Value; 10777cd08927SColin LeMahieu // 27:16 High 12 bits of 26-bit extender. 10787cd08927SColin LeMahieu Value = (insn & 0x0fff0000) << 4; 10797cd08927SColin LeMahieu // 13:0 Low 14 bits of 26-bit extender. 10807cd08927SColin LeMahieu Value |= ((insn & 0x3fff) << 6); 10817cd08927SColin LeMahieu MI.setOpcode(Hexagon::A4_ext); 10827cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Value, contextFromDecoder(Decoder)); 10837cd08927SColin LeMahieu return MCDisassembler::Success; 10847cd08927SColin LeMahieu } 10857cd08927SColin LeMahieu return MCDisassembler::Fail; 10867cd08927SColin LeMahieu } 10877cd08927SColin LeMahieu 1088be8c453dSColin LeMahieu // These values are from HexagonGenMCCodeEmitter.inc and HexagonIsetDx.td 1089be8c453dSColin LeMahieu enum subInstBinaryValues { 1090*8ed1aee9SColin LeMahieu SA1_addi_BITS = 0x0000, 1091*8ed1aee9SColin LeMahieu SA1_addi_MASK = 0x1800, 1092*8ed1aee9SColin LeMahieu SA1_addrx_BITS = 0x1800, 1093*8ed1aee9SColin LeMahieu SA1_addrx_MASK = 0x1f00, 1094*8ed1aee9SColin LeMahieu SA1_addsp_BITS = 0x0c00, 1095*8ed1aee9SColin LeMahieu SA1_addsp_MASK = 0x1c00, 1096*8ed1aee9SColin LeMahieu SA1_and1_BITS = 0x1200, 1097*8ed1aee9SColin LeMahieu SA1_and1_MASK = 0x1f00, 1098*8ed1aee9SColin LeMahieu SA1_clrf_BITS = 0x1a70, 1099*8ed1aee9SColin LeMahieu SA1_clrf_MASK = 0x1e70, 1100*8ed1aee9SColin LeMahieu SA1_clrfnew_BITS = 0x1a50, 1101*8ed1aee9SColin LeMahieu SA1_clrfnew_MASK = 0x1e70, 1102*8ed1aee9SColin LeMahieu SA1_clrt_BITS = 0x1a60, 1103*8ed1aee9SColin LeMahieu SA1_clrt_MASK = 0x1e70, 1104*8ed1aee9SColin LeMahieu SA1_clrtnew_BITS = 0x1a40, 1105*8ed1aee9SColin LeMahieu SA1_clrtnew_MASK = 0x1e70, 1106*8ed1aee9SColin LeMahieu SA1_cmpeqi_BITS = 0x1900, 1107*8ed1aee9SColin LeMahieu SA1_cmpeqi_MASK = 0x1f00, 1108*8ed1aee9SColin LeMahieu SA1_combine0i_BITS = 0x1c00, 1109*8ed1aee9SColin LeMahieu SA1_combine0i_MASK = 0x1d18, 1110*8ed1aee9SColin LeMahieu SA1_combine1i_BITS = 0x1c08, 1111*8ed1aee9SColin LeMahieu SA1_combine1i_MASK = 0x1d18, 1112*8ed1aee9SColin LeMahieu SA1_combine2i_BITS = 0x1c10, 1113*8ed1aee9SColin LeMahieu SA1_combine2i_MASK = 0x1d18, 1114*8ed1aee9SColin LeMahieu SA1_combine3i_BITS = 0x1c18, 1115*8ed1aee9SColin LeMahieu SA1_combine3i_MASK = 0x1d18, 1116*8ed1aee9SColin LeMahieu SA1_combinerz_BITS = 0x1d08, 1117*8ed1aee9SColin LeMahieu SA1_combinerz_MASK = 0x1d08, 1118*8ed1aee9SColin LeMahieu SA1_combinezr_BITS = 0x1d00, 1119*8ed1aee9SColin LeMahieu SA1_combinezr_MASK = 0x1d08, 1120*8ed1aee9SColin LeMahieu SA1_dec_BITS = 0x1300, 1121*8ed1aee9SColin LeMahieu SA1_dec_MASK = 0x1f00, 1122*8ed1aee9SColin LeMahieu SA1_inc_BITS = 0x1100, 1123*8ed1aee9SColin LeMahieu SA1_inc_MASK = 0x1f00, 1124*8ed1aee9SColin LeMahieu SA1_seti_BITS = 0x0800, 1125*8ed1aee9SColin LeMahieu SA1_seti_MASK = 0x1c00, 1126*8ed1aee9SColin LeMahieu SA1_setin1_BITS = 0x1a00, 1127*8ed1aee9SColin LeMahieu SA1_setin1_MASK = 0x1e40, 1128*8ed1aee9SColin LeMahieu SA1_sxtb_BITS = 0x1500, 1129*8ed1aee9SColin LeMahieu SA1_sxtb_MASK = 0x1f00, 1130*8ed1aee9SColin LeMahieu SA1_sxth_BITS = 0x1400, 1131*8ed1aee9SColin LeMahieu SA1_sxth_MASK = 0x1f00, 1132*8ed1aee9SColin LeMahieu SA1_tfr_BITS = 0x1000, 1133*8ed1aee9SColin LeMahieu SA1_tfr_MASK = 0x1f00, 1134*8ed1aee9SColin LeMahieu SA1_zxtb_BITS = 0x1700, 1135*8ed1aee9SColin LeMahieu SA1_zxtb_MASK = 0x1f00, 1136*8ed1aee9SColin LeMahieu SA1_zxth_BITS = 0x1600, 1137*8ed1aee9SColin LeMahieu SA1_zxth_MASK = 0x1f00, 1138*8ed1aee9SColin LeMahieu SL1_loadri_io_BITS = 0x0000, 1139*8ed1aee9SColin LeMahieu SL1_loadri_io_MASK = 0x1000, 1140*8ed1aee9SColin LeMahieu SL1_loadrub_io_BITS = 0x1000, 1141*8ed1aee9SColin LeMahieu SL1_loadrub_io_MASK = 0x1000, 1142*8ed1aee9SColin LeMahieu SL2_deallocframe_BITS = 0x1f00, 1143*8ed1aee9SColin LeMahieu SL2_deallocframe_MASK = 0x1fc0, 1144*8ed1aee9SColin LeMahieu SL2_jumpr31_BITS = 0x1fc0, 1145*8ed1aee9SColin LeMahieu SL2_jumpr31_MASK = 0x1fc4, 1146*8ed1aee9SColin LeMahieu SL2_jumpr31_f_BITS = 0x1fc5, 1147*8ed1aee9SColin LeMahieu SL2_jumpr31_f_MASK = 0x1fc7, 1148*8ed1aee9SColin LeMahieu SL2_jumpr31_fnew_BITS = 0x1fc7, 1149*8ed1aee9SColin LeMahieu SL2_jumpr31_fnew_MASK = 0x1fc7, 1150*8ed1aee9SColin LeMahieu SL2_jumpr31_t_BITS = 0x1fc4, 1151*8ed1aee9SColin LeMahieu SL2_jumpr31_t_MASK = 0x1fc7, 1152*8ed1aee9SColin LeMahieu SL2_jumpr31_tnew_BITS = 0x1fc6, 1153*8ed1aee9SColin LeMahieu SL2_jumpr31_tnew_MASK = 0x1fc7, 1154*8ed1aee9SColin LeMahieu SL2_loadrb_io_BITS = 0x1000, 1155*8ed1aee9SColin LeMahieu SL2_loadrb_io_MASK = 0x1800, 1156*8ed1aee9SColin LeMahieu SL2_loadrd_sp_BITS = 0x1e00, 1157*8ed1aee9SColin LeMahieu SL2_loadrd_sp_MASK = 0x1f00, 1158*8ed1aee9SColin LeMahieu SL2_loadrh_io_BITS = 0x0000, 1159*8ed1aee9SColin LeMahieu SL2_loadrh_io_MASK = 0x1800, 1160*8ed1aee9SColin LeMahieu SL2_loadri_sp_BITS = 0x1c00, 1161*8ed1aee9SColin LeMahieu SL2_loadri_sp_MASK = 0x1e00, 1162*8ed1aee9SColin LeMahieu SL2_loadruh_io_BITS = 0x0800, 1163*8ed1aee9SColin LeMahieu SL2_loadruh_io_MASK = 0x1800, 1164*8ed1aee9SColin LeMahieu SL2_return_BITS = 0x1f40, 1165*8ed1aee9SColin LeMahieu SL2_return_MASK = 0x1fc4, 1166*8ed1aee9SColin LeMahieu SL2_return_f_BITS = 0x1f45, 1167*8ed1aee9SColin LeMahieu SL2_return_f_MASK = 0x1fc7, 1168*8ed1aee9SColin LeMahieu SL2_return_fnew_BITS = 0x1f47, 1169*8ed1aee9SColin LeMahieu SL2_return_fnew_MASK = 0x1fc7, 1170*8ed1aee9SColin LeMahieu SL2_return_t_BITS = 0x1f44, 1171*8ed1aee9SColin LeMahieu SL2_return_t_MASK = 0x1fc7, 1172*8ed1aee9SColin LeMahieu SL2_return_tnew_BITS = 0x1f46, 1173*8ed1aee9SColin LeMahieu SL2_return_tnew_MASK = 0x1fc7, 1174*8ed1aee9SColin LeMahieu SS1_storeb_io_BITS = 0x1000, 1175*8ed1aee9SColin LeMahieu SS1_storeb_io_MASK = 0x1000, 1176*8ed1aee9SColin LeMahieu SS1_storew_io_BITS = 0x0000, 1177*8ed1aee9SColin LeMahieu SS1_storew_io_MASK = 0x1000, 1178*8ed1aee9SColin LeMahieu SS2_allocframe_BITS = 0x1c00, 1179*8ed1aee9SColin LeMahieu SS2_allocframe_MASK = 0x1e00, 1180*8ed1aee9SColin LeMahieu SS2_storebi0_BITS = 0x1200, 1181*8ed1aee9SColin LeMahieu SS2_storebi0_MASK = 0x1f00, 1182*8ed1aee9SColin LeMahieu SS2_storebi1_BITS = 0x1300, 1183*8ed1aee9SColin LeMahieu SS2_storebi1_MASK = 0x1f00, 1184*8ed1aee9SColin LeMahieu SS2_stored_sp_BITS = 0x0a00, 1185*8ed1aee9SColin LeMahieu SS2_stored_sp_MASK = 0x1e00, 1186*8ed1aee9SColin LeMahieu SS2_storeh_io_BITS = 0x0000, 1187*8ed1aee9SColin LeMahieu SS2_storeh_io_MASK = 0x1800, 1188*8ed1aee9SColin LeMahieu SS2_storew_sp_BITS = 0x0800, 1189*8ed1aee9SColin LeMahieu SS2_storew_sp_MASK = 0x1e00, 1190*8ed1aee9SColin LeMahieu SS2_storewi0_BITS = 0x1000, 1191*8ed1aee9SColin LeMahieu SS2_storewi0_MASK = 0x1f00, 1192*8ed1aee9SColin LeMahieu SS2_storewi1_BITS = 0x1100, 1193*8ed1aee9SColin LeMahieu SS2_storewi1_MASK = 0x1f00 1194be8c453dSColin LeMahieu }; 1195be8c453dSColin LeMahieu 1196be8c453dSColin LeMahieu static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op, 1197be8c453dSColin LeMahieu raw_ostream &os) { 1198be8c453dSColin LeMahieu switch (IClass) { 1199be8c453dSColin LeMahieu case HexagonII::HSIG_L1: 1200*8ed1aee9SColin LeMahieu if ((inst & SL1_loadri_io_MASK) == SL1_loadri_io_BITS) 1201*8ed1aee9SColin LeMahieu op = Hexagon::SL1_loadri_io; 1202*8ed1aee9SColin LeMahieu else if ((inst & SL1_loadrub_io_MASK) == SL1_loadrub_io_BITS) 1203*8ed1aee9SColin LeMahieu op = Hexagon::SL1_loadrub_io; 1204be8c453dSColin LeMahieu else { 1205be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1206be8c453dSColin LeMahieu return MCDisassembler::Fail; 1207be8c453dSColin LeMahieu } 1208be8c453dSColin LeMahieu break; 1209be8c453dSColin LeMahieu case HexagonII::HSIG_L2: 1210*8ed1aee9SColin LeMahieu if ((inst & SL2_deallocframe_MASK) == SL2_deallocframe_BITS) 1211*8ed1aee9SColin LeMahieu op = Hexagon::SL2_deallocframe; 1212*8ed1aee9SColin LeMahieu else if ((inst & SL2_jumpr31_MASK) == SL2_jumpr31_BITS) 1213*8ed1aee9SColin LeMahieu op = Hexagon::SL2_jumpr31; 1214*8ed1aee9SColin LeMahieu else if ((inst & SL2_jumpr31_f_MASK) == SL2_jumpr31_f_BITS) 1215*8ed1aee9SColin LeMahieu op = Hexagon::SL2_jumpr31_f; 1216*8ed1aee9SColin LeMahieu else if ((inst & SL2_jumpr31_fnew_MASK) == SL2_jumpr31_fnew_BITS) 1217*8ed1aee9SColin LeMahieu op = Hexagon::SL2_jumpr31_fnew; 1218*8ed1aee9SColin LeMahieu else if ((inst & SL2_jumpr31_t_MASK) == SL2_jumpr31_t_BITS) 1219*8ed1aee9SColin LeMahieu op = Hexagon::SL2_jumpr31_t; 1220*8ed1aee9SColin LeMahieu else if ((inst & SL2_jumpr31_tnew_MASK) == SL2_jumpr31_tnew_BITS) 1221*8ed1aee9SColin LeMahieu op = Hexagon::SL2_jumpr31_tnew; 1222*8ed1aee9SColin LeMahieu else if ((inst & SL2_loadrb_io_MASK) == SL2_loadrb_io_BITS) 1223*8ed1aee9SColin LeMahieu op = Hexagon::SL2_loadrb_io; 1224*8ed1aee9SColin LeMahieu else if ((inst & SL2_loadrd_sp_MASK) == SL2_loadrd_sp_BITS) 1225*8ed1aee9SColin LeMahieu op = Hexagon::SL2_loadrd_sp; 1226*8ed1aee9SColin LeMahieu else if ((inst & SL2_loadrh_io_MASK) == SL2_loadrh_io_BITS) 1227*8ed1aee9SColin LeMahieu op = Hexagon::SL2_loadrh_io; 1228*8ed1aee9SColin LeMahieu else if ((inst & SL2_loadri_sp_MASK) == SL2_loadri_sp_BITS) 1229*8ed1aee9SColin LeMahieu op = Hexagon::SL2_loadri_sp; 1230*8ed1aee9SColin LeMahieu else if ((inst & SL2_loadruh_io_MASK) == SL2_loadruh_io_BITS) 1231*8ed1aee9SColin LeMahieu op = Hexagon::SL2_loadruh_io; 1232*8ed1aee9SColin LeMahieu else if ((inst & SL2_return_MASK) == SL2_return_BITS) 1233*8ed1aee9SColin LeMahieu op = Hexagon::SL2_return; 1234*8ed1aee9SColin LeMahieu else if ((inst & SL2_return_f_MASK) == SL2_return_f_BITS) 1235*8ed1aee9SColin LeMahieu op = Hexagon::SL2_return_f; 1236*8ed1aee9SColin LeMahieu else if ((inst & SL2_return_fnew_MASK) == SL2_return_fnew_BITS) 1237*8ed1aee9SColin LeMahieu op = Hexagon::SL2_return_fnew; 1238*8ed1aee9SColin LeMahieu else if ((inst & SL2_return_t_MASK) == SL2_return_t_BITS) 1239*8ed1aee9SColin LeMahieu op = Hexagon::SL2_return_t; 1240*8ed1aee9SColin LeMahieu else if ((inst & SL2_return_tnew_MASK) == SL2_return_tnew_BITS) 1241*8ed1aee9SColin LeMahieu op = Hexagon::SL2_return_tnew; 1242be8c453dSColin LeMahieu else { 1243be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1244be8c453dSColin LeMahieu return MCDisassembler::Fail; 1245be8c453dSColin LeMahieu } 1246be8c453dSColin LeMahieu break; 1247be8c453dSColin LeMahieu case HexagonII::HSIG_A: 1248*8ed1aee9SColin LeMahieu if ((inst & SA1_addi_MASK) == SA1_addi_BITS) 1249*8ed1aee9SColin LeMahieu op = Hexagon::SA1_addi; 1250*8ed1aee9SColin LeMahieu else if ((inst & SA1_addrx_MASK) == SA1_addrx_BITS) 1251*8ed1aee9SColin LeMahieu op = Hexagon::SA1_addrx; 1252*8ed1aee9SColin LeMahieu else if ((inst & SA1_addsp_MASK) == SA1_addsp_BITS) 1253*8ed1aee9SColin LeMahieu op = Hexagon::SA1_addsp; 1254*8ed1aee9SColin LeMahieu else if ((inst & SA1_and1_MASK) == SA1_and1_BITS) 1255*8ed1aee9SColin LeMahieu op = Hexagon::SA1_and1; 1256*8ed1aee9SColin LeMahieu else if ((inst & SA1_clrf_MASK) == SA1_clrf_BITS) 1257*8ed1aee9SColin LeMahieu op = Hexagon::SA1_clrf; 1258*8ed1aee9SColin LeMahieu else if ((inst & SA1_clrfnew_MASK) == SA1_clrfnew_BITS) 1259*8ed1aee9SColin LeMahieu op = Hexagon::SA1_clrfnew; 1260*8ed1aee9SColin LeMahieu else if ((inst & SA1_clrt_MASK) == SA1_clrt_BITS) 1261*8ed1aee9SColin LeMahieu op = Hexagon::SA1_clrt; 1262*8ed1aee9SColin LeMahieu else if ((inst & SA1_clrtnew_MASK) == SA1_clrtnew_BITS) 1263*8ed1aee9SColin LeMahieu op = Hexagon::SA1_clrtnew; 1264*8ed1aee9SColin LeMahieu else if ((inst & SA1_cmpeqi_MASK) == SA1_cmpeqi_BITS) 1265*8ed1aee9SColin LeMahieu op = Hexagon::SA1_cmpeqi; 1266*8ed1aee9SColin LeMahieu else if ((inst & SA1_combine0i_MASK) == SA1_combine0i_BITS) 1267*8ed1aee9SColin LeMahieu op = Hexagon::SA1_combine0i; 1268*8ed1aee9SColin LeMahieu else if ((inst & SA1_combine1i_MASK) == SA1_combine1i_BITS) 1269*8ed1aee9SColin LeMahieu op = Hexagon::SA1_combine1i; 1270*8ed1aee9SColin LeMahieu else if ((inst & SA1_combine2i_MASK) == SA1_combine2i_BITS) 1271*8ed1aee9SColin LeMahieu op = Hexagon::SA1_combine2i; 1272*8ed1aee9SColin LeMahieu else if ((inst & SA1_combine3i_MASK) == SA1_combine3i_BITS) 1273*8ed1aee9SColin LeMahieu op = Hexagon::SA1_combine3i; 1274*8ed1aee9SColin LeMahieu else if ((inst & SA1_combinerz_MASK) == SA1_combinerz_BITS) 1275*8ed1aee9SColin LeMahieu op = Hexagon::SA1_combinerz; 1276*8ed1aee9SColin LeMahieu else if ((inst & SA1_combinezr_MASK) == SA1_combinezr_BITS) 1277*8ed1aee9SColin LeMahieu op = Hexagon::SA1_combinezr; 1278*8ed1aee9SColin LeMahieu else if ((inst & SA1_dec_MASK) == SA1_dec_BITS) 1279*8ed1aee9SColin LeMahieu op = Hexagon::SA1_dec; 1280*8ed1aee9SColin LeMahieu else if ((inst & SA1_inc_MASK) == SA1_inc_BITS) 1281*8ed1aee9SColin LeMahieu op = Hexagon::SA1_inc; 1282*8ed1aee9SColin LeMahieu else if ((inst & SA1_seti_MASK) == SA1_seti_BITS) 1283*8ed1aee9SColin LeMahieu op = Hexagon::SA1_seti; 1284*8ed1aee9SColin LeMahieu else if ((inst & SA1_setin1_MASK) == SA1_setin1_BITS) 1285*8ed1aee9SColin LeMahieu op = Hexagon::SA1_setin1; 1286*8ed1aee9SColin LeMahieu else if ((inst & SA1_sxtb_MASK) == SA1_sxtb_BITS) 1287*8ed1aee9SColin LeMahieu op = Hexagon::SA1_sxtb; 1288*8ed1aee9SColin LeMahieu else if ((inst & SA1_sxth_MASK) == SA1_sxth_BITS) 1289*8ed1aee9SColin LeMahieu op = Hexagon::SA1_sxth; 1290*8ed1aee9SColin LeMahieu else if ((inst & SA1_tfr_MASK) == SA1_tfr_BITS) 1291*8ed1aee9SColin LeMahieu op = Hexagon::SA1_tfr; 1292*8ed1aee9SColin LeMahieu else if ((inst & SA1_zxtb_MASK) == SA1_zxtb_BITS) 1293*8ed1aee9SColin LeMahieu op = Hexagon::SA1_zxtb; 1294*8ed1aee9SColin LeMahieu else if ((inst & SA1_zxth_MASK) == SA1_zxth_BITS) 1295*8ed1aee9SColin LeMahieu op = Hexagon::SA1_zxth; 1296be8c453dSColin LeMahieu else { 1297be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1298be8c453dSColin LeMahieu return MCDisassembler::Fail; 1299be8c453dSColin LeMahieu } 1300be8c453dSColin LeMahieu break; 1301be8c453dSColin LeMahieu case HexagonII::HSIG_S1: 1302*8ed1aee9SColin LeMahieu if ((inst & SS1_storeb_io_MASK) == SS1_storeb_io_BITS) 1303*8ed1aee9SColin LeMahieu op = Hexagon::SS1_storeb_io; 1304*8ed1aee9SColin LeMahieu else if ((inst & SS1_storew_io_MASK) == SS1_storew_io_BITS) 1305*8ed1aee9SColin LeMahieu op = Hexagon::SS1_storew_io; 1306be8c453dSColin LeMahieu else { 1307be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1308be8c453dSColin LeMahieu return MCDisassembler::Fail; 1309be8c453dSColin LeMahieu } 1310be8c453dSColin LeMahieu break; 1311be8c453dSColin LeMahieu case HexagonII::HSIG_S2: 1312*8ed1aee9SColin LeMahieu if ((inst & SS2_allocframe_MASK) == SS2_allocframe_BITS) 1313*8ed1aee9SColin LeMahieu op = Hexagon::SS2_allocframe; 1314*8ed1aee9SColin LeMahieu else if ((inst & SS2_storebi0_MASK) == SS2_storebi0_BITS) 1315*8ed1aee9SColin LeMahieu op = Hexagon::SS2_storebi0; 1316*8ed1aee9SColin LeMahieu else if ((inst & SS2_storebi1_MASK) == SS2_storebi1_BITS) 1317*8ed1aee9SColin LeMahieu op = Hexagon::SS2_storebi1; 1318*8ed1aee9SColin LeMahieu else if ((inst & SS2_stored_sp_MASK) == SS2_stored_sp_BITS) 1319*8ed1aee9SColin LeMahieu op = Hexagon::SS2_stored_sp; 1320*8ed1aee9SColin LeMahieu else if ((inst & SS2_storeh_io_MASK) == SS2_storeh_io_BITS) 1321*8ed1aee9SColin LeMahieu op = Hexagon::SS2_storeh_io; 1322*8ed1aee9SColin LeMahieu else if ((inst & SS2_storew_sp_MASK) == SS2_storew_sp_BITS) 1323*8ed1aee9SColin LeMahieu op = Hexagon::SS2_storew_sp; 1324*8ed1aee9SColin LeMahieu else if ((inst & SS2_storewi0_MASK) == SS2_storewi0_BITS) 1325*8ed1aee9SColin LeMahieu op = Hexagon::SS2_storewi0; 1326*8ed1aee9SColin LeMahieu else if ((inst & SS2_storewi1_MASK) == SS2_storewi1_BITS) 1327*8ed1aee9SColin LeMahieu op = Hexagon::SS2_storewi1; 1328be8c453dSColin LeMahieu else { 1329be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1330be8c453dSColin LeMahieu return MCDisassembler::Fail; 1331be8c453dSColin LeMahieu } 1332be8c453dSColin LeMahieu break; 1333be8c453dSColin LeMahieu default: 1334be8c453dSColin LeMahieu os << "<unknown>"; 1335be8c453dSColin LeMahieu return MCDisassembler::Fail; 1336be8c453dSColin LeMahieu } 1337be8c453dSColin LeMahieu return MCDisassembler::Success; 1338be8c453dSColin LeMahieu } 1339be8c453dSColin LeMahieu 1340be8c453dSColin LeMahieu static unsigned getRegFromSubinstEncoding(unsigned encoded_reg) { 1341be8c453dSColin LeMahieu if (encoded_reg < 8) 1342be8c453dSColin LeMahieu return Hexagon::R0 + encoded_reg; 1343be8c453dSColin LeMahieu else if (encoded_reg < 16) 1344be8c453dSColin LeMahieu return Hexagon::R0 + encoded_reg + 8; 13457cd08927SColin LeMahieu 13467cd08927SColin LeMahieu // patently false value 1347be8c453dSColin LeMahieu return Hexagon::NoRegister; 1348be8c453dSColin LeMahieu } 1349be8c453dSColin LeMahieu 1350be8c453dSColin LeMahieu static unsigned getDRegFromSubinstEncoding(unsigned encoded_dreg) { 1351be8c453dSColin LeMahieu if (encoded_dreg < 4) 1352be8c453dSColin LeMahieu return Hexagon::D0 + encoded_dreg; 1353be8c453dSColin LeMahieu else if (encoded_dreg < 8) 1354be8c453dSColin LeMahieu return Hexagon::D0 + encoded_dreg + 4; 13557cd08927SColin LeMahieu 13567cd08927SColin LeMahieu // patently false value 1357be8c453dSColin LeMahieu return Hexagon::NoRegister; 1358be8c453dSColin LeMahieu } 1359be8c453dSColin LeMahieu 13607cd08927SColin LeMahieu void HexagonDisassembler::addSubinstOperands(MCInst *MI, unsigned opcode, 13617cd08927SColin LeMahieu unsigned inst) const { 1362be8c453dSColin LeMahieu int64_t operand; 1363be8c453dSColin LeMahieu MCOperand Op; 1364be8c453dSColin LeMahieu switch (opcode) { 1365*8ed1aee9SColin LeMahieu case Hexagon::SL2_deallocframe: 1366*8ed1aee9SColin LeMahieu case Hexagon::SL2_jumpr31: 1367*8ed1aee9SColin LeMahieu case Hexagon::SL2_jumpr31_f: 1368*8ed1aee9SColin LeMahieu case Hexagon::SL2_jumpr31_fnew: 1369*8ed1aee9SColin LeMahieu case Hexagon::SL2_jumpr31_t: 1370*8ed1aee9SColin LeMahieu case Hexagon::SL2_jumpr31_tnew: 1371*8ed1aee9SColin LeMahieu case Hexagon::SL2_return: 1372*8ed1aee9SColin LeMahieu case Hexagon::SL2_return_f: 1373*8ed1aee9SColin LeMahieu case Hexagon::SL2_return_fnew: 1374*8ed1aee9SColin LeMahieu case Hexagon::SL2_return_t: 1375*8ed1aee9SColin LeMahieu case Hexagon::SL2_return_tnew: 1376be8c453dSColin LeMahieu // no operands for these instructions 1377be8c453dSColin LeMahieu break; 1378*8ed1aee9SColin LeMahieu case Hexagon::SS2_allocframe: 1379be8c453dSColin LeMahieu // u 8-4{5_3} 1380be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 3; 13817cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1382be8c453dSColin LeMahieu break; 1383*8ed1aee9SColin LeMahieu case Hexagon::SL1_loadri_io: 1384be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 11-8{4_2} 1385be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1386be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1387be8c453dSColin LeMahieu MI->addOperand(Op); 1388be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1389be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1390be8c453dSColin LeMahieu MI->addOperand(Op); 1391be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 6; 13927cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1393be8c453dSColin LeMahieu break; 1394*8ed1aee9SColin LeMahieu case Hexagon::SL1_loadrub_io: 1395be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 11-8 1396be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1397be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1398be8c453dSColin LeMahieu MI->addOperand(Op); 1399be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1400be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1401be8c453dSColin LeMahieu MI->addOperand(Op); 1402be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 8; 14037cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1404be8c453dSColin LeMahieu break; 1405*8ed1aee9SColin LeMahieu case Hexagon::SL2_loadrb_io: 1406be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 10-8 1407be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1408be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1409be8c453dSColin LeMahieu MI->addOperand(Op); 1410be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1411be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1412be8c453dSColin LeMahieu MI->addOperand(Op); 1413be8c453dSColin LeMahieu operand = (inst & 0x700) >> 8; 14147cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1415be8c453dSColin LeMahieu break; 1416*8ed1aee9SColin LeMahieu case Hexagon::SL2_loadrh_io: 1417*8ed1aee9SColin LeMahieu case Hexagon::SL2_loadruh_io: 1418be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 10-8{3_1} 1419be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1420be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1421be8c453dSColin LeMahieu MI->addOperand(Op); 1422be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1423be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1424be8c453dSColin LeMahieu MI->addOperand(Op); 1425be8c453dSColin LeMahieu operand = ((inst & 0x700) >> 8) << 1; 14267cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1427be8c453dSColin LeMahieu break; 1428*8ed1aee9SColin LeMahieu case Hexagon::SL2_loadrd_sp: 1429be8c453dSColin LeMahieu // Rdd 2-0, u 7-3{5_3} 1430be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1431be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1432be8c453dSColin LeMahieu MI->addOperand(Op); 1433be8c453dSColin LeMahieu operand = ((inst & 0x0f8) >> 3) << 3; 14347cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1435be8c453dSColin LeMahieu break; 1436*8ed1aee9SColin LeMahieu case Hexagon::SL2_loadri_sp: 1437be8c453dSColin LeMahieu // Rd 3-0, u 8-4{5_2} 1438be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1439be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1440be8c453dSColin LeMahieu MI->addOperand(Op); 1441be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 2; 14427cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1443be8c453dSColin LeMahieu break; 1444*8ed1aee9SColin LeMahieu case Hexagon::SA1_addi: 1445be8c453dSColin LeMahieu // Rx 3-0 (x2), s7 10-4 1446be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1447be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1448be8c453dSColin LeMahieu MI->addOperand(Op); 1449be8c453dSColin LeMahieu MI->addOperand(Op); 1450be8c453dSColin LeMahieu operand = SignExtend64<7>((inst & 0x7f0) >> 4); 14517cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1452be8c453dSColin LeMahieu break; 1453*8ed1aee9SColin LeMahieu case Hexagon::SA1_addrx: 1454be8c453dSColin LeMahieu // Rx 3-0 (x2), Rs 7-4 1455be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1456be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1457be8c453dSColin LeMahieu MI->addOperand(Op); 1458be8c453dSColin LeMahieu MI->addOperand(Op); 1459be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1460be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1461be8c453dSColin LeMahieu MI->addOperand(Op); 1462bb0cdfb9SColin LeMahieu break; 1463*8ed1aee9SColin LeMahieu case Hexagon::SA1_and1: 1464*8ed1aee9SColin LeMahieu case Hexagon::SA1_dec: 1465*8ed1aee9SColin LeMahieu case Hexagon::SA1_inc: 1466*8ed1aee9SColin LeMahieu case Hexagon::SA1_sxtb: 1467*8ed1aee9SColin LeMahieu case Hexagon::SA1_sxth: 1468*8ed1aee9SColin LeMahieu case Hexagon::SA1_tfr: 1469*8ed1aee9SColin LeMahieu case Hexagon::SA1_zxtb: 1470*8ed1aee9SColin LeMahieu case Hexagon::SA1_zxth: 1471be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4 1472be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1473be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1474be8c453dSColin LeMahieu MI->addOperand(Op); 1475be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1476be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1477be8c453dSColin LeMahieu MI->addOperand(Op); 1478be8c453dSColin LeMahieu break; 1479*8ed1aee9SColin LeMahieu case Hexagon::SA1_addsp: 1480be8c453dSColin LeMahieu // Rd 3-0, u 9-4{6_2} 1481be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1482be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1483be8c453dSColin LeMahieu MI->addOperand(Op); 1484be8c453dSColin LeMahieu operand = ((inst & 0x3f0) >> 4) << 2; 14857cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1486be8c453dSColin LeMahieu break; 1487*8ed1aee9SColin LeMahieu case Hexagon::SA1_seti: 1488be8c453dSColin LeMahieu // Rd 3-0, u 9-4 1489be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1490be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1491be8c453dSColin LeMahieu MI->addOperand(Op); 1492be8c453dSColin LeMahieu operand = (inst & 0x3f0) >> 4; 14937cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1494be8c453dSColin LeMahieu break; 1495*8ed1aee9SColin LeMahieu case Hexagon::SA1_clrf: 1496*8ed1aee9SColin LeMahieu case Hexagon::SA1_clrfnew: 1497*8ed1aee9SColin LeMahieu case Hexagon::SA1_clrt: 1498*8ed1aee9SColin LeMahieu case Hexagon::SA1_clrtnew: 1499*8ed1aee9SColin LeMahieu case Hexagon::SA1_setin1: 1500be8c453dSColin LeMahieu // Rd 3-0 1501be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1502be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1503be8c453dSColin LeMahieu MI->addOperand(Op); 1504*8ed1aee9SColin LeMahieu if (opcode == Hexagon::SA1_setin1) 150573e0ad82SKrzysztof Parzyszek break; 150673e0ad82SKrzysztof Parzyszek MI->addOperand(MCOperand::createReg(Hexagon::P0)); 1507be8c453dSColin LeMahieu break; 1508*8ed1aee9SColin LeMahieu case Hexagon::SA1_cmpeqi: 1509be8c453dSColin LeMahieu // Rs 7-4, u 1-0 1510be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1511be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1512be8c453dSColin LeMahieu MI->addOperand(Op); 1513be8c453dSColin LeMahieu operand = inst & 0x3; 15147cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1515be8c453dSColin LeMahieu break; 1516*8ed1aee9SColin LeMahieu case Hexagon::SA1_combine0i: 1517*8ed1aee9SColin LeMahieu case Hexagon::SA1_combine1i: 1518*8ed1aee9SColin LeMahieu case Hexagon::SA1_combine2i: 1519*8ed1aee9SColin LeMahieu case Hexagon::SA1_combine3i: 1520be8c453dSColin LeMahieu // Rdd 2-0, u 6-5 1521be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1522be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1523be8c453dSColin LeMahieu MI->addOperand(Op); 1524be8c453dSColin LeMahieu operand = (inst & 0x060) >> 5; 15257cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1526be8c453dSColin LeMahieu break; 1527*8ed1aee9SColin LeMahieu case Hexagon::SA1_combinerz: 1528*8ed1aee9SColin LeMahieu case Hexagon::SA1_combinezr: 1529be8c453dSColin LeMahieu // Rdd 2-0, Rs 7-4 1530be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1531be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1532be8c453dSColin LeMahieu MI->addOperand(Op); 1533be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1534be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1535be8c453dSColin LeMahieu MI->addOperand(Op); 1536be8c453dSColin LeMahieu break; 1537*8ed1aee9SColin LeMahieu case Hexagon::SS1_storeb_io: 1538be8c453dSColin LeMahieu // Rs 7-4, u 11-8, Rt 3-0 1539be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1540be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1541be8c453dSColin LeMahieu MI->addOperand(Op); 1542be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 8; 15437cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1544be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1545be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1546be8c453dSColin LeMahieu MI->addOperand(Op); 1547be8c453dSColin LeMahieu break; 1548*8ed1aee9SColin LeMahieu case Hexagon::SS1_storew_io: 1549be8c453dSColin LeMahieu // Rs 7-4, u 11-8{4_2}, Rt 3-0 1550be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1551be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1552be8c453dSColin LeMahieu MI->addOperand(Op); 1553be8c453dSColin LeMahieu operand = ((inst & 0xf00) >> 8) << 2; 15547cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1555be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1556be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1557be8c453dSColin LeMahieu MI->addOperand(Op); 1558be8c453dSColin LeMahieu break; 1559*8ed1aee9SColin LeMahieu case Hexagon::SS2_storebi0: 1560*8ed1aee9SColin LeMahieu case Hexagon::SS2_storebi1: 1561be8c453dSColin LeMahieu // Rs 7-4, u 3-0 1562be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1563be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1564be8c453dSColin LeMahieu MI->addOperand(Op); 1565be8c453dSColin LeMahieu operand = inst & 0xf; 15667cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1567be8c453dSColin LeMahieu break; 1568*8ed1aee9SColin LeMahieu case Hexagon::SS2_storewi0: 1569*8ed1aee9SColin LeMahieu case Hexagon::SS2_storewi1: 1570be8c453dSColin LeMahieu // Rs 7-4, u 3-0{4_2} 1571be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1572be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1573be8c453dSColin LeMahieu MI->addOperand(Op); 1574be8c453dSColin LeMahieu operand = (inst & 0xf) << 2; 15757cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1576be8c453dSColin LeMahieu break; 1577*8ed1aee9SColin LeMahieu case Hexagon::SS2_stored_sp: 1578be8c453dSColin LeMahieu // s 8-3{6_3}, Rtt 2-0 1579be8c453dSColin LeMahieu operand = SignExtend64<9>(((inst & 0x1f8) >> 3) << 3); 15807cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1581be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1582be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1583be8c453dSColin LeMahieu MI->addOperand(Op); 1584160f73e3SColin LeMahieu break; 1585*8ed1aee9SColin LeMahieu case Hexagon::SS2_storeh_io: 1586be8c453dSColin LeMahieu // Rs 7-4, u 10-8{3_1}, Rt 3-0 1587be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1588be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1589be8c453dSColin LeMahieu MI->addOperand(Op); 1590be8c453dSColin LeMahieu operand = ((inst & 0x700) >> 8) << 1; 15917cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1592be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1593be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1594be8c453dSColin LeMahieu MI->addOperand(Op); 1595be8c453dSColin LeMahieu break; 1596*8ed1aee9SColin LeMahieu case Hexagon::SS2_storew_sp: 1597be8c453dSColin LeMahieu // u 8-4{5_2}, Rd 3-0 1598be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 2; 15997cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1600be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1601be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1602be8c453dSColin LeMahieu MI->addOperand(Op); 1603be8c453dSColin LeMahieu break; 1604be8c453dSColin LeMahieu default: 1605be8c453dSColin LeMahieu // don't crash with an invalid subinstruction 1606be8c453dSColin LeMahieu // llvm_unreachable("Invalid subinstruction in duplex instruction"); 1607be8c453dSColin LeMahieu break; 1608be8c453dSColin LeMahieu } 1609be8c453dSColin LeMahieu } 1610