blob: fb82945356e2cf069e72a8dec0e78e66df6f2136 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA --------------===//
Johnny Chenb68a3ee2010-04-02 22:27:38 +00002//
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//===----------------------------------------------------------------------===//
Johnny Chenb68a3ee2010-04-02 22:27:38 +00009
10#define DEBUG_TYPE "arm-disassembler"
11
Chandler Carruthd04a8d42012-12-03 16:50:05 +000012#include "llvm/MC/MCDisassembler.h"
Owen Anderson8d7d2e12011-08-09 20:55:18 +000013#include "MCTargetDesc/ARMAddressingModes.h"
14#include "MCTargetDesc/ARMBaseInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000015#include "MCTargetDesc/ARMMCExpr.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCFixedLenDisassembler.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000019#include "llvm/MC/MCInst.h"
Benjamin Kramereea66f62011-11-11 12:39:41 +000020#include "llvm/MC/MCInstrDesc.h"
Dylan Noblesmith75e3b7f2012-04-03 15:48:14 +000021#include "llvm/MC/MCSubtargetInfo.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000022#include "llvm/Support/Debug.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000023#include "llvm/Support/ErrorHandling.h"
Jim Grosbachfc1a1612012-08-14 19:06:05 +000024#include "llvm/Support/LEB128.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000025#include "llvm/Support/MemoryObject.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000026#include "llvm/Support/TargetRegistry.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000027#include "llvm/Support/raw_ostream.h"
Richard Bartonf4478f92012-04-24 11:13:20 +000028#include <vector>
Johnny Chenb68a3ee2010-04-02 22:27:38 +000029
James Molloyc047dca2011-09-01 18:02:14 +000030using namespace llvm;
Owen Anderson83e3f672011-08-17 17:44:15 +000031
Owen Andersona6804442011-09-01 23:23:50 +000032typedef MCDisassembler::DecodeStatus DecodeStatus;
33
Owen Andersona1c11002011-09-01 23:35:51 +000034namespace {
Richard Bartonf4478f92012-04-24 11:13:20 +000035 // Handles the condition code status of instructions in IT blocks
36 class ITStatus
37 {
38 public:
39 // Returns the condition code for instruction in IT block
40 unsigned getITCC() {
41 unsigned CC = ARMCC::AL;
42 if (instrInITBlock())
43 CC = ITStates.back();
44 return CC;
45 }
46
47 // Advances the IT block state to the next T or E
48 void advanceITState() {
49 ITStates.pop_back();
50 }
51
52 // Returns true if the current instruction is in an IT block
53 bool instrInITBlock() {
54 return !ITStates.empty();
55 }
56
57 // Returns true if current instruction is the last instruction in an IT block
58 bool instrLastInITBlock() {
59 return ITStates.size() == 1;
60 }
61
62 // Called when decoding an IT instruction. Sets the IT state for the following
63 // instructions that for the IT block. Firstcond and Mask correspond to the
64 // fields in the IT instruction encoding.
65 void setITState(char Firstcond, char Mask) {
66 // (3 - the number of trailing zeros) is the number of then / else.
Richard Barton4d2f0772012-04-27 08:42:59 +000067 unsigned CondBit0 = Firstcond & 1;
Richard Bartonf4478f92012-04-24 11:13:20 +000068 unsigned NumTZ = CountTrailingZeros_32(Mask);
69 unsigned char CCBits = static_cast<unsigned char>(Firstcond & 0xf);
70 assert(NumTZ <= 3 && "Invalid IT mask!");
71 // push condition codes onto the stack the correct order for the pops
72 for (unsigned Pos = NumTZ+1; Pos <= 3; ++Pos) {
73 bool T = ((Mask >> Pos) & 1) == CondBit0;
74 if (T)
75 ITStates.push_back(CCBits);
76 else
77 ITStates.push_back(CCBits ^ 1);
78 }
79 ITStates.push_back(CCBits);
80 }
81
82 private:
83 std::vector<unsigned char> ITStates;
84 };
85}
86
87namespace {
Owen Andersona1c11002011-09-01 23:35:51 +000088/// ARMDisassembler - ARM disassembler for all ARM platforms.
89class ARMDisassembler : public MCDisassembler {
90public:
91 /// Constructor - Initializes the disassembler.
92 ///
James Molloyb9505852011-09-07 17:24:38 +000093 ARMDisassembler(const MCSubtargetInfo &STI) :
94 MCDisassembler(STI) {
Owen Andersona1c11002011-09-01 23:35:51 +000095 }
96
97 ~ARMDisassembler() {
98 }
99
100 /// getInstruction - See MCDisassembler.
101 DecodeStatus getInstruction(MCInst &instr,
102 uint64_t &size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000103 const MemoryObject &region,
Owen Andersona1c11002011-09-01 23:35:51 +0000104 uint64_t address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000105 raw_ostream &vStream,
106 raw_ostream &cStream) const;
Owen Andersona1c11002011-09-01 23:35:51 +0000107};
108
109/// ThumbDisassembler - Thumb disassembler for all Thumb platforms.
110class ThumbDisassembler : public MCDisassembler {
111public:
112 /// Constructor - Initializes the disassembler.
113 ///
James Molloyb9505852011-09-07 17:24:38 +0000114 ThumbDisassembler(const MCSubtargetInfo &STI) :
115 MCDisassembler(STI) {
Owen Andersona1c11002011-09-01 23:35:51 +0000116 }
117
118 ~ThumbDisassembler() {
119 }
120
121 /// getInstruction - See MCDisassembler.
122 DecodeStatus getInstruction(MCInst &instr,
123 uint64_t &size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000124 const MemoryObject &region,
Owen Andersona1c11002011-09-01 23:35:51 +0000125 uint64_t address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000126 raw_ostream &vStream,
127 raw_ostream &cStream) const;
Owen Andersona1c11002011-09-01 23:35:51 +0000128
Owen Andersona1c11002011-09-01 23:35:51 +0000129private:
Richard Bartonf4478f92012-04-24 11:13:20 +0000130 mutable ITStatus ITBlock;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000131 DecodeStatus AddThumbPredicate(MCInst&) const;
Owen Andersona1c11002011-09-01 23:35:51 +0000132 void UpdateThumbVFPPredicate(MCInst&) const;
133};
134}
135
Owen Andersona6804442011-09-01 23:23:50 +0000136static bool Check(DecodeStatus &Out, DecodeStatus In) {
James Molloyc047dca2011-09-01 18:02:14 +0000137 switch (In) {
138 case MCDisassembler::Success:
139 // Out stays the same.
140 return true;
141 case MCDisassembler::SoftFail:
142 Out = In;
143 return true;
144 case MCDisassembler::Fail:
145 Out = In;
146 return false;
147 }
David Blaikie4d6ccb52012-01-20 21:51:11 +0000148 llvm_unreachable("Invalid DecodeStatus!");
James Molloyc047dca2011-09-01 18:02:14 +0000149}
Owen Anderson83e3f672011-08-17 17:44:15 +0000150
James Molloya5d58562011-09-07 19:42:28 +0000151
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000152// Forward declare these because the autogenerated code will reference them.
153// Definitions are further down.
Craig Topperc89c7442012-03-27 07:21:54 +0000154static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000155 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000156static DecodeStatus DecodeGPRnopcRegisterClass(MCInst &Inst,
Jim Grosbachc4057822011-08-17 21:58:18 +0000157 unsigned RegNo, uint64_t Address,
158 const void *Decoder);
Mihai Popaf86e4362013-05-13 14:10:04 +0000159static DecodeStatus DecodeGPRwithAPSRRegisterClass(MCInst &Inst,
160 unsigned RegNo, uint64_t Address,
161 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000162static DecodeStatus DecodetGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000163 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000164static DecodeStatus DecodetcGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000165 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000166static DecodeStatus DecoderGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000167 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000168static DecodeStatus DecodeSPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000169 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000170static DecodeStatus DecodeDPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000171 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000172static DecodeStatus DecodeDPR_8RegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000173 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000174static DecodeStatus DecodeDPR_VFP2RegisterClass(MCInst &Inst,
Jim Grosbachc4057822011-08-17 21:58:18 +0000175 unsigned RegNo,
176 uint64_t Address,
177 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000178static DecodeStatus DecodeQPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000179 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000180static DecodeStatus DecodeDPairRegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbach28f08c92012-03-05 19:33:30 +0000181 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000182static DecodeStatus DecodeDPairSpacedRegisterClass(MCInst &Inst,
Jim Grosbachc3384c92012-03-05 21:43:40 +0000183 unsigned RegNo, uint64_t Address,
184 const void *Decoder);
Johnny Chen270159f2010-08-12 01:40:54 +0000185
Craig Topperc89c7442012-03-27 07:21:54 +0000186static DecodeStatus DecodePredicateOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000187 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000188static DecodeStatus DecodeCCOutOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000189 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000190static DecodeStatus DecodeSOImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000191 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000192static DecodeStatus DecodeRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000193 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000194static DecodeStatus DecodeSPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000195 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000196static DecodeStatus DecodeDPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000197 uint64_t Address, const void *Decoder);
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000198
Craig Topperc89c7442012-03-27 07:21:54 +0000199static DecodeStatus DecodeBitfieldMaskOperand(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000200 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000201static DecodeStatus DecodeCopMemInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000202 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000203static DecodeStatus DecodeAddrMode2IdxInstruction(MCInst &Inst,
Jim Grosbachc4057822011-08-17 21:58:18 +0000204 unsigned Insn,
205 uint64_t Address,
206 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000207static DecodeStatus DecodeSORegMemOperand(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000208 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000209static DecodeStatus DecodeAddrMode3Instruction(MCInst &Inst,unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000210 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000211static DecodeStatus DecodeSORegImmOperand(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000212 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000213static DecodeStatus DecodeSORegRegOperand(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000214 uint64_t Address, const void *Decoder);
215
Craig Topperc89c7442012-03-27 07:21:54 +0000216static DecodeStatus DecodeMemMultipleWritebackInstruction(MCInst & Inst,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000217 unsigned Insn,
218 uint64_t Adddress,
219 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000220static DecodeStatus DecodeT2MOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000221 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000222static DecodeStatus DecodeArmMOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000223 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000224static DecodeStatus DecodeSMLAInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000225 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000226static DecodeStatus DecodeCPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson35008c22011-08-09 23:05:39 +0000227 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000228static DecodeStatus DecodeT2CPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson6153a032011-08-23 17:45:18 +0000229 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000230static DecodeStatus DecodeAddrModeImm12Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000231 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000232static DecodeStatus DecodeAddrMode5Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000233 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000234static DecodeStatus DecodeAddrMode7Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000235 uint64_t Address, const void *Decoder);
Kevin Enderby2a7d3a92012-04-12 23:13:34 +0000236static DecodeStatus DecodeT2BInstruction(MCInst &Inst, unsigned Insn,
237 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000238static DecodeStatus DecodeBranchImmInstruction(MCInst &Inst,unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000239 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000240static DecodeStatus DecodeAddrMode6Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000241 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000242static DecodeStatus DecodeVLDInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000243 uint64_t Address, const void *Decoder);
Mihai Popa30a7a7c2013-05-20 14:57:05 +0000244static DecodeStatus DecodeVST1Instruction(MCInst &Inst, unsigned Val,
245 uint64_t Address, const void *Decoder);
246static DecodeStatus DecodeVST2Instruction(MCInst &Inst, unsigned Val,
247 uint64_t Address, const void *Decoder);
248static DecodeStatus DecodeVST3Instruction(MCInst &Inst, unsigned Val,
249 uint64_t Address, const void *Decoder);
250static DecodeStatus DecodeVST4Instruction(MCInst &Inst, unsigned Val,
251 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000252static DecodeStatus DecodeVSTInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000253 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000254static DecodeStatus DecodeVLD1DupInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000255 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000256static DecodeStatus DecodeVLD2DupInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000257 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000258static DecodeStatus DecodeVLD3DupInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000259 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000260static DecodeStatus DecodeVLD4DupInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000261 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000262static DecodeStatus DecodeNEONModImmInstruction(MCInst &Inst,unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000263 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000264static DecodeStatus DecodeVSHLMaxInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000265 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000266static DecodeStatus DecodeShiftRight8Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000267 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000268static DecodeStatus DecodeShiftRight16Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000269 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000270static DecodeStatus DecodeShiftRight32Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000271 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000272static DecodeStatus DecodeShiftRight64Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000273 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000274static DecodeStatus DecodeTBLInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000275 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000276static DecodeStatus DecodePostIdxReg(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000277 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000278static DecodeStatus DecodeCoprocessor(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000279 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000280static DecodeStatus DecodeMemBarrierOption(MCInst &Inst, unsigned Insn,
Owen Andersonc36481c2011-08-09 23:25:42 +0000281 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000282static DecodeStatus DecodeMSRMask(MCInst &Inst, unsigned Insn,
Owen Anderson26d2f0a2011-08-11 20:21:46 +0000283 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000284static DecodeStatus DecodeDoubleRegLoad(MCInst &Inst, unsigned Insn,
Owen Andersoncbfc0442011-08-11 21:34:58 +0000285 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000286static DecodeStatus DecodeDoubleRegStore(MCInst &Inst, unsigned Insn,
Owen Anderson3f3570a2011-08-12 17:58:32 +0000287 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000288static DecodeStatus DecodeLDRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +0000289 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000290static DecodeStatus DecodeLDRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +0000291 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000292static DecodeStatus DecodeSTRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +0000293 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000294static DecodeStatus DecodeSTRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +0000295 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000296static DecodeStatus DecodeVLD1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000297 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000298static DecodeStatus DecodeVLD2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000299 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000300static DecodeStatus DecodeVLD3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000301 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000302static DecodeStatus DecodeVLD4LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000303 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000304static DecodeStatus DecodeVST1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000305 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000306static DecodeStatus DecodeVST2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000307 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000308static DecodeStatus DecodeVST3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000309 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000310static DecodeStatus DecodeVST4LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000311 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000312static DecodeStatus DecodeVMOVSRR(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +0000313 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000314static DecodeStatus DecodeVMOVRRS(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +0000315 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000316static DecodeStatus DecodeSwap(MCInst &Inst, unsigned Insn,
Owen Andersoncb9fed62011-10-28 18:02:13 +0000317 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000318static DecodeStatus DecodeVCVTD(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +0000319 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000320static DecodeStatus DecodeVCVTQ(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +0000321 uint64_t Address, const void *Decoder);
Quentin Colombet7c4cf032013-04-17 18:46:12 +0000322static DecodeStatus DecodeImm0_4(MCInst &Inst, unsigned Insn, uint64_t Address,
323 const void *Decoder);
Owen Andersonb589be92011-11-15 19:55:00 +0000324
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000325
Craig Topperc89c7442012-03-27 07:21:54 +0000326static DecodeStatus DecodeThumbAddSpecialReg(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000327 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000328static DecodeStatus DecodeThumbBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000329 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000330static DecodeStatus DecodeT2BROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000331 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000332static DecodeStatus DecodeThumbCmpBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000333 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000334static DecodeStatus DecodeThumbAddrModeRR(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000335 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000336static DecodeStatus DecodeThumbAddrModeIS(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000337 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000338static DecodeStatus DecodeThumbAddrModePC(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000339 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000340static DecodeStatus DecodeThumbAddrModeSP(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000341 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000342static DecodeStatus DecodeT2AddrModeSOReg(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000343 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000344static DecodeStatus DecodeT2LoadShift(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000345 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000346static DecodeStatus DecodeT2Imm8S4(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000347 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000348static DecodeStatus DecodeT2AddrModeImm8s4(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000349 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000350static DecodeStatus DecodeT2AddrModeImm0_1020s4(MCInst &Inst,unsigned Val,
Jim Grosbachb6aed502011-09-09 18:37:27 +0000351 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000352static DecodeStatus DecodeT2Imm8(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000353 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000354static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000355 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000356static DecodeStatus DecodeThumbAddSPImm(MCInst &Inst, uint16_t Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000357 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000358static DecodeStatus DecodeThumbAddSPReg(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000359 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000360static DecodeStatus DecodeThumbCPS(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000361 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000362static DecodeStatus DecodeThumbBLXOffset(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000363 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000364static DecodeStatus DecodeT2AddrModeImm12(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000365 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000366static DecodeStatus DecodeThumbTableBranch(MCInst &Inst, unsigned Val,
Jim Grosbach7f739be2011-09-19 22:21:13 +0000367 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000368static DecodeStatus DecodeThumb2BCCInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000369 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000370static DecodeStatus DecodeT2SOImm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000371 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000372static DecodeStatus DecodeThumbBCCTargetOperand(MCInst &Inst,unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000373 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000374static DecodeStatus DecodeThumbBLTargetOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000375 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000376static DecodeStatus DecodeIT(MCInst &Inst, unsigned Val,
Owen Andersonf4408202011-08-24 22:40:22 +0000377 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000378static DecodeStatus DecodeT2LDRDPreInstruction(MCInst &Inst,unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +0000379 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000380static DecodeStatus DecodeT2STRDPreInstruction(MCInst &Inst,unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +0000381 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000382static DecodeStatus DecodeT2Adr(MCInst &Inst, unsigned Val,
Owen Anderson08fef882011-09-09 22:24:36 +0000383 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000384static DecodeStatus DecodeT2LdStPre(MCInst &Inst, unsigned Val,
Owen Andersona3157b42011-09-12 18:56:30 +0000385 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000386static DecodeStatus DecodeT2ShifterImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson0afa0092011-09-26 21:06:22 +0000387 uint64_t Address, const void *Decoder);
388
Craig Topperc89c7442012-03-27 07:21:54 +0000389static DecodeStatus DecodeLDR(MCInst &Inst, unsigned Val,
Silviu Barangab7c2ed62012-03-22 13:24:43 +0000390 uint64_t Address, const void *Decoder);
Silviu Barangafa1ebc62012-04-18 13:12:50 +0000391static DecodeStatus DecodeMRRC2(llvm::MCInst &Inst, unsigned Val,
392 uint64_t Address, const void *Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000393#include "ARMGenDisassemblerTables.inc"
Sean Callanan9899f702010-04-13 21:21:57 +0000394
James Molloyb9505852011-09-07 17:24:38 +0000395static MCDisassembler *createARMDisassembler(const Target &T, const MCSubtargetInfo &STI) {
396 return new ARMDisassembler(STI);
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000397}
398
James Molloyb9505852011-09-07 17:24:38 +0000399static MCDisassembler *createThumbDisassembler(const Target &T, const MCSubtargetInfo &STI) {
400 return new ThumbDisassembler(STI);
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000401}
402
Owen Andersona6804442011-09-01 23:23:50 +0000403DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000404 const MemoryObject &Region,
Jim Grosbachc4057822011-08-17 21:58:18 +0000405 uint64_t Address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000406 raw_ostream &os,
407 raw_ostream &cs) const {
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000408 CommentStream = &cs;
409
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000410 uint8_t bytes[4];
411
James Molloya5d58562011-09-07 19:42:28 +0000412 assert(!(STI.getFeatureBits() & ARM::ModeThumb) &&
413 "Asked to disassemble an ARM instruction but Subtarget is in Thumb mode!");
414
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000415 // We want to read exactly 4 bytes of data.
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000416 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
417 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000418 return MCDisassembler::Fail;
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000419 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000420
421 // Encoded as a small-endian 32-bit word in the stream.
422 uint32_t insn = (bytes[3] << 24) |
423 (bytes[2] << 16) |
424 (bytes[1] << 8) |
425 (bytes[0] << 0);
426
427 // Calling the auto-generated decoder function.
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000428 DecodeStatus result = decodeInstruction(DecoderTableARM32, MI, insn,
429 Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000430 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000431 Size = 4;
Owen Anderson83e3f672011-08-17 17:44:15 +0000432 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000433 }
434
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000435 // VFP and NEON instructions, similarly, are shared between ARM
436 // and Thumb modes.
437 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000438 result = decodeInstruction(DecoderTableVFP32, MI, insn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000439 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000440 Size = 4;
Owen Anderson83e3f672011-08-17 17:44:15 +0000441 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000442 }
443
444 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000445 result = decodeInstruction(DecoderTableNEONData32, MI, insn, Address,
446 this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000447 if (result != MCDisassembler::Fail) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000448 Size = 4;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000449 // Add a fake predicate operand, because we share these instruction
450 // definitions with Thumb2 where these instructions are predicable.
Owen Andersona6804442011-09-01 23:23:50 +0000451 if (!DecodePredicateOperand(MI, 0xE, Address, this))
452 return MCDisassembler::Fail;
Owen Anderson83e3f672011-08-17 17:44:15 +0000453 return result;
Owen Anderson8533eba2011-08-10 19:01:10 +0000454 }
455
456 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000457 result = decodeInstruction(DecoderTableNEONLoadStore32, MI, insn, Address,
458 this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000459 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000460 Size = 4;
Owen Anderson8533eba2011-08-10 19:01:10 +0000461 // Add a fake predicate operand, because we share these instruction
462 // definitions with Thumb2 where these instructions are predicable.
Owen Andersona6804442011-09-01 23:23:50 +0000463 if (!DecodePredicateOperand(MI, 0xE, Address, this))
464 return MCDisassembler::Fail;
Owen Anderson83e3f672011-08-17 17:44:15 +0000465 return result;
Owen Anderson8533eba2011-08-10 19:01:10 +0000466 }
467
468 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000469 result = decodeInstruction(DecoderTableNEONDup32, MI, insn, Address,
470 this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000471 if (result != MCDisassembler::Fail) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000472 Size = 4;
473 // Add a fake predicate operand, because we share these instruction
474 // definitions with Thumb2 where these instructions are predicable.
Owen Andersona6804442011-09-01 23:23:50 +0000475 if (!DecodePredicateOperand(MI, 0xE, Address, this))
476 return MCDisassembler::Fail;
Owen Anderson83e3f672011-08-17 17:44:15 +0000477 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000478 }
479
480 MI.clear();
481
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000482 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000483 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000484}
485
486namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000487extern const MCInstrDesc ARMInsts[];
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000488}
489
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000490/// tryAddingSymbolicOperand - trys to add a symbolic operand in place of the
491/// immediate Value in the MCInst. The immediate Value has had any PC
492/// adjustment made by the caller. If the instruction is a branch instruction
493/// then isBranch is true, else false. If the getOpInfo() function was set as
494/// part of the setupForSymbolicDisassembly() call then that function is called
495/// to get any symbolic information at the Address for this instruction. If
496/// that returns non-zero then the symbolic information it returns is used to
497/// create an MCExpr and that is added as an operand to the MCInst. If
498/// getOpInfo() returns zero and isBranch is true then a symbol look up for
499/// Value is done and if a symbol is found an MCExpr is created with that, else
500/// an MCExpr with Value is created. This function returns true if it adds an
501/// operand to the MCInst and false otherwise.
502static bool tryAddingSymbolicOperand(uint64_t Address, int32_t Value,
503 bool isBranch, uint64_t InstSize,
504 MCInst &MI, const void *Decoder) {
505 const MCDisassembler *Dis = static_cast<const MCDisassembler*>(Decoder);
506 LLVMOpInfoCallback getOpInfo = Dis->getLLVMOpInfoCallback();
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000507 struct LLVMOpInfo1 SymbolicOp;
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000508 memset(&SymbolicOp, '\0', sizeof(struct LLVMOpInfo1));
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000509 SymbolicOp.Value = Value;
510 void *DisInfo = Dis->getDisInfoBlock();
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000511
512 if (!getOpInfo ||
513 !getOpInfo(DisInfo, Address, 0 /* Offset */, InstSize, 1, &SymbolicOp)) {
514 // Clear SymbolicOp.Value from above and also all other fields.
515 memset(&SymbolicOp, '\0', sizeof(struct LLVMOpInfo1));
516 LLVMSymbolLookupCallback SymbolLookUp = Dis->getLLVMSymbolLookupCallback();
517 if (!SymbolLookUp)
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000518 return false;
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000519 uint64_t ReferenceType;
520 if (isBranch)
521 ReferenceType = LLVMDisassembler_ReferenceType_In_Branch;
522 else
523 ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
524 const char *ReferenceName;
Kevin Enderby88d12662012-10-18 21:49:18 +0000525 uint64_t SymbolValue = 0x00000000ffffffffULL & Value;
526 const char *Name = SymbolLookUp(DisInfo, SymbolValue, &ReferenceType,
527 Address, &ReferenceName);
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000528 if (Name) {
529 SymbolicOp.AddSymbol.Name = Name;
530 SymbolicOp.AddSymbol.Present = true;
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000531 }
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000532 // For branches always create an MCExpr so it gets printed as hex address.
533 else if (isBranch) {
534 SymbolicOp.Value = Value;
535 }
536 if(ReferenceType == LLVMDisassembler_ReferenceType_Out_SymbolStub)
537 (*Dis->CommentStream) << "symbol stub for: " << ReferenceName;
538 if (!Name && !isBranch)
539 return false;
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000540 }
541
542 MCContext *Ctx = Dis->getMCContext();
543 const MCExpr *Add = NULL;
544 if (SymbolicOp.AddSymbol.Present) {
545 if (SymbolicOp.AddSymbol.Name) {
546 StringRef Name(SymbolicOp.AddSymbol.Name);
547 MCSymbol *Sym = Ctx->GetOrCreateSymbol(Name);
548 Add = MCSymbolRefExpr::Create(Sym, *Ctx);
549 } else {
550 Add = MCConstantExpr::Create(SymbolicOp.AddSymbol.Value, *Ctx);
551 }
552 }
553
554 const MCExpr *Sub = NULL;
555 if (SymbolicOp.SubtractSymbol.Present) {
556 if (SymbolicOp.SubtractSymbol.Name) {
557 StringRef Name(SymbolicOp.SubtractSymbol.Name);
558 MCSymbol *Sym = Ctx->GetOrCreateSymbol(Name);
559 Sub = MCSymbolRefExpr::Create(Sym, *Ctx);
560 } else {
561 Sub = MCConstantExpr::Create(SymbolicOp.SubtractSymbol.Value, *Ctx);
562 }
563 }
564
565 const MCExpr *Off = NULL;
566 if (SymbolicOp.Value != 0)
567 Off = MCConstantExpr::Create(SymbolicOp.Value, *Ctx);
568
569 const MCExpr *Expr;
570 if (Sub) {
571 const MCExpr *LHS;
572 if (Add)
573 LHS = MCBinaryExpr::CreateSub(Add, Sub, *Ctx);
574 else
575 LHS = MCUnaryExpr::CreateMinus(Sub, *Ctx);
576 if (Off != 0)
577 Expr = MCBinaryExpr::CreateAdd(LHS, Off, *Ctx);
578 else
579 Expr = LHS;
580 } else if (Add) {
581 if (Off != 0)
582 Expr = MCBinaryExpr::CreateAdd(Add, Off, *Ctx);
583 else
584 Expr = Add;
585 } else {
586 if (Off != 0)
587 Expr = Off;
588 else
589 Expr = MCConstantExpr::Create(0, *Ctx);
590 }
591
592 if (SymbolicOp.VariantKind == LLVMDisassembler_VariantKind_ARM_HI16)
593 MI.addOperand(MCOperand::CreateExpr(ARMMCExpr::CreateUpper16(Expr, *Ctx)));
594 else if (SymbolicOp.VariantKind == LLVMDisassembler_VariantKind_ARM_LO16)
595 MI.addOperand(MCOperand::CreateExpr(ARMMCExpr::CreateLower16(Expr, *Ctx)));
596 else if (SymbolicOp.VariantKind == LLVMDisassembler_VariantKind_None)
597 MI.addOperand(MCOperand::CreateExpr(Expr));
Jim Grosbach01817c32011-10-20 17:28:20 +0000598 else
Craig Topperbc219812012-02-07 02:50:20 +0000599 llvm_unreachable("bad SymbolicOp.VariantKind");
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000600
601 return true;
602}
603
604/// tryAddingPcLoadReferenceComment - trys to add a comment as to what is being
605/// referenced by a load instruction with the base register that is the Pc.
606/// These can often be values in a literal pool near the Address of the
607/// instruction. The Address of the instruction and its immediate Value are
608/// used as a possible literal pool entry. The SymbolLookUp call back will
Sylvestre Ledruc8e41c52012-07-23 08:51:15 +0000609/// return the name of a symbol referenced by the literal pool's entry if
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000610/// the referenced address is that of a symbol. Or it will return a pointer to
611/// a literal 'C' string if the referenced address of the literal pool's entry
612/// is an address into a section with 'C' string literals.
613static void tryAddingPcLoadReferenceComment(uint64_t Address, int Value,
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000614 const void *Decoder) {
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000615 const MCDisassembler *Dis = static_cast<const MCDisassembler*>(Decoder);
616 LLVMSymbolLookupCallback SymbolLookUp = Dis->getLLVMSymbolLookupCallback();
617 if (SymbolLookUp) {
618 void *DisInfo = Dis->getDisInfoBlock();
619 uint64_t ReferenceType;
620 ReferenceType = LLVMDisassembler_ReferenceType_In_PCrel_Load;
621 const char *ReferenceName;
622 (void)SymbolLookUp(DisInfo, Value, &ReferenceType, Address, &ReferenceName);
623 if(ReferenceType == LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr ||
624 ReferenceType == LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr)
625 (*Dis->CommentStream) << "literal pool for: " << ReferenceName;
626 }
627}
628
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000629// Thumb1 instructions don't have explicit S bits. Rather, they
630// implicitly set CPSR. Since it's not represented in the encoding, the
631// auto-generated decoder won't inject the CPSR operand. We need to fix
632// that as a post-pass.
633static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
634 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000635 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000636 MCInst::iterator I = MI.begin();
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000637 for (unsigned i = 0; i < NumOps; ++i, ++I) {
638 if (I == MI.end()) break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000639 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000640 if (i > 0 && OpInfo[i-1].isPredicate()) continue;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000641 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
642 return;
643 }
644 }
645
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000646 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000647}
648
649// Most Thumb instructions don't have explicit predicates in the
650// encoding, but rather get their predicates from IT context. We need
651// to fix up the predicate operands using this context information as a
652// post-pass.
Owen Andersond2fc31b2011-09-08 22:42:49 +0000653MCDisassembler::DecodeStatus
654ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000655 MCDisassembler::DecodeStatus S = Success;
656
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000657 // A few instructions actually have predicates encoded in them. Don't
658 // try to overwrite it if we're seeing one of those.
659 switch (MI.getOpcode()) {
660 case ARM::tBcc:
661 case ARM::t2Bcc:
Owen Andersond2fc31b2011-09-08 22:42:49 +0000662 case ARM::tCBZ:
663 case ARM::tCBNZ:
Owen Anderson9f666b52011-09-19 23:47:10 +0000664 case ARM::tCPS:
665 case ARM::t2CPS3p:
666 case ARM::t2CPS2p:
667 case ARM::t2CPS1p:
Owen Andersond9346fb2011-09-19 23:57:20 +0000668 case ARM::tMOVSr:
Owen Andersonc18e9402011-10-13 17:58:39 +0000669 case ARM::tSETEND:
Owen Anderson441462f2011-09-08 22:48:37 +0000670 // Some instructions (mostly conditional branches) are not
671 // allowed in IT blocks.
Richard Bartonf4478f92012-04-24 11:13:20 +0000672 if (ITBlock.instrInITBlock())
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000673 S = SoftFail;
674 else
675 return Success;
676 break;
677 case ARM::tB:
678 case ARM::t2B:
Owen Anderson04c78772011-09-19 22:34:23 +0000679 case ARM::t2TBB:
680 case ARM::t2TBH:
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000681 // Some instructions (mostly unconditional branches) can
682 // only appears at the end of, or outside of, an IT.
Richard Bartonf4478f92012-04-24 11:13:20 +0000683 if (ITBlock.instrInITBlock() && !ITBlock.instrLastInITBlock())
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000684 S = SoftFail;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000685 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000686 default:
687 break;
688 }
689
690 // If we're in an IT block, base the predicate on that. Otherwise,
691 // assume a predicate of AL.
692 unsigned CC;
Richard Bartonf4478f92012-04-24 11:13:20 +0000693 CC = ITBlock.getITCC();
694 if (CC == 0xF)
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000695 CC = ARMCC::AL;
Richard Bartonf4478f92012-04-24 11:13:20 +0000696 if (ITBlock.instrInITBlock())
697 ITBlock.advanceITState();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000698
699 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000700 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000701 MCInst::iterator I = MI.begin();
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000702 for (unsigned i = 0; i < NumOps; ++i, ++I) {
703 if (I == MI.end()) break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000704 if (OpInfo[i].isPredicate()) {
705 I = MI.insert(I, MCOperand::CreateImm(CC));
706 ++I;
707 if (CC == ARMCC::AL)
708 MI.insert(I, MCOperand::CreateReg(0));
709 else
710 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000711 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000712 }
713 }
714
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000715 I = MI.insert(I, MCOperand::CreateImm(CC));
716 ++I;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000717 if (CC == ARMCC::AL)
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000718 MI.insert(I, MCOperand::CreateReg(0));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000719 else
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000720 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
Owen Andersond2fc31b2011-09-08 22:42:49 +0000721
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000722 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000723}
724
725// Thumb VFP instructions are a special case. Because we share their
726// encodings between ARM and Thumb modes, and they are predicable in ARM
727// mode, the auto-generated decoder will give them an (incorrect)
728// predicate operand. We need to rewrite these operands based on the IT
729// context as a post-pass.
730void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
731 unsigned CC;
Richard Bartonf4478f92012-04-24 11:13:20 +0000732 CC = ITBlock.getITCC();
733 if (ITBlock.instrInITBlock())
734 ITBlock.advanceITState();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000735
736 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
737 MCInst::iterator I = MI.begin();
Owen Anderson12a1e3b2011-08-24 21:35:46 +0000738 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
739 for (unsigned i = 0; i < NumOps; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000740 if (OpInfo[i].isPredicate() ) {
741 I->setImm(CC);
742 ++I;
743 if (CC == ARMCC::AL)
744 I->setReg(0);
745 else
746 I->setReg(ARM::CPSR);
747 return;
748 }
749 }
750}
751
Owen Andersona6804442011-09-01 23:23:50 +0000752DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000753 const MemoryObject &Region,
Jim Grosbachc4057822011-08-17 21:58:18 +0000754 uint64_t Address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000755 raw_ostream &os,
756 raw_ostream &cs) const {
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000757 CommentStream = &cs;
758
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000759 uint8_t bytes[4];
760
James Molloya5d58562011-09-07 19:42:28 +0000761 assert((STI.getFeatureBits() & ARM::ModeThumb) &&
762 "Asked to disassemble in Thumb mode but Subtarget is in ARM mode!");
763
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000764 // We want to read exactly 2 bytes of data.
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000765 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1) {
766 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000767 return MCDisassembler::Fail;
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000768 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000769
770 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000771 DecodeStatus result = decodeInstruction(DecoderTableThumb16, MI, insn16,
772 Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000773 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000774 Size = 2;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000775 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000776 return result;
Owen Anderson16280302011-08-16 23:45:44 +0000777 }
778
779 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000780 result = decodeInstruction(DecoderTableThumbSBit16, MI, insn16,
781 Address, this, STI);
Owen Anderson16280302011-08-16 23:45:44 +0000782 if (result) {
783 Size = 2;
Richard Bartonf4478f92012-04-24 11:13:20 +0000784 bool InITBlock = ITBlock.instrInITBlock();
Owen Andersond2fc31b2011-09-08 22:42:49 +0000785 Check(result, AddThumbPredicate(MI));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000786 AddThumb1SBit(MI, InITBlock);
Owen Anderson83e3f672011-08-17 17:44:15 +0000787 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000788 }
789
790 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000791 result = decodeInstruction(DecoderTableThumb216, MI, insn16,
792 Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000793 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000794 Size = 2;
Owen Anderson7011eee2011-10-06 23:33:11 +0000795
796 // Nested IT blocks are UNPREDICTABLE. Must be checked before we add
797 // the Thumb predicate.
Richard Bartonf4478f92012-04-24 11:13:20 +0000798 if (MI.getOpcode() == ARM::t2IT && ITBlock.instrInITBlock())
Owen Anderson7011eee2011-10-06 23:33:11 +0000799 result = MCDisassembler::SoftFail;
800
Owen Andersond2fc31b2011-09-08 22:42:49 +0000801 Check(result, AddThumbPredicate(MI));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000802
803 // If we find an IT instruction, we need to parse its condition
804 // code and mask operands so that we can apply them correctly
805 // to the subsequent instructions.
806 if (MI.getOpcode() == ARM::t2IT) {
Owen Anderson34626ac2011-09-14 21:06:21 +0000807
Richard Bartonf4478f92012-04-24 11:13:20 +0000808 unsigned Firstcond = MI.getOperand(0).getImm();
Owen Andersoneaca9282011-08-30 22:58:27 +0000809 unsigned Mask = MI.getOperand(1).getImm();
Richard Bartonf4478f92012-04-24 11:13:20 +0000810 ITBlock.setITState(Firstcond, Mask);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000811 }
812
Owen Anderson83e3f672011-08-17 17:44:15 +0000813 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000814 }
815
816 // We want to read exactly 4 bytes of data.
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000817 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
818 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000819 return MCDisassembler::Fail;
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000820 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000821
822 uint32_t insn32 = (bytes[3] << 8) |
823 (bytes[2] << 0) |
824 (bytes[1] << 24) |
825 (bytes[0] << 16);
826 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000827 result = decodeInstruction(DecoderTableThumb32, MI, insn32, Address,
828 this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000829 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000830 Size = 4;
Richard Bartonf4478f92012-04-24 11:13:20 +0000831 bool InITBlock = ITBlock.instrInITBlock();
Owen Andersond2fc31b2011-09-08 22:42:49 +0000832 Check(result, AddThumbPredicate(MI));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000833 AddThumb1SBit(MI, InITBlock);
Owen Anderson83e3f672011-08-17 17:44:15 +0000834 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000835 }
836
837 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000838 result = decodeInstruction(DecoderTableThumb232, MI, insn32, Address,
839 this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000840 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000841 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000842 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000843 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000844 }
845
846 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000847 result = decodeInstruction(DecoderTableVFP32, MI, insn32, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000848 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000849 Size = 4;
850 UpdateThumbVFPPredicate(MI);
Owen Anderson83e3f672011-08-17 17:44:15 +0000851 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000852 }
853
854 MI.clear();
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000855 result = decodeInstruction(DecoderTableNEONDup32, MI, insn32, Address,
856 this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000857 if (result != MCDisassembler::Fail) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000858 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000859 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000860 return result;
Owen Andersonef2865a2011-08-15 23:38:54 +0000861 }
862
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000863 if (fieldFromInstruction(insn32, 24, 8) == 0xF9) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000864 MI.clear();
865 uint32_t NEONLdStInsn = insn32;
866 NEONLdStInsn &= 0xF0FFFFFF;
867 NEONLdStInsn |= 0x04000000;
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000868 result = decodeInstruction(DecoderTableNEONLoadStore32, MI, NEONLdStInsn,
869 Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000870 if (result != MCDisassembler::Fail) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000871 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000872 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000873 return result;
Owen Andersonef2865a2011-08-15 23:38:54 +0000874 }
875 }
876
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000877 if (fieldFromInstruction(insn32, 24, 4) == 0xF) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000878 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000879 uint32_t NEONDataInsn = insn32;
880 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
881 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
882 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
Jim Grosbachfc1a1612012-08-14 19:06:05 +0000883 result = decodeInstruction(DecoderTableNEONData32, MI, NEONDataInsn,
884 Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000885 if (result != MCDisassembler::Fail) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000886 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000887 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000888 return result;
Owen Anderson8533eba2011-08-10 19:01:10 +0000889 }
890 }
891
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000892 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000893 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000894}
895
896
897extern "C" void LLVMInitializeARMDisassembler() {
898 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
899 createARMDisassembler);
900 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
901 createThumbDisassembler);
902}
903
Craig Topperb78ca422012-03-11 07:16:55 +0000904static const uint16_t GPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000905 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
906 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
907 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
908 ARM::R12, ARM::SP, ARM::LR, ARM::PC
909};
910
Craig Topperc89c7442012-03-27 07:21:54 +0000911static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000912 uint64_t Address, const void *Decoder) {
913 if (RegNo > 15)
James Molloyc047dca2011-09-01 18:02:14 +0000914 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000915
916 unsigned Register = GPRDecoderTable[RegNo];
917 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +0000918 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000919}
920
Owen Andersona6804442011-09-01 23:23:50 +0000921static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +0000922DecodeGPRnopcRegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbachc4057822011-08-17 21:58:18 +0000923 uint64_t Address, const void *Decoder) {
Silviu Baranga5c062ad2012-03-20 15:54:56 +0000924 DecodeStatus S = MCDisassembler::Success;
925
926 if (RegNo == 15)
927 S = MCDisassembler::SoftFail;
928
929 Check(S, DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder));
930
931 return S;
Owen Anderson51c98052011-08-09 22:48:45 +0000932}
933
Mihai Popaf86e4362013-05-13 14:10:04 +0000934static DecodeStatus
935DecodeGPRwithAPSRRegisterClass(MCInst &Inst, unsigned RegNo,
936 uint64_t Address, const void *Decoder) {
937 DecodeStatus S = MCDisassembler::Success;
938
939 if (RegNo == 15)
940 {
941 Inst.addOperand(MCOperand::CreateReg(ARM::APSR_NZCV));
942 return MCDisassembler::Success;
943 }
944
945 Check(S, DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder));
946 return S;
947}
948
Craig Topperc89c7442012-03-27 07:21:54 +0000949static DecodeStatus DecodetGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000950 uint64_t Address, const void *Decoder) {
951 if (RegNo > 7)
James Molloyc047dca2011-09-01 18:02:14 +0000952 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000953 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
954}
955
Craig Topperc89c7442012-03-27 07:21:54 +0000956static DecodeStatus DecodetcGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000957 uint64_t Address, const void *Decoder) {
958 unsigned Register = 0;
959 switch (RegNo) {
960 case 0:
961 Register = ARM::R0;
962 break;
963 case 1:
964 Register = ARM::R1;
965 break;
966 case 2:
967 Register = ARM::R2;
968 break;
969 case 3:
970 Register = ARM::R3;
971 break;
972 case 9:
973 Register = ARM::R9;
974 break;
975 case 12:
976 Register = ARM::R12;
977 break;
978 default:
James Molloyc047dca2011-09-01 18:02:14 +0000979 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000980 }
981
982 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +0000983 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000984}
985
Craig Topperc89c7442012-03-27 07:21:54 +0000986static DecodeStatus DecoderGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000987 uint64_t Address, const void *Decoder) {
James Molloyc047dca2011-09-01 18:02:14 +0000988 if (RegNo == 13 || RegNo == 15) return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000989 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
990}
991
Craig Topperb78ca422012-03-11 07:16:55 +0000992static const uint16_t SPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000993 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
994 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
995 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
996 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
997 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
998 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
999 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
1000 ARM::S28, ARM::S29, ARM::S30, ARM::S31
1001};
1002
Craig Topperc89c7442012-03-27 07:21:54 +00001003static DecodeStatus DecodeSPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001004 uint64_t Address, const void *Decoder) {
1005 if (RegNo > 31)
James Molloyc047dca2011-09-01 18:02:14 +00001006 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001007
1008 unsigned Register = SPRDecoderTable[RegNo];
1009 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +00001010 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001011}
1012
Craig Topperb78ca422012-03-11 07:16:55 +00001013static const uint16_t DPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001014 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
1015 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
1016 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
1017 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
1018 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
1019 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
1020 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
1021 ARM::D28, ARM::D29, ARM::D30, ARM::D31
1022};
1023
Craig Topperc89c7442012-03-27 07:21:54 +00001024static DecodeStatus DecodeDPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001025 uint64_t Address, const void *Decoder) {
1026 if (RegNo > 31)
James Molloyc047dca2011-09-01 18:02:14 +00001027 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001028
1029 unsigned Register = DPRDecoderTable[RegNo];
1030 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +00001031 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001032}
1033
Craig Topperc89c7442012-03-27 07:21:54 +00001034static DecodeStatus DecodeDPR_8RegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001035 uint64_t Address, const void *Decoder) {
1036 if (RegNo > 7)
James Molloyc047dca2011-09-01 18:02:14 +00001037 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001038 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
1039}
1040
Owen Andersona6804442011-09-01 23:23:50 +00001041static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00001042DecodeDPR_VFP2RegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbachc4057822011-08-17 21:58:18 +00001043 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001044 if (RegNo > 15)
James Molloyc047dca2011-09-01 18:02:14 +00001045 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001046 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
1047}
1048
Craig Topperb78ca422012-03-11 07:16:55 +00001049static const uint16_t QPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001050 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
1051 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
1052 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
1053 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
1054};
1055
1056
Craig Topperc89c7442012-03-27 07:21:54 +00001057static DecodeStatus DecodeQPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001058 uint64_t Address, const void *Decoder) {
Mihai Popabac932e2013-05-20 14:42:43 +00001059 if (RegNo > 31 || (RegNo & 1) != 0)
James Molloyc047dca2011-09-01 18:02:14 +00001060 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001061 RegNo >>= 1;
1062
1063 unsigned Register = QPRDecoderTable[RegNo];
1064 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +00001065 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001066}
1067
Craig Topperb78ca422012-03-11 07:16:55 +00001068static const uint16_t DPairDecoderTable[] = {
Jim Grosbach28f08c92012-03-05 19:33:30 +00001069 ARM::Q0, ARM::D1_D2, ARM::Q1, ARM::D3_D4, ARM::Q2, ARM::D5_D6,
1070 ARM::Q3, ARM::D7_D8, ARM::Q4, ARM::D9_D10, ARM::Q5, ARM::D11_D12,
1071 ARM::Q6, ARM::D13_D14, ARM::Q7, ARM::D15_D16, ARM::Q8, ARM::D17_D18,
1072 ARM::Q9, ARM::D19_D20, ARM::Q10, ARM::D21_D22, ARM::Q11, ARM::D23_D24,
1073 ARM::Q12, ARM::D25_D26, ARM::Q13, ARM::D27_D28, ARM::Q14, ARM::D29_D30,
1074 ARM::Q15
1075};
1076
Craig Topperc89c7442012-03-27 07:21:54 +00001077static DecodeStatus DecodeDPairRegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbach28f08c92012-03-05 19:33:30 +00001078 uint64_t Address, const void *Decoder) {
1079 if (RegNo > 30)
1080 return MCDisassembler::Fail;
1081
1082 unsigned Register = DPairDecoderTable[RegNo];
1083 Inst.addOperand(MCOperand::CreateReg(Register));
1084 return MCDisassembler::Success;
1085}
1086
Craig Topperb78ca422012-03-11 07:16:55 +00001087static const uint16_t DPairSpacedDecoderTable[] = {
Jim Grosbachc3384c92012-03-05 21:43:40 +00001088 ARM::D0_D2, ARM::D1_D3, ARM::D2_D4, ARM::D3_D5,
1089 ARM::D4_D6, ARM::D5_D7, ARM::D6_D8, ARM::D7_D9,
1090 ARM::D8_D10, ARM::D9_D11, ARM::D10_D12, ARM::D11_D13,
1091 ARM::D12_D14, ARM::D13_D15, ARM::D14_D16, ARM::D15_D17,
1092 ARM::D16_D18, ARM::D17_D19, ARM::D18_D20, ARM::D19_D21,
1093 ARM::D20_D22, ARM::D21_D23, ARM::D22_D24, ARM::D23_D25,
1094 ARM::D24_D26, ARM::D25_D27, ARM::D26_D28, ARM::D27_D29,
1095 ARM::D28_D30, ARM::D29_D31
1096};
1097
Craig Topperc89c7442012-03-27 07:21:54 +00001098static DecodeStatus DecodeDPairSpacedRegisterClass(MCInst &Inst,
Jim Grosbachc3384c92012-03-05 21:43:40 +00001099 unsigned RegNo,
1100 uint64_t Address,
1101 const void *Decoder) {
1102 if (RegNo > 29)
1103 return MCDisassembler::Fail;
1104
1105 unsigned Register = DPairSpacedDecoderTable[RegNo];
1106 Inst.addOperand(MCOperand::CreateReg(Register));
1107 return MCDisassembler::Success;
1108}
1109
Craig Topperc89c7442012-03-27 07:21:54 +00001110static DecodeStatus DecodePredicateOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001111 uint64_t Address, const void *Decoder) {
James Molloyc047dca2011-09-01 18:02:14 +00001112 if (Val == 0xF) return MCDisassembler::Fail;
Owen Andersonbd9091c2011-08-09 21:07:45 +00001113 // AL predicate is not allowed on Thumb1 branches.
1114 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
James Molloyc047dca2011-09-01 18:02:14 +00001115 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001116 Inst.addOperand(MCOperand::CreateImm(Val));
1117 if (Val == ARMCC::AL) {
1118 Inst.addOperand(MCOperand::CreateReg(0));
1119 } else
1120 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
James Molloyc047dca2011-09-01 18:02:14 +00001121 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001122}
1123
Craig Topperc89c7442012-03-27 07:21:54 +00001124static DecodeStatus DecodeCCOutOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001125 uint64_t Address, const void *Decoder) {
1126 if (Val)
1127 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
1128 else
1129 Inst.addOperand(MCOperand::CreateReg(0));
James Molloyc047dca2011-09-01 18:02:14 +00001130 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001131}
1132
Craig Topperc89c7442012-03-27 07:21:54 +00001133static DecodeStatus DecodeSOImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001134 uint64_t Address, const void *Decoder) {
1135 uint32_t imm = Val & 0xFF;
1136 uint32_t rot = (Val & 0xF00) >> 7;
Eli Friedmanecb830e2011-10-13 23:36:06 +00001137 uint32_t rot_imm = (imm >> rot) | (imm << ((32-rot) & 0x1F));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001138 Inst.addOperand(MCOperand::CreateImm(rot_imm));
James Molloyc047dca2011-09-01 18:02:14 +00001139 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001140}
1141
Craig Topperc89c7442012-03-27 07:21:54 +00001142static DecodeStatus DecodeSORegImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001143 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001144 DecodeStatus S = MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001145
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001146 unsigned Rm = fieldFromInstruction(Val, 0, 4);
1147 unsigned type = fieldFromInstruction(Val, 5, 2);
1148 unsigned imm = fieldFromInstruction(Val, 7, 5);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001149
1150 // Register-immediate
Owen Andersona6804442011-09-01 23:23:50 +00001151 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
1152 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001153
1154 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
1155 switch (type) {
1156 case 0:
1157 Shift = ARM_AM::lsl;
1158 break;
1159 case 1:
1160 Shift = ARM_AM::lsr;
1161 break;
1162 case 2:
1163 Shift = ARM_AM::asr;
1164 break;
1165 case 3:
1166 Shift = ARM_AM::ror;
1167 break;
1168 }
1169
1170 if (Shift == ARM_AM::ror && imm == 0)
1171 Shift = ARM_AM::rrx;
1172
1173 unsigned Op = Shift | (imm << 3);
1174 Inst.addOperand(MCOperand::CreateImm(Op));
1175
Owen Anderson83e3f672011-08-17 17:44:15 +00001176 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001177}
1178
Craig Topperc89c7442012-03-27 07:21:54 +00001179static DecodeStatus DecodeSORegRegOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001180 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001181 DecodeStatus S = MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001182
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001183 unsigned Rm = fieldFromInstruction(Val, 0, 4);
1184 unsigned type = fieldFromInstruction(Val, 5, 2);
1185 unsigned Rs = fieldFromInstruction(Val, 8, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001186
1187 // Register-register
Owen Andersona6804442011-09-01 23:23:50 +00001188 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
1189 return MCDisassembler::Fail;
1190 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder)))
1191 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001192
1193 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
1194 switch (type) {
1195 case 0:
1196 Shift = ARM_AM::lsl;
1197 break;
1198 case 1:
1199 Shift = ARM_AM::lsr;
1200 break;
1201 case 2:
1202 Shift = ARM_AM::asr;
1203 break;
1204 case 3:
1205 Shift = ARM_AM::ror;
1206 break;
1207 }
1208
1209 Inst.addOperand(MCOperand::CreateImm(Shift));
1210
Owen Anderson83e3f672011-08-17 17:44:15 +00001211 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001212}
1213
Craig Topperc89c7442012-03-27 07:21:54 +00001214static DecodeStatus DecodeRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001215 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001216 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001217
Owen Anderson921d01a2011-09-09 23:13:33 +00001218 bool writebackLoad = false;
1219 unsigned writebackReg = 0;
1220 switch (Inst.getOpcode()) {
1221 default:
1222 break;
1223 case ARM::LDMIA_UPD:
1224 case ARM::LDMDB_UPD:
1225 case ARM::LDMIB_UPD:
1226 case ARM::LDMDA_UPD:
1227 case ARM::t2LDMIA_UPD:
1228 case ARM::t2LDMDB_UPD:
1229 writebackLoad = true;
1230 writebackReg = Inst.getOperand(0).getReg();
1231 break;
1232 }
1233
Owen Anderson26d2f0a2011-08-11 20:21:46 +00001234 // Empty register lists are not allowed.
Benjamin Kramer4dc8bdf2013-05-19 22:01:57 +00001235 if (Val == 0) return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001236 for (unsigned i = 0; i < 16; ++i) {
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001237 if (Val & (1 << i)) {
Owen Andersona6804442011-09-01 23:23:50 +00001238 if (!Check(S, DecodeGPRRegisterClass(Inst, i, Address, Decoder)))
1239 return MCDisassembler::Fail;
Owen Anderson921d01a2011-09-09 23:13:33 +00001240 // Writeback not allowed if Rn is in the target list.
1241 if (writebackLoad && writebackReg == Inst.end()[-1].getReg())
1242 Check(S, MCDisassembler::SoftFail);
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001243 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001244 }
1245
Owen Anderson83e3f672011-08-17 17:44:15 +00001246 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001247}
1248
Craig Topperc89c7442012-03-27 07:21:54 +00001249static DecodeStatus DecodeSPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001250 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001251 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001252
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001253 unsigned Vd = fieldFromInstruction(Val, 8, 5);
1254 unsigned regs = fieldFromInstruction(Val, 0, 8);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001255
Owen Andersona6804442011-09-01 23:23:50 +00001256 if (!Check(S, DecodeSPRRegisterClass(Inst, Vd, Address, Decoder)))
1257 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001258 for (unsigned i = 0; i < (regs - 1); ++i) {
Owen Andersona6804442011-09-01 23:23:50 +00001259 if (!Check(S, DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder)))
1260 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001261 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001262
Owen Anderson83e3f672011-08-17 17:44:15 +00001263 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001264}
1265
Craig Topperc89c7442012-03-27 07:21:54 +00001266static DecodeStatus DecodeDPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001267 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001268 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001269
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001270 unsigned Vd = fieldFromInstruction(Val, 8, 5);
1271 unsigned regs = fieldFromInstruction(Val, 0, 8);
Silviu Barangab422d0b2012-05-03 16:38:40 +00001272
1273 regs = regs >> 1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001274
Owen Andersona6804442011-09-01 23:23:50 +00001275 if (!Check(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)))
1276 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001277 for (unsigned i = 0; i < (regs - 1); ++i) {
Owen Andersona6804442011-09-01 23:23:50 +00001278 if (!Check(S, DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder)))
1279 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001280 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001281
Owen Anderson83e3f672011-08-17 17:44:15 +00001282 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001283}
1284
Craig Topperc89c7442012-03-27 07:21:54 +00001285static DecodeStatus DecodeBitfieldMaskOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001286 uint64_t Address, const void *Decoder) {
Owen Anderson10cbaab2011-08-10 17:36:48 +00001287 // This operand encodes a mask of contiguous zeros between a specified MSB
1288 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
1289 // the mask of all bits LSB-and-lower, and then xor them to create
Jim Grosbachc4057822011-08-17 21:58:18 +00001290 // the mask of that's all ones on [msb, lsb]. Finally we not it to
Owen Anderson10cbaab2011-08-10 17:36:48 +00001291 // create the final mask.
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001292 unsigned msb = fieldFromInstruction(Val, 5, 5);
1293 unsigned lsb = fieldFromInstruction(Val, 0, 5);
Owen Anderson89db0f62011-09-16 22:29:48 +00001294
Owen Andersoncb775512011-09-16 23:30:01 +00001295 DecodeStatus S = MCDisassembler::Success;
Kevin Enderby1c830932012-11-29 23:47:11 +00001296 if (lsb > msb) {
1297 Check(S, MCDisassembler::SoftFail);
1298 // The check above will cause the warning for the "potentially undefined
1299 // instruction encoding" but we can't build a bad MCOperand value here
1300 // with a lsb > msb or else printing the MCInst will cause a crash.
1301 lsb = msb;
1302 }
Owen Andersoncb775512011-09-16 23:30:01 +00001303
Owen Anderson8b227782011-09-16 23:04:48 +00001304 uint32_t msb_mask = 0xFFFFFFFF;
1305 if (msb != 31) msb_mask = (1U << (msb+1)) - 1;
1306 uint32_t lsb_mask = (1U << lsb) - 1;
Owen Anderson89db0f62011-09-16 22:29:48 +00001307
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001308 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
Owen Andersoncb775512011-09-16 23:30:01 +00001309 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001310}
1311
Craig Topperc89c7442012-03-27 07:21:54 +00001312static DecodeStatus DecodeCopMemInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001313 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001314 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001315
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001316 unsigned pred = fieldFromInstruction(Insn, 28, 4);
1317 unsigned CRd = fieldFromInstruction(Insn, 12, 4);
1318 unsigned coproc = fieldFromInstruction(Insn, 8, 4);
1319 unsigned imm = fieldFromInstruction(Insn, 0, 8);
1320 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
1321 unsigned U = fieldFromInstruction(Insn, 23, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001322
1323 switch (Inst.getOpcode()) {
1324 case ARM::LDC_OFFSET:
1325 case ARM::LDC_PRE:
1326 case ARM::LDC_POST:
1327 case ARM::LDC_OPTION:
1328 case ARM::LDCL_OFFSET:
1329 case ARM::LDCL_PRE:
1330 case ARM::LDCL_POST:
1331 case ARM::LDCL_OPTION:
1332 case ARM::STC_OFFSET:
1333 case ARM::STC_PRE:
1334 case ARM::STC_POST:
1335 case ARM::STC_OPTION:
1336 case ARM::STCL_OFFSET:
1337 case ARM::STCL_PRE:
1338 case ARM::STCL_POST:
1339 case ARM::STCL_OPTION:
Owen Anderson8a83f712011-09-07 21:10:42 +00001340 case ARM::t2LDC_OFFSET:
1341 case ARM::t2LDC_PRE:
1342 case ARM::t2LDC_POST:
1343 case ARM::t2LDC_OPTION:
1344 case ARM::t2LDCL_OFFSET:
1345 case ARM::t2LDCL_PRE:
1346 case ARM::t2LDCL_POST:
1347 case ARM::t2LDCL_OPTION:
1348 case ARM::t2STC_OFFSET:
1349 case ARM::t2STC_PRE:
1350 case ARM::t2STC_POST:
1351 case ARM::t2STC_OPTION:
1352 case ARM::t2STCL_OFFSET:
1353 case ARM::t2STCL_PRE:
1354 case ARM::t2STCL_POST:
1355 case ARM::t2STCL_OPTION:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001356 if (coproc == 0xA || coproc == 0xB)
James Molloyc047dca2011-09-01 18:02:14 +00001357 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001358 break;
1359 default:
1360 break;
1361 }
1362
1363 Inst.addOperand(MCOperand::CreateImm(coproc));
1364 Inst.addOperand(MCOperand::CreateImm(CRd));
Owen Andersona6804442011-09-01 23:23:50 +00001365 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1366 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001367
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001368 switch (Inst.getOpcode()) {
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001369 case ARM::t2LDC2_OFFSET:
1370 case ARM::t2LDC2L_OFFSET:
1371 case ARM::t2LDC2_PRE:
1372 case ARM::t2LDC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001373 case ARM::t2STC2_OFFSET:
1374 case ARM::t2STC2L_OFFSET:
1375 case ARM::t2STC2_PRE:
1376 case ARM::t2STC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001377 case ARM::LDC2_OFFSET:
1378 case ARM::LDC2L_OFFSET:
1379 case ARM::LDC2_PRE:
1380 case ARM::LDC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001381 case ARM::STC2_OFFSET:
1382 case ARM::STC2L_OFFSET:
1383 case ARM::STC2_PRE:
1384 case ARM::STC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001385 case ARM::t2LDC_OFFSET:
1386 case ARM::t2LDCL_OFFSET:
1387 case ARM::t2LDC_PRE:
1388 case ARM::t2LDCL_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001389 case ARM::t2STC_OFFSET:
1390 case ARM::t2STCL_OFFSET:
1391 case ARM::t2STC_PRE:
1392 case ARM::t2STCL_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001393 case ARM::LDC_OFFSET:
1394 case ARM::LDCL_OFFSET:
1395 case ARM::LDC_PRE:
1396 case ARM::LDCL_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001397 case ARM::STC_OFFSET:
1398 case ARM::STCL_OFFSET:
1399 case ARM::STC_PRE:
1400 case ARM::STCL_PRE:
Jim Grosbach81b29282011-10-12 21:59:02 +00001401 imm = ARM_AM::getAM5Opc(U ? ARM_AM::add : ARM_AM::sub, imm);
1402 Inst.addOperand(MCOperand::CreateImm(imm));
1403 break;
1404 case ARM::t2LDC2_POST:
1405 case ARM::t2LDC2L_POST:
1406 case ARM::t2STC2_POST:
1407 case ARM::t2STC2L_POST:
1408 case ARM::LDC2_POST:
1409 case ARM::LDC2L_POST:
1410 case ARM::STC2_POST:
1411 case ARM::STC2L_POST:
1412 case ARM::t2LDC_POST:
1413 case ARM::t2LDCL_POST:
1414 case ARM::t2STC_POST:
1415 case ARM::t2STCL_POST:
1416 case ARM::LDC_POST:
1417 case ARM::LDCL_POST:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001418 case ARM::STC_POST:
1419 case ARM::STCL_POST:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001420 imm |= U << 8;
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001421 // fall through.
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001422 default:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001423 // The 'option' variant doesn't encode 'U' in the immediate since
1424 // the immediate is unsigned [0,255].
1425 Inst.addOperand(MCOperand::CreateImm(imm));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001426 break;
1427 }
1428
1429 switch (Inst.getOpcode()) {
1430 case ARM::LDC_OFFSET:
1431 case ARM::LDC_PRE:
1432 case ARM::LDC_POST:
1433 case ARM::LDC_OPTION:
1434 case ARM::LDCL_OFFSET:
1435 case ARM::LDCL_PRE:
1436 case ARM::LDCL_POST:
1437 case ARM::LDCL_OPTION:
1438 case ARM::STC_OFFSET:
1439 case ARM::STC_PRE:
1440 case ARM::STC_POST:
1441 case ARM::STC_OPTION:
1442 case ARM::STCL_OFFSET:
1443 case ARM::STCL_PRE:
1444 case ARM::STCL_POST:
1445 case ARM::STCL_OPTION:
Owen Andersona6804442011-09-01 23:23:50 +00001446 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1447 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001448 break;
1449 default:
1450 break;
1451 }
1452
Owen Anderson83e3f672011-08-17 17:44:15 +00001453 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001454}
1455
Owen Andersona6804442011-09-01 23:23:50 +00001456static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00001457DecodeAddrMode2IdxInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00001458 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001459 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001460
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001461 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
1462 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
1463 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
1464 unsigned imm = fieldFromInstruction(Insn, 0, 12);
1465 unsigned pred = fieldFromInstruction(Insn, 28, 4);
1466 unsigned reg = fieldFromInstruction(Insn, 25, 1);
1467 unsigned P = fieldFromInstruction(Insn, 24, 1);
1468 unsigned W = fieldFromInstruction(Insn, 21, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001469
1470 // On stores, the writeback operand precedes Rt.
1471 switch (Inst.getOpcode()) {
1472 case ARM::STR_POST_IMM:
1473 case ARM::STR_POST_REG:
Owen Anderson508e1d32011-08-11 20:47:56 +00001474 case ARM::STRB_POST_IMM:
1475 case ARM::STRB_POST_REG:
Jim Grosbach342ebd52011-08-11 22:18:00 +00001476 case ARM::STRT_POST_REG:
1477 case ARM::STRT_POST_IMM:
Jim Grosbach10348e72011-08-11 20:04:56 +00001478 case ARM::STRBT_POST_REG:
1479 case ARM::STRBT_POST_IMM:
Owen Andersona6804442011-09-01 23:23:50 +00001480 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1481 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001482 break;
1483 default:
1484 break;
1485 }
1486
Owen Andersona6804442011-09-01 23:23:50 +00001487 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
1488 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001489
1490 // On loads, the writeback operand comes after Rt.
1491 switch (Inst.getOpcode()) {
1492 case ARM::LDR_POST_IMM:
1493 case ARM::LDR_POST_REG:
Owen Anderson508e1d32011-08-11 20:47:56 +00001494 case ARM::LDRB_POST_IMM:
1495 case ARM::LDRB_POST_REG:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001496 case ARM::LDRBT_POST_REG:
1497 case ARM::LDRBT_POST_IMM:
Jim Grosbach59999262011-08-10 23:43:54 +00001498 case ARM::LDRT_POST_REG:
1499 case ARM::LDRT_POST_IMM:
Owen Andersona6804442011-09-01 23:23:50 +00001500 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1501 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001502 break;
1503 default:
1504 break;
1505 }
1506
Owen Andersona6804442011-09-01 23:23:50 +00001507 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1508 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001509
1510 ARM_AM::AddrOpc Op = ARM_AM::add;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001511 if (!fieldFromInstruction(Insn, 23, 1))
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001512 Op = ARM_AM::sub;
1513
1514 bool writeback = (P == 0) || (W == 1);
1515 unsigned idx_mode = 0;
1516 if (P && writeback)
1517 idx_mode = ARMII::IndexModePre;
1518 else if (!P && writeback)
1519 idx_mode = ARMII::IndexModePost;
1520
Owen Andersona6804442011-09-01 23:23:50 +00001521 if (writeback && (Rn == 15 || Rn == Rt))
1522 S = MCDisassembler::SoftFail; // UNPREDICTABLE
Owen Anderson71156a62011-08-11 19:00:18 +00001523
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001524 if (reg) {
Owen Andersona6804442011-09-01 23:23:50 +00001525 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
1526 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001527 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001528 switch( fieldFromInstruction(Insn, 5, 2)) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001529 case 0:
1530 Opc = ARM_AM::lsl;
1531 break;
1532 case 1:
1533 Opc = ARM_AM::lsr;
1534 break;
1535 case 2:
1536 Opc = ARM_AM::asr;
1537 break;
1538 case 3:
1539 Opc = ARM_AM::ror;
1540 break;
1541 default:
James Molloyc047dca2011-09-01 18:02:14 +00001542 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001543 }
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001544 unsigned amt = fieldFromInstruction(Insn, 7, 5);
Tim Northover93c7c442012-09-22 11:18:12 +00001545 if (Opc == ARM_AM::ror && amt == 0)
1546 Opc = ARM_AM::rrx;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001547 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1548
1549 Inst.addOperand(MCOperand::CreateImm(imm));
1550 } else {
1551 Inst.addOperand(MCOperand::CreateReg(0));
1552 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1553 Inst.addOperand(MCOperand::CreateImm(tmp));
1554 }
1555
Owen Andersona6804442011-09-01 23:23:50 +00001556 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1557 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001558
Owen Anderson83e3f672011-08-17 17:44:15 +00001559 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001560}
1561
Craig Topperc89c7442012-03-27 07:21:54 +00001562static DecodeStatus DecodeSORegMemOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001563 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001564 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001565
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001566 unsigned Rn = fieldFromInstruction(Val, 13, 4);
1567 unsigned Rm = fieldFromInstruction(Val, 0, 4);
1568 unsigned type = fieldFromInstruction(Val, 5, 2);
1569 unsigned imm = fieldFromInstruction(Val, 7, 5);
1570 unsigned U = fieldFromInstruction(Val, 12, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001571
Owen Anderson51157d22011-08-09 21:38:14 +00001572 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001573 switch (type) {
1574 case 0:
1575 ShOp = ARM_AM::lsl;
1576 break;
1577 case 1:
1578 ShOp = ARM_AM::lsr;
1579 break;
1580 case 2:
1581 ShOp = ARM_AM::asr;
1582 break;
1583 case 3:
1584 ShOp = ARM_AM::ror;
1585 break;
1586 }
1587
Tim Northover93c7c442012-09-22 11:18:12 +00001588 if (ShOp == ARM_AM::ror && imm == 0)
1589 ShOp = ARM_AM::rrx;
1590
Owen Andersona6804442011-09-01 23:23:50 +00001591 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1592 return MCDisassembler::Fail;
1593 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
1594 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001595 unsigned shift;
1596 if (U)
1597 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1598 else
1599 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1600 Inst.addOperand(MCOperand::CreateImm(shift));
1601
Owen Anderson83e3f672011-08-17 17:44:15 +00001602 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001603}
1604
Owen Andersona6804442011-09-01 23:23:50 +00001605static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00001606DecodeAddrMode3Instruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00001607 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001608 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001609
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001610 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
1611 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
1612 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
1613 unsigned type = fieldFromInstruction(Insn, 22, 1);
1614 unsigned imm = fieldFromInstruction(Insn, 8, 4);
1615 unsigned U = ((~fieldFromInstruction(Insn, 23, 1)) & 1) << 8;
1616 unsigned pred = fieldFromInstruction(Insn, 28, 4);
1617 unsigned W = fieldFromInstruction(Insn, 21, 1);
1618 unsigned P = fieldFromInstruction(Insn, 24, 1);
Silviu Baranga6fe310e2012-03-22 14:14:49 +00001619 unsigned Rt2 = Rt + 1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001620
1621 bool writeback = (W == 1) | (P == 0);
Owen Andersonc537f3b2011-08-15 20:51:32 +00001622
1623 // For {LD,ST}RD, Rt must be even, else undefined.
1624 switch (Inst.getOpcode()) {
1625 case ARM::STRD:
1626 case ARM::STRD_PRE:
1627 case ARM::STRD_POST:
1628 case ARM::LDRD:
1629 case ARM::LDRD_PRE:
1630 case ARM::LDRD_POST:
Silviu Baranga6fe310e2012-03-22 14:14:49 +00001631 if (Rt & 0x1) S = MCDisassembler::SoftFail;
1632 break;
1633 default:
1634 break;
1635 }
1636 switch (Inst.getOpcode()) {
1637 case ARM::STRD:
1638 case ARM::STRD_PRE:
1639 case ARM::STRD_POST:
1640 if (P == 0 && W == 1)
1641 S = MCDisassembler::SoftFail;
1642
1643 if (writeback && (Rn == 15 || Rn == Rt || Rn == Rt2))
1644 S = MCDisassembler::SoftFail;
1645 if (type && Rm == 15)
1646 S = MCDisassembler::SoftFail;
1647 if (Rt2 == 15)
1648 S = MCDisassembler::SoftFail;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001649 if (!type && fieldFromInstruction(Insn, 8, 4))
Silviu Baranga6fe310e2012-03-22 14:14:49 +00001650 S = MCDisassembler::SoftFail;
1651 break;
1652 case ARM::STRH:
1653 case ARM::STRH_PRE:
1654 case ARM::STRH_POST:
1655 if (Rt == 15)
1656 S = MCDisassembler::SoftFail;
1657 if (writeback && (Rn == 15 || Rn == Rt))
1658 S = MCDisassembler::SoftFail;
1659 if (!type && Rm == 15)
1660 S = MCDisassembler::SoftFail;
1661 break;
1662 case ARM::LDRD:
1663 case ARM::LDRD_PRE:
1664 case ARM::LDRD_POST:
1665 if (type && Rn == 15){
1666 if (Rt2 == 15)
1667 S = MCDisassembler::SoftFail;
1668 break;
1669 }
1670 if (P == 0 && W == 1)
1671 S = MCDisassembler::SoftFail;
1672 if (!type && (Rt2 == 15 || Rm == 15 || Rm == Rt || Rm == Rt2))
1673 S = MCDisassembler::SoftFail;
1674 if (!type && writeback && Rn == 15)
1675 S = MCDisassembler::SoftFail;
1676 if (writeback && (Rn == Rt || Rn == Rt2))
1677 S = MCDisassembler::SoftFail;
1678 break;
1679 case ARM::LDRH:
1680 case ARM::LDRH_PRE:
1681 case ARM::LDRH_POST:
1682 if (type && Rn == 15){
1683 if (Rt == 15)
1684 S = MCDisassembler::SoftFail;
1685 break;
1686 }
1687 if (Rt == 15)
1688 S = MCDisassembler::SoftFail;
1689 if (!type && Rm == 15)
1690 S = MCDisassembler::SoftFail;
1691 if (!type && writeback && (Rn == 15 || Rn == Rt))
1692 S = MCDisassembler::SoftFail;
1693 break;
1694 case ARM::LDRSH:
1695 case ARM::LDRSH_PRE:
1696 case ARM::LDRSH_POST:
1697 case ARM::LDRSB:
1698 case ARM::LDRSB_PRE:
1699 case ARM::LDRSB_POST:
1700 if (type && Rn == 15){
1701 if (Rt == 15)
1702 S = MCDisassembler::SoftFail;
1703 break;
1704 }
1705 if (type && (Rt == 15 || (writeback && Rn == Rt)))
1706 S = MCDisassembler::SoftFail;
1707 if (!type && (Rt == 15 || Rm == 15))
1708 S = MCDisassembler::SoftFail;
1709 if (!type && writeback && (Rn == 15 || Rn == Rt))
1710 S = MCDisassembler::SoftFail;
Owen Andersonc537f3b2011-08-15 20:51:32 +00001711 break;
Owen Andersona6804442011-09-01 23:23:50 +00001712 default:
1713 break;
Owen Andersonc537f3b2011-08-15 20:51:32 +00001714 }
1715
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001716 if (writeback) { // Writeback
1717 if (P)
1718 U |= ARMII::IndexModePre << 9;
1719 else
1720 U |= ARMII::IndexModePost << 9;
1721
1722 // On stores, the writeback operand precedes Rt.
1723 switch (Inst.getOpcode()) {
1724 case ARM::STRD:
1725 case ARM::STRD_PRE:
1726 case ARM::STRD_POST:
Owen Anderson79628e92011-08-12 20:02:50 +00001727 case ARM::STRH:
1728 case ARM::STRH_PRE:
1729 case ARM::STRH_POST:
Owen Andersona6804442011-09-01 23:23:50 +00001730 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1731 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001732 break;
1733 default:
1734 break;
1735 }
1736 }
1737
Owen Andersona6804442011-09-01 23:23:50 +00001738 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
1739 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001740 switch (Inst.getOpcode()) {
1741 case ARM::STRD:
1742 case ARM::STRD_PRE:
1743 case ARM::STRD_POST:
1744 case ARM::LDRD:
1745 case ARM::LDRD_PRE:
1746 case ARM::LDRD_POST:
Owen Andersona6804442011-09-01 23:23:50 +00001747 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)))
1748 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001749 break;
1750 default:
1751 break;
1752 }
1753
1754 if (writeback) {
1755 // On loads, the writeback operand comes after Rt.
1756 switch (Inst.getOpcode()) {
1757 case ARM::LDRD:
1758 case ARM::LDRD_PRE:
1759 case ARM::LDRD_POST:
Owen Anderson0d094992011-08-12 20:36:11 +00001760 case ARM::LDRH:
1761 case ARM::LDRH_PRE:
1762 case ARM::LDRH_POST:
1763 case ARM::LDRSH:
1764 case ARM::LDRSH_PRE:
1765 case ARM::LDRSH_POST:
1766 case ARM::LDRSB:
1767 case ARM::LDRSB_PRE:
1768 case ARM::LDRSB_POST:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001769 case ARM::LDRHTr:
1770 case ARM::LDRSBTr:
Owen Andersona6804442011-09-01 23:23:50 +00001771 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1772 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001773 break;
1774 default:
1775 break;
1776 }
1777 }
1778
Owen Andersona6804442011-09-01 23:23:50 +00001779 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1780 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001781
1782 if (type) {
1783 Inst.addOperand(MCOperand::CreateReg(0));
1784 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1785 } else {
Owen Andersona6804442011-09-01 23:23:50 +00001786 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
1787 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001788 Inst.addOperand(MCOperand::CreateImm(U));
1789 }
1790
Owen Andersona6804442011-09-01 23:23:50 +00001791 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1792 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001793
Owen Anderson83e3f672011-08-17 17:44:15 +00001794 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001795}
1796
Craig Topperc89c7442012-03-27 07:21:54 +00001797static DecodeStatus DecodeRFEInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001798 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001799 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001800
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001801 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
1802 unsigned mode = fieldFromInstruction(Insn, 23, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001803
1804 switch (mode) {
1805 case 0:
1806 mode = ARM_AM::da;
1807 break;
1808 case 1:
1809 mode = ARM_AM::ia;
1810 break;
1811 case 2:
1812 mode = ARM_AM::db;
1813 break;
1814 case 3:
1815 mode = ARM_AM::ib;
1816 break;
1817 }
1818
1819 Inst.addOperand(MCOperand::CreateImm(mode));
Owen Andersona6804442011-09-01 23:23:50 +00001820 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1821 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001822
Owen Anderson83e3f672011-08-17 17:44:15 +00001823 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001824}
1825
Craig Topperc89c7442012-03-27 07:21:54 +00001826static DecodeStatus DecodeMemMultipleWritebackInstruction(MCInst &Inst,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001827 unsigned Insn,
1828 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001829 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001830
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001831 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
1832 unsigned pred = fieldFromInstruction(Insn, 28, 4);
1833 unsigned reglist = fieldFromInstruction(Insn, 0, 16);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001834
1835 if (pred == 0xF) {
1836 switch (Inst.getOpcode()) {
Owen Anderson846dd952011-08-18 22:31:17 +00001837 case ARM::LDMDA:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001838 Inst.setOpcode(ARM::RFEDA);
1839 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001840 case ARM::LDMDA_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001841 Inst.setOpcode(ARM::RFEDA_UPD);
1842 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001843 case ARM::LDMDB:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001844 Inst.setOpcode(ARM::RFEDB);
1845 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001846 case ARM::LDMDB_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001847 Inst.setOpcode(ARM::RFEDB_UPD);
1848 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001849 case ARM::LDMIA:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001850 Inst.setOpcode(ARM::RFEIA);
1851 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001852 case ARM::LDMIA_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001853 Inst.setOpcode(ARM::RFEIA_UPD);
1854 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001855 case ARM::LDMIB:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001856 Inst.setOpcode(ARM::RFEIB);
1857 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001858 case ARM::LDMIB_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001859 Inst.setOpcode(ARM::RFEIB_UPD);
1860 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001861 case ARM::STMDA:
1862 Inst.setOpcode(ARM::SRSDA);
1863 break;
1864 case ARM::STMDA_UPD:
1865 Inst.setOpcode(ARM::SRSDA_UPD);
1866 break;
1867 case ARM::STMDB:
1868 Inst.setOpcode(ARM::SRSDB);
1869 break;
1870 case ARM::STMDB_UPD:
1871 Inst.setOpcode(ARM::SRSDB_UPD);
1872 break;
1873 case ARM::STMIA:
1874 Inst.setOpcode(ARM::SRSIA);
1875 break;
1876 case ARM::STMIA_UPD:
1877 Inst.setOpcode(ARM::SRSIA_UPD);
1878 break;
1879 case ARM::STMIB:
1880 Inst.setOpcode(ARM::SRSIB);
1881 break;
1882 case ARM::STMIB_UPD:
1883 Inst.setOpcode(ARM::SRSIB_UPD);
1884 break;
1885 default:
James Molloyc047dca2011-09-01 18:02:14 +00001886 if (!Check(S, MCDisassembler::Fail)) return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001887 }
Owen Anderson846dd952011-08-18 22:31:17 +00001888
1889 // For stores (which become SRS's, the only operand is the mode.
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001890 if (fieldFromInstruction(Insn, 20, 1) == 0) {
Owen Anderson846dd952011-08-18 22:31:17 +00001891 Inst.addOperand(
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001892 MCOperand::CreateImm(fieldFromInstruction(Insn, 0, 4)));
Owen Anderson846dd952011-08-18 22:31:17 +00001893 return S;
1894 }
1895
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001896 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1897 }
1898
Owen Andersona6804442011-09-01 23:23:50 +00001899 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1900 return MCDisassembler::Fail;
1901 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1902 return MCDisassembler::Fail; // Tied
1903 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1904 return MCDisassembler::Fail;
1905 if (!Check(S, DecodeRegListOperand(Inst, reglist, Address, Decoder)))
1906 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001907
Owen Anderson83e3f672011-08-17 17:44:15 +00001908 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001909}
1910
Craig Topperc89c7442012-03-27 07:21:54 +00001911static DecodeStatus DecodeCPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001912 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001913 unsigned imod = fieldFromInstruction(Insn, 18, 2);
1914 unsigned M = fieldFromInstruction(Insn, 17, 1);
1915 unsigned iflags = fieldFromInstruction(Insn, 6, 3);
1916 unsigned mode = fieldFromInstruction(Insn, 0, 5);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001917
Owen Andersona6804442011-09-01 23:23:50 +00001918 DecodeStatus S = MCDisassembler::Success;
Owen Anderson35008c22011-08-09 23:05:39 +00001919
Owen Anderson14090bf2011-08-18 22:11:02 +00001920 // imod == '01' --> UNPREDICTABLE
1921 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1922 // return failure here. The '01' imod value is unprintable, so there's
1923 // nothing useful we could do even if we returned UNPREDICTABLE.
1924
James Molloyc047dca2011-09-01 18:02:14 +00001925 if (imod == 1) return MCDisassembler::Fail;
Owen Anderson14090bf2011-08-18 22:11:02 +00001926
1927 if (imod && M) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001928 Inst.setOpcode(ARM::CPS3p);
1929 Inst.addOperand(MCOperand::CreateImm(imod));
1930 Inst.addOperand(MCOperand::CreateImm(iflags));
1931 Inst.addOperand(MCOperand::CreateImm(mode));
Owen Anderson14090bf2011-08-18 22:11:02 +00001932 } else if (imod && !M) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001933 Inst.setOpcode(ARM::CPS2p);
1934 Inst.addOperand(MCOperand::CreateImm(imod));
1935 Inst.addOperand(MCOperand::CreateImm(iflags));
James Molloyc047dca2011-09-01 18:02:14 +00001936 if (mode) S = MCDisassembler::SoftFail;
Owen Anderson14090bf2011-08-18 22:11:02 +00001937 } else if (!imod && M) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001938 Inst.setOpcode(ARM::CPS1p);
1939 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001940 if (iflags) S = MCDisassembler::SoftFail;
Owen Anderson1dd56f02011-08-18 22:15:25 +00001941 } else {
Owen Anderson14090bf2011-08-18 22:11:02 +00001942 // imod == '00' && M == '0' --> UNPREDICTABLE
Owen Anderson1dd56f02011-08-18 22:15:25 +00001943 Inst.setOpcode(ARM::CPS1p);
1944 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001945 S = MCDisassembler::SoftFail;
Owen Anderson1dd56f02011-08-18 22:15:25 +00001946 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001947
Owen Anderson14090bf2011-08-18 22:11:02 +00001948 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001949}
1950
Craig Topperc89c7442012-03-27 07:21:54 +00001951static DecodeStatus DecodeT2CPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson6153a032011-08-23 17:45:18 +00001952 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001953 unsigned imod = fieldFromInstruction(Insn, 9, 2);
1954 unsigned M = fieldFromInstruction(Insn, 8, 1);
1955 unsigned iflags = fieldFromInstruction(Insn, 5, 3);
1956 unsigned mode = fieldFromInstruction(Insn, 0, 5);
Owen Anderson6153a032011-08-23 17:45:18 +00001957
Owen Andersona6804442011-09-01 23:23:50 +00001958 DecodeStatus S = MCDisassembler::Success;
Owen Anderson6153a032011-08-23 17:45:18 +00001959
1960 // imod == '01' --> UNPREDICTABLE
1961 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1962 // return failure here. The '01' imod value is unprintable, so there's
1963 // nothing useful we could do even if we returned UNPREDICTABLE.
1964
James Molloyc047dca2011-09-01 18:02:14 +00001965 if (imod == 1) return MCDisassembler::Fail;
Owen Anderson6153a032011-08-23 17:45:18 +00001966
1967 if (imod && M) {
1968 Inst.setOpcode(ARM::t2CPS3p);
1969 Inst.addOperand(MCOperand::CreateImm(imod));
1970 Inst.addOperand(MCOperand::CreateImm(iflags));
1971 Inst.addOperand(MCOperand::CreateImm(mode));
1972 } else if (imod && !M) {
1973 Inst.setOpcode(ARM::t2CPS2p);
1974 Inst.addOperand(MCOperand::CreateImm(imod));
1975 Inst.addOperand(MCOperand::CreateImm(iflags));
James Molloyc047dca2011-09-01 18:02:14 +00001976 if (mode) S = MCDisassembler::SoftFail;
Owen Anderson6153a032011-08-23 17:45:18 +00001977 } else if (!imod && M) {
1978 Inst.setOpcode(ARM::t2CPS1p);
1979 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001980 if (iflags) S = MCDisassembler::SoftFail;
Owen Anderson6153a032011-08-23 17:45:18 +00001981 } else {
Quentin Colombet1ad3a412013-04-26 17:54:54 +00001982 // imod == '00' && M == '0' --> this is a HINT instruction
1983 int imm = fieldFromInstruction(Insn, 0, 8);
1984 // HINT are defined only for immediate in [0..4]
1985 if(imm > 4) return MCDisassembler::Fail;
1986 Inst.setOpcode(ARM::t2HINT);
1987 Inst.addOperand(MCOperand::CreateImm(imm));
Owen Anderson6153a032011-08-23 17:45:18 +00001988 }
1989
1990 return S;
1991}
1992
Craig Topperc89c7442012-03-27 07:21:54 +00001993static DecodeStatus DecodeT2MOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +00001994 uint64_t Address, const void *Decoder) {
1995 DecodeStatus S = MCDisassembler::Success;
1996
Jim Grosbachfc1a1612012-08-14 19:06:05 +00001997 unsigned Rd = fieldFromInstruction(Insn, 8, 4);
Kevin Enderby9e5887b2011-10-04 22:44:48 +00001998 unsigned imm = 0;
1999
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002000 imm |= (fieldFromInstruction(Insn, 0, 8) << 0);
2001 imm |= (fieldFromInstruction(Insn, 12, 3) << 8);
2002 imm |= (fieldFromInstruction(Insn, 16, 4) << 12);
2003 imm |= (fieldFromInstruction(Insn, 26, 1) << 11);
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002004
2005 if (Inst.getOpcode() == ARM::t2MOVTi16)
2006 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
2007 return MCDisassembler::Fail;
2008 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
2009 return MCDisassembler::Fail;
2010
2011 if (!tryAddingSymbolicOperand(Address, imm, false, 4, Inst, Decoder))
2012 Inst.addOperand(MCOperand::CreateImm(imm));
2013
2014 return S;
2015}
2016
Craig Topperc89c7442012-03-27 07:21:54 +00002017static DecodeStatus DecodeArmMOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002018 uint64_t Address, const void *Decoder) {
2019 DecodeStatus S = MCDisassembler::Success;
2020
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002021 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2022 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002023 unsigned imm = 0;
2024
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002025 imm |= (fieldFromInstruction(Insn, 0, 12) << 0);
2026 imm |= (fieldFromInstruction(Insn, 16, 4) << 12);
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002027
2028 if (Inst.getOpcode() == ARM::MOVTi16)
Tim Northover45210192013-04-19 09:58:09 +00002029 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder)))
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002030 return MCDisassembler::Fail;
Tim Northover45210192013-04-19 09:58:09 +00002031
2032 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder)))
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002033 return MCDisassembler::Fail;
2034
2035 if (!tryAddingSymbolicOperand(Address, imm, false, 4, Inst, Decoder))
2036 Inst.addOperand(MCOperand::CreateImm(imm));
2037
2038 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
2039 return MCDisassembler::Fail;
2040
2041 return S;
2042}
Owen Anderson6153a032011-08-23 17:45:18 +00002043
Craig Topperc89c7442012-03-27 07:21:54 +00002044static DecodeStatus DecodeSMLAInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002045 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002046 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002047
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002048 unsigned Rd = fieldFromInstruction(Insn, 16, 4);
2049 unsigned Rn = fieldFromInstruction(Insn, 0, 4);
2050 unsigned Rm = fieldFromInstruction(Insn, 8, 4);
2051 unsigned Ra = fieldFromInstruction(Insn, 12, 4);
2052 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002053
2054 if (pred == 0xF)
2055 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
2056
Owen Andersona6804442011-09-01 23:23:50 +00002057 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder)))
2058 return MCDisassembler::Fail;
2059 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
2060 return MCDisassembler::Fail;
2061 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
2062 return MCDisassembler::Fail;
2063 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder)))
2064 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002065
Owen Andersona6804442011-09-01 23:23:50 +00002066 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
2067 return MCDisassembler::Fail;
Owen Anderson1fb66732011-08-11 22:05:38 +00002068
Owen Anderson83e3f672011-08-17 17:44:15 +00002069 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002070}
2071
Craig Topperc89c7442012-03-27 07:21:54 +00002072static DecodeStatus DecodeAddrModeImm12Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002073 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002074 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002075
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002076 unsigned add = fieldFromInstruction(Val, 12, 1);
2077 unsigned imm = fieldFromInstruction(Val, 0, 12);
2078 unsigned Rn = fieldFromInstruction(Val, 13, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002079
Owen Andersona6804442011-09-01 23:23:50 +00002080 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2081 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002082
2083 if (!add) imm *= -1;
2084 if (imm == 0 && !add) imm = INT32_MIN;
2085 Inst.addOperand(MCOperand::CreateImm(imm));
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002086 if (Rn == 15)
2087 tryAddingPcLoadReferenceComment(Address, Address + imm + 8, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002088
Owen Anderson83e3f672011-08-17 17:44:15 +00002089 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002090}
2091
Craig Topperc89c7442012-03-27 07:21:54 +00002092static DecodeStatus DecodeAddrMode5Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002093 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002094 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002095
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002096 unsigned Rn = fieldFromInstruction(Val, 9, 4);
2097 unsigned U = fieldFromInstruction(Val, 8, 1);
2098 unsigned imm = fieldFromInstruction(Val, 0, 8);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002099
Owen Andersona6804442011-09-01 23:23:50 +00002100 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2101 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002102
2103 if (U)
2104 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
2105 else
2106 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
2107
Owen Anderson83e3f672011-08-17 17:44:15 +00002108 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002109}
2110
Craig Topperc89c7442012-03-27 07:21:54 +00002111static DecodeStatus DecodeAddrMode7Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002112 uint64_t Address, const void *Decoder) {
2113 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
2114}
2115
Owen Andersona6804442011-09-01 23:23:50 +00002116static DecodeStatus
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00002117DecodeT2BInstruction(MCInst &Inst, unsigned Insn,
2118 uint64_t Address, const void *Decoder) {
Kevin Enderby445ba852012-10-29 23:27:20 +00002119 DecodeStatus Status = MCDisassembler::Success;
2120
2121 // Note the J1 and J2 values are from the encoded instruction. So here
2122 // change them to I1 and I2 values via as documented:
2123 // I1 = NOT(J1 EOR S);
2124 // I2 = NOT(J2 EOR S);
2125 // and build the imm32 with one trailing zero as documented:
2126 // imm32 = SignExtend(S:I1:I2:imm10:imm11:'0', 32);
2127 unsigned S = fieldFromInstruction(Insn, 26, 1);
2128 unsigned J1 = fieldFromInstruction(Insn, 13, 1);
2129 unsigned J2 = fieldFromInstruction(Insn, 11, 1);
2130 unsigned I1 = !(J1 ^ S);
2131 unsigned I2 = !(J2 ^ S);
2132 unsigned imm10 = fieldFromInstruction(Insn, 16, 10);
2133 unsigned imm11 = fieldFromInstruction(Insn, 0, 11);
2134 unsigned tmp = (S << 23) | (I1 << 22) | (I2 << 21) | (imm10 << 11) | imm11;
2135 int imm32 = SignExtend32<24>(tmp << 1);
2136 if (!tryAddingSymbolicOperand(Address, Address + imm32 + 4,
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00002137 true, 4, Inst, Decoder))
Kevin Enderby445ba852012-10-29 23:27:20 +00002138 Inst.addOperand(MCOperand::CreateImm(imm32));
2139
2140 return Status;
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00002141}
2142
2143static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00002144DecodeBranchImmInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00002145 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002146 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002147
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002148 unsigned pred = fieldFromInstruction(Insn, 28, 4);
2149 unsigned imm = fieldFromInstruction(Insn, 0, 24) << 2;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002150
2151 if (pred == 0xF) {
2152 Inst.setOpcode(ARM::BLXi);
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002153 imm |= fieldFromInstruction(Insn, 24, 1) << 1;
Kevin Enderbyb80d5712012-02-23 18:18:17 +00002154 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<26>(imm) + 8,
2155 true, 4, Inst, Decoder))
Benjamin Kramer793b8112011-08-09 22:02:50 +00002156 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Anderson83e3f672011-08-17 17:44:15 +00002157 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002158 }
2159
Kevin Enderbyb80d5712012-02-23 18:18:17 +00002160 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<26>(imm) + 8,
2161 true, 4, Inst, Decoder))
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002162 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Andersona6804442011-09-01 23:23:50 +00002163 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
2164 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002165
Owen Anderson83e3f672011-08-17 17:44:15 +00002166 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002167}
2168
2169
Craig Topperc89c7442012-03-27 07:21:54 +00002170static DecodeStatus DecodeAddrMode6Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002171 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002172 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002173
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002174 unsigned Rm = fieldFromInstruction(Val, 0, 4);
2175 unsigned align = fieldFromInstruction(Val, 4, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002176
Owen Andersona6804442011-09-01 23:23:50 +00002177 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2178 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002179 if (!align)
2180 Inst.addOperand(MCOperand::CreateImm(0));
2181 else
2182 Inst.addOperand(MCOperand::CreateImm(4 << align));
2183
Owen Anderson83e3f672011-08-17 17:44:15 +00002184 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002185}
2186
Craig Topperc89c7442012-03-27 07:21:54 +00002187static DecodeStatus DecodeVLDInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002188 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002189 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002190
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002191 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2192 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2193 unsigned wb = fieldFromInstruction(Insn, 16, 4);
2194 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
2195 Rn |= fieldFromInstruction(Insn, 4, 2) << 4;
2196 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002197
2198 // First output register
Jim Grosbach28f08c92012-03-05 19:33:30 +00002199 switch (Inst.getOpcode()) {
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002200 case ARM::VLD1q16: case ARM::VLD1q32: case ARM::VLD1q64: case ARM::VLD1q8:
2201 case ARM::VLD1q16wb_fixed: case ARM::VLD1q16wb_register:
2202 case ARM::VLD1q32wb_fixed: case ARM::VLD1q32wb_register:
2203 case ARM::VLD1q64wb_fixed: case ARM::VLD1q64wb_register:
2204 case ARM::VLD1q8wb_fixed: case ARM::VLD1q8wb_register:
2205 case ARM::VLD2d16: case ARM::VLD2d32: case ARM::VLD2d8:
2206 case ARM::VLD2d16wb_fixed: case ARM::VLD2d16wb_register:
2207 case ARM::VLD2d32wb_fixed: case ARM::VLD2d32wb_register:
2208 case ARM::VLD2d8wb_fixed: case ARM::VLD2d8wb_register:
Jim Grosbach28f08c92012-03-05 19:33:30 +00002209 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2210 return MCDisassembler::Fail;
2211 break;
Jim Grosbachc3384c92012-03-05 21:43:40 +00002212 case ARM::VLD2b16:
2213 case ARM::VLD2b32:
2214 case ARM::VLD2b8:
2215 case ARM::VLD2b16wb_fixed:
2216 case ARM::VLD2b16wb_register:
2217 case ARM::VLD2b32wb_fixed:
2218 case ARM::VLD2b32wb_register:
2219 case ARM::VLD2b8wb_fixed:
2220 case ARM::VLD2b8wb_register:
2221 if (!Check(S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder)))
2222 return MCDisassembler::Fail;
2223 break;
Jim Grosbach28f08c92012-03-05 19:33:30 +00002224 default:
2225 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2226 return MCDisassembler::Fail;
2227 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002228
2229 // Second output register
2230 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002231 case ARM::VLD3d8:
2232 case ARM::VLD3d16:
2233 case ARM::VLD3d32:
2234 case ARM::VLD3d8_UPD:
2235 case ARM::VLD3d16_UPD:
2236 case ARM::VLD3d32_UPD:
2237 case ARM::VLD4d8:
2238 case ARM::VLD4d16:
2239 case ARM::VLD4d32:
2240 case ARM::VLD4d8_UPD:
2241 case ARM::VLD4d16_UPD:
2242 case ARM::VLD4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002243 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)))
2244 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002245 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002246 case ARM::VLD3q8:
2247 case ARM::VLD3q16:
2248 case ARM::VLD3q32:
2249 case ARM::VLD3q8_UPD:
2250 case ARM::VLD3q16_UPD:
2251 case ARM::VLD3q32_UPD:
2252 case ARM::VLD4q8:
2253 case ARM::VLD4q16:
2254 case ARM::VLD4q32:
2255 case ARM::VLD4q8_UPD:
2256 case ARM::VLD4q16_UPD:
2257 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002258 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2259 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002260 default:
2261 break;
2262 }
2263
2264 // Third output register
2265 switch(Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002266 case ARM::VLD3d8:
2267 case ARM::VLD3d16:
2268 case ARM::VLD3d32:
2269 case ARM::VLD3d8_UPD:
2270 case ARM::VLD3d16_UPD:
2271 case ARM::VLD3d32_UPD:
2272 case ARM::VLD4d8:
2273 case ARM::VLD4d16:
2274 case ARM::VLD4d32:
2275 case ARM::VLD4d8_UPD:
2276 case ARM::VLD4d16_UPD:
2277 case ARM::VLD4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002278 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2279 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002280 break;
2281 case ARM::VLD3q8:
2282 case ARM::VLD3q16:
2283 case ARM::VLD3q32:
2284 case ARM::VLD3q8_UPD:
2285 case ARM::VLD3q16_UPD:
2286 case ARM::VLD3q32_UPD:
2287 case ARM::VLD4q8:
2288 case ARM::VLD4q16:
2289 case ARM::VLD4q32:
2290 case ARM::VLD4q8_UPD:
2291 case ARM::VLD4q16_UPD:
2292 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002293 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)))
2294 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002295 break;
2296 default:
2297 break;
2298 }
2299
2300 // Fourth output register
2301 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002302 case ARM::VLD4d8:
2303 case ARM::VLD4d16:
2304 case ARM::VLD4d32:
2305 case ARM::VLD4d8_UPD:
2306 case ARM::VLD4d16_UPD:
2307 case ARM::VLD4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002308 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)))
2309 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002310 break;
2311 case ARM::VLD4q8:
2312 case ARM::VLD4q16:
2313 case ARM::VLD4q32:
2314 case ARM::VLD4q8_UPD:
2315 case ARM::VLD4q16_UPD:
2316 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002317 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)))
2318 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002319 break;
2320 default:
2321 break;
2322 }
2323
2324 // Writeback operand
2325 switch (Inst.getOpcode()) {
Jim Grosbach10b90a92011-10-24 21:45:13 +00002326 case ARM::VLD1d8wb_fixed:
2327 case ARM::VLD1d16wb_fixed:
2328 case ARM::VLD1d32wb_fixed:
2329 case ARM::VLD1d64wb_fixed:
2330 case ARM::VLD1d8wb_register:
2331 case ARM::VLD1d16wb_register:
2332 case ARM::VLD1d32wb_register:
2333 case ARM::VLD1d64wb_register:
2334 case ARM::VLD1q8wb_fixed:
2335 case ARM::VLD1q16wb_fixed:
2336 case ARM::VLD1q32wb_fixed:
2337 case ARM::VLD1q64wb_fixed:
2338 case ARM::VLD1q8wb_register:
2339 case ARM::VLD1q16wb_register:
2340 case ARM::VLD1q32wb_register:
2341 case ARM::VLD1q64wb_register:
Jim Grosbach59216752011-10-24 23:26:05 +00002342 case ARM::VLD1d8Twb_fixed:
2343 case ARM::VLD1d8Twb_register:
2344 case ARM::VLD1d16Twb_fixed:
2345 case ARM::VLD1d16Twb_register:
2346 case ARM::VLD1d32Twb_fixed:
2347 case ARM::VLD1d32Twb_register:
2348 case ARM::VLD1d64Twb_fixed:
2349 case ARM::VLD1d64Twb_register:
Jim Grosbach399cdca2011-10-25 00:14:01 +00002350 case ARM::VLD1d8Qwb_fixed:
2351 case ARM::VLD1d8Qwb_register:
2352 case ARM::VLD1d16Qwb_fixed:
2353 case ARM::VLD1d16Qwb_register:
2354 case ARM::VLD1d32Qwb_fixed:
2355 case ARM::VLD1d32Qwb_register:
2356 case ARM::VLD1d64Qwb_fixed:
2357 case ARM::VLD1d64Qwb_register:
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00002358 case ARM::VLD2d8wb_fixed:
2359 case ARM::VLD2d16wb_fixed:
2360 case ARM::VLD2d32wb_fixed:
2361 case ARM::VLD2q8wb_fixed:
2362 case ARM::VLD2q16wb_fixed:
2363 case ARM::VLD2q32wb_fixed:
2364 case ARM::VLD2d8wb_register:
2365 case ARM::VLD2d16wb_register:
2366 case ARM::VLD2d32wb_register:
2367 case ARM::VLD2q8wb_register:
2368 case ARM::VLD2q16wb_register:
2369 case ARM::VLD2q32wb_register:
2370 case ARM::VLD2b8wb_fixed:
2371 case ARM::VLD2b16wb_fixed:
2372 case ARM::VLD2b32wb_fixed:
2373 case ARM::VLD2b8wb_register:
2374 case ARM::VLD2b16wb_register:
2375 case ARM::VLD2b32wb_register:
Kevin Enderbya69da352012-04-11 00:25:40 +00002376 Inst.addOperand(MCOperand::CreateImm(0));
2377 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002378 case ARM::VLD3d8_UPD:
2379 case ARM::VLD3d16_UPD:
2380 case ARM::VLD3d32_UPD:
2381 case ARM::VLD3q8_UPD:
2382 case ARM::VLD3q16_UPD:
2383 case ARM::VLD3q32_UPD:
2384 case ARM::VLD4d8_UPD:
2385 case ARM::VLD4d16_UPD:
2386 case ARM::VLD4d32_UPD:
2387 case ARM::VLD4q8_UPD:
2388 case ARM::VLD4q16_UPD:
2389 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002390 if (!Check(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder)))
2391 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002392 break;
2393 default:
2394 break;
2395 }
2396
2397 // AddrMode6 Base (register+alignment)
Owen Andersona6804442011-09-01 23:23:50 +00002398 if (!Check(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)))
2399 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002400
2401 // AddrMode6 Offset (register)
Jim Grosbach10b90a92011-10-24 21:45:13 +00002402 switch (Inst.getOpcode()) {
2403 default:
2404 // The below have been updated to have explicit am6offset split
2405 // between fixed and register offset. For those instructions not
2406 // yet updated, we need to add an additional reg0 operand for the
2407 // fixed variant.
2408 //
2409 // The fixed offset encodes as Rm == 0xd, so we check for that.
2410 if (Rm == 0xd) {
2411 Inst.addOperand(MCOperand::CreateReg(0));
2412 break;
2413 }
2414 // Fall through to handle the register offset variant.
2415 case ARM::VLD1d8wb_fixed:
2416 case ARM::VLD1d16wb_fixed:
2417 case ARM::VLD1d32wb_fixed:
2418 case ARM::VLD1d64wb_fixed:
Owen Anderson04b12a42011-10-27 22:53:10 +00002419 case ARM::VLD1d8Twb_fixed:
2420 case ARM::VLD1d16Twb_fixed:
2421 case ARM::VLD1d32Twb_fixed:
2422 case ARM::VLD1d64Twb_fixed:
Owen Andersonfb6ab2b2011-10-31 17:17:32 +00002423 case ARM::VLD1d8Qwb_fixed:
2424 case ARM::VLD1d16Qwb_fixed:
2425 case ARM::VLD1d32Qwb_fixed:
2426 case ARM::VLD1d64Qwb_fixed:
Jim Grosbach10b90a92011-10-24 21:45:13 +00002427 case ARM::VLD1d8wb_register:
2428 case ARM::VLD1d16wb_register:
2429 case ARM::VLD1d32wb_register:
2430 case ARM::VLD1d64wb_register:
2431 case ARM::VLD1q8wb_fixed:
2432 case ARM::VLD1q16wb_fixed:
2433 case ARM::VLD1q32wb_fixed:
2434 case ARM::VLD1q64wb_fixed:
2435 case ARM::VLD1q8wb_register:
2436 case ARM::VLD1q16wb_register:
2437 case ARM::VLD1q32wb_register:
2438 case ARM::VLD1q64wb_register:
2439 // The fixed offset post-increment encodes Rm == 0xd. The no-writeback
2440 // variant encodes Rm == 0xf. Anything else is a register offset post-
2441 // increment and we need to add the register operand to the instruction.
2442 if (Rm != 0xD && Rm != 0xF &&
2443 !Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00002444 return MCDisassembler::Fail;
Jim Grosbach10b90a92011-10-24 21:45:13 +00002445 break;
Kevin Enderbya69da352012-04-11 00:25:40 +00002446 case ARM::VLD2d8wb_fixed:
2447 case ARM::VLD2d16wb_fixed:
2448 case ARM::VLD2d32wb_fixed:
2449 case ARM::VLD2b8wb_fixed:
2450 case ARM::VLD2b16wb_fixed:
2451 case ARM::VLD2b32wb_fixed:
2452 case ARM::VLD2q8wb_fixed:
2453 case ARM::VLD2q16wb_fixed:
2454 case ARM::VLD2q32wb_fixed:
2455 break;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002456 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002457
Owen Anderson83e3f672011-08-17 17:44:15 +00002458 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002459}
2460
Mihai Popa30a7a7c2013-05-20 14:57:05 +00002461static DecodeStatus DecodeVST1Instruction(MCInst& Inst, unsigned Insn,
2462 uint64_t Addr, const void* Decoder) {
2463 unsigned type = fieldFromInstruction(Insn, 8, 4);
2464 unsigned align = fieldFromInstruction(Insn, 4, 2);
2465 if(type == 7 && (align & 2)) return MCDisassembler::Fail;
2466 if(type == 10 && align == 3) return MCDisassembler::Fail;
2467 if(type == 6 && (align & 2)) return MCDisassembler::Fail;
2468
2469 return DecodeVSTInstruction(Inst, Insn, Addr, Decoder);
2470}
2471
2472static DecodeStatus DecodeVST2Instruction(MCInst& Inst, unsigned Insn,
2473 uint64_t Addr, const void* Decoder) {
2474 unsigned size = fieldFromInstruction(Insn, 6, 2);
2475 if(size == 3) return MCDisassembler::Fail;
2476
2477 unsigned type = fieldFromInstruction(Insn, 8, 4);
2478 unsigned align = fieldFromInstruction(Insn, 4, 2);
2479 if(type == 8 && align == 3) return MCDisassembler::Fail;
2480 if(type == 9 && align == 3) return MCDisassembler::Fail;
2481
2482 return DecodeVSTInstruction(Inst, Insn, Addr, Decoder);
2483}
2484
2485static DecodeStatus DecodeVST3Instruction(MCInst& Inst, unsigned Insn,
2486 uint64_t Addr, const void* Decoder) {
2487 unsigned size = fieldFromInstruction(Insn, 6, 2);
2488 if(size == 3) return MCDisassembler::Fail;
2489
2490 unsigned align = fieldFromInstruction(Insn, 4, 2);
2491 if(align & 2) return MCDisassembler::Fail;
2492
2493 return DecodeVSTInstruction(Inst, Insn, Addr, Decoder);
2494}
2495
2496static DecodeStatus DecodeVST4Instruction(MCInst& Inst, unsigned Insn,
2497 uint64_t Addr, const void* Decoder) {
2498 unsigned size = fieldFromInstruction(Insn, 6, 2);
2499 if(size == 3) return MCDisassembler::Fail;
2500
2501 return DecodeVSTInstruction(Inst, Insn, Addr, Decoder);
2502}
2503
Craig Topperc89c7442012-03-27 07:21:54 +00002504static DecodeStatus DecodeVSTInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002505 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002506 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002507
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002508 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2509 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2510 unsigned wb = fieldFromInstruction(Insn, 16, 4);
2511 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
2512 Rn |= fieldFromInstruction(Insn, 4, 2) << 4;
2513 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002514
2515 // Writeback Operand
2516 switch (Inst.getOpcode()) {
Jim Grosbach4334e032011-10-31 21:50:31 +00002517 case ARM::VST1d8wb_fixed:
2518 case ARM::VST1d16wb_fixed:
2519 case ARM::VST1d32wb_fixed:
2520 case ARM::VST1d64wb_fixed:
2521 case ARM::VST1d8wb_register:
2522 case ARM::VST1d16wb_register:
2523 case ARM::VST1d32wb_register:
2524 case ARM::VST1d64wb_register:
2525 case ARM::VST1q8wb_fixed:
2526 case ARM::VST1q16wb_fixed:
2527 case ARM::VST1q32wb_fixed:
2528 case ARM::VST1q64wb_fixed:
2529 case ARM::VST1q8wb_register:
2530 case ARM::VST1q16wb_register:
2531 case ARM::VST1q32wb_register:
2532 case ARM::VST1q64wb_register:
Jim Grosbachd5ca2012011-11-29 22:38:04 +00002533 case ARM::VST1d8Twb_fixed:
2534 case ARM::VST1d16Twb_fixed:
2535 case ARM::VST1d32Twb_fixed:
2536 case ARM::VST1d64Twb_fixed:
2537 case ARM::VST1d8Twb_register:
2538 case ARM::VST1d16Twb_register:
2539 case ARM::VST1d32Twb_register:
2540 case ARM::VST1d64Twb_register:
Jim Grosbach4c7edb32011-11-29 22:58:48 +00002541 case ARM::VST1d8Qwb_fixed:
2542 case ARM::VST1d16Qwb_fixed:
2543 case ARM::VST1d32Qwb_fixed:
2544 case ARM::VST1d64Qwb_fixed:
2545 case ARM::VST1d8Qwb_register:
2546 case ARM::VST1d16Qwb_register:
2547 case ARM::VST1d32Qwb_register:
2548 case ARM::VST1d64Qwb_register:
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00002549 case ARM::VST2d8wb_fixed:
2550 case ARM::VST2d16wb_fixed:
2551 case ARM::VST2d32wb_fixed:
2552 case ARM::VST2d8wb_register:
2553 case ARM::VST2d16wb_register:
2554 case ARM::VST2d32wb_register:
2555 case ARM::VST2q8wb_fixed:
2556 case ARM::VST2q16wb_fixed:
2557 case ARM::VST2q32wb_fixed:
2558 case ARM::VST2q8wb_register:
2559 case ARM::VST2q16wb_register:
2560 case ARM::VST2q32wb_register:
2561 case ARM::VST2b8wb_fixed:
2562 case ARM::VST2b16wb_fixed:
2563 case ARM::VST2b32wb_fixed:
2564 case ARM::VST2b8wb_register:
2565 case ARM::VST2b16wb_register:
2566 case ARM::VST2b32wb_register:
Kevin Enderbyb318cc12012-04-11 22:40:17 +00002567 if (Rm == 0xF)
2568 return MCDisassembler::Fail;
Kevin Enderbyf0586f02012-03-21 20:54:32 +00002569 Inst.addOperand(MCOperand::CreateImm(0));
2570 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002571 case ARM::VST3d8_UPD:
2572 case ARM::VST3d16_UPD:
2573 case ARM::VST3d32_UPD:
2574 case ARM::VST3q8_UPD:
2575 case ARM::VST3q16_UPD:
2576 case ARM::VST3q32_UPD:
2577 case ARM::VST4d8_UPD:
2578 case ARM::VST4d16_UPD:
2579 case ARM::VST4d32_UPD:
2580 case ARM::VST4q8_UPD:
2581 case ARM::VST4q16_UPD:
2582 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002583 if (!Check(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder)))
2584 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002585 break;
2586 default:
2587 break;
2588 }
2589
2590 // AddrMode6 Base (register+alignment)
Owen Andersona6804442011-09-01 23:23:50 +00002591 if (!Check(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)))
2592 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002593
2594 // AddrMode6 Offset (register)
Owen Anderson60cb6432011-11-01 22:18:13 +00002595 switch (Inst.getOpcode()) {
2596 default:
2597 if (Rm == 0xD)
2598 Inst.addOperand(MCOperand::CreateReg(0));
2599 else if (Rm != 0xF) {
2600 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2601 return MCDisassembler::Fail;
2602 }
2603 break;
2604 case ARM::VST1d8wb_fixed:
2605 case ARM::VST1d16wb_fixed:
2606 case ARM::VST1d32wb_fixed:
2607 case ARM::VST1d64wb_fixed:
2608 case ARM::VST1q8wb_fixed:
2609 case ARM::VST1q16wb_fixed:
2610 case ARM::VST1q32wb_fixed:
2611 case ARM::VST1q64wb_fixed:
Kevin Enderbyf0586f02012-03-21 20:54:32 +00002612 case ARM::VST1d8Twb_fixed:
2613 case ARM::VST1d16Twb_fixed:
2614 case ARM::VST1d32Twb_fixed:
2615 case ARM::VST1d64Twb_fixed:
2616 case ARM::VST1d8Qwb_fixed:
2617 case ARM::VST1d16Qwb_fixed:
2618 case ARM::VST1d32Qwb_fixed:
2619 case ARM::VST1d64Qwb_fixed:
2620 case ARM::VST2d8wb_fixed:
2621 case ARM::VST2d16wb_fixed:
2622 case ARM::VST2d32wb_fixed:
2623 case ARM::VST2q8wb_fixed:
2624 case ARM::VST2q16wb_fixed:
2625 case ARM::VST2q32wb_fixed:
2626 case ARM::VST2b8wb_fixed:
2627 case ARM::VST2b16wb_fixed:
2628 case ARM::VST2b32wb_fixed:
Owen Anderson60cb6432011-11-01 22:18:13 +00002629 break;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002630 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002631
Owen Anderson60cb6432011-11-01 22:18:13 +00002632
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002633 // First input register
Jim Grosbach28f08c92012-03-05 19:33:30 +00002634 switch (Inst.getOpcode()) {
2635 case ARM::VST1q16:
2636 case ARM::VST1q32:
2637 case ARM::VST1q64:
2638 case ARM::VST1q8:
2639 case ARM::VST1q16wb_fixed:
2640 case ARM::VST1q16wb_register:
2641 case ARM::VST1q32wb_fixed:
2642 case ARM::VST1q32wb_register:
2643 case ARM::VST1q64wb_fixed:
2644 case ARM::VST1q64wb_register:
2645 case ARM::VST1q8wb_fixed:
2646 case ARM::VST1q8wb_register:
2647 case ARM::VST2d16:
2648 case ARM::VST2d32:
2649 case ARM::VST2d8:
2650 case ARM::VST2d16wb_fixed:
2651 case ARM::VST2d16wb_register:
2652 case ARM::VST2d32wb_fixed:
2653 case ARM::VST2d32wb_register:
2654 case ARM::VST2d8wb_fixed:
2655 case ARM::VST2d8wb_register:
2656 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2657 return MCDisassembler::Fail;
2658 break;
Jim Grosbachc3384c92012-03-05 21:43:40 +00002659 case ARM::VST2b16:
2660 case ARM::VST2b32:
2661 case ARM::VST2b8:
2662 case ARM::VST2b16wb_fixed:
2663 case ARM::VST2b16wb_register:
2664 case ARM::VST2b32wb_fixed:
2665 case ARM::VST2b32wb_register:
2666 case ARM::VST2b8wb_fixed:
2667 case ARM::VST2b8wb_register:
2668 if (!Check(S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder)))
2669 return MCDisassembler::Fail;
2670 break;
Jim Grosbach28f08c92012-03-05 19:33:30 +00002671 default:
2672 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2673 return MCDisassembler::Fail;
2674 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002675
2676 // Second input register
2677 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002678 case ARM::VST3d8:
2679 case ARM::VST3d16:
2680 case ARM::VST3d32:
2681 case ARM::VST3d8_UPD:
2682 case ARM::VST3d16_UPD:
2683 case ARM::VST3d32_UPD:
2684 case ARM::VST4d8:
2685 case ARM::VST4d16:
2686 case ARM::VST4d32:
2687 case ARM::VST4d8_UPD:
2688 case ARM::VST4d16_UPD:
2689 case ARM::VST4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002690 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)))
2691 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002692 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002693 case ARM::VST3q8:
2694 case ARM::VST3q16:
2695 case ARM::VST3q32:
2696 case ARM::VST3q8_UPD:
2697 case ARM::VST3q16_UPD:
2698 case ARM::VST3q32_UPD:
2699 case ARM::VST4q8:
2700 case ARM::VST4q16:
2701 case ARM::VST4q32:
2702 case ARM::VST4q8_UPD:
2703 case ARM::VST4q16_UPD:
2704 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002705 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2706 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002707 break;
2708 default:
2709 break;
2710 }
2711
2712 // Third input register
2713 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002714 case ARM::VST3d8:
2715 case ARM::VST3d16:
2716 case ARM::VST3d32:
2717 case ARM::VST3d8_UPD:
2718 case ARM::VST3d16_UPD:
2719 case ARM::VST3d32_UPD:
2720 case ARM::VST4d8:
2721 case ARM::VST4d16:
2722 case ARM::VST4d32:
2723 case ARM::VST4d8_UPD:
2724 case ARM::VST4d16_UPD:
2725 case ARM::VST4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002726 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2727 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002728 break;
2729 case ARM::VST3q8:
2730 case ARM::VST3q16:
2731 case ARM::VST3q32:
2732 case ARM::VST3q8_UPD:
2733 case ARM::VST3q16_UPD:
2734 case ARM::VST3q32_UPD:
2735 case ARM::VST4q8:
2736 case ARM::VST4q16:
2737 case ARM::VST4q32:
2738 case ARM::VST4q8_UPD:
2739 case ARM::VST4q16_UPD:
2740 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002741 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)))
2742 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002743 break;
2744 default:
2745 break;
2746 }
2747
2748 // Fourth input register
2749 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002750 case ARM::VST4d8:
2751 case ARM::VST4d16:
2752 case ARM::VST4d32:
2753 case ARM::VST4d8_UPD:
2754 case ARM::VST4d16_UPD:
2755 case ARM::VST4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002756 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)))
2757 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002758 break;
2759 case ARM::VST4q8:
2760 case ARM::VST4q16:
2761 case ARM::VST4q32:
2762 case ARM::VST4q8_UPD:
2763 case ARM::VST4q16_UPD:
2764 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002765 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)))
2766 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002767 break;
2768 default:
2769 break;
2770 }
2771
Owen Anderson83e3f672011-08-17 17:44:15 +00002772 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002773}
2774
Craig Topperc89c7442012-03-27 07:21:54 +00002775static DecodeStatus DecodeVLD1DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002776 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002777 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002778
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002779 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2780 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2781 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
2782 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
2783 unsigned align = fieldFromInstruction(Insn, 4, 1);
2784 unsigned size = fieldFromInstruction(Insn, 6, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002785
Tim Northover24b9f252012-09-06 15:27:12 +00002786 if (size == 0 && align == 1)
2787 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002788 align *= (1 << size);
2789
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002790 switch (Inst.getOpcode()) {
2791 case ARM::VLD1DUPq16: case ARM::VLD1DUPq32: case ARM::VLD1DUPq8:
2792 case ARM::VLD1DUPq16wb_fixed: case ARM::VLD1DUPq16wb_register:
2793 case ARM::VLD1DUPq32wb_fixed: case ARM::VLD1DUPq32wb_register:
2794 case ARM::VLD1DUPq8wb_fixed: case ARM::VLD1DUPq8wb_register:
2795 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2796 return MCDisassembler::Fail;
2797 break;
2798 default:
2799 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2800 return MCDisassembler::Fail;
2801 break;
2802 }
Owen Andersonf1c8e3e2011-08-22 18:22:06 +00002803 if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002804 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2805 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002806 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002807
Owen Andersona6804442011-09-01 23:23:50 +00002808 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2809 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002810 Inst.addOperand(MCOperand::CreateImm(align));
2811
Jim Grosbach096334e2011-11-30 19:35:44 +00002812 // The fixed offset post-increment encodes Rm == 0xd. The no-writeback
2813 // variant encodes Rm == 0xf. Anything else is a register offset post-
2814 // increment and we need to add the register operand to the instruction.
2815 if (Rm != 0xD && Rm != 0xF &&
2816 !Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2817 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002818
Owen Anderson83e3f672011-08-17 17:44:15 +00002819 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002820}
2821
Craig Topperc89c7442012-03-27 07:21:54 +00002822static DecodeStatus DecodeVLD2DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002823 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002824 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002825
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002826 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2827 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2828 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
2829 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
2830 unsigned align = fieldFromInstruction(Insn, 4, 1);
2831 unsigned size = 1 << fieldFromInstruction(Insn, 6, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002832 align *= 2*size;
2833
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002834 switch (Inst.getOpcode()) {
2835 case ARM::VLD2DUPd16: case ARM::VLD2DUPd32: case ARM::VLD2DUPd8:
2836 case ARM::VLD2DUPd16wb_fixed: case ARM::VLD2DUPd16wb_register:
2837 case ARM::VLD2DUPd32wb_fixed: case ARM::VLD2DUPd32wb_register:
2838 case ARM::VLD2DUPd8wb_fixed: case ARM::VLD2DUPd8wb_register:
2839 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2840 return MCDisassembler::Fail;
2841 break;
Jim Grosbach4d0983a2012-03-06 23:10:38 +00002842 case ARM::VLD2DUPd16x2: case ARM::VLD2DUPd32x2: case ARM::VLD2DUPd8x2:
2843 case ARM::VLD2DUPd16x2wb_fixed: case ARM::VLD2DUPd16x2wb_register:
2844 case ARM::VLD2DUPd32x2wb_fixed: case ARM::VLD2DUPd32x2wb_register:
2845 case ARM::VLD2DUPd8x2wb_fixed: case ARM::VLD2DUPd8x2wb_register:
2846 if (!Check(S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder)))
2847 return MCDisassembler::Fail;
2848 break;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002849 default:
2850 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2851 return MCDisassembler::Fail;
2852 break;
2853 }
Kevin Enderby158c8a42012-03-06 18:33:12 +00002854
2855 if (Rm != 0xF)
2856 Inst.addOperand(MCOperand::CreateImm(0));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002857
Owen Andersona6804442011-09-01 23:23:50 +00002858 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2859 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002860 Inst.addOperand(MCOperand::CreateImm(align));
2861
Kevin Enderbyc5a2a332012-04-17 00:49:27 +00002862 if (Rm != 0xD && Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002863 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2864 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002865 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002866
Owen Anderson83e3f672011-08-17 17:44:15 +00002867 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002868}
2869
Craig Topperc89c7442012-03-27 07:21:54 +00002870static DecodeStatus DecodeVLD3DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002871 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002872 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002873
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002874 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2875 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2876 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
2877 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
2878 unsigned inc = fieldFromInstruction(Insn, 5, 1) + 1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002879
Owen Andersona6804442011-09-01 23:23:50 +00002880 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2881 return MCDisassembler::Fail;
2882 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)))
2883 return MCDisassembler::Fail;
2884 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder)))
2885 return MCDisassembler::Fail;
Owen Andersonf1c8e3e2011-08-22 18:22:06 +00002886 if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002887 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2888 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002889 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002890
Owen Andersona6804442011-09-01 23:23:50 +00002891 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2892 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002893 Inst.addOperand(MCOperand::CreateImm(0));
2894
2895 if (Rm == 0xD)
2896 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002897 else if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002898 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2899 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002900 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002901
Owen Anderson83e3f672011-08-17 17:44:15 +00002902 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002903}
2904
Craig Topperc89c7442012-03-27 07:21:54 +00002905static DecodeStatus DecodeVLD4DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002906 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002907 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002908
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002909 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2910 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2911 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
2912 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
2913 unsigned size = fieldFromInstruction(Insn, 6, 2);
2914 unsigned inc = fieldFromInstruction(Insn, 5, 1) + 1;
2915 unsigned align = fieldFromInstruction(Insn, 4, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002916
2917 if (size == 0x3) {
Tim Northover24b9f252012-09-06 15:27:12 +00002918 if (align == 0)
2919 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002920 size = 4;
2921 align = 16;
2922 } else {
2923 if (size == 2) {
2924 size = 1 << size;
2925 align *= 8;
2926 } else {
2927 size = 1 << size;
2928 align *= 4*size;
2929 }
2930 }
2931
Owen Andersona6804442011-09-01 23:23:50 +00002932 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2933 return MCDisassembler::Fail;
2934 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)))
2935 return MCDisassembler::Fail;
2936 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder)))
2937 return MCDisassembler::Fail;
2938 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder)))
2939 return MCDisassembler::Fail;
Owen Andersonf1c8e3e2011-08-22 18:22:06 +00002940 if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002941 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2942 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002943 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002944
Owen Andersona6804442011-09-01 23:23:50 +00002945 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2946 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002947 Inst.addOperand(MCOperand::CreateImm(align));
2948
2949 if (Rm == 0xD)
2950 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002951 else if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002952 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2953 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002954 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002955
Owen Anderson83e3f672011-08-17 17:44:15 +00002956 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002957}
2958
Owen Andersona6804442011-09-01 23:23:50 +00002959static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00002960DecodeNEONModImmInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00002961 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002962 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002963
Jim Grosbachfc1a1612012-08-14 19:06:05 +00002964 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
2965 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
2966 unsigned imm = fieldFromInstruction(Insn, 0, 4);
2967 imm |= fieldFromInstruction(Insn, 16, 3) << 4;
2968 imm |= fieldFromInstruction(Insn, 24, 1) << 7;
2969 imm |= fieldFromInstruction(Insn, 8, 4) << 8;
2970 imm |= fieldFromInstruction(Insn, 5, 1) << 12;
2971 unsigned Q = fieldFromInstruction(Insn, 6, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002972
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002973 if (Q) {
Owen Andersona6804442011-09-01 23:23:50 +00002974 if (!Check(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)))
2975 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002976 } else {
Owen Andersona6804442011-09-01 23:23:50 +00002977 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2978 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002979 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002980
2981 Inst.addOperand(MCOperand::CreateImm(imm));
2982
2983 switch (Inst.getOpcode()) {
2984 case ARM::VORRiv4i16:
2985 case ARM::VORRiv2i32:
2986 case ARM::VBICiv4i16:
2987 case ARM::VBICiv2i32:
Owen Andersona6804442011-09-01 23:23:50 +00002988 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2989 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002990 break;
2991 case ARM::VORRiv8i16:
2992 case ARM::VORRiv4i32:
2993 case ARM::VBICiv8i16:
2994 case ARM::VBICiv4i32:
Owen Andersona6804442011-09-01 23:23:50 +00002995 if (!Check(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)))
2996 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002997 break;
2998 default:
2999 break;
3000 }
3001
Owen Anderson83e3f672011-08-17 17:44:15 +00003002 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003003}
3004
Craig Topperc89c7442012-03-27 07:21:54 +00003005static DecodeStatus DecodeVSHLMaxInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003006 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003007 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003008
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003009 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3010 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
3011 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3012 Rm |= fieldFromInstruction(Insn, 5, 1) << 4;
3013 unsigned size = fieldFromInstruction(Insn, 18, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003014
Owen Andersona6804442011-09-01 23:23:50 +00003015 if (!Check(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)))
3016 return MCDisassembler::Fail;
3017 if (!Check(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)))
3018 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003019 Inst.addOperand(MCOperand::CreateImm(8 << size));
3020
Owen Anderson83e3f672011-08-17 17:44:15 +00003021 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003022}
3023
Craig Topperc89c7442012-03-27 07:21:54 +00003024static DecodeStatus DecodeShiftRight8Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003025 uint64_t Address, const void *Decoder) {
3026 Inst.addOperand(MCOperand::CreateImm(8 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00003027 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003028}
3029
Craig Topperc89c7442012-03-27 07:21:54 +00003030static DecodeStatus DecodeShiftRight16Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003031 uint64_t Address, const void *Decoder) {
3032 Inst.addOperand(MCOperand::CreateImm(16 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00003033 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003034}
3035
Craig Topperc89c7442012-03-27 07:21:54 +00003036static DecodeStatus DecodeShiftRight32Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003037 uint64_t Address, const void *Decoder) {
3038 Inst.addOperand(MCOperand::CreateImm(32 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00003039 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003040}
3041
Craig Topperc89c7442012-03-27 07:21:54 +00003042static DecodeStatus DecodeShiftRight64Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003043 uint64_t Address, const void *Decoder) {
3044 Inst.addOperand(MCOperand::CreateImm(64 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00003045 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003046}
3047
Craig Topperc89c7442012-03-27 07:21:54 +00003048static DecodeStatus DecodeTBLInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003049 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003050 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003051
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003052 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3053 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
3054 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3055 Rn |= fieldFromInstruction(Insn, 7, 1) << 4;
3056 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3057 Rm |= fieldFromInstruction(Insn, 5, 1) << 4;
3058 unsigned op = fieldFromInstruction(Insn, 6, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003059
Owen Andersona6804442011-09-01 23:23:50 +00003060 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3061 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00003062 if (op) {
Owen Andersona6804442011-09-01 23:23:50 +00003063 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3064 return MCDisassembler::Fail; // Writeback
Owen Andersonae0bc5d2011-08-11 18:24:51 +00003065 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003066
Jim Grosbach28f08c92012-03-05 19:33:30 +00003067 switch (Inst.getOpcode()) {
3068 case ARM::VTBL2:
3069 case ARM::VTBX2:
3070 if (!Check(S, DecodeDPairRegisterClass(Inst, Rn, Address, Decoder)))
3071 return MCDisassembler::Fail;
3072 break;
3073 default:
3074 if (!Check(S, DecodeDPRRegisterClass(Inst, Rn, Address, Decoder)))
3075 return MCDisassembler::Fail;
3076 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003077
Owen Andersona6804442011-09-01 23:23:50 +00003078 if (!Check(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)))
3079 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003080
Owen Anderson83e3f672011-08-17 17:44:15 +00003081 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003082}
3083
Craig Topperc89c7442012-03-27 07:21:54 +00003084static DecodeStatus DecodeThumbAddSpecialReg(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003085 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003086 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003087
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003088 unsigned dst = fieldFromInstruction(Insn, 8, 3);
3089 unsigned imm = fieldFromInstruction(Insn, 0, 8);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003090
Owen Andersona6804442011-09-01 23:23:50 +00003091 if (!Check(S, DecodetGPRRegisterClass(Inst, dst, Address, Decoder)))
3092 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003093
Owen Anderson96425c82011-08-26 18:09:22 +00003094 switch(Inst.getOpcode()) {
Owen Anderson1af7f722011-08-26 19:39:26 +00003095 default:
James Molloyc047dca2011-09-01 18:02:14 +00003096 return MCDisassembler::Fail;
Owen Anderson96425c82011-08-26 18:09:22 +00003097 case ARM::tADR:
Owen Anderson9f7e8312011-08-26 21:47:57 +00003098 break; // tADR does not explicitly represent the PC as an operand.
Owen Anderson96425c82011-08-26 18:09:22 +00003099 case ARM::tADDrSPi:
3100 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3101 break;
Owen Anderson96425c82011-08-26 18:09:22 +00003102 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003103
3104 Inst.addOperand(MCOperand::CreateImm(imm));
Owen Anderson83e3f672011-08-17 17:44:15 +00003105 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003106}
3107
Craig Topperc89c7442012-03-27 07:21:54 +00003108static DecodeStatus DecodeThumbBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003109 uint64_t Address, const void *Decoder) {
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003110 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<12>(Val<<1) + 4,
3111 true, 2, Inst, Decoder))
3112 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003113 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003114}
3115
Craig Topperc89c7442012-03-27 07:21:54 +00003116static DecodeStatus DecodeT2BROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003117 uint64_t Address, const void *Decoder) {
Kevin Enderby3610a152012-05-04 22:09:52 +00003118 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<21>(Val) + 4,
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003119 true, 4, Inst, Decoder))
3120 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
James Molloyc047dca2011-09-01 18:02:14 +00003121 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003122}
3123
Craig Topperc89c7442012-03-27 07:21:54 +00003124static DecodeStatus DecodeThumbCmpBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003125 uint64_t Address, const void *Decoder) {
Gordon Keiserce888352013-03-28 19:22:28 +00003126 if (!tryAddingSymbolicOperand(Address, Address + (Val<<1) + 4,
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003127 true, 2, Inst, Decoder))
Gordon Keiserce888352013-03-28 19:22:28 +00003128 Inst.addOperand(MCOperand::CreateImm(Val << 1));
James Molloyc047dca2011-09-01 18:02:14 +00003129 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003130}
3131
Craig Topperc89c7442012-03-27 07:21:54 +00003132static DecodeStatus DecodeThumbAddrModeRR(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003133 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003134 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003135
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003136 unsigned Rn = fieldFromInstruction(Val, 0, 3);
3137 unsigned Rm = fieldFromInstruction(Val, 3, 3);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003138
Owen Andersona6804442011-09-01 23:23:50 +00003139 if (!Check(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)))
3140 return MCDisassembler::Fail;
3141 if (!Check(S, DecodetGPRRegisterClass(Inst, Rm, Address, Decoder)))
3142 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003143
Owen Anderson83e3f672011-08-17 17:44:15 +00003144 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003145}
3146
Craig Topperc89c7442012-03-27 07:21:54 +00003147static DecodeStatus DecodeThumbAddrModeIS(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003148 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003149 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003150
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003151 unsigned Rn = fieldFromInstruction(Val, 0, 3);
3152 unsigned imm = fieldFromInstruction(Val, 3, 5);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003153
Owen Andersona6804442011-09-01 23:23:50 +00003154 if (!Check(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)))
3155 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003156 Inst.addOperand(MCOperand::CreateImm(imm));
3157
Owen Anderson83e3f672011-08-17 17:44:15 +00003158 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003159}
3160
Craig Topperc89c7442012-03-27 07:21:54 +00003161static DecodeStatus DecodeThumbAddrModePC(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003162 uint64_t Address, const void *Decoder) {
Kevin Enderby9e5887b2011-10-04 22:44:48 +00003163 unsigned imm = Val << 2;
3164
3165 Inst.addOperand(MCOperand::CreateImm(imm));
3166 tryAddingPcLoadReferenceComment(Address, (Address & ~2u) + imm + 4, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003167
James Molloyc047dca2011-09-01 18:02:14 +00003168 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003169}
3170
Craig Topperc89c7442012-03-27 07:21:54 +00003171static DecodeStatus DecodeThumbAddrModeSP(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003172 uint64_t Address, const void *Decoder) {
3173 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersonb113ec52011-08-22 17:56:58 +00003174 Inst.addOperand(MCOperand::CreateImm(Val));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003175
James Molloyc047dca2011-09-01 18:02:14 +00003176 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003177}
3178
Craig Topperc89c7442012-03-27 07:21:54 +00003179static DecodeStatus DecodeT2AddrModeSOReg(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003180 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003181 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003182
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003183 unsigned Rn = fieldFromInstruction(Val, 6, 4);
3184 unsigned Rm = fieldFromInstruction(Val, 2, 4);
3185 unsigned imm = fieldFromInstruction(Val, 0, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003186
Owen Andersona6804442011-09-01 23:23:50 +00003187 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3188 return MCDisassembler::Fail;
3189 if (!Check(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder)))
3190 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003191 Inst.addOperand(MCOperand::CreateImm(imm));
3192
Owen Anderson83e3f672011-08-17 17:44:15 +00003193 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003194}
3195
Craig Topperc89c7442012-03-27 07:21:54 +00003196static DecodeStatus DecodeT2LoadShift(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003197 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003198 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003199
Owen Anderson82265a22011-08-23 17:51:38 +00003200 switch (Inst.getOpcode()) {
3201 case ARM::t2PLDs:
3202 case ARM::t2PLDWs:
3203 case ARM::t2PLIs:
3204 break;
3205 default: {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003206 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
Owen Anderson31d485e2011-09-23 21:07:25 +00003207 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00003208 return MCDisassembler::Fail;
Owen Anderson82265a22011-08-23 17:51:38 +00003209 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003210 }
3211
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003212 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003213 if (Rn == 0xF) {
3214 switch (Inst.getOpcode()) {
3215 case ARM::t2LDRBs:
3216 Inst.setOpcode(ARM::t2LDRBpci);
3217 break;
3218 case ARM::t2LDRHs:
3219 Inst.setOpcode(ARM::t2LDRHpci);
3220 break;
3221 case ARM::t2LDRSHs:
3222 Inst.setOpcode(ARM::t2LDRSHpci);
3223 break;
3224 case ARM::t2LDRSBs:
3225 Inst.setOpcode(ARM::t2LDRSBpci);
3226 break;
3227 case ARM::t2PLDs:
3228 Inst.setOpcode(ARM::t2PLDi12);
3229 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
3230 break;
3231 default:
James Molloyc047dca2011-09-01 18:02:14 +00003232 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003233 }
3234
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003235 int imm = fieldFromInstruction(Insn, 0, 12);
3236 if (!fieldFromInstruction(Insn, 23, 1)) imm *= -1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003237 Inst.addOperand(MCOperand::CreateImm(imm));
3238
Owen Anderson83e3f672011-08-17 17:44:15 +00003239 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003240 }
3241
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003242 unsigned addrmode = fieldFromInstruction(Insn, 4, 2);
3243 addrmode |= fieldFromInstruction(Insn, 0, 4) << 2;
3244 addrmode |= fieldFromInstruction(Insn, 16, 4) << 6;
Owen Andersona6804442011-09-01 23:23:50 +00003245 if (!Check(S, DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder)))
3246 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003247
Owen Anderson83e3f672011-08-17 17:44:15 +00003248 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003249}
3250
Craig Topperc89c7442012-03-27 07:21:54 +00003251static DecodeStatus DecodeT2Imm8S4(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003252 uint64_t Address, const void *Decoder) {
Jiangning Liufd652df2012-08-02 08:29:50 +00003253 if (Val == 0)
3254 Inst.addOperand(MCOperand::CreateImm(INT32_MIN));
3255 else {
3256 int imm = Val & 0xFF;
3257
3258 if (!(Val & 0x100)) imm *= -1;
Richard Smith1144af32012-08-24 23:29:28 +00003259 Inst.addOperand(MCOperand::CreateImm(imm * 4));
Jiangning Liufd652df2012-08-02 08:29:50 +00003260 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003261
James Molloyc047dca2011-09-01 18:02:14 +00003262 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003263}
3264
Craig Topperc89c7442012-03-27 07:21:54 +00003265static DecodeStatus DecodeT2AddrModeImm8s4(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003266 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003267 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003268
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003269 unsigned Rn = fieldFromInstruction(Val, 9, 4);
3270 unsigned imm = fieldFromInstruction(Val, 0, 9);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003271
Owen Andersona6804442011-09-01 23:23:50 +00003272 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3273 return MCDisassembler::Fail;
3274 if (!Check(S, DecodeT2Imm8S4(Inst, imm, Address, Decoder)))
3275 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003276
Owen Anderson83e3f672011-08-17 17:44:15 +00003277 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003278}
3279
Craig Topperc89c7442012-03-27 07:21:54 +00003280static DecodeStatus DecodeT2AddrModeImm0_1020s4(MCInst &Inst,unsigned Val,
Jim Grosbachb6aed502011-09-09 18:37:27 +00003281 uint64_t Address, const void *Decoder) {
3282 DecodeStatus S = MCDisassembler::Success;
3283
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003284 unsigned Rn = fieldFromInstruction(Val, 8, 4);
3285 unsigned imm = fieldFromInstruction(Val, 0, 8);
Jim Grosbachb6aed502011-09-09 18:37:27 +00003286
3287 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
3288 return MCDisassembler::Fail;
3289
3290 Inst.addOperand(MCOperand::CreateImm(imm));
3291
3292 return S;
3293}
3294
Craig Topperc89c7442012-03-27 07:21:54 +00003295static DecodeStatus DecodeT2Imm8(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003296 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003297 int imm = Val & 0xFF;
Owen Anderson705b48f2011-09-16 21:08:33 +00003298 if (Val == 0)
3299 imm = INT32_MIN;
3300 else if (!(Val & 0x100))
3301 imm *= -1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003302 Inst.addOperand(MCOperand::CreateImm(imm));
3303
James Molloyc047dca2011-09-01 18:02:14 +00003304 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003305}
3306
3307
Craig Topperc89c7442012-03-27 07:21:54 +00003308static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003309 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003310 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003311
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003312 unsigned Rn = fieldFromInstruction(Val, 9, 4);
3313 unsigned imm = fieldFromInstruction(Val, 0, 9);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003314
3315 // Some instructions always use an additive offset.
3316 switch (Inst.getOpcode()) {
3317 case ARM::t2LDRT:
3318 case ARM::t2LDRBT:
3319 case ARM::t2LDRHT:
3320 case ARM::t2LDRSBT:
3321 case ARM::t2LDRSHT:
Owen Andersonecd1c552011-09-19 18:07:10 +00003322 case ARM::t2STRT:
3323 case ARM::t2STRBT:
3324 case ARM::t2STRHT:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003325 imm |= 0x100;
3326 break;
3327 default:
3328 break;
3329 }
3330
Owen Andersona6804442011-09-01 23:23:50 +00003331 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3332 return MCDisassembler::Fail;
3333 if (!Check(S, DecodeT2Imm8(Inst, imm, Address, Decoder)))
3334 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003335
Owen Anderson83e3f672011-08-17 17:44:15 +00003336 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003337}
3338
Craig Topperc89c7442012-03-27 07:21:54 +00003339static DecodeStatus DecodeT2LdStPre(MCInst &Inst, unsigned Insn,
Owen Andersona3157b42011-09-12 18:56:30 +00003340 uint64_t Address, const void *Decoder) {
3341 DecodeStatus S = MCDisassembler::Success;
3342
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003343 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
3344 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3345 unsigned addr = fieldFromInstruction(Insn, 0, 8);
3346 addr |= fieldFromInstruction(Insn, 9, 1) << 8;
Owen Andersona3157b42011-09-12 18:56:30 +00003347 addr |= Rn << 9;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003348 unsigned load = fieldFromInstruction(Insn, 20, 1);
Owen Andersona3157b42011-09-12 18:56:30 +00003349
3350 if (!load) {
3351 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3352 return MCDisassembler::Fail;
3353 }
3354
Joe Abbeyb78821d2013-03-26 13:58:53 +00003355 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
Owen Andersona3157b42011-09-12 18:56:30 +00003356 return MCDisassembler::Fail;
3357
3358 if (load) {
3359 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3360 return MCDisassembler::Fail;
3361 }
3362
3363 if (!Check(S, DecodeT2AddrModeImm8(Inst, addr, Address, Decoder)))
3364 return MCDisassembler::Fail;
3365
3366 return S;
3367}
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003368
Craig Topperc89c7442012-03-27 07:21:54 +00003369static DecodeStatus DecodeT2AddrModeImm12(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003370 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003371 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003372
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003373 unsigned Rn = fieldFromInstruction(Val, 13, 4);
3374 unsigned imm = fieldFromInstruction(Val, 0, 12);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003375
Owen Andersona6804442011-09-01 23:23:50 +00003376 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3377 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003378 Inst.addOperand(MCOperand::CreateImm(imm));
3379
Owen Anderson83e3f672011-08-17 17:44:15 +00003380 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003381}
3382
3383
Craig Topperc89c7442012-03-27 07:21:54 +00003384static DecodeStatus DecodeThumbAddSPImm(MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003385 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003386 unsigned imm = fieldFromInstruction(Insn, 0, 7);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003387
3388 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3389 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3390 Inst.addOperand(MCOperand::CreateImm(imm));
3391
James Molloyc047dca2011-09-01 18:02:14 +00003392 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003393}
3394
Craig Topperc89c7442012-03-27 07:21:54 +00003395static DecodeStatus DecodeThumbAddSPReg(MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003396 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003397 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003398
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003399 if (Inst.getOpcode() == ARM::tADDrSP) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003400 unsigned Rdm = fieldFromInstruction(Insn, 0, 3);
3401 Rdm |= fieldFromInstruction(Insn, 7, 1) << 3;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003402
Owen Andersona6804442011-09-01 23:23:50 +00003403 if (!Check(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)))
3404 return MCDisassembler::Fail;
Jim Grosbachbb32f1d2012-04-27 23:51:33 +00003405 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersona6804442011-09-01 23:23:50 +00003406 if (!Check(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)))
3407 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003408 } else if (Inst.getOpcode() == ARM::tADDspr) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003409 unsigned Rm = fieldFromInstruction(Insn, 3, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003410
3411 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3412 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersona6804442011-09-01 23:23:50 +00003413 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3414 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003415 }
3416
Owen Anderson83e3f672011-08-17 17:44:15 +00003417 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003418}
3419
Craig Topperc89c7442012-03-27 07:21:54 +00003420static DecodeStatus DecodeThumbCPS(MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003421 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003422 unsigned imod = fieldFromInstruction(Insn, 4, 1) | 0x2;
3423 unsigned flags = fieldFromInstruction(Insn, 0, 3);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003424
3425 Inst.addOperand(MCOperand::CreateImm(imod));
3426 Inst.addOperand(MCOperand::CreateImm(flags));
3427
James Molloyc047dca2011-09-01 18:02:14 +00003428 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003429}
3430
Craig Topperc89c7442012-03-27 07:21:54 +00003431static DecodeStatus DecodePostIdxReg(MCInst &Inst, unsigned Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003432 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003433 DecodeStatus S = MCDisassembler::Success;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003434 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3435 unsigned add = fieldFromInstruction(Insn, 4, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003436
Silviu Barangab7c2ed62012-03-22 13:24:43 +00003437 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00003438 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003439 Inst.addOperand(MCOperand::CreateImm(add));
3440
Owen Anderson83e3f672011-08-17 17:44:15 +00003441 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003442}
3443
Craig Topperc89c7442012-03-27 07:21:54 +00003444static DecodeStatus DecodeThumbBLXOffset(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003445 uint64_t Address, const void *Decoder) {
NAKAMURA Takumidd051a02012-05-22 21:47:02 +00003446 // Val is passed in as S:J1:J2:imm10H:imm10L:'0'
Kevin Enderby2d524b02012-05-03 22:41:56 +00003447 // Note only one trailing zero not two. Also the J1 and J2 values are from
3448 // the encoded instruction. So here change to I1 and I2 values via:
3449 // I1 = NOT(J1 EOR S);
3450 // I2 = NOT(J2 EOR S);
3451 // and build the imm32 with two trailing zeros as documented:
NAKAMURA Takumidd051a02012-05-22 21:47:02 +00003452 // imm32 = SignExtend(S:I1:I2:imm10H:imm10L:'00', 32);
Kevin Enderby2d524b02012-05-03 22:41:56 +00003453 unsigned S = (Val >> 23) & 1;
3454 unsigned J1 = (Val >> 22) & 1;
3455 unsigned J2 = (Val >> 21) & 1;
3456 unsigned I1 = !(J1 ^ S);
3457 unsigned I2 = !(J2 ^ S);
3458 unsigned tmp = (Val & ~0x600000) | (I1 << 22) | (I2 << 21);
3459 int imm32 = SignExtend32<25>(tmp << 1);
3460
Jim Grosbach01817c32011-10-20 17:28:20 +00003461 if (!tryAddingSymbolicOperand(Address,
Kevin Enderby2d524b02012-05-03 22:41:56 +00003462 (Address & ~2u) + imm32 + 4,
Kevin Enderby9e5887b2011-10-04 22:44:48 +00003463 true, 4, Inst, Decoder))
Kevin Enderby2d524b02012-05-03 22:41:56 +00003464 Inst.addOperand(MCOperand::CreateImm(imm32));
James Molloyc047dca2011-09-01 18:02:14 +00003465 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003466}
3467
Craig Topperc89c7442012-03-27 07:21:54 +00003468static DecodeStatus DecodeCoprocessor(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003469 uint64_t Address, const void *Decoder) {
3470 if (Val == 0xA || Val == 0xB)
James Molloyc047dca2011-09-01 18:02:14 +00003471 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003472
3473 Inst.addOperand(MCOperand::CreateImm(Val));
James Molloyc047dca2011-09-01 18:02:14 +00003474 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003475}
3476
Owen Andersona6804442011-09-01 23:23:50 +00003477static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00003478DecodeThumbTableBranch(MCInst &Inst, unsigned Insn,
Jim Grosbach7f739be2011-09-19 22:21:13 +00003479 uint64_t Address, const void *Decoder) {
3480 DecodeStatus S = MCDisassembler::Success;
3481
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003482 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3483 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
Jim Grosbach7f739be2011-09-19 22:21:13 +00003484
3485 if (Rn == ARM::SP) S = MCDisassembler::SoftFail;
3486 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3487 return MCDisassembler::Fail;
3488 if (!Check(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder)))
3489 return MCDisassembler::Fail;
3490 return S;
3491}
3492
3493static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00003494DecodeThumb2BCCInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00003495 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003496 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003497
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003498 unsigned pred = fieldFromInstruction(Insn, 22, 4);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003499 if (pred == 0xE || pred == 0xF) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003500 unsigned opc = fieldFromInstruction(Insn, 4, 28);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003501 switch (opc) {
3502 default:
James Molloyc047dca2011-09-01 18:02:14 +00003503 return MCDisassembler::Fail;
Owen Andersonb45b11b2011-08-31 22:00:41 +00003504 case 0xf3bf8f4:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003505 Inst.setOpcode(ARM::t2DSB);
3506 break;
Owen Andersonb45b11b2011-08-31 22:00:41 +00003507 case 0xf3bf8f5:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003508 Inst.setOpcode(ARM::t2DMB);
3509 break;
Owen Andersonb45b11b2011-08-31 22:00:41 +00003510 case 0xf3bf8f6:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003511 Inst.setOpcode(ARM::t2ISB);
Owen Anderson6de3c6f2011-09-07 17:55:19 +00003512 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003513 }
3514
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003515 unsigned imm = fieldFromInstruction(Insn, 0, 4);
Owen Andersonc36481c2011-08-09 23:25:42 +00003516 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003517 }
3518
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003519 unsigned brtarget = fieldFromInstruction(Insn, 0, 11) << 1;
3520 brtarget |= fieldFromInstruction(Insn, 11, 1) << 19;
3521 brtarget |= fieldFromInstruction(Insn, 13, 1) << 18;
3522 brtarget |= fieldFromInstruction(Insn, 16, 6) << 12;
3523 brtarget |= fieldFromInstruction(Insn, 26, 1) << 20;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003524
Owen Andersona6804442011-09-01 23:23:50 +00003525 if (!Check(S, DecodeT2BROperand(Inst, brtarget, Address, Decoder)))
3526 return MCDisassembler::Fail;
3527 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3528 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003529
Owen Anderson83e3f672011-08-17 17:44:15 +00003530 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003531}
3532
3533// Decode a shifted immediate operand. These basically consist
3534// of an 8-bit value, and a 4-bit directive that specifies either
3535// a splat operation or a rotation.
Craig Topperc89c7442012-03-27 07:21:54 +00003536static DecodeStatus DecodeT2SOImm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003537 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003538 unsigned ctrl = fieldFromInstruction(Val, 10, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003539 if (ctrl == 0) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003540 unsigned byte = fieldFromInstruction(Val, 8, 2);
3541 unsigned imm = fieldFromInstruction(Val, 0, 8);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003542 switch (byte) {
3543 case 0:
3544 Inst.addOperand(MCOperand::CreateImm(imm));
3545 break;
3546 case 1:
3547 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
3548 break;
3549 case 2:
3550 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
3551 break;
3552 case 3:
3553 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
3554 (imm << 8) | imm));
3555 break;
3556 }
3557 } else {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003558 unsigned unrot = fieldFromInstruction(Val, 0, 7) | 0x80;
3559 unsigned rot = fieldFromInstruction(Val, 7, 5);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003560 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
3561 Inst.addOperand(MCOperand::CreateImm(imm));
3562 }
3563
James Molloyc047dca2011-09-01 18:02:14 +00003564 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003565}
3566
Owen Andersona6804442011-09-01 23:23:50 +00003567static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00003568DecodeThumbBCCTargetOperand(MCInst &Inst, unsigned Val,
Jim Grosbachc4057822011-08-17 21:58:18 +00003569 uint64_t Address, const void *Decoder){
Richard Bartonc8f2fcc2012-06-06 09:12:53 +00003570 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<9>(Val<<1) + 4,
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003571 true, 2, Inst, Decoder))
Richard Bartonc8f2fcc2012-06-06 09:12:53 +00003572 Inst.addOperand(MCOperand::CreateImm(SignExtend32<9>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003573 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003574}
3575
Craig Topperc89c7442012-03-27 07:21:54 +00003576static DecodeStatus DecodeThumbBLTargetOperand(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003577 uint64_t Address, const void *Decoder){
Kevin Enderby2d524b02012-05-03 22:41:56 +00003578 // Val is passed in as S:J1:J2:imm10:imm11
3579 // Note no trailing zero after imm11. Also the J1 and J2 values are from
3580 // the encoded instruction. So here change to I1 and I2 values via:
3581 // I1 = NOT(J1 EOR S);
3582 // I2 = NOT(J2 EOR S);
3583 // and build the imm32 with one trailing zero as documented:
NAKAMURA Takumidd051a02012-05-22 21:47:02 +00003584 // imm32 = SignExtend(S:I1:I2:imm10:imm11:'0', 32);
Kevin Enderby2d524b02012-05-03 22:41:56 +00003585 unsigned S = (Val >> 23) & 1;
3586 unsigned J1 = (Val >> 22) & 1;
3587 unsigned J2 = (Val >> 21) & 1;
3588 unsigned I1 = !(J1 ^ S);
3589 unsigned I2 = !(J2 ^ S);
3590 unsigned tmp = (Val & ~0x600000) | (I1 << 22) | (I2 << 21);
3591 int imm32 = SignExtend32<25>(tmp << 1);
3592
3593 if (!tryAddingSymbolicOperand(Address, Address + imm32 + 4,
Kevin Enderbyb80d5712012-02-23 18:18:17 +00003594 true, 4, Inst, Decoder))
Kevin Enderby2d524b02012-05-03 22:41:56 +00003595 Inst.addOperand(MCOperand::CreateImm(imm32));
James Molloyc047dca2011-09-01 18:02:14 +00003596 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003597}
3598
Craig Topperc89c7442012-03-27 07:21:54 +00003599static DecodeStatus DecodeMemBarrierOption(MCInst &Inst, unsigned Val,
Owen Andersonc36481c2011-08-09 23:25:42 +00003600 uint64_t Address, const void *Decoder) {
Jiangning Liuc1b7ca52012-08-02 08:21:27 +00003601 if (Val & ~0xf)
James Molloyc047dca2011-09-01 18:02:14 +00003602 return MCDisassembler::Fail;
Owen Andersonc36481c2011-08-09 23:25:42 +00003603
3604 Inst.addOperand(MCOperand::CreateImm(Val));
James Molloyc047dca2011-09-01 18:02:14 +00003605 return MCDisassembler::Success;
Owen Andersonc36481c2011-08-09 23:25:42 +00003606}
3607
Craig Topperc89c7442012-03-27 07:21:54 +00003608static DecodeStatus DecodeMSRMask(MCInst &Inst, unsigned Val,
Owen Anderson26d2f0a2011-08-11 20:21:46 +00003609 uint64_t Address, const void *Decoder) {
James Molloyc047dca2011-09-01 18:02:14 +00003610 if (!Val) return MCDisassembler::Fail;
Owen Anderson26d2f0a2011-08-11 20:21:46 +00003611 Inst.addOperand(MCOperand::CreateImm(Val));
James Molloyc047dca2011-09-01 18:02:14 +00003612 return MCDisassembler::Success;
Owen Anderson26d2f0a2011-08-11 20:21:46 +00003613}
Owen Andersoncbfc0442011-08-11 21:34:58 +00003614
Craig Topperc89c7442012-03-27 07:21:54 +00003615static DecodeStatus DecodeDoubleRegLoad(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00003616 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003617 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003618
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003619 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
3620 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3621 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Anderson3f3570a2011-08-12 17:58:32 +00003622
James Molloyc047dca2011-09-01 18:02:14 +00003623 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return MCDisassembler::Fail;
Owen Anderson3f3570a2011-08-12 17:58:32 +00003624
Owen Andersona6804442011-09-01 23:23:50 +00003625 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3626 return MCDisassembler::Fail;
3627 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)))
3628 return MCDisassembler::Fail;
3629 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3630 return MCDisassembler::Fail;
3631 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3632 return MCDisassembler::Fail;
Owen Anderson3f3570a2011-08-12 17:58:32 +00003633
Owen Anderson83e3f672011-08-17 17:44:15 +00003634 return S;
Owen Anderson3f3570a2011-08-12 17:58:32 +00003635}
3636
3637
Craig Topperc89c7442012-03-27 07:21:54 +00003638static DecodeStatus DecodeDoubleRegStore(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00003639 uint64_t Address, const void *Decoder){
Owen Andersona6804442011-09-01 23:23:50 +00003640 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003641
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003642 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3643 unsigned Rt = fieldFromInstruction(Insn, 0, 4);
3644 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3645 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Andersoncbfc0442011-08-11 21:34:58 +00003646
Tim Northoverd3af6962013-04-19 15:44:32 +00003647 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00003648 return MCDisassembler::Fail;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003649
James Molloyc047dca2011-09-01 18:02:14 +00003650 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return MCDisassembler::Fail;
3651 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return MCDisassembler::Fail;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003652
Owen Andersona6804442011-09-01 23:23:50 +00003653 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3654 return MCDisassembler::Fail;
3655 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)))
3656 return MCDisassembler::Fail;
3657 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3658 return MCDisassembler::Fail;
3659 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3660 return MCDisassembler::Fail;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003661
Owen Anderson83e3f672011-08-17 17:44:15 +00003662 return S;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003663}
3664
Craig Topperc89c7442012-03-27 07:21:54 +00003665static DecodeStatus DecodeLDRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003666 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003667 DecodeStatus S = MCDisassembler::Success;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003668
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003669 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3670 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
3671 unsigned imm = fieldFromInstruction(Insn, 0, 12);
3672 imm |= fieldFromInstruction(Insn, 16, 4) << 13;
3673 imm |= fieldFromInstruction(Insn, 23, 1) << 12;
3674 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Anderson9ab0f252011-08-26 20:43:14 +00003675
James Molloyc047dca2011-09-01 18:02:14 +00003676 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003677
Owen Andersona6804442011-09-01 23:23:50 +00003678 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3679 return MCDisassembler::Fail;
3680 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3681 return MCDisassembler::Fail;
3682 if (!Check(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder)))
3683 return MCDisassembler::Fail;
3684 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3685 return MCDisassembler::Fail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003686
3687 return S;
3688}
3689
Craig Topperc89c7442012-03-27 07:21:54 +00003690static DecodeStatus DecodeLDRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003691 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003692 DecodeStatus S = MCDisassembler::Success;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003693
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003694 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3695 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
3696 unsigned imm = fieldFromInstruction(Insn, 0, 12);
3697 imm |= fieldFromInstruction(Insn, 16, 4) << 13;
3698 imm |= fieldFromInstruction(Insn, 23, 1) << 12;
3699 unsigned pred = fieldFromInstruction(Insn, 28, 4);
3700 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
Owen Anderson9ab0f252011-08-26 20:43:14 +00003701
James Molloyc047dca2011-09-01 18:02:14 +00003702 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
3703 if (Rm == 0xF) S = MCDisassembler::SoftFail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003704
Owen Andersona6804442011-09-01 23:23:50 +00003705 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3706 return MCDisassembler::Fail;
3707 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3708 return MCDisassembler::Fail;
3709 if (!Check(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder)))
3710 return MCDisassembler::Fail;
3711 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3712 return MCDisassembler::Fail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003713
3714 return S;
3715}
3716
3717
Craig Topperc89c7442012-03-27 07:21:54 +00003718static DecodeStatus DecodeSTRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +00003719 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003720 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003721
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003722 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3723 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
3724 unsigned imm = fieldFromInstruction(Insn, 0, 12);
3725 imm |= fieldFromInstruction(Insn, 16, 4) << 13;
3726 imm |= fieldFromInstruction(Insn, 23, 1) << 12;
3727 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Andersoncbfc0442011-08-11 21:34:58 +00003728
James Molloyc047dca2011-09-01 18:02:14 +00003729 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003730
Owen Andersona6804442011-09-01 23:23:50 +00003731 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3732 return MCDisassembler::Fail;
3733 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3734 return MCDisassembler::Fail;
3735 if (!Check(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder)))
3736 return MCDisassembler::Fail;
3737 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3738 return MCDisassembler::Fail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003739
Owen Anderson83e3f672011-08-17 17:44:15 +00003740 return S;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003741}
3742
Craig Topperc89c7442012-03-27 07:21:54 +00003743static DecodeStatus DecodeSTRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +00003744 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003745 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003746
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003747 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3748 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
3749 unsigned imm = fieldFromInstruction(Insn, 0, 12);
3750 imm |= fieldFromInstruction(Insn, 16, 4) << 13;
3751 imm |= fieldFromInstruction(Insn, 23, 1) << 12;
3752 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Anderson7cdbf082011-08-12 18:12:39 +00003753
James Molloyc047dca2011-09-01 18:02:14 +00003754 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003755
Owen Andersona6804442011-09-01 23:23:50 +00003756 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3757 return MCDisassembler::Fail;
3758 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3759 return MCDisassembler::Fail;
3760 if (!Check(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder)))
3761 return MCDisassembler::Fail;
3762 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3763 return MCDisassembler::Fail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003764
Owen Anderson83e3f672011-08-17 17:44:15 +00003765 return S;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003766}
Owen Anderson7a2e1772011-08-15 18:44:44 +00003767
Craig Topperc89c7442012-03-27 07:21:54 +00003768static DecodeStatus DecodeVLD1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003769 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003770 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003771
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003772 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3773 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3774 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3775 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
3776 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00003777
3778 unsigned align = 0;
3779 unsigned index = 0;
3780 switch (size) {
3781 default:
James Molloyc047dca2011-09-01 18:02:14 +00003782 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003783 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003784 if (fieldFromInstruction(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003785 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003786 index = fieldFromInstruction(Insn, 5, 3);
Owen Anderson7a2e1772011-08-15 18:44:44 +00003787 break;
3788 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003789 if (fieldFromInstruction(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003790 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003791 index = fieldFromInstruction(Insn, 6, 2);
3792 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003793 align = 2;
3794 break;
3795 case 2:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003796 if (fieldFromInstruction(Insn, 6, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003797 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003798 index = fieldFromInstruction(Insn, 7, 1);
Tim Northovereae1d342012-09-06 15:17:49 +00003799
3800 switch (fieldFromInstruction(Insn, 4, 2)) {
3801 case 0 :
3802 align = 0; break;
3803 case 3:
3804 align = 4; break;
3805 default:
3806 return MCDisassembler::Fail;
3807 }
3808 break;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003809 }
3810
Owen Andersona6804442011-09-01 23:23:50 +00003811 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3812 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003813 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003814 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3815 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003816 }
Owen Andersona6804442011-09-01 23:23:50 +00003817 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3818 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003819 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003820 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003821 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003822 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3823 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003824 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003825 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003826 }
3827
Owen Andersona6804442011-09-01 23:23:50 +00003828 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3829 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003830 Inst.addOperand(MCOperand::CreateImm(index));
3831
Owen Anderson83e3f672011-08-17 17:44:15 +00003832 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003833}
3834
Craig Topperc89c7442012-03-27 07:21:54 +00003835static DecodeStatus DecodeVST1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003836 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003837 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003838
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003839 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3840 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3841 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3842 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
3843 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00003844
3845 unsigned align = 0;
3846 unsigned index = 0;
3847 switch (size) {
3848 default:
James Molloyc047dca2011-09-01 18:02:14 +00003849 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003850 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003851 if (fieldFromInstruction(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003852 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003853 index = fieldFromInstruction(Insn, 5, 3);
Owen Anderson7a2e1772011-08-15 18:44:44 +00003854 break;
3855 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003856 if (fieldFromInstruction(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003857 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003858 index = fieldFromInstruction(Insn, 6, 2);
3859 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003860 align = 2;
3861 break;
3862 case 2:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003863 if (fieldFromInstruction(Insn, 6, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003864 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003865 index = fieldFromInstruction(Insn, 7, 1);
Tim Northovereae1d342012-09-06 15:17:49 +00003866
3867 switch (fieldFromInstruction(Insn, 4, 2)) {
3868 case 0:
3869 align = 0; break;
3870 case 3:
3871 align = 4; break;
3872 default:
3873 return MCDisassembler::Fail;
3874 }
3875 break;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003876 }
3877
3878 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003879 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3880 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003881 }
Owen Andersona6804442011-09-01 23:23:50 +00003882 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3883 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003884 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003885 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003886 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003887 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3888 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003889 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003890 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003891 }
3892
Owen Andersona6804442011-09-01 23:23:50 +00003893 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3894 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003895 Inst.addOperand(MCOperand::CreateImm(index));
3896
Owen Anderson83e3f672011-08-17 17:44:15 +00003897 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003898}
3899
3900
Craig Topperc89c7442012-03-27 07:21:54 +00003901static DecodeStatus DecodeVLD2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003902 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003903 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003904
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003905 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3906 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3907 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3908 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
3909 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00003910
3911 unsigned align = 0;
3912 unsigned index = 0;
3913 unsigned inc = 1;
3914 switch (size) {
3915 default:
James Molloyc047dca2011-09-01 18:02:14 +00003916 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003917 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003918 index = fieldFromInstruction(Insn, 5, 3);
3919 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003920 align = 2;
3921 break;
3922 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003923 index = fieldFromInstruction(Insn, 6, 2);
3924 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003925 align = 4;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003926 if (fieldFromInstruction(Insn, 5, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003927 inc = 2;
3928 break;
3929 case 2:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003930 if (fieldFromInstruction(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003931 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003932 index = fieldFromInstruction(Insn, 7, 1);
3933 if (fieldFromInstruction(Insn, 4, 1) != 0)
Owen Anderson7a2e1772011-08-15 18:44:44 +00003934 align = 8;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003935 if (fieldFromInstruction(Insn, 6, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003936 inc = 2;
3937 break;
3938 }
3939
Owen Andersona6804442011-09-01 23:23:50 +00003940 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3941 return MCDisassembler::Fail;
3942 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3943 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003944 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003945 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3946 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003947 }
Owen Andersona6804442011-09-01 23:23:50 +00003948 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3949 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003950 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003951 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003952 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003953 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3954 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003955 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003956 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003957 }
3958
Owen Andersona6804442011-09-01 23:23:50 +00003959 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3960 return MCDisassembler::Fail;
3961 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3962 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003963 Inst.addOperand(MCOperand::CreateImm(index));
3964
Owen Anderson83e3f672011-08-17 17:44:15 +00003965 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003966}
3967
Craig Topperc89c7442012-03-27 07:21:54 +00003968static DecodeStatus DecodeVST2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003969 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003970 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003971
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003972 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
3973 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
3974 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
3975 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
3976 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00003977
3978 unsigned align = 0;
3979 unsigned index = 0;
3980 unsigned inc = 1;
3981 switch (size) {
3982 default:
James Molloyc047dca2011-09-01 18:02:14 +00003983 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003984 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003985 index = fieldFromInstruction(Insn, 5, 3);
3986 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003987 align = 2;
3988 break;
3989 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003990 index = fieldFromInstruction(Insn, 6, 2);
3991 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003992 align = 4;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003993 if (fieldFromInstruction(Insn, 5, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00003994 inc = 2;
3995 break;
3996 case 2:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003997 if (fieldFromInstruction(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003998 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00003999 index = fieldFromInstruction(Insn, 7, 1);
4000 if (fieldFromInstruction(Insn, 4, 1) != 0)
Owen Anderson7a2e1772011-08-15 18:44:44 +00004001 align = 8;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004002 if (fieldFromInstruction(Insn, 6, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004003 inc = 2;
4004 break;
4005 }
4006
4007 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004008 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4009 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004010 }
Owen Andersona6804442011-09-01 23:23:50 +00004011 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4012 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004013 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004014 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004015 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004016 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4017 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004018 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004019 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004020 }
4021
Owen Andersona6804442011-09-01 23:23:50 +00004022 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4023 return MCDisassembler::Fail;
4024 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4025 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004026 Inst.addOperand(MCOperand::CreateImm(index));
4027
Owen Anderson83e3f672011-08-17 17:44:15 +00004028 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004029}
4030
4031
Craig Topperc89c7442012-03-27 07:21:54 +00004032static DecodeStatus DecodeVLD3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00004033 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004034 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00004035
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004036 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4037 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
4038 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
4039 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
4040 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004041
4042 unsigned align = 0;
4043 unsigned index = 0;
4044 unsigned inc = 1;
4045 switch (size) {
4046 default:
James Molloyc047dca2011-09-01 18:02:14 +00004047 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004048 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004049 if (fieldFromInstruction(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00004050 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004051 index = fieldFromInstruction(Insn, 5, 3);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004052 break;
4053 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004054 if (fieldFromInstruction(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00004055 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004056 index = fieldFromInstruction(Insn, 6, 2);
4057 if (fieldFromInstruction(Insn, 5, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004058 inc = 2;
4059 break;
4060 case 2:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004061 if (fieldFromInstruction(Insn, 4, 2))
James Molloyc047dca2011-09-01 18:02:14 +00004062 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004063 index = fieldFromInstruction(Insn, 7, 1);
4064 if (fieldFromInstruction(Insn, 6, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004065 inc = 2;
4066 break;
4067 }
4068
Owen Andersona6804442011-09-01 23:23:50 +00004069 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4070 return MCDisassembler::Fail;
4071 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4072 return MCDisassembler::Fail;
4073 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4074 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004075
4076 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004077 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4078 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004079 }
Owen Andersona6804442011-09-01 23:23:50 +00004080 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4081 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004082 Inst.addOperand(MCOperand::CreateImm(align));
Owen Andersoneaca9282011-08-30 22:58:27 +00004083 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004084 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004085 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4086 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004087 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004088 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004089 }
4090
Owen Andersona6804442011-09-01 23:23:50 +00004091 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4092 return MCDisassembler::Fail;
4093 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4094 return MCDisassembler::Fail;
4095 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4096 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004097 Inst.addOperand(MCOperand::CreateImm(index));
4098
Owen Anderson83e3f672011-08-17 17:44:15 +00004099 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004100}
4101
Craig Topperc89c7442012-03-27 07:21:54 +00004102static DecodeStatus DecodeVST3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00004103 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004104 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00004105
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004106 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4107 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
4108 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
4109 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
4110 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004111
4112 unsigned align = 0;
4113 unsigned index = 0;
4114 unsigned inc = 1;
4115 switch (size) {
4116 default:
James Molloyc047dca2011-09-01 18:02:14 +00004117 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004118 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004119 if (fieldFromInstruction(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00004120 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004121 index = fieldFromInstruction(Insn, 5, 3);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004122 break;
4123 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004124 if (fieldFromInstruction(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00004125 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004126 index = fieldFromInstruction(Insn, 6, 2);
4127 if (fieldFromInstruction(Insn, 5, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004128 inc = 2;
4129 break;
4130 case 2:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004131 if (fieldFromInstruction(Insn, 4, 2))
James Molloyc047dca2011-09-01 18:02:14 +00004132 return MCDisassembler::Fail; // UNDEFINED
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004133 index = fieldFromInstruction(Insn, 7, 1);
4134 if (fieldFromInstruction(Insn, 6, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004135 inc = 2;
4136 break;
4137 }
4138
4139 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004140 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4141 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004142 }
Owen Andersona6804442011-09-01 23:23:50 +00004143 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4144 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004145 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004146 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004147 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004148 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4149 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004150 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004151 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004152 }
4153
Owen Andersona6804442011-09-01 23:23:50 +00004154 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4155 return MCDisassembler::Fail;
4156 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4157 return MCDisassembler::Fail;
4158 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4159 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004160 Inst.addOperand(MCOperand::CreateImm(index));
4161
Owen Anderson83e3f672011-08-17 17:44:15 +00004162 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004163}
4164
4165
Craig Topperc89c7442012-03-27 07:21:54 +00004166static DecodeStatus DecodeVLD4LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00004167 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004168 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00004169
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004170 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4171 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
4172 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
4173 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
4174 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004175
4176 unsigned align = 0;
4177 unsigned index = 0;
4178 unsigned inc = 1;
4179 switch (size) {
4180 default:
James Molloyc047dca2011-09-01 18:02:14 +00004181 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004182 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004183 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004184 align = 4;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004185 index = fieldFromInstruction(Insn, 5, 3);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004186 break;
4187 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004188 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004189 align = 8;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004190 index = fieldFromInstruction(Insn, 6, 2);
4191 if (fieldFromInstruction(Insn, 5, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004192 inc = 2;
4193 break;
4194 case 2:
Tim Northovereae1d342012-09-06 15:17:49 +00004195 switch (fieldFromInstruction(Insn, 4, 2)) {
4196 case 0:
4197 align = 0; break;
4198 case 3:
4199 return MCDisassembler::Fail;
4200 default:
4201 align = 4 << fieldFromInstruction(Insn, 4, 2); break;
4202 }
4203
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004204 index = fieldFromInstruction(Insn, 7, 1);
4205 if (fieldFromInstruction(Insn, 6, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004206 inc = 2;
4207 break;
4208 }
4209
Owen Andersona6804442011-09-01 23:23:50 +00004210 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4211 return MCDisassembler::Fail;
4212 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4213 return MCDisassembler::Fail;
4214 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4215 return MCDisassembler::Fail;
4216 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)))
4217 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004218
4219 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004220 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4221 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004222 }
Owen Andersona6804442011-09-01 23:23:50 +00004223 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4224 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004225 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004226 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004227 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004228 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4229 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004230 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004231 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004232 }
4233
Owen Andersona6804442011-09-01 23:23:50 +00004234 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4235 return MCDisassembler::Fail;
4236 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4237 return MCDisassembler::Fail;
4238 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4239 return MCDisassembler::Fail;
4240 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)))
4241 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004242 Inst.addOperand(MCOperand::CreateImm(index));
4243
Owen Anderson83e3f672011-08-17 17:44:15 +00004244 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004245}
4246
Craig Topperc89c7442012-03-27 07:21:54 +00004247static DecodeStatus DecodeVST4LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00004248 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004249 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00004250
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004251 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4252 unsigned Rm = fieldFromInstruction(Insn, 0, 4);
4253 unsigned Rd = fieldFromInstruction(Insn, 12, 4);
4254 Rd |= fieldFromInstruction(Insn, 22, 1) << 4;
4255 unsigned size = fieldFromInstruction(Insn, 10, 2);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004256
4257 unsigned align = 0;
4258 unsigned index = 0;
4259 unsigned inc = 1;
4260 switch (size) {
4261 default:
James Molloyc047dca2011-09-01 18:02:14 +00004262 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004263 case 0:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004264 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004265 align = 4;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004266 index = fieldFromInstruction(Insn, 5, 3);
Owen Anderson7a2e1772011-08-15 18:44:44 +00004267 break;
4268 case 1:
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004269 if (fieldFromInstruction(Insn, 4, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004270 align = 8;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004271 index = fieldFromInstruction(Insn, 6, 2);
4272 if (fieldFromInstruction(Insn, 5, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004273 inc = 2;
4274 break;
4275 case 2:
Tim Northovereae1d342012-09-06 15:17:49 +00004276 switch (fieldFromInstruction(Insn, 4, 2)) {
4277 case 0:
4278 align = 0; break;
4279 case 3:
4280 return MCDisassembler::Fail;
4281 default:
4282 align = 4 << fieldFromInstruction(Insn, 4, 2); break;
4283 }
4284
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004285 index = fieldFromInstruction(Insn, 7, 1);
4286 if (fieldFromInstruction(Insn, 6, 1))
Owen Anderson7a2e1772011-08-15 18:44:44 +00004287 inc = 2;
4288 break;
4289 }
4290
4291 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004292 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4293 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004294 }
Owen Andersona6804442011-09-01 23:23:50 +00004295 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4296 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004297 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004298 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004299 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004300 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4301 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004302 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004303 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004304 }
4305
Owen Andersona6804442011-09-01 23:23:50 +00004306 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4307 return MCDisassembler::Fail;
4308 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4309 return MCDisassembler::Fail;
4310 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4311 return MCDisassembler::Fail;
4312 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)))
4313 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004314 Inst.addOperand(MCOperand::CreateImm(index));
4315
Owen Anderson83e3f672011-08-17 17:44:15 +00004316 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004317}
4318
Craig Topperc89c7442012-03-27 07:21:54 +00004319static DecodeStatus DecodeVMOVSRR(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +00004320 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004321 DecodeStatus S = MCDisassembler::Success;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004322 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
4323 unsigned Rt2 = fieldFromInstruction(Insn, 16, 4);
4324 unsigned Rm = fieldFromInstruction(Insn, 5, 1);
4325 unsigned pred = fieldFromInstruction(Insn, 28, 4);
4326 Rm |= fieldFromInstruction(Insn, 0, 4) << 1;
Owen Anderson357ec682011-08-22 20:27:12 +00004327
4328 if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F)
James Molloyc047dca2011-09-01 18:02:14 +00004329 S = MCDisassembler::SoftFail;
Owen Anderson357ec682011-08-22 20:27:12 +00004330
Owen Andersona6804442011-09-01 23:23:50 +00004331 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder)))
4332 return MCDisassembler::Fail;
4333 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm+1, Address, Decoder)))
4334 return MCDisassembler::Fail;
4335 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder)))
4336 return MCDisassembler::Fail;
4337 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder)))
4338 return MCDisassembler::Fail;
4339 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
4340 return MCDisassembler::Fail;
Owen Anderson357ec682011-08-22 20:27:12 +00004341
4342 return S;
4343}
4344
Craig Topperc89c7442012-03-27 07:21:54 +00004345static DecodeStatus DecodeVMOVRRS(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +00004346 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004347 DecodeStatus S = MCDisassembler::Success;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004348 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
4349 unsigned Rt2 = fieldFromInstruction(Insn, 16, 4);
4350 unsigned Rm = fieldFromInstruction(Insn, 5, 1);
4351 unsigned pred = fieldFromInstruction(Insn, 28, 4);
4352 Rm |= fieldFromInstruction(Insn, 0, 4) << 1;
Owen Anderson357ec682011-08-22 20:27:12 +00004353
4354 if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F)
James Molloyc047dca2011-09-01 18:02:14 +00004355 S = MCDisassembler::SoftFail;
Owen Anderson357ec682011-08-22 20:27:12 +00004356
Owen Andersona6804442011-09-01 23:23:50 +00004357 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder)))
4358 return MCDisassembler::Fail;
4359 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder)))
4360 return MCDisassembler::Fail;
4361 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder)))
4362 return MCDisassembler::Fail;
4363 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm+1, Address, Decoder)))
4364 return MCDisassembler::Fail;
4365 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
4366 return MCDisassembler::Fail;
Owen Anderson357ec682011-08-22 20:27:12 +00004367
4368 return S;
4369}
Owen Anderson8e1e60b2011-08-22 23:44:04 +00004370
Craig Topperc89c7442012-03-27 07:21:54 +00004371static DecodeStatus DecodeIT(MCInst &Inst, unsigned Insn,
Owen Andersoneaca9282011-08-30 22:58:27 +00004372 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004373 DecodeStatus S = MCDisassembler::Success;
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004374 unsigned pred = fieldFromInstruction(Insn, 4, 4);
4375 unsigned mask = fieldFromInstruction(Insn, 0, 4);
Owen Andersoneaca9282011-08-30 22:58:27 +00004376
4377 if (pred == 0xF) {
4378 pred = 0xE;
James Molloyc047dca2011-09-01 18:02:14 +00004379 S = MCDisassembler::SoftFail;
Owen Andersone234d022011-08-24 17:21:43 +00004380 }
4381
Richard Barton4d2f0772012-04-27 08:42:59 +00004382 if (mask == 0x0) {
Owen Andersoneaca9282011-08-30 22:58:27 +00004383 mask |= 0x8;
James Molloyc047dca2011-09-01 18:02:14 +00004384 S = MCDisassembler::SoftFail;
Owen Andersonf4408202011-08-24 22:40:22 +00004385 }
Owen Andersoneaca9282011-08-30 22:58:27 +00004386
4387 Inst.addOperand(MCOperand::CreateImm(pred));
4388 Inst.addOperand(MCOperand::CreateImm(mask));
Owen Andersonf4408202011-08-24 22:40:22 +00004389 return S;
4390}
Jim Grosbacha77295d2011-09-08 22:07:06 +00004391
4392static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00004393DecodeT2LDRDPreInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +00004394 uint64_t Address, const void *Decoder) {
4395 DecodeStatus S = MCDisassembler::Success;
4396
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004397 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
4398 unsigned Rt2 = fieldFromInstruction(Insn, 8, 4);
4399 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4400 unsigned addr = fieldFromInstruction(Insn, 0, 8);
4401 unsigned W = fieldFromInstruction(Insn, 21, 1);
4402 unsigned U = fieldFromInstruction(Insn, 23, 1);
4403 unsigned P = fieldFromInstruction(Insn, 24, 1);
Jim Grosbacha77295d2011-09-08 22:07:06 +00004404 bool writeback = (W == 1) | (P == 0);
4405
4406 addr |= (U << 8) | (Rn << 9);
4407
4408 if (writeback && (Rn == Rt || Rn == Rt2))
4409 Check(S, MCDisassembler::SoftFail);
4410 if (Rt == Rt2)
4411 Check(S, MCDisassembler::SoftFail);
4412
4413 // Rt
4414 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
4415 return MCDisassembler::Fail;
4416 // Rt2
4417 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt2, Address, Decoder)))
4418 return MCDisassembler::Fail;
4419 // Writeback operand
4420 if (!Check(S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder)))
4421 return MCDisassembler::Fail;
4422 // addr
4423 if (!Check(S, DecodeT2AddrModeImm8s4(Inst, addr, Address, Decoder)))
4424 return MCDisassembler::Fail;
4425
4426 return S;
4427}
4428
4429static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00004430DecodeT2STRDPreInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +00004431 uint64_t Address, const void *Decoder) {
4432 DecodeStatus S = MCDisassembler::Success;
4433
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004434 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
4435 unsigned Rt2 = fieldFromInstruction(Insn, 8, 4);
4436 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4437 unsigned addr = fieldFromInstruction(Insn, 0, 8);
4438 unsigned W = fieldFromInstruction(Insn, 21, 1);
4439 unsigned U = fieldFromInstruction(Insn, 23, 1);
4440 unsigned P = fieldFromInstruction(Insn, 24, 1);
Jim Grosbacha77295d2011-09-08 22:07:06 +00004441 bool writeback = (W == 1) | (P == 0);
4442
4443 addr |= (U << 8) | (Rn << 9);
4444
4445 if (writeback && (Rn == Rt || Rn == Rt2))
4446 Check(S, MCDisassembler::SoftFail);
4447
4448 // Writeback operand
4449 if (!Check(S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder)))
4450 return MCDisassembler::Fail;
4451 // Rt
4452 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
4453 return MCDisassembler::Fail;
4454 // Rt2
4455 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt2, Address, Decoder)))
4456 return MCDisassembler::Fail;
4457 // addr
4458 if (!Check(S, DecodeT2AddrModeImm8s4(Inst, addr, Address, Decoder)))
4459 return MCDisassembler::Fail;
4460
4461 return S;
4462}
Owen Anderson08fef882011-09-09 22:24:36 +00004463
Craig Topperc89c7442012-03-27 07:21:54 +00004464static DecodeStatus DecodeT2Adr(MCInst &Inst, uint32_t Insn,
Owen Anderson08fef882011-09-09 22:24:36 +00004465 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004466 unsigned sign1 = fieldFromInstruction(Insn, 21, 1);
4467 unsigned sign2 = fieldFromInstruction(Insn, 23, 1);
Owen Anderson08fef882011-09-09 22:24:36 +00004468 if (sign1 != sign2) return MCDisassembler::Fail;
4469
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004470 unsigned Val = fieldFromInstruction(Insn, 0, 8);
4471 Val |= fieldFromInstruction(Insn, 12, 3) << 8;
4472 Val |= fieldFromInstruction(Insn, 26, 1) << 11;
Owen Anderson08fef882011-09-09 22:24:36 +00004473 Val |= sign1 << 12;
4474 Inst.addOperand(MCOperand::CreateImm(SignExtend32<13>(Val)));
4475
4476 return MCDisassembler::Success;
4477}
4478
Craig Topperc89c7442012-03-27 07:21:54 +00004479static DecodeStatus DecodeT2ShifterImmOperand(MCInst &Inst, uint32_t Val,
Owen Anderson0afa0092011-09-26 21:06:22 +00004480 uint64_t Address,
4481 const void *Decoder) {
4482 DecodeStatus S = MCDisassembler::Success;
4483
4484 // Shift of "asr #32" is not allowed in Thumb2 mode.
4485 if (Val == 0x20) S = MCDisassembler::SoftFail;
4486 Inst.addOperand(MCOperand::CreateImm(Val));
4487 return S;
4488}
4489
Craig Topperc89c7442012-03-27 07:21:54 +00004490static DecodeStatus DecodeSwap(MCInst &Inst, unsigned Insn,
Owen Andersoncb9fed62011-10-28 18:02:13 +00004491 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004492 unsigned Rt = fieldFromInstruction(Insn, 12, 4);
4493 unsigned Rt2 = fieldFromInstruction(Insn, 0, 4);
4494 unsigned Rn = fieldFromInstruction(Insn, 16, 4);
4495 unsigned pred = fieldFromInstruction(Insn, 28, 4);
Owen Andersoncb9fed62011-10-28 18:02:13 +00004496
4497 if (pred == 0xF)
4498 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
4499
4500 DecodeStatus S = MCDisassembler::Success;
Silviu Baranga35ee7d22012-04-18 14:18:57 +00004501
4502 if (Rt == Rn || Rn == Rt2)
4503 S = MCDisassembler::SoftFail;
4504
Owen Andersoncb9fed62011-10-28 18:02:13 +00004505 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)))
4506 return MCDisassembler::Fail;
4507 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder)))
4508 return MCDisassembler::Fail;
4509 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
4510 return MCDisassembler::Fail;
4511 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
4512 return MCDisassembler::Fail;
4513
4514 return S;
4515}
Owen Andersonb589be92011-11-15 19:55:00 +00004516
Craig Topperc89c7442012-03-27 07:21:54 +00004517static DecodeStatus DecodeVCVTD(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +00004518 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004519 unsigned Vd = (fieldFromInstruction(Insn, 12, 4) << 0);
4520 Vd |= (fieldFromInstruction(Insn, 22, 1) << 4);
4521 unsigned Vm = (fieldFromInstruction(Insn, 0, 4) << 0);
4522 Vm |= (fieldFromInstruction(Insn, 5, 1) << 4);
4523 unsigned imm = fieldFromInstruction(Insn, 16, 6);
4524 unsigned cmode = fieldFromInstruction(Insn, 8, 4);
Owen Andersonb589be92011-11-15 19:55:00 +00004525
4526 DecodeStatus S = MCDisassembler::Success;
4527
4528 // VMOVv2f32 is ambiguous with these decodings.
Owen Anderson22925d92011-11-15 20:30:41 +00004529 if (!(imm & 0x38) && cmode == 0xF) {
Owen Andersonb589be92011-11-15 19:55:00 +00004530 Inst.setOpcode(ARM::VMOVv2f32);
4531 return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder);
4532 }
4533
4534 if (!(imm & 0x20)) Check(S, MCDisassembler::SoftFail);
4535
4536 if (!Check(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)))
4537 return MCDisassembler::Fail;
4538 if (!Check(S, DecodeDPRRegisterClass(Inst, Vm, Address, Decoder)))
4539 return MCDisassembler::Fail;
4540 Inst.addOperand(MCOperand::CreateImm(64 - imm));
4541
4542 return S;
4543}
4544
Craig Topperc89c7442012-03-27 07:21:54 +00004545static DecodeStatus DecodeVCVTQ(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +00004546 uint64_t Address, const void *Decoder) {
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004547 unsigned Vd = (fieldFromInstruction(Insn, 12, 4) << 0);
4548 Vd |= (fieldFromInstruction(Insn, 22, 1) << 4);
4549 unsigned Vm = (fieldFromInstruction(Insn, 0, 4) << 0);
4550 Vm |= (fieldFromInstruction(Insn, 5, 1) << 4);
4551 unsigned imm = fieldFromInstruction(Insn, 16, 6);
4552 unsigned cmode = fieldFromInstruction(Insn, 8, 4);
Owen Andersonb589be92011-11-15 19:55:00 +00004553
4554 DecodeStatus S = MCDisassembler::Success;
4555
4556 // VMOVv4f32 is ambiguous with these decodings.
4557 if (!(imm & 0x38) && cmode == 0xF) {
4558 Inst.setOpcode(ARM::VMOVv4f32);
4559 return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder);
4560 }
4561
4562 if (!(imm & 0x20)) Check(S, MCDisassembler::SoftFail);
4563
4564 if (!Check(S, DecodeQPRRegisterClass(Inst, Vd, Address, Decoder)))
4565 return MCDisassembler::Fail;
4566 if (!Check(S, DecodeQPRRegisterClass(Inst, Vm, Address, Decoder)))
4567 return MCDisassembler::Fail;
4568 Inst.addOperand(MCOperand::CreateImm(64 - imm));
4569
4570 return S;
4571}
Silviu Barangab7c2ed62012-03-22 13:24:43 +00004572
Quentin Colombet7c4cf032013-04-17 18:46:12 +00004573static DecodeStatus DecodeImm0_4(MCInst &Inst, unsigned Insn, uint64_t Address,
4574 const void *Decoder)
4575{
4576 unsigned Imm = fieldFromInstruction(Insn, 0, 3);
4577 if (Imm > 4) return MCDisassembler::Fail;
4578 Inst.addOperand(MCOperand::CreateImm(Imm));
4579 return MCDisassembler::Success;
4580}
4581
Craig Topperc89c7442012-03-27 07:21:54 +00004582static DecodeStatus DecodeLDR(MCInst &Inst, unsigned Val,
Silviu Barangab7c2ed62012-03-22 13:24:43 +00004583 uint64_t Address, const void *Decoder) {
4584 DecodeStatus S = MCDisassembler::Success;
4585
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004586 unsigned Rn = fieldFromInstruction(Val, 16, 4);
4587 unsigned Rt = fieldFromInstruction(Val, 12, 4);
4588 unsigned Rm = fieldFromInstruction(Val, 0, 4);
4589 Rm |= (fieldFromInstruction(Val, 23, 1) << 4);
4590 unsigned Cond = fieldFromInstruction(Val, 28, 4);
Silviu Barangab7c2ed62012-03-22 13:24:43 +00004591
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004592 if (fieldFromInstruction(Val, 8, 4) != 0 || Rn == Rt)
Silviu Barangab7c2ed62012-03-22 13:24:43 +00004593 S = MCDisassembler::SoftFail;
4594
4595 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)))
4596 return MCDisassembler::Fail;
4597 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
4598 return MCDisassembler::Fail;
4599 if (!Check(S, DecodeAddrMode7Operand(Inst, Rn, Address, Decoder)))
4600 return MCDisassembler::Fail;
4601 if (!Check(S, DecodePostIdxReg(Inst, Rm, Address, Decoder)))
4602 return MCDisassembler::Fail;
4603 if (!Check(S, DecodePredicateOperand(Inst, Cond, Address, Decoder)))
4604 return MCDisassembler::Fail;
4605
4606 return S;
4607}
4608
Silviu Barangafa1ebc62012-04-18 13:12:50 +00004609static DecodeStatus DecodeMRRC2(llvm::MCInst &Inst, unsigned Val,
4610 uint64_t Address, const void *Decoder) {
4611
4612 DecodeStatus S = MCDisassembler::Success;
4613
Jim Grosbachfc1a1612012-08-14 19:06:05 +00004614 unsigned CRm = fieldFromInstruction(Val, 0, 4);
4615 unsigned opc1 = fieldFromInstruction(Val, 4, 4);
4616 unsigned cop = fieldFromInstruction(Val, 8, 4);
4617 unsigned Rt = fieldFromInstruction(Val, 12, 4);
4618 unsigned Rt2 = fieldFromInstruction(Val, 16, 4);
Silviu Barangafa1ebc62012-04-18 13:12:50 +00004619
4620 if ((cop & ~0x1) == 0xa)
4621 return MCDisassembler::Fail;
4622
4623 if (Rt == Rt2)
4624 S = MCDisassembler::SoftFail;
4625
4626 Inst.addOperand(MCOperand::CreateImm(cop));
4627 Inst.addOperand(MCOperand::CreateImm(opc1));
4628 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)))
4629 return MCDisassembler::Fail;
4630 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder)))
4631 return MCDisassembler::Fail;
4632 Inst.addOperand(MCOperand::CreateImm(CRm));
4633
4634 return S;
4635}
4636