blob: 92c20365fe04a3687ab6bbda7e85460302d203cf [file] [log] [blame]
NAKAMURA Takumi729be142014-10-27 12:37:26 +00001//===-- 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 LeMahieu7cd08922015-11-09 04:07:48 +000010#define DEBUG_TYPE "hexagon-disassembler"
11
Colin LeMahieu68d967d2015-05-29 14:44:13 +000012#include "Hexagon.h"
NAKAMURA Takumi729be142014-10-27 12:37:26 +000013#include "MCTargetDesc/HexagonBaseInfo.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000014#include "MCTargetDesc/HexagonMCChecker.h"
NAKAMURA Takumi729be142014-10-27 12:37:26 +000015#include "MCTargetDesc/HexagonMCTargetDesc.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000016#include "MCTargetDesc/HexagonMCInstrInfo.h"
17#include "MCTargetDesc/HexagonInstPrinter.h"
18#include "llvm/ADT/StringExtras.h"
Benjamin Kramerf57c1972016-01-26 16:44:37 +000019#include "llvm/MC/MCDisassembler/MCDisassembler.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000020#include "llvm/MC/MCContext.h"
NAKAMURA Takumi729be142014-10-27 12:37:26 +000021#include "llvm/MC/MCExpr.h"
22#include "llvm/MC/MCFixedLenDisassembler.h"
23#include "llvm/MC/MCInst.h"
24#include "llvm/MC/MCInstrDesc.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000025#include "llvm/MC/MCInstrInfo.h"
NAKAMURA Takumi729be142014-10-27 12:37:26 +000026#include "llvm/MC/MCSubtargetInfo.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/ErrorHandling.h"
29#include "llvm/Support/LEB128.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000030#include "llvm/Support/raw_ostream.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000031#include "llvm/Support/TargetRegistry.h"
NAKAMURA Takumi729be142014-10-27 12:37:26 +000032
33using namespace llvm;
Colin LeMahieu68d967d2015-05-29 14:44:13 +000034using namespace Hexagon;
NAKAMURA Takumi729be142014-10-27 12:37:26 +000035
Colin LeMahieu7cd08922015-11-09 04:07:48 +000036typedef MCDisassembler::DecodeStatus DecodeStatus;
NAKAMURA Takumi729be142014-10-27 12:37:26 +000037
38namespace {
39/// \brief Hexagon disassembler for all Hexagon platforms.
40class HexagonDisassembler : public MCDisassembler {
41public:
Colin LeMahieu7cd08922015-11-09 04:07:48 +000042 std::unique_ptr<MCInstrInfo const> const MCII;
Colin LeMahieu68d967d2015-05-29 14:44:13 +000043 std::unique_ptr<MCInst *> CurrentBundle;
Colin LeMahieu7cd08922015-11-09 04:07:48 +000044 HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
45 MCInstrInfo const *MCII)
46 : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *) {}
NAKAMURA Takumi729be142014-10-27 12:37:26 +000047
Colin LeMahieu68d967d2015-05-29 14:44:13 +000048 DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB,
49 ArrayRef<uint8_t> Bytes, uint64_t Address,
50 raw_ostream &VStream, raw_ostream &CStream,
51 bool &Complete) const;
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000052 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +000053 ArrayRef<uint8_t> Bytes, uint64_t Address,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000054 raw_ostream &VStream,
55 raw_ostream &CStream) const override;
Colin LeMahieu7cd08922015-11-09 04:07:48 +000056
57 void adjustExtendedInstructions(MCInst &MCI, MCInst const &MCB) const;
58 void addSubinstOperands(MCInst *MI, unsigned opcode, unsigned inst) const;
NAKAMURA Takumi729be142014-10-27 12:37:26 +000059};
Alexander Kornienkof00654e2015-06-23 09:49:53 +000060}
NAKAMURA Takumi729be142014-10-27 12:37:26 +000061
Colin LeMahieu7cd08922015-11-09 04:07:48 +000062// Forward declare these because the auto-generated code will reference them.
63// Definitions are further down.
64
65static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
Colin LeMahieube8c4532015-06-05 16:00:11 +000066 uint64_t Address,
67 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +000068static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo,
69 uint64_t Address,
70 const void *Decoder);
71static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo,
72 uint64_t Address,
73 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000074static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo,
75 uint64_t Address,
76 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +000077static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo,
78 uint64_t Address,
79 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000080static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
81 uint64_t Address,
82 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +000083static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
84 uint64_t Address,
85 const void *Decoder);
Colin LeMahieuf3db8842014-12-19 19:06:32 +000086static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
Colin LeMahieube8c4532015-06-05 16:00:11 +000087 uint64_t Address,
88 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000089static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
90 uint64_t Address,
91 const void *Decoder);
Colin LeMahieu404d5b22015-02-10 16:59:36 +000092static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
Colin LeMahieube8c4532015-06-05 16:00:11 +000093 uint64_t Address,
Colin LeMahieu7cd08922015-11-09 04:07:48 +000094 const void *Decoder);
95
96static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn);
97static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn,
98 void const *Decoder);
Colin LeMahieube8c4532015-06-05 16:00:11 +000099
100static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op,
101 raw_ostream &os);
Colin LeMahieuf3db8842014-12-19 19:06:32 +0000102
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000103static unsigned getRegFromSubinstEncoding(unsigned encoded_reg);
104
105static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
106 uint64_t Address, const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000107static DecodeStatus s16_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000108 const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000109static DecodeStatus s12_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000110 const void *Decoder);
111static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
112 const void *Decoder);
113static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
114 const void *Decoder);
115static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
116 const void *Decoder);
117static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
118 const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000119static DecodeStatus s10_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000120 const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000121static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000122 const void *Decoder);
123static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
124 const void *Decoder);
125static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
126 const void *Decoder);
127static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
128 const void *Decoder);
129static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
130 const void *Decoder);
131static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
132 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000133static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
134 const void *Decoder);
135static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
136 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000137static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
138 const void *Decoder);
Colin LeMahieuefa74e02014-11-18 20:28:11 +0000139
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000140#include "HexagonGenDisassemblerTables.inc"
141
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000142static MCDisassembler *createHexagonDisassembler(const Target &T,
143 const MCSubtargetInfo &STI,
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000144 MCContext &Ctx) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000145 return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo());
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000146}
147
148extern "C" void LLVMInitializeHexagonDisassembler() {
Mehdi Aminif42454b2016-10-09 23:00:34 +0000149 TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(),
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000150 createHexagonDisassembler);
151}
152
153DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000154 ArrayRef<uint8_t> Bytes,
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000155 uint64_t Address,
156 raw_ostream &os,
157 raw_ostream &cs) const {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000158 DecodeStatus Result = DecodeStatus::Success;
159 bool Complete = false;
160 Size = 0;
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000161
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000162 *CurrentBundle = &MI;
Colin LeMahieuf0af6e52015-11-13 17:42:46 +0000163 MI = HexagonMCInstrInfo::createBundle();
Colin LeMahieube8c4532015-06-05 16:00:11 +0000164 while (Result == Success && Complete == false) {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000165 if (Bytes.size() < HEXAGON_INSTR_SIZE)
166 return MCDisassembler::Fail;
Colin LeMahieube8c4532015-06-05 16:00:11 +0000167 MCInst *Inst = new (getContext()) MCInst;
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000168 Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete);
169 MI.addOperand(MCOperand::createInst(Inst));
170 Size += HEXAGON_INSTR_SIZE;
171 Bytes = Bytes.slice(HEXAGON_INSTR_SIZE);
172 }
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000173 if(Result == MCDisassembler::Fail)
174 return Result;
175 HexagonMCChecker Checker (*MCII, STI, MI, MI, *getContext().getRegisterInfo());
176 if(!Checker.check())
177 return MCDisassembler::Fail;
178 return MCDisassembler::Success;
179}
180
181namespace {
182HexagonDisassembler const &disassembler(void const *Decoder) {
183 return *static_cast<HexagonDisassembler const *>(Decoder);
184}
185MCContext &contextFromDecoder(void const *Decoder) {
186 return disassembler(Decoder).getContext();
187}
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000188}
189
190DecodeStatus HexagonDisassembler::getSingleInstruction(
191 MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address,
192 raw_ostream &os, raw_ostream &cs, bool &Complete) const {
193 assert(Bytes.size() >= HEXAGON_INSTR_SIZE);
194
195 uint32_t Instruction =
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000196 (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0);
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000197
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000198 auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB);
199 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
200 HexagonII::INST_PARSE_LOOP_END) {
201 if (BundleSize == 0)
202 HexagonMCInstrInfo::setInnerLoop(MCB);
203 else if (BundleSize == 1)
204 HexagonMCInstrInfo::setOuterLoop(MCB);
205 else
206 return DecodeStatus::Fail;
207 }
208
209 DecodeStatus Result = DecodeStatus::Success;
210 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
Colin LeMahieube8c4532015-06-05 16:00:11 +0000211 HexagonII::INST_PARSE_DUPLEX) {
212 // Determine the instruction class of each instruction in the duplex.
213 unsigned duplexIClass, IClassLow, IClassHigh;
214
215 duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1);
216 switch (duplexIClass) {
217 default:
218 return MCDisassembler::Fail;
219 case 0:
220 IClassLow = HexagonII::HSIG_L1;
221 IClassHigh = HexagonII::HSIG_L1;
222 break;
223 case 1:
224 IClassLow = HexagonII::HSIG_L2;
225 IClassHigh = HexagonII::HSIG_L1;
226 break;
227 case 2:
228 IClassLow = HexagonII::HSIG_L2;
229 IClassHigh = HexagonII::HSIG_L2;
230 break;
231 case 3:
232 IClassLow = HexagonII::HSIG_A;
233 IClassHigh = HexagonII::HSIG_A;
234 break;
235 case 4:
236 IClassLow = HexagonII::HSIG_L1;
237 IClassHigh = HexagonII::HSIG_A;
238 break;
239 case 5:
240 IClassLow = HexagonII::HSIG_L2;
241 IClassHigh = HexagonII::HSIG_A;
242 break;
243 case 6:
244 IClassLow = HexagonII::HSIG_S1;
245 IClassHigh = HexagonII::HSIG_A;
246 break;
247 case 7:
248 IClassLow = HexagonII::HSIG_S2;
249 IClassHigh = HexagonII::HSIG_A;
250 break;
251 case 8:
252 IClassLow = HexagonII::HSIG_S1;
253 IClassHigh = HexagonII::HSIG_L1;
254 break;
255 case 9:
256 IClassLow = HexagonII::HSIG_S1;
257 IClassHigh = HexagonII::HSIG_L2;
258 break;
259 case 10:
260 IClassLow = HexagonII::HSIG_S1;
261 IClassHigh = HexagonII::HSIG_S1;
262 break;
263 case 11:
264 IClassLow = HexagonII::HSIG_S2;
265 IClassHigh = HexagonII::HSIG_S1;
266 break;
267 case 12:
268 IClassLow = HexagonII::HSIG_S2;
269 IClassHigh = HexagonII::HSIG_L1;
270 break;
271 case 13:
272 IClassLow = HexagonII::HSIG_S2;
273 IClassHigh = HexagonII::HSIG_L2;
274 break;
275 case 14:
276 IClassLow = HexagonII::HSIG_S2;
277 IClassHigh = HexagonII::HSIG_S2;
278 break;
279 }
280
281 // Set the MCInst to be a duplex instruction. Which one doesn't matter.
282 MI.setOpcode(Hexagon::DuplexIClass0);
283
284 // Decode each instruction in the duplex.
285 // Create an MCInst for each instruction.
286 unsigned instLow = Instruction & 0x1fff;
287 unsigned instHigh = (Instruction >> 16) & 0x1fff;
288 unsigned opLow;
289 if (GetSubinstOpcode(IClassLow, instLow, opLow, os) !=
290 MCDisassembler::Success)
291 return MCDisassembler::Fail;
292 unsigned opHigh;
293 if (GetSubinstOpcode(IClassHigh, instHigh, opHigh, os) !=
294 MCDisassembler::Success)
295 return MCDisassembler::Fail;
296 MCInst *MILow = new (getContext()) MCInst;
297 MILow->setOpcode(opLow);
298 MCInst *MIHigh = new (getContext()) MCInst;
299 MIHigh->setOpcode(opHigh);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000300 addSubinstOperands(MILow, opLow, instLow);
301 addSubinstOperands(MIHigh, opHigh, instHigh);
Colin LeMahieube8c4532015-06-05 16:00:11 +0000302 // see ConvertToSubInst() in
303 // lib/Target/Hexagon/MCTargetDesc/HexagonMCDuplexInfo.cpp
304
305 // Add the duplex instruction MCInsts as operands to the passed in MCInst.
306 MCOperand OPLow = MCOperand::createInst(MILow);
307 MCOperand OPHigh = MCOperand::createInst(MIHigh);
308 MI.addOperand(OPLow);
309 MI.addOperand(OPHigh);
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000310 Complete = true;
Colin LeMahieube8c4532015-06-05 16:00:11 +0000311 } else {
312 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
313 HexagonII::INST_PARSE_PACKET_END)
314 Complete = true;
315 // Calling the auto-generated decoder function.
316 Result =
317 decodeInstruction(DecoderTable32, MI, Instruction, Address, this, STI);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000318
319 // If a, "standard" insn isn't found check special cases.
320 if (MCDisassembler::Success != Result ||
321 MI.getOpcode() == Hexagon::A4_ext) {
322 Result = decodeImmext(MI, Instruction, this);
323 if (MCDisassembler::Success != Result) {
324 Result = decodeSpecial(MI, Instruction);
325 }
326 } else {
327 // If the instruction is a compound instruction, register values will
328 // follow the duplex model, so the register values in the MCInst are
329 // incorrect. If the instruction is a compound, loop through the
330 // operands and change registers appropriately.
331 if (llvm::HexagonMCInstrInfo::getType(*MCII, MI) ==
332 HexagonII::TypeCOMPOUND) {
333 for (MCInst::iterator i = MI.begin(), last = MI.end(); i < last; ++i) {
334 if (i->isReg()) {
335 unsigned reg = i->getReg() - Hexagon::R0;
336 i->setReg(getRegFromSubinstEncoding(reg));
337 }
338 }
339 }
340 }
Colin LeMahieube8c4532015-06-05 16:00:11 +0000341 }
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000342
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000343 if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) {
344 unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI);
345 MCOperand &MCO = MI.getOperand(OpIndex);
346 assert(MCO.isReg() && "New value consumers must be registers");
347 unsigned Register =
348 getContext().getRegisterInfo()->getEncodingValue(MCO.getReg());
349 if ((Register & 0x6) == 0)
350 // HexagonPRM 10.11 Bit 1-2 == 0 is reserved
351 return MCDisassembler::Fail;
352 unsigned Lookback = (Register & 0x6) >> 1;
353 unsigned Offset = 1;
354 bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI);
355 auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle);
356 auto i = Instructions.end() - 1;
357 for (auto n = Instructions.begin() - 1;; --i, ++Offset) {
358 if (i == n)
359 // Couldn't find producer
360 return MCDisassembler::Fail;
361 if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst()))
362 // Skip scalars when calculating distances for vectors
363 ++Lookback;
364 if (HexagonMCInstrInfo::isImmext(*i->getInst()))
365 ++Lookback;
366 if (Offset == Lookback)
367 break;
368 }
369 auto const &Inst = *i->getInst();
370 bool SubregBit = (Register & 0x1) != 0;
371 if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) {
372 // If subreg bit is set we're selecting the second produced newvalue
373 unsigned Producer =
374 HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg();
375 assert(Producer != Hexagon::NoRegister);
376 MCO.setReg(Producer);
377 } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) {
378 unsigned Producer =
379 HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg();
380 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
381 Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0;
382 else if (SubregBit)
Colin LeMahieu2d497a02016-03-01 22:05:03 +0000383 // Hexagon PRM 10.11 New-value operands
384 // Nt[0] is reserved and should always be encoded as zero.
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000385 return MCDisassembler::Fail;
386 assert(Producer != Hexagon::NoRegister);
387 MCO.setReg(Producer);
388 } else
389 return MCDisassembler::Fail;
390 }
391
392 adjustExtendedInstructions(MI, MCB);
393 MCInst const *Extender =
394 HexagonMCInstrInfo::extenderForIndex(MCB,
395 HexagonMCInstrInfo::bundleSize(MCB));
396 if(Extender != nullptr) {
397 MCInst const & Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) ?
398 *MI.getOperand(1).getInst() : MI;
399 if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) &&
400 !HexagonMCInstrInfo::isExtended(*MCII, Inst))
401 return MCDisassembler::Fail;
402 }
Colin LeMahieu5d6f03b2014-12-04 03:41:21 +0000403 return Result;
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000404}
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000405
406void HexagonDisassembler::adjustExtendedInstructions(MCInst &MCI,
407 MCInst const &MCB) const {
408 if (!HexagonMCInstrInfo::hasExtenderForIndex(
409 MCB, HexagonMCInstrInfo::bundleSize(MCB))) {
410 unsigned opcode;
411 // This code is used by the disassembler to disambiguate between GP
412 // relative and absolute addressing instructions since they both have
413 // same encoding bits. However, an absolute addressing instruction must
414 // follow an immediate extender. Disassembler alwaus select absolute
415 // addressing instructions first and uses this code to change them into
416 // GP relative instruction in the absence of the corresponding immediate
417 // extender.
418 switch (MCI.getOpcode()) {
Colin LeMahieu9675de52016-10-06 23:02:11 +0000419 case Hexagon::PS_storerbabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000420 opcode = Hexagon::S2_storerbgp;
421 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000422 case Hexagon::PS_storerhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000423 opcode = Hexagon::S2_storerhgp;
424 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000425 case Hexagon::PS_storerfabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000426 opcode = Hexagon::S2_storerfgp;
427 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000428 case Hexagon::PS_storeriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000429 opcode = Hexagon::S2_storerigp;
430 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000431 case Hexagon::PS_storerbnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000432 opcode = Hexagon::S2_storerbnewgp;
433 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000434 case Hexagon::PS_storerhnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000435 opcode = Hexagon::S2_storerhnewgp;
436 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000437 case Hexagon::PS_storerinewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000438 opcode = Hexagon::S2_storerinewgp;
439 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000440 case Hexagon::PS_storerdabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000441 opcode = Hexagon::S2_storerdgp;
442 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000443 case Hexagon::PS_loadrbabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000444 opcode = Hexagon::L2_loadrbgp;
445 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000446 case Hexagon::PS_loadrubabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000447 opcode = Hexagon::L2_loadrubgp;
448 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000449 case Hexagon::PS_loadrhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000450 opcode = Hexagon::L2_loadrhgp;
451 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000452 case Hexagon::PS_loadruhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000453 opcode = Hexagon::L2_loadruhgp;
454 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000455 case Hexagon::PS_loadriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000456 opcode = Hexagon::L2_loadrigp;
457 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000458 case Hexagon::PS_loadrdabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000459 opcode = Hexagon::L2_loadrdgp;
460 break;
461 default:
462 opcode = MCI.getOpcode();
463 }
464 MCI.setOpcode(opcode);
465 }
466}
467
468namespace llvm {
469extern const MCInstrDesc HexagonInsts[];
470}
471
472static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
Craig Toppere5e035a32015-12-05 07:13:35 +0000473 ArrayRef<MCPhysReg> Table) {
Craig Topper3da000c2015-12-01 06:13:04 +0000474 if (RegNo < Table.size()) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000475 Inst.addOperand(MCOperand::createReg(Table[RegNo]));
476 return MCDisassembler::Success;
Craig Topper3da000c2015-12-01 06:13:04 +0000477 }
478
479 return MCDisassembler::Fail;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000480}
481
Colin LeMahieu7c958712015-10-17 01:33:04 +0000482static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo,
483 uint64_t Address,
484 const void *Decoder) {
485 return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
486}
487
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000488static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
489 uint64_t Address,
490 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000491 static const MCPhysReg IntRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000492 Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
493 Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
494 Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
495 Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
496 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
497 Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
498 Hexagon::R30, Hexagon::R31};
499
Craig Toppere5e035a32015-12-05 07:13:35 +0000500 return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000501}
Colin LeMahieu7c958712015-10-17 01:33:04 +0000502
503static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo,
504 uint64_t /*Address*/,
505 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000506 static const MCPhysReg VecRegDecoderTable[] = {
Colin LeMahieu7c958712015-10-17 01:33:04 +0000507 Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4,
508 Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
509 Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
510 Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
511 Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
512 Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
513 Hexagon::V30, Hexagon::V31};
514
Craig Toppere5e035a32015-12-05 07:13:35 +0000515 return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000516}
517
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000518static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo,
519 uint64_t /*Address*/,
520 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000521 static const MCPhysReg DoubleRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000522 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
523 Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
524 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
525 Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
526
Craig Toppere5e035a32015-12-05 07:13:35 +0000527 return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000528}
529
Colin LeMahieu7c958712015-10-17 01:33:04 +0000530static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo,
531 uint64_t /*Address*/,
532 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000533 static const MCPhysReg VecDblRegDecoderTable[] = {
Colin LeMahieu7c958712015-10-17 01:33:04 +0000534 Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3,
535 Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7,
536 Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11,
537 Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15};
538
Craig Topper3da000c2015-12-01 06:13:04 +0000539 return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable));
Colin LeMahieu7c958712015-10-17 01:33:04 +0000540}
541
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000542static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
543 uint64_t /*Address*/,
544 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000545 static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
546 Hexagon::P2, Hexagon::P3};
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000547
Craig Toppere5e035a32015-12-05 07:13:35 +0000548 return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000549}
550
Colin LeMahieu7c958712015-10-17 01:33:04 +0000551static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
552 uint64_t /*Address*/,
553 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000554 static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
555 Hexagon::Q2, Hexagon::Q3};
Colin LeMahieu7c958712015-10-17 01:33:04 +0000556
Craig Toppere5e035a32015-12-05 07:13:35 +0000557 return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000558}
Colin LeMahieube8c4532015-06-05 16:00:11 +0000559
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000560static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
561 uint64_t /*Address*/,
562 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000563 static const MCPhysReg CtrlRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000564 Hexagon::SA0, Hexagon::LC0, Hexagon::SA1, Hexagon::LC1,
565 Hexagon::P3_0, Hexagon::C5, Hexagon::C6, Hexagon::C7,
566 Hexagon::USR, Hexagon::PC, Hexagon::UGP, Hexagon::GP,
567 Hexagon::CS0, Hexagon::CS1, Hexagon::UPCL, Hexagon::UPC
568 };
569
Craig Topper6261e1b2015-12-01 06:13:06 +0000570 if (RegNo >= array_lengthof(CtrlRegDecoderTable))
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000571 return MCDisassembler::Fail;
572
573 if (CtrlRegDecoderTable[RegNo] == Hexagon::NoRegister)
574 return MCDisassembler::Fail;
575
576 unsigned Register = CtrlRegDecoderTable[RegNo];
577 Inst.addOperand(MCOperand::createReg(Register));
578 return MCDisassembler::Success;
579}
580
581static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
582 uint64_t /*Address*/,
583 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000584 static const MCPhysReg CtrlReg64DecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000585 Hexagon::C1_0, Hexagon::NoRegister,
586 Hexagon::C3_2, Hexagon::NoRegister,
587 Hexagon::C7_6, Hexagon::NoRegister,
588 Hexagon::C9_8, Hexagon::NoRegister,
589 Hexagon::C11_10, Hexagon::NoRegister,
590 Hexagon::CS, Hexagon::NoRegister,
591 Hexagon::UPC, Hexagon::NoRegister
592 };
593
Craig Topper6261e1b2015-12-01 06:13:06 +0000594 if (RegNo >= array_lengthof(CtrlReg64DecoderTable))
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000595 return MCDisassembler::Fail;
596
597 if (CtrlReg64DecoderTable[RegNo] == Hexagon::NoRegister)
598 return MCDisassembler::Fail;
599
600 unsigned Register = CtrlReg64DecoderTable[RegNo];
601 Inst.addOperand(MCOperand::createReg(Register));
602 return MCDisassembler::Success;
603}
604
605static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
606 uint64_t /*Address*/,
607 const void *Decoder) {
608 unsigned Register = 0;
609 switch (RegNo) {
610 case 0:
611 Register = Hexagon::M0;
612 break;
613 case 1:
614 Register = Hexagon::M1;
615 break;
616 default:
617 return MCDisassembler::Fail;
618 }
619 Inst.addOperand(MCOperand::createReg(Register));
620 return MCDisassembler::Success;
621}
622
623namespace {
624uint32_t fullValue(MCInstrInfo const &MCII,
625 MCInst &MCB,
626 MCInst &MI,
627 int64_t Value) {
628 MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex(
629 MCB, HexagonMCInstrInfo::bundleSize(MCB));
630 if(!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI))
631 return Value;
632 unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI);
633 uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f;
634 int64_t Bits;
635 bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits);
636 assert(Success);(void)Success;
637 uint32_t Upper26 = static_cast<uint32_t>(Bits);
638 uint32_t Operand = Upper26 | Lower6;
639 return Operand;
640}
641template <size_t T>
642void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) {
643 HexagonDisassembler const &Disassembler = disassembler(Decoder);
644 int64_t FullValue = fullValue(*Disassembler.MCII,
645 **Disassembler.CurrentBundle,
646 MI, SignExtend64<T>(tmp));
647 int64_t Extended = SignExtend64<32>(FullValue);
648 HexagonMCInstrInfo::addConstant(MI, Extended,
649 Disassembler.getContext());
650}
651}
652
653static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
654 uint64_t /*Address*/,
655 const void *Decoder) {
656 HexagonDisassembler const &Disassembler = disassembler(Decoder);
657 int64_t FullValue = fullValue(*Disassembler.MCII,
658 **Disassembler.CurrentBundle,
659 MI, tmp);
660 assert(FullValue >= 0 && "Negative in unsigned decoder");
661 HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext());
662 return MCDisassembler::Success;
663}
664
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000665static DecodeStatus s16_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000666 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000667 signedDecoder<16>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000668 return MCDisassembler::Success;
669}
670
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000671static DecodeStatus s12_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000672 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000673 signedDecoder<12>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000674 return MCDisassembler::Success;
675}
676
677static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp,
678 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000679 signedDecoder<11>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000680 return MCDisassembler::Success;
681}
682
683static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp,
684 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000685 HexagonMCInstrInfo::addConstant(MI, SignExtend64<12>(tmp), contextFromDecoder(Decoder));
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000686 return MCDisassembler::Success;
687}
688
689static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp,
690 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000691 signedDecoder<13>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000692 return MCDisassembler::Success;
693}
694
695static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp,
696 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000697 signedDecoder<14>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000698 return MCDisassembler::Success;
699}
700
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000701static DecodeStatus s10_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000702 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000703 signedDecoder<10>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000704 return MCDisassembler::Success;
705}
706
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000707static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t /*Address*/,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000708 const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000709 signedDecoder<8>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000710 return MCDisassembler::Success;
711}
712
713static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp,
714 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000715 signedDecoder<6>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000716 return MCDisassembler::Success;
717}
718
719static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp,
720 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000721 signedDecoder<4>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000722 return MCDisassembler::Success;
723}
724
725static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp,
726 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000727 signedDecoder<5>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000728 return MCDisassembler::Success;
729}
730
731static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp,
732 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000733 signedDecoder<6>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000734 return MCDisassembler::Success;
735}
736
737static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp,
738 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000739 signedDecoder<7>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000740 return MCDisassembler::Success;
741}
742
Colin LeMahieu7c958712015-10-17 01:33:04 +0000743static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp,
744 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000745 signedDecoder<10>(MI, tmp, Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000746 return MCDisassembler::Success;
747}
748
749static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp,
750 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000751 signedDecoder<19>(MI, tmp, Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000752 return MCDisassembler::Success;
753}
754
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000755// custom decoder for various jump/call immediates
756static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
757 const void *Decoder) {
758 HexagonDisassembler const &Disassembler = disassembler(Decoder);
759 unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI);
760 // r13_2 is not extendable, so if there are no extent bits, it's r13_2
761 if (Bits == 0)
762 Bits = 15;
763 uint32_t FullValue = fullValue(*Disassembler.MCII,
764 **Disassembler.CurrentBundle,
765 MI, SignExtend64(tmp, Bits));
766 int64_t Extended = SignExtend64<32>(FullValue) + Address;
767 if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true,
768 0, 4))
769 HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext());
770 return MCDisassembler::Success;
771}
772
773// Addressing mode dependent load store opcode map.
774// - If an insn is preceded by an extender the address is absolute.
775// - memw(##symbol) = r0
776// - If an insn is not preceded by an extender the address is GP relative.
777// - memw(gp + #symbol) = r0
778// Please note that the instructions must be ordered in the descending order
779// of their opcode.
780// HexagonII::INST_ICLASS_ST
Craig Topperd824f5f2015-12-01 06:13:08 +0000781static const unsigned int StoreConditionalOpcodeData[][2] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000782 {S4_pstorerdfnew_abs, 0xafc02084},
783 {S4_pstorerdtnew_abs, 0xafc02080},
784 {S4_pstorerdf_abs, 0xafc00084},
785 {S4_pstorerdt_abs, 0xafc00080},
786 {S4_pstorerinewfnew_abs, 0xafa03084},
787 {S4_pstorerinewtnew_abs, 0xafa03080},
788 {S4_pstorerhnewfnew_abs, 0xafa02884},
789 {S4_pstorerhnewtnew_abs, 0xafa02880},
790 {S4_pstorerbnewfnew_abs, 0xafa02084},
791 {S4_pstorerbnewtnew_abs, 0xafa02080},
792 {S4_pstorerinewf_abs, 0xafa01084},
793 {S4_pstorerinewt_abs, 0xafa01080},
794 {S4_pstorerhnewf_abs, 0xafa00884},
795 {S4_pstorerhnewt_abs, 0xafa00880},
796 {S4_pstorerbnewf_abs, 0xafa00084},
797 {S4_pstorerbnewt_abs, 0xafa00080},
798 {S4_pstorerifnew_abs, 0xaf802084},
799 {S4_pstoreritnew_abs, 0xaf802080},
800 {S4_pstorerif_abs, 0xaf800084},
801 {S4_pstorerit_abs, 0xaf800080},
802 {S4_pstorerhfnew_abs, 0xaf402084},
803 {S4_pstorerhtnew_abs, 0xaf402080},
804 {S4_pstorerhf_abs, 0xaf400084},
805 {S4_pstorerht_abs, 0xaf400080},
806 {S4_pstorerbfnew_abs, 0xaf002084},
807 {S4_pstorerbtnew_abs, 0xaf002080},
808 {S4_pstorerbf_abs, 0xaf000084},
809 {S4_pstorerbt_abs, 0xaf000080}};
810// HexagonII::INST_ICLASS_LD
811
812// HexagonII::INST_ICLASS_LD_ST_2
Colin LeMahieu9675de52016-10-06 23:02:11 +0000813static unsigned int LoadStoreOpcodeData[][2] = {{PS_loadrdabs, 0x49c00000},
814 {PS_loadriabs, 0x49800000},
815 {PS_loadruhabs, 0x49600000},
816 {PS_loadrhabs, 0x49400000},
817 {PS_loadrubabs, 0x49200000},
818 {PS_loadrbabs, 0x49000000},
819 {PS_storerdabs, 0x48c00000},
820 {PS_storerinewabs, 0x48a01000},
821 {PS_storerhnewabs, 0x48a00800},
822 {PS_storerbnewabs, 0x48a00000},
823 {PS_storeriabs, 0x48800000},
824 {PS_storerfabs, 0x48600000},
825 {PS_storerhabs, 0x48400000},
826 {PS_storerbabs, 0x48000000}};
Craig Topperd824f5f2015-12-01 06:13:08 +0000827static const size_t NumCondS = array_lengthof(StoreConditionalOpcodeData);
828static const size_t NumLS = array_lengthof(LoadStoreOpcodeData);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000829
830static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn) {
831
832 unsigned MachineOpcode = 0;
833 unsigned LLVMOpcode = 0;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000834
835 if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_ST) {
Craig Topperd824f5f2015-12-01 06:13:08 +0000836 for (size_t i = 0; i < NumCondS; ++i) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000837 if ((insn & StoreConditionalOpcodeData[i][1]) ==
838 StoreConditionalOpcodeData[i][1]) {
839 MachineOpcode = StoreConditionalOpcodeData[i][1];
840 LLVMOpcode = StoreConditionalOpcodeData[i][0];
841 break;
842 }
843 }
844 }
845 if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_LD_ST_2) {
Craig Topperd824f5f2015-12-01 06:13:08 +0000846 for (size_t i = 0; i < NumLS; ++i) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000847 if ((insn & LoadStoreOpcodeData[i][1]) == LoadStoreOpcodeData[i][1]) {
848 MachineOpcode = LoadStoreOpcodeData[i][1];
849 LLVMOpcode = LoadStoreOpcodeData[i][0];
850 break;
851 }
852 }
853 }
854
855 if (MachineOpcode) {
856 unsigned Value = 0;
857 unsigned shift = 0;
858 MI.setOpcode(LLVMOpcode);
859 // Remove the parse bits from the insn.
860 insn &= ~HexagonII::INST_PARSE_MASK;
861
862 switch (LLVMOpcode) {
863 default:
864 return MCDisassembler::Fail;
865 break;
866
867 case Hexagon::S4_pstorerdf_abs:
868 case Hexagon::S4_pstorerdt_abs:
869 case Hexagon::S4_pstorerdfnew_abs:
870 case Hexagon::S4_pstorerdtnew_abs: {
871 // op: Pv
872 Value = insn & UINT64_C(3);
873 DecodePredRegsRegisterClass(MI, Value, 0, 0);
874 // op: u6
875 Value = (insn >> 12) & UINT64_C(48);
876 Value |= (insn >> 3) & UINT64_C(15);
877 MI.addOperand(MCOperand::createImm(Value));
878 // op: Rtt
879 Value = (insn >> 8) & UINT64_C(31);
880 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
881 break;
882 }
883
884 case Hexagon::S4_pstorerbnewf_abs:
885 case Hexagon::S4_pstorerbnewt_abs:
886 case Hexagon::S4_pstorerbnewfnew_abs:
887 case Hexagon::S4_pstorerbnewtnew_abs:
888 case Hexagon::S4_pstorerhnewf_abs:
889 case Hexagon::S4_pstorerhnewt_abs:
890 case Hexagon::S4_pstorerhnewfnew_abs:
891 case Hexagon::S4_pstorerhnewtnew_abs:
892 case Hexagon::S4_pstorerinewf_abs:
893 case Hexagon::S4_pstorerinewt_abs:
894 case Hexagon::S4_pstorerinewfnew_abs:
895 case Hexagon::S4_pstorerinewtnew_abs: {
896 // op: Pv
897 Value = insn & UINT64_C(3);
898 DecodePredRegsRegisterClass(MI, Value, 0, 0);
899 // op: u6
900 Value = (insn >> 12) & UINT64_C(48);
901 Value |= (insn >> 3) & UINT64_C(15);
902 MI.addOperand(MCOperand::createImm(Value));
903 // op: Nt
904 Value = (insn >> 8) & UINT64_C(7);
905 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
906 break;
907 }
908
909 case Hexagon::S4_pstorerbf_abs:
910 case Hexagon::S4_pstorerbt_abs:
911 case Hexagon::S4_pstorerbfnew_abs:
912 case Hexagon::S4_pstorerbtnew_abs:
913 case Hexagon::S4_pstorerhf_abs:
914 case Hexagon::S4_pstorerht_abs:
915 case Hexagon::S4_pstorerhfnew_abs:
916 case Hexagon::S4_pstorerhtnew_abs:
917 case Hexagon::S4_pstorerif_abs:
918 case Hexagon::S4_pstorerit_abs:
919 case Hexagon::S4_pstorerifnew_abs:
920 case Hexagon::S4_pstoreritnew_abs: {
921 // op: Pv
922 Value = insn & UINT64_C(3);
923 DecodePredRegsRegisterClass(MI, Value, 0, 0);
924 // op: u6
925 Value = (insn >> 12) & UINT64_C(48);
926 Value |= (insn >> 3) & UINT64_C(15);
927 MI.addOperand(MCOperand::createImm(Value));
928 // op: Rt
929 Value = (insn >> 8) & UINT64_C(31);
930 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
931 break;
932 }
933
934 case Hexagon::L4_ploadrdf_abs:
935 case Hexagon::L4_ploadrdt_abs:
936 case Hexagon::L4_ploadrdfnew_abs:
937 case Hexagon::L4_ploadrdtnew_abs: {
938 // op: Rdd
939 Value = insn & UINT64_C(31);
940 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
941 // op: Pt
942 Value = ((insn >> 9) & UINT64_C(3));
943 DecodePredRegsRegisterClass(MI, Value, 0, 0);
944 // op: u6
945 Value = ((insn >> 15) & UINT64_C(62));
946 Value |= ((insn >> 8) & UINT64_C(1));
947 MI.addOperand(MCOperand::createImm(Value));
948 break;
949 }
950
951 case Hexagon::L4_ploadrbf_abs:
952 case Hexagon::L4_ploadrbt_abs:
953 case Hexagon::L4_ploadrbfnew_abs:
954 case Hexagon::L4_ploadrbtnew_abs:
955 case Hexagon::L4_ploadrhf_abs:
956 case Hexagon::L4_ploadrht_abs:
957 case Hexagon::L4_ploadrhfnew_abs:
958 case Hexagon::L4_ploadrhtnew_abs:
959 case Hexagon::L4_ploadrubf_abs:
960 case Hexagon::L4_ploadrubt_abs:
961 case Hexagon::L4_ploadrubfnew_abs:
962 case Hexagon::L4_ploadrubtnew_abs:
963 case Hexagon::L4_ploadruhf_abs:
964 case Hexagon::L4_ploadruht_abs:
965 case Hexagon::L4_ploadruhfnew_abs:
966 case Hexagon::L4_ploadruhtnew_abs:
967 case Hexagon::L4_ploadrif_abs:
968 case Hexagon::L4_ploadrit_abs:
969 case Hexagon::L4_ploadrifnew_abs:
970 case Hexagon::L4_ploadritnew_abs:
971 // op: Rd
972 Value = insn & UINT64_C(31);
973 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
974 // op: Pt
975 Value = (insn >> 9) & UINT64_C(3);
976 DecodePredRegsRegisterClass(MI, Value, 0, 0);
977 // op: u6
978 Value = (insn >> 15) & UINT64_C(62);
979 Value |= (insn >> 8) & UINT64_C(1);
980 MI.addOperand(MCOperand::createImm(Value));
981 break;
982
983 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +0000984 case (Hexagon::PS_loadriabs):
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000985 ++shift;
986 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +0000987 case Hexagon::PS_loadrhabs:
988 case Hexagon::PS_loadruhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000989 ++shift;
990 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +0000991 case Hexagon::PS_loadrbabs:
992 case Hexagon::PS_loadrubabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000993 // op: Rd
994 Value |= insn & UINT64_C(31);
995 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
996 Value = (insn >> 11) & UINT64_C(49152);
997 Value |= (insn >> 7) & UINT64_C(15872);
998 Value |= (insn >> 5) & UINT64_C(511);
999 MI.addOperand(MCOperand::createImm(Value << shift));
1000 break;
1001 }
1002
Colin LeMahieu9675de52016-10-06 23:02:11 +00001003 case Hexagon::PS_loadrdabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001004 Value = insn & UINT64_C(31);
1005 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
1006 Value = (insn >> 11) & UINT64_C(49152);
1007 Value |= (insn >> 7) & UINT64_C(15872);
1008 Value |= (insn >> 5) & UINT64_C(511);
1009 MI.addOperand(MCOperand::createImm(Value << 3));
1010 break;
1011 }
1012
Colin LeMahieu9675de52016-10-06 23:02:11 +00001013 case Hexagon::PS_storerdabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001014 // op: g16_3
1015 Value = (insn >> 11) & UINT64_C(49152);
1016 Value |= (insn >> 7) & UINT64_C(15872);
1017 Value |= (insn >> 5) & UINT64_C(256);
1018 Value |= insn & UINT64_C(255);
1019 MI.addOperand(MCOperand::createImm(Value << 3));
1020 // op: Rtt
1021 Value = (insn >> 8) & UINT64_C(31);
1022 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
1023 break;
1024 }
1025
1026 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001027 case Hexagon::PS_storerinewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001028 ++shift;
1029 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001030 case Hexagon::PS_storerhnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001031 ++shift;
1032 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001033 case Hexagon::PS_storerbnewabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001034 Value = (insn >> 11) & UINT64_C(49152);
1035 Value |= (insn >> 7) & UINT64_C(15872);
1036 Value |= (insn >> 5) & UINT64_C(256);
1037 Value |= insn & UINT64_C(255);
1038 MI.addOperand(MCOperand::createImm(Value << shift));
1039 // op: Nt
1040 Value = (insn >> 8) & UINT64_C(7);
1041 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1042 break;
1043 }
1044
1045 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001046 case Hexagon::PS_storeriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001047 ++shift;
1048 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001049 case Hexagon::PS_storerhabs:
1050 case Hexagon::PS_storerfabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001051 ++shift;
1052 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001053 case Hexagon::PS_storerbabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001054 Value = (insn >> 11) & UINT64_C(49152);
1055 Value |= (insn >> 7) & UINT64_C(15872);
1056 Value |= (insn >> 5) & UINT64_C(256);
1057 Value |= insn & UINT64_C(255);
1058 MI.addOperand(MCOperand::createImm(Value << shift));
1059 // op: Rt
1060 Value = (insn >> 8) & UINT64_C(31);
1061 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1062 break;
1063 }
1064 }
1065 return MCDisassembler::Success;
1066 }
1067 return MCDisassembler::Fail;
1068}
1069
1070static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn,
1071 void const *Decoder) {
1072
1073 // Instruction Class for a constant a extender: bits 31:28 = 0x0000
1074 if ((~insn & 0xf0000000) == 0xf0000000) {
1075 unsigned Value;
1076 // 27:16 High 12 bits of 26-bit extender.
1077 Value = (insn & 0x0fff0000) << 4;
1078 // 13:0 Low 14 bits of 26-bit extender.
1079 Value |= ((insn & 0x3fff) << 6);
1080 MI.setOpcode(Hexagon::A4_ext);
1081 HexagonMCInstrInfo::addConstant(MI, Value, contextFromDecoder(Decoder));
1082 return MCDisassembler::Success;
1083 }
1084 return MCDisassembler::Fail;
1085}
1086
Colin LeMahieube8c4532015-06-05 16:00:11 +00001087// These values are from HexagonGenMCCodeEmitter.inc and HexagonIsetDx.td
1088enum subInstBinaryValues {
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001089 SA1_addi_BITS = 0x0000,
1090 SA1_addi_MASK = 0x1800,
1091 SA1_addrx_BITS = 0x1800,
1092 SA1_addrx_MASK = 0x1f00,
1093 SA1_addsp_BITS = 0x0c00,
1094 SA1_addsp_MASK = 0x1c00,
1095 SA1_and1_BITS = 0x1200,
1096 SA1_and1_MASK = 0x1f00,
1097 SA1_clrf_BITS = 0x1a70,
1098 SA1_clrf_MASK = 0x1e70,
1099 SA1_clrfnew_BITS = 0x1a50,
1100 SA1_clrfnew_MASK = 0x1e70,
1101 SA1_clrt_BITS = 0x1a60,
1102 SA1_clrt_MASK = 0x1e70,
1103 SA1_clrtnew_BITS = 0x1a40,
1104 SA1_clrtnew_MASK = 0x1e70,
1105 SA1_cmpeqi_BITS = 0x1900,
1106 SA1_cmpeqi_MASK = 0x1f00,
1107 SA1_combine0i_BITS = 0x1c00,
1108 SA1_combine0i_MASK = 0x1d18,
1109 SA1_combine1i_BITS = 0x1c08,
1110 SA1_combine1i_MASK = 0x1d18,
1111 SA1_combine2i_BITS = 0x1c10,
1112 SA1_combine2i_MASK = 0x1d18,
1113 SA1_combine3i_BITS = 0x1c18,
1114 SA1_combine3i_MASK = 0x1d18,
1115 SA1_combinerz_BITS = 0x1d08,
1116 SA1_combinerz_MASK = 0x1d08,
1117 SA1_combinezr_BITS = 0x1d00,
1118 SA1_combinezr_MASK = 0x1d08,
1119 SA1_dec_BITS = 0x1300,
1120 SA1_dec_MASK = 0x1f00,
1121 SA1_inc_BITS = 0x1100,
1122 SA1_inc_MASK = 0x1f00,
1123 SA1_seti_BITS = 0x0800,
1124 SA1_seti_MASK = 0x1c00,
1125 SA1_setin1_BITS = 0x1a00,
1126 SA1_setin1_MASK = 0x1e40,
1127 SA1_sxtb_BITS = 0x1500,
1128 SA1_sxtb_MASK = 0x1f00,
1129 SA1_sxth_BITS = 0x1400,
1130 SA1_sxth_MASK = 0x1f00,
1131 SA1_tfr_BITS = 0x1000,
1132 SA1_tfr_MASK = 0x1f00,
1133 SA1_zxtb_BITS = 0x1700,
1134 SA1_zxtb_MASK = 0x1f00,
1135 SA1_zxth_BITS = 0x1600,
1136 SA1_zxth_MASK = 0x1f00,
1137 SL1_loadri_io_BITS = 0x0000,
1138 SL1_loadri_io_MASK = 0x1000,
1139 SL1_loadrub_io_BITS = 0x1000,
1140 SL1_loadrub_io_MASK = 0x1000,
1141 SL2_deallocframe_BITS = 0x1f00,
1142 SL2_deallocframe_MASK = 0x1fc0,
1143 SL2_jumpr31_BITS = 0x1fc0,
1144 SL2_jumpr31_MASK = 0x1fc4,
1145 SL2_jumpr31_f_BITS = 0x1fc5,
1146 SL2_jumpr31_f_MASK = 0x1fc7,
1147 SL2_jumpr31_fnew_BITS = 0x1fc7,
1148 SL2_jumpr31_fnew_MASK = 0x1fc7,
1149 SL2_jumpr31_t_BITS = 0x1fc4,
1150 SL2_jumpr31_t_MASK = 0x1fc7,
1151 SL2_jumpr31_tnew_BITS = 0x1fc6,
1152 SL2_jumpr31_tnew_MASK = 0x1fc7,
1153 SL2_loadrb_io_BITS = 0x1000,
1154 SL2_loadrb_io_MASK = 0x1800,
1155 SL2_loadrd_sp_BITS = 0x1e00,
1156 SL2_loadrd_sp_MASK = 0x1f00,
1157 SL2_loadrh_io_BITS = 0x0000,
1158 SL2_loadrh_io_MASK = 0x1800,
1159 SL2_loadri_sp_BITS = 0x1c00,
1160 SL2_loadri_sp_MASK = 0x1e00,
1161 SL2_loadruh_io_BITS = 0x0800,
1162 SL2_loadruh_io_MASK = 0x1800,
1163 SL2_return_BITS = 0x1f40,
1164 SL2_return_MASK = 0x1fc4,
1165 SL2_return_f_BITS = 0x1f45,
1166 SL2_return_f_MASK = 0x1fc7,
1167 SL2_return_fnew_BITS = 0x1f47,
1168 SL2_return_fnew_MASK = 0x1fc7,
1169 SL2_return_t_BITS = 0x1f44,
1170 SL2_return_t_MASK = 0x1fc7,
1171 SL2_return_tnew_BITS = 0x1f46,
1172 SL2_return_tnew_MASK = 0x1fc7,
1173 SS1_storeb_io_BITS = 0x1000,
1174 SS1_storeb_io_MASK = 0x1000,
1175 SS1_storew_io_BITS = 0x0000,
1176 SS1_storew_io_MASK = 0x1000,
1177 SS2_allocframe_BITS = 0x1c00,
1178 SS2_allocframe_MASK = 0x1e00,
1179 SS2_storebi0_BITS = 0x1200,
1180 SS2_storebi0_MASK = 0x1f00,
1181 SS2_storebi1_BITS = 0x1300,
1182 SS2_storebi1_MASK = 0x1f00,
1183 SS2_stored_sp_BITS = 0x0a00,
1184 SS2_stored_sp_MASK = 0x1e00,
1185 SS2_storeh_io_BITS = 0x0000,
1186 SS2_storeh_io_MASK = 0x1800,
1187 SS2_storew_sp_BITS = 0x0800,
1188 SS2_storew_sp_MASK = 0x1e00,
1189 SS2_storewi0_BITS = 0x1000,
1190 SS2_storewi0_MASK = 0x1f00,
1191 SS2_storewi1_BITS = 0x1100,
1192 SS2_storewi1_MASK = 0x1f00
Colin LeMahieube8c4532015-06-05 16:00:11 +00001193};
1194
1195static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op,
1196 raw_ostream &os) {
1197 switch (IClass) {
1198 case HexagonII::HSIG_L1:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001199 if ((inst & SL1_loadri_io_MASK) == SL1_loadri_io_BITS)
1200 op = Hexagon::SL1_loadri_io;
1201 else if ((inst & SL1_loadrub_io_MASK) == SL1_loadrub_io_BITS)
1202 op = Hexagon::SL1_loadrub_io;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001203 else {
1204 os << "<unknown subinstruction>";
1205 return MCDisassembler::Fail;
1206 }
1207 break;
1208 case HexagonII::HSIG_L2:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001209 if ((inst & SL2_deallocframe_MASK) == SL2_deallocframe_BITS)
1210 op = Hexagon::SL2_deallocframe;
1211 else if ((inst & SL2_jumpr31_MASK) == SL2_jumpr31_BITS)
1212 op = Hexagon::SL2_jumpr31;
1213 else if ((inst & SL2_jumpr31_f_MASK) == SL2_jumpr31_f_BITS)
1214 op = Hexagon::SL2_jumpr31_f;
1215 else if ((inst & SL2_jumpr31_fnew_MASK) == SL2_jumpr31_fnew_BITS)
1216 op = Hexagon::SL2_jumpr31_fnew;
1217 else if ((inst & SL2_jumpr31_t_MASK) == SL2_jumpr31_t_BITS)
1218 op = Hexagon::SL2_jumpr31_t;
1219 else if ((inst & SL2_jumpr31_tnew_MASK) == SL2_jumpr31_tnew_BITS)
1220 op = Hexagon::SL2_jumpr31_tnew;
1221 else if ((inst & SL2_loadrb_io_MASK) == SL2_loadrb_io_BITS)
1222 op = Hexagon::SL2_loadrb_io;
1223 else if ((inst & SL2_loadrd_sp_MASK) == SL2_loadrd_sp_BITS)
1224 op = Hexagon::SL2_loadrd_sp;
1225 else if ((inst & SL2_loadrh_io_MASK) == SL2_loadrh_io_BITS)
1226 op = Hexagon::SL2_loadrh_io;
1227 else if ((inst & SL2_loadri_sp_MASK) == SL2_loadri_sp_BITS)
1228 op = Hexagon::SL2_loadri_sp;
1229 else if ((inst & SL2_loadruh_io_MASK) == SL2_loadruh_io_BITS)
1230 op = Hexagon::SL2_loadruh_io;
1231 else if ((inst & SL2_return_MASK) == SL2_return_BITS)
1232 op = Hexagon::SL2_return;
1233 else if ((inst & SL2_return_f_MASK) == SL2_return_f_BITS)
1234 op = Hexagon::SL2_return_f;
1235 else if ((inst & SL2_return_fnew_MASK) == SL2_return_fnew_BITS)
1236 op = Hexagon::SL2_return_fnew;
1237 else if ((inst & SL2_return_t_MASK) == SL2_return_t_BITS)
1238 op = Hexagon::SL2_return_t;
1239 else if ((inst & SL2_return_tnew_MASK) == SL2_return_tnew_BITS)
1240 op = Hexagon::SL2_return_tnew;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001241 else {
1242 os << "<unknown subinstruction>";
1243 return MCDisassembler::Fail;
1244 }
1245 break;
1246 case HexagonII::HSIG_A:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001247 if ((inst & SA1_addi_MASK) == SA1_addi_BITS)
1248 op = Hexagon::SA1_addi;
1249 else if ((inst & SA1_addrx_MASK) == SA1_addrx_BITS)
1250 op = Hexagon::SA1_addrx;
1251 else if ((inst & SA1_addsp_MASK) == SA1_addsp_BITS)
1252 op = Hexagon::SA1_addsp;
1253 else if ((inst & SA1_and1_MASK) == SA1_and1_BITS)
1254 op = Hexagon::SA1_and1;
1255 else if ((inst & SA1_clrf_MASK) == SA1_clrf_BITS)
1256 op = Hexagon::SA1_clrf;
1257 else if ((inst & SA1_clrfnew_MASK) == SA1_clrfnew_BITS)
1258 op = Hexagon::SA1_clrfnew;
1259 else if ((inst & SA1_clrt_MASK) == SA1_clrt_BITS)
1260 op = Hexagon::SA1_clrt;
1261 else if ((inst & SA1_clrtnew_MASK) == SA1_clrtnew_BITS)
1262 op = Hexagon::SA1_clrtnew;
1263 else if ((inst & SA1_cmpeqi_MASK) == SA1_cmpeqi_BITS)
1264 op = Hexagon::SA1_cmpeqi;
1265 else if ((inst & SA1_combine0i_MASK) == SA1_combine0i_BITS)
1266 op = Hexagon::SA1_combine0i;
1267 else if ((inst & SA1_combine1i_MASK) == SA1_combine1i_BITS)
1268 op = Hexagon::SA1_combine1i;
1269 else if ((inst & SA1_combine2i_MASK) == SA1_combine2i_BITS)
1270 op = Hexagon::SA1_combine2i;
1271 else if ((inst & SA1_combine3i_MASK) == SA1_combine3i_BITS)
1272 op = Hexagon::SA1_combine3i;
1273 else if ((inst & SA1_combinerz_MASK) == SA1_combinerz_BITS)
1274 op = Hexagon::SA1_combinerz;
1275 else if ((inst & SA1_combinezr_MASK) == SA1_combinezr_BITS)
1276 op = Hexagon::SA1_combinezr;
1277 else if ((inst & SA1_dec_MASK) == SA1_dec_BITS)
1278 op = Hexagon::SA1_dec;
1279 else if ((inst & SA1_inc_MASK) == SA1_inc_BITS)
1280 op = Hexagon::SA1_inc;
1281 else if ((inst & SA1_seti_MASK) == SA1_seti_BITS)
1282 op = Hexagon::SA1_seti;
1283 else if ((inst & SA1_setin1_MASK) == SA1_setin1_BITS)
1284 op = Hexagon::SA1_setin1;
1285 else if ((inst & SA1_sxtb_MASK) == SA1_sxtb_BITS)
1286 op = Hexagon::SA1_sxtb;
1287 else if ((inst & SA1_sxth_MASK) == SA1_sxth_BITS)
1288 op = Hexagon::SA1_sxth;
1289 else if ((inst & SA1_tfr_MASK) == SA1_tfr_BITS)
1290 op = Hexagon::SA1_tfr;
1291 else if ((inst & SA1_zxtb_MASK) == SA1_zxtb_BITS)
1292 op = Hexagon::SA1_zxtb;
1293 else if ((inst & SA1_zxth_MASK) == SA1_zxth_BITS)
1294 op = Hexagon::SA1_zxth;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001295 else {
1296 os << "<unknown subinstruction>";
1297 return MCDisassembler::Fail;
1298 }
1299 break;
1300 case HexagonII::HSIG_S1:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001301 if ((inst & SS1_storeb_io_MASK) == SS1_storeb_io_BITS)
1302 op = Hexagon::SS1_storeb_io;
1303 else if ((inst & SS1_storew_io_MASK) == SS1_storew_io_BITS)
1304 op = Hexagon::SS1_storew_io;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001305 else {
1306 os << "<unknown subinstruction>";
1307 return MCDisassembler::Fail;
1308 }
1309 break;
1310 case HexagonII::HSIG_S2:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001311 if ((inst & SS2_allocframe_MASK) == SS2_allocframe_BITS)
1312 op = Hexagon::SS2_allocframe;
1313 else if ((inst & SS2_storebi0_MASK) == SS2_storebi0_BITS)
1314 op = Hexagon::SS2_storebi0;
1315 else if ((inst & SS2_storebi1_MASK) == SS2_storebi1_BITS)
1316 op = Hexagon::SS2_storebi1;
1317 else if ((inst & SS2_stored_sp_MASK) == SS2_stored_sp_BITS)
1318 op = Hexagon::SS2_stored_sp;
1319 else if ((inst & SS2_storeh_io_MASK) == SS2_storeh_io_BITS)
1320 op = Hexagon::SS2_storeh_io;
1321 else if ((inst & SS2_storew_sp_MASK) == SS2_storew_sp_BITS)
1322 op = Hexagon::SS2_storew_sp;
1323 else if ((inst & SS2_storewi0_MASK) == SS2_storewi0_BITS)
1324 op = Hexagon::SS2_storewi0;
1325 else if ((inst & SS2_storewi1_MASK) == SS2_storewi1_BITS)
1326 op = Hexagon::SS2_storewi1;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001327 else {
1328 os << "<unknown subinstruction>";
1329 return MCDisassembler::Fail;
1330 }
1331 break;
1332 default:
1333 os << "<unknown>";
1334 return MCDisassembler::Fail;
1335 }
1336 return MCDisassembler::Success;
1337}
1338
1339static unsigned getRegFromSubinstEncoding(unsigned encoded_reg) {
1340 if (encoded_reg < 8)
1341 return Hexagon::R0 + encoded_reg;
1342 else if (encoded_reg < 16)
1343 return Hexagon::R0 + encoded_reg + 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001344
1345 // patently false value
Colin LeMahieube8c4532015-06-05 16:00:11 +00001346 return Hexagon::NoRegister;
1347}
1348
1349static unsigned getDRegFromSubinstEncoding(unsigned encoded_dreg) {
1350 if (encoded_dreg < 4)
1351 return Hexagon::D0 + encoded_dreg;
1352 else if (encoded_dreg < 8)
1353 return Hexagon::D0 + encoded_dreg + 4;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001354
1355 // patently false value
Colin LeMahieube8c4532015-06-05 16:00:11 +00001356 return Hexagon::NoRegister;
1357}
1358
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001359void HexagonDisassembler::addSubinstOperands(MCInst *MI, unsigned opcode,
1360 unsigned inst) const {
Colin LeMahieube8c4532015-06-05 16:00:11 +00001361 int64_t operand;
1362 MCOperand Op;
1363 switch (opcode) {
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001364 case Hexagon::SL2_deallocframe:
1365 case Hexagon::SL2_jumpr31:
1366 case Hexagon::SL2_jumpr31_f:
1367 case Hexagon::SL2_jumpr31_fnew:
1368 case Hexagon::SL2_jumpr31_t:
1369 case Hexagon::SL2_jumpr31_tnew:
1370 case Hexagon::SL2_return:
1371 case Hexagon::SL2_return_f:
1372 case Hexagon::SL2_return_fnew:
1373 case Hexagon::SL2_return_t:
1374 case Hexagon::SL2_return_tnew:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001375 // no operands for these instructions
1376 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001377 case Hexagon::SS2_allocframe:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001378 // u 8-4{5_3}
1379 operand = ((inst & 0x1f0) >> 4) << 3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001380 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001381 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001382 case Hexagon::SL1_loadri_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001383 // Rd 3-0, Rs 7-4, u 11-8{4_2}
1384 operand = getRegFromSubinstEncoding(inst & 0xf);
1385 Op = MCOperand::createReg(operand);
1386 MI->addOperand(Op);
1387 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1388 Op = MCOperand::createReg(operand);
1389 MI->addOperand(Op);
1390 operand = (inst & 0xf00) >> 6;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001391 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001392 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001393 case Hexagon::SL1_loadrub_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001394 // Rd 3-0, Rs 7-4, u 11-8
1395 operand = getRegFromSubinstEncoding(inst & 0xf);
1396 Op = MCOperand::createReg(operand);
1397 MI->addOperand(Op);
1398 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1399 Op = MCOperand::createReg(operand);
1400 MI->addOperand(Op);
1401 operand = (inst & 0xf00) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001402 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001403 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001404 case Hexagon::SL2_loadrb_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001405 // Rd 3-0, Rs 7-4, u 10-8
1406 operand = getRegFromSubinstEncoding(inst & 0xf);
1407 Op = MCOperand::createReg(operand);
1408 MI->addOperand(Op);
1409 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1410 Op = MCOperand::createReg(operand);
1411 MI->addOperand(Op);
1412 operand = (inst & 0x700) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001413 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001414 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001415 case Hexagon::SL2_loadrh_io:
1416 case Hexagon::SL2_loadruh_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001417 // Rd 3-0, Rs 7-4, u 10-8{3_1}
1418 operand = getRegFromSubinstEncoding(inst & 0xf);
1419 Op = MCOperand::createReg(operand);
1420 MI->addOperand(Op);
1421 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1422 Op = MCOperand::createReg(operand);
1423 MI->addOperand(Op);
1424 operand = ((inst & 0x700) >> 8) << 1;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001425 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001426 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001427 case Hexagon::SL2_loadrd_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001428 // Rdd 2-0, u 7-3{5_3}
1429 operand = getDRegFromSubinstEncoding(inst & 0x7);
1430 Op = MCOperand::createReg(operand);
1431 MI->addOperand(Op);
1432 operand = ((inst & 0x0f8) >> 3) << 3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001433 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001434 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001435 case Hexagon::SL2_loadri_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001436 // Rd 3-0, u 8-4{5_2}
1437 operand = getRegFromSubinstEncoding(inst & 0xf);
1438 Op = MCOperand::createReg(operand);
1439 MI->addOperand(Op);
1440 operand = ((inst & 0x1f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001441 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001442 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001443 case Hexagon::SA1_addi:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001444 // Rx 3-0 (x2), s7 10-4
1445 operand = getRegFromSubinstEncoding(inst & 0xf);
1446 Op = MCOperand::createReg(operand);
1447 MI->addOperand(Op);
1448 MI->addOperand(Op);
1449 operand = SignExtend64<7>((inst & 0x7f0) >> 4);
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001450 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001451 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001452 case Hexagon::SA1_addrx:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001453 // Rx 3-0 (x2), Rs 7-4
1454 operand = getRegFromSubinstEncoding(inst & 0xf);
1455 Op = MCOperand::createReg(operand);
1456 MI->addOperand(Op);
1457 MI->addOperand(Op);
1458 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1459 Op = MCOperand::createReg(operand);
1460 MI->addOperand(Op);
Colin LeMahieubb0cdfb2016-03-16 20:00:38 +00001461 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001462 case Hexagon::SA1_and1:
1463 case Hexagon::SA1_dec:
1464 case Hexagon::SA1_inc:
1465 case Hexagon::SA1_sxtb:
1466 case Hexagon::SA1_sxth:
1467 case Hexagon::SA1_tfr:
1468 case Hexagon::SA1_zxtb:
1469 case Hexagon::SA1_zxth:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001470 // Rd 3-0, Rs 7-4
1471 operand = getRegFromSubinstEncoding(inst & 0xf);
1472 Op = MCOperand::createReg(operand);
1473 MI->addOperand(Op);
1474 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1475 Op = MCOperand::createReg(operand);
1476 MI->addOperand(Op);
1477 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001478 case Hexagon::SA1_addsp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001479 // Rd 3-0, u 9-4{6_2}
1480 operand = getRegFromSubinstEncoding(inst & 0xf);
1481 Op = MCOperand::createReg(operand);
1482 MI->addOperand(Op);
1483 operand = ((inst & 0x3f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001484 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001485 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001486 case Hexagon::SA1_seti:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001487 // Rd 3-0, u 9-4
1488 operand = getRegFromSubinstEncoding(inst & 0xf);
1489 Op = MCOperand::createReg(operand);
1490 MI->addOperand(Op);
1491 operand = (inst & 0x3f0) >> 4;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001492 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001493 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001494 case Hexagon::SA1_clrf:
1495 case Hexagon::SA1_clrfnew:
1496 case Hexagon::SA1_clrt:
1497 case Hexagon::SA1_clrtnew:
1498 case Hexagon::SA1_setin1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001499 // Rd 3-0
1500 operand = getRegFromSubinstEncoding(inst & 0xf);
1501 Op = MCOperand::createReg(operand);
1502 MI->addOperand(Op);
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001503 if (opcode == Hexagon::SA1_setin1)
Krzysztof Parzyszek73e0ad82016-09-09 21:45:00 +00001504 break;
1505 MI->addOperand(MCOperand::createReg(Hexagon::P0));
Colin LeMahieube8c4532015-06-05 16:00:11 +00001506 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001507 case Hexagon::SA1_cmpeqi:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001508 // Rs 7-4, u 1-0
1509 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1510 Op = MCOperand::createReg(operand);
1511 MI->addOperand(Op);
1512 operand = inst & 0x3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001513 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001514 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001515 case Hexagon::SA1_combine0i:
1516 case Hexagon::SA1_combine1i:
1517 case Hexagon::SA1_combine2i:
1518 case Hexagon::SA1_combine3i:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001519 // Rdd 2-0, u 6-5
1520 operand = getDRegFromSubinstEncoding(inst & 0x7);
1521 Op = MCOperand::createReg(operand);
1522 MI->addOperand(Op);
1523 operand = (inst & 0x060) >> 5;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001524 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001525 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001526 case Hexagon::SA1_combinerz:
1527 case Hexagon::SA1_combinezr:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001528 // Rdd 2-0, Rs 7-4
1529 operand = getDRegFromSubinstEncoding(inst & 0x7);
1530 Op = MCOperand::createReg(operand);
1531 MI->addOperand(Op);
1532 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1533 Op = MCOperand::createReg(operand);
1534 MI->addOperand(Op);
1535 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001536 case Hexagon::SS1_storeb_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001537 // Rs 7-4, u 11-8, Rt 3-0
1538 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1539 Op = MCOperand::createReg(operand);
1540 MI->addOperand(Op);
1541 operand = (inst & 0xf00) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001542 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001543 operand = getRegFromSubinstEncoding(inst & 0xf);
1544 Op = MCOperand::createReg(operand);
1545 MI->addOperand(Op);
1546 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001547 case Hexagon::SS1_storew_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001548 // Rs 7-4, u 11-8{4_2}, Rt 3-0
1549 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1550 Op = MCOperand::createReg(operand);
1551 MI->addOperand(Op);
1552 operand = ((inst & 0xf00) >> 8) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001553 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001554 operand = getRegFromSubinstEncoding(inst & 0xf);
1555 Op = MCOperand::createReg(operand);
1556 MI->addOperand(Op);
1557 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001558 case Hexagon::SS2_storebi0:
1559 case Hexagon::SS2_storebi1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001560 // Rs 7-4, u 3-0
1561 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1562 Op = MCOperand::createReg(operand);
1563 MI->addOperand(Op);
1564 operand = inst & 0xf;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001565 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001566 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001567 case Hexagon::SS2_storewi0:
1568 case Hexagon::SS2_storewi1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001569 // Rs 7-4, u 3-0{4_2}
1570 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1571 Op = MCOperand::createReg(operand);
1572 MI->addOperand(Op);
1573 operand = (inst & 0xf) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001574 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001575 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001576 case Hexagon::SS2_stored_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001577 // s 8-3{6_3}, Rtt 2-0
1578 operand = SignExtend64<9>(((inst & 0x1f8) >> 3) << 3);
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001579 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001580 operand = getDRegFromSubinstEncoding(inst & 0x7);
1581 Op = MCOperand::createReg(operand);
1582 MI->addOperand(Op);
Colin LeMahieu160f73e2015-11-03 00:21:19 +00001583 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001584 case Hexagon::SS2_storeh_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001585 // Rs 7-4, u 10-8{3_1}, Rt 3-0
1586 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1587 Op = MCOperand::createReg(operand);
1588 MI->addOperand(Op);
1589 operand = ((inst & 0x700) >> 8) << 1;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001590 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001591 operand = getRegFromSubinstEncoding(inst & 0xf);
1592 Op = MCOperand::createReg(operand);
1593 MI->addOperand(Op);
1594 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001595 case Hexagon::SS2_storew_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001596 // u 8-4{5_2}, Rd 3-0
1597 operand = ((inst & 0x1f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001598 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001599 operand = getRegFromSubinstEncoding(inst & 0xf);
1600 Op = MCOperand::createReg(operand);
1601 MI->addOperand(Op);
1602 break;
1603 default:
1604 // don't crash with an invalid subinstruction
1605 // llvm_unreachable("Invalid subinstruction in duplex instruction");
1606 break;
1607 }
1608}