blob: 5c3e5df3ead2b9cfbb49cc312df2760fbc31ec85 [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 LeMahieu81707542016-12-05 04:29:00 +0000343 switch(MI.getOpcode()) {
344 case Hexagon::J4_cmpeqn1_f_jumpnv_nt:
345 case Hexagon::J4_cmpeqn1_f_jumpnv_t:
346 case Hexagon::J4_cmpeqn1_fp0_jump_nt:
347 case Hexagon::J4_cmpeqn1_fp0_jump_t:
348 case Hexagon::J4_cmpeqn1_fp1_jump_nt:
349 case Hexagon::J4_cmpeqn1_fp1_jump_t:
350 case Hexagon::J4_cmpeqn1_t_jumpnv_nt:
351 case Hexagon::J4_cmpeqn1_t_jumpnv_t:
352 case Hexagon::J4_cmpeqn1_tp0_jump_nt:
353 case Hexagon::J4_cmpeqn1_tp0_jump_t:
354 case Hexagon::J4_cmpeqn1_tp1_jump_nt:
355 case Hexagon::J4_cmpeqn1_tp1_jump_t:
356 case Hexagon::J4_cmpgtn1_f_jumpnv_nt:
357 case Hexagon::J4_cmpgtn1_f_jumpnv_t:
358 case Hexagon::J4_cmpgtn1_fp0_jump_nt:
359 case Hexagon::J4_cmpgtn1_fp0_jump_t:
360 case Hexagon::J4_cmpgtn1_fp1_jump_nt:
361 case Hexagon::J4_cmpgtn1_fp1_jump_t:
362 case Hexagon::J4_cmpgtn1_t_jumpnv_nt:
363 case Hexagon::J4_cmpgtn1_t_jumpnv_t:
364 case Hexagon::J4_cmpgtn1_tp0_jump_nt:
365 case Hexagon::J4_cmpgtn1_tp0_jump_t:
366 case Hexagon::J4_cmpgtn1_tp1_jump_nt:
367 case Hexagon::J4_cmpgtn1_tp1_jump_t:
368 MI.insert(MI.begin() + 1, MCOperand::createExpr(MCConstantExpr::create(-1, getContext())));
369 break;
370 default:
371 break;
372 }
373
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000374 if (HexagonMCInstrInfo::isNewValue(*MCII, MI)) {
375 unsigned OpIndex = HexagonMCInstrInfo::getNewValueOp(*MCII, MI);
376 MCOperand &MCO = MI.getOperand(OpIndex);
377 assert(MCO.isReg() && "New value consumers must be registers");
378 unsigned Register =
379 getContext().getRegisterInfo()->getEncodingValue(MCO.getReg());
380 if ((Register & 0x6) == 0)
381 // HexagonPRM 10.11 Bit 1-2 == 0 is reserved
382 return MCDisassembler::Fail;
383 unsigned Lookback = (Register & 0x6) >> 1;
384 unsigned Offset = 1;
385 bool Vector = HexagonMCInstrInfo::isVector(*MCII, MI);
386 auto Instructions = HexagonMCInstrInfo::bundleInstructions(**CurrentBundle);
387 auto i = Instructions.end() - 1;
388 for (auto n = Instructions.begin() - 1;; --i, ++Offset) {
389 if (i == n)
390 // Couldn't find producer
391 return MCDisassembler::Fail;
392 if (Vector && !HexagonMCInstrInfo::isVector(*MCII, *i->getInst()))
393 // Skip scalars when calculating distances for vectors
394 ++Lookback;
395 if (HexagonMCInstrInfo::isImmext(*i->getInst()))
396 ++Lookback;
397 if (Offset == Lookback)
398 break;
399 }
400 auto const &Inst = *i->getInst();
401 bool SubregBit = (Register & 0x1) != 0;
402 if (SubregBit && HexagonMCInstrInfo::hasNewValue2(*MCII, Inst)) {
403 // If subreg bit is set we're selecting the second produced newvalue
404 unsigned Producer =
405 HexagonMCInstrInfo::getNewValueOperand2(*MCII, Inst).getReg();
406 assert(Producer != Hexagon::NoRegister);
407 MCO.setReg(Producer);
408 } else if (HexagonMCInstrInfo::hasNewValue(*MCII, Inst)) {
409 unsigned Producer =
410 HexagonMCInstrInfo::getNewValueOperand(*MCII, Inst).getReg();
411 if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
412 Producer = ((Producer - Hexagon::W0) << 1) + SubregBit + Hexagon::V0;
413 else if (SubregBit)
Colin LeMahieu2d497a02016-03-01 22:05:03 +0000414 // Hexagon PRM 10.11 New-value operands
415 // Nt[0] is reserved and should always be encoded as zero.
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000416 return MCDisassembler::Fail;
417 assert(Producer != Hexagon::NoRegister);
418 MCO.setReg(Producer);
419 } else
420 return MCDisassembler::Fail;
421 }
422
423 adjustExtendedInstructions(MI, MCB);
424 MCInst const *Extender =
425 HexagonMCInstrInfo::extenderForIndex(MCB,
426 HexagonMCInstrInfo::bundleSize(MCB));
427 if(Extender != nullptr) {
428 MCInst const & Inst = HexagonMCInstrInfo::isDuplex(*MCII, MI) ?
429 *MI.getOperand(1).getInst() : MI;
430 if (!HexagonMCInstrInfo::isExtendable(*MCII, Inst) &&
431 !HexagonMCInstrInfo::isExtended(*MCII, Inst))
432 return MCDisassembler::Fail;
433 }
Colin LeMahieu5d6f03b2014-12-04 03:41:21 +0000434 return Result;
NAKAMURA Takumi729be142014-10-27 12:37:26 +0000435}
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000436
437void HexagonDisassembler::adjustExtendedInstructions(MCInst &MCI,
438 MCInst const &MCB) const {
439 if (!HexagonMCInstrInfo::hasExtenderForIndex(
440 MCB, HexagonMCInstrInfo::bundleSize(MCB))) {
441 unsigned opcode;
442 // This code is used by the disassembler to disambiguate between GP
443 // relative and absolute addressing instructions since they both have
444 // same encoding bits. However, an absolute addressing instruction must
445 // follow an immediate extender. Disassembler alwaus select absolute
446 // addressing instructions first and uses this code to change them into
447 // GP relative instruction in the absence of the corresponding immediate
448 // extender.
449 switch (MCI.getOpcode()) {
Colin LeMahieu9675de52016-10-06 23:02:11 +0000450 case Hexagon::PS_storerbabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000451 opcode = Hexagon::S2_storerbgp;
452 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000453 case Hexagon::PS_storerhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000454 opcode = Hexagon::S2_storerhgp;
455 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000456 case Hexagon::PS_storerfabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000457 opcode = Hexagon::S2_storerfgp;
458 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000459 case Hexagon::PS_storeriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000460 opcode = Hexagon::S2_storerigp;
461 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000462 case Hexagon::PS_storerbnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000463 opcode = Hexagon::S2_storerbnewgp;
464 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000465 case Hexagon::PS_storerhnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000466 opcode = Hexagon::S2_storerhnewgp;
467 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000468 case Hexagon::PS_storerinewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000469 opcode = Hexagon::S2_storerinewgp;
470 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000471 case Hexagon::PS_storerdabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000472 opcode = Hexagon::S2_storerdgp;
473 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000474 case Hexagon::PS_loadrbabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000475 opcode = Hexagon::L2_loadrbgp;
476 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000477 case Hexagon::PS_loadrubabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000478 opcode = Hexagon::L2_loadrubgp;
479 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000480 case Hexagon::PS_loadrhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000481 opcode = Hexagon::L2_loadrhgp;
482 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000483 case Hexagon::PS_loadruhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000484 opcode = Hexagon::L2_loadruhgp;
485 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000486 case Hexagon::PS_loadriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000487 opcode = Hexagon::L2_loadrigp;
488 break;
Colin LeMahieu9675de52016-10-06 23:02:11 +0000489 case Hexagon::PS_loadrdabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000490 opcode = Hexagon::L2_loadrdgp;
491 break;
492 default:
493 opcode = MCI.getOpcode();
494 }
495 MCI.setOpcode(opcode);
496 }
497}
498
499namespace llvm {
500extern const MCInstrDesc HexagonInsts[];
501}
502
503static DecodeStatus DecodeRegisterClass(MCInst &Inst, unsigned RegNo,
Craig Toppere5e035a32015-12-05 07:13:35 +0000504 ArrayRef<MCPhysReg> Table) {
Craig Topper3da000c2015-12-01 06:13:04 +0000505 if (RegNo < Table.size()) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000506 Inst.addOperand(MCOperand::createReg(Table[RegNo]));
507 return MCDisassembler::Success;
Craig Topper3da000c2015-12-01 06:13:04 +0000508 }
509
510 return MCDisassembler::Fail;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000511}
512
Colin LeMahieu7c958712015-10-17 01:33:04 +0000513static DecodeStatus DecodeIntRegsLow8RegisterClass(MCInst &Inst, unsigned RegNo,
514 uint64_t Address,
515 const void *Decoder) {
516 return DecodeIntRegsRegisterClass(Inst, RegNo, Address, Decoder);
517}
518
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000519static DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst, unsigned RegNo,
520 uint64_t Address,
521 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000522 static const MCPhysReg IntRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000523 Hexagon::R0, Hexagon::R1, Hexagon::R2, Hexagon::R3, Hexagon::R4,
524 Hexagon::R5, Hexagon::R6, Hexagon::R7, Hexagon::R8, Hexagon::R9,
525 Hexagon::R10, Hexagon::R11, Hexagon::R12, Hexagon::R13, Hexagon::R14,
526 Hexagon::R15, Hexagon::R16, Hexagon::R17, Hexagon::R18, Hexagon::R19,
527 Hexagon::R20, Hexagon::R21, Hexagon::R22, Hexagon::R23, Hexagon::R24,
528 Hexagon::R25, Hexagon::R26, Hexagon::R27, Hexagon::R28, Hexagon::R29,
529 Hexagon::R30, Hexagon::R31};
530
Craig Toppere5e035a32015-12-05 07:13:35 +0000531 return DecodeRegisterClass(Inst, RegNo, IntRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000532}
Colin LeMahieu7c958712015-10-17 01:33:04 +0000533
534static DecodeStatus DecodeVectorRegsRegisterClass(MCInst &Inst, unsigned RegNo,
535 uint64_t /*Address*/,
536 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000537 static const MCPhysReg VecRegDecoderTable[] = {
Colin LeMahieu7c958712015-10-17 01:33:04 +0000538 Hexagon::V0, Hexagon::V1, Hexagon::V2, Hexagon::V3, Hexagon::V4,
539 Hexagon::V5, Hexagon::V6, Hexagon::V7, Hexagon::V8, Hexagon::V9,
540 Hexagon::V10, Hexagon::V11, Hexagon::V12, Hexagon::V13, Hexagon::V14,
541 Hexagon::V15, Hexagon::V16, Hexagon::V17, Hexagon::V18, Hexagon::V19,
542 Hexagon::V20, Hexagon::V21, Hexagon::V22, Hexagon::V23, Hexagon::V24,
543 Hexagon::V25, Hexagon::V26, Hexagon::V27, Hexagon::V28, Hexagon::V29,
544 Hexagon::V30, Hexagon::V31};
545
Craig Toppere5e035a32015-12-05 07:13:35 +0000546 return DecodeRegisterClass(Inst, RegNo, VecRegDecoderTable);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000547}
548
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000549static DecodeStatus DecodeDoubleRegsRegisterClass(MCInst &Inst, unsigned RegNo,
550 uint64_t /*Address*/,
551 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000552 static const MCPhysReg DoubleRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000553 Hexagon::D0, Hexagon::D1, Hexagon::D2, Hexagon::D3,
554 Hexagon::D4, Hexagon::D5, Hexagon::D6, Hexagon::D7,
555 Hexagon::D8, Hexagon::D9, Hexagon::D10, Hexagon::D11,
556 Hexagon::D12, Hexagon::D13, Hexagon::D14, Hexagon::D15};
557
Craig Toppere5e035a32015-12-05 07:13:35 +0000558 return DecodeRegisterClass(Inst, RegNo >> 1, DoubleRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000559}
560
Colin LeMahieu7c958712015-10-17 01:33:04 +0000561static DecodeStatus DecodeVecDblRegsRegisterClass(MCInst &Inst, unsigned RegNo,
562 uint64_t /*Address*/,
563 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000564 static const MCPhysReg VecDblRegDecoderTable[] = {
Colin LeMahieu7c958712015-10-17 01:33:04 +0000565 Hexagon::W0, Hexagon::W1, Hexagon::W2, Hexagon::W3,
566 Hexagon::W4, Hexagon::W5, Hexagon::W6, Hexagon::W7,
567 Hexagon::W8, Hexagon::W9, Hexagon::W10, Hexagon::W11,
568 Hexagon::W12, Hexagon::W13, Hexagon::W14, Hexagon::W15};
569
Craig Topper3da000c2015-12-01 06:13:04 +0000570 return (DecodeRegisterClass(Inst, RegNo >> 1, VecDblRegDecoderTable));
Colin LeMahieu7c958712015-10-17 01:33:04 +0000571}
572
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000573static DecodeStatus DecodePredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
574 uint64_t /*Address*/,
575 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000576 static const MCPhysReg PredRegDecoderTable[] = {Hexagon::P0, Hexagon::P1,
577 Hexagon::P2, Hexagon::P3};
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000578
Craig Toppere5e035a32015-12-05 07:13:35 +0000579 return DecodeRegisterClass(Inst, RegNo, PredRegDecoderTable);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000580}
581
Colin LeMahieu7c958712015-10-17 01:33:04 +0000582static DecodeStatus DecodeVecPredRegsRegisterClass(MCInst &Inst, unsigned RegNo,
583 uint64_t /*Address*/,
584 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000585 static const MCPhysReg VecPredRegDecoderTable[] = {Hexagon::Q0, Hexagon::Q1,
586 Hexagon::Q2, Hexagon::Q3};
Colin LeMahieu7c958712015-10-17 01:33:04 +0000587
Craig Toppere5e035a32015-12-05 07:13:35 +0000588 return DecodeRegisterClass(Inst, RegNo, VecPredRegDecoderTable);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000589}
Colin LeMahieube8c4532015-06-05 16:00:11 +0000590
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000591static DecodeStatus DecodeCtrRegsRegisterClass(MCInst &Inst, unsigned RegNo,
592 uint64_t /*Address*/,
593 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000594 static const MCPhysReg CtrlRegDecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000595 Hexagon::SA0, Hexagon::LC0, Hexagon::SA1, Hexagon::LC1,
596 Hexagon::P3_0, Hexagon::C5, Hexagon::C6, Hexagon::C7,
597 Hexagon::USR, Hexagon::PC, Hexagon::UGP, Hexagon::GP,
598 Hexagon::CS0, Hexagon::CS1, Hexagon::UPCL, Hexagon::UPC
599 };
600
Craig Topper6261e1b2015-12-01 06:13:06 +0000601 if (RegNo >= array_lengthof(CtrlRegDecoderTable))
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000602 return MCDisassembler::Fail;
603
604 if (CtrlRegDecoderTable[RegNo] == Hexagon::NoRegister)
605 return MCDisassembler::Fail;
606
607 unsigned Register = CtrlRegDecoderTable[RegNo];
608 Inst.addOperand(MCOperand::createReg(Register));
609 return MCDisassembler::Success;
610}
611
612static DecodeStatus DecodeCtrRegs64RegisterClass(MCInst &Inst, unsigned RegNo,
613 uint64_t /*Address*/,
614 const void *Decoder) {
Craig Toppere5e035a32015-12-05 07:13:35 +0000615 static const MCPhysReg CtrlReg64DecoderTable[] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000616 Hexagon::C1_0, Hexagon::NoRegister,
617 Hexagon::C3_2, Hexagon::NoRegister,
618 Hexagon::C7_6, Hexagon::NoRegister,
619 Hexagon::C9_8, Hexagon::NoRegister,
620 Hexagon::C11_10, Hexagon::NoRegister,
621 Hexagon::CS, Hexagon::NoRegister,
622 Hexagon::UPC, Hexagon::NoRegister
623 };
624
Craig Topper6261e1b2015-12-01 06:13:06 +0000625 if (RegNo >= array_lengthof(CtrlReg64DecoderTable))
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000626 return MCDisassembler::Fail;
627
628 if (CtrlReg64DecoderTable[RegNo] == Hexagon::NoRegister)
629 return MCDisassembler::Fail;
630
631 unsigned Register = CtrlReg64DecoderTable[RegNo];
632 Inst.addOperand(MCOperand::createReg(Register));
633 return MCDisassembler::Success;
634}
635
636static DecodeStatus DecodeModRegsRegisterClass(MCInst &Inst, unsigned RegNo,
637 uint64_t /*Address*/,
638 const void *Decoder) {
639 unsigned Register = 0;
640 switch (RegNo) {
641 case 0:
642 Register = Hexagon::M0;
643 break;
644 case 1:
645 Register = Hexagon::M1;
646 break;
647 default:
648 return MCDisassembler::Fail;
649 }
650 Inst.addOperand(MCOperand::createReg(Register));
651 return MCDisassembler::Success;
652}
653
654namespace {
655uint32_t fullValue(MCInstrInfo const &MCII,
656 MCInst &MCB,
657 MCInst &MI,
658 int64_t Value) {
659 MCInst const *Extender = HexagonMCInstrInfo::extenderForIndex(
660 MCB, HexagonMCInstrInfo::bundleSize(MCB));
661 if(!Extender || MI.size() != HexagonMCInstrInfo::getExtendableOp(MCII, MI))
662 return Value;
663 unsigned Alignment = HexagonMCInstrInfo::getExtentAlignment(MCII, MI);
664 uint32_t Lower6 = static_cast<uint32_t>(Value >> Alignment) & 0x3f;
665 int64_t Bits;
666 bool Success = Extender->getOperand(0).getExpr()->evaluateAsAbsolute(Bits);
667 assert(Success);(void)Success;
668 uint32_t Upper26 = static_cast<uint32_t>(Bits);
669 uint32_t Operand = Upper26 | Lower6;
670 return Operand;
671}
672template <size_t T>
673void signedDecoder(MCInst &MI, unsigned tmp, const void *Decoder) {
674 HexagonDisassembler const &Disassembler = disassembler(Decoder);
675 int64_t FullValue = fullValue(*Disassembler.MCII,
676 **Disassembler.CurrentBundle,
677 MI, SignExtend64<T>(tmp));
678 int64_t Extended = SignExtend64<32>(FullValue);
679 HexagonMCInstrInfo::addConstant(MI, Extended,
680 Disassembler.getContext());
681}
682}
683
684static DecodeStatus unsignedImmDecoder(MCInst &MI, unsigned tmp,
685 uint64_t /*Address*/,
686 const void *Decoder) {
687 HexagonDisassembler const &Disassembler = disassembler(Decoder);
688 int64_t FullValue = fullValue(*Disassembler.MCII,
689 **Disassembler.CurrentBundle,
690 MI, tmp);
691 assert(FullValue >= 0 && "Negative in unsigned decoder");
692 HexagonMCInstrInfo::addConstant(MI, FullValue, Disassembler.getContext());
693 return MCDisassembler::Success;
694}
695
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000696static DecodeStatus s16_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000697 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000698 signedDecoder<16>(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 s12_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<12>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000705 return MCDisassembler::Success;
706}
707
708static DecodeStatus s11_0ImmDecoder(MCInst &MI, unsigned tmp,
709 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000710 signedDecoder<11>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000711 return MCDisassembler::Success;
712}
713
714static DecodeStatus s11_1ImmDecoder(MCInst &MI, unsigned tmp,
715 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000716 HexagonMCInstrInfo::addConstant(MI, SignExtend64<12>(tmp), contextFromDecoder(Decoder));
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000717 return MCDisassembler::Success;
718}
719
720static DecodeStatus s11_2ImmDecoder(MCInst &MI, unsigned tmp,
721 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000722 signedDecoder<13>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000723 return MCDisassembler::Success;
724}
725
726static DecodeStatus s11_3ImmDecoder(MCInst &MI, unsigned tmp,
727 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000728 signedDecoder<14>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000729 return MCDisassembler::Success;
730}
731
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000732static DecodeStatus s10_0ImmDecoder(MCInst &MI, unsigned tmp,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000733 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000734 signedDecoder<10>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000735 return MCDisassembler::Success;
736}
737
Krzysztof Parzyszek654dc112016-11-01 19:02:10 +0000738static DecodeStatus s8_0ImmDecoder(MCInst &MI, unsigned tmp, uint64_t /*Address*/,
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000739 const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000740 signedDecoder<8>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000741 return MCDisassembler::Success;
742}
743
744static DecodeStatus s6_0ImmDecoder(MCInst &MI, unsigned tmp,
745 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000746 signedDecoder<6>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000747 return MCDisassembler::Success;
748}
749
750static DecodeStatus s4_0ImmDecoder(MCInst &MI, unsigned tmp,
751 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000752 signedDecoder<4>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000753 return MCDisassembler::Success;
754}
755
756static DecodeStatus s4_1ImmDecoder(MCInst &MI, unsigned tmp,
757 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000758 signedDecoder<5>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000759 return MCDisassembler::Success;
760}
761
762static DecodeStatus s4_2ImmDecoder(MCInst &MI, unsigned tmp,
763 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000764 signedDecoder<6>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000765 return MCDisassembler::Success;
766}
767
768static DecodeStatus s4_3ImmDecoder(MCInst &MI, unsigned tmp,
769 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000770 signedDecoder<7>(MI, tmp, Decoder);
Colin LeMahieu1e9d1d72015-06-10 16:52:32 +0000771 return MCDisassembler::Success;
772}
773
Colin LeMahieu7c958712015-10-17 01:33:04 +0000774static DecodeStatus s4_6ImmDecoder(MCInst &MI, unsigned tmp,
775 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000776 signedDecoder<10>(MI, tmp, Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000777 return MCDisassembler::Success;
778}
779
780static DecodeStatus s3_6ImmDecoder(MCInst &MI, unsigned tmp,
781 uint64_t /*Address*/, const void *Decoder) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000782 signedDecoder<19>(MI, tmp, Decoder);
Colin LeMahieu7c958712015-10-17 01:33:04 +0000783 return MCDisassembler::Success;
784}
785
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000786// custom decoder for various jump/call immediates
787static DecodeStatus brtargetDecoder(MCInst &MI, unsigned tmp, uint64_t Address,
788 const void *Decoder) {
789 HexagonDisassembler const &Disassembler = disassembler(Decoder);
790 unsigned Bits = HexagonMCInstrInfo::getExtentBits(*Disassembler.MCII, MI);
791 // r13_2 is not extendable, so if there are no extent bits, it's r13_2
792 if (Bits == 0)
793 Bits = 15;
794 uint32_t FullValue = fullValue(*Disassembler.MCII,
795 **Disassembler.CurrentBundle,
796 MI, SignExtend64(tmp, Bits));
797 int64_t Extended = SignExtend64<32>(FullValue) + Address;
798 if (!Disassembler.tryAddingSymbolicOperand(MI, Extended, Address, true,
799 0, 4))
800 HexagonMCInstrInfo::addConstant(MI, Extended, Disassembler.getContext());
801 return MCDisassembler::Success;
802}
803
804// Addressing mode dependent load store opcode map.
805// - If an insn is preceded by an extender the address is absolute.
806// - memw(##symbol) = r0
807// - If an insn is not preceded by an extender the address is GP relative.
808// - memw(gp + #symbol) = r0
809// Please note that the instructions must be ordered in the descending order
810// of their opcode.
811// HexagonII::INST_ICLASS_ST
Craig Topperd824f5f2015-12-01 06:13:08 +0000812static const unsigned int StoreConditionalOpcodeData[][2] = {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000813 {S4_pstorerdfnew_abs, 0xafc02084},
814 {S4_pstorerdtnew_abs, 0xafc02080},
815 {S4_pstorerdf_abs, 0xafc00084},
816 {S4_pstorerdt_abs, 0xafc00080},
817 {S4_pstorerinewfnew_abs, 0xafa03084},
818 {S4_pstorerinewtnew_abs, 0xafa03080},
819 {S4_pstorerhnewfnew_abs, 0xafa02884},
820 {S4_pstorerhnewtnew_abs, 0xafa02880},
821 {S4_pstorerbnewfnew_abs, 0xafa02084},
822 {S4_pstorerbnewtnew_abs, 0xafa02080},
823 {S4_pstorerinewf_abs, 0xafa01084},
824 {S4_pstorerinewt_abs, 0xafa01080},
825 {S4_pstorerhnewf_abs, 0xafa00884},
826 {S4_pstorerhnewt_abs, 0xafa00880},
827 {S4_pstorerbnewf_abs, 0xafa00084},
828 {S4_pstorerbnewt_abs, 0xafa00080},
829 {S4_pstorerifnew_abs, 0xaf802084},
830 {S4_pstoreritnew_abs, 0xaf802080},
831 {S4_pstorerif_abs, 0xaf800084},
832 {S4_pstorerit_abs, 0xaf800080},
833 {S4_pstorerhfnew_abs, 0xaf402084},
834 {S4_pstorerhtnew_abs, 0xaf402080},
835 {S4_pstorerhf_abs, 0xaf400084},
836 {S4_pstorerht_abs, 0xaf400080},
837 {S4_pstorerbfnew_abs, 0xaf002084},
838 {S4_pstorerbtnew_abs, 0xaf002080},
839 {S4_pstorerbf_abs, 0xaf000084},
840 {S4_pstorerbt_abs, 0xaf000080}};
841// HexagonII::INST_ICLASS_LD
842
843// HexagonII::INST_ICLASS_LD_ST_2
Colin LeMahieu9675de52016-10-06 23:02:11 +0000844static unsigned int LoadStoreOpcodeData[][2] = {{PS_loadrdabs, 0x49c00000},
845 {PS_loadriabs, 0x49800000},
846 {PS_loadruhabs, 0x49600000},
847 {PS_loadrhabs, 0x49400000},
848 {PS_loadrubabs, 0x49200000},
849 {PS_loadrbabs, 0x49000000},
850 {PS_storerdabs, 0x48c00000},
851 {PS_storerinewabs, 0x48a01000},
852 {PS_storerhnewabs, 0x48a00800},
853 {PS_storerbnewabs, 0x48a00000},
854 {PS_storeriabs, 0x48800000},
855 {PS_storerfabs, 0x48600000},
856 {PS_storerhabs, 0x48400000},
857 {PS_storerbabs, 0x48000000}};
Craig Topperd824f5f2015-12-01 06:13:08 +0000858static const size_t NumCondS = array_lengthof(StoreConditionalOpcodeData);
859static const size_t NumLS = array_lengthof(LoadStoreOpcodeData);
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000860
861static DecodeStatus decodeSpecial(MCInst &MI, uint32_t insn) {
862
863 unsigned MachineOpcode = 0;
864 unsigned LLVMOpcode = 0;
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000865
866 if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_ST) {
Craig Topperd824f5f2015-12-01 06:13:08 +0000867 for (size_t i = 0; i < NumCondS; ++i) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000868 if ((insn & StoreConditionalOpcodeData[i][1]) ==
869 StoreConditionalOpcodeData[i][1]) {
870 MachineOpcode = StoreConditionalOpcodeData[i][1];
871 LLVMOpcode = StoreConditionalOpcodeData[i][0];
872 break;
873 }
874 }
875 }
876 if ((insn & HexagonII::INST_ICLASS_MASK) == HexagonII::INST_ICLASS_LD_ST_2) {
Craig Topperd824f5f2015-12-01 06:13:08 +0000877 for (size_t i = 0; i < NumLS; ++i) {
Colin LeMahieu7cd08922015-11-09 04:07:48 +0000878 if ((insn & LoadStoreOpcodeData[i][1]) == LoadStoreOpcodeData[i][1]) {
879 MachineOpcode = LoadStoreOpcodeData[i][1];
880 LLVMOpcode = LoadStoreOpcodeData[i][0];
881 break;
882 }
883 }
884 }
885
886 if (MachineOpcode) {
887 unsigned Value = 0;
888 unsigned shift = 0;
889 MI.setOpcode(LLVMOpcode);
890 // Remove the parse bits from the insn.
891 insn &= ~HexagonII::INST_PARSE_MASK;
892
893 switch (LLVMOpcode) {
894 default:
895 return MCDisassembler::Fail;
896 break;
897
898 case Hexagon::S4_pstorerdf_abs:
899 case Hexagon::S4_pstorerdt_abs:
900 case Hexagon::S4_pstorerdfnew_abs:
901 case Hexagon::S4_pstorerdtnew_abs: {
902 // op: Pv
903 Value = insn & UINT64_C(3);
904 DecodePredRegsRegisterClass(MI, Value, 0, 0);
905 // op: u6
906 Value = (insn >> 12) & UINT64_C(48);
907 Value |= (insn >> 3) & UINT64_C(15);
908 MI.addOperand(MCOperand::createImm(Value));
909 // op: Rtt
910 Value = (insn >> 8) & UINT64_C(31);
911 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
912 break;
913 }
914
915 case Hexagon::S4_pstorerbnewf_abs:
916 case Hexagon::S4_pstorerbnewt_abs:
917 case Hexagon::S4_pstorerbnewfnew_abs:
918 case Hexagon::S4_pstorerbnewtnew_abs:
919 case Hexagon::S4_pstorerhnewf_abs:
920 case Hexagon::S4_pstorerhnewt_abs:
921 case Hexagon::S4_pstorerhnewfnew_abs:
922 case Hexagon::S4_pstorerhnewtnew_abs:
923 case Hexagon::S4_pstorerinewf_abs:
924 case Hexagon::S4_pstorerinewt_abs:
925 case Hexagon::S4_pstorerinewfnew_abs:
926 case Hexagon::S4_pstorerinewtnew_abs: {
927 // op: Pv
928 Value = insn & UINT64_C(3);
929 DecodePredRegsRegisterClass(MI, Value, 0, 0);
930 // op: u6
931 Value = (insn >> 12) & UINT64_C(48);
932 Value |= (insn >> 3) & UINT64_C(15);
933 MI.addOperand(MCOperand::createImm(Value));
934 // op: Nt
935 Value = (insn >> 8) & UINT64_C(7);
936 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
937 break;
938 }
939
940 case Hexagon::S4_pstorerbf_abs:
941 case Hexagon::S4_pstorerbt_abs:
942 case Hexagon::S4_pstorerbfnew_abs:
943 case Hexagon::S4_pstorerbtnew_abs:
944 case Hexagon::S4_pstorerhf_abs:
945 case Hexagon::S4_pstorerht_abs:
946 case Hexagon::S4_pstorerhfnew_abs:
947 case Hexagon::S4_pstorerhtnew_abs:
948 case Hexagon::S4_pstorerif_abs:
949 case Hexagon::S4_pstorerit_abs:
950 case Hexagon::S4_pstorerifnew_abs:
951 case Hexagon::S4_pstoreritnew_abs: {
952 // op: Pv
953 Value = insn & UINT64_C(3);
954 DecodePredRegsRegisterClass(MI, Value, 0, 0);
955 // op: u6
956 Value = (insn >> 12) & UINT64_C(48);
957 Value |= (insn >> 3) & UINT64_C(15);
958 MI.addOperand(MCOperand::createImm(Value));
959 // op: Rt
960 Value = (insn >> 8) & UINT64_C(31);
961 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
962 break;
963 }
964
965 case Hexagon::L4_ploadrdf_abs:
966 case Hexagon::L4_ploadrdt_abs:
967 case Hexagon::L4_ploadrdfnew_abs:
968 case Hexagon::L4_ploadrdtnew_abs: {
969 // op: Rdd
970 Value = insn & UINT64_C(31);
971 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
972 // op: Pt
973 Value = ((insn >> 9) & UINT64_C(3));
974 DecodePredRegsRegisterClass(MI, Value, 0, 0);
975 // op: u6
976 Value = ((insn >> 15) & UINT64_C(62));
977 Value |= ((insn >> 8) & UINT64_C(1));
978 MI.addOperand(MCOperand::createImm(Value));
979 break;
980 }
981
982 case Hexagon::L4_ploadrbf_abs:
983 case Hexagon::L4_ploadrbt_abs:
984 case Hexagon::L4_ploadrbfnew_abs:
985 case Hexagon::L4_ploadrbtnew_abs:
986 case Hexagon::L4_ploadrhf_abs:
987 case Hexagon::L4_ploadrht_abs:
988 case Hexagon::L4_ploadrhfnew_abs:
989 case Hexagon::L4_ploadrhtnew_abs:
990 case Hexagon::L4_ploadrubf_abs:
991 case Hexagon::L4_ploadrubt_abs:
992 case Hexagon::L4_ploadrubfnew_abs:
993 case Hexagon::L4_ploadrubtnew_abs:
994 case Hexagon::L4_ploadruhf_abs:
995 case Hexagon::L4_ploadruht_abs:
996 case Hexagon::L4_ploadruhfnew_abs:
997 case Hexagon::L4_ploadruhtnew_abs:
998 case Hexagon::L4_ploadrif_abs:
999 case Hexagon::L4_ploadrit_abs:
1000 case Hexagon::L4_ploadrifnew_abs:
1001 case Hexagon::L4_ploadritnew_abs:
1002 // op: Rd
1003 Value = insn & UINT64_C(31);
1004 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1005 // op: Pt
1006 Value = (insn >> 9) & UINT64_C(3);
1007 DecodePredRegsRegisterClass(MI, Value, 0, 0);
1008 // op: u6
1009 Value = (insn >> 15) & UINT64_C(62);
1010 Value |= (insn >> 8) & UINT64_C(1);
1011 MI.addOperand(MCOperand::createImm(Value));
1012 break;
1013
1014 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001015 case (Hexagon::PS_loadriabs):
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001016 ++shift;
1017 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001018 case Hexagon::PS_loadrhabs:
1019 case Hexagon::PS_loadruhabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001020 ++shift;
1021 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001022 case Hexagon::PS_loadrbabs:
1023 case Hexagon::PS_loadrubabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001024 // op: Rd
1025 Value |= insn & UINT64_C(31);
1026 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1027 Value = (insn >> 11) & UINT64_C(49152);
1028 Value |= (insn >> 7) & UINT64_C(15872);
1029 Value |= (insn >> 5) & UINT64_C(511);
1030 MI.addOperand(MCOperand::createImm(Value << shift));
1031 break;
1032 }
1033
Colin LeMahieu9675de52016-10-06 23:02:11 +00001034 case Hexagon::PS_loadrdabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001035 Value = insn & UINT64_C(31);
1036 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
1037 Value = (insn >> 11) & UINT64_C(49152);
1038 Value |= (insn >> 7) & UINT64_C(15872);
1039 Value |= (insn >> 5) & UINT64_C(511);
1040 MI.addOperand(MCOperand::createImm(Value << 3));
1041 break;
1042 }
1043
Colin LeMahieu9675de52016-10-06 23:02:11 +00001044 case Hexagon::PS_storerdabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001045 // op: g16_3
1046 Value = (insn >> 11) & UINT64_C(49152);
1047 Value |= (insn >> 7) & UINT64_C(15872);
1048 Value |= (insn >> 5) & UINT64_C(256);
1049 Value |= insn & UINT64_C(255);
1050 MI.addOperand(MCOperand::createImm(Value << 3));
1051 // op: Rtt
1052 Value = (insn >> 8) & UINT64_C(31);
1053 DecodeDoubleRegsRegisterClass(MI, Value, 0, 0);
1054 break;
1055 }
1056
1057 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001058 case Hexagon::PS_storerinewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001059 ++shift;
1060 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001061 case Hexagon::PS_storerhnewabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001062 ++shift;
1063 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001064 case Hexagon::PS_storerbnewabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001065 Value = (insn >> 11) & UINT64_C(49152);
1066 Value |= (insn >> 7) & UINT64_C(15872);
1067 Value |= (insn >> 5) & UINT64_C(256);
1068 Value |= insn & UINT64_C(255);
1069 MI.addOperand(MCOperand::createImm(Value << shift));
1070 // op: Nt
1071 Value = (insn >> 8) & UINT64_C(7);
1072 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1073 break;
1074 }
1075
1076 // op: g16_2
Colin LeMahieu9675de52016-10-06 23:02:11 +00001077 case Hexagon::PS_storeriabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001078 ++shift;
1079 // op: g16_1
Colin LeMahieu9675de52016-10-06 23:02:11 +00001080 case Hexagon::PS_storerhabs:
1081 case Hexagon::PS_storerfabs:
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001082 ++shift;
1083 // op: g16_0
Colin LeMahieu9675de52016-10-06 23:02:11 +00001084 case Hexagon::PS_storerbabs: {
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001085 Value = (insn >> 11) & UINT64_C(49152);
1086 Value |= (insn >> 7) & UINT64_C(15872);
1087 Value |= (insn >> 5) & UINT64_C(256);
1088 Value |= insn & UINT64_C(255);
1089 MI.addOperand(MCOperand::createImm(Value << shift));
1090 // op: Rt
1091 Value = (insn >> 8) & UINT64_C(31);
1092 DecodeIntRegsRegisterClass(MI, Value, 0, 0);
1093 break;
1094 }
1095 }
1096 return MCDisassembler::Success;
1097 }
1098 return MCDisassembler::Fail;
1099}
1100
1101static DecodeStatus decodeImmext(MCInst &MI, uint32_t insn,
1102 void const *Decoder) {
1103
1104 // Instruction Class for a constant a extender: bits 31:28 = 0x0000
1105 if ((~insn & 0xf0000000) == 0xf0000000) {
1106 unsigned Value;
1107 // 27:16 High 12 bits of 26-bit extender.
1108 Value = (insn & 0x0fff0000) << 4;
1109 // 13:0 Low 14 bits of 26-bit extender.
1110 Value |= ((insn & 0x3fff) << 6);
1111 MI.setOpcode(Hexagon::A4_ext);
1112 HexagonMCInstrInfo::addConstant(MI, Value, contextFromDecoder(Decoder));
1113 return MCDisassembler::Success;
1114 }
1115 return MCDisassembler::Fail;
1116}
1117
Colin LeMahieube8c4532015-06-05 16:00:11 +00001118// These values are from HexagonGenMCCodeEmitter.inc and HexagonIsetDx.td
1119enum subInstBinaryValues {
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001120 SA1_addi_BITS = 0x0000,
1121 SA1_addi_MASK = 0x1800,
1122 SA1_addrx_BITS = 0x1800,
1123 SA1_addrx_MASK = 0x1f00,
1124 SA1_addsp_BITS = 0x0c00,
1125 SA1_addsp_MASK = 0x1c00,
1126 SA1_and1_BITS = 0x1200,
1127 SA1_and1_MASK = 0x1f00,
1128 SA1_clrf_BITS = 0x1a70,
1129 SA1_clrf_MASK = 0x1e70,
1130 SA1_clrfnew_BITS = 0x1a50,
1131 SA1_clrfnew_MASK = 0x1e70,
1132 SA1_clrt_BITS = 0x1a60,
1133 SA1_clrt_MASK = 0x1e70,
1134 SA1_clrtnew_BITS = 0x1a40,
1135 SA1_clrtnew_MASK = 0x1e70,
1136 SA1_cmpeqi_BITS = 0x1900,
1137 SA1_cmpeqi_MASK = 0x1f00,
1138 SA1_combine0i_BITS = 0x1c00,
1139 SA1_combine0i_MASK = 0x1d18,
1140 SA1_combine1i_BITS = 0x1c08,
1141 SA1_combine1i_MASK = 0x1d18,
1142 SA1_combine2i_BITS = 0x1c10,
1143 SA1_combine2i_MASK = 0x1d18,
1144 SA1_combine3i_BITS = 0x1c18,
1145 SA1_combine3i_MASK = 0x1d18,
1146 SA1_combinerz_BITS = 0x1d08,
1147 SA1_combinerz_MASK = 0x1d08,
1148 SA1_combinezr_BITS = 0x1d00,
1149 SA1_combinezr_MASK = 0x1d08,
1150 SA1_dec_BITS = 0x1300,
1151 SA1_dec_MASK = 0x1f00,
1152 SA1_inc_BITS = 0x1100,
1153 SA1_inc_MASK = 0x1f00,
1154 SA1_seti_BITS = 0x0800,
1155 SA1_seti_MASK = 0x1c00,
1156 SA1_setin1_BITS = 0x1a00,
1157 SA1_setin1_MASK = 0x1e40,
1158 SA1_sxtb_BITS = 0x1500,
1159 SA1_sxtb_MASK = 0x1f00,
1160 SA1_sxth_BITS = 0x1400,
1161 SA1_sxth_MASK = 0x1f00,
1162 SA1_tfr_BITS = 0x1000,
1163 SA1_tfr_MASK = 0x1f00,
1164 SA1_zxtb_BITS = 0x1700,
1165 SA1_zxtb_MASK = 0x1f00,
1166 SA1_zxth_BITS = 0x1600,
1167 SA1_zxth_MASK = 0x1f00,
1168 SL1_loadri_io_BITS = 0x0000,
1169 SL1_loadri_io_MASK = 0x1000,
1170 SL1_loadrub_io_BITS = 0x1000,
1171 SL1_loadrub_io_MASK = 0x1000,
1172 SL2_deallocframe_BITS = 0x1f00,
1173 SL2_deallocframe_MASK = 0x1fc0,
1174 SL2_jumpr31_BITS = 0x1fc0,
1175 SL2_jumpr31_MASK = 0x1fc4,
1176 SL2_jumpr31_f_BITS = 0x1fc5,
1177 SL2_jumpr31_f_MASK = 0x1fc7,
1178 SL2_jumpr31_fnew_BITS = 0x1fc7,
1179 SL2_jumpr31_fnew_MASK = 0x1fc7,
1180 SL2_jumpr31_t_BITS = 0x1fc4,
1181 SL2_jumpr31_t_MASK = 0x1fc7,
1182 SL2_jumpr31_tnew_BITS = 0x1fc6,
1183 SL2_jumpr31_tnew_MASK = 0x1fc7,
1184 SL2_loadrb_io_BITS = 0x1000,
1185 SL2_loadrb_io_MASK = 0x1800,
1186 SL2_loadrd_sp_BITS = 0x1e00,
1187 SL2_loadrd_sp_MASK = 0x1f00,
1188 SL2_loadrh_io_BITS = 0x0000,
1189 SL2_loadrh_io_MASK = 0x1800,
1190 SL2_loadri_sp_BITS = 0x1c00,
1191 SL2_loadri_sp_MASK = 0x1e00,
1192 SL2_loadruh_io_BITS = 0x0800,
1193 SL2_loadruh_io_MASK = 0x1800,
1194 SL2_return_BITS = 0x1f40,
1195 SL2_return_MASK = 0x1fc4,
1196 SL2_return_f_BITS = 0x1f45,
1197 SL2_return_f_MASK = 0x1fc7,
1198 SL2_return_fnew_BITS = 0x1f47,
1199 SL2_return_fnew_MASK = 0x1fc7,
1200 SL2_return_t_BITS = 0x1f44,
1201 SL2_return_t_MASK = 0x1fc7,
1202 SL2_return_tnew_BITS = 0x1f46,
1203 SL2_return_tnew_MASK = 0x1fc7,
1204 SS1_storeb_io_BITS = 0x1000,
1205 SS1_storeb_io_MASK = 0x1000,
1206 SS1_storew_io_BITS = 0x0000,
1207 SS1_storew_io_MASK = 0x1000,
1208 SS2_allocframe_BITS = 0x1c00,
1209 SS2_allocframe_MASK = 0x1e00,
1210 SS2_storebi0_BITS = 0x1200,
1211 SS2_storebi0_MASK = 0x1f00,
1212 SS2_storebi1_BITS = 0x1300,
1213 SS2_storebi1_MASK = 0x1f00,
1214 SS2_stored_sp_BITS = 0x0a00,
1215 SS2_stored_sp_MASK = 0x1e00,
1216 SS2_storeh_io_BITS = 0x0000,
1217 SS2_storeh_io_MASK = 0x1800,
1218 SS2_storew_sp_BITS = 0x0800,
1219 SS2_storew_sp_MASK = 0x1e00,
1220 SS2_storewi0_BITS = 0x1000,
1221 SS2_storewi0_MASK = 0x1f00,
1222 SS2_storewi1_BITS = 0x1100,
1223 SS2_storewi1_MASK = 0x1f00
Colin LeMahieube8c4532015-06-05 16:00:11 +00001224};
1225
1226static unsigned GetSubinstOpcode(unsigned IClass, unsigned inst, unsigned &op,
1227 raw_ostream &os) {
1228 switch (IClass) {
1229 case HexagonII::HSIG_L1:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001230 if ((inst & SL1_loadri_io_MASK) == SL1_loadri_io_BITS)
1231 op = Hexagon::SL1_loadri_io;
1232 else if ((inst & SL1_loadrub_io_MASK) == SL1_loadrub_io_BITS)
1233 op = Hexagon::SL1_loadrub_io;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001234 else {
1235 os << "<unknown subinstruction>";
1236 return MCDisassembler::Fail;
1237 }
1238 break;
1239 case HexagonII::HSIG_L2:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001240 if ((inst & SL2_deallocframe_MASK) == SL2_deallocframe_BITS)
1241 op = Hexagon::SL2_deallocframe;
1242 else if ((inst & SL2_jumpr31_MASK) == SL2_jumpr31_BITS)
1243 op = Hexagon::SL2_jumpr31;
1244 else if ((inst & SL2_jumpr31_f_MASK) == SL2_jumpr31_f_BITS)
1245 op = Hexagon::SL2_jumpr31_f;
1246 else if ((inst & SL2_jumpr31_fnew_MASK) == SL2_jumpr31_fnew_BITS)
1247 op = Hexagon::SL2_jumpr31_fnew;
1248 else if ((inst & SL2_jumpr31_t_MASK) == SL2_jumpr31_t_BITS)
1249 op = Hexagon::SL2_jumpr31_t;
1250 else if ((inst & SL2_jumpr31_tnew_MASK) == SL2_jumpr31_tnew_BITS)
1251 op = Hexagon::SL2_jumpr31_tnew;
1252 else if ((inst & SL2_loadrb_io_MASK) == SL2_loadrb_io_BITS)
1253 op = Hexagon::SL2_loadrb_io;
1254 else if ((inst & SL2_loadrd_sp_MASK) == SL2_loadrd_sp_BITS)
1255 op = Hexagon::SL2_loadrd_sp;
1256 else if ((inst & SL2_loadrh_io_MASK) == SL2_loadrh_io_BITS)
1257 op = Hexagon::SL2_loadrh_io;
1258 else if ((inst & SL2_loadri_sp_MASK) == SL2_loadri_sp_BITS)
1259 op = Hexagon::SL2_loadri_sp;
1260 else if ((inst & SL2_loadruh_io_MASK) == SL2_loadruh_io_BITS)
1261 op = Hexagon::SL2_loadruh_io;
1262 else if ((inst & SL2_return_MASK) == SL2_return_BITS)
1263 op = Hexagon::SL2_return;
1264 else if ((inst & SL2_return_f_MASK) == SL2_return_f_BITS)
1265 op = Hexagon::SL2_return_f;
1266 else if ((inst & SL2_return_fnew_MASK) == SL2_return_fnew_BITS)
1267 op = Hexagon::SL2_return_fnew;
1268 else if ((inst & SL2_return_t_MASK) == SL2_return_t_BITS)
1269 op = Hexagon::SL2_return_t;
1270 else if ((inst & SL2_return_tnew_MASK) == SL2_return_tnew_BITS)
1271 op = Hexagon::SL2_return_tnew;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001272 else {
1273 os << "<unknown subinstruction>";
1274 return MCDisassembler::Fail;
1275 }
1276 break;
1277 case HexagonII::HSIG_A:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001278 if ((inst & SA1_addi_MASK) == SA1_addi_BITS)
1279 op = Hexagon::SA1_addi;
1280 else if ((inst & SA1_addrx_MASK) == SA1_addrx_BITS)
1281 op = Hexagon::SA1_addrx;
1282 else if ((inst & SA1_addsp_MASK) == SA1_addsp_BITS)
1283 op = Hexagon::SA1_addsp;
1284 else if ((inst & SA1_and1_MASK) == SA1_and1_BITS)
1285 op = Hexagon::SA1_and1;
1286 else if ((inst & SA1_clrf_MASK) == SA1_clrf_BITS)
1287 op = Hexagon::SA1_clrf;
1288 else if ((inst & SA1_clrfnew_MASK) == SA1_clrfnew_BITS)
1289 op = Hexagon::SA1_clrfnew;
1290 else if ((inst & SA1_clrt_MASK) == SA1_clrt_BITS)
1291 op = Hexagon::SA1_clrt;
1292 else if ((inst & SA1_clrtnew_MASK) == SA1_clrtnew_BITS)
1293 op = Hexagon::SA1_clrtnew;
1294 else if ((inst & SA1_cmpeqi_MASK) == SA1_cmpeqi_BITS)
1295 op = Hexagon::SA1_cmpeqi;
1296 else if ((inst & SA1_combine0i_MASK) == SA1_combine0i_BITS)
1297 op = Hexagon::SA1_combine0i;
1298 else if ((inst & SA1_combine1i_MASK) == SA1_combine1i_BITS)
1299 op = Hexagon::SA1_combine1i;
1300 else if ((inst & SA1_combine2i_MASK) == SA1_combine2i_BITS)
1301 op = Hexagon::SA1_combine2i;
1302 else if ((inst & SA1_combine3i_MASK) == SA1_combine3i_BITS)
1303 op = Hexagon::SA1_combine3i;
1304 else if ((inst & SA1_combinerz_MASK) == SA1_combinerz_BITS)
1305 op = Hexagon::SA1_combinerz;
1306 else if ((inst & SA1_combinezr_MASK) == SA1_combinezr_BITS)
1307 op = Hexagon::SA1_combinezr;
1308 else if ((inst & SA1_dec_MASK) == SA1_dec_BITS)
1309 op = Hexagon::SA1_dec;
1310 else if ((inst & SA1_inc_MASK) == SA1_inc_BITS)
1311 op = Hexagon::SA1_inc;
1312 else if ((inst & SA1_seti_MASK) == SA1_seti_BITS)
1313 op = Hexagon::SA1_seti;
1314 else if ((inst & SA1_setin1_MASK) == SA1_setin1_BITS)
1315 op = Hexagon::SA1_setin1;
1316 else if ((inst & SA1_sxtb_MASK) == SA1_sxtb_BITS)
1317 op = Hexagon::SA1_sxtb;
1318 else if ((inst & SA1_sxth_MASK) == SA1_sxth_BITS)
1319 op = Hexagon::SA1_sxth;
1320 else if ((inst & SA1_tfr_MASK) == SA1_tfr_BITS)
1321 op = Hexagon::SA1_tfr;
1322 else if ((inst & SA1_zxtb_MASK) == SA1_zxtb_BITS)
1323 op = Hexagon::SA1_zxtb;
1324 else if ((inst & SA1_zxth_MASK) == SA1_zxth_BITS)
1325 op = Hexagon::SA1_zxth;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001326 else {
1327 os << "<unknown subinstruction>";
1328 return MCDisassembler::Fail;
1329 }
1330 break;
1331 case HexagonII::HSIG_S1:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001332 if ((inst & SS1_storeb_io_MASK) == SS1_storeb_io_BITS)
1333 op = Hexagon::SS1_storeb_io;
1334 else if ((inst & SS1_storew_io_MASK) == SS1_storew_io_BITS)
1335 op = Hexagon::SS1_storew_io;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001336 else {
1337 os << "<unknown subinstruction>";
1338 return MCDisassembler::Fail;
1339 }
1340 break;
1341 case HexagonII::HSIG_S2:
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001342 if ((inst & SS2_allocframe_MASK) == SS2_allocframe_BITS)
1343 op = Hexagon::SS2_allocframe;
1344 else if ((inst & SS2_storebi0_MASK) == SS2_storebi0_BITS)
1345 op = Hexagon::SS2_storebi0;
1346 else if ((inst & SS2_storebi1_MASK) == SS2_storebi1_BITS)
1347 op = Hexagon::SS2_storebi1;
1348 else if ((inst & SS2_stored_sp_MASK) == SS2_stored_sp_BITS)
1349 op = Hexagon::SS2_stored_sp;
1350 else if ((inst & SS2_storeh_io_MASK) == SS2_storeh_io_BITS)
1351 op = Hexagon::SS2_storeh_io;
1352 else if ((inst & SS2_storew_sp_MASK) == SS2_storew_sp_BITS)
1353 op = Hexagon::SS2_storew_sp;
1354 else if ((inst & SS2_storewi0_MASK) == SS2_storewi0_BITS)
1355 op = Hexagon::SS2_storewi0;
1356 else if ((inst & SS2_storewi1_MASK) == SS2_storewi1_BITS)
1357 op = Hexagon::SS2_storewi1;
Colin LeMahieube8c4532015-06-05 16:00:11 +00001358 else {
1359 os << "<unknown subinstruction>";
1360 return MCDisassembler::Fail;
1361 }
1362 break;
1363 default:
1364 os << "<unknown>";
1365 return MCDisassembler::Fail;
1366 }
1367 return MCDisassembler::Success;
1368}
1369
1370static unsigned getRegFromSubinstEncoding(unsigned encoded_reg) {
1371 if (encoded_reg < 8)
1372 return Hexagon::R0 + encoded_reg;
1373 else if (encoded_reg < 16)
1374 return Hexagon::R0 + encoded_reg + 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001375
1376 // patently false value
Colin LeMahieube8c4532015-06-05 16:00:11 +00001377 return Hexagon::NoRegister;
1378}
1379
1380static unsigned getDRegFromSubinstEncoding(unsigned encoded_dreg) {
1381 if (encoded_dreg < 4)
1382 return Hexagon::D0 + encoded_dreg;
1383 else if (encoded_dreg < 8)
1384 return Hexagon::D0 + encoded_dreg + 4;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001385
1386 // patently false value
Colin LeMahieube8c4532015-06-05 16:00:11 +00001387 return Hexagon::NoRegister;
1388}
1389
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001390void HexagonDisassembler::addSubinstOperands(MCInst *MI, unsigned opcode,
1391 unsigned inst) const {
Colin LeMahieube8c4532015-06-05 16:00:11 +00001392 int64_t operand;
1393 MCOperand Op;
1394 switch (opcode) {
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001395 case Hexagon::SL2_deallocframe:
1396 case Hexagon::SL2_jumpr31:
1397 case Hexagon::SL2_jumpr31_f:
1398 case Hexagon::SL2_jumpr31_fnew:
1399 case Hexagon::SL2_jumpr31_t:
1400 case Hexagon::SL2_jumpr31_tnew:
1401 case Hexagon::SL2_return:
1402 case Hexagon::SL2_return_f:
1403 case Hexagon::SL2_return_fnew:
1404 case Hexagon::SL2_return_t:
1405 case Hexagon::SL2_return_tnew:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001406 // no operands for these instructions
1407 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001408 case Hexagon::SS2_allocframe:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001409 // u 8-4{5_3}
1410 operand = ((inst & 0x1f0) >> 4) << 3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001411 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001412 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001413 case Hexagon::SL1_loadri_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001414 // Rd 3-0, Rs 7-4, u 11-8{4_2}
1415 operand = getRegFromSubinstEncoding(inst & 0xf);
1416 Op = MCOperand::createReg(operand);
1417 MI->addOperand(Op);
1418 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1419 Op = MCOperand::createReg(operand);
1420 MI->addOperand(Op);
1421 operand = (inst & 0xf00) >> 6;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001422 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001423 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001424 case Hexagon::SL1_loadrub_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001425 // Rd 3-0, Rs 7-4, u 11-8
1426 operand = getRegFromSubinstEncoding(inst & 0xf);
1427 Op = MCOperand::createReg(operand);
1428 MI->addOperand(Op);
1429 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1430 Op = MCOperand::createReg(operand);
1431 MI->addOperand(Op);
1432 operand = (inst & 0xf00) >> 8;
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_loadrb_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001436 // Rd 3-0, Rs 7-4, u 10-8
1437 operand = getRegFromSubinstEncoding(inst & 0xf);
1438 Op = MCOperand::createReg(operand);
1439 MI->addOperand(Op);
1440 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1441 Op = MCOperand::createReg(operand);
1442 MI->addOperand(Op);
1443 operand = (inst & 0x700) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001444 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001445 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001446 case Hexagon::SL2_loadrh_io:
1447 case Hexagon::SL2_loadruh_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001448 // Rd 3-0, Rs 7-4, u 10-8{3_1}
1449 operand = getRegFromSubinstEncoding(inst & 0xf);
1450 Op = MCOperand::createReg(operand);
1451 MI->addOperand(Op);
1452 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1453 Op = MCOperand::createReg(operand);
1454 MI->addOperand(Op);
1455 operand = ((inst & 0x700) >> 8) << 1;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001456 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001457 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001458 case Hexagon::SL2_loadrd_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001459 // Rdd 2-0, u 7-3{5_3}
1460 operand = getDRegFromSubinstEncoding(inst & 0x7);
1461 Op = MCOperand::createReg(operand);
1462 MI->addOperand(Op);
1463 operand = ((inst & 0x0f8) >> 3) << 3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001464 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001465 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001466 case Hexagon::SL2_loadri_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001467 // Rd 3-0, u 8-4{5_2}
1468 operand = getRegFromSubinstEncoding(inst & 0xf);
1469 Op = MCOperand::createReg(operand);
1470 MI->addOperand(Op);
1471 operand = ((inst & 0x1f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001472 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001473 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001474 case Hexagon::SA1_addi:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001475 // Rx 3-0 (x2), s7 10-4
1476 operand = getRegFromSubinstEncoding(inst & 0xf);
1477 Op = MCOperand::createReg(operand);
1478 MI->addOperand(Op);
1479 MI->addOperand(Op);
1480 operand = SignExtend64<7>((inst & 0x7f0) >> 4);
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001481 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001482 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001483 case Hexagon::SA1_addrx:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001484 // Rx 3-0 (x2), Rs 7-4
1485 operand = getRegFromSubinstEncoding(inst & 0xf);
1486 Op = MCOperand::createReg(operand);
1487 MI->addOperand(Op);
1488 MI->addOperand(Op);
1489 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1490 Op = MCOperand::createReg(operand);
1491 MI->addOperand(Op);
Colin LeMahieubb0cdfb2016-03-16 20:00:38 +00001492 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001493 case Hexagon::SA1_and1:
1494 case Hexagon::SA1_dec:
1495 case Hexagon::SA1_inc:
1496 case Hexagon::SA1_sxtb:
1497 case Hexagon::SA1_sxth:
1498 case Hexagon::SA1_tfr:
1499 case Hexagon::SA1_zxtb:
1500 case Hexagon::SA1_zxth:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001501 // Rd 3-0, Rs 7-4
1502 operand = getRegFromSubinstEncoding(inst & 0xf);
1503 Op = MCOperand::createReg(operand);
1504 MI->addOperand(Op);
1505 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1506 Op = MCOperand::createReg(operand);
1507 MI->addOperand(Op);
1508 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001509 case Hexagon::SA1_addsp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001510 // Rd 3-0, u 9-4{6_2}
1511 operand = getRegFromSubinstEncoding(inst & 0xf);
1512 Op = MCOperand::createReg(operand);
1513 MI->addOperand(Op);
1514 operand = ((inst & 0x3f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001515 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001516 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001517 case Hexagon::SA1_seti:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001518 // Rd 3-0, u 9-4
1519 operand = getRegFromSubinstEncoding(inst & 0xf);
1520 Op = MCOperand::createReg(operand);
1521 MI->addOperand(Op);
1522 operand = (inst & 0x3f0) >> 4;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001523 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001524 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001525 case Hexagon::SA1_clrf:
1526 case Hexagon::SA1_clrfnew:
1527 case Hexagon::SA1_clrt:
1528 case Hexagon::SA1_clrtnew:
1529 case Hexagon::SA1_setin1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001530 // Rd 3-0
1531 operand = getRegFromSubinstEncoding(inst & 0xf);
1532 Op = MCOperand::createReg(operand);
1533 MI->addOperand(Op);
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001534 if (opcode == Hexagon::SA1_setin1)
Krzysztof Parzyszek73e0ad82016-09-09 21:45:00 +00001535 break;
1536 MI->addOperand(MCOperand::createReg(Hexagon::P0));
Colin LeMahieube8c4532015-06-05 16:00:11 +00001537 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001538 case Hexagon::SA1_cmpeqi:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001539 // Rs 7-4, u 1-0
1540 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1541 Op = MCOperand::createReg(operand);
1542 MI->addOperand(Op);
1543 operand = inst & 0x3;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001544 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001545 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001546 case Hexagon::SA1_combine0i:
1547 case Hexagon::SA1_combine1i:
1548 case Hexagon::SA1_combine2i:
1549 case Hexagon::SA1_combine3i:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001550 // Rdd 2-0, u 6-5
1551 operand = getDRegFromSubinstEncoding(inst & 0x7);
1552 Op = MCOperand::createReg(operand);
1553 MI->addOperand(Op);
1554 operand = (inst & 0x060) >> 5;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001555 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001556 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001557 case Hexagon::SA1_combinerz:
1558 case Hexagon::SA1_combinezr:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001559 // Rdd 2-0, Rs 7-4
1560 operand = getDRegFromSubinstEncoding(inst & 0x7);
1561 Op = MCOperand::createReg(operand);
1562 MI->addOperand(Op);
1563 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1564 Op = MCOperand::createReg(operand);
1565 MI->addOperand(Op);
1566 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001567 case Hexagon::SS1_storeb_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001568 // Rs 7-4, u 11-8, Rt 3-0
1569 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1570 Op = MCOperand::createReg(operand);
1571 MI->addOperand(Op);
1572 operand = (inst & 0xf00) >> 8;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001573 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001574 operand = getRegFromSubinstEncoding(inst & 0xf);
1575 Op = MCOperand::createReg(operand);
1576 MI->addOperand(Op);
1577 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001578 case Hexagon::SS1_storew_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001579 // Rs 7-4, u 11-8{4_2}, Rt 3-0
1580 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1581 Op = MCOperand::createReg(operand);
1582 MI->addOperand(Op);
1583 operand = ((inst & 0xf00) >> 8) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001584 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001585 operand = getRegFromSubinstEncoding(inst & 0xf);
1586 Op = MCOperand::createReg(operand);
1587 MI->addOperand(Op);
1588 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001589 case Hexagon::SS2_storebi0:
1590 case Hexagon::SS2_storebi1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001591 // Rs 7-4, u 3-0
1592 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1593 Op = MCOperand::createReg(operand);
1594 MI->addOperand(Op);
1595 operand = inst & 0xf;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001596 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001597 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001598 case Hexagon::SS2_storewi0:
1599 case Hexagon::SS2_storewi1:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001600 // Rs 7-4, u 3-0{4_2}
1601 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1602 Op = MCOperand::createReg(operand);
1603 MI->addOperand(Op);
1604 operand = (inst & 0xf) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001605 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001606 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001607 case Hexagon::SS2_stored_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001608 // s 8-3{6_3}, Rtt 2-0
1609 operand = SignExtend64<9>(((inst & 0x1f8) >> 3) << 3);
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001610 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001611 operand = getDRegFromSubinstEncoding(inst & 0x7);
1612 Op = MCOperand::createReg(operand);
1613 MI->addOperand(Op);
Colin LeMahieu160f73e2015-11-03 00:21:19 +00001614 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001615 case Hexagon::SS2_storeh_io:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001616 // Rs 7-4, u 10-8{3_1}, Rt 3-0
1617 operand = getRegFromSubinstEncoding((inst & 0xf0) >> 4);
1618 Op = MCOperand::createReg(operand);
1619 MI->addOperand(Op);
1620 operand = ((inst & 0x700) >> 8) << 1;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001621 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001622 operand = getRegFromSubinstEncoding(inst & 0xf);
1623 Op = MCOperand::createReg(operand);
1624 MI->addOperand(Op);
1625 break;
Colin LeMahieu8ed1aee2016-10-07 00:15:07 +00001626 case Hexagon::SS2_storew_sp:
Colin LeMahieube8c4532015-06-05 16:00:11 +00001627 // u 8-4{5_2}, Rd 3-0
1628 operand = ((inst & 0x1f0) >> 4) << 2;
Colin LeMahieu7cd08922015-11-09 04:07:48 +00001629 HexagonMCInstrInfo::addConstant(*MI, operand, getContext());
Colin LeMahieube8c4532015-06-05 16:00:11 +00001630 operand = getRegFromSubinstEncoding(inst & 0xf);
1631 Op = MCOperand::createReg(operand);
1632 MI->addOperand(Op);
1633 break;
1634 default:
1635 // don't crash with an invalid subinstruction
1636 // llvm_unreachable("Invalid subinstruction in duplex instruction");
1637 break;
1638 }
1639}