NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 1 | //===-- HexagonDisassembler.cpp - Disassembler for Hexagon ISA ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 10 | #define DEBUG_TYPE "hexagon-disassembler" |
| 11 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 12 | #include "Hexagon.h" |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 13 | #include "MCTargetDesc/HexagonBaseInfo.h" |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 14 | #include "MCTargetDesc/HexagonMCChecker.h" |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/HexagonMCInstrInfo.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame^] | 16 | #include "MCTargetDesc/HexagonMCTargetDesc.h" |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/ArrayRef.h" |
| 18 | #include "llvm/ADT/STLExtras.h" |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCContext.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame^] | 20 | #include "llvm/MC/MCDisassembler/MCDisassembler.h" |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCExpr.h" |
| 22 | #include "llvm/MC/MCFixedLenDisassembler.h" |
| 23 | #include "llvm/MC/MCInst.h" |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCInstrInfo.h" |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCRegisterInfo.h" |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSubtargetInfo.h" |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 27 | #include "llvm/Support/MathExtras.h" |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 28 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame^] | 29 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 30 | #include <cassert> |
| 31 | #include <cstddef> |
| 32 | #include <cstdint> |
| 33 | #include <memory> |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 34 | |
| 35 | using namespace llvm; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 36 | using namespace Hexagon; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 37 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 38 | typedef MCDisassembler::DecodeStatus DecodeStatus; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 39 | |
| 40 | namespace { |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 41 | |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 42 | /// \brief Hexagon disassembler for all Hexagon platforms. |
| 43 | class HexagonDisassembler : public MCDisassembler { |
| 44 | public: |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 45 | std::unique_ptr<MCInstrInfo const> const MCII; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 46 | std::unique_ptr<MCInst *> CurrentBundle; |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 47 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 48 | HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
| 49 | MCInstrInfo const *MCII) |
| 50 | : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *) {} |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 51 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 52 | DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB, |
| 53 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 54 | raw_ostream &VStream, raw_ostream &CStream, |
| 55 | bool &Complete) const; |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 56 | DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 57 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 58 | raw_ostream &VStream, |
| 59 | raw_ostream &CStream) const override; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 60 | void addSubinstOperands(MCInst *MI, unsigned opcode, unsigned inst) const; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 61 | }; |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 62 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 63 | namespace { |
| 64 | uint32_t fullValue(MCInstrInfo const &MCII, MCInst &MCB, MCInst &MI, |
| 65 | int64_t Value) { |
| 66 | MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( |
| 67 | MCB, HexagonMCInstrInfo::bundleSize(MCB)); |
| 68 | if (!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI)) |
| 69 | return Value; |
| 70 | unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI); |
| 71 | uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f; |
| 72 | int64_t Bits; |
| 73 | bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits); |
| 74 | assert(Success); (void)Success; |
| 75 | uint32_t Upper26 = static_cast<uint32_t>(Bits); |
| 76 | uint32_t Operand = Upper26 | Lower6; |
| 77 | return Operand; |
| 78 | } |
| 79 | HexagonDisassembler const &disassembler(void const *Decoder) { |
| 80 | return *static_cast<HexagonDisassembler const *>(Decoder); |
| 81 | } |
| 82 | template <size_t T> |
| 83 | void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) { |
| 84 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
| 85 | int64_t FullValue = |
| 86 | fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, |
| 87 | SignExtend64<T>(tmp)); |
| 88 | int64_t Extended = SignExtend64<32>(FullValue); |
| 89 | HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); |
| 90 | } |
| 91 | } |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 92 | } // end anonymous namespace |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 93 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 94 | // Forward declare these because the auto-generated code will reference them. |
| 95 | // Definitions are further down. |
| 96 | |
| 97 | static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 98 | uint64_t Address, |
| 99 | const void *Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 100 | static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, |
| 101 | unsigned RegNo, |
| 102 | uint64_t Address, |
| 103 | const void *Decoder); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 104 | static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, |
| 105 | uint64_t Address, |
| 106 | const void *Decoder); |
| 107 | static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 108 | uint64_t Address, |
| 109 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 110 | static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 111 | uint64_t Address, |
| 112 | const void *Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 113 | static DecodeStatus |
| 114 | DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 115 | uint64_t Address, const void *Decoder); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 116 | static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 117 | uint64_t Address, |
| 118 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 119 | static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 120 | uint64_t Address, |
| 121 | const void *Decoder); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 122 | static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 123 | uint64_t Address, |
| 124 | const void *Decoder); |
Colin LeMahieu | f3db884 | 2014-12-19 19:06:32 +0000 | [diff] [blame] | 125 | static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 126 | uint64_t Address, |
| 127 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 128 | static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 129 | uint64_t Address, |
| 130 | const void *Decoder); |
Colin LeMahieu | 404d5b2 | 2015-02-10 16:59:36 +0000 | [diff] [blame] | 131 | static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 132 | uint64_t Address, |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 133 | const void *Decoder); |
| 134 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 135 | static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, |
| 136 | uint64_t Address, const void *Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 137 | static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, |
| 138 | uint64_t /*Address*/, const void *Decoder); |
Krzysztof Parzyszek | 654dc11 | 2016-11-01 19:02:10 +0000 | [diff] [blame] | 139 | static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
Colin LeMahieu | 1e9d1d7 | 2015-06-10 16:52:32 +0000 | [diff] [blame] | 140 | const void *Decoder); |
| 141 | static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 142 | const void *Decoder); |
| 143 | static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 144 | const void *Decoder); |
| 145 | static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 146 | const void *Decoder); |
| 147 | static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 148 | const void *Decoder); |
| 149 | static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 150 | const void *Decoder); |
Krzysztof Parzyszek | 058abf1a | 2017-04-06 17:28:21 +0000 | [diff] [blame] | 151 | static DecodeStatus s3_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 152 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 153 | static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 154 | const void *Decoder); |
Colin LeMahieu | efa74e0 | 2014-11-18 20:28:11 +0000 | [diff] [blame] | 155 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 156 | #include "HexagonDepDecoders.h" |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 157 | #include "HexagonGenDisassemblerTables.inc" |
| 158 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 159 | static MCDisassembler *createHexagonDisassembler(const Target &T, |
| 160 | const MCSubtargetInfo &STI, |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 161 | MCContext &Ctx) { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 162 | return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo()); |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | extern "C" void LLVMInitializeHexagonDisassembler() { |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 166 | TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(), |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 167 | createHexagonDisassembler); |
| 168 | } |
| 169 | |
| 170 | DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 171 | ArrayRef<uint8_t> Bytes, |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 172 | uint64_t Address, |
| 173 | raw_ostream &os, |
| 174 | raw_ostream &cs) const { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 175 | DecodeStatus Result = DecodeStatus::Success; |
| 176 | bool Complete = false; |
| 177 | Size = 0; |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 178 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 179 | *CurrentBundle = &MI; |
Colin LeMahieu | f0af6e5 | 2015-11-13 17:42:46 +0000 | [diff] [blame] | 180 | MI = HexagonMCInstrInfo::createBundle(); |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 181 | while (Result == Success && !Complete) { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 182 | if (Bytes.size() < HEXAGON_INSTR_SIZE) |
| 183 | return MCDisassembler::Fail; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 184 | MCInst *Inst = new (getContext()) MCInst; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 185 | Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete); |
| 186 | MI.addOperand(MCOperand::createInst(Inst)); |
| 187 | Size += HEXAGON_INSTR_SIZE; |
| 188 | Bytes = Bytes.slice(HEXAGON_INSTR_SIZE); |
| 189 | } |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 190 | if (Result == MCDisassembler::Fail) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 191 | return Result; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 192 | if (Size > HEXAGON_MAX_PACKET_SIZE) |
| 193 | return MCDisassembler::Fail; |
Krzysztof Parzyszek | e12d1e7 | 2017-05-01 19:41:43 +0000 | [diff] [blame] | 194 | HexagonMCChecker Checker(getContext(), *MCII, STI, MI, |
| 195 | *getContext().getRegisterInfo(), false); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 196 | if (!Checker.check()) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 197 | return MCDisassembler::Fail; |
| 198 | return MCDisassembler::Success; |
| 199 | } |
| 200 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 201 | namespace { |
| 202 | void adjustDuplex(MCInst &MI, MCContext &Context) { |
| 203 | switch (MI.getOpcode()) { |
| 204 | case Hexagon::SA1_setin1: |
| 205 | MI.insert(MI.begin() + 1, |
| 206 | MCOperand::createExpr(MCConstantExpr::create(-1, Context))); |
| 207 | break; |
| 208 | case Hexagon::SA1_dec: |
| 209 | MI.insert(MI.begin() + 2, |
| 210 | MCOperand::createExpr(MCConstantExpr::create(-1, Context))); |
| 211 | break; |
| 212 | default: |
| 213 | break; |
| 214 | } |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 215 | } |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 216 | } |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 217 | |
| 218 | DecodeStatus HexagonDisassembler::getSingleInstruction( |
| 219 | MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 220 | raw_ostream &os, raw_ostream &cs, bool &Complete) const { |
| 221 | assert(Bytes.size() >= HEXAGON_INSTR_SIZE); |
| 222 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 223 | uint32_t Instruction = support::endian::read32le(Bytes.data()); |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 224 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 225 | auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB); |
| 226 | if ((Instruction & HexagonII::INST_PARSE_MASK) == |
| 227 | HexagonII::INST_PARSE_LOOP_END) { |
| 228 | if (BundleSize == 0) |
| 229 | HexagonMCInstrInfo::setInnerLoop(MCB); |
| 230 | else if (BundleSize == 1) |
| 231 | HexagonMCInstrInfo::setOuterLoop(MCB); |
| 232 | else |
| 233 | return DecodeStatus::Fail; |
| 234 | } |
| 235 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 236 | MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex( |
| 237 | MCB, HexagonMCInstrInfo::bundleSize(MCB)); |
| 238 | |
| 239 | DecodeStatus Result = DecodeStatus::Fail; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 240 | if ((Instruction & HexagonII::INST_PARSE_MASK) == |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 241 | HexagonII::INST_PARSE_DUPLEX) { |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 242 | unsigned duplexIClass; |
| 243 | uint8_t const *DecodeLow, *DecodeHigh; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 244 | duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1); |
| 245 | switch (duplexIClass) { |
| 246 | default: |
| 247 | return MCDisassembler::Fail; |
| 248 | case 0: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 249 | DecodeLow = DecoderTableSUBINSN_L132; |
| 250 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 251 | break; |
| 252 | case 1: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 253 | DecodeLow = DecoderTableSUBINSN_L232; |
| 254 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 255 | break; |
| 256 | case 2: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 257 | DecodeLow = DecoderTableSUBINSN_L232; |
| 258 | DecodeHigh = DecoderTableSUBINSN_L232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 259 | break; |
| 260 | case 3: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 261 | DecodeLow = DecoderTableSUBINSN_A32; |
| 262 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 263 | break; |
| 264 | case 4: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 265 | DecodeLow = DecoderTableSUBINSN_L132; |
| 266 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 267 | break; |
| 268 | case 5: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 269 | DecodeLow = DecoderTableSUBINSN_L232; |
| 270 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 271 | break; |
| 272 | case 6: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 273 | DecodeLow = DecoderTableSUBINSN_S132; |
| 274 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 275 | break; |
| 276 | case 7: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 277 | DecodeLow = DecoderTableSUBINSN_S232; |
| 278 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 279 | break; |
| 280 | case 8: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 281 | DecodeLow = DecoderTableSUBINSN_S132; |
| 282 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 283 | break; |
| 284 | case 9: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 285 | DecodeLow = DecoderTableSUBINSN_S132; |
| 286 | DecodeHigh = DecoderTableSUBINSN_L232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 287 | break; |
| 288 | case 10: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 289 | DecodeLow = DecoderTableSUBINSN_S132; |
| 290 | DecodeHigh = DecoderTableSUBINSN_S132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 291 | break; |
| 292 | case 11: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 293 | DecodeLow = DecoderTableSUBINSN_S232; |
| 294 | DecodeHigh = DecoderTableSUBINSN_S132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 295 | break; |
| 296 | case 12: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 297 | DecodeLow = DecoderTableSUBINSN_S232; |
| 298 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 299 | break; |
| 300 | case 13: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 301 | DecodeLow = DecoderTableSUBINSN_S232; |
| 302 | DecodeHigh = DecoderTableSUBINSN_L232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 303 | break; |
| 304 | case 14: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 305 | DecodeLow = DecoderTableSUBINSN_S232; |
| 306 | DecodeHigh = DecoderTableSUBINSN_S232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 307 | break; |
| 308 | } |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 309 | MI.setOpcode(Hexagon::DuplexIClass0 + duplexIClass); |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 310 | MCInst *MILow = new (getContext()) MCInst; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 311 | MCInst *MIHigh = new (getContext()) MCInst; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 312 | Result = decodeInstruction(DecodeLow, *MILow, Instruction & 0x1fff, Address, |
| 313 | this, STI); |
| 314 | if (Result != DecodeStatus::Success) |
| 315 | return DecodeStatus::Fail; |
| 316 | adjustDuplex(*MILow, getContext()); |
| 317 | Result = decodeInstruction( |
| 318 | DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff, Address, this, STI); |
| 319 | if (Result != DecodeStatus::Success) |
| 320 | return DecodeStatus::Fail; |
| 321 | adjustDuplex(*MIHigh, getContext()); |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 322 | MCOperand OPLow = MCOperand::createInst(MILow); |
| 323 | MCOperand OPHigh = MCOperand::createInst(MIHigh); |
| 324 | MI.addOperand(OPLow); |
| 325 | MI.addOperand(OPHigh); |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 326 | Complete = true; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 327 | } else { |
| 328 | if ((Instruction & HexagonII::INST_PARSE_MASK) == |
| 329 | HexagonII::INST_PARSE_PACKET_END) |
| 330 | Complete = true; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 331 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 332 | if (Extender != nullptr) |
| 333 | Result = decodeInstruction(DecoderTableMustExtend32, MI, Instruction, |
| 334 | Address, this, STI); |
| 335 | |
| 336 | if (Result != MCDisassembler::Success) |
| 337 | Result = decodeInstruction(DecoderTable32, MI, Instruction, Address, this, |
| 338 | STI); |
| 339 | |
| 340 | if (Result != MCDisassembler::Success && |
| 341 | STI.getFeatureBits()[Hexagon::ExtensionHVX]) |
| 342 | Result = decodeInstruction(DecoderTableEXT_mmvec32, MI, Instruction, |
| 343 | Address, this, STI); |
| 344 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 345 | } |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 346 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 347 | switch (MI.getOpcode()) { |
Colin LeMahieu | 8170754 | 2016-12-05 04:29:00 +0000 | [diff] [blame] | 348 | case Hexagon::J4_cmpeqn1_f_jumpnv_nt: |
| 349 | case Hexagon::J4_cmpeqn1_f_jumpnv_t: |
| 350 | case Hexagon::J4_cmpeqn1_fp0_jump_nt: |
| 351 | case Hexagon::J4_cmpeqn1_fp0_jump_t: |
| 352 | case Hexagon::J4_cmpeqn1_fp1_jump_nt: |
| 353 | case Hexagon::J4_cmpeqn1_fp1_jump_t: |
| 354 | case Hexagon::J4_cmpeqn1_t_jumpnv_nt: |
| 355 | case Hexagon::J4_cmpeqn1_t_jumpnv_t: |
| 356 | case Hexagon::J4_cmpeqn1_tp0_jump_nt: |
| 357 | case Hexagon::J4_cmpeqn1_tp0_jump_t: |
| 358 | case Hexagon::J4_cmpeqn1_tp1_jump_nt: |
| 359 | case Hexagon::J4_cmpeqn1_tp1_jump_t: |
| 360 | case Hexagon::J4_cmpgtn1_f_jumpnv_nt: |
| 361 | case Hexagon::J4_cmpgtn1_f_jumpnv_t: |
| 362 | case Hexagon::J4_cmpgtn1_fp0_jump_nt: |
| 363 | case Hexagon::J4_cmpgtn1_fp0_jump_t: |
| 364 | case Hexagon::J4_cmpgtn1_fp1_jump_nt: |
| 365 | case Hexagon::J4_cmpgtn1_fp1_jump_t: |
| 366 | case Hexagon::J4_cmpgtn1_t_jumpnv_nt: |
| 367 | case Hexagon::J4_cmpgtn1_t_jumpnv_t: |
| 368 | case Hexagon::J4_cmpgtn1_tp0_jump_nt: |
| 369 | case Hexagon::J4_cmpgtn1_tp0_jump_t: |
| 370 | case Hexagon::J4_cmpgtn1_tp1_jump_nt: |
| 371 | case Hexagon::J4_cmpgtn1_tp1_jump_t: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 372 | MI.insert(MI.begin() + 1, |
| 373 | MCOperand::createExpr(MCConstantExpr::create(-1, getContext()))); |
Colin LeMahieu | 8170754 | 2016-12-05 04:29:00 +0000 | [diff] [blame] | 374 | break; |
| 375 | default: |
| 376 | break; |
| 377 | } |
| 378 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 379 | if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) { |
| 380 | unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI); |
| 381 | MCOperand &MCO = MI.getOperand(OpIndex); |
| 382 | assert(MCO.isReg() && "New value consumers must be registers"); |
| 383 | unsigned Register = |
| 384 | getContext().getRegisterInfo()->getEncodingValue(MCO.getReg()); |
| 385 | if ((Register & 0x6) == 0) |
| 386 | // HexagonPRM 10.11 Bit 1-2 == 0 is reserved |
| 387 | return MCDisassembler::Fail; |
| 388 | unsigned Lookback = (Register & 0x6) >> 1; |
| 389 | unsigned Offset = 1; |
| 390 | bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI); |
| 391 | auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); |
| 392 | auto i = Instructions.end() - 1; |
| 393 | for (auto n = Instructions.begin() - 1;; --i, ++Offset) { |
| 394 | if (i == n) |
| 395 | // Couldn't find producer |
| 396 | return MCDisassembler::Fail; |
| 397 | if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst())) |
| 398 | // Skip scalars when calculating distances for vectors |
| 399 | ++Lookback; |
| 400 | if (HexagonMCInstrInfo::isImmext(*i->getInst())) |
| 401 | ++Lookback; |
| 402 | if (Offset == Lookback) |
| 403 | break; |
| 404 | } |
| 405 | auto const &Inst = *i->getInst(); |
| 406 | bool SubregBit = (Register & 0x1) != 0; |
| 407 | if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) { |
| 408 | // If subreg bit is set we're selecting the second produced newvalue |
| 409 | unsigned Producer = |
| 410 | HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg(); |
| 411 | assert(Producer != Hexagon::NoRegister); |
| 412 | MCO.setReg(Producer); |
| 413 | } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) { |
| 414 | unsigned Producer = |
| 415 | HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg(); |
| 416 | if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15) |
| 417 | Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0; |
| 418 | else if (SubregBit) |
Colin LeMahieu | 2d497a0 | 2016-03-01 22:05:03 +0000 | [diff] [blame] | 419 | // Hexagon PRM 10.11 New-value operands |
| 420 | // Nt[0] is reserved and should always be encoded as zero. |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 421 | return MCDisassembler::Fail; |
| 422 | assert(Producer != Hexagon::NoRegister); |
| 423 | MCO.setReg(Producer); |
| 424 | } else |
| 425 | return MCDisassembler::Fail; |
| 426 | } |
| 427 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 428 | if (Extender != nullptr) { |
| 429 | MCInst const &Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) |
| 430 | ? *MI.getOperand(1).getInst() |
| 431 | : MI; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 432 | if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) && |
| 433 | !HexagonMCInstrInfo::isExtended(*MCII, Inst)) |
| 434 | return MCDisassembler::Fail; |
| 435 | } |
Colin LeMahieu | 5d6f03b | 2014-12-04 03:41:21 +0000 | [diff] [blame] | 436 | return Result; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 437 | } |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 438 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 439 | static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 440 | ArrayRef<MCPhysReg> Table) { |
Craig Topper | 3da000c | 2015-12-01 06:13:04 +0000 | [diff] [blame] | 441 | if (RegNo < Table.size()) { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 442 | Inst.addOperand(MCOperand::createReg(Table[RegNo])); |
| 443 | return MCDisassembler::Success; |
Craig Topper | 3da000c | 2015-12-01 06:13:04 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | return MCDisassembler::Fail; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 449 | static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, |
| 450 | uint64_t Address, |
| 451 | const void *Decoder) { |
| 452 | return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder); |
| 453 | } |
| 454 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 455 | static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 456 | uint64_t Address, |
| 457 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 458 | static const MCPhysReg IntRegDecoderTable[] = { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 459 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, |
| 460 | Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9, |
| 461 | Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14, |
| 462 | Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, |
| 463 | Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24, |
| 464 | Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29, |
| 465 | Hexagon::R30, Hexagon::R31}; |
| 466 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 467 | return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 468 | } |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 469 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 470 | static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, |
| 471 | unsigned RegNo, |
| 472 | uint64_t Address, |
| 473 | const void *Decoder) { |
| 474 | static const MCPhysReg GeneralSubRegDecoderTable[] = { |
| 475 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, |
| 476 | Hexagon::R4, Hexagon::R5, Hexagon::R6, Hexagon::R7, |
| 477 | Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, |
| 478 | Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, |
| 479 | }; |
| 480 | |
| 481 | return DecodeRegisterClass(Inst, RegNo, GeneralSubRegDecoderTable); |
| 482 | } |
| 483 | |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 484 | static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 485 | uint64_t /*Address*/, |
| 486 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 487 | static const MCPhysReg VecRegDecoderTable[] = { |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 488 | Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, |
| 489 | Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, |
| 490 | Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, |
| 491 | Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19, |
| 492 | Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24, |
| 493 | Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29, |
| 494 | Hexagon::V30, Hexagon::V31}; |
| 495 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 496 | return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 499 | static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 500 | uint64_t /*Address*/, |
| 501 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 502 | static const MCPhysReg DoubleRegDecoderTable[] = { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 503 | Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, |
| 504 | Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7, |
| 505 | Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11, |
| 506 | Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15}; |
| 507 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 508 | return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 511 | static DecodeStatus DecodeGeneralDoubleLow8RegsRegisterClass( |
| 512 | MCInst &Inst, unsigned RegNo, uint64_t /*Address*/, const void *Decoder) { |
| 513 | static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = { |
| 514 | Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, |
| 515 | Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11}; |
| 516 | |
| 517 | return DecodeRegisterClass(Inst, RegNo, GeneralDoubleLow8RegDecoderTable); |
| 518 | } |
| 519 | |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 520 | static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 521 | uint64_t /*Address*/, |
| 522 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 523 | static const MCPhysReg VecDblRegDecoderTable[] = { |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 524 | Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, |
| 525 | Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7, |
| 526 | Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11, |
| 527 | Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15}; |
| 528 | |
Craig Topper | 3da000c | 2015-12-01 06:13:04 +0000 | [diff] [blame] | 529 | return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable)); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 532 | static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 533 | uint64_t /*Address*/, |
| 534 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 535 | static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1, |
| 536 | Hexagon::P2, Hexagon::P3}; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 537 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 538 | return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 541 | static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 542 | uint64_t /*Address*/, |
| 543 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 544 | static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1, |
| 545 | Hexagon::Q2, Hexagon::Q3}; |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 546 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 547 | return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 548 | } |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 549 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 550 | static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 551 | uint64_t /*Address*/, |
| 552 | const void *Decoder) { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 553 | using namespace Hexagon; |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 554 | static const MCPhysReg CtrlRegDecoderTable[] = { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 555 | /* 0 */ SA0, LC0, SA1, LC1, |
Krzysztof Parzyszek | e260332 | 2017-05-05 22:12:12 +0000 | [diff] [blame] | 556 | /* 4 */ P3_0, C5, M0, M1, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 557 | /* 8 */ USR, PC, UGP, GP, |
Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 558 | /* 12 */ CS0, CS1, UPCYCLELO, UPCYCLEHI, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 559 | /* 16 */ FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI, |
| 560 | /* 20 */ 0, 0, 0, 0, |
| 561 | /* 24 */ 0, 0, 0, 0, |
| 562 | /* 28 */ 0, 0, UTIMERLO, UTIMERHI |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
Craig Topper | 6261e1b | 2015-12-01 06:13:06 +0000 | [diff] [blame] | 565 | if (RegNo >= array_lengthof(CtrlRegDecoderTable)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 566 | return MCDisassembler::Fail; |
| 567 | |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 568 | static_assert(NoRegister == 0, "Expecting NoRegister to be 0"); |
| 569 | if (CtrlRegDecoderTable[RegNo] == NoRegister) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 570 | return MCDisassembler::Fail; |
| 571 | |
| 572 | unsigned Register = CtrlRegDecoderTable[RegNo]; |
| 573 | Inst.addOperand(MCOperand::createReg(Register)); |
| 574 | return MCDisassembler::Success; |
| 575 | } |
| 576 | |
| 577 | static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, |
| 578 | uint64_t /*Address*/, |
| 579 | const void *Decoder) { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 580 | using namespace Hexagon; |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 581 | static const MCPhysReg CtrlReg64DecoderTable[] = { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 582 | /* 0 */ C1_0, 0, C3_2, 0, |
| 583 | /* 4 */ C5_4, 0, C7_6, 0, |
| 584 | /* 8 */ C9_8, 0, C11_10, 0, |
Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 585 | /* 12 */ CS, 0, UPCYCLE, 0, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 586 | /* 16 */ C17_16, 0, PKTCOUNT, 0, |
| 587 | /* 20 */ 0, 0, 0, 0, |
| 588 | /* 24 */ 0, 0, 0, 0, |
| 589 | /* 28 */ 0, 0, UTIMER, 0 |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 590 | }; |
| 591 | |
Craig Topper | 6261e1b | 2015-12-01 06:13:06 +0000 | [diff] [blame] | 592 | if (RegNo >= array_lengthof(CtrlReg64DecoderTable)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 593 | return MCDisassembler::Fail; |
| 594 | |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 595 | static_assert(NoRegister == 0, "Expecting NoRegister to be 0"); |
| 596 | if (CtrlReg64DecoderTable[RegNo] == NoRegister) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 597 | return MCDisassembler::Fail; |
| 598 | |
| 599 | unsigned Register = CtrlReg64DecoderTable[RegNo]; |
| 600 | Inst.addOperand(MCOperand::createReg(Register)); |
| 601 | return MCDisassembler::Success; |
| 602 | } |
| 603 | |
| 604 | static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 605 | uint64_t /*Address*/, |
| 606 | const void *Decoder) { |
| 607 | unsigned Register = 0; |
| 608 | switch (RegNo) { |
| 609 | case 0: |
| 610 | Register = Hexagon::M0; |
| 611 | break; |
| 612 | case 1: |
| 613 | Register = Hexagon::M1; |
| 614 | break; |
| 615 | default: |
| 616 | return MCDisassembler::Fail; |
| 617 | } |
| 618 | Inst.addOperand(MCOperand::createReg(Register)); |
| 619 | return MCDisassembler::Success; |
| 620 | } |
| 621 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 622 | static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, |
| 623 | uint64_t /*Address*/, |
| 624 | const void *Decoder) { |
| 625 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 626 | int64_t FullValue = |
| 627 | fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, tmp); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 628 | assert(FullValue >= 0 && "Negative in unsigned decoder"); |
| 629 | HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext()); |
| 630 | return MCDisassembler::Success; |
| 631 | } |
| 632 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 633 | static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, |
| 634 | uint64_t /*Address*/, const void *Decoder) { |
| 635 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
| 636 | unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); |
| 637 | tmp = SignExtend64(tmp, Bits); |
| 638 | signedDecoder<32>(MI, tmp, Decoder); |
| 639 | return MCDisassembler::Success; |
| 640 | } |
| 641 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 642 | // custom decoder for various jump/call immediates |
| 643 | static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 644 | const void *Decoder) { |
| 645 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
| 646 | unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); |
| 647 | // r13_2 is not extendable, so if there are no extent bits, it's r13_2 |
| 648 | if (Bits == 0) |
| 649 | Bits = 15; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 650 | uint32_t FullValue = |
| 651 | fullValue(*Disassembler.MCII, **Disassembler.CurrentBundle, MI, |
| 652 | SignExtend64(tmp, Bits)); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 653 | int64_t Extended = SignExtend64<32>(FullValue) + Address; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 654 | if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 0, 4)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 655 | HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); |
| 656 | return MCDisassembler::Success; |
| 657 | } |
| 658 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 659 | |