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" 19*f57c1977SBenjamin 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) 3857cd08927SColin LeMahieu // Subreg bit should not be set for non-doublevector newvalue producers 3867cd08927SColin LeMahieu return MCDisassembler::Fail; 3877cd08927SColin LeMahieu assert(Producer != Hexagon::NoRegister); 3887cd08927SColin LeMahieu MCO.setReg(Producer); 3897cd08927SColin LeMahieu } else 3907cd08927SColin LeMahieu return MCDisassembler::Fail; 3917cd08927SColin LeMahieu } 3927cd08927SColin LeMahieu 3937cd08927SColin LeMahieu adjustExtendedInstructions(MI, MCB); 3947cd08927SColin LeMahieu MCInst const *Extender = 3957cd08927SColin LeMahieu HexagonMCInstrInfo::extenderForIndex(MCB, 3967cd08927SColin LeMahieu HexagonMCInstrInfo::bundleSize(MCB)); 3977cd08927SColin LeMahieu if(Extender != nullptr) { 3987cd08927SColin LeMahieu MCInst const & Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) ? 3997cd08927SColin LeMahieu *MI.getOperand(1).getInst() : MI; 4007cd08927SColin LeMahieu if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) && 4017cd08927SColin LeMahieu !HexagonMCInstrInfo::isExtended(*MCII, Inst)) 4027cd08927SColin LeMahieu return MCDisassembler::Fail; 4037cd08927SColin LeMahieu } 4045d6f03bdSColin LeMahieu return Result; 40588ebb9e2SColin LeMahieu } 4067cd08927SColin LeMahieu 4077cd08927SColin LeMahieu void HexagonDisassembler::adjustExtendedInstructions(MCInst &MCI, 4087cd08927SColin LeMahieu MCInst const &MCB) const { 4097cd08927SColin LeMahieu if (!HexagonMCInstrInfo::hasExtenderForIndex( 4107cd08927SColin LeMahieu MCB, HexagonMCInstrInfo::bundleSize(MCB))) { 4117cd08927SColin LeMahieu unsigned opcode; 4127cd08927SColin LeMahieu // This code is used by the disassembler to disambiguate between GP 4137cd08927SColin LeMahieu // relative and absolute addressing instructions since they both have 4147cd08927SColin LeMahieu // same encoding bits. However, an absolute addressing instruction must 4157cd08927SColin LeMahieu // follow an immediate extender. Disassembler alwaus select absolute 4167cd08927SColin LeMahieu // addressing instructions first and uses this code to change them into 4177cd08927SColin LeMahieu // GP relative instruction in the absence of the corresponding immediate 4187cd08927SColin LeMahieu // extender. 4197cd08927SColin LeMahieu switch (MCI.getOpcode()) { 4207cd08927SColin LeMahieu case Hexagon::S2_storerbabs: 4217cd08927SColin LeMahieu opcode = Hexagon::S2_storerbgp; 4227cd08927SColin LeMahieu break; 4237cd08927SColin LeMahieu case Hexagon::S2_storerhabs: 4247cd08927SColin LeMahieu opcode = Hexagon::S2_storerhgp; 4257cd08927SColin LeMahieu break; 4267cd08927SColin LeMahieu case Hexagon::S2_storerfabs: 4277cd08927SColin LeMahieu opcode = Hexagon::S2_storerfgp; 4287cd08927SColin LeMahieu break; 4297cd08927SColin LeMahieu case Hexagon::S2_storeriabs: 4307cd08927SColin LeMahieu opcode = Hexagon::S2_storerigp; 4317cd08927SColin LeMahieu break; 4327cd08927SColin LeMahieu case Hexagon::S2_storerbnewabs: 4337cd08927SColin LeMahieu opcode = Hexagon::S2_storerbnewgp; 4347cd08927SColin LeMahieu break; 4357cd08927SColin LeMahieu case Hexagon::S2_storerhnewabs: 4367cd08927SColin LeMahieu opcode = Hexagon::S2_storerhnewgp; 4377cd08927SColin LeMahieu break; 4387cd08927SColin LeMahieu case Hexagon::S2_storerinewabs: 4397cd08927SColin LeMahieu opcode = Hexagon::S2_storerinewgp; 4407cd08927SColin LeMahieu break; 4417cd08927SColin LeMahieu case Hexagon::S2_storerdabs: 4427cd08927SColin LeMahieu opcode = Hexagon::S2_storerdgp; 4437cd08927SColin LeMahieu break; 4447cd08927SColin LeMahieu case Hexagon::L4_loadrb_abs: 4457cd08927SColin LeMahieu opcode = Hexagon::L2_loadrbgp; 4467cd08927SColin LeMahieu break; 4477cd08927SColin LeMahieu case Hexagon::L4_loadrub_abs: 4487cd08927SColin LeMahieu opcode = Hexagon::L2_loadrubgp; 4497cd08927SColin LeMahieu break; 4507cd08927SColin LeMahieu case Hexagon::L4_loadrh_abs: 4517cd08927SColin LeMahieu opcode = Hexagon::L2_loadrhgp; 4527cd08927SColin LeMahieu break; 4537cd08927SColin LeMahieu case Hexagon::L4_loadruh_abs: 4547cd08927SColin LeMahieu opcode = Hexagon::L2_loadruhgp; 4557cd08927SColin LeMahieu break; 4567cd08927SColin LeMahieu case Hexagon::L4_loadri_abs: 4577cd08927SColin LeMahieu opcode = Hexagon::L2_loadrigp; 4587cd08927SColin LeMahieu break; 4597cd08927SColin LeMahieu case Hexagon::L4_loadrd_abs: 4607cd08927SColin LeMahieu opcode = Hexagon::L2_loadrdgp; 4617cd08927SColin LeMahieu break; 4627cd08927SColin LeMahieu default: 4637cd08927SColin LeMahieu opcode = MCI.getOpcode(); 4647cd08927SColin LeMahieu } 4657cd08927SColin LeMahieu MCI.setOpcode(opcode); 4667cd08927SColin LeMahieu } 4677cd08927SColin LeMahieu } 4687cd08927SColin LeMahieu 4697cd08927SColin LeMahieu namespace llvm { 4707cd08927SColin LeMahieu extern const MCInstrDesc HexagonInsts[]; 4717cd08927SColin LeMahieu } 4727cd08927SColin LeMahieu 4737cd08927SColin LeMahieu static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, 474e5e035a3SCraig Topper ArrayRef<MCPhysReg> Table) { 4753da000c0SCraig Topper if (RegNo < Table.size()) { 4767cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Table[RegNo])); 4777cd08927SColin LeMahieu return MCDisassembler::Success; 4783da000c0SCraig Topper } 4793da000c0SCraig Topper 4807cd08927SColin LeMahieu return MCDisassembler::Fail; 4817cd08927SColin LeMahieu } 4827cd08927SColin LeMahieu 4837c958713SColin LeMahieu static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, 4847c958713SColin LeMahieu uint64_t Address, 4857c958713SColin LeMahieu const void *Decoder) { 4867c958713SColin LeMahieu return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder); 4877c958713SColin LeMahieu } 4887c958713SColin LeMahieu 4897cd08927SColin LeMahieu static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, 4907cd08927SColin LeMahieu uint64_t Address, 4917cd08927SColin LeMahieu const void *Decoder) { 492e5e035a3SCraig Topper static const MCPhysReg IntRegDecoderTable[] = { 4937cd08927SColin LeMahieu Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, 4947cd08927SColin LeMahieu Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9, 4957cd08927SColin LeMahieu Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14, 4967cd08927SColin LeMahieu Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, 4977cd08927SColin LeMahieu Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24, 4987cd08927SColin LeMahieu Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29, 4997cd08927SColin LeMahieu Hexagon::R30, Hexagon::R31}; 5007cd08927SColin LeMahieu 501e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable); 5027cd08927SColin LeMahieu } 5037c958713SColin LeMahieu 5047c958713SColin LeMahieu static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5057c958713SColin LeMahieu uint64_t /*Address*/, 5067c958713SColin LeMahieu const void *Decoder) { 507e5e035a3SCraig Topper static const MCPhysReg VecRegDecoderTable[] = { 5087c958713SColin LeMahieu Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, 5097c958713SColin LeMahieu Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, 5107c958713SColin LeMahieu Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, 5117c958713SColin LeMahieu Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19, 5127c958713SColin LeMahieu Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24, 5137c958713SColin LeMahieu Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29, 5147c958713SColin LeMahieu Hexagon::V30, Hexagon::V31}; 5157c958713SColin LeMahieu 516e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable); 5177c958713SColin LeMahieu } 5187c958713SColin LeMahieu 5197cd08927SColin LeMahieu static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5207cd08927SColin LeMahieu uint64_t /*Address*/, 5217cd08927SColin LeMahieu const void *Decoder) { 522e5e035a3SCraig Topper static const MCPhysReg DoubleRegDecoderTable[] = { 5237cd08927SColin LeMahieu Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, 5247cd08927SColin LeMahieu Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7, 5257cd08927SColin LeMahieu Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11, 5267cd08927SColin LeMahieu Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15}; 5277cd08927SColin LeMahieu 528e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable); 5297cd08927SColin LeMahieu } 5307cd08927SColin LeMahieu 5317c958713SColin LeMahieu static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5327c958713SColin LeMahieu uint64_t /*Address*/, 5337c958713SColin LeMahieu const void *Decoder) { 534e5e035a3SCraig Topper static const MCPhysReg VecDblRegDecoderTable[] = { 5357c958713SColin LeMahieu Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, 5367c958713SColin LeMahieu Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7, 5377c958713SColin LeMahieu Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11, 5387c958713SColin LeMahieu Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15}; 5397c958713SColin LeMahieu 5403da000c0SCraig Topper return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable)); 5417c958713SColin LeMahieu } 5427c958713SColin LeMahieu 5437cd08927SColin LeMahieu static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5447cd08927SColin LeMahieu uint64_t /*Address*/, 5457cd08927SColin LeMahieu const void *Decoder) { 546e5e035a3SCraig Topper static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1, 5477cd08927SColin LeMahieu Hexagon::P2, Hexagon::P3}; 5487cd08927SColin LeMahieu 549e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable); 5507cd08927SColin LeMahieu } 5517cd08927SColin LeMahieu 5527c958713SColin LeMahieu static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5537c958713SColin LeMahieu uint64_t /*Address*/, 5547c958713SColin LeMahieu const void *Decoder) { 555e5e035a3SCraig Topper static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1, 5567c958713SColin LeMahieu Hexagon::Q2, Hexagon::Q3}; 5577c958713SColin LeMahieu 558e5e035a3SCraig Topper return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable); 5597c958713SColin LeMahieu } 560be8c453dSColin LeMahieu 5617cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, 5627cd08927SColin LeMahieu uint64_t /*Address*/, 5637cd08927SColin LeMahieu const void *Decoder) { 564e5e035a3SCraig Topper static const MCPhysReg CtrlRegDecoderTable[] = { 5657cd08927SColin LeMahieu Hexagon::SA0, Hexagon::LC0, Hexagon::SA1, Hexagon::LC1, 5667cd08927SColin LeMahieu Hexagon::P3_0, Hexagon::C5, Hexagon::C6, Hexagon::C7, 5677cd08927SColin LeMahieu Hexagon::USR, Hexagon::PC, Hexagon::UGP, Hexagon::GP, 5687cd08927SColin LeMahieu Hexagon::CS0, Hexagon::CS1, Hexagon::UPCL, Hexagon::UPC 5697cd08927SColin LeMahieu }; 5707cd08927SColin LeMahieu 5716261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlRegDecoderTable)) 5727cd08927SColin LeMahieu return MCDisassembler::Fail; 5737cd08927SColin LeMahieu 5747cd08927SColin LeMahieu if (CtrlRegDecoderTable[RegNo] == Hexagon::NoRegister) 5757cd08927SColin LeMahieu return MCDisassembler::Fail; 5767cd08927SColin LeMahieu 5777cd08927SColin LeMahieu unsigned Register = CtrlRegDecoderTable[RegNo]; 5787cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 5797cd08927SColin LeMahieu return MCDisassembler::Success; 5807cd08927SColin LeMahieu } 5817cd08927SColin LeMahieu 5827cd08927SColin LeMahieu static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, 5837cd08927SColin LeMahieu uint64_t /*Address*/, 5847cd08927SColin LeMahieu const void *Decoder) { 585e5e035a3SCraig Topper static const MCPhysReg CtrlReg64DecoderTable[] = { 5867cd08927SColin LeMahieu Hexagon::C1_0, Hexagon::NoRegister, 5877cd08927SColin LeMahieu Hexagon::C3_2, Hexagon::NoRegister, 5887cd08927SColin LeMahieu Hexagon::C7_6, Hexagon::NoRegister, 5897cd08927SColin LeMahieu Hexagon::C9_8, Hexagon::NoRegister, 5907cd08927SColin LeMahieu Hexagon::C11_10, Hexagon::NoRegister, 5917cd08927SColin LeMahieu Hexagon::CS, Hexagon::NoRegister, 5927cd08927SColin LeMahieu Hexagon::UPC, Hexagon::NoRegister 5937cd08927SColin LeMahieu }; 5947cd08927SColin LeMahieu 5956261e1b9SCraig Topper if (RegNo >= array_lengthof(CtrlReg64DecoderTable)) 5967cd08927SColin LeMahieu return MCDisassembler::Fail; 5977cd08927SColin LeMahieu 5987cd08927SColin LeMahieu if (CtrlReg64DecoderTable[RegNo] == Hexagon::NoRegister) 5997cd08927SColin LeMahieu return MCDisassembler::Fail; 6007cd08927SColin LeMahieu 6017cd08927SColin LeMahieu unsigned Register = CtrlReg64DecoderTable[RegNo]; 6027cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 6037cd08927SColin LeMahieu return MCDisassembler::Success; 6047cd08927SColin LeMahieu } 6057cd08927SColin LeMahieu 6067cd08927SColin LeMahieu static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, 6077cd08927SColin LeMahieu uint64_t /*Address*/, 6087cd08927SColin LeMahieu const void *Decoder) { 6097cd08927SColin LeMahieu unsigned Register = 0; 6107cd08927SColin LeMahieu switch (RegNo) { 6117cd08927SColin LeMahieu case 0: 6127cd08927SColin LeMahieu Register = Hexagon::M0; 6137cd08927SColin LeMahieu break; 6147cd08927SColin LeMahieu case 1: 6157cd08927SColin LeMahieu Register = Hexagon::M1; 6167cd08927SColin LeMahieu break; 6177cd08927SColin LeMahieu default: 6187cd08927SColin LeMahieu return MCDisassembler::Fail; 6197cd08927SColin LeMahieu } 6207cd08927SColin LeMahieu Inst.addOperand(MCOperand::createReg(Register)); 6217cd08927SColin LeMahieu return MCDisassembler::Success; 6227cd08927SColin LeMahieu } 6237cd08927SColin LeMahieu 6247cd08927SColin LeMahieu namespace { 6257cd08927SColin LeMahieu uint32_t fullValue(MCInstrInfo const &MCII, 6267cd08927SColin LeMahieu MCInst &MCB, 6277cd08927SColin LeMahieu MCInst &MI, 6287cd08927SColin LeMahieu int64_t Value) { 6297cd08927SColin LeMahieu MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( 6307cd08927SColin LeMahieu MCB, HexagonMCInstrInfo::bundleSize(MCB)); 6317cd08927SColin LeMahieu if(!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI)) 6327cd08927SColin LeMahieu return Value; 6337cd08927SColin LeMahieu unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI); 6347cd08927SColin LeMahieu uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f; 6357cd08927SColin LeMahieu int64_t Bits; 6367cd08927SColin LeMahieu bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits); 6377cd08927SColin LeMahieu assert(Success);(void)Success; 6387cd08927SColin LeMahieu uint32_t Upper26 = static_cast<uint32_t>(Bits); 6397cd08927SColin LeMahieu uint32_t Operand = Upper26 | Lower6; 6407cd08927SColin LeMahieu return Operand; 6417cd08927SColin LeMahieu } 6427cd08927SColin LeMahieu template <size_t T> 6437cd08927SColin LeMahieu void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) { 6447cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6457cd08927SColin LeMahieu int64_t FullValue = fullValue(*Disassembler.MCII, 6467cd08927SColin LeMahieu **Disassembler.CurrentBundle, 6477cd08927SColin LeMahieu MI, SignExtend64<T>(tmp)); 6487cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue); 6497cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, 6507cd08927SColin LeMahieu Disassembler.getContext()); 6517cd08927SColin LeMahieu } 6527cd08927SColin LeMahieu } 6537cd08927SColin LeMahieu 6547cd08927SColin LeMahieu static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, 6557cd08927SColin LeMahieu uint64_t /*Address*/, 6567cd08927SColin LeMahieu const void *Decoder) { 6577cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 6587cd08927SColin LeMahieu int64_t FullValue = fullValue(*Disassembler.MCII, 6597cd08927SColin LeMahieu **Disassembler.CurrentBundle, 6607cd08927SColin LeMahieu MI, tmp); 6617cd08927SColin LeMahieu assert(FullValue >= 0 && "Negative in unsigned decoder"); 6627cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext()); 6637cd08927SColin LeMahieu return MCDisassembler::Success; 6647cd08927SColin LeMahieu } 6657cd08927SColin LeMahieu 6661e9d1d76SColin LeMahieu static DecodeStatus s16ImmDecoder(MCInst &MI, unsigned tmp, 6671e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6687cd08927SColin LeMahieu signedDecoder<16>(MI, tmp, Decoder); 6691e9d1d76SColin LeMahieu return MCDisassembler::Success; 6701e9d1d76SColin LeMahieu } 6711e9d1d76SColin LeMahieu 6721e9d1d76SColin LeMahieu static DecodeStatus s12ImmDecoder(MCInst &MI, unsigned tmp, 6731e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6747cd08927SColin LeMahieu signedDecoder<12>(MI, tmp, Decoder); 6751e9d1d76SColin LeMahieu return MCDisassembler::Success; 6761e9d1d76SColin LeMahieu } 6771e9d1d76SColin LeMahieu 6781e9d1d76SColin LeMahieu static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, 6791e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6807cd08927SColin LeMahieu signedDecoder<11>(MI, tmp, Decoder); 6811e9d1d76SColin LeMahieu return MCDisassembler::Success; 6821e9d1d76SColin LeMahieu } 6831e9d1d76SColin LeMahieu 6841e9d1d76SColin LeMahieu static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, 6851e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6867cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, SignExtend64<12>(tmp), contextFromDecoder(Decoder)); 6871e9d1d76SColin LeMahieu return MCDisassembler::Success; 6881e9d1d76SColin LeMahieu } 6891e9d1d76SColin LeMahieu 6901e9d1d76SColin LeMahieu static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, 6911e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6927cd08927SColin LeMahieu signedDecoder<13>(MI, tmp, Decoder); 6931e9d1d76SColin LeMahieu return MCDisassembler::Success; 6941e9d1d76SColin LeMahieu } 6951e9d1d76SColin LeMahieu 6961e9d1d76SColin LeMahieu static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, 6971e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 6987cd08927SColin LeMahieu signedDecoder<14>(MI, tmp, Decoder); 6991e9d1d76SColin LeMahieu return MCDisassembler::Success; 7001e9d1d76SColin LeMahieu } 7011e9d1d76SColin LeMahieu 7021e9d1d76SColin LeMahieu static DecodeStatus s10ImmDecoder(MCInst &MI, unsigned tmp, 7031e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7047cd08927SColin LeMahieu signedDecoder<10>(MI, tmp, Decoder); 7051e9d1d76SColin LeMahieu return MCDisassembler::Success; 7061e9d1d76SColin LeMahieu } 7071e9d1d76SColin LeMahieu 7081e9d1d76SColin LeMahieu static DecodeStatus s8ImmDecoder(MCInst &MI, unsigned tmp, uint64_t /*Address*/, 7091e9d1d76SColin LeMahieu const void *Decoder) { 7107cd08927SColin LeMahieu signedDecoder<8>(MI, tmp, Decoder); 7111e9d1d76SColin LeMahieu return MCDisassembler::Success; 7121e9d1d76SColin LeMahieu } 7131e9d1d76SColin LeMahieu 7141e9d1d76SColin LeMahieu static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, 7151e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7167cd08927SColin LeMahieu signedDecoder<6>(MI, tmp, Decoder); 7171e9d1d76SColin LeMahieu return MCDisassembler::Success; 7181e9d1d76SColin LeMahieu } 7191e9d1d76SColin LeMahieu 7201e9d1d76SColin LeMahieu static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, 7211e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7227cd08927SColin LeMahieu signedDecoder<4>(MI, tmp, Decoder); 7231e9d1d76SColin LeMahieu return MCDisassembler::Success; 7241e9d1d76SColin LeMahieu } 7251e9d1d76SColin LeMahieu 7261e9d1d76SColin LeMahieu static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, 7271e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7287cd08927SColin LeMahieu signedDecoder<5>(MI, tmp, Decoder); 7291e9d1d76SColin LeMahieu return MCDisassembler::Success; 7301e9d1d76SColin LeMahieu } 7311e9d1d76SColin LeMahieu 7321e9d1d76SColin LeMahieu static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, 7331e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7347cd08927SColin LeMahieu signedDecoder<6>(MI, tmp, Decoder); 7351e9d1d76SColin LeMahieu return MCDisassembler::Success; 7361e9d1d76SColin LeMahieu } 7371e9d1d76SColin LeMahieu 7381e9d1d76SColin LeMahieu static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, 7391e9d1d76SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7407cd08927SColin LeMahieu signedDecoder<7>(MI, tmp, Decoder); 7411e9d1d76SColin LeMahieu return MCDisassembler::Success; 7421e9d1d76SColin LeMahieu } 7431e9d1d76SColin LeMahieu 7447c958713SColin LeMahieu static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, 7457c958713SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7467cd08927SColin LeMahieu signedDecoder<10>(MI, tmp, Decoder); 7477c958713SColin LeMahieu return MCDisassembler::Success; 7487c958713SColin LeMahieu } 7497c958713SColin LeMahieu 7507c958713SColin LeMahieu static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, 7517c958713SColin LeMahieu uint64_t /*Address*/, const void *Decoder) { 7527cd08927SColin LeMahieu signedDecoder<19>(MI, tmp, Decoder); 7537c958713SColin LeMahieu return MCDisassembler::Success; 7547c958713SColin LeMahieu } 7557c958713SColin LeMahieu 7567cd08927SColin LeMahieu // custom decoder for various jump/call immediates 7577cd08927SColin LeMahieu static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, 7587cd08927SColin LeMahieu const void *Decoder) { 7597cd08927SColin LeMahieu HexagonDisassembler const &Disassembler = disassembler(Decoder); 7607cd08927SColin LeMahieu unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); 7617cd08927SColin LeMahieu // r13_2 is not extendable, so if there are no extent bits, it's r13_2 7627cd08927SColin LeMahieu if (Bits == 0) 7637cd08927SColin LeMahieu Bits = 15; 7647cd08927SColin LeMahieu uint32_t FullValue = fullValue(*Disassembler.MCII, 7657cd08927SColin LeMahieu **Disassembler.CurrentBundle, 7667cd08927SColin LeMahieu MI, SignExtend64(tmp, Bits)); 7677cd08927SColin LeMahieu int64_t Extended = SignExtend64<32>(FullValue) + Address; 7687cd08927SColin LeMahieu if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 7697cd08927SColin LeMahieu 0, 4)) 7707cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); 7717cd08927SColin LeMahieu return MCDisassembler::Success; 7727cd08927SColin LeMahieu } 7737cd08927SColin LeMahieu 7747cd08927SColin LeMahieu // Addressing mode dependent load store opcode map. 7757cd08927SColin LeMahieu // - If an insn is preceded by an extender the address is absolute. 7767cd08927SColin LeMahieu // - memw(##symbol) = r0 7777cd08927SColin LeMahieu // - If an insn is not preceded by an extender the address is GP relative. 7787cd08927SColin LeMahieu // - memw(gp + #symbol) = r0 7797cd08927SColin LeMahieu // Please note that the instructions must be ordered in the descending order 7807cd08927SColin LeMahieu // of their opcode. 7817cd08927SColin LeMahieu // HexagonII::INST_ICLASS_ST 782d824f5f0SCraig Topper static const unsigned int StoreConditionalOpcodeData[][2] = { 7837cd08927SColin LeMahieu {S4_pstorerdfnew_abs, 0xafc02084}, 7847cd08927SColin LeMahieu {S4_pstorerdtnew_abs, 0xafc02080}, 7857cd08927SColin LeMahieu {S4_pstorerdf_abs, 0xafc00084}, 7867cd08927SColin LeMahieu {S4_pstorerdt_abs, 0xafc00080}, 7877cd08927SColin LeMahieu {S4_pstorerinewfnew_abs, 0xafa03084}, 7887cd08927SColin LeMahieu {S4_pstorerinewtnew_abs, 0xafa03080}, 7897cd08927SColin LeMahieu {S4_pstorerhnewfnew_abs, 0xafa02884}, 7907cd08927SColin LeMahieu {S4_pstorerhnewtnew_abs, 0xafa02880}, 7917cd08927SColin LeMahieu {S4_pstorerbnewfnew_abs, 0xafa02084}, 7927cd08927SColin LeMahieu {S4_pstorerbnewtnew_abs, 0xafa02080}, 7937cd08927SColin LeMahieu {S4_pstorerinewf_abs, 0xafa01084}, 7947cd08927SColin LeMahieu {S4_pstorerinewt_abs, 0xafa01080}, 7957cd08927SColin LeMahieu {S4_pstorerhnewf_abs, 0xafa00884}, 7967cd08927SColin LeMahieu {S4_pstorerhnewt_abs, 0xafa00880}, 7977cd08927SColin LeMahieu {S4_pstorerbnewf_abs, 0xafa00084}, 7987cd08927SColin LeMahieu {S4_pstorerbnewt_abs, 0xafa00080}, 7997cd08927SColin LeMahieu {S4_pstorerifnew_abs, 0xaf802084}, 8007cd08927SColin LeMahieu {S4_pstoreritnew_abs, 0xaf802080}, 8017cd08927SColin LeMahieu {S4_pstorerif_abs, 0xaf800084}, 8027cd08927SColin LeMahieu {S4_pstorerit_abs, 0xaf800080}, 8037cd08927SColin LeMahieu {S4_pstorerhfnew_abs, 0xaf402084}, 8047cd08927SColin LeMahieu {S4_pstorerhtnew_abs, 0xaf402080}, 8057cd08927SColin LeMahieu {S4_pstorerhf_abs, 0xaf400084}, 8067cd08927SColin LeMahieu {S4_pstorerht_abs, 0xaf400080}, 8077cd08927SColin LeMahieu {S4_pstorerbfnew_abs, 0xaf002084}, 8087cd08927SColin LeMahieu {S4_pstorerbtnew_abs, 0xaf002080}, 8097cd08927SColin LeMahieu {S4_pstorerbf_abs, 0xaf000084}, 8107cd08927SColin LeMahieu {S4_pstorerbt_abs, 0xaf000080}}; 8117cd08927SColin LeMahieu // HexagonII::INST_ICLASS_LD 8127cd08927SColin LeMahieu 8137cd08927SColin LeMahieu // HexagonII::INST_ICLASS_LD_ST_2 8147cd08927SColin LeMahieu static unsigned int LoadStoreOpcodeData[][2] = {{L4_loadrd_abs, 0x49c00000}, 8157cd08927SColin LeMahieu {L4_loadri_abs, 0x49800000}, 8167cd08927SColin LeMahieu {L4_loadruh_abs, 0x49600000}, 8177cd08927SColin LeMahieu {L4_loadrh_abs, 0x49400000}, 8187cd08927SColin LeMahieu {L4_loadrub_abs, 0x49200000}, 8197cd08927SColin LeMahieu {L4_loadrb_abs, 0x49000000}, 8207cd08927SColin LeMahieu {S2_storerdabs, 0x48c00000}, 8217cd08927SColin LeMahieu {S2_storerinewabs, 0x48a01000}, 8227cd08927SColin LeMahieu {S2_storerhnewabs, 0x48a00800}, 8237cd08927SColin LeMahieu {S2_storerbnewabs, 0x48a00000}, 8247cd08927SColin LeMahieu {S2_storeriabs, 0x48800000}, 8257cd08927SColin LeMahieu {S2_storerfabs, 0x48600000}, 8267cd08927SColin LeMahieu {S2_storerhabs, 0x48400000}, 8277cd08927SColin LeMahieu {S2_storerbabs, 0x48000000}}; 828d824f5f0SCraig Topper static const size_t NumCondS = array_lengthof(StoreConditionalOpcodeData); 829d824f5f0SCraig Topper static const size_t NumLS = array_lengthof(LoadStoreOpcodeData); 8307cd08927SColin LeMahieu 8317cd08927SColin LeMahieu static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn) { 8327cd08927SColin LeMahieu 8337cd08927SColin LeMahieu unsigned MachineOpcode = 0; 8347cd08927SColin LeMahieu unsigned LLVMOpcode = 0; 8357cd08927SColin LeMahieu 8367cd08927SColin LeMahieu if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_ST) { 837d824f5f0SCraig Topper for (size_t i = 0; i < NumCondS; ++i) { 8387cd08927SColin LeMahieu if ((insn & StoreConditionalOpcodeData[i][1]) == 8397cd08927SColin LeMahieu StoreConditionalOpcodeData[i][1]) { 8407cd08927SColin LeMahieu MachineOpcode = StoreConditionalOpcodeData[i][1]; 8417cd08927SColin LeMahieu LLVMOpcode = StoreConditionalOpcodeData[i][0]; 8427cd08927SColin LeMahieu break; 8437cd08927SColin LeMahieu } 8447cd08927SColin LeMahieu } 8457cd08927SColin LeMahieu } 8467cd08927SColin LeMahieu if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_LD_ST_2) { 847d824f5f0SCraig Topper for (size_t i = 0; i < NumLS; ++i) { 8487cd08927SColin LeMahieu if ((insn & LoadStoreOpcodeData[i][1]) == LoadStoreOpcodeData[i][1]) { 8497cd08927SColin LeMahieu MachineOpcode = LoadStoreOpcodeData[i][1]; 8507cd08927SColin LeMahieu LLVMOpcode = LoadStoreOpcodeData[i][0]; 8517cd08927SColin LeMahieu break; 8527cd08927SColin LeMahieu } 8537cd08927SColin LeMahieu } 8547cd08927SColin LeMahieu } 8557cd08927SColin LeMahieu 8567cd08927SColin LeMahieu if (MachineOpcode) { 8577cd08927SColin LeMahieu unsigned Value = 0; 8587cd08927SColin LeMahieu unsigned shift = 0; 8597cd08927SColin LeMahieu MI.setOpcode(LLVMOpcode); 8607cd08927SColin LeMahieu // Remove the parse bits from the insn. 8617cd08927SColin LeMahieu insn &= ~HexagonII::INST_PARSE_MASK; 8627cd08927SColin LeMahieu 8637cd08927SColin LeMahieu switch (LLVMOpcode) { 8647cd08927SColin LeMahieu default: 8657cd08927SColin LeMahieu return MCDisassembler::Fail; 8667cd08927SColin LeMahieu break; 8677cd08927SColin LeMahieu 8687cd08927SColin LeMahieu case Hexagon::S4_pstorerdf_abs: 8697cd08927SColin LeMahieu case Hexagon::S4_pstorerdt_abs: 8707cd08927SColin LeMahieu case Hexagon::S4_pstorerdfnew_abs: 8717cd08927SColin LeMahieu case Hexagon::S4_pstorerdtnew_abs: { 8727cd08927SColin LeMahieu // op: Pv 8737cd08927SColin LeMahieu Value = insn & UINT64_C(3); 8747cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 8757cd08927SColin LeMahieu // op: u6 8767cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 8777cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 8787cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 8797cd08927SColin LeMahieu // op: Rtt 8807cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 8817cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 8827cd08927SColin LeMahieu break; 8837cd08927SColin LeMahieu } 8847cd08927SColin LeMahieu 8857cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewf_abs: 8867cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewt_abs: 8877cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewfnew_abs: 8887cd08927SColin LeMahieu case Hexagon::S4_pstorerbnewtnew_abs: 8897cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewf_abs: 8907cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewt_abs: 8917cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewfnew_abs: 8927cd08927SColin LeMahieu case Hexagon::S4_pstorerhnewtnew_abs: 8937cd08927SColin LeMahieu case Hexagon::S4_pstorerinewf_abs: 8947cd08927SColin LeMahieu case Hexagon::S4_pstorerinewt_abs: 8957cd08927SColin LeMahieu case Hexagon::S4_pstorerinewfnew_abs: 8967cd08927SColin LeMahieu case Hexagon::S4_pstorerinewtnew_abs: { 8977cd08927SColin LeMahieu // op: Pv 8987cd08927SColin LeMahieu Value = insn & UINT64_C(3); 8997cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9007cd08927SColin LeMahieu // op: u6 9017cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 9027cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 9037cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9047cd08927SColin LeMahieu // op: Nt 9057cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(7); 9067cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9077cd08927SColin LeMahieu break; 9087cd08927SColin LeMahieu } 9097cd08927SColin LeMahieu 9107cd08927SColin LeMahieu case Hexagon::S4_pstorerbf_abs: 9117cd08927SColin LeMahieu case Hexagon::S4_pstorerbt_abs: 9127cd08927SColin LeMahieu case Hexagon::S4_pstorerbfnew_abs: 9137cd08927SColin LeMahieu case Hexagon::S4_pstorerbtnew_abs: 9147cd08927SColin LeMahieu case Hexagon::S4_pstorerhf_abs: 9157cd08927SColin LeMahieu case Hexagon::S4_pstorerht_abs: 9167cd08927SColin LeMahieu case Hexagon::S4_pstorerhfnew_abs: 9177cd08927SColin LeMahieu case Hexagon::S4_pstorerhtnew_abs: 9187cd08927SColin LeMahieu case Hexagon::S4_pstorerif_abs: 9197cd08927SColin LeMahieu case Hexagon::S4_pstorerit_abs: 9207cd08927SColin LeMahieu case Hexagon::S4_pstorerifnew_abs: 9217cd08927SColin LeMahieu case Hexagon::S4_pstoreritnew_abs: { 9227cd08927SColin LeMahieu // op: Pv 9237cd08927SColin LeMahieu Value = insn & UINT64_C(3); 9247cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9257cd08927SColin LeMahieu // op: u6 9267cd08927SColin LeMahieu Value = (insn >> 12) & UINT64_C(48); 9277cd08927SColin LeMahieu Value |= (insn >> 3) & UINT64_C(15); 9287cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9297cd08927SColin LeMahieu // op: Rt 9307cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 9317cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9327cd08927SColin LeMahieu break; 9337cd08927SColin LeMahieu } 9347cd08927SColin LeMahieu 9357cd08927SColin LeMahieu case Hexagon::L4_ploadrdf_abs: 9367cd08927SColin LeMahieu case Hexagon::L4_ploadrdt_abs: 9377cd08927SColin LeMahieu case Hexagon::L4_ploadrdfnew_abs: 9387cd08927SColin LeMahieu case Hexagon::L4_ploadrdtnew_abs: { 9397cd08927SColin LeMahieu // op: Rdd 9407cd08927SColin LeMahieu Value = insn & UINT64_C(31); 9417cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 9427cd08927SColin LeMahieu // op: Pt 9437cd08927SColin LeMahieu Value = ((insn >> 9) & UINT64_C(3)); 9447cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9457cd08927SColin LeMahieu // op: u6 9467cd08927SColin LeMahieu Value = ((insn >> 15) & UINT64_C(62)); 9477cd08927SColin LeMahieu Value |= ((insn >> 8) & UINT64_C(1)); 9487cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9497cd08927SColin LeMahieu break; 9507cd08927SColin LeMahieu } 9517cd08927SColin LeMahieu 9527cd08927SColin LeMahieu case Hexagon::L4_ploadrbf_abs: 9537cd08927SColin LeMahieu case Hexagon::L4_ploadrbt_abs: 9547cd08927SColin LeMahieu case Hexagon::L4_ploadrbfnew_abs: 9557cd08927SColin LeMahieu case Hexagon::L4_ploadrbtnew_abs: 9567cd08927SColin LeMahieu case Hexagon::L4_ploadrhf_abs: 9577cd08927SColin LeMahieu case Hexagon::L4_ploadrht_abs: 9587cd08927SColin LeMahieu case Hexagon::L4_ploadrhfnew_abs: 9597cd08927SColin LeMahieu case Hexagon::L4_ploadrhtnew_abs: 9607cd08927SColin LeMahieu case Hexagon::L4_ploadrubf_abs: 9617cd08927SColin LeMahieu case Hexagon::L4_ploadrubt_abs: 9627cd08927SColin LeMahieu case Hexagon::L4_ploadrubfnew_abs: 9637cd08927SColin LeMahieu case Hexagon::L4_ploadrubtnew_abs: 9647cd08927SColin LeMahieu case Hexagon::L4_ploadruhf_abs: 9657cd08927SColin LeMahieu case Hexagon::L4_ploadruht_abs: 9667cd08927SColin LeMahieu case Hexagon::L4_ploadruhfnew_abs: 9677cd08927SColin LeMahieu case Hexagon::L4_ploadruhtnew_abs: 9687cd08927SColin LeMahieu case Hexagon::L4_ploadrif_abs: 9697cd08927SColin LeMahieu case Hexagon::L4_ploadrit_abs: 9707cd08927SColin LeMahieu case Hexagon::L4_ploadrifnew_abs: 9717cd08927SColin LeMahieu case Hexagon::L4_ploadritnew_abs: 9727cd08927SColin LeMahieu // op: Rd 9737cd08927SColin LeMahieu Value = insn & UINT64_C(31); 9747cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9757cd08927SColin LeMahieu // op: Pt 9767cd08927SColin LeMahieu Value = (insn >> 9) & UINT64_C(3); 9777cd08927SColin LeMahieu DecodePredRegsRegisterClass(MI, Value, 0, 0); 9787cd08927SColin LeMahieu // op: u6 9797cd08927SColin LeMahieu Value = (insn >> 15) & UINT64_C(62); 9807cd08927SColin LeMahieu Value |= (insn >> 8) & UINT64_C(1); 9817cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value)); 9827cd08927SColin LeMahieu break; 9837cd08927SColin LeMahieu 9847cd08927SColin LeMahieu // op: g16_2 9857cd08927SColin LeMahieu case (Hexagon::L4_loadri_abs): 9867cd08927SColin LeMahieu ++shift; 9877cd08927SColin LeMahieu // op: g16_1 9887cd08927SColin LeMahieu case Hexagon::L4_loadrh_abs: 9897cd08927SColin LeMahieu case Hexagon::L4_loadruh_abs: 9907cd08927SColin LeMahieu ++shift; 9917cd08927SColin LeMahieu // op: g16_0 9927cd08927SColin LeMahieu case Hexagon::L4_loadrb_abs: 9937cd08927SColin LeMahieu case Hexagon::L4_loadrub_abs: { 9947cd08927SColin LeMahieu // op: Rd 9957cd08927SColin LeMahieu Value |= insn & UINT64_C(31); 9967cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 9977cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 9987cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 9997cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(511); 10007cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10017cd08927SColin LeMahieu break; 10027cd08927SColin LeMahieu } 10037cd08927SColin LeMahieu 10047cd08927SColin LeMahieu case Hexagon::L4_loadrd_abs: { 10057cd08927SColin LeMahieu Value = insn & UINT64_C(31); 10067cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 10077cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10087cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10097cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(511); 10107cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << 3)); 10117cd08927SColin LeMahieu break; 10127cd08927SColin LeMahieu } 10137cd08927SColin LeMahieu 10147cd08927SColin LeMahieu case Hexagon::S2_storerdabs: { 10157cd08927SColin LeMahieu // op: g16_3 10167cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10177cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10187cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10197cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10207cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << 3)); 10217cd08927SColin LeMahieu // op: Rtt 10227cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 10237cd08927SColin LeMahieu DecodeDoubleRegsRegisterClass(MI, Value, 0, 0); 10247cd08927SColin LeMahieu break; 10257cd08927SColin LeMahieu } 10267cd08927SColin LeMahieu 10277cd08927SColin LeMahieu // op: g16_2 10287cd08927SColin LeMahieu case Hexagon::S2_storerinewabs: 10297cd08927SColin LeMahieu ++shift; 10307cd08927SColin LeMahieu // op: g16_1 10317cd08927SColin LeMahieu case Hexagon::S2_storerhnewabs: 10327cd08927SColin LeMahieu ++shift; 10337cd08927SColin LeMahieu // op: g16_0 10347cd08927SColin LeMahieu case Hexagon::S2_storerbnewabs: { 10357cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10367cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10377cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10387cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10397cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10407cd08927SColin LeMahieu // op: Nt 10417cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(7); 10427cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 10437cd08927SColin LeMahieu break; 10447cd08927SColin LeMahieu } 10457cd08927SColin LeMahieu 10467cd08927SColin LeMahieu // op: g16_2 10477cd08927SColin LeMahieu case Hexagon::S2_storeriabs: 10487cd08927SColin LeMahieu ++shift; 10497cd08927SColin LeMahieu // op: g16_1 10507cd08927SColin LeMahieu case Hexagon::S2_storerhabs: 10517cd08927SColin LeMahieu case Hexagon::S2_storerfabs: 10527cd08927SColin LeMahieu ++shift; 10537cd08927SColin LeMahieu // op: g16_0 10547cd08927SColin LeMahieu case Hexagon::S2_storerbabs: { 10557cd08927SColin LeMahieu Value = (insn >> 11) & UINT64_C(49152); 10567cd08927SColin LeMahieu Value |= (insn >> 7) & UINT64_C(15872); 10577cd08927SColin LeMahieu Value |= (insn >> 5) & UINT64_C(256); 10587cd08927SColin LeMahieu Value |= insn & UINT64_C(255); 10597cd08927SColin LeMahieu MI.addOperand(MCOperand::createImm(Value << shift)); 10607cd08927SColin LeMahieu // op: Rt 10617cd08927SColin LeMahieu Value = (insn >> 8) & UINT64_C(31); 10627cd08927SColin LeMahieu DecodeIntRegsRegisterClass(MI, Value, 0, 0); 10637cd08927SColin LeMahieu break; 10647cd08927SColin LeMahieu } 10657cd08927SColin LeMahieu } 10667cd08927SColin LeMahieu return MCDisassembler::Success; 10677cd08927SColin LeMahieu } 10687cd08927SColin LeMahieu return MCDisassembler::Fail; 10697cd08927SColin LeMahieu } 10707cd08927SColin LeMahieu 10717cd08927SColin LeMahieu static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn, 10727cd08927SColin LeMahieu void const *Decoder) { 10737cd08927SColin LeMahieu 10747cd08927SColin LeMahieu // Instruction Class for a constant a extender: bits 31:28 = 0x0000 10757cd08927SColin LeMahieu if ((~insn & 0xf0000000) == 0xf0000000) { 10767cd08927SColin LeMahieu unsigned Value; 10777cd08927SColin LeMahieu // 27:16 High 12 bits of 26-bit extender. 10787cd08927SColin LeMahieu Value = (insn & 0x0fff0000) << 4; 10797cd08927SColin LeMahieu // 13:0 Low 14 bits of 26-bit extender. 10807cd08927SColin LeMahieu Value |= ((insn & 0x3fff) << 6); 10817cd08927SColin LeMahieu MI.setOpcode(Hexagon::A4_ext); 10827cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(MI, Value, contextFromDecoder(Decoder)); 10837cd08927SColin LeMahieu return MCDisassembler::Success; 10847cd08927SColin LeMahieu } 10857cd08927SColin LeMahieu return MCDisassembler::Fail; 10867cd08927SColin LeMahieu } 10877cd08927SColin LeMahieu 1088be8c453dSColin LeMahieu // These values are from HexagonGenMCCodeEmitter.inc and HexagonIsetDx.td 1089be8c453dSColin LeMahieu enum subInstBinaryValues { 1090be8c453dSColin LeMahieu V4_SA1_addi_BITS = 0x0000, 1091be8c453dSColin LeMahieu V4_SA1_addi_MASK = 0x1800, 1092be8c453dSColin LeMahieu V4_SA1_addrx_BITS = 0x1800, 1093be8c453dSColin LeMahieu V4_SA1_addrx_MASK = 0x1f00, 1094be8c453dSColin LeMahieu V4_SA1_addsp_BITS = 0x0c00, 1095be8c453dSColin LeMahieu V4_SA1_addsp_MASK = 0x1c00, 1096be8c453dSColin LeMahieu V4_SA1_and1_BITS = 0x1200, 1097be8c453dSColin LeMahieu V4_SA1_and1_MASK = 0x1f00, 1098be8c453dSColin LeMahieu V4_SA1_clrf_BITS = 0x1a70, 1099be8c453dSColin LeMahieu V4_SA1_clrf_MASK = 0x1e70, 1100be8c453dSColin LeMahieu V4_SA1_clrfnew_BITS = 0x1a50, 1101be8c453dSColin LeMahieu V4_SA1_clrfnew_MASK = 0x1e70, 1102be8c453dSColin LeMahieu V4_SA1_clrt_BITS = 0x1a60, 1103be8c453dSColin LeMahieu V4_SA1_clrt_MASK = 0x1e70, 1104be8c453dSColin LeMahieu V4_SA1_clrtnew_BITS = 0x1a40, 1105be8c453dSColin LeMahieu V4_SA1_clrtnew_MASK = 0x1e70, 1106be8c453dSColin LeMahieu V4_SA1_cmpeqi_BITS = 0x1900, 1107be8c453dSColin LeMahieu V4_SA1_cmpeqi_MASK = 0x1f00, 1108be8c453dSColin LeMahieu V4_SA1_combine0i_BITS = 0x1c00, 1109be8c453dSColin LeMahieu V4_SA1_combine0i_MASK = 0x1d18, 1110be8c453dSColin LeMahieu V4_SA1_combine1i_BITS = 0x1c08, 1111be8c453dSColin LeMahieu V4_SA1_combine1i_MASK = 0x1d18, 1112be8c453dSColin LeMahieu V4_SA1_combine2i_BITS = 0x1c10, 1113be8c453dSColin LeMahieu V4_SA1_combine2i_MASK = 0x1d18, 1114be8c453dSColin LeMahieu V4_SA1_combine3i_BITS = 0x1c18, 1115be8c453dSColin LeMahieu V4_SA1_combine3i_MASK = 0x1d18, 1116be8c453dSColin LeMahieu V4_SA1_combinerz_BITS = 0x1d08, 1117be8c453dSColin LeMahieu V4_SA1_combinerz_MASK = 0x1d08, 1118be8c453dSColin LeMahieu V4_SA1_combinezr_BITS = 0x1d00, 1119be8c453dSColin LeMahieu V4_SA1_combinezr_MASK = 0x1d08, 1120be8c453dSColin LeMahieu V4_SA1_dec_BITS = 0x1300, 1121be8c453dSColin LeMahieu V4_SA1_dec_MASK = 0x1f00, 1122be8c453dSColin LeMahieu V4_SA1_inc_BITS = 0x1100, 1123be8c453dSColin LeMahieu V4_SA1_inc_MASK = 0x1f00, 1124be8c453dSColin LeMahieu V4_SA1_seti_BITS = 0x0800, 1125be8c453dSColin LeMahieu V4_SA1_seti_MASK = 0x1c00, 1126be8c453dSColin LeMahieu V4_SA1_setin1_BITS = 0x1a00, 1127be8c453dSColin LeMahieu V4_SA1_setin1_MASK = 0x1e40, 1128be8c453dSColin LeMahieu V4_SA1_sxtb_BITS = 0x1500, 1129be8c453dSColin LeMahieu V4_SA1_sxtb_MASK = 0x1f00, 1130be8c453dSColin LeMahieu V4_SA1_sxth_BITS = 0x1400, 1131be8c453dSColin LeMahieu V4_SA1_sxth_MASK = 0x1f00, 1132be8c453dSColin LeMahieu V4_SA1_tfr_BITS = 0x1000, 1133be8c453dSColin LeMahieu V4_SA1_tfr_MASK = 0x1f00, 1134be8c453dSColin LeMahieu V4_SA1_zxtb_BITS = 0x1700, 1135be8c453dSColin LeMahieu V4_SA1_zxtb_MASK = 0x1f00, 1136be8c453dSColin LeMahieu V4_SA1_zxth_BITS = 0x1600, 1137be8c453dSColin LeMahieu V4_SA1_zxth_MASK = 0x1f00, 1138be8c453dSColin LeMahieu V4_SL1_loadri_io_BITS = 0x0000, 1139be8c453dSColin LeMahieu V4_SL1_loadri_io_MASK = 0x1000, 1140be8c453dSColin LeMahieu V4_SL1_loadrub_io_BITS = 0x1000, 1141be8c453dSColin LeMahieu V4_SL1_loadrub_io_MASK = 0x1000, 1142be8c453dSColin LeMahieu V4_SL2_deallocframe_BITS = 0x1f00, 1143be8c453dSColin LeMahieu V4_SL2_deallocframe_MASK = 0x1fc0, 1144be8c453dSColin LeMahieu V4_SL2_jumpr31_BITS = 0x1fc0, 1145be8c453dSColin LeMahieu V4_SL2_jumpr31_MASK = 0x1fc4, 1146be8c453dSColin LeMahieu V4_SL2_jumpr31_f_BITS = 0x1fc5, 1147be8c453dSColin LeMahieu V4_SL2_jumpr31_f_MASK = 0x1fc7, 1148be8c453dSColin LeMahieu V4_SL2_jumpr31_fnew_BITS = 0x1fc7, 1149be8c453dSColin LeMahieu V4_SL2_jumpr31_fnew_MASK = 0x1fc7, 1150be8c453dSColin LeMahieu V4_SL2_jumpr31_t_BITS = 0x1fc4, 1151be8c453dSColin LeMahieu V4_SL2_jumpr31_t_MASK = 0x1fc7, 1152be8c453dSColin LeMahieu V4_SL2_jumpr31_tnew_BITS = 0x1fc6, 1153be8c453dSColin LeMahieu V4_SL2_jumpr31_tnew_MASK = 0x1fc7, 1154be8c453dSColin LeMahieu V4_SL2_loadrb_io_BITS = 0x1000, 1155be8c453dSColin LeMahieu V4_SL2_loadrb_io_MASK = 0x1800, 1156be8c453dSColin LeMahieu V4_SL2_loadrd_sp_BITS = 0x1e00, 1157be8c453dSColin LeMahieu V4_SL2_loadrd_sp_MASK = 0x1f00, 1158be8c453dSColin LeMahieu V4_SL2_loadrh_io_BITS = 0x0000, 1159be8c453dSColin LeMahieu V4_SL2_loadrh_io_MASK = 0x1800, 1160be8c453dSColin LeMahieu V4_SL2_loadri_sp_BITS = 0x1c00, 1161be8c453dSColin LeMahieu V4_SL2_loadri_sp_MASK = 0x1e00, 1162be8c453dSColin LeMahieu V4_SL2_loadruh_io_BITS = 0x0800, 1163be8c453dSColin LeMahieu V4_SL2_loadruh_io_MASK = 0x1800, 1164be8c453dSColin LeMahieu V4_SL2_return_BITS = 0x1f40, 1165be8c453dSColin LeMahieu V4_SL2_return_MASK = 0x1fc4, 1166be8c453dSColin LeMahieu V4_SL2_return_f_BITS = 0x1f45, 1167be8c453dSColin LeMahieu V4_SL2_return_f_MASK = 0x1fc7, 1168be8c453dSColin LeMahieu V4_SL2_return_fnew_BITS = 0x1f47, 1169be8c453dSColin LeMahieu V4_SL2_return_fnew_MASK = 0x1fc7, 1170be8c453dSColin LeMahieu V4_SL2_return_t_BITS = 0x1f44, 1171be8c453dSColin LeMahieu V4_SL2_return_t_MASK = 0x1fc7, 1172be8c453dSColin LeMahieu V4_SL2_return_tnew_BITS = 0x1f46, 1173be8c453dSColin LeMahieu V4_SL2_return_tnew_MASK = 0x1fc7, 1174be8c453dSColin LeMahieu V4_SS1_storeb_io_BITS = 0x1000, 1175be8c453dSColin LeMahieu V4_SS1_storeb_io_MASK = 0x1000, 1176be8c453dSColin LeMahieu V4_SS1_storew_io_BITS = 0x0000, 1177be8c453dSColin LeMahieu V4_SS1_storew_io_MASK = 0x1000, 1178be8c453dSColin LeMahieu V4_SS2_allocframe_BITS = 0x1c00, 1179be8c453dSColin LeMahieu V4_SS2_allocframe_MASK = 0x1e00, 1180be8c453dSColin LeMahieu V4_SS2_storebi0_BITS = 0x1200, 1181be8c453dSColin LeMahieu V4_SS2_storebi0_MASK = 0x1f00, 1182be8c453dSColin LeMahieu V4_SS2_storebi1_BITS = 0x1300, 1183be8c453dSColin LeMahieu V4_SS2_storebi1_MASK = 0x1f00, 1184be8c453dSColin LeMahieu V4_SS2_stored_sp_BITS = 0x0a00, 1185be8c453dSColin LeMahieu V4_SS2_stored_sp_MASK = 0x1e00, 1186be8c453dSColin LeMahieu V4_SS2_storeh_io_BITS = 0x0000, 1187be8c453dSColin LeMahieu V4_SS2_storeh_io_MASK = 0x1800, 1188be8c453dSColin LeMahieu V4_SS2_storew_sp_BITS = 0x0800, 1189be8c453dSColin LeMahieu V4_SS2_storew_sp_MASK = 0x1e00, 1190be8c453dSColin LeMahieu V4_SS2_storewi0_BITS = 0x1000, 1191be8c453dSColin LeMahieu V4_SS2_storewi0_MASK = 0x1f00, 1192be8c453dSColin LeMahieu V4_SS2_storewi1_BITS = 0x1100, 1193be8c453dSColin LeMahieu V4_SS2_storewi1_MASK = 0x1f00 1194be8c453dSColin LeMahieu }; 1195be8c453dSColin LeMahieu 1196be8c453dSColin LeMahieu static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op, 1197be8c453dSColin LeMahieu raw_ostream &os) { 1198be8c453dSColin LeMahieu switch (IClass) { 1199be8c453dSColin LeMahieu case HexagonII::HSIG_L1: 1200be8c453dSColin LeMahieu if ((inst & V4_SL1_loadri_io_MASK) == V4_SL1_loadri_io_BITS) 1201be8c453dSColin LeMahieu op = Hexagon::V4_SL1_loadri_io; 1202be8c453dSColin LeMahieu else if ((inst & V4_SL1_loadrub_io_MASK) == V4_SL1_loadrub_io_BITS) 1203be8c453dSColin LeMahieu op = Hexagon::V4_SL1_loadrub_io; 1204be8c453dSColin LeMahieu else { 1205be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1206be8c453dSColin LeMahieu return MCDisassembler::Fail; 1207be8c453dSColin LeMahieu } 1208be8c453dSColin LeMahieu break; 1209be8c453dSColin LeMahieu case HexagonII::HSIG_L2: 1210be8c453dSColin LeMahieu if ((inst & V4_SL2_deallocframe_MASK) == V4_SL2_deallocframe_BITS) 1211be8c453dSColin LeMahieu op = Hexagon::V4_SL2_deallocframe; 1212be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_MASK) == V4_SL2_jumpr31_BITS) 1213be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31; 1214be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_f_MASK) == V4_SL2_jumpr31_f_BITS) 1215be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_f; 1216be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_fnew_MASK) == V4_SL2_jumpr31_fnew_BITS) 1217be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_fnew; 1218be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_t_MASK) == V4_SL2_jumpr31_t_BITS) 1219be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_t; 1220be8c453dSColin LeMahieu else if ((inst & V4_SL2_jumpr31_tnew_MASK) == V4_SL2_jumpr31_tnew_BITS) 1221be8c453dSColin LeMahieu op = Hexagon::V4_SL2_jumpr31_tnew; 1222be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadrb_io_MASK) == V4_SL2_loadrb_io_BITS) 1223be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadrb_io; 1224be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadrd_sp_MASK) == V4_SL2_loadrd_sp_BITS) 1225be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadrd_sp; 1226be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadrh_io_MASK) == V4_SL2_loadrh_io_BITS) 1227be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadrh_io; 1228be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadri_sp_MASK) == V4_SL2_loadri_sp_BITS) 1229be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadri_sp; 1230be8c453dSColin LeMahieu else if ((inst & V4_SL2_loadruh_io_MASK) == V4_SL2_loadruh_io_BITS) 1231be8c453dSColin LeMahieu op = Hexagon::V4_SL2_loadruh_io; 1232be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_MASK) == V4_SL2_return_BITS) 1233be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return; 1234be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_f_MASK) == V4_SL2_return_f_BITS) 1235be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_f; 1236be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_fnew_MASK) == V4_SL2_return_fnew_BITS) 1237be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_fnew; 1238be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_t_MASK) == V4_SL2_return_t_BITS) 1239be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_t; 1240be8c453dSColin LeMahieu else if ((inst & V4_SL2_return_tnew_MASK) == V4_SL2_return_tnew_BITS) 1241be8c453dSColin LeMahieu op = Hexagon::V4_SL2_return_tnew; 1242be8c453dSColin LeMahieu else { 1243be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1244be8c453dSColin LeMahieu return MCDisassembler::Fail; 1245be8c453dSColin LeMahieu } 1246be8c453dSColin LeMahieu break; 1247be8c453dSColin LeMahieu case HexagonII::HSIG_A: 1248be8c453dSColin LeMahieu if ((inst & V4_SA1_addi_MASK) == V4_SA1_addi_BITS) 1249be8c453dSColin LeMahieu op = Hexagon::V4_SA1_addi; 1250be8c453dSColin LeMahieu else if ((inst & V4_SA1_addrx_MASK) == V4_SA1_addrx_BITS) 1251be8c453dSColin LeMahieu op = Hexagon::V4_SA1_addrx; 1252be8c453dSColin LeMahieu else if ((inst & V4_SA1_addsp_MASK) == V4_SA1_addsp_BITS) 1253be8c453dSColin LeMahieu op = Hexagon::V4_SA1_addsp; 1254be8c453dSColin LeMahieu else if ((inst & V4_SA1_and1_MASK) == V4_SA1_and1_BITS) 1255be8c453dSColin LeMahieu op = Hexagon::V4_SA1_and1; 1256be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrf_MASK) == V4_SA1_clrf_BITS) 1257be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrf; 1258be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrfnew_MASK) == V4_SA1_clrfnew_BITS) 1259be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrfnew; 1260be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrt_MASK) == V4_SA1_clrt_BITS) 1261be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrt; 1262be8c453dSColin LeMahieu else if ((inst & V4_SA1_clrtnew_MASK) == V4_SA1_clrtnew_BITS) 1263be8c453dSColin LeMahieu op = Hexagon::V4_SA1_clrtnew; 1264be8c453dSColin LeMahieu else if ((inst & V4_SA1_cmpeqi_MASK) == V4_SA1_cmpeqi_BITS) 1265be8c453dSColin LeMahieu op = Hexagon::V4_SA1_cmpeqi; 1266be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine0i_MASK) == V4_SA1_combine0i_BITS) 1267be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine0i; 1268be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine1i_MASK) == V4_SA1_combine1i_BITS) 1269be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine1i; 1270be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine2i_MASK) == V4_SA1_combine2i_BITS) 1271be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine2i; 1272be8c453dSColin LeMahieu else if ((inst & V4_SA1_combine3i_MASK) == V4_SA1_combine3i_BITS) 1273be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combine3i; 1274be8c453dSColin LeMahieu else if ((inst & V4_SA1_combinerz_MASK) == V4_SA1_combinerz_BITS) 1275be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combinerz; 1276be8c453dSColin LeMahieu else if ((inst & V4_SA1_combinezr_MASK) == V4_SA1_combinezr_BITS) 1277be8c453dSColin LeMahieu op = Hexagon::V4_SA1_combinezr; 1278be8c453dSColin LeMahieu else if ((inst & V4_SA1_dec_MASK) == V4_SA1_dec_BITS) 1279be8c453dSColin LeMahieu op = Hexagon::V4_SA1_dec; 1280be8c453dSColin LeMahieu else if ((inst & V4_SA1_inc_MASK) == V4_SA1_inc_BITS) 1281be8c453dSColin LeMahieu op = Hexagon::V4_SA1_inc; 1282be8c453dSColin LeMahieu else if ((inst & V4_SA1_seti_MASK) == V4_SA1_seti_BITS) 1283be8c453dSColin LeMahieu op = Hexagon::V4_SA1_seti; 1284be8c453dSColin LeMahieu else if ((inst & V4_SA1_setin1_MASK) == V4_SA1_setin1_BITS) 1285be8c453dSColin LeMahieu op = Hexagon::V4_SA1_setin1; 1286be8c453dSColin LeMahieu else if ((inst & V4_SA1_sxtb_MASK) == V4_SA1_sxtb_BITS) 1287be8c453dSColin LeMahieu op = Hexagon::V4_SA1_sxtb; 1288be8c453dSColin LeMahieu else if ((inst & V4_SA1_sxth_MASK) == V4_SA1_sxth_BITS) 1289be8c453dSColin LeMahieu op = Hexagon::V4_SA1_sxth; 1290be8c453dSColin LeMahieu else if ((inst & V4_SA1_tfr_MASK) == V4_SA1_tfr_BITS) 1291be8c453dSColin LeMahieu op = Hexagon::V4_SA1_tfr; 1292be8c453dSColin LeMahieu else if ((inst & V4_SA1_zxtb_MASK) == V4_SA1_zxtb_BITS) 1293be8c453dSColin LeMahieu op = Hexagon::V4_SA1_zxtb; 1294be8c453dSColin LeMahieu else if ((inst & V4_SA1_zxth_MASK) == V4_SA1_zxth_BITS) 1295be8c453dSColin LeMahieu op = Hexagon::V4_SA1_zxth; 1296be8c453dSColin LeMahieu else { 1297be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1298be8c453dSColin LeMahieu return MCDisassembler::Fail; 1299be8c453dSColin LeMahieu } 1300be8c453dSColin LeMahieu break; 1301be8c453dSColin LeMahieu case HexagonII::HSIG_S1: 1302be8c453dSColin LeMahieu if ((inst & V4_SS1_storeb_io_MASK) == V4_SS1_storeb_io_BITS) 1303be8c453dSColin LeMahieu op = Hexagon::V4_SS1_storeb_io; 1304be8c453dSColin LeMahieu else if ((inst & V4_SS1_storew_io_MASK) == V4_SS1_storew_io_BITS) 1305be8c453dSColin LeMahieu op = Hexagon::V4_SS1_storew_io; 1306be8c453dSColin LeMahieu else { 1307be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1308be8c453dSColin LeMahieu return MCDisassembler::Fail; 1309be8c453dSColin LeMahieu } 1310be8c453dSColin LeMahieu break; 1311be8c453dSColin LeMahieu case HexagonII::HSIG_S2: 1312be8c453dSColin LeMahieu if ((inst & V4_SS2_allocframe_MASK) == V4_SS2_allocframe_BITS) 1313be8c453dSColin LeMahieu op = Hexagon::V4_SS2_allocframe; 1314be8c453dSColin LeMahieu else if ((inst & V4_SS2_storebi0_MASK) == V4_SS2_storebi0_BITS) 1315be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storebi0; 1316be8c453dSColin LeMahieu else if ((inst & V4_SS2_storebi1_MASK) == V4_SS2_storebi1_BITS) 1317be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storebi1; 1318be8c453dSColin LeMahieu else if ((inst & V4_SS2_stored_sp_MASK) == V4_SS2_stored_sp_BITS) 1319be8c453dSColin LeMahieu op = Hexagon::V4_SS2_stored_sp; 1320be8c453dSColin LeMahieu else if ((inst & V4_SS2_storeh_io_MASK) == V4_SS2_storeh_io_BITS) 1321be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storeh_io; 1322be8c453dSColin LeMahieu else if ((inst & V4_SS2_storew_sp_MASK) == V4_SS2_storew_sp_BITS) 1323be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storew_sp; 1324be8c453dSColin LeMahieu else if ((inst & V4_SS2_storewi0_MASK) == V4_SS2_storewi0_BITS) 1325be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storewi0; 1326be8c453dSColin LeMahieu else if ((inst & V4_SS2_storewi1_MASK) == V4_SS2_storewi1_BITS) 1327be8c453dSColin LeMahieu op = Hexagon::V4_SS2_storewi1; 1328be8c453dSColin LeMahieu else { 1329be8c453dSColin LeMahieu os << "<unknown subinstruction>"; 1330be8c453dSColin LeMahieu return MCDisassembler::Fail; 1331be8c453dSColin LeMahieu } 1332be8c453dSColin LeMahieu break; 1333be8c453dSColin LeMahieu default: 1334be8c453dSColin LeMahieu os << "<unknown>"; 1335be8c453dSColin LeMahieu return MCDisassembler::Fail; 1336be8c453dSColin LeMahieu } 1337be8c453dSColin LeMahieu return MCDisassembler::Success; 1338be8c453dSColin LeMahieu } 1339be8c453dSColin LeMahieu 1340be8c453dSColin LeMahieu static unsigned getRegFromSubinstEncoding(unsigned encoded_reg) { 1341be8c453dSColin LeMahieu if (encoded_reg < 8) 1342be8c453dSColin LeMahieu return Hexagon::R0 + encoded_reg; 1343be8c453dSColin LeMahieu else if (encoded_reg < 16) 1344be8c453dSColin LeMahieu return Hexagon::R0 + encoded_reg + 8; 13457cd08927SColin LeMahieu 13467cd08927SColin LeMahieu // patently false value 1347be8c453dSColin LeMahieu return Hexagon::NoRegister; 1348be8c453dSColin LeMahieu } 1349be8c453dSColin LeMahieu 1350be8c453dSColin LeMahieu static unsigned getDRegFromSubinstEncoding(unsigned encoded_dreg) { 1351be8c453dSColin LeMahieu if (encoded_dreg < 4) 1352be8c453dSColin LeMahieu return Hexagon::D0 + encoded_dreg; 1353be8c453dSColin LeMahieu else if (encoded_dreg < 8) 1354be8c453dSColin LeMahieu return Hexagon::D0 + encoded_dreg + 4; 13557cd08927SColin LeMahieu 13567cd08927SColin LeMahieu // patently false value 1357be8c453dSColin LeMahieu return Hexagon::NoRegister; 1358be8c453dSColin LeMahieu } 1359be8c453dSColin LeMahieu 13607cd08927SColin LeMahieu void HexagonDisassembler::addSubinstOperands(MCInst *MI, unsigned opcode, 13617cd08927SColin LeMahieu unsigned inst) const { 1362be8c453dSColin LeMahieu int64_t operand; 1363be8c453dSColin LeMahieu MCOperand Op; 1364be8c453dSColin LeMahieu switch (opcode) { 1365be8c453dSColin LeMahieu case Hexagon::V4_SL2_deallocframe: 1366be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31: 1367be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_f: 1368be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_fnew: 1369be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_t: 1370be8c453dSColin LeMahieu case Hexagon::V4_SL2_jumpr31_tnew: 1371be8c453dSColin LeMahieu case Hexagon::V4_SL2_return: 1372be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_f: 1373be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_fnew: 1374be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_t: 1375be8c453dSColin LeMahieu case Hexagon::V4_SL2_return_tnew: 1376be8c453dSColin LeMahieu // no operands for these instructions 1377be8c453dSColin LeMahieu break; 1378be8c453dSColin LeMahieu case Hexagon::V4_SS2_allocframe: 1379be8c453dSColin LeMahieu // u 8-4{5_3} 1380be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 3; 13817cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1382be8c453dSColin LeMahieu break; 1383be8c453dSColin LeMahieu case Hexagon::V4_SL1_loadri_io: 1384be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 11-8{4_2} 1385be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1386be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1387be8c453dSColin LeMahieu MI->addOperand(Op); 1388be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1389be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1390be8c453dSColin LeMahieu MI->addOperand(Op); 1391be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 6; 13927cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1393be8c453dSColin LeMahieu break; 1394be8c453dSColin LeMahieu case Hexagon::V4_SL1_loadrub_io: 1395be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 11-8 1396be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1397be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1398be8c453dSColin LeMahieu MI->addOperand(Op); 1399be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1400be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1401be8c453dSColin LeMahieu MI->addOperand(Op); 1402be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 8; 14037cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1404be8c453dSColin LeMahieu break; 1405be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadrb_io: 1406be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 10-8 1407be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1408be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1409be8c453dSColin LeMahieu MI->addOperand(Op); 1410be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1411be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1412be8c453dSColin LeMahieu MI->addOperand(Op); 1413be8c453dSColin LeMahieu operand = (inst & 0x700) >> 8; 14147cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1415be8c453dSColin LeMahieu break; 1416be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadrh_io: 1417be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadruh_io: 1418be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4, u 10-8{3_1} 1419be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1420be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1421be8c453dSColin LeMahieu MI->addOperand(Op); 1422be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1423be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1424be8c453dSColin LeMahieu MI->addOperand(Op); 1425be8c453dSColin LeMahieu operand = ((inst & 0x700) >> 8) << 1; 14267cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1427be8c453dSColin LeMahieu break; 1428be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadrd_sp: 1429be8c453dSColin LeMahieu // Rdd 2-0, u 7-3{5_3} 1430be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1431be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1432be8c453dSColin LeMahieu MI->addOperand(Op); 1433be8c453dSColin LeMahieu operand = ((inst & 0x0f8) >> 3) << 3; 14347cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1435be8c453dSColin LeMahieu break; 1436be8c453dSColin LeMahieu case Hexagon::V4_SL2_loadri_sp: 1437be8c453dSColin LeMahieu // Rd 3-0, u 8-4{5_2} 1438be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1439be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1440be8c453dSColin LeMahieu MI->addOperand(Op); 1441be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 2; 14427cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1443be8c453dSColin LeMahieu break; 1444be8c453dSColin LeMahieu case Hexagon::V4_SA1_addi: 1445be8c453dSColin LeMahieu // Rx 3-0 (x2), s7 10-4 1446be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1447be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1448be8c453dSColin LeMahieu MI->addOperand(Op); 1449be8c453dSColin LeMahieu MI->addOperand(Op); 1450be8c453dSColin LeMahieu operand = SignExtend64<7>((inst & 0x7f0) >> 4); 14517cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1452be8c453dSColin LeMahieu break; 1453be8c453dSColin LeMahieu case Hexagon::V4_SA1_addrx: 1454be8c453dSColin LeMahieu // Rx 3-0 (x2), Rs 7-4 1455be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1456be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1457be8c453dSColin LeMahieu MI->addOperand(Op); 1458be8c453dSColin LeMahieu MI->addOperand(Op); 1459be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1460be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1461be8c453dSColin LeMahieu MI->addOperand(Op); 1462be8c453dSColin LeMahieu case Hexagon::V4_SA1_and1: 1463be8c453dSColin LeMahieu case Hexagon::V4_SA1_dec: 1464be8c453dSColin LeMahieu case Hexagon::V4_SA1_inc: 1465be8c453dSColin LeMahieu case Hexagon::V4_SA1_sxtb: 1466be8c453dSColin LeMahieu case Hexagon::V4_SA1_sxth: 1467be8c453dSColin LeMahieu case Hexagon::V4_SA1_tfr: 1468be8c453dSColin LeMahieu case Hexagon::V4_SA1_zxtb: 1469be8c453dSColin LeMahieu case Hexagon::V4_SA1_zxth: 1470be8c453dSColin LeMahieu // Rd 3-0, Rs 7-4 1471be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1472be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1473be8c453dSColin LeMahieu MI->addOperand(Op); 1474be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1475be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1476be8c453dSColin LeMahieu MI->addOperand(Op); 1477be8c453dSColin LeMahieu break; 1478be8c453dSColin LeMahieu case Hexagon::V4_SA1_addsp: 1479be8c453dSColin LeMahieu // Rd 3-0, u 9-4{6_2} 1480be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1481be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1482be8c453dSColin LeMahieu MI->addOperand(Op); 1483be8c453dSColin LeMahieu operand = ((inst & 0x3f0) >> 4) << 2; 14847cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1485be8c453dSColin LeMahieu break; 1486be8c453dSColin LeMahieu case Hexagon::V4_SA1_seti: 1487be8c453dSColin LeMahieu // Rd 3-0, u 9-4 1488be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1489be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1490be8c453dSColin LeMahieu MI->addOperand(Op); 1491be8c453dSColin LeMahieu operand = (inst & 0x3f0) >> 4; 14927cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1493be8c453dSColin LeMahieu break; 1494be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrf: 1495be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrfnew: 1496be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrt: 1497be8c453dSColin LeMahieu case Hexagon::V4_SA1_clrtnew: 1498be8c453dSColin LeMahieu case Hexagon::V4_SA1_setin1: 1499be8c453dSColin LeMahieu // Rd 3-0 1500be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1501be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1502be8c453dSColin LeMahieu MI->addOperand(Op); 1503be8c453dSColin LeMahieu break; 1504be8c453dSColin LeMahieu case Hexagon::V4_SA1_cmpeqi: 1505be8c453dSColin LeMahieu // Rs 7-4, u 1-0 1506be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1507be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1508be8c453dSColin LeMahieu MI->addOperand(Op); 1509be8c453dSColin LeMahieu operand = inst & 0x3; 15107cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1511be8c453dSColin LeMahieu break; 1512be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine0i: 1513be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine1i: 1514be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine2i: 1515be8c453dSColin LeMahieu case Hexagon::V4_SA1_combine3i: 1516be8c453dSColin LeMahieu // Rdd 2-0, u 6-5 1517be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1518be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1519be8c453dSColin LeMahieu MI->addOperand(Op); 1520be8c453dSColin LeMahieu operand = (inst & 0x060) >> 5; 15217cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1522be8c453dSColin LeMahieu break; 1523be8c453dSColin LeMahieu case Hexagon::V4_SA1_combinerz: 1524be8c453dSColin LeMahieu case Hexagon::V4_SA1_combinezr: 1525be8c453dSColin LeMahieu // Rdd 2-0, Rs 7-4 1526be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1527be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1528be8c453dSColin LeMahieu MI->addOperand(Op); 1529be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1530be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1531be8c453dSColin LeMahieu MI->addOperand(Op); 1532be8c453dSColin LeMahieu break; 1533be8c453dSColin LeMahieu case Hexagon::V4_SS1_storeb_io: 1534be8c453dSColin LeMahieu // Rs 7-4, u 11-8, Rt 3-0 1535be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1536be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1537be8c453dSColin LeMahieu MI->addOperand(Op); 1538be8c453dSColin LeMahieu operand = (inst & 0xf00) >> 8; 15397cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1540be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1541be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1542be8c453dSColin LeMahieu MI->addOperand(Op); 1543be8c453dSColin LeMahieu break; 1544be8c453dSColin LeMahieu case Hexagon::V4_SS1_storew_io: 1545be8c453dSColin LeMahieu // Rs 7-4, u 11-8{4_2}, Rt 3-0 1546be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1547be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1548be8c453dSColin LeMahieu MI->addOperand(Op); 1549be8c453dSColin LeMahieu operand = ((inst & 0xf00) >> 8) << 2; 15507cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1551be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1552be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1553be8c453dSColin LeMahieu MI->addOperand(Op); 1554be8c453dSColin LeMahieu break; 1555be8c453dSColin LeMahieu case Hexagon::V4_SS2_storebi0: 1556be8c453dSColin LeMahieu case Hexagon::V4_SS2_storebi1: 1557be8c453dSColin LeMahieu // Rs 7-4, u 3-0 1558be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1559be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1560be8c453dSColin LeMahieu MI->addOperand(Op); 1561be8c453dSColin LeMahieu operand = inst & 0xf; 15627cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1563be8c453dSColin LeMahieu break; 1564be8c453dSColin LeMahieu case Hexagon::V4_SS2_storewi0: 1565be8c453dSColin LeMahieu case Hexagon::V4_SS2_storewi1: 1566be8c453dSColin LeMahieu // Rs 7-4, u 3-0{4_2} 1567be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1568be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1569be8c453dSColin LeMahieu MI->addOperand(Op); 1570be8c453dSColin LeMahieu operand = (inst & 0xf) << 2; 15717cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1572be8c453dSColin LeMahieu break; 1573be8c453dSColin LeMahieu case Hexagon::V4_SS2_stored_sp: 1574be8c453dSColin LeMahieu // s 8-3{6_3}, Rtt 2-0 1575be8c453dSColin LeMahieu operand = SignExtend64<9>(((inst & 0x1f8) >> 3) << 3); 15767cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1577be8c453dSColin LeMahieu operand = getDRegFromSubinstEncoding(inst & 0x7); 1578be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1579be8c453dSColin LeMahieu MI->addOperand(Op); 1580160f73e3SColin LeMahieu break; 1581be8c453dSColin LeMahieu case Hexagon::V4_SS2_storeh_io: 1582be8c453dSColin LeMahieu // Rs 7-4, u 10-8{3_1}, Rt 3-0 1583be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4); 1584be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1585be8c453dSColin LeMahieu MI->addOperand(Op); 1586be8c453dSColin LeMahieu operand = ((inst & 0x700) >> 8) << 1; 15877cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1588be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1589be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1590be8c453dSColin LeMahieu MI->addOperand(Op); 1591be8c453dSColin LeMahieu break; 1592be8c453dSColin LeMahieu case Hexagon::V4_SS2_storew_sp: 1593be8c453dSColin LeMahieu // u 8-4{5_2}, Rd 3-0 1594be8c453dSColin LeMahieu operand = ((inst & 0x1f0) >> 4) << 2; 15957cd08927SColin LeMahieu HexagonMCInstrInfo::addConstant(*MI, operand, getContext()); 1596be8c453dSColin LeMahieu operand = getRegFromSubinstEncoding(inst & 0xf); 1597be8c453dSColin LeMahieu Op = MCOperand::createReg(operand); 1598be8c453dSColin LeMahieu MI->addOperand(Op); 1599be8c453dSColin LeMahieu break; 1600be8c453dSColin LeMahieu default: 1601be8c453dSColin LeMahieu // don't crash with an invalid subinstruction 1602be8c453dSColin LeMahieu // llvm_unreachable("Invalid subinstruction in duplex instruction"); 1603be8c453dSColin LeMahieu break; 1604be8c453dSColin LeMahieu } 1605be8c453dSColin LeMahieu } 1606