Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 1 | //===- HexagonDisassembler.cpp - Disassembler for Hexagon ISA -------------===// |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 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 | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Endian.h" |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 28 | #include "llvm/Support/MathExtras.h" |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 29 | #include "llvm/Support/TargetRegistry.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 31 | #include <cassert> |
| 32 | #include <cstddef> |
| 33 | #include <cstdint> |
| 34 | #include <memory> |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 35 | |
| 36 | using namespace llvm; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 37 | using namespace Hexagon; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 38 | |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 39 | using DecodeStatus = MCDisassembler::DecodeStatus; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 40 | |
| 41 | namespace { |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 42 | |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 43 | /// \brief Hexagon disassembler for all Hexagon platforms. |
| 44 | class HexagonDisassembler : public MCDisassembler { |
| 45 | public: |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 46 | std::unique_ptr<MCInstrInfo const> const MCII; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 47 | std::unique_ptr<MCInst *> CurrentBundle; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 48 | mutable MCInst const *CurrentExtender; |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 49 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 50 | HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx, |
| 51 | MCInstrInfo const *MCII) |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 52 | : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *), |
| 53 | CurrentExtender(nullptr) {} |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 54 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 55 | DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB, |
| 56 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 57 | raw_ostream &VStream, raw_ostream &CStream, |
| 58 | bool &Complete) const; |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 59 | DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 60 | ArrayRef<uint8_t> Bytes, uint64_t Address, |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 61 | raw_ostream &VStream, |
| 62 | raw_ostream &CStream) const override; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 63 | void remapInstruction(MCInst &Instr) const; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 64 | }; |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 65 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 66 | static uint64_t fullValue(HexagonDisassembler const &Disassembler, MCInst &MI, |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 67 | int64_t Value) { |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 68 | MCInstrInfo MCII = *Disassembler.MCII; |
| 69 | if (!Disassembler.CurrentExtender || |
| 70 | MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI)) |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 71 | return Value; |
| 72 | unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI); |
| 73 | uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f; |
| 74 | int64_t Bits; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 75 | bool Success = |
| 76 | Disassembler.CurrentExtender->getOperand(0).getExpr()->evaluateAsAbsolute( |
| 77 | Bits); |
| 78 | assert(Success); |
| 79 | (void)Success; |
| 80 | uint64_t Upper26 = static_cast<uint64_t>(Bits); |
| 81 | uint64_t Operand = Upper26 | Lower6; |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 82 | return Operand; |
| 83 | } |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 84 | static HexagonDisassembler const &disassembler(void const *Decoder) { |
| 85 | return *static_cast<HexagonDisassembler const *>(Decoder); |
| 86 | } |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 87 | template <size_t T> |
| 88 | static void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) { |
| 89 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 90 | int64_t FullValue = fullValue(Disassembler, MI, SignExtend64<T>(tmp)); |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 91 | int64_t Extended = SignExtend64<32>(FullValue); |
| 92 | HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); |
| 93 | } |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 94 | } |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 95 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 96 | // Forward declare these because the auto-generated code will reference them. |
| 97 | // Definitions are further down. |
| 98 | |
| 99 | static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 100 | uint64_t Address, |
| 101 | const void *Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 102 | static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, |
| 103 | unsigned RegNo, |
| 104 | uint64_t Address, |
| 105 | const void *Decoder); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 106 | static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, |
| 107 | uint64_t Address, |
| 108 | const void *Decoder); |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 109 | static DecodeStatus DecodeHvxVRRegisterClass(MCInst &Inst, unsigned RegNo, |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 110 | uint64_t Address, |
| 111 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 112 | static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 113 | uint64_t Address, |
| 114 | const void *Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 115 | static DecodeStatus |
| 116 | DecodeGeneralDoubleLow8RegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 117 | uint64_t Address, const void *Decoder); |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 118 | static DecodeStatus DecodeHvxWRRegisterClass(MCInst &Inst, unsigned RegNo, |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 119 | uint64_t Address, |
| 120 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 121 | static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 122 | uint64_t Address, |
| 123 | const void *Decoder); |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 124 | static DecodeStatus DecodeHvxQRRegisterClass(MCInst &Inst, unsigned RegNo, |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 125 | uint64_t Address, |
| 126 | const void *Decoder); |
Colin LeMahieu | f3db884 | 2014-12-19 19:06:32 +0000 | [diff] [blame] | 127 | static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 128 | uint64_t Address, |
| 129 | const void *Decoder); |
Krzysztof Parzyszek | 22a21d4 | 2018-03-01 17:03:26 +0000 | [diff] [blame^] | 130 | static DecodeStatus DecodeGuestRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 131 | uint64_t Address, |
| 132 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 133 | static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 134 | uint64_t Address, |
| 135 | const void *Decoder); |
Colin LeMahieu | 404d5b2 | 2015-02-10 16:59:36 +0000 | [diff] [blame] | 136 | static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 137 | uint64_t Address, |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 138 | const void *Decoder); |
Krzysztof Parzyszek | 22a21d4 | 2018-03-01 17:03:26 +0000 | [diff] [blame^] | 139 | static DecodeStatus DecodeGuestRegs64RegisterClass(MCInst &Inst, unsigned RegNo, |
| 140 | uint64_t Address, |
| 141 | const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 142 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 143 | static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, |
| 144 | uint64_t Address, const void *Decoder); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 145 | static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, |
| 146 | uint64_t /*Address*/, const void *Decoder); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 147 | static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 148 | const void *Decoder); |
Colin LeMahieu | efa74e0 | 2014-11-18 20:28:11 +0000 | [diff] [blame] | 149 | |
David Blaikie | f157ad4 | 2017-12-14 23:45:58 +0000 | [diff] [blame] | 150 | static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 151 | const void *Decoder) { |
| 152 | signedDecoder<4>(MI, tmp, Decoder); |
| 153 | return MCDisassembler::Success; |
| 154 | } |
| 155 | static DecodeStatus s29_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 156 | const void *Decoder) { |
| 157 | signedDecoder<14>(MI, tmp, Decoder); |
| 158 | return MCDisassembler::Success; |
| 159 | } |
| 160 | static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 161 | const void *Decoder) { |
| 162 | signedDecoder<8>(MI, tmp, Decoder); |
| 163 | return MCDisassembler::Success; |
| 164 | } |
| 165 | static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 166 | const void *Decoder) { |
| 167 | signedDecoder<7>(MI, tmp, Decoder); |
| 168 | return MCDisassembler::Success; |
| 169 | } |
| 170 | static DecodeStatus s31_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 171 | const void *Decoder) { |
| 172 | signedDecoder<12>(MI, tmp, Decoder); |
| 173 | return MCDisassembler::Success; |
| 174 | } |
| 175 | static DecodeStatus s3_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 176 | const void *Decoder) { |
| 177 | signedDecoder<3>(MI, tmp, Decoder); |
| 178 | return MCDisassembler::Success; |
| 179 | } |
| 180 | static DecodeStatus s30_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 181 | const void *Decoder) { |
| 182 | signedDecoder<13>(MI, tmp, Decoder); |
| 183 | return MCDisassembler::Success; |
| 184 | } |
| 185 | static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 186 | const void *Decoder) { |
| 187 | signedDecoder<6>(MI, tmp, Decoder); |
| 188 | return MCDisassembler::Success; |
| 189 | } |
| 190 | static DecodeStatus s6_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 191 | const void *Decoder) { |
| 192 | signedDecoder<9>(MI, tmp, Decoder); |
| 193 | return MCDisassembler::Success; |
| 194 | } |
| 195 | static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 196 | const void *Decoder) { |
| 197 | signedDecoder<5>(MI, tmp, Decoder); |
| 198 | return MCDisassembler::Success; |
| 199 | } |
| 200 | static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t, |
| 201 | const void *Decoder) { |
| 202 | signedDecoder<6>(MI, tmp, Decoder); |
| 203 | return MCDisassembler::Success; |
| 204 | } |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 205 | #include "HexagonGenDisassemblerTables.inc" |
| 206 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 207 | static MCDisassembler *createHexagonDisassembler(const Target &T, |
| 208 | const MCSubtargetInfo &STI, |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 209 | MCContext &Ctx) { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 210 | return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo()); |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | extern "C" void LLVMInitializeHexagonDisassembler() { |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 214 | TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(), |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 215 | createHexagonDisassembler); |
| 216 | } |
| 217 | |
| 218 | DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size, |
Rafael Espindola | 7fc5b87 | 2014-11-12 02:04:27 +0000 | [diff] [blame] | 219 | ArrayRef<uint8_t> Bytes, |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 220 | uint64_t Address, |
| 221 | raw_ostream &os, |
| 222 | raw_ostream &cs) const { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 223 | DecodeStatus Result = DecodeStatus::Success; |
| 224 | bool Complete = false; |
| 225 | Size = 0; |
Rafael Espindola | 4aa6bea | 2014-11-10 18:11:10 +0000 | [diff] [blame] | 226 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 227 | *CurrentBundle = &MI; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 228 | MI.setOpcode(Hexagon::BUNDLE); |
| 229 | MI.addOperand(MCOperand::createImm(0)); |
Eugene Zelenko | 8208592 | 2016-12-13 22:13:50 +0000 | [diff] [blame] | 230 | while (Result == Success && !Complete) { |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 231 | if (Bytes.size() < HEXAGON_INSTR_SIZE) |
| 232 | return MCDisassembler::Fail; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 233 | MCInst *Inst = new (getContext()) MCInst; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 234 | Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete); |
| 235 | MI.addOperand(MCOperand::createInst(Inst)); |
| 236 | Size += HEXAGON_INSTR_SIZE; |
| 237 | Bytes = Bytes.slice(HEXAGON_INSTR_SIZE); |
| 238 | } |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 239 | if (Result == MCDisassembler::Fail) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 240 | return Result; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 241 | if (Size > HEXAGON_MAX_PACKET_SIZE) |
| 242 | return MCDisassembler::Fail; |
Krzysztof Parzyszek | e12d1e7 | 2017-05-01 19:41:43 +0000 | [diff] [blame] | 243 | HexagonMCChecker Checker(getContext(), *MCII, STI, MI, |
| 244 | *getContext().getRegisterInfo(), false); |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 245 | if (!Checker.check()) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 246 | return MCDisassembler::Fail; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 247 | remapInstruction(MI); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 248 | return MCDisassembler::Success; |
| 249 | } |
| 250 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 251 | void HexagonDisassembler::remapInstruction(MCInst &Instr) const { |
| 252 | for (auto I: HexagonMCInstrInfo::bundleInstructions(Instr)) { |
| 253 | auto &MI = const_cast<MCInst &>(*I.getInst()); |
| 254 | switch (MI.getOpcode()) { |
| 255 | case Hexagon::S2_allocframe: |
| 256 | if (MI.getOperand(0).getReg() == Hexagon::R29) { |
| 257 | MI.setOpcode(Hexagon::S6_allocframe_to_raw); |
| 258 | MI.erase(MI.begin () + 1); |
| 259 | MI.erase(MI.begin ()); |
| 260 | } |
| 261 | break; |
| 262 | case Hexagon::L2_deallocframe: |
| 263 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 264 | MI.getOperand(1).getReg() == Hexagon::R30) { |
| 265 | MI.setOpcode(L6_deallocframe_map_to_raw); |
| 266 | MI.erase(MI.begin () + 1); |
| 267 | MI.erase(MI.begin ()); |
| 268 | } |
| 269 | break; |
| 270 | case Hexagon::L4_return: |
| 271 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 272 | MI.getOperand(1).getReg() == Hexagon::R30) { |
| 273 | MI.setOpcode(L6_return_map_to_raw); |
| 274 | MI.erase(MI.begin () + 1); |
| 275 | MI.erase(MI.begin ()); |
| 276 | } |
| 277 | break; |
| 278 | case Hexagon::L4_return_t: |
| 279 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 280 | MI.getOperand(2).getReg() == Hexagon::R30) { |
| 281 | MI.setOpcode(L4_return_map_to_raw_t); |
| 282 | MI.erase(MI.begin () + 2); |
| 283 | MI.erase(MI.begin ()); |
| 284 | } |
| 285 | break; |
| 286 | case Hexagon::L4_return_f: |
| 287 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 288 | MI.getOperand(2).getReg() == Hexagon::R30) { |
| 289 | MI.setOpcode(L4_return_map_to_raw_f); |
| 290 | MI.erase(MI.begin () + 2); |
| 291 | MI.erase(MI.begin ()); |
| 292 | } |
| 293 | break; |
| 294 | case Hexagon::L4_return_tnew_pt: |
| 295 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 296 | MI.getOperand(2).getReg() == Hexagon::R30) { |
| 297 | MI.setOpcode(L4_return_map_to_raw_tnew_pt); |
| 298 | MI.erase(MI.begin () + 2); |
| 299 | MI.erase(MI.begin ()); |
| 300 | } |
| 301 | break; |
| 302 | case Hexagon::L4_return_fnew_pt: |
| 303 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 304 | MI.getOperand(2).getReg() == Hexagon::R30) { |
| 305 | MI.setOpcode(L4_return_map_to_raw_fnew_pt); |
| 306 | MI.erase(MI.begin () + 2); |
| 307 | MI.erase(MI.begin ()); |
| 308 | } |
| 309 | break; |
| 310 | case Hexagon::L4_return_tnew_pnt: |
| 311 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 312 | MI.getOperand(2).getReg() == Hexagon::R30) { |
| 313 | MI.setOpcode(L4_return_map_to_raw_tnew_pnt); |
| 314 | MI.erase(MI.begin () + 2); |
| 315 | MI.erase(MI.begin ()); |
| 316 | } |
| 317 | break; |
| 318 | case Hexagon::L4_return_fnew_pnt: |
| 319 | if (MI.getOperand(0).getReg() == Hexagon::D15 && |
| 320 | MI.getOperand(2).getReg() == Hexagon::R30) { |
| 321 | MI.setOpcode(L4_return_map_to_raw_fnew_pnt); |
| 322 | MI.erase(MI.begin () + 2); |
| 323 | MI.erase(MI.begin ()); |
| 324 | } |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 330 | static void adjustDuplex(MCInst &MI, MCContext &Context) { |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 331 | switch (MI.getOpcode()) { |
| 332 | case Hexagon::SA1_setin1: |
| 333 | MI.insert(MI.begin() + 1, |
| 334 | MCOperand::createExpr(MCConstantExpr::create(-1, Context))); |
| 335 | break; |
| 336 | case Hexagon::SA1_dec: |
| 337 | MI.insert(MI.begin() + 2, |
| 338 | MCOperand::createExpr(MCConstantExpr::create(-1, Context))); |
| 339 | break; |
| 340 | default: |
| 341 | break; |
| 342 | } |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 343 | } |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 344 | |
| 345 | DecodeStatus HexagonDisassembler::getSingleInstruction( |
| 346 | MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address, |
| 347 | raw_ostream &os, raw_ostream &cs, bool &Complete) const { |
| 348 | assert(Bytes.size() >= HEXAGON_INSTR_SIZE); |
| 349 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 350 | uint32_t Instruction = support::endian::read32le(Bytes.data()); |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 351 | |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 352 | auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB); |
| 353 | if ((Instruction & HexagonII::INST_PARSE_MASK) == |
| 354 | HexagonII::INST_PARSE_LOOP_END) { |
| 355 | if (BundleSize == 0) |
| 356 | HexagonMCInstrInfo::setInnerLoop(MCB); |
| 357 | else if (BundleSize == 1) |
| 358 | HexagonMCInstrInfo::setOuterLoop(MCB); |
| 359 | else |
| 360 | return DecodeStatus::Fail; |
| 361 | } |
| 362 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 363 | CurrentExtender = HexagonMCInstrInfo::extenderForIndex( |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 364 | MCB, HexagonMCInstrInfo::bundleSize(MCB)); |
| 365 | |
| 366 | DecodeStatus Result = DecodeStatus::Fail; |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 367 | if ((Instruction & HexagonII::INST_PARSE_MASK) == |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 368 | HexagonII::INST_PARSE_DUPLEX) { |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 369 | unsigned duplexIClass; |
| 370 | uint8_t const *DecodeLow, *DecodeHigh; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 371 | duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1); |
| 372 | switch (duplexIClass) { |
| 373 | default: |
| 374 | return MCDisassembler::Fail; |
| 375 | case 0: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 376 | DecodeLow = DecoderTableSUBINSN_L132; |
| 377 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 378 | break; |
| 379 | case 1: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 380 | DecodeLow = DecoderTableSUBINSN_L232; |
| 381 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 382 | break; |
| 383 | case 2: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 384 | DecodeLow = DecoderTableSUBINSN_L232; |
| 385 | DecodeHigh = DecoderTableSUBINSN_L232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 386 | break; |
| 387 | case 3: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 388 | DecodeLow = DecoderTableSUBINSN_A32; |
| 389 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 390 | break; |
| 391 | case 4: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 392 | DecodeLow = DecoderTableSUBINSN_L132; |
| 393 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 394 | break; |
| 395 | case 5: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 396 | DecodeLow = DecoderTableSUBINSN_L232; |
| 397 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 398 | break; |
| 399 | case 6: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 400 | DecodeLow = DecoderTableSUBINSN_S132; |
| 401 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 402 | break; |
| 403 | case 7: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 404 | DecodeLow = DecoderTableSUBINSN_S232; |
| 405 | DecodeHigh = DecoderTableSUBINSN_A32; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 406 | break; |
| 407 | case 8: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 408 | DecodeLow = DecoderTableSUBINSN_S132; |
| 409 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 410 | break; |
| 411 | case 9: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 412 | DecodeLow = DecoderTableSUBINSN_S132; |
| 413 | DecodeHigh = DecoderTableSUBINSN_L232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 414 | break; |
| 415 | case 10: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 416 | DecodeLow = DecoderTableSUBINSN_S132; |
| 417 | DecodeHigh = DecoderTableSUBINSN_S132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 418 | break; |
| 419 | case 11: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 420 | DecodeLow = DecoderTableSUBINSN_S232; |
| 421 | DecodeHigh = DecoderTableSUBINSN_S132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 422 | break; |
| 423 | case 12: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 424 | DecodeLow = DecoderTableSUBINSN_S232; |
| 425 | DecodeHigh = DecoderTableSUBINSN_L132; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 426 | break; |
| 427 | case 13: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 428 | DecodeLow = DecoderTableSUBINSN_S232; |
| 429 | DecodeHigh = DecoderTableSUBINSN_L232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 430 | break; |
| 431 | case 14: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 432 | DecodeLow = DecoderTableSUBINSN_S232; |
| 433 | DecodeHigh = DecoderTableSUBINSN_S232; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 434 | break; |
| 435 | } |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 436 | MI.setOpcode(Hexagon::DuplexIClass0 + duplexIClass); |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 437 | MCInst *MILow = new (getContext()) MCInst; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 438 | MCInst *MIHigh = new (getContext()) MCInst; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 439 | auto TmpExtender = CurrentExtender; |
| 440 | CurrentExtender = |
| 441 | nullptr; // constant extenders in duplex must always be in slot 1 |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 442 | Result = decodeInstruction(DecodeLow, *MILow, Instruction & 0x1fff, Address, |
| 443 | this, STI); |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 444 | CurrentExtender = TmpExtender; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 445 | if (Result != DecodeStatus::Success) |
| 446 | return DecodeStatus::Fail; |
| 447 | adjustDuplex(*MILow, getContext()); |
| 448 | Result = decodeInstruction( |
| 449 | DecodeHigh, *MIHigh, (Instruction >> 16) & 0x1fff, Address, this, STI); |
| 450 | if (Result != DecodeStatus::Success) |
| 451 | return DecodeStatus::Fail; |
| 452 | adjustDuplex(*MIHigh, getContext()); |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 453 | MCOperand OPLow = MCOperand::createInst(MILow); |
| 454 | MCOperand OPHigh = MCOperand::createInst(MIHigh); |
| 455 | MI.addOperand(OPLow); |
| 456 | MI.addOperand(OPHigh); |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 457 | Complete = true; |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 458 | } else { |
| 459 | if ((Instruction & HexagonII::INST_PARSE_MASK) == |
| 460 | HexagonII::INST_PARSE_PACKET_END) |
| 461 | Complete = true; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 462 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 463 | if (CurrentExtender != nullptr) |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 464 | Result = decodeInstruction(DecoderTableMustExtend32, MI, Instruction, |
| 465 | Address, this, STI); |
| 466 | |
| 467 | if (Result != MCDisassembler::Success) |
| 468 | Result = decodeInstruction(DecoderTable32, MI, Instruction, Address, this, |
| 469 | STI); |
| 470 | |
| 471 | if (Result != MCDisassembler::Success && |
| 472 | STI.getFeatureBits()[Hexagon::ExtensionHVX]) |
| 473 | Result = decodeInstruction(DecoderTableEXT_mmvec32, MI, Instruction, |
| 474 | Address, this, STI); |
| 475 | |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 476 | } |
Colin LeMahieu | 68d967d | 2015-05-29 14:44:13 +0000 | [diff] [blame] | 477 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 478 | switch (MI.getOpcode()) { |
Colin LeMahieu | 8170754 | 2016-12-05 04:29:00 +0000 | [diff] [blame] | 479 | case Hexagon::J4_cmpeqn1_f_jumpnv_nt: |
| 480 | case Hexagon::J4_cmpeqn1_f_jumpnv_t: |
| 481 | case Hexagon::J4_cmpeqn1_fp0_jump_nt: |
| 482 | case Hexagon::J4_cmpeqn1_fp0_jump_t: |
| 483 | case Hexagon::J4_cmpeqn1_fp1_jump_nt: |
| 484 | case Hexagon::J4_cmpeqn1_fp1_jump_t: |
| 485 | case Hexagon::J4_cmpeqn1_t_jumpnv_nt: |
| 486 | case Hexagon::J4_cmpeqn1_t_jumpnv_t: |
| 487 | case Hexagon::J4_cmpeqn1_tp0_jump_nt: |
| 488 | case Hexagon::J4_cmpeqn1_tp0_jump_t: |
| 489 | case Hexagon::J4_cmpeqn1_tp1_jump_nt: |
| 490 | case Hexagon::J4_cmpeqn1_tp1_jump_t: |
| 491 | case Hexagon::J4_cmpgtn1_f_jumpnv_nt: |
| 492 | case Hexagon::J4_cmpgtn1_f_jumpnv_t: |
| 493 | case Hexagon::J4_cmpgtn1_fp0_jump_nt: |
| 494 | case Hexagon::J4_cmpgtn1_fp0_jump_t: |
| 495 | case Hexagon::J4_cmpgtn1_fp1_jump_nt: |
| 496 | case Hexagon::J4_cmpgtn1_fp1_jump_t: |
| 497 | case Hexagon::J4_cmpgtn1_t_jumpnv_nt: |
| 498 | case Hexagon::J4_cmpgtn1_t_jumpnv_t: |
| 499 | case Hexagon::J4_cmpgtn1_tp0_jump_nt: |
| 500 | case Hexagon::J4_cmpgtn1_tp0_jump_t: |
| 501 | case Hexagon::J4_cmpgtn1_tp1_jump_nt: |
| 502 | case Hexagon::J4_cmpgtn1_tp1_jump_t: |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 503 | MI.insert(MI.begin() + 1, |
| 504 | MCOperand::createExpr(MCConstantExpr::create(-1, getContext()))); |
Colin LeMahieu | 8170754 | 2016-12-05 04:29:00 +0000 | [diff] [blame] | 505 | break; |
| 506 | default: |
| 507 | break; |
| 508 | } |
| 509 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 510 | if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) { |
| 511 | unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI); |
| 512 | MCOperand &MCO = MI.getOperand(OpIndex); |
| 513 | assert(MCO.isReg() && "New value consumers must be registers"); |
| 514 | unsigned Register = |
| 515 | getContext().getRegisterInfo()->getEncodingValue(MCO.getReg()); |
| 516 | if ((Register & 0x6) == 0) |
| 517 | // HexagonPRM 10.11 Bit 1-2 == 0 is reserved |
| 518 | return MCDisassembler::Fail; |
| 519 | unsigned Lookback = (Register & 0x6) >> 1; |
| 520 | unsigned Offset = 1; |
| 521 | bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI); |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 522 | bool PrevVector = false; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 523 | auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle); |
| 524 | auto i = Instructions.end() - 1; |
| 525 | for (auto n = Instructions.begin() - 1;; --i, ++Offset) { |
| 526 | if (i == n) |
| 527 | // Couldn't find producer |
| 528 | return MCDisassembler::Fail; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 529 | bool CurrentVector = HexagonMCInstrInfo::isVector(*MCII, *i->getInst()); |
| 530 | if (Vector && !CurrentVector) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 531 | // Skip scalars when calculating distances for vectors |
| 532 | ++Lookback; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 533 | if (HexagonMCInstrInfo::isImmext(*i->getInst()) && (Vector == PrevVector)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 534 | ++Lookback; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 535 | PrevVector = CurrentVector; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 536 | if (Offset == Lookback) |
| 537 | break; |
| 538 | } |
| 539 | auto const &Inst = *i->getInst(); |
| 540 | bool SubregBit = (Register & 0x1) != 0; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 541 | if (HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 542 | // If subreg bit is set we're selecting the second produced newvalue |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 543 | unsigned Producer = SubregBit ? |
| 544 | HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg() : |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 545 | HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg(); |
| 546 | assert(Producer != Hexagon::NoRegister); |
| 547 | MCO.setReg(Producer); |
| 548 | } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) { |
| 549 | unsigned Producer = |
| 550 | HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg(); |
| 551 | if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15) |
| 552 | Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0; |
| 553 | else if (SubregBit) |
Colin LeMahieu | 2d497a0 | 2016-03-01 22:05:03 +0000 | [diff] [blame] | 554 | // Hexagon PRM 10.11 New-value operands |
| 555 | // Nt[0] is reserved and should always be encoded as zero. |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 556 | return MCDisassembler::Fail; |
| 557 | assert(Producer != Hexagon::NoRegister); |
| 558 | MCO.setReg(Producer); |
| 559 | } else |
| 560 | return MCDisassembler::Fail; |
| 561 | } |
| 562 | |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 563 | if (CurrentExtender != nullptr) { |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 564 | MCInst const &Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) |
| 565 | ? *MI.getOperand(1).getInst() |
| 566 | : MI; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 567 | if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) && |
| 568 | !HexagonMCInstrInfo::isExtended(*MCII, Inst)) |
| 569 | return MCDisassembler::Fail; |
| 570 | } |
Colin LeMahieu | 5d6f03b | 2014-12-04 03:41:21 +0000 | [diff] [blame] | 571 | return Result; |
NAKAMURA Takumi | 729be14 | 2014-10-27 12:37:26 +0000 | [diff] [blame] | 572 | } |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 573 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 574 | static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo, |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 575 | ArrayRef<MCPhysReg> Table) { |
Craig Topper | 3da000c | 2015-12-01 06:13:04 +0000 | [diff] [blame] | 576 | if (RegNo < Table.size()) { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 577 | Inst.addOperand(MCOperand::createReg(Table[RegNo])); |
| 578 | return MCDisassembler::Success; |
Craig Topper | 3da000c | 2015-12-01 06:13:04 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | return MCDisassembler::Fail; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 584 | static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo, |
| 585 | uint64_t Address, |
| 586 | const void *Decoder) { |
| 587 | return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder); |
| 588 | } |
| 589 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 590 | static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 591 | uint64_t Address, |
| 592 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 593 | static const MCPhysReg IntRegDecoderTable[] = { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 594 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4, |
| 595 | Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9, |
| 596 | Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14, |
| 597 | Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, |
| 598 | Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24, |
| 599 | Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29, |
| 600 | Hexagon::R30, Hexagon::R31}; |
| 601 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 602 | return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 603 | } |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 604 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 605 | static DecodeStatus DecodeGeneralSubRegsRegisterClass(MCInst &Inst, |
| 606 | unsigned RegNo, |
| 607 | uint64_t Address, |
| 608 | const void *Decoder) { |
| 609 | static const MCPhysReg GeneralSubRegDecoderTable[] = { |
| 610 | Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, |
| 611 | Hexagon::R4, Hexagon::R5, Hexagon::R6, Hexagon::R7, |
| 612 | Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19, |
| 613 | Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, |
| 614 | }; |
| 615 | |
| 616 | return DecodeRegisterClass(Inst, RegNo, GeneralSubRegDecoderTable); |
| 617 | } |
| 618 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 619 | static DecodeStatus DecodeHvxVRRegisterClass(MCInst &Inst, unsigned RegNo, |
| 620 | uint64_t /*Address*/, |
| 621 | const void *Decoder) { |
| 622 | static const MCPhysReg HvxVRDecoderTable[] = { |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 623 | Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4, |
| 624 | Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9, |
| 625 | Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14, |
| 626 | Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19, |
| 627 | Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24, |
| 628 | Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29, |
| 629 | Hexagon::V30, Hexagon::V31}; |
| 630 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 631 | return DecodeRegisterClass(Inst, RegNo, HvxVRDecoderTable); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 634 | static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 635 | uint64_t /*Address*/, |
| 636 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 637 | static const MCPhysReg DoubleRegDecoderTable[] = { |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 638 | Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, |
| 639 | Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7, |
| 640 | Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11, |
| 641 | Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15}; |
| 642 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 643 | return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 646 | static DecodeStatus DecodeGeneralDoubleLow8RegsRegisterClass( |
| 647 | MCInst &Inst, unsigned RegNo, uint64_t /*Address*/, const void *Decoder) { |
| 648 | static const MCPhysReg GeneralDoubleLow8RegDecoderTable[] = { |
| 649 | Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3, |
| 650 | Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11}; |
| 651 | |
| 652 | return DecodeRegisterClass(Inst, RegNo, GeneralDoubleLow8RegDecoderTable); |
| 653 | } |
| 654 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 655 | static DecodeStatus DecodeHvxWRRegisterClass(MCInst &Inst, unsigned RegNo, |
| 656 | uint64_t /*Address*/, |
| 657 | const void *Decoder) { |
| 658 | static const MCPhysReg HvxWRDecoderTable[] = { |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 659 | Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3, |
| 660 | Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7, |
| 661 | Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11, |
| 662 | Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15}; |
| 663 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 664 | return (DecodeRegisterClass(Inst, RegNo >> 1, HvxWRDecoderTable)); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 667 | static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 668 | uint64_t /*Address*/, |
| 669 | const void *Decoder) { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 670 | static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1, |
| 671 | Hexagon::P2, Hexagon::P3}; |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 672 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 673 | return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 676 | static DecodeStatus DecodeHvxQRRegisterClass(MCInst &Inst, unsigned RegNo, |
| 677 | uint64_t /*Address*/, |
| 678 | const void *Decoder) { |
| 679 | static const MCPhysReg HvxQRDecoderTable[] = {Hexagon::Q0, Hexagon::Q1, |
| 680 | Hexagon::Q2, Hexagon::Q3}; |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 681 | |
Krzysztof Parzyszek | 5577297 | 2017-09-15 15:46:05 +0000 | [diff] [blame] | 682 | return DecodeRegisterClass(Inst, RegNo, HvxQRDecoderTable); |
Colin LeMahieu | 7c95871 | 2015-10-17 01:33:04 +0000 | [diff] [blame] | 683 | } |
Colin LeMahieu | be8c453 | 2015-06-05 16:00:11 +0000 | [diff] [blame] | 684 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 685 | static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 686 | uint64_t /*Address*/, |
| 687 | const void *Decoder) { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 688 | using namespace Hexagon; |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 689 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 690 | static const MCPhysReg CtrlRegDecoderTable[] = { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 691 | /* 0 */ SA0, LC0, SA1, LC1, |
Krzysztof Parzyszek | e260332 | 2017-05-05 22:12:12 +0000 | [diff] [blame] | 692 | /* 4 */ P3_0, C5, M0, M1, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 693 | /* 8 */ USR, PC, UGP, GP, |
Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 694 | /* 12 */ CS0, CS1, UPCYCLELO, UPCYCLEHI, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 695 | /* 16 */ FRAMELIMIT, FRAMEKEY, PKTCOUNTLO, PKTCOUNTHI, |
| 696 | /* 20 */ 0, 0, 0, 0, |
| 697 | /* 24 */ 0, 0, 0, 0, |
| 698 | /* 28 */ 0, 0, UTIMERLO, UTIMERHI |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 699 | }; |
| 700 | |
Craig Topper | 6261e1b | 2015-12-01 06:13:06 +0000 | [diff] [blame] | 701 | if (RegNo >= array_lengthof(CtrlRegDecoderTable)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 702 | return MCDisassembler::Fail; |
| 703 | |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 704 | static_assert(NoRegister == 0, "Expecting NoRegister to be 0"); |
| 705 | if (CtrlRegDecoderTable[RegNo] == NoRegister) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 706 | return MCDisassembler::Fail; |
| 707 | |
| 708 | unsigned Register = CtrlRegDecoderTable[RegNo]; |
| 709 | Inst.addOperand(MCOperand::createReg(Register)); |
| 710 | return MCDisassembler::Success; |
| 711 | } |
| 712 | |
| 713 | static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo, |
| 714 | uint64_t /*Address*/, |
| 715 | const void *Decoder) { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 716 | using namespace Hexagon; |
Eugene Zelenko | e4fc6ee | 2017-07-26 23:20:35 +0000 | [diff] [blame] | 717 | |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 718 | static const MCPhysReg CtrlReg64DecoderTable[] = { |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 719 | /* 0 */ C1_0, 0, C3_2, 0, |
| 720 | /* 4 */ C5_4, 0, C7_6, 0, |
| 721 | /* 8 */ C9_8, 0, C11_10, 0, |
Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 722 | /* 12 */ CS, 0, UPCYCLE, 0, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 723 | /* 16 */ C17_16, 0, PKTCOUNT, 0, |
| 724 | /* 20 */ 0, 0, 0, 0, |
| 725 | /* 24 */ 0, 0, 0, 0, |
| 726 | /* 28 */ 0, 0, UTIMER, 0 |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 727 | }; |
| 728 | |
Craig Topper | 6261e1b | 2015-12-01 06:13:06 +0000 | [diff] [blame] | 729 | if (RegNo >= array_lengthof(CtrlReg64DecoderTable)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 730 | return MCDisassembler::Fail; |
| 731 | |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 732 | static_assert(NoRegister == 0, "Expecting NoRegister to be 0"); |
| 733 | if (CtrlReg64DecoderTable[RegNo] == NoRegister) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 734 | return MCDisassembler::Fail; |
| 735 | |
| 736 | unsigned Register = CtrlReg64DecoderTable[RegNo]; |
| 737 | Inst.addOperand(MCOperand::createReg(Register)); |
| 738 | return MCDisassembler::Success; |
| 739 | } |
| 740 | |
| 741 | static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 742 | uint64_t /*Address*/, |
| 743 | const void *Decoder) { |
| 744 | unsigned Register = 0; |
| 745 | switch (RegNo) { |
| 746 | case 0: |
| 747 | Register = Hexagon::M0; |
| 748 | break; |
| 749 | case 1: |
| 750 | Register = Hexagon::M1; |
| 751 | break; |
| 752 | default: |
| 753 | return MCDisassembler::Fail; |
| 754 | } |
| 755 | Inst.addOperand(MCOperand::createReg(Register)); |
| 756 | return MCDisassembler::Success; |
| 757 | } |
| 758 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 759 | static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp, |
| 760 | uint64_t /*Address*/, |
| 761 | const void *Decoder) { |
| 762 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 763 | int64_t FullValue = fullValue(Disassembler, MI, tmp); |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 764 | assert(FullValue >= 0 && "Negative in unsigned decoder"); |
| 765 | HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext()); |
| 766 | return MCDisassembler::Success; |
| 767 | } |
| 768 | |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 769 | static DecodeStatus s32_0ImmDecoder(MCInst &MI, unsigned tmp, |
| 770 | uint64_t /*Address*/, const void *Decoder) { |
| 771 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
| 772 | unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); |
| 773 | tmp = SignExtend64(tmp, Bits); |
| 774 | signedDecoder<32>(MI, tmp, Decoder); |
| 775 | return MCDisassembler::Success; |
| 776 | } |
| 777 | |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 778 | // custom decoder for various jump/call immediates |
| 779 | static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address, |
| 780 | const void *Decoder) { |
| 781 | HexagonDisassembler const &Disassembler = disassembler(Decoder); |
| 782 | unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI); |
| 783 | // r13_2 is not extendable, so if there are no extent bits, it's r13_2 |
| 784 | if (Bits == 0) |
| 785 | Bits = 15; |
Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 786 | uint64_t FullValue = fullValue(Disassembler, MI, SignExtend64(tmp, Bits)); |
| 787 | uint32_t Extended = FullValue + Address; |
Krzysztof Parzyszek | a72fad9 | 2017-02-10 15:33:13 +0000 | [diff] [blame] | 788 | if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true, 0, 4)) |
Colin LeMahieu | 7cd0892 | 2015-11-09 04:07:48 +0000 | [diff] [blame] | 789 | HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext()); |
| 790 | return MCDisassembler::Success; |
| 791 | } |
Krzysztof Parzyszek | 22a21d4 | 2018-03-01 17:03:26 +0000 | [diff] [blame^] | 792 | |
| 793 | static DecodeStatus DecodeGuestRegsRegisterClass(MCInst &Inst, unsigned RegNo, |
| 794 | uint64_t /*Address*/, |
| 795 | const void *Decoder) { |
| 796 | using namespace Hexagon; |
| 797 | |
| 798 | static const MCPhysReg GuestRegDecoderTable[] = { |
| 799 | /* 0 */ GELR, GSR, GOSP, G3, |
| 800 | /* 4 */ G4, G5, G6, G7, |
| 801 | /* 8 */ G8, G9, G10, G11, |
| 802 | /* 12 */ G12, G13, G14, G15, |
| 803 | /* 16 */ GPMUCNT4, GPMUCNT5, GPMUCNT6, GPMUCNT7, |
| 804 | /* 20 */ G20, G21, G22, G23, |
| 805 | /* 24 */ GPCYCLELO, GPCYCLEHI, GPMUCNT0, GPMUCNT1, |
| 806 | /* 28 */ GPMUCNT2, GPMUCNT3, G30, G31 |
| 807 | }; |
| 808 | |
| 809 | if (RegNo >= array_lengthof(GuestRegDecoderTable)) |
| 810 | return MCDisassembler::Fail; |
| 811 | if (GuestRegDecoderTable[RegNo] == Hexagon::NoRegister) |
| 812 | return MCDisassembler::Fail; |
| 813 | |
| 814 | unsigned Register = GuestRegDecoderTable[RegNo]; |
| 815 | Inst.addOperand(MCOperand::createReg(Register)); |
| 816 | return MCDisassembler::Success; |
| 817 | } |
| 818 | |
| 819 | static DecodeStatus DecodeGuestRegs64RegisterClass(MCInst &Inst, unsigned RegNo, |
| 820 | uint64_t /*Address*/, |
| 821 | const void *Decoder) { |
| 822 | using namespace Hexagon; |
| 823 | |
| 824 | static const MCPhysReg GuestReg64DecoderTable[] = { |
| 825 | /* 0 */ G1_0, 0, G3_2, 0, |
| 826 | /* 4 */ G5_4, 0, G7_6, 0, |
| 827 | /* 8 */ G9_8, 0, G11_10, 0, |
| 828 | /* 12 */ G13_12, 0, G15_14, 0, |
| 829 | /* 16 */ G17_16, 0, G19_18, 0, |
| 830 | /* 20 */ G21_20, 0, G23_22, 0, |
| 831 | /* 24 */ G25_24, 0, G27_26, 0, |
| 832 | /* 28 */ G29_28, 0, G31_30, 0 |
| 833 | }; |
| 834 | |
| 835 | if (RegNo >= array_lengthof(GuestReg64DecoderTable)) |
| 836 | return MCDisassembler::Fail; |
| 837 | if (GuestReg64DecoderTable[RegNo] == Hexagon::NoRegister) |
| 838 | return MCDisassembler::Fail; |
| 839 | |
| 840 | unsigned Register = GuestReg64DecoderTable[RegNo]; |
| 841 | Inst.addOperand(MCOperand::createReg(Register)); |
| 842 | return MCDisassembler::Success; |
| 843 | } |