blob: 81a61fe96462de793410d0f723d56b2a2576c94f [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
Owen Anderson8d7d2e12011-08-09 20:55:18 +000012#include "MCTargetDesc/ARMAddressingModes.h"
Kevin Enderby9e5887b2011-10-04 22:44:48 +000013#include "MCTargetDesc/ARMMCExpr.h"
Owen Anderson8d7d2e12011-08-09 20:55:18 +000014#include "MCTargetDesc/ARMBaseInfo.h"
Sean Callanan9899f702010-04-13 21:21:57 +000015#include "llvm/MC/EDInstInfo.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000016#include "llvm/MC/MCInst.h"
Benjamin Kramereea66f62011-11-11 12:39:41 +000017#include "llvm/MC/MCInstrDesc.h"
Owen Anderson8d7d2e12011-08-09 20:55:18 +000018#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCContext.h"
Owen Andersona1c11002011-09-01 23:35:51 +000020#include "llvm/MC/MCDisassembler.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"
23#include "llvm/Support/MemoryObject.h"
24#include "llvm/Support/ErrorHandling.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000025#include "llvm/Support/TargetRegistry.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000026#include "llvm/Support/raw_ostream.h"
Richard Bartonf4478f92012-04-24 11:13:20 +000027#include <vector>
Johnny Chenb68a3ee2010-04-02 22:27:38 +000028
James Molloyc047dca2011-09-01 18:02:14 +000029using namespace llvm;
Owen Anderson83e3f672011-08-17 17:44:15 +000030
Owen Andersona6804442011-09-01 23:23:50 +000031typedef MCDisassembler::DecodeStatus DecodeStatus;
32
Owen Andersona1c11002011-09-01 23:35:51 +000033namespace {
Richard Bartonf4478f92012-04-24 11:13:20 +000034 // Handles the condition code status of instructions in IT blocks
35 class ITStatus
36 {
37 public:
38 // Returns the condition code for instruction in IT block
39 unsigned getITCC() {
40 unsigned CC = ARMCC::AL;
41 if (instrInITBlock())
42 CC = ITStates.back();
43 return CC;
44 }
45
46 // Advances the IT block state to the next T or E
47 void advanceITState() {
48 ITStates.pop_back();
49 }
50
51 // Returns true if the current instruction is in an IT block
52 bool instrInITBlock() {
53 return !ITStates.empty();
54 }
55
56 // Returns true if current instruction is the last instruction in an IT block
57 bool instrLastInITBlock() {
58 return ITStates.size() == 1;
59 }
60
61 // Called when decoding an IT instruction. Sets the IT state for the following
62 // instructions that for the IT block. Firstcond and Mask correspond to the
63 // fields in the IT instruction encoding.
64 void setITState(char Firstcond, char Mask) {
65 // (3 - the number of trailing zeros) is the number of then / else.
66 unsigned CondBit0 = Mask >> 4 & 1;
67 unsigned NumTZ = CountTrailingZeros_32(Mask);
68 unsigned char CCBits = static_cast<unsigned char>(Firstcond & 0xf);
69 assert(NumTZ <= 3 && "Invalid IT mask!");
70 // push condition codes onto the stack the correct order for the pops
71 for (unsigned Pos = NumTZ+1; Pos <= 3; ++Pos) {
72 bool T = ((Mask >> Pos) & 1) == CondBit0;
73 if (T)
74 ITStates.push_back(CCBits);
75 else
76 ITStates.push_back(CCBits ^ 1);
77 }
78 ITStates.push_back(CCBits);
79 }
80
81 private:
82 std::vector<unsigned char> ITStates;
83 };
84}
85
86namespace {
Owen Andersona1c11002011-09-01 23:35:51 +000087/// ARMDisassembler - ARM disassembler for all ARM platforms.
88class ARMDisassembler : public MCDisassembler {
89public:
90 /// Constructor - Initializes the disassembler.
91 ///
James Molloyb9505852011-09-07 17:24:38 +000092 ARMDisassembler(const MCSubtargetInfo &STI) :
93 MCDisassembler(STI) {
Owen Andersona1c11002011-09-01 23:35:51 +000094 }
95
96 ~ARMDisassembler() {
97 }
98
99 /// getInstruction - See MCDisassembler.
100 DecodeStatus getInstruction(MCInst &instr,
101 uint64_t &size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000102 const MemoryObject &region,
Owen Andersona1c11002011-09-01 23:35:51 +0000103 uint64_t address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000104 raw_ostream &vStream,
105 raw_ostream &cStream) const;
Owen Andersona1c11002011-09-01 23:35:51 +0000106
107 /// getEDInfo - See MCDisassembler.
Benjamin Kramer88b6fc02012-02-11 14:51:07 +0000108 const EDInstInfo *getEDInfo() const;
Owen Andersona1c11002011-09-01 23:35:51 +0000109private:
110};
111
112/// ThumbDisassembler - Thumb disassembler for all Thumb platforms.
113class ThumbDisassembler : public MCDisassembler {
114public:
115 /// Constructor - Initializes the disassembler.
116 ///
James Molloyb9505852011-09-07 17:24:38 +0000117 ThumbDisassembler(const MCSubtargetInfo &STI) :
118 MCDisassembler(STI) {
Owen Andersona1c11002011-09-01 23:35:51 +0000119 }
120
121 ~ThumbDisassembler() {
122 }
123
124 /// getInstruction - See MCDisassembler.
125 DecodeStatus getInstruction(MCInst &instr,
126 uint64_t &size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000127 const MemoryObject &region,
Owen Andersona1c11002011-09-01 23:35:51 +0000128 uint64_t address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000129 raw_ostream &vStream,
130 raw_ostream &cStream) const;
Owen Andersona1c11002011-09-01 23:35:51 +0000131
132 /// getEDInfo - See MCDisassembler.
Benjamin Kramer88b6fc02012-02-11 14:51:07 +0000133 const EDInstInfo *getEDInfo() const;
Owen Andersona1c11002011-09-01 23:35:51 +0000134private:
Richard Bartonf4478f92012-04-24 11:13:20 +0000135 mutable ITStatus ITBlock;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000136 DecodeStatus AddThumbPredicate(MCInst&) const;
Owen Andersona1c11002011-09-01 23:35:51 +0000137 void UpdateThumbVFPPredicate(MCInst&) const;
138};
139}
140
Owen Andersona6804442011-09-01 23:23:50 +0000141static bool Check(DecodeStatus &Out, DecodeStatus In) {
James Molloyc047dca2011-09-01 18:02:14 +0000142 switch (In) {
143 case MCDisassembler::Success:
144 // Out stays the same.
145 return true;
146 case MCDisassembler::SoftFail:
147 Out = In;
148 return true;
149 case MCDisassembler::Fail:
150 Out = In;
151 return false;
152 }
David Blaikie4d6ccb52012-01-20 21:51:11 +0000153 llvm_unreachable("Invalid DecodeStatus!");
James Molloyc047dca2011-09-01 18:02:14 +0000154}
Owen Anderson83e3f672011-08-17 17:44:15 +0000155
James Molloya5d58562011-09-07 19:42:28 +0000156
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000157// Forward declare these because the autogenerated code will reference them.
158// Definitions are further down.
Craig Topperc89c7442012-03-27 07:21:54 +0000159static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000160 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000161static DecodeStatus DecodeGPRnopcRegisterClass(MCInst &Inst,
Jim Grosbachc4057822011-08-17 21:58:18 +0000162 unsigned RegNo, uint64_t Address,
163 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000164static DecodeStatus DecodetGPRRegisterClass(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 DecodetcGPRRegisterClass(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 DecoderGPRRegisterClass(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 DecodeSPRRegisterClass(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 DecodeDPRRegisterClass(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_8RegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000175 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000176static DecodeStatus DecodeDPR_VFP2RegisterClass(MCInst &Inst,
Jim Grosbachc4057822011-08-17 21:58:18 +0000177 unsigned RegNo,
178 uint64_t Address,
179 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000180static DecodeStatus DecodeQPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000181 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000182static DecodeStatus DecodeDPairRegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbach28f08c92012-03-05 19:33:30 +0000183 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000184static DecodeStatus DecodeDPairSpacedRegisterClass(MCInst &Inst,
Jim Grosbachc3384c92012-03-05 21:43:40 +0000185 unsigned RegNo, uint64_t Address,
186 const void *Decoder);
Johnny Chen270159f2010-08-12 01:40:54 +0000187
Craig Topperc89c7442012-03-27 07:21:54 +0000188static DecodeStatus DecodePredicateOperand(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 DecodeCCOutOperand(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 DecodeSOImmOperand(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 DecodeRegListOperand(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 DecodeSPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000197 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000198static DecodeStatus DecodeDPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000199 uint64_t Address, const void *Decoder);
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000200
Craig Topperc89c7442012-03-27 07:21:54 +0000201static DecodeStatus DecodeBitfieldMaskOperand(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 DecodeCopMemInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000204 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000205static DecodeStatus DecodeAddrMode2IdxInstruction(MCInst &Inst,
Jim Grosbachc4057822011-08-17 21:58:18 +0000206 unsigned Insn,
207 uint64_t Address,
208 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000209static DecodeStatus DecodeSORegMemOperand(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 DecodeAddrMode3Instruction(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 DecodeSORegImmOperand(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000214 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000215static DecodeStatus DecodeSORegRegOperand(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000216 uint64_t Address, const void *Decoder);
217
Craig Topperc89c7442012-03-27 07:21:54 +0000218static DecodeStatus DecodeMemMultipleWritebackInstruction(MCInst & Inst,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000219 unsigned Insn,
220 uint64_t Adddress,
221 const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000222static DecodeStatus DecodeT2MOVTWInstruction(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 DecodeArmMOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000225 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000226static DecodeStatus DecodeSMLAInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000227 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000228static DecodeStatus DecodeCPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson35008c22011-08-09 23:05:39 +0000229 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000230static DecodeStatus DecodeT2CPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson6153a032011-08-23 17:45:18 +0000231 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000232static DecodeStatus DecodeAddrModeImm12Operand(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 DecodeAddrMode5Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000235 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000236static DecodeStatus DecodeAddrMode7Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000237 uint64_t Address, const void *Decoder);
Kevin Enderby2a7d3a92012-04-12 23:13:34 +0000238static DecodeStatus DecodeT2BInstruction(MCInst &Inst, unsigned Insn,
239 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000240static DecodeStatus DecodeBranchImmInstruction(MCInst &Inst,unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000241 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000242static DecodeStatus DecodeAddrMode6Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000243 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000244static DecodeStatus DecodeVLDInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000245 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000246static DecodeStatus DecodeVSTInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000247 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000248static DecodeStatus DecodeVLD1DupInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000249 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000250static DecodeStatus DecodeVLD2DupInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000251 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000252static DecodeStatus DecodeVLD3DupInstruction(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 DecodeVLD4DupInstruction(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 DecodeNEONModImmInstruction(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 DecodeVSHLMaxInstruction(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 DecodeShiftRight8Imm(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 DecodeShiftRight16Imm(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 DecodeShiftRight32Imm(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 DecodeShiftRight64Imm(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 DecodeTBLInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000269 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000270static DecodeStatus DecodePostIdxReg(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000271 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000272static DecodeStatus DecodeCoprocessor(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000273 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000274static DecodeStatus DecodeMemBarrierOption(MCInst &Inst, unsigned Insn,
Owen Andersonc36481c2011-08-09 23:25:42 +0000275 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000276static DecodeStatus DecodeMSRMask(MCInst &Inst, unsigned Insn,
Owen Anderson26d2f0a2011-08-11 20:21:46 +0000277 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000278static DecodeStatus DecodeDoubleRegLoad(MCInst &Inst, unsigned Insn,
Owen Andersoncbfc0442011-08-11 21:34:58 +0000279 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000280static DecodeStatus DecodeDoubleRegStore(MCInst &Inst, unsigned Insn,
Owen Anderson3f3570a2011-08-12 17:58:32 +0000281 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000282static DecodeStatus DecodeLDRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +0000283 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000284static DecodeStatus DecodeLDRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +0000285 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000286static DecodeStatus DecodeSTRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +0000287 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000288static DecodeStatus DecodeSTRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +0000289 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000290static DecodeStatus DecodeVLD1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000291 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000292static DecodeStatus DecodeVLD2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000293 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000294static DecodeStatus DecodeVLD3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +0000295 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000296static DecodeStatus DecodeVLD4LN(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 DecodeVST1LN(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 DecodeVST2LN(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 DecodeVST3LN(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 DecodeVST4LN(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 DecodeVMOVSRR(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +0000307 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000308static DecodeStatus DecodeVMOVRRS(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +0000309 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000310static DecodeStatus DecodeSwap(MCInst &Inst, unsigned Insn,
Owen Andersoncb9fed62011-10-28 18:02:13 +0000311 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000312static DecodeStatus DecodeVCVTD(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +0000313 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000314static DecodeStatus DecodeVCVTQ(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +0000315 uint64_t Address, const void *Decoder);
316
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000317
Craig Topperc89c7442012-03-27 07:21:54 +0000318static DecodeStatus DecodeThumbAddSpecialReg(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000319 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000320static DecodeStatus DecodeThumbBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000321 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000322static DecodeStatus DecodeT2BROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000323 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000324static DecodeStatus DecodeThumbCmpBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000325 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000326static DecodeStatus DecodeThumbAddrModeRR(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000327 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000328static DecodeStatus DecodeThumbAddrModeIS(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 DecodeThumbAddrModePC(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 DecodeThumbAddrModeSP(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 DecodeT2AddrModeSOReg(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 DecodeT2LoadShift(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 DecodeT2Imm8S4(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 DecodeT2AddrModeImm8s4(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 DecodeT2AddrModeImm0_1020s4(MCInst &Inst,unsigned Val,
Jim Grosbachb6aed502011-09-09 18:37:27 +0000343 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000344static DecodeStatus DecodeT2Imm8(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 DecodeT2AddrModeImm8(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 DecodeThumbAddSPImm(MCInst &Inst, uint16_t Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000349 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000350static DecodeStatus DecodeThumbAddSPReg(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000351 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000352static DecodeStatus DecodeThumbCPS(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000353 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000354static DecodeStatus DecodeThumbBLXOffset(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000355 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000356static DecodeStatus DecodeT2AddrModeImm12(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000357 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000358static DecodeStatus DecodeThumbTableBranch(MCInst &Inst, unsigned Val,
Jim Grosbach7f739be2011-09-19 22:21:13 +0000359 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000360static DecodeStatus DecodeThumb2BCCInstruction(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000361 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000362static DecodeStatus DecodeT2SOImm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000363 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000364static DecodeStatus DecodeThumbBCCTargetOperand(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 DecodeThumbBLTargetOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000367 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000368static DecodeStatus DecodeIT(MCInst &Inst, unsigned Val,
Owen Andersonf4408202011-08-24 22:40:22 +0000369 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000370static DecodeStatus DecodeT2LDRDPreInstruction(MCInst &Inst,unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +0000371 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000372static DecodeStatus DecodeT2STRDPreInstruction(MCInst &Inst,unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +0000373 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000374static DecodeStatus DecodeT2Adr(MCInst &Inst, unsigned Val,
Owen Anderson08fef882011-09-09 22:24:36 +0000375 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000376static DecodeStatus DecodeT2LdStPre(MCInst &Inst, unsigned Val,
Owen Andersona3157b42011-09-12 18:56:30 +0000377 uint64_t Address, const void *Decoder);
Craig Topperc89c7442012-03-27 07:21:54 +0000378static DecodeStatus DecodeT2ShifterImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson0afa0092011-09-26 21:06:22 +0000379 uint64_t Address, const void *Decoder);
380
Craig Topperc89c7442012-03-27 07:21:54 +0000381static DecodeStatus DecodeLDR(MCInst &Inst, unsigned Val,
Silviu Barangab7c2ed62012-03-22 13:24:43 +0000382 uint64_t Address, const void *Decoder);
Silviu Barangafa1ebc62012-04-18 13:12:50 +0000383static DecodeStatus DecodeMRRC2(llvm::MCInst &Inst, unsigned Val,
384 uint64_t Address, const void *Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000385#include "ARMGenDisassemblerTables.inc"
386#include "ARMGenInstrInfo.inc"
Oscar Fuentes38e13902010-09-28 11:48:19 +0000387#include "ARMGenEDInfo.inc"
Sean Callanan9899f702010-04-13 21:21:57 +0000388
James Molloyb9505852011-09-07 17:24:38 +0000389static MCDisassembler *createARMDisassembler(const Target &T, const MCSubtargetInfo &STI) {
390 return new ARMDisassembler(STI);
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000391}
392
James Molloyb9505852011-09-07 17:24:38 +0000393static MCDisassembler *createThumbDisassembler(const Target &T, const MCSubtargetInfo &STI) {
394 return new ThumbDisassembler(STI);
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000395}
396
Benjamin Kramer88b6fc02012-02-11 14:51:07 +0000397const EDInstInfo *ARMDisassembler::getEDInfo() const {
Sean Callanan9899f702010-04-13 21:21:57 +0000398 return instInfoARM;
399}
400
Benjamin Kramer88b6fc02012-02-11 14:51:07 +0000401const EDInstInfo *ThumbDisassembler::getEDInfo() const {
Sean Callanan9899f702010-04-13 21:21:57 +0000402 return instInfoARM;
403}
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000404
Owen Andersona6804442011-09-01 23:23:50 +0000405DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000406 const MemoryObject &Region,
Jim Grosbachc4057822011-08-17 21:58:18 +0000407 uint64_t Address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000408 raw_ostream &os,
409 raw_ostream &cs) const {
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000410 CommentStream = &cs;
411
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000412 uint8_t bytes[4];
413
James Molloya5d58562011-09-07 19:42:28 +0000414 assert(!(STI.getFeatureBits() & ARM::ModeThumb) &&
415 "Asked to disassemble an ARM instruction but Subtarget is in Thumb mode!");
416
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000417 // We want to read exactly 4 bytes of data.
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000418 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
419 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000420 return MCDisassembler::Fail;
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000421 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000422
423 // Encoded as a small-endian 32-bit word in the stream.
424 uint32_t insn = (bytes[3] << 24) |
425 (bytes[2] << 16) |
426 (bytes[1] << 8) |
427 (bytes[0] << 0);
428
429 // Calling the auto-generated decoder function.
James Molloya5d58562011-09-07 19:42:28 +0000430 DecodeStatus result = decodeARMInstruction32(MI, insn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000431 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000432 Size = 4;
Owen Anderson83e3f672011-08-17 17:44:15 +0000433 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000434 }
435
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000436 // VFP and NEON instructions, similarly, are shared between ARM
437 // and Thumb modes.
438 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000439 result = decodeVFPInstruction32(MI, insn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000440 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000441 Size = 4;
Owen Anderson83e3f672011-08-17 17:44:15 +0000442 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000443 }
444
445 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000446 result = decodeNEONDataInstruction32(MI, insn, Address, 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();
James Molloya5d58562011-09-07 19:42:28 +0000457 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000458 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000459 Size = 4;
Owen Anderson8533eba2011-08-10 19:01:10 +0000460 // Add a fake predicate operand, because we share these instruction
461 // definitions with Thumb2 where these instructions are predicable.
Owen Andersona6804442011-09-01 23:23:50 +0000462 if (!DecodePredicateOperand(MI, 0xE, Address, this))
463 return MCDisassembler::Fail;
Owen Anderson83e3f672011-08-17 17:44:15 +0000464 return result;
Owen Anderson8533eba2011-08-10 19:01:10 +0000465 }
466
467 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000468 result = decodeNEONDupInstruction32(MI, insn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000469 if (result != MCDisassembler::Fail) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000470 Size = 4;
471 // Add a fake predicate operand, because we share these instruction
472 // definitions with Thumb2 where these instructions are predicable.
Owen Andersona6804442011-09-01 23:23:50 +0000473 if (!DecodePredicateOperand(MI, 0xE, Address, this))
474 return MCDisassembler::Fail;
Owen Anderson83e3f672011-08-17 17:44:15 +0000475 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000476 }
477
478 MI.clear();
479
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000480 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000481 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000482}
483
484namespace llvm {
Benjamin Kramer1a2f9882011-10-22 16:50:00 +0000485extern const MCInstrDesc ARMInsts[];
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000486}
487
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000488/// tryAddingSymbolicOperand - trys to add a symbolic operand in place of the
489/// immediate Value in the MCInst. The immediate Value has had any PC
490/// adjustment made by the caller. If the instruction is a branch instruction
491/// then isBranch is true, else false. If the getOpInfo() function was set as
492/// part of the setupForSymbolicDisassembly() call then that function is called
493/// to get any symbolic information at the Address for this instruction. If
494/// that returns non-zero then the symbolic information it returns is used to
495/// create an MCExpr and that is added as an operand to the MCInst. If
496/// getOpInfo() returns zero and isBranch is true then a symbol look up for
497/// Value is done and if a symbol is found an MCExpr is created with that, else
498/// an MCExpr with Value is created. This function returns true if it adds an
499/// operand to the MCInst and false otherwise.
500static bool tryAddingSymbolicOperand(uint64_t Address, int32_t Value,
501 bool isBranch, uint64_t InstSize,
502 MCInst &MI, const void *Decoder) {
503 const MCDisassembler *Dis = static_cast<const MCDisassembler*>(Decoder);
504 LLVMOpInfoCallback getOpInfo = Dis->getLLVMOpInfoCallback();
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000505 struct LLVMOpInfo1 SymbolicOp;
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000506 memset(&SymbolicOp, '\0', sizeof(struct LLVMOpInfo1));
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000507 SymbolicOp.Value = Value;
508 void *DisInfo = Dis->getDisInfoBlock();
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000509
510 if (!getOpInfo ||
511 !getOpInfo(DisInfo, Address, 0 /* Offset */, InstSize, 1, &SymbolicOp)) {
512 // Clear SymbolicOp.Value from above and also all other fields.
513 memset(&SymbolicOp, '\0', sizeof(struct LLVMOpInfo1));
514 LLVMSymbolLookupCallback SymbolLookUp = Dis->getLLVMSymbolLookupCallback();
515 if (!SymbolLookUp)
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000516 return false;
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000517 uint64_t ReferenceType;
518 if (isBranch)
519 ReferenceType = LLVMDisassembler_ReferenceType_In_Branch;
520 else
521 ReferenceType = LLVMDisassembler_ReferenceType_InOut_None;
522 const char *ReferenceName;
523 const char *Name = SymbolLookUp(DisInfo, Value, &ReferenceType, Address,
524 &ReferenceName);
525 if (Name) {
526 SymbolicOp.AddSymbol.Name = Name;
527 SymbolicOp.AddSymbol.Present = true;
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000528 }
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000529 // For branches always create an MCExpr so it gets printed as hex address.
530 else if (isBranch) {
531 SymbolicOp.Value = Value;
532 }
533 if(ReferenceType == LLVMDisassembler_ReferenceType_Out_SymbolStub)
534 (*Dis->CommentStream) << "symbol stub for: " << ReferenceName;
535 if (!Name && !isBranch)
536 return false;
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000537 }
538
539 MCContext *Ctx = Dis->getMCContext();
540 const MCExpr *Add = NULL;
541 if (SymbolicOp.AddSymbol.Present) {
542 if (SymbolicOp.AddSymbol.Name) {
543 StringRef Name(SymbolicOp.AddSymbol.Name);
544 MCSymbol *Sym = Ctx->GetOrCreateSymbol(Name);
545 Add = MCSymbolRefExpr::Create(Sym, *Ctx);
546 } else {
547 Add = MCConstantExpr::Create(SymbolicOp.AddSymbol.Value, *Ctx);
548 }
549 }
550
551 const MCExpr *Sub = NULL;
552 if (SymbolicOp.SubtractSymbol.Present) {
553 if (SymbolicOp.SubtractSymbol.Name) {
554 StringRef Name(SymbolicOp.SubtractSymbol.Name);
555 MCSymbol *Sym = Ctx->GetOrCreateSymbol(Name);
556 Sub = MCSymbolRefExpr::Create(Sym, *Ctx);
557 } else {
558 Sub = MCConstantExpr::Create(SymbolicOp.SubtractSymbol.Value, *Ctx);
559 }
560 }
561
562 const MCExpr *Off = NULL;
563 if (SymbolicOp.Value != 0)
564 Off = MCConstantExpr::Create(SymbolicOp.Value, *Ctx);
565
566 const MCExpr *Expr;
567 if (Sub) {
568 const MCExpr *LHS;
569 if (Add)
570 LHS = MCBinaryExpr::CreateSub(Add, Sub, *Ctx);
571 else
572 LHS = MCUnaryExpr::CreateMinus(Sub, *Ctx);
573 if (Off != 0)
574 Expr = MCBinaryExpr::CreateAdd(LHS, Off, *Ctx);
575 else
576 Expr = LHS;
577 } else if (Add) {
578 if (Off != 0)
579 Expr = MCBinaryExpr::CreateAdd(Add, Off, *Ctx);
580 else
581 Expr = Add;
582 } else {
583 if (Off != 0)
584 Expr = Off;
585 else
586 Expr = MCConstantExpr::Create(0, *Ctx);
587 }
588
589 if (SymbolicOp.VariantKind == LLVMDisassembler_VariantKind_ARM_HI16)
590 MI.addOperand(MCOperand::CreateExpr(ARMMCExpr::CreateUpper16(Expr, *Ctx)));
591 else if (SymbolicOp.VariantKind == LLVMDisassembler_VariantKind_ARM_LO16)
592 MI.addOperand(MCOperand::CreateExpr(ARMMCExpr::CreateLower16(Expr, *Ctx)));
593 else if (SymbolicOp.VariantKind == LLVMDisassembler_VariantKind_None)
594 MI.addOperand(MCOperand::CreateExpr(Expr));
Jim Grosbach01817c32011-10-20 17:28:20 +0000595 else
Craig Topperbc219812012-02-07 02:50:20 +0000596 llvm_unreachable("bad SymbolicOp.VariantKind");
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000597
598 return true;
599}
600
601/// tryAddingPcLoadReferenceComment - trys to add a comment as to what is being
602/// referenced by a load instruction with the base register that is the Pc.
603/// These can often be values in a literal pool near the Address of the
604/// instruction. The Address of the instruction and its immediate Value are
605/// used as a possible literal pool entry. The SymbolLookUp call back will
606/// return the name of a symbol referenced by the the literal pool's entry if
607/// the referenced address is that of a symbol. Or it will return a pointer to
608/// a literal 'C' string if the referenced address of the literal pool's entry
609/// is an address into a section with 'C' string literals.
610static void tryAddingPcLoadReferenceComment(uint64_t Address, int Value,
Kevin Enderbyb80d5712012-02-23 18:18:17 +0000611 const void *Decoder) {
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000612 const MCDisassembler *Dis = static_cast<const MCDisassembler*>(Decoder);
613 LLVMSymbolLookupCallback SymbolLookUp = Dis->getLLVMSymbolLookupCallback();
614 if (SymbolLookUp) {
615 void *DisInfo = Dis->getDisInfoBlock();
616 uint64_t ReferenceType;
617 ReferenceType = LLVMDisassembler_ReferenceType_In_PCrel_Load;
618 const char *ReferenceName;
619 (void)SymbolLookUp(DisInfo, Value, &ReferenceType, Address, &ReferenceName);
620 if(ReferenceType == LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr ||
621 ReferenceType == LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr)
622 (*Dis->CommentStream) << "literal pool for: " << ReferenceName;
623 }
624}
625
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000626// Thumb1 instructions don't have explicit S bits. Rather, they
627// implicitly set CPSR. Since it's not represented in the encoding, the
628// auto-generated decoder won't inject the CPSR operand. We need to fix
629// that as a post-pass.
630static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
631 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000632 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000633 MCInst::iterator I = MI.begin();
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000634 for (unsigned i = 0; i < NumOps; ++i, ++I) {
635 if (I == MI.end()) break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000636 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000637 if (i > 0 && OpInfo[i-1].isPredicate()) continue;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000638 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
639 return;
640 }
641 }
642
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000643 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000644}
645
646// Most Thumb instructions don't have explicit predicates in the
647// encoding, but rather get their predicates from IT context. We need
648// to fix up the predicate operands using this context information as a
649// post-pass.
Owen Andersond2fc31b2011-09-08 22:42:49 +0000650MCDisassembler::DecodeStatus
651ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000652 MCDisassembler::DecodeStatus S = Success;
653
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000654 // A few instructions actually have predicates encoded in them. Don't
655 // try to overwrite it if we're seeing one of those.
656 switch (MI.getOpcode()) {
657 case ARM::tBcc:
658 case ARM::t2Bcc:
Owen Andersond2fc31b2011-09-08 22:42:49 +0000659 case ARM::tCBZ:
660 case ARM::tCBNZ:
Owen Anderson9f666b52011-09-19 23:47:10 +0000661 case ARM::tCPS:
662 case ARM::t2CPS3p:
663 case ARM::t2CPS2p:
664 case ARM::t2CPS1p:
Owen Andersond9346fb2011-09-19 23:57:20 +0000665 case ARM::tMOVSr:
Owen Andersonc18e9402011-10-13 17:58:39 +0000666 case ARM::tSETEND:
Owen Anderson441462f2011-09-08 22:48:37 +0000667 // Some instructions (mostly conditional branches) are not
668 // allowed in IT blocks.
Richard Bartonf4478f92012-04-24 11:13:20 +0000669 if (ITBlock.instrInITBlock())
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000670 S = SoftFail;
671 else
672 return Success;
673 break;
674 case ARM::tB:
675 case ARM::t2B:
Owen Anderson04c78772011-09-19 22:34:23 +0000676 case ARM::t2TBB:
677 case ARM::t2TBH:
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000678 // Some instructions (mostly unconditional branches) can
679 // only appears at the end of, or outside of, an IT.
Richard Bartonf4478f92012-04-24 11:13:20 +0000680 if (ITBlock.instrInITBlock() && !ITBlock.instrLastInITBlock())
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000681 S = SoftFail;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000682 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000683 default:
684 break;
685 }
686
687 // If we're in an IT block, base the predicate on that. Otherwise,
688 // assume a predicate of AL.
689 unsigned CC;
Richard Bartonf4478f92012-04-24 11:13:20 +0000690 CC = ITBlock.getITCC();
691 if (CC == 0xF)
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000692 CC = ARMCC::AL;
Richard Bartonf4478f92012-04-24 11:13:20 +0000693 if (ITBlock.instrInITBlock())
694 ITBlock.advanceITState();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000695
696 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000697 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000698 MCInst::iterator I = MI.begin();
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000699 for (unsigned i = 0; i < NumOps; ++i, ++I) {
700 if (I == MI.end()) break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000701 if (OpInfo[i].isPredicate()) {
702 I = MI.insert(I, MCOperand::CreateImm(CC));
703 ++I;
704 if (CC == ARMCC::AL)
705 MI.insert(I, MCOperand::CreateReg(0));
706 else
707 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000708 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000709 }
710 }
711
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000712 I = MI.insert(I, MCOperand::CreateImm(CC));
713 ++I;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000714 if (CC == ARMCC::AL)
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000715 MI.insert(I, MCOperand::CreateReg(0));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000716 else
Owen Anderson0aa38ab2011-08-17 18:14:48 +0000717 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
Owen Andersond2fc31b2011-09-08 22:42:49 +0000718
Owen Anderson51f6a7a2011-09-09 21:48:23 +0000719 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000720}
721
722// Thumb VFP instructions are a special case. Because we share their
723// encodings between ARM and Thumb modes, and they are predicable in ARM
724// mode, the auto-generated decoder will give them an (incorrect)
725// predicate operand. We need to rewrite these operands based on the IT
726// context as a post-pass.
727void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
728 unsigned CC;
Richard Bartonf4478f92012-04-24 11:13:20 +0000729 CC = ITBlock.getITCC();
730 if (ITBlock.instrInITBlock())
731 ITBlock.advanceITState();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000732
733 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
734 MCInst::iterator I = MI.begin();
Owen Anderson12a1e3b2011-08-24 21:35:46 +0000735 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
736 for (unsigned i = 0; i < NumOps; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000737 if (OpInfo[i].isPredicate() ) {
738 I->setImm(CC);
739 ++I;
740 if (CC == ARMCC::AL)
741 I->setReg(0);
742 else
743 I->setReg(ARM::CPSR);
744 return;
745 }
746 }
747}
748
Owen Andersona6804442011-09-01 23:23:50 +0000749DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
Derek Schuffadef06a2012-02-29 01:09:06 +0000750 const MemoryObject &Region,
Jim Grosbachc4057822011-08-17 21:58:18 +0000751 uint64_t Address,
Owen Anderson98c5dda2011-09-15 23:38:46 +0000752 raw_ostream &os,
753 raw_ostream &cs) const {
Kevin Enderby9e5887b2011-10-04 22:44:48 +0000754 CommentStream = &cs;
755
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000756 uint8_t bytes[4];
757
James Molloya5d58562011-09-07 19:42:28 +0000758 assert((STI.getFeatureBits() & ARM::ModeThumb) &&
759 "Asked to disassemble in Thumb mode but Subtarget is in ARM mode!");
760
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000761 // We want to read exactly 2 bytes of data.
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000762 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1) {
763 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000764 return MCDisassembler::Fail;
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000765 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000766
767 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
James Molloya5d58562011-09-07 19:42:28 +0000768 DecodeStatus result = decodeThumbInstruction16(MI, insn16, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000769 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000770 Size = 2;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000771 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000772 return result;
Owen Anderson16280302011-08-16 23:45:44 +0000773 }
774
775 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000776 result = decodeThumbSBitInstruction16(MI, insn16, Address, this, STI);
Owen Anderson16280302011-08-16 23:45:44 +0000777 if (result) {
778 Size = 2;
Richard Bartonf4478f92012-04-24 11:13:20 +0000779 bool InITBlock = ITBlock.instrInITBlock();
Owen Andersond2fc31b2011-09-08 22:42:49 +0000780 Check(result, AddThumbPredicate(MI));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000781 AddThumb1SBit(MI, InITBlock);
Owen Anderson83e3f672011-08-17 17:44:15 +0000782 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000783 }
784
785 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000786 result = decodeThumb2Instruction16(MI, insn16, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000787 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000788 Size = 2;
Owen Anderson7011eee2011-10-06 23:33:11 +0000789
790 // Nested IT blocks are UNPREDICTABLE. Must be checked before we add
791 // the Thumb predicate.
Richard Bartonf4478f92012-04-24 11:13:20 +0000792 if (MI.getOpcode() == ARM::t2IT && ITBlock.instrInITBlock())
Owen Anderson7011eee2011-10-06 23:33:11 +0000793 result = MCDisassembler::SoftFail;
794
Owen Andersond2fc31b2011-09-08 22:42:49 +0000795 Check(result, AddThumbPredicate(MI));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000796
797 // If we find an IT instruction, we need to parse its condition
798 // code and mask operands so that we can apply them correctly
799 // to the subsequent instructions.
800 if (MI.getOpcode() == ARM::t2IT) {
Owen Anderson34626ac2011-09-14 21:06:21 +0000801
Richard Bartonf4478f92012-04-24 11:13:20 +0000802 unsigned Firstcond = MI.getOperand(0).getImm();
Owen Andersoneaca9282011-08-30 22:58:27 +0000803 unsigned Mask = MI.getOperand(1).getImm();
Richard Bartonf4478f92012-04-24 11:13:20 +0000804 ITBlock.setITState(Firstcond, Mask);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000805 }
806
Owen Anderson83e3f672011-08-17 17:44:15 +0000807 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000808 }
809
810 // We want to read exactly 4 bytes of data.
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000811 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
812 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000813 return MCDisassembler::Fail;
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000814 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000815
816 uint32_t insn32 = (bytes[3] << 8) |
817 (bytes[2] << 0) |
818 (bytes[1] << 24) |
819 (bytes[0] << 16);
820 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000821 result = decodeThumbInstruction32(MI, insn32, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000822 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000823 Size = 4;
Richard Bartonf4478f92012-04-24 11:13:20 +0000824 bool InITBlock = ITBlock.instrInITBlock();
Owen Andersond2fc31b2011-09-08 22:42:49 +0000825 Check(result, AddThumbPredicate(MI));
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000826 AddThumb1SBit(MI, InITBlock);
Owen Anderson83e3f672011-08-17 17:44:15 +0000827 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000828 }
829
830 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000831 result = decodeThumb2Instruction32(MI, insn32, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000832 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000833 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000834 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000835 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000836 }
837
838 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000839 result = decodeVFPInstruction32(MI, insn32, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000840 if (result != MCDisassembler::Fail) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000841 Size = 4;
842 UpdateThumbVFPPredicate(MI);
Owen Anderson83e3f672011-08-17 17:44:15 +0000843 return result;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000844 }
845
846 MI.clear();
James Molloya5d58562011-09-07 19:42:28 +0000847 result = decodeNEONDupInstruction32(MI, insn32, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000848 if (result != MCDisassembler::Fail) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000849 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000850 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000851 return result;
Owen Andersonef2865a2011-08-15 23:38:54 +0000852 }
853
854 if (fieldFromInstruction32(insn32, 24, 8) == 0xF9) {
855 MI.clear();
856 uint32_t NEONLdStInsn = insn32;
857 NEONLdStInsn &= 0xF0FFFFFF;
858 NEONLdStInsn |= 0x04000000;
James Molloya5d58562011-09-07 19:42:28 +0000859 result = decodeNEONLoadStoreInstruction32(MI, NEONLdStInsn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000860 if (result != MCDisassembler::Fail) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000861 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000862 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000863 return result;
Owen Andersonef2865a2011-08-15 23:38:54 +0000864 }
865 }
866
Owen Anderson8533eba2011-08-10 19:01:10 +0000867 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
Owen Andersonef2865a2011-08-15 23:38:54 +0000868 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000869 uint32_t NEONDataInsn = insn32;
870 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
871 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
872 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
James Molloya5d58562011-09-07 19:42:28 +0000873 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this, STI);
James Molloyc047dca2011-09-01 18:02:14 +0000874 if (result != MCDisassembler::Fail) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000875 Size = 4;
Owen Andersond2fc31b2011-09-08 22:42:49 +0000876 Check(result, AddThumbPredicate(MI));
Owen Anderson83e3f672011-08-17 17:44:15 +0000877 return result;
Owen Anderson8533eba2011-08-10 19:01:10 +0000878 }
879 }
880
Benjamin Kramer86ce8522011-08-26 18:21:36 +0000881 Size = 0;
James Molloyc047dca2011-09-01 18:02:14 +0000882 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000883}
884
885
886extern "C" void LLVMInitializeARMDisassembler() {
887 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
888 createARMDisassembler);
889 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
890 createThumbDisassembler);
891}
892
Craig Topperb78ca422012-03-11 07:16:55 +0000893static const uint16_t GPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000894 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
895 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
896 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
897 ARM::R12, ARM::SP, ARM::LR, ARM::PC
898};
899
Craig Topperc89c7442012-03-27 07:21:54 +0000900static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000901 uint64_t Address, const void *Decoder) {
902 if (RegNo > 15)
James Molloyc047dca2011-09-01 18:02:14 +0000903 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000904
905 unsigned Register = GPRDecoderTable[RegNo];
906 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +0000907 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000908}
909
Owen Andersona6804442011-09-01 23:23:50 +0000910static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +0000911DecodeGPRnopcRegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbachc4057822011-08-17 21:58:18 +0000912 uint64_t Address, const void *Decoder) {
Silviu Baranga5c062ad2012-03-20 15:54:56 +0000913 DecodeStatus S = MCDisassembler::Success;
914
915 if (RegNo == 15)
916 S = MCDisassembler::SoftFail;
917
918 Check(S, DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder));
919
920 return S;
Owen Anderson51c98052011-08-09 22:48:45 +0000921}
922
Craig Topperc89c7442012-03-27 07:21:54 +0000923static DecodeStatus DecodetGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000924 uint64_t Address, const void *Decoder) {
925 if (RegNo > 7)
James Molloyc047dca2011-09-01 18:02:14 +0000926 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000927 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
928}
929
Craig Topperc89c7442012-03-27 07:21:54 +0000930static DecodeStatus DecodetcGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000931 uint64_t Address, const void *Decoder) {
932 unsigned Register = 0;
933 switch (RegNo) {
934 case 0:
935 Register = ARM::R0;
936 break;
937 case 1:
938 Register = ARM::R1;
939 break;
940 case 2:
941 Register = ARM::R2;
942 break;
943 case 3:
944 Register = ARM::R3;
945 break;
946 case 9:
947 Register = ARM::R9;
948 break;
949 case 12:
950 Register = ARM::R12;
951 break;
952 default:
James Molloyc047dca2011-09-01 18:02:14 +0000953 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000954 }
955
956 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +0000957 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000958}
959
Craig Topperc89c7442012-03-27 07:21:54 +0000960static DecodeStatus DecoderGPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000961 uint64_t Address, const void *Decoder) {
James Molloyc047dca2011-09-01 18:02:14 +0000962 if (RegNo == 13 || RegNo == 15) return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000963 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
964}
965
Craig Topperb78ca422012-03-11 07:16:55 +0000966static const uint16_t SPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000967 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
968 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
969 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
970 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
971 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
972 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
973 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
974 ARM::S28, ARM::S29, ARM::S30, ARM::S31
975};
976
Craig Topperc89c7442012-03-27 07:21:54 +0000977static DecodeStatus DecodeSPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000978 uint64_t Address, const void *Decoder) {
979 if (RegNo > 31)
James Molloyc047dca2011-09-01 18:02:14 +0000980 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000981
982 unsigned Register = SPRDecoderTable[RegNo];
983 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +0000984 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000985}
986
Craig Topperb78ca422012-03-11 07:16:55 +0000987static const uint16_t DPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000988 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
989 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
990 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
991 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
992 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
993 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
994 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
995 ARM::D28, ARM::D29, ARM::D30, ARM::D31
996};
997
Craig Topperc89c7442012-03-27 07:21:54 +0000998static DecodeStatus DecodeDPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000999 uint64_t Address, const void *Decoder) {
1000 if (RegNo > 31)
James Molloyc047dca2011-09-01 18:02:14 +00001001 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001002
1003 unsigned Register = DPRDecoderTable[RegNo];
1004 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +00001005 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001006}
1007
Craig Topperc89c7442012-03-27 07:21:54 +00001008static DecodeStatus DecodeDPR_8RegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001009 uint64_t Address, const void *Decoder) {
1010 if (RegNo > 7)
James Molloyc047dca2011-09-01 18:02:14 +00001011 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001012 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
1013}
1014
Owen Andersona6804442011-09-01 23:23:50 +00001015static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00001016DecodeDPR_VFP2RegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbachc4057822011-08-17 21:58:18 +00001017 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001018 if (RegNo > 15)
James Molloyc047dca2011-09-01 18:02:14 +00001019 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001020 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
1021}
1022
Craig Topperb78ca422012-03-11 07:16:55 +00001023static const uint16_t QPRDecoderTable[] = {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001024 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
1025 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
1026 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
1027 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
1028};
1029
1030
Craig Topperc89c7442012-03-27 07:21:54 +00001031static DecodeStatus DecodeQPRRegisterClass(MCInst &Inst, unsigned RegNo,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001032 uint64_t Address, const void *Decoder) {
1033 if (RegNo > 31)
James Molloyc047dca2011-09-01 18:02:14 +00001034 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001035 RegNo >>= 1;
1036
1037 unsigned Register = QPRDecoderTable[RegNo];
1038 Inst.addOperand(MCOperand::CreateReg(Register));
James Molloyc047dca2011-09-01 18:02:14 +00001039 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001040}
1041
Craig Topperb78ca422012-03-11 07:16:55 +00001042static const uint16_t DPairDecoderTable[] = {
Jim Grosbach28f08c92012-03-05 19:33:30 +00001043 ARM::Q0, ARM::D1_D2, ARM::Q1, ARM::D3_D4, ARM::Q2, ARM::D5_D6,
1044 ARM::Q3, ARM::D7_D8, ARM::Q4, ARM::D9_D10, ARM::Q5, ARM::D11_D12,
1045 ARM::Q6, ARM::D13_D14, ARM::Q7, ARM::D15_D16, ARM::Q8, ARM::D17_D18,
1046 ARM::Q9, ARM::D19_D20, ARM::Q10, ARM::D21_D22, ARM::Q11, ARM::D23_D24,
1047 ARM::Q12, ARM::D25_D26, ARM::Q13, ARM::D27_D28, ARM::Q14, ARM::D29_D30,
1048 ARM::Q15
1049};
1050
Craig Topperc89c7442012-03-27 07:21:54 +00001051static DecodeStatus DecodeDPairRegisterClass(MCInst &Inst, unsigned RegNo,
Jim Grosbach28f08c92012-03-05 19:33:30 +00001052 uint64_t Address, const void *Decoder) {
1053 if (RegNo > 30)
1054 return MCDisassembler::Fail;
1055
1056 unsigned Register = DPairDecoderTable[RegNo];
1057 Inst.addOperand(MCOperand::CreateReg(Register));
1058 return MCDisassembler::Success;
1059}
1060
Craig Topperb78ca422012-03-11 07:16:55 +00001061static const uint16_t DPairSpacedDecoderTable[] = {
Jim Grosbachc3384c92012-03-05 21:43:40 +00001062 ARM::D0_D2, ARM::D1_D3, ARM::D2_D4, ARM::D3_D5,
1063 ARM::D4_D6, ARM::D5_D7, ARM::D6_D8, ARM::D7_D9,
1064 ARM::D8_D10, ARM::D9_D11, ARM::D10_D12, ARM::D11_D13,
1065 ARM::D12_D14, ARM::D13_D15, ARM::D14_D16, ARM::D15_D17,
1066 ARM::D16_D18, ARM::D17_D19, ARM::D18_D20, ARM::D19_D21,
1067 ARM::D20_D22, ARM::D21_D23, ARM::D22_D24, ARM::D23_D25,
1068 ARM::D24_D26, ARM::D25_D27, ARM::D26_D28, ARM::D27_D29,
1069 ARM::D28_D30, ARM::D29_D31
1070};
1071
Craig Topperc89c7442012-03-27 07:21:54 +00001072static DecodeStatus DecodeDPairSpacedRegisterClass(MCInst &Inst,
Jim Grosbachc3384c92012-03-05 21:43:40 +00001073 unsigned RegNo,
1074 uint64_t Address,
1075 const void *Decoder) {
1076 if (RegNo > 29)
1077 return MCDisassembler::Fail;
1078
1079 unsigned Register = DPairSpacedDecoderTable[RegNo];
1080 Inst.addOperand(MCOperand::CreateReg(Register));
1081 return MCDisassembler::Success;
1082}
1083
Craig Topperc89c7442012-03-27 07:21:54 +00001084static DecodeStatus DecodePredicateOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001085 uint64_t Address, const void *Decoder) {
James Molloyc047dca2011-09-01 18:02:14 +00001086 if (Val == 0xF) return MCDisassembler::Fail;
Owen Andersonbd9091c2011-08-09 21:07:45 +00001087 // AL predicate is not allowed on Thumb1 branches.
1088 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
James Molloyc047dca2011-09-01 18:02:14 +00001089 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001090 Inst.addOperand(MCOperand::CreateImm(Val));
1091 if (Val == ARMCC::AL) {
1092 Inst.addOperand(MCOperand::CreateReg(0));
1093 } else
1094 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
James Molloyc047dca2011-09-01 18:02:14 +00001095 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001096}
1097
Craig Topperc89c7442012-03-27 07:21:54 +00001098static DecodeStatus DecodeCCOutOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001099 uint64_t Address, const void *Decoder) {
1100 if (Val)
1101 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
1102 else
1103 Inst.addOperand(MCOperand::CreateReg(0));
James Molloyc047dca2011-09-01 18:02:14 +00001104 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001105}
1106
Craig Topperc89c7442012-03-27 07:21:54 +00001107static DecodeStatus DecodeSOImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001108 uint64_t Address, const void *Decoder) {
1109 uint32_t imm = Val & 0xFF;
1110 uint32_t rot = (Val & 0xF00) >> 7;
Eli Friedmanecb830e2011-10-13 23:36:06 +00001111 uint32_t rot_imm = (imm >> rot) | (imm << ((32-rot) & 0x1F));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001112 Inst.addOperand(MCOperand::CreateImm(rot_imm));
James Molloyc047dca2011-09-01 18:02:14 +00001113 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001114}
1115
Craig Topperc89c7442012-03-27 07:21:54 +00001116static DecodeStatus DecodeSORegImmOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001117 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001118 DecodeStatus S = MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001119
1120 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1121 unsigned type = fieldFromInstruction32(Val, 5, 2);
1122 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1123
1124 // Register-immediate
Owen Andersona6804442011-09-01 23:23:50 +00001125 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
1126 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001127
1128 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
1129 switch (type) {
1130 case 0:
1131 Shift = ARM_AM::lsl;
1132 break;
1133 case 1:
1134 Shift = ARM_AM::lsr;
1135 break;
1136 case 2:
1137 Shift = ARM_AM::asr;
1138 break;
1139 case 3:
1140 Shift = ARM_AM::ror;
1141 break;
1142 }
1143
1144 if (Shift == ARM_AM::ror && imm == 0)
1145 Shift = ARM_AM::rrx;
1146
1147 unsigned Op = Shift | (imm << 3);
1148 Inst.addOperand(MCOperand::CreateImm(Op));
1149
Owen Anderson83e3f672011-08-17 17:44:15 +00001150 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001151}
1152
Craig Topperc89c7442012-03-27 07:21:54 +00001153static DecodeStatus DecodeSORegRegOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001154 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001155 DecodeStatus S = MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001156
1157 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1158 unsigned type = fieldFromInstruction32(Val, 5, 2);
1159 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
1160
1161 // Register-register
Owen Andersona6804442011-09-01 23:23:50 +00001162 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
1163 return MCDisassembler::Fail;
1164 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder)))
1165 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001166
1167 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
1168 switch (type) {
1169 case 0:
1170 Shift = ARM_AM::lsl;
1171 break;
1172 case 1:
1173 Shift = ARM_AM::lsr;
1174 break;
1175 case 2:
1176 Shift = ARM_AM::asr;
1177 break;
1178 case 3:
1179 Shift = ARM_AM::ror;
1180 break;
1181 }
1182
1183 Inst.addOperand(MCOperand::CreateImm(Shift));
1184
Owen Anderson83e3f672011-08-17 17:44:15 +00001185 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001186}
1187
Craig Topperc89c7442012-03-27 07:21:54 +00001188static DecodeStatus DecodeRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001189 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001190 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001191
Owen Anderson921d01a2011-09-09 23:13:33 +00001192 bool writebackLoad = false;
1193 unsigned writebackReg = 0;
1194 switch (Inst.getOpcode()) {
1195 default:
1196 break;
1197 case ARM::LDMIA_UPD:
1198 case ARM::LDMDB_UPD:
1199 case ARM::LDMIB_UPD:
1200 case ARM::LDMDA_UPD:
1201 case ARM::t2LDMIA_UPD:
1202 case ARM::t2LDMDB_UPD:
1203 writebackLoad = true;
1204 writebackReg = Inst.getOperand(0).getReg();
1205 break;
1206 }
1207
Owen Anderson26d2f0a2011-08-11 20:21:46 +00001208 // Empty register lists are not allowed.
Owen Anderson244006d2011-11-02 17:46:18 +00001209 if (CountPopulation_32(Val) == 0) return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001210 for (unsigned i = 0; i < 16; ++i) {
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001211 if (Val & (1 << i)) {
Owen Andersona6804442011-09-01 23:23:50 +00001212 if (!Check(S, DecodeGPRRegisterClass(Inst, i, Address, Decoder)))
1213 return MCDisassembler::Fail;
Owen Anderson921d01a2011-09-09 23:13:33 +00001214 // Writeback not allowed if Rn is in the target list.
1215 if (writebackLoad && writebackReg == Inst.end()[-1].getReg())
1216 Check(S, MCDisassembler::SoftFail);
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001217 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001218 }
1219
Owen Anderson83e3f672011-08-17 17:44:15 +00001220 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001221}
1222
Craig Topperc89c7442012-03-27 07:21:54 +00001223static DecodeStatus DecodeSPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001224 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001225 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001226
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001227 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
1228 unsigned regs = Val & 0xFF;
1229
Owen Andersona6804442011-09-01 23:23:50 +00001230 if (!Check(S, DecodeSPRRegisterClass(Inst, Vd, Address, Decoder)))
1231 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001232 for (unsigned i = 0; i < (regs - 1); ++i) {
Owen Andersona6804442011-09-01 23:23:50 +00001233 if (!Check(S, DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder)))
1234 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001235 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001236
Owen Anderson83e3f672011-08-17 17:44:15 +00001237 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001238}
1239
Craig Topperc89c7442012-03-27 07:21:54 +00001240static DecodeStatus DecodeDPRRegListOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001241 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001242 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001243
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001244 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
1245 unsigned regs = (Val & 0xFF) / 2;
1246
Owen Andersona6804442011-09-01 23:23:50 +00001247 if (!Check(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)))
1248 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001249 for (unsigned i = 0; i < (regs - 1); ++i) {
Owen Andersona6804442011-09-01 23:23:50 +00001250 if (!Check(S, DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder)))
1251 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001252 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001253
Owen Anderson83e3f672011-08-17 17:44:15 +00001254 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001255}
1256
Craig Topperc89c7442012-03-27 07:21:54 +00001257static DecodeStatus DecodeBitfieldMaskOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001258 uint64_t Address, const void *Decoder) {
Owen Anderson10cbaab2011-08-10 17:36:48 +00001259 // This operand encodes a mask of contiguous zeros between a specified MSB
1260 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
1261 // the mask of all bits LSB-and-lower, and then xor them to create
Jim Grosbachc4057822011-08-17 21:58:18 +00001262 // the mask of that's all ones on [msb, lsb]. Finally we not it to
Owen Anderson10cbaab2011-08-10 17:36:48 +00001263 // create the final mask.
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001264 unsigned msb = fieldFromInstruction32(Val, 5, 5);
1265 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
Owen Anderson89db0f62011-09-16 22:29:48 +00001266
Owen Andersoncb775512011-09-16 23:30:01 +00001267 DecodeStatus S = MCDisassembler::Success;
1268 if (lsb > msb) Check(S, MCDisassembler::SoftFail);
1269
Owen Anderson8b227782011-09-16 23:04:48 +00001270 uint32_t msb_mask = 0xFFFFFFFF;
1271 if (msb != 31) msb_mask = (1U << (msb+1)) - 1;
1272 uint32_t lsb_mask = (1U << lsb) - 1;
Owen Anderson89db0f62011-09-16 22:29:48 +00001273
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001274 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
Owen Andersoncb775512011-09-16 23:30:01 +00001275 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001276}
1277
Craig Topperc89c7442012-03-27 07:21:54 +00001278static DecodeStatus DecodeCopMemInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001279 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001280 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001281
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001282 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1283 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
1284 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
1285 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
1286 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1287 unsigned U = fieldFromInstruction32(Insn, 23, 1);
1288
1289 switch (Inst.getOpcode()) {
1290 case ARM::LDC_OFFSET:
1291 case ARM::LDC_PRE:
1292 case ARM::LDC_POST:
1293 case ARM::LDC_OPTION:
1294 case ARM::LDCL_OFFSET:
1295 case ARM::LDCL_PRE:
1296 case ARM::LDCL_POST:
1297 case ARM::LDCL_OPTION:
1298 case ARM::STC_OFFSET:
1299 case ARM::STC_PRE:
1300 case ARM::STC_POST:
1301 case ARM::STC_OPTION:
1302 case ARM::STCL_OFFSET:
1303 case ARM::STCL_PRE:
1304 case ARM::STCL_POST:
1305 case ARM::STCL_OPTION:
Owen Anderson8a83f712011-09-07 21:10:42 +00001306 case ARM::t2LDC_OFFSET:
1307 case ARM::t2LDC_PRE:
1308 case ARM::t2LDC_POST:
1309 case ARM::t2LDC_OPTION:
1310 case ARM::t2LDCL_OFFSET:
1311 case ARM::t2LDCL_PRE:
1312 case ARM::t2LDCL_POST:
1313 case ARM::t2LDCL_OPTION:
1314 case ARM::t2STC_OFFSET:
1315 case ARM::t2STC_PRE:
1316 case ARM::t2STC_POST:
1317 case ARM::t2STC_OPTION:
1318 case ARM::t2STCL_OFFSET:
1319 case ARM::t2STCL_PRE:
1320 case ARM::t2STCL_POST:
1321 case ARM::t2STCL_OPTION:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001322 if (coproc == 0xA || coproc == 0xB)
James Molloyc047dca2011-09-01 18:02:14 +00001323 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001324 break;
1325 default:
1326 break;
1327 }
1328
1329 Inst.addOperand(MCOperand::CreateImm(coproc));
1330 Inst.addOperand(MCOperand::CreateImm(CRd));
Owen Andersona6804442011-09-01 23:23:50 +00001331 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1332 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001333
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001334 switch (Inst.getOpcode()) {
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001335 case ARM::t2LDC2_OFFSET:
1336 case ARM::t2LDC2L_OFFSET:
1337 case ARM::t2LDC2_PRE:
1338 case ARM::t2LDC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001339 case ARM::t2STC2_OFFSET:
1340 case ARM::t2STC2L_OFFSET:
1341 case ARM::t2STC2_PRE:
1342 case ARM::t2STC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001343 case ARM::LDC2_OFFSET:
1344 case ARM::LDC2L_OFFSET:
1345 case ARM::LDC2_PRE:
1346 case ARM::LDC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001347 case ARM::STC2_OFFSET:
1348 case ARM::STC2L_OFFSET:
1349 case ARM::STC2_PRE:
1350 case ARM::STC2L_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001351 case ARM::t2LDC_OFFSET:
1352 case ARM::t2LDCL_OFFSET:
1353 case ARM::t2LDC_PRE:
1354 case ARM::t2LDCL_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001355 case ARM::t2STC_OFFSET:
1356 case ARM::t2STCL_OFFSET:
1357 case ARM::t2STC_PRE:
1358 case ARM::t2STCL_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001359 case ARM::LDC_OFFSET:
1360 case ARM::LDCL_OFFSET:
1361 case ARM::LDC_PRE:
1362 case ARM::LDCL_PRE:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001363 case ARM::STC_OFFSET:
1364 case ARM::STCL_OFFSET:
1365 case ARM::STC_PRE:
1366 case ARM::STCL_PRE:
Jim Grosbach81b29282011-10-12 21:59:02 +00001367 imm = ARM_AM::getAM5Opc(U ? ARM_AM::add : ARM_AM::sub, imm);
1368 Inst.addOperand(MCOperand::CreateImm(imm));
1369 break;
1370 case ARM::t2LDC2_POST:
1371 case ARM::t2LDC2L_POST:
1372 case ARM::t2STC2_POST:
1373 case ARM::t2STC2L_POST:
1374 case ARM::LDC2_POST:
1375 case ARM::LDC2L_POST:
1376 case ARM::STC2_POST:
1377 case ARM::STC2L_POST:
1378 case ARM::t2LDC_POST:
1379 case ARM::t2LDCL_POST:
1380 case ARM::t2STC_POST:
1381 case ARM::t2STCL_POST:
1382 case ARM::LDC_POST:
1383 case ARM::LDCL_POST:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001384 case ARM::STC_POST:
1385 case ARM::STCL_POST:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001386 imm |= U << 8;
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001387 // fall through.
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001388 default:
Jim Grosbachc66e7af2011-10-12 20:54:17 +00001389 // The 'option' variant doesn't encode 'U' in the immediate since
1390 // the immediate is unsigned [0,255].
1391 Inst.addOperand(MCOperand::CreateImm(imm));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001392 break;
1393 }
1394
1395 switch (Inst.getOpcode()) {
1396 case ARM::LDC_OFFSET:
1397 case ARM::LDC_PRE:
1398 case ARM::LDC_POST:
1399 case ARM::LDC_OPTION:
1400 case ARM::LDCL_OFFSET:
1401 case ARM::LDCL_PRE:
1402 case ARM::LDCL_POST:
1403 case ARM::LDCL_OPTION:
1404 case ARM::STC_OFFSET:
1405 case ARM::STC_PRE:
1406 case ARM::STC_POST:
1407 case ARM::STC_OPTION:
1408 case ARM::STCL_OFFSET:
1409 case ARM::STCL_PRE:
1410 case ARM::STCL_POST:
1411 case ARM::STCL_OPTION:
Owen Andersona6804442011-09-01 23:23:50 +00001412 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1413 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001414 break;
1415 default:
1416 break;
1417 }
1418
Owen Anderson83e3f672011-08-17 17:44:15 +00001419 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001420}
1421
Owen Andersona6804442011-09-01 23:23:50 +00001422static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00001423DecodeAddrMode2IdxInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00001424 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001425 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001426
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001427 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1428 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1429 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1430 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
1431 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1432 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
1433 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1434 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1435
1436 // On stores, the writeback operand precedes Rt.
1437 switch (Inst.getOpcode()) {
1438 case ARM::STR_POST_IMM:
1439 case ARM::STR_POST_REG:
Owen Anderson508e1d32011-08-11 20:47:56 +00001440 case ARM::STRB_POST_IMM:
1441 case ARM::STRB_POST_REG:
Jim Grosbach342ebd52011-08-11 22:18:00 +00001442 case ARM::STRT_POST_REG:
1443 case ARM::STRT_POST_IMM:
Jim Grosbach10348e72011-08-11 20:04:56 +00001444 case ARM::STRBT_POST_REG:
1445 case ARM::STRBT_POST_IMM:
Owen Andersona6804442011-09-01 23:23:50 +00001446 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1447 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001448 break;
1449 default:
1450 break;
1451 }
1452
Owen Andersona6804442011-09-01 23:23:50 +00001453 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
1454 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001455
1456 // On loads, the writeback operand comes after Rt.
1457 switch (Inst.getOpcode()) {
1458 case ARM::LDR_POST_IMM:
1459 case ARM::LDR_POST_REG:
Owen Anderson508e1d32011-08-11 20:47:56 +00001460 case ARM::LDRB_POST_IMM:
1461 case ARM::LDRB_POST_REG:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001462 case ARM::LDRBT_POST_REG:
1463 case ARM::LDRBT_POST_IMM:
Jim Grosbach59999262011-08-10 23:43:54 +00001464 case ARM::LDRT_POST_REG:
1465 case ARM::LDRT_POST_IMM:
Owen Andersona6804442011-09-01 23:23:50 +00001466 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1467 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001468 break;
1469 default:
1470 break;
1471 }
1472
Owen Andersona6804442011-09-01 23:23:50 +00001473 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1474 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001475
1476 ARM_AM::AddrOpc Op = ARM_AM::add;
1477 if (!fieldFromInstruction32(Insn, 23, 1))
1478 Op = ARM_AM::sub;
1479
1480 bool writeback = (P == 0) || (W == 1);
1481 unsigned idx_mode = 0;
1482 if (P && writeback)
1483 idx_mode = ARMII::IndexModePre;
1484 else if (!P && writeback)
1485 idx_mode = ARMII::IndexModePost;
1486
Owen Andersona6804442011-09-01 23:23:50 +00001487 if (writeback && (Rn == 15 || Rn == Rt))
1488 S = MCDisassembler::SoftFail; // UNPREDICTABLE
Owen Anderson71156a62011-08-11 19:00:18 +00001489
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001490 if (reg) {
Owen Andersona6804442011-09-01 23:23:50 +00001491 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
1492 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001493 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
1494 switch( fieldFromInstruction32(Insn, 5, 2)) {
1495 case 0:
1496 Opc = ARM_AM::lsl;
1497 break;
1498 case 1:
1499 Opc = ARM_AM::lsr;
1500 break;
1501 case 2:
1502 Opc = ARM_AM::asr;
1503 break;
1504 case 3:
1505 Opc = ARM_AM::ror;
1506 break;
1507 default:
James Molloyc047dca2011-09-01 18:02:14 +00001508 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001509 }
1510 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1511 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1512
1513 Inst.addOperand(MCOperand::CreateImm(imm));
1514 } else {
1515 Inst.addOperand(MCOperand::CreateReg(0));
1516 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1517 Inst.addOperand(MCOperand::CreateImm(tmp));
1518 }
1519
Owen Andersona6804442011-09-01 23:23:50 +00001520 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1521 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001522
Owen Anderson83e3f672011-08-17 17:44:15 +00001523 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001524}
1525
Craig Topperc89c7442012-03-27 07:21:54 +00001526static DecodeStatus DecodeSORegMemOperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001527 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001528 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001529
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001530 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1531 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1532 unsigned type = fieldFromInstruction32(Val, 5, 2);
1533 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1534 unsigned U = fieldFromInstruction32(Val, 12, 1);
1535
Owen Anderson51157d22011-08-09 21:38:14 +00001536 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001537 switch (type) {
1538 case 0:
1539 ShOp = ARM_AM::lsl;
1540 break;
1541 case 1:
1542 ShOp = ARM_AM::lsr;
1543 break;
1544 case 2:
1545 ShOp = ARM_AM::asr;
1546 break;
1547 case 3:
1548 ShOp = ARM_AM::ror;
1549 break;
1550 }
1551
Owen Andersona6804442011-09-01 23:23:50 +00001552 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1553 return MCDisassembler::Fail;
1554 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
1555 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001556 unsigned shift;
1557 if (U)
1558 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1559 else
1560 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1561 Inst.addOperand(MCOperand::CreateImm(shift));
1562
Owen Anderson83e3f672011-08-17 17:44:15 +00001563 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001564}
1565
Owen Andersona6804442011-09-01 23:23:50 +00001566static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00001567DecodeAddrMode3Instruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00001568 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001569 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001570
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001571 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1572 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1573 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1574 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1575 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1576 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1577 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1578 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1579 unsigned P = fieldFromInstruction32(Insn, 24, 1);
Silviu Baranga6fe310e2012-03-22 14:14:49 +00001580 unsigned Rt2 = Rt + 1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001581
1582 bool writeback = (W == 1) | (P == 0);
Owen Andersonc537f3b2011-08-15 20:51:32 +00001583
1584 // For {LD,ST}RD, Rt must be even, else undefined.
1585 switch (Inst.getOpcode()) {
1586 case ARM::STRD:
1587 case ARM::STRD_PRE:
1588 case ARM::STRD_POST:
1589 case ARM::LDRD:
1590 case ARM::LDRD_PRE:
1591 case ARM::LDRD_POST:
Silviu Baranga6fe310e2012-03-22 14:14:49 +00001592 if (Rt & 0x1) S = MCDisassembler::SoftFail;
1593 break;
1594 default:
1595 break;
1596 }
1597 switch (Inst.getOpcode()) {
1598 case ARM::STRD:
1599 case ARM::STRD_PRE:
1600 case ARM::STRD_POST:
1601 if (P == 0 && W == 1)
1602 S = MCDisassembler::SoftFail;
1603
1604 if (writeback && (Rn == 15 || Rn == Rt || Rn == Rt2))
1605 S = MCDisassembler::SoftFail;
1606 if (type && Rm == 15)
1607 S = MCDisassembler::SoftFail;
1608 if (Rt2 == 15)
1609 S = MCDisassembler::SoftFail;
1610 if (!type && fieldFromInstruction32(Insn, 8, 4))
1611 S = MCDisassembler::SoftFail;
1612 break;
1613 case ARM::STRH:
1614 case ARM::STRH_PRE:
1615 case ARM::STRH_POST:
1616 if (Rt == 15)
1617 S = MCDisassembler::SoftFail;
1618 if (writeback && (Rn == 15 || Rn == Rt))
1619 S = MCDisassembler::SoftFail;
1620 if (!type && Rm == 15)
1621 S = MCDisassembler::SoftFail;
1622 break;
1623 case ARM::LDRD:
1624 case ARM::LDRD_PRE:
1625 case ARM::LDRD_POST:
1626 if (type && Rn == 15){
1627 if (Rt2 == 15)
1628 S = MCDisassembler::SoftFail;
1629 break;
1630 }
1631 if (P == 0 && W == 1)
1632 S = MCDisassembler::SoftFail;
1633 if (!type && (Rt2 == 15 || Rm == 15 || Rm == Rt || Rm == Rt2))
1634 S = MCDisassembler::SoftFail;
1635 if (!type && writeback && Rn == 15)
1636 S = MCDisassembler::SoftFail;
1637 if (writeback && (Rn == Rt || Rn == Rt2))
1638 S = MCDisassembler::SoftFail;
1639 break;
1640 case ARM::LDRH:
1641 case ARM::LDRH_PRE:
1642 case ARM::LDRH_POST:
1643 if (type && Rn == 15){
1644 if (Rt == 15)
1645 S = MCDisassembler::SoftFail;
1646 break;
1647 }
1648 if (Rt == 15)
1649 S = MCDisassembler::SoftFail;
1650 if (!type && Rm == 15)
1651 S = MCDisassembler::SoftFail;
1652 if (!type && writeback && (Rn == 15 || Rn == Rt))
1653 S = MCDisassembler::SoftFail;
1654 break;
1655 case ARM::LDRSH:
1656 case ARM::LDRSH_PRE:
1657 case ARM::LDRSH_POST:
1658 case ARM::LDRSB:
1659 case ARM::LDRSB_PRE:
1660 case ARM::LDRSB_POST:
1661 if (type && Rn == 15){
1662 if (Rt == 15)
1663 S = MCDisassembler::SoftFail;
1664 break;
1665 }
1666 if (type && (Rt == 15 || (writeback && Rn == Rt)))
1667 S = MCDisassembler::SoftFail;
1668 if (!type && (Rt == 15 || Rm == 15))
1669 S = MCDisassembler::SoftFail;
1670 if (!type && writeback && (Rn == 15 || Rn == Rt))
1671 S = MCDisassembler::SoftFail;
Owen Andersonc537f3b2011-08-15 20:51:32 +00001672 break;
Owen Andersona6804442011-09-01 23:23:50 +00001673 default:
1674 break;
Owen Andersonc537f3b2011-08-15 20:51:32 +00001675 }
1676
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001677 if (writeback) { // Writeback
1678 if (P)
1679 U |= ARMII::IndexModePre << 9;
1680 else
1681 U |= ARMII::IndexModePost << 9;
1682
1683 // On stores, the writeback operand precedes Rt.
1684 switch (Inst.getOpcode()) {
1685 case ARM::STRD:
1686 case ARM::STRD_PRE:
1687 case ARM::STRD_POST:
Owen Anderson79628e92011-08-12 20:02:50 +00001688 case ARM::STRH:
1689 case ARM::STRH_PRE:
1690 case ARM::STRH_POST:
Owen Andersona6804442011-09-01 23:23:50 +00001691 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1692 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001693 break;
1694 default:
1695 break;
1696 }
1697 }
1698
Owen Andersona6804442011-09-01 23:23:50 +00001699 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
1700 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001701 switch (Inst.getOpcode()) {
1702 case ARM::STRD:
1703 case ARM::STRD_PRE:
1704 case ARM::STRD_POST:
1705 case ARM::LDRD:
1706 case ARM::LDRD_PRE:
1707 case ARM::LDRD_POST:
Owen Andersona6804442011-09-01 23:23:50 +00001708 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)))
1709 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001710 break;
1711 default:
1712 break;
1713 }
1714
1715 if (writeback) {
1716 // On loads, the writeback operand comes after Rt.
1717 switch (Inst.getOpcode()) {
1718 case ARM::LDRD:
1719 case ARM::LDRD_PRE:
1720 case ARM::LDRD_POST:
Owen Anderson0d094992011-08-12 20:36:11 +00001721 case ARM::LDRH:
1722 case ARM::LDRH_PRE:
1723 case ARM::LDRH_POST:
1724 case ARM::LDRSH:
1725 case ARM::LDRSH_PRE:
1726 case ARM::LDRSH_POST:
1727 case ARM::LDRSB:
1728 case ARM::LDRSB_PRE:
1729 case ARM::LDRSB_POST:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001730 case ARM::LDRHTr:
1731 case ARM::LDRSBTr:
Owen Andersona6804442011-09-01 23:23:50 +00001732 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1733 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001734 break;
1735 default:
1736 break;
1737 }
1738 }
1739
Owen Andersona6804442011-09-01 23:23:50 +00001740 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1741 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001742
1743 if (type) {
1744 Inst.addOperand(MCOperand::CreateReg(0));
1745 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1746 } else {
Owen Andersona6804442011-09-01 23:23:50 +00001747 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
1748 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001749 Inst.addOperand(MCOperand::CreateImm(U));
1750 }
1751
Owen Andersona6804442011-09-01 23:23:50 +00001752 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1753 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001754
Owen Anderson83e3f672011-08-17 17:44:15 +00001755 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001756}
1757
Craig Topperc89c7442012-03-27 07:21:54 +00001758static DecodeStatus DecodeRFEInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001759 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001760 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001761
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001762 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1763 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1764
1765 switch (mode) {
1766 case 0:
1767 mode = ARM_AM::da;
1768 break;
1769 case 1:
1770 mode = ARM_AM::ia;
1771 break;
1772 case 2:
1773 mode = ARM_AM::db;
1774 break;
1775 case 3:
1776 mode = ARM_AM::ib;
1777 break;
1778 }
1779
1780 Inst.addOperand(MCOperand::CreateImm(mode));
Owen Andersona6804442011-09-01 23:23:50 +00001781 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1782 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001783
Owen Anderson83e3f672011-08-17 17:44:15 +00001784 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001785}
1786
Craig Topperc89c7442012-03-27 07:21:54 +00001787static DecodeStatus DecodeMemMultipleWritebackInstruction(MCInst &Inst,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001788 unsigned Insn,
1789 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00001790 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00001791
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001792 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1793 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1794 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1795
1796 if (pred == 0xF) {
1797 switch (Inst.getOpcode()) {
Owen Anderson846dd952011-08-18 22:31:17 +00001798 case ARM::LDMDA:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001799 Inst.setOpcode(ARM::RFEDA);
1800 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001801 case ARM::LDMDA_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001802 Inst.setOpcode(ARM::RFEDA_UPD);
1803 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001804 case ARM::LDMDB:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001805 Inst.setOpcode(ARM::RFEDB);
1806 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001807 case ARM::LDMDB_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001808 Inst.setOpcode(ARM::RFEDB_UPD);
1809 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001810 case ARM::LDMIA:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001811 Inst.setOpcode(ARM::RFEIA);
1812 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001813 case ARM::LDMIA_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001814 Inst.setOpcode(ARM::RFEIA_UPD);
1815 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001816 case ARM::LDMIB:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001817 Inst.setOpcode(ARM::RFEIB);
1818 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001819 case ARM::LDMIB_UPD:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001820 Inst.setOpcode(ARM::RFEIB_UPD);
1821 break;
Owen Anderson846dd952011-08-18 22:31:17 +00001822 case ARM::STMDA:
1823 Inst.setOpcode(ARM::SRSDA);
1824 break;
1825 case ARM::STMDA_UPD:
1826 Inst.setOpcode(ARM::SRSDA_UPD);
1827 break;
1828 case ARM::STMDB:
1829 Inst.setOpcode(ARM::SRSDB);
1830 break;
1831 case ARM::STMDB_UPD:
1832 Inst.setOpcode(ARM::SRSDB_UPD);
1833 break;
1834 case ARM::STMIA:
1835 Inst.setOpcode(ARM::SRSIA);
1836 break;
1837 case ARM::STMIA_UPD:
1838 Inst.setOpcode(ARM::SRSIA_UPD);
1839 break;
1840 case ARM::STMIB:
1841 Inst.setOpcode(ARM::SRSIB);
1842 break;
1843 case ARM::STMIB_UPD:
1844 Inst.setOpcode(ARM::SRSIB_UPD);
1845 break;
1846 default:
James Molloyc047dca2011-09-01 18:02:14 +00001847 if (!Check(S, MCDisassembler::Fail)) return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001848 }
Owen Anderson846dd952011-08-18 22:31:17 +00001849
1850 // For stores (which become SRS's, the only operand is the mode.
1851 if (fieldFromInstruction32(Insn, 20, 1) == 0) {
1852 Inst.addOperand(
1853 MCOperand::CreateImm(fieldFromInstruction32(Insn, 0, 4)));
1854 return S;
1855 }
1856
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001857 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1858 }
1859
Owen Andersona6804442011-09-01 23:23:50 +00001860 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1861 return MCDisassembler::Fail;
1862 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
1863 return MCDisassembler::Fail; // Tied
1864 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1865 return MCDisassembler::Fail;
1866 if (!Check(S, DecodeRegListOperand(Inst, reglist, Address, Decoder)))
1867 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001868
Owen Anderson83e3f672011-08-17 17:44:15 +00001869 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001870}
1871
Craig Topperc89c7442012-03-27 07:21:54 +00001872static DecodeStatus DecodeCPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001873 uint64_t Address, const void *Decoder) {
1874 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1875 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1876 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1877 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1878
Owen Andersona6804442011-09-01 23:23:50 +00001879 DecodeStatus S = MCDisassembler::Success;
Owen Anderson35008c22011-08-09 23:05:39 +00001880
Owen Anderson14090bf2011-08-18 22:11:02 +00001881 // imod == '01' --> UNPREDICTABLE
1882 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1883 // return failure here. The '01' imod value is unprintable, so there's
1884 // nothing useful we could do even if we returned UNPREDICTABLE.
1885
James Molloyc047dca2011-09-01 18:02:14 +00001886 if (imod == 1) return MCDisassembler::Fail;
Owen Anderson14090bf2011-08-18 22:11:02 +00001887
1888 if (imod && M) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001889 Inst.setOpcode(ARM::CPS3p);
1890 Inst.addOperand(MCOperand::CreateImm(imod));
1891 Inst.addOperand(MCOperand::CreateImm(iflags));
1892 Inst.addOperand(MCOperand::CreateImm(mode));
Owen Anderson14090bf2011-08-18 22:11:02 +00001893 } else if (imod && !M) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001894 Inst.setOpcode(ARM::CPS2p);
1895 Inst.addOperand(MCOperand::CreateImm(imod));
1896 Inst.addOperand(MCOperand::CreateImm(iflags));
James Molloyc047dca2011-09-01 18:02:14 +00001897 if (mode) S = MCDisassembler::SoftFail;
Owen Anderson14090bf2011-08-18 22:11:02 +00001898 } else if (!imod && M) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001899 Inst.setOpcode(ARM::CPS1p);
1900 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001901 if (iflags) S = MCDisassembler::SoftFail;
Owen Anderson1dd56f02011-08-18 22:15:25 +00001902 } else {
Owen Anderson14090bf2011-08-18 22:11:02 +00001903 // imod == '00' && M == '0' --> UNPREDICTABLE
Owen Anderson1dd56f02011-08-18 22:15:25 +00001904 Inst.setOpcode(ARM::CPS1p);
1905 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001906 S = MCDisassembler::SoftFail;
Owen Anderson1dd56f02011-08-18 22:15:25 +00001907 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001908
Owen Anderson14090bf2011-08-18 22:11:02 +00001909 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001910}
1911
Craig Topperc89c7442012-03-27 07:21:54 +00001912static DecodeStatus DecodeT2CPSInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson6153a032011-08-23 17:45:18 +00001913 uint64_t Address, const void *Decoder) {
1914 unsigned imod = fieldFromInstruction32(Insn, 9, 2);
1915 unsigned M = fieldFromInstruction32(Insn, 8, 1);
1916 unsigned iflags = fieldFromInstruction32(Insn, 5, 3);
1917 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1918
Owen Andersona6804442011-09-01 23:23:50 +00001919 DecodeStatus S = MCDisassembler::Success;
Owen Anderson6153a032011-08-23 17:45:18 +00001920
1921 // imod == '01' --> UNPREDICTABLE
1922 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1923 // return failure here. The '01' imod value is unprintable, so there's
1924 // nothing useful we could do even if we returned UNPREDICTABLE.
1925
James Molloyc047dca2011-09-01 18:02:14 +00001926 if (imod == 1) return MCDisassembler::Fail;
Owen Anderson6153a032011-08-23 17:45:18 +00001927
1928 if (imod && M) {
1929 Inst.setOpcode(ARM::t2CPS3p);
1930 Inst.addOperand(MCOperand::CreateImm(imod));
1931 Inst.addOperand(MCOperand::CreateImm(iflags));
1932 Inst.addOperand(MCOperand::CreateImm(mode));
1933 } else if (imod && !M) {
1934 Inst.setOpcode(ARM::t2CPS2p);
1935 Inst.addOperand(MCOperand::CreateImm(imod));
1936 Inst.addOperand(MCOperand::CreateImm(iflags));
James Molloyc047dca2011-09-01 18:02:14 +00001937 if (mode) S = MCDisassembler::SoftFail;
Owen Anderson6153a032011-08-23 17:45:18 +00001938 } else if (!imod && M) {
1939 Inst.setOpcode(ARM::t2CPS1p);
1940 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001941 if (iflags) S = MCDisassembler::SoftFail;
Owen Anderson6153a032011-08-23 17:45:18 +00001942 } else {
1943 // imod == '00' && M == '0' --> UNPREDICTABLE
1944 Inst.setOpcode(ARM::t2CPS1p);
1945 Inst.addOperand(MCOperand::CreateImm(mode));
James Molloyc047dca2011-09-01 18:02:14 +00001946 S = MCDisassembler::SoftFail;
Owen Anderson6153a032011-08-23 17:45:18 +00001947 }
1948
1949 return S;
1950}
1951
Craig Topperc89c7442012-03-27 07:21:54 +00001952static DecodeStatus DecodeT2MOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +00001953 uint64_t Address, const void *Decoder) {
1954 DecodeStatus S = MCDisassembler::Success;
1955
1956 unsigned Rd = fieldFromInstruction32(Insn, 8, 4);
1957 unsigned imm = 0;
1958
1959 imm |= (fieldFromInstruction32(Insn, 0, 8) << 0);
1960 imm |= (fieldFromInstruction32(Insn, 12, 3) << 8);
1961 imm |= (fieldFromInstruction32(Insn, 16, 4) << 12);
1962 imm |= (fieldFromInstruction32(Insn, 26, 1) << 11);
1963
1964 if (Inst.getOpcode() == ARM::t2MOVTi16)
1965 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
1966 return MCDisassembler::Fail;
1967 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
1968 return MCDisassembler::Fail;
1969
1970 if (!tryAddingSymbolicOperand(Address, imm, false, 4, Inst, Decoder))
1971 Inst.addOperand(MCOperand::CreateImm(imm));
1972
1973 return S;
1974}
1975
Craig Topperc89c7442012-03-27 07:21:54 +00001976static DecodeStatus DecodeArmMOVTWInstruction(MCInst &Inst, unsigned Insn,
Kevin Enderby9e5887b2011-10-04 22:44:48 +00001977 uint64_t Address, const void *Decoder) {
1978 DecodeStatus S = MCDisassembler::Success;
1979
1980 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1981 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1982 unsigned imm = 0;
1983
1984 imm |= (fieldFromInstruction32(Insn, 0, 12) << 0);
1985 imm |= (fieldFromInstruction32(Insn, 16, 4) << 12);
1986
1987 if (Inst.getOpcode() == ARM::MOVTi16)
1988 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
1989 return MCDisassembler::Fail;
1990 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
1991 return MCDisassembler::Fail;
1992
1993 if (!tryAddingSymbolicOperand(Address, imm, false, 4, Inst, Decoder))
1994 Inst.addOperand(MCOperand::CreateImm(imm));
1995
1996 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
1997 return MCDisassembler::Fail;
1998
1999 return S;
2000}
Owen Anderson6153a032011-08-23 17:45:18 +00002001
Craig Topperc89c7442012-03-27 07:21:54 +00002002static DecodeStatus DecodeSMLAInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002003 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002004 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002005
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002006 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
2007 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
2008 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
2009 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
2010 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2011
2012 if (pred == 0xF)
2013 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
2014
Owen Andersona6804442011-09-01 23:23:50 +00002015 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder)))
2016 return MCDisassembler::Fail;
2017 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
2018 return MCDisassembler::Fail;
2019 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
2020 return MCDisassembler::Fail;
2021 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder)))
2022 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002023
Owen Andersona6804442011-09-01 23:23:50 +00002024 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
2025 return MCDisassembler::Fail;
Owen Anderson1fb66732011-08-11 22:05:38 +00002026
Owen Anderson83e3f672011-08-17 17:44:15 +00002027 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002028}
2029
Craig Topperc89c7442012-03-27 07:21:54 +00002030static DecodeStatus DecodeAddrModeImm12Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002031 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002032 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002033
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002034 unsigned add = fieldFromInstruction32(Val, 12, 1);
2035 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2036 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2037
Owen Andersona6804442011-09-01 23:23:50 +00002038 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2039 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002040
2041 if (!add) imm *= -1;
2042 if (imm == 0 && !add) imm = INT32_MIN;
2043 Inst.addOperand(MCOperand::CreateImm(imm));
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002044 if (Rn == 15)
2045 tryAddingPcLoadReferenceComment(Address, Address + imm + 8, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002046
Owen Anderson83e3f672011-08-17 17:44:15 +00002047 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002048}
2049
Craig Topperc89c7442012-03-27 07:21:54 +00002050static DecodeStatus DecodeAddrMode5Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002051 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002052 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002053
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002054 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2055 unsigned U = fieldFromInstruction32(Val, 8, 1);
2056 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2057
Owen Andersona6804442011-09-01 23:23:50 +00002058 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2059 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002060
2061 if (U)
2062 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
2063 else
2064 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
2065
Owen Anderson83e3f672011-08-17 17:44:15 +00002066 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002067}
2068
Craig Topperc89c7442012-03-27 07:21:54 +00002069static DecodeStatus DecodeAddrMode7Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002070 uint64_t Address, const void *Decoder) {
2071 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
2072}
2073
Owen Andersona6804442011-09-01 23:23:50 +00002074static DecodeStatus
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00002075DecodeT2BInstruction(MCInst &Inst, unsigned Insn,
2076 uint64_t Address, const void *Decoder) {
2077 DecodeStatus S = MCDisassembler::Success;
2078 unsigned imm = (fieldFromInstruction32(Insn, 0, 11) << 0) |
2079 (fieldFromInstruction32(Insn, 11, 1) << 18) |
2080 (fieldFromInstruction32(Insn, 13, 1) << 17) |
2081 (fieldFromInstruction32(Insn, 16, 6) << 11) |
2082 (fieldFromInstruction32(Insn, 26, 1) << 19);
2083 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<20>(imm<<1) + 4,
2084 true, 4, Inst, Decoder))
2085 Inst.addOperand(MCOperand::CreateImm(SignExtend32<20>(imm << 1)));
2086 return S;
2087}
2088
2089static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00002090DecodeBranchImmInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00002091 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002092 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002093
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002094 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2095 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
2096
2097 if (pred == 0xF) {
2098 Inst.setOpcode(ARM::BLXi);
2099 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
Kevin Enderbyb80d5712012-02-23 18:18:17 +00002100 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<26>(imm) + 8,
2101 true, 4, Inst, Decoder))
Benjamin Kramer793b8112011-08-09 22:02:50 +00002102 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Anderson83e3f672011-08-17 17:44:15 +00002103 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002104 }
2105
Kevin Enderbyb80d5712012-02-23 18:18:17 +00002106 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<26>(imm) + 8,
2107 true, 4, Inst, Decoder))
Kevin Enderby9e5887b2011-10-04 22:44:48 +00002108 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Andersona6804442011-09-01 23:23:50 +00002109 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
2110 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002111
Owen Anderson83e3f672011-08-17 17:44:15 +00002112 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002113}
2114
2115
Craig Topperc89c7442012-03-27 07:21:54 +00002116static DecodeStatus DecodeAddrMode6Operand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002117 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002118 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002119
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002120 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
2121 unsigned align = fieldFromInstruction32(Val, 4, 2);
2122
Owen Andersona6804442011-09-01 23:23:50 +00002123 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2124 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002125 if (!align)
2126 Inst.addOperand(MCOperand::CreateImm(0));
2127 else
2128 Inst.addOperand(MCOperand::CreateImm(4 << align));
2129
Owen Anderson83e3f672011-08-17 17:44:15 +00002130 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002131}
2132
Craig Topperc89c7442012-03-27 07:21:54 +00002133static DecodeStatus DecodeVLDInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002134 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002135 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002136
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002137 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2138 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2139 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
2140 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2141 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
2142 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2143
2144 // First output register
Jim Grosbach28f08c92012-03-05 19:33:30 +00002145 switch (Inst.getOpcode()) {
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002146 case ARM::VLD1q16: case ARM::VLD1q32: case ARM::VLD1q64: case ARM::VLD1q8:
2147 case ARM::VLD1q16wb_fixed: case ARM::VLD1q16wb_register:
2148 case ARM::VLD1q32wb_fixed: case ARM::VLD1q32wb_register:
2149 case ARM::VLD1q64wb_fixed: case ARM::VLD1q64wb_register:
2150 case ARM::VLD1q8wb_fixed: case ARM::VLD1q8wb_register:
2151 case ARM::VLD2d16: case ARM::VLD2d32: case ARM::VLD2d8:
2152 case ARM::VLD2d16wb_fixed: case ARM::VLD2d16wb_register:
2153 case ARM::VLD2d32wb_fixed: case ARM::VLD2d32wb_register:
2154 case ARM::VLD2d8wb_fixed: case ARM::VLD2d8wb_register:
Jim Grosbach28f08c92012-03-05 19:33:30 +00002155 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2156 return MCDisassembler::Fail;
2157 break;
Jim Grosbachc3384c92012-03-05 21:43:40 +00002158 case ARM::VLD2b16:
2159 case ARM::VLD2b32:
2160 case ARM::VLD2b8:
2161 case ARM::VLD2b16wb_fixed:
2162 case ARM::VLD2b16wb_register:
2163 case ARM::VLD2b32wb_fixed:
2164 case ARM::VLD2b32wb_register:
2165 case ARM::VLD2b8wb_fixed:
2166 case ARM::VLD2b8wb_register:
2167 if (!Check(S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder)))
2168 return MCDisassembler::Fail;
2169 break;
Jim Grosbach28f08c92012-03-05 19:33:30 +00002170 default:
2171 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2172 return MCDisassembler::Fail;
2173 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002174
2175 // Second output register
2176 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002177 case ARM::VLD3d8:
2178 case ARM::VLD3d16:
2179 case ARM::VLD3d32:
2180 case ARM::VLD3d8_UPD:
2181 case ARM::VLD3d16_UPD:
2182 case ARM::VLD3d32_UPD:
2183 case ARM::VLD4d8:
2184 case ARM::VLD4d16:
2185 case ARM::VLD4d32:
2186 case ARM::VLD4d8_UPD:
2187 case ARM::VLD4d16_UPD:
2188 case ARM::VLD4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002189 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)))
2190 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002191 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002192 case ARM::VLD3q8:
2193 case ARM::VLD3q16:
2194 case ARM::VLD3q32:
2195 case ARM::VLD3q8_UPD:
2196 case ARM::VLD3q16_UPD:
2197 case ARM::VLD3q32_UPD:
2198 case ARM::VLD4q8:
2199 case ARM::VLD4q16:
2200 case ARM::VLD4q32:
2201 case ARM::VLD4q8_UPD:
2202 case ARM::VLD4q16_UPD:
2203 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002204 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2205 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002206 default:
2207 break;
2208 }
2209
2210 // Third output register
2211 switch(Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002212 case ARM::VLD3d8:
2213 case ARM::VLD3d16:
2214 case ARM::VLD3d32:
2215 case ARM::VLD3d8_UPD:
2216 case ARM::VLD3d16_UPD:
2217 case ARM::VLD3d32_UPD:
2218 case ARM::VLD4d8:
2219 case ARM::VLD4d16:
2220 case ARM::VLD4d32:
2221 case ARM::VLD4d8_UPD:
2222 case ARM::VLD4d16_UPD:
2223 case ARM::VLD4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002224 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2225 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002226 break;
2227 case ARM::VLD3q8:
2228 case ARM::VLD3q16:
2229 case ARM::VLD3q32:
2230 case ARM::VLD3q8_UPD:
2231 case ARM::VLD3q16_UPD:
2232 case ARM::VLD3q32_UPD:
2233 case ARM::VLD4q8:
2234 case ARM::VLD4q16:
2235 case ARM::VLD4q32:
2236 case ARM::VLD4q8_UPD:
2237 case ARM::VLD4q16_UPD:
2238 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002239 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)))
2240 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002241 break;
2242 default:
2243 break;
2244 }
2245
2246 // Fourth output register
2247 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002248 case ARM::VLD4d8:
2249 case ARM::VLD4d16:
2250 case ARM::VLD4d32:
2251 case ARM::VLD4d8_UPD:
2252 case ARM::VLD4d16_UPD:
2253 case ARM::VLD4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002254 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)))
2255 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002256 break;
2257 case ARM::VLD4q8:
2258 case ARM::VLD4q16:
2259 case ARM::VLD4q32:
2260 case ARM::VLD4q8_UPD:
2261 case ARM::VLD4q16_UPD:
2262 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002263 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)))
2264 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002265 break;
2266 default:
2267 break;
2268 }
2269
2270 // Writeback operand
2271 switch (Inst.getOpcode()) {
Jim Grosbach10b90a92011-10-24 21:45:13 +00002272 case ARM::VLD1d8wb_fixed:
2273 case ARM::VLD1d16wb_fixed:
2274 case ARM::VLD1d32wb_fixed:
2275 case ARM::VLD1d64wb_fixed:
2276 case ARM::VLD1d8wb_register:
2277 case ARM::VLD1d16wb_register:
2278 case ARM::VLD1d32wb_register:
2279 case ARM::VLD1d64wb_register:
2280 case ARM::VLD1q8wb_fixed:
2281 case ARM::VLD1q16wb_fixed:
2282 case ARM::VLD1q32wb_fixed:
2283 case ARM::VLD1q64wb_fixed:
2284 case ARM::VLD1q8wb_register:
2285 case ARM::VLD1q16wb_register:
2286 case ARM::VLD1q32wb_register:
2287 case ARM::VLD1q64wb_register:
Jim Grosbach59216752011-10-24 23:26:05 +00002288 case ARM::VLD1d8Twb_fixed:
2289 case ARM::VLD1d8Twb_register:
2290 case ARM::VLD1d16Twb_fixed:
2291 case ARM::VLD1d16Twb_register:
2292 case ARM::VLD1d32Twb_fixed:
2293 case ARM::VLD1d32Twb_register:
2294 case ARM::VLD1d64Twb_fixed:
2295 case ARM::VLD1d64Twb_register:
Jim Grosbach399cdca2011-10-25 00:14:01 +00002296 case ARM::VLD1d8Qwb_fixed:
2297 case ARM::VLD1d8Qwb_register:
2298 case ARM::VLD1d16Qwb_fixed:
2299 case ARM::VLD1d16Qwb_register:
2300 case ARM::VLD1d32Qwb_fixed:
2301 case ARM::VLD1d32Qwb_register:
2302 case ARM::VLD1d64Qwb_fixed:
2303 case ARM::VLD1d64Qwb_register:
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00002304 case ARM::VLD2d8wb_fixed:
2305 case ARM::VLD2d16wb_fixed:
2306 case ARM::VLD2d32wb_fixed:
2307 case ARM::VLD2q8wb_fixed:
2308 case ARM::VLD2q16wb_fixed:
2309 case ARM::VLD2q32wb_fixed:
2310 case ARM::VLD2d8wb_register:
2311 case ARM::VLD2d16wb_register:
2312 case ARM::VLD2d32wb_register:
2313 case ARM::VLD2q8wb_register:
2314 case ARM::VLD2q16wb_register:
2315 case ARM::VLD2q32wb_register:
2316 case ARM::VLD2b8wb_fixed:
2317 case ARM::VLD2b16wb_fixed:
2318 case ARM::VLD2b32wb_fixed:
2319 case ARM::VLD2b8wb_register:
2320 case ARM::VLD2b16wb_register:
2321 case ARM::VLD2b32wb_register:
Kevin Enderbya69da352012-04-11 00:25:40 +00002322 Inst.addOperand(MCOperand::CreateImm(0));
2323 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002324 case ARM::VLD3d8_UPD:
2325 case ARM::VLD3d16_UPD:
2326 case ARM::VLD3d32_UPD:
2327 case ARM::VLD3q8_UPD:
2328 case ARM::VLD3q16_UPD:
2329 case ARM::VLD3q32_UPD:
2330 case ARM::VLD4d8_UPD:
2331 case ARM::VLD4d16_UPD:
2332 case ARM::VLD4d32_UPD:
2333 case ARM::VLD4q8_UPD:
2334 case ARM::VLD4q16_UPD:
2335 case ARM::VLD4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002336 if (!Check(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder)))
2337 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002338 break;
2339 default:
2340 break;
2341 }
2342
2343 // AddrMode6 Base (register+alignment)
Owen Andersona6804442011-09-01 23:23:50 +00002344 if (!Check(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)))
2345 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002346
2347 // AddrMode6 Offset (register)
Jim Grosbach10b90a92011-10-24 21:45:13 +00002348 switch (Inst.getOpcode()) {
2349 default:
2350 // The below have been updated to have explicit am6offset split
2351 // between fixed and register offset. For those instructions not
2352 // yet updated, we need to add an additional reg0 operand for the
2353 // fixed variant.
2354 //
2355 // The fixed offset encodes as Rm == 0xd, so we check for that.
2356 if (Rm == 0xd) {
2357 Inst.addOperand(MCOperand::CreateReg(0));
2358 break;
2359 }
2360 // Fall through to handle the register offset variant.
2361 case ARM::VLD1d8wb_fixed:
2362 case ARM::VLD1d16wb_fixed:
2363 case ARM::VLD1d32wb_fixed:
2364 case ARM::VLD1d64wb_fixed:
Owen Anderson04b12a42011-10-27 22:53:10 +00002365 case ARM::VLD1d8Twb_fixed:
2366 case ARM::VLD1d16Twb_fixed:
2367 case ARM::VLD1d32Twb_fixed:
2368 case ARM::VLD1d64Twb_fixed:
Owen Andersonfb6ab2b2011-10-31 17:17:32 +00002369 case ARM::VLD1d8Qwb_fixed:
2370 case ARM::VLD1d16Qwb_fixed:
2371 case ARM::VLD1d32Qwb_fixed:
2372 case ARM::VLD1d64Qwb_fixed:
Jim Grosbach10b90a92011-10-24 21:45:13 +00002373 case ARM::VLD1d8wb_register:
2374 case ARM::VLD1d16wb_register:
2375 case ARM::VLD1d32wb_register:
2376 case ARM::VLD1d64wb_register:
2377 case ARM::VLD1q8wb_fixed:
2378 case ARM::VLD1q16wb_fixed:
2379 case ARM::VLD1q32wb_fixed:
2380 case ARM::VLD1q64wb_fixed:
2381 case ARM::VLD1q8wb_register:
2382 case ARM::VLD1q16wb_register:
2383 case ARM::VLD1q32wb_register:
2384 case ARM::VLD1q64wb_register:
2385 // The fixed offset post-increment encodes Rm == 0xd. The no-writeback
2386 // variant encodes Rm == 0xf. Anything else is a register offset post-
2387 // increment and we need to add the register operand to the instruction.
2388 if (Rm != 0xD && Rm != 0xF &&
2389 !Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00002390 return MCDisassembler::Fail;
Jim Grosbach10b90a92011-10-24 21:45:13 +00002391 break;
Kevin Enderbya69da352012-04-11 00:25:40 +00002392 case ARM::VLD2d8wb_fixed:
2393 case ARM::VLD2d16wb_fixed:
2394 case ARM::VLD2d32wb_fixed:
2395 case ARM::VLD2b8wb_fixed:
2396 case ARM::VLD2b16wb_fixed:
2397 case ARM::VLD2b32wb_fixed:
2398 case ARM::VLD2q8wb_fixed:
2399 case ARM::VLD2q16wb_fixed:
2400 case ARM::VLD2q32wb_fixed:
2401 break;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002402 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002403
Owen Anderson83e3f672011-08-17 17:44:15 +00002404 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002405}
2406
Craig Topperc89c7442012-03-27 07:21:54 +00002407static DecodeStatus DecodeVSTInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002408 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002409 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002410
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002411 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2412 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2413 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
2414 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2415 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
2416 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2417
2418 // Writeback Operand
2419 switch (Inst.getOpcode()) {
Jim Grosbach4334e032011-10-31 21:50:31 +00002420 case ARM::VST1d8wb_fixed:
2421 case ARM::VST1d16wb_fixed:
2422 case ARM::VST1d32wb_fixed:
2423 case ARM::VST1d64wb_fixed:
2424 case ARM::VST1d8wb_register:
2425 case ARM::VST1d16wb_register:
2426 case ARM::VST1d32wb_register:
2427 case ARM::VST1d64wb_register:
2428 case ARM::VST1q8wb_fixed:
2429 case ARM::VST1q16wb_fixed:
2430 case ARM::VST1q32wb_fixed:
2431 case ARM::VST1q64wb_fixed:
2432 case ARM::VST1q8wb_register:
2433 case ARM::VST1q16wb_register:
2434 case ARM::VST1q32wb_register:
2435 case ARM::VST1q64wb_register:
Jim Grosbachd5ca2012011-11-29 22:38:04 +00002436 case ARM::VST1d8Twb_fixed:
2437 case ARM::VST1d16Twb_fixed:
2438 case ARM::VST1d32Twb_fixed:
2439 case ARM::VST1d64Twb_fixed:
2440 case ARM::VST1d8Twb_register:
2441 case ARM::VST1d16Twb_register:
2442 case ARM::VST1d32Twb_register:
2443 case ARM::VST1d64Twb_register:
Jim Grosbach4c7edb32011-11-29 22:58:48 +00002444 case ARM::VST1d8Qwb_fixed:
2445 case ARM::VST1d16Qwb_fixed:
2446 case ARM::VST1d32Qwb_fixed:
2447 case ARM::VST1d64Qwb_fixed:
2448 case ARM::VST1d8Qwb_register:
2449 case ARM::VST1d16Qwb_register:
2450 case ARM::VST1d32Qwb_register:
2451 case ARM::VST1d64Qwb_register:
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00002452 case ARM::VST2d8wb_fixed:
2453 case ARM::VST2d16wb_fixed:
2454 case ARM::VST2d32wb_fixed:
2455 case ARM::VST2d8wb_register:
2456 case ARM::VST2d16wb_register:
2457 case ARM::VST2d32wb_register:
2458 case ARM::VST2q8wb_fixed:
2459 case ARM::VST2q16wb_fixed:
2460 case ARM::VST2q32wb_fixed:
2461 case ARM::VST2q8wb_register:
2462 case ARM::VST2q16wb_register:
2463 case ARM::VST2q32wb_register:
2464 case ARM::VST2b8wb_fixed:
2465 case ARM::VST2b16wb_fixed:
2466 case ARM::VST2b32wb_fixed:
2467 case ARM::VST2b8wb_register:
2468 case ARM::VST2b16wb_register:
2469 case ARM::VST2b32wb_register:
Kevin Enderbyb318cc12012-04-11 22:40:17 +00002470 if (Rm == 0xF)
2471 return MCDisassembler::Fail;
Kevin Enderbyf0586f02012-03-21 20:54:32 +00002472 Inst.addOperand(MCOperand::CreateImm(0));
2473 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002474 case ARM::VST3d8_UPD:
2475 case ARM::VST3d16_UPD:
2476 case ARM::VST3d32_UPD:
2477 case ARM::VST3q8_UPD:
2478 case ARM::VST3q16_UPD:
2479 case ARM::VST3q32_UPD:
2480 case ARM::VST4d8_UPD:
2481 case ARM::VST4d16_UPD:
2482 case ARM::VST4d32_UPD:
2483 case ARM::VST4q8_UPD:
2484 case ARM::VST4q16_UPD:
2485 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002486 if (!Check(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder)))
2487 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002488 break;
2489 default:
2490 break;
2491 }
2492
2493 // AddrMode6 Base (register+alignment)
Owen Andersona6804442011-09-01 23:23:50 +00002494 if (!Check(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)))
2495 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002496
2497 // AddrMode6 Offset (register)
Owen Anderson60cb6432011-11-01 22:18:13 +00002498 switch (Inst.getOpcode()) {
2499 default:
2500 if (Rm == 0xD)
2501 Inst.addOperand(MCOperand::CreateReg(0));
2502 else if (Rm != 0xF) {
2503 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2504 return MCDisassembler::Fail;
2505 }
2506 break;
2507 case ARM::VST1d8wb_fixed:
2508 case ARM::VST1d16wb_fixed:
2509 case ARM::VST1d32wb_fixed:
2510 case ARM::VST1d64wb_fixed:
2511 case ARM::VST1q8wb_fixed:
2512 case ARM::VST1q16wb_fixed:
2513 case ARM::VST1q32wb_fixed:
2514 case ARM::VST1q64wb_fixed:
Kevin Enderbyf0586f02012-03-21 20:54:32 +00002515 case ARM::VST1d8Twb_fixed:
2516 case ARM::VST1d16Twb_fixed:
2517 case ARM::VST1d32Twb_fixed:
2518 case ARM::VST1d64Twb_fixed:
2519 case ARM::VST1d8Qwb_fixed:
2520 case ARM::VST1d16Qwb_fixed:
2521 case ARM::VST1d32Qwb_fixed:
2522 case ARM::VST1d64Qwb_fixed:
2523 case ARM::VST2d8wb_fixed:
2524 case ARM::VST2d16wb_fixed:
2525 case ARM::VST2d32wb_fixed:
2526 case ARM::VST2q8wb_fixed:
2527 case ARM::VST2q16wb_fixed:
2528 case ARM::VST2q32wb_fixed:
2529 case ARM::VST2b8wb_fixed:
2530 case ARM::VST2b16wb_fixed:
2531 case ARM::VST2b32wb_fixed:
Owen Anderson60cb6432011-11-01 22:18:13 +00002532 break;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002533 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002534
Owen Anderson60cb6432011-11-01 22:18:13 +00002535
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002536 // First input register
Jim Grosbach28f08c92012-03-05 19:33:30 +00002537 switch (Inst.getOpcode()) {
2538 case ARM::VST1q16:
2539 case ARM::VST1q32:
2540 case ARM::VST1q64:
2541 case ARM::VST1q8:
2542 case ARM::VST1q16wb_fixed:
2543 case ARM::VST1q16wb_register:
2544 case ARM::VST1q32wb_fixed:
2545 case ARM::VST1q32wb_register:
2546 case ARM::VST1q64wb_fixed:
2547 case ARM::VST1q64wb_register:
2548 case ARM::VST1q8wb_fixed:
2549 case ARM::VST1q8wb_register:
2550 case ARM::VST2d16:
2551 case ARM::VST2d32:
2552 case ARM::VST2d8:
2553 case ARM::VST2d16wb_fixed:
2554 case ARM::VST2d16wb_register:
2555 case ARM::VST2d32wb_fixed:
2556 case ARM::VST2d32wb_register:
2557 case ARM::VST2d8wb_fixed:
2558 case ARM::VST2d8wb_register:
2559 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2560 return MCDisassembler::Fail;
2561 break;
Jim Grosbachc3384c92012-03-05 21:43:40 +00002562 case ARM::VST2b16:
2563 case ARM::VST2b32:
2564 case ARM::VST2b8:
2565 case ARM::VST2b16wb_fixed:
2566 case ARM::VST2b16wb_register:
2567 case ARM::VST2b32wb_fixed:
2568 case ARM::VST2b32wb_register:
2569 case ARM::VST2b8wb_fixed:
2570 case ARM::VST2b8wb_register:
2571 if (!Check(S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder)))
2572 return MCDisassembler::Fail;
2573 break;
Jim Grosbach28f08c92012-03-05 19:33:30 +00002574 default:
2575 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2576 return MCDisassembler::Fail;
2577 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002578
2579 // Second input register
2580 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002581 case ARM::VST3d8:
2582 case ARM::VST3d16:
2583 case ARM::VST3d32:
2584 case ARM::VST3d8_UPD:
2585 case ARM::VST3d16_UPD:
2586 case ARM::VST3d32_UPD:
2587 case ARM::VST4d8:
2588 case ARM::VST4d16:
2589 case ARM::VST4d32:
2590 case ARM::VST4d8_UPD:
2591 case ARM::VST4d16_UPD:
2592 case ARM::VST4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002593 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)))
2594 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002595 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002596 case ARM::VST3q8:
2597 case ARM::VST3q16:
2598 case ARM::VST3q32:
2599 case ARM::VST3q8_UPD:
2600 case ARM::VST3q16_UPD:
2601 case ARM::VST3q32_UPD:
2602 case ARM::VST4q8:
2603 case ARM::VST4q16:
2604 case ARM::VST4q32:
2605 case ARM::VST4q8_UPD:
2606 case ARM::VST4q16_UPD:
2607 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002608 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2609 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002610 break;
2611 default:
2612 break;
2613 }
2614
2615 // Third input register
2616 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002617 case ARM::VST3d8:
2618 case ARM::VST3d16:
2619 case ARM::VST3d32:
2620 case ARM::VST3d8_UPD:
2621 case ARM::VST3d16_UPD:
2622 case ARM::VST3d32_UPD:
2623 case ARM::VST4d8:
2624 case ARM::VST4d16:
2625 case ARM::VST4d32:
2626 case ARM::VST4d8_UPD:
2627 case ARM::VST4d16_UPD:
2628 case ARM::VST4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002629 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)))
2630 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002631 break;
2632 case ARM::VST3q8:
2633 case ARM::VST3q16:
2634 case ARM::VST3q32:
2635 case ARM::VST3q8_UPD:
2636 case ARM::VST3q16_UPD:
2637 case ARM::VST3q32_UPD:
2638 case ARM::VST4q8:
2639 case ARM::VST4q16:
2640 case ARM::VST4q32:
2641 case ARM::VST4q8_UPD:
2642 case ARM::VST4q16_UPD:
2643 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002644 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)))
2645 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002646 break;
2647 default:
2648 break;
2649 }
2650
2651 // Fourth input register
2652 switch (Inst.getOpcode()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002653 case ARM::VST4d8:
2654 case ARM::VST4d16:
2655 case ARM::VST4d32:
2656 case ARM::VST4d8_UPD:
2657 case ARM::VST4d16_UPD:
2658 case ARM::VST4d32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002659 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)))
2660 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002661 break;
2662 case ARM::VST4q8:
2663 case ARM::VST4q16:
2664 case ARM::VST4q32:
2665 case ARM::VST4q8_UPD:
2666 case ARM::VST4q16_UPD:
2667 case ARM::VST4q32_UPD:
Owen Andersona6804442011-09-01 23:23:50 +00002668 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)))
2669 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002670 break;
2671 default:
2672 break;
2673 }
2674
Owen Anderson83e3f672011-08-17 17:44:15 +00002675 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002676}
2677
Craig Topperc89c7442012-03-27 07:21:54 +00002678static DecodeStatus DecodeVLD1DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002679 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002680 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002681
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002682 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2683 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2684 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2685 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2686 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2687 unsigned size = fieldFromInstruction32(Insn, 6, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002688
2689 align *= (1 << size);
2690
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002691 switch (Inst.getOpcode()) {
2692 case ARM::VLD1DUPq16: case ARM::VLD1DUPq32: case ARM::VLD1DUPq8:
2693 case ARM::VLD1DUPq16wb_fixed: case ARM::VLD1DUPq16wb_register:
2694 case ARM::VLD1DUPq32wb_fixed: case ARM::VLD1DUPq32wb_register:
2695 case ARM::VLD1DUPq8wb_fixed: case ARM::VLD1DUPq8wb_register:
2696 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2697 return MCDisassembler::Fail;
2698 break;
2699 default:
2700 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2701 return MCDisassembler::Fail;
2702 break;
2703 }
Owen Andersonf1c8e3e2011-08-22 18:22:06 +00002704 if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002705 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2706 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002707 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002708
Owen Andersona6804442011-09-01 23:23:50 +00002709 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2710 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002711 Inst.addOperand(MCOperand::CreateImm(align));
2712
Jim Grosbach096334e2011-11-30 19:35:44 +00002713 // The fixed offset post-increment encodes Rm == 0xd. The no-writeback
2714 // variant encodes Rm == 0xf. Anything else is a register offset post-
2715 // increment and we need to add the register operand to the instruction.
2716 if (Rm != 0xD && Rm != 0xF &&
2717 !Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2718 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002719
Owen Anderson83e3f672011-08-17 17:44:15 +00002720 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002721}
2722
Craig Topperc89c7442012-03-27 07:21:54 +00002723static DecodeStatus DecodeVLD2DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002724 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002725 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002726
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002727 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2728 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2729 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2730 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2731 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2732 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002733 align *= 2*size;
2734
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002735 switch (Inst.getOpcode()) {
2736 case ARM::VLD2DUPd16: case ARM::VLD2DUPd32: case ARM::VLD2DUPd8:
2737 case ARM::VLD2DUPd16wb_fixed: case ARM::VLD2DUPd16wb_register:
2738 case ARM::VLD2DUPd32wb_fixed: case ARM::VLD2DUPd32wb_register:
2739 case ARM::VLD2DUPd8wb_fixed: case ARM::VLD2DUPd8wb_register:
2740 if (!Check(S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder)))
2741 return MCDisassembler::Fail;
2742 break;
Jim Grosbach4d0983a2012-03-06 23:10:38 +00002743 case ARM::VLD2DUPd16x2: case ARM::VLD2DUPd32x2: case ARM::VLD2DUPd8x2:
2744 case ARM::VLD2DUPd16x2wb_fixed: case ARM::VLD2DUPd16x2wb_register:
2745 case ARM::VLD2DUPd32x2wb_fixed: case ARM::VLD2DUPd32x2wb_register:
2746 case ARM::VLD2DUPd8x2wb_fixed: case ARM::VLD2DUPd8x2wb_register:
2747 if (!Check(S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder)))
2748 return MCDisassembler::Fail;
2749 break;
Jim Grosbachc0fc4502012-03-06 22:01:44 +00002750 default:
2751 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2752 return MCDisassembler::Fail;
2753 break;
2754 }
Kevin Enderby158c8a42012-03-06 18:33:12 +00002755
2756 if (Rm != 0xF)
2757 Inst.addOperand(MCOperand::CreateImm(0));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002758
Owen Andersona6804442011-09-01 23:23:50 +00002759 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2760 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002761 Inst.addOperand(MCOperand::CreateImm(align));
2762
Kevin Enderbyc5a2a332012-04-17 00:49:27 +00002763 if (Rm != 0xD && Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002764 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2765 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002766 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002767
Owen Anderson83e3f672011-08-17 17:44:15 +00002768 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002769}
2770
Craig Topperc89c7442012-03-27 07:21:54 +00002771static DecodeStatus DecodeVLD3DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002772 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002773 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002774
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002775 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2776 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2777 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2778 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2779 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2780
Owen Andersona6804442011-09-01 23:23:50 +00002781 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2782 return MCDisassembler::Fail;
2783 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)))
2784 return MCDisassembler::Fail;
2785 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder)))
2786 return MCDisassembler::Fail;
Owen Andersonf1c8e3e2011-08-22 18:22:06 +00002787 if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002788 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2789 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002790 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002791
Owen Andersona6804442011-09-01 23:23:50 +00002792 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2793 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002794 Inst.addOperand(MCOperand::CreateImm(0));
2795
2796 if (Rm == 0xD)
2797 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002798 else if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002799 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2800 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002801 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002802
Owen Anderson83e3f672011-08-17 17:44:15 +00002803 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002804}
2805
Craig Topperc89c7442012-03-27 07:21:54 +00002806static DecodeStatus DecodeVLD4DupInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002807 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002808 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002809
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002810 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2811 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2812 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2813 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2814 unsigned size = fieldFromInstruction32(Insn, 6, 2);
2815 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2816 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2817
2818 if (size == 0x3) {
2819 size = 4;
2820 align = 16;
2821 } else {
2822 if (size == 2) {
2823 size = 1 << size;
2824 align *= 8;
2825 } else {
2826 size = 1 << size;
2827 align *= 4*size;
2828 }
2829 }
2830
Owen Andersona6804442011-09-01 23:23:50 +00002831 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2832 return MCDisassembler::Fail;
2833 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)))
2834 return MCDisassembler::Fail;
2835 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder)))
2836 return MCDisassembler::Fail;
2837 if (!Check(S, DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder)))
2838 return MCDisassembler::Fail;
Owen Andersonf1c8e3e2011-08-22 18:22:06 +00002839 if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002840 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2841 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002842 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002843
Owen Andersona6804442011-09-01 23:23:50 +00002844 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
2845 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002846 Inst.addOperand(MCOperand::CreateImm(align));
2847
2848 if (Rm == 0xD)
2849 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002850 else if (Rm != 0xF) {
Owen Andersona6804442011-09-01 23:23:50 +00002851 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
2852 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002853 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002854
Owen Anderson83e3f672011-08-17 17:44:15 +00002855 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002856}
2857
Owen Andersona6804442011-09-01 23:23:50 +00002858static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00002859DecodeNEONModImmInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00002860 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002861 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002862
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002863 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2864 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2865 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2866 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
2867 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
2868 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
2869 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
2870 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
2871
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002872 if (Q) {
Owen Andersona6804442011-09-01 23:23:50 +00002873 if (!Check(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)))
2874 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002875 } else {
Owen Andersona6804442011-09-01 23:23:50 +00002876 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2877 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002878 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002879
2880 Inst.addOperand(MCOperand::CreateImm(imm));
2881
2882 switch (Inst.getOpcode()) {
2883 case ARM::VORRiv4i16:
2884 case ARM::VORRiv2i32:
2885 case ARM::VBICiv4i16:
2886 case ARM::VBICiv2i32:
Owen Andersona6804442011-09-01 23:23:50 +00002887 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2888 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002889 break;
2890 case ARM::VORRiv8i16:
2891 case ARM::VORRiv4i32:
2892 case ARM::VBICiv8i16:
2893 case ARM::VBICiv4i32:
Owen Andersona6804442011-09-01 23:23:50 +00002894 if (!Check(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)))
2895 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002896 break;
2897 default:
2898 break;
2899 }
2900
Owen Anderson83e3f672011-08-17 17:44:15 +00002901 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002902}
2903
Craig Topperc89c7442012-03-27 07:21:54 +00002904static DecodeStatus DecodeVSHLMaxInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002905 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002906 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002907
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002908 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2909 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2910 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2911 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2912 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2913
Owen Andersona6804442011-09-01 23:23:50 +00002914 if (!Check(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)))
2915 return MCDisassembler::Fail;
2916 if (!Check(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)))
2917 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002918 Inst.addOperand(MCOperand::CreateImm(8 << size));
2919
Owen Anderson83e3f672011-08-17 17:44:15 +00002920 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002921}
2922
Craig Topperc89c7442012-03-27 07:21:54 +00002923static DecodeStatus DecodeShiftRight8Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002924 uint64_t Address, const void *Decoder) {
2925 Inst.addOperand(MCOperand::CreateImm(8 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00002926 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002927}
2928
Craig Topperc89c7442012-03-27 07:21:54 +00002929static DecodeStatus DecodeShiftRight16Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002930 uint64_t Address, const void *Decoder) {
2931 Inst.addOperand(MCOperand::CreateImm(16 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00002932 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002933}
2934
Craig Topperc89c7442012-03-27 07:21:54 +00002935static DecodeStatus DecodeShiftRight32Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002936 uint64_t Address, const void *Decoder) {
2937 Inst.addOperand(MCOperand::CreateImm(32 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00002938 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002939}
2940
Craig Topperc89c7442012-03-27 07:21:54 +00002941static DecodeStatus DecodeShiftRight64Imm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002942 uint64_t Address, const void *Decoder) {
2943 Inst.addOperand(MCOperand::CreateImm(64 - Val));
James Molloyc047dca2011-09-01 18:02:14 +00002944 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002945}
2946
Craig Topperc89c7442012-03-27 07:21:54 +00002947static DecodeStatus DecodeTBLInstruction(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002948 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002949 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002950
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002951 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2952 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2953 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2954 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2955 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2956 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2957 unsigned op = fieldFromInstruction32(Insn, 6, 1);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002958
Owen Andersona6804442011-09-01 23:23:50 +00002959 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2960 return MCDisassembler::Fail;
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002961 if (op) {
Owen Andersona6804442011-09-01 23:23:50 +00002962 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
2963 return MCDisassembler::Fail; // Writeback
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002964 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002965
Jim Grosbach28f08c92012-03-05 19:33:30 +00002966 switch (Inst.getOpcode()) {
2967 case ARM::VTBL2:
2968 case ARM::VTBX2:
2969 if (!Check(S, DecodeDPairRegisterClass(Inst, Rn, Address, Decoder)))
2970 return MCDisassembler::Fail;
2971 break;
2972 default:
2973 if (!Check(S, DecodeDPRRegisterClass(Inst, Rn, Address, Decoder)))
2974 return MCDisassembler::Fail;
2975 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002976
Owen Andersona6804442011-09-01 23:23:50 +00002977 if (!Check(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)))
2978 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002979
Owen Anderson83e3f672011-08-17 17:44:15 +00002980 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002981}
2982
Craig Topperc89c7442012-03-27 07:21:54 +00002983static DecodeStatus DecodeThumbAddSpecialReg(MCInst &Inst, uint16_t Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002984 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00002985 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00002986
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002987 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2988 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2989
Owen Andersona6804442011-09-01 23:23:50 +00002990 if (!Check(S, DecodetGPRRegisterClass(Inst, dst, Address, Decoder)))
2991 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002992
Owen Anderson96425c82011-08-26 18:09:22 +00002993 switch(Inst.getOpcode()) {
Owen Anderson1af7f722011-08-26 19:39:26 +00002994 default:
James Molloyc047dca2011-09-01 18:02:14 +00002995 return MCDisassembler::Fail;
Owen Anderson96425c82011-08-26 18:09:22 +00002996 case ARM::tADR:
Owen Anderson9f7e8312011-08-26 21:47:57 +00002997 break; // tADR does not explicitly represent the PC as an operand.
Owen Anderson96425c82011-08-26 18:09:22 +00002998 case ARM::tADDrSPi:
2999 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3000 break;
Owen Anderson96425c82011-08-26 18:09:22 +00003001 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003002
3003 Inst.addOperand(MCOperand::CreateImm(imm));
Owen Anderson83e3f672011-08-17 17:44:15 +00003004 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003005}
3006
Craig Topperc89c7442012-03-27 07:21:54 +00003007static DecodeStatus DecodeThumbBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003008 uint64_t Address, const void *Decoder) {
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003009 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<12>(Val<<1) + 4,
3010 true, 2, Inst, Decoder))
3011 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003012 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003013}
3014
Craig Topperc89c7442012-03-27 07:21:54 +00003015static DecodeStatus DecodeT2BROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003016 uint64_t Address, const void *Decoder) {
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003017 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<22>(Val<<1) + 4,
3018 true, 4, Inst, Decoder))
3019 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
James Molloyc047dca2011-09-01 18:02:14 +00003020 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003021}
3022
Craig Topperc89c7442012-03-27 07:21:54 +00003023static DecodeStatus DecodeThumbCmpBROperand(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003024 uint64_t Address, const void *Decoder) {
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003025 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<7>(Val<<1) + 4,
3026 true, 2, Inst, Decoder))
3027 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003028 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003029}
3030
Craig Topperc89c7442012-03-27 07:21:54 +00003031static DecodeStatus DecodeThumbAddrModeRR(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003032 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003033 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003034
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003035 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
3036 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
3037
Owen Andersona6804442011-09-01 23:23:50 +00003038 if (!Check(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)))
3039 return MCDisassembler::Fail;
3040 if (!Check(S, DecodetGPRRegisterClass(Inst, Rm, Address, Decoder)))
3041 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003042
Owen Anderson83e3f672011-08-17 17:44:15 +00003043 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003044}
3045
Craig Topperc89c7442012-03-27 07:21:54 +00003046static DecodeStatus DecodeThumbAddrModeIS(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003047 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003048 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003049
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003050 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
3051 unsigned imm = fieldFromInstruction32(Val, 3, 5);
3052
Owen Andersona6804442011-09-01 23:23:50 +00003053 if (!Check(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)))
3054 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003055 Inst.addOperand(MCOperand::CreateImm(imm));
3056
Owen Anderson83e3f672011-08-17 17:44:15 +00003057 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003058}
3059
Craig Topperc89c7442012-03-27 07:21:54 +00003060static DecodeStatus DecodeThumbAddrModePC(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003061 uint64_t Address, const void *Decoder) {
Kevin Enderby9e5887b2011-10-04 22:44:48 +00003062 unsigned imm = Val << 2;
3063
3064 Inst.addOperand(MCOperand::CreateImm(imm));
3065 tryAddingPcLoadReferenceComment(Address, (Address & ~2u) + imm + 4, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003066
James Molloyc047dca2011-09-01 18:02:14 +00003067 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003068}
3069
Craig Topperc89c7442012-03-27 07:21:54 +00003070static DecodeStatus DecodeThumbAddrModeSP(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003071 uint64_t Address, const void *Decoder) {
3072 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersonb113ec52011-08-22 17:56:58 +00003073 Inst.addOperand(MCOperand::CreateImm(Val));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003074
James Molloyc047dca2011-09-01 18:02:14 +00003075 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003076}
3077
Craig Topperc89c7442012-03-27 07:21:54 +00003078static DecodeStatus DecodeT2AddrModeSOReg(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003079 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003080 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003081
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003082 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
3083 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
3084 unsigned imm = fieldFromInstruction32(Val, 0, 2);
3085
Owen Andersona6804442011-09-01 23:23:50 +00003086 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3087 return MCDisassembler::Fail;
3088 if (!Check(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder)))
3089 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003090 Inst.addOperand(MCOperand::CreateImm(imm));
3091
Owen Anderson83e3f672011-08-17 17:44:15 +00003092 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003093}
3094
Craig Topperc89c7442012-03-27 07:21:54 +00003095static DecodeStatus DecodeT2LoadShift(MCInst &Inst, unsigned Insn,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003096 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003097 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003098
Owen Anderson82265a22011-08-23 17:51:38 +00003099 switch (Inst.getOpcode()) {
3100 case ARM::t2PLDs:
3101 case ARM::t2PLDWs:
3102 case ARM::t2PLIs:
3103 break;
3104 default: {
3105 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
Owen Anderson31d485e2011-09-23 21:07:25 +00003106 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00003107 return MCDisassembler::Fail;
Owen Anderson82265a22011-08-23 17:51:38 +00003108 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003109 }
3110
3111 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3112 if (Rn == 0xF) {
3113 switch (Inst.getOpcode()) {
3114 case ARM::t2LDRBs:
3115 Inst.setOpcode(ARM::t2LDRBpci);
3116 break;
3117 case ARM::t2LDRHs:
3118 Inst.setOpcode(ARM::t2LDRHpci);
3119 break;
3120 case ARM::t2LDRSHs:
3121 Inst.setOpcode(ARM::t2LDRSHpci);
3122 break;
3123 case ARM::t2LDRSBs:
3124 Inst.setOpcode(ARM::t2LDRSBpci);
3125 break;
3126 case ARM::t2PLDs:
3127 Inst.setOpcode(ARM::t2PLDi12);
3128 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
3129 break;
3130 default:
James Molloyc047dca2011-09-01 18:02:14 +00003131 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003132 }
3133
3134 int imm = fieldFromInstruction32(Insn, 0, 12);
3135 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
3136 Inst.addOperand(MCOperand::CreateImm(imm));
3137
Owen Anderson83e3f672011-08-17 17:44:15 +00003138 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003139 }
3140
3141 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
3142 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
3143 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
Owen Andersona6804442011-09-01 23:23:50 +00003144 if (!Check(S, DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder)))
3145 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003146
Owen Anderson83e3f672011-08-17 17:44:15 +00003147 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003148}
3149
Craig Topperc89c7442012-03-27 07:21:54 +00003150static DecodeStatus DecodeT2Imm8S4(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003151 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003152 int imm = Val & 0xFF;
3153 if (!(Val & 0x100)) imm *= -1;
3154 Inst.addOperand(MCOperand::CreateImm(imm << 2));
3155
James Molloyc047dca2011-09-01 18:02:14 +00003156 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003157}
3158
Craig Topperc89c7442012-03-27 07:21:54 +00003159static DecodeStatus DecodeT2AddrModeImm8s4(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003160 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003161 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003162
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003163 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
3164 unsigned imm = fieldFromInstruction32(Val, 0, 9);
3165
Owen Andersona6804442011-09-01 23:23:50 +00003166 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3167 return MCDisassembler::Fail;
3168 if (!Check(S, DecodeT2Imm8S4(Inst, imm, Address, Decoder)))
3169 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003170
Owen Anderson83e3f672011-08-17 17:44:15 +00003171 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003172}
3173
Craig Topperc89c7442012-03-27 07:21:54 +00003174static DecodeStatus DecodeT2AddrModeImm0_1020s4(MCInst &Inst,unsigned Val,
Jim Grosbachb6aed502011-09-09 18:37:27 +00003175 uint64_t Address, const void *Decoder) {
3176 DecodeStatus S = MCDisassembler::Success;
3177
3178 unsigned Rn = fieldFromInstruction32(Val, 8, 4);
3179 unsigned imm = fieldFromInstruction32(Val, 0, 8);
3180
3181 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
3182 return MCDisassembler::Fail;
3183
3184 Inst.addOperand(MCOperand::CreateImm(imm));
3185
3186 return S;
3187}
3188
Craig Topperc89c7442012-03-27 07:21:54 +00003189static DecodeStatus DecodeT2Imm8(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003190 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003191 int imm = Val & 0xFF;
Owen Anderson705b48f2011-09-16 21:08:33 +00003192 if (Val == 0)
3193 imm = INT32_MIN;
3194 else if (!(Val & 0x100))
3195 imm *= -1;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003196 Inst.addOperand(MCOperand::CreateImm(imm));
3197
James Molloyc047dca2011-09-01 18:02:14 +00003198 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003199}
3200
3201
Craig Topperc89c7442012-03-27 07:21:54 +00003202static DecodeStatus DecodeT2AddrModeImm8(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003203 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003204 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003205
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003206 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
3207 unsigned imm = fieldFromInstruction32(Val, 0, 9);
3208
3209 // Some instructions always use an additive offset.
3210 switch (Inst.getOpcode()) {
3211 case ARM::t2LDRT:
3212 case ARM::t2LDRBT:
3213 case ARM::t2LDRHT:
3214 case ARM::t2LDRSBT:
3215 case ARM::t2LDRSHT:
Owen Andersonecd1c552011-09-19 18:07:10 +00003216 case ARM::t2STRT:
3217 case ARM::t2STRBT:
3218 case ARM::t2STRHT:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003219 imm |= 0x100;
3220 break;
3221 default:
3222 break;
3223 }
3224
Owen Andersona6804442011-09-01 23:23:50 +00003225 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3226 return MCDisassembler::Fail;
3227 if (!Check(S, DecodeT2Imm8(Inst, imm, Address, Decoder)))
3228 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003229
Owen Anderson83e3f672011-08-17 17:44:15 +00003230 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003231}
3232
Craig Topperc89c7442012-03-27 07:21:54 +00003233static DecodeStatus DecodeT2LdStPre(MCInst &Inst, unsigned Insn,
Owen Andersona3157b42011-09-12 18:56:30 +00003234 uint64_t Address, const void *Decoder) {
3235 DecodeStatus S = MCDisassembler::Success;
3236
3237 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3238 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3239 unsigned addr = fieldFromInstruction32(Insn, 0, 8);
3240 addr |= fieldFromInstruction32(Insn, 9, 1) << 8;
3241 addr |= Rn << 9;
3242 unsigned load = fieldFromInstruction32(Insn, 20, 1);
3243
3244 if (!load) {
3245 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3246 return MCDisassembler::Fail;
3247 }
3248
Owen Andersone4f2df92011-09-16 22:42:36 +00003249 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
Owen Andersona3157b42011-09-12 18:56:30 +00003250 return MCDisassembler::Fail;
3251
3252 if (load) {
3253 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3254 return MCDisassembler::Fail;
3255 }
3256
3257 if (!Check(S, DecodeT2AddrModeImm8(Inst, addr, Address, Decoder)))
3258 return MCDisassembler::Fail;
3259
3260 return S;
3261}
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003262
Craig Topperc89c7442012-03-27 07:21:54 +00003263static DecodeStatus DecodeT2AddrModeImm12(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003264 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003265 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003266
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003267 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
3268 unsigned imm = fieldFromInstruction32(Val, 0, 12);
3269
Owen Andersona6804442011-09-01 23:23:50 +00003270 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3271 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003272 Inst.addOperand(MCOperand::CreateImm(imm));
3273
Owen Anderson83e3f672011-08-17 17:44:15 +00003274 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003275}
3276
3277
Craig Topperc89c7442012-03-27 07:21:54 +00003278static DecodeStatus DecodeThumbAddSPImm(MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003279 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003280 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
3281
3282 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3283 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3284 Inst.addOperand(MCOperand::CreateImm(imm));
3285
James Molloyc047dca2011-09-01 18:02:14 +00003286 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003287}
3288
Craig Topperc89c7442012-03-27 07:21:54 +00003289static DecodeStatus DecodeThumbAddSPReg(MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003290 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003291 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003292
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003293 if (Inst.getOpcode() == ARM::tADDrSP) {
3294 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
3295 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
3296
Owen Andersona6804442011-09-01 23:23:50 +00003297 if (!Check(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)))
3298 return MCDisassembler::Fail;
3299 if (!Check(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)))
3300 return MCDisassembler::Fail;
Owen Anderson99906832011-08-25 18:30:18 +00003301 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003302 } else if (Inst.getOpcode() == ARM::tADDspr) {
3303 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
3304
3305 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
3306 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersona6804442011-09-01 23:23:50 +00003307 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3308 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003309 }
3310
Owen Anderson83e3f672011-08-17 17:44:15 +00003311 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003312}
3313
Craig Topperc89c7442012-03-27 07:21:54 +00003314static DecodeStatus DecodeThumbCPS(MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003315 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003316 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
3317 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
3318
3319 Inst.addOperand(MCOperand::CreateImm(imod));
3320 Inst.addOperand(MCOperand::CreateImm(flags));
3321
James Molloyc047dca2011-09-01 18:02:14 +00003322 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003323}
3324
Craig Topperc89c7442012-03-27 07:21:54 +00003325static DecodeStatus DecodePostIdxReg(MCInst &Inst, unsigned Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003326 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003327 DecodeStatus S = MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003328 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3329 unsigned add = fieldFromInstruction32(Insn, 4, 1);
3330
Silviu Barangab7c2ed62012-03-22 13:24:43 +00003331 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)))
Owen Andersona6804442011-09-01 23:23:50 +00003332 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003333 Inst.addOperand(MCOperand::CreateImm(add));
3334
Owen Anderson83e3f672011-08-17 17:44:15 +00003335 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003336}
3337
Craig Topperc89c7442012-03-27 07:21:54 +00003338static DecodeStatus DecodeThumbBLXOffset(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003339 uint64_t Address, const void *Decoder) {
Jim Grosbach01817c32011-10-20 17:28:20 +00003340 if (!tryAddingSymbolicOperand(Address,
Kevin Enderby9e5887b2011-10-04 22:44:48 +00003341 (Address & ~2u) + SignExtend32<22>(Val << 1) + 4,
3342 true, 4, Inst, Decoder))
3343 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003344 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003345}
3346
Craig Topperc89c7442012-03-27 07:21:54 +00003347static DecodeStatus DecodeCoprocessor(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003348 uint64_t Address, const void *Decoder) {
3349 if (Val == 0xA || Val == 0xB)
James Molloyc047dca2011-09-01 18:02:14 +00003350 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003351
3352 Inst.addOperand(MCOperand::CreateImm(Val));
James Molloyc047dca2011-09-01 18:02:14 +00003353 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003354}
3355
Owen Andersona6804442011-09-01 23:23:50 +00003356static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00003357DecodeThumbTableBranch(MCInst &Inst, unsigned Insn,
Jim Grosbach7f739be2011-09-19 22:21:13 +00003358 uint64_t Address, const void *Decoder) {
3359 DecodeStatus S = MCDisassembler::Success;
3360
3361 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3362 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3363
3364 if (Rn == ARM::SP) S = MCDisassembler::SoftFail;
3365 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3366 return MCDisassembler::Fail;
3367 if (!Check(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder)))
3368 return MCDisassembler::Fail;
3369 return S;
3370}
3371
3372static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00003373DecodeThumb2BCCInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00003374 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003375 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003376
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003377 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
3378 if (pred == 0xE || pred == 0xF) {
Owen Andersonb45b11b2011-08-31 22:00:41 +00003379 unsigned opc = fieldFromInstruction32(Insn, 4, 28);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003380 switch (opc) {
3381 default:
James Molloyc047dca2011-09-01 18:02:14 +00003382 return MCDisassembler::Fail;
Owen Andersonb45b11b2011-08-31 22:00:41 +00003383 case 0xf3bf8f4:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003384 Inst.setOpcode(ARM::t2DSB);
3385 break;
Owen Andersonb45b11b2011-08-31 22:00:41 +00003386 case 0xf3bf8f5:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003387 Inst.setOpcode(ARM::t2DMB);
3388 break;
Owen Andersonb45b11b2011-08-31 22:00:41 +00003389 case 0xf3bf8f6:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003390 Inst.setOpcode(ARM::t2ISB);
Owen Anderson6de3c6f2011-09-07 17:55:19 +00003391 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003392 }
3393
3394 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
Owen Andersonc36481c2011-08-09 23:25:42 +00003395 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003396 }
3397
3398 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
3399 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
3400 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
3401 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
3402 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
3403
Owen Andersona6804442011-09-01 23:23:50 +00003404 if (!Check(S, DecodeT2BROperand(Inst, brtarget, Address, Decoder)))
3405 return MCDisassembler::Fail;
3406 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3407 return MCDisassembler::Fail;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003408
Owen Anderson83e3f672011-08-17 17:44:15 +00003409 return S;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003410}
3411
3412// Decode a shifted immediate operand. These basically consist
3413// of an 8-bit value, and a 4-bit directive that specifies either
3414// a splat operation or a rotation.
Craig Topperc89c7442012-03-27 07:21:54 +00003415static DecodeStatus DecodeT2SOImm(MCInst &Inst, unsigned Val,
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003416 uint64_t Address, const void *Decoder) {
3417 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
3418 if (ctrl == 0) {
3419 unsigned byte = fieldFromInstruction32(Val, 8, 2);
3420 unsigned imm = fieldFromInstruction32(Val, 0, 8);
3421 switch (byte) {
3422 case 0:
3423 Inst.addOperand(MCOperand::CreateImm(imm));
3424 break;
3425 case 1:
3426 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
3427 break;
3428 case 2:
3429 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
3430 break;
3431 case 3:
3432 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
3433 (imm << 8) | imm));
3434 break;
3435 }
3436 } else {
3437 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
3438 unsigned rot = fieldFromInstruction32(Val, 7, 5);
3439 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
3440 Inst.addOperand(MCOperand::CreateImm(imm));
3441 }
3442
James Molloyc047dca2011-09-01 18:02:14 +00003443 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003444}
3445
Owen Andersona6804442011-09-01 23:23:50 +00003446static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00003447DecodeThumbBCCTargetOperand(MCInst &Inst, unsigned Val,
Jim Grosbachc4057822011-08-17 21:58:18 +00003448 uint64_t Address, const void *Decoder){
Kevin Enderby2a7d3a92012-04-12 23:13:34 +00003449 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<8>(Val<<1) + 4,
3450 true, 2, Inst, Decoder))
3451 Inst.addOperand(MCOperand::CreateImm(SignExtend32<8>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003452 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003453}
3454
Craig Topperc89c7442012-03-27 07:21:54 +00003455static DecodeStatus DecodeThumbBLTargetOperand(MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00003456 uint64_t Address, const void *Decoder){
Kevin Enderby09433032012-02-27 18:15:15 +00003457 if (!tryAddingSymbolicOperand(Address, Address + SignExtend32<22>(Val<<1) + 4,
Kevin Enderbyb80d5712012-02-23 18:18:17 +00003458 true, 4, Inst, Decoder))
3459 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
James Molloyc047dca2011-09-01 18:02:14 +00003460 return MCDisassembler::Success;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003461}
3462
Craig Topperc89c7442012-03-27 07:21:54 +00003463static DecodeStatus DecodeMemBarrierOption(MCInst &Inst, unsigned Val,
Owen Andersonc36481c2011-08-09 23:25:42 +00003464 uint64_t Address, const void *Decoder) {
3465 switch (Val) {
3466 default:
James Molloyc047dca2011-09-01 18:02:14 +00003467 return MCDisassembler::Fail;
Owen Andersonc36481c2011-08-09 23:25:42 +00003468 case 0xF: // SY
3469 case 0xE: // ST
3470 case 0xB: // ISH
3471 case 0xA: // ISHST
3472 case 0x7: // NSH
3473 case 0x6: // NSHST
3474 case 0x3: // OSH
3475 case 0x2: // OSHST
3476 break;
3477 }
3478
3479 Inst.addOperand(MCOperand::CreateImm(Val));
James Molloyc047dca2011-09-01 18:02:14 +00003480 return MCDisassembler::Success;
Owen Andersonc36481c2011-08-09 23:25:42 +00003481}
3482
Craig Topperc89c7442012-03-27 07:21:54 +00003483static DecodeStatus DecodeMSRMask(MCInst &Inst, unsigned Val,
Owen Anderson26d2f0a2011-08-11 20:21:46 +00003484 uint64_t Address, const void *Decoder) {
James Molloyc047dca2011-09-01 18:02:14 +00003485 if (!Val) return MCDisassembler::Fail;
Owen Anderson26d2f0a2011-08-11 20:21:46 +00003486 Inst.addOperand(MCOperand::CreateImm(Val));
James Molloyc047dca2011-09-01 18:02:14 +00003487 return MCDisassembler::Success;
Owen Anderson26d2f0a2011-08-11 20:21:46 +00003488}
Owen Andersoncbfc0442011-08-11 21:34:58 +00003489
Craig Topperc89c7442012-03-27 07:21:54 +00003490static DecodeStatus DecodeDoubleRegLoad(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00003491 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003492 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003493
Owen Anderson3f3570a2011-08-12 17:58:32 +00003494 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3495 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3496 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
3497
James Molloyc047dca2011-09-01 18:02:14 +00003498 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return MCDisassembler::Fail;
Owen Anderson3f3570a2011-08-12 17:58:32 +00003499
Owen Andersona6804442011-09-01 23:23:50 +00003500 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3501 return MCDisassembler::Fail;
3502 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)))
3503 return MCDisassembler::Fail;
3504 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3505 return MCDisassembler::Fail;
3506 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3507 return MCDisassembler::Fail;
Owen Anderson3f3570a2011-08-12 17:58:32 +00003508
Owen Anderson83e3f672011-08-17 17:44:15 +00003509 return S;
Owen Anderson3f3570a2011-08-12 17:58:32 +00003510}
3511
3512
Craig Topperc89c7442012-03-27 07:21:54 +00003513static DecodeStatus DecodeDoubleRegStore(MCInst &Inst, unsigned Insn,
Jim Grosbachc4057822011-08-17 21:58:18 +00003514 uint64_t Address, const void *Decoder){
Owen Andersona6804442011-09-01 23:23:50 +00003515 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003516
Owen Andersoncbfc0442011-08-11 21:34:58 +00003517 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3518 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
3519 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
Owen Andersonadf2b092011-08-11 22:08:38 +00003520 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
Owen Andersoncbfc0442011-08-11 21:34:58 +00003521
Owen Andersona6804442011-09-01 23:23:50 +00003522 if (!Check(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)))
3523 return MCDisassembler::Fail;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003524
James Molloyc047dca2011-09-01 18:02:14 +00003525 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return MCDisassembler::Fail;
3526 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return MCDisassembler::Fail;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003527
Owen Andersona6804442011-09-01 23:23:50 +00003528 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3529 return MCDisassembler::Fail;
3530 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)))
3531 return MCDisassembler::Fail;
3532 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3533 return MCDisassembler::Fail;
3534 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3535 return MCDisassembler::Fail;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003536
Owen Anderson83e3f672011-08-17 17:44:15 +00003537 return S;
Owen Andersoncbfc0442011-08-11 21:34:58 +00003538}
3539
Craig Topperc89c7442012-03-27 07:21:54 +00003540static DecodeStatus DecodeLDRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003541 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003542 DecodeStatus S = MCDisassembler::Success;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003543
3544 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3545 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3546 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
3547 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
3548 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
3549 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
3550
James Molloyc047dca2011-09-01 18:02:14 +00003551 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003552
Owen Andersona6804442011-09-01 23:23:50 +00003553 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3554 return MCDisassembler::Fail;
3555 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3556 return MCDisassembler::Fail;
3557 if (!Check(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder)))
3558 return MCDisassembler::Fail;
3559 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3560 return MCDisassembler::Fail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003561
3562 return S;
3563}
3564
Craig Topperc89c7442012-03-27 07:21:54 +00003565static DecodeStatus DecodeLDRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson9ab0f252011-08-26 20:43:14 +00003566 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003567 DecodeStatus S = MCDisassembler::Success;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003568
3569 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3570 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3571 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
3572 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
3573 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
3574 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
3575 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3576
James Molloyc047dca2011-09-01 18:02:14 +00003577 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
3578 if (Rm == 0xF) S = MCDisassembler::SoftFail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003579
Owen Andersona6804442011-09-01 23:23:50 +00003580 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3581 return MCDisassembler::Fail;
3582 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3583 return MCDisassembler::Fail;
3584 if (!Check(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder)))
3585 return MCDisassembler::Fail;
3586 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3587 return MCDisassembler::Fail;
Owen Anderson9ab0f252011-08-26 20:43:14 +00003588
3589 return S;
3590}
3591
3592
Craig Topperc89c7442012-03-27 07:21:54 +00003593static DecodeStatus DecodeSTRPreImm(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +00003594 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003595 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003596
Owen Anderson7cdbf082011-08-12 18:12:39 +00003597 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3598 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3599 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
3600 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
3601 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
3602 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
Owen Andersoncbfc0442011-08-11 21:34:58 +00003603
James Molloyc047dca2011-09-01 18:02:14 +00003604 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003605
Owen Andersona6804442011-09-01 23:23:50 +00003606 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3607 return MCDisassembler::Fail;
3608 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3609 return MCDisassembler::Fail;
3610 if (!Check(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder)))
3611 return MCDisassembler::Fail;
3612 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3613 return MCDisassembler::Fail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003614
Owen Anderson83e3f672011-08-17 17:44:15 +00003615 return S;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003616}
3617
Craig Topperc89c7442012-03-27 07:21:54 +00003618static DecodeStatus DecodeSTRPreReg(MCInst &Inst, unsigned Insn,
Owen Anderson7cdbf082011-08-12 18:12:39 +00003619 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003620 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003621
Owen Anderson7cdbf082011-08-12 18:12:39 +00003622 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3623 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3624 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
3625 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
3626 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
3627 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
3628
James Molloyc047dca2011-09-01 18:02:14 +00003629 if (Rn == 0xF || Rn == Rt) S = MCDisassembler::SoftFail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003630
Owen Andersona6804442011-09-01 23:23:50 +00003631 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3632 return MCDisassembler::Fail;
3633 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)))
3634 return MCDisassembler::Fail;
3635 if (!Check(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder)))
3636 return MCDisassembler::Fail;
3637 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
3638 return MCDisassembler::Fail;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003639
Owen Anderson83e3f672011-08-17 17:44:15 +00003640 return S;
Owen Anderson7cdbf082011-08-12 18:12:39 +00003641}
Owen Anderson7a2e1772011-08-15 18:44:44 +00003642
Craig Topperc89c7442012-03-27 07:21:54 +00003643static DecodeStatus DecodeVLD1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003644 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003645 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003646
Owen Anderson7a2e1772011-08-15 18:44:44 +00003647 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3648 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3649 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3650 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3651 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3652
3653 unsigned align = 0;
3654 unsigned index = 0;
3655 switch (size) {
3656 default:
James Molloyc047dca2011-09-01 18:02:14 +00003657 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003658 case 0:
3659 if (fieldFromInstruction32(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003660 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003661 index = fieldFromInstruction32(Insn, 5, 3);
3662 break;
3663 case 1:
3664 if (fieldFromInstruction32(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003665 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003666 index = fieldFromInstruction32(Insn, 6, 2);
3667 if (fieldFromInstruction32(Insn, 4, 1))
3668 align = 2;
3669 break;
3670 case 2:
3671 if (fieldFromInstruction32(Insn, 6, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003672 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003673 index = fieldFromInstruction32(Insn, 7, 1);
3674 if (fieldFromInstruction32(Insn, 4, 2) != 0)
3675 align = 4;
3676 }
3677
Owen Andersona6804442011-09-01 23:23:50 +00003678 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3679 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003680 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003681 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3682 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003683 }
Owen Andersona6804442011-09-01 23:23:50 +00003684 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3685 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003686 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003687 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003688 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003689 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3690 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003691 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003692 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003693 }
3694
Owen Andersona6804442011-09-01 23:23:50 +00003695 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3696 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003697 Inst.addOperand(MCOperand::CreateImm(index));
3698
Owen Anderson83e3f672011-08-17 17:44:15 +00003699 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003700}
3701
Craig Topperc89c7442012-03-27 07:21:54 +00003702static DecodeStatus DecodeVST1LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003703 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003704 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003705
Owen Anderson7a2e1772011-08-15 18:44:44 +00003706 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3707 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3708 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3709 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3710 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3711
3712 unsigned align = 0;
3713 unsigned index = 0;
3714 switch (size) {
3715 default:
James Molloyc047dca2011-09-01 18:02:14 +00003716 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003717 case 0:
3718 if (fieldFromInstruction32(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003719 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003720 index = fieldFromInstruction32(Insn, 5, 3);
3721 break;
3722 case 1:
3723 if (fieldFromInstruction32(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003724 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003725 index = fieldFromInstruction32(Insn, 6, 2);
3726 if (fieldFromInstruction32(Insn, 4, 1))
3727 align = 2;
3728 break;
3729 case 2:
3730 if (fieldFromInstruction32(Insn, 6, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003731 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003732 index = fieldFromInstruction32(Insn, 7, 1);
3733 if (fieldFromInstruction32(Insn, 4, 2) != 0)
3734 align = 4;
3735 }
3736
3737 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003738 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3739 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003740 }
Owen Andersona6804442011-09-01 23:23:50 +00003741 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3742 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003743 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003744 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003745 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003746 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3747 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003748 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003749 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003750 }
3751
Owen Andersona6804442011-09-01 23:23:50 +00003752 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3753 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003754 Inst.addOperand(MCOperand::CreateImm(index));
3755
Owen Anderson83e3f672011-08-17 17:44:15 +00003756 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003757}
3758
3759
Craig Topperc89c7442012-03-27 07:21:54 +00003760static DecodeStatus DecodeVLD2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003761 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003762 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003763
Owen Anderson7a2e1772011-08-15 18:44:44 +00003764 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3765 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3766 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3767 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3768 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3769
3770 unsigned align = 0;
3771 unsigned index = 0;
3772 unsigned inc = 1;
3773 switch (size) {
3774 default:
James Molloyc047dca2011-09-01 18:02:14 +00003775 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003776 case 0:
3777 index = fieldFromInstruction32(Insn, 5, 3);
3778 if (fieldFromInstruction32(Insn, 4, 1))
3779 align = 2;
3780 break;
3781 case 1:
3782 index = fieldFromInstruction32(Insn, 6, 2);
3783 if (fieldFromInstruction32(Insn, 4, 1))
3784 align = 4;
3785 if (fieldFromInstruction32(Insn, 5, 1))
3786 inc = 2;
3787 break;
3788 case 2:
3789 if (fieldFromInstruction32(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003790 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003791 index = fieldFromInstruction32(Insn, 7, 1);
3792 if (fieldFromInstruction32(Insn, 4, 1) != 0)
3793 align = 8;
3794 if (fieldFromInstruction32(Insn, 6, 1))
3795 inc = 2;
3796 break;
3797 }
3798
Owen Andersona6804442011-09-01 23:23:50 +00003799 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3800 return MCDisassembler::Fail;
3801 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3802 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003803 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003804 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3805 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003806 }
Owen Andersona6804442011-09-01 23:23:50 +00003807 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3808 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003809 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003810 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003811 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003812 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3813 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003814 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003815 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003816 }
3817
Owen Andersona6804442011-09-01 23:23:50 +00003818 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3819 return MCDisassembler::Fail;
3820 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3821 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003822 Inst.addOperand(MCOperand::CreateImm(index));
3823
Owen Anderson83e3f672011-08-17 17:44:15 +00003824 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003825}
3826
Craig Topperc89c7442012-03-27 07:21:54 +00003827static DecodeStatus DecodeVST2LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003828 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003829 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003830
Owen Anderson7a2e1772011-08-15 18:44:44 +00003831 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3832 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3833 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3834 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3835 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3836
3837 unsigned align = 0;
3838 unsigned index = 0;
3839 unsigned inc = 1;
3840 switch (size) {
3841 default:
James Molloyc047dca2011-09-01 18:02:14 +00003842 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003843 case 0:
3844 index = fieldFromInstruction32(Insn, 5, 3);
3845 if (fieldFromInstruction32(Insn, 4, 1))
3846 align = 2;
3847 break;
3848 case 1:
3849 index = fieldFromInstruction32(Insn, 6, 2);
3850 if (fieldFromInstruction32(Insn, 4, 1))
3851 align = 4;
3852 if (fieldFromInstruction32(Insn, 5, 1))
3853 inc = 2;
3854 break;
3855 case 2:
3856 if (fieldFromInstruction32(Insn, 5, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003857 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003858 index = fieldFromInstruction32(Insn, 7, 1);
3859 if (fieldFromInstruction32(Insn, 4, 1) != 0)
3860 align = 8;
3861 if (fieldFromInstruction32(Insn, 6, 1))
3862 inc = 2;
3863 break;
3864 }
3865
3866 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003867 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3868 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003869 }
Owen Andersona6804442011-09-01 23:23:50 +00003870 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3871 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003872 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00003873 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003874 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003875 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3876 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003877 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003878 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003879 }
3880
Owen Andersona6804442011-09-01 23:23:50 +00003881 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3882 return MCDisassembler::Fail;
3883 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3884 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003885 Inst.addOperand(MCOperand::CreateImm(index));
3886
Owen Anderson83e3f672011-08-17 17:44:15 +00003887 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003888}
3889
3890
Craig Topperc89c7442012-03-27 07:21:54 +00003891static DecodeStatus DecodeVLD3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003892 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003893 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003894
Owen Anderson7a2e1772011-08-15 18:44:44 +00003895 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3896 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3897 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3898 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3899 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3900
3901 unsigned align = 0;
3902 unsigned index = 0;
3903 unsigned inc = 1;
3904 switch (size) {
3905 default:
James Molloyc047dca2011-09-01 18:02:14 +00003906 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003907 case 0:
3908 if (fieldFromInstruction32(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003909 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003910 index = fieldFromInstruction32(Insn, 5, 3);
3911 break;
3912 case 1:
3913 if (fieldFromInstruction32(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003914 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003915 index = fieldFromInstruction32(Insn, 6, 2);
3916 if (fieldFromInstruction32(Insn, 5, 1))
3917 inc = 2;
3918 break;
3919 case 2:
3920 if (fieldFromInstruction32(Insn, 4, 2))
James Molloyc047dca2011-09-01 18:02:14 +00003921 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003922 index = fieldFromInstruction32(Insn, 7, 1);
3923 if (fieldFromInstruction32(Insn, 6, 1))
3924 inc = 2;
3925 break;
3926 }
3927
Owen Andersona6804442011-09-01 23:23:50 +00003928 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3929 return MCDisassembler::Fail;
3930 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3931 return MCDisassembler::Fail;
3932 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
3933 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003934
3935 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003936 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3937 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003938 }
Owen Andersona6804442011-09-01 23:23:50 +00003939 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
3940 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003941 Inst.addOperand(MCOperand::CreateImm(align));
Owen Andersoneaca9282011-08-30 22:58:27 +00003942 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00003943 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00003944 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
3945 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00003946 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00003947 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00003948 }
3949
Owen Andersona6804442011-09-01 23:23:50 +00003950 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
3951 return MCDisassembler::Fail;
3952 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
3953 return MCDisassembler::Fail;
3954 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
3955 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003956 Inst.addOperand(MCOperand::CreateImm(index));
3957
Owen Anderson83e3f672011-08-17 17:44:15 +00003958 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003959}
3960
Craig Topperc89c7442012-03-27 07:21:54 +00003961static DecodeStatus DecodeVST3LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00003962 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00003963 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00003964
Owen Anderson7a2e1772011-08-15 18:44:44 +00003965 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3966 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3967 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3968 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3969 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3970
3971 unsigned align = 0;
3972 unsigned index = 0;
3973 unsigned inc = 1;
3974 switch (size) {
3975 default:
James Molloyc047dca2011-09-01 18:02:14 +00003976 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00003977 case 0:
3978 if (fieldFromInstruction32(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003979 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003980 index = fieldFromInstruction32(Insn, 5, 3);
3981 break;
3982 case 1:
3983 if (fieldFromInstruction32(Insn, 4, 1))
James Molloyc047dca2011-09-01 18:02:14 +00003984 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003985 index = fieldFromInstruction32(Insn, 6, 2);
3986 if (fieldFromInstruction32(Insn, 5, 1))
3987 inc = 2;
3988 break;
3989 case 2:
3990 if (fieldFromInstruction32(Insn, 4, 2))
James Molloyc047dca2011-09-01 18:02:14 +00003991 return MCDisassembler::Fail; // UNDEFINED
Owen Anderson7a2e1772011-08-15 18:44:44 +00003992 index = fieldFromInstruction32(Insn, 7, 1);
3993 if (fieldFromInstruction32(Insn, 6, 1))
3994 inc = 2;
3995 break;
3996 }
3997
3998 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00003999 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4000 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004001 }
Owen Andersona6804442011-09-01 23:23:50 +00004002 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4003 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004004 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004005 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004006 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004007 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4008 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004009 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004010 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004011 }
4012
Owen Andersona6804442011-09-01 23:23:50 +00004013 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4014 return MCDisassembler::Fail;
4015 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4016 return MCDisassembler::Fail;
4017 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4018 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004019 Inst.addOperand(MCOperand::CreateImm(index));
4020
Owen Anderson83e3f672011-08-17 17:44:15 +00004021 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004022}
4023
4024
Craig Topperc89c7442012-03-27 07:21:54 +00004025static DecodeStatus DecodeVLD4LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00004026 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004027 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00004028
Owen Anderson7a2e1772011-08-15 18:44:44 +00004029 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
4030 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
4031 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
4032 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
4033 unsigned size = fieldFromInstruction32(Insn, 10, 2);
4034
4035 unsigned align = 0;
4036 unsigned index = 0;
4037 unsigned inc = 1;
4038 switch (size) {
4039 default:
James Molloyc047dca2011-09-01 18:02:14 +00004040 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004041 case 0:
4042 if (fieldFromInstruction32(Insn, 4, 1))
4043 align = 4;
4044 index = fieldFromInstruction32(Insn, 5, 3);
4045 break;
4046 case 1:
4047 if (fieldFromInstruction32(Insn, 4, 1))
4048 align = 8;
4049 index = fieldFromInstruction32(Insn, 6, 2);
4050 if (fieldFromInstruction32(Insn, 5, 1))
4051 inc = 2;
4052 break;
4053 case 2:
4054 if (fieldFromInstruction32(Insn, 4, 2))
4055 align = 4 << fieldFromInstruction32(Insn, 4, 2);
4056 index = fieldFromInstruction32(Insn, 7, 1);
4057 if (fieldFromInstruction32(Insn, 6, 1))
4058 inc = 2;
4059 break;
4060 }
4061
Owen Andersona6804442011-09-01 23:23:50 +00004062 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4063 return MCDisassembler::Fail;
4064 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4065 return MCDisassembler::Fail;
4066 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4067 return MCDisassembler::Fail;
4068 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)))
4069 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004070
4071 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004072 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4073 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004074 }
Owen Andersona6804442011-09-01 23:23:50 +00004075 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4076 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004077 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004078 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004079 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004080 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4081 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004082 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004083 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004084 }
4085
Owen Andersona6804442011-09-01 23:23:50 +00004086 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4087 return MCDisassembler::Fail;
4088 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4089 return MCDisassembler::Fail;
4090 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4091 return MCDisassembler::Fail;
4092 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)))
4093 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004094 Inst.addOperand(MCOperand::CreateImm(index));
4095
Owen Anderson83e3f672011-08-17 17:44:15 +00004096 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004097}
4098
Craig Topperc89c7442012-03-27 07:21:54 +00004099static DecodeStatus DecodeVST4LN(MCInst &Inst, unsigned Insn,
Owen Anderson7a2e1772011-08-15 18:44:44 +00004100 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004101 DecodeStatus S = MCDisassembler::Success;
Owen Anderson83e3f672011-08-17 17:44:15 +00004102
Owen Anderson7a2e1772011-08-15 18:44:44 +00004103 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
4104 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
4105 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
4106 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
4107 unsigned size = fieldFromInstruction32(Insn, 10, 2);
4108
4109 unsigned align = 0;
4110 unsigned index = 0;
4111 unsigned inc = 1;
4112 switch (size) {
4113 default:
James Molloyc047dca2011-09-01 18:02:14 +00004114 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004115 case 0:
4116 if (fieldFromInstruction32(Insn, 4, 1))
4117 align = 4;
4118 index = fieldFromInstruction32(Insn, 5, 3);
4119 break;
4120 case 1:
4121 if (fieldFromInstruction32(Insn, 4, 1))
4122 align = 8;
4123 index = fieldFromInstruction32(Insn, 6, 2);
4124 if (fieldFromInstruction32(Insn, 5, 1))
4125 inc = 2;
4126 break;
4127 case 2:
4128 if (fieldFromInstruction32(Insn, 4, 2))
4129 align = 4 << fieldFromInstruction32(Insn, 4, 2);
4130 index = fieldFromInstruction32(Insn, 7, 1);
4131 if (fieldFromInstruction32(Insn, 6, 1))
4132 inc = 2;
4133 break;
4134 }
4135
4136 if (Rm != 0xF) { // Writeback
Owen Andersona6804442011-09-01 23:23:50 +00004137 if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
4138 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004139 }
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 Inst.addOperand(MCOperand::CreateImm(align));
Owen Anderson2cbf2102011-08-22 18:42:13 +00004143 if (Rm != 0xF) {
James Molloyc047dca2011-09-01 18:02:14 +00004144 if (Rm != 0xD) {
Owen Andersona6804442011-09-01 23:23:50 +00004145 if (!Check(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)))
4146 return MCDisassembler::Fail;
James Molloyc047dca2011-09-01 18:02:14 +00004147 } else
Owen Anderson2cbf2102011-08-22 18:42:13 +00004148 Inst.addOperand(MCOperand::CreateReg(0));
Owen Anderson7a2e1772011-08-15 18:44:44 +00004149 }
4150
Owen Andersona6804442011-09-01 23:23:50 +00004151 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)))
4152 return MCDisassembler::Fail;
4153 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)))
4154 return MCDisassembler::Fail;
4155 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)))
4156 return MCDisassembler::Fail;
4157 if (!Check(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)))
4158 return MCDisassembler::Fail;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004159 Inst.addOperand(MCOperand::CreateImm(index));
4160
Owen Anderson83e3f672011-08-17 17:44:15 +00004161 return S;
Owen Anderson7a2e1772011-08-15 18:44:44 +00004162}
4163
Craig Topperc89c7442012-03-27 07:21:54 +00004164static DecodeStatus DecodeVMOVSRR(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +00004165 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004166 DecodeStatus S = MCDisassembler::Success;
Owen Anderson357ec682011-08-22 20:27:12 +00004167 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
4168 unsigned Rt2 = fieldFromInstruction32(Insn, 16, 4);
4169 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
4170 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
4171 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
4172
4173 if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F)
James Molloyc047dca2011-09-01 18:02:14 +00004174 S = MCDisassembler::SoftFail;
Owen Anderson357ec682011-08-22 20:27:12 +00004175
Owen Andersona6804442011-09-01 23:23:50 +00004176 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder)))
4177 return MCDisassembler::Fail;
4178 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm+1, Address, Decoder)))
4179 return MCDisassembler::Fail;
4180 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder)))
4181 return MCDisassembler::Fail;
4182 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder)))
4183 return MCDisassembler::Fail;
4184 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
4185 return MCDisassembler::Fail;
Owen Anderson357ec682011-08-22 20:27:12 +00004186
4187 return S;
4188}
4189
Craig Topperc89c7442012-03-27 07:21:54 +00004190static DecodeStatus DecodeVMOVRRS(MCInst &Inst, unsigned Insn,
Owen Anderson357ec682011-08-22 20:27:12 +00004191 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004192 DecodeStatus S = MCDisassembler::Success;
Owen Anderson357ec682011-08-22 20:27:12 +00004193 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
4194 unsigned Rt2 = fieldFromInstruction32(Insn, 16, 4);
4195 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
4196 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
4197 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
4198
4199 if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F)
James Molloyc047dca2011-09-01 18:02:14 +00004200 S = MCDisassembler::SoftFail;
Owen Anderson357ec682011-08-22 20:27:12 +00004201
Owen Andersona6804442011-09-01 23:23:50 +00004202 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder)))
4203 return MCDisassembler::Fail;
4204 if (!Check(S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder)))
4205 return MCDisassembler::Fail;
4206 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder)))
4207 return MCDisassembler::Fail;
4208 if (!Check(S, DecodeSPRRegisterClass(Inst, Rm+1, Address, Decoder)))
4209 return MCDisassembler::Fail;
4210 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
4211 return MCDisassembler::Fail;
Owen Anderson357ec682011-08-22 20:27:12 +00004212
4213 return S;
4214}
Owen Anderson8e1e60b2011-08-22 23:44:04 +00004215
Craig Topperc89c7442012-03-27 07:21:54 +00004216static DecodeStatus DecodeIT(MCInst &Inst, unsigned Insn,
Owen Andersoneaca9282011-08-30 22:58:27 +00004217 uint64_t Address, const void *Decoder) {
Owen Andersona6804442011-09-01 23:23:50 +00004218 DecodeStatus S = MCDisassembler::Success;
Owen Andersoneaca9282011-08-30 22:58:27 +00004219 unsigned pred = fieldFromInstruction16(Insn, 4, 4);
4220 // The InstPrinter needs to have the low bit of the predicate in
4221 // the mask operand to be able to print it properly.
4222 unsigned mask = fieldFromInstruction16(Insn, 0, 5);
4223
4224 if (pred == 0xF) {
4225 pred = 0xE;
James Molloyc047dca2011-09-01 18:02:14 +00004226 S = MCDisassembler::SoftFail;
Owen Andersone234d022011-08-24 17:21:43 +00004227 }
4228
Owen Andersoneaca9282011-08-30 22:58:27 +00004229 if ((mask & 0xF) == 0) {
4230 // Preserve the high bit of the mask, which is the low bit of
4231 // the predicate.
4232 mask &= 0x10;
4233 mask |= 0x8;
James Molloyc047dca2011-09-01 18:02:14 +00004234 S = MCDisassembler::SoftFail;
Owen Andersonf4408202011-08-24 22:40:22 +00004235 }
Owen Andersoneaca9282011-08-30 22:58:27 +00004236
4237 Inst.addOperand(MCOperand::CreateImm(pred));
4238 Inst.addOperand(MCOperand::CreateImm(mask));
Owen Andersonf4408202011-08-24 22:40:22 +00004239 return S;
4240}
Jim Grosbacha77295d2011-09-08 22:07:06 +00004241
4242static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00004243DecodeT2LDRDPreInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +00004244 uint64_t Address, const void *Decoder) {
4245 DecodeStatus S = MCDisassembler::Success;
4246
4247 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
4248 unsigned Rt2 = fieldFromInstruction32(Insn, 8, 4);
4249 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
4250 unsigned addr = fieldFromInstruction32(Insn, 0, 8);
4251 unsigned W = fieldFromInstruction32(Insn, 21, 1);
4252 unsigned U = fieldFromInstruction32(Insn, 23, 1);
4253 unsigned P = fieldFromInstruction32(Insn, 24, 1);
4254 bool writeback = (W == 1) | (P == 0);
4255
4256 addr |= (U << 8) | (Rn << 9);
4257
4258 if (writeback && (Rn == Rt || Rn == Rt2))
4259 Check(S, MCDisassembler::SoftFail);
4260 if (Rt == Rt2)
4261 Check(S, MCDisassembler::SoftFail);
4262
4263 // Rt
4264 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
4265 return MCDisassembler::Fail;
4266 // Rt2
4267 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt2, Address, Decoder)))
4268 return MCDisassembler::Fail;
4269 // Writeback operand
4270 if (!Check(S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder)))
4271 return MCDisassembler::Fail;
4272 // addr
4273 if (!Check(S, DecodeT2AddrModeImm8s4(Inst, addr, Address, Decoder)))
4274 return MCDisassembler::Fail;
4275
4276 return S;
4277}
4278
4279static DecodeStatus
Craig Topperc89c7442012-03-27 07:21:54 +00004280DecodeT2STRDPreInstruction(MCInst &Inst, unsigned Insn,
Jim Grosbacha77295d2011-09-08 22:07:06 +00004281 uint64_t Address, const void *Decoder) {
4282 DecodeStatus S = MCDisassembler::Success;
4283
4284 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
4285 unsigned Rt2 = fieldFromInstruction32(Insn, 8, 4);
4286 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
4287 unsigned addr = fieldFromInstruction32(Insn, 0, 8);
4288 unsigned W = fieldFromInstruction32(Insn, 21, 1);
4289 unsigned U = fieldFromInstruction32(Insn, 23, 1);
4290 unsigned P = fieldFromInstruction32(Insn, 24, 1);
4291 bool writeback = (W == 1) | (P == 0);
4292
4293 addr |= (U << 8) | (Rn << 9);
4294
4295 if (writeback && (Rn == Rt || Rn == Rt2))
4296 Check(S, MCDisassembler::SoftFail);
4297
4298 // Writeback operand
4299 if (!Check(S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder)))
4300 return MCDisassembler::Fail;
4301 // Rt
4302 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder)))
4303 return MCDisassembler::Fail;
4304 // Rt2
4305 if (!Check(S, DecoderGPRRegisterClass(Inst, Rt2, Address, Decoder)))
4306 return MCDisassembler::Fail;
4307 // addr
4308 if (!Check(S, DecodeT2AddrModeImm8s4(Inst, addr, Address, Decoder)))
4309 return MCDisassembler::Fail;
4310
4311 return S;
4312}
Owen Anderson08fef882011-09-09 22:24:36 +00004313
Craig Topperc89c7442012-03-27 07:21:54 +00004314static DecodeStatus DecodeT2Adr(MCInst &Inst, uint32_t Insn,
Owen Anderson08fef882011-09-09 22:24:36 +00004315 uint64_t Address, const void *Decoder) {
4316 unsigned sign1 = fieldFromInstruction32(Insn, 21, 1);
4317 unsigned sign2 = fieldFromInstruction32(Insn, 23, 1);
4318 if (sign1 != sign2) return MCDisassembler::Fail;
4319
4320 unsigned Val = fieldFromInstruction32(Insn, 0, 8);
4321 Val |= fieldFromInstruction32(Insn, 12, 3) << 8;
4322 Val |= fieldFromInstruction32(Insn, 26, 1) << 11;
4323 Val |= sign1 << 12;
4324 Inst.addOperand(MCOperand::CreateImm(SignExtend32<13>(Val)));
4325
4326 return MCDisassembler::Success;
4327}
4328
Craig Topperc89c7442012-03-27 07:21:54 +00004329static DecodeStatus DecodeT2ShifterImmOperand(MCInst &Inst, uint32_t Val,
Owen Anderson0afa0092011-09-26 21:06:22 +00004330 uint64_t Address,
4331 const void *Decoder) {
4332 DecodeStatus S = MCDisassembler::Success;
4333
4334 // Shift of "asr #32" is not allowed in Thumb2 mode.
4335 if (Val == 0x20) S = MCDisassembler::SoftFail;
4336 Inst.addOperand(MCOperand::CreateImm(Val));
4337 return S;
4338}
4339
Craig Topperc89c7442012-03-27 07:21:54 +00004340static DecodeStatus DecodeSwap(MCInst &Inst, unsigned Insn,
Owen Andersoncb9fed62011-10-28 18:02:13 +00004341 uint64_t Address, const void *Decoder) {
4342 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
4343 unsigned Rt2 = fieldFromInstruction32(Insn, 0, 4);
4344 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
4345 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
4346
4347 if (pred == 0xF)
4348 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
4349
4350 DecodeStatus S = MCDisassembler::Success;
Silviu Baranga35ee7d22012-04-18 14:18:57 +00004351
4352 if (Rt == Rn || Rn == Rt2)
4353 S = MCDisassembler::SoftFail;
4354
Owen Andersoncb9fed62011-10-28 18:02:13 +00004355 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)))
4356 return MCDisassembler::Fail;
4357 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder)))
4358 return MCDisassembler::Fail;
4359 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
4360 return MCDisassembler::Fail;
4361 if (!Check(S, DecodePredicateOperand(Inst, pred, Address, Decoder)))
4362 return MCDisassembler::Fail;
4363
4364 return S;
4365}
Owen Andersonb589be92011-11-15 19:55:00 +00004366
Craig Topperc89c7442012-03-27 07:21:54 +00004367static DecodeStatus DecodeVCVTD(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +00004368 uint64_t Address, const void *Decoder) {
4369 unsigned Vd = (fieldFromInstruction32(Insn, 12, 4) << 0);
4370 Vd |= (fieldFromInstruction32(Insn, 22, 1) << 4);
4371 unsigned Vm = (fieldFromInstruction32(Insn, 0, 4) << 0);
4372 Vm |= (fieldFromInstruction32(Insn, 5, 1) << 4);
4373 unsigned imm = fieldFromInstruction32(Insn, 16, 6);
4374 unsigned cmode = fieldFromInstruction32(Insn, 8, 4);
4375
4376 DecodeStatus S = MCDisassembler::Success;
4377
4378 // VMOVv2f32 is ambiguous with these decodings.
Owen Anderson22925d92011-11-15 20:30:41 +00004379 if (!(imm & 0x38) && cmode == 0xF) {
Owen Andersonb589be92011-11-15 19:55:00 +00004380 Inst.setOpcode(ARM::VMOVv2f32);
4381 return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder);
4382 }
4383
4384 if (!(imm & 0x20)) Check(S, MCDisassembler::SoftFail);
4385
4386 if (!Check(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)))
4387 return MCDisassembler::Fail;
4388 if (!Check(S, DecodeDPRRegisterClass(Inst, Vm, Address, Decoder)))
4389 return MCDisassembler::Fail;
4390 Inst.addOperand(MCOperand::CreateImm(64 - imm));
4391
4392 return S;
4393}
4394
Craig Topperc89c7442012-03-27 07:21:54 +00004395static DecodeStatus DecodeVCVTQ(MCInst &Inst, unsigned Insn,
Owen Andersonb589be92011-11-15 19:55:00 +00004396 uint64_t Address, const void *Decoder) {
4397 unsigned Vd = (fieldFromInstruction32(Insn, 12, 4) << 0);
4398 Vd |= (fieldFromInstruction32(Insn, 22, 1) << 4);
4399 unsigned Vm = (fieldFromInstruction32(Insn, 0, 4) << 0);
4400 Vm |= (fieldFromInstruction32(Insn, 5, 1) << 4);
4401 unsigned imm = fieldFromInstruction32(Insn, 16, 6);
4402 unsigned cmode = fieldFromInstruction32(Insn, 8, 4);
4403
4404 DecodeStatus S = MCDisassembler::Success;
4405
4406 // VMOVv4f32 is ambiguous with these decodings.
4407 if (!(imm & 0x38) && cmode == 0xF) {
4408 Inst.setOpcode(ARM::VMOVv4f32);
4409 return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder);
4410 }
4411
4412 if (!(imm & 0x20)) Check(S, MCDisassembler::SoftFail);
4413
4414 if (!Check(S, DecodeQPRRegisterClass(Inst, Vd, Address, Decoder)))
4415 return MCDisassembler::Fail;
4416 if (!Check(S, DecodeQPRRegisterClass(Inst, Vm, Address, Decoder)))
4417 return MCDisassembler::Fail;
4418 Inst.addOperand(MCOperand::CreateImm(64 - imm));
4419
4420 return S;
4421}
Silviu Barangab7c2ed62012-03-22 13:24:43 +00004422
Craig Topperc89c7442012-03-27 07:21:54 +00004423static DecodeStatus DecodeLDR(MCInst &Inst, unsigned Val,
Silviu Barangab7c2ed62012-03-22 13:24:43 +00004424 uint64_t Address, const void *Decoder) {
4425 DecodeStatus S = MCDisassembler::Success;
4426
4427 unsigned Rn = fieldFromInstruction32(Val, 16, 4);
4428 unsigned Rt = fieldFromInstruction32(Val, 12, 4);
4429 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
4430 Rm |= (fieldFromInstruction32(Val, 23, 1) << 4);
4431 unsigned Cond = fieldFromInstruction32(Val, 28, 4);
4432
4433 if (fieldFromInstruction32(Val, 8, 4) != 0 || Rn == Rt)
4434 S = MCDisassembler::SoftFail;
4435
4436 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)))
4437 return MCDisassembler::Fail;
4438 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder)))
4439 return MCDisassembler::Fail;
4440 if (!Check(S, DecodeAddrMode7Operand(Inst, Rn, Address, Decoder)))
4441 return MCDisassembler::Fail;
4442 if (!Check(S, DecodePostIdxReg(Inst, Rm, Address, Decoder)))
4443 return MCDisassembler::Fail;
4444 if (!Check(S, DecodePredicateOperand(Inst, Cond, Address, Decoder)))
4445 return MCDisassembler::Fail;
4446
4447 return S;
4448}
4449
Silviu Barangafa1ebc62012-04-18 13:12:50 +00004450static DecodeStatus DecodeMRRC2(llvm::MCInst &Inst, unsigned Val,
4451 uint64_t Address, const void *Decoder) {
4452
4453 DecodeStatus S = MCDisassembler::Success;
4454
4455 unsigned CRm = fieldFromInstruction32(Val, 0, 4);
4456 unsigned opc1 = fieldFromInstruction32(Val, 4, 4);
4457 unsigned cop = fieldFromInstruction32(Val, 8, 4);
4458 unsigned Rt = fieldFromInstruction32(Val, 12, 4);
4459 unsigned Rt2 = fieldFromInstruction32(Val, 16, 4);
4460
4461 if ((cop & ~0x1) == 0xa)
4462 return MCDisassembler::Fail;
4463
4464 if (Rt == Rt2)
4465 S = MCDisassembler::SoftFail;
4466
4467 Inst.addOperand(MCOperand::CreateImm(cop));
4468 Inst.addOperand(MCOperand::CreateImm(opc1));
4469 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)))
4470 return MCDisassembler::Fail;
4471 if (!Check(S, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder)))
4472 return MCDisassembler::Fail;
4473 Inst.addOperand(MCOperand::CreateImm(CRm));
4474
4475 return S;
4476}
4477