| 1 | //===-- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | /* Capstone Disassembly Engine */ |
| 11 | /* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */ |
| 12 | |
| 13 | #ifdef CAPSTONE_HAS_ARM |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include <string.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <capstone/platform.h> |
| 19 | |
| 20 | #include "ARMAddressingModes.h" |
| 21 | #include "ARMBaseInfo.h" |
| 22 | #include "../../MCFixedLenDisassembler.h" |
| 23 | #include "../../MCInst.h" |
| 24 | #include "../../MCInstrDesc.h" |
| 25 | #include "../../MCRegisterInfo.h" |
| 26 | #include "../../LEB128.h" |
| 27 | #include "../../MCDisassembler.h" |
| 28 | #include "../../cs_priv.h" |
| 29 | #include "../../utils.h" |
| 30 | |
| 31 | #include "ARMDisassembler.h" |
| 32 | #include "ARMMapping.h" |
| 33 | |
| 34 | #define GET_SUBTARGETINFO_ENUM |
| 35 | #include "ARMGenSubtargetInfo.inc" |
| 36 | |
| 37 | #define GET_INSTRINFO_MC_DESC |
| 38 | #include "ARMGenInstrInfo.inc" |
| 39 | |
| 40 | #define GET_INSTRINFO_ENUM |
| 41 | #include "ARMGenInstrInfo.inc" |
| 42 | |
| 43 | static bool ITStatus_push_back(ARM_ITStatus *it, char v) |
| 44 | { |
| 45 | if (it->size >= sizeof(it->ITStates)) { |
| 46 | // TODO: consider warning user. |
| 47 | it->size = 0; |
| 48 | } |
| 49 | it->ITStates[it->size] = v; |
| 50 | it->size++; |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | // Returns true if the current instruction is in an IT block |
| 56 | static bool ITStatus_instrInITBlock(ARM_ITStatus *it) |
| 57 | { |
| 58 | //return !ITStates.empty(); |
| 59 | return (it->size > 0); |
| 60 | } |
| 61 | |
| 62 | // Returns true if current instruction is the last instruction in an IT block |
| 63 | static bool ITStatus_instrLastInITBlock(ARM_ITStatus *it) |
| 64 | { |
| 65 | return (it->size == 1); |
| 66 | } |
| 67 | |
| 68 | // Handles the condition code status of instructions in IT blocks |
| 69 | |
| 70 | // Returns the condition code for instruction in IT block |
| 71 | static unsigned ITStatus_getITCC(ARM_ITStatus *it) |
| 72 | { |
| 73 | unsigned CC = ARMCC_AL; |
| 74 | |
| 75 | if (ITStatus_instrInITBlock(it)) |
| 76 | //CC = ITStates.back(); |
| 77 | CC = it->ITStates[it->size-1]; |
| 78 | |
| 79 | return CC; |
| 80 | } |
| 81 | |
| 82 | // Advances the IT block state to the next T or E |
| 83 | static void ITStatus_advanceITState(ARM_ITStatus *it) |
| 84 | { |
| 85 | //ITStates.pop_back(); |
| 86 | it->size--; |
| 87 | } |
| 88 | |
| 89 | // Called when decoding an IT instruction. Sets the IT state for the following |
| 90 | // instructions that for the IT block. Firstcond and Mask correspond to the |
| 91 | // fields in the IT instruction encoding. |
| 92 | static void ITStatus_setITState(ARM_ITStatus *it, char Firstcond, char Mask) |
| 93 | { |
| 94 | // (3 - the number of trailing zeros) is the number of then / else. |
| 95 | unsigned CondBit0 = Firstcond & 1; |
| 96 | unsigned NumTZ = CountTrailingZeros_32(Mask); |
| 97 | unsigned char CCBits = (unsigned char)Firstcond & 0xf; |
| 98 | unsigned Pos; |
| 99 | |
| 100 | //assert(NumTZ <= 3 && "Invalid IT mask!"); |
| 101 | // push condition codes onto the stack the correct order for the pops |
| 102 | for (Pos = NumTZ + 1; Pos <= 3; ++Pos) { |
| 103 | bool T = ((Mask >> Pos) & 1) == (int)CondBit0; |
| 104 | |
| 105 | if (T) |
| 106 | ITStatus_push_back(it, CCBits); |
| 107 | else |
| 108 | ITStatus_push_back(it, CCBits ^ 1); |
| 109 | } |
| 110 | |
| 111 | ITStatus_push_back(it, CCBits); |
| 112 | } |
| 113 | |
| 114 | /// ThumbDisassembler - Thumb disassembler for all Thumb platforms. |
| 115 | |
| 116 | static bool Check(DecodeStatus *Out, DecodeStatus In) |
| 117 | { |
| 118 | switch (In) { |
| 119 | case MCDisassembler_Success: |
| 120 | // Out stays the same. |
| 121 | return true; |
| 122 | case MCDisassembler_SoftFail: |
| 123 | *Out = In; |
| 124 | return true; |
| 125 | case MCDisassembler_Fail: |
| 126 | *Out = In; |
| 127 | return false; |
| 128 | default: // never reached |
| 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Forward declare these because the autogenerated code will reference them. |
| 134 | // Definitions are further down. |
| 135 | static DecodeStatus DecodeGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 136 | uint64_t Address, const void *Decoder); |
| 137 | static DecodeStatus DecodeGPRnopcRegisterClass(MCInst *Inst, |
| 138 | unsigned RegNo, uint64_t Address, const void *Decoder); |
| 139 | static DecodeStatus DecodeGPRwithAPSRRegisterClass(MCInst *Inst, |
| 140 | unsigned RegNo, uint64_t Address, const void *Decoder); |
| 141 | static DecodeStatus DecodetGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 142 | uint64_t Address, const void *Decoder); |
| 143 | static DecodeStatus DecodetcGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 144 | uint64_t Address, const void *Decoder); |
| 145 | static DecodeStatus DecoderGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 146 | uint64_t Address, const void *Decoder); |
| 147 | static DecodeStatus DecodeGPRPairRegisterClass(MCInst *Inst, unsigned RegNo, |
| 148 | uint64_t Address, const void *Decoder); |
| 149 | static DecodeStatus DecodeSPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 150 | uint64_t Address, const void *Decoder); |
| 151 | static DecodeStatus DecodeDPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 152 | uint64_t Address, const void *Decoder); |
| 153 | static DecodeStatus DecodeDPR_8RegisterClass(MCInst *Inst, unsigned RegNo, |
| 154 | uint64_t Address, const void *Decoder); |
| 155 | static DecodeStatus DecodeDPR_VFP2RegisterClass(MCInst *Inst, |
| 156 | unsigned RegNo, uint64_t Address, const void *Decoder); |
| 157 | static DecodeStatus DecodeQPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 158 | uint64_t Address, const void *Decoder); |
| 159 | static DecodeStatus DecodeDPairRegisterClass(MCInst *Inst, unsigned RegNo, |
| 160 | uint64_t Address, const void *Decoder); |
| 161 | static DecodeStatus DecodeDPairSpacedRegisterClass(MCInst *Inst, |
| 162 | unsigned RegNo, uint64_t Address, const void *Decoder); |
| 163 | static DecodeStatus DecodePredicateOperand(MCInst *Inst, unsigned Val, |
| 164 | uint64_t Address, const void *Decoder); |
| 165 | static DecodeStatus DecodeCCOutOperand(MCInst *Inst, unsigned Val, |
| 166 | uint64_t Address, const void *Decoder); |
| 167 | static DecodeStatus DecodeRegListOperand(MCInst *Inst, unsigned Val, |
| 168 | uint64_t Address, const void *Decoder); |
| 169 | static DecodeStatus DecodeSPRRegListOperand(MCInst *Inst, unsigned Val, |
| 170 | uint64_t Address, const void *Decoder); |
| 171 | static DecodeStatus DecodeDPRRegListOperand(MCInst *Inst, unsigned Val, |
| 172 | uint64_t Address, const void *Decoder); |
| 173 | static DecodeStatus DecodeBitfieldMaskOperand(MCInst *Inst, unsigned Insn, |
| 174 | uint64_t Address, const void *Decoder); |
| 175 | static DecodeStatus DecodeCopMemInstruction(MCInst *Inst, unsigned Insn, |
| 176 | uint64_t Address, const void *Decoder); |
| 177 | static DecodeStatus DecodeAddrMode2IdxInstruction(MCInst *Inst, |
| 178 | unsigned Insn, uint64_t Address, const void *Decoder); |
| 179 | static DecodeStatus DecodeSORegMemOperand(MCInst *Inst, unsigned Insn, |
| 180 | uint64_t Address, const void *Decoder); |
| 181 | static DecodeStatus DecodeAddrMode3Instruction(MCInst *Inst,unsigned Insn, |
| 182 | uint64_t Address, const void *Decoder); |
| 183 | static DecodeStatus DecodeSORegImmOperand(MCInst *Inst, unsigned Insn, |
| 184 | uint64_t Address, const void *Decoder); |
| 185 | static DecodeStatus DecodeSORegRegOperand(MCInst *Inst, unsigned Insn, |
| 186 | uint64_t Address, const void *Decoder); |
| 187 | static DecodeStatus DecodeMemMultipleWritebackInstruction(MCInst * Inst, |
| 188 | unsigned Insn, uint64_t Adddress, const void *Decoder); |
| 189 | static DecodeStatus DecodeT2MOVTWInstruction(MCInst *Inst, unsigned Insn, |
| 190 | uint64_t Address, const void *Decoder); |
| 191 | static DecodeStatus DecodeArmMOVTWInstruction(MCInst *Inst, unsigned Insn, |
| 192 | uint64_t Address, const void *Decoder); |
| 193 | static DecodeStatus DecodeSMLAInstruction(MCInst *Inst, unsigned Insn, |
| 194 | uint64_t Address, const void *Decoder); |
| 195 | static DecodeStatus DecodeCPSInstruction(MCInst *Inst, unsigned Insn, |
| 196 | uint64_t Address, const void *Decoder); |
| 197 | static DecodeStatus DecodeT2CPSInstruction(MCInst *Inst, unsigned Insn, |
| 198 | uint64_t Address, const void *Decoder); |
| 199 | static DecodeStatus DecodeAddrModeImm12Operand(MCInst *Inst, unsigned Val, |
| 200 | uint64_t Address, const void *Decoder); |
| 201 | static DecodeStatus DecodeAddrMode5Operand(MCInst *Inst, unsigned Val, |
| 202 | uint64_t Address, const void *Decoder); |
| 203 | static DecodeStatus DecodeAddrMode7Operand(MCInst *Inst, unsigned Val, |
| 204 | uint64_t Address, const void *Decoder); |
| 205 | static DecodeStatus DecodeT2BInstruction(MCInst *Inst, unsigned Insn, |
| 206 | uint64_t Address, const void *Decoder); |
| 207 | static DecodeStatus DecodeBranchImmInstruction(MCInst *Inst,unsigned Insn, |
| 208 | uint64_t Address, const void *Decoder); |
| 209 | static DecodeStatus DecodeAddrMode6Operand(MCInst *Inst, unsigned Val, |
| 210 | uint64_t Address, const void *Decoder); |
| 211 | static DecodeStatus DecodeVLDST1Instruction(MCInst *Inst, unsigned Val, |
| 212 | uint64_t Address, const void *Decoder); |
| 213 | static DecodeStatus DecodeVLDST2Instruction(MCInst *Inst, unsigned Val, |
| 214 | uint64_t Address, const void *Decoder); |
| 215 | static DecodeStatus DecodeVLDST3Instruction(MCInst *Inst, unsigned Val, |
| 216 | uint64_t Address, const void *Decoder); |
| 217 | static DecodeStatus DecodeVLDST4Instruction(MCInst *Inst, unsigned Val, |
| 218 | uint64_t Address, const void *Decoder); |
| 219 | static DecodeStatus DecodeVLDInstruction(MCInst *Inst, unsigned Val, |
| 220 | uint64_t Address, const void *Decoder); |
| 221 | static DecodeStatus DecodeVSTInstruction(MCInst *Inst, unsigned Val, |
| 222 | uint64_t Address, const void *Decoder); |
| 223 | static DecodeStatus DecodeVLD1DupInstruction(MCInst *Inst, unsigned Val, |
| 224 | uint64_t Address, const void *Decoder); |
| 225 | static DecodeStatus DecodeVLD2DupInstruction(MCInst *Inst, unsigned Val, |
| 226 | uint64_t Address, const void *Decoder); |
| 227 | static DecodeStatus DecodeVLD3DupInstruction(MCInst *Inst, unsigned Val, |
| 228 | uint64_t Address, const void *Decoder); |
| 229 | static DecodeStatus DecodeVLD4DupInstruction(MCInst *Inst, unsigned Val, |
| 230 | uint64_t Address, const void *Decoder); |
| 231 | static DecodeStatus DecodeNEONModImmInstruction(MCInst *Inst,unsigned Val, |
| 232 | uint64_t Address, const void *Decoder); |
| 233 | static DecodeStatus DecodeVSHLMaxInstruction(MCInst *Inst, unsigned Val, |
| 234 | uint64_t Address, const void *Decoder); |
| 235 | static DecodeStatus DecodeShiftRight8Imm(MCInst *Inst, unsigned Val, |
| 236 | uint64_t Address, const void *Decoder); |
| 237 | static DecodeStatus DecodeShiftRight16Imm(MCInst *Inst, unsigned Val, |
| 238 | uint64_t Address, const void *Decoder); |
| 239 | static DecodeStatus DecodeShiftRight32Imm(MCInst *Inst, unsigned Val, |
| 240 | uint64_t Address, const void *Decoder); |
| 241 | static DecodeStatus DecodeShiftRight64Imm(MCInst *Inst, unsigned Val, |
| 242 | uint64_t Address, const void *Decoder); |
| 243 | static DecodeStatus DecodeTBLInstruction(MCInst *Inst, unsigned Insn, |
| 244 | uint64_t Address, const void *Decoder); |
| 245 | static DecodeStatus DecodePostIdxReg(MCInst *Inst, unsigned Insn, |
| 246 | uint64_t Address, const void *Decoder); |
| 247 | static DecodeStatus DecodeCoprocessor(MCInst *Inst, unsigned Insn, |
| 248 | uint64_t Address, const void *Decoder); |
| 249 | static DecodeStatus DecodeMemBarrierOption(MCInst *Inst, unsigned Insn, |
| 250 | uint64_t Address, const void *Decoder); |
| 251 | static DecodeStatus DecodeInstSyncBarrierOption(MCInst *Inst, unsigned Insn, |
| 252 | uint64_t Address, const void *Decoder); |
| 253 | static DecodeStatus DecodeMSRMask(MCInst *Inst, unsigned Insn, |
| 254 | uint64_t Address, const void *Decoder); |
| 255 | static DecodeStatus DecodeBankedReg(MCInst *Inst, unsigned Insn, |
| 256 | uint64_t Address, const void *Decoder); |
| 257 | static DecodeStatus DecodeDoubleRegLoad(MCInst *Inst, unsigned Insn, |
| 258 | uint64_t Address, const void *Decoder); |
| 259 | static DecodeStatus DecodeDoubleRegStore(MCInst *Inst, unsigned Insn, |
| 260 | uint64_t Address, const void *Decoder); |
| 261 | static DecodeStatus DecodeLDRPreImm(MCInst *Inst, unsigned Insn, |
| 262 | uint64_t Address, const void *Decoder); |
| 263 | static DecodeStatus DecodeLDRPreReg(MCInst *Inst, unsigned Insn, |
| 264 | uint64_t Address, const void *Decoder); |
| 265 | static DecodeStatus DecodeSTRPreImm(MCInst *Inst, unsigned Insn, |
| 266 | uint64_t Address, const void *Decoder); |
| 267 | static DecodeStatus DecodeSTRPreReg(MCInst *Inst, unsigned Insn, |
| 268 | uint64_t Address, const void *Decoder); |
| 269 | static DecodeStatus DecodeVLD1LN(MCInst *Inst, unsigned Insn, |
| 270 | uint64_t Address, const void *Decoder); |
| 271 | static DecodeStatus DecodeVLD2LN(MCInst *Inst, unsigned Insn, |
| 272 | uint64_t Address, const void *Decoder); |
| 273 | static DecodeStatus DecodeVLD3LN(MCInst *Inst, unsigned Insn, |
| 274 | uint64_t Address, const void *Decoder); |
| 275 | static DecodeStatus DecodeVLD4LN(MCInst *Inst, unsigned Insn, |
| 276 | uint64_t Address, const void *Decoder); |
| 277 | static DecodeStatus DecodeVST1LN(MCInst *Inst, unsigned Insn, |
| 278 | uint64_t Address, const void *Decoder); |
| 279 | static DecodeStatus DecodeVST2LN(MCInst *Inst, unsigned Insn, |
| 280 | uint64_t Address, const void *Decoder); |
| 281 | static DecodeStatus DecodeVST3LN(MCInst *Inst, unsigned Insn, |
| 282 | uint64_t Address, const void *Decoder); |
| 283 | static DecodeStatus DecodeVST4LN(MCInst *Inst, unsigned Insn, |
| 284 | uint64_t Address, const void *Decoder); |
| 285 | static DecodeStatus DecodeVMOVSRR(MCInst *Inst, unsigned Insn, |
| 286 | uint64_t Address, const void *Decoder); |
| 287 | static DecodeStatus DecodeVMOVRRS(MCInst *Inst, unsigned Insn, |
| 288 | uint64_t Address, const void *Decoder); |
| 289 | static DecodeStatus DecodeSwap(MCInst *Inst, unsigned Insn, |
| 290 | uint64_t Address, const void *Decoder); |
| 291 | static DecodeStatus DecodeVCVTD(MCInst *Inst, unsigned Insn, |
| 292 | uint64_t Address, const void *Decoder); |
| 293 | static DecodeStatus DecodeVCVTQ(MCInst *Inst, unsigned Insn, |
| 294 | uint64_t Address, const void *Decoder); |
| 295 | static DecodeStatus DecodeThumbAddSpecialReg(MCInst *Inst, uint16_t Insn, |
| 296 | uint64_t Address, const void *Decoder); |
| 297 | static DecodeStatus DecodeThumbBROperand(MCInst *Inst, unsigned Val, |
| 298 | uint64_t Address, const void *Decoder); |
| 299 | static DecodeStatus DecodeT2BROperand(MCInst *Inst, unsigned Val, |
| 300 | uint64_t Address, const void *Decoder); |
| 301 | static DecodeStatus DecodeThumbCmpBROperand(MCInst *Inst, unsigned Val, |
| 302 | uint64_t Address, const void *Decoder); |
| 303 | static DecodeStatus DecodeThumbAddrModeRR(MCInst *Inst, unsigned Val, |
| 304 | uint64_t Address, const void *Decoder); |
| 305 | static DecodeStatus DecodeThumbAddrModeIS(MCInst *Inst, unsigned Val, |
| 306 | uint64_t Address, const void *Decoder); |
| 307 | static DecodeStatus DecodeThumbAddrModePC(MCInst *Inst, unsigned Val, |
| 308 | uint64_t Address, const void *Decoder); |
| 309 | static DecodeStatus DecodeThumbAddrModeSP(MCInst *Inst, unsigned Val, |
| 310 | uint64_t Address, const void *Decoder); |
| 311 | static DecodeStatus DecodeT2AddrModeSOReg(MCInst *Inst, unsigned Val, |
| 312 | uint64_t Address, const void *Decoder); |
| 313 | static DecodeStatus DecodeT2LoadShift(MCInst *Inst, unsigned Val, |
| 314 | uint64_t Address, const void *Decoder); |
| 315 | static DecodeStatus DecodeT2LoadImm8(MCInst *Inst, unsigned Insn, |
| 316 | uint64_t Address, const void* Decoder); |
| 317 | static DecodeStatus DecodeT2LoadImm12(MCInst *Inst, unsigned Insn, |
| 318 | uint64_t Address, const void* Decoder); |
| 319 | static DecodeStatus DecodeT2LoadT(MCInst *Inst, unsigned Insn, |
| 320 | uint64_t Address, const void* Decoder); |
| 321 | static DecodeStatus DecodeT2LoadLabel(MCInst *Inst, unsigned Insn, |
| 322 | uint64_t Address, const void* Decoder); |
| 323 | static DecodeStatus DecodeT2Imm8S4(MCInst *Inst, unsigned Val, |
| 324 | uint64_t Address, const void *Decoder); |
| 325 | static DecodeStatus DecodeT2AddrModeImm8s4(MCInst *Inst, unsigned Val, |
| 326 | uint64_t Address, const void *Decoder); |
| 327 | static DecodeStatus DecodeT2AddrModeImm0_1020s4(MCInst *Inst,unsigned Val, |
| 328 | uint64_t Address, const void *Decoder); |
| 329 | static DecodeStatus DecodeT2Imm8(MCInst *Inst, unsigned Val, |
| 330 | uint64_t Address, const void *Decoder); |
| 331 | static DecodeStatus DecodeT2AddrModeImm8(MCInst *Inst, unsigned Val, |
| 332 | uint64_t Address, const void *Decoder); |
| 333 | static DecodeStatus DecodeThumbAddSPImm(MCInst *Inst, uint16_t Val, |
| 334 | uint64_t Address, const void *Decoder); |
| 335 | static DecodeStatus DecodeThumbAddSPReg(MCInst *Inst, uint16_t Insn, |
| 336 | uint64_t Address, const void *Decoder); |
| 337 | static DecodeStatus DecodeThumbCPS(MCInst *Inst, uint16_t Insn, |
| 338 | uint64_t Address, const void *Decoder); |
| 339 | static DecodeStatus DecodeQADDInstruction(MCInst *Inst, unsigned Insn, |
| 340 | uint64_t Address, const void *Decoder); |
| 341 | static DecodeStatus DecodeThumbBLXOffset(MCInst *Inst, unsigned Insn, |
| 342 | uint64_t Address, const void *Decoder); |
| 343 | static DecodeStatus DecodeT2AddrModeImm12(MCInst *Inst, unsigned Val, |
| 344 | uint64_t Address, const void *Decoder); |
| 345 | static DecodeStatus DecodeThumbTableBranch(MCInst *Inst, unsigned Val, |
| 346 | uint64_t Address, const void *Decoder); |
| 347 | static DecodeStatus DecodeThumb2BCCInstruction(MCInst *Inst, unsigned Val, |
| 348 | uint64_t Address, const void *Decoder); |
| 349 | static DecodeStatus DecodeT2SOImm(MCInst *Inst, unsigned Val, |
| 350 | uint64_t Address, const void *Decoder); |
| 351 | static DecodeStatus DecodeThumbBCCTargetOperand(MCInst *Inst,unsigned Val, |
| 352 | uint64_t Address, const void *Decoder); |
| 353 | static DecodeStatus DecodeThumbBLTargetOperand(MCInst *Inst, unsigned Val, |
| 354 | uint64_t Address, const void *Decoder); |
| 355 | static DecodeStatus DecodeIT(MCInst *Inst, unsigned Val, |
| 356 | uint64_t Address, const void *Decoder); |
| 357 | static DecodeStatus DecodeT2LDRDPreInstruction(MCInst *Inst,unsigned Insn, |
| 358 | uint64_t Address, const void *Decoder); |
| 359 | static DecodeStatus DecodeT2STRDPreInstruction(MCInst *Inst,unsigned Insn, |
| 360 | uint64_t Address, const void *Decoder); |
| 361 | static DecodeStatus DecodeT2Adr(MCInst *Inst, uint32_t Val, |
| 362 | uint64_t Address, const void *Decoder); |
| 363 | static DecodeStatus DecodeT2LdStPre(MCInst *Inst, unsigned Val, |
| 364 | uint64_t Address, const void *Decoder); |
| 365 | static DecodeStatus DecodeT2ShifterImmOperand(MCInst *Inst, uint32_t Val, |
| 366 | uint64_t Address, const void *Decoder); |
| 367 | static DecodeStatus DecodeLDR(MCInst *Inst, unsigned Val, |
| 368 | uint64_t Address, const void *Decoder); |
| 369 | static DecodeStatus DecoderForMRRC2AndMCRR2(MCInst *Inst, unsigned Val, |
| 370 | uint64_t Address, const void *Decoder); |
| 371 | static DecodeStatus DecodeHINTInstruction(MCInst *Inst, unsigned Insn, |
| 372 | uint64_t Address, const void *Decoder); |
| 373 | static DecodeStatus DecodeTSTInstruction(MCInst *Inst, unsigned Insn, |
| 374 | uint64_t Address, const void *Decoder); |
| 375 | static DecodeStatus DecodeSETPANInstruction(MCInst *Inst, unsigned Insn, |
| 376 | uint64_t Address, const void *Decoder); |
| 377 | static DecodeStatus DecodeAddrMode5FP16Operand(MCInst *Inst, unsigned Val, |
| 378 | uint64_t Address, const void *Decoder); |
| 379 | static DecodeStatus DecodeForVMRSandVMSR(MCInst *Inst, unsigned Val, |
| 380 | uint64_t Address, const void *Decoder); |
| 381 | static DecodeStatus DecodeNEONComplexLane64Instruction(MCInst *Inst, unsigned Insn, |
| 382 | uint64_t Address, const void *Decoder); |
| 383 | static DecodeStatus DecodeHPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 384 | uint64_t Address, const void *Decoder); |
| 385 | |
| 386 | // Hacky: enable all features for disassembler |
| 387 | bool ARM_getFeatureBits(unsigned int mode, unsigned int feature) |
| 388 | { |
| 389 | if ((mode & CS_MODE_V8) == 0) { |
| 390 | // not V8 mode |
| 391 | if (feature == ARM_HasV8Ops || feature == ARM_HasV8_1aOps || |
| 392 | feature == ARM_HasV8_4aOps || feature == ARM_HasV8_3aOps) |
| 393 | // HasV8MBaselineOps |
| 394 | return false; |
| 395 | } |
| 396 | if (feature == ARM_FeatureVFPOnlySP) |
| 397 | return false; |
| 398 | |
| 399 | if ((mode & CS_MODE_MCLASS) == 0) { |
| 400 | if (feature == ARM_FeatureMClass) |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | if ((mode & CS_MODE_THUMB) == 0) { |
| 405 | // not Thumb |
| 406 | if (feature == ARM_FeatureThumb2 || feature == ARM_ModeThumb) |
| 407 | return false; |
| 408 | // FIXME: what mode enables D16? |
| 409 | if (feature == ARM_FeatureD16) |
| 410 | return false; |
| 411 | } else { |
| 412 | // Thumb |
| 413 | if (feature == ARM_FeatureD16) |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | if (feature == ARM_FeatureMClass && (mode & CS_MODE_MCLASS) == 0) |
| 418 | return false; |
| 419 | |
| 420 | // we support everything |
| 421 | return true; |
| 422 | } |
| 423 | |
| 424 | #include "ARMGenDisassemblerTables.inc" |
| 425 | |
| 426 | static DecodeStatus DecodePredicateOperand(MCInst *Inst, unsigned Val, |
| 427 | uint64_t Address, const void *Decoder) |
| 428 | { |
| 429 | if (Val == 0xF) return MCDisassembler_Fail; |
| 430 | |
| 431 | // AL predicate is not allowed on Thumb1 branches. |
| 432 | if (MCInst_getOpcode(Inst) == ARM_tBcc && Val == 0xE) |
| 433 | return MCDisassembler_Fail; |
| 434 | |
| 435 | MCOperand_CreateImm0(Inst, Val); |
| 436 | |
| 437 | if (Val == ARMCC_AL) { |
| 438 | MCOperand_CreateReg0(Inst, 0); |
| 439 | } else |
| 440 | MCOperand_CreateReg0(Inst, ARM_CPSR); |
| 441 | |
| 442 | return MCDisassembler_Success; |
| 443 | } |
| 444 | |
| 445 | #define GET_REGINFO_MC_DESC |
| 446 | #include "ARMGenRegisterInfo.inc" |
| 447 | void ARM_init(MCRegisterInfo *MRI) |
| 448 | { |
| 449 | /* |
| 450 | InitMCRegisterInfo(ARMRegDesc, 289, |
| 451 | RA, PC, |
| 452 | ARMMCRegisterClasses, 103, |
| 453 | ARMRegUnitRoots, 77, ARMRegDiffLists, ARMRegStrings, |
| 454 | ARMSubRegIdxLists, 57, |
| 455 | ARMSubRegIdxRanges, ARMRegEncodingTable); |
| 456 | */ |
| 457 | |
| 458 | MCRegisterInfo_InitMCRegisterInfo(MRI, ARMRegDesc, 289, |
| 459 | 0, 0, |
| 460 | ARMMCRegisterClasses, 103, |
| 461 | 0, 0, ARMRegDiffLists, 0, |
| 462 | ARMSubRegIdxLists, 57, |
| 463 | 0); |
| 464 | } |
| 465 | |
| 466 | // Post-decoding checks |
| 467 | static DecodeStatus checkDecodedInstruction(MCInst *MI, |
| 468 | uint32_t Insn, |
| 469 | DecodeStatus Result) |
| 470 | { |
| 471 | switch (MCInst_getOpcode(MI)) { |
| 472 | case ARM_HVC: { |
| 473 | // HVC is undefined if condition = 0xf otherwise upredictable |
| 474 | // if condition != 0xe |
| 475 | uint32_t Cond = (Insn >> 28) & 0xF; |
| 476 | |
| 477 | if (Cond == 0xF) |
| 478 | return MCDisassembler_Fail; |
| 479 | |
| 480 | if (Cond != 0xE) |
| 481 | return MCDisassembler_SoftFail; |
| 482 | |
| 483 | return Result; |
| 484 | } |
| 485 | default: |
| 486 | return Result; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | static DecodeStatus _ARM_getInstruction(cs_struct *ud, MCInst *MI, const uint8_t *code, size_t code_len, |
| 491 | uint16_t *Size, uint64_t Address) |
| 492 | { |
| 493 | uint32_t insn; |
| 494 | DecodeStatus result; |
| 495 | |
| 496 | *Size = 0; |
| 497 | |
| 498 | if (code_len < 4) |
| 499 | // not enough data |
| 500 | return MCDisassembler_Fail; |
| 501 | |
| 502 | if (MI->flat_insn->detail) { |
| 503 | unsigned int i; |
| 504 | |
| 505 | memset(MI->flat_insn->detail, 0, offsetof(cs_detail, arm) + sizeof(cs_arm)); |
| 506 | |
| 507 | for (i = 0; i < ARR_SIZE(MI->flat_insn->detail->arm.operands); i++) { |
| 508 | MI->flat_insn->detail->arm.operands[i].vector_index = -1; |
| 509 | MI->flat_insn->detail->arm.operands[i].neon_lane = -1; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | if (MODE_IS_BIG_ENDIAN(ud->mode)) |
| 514 | insn = (code[3] << 0) | (code[2] << 8) | |
| 515 | (code[1] << 16) | ((uint32_t) code[0] << 24); |
| 516 | else |
| 517 | insn = ((uint32_t) code[3] << 24) | (code[2] << 16) | |
| 518 | (code[1] << 8) | (code[0] << 0); |
| 519 | |
| 520 | // Calling the auto-generated decoder function. |
| 521 | result = decodeInstruction_4(DecoderTableARM32, MI, insn, Address); |
| 522 | if (result != MCDisassembler_Fail) { |
| 523 | result = checkDecodedInstruction(MI, insn, result); |
| 524 | if (result != MCDisassembler_Fail) |
| 525 | *Size = 4; |
| 526 | |
| 527 | return result; |
| 528 | } |
| 529 | |
| 530 | // VFP and NEON instructions, similarly, are shared between ARM |
| 531 | // and Thumb modes. |
| 532 | MCInst_clear(MI); |
| 533 | result = decodeInstruction_4(DecoderTableVFP32, MI, insn, Address); |
| 534 | if (result != MCDisassembler_Fail) { |
| 535 | *Size = 4; |
| 536 | return result; |
| 537 | } |
| 538 | |
| 539 | MCInst_clear(MI); |
| 540 | result = decodeInstruction_4(DecoderTableVFPV832, MI, insn, Address); |
| 541 | if (result != MCDisassembler_Fail) { |
| 542 | *Size = 4; |
| 543 | return result; |
| 544 | } |
| 545 | |
| 546 | MCInst_clear(MI); |
| 547 | result = decodeInstruction_4(DecoderTableNEONData32, MI, insn, Address); |
| 548 | if (result != MCDisassembler_Fail) { |
| 549 | *Size = 4; |
| 550 | // Add a fake predicate operand, because we share these instruction |
| 551 | // definitions with Thumb2 where these instructions are predicable. |
| 552 | if (!DecodePredicateOperand(MI, 0xE, Address, NULL)) |
| 553 | return MCDisassembler_Fail; |
| 554 | return result; |
| 555 | } |
| 556 | |
| 557 | MCInst_clear(MI); |
| 558 | result = decodeInstruction_4(DecoderTableNEONLoadStore32, MI, insn, Address); |
| 559 | if (result != MCDisassembler_Fail) { |
| 560 | *Size = 4; |
| 561 | // Add a fake predicate operand, because we share these instruction |
| 562 | // definitions with Thumb2 where these instructions are predicable. |
| 563 | if (!DecodePredicateOperand(MI, 0xE, Address, NULL)) |
| 564 | return MCDisassembler_Fail; |
| 565 | return result; |
| 566 | } |
| 567 | |
| 568 | MCInst_clear(MI); |
| 569 | result = decodeInstruction_4(DecoderTableNEONDup32, MI, insn, Address); |
| 570 | if (result != MCDisassembler_Fail) { |
| 571 | *Size = 4; |
| 572 | // Add a fake predicate operand, because we share these instruction |
| 573 | // definitions with Thumb2 where these instructions are predicable. |
| 574 | if (!DecodePredicateOperand(MI, 0xE, Address, NULL)) |
| 575 | return MCDisassembler_Fail; |
| 576 | return result; |
| 577 | } |
| 578 | |
| 579 | MCInst_clear(MI); |
| 580 | result = decodeInstruction_4(DecoderTablev8NEON32, MI, insn, Address); |
| 581 | if (result != MCDisassembler_Fail) { |
| 582 | *Size = 4; |
| 583 | return result; |
| 584 | } |
| 585 | |
| 586 | MCInst_clear(MI); |
| 587 | result = decodeInstruction_4(DecoderTablev8Crypto32, MI, insn, Address); |
| 588 | if (result != MCDisassembler_Fail) { |
| 589 | *Size = 4; |
| 590 | return result; |
| 591 | } |
| 592 | |
| 593 | result = decodeInstruction_4(DecoderTableCoProc32, MI, insn, Address); |
| 594 | if (result != MCDisassembler_Fail) { |
| 595 | result = checkDecodedInstruction(MI, insn, result); |
| 596 | if (result != MCDisassembler_Fail) |
| 597 | *Size = 4; |
| 598 | |
| 599 | return result; |
| 600 | } |
| 601 | |
| 602 | MCInst_clear(MI); |
| 603 | *Size = 0; |
| 604 | return MCDisassembler_Fail; |
| 605 | } |
| 606 | |
| 607 | // Thumb1 instructions don't have explicit S bits. Rather, they |
| 608 | // implicitly set CPSR. Since it's not represented in the encoding, the |
| 609 | // auto-generated decoder won't inject the CPSR operand. We need to fix |
| 610 | // that as a post-pass. |
| 611 | static void AddThumb1SBit(MCInst *MI, bool InITBlock) |
| 612 | { |
| 613 | const MCOperandInfo *OpInfo = ARMInsts[MCInst_getOpcode(MI)].OpInfo; |
| 614 | unsigned short NumOps = ARMInsts[MCInst_getOpcode(MI)].NumOperands; |
| 615 | unsigned i; |
| 616 | |
| 617 | for (i = 0; i < NumOps; ++i) { |
| 618 | if (i == MCInst_getNumOperands(MI)) break; |
| 619 | |
| 620 | if (MCOperandInfo_isOptionalDef(&OpInfo[i]) && OpInfo[i].RegClass == ARM_CCRRegClassID) { |
| 621 | if (i > 0 && MCOperandInfo_isPredicate(&OpInfo[i - 1])) continue; |
| 622 | MCInst_insert0(MI, i, MCOperand_CreateReg1(MI, InITBlock ? 0 : ARM_CPSR)); |
| 623 | return; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | //MI.insert(I, MCOperand_CreateReg0(Inst, InITBlock ? 0 : ARM_CPSR)); |
| 628 | MCInst_insert0(MI, i, MCOperand_CreateReg1(MI, InITBlock ? 0 : ARM_CPSR)); |
| 629 | } |
| 630 | |
| 631 | // Most Thumb instructions don't have explicit predicates in the |
| 632 | // encoding, but rather get their predicates from IT context. We need |
| 633 | // to fix up the predicate operands using this context information as a |
| 634 | // post-pass. |
| 635 | static DecodeStatus AddThumbPredicate(cs_struct *ud, MCInst *MI) |
| 636 | { |
| 637 | DecodeStatus S = MCDisassembler_Success; |
| 638 | const MCOperandInfo *OpInfo; |
| 639 | unsigned short NumOps; |
| 640 | unsigned int i; |
| 641 | unsigned CC; |
| 642 | |
| 643 | // A few instructions actually have predicates encoded in them. Don't |
| 644 | // try to overwrite it if we're seeing one of those. |
| 645 | switch (MCInst_getOpcode(MI)) { |
| 646 | case ARM_tBcc: |
| 647 | case ARM_t2Bcc: |
| 648 | case ARM_tCBZ: |
| 649 | case ARM_tCBNZ: |
| 650 | case ARM_tCPS: |
| 651 | case ARM_t2CPS3p: |
| 652 | case ARM_t2CPS2p: |
| 653 | case ARM_t2CPS1p: |
| 654 | case ARM_tMOVSr: |
| 655 | case ARM_tSETEND: |
| 656 | // Some instructions (mostly conditional branches) are not |
| 657 | // allowed in IT blocks. |
| 658 | if (ITStatus_instrInITBlock(&(ud->ITBlock))) |
| 659 | S = MCDisassembler_SoftFail; |
| 660 | else |
| 661 | return MCDisassembler_Success; |
| 662 | break; |
| 663 | |
| 664 | case ARM_t2HINT: |
| 665 | if (MCOperand_getImm(MCInst_getOperand(MI, 0)) == 0x10) |
| 666 | S = MCDisassembler_SoftFail; |
| 667 | break; |
| 668 | |
| 669 | case ARM_tB: |
| 670 | case ARM_t2B: |
| 671 | case ARM_t2TBB: |
| 672 | case ARM_t2TBH: |
| 673 | // Some instructions (mostly unconditional branches) can |
| 674 | // only appears at the end of, or outside of, an IT. |
| 675 | // if (ITBlock.instrInITBlock() && !ITBlock.instrLastInITBlock()) |
| 676 | if (ITStatus_instrInITBlock(&(ud->ITBlock)) && !ITStatus_instrLastInITBlock(&(ud->ITBlock))) |
| 677 | S = MCDisassembler_SoftFail; |
| 678 | break; |
| 679 | default: |
| 680 | break; |
| 681 | } |
| 682 | |
| 683 | // If we're in an IT block, base the predicate on that. Otherwise, |
| 684 | // assume a predicate of AL. |
| 685 | CC = ITStatus_getITCC(&(ud->ITBlock)); |
| 686 | if (CC == 0xF) |
| 687 | CC = ARMCC_AL; |
| 688 | |
| 689 | if (ITStatus_instrInITBlock(&(ud->ITBlock))) |
| 690 | ITStatus_advanceITState(&(ud->ITBlock)); |
| 691 | |
| 692 | OpInfo = ARMInsts[MCInst_getOpcode(MI)].OpInfo; |
| 693 | NumOps = ARMInsts[MCInst_getOpcode(MI)].NumOperands; |
| 694 | |
| 695 | for (i = 0; i < NumOps; ++i) { |
| 696 | if (i == MCInst_getNumOperands(MI)) break; |
| 697 | |
| 698 | if (MCOperandInfo_isPredicate(&OpInfo[i])) { |
| 699 | MCInst_insert0(MI, i, MCOperand_CreateImm1(MI, CC)); |
| 700 | |
| 701 | if (CC == ARMCC_AL) |
| 702 | MCInst_insert0(MI, i+1, MCOperand_CreateReg1(MI, 0)); |
| 703 | else |
| 704 | MCInst_insert0(MI, i+1, MCOperand_CreateReg1(MI, ARM_CPSR)); |
| 705 | |
| 706 | return S; |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | MCInst_insert0(MI, i, MCOperand_CreateImm1(MI, CC)); |
| 711 | |
| 712 | if (CC == ARMCC_AL) |
| 713 | MCInst_insert0(MI, i + 1, MCOperand_CreateReg1(MI, 0)); |
| 714 | else |
| 715 | MCInst_insert0(MI, i + 1, MCOperand_CreateReg1(MI, ARM_CPSR)); |
| 716 | |
| 717 | return S; |
| 718 | } |
| 719 | |
| 720 | // Thumb VFP instructions are a special case. Because we share their |
| 721 | // encodings between ARM and Thumb modes, and they are predicable in ARM |
| 722 | // mode, the auto-generated decoder will give them an (incorrect) |
| 723 | // predicate operand. We need to rewrite these operands based on the IT |
| 724 | // context as a post-pass. |
| 725 | static void UpdateThumbVFPPredicate(cs_struct *ud, MCInst *MI) |
| 726 | { |
| 727 | unsigned CC; |
| 728 | unsigned short NumOps; |
| 729 | const MCOperandInfo *OpInfo; |
| 730 | unsigned i; |
| 731 | |
| 732 | CC = ITStatus_getITCC(&(ud->ITBlock)); |
| 733 | if (ITStatus_instrInITBlock(&(ud->ITBlock))) |
| 734 | ITStatus_advanceITState(&(ud->ITBlock)); |
| 735 | |
| 736 | OpInfo = ARMInsts[MCInst_getOpcode(MI)].OpInfo; |
| 737 | NumOps = ARMInsts[MCInst_getOpcode(MI)].NumOperands; |
| 738 | |
| 739 | for (i = 0; i < NumOps; ++i) { |
| 740 | if (MCOperandInfo_isPredicate(&OpInfo[i])) { |
| 741 | MCOperand_setImm(MCInst_getOperand(MI, i), CC); |
| 742 | |
| 743 | if (CC == ARMCC_AL) |
| 744 | MCOperand_setReg(MCInst_getOperand(MI, i + 1), 0); |
| 745 | else |
| 746 | MCOperand_setReg(MCInst_getOperand(MI, i + 1), ARM_CPSR); |
| 747 | |
| 748 | return; |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | static DecodeStatus _Thumb_getInstruction(cs_struct *ud, MCInst *MI, const uint8_t *code, size_t code_len, |
| 754 | uint16_t *Size, uint64_t Address) |
| 755 | { |
| 756 | uint16_t insn16; |
| 757 | DecodeStatus result; |
| 758 | bool InITBlock; |
| 759 | unsigned Firstcond, Mask; |
| 760 | uint32_t NEONLdStInsn, insn32, NEONDataInsn, NEONCryptoInsn, NEONv8Insn; |
| 761 | size_t i; |
| 762 | |
| 763 | // We want to read exactly 2 bytes of data. |
| 764 | if (code_len < 2) |
| 765 | // not enough data |
| 766 | return MCDisassembler_Fail; |
| 767 | |
| 768 | if (MI->flat_insn->detail) { |
| 769 | memset(MI->flat_insn->detail, 0, offsetof(cs_detail, arm)+sizeof(cs_arm)); |
| 770 | for (i = 0; i < ARR_SIZE(MI->flat_insn->detail->arm.operands); i++) { |
| 771 | MI->flat_insn->detail->arm.operands[i].vector_index = -1; |
| 772 | MI->flat_insn->detail->arm.operands[i].neon_lane = -1; |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | if (MODE_IS_BIG_ENDIAN(ud->mode)) |
| 777 | insn16 = (code[0] << 8) | code[1]; |
| 778 | else |
| 779 | insn16 = (code[1] << 8) | code[0]; |
| 780 | |
| 781 | result = decodeInstruction_2(DecoderTableThumb16, MI, insn16, Address); |
| 782 | if (result != MCDisassembler_Fail) { |
| 783 | *Size = 2; |
| 784 | Check(&result, AddThumbPredicate(ud, MI)); |
| 785 | return result; |
| 786 | } |
| 787 | |
| 788 | MCInst_clear(MI); |
| 789 | result = decodeInstruction_2(DecoderTableThumbSBit16, MI, insn16, Address); |
| 790 | if (result) { |
| 791 | *Size = 2; |
| 792 | InITBlock = ITStatus_instrInITBlock(&(ud->ITBlock)); |
| 793 | Check(&result, AddThumbPredicate(ud, MI)); |
| 794 | AddThumb1SBit(MI, InITBlock); |
| 795 | return result; |
| 796 | } |
| 797 | |
| 798 | MCInst_clear(MI); |
| 799 | result = decodeInstruction_2(DecoderTableThumb216, MI, insn16, Address); |
| 800 | if (result != MCDisassembler_Fail) { |
| 801 | *Size = 2; |
| 802 | |
| 803 | // Nested IT blocks are UNPREDICTABLE. Must be checked before we add |
| 804 | // the Thumb predicate. |
| 805 | if (MCInst_getOpcode(MI) == ARM_t2IT && ITStatus_instrInITBlock(&(ud->ITBlock))) |
| 806 | return MCDisassembler_SoftFail; |
| 807 | |
| 808 | Check(&result, AddThumbPredicate(ud, MI)); |
| 809 | |
| 810 | // If we find an IT instruction, we need to parse its condition |
| 811 | // code and mask operands so that we can apply them correctly |
| 812 | // to the subsequent instructions. |
| 813 | if (MCInst_getOpcode(MI) == ARM_t2IT) { |
| 814 | Firstcond = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, 0)); |
| 815 | Mask = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, 1)); |
| 816 | ITStatus_setITState(&(ud->ITBlock), (char)Firstcond, (char)Mask); |
| 817 | |
| 818 | // An IT instruction that would give a 'NV' predicate is unpredictable. |
| 819 | // if (Firstcond == ARMCC_AL && !isPowerOf2_32(Mask)) |
| 820 | // CS << "unpredictable IT predicate sequence"; |
| 821 | } |
| 822 | |
| 823 | return result; |
| 824 | } |
| 825 | |
| 826 | // We want to read exactly 4 bytes of data. |
| 827 | if (code_len < 4) |
| 828 | // not enough data |
| 829 | return MCDisassembler_Fail; |
| 830 | |
| 831 | if (MODE_IS_BIG_ENDIAN(ud->mode)) |
| 832 | insn32 = (code[3] << 0) | (code[2] << 8) | |
| 833 | (code[1] << 16) | ((uint32_t) code[0] << 24); |
| 834 | else |
| 835 | insn32 = (code[3] << 8) | (code[2] << 0) | |
| 836 | ((uint32_t) code[1] << 24) | (code[0] << 16); |
| 837 | |
| 838 | MCInst_clear(MI); |
| 839 | result = decodeInstruction_4(DecoderTableThumb32, MI, insn32, Address); |
| 840 | if (result != MCDisassembler_Fail) { |
| 841 | *Size = 4; |
| 842 | InITBlock = ITStatus_instrInITBlock(&(ud->ITBlock)); |
| 843 | Check(&result, AddThumbPredicate(ud, MI)); |
| 844 | AddThumb1SBit(MI, InITBlock); |
| 845 | |
| 846 | return result; |
| 847 | } |
| 848 | |
| 849 | MCInst_clear(MI); |
| 850 | result = decodeInstruction_4(DecoderTableThumb232, MI, insn32, Address); |
| 851 | if (result != MCDisassembler_Fail) { |
| 852 | *Size = 4; |
| 853 | Check(&result, AddThumbPredicate(ud, MI)); |
| 854 | return result; |
| 855 | } |
| 856 | |
| 857 | if (fieldFromInstruction_4(insn32, 28, 4) == 0xE) { |
| 858 | MCInst_clear(MI); |
| 859 | result = decodeInstruction_4(DecoderTableVFP32, MI, insn32, Address); |
| 860 | if (result != MCDisassembler_Fail) { |
| 861 | *Size = 4; |
| 862 | UpdateThumbVFPPredicate(ud, MI); |
| 863 | return result; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | MCInst_clear(MI); |
| 868 | result = decodeInstruction_4(DecoderTableVFPV832, MI, insn32, Address); |
| 869 | if (result != MCDisassembler_Fail) { |
| 870 | *Size = 4; |
| 871 | return result; |
| 872 | } |
| 873 | |
| 874 | if (fieldFromInstruction_4(insn32, 28, 4) == 0xE) { |
| 875 | MCInst_clear(MI); |
| 876 | result = decodeInstruction_4(DecoderTableNEONDup32, MI, insn32, Address); |
| 877 | if (result != MCDisassembler_Fail) { |
| 878 | *Size = 4; |
| 879 | Check(&result, AddThumbPredicate(ud, MI)); |
| 880 | return result; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | if (fieldFromInstruction_4(insn32, 24, 8) == 0xF9) { |
| 885 | MCInst_clear(MI); |
| 886 | NEONLdStInsn = insn32; |
| 887 | NEONLdStInsn &= 0xF0FFFFFF; |
| 888 | NEONLdStInsn |= 0x04000000; |
| 889 | result = decodeInstruction_4(DecoderTableNEONLoadStore32, MI, NEONLdStInsn, Address); |
| 890 | if (result != MCDisassembler_Fail) { |
| 891 | *Size = 4; |
| 892 | Check(&result, AddThumbPredicate(ud, MI)); |
| 893 | return result; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | if (fieldFromInstruction_4(insn32, 24, 4) == 0xF) { |
| 898 | MCInst_clear(MI); |
| 899 | NEONDataInsn = insn32; |
| 900 | NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24 |
| 901 | NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24 |
| 902 | NEONDataInsn |= 0x12000000; // Set bits 28 and 25 |
| 903 | result = decodeInstruction_4(DecoderTableNEONData32, MI, NEONDataInsn, Address); |
| 904 | if (result != MCDisassembler_Fail) { |
| 905 | *Size = 4; |
| 906 | Check(&result, AddThumbPredicate(ud, MI)); |
| 907 | return result; |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | MCInst_clear(MI); |
| 912 | NEONCryptoInsn = insn32; |
| 913 | NEONCryptoInsn &= 0xF0FFFFFF; // Clear bits 27-24 |
| 914 | NEONCryptoInsn |= (NEONCryptoInsn & 0x10000000) >> 4; // Move bit 28 to bit 24 |
| 915 | NEONCryptoInsn |= 0x12000000; // Set bits 28 and 25 |
| 916 | result = decodeInstruction_4(DecoderTablev8Crypto32, MI, NEONCryptoInsn, Address); |
| 917 | if (result != MCDisassembler_Fail) { |
| 918 | *Size = 4; |
| 919 | return result; |
| 920 | } |
| 921 | |
| 922 | MCInst_clear(MI); |
| 923 | NEONv8Insn = insn32; |
| 924 | NEONv8Insn &= 0xF3FFFFFF; // Clear bits 27-26 |
| 925 | result = decodeInstruction_4(DecoderTablev8NEON32, MI, NEONv8Insn, Address); |
| 926 | if (result != MCDisassembler_Fail) { |
| 927 | *Size = 4; |
| 928 | return result; |
| 929 | } |
| 930 | |
| 931 | MCInst_clear(MI); |
| 932 | result = decodeInstruction_4(DecoderTableThumb2CoProc32, MI, insn32, Address); |
| 933 | if (result != MCDisassembler_Fail) { |
| 934 | *Size = 4; |
| 935 | Check(&result, AddThumbPredicate(ud, MI)); |
| 936 | return result; |
| 937 | } |
| 938 | |
| 939 | MCInst_clear(MI); |
| 940 | *Size = 0; |
| 941 | |
| 942 | return MCDisassembler_Fail; |
| 943 | } |
| 944 | |
| 945 | bool Thumb_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr, |
| 946 | uint16_t *size, uint64_t address, void *info) |
| 947 | { |
| 948 | DecodeStatus status = _Thumb_getInstruction((cs_struct *)ud, instr, code, code_len, size, address); |
| 949 | |
| 950 | // TODO: fix table gen to eliminate these special cases |
| 951 | if (instr->Opcode == ARM_t__brkdiv0) |
| 952 | return false; |
| 953 | |
| 954 | //return status == MCDisassembler_Success; |
| 955 | return status != MCDisassembler_Fail; |
| 956 | } |
| 957 | |
| 958 | bool ARM_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *instr, |
| 959 | uint16_t *size, uint64_t address, void *info) |
| 960 | { |
| 961 | DecodeStatus status = _ARM_getInstruction((cs_struct *)ud, instr, code, code_len, size, address); |
| 962 | |
| 963 | //return status == MCDisassembler_Success; |
| 964 | return status != MCDisassembler_Fail; |
| 965 | } |
| 966 | |
| 967 | static const uint16_t GPRDecoderTable[] = { |
| 968 | ARM_R0, ARM_R1, ARM_R2, ARM_R3, |
| 969 | ARM_R4, ARM_R5, ARM_R6, ARM_R7, |
| 970 | ARM_R8, ARM_R9, ARM_R10, ARM_R11, |
| 971 | ARM_R12, ARM_SP, ARM_LR, ARM_PC |
| 972 | }; |
| 973 | |
| 974 | static DecodeStatus DecodeGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 975 | uint64_t Address, const void *Decoder) |
| 976 | { |
| 977 | unsigned Register; |
| 978 | |
| 979 | if (RegNo > 15) |
| 980 | return MCDisassembler_Fail; |
| 981 | |
| 982 | Register = GPRDecoderTable[RegNo]; |
| 983 | MCOperand_CreateReg0(Inst, Register); |
| 984 | |
| 985 | return MCDisassembler_Success; |
| 986 | } |
| 987 | |
| 988 | static DecodeStatus DecodeGPRnopcRegisterClass(MCInst *Inst, unsigned RegNo, |
| 989 | uint64_t Address, const void *Decoder) |
| 990 | { |
| 991 | DecodeStatus S = MCDisassembler_Success; |
| 992 | |
| 993 | if (RegNo == 15) |
| 994 | S = MCDisassembler_SoftFail; |
| 995 | |
| 996 | Check(&S, DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder)); |
| 997 | |
| 998 | return S; |
| 999 | } |
| 1000 | |
| 1001 | static DecodeStatus DecodeGPRwithAPSRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1002 | uint64_t Address, const void *Decoder) |
| 1003 | { |
| 1004 | DecodeStatus S = MCDisassembler_Success; |
| 1005 | |
| 1006 | if (RegNo == 15) { |
| 1007 | MCOperand_CreateReg0(Inst, ARM_APSR_NZCV); |
| 1008 | |
| 1009 | return MCDisassembler_Success; |
| 1010 | } |
| 1011 | |
| 1012 | Check(&S, DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder)); |
| 1013 | return S; |
| 1014 | } |
| 1015 | |
| 1016 | static DecodeStatus DecodetGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1017 | uint64_t Address, const void *Decoder) |
| 1018 | { |
| 1019 | if (RegNo > 7) |
| 1020 | return MCDisassembler_Fail; |
| 1021 | |
| 1022 | return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder); |
| 1023 | } |
| 1024 | |
| 1025 | static const uint16_t GPRPairDecoderTable[] = { |
| 1026 | ARM_R0_R1, ARM_R2_R3, ARM_R4_R5, ARM_R6_R7, |
| 1027 | ARM_R8_R9, ARM_R10_R11, ARM_R12_SP |
| 1028 | }; |
| 1029 | |
| 1030 | static DecodeStatus DecodeGPRPairRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1031 | uint64_t Address, const void *Decoder) |
| 1032 | { |
| 1033 | unsigned RegisterPair; |
| 1034 | DecodeStatus S = MCDisassembler_Success; |
| 1035 | |
| 1036 | if (RegNo > 13) |
| 1037 | return MCDisassembler_Fail; |
| 1038 | |
| 1039 | if ((RegNo & 1) || RegNo == 0xe) |
| 1040 | S = MCDisassembler_SoftFail; |
| 1041 | |
| 1042 | RegisterPair = GPRPairDecoderTable[RegNo / 2]; |
| 1043 | MCOperand_CreateReg0(Inst, RegisterPair); |
| 1044 | |
| 1045 | return S; |
| 1046 | } |
| 1047 | |
| 1048 | static DecodeStatus DecodetcGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1049 | uint64_t Address, const void *Decoder) |
| 1050 | { |
| 1051 | unsigned Register = 0; |
| 1052 | |
| 1053 | switch (RegNo) { |
| 1054 | case 0: |
| 1055 | Register = ARM_R0; |
| 1056 | break; |
| 1057 | case 1: |
| 1058 | Register = ARM_R1; |
| 1059 | break; |
| 1060 | case 2: |
| 1061 | Register = ARM_R2; |
| 1062 | break; |
| 1063 | case 3: |
| 1064 | Register = ARM_R3; |
| 1065 | break; |
| 1066 | case 9: |
| 1067 | Register = ARM_R9; |
| 1068 | break; |
| 1069 | case 12: |
| 1070 | Register = ARM_R12; |
| 1071 | break; |
| 1072 | default: |
| 1073 | return MCDisassembler_Fail; |
| 1074 | } |
| 1075 | |
| 1076 | MCOperand_CreateReg0(Inst, Register); |
| 1077 | |
| 1078 | return MCDisassembler_Success; |
| 1079 | } |
| 1080 | |
| 1081 | static DecodeStatus DecoderGPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1082 | uint64_t Address, const void *Decoder) |
| 1083 | { |
| 1084 | DecodeStatus S = MCDisassembler_Success; |
| 1085 | |
| 1086 | if ((RegNo == 13 && !ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8Ops)) || RegNo == 15) |
| 1087 | S = MCDisassembler_SoftFail; |
| 1088 | |
| 1089 | Check(&S, DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder)); |
| 1090 | |
| 1091 | return S; |
| 1092 | } |
| 1093 | |
| 1094 | static const uint16_t SPRDecoderTable[] = { |
| 1095 | ARM_S0, ARM_S1, ARM_S2, ARM_S3, |
| 1096 | ARM_S4, ARM_S5, ARM_S6, ARM_S7, |
| 1097 | ARM_S8, ARM_S9, ARM_S10, ARM_S11, |
| 1098 | ARM_S12, ARM_S13, ARM_S14, ARM_S15, |
| 1099 | ARM_S16, ARM_S17, ARM_S18, ARM_S19, |
| 1100 | ARM_S20, ARM_S21, ARM_S22, ARM_S23, |
| 1101 | ARM_S24, ARM_S25, ARM_S26, ARM_S27, |
| 1102 | ARM_S28, ARM_S29, ARM_S30, ARM_S31 |
| 1103 | }; |
| 1104 | |
| 1105 | static DecodeStatus DecodeSPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1106 | uint64_t Address, const void *Decoder) |
| 1107 | { |
| 1108 | unsigned Register; |
| 1109 | |
| 1110 | if (RegNo > 31) |
| 1111 | return MCDisassembler_Fail; |
| 1112 | |
| 1113 | Register = SPRDecoderTable[RegNo]; |
| 1114 | MCOperand_CreateReg0(Inst, Register); |
| 1115 | |
| 1116 | return MCDisassembler_Success; |
| 1117 | } |
| 1118 | |
| 1119 | static DecodeStatus DecodeHPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1120 | uint64_t Address, const void *Decoder) |
| 1121 | { |
| 1122 | return DecodeSPRRegisterClass(Inst, RegNo, Address, Decoder); |
| 1123 | } |
| 1124 | |
| 1125 | static const uint16_t DPRDecoderTable[] = { |
| 1126 | ARM_D0, ARM_D1, ARM_D2, ARM_D3, |
| 1127 | ARM_D4, ARM_D5, ARM_D6, ARM_D7, |
| 1128 | ARM_D8, ARM_D9, ARM_D10, ARM_D11, |
| 1129 | ARM_D12, ARM_D13, ARM_D14, ARM_D15, |
| 1130 | ARM_D16, ARM_D17, ARM_D18, ARM_D19, |
| 1131 | ARM_D20, ARM_D21, ARM_D22, ARM_D23, |
| 1132 | ARM_D24, ARM_D25, ARM_D26, ARM_D27, |
| 1133 | ARM_D28, ARM_D29, ARM_D30, ARM_D31 |
| 1134 | }; |
| 1135 | |
| 1136 | static DecodeStatus DecodeDPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1137 | uint64_t Address, const void *Decoder) |
| 1138 | { |
| 1139 | unsigned Register; |
| 1140 | |
| 1141 | if (RegNo > 31 || (ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureD16) && RegNo > 15)) |
| 1142 | return MCDisassembler_Fail; |
| 1143 | |
| 1144 | Register = DPRDecoderTable[RegNo]; |
| 1145 | MCOperand_CreateReg0(Inst, Register); |
| 1146 | |
| 1147 | return MCDisassembler_Success; |
| 1148 | } |
| 1149 | |
| 1150 | static DecodeStatus DecodeDPR_8RegisterClass(MCInst *Inst, unsigned RegNo, |
| 1151 | uint64_t Address, const void *Decoder) |
| 1152 | { |
| 1153 | if (RegNo > 7) |
| 1154 | return MCDisassembler_Fail; |
| 1155 | |
| 1156 | return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder); |
| 1157 | } |
| 1158 | |
| 1159 | static DecodeStatus DecodeDPR_VFP2RegisterClass(MCInst *Inst, unsigned RegNo, |
| 1160 | uint64_t Address, const void *Decoder) |
| 1161 | { |
| 1162 | if (RegNo > 15) |
| 1163 | return MCDisassembler_Fail; |
| 1164 | |
| 1165 | return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder); |
| 1166 | } |
| 1167 | |
| 1168 | static const uint16_t QPRDecoderTable[] = { |
| 1169 | ARM_Q0, ARM_Q1, ARM_Q2, ARM_Q3, |
| 1170 | ARM_Q4, ARM_Q5, ARM_Q6, ARM_Q7, |
| 1171 | ARM_Q8, ARM_Q9, ARM_Q10, ARM_Q11, |
| 1172 | ARM_Q12, ARM_Q13, ARM_Q14, ARM_Q15 |
| 1173 | }; |
| 1174 | |
| 1175 | static DecodeStatus DecodeQPRRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1176 | uint64_t Address, const void *Decoder) |
| 1177 | { |
| 1178 | unsigned Register; |
| 1179 | |
| 1180 | if (RegNo > 31 || (RegNo & 1) != 0) |
| 1181 | return MCDisassembler_Fail; |
| 1182 | |
| 1183 | RegNo >>= 1; |
| 1184 | |
| 1185 | Register = QPRDecoderTable[RegNo]; |
| 1186 | MCOperand_CreateReg0(Inst, Register); |
| 1187 | |
| 1188 | return MCDisassembler_Success; |
| 1189 | } |
| 1190 | |
| 1191 | static const uint16_t DPairDecoderTable[] = { |
| 1192 | ARM_Q0, ARM_D1_D2, ARM_Q1, ARM_D3_D4, ARM_Q2, ARM_D5_D6, |
| 1193 | ARM_Q3, ARM_D7_D8, ARM_Q4, ARM_D9_D10, ARM_Q5, ARM_D11_D12, |
| 1194 | ARM_Q6, ARM_D13_D14, ARM_Q7, ARM_D15_D16, ARM_Q8, ARM_D17_D18, |
| 1195 | ARM_Q9, ARM_D19_D20, ARM_Q10, ARM_D21_D22, ARM_Q11, ARM_D23_D24, |
| 1196 | ARM_Q12, ARM_D25_D26, ARM_Q13, ARM_D27_D28, ARM_Q14, ARM_D29_D30, |
| 1197 | ARM_Q15 |
| 1198 | }; |
| 1199 | |
| 1200 | static DecodeStatus DecodeDPairRegisterClass(MCInst *Inst, unsigned RegNo, |
| 1201 | uint64_t Address, const void *Decoder) |
| 1202 | { |
| 1203 | unsigned Register; |
| 1204 | |
| 1205 | if (RegNo > 30) |
| 1206 | return MCDisassembler_Fail; |
| 1207 | |
| 1208 | Register = DPairDecoderTable[RegNo]; |
| 1209 | MCOperand_CreateReg0(Inst, Register); |
| 1210 | |
| 1211 | return MCDisassembler_Success; |
| 1212 | } |
| 1213 | |
| 1214 | static const uint16_t DPairSpacedDecoderTable[] = { |
| 1215 | ARM_D0_D2, ARM_D1_D3, ARM_D2_D4, ARM_D3_D5, |
| 1216 | ARM_D4_D6, ARM_D5_D7, ARM_D6_D8, ARM_D7_D9, |
| 1217 | ARM_D8_D10, ARM_D9_D11, ARM_D10_D12, ARM_D11_D13, |
| 1218 | ARM_D12_D14, ARM_D13_D15, ARM_D14_D16, ARM_D15_D17, |
| 1219 | ARM_D16_D18, ARM_D17_D19, ARM_D18_D20, ARM_D19_D21, |
| 1220 | ARM_D20_D22, ARM_D21_D23, ARM_D22_D24, ARM_D23_D25, |
| 1221 | ARM_D24_D26, ARM_D25_D27, ARM_D26_D28, ARM_D27_D29, |
| 1222 | ARM_D28_D30, ARM_D29_D31 |
| 1223 | }; |
| 1224 | |
| 1225 | static DecodeStatus DecodeDPairSpacedRegisterClass(MCInst *Inst, |
| 1226 | unsigned RegNo, uint64_t Address, const void *Decoder) |
| 1227 | { |
| 1228 | unsigned Register; |
| 1229 | |
| 1230 | if (RegNo > 29) |
| 1231 | return MCDisassembler_Fail; |
| 1232 | |
| 1233 | Register = DPairSpacedDecoderTable[RegNo]; |
| 1234 | MCOperand_CreateReg0(Inst, Register); |
| 1235 | |
| 1236 | return MCDisassembler_Success; |
| 1237 | } |
| 1238 | |
| 1239 | static DecodeStatus DecodeCCOutOperand(MCInst *Inst, unsigned Val, |
| 1240 | uint64_t Address, const void *Decoder) |
| 1241 | { |
| 1242 | if (Val) |
| 1243 | MCOperand_CreateReg0(Inst, ARM_CPSR); |
| 1244 | else |
| 1245 | MCOperand_CreateReg0(Inst, 0); |
| 1246 | |
| 1247 | return MCDisassembler_Success; |
| 1248 | } |
| 1249 | |
| 1250 | static DecodeStatus DecodeSORegImmOperand(MCInst *Inst, unsigned Val, |
| 1251 | uint64_t Address, const void *Decoder) |
| 1252 | { |
| 1253 | DecodeStatus S = MCDisassembler_Success; |
| 1254 | ARM_AM_ShiftOpc Shift; |
| 1255 | unsigned Op; |
| 1256 | unsigned Rm = fieldFromInstruction_4(Val, 0, 4); |
| 1257 | unsigned type = fieldFromInstruction_4(Val, 5, 2); |
| 1258 | unsigned imm = fieldFromInstruction_4(Val, 7, 5); |
| 1259 | |
| 1260 | // Register-immediate |
| 1261 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 1262 | return MCDisassembler_Fail; |
| 1263 | |
| 1264 | Shift = ARM_AM_lsl; |
| 1265 | switch (type) { |
| 1266 | case 0: |
| 1267 | Shift = ARM_AM_lsl; |
| 1268 | break; |
| 1269 | case 1: |
| 1270 | Shift = ARM_AM_lsr; |
| 1271 | break; |
| 1272 | case 2: |
| 1273 | Shift = ARM_AM_asr; |
| 1274 | break; |
| 1275 | case 3: |
| 1276 | Shift = ARM_AM_ror; |
| 1277 | break; |
| 1278 | } |
| 1279 | |
| 1280 | if (Shift == ARM_AM_ror && imm == 0) |
| 1281 | Shift = ARM_AM_rrx; |
| 1282 | |
| 1283 | Op = Shift | (imm << 3); |
| 1284 | MCOperand_CreateImm0(Inst, Op); |
| 1285 | |
| 1286 | return S; |
| 1287 | } |
| 1288 | |
| 1289 | static DecodeStatus DecodeSORegRegOperand(MCInst *Inst, unsigned Val, |
| 1290 | uint64_t Address, const void *Decoder) |
| 1291 | { |
| 1292 | DecodeStatus S = MCDisassembler_Success; |
| 1293 | ARM_AM_ShiftOpc Shift; |
| 1294 | |
| 1295 | unsigned Rm = fieldFromInstruction_4(Val, 0, 4); |
| 1296 | unsigned type = fieldFromInstruction_4(Val, 5, 2); |
| 1297 | unsigned Rs = fieldFromInstruction_4(Val, 8, 4); |
| 1298 | |
| 1299 | // Register-register |
| 1300 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder))) |
| 1301 | return MCDisassembler_Fail; |
| 1302 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder))) |
| 1303 | return MCDisassembler_Fail; |
| 1304 | |
| 1305 | Shift = ARM_AM_lsl; |
| 1306 | switch (type) { |
| 1307 | case 0: |
| 1308 | Shift = ARM_AM_lsl; |
| 1309 | break; |
| 1310 | case 1: |
| 1311 | Shift = ARM_AM_lsr; |
| 1312 | break; |
| 1313 | case 2: |
| 1314 | Shift = ARM_AM_asr; |
| 1315 | break; |
| 1316 | case 3: |
| 1317 | Shift = ARM_AM_ror; |
| 1318 | break; |
| 1319 | } |
| 1320 | |
| 1321 | MCOperand_CreateImm0(Inst, Shift); |
| 1322 | |
| 1323 | return S; |
| 1324 | } |
| 1325 | |
| 1326 | static DecodeStatus DecodeRegListOperand(MCInst *Inst, unsigned Val, |
| 1327 | uint64_t Address, const void *Decoder) |
| 1328 | { |
| 1329 | unsigned i; |
| 1330 | DecodeStatus S = MCDisassembler_Success; |
| 1331 | unsigned opcode; |
| 1332 | bool NeedDisjointWriteback = false; |
| 1333 | unsigned WritebackReg = 0; |
| 1334 | |
| 1335 | opcode = MCInst_getOpcode(Inst); |
| 1336 | switch (opcode) { |
| 1337 | default: |
| 1338 | break; |
| 1339 | |
| 1340 | case ARM_LDMIA_UPD: |
| 1341 | case ARM_LDMDB_UPD: |
| 1342 | case ARM_LDMIB_UPD: |
| 1343 | case ARM_LDMDA_UPD: |
| 1344 | case ARM_t2LDMIA_UPD: |
| 1345 | case ARM_t2LDMDB_UPD: |
| 1346 | case ARM_t2STMIA_UPD: |
| 1347 | case ARM_t2STMDB_UPD: |
| 1348 | NeedDisjointWriteback = true; |
| 1349 | WritebackReg = MCOperand_getReg(MCInst_getOperand(Inst, 0)); |
| 1350 | break; |
| 1351 | } |
| 1352 | |
| 1353 | // Empty register lists are not allowed. |
| 1354 | if (Val == 0) return MCDisassembler_Fail; |
| 1355 | |
| 1356 | for (i = 0; i < 16; ++i) { |
| 1357 | if (Val & (1 << i)) { |
| 1358 | if (!Check(&S, DecodeGPRRegisterClass(Inst, i, Address, Decoder))) |
| 1359 | return MCDisassembler_Fail; |
| 1360 | |
| 1361 | // Writeback not allowed if Rn is in the target list. |
| 1362 | if (NeedDisjointWriteback && WritebackReg == MCOperand_getReg(&(Inst->Operands[Inst->size - 1]))) |
| 1363 | Check(&S, MCDisassembler_SoftFail); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | return S; |
| 1368 | } |
| 1369 | |
| 1370 | static DecodeStatus DecodeSPRRegListOperand(MCInst *Inst, unsigned Val, |
| 1371 | uint64_t Address, const void *Decoder) |
| 1372 | { |
| 1373 | DecodeStatus S = MCDisassembler_Success; |
| 1374 | unsigned i; |
| 1375 | unsigned Vd = fieldFromInstruction_4(Val, 8, 5); |
| 1376 | unsigned regs = fieldFromInstruction_4(Val, 0, 8); |
| 1377 | |
| 1378 | // In case of unpredictable encoding, tweak the operands. |
| 1379 | if (regs == 0 || (Vd + regs) > 32) { |
| 1380 | regs = Vd + regs > 32 ? 32 - Vd : regs; |
| 1381 | regs = (1u > regs? 1u : regs); |
| 1382 | S = MCDisassembler_SoftFail; |
| 1383 | } |
| 1384 | |
| 1385 | if (!Check(&S, DecodeSPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 1386 | return MCDisassembler_Fail; |
| 1387 | |
| 1388 | for (i = 0; i < (regs - 1); ++i) { |
| 1389 | if (!Check(&S, DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder))) |
| 1390 | return MCDisassembler_Fail; |
| 1391 | } |
| 1392 | |
| 1393 | return S; |
| 1394 | } |
| 1395 | |
| 1396 | static DecodeStatus DecodeDPRRegListOperand(MCInst *Inst, unsigned Val, |
| 1397 | uint64_t Address, const void *Decoder) |
| 1398 | { |
| 1399 | DecodeStatus S = MCDisassembler_Success; |
| 1400 | unsigned i; |
| 1401 | unsigned Vd = fieldFromInstruction_4(Val, 8, 5); |
| 1402 | unsigned regs = fieldFromInstruction_4(Val, 1, 7); |
| 1403 | |
| 1404 | // In case of unpredictable encoding, tweak the operands. |
| 1405 | if (regs == 0 || regs > 16 || (Vd + regs) > 32) { |
| 1406 | regs = Vd + regs > 32 ? 32 - Vd : regs; |
| 1407 | regs = (1u > regs? 1u : regs); |
| 1408 | regs = (16u > regs? regs : 16u); |
| 1409 | S = MCDisassembler_SoftFail; |
| 1410 | } |
| 1411 | |
| 1412 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 1413 | return MCDisassembler_Fail; |
| 1414 | |
| 1415 | for (i = 0; i < (regs - 1); ++i) { |
| 1416 | if (!Check(&S, DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder))) |
| 1417 | return MCDisassembler_Fail; |
| 1418 | } |
| 1419 | |
| 1420 | return S; |
| 1421 | } |
| 1422 | |
| 1423 | static DecodeStatus DecodeBitfieldMaskOperand(MCInst *Inst, unsigned Val, |
| 1424 | uint64_t Address, const void *Decoder) |
| 1425 | { |
| 1426 | // This operand encodes a mask of contiguous zeros between a specified MSB |
| 1427 | // and LSB. To decode it, we create the mask of all bits MSB-and-lower, |
| 1428 | // the mask of all bits LSB-and-lower, and then xor them to create |
| 1429 | // the mask of that's all ones on [msb, lsb]. Finally we not it to |
| 1430 | // create the final mask. |
| 1431 | unsigned msb = fieldFromInstruction_4(Val, 5, 5); |
| 1432 | unsigned lsb = fieldFromInstruction_4(Val, 0, 5); |
| 1433 | uint32_t lsb_mask, msb_mask; |
| 1434 | |
| 1435 | DecodeStatus S = MCDisassembler_Success; |
| 1436 | if (lsb > msb) { |
| 1437 | Check(&S, MCDisassembler_SoftFail); |
| 1438 | // The check above will cause the warning for the "potentially undefined |
| 1439 | // instruction encoding" but we can't build a bad MCOperand value here |
| 1440 | // with a lsb > msb or else printing the MCInst will cause a crash. |
| 1441 | lsb = msb; |
| 1442 | } |
| 1443 | |
| 1444 | msb_mask = 0xFFFFFFFF; |
| 1445 | if (msb != 31) msb_mask = (1U << (msb + 1)) - 1; |
| 1446 | lsb_mask = (1U << lsb) - 1; |
| 1447 | |
| 1448 | MCOperand_CreateImm0(Inst, ~(msb_mask ^ lsb_mask)); |
| 1449 | return S; |
| 1450 | } |
| 1451 | |
| 1452 | static DecodeStatus DecodeCopMemInstruction(MCInst *Inst, unsigned Insn, |
| 1453 | uint64_t Address, const void *Decoder) |
| 1454 | { |
| 1455 | DecodeStatus S = MCDisassembler_Success; |
| 1456 | |
| 1457 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 1458 | unsigned CRd = fieldFromInstruction_4(Insn, 12, 4); |
| 1459 | unsigned coproc = fieldFromInstruction_4(Insn, 8, 4); |
| 1460 | unsigned imm = fieldFromInstruction_4(Insn, 0, 8); |
| 1461 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 1462 | unsigned U = fieldFromInstruction_4(Insn, 23, 1); |
| 1463 | |
| 1464 | switch (MCInst_getOpcode(Inst)) { |
| 1465 | case ARM_LDC_OFFSET: |
| 1466 | case ARM_LDC_PRE: |
| 1467 | case ARM_LDC_POST: |
| 1468 | case ARM_LDC_OPTION: |
| 1469 | case ARM_LDCL_OFFSET: |
| 1470 | case ARM_LDCL_PRE: |
| 1471 | case ARM_LDCL_POST: |
| 1472 | case ARM_LDCL_OPTION: |
| 1473 | case ARM_STC_OFFSET: |
| 1474 | case ARM_STC_PRE: |
| 1475 | case ARM_STC_POST: |
| 1476 | case ARM_STC_OPTION: |
| 1477 | case ARM_STCL_OFFSET: |
| 1478 | case ARM_STCL_PRE: |
| 1479 | case ARM_STCL_POST: |
| 1480 | case ARM_STCL_OPTION: |
| 1481 | case ARM_t2LDC_OFFSET: |
| 1482 | case ARM_t2LDC_PRE: |
| 1483 | case ARM_t2LDC_POST: |
| 1484 | case ARM_t2LDC_OPTION: |
| 1485 | case ARM_t2LDCL_OFFSET: |
| 1486 | case ARM_t2LDCL_PRE: |
| 1487 | case ARM_t2LDCL_POST: |
| 1488 | case ARM_t2LDCL_OPTION: |
| 1489 | case ARM_t2STC_OFFSET: |
| 1490 | case ARM_t2STC_PRE: |
| 1491 | case ARM_t2STC_POST: |
| 1492 | case ARM_t2STC_OPTION: |
| 1493 | case ARM_t2STCL_OFFSET: |
| 1494 | case ARM_t2STCL_PRE: |
| 1495 | case ARM_t2STCL_POST: |
| 1496 | case ARM_t2STCL_OPTION: |
| 1497 | if (coproc == 0xA || coproc == 0xB) |
| 1498 | return MCDisassembler_Fail; |
| 1499 | break; |
| 1500 | default: |
| 1501 | break; |
| 1502 | } |
| 1503 | |
| 1504 | if (ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8Ops) && (coproc != 14)) |
| 1505 | return MCDisassembler_Fail; |
| 1506 | |
| 1507 | MCOperand_CreateImm0(Inst, coproc); |
| 1508 | MCOperand_CreateImm0(Inst, CRd); |
| 1509 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1510 | return MCDisassembler_Fail; |
| 1511 | |
| 1512 | switch (MCInst_getOpcode(Inst)) { |
| 1513 | case ARM_t2LDC2_OFFSET: |
| 1514 | case ARM_t2LDC2L_OFFSET: |
| 1515 | case ARM_t2LDC2_PRE: |
| 1516 | case ARM_t2LDC2L_PRE: |
| 1517 | case ARM_t2STC2_OFFSET: |
| 1518 | case ARM_t2STC2L_OFFSET: |
| 1519 | case ARM_t2STC2_PRE: |
| 1520 | case ARM_t2STC2L_PRE: |
| 1521 | case ARM_LDC2_OFFSET: |
| 1522 | case ARM_LDC2L_OFFSET: |
| 1523 | case ARM_LDC2_PRE: |
| 1524 | case ARM_LDC2L_PRE: |
| 1525 | case ARM_STC2_OFFSET: |
| 1526 | case ARM_STC2L_OFFSET: |
| 1527 | case ARM_STC2_PRE: |
| 1528 | case ARM_STC2L_PRE: |
| 1529 | case ARM_t2LDC_OFFSET: |
| 1530 | case ARM_t2LDCL_OFFSET: |
| 1531 | case ARM_t2LDC_PRE: |
| 1532 | case ARM_t2LDCL_PRE: |
| 1533 | case ARM_t2STC_OFFSET: |
| 1534 | case ARM_t2STCL_OFFSET: |
| 1535 | case ARM_t2STC_PRE: |
| 1536 | case ARM_t2STCL_PRE: |
| 1537 | case ARM_LDC_OFFSET: |
| 1538 | case ARM_LDCL_OFFSET: |
| 1539 | case ARM_LDC_PRE: |
| 1540 | case ARM_LDCL_PRE: |
| 1541 | case ARM_STC_OFFSET: |
| 1542 | case ARM_STCL_OFFSET: |
| 1543 | case ARM_STC_PRE: |
| 1544 | case ARM_STCL_PRE: |
| 1545 | imm = ARM_AM_getAM5Opc(U ? ARM_AM_add : ARM_AM_sub, (unsigned char)imm); |
| 1546 | MCOperand_CreateImm0(Inst, imm); |
| 1547 | break; |
| 1548 | case ARM_t2LDC2_POST: |
| 1549 | case ARM_t2LDC2L_POST: |
| 1550 | case ARM_t2STC2_POST: |
| 1551 | case ARM_t2STC2L_POST: |
| 1552 | case ARM_LDC2_POST: |
| 1553 | case ARM_LDC2L_POST: |
| 1554 | case ARM_STC2_POST: |
| 1555 | case ARM_STC2L_POST: |
| 1556 | case ARM_t2LDC_POST: |
| 1557 | case ARM_t2LDCL_POST: |
| 1558 | case ARM_t2STC_POST: |
| 1559 | case ARM_t2STCL_POST: |
| 1560 | case ARM_LDC_POST: |
| 1561 | case ARM_LDCL_POST: |
| 1562 | case ARM_STC_POST: |
| 1563 | case ARM_STCL_POST: |
| 1564 | imm |= U << 8; |
| 1565 | // fall through. |
| 1566 | default: |
| 1567 | // The 'option' variant doesn't encode 'U' in the immediate since |
| 1568 | // the immediate is unsigned [0,255]. |
| 1569 | MCOperand_CreateImm0(Inst, imm); |
| 1570 | break; |
| 1571 | } |
| 1572 | |
| 1573 | switch (MCInst_getOpcode(Inst)) { |
| 1574 | case ARM_LDC_OFFSET: |
| 1575 | case ARM_LDC_PRE: |
| 1576 | case ARM_LDC_POST: |
| 1577 | case ARM_LDC_OPTION: |
| 1578 | case ARM_LDCL_OFFSET: |
| 1579 | case ARM_LDCL_PRE: |
| 1580 | case ARM_LDCL_POST: |
| 1581 | case ARM_LDCL_OPTION: |
| 1582 | case ARM_STC_OFFSET: |
| 1583 | case ARM_STC_PRE: |
| 1584 | case ARM_STC_POST: |
| 1585 | case ARM_STC_OPTION: |
| 1586 | case ARM_STCL_OFFSET: |
| 1587 | case ARM_STCL_PRE: |
| 1588 | case ARM_STCL_POST: |
| 1589 | case ARM_STCL_OPTION: |
| 1590 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 1591 | return MCDisassembler_Fail; |
| 1592 | break; |
| 1593 | default: |
| 1594 | break; |
| 1595 | } |
| 1596 | |
| 1597 | return S; |
| 1598 | } |
| 1599 | |
| 1600 | static DecodeStatus DecodeAddrMode2IdxInstruction(MCInst *Inst, unsigned Insn, |
| 1601 | uint64_t Address, const void *Decoder) |
| 1602 | { |
| 1603 | DecodeStatus S = MCDisassembler_Success; |
| 1604 | ARM_AM_AddrOpc Op; |
| 1605 | ARM_AM_ShiftOpc Opc; |
| 1606 | bool writeback; |
| 1607 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 1608 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 1609 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 1610 | unsigned imm = fieldFromInstruction_4(Insn, 0, 12); |
| 1611 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 1612 | unsigned reg = fieldFromInstruction_4(Insn, 25, 1); |
| 1613 | unsigned P = fieldFromInstruction_4(Insn, 24, 1); |
| 1614 | unsigned W = fieldFromInstruction_4(Insn, 21, 1); |
| 1615 | unsigned idx_mode = 0, amt, tmp; |
| 1616 | |
| 1617 | // On stores, the writeback operand precedes Rt. |
| 1618 | switch (MCInst_getOpcode(Inst)) { |
| 1619 | case ARM_STR_POST_IMM: |
| 1620 | case ARM_STR_POST_REG: |
| 1621 | case ARM_STRB_POST_IMM: |
| 1622 | case ARM_STRB_POST_REG: |
| 1623 | case ARM_STRT_POST_REG: |
| 1624 | case ARM_STRT_POST_IMM: |
| 1625 | case ARM_STRBT_POST_REG: |
| 1626 | case ARM_STRBT_POST_IMM: |
| 1627 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1628 | return MCDisassembler_Fail; |
| 1629 | break; |
| 1630 | default: |
| 1631 | break; |
| 1632 | } |
| 1633 | |
| 1634 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 1635 | return MCDisassembler_Fail; |
| 1636 | |
| 1637 | // On loads, the writeback operand comes after Rt. |
| 1638 | switch (MCInst_getOpcode(Inst)) { |
| 1639 | case ARM_LDR_POST_IMM: |
| 1640 | case ARM_LDR_POST_REG: |
| 1641 | case ARM_LDRB_POST_IMM: |
| 1642 | case ARM_LDRB_POST_REG: |
| 1643 | case ARM_LDRBT_POST_REG: |
| 1644 | case ARM_LDRBT_POST_IMM: |
| 1645 | case ARM_LDRT_POST_REG: |
| 1646 | case ARM_LDRT_POST_IMM: |
| 1647 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1648 | return MCDisassembler_Fail; |
| 1649 | break; |
| 1650 | default: |
| 1651 | break; |
| 1652 | } |
| 1653 | |
| 1654 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1655 | return MCDisassembler_Fail; |
| 1656 | |
| 1657 | Op = ARM_AM_add; |
| 1658 | if (!fieldFromInstruction_4(Insn, 23, 1)) |
| 1659 | Op = ARM_AM_sub; |
| 1660 | |
| 1661 | writeback = (P == 0) || (W == 1); |
| 1662 | if (P && writeback) |
| 1663 | idx_mode = ARMII_IndexModePre; |
| 1664 | else if (!P && writeback) |
| 1665 | idx_mode = ARMII_IndexModePost; |
| 1666 | |
| 1667 | if (writeback && (Rn == 15 || Rn == Rt)) |
| 1668 | S = MCDisassembler_SoftFail; // UNPREDICTABLE |
| 1669 | |
| 1670 | if (reg) { |
| 1671 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder))) |
| 1672 | return MCDisassembler_Fail; |
| 1673 | |
| 1674 | Opc = ARM_AM_lsl; |
| 1675 | switch(fieldFromInstruction_4(Insn, 5, 2)) { |
| 1676 | case 0: |
| 1677 | Opc = ARM_AM_lsl; |
| 1678 | break; |
| 1679 | case 1: |
| 1680 | Opc = ARM_AM_lsr; |
| 1681 | break; |
| 1682 | case 2: |
| 1683 | Opc = ARM_AM_asr; |
| 1684 | break; |
| 1685 | case 3: |
| 1686 | Opc = ARM_AM_ror; |
| 1687 | break; |
| 1688 | default: |
| 1689 | return MCDisassembler_Fail; |
| 1690 | } |
| 1691 | |
| 1692 | amt = fieldFromInstruction_4(Insn, 7, 5); |
| 1693 | if (Opc == ARM_AM_ror && amt == 0) |
| 1694 | Opc = ARM_AM_rrx; |
| 1695 | |
| 1696 | imm = ARM_AM_getAM2Opc(Op, amt, Opc, idx_mode); |
| 1697 | |
| 1698 | MCOperand_CreateImm0(Inst, imm); |
| 1699 | } else { |
| 1700 | MCOperand_CreateReg0(Inst, 0); |
| 1701 | tmp = ARM_AM_getAM2Opc(Op, imm, ARM_AM_lsl, idx_mode); |
| 1702 | MCOperand_CreateImm0(Inst, tmp); |
| 1703 | } |
| 1704 | |
| 1705 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 1706 | return MCDisassembler_Fail; |
| 1707 | |
| 1708 | return S; |
| 1709 | } |
| 1710 | |
| 1711 | static DecodeStatus DecodeSORegMemOperand(MCInst *Inst, unsigned Val, |
| 1712 | uint64_t Address, const void *Decoder) |
| 1713 | { |
| 1714 | DecodeStatus S = MCDisassembler_Success; |
| 1715 | ARM_AM_ShiftOpc ShOp; |
| 1716 | unsigned shift; |
| 1717 | unsigned Rn = fieldFromInstruction_4(Val, 13, 4); |
| 1718 | unsigned Rm = fieldFromInstruction_4(Val, 0, 4); |
| 1719 | unsigned type = fieldFromInstruction_4(Val, 5, 2); |
| 1720 | unsigned imm = fieldFromInstruction_4(Val, 7, 5); |
| 1721 | unsigned U = fieldFromInstruction_4(Val, 12, 1); |
| 1722 | |
| 1723 | ShOp = ARM_AM_lsl; |
| 1724 | switch (type) { |
| 1725 | case 0: |
| 1726 | ShOp = ARM_AM_lsl; |
| 1727 | break; |
| 1728 | case 1: |
| 1729 | ShOp = ARM_AM_lsr; |
| 1730 | break; |
| 1731 | case 2: |
| 1732 | ShOp = ARM_AM_asr; |
| 1733 | break; |
| 1734 | case 3: |
| 1735 | ShOp = ARM_AM_ror; |
| 1736 | break; |
| 1737 | } |
| 1738 | |
| 1739 | if (ShOp == ARM_AM_ror && imm == 0) |
| 1740 | ShOp = ARM_AM_rrx; |
| 1741 | |
| 1742 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1743 | return MCDisassembler_Fail; |
| 1744 | |
| 1745 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 1746 | return MCDisassembler_Fail; |
| 1747 | |
| 1748 | if (U) |
| 1749 | shift = ARM_AM_getAM2Opc(ARM_AM_add, imm, ShOp, 0); |
| 1750 | else |
| 1751 | shift = ARM_AM_getAM2Opc(ARM_AM_sub, imm, ShOp, 0); |
| 1752 | |
| 1753 | MCOperand_CreateImm0(Inst, shift); |
| 1754 | |
| 1755 | return S; |
| 1756 | } |
| 1757 | |
| 1758 | static DecodeStatus DecodeAddrMode3Instruction(MCInst *Inst, unsigned Insn, |
| 1759 | uint64_t Address, const void *Decoder) |
| 1760 | { |
| 1761 | DecodeStatus S = MCDisassembler_Success; |
| 1762 | |
| 1763 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 1764 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 1765 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 1766 | unsigned type = fieldFromInstruction_4(Insn, 22, 1); |
| 1767 | unsigned imm = fieldFromInstruction_4(Insn, 8, 4); |
| 1768 | unsigned U = ((~fieldFromInstruction_4(Insn, 23, 1)) & 1) << 8; |
| 1769 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 1770 | unsigned W = fieldFromInstruction_4(Insn, 21, 1); |
| 1771 | unsigned P = fieldFromInstruction_4(Insn, 24, 1); |
| 1772 | unsigned Rt2 = Rt + 1; |
| 1773 | |
| 1774 | bool writeback = (W == 1) | (P == 0); |
| 1775 | |
| 1776 | // For {LD,ST}RD, Rt must be even, else undefined. |
| 1777 | switch (MCInst_getOpcode(Inst)) { |
| 1778 | case ARM_STRD: |
| 1779 | case ARM_STRD_PRE: |
| 1780 | case ARM_STRD_POST: |
| 1781 | case ARM_LDRD: |
| 1782 | case ARM_LDRD_PRE: |
| 1783 | case ARM_LDRD_POST: |
| 1784 | if (Rt & 0x1) |
| 1785 | S = MCDisassembler_SoftFail; |
| 1786 | break; |
| 1787 | default: |
| 1788 | break; |
| 1789 | } |
| 1790 | |
| 1791 | switch (MCInst_getOpcode(Inst)) { |
| 1792 | case ARM_STRD: |
| 1793 | case ARM_STRD_PRE: |
| 1794 | case ARM_STRD_POST: |
| 1795 | if (P == 0 && W == 1) |
| 1796 | S = MCDisassembler_SoftFail; |
| 1797 | |
| 1798 | if (writeback && (Rn == 15 || Rn == Rt || Rn == Rt2)) |
| 1799 | S = MCDisassembler_SoftFail; |
| 1800 | |
| 1801 | if (type && Rm == 15) |
| 1802 | S = MCDisassembler_SoftFail; |
| 1803 | |
| 1804 | if (Rt2 == 15) |
| 1805 | S = MCDisassembler_SoftFail; |
| 1806 | |
| 1807 | if (!type && fieldFromInstruction_4(Insn, 8, 4)) |
| 1808 | S = MCDisassembler_SoftFail; |
| 1809 | |
| 1810 | break; |
| 1811 | |
| 1812 | case ARM_STRH: |
| 1813 | case ARM_STRH_PRE: |
| 1814 | case ARM_STRH_POST: |
| 1815 | if (Rt == 15) |
| 1816 | S = MCDisassembler_SoftFail; |
| 1817 | |
| 1818 | if (writeback && (Rn == 15 || Rn == Rt)) |
| 1819 | S = MCDisassembler_SoftFail; |
| 1820 | |
| 1821 | if (!type && Rm == 15) |
| 1822 | S = MCDisassembler_SoftFail; |
| 1823 | |
| 1824 | break; |
| 1825 | |
| 1826 | case ARM_LDRD: |
| 1827 | case ARM_LDRD_PRE: |
| 1828 | case ARM_LDRD_POST: |
| 1829 | if (type && Rn == 15) { |
| 1830 | if (Rt2 == 15) |
| 1831 | S = MCDisassembler_SoftFail; |
| 1832 | break; |
| 1833 | } |
| 1834 | |
| 1835 | if (P == 0 && W == 1) |
| 1836 | S = MCDisassembler_SoftFail; |
| 1837 | |
| 1838 | if (!type && (Rt2 == 15 || Rm == 15 || Rm == Rt || Rm == Rt2)) |
| 1839 | S = MCDisassembler_SoftFail; |
| 1840 | |
| 1841 | if (!type && writeback && Rn == 15) |
| 1842 | S = MCDisassembler_SoftFail; |
| 1843 | |
| 1844 | if (writeback && (Rn == Rt || Rn == Rt2)) |
| 1845 | S = MCDisassembler_SoftFail; |
| 1846 | |
| 1847 | break; |
| 1848 | |
| 1849 | case ARM_LDRH: |
| 1850 | case ARM_LDRH_PRE: |
| 1851 | case ARM_LDRH_POST: |
| 1852 | if (type && Rn == 15) { |
| 1853 | if (Rt == 15) |
| 1854 | S = MCDisassembler_SoftFail; |
| 1855 | break; |
| 1856 | } |
| 1857 | |
| 1858 | if (Rt == 15) |
| 1859 | S = MCDisassembler_SoftFail; |
| 1860 | |
| 1861 | if (!type && Rm == 15) |
| 1862 | S = MCDisassembler_SoftFail; |
| 1863 | |
| 1864 | if (!type && writeback && (Rn == 15 || Rn == Rt)) |
| 1865 | S = MCDisassembler_SoftFail; |
| 1866 | break; |
| 1867 | |
| 1868 | case ARM_LDRSH: |
| 1869 | case ARM_LDRSH_PRE: |
| 1870 | case ARM_LDRSH_POST: |
| 1871 | case ARM_LDRSB: |
| 1872 | case ARM_LDRSB_PRE: |
| 1873 | case ARM_LDRSB_POST: |
| 1874 | if (type && Rn == 15){ |
| 1875 | if (Rt == 15) |
| 1876 | S = MCDisassembler_SoftFail; |
| 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | if (type && (Rt == 15 || (writeback && Rn == Rt))) |
| 1881 | S = MCDisassembler_SoftFail; |
| 1882 | |
| 1883 | if (!type && (Rt == 15 || Rm == 15)) |
| 1884 | S = MCDisassembler_SoftFail; |
| 1885 | |
| 1886 | if (!type && writeback && (Rn == 15 || Rn == Rt)) |
| 1887 | S = MCDisassembler_SoftFail; |
| 1888 | |
| 1889 | break; |
| 1890 | |
| 1891 | default: |
| 1892 | break; |
| 1893 | } |
| 1894 | |
| 1895 | if (writeback) { // Writeback |
| 1896 | Inst->writeback = true; |
| 1897 | |
| 1898 | if (P) |
| 1899 | U |= ARMII_IndexModePre << 9; |
| 1900 | else |
| 1901 | U |= ARMII_IndexModePost << 9; |
| 1902 | |
| 1903 | // On stores, the writeback operand precedes Rt. |
| 1904 | switch (MCInst_getOpcode(Inst)) { |
| 1905 | case ARM_STRD: |
| 1906 | case ARM_STRD_PRE: |
| 1907 | case ARM_STRD_POST: |
| 1908 | case ARM_STRH: |
| 1909 | case ARM_STRH_PRE: |
| 1910 | case ARM_STRH_POST: |
| 1911 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1912 | return MCDisassembler_Fail; |
| 1913 | break; |
| 1914 | default: |
| 1915 | break; |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 1920 | return MCDisassembler_Fail; |
| 1921 | |
| 1922 | switch (MCInst_getOpcode(Inst)) { |
| 1923 | case ARM_STRD: |
| 1924 | case ARM_STRD_PRE: |
| 1925 | case ARM_STRD_POST: |
| 1926 | case ARM_LDRD: |
| 1927 | case ARM_LDRD_PRE: |
| 1928 | case ARM_LDRD_POST: |
| 1929 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt + 1, Address, Decoder))) |
| 1930 | return MCDisassembler_Fail; |
| 1931 | break; |
| 1932 | default: |
| 1933 | break; |
| 1934 | } |
| 1935 | |
| 1936 | if (writeback) { |
| 1937 | // On loads, the writeback operand comes after Rt. |
| 1938 | switch (MCInst_getOpcode(Inst)) { |
| 1939 | case ARM_LDRD: |
| 1940 | case ARM_LDRD_PRE: |
| 1941 | case ARM_LDRD_POST: |
| 1942 | case ARM_LDRH: |
| 1943 | case ARM_LDRH_PRE: |
| 1944 | case ARM_LDRH_POST: |
| 1945 | case ARM_LDRSH: |
| 1946 | case ARM_LDRSH_PRE: |
| 1947 | case ARM_LDRSH_POST: |
| 1948 | case ARM_LDRSB: |
| 1949 | case ARM_LDRSB_PRE: |
| 1950 | case ARM_LDRSB_POST: |
| 1951 | case ARM_LDRHTr: |
| 1952 | case ARM_LDRSBTr: |
| 1953 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1954 | return MCDisassembler_Fail; |
| 1955 | break; |
| 1956 | default: |
| 1957 | break; |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 1962 | return MCDisassembler_Fail; |
| 1963 | |
| 1964 | if (type) { |
| 1965 | MCOperand_CreateReg0(Inst, 0); |
| 1966 | MCOperand_CreateImm0(Inst, U | (imm << 4) | Rm); |
| 1967 | } else { |
| 1968 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 1969 | return MCDisassembler_Fail; |
| 1970 | |
| 1971 | MCOperand_CreateImm0(Inst, U); |
| 1972 | } |
| 1973 | |
| 1974 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 1975 | return MCDisassembler_Fail; |
| 1976 | |
| 1977 | return S; |
| 1978 | } |
| 1979 | |
| 1980 | static DecodeStatus DecodeRFEInstruction(MCInst *Inst, unsigned Insn, |
| 1981 | uint64_t Address, const void *Decoder) |
| 1982 | { |
| 1983 | DecodeStatus S = MCDisassembler_Success; |
| 1984 | |
| 1985 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 1986 | unsigned mode = fieldFromInstruction_4(Insn, 23, 2); |
| 1987 | |
| 1988 | switch (mode) { |
| 1989 | case 0: |
| 1990 | mode = ARM_AM_da; |
| 1991 | break; |
| 1992 | case 1: |
| 1993 | mode = ARM_AM_ia; |
| 1994 | break; |
| 1995 | case 2: |
| 1996 | mode = ARM_AM_db; |
| 1997 | break; |
| 1998 | case 3: |
| 1999 | mode = ARM_AM_ib; |
| 2000 | break; |
| 2001 | } |
| 2002 | |
| 2003 | MCOperand_CreateImm0(Inst, mode); |
| 2004 | |
| 2005 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2006 | return MCDisassembler_Fail; |
| 2007 | |
| 2008 | return S; |
| 2009 | } |
| 2010 | |
| 2011 | static DecodeStatus DecodeQADDInstruction(MCInst *Inst, unsigned Insn, |
| 2012 | uint64_t Address, const void *Decoder) |
| 2013 | { |
| 2014 | DecodeStatus S = MCDisassembler_Success; |
| 2015 | |
| 2016 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 2017 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 2018 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 2019 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2020 | |
| 2021 | if (pred == 0xF) |
| 2022 | return DecodeCPSInstruction(Inst, Insn, Address, Decoder); |
| 2023 | |
| 2024 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder))) |
| 2025 | return MCDisassembler_Fail; |
| 2026 | |
| 2027 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder))) |
| 2028 | return MCDisassembler_Fail; |
| 2029 | |
| 2030 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder))) |
| 2031 | return MCDisassembler_Fail; |
| 2032 | |
| 2033 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 2034 | return MCDisassembler_Fail; |
| 2035 | |
| 2036 | return S; |
| 2037 | } |
| 2038 | |
| 2039 | static DecodeStatus DecodeMemMultipleWritebackInstruction(MCInst *Inst, |
| 2040 | unsigned Insn, uint64_t Address, const void *Decoder) |
| 2041 | { |
| 2042 | DecodeStatus S = MCDisassembler_Success; |
| 2043 | |
| 2044 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 2045 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2046 | unsigned reglist = fieldFromInstruction_4(Insn, 0, 16); |
| 2047 | |
| 2048 | if (pred == 0xF) { |
| 2049 | // Ambiguous with RFE and SRS |
| 2050 | switch (MCInst_getOpcode(Inst)) { |
| 2051 | case ARM_LDMDA: |
| 2052 | MCInst_setOpcode(Inst, ARM_RFEDA); |
| 2053 | break; |
| 2054 | case ARM_LDMDA_UPD: |
| 2055 | MCInst_setOpcode(Inst, ARM_RFEDA_UPD); |
| 2056 | break; |
| 2057 | case ARM_LDMDB: |
| 2058 | MCInst_setOpcode(Inst, ARM_RFEDB); |
| 2059 | break; |
| 2060 | case ARM_LDMDB_UPD: |
| 2061 | MCInst_setOpcode(Inst, ARM_RFEDB_UPD); |
| 2062 | break; |
| 2063 | case ARM_LDMIA: |
| 2064 | MCInst_setOpcode(Inst, ARM_RFEIA); |
| 2065 | break; |
| 2066 | case ARM_LDMIA_UPD: |
| 2067 | MCInst_setOpcode(Inst, ARM_RFEIA_UPD); |
| 2068 | break; |
| 2069 | case ARM_LDMIB: |
| 2070 | MCInst_setOpcode(Inst, ARM_RFEIB); |
| 2071 | break; |
| 2072 | case ARM_LDMIB_UPD: |
| 2073 | MCInst_setOpcode(Inst, ARM_RFEIB_UPD); |
| 2074 | break; |
| 2075 | case ARM_STMDA: |
| 2076 | MCInst_setOpcode(Inst, ARM_SRSDA); |
| 2077 | break; |
| 2078 | case ARM_STMDA_UPD: |
| 2079 | MCInst_setOpcode(Inst, ARM_SRSDA_UPD); |
| 2080 | break; |
| 2081 | case ARM_STMDB: |
| 2082 | MCInst_setOpcode(Inst, ARM_SRSDB); |
| 2083 | break; |
| 2084 | case ARM_STMDB_UPD: |
| 2085 | MCInst_setOpcode(Inst, ARM_SRSDB_UPD); |
| 2086 | break; |
| 2087 | case ARM_STMIA: |
| 2088 | MCInst_setOpcode(Inst, ARM_SRSIA); |
| 2089 | break; |
| 2090 | case ARM_STMIA_UPD: |
| 2091 | MCInst_setOpcode(Inst, ARM_SRSIA_UPD); |
| 2092 | break; |
| 2093 | case ARM_STMIB: |
| 2094 | MCInst_setOpcode(Inst, ARM_SRSIB); |
| 2095 | break; |
| 2096 | case ARM_STMIB_UPD: |
| 2097 | MCInst_setOpcode(Inst, ARM_SRSIB_UPD); |
| 2098 | break; |
| 2099 | default: |
| 2100 | return MCDisassembler_Fail; |
| 2101 | } |
| 2102 | |
| 2103 | // For stores (which become SRS's, the only operand is the mode. |
| 2104 | if (fieldFromInstruction_4(Insn, 20, 1) == 0) { |
| 2105 | // Check SRS encoding constraints |
| 2106 | if (!(fieldFromInstruction_4(Insn, 22, 1) == 1 && |
| 2107 | fieldFromInstruction_4(Insn, 20, 1) == 0)) |
| 2108 | return MCDisassembler_Fail; |
| 2109 | |
| 2110 | MCOperand_CreateImm0(Inst, fieldFromInstruction_4(Insn, 0, 4)); |
| 2111 | return S; |
| 2112 | } |
| 2113 | |
| 2114 | return DecodeRFEInstruction(Inst, Insn, Address, Decoder); |
| 2115 | } |
| 2116 | |
| 2117 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2118 | return MCDisassembler_Fail; |
| 2119 | |
| 2120 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2121 | return MCDisassembler_Fail; // Tied |
| 2122 | |
| 2123 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 2124 | return MCDisassembler_Fail; |
| 2125 | |
| 2126 | if (!Check(&S, DecodeRegListOperand(Inst, reglist, Address, Decoder))) |
| 2127 | return MCDisassembler_Fail; |
| 2128 | |
| 2129 | return S; |
| 2130 | } |
| 2131 | |
| 2132 | // Check for UNPREDICTABLE predicated ESB instruction |
| 2133 | static DecodeStatus DecodeHINTInstruction(MCInst *Inst, unsigned Insn, |
| 2134 | uint64_t Address, const void *Decoder) |
| 2135 | { |
| 2136 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2137 | unsigned imm8 = fieldFromInstruction_4(Insn, 0, 8); |
| 2138 | DecodeStatus result = MCDisassembler_Success; |
| 2139 | |
| 2140 | MCOperand_CreateImm0(Inst, imm8); |
| 2141 | |
| 2142 | if (!Check(&result, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 2143 | return MCDisassembler_Fail; |
| 2144 | |
| 2145 | // ESB is unpredictable if pred != AL. Without the RAS extension, it is a NOP, |
| 2146 | // so all predicates should be allowed. |
| 2147 | if (imm8 == 0x10 && pred != 0xe && ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureRAS)) |
| 2148 | result = MCDisassembler_SoftFail; |
| 2149 | |
| 2150 | return result; |
| 2151 | } |
| 2152 | |
| 2153 | static DecodeStatus DecodeCPSInstruction(MCInst *Inst, unsigned Insn, |
| 2154 | uint64_t Address, const void *Decoder) |
| 2155 | { |
| 2156 | unsigned imod = fieldFromInstruction_4(Insn, 18, 2); |
| 2157 | unsigned M = fieldFromInstruction_4(Insn, 17, 1); |
| 2158 | unsigned iflags = fieldFromInstruction_4(Insn, 6, 3); |
| 2159 | unsigned mode = fieldFromInstruction_4(Insn, 0, 5); |
| 2160 | |
| 2161 | DecodeStatus S = MCDisassembler_Success; |
| 2162 | |
| 2163 | // This decoder is called from multiple location that do not check |
| 2164 | // the full encoding is valid before they do. |
| 2165 | if (fieldFromInstruction_4(Insn, 5, 1) != 0 || |
| 2166 | fieldFromInstruction_4(Insn, 16, 1) != 0 || |
| 2167 | fieldFromInstruction_4(Insn, 20, 8) != 0x10) |
| 2168 | return MCDisassembler_Fail; |
| 2169 | |
| 2170 | // imod == '01' --> UNPREDICTABLE |
| 2171 | // NOTE: Even though this is technically UNPREDICTABLE, we choose to |
| 2172 | // return failure here. The '01' imod value is unprintable, so there's |
| 2173 | // nothing useful we could do even if we returned UNPREDICTABLE. |
| 2174 | |
| 2175 | if (imod == 1) return MCDisassembler_Fail; |
| 2176 | |
| 2177 | if (imod && M) { |
| 2178 | MCInst_setOpcode(Inst, ARM_CPS3p); |
| 2179 | MCOperand_CreateImm0(Inst, imod); |
| 2180 | MCOperand_CreateImm0(Inst, iflags); |
| 2181 | MCOperand_CreateImm0(Inst, mode); |
| 2182 | } else if (imod && !M) { |
| 2183 | MCInst_setOpcode(Inst, ARM_CPS2p); |
| 2184 | MCOperand_CreateImm0(Inst, imod); |
| 2185 | MCOperand_CreateImm0(Inst, iflags); |
| 2186 | if (mode) S = MCDisassembler_SoftFail; |
| 2187 | } else if (!imod && M) { |
| 2188 | MCInst_setOpcode(Inst, ARM_CPS1p); |
| 2189 | MCOperand_CreateImm0(Inst, mode); |
| 2190 | if (iflags) S = MCDisassembler_SoftFail; |
| 2191 | } else { |
| 2192 | // imod == '00' && M == '0' --> UNPREDICTABLE |
| 2193 | MCInst_setOpcode(Inst, ARM_CPS1p); |
| 2194 | MCOperand_CreateImm0(Inst, mode); |
| 2195 | S = MCDisassembler_SoftFail; |
| 2196 | } |
| 2197 | |
| 2198 | return S; |
| 2199 | } |
| 2200 | |
| 2201 | static DecodeStatus DecodeT2CPSInstruction(MCInst *Inst, unsigned Insn, |
| 2202 | uint64_t Address, const void *Decoder) |
| 2203 | { |
| 2204 | unsigned imod = fieldFromInstruction_4(Insn, 9, 2); |
| 2205 | unsigned M = fieldFromInstruction_4(Insn, 8, 1); |
| 2206 | unsigned iflags = fieldFromInstruction_4(Insn, 5, 3); |
| 2207 | unsigned mode = fieldFromInstruction_4(Insn, 0, 5); |
| 2208 | |
| 2209 | DecodeStatus S = MCDisassembler_Success; |
| 2210 | |
| 2211 | // imod == '01' --> UNPREDICTABLE |
| 2212 | // NOTE: Even though this is technically UNPREDICTABLE, we choose to |
| 2213 | // return failure here. The '01' imod value is unprintable, so there's |
| 2214 | // nothing useful we could do even if we returned UNPREDICTABLE. |
| 2215 | |
| 2216 | if (imod == 1) return MCDisassembler_Fail; |
| 2217 | |
| 2218 | if (imod && M) { |
| 2219 | MCInst_setOpcode(Inst, ARM_t2CPS3p); |
| 2220 | MCOperand_CreateImm0(Inst, imod); |
| 2221 | MCOperand_CreateImm0(Inst, iflags); |
| 2222 | MCOperand_CreateImm0(Inst, mode); |
| 2223 | } else if (imod && !M) { |
| 2224 | MCInst_setOpcode(Inst, ARM_t2CPS2p); |
| 2225 | MCOperand_CreateImm0(Inst, imod); |
| 2226 | MCOperand_CreateImm0(Inst, iflags); |
| 2227 | if (mode) S = MCDisassembler_SoftFail; |
| 2228 | } else if (!imod && M) { |
| 2229 | MCInst_setOpcode(Inst, ARM_t2CPS1p); |
| 2230 | MCOperand_CreateImm0(Inst, mode); |
| 2231 | if (iflags) S = MCDisassembler_SoftFail; |
| 2232 | } else { |
| 2233 | // imod == '00' && M == '0' --> this is a HINT instruction |
| 2234 | int imm = fieldFromInstruction_4(Insn, 0, 8); |
| 2235 | // HINT are defined only for immediate in [0..4] |
| 2236 | if (imm > 4) return MCDisassembler_Fail; |
| 2237 | |
| 2238 | MCInst_setOpcode(Inst, ARM_t2HINT); |
| 2239 | MCOperand_CreateImm0(Inst, imm); |
| 2240 | } |
| 2241 | |
| 2242 | return S; |
| 2243 | } |
| 2244 | |
| 2245 | static DecodeStatus DecodeT2MOVTWInstruction(MCInst *Inst, unsigned Insn, |
| 2246 | uint64_t Address, const void *Decoder) |
| 2247 | { |
| 2248 | DecodeStatus S = MCDisassembler_Success; |
| 2249 | |
| 2250 | unsigned Rd = fieldFromInstruction_4(Insn, 8, 4); |
| 2251 | unsigned imm = 0; |
| 2252 | |
| 2253 | imm |= (fieldFromInstruction_4(Insn, 0, 8) << 0); |
| 2254 | imm |= (fieldFromInstruction_4(Insn, 12, 3) << 8); |
| 2255 | imm |= (fieldFromInstruction_4(Insn, 16, 4) << 12); |
| 2256 | imm |= (fieldFromInstruction_4(Insn, 26, 1) << 11); |
| 2257 | |
| 2258 | if (MCInst_getOpcode(Inst) == ARM_t2MOVTi16) |
| 2259 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 2260 | return MCDisassembler_Fail; |
| 2261 | |
| 2262 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 2263 | return MCDisassembler_Fail; |
| 2264 | |
| 2265 | MCOperand_CreateImm0(Inst, imm); |
| 2266 | |
| 2267 | return S; |
| 2268 | } |
| 2269 | |
| 2270 | static DecodeStatus DecodeArmMOVTWInstruction(MCInst *Inst, unsigned Insn, |
| 2271 | uint64_t Address, const void *Decoder) |
| 2272 | { |
| 2273 | DecodeStatus S = MCDisassembler_Success; |
| 2274 | |
| 2275 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 2276 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2277 | unsigned imm = 0; |
| 2278 | |
| 2279 | imm |= (fieldFromInstruction_4(Insn, 0, 12) << 0); |
| 2280 | imm |= (fieldFromInstruction_4(Insn, 16, 4) << 12); |
| 2281 | |
| 2282 | if (MCInst_getOpcode(Inst) == ARM_MOVTi16) |
| 2283 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder))) |
| 2284 | return MCDisassembler_Fail; |
| 2285 | |
| 2286 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder))) |
| 2287 | return MCDisassembler_Fail; |
| 2288 | |
| 2289 | MCOperand_CreateImm0(Inst, imm); |
| 2290 | |
| 2291 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 2292 | return MCDisassembler_Fail; |
| 2293 | |
| 2294 | return S; |
| 2295 | } |
| 2296 | |
| 2297 | static DecodeStatus DecodeSMLAInstruction(MCInst *Inst, unsigned Insn, |
| 2298 | uint64_t Address, const void *Decoder) |
| 2299 | { |
| 2300 | DecodeStatus S = MCDisassembler_Success; |
| 2301 | |
| 2302 | unsigned Rd = fieldFromInstruction_4(Insn, 16, 4); |
| 2303 | unsigned Rn = fieldFromInstruction_4(Insn, 0, 4); |
| 2304 | unsigned Rm = fieldFromInstruction_4(Insn, 8, 4); |
| 2305 | unsigned Ra = fieldFromInstruction_4(Insn, 12, 4); |
| 2306 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2307 | |
| 2308 | if (pred == 0xF) |
| 2309 | return DecodeCPSInstruction(Inst, Insn, Address, Decoder); |
| 2310 | |
| 2311 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder))) |
| 2312 | return MCDisassembler_Fail; |
| 2313 | |
| 2314 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder))) |
| 2315 | return MCDisassembler_Fail; |
| 2316 | |
| 2317 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder))) |
| 2318 | return MCDisassembler_Fail; |
| 2319 | |
| 2320 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder))) |
| 2321 | return MCDisassembler_Fail; |
| 2322 | |
| 2323 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 2324 | return MCDisassembler_Fail; |
| 2325 | |
| 2326 | return S; |
| 2327 | } |
| 2328 | |
| 2329 | static DecodeStatus DecodeTSTInstruction(MCInst *Inst, unsigned Insn, |
| 2330 | uint64_t Address, const void *Decoder) |
| 2331 | { |
| 2332 | DecodeStatus S = MCDisassembler_Success; |
| 2333 | unsigned Pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2334 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 2335 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 2336 | |
| 2337 | if (Pred == 0xF) |
| 2338 | return DecodeSETPANInstruction(Inst, Insn, Address, Decoder); |
| 2339 | |
| 2340 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2341 | return MCDisassembler_Fail; |
| 2342 | |
| 2343 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 2344 | return MCDisassembler_Fail; |
| 2345 | |
| 2346 | if (!Check(&S, DecodePredicateOperand(Inst, Pred, Address, Decoder))) |
| 2347 | return MCDisassembler_Fail; |
| 2348 | |
| 2349 | return S; |
| 2350 | } |
| 2351 | |
| 2352 | static DecodeStatus DecodeSETPANInstruction(MCInst *Inst, unsigned Insn, |
| 2353 | uint64_t Address, const void *Decoder) |
| 2354 | { |
| 2355 | DecodeStatus S = MCDisassembler_Success; |
| 2356 | unsigned Imm = fieldFromInstruction_4(Insn, 9, 1); |
| 2357 | |
| 2358 | if (!ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8_1aOps) || !ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8Ops)) |
| 2359 | return MCDisassembler_Fail; |
| 2360 | |
| 2361 | // Decoder can be called from DecodeTST, which does not check the full |
| 2362 | // encoding is valid. |
| 2363 | if (fieldFromInstruction_4(Insn, 20, 12) != 0xf11 || |
| 2364 | fieldFromInstruction_4(Insn, 4, 4) != 0) |
| 2365 | return MCDisassembler_Fail; |
| 2366 | |
| 2367 | if (fieldFromInstruction_4(Insn, 10, 10) != 0 || |
| 2368 | fieldFromInstruction_4(Insn, 0, 4) != 0) |
| 2369 | S = MCDisassembler_SoftFail; |
| 2370 | |
| 2371 | MCInst_setOpcode(Inst, ARM_SETPAN); |
| 2372 | MCOperand_CreateImm0(Inst, Imm); |
| 2373 | |
| 2374 | return S; |
| 2375 | } |
| 2376 | |
| 2377 | static DecodeStatus DecodeAddrModeImm12Operand(MCInst *Inst, unsigned Val, |
| 2378 | uint64_t Address, const void *Decoder) |
| 2379 | { |
| 2380 | DecodeStatus S = MCDisassembler_Success; |
| 2381 | unsigned add = fieldFromInstruction_4(Val, 12, 1); |
| 2382 | unsigned imm = fieldFromInstruction_4(Val, 0, 12); |
| 2383 | unsigned Rn = fieldFromInstruction_4(Val, 13, 4); |
| 2384 | |
| 2385 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2386 | return MCDisassembler_Fail; |
| 2387 | |
| 2388 | if (!add) imm *= (unsigned int)-1; |
| 2389 | if (imm == 0 && !add) imm = (unsigned int)INT32_MIN; |
| 2390 | |
| 2391 | MCOperand_CreateImm0(Inst, imm); |
| 2392 | //if (Rn == 15) |
| 2393 | // tryAddingPcLoadReferenceComment(Address, Address + imm + 8, Decoder); |
| 2394 | |
| 2395 | return S; |
| 2396 | } |
| 2397 | |
| 2398 | static DecodeStatus DecodeAddrMode5Operand(MCInst *Inst, unsigned Val, |
| 2399 | uint64_t Address, const void *Decoder) |
| 2400 | { |
| 2401 | DecodeStatus S = MCDisassembler_Success; |
| 2402 | unsigned Rn = fieldFromInstruction_4(Val, 9, 4); |
| 2403 | // U == 1 to add imm, 0 to subtract it. |
| 2404 | unsigned U = fieldFromInstruction_4(Val, 8, 1); |
| 2405 | unsigned imm = fieldFromInstruction_4(Val, 0, 8); |
| 2406 | |
| 2407 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2408 | return MCDisassembler_Fail; |
| 2409 | |
| 2410 | if (U) |
| 2411 | MCOperand_CreateImm0(Inst, ARM_AM_getAM5Opc(ARM_AM_add, (unsigned char)imm)); |
| 2412 | else |
| 2413 | MCOperand_CreateImm0(Inst, ARM_AM_getAM5Opc(ARM_AM_sub, (unsigned char)imm)); |
| 2414 | |
| 2415 | return S; |
| 2416 | } |
| 2417 | |
| 2418 | static DecodeStatus DecodeAddrMode5FP16Operand(MCInst *Inst, unsigned Val, |
| 2419 | uint64_t Address, const void *Decoder) |
| 2420 | { |
| 2421 | DecodeStatus S = MCDisassembler_Success; |
| 2422 | unsigned Rn = fieldFromInstruction_4(Val, 9, 4); |
| 2423 | // U == 1 to add imm, 0 to subtract it. |
| 2424 | unsigned U = fieldFromInstruction_4(Val, 8, 1); |
| 2425 | unsigned imm = fieldFromInstruction_4(Val, 0, 8); |
| 2426 | |
| 2427 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 2428 | return MCDisassembler_Fail; |
| 2429 | |
| 2430 | if (U) |
| 2431 | MCOperand_CreateImm0(Inst, getAM5FP16Opc(ARM_AM_add, imm)); |
| 2432 | else |
| 2433 | MCOperand_CreateImm0(Inst, getAM5FP16Opc(ARM_AM_sub, imm)); |
| 2434 | |
| 2435 | return S; |
| 2436 | } |
| 2437 | |
| 2438 | static DecodeStatus DecodeAddrMode7Operand(MCInst *Inst, unsigned Val, |
| 2439 | uint64_t Address, const void *Decoder) |
| 2440 | { |
| 2441 | return DecodeGPRRegisterClass(Inst, Val, Address, Decoder); |
| 2442 | } |
| 2443 | |
| 2444 | static DecodeStatus DecodeT2BInstruction(MCInst *Inst, unsigned Insn, |
| 2445 | uint64_t Address, const void *Decoder) |
| 2446 | { |
| 2447 | DecodeStatus Status = MCDisassembler_Success; |
| 2448 | |
| 2449 | // Note the J1 and J2 values are from the encoded instruction. So here |
| 2450 | // change them to I1 and I2 values via as documented: |
| 2451 | // I1 = NOT(J1 EOR S); |
| 2452 | // I2 = NOT(J2 EOR S); |
| 2453 | // and build the imm32 with one trailing zero as documented: |
| 2454 | // imm32 = SignExtend(S:I1:I2:imm10:imm11:'0', 32); |
| 2455 | unsigned S = fieldFromInstruction_4(Insn, 26, 1); |
| 2456 | unsigned J1 = fieldFromInstruction_4(Insn, 13, 1); |
| 2457 | unsigned J2 = fieldFromInstruction_4(Insn, 11, 1); |
| 2458 | unsigned I1 = !(J1 ^ S); |
| 2459 | unsigned I2 = !(J2 ^ S); |
| 2460 | unsigned imm10 = fieldFromInstruction_4(Insn, 16, 10); |
| 2461 | unsigned imm11 = fieldFromInstruction_4(Insn, 0, 11); |
| 2462 | unsigned tmp = (S << 23) | (I1 << 22) | (I2 << 21) | (imm10 << 11) | imm11; |
| 2463 | int imm32 = SignExtend32(tmp << 1, 25); |
| 2464 | |
| 2465 | MCOperand_CreateImm0(Inst, imm32); |
| 2466 | |
| 2467 | return Status; |
| 2468 | } |
| 2469 | |
| 2470 | static DecodeStatus DecodeBranchImmInstruction(MCInst *Inst, unsigned Insn, |
| 2471 | uint64_t Address, const void *Decoder) |
| 2472 | { |
| 2473 | DecodeStatus S = MCDisassembler_Success; |
| 2474 | |
| 2475 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 2476 | unsigned imm = fieldFromInstruction_4(Insn, 0, 24) << 2; |
| 2477 | |
| 2478 | if (pred == 0xF) { |
| 2479 | MCInst_setOpcode(Inst, ARM_BLXi); |
| 2480 | imm |= fieldFromInstruction_4(Insn, 24, 1) << 1; |
| 2481 | MCOperand_CreateImm0(Inst, SignExtend32(imm, 26)); |
| 2482 | return S; |
| 2483 | } |
| 2484 | |
| 2485 | MCOperand_CreateImm0(Inst, SignExtend32(imm, 26)); |
| 2486 | |
| 2487 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 2488 | return MCDisassembler_Fail; |
| 2489 | |
| 2490 | return S; |
| 2491 | } |
| 2492 | |
| 2493 | |
| 2494 | static DecodeStatus DecodeAddrMode6Operand(MCInst *Inst, unsigned Val, |
| 2495 | uint64_t Address, const void *Decoder) |
| 2496 | { |
| 2497 | DecodeStatus S = MCDisassembler_Success; |
| 2498 | |
| 2499 | unsigned Rm = fieldFromInstruction_4(Val, 0, 4); |
| 2500 | unsigned align = fieldFromInstruction_4(Val, 4, 2); |
| 2501 | |
| 2502 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 2503 | return MCDisassembler_Fail; |
| 2504 | |
| 2505 | if (!align) |
| 2506 | MCOperand_CreateImm0(Inst, 0); |
| 2507 | else |
| 2508 | MCOperand_CreateImm0(Inst, 4 << align); |
| 2509 | |
| 2510 | return S; |
| 2511 | } |
| 2512 | |
| 2513 | static DecodeStatus DecodeVLDInstruction(MCInst *Inst, unsigned Insn, |
| 2514 | uint64_t Address, const void *Decoder) |
| 2515 | { |
| 2516 | DecodeStatus S = MCDisassembler_Success; |
| 2517 | unsigned wb, Rn, Rm; |
| 2518 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 2519 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 2520 | wb = fieldFromInstruction_4(Insn, 16, 4); |
| 2521 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 2522 | Rn |= fieldFromInstruction_4(Insn, 4, 2) << 4; |
| 2523 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 2524 | |
| 2525 | // First output register |
| 2526 | switch (MCInst_getOpcode(Inst)) { |
| 2527 | case ARM_VLD1q16: case ARM_VLD1q32: case ARM_VLD1q64: case ARM_VLD1q8: |
| 2528 | case ARM_VLD1q16wb_fixed: case ARM_VLD1q16wb_register: |
| 2529 | case ARM_VLD1q32wb_fixed: case ARM_VLD1q32wb_register: |
| 2530 | case ARM_VLD1q64wb_fixed: case ARM_VLD1q64wb_register: |
| 2531 | case ARM_VLD1q8wb_fixed: case ARM_VLD1q8wb_register: |
| 2532 | case ARM_VLD2d16: case ARM_VLD2d32: case ARM_VLD2d8: |
| 2533 | case ARM_VLD2d16wb_fixed: case ARM_VLD2d16wb_register: |
| 2534 | case ARM_VLD2d32wb_fixed: case ARM_VLD2d32wb_register: |
| 2535 | case ARM_VLD2d8wb_fixed: case ARM_VLD2d8wb_register: |
| 2536 | if (!Check(&S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder))) |
| 2537 | return MCDisassembler_Fail; |
| 2538 | break; |
| 2539 | |
| 2540 | case ARM_VLD2b16: |
| 2541 | case ARM_VLD2b32: |
| 2542 | case ARM_VLD2b8: |
| 2543 | case ARM_VLD2b16wb_fixed: |
| 2544 | case ARM_VLD2b16wb_register: |
| 2545 | case ARM_VLD2b32wb_fixed: |
| 2546 | case ARM_VLD2b32wb_register: |
| 2547 | case ARM_VLD2b8wb_fixed: |
| 2548 | case ARM_VLD2b8wb_register: |
| 2549 | if (!Check(&S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder))) |
| 2550 | return MCDisassembler_Fail; |
| 2551 | break; |
| 2552 | |
| 2553 | default: |
| 2554 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 2555 | return MCDisassembler_Fail; |
| 2556 | } |
| 2557 | |
| 2558 | // Second output register |
| 2559 | switch (MCInst_getOpcode(Inst)) { |
| 2560 | case ARM_VLD3d8: |
| 2561 | case ARM_VLD3d16: |
| 2562 | case ARM_VLD3d32: |
| 2563 | case ARM_VLD3d8_UPD: |
| 2564 | case ARM_VLD3d16_UPD: |
| 2565 | case ARM_VLD3d32_UPD: |
| 2566 | case ARM_VLD4d8: |
| 2567 | case ARM_VLD4d16: |
| 2568 | case ARM_VLD4d32: |
| 2569 | case ARM_VLD4d8_UPD: |
| 2570 | case ARM_VLD4d16_UPD: |
| 2571 | case ARM_VLD4d32_UPD: |
| 2572 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 1) % 32, Address, Decoder))) |
| 2573 | return MCDisassembler_Fail; |
| 2574 | break; |
| 2575 | |
| 2576 | case ARM_VLD3q8: |
| 2577 | case ARM_VLD3q16: |
| 2578 | case ARM_VLD3q32: |
| 2579 | case ARM_VLD3q8_UPD: |
| 2580 | case ARM_VLD3q16_UPD: |
| 2581 | case ARM_VLD3q32_UPD: |
| 2582 | case ARM_VLD4q8: |
| 2583 | case ARM_VLD4q16: |
| 2584 | case ARM_VLD4q32: |
| 2585 | case ARM_VLD4q8_UPD: |
| 2586 | case ARM_VLD4q16_UPD: |
| 2587 | case ARM_VLD4q32_UPD: |
| 2588 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 2) % 32, Address, Decoder))) |
| 2589 | return MCDisassembler_Fail; |
| 2590 | |
| 2591 | default: |
| 2592 | break; |
| 2593 | } |
| 2594 | |
| 2595 | // Third output register |
| 2596 | switch(MCInst_getOpcode(Inst)) { |
| 2597 | case ARM_VLD3d8: |
| 2598 | case ARM_VLD3d16: |
| 2599 | case ARM_VLD3d32: |
| 2600 | case ARM_VLD3d8_UPD: |
| 2601 | case ARM_VLD3d16_UPD: |
| 2602 | case ARM_VLD3d32_UPD: |
| 2603 | case ARM_VLD4d8: |
| 2604 | case ARM_VLD4d16: |
| 2605 | case ARM_VLD4d32: |
| 2606 | case ARM_VLD4d8_UPD: |
| 2607 | case ARM_VLD4d16_UPD: |
| 2608 | case ARM_VLD4d32_UPD: |
| 2609 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 2) % 32, Address, Decoder))) |
| 2610 | return MCDisassembler_Fail; |
| 2611 | break; |
| 2612 | case ARM_VLD3q8: |
| 2613 | case ARM_VLD3q16: |
| 2614 | case ARM_VLD3q32: |
| 2615 | case ARM_VLD3q8_UPD: |
| 2616 | case ARM_VLD3q16_UPD: |
| 2617 | case ARM_VLD3q32_UPD: |
| 2618 | case ARM_VLD4q8: |
| 2619 | case ARM_VLD4q16: |
| 2620 | case ARM_VLD4q32: |
| 2621 | case ARM_VLD4q8_UPD: |
| 2622 | case ARM_VLD4q16_UPD: |
| 2623 | case ARM_VLD4q32_UPD: |
| 2624 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 4) % 32, Address, Decoder))) |
| 2625 | return MCDisassembler_Fail; |
| 2626 | break; |
| 2627 | default: |
| 2628 | break; |
| 2629 | } |
| 2630 | |
| 2631 | // Fourth output register |
| 2632 | switch (MCInst_getOpcode(Inst)) { |
| 2633 | case ARM_VLD4d8: |
| 2634 | case ARM_VLD4d16: |
| 2635 | case ARM_VLD4d32: |
| 2636 | case ARM_VLD4d8_UPD: |
| 2637 | case ARM_VLD4d16_UPD: |
| 2638 | case ARM_VLD4d32_UPD: |
| 2639 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 3) % 32, Address, Decoder))) |
| 2640 | return MCDisassembler_Fail; |
| 2641 | break; |
| 2642 | case ARM_VLD4q8: |
| 2643 | case ARM_VLD4q16: |
| 2644 | case ARM_VLD4q32: |
| 2645 | case ARM_VLD4q8_UPD: |
| 2646 | case ARM_VLD4q16_UPD: |
| 2647 | case ARM_VLD4q32_UPD: |
| 2648 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 6) % 32, Address, Decoder))) |
| 2649 | return MCDisassembler_Fail; |
| 2650 | break; |
| 2651 | default: |
| 2652 | break; |
| 2653 | } |
| 2654 | |
| 2655 | // Writeback operand |
| 2656 | switch (MCInst_getOpcode(Inst)) { |
| 2657 | case ARM_VLD1d8wb_fixed: |
| 2658 | case ARM_VLD1d16wb_fixed: |
| 2659 | case ARM_VLD1d32wb_fixed: |
| 2660 | case ARM_VLD1d64wb_fixed: |
| 2661 | case ARM_VLD1d8wb_register: |
| 2662 | case ARM_VLD1d16wb_register: |
| 2663 | case ARM_VLD1d32wb_register: |
| 2664 | case ARM_VLD1d64wb_register: |
| 2665 | case ARM_VLD1q8wb_fixed: |
| 2666 | case ARM_VLD1q16wb_fixed: |
| 2667 | case ARM_VLD1q32wb_fixed: |
| 2668 | case ARM_VLD1q64wb_fixed: |
| 2669 | case ARM_VLD1q8wb_register: |
| 2670 | case ARM_VLD1q16wb_register: |
| 2671 | case ARM_VLD1q32wb_register: |
| 2672 | case ARM_VLD1q64wb_register: |
| 2673 | case ARM_VLD1d8Twb_fixed: |
| 2674 | case ARM_VLD1d8Twb_register: |
| 2675 | case ARM_VLD1d16Twb_fixed: |
| 2676 | case ARM_VLD1d16Twb_register: |
| 2677 | case ARM_VLD1d32Twb_fixed: |
| 2678 | case ARM_VLD1d32Twb_register: |
| 2679 | case ARM_VLD1d64Twb_fixed: |
| 2680 | case ARM_VLD1d64Twb_register: |
| 2681 | case ARM_VLD1d8Qwb_fixed: |
| 2682 | case ARM_VLD1d8Qwb_register: |
| 2683 | case ARM_VLD1d16Qwb_fixed: |
| 2684 | case ARM_VLD1d16Qwb_register: |
| 2685 | case ARM_VLD1d32Qwb_fixed: |
| 2686 | case ARM_VLD1d32Qwb_register: |
| 2687 | case ARM_VLD1d64Qwb_fixed: |
| 2688 | case ARM_VLD1d64Qwb_register: |
| 2689 | case ARM_VLD2d8wb_fixed: |
| 2690 | case ARM_VLD2d16wb_fixed: |
| 2691 | case ARM_VLD2d32wb_fixed: |
| 2692 | case ARM_VLD2q8wb_fixed: |
| 2693 | case ARM_VLD2q16wb_fixed: |
| 2694 | case ARM_VLD2q32wb_fixed: |
| 2695 | case ARM_VLD2d8wb_register: |
| 2696 | case ARM_VLD2d16wb_register: |
| 2697 | case ARM_VLD2d32wb_register: |
| 2698 | case ARM_VLD2q8wb_register: |
| 2699 | case ARM_VLD2q16wb_register: |
| 2700 | case ARM_VLD2q32wb_register: |
| 2701 | case ARM_VLD2b8wb_fixed: |
| 2702 | case ARM_VLD2b16wb_fixed: |
| 2703 | case ARM_VLD2b32wb_fixed: |
| 2704 | case ARM_VLD2b8wb_register: |
| 2705 | case ARM_VLD2b16wb_register: |
| 2706 | case ARM_VLD2b32wb_register: |
| 2707 | MCOperand_CreateImm0(Inst, 0); |
| 2708 | break; |
| 2709 | |
| 2710 | case ARM_VLD3d8_UPD: |
| 2711 | case ARM_VLD3d16_UPD: |
| 2712 | case ARM_VLD3d32_UPD: |
| 2713 | case ARM_VLD3q8_UPD: |
| 2714 | case ARM_VLD3q16_UPD: |
| 2715 | case ARM_VLD3q32_UPD: |
| 2716 | case ARM_VLD4d8_UPD: |
| 2717 | case ARM_VLD4d16_UPD: |
| 2718 | case ARM_VLD4d32_UPD: |
| 2719 | case ARM_VLD4q8_UPD: |
| 2720 | case ARM_VLD4q16_UPD: |
| 2721 | case ARM_VLD4q32_UPD: |
| 2722 | if (!Check(&S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder))) |
| 2723 | return MCDisassembler_Fail; |
| 2724 | break; |
| 2725 | |
| 2726 | default: |
| 2727 | break; |
| 2728 | } |
| 2729 | |
| 2730 | // AddrMode6 Base (register+alignment) |
| 2731 | if (!Check(&S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder))) |
| 2732 | return MCDisassembler_Fail; |
| 2733 | |
| 2734 | // AddrMode6 Offset (register) |
| 2735 | switch (MCInst_getOpcode(Inst)) { |
| 2736 | default: |
| 2737 | // The below have been updated to have explicit am6offset split |
| 2738 | // between fixed and register offset. For those instructions not |
| 2739 | // yet updated, we need to add an additional reg0 operand for the |
| 2740 | // fixed variant. |
| 2741 | // |
| 2742 | // The fixed offset encodes as Rm == 0xd, so we check for that. |
| 2743 | if (Rm == 0xd) { |
| 2744 | MCOperand_CreateReg0(Inst, 0); |
| 2745 | break; |
| 2746 | } |
| 2747 | // Fall through to handle the register offset variant. |
| 2748 | |
| 2749 | case ARM_VLD1d8wb_fixed: |
| 2750 | case ARM_VLD1d16wb_fixed: |
| 2751 | case ARM_VLD1d32wb_fixed: |
| 2752 | case ARM_VLD1d64wb_fixed: |
| 2753 | case ARM_VLD1d8Twb_fixed: |
| 2754 | case ARM_VLD1d16Twb_fixed: |
| 2755 | case ARM_VLD1d32Twb_fixed: |
| 2756 | case ARM_VLD1d64Twb_fixed: |
| 2757 | case ARM_VLD1d8Qwb_fixed: |
| 2758 | case ARM_VLD1d16Qwb_fixed: |
| 2759 | case ARM_VLD1d32Qwb_fixed: |
| 2760 | case ARM_VLD1d64Qwb_fixed: |
| 2761 | case ARM_VLD1d8wb_register: |
| 2762 | case ARM_VLD1d16wb_register: |
| 2763 | case ARM_VLD1d32wb_register: |
| 2764 | case ARM_VLD1d64wb_register: |
| 2765 | case ARM_VLD1q8wb_fixed: |
| 2766 | case ARM_VLD1q16wb_fixed: |
| 2767 | case ARM_VLD1q32wb_fixed: |
| 2768 | case ARM_VLD1q64wb_fixed: |
| 2769 | case ARM_VLD1q8wb_register: |
| 2770 | case ARM_VLD1q16wb_register: |
| 2771 | case ARM_VLD1q32wb_register: |
| 2772 | case ARM_VLD1q64wb_register: |
| 2773 | // The fixed offset post-increment encodes Rm == 0xd. The no-writeback |
| 2774 | // variant encodes Rm == 0xf. Anything else is a register offset post- |
| 2775 | // increment and we need to add the register operand to the instruction. |
| 2776 | if (Rm != 0xD && Rm != 0xF && |
| 2777 | !Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 2778 | return MCDisassembler_Fail; |
| 2779 | break; |
| 2780 | |
| 2781 | case ARM_VLD2d8wb_fixed: |
| 2782 | case ARM_VLD2d16wb_fixed: |
| 2783 | case ARM_VLD2d32wb_fixed: |
| 2784 | case ARM_VLD2b8wb_fixed: |
| 2785 | case ARM_VLD2b16wb_fixed: |
| 2786 | case ARM_VLD2b32wb_fixed: |
| 2787 | case ARM_VLD2q8wb_fixed: |
| 2788 | case ARM_VLD2q16wb_fixed: |
| 2789 | case ARM_VLD2q32wb_fixed: |
| 2790 | break; |
| 2791 | } |
| 2792 | |
| 2793 | return S; |
| 2794 | } |
| 2795 | |
| 2796 | static DecodeStatus DecodeVLDST1Instruction(MCInst *Inst, unsigned Insn, |
| 2797 | uint64_t Address, const void *Decoder) |
| 2798 | { |
| 2799 | unsigned load; |
| 2800 | unsigned type = fieldFromInstruction_4(Insn, 8, 4); |
| 2801 | unsigned align = fieldFromInstruction_4(Insn, 4, 2); |
| 2802 | if (type == 6 && (align & 2)) return MCDisassembler_Fail; |
| 2803 | if (type == 7 && (align & 2)) return MCDisassembler_Fail; |
| 2804 | if (type == 10 && align == 3) return MCDisassembler_Fail; |
| 2805 | |
| 2806 | load = fieldFromInstruction_4(Insn, 21, 1); |
| 2807 | |
| 2808 | return load ? DecodeVLDInstruction(Inst, Insn, Address, Decoder) |
| 2809 | : DecodeVSTInstruction(Inst, Insn, Address, Decoder); |
| 2810 | } |
| 2811 | |
| 2812 | static DecodeStatus DecodeVLDST2Instruction(MCInst *Inst, unsigned Insn, |
| 2813 | uint64_t Address, const void *Decoder) |
| 2814 | { |
| 2815 | unsigned type, align, load; |
| 2816 | unsigned size = fieldFromInstruction_4(Insn, 6, 2); |
| 2817 | if (size == 3) return MCDisassembler_Fail; |
| 2818 | |
| 2819 | type = fieldFromInstruction_4(Insn, 8, 4); |
| 2820 | align = fieldFromInstruction_4(Insn, 4, 2); |
| 2821 | if (type == 8 && align == 3) return MCDisassembler_Fail; |
| 2822 | if (type == 9 && align == 3) return MCDisassembler_Fail; |
| 2823 | |
| 2824 | load = fieldFromInstruction_4(Insn, 21, 1); |
| 2825 | |
| 2826 | return load ? DecodeVLDInstruction(Inst, Insn, Address, Decoder) |
| 2827 | : DecodeVSTInstruction(Inst, Insn, Address, Decoder); |
| 2828 | } |
| 2829 | |
| 2830 | static DecodeStatus DecodeVLDST3Instruction(MCInst *Inst, unsigned Insn, |
| 2831 | uint64_t Address, const void *Decoder) |
| 2832 | { |
| 2833 | unsigned align, load; |
| 2834 | unsigned size = fieldFromInstruction_4(Insn, 6, 2); |
| 2835 | if (size == 3) return MCDisassembler_Fail; |
| 2836 | |
| 2837 | align = fieldFromInstruction_4(Insn, 4, 2); |
| 2838 | if (align & 2) return MCDisassembler_Fail; |
| 2839 | |
| 2840 | load = fieldFromInstruction_4(Insn, 21, 1); |
| 2841 | |
| 2842 | return load ? DecodeVLDInstruction(Inst, Insn, Address, Decoder) |
| 2843 | : DecodeVSTInstruction(Inst, Insn, Address, Decoder); |
| 2844 | } |
| 2845 | |
| 2846 | static DecodeStatus DecodeVLDST4Instruction(MCInst *Inst, unsigned Insn, |
| 2847 | uint64_t Address, const void *Decoder) |
| 2848 | { |
| 2849 | unsigned load; |
| 2850 | unsigned size = fieldFromInstruction_4(Insn, 6, 2); |
| 2851 | if (size == 3) return MCDisassembler_Fail; |
| 2852 | |
| 2853 | load = fieldFromInstruction_4(Insn, 21, 1); |
| 2854 | |
| 2855 | return load ? DecodeVLDInstruction(Inst, Insn, Address, Decoder) |
| 2856 | : DecodeVSTInstruction(Inst, Insn, Address, Decoder); |
| 2857 | } |
| 2858 | |
| 2859 | static DecodeStatus DecodeVSTInstruction(MCInst *Inst, unsigned Insn, |
| 2860 | uint64_t Address, const void *Decoder) |
| 2861 | { |
| 2862 | DecodeStatus S = MCDisassembler_Success; |
| 2863 | unsigned wb, Rn, Rm; |
| 2864 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 2865 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 2866 | wb = fieldFromInstruction_4(Insn, 16, 4); |
| 2867 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 2868 | Rn |= fieldFromInstruction_4(Insn, 4, 2) << 4; |
| 2869 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 2870 | |
| 2871 | // Writeback Operand |
| 2872 | switch (MCInst_getOpcode(Inst)) { |
| 2873 | case ARM_VST1d8wb_fixed: |
| 2874 | case ARM_VST1d16wb_fixed: |
| 2875 | case ARM_VST1d32wb_fixed: |
| 2876 | case ARM_VST1d64wb_fixed: |
| 2877 | case ARM_VST1d8wb_register: |
| 2878 | case ARM_VST1d16wb_register: |
| 2879 | case ARM_VST1d32wb_register: |
| 2880 | case ARM_VST1d64wb_register: |
| 2881 | case ARM_VST1q8wb_fixed: |
| 2882 | case ARM_VST1q16wb_fixed: |
| 2883 | case ARM_VST1q32wb_fixed: |
| 2884 | case ARM_VST1q64wb_fixed: |
| 2885 | case ARM_VST1q8wb_register: |
| 2886 | case ARM_VST1q16wb_register: |
| 2887 | case ARM_VST1q32wb_register: |
| 2888 | case ARM_VST1q64wb_register: |
| 2889 | case ARM_VST1d8Twb_fixed: |
| 2890 | case ARM_VST1d16Twb_fixed: |
| 2891 | case ARM_VST1d32Twb_fixed: |
| 2892 | case ARM_VST1d64Twb_fixed: |
| 2893 | case ARM_VST1d8Twb_register: |
| 2894 | case ARM_VST1d16Twb_register: |
| 2895 | case ARM_VST1d32Twb_register: |
| 2896 | case ARM_VST1d64Twb_register: |
| 2897 | case ARM_VST1d8Qwb_fixed: |
| 2898 | case ARM_VST1d16Qwb_fixed: |
| 2899 | case ARM_VST1d32Qwb_fixed: |
| 2900 | case ARM_VST1d64Qwb_fixed: |
| 2901 | case ARM_VST1d8Qwb_register: |
| 2902 | case ARM_VST1d16Qwb_register: |
| 2903 | case ARM_VST1d32Qwb_register: |
| 2904 | case ARM_VST1d64Qwb_register: |
| 2905 | case ARM_VST2d8wb_fixed: |
| 2906 | case ARM_VST2d16wb_fixed: |
| 2907 | case ARM_VST2d32wb_fixed: |
| 2908 | case ARM_VST2d8wb_register: |
| 2909 | case ARM_VST2d16wb_register: |
| 2910 | case ARM_VST2d32wb_register: |
| 2911 | case ARM_VST2q8wb_fixed: |
| 2912 | case ARM_VST2q16wb_fixed: |
| 2913 | case ARM_VST2q32wb_fixed: |
| 2914 | case ARM_VST2q8wb_register: |
| 2915 | case ARM_VST2q16wb_register: |
| 2916 | case ARM_VST2q32wb_register: |
| 2917 | case ARM_VST2b8wb_fixed: |
| 2918 | case ARM_VST2b16wb_fixed: |
| 2919 | case ARM_VST2b32wb_fixed: |
| 2920 | case ARM_VST2b8wb_register: |
| 2921 | case ARM_VST2b16wb_register: |
| 2922 | case ARM_VST2b32wb_register: |
| 2923 | if (Rm == 0xF) |
| 2924 | return MCDisassembler_Fail; |
| 2925 | MCOperand_CreateImm0(Inst, 0); |
| 2926 | break; |
| 2927 | case ARM_VST3d8_UPD: |
| 2928 | case ARM_VST3d16_UPD: |
| 2929 | case ARM_VST3d32_UPD: |
| 2930 | case ARM_VST3q8_UPD: |
| 2931 | case ARM_VST3q16_UPD: |
| 2932 | case ARM_VST3q32_UPD: |
| 2933 | case ARM_VST4d8_UPD: |
| 2934 | case ARM_VST4d16_UPD: |
| 2935 | case ARM_VST4d32_UPD: |
| 2936 | case ARM_VST4q8_UPD: |
| 2937 | case ARM_VST4q16_UPD: |
| 2938 | case ARM_VST4q32_UPD: |
| 2939 | if (!Check(&S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder))) |
| 2940 | return MCDisassembler_Fail; |
| 2941 | break; |
| 2942 | default: |
| 2943 | break; |
| 2944 | } |
| 2945 | |
| 2946 | // AddrMode6 Base (register+alignment) |
| 2947 | if (!Check(&S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder))) |
| 2948 | return MCDisassembler_Fail; |
| 2949 | |
| 2950 | // AddrMode6 Offset (register) |
| 2951 | switch (MCInst_getOpcode(Inst)) { |
| 2952 | default: |
| 2953 | if (Rm == 0xD) |
| 2954 | MCOperand_CreateReg0(Inst, 0); |
| 2955 | else if (Rm != 0xF) { |
| 2956 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 2957 | return MCDisassembler_Fail; |
| 2958 | } |
| 2959 | break; |
| 2960 | |
| 2961 | case ARM_VST1d8wb_fixed: |
| 2962 | case ARM_VST1d16wb_fixed: |
| 2963 | case ARM_VST1d32wb_fixed: |
| 2964 | case ARM_VST1d64wb_fixed: |
| 2965 | case ARM_VST1q8wb_fixed: |
| 2966 | case ARM_VST1q16wb_fixed: |
| 2967 | case ARM_VST1q32wb_fixed: |
| 2968 | case ARM_VST1q64wb_fixed: |
| 2969 | case ARM_VST1d8Twb_fixed: |
| 2970 | case ARM_VST1d16Twb_fixed: |
| 2971 | case ARM_VST1d32Twb_fixed: |
| 2972 | case ARM_VST1d64Twb_fixed: |
| 2973 | case ARM_VST1d8Qwb_fixed: |
| 2974 | case ARM_VST1d16Qwb_fixed: |
| 2975 | case ARM_VST1d32Qwb_fixed: |
| 2976 | case ARM_VST1d64Qwb_fixed: |
| 2977 | case ARM_VST2d8wb_fixed: |
| 2978 | case ARM_VST2d16wb_fixed: |
| 2979 | case ARM_VST2d32wb_fixed: |
| 2980 | case ARM_VST2q8wb_fixed: |
| 2981 | case ARM_VST2q16wb_fixed: |
| 2982 | case ARM_VST2q32wb_fixed: |
| 2983 | case ARM_VST2b8wb_fixed: |
| 2984 | case ARM_VST2b16wb_fixed: |
| 2985 | case ARM_VST2b32wb_fixed: |
| 2986 | break; |
| 2987 | } |
| 2988 | |
| 2989 | |
| 2990 | // First input register |
| 2991 | switch (MCInst_getOpcode(Inst)) { |
| 2992 | case ARM_VST1q16: |
| 2993 | case ARM_VST1q32: |
| 2994 | case ARM_VST1q64: |
| 2995 | case ARM_VST1q8: |
| 2996 | case ARM_VST1q16wb_fixed: |
| 2997 | case ARM_VST1q16wb_register: |
| 2998 | case ARM_VST1q32wb_fixed: |
| 2999 | case ARM_VST1q32wb_register: |
| 3000 | case ARM_VST1q64wb_fixed: |
| 3001 | case ARM_VST1q64wb_register: |
| 3002 | case ARM_VST1q8wb_fixed: |
| 3003 | case ARM_VST1q8wb_register: |
| 3004 | case ARM_VST2d16: |
| 3005 | case ARM_VST2d32: |
| 3006 | case ARM_VST2d8: |
| 3007 | case ARM_VST2d16wb_fixed: |
| 3008 | case ARM_VST2d16wb_register: |
| 3009 | case ARM_VST2d32wb_fixed: |
| 3010 | case ARM_VST2d32wb_register: |
| 3011 | case ARM_VST2d8wb_fixed: |
| 3012 | case ARM_VST2d8wb_register: |
| 3013 | if (!Check(&S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder))) |
| 3014 | return MCDisassembler_Fail; |
| 3015 | break; |
| 3016 | |
| 3017 | case ARM_VST2b16: |
| 3018 | case ARM_VST2b32: |
| 3019 | case ARM_VST2b8: |
| 3020 | case ARM_VST2b16wb_fixed: |
| 3021 | case ARM_VST2b16wb_register: |
| 3022 | case ARM_VST2b32wb_fixed: |
| 3023 | case ARM_VST2b32wb_register: |
| 3024 | case ARM_VST2b8wb_fixed: |
| 3025 | case ARM_VST2b8wb_register: |
| 3026 | if (!Check(&S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder))) |
| 3027 | return MCDisassembler_Fail; |
| 3028 | break; |
| 3029 | |
| 3030 | default: |
| 3031 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3032 | return MCDisassembler_Fail; |
| 3033 | } |
| 3034 | |
| 3035 | // Second input register |
| 3036 | switch (MCInst_getOpcode(Inst)) { |
| 3037 | case ARM_VST3d8: |
| 3038 | case ARM_VST3d16: |
| 3039 | case ARM_VST3d32: |
| 3040 | case ARM_VST3d8_UPD: |
| 3041 | case ARM_VST3d16_UPD: |
| 3042 | case ARM_VST3d32_UPD: |
| 3043 | case ARM_VST4d8: |
| 3044 | case ARM_VST4d16: |
| 3045 | case ARM_VST4d32: |
| 3046 | case ARM_VST4d8_UPD: |
| 3047 | case ARM_VST4d16_UPD: |
| 3048 | case ARM_VST4d32_UPD: |
| 3049 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 1) % 32, Address, Decoder))) |
| 3050 | return MCDisassembler_Fail; |
| 3051 | break; |
| 3052 | |
| 3053 | case ARM_VST3q8: |
| 3054 | case ARM_VST3q16: |
| 3055 | case ARM_VST3q32: |
| 3056 | case ARM_VST3q8_UPD: |
| 3057 | case ARM_VST3q16_UPD: |
| 3058 | case ARM_VST3q32_UPD: |
| 3059 | case ARM_VST4q8: |
| 3060 | case ARM_VST4q16: |
| 3061 | case ARM_VST4q32: |
| 3062 | case ARM_VST4q8_UPD: |
| 3063 | case ARM_VST4q16_UPD: |
| 3064 | case ARM_VST4q32_UPD: |
| 3065 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 2) % 32, Address, Decoder))) |
| 3066 | return MCDisassembler_Fail; |
| 3067 | break; |
| 3068 | default: |
| 3069 | break; |
| 3070 | } |
| 3071 | |
| 3072 | // Third input register |
| 3073 | switch (MCInst_getOpcode(Inst)) { |
| 3074 | case ARM_VST3d8: |
| 3075 | case ARM_VST3d16: |
| 3076 | case ARM_VST3d32: |
| 3077 | case ARM_VST3d8_UPD: |
| 3078 | case ARM_VST3d16_UPD: |
| 3079 | case ARM_VST3d32_UPD: |
| 3080 | case ARM_VST4d8: |
| 3081 | case ARM_VST4d16: |
| 3082 | case ARM_VST4d32: |
| 3083 | case ARM_VST4d8_UPD: |
| 3084 | case ARM_VST4d16_UPD: |
| 3085 | case ARM_VST4d32_UPD: |
| 3086 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 2) % 32, Address, Decoder))) |
| 3087 | return MCDisassembler_Fail; |
| 3088 | break; |
| 3089 | |
| 3090 | case ARM_VST3q8: |
| 3091 | case ARM_VST3q16: |
| 3092 | case ARM_VST3q32: |
| 3093 | case ARM_VST3q8_UPD: |
| 3094 | case ARM_VST3q16_UPD: |
| 3095 | case ARM_VST3q32_UPD: |
| 3096 | case ARM_VST4q8: |
| 3097 | case ARM_VST4q16: |
| 3098 | case ARM_VST4q32: |
| 3099 | case ARM_VST4q8_UPD: |
| 3100 | case ARM_VST4q16_UPD: |
| 3101 | case ARM_VST4q32_UPD: |
| 3102 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 4) % 32, Address, Decoder))) |
| 3103 | return MCDisassembler_Fail; |
| 3104 | break; |
| 3105 | default: |
| 3106 | break; |
| 3107 | } |
| 3108 | |
| 3109 | // Fourth input register |
| 3110 | switch (MCInst_getOpcode(Inst)) { |
| 3111 | case ARM_VST4d8: |
| 3112 | case ARM_VST4d16: |
| 3113 | case ARM_VST4d32: |
| 3114 | case ARM_VST4d8_UPD: |
| 3115 | case ARM_VST4d16_UPD: |
| 3116 | case ARM_VST4d32_UPD: |
| 3117 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 3) % 32, Address, Decoder))) |
| 3118 | return MCDisassembler_Fail; |
| 3119 | break; |
| 3120 | |
| 3121 | case ARM_VST4q8: |
| 3122 | case ARM_VST4q16: |
| 3123 | case ARM_VST4q32: |
| 3124 | case ARM_VST4q8_UPD: |
| 3125 | case ARM_VST4q16_UPD: |
| 3126 | case ARM_VST4q32_UPD: |
| 3127 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 6) % 32, Address, Decoder))) |
| 3128 | return MCDisassembler_Fail; |
| 3129 | break; |
| 3130 | default: |
| 3131 | break; |
| 3132 | } |
| 3133 | |
| 3134 | return S; |
| 3135 | } |
| 3136 | |
| 3137 | static DecodeStatus DecodeVLD1DupInstruction(MCInst *Inst, unsigned Insn, |
| 3138 | uint64_t Address, const void *Decoder) |
| 3139 | { |
| 3140 | DecodeStatus S = MCDisassembler_Success; |
| 3141 | unsigned Rn, Rm, align, size; |
| 3142 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3143 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3144 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3145 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 3146 | align = fieldFromInstruction_4(Insn, 4, 1); |
| 3147 | size = fieldFromInstruction_4(Insn, 6, 2); |
| 3148 | |
| 3149 | if (size == 0 && align == 1) |
| 3150 | return MCDisassembler_Fail; |
| 3151 | |
| 3152 | align *= (1 << size); |
| 3153 | |
| 3154 | switch (MCInst_getOpcode(Inst)) { |
| 3155 | case ARM_VLD1DUPq16: case ARM_VLD1DUPq32: case ARM_VLD1DUPq8: |
| 3156 | case ARM_VLD1DUPq16wb_fixed: case ARM_VLD1DUPq16wb_register: |
| 3157 | case ARM_VLD1DUPq32wb_fixed: case ARM_VLD1DUPq32wb_register: |
| 3158 | case ARM_VLD1DUPq8wb_fixed: case ARM_VLD1DUPq8wb_register: |
| 3159 | if (!Check(&S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder))) |
| 3160 | return MCDisassembler_Fail; |
| 3161 | break; |
| 3162 | |
| 3163 | default: |
| 3164 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3165 | return MCDisassembler_Fail; |
| 3166 | break; |
| 3167 | } |
| 3168 | |
| 3169 | if (Rm != 0xF) { |
| 3170 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3171 | return MCDisassembler_Fail; |
| 3172 | } |
| 3173 | |
| 3174 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3175 | return MCDisassembler_Fail; |
| 3176 | |
| 3177 | MCOperand_CreateImm0(Inst, align); |
| 3178 | |
| 3179 | // The fixed offset post-increment encodes Rm == 0xd. The no-writeback |
| 3180 | // variant encodes Rm == 0xf. Anything else is a register offset post- |
| 3181 | // increment and we need to add the register operand to the instruction. |
| 3182 | if (Rm != 0xD && Rm != 0xF && |
| 3183 | !Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3184 | return MCDisassembler_Fail; |
| 3185 | |
| 3186 | return S; |
| 3187 | } |
| 3188 | |
| 3189 | static DecodeStatus DecodeVLD2DupInstruction(MCInst *Inst, unsigned Insn, |
| 3190 | uint64_t Address, const void *Decoder) |
| 3191 | { |
| 3192 | DecodeStatus S = MCDisassembler_Success; |
| 3193 | unsigned Rn, Rm, align, size; |
| 3194 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3195 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3196 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3197 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 3198 | align = fieldFromInstruction_4(Insn, 4, 1); |
| 3199 | size = 1 << fieldFromInstruction_4(Insn, 6, 2); |
| 3200 | align *= 2 * size; |
| 3201 | |
| 3202 | switch (MCInst_getOpcode(Inst)) { |
| 3203 | case ARM_VLD2DUPd16: case ARM_VLD2DUPd32: case ARM_VLD2DUPd8: |
| 3204 | case ARM_VLD2DUPd16wb_fixed: case ARM_VLD2DUPd16wb_register: |
| 3205 | case ARM_VLD2DUPd32wb_fixed: case ARM_VLD2DUPd32wb_register: |
| 3206 | case ARM_VLD2DUPd8wb_fixed: case ARM_VLD2DUPd8wb_register: |
| 3207 | if (!Check(&S, DecodeDPairRegisterClass(Inst, Rd, Address, Decoder))) |
| 3208 | return MCDisassembler_Fail; |
| 3209 | break; |
| 3210 | |
| 3211 | case ARM_VLD2DUPd16x2: case ARM_VLD2DUPd32x2: case ARM_VLD2DUPd8x2: |
| 3212 | case ARM_VLD2DUPd16x2wb_fixed: case ARM_VLD2DUPd16x2wb_register: |
| 3213 | case ARM_VLD2DUPd32x2wb_fixed: case ARM_VLD2DUPd32x2wb_register: |
| 3214 | case ARM_VLD2DUPd8x2wb_fixed: case ARM_VLD2DUPd8x2wb_register: |
| 3215 | if (!Check(&S, DecodeDPairSpacedRegisterClass(Inst, Rd, Address, Decoder))) |
| 3216 | return MCDisassembler_Fail; |
| 3217 | break; |
| 3218 | |
| 3219 | default: |
| 3220 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3221 | return MCDisassembler_Fail; |
| 3222 | break; |
| 3223 | } |
| 3224 | |
| 3225 | if (Rm != 0xF) |
| 3226 | MCOperand_CreateImm0(Inst, 0); |
| 3227 | |
| 3228 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3229 | return MCDisassembler_Fail; |
| 3230 | |
| 3231 | MCOperand_CreateImm0(Inst, align); |
| 3232 | |
| 3233 | if (Rm != 0xD && Rm != 0xF) { |
| 3234 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3235 | return MCDisassembler_Fail; |
| 3236 | } |
| 3237 | |
| 3238 | return S; |
| 3239 | } |
| 3240 | |
| 3241 | static DecodeStatus DecodeVLD3DupInstruction(MCInst *Inst, unsigned Insn, |
| 3242 | uint64_t Address, const void *Decoder) |
| 3243 | { |
| 3244 | DecodeStatus S = MCDisassembler_Success; |
| 3245 | unsigned Rn, Rm, inc; |
| 3246 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3247 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3248 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3249 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 3250 | inc = fieldFromInstruction_4(Insn, 5, 1) + 1; |
| 3251 | |
| 3252 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3253 | return MCDisassembler_Fail; |
| 3254 | |
| 3255 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + inc) % 32, Address, Decoder))) |
| 3256 | return MCDisassembler_Fail; |
| 3257 | |
| 3258 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 2*inc) % 32, Address, Decoder))) |
| 3259 | return MCDisassembler_Fail; |
| 3260 | |
| 3261 | if (Rm != 0xF) { |
| 3262 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3263 | return MCDisassembler_Fail; |
| 3264 | } |
| 3265 | |
| 3266 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3267 | return MCDisassembler_Fail; |
| 3268 | |
| 3269 | MCOperand_CreateImm0(Inst, 0); |
| 3270 | |
| 3271 | if (Rm == 0xD) |
| 3272 | MCOperand_CreateReg0(Inst, 0); |
| 3273 | else if (Rm != 0xF) { |
| 3274 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3275 | return MCDisassembler_Fail; |
| 3276 | } |
| 3277 | |
| 3278 | return S; |
| 3279 | } |
| 3280 | |
| 3281 | static DecodeStatus DecodeVLD4DupInstruction(MCInst *Inst, unsigned Insn, |
| 3282 | uint64_t Address, const void *Decoder) |
| 3283 | { |
| 3284 | DecodeStatus S = MCDisassembler_Success; |
| 3285 | unsigned Rn, Rm, size, inc, align; |
| 3286 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3287 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3288 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3289 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 3290 | size = fieldFromInstruction_4(Insn, 6, 2); |
| 3291 | inc = fieldFromInstruction_4(Insn, 5, 1) + 1; |
| 3292 | align = fieldFromInstruction_4(Insn, 4, 1); |
| 3293 | |
| 3294 | if (size == 0x3) { |
| 3295 | if (align == 0) |
| 3296 | return MCDisassembler_Fail; |
| 3297 | align = 16; |
| 3298 | } else { |
| 3299 | if (size == 2) { |
| 3300 | align *= 8; |
| 3301 | } else { |
| 3302 | size = 1 << size; |
| 3303 | align *= 4 * size; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3308 | return MCDisassembler_Fail; |
| 3309 | |
| 3310 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + inc) % 32, Address, Decoder))) |
| 3311 | return MCDisassembler_Fail; |
| 3312 | |
| 3313 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 2*inc) % 32, Address, Decoder))) |
| 3314 | return MCDisassembler_Fail; |
| 3315 | |
| 3316 | if (!Check(&S, DecodeDPRRegisterClass(Inst, (Rd + 3*inc) % 32, Address, Decoder))) |
| 3317 | return MCDisassembler_Fail; |
| 3318 | |
| 3319 | if (Rm != 0xF) { |
| 3320 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3321 | return MCDisassembler_Fail; |
| 3322 | } |
| 3323 | |
| 3324 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3325 | return MCDisassembler_Fail; |
| 3326 | |
| 3327 | MCOperand_CreateImm0(Inst, align); |
| 3328 | |
| 3329 | if (Rm == 0xD) |
| 3330 | MCOperand_CreateReg0(Inst, 0); |
| 3331 | else if (Rm != 0xF) { |
| 3332 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3333 | return MCDisassembler_Fail; |
| 3334 | } |
| 3335 | |
| 3336 | return S; |
| 3337 | } |
| 3338 | |
| 3339 | static DecodeStatus DecodeNEONModImmInstruction(MCInst *Inst, unsigned Insn, |
| 3340 | uint64_t Address, const void *Decoder) |
| 3341 | { |
| 3342 | DecodeStatus S = MCDisassembler_Success; |
| 3343 | unsigned imm, Q; |
| 3344 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3345 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3346 | imm = fieldFromInstruction_4(Insn, 0, 4); |
| 3347 | imm |= fieldFromInstruction_4(Insn, 16, 3) << 4; |
| 3348 | imm |= fieldFromInstruction_4(Insn, 24, 1) << 7; |
| 3349 | imm |= fieldFromInstruction_4(Insn, 8, 4) << 8; |
| 3350 | imm |= fieldFromInstruction_4(Insn, 5, 1) << 12; |
| 3351 | Q = fieldFromInstruction_4(Insn, 6, 1); |
| 3352 | |
| 3353 | if (Q) { |
| 3354 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3355 | return MCDisassembler_Fail; |
| 3356 | } else { |
| 3357 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3358 | return MCDisassembler_Fail; |
| 3359 | } |
| 3360 | |
| 3361 | MCOperand_CreateImm0(Inst, imm); |
| 3362 | |
| 3363 | switch (MCInst_getOpcode(Inst)) { |
| 3364 | case ARM_VORRiv4i16: |
| 3365 | case ARM_VORRiv2i32: |
| 3366 | case ARM_VBICiv4i16: |
| 3367 | case ARM_VBICiv2i32: |
| 3368 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3369 | return MCDisassembler_Fail; |
| 3370 | break; |
| 3371 | case ARM_VORRiv8i16: |
| 3372 | case ARM_VORRiv4i32: |
| 3373 | case ARM_VBICiv8i16: |
| 3374 | case ARM_VBICiv4i32: |
| 3375 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3376 | return MCDisassembler_Fail; |
| 3377 | break; |
| 3378 | default: |
| 3379 | break; |
| 3380 | } |
| 3381 | |
| 3382 | return S; |
| 3383 | } |
| 3384 | |
| 3385 | static DecodeStatus DecodeVSHLMaxInstruction(MCInst *Inst, unsigned Insn, |
| 3386 | uint64_t Address, const void *Decoder) |
| 3387 | { |
| 3388 | DecodeStatus S = MCDisassembler_Success; |
| 3389 | unsigned Rm, size; |
| 3390 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3391 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3392 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 3393 | Rm |= fieldFromInstruction_4(Insn, 5, 1) << 4; |
| 3394 | size = fieldFromInstruction_4(Insn, 18, 2); |
| 3395 | |
| 3396 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3397 | return MCDisassembler_Fail; |
| 3398 | |
| 3399 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3400 | return MCDisassembler_Fail; |
| 3401 | |
| 3402 | MCOperand_CreateImm0(Inst, 8 << size); |
| 3403 | |
| 3404 | return S; |
| 3405 | } |
| 3406 | |
| 3407 | static DecodeStatus DecodeShiftRight8Imm(MCInst *Inst, unsigned Val, |
| 3408 | uint64_t Address, const void *Decoder) |
| 3409 | { |
| 3410 | MCOperand_CreateImm0(Inst, 8 - Val); |
| 3411 | |
| 3412 | return MCDisassembler_Success; |
| 3413 | } |
| 3414 | |
| 3415 | static DecodeStatus DecodeShiftRight16Imm(MCInst *Inst, unsigned Val, |
| 3416 | uint64_t Address, const void *Decoder) |
| 3417 | { |
| 3418 | MCOperand_CreateImm0(Inst, 16 - Val); |
| 3419 | |
| 3420 | return MCDisassembler_Success; |
| 3421 | } |
| 3422 | |
| 3423 | static DecodeStatus DecodeShiftRight32Imm(MCInst *Inst, unsigned Val, |
| 3424 | uint64_t Address, const void *Decoder) |
| 3425 | { |
| 3426 | MCOperand_CreateImm0(Inst, 32 - Val); |
| 3427 | |
| 3428 | return MCDisassembler_Success; |
| 3429 | } |
| 3430 | |
| 3431 | static DecodeStatus DecodeShiftRight64Imm(MCInst *Inst, unsigned Val, |
| 3432 | uint64_t Address, const void *Decoder) |
| 3433 | { |
| 3434 | MCOperand_CreateImm0(Inst, 64 - Val); |
| 3435 | |
| 3436 | return MCDisassembler_Success; |
| 3437 | } |
| 3438 | |
| 3439 | static DecodeStatus DecodeTBLInstruction(MCInst *Inst, unsigned Insn, |
| 3440 | uint64_t Address, const void *Decoder) |
| 3441 | { |
| 3442 | DecodeStatus S = MCDisassembler_Success; |
| 3443 | unsigned Rn, Rm, op; |
| 3444 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 3445 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 3446 | Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3447 | Rn |= fieldFromInstruction_4(Insn, 7, 1) << 4; |
| 3448 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 3449 | Rm |= fieldFromInstruction_4(Insn, 5, 1) << 4; |
| 3450 | op = fieldFromInstruction_4(Insn, 6, 1); |
| 3451 | |
| 3452 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3453 | return MCDisassembler_Fail; |
| 3454 | |
| 3455 | if (op) { |
| 3456 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 3457 | return MCDisassembler_Fail; // Writeback |
| 3458 | } |
| 3459 | |
| 3460 | switch (MCInst_getOpcode(Inst)) { |
| 3461 | case ARM_VTBL2: |
| 3462 | case ARM_VTBX2: |
| 3463 | if (!Check(&S, DecodeDPairRegisterClass(Inst, Rn, Address, Decoder))) |
| 3464 | return MCDisassembler_Fail; |
| 3465 | break; |
| 3466 | default: |
| 3467 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3468 | return MCDisassembler_Fail; |
| 3469 | } |
| 3470 | |
| 3471 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3472 | return MCDisassembler_Fail; |
| 3473 | |
| 3474 | return S; |
| 3475 | } |
| 3476 | |
| 3477 | static DecodeStatus DecodeThumbAddSpecialReg(MCInst *Inst, uint16_t Insn, |
| 3478 | uint64_t Address, const void *Decoder) |
| 3479 | { |
| 3480 | DecodeStatus S = MCDisassembler_Success; |
| 3481 | unsigned dst = fieldFromInstruction_2(Insn, 8, 3); |
| 3482 | unsigned imm = fieldFromInstruction_2(Insn, 0, 8); |
| 3483 | |
| 3484 | if (!Check(&S, DecodetGPRRegisterClass(Inst, dst, Address, Decoder))) |
| 3485 | return MCDisassembler_Fail; |
| 3486 | |
| 3487 | switch(MCInst_getOpcode(Inst)) { |
| 3488 | default: |
| 3489 | return MCDisassembler_Fail; |
| 3490 | case ARM_tADR: |
| 3491 | break; // tADR does not explicitly represent the PC as an operand. |
| 3492 | case ARM_tADDrSPi: |
| 3493 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 3494 | break; |
| 3495 | } |
| 3496 | |
| 3497 | MCOperand_CreateImm0(Inst, imm); |
| 3498 | |
| 3499 | return S; |
| 3500 | } |
| 3501 | |
| 3502 | static DecodeStatus DecodeThumbBROperand(MCInst *Inst, unsigned Val, |
| 3503 | uint64_t Address, const void *Decoder) |
| 3504 | { |
| 3505 | MCOperand_CreateImm0(Inst, SignExtend32(Val << 1, 12)); |
| 3506 | |
| 3507 | return MCDisassembler_Success; |
| 3508 | } |
| 3509 | |
| 3510 | static DecodeStatus DecodeT2BROperand(MCInst *Inst, unsigned Val, |
| 3511 | uint64_t Address, const void *Decoder) |
| 3512 | { |
| 3513 | MCOperand_CreateImm0(Inst, SignExtend32(Val, 21)); |
| 3514 | |
| 3515 | return MCDisassembler_Success; |
| 3516 | } |
| 3517 | |
| 3518 | static DecodeStatus DecodeThumbCmpBROperand(MCInst *Inst, unsigned Val, |
| 3519 | uint64_t Address, const void *Decoder) |
| 3520 | { |
| 3521 | MCOperand_CreateImm0(Inst, Val << 1); |
| 3522 | |
| 3523 | return MCDisassembler_Success; |
| 3524 | } |
| 3525 | |
| 3526 | static DecodeStatus DecodeThumbAddrModeRR(MCInst *Inst, unsigned Val, |
| 3527 | uint64_t Address, const void *Decoder) |
| 3528 | { |
| 3529 | DecodeStatus S = MCDisassembler_Success; |
| 3530 | unsigned Rn = fieldFromInstruction_4(Val, 0, 3); |
| 3531 | unsigned Rm = fieldFromInstruction_4(Val, 3, 3); |
| 3532 | |
| 3533 | if (!Check(&S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3534 | return MCDisassembler_Fail; |
| 3535 | |
| 3536 | if (!Check(&S, DecodetGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3537 | return MCDisassembler_Fail; |
| 3538 | |
| 3539 | return S; |
| 3540 | } |
| 3541 | |
| 3542 | static DecodeStatus DecodeThumbAddrModeIS(MCInst *Inst, unsigned Val, |
| 3543 | uint64_t Address, const void *Decoder) |
| 3544 | { |
| 3545 | DecodeStatus S = MCDisassembler_Success; |
| 3546 | unsigned Rn = fieldFromInstruction_4(Val, 0, 3); |
| 3547 | unsigned imm = fieldFromInstruction_4(Val, 3, 5); |
| 3548 | |
| 3549 | if (!Check(&S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3550 | return MCDisassembler_Fail; |
| 3551 | |
| 3552 | MCOperand_CreateImm0(Inst, imm); |
| 3553 | |
| 3554 | return S; |
| 3555 | } |
| 3556 | |
| 3557 | static DecodeStatus DecodeThumbAddrModePC(MCInst *Inst, unsigned Val, |
| 3558 | uint64_t Address, const void *Decoder) |
| 3559 | { |
| 3560 | unsigned imm = Val << 2; |
| 3561 | |
| 3562 | MCOperand_CreateImm0(Inst, imm); |
| 3563 | //tryAddingPcLoadReferenceComment(Address, (Address & ~2u) + imm + 4, Decoder); |
| 3564 | |
| 3565 | return MCDisassembler_Success; |
| 3566 | } |
| 3567 | |
| 3568 | static DecodeStatus DecodeThumbAddrModeSP(MCInst *Inst, unsigned Val, |
| 3569 | uint64_t Address, const void *Decoder) |
| 3570 | { |
| 3571 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 3572 | MCOperand_CreateImm0(Inst, Val); |
| 3573 | |
| 3574 | return MCDisassembler_Success; |
| 3575 | } |
| 3576 | |
| 3577 | static DecodeStatus DecodeT2AddrModeSOReg(MCInst *Inst, unsigned Val, |
| 3578 | uint64_t Address, const void *Decoder) |
| 3579 | { |
| 3580 | DecodeStatus S = MCDisassembler_Success; |
| 3581 | unsigned Rn = fieldFromInstruction_4(Val, 6, 4); |
| 3582 | unsigned Rm = fieldFromInstruction_4(Val, 2, 4); |
| 3583 | unsigned imm = fieldFromInstruction_4(Val, 0, 2); |
| 3584 | |
| 3585 | // Thumb stores cannot use PC as dest register. |
| 3586 | switch (MCInst_getOpcode(Inst)) { |
| 3587 | case ARM_t2STRHs: |
| 3588 | case ARM_t2STRBs: |
| 3589 | case ARM_t2STRs: |
| 3590 | if (Rn == 15) |
| 3591 | return MCDisassembler_Fail; |
| 3592 | default: |
| 3593 | break; |
| 3594 | } |
| 3595 | |
| 3596 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3597 | return MCDisassembler_Fail; |
| 3598 | |
| 3599 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 3600 | return MCDisassembler_Fail; |
| 3601 | |
| 3602 | MCOperand_CreateImm0(Inst, imm); |
| 3603 | |
| 3604 | return S; |
| 3605 | } |
| 3606 | |
| 3607 | static DecodeStatus DecodeT2LoadShift(MCInst *Inst, unsigned Insn, |
| 3608 | uint64_t Address, const void *Decoder) |
| 3609 | { |
| 3610 | DecodeStatus S = MCDisassembler_Success; |
| 3611 | unsigned addrmode; |
| 3612 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 3613 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3614 | bool hasMP = ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureMP); |
| 3615 | bool hasV7Ops = ARM_getFeatureBits(Inst->csh->mode, ARM_HasV7Ops); |
| 3616 | |
| 3617 | if (Rn == 15) { |
| 3618 | switch (MCInst_getOpcode(Inst)) { |
| 3619 | case ARM_t2LDRBs: |
| 3620 | MCInst_setOpcode(Inst, ARM_t2LDRBpci); |
| 3621 | break; |
| 3622 | case ARM_t2LDRHs: |
| 3623 | MCInst_setOpcode(Inst, ARM_t2LDRHpci); |
| 3624 | break; |
| 3625 | case ARM_t2LDRSHs: |
| 3626 | MCInst_setOpcode(Inst, ARM_t2LDRSHpci); |
| 3627 | break; |
| 3628 | case ARM_t2LDRSBs: |
| 3629 | MCInst_setOpcode(Inst, ARM_t2LDRSBpci); |
| 3630 | break; |
| 3631 | case ARM_t2LDRs: |
| 3632 | MCInst_setOpcode(Inst, ARM_t2LDRpci); |
| 3633 | break; |
| 3634 | case ARM_t2PLDs: |
| 3635 | MCInst_setOpcode(Inst, ARM_t2PLDpci); |
| 3636 | break; |
| 3637 | case ARM_t2PLIs: |
| 3638 | MCInst_setOpcode(Inst, ARM_t2PLIpci); |
| 3639 | break; |
| 3640 | default: |
| 3641 | return MCDisassembler_Fail; |
| 3642 | } |
| 3643 | |
| 3644 | return DecodeT2LoadLabel(Inst, Insn, Address, Decoder); |
| 3645 | } |
| 3646 | |
| 3647 | if (Rt == 15) { |
| 3648 | switch (MCInst_getOpcode(Inst)) { |
| 3649 | case ARM_t2LDRSHs: |
| 3650 | return MCDisassembler_Fail; |
| 3651 | case ARM_t2LDRHs: |
| 3652 | MCInst_setOpcode(Inst, ARM_t2PLDWs); |
| 3653 | break; |
| 3654 | case ARM_t2LDRSBs: |
| 3655 | MCInst_setOpcode(Inst, ARM_t2PLIs); |
| 3656 | default: |
| 3657 | break; |
| 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | switch (MCInst_getOpcode(Inst)) { |
| 3662 | case ARM_t2PLDs: |
| 3663 | break; |
| 3664 | case ARM_t2PLIs: |
| 3665 | if (!hasV7Ops) |
| 3666 | return MCDisassembler_Fail; |
| 3667 | break; |
| 3668 | case ARM_t2PLDWs: |
| 3669 | if (!hasV7Ops || !hasMP) |
| 3670 | return MCDisassembler_Fail; |
| 3671 | break; |
| 3672 | default: |
| 3673 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 3674 | return MCDisassembler_Fail; |
| 3675 | } |
| 3676 | |
| 3677 | addrmode = fieldFromInstruction_4(Insn, 4, 2); |
| 3678 | addrmode |= fieldFromInstruction_4(Insn, 0, 4) << 2; |
| 3679 | addrmode |= fieldFromInstruction_4(Insn, 16, 4) << 6; |
| 3680 | |
| 3681 | if (!Check(&S, DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder))) |
| 3682 | return MCDisassembler_Fail; |
| 3683 | |
| 3684 | return S; |
| 3685 | } |
| 3686 | |
| 3687 | static DecodeStatus DecodeT2LoadImm8(MCInst *Inst, unsigned Insn, |
| 3688 | uint64_t Address, const void* Decoder) |
| 3689 | { |
| 3690 | DecodeStatus S = MCDisassembler_Success; |
| 3691 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3692 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 3693 | unsigned U = fieldFromInstruction_4(Insn, 9, 1); |
| 3694 | unsigned imm = fieldFromInstruction_4(Insn, 0, 8); |
| 3695 | unsigned add = fieldFromInstruction_4(Insn, 9, 1); |
| 3696 | bool hasMP = ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureMP); |
| 3697 | bool hasV7Ops = ARM_getFeatureBits(Inst->csh->mode, ARM_HasV7Ops); |
| 3698 | |
| 3699 | imm |= (U << 8); |
| 3700 | imm |= (Rn << 9); |
| 3701 | |
| 3702 | if (Rn == 15) { |
| 3703 | switch (MCInst_getOpcode(Inst)) { |
| 3704 | case ARM_t2LDRi8: |
| 3705 | MCInst_setOpcode(Inst, ARM_t2LDRpci); |
| 3706 | break; |
| 3707 | case ARM_t2LDRBi8: |
| 3708 | MCInst_setOpcode(Inst, ARM_t2LDRBpci); |
| 3709 | break; |
| 3710 | case ARM_t2LDRSBi8: |
| 3711 | MCInst_setOpcode(Inst, ARM_t2LDRSBpci); |
| 3712 | break; |
| 3713 | case ARM_t2LDRHi8: |
| 3714 | MCInst_setOpcode(Inst, ARM_t2LDRHpci); |
| 3715 | break; |
| 3716 | case ARM_t2LDRSHi8: |
| 3717 | MCInst_setOpcode(Inst, ARM_t2LDRSHpci); |
| 3718 | break; |
| 3719 | case ARM_t2PLDi8: |
| 3720 | MCInst_setOpcode(Inst, ARM_t2PLDpci); |
| 3721 | break; |
| 3722 | case ARM_t2PLIi8: |
| 3723 | MCInst_setOpcode(Inst, ARM_t2PLIpci); |
| 3724 | break; |
| 3725 | default: |
| 3726 | return MCDisassembler_Fail; |
| 3727 | } |
| 3728 | |
| 3729 | return DecodeT2LoadLabel(Inst, Insn, Address, Decoder); |
| 3730 | } |
| 3731 | |
| 3732 | if (Rt == 15) { |
| 3733 | switch (MCInst_getOpcode(Inst)) { |
| 3734 | case ARM_t2LDRSHi8: |
| 3735 | return MCDisassembler_Fail; |
| 3736 | case ARM_t2LDRHi8: |
| 3737 | if (!add) |
| 3738 | MCInst_setOpcode(Inst, ARM_t2PLDWi8); |
| 3739 | break; |
| 3740 | case ARM_t2LDRSBi8: |
| 3741 | MCInst_setOpcode(Inst, ARM_t2PLIi8); |
| 3742 | break; |
| 3743 | default: |
| 3744 | break; |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | switch (MCInst_getOpcode(Inst)) { |
| 3749 | case ARM_t2PLDi8: |
| 3750 | break; |
| 3751 | case ARM_t2PLIi8: |
| 3752 | if (!hasV7Ops) |
| 3753 | return MCDisassembler_Fail; |
| 3754 | break; |
| 3755 | case ARM_t2PLDWi8: |
| 3756 | if (!hasV7Ops || !hasMP) |
| 3757 | return MCDisassembler_Fail; |
| 3758 | break; |
| 3759 | default: |
| 3760 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 3761 | return MCDisassembler_Fail; |
| 3762 | } |
| 3763 | |
| 3764 | if (!Check(&S, DecodeT2AddrModeImm8(Inst, imm, Address, Decoder))) |
| 3765 | return MCDisassembler_Fail; |
| 3766 | |
| 3767 | return S; |
| 3768 | } |
| 3769 | |
| 3770 | static DecodeStatus DecodeT2LoadImm12(MCInst *Inst, unsigned Insn, |
| 3771 | uint64_t Address, const void* Decoder) |
| 3772 | { |
| 3773 | DecodeStatus S = MCDisassembler_Success; |
| 3774 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3775 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 3776 | unsigned imm = fieldFromInstruction_4(Insn, 0, 12); |
| 3777 | bool hasMP = ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureMP); |
| 3778 | bool hasV7Ops = ARM_getFeatureBits(Inst->csh->mode, ARM_HasV7Ops); |
| 3779 | |
| 3780 | imm |= (Rn << 13); |
| 3781 | |
| 3782 | if (Rn == 15) { |
| 3783 | switch (MCInst_getOpcode(Inst)) { |
| 3784 | case ARM_t2LDRi12: |
| 3785 | MCInst_setOpcode(Inst, ARM_t2LDRpci); |
| 3786 | break; |
| 3787 | case ARM_t2LDRHi12: |
| 3788 | MCInst_setOpcode(Inst, ARM_t2LDRHpci); |
| 3789 | break; |
| 3790 | case ARM_t2LDRSHi12: |
| 3791 | MCInst_setOpcode(Inst, ARM_t2LDRSHpci); |
| 3792 | break; |
| 3793 | case ARM_t2LDRBi12: |
| 3794 | MCInst_setOpcode(Inst, ARM_t2LDRBpci); |
| 3795 | break; |
| 3796 | case ARM_t2LDRSBi12: |
| 3797 | MCInst_setOpcode(Inst, ARM_t2LDRSBpci); |
| 3798 | break; |
| 3799 | case ARM_t2PLDi12: |
| 3800 | MCInst_setOpcode(Inst, ARM_t2PLDpci); |
| 3801 | break; |
| 3802 | case ARM_t2PLIi12: |
| 3803 | MCInst_setOpcode(Inst, ARM_t2PLIpci); |
| 3804 | break; |
| 3805 | default: |
| 3806 | return MCDisassembler_Fail; |
| 3807 | } |
| 3808 | return DecodeT2LoadLabel(Inst, Insn, Address, Decoder); |
| 3809 | } |
| 3810 | |
| 3811 | if (Rt == 15) { |
| 3812 | switch (MCInst_getOpcode(Inst)) { |
| 3813 | case ARM_t2LDRSHi12: |
| 3814 | return MCDisassembler_Fail; |
| 3815 | case ARM_t2LDRHi12: |
| 3816 | MCInst_setOpcode(Inst, ARM_t2PLDWi12); |
| 3817 | break; |
| 3818 | case ARM_t2LDRSBi12: |
| 3819 | MCInst_setOpcode(Inst, ARM_t2PLIi12); |
| 3820 | break; |
| 3821 | default: |
| 3822 | break; |
| 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | switch (MCInst_getOpcode(Inst)) { |
| 3827 | case ARM_t2PLDi12: |
| 3828 | break; |
| 3829 | case ARM_t2PLIi12: |
| 3830 | if (!hasV7Ops) |
| 3831 | return MCDisassembler_Fail; |
| 3832 | break; |
| 3833 | case ARM_t2PLDWi12: |
| 3834 | if (!hasV7Ops || !hasMP) |
| 3835 | return MCDisassembler_Fail; |
| 3836 | break; |
| 3837 | default: |
| 3838 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 3839 | return MCDisassembler_Fail; |
| 3840 | } |
| 3841 | |
| 3842 | if (!Check(&S, DecodeT2AddrModeImm12(Inst, imm, Address, Decoder))) |
| 3843 | return MCDisassembler_Fail; |
| 3844 | |
| 3845 | return S; |
| 3846 | } |
| 3847 | |
| 3848 | static DecodeStatus DecodeT2LoadT(MCInst *Inst, unsigned Insn, |
| 3849 | uint64_t Address, const void* Decoder) |
| 3850 | { |
| 3851 | DecodeStatus S = MCDisassembler_Success; |
| 3852 | |
| 3853 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 3854 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 3855 | unsigned imm = fieldFromInstruction_4(Insn, 0, 8); |
| 3856 | imm |= (Rn << 9); |
| 3857 | |
| 3858 | if (Rn == 15) { |
| 3859 | switch (MCInst_getOpcode(Inst)) { |
| 3860 | case ARM_t2LDRT: |
| 3861 | MCInst_setOpcode(Inst, ARM_t2LDRpci); |
| 3862 | break; |
| 3863 | case ARM_t2LDRBT: |
| 3864 | MCInst_setOpcode(Inst, ARM_t2LDRBpci); |
| 3865 | break; |
| 3866 | case ARM_t2LDRHT: |
| 3867 | MCInst_setOpcode(Inst, ARM_t2LDRHpci); |
| 3868 | break; |
| 3869 | case ARM_t2LDRSBT: |
| 3870 | MCInst_setOpcode(Inst, ARM_t2LDRSBpci); |
| 3871 | break; |
| 3872 | case ARM_t2LDRSHT: |
| 3873 | MCInst_setOpcode(Inst, ARM_t2LDRSHpci); |
| 3874 | break; |
| 3875 | default: |
| 3876 | return MCDisassembler_Fail; |
| 3877 | } |
| 3878 | |
| 3879 | return DecodeT2LoadLabel(Inst, Insn, Address, Decoder); |
| 3880 | } |
| 3881 | |
| 3882 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 3883 | return MCDisassembler_Fail; |
| 3884 | |
| 3885 | if (!Check(&S, DecodeT2AddrModeImm8(Inst, imm, Address, Decoder))) |
| 3886 | return MCDisassembler_Fail; |
| 3887 | |
| 3888 | return S; |
| 3889 | } |
| 3890 | |
| 3891 | static DecodeStatus DecodeT2LoadLabel(MCInst *Inst, unsigned Insn, |
| 3892 | uint64_t Address, const void* Decoder) |
| 3893 | { |
| 3894 | DecodeStatus S = MCDisassembler_Success; |
| 3895 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 3896 | unsigned U = fieldFromInstruction_4(Insn, 23, 1); |
| 3897 | int imm = fieldFromInstruction_4(Insn, 0, 12); |
| 3898 | bool hasV7Ops = ARM_getFeatureBits(Inst->csh->mode, ARM_HasV7Ops); |
| 3899 | |
| 3900 | if (Rt == 15) { |
| 3901 | switch (MCInst_getOpcode(Inst)) { |
| 3902 | case ARM_t2LDRBpci: |
| 3903 | case ARM_t2LDRHpci: |
| 3904 | MCInst_setOpcode(Inst, ARM_t2PLDpci); |
| 3905 | break; |
| 3906 | case ARM_t2LDRSBpci: |
| 3907 | MCInst_setOpcode(Inst, ARM_t2PLIpci); |
| 3908 | break; |
| 3909 | case ARM_t2LDRSHpci: |
| 3910 | return MCDisassembler_Fail; |
| 3911 | default: |
| 3912 | break; |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | switch(MCInst_getOpcode(Inst)) { |
| 3917 | case ARM_t2PLDpci: |
| 3918 | break; |
| 3919 | case ARM_t2PLIpci: |
| 3920 | if (!hasV7Ops) |
| 3921 | return MCDisassembler_Fail; |
| 3922 | break; |
| 3923 | default: |
| 3924 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 3925 | return MCDisassembler_Fail; |
| 3926 | } |
| 3927 | |
| 3928 | if (!U) { |
| 3929 | // Special case for #-0. |
| 3930 | if (imm == 0) |
| 3931 | imm = INT32_MIN; |
| 3932 | else |
| 3933 | imm = -imm; |
| 3934 | } |
| 3935 | |
| 3936 | MCOperand_CreateImm0(Inst, imm); |
| 3937 | |
| 3938 | return S; |
| 3939 | } |
| 3940 | |
| 3941 | static DecodeStatus DecodeT2Imm8S4(MCInst *Inst, unsigned Val, |
| 3942 | uint64_t Address, const void *Decoder) |
| 3943 | { |
| 3944 | if (Val == 0) |
| 3945 | MCOperand_CreateImm0(Inst, INT32_MIN); |
| 3946 | else { |
| 3947 | int imm = Val & 0xFF; |
| 3948 | |
| 3949 | if (!(Val & 0x100)) imm *= -1; |
| 3950 | |
| 3951 | MCOperand_CreateImm0(Inst, imm * 4); |
| 3952 | } |
| 3953 | |
| 3954 | return MCDisassembler_Success; |
| 3955 | } |
| 3956 | |
| 3957 | static DecodeStatus DecodeT2AddrModeImm8s4(MCInst *Inst, unsigned Val, |
| 3958 | uint64_t Address, const void *Decoder) |
| 3959 | { |
| 3960 | DecodeStatus S = MCDisassembler_Success; |
| 3961 | unsigned Rn = fieldFromInstruction_4(Val, 9, 4); |
| 3962 | unsigned imm = fieldFromInstruction_4(Val, 0, 9); |
| 3963 | |
| 3964 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 3965 | return MCDisassembler_Fail; |
| 3966 | |
| 3967 | if (!Check(&S, DecodeT2Imm8S4(Inst, imm, Address, Decoder))) |
| 3968 | return MCDisassembler_Fail; |
| 3969 | |
| 3970 | return S; |
| 3971 | } |
| 3972 | |
| 3973 | static DecodeStatus DecodeT2AddrModeImm0_1020s4(MCInst *Inst,unsigned Val, |
| 3974 | uint64_t Address, const void *Decoder) |
| 3975 | { |
| 3976 | DecodeStatus S = MCDisassembler_Success; |
| 3977 | unsigned Rn = fieldFromInstruction_4(Val, 8, 4); |
| 3978 | unsigned imm = fieldFromInstruction_4(Val, 0, 8); |
| 3979 | |
| 3980 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder))) |
| 3981 | return MCDisassembler_Fail; |
| 3982 | |
| 3983 | MCOperand_CreateImm0(Inst, imm); |
| 3984 | |
| 3985 | return S; |
| 3986 | } |
| 3987 | |
| 3988 | static DecodeStatus DecodeT2Imm8(MCInst *Inst, unsigned Val, |
| 3989 | uint64_t Address, const void *Decoder) |
| 3990 | { |
| 3991 | int imm = Val & 0xFF; |
| 3992 | |
| 3993 | if (Val == 0) |
| 3994 | imm = INT32_MIN; |
| 3995 | else if (!(Val & 0x100)) |
| 3996 | imm *= -1; |
| 3997 | |
| 3998 | MCOperand_CreateImm0(Inst, imm); |
| 3999 | |
| 4000 | return MCDisassembler_Success; |
| 4001 | } |
| 4002 | |
| 4003 | static DecodeStatus DecodeT2AddrModeImm8(MCInst *Inst, unsigned Val, |
| 4004 | uint64_t Address, const void *Decoder) |
| 4005 | { |
| 4006 | DecodeStatus S = MCDisassembler_Success; |
| 4007 | |
| 4008 | unsigned Rn = fieldFromInstruction_4(Val, 9, 4); |
| 4009 | unsigned imm = fieldFromInstruction_4(Val, 0, 9); |
| 4010 | |
| 4011 | // Thumb stores cannot use PC as dest register. |
| 4012 | switch (MCInst_getOpcode(Inst)) { |
| 4013 | case ARM_t2STRT: |
| 4014 | case ARM_t2STRBT: |
| 4015 | case ARM_t2STRHT: |
| 4016 | case ARM_t2STRi8: |
| 4017 | case ARM_t2STRHi8: |
| 4018 | case ARM_t2STRBi8: |
| 4019 | if (Rn == 15) |
| 4020 | return MCDisassembler_Fail; |
| 4021 | break; |
| 4022 | default: |
| 4023 | break; |
| 4024 | } |
| 4025 | |
| 4026 | // Some instructions always use an additive offset. |
| 4027 | switch (MCInst_getOpcode(Inst)) { |
| 4028 | case ARM_t2LDRT: |
| 4029 | case ARM_t2LDRBT: |
| 4030 | case ARM_t2LDRHT: |
| 4031 | case ARM_t2LDRSBT: |
| 4032 | case ARM_t2LDRSHT: |
| 4033 | case ARM_t2STRT: |
| 4034 | case ARM_t2STRBT: |
| 4035 | case ARM_t2STRHT: |
| 4036 | imm |= 0x100; |
| 4037 | break; |
| 4038 | default: |
| 4039 | break; |
| 4040 | } |
| 4041 | |
| 4042 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4043 | return MCDisassembler_Fail; |
| 4044 | |
| 4045 | if (!Check(&S, DecodeT2Imm8(Inst, imm, Address, Decoder))) |
| 4046 | return MCDisassembler_Fail; |
| 4047 | |
| 4048 | return S; |
| 4049 | } |
| 4050 | |
| 4051 | static DecodeStatus DecodeT2LdStPre(MCInst *Inst, unsigned Insn, |
| 4052 | uint64_t Address, const void *Decoder) |
| 4053 | { |
| 4054 | DecodeStatus S = MCDisassembler_Success; |
| 4055 | unsigned load; |
| 4056 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 4057 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4058 | unsigned addr = fieldFromInstruction_4(Insn, 0, 8); |
| 4059 | addr |= fieldFromInstruction_4(Insn, 9, 1) << 8; |
| 4060 | addr |= Rn << 9; |
| 4061 | load = fieldFromInstruction_4(Insn, 20, 1); |
| 4062 | |
| 4063 | if (Rn == 15) { |
| 4064 | switch (MCInst_getOpcode(Inst)) { |
| 4065 | case ARM_t2LDR_PRE: |
| 4066 | case ARM_t2LDR_POST: |
| 4067 | MCInst_setOpcode(Inst, ARM_t2LDRpci); |
| 4068 | break; |
| 4069 | case ARM_t2LDRB_PRE: |
| 4070 | case ARM_t2LDRB_POST: |
| 4071 | MCInst_setOpcode(Inst, ARM_t2LDRBpci); |
| 4072 | break; |
| 4073 | case ARM_t2LDRH_PRE: |
| 4074 | case ARM_t2LDRH_POST: |
| 4075 | MCInst_setOpcode(Inst, ARM_t2LDRHpci); |
| 4076 | break; |
| 4077 | case ARM_t2LDRSB_PRE: |
| 4078 | case ARM_t2LDRSB_POST: |
| 4079 | if (Rt == 15) |
| 4080 | MCInst_setOpcode(Inst, ARM_t2PLIpci); |
| 4081 | else |
| 4082 | MCInst_setOpcode(Inst, ARM_t2LDRSBpci); |
| 4083 | break; |
| 4084 | case ARM_t2LDRSH_PRE: |
| 4085 | case ARM_t2LDRSH_POST: |
| 4086 | MCInst_setOpcode(Inst, ARM_t2LDRSHpci); |
| 4087 | break; |
| 4088 | default: |
| 4089 | return MCDisassembler_Fail; |
| 4090 | } |
| 4091 | |
| 4092 | return DecodeT2LoadLabel(Inst, Insn, Address, Decoder); |
| 4093 | } |
| 4094 | |
| 4095 | if (!load) { |
| 4096 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4097 | return MCDisassembler_Fail; |
| 4098 | } |
| 4099 | |
| 4100 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 4101 | return MCDisassembler_Fail; |
| 4102 | |
| 4103 | if (load) { |
| 4104 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4105 | return MCDisassembler_Fail; |
| 4106 | } |
| 4107 | |
| 4108 | if (!Check(&S, DecodeT2AddrModeImm8(Inst, addr, Address, Decoder))) |
| 4109 | return MCDisassembler_Fail; |
| 4110 | |
| 4111 | return S; |
| 4112 | } |
| 4113 | |
| 4114 | static DecodeStatus DecodeT2AddrModeImm12(MCInst *Inst, unsigned Val, |
| 4115 | uint64_t Address, const void *Decoder) |
| 4116 | { |
| 4117 | DecodeStatus S = MCDisassembler_Success; |
| 4118 | unsigned Rn = fieldFromInstruction_4(Val, 13, 4); |
| 4119 | unsigned imm = fieldFromInstruction_4(Val, 0, 12); |
| 4120 | |
| 4121 | // Thumb stores cannot use PC as dest register. |
| 4122 | switch (MCInst_getOpcode(Inst)) { |
| 4123 | case ARM_t2STRi12: |
| 4124 | case ARM_t2STRBi12: |
| 4125 | case ARM_t2STRHi12: |
| 4126 | if (Rn == 15) |
| 4127 | return MCDisassembler_Fail; |
| 4128 | default: |
| 4129 | break; |
| 4130 | } |
| 4131 | |
| 4132 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4133 | return MCDisassembler_Fail; |
| 4134 | |
| 4135 | MCOperand_CreateImm0(Inst, imm); |
| 4136 | |
| 4137 | return S; |
| 4138 | } |
| 4139 | |
| 4140 | static DecodeStatus DecodeThumbAddSPImm(MCInst *Inst, uint16_t Insn, |
| 4141 | uint64_t Address, const void *Decoder) |
| 4142 | { |
| 4143 | unsigned imm = fieldFromInstruction_2(Insn, 0, 7); |
| 4144 | |
| 4145 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 4146 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 4147 | MCOperand_CreateImm0(Inst, imm); |
| 4148 | |
| 4149 | return MCDisassembler_Success; |
| 4150 | } |
| 4151 | |
| 4152 | static DecodeStatus DecodeThumbAddSPReg(MCInst *Inst, uint16_t Insn, |
| 4153 | uint64_t Address, const void *Decoder) |
| 4154 | { |
| 4155 | DecodeStatus S = MCDisassembler_Success; |
| 4156 | |
| 4157 | if (MCInst_getOpcode(Inst) == ARM_tADDrSP) { |
| 4158 | unsigned Rdm = fieldFromInstruction_2(Insn, 0, 3); |
| 4159 | Rdm |= fieldFromInstruction_2(Insn, 7, 1) << 3; |
| 4160 | |
| 4161 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder))) |
| 4162 | return MCDisassembler_Fail; |
| 4163 | |
| 4164 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 4165 | |
| 4166 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder))) |
| 4167 | return MCDisassembler_Fail; |
| 4168 | } else if (MCInst_getOpcode(Inst) == ARM_tADDspr) { |
| 4169 | unsigned Rm = fieldFromInstruction_2(Insn, 3, 4); |
| 4170 | |
| 4171 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 4172 | MCOperand_CreateReg0(Inst, ARM_SP); |
| 4173 | |
| 4174 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4175 | return MCDisassembler_Fail; |
| 4176 | } |
| 4177 | |
| 4178 | return S; |
| 4179 | } |
| 4180 | |
| 4181 | static DecodeStatus DecodeThumbCPS(MCInst *Inst, uint16_t Insn, |
| 4182 | uint64_t Address, const void *Decoder) |
| 4183 | { |
| 4184 | unsigned imod = fieldFromInstruction_2(Insn, 4, 1) | 0x2; |
| 4185 | unsigned flags = fieldFromInstruction_2(Insn, 0, 3); |
| 4186 | |
| 4187 | MCOperand_CreateImm0(Inst, imod); |
| 4188 | MCOperand_CreateImm0(Inst, flags); |
| 4189 | |
| 4190 | return MCDisassembler_Success; |
| 4191 | } |
| 4192 | |
| 4193 | static DecodeStatus DecodePostIdxReg(MCInst *Inst, unsigned Insn, |
| 4194 | uint64_t Address, const void *Decoder) |
| 4195 | { |
| 4196 | DecodeStatus S = MCDisassembler_Success; |
| 4197 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4198 | unsigned add = fieldFromInstruction_4(Insn, 4, 1); |
| 4199 | |
| 4200 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder))) |
| 4201 | return MCDisassembler_Fail; |
| 4202 | |
| 4203 | MCOperand_CreateImm0(Inst, add); |
| 4204 | |
| 4205 | return S; |
| 4206 | } |
| 4207 | |
| 4208 | static DecodeStatus DecodeThumbBLXOffset(MCInst *Inst, unsigned Val, |
| 4209 | uint64_t Address, const void *Decoder) |
| 4210 | { |
| 4211 | // Val is passed in as S:J1:J2:imm10H:imm10L:'0' |
| 4212 | // Note only one trailing zero not two. Also the J1 and J2 values are from |
| 4213 | // the encoded instruction. So here change to I1 and I2 values via: |
| 4214 | // I1 = NOT(J1 EOR S); |
| 4215 | // I2 = NOT(J2 EOR S); |
| 4216 | // and build the imm32 with two trailing zeros as documented: |
| 4217 | // imm32 = SignExtend(S:I1:I2:imm10H:imm10L:'00', 32); |
| 4218 | unsigned S = (Val >> 23) & 1; |
| 4219 | unsigned J1 = (Val >> 22) & 1; |
| 4220 | unsigned J2 = (Val >> 21) & 1; |
| 4221 | unsigned I1 = !(J1 ^ S); |
| 4222 | unsigned I2 = !(J2 ^ S); |
| 4223 | unsigned tmp = (Val & ~0x600000) | (I1 << 22) | (I2 << 21); |
| 4224 | int imm32 = SignExtend32(tmp << 1, 25); |
| 4225 | |
| 4226 | MCOperand_CreateImm0(Inst, imm32); |
| 4227 | |
| 4228 | return MCDisassembler_Success; |
| 4229 | } |
| 4230 | |
| 4231 | static DecodeStatus DecodeCoprocessor(MCInst *Inst, unsigned Val, |
| 4232 | uint64_t Address, const void *Decoder) |
| 4233 | { |
| 4234 | if (Val == 0xA || Val == 0xB) |
| 4235 | return MCDisassembler_Fail; |
| 4236 | |
| 4237 | if (ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8Ops) && !(Val == 14 || Val == 15)) |
| 4238 | return MCDisassembler_Fail; |
| 4239 | |
| 4240 | MCOperand_CreateImm0(Inst, Val); |
| 4241 | |
| 4242 | return MCDisassembler_Success; |
| 4243 | } |
| 4244 | |
| 4245 | static DecodeStatus DecodeThumbTableBranch(MCInst *Inst, unsigned Insn, |
| 4246 | uint64_t Address, const void *Decoder) |
| 4247 | { |
| 4248 | DecodeStatus S = MCDisassembler_Success; |
| 4249 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4250 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4251 | |
| 4252 | if (Rn == ARM_SP) S = MCDisassembler_SoftFail; |
| 4253 | |
| 4254 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4255 | return MCDisassembler_Fail; |
| 4256 | |
| 4257 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4258 | return MCDisassembler_Fail; |
| 4259 | |
| 4260 | return S; |
| 4261 | } |
| 4262 | |
| 4263 | static DecodeStatus DecodeThumb2BCCInstruction(MCInst *Inst, unsigned Insn, |
| 4264 | uint64_t Address, const void *Decoder) |
| 4265 | { |
| 4266 | DecodeStatus S = MCDisassembler_Success; |
| 4267 | unsigned brtarget; |
| 4268 | unsigned pred = fieldFromInstruction_4(Insn, 22, 4); |
| 4269 | |
| 4270 | if (pred == 0xE || pred == 0xF) { |
| 4271 | unsigned imm; |
| 4272 | unsigned opc = fieldFromInstruction_4(Insn, 4, 28); |
| 4273 | switch (opc) { |
| 4274 | default: |
| 4275 | return MCDisassembler_Fail; |
| 4276 | case 0xf3bf8f4: |
| 4277 | MCInst_setOpcode(Inst, ARM_t2DSB); |
| 4278 | break; |
| 4279 | case 0xf3bf8f5: |
| 4280 | MCInst_setOpcode(Inst, ARM_t2DMB); |
| 4281 | break; |
| 4282 | case 0xf3bf8f6: |
| 4283 | MCInst_setOpcode(Inst, ARM_t2ISB); |
| 4284 | break; |
| 4285 | } |
| 4286 | |
| 4287 | imm = fieldFromInstruction_4(Insn, 0, 4); |
| 4288 | return DecodeMemBarrierOption(Inst, imm, Address, Decoder); |
| 4289 | } |
| 4290 | |
| 4291 | brtarget = fieldFromInstruction_4(Insn, 0, 11) << 1; |
| 4292 | brtarget |= fieldFromInstruction_4(Insn, 11, 1) << 19; |
| 4293 | brtarget |= fieldFromInstruction_4(Insn, 13, 1) << 18; |
| 4294 | brtarget |= fieldFromInstruction_4(Insn, 16, 6) << 12; |
| 4295 | brtarget |= fieldFromInstruction_4(Insn, 26, 1) << 20; |
| 4296 | |
| 4297 | if (!Check(&S, DecodeT2BROperand(Inst, brtarget, Address, Decoder))) |
| 4298 | return MCDisassembler_Fail; |
| 4299 | |
| 4300 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4301 | return MCDisassembler_Fail; |
| 4302 | |
| 4303 | return S; |
| 4304 | } |
| 4305 | |
| 4306 | // Decode a shifted immediate operand. These basically consist |
| 4307 | // of an 8-bit value, and a 4-bit directive that specifies either |
| 4308 | // a splat operation or a rotation. |
| 4309 | static DecodeStatus DecodeT2SOImm(MCInst *Inst, unsigned Val, |
| 4310 | uint64_t Address, const void *Decoder) |
| 4311 | { |
| 4312 | unsigned ctrl = fieldFromInstruction_4(Val, 10, 2); |
| 4313 | |
| 4314 | if (ctrl == 0) { |
| 4315 | unsigned byte = fieldFromInstruction_4(Val, 8, 2); |
| 4316 | unsigned imm = fieldFromInstruction_4(Val, 0, 8); |
| 4317 | |
| 4318 | switch (byte) { |
| 4319 | case 0: |
| 4320 | MCOperand_CreateImm0(Inst, imm); |
| 4321 | break; |
| 4322 | case 1: |
| 4323 | MCOperand_CreateImm0(Inst, (imm << 16) | imm); |
| 4324 | break; |
| 4325 | case 2: |
| 4326 | MCOperand_CreateImm0(Inst, (imm << 24) | (imm << 8)); |
| 4327 | break; |
| 4328 | case 3: |
| 4329 | MCOperand_CreateImm0(Inst, (imm << 24) | (imm << 16) | (imm << 8) | imm); |
| 4330 | break; |
| 4331 | } |
| 4332 | } else { |
| 4333 | unsigned unrot = fieldFromInstruction_4(Val, 0, 7) | 0x80; |
| 4334 | unsigned rot = fieldFromInstruction_4(Val, 7, 5); |
| 4335 | unsigned imm = (unrot >> rot) | (unrot << ((32 - rot) & 31)); |
| 4336 | |
| 4337 | MCOperand_CreateImm0(Inst, imm); |
| 4338 | } |
| 4339 | |
| 4340 | return MCDisassembler_Success; |
| 4341 | } |
| 4342 | |
| 4343 | static DecodeStatus DecodeThumbBCCTargetOperand(MCInst *Inst, unsigned Val, |
| 4344 | uint64_t Address, const void *Decoder) |
| 4345 | { |
| 4346 | MCOperand_CreateImm0(Inst, SignExtend32(Val << 1, 9)); |
| 4347 | |
| 4348 | return MCDisassembler_Success; |
| 4349 | } |
| 4350 | |
| 4351 | static DecodeStatus DecodeThumbBLTargetOperand(MCInst *Inst, unsigned Val, |
| 4352 | uint64_t Address, const void *Decoder) |
| 4353 | { |
| 4354 | // Val is passed in as S:J1:J2:imm10:imm11 |
| 4355 | // Note no trailing zero after imm11. Also the J1 and J2 values are from |
| 4356 | // the encoded instruction. So here change to I1 and I2 values via: |
| 4357 | // I1 = NOT(J1 EOR S); |
| 4358 | // I2 = NOT(J2 EOR S); |
| 4359 | // and build the imm32 with one trailing zero as documented: |
| 4360 | // imm32 = SignExtend(S:I1:I2:imm10:imm11:'0', 32); |
| 4361 | unsigned S = (Val >> 23) & 1; |
| 4362 | unsigned J1 = (Val >> 22) & 1; |
| 4363 | unsigned J2 = (Val >> 21) & 1; |
| 4364 | unsigned I1 = !(J1 ^ S); |
| 4365 | unsigned I2 = !(J2 ^ S); |
| 4366 | unsigned tmp = (Val & ~0x600000) | (I1 << 22) | (I2 << 21); |
| 4367 | int imm32 = SignExtend32(tmp << 1, 25); |
| 4368 | |
| 4369 | MCOperand_CreateImm0(Inst, imm32); |
| 4370 | |
| 4371 | return MCDisassembler_Success; |
| 4372 | } |
| 4373 | |
| 4374 | static DecodeStatus DecodeMemBarrierOption(MCInst *Inst, unsigned Val, |
| 4375 | uint64_t Address, const void *Decoder) |
| 4376 | { |
| 4377 | if (Val & ~0xf) |
| 4378 | return MCDisassembler_Fail; |
| 4379 | |
| 4380 | MCOperand_CreateImm0(Inst, Val); |
| 4381 | |
| 4382 | return MCDisassembler_Success; |
| 4383 | } |
| 4384 | |
| 4385 | static DecodeStatus DecodeInstSyncBarrierOption(MCInst *Inst, unsigned Val, |
| 4386 | uint64_t Address, const void *Decoder) |
| 4387 | { |
| 4388 | if (Val & ~0xf) |
| 4389 | return MCDisassembler_Fail; |
| 4390 | |
| 4391 | MCOperand_CreateImm0(Inst, Val); |
| 4392 | |
| 4393 | return MCDisassembler_Success; |
| 4394 | } |
| 4395 | |
| 4396 | static DecodeStatus DecodeMSRMask(MCInst *Inst, unsigned Val, |
| 4397 | uint64_t Address, const void *Decoder) |
| 4398 | { |
| 4399 | DecodeStatus S = MCDisassembler_Success; |
| 4400 | |
| 4401 | if (ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureMClass)) { |
| 4402 | unsigned ValLow = Val & 0xff; |
| 4403 | |
| 4404 | // Validate the SYSm value first. |
| 4405 | switch (ValLow) { |
| 4406 | case 0: // apsr |
| 4407 | case 1: // iapsr |
| 4408 | case 2: // eapsr |
| 4409 | case 3: // xpsr |
| 4410 | case 5: // ipsr |
| 4411 | case 6: // epsr |
| 4412 | case 7: // iepsr |
| 4413 | case 8: // msp |
| 4414 | case 9: // psp |
| 4415 | case 16: // primask |
| 4416 | case 20: // control |
| 4417 | break; |
| 4418 | case 17: // basepri |
| 4419 | case 18: // basepri_max |
| 4420 | case 19: // faultmask |
| 4421 | if (!ARM_getFeatureBits(Inst->csh->mode, ARM_HasV7Ops)) |
| 4422 | // Values basepri, basepri_max and faultmask are only valid for v7m. |
| 4423 | return MCDisassembler_Fail; |
| 4424 | break; |
| 4425 | case 0x8a: // msplim_ns |
| 4426 | case 0x8b: // psplim_ns |
| 4427 | case 0x91: // basepri_ns |
| 4428 | case 0x93: // faultmask_ns |
| 4429 | if (!ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8MMainlineOps)) |
| 4430 | return MCDisassembler_Fail; |
| 4431 | // LLVM_FALLTHROUGH; |
| 4432 | case 10: // msplim |
| 4433 | case 11: // psplim |
| 4434 | case 0x88: // msp_ns |
| 4435 | case 0x89: // psp_ns |
| 4436 | case 0x90: // primask_ns |
| 4437 | case 0x94: // control_ns |
| 4438 | case 0x98: // sp_ns |
| 4439 | if (!ARM_getFeatureBits(Inst->csh->mode, ARM_Feature8MSecExt)) |
| 4440 | return MCDisassembler_Fail; |
| 4441 | break; |
| 4442 | default: |
| 4443 | return MCDisassembler_SoftFail; |
| 4444 | } |
| 4445 | |
| 4446 | if (MCInst_getOpcode(Inst) == ARM_t2MSR_M) { |
| 4447 | unsigned Mask = fieldFromInstruction_4(Val, 10, 2); |
| 4448 | if (!ARM_getFeatureBits(Inst->csh->mode, ARM_HasV7Ops)) { |
| 4449 | // The ARMv6-M MSR bits {11-10} can be only 0b10, other values are |
| 4450 | // unpredictable. |
| 4451 | if (Mask != 2) |
| 4452 | S = MCDisassembler_SoftFail; |
| 4453 | } else { |
| 4454 | // The ARMv7-M architecture stores an additional 2-bit mask value in |
| 4455 | // MSR bits {11-10}. The mask is used only with apsr, iapsr, eapsr and |
| 4456 | // xpsr, it has to be 0b10 in other cases. Bit mask{1} indicates if |
| 4457 | // the NZCVQ bits should be moved by the instruction. Bit mask{0} |
| 4458 | // indicates the move for the GE{3:0} bits, the mask{0} bit can be set |
| 4459 | // only if the processor includes the DSP extension. |
| 4460 | if (Mask == 0 || (Mask != 2 && ValLow > 3) || |
| 4461 | (!ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureDSP) && (Mask & 1))) |
| 4462 | S = MCDisassembler_SoftFail; |
| 4463 | } |
| 4464 | } |
| 4465 | } else { |
| 4466 | // A/R class |
| 4467 | if (Val == 0) |
| 4468 | return MCDisassembler_Fail; |
| 4469 | } |
| 4470 | |
| 4471 | MCOperand_CreateImm0(Inst, Val); |
| 4472 | return S; |
| 4473 | } |
| 4474 | |
| 4475 | static DecodeStatus DecodeBankedReg(MCInst *Inst, unsigned Val, |
| 4476 | uint64_t Address, const void *Decoder) |
| 4477 | { |
| 4478 | unsigned R = fieldFromInstruction_4(Val, 5, 1); |
| 4479 | unsigned SysM = fieldFromInstruction_4(Val, 0, 5); |
| 4480 | |
| 4481 | // The table of encodings for these banked registers comes from B9.2.3 of the |
| 4482 | // ARM ARM. There are patterns, but nothing regular enough to make this logic |
| 4483 | // neater. So by fiat, these values are UNPREDICTABLE: |
| 4484 | if (!lookupBankedRegByEncoding((R << 5) | SysM)) |
| 4485 | return MCDisassembler_Fail; |
| 4486 | |
| 4487 | MCOperand_CreateImm0(Inst, Val); |
| 4488 | |
| 4489 | return MCDisassembler_Success; |
| 4490 | } |
| 4491 | |
| 4492 | static DecodeStatus DecodeDoubleRegLoad(MCInst *Inst, unsigned Insn, |
| 4493 | uint64_t Address, const void *Decoder) |
| 4494 | { |
| 4495 | DecodeStatus S = MCDisassembler_Success; |
| 4496 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 4497 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4498 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 4499 | |
| 4500 | if (Rn == 0xF) |
| 4501 | S = MCDisassembler_SoftFail; |
| 4502 | |
| 4503 | if (!Check(&S, DecodeGPRPairRegisterClass(Inst, Rt, Address, Decoder))) |
| 4504 | return MCDisassembler_Fail; |
| 4505 | |
| 4506 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4507 | return MCDisassembler_Fail; |
| 4508 | |
| 4509 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4510 | return MCDisassembler_Fail; |
| 4511 | |
| 4512 | return S; |
| 4513 | } |
| 4514 | |
| 4515 | static DecodeStatus DecodeDoubleRegStore(MCInst *Inst, unsigned Insn, |
| 4516 | uint64_t Address, const void *Decoder) |
| 4517 | { |
| 4518 | DecodeStatus S = MCDisassembler_Success; |
| 4519 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 4520 | unsigned Rt = fieldFromInstruction_4(Insn, 0, 4); |
| 4521 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4522 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 4523 | |
| 4524 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder))) |
| 4525 | return MCDisassembler_Fail; |
| 4526 | |
| 4527 | if (Rn == 0xF || Rd == Rn || Rd == Rt || Rd == Rt + 1) |
| 4528 | S = MCDisassembler_SoftFail; |
| 4529 | |
| 4530 | if (!Check(&S, DecodeGPRPairRegisterClass(Inst, Rt, Address, Decoder))) |
| 4531 | return MCDisassembler_Fail; |
| 4532 | |
| 4533 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4534 | return MCDisassembler_Fail; |
| 4535 | |
| 4536 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4537 | return MCDisassembler_Fail; |
| 4538 | |
| 4539 | return S; |
| 4540 | } |
| 4541 | |
| 4542 | static DecodeStatus DecodeLDRPreImm(MCInst *Inst, unsigned Insn, |
| 4543 | uint64_t Address, const void *Decoder) |
| 4544 | { |
| 4545 | DecodeStatus S = MCDisassembler_Success; |
| 4546 | unsigned pred; |
| 4547 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4548 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 4549 | unsigned imm = fieldFromInstruction_4(Insn, 0, 12); |
| 4550 | imm |= fieldFromInstruction_4(Insn, 16, 4) << 13; |
| 4551 | imm |= fieldFromInstruction_4(Insn, 23, 1) << 12; |
| 4552 | pred = fieldFromInstruction_4(Insn, 28, 4); |
| 4553 | |
| 4554 | if (Rn == 0xF || Rn == Rt) S = MCDisassembler_SoftFail; |
| 4555 | |
| 4556 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 4557 | return MCDisassembler_Fail; |
| 4558 | |
| 4559 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4560 | return MCDisassembler_Fail; |
| 4561 | |
| 4562 | if (!Check(&S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder))) |
| 4563 | return MCDisassembler_Fail; |
| 4564 | |
| 4565 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4566 | return MCDisassembler_Fail; |
| 4567 | |
| 4568 | return S; |
| 4569 | } |
| 4570 | |
| 4571 | static DecodeStatus DecodeLDRPreReg(MCInst *Inst, unsigned Insn, |
| 4572 | uint64_t Address, const void *Decoder) |
| 4573 | { |
| 4574 | DecodeStatus S = MCDisassembler_Success; |
| 4575 | unsigned pred, Rm; |
| 4576 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4577 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 4578 | unsigned imm = fieldFromInstruction_4(Insn, 0, 12); |
| 4579 | imm |= fieldFromInstruction_4(Insn, 16, 4) << 13; |
| 4580 | imm |= fieldFromInstruction_4(Insn, 23, 1) << 12; |
| 4581 | pred = fieldFromInstruction_4(Insn, 28, 4); |
| 4582 | Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4583 | |
| 4584 | if (Rn == 0xF || Rn == Rt) S = MCDisassembler_SoftFail; |
| 4585 | if (Rm == 0xF) S = MCDisassembler_SoftFail; |
| 4586 | |
| 4587 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 4588 | return MCDisassembler_Fail; |
| 4589 | |
| 4590 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4591 | return MCDisassembler_Fail; |
| 4592 | |
| 4593 | if (!Check(&S, DecodeSORegMemOperand(Inst, imm, Address, Decoder))) |
| 4594 | return MCDisassembler_Fail; |
| 4595 | |
| 4596 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4597 | return MCDisassembler_Fail; |
| 4598 | |
| 4599 | return S; |
| 4600 | } |
| 4601 | |
| 4602 | static DecodeStatus DecodeSTRPreImm(MCInst *Inst, unsigned Insn, |
| 4603 | uint64_t Address, const void *Decoder) |
| 4604 | { |
| 4605 | DecodeStatus S = MCDisassembler_Success; |
| 4606 | unsigned pred; |
| 4607 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4608 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 4609 | unsigned imm = fieldFromInstruction_4(Insn, 0, 12); |
| 4610 | imm |= fieldFromInstruction_4(Insn, 16, 4) << 13; |
| 4611 | imm |= fieldFromInstruction_4(Insn, 23, 1) << 12; |
| 4612 | pred = fieldFromInstruction_4(Insn, 28, 4); |
| 4613 | |
| 4614 | if (Rn == 0xF || Rn == Rt) S = MCDisassembler_SoftFail; |
| 4615 | |
| 4616 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4617 | return MCDisassembler_Fail; |
| 4618 | |
| 4619 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 4620 | return MCDisassembler_Fail; |
| 4621 | |
| 4622 | if (!Check(&S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder))) |
| 4623 | return MCDisassembler_Fail; |
| 4624 | |
| 4625 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4626 | return MCDisassembler_Fail; |
| 4627 | |
| 4628 | return S; |
| 4629 | } |
| 4630 | |
| 4631 | static DecodeStatus DecodeSTRPreReg(MCInst *Inst, unsigned Insn, |
| 4632 | uint64_t Address, const void *Decoder) |
| 4633 | { |
| 4634 | DecodeStatus S = MCDisassembler_Success; |
| 4635 | unsigned pred; |
| 4636 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4637 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 4638 | unsigned imm = fieldFromInstruction_4(Insn, 0, 12); |
| 4639 | imm |= fieldFromInstruction_4(Insn, 16, 4) << 13; |
| 4640 | imm |= fieldFromInstruction_4(Insn, 23, 1) << 12; |
| 4641 | pred = fieldFromInstruction_4(Insn, 28, 4); |
| 4642 | |
| 4643 | if (Rn == 0xF || Rn == Rt) S = MCDisassembler_SoftFail; |
| 4644 | |
| 4645 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4646 | return MCDisassembler_Fail; |
| 4647 | |
| 4648 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 4649 | return MCDisassembler_Fail; |
| 4650 | |
| 4651 | if (!Check(&S, DecodeSORegMemOperand(Inst, imm, Address, Decoder))) |
| 4652 | return MCDisassembler_Fail; |
| 4653 | |
| 4654 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 4655 | return MCDisassembler_Fail; |
| 4656 | |
| 4657 | return S; |
| 4658 | } |
| 4659 | |
| 4660 | static DecodeStatus DecodeVLD1LN(MCInst *Inst, unsigned Insn, |
| 4661 | uint64_t Address, const void *Decoder) |
| 4662 | { |
| 4663 | DecodeStatus S = MCDisassembler_Success; |
| 4664 | unsigned size, align = 0, index = 0; |
| 4665 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4666 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4667 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 4668 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 4669 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 4670 | |
| 4671 | switch (size) { |
| 4672 | default: |
| 4673 | return MCDisassembler_Fail; |
| 4674 | case 0: |
| 4675 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4676 | return MCDisassembler_Fail; // UNDEFINED |
| 4677 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 4678 | break; |
| 4679 | case 1: |
| 4680 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4681 | return MCDisassembler_Fail; // UNDEFINED |
| 4682 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 4683 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4684 | align = 2; |
| 4685 | break; |
| 4686 | case 2: |
| 4687 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 4688 | return MCDisassembler_Fail; // UNDEFINED |
| 4689 | |
| 4690 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 4691 | |
| 4692 | switch (fieldFromInstruction_4(Insn, 4, 2)) { |
| 4693 | case 0 : |
| 4694 | align = 0; break; |
| 4695 | case 3: |
| 4696 | align = 4; break; |
| 4697 | default: |
| 4698 | return MCDisassembler_Fail; |
| 4699 | } |
| 4700 | break; |
| 4701 | } |
| 4702 | |
| 4703 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4704 | return MCDisassembler_Fail; |
| 4705 | |
| 4706 | if (Rm != 0xF) { // Writeback |
| 4707 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4708 | return MCDisassembler_Fail; |
| 4709 | } |
| 4710 | |
| 4711 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4712 | return MCDisassembler_Fail; |
| 4713 | |
| 4714 | MCOperand_CreateImm0(Inst, align); |
| 4715 | |
| 4716 | if (Rm != 0xF) { |
| 4717 | if (Rm != 0xD) { |
| 4718 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4719 | return MCDisassembler_Fail; |
| 4720 | } else |
| 4721 | MCOperand_CreateReg0(Inst, 0); |
| 4722 | } |
| 4723 | |
| 4724 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4725 | return MCDisassembler_Fail; |
| 4726 | |
| 4727 | MCOperand_CreateImm0(Inst, index); |
| 4728 | |
| 4729 | return S; |
| 4730 | } |
| 4731 | |
| 4732 | static DecodeStatus DecodeVST1LN(MCInst *Inst, unsigned Insn, |
| 4733 | uint64_t Address, const void *Decoder) |
| 4734 | { |
| 4735 | DecodeStatus S = MCDisassembler_Success; |
| 4736 | unsigned size, align = 0, index = 0; |
| 4737 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4738 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4739 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 4740 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 4741 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 4742 | |
| 4743 | switch (size) { |
| 4744 | default: |
| 4745 | return MCDisassembler_Fail; |
| 4746 | case 0: |
| 4747 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4748 | return MCDisassembler_Fail; // UNDEFINED |
| 4749 | |
| 4750 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 4751 | break; |
| 4752 | case 1: |
| 4753 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4754 | return MCDisassembler_Fail; // UNDEFINED |
| 4755 | |
| 4756 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 4757 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4758 | align = 2; |
| 4759 | break; |
| 4760 | case 2: |
| 4761 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 4762 | return MCDisassembler_Fail; // UNDEFINED |
| 4763 | |
| 4764 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 4765 | |
| 4766 | switch (fieldFromInstruction_4(Insn, 4, 2)) { |
| 4767 | case 0: |
| 4768 | align = 0; break; |
| 4769 | case 3: |
| 4770 | align = 4; break; |
| 4771 | default: |
| 4772 | return MCDisassembler_Fail; |
| 4773 | } |
| 4774 | break; |
| 4775 | } |
| 4776 | |
| 4777 | if (Rm != 0xF) { // Writeback |
| 4778 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4779 | return MCDisassembler_Fail; |
| 4780 | } |
| 4781 | |
| 4782 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4783 | return MCDisassembler_Fail; |
| 4784 | |
| 4785 | MCOperand_CreateImm0(Inst, align); |
| 4786 | |
| 4787 | if (Rm != 0xF) { |
| 4788 | if (Rm != 0xD) { |
| 4789 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4790 | return MCDisassembler_Fail; |
| 4791 | } else |
| 4792 | MCOperand_CreateReg0(Inst, 0); |
| 4793 | } |
| 4794 | |
| 4795 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4796 | return MCDisassembler_Fail; |
| 4797 | |
| 4798 | MCOperand_CreateImm0(Inst, index); |
| 4799 | |
| 4800 | return S; |
| 4801 | } |
| 4802 | |
| 4803 | static DecodeStatus DecodeVLD2LN(MCInst *Inst, unsigned Insn, |
| 4804 | uint64_t Address, const void *Decoder) |
| 4805 | { |
| 4806 | DecodeStatus S = MCDisassembler_Success; |
| 4807 | unsigned size, align = 0, index = 0, inc = 1; |
| 4808 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4809 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4810 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 4811 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 4812 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 4813 | |
| 4814 | switch (size) { |
| 4815 | default: |
| 4816 | return MCDisassembler_Fail; |
| 4817 | case 0: |
| 4818 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 4819 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4820 | align = 2; |
| 4821 | break; |
| 4822 | case 1: |
| 4823 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 4824 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4825 | align = 4; |
| 4826 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4827 | inc = 2; |
| 4828 | break; |
| 4829 | case 2: |
| 4830 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4831 | return MCDisassembler_Fail; // UNDEFINED |
| 4832 | |
| 4833 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 4834 | if (fieldFromInstruction_4(Insn, 4, 1) != 0) |
| 4835 | align = 8; |
| 4836 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 4837 | inc = 2; |
| 4838 | break; |
| 4839 | } |
| 4840 | |
| 4841 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4842 | return MCDisassembler_Fail; |
| 4843 | |
| 4844 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 4845 | return MCDisassembler_Fail; |
| 4846 | |
| 4847 | if (Rm != 0xF) { // Writeback |
| 4848 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4849 | return MCDisassembler_Fail; |
| 4850 | } |
| 4851 | |
| 4852 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4853 | return MCDisassembler_Fail; |
| 4854 | |
| 4855 | MCOperand_CreateImm0(Inst, align); |
| 4856 | |
| 4857 | if (Rm != 0xF) { |
| 4858 | if (Rm != 0xD) { |
| 4859 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4860 | return MCDisassembler_Fail; |
| 4861 | } else |
| 4862 | MCOperand_CreateReg0(Inst, 0); |
| 4863 | } |
| 4864 | |
| 4865 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4866 | return MCDisassembler_Fail; |
| 4867 | |
| 4868 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 4869 | return MCDisassembler_Fail; |
| 4870 | |
| 4871 | MCOperand_CreateImm0(Inst, index); |
| 4872 | |
| 4873 | return S; |
| 4874 | } |
| 4875 | |
| 4876 | static DecodeStatus DecodeVST2LN(MCInst *Inst, unsigned Insn, |
| 4877 | uint64_t Address, const void *Decoder) |
| 4878 | { |
| 4879 | DecodeStatus S = MCDisassembler_Success; |
| 4880 | unsigned size, align = 0, index = 0, inc = 1; |
| 4881 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4882 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4883 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 4884 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 4885 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 4886 | |
| 4887 | switch (size) { |
| 4888 | default: |
| 4889 | return MCDisassembler_Fail; |
| 4890 | case 0: |
| 4891 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 4892 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4893 | align = 2; |
| 4894 | break; |
| 4895 | case 1: |
| 4896 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 4897 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4898 | align = 4; |
| 4899 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4900 | inc = 2; |
| 4901 | break; |
| 4902 | case 2: |
| 4903 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4904 | return MCDisassembler_Fail; // UNDEFINED |
| 4905 | |
| 4906 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 4907 | if (fieldFromInstruction_4(Insn, 4, 1) != 0) |
| 4908 | align = 8; |
| 4909 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 4910 | inc = 2; |
| 4911 | break; |
| 4912 | } |
| 4913 | |
| 4914 | if (Rm != 0xF) { // Writeback |
| 4915 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4916 | return MCDisassembler_Fail; |
| 4917 | } |
| 4918 | |
| 4919 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4920 | return MCDisassembler_Fail; |
| 4921 | |
| 4922 | MCOperand_CreateImm0(Inst, align); |
| 4923 | |
| 4924 | if (Rm != 0xF) { |
| 4925 | if (Rm != 0xD) { |
| 4926 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4927 | return MCDisassembler_Fail; |
| 4928 | } else |
| 4929 | MCOperand_CreateReg0(Inst, 0); |
| 4930 | } |
| 4931 | |
| 4932 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4933 | return MCDisassembler_Fail; |
| 4934 | |
| 4935 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 4936 | return MCDisassembler_Fail; |
| 4937 | |
| 4938 | MCOperand_CreateImm0(Inst, index); |
| 4939 | |
| 4940 | return S; |
| 4941 | } |
| 4942 | |
| 4943 | static DecodeStatus DecodeVLD3LN(MCInst *Inst, unsigned Insn, |
| 4944 | uint64_t Address, const void *Decoder) |
| 4945 | { |
| 4946 | DecodeStatus S = MCDisassembler_Success; |
| 4947 | unsigned size, align = 0, index = 0, inc = 1; |
| 4948 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 4949 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 4950 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 4951 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 4952 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 4953 | |
| 4954 | switch (size) { |
| 4955 | default: |
| 4956 | return MCDisassembler_Fail; |
| 4957 | case 0: |
| 4958 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4959 | return MCDisassembler_Fail; // UNDEFINED |
| 4960 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 4961 | break; |
| 4962 | case 1: |
| 4963 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 4964 | return MCDisassembler_Fail; // UNDEFINED |
| 4965 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 4966 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 4967 | inc = 2; |
| 4968 | break; |
| 4969 | case 2: |
| 4970 | if (fieldFromInstruction_4(Insn, 4, 2)) |
| 4971 | return MCDisassembler_Fail; // UNDEFINED |
| 4972 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 4973 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 4974 | inc = 2; |
| 4975 | break; |
| 4976 | } |
| 4977 | |
| 4978 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 4979 | return MCDisassembler_Fail; |
| 4980 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 4981 | return MCDisassembler_Fail; |
| 4982 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 2*inc, Address, Decoder))) |
| 4983 | return MCDisassembler_Fail; |
| 4984 | |
| 4985 | if (Rm != 0xF) { // Writeback |
| 4986 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4987 | return MCDisassembler_Fail; |
| 4988 | } |
| 4989 | |
| 4990 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 4991 | return MCDisassembler_Fail; |
| 4992 | |
| 4993 | MCOperand_CreateImm0(Inst, align); |
| 4994 | |
| 4995 | if (Rm != 0xF) { |
| 4996 | if (Rm != 0xD) { |
| 4997 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 4998 | return MCDisassembler_Fail; |
| 4999 | } else |
| 5000 | MCOperand_CreateReg0(Inst, 0); |
| 5001 | } |
| 5002 | |
| 5003 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 5004 | return MCDisassembler_Fail; |
| 5005 | |
| 5006 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 5007 | return MCDisassembler_Fail; |
| 5008 | |
| 5009 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 2*inc, Address, Decoder))) |
| 5010 | return MCDisassembler_Fail; |
| 5011 | |
| 5012 | MCOperand_CreateImm0(Inst, index); |
| 5013 | |
| 5014 | return S; |
| 5015 | } |
| 5016 | |
| 5017 | static DecodeStatus DecodeVST3LN(MCInst *Inst, unsigned Insn, |
| 5018 | uint64_t Address, const void *Decoder) |
| 5019 | { |
| 5020 | DecodeStatus S = MCDisassembler_Success; |
| 5021 | unsigned size, align = 0, index = 0, inc = 1; |
| 5022 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 5023 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 5024 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 5025 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 5026 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 5027 | |
| 5028 | switch (size) { |
| 5029 | default: |
| 5030 | return MCDisassembler_Fail; |
| 5031 | case 0: |
| 5032 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 5033 | return MCDisassembler_Fail; // UNDEFINED |
| 5034 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 5035 | break; |
| 5036 | case 1: |
| 5037 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 5038 | return MCDisassembler_Fail; // UNDEFINED |
| 5039 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 5040 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 5041 | inc = 2; |
| 5042 | break; |
| 5043 | case 2: |
| 5044 | if (fieldFromInstruction_4(Insn, 4, 2)) |
| 5045 | return MCDisassembler_Fail; // UNDEFINED |
| 5046 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 5047 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 5048 | inc = 2; |
| 5049 | break; |
| 5050 | } |
| 5051 | |
| 5052 | if (Rm != 0xF) { // Writeback |
| 5053 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5054 | return MCDisassembler_Fail; |
| 5055 | } |
| 5056 | |
| 5057 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5058 | return MCDisassembler_Fail; |
| 5059 | |
| 5060 | MCOperand_CreateImm0(Inst, align); |
| 5061 | |
| 5062 | if (Rm != 0xF) { |
| 5063 | if (Rm != 0xD) { |
| 5064 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 5065 | return MCDisassembler_Fail; |
| 5066 | } else |
| 5067 | MCOperand_CreateReg0(Inst, 0); |
| 5068 | } |
| 5069 | |
| 5070 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 5071 | return MCDisassembler_Fail; |
| 5072 | |
| 5073 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 5074 | return MCDisassembler_Fail; |
| 5075 | |
| 5076 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 2*inc, Address, Decoder))) |
| 5077 | return MCDisassembler_Fail; |
| 5078 | |
| 5079 | MCOperand_CreateImm0(Inst, index); |
| 5080 | |
| 5081 | return S; |
| 5082 | } |
| 5083 | |
| 5084 | static DecodeStatus DecodeVLD4LN(MCInst *Inst, unsigned Insn, |
| 5085 | uint64_t Address, const void *Decoder) |
| 5086 | { |
| 5087 | DecodeStatus S = MCDisassembler_Success; |
| 5088 | unsigned size, align = 0, index = 0, inc = 1; |
| 5089 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 5090 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 5091 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 5092 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 5093 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 5094 | |
| 5095 | switch (size) { |
| 5096 | default: |
| 5097 | return MCDisassembler_Fail; |
| 5098 | case 0: |
| 5099 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 5100 | align = 4; |
| 5101 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 5102 | break; |
| 5103 | case 1: |
| 5104 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 5105 | align = 8; |
| 5106 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 5107 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 5108 | inc = 2; |
| 5109 | break; |
| 5110 | case 2: |
| 5111 | switch (fieldFromInstruction_4(Insn, 4, 2)) { |
| 5112 | case 0: |
| 5113 | align = 0; break; |
| 5114 | case 3: |
| 5115 | return MCDisassembler_Fail; |
| 5116 | default: |
| 5117 | align = 4 << fieldFromInstruction_4(Insn, 4, 2); break; |
| 5118 | } |
| 5119 | |
| 5120 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 5121 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 5122 | inc = 2; |
| 5123 | break; |
| 5124 | } |
| 5125 | |
| 5126 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 5127 | return MCDisassembler_Fail; |
| 5128 | |
| 5129 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 5130 | return MCDisassembler_Fail; |
| 5131 | |
| 5132 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 2*inc, Address, Decoder))) |
| 5133 | return MCDisassembler_Fail; |
| 5134 | |
| 5135 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 3*inc, Address, Decoder))) |
| 5136 | return MCDisassembler_Fail; |
| 5137 | |
| 5138 | if (Rm != 0xF) { // Writeback |
| 5139 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5140 | return MCDisassembler_Fail; |
| 5141 | } |
| 5142 | |
| 5143 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5144 | return MCDisassembler_Fail; |
| 5145 | |
| 5146 | MCOperand_CreateImm0(Inst, align); |
| 5147 | |
| 5148 | if (Rm != 0xF) { |
| 5149 | if (Rm != 0xD) { |
| 5150 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 5151 | return MCDisassembler_Fail; |
| 5152 | } else |
| 5153 | MCOperand_CreateReg0(Inst, 0); |
| 5154 | } |
| 5155 | |
| 5156 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 5157 | return MCDisassembler_Fail; |
| 5158 | |
| 5159 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 5160 | return MCDisassembler_Fail; |
| 5161 | |
| 5162 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 2*inc, Address, Decoder))) |
| 5163 | return MCDisassembler_Fail; |
| 5164 | |
| 5165 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 3*inc, Address, Decoder))) |
| 5166 | return MCDisassembler_Fail; |
| 5167 | |
| 5168 | MCOperand_CreateImm0(Inst, index); |
| 5169 | |
| 5170 | return S; |
| 5171 | } |
| 5172 | |
| 5173 | static DecodeStatus DecodeVST4LN(MCInst *Inst, unsigned Insn, |
| 5174 | uint64_t Address, const void *Decoder) |
| 5175 | { |
| 5176 | DecodeStatus S = MCDisassembler_Success; |
| 5177 | unsigned size, align = 0, index = 0, inc = 1; |
| 5178 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 5179 | unsigned Rm = fieldFromInstruction_4(Insn, 0, 4); |
| 5180 | unsigned Rd = fieldFromInstruction_4(Insn, 12, 4); |
| 5181 | Rd |= fieldFromInstruction_4(Insn, 22, 1) << 4; |
| 5182 | size = fieldFromInstruction_4(Insn, 10, 2); |
| 5183 | |
| 5184 | switch (size) { |
| 5185 | default: |
| 5186 | return MCDisassembler_Fail; |
| 5187 | case 0: |
| 5188 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 5189 | align = 4; |
| 5190 | index = fieldFromInstruction_4(Insn, 5, 3); |
| 5191 | break; |
| 5192 | case 1: |
| 5193 | if (fieldFromInstruction_4(Insn, 4, 1)) |
| 5194 | align = 8; |
| 5195 | index = fieldFromInstruction_4(Insn, 6, 2); |
| 5196 | if (fieldFromInstruction_4(Insn, 5, 1)) |
| 5197 | inc = 2; |
| 5198 | break; |
| 5199 | case 2: |
| 5200 | switch (fieldFromInstruction_4(Insn, 4, 2)) { |
| 5201 | case 0: |
| 5202 | align = 0; break; |
| 5203 | case 3: |
| 5204 | return MCDisassembler_Fail; |
| 5205 | default: |
| 5206 | align = 4 << fieldFromInstruction_4(Insn, 4, 2); break; |
| 5207 | } |
| 5208 | |
| 5209 | index = fieldFromInstruction_4(Insn, 7, 1); |
| 5210 | if (fieldFromInstruction_4(Insn, 6, 1)) |
| 5211 | inc = 2; |
| 5212 | break; |
| 5213 | } |
| 5214 | |
| 5215 | if (Rm != 0xF) { // Writeback |
| 5216 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5217 | return MCDisassembler_Fail; |
| 5218 | } |
| 5219 | |
| 5220 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5221 | return MCDisassembler_Fail; |
| 5222 | |
| 5223 | MCOperand_CreateImm0(Inst, align); |
| 5224 | |
| 5225 | if (Rm != 0xF) { |
| 5226 | if (Rm != 0xD) { |
| 5227 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))) |
| 5228 | return MCDisassembler_Fail; |
| 5229 | } else |
| 5230 | MCOperand_CreateReg0(Inst, 0); |
| 5231 | } |
| 5232 | |
| 5233 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder))) |
| 5234 | return MCDisassembler_Fail; |
| 5235 | |
| 5236 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + inc, Address, Decoder))) |
| 5237 | return MCDisassembler_Fail; |
| 5238 | |
| 5239 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 2*inc, Address, Decoder))) |
| 5240 | return MCDisassembler_Fail; |
| 5241 | |
| 5242 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Rd + 3*inc, Address, Decoder))) |
| 5243 | return MCDisassembler_Fail; |
| 5244 | |
| 5245 | MCOperand_CreateImm0(Inst, index); |
| 5246 | |
| 5247 | return S; |
| 5248 | } |
| 5249 | |
| 5250 | static DecodeStatus DecodeVMOVSRR(MCInst *Inst, unsigned Insn, |
| 5251 | uint64_t Address, const void *Decoder) |
| 5252 | { |
| 5253 | DecodeStatus S = MCDisassembler_Success; |
| 5254 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 5255 | unsigned Rt2 = fieldFromInstruction_4(Insn, 16, 4); |
| 5256 | unsigned Rm = fieldFromInstruction_4(Insn, 5, 1); |
| 5257 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 5258 | Rm |= fieldFromInstruction_4(Insn, 0, 4) << 1; |
| 5259 | |
| 5260 | if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F) |
| 5261 | S = MCDisassembler_SoftFail; |
| 5262 | |
| 5263 | if (!Check(&S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder))) |
| 5264 | return MCDisassembler_Fail; |
| 5265 | |
| 5266 | if (!Check(&S, DecodeSPRRegisterClass(Inst, Rm + 1, Address, Decoder))) |
| 5267 | return MCDisassembler_Fail; |
| 5268 | |
| 5269 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder))) |
| 5270 | return MCDisassembler_Fail; |
| 5271 | |
| 5272 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder))) |
| 5273 | return MCDisassembler_Fail; |
| 5274 | |
| 5275 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 5276 | return MCDisassembler_Fail; |
| 5277 | |
| 5278 | return S; |
| 5279 | } |
| 5280 | |
| 5281 | static DecodeStatus DecodeVMOVRRS(MCInst *Inst, unsigned Insn, |
| 5282 | uint64_t Address, const void *Decoder) |
| 5283 | { |
| 5284 | DecodeStatus S = MCDisassembler_Success; |
| 5285 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 5286 | unsigned Rt2 = fieldFromInstruction_4(Insn, 16, 4); |
| 5287 | unsigned Rm = fieldFromInstruction_4(Insn, 5, 1); |
| 5288 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 5289 | Rm |= fieldFromInstruction_4(Insn, 0, 4) << 1; |
| 5290 | |
| 5291 | if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F) |
| 5292 | S = MCDisassembler_SoftFail; |
| 5293 | |
| 5294 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder))) |
| 5295 | return MCDisassembler_Fail; |
| 5296 | |
| 5297 | if (!Check(&S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder))) |
| 5298 | return MCDisassembler_Fail; |
| 5299 | |
| 5300 | if (!Check(&S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder))) |
| 5301 | return MCDisassembler_Fail; |
| 5302 | |
| 5303 | if (!Check(&S, DecodeSPRRegisterClass(Inst, Rm + 1, Address, Decoder))) |
| 5304 | return MCDisassembler_Fail; |
| 5305 | |
| 5306 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 5307 | return MCDisassembler_Fail; |
| 5308 | |
| 5309 | return S; |
| 5310 | } |
| 5311 | |
| 5312 | static DecodeStatus DecodeIT(MCInst *Inst, unsigned Insn, |
| 5313 | uint64_t Address, const void *Decoder) |
| 5314 | { |
| 5315 | DecodeStatus S = MCDisassembler_Success; |
| 5316 | unsigned pred = fieldFromInstruction_4(Insn, 4, 4); |
| 5317 | unsigned mask = fieldFromInstruction_4(Insn, 0, 4); |
| 5318 | |
| 5319 | if (pred == 0xF) { |
| 5320 | pred = 0xE; |
| 5321 | S = MCDisassembler_SoftFail; |
| 5322 | } |
| 5323 | |
| 5324 | if (mask == 0x0) |
| 5325 | return MCDisassembler_Fail; |
| 5326 | |
| 5327 | MCOperand_CreateImm0(Inst, pred); |
| 5328 | MCOperand_CreateImm0(Inst, mask); |
| 5329 | |
| 5330 | return S; |
| 5331 | } |
| 5332 | |
| 5333 | static DecodeStatus DecodeT2LDRDPreInstruction(MCInst *Inst, unsigned Insn, |
| 5334 | uint64_t Address, const void *Decoder) |
| 5335 | { |
| 5336 | DecodeStatus S = MCDisassembler_Success; |
| 5337 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 5338 | unsigned Rt2 = fieldFromInstruction_4(Insn, 8, 4); |
| 5339 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 5340 | unsigned addr = fieldFromInstruction_4(Insn, 0, 8); |
| 5341 | unsigned W = fieldFromInstruction_4(Insn, 21, 1); |
| 5342 | unsigned U = fieldFromInstruction_4(Insn, 23, 1); |
| 5343 | unsigned P = fieldFromInstruction_4(Insn, 24, 1); |
| 5344 | bool writeback = (W == 1) | (P == 0); |
| 5345 | |
| 5346 | addr |= (U << 8) | (Rn << 9); |
| 5347 | |
| 5348 | if (writeback && (Rn == Rt || Rn == Rt2)) |
| 5349 | Check(&S, MCDisassembler_SoftFail); |
| 5350 | |
| 5351 | if (Rt == Rt2) |
| 5352 | Check(&S, MCDisassembler_SoftFail); |
| 5353 | |
| 5354 | // Rt |
| 5355 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 5356 | return MCDisassembler_Fail; |
| 5357 | |
| 5358 | // Rt2 |
| 5359 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rt2, Address, Decoder))) |
| 5360 | return MCDisassembler_Fail; |
| 5361 | |
| 5362 | // Writeback operand |
| 5363 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5364 | return MCDisassembler_Fail; |
| 5365 | |
| 5366 | // addr |
| 5367 | if (!Check(&S, DecodeT2AddrModeImm8s4(Inst, addr, Address, Decoder))) |
| 5368 | return MCDisassembler_Fail; |
| 5369 | |
| 5370 | return S; |
| 5371 | } |
| 5372 | |
| 5373 | static DecodeStatus DecodeT2STRDPreInstruction(MCInst *Inst, unsigned Insn, |
| 5374 | uint64_t Address, const void *Decoder) |
| 5375 | { |
| 5376 | DecodeStatus S = MCDisassembler_Success; |
| 5377 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 5378 | unsigned Rt2 = fieldFromInstruction_4(Insn, 8, 4); |
| 5379 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 5380 | unsigned addr = fieldFromInstruction_4(Insn, 0, 8); |
| 5381 | unsigned W = fieldFromInstruction_4(Insn, 21, 1); |
| 5382 | unsigned U = fieldFromInstruction_4(Insn, 23, 1); |
| 5383 | unsigned P = fieldFromInstruction_4(Insn, 24, 1); |
| 5384 | bool writeback = (W == 1) | (P == 0); |
| 5385 | |
| 5386 | addr |= (U << 8) | (Rn << 9); |
| 5387 | |
| 5388 | if (writeback && (Rn == Rt || Rn == Rt2)) |
| 5389 | Check(&S, MCDisassembler_SoftFail); |
| 5390 | |
| 5391 | // Writeback operand |
| 5392 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rn, Address, Decoder))) |
| 5393 | return MCDisassembler_Fail; |
| 5394 | |
| 5395 | // Rt |
| 5396 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rt, Address, Decoder))) |
| 5397 | return MCDisassembler_Fail; |
| 5398 | |
| 5399 | // Rt2 |
| 5400 | if (!Check(&S, DecoderGPRRegisterClass(Inst, Rt2, Address, Decoder))) |
| 5401 | return MCDisassembler_Fail; |
| 5402 | |
| 5403 | // addr |
| 5404 | if (!Check(&S, DecodeT2AddrModeImm8s4(Inst, addr, Address, Decoder))) |
| 5405 | return MCDisassembler_Fail; |
| 5406 | |
| 5407 | return S; |
| 5408 | } |
| 5409 | |
| 5410 | static DecodeStatus DecodeT2Adr(MCInst *Inst, uint32_t Insn, |
| 5411 | uint64_t Address, const void *Decoder) |
| 5412 | { |
| 5413 | unsigned Val; |
| 5414 | unsigned sign1 = fieldFromInstruction_4(Insn, 21, 1); |
| 5415 | unsigned sign2 = fieldFromInstruction_4(Insn, 23, 1); |
| 5416 | |
| 5417 | if (sign1 != sign2) return MCDisassembler_Fail; |
| 5418 | |
| 5419 | Val = fieldFromInstruction_4(Insn, 0, 8); |
| 5420 | Val |= fieldFromInstruction_4(Insn, 12, 3) << 8; |
| 5421 | Val |= fieldFromInstruction_4(Insn, 26, 1) << 11; |
| 5422 | Val |= sign1 << 12; |
| 5423 | |
| 5424 | MCOperand_CreateImm0(Inst, SignExtend32(Val, 13)); |
| 5425 | |
| 5426 | return MCDisassembler_Success; |
| 5427 | } |
| 5428 | |
| 5429 | static DecodeStatus DecodeT2ShifterImmOperand(MCInst *Inst, uint32_t Val, |
| 5430 | uint64_t Address, const void *Decoder) |
| 5431 | { |
| 5432 | // Shift of "asr #32" is not allowed in Thumb2 mode. |
| 5433 | if (Val == 0x20) |
| 5434 | return MCDisassembler_Fail; |
| 5435 | |
| 5436 | MCOperand_CreateImm0(Inst, Val); |
| 5437 | |
| 5438 | return MCDisassembler_Success; |
| 5439 | } |
| 5440 | |
| 5441 | static DecodeStatus DecodeSwap(MCInst *Inst, unsigned Insn, |
| 5442 | uint64_t Address, const void *Decoder) |
| 5443 | { |
| 5444 | DecodeStatus S; |
| 5445 | unsigned Rt = fieldFromInstruction_4(Insn, 12, 4); |
| 5446 | unsigned Rt2 = fieldFromInstruction_4(Insn, 0, 4); |
| 5447 | unsigned Rn = fieldFromInstruction_4(Insn, 16, 4); |
| 5448 | unsigned pred = fieldFromInstruction_4(Insn, 28, 4); |
| 5449 | |
| 5450 | if (pred == 0xF) |
| 5451 | return DecodeCPSInstruction(Inst, Insn, Address, Decoder); |
| 5452 | |
| 5453 | S = MCDisassembler_Success; |
| 5454 | |
| 5455 | if (Rt == Rn || Rn == Rt2) |
| 5456 | S = MCDisassembler_SoftFail; |
| 5457 | |
| 5458 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder))) |
| 5459 | return MCDisassembler_Fail; |
| 5460 | |
| 5461 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder))) |
| 5462 | return MCDisassembler_Fail; |
| 5463 | |
| 5464 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder))) |
| 5465 | return MCDisassembler_Fail; |
| 5466 | |
| 5467 | if (!Check(&S, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 5468 | return MCDisassembler_Fail; |
| 5469 | |
| 5470 | return S; |
| 5471 | } |
| 5472 | |
| 5473 | static DecodeStatus DecodeVCVTD(MCInst *Inst, unsigned Insn, |
| 5474 | uint64_t Address, const void *Decoder) |
| 5475 | { |
| 5476 | DecodeStatus S = MCDisassembler_Success; |
| 5477 | bool hasFullFP16 = ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureFullFP16); |
| 5478 | unsigned Vm, imm, cmode, op; |
| 5479 | unsigned Vd = (fieldFromInstruction_4(Insn, 12, 4) << 0); |
| 5480 | |
| 5481 | Vd |= (fieldFromInstruction_4(Insn, 22, 1) << 4); |
| 5482 | Vm = (fieldFromInstruction_4(Insn, 0, 4) << 0); |
| 5483 | Vm |= (fieldFromInstruction_4(Insn, 5, 1) << 4); |
| 5484 | imm = fieldFromInstruction_4(Insn, 16, 6); |
| 5485 | cmode = fieldFromInstruction_4(Insn, 8, 4); |
| 5486 | op = fieldFromInstruction_4(Insn, 5, 1); |
| 5487 | |
| 5488 | // If the top 3 bits of imm are clear, this is a VMOV (immediate) |
| 5489 | if (!(imm & 0x38)) { |
| 5490 | if (cmode == 0xF) { |
| 5491 | if (op == 1) return MCDisassembler_Fail; |
| 5492 | MCInst_setOpcode(Inst, ARM_VMOVv2f32); |
| 5493 | } |
| 5494 | |
| 5495 | if (hasFullFP16) { |
| 5496 | if (cmode == 0xE) { |
| 5497 | if (op == 1) { |
| 5498 | MCInst_setOpcode(Inst, ARM_VMOVv1i64); |
| 5499 | } else { |
| 5500 | MCInst_setOpcode(Inst, ARM_VMOVv8i8); |
| 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | if (cmode == 0xD) { |
| 5505 | if (op == 1) { |
| 5506 | MCInst_setOpcode(Inst, ARM_VMVNv2i32); |
| 5507 | } else { |
| 5508 | MCInst_setOpcode(Inst, ARM_VMOVv2i32); |
| 5509 | } |
| 5510 | } |
| 5511 | |
| 5512 | if (cmode == 0xC) { |
| 5513 | if (op == 1) { |
| 5514 | MCInst_setOpcode(Inst, ARM_VMVNv2i32); |
| 5515 | } else { |
| 5516 | MCInst_setOpcode(Inst, ARM_VMOVv2i32); |
| 5517 | } |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder); |
| 5522 | } |
| 5523 | |
| 5524 | if (!(imm & 0x20)) return MCDisassembler_Fail; |
| 5525 | |
| 5526 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 5527 | return MCDisassembler_Fail; |
| 5528 | |
| 5529 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vm, Address, Decoder))) |
| 5530 | return MCDisassembler_Fail; |
| 5531 | |
| 5532 | MCOperand_CreateImm0(Inst, 64 - imm); |
| 5533 | |
| 5534 | return S; |
| 5535 | } |
| 5536 | |
| 5537 | static DecodeStatus DecodeVCVTQ(MCInst *Inst, unsigned Insn, |
| 5538 | uint64_t Address, const void *Decoder) |
| 5539 | { |
| 5540 | DecodeStatus S = MCDisassembler_Success; |
| 5541 | bool hasFullFP16 = ARM_getFeatureBits(Inst->csh->mode, ARM_FeatureFullFP16); |
| 5542 | unsigned Vm, imm, cmode, op; |
| 5543 | unsigned Vd = (fieldFromInstruction_4(Insn, 12, 4) << 0); |
| 5544 | |
| 5545 | Vd |= (fieldFromInstruction_4(Insn, 22, 1) << 4); |
| 5546 | Vm = (fieldFromInstruction_4(Insn, 0, 4) << 0); |
| 5547 | Vm |= (fieldFromInstruction_4(Insn, 5, 1) << 4); |
| 5548 | imm = fieldFromInstruction_4(Insn, 16, 6); |
| 5549 | cmode = fieldFromInstruction_4(Insn, 8, 4); |
| 5550 | op = fieldFromInstruction_4(Insn, 5, 1); |
| 5551 | |
| 5552 | // VMOVv4f32 is ambiguous with these decodings. |
| 5553 | if (!(imm & 0x38) && cmode == 0xF) { |
| 5554 | if (op == 1) return MCDisassembler_Fail; |
| 5555 | MCInst_setOpcode(Inst, ARM_VMOVv4f32); |
| 5556 | return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder); |
| 5557 | } |
| 5558 | |
| 5559 | // If the top 3 bits of imm are clear, this is a VMOV (immediate) |
| 5560 | if (!(imm & 0x38)) { |
| 5561 | if (cmode == 0xF) { |
| 5562 | if (op == 1) return MCDisassembler_Fail; |
| 5563 | MCInst_setOpcode(Inst, ARM_VMOVv4f32); |
| 5564 | } |
| 5565 | |
| 5566 | if (hasFullFP16) { |
| 5567 | if (cmode == 0xE) { |
| 5568 | if (op == 1) { |
| 5569 | MCInst_setOpcode(Inst, ARM_VMOVv2i64); |
| 5570 | } else { |
| 5571 | MCInst_setOpcode(Inst, ARM_VMOVv16i8); |
| 5572 | } |
| 5573 | } |
| 5574 | |
| 5575 | if (cmode == 0xD) { |
| 5576 | if (op == 1) { |
| 5577 | MCInst_setOpcode(Inst, ARM_VMVNv4i32); |
| 5578 | } else { |
| 5579 | MCInst_setOpcode(Inst, ARM_VMOVv4i32); |
| 5580 | } |
| 5581 | } |
| 5582 | |
| 5583 | if (cmode == 0xC) { |
| 5584 | if (op == 1) { |
| 5585 | MCInst_setOpcode(Inst, ARM_VMVNv4i32); |
| 5586 | } else { |
| 5587 | MCInst_setOpcode(Inst, ARM_VMOVv4i32); |
| 5588 | } |
| 5589 | } |
| 5590 | } |
| 5591 | |
| 5592 | return DecodeNEONModImmInstruction(Inst, Insn, Address, Decoder); |
| 5593 | } |
| 5594 | |
| 5595 | if (!(imm & 0x20)) return MCDisassembler_Fail; |
| 5596 | |
| 5597 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 5598 | return MCDisassembler_Fail; |
| 5599 | |
| 5600 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Vm, Address, Decoder))) |
| 5601 | return MCDisassembler_Fail; |
| 5602 | |
| 5603 | MCOperand_CreateImm0(Inst, 64 - imm); |
| 5604 | |
| 5605 | return S; |
| 5606 | } |
| 5607 | |
| 5608 | static DecodeStatus DecodeNEONComplexLane64Instruction(MCInst *Inst, unsigned Insn, |
| 5609 | uint64_t Address, const void *Decoder) |
| 5610 | { |
| 5611 | DecodeStatus S = MCDisassembler_Success; |
| 5612 | unsigned Vd = (fieldFromInstruction_4(Insn, 12, 4) << 0); |
| 5613 | unsigned Vn = (fieldFromInstruction_4(Insn, 16, 4) << 0); |
| 5614 | unsigned Vm = (fieldFromInstruction_4(Insn, 0, 4) << 0); |
| 5615 | unsigned q = (fieldFromInstruction_4(Insn, 6, 1) << 0); |
| 5616 | unsigned rotate = (fieldFromInstruction_4(Insn, 20, 2) << 0); |
| 5617 | |
| 5618 | Vd |= (fieldFromInstruction_4(Insn, 22, 1) << 4); |
| 5619 | Vn |= (fieldFromInstruction_4(Insn, 7, 1) << 4); |
| 5620 | Vm |= (fieldFromInstruction_4(Insn, 5, 1) << 4); |
| 5621 | |
| 5622 | if (q) { |
| 5623 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 5624 | return MCDisassembler_Fail; |
| 5625 | |
| 5626 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 5627 | return MCDisassembler_Fail; |
| 5628 | |
| 5629 | if (!Check(&S, DecodeQPRRegisterClass(Inst, Vn, Address, Decoder))) |
| 5630 | return MCDisassembler_Fail; |
| 5631 | } else { |
| 5632 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 5633 | return MCDisassembler_Fail; |
| 5634 | |
| 5635 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder))) |
| 5636 | return MCDisassembler_Fail; |
| 5637 | |
| 5638 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vn, Address, Decoder))) |
| 5639 | return MCDisassembler_Fail; |
| 5640 | } |
| 5641 | |
| 5642 | if (!Check(&S, DecodeDPRRegisterClass(Inst, Vm, Address, Decoder))) |
| 5643 | return MCDisassembler_Fail; |
| 5644 | |
| 5645 | // The lane index does not have any bits in the encoding, because it can only |
| 5646 | // be 0. |
| 5647 | MCOperand_CreateImm0(Inst, 0); |
| 5648 | MCOperand_CreateImm0(Inst, rotate); |
| 5649 | |
| 5650 | return S; |
| 5651 | } |
| 5652 | |
| 5653 | static DecodeStatus DecodeLDR(MCInst *Inst, unsigned Val, |
| 5654 | uint64_t Address, const void *Decoder) |
| 5655 | { |
| 5656 | DecodeStatus S = MCDisassembler_Success; |
| 5657 | unsigned Cond; |
| 5658 | unsigned Rn = fieldFromInstruction_4(Val, 16, 4); |
| 5659 | unsigned Rt = fieldFromInstruction_4(Val, 12, 4); |
| 5660 | unsigned Rm = fieldFromInstruction_4(Val, 0, 4); |
| 5661 | |
| 5662 | Rm |= (fieldFromInstruction_4(Val, 23, 1) << 4); |
| 5663 | Cond = fieldFromInstruction_4(Val, 28, 4); |
| 5664 | |
| 5665 | if (fieldFromInstruction_4(Val, 8, 4) != 0 || Rn == Rt) |
| 5666 | S = MCDisassembler_SoftFail; |
| 5667 | |
| 5668 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder))) |
| 5669 | return MCDisassembler_Fail; |
| 5670 | |
| 5671 | if (!Check(&S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder))) |
| 5672 | return MCDisassembler_Fail; |
| 5673 | |
| 5674 | if (!Check(&S, DecodeAddrMode7Operand(Inst, Rn, Address, Decoder))) |
| 5675 | return MCDisassembler_Fail; |
| 5676 | |
| 5677 | if (!Check(&S, DecodePostIdxReg(Inst, Rm, Address, Decoder))) |
| 5678 | return MCDisassembler_Fail; |
| 5679 | |
| 5680 | if (!Check(&S, DecodePredicateOperand(Inst, Cond, Address, Decoder))) |
| 5681 | return MCDisassembler_Fail; |
| 5682 | |
| 5683 | return S; |
| 5684 | } |
| 5685 | |
| 5686 | static DecodeStatus DecoderForMRRC2AndMCRR2(MCInst *Inst, unsigned Val, |
| 5687 | uint64_t Address, const void *Decoder) |
| 5688 | { |
| 5689 | DecodeStatus result = MCDisassembler_Success; |
| 5690 | unsigned CRm = fieldFromInstruction_4(Val, 0, 4); |
| 5691 | unsigned opc1 = fieldFromInstruction_4(Val, 4, 4); |
| 5692 | unsigned cop = fieldFromInstruction_4(Val, 8, 4); |
| 5693 | unsigned Rt = fieldFromInstruction_4(Val, 12, 4); |
| 5694 | unsigned Rt2 = fieldFromInstruction_4(Val, 16, 4); |
| 5695 | |
| 5696 | if ((cop & ~0x1) == 0xa) |
| 5697 | return MCDisassembler_Fail; |
| 5698 | |
| 5699 | if (Rt == Rt2) |
| 5700 | result = MCDisassembler_SoftFail; |
| 5701 | |
| 5702 | // We have to check if the instruction is MRRC2 |
| 5703 | // or MCRR2 when constructing the operands for |
| 5704 | // Inst. Reason is because MRRC2 stores to two |
| 5705 | // registers so it's tablegen desc has has two |
| 5706 | // outputs whereas MCRR doesn't store to any |
| 5707 | // registers so all of it's operands are listed |
| 5708 | // as inputs, therefore the operand order for |
| 5709 | // MRRC2 needs to be [Rt, Rt2, cop, opc1, CRm] |
| 5710 | // and MCRR2 operand order is [cop, opc1, Rt, Rt2, CRm] |
| 5711 | |
| 5712 | if (MCInst_getOpcode(Inst) == ARM_MRRC2) { |
| 5713 | if (!Check(&result, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder))) |
| 5714 | return MCDisassembler_Fail; |
| 5715 | |
| 5716 | if (!Check(&result, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder))) |
| 5717 | return MCDisassembler_Fail; |
| 5718 | } |
| 5719 | |
| 5720 | MCOperand_CreateImm0(Inst, cop); |
| 5721 | MCOperand_CreateImm0(Inst, opc1); |
| 5722 | |
| 5723 | if (MCInst_getOpcode(Inst) == ARM_MCRR2) { |
| 5724 | if (!Check(&result, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder))) |
| 5725 | return MCDisassembler_Fail; |
| 5726 | |
| 5727 | if (!Check(&result, DecodeGPRnopcRegisterClass(Inst, Rt2, Address, Decoder))) |
| 5728 | return MCDisassembler_Fail; |
| 5729 | } |
| 5730 | |
| 5731 | MCOperand_CreateImm0(Inst, CRm); |
| 5732 | |
| 5733 | return result; |
| 5734 | } |
| 5735 | |
| 5736 | static DecodeStatus DecodeForVMRSandVMSR(MCInst *Inst, unsigned Val, |
| 5737 | uint64_t Address, const void *Decoder) |
| 5738 | { |
| 5739 | DecodeStatus result = MCDisassembler_Success; |
| 5740 | bool HasV8Ops = ARM_getFeatureBits(Inst->csh->mode, ARM_HasV8Ops); |
| 5741 | unsigned Rt = fieldFromInstruction_4(Val, 12, 4); |
| 5742 | |
| 5743 | if ((Inst->csh->mode & CS_MODE_THUMB) && !HasV8Ops) { |
| 5744 | if (Rt == 13 || Rt == 15) |
| 5745 | result = MCDisassembler_SoftFail; |
| 5746 | |
| 5747 | Check(&result, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)); |
| 5748 | } else |
| 5749 | Check(&result, DecodeGPRnopcRegisterClass(Inst, Rt, Address, Decoder)); |
| 5750 | |
| 5751 | if (Inst->csh->mode & CS_MODE_THUMB) { |
| 5752 | MCOperand_CreateImm0(Inst, ARMCC_AL); |
| 5753 | MCOperand_CreateReg0(Inst, 0); |
| 5754 | } else { |
| 5755 | unsigned pred = fieldFromInstruction_4(Val, 28, 4); |
| 5756 | if (!Check(&result, DecodePredicateOperand(Inst, pred, Address, Decoder))) |
| 5757 | return MCDisassembler_Fail; |
| 5758 | } |
| 5759 | |
| 5760 | return result; |
| 5761 | } |
| 5762 | |
| 5763 | #endif |