/src/capstonenext/arch/AArch64/AArch64Disassembler.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Capstone Disassembly Engine, http://www.capstone-engine.org */ |
2 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */ |
3 | | /* Rot127 <unisono@quyllur.org> 2022-2023 */ |
4 | | /* Automatically translated source file from LLVM. */ |
5 | | |
6 | | /* LLVM-commit: <commit> */ |
7 | | /* LLVM-tag: <tag> */ |
8 | | |
9 | | /* Only small edits allowed. */ |
10 | | /* For multiple similar edits, please create a Patch for the translator. */ |
11 | | |
12 | | /* Capstone's C++ file translator: */ |
13 | | /* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */ |
14 | | |
15 | | //===- AArch64Disassembler.cpp - Disassembler for AArch64 -----------------===// |
16 | | // |
17 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
18 | | // See https://llvm.org/LICENSE.txt for license information. |
19 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
20 | | // |
21 | | //===----------------------------------------------------------------------===// |
22 | | // |
23 | | // |
24 | | //===----------------------------------------------------------------------===// |
25 | | |
26 | | #include <stdio.h> |
27 | | #include <string.h> |
28 | | #include <stdlib.h> |
29 | | #include <capstone/platform.h> |
30 | | |
31 | | #include "../../MCFixedLenDisassembler.h" |
32 | | #include "../../MCInst.h" |
33 | | #include "../../MCInstrDesc.h" |
34 | | #include "../../MCRegisterInfo.h" |
35 | | #include "../../LEB128.h" |
36 | | #include "../../MCDisassembler.h" |
37 | | #include "../../cs_priv.h" |
38 | | #include "../../utils.h" |
39 | | #include "AArch64AddressingModes.h" |
40 | | #include "AArch64BaseInfo.h" |
41 | | #include "AArch64DisassemblerExtension.h" |
42 | | #include "AArch64Linkage.h" |
43 | | #include "AArch64Mapping.h" |
44 | | |
45 | | #define GET_INSTRINFO_MC_DESC |
46 | | #include "AArch64GenInstrInfo.inc" |
47 | | |
48 | 456 | #define CONCAT(a, b) CONCAT_(a, b) |
49 | 456 | #define CONCAT_(a, b) a##_##b |
50 | | |
51 | | #define DEBUG_TYPE "aarch64-disassembler" |
52 | | |
53 | | // Pull DecodeStatus and its enum values into the global namespace. |
54 | | |
55 | | // Forward declare these because the autogenerated code will reference them. |
56 | | // Definitions are further down. |
57 | | static DecodeStatus DecodeFPR128RegisterClass(MCInst *Inst, unsigned RegNo, |
58 | | uint64_t Address, |
59 | | const void *Decoder); |
60 | | static DecodeStatus DecodeFPR128_loRegisterClass(MCInst *Inst, unsigned RegNo, |
61 | | uint64_t Address, |
62 | | const void *Decoder); |
63 | | static DecodeStatus DecodeFPR128_0to7RegisterClass(MCInst *Inst, unsigned RegNo, |
64 | | uint64_t Address, |
65 | | const void *Decoder); |
66 | | static DecodeStatus DecodeFPR64RegisterClass(MCInst *Inst, unsigned RegNo, |
67 | | uint64_t Address, |
68 | | const void *Decoder); |
69 | | static DecodeStatus DecodeFPR32RegisterClass(MCInst *Inst, unsigned RegNo, |
70 | | uint64_t Address, |
71 | | const void *Decoder); |
72 | | static DecodeStatus DecodeFPR16RegisterClass(MCInst *Inst, unsigned RegNo, |
73 | | uint64_t Address, |
74 | | const void *Decoder); |
75 | | static DecodeStatus DecodeFPR8RegisterClass(MCInst *Inst, unsigned RegNo, |
76 | | uint64_t Address, |
77 | | const void *Decoder); |
78 | | static DecodeStatus DecodeGPR64commonRegisterClass(MCInst *Inst, unsigned RegNo, |
79 | | uint64_t Address, |
80 | | const void *Decoder); |
81 | | static DecodeStatus DecodeGPR64RegisterClass(MCInst *Inst, unsigned RegNo, |
82 | | uint64_t Address, |
83 | | const void *Decoder); |
84 | | static DecodeStatus DecodeGPR64x8ClassRegisterClass(MCInst *Inst, |
85 | | unsigned RegNo, |
86 | | uint64_t Address, |
87 | | const void *Decoder); |
88 | | static DecodeStatus DecodeGPR64spRegisterClass(MCInst *Inst, unsigned RegNo, |
89 | | uint64_t Address, |
90 | | const void *Decoder); |
91 | | static DecodeStatus |
92 | | DecodeMatrixIndexGPR32_8_11RegisterClass(MCInst *Inst, unsigned RegNo, |
93 | | uint64_t Address, const void *Decoder); |
94 | | static DecodeStatus DecodeMatrixIndexGPR32_12_15RegisterClass( |
95 | | MCInst *Inst, unsigned RegNo, uint64_t Address, const void *Decoder); |
96 | | static DecodeStatus DecodeGPR32RegisterClass(MCInst *Inst, unsigned RegNo, |
97 | | uint64_t Address, |
98 | | const void *Decoder); |
99 | | static DecodeStatus DecodeGPR32spRegisterClass(MCInst *Inst, unsigned RegNo, |
100 | | uint64_t Address, |
101 | | const void *Decoder); |
102 | | static DecodeStatus DecodeQQRegisterClass(MCInst *Inst, unsigned RegNo, |
103 | | uint64_t Address, |
104 | | const void *Decoder); |
105 | | static DecodeStatus DecodeQQQRegisterClass(MCInst *Inst, unsigned RegNo, |
106 | | uint64_t Address, |
107 | | const void *Decoder); |
108 | | static DecodeStatus DecodeQQQQRegisterClass(MCInst *Inst, unsigned RegNo, |
109 | | uint64_t Address, |
110 | | const void *Decoder); |
111 | | static DecodeStatus DecodeDDRegisterClass(MCInst *Inst, unsigned RegNo, |
112 | | uint64_t Address, |
113 | | const void *Decoder); |
114 | | static DecodeStatus DecodeDDDRegisterClass(MCInst *Inst, unsigned RegNo, |
115 | | uint64_t Address, |
116 | | const void *Decoder); |
117 | | static DecodeStatus DecodeDDDDRegisterClass(MCInst *Inst, unsigned RegNo, |
118 | | uint64_t Address, |
119 | | const void *Decoder); |
120 | | static DecodeStatus DecodeZPRRegisterClass(MCInst *Inst, unsigned RegNo, |
121 | | uint64_t Address, |
122 | | const void *Decoder); |
123 | | static DecodeStatus DecodeZPR_4bRegisterClass(MCInst *Inst, unsigned RegNo, |
124 | | uint64_t Address, |
125 | | const void *Decoder); |
126 | | static DecodeStatus DecodeZPR_3bRegisterClass(MCInst *Inst, unsigned RegNo, |
127 | | uint64_t Address, |
128 | | const void *Decoder); |
129 | | static DecodeStatus DecodeZPR2RegisterClass(MCInst *Inst, unsigned RegNo, |
130 | | uint64_t Address, |
131 | | const void *Decoder); |
132 | | static DecodeStatus DecodeZPR3RegisterClass(MCInst *Inst, unsigned RegNo, |
133 | | uint64_t Address, |
134 | | const void *Decoder); |
135 | | static DecodeStatus DecodeZPR4RegisterClass(MCInst *Inst, unsigned RegNo, |
136 | | uint64_t Address, |
137 | | const void *Decoder); |
138 | | static DecodeStatus DecodeZPR2Mul2RegisterClass(MCInst *Inst, unsigned RegNo, |
139 | | uint64_t Address, |
140 | | const void *Decoder); |
141 | | static DecodeStatus DecodeZPR4Mul4RegisterClass(MCInst *Inst, unsigned RegNo, |
142 | | uint64_t Address, |
143 | | const void *Decoder); |
144 | | static DecodeStatus DecodeZPR2StridedRegisterClass(MCInst *Inst, unsigned RegNo, |
145 | | uint64_t Address, |
146 | | const void *Decoder); |
147 | | static DecodeStatus DecodeZPR4StridedRegisterClass(MCInst *Inst, unsigned RegNo, |
148 | | uint64_t Address, |
149 | | const void *Decoder); |
150 | | #define DECLARE_DecodeMatrixTile(NumBitsForTile) \ |
151 | | static DecodeStatus CONCAT(DecodeMatrixTile, NumBitsForTile)( \ |
152 | | MCInst * Inst, unsigned RegNo, uint64_t Address, \ |
153 | | const void *Decoder); |
154 | | DECLARE_DecodeMatrixTile(2); |
155 | | DECLARE_DecodeMatrixTile(1); |
156 | | DECLARE_DecodeMatrixTile(3); |
157 | | DECLARE_DecodeMatrixTile(4); |
158 | | |
159 | | static DecodeStatus DecodeMatrixTileListRegisterClass(MCInst *Inst, |
160 | | unsigned RegMask, |
161 | | uint64_t Address, |
162 | | const void *Decoder); |
163 | | static DecodeStatus DecodePPRRegisterClass(MCInst *Inst, unsigned RegNo, |
164 | | uint64_t Address, |
165 | | const void *Decoder); |
166 | | static DecodeStatus DecodePNRRegisterClass(MCInst *Inst, unsigned RegNo, |
167 | | uint64_t Address, |
168 | | const void *Decoder); |
169 | | static DecodeStatus DecodePPR_3bRegisterClass(MCInst *Inst, unsigned RegNo, |
170 | | uint64_t Address, |
171 | | const void *Decoder); |
172 | | static DecodeStatus DecodePNR_p8to15RegisterClass(MCInst *Inst, unsigned RegNo, |
173 | | uint64_t Address, |
174 | | const void *Decoder); |
175 | | static DecodeStatus DecodePPR2RegisterClass(MCInst *Inst, unsigned RegNo, |
176 | | uint64_t Address, |
177 | | const void *Decoder); |
178 | | static DecodeStatus DecodePPR2Mul2RegisterClass(MCInst *Inst, unsigned RegNo, |
179 | | uint64_t Address, |
180 | | const void *Decoder); |
181 | | |
182 | | static DecodeStatus DecodeFixedPointScaleImm32(MCInst *Inst, unsigned Imm, |
183 | | uint64_t Address, |
184 | | const void *Decoder); |
185 | | static DecodeStatus DecodeFixedPointScaleImm64(MCInst *Inst, unsigned Imm, |
186 | | uint64_t Address, |
187 | | const void *Decoder); |
188 | | static DecodeStatus DecodePCRelLabel16(MCInst *Inst, unsigned Imm, |
189 | | uint64_t Address, const void *Decoder); |
190 | | static DecodeStatus DecodePCRelLabel19(MCInst *Inst, unsigned Imm, |
191 | | uint64_t Address, const void *Decoder); |
192 | | static DecodeStatus DecodeMemExtend(MCInst *Inst, unsigned Imm, |
193 | | uint64_t Address, const void *Decoder); |
194 | | static DecodeStatus DecodeMRSSystemRegister(MCInst *Inst, unsigned Imm, |
195 | | uint64_t Address, |
196 | | const void *Decoder); |
197 | | static DecodeStatus DecodeMSRSystemRegister(MCInst *Inst, unsigned Imm, |
198 | | uint64_t Address, |
199 | | const void *Decoder); |
200 | | static DecodeStatus DecodeThreeAddrSRegInstruction(MCInst *Inst, uint32_t insn, |
201 | | uint64_t Address, |
202 | | const void *Decoder); |
203 | | static DecodeStatus DecodeMoveImmInstruction(MCInst *Inst, uint32_t insn, |
204 | | uint64_t Address, |
205 | | const void *Decoder); |
206 | | static DecodeStatus DecodeUnsignedLdStInstruction(MCInst *Inst, uint32_t insn, |
207 | | uint64_t Address, |
208 | | const void *Decoder); |
209 | | static DecodeStatus DecodeSignedLdStInstruction(MCInst *Inst, uint32_t insn, |
210 | | uint64_t Address, |
211 | | const void *Decoder); |
212 | | static DecodeStatus DecodeExclusiveLdStInstruction(MCInst *Inst, uint32_t insn, |
213 | | uint64_t Address, |
214 | | const void *Decoder); |
215 | | static DecodeStatus DecodePairLdStInstruction(MCInst *Inst, uint32_t insn, |
216 | | uint64_t Address, |
217 | | const void *Decoder); |
218 | | static DecodeStatus DecodeAuthLoadInstruction(MCInst *Inst, uint32_t insn, |
219 | | uint64_t Address, |
220 | | const void *Decoder); |
221 | | static DecodeStatus DecodeAddSubERegInstruction(MCInst *Inst, uint32_t insn, |
222 | | uint64_t Address, |
223 | | const void *Decoder); |
224 | | static DecodeStatus DecodeLogicalImmInstruction(MCInst *Inst, uint32_t insn, |
225 | | uint64_t Address, |
226 | | const void *Decoder); |
227 | | static DecodeStatus DecodeModImmInstruction(MCInst *Inst, uint32_t insn, |
228 | | uint64_t Address, |
229 | | const void *Decoder); |
230 | | static DecodeStatus DecodeModImmTiedInstruction(MCInst *Inst, uint32_t insn, |
231 | | uint64_t Address, |
232 | | const void *Decoder); |
233 | | static DecodeStatus DecodeAdrInstruction(MCInst *Inst, uint32_t insn, |
234 | | uint64_t Address, const void *Decoder); |
235 | | static DecodeStatus DecodeAddSubImmShift(MCInst *Inst, uint32_t insn, |
236 | | uint64_t Address, const void *Decoder); |
237 | | static DecodeStatus DecodeUnconditionalBranch(MCInst *Inst, uint32_t insn, |
238 | | uint64_t Address, |
239 | | const void *Decoder); |
240 | | static DecodeStatus DecodeSystemPStateImm0_15Instruction(MCInst *Inst, |
241 | | uint32_t insn, |
242 | | uint64_t Address, |
243 | | const void *Decoder); |
244 | | static DecodeStatus DecodeSystemPStateImm0_1Instruction(MCInst *Inst, |
245 | | uint32_t insn, |
246 | | uint64_t Address, |
247 | | const void *Decoder); |
248 | | static DecodeStatus DecodeTestAndBranch(MCInst *Inst, uint32_t insn, |
249 | | uint64_t Address, const void *Decoder); |
250 | | |
251 | | static DecodeStatus DecodeFMOVLaneInstruction(MCInst *Inst, unsigned Insn, |
252 | | uint64_t Address, |
253 | | const void *Decoder); |
254 | | static DecodeStatus DecodeVecShiftR64Imm(MCInst *Inst, unsigned Imm, |
255 | | uint64_t Addr, const void *Decoder); |
256 | | static DecodeStatus DecodeVecShiftR64ImmNarrow(MCInst *Inst, unsigned Imm, |
257 | | uint64_t Addr, |
258 | | const void *Decoder); |
259 | | static DecodeStatus DecodeVecShiftR32Imm(MCInst *Inst, unsigned Imm, |
260 | | uint64_t Addr, const void *Decoder); |
261 | | static DecodeStatus DecodeVecShiftR32ImmNarrow(MCInst *Inst, unsigned Imm, |
262 | | uint64_t Addr, |
263 | | const void *Decoder); |
264 | | static DecodeStatus DecodeVecShiftR16Imm(MCInst *Inst, unsigned Imm, |
265 | | uint64_t Addr, const void *Decoder); |
266 | | static DecodeStatus DecodeVecShiftR16ImmNarrow(MCInst *Inst, unsigned Imm, |
267 | | uint64_t Addr, |
268 | | const void *Decoder); |
269 | | static DecodeStatus DecodeVecShiftR8Imm(MCInst *Inst, unsigned Imm, |
270 | | uint64_t Addr, const void *Decoder); |
271 | | static DecodeStatus DecodeVecShiftL64Imm(MCInst *Inst, unsigned Imm, |
272 | | uint64_t Addr, const void *Decoder); |
273 | | static DecodeStatus DecodeVecShiftL32Imm(MCInst *Inst, unsigned Imm, |
274 | | uint64_t Addr, const void *Decoder); |
275 | | static DecodeStatus DecodeVecShiftL16Imm(MCInst *Inst, unsigned Imm, |
276 | | uint64_t Addr, const void *Decoder); |
277 | | static DecodeStatus DecodeVecShiftL8Imm(MCInst *Inst, unsigned Imm, |
278 | | uint64_t Addr, const void *Decoder); |
279 | | static DecodeStatus DecodeWSeqPairsClassRegisterClass(MCInst *Inst, |
280 | | unsigned RegNo, |
281 | | uint64_t Addr, |
282 | | const void *Decoder); |
283 | | static DecodeStatus DecodeXSeqPairsClassRegisterClass(MCInst *Inst, |
284 | | unsigned RegNo, |
285 | | uint64_t Addr, |
286 | | const void *Decoder); |
287 | | static DecodeStatus DecodeSyspXzrInstruction(MCInst *Inst, uint32_t insn, |
288 | | uint64_t Addr, |
289 | | const void *Decoder); |
290 | | static DecodeStatus DecodeSVELogicalImmInstruction(MCInst *Inst, uint32_t insn, |
291 | | uint64_t Address, |
292 | | const void *Decoder); |
293 | | #define DECLARE_DecodeSImm(Bits) \ |
294 | | static DecodeStatus CONCAT(DecodeSImm, Bits)(MCInst * Inst, \ |
295 | | uint64_t Imm, \ |
296 | | uint64_t Address, \ |
297 | | const void *Decoder); |
298 | | DECLARE_DecodeSImm(4); |
299 | | DECLARE_DecodeSImm(5); |
300 | | DECLARE_DecodeSImm(6); |
301 | | DECLARE_DecodeSImm(8); |
302 | | DECLARE_DecodeSImm(9); |
303 | | DECLARE_DecodeSImm(10); |
304 | | |
305 | | #define DECLARE_DecodeImm8OptLsl(ElementWidth) \ |
306 | | static DecodeStatus CONCAT(DecodeImm8OptLsl, ElementWidth)( \ |
307 | | MCInst * Inst, unsigned Imm, uint64_t Addr, \ |
308 | | const void *Decoder); |
309 | | DECLARE_DecodeImm8OptLsl(8); |
310 | | DECLARE_DecodeImm8OptLsl(16); |
311 | | DECLARE_DecodeImm8OptLsl(32); |
312 | | DECLARE_DecodeImm8OptLsl(64); |
313 | | |
314 | | static DecodeStatus DecodeSVEIncDecImm(MCInst *Inst, unsigned Imm, |
315 | | uint64_t Addr, const void *Decoder); |
316 | | static DecodeStatus DecodeSVCROp(MCInst *Inst, unsigned Imm, uint64_t Address, |
317 | | const void *Decoder); |
318 | | static DecodeStatus DecodeCPYMemOpInstruction(MCInst *Inst, uint32_t insn, |
319 | | uint64_t Addr, |
320 | | const void *Decoder); |
321 | | static DecodeStatus DecodeSETMemOpInstruction(MCInst *Inst, uint32_t insn, |
322 | | uint64_t Addr, |
323 | | const void *Decoder); |
324 | | static DecodeStatus DecodePRFMRegInstruction(MCInst *Inst, uint32_t insn, |
325 | | uint64_t Address, |
326 | | const void *Decoder); |
327 | | |
328 | | #include "AArch64GenDisassemblerTables.inc" |
329 | | |
330 | 543k | #define Success MCDisassembler_Success |
331 | 5.82k | #define Fail MCDisassembler_Fail |
332 | 720 | #define SoftFail MCDisassembler_SoftFail |
333 | | |
334 | | static DecodeStatus getInstruction(csh handle, const uint8_t *Bytes, |
335 | | size_t ByteLen, MCInst *MI, uint16_t *Size, |
336 | | uint64_t Address, void *Info) |
337 | 185k | { |
338 | 185k | *Size = 0; |
339 | | // We want to read exactly 4 bytes of data. |
340 | 185k | if (ByteLen < 4) |
341 | 2.65k | return Fail; |
342 | 183k | *Size = 4; |
343 | | |
344 | | // Encoded as a small-endian 32-bit word in the stream. |
345 | 183k | uint32_t Insn = readBytes32(MI, Bytes); |
346 | | |
347 | 183k | const uint8_t *Tables[] = { DecoderTable32, DecoderTableFallback32 }; |
348 | | |
349 | 190k | for (int i = 0; i < (sizeof(Tables) / sizeof(Tables[0])); ++i) { |
350 | 188k | void *Decoder = NULL; |
351 | 188k | DecodeStatus Result = decodeInstruction_4(Tables[i], MI, Insn, |
352 | 188k | Address, Decoder); |
353 | | |
354 | | // Table is indexed backwards |
355 | 188k | const MCInstrDesc Desc = |
356 | 188k | AArch64Descs.Insts[ARR_SIZE(AArch64Descs.Insts) - 1 - MCInst_getOpcode(MI)]; |
357 | | |
358 | | // For Scalable Matrix Extension (SME) instructions that have an |
359 | | // implicit operand for the accumulator (ZA) or implicit immediate zero |
360 | | // which isn't encoded, manually insert operand. |
361 | 839k | for (unsigned j = 0; j < Desc.NumOperands; j++) { |
362 | 650k | if (Desc.OpInfo[j].OperandType == |
363 | 650k | MCOI_OPERAND_REGISTER) { |
364 | 460k | switch (Desc.OpInfo[j].RegClass) { |
365 | 448k | default: |
366 | 448k | break; |
367 | 448k | case AArch64_MPRRegClassID: |
368 | 10.1k | MCInst_insert0(MI, j, |
369 | 10.1k | MCOperand_CreateReg1( |
370 | 10.1k | MI, AArch64_ZA)); |
371 | 10.1k | break; |
372 | 1.27k | case AArch64_MPR8RegClassID: |
373 | 1.27k | MCInst_insert0(MI, j, |
374 | 1.27k | MCOperand_CreateReg1( |
375 | 1.27k | MI, |
376 | 1.27k | AArch64_ZAB0)); |
377 | 1.27k | break; |
378 | 533 | case AArch64_ZTRRegClassID: |
379 | 533 | MCInst_insert0(MI, j, |
380 | 533 | MCOperand_CreateReg1( |
381 | 533 | MI, |
382 | 533 | AArch64_ZT0)); |
383 | 533 | break; |
384 | 460k | } |
385 | 460k | } else if (Desc.OpInfo[j].OperandType == |
386 | 189k | AARCH64_OP_IMPLICIT_IMM_0) { |
387 | 852 | MCInst_insert0(MI, j, |
388 | 852 | MCOperand_CreateImm1(MI, 0)); |
389 | 852 | } |
390 | 650k | } |
391 | | |
392 | 188k | if (MCInst_getOpcode(MI) == AArch64_LDR_ZA || |
393 | 188k | MCInst_getOpcode(MI) == AArch64_STR_ZA) { |
394 | | // Spill and fill instructions have a single immediate used for both |
395 | | // the vector select offset and optional memory offset. Replicate |
396 | | // the decoded immediate. |
397 | 58 | MCOperand *Imm4Op = MCInst_getOperand(MI, (2)); |
398 | | |
399 | 58 | MCInst_addOperand2(MI, (Imm4Op)); |
400 | 58 | } |
401 | | |
402 | 188k | if (Result != MCDisassembler_Fail) |
403 | 181k | return Result; |
404 | 188k | } |
405 | | |
406 | 1.56k | return MCDisassembler_Fail; |
407 | 183k | } |
408 | | |
409 | | DecodeStatus AArch64_LLVM_getInstruction(csh handle, const uint8_t *Bytes, |
410 | | size_t ByteLen, MCInst *MI, |
411 | | uint16_t *Size, uint64_t Address, |
412 | | void *Info) |
413 | 185k | { |
414 | 185k | DecodeStatus Result = MCDisassembler_Fail; |
415 | 185k | Result = |
416 | 185k | getInstruction(handle, Bytes, ByteLen, MI, Size, Address, Info); |
417 | 185k | MCInst_handleWriteback(MI, AArch64Descs.Insts, ARR_SIZE(AArch64Descs.Insts)); |
418 | 185k | return Result; |
419 | 185k | } |
420 | | |
421 | | uint64_t suggestBytesToSkip(const uint8_t *Bytes, uint64_t Address) |
422 | 0 | { |
423 | | // AArch64 instructions are always 4 bytes wide, so there's no point |
424 | | // in skipping any smaller number of bytes if an instruction can't |
425 | | // be decoded. |
426 | 0 | return 4; |
427 | 0 | } |
428 | | |
429 | | static DecodeStatus DecodeFPR128RegisterClass(MCInst *Inst, unsigned RegNo, |
430 | | uint64_t Addr, |
431 | | const void *Decoder) |
432 | 34.4k | { |
433 | 34.4k | if (RegNo > 31) |
434 | 0 | return Fail; |
435 | | |
436 | 34.4k | unsigned Register = AArch64MCRegisterClasses[AArch64_FPR128RegClassID] |
437 | 34.4k | .RegsBegin[RegNo]; |
438 | 34.4k | MCOperand_CreateReg0(Inst, (Register)); |
439 | 34.4k | return Success; |
440 | 34.4k | } |
441 | | |
442 | | static DecodeStatus DecodeFPR128_loRegisterClass(MCInst *Inst, unsigned RegNo, |
443 | | uint64_t Addr, |
444 | | const void *Decoder) |
445 | 870 | { |
446 | 870 | if (RegNo > 15) |
447 | 0 | return Fail; |
448 | 870 | return DecodeFPR128RegisterClass(Inst, RegNo, Addr, Decoder); |
449 | 870 | } |
450 | | |
451 | | static DecodeStatus DecodeFPR128_0to7RegisterClass(MCInst *Inst, unsigned RegNo, |
452 | | uint64_t Addr, |
453 | | const void *Decoder) |
454 | 29 | { |
455 | 29 | if (RegNo > 7) |
456 | 0 | return Fail; |
457 | 29 | return DecodeFPR128RegisterClass(Inst, RegNo, Addr, Decoder); |
458 | 29 | } |
459 | | |
460 | | static DecodeStatus DecodeFPR64RegisterClass(MCInst *Inst, unsigned RegNo, |
461 | | uint64_t Addr, const void *Decoder) |
462 | 19.8k | { |
463 | 19.8k | if (RegNo > 31) |
464 | 0 | return Fail; |
465 | | |
466 | 19.8k | unsigned Register = AArch64MCRegisterClasses[AArch64_FPR64RegClassID] |
467 | 19.8k | .RegsBegin[RegNo]; |
468 | 19.8k | MCOperand_CreateReg0(Inst, (Register)); |
469 | 19.8k | return Success; |
470 | 19.8k | } |
471 | | |
472 | | static DecodeStatus DecodeFPR32RegisterClass(MCInst *Inst, unsigned RegNo, |
473 | | uint64_t Addr, const void *Decoder) |
474 | 12.2k | { |
475 | 12.2k | if (RegNo > 31) |
476 | 0 | return Fail; |
477 | | |
478 | 12.2k | unsigned Register = AArch64MCRegisterClasses[AArch64_FPR32RegClassID] |
479 | 12.2k | .RegsBegin[RegNo]; |
480 | 12.2k | MCOperand_CreateReg0(Inst, (Register)); |
481 | 12.2k | return Success; |
482 | 12.2k | } |
483 | | |
484 | | static DecodeStatus DecodeFPR16RegisterClass(MCInst *Inst, unsigned RegNo, |
485 | | uint64_t Addr, const void *Decoder) |
486 | 8.48k | { |
487 | 8.48k | if (RegNo > 31) |
488 | 0 | return Fail; |
489 | | |
490 | 8.48k | unsigned Register = AArch64MCRegisterClasses[AArch64_FPR16RegClassID] |
491 | 8.48k | .RegsBegin[RegNo]; |
492 | 8.48k | MCOperand_CreateReg0(Inst, (Register)); |
493 | 8.48k | return Success; |
494 | 8.48k | } |
495 | | |
496 | | static DecodeStatus DecodeFPR8RegisterClass(MCInst *Inst, unsigned RegNo, |
497 | | uint64_t Addr, const void *Decoder) |
498 | 4.52k | { |
499 | 4.52k | if (RegNo > 31) |
500 | 0 | return Fail; |
501 | | |
502 | 4.52k | unsigned Register = AArch64MCRegisterClasses[AArch64_FPR8RegClassID] |
503 | 4.52k | .RegsBegin[RegNo]; |
504 | 4.52k | MCOperand_CreateReg0(Inst, (Register)); |
505 | 4.52k | return Success; |
506 | 4.52k | } |
507 | | |
508 | | static DecodeStatus DecodeGPR64commonRegisterClass(MCInst *Inst, unsigned RegNo, |
509 | | uint64_t Addr, |
510 | | const void *Decoder) |
511 | 3.13k | { |
512 | 3.13k | if (RegNo > 30) |
513 | 10 | return Fail; |
514 | | |
515 | 3.12k | unsigned Register = |
516 | 3.12k | AArch64MCRegisterClasses[AArch64_GPR64commonRegClassID] |
517 | 3.12k | .RegsBegin[RegNo]; |
518 | 3.12k | MCOperand_CreateReg0(Inst, (Register)); |
519 | 3.12k | return Success; |
520 | 3.13k | } |
521 | | |
522 | | static DecodeStatus DecodeGPR64RegisterClass(MCInst *Inst, unsigned RegNo, |
523 | | uint64_t Addr, const void *Decoder) |
524 | 70.5k | { |
525 | 70.5k | if (RegNo > 31) |
526 | 0 | return Fail; |
527 | | |
528 | 70.5k | unsigned Register = AArch64MCRegisterClasses[AArch64_GPR64RegClassID] |
529 | 70.5k | .RegsBegin[RegNo]; |
530 | 70.5k | MCOperand_CreateReg0(Inst, (Register)); |
531 | 70.5k | return Success; |
532 | 70.5k | } |
533 | | |
534 | | static DecodeStatus DecodeGPR64x8ClassRegisterClass(MCInst *Inst, |
535 | | unsigned RegNo, |
536 | | uint64_t Address, |
537 | | const void *Decoder) |
538 | 31 | { |
539 | 31 | if (RegNo > 22) |
540 | 2 | return Fail; |
541 | 29 | if (RegNo & 1) |
542 | 3 | return Fail; |
543 | | |
544 | 26 | unsigned Register = |
545 | 26 | AArch64MCRegisterClasses[AArch64_GPR64x8ClassRegClassID] |
546 | 26 | .RegsBegin[RegNo >> 1]; |
547 | 26 | MCOperand_CreateReg0(Inst, (Register)); |
548 | 26 | return Success; |
549 | 29 | } |
550 | | |
551 | | static DecodeStatus DecodeGPR64spRegisterClass(MCInst *Inst, unsigned RegNo, |
552 | | uint64_t Addr, |
553 | | const void *Decoder) |
554 | 87.5k | { |
555 | 87.5k | if (RegNo > 31) |
556 | 0 | return Fail; |
557 | 87.5k | unsigned Register = AArch64MCRegisterClasses[AArch64_GPR64spRegClassID] |
558 | 87.5k | .RegsBegin[RegNo]; |
559 | 87.5k | MCOperand_CreateReg0(Inst, (Register)); |
560 | 87.5k | return Success; |
561 | 87.5k | } |
562 | | |
563 | | static DecodeStatus |
564 | | DecodeMatrixIndexGPR32_8_11RegisterClass(MCInst *Inst, unsigned RegNo, |
565 | | uint64_t Addr, const void *Decoder) |
566 | 5.15k | { |
567 | 5.15k | if (RegNo > 3) |
568 | 0 | return Fail; |
569 | | |
570 | 5.15k | unsigned Register = |
571 | 5.15k | AArch64MCRegisterClasses[AArch64_MatrixIndexGPR32_8_11RegClassID] |
572 | 5.15k | .RegsBegin[RegNo]; |
573 | 5.15k | MCOperand_CreateReg0(Inst, (Register)); |
574 | 5.15k | return Success; |
575 | 5.15k | } |
576 | | |
577 | | static DecodeStatus |
578 | | DecodeMatrixIndexGPR32_12_15RegisterClass(MCInst *Inst, unsigned RegNo, |
579 | | uint64_t Addr, const void *Decoder) |
580 | 3.91k | { |
581 | 3.91k | if (RegNo > 3) |
582 | 0 | return Fail; |
583 | | |
584 | 3.91k | unsigned Register = |
585 | 3.91k | AArch64MCRegisterClasses[AArch64_MatrixIndexGPR32_12_15RegClassID] |
586 | 3.91k | .RegsBegin[RegNo]; |
587 | 3.91k | MCOperand_CreateReg0(Inst, (Register)); |
588 | 3.91k | return Success; |
589 | 3.91k | } |
590 | | |
591 | | static DecodeStatus DecodeGPR32RegisterClass(MCInst *Inst, unsigned RegNo, |
592 | | uint64_t Addr, const void *Decoder) |
593 | 36.6k | { |
594 | 36.6k | if (RegNo > 31) |
595 | 0 | return Fail; |
596 | | |
597 | 36.6k | unsigned Register = AArch64MCRegisterClasses[AArch64_GPR32RegClassID] |
598 | 36.6k | .RegsBegin[RegNo]; |
599 | 36.6k | MCOperand_CreateReg0(Inst, (Register)); |
600 | 36.6k | return Success; |
601 | 36.6k | } |
602 | | |
603 | | static DecodeStatus DecodeGPR32spRegisterClass(MCInst *Inst, unsigned RegNo, |
604 | | uint64_t Addr, |
605 | | const void *Decoder) |
606 | 3.36k | { |
607 | 3.36k | if (RegNo > 31) |
608 | 0 | return Fail; |
609 | | |
610 | 3.36k | unsigned Register = AArch64MCRegisterClasses[AArch64_GPR32spRegClassID] |
611 | 3.36k | .RegsBegin[RegNo]; |
612 | 3.36k | MCOperand_CreateReg0(Inst, (Register)); |
613 | 3.36k | return Success; |
614 | 3.36k | } |
615 | | |
616 | | static DecodeStatus DecodeZPRRegisterClass(MCInst *Inst, unsigned RegNo, |
617 | | uint64_t Address, |
618 | | const void *Decoder) |
619 | 92.9k | { |
620 | 92.9k | if (RegNo > 31) |
621 | 0 | return Fail; |
622 | | |
623 | 92.9k | unsigned Register = |
624 | 92.9k | AArch64MCRegisterClasses[AArch64_ZPRRegClassID].RegsBegin[RegNo]; |
625 | 92.9k | MCOperand_CreateReg0(Inst, (Register)); |
626 | 92.9k | return Success; |
627 | 92.9k | } |
628 | | |
629 | | static DecodeStatus DecodeZPR_4bRegisterClass(MCInst *Inst, unsigned RegNo, |
630 | | uint64_t Address, |
631 | | const void *Decoder) |
632 | 5.16k | { |
633 | 5.16k | if (RegNo > 15) |
634 | 0 | return Fail; |
635 | 5.16k | return DecodeZPRRegisterClass(Inst, RegNo, Address, Decoder); |
636 | 5.16k | } |
637 | | |
638 | | static DecodeStatus DecodeZPR_3bRegisterClass(MCInst *Inst, unsigned RegNo, |
639 | | uint64_t Address, |
640 | | const void *Decoder) |
641 | 930 | { |
642 | 930 | if (RegNo > 7) |
643 | 0 | return Fail; |
644 | 930 | return DecodeZPRRegisterClass(Inst, RegNo, Address, Decoder); |
645 | 930 | } |
646 | | |
647 | | static DecodeStatus DecodeZPR2RegisterClass(MCInst *Inst, unsigned RegNo, |
648 | | uint64_t Address, |
649 | | const void *Decoder) |
650 | 982 | { |
651 | 982 | if (RegNo > 31) |
652 | 0 | return Fail; |
653 | 982 | unsigned Register = AArch64MCRegisterClasses[AArch64_ZPR2RegClassID] |
654 | 982 | .RegsBegin[RegNo]; |
655 | 982 | MCOperand_CreateReg0(Inst, (Register)); |
656 | 982 | return Success; |
657 | 982 | } |
658 | | |
659 | | static DecodeStatus DecodeZPR3RegisterClass(MCInst *Inst, unsigned RegNo, |
660 | | uint64_t Address, |
661 | | const void *Decoder) |
662 | 142 | { |
663 | 142 | if (RegNo > 31) |
664 | 0 | return Fail; |
665 | 142 | unsigned Register = AArch64MCRegisterClasses[AArch64_ZPR3RegClassID] |
666 | 142 | .RegsBegin[RegNo]; |
667 | 142 | MCOperand_CreateReg0(Inst, (Register)); |
668 | 142 | return Success; |
669 | 142 | } |
670 | | |
671 | | static DecodeStatus DecodeZPR4RegisterClass(MCInst *Inst, unsigned RegNo, |
672 | | uint64_t Address, |
673 | | const void *Decoder) |
674 | 1.02k | { |
675 | 1.02k | if (RegNo > 31) |
676 | 0 | return Fail; |
677 | 1.02k | unsigned Register = AArch64MCRegisterClasses[AArch64_ZPR4RegClassID] |
678 | 1.02k | .RegsBegin[RegNo]; |
679 | 1.02k | MCOperand_CreateReg0(Inst, (Register)); |
680 | 1.02k | return Success; |
681 | 1.02k | } |
682 | | |
683 | | static DecodeStatus DecodeZPR2Mul2RegisterClass(MCInst *Inst, unsigned RegNo, |
684 | | uint64_t Address, |
685 | | const void *Decoder) |
686 | 4.54k | { |
687 | 4.54k | if (RegNo * 2 > 30) |
688 | 0 | return Fail; |
689 | 4.54k | unsigned Register = AArch64MCRegisterClasses[AArch64_ZPR2RegClassID] |
690 | 4.54k | .RegsBegin[RegNo * 2]; |
691 | 4.54k | MCOperand_CreateReg0(Inst, (Register)); |
692 | 4.54k | return Success; |
693 | 4.54k | } |
694 | | |
695 | | static DecodeStatus DecodeZPR4Mul4RegisterClass(MCInst *Inst, unsigned RegNo, |
696 | | uint64_t Address, |
697 | | const void *Decoder) |
698 | 2.79k | { |
699 | 2.79k | if (RegNo * 4 > 28) |
700 | 0 | return Fail; |
701 | 2.79k | unsigned Register = AArch64MCRegisterClasses[AArch64_ZPR4RegClassID] |
702 | 2.79k | .RegsBegin[RegNo * 4]; |
703 | 2.79k | MCOperand_CreateReg0(Inst, (Register)); |
704 | 2.79k | return Success; |
705 | 2.79k | } |
706 | | |
707 | | static DecodeStatus DecodeZPR2StridedRegisterClass(MCInst *Inst, unsigned RegNo, |
708 | | uint64_t Address, |
709 | | const void *Decoder) |
710 | 979 | { |
711 | 979 | if (RegNo > 15) |
712 | 0 | return Fail; |
713 | 979 | unsigned Register = |
714 | 979 | AArch64MCRegisterClasses[AArch64_ZPR2StridedRegClassID] |
715 | 979 | .RegsBegin[RegNo]; |
716 | 979 | MCOperand_CreateReg0(Inst, (Register)); |
717 | 979 | return Success; |
718 | 979 | } |
719 | | |
720 | | static DecodeStatus DecodeZPR4StridedRegisterClass(MCInst *Inst, unsigned RegNo, |
721 | | uint64_t Address, |
722 | | const void *Decoder) |
723 | 629 | { |
724 | 629 | if (RegNo > 7) |
725 | 0 | return Fail; |
726 | 629 | unsigned Register = |
727 | 629 | AArch64MCRegisterClasses[AArch64_ZPR4StridedRegClassID] |
728 | 629 | .RegsBegin[RegNo]; |
729 | 629 | MCOperand_CreateReg0(Inst, (Register)); |
730 | 629 | return Success; |
731 | 629 | } |
732 | | |
733 | | static DecodeStatus DecodeMatrixTileListRegisterClass(MCInst *Inst, |
734 | | unsigned RegMask, |
735 | | uint64_t Address, |
736 | | const void *Decoder) |
737 | 1.04k | { |
738 | 1.04k | if (RegMask > 0xFF) |
739 | 0 | return Fail; |
740 | 1.04k | MCOperand_CreateImm0(Inst, (RegMask)); |
741 | 1.04k | return Success; |
742 | 1.04k | } |
743 | | |
744 | | static const MCPhysReg MatrixZATileDecoderTable[5][16] = { |
745 | | { AArch64_ZAB0 }, |
746 | | { AArch64_ZAH0, AArch64_ZAH1 }, |
747 | | { AArch64_ZAS0, AArch64_ZAS1, AArch64_ZAS2, AArch64_ZAS3 }, |
748 | | { AArch64_ZAD0, AArch64_ZAD1, AArch64_ZAD2, AArch64_ZAD3, AArch64_ZAD4, |
749 | | AArch64_ZAD5, AArch64_ZAD6, AArch64_ZAD7 }, |
750 | | { AArch64_ZAQ0, AArch64_ZAQ1, AArch64_ZAQ2, AArch64_ZAQ3, AArch64_ZAQ4, |
751 | | AArch64_ZAQ5, AArch64_ZAQ6, AArch64_ZAQ7, AArch64_ZAQ8, AArch64_ZAQ9, |
752 | | AArch64_ZAQ10, AArch64_ZAQ11, AArch64_ZAQ12, AArch64_ZAQ13, |
753 | | AArch64_ZAQ14, AArch64_ZAQ15 } |
754 | | }; |
755 | | |
756 | | #define DEFINE_DecodeMatrixTile(NumBitsForTile) \ |
757 | | static DecodeStatus CONCAT(DecodeMatrixTile, NumBitsForTile)( \ |
758 | | MCInst * Inst, unsigned RegNo, uint64_t Address, \ |
759 | | const void *Decoder) \ |
760 | 7.25k | { \ |
761 | 7.25k | unsigned LastReg = (1 << NumBitsForTile) - 1; \ |
762 | 7.25k | if (RegNo > LastReg) \ |
763 | 7.25k | return Fail; \ |
764 | 7.25k | MCOperand_CreateReg0( \ |
765 | 7.25k | Inst, \ |
766 | 7.25k | (MatrixZATileDecoderTable[NumBitsForTile][RegNo])); \ |
767 | 7.25k | return Success; \ |
768 | 7.25k | } AArch64Disassembler.c:DecodeMatrixTile_2 Line | Count | Source | 760 | 2.66k | { \ | 761 | 2.66k | unsigned LastReg = (1 << NumBitsForTile) - 1; \ | 762 | 2.66k | if (RegNo > LastReg) \ | 763 | 2.66k | return Fail; \ | 764 | 2.66k | MCOperand_CreateReg0( \ | 765 | 2.66k | Inst, \ | 766 | 2.66k | (MatrixZATileDecoderTable[NumBitsForTile][RegNo])); \ | 767 | 2.66k | return Success; \ | 768 | 2.66k | } |
AArch64Disassembler.c:DecodeMatrixTile_1 Line | Count | Source | 760 | 613 | { \ | 761 | 613 | unsigned LastReg = (1 << NumBitsForTile) - 1; \ | 762 | 613 | if (RegNo > LastReg) \ | 763 | 613 | return Fail; \ | 764 | 613 | MCOperand_CreateReg0( \ | 765 | 613 | Inst, \ | 766 | 613 | (MatrixZATileDecoderTable[NumBitsForTile][RegNo])); \ | 767 | 613 | return Success; \ | 768 | 613 | } |
AArch64Disassembler.c:DecodeMatrixTile_3 Line | Count | Source | 760 | 3.41k | { \ | 761 | 3.41k | unsigned LastReg = (1 << NumBitsForTile) - 1; \ | 762 | 3.41k | if (RegNo > LastReg) \ | 763 | 3.41k | return Fail; \ | 764 | 3.41k | MCOperand_CreateReg0( \ | 765 | 3.41k | Inst, \ | 766 | 3.41k | (MatrixZATileDecoderTable[NumBitsForTile][RegNo])); \ | 767 | 3.41k | return Success; \ | 768 | 3.41k | } |
AArch64Disassembler.c:DecodeMatrixTile_4 Line | Count | Source | 760 | 564 | { \ | 761 | 564 | unsigned LastReg = (1 << NumBitsForTile) - 1; \ | 762 | 564 | if (RegNo > LastReg) \ | 763 | 564 | return Fail; \ | 764 | 564 | MCOperand_CreateReg0( \ | 765 | 564 | Inst, \ | 766 | 564 | (MatrixZATileDecoderTable[NumBitsForTile][RegNo])); \ | 767 | 564 | return Success; \ | 768 | 564 | } |
|
769 | | DEFINE_DecodeMatrixTile(2); |
770 | | DEFINE_DecodeMatrixTile(1); |
771 | | DEFINE_DecodeMatrixTile(3); |
772 | | DEFINE_DecodeMatrixTile(4); |
773 | | |
774 | | static DecodeStatus DecodePPRRegisterClass(MCInst *Inst, unsigned RegNo, |
775 | | uint64_t Addr, const void *Decoder) |
776 | 30.9k | { |
777 | 30.9k | if (RegNo > 15) |
778 | 0 | return Fail; |
779 | | |
780 | 30.9k | unsigned Register = |
781 | 30.9k | AArch64MCRegisterClasses[AArch64_PPRRegClassID].RegsBegin[RegNo]; |
782 | 30.9k | MCOperand_CreateReg0(Inst, (Register)); |
783 | 30.9k | return Success; |
784 | 30.9k | } |
785 | | |
786 | | static DecodeStatus DecodePNRRegisterClass(MCInst *Inst, unsigned RegNo, |
787 | | uint64_t Addr, const void *Decoder) |
788 | 3.59k | { |
789 | 3.59k | if (RegNo > 15) |
790 | 0 | return Fail; |
791 | | |
792 | 3.59k | unsigned Register = |
793 | 3.59k | AArch64MCRegisterClasses[AArch64_PNRRegClassID].RegsBegin[RegNo]; |
794 | 3.59k | MCOperand_CreateReg0(Inst, (Register)); |
795 | 3.59k | return Success; |
796 | 3.59k | } |
797 | | |
798 | | static DecodeStatus DecodePPR_3bRegisterClass(MCInst *Inst, unsigned RegNo, |
799 | | uint64_t Addr, |
800 | | const void *Decoder) |
801 | 25.0k | { |
802 | 25.0k | if (RegNo > 7) |
803 | 0 | return Fail; |
804 | | |
805 | | // Just reuse the PPR decode table |
806 | 25.0k | return DecodePPRRegisterClass(Inst, RegNo, Addr, Decoder); |
807 | 25.0k | } |
808 | | |
809 | | static DecodeStatus DecodePNR_p8to15RegisterClass(MCInst *Inst, unsigned RegNo, |
810 | | uint64_t Addr, |
811 | | const void *Decoder) |
812 | 3.48k | { |
813 | 3.48k | if (RegNo > 7) |
814 | 0 | return Fail; |
815 | | |
816 | | // Just reuse the PPR decode table |
817 | 3.48k | return DecodePNRRegisterClass(Inst, RegNo + 8, Addr, Decoder); |
818 | 3.48k | } |
819 | | |
820 | | static DecodeStatus DecodePPR2RegisterClass(MCInst *Inst, unsigned RegNo, |
821 | | uint64_t Address, |
822 | | const void *Decoder) |
823 | 229 | { |
824 | 229 | if (RegNo > 15) |
825 | 0 | return Fail; |
826 | | |
827 | 229 | unsigned Register = AArch64MCRegisterClasses[AArch64_PPR2RegClassID] |
828 | 229 | .RegsBegin[RegNo]; |
829 | 229 | MCOperand_CreateReg0(Inst, (Register)); |
830 | 229 | return Success; |
831 | 229 | } |
832 | | |
833 | | static DecodeStatus DecodePPR2Mul2RegisterClass(MCInst *Inst, unsigned RegNo, |
834 | | uint64_t Address, |
835 | | const void *Decoder) |
836 | 119 | { |
837 | 119 | if ((RegNo * 2) > 14) |
838 | 0 | return Fail; |
839 | 119 | unsigned Register = AArch64MCRegisterClasses[AArch64_PPR2RegClassID] |
840 | 119 | .RegsBegin[RegNo * 2]; |
841 | 119 | MCOperand_CreateReg0(Inst, (Register)); |
842 | 119 | return Success; |
843 | 119 | } |
844 | | |
845 | | static DecodeStatus DecodeQQRegisterClass(MCInst *Inst, unsigned RegNo, |
846 | | uint64_t Addr, const void *Decoder) |
847 | 5.09k | { |
848 | 5.09k | if (RegNo > 31) |
849 | 0 | return Fail; |
850 | 5.09k | unsigned Register = |
851 | 5.09k | AArch64MCRegisterClasses[AArch64_QQRegClassID].RegsBegin[RegNo]; |
852 | 5.09k | MCOperand_CreateReg0(Inst, (Register)); |
853 | 5.09k | return Success; |
854 | 5.09k | } |
855 | | |
856 | | static DecodeStatus DecodeQQQRegisterClass(MCInst *Inst, unsigned RegNo, |
857 | | uint64_t Addr, const void *Decoder) |
858 | 4.03k | { |
859 | 4.03k | if (RegNo > 31) |
860 | 0 | return Fail; |
861 | 4.03k | unsigned Register = |
862 | 4.03k | AArch64MCRegisterClasses[AArch64_QQQRegClassID].RegsBegin[RegNo]; |
863 | 4.03k | MCOperand_CreateReg0(Inst, (Register)); |
864 | 4.03k | return Success; |
865 | 4.03k | } |
866 | | |
867 | | static DecodeStatus DecodeQQQQRegisterClass(MCInst *Inst, unsigned RegNo, |
868 | | uint64_t Addr, const void *Decoder) |
869 | 5.55k | { |
870 | 5.55k | if (RegNo > 31) |
871 | 0 | return Fail; |
872 | 5.55k | unsigned Register = AArch64MCRegisterClasses[AArch64_QQQQRegClassID] |
873 | 5.55k | .RegsBegin[RegNo]; |
874 | 5.55k | MCOperand_CreateReg0(Inst, (Register)); |
875 | 5.55k | return Success; |
876 | 5.55k | } |
877 | | |
878 | | static DecodeStatus DecodeDDRegisterClass(MCInst *Inst, unsigned RegNo, |
879 | | uint64_t Addr, const void *Decoder) |
880 | 339 | { |
881 | 339 | if (RegNo > 31) |
882 | 0 | return Fail; |
883 | 339 | unsigned Register = |
884 | 339 | AArch64MCRegisterClasses[AArch64_DDRegClassID].RegsBegin[RegNo]; |
885 | 339 | MCOperand_CreateReg0(Inst, (Register)); |
886 | 339 | return Success; |
887 | 339 | } |
888 | | |
889 | | static DecodeStatus DecodeDDDRegisterClass(MCInst *Inst, unsigned RegNo, |
890 | | uint64_t Addr, const void *Decoder) |
891 | 717 | { |
892 | 717 | if (RegNo > 31) |
893 | 0 | return Fail; |
894 | 717 | unsigned Register = |
895 | 717 | AArch64MCRegisterClasses[AArch64_DDDRegClassID].RegsBegin[RegNo]; |
896 | 717 | MCOperand_CreateReg0(Inst, (Register)); |
897 | 717 | return Success; |
898 | 717 | } |
899 | | |
900 | | static DecodeStatus DecodeDDDDRegisterClass(MCInst *Inst, unsigned RegNo, |
901 | | uint64_t Addr, const void *Decoder) |
902 | 375 | { |
903 | 375 | if (RegNo > 31) |
904 | 0 | return Fail; |
905 | 375 | unsigned Register = AArch64MCRegisterClasses[AArch64_DDDDRegClassID] |
906 | 375 | .RegsBegin[RegNo]; |
907 | 375 | MCOperand_CreateReg0(Inst, (Register)); |
908 | 375 | return Success; |
909 | 375 | } |
910 | | |
911 | | static DecodeStatus DecodeFixedPointScaleImm32(MCInst *Inst, unsigned Imm, |
912 | | uint64_t Addr, |
913 | | const void *Decoder) |
914 | 96 | { |
915 | | // scale{5} is asserted as 1 in tblgen. |
916 | 96 | Imm |= 0x20; |
917 | 96 | MCOperand_CreateImm0(Inst, (64 - Imm)); |
918 | 96 | return Success; |
919 | 96 | } |
920 | | |
921 | | static DecodeStatus DecodeFixedPointScaleImm64(MCInst *Inst, unsigned Imm, |
922 | | uint64_t Addr, |
923 | | const void *Decoder) |
924 | 232 | { |
925 | 232 | MCOperand_CreateImm0(Inst, (64 - Imm)); |
926 | 232 | return Success; |
927 | 232 | } |
928 | | |
929 | | static DecodeStatus DecodePCRelLabel16(MCInst *Inst, unsigned Imm, |
930 | | uint64_t Addr, const void *Decoder) |
931 | 65 | { |
932 | | // Immediate is encoded as the top 16-bits of an unsigned 18-bit negative |
933 | | // PC-relative offset. |
934 | 65 | uint64_t ImmVal = Imm; |
935 | 65 | if (ImmVal > (1 << 16)) |
936 | 0 | return Fail; |
937 | | // Symbols are not supported by Capstone |
938 | 65 | return Success; |
939 | 65 | } |
940 | | |
941 | | static DecodeStatus DecodePCRelLabel19(MCInst *Inst, unsigned Imm, |
942 | | uint64_t Addr, const void *Decoder) |
943 | 5.70k | { |
944 | 5.70k | int64_t ImmVal = Imm; |
945 | | |
946 | | // Sign-extend 19-bit immediate. |
947 | 5.70k | if (ImmVal & (1 << (19 - 1))) |
948 | 2.33k | ImmVal |= ~((1LL << 19) - 1); |
949 | | |
950 | | // No symbols supported in Capstone |
951 | | // if (!Decoder->tryAddingSymbolicOperand( |
952 | | // Inst, ImmVal * 4, Addr, MCInst_getOpcode(Inst) != AArch64_LDRXl, 0, |
953 | | // 0, 4)) |
954 | 5.70k | MCOperand_CreateImm0(Inst, (ImmVal)); |
955 | 5.70k | return Success; |
956 | 5.70k | } |
957 | | |
958 | | static DecodeStatus DecodeMemExtend(MCInst *Inst, unsigned Imm, |
959 | | uint64_t Address, const void *Decoder) |
960 | 3.53k | { |
961 | 3.53k | MCOperand_CreateImm0(Inst, ((Imm >> 1) & 1)); |
962 | 3.53k | MCOperand_CreateImm0(Inst, (Imm & 1)); |
963 | 3.53k | return Success; |
964 | 3.53k | } |
965 | | |
966 | | static DecodeStatus DecodeMRSSystemRegister(MCInst *Inst, unsigned Imm, |
967 | | uint64_t Address, |
968 | | const void *Decoder) |
969 | 1.15k | { |
970 | 1.15k | MCOperand_CreateImm0(Inst, (Imm)); |
971 | | |
972 | | // Every system register in the encoding space is valid with the syntax |
973 | | // S<op0>_<op1>_<Cn>_<Cm>_<op2>, so decoding system registers always |
974 | | // succeeds. |
975 | 1.15k | return Success; |
976 | 1.15k | } |
977 | | |
978 | | static DecodeStatus DecodeMSRSystemRegister(MCInst *Inst, unsigned Imm, |
979 | | uint64_t Address, |
980 | | const void *Decoder) |
981 | 2.91k | { |
982 | 2.91k | MCOperand_CreateImm0(Inst, (Imm)); |
983 | | |
984 | 2.91k | return Success; |
985 | 2.91k | } |
986 | | |
987 | | static DecodeStatus DecodeFMOVLaneInstruction(MCInst *Inst, unsigned Insn, |
988 | | uint64_t Address, |
989 | | const void *Decoder) |
990 | 30 | { |
991 | | // This decoder exists to add the dummy Lane operand to the MCInst, which |
992 | | // must be 1 in assembly but has no other real manifestation. |
993 | 30 | unsigned Rd = fieldFromInstruction_4(Insn, 0, 5); |
994 | 30 | unsigned Rn = fieldFromInstruction_4(Insn, 5, 5); |
995 | 30 | unsigned IsToVec = fieldFromInstruction_4(Insn, 16, 1); |
996 | | |
997 | 30 | if (IsToVec) { |
998 | 8 | DecodeFPR128RegisterClass(Inst, Rd, Address, Decoder); |
999 | 8 | DecodeGPR64RegisterClass(Inst, Rn, Address, Decoder); |
1000 | 22 | } else { |
1001 | 22 | DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder); |
1002 | 22 | DecodeFPR128RegisterClass(Inst, Rn, Address, Decoder); |
1003 | 22 | } |
1004 | | |
1005 | | // Add the lane |
1006 | 30 | MCOperand_CreateImm0(Inst, (1)); |
1007 | | |
1008 | 30 | return Success; |
1009 | 30 | } |
1010 | | |
1011 | | static DecodeStatus DecodeVecShiftRImm(MCInst *Inst, unsigned Imm, unsigned Add) |
1012 | 2.40k | { |
1013 | 2.40k | MCOperand_CreateImm0(Inst, (Add - Imm)); |
1014 | 2.40k | return Success; |
1015 | 2.40k | } |
1016 | | |
1017 | | static DecodeStatus DecodeVecShiftLImm(MCInst *Inst, unsigned Imm, unsigned Add) |
1018 | 2.70k | { |
1019 | 2.70k | MCOperand_CreateImm0(Inst, ((Imm + Add) & (Add - 1))); |
1020 | 2.70k | return Success; |
1021 | 2.70k | } |
1022 | | |
1023 | | static DecodeStatus DecodeVecShiftR64Imm(MCInst *Inst, unsigned Imm, |
1024 | | uint64_t Addr, const void *Decoder) |
1025 | 303 | { |
1026 | 303 | return DecodeVecShiftRImm(Inst, Imm, 64); |
1027 | 303 | } |
1028 | | |
1029 | | static DecodeStatus DecodeVecShiftR64ImmNarrow(MCInst *Inst, unsigned Imm, |
1030 | | uint64_t Addr, |
1031 | | const void *Decoder) |
1032 | 494 | { |
1033 | 494 | return DecodeVecShiftRImm(Inst, Imm | 0x20, 64); |
1034 | 494 | } |
1035 | | |
1036 | | static DecodeStatus DecodeVecShiftR32Imm(MCInst *Inst, unsigned Imm, |
1037 | | uint64_t Addr, const void *Decoder) |
1038 | 266 | { |
1039 | 266 | return DecodeVecShiftRImm(Inst, Imm, 32); |
1040 | 266 | } |
1041 | | |
1042 | | static DecodeStatus DecodeVecShiftR32ImmNarrow(MCInst *Inst, unsigned Imm, |
1043 | | uint64_t Addr, |
1044 | | const void *Decoder) |
1045 | 20 | { |
1046 | 20 | return DecodeVecShiftRImm(Inst, Imm | 0x10, 32); |
1047 | 20 | } |
1048 | | |
1049 | | static DecodeStatus DecodeVecShiftR16Imm(MCInst *Inst, unsigned Imm, |
1050 | | uint64_t Addr, const void *Decoder) |
1051 | 549 | { |
1052 | 549 | return DecodeVecShiftRImm(Inst, Imm, 16); |
1053 | 549 | } |
1054 | | |
1055 | | static DecodeStatus DecodeVecShiftR16ImmNarrow(MCInst *Inst, unsigned Imm, |
1056 | | uint64_t Addr, |
1057 | | const void *Decoder) |
1058 | 64 | { |
1059 | 64 | return DecodeVecShiftRImm(Inst, Imm | 0x8, 16); |
1060 | 64 | } |
1061 | | |
1062 | | static DecodeStatus DecodeVecShiftR8Imm(MCInst *Inst, unsigned Imm, |
1063 | | uint64_t Addr, const void *Decoder) |
1064 | 709 | { |
1065 | 709 | return DecodeVecShiftRImm(Inst, Imm, 8); |
1066 | 709 | } |
1067 | | |
1068 | | static DecodeStatus DecodeVecShiftL64Imm(MCInst *Inst, unsigned Imm, |
1069 | | uint64_t Addr, const void *Decoder) |
1070 | 269 | { |
1071 | 269 | return DecodeVecShiftLImm(Inst, Imm, 64); |
1072 | 269 | } |
1073 | | |
1074 | | static DecodeStatus DecodeVecShiftL32Imm(MCInst *Inst, unsigned Imm, |
1075 | | uint64_t Addr, const void *Decoder) |
1076 | 264 | { |
1077 | 264 | return DecodeVecShiftLImm(Inst, Imm, 32); |
1078 | 264 | } |
1079 | | |
1080 | | static DecodeStatus DecodeVecShiftL16Imm(MCInst *Inst, unsigned Imm, |
1081 | | uint64_t Addr, const void *Decoder) |
1082 | 1.02k | { |
1083 | 1.02k | return DecodeVecShiftLImm(Inst, Imm, 16); |
1084 | 1.02k | } |
1085 | | |
1086 | | static DecodeStatus DecodeVecShiftL8Imm(MCInst *Inst, unsigned Imm, |
1087 | | uint64_t Addr, const void *Decoder) |
1088 | 1.14k | { |
1089 | 1.14k | return DecodeVecShiftLImm(Inst, Imm, 8); |
1090 | 1.14k | } |
1091 | | |
1092 | | static DecodeStatus DecodeThreeAddrSRegInstruction(MCInst *Inst, uint32_t insn, |
1093 | | uint64_t Addr, |
1094 | | const void *Decoder) |
1095 | 4.73k | { |
1096 | 4.73k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1097 | 4.73k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1098 | 4.73k | unsigned Rm = fieldFromInstruction_4(insn, 16, 5); |
1099 | 4.73k | unsigned shiftHi = fieldFromInstruction_4(insn, 22, 2); |
1100 | 4.73k | unsigned shiftLo = fieldFromInstruction_4(insn, 10, 6); |
1101 | 4.73k | unsigned shift = (shiftHi << 6) | shiftLo; |
1102 | 4.73k | switch (MCInst_getOpcode(Inst)) { |
1103 | 0 | default: |
1104 | 0 | return Fail; |
1105 | 244 | case AArch64_ADDWrs: |
1106 | 372 | case AArch64_ADDSWrs: |
1107 | 632 | case AArch64_SUBWrs: |
1108 | 702 | case AArch64_SUBSWrs: |
1109 | | // if shift == '11' then ReservedValue() |
1110 | 702 | if (shiftHi == 0x3) |
1111 | 4 | return Fail; |
1112 | | // fall through |
1113 | 1.00k | case AArch64_ANDWrs: |
1114 | 1.04k | case AArch64_ANDSWrs: |
1115 | 1.09k | case AArch64_BICWrs: |
1116 | 1.29k | case AArch64_BICSWrs: |
1117 | 1.49k | case AArch64_ORRWrs: |
1118 | 1.91k | case AArch64_ORNWrs: |
1119 | 2.24k | case AArch64_EORWrs: |
1120 | 2.27k | case AArch64_EONWrs: { |
1121 | | // if sf == '0' and imm6<5> == '1' then ReservedValue() |
1122 | 2.27k | if (shiftLo >> 5 == 1) |
1123 | 20 | return Fail; |
1124 | 2.25k | DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder); |
1125 | 2.25k | DecodeGPR32RegisterClass(Inst, Rn, Addr, Decoder); |
1126 | 2.25k | DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder); |
1127 | 2.25k | break; |
1128 | 2.27k | } |
1129 | 177 | case AArch64_ADDXrs: |
1130 | 270 | case AArch64_ADDSXrs: |
1131 | 299 | case AArch64_SUBXrs: |
1132 | 465 | case AArch64_SUBSXrs: |
1133 | | // if shift == '11' then ReservedValue() |
1134 | 465 | if (shiftHi == 0x3) |
1135 | 5 | return Fail; |
1136 | | // fall through |
1137 | 881 | case AArch64_ANDXrs: |
1138 | 1.10k | case AArch64_ANDSXrs: |
1139 | 1.31k | case AArch64_BICXrs: |
1140 | 1.45k | case AArch64_BICSXrs: |
1141 | 1.54k | case AArch64_ORRXrs: |
1142 | 1.69k | case AArch64_ORNXrs: |
1143 | 2.18k | case AArch64_EORXrs: |
1144 | 2.44k | case AArch64_EONXrs: |
1145 | 2.44k | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1146 | 2.44k | DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder); |
1147 | 2.44k | DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder); |
1148 | 2.44k | break; |
1149 | 4.73k | } |
1150 | | |
1151 | 4.70k | MCOperand_CreateImm0(Inst, (shift)); |
1152 | 4.70k | return Success; |
1153 | 4.73k | } |
1154 | | |
1155 | | static DecodeStatus DecodeMoveImmInstruction(MCInst *Inst, uint32_t insn, |
1156 | | uint64_t Addr, const void *Decoder) |
1157 | 2.09k | { |
1158 | 2.09k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1159 | 2.09k | unsigned imm = fieldFromInstruction_4(insn, 5, 16); |
1160 | 2.09k | unsigned shift = fieldFromInstruction_4(insn, 21, 2); |
1161 | 2.09k | shift <<= 4; |
1162 | 2.09k | switch (MCInst_getOpcode(Inst)) { |
1163 | 0 | default: |
1164 | 0 | return Fail; |
1165 | 30 | case AArch64_MOVZWi: |
1166 | 119 | case AArch64_MOVNWi: |
1167 | 146 | case AArch64_MOVKWi: |
1168 | 146 | if (shift & (1U << 5)) |
1169 | 3 | return Fail; |
1170 | 143 | DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder); |
1171 | 143 | break; |
1172 | 702 | case AArch64_MOVZXi: |
1173 | 1.19k | case AArch64_MOVNXi: |
1174 | 1.95k | case AArch64_MOVKXi: |
1175 | 1.95k | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1176 | 1.95k | break; |
1177 | 2.09k | } |
1178 | | |
1179 | 2.09k | if (MCInst_getOpcode(Inst) == AArch64_MOVKWi || |
1180 | 2.09k | MCInst_getOpcode(Inst) == AArch64_MOVKXi) |
1181 | 786 | MCInst_addOperand2(Inst, (MCInst_getOperand(Inst, (0)))); |
1182 | | |
1183 | 2.09k | MCOperand_CreateImm0(Inst, (imm)); |
1184 | 2.09k | MCOperand_CreateImm0(Inst, (shift)); |
1185 | 2.09k | return Success; |
1186 | 2.09k | } |
1187 | | |
1188 | | static DecodeStatus DecodeUnsignedLdStInstruction(MCInst *Inst, uint32_t insn, |
1189 | | uint64_t Addr, |
1190 | | const void *Decoder) |
1191 | 4.69k | { |
1192 | 4.69k | unsigned Rt = fieldFromInstruction_4(insn, 0, 5); |
1193 | 4.69k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1194 | 4.69k | unsigned offset = fieldFromInstruction_4(insn, 10, 12); |
1195 | | |
1196 | 4.69k | switch (MCInst_getOpcode(Inst)) { |
1197 | 0 | default: |
1198 | 0 | return Fail; |
1199 | 86 | case AArch64_PRFMui: |
1200 | | // Rt is an immediate in prefetch. |
1201 | 86 | MCOperand_CreateImm0(Inst, (Rt)); |
1202 | 86 | break; |
1203 | 741 | case AArch64_STRBBui: |
1204 | 944 | case AArch64_LDRBBui: |
1205 | 1.29k | case AArch64_LDRSBWui: |
1206 | 1.51k | case AArch64_STRHHui: |
1207 | 1.81k | case AArch64_LDRHHui: |
1208 | 1.86k | case AArch64_LDRSHWui: |
1209 | 1.94k | case AArch64_STRWui: |
1210 | 2.03k | case AArch64_LDRWui: |
1211 | 2.03k | DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1212 | 2.03k | break; |
1213 | 26 | case AArch64_LDRSBXui: |
1214 | 93 | case AArch64_LDRSHXui: |
1215 | 354 | case AArch64_LDRSWui: |
1216 | 590 | case AArch64_STRXui: |
1217 | 774 | case AArch64_LDRXui: |
1218 | 774 | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1219 | 774 | break; |
1220 | 150 | case AArch64_LDRQui: |
1221 | 212 | case AArch64_STRQui: |
1222 | 212 | DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder); |
1223 | 212 | break; |
1224 | 43 | case AArch64_LDRDui: |
1225 | 142 | case AArch64_STRDui: |
1226 | 142 | DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1227 | 142 | break; |
1228 | 199 | case AArch64_LDRSui: |
1229 | 273 | case AArch64_STRSui: |
1230 | 273 | DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1231 | 273 | break; |
1232 | 99 | case AArch64_LDRHui: |
1233 | 288 | case AArch64_STRHui: |
1234 | 288 | DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder); |
1235 | 288 | break; |
1236 | 213 | case AArch64_LDRBui: |
1237 | 885 | case AArch64_STRBui: |
1238 | 885 | DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder); |
1239 | 885 | break; |
1240 | 4.69k | } |
1241 | | |
1242 | 4.69k | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1243 | | // No symbols supported in Capstone |
1244 | | // if (!Decoder->tryAddingSymbolicOperand(Inst, offset, Addr, Fail, 0, 0, 4)) |
1245 | 4.69k | MCOperand_CreateImm0(Inst, (offset)); |
1246 | 4.69k | return Success; |
1247 | 4.69k | } |
1248 | | |
1249 | | static DecodeStatus DecodeSignedLdStInstruction(MCInst *Inst, uint32_t insn, |
1250 | | uint64_t Addr, |
1251 | | const void *Decoder) |
1252 | 8.03k | { |
1253 | 8.03k | unsigned Rt = fieldFromInstruction_4(insn, 0, 5); |
1254 | 8.03k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1255 | 8.03k | int64_t offset = fieldFromInstruction_4(insn, 12, 9); |
1256 | | |
1257 | | // offset is a 9-bit signed immediate, so sign extend it to |
1258 | | // fill the unsigned. |
1259 | 8.03k | if (offset & (1 << (9 - 1))) |
1260 | 2.31k | offset |= ~((1LL << 9) - 1); |
1261 | | |
1262 | | // First operand is always the writeback to the address register, if needed. |
1263 | 8.03k | switch (MCInst_getOpcode(Inst)) { |
1264 | 3.86k | default: |
1265 | 3.86k | break; |
1266 | 3.86k | case AArch64_LDRSBWpre: |
1267 | 109 | case AArch64_LDRSHWpre: |
1268 | 127 | case AArch64_STRBBpre: |
1269 | 161 | case AArch64_LDRBBpre: |
1270 | 173 | case AArch64_STRHHpre: |
1271 | 355 | case AArch64_LDRHHpre: |
1272 | 413 | case AArch64_STRWpre: |
1273 | 424 | case AArch64_LDRWpre: |
1274 | 473 | case AArch64_LDRSBWpost: |
1275 | 793 | case AArch64_LDRSHWpost: |
1276 | 834 | case AArch64_STRBBpost: |
1277 | 908 | case AArch64_LDRBBpost: |
1278 | 971 | case AArch64_STRHHpost: |
1279 | 1.02k | case AArch64_LDRHHpost: |
1280 | 1.05k | case AArch64_STRWpost: |
1281 | 1.55k | case AArch64_LDRWpost: |
1282 | 1.58k | case AArch64_LDRSBXpre: |
1283 | 1.60k | case AArch64_LDRSHXpre: |
1284 | 1.65k | case AArch64_STRXpre: |
1285 | 1.73k | case AArch64_LDRSWpre: |
1286 | 1.81k | case AArch64_LDRXpre: |
1287 | 1.83k | case AArch64_LDRSBXpost: |
1288 | 1.90k | case AArch64_LDRSHXpost: |
1289 | 1.96k | case AArch64_STRXpost: |
1290 | 1.99k | case AArch64_LDRSWpost: |
1291 | 2.46k | case AArch64_LDRXpost: |
1292 | 2.52k | case AArch64_LDRQpre: |
1293 | 2.74k | case AArch64_STRQpre: |
1294 | 2.76k | case AArch64_LDRQpost: |
1295 | 3.05k | case AArch64_STRQpost: |
1296 | 3.12k | case AArch64_LDRDpre: |
1297 | 3.15k | case AArch64_STRDpre: |
1298 | 3.18k | case AArch64_LDRDpost: |
1299 | 3.23k | case AArch64_STRDpost: |
1300 | 3.27k | case AArch64_LDRSpre: |
1301 | 3.29k | case AArch64_STRSpre: |
1302 | 3.41k | case AArch64_LDRSpost: |
1303 | 3.47k | case AArch64_STRSpost: |
1304 | 3.53k | case AArch64_LDRHpre: |
1305 | 3.56k | case AArch64_STRHpre: |
1306 | 3.78k | case AArch64_LDRHpost: |
1307 | 3.79k | case AArch64_STRHpost: |
1308 | 3.84k | case AArch64_LDRBpre: |
1309 | 4.09k | case AArch64_STRBpre: |
1310 | 4.11k | case AArch64_LDRBpost: |
1311 | 4.16k | case AArch64_STRBpost: |
1312 | 4.16k | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1313 | 4.16k | break; |
1314 | 8.03k | } |
1315 | | |
1316 | 8.03k | switch (MCInst_getOpcode(Inst)) { |
1317 | 0 | default: |
1318 | 0 | return Fail; |
1319 | 47 | case AArch64_PRFUMi: |
1320 | | // Rt is an immediate in prefetch. |
1321 | 47 | MCOperand_CreateImm0(Inst, (Rt)); |
1322 | 47 | break; |
1323 | 318 | case AArch64_STURBBi: |
1324 | 359 | case AArch64_LDURBBi: |
1325 | 385 | case AArch64_LDURSBWi: |
1326 | 442 | case AArch64_STURHHi: |
1327 | 502 | case AArch64_LDURHHi: |
1328 | 712 | case AArch64_LDURSHWi: |
1329 | 784 | case AArch64_STURWi: |
1330 | 796 | case AArch64_LDURWi: |
1331 | 813 | case AArch64_LDTRSBWi: |
1332 | 837 | case AArch64_LDTRSHWi: |
1333 | 886 | case AArch64_STTRWi: |
1334 | 916 | case AArch64_LDTRWi: |
1335 | 1.09k | case AArch64_STTRHi: |
1336 | 1.23k | case AArch64_LDTRHi: |
1337 | 1.25k | case AArch64_LDTRBi: |
1338 | 1.29k | case AArch64_STTRBi: |
1339 | 1.34k | case AArch64_LDRSBWpre: |
1340 | 1.39k | case AArch64_LDRSHWpre: |
1341 | 1.41k | case AArch64_STRBBpre: |
1342 | 1.45k | case AArch64_LDRBBpre: |
1343 | 1.46k | case AArch64_STRHHpre: |
1344 | 1.64k | case AArch64_LDRHHpre: |
1345 | 1.70k | case AArch64_STRWpre: |
1346 | 1.71k | case AArch64_LDRWpre: |
1347 | 1.76k | case AArch64_LDRSBWpost: |
1348 | 2.08k | case AArch64_LDRSHWpost: |
1349 | 2.12k | case AArch64_STRBBpost: |
1350 | 2.19k | case AArch64_LDRBBpost: |
1351 | 2.26k | case AArch64_STRHHpost: |
1352 | 2.31k | case AArch64_LDRHHpost: |
1353 | 2.34k | case AArch64_STRWpost: |
1354 | 2.84k | case AArch64_LDRWpost: |
1355 | 2.91k | case AArch64_STLURBi: |
1356 | 2.93k | case AArch64_STLURHi: |
1357 | 2.98k | case AArch64_STLURWi: |
1358 | 3.01k | case AArch64_LDAPURBi: |
1359 | 3.02k | case AArch64_LDAPURSBWi: |
1360 | 3.06k | case AArch64_LDAPURHi: |
1361 | 3.20k | case AArch64_LDAPURSHWi: |
1362 | 3.37k | case AArch64_LDAPURi: |
1363 | 3.37k | DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1364 | 3.37k | break; |
1365 | 17 | case AArch64_LDURSBXi: |
1366 | 31 | case AArch64_LDURSHXi: |
1367 | 60 | case AArch64_LDURSWi: |
1368 | 82 | case AArch64_STURXi: |
1369 | 241 | case AArch64_LDURXi: |
1370 | 279 | case AArch64_LDTRSBXi: |
1371 | 329 | case AArch64_LDTRSHXi: |
1372 | 413 | case AArch64_LDTRSWi: |
1373 | 599 | case AArch64_STTRXi: |
1374 | 663 | case AArch64_LDTRXi: |
1375 | 685 | case AArch64_LDRSBXpre: |
1376 | 704 | case AArch64_LDRSHXpre: |
1377 | 761 | case AArch64_STRXpre: |
1378 | 837 | case AArch64_LDRSWpre: |
1379 | 918 | case AArch64_LDRXpre: |
1380 | 937 | case AArch64_LDRSBXpost: |
1381 | 1.01k | case AArch64_LDRSHXpost: |
1382 | 1.07k | case AArch64_STRXpost: |
1383 | 1.09k | case AArch64_LDRSWpost: |
1384 | 1.57k | case AArch64_LDRXpost: |
1385 | 1.61k | case AArch64_LDAPURSWi: |
1386 | 1.64k | case AArch64_LDAPURSHXi: |
1387 | 1.92k | case AArch64_LDAPURSBXi: |
1388 | 2.05k | case AArch64_STLURXi: |
1389 | 2.06k | case AArch64_LDAPURXi: |
1390 | 2.06k | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1391 | 2.06k | break; |
1392 | 20 | case AArch64_LDURQi: |
1393 | 391 | case AArch64_STURQi: |
1394 | 450 | case AArch64_LDRQpre: |
1395 | 667 | case AArch64_STRQpre: |
1396 | 691 | case AArch64_LDRQpost: |
1397 | 980 | case AArch64_STRQpost: |
1398 | 980 | DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder); |
1399 | 980 | break; |
1400 | 38 | case AArch64_LDURDi: |
1401 | 133 | case AArch64_STURDi: |
1402 | 203 | case AArch64_LDRDpre: |
1403 | 230 | case AArch64_STRDpre: |
1404 | 259 | case AArch64_LDRDpost: |
1405 | 313 | case AArch64_STRDpost: |
1406 | 313 | DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1407 | 313 | break; |
1408 | 28 | case AArch64_LDURSi: |
1409 | 92 | case AArch64_STURSi: |
1410 | 133 | case AArch64_LDRSpre: |
1411 | 153 | case AArch64_STRSpre: |
1412 | 270 | case AArch64_LDRSpost: |
1413 | 327 | case AArch64_STRSpost: |
1414 | 327 | DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1415 | 327 | break; |
1416 | 48 | case AArch64_LDURHi: |
1417 | 88 | case AArch64_STURHi: |
1418 | 148 | case AArch64_LDRHpre: |
1419 | 182 | case AArch64_STRHpre: |
1420 | 399 | case AArch64_LDRHpost: |
1421 | 414 | case AArch64_STRHpost: |
1422 | 414 | DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder); |
1423 | 414 | break; |
1424 | 45 | case AArch64_LDURBi: |
1425 | 144 | case AArch64_STURBi: |
1426 | 191 | case AArch64_LDRBpre: |
1427 | 442 | case AArch64_STRBpre: |
1428 | 455 | case AArch64_LDRBpost: |
1429 | 509 | case AArch64_STRBpost: |
1430 | 509 | DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder); |
1431 | 509 | break; |
1432 | 8.03k | } |
1433 | | |
1434 | 8.03k | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1435 | 8.03k | MCOperand_CreateImm0(Inst, (offset)); |
1436 | | |
1437 | 8.03k | bool IsLoad = fieldFromInstruction_4(insn, 22, 1); |
1438 | 8.03k | bool IsIndexed = fieldFromInstruction_4(insn, 10, 2) != 0; |
1439 | 8.03k | bool IsFP = fieldFromInstruction_4(insn, 26, 1); |
1440 | | |
1441 | | // Cannot write back to a transfer register (but xzr != sp). |
1442 | 8.03k | if (IsLoad && IsIndexed && !IsFP && Rn != 31 && Rt == Rn) |
1443 | 59 | return SoftFail; |
1444 | | |
1445 | 7.97k | return Success; |
1446 | 8.03k | } |
1447 | | |
1448 | | static DecodeStatus DecodeExclusiveLdStInstruction(MCInst *Inst, uint32_t insn, |
1449 | | uint64_t Addr, |
1450 | | const void *Decoder) |
1451 | 6.23k | { |
1452 | 6.23k | unsigned Rt = fieldFromInstruction_4(insn, 0, 5); |
1453 | 6.23k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1454 | 6.23k | unsigned Rt2 = fieldFromInstruction_4(insn, 10, 5); |
1455 | 6.23k | unsigned Rs = fieldFromInstruction_4(insn, 16, 5); |
1456 | | |
1457 | 6.23k | unsigned Opcode = MCInst_getOpcode(Inst); |
1458 | 6.23k | switch (Opcode) { |
1459 | 0 | default: |
1460 | 0 | return Fail; |
1461 | 37 | case AArch64_STLXRW: |
1462 | 321 | case AArch64_STLXRB: |
1463 | 360 | case AArch64_STLXRH: |
1464 | 386 | case AArch64_STXRW: |
1465 | 801 | case AArch64_STXRB: |
1466 | 852 | case AArch64_STXRH: |
1467 | 852 | DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder); |
1468 | | // fall through |
1469 | 928 | case AArch64_LDARW: |
1470 | 975 | case AArch64_LDARB: |
1471 | 1.04k | case AArch64_LDARH: |
1472 | 1.09k | case AArch64_LDAXRW: |
1473 | 1.11k | case AArch64_LDAXRB: |
1474 | 1.21k | case AArch64_LDAXRH: |
1475 | 1.70k | case AArch64_LDXRW: |
1476 | 1.71k | case AArch64_LDXRB: |
1477 | 1.95k | case AArch64_LDXRH: |
1478 | 2.56k | case AArch64_STLRW: |
1479 | 2.61k | case AArch64_STLRB: |
1480 | 2.68k | case AArch64_STLRH: |
1481 | 2.76k | case AArch64_STLLRW: |
1482 | 2.84k | case AArch64_STLLRB: |
1483 | 2.92k | case AArch64_STLLRH: |
1484 | 3.05k | case AArch64_LDLARW: |
1485 | 3.11k | case AArch64_LDLARB: |
1486 | 3.16k | case AArch64_LDLARH: |
1487 | 3.16k | DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1488 | 3.16k | break; |
1489 | 18 | case AArch64_STLXRX: |
1490 | 65 | case AArch64_STXRX: |
1491 | 65 | DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder); |
1492 | | // fall through |
1493 | 1.21k | case AArch64_LDARX: |
1494 | 1.26k | case AArch64_LDAXRX: |
1495 | 1.39k | case AArch64_LDXRX: |
1496 | 2.26k | case AArch64_STLRX: |
1497 | 2.40k | case AArch64_LDLARX: |
1498 | 2.40k | case AArch64_STLLRX: |
1499 | 2.40k | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1500 | 2.40k | break; |
1501 | 79 | case AArch64_STLXPW: |
1502 | 130 | case AArch64_STXPW: |
1503 | 130 | DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder); |
1504 | | // fall through |
1505 | 344 | case AArch64_LDAXPW: |
1506 | 418 | case AArch64_LDXPW: |
1507 | 418 | DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1508 | 418 | DecodeGPR32RegisterClass(Inst, Rt2, Addr, Decoder); |
1509 | 418 | break; |
1510 | 66 | case AArch64_STLXPX: |
1511 | 149 | case AArch64_STXPX: |
1512 | 149 | DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder); |
1513 | | // fall through |
1514 | 183 | case AArch64_LDAXPX: |
1515 | 239 | case AArch64_LDXPX: |
1516 | 239 | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1517 | 239 | DecodeGPR64RegisterClass(Inst, Rt2, Addr, Decoder); |
1518 | 239 | break; |
1519 | 6.23k | } |
1520 | | |
1521 | 6.23k | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1522 | | |
1523 | | // You shouldn't load to the same register twice in an instruction... |
1524 | 6.23k | if ((Opcode == AArch64_LDAXPW || Opcode == AArch64_LDXPW || |
1525 | 6.23k | Opcode == AArch64_LDAXPX || Opcode == AArch64_LDXPX) && |
1526 | 6.23k | Rt == Rt2) |
1527 | 37 | return SoftFail; |
1528 | | |
1529 | 6.19k | return Success; |
1530 | 6.23k | } |
1531 | | |
1532 | | static DecodeStatus DecodePairLdStInstruction(MCInst *Inst, uint32_t insn, |
1533 | | uint64_t Addr, |
1534 | | const void *Decoder) |
1535 | 12.4k | { |
1536 | 12.4k | unsigned Rt = fieldFromInstruction_4(insn, 0, 5); |
1537 | 12.4k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1538 | 12.4k | unsigned Rt2 = fieldFromInstruction_4(insn, 10, 5); |
1539 | 12.4k | int64_t offset = fieldFromInstruction_4(insn, 15, 7); |
1540 | 12.4k | bool IsLoad = fieldFromInstruction_4(insn, 22, 1); |
1541 | | |
1542 | | // offset is a 7-bit signed immediate, so sign extend it to |
1543 | | // fill the unsigned. |
1544 | 12.4k | if (offset & (1 << (7 - 1))) |
1545 | 9.20k | offset |= ~((1LL << 7) - 1); |
1546 | | |
1547 | 12.4k | unsigned Opcode = MCInst_getOpcode(Inst); |
1548 | 12.4k | bool NeedsDisjointWritebackTransfer = false; |
1549 | | |
1550 | | // First operand is always writeback of base register. |
1551 | 12.4k | switch (Opcode) { |
1552 | 7.00k | default: |
1553 | 7.00k | break; |
1554 | 7.00k | case AArch64_LDPXpost: |
1555 | 1.27k | case AArch64_STPXpost: |
1556 | 1.44k | case AArch64_LDPSWpost: |
1557 | 1.56k | case AArch64_LDPXpre: |
1558 | 1.94k | case AArch64_STPXpre: |
1559 | 1.98k | case AArch64_LDPSWpre: |
1560 | 2.42k | case AArch64_LDPWpost: |
1561 | 2.73k | case AArch64_STPWpost: |
1562 | 2.86k | case AArch64_LDPWpre: |
1563 | 3.10k | case AArch64_STPWpre: |
1564 | 3.32k | case AArch64_LDPQpost: |
1565 | 3.86k | case AArch64_STPQpost: |
1566 | 3.96k | case AArch64_LDPQpre: |
1567 | 4.07k | case AArch64_STPQpre: |
1568 | 4.34k | case AArch64_LDPDpost: |
1569 | 4.43k | case AArch64_STPDpost: |
1570 | 4.60k | case AArch64_LDPDpre: |
1571 | 4.62k | case AArch64_STPDpre: |
1572 | 4.69k | case AArch64_LDPSpost: |
1573 | 4.82k | case AArch64_STPSpost: |
1574 | 4.97k | case AArch64_LDPSpre: |
1575 | 5.16k | case AArch64_STPSpre: |
1576 | 5.36k | case AArch64_STGPpre: |
1577 | 5.47k | case AArch64_STGPpost: |
1578 | 5.47k | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1579 | 5.47k | break; |
1580 | 12.4k | } |
1581 | | |
1582 | 12.4k | switch (Opcode) { |
1583 | 0 | default: |
1584 | 0 | return Fail; |
1585 | 26 | case AArch64_LDPXpost: |
1586 | 1.27k | case AArch64_STPXpost: |
1587 | 1.44k | case AArch64_LDPSWpost: |
1588 | 1.56k | case AArch64_LDPXpre: |
1589 | 1.94k | case AArch64_STPXpre: |
1590 | 1.98k | case AArch64_LDPSWpre: |
1591 | 2.18k | case AArch64_STGPpre: |
1592 | 2.29k | case AArch64_STGPpost: |
1593 | 2.29k | NeedsDisjointWritebackTransfer = true; |
1594 | | // fall through |
1595 | 2.32k | case AArch64_LDNPXi: |
1596 | 2.36k | case AArch64_STNPXi: |
1597 | 2.62k | case AArch64_LDPXi: |
1598 | 2.66k | case AArch64_STPXi: |
1599 | 3.31k | case AArch64_LDPSWi: |
1600 | 3.36k | case AArch64_STGPi: |
1601 | 3.36k | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1602 | 3.36k | DecodeGPR64RegisterClass(Inst, Rt2, Addr, Decoder); |
1603 | 3.36k | break; |
1604 | 435 | case AArch64_LDPWpost: |
1605 | 748 | case AArch64_STPWpost: |
1606 | 872 | case AArch64_LDPWpre: |
1607 | 1.11k | case AArch64_STPWpre: |
1608 | 1.11k | NeedsDisjointWritebackTransfer = true; |
1609 | | // fall through |
1610 | 1.16k | case AArch64_LDNPWi: |
1611 | 1.52k | case AArch64_STNPWi: |
1612 | 1.71k | case AArch64_LDPWi: |
1613 | 2.17k | case AArch64_STPWi: |
1614 | 2.17k | DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1615 | 2.17k | DecodeGPR32RegisterClass(Inst, Rt2, Addr, Decoder); |
1616 | 2.17k | break; |
1617 | 154 | case AArch64_LDNPQi: |
1618 | 771 | case AArch64_STNPQi: |
1619 | 993 | case AArch64_LDPQpost: |
1620 | 1.53k | case AArch64_STPQpost: |
1621 | 1.55k | case AArch64_LDPQi: |
1622 | 1.72k | case AArch64_STPQi: |
1623 | 1.82k | case AArch64_LDPQpre: |
1624 | 1.93k | case AArch64_STPQpre: |
1625 | 1.93k | DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder); |
1626 | 1.93k | DecodeFPR128RegisterClass(Inst, Rt2, Addr, Decoder); |
1627 | 1.93k | break; |
1628 | 746 | case AArch64_LDNPDi: |
1629 | 1.01k | case AArch64_STNPDi: |
1630 | 1.28k | case AArch64_LDPDpost: |
1631 | 1.38k | case AArch64_STPDpost: |
1632 | 1.90k | case AArch64_LDPDi: |
1633 | 1.97k | case AArch64_STPDi: |
1634 | 2.14k | case AArch64_LDPDpre: |
1635 | 2.16k | case AArch64_STPDpre: |
1636 | 2.16k | DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1637 | 2.16k | DecodeFPR64RegisterClass(Inst, Rt2, Addr, Decoder); |
1638 | 2.16k | break; |
1639 | 296 | case AArch64_LDNPSi: |
1640 | 1.76k | case AArch64_STNPSi: |
1641 | 1.84k | case AArch64_LDPSpost: |
1642 | 1.97k | case AArch64_STPSpost: |
1643 | 2.05k | case AArch64_LDPSi: |
1644 | 2.50k | case AArch64_STPSi: |
1645 | 2.64k | case AArch64_LDPSpre: |
1646 | 2.84k | case AArch64_STPSpre: |
1647 | 2.84k | DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1648 | 2.84k | DecodeFPR32RegisterClass(Inst, Rt2, Addr, Decoder); |
1649 | 2.84k | break; |
1650 | 12.4k | } |
1651 | | |
1652 | 12.4k | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1653 | 12.4k | MCOperand_CreateImm0(Inst, (offset)); |
1654 | | |
1655 | | // You shouldn't load to the same register twice in an instruction... |
1656 | 12.4k | if (IsLoad && Rt == Rt2) |
1657 | 179 | return SoftFail; |
1658 | | |
1659 | | // ... or do any operation that writes-back to a transfer register. But note |
1660 | | // that "stp xzr, xzr, [sp], #4" is fine because xzr and sp are different. |
1661 | 12.3k | if (NeedsDisjointWritebackTransfer && Rn != 31 && |
1662 | 12.3k | (Rt == Rn || Rt2 == Rn)) |
1663 | 384 | return SoftFail; |
1664 | | |
1665 | 11.9k | return Success; |
1666 | 12.3k | } |
1667 | | |
1668 | | static DecodeStatus DecodeAuthLoadInstruction(MCInst *Inst, uint32_t insn, |
1669 | | uint64_t Addr, |
1670 | | const void *Decoder) |
1671 | 456 | { |
1672 | 456 | unsigned Rt = fieldFromInstruction_4(insn, 0, 5); |
1673 | 456 | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1674 | 456 | uint64_t offset = fieldFromInstruction_4(insn, 22, 1) << 9 | |
1675 | 456 | fieldFromInstruction_4(insn, 12, 9); |
1676 | 456 | unsigned writeback = fieldFromInstruction_4(insn, 11, 1); |
1677 | | |
1678 | 456 | switch (MCInst_getOpcode(Inst)) { |
1679 | 0 | default: |
1680 | 0 | return Fail; |
1681 | 131 | case AArch64_LDRAAwriteback: |
1682 | 384 | case AArch64_LDRABwriteback: |
1683 | 384 | DecodeGPR64spRegisterClass(Inst, Rn /* writeback register */, |
1684 | 384 | Addr, Decoder); |
1685 | 384 | break; |
1686 | 14 | case AArch64_LDRAAindexed: |
1687 | 72 | case AArch64_LDRABindexed: |
1688 | 72 | break; |
1689 | 456 | } |
1690 | | |
1691 | 456 | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1692 | 456 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1693 | 456 | CONCAT(DecodeSImm, 10)(Inst, offset, Addr, Decoder); |
1694 | | |
1695 | 456 | if (writeback && Rt == Rn && Rn != 31) { |
1696 | 61 | return SoftFail; |
1697 | 61 | } |
1698 | | |
1699 | 395 | return Success; |
1700 | 456 | } |
1701 | | |
1702 | | static DecodeStatus DecodeAddSubERegInstruction(MCInst *Inst, uint32_t insn, |
1703 | | uint64_t Addr, |
1704 | | const void *Decoder) |
1705 | 1.79k | { |
1706 | 1.79k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1707 | 1.79k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1708 | 1.79k | unsigned Rm = fieldFromInstruction_4(insn, 16, 5); |
1709 | 1.79k | unsigned extend = fieldFromInstruction_4(insn, 10, 6); |
1710 | | |
1711 | 1.79k | unsigned shift = extend & 0x7; |
1712 | 1.79k | if (shift > 4) |
1713 | 3 | return Fail; |
1714 | | |
1715 | 1.79k | switch (MCInst_getOpcode(Inst)) { |
1716 | 0 | default: |
1717 | 0 | return Fail; |
1718 | 178 | case AArch64_ADDWrx: |
1719 | 274 | case AArch64_SUBWrx: |
1720 | 274 | DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder); |
1721 | 274 | DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder); |
1722 | 274 | DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder); |
1723 | 274 | break; |
1724 | 310 | case AArch64_ADDSWrx: |
1725 | 387 | case AArch64_SUBSWrx: |
1726 | 387 | DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder); |
1727 | 387 | DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder); |
1728 | 387 | DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder); |
1729 | 387 | break; |
1730 | 53 | case AArch64_ADDXrx: |
1731 | 143 | case AArch64_SUBXrx: |
1732 | 143 | DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder); |
1733 | 143 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1734 | 143 | DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder); |
1735 | 143 | break; |
1736 | 520 | case AArch64_ADDSXrx: |
1737 | 532 | case AArch64_SUBSXrx: |
1738 | 532 | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1739 | 532 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1740 | 532 | DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder); |
1741 | 532 | break; |
1742 | 9 | case AArch64_ADDXrx64: |
1743 | 48 | case AArch64_SUBXrx64: |
1744 | 48 | DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder); |
1745 | 48 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1746 | 48 | DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder); |
1747 | 48 | break; |
1748 | 180 | case AArch64_SUBSXrx64: |
1749 | 407 | case AArch64_ADDSXrx64: |
1750 | 407 | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1751 | 407 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1752 | 407 | DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder); |
1753 | 407 | break; |
1754 | 1.79k | } |
1755 | | |
1756 | 1.79k | MCOperand_CreateImm0(Inst, (extend)); |
1757 | 1.79k | return Success; |
1758 | 1.79k | } |
1759 | | |
1760 | | static DecodeStatus DecodeLogicalImmInstruction(MCInst *Inst, uint32_t insn, |
1761 | | uint64_t Addr, |
1762 | | const void *Decoder) |
1763 | 2.80k | { |
1764 | 2.80k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1765 | 2.80k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1766 | 2.80k | unsigned Datasize = fieldFromInstruction_4(insn, 31, 1); |
1767 | 2.80k | unsigned imm; |
1768 | | |
1769 | 2.80k | if (Datasize) { |
1770 | 1.70k | if (MCInst_getOpcode(Inst) == AArch64_ANDSXri) |
1771 | 285 | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1772 | 1.41k | else |
1773 | 1.41k | DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder); |
1774 | 1.70k | DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder); |
1775 | 1.70k | imm = fieldFromInstruction_4(insn, 10, 13); |
1776 | 1.70k | if (!AArch64_AM_isValidDecodeLogicalImmediate(imm, 64)) |
1777 | 4 | return Fail; |
1778 | 1.70k | } else { |
1779 | 1.10k | if (MCInst_getOpcode(Inst) == AArch64_ANDSWri) |
1780 | 153 | DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder); |
1781 | 949 | else |
1782 | 949 | DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder); |
1783 | 1.10k | DecodeGPR32RegisterClass(Inst, Rn, Addr, Decoder); |
1784 | 1.10k | imm = fieldFromInstruction_4(insn, 10, 12); |
1785 | 1.10k | if (!AArch64_AM_isValidDecodeLogicalImmediate(imm, 32)) |
1786 | 4 | return Fail; |
1787 | 1.10k | } |
1788 | 2.79k | MCOperand_CreateImm0(Inst, (imm)); |
1789 | 2.79k | return Success; |
1790 | 2.80k | } |
1791 | | |
1792 | | static DecodeStatus DecodeModImmInstruction(MCInst *Inst, uint32_t insn, |
1793 | | uint64_t Addr, const void *Decoder) |
1794 | 1.31k | { |
1795 | 1.31k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1796 | 1.31k | unsigned cmode = fieldFromInstruction_4(insn, 12, 4); |
1797 | 1.31k | unsigned imm = fieldFromInstruction_4(insn, 16, 3) << 5; |
1798 | 1.31k | imm |= fieldFromInstruction_4(insn, 5, 5); |
1799 | | |
1800 | 1.31k | if (MCInst_getOpcode(Inst) == AArch64_MOVID) |
1801 | 212 | DecodeFPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1802 | 1.10k | else |
1803 | 1.10k | DecodeFPR128RegisterClass(Inst, Rd, Addr, Decoder); |
1804 | | |
1805 | 1.31k | MCOperand_CreateImm0(Inst, (imm)); |
1806 | | |
1807 | 1.31k | switch (MCInst_getOpcode(Inst)) { |
1808 | 821 | default: |
1809 | 821 | break; |
1810 | 821 | case AArch64_MOVIv4i16: |
1811 | 71 | case AArch64_MOVIv8i16: |
1812 | 88 | case AArch64_MVNIv4i16: |
1813 | 105 | case AArch64_MVNIv8i16: |
1814 | 157 | case AArch64_MOVIv2i32: |
1815 | 180 | case AArch64_MOVIv4i32: |
1816 | 207 | case AArch64_MVNIv2i32: |
1817 | 233 | case AArch64_MVNIv4i32: |
1818 | 233 | MCOperand_CreateImm0(Inst, ((cmode & 6) << 2)); |
1819 | 233 | break; |
1820 | 143 | case AArch64_MOVIv2s_msl: |
1821 | 176 | case AArch64_MOVIv4s_msl: |
1822 | 214 | case AArch64_MVNIv2s_msl: |
1823 | 258 | case AArch64_MVNIv4s_msl: |
1824 | 258 | MCOperand_CreateImm0(Inst, ((cmode & 1) ? 0x110 : 0x108)); |
1825 | 258 | break; |
1826 | 1.31k | } |
1827 | | |
1828 | 1.31k | return Success; |
1829 | 1.31k | } |
1830 | | |
1831 | | static DecodeStatus DecodeModImmTiedInstruction(MCInst *Inst, uint32_t insn, |
1832 | | uint64_t Addr, |
1833 | | const void *Decoder) |
1834 | 25 | { |
1835 | 25 | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1836 | 25 | unsigned cmode = fieldFromInstruction_4(insn, 12, 4); |
1837 | 25 | unsigned imm = fieldFromInstruction_4(insn, 16, 3) << 5; |
1838 | 25 | imm |= fieldFromInstruction_4(insn, 5, 5); |
1839 | | |
1840 | | // Tied operands added twice. |
1841 | 25 | DecodeFPR128RegisterClass(Inst, Rd, Addr, Decoder); |
1842 | 25 | DecodeFPR128RegisterClass(Inst, Rd, Addr, Decoder); |
1843 | | |
1844 | 25 | MCOperand_CreateImm0(Inst, (imm)); |
1845 | 25 | MCOperand_CreateImm0(Inst, ((cmode & 6) << 2)); |
1846 | | |
1847 | 25 | return Success; |
1848 | 25 | } |
1849 | | |
1850 | | static DecodeStatus DecodeAdrInstruction(MCInst *Inst, uint32_t insn, |
1851 | | uint64_t Addr, const void *Decoder) |
1852 | 3.46k | { |
1853 | 3.46k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1854 | 3.46k | int64_t imm = fieldFromInstruction_4(insn, 5, 19) << 2; |
1855 | 3.46k | imm |= fieldFromInstruction_4(insn, 29, 2); |
1856 | | |
1857 | | // Sign-extend the 21-bit immediate. |
1858 | 3.46k | if (imm & (1 << (21 - 1))) |
1859 | 1.57k | imm |= ~((1LL << 21) - 1); |
1860 | | |
1861 | 3.46k | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1862 | | // No symbols supported in Capstone |
1863 | | // if (!Decoder->tryAddingSymbolicOperand(Inst, imm, Addr, Fail, 0, 0, 4)) |
1864 | 3.46k | MCOperand_CreateImm0(Inst, (imm)); |
1865 | | |
1866 | 3.46k | return Success; |
1867 | 3.46k | } |
1868 | | |
1869 | | static DecodeStatus DecodeAddSubImmShift(MCInst *Inst, uint32_t insn, |
1870 | | uint64_t Addr, const void *Decoder) |
1871 | 1.68k | { |
1872 | 1.68k | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
1873 | 1.68k | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
1874 | 1.68k | unsigned Imm = fieldFromInstruction_4(insn, 10, 14); |
1875 | 1.68k | unsigned S = fieldFromInstruction_4(insn, 29, 1); |
1876 | 1.68k | unsigned Datasize = fieldFromInstruction_4(insn, 31, 1); |
1877 | | |
1878 | 1.68k | unsigned ShifterVal = (Imm >> 12) & 3; |
1879 | 1.68k | unsigned ImmVal = Imm & 0xFFF; |
1880 | | |
1881 | 1.68k | if (ShifterVal != 0 && ShifterVal != 1) |
1882 | 12 | return Fail; |
1883 | | |
1884 | 1.66k | if (Datasize) { |
1885 | 414 | if (Rd == 31 && !S) |
1886 | 28 | DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder); |
1887 | 386 | else |
1888 | 386 | DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder); |
1889 | 414 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
1890 | 1.25k | } else { |
1891 | 1.25k | if (Rd == 31 && !S) |
1892 | 161 | DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder); |
1893 | 1.09k | else |
1894 | 1.09k | DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder); |
1895 | 1.25k | DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder); |
1896 | 1.25k | } |
1897 | | |
1898 | | // No symbols supported in Capstone |
1899 | | // if (!Decoder->tryAddingSymbolicOperand(Inst, Imm, Addr, Fail, 0, 0, 4)) |
1900 | 1.66k | MCOperand_CreateImm0(Inst, (ImmVal)); |
1901 | 1.66k | MCOperand_CreateImm0(Inst, (12 * ShifterVal)); |
1902 | 1.66k | return Success; |
1903 | 1.68k | } |
1904 | | |
1905 | | static DecodeStatus DecodeUnconditionalBranch(MCInst *Inst, uint32_t insn, |
1906 | | uint64_t Addr, |
1907 | | const void *Decoder) |
1908 | 2.05k | { |
1909 | 2.05k | int64_t imm = fieldFromInstruction_4(insn, 0, 26); |
1910 | | |
1911 | | // Sign-extend the 26-bit immediate. |
1912 | 2.05k | if (imm & (1 << (26 - 1))) |
1913 | 1.00k | imm |= ~((1LL << 26) - 1); |
1914 | | |
1915 | | // No symbols supported in Capstone |
1916 | | // if (!Decoder->tryAddingSymbolicOperand(Inst, imm * 4, Addr, true, 0, 0, 4)) |
1917 | 2.05k | MCOperand_CreateImm0(Inst, (imm)); |
1918 | | |
1919 | 2.05k | return Success; |
1920 | 2.05k | } |
1921 | | |
1922 | | static bool isInvalidPState(uint64_t Op1, uint64_t Op2) |
1923 | 2.45k | { |
1924 | 2.45k | return Op1 == 0 && (Op2 == 0 || // CFINV |
1925 | 945 | Op2 == 1 || // XAFlag |
1926 | 945 | Op2 == 2); // AXFlag |
1927 | 2.45k | } |
1928 | | |
1929 | | static DecodeStatus DecodeSystemPStateImm0_15Instruction(MCInst *Inst, |
1930 | | uint32_t insn, |
1931 | | uint64_t Addr, |
1932 | | const void *Decoder) |
1933 | 1.05k | { |
1934 | 1.05k | uint64_t op1 = fieldFromInstruction_4(insn, 16, 3); |
1935 | 1.05k | uint64_t op2 = fieldFromInstruction_4(insn, 5, 3); |
1936 | 1.05k | uint64_t imm = fieldFromInstruction_4(insn, 8, 4); |
1937 | 1.05k | uint64_t pstate_field = (op1 << 3) | op2; |
1938 | | |
1939 | 1.05k | if (isInvalidPState(op1, op2)) |
1940 | 61 | return Fail; |
1941 | | |
1942 | 989 | MCOperand_CreateImm0(Inst, (pstate_field)); |
1943 | 989 | MCOperand_CreateImm0(Inst, (imm)); |
1944 | | |
1945 | 989 | const AArch64PState_PStateImm0_15 *PState = |
1946 | 989 | AArch64PState_lookupPStateImm0_15ByEncoding(pstate_field); |
1947 | 989 | if (PState && |
1948 | 989 | AArch64_testFeatureList(Inst->csh->mode, PState->FeaturesRequired)) |
1949 | 564 | return Success; |
1950 | 425 | return Fail; |
1951 | 989 | } |
1952 | | |
1953 | | static DecodeStatus DecodeSystemPStateImm0_1Instruction(MCInst *Inst, |
1954 | | uint32_t insn, |
1955 | | uint64_t Addr, |
1956 | | const void *Decoder) |
1957 | 1.40k | { |
1958 | 1.40k | uint64_t op1 = fieldFromInstruction_4(insn, 16, 3); |
1959 | 1.40k | uint64_t op2 = fieldFromInstruction_4(insn, 5, 3); |
1960 | 1.40k | uint64_t crm_high = fieldFromInstruction_4(insn, 9, 3); |
1961 | 1.40k | uint64_t imm = fieldFromInstruction_4(insn, 8, 1); |
1962 | 1.40k | uint64_t pstate_field = (crm_high << 6) | (op1 << 3) | op2; |
1963 | | |
1964 | 1.40k | if (isInvalidPState(op1, op2)) |
1965 | 61 | return Fail; |
1966 | | |
1967 | 1.34k | MCOperand_CreateImm0(Inst, (pstate_field)); |
1968 | 1.34k | MCOperand_CreateImm0(Inst, (imm)); |
1969 | | |
1970 | 1.34k | const AArch64PState_PStateImm0_1 *PState = |
1971 | 1.34k | AArch64PState_lookupPStateImm0_1ByEncoding(pstate_field); |
1972 | 1.34k | if (PState && |
1973 | 1.34k | AArch64_testFeatureList(Inst->csh->mode, PState->FeaturesRequired)) |
1974 | 4 | return Success; |
1975 | 1.34k | return Fail; |
1976 | 1.34k | } |
1977 | | |
1978 | | static DecodeStatus DecodeTestAndBranch(MCInst *Inst, uint32_t insn, |
1979 | | uint64_t Addr, const void *Decoder) |
1980 | 971 | { |
1981 | 971 | uint64_t Rt = fieldFromInstruction_4(insn, 0, 5); |
1982 | 971 | uint64_t bit = fieldFromInstruction_4(insn, 31, 1) << 5; |
1983 | 971 | bit |= fieldFromInstruction_4(insn, 19, 5); |
1984 | 971 | int64_t dst = fieldFromInstruction_4(insn, 5, 14); |
1985 | | |
1986 | | // Sign-extend 14-bit immediate. |
1987 | 971 | if (dst & (1 << (14 - 1))) |
1988 | 684 | dst |= ~((1LL << 14) - 1); |
1989 | | |
1990 | 971 | if (fieldFromInstruction_4(insn, 31, 1) == 0) |
1991 | 563 | DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder); |
1992 | 408 | else |
1993 | 408 | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
1994 | 971 | MCOperand_CreateImm0(Inst, (bit)); |
1995 | | // No symbols supported in Capstone |
1996 | | // if (!Decoder->tryAddingSymbolicOperand(Inst, dst * 4, Addr, true, 0, 0, 4)) |
1997 | 971 | MCOperand_CreateImm0(Inst, (dst)); |
1998 | | |
1999 | 971 | return Success; |
2000 | 971 | } |
2001 | | |
2002 | | static DecodeStatus DecodeGPRSeqPairsClassRegisterClass(MCInst *Inst, |
2003 | | unsigned RegClassID, |
2004 | | unsigned RegNo, |
2005 | | uint64_t Addr, |
2006 | | const void *Decoder) |
2007 | 912 | { |
2008 | | // Register number must be even (see CASP instruction) |
2009 | 912 | if (RegNo & 0x1) |
2010 | 10 | return Fail; |
2011 | | |
2012 | 902 | unsigned Reg = |
2013 | 902 | AArch64MCRegisterClasses[RegClassID].RegsBegin[RegNo / 2]; |
2014 | 902 | MCOperand_CreateReg0(Inst, (Reg)); |
2015 | 902 | return Success; |
2016 | 912 | } |
2017 | | |
2018 | | static DecodeStatus DecodeWSeqPairsClassRegisterClass(MCInst *Inst, |
2019 | | unsigned RegNo, |
2020 | | uint64_t Addr, |
2021 | | const void *Decoder) |
2022 | 94 | { |
2023 | 94 | return DecodeGPRSeqPairsClassRegisterClass( |
2024 | 94 | Inst, AArch64_WSeqPairsClassRegClassID, RegNo, Addr, Decoder); |
2025 | 94 | } |
2026 | | |
2027 | | static DecodeStatus DecodeXSeqPairsClassRegisterClass(MCInst *Inst, |
2028 | | unsigned RegNo, |
2029 | | uint64_t Addr, |
2030 | | const void *Decoder) |
2031 | 818 | { |
2032 | 818 | return DecodeGPRSeqPairsClassRegisterClass( |
2033 | 818 | Inst, AArch64_XSeqPairsClassRegClassID, RegNo, Addr, Decoder); |
2034 | 818 | } |
2035 | | |
2036 | | static DecodeStatus DecodeSyspXzrInstruction(MCInst *Inst, uint32_t insn, |
2037 | | uint64_t Addr, const void *Decoder) |
2038 | 352 | { |
2039 | 352 | unsigned op1 = fieldFromInstruction_4(insn, 16, 3); |
2040 | 352 | unsigned CRn = fieldFromInstruction_4(insn, 12, 4); |
2041 | 352 | unsigned CRm = fieldFromInstruction_4(insn, 8, 4); |
2042 | 352 | unsigned op2 = fieldFromInstruction_4(insn, 5, 3); |
2043 | 352 | unsigned Rt = fieldFromInstruction_4(insn, 0, 5); |
2044 | 352 | if (Rt != 0x1f) |
2045 | 0 | return Fail; |
2046 | | |
2047 | 352 | MCOperand_CreateImm0(Inst, (op1)); |
2048 | 352 | MCOperand_CreateImm0(Inst, (CRn)); |
2049 | 352 | MCOperand_CreateImm0(Inst, (CRm)); |
2050 | 352 | MCOperand_CreateImm0(Inst, (op2)); |
2051 | 352 | DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder); |
2052 | | |
2053 | 352 | return Success; |
2054 | 352 | } |
2055 | | |
2056 | | static DecodeStatus DecodeSVELogicalImmInstruction(MCInst *Inst, uint32_t insn, |
2057 | | uint64_t Addr, |
2058 | | const void *Decoder) |
2059 | 4.41k | { |
2060 | 4.41k | unsigned Zdn = fieldFromInstruction_4(insn, 0, 5); |
2061 | 4.41k | unsigned imm = fieldFromInstruction_4(insn, 5, 13); |
2062 | 4.41k | if (!AArch64_AM_isValidDecodeLogicalImmediate(imm, 64)) |
2063 | 2 | return Fail; |
2064 | | |
2065 | | // The same (tied) operand is added twice to the instruction. |
2066 | 4.41k | DecodeZPRRegisterClass(Inst, Zdn, Addr, Decoder); |
2067 | 4.41k | if (MCInst_getOpcode(Inst) != AArch64_DUPM_ZI) |
2068 | 470 | DecodeZPRRegisterClass(Inst, Zdn, Addr, Decoder); |
2069 | 4.41k | MCOperand_CreateImm0(Inst, (imm)); |
2070 | 4.41k | return Success; |
2071 | 4.41k | } |
2072 | | |
2073 | | #define DEFINE_DecodeSImm(Bits) \ |
2074 | | static DecodeStatus CONCAT(DecodeSImm, Bits)(MCInst * Inst, \ |
2075 | | uint64_t Imm, \ |
2076 | | uint64_t Address, \ |
2077 | | const void *Decoder) \ |
2078 | 7.02k | { \ |
2079 | 7.02k | if (Imm & ~((1LL << Bits) - 1)) \ |
2080 | 7.02k | return Fail; \ |
2081 | 7.02k | \ |
2082 | 7.02k | if (Imm & (1 << (Bits - 1))) \ |
2083 | 7.02k | Imm |= ~((1LL << Bits) - 1); \ |
2084 | 7.02k | \ |
2085 | 7.02k | MCOperand_CreateImm0(Inst, (Imm)); \ |
2086 | 7.02k | return Success; \ |
2087 | 7.02k | } AArch64Disassembler.c:DecodeSImm_5 Line | Count | Source | 2078 | 1.07k | { \ | 2079 | 1.07k | if (Imm & ~((1LL << Bits) - 1)) \ | 2080 | 1.07k | return Fail; \ | 2081 | 1.07k | \ | 2082 | 1.07k | if (Imm & (1 << (Bits - 1))) \ | 2083 | 1.07k | Imm |= ~((1LL << Bits) - 1); \ | 2084 | 1.07k | \ | 2085 | 1.07k | MCOperand_CreateImm0(Inst, (Imm)); \ | 2086 | 1.07k | return Success; \ | 2087 | 1.07k | } |
AArch64Disassembler.c:DecodeSImm_4 Line | Count | Source | 2078 | 4.37k | { \ | 2079 | 4.37k | if (Imm & ~((1LL << Bits) - 1)) \ | 2080 | 4.37k | return Fail; \ | 2081 | 4.37k | \ | 2082 | 4.37k | if (Imm & (1 << (Bits - 1))) \ | 2083 | 4.37k | Imm |= ~((1LL << Bits) - 1); \ | 2084 | 4.37k | \ | 2085 | 4.37k | MCOperand_CreateImm0(Inst, (Imm)); \ | 2086 | 4.37k | return Success; \ | 2087 | 4.37k | } |
AArch64Disassembler.c:DecodeSImm_6 Line | Count | Source | 2078 | 225 | { \ | 2079 | 225 | if (Imm & ~((1LL << Bits) - 1)) \ | 2080 | 225 | return Fail; \ | 2081 | 225 | \ | 2082 | 225 | if (Imm & (1 << (Bits - 1))) \ | 2083 | 225 | Imm |= ~((1LL << Bits) - 1); \ | 2084 | 225 | \ | 2085 | 225 | MCOperand_CreateImm0(Inst, (Imm)); \ | 2086 | 225 | return Success; \ | 2087 | 225 | } |
AArch64Disassembler.c:DecodeSImm_8 Line | Count | Source | 2078 | 344 | { \ | 2079 | 344 | if (Imm & ~((1LL << Bits) - 1)) \ | 2080 | 344 | return Fail; \ | 2081 | 344 | \ | 2082 | 344 | if (Imm & (1 << (Bits - 1))) \ | 2083 | 344 | Imm |= ~((1LL << Bits) - 1); \ | 2084 | 344 | \ | 2085 | 344 | MCOperand_CreateImm0(Inst, (Imm)); \ | 2086 | 344 | return Success; \ | 2087 | 344 | } |
AArch64Disassembler.c:DecodeSImm_9 Line | Count | Source | 2078 | 551 | { \ | 2079 | 551 | if (Imm & ~((1LL << Bits) - 1)) \ | 2080 | 551 | return Fail; \ | 2081 | 551 | \ | 2082 | 551 | if (Imm & (1 << (Bits - 1))) \ | 2083 | 551 | Imm |= ~((1LL << Bits) - 1); \ | 2084 | 551 | \ | 2085 | 551 | MCOperand_CreateImm0(Inst, (Imm)); \ | 2086 | 551 | return Success; \ | 2087 | 551 | } |
AArch64Disassembler.c:DecodeSImm_10 Line | Count | Source | 2078 | 456 | { \ | 2079 | 456 | if (Imm & ~((1LL << Bits) - 1)) \ | 2080 | 456 | return Fail; \ | 2081 | 456 | \ | 2082 | 456 | if (Imm & (1 << (Bits - 1))) \ | 2083 | 456 | Imm |= ~((1LL << Bits) - 1); \ | 2084 | 456 | \ | 2085 | 456 | MCOperand_CreateImm0(Inst, (Imm)); \ | 2086 | 456 | return Success; \ | 2087 | 456 | } |
|
2088 | | DEFINE_DecodeSImm(4); |
2089 | | DEFINE_DecodeSImm(5); |
2090 | | DEFINE_DecodeSImm(6); |
2091 | | DEFINE_DecodeSImm(8); |
2092 | | DEFINE_DecodeSImm(9); |
2093 | | DEFINE_DecodeSImm(10); |
2094 | | |
2095 | | // Decode 8-bit signed/unsigned immediate for a given element width. |
2096 | | #define DEFINE_DecodeImm8OptLsl(ElementWidth) \ |
2097 | | static DecodeStatus CONCAT(DecodeImm8OptLsl, ElementWidth)( \ |
2098 | | MCInst * Inst, unsigned Imm, uint64_t Addr, \ |
2099 | | const void *Decoder) \ |
2100 | 2.38k | { \ |
2101 | 2.38k | unsigned Val = (uint8_t)Imm; \ |
2102 | 2.38k | unsigned Shift = (Imm & 0x100) ? 8 : 0; \ |
2103 | 2.38k | if (ElementWidth == 8 && Shift) \ |
2104 | 2.38k | return Fail; \ |
2105 | 2.38k | MCOperand_CreateImm0(Inst, (Val)); \ |
2106 | 2.38k | MCOperand_CreateImm0(Inst, (Shift)); \ |
2107 | 2.38k | return Success; \ |
2108 | 2.38k | } AArch64Disassembler.c:DecodeImm8OptLsl_8 Line | Count | Source | 2100 | 184 | { \ | 2101 | 184 | unsigned Val = (uint8_t)Imm; \ | 2102 | 184 | unsigned Shift = (Imm & 0x100) ? 8 : 0; \ | 2103 | 184 | if (ElementWidth == 8 && Shift) \ | 2104 | 184 | return Fail; \ | 2105 | 184 | MCOperand_CreateImm0(Inst, (Val)); \ | 2106 | 180 | MCOperand_CreateImm0(Inst, (Shift)); \ | 2107 | 180 | return Success; \ | 2108 | 184 | } |
AArch64Disassembler.c:DecodeImm8OptLsl_16 Line | Count | Source | 2100 | 894 | { \ | 2101 | 894 | unsigned Val = (uint8_t)Imm; \ | 2102 | 894 | unsigned Shift = (Imm & 0x100) ? 8 : 0; \ | 2103 | 894 | if (ElementWidth == 8 && Shift) \ | 2104 | 894 | return Fail; \ | 2105 | 894 | MCOperand_CreateImm0(Inst, (Val)); \ | 2106 | 894 | MCOperand_CreateImm0(Inst, (Shift)); \ | 2107 | 894 | return Success; \ | 2108 | 894 | } |
AArch64Disassembler.c:DecodeImm8OptLsl_32 Line | Count | Source | 2100 | 769 | { \ | 2101 | 769 | unsigned Val = (uint8_t)Imm; \ | 2102 | 769 | unsigned Shift = (Imm & 0x100) ? 8 : 0; \ | 2103 | 769 | if (ElementWidth == 8 && Shift) \ | 2104 | 769 | return Fail; \ | 2105 | 769 | MCOperand_CreateImm0(Inst, (Val)); \ | 2106 | 769 | MCOperand_CreateImm0(Inst, (Shift)); \ | 2107 | 769 | return Success; \ | 2108 | 769 | } |
AArch64Disassembler.c:DecodeImm8OptLsl_64 Line | Count | Source | 2100 | 542 | { \ | 2101 | 542 | unsigned Val = (uint8_t)Imm; \ | 2102 | 542 | unsigned Shift = (Imm & 0x100) ? 8 : 0; \ | 2103 | 542 | if (ElementWidth == 8 && Shift) \ | 2104 | 542 | return Fail; \ | 2105 | 542 | MCOperand_CreateImm0(Inst, (Val)); \ | 2106 | 542 | MCOperand_CreateImm0(Inst, (Shift)); \ | 2107 | 542 | return Success; \ | 2108 | 542 | } |
|
2109 | | DEFINE_DecodeImm8OptLsl(8); |
2110 | | DEFINE_DecodeImm8OptLsl(16); |
2111 | | DEFINE_DecodeImm8OptLsl(32); |
2112 | | DEFINE_DecodeImm8OptLsl(64); |
2113 | | |
2114 | | // Decode uimm4 ranged from 1-16. |
2115 | | static DecodeStatus DecodeSVEIncDecImm(MCInst *Inst, unsigned Imm, |
2116 | | uint64_t Addr, const void *Decoder) |
2117 | 3.56k | { |
2118 | 3.56k | MCOperand_CreateImm0(Inst, (Imm + 1)); |
2119 | 3.56k | return Success; |
2120 | 3.56k | } |
2121 | | |
2122 | | static DecodeStatus DecodeSVCROp(MCInst *Inst, unsigned Imm, uint64_t Address, |
2123 | | const void *Decoder) |
2124 | 1.12k | { |
2125 | 1.12k | if (AArch64SVCR_lookupSVCRByEncoding(Imm)) { |
2126 | 205 | MCOperand_CreateImm0(Inst, (Imm)); |
2127 | 205 | return Success; |
2128 | 205 | } |
2129 | 921 | return Fail; |
2130 | 1.12k | } |
2131 | | |
2132 | | static DecodeStatus DecodeCPYMemOpInstruction(MCInst *Inst, uint32_t insn, |
2133 | | uint64_t Addr, |
2134 | | const void *Decoder) |
2135 | 367 | { |
2136 | 367 | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
2137 | 367 | unsigned Rs = fieldFromInstruction_4(insn, 16, 5); |
2138 | 367 | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
2139 | | |
2140 | | // None of the registers may alias: if they do, then the instruction is not |
2141 | | // merely unpredictable but actually entirely unallocated. |
2142 | 367 | if (Rd == Rs || Rs == Rn || Rd == Rn) |
2143 | 4 | return MCDisassembler_Fail; |
2144 | | |
2145 | | // All three register operands are written back, so they all appear |
2146 | | // twice in the operand list, once as outputs and once as inputs. |
2147 | 363 | if (!DecodeGPR64commonRegisterClass(Inst, Rd, Addr, Decoder) || |
2148 | 363 | !DecodeGPR64commonRegisterClass(Inst, Rs, Addr, Decoder) || |
2149 | 363 | !DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder) || |
2150 | 363 | !DecodeGPR64commonRegisterClass(Inst, Rd, Addr, Decoder) || |
2151 | 363 | !DecodeGPR64commonRegisterClass(Inst, Rs, Addr, Decoder) || |
2152 | 363 | !DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder)) |
2153 | 2 | return MCDisassembler_Fail; |
2154 | | |
2155 | 361 | return MCDisassembler_Success; |
2156 | 363 | } |
2157 | | |
2158 | | static DecodeStatus DecodeSETMemOpInstruction(MCInst *Inst, uint32_t insn, |
2159 | | uint64_t Addr, |
2160 | | const void *Decoder) |
2161 | 174 | { |
2162 | 174 | unsigned Rd = fieldFromInstruction_4(insn, 0, 5); |
2163 | 174 | unsigned Rm = fieldFromInstruction_4(insn, 16, 5); |
2164 | 174 | unsigned Rn = fieldFromInstruction_4(insn, 5, 5); |
2165 | | |
2166 | | // None of the registers may alias: if they do, then the instruction is not |
2167 | | // merely unpredictable but actually entirely unallocated. |
2168 | 174 | if (Rd == Rm || Rm == Rn || Rd == Rn) |
2169 | 3 | return MCDisassembler_Fail; |
2170 | | |
2171 | | // Rd and Rn (not Rm) register operands are written back, so they appear |
2172 | | // twice in the operand list, once as outputs and once as inputs. |
2173 | 171 | if (!DecodeGPR64commonRegisterClass(Inst, Rd, Addr, Decoder) || |
2174 | 171 | !DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder) || |
2175 | 171 | !DecodeGPR64commonRegisterClass(Inst, Rd, Addr, Decoder) || |
2176 | 171 | !DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder) || |
2177 | 171 | !DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder)) |
2178 | 1 | return MCDisassembler_Fail; |
2179 | | |
2180 | 170 | return MCDisassembler_Success; |
2181 | 171 | } |
2182 | | |
2183 | | static DecodeStatus DecodePRFMRegInstruction(MCInst *Inst, uint32_t insn, |
2184 | | uint64_t Addr, const void *Decoder) |
2185 | 368 | { |
2186 | | // PRFM with Rt = '11xxx' should be decoded as RPRFM. |
2187 | | // Fail to decode and defer to fallback decoder table to decode RPRFM. |
2188 | 368 | unsigned Mask = 0x18; |
2189 | 368 | uint64_t Rt = fieldFromInstruction_4(insn, 0, 5); |
2190 | 368 | if ((Rt & Mask) == Mask) |
2191 | 279 | return Fail; |
2192 | | |
2193 | 89 | uint64_t Rn = fieldFromInstruction_4(insn, 5, 5); |
2194 | 89 | uint64_t Shift = fieldFromInstruction_4(insn, 12, 1); |
2195 | 89 | uint64_t Extend = fieldFromInstruction_4(insn, 15, 1); |
2196 | 89 | uint64_t Rm = fieldFromInstruction_4(insn, 16, 5); |
2197 | | |
2198 | 89 | MCOperand_CreateImm0(Inst, (Rt)); |
2199 | 89 | DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder); |
2200 | | |
2201 | 89 | switch (MCInst_getOpcode(Inst)) { |
2202 | 0 | default: |
2203 | 0 | return Fail; |
2204 | 46 | case AArch64_PRFMroW: |
2205 | 46 | DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder); |
2206 | 46 | break; |
2207 | 43 | case AArch64_PRFMroX: |
2208 | 43 | DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder); |
2209 | 43 | break; |
2210 | 89 | } |
2211 | | |
2212 | 89 | DecodeMemExtend(Inst, (Extend << 1) | Shift, Addr, Decoder); |
2213 | | |
2214 | 89 | return Success; |
2215 | 89 | } |