blob: a65522cb14acb38a4176310ed12d7c356ebee495 [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"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000030#include "llvm/Support/MemoryObject.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000031#include "llvm/Support/raw_ostream.h"
Colin LeMahieu7cd08922015-11-09 04:07:48 +000032#include "llvm/Support/TargetRegistry.h"
NAKAMURA Takumi729be142014-10-27 12:37:26 +000033
34using namespace llvm;
Colin LeMahieu68d967d2015-05-29 14:44:13 +000035using namespace Hexagon;
NAKAMURA Takumi729be142014-10-27 12:37:26 +000036
Colin LeMahieu7cd08922015-11-09 04:07:48 +000037typedef MCDisassembler::DecodeStatus DecodeStatus;
NAKAMURA Takumi729be142014-10-27 12:37:26 +000038
39namespace {
40/// \brief Hexagon disassembler for all Hexagon platforms.
41class HexagonDisassembler : public MCDisassembler {
42public:
Colin LeMahieu7cd08922015-11-09 04:07:48 +000043 std::unique_ptr<MCInstrInfo const> const MCII;
Colin LeMahieu68d967d2015-05-29 14:44:13 +000044 std::unique_ptr<MCInst *> CurrentBundle;
Colin LeMahieu7cd08922015-11-09 04:07:48 +000045 HexagonDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
46 MCInstrInfo const *MCII)
47 : MCDisassembler(STI, Ctx), MCII(MCII), CurrentBundle(new MCInst *) {}
NAKAMURA Takumi729be142014-10-27 12:37:26 +000048
Colin LeMahieu68d967d2015-05-29 14:44:13 +000049 DecodeStatus getSingleInstruction(MCInst &Instr, MCInst &MCB,
50 ArrayRef<uint8_t> Bytes, uint64_t Address,
51 raw_ostream &VStream, raw_ostream &CStream,
52 bool &Complete) const;
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000053 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +000054 ArrayRef<uint8_t> Bytes, uint64_t Address,
Rafael Espindola4aa6bea2014-11-10 18:11:10 +000055 raw_ostream &VStream,
56 raw_ostream &CStream) const override;
Colin LeMahieu7cd08922015-11-09 04:07:48 +000057
58 void adjustExtendedInstructions(MCInst &MCI, MCInst const &MCB) const;
59 void addSubinstOperands(MCInst *MI, unsigned opcode, unsigned inst) const;
NAKAMURA Takumi729be142014-10-27 12:37:26 +000060};
Alexander Kornienkof00654e2015-06-23 09:49:53 +000061}
NAKAMURA Takumi729be142014-10-27 12:37:26 +000062
Colin LeMahieu7cd08922015-11-09 04:07:48 +000063// Forward declare these because the auto-generated code will reference them.
64// Definitions are further down.
65
66static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
Colin LeMahieube8c4532015-06-05 16:00:11 +000067 uint64_t Address,
68 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +000069static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo,
70 uint64_t Address,
71 const void *Decoder);
72static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo,
73 uint64_t Address,
74 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000075static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo,
76 uint64_t Address,
77 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +000078static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo,
79 uint64_t Address,
80 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000081static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
82 uint64_t Address,
83 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +000084static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
85 uint64_t Address,
86 const void *Decoder);
Colin LeMahieuf3db8842014-12-19 19:06:32 +000087static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
Colin LeMahieube8c4532015-06-05 16:00:11 +000088 uint64_t Address,
89 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +000090static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
91 uint64_t Address,
92 const void *Decoder);
Colin LeMahieu404d5b22015-02-10 16:59:36 +000093static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
Colin LeMahieube8c4532015-06-05 16:00:11 +000094 uint64_t Address,
Colin LeMahieu7cd08922015-11-09 04:07:48 +000095 const void *Decoder);
96
97static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn);
98static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn,
99 void const *Decoder);
Colin LeMahieube8c4532015-06-05 16:00:11 +0000100
101static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op,
102 raw_ostream &os);
Colin LeMahieuf3db8842014-12-19 19:06:32 +0000103
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000104static unsigned getRegFromSubinstEncoding(unsigned encoded_reg);
105
106static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
107 uint64_t Address, const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000108static DecodeStatus s16_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000109 const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000110static DecodeStatus s12_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000111 const void *Decoder);
112static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
113 const void *Decoder);
114static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
115 const void *Decoder);
116static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
117 const void *Decoder);
118static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
119 const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000120static DecodeStatus s10_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000121 const void *Decoder);
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000122static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000123 const void *Decoder);
124static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
125 const void *Decoder);
126static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
127 const void *Decoder);
128static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
129 const void *Decoder);
130static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
131 const void *Decoder);
132static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
133 const void *Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000134static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
135 const void *Decoder);
136static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
137 const void *Decoder);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000138static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
139 const void *Decoder);
Colin LeMahieuefa74e02014-11-18 20:28:11 +0000140
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000141#include "HexagonGenDisassemblerTables.inc"
142
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000143static MCDisassembler *createHexagonDisassembler(const Target &T,
144 const MCSubtargetInfo &STI,
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000145 MCContext &Ctx) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000146 return new HexagonDisassembler(STI, Ctx, T.createMCInstrInfo());
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000147}
148
149extern "C" void LLVMInitializeHexagonDisassembler() {
Mehdi Aminif42454b2016-10-09 23:00:34 +0000150 TargetRegistry::RegisterMCDisassembler(getTheHexagonTarget(),
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000151 createHexagonDisassembler);
152}
153
154DecodeStatus HexagonDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Rafael Espindola7fc5b872014-11-12 02:04:27 +0000155 ArrayRef<uint8_t> Bytes,
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000156 uint64_t Address,
157 raw_ostream &os,
158 raw_ostream &cs) const {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000159 DecodeStatus Result = DecodeStatus::Success;
160 bool Complete = false;
161 Size = 0;
Rafael Espindola4aa6bea2014-11-10 18:11:10 +0000162
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000163 *CurrentBundle = &MI;
Colin LeMahieuf0af6e52015-11-13 17:42:46 +0000164 MI = HexagonMCInstrInfo::createBundle();
Colin LeMahieube8c4532015-06-05 16:00:11 +0000165 while (Result == Success && Complete == false) {
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000166 if (Bytes.size() < HEXAGON_INSTR_SIZE)
167 return MCDisassembler::Fail;
Colin LeMahieube8c4532015-06-05 16:00:11 +0000168 MCInst *Inst = new (getContext()) MCInst;
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000169 Result = getSingleInstruction(*Inst, MI, Bytes, Address, os, cs, Complete);
170 MI.addOperand(MCOperand::createInst(Inst));
171 Size += HEXAGON_INSTR_SIZE;
172 Bytes = Bytes.slice(HEXAGON_INSTR_SIZE);
173 }
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000174 if(Result == MCDisassembler::Fail)
175 return Result;
176 HexagonMCChecker Checker (*MCII, STI, MI, MI, *getContext().getRegisterInfo());
177 if(!Checker.check())
178 return MCDisassembler::Fail;
179 return MCDisassembler::Success;
180}
181
182namespace {
183HexagonDisassembler const &disassembler(void const *Decoder) {
184 return *static_cast<HexagonDisassembler const *>(Decoder);
185}
186MCContext &contextFromDecoder(void const *Decoder) {
187 return disassembler(Decoder).getContext();
188}
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000189}
190
191DecodeStatus HexagonDisassembler::getSingleInstruction(
192 MCInst &MI, MCInst &MCB, ArrayRef<uint8_t> Bytes, uint64_t Address,
193 raw_ostream &os, raw_ostream &cs, bool &Complete) const {
194 assert(Bytes.size() >= HEXAGON_INSTR_SIZE);
195
196 uint32_t Instruction =
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000197 (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0);
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000198
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000199 auto BundleSize = HexagonMCInstrInfo::bundleSize(MCB);
200 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
201 HexagonII::INST_PARSE_LOOP_END) {
202 if (BundleSize == 0)
203 HexagonMCInstrInfo::setInnerLoop(MCB);
204 else if (BundleSize == 1)
205 HexagonMCInstrInfo::setOuterLoop(MCB);
206 else
207 return DecodeStatus::Fail;
208 }
209
210 DecodeStatus Result = DecodeStatus::Success;
211 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
Colin LeMahieube8c4532015-06-05 16:00:11 +0000212 HexagonII::INST_PARSE_DUPLEX) {
213 // Determine the instruction class of each instruction in the duplex.
214 unsigned duplexIClass, IClassLow, IClassHigh;
215
216 duplexIClass = ((Instruction >> 28) & 0xe) | ((Instruction >> 13) & 0x1);
217 switch (duplexIClass) {
218 default:
219 return MCDisassembler::Fail;
220 case 0:
221 IClassLow = HexagonII::HSIG_L1;
222 IClassHigh = HexagonII::HSIG_L1;
223 break;
224 case 1:
225 IClassLow = HexagonII::HSIG_L2;
226 IClassHigh = HexagonII::HSIG_L1;
227 break;
228 case 2:
229 IClassLow = HexagonII::HSIG_L2;
230 IClassHigh = HexagonII::HSIG_L2;
231 break;
232 case 3:
233 IClassLow = HexagonII::HSIG_A;
234 IClassHigh = HexagonII::HSIG_A;
235 break;
236 case 4:
237 IClassLow = HexagonII::HSIG_L1;
238 IClassHigh = HexagonII::HSIG_A;
239 break;
240 case 5:
241 IClassLow = HexagonII::HSIG_L2;
242 IClassHigh = HexagonII::HSIG_A;
243 break;
244 case 6:
245 IClassLow = HexagonII::HSIG_S1;
246 IClassHigh = HexagonII::HSIG_A;
247 break;
248 case 7:
249 IClassLow = HexagonII::HSIG_S2;
250 IClassHigh = HexagonII::HSIG_A;
251 break;
252 case 8:
253 IClassLow = HexagonII::HSIG_S1;
254 IClassHigh = HexagonII::HSIG_L1;
255 break;
256 case 9:
257 IClassLow = HexagonII::HSIG_S1;
258 IClassHigh = HexagonII::HSIG_L2;
259 break;
260 case 10:
261 IClassLow = HexagonII::HSIG_S1;
262 IClassHigh = HexagonII::HSIG_S1;
263 break;
264 case 11:
265 IClassLow = HexagonII::HSIG_S2;
266 IClassHigh = HexagonII::HSIG_S1;
267 break;
268 case 12:
269 IClassLow = HexagonII::HSIG_S2;
270 IClassHigh = HexagonII::HSIG_L1;
271 break;
272 case 13:
273 IClassLow = HexagonII::HSIG_S2;
274 IClassHigh = HexagonII::HSIG_L2;
275 break;
276 case 14:
277 IClassLow = HexagonII::HSIG_S2;
278 IClassHigh = HexagonII::HSIG_S2;
279 break;
280 }
281
282 // Set the MCInst to be a duplex instruction. Which one doesn't matter.
283 MI.setOpcode(Hexagon::DuplexIClass0);
284
285 // Decode each instruction in the duplex.
286 // Create an MCInst for each instruction.
287 unsigned instLow = Instruction & 0x1fff;
288 unsigned instHigh = (Instruction >> 16) & 0x1fff;
289 unsigned opLow;
290 if (GetSubinstOpcode(IClassLow, instLow, opLow, os) !=
291 MCDisassembler::Success)
292 return MCDisassembler::Fail;
293 unsigned opHigh;
294 if (GetSubinstOpcode(IClassHigh, instHigh, opHigh, os) !=
295 MCDisassembler::Success)
296 return MCDisassembler::Fail;
297 MCInst *MILow = new (getContext()) MCInst;
298 MILow->setOpcode(opLow);
299 MCInst *MIHigh = new (getContext()) MCInst;
300 MIHigh->setOpcode(opHigh);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000301 addSubinstOperands(MILow, opLow, instLow);
302 addSubinstOperands(MIHigh, opHigh, instHigh);
Colin LeMahieube8c4532015-06-05 16:00:11 +0000303 // see ConvertToSubInst() in
304 // lib/Target/Hexagon/MCTargetDesc/HexagonMCDuplexInfo.cpp
305
306 // Add the duplex instruction MCInsts as operands to the passed in MCInst.
307 MCOperand OPLow = MCOperand::createInst(MILow);
308 MCOperand OPHigh = MCOperand::createInst(MIHigh);
309 MI.addOperand(OPLow);
310 MI.addOperand(OPHigh);
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000311 Complete = true;
Colin LeMahieube8c4532015-06-05 16:00:11 +0000312 } else {
313 if ((Instruction & HexagonII::INST_PARSE_MASK) ==
314 HexagonII::INST_PARSE_PACKET_END)
315 Complete = true;
316 // Calling the auto-generated decoder function.
317 Result =
318 decodeInstruction(DecoderTable32, MI, Instruction, Address, this, STI);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000319
320 // If a, "standard" insn isn't found check special cases.
321 if (MCDisassembler::Success != Result ||
322 MI.getOpcode() == Hexagon::A4_ext) {
323 Result = decodeImmext(MI, Instruction, this);
324 if (MCDisassembler::Success != Result) {
325 Result = decodeSpecial(MI, Instruction);
326 }
327 } else {
328 // If the instruction is a compound instruction, register values will
329 // follow the duplex model, so the register values in the MCInst are
330 // incorrect. If the instruction is a compound, loop through the
331 // operands and change registers appropriately.
332 if (llvm::HexagonMCInstrInfo::getType(*MCII, MI) ==
333 HexagonII::TypeCOMPOUND) {
334 for (MCInst::iterator i = MI.begin(), last = MI.end(); i < last; ++i) {
335 if (i->isReg()) {
336 unsigned reg = i->getReg() - Hexagon::R0;
337 i->setReg(getRegFromSubinstEncoding(reg));
338 }
339 }
340 }
341 }
Colin LeMahieube8c4532015-06-05 16:00:11 +0000342 }
Colin LeMahieu68d967d2015-05-29 14:44:13 +0000343
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000344 if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) {
345 unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI);
346 MCOperand &MCO = MI.getOperand(OpIndex);
347 assert(MCO.isReg() && "New value consumers must be registers");
348 unsigned Register =
349 getContext().getRegisterInfo()->getEncodingValue(MCO.getReg());
350 if ((Register & 0x6) == 0)
351 // HexagonPRM 10.11 Bit 1-2 == 0 is reserved
352 return MCDisassembler::Fail;
353 unsigned Lookback = (Register & 0x6) >> 1;
354 unsigned Offset = 1;
355 bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI);
356 auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle);
357 auto i = Instructions.end() - 1;
358 for (auto n = Instructions.begin() - 1;; --i, ++Offset) {
359 if (i == n)
360 // Couldn't find producer
361 return MCDisassembler::Fail;
362 if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst()))
363 // Skip scalars when calculating distances for vectors
364 ++Lookback;
365 if (HexagonMCInstrInfo::isImmext(*i->getInst()))
366 ++Lookback;
367 if (Offset == Lookback)
368 break;
369 }
370 auto const &Inst = *i->getInst();
371 bool SubregBit = (Register & 0x1) != 0;
372 if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) {
373 // If subreg bit is set we're selecting the second produced newvalue
374 unsigned Producer =
375 HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg();
376 assert(Producer != Hexagon::NoRegister);
377 MCO.setReg(Producer);
378 } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) {
379 unsigned Producer =
380 HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg();
381 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
382 Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0;
383 else if (SubregBit)
Colin LeMahieu2d497a02016-03-01 22:05:03 +0000384 // Hexagon PRM 10.11 New-value operands
385 // Nt[0] is reserved and should always be encoded as zero.
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000386 return MCDisassembler::Fail;
387 assert(Producer != Hexagon::NoRegister);
388 MCO.setReg(Producer);
389 } else
390 return MCDisassembler::Fail;
391 }
392
393 adjustExtendedInstructions(MI, MCB);
394 MCInst const *Extender =
395 HexagonMCInstrInfo::extenderForIndex(MCB,
396 HexagonMCInstrInfo::bundleSize(MCB));
397 if(Extender != nullptr) {
398 MCInst const & Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) ?
399 *MI.getOperand(1).getInst() : MI;
400 if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) &&
401 !HexagonMCInstrInfo::isExtended(*MCII, Inst))
402 return MCDisassembler::Fail;
403 }
Colin LeMahieu5d6f03b2014-12-04 03:41:21 +0000404 return Result;
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000405}
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000406
407void HexagonDisassembler::adjustExtendedInstructions(MCInst &MCI,
408 MCInst const &MCB) const {
409 if (!HexagonMCInstrInfo::hasExtenderForIndex(
410 MCB, HexagonMCInstrInfo::bundleSize(MCB))) {
411 unsigned opcode;
412 // This code is used by the disassembler to disambiguate between GP
413 // relative and absolute addressing instructions since they both have
414 // same encoding bits. However, an absolute addressing instruction must
415 // follow an immediate extender. Disassembler alwaus select absolute
416 // addressing instructions first and uses this code to change them into
417 // GP relative instruction in the absence of the corresponding immediate
418 // extender.
419 switch (MCI.getOpcode()) {
Colin LeMahieu9675de52016-10-06 23:02:11 +0000420 case Hexagon::PS_storerbabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000421 opcode = Hexagon::S2_storerbgp;
422 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000423 case Hexagon::PS_storerhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000424 opcode = Hexagon::S2_storerhgp;
425 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000426 case Hexagon::PS_storerfabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000427 opcode = Hexagon::S2_storerfgp;
428 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000429 case Hexagon::PS_storeriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000430 opcode = Hexagon::S2_storerigp;
431 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000432 case Hexagon::PS_storerbnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000433 opcode = Hexagon::S2_storerbnewgp;
434 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000435 case Hexagon::PS_storerhnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000436 opcode = Hexagon::S2_storerhnewgp;
437 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000438 case Hexagon::PS_storerinewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000439 opcode = Hexagon::S2_storerinewgp;
440 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000441 case Hexagon::PS_storerdabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000442 opcode = Hexagon::S2_storerdgp;
443 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000444 case Hexagon::PS_loadrbabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000445 opcode = Hexagon::L2_loadrbgp;
446 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000447 case Hexagon::PS_loadrubabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000448 opcode = Hexagon::L2_loadrubgp;
449 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000450 case Hexagon::PS_loadrhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000451 opcode = Hexagon::L2_loadrhgp;
452 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000453 case Hexagon::PS_loadruhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000454 opcode = Hexagon::L2_loadruhgp;
455 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000456 case Hexagon::PS_loadriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000457 opcode = Hexagon::L2_loadrigp;
458 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000459 case Hexagon::PS_loadrdabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000460 opcode = Hexagon::L2_loadrdgp;
461 break;
462 default:
463 opcode = MCI.getOpcode();
464 }
465 MCI.setOpcode(opcode);
466 }
467}
468
469namespace llvm {
470extern const MCInstrDesc HexagonInsts[];
471}
472
473static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
Craig Toppere5e035a32015-12-05 07:13:35 +0000474 ArrayRef<MCPhysReg> Table) {
Craig Topper3da000c2015-12-01 06:13:04 +0000475 if (RegNo < Table.size()) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000476 Inst.addOperand(MCOperand::createReg(Table[RegNo]));
477 return MCDisassembler::Success;
Craig Topper3da000c2015-12-01 06:13:04 +0000478 }
479
480 return MCDisassembler::Fail;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000481}
482
Colin LeMahieu7c958712015-10-17 01:33:04 +0000483static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo,
484 uint64_t Address,
485 const void *Decoder) {
486 return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
487}
488
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000489static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
490 uint64_t Address,
491 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000492 static const MCPhysReg IntRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000493 Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
494 Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
495 Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
496 Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
497 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
498 Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
499 Hexagon::R30, Hexagon::R31};
500
Craig Toppere5e035a32015-12-05 07:13:35 +0000501 return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000502}
Colin LeMahieu7c958712015-10-17 01:33:04 +0000503
504static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo,
505 uint64_t /*Address*/,
506 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000507 static const MCPhysReg VecRegDecoderTable[] = {
Colin LeMahieu7c958712015-10-17 01:33:04 +0000508 Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4,
509 Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
510 Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
511 Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
512 Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
513 Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
514 Hexagon::V30, Hexagon::V31};
515
Craig Toppere5e035a32015-12-05 07:13:35 +0000516 return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000517}
518
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000519static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo,
520 uint64_t /*Address*/,
521 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000522 static const MCPhysReg DoubleRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000523 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
524 Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
525 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
526 Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
527
Craig Toppere5e035a32015-12-05 07:13:35 +0000528 return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000529}
530
Colin LeMahieu7c958712015-10-17 01:33:04 +0000531static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo,
532 uint64_t /*Address*/,
533 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000534 static const MCPhysReg VecDblRegDecoderTable[] = {
Colin LeMahieu7c958712015-10-17 01:33:04 +0000535 Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3,
536 Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7,
537 Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11,
538 Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15};
539
Craig Topper3da000c2015-12-01 06:13:04 +0000540 return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable));
Colin LeMahieu7c958712015-10-17 01:33:04 +0000541}
542
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000543static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
544 uint64_t /*Address*/,
545 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000546 static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
547 Hexagon::P2, Hexagon::P3};
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000548
Craig Toppere5e035a32015-12-05 07:13:35 +0000549 return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000550}
551
Colin LeMahieu7c958712015-10-17 01:33:04 +0000552static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
553 uint64_t /*Address*/,
554 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000555 static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
556 Hexagon::Q2, Hexagon::Q3};
Colin LeMahieu7c958712015-10-17 01:33:04 +0000557
Craig Toppere5e035a32015-12-05 07:13:35 +0000558 return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000559}
Colin LeMahieube8c4532015-06-05 16:00:11 +0000560
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000561static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
562 uint64_t /*Address*/,
563 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000564 static const MCPhysReg CtrlRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000565 Hexagon::SA0, Hexagon::LC0, Hexagon::SA1, Hexagon::LC1,
566 Hexagon::P3_0, Hexagon::C5, Hexagon::C6, Hexagon::C7,
567 Hexagon::USR, Hexagon::PC, Hexagon::UGP, Hexagon::GP,
568 Hexagon::CS0, Hexagon::CS1, Hexagon::UPCL, Hexagon::UPC
569 };
570
Craig Topper6261e1b2015-12-01 06:13:06 +0000571 if (RegNo >= array_lengthof(CtrlRegDecoderTable))
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000572 return MCDisassembler::Fail;
573
574 if (CtrlRegDecoderTable[RegNo] == Hexagon::NoRegister)
575 return MCDisassembler::Fail;
576
577 unsigned Register = CtrlRegDecoderTable[RegNo];
578 Inst.addOperand(MCOperand::createReg(Register));
579 return MCDisassembler::Success;
580}
581
582static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
583 uint64_t /*Address*/,
584 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000585 static const MCPhysReg CtrlReg64DecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000586 Hexagon::C1_0, Hexagon::NoRegister,
587 Hexagon::C3_2, Hexagon::NoRegister,
588 Hexagon::C7_6, Hexagon::NoRegister,
589 Hexagon::C9_8, Hexagon::NoRegister,
590 Hexagon::C11_10, Hexagon::NoRegister,
591 Hexagon::CS, Hexagon::NoRegister,
592 Hexagon::UPC, Hexagon::NoRegister
593 };
594
Craig Topper6261e1b2015-12-01 06:13:06 +0000595 if (RegNo >= array_lengthof(CtrlReg64DecoderTable))
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000596 return MCDisassembler::Fail;
597
598 if (CtrlReg64DecoderTable[RegNo] == Hexagon::NoRegister)
599 return MCDisassembler::Fail;
600
601 unsigned Register = CtrlReg64DecoderTable[RegNo];
602 Inst.addOperand(MCOperand::createReg(Register));
603 return MCDisassembler::Success;
604}
605
606static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
607 uint64_t /*Address*/,
608 const void *Decoder) {
609 unsigned Register = 0;
610 switch (RegNo) {
611 case 0:
612 Register = Hexagon::M0;
613 break;
614 case 1:
615 Register = Hexagon::M1;
616 break;
617 default:
618 return MCDisassembler::Fail;
619 }
620 Inst.addOperand(MCOperand::createReg(Register));
621 return MCDisassembler::Success;
622}
623
624namespace {
625uint32_t fullValue(MCInstrInfo const &MCII,
626 MCInst &MCB,
627 MCInst &MI,
628 int64_t Value) {
629 MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex(
630 MCB, HexagonMCInstrInfo::bundleSize(MCB));
631 if(!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI))
632 return Value;
633 unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI);
634 uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f;
635 int64_t Bits;
636 bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits);
637 assert(Success);(void)Success;
638 uint32_t Upper26 = static_cast<uint32_t>(Bits);
639 uint32_t Operand = Upper26 | Lower6;
640 return Operand;
641}
642template <size_t T>
643void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) {
644 HexagonDisassembler const &Disassembler = disassembler(Decoder);
645 int64_t FullValue = fullValue(*Disassembler.MCII,
646 **Disassembler.CurrentBundle,
647 MI, SignExtend64<T>(tmp));
648 int64_t Extended = SignExtend64<32>(FullValue);
649 HexagonMCInstrInfo::addConstant(MI, Extended,
650 Disassembler.getContext());
651}
652}
653
654static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
655 uint64_t /*Address*/,
656 const void *Decoder) {
657 HexagonDisassembler const &Disassembler = disassembler(Decoder);
658 int64_t FullValue = fullValue(*Disassembler.MCII,
659 **Disassembler.CurrentBundle,
660 MI, tmp);
661 assert(FullValue >= 0 && "Negative in unsigned decoder");
662 HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext());
663 return MCDisassembler::Success;
664}
665
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000666static DecodeStatus s16_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000667 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000668 signedDecoder<16>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000669 return MCDisassembler::Success;
670}
671
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000672static DecodeStatus s12_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000673 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000674 signedDecoder<12>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000675 return MCDisassembler::Success;
676}
677
678static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp,
679 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000680 signedDecoder<11>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000681 return MCDisassembler::Success;
682}
683
684static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp,
685 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000686 HexagonMCInstrInfo::addConstant(MI, SignExtend64<12>(tmp), contextFromDecoder(Decoder));
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000687 return MCDisassembler::Success;
688}
689
690static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp,
691 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000692 signedDecoder<13>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000693 return MCDisassembler::Success;
694}
695
696static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp,
697 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000698 signedDecoder<14>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000699 return MCDisassembler::Success;
700}
701
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000702static DecodeStatus s10_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000703 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000704 signedDecoder<10>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000705 return MCDisassembler::Success;
706}
707
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000708static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t /*Address*/,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000709 const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000710 signedDecoder<8>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000711 return MCDisassembler::Success;
712}
713
714static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp,
715 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000716 signedDecoder<6>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000717 return MCDisassembler::Success;
718}
719
720static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp,
721 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000722 signedDecoder<4>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000723 return MCDisassembler::Success;
724}
725
726static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp,
727 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000728 signedDecoder<5>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000729 return MCDisassembler::Success;
730}
731
732static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp,
733 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000734 signedDecoder<6>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000735 return MCDisassembler::Success;
736}
737
738static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp,
739 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000740 signedDecoder<7>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000741 return MCDisassembler::Success;
742}
743
Colin LeMahieu7c958712015-10-17 01:33:04 +0000744static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp,
745 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000746 signedDecoder<10>(MI, tmp, Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000747 return MCDisassembler::Success;
748}
749
750static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp,
751 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000752 signedDecoder<19>(MI, tmp, Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000753 return MCDisassembler::Success;
754}
755
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000756// custom decoder for various jump/call immediates
757static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
758 const void *Decoder) {
759 HexagonDisassembler const &Disassembler = disassembler(Decoder);
760 unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI);
761 // r13_2 is not extendable, so if there are no extent bits, it's r13_2
762 if (Bits == 0)
763 Bits = 15;
764 uint32_t FullValue = fullValue(*Disassembler.MCII,
765 **Disassembler.CurrentBundle,
766 MI, SignExtend64(tmp, Bits));
767 int64_t Extended = SignExtend64<32>(FullValue) + Address;
768 if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true,
769 0, 4))
770 HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext());
771 return MCDisassembler::Success;
772}
773
774// Addressing mode dependent load store opcode map.
775// - If an insn is preceded by an extender the address is absolute.
776// - memw(##symbol) = r0
777// - If an insn is not preceded by an extender the address is GP relative.
778// - memw(gp + #symbol) = r0
779// Please note that the instructions must be ordered in the descending order
780// of their opcode.
781// HexagonII::INST_ICLASS_ST
Craig Topperd824f5f2015-12-01 06:13:08 +0000782static const unsigned int StoreConditionalOpcodeData[][2] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000783 {S4_pstorerdfnew_abs, 0xafc02084},
784 {S4_pstorerdtnew_abs, 0xafc02080},
785 {S4_pstorerdf_abs, 0xafc00084},
786 {S4_pstorerdt_abs, 0xafc00080},
787 {S4_pstorerinewfnew_abs, 0xafa03084},
788 {S4_pstorerinewtnew_abs, 0xafa03080},
789 {S4_pstorerhnewfnew_abs, 0xafa02884},
790 {S4_pstorerhnewtnew_abs, 0xafa02880},
791 {S4_pstorerbnewfnew_abs, 0xafa02084},
792 {S4_pstorerbnewtnew_abs, 0xafa02080},
793 {S4_pstorerinewf_abs, 0xafa01084},
794 {S4_pstorerinewt_abs, 0xafa01080},
795 {S4_pstorerhnewf_abs, 0xafa00884},
796 {S4_pstorerhnewt_abs, 0xafa00880},
797 {S4_pstorerbnewf_abs, 0xafa00084},
798 {S4_pstorerbnewt_abs, 0xafa00080},
799 {S4_pstorerifnew_abs, 0xaf802084},
800 {S4_pstoreritnew_abs, 0xaf802080},
801 {S4_pstorerif_abs, 0xaf800084},
802 {S4_pstorerit_abs, 0xaf800080},
803 {S4_pstorerhfnew_abs, 0xaf402084},
804 {S4_pstorerhtnew_abs, 0xaf402080},
805 {S4_pstorerhf_abs, 0xaf400084},
806 {S4_pstorerht_abs, 0xaf400080},
807 {S4_pstorerbfnew_abs, 0xaf002084},
808 {S4_pstorerbtnew_abs, 0xaf002080},
809 {S4_pstorerbf_abs, 0xaf000084},
810 {S4_pstorerbt_abs, 0xaf000080}};
811// HexagonII::INST_ICLASS_LD
812
813// HexagonII::INST_ICLASS_LD_ST_2
Colin LeMahieu9675de52016-10-06 23:02:11 +0000814static unsigned int LoadStoreOpcodeData[][2] = {{PS_loadrdabs, 0x49c00000},
815 {PS_loadriabs, 0x49800000},
816 {PS_loadruhabs, 0x49600000},
817 {PS_loadrhabs, 0x49400000},
818 {PS_loadrubabs, 0x49200000},
819 {PS_loadrbabs, 0x49000000},
820 {PS_storerdabs, 0x48c00000},
821 {PS_storerinewabs, 0x48a01000},
822 {PS_storerhnewabs, 0x48a00800},
823 {PS_storerbnewabs, 0x48a00000},
824 {PS_storeriabs, 0x48800000},
825 {PS_storerfabs, 0x48600000},
826 {PS_storerhabs, 0x48400000},
827 {PS_storerbabs, 0x48000000}};
Craig Topperd824f5f2015-12-01 06:13:08 +0000828static const size_t NumCondS = array_lengthof(StoreConditionalOpcodeData);
829static const size_t NumLS = array_lengthof(LoadStoreOpcodeData);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000830
831static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn) {
832
833 unsigned MachineOpcode = 0;
834 unsigned LLVMOpcode = 0;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000835
836 if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_ST) {
Craig Topperd824f5f2015-12-01 06:13:08 +0000837 for (size_t i = 0; i < NumCondS; ++i) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000838 if ((insn & StoreConditionalOpcodeData[i][1]) ==
839 StoreConditionalOpcodeData[i][1]) {
840 MachineOpcode = StoreConditionalOpcodeData[i][1];
841 LLVMOpcode = StoreConditionalOpcodeData[i][0];
842 break;
843 }
844 }
845 }
846 if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_LD_ST_2) {
Craig Topperd824f5f2015-12-01 06:13:08 +0000847 for (size_t i = 0; i < NumLS; ++i) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000848 if ((insn & LoadStoreOpcodeData[i][1]) == LoadStoreOpcodeData[i][1]) {
849 MachineOpcode = LoadStoreOpcodeData[i][1];
850 LLVMOpcode = LoadStoreOpcodeData[i][0];
851 break;
852 }
853 }
854 }
855
856 if (MachineOpcode) {
857 unsigned Value = 0;
858 unsigned shift = 0;
859 MI.setOpcode(LLVMOpcode);
860 // Remove the parse bits from the insn.
861 insn &= ~HexagonII::INST_PARSE_MASK;
862
863 switch (LLVMOpcode) {
864 default:
865 return MCDisassembler::Fail;
866 break;
867
868 case Hexagon::S4_pstorerdf_abs:
869 case Hexagon::S4_pstorerdt_abs:
870 case Hexagon::S4_pstorerdfnew_abs:
871 case Hexagon::S4_pstorerdtnew_abs: {
872 // op: Pv
873 Value = insn & UINT64_C(3);
874 DecodePredRegsRegisterClass(MI, Value, 0, 0);
875 // op: u6
876 Value = (insn >> 12) & UINT64_C(48);
877 Value |= (insn >> 3) & UINT64_C(15);
878 MI.addOperand(MCOperand::createImm(Value));
879 // op: Rtt
880 Value = (insn >> 8) & UINT64_C(31);
881 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
882 break;
883 }
884
885 case Hexagon::S4_pstorerbnewf_abs:
886 case Hexagon::S4_pstorerbnewt_abs:
887 case Hexagon::S4_pstorerbnewfnew_abs:
888 case Hexagon::S4_pstorerbnewtnew_abs:
889 case Hexagon::S4_pstorerhnewf_abs:
890 case Hexagon::S4_pstorerhnewt_abs:
891 case Hexagon::S4_pstorerhnewfnew_abs:
892 case Hexagon::S4_pstorerhnewtnew_abs:
893 case Hexagon::S4_pstorerinewf_abs:
894 case Hexagon::S4_pstorerinewt_abs:
895 case Hexagon::S4_pstorerinewfnew_abs:
896 case Hexagon::S4_pstorerinewtnew_abs: {
897 // op: Pv
898 Value = insn & UINT64_C(3);
899 DecodePredRegsRegisterClass(MI, Value, 0, 0);
900 // op: u6
901 Value = (insn >> 12) & UINT64_C(48);
902 Value |= (insn >> 3) & UINT64_C(15);
903 MI.addOperand(MCOperand::createImm(Value));
904 // op: Nt
905 Value = (insn >> 8) & UINT64_C(7);
906 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
907 break;
908 }
909
910 case Hexagon::S4_pstorerbf_abs:
911 case Hexagon::S4_pstorerbt_abs:
912 case Hexagon::S4_pstorerbfnew_abs:
913 case Hexagon::S4_pstorerbtnew_abs:
914 case Hexagon::S4_pstorerhf_abs:
915 case Hexagon::S4_pstorerht_abs:
916 case Hexagon::S4_pstorerhfnew_abs:
917 case Hexagon::S4_pstorerhtnew_abs:
918 case Hexagon::S4_pstorerif_abs:
919 case Hexagon::S4_pstorerit_abs:
920 case Hexagon::S4_pstorerifnew_abs:
921 case Hexagon::S4_pstoreritnew_abs: {
922 // op: Pv
923 Value = insn & UINT64_C(3);
924 DecodePredRegsRegisterClass(MI, Value, 0, 0);
925 // op: u6
926 Value = (insn >> 12) & UINT64_C(48);
927 Value |= (insn >> 3) & UINT64_C(15);
928 MI.addOperand(MCOperand::createImm(Value));
929 // op: Rt
930 Value = (insn >> 8) & UINT64_C(31);
931 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
932 break;
933 }
934
935 case Hexagon::L4_ploadrdf_abs:
936 case Hexagon::L4_ploadrdt_abs:
937 case Hexagon::L4_ploadrdfnew_abs:
938 case Hexagon::L4_ploadrdtnew_abs: {
939 // op: Rdd
940 Value = insn & UINT64_C(31);
941 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
942 // op: Pt
943 Value = ((insn >> 9) & UINT64_C(3));
944 DecodePredRegsRegisterClass(MI, Value, 0, 0);
945 // op: u6
946 Value = ((insn >> 15) & UINT64_C(62));
947 Value |= ((insn >> 8) & UINT64_C(1));
948 MI.addOperand(MCOperand::createImm(Value));
949 break;
950 }
951
952 case Hexagon::L4_ploadrbf_abs:
953 case Hexagon::L4_ploadrbt_abs:
954 case Hexagon::L4_ploadrbfnew_abs:
955 case Hexagon::L4_ploadrbtnew_abs:
956 case Hexagon::L4_ploadrhf_abs:
957 case Hexagon::L4_ploadrht_abs:
958 case Hexagon::L4_ploadrhfnew_abs:
959 case Hexagon::L4_ploadrhtnew_abs:
960 case Hexagon::L4_ploadrubf_abs:
961 case Hexagon::L4_ploadrubt_abs:
962 case Hexagon::L4_ploadrubfnew_abs:
963 case Hexagon::L4_ploadrubtnew_abs:
964 case Hexagon::L4_ploadruhf_abs:
965 case Hexagon::L4_ploadruht_abs:
966 case Hexagon::L4_ploadruhfnew_abs:
967 case Hexagon::L4_ploadruhtnew_abs:
968 case Hexagon::L4_ploadrif_abs:
969 case Hexagon::L4_ploadrit_abs:
970 case Hexagon::L4_ploadrifnew_abs:
971 case Hexagon::L4_ploadritnew_abs:
972 // op: Rd
973 Value = insn & UINT64_C(31);
974 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
975 // op: Pt
976 Value = (insn >> 9) & UINT64_C(3);
977 DecodePredRegsRegisterClass(MI, Value, 0, 0);
978 // op: u6
979 Value = (insn >> 15) & UINT64_C(62);
980 Value |= (insn >> 8) & UINT64_C(1);
981 MI.addOperand(MCOperand::createImm(Value));
982 break;
983
984 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +0000985 case (Hexagon::PS_loadriabs):
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000986 ++shift;
987 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +0000988 case Hexagon::PS_loadrhabs:
989 case Hexagon::PS_loadruhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000990 ++shift;
991 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +0000992 case Hexagon::PS_loadrbabs:
993 case Hexagon::PS_loadrubabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000994 // op: Rd
995 Value |= insn & UINT64_C(31);
996 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
997 Value = (insn >> 11) & UINT64_C(49152);
998 Value |= (insn >> 7) & UINT64_C(15872);
999 Value |= (insn >> 5) & UINT64_C(511);
1000 MI.addOperand(MCOperand::createImm(Value << shift));
1001 break;
1002 }
1003
Colin LeMahieu9675de52016-10-06 23:02:11 +00001004 case Hexagon::PS_loadrdabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001005 Value = insn & UINT64_C(31);
1006 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
1007 Value = (insn >> 11) & UINT64_C(49152);
1008 Value |= (insn >> 7) & UINT64_C(15872);
1009 Value |= (insn >> 5) & UINT64_C(511);
1010 MI.addOperand(MCOperand::createImm(Value << 3));
1011 break;
1012 }
1013
Colin LeMahieu9675de52016-10-06 23:02:11 +00001014 case Hexagon::PS_storerdabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001015 // op: g16_3
1016 Value = (insn >> 11) & UINT64_C(49152);
1017 Value |= (insn >> 7) & UINT64_C(15872);
1018 Value |= (insn >> 5) & UINT64_C(256);
1019 Value |= insn & UINT64_C(255);
1020 MI.addOperand(MCOperand::createImm(Value << 3));
1021 // op: Rtt
1022 Value = (insn >> 8) & UINT64_C(31);
1023 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
1024 break;
1025 }
1026
1027 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001028 case Hexagon::PS_storerinewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001029 ++shift;
1030 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001031 case Hexagon::PS_storerhnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001032 ++shift;
1033 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001034 case Hexagon::PS_storerbnewabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001035 Value = (insn >> 11) & UINT64_C(49152);
1036 Value |= (insn >> 7) & UINT64_C(15872);
1037 Value |= (insn >> 5) & UINT64_C(256);
1038 Value |= insn & UINT64_C(255);
1039 MI.addOperand(MCOperand::createImm(Value << shift));
1040 // op: Nt
1041 Value = (insn >> 8) & UINT64_C(7);
1042 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1043 break;
1044 }
1045
1046 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001047 case Hexagon::PS_storeriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001048 ++shift;
1049 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001050 case Hexagon::PS_storerhabs:
1051 case Hexagon::PS_storerfabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001052 ++shift;
1053 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001054 case Hexagon::PS_storerbabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001055 Value = (insn >> 11) & UINT64_C(49152);
1056 Value |= (insn >> 7) & UINT64_C(15872);
1057 Value |= (insn >> 5) & UINT64_C(256);
1058 Value |= insn & UINT64_C(255);
1059 MI.addOperand(MCOperand::createImm(Value << shift));
1060 // op: Rt
1061 Value = (insn >> 8) & UINT64_C(31);
1062 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1063 break;
1064 }
1065 }
1066 return MCDisassembler::Success;
1067 }
1068 return MCDisassembler::Fail;
1069}
1070
1071static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn,
1072 void const *Decoder) {
1073
1074 // Instruction Class for a constant a extender: bits 31:28 = 0x0000
1075 if ((~insn & 0xf0000000) == 0xf0000000) {
1076 unsigned Value;
1077 // 27:16 High 12 bits of 26-bit extender.
1078 Value = (insn & 0x0fff0000) << 4;
1079 // 13:0 Low 14 bits of 26-bit extender.
1080 Value |= ((insn & 0x3fff) << 6);
1081 MI.setOpcode(Hexagon::A4_ext);
1082 HexagonMCInstrInfo::addConstant(MI, Value, contextFromDecoder(Decoder));
1083 return MCDisassembler::Success;
1084 }
1085 return MCDisassembler::Fail;
1086}
1087
Colin LeMahieube8c4532015-06-05 16:00:11 +00001088// These values are from HexagonGenMCCodeEmitter.inc and HexagonIsetDx.td
1089enum subInstBinaryValues {
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001090 SA1_addi_BITS = 0x0000,
1091 SA1_addi_MASK = 0x1800,
1092 SA1_addrx_BITS = 0x1800,
1093 SA1_addrx_MASK = 0x1f00,
1094 SA1_addsp_BITS = 0x0c00,
1095 SA1_addsp_MASK = 0x1c00,
1096 SA1_and1_BITS = 0x1200,
1097 SA1_and1_MASK = 0x1f00,
1098 SA1_clrf_BITS = 0x1a70,
1099 SA1_clrf_MASK = 0x1e70,
1100 SA1_clrfnew_BITS = 0x1a50,
1101 SA1_clrfnew_MASK = 0x1e70,
1102 SA1_clrt_BITS = 0x1a60,
1103 SA1_clrt_MASK = 0x1e70,
1104 SA1_clrtnew_BITS = 0x1a40,
1105 SA1_clrtnew_MASK = 0x1e70,
1106 SA1_cmpeqi_BITS = 0x1900,
1107 SA1_cmpeqi_MASK = 0x1f00,
1108 SA1_combine0i_BITS = 0x1c00,
1109 SA1_combine0i_MASK = 0x1d18,
1110 SA1_combine1i_BITS = 0x1c08,
1111 SA1_combine1i_MASK = 0x1d18,
1112 SA1_combine2i_BITS = 0x1c10,
1113 SA1_combine2i_MASK = 0x1d18,
1114 SA1_combine3i_BITS = 0x1c18,
1115 SA1_combine3i_MASK = 0x1d18,
1116 SA1_combinerz_BITS = 0x1d08,
1117 SA1_combinerz_MASK = 0x1d08,
1118 SA1_combinezr_BITS = 0x1d00,
1119 SA1_combinezr_MASK = 0x1d08,
1120 SA1_dec_BITS = 0x1300,
1121 SA1_dec_MASK = 0x1f00,
1122 SA1_inc_BITS = 0x1100,
1123 SA1_inc_MASK = 0x1f00,
1124 SA1_seti_BITS = 0x0800,
1125 SA1_seti_MASK = 0x1c00,
1126 SA1_setin1_BITS = 0x1a00,
1127 SA1_setin1_MASK = 0x1e40,
1128 SA1_sxtb_BITS = 0x1500,
1129 SA1_sxtb_MASK = 0x1f00,
1130 SA1_sxth_BITS = 0x1400,
1131 SA1_sxth_MASK = 0x1f00,
1132 SA1_tfr_BITS = 0x1000,
1133 SA1_tfr_MASK = 0x1f00,
1134 SA1_zxtb_BITS = 0x1700,
1135 SA1_zxtb_MASK = 0x1f00,
1136 SA1_zxth_BITS = 0x1600,
1137 SA1_zxth_MASK = 0x1f00,
1138 SL1_loadri_io_BITS = 0x0000,
1139 SL1_loadri_io_MASK = 0x1000,
1140 SL1_loadrub_io_BITS = 0x1000,
1141 SL1_loadrub_io_MASK = 0x1000,
1142 SL2_deallocframe_BITS = 0x1f00,
1143 SL2_deallocframe_MASK = 0x1fc0,
1144 SL2_jumpr31_BITS = 0x1fc0,
1145 SL2_jumpr31_MASK = 0x1fc4,
1146 SL2_jumpr31_f_BITS = 0x1fc5,
1147 SL2_jumpr31_f_MASK = 0x1fc7,
1148 SL2_jumpr31_fnew_BITS = 0x1fc7,
1149 SL2_jumpr31_fnew_MASK = 0x1fc7,
1150 SL2_jumpr31_t_BITS = 0x1fc4,
1151 SL2_jumpr31_t_MASK = 0x1fc7,
1152 SL2_jumpr31_tnew_BITS = 0x1fc6,
1153 SL2_jumpr31_tnew_MASK = 0x1fc7,
1154 SL2_loadrb_io_BITS = 0x1000,
1155 SL2_loadrb_io_MASK = 0x1800,
1156 SL2_loadrd_sp_BITS = 0x1e00,
1157 SL2_loadrd_sp_MASK = 0x1f00,
1158 SL2_loadrh_io_BITS = 0x0000,
1159 SL2_loadrh_io_MASK = 0x1800,
1160 SL2_loadri_sp_BITS = 0x1c00,
1161 SL2_loadri_sp_MASK = 0x1e00,
1162 SL2_loadruh_io_BITS = 0x0800,
1163 SL2_loadruh_io_MASK = 0x1800,
1164 SL2_return_BITS = 0x1f40,
1165 SL2_return_MASK = 0x1fc4,
1166 SL2_return_f_BITS = 0x1f45,
1167 SL2_return_f_MASK = 0x1fc7,
1168 SL2_return_fnew_BITS = 0x1f47,
1169 SL2_return_fnew_MASK = 0x1fc7,
1170 SL2_return_t_BITS = 0x1f44,
1171 SL2_return_t_MASK = 0x1fc7,
1172 SL2_return_tnew_BITS = 0x1f46,
1173 SL2_return_tnew_MASK = 0x1fc7,
1174 SS1_storeb_io_BITS = 0x1000,
1175 SS1_storeb_io_MASK = 0x1000,
1176 SS1_storew_io_BITS = 0x0000,
1177 SS1_storew_io_MASK = 0x1000,
1178 SS2_allocframe_BITS = 0x1c00,
1179 SS2_allocframe_MASK = 0x1e00,
1180 SS2_storebi0_BITS = 0x1200,
1181 SS2_storebi0_MASK = 0x1f00,
1182 SS2_storebi1_BITS = 0x1300,
1183 SS2_storebi1_MASK = 0x1f00,
1184 SS2_stored_sp_BITS = 0x0a00,
1185 SS2_stored_sp_MASK = 0x1e00,
1186 SS2_storeh_io_BITS = 0x0000,
1187 SS2_storeh_io_MASK = 0x1800,
1188 SS2_storew_sp_BITS = 0x0800,
1189 SS2_storew_sp_MASK = 0x1e00,
1190 SS2_storewi0_BITS = 0x1000,
1191 SS2_storewi0_MASK = 0x1f00,
1192 SS2_storewi1_BITS = 0x1100,
1193 SS2_storewi1_MASK = 0x1f00
Colin LeMahieube8c4532015-06-05 16:00:11 +00001194};
1195
1196static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op,
1197 raw_ostream &os) {
1198 switch (IClass) {
1199 case HexagonII::HSIG_L1:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001200 if ((inst & SL1_loadri_io_MASK) == SL1_loadri_io_BITS)
1201 op = Hexagon::SL1_loadri_io;
1202 else if ((inst & SL1_loadrub_io_MASK) == SL1_loadrub_io_BITS)
1203 op = Hexagon::SL1_loadrub_io;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001204 else {
1205 os << "<unknown subinstruction>";
1206 return MCDisassembler::Fail;
1207 }
1208 break;
1209 case HexagonII::HSIG_L2:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001210 if ((inst & SL2_deallocframe_MASK) == SL2_deallocframe_BITS)
1211 op = Hexagon::SL2_deallocframe;
1212 else if ((inst & SL2_jumpr31_MASK) == SL2_jumpr31_BITS)
1213 op = Hexagon::SL2_jumpr31;
1214 else if ((inst & SL2_jumpr31_f_MASK) == SL2_jumpr31_f_BITS)
1215 op = Hexagon::SL2_jumpr31_f;
1216 else if ((inst & SL2_jumpr31_fnew_MASK) == SL2_jumpr31_fnew_BITS)
1217 op = Hexagon::SL2_jumpr31_fnew;
1218 else if ((inst & SL2_jumpr31_t_MASK) == SL2_jumpr31_t_BITS)
1219 op = Hexagon::SL2_jumpr31_t;
1220 else if ((inst & SL2_jumpr31_tnew_MASK) == SL2_jumpr31_tnew_BITS)
1221 op = Hexagon::SL2_jumpr31_tnew;
1222 else if ((inst & SL2_loadrb_io_MASK) == SL2_loadrb_io_BITS)
1223 op = Hexagon::SL2_loadrb_io;
1224 else if ((inst & SL2_loadrd_sp_MASK) == SL2_loadrd_sp_BITS)
1225 op = Hexagon::SL2_loadrd_sp;
1226 else if ((inst & SL2_loadrh_io_MASK) == SL2_loadrh_io_BITS)
1227 op = Hexagon::SL2_loadrh_io;
1228 else if ((inst & SL2_loadri_sp_MASK) == SL2_loadri_sp_BITS)
1229 op = Hexagon::SL2_loadri_sp;
1230 else if ((inst & SL2_loadruh_io_MASK) == SL2_loadruh_io_BITS)
1231 op = Hexagon::SL2_loadruh_io;
1232 else if ((inst & SL2_return_MASK) == SL2_return_BITS)
1233 op = Hexagon::SL2_return;
1234 else if ((inst & SL2_return_f_MASK) == SL2_return_f_BITS)
1235 op = Hexagon::SL2_return_f;
1236 else if ((inst & SL2_return_fnew_MASK) == SL2_return_fnew_BITS)
1237 op = Hexagon::SL2_return_fnew;
1238 else if ((inst & SL2_return_t_MASK) == SL2_return_t_BITS)
1239 op = Hexagon::SL2_return_t;
1240 else if ((inst & SL2_return_tnew_MASK) == SL2_return_tnew_BITS)
1241 op = Hexagon::SL2_return_tnew;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001242 else {
1243 os << "<unknown subinstruction>";
1244 return MCDisassembler::Fail;
1245 }
1246 break;
1247 case HexagonII::HSIG_A:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001248 if ((inst & SA1_addi_MASK) == SA1_addi_BITS)
1249 op = Hexagon::SA1_addi;
1250 else if ((inst & SA1_addrx_MASK) == SA1_addrx_BITS)
1251 op = Hexagon::SA1_addrx;
1252 else if ((inst & SA1_addsp_MASK) == SA1_addsp_BITS)
1253 op = Hexagon::SA1_addsp;
1254 else if ((inst & SA1_and1_MASK) == SA1_and1_BITS)
1255 op = Hexagon::SA1_and1;
1256 else if ((inst & SA1_clrf_MASK) == SA1_clrf_BITS)
1257 op = Hexagon::SA1_clrf;
1258 else if ((inst & SA1_clrfnew_MASK) == SA1_clrfnew_BITS)
1259 op = Hexagon::SA1_clrfnew;
1260 else if ((inst & SA1_clrt_MASK) == SA1_clrt_BITS)
1261 op = Hexagon::SA1_clrt;
1262 else if ((inst & SA1_clrtnew_MASK) == SA1_clrtnew_BITS)
1263 op = Hexagon::SA1_clrtnew;
1264 else if ((inst & SA1_cmpeqi_MASK) == SA1_cmpeqi_BITS)
1265 op = Hexagon::SA1_cmpeqi;
1266 else if ((inst & SA1_combine0i_MASK) == SA1_combine0i_BITS)
1267 op = Hexagon::SA1_combine0i;
1268 else if ((inst & SA1_combine1i_MASK) == SA1_combine1i_BITS)
1269 op = Hexagon::SA1_combine1i;
1270 else if ((inst & SA1_combine2i_MASK) == SA1_combine2i_BITS)
1271 op = Hexagon::SA1_combine2i;
1272 else if ((inst & SA1_combine3i_MASK) == SA1_combine3i_BITS)
1273 op = Hexagon::SA1_combine3i;
1274 else if ((inst & SA1_combinerz_MASK) == SA1_combinerz_BITS)
1275 op = Hexagon::SA1_combinerz;
1276 else if ((inst & SA1_combinezr_MASK) == SA1_combinezr_BITS)
1277 op = Hexagon::SA1_combinezr;
1278 else if ((inst & SA1_dec_MASK) == SA1_dec_BITS)
1279 op = Hexagon::SA1_dec;
1280 else if ((inst & SA1_inc_MASK) == SA1_inc_BITS)
1281 op = Hexagon::SA1_inc;
1282 else if ((inst & SA1_seti_MASK) == SA1_seti_BITS)
1283 op = Hexagon::SA1_seti;
1284 else if ((inst & SA1_setin1_MASK) == SA1_setin1_BITS)
1285 op = Hexagon::SA1_setin1;
1286 else if ((inst & SA1_sxtb_MASK) == SA1_sxtb_BITS)
1287 op = Hexagon::SA1_sxtb;
1288 else if ((inst & SA1_sxth_MASK) == SA1_sxth_BITS)
1289 op = Hexagon::SA1_sxth;
1290 else if ((inst & SA1_tfr_MASK) == SA1_tfr_BITS)
1291 op = Hexagon::SA1_tfr;
1292 else if ((inst & SA1_zxtb_MASK) == SA1_zxtb_BITS)
1293 op = Hexagon::SA1_zxtb;
1294 else if ((inst & SA1_zxth_MASK) == SA1_zxth_BITS)
1295 op = Hexagon::SA1_zxth;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001296 else {
1297 os << "<unknown subinstruction>";
1298 return MCDisassembler::Fail;
1299 }
1300 break;
1301 case HexagonII::HSIG_S1:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001302 if ((inst & SS1_storeb_io_MASK) == SS1_storeb_io_BITS)
1303 op = Hexagon::SS1_storeb_io;
1304 else if ((inst & SS1_storew_io_MASK) == SS1_storew_io_BITS)
1305 op = Hexagon::SS1_storew_io;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001306 else {
1307 os << "<unknown subinstruction>";
1308 return MCDisassembler::Fail;
1309 }
1310 break;
1311 case HexagonII::HSIG_S2:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001312 if ((inst & SS2_allocframe_MASK) == SS2_allocframe_BITS)
1313 op = Hexagon::SS2_allocframe;
1314 else if ((inst & SS2_storebi0_MASK) == SS2_storebi0_BITS)
1315 op = Hexagon::SS2_storebi0;
1316 else if ((inst & SS2_storebi1_MASK) == SS2_storebi1_BITS)
1317 op = Hexagon::SS2_storebi1;
1318 else if ((inst & SS2_stored_sp_MASK) == SS2_stored_sp_BITS)
1319 op = Hexagon::SS2_stored_sp;
1320 else if ((inst & SS2_storeh_io_MASK) == SS2_storeh_io_BITS)
1321 op = Hexagon::SS2_storeh_io;
1322 else if ((inst & SS2_storew_sp_MASK) == SS2_storew_sp_BITS)
1323 op = Hexagon::SS2_storew_sp;
1324 else if ((inst & SS2_storewi0_MASK) == SS2_storewi0_BITS)
1325 op = Hexagon::SS2_storewi0;
1326 else if ((inst & SS2_storewi1_MASK) == SS2_storewi1_BITS)
1327 op = Hexagon::SS2_storewi1;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001328 else {
1329 os << "<unknown subinstruction>";
1330 return MCDisassembler::Fail;
1331 }
1332 break;
1333 default:
1334 os << "<unknown>";
1335 return MCDisassembler::Fail;
1336 }
1337 return MCDisassembler::Success;
1338}
1339
1340static unsigned getRegFromSubinstEncoding(unsigned encoded_reg) {
1341 if (encoded_reg < 8)
1342 return Hexagon::R0 + encoded_reg;
1343 else if (encoded_reg < 16)
1344 return Hexagon::R0 + encoded_reg + 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001345
1346 // patently false value
Colin LeMahieube8c4532015-06-05 16:00:11 +00001347 return Hexagon::NoRegister;
1348}
1349
1350static unsigned getDRegFromSubinstEncoding(unsigned encoded_dreg) {
1351 if (encoded_dreg < 4)
1352 return Hexagon::D0 + encoded_dreg;
1353 else if (encoded_dreg < 8)
1354 return Hexagon::D0 + encoded_dreg + 4;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001355
1356 // patently false value
Colin LeMahieube8c4532015-06-05 16:00:11 +00001357 return Hexagon::NoRegister;
1358}
1359
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001360void HexagonDisassembler::addSubinstOperands(MCInst *MI, unsigned opcode,
1361 unsigned inst) const {
Colin LeMahieube8c4532015-06-05 16:00:11 +00001362 int64_t operand;
1363 MCOperand Op;
1364 switch (opcode) {
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001365 case Hexagon::SL2_deallocframe:
1366 case Hexagon::SL2_jumpr31:
1367 case Hexagon::SL2_jumpr31_f:
1368 case Hexagon::SL2_jumpr31_fnew:
1369 case Hexagon::SL2_jumpr31_t:
1370 case Hexagon::SL2_jumpr31_tnew:
1371 case Hexagon::SL2_return:
1372 case Hexagon::SL2_return_f:
1373 case Hexagon::SL2_return_fnew:
1374 case Hexagon::SL2_return_t:
1375 case Hexagon::SL2_return_tnew:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001376 // no operands for these instructions
1377 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001378 case Hexagon::SS2_allocframe:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001379 // u 8-4{5_3}
1380 operand = ((inst & 0x1f0) >> 4) << 3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001381 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001382 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001383 case Hexagon::SL1_loadri_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001384 // Rd 3-0, Rs 7-4, u 11-8{4_2}
1385 operand = getRegFromSubinstEncoding(inst & 0xf);
1386 Op = MCOperand::createReg(operand);
1387 MI->addOperand(Op);
1388 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1389 Op = MCOperand::createReg(operand);
1390 MI->addOperand(Op);
1391 operand = (inst & 0xf00) >> 6;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001392 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001393 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001394 case Hexagon::SL1_loadrub_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001395 // Rd 3-0, Rs 7-4, u 11-8
1396 operand = getRegFromSubinstEncoding(inst & 0xf);
1397 Op = MCOperand::createReg(operand);
1398 MI->addOperand(Op);
1399 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1400 Op = MCOperand::createReg(operand);
1401 MI->addOperand(Op);
1402 operand = (inst & 0xf00) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001403 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001404 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001405 case Hexagon::SL2_loadrb_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001406 // Rd 3-0, Rs 7-4, u 10-8
1407 operand = getRegFromSubinstEncoding(inst & 0xf);
1408 Op = MCOperand::createReg(operand);
1409 MI->addOperand(Op);
1410 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1411 Op = MCOperand::createReg(operand);
1412 MI->addOperand(Op);
1413 operand = (inst & 0x700) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001414 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001415 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001416 case Hexagon::SL2_loadrh_io:
1417 case Hexagon::SL2_loadruh_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001418 // Rd 3-0, Rs 7-4, u 10-8{3_1}
1419 operand = getRegFromSubinstEncoding(inst & 0xf);
1420 Op = MCOperand::createReg(operand);
1421 MI->addOperand(Op);
1422 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1423 Op = MCOperand::createReg(operand);
1424 MI->addOperand(Op);
1425 operand = ((inst & 0x700) >> 8) << 1;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001426 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001427 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001428 case Hexagon::SL2_loadrd_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001429 // Rdd 2-0, u 7-3{5_3}
1430 operand = getDRegFromSubinstEncoding(inst & 0x7);
1431 Op = MCOperand::createReg(operand);
1432 MI->addOperand(Op);
1433 operand = ((inst & 0x0f8) >> 3) << 3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001434 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001435 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001436 case Hexagon::SL2_loadri_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001437 // Rd 3-0, u 8-4{5_2}
1438 operand = getRegFromSubinstEncoding(inst & 0xf);
1439 Op = MCOperand::createReg(operand);
1440 MI->addOperand(Op);
1441 operand = ((inst & 0x1f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001442 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001443 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001444 case Hexagon::SA1_addi:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001445 // Rx 3-0 (x2), s7 10-4
1446 operand = getRegFromSubinstEncoding(inst & 0xf);
1447 Op = MCOperand::createReg(operand);
1448 MI->addOperand(Op);
1449 MI->addOperand(Op);
1450 operand = SignExtend64<7>((inst & 0x7f0) >> 4);
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001451 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001452 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001453 case Hexagon::SA1_addrx:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001454 // Rx 3-0 (x2), Rs 7-4
1455 operand = getRegFromSubinstEncoding(inst & 0xf);
1456 Op = MCOperand::createReg(operand);
1457 MI->addOperand(Op);
1458 MI->addOperand(Op);
1459 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1460 Op = MCOperand::createReg(operand);
1461 MI->addOperand(Op);
Colin LeMahieubb0cdfb2016-03-16 20:00:38 +00001462 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001463 case Hexagon::SA1_and1:
1464 case Hexagon::SA1_dec:
1465 case Hexagon::SA1_inc:
1466 case Hexagon::SA1_sxtb:
1467 case Hexagon::SA1_sxth:
1468 case Hexagon::SA1_tfr:
1469 case Hexagon::SA1_zxtb:
1470 case Hexagon::SA1_zxth:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001471 // Rd 3-0, Rs 7-4
1472 operand = getRegFromSubinstEncoding(inst & 0xf);
1473 Op = MCOperand::createReg(operand);
1474 MI->addOperand(Op);
1475 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1476 Op = MCOperand::createReg(operand);
1477 MI->addOperand(Op);
1478 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001479 case Hexagon::SA1_addsp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001480 // Rd 3-0, u 9-4{6_2}
1481 operand = getRegFromSubinstEncoding(inst & 0xf);
1482 Op = MCOperand::createReg(operand);
1483 MI->addOperand(Op);
1484 operand = ((inst & 0x3f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001485 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001486 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001487 case Hexagon::SA1_seti:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001488 // Rd 3-0, u 9-4
1489 operand = getRegFromSubinstEncoding(inst & 0xf);
1490 Op = MCOperand::createReg(operand);
1491 MI->addOperand(Op);
1492 operand = (inst & 0x3f0) >> 4;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001493 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001494 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001495 case Hexagon::SA1_clrf:
1496 case Hexagon::SA1_clrfnew:
1497 case Hexagon::SA1_clrt:
1498 case Hexagon::SA1_clrtnew:
1499 case Hexagon::SA1_setin1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001500 // Rd 3-0
1501 operand = getRegFromSubinstEncoding(inst & 0xf);
1502 Op = MCOperand::createReg(operand);
1503 MI->addOperand(Op);
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001504 if (opcode == Hexagon::SA1_setin1)
Krzysztof Parzyszek73e0ad82016-09-09 21:45:00 +00001505 break;
1506 MI->addOperand(MCOperand::createReg(Hexagon::P0));
Colin LeMahieube8c4532015-06-05 16:00:11 +00001507 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001508 case Hexagon::SA1_cmpeqi:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001509 // Rs 7-4, u 1-0
1510 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1511 Op = MCOperand::createReg(operand);
1512 MI->addOperand(Op);
1513 operand = inst & 0x3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001514 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001515 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001516 case Hexagon::SA1_combine0i:
1517 case Hexagon::SA1_combine1i:
1518 case Hexagon::SA1_combine2i:
1519 case Hexagon::SA1_combine3i:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001520 // Rdd 2-0, u 6-5
1521 operand = getDRegFromSubinstEncoding(inst & 0x7);
1522 Op = MCOperand::createReg(operand);
1523 MI->addOperand(Op);
1524 operand = (inst & 0x060) >> 5;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001525 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001526 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001527 case Hexagon::SA1_combinerz:
1528 case Hexagon::SA1_combinezr:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001529 // Rdd 2-0, Rs 7-4
1530 operand = getDRegFromSubinstEncoding(inst & 0x7);
1531 Op = MCOperand::createReg(operand);
1532 MI->addOperand(Op);
1533 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1534 Op = MCOperand::createReg(operand);
1535 MI->addOperand(Op);
1536 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001537 case Hexagon::SS1_storeb_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001538 // Rs 7-4, u 11-8, Rt 3-0
1539 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1540 Op = MCOperand::createReg(operand);
1541 MI->addOperand(Op);
1542 operand = (inst & 0xf00) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001543 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001544 operand = getRegFromSubinstEncoding(inst & 0xf);
1545 Op = MCOperand::createReg(operand);
1546 MI->addOperand(Op);
1547 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001548 case Hexagon::SS1_storew_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001549 // Rs 7-4, u 11-8{4_2}, Rt 3-0
1550 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1551 Op = MCOperand::createReg(operand);
1552 MI->addOperand(Op);
1553 operand = ((inst & 0xf00) >> 8) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001554 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001555 operand = getRegFromSubinstEncoding(inst & 0xf);
1556 Op = MCOperand::createReg(operand);
1557 MI->addOperand(Op);
1558 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001559 case Hexagon::SS2_storebi0:
1560 case Hexagon::SS2_storebi1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001561 // Rs 7-4, u 3-0
1562 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1563 Op = MCOperand::createReg(operand);
1564 MI->addOperand(Op);
1565 operand = inst & 0xf;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001566 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001567 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001568 case Hexagon::SS2_storewi0:
1569 case Hexagon::SS2_storewi1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001570 // Rs 7-4, u 3-0{4_2}
1571 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1572 Op = MCOperand::createReg(operand);
1573 MI->addOperand(Op);
1574 operand = (inst & 0xf) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001575 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001576 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001577 case Hexagon::SS2_stored_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001578 // s 8-3{6_3}, Rtt 2-0
1579 operand = SignExtend64<9>(((inst & 0x1f8) >> 3) << 3);
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001580 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001581 operand = getDRegFromSubinstEncoding(inst & 0x7);
1582 Op = MCOperand::createReg(operand);
1583 MI->addOperand(Op);
Colin LeMahieu160f73e2015-11-03 00:21:19 +00001584 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001585 case Hexagon::SS2_storeh_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001586 // Rs 7-4, u 10-8{3_1}, Rt 3-0
1587 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1588 Op = MCOperand::createReg(operand);
1589 MI->addOperand(Op);
1590 operand = ((inst & 0x700) >> 8) << 1;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001591 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001592 operand = getRegFromSubinstEncoding(inst & 0xf);
1593 Op = MCOperand::createReg(operand);
1594 MI->addOperand(Op);
1595 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001596 case Hexagon::SS2_storew_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001597 // u 8-4{5_2}, Rd 3-0
1598 operand = ((inst & 0x1f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001599 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001600 operand = getRegFromSubinstEncoding(inst & 0xf);
1601 Op = MCOperand::createReg(operand);
1602 MI->addOperand(Op);
1603 break;
1604 default:
1605 // don't crash with an invalid subinstruction
1606 // llvm_unreachable("Invalid subinstruction in duplex instruction");
1607 break;
1608 }
1609}