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" 33d9903888SChandler Carruth #include <vector> 3488ebb9e2SColin LeMahieu 3588ebb9e2SColin LeMahieu using namespace llvm; 3668d967d9SColin LeMahieu using namespace Hexagon; 3788ebb9e2SColin LeMahieu 387cd08927SColin LeMahieu typedef MCDisassembler::DecodeStatus DecodeStatus; 3988ebb9e2SColin LeMahieu 4088ebb9e2SColin LeMahieu namespace { 4188ebb9e2SColin LeMahieu /// \brief Hexagon disassembler for all Hexagon platforms. 4288ebb9e2SColin LeMahieu class HexagonDisassembler : public MCDisassembler { 4388ebb9e2SColin LeMahieu public: 447cd08927SColin LeMahieu std::unique_ptr<MCInstrInfo const> const MCII; 4568d967d9SColin LeMahieu std::unique_ptr<MCInst *> CurrentBundle; 467cd08927SColin LeMahieu HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, 477cd08927SColin LeMahieu MCInstrInfo const *MCII) 487cd08927SColin LeMahieu : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *) {} 4988ebb9e2SColin LeMahieu 5068d967d9SColin LeMahieu DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB, 5168d967d9SColin LeMahieu ArrayRef<uint8_t> Bytes, uint64_t Address, 5268d967d9SColin LeMahieu raw_ostream &VStream, raw_ostream &CStream, 5368d967d9SColin LeMahieu bool &Complete) const; 544aa6bea7SRafael Espindola DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, 557fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes, uint64_t Address, 564aa6bea7SRafael Espindola raw_ostream &VStream, 574aa6bea7SRafael Espindola raw_ostream &CStream) const override; 587cd08927SColin LeMahieu 597cd08927SColin LeMahieu void adjustExtendedInstructions(MCInst &MCI, MCInst const &MCB) const; 607cd08927SColin LeMahieu void addSubinstOperands(MCInst *MI, unsigned opcode, unsigned inst) const; 6188ebb9e2SColin LeMahieu }; 62f00654e3SAlexander Kornienko } 6388ebb9e2SColin LeMahieu 647cd08927SColin LeMahieu // Forward declare these because the auto-generated code will reference them. 657cd08927SColin LeMahieu // Definitions are further down. 667cd08927SColin LeMahieu 677cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 68be8c453dSColin LeMahieu uint64_t Address, 69be8c453dSColin LeMahieu const void *Decoder); 707c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 717c958713SColin LeMahieu uint64_t Address, 727c958713SColin LeMahieu const void *Decoder); 737c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 747c958713SColin LeMahieu uint64_t Address, 757c958713SColin LeMahieu const void *Decoder); 767cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 777cd08927SColin LeMahieu uint64_t Address, 787cd08927SColin LeMahieu const void *Decoder); 797c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 807c958713SColin LeMahieu uint64_t Address, 817c958713SColin LeMahieu const void *Decoder); 827cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 837cd08927SColin LeMahieu uint64_t Address, 847cd08927SColin LeMahieu const void *Decoder); 857c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 867c958713SColin LeMahieu uint64_t Address, 877c958713SColin LeMahieu const void *Decoder); 88f3db884eSColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 89be8c453dSColin LeMahieu uint64_t Address, 90be8c453dSColin LeMahieu const void *Decoder); 917cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, 927cd08927SColin LeMahieu uint64_t Address, 937cd08927SColin LeMahieu const void *Decoder); 94404d5b24SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 95be8c453dSColin LeMahieu uint64_t Address, 967cd08927SColin LeMahieu const void *Decoder); 977cd08927SColin LeMahieu 987cd08927SColin LeMahieu static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn); 997cd08927SColin LeMahieu static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn, 100be8c453dSColin LeMahieu void const *Decoder); 101be8c453dSColin LeMahieu 102be8c453dSColin LeMahieu static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op, 103be8c453dSColin LeMahieu raw_ostream &os); 104f3db884eSColin LeMahieu 1057cd08927SColin LeMahieu static unsigned getRegFromSubinstEncoding(unsigned encoded_reg); 1067cd08927SColin LeMahieu 1077cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 1087cd08927SColin LeMahieu uint64_t Address, const void *Decoder); 1091e9d1d76SColin LeMahieu static DecodeStatus s16ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1101e9d1d76SColin LeMahieu const void *Decoder); 1111e9d1d76SColin LeMahieu static DecodeStatus s12ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1121e9d1d76SColin LeMahieu const void *Decoder); 1131e9d1d76SColin LeMahieu static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1141e9d1d76SColin LeMahieu const void *Decoder); 1151e9d1d76SColin LeMahieu static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1161e9d1d76SColin LeMahieu const void *Decoder); 1171e9d1d76SColin LeMahieu static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1181e9d1d76SColin LeMahieu const void *Decoder); 1191e9d1d76SColin LeMahieu static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1201e9d1d76SColin LeMahieu const void *Decoder); 1211e9d1d76SColin LeMahieu static DecodeStatus s10ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1221e9d1d76SColin LeMahieu const void *Decoder); 1231e9d1d76SColin LeMahieu static DecodeStatus s8ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1241e9d1d76SColin LeMahieu const void *Decoder); 1251e9d1d76SColin LeMahieu static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1261e9d1d76SColin LeMahieu const void *Decoder); 1271e9d1d76SColin LeMahieu static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1281e9d1d76SColin LeMahieu const void *Decoder); 1291e9d1d76SColin LeMahieu static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1301e9d1d76SColin LeMahieu const void *Decoder); 1311e9d1d76SColin LeMahieu static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1321e9d1d76SColin LeMahieu const void *Decoder); 1331e9d1d76SColin LeMahieu static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1341e9d1d76SColin LeMahieu const void *Decoder); 1357c958713SColin LeMahieu static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1367c958713SColin LeMahieu const void *Decoder); 1377c958713SColin LeMahieu static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1387c958713SColin LeMahieu const void *Decoder); 1397cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 1407cd08927SColin LeMahieu const void *Decoder); 141efa74e02SColin LeMahieu 14288ebb9e2SColin LeMahieu #include "HexagonGenDisassemblerTables.inc" 14388ebb9e2SColin LeMahieu 1447cd08927SColin LeMahieu static MCDisassembler *createHexagonDisassembler(const Target &T, 1457cd08927SColin LeMahieu const MCSubtargetInfo &STI, 14688ebb9e2SColin LeMahieu MCContext &Ctx) { 1477cd08927SColin LeMahieu return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo()); 14888ebb9e2SColin LeMahieu } 14988ebb9e2SColin LeMahieu 15088ebb9e2SColin LeMahieu extern "C" void LLVMInitializeHexagonDisassembler() { 15188ebb9e2SColin LeMahieu TargetRegistry::RegisterMCDisassembler(TheHexagonTarget, 15288ebb9e2SColin LeMahieu createHexagonDisassembler); 15388ebb9e2SColin LeMahieu } 15488ebb9e2SColin LeMahieu 15588ebb9e2SColin LeMahieu DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size, 1567fc5b874SRafael Espindola ArrayRef<uint8_t> Bytes, 15788ebb9e2SColin LeMahieu uint64_t Address, 15888ebb9e2SColin LeMahieu raw_ostream &os, 15988ebb9e2SColin LeMahieu raw_ostream &cs) const { 16068d967d9SColin LeMahieu DecodeStatus Result = DecodeStatus::Success; 16168d967d9SColin LeMahieu bool Complete = false; 16268d967d9SColin LeMahieu Size = 0; 1634aa6bea7SRafael Espindola 16468d967d9SColin LeMahieu *CurrentBundle = &MI; 165f0af6e52SColin LeMahieu MI = HexagonMCInstrInfo::createBundle(); 166be8c453dSColin LeMahieu while (Result == Success && Complete == false) { 16768d967d9SColin LeMahieu if (Bytes.size() < HEXAGON_INSTR_SIZE) 16868d967d9SColin LeMahieu return MCDisassembler::Fail; 16968d967d9SColin LeMahieu MCInst *Inst = new (getContext()) MCInst; 17068d967d9SColin LeMahieu Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete); 17168d967d9SColin LeMahieu MI.addOperand(MCOperand::createInst(Inst)); 17268d967d9SColin LeMahieu Size += HEXAGON_INSTR_SIZE; 17368d967d9SColin LeMahieu Bytes = Bytes.slice(HEXAGON_INSTR_SIZE); 17468d967d9SColin LeMahieu } 1757cd08927SColin LeMahieu if(Result == MCDisassembler::Fail) 17668d967d9SColin LeMahieu return Result; 1777cd08927SColin LeMahieu HexagonMCChecker Checker (*MCII, STI, MI, MI, *getContext().getRegisterInfo()); 1787cd08927SColin LeMahieu if(!Checker.check()) 1797cd08927SColin LeMahieu return MCDisassembler::Fail; 1807cd08927SColin LeMahieu return MCDisassembler::Success; 1817cd08927SColin LeMahieu } 1827cd08927SColin LeMahieu 1837cd08927SColin LeMahieu namespace { 1847cd08927SColin LeMahieu HexagonDisassembler const &disassembler(void const *Decoder) { 1857cd08927SColin LeMahieu return *static_cast<HexagonDisassembler const *>(Decoder); 1867cd08927SColin LeMahieu } 1877cd08927SColin LeMahieu MCContext &contextFromDecoder(void const *Decoder) { 1887cd08927SColin LeMahieu return disassembler(Decoder).getContext(); 1897cd08927SColin LeMahieu } 19068d967d9SColin LeMahieu } 19168d967d9SColin LeMahieu 19268d967d9SColin LeMahieu DecodeStatus HexagonDisassembler::getSingleInstruction( 19368d967d9SColin LeMahieu MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address, 19468d967d9SColin LeMahieu raw_ostream &os, raw_ostream &cs, bool &Complete) const { 19568d967d9SColin LeMahieu assert(Bytes.size() >= HEXAGON_INSTR_SIZE); 19668d967d9SColin LeMahieu 19768d967d9SColin LeMahieu uint32_t Instruction = 1987cd08927SColin LeMahieu (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0); 19988ebb9e2SColin LeMahieu 20068d967d9SColin LeMahieu auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB); 20168d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 20268d967d9SColin LeMahieu HexagonII::INST_PARSE_LOOP_END) { 20368d967d9SColin LeMahieu if (BundleSize == 0) 20468d967d9SColin LeMahieu HexagonMCInstrInfo::setInnerLoop(MCB); 20568d967d9SColin LeMahieu else if (BundleSize == 1) 20668d967d9SColin LeMahieu HexagonMCInstrInfo::setOuterLoop(MCB); 20768d967d9SColin LeMahieu else 20868d967d9SColin LeMahieu return DecodeStatus::Fail; 20968d967d9SColin LeMahieu } 21068d967d9SColin LeMahieu 21168d967d9SColin LeMahieu DecodeStatus Result = DecodeStatus::Success; 21268d967d9SColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 213be8c453dSColin LeMahieu HexagonII::INST_PARSE_DUPLEX) { 214be8c453dSColin LeMahieu // Determine the instruction class of each instruction in the duplex. 215be8c453dSColin LeMahieu unsigned duplexIClass, IClassLow, IClassHigh; 216be8c453dSColin LeMahieu 217be8c453dSColin LeMahieu duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1); 218be8c453dSColin LeMahieu switch (duplexIClass) { 219be8c453dSColin LeMahieu default: 220be8c453dSColin LeMahieu return MCDisassembler::Fail; 221be8c453dSColin LeMahieu case 0: 222be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L1; 223be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 224be8c453dSColin LeMahieu break; 225be8c453dSColin LeMahieu case 1: 226be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L2; 227be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 228be8c453dSColin LeMahieu break; 229be8c453dSColin LeMahieu case 2: 230be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L2; 231be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L2; 232be8c453dSColin LeMahieu break; 233be8c453dSColin LeMahieu case 3: 234be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_A; 235be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 236be8c453dSColin LeMahieu break; 237be8c453dSColin LeMahieu case 4: 238be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L1; 239be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 240be8c453dSColin LeMahieu break; 241be8c453dSColin LeMahieu case 5: 242be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_L2; 243be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 244be8c453dSColin LeMahieu break; 245be8c453dSColin LeMahieu case 6: 246be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 247be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 248be8c453dSColin LeMahieu break; 249be8c453dSColin LeMahieu case 7: 250be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 251be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_A; 252be8c453dSColin LeMahieu break; 253be8c453dSColin LeMahieu case 8: 254be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 255be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 256be8c453dSColin LeMahieu break; 257be8c453dSColin LeMahieu case 9: 258be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 259be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L2; 260be8c453dSColin LeMahieu break; 261be8c453dSColin LeMahieu case 10: 262be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S1; 263be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_S1; 264be8c453dSColin LeMahieu break; 265be8c453dSColin LeMahieu case 11: 266be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 267be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_S1; 268be8c453dSColin LeMahieu break; 269be8c453dSColin LeMahieu case 12: 270be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 271be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L1; 272be8c453dSColin LeMahieu break; 273be8c453dSColin LeMahieu case 13: 274be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 275be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_L2; 276be8c453dSColin LeMahieu break; 277be8c453dSColin LeMahieu case 14: 278be8c453dSColin LeMahieu IClassLow = HexagonII::HSIG_S2; 279be8c453dSColin LeMahieu IClassHigh = HexagonII::HSIG_S2; 280be8c453dSColin LeMahieu break; 281be8c453dSColin LeMahieu } 282be8c453dSColin LeMahieu 283be8c453dSColin LeMahieu // Set the MCInst to be a duplex instruction. Which one doesn't matter. 284be8c453dSColin LeMahieu MI.setOpcode(Hexagon::DuplexIClass0); 285be8c453dSColin LeMahieu 286be8c453dSColin LeMahieu // Decode each instruction in the duplex. 287be8c453dSColin LeMahieu // Create an MCInst for each instruction. 288be8c453dSColin LeMahieu unsigned instLow = Instruction & 0x1fff; 289be8c453dSColin LeMahieu unsigned instHigh = (Instruction >> 16) & 0x1fff; 290be8c453dSColin LeMahieu unsigned opLow; 291be8c453dSColin LeMahieu if (GetSubinstOpcode(IClassLow, instLow, opLow, os) != 292be8c453dSColin LeMahieu MCDisassembler::Success) 293be8c453dSColin LeMahieu return MCDisassembler::Fail; 294be8c453dSColin LeMahieu unsigned opHigh; 295be8c453dSColin LeMahieu if (GetSubinstOpcode(IClassHigh, instHigh, opHigh, os) != 296be8c453dSColin LeMahieu MCDisassembler::Success) 297be8c453dSColin LeMahieu return MCDisassembler::Fail; 298be8c453dSColin LeMahieu MCInst *MILow = new (getContext()) MCInst; 299be8c453dSColin LeMahieu MILow->setOpcode(opLow); 300be8c453dSColin LeMahieu MCInst *MIHigh = new (getContext()) MCInst; 301be8c453dSColin LeMahieu MIHigh->setOpcode(opHigh); 3027cd08927SColin LeMahieu addSubinstOperands(MILow, opLow, instLow); 3037cd08927SColin LeMahieu addSubinstOperands(MIHigh, opHigh, instHigh); 304be8c453dSColin LeMahieu // see ConvertToSubInst() in 305be8c453dSColin LeMahieu // lib/Target/Hexagon/MCTargetDesc/HexagonMCDuplexInfo.cpp 306be8c453dSColin LeMahieu 307be8c453dSColin LeMahieu // Add the duplex instruction MCInsts as operands to the passed in MCInst. 308be8c453dSColin LeMahieu MCOperand OPLow = MCOperand::createInst(MILow); 309be8c453dSColin LeMahieu MCOperand OPHigh = MCOperand::createInst(MIHigh); 310be8c453dSColin LeMahieu MI.addOperand(OPLow); 311be8c453dSColin LeMahieu MI.addOperand(OPHigh); 312be8c453dSColin LeMahieu Complete = true; 313be8c453dSColin LeMahieu } else { 314be8c453dSColin LeMahieu if ((Instruction & HexagonII::INST_PARSE_MASK) == 31568d967d9SColin LeMahieu HexagonII::INST_PARSE_PACKET_END) 31668d967d9SColin LeMahieu Complete = true; 31768d967d9SColin LeMahieu // Calling the auto-generated decoder function. 31868d967d9SColin LeMahieu Result = 31968d967d9SColin LeMahieu decodeInstruction(DecoderTable32, MI, Instruction, Address, this, STI); 3207cd08927SColin LeMahieu 3217cd08927SColin LeMahieu // If a, "standard" insn isn't found check special cases. 3227cd08927SColin LeMahieu if (MCDisassembler::Success != Result || 3237cd08927SColin LeMahieu MI.getOpcode() == Hexagon::A4_ext) { 3247cd08927SColin LeMahieu Result = decodeImmext(MI, Instruction, this); 3257cd08927SColin LeMahieu if (MCDisassembler::Success != Result) { 3267cd08927SColin LeMahieu Result = decodeSpecial(MI, Instruction); 3277cd08927SColin LeMahieu } 3287cd08927SColin LeMahieu } else { 3297cd08927SColin LeMahieu // If the instruction is a compound instruction, register values will 3307cd08927SColin LeMahieu // follow the duplex model, so the register values in the MCInst are 3317cd08927SColin LeMahieu // incorrect. If the instruction is a compound, loop through the 3327cd08927SColin LeMahieu // operands and change registers appropriately. 3337cd08927SColin LeMahieu if (llvm::HexagonMCInstrInfo::getType(*MCII, MI) == 3347cd08927SColin LeMahieu HexagonII::TypeCOMPOUND) { 3357cd08927SColin LeMahieu for (MCInst::iterator i = MI.begin(), last = MI.end(); i < last; ++i) { 3367cd08927SColin LeMahieu if (i->isReg()) { 3377cd08927SColin LeMahieu unsigned reg = i->getReg() - Hexagon::R0; 3387cd08927SColin LeMahieu i->setReg(getRegFromSubinstEncoding(reg)); 3397cd08927SColin LeMahieu } 3407cd08927SColin LeMahieu } 3417cd08927SColin LeMahieu } 3427cd08927SColin LeMahieu } 343be8c453dSColin LeMahieu } 34468d967d9SColin LeMahieu 3457cd08927SColin LeMahieu if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) { 3467cd08927SColin LeMahieu unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI); 3477cd08927SColin LeMahieu MCOperand &MCO = MI.getOperand(OpIndex); 3487cd08927SColin LeMahieu assert(MCO.isReg() && "New value consumers must be registers"); 3497cd08927SColin LeMahieu unsigned Register = 3507cd08927SColin LeMahieu getContext().getRegisterInfo()->getEncodingValue(MCO.getReg()); 3517cd08927SColin LeMahieu if ((Register & 0x6) == 0) 3527cd08927SColin LeMahieu // HexagonPRM 10.11 Bit 1-2 == 0 is reserved 3537cd08927SColin LeMahieu return MCDisassembler::Fail; 3547cd08927SColin LeMahieu unsigned Lookback = (Register & 0x6) >> 1; 3557cd08927SColin LeMahieu unsigned Offset = 1; 3567cd08927SColin LeMahieu bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI); 3577cd08927SColin LeMahieu auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); 3587cd08927SColin LeMahieu auto i = Instructions.end() - 1; 3597cd08927SColin LeMahieu for (auto n = Instructions.begin() - 1;; --i, ++Offset) { 3607cd08927SColin LeMahieu if (i == n) 3617cd08927SColin LeMahieu // Couldn't find producer 3627cd08927SColin LeMahieu return MCDisassembler::Fail; 3637cd08927SColin LeMahieu if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst())) 3647cd08927SColin LeMahieu // Skip scalars when calculating distances for vectors 3657cd08927SColin LeMahieu ++Lookback; 3667cd08927SColin LeMahieu if (HexagonMCInstrInfo::isImmext(*i->getInst())) 3677cd08927SColin LeMahieu ++Lookback; 3687cd08927SColin LeMahieu if (Offset == Lookback) 3697cd08927SColin LeMahieu break; 3707cd08927SColin LeMahieu } 3717cd08927SColin LeMahieu auto const &Inst = *i->getInst(); 3727cd08927SColin LeMahieu bool SubregBit = (Register & 0x1) != 0; 3737cd08927SColin LeMahieu if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) { 3747cd08927SColin LeMahieu // If subreg bit is set we're selecting the second produced newvalue 3757cd08927SColin LeMahieu unsigned Producer = 3767cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg(); 3777cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 3787cd08927SColin LeMahieu MCO.setReg(Producer); 3797cd08927SColin LeMahieu } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) { 3807cd08927SColin LeMahieu unsigned Producer = 3817cd08927SColin LeMahieu HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg(); 3827cd08927SColin LeMahieu if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15) 3837cd08927SColin LeMahieu Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0; 3847cd08927SColin LeMahieu else if (SubregBit) 3856fdfa3dcSColin LeMahieu // Hexagon PRM 10.11 New-value operands 3866fdfa3dcSColin LeMahieu // Nt[0] is reserved and should always be encoded as zero. 3877cd08927SColin LeMahieu return MCDisassembler::Fail; 3887cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 3897cd08927SColin LeMahieu MCO.setReg(Producer); 3907cd08927SColin LeMahieu } else 3917cd08927SColin LeMahieu return MCDisassembler::Fail; 3927cd08927SColin LeMahieu } 3937cd08927SColin LeMahieu 3947cd08927SColin LeMahieu adjustExtendedInstructions(MI, MCB); 3957cd08927SColin LeMahieu MCInst const *Extender = 3967cd08927SColin LeMahieu HexagonMCInstrInfo::extenderForIndex(MCB, 3977cd08927SColin LeMahieu HexagonMCInstrInfo::bundleSize(MCB)); 3987cd08927SColin LeMahieu if(Extender != nullptr) { 3997cd08927SColin LeMahieu MCInst const & Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) ? 4007cd08927SColin LeMahieu *MI.getOperand(1).getInst() : MI; 4017cd08927SColin LeMahieu if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) && 4027cd08927SColin LeMahieu !HexagonMCInstrInfo::isExtended(*MCII, Inst)) 4037cd08927SColin LeMahieu return MCDisassembler::Fail; 4047cd08927SColin LeMahieu } 4055d6f03bdSColin LeMahieu return Result; 40688ebb9e2SColin LeMahieu } 4077cd08927SColin LeMahieu 4087cd08927SColin LeMahieu void HexagonDisassembler::adjustExtendedInstructions(MCInst &MCI, 4097cd08927SColin LeMahieu MCInst const &MCB) const { 4107cd08927SColin LeMahieu if (!HexagonMCInstrInfo::hasExtenderForIndex( 4117cd08927SColin LeMahieu MCB, HexagonMCInstrInfo::bundleSize(MCB))) { 4127cd08927SColin LeMahieu unsigned opcode; 4137cd08927SColin LeMahieu // This code is used by the disassembler to disambiguate between GP 4147cd08927SColin LeMahieu // relative and absolute addressing instructions since they both have 4157cd08927SColin LeMahieu // same encoding bits. However, an absolute addressing instruction must 4167cd08927SColin LeMahieu // follow an immediate extender. Disassembler alwaus select absolute 4177cd08927SColin LeMahieu // addressing instructions first and uses this code to change them into 4187cd08927SColin LeMahieu // GP relative instruction in the absence of the corresponding immediate 4197cd08927SColin LeMahieu // extender. 4207cd08927SColin LeMahieu switch (MCI.getOpcode()) { 4217cd08927SColin LeMahieu case Hexagon::S2_storerbabs: 4227cd08927SColin LeMahieu opcode = Hexagon::S2_storerbgp; 4237cd08927SColin LeMahieu break; 4247cd08927SColin LeMahieu case Hexagon::S2_storerhabs: 4257cd08927SColin LeMahieu opcode = Hexagon::S2_storerhgp; 4267cd08927SColin LeMahieu break; 4277cd08927SColin LeMahieu case Hexagon::S2_storerfabs: 4287cd08927SColin LeMahieu opcode = Hexagon::S2_storerfgp; 4297cd08927SColin LeMahieu break; 4307cd08927SColin LeMahieu case Hexagon::S2_storeriabs: 4317cd08927SColin LeMahieu opcode = Hexagon::S2_storerigp; 4327cd08927SColin LeMahieu break; 4337cd08927SColin LeMahieu case Hexagon::S2_storerbnewabs: 4347cd08927SColin LeMahieu opcode = Hexagon::S2_storerbnewgp; 4357cd08927SColin LeMahieu break; 4367cd08927SColin LeMahieu case Hexagon::S2_storerhnewabs: 4377cd08927SColin LeMahieu opcode = Hexagon::S2_storerhnewgp; 4387cd08927SColin LeMahieu break; 4397cd08927SColin LeMahieu case Hexagon::S2_storerinewabs: 4407cd08927SColin LeMahieu opcode = Hexagon::S2_storerinewgp; 4417cd08927SColin LeMahieu break; 4427cd08927SColin LeMahieu case Hexagon::S2_storerdabs: 4437cd08927SColin LeMahieu opcode = Hexagon::S2_storerdgp; 4447cd08927SColin LeMahieu break; 4457cd08927SColin LeMahieu case Hexagon::L4_loadrb_abs: 4467cd08927SColin LeMahieu opcode = Hexagon::L2_loadrbgp; 4477cd08927SColin LeMahieu break; 4487cd08927SColin LeMahieu case Hexagon::L4_loadrub_abs: 4497cd08927SColin LeMahieu opcode = Hexagon::L2_loadrubgp; 4507cd08927SColin LeMahieu break; 4517cd08927SColin LeMahieu case Hexagon::L4_loadrh_abs: 4527cd08927SColin LeMahieu opcode = Hexagon::L2_loadrhgp; 4537cd08927SColin LeMahieu break; 4547cd08927SColin LeMahieu case Hexagon::L4_loadruh_abs: 4557cd08927SColin LeMahieu opcode = Hexagon::L2_loadruhgp; 4567cd08927SColin LeMahieu break; 4577cd08927SColin LeMahieu case Hexagon::L4_loadri_abs: 4587cd08927SColin LeMahieu opcode = Hexagon::L2_loadrigp; 4597cd08927SColin LeMahieu break; 4607cd08927SColin LeMahieu case Hexagon::L4_loadrd_abs: 4617cd08927SColin LeMahieu opcode = Hexagon::L2_loadrdgp; 4627cd08927SColin LeMahieu break; 4637cd08927SColin LeMahieu default: 4647cd08927SColin LeMahieu opcode = MCI.getOpcode(); 4657cd08927SColin LeMahieu } 4667cd08927SColin LeMahieu MCI.setOpcode(opcode); 4677cd08927SColin LeMahieu } 4687cd08927SColin LeMahieu } 4697cd08927SColin LeMahieu 4707cd08927SColin LeMahieu namespace llvm { 4717cd08927SColin LeMahieu extern const MCInstrDesc HexagonInsts[]; 4727cd08927SColin LeMahieu } 4737cd08927SColin LeMahieu 4747cd08927SColin LeMahieu static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, 475e5e035a3SCraig Topper ArrayRef<MCPhysReg> Table) { 4763da000c0SCraig Topper if (RegNo < Table.size()) { 4777cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Table[RegNo])); 4787cd08927SColin LeMahieu return MCDisassembler::Success; 4793da000c0SCraig Topper } 4803da000c0SCraig Topper 4817cd08927SColin LeMahieu return MCDisassembler::Fail; 4827cd08927SColin LeMahieu } 4837cd08927SColin LeMahieu 4847c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 4857c958713SColin LeMahieu uint64_t Address, 4867c958713SColin LeMahieu const void *Decoder) { 4877c958713SColin LeMahieu return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder); 4887c958713SColin LeMahieu } 4897c958713SColin LeMahieu 4907cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 4917cd08927SColin LeMahieu uint64_t Address, 4927cd08927SColin LeMahieu const void *Decoder) { 493e5e035a3SCraig Topper static const MCPhysReg IntRegDecoderTable[] = { 4947cd08927SColin LeMahieu Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, 4957cd08927SColin LeMahieu Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9, 4967cd08927SColin LeMahieu Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14, 4977cd08927SColin LeMahieu Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 4987cd08927SColin LeMahieu Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24, 4997cd08927SColin LeMahieu Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29, 5007cd08927SColin LeMahieu Hexagon::R30, Hexagon::R31}; 5017cd08927SColin LeMahieu 502e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable); 5037cd08927SColin LeMahieu } 5047c958713SColin LeMahieu 5057c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5067c958713SColin LeMahieu uint64_t /*Address*/, 5077c958713SColin LeMahieu const void *Decoder) { 508e5e035a3SCraig Topper static const MCPhysReg VecRegDecoderTable[] = { 5097c958713SColin LeMahieu Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, 5107c958713SColin LeMahieu Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, 5117c958713SColin LeMahieu Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, 5127c958713SColin LeMahieu Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19, 5137c958713SColin LeMahieu Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24, 5147c958713SColin LeMahieu Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29, 5157c958713SColin LeMahieu Hexagon::V30, Hexagon::V31}; 5167c958713SColin LeMahieu 517e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable); 5187c958713SColin LeMahieu } 5197c958713SColin LeMahieu 5207cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5217cd08927SColin LeMahieu uint64_t /*Address*/, 5227cd08927SColin LeMahieu const void *Decoder) { 523e5e035a3SCraig Topper static const MCPhysReg DoubleRegDecoderTable[] = { 5247cd08927SColin LeMahieu Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, 5257cd08927SColin LeMahieu Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7, 5267cd08927SColin LeMahieu Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11, 5277cd08927SColin LeMahieu Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15}; 5287cd08927SColin LeMahieu 529e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable); 5307cd08927SColin LeMahieu } 5317cd08927SColin LeMahieu 5327c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5337c958713SColin LeMahieu uint64_t /*Address*/, 5347c958713SColin LeMahieu const void *Decoder) { 535e5e035a3SCraig Topper static const MCPhysReg VecDblRegDecoderTable[] = { 5367c958713SColin LeMahieu Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, 5377c958713SColin LeMahieu Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7, 5387c958713SColin LeMahieu Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11, 5397c958713SColin LeMahieu Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15}; 5407c958713SColin LeMahieu 5413da000c0SCraig Topper return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable)); 5427c958713SColin LeMahieu } 5437c958713SColin LeMahieu 5447cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5457cd08927SColin LeMahieu uint64_t /*Address*/, 5467cd08927SColin LeMahieu const void *Decoder) { 547e5e035a3SCraig Topper static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1, 5487cd08927SColin LeMahieu Hexagon::P2, Hexagon::P3}; 5497cd08927SColin LeMahieu 550e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable); 5517cd08927SColin LeMahieu } 5527cd08927SColin LeMahieu 5537c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5547c958713SColin LeMahieu uint64_t /*Address*/, 5557c958713SColin LeMahieu const void *Decoder) { 556e5e035a3SCraig Topper static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1, 5577c958713SColin LeMahieu Hexagon::Q2, Hexagon::Q3}; 5587c958713SColin LeMahieu 559e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable); 5607c958713SColin LeMahieu } 561be8c453dSColin LeMahieu 5627cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5637cd08927SColin LeMahieu uint64_t /*Address*/, 5647cd08927SColin LeMahieu const void *Decoder) { 565e5e035a3SCraig Topper static const MCPhysReg CtrlRegDecoderTable[] = { 5667cd08927SColin LeMahieu Hexagon::SA0, Hexagon::LC0, Hexagon::SA1, Hexagon::LC1, 5677cd08927SColin LeMahieu Hexagon::P3_0, Hexagon::C5, Hexagon::C6, Hexagon::C7, 5687cd08927SColin LeMahieu Hexagon::USR, Hexagon::PC, Hexagon::UGP, Hexagon::GP, 5697cd08927SColin LeMahieu Hexagon::CS0, Hexagon::CS1, Hexagon::UPCL, Hexagon::UPC 5707cd08927SColin LeMahieu }; 5717cd08927SColin LeMahieu 5726261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlRegDecoderTable)) 5737cd08927SColin LeMahieu return MCDisassembler::Fail; 5747cd08927SColin LeMahieu 5757cd08927SColin LeMahieu if (CtrlRegDecoderTable[RegNo] == Hexagon::NoRegister) 5767cd08927SColin LeMahieu return MCDisassembler::Fail; 5777cd08927SColin LeMahieu 5787cd08927SColin LeMahieu unsigned Register = CtrlRegDecoderTable[RegNo]; 5797cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 5807cd08927SColin LeMahieu return MCDisassembler::Success; 5817cd08927SColin LeMahieu } 5827cd08927SColin LeMahieu 5837cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 5847cd08927SColin LeMahieu uint64_t /*Address*/, 5857cd08927SColin LeMahieu const void *Decoder) { 586e5e035a3SCraig Topper static const MCPhysReg CtrlReg64DecoderTable[] = { 5877cd08927SColin LeMahieu Hexagon::C1_0, Hexagon::NoRegister, 5887cd08927SColin LeMahieu Hexagon::C3_2, Hexagon::NoRegister, 5897cd08927SColin LeMahieu Hexagon::C7_6, Hexagon::NoRegister, 5907cd08927SColin LeMahieu Hexagon::C9_8, Hexagon::NoRegister, 5917cd08927SColin LeMahieu Hexagon::C11_10, Hexagon::NoRegister, 5927cd08927SColin LeMahieu Hexagon::CS, Hexagon::NoRegister, 5937cd08927SColin LeMahieu Hexagon::UPC, Hexagon::NoRegister 5947cd08927SColin LeMahieu }; 5957cd08927SColin LeMahieu 5966261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlReg64DecoderTable)) 5977cd08927SColin LeMahieu return MCDisassembler::Fail; 5987cd08927SColin LeMahieu 5997cd08927SColin LeMahieu if (CtrlReg64DecoderTable[RegNo] == Hexagon::NoRegister) 6007cd08927SColin LeMahieu return MCDisassembler::Fail; 6017cd08927SColin LeMahieu 6027cd08927SColin LeMahieu unsigned Register = CtrlReg64DecoderTable[RegNo]; 6037cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 6047cd08927SColin LeMahieu return MCDisassembler::Success; 6057cd08927SColin LeMahieu } 6067cd08927SColin LeMahieu 6077cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, 6087cd08927SColin LeMahieu uint64_t /*Address*/, 6097cd08927SColin LeMahieu const void *Decoder) { 6107cd08927SColin LeMahieu unsigned Register = 0; 6117cd08927SColin LeMahieu switch (RegNo) { 6127cd08927SColin LeMahieu case 0: 6137cd08927SColin LeMahieu Register = Hexagon::M0; 6147cd08927SColin LeMahieu break; 6157cd08927SColin LeMahieu case 1: 6167cd08927SColin LeMahieu Register = Hexagon::M1; 6177cd08927SColin LeMahieu break; 6187cd08927SColin LeMahieu default: 6197cd08927SColin LeMahieu return MCDisassembler::Fail; 6207cd08927SColin LeMahieu } 6217cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 6227cd08927SColin LeMahieu return MCDisassembler::Success; 6237cd08927SColin LeMahieu } 6247cd08927SColin LeMahieu 6257cd08927SColin LeMahieu namespace { 6267cd08927SColin LeMahieu uint32_t fullValue(MCInstrInfo const &MCII, 6277cd08927SColin LeMahieu MCInst &MCB, 6287cd08927SColin LeMahieu MCInst &MI, 6297cd08927SColin LeMahieu int64_t Value) { 6307cd08927SColin LeMahieu MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( 6317cd08927SColin LeMahieu MCB, HexagonMCInstrInfo::bundleSize(MCB)); 6327cd08927SColin LeMahieu if(!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI)) 6337cd08927SColin LeMahieu return Value; 6347cd08927SColin LeMahieu unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI); 6357cd08927SColin LeMahieu uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f; 6367cd08927SColin LeMahieu int64_t Bits; 6377cd08927SColin LeMahieu bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits); 6387cd08927SColin LeMahieu assert(Success);(void)Success; 6397cd08927SColin LeMahieu uint32_t Upper26 = static_cast<uint32_t>(Bits); 6407cd08927SColin LeMahieu uint32_t Operand = Upper26 | Lower6; 6417cd08927SColin LeMahieu return Operand; 6427cd08927SColin LeMahieu } 6437cd08927SColin LeMahieu template <size_t T> 6447cd08927SColin LeMahieu void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) { 6457cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6467cd08927SColin LeMahieu int64_t FullValue = fullValue(*Disassembler.MCII, 6477cd08927SColin LeMahieu **Disassembler.CurrentBundle, 6487cd08927SColin LeMahieu MI, SignExtend64<T>(tmp)); 6497cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue); 6507cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, 6517cd08927SColin LeMahieu Disassembler.getContext()); 6527cd08927SColin LeMahieu } 6537cd08927SColin LeMahieu } 6547cd08927SColin LeMahieu 6557cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 6567cd08927SColin LeMahieu uint64_t /*Address*/, 6577cd08927SColin LeMahieu const void *Decoder) { 6587cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6597cd08927SColin LeMahieu int64_t FullValue = fullValue(*Disassembler.MCII, 6607cd08927SColin LeMahieu **Disassembler.CurrentBundle, 6617cd08927SColin LeMahieu MI, tmp); 6627cd08927SColin LeMahieu assert(FullValue >= 0 && "Negative in unsigned decoder"); 6637cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext()); 6647cd08927SColin LeMahieu return MCDisassembler::Success; 6657cd08927SColin LeMahieu } 6667cd08927SColin LeMahieu 6671e9d1d76SColin LeMahieu static DecodeStatus s16ImmDecoder(MCInst &MI, unsigned tmp, 6681e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6697cd08927SColin LeMahieu signedDecoder<16>(MI, tmp, Decoder); 6701e9d1d76SColin LeMahieu return MCDisassembler::Success; 6711e9d1d76SColin LeMahieu } 6721e9d1d76SColin LeMahieu 6731e9d1d76SColin LeMahieu static DecodeStatus s12ImmDecoder(MCInst &MI, unsigned tmp, 6741e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6757cd08927SColin LeMahieu signedDecoder<12>(MI, tmp, Decoder); 6761e9d1d76SColin LeMahieu return MCDisassembler::Success; 6771e9d1d76SColin LeMahieu } 6781e9d1d76SColin LeMahieu 6791e9d1d76SColin LeMahieu static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, 6801e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6817cd08927SColin LeMahieu signedDecoder<11>(MI, tmp, Decoder); 6821e9d1d76SColin LeMahieu return MCDisassembler::Success; 6831e9d1d76SColin LeMahieu } 6841e9d1d76SColin LeMahieu 6851e9d1d76SColin LeMahieu static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, 6861e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6877cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, SignExtend64<12>(tmp), contextFromDecoder(Decoder)); 6881e9d1d76SColin LeMahieu return MCDisassembler::Success; 6891e9d1d76SColin LeMahieu } 6901e9d1d76SColin LeMahieu 6911e9d1d76SColin LeMahieu static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, 6921e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6937cd08927SColin LeMahieu signedDecoder<13>(MI, tmp, Decoder); 6941e9d1d76SColin LeMahieu return MCDisassembler::Success; 6951e9d1d76SColin LeMahieu } 6961e9d1d76SColin LeMahieu 6971e9d1d76SColin LeMahieu static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, 6981e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6997cd08927SColin LeMahieu signedDecoder<14>(MI, tmp, Decoder); 7001e9d1d76SColin LeMahieu return MCDisassembler::Success; 7011e9d1d76SColin LeMahieu } 7021e9d1d76SColin LeMahieu 7031e9d1d76SColin LeMahieu static DecodeStatus s10ImmDecoder(MCInst &MI, unsigned tmp, 7041e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7057cd08927SColin LeMahieu signedDecoder<10>(MI, tmp, Decoder); 7061e9d1d76SColin LeMahieu return MCDisassembler::Success; 7071e9d1d76SColin LeMahieu } 7081e9d1d76SColin LeMahieu 7091e9d1d76SColin LeMahieu static DecodeStatus s8ImmDecoder(MCInst &MI, unsigned tmp, uint64_t /*Address*/, 7101e9d1d76SColin LeMahieu const void *Decoder) { 7117cd08927SColin LeMahieu signedDecoder<8>(MI, tmp, Decoder); 7121e9d1d76SColin LeMahieu return MCDisassembler::Success; 7131e9d1d76SColin LeMahieu } 7141e9d1d76SColin LeMahieu 7151e9d1d76SColin LeMahieu static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, 7161e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7177cd08927SColin LeMahieu signedDecoder<6>(MI, tmp, Decoder); 7181e9d1d76SColin LeMahieu return MCDisassembler::Success; 7191e9d1d76SColin LeMahieu } 7201e9d1d76SColin LeMahieu 7211e9d1d76SColin LeMahieu static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, 7221e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7237cd08927SColin LeMahieu signedDecoder<4>(MI, tmp, Decoder); 7241e9d1d76SColin LeMahieu return MCDisassembler::Success; 7251e9d1d76SColin LeMahieu } 7261e9d1d76SColin LeMahieu 7271e9d1d76SColin LeMahieu static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, 7281e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7297cd08927SColin LeMahieu signedDecoder<5>(MI, tmp, Decoder); 7301e9d1d76SColin LeMahieu return MCDisassembler::Success; 7311e9d1d76SColin LeMahieu } 7321e9d1d76SColin LeMahieu 7331e9d1d76SColin LeMahieu static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, 7341e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7357cd08927SColin LeMahieu signedDecoder<6>(MI, tmp, Decoder); 7361e9d1d76SColin LeMahieu return MCDisassembler::Success; 7371e9d1d76SColin LeMahieu } 7381e9d1d76SColin LeMahieu 7391e9d1d76SColin LeMahieu static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, 7401e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7417cd08927SColin LeMahieu signedDecoder<7>(MI, tmp, Decoder); 7421e9d1d76SColin LeMahieu return MCDisassembler::Success; 7431e9d1d76SColin LeMahieu } 7441e9d1d76SColin LeMahieu 7457c958713SColin LeMahieu static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, 7467c958713SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7477cd08927SColin LeMahieu signedDecoder<10>(MI, tmp, Decoder); 7487c958713SColin LeMahieu return MCDisassembler::Success; 7497c958713SColin LeMahieu } 7507c958713SColin LeMahieu 7517c958713SColin LeMahieu static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, 7527c958713SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7537cd08927SColin LeMahieu signedDecoder<19>(MI, tmp, Decoder); 7547c958713SColin LeMahieu return MCDisassembler::Success; 7557c958713SColin LeMahieu } 7567c958713SColin LeMahieu 7577cd08927SColin LeMahieu // custom decoder for various jump/call immediates 7587cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 7597cd08927SColin LeMahieu const void *Decoder) { 7607cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 7617cd08927SColin LeMahieu unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); 7627cd08927SColin LeMahieu // r13_2 is not extendable, so if there are no extent bits, it's r13_2 7637cd08927SColin LeMahieu if (Bits == 0) 7647cd08927SColin LeMahieu Bits = 15; 7657cd08927SColin LeMahieu uint32_t FullValue = fullValue(*Disassembler.MCII, 7667cd08927SColin LeMahieu **Disassembler.CurrentBundle, 7677cd08927SColin LeMahieu MI, SignExtend64(tmp, Bits)); 7687cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue) + Address; 7697cd08927SColin LeMahieu if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 7707cd08927SColin LeMahieu 0, 4)) 7717cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); 7727cd08927SColin LeMahieu return MCDisassembler::Success; 7737cd08927SColin LeMahieu } 7747cd08927SColin LeMahieu 7757cd08927SColin LeMahieu // Addressing mode dependent load store opcode map. 7767cd08927SColin LeMahieu // - If an insn is preceded by an extender the address is absolute. 7777cd08927SColin LeMahieu // - memw(##symbol) = r0 7787cd08927SColin LeMahieu // - If an insn is not preceded by an extender the address is GP relative. 7797cd08927SColin LeMahieu // - memw(gp + #symbol) = r0 7807cd08927SColin LeMahieu // Please note that the instructions must be ordered in the descending order 7817cd08927SColin LeMahieu // of their opcode. 7827cd08927SColin LeMahieu // HexagonII::INST_ICLASS_ST 783d824f5f0SCraig Topper static const unsigned int StoreConditionalOpcodeData[][2] = { 7847cd08927SColin LeMahieu {S4_pstorerdfnew_abs, 0xafc02084}, 7857cd08927SColin LeMahieu {S4_pstorerdtnew_abs, 0xafc02080}, 7867cd08927SColin LeMahieu {S4_pstorerdf_abs, 0xafc00084}, 7877cd08927SColin LeMahieu {S4_pstorerdt_abs, 0xafc00080}, 7887cd08927SColin LeMahieu {S4_pstorerinewfnew_abs, 0xafa03084}, 7897cd08927SColin LeMahieu {S4_pstorerinewtnew_abs, 0xafa03080}, 7907cd08927SColin LeMahieu {S4_pstorerhnewfnew_abs, 0xafa02884}, 7917cd08927SColin LeMahieu {S4_pstorerhnewtnew_abs, 0xafa02880}, 7927cd08927SColin LeMahieu {S4_pstorerbnewfnew_abs, 0xafa02084}, 7937cd08927SColin LeMahieu {S4_pstorerbnewtnew_abs, 0xafa02080}, 7947cd08927SColin LeMahieu {S4_pstorerinewf_abs, 0xafa01084}, 7957cd08927SColin LeMahieu {S4_pstorerinewt_abs, 0xafa01080}, 7967cd08927SColin LeMahieu {S4_pstorerhnewf_abs, 0xafa00884}, 7977cd08927SColin LeMahieu {S4_pstorerhnewt_abs, 0xafa00880}, 7987cd08927SColin LeMahieu {S4_pstorerbnewf_abs, 0xafa00084}, 7997cd08927SColin LeMahieu {S4_pstorerbnewt_abs, 0xafa00080}, 8007cd08927SColin LeMahieu {S4_pstorerifnew_abs, 0xaf802084}, 8017cd08927SColin LeMahieu {S4_pstoreritnew_abs, 0xaf802080}, 8027cd08927SColin LeMahieu {S4_pstorerif_abs, 0xaf800084}, 8037cd08927SColin LeMahieu {S4_pstorerit_abs, 0xaf800080}, 8047cd08927SColin LeMahieu {S4_pstorerhfnew_abs, 0xaf402084}, 8057cd08927SColin LeMahieu {S4_pstorerhtnew_abs, 0xaf402080}, 8067cd08927SColin LeMahieu {S4_pstorerhf_abs, 0xaf400084}, 8077cd08927SColin LeMahieu {S4_pstorerht_abs, 0xaf400080}, 8087cd08927SColin LeMahieu {S4_pstorerbfnew_abs, 0xaf002084}, 8097cd08927SColin LeMahieu {S4_pstorerbtnew_abs, 0xaf002080}, 8107cd08927SColin LeMahieu {S4_pstorerbf_abs, 0xaf000084}, 8117cd08927SColin LeMahieu {S4_pstorerbt_abs, 0xaf000080}}; 8127cd08927SColin LeMahieu // HexagonII::INST_ICLASS_LD 8137cd08927SColin LeMahieu 8147cd08927SColin LeMahieu // HexagonII::INST_ICLASS_LD_ST_2 8157cd08927SColin LeMahieu static unsigned int LoadStoreOpcodeData[][2] = {{L4_loadrd_abs, 0x49c00000}, 8167cd08927SColin LeMahieu {L4_loadri_abs, 0x49800000}, 8177cd08927SColin LeMahieu {L4_loadruh_abs, 0x49600000}, 8187cd08927SColin LeMahieu {L4_loadrh_abs, 0x49400000}, 8197cd08927SColin LeMahieu {L4_loadrub_abs, 0x49200000}, 8207cd08927SColin LeMahieu {L4_loadrb_abs, 0x49000000}, 8217cd08927SColin LeMahieu {S2_storerdabs, 0x48c00000}, 8227cd08927SColin LeMahieu {S2_storerinewabs, 0x48a01000}, 8237cd08927SColin LeMahieu {S2_storerhnewabs, 0x48a00800}, 8247cd08927SColin LeMahieu {S2_storerbnewabs, 0x48a00000}, 8257cd08927SColin LeMahieu {S2_storeriabs, 0x48800000}, 8267cd08927SColin LeMahieu {S2_storerfabs, 0x48600000}, 8277cd08927SColin LeMahieu {S2_storerhabs, 0x48400000}, 8287cd08927SColin LeMahieu {S2_storerbabs, 0x48000000}}; 829d824f5f0SCraig Topper static const size_t NumCondS = array_lengthof(StoreConditionalOpcodeData); 830d824f5f0SCraig Topper static const size_t NumLS = array_lengthof(LoadStoreOpcodeData); 8317cd08927SColin LeMahieu 8327cd08927SColin LeMahieu static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn) { 8337cd08927SColin LeMahieu 8347cd08927SColin LeMahieu unsigned MachineOpcode = 0; 8357cd08927SColin LeMahieu unsigned LLVMOpcode = 0; 8367cd08927SColin LeMahieu 8377cd08927SColin LeMahieu if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_ST) { 838d824f5f0SCraig Topper for (size_t i = 0; i < NumCondS; ++i) { 8397cd08927SColin LeMahieu if ((insn & StoreConditionalOpcodeData[i][1]) == 8407cd08927SColin LeMahieu StoreConditionalOpcodeData[i][1]) { 8417cd08927SColin LeMahieu MachineOpcode = StoreConditionalOpcodeData[i][1]; 8427cd08927SColin LeMahieu LLVMOpcode = StoreConditionalOpcodeData[i][0]; 8437cd08927SColin LeMahieu break; 8447cd08927SColin LeMahieu } 8457cd08927SColin LeMahieu } 8467cd08927SColin LeMahieu } 8477cd08927SColin LeMahieu if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_LD_ST_2) { 848d824f5f0SCraig Topper for (size_t i = 0; i < NumLS; ++i) { 8497cd08927SColin LeMahieu if ((insn & LoadStoreOpcodeData[i][1]) == LoadStoreOpcodeData[i][1]) { 8507cd08927SColin LeMahieu MachineOpcode = LoadStoreOpcodeData[i][1]; 8517cd08927SColin LeMahieu LLVMOpcode = LoadStoreOpcodeData[i][0]; 8527cd08927SColin LeMahieu break; 8537cd08927SColin LeMahieu } 8547cd08927SColin LeMahieu } 8557cd08927SColin LeMahieu } 8567cd08927SColin LeMahieu 8577cd08927SColin LeMahieu if (MachineOpcode) { 8587cd08927SColin LeMahieu unsigned Value = 0; 8597cd08927SColin LeMahieu unsigned shift = 0; 8607cd08927SColin LeMahieu MI.setOpcode(LLVMOpcode); 8617cd08927SColin LeMahieu // Remove the parse bits from the insn. 8627cd08927SColin LeMahieu insn &= ~HexagonII::INST_PARSE_MASK; 8637cd08927SColin LeMahieu 8647cd08927SColin LeMahieu switch (LLVMOpcode) { 8657cd08927SColin LeMahieu default: 8667cd08927SColin LeMahieu return MCDisassembler::Fail; 8677cd08927SColin LeMahieu break; 8687cd08927SColin LeMahieu 8697cd08927SColin LeMahieu case Hexagon::S4_pstorerdf_abs: 8707cd08927SColin LeMahieu case Hexagon::S4_pstorerdt_abs: 8717cd08927SColin LeMahieu case Hexagon::S4_pstorerdfnew_abs: 8727cd08927SColin LeMahieu case Hexagon::S4_pstorerdtnew_abs: { 8737cd08927SColin LeMahieu // op: Pv 8747cd08927SColin LeMahieu Value = insn & UINT64_C(3); 8757cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 8767cd08927SColin LeMahieu // op: u6 8777cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 8787cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 8797cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 8807cd08927SColin LeMahieu // op: Rtt 8817cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 8827cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 8837cd08927SColin LeMahieu break; 8847cd08927SColin LeMahieu } 8857cd08927SColin LeMahieu 8867cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewf_abs: 8877cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewt_abs: 8887cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewfnew_abs: 8897cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewtnew_abs: 8907cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewf_abs: 8917cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewt_abs: 8927cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewfnew_abs: 8937cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewtnew_abs: 8947cd08927SColin LeMahieu case Hexagon::S4_pstorerinewf_abs: 8957cd08927SColin LeMahieu case Hexagon::S4_pstorerinewt_abs: 8967cd08927SColin LeMahieu case Hexagon::S4_pstorerinewfnew_abs: 8977cd08927SColin LeMahieu case Hexagon::S4_pstorerinewtnew_abs: { 8987cd08927SColin LeMahieu // op: Pv 8997cd08927SColin LeMahieu Value = insn & UINT64_C(3); 9007cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9017cd08927SColin LeMahieu // op: u6 9027cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 9037cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 9047cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9057cd08927SColin LeMahieu // op: Nt 9067cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(7); 9077cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9087cd08927SColin LeMahieu break; 9097cd08927SColin LeMahieu } 9107cd08927SColin LeMahieu 9117cd08927SColin LeMahieu case Hexagon::S4_pstorerbf_abs: 9127cd08927SColin LeMahieu case Hexagon::S4_pstorerbt_abs: 9137cd08927SColin LeMahieu case Hexagon::S4_pstorerbfnew_abs: 9147cd08927SColin LeMahieu case Hexagon::S4_pstorerbtnew_abs: 9157cd08927SColin LeMahieu case Hexagon::S4_pstorerhf_abs: 9167cd08927SColin LeMahieu case Hexagon::S4_pstorerht_abs: 9177cd08927SColin LeMahieu case Hexagon::S4_pstorerhfnew_abs: 9187cd08927SColin LeMahieu case Hexagon::S4_pstorerhtnew_abs: 9197cd08927SColin LeMahieu case Hexagon::S4_pstorerif_abs: 9207cd08927SColin LeMahieu case Hexagon::S4_pstorerit_abs: 9217cd08927SColin LeMahieu case Hexagon::S4_pstorerifnew_abs: 9227cd08927SColin LeMahieu case Hexagon::S4_pstoreritnew_abs: { 9237cd08927SColin LeMahieu // op: Pv 9247cd08927SColin LeMahieu Value = insn & UINT64_C(3); 9257cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9267cd08927SColin LeMahieu // op: u6 9277cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 9287cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 9297cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9307cd08927SColin LeMahieu // op: Rt 9317cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 9327cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9337cd08927SColin LeMahieu break; 9347cd08927SColin LeMahieu } 9357cd08927SColin LeMahieu 9367cd08927SColin LeMahieu case Hexagon::L4_ploadrdf_abs: 9377cd08927SColin LeMahieu case Hexagon::L4_ploadrdt_abs: 9387cd08927SColin LeMahieu case Hexagon::L4_ploadrdfnew_abs: 9397cd08927SColin LeMahieu case Hexagon::L4_ploadrdtnew_abs: { 9407cd08927SColin LeMahieu // op: Rdd 9417cd08927SColin LeMahieu Value = insn & UINT64_C(31); 9427cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 9437cd08927SColin LeMahieu // op: Pt 9447cd08927SColin LeMahieu Value = ((insn >> 9) & UINT64_C(3)); 9457cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9467cd08927SColin LeMahieu // op: u6 9477cd08927SColin LeMahieu Value = ((insn >> 15) & UINT64_C(62)); 9487cd08927SColin LeMahieu Value |= ((insn >> 8) & UINT64_C(1)); 9497cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9507cd08927SColin LeMahieu break; 9517cd08927SColin LeMahieu } 9527cd08927SColin LeMahieu 9537cd08927SColin LeMahieu case Hexagon::L4_ploadrbf_abs: 9547cd08927SColin LeMahieu case Hexagon::L4_ploadrbt_abs: 9557cd08927SColin LeMahieu case Hexagon::L4_ploadrbfnew_abs: 9567cd08927SColin LeMahieu case Hexagon::L4_ploadrbtnew_abs: 9577cd08927SColin LeMahieu case Hexagon::L4_ploadrhf_abs: 9587cd08927SColin LeMahieu case Hexagon::L4_ploadrht_abs: 9597cd08927SColin LeMahieu case Hexagon::L4_ploadrhfnew_abs: 9607cd08927SColin LeMahieu case Hexagon::L4_ploadrhtnew_abs: 9617cd08927SColin LeMahieu case Hexagon::L4_ploadrubf_abs: 9627cd08927SColin LeMahieu case Hexagon::L4_ploadrubt_abs: 9637cd08927SColin LeMahieu case Hexagon::L4_ploadrubfnew_abs: 9647cd08927SColin LeMahieu case Hexagon::L4_ploadrubtnew_abs: 9657cd08927SColin LeMahieu case Hexagon::L4_ploadruhf_abs: 9667cd08927SColin LeMahieu case Hexagon::L4_ploadruht_abs: 9677cd08927SColin LeMahieu case Hexagon::L4_ploadruhfnew_abs: 9687cd08927SColin LeMahieu case Hexagon::L4_ploadruhtnew_abs: 9697cd08927SColin LeMahieu case Hexagon::L4_ploadrif_abs: 9707cd08927SColin LeMahieu case Hexagon::L4_ploadrit_abs: 9717cd08927SColin LeMahieu case Hexagon::L4_ploadrifnew_abs: 9727cd08927SColin LeMahieu case Hexagon::L4_ploadritnew_abs: 9737cd08927SColin LeMahieu // op: Rd 9747cd08927SColin LeMahieu Value = insn & UINT64_C(31); 9757cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9767cd08927SColin LeMahieu // op: Pt 9777cd08927SColin LeMahieu Value = (insn >> 9) & UINT64_C(3); 9787cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9797cd08927SColin LeMahieu // op: u6 9807cd08927SColin LeMahieu Value = (insn >> 15) & UINT64_C(62); 9817cd08927SColin LeMahieu Value |= (insn >> 8) & UINT64_C(1); 9827cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9837cd08927SColin LeMahieu break; 9847cd08927SColin LeMahieu 9857cd08927SColin LeMahieu // op: g16_2 9867cd08927SColin LeMahieu case (Hexagon::L4_loadri_abs): 9877cd08927SColin LeMahieu ++shift; 9887cd08927SColin LeMahieu // op: g16_1 9897cd08927SColin LeMahieu case Hexagon::L4_loadrh_abs: 9907cd08927SColin LeMahieu case Hexagon::L4_loadruh_abs: 9917cd08927SColin LeMahieu ++shift; 9927cd08927SColin LeMahieu // op: g16_0 9937cd08927SColin LeMahieu case Hexagon::L4_loadrb_abs: 9947cd08927SColin LeMahieu case Hexagon::L4_loadrub_abs: { 9957cd08927SColin LeMahieu // op: Rd 9967cd08927SColin LeMahieu Value |= insn & UINT64_C(31); 9977cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9987cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 9997cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10007cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(511); 10017cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10027cd08927SColin LeMahieu break; 10037cd08927SColin LeMahieu } 10047cd08927SColin LeMahieu 10057cd08927SColin LeMahieu case Hexagon::L4_loadrd_abs: { 10067cd08927SColin LeMahieu Value = insn & UINT64_C(31); 10077cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 10087cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10097cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10107cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(511); 10117cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << 3)); 10127cd08927SColin LeMahieu break; 10137cd08927SColin LeMahieu } 10147cd08927SColin LeMahieu 10157cd08927SColin LeMahieu case Hexagon::S2_storerdabs: { 10167cd08927SColin LeMahieu // op: g16_3 10177cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10187cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10197cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10207cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10217cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << 3)); 10227cd08927SColin LeMahieu // op: Rtt 10237cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 10247cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 10257cd08927SColin LeMahieu break; 10267cd08927SColin LeMahieu } 10277cd08927SColin LeMahieu 10287cd08927SColin LeMahieu // op: g16_2 10297cd08927SColin LeMahieu case Hexagon::S2_storerinewabs: 10307cd08927SColin LeMahieu ++shift; 10317cd08927SColin LeMahieu // op: g16_1 10327cd08927SColin LeMahieu case Hexagon::S2_storerhnewabs: 10337cd08927SColin LeMahieu ++shift; 10347cd08927SColin LeMahieu // op: g16_0 10357cd08927SColin LeMahieu case Hexagon::S2_storerbnewabs: { 10367cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10377cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10387cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10397cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10407cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10417cd08927SColin LeMahieu // op: Nt 10427cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(7); 10437cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 10447cd08927SColin LeMahieu break; 10457cd08927SColin LeMahieu } 10467cd08927SColin LeMahieu 10477cd08927SColin LeMahieu // op: g16_2 10487cd08927SColin LeMahieu case Hexagon::S2_storeriabs: 10497cd08927SColin LeMahieu ++shift; 10507cd08927SColin LeMahieu // op: g16_1 10517cd08927SColin LeMahieu case Hexagon::S2_storerhabs: 10527cd08927SColin LeMahieu case Hexagon::S2_storerfabs: 10537cd08927SColin LeMahieu ++shift; 10547cd08927SColin LeMahieu // op: g16_0 10557cd08927SColin LeMahieu case Hexagon::S2_storerbabs: { 10567cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10577cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10587cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10597cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10607cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10617cd08927SColin LeMahieu // op: Rt 10627cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 10637cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 10647cd08927SColin LeMahieu break; 10657cd08927SColin LeMahieu } 10667cd08927SColin LeMahieu } 10677cd08927SColin LeMahieu return MCDisassembler::Success; 10687cd08927SColin LeMahieu } 10697cd08927SColin LeMahieu return MCDisassembler::Fail; 10707cd08927SColin LeMahieu } 10717cd08927SColin LeMahieu 10727cd08927SColin LeMahieu static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn, 10737cd08927SColin LeMahieu void const *Decoder) { 10747cd08927SColin LeMahieu 10757cd08927SColin LeMahieu // Instruction Class for a constant a extender: bits 31:28 = 0x0000 10767cd08927SColin LeMahieu if ((~insn & 0xf0000000) == 0xf0000000) { 10777cd08927SColin LeMahieu unsigned Value; 10787cd08927SColin LeMahieu // 27:16 High 12 bits of 26-bit extender. 10797cd08927SColin LeMahieu Value = (insn & 0x0fff0000) << 4; 10807cd08927SColin LeMahieu // 13:0 Low 14 bits of 26-bit extender. 10817cd08927SColin LeMahieu Value |= ((insn & 0x3fff) << 6); 10827cd08927SColin LeMahieu MI.setOpcode(Hexagon::A4_ext); 10837cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Value, contextFromDecoder(Decoder)); 10847cd08927SColin LeMahieu return MCDisassembler::Success; 10857cd08927SColin LeMahieu } 10867cd08927SColin LeMahieu return MCDisassembler::Fail; 10877cd08927SColin LeMahieu } 10887cd08927SColin LeMahieu 1089be8c453dSColin LeMahieu // These values are from HexagonGenMCCodeEmitter.inc and HexagonIsetDx.td 1090be8c453dSColin LeMahieu enum subInstBinaryValues { 1091be8c453dSColin LeMahieu V4_SA1_addi_BITS = 0x0000, 1092be8c453dSColin LeMahieu V4_SA1_addi_MASK = 0x1800, 1093be8c453dSColin LeMahieu V4_SA1_addrx_BITS = 0x1800, 1094be8c453dSColin LeMahieu V4_SA1_addrx_MASK = 0x1f00, 1095be8c453dSColin LeMahieu V4_SA1_addsp_BITS = 0x0c00, 1096be8c453dSColin LeMahieu V4_SA1_addsp_MASK = 0x1c00, 1097be8c453dSColin LeMahieu V4_SA1_and1_BITS = 0x1200, 1098be8c453dSColin LeMahieu V4_SA1_and1_MASK = 0x1f00, 1099be8c453dSColin LeMahieu V4_SA1_clrf_BITS = 0x1a70, 1100be8c453dSColin LeMahieu V4_SA1_clrf_MASK = 0x1e70, 1101be8c453dSColin LeMahieu V4_SA1_clrfnew_BITS = 0x1a50, 1102be8c453dSColin LeMahieu V4_SA1_clrfnew_MASK = 0x1e70, 1103be8c453dSColin LeMahieu V4_SA1_clrt_BITS = 0x1a60, 1104be8c453dSColin LeMahieu V4_SA1_clrt_MASK = 0x1e70, 1105be8c453dSColin LeMahieu V4_SA1_clrtnew_BITS = 0x1a40, 1106be8c453dSColin LeMahieu V4_SA1_clrtnew_MASK = 0x1e70, 1107be8c453dSColin LeMahieu V4_SA1_cmpeqi_BITS = 0x1900, 1108be8c453dSColin LeMahieu V4_SA1_cmpeqi_MASK = 0x1f00, 1109be8c453dSColin LeMahieu V4_SA1_combine0i_BITS = 0x1c00, 1110be8c453dSColin LeMahieu V4_SA1_combine0i_MASK = 0x1d18, 1111be8c453dSColin LeMahieu V4_SA1_combine1i_BITS = 0x1c08, 1112be8c453dSColin LeMahieu V4_SA1_combine1i_MASK = 0x1d18, 1113be8c453dSColin LeMahieu V4_SA1_combine2i_BITS = 0x1c10, 1114be8c453dSColin LeMahieu V4_SA1_combine2i_MASK = 0x1d18, 1115be8c453dSColin LeMahieu V4_SA1_combine3i_BITS = 0x1c18, 1116be8c453dSColin LeMahieu V4_SA1_combine3i_MASK = 0x1d18, 1117be8c453dSColin LeMahieu V4_SA1_combinerz_BITS = 0x1d08, 1118be8c453dSColin LeMahieu V4_SA1_combinerz_MASK = 0x1d08, 1119be8c453dSColin LeMahieu V4_SA1_combinezr_BITS = 0x1d00, 1120be8c453dSColin LeMahieu V4_SA1_combinezr_MASK = 0x1d08, 1121be8c453dSColin LeMahieu V4_SA1_dec_BITS = 0x1300, 1122be8c453dSColin LeMahieu V4_SA1_dec_MASK = 0x1f00, 1123be8c453dSColin LeMahieu V4_SA1_inc_BITS = 0x1100, 1124be8c453dSColin LeMahieu V4_SA1_inc_MASK = 0x1f00, 1125be8c453dSColin LeMahieu V4_SA1_seti_BITS = 0x0800, 1126be8c453dSColin LeMahieu V4_SA1_seti_MASK = 0x1c00, 1127be8c453dSColin LeMahieu V4_SA1_setin1_BITS = 0x1a00, 1128be8c453dSColin LeMahieu V4_SA1_setin1_MASK = 0x1e40, 1129be8c453dSColin LeMahieu V4_SA1_sxtb_BITS = 0x1500, 1130be8c453dSColin LeMahieu V4_SA1_sxtb_MASK = 0x1f00, 1131be8c453dSColin LeMahieu V4_SA1_sxth_BITS = 0x1400, 1132be8c453dSColin LeMahieu V4_SA1_sxth_MASK = 0x1f00, 1133be8c453dSColin LeMahieu V4_SA1_tfr_BITS = 0x1000, 1134be8c453dSColin LeMahieu V4_SA1_tfr_MASK = 0x1f00, 1135be8c453dSColin LeMahieu V4_SA1_zxtb_BITS = 0x1700, 1136be8c453dSColin LeMahieu V4_SA1_zxtb_MASK = 0x1f00, 1137be8c453dSColin LeMahieu V4_SA1_zxth_BITS = 0x1600, 1138be8c453dSColin LeMahieu V4_SA1_zxth_MASK = 0x1f00, 1139be8c453dSColin LeMahieu V4_SL1_loadri_io_BITS = 0x0000, 1140be8c453dSColin LeMahieu V4_SL1_loadri_io_MASK = 0x1000, 1141be8c453dSColin LeMahieu V4_SL1_loadrub_io_BITS = 0x1000, 1142be8c453dSColin LeMahieu V4_SL1_loadrub_io_MASK = 0x1000, 1143be8c453dSColin LeMahieu V4_SL2_deallocframe_BITS = 0x1f00, 1144be8c453dSColin LeMahieu V4_SL2_deallocframe_MASK = 0x1fc0, 1145be8c453dSColin LeMahieu V4_SL2_jumpr31_BITS = 0x1fc0, 1146be8c453dSColin LeMahieu V4_SL2_jumpr31_MASK = 0x1fc4, 1147be8c453dSColin LeMahieu V4_SL2_jumpr31_f_BITS = 0x1fc5, 1148be8c453dSColin LeMahieu V4_SL2_jumpr31_f_MASK = 0x1fc7, 1149be8c453dSColin LeMahieu V4_SL2_jumpr31_fnew_BITS = 0x1fc7, 1150be8c453dSColin LeMahieu V4_SL2_jumpr31_fnew_MASK = 0x1fc7, 1151be8c453dSColin LeMahieu V4_SL2_jumpr31_t_BITS = 0x1fc4, 1152be8c453dSColin LeMahieu V4_SL2_jumpr31_t_MASK = 0x1fc7, 1153be8c453dSColin LeMahieu V4_SL2_jumpr31_tnew_BITS = 0x1fc6, 1154be8c453dSColin LeMahieu V4_SL2_jumpr31_tnew_MASK = 0x1fc7, 1155be8c453dSColin LeMahieu V4_SL2_loadrb_io_BITS = 0x1000, 1156be8c453dSColin LeMahieu V4_SL2_loadrb_io_MASK = 0x1800, 1157be8c453dSColin LeMahieu V4_SL2_loadrd_sp_BITS = 0x1e00, 1158be8c453dSColin LeMahieu V4_SL2_loadrd_sp_MASK = 0x1f00, 1159be8c453dSColin LeMahieu V4_SL2_loadrh_io_BITS = 0x0000, 1160be8c453dSColin LeMahieu V4_SL2_loadrh_io_MASK = 0x1800, 1161be8c453dSColin LeMahieu V4_SL2_loadri_sp_BITS = 0x1c00, 1162be8c453dSColin LeMahieu V4_SL2_loadri_sp_MASK = 0x1e00, 1163be8c453dSColin LeMahieu V4_SL2_loadruh_io_BITS = 0x0800, 1164be8c453dSColin LeMahieu V4_SL2_loadruh_io_MASK = 0x1800, 1165be8c453dSColin LeMahieu V4_SL2_return_BITS = 0x1f40, 1166be8c453dSColin LeMahieu V4_SL2_return_MASK = 0x1fc4, 1167be8c453dSColin LeMahieu V4_SL2_return_f_BITS = 0x1f45, 1168be8c453dSColin LeMahieu V4_SL2_return_f_MASK = 0x1fc7, 1169be8c453dSColin LeMahieu V4_SL2_return_fnew_BITS = 0x1f47, 1170be8c453dSColin LeMahieu V4_SL2_return_fnew_MASK = 0x1fc7, 1171be8c453dSColin LeMahieu V4_SL2_return_t_BITS = 0x1f44, 1172be8c453dSColin LeMahieu V4_SL2_return_t_MASK = 0x1fc7, 1173be8c453dSColin LeMahieu V4_SL2_return_tnew_BITS = 0x1f46, 1174be8c453dSColin LeMahieu V4_SL2_return_tnew_MASK = 0x1fc7, 1175be8c453dSColin LeMahieu V4_SS1_storeb_io_BITS = 0x1000, 1176be8c453dSColin LeMahieu V4_SS1_storeb_io_MASK = 0x1000, 1177be8c453dSColin LeMahieu V4_SS1_storew_io_BITS = 0x0000, 1178be8c453dSColin LeMahieu V4_SS1_storew_io_MASK = 0x1000, 1179be8c453dSColin LeMahieu V4_SS2_allocframe_BITS = 0x1c00, 1180be8c453dSColin LeMahieu V4_SS2_allocframe_MASK = 0x1e00, 1181be8c453dSColin LeMahieu V4_SS2_storebi0_BITS = 0x1200, 1182be8c453dSColin LeMahieu V4_SS2_storebi0_MASK = 0x1f00, 1183be8c453dSColin LeMahieu V4_SS2_storebi1_BITS = 0x1300, 1184be8c453dSColin LeMahieu V4_SS2_storebi1_MASK = 0x1f00, 1185be8c453dSColin LeMahieu V4_SS2_stored_sp_BITS = 0x0a00, 1186be8c453dSColin LeMahieu V4_SS2_stored_sp_MASK = 0x1e00, 1187be8c453dSColin LeMahieu V4_SS2_storeh_io_BITS = 0x0000, 1188be8c453dSColin LeMahieu V4_SS2_storeh_io_MASK = 0x1800, 1189be8c453dSColin LeMahieu V4_SS2_storew_sp_BITS = 0x0800, 1190be8c453dSColin LeMahieu V4_SS2_storew_sp_MASK = 0x1e00, 1191be8c453dSColin LeMahieu V4_SS2_storewi0_BITS = 0x1000, 1192be8c453dSColin LeMahieu V4_SS2_storewi0_MASK = 0x1f00, 1193be8c453dSColin LeMahieu V4_SS2_storewi1_BITS = 0x1100, 1194be8c453dSColin LeMahieu V4_SS2_storewi1_MASK = 0x1f00 1195be8c453dSColin LeMahieu }; 1196be8c453dSColin LeMahieu 1197be8c453dSColin LeMahieu static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op, 1198be8c453dSColin LeMahieu raw_ostream &os) { 1199be8c453dSColin LeMahieu switch (IClass) { 1200be8c453dSColin LeMahieu case HexagonII::HSIG_L1: 1201be8c453dSColin LeMahieu if ((inst & V4_SL1_loadri_io_MASK) == V4_SL1_loadri_io_BITS) 1202be8c453dSColin LeMahieu op = Hexagon::V4_SL1_loadri_io; 1203be8c453dSColin LeMahieu else if ((inst & V4_SL1_loadrub_io_MASK) == V4_SL1_loadrub_io_BITS) 1204be8c453dSColin LeMahieu op = Hexagon::V4_SL1_loadrub_io; 1205be8c453dSColin LeMahieu else { 1206be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1207be8c453dSColin LeMahieu return MCDisassembler::Fail; 1208be8c453dSColin LeMahieu } 1209be8c453dSColin LeMahieu break; 1210be8c453dSColin LeMahieu case HexagonII::HSIG_L2: 1211be8c453dSColin LeMahieu if ((inst & V4_SL2_deallocframe_MASK) == V4_SL2_deallocframe_BITS) 1212be8c453dSColin LeMahieu op = Hexagon::V4_SL2_deallocframe; 1213be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_MASK) == V4_SL2_jumpr31_BITS) 1214be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31; 1215be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_f_MASK) == V4_SL2_jumpr31_f_BITS) 1216be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_f; 1217be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_fnew_MASK) == V4_SL2_jumpr31_fnew_BITS) 1218be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_fnew; 1219be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_t_MASK) == V4_SL2_jumpr31_t_BITS) 1220be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_t; 1221be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_tnew_MASK) == V4_SL2_jumpr31_tnew_BITS) 1222be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_tnew; 1223be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadrb_io_MASK) == V4_SL2_loadrb_io_BITS) 1224be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadrb_io; 1225be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadrd_sp_MASK) == V4_SL2_loadrd_sp_BITS) 1226be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadrd_sp; 1227be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadrh_io_MASK) == V4_SL2_loadrh_io_BITS) 1228be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadrh_io; 1229be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadri_sp_MASK) == V4_SL2_loadri_sp_BITS) 1230be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadri_sp; 1231be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadruh_io_MASK) == V4_SL2_loadruh_io_BITS) 1232be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadruh_io; 1233be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_MASK) == V4_SL2_return_BITS) 1234be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return; 1235be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_f_MASK) == V4_SL2_return_f_BITS) 1236be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_f; 1237be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_fnew_MASK) == V4_SL2_return_fnew_BITS) 1238be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_fnew; 1239be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_t_MASK) == V4_SL2_return_t_BITS) 1240be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_t; 1241be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_tnew_MASK) == V4_SL2_return_tnew_BITS) 1242be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_tnew; 1243be8c453dSColin LeMahieu else { 1244be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1245be8c453dSColin LeMahieu return MCDisassembler::Fail; 1246be8c453dSColin LeMahieu } 1247be8c453dSColin LeMahieu break; 1248be8c453dSColin LeMahieu case HexagonII::HSIG_A: 1249be8c453dSColin LeMahieu if ((inst & V4_SA1_addi_MASK) == V4_SA1_addi_BITS) 1250be8c453dSColin LeMahieu op = Hexagon::V4_SA1_addi; 1251be8c453dSColin LeMahieu else if ((inst & V4_SA1_addrx_MASK) == V4_SA1_addrx_BITS) 1252be8c453dSColin LeMahieu op = Hexagon::V4_SA1_addrx; 1253be8c453dSColin LeMahieu else if ((inst & V4_SA1_addsp_MASK) == V4_SA1_addsp_BITS) 1254be8c453dSColin LeMahieu op = Hexagon::V4_SA1_addsp; 1255be8c453dSColin LeMahieu else if ((inst & V4_SA1_and1_MASK) == V4_SA1_and1_BITS) 1256be8c453dSColin LeMahieu op = Hexagon::V4_SA1_and1; 1257be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrf_MASK) == V4_SA1_clrf_BITS) 1258be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrf; 1259be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrfnew_MASK) == V4_SA1_clrfnew_BITS) 1260be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrfnew; 1261be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrt_MASK) == V4_SA1_clrt_BITS) 1262be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrt; 1263be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrtnew_MASK) == V4_SA1_clrtnew_BITS) 1264be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrtnew; 1265be8c453dSColin LeMahieu else if ((inst & V4_SA1_cmpeqi_MASK) == V4_SA1_cmpeqi_BITS) 1266be8c453dSColin LeMahieu op = Hexagon::V4_SA1_cmpeqi; 1267be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine0i_MASK) == V4_SA1_combine0i_BITS) 1268be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine0i; 1269be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine1i_MASK) == V4_SA1_combine1i_BITS) 1270be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine1i; 1271be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine2i_MASK) == V4_SA1_combine2i_BITS) 1272be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine2i; 1273be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine3i_MASK) == V4_SA1_combine3i_BITS) 1274be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine3i; 1275be8c453dSColin LeMahieu else if ((inst & V4_SA1_combinerz_MASK) == V4_SA1_combinerz_BITS) 1276be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combinerz; 1277be8c453dSColin LeMahieu else if ((inst & V4_SA1_combinezr_MASK) == V4_SA1_combinezr_BITS) 1278be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combinezr; 1279be8c453dSColin LeMahieu else if ((inst & V4_SA1_dec_MASK) == V4_SA1_dec_BITS) 1280be8c453dSColin LeMahieu op = Hexagon::V4_SA1_dec; 1281be8c453dSColin LeMahieu else if ((inst & V4_SA1_inc_MASK) == V4_SA1_inc_BITS) 1282be8c453dSColin LeMahieu op = Hexagon::V4_SA1_inc; 1283be8c453dSColin LeMahieu else if ((inst & V4_SA1_seti_MASK) == V4_SA1_seti_BITS) 1284be8c453dSColin LeMahieu op = Hexagon::V4_SA1_seti; 1285be8c453dSColin LeMahieu else if ((inst & V4_SA1_setin1_MASK) == V4_SA1_setin1_BITS) 1286be8c453dSColin LeMahieu op = Hexagon::V4_SA1_setin1; 1287be8c453dSColin LeMahieu else if ((inst & V4_SA1_sxtb_MASK) == V4_SA1_sxtb_BITS) 1288be8c453dSColin LeMahieu op = Hexagon::V4_SA1_sxtb; 1289be8c453dSColin LeMahieu else if ((inst & V4_SA1_sxth_MASK) == V4_SA1_sxth_BITS) 1290be8c453dSColin LeMahieu op = Hexagon::V4_SA1_sxth; 1291be8c453dSColin LeMahieu else if ((inst & V4_SA1_tfr_MASK) == V4_SA1_tfr_BITS) 1292be8c453dSColin LeMahieu op = Hexagon::V4_SA1_tfr; 1293be8c453dSColin LeMahieu else if ((inst & V4_SA1_zxtb_MASK) == V4_SA1_zxtb_BITS) 1294be8c453dSColin LeMahieu op = Hexagon::V4_SA1_zxtb; 1295be8c453dSColin LeMahieu else if ((inst & V4_SA1_zxth_MASK) == V4_SA1_zxth_BITS) 1296be8c453dSColin LeMahieu op = Hexagon::V4_SA1_zxth; 1297be8c453dSColin LeMahieu else { 1298be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1299be8c453dSColin LeMahieu return MCDisassembler::Fail; 1300be8c453dSColin LeMahieu } 1301be8c453dSColin LeMahieu break; 1302be8c453dSColin LeMahieu case HexagonII::HSIG_S1: 1303be8c453dSColin LeMahieu if ((inst & V4_SS1_storeb_io_MASK) == V4_SS1_storeb_io_BITS) 1304be8c453dSColin LeMahieu op = Hexagon::V4_SS1_storeb_io; 1305be8c453dSColin LeMahieu else if ((inst & V4_SS1_storew_io_MASK) == V4_SS1_storew_io_BITS) 1306be8c453dSColin LeMahieu op = Hexagon::V4_SS1_storew_io; 1307be8c453dSColin LeMahieu else { 1308be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1309be8c453dSColin LeMahieu return MCDisassembler::Fail; 1310be8c453dSColin LeMahieu } 1311be8c453dSColin LeMahieu break; 1312be8c453dSColin LeMahieu case HexagonII::HSIG_S2: 1313be8c453dSColin LeMahieu if ((inst & V4_SS2_allocframe_MASK) == V4_SS2_allocframe_BITS) 1314be8c453dSColin LeMahieu op = Hexagon::V4_SS2_allocframe; 1315be8c453dSColin LeMahieu else if ((inst & V4_SS2_storebi0_MASK) == V4_SS2_storebi0_BITS) 1316be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storebi0; 1317be8c453dSColin LeMahieu else if ((inst & V4_SS2_storebi1_MASK) == V4_SS2_storebi1_BITS) 1318be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storebi1; 1319be8c453dSColin LeMahieu else if ((inst & V4_SS2_stored_sp_MASK) == V4_SS2_stored_sp_BITS) 1320be8c453dSColin LeMahieu op = Hexagon::V4_SS2_stored_sp; 1321be8c453dSColin LeMahieu else if ((inst & V4_SS2_storeh_io_MASK) == V4_SS2_storeh_io_BITS) 1322be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storeh_io; 1323be8c453dSColin LeMahieu else if ((inst & V4_SS2_storew_sp_MASK) == V4_SS2_storew_sp_BITS) 1324be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storew_sp; 1325be8c453dSColin LeMahieu else if ((inst & V4_SS2_storewi0_MASK) == V4_SS2_storewi0_BITS) 1326be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storewi0; 1327be8c453dSColin LeMahieu else if ((inst & V4_SS2_storewi1_MASK) == V4_SS2_storewi1_BITS) 1328be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storewi1; 1329be8c453dSColin LeMahieu else { 1330be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1331be8c453dSColin LeMahieu return MCDisassembler::Fail; 1332be8c453dSColin LeMahieu } 1333be8c453dSColin LeMahieu break; 1334be8c453dSColin LeMahieu default: 1335be8c453dSColin LeMahieu os << "<unknown>"; 1336be8c453dSColin LeMahieu return MCDisassembler::Fail; 1337be8c453dSColin LeMahieu } 1338be8c453dSColin LeMahieu return MCDisassembler::Success; 1339be8c453dSColin LeMahieu } 1340be8c453dSColin LeMahieu 1341be8c453dSColin LeMahieu static unsigned getRegFromSubinstEncoding(unsigned encoded_reg) { 1342be8c453dSColin LeMahieu if (encoded_reg < 8) 1343be8c453dSColin LeMahieu return Hexagon::R0 + encoded_reg; 1344be8c453dSColin LeMahieu else if (encoded_reg < 16) 1345be8c453dSColin LeMahieu return Hexagon::R0 + encoded_reg + 8; 13467cd08927SColin LeMahieu 13477cd08927SColin LeMahieu // patently false value 1348be8c453dSColin LeMahieu return Hexagon::NoRegister; 1349be8c453dSColin LeMahieu } 1350be8c453dSColin LeMahieu 1351be8c453dSColin LeMahieu static unsigned getDRegFromSubinstEncoding(unsigned encoded_dreg) { 1352be8c453dSColin LeMahieu if (encoded_dreg < 4) 1353be8c453dSColin LeMahieu return Hexagon::D0 + encoded_dreg; 1354be8c453dSColin LeMahieu else if (encoded_dreg < 8) 1355be8c453dSColin LeMahieu return Hexagon::D0 + encoded_dreg + 4; 13567cd08927SColin LeMahieu 13577cd08927SColin LeMahieu // patently false value 1358be8c453dSColin LeMahieu return Hexagon::NoRegister; 1359be8c453dSColin LeMahieu } 1360be8c453dSColin LeMahieu 13617cd08927SColin LeMahieu void HexagonDisassembler::addSubinstOperands(MCInst *MI, unsigned opcode, 13627cd08927SColin LeMahieu unsigned inst) const { 1363be8c453dSColin LeMahieu int64_t operand; 1364be8c453dSColin LeMahieu MCOperand Op; 1365be8c453dSColin LeMahieu switch (opcode) { 1366be8c453dSColin LeMahieu case Hexagon::V4_SL2_deallocframe: 1367be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31: 1368be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_f: 1369be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_fnew: 1370be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_t: 1371be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_tnew: 1372be8c453dSColin LeMahieu case Hexagon::V4_SL2_return: 1373be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_f: 1374be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_fnew: 1375be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_t: 1376be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_tnew: 1377be8c453dSColin LeMahieu // no operands for these instructions 1378be8c453dSColin LeMahieu break; 1379be8c453dSColin LeMahieu case Hexagon::V4_SS2_allocframe: 1380be8c453dSColin LeMahieu // u 8-4{5_3} 1381be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 3; 13827cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1383be8c453dSColin LeMahieu break; 1384be8c453dSColin LeMahieu case Hexagon::V4_SL1_loadri_io: 1385be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 11-8{4_2} 1386be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1387be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1388be8c453dSColin LeMahieu MI->addOperand(Op); 1389be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1390be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1391be8c453dSColin LeMahieu MI->addOperand(Op); 1392be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 6; 13937cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1394be8c453dSColin LeMahieu break; 1395be8c453dSColin LeMahieu case Hexagon::V4_SL1_loadrub_io: 1396be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 11-8 1397be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1398be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1399be8c453dSColin LeMahieu MI->addOperand(Op); 1400be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1401be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1402be8c453dSColin LeMahieu MI->addOperand(Op); 1403be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 8; 14047cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1405be8c453dSColin LeMahieu break; 1406be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadrb_io: 1407be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 10-8 1408be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1409be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1410be8c453dSColin LeMahieu MI->addOperand(Op); 1411be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1412be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1413be8c453dSColin LeMahieu MI->addOperand(Op); 1414be8c453dSColin LeMahieu operand = (inst & 0x700) >> 8; 14157cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1416be8c453dSColin LeMahieu break; 1417be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadrh_io: 1418be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadruh_io: 1419be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 10-8{3_1} 1420be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1421be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1422be8c453dSColin LeMahieu MI->addOperand(Op); 1423be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1424be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1425be8c453dSColin LeMahieu MI->addOperand(Op); 1426be8c453dSColin LeMahieu operand = ((inst & 0x700) >> 8) << 1; 14277cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1428be8c453dSColin LeMahieu break; 1429be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadrd_sp: 1430be8c453dSColin LeMahieu // Rdd 2-0, u 7-3{5_3} 1431be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1432be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1433be8c453dSColin LeMahieu MI->addOperand(Op); 1434be8c453dSColin LeMahieu operand = ((inst & 0x0f8) >> 3) << 3; 14357cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1436be8c453dSColin LeMahieu break; 1437be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadri_sp: 1438be8c453dSColin LeMahieu // Rd 3-0, u 8-4{5_2} 1439be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1440be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1441be8c453dSColin LeMahieu MI->addOperand(Op); 1442be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 2; 14437cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1444be8c453dSColin LeMahieu break; 1445be8c453dSColin LeMahieu case Hexagon::V4_SA1_addi: 1446be8c453dSColin LeMahieu // Rx 3-0 (x2), s7 10-4 1447be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1448be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1449be8c453dSColin LeMahieu MI->addOperand(Op); 1450be8c453dSColin LeMahieu MI->addOperand(Op); 1451be8c453dSColin LeMahieu operand = SignExtend64<7>((inst & 0x7f0) >> 4); 14527cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1453be8c453dSColin LeMahieu break; 1454be8c453dSColin LeMahieu case Hexagon::V4_SA1_addrx: 1455be8c453dSColin LeMahieu // Rx 3-0 (x2), Rs 7-4 1456be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1457be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1458be8c453dSColin LeMahieu MI->addOperand(Op); 1459be8c453dSColin LeMahieu MI->addOperand(Op); 1460be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1461be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1462be8c453dSColin LeMahieu MI->addOperand(Op); 1463*bb0cdfb9SColin LeMahieu break; 1464be8c453dSColin LeMahieu case Hexagon::V4_SA1_and1: 1465be8c453dSColin LeMahieu case Hexagon::V4_SA1_dec: 1466be8c453dSColin LeMahieu case Hexagon::V4_SA1_inc: 1467be8c453dSColin LeMahieu case Hexagon::V4_SA1_sxtb: 1468be8c453dSColin LeMahieu case Hexagon::V4_SA1_sxth: 1469be8c453dSColin LeMahieu case Hexagon::V4_SA1_tfr: 1470be8c453dSColin LeMahieu case Hexagon::V4_SA1_zxtb: 1471be8c453dSColin LeMahieu case Hexagon::V4_SA1_zxth: 1472be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4 1473be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1474be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1475be8c453dSColin LeMahieu MI->addOperand(Op); 1476be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1477be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1478be8c453dSColin LeMahieu MI->addOperand(Op); 1479be8c453dSColin LeMahieu break; 1480be8c453dSColin LeMahieu case Hexagon::V4_SA1_addsp: 1481be8c453dSColin LeMahieu // Rd 3-0, u 9-4{6_2} 1482be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1483be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1484be8c453dSColin LeMahieu MI->addOperand(Op); 1485be8c453dSColin LeMahieu operand = ((inst & 0x3f0) >> 4) << 2; 14867cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1487be8c453dSColin LeMahieu break; 1488be8c453dSColin LeMahieu case Hexagon::V4_SA1_seti: 1489be8c453dSColin LeMahieu // Rd 3-0, u 9-4 1490be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1491be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1492be8c453dSColin LeMahieu MI->addOperand(Op); 1493be8c453dSColin LeMahieu operand = (inst & 0x3f0) >> 4; 14947cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1495be8c453dSColin LeMahieu break; 1496be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrf: 1497be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrfnew: 1498be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrt: 1499be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrtnew: 1500be8c453dSColin LeMahieu case Hexagon::V4_SA1_setin1: 1501be8c453dSColin LeMahieu // Rd 3-0 1502be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1503be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1504be8c453dSColin LeMahieu MI->addOperand(Op); 1505be8c453dSColin LeMahieu break; 1506be8c453dSColin LeMahieu case Hexagon::V4_SA1_cmpeqi: 1507be8c453dSColin LeMahieu // Rs 7-4, u 1-0 1508be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1509be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1510be8c453dSColin LeMahieu MI->addOperand(Op); 1511be8c453dSColin LeMahieu operand = inst & 0x3; 15127cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1513be8c453dSColin LeMahieu break; 1514be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine0i: 1515be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine1i: 1516be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine2i: 1517be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine3i: 1518be8c453dSColin LeMahieu // Rdd 2-0, u 6-5 1519be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1520be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1521be8c453dSColin LeMahieu MI->addOperand(Op); 1522be8c453dSColin LeMahieu operand = (inst & 0x060) >> 5; 15237cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1524be8c453dSColin LeMahieu break; 1525be8c453dSColin LeMahieu case Hexagon::V4_SA1_combinerz: 1526be8c453dSColin LeMahieu case Hexagon::V4_SA1_combinezr: 1527be8c453dSColin LeMahieu // Rdd 2-0, Rs 7-4 1528be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1529be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1530be8c453dSColin LeMahieu MI->addOperand(Op); 1531be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1532be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1533be8c453dSColin LeMahieu MI->addOperand(Op); 1534be8c453dSColin LeMahieu break; 1535be8c453dSColin LeMahieu case Hexagon::V4_SS1_storeb_io: 1536be8c453dSColin LeMahieu // Rs 7-4, u 11-8, Rt 3-0 1537be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1538be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1539be8c453dSColin LeMahieu MI->addOperand(Op); 1540be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 8; 15417cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1542be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1543be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1544be8c453dSColin LeMahieu MI->addOperand(Op); 1545be8c453dSColin LeMahieu break; 1546be8c453dSColin LeMahieu case Hexagon::V4_SS1_storew_io: 1547be8c453dSColin LeMahieu // Rs 7-4, u 11-8{4_2}, Rt 3-0 1548be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1549be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1550be8c453dSColin LeMahieu MI->addOperand(Op); 1551be8c453dSColin LeMahieu operand = ((inst & 0xf00) >> 8) << 2; 15527cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1553be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1554be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1555be8c453dSColin LeMahieu MI->addOperand(Op); 1556be8c453dSColin LeMahieu break; 1557be8c453dSColin LeMahieu case Hexagon::V4_SS2_storebi0: 1558be8c453dSColin LeMahieu case Hexagon::V4_SS2_storebi1: 1559be8c453dSColin LeMahieu // Rs 7-4, u 3-0 1560be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1561be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1562be8c453dSColin LeMahieu MI->addOperand(Op); 1563be8c453dSColin LeMahieu operand = inst & 0xf; 15647cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1565be8c453dSColin LeMahieu break; 1566be8c453dSColin LeMahieu case Hexagon::V4_SS2_storewi0: 1567be8c453dSColin LeMahieu case Hexagon::V4_SS2_storewi1: 1568be8c453dSColin LeMahieu // Rs 7-4, u 3-0{4_2} 1569be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1570be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1571be8c453dSColin LeMahieu MI->addOperand(Op); 1572be8c453dSColin LeMahieu operand = (inst & 0xf) << 2; 15737cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1574be8c453dSColin LeMahieu break; 1575be8c453dSColin LeMahieu case Hexagon::V4_SS2_stored_sp: 1576be8c453dSColin LeMahieu // s 8-3{6_3}, Rtt 2-0 1577be8c453dSColin LeMahieu operand = SignExtend64<9>(((inst & 0x1f8) >> 3) << 3); 15787cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1579be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1580be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1581be8c453dSColin LeMahieu MI->addOperand(Op); 1582160f73e3SColin LeMahieu break; 1583be8c453dSColin LeMahieu case Hexagon::V4_SS2_storeh_io: 1584be8c453dSColin LeMahieu // Rs 7-4, u 10-8{3_1}, Rt 3-0 1585be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1586be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1587be8c453dSColin LeMahieu MI->addOperand(Op); 1588be8c453dSColin LeMahieu operand = ((inst & 0x700) >> 8) << 1; 15897cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1590be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1591be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1592be8c453dSColin LeMahieu MI->addOperand(Op); 1593be8c453dSColin LeMahieu break; 1594be8c453dSColin LeMahieu case Hexagon::V4_SS2_storew_sp: 1595be8c453dSColin LeMahieu // u 8-4{5_2}, Rd 3-0 1596be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 2; 15977cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1598be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1599be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1600be8c453dSColin LeMahieu MI->addOperand(Op); 1601be8c453dSColin LeMahieu break; 1602be8c453dSColin LeMahieu default: 1603be8c453dSColin LeMahieu // don't crash with an invalid subinstruction 1604be8c453dSColin LeMahieu // llvm_unreachable("Invalid subinstruction in duplex instruction"); 1605be8c453dSColin LeMahieu break; 1606be8c453dSColin LeMahieu } 1607be8c453dSColin LeMahieu } 1608