/src/capstonev5/arch/AArch64/AArch64InstPrinter.c
Line | Count | Source (jump to first uncovered line) |
1 | | //==-- AArch64InstPrinter.cpp - Convert AArch64 MCInst to assembly syntax --==// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | // |
10 | | // This class prints an AArch64 MCInst to a .s file. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | /* Capstone Disassembly Engine */ |
15 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2016 */ |
16 | | |
17 | | #ifdef CAPSTONE_HAS_ARM64 |
18 | | |
19 | | #include <capstone/platform.h> |
20 | | #include <stdio.h> |
21 | | #include <stdlib.h> |
22 | | |
23 | | #include "AArch64InstPrinter.h" |
24 | | #include "AArch64Disassembler.h" |
25 | | #include "AArch64BaseInfo.h" |
26 | | #include "../../utils.h" |
27 | | #include "../../MCInst.h" |
28 | | #include "../../SStream.h" |
29 | | #include "../../MCRegisterInfo.h" |
30 | | #include "../../MathExtras.h" |
31 | | |
32 | | #include "AArch64Mapping.h" |
33 | | #include "AArch64AddressingModes.h" |
34 | | |
35 | | #define GET_REGINFO_ENUM |
36 | | #include "AArch64GenRegisterInfo.inc" |
37 | | |
38 | | #define GET_INSTRINFO_ENUM |
39 | | #include "AArch64GenInstrInfo.inc" |
40 | | |
41 | | #include "AArch64GenSubtargetInfo.inc" |
42 | | |
43 | | |
44 | | static const char *getRegisterName(unsigned RegNo, unsigned AltIdx); |
45 | | static void printOperand(MCInst *MI, unsigned OpNum, SStream *O); |
46 | | static bool printSysAlias(MCInst *MI, SStream *O); |
47 | | static char *printAliasInstr(MCInst *MI, SStream *OS, MCRegisterInfo *MRI); |
48 | | static void printInstruction(MCInst *MI, SStream *O); |
49 | | static void printShifter(MCInst *MI, unsigned OpNum, SStream *O); |
50 | | static void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx, |
51 | | unsigned PrintMethodIdx, SStream *OS); |
52 | | |
53 | | |
54 | | static cs_ac_type get_op_access(cs_struct *h, unsigned int id, unsigned int index) |
55 | 801k | { |
56 | 801k | #ifndef CAPSTONE_DIET |
57 | 801k | const uint8_t *arr = AArch64_get_op_access(h, id); |
58 | | |
59 | 801k | if (arr[index] == CS_AC_IGNORE) |
60 | 0 | return 0; |
61 | | |
62 | 801k | return arr[index]; |
63 | | #else |
64 | | return 0; |
65 | | #endif |
66 | 801k | } |
67 | | |
68 | | static void op_addImm(MCInst *MI, int v) |
69 | 1.36k | { |
70 | 1.36k | if (MI->csh->detail) { |
71 | 1.36k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
72 | 1.36k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = v; |
73 | 1.36k | MI->flat_insn->detail->arm64.op_count++; |
74 | 1.36k | } |
75 | 1.36k | } |
76 | | |
77 | | static void set_sme_index(MCInst *MI, bool status) |
78 | 6.43k | { |
79 | | // Doing SME Index operand |
80 | 6.43k | MI->csh->doing_SME_Index = status; |
81 | | |
82 | 6.43k | if (MI->csh->detail != CS_OPT_ON) |
83 | 0 | return; |
84 | | |
85 | 6.43k | if (status) { |
86 | 4.58k | unsigned prevOpNum = MI->flat_insn->detail->arm64.op_count - 1; |
87 | 4.58k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, prevOpNum)); |
88 | | // Replace previous SME register operand with an OP_SME_INDEX operand |
89 | 4.58k | MI->flat_insn->detail->arm64.operands[prevOpNum].type = ARM64_OP_SME_INDEX; |
90 | 4.58k | MI->flat_insn->detail->arm64.operands[prevOpNum].sme_index.reg = Reg; |
91 | 4.58k | MI->flat_insn->detail->arm64.operands[prevOpNum].sme_index.base = ARM64_REG_INVALID; |
92 | 4.58k | MI->flat_insn->detail->arm64.operands[prevOpNum].sme_index.disp = 0; |
93 | 4.58k | } |
94 | 6.43k | } |
95 | | |
96 | | static void set_mem_access(MCInst *MI, bool status) |
97 | 264k | { |
98 | | // If status == false, check if this is meant for SME_index |
99 | 264k | if(!status && MI->csh->doing_SME_Index) { |
100 | 2.72k | MI->csh->doing_SME_Index = status; |
101 | 2.72k | return; |
102 | 2.72k | } |
103 | | |
104 | | // Doing Memory Operation |
105 | 261k | MI->csh->doing_mem = status; |
106 | | |
107 | | |
108 | 261k | if (MI->csh->detail != CS_OPT_ON) |
109 | 0 | return; |
110 | | |
111 | 261k | if (status) { |
112 | 130k | #ifndef CAPSTONE_DIET |
113 | 130k | uint8_t access; |
114 | 130k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
115 | 130k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
116 | 130k | MI->ac_idx++; |
117 | 130k | #endif |
118 | 130k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_MEM; |
119 | 130k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.base = ARM64_REG_INVALID; |
120 | 130k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.index = ARM64_REG_INVALID; |
121 | 130k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = 0; |
122 | 130k | } else { |
123 | | // done, create the next operand slot |
124 | 130k | MI->flat_insn->detail->arm64.op_count++; |
125 | 130k | } |
126 | 261k | } |
127 | | |
128 | | void AArch64_printInst(MCInst *MI, SStream *O, void *Info) |
129 | 284k | { |
130 | | // Check for special encodings and print the canonical alias instead. |
131 | 284k | unsigned Opcode = MCInst_getOpcode(MI); |
132 | 284k | int LSB, Width; |
133 | 284k | char *mnem; |
134 | | |
135 | | // printf(">>> opcode = %u\n", MCInst_getOpcode(MI)); |
136 | | |
137 | 284k | if (Opcode == AArch64_SYSxt && printSysAlias(MI, O)) |
138 | 581 | return; |
139 | | |
140 | | // SBFM/UBFM should print to a nicer aliased form if possible. |
141 | 284k | if (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri || |
142 | 284k | Opcode == AArch64_UBFMXri || Opcode == AArch64_UBFMWri) { |
143 | 5.78k | bool IsSigned = (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri); |
144 | 5.78k | bool Is64Bit = (Opcode == AArch64_SBFMXri || Opcode == AArch64_UBFMXri); |
145 | | |
146 | 5.78k | MCOperand *Op0 = MCInst_getOperand(MI, 0); |
147 | 5.78k | MCOperand *Op1 = MCInst_getOperand(MI, 1); |
148 | 5.78k | MCOperand *Op2 = MCInst_getOperand(MI, 2); |
149 | 5.78k | MCOperand *Op3 = MCInst_getOperand(MI, 3); |
150 | | |
151 | 5.78k | if (MCOperand_isImm(Op2) && MCOperand_getImm(Op2) == 0 && MCOperand_isImm(Op3)) { |
152 | 4.84k | const char *AsmMnemonic = NULL; |
153 | | |
154 | 4.84k | switch (MCOperand_getImm(Op3)) { |
155 | 498 | default: |
156 | 498 | break; |
157 | | |
158 | 1.54k | case 7: |
159 | 1.54k | if (IsSigned) |
160 | 1.45k | AsmMnemonic = "sxtb"; |
161 | 87 | else if (!Is64Bit) |
162 | 66 | AsmMnemonic = "uxtb"; |
163 | 1.54k | break; |
164 | | |
165 | 2.37k | case 15: |
166 | 2.37k | if (IsSigned) |
167 | 2.31k | AsmMnemonic = "sxth"; |
168 | 52 | else if (!Is64Bit) |
169 | 34 | AsmMnemonic = "uxth"; |
170 | 2.37k | break; |
171 | | |
172 | 429 | case 31: |
173 | | // *xtw is only valid for signed 64-bit operations. |
174 | 429 | if (Is64Bit && IsSigned) |
175 | 185 | AsmMnemonic = "sxtw"; |
176 | 429 | break; |
177 | 4.84k | } |
178 | | |
179 | 4.84k | if (AsmMnemonic) { |
180 | 4.05k | SStream_concat(O, "%s\t%s, %s", AsmMnemonic, |
181 | 4.05k | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName), |
182 | 4.05k | getRegisterName(getWRegFromXReg(MCOperand_getReg(Op1)), AArch64_NoRegAltName)); |
183 | | |
184 | 4.05k | if (MI->csh->detail) { |
185 | 4.05k | #ifndef CAPSTONE_DIET |
186 | 4.05k | uint8_t access; |
187 | 4.05k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
188 | 4.05k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
189 | 4.05k | MI->ac_idx++; |
190 | 4.05k | #endif |
191 | 4.05k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
192 | 4.05k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
193 | 4.05k | MI->flat_insn->detail->arm64.op_count++; |
194 | 4.05k | #ifndef CAPSTONE_DIET |
195 | 4.05k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
196 | 4.05k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
197 | 4.05k | MI->ac_idx++; |
198 | 4.05k | #endif |
199 | 4.05k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
200 | 4.05k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = getWRegFromXReg(MCOperand_getReg(Op1)); |
201 | 4.05k | MI->flat_insn->detail->arm64.op_count++; |
202 | 4.05k | } |
203 | | |
204 | 4.05k | MCInst_setOpcodePub(MI, AArch64_map_insn(AsmMnemonic)); |
205 | | |
206 | 4.05k | return; |
207 | 4.05k | } |
208 | 4.84k | } |
209 | | |
210 | | // All immediate shifts are aliases, implemented using the Bitfield |
211 | | // instruction. In all cases the immediate shift amount shift must be in |
212 | | // the range 0 to (reg.size -1). |
213 | 1.72k | if (MCOperand_isImm(Op2) && MCOperand_isImm(Op3)) { |
214 | 1.72k | const char *AsmMnemonic = NULL; |
215 | 1.72k | int shift = 0; |
216 | 1.72k | int immr = (int)MCOperand_getImm(Op2); |
217 | 1.72k | int imms = (int)MCOperand_getImm(Op3); |
218 | | |
219 | 1.72k | if (Opcode == AArch64_UBFMWri && imms != 0x1F && ((imms + 1) == immr)) { |
220 | 34 | AsmMnemonic = "lsl"; |
221 | 34 | shift = 31 - imms; |
222 | 1.69k | } else if (Opcode == AArch64_UBFMXri && imms != 0x3f && |
223 | 1.69k | ((imms + 1 == immr))) { |
224 | 76 | AsmMnemonic = "lsl"; |
225 | 76 | shift = 63 - imms; |
226 | 1.61k | } else if (Opcode == AArch64_UBFMWri && imms == 0x1f) { |
227 | 18 | AsmMnemonic = "lsr"; |
228 | 18 | shift = immr; |
229 | 1.60k | } else if (Opcode == AArch64_UBFMXri && imms == 0x3f) { |
230 | 83 | AsmMnemonic = "lsr"; |
231 | 83 | shift = immr; |
232 | 1.51k | } else if (Opcode == AArch64_SBFMWri && imms == 0x1f) { |
233 | 158 | AsmMnemonic = "asr"; |
234 | 158 | shift = immr; |
235 | 1.35k | } else if (Opcode == AArch64_SBFMXri && imms == 0x3f) { |
236 | 80 | AsmMnemonic = "asr"; |
237 | 80 | shift = immr; |
238 | 80 | } |
239 | | |
240 | 1.72k | if (AsmMnemonic) { |
241 | 449 | SStream_concat(O, "%s\t%s, %s, ", AsmMnemonic, |
242 | 449 | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName), |
243 | 449 | getRegisterName(MCOperand_getReg(Op1), AArch64_NoRegAltName)); |
244 | | |
245 | 449 | printInt32Bang(O, shift); |
246 | | |
247 | 449 | MCInst_setOpcodePub(MI, AArch64_map_insn(AsmMnemonic)); |
248 | | |
249 | 449 | if (MI->csh->detail) { |
250 | 449 | #ifndef CAPSTONE_DIET |
251 | 449 | uint8_t access; |
252 | 449 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
253 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
254 | 449 | MI->ac_idx++; |
255 | 449 | #endif |
256 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
257 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
258 | 449 | MI->flat_insn->detail->arm64.op_count++; |
259 | 449 | #ifndef CAPSTONE_DIET |
260 | 449 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
261 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
262 | 449 | MI->ac_idx++; |
263 | 449 | #endif |
264 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
265 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1); |
266 | 449 | MI->flat_insn->detail->arm64.op_count++; |
267 | 449 | #ifndef CAPSTONE_DIET |
268 | 449 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
269 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
270 | 449 | MI->ac_idx++; |
271 | 449 | #endif |
272 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
273 | 449 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = shift; |
274 | 449 | MI->flat_insn->detail->arm64.op_count++; |
275 | 449 | } |
276 | | |
277 | 449 | return; |
278 | 449 | } |
279 | 1.72k | } |
280 | | |
281 | | // SBFIZ/UBFIZ aliases |
282 | 1.27k | if (MCOperand_getImm(Op2) > MCOperand_getImm(Op3)) { |
283 | 505 | SStream_concat(O, "%s\t%s, %s, ", (IsSigned ? "sbfiz" : "ubfiz"), |
284 | 505 | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName), |
285 | 505 | getRegisterName(MCOperand_getReg(Op1), AArch64_NoRegAltName)); |
286 | | |
287 | 505 | printInt32Bang(O, (int)((Is64Bit ? 64 : 32) - MCOperand_getImm(Op2))); |
288 | | |
289 | 505 | SStream_concat0(O, ", "); |
290 | | |
291 | 505 | printInt32Bang(O, (int)MCOperand_getImm(Op3) + 1); |
292 | | |
293 | 505 | MCInst_setOpcodePub(MI, AArch64_map_insn(IsSigned ? "sbfiz" : "ubfiz")); |
294 | | |
295 | 505 | if (MI->csh->detail) { |
296 | 505 | #ifndef CAPSTONE_DIET |
297 | 505 | uint8_t access; |
298 | 505 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
299 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
300 | 505 | MI->ac_idx++; |
301 | 505 | #endif |
302 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
303 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
304 | 505 | MI->flat_insn->detail->arm64.op_count++; |
305 | 505 | #ifndef CAPSTONE_DIET |
306 | 505 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
307 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
308 | 505 | MI->ac_idx++; |
309 | 505 | #endif |
310 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
311 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1); |
312 | 505 | MI->flat_insn->detail->arm64.op_count++; |
313 | 505 | #ifndef CAPSTONE_DIET |
314 | 505 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
315 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
316 | 505 | MI->ac_idx++; |
317 | 505 | #endif |
318 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
319 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (Is64Bit ? 64 : 32) - (int)MCOperand_getImm(Op2); |
320 | 505 | MI->flat_insn->detail->arm64.op_count++; |
321 | 505 | #ifndef CAPSTONE_DIET |
322 | 505 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
323 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
324 | 505 | MI->ac_idx++; |
325 | 505 | #endif |
326 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
327 | 505 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op3) + 1; |
328 | 505 | MI->flat_insn->detail->arm64.op_count++; |
329 | 505 | } |
330 | | |
331 | 505 | return; |
332 | 505 | } |
333 | | |
334 | | // Otherwise SBFX/UBFX is the preferred form |
335 | 774 | SStream_concat(O, "%s\t%s, %s, ", (IsSigned ? "sbfx" : "ubfx"), |
336 | 774 | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName), |
337 | 774 | getRegisterName(MCOperand_getReg(Op1), AArch64_NoRegAltName)); |
338 | | |
339 | 774 | printInt32Bang(O, (int)MCOperand_getImm(Op2)); |
340 | 774 | SStream_concat0(O, ", "); |
341 | 774 | printInt32Bang(O, (int)MCOperand_getImm(Op3) - (int)MCOperand_getImm(Op2) + 1); |
342 | | |
343 | 774 | MCInst_setOpcodePub(MI, AArch64_map_insn(IsSigned ? "sbfx" : "ubfx")); |
344 | | |
345 | 774 | if (MI->csh->detail) { |
346 | 774 | #ifndef CAPSTONE_DIET |
347 | 774 | uint8_t access; |
348 | 774 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
349 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
350 | 774 | MI->ac_idx++; |
351 | 774 | #endif |
352 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
353 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
354 | 774 | MI->flat_insn->detail->arm64.op_count++; |
355 | 774 | #ifndef CAPSTONE_DIET |
356 | 774 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
357 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
358 | 774 | MI->ac_idx++; |
359 | 774 | #endif |
360 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
361 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1); |
362 | 774 | MI->flat_insn->detail->arm64.op_count++; |
363 | 774 | #ifndef CAPSTONE_DIET |
364 | 774 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
365 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
366 | 774 | MI->ac_idx++; |
367 | 774 | #endif |
368 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
369 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op2); |
370 | 774 | MI->flat_insn->detail->arm64.op_count++; |
371 | 774 | #ifndef CAPSTONE_DIET |
372 | 774 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
373 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
374 | 774 | MI->ac_idx++; |
375 | 774 | #endif |
376 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
377 | 774 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op3) - MCOperand_getImm(Op2) + 1; |
378 | 774 | MI->flat_insn->detail->arm64.op_count++; |
379 | 774 | } |
380 | | |
381 | 774 | return; |
382 | 1.27k | } |
383 | | |
384 | 278k | if (Opcode == AArch64_BFMXri || Opcode == AArch64_BFMWri) { |
385 | 731 | MCOperand *Op0 = MCInst_getOperand(MI, 0); // Op1 == Op0 |
386 | 731 | MCOperand *Op2 = MCInst_getOperand(MI, 2); |
387 | 731 | int ImmR = (int)MCOperand_getImm(MCInst_getOperand(MI, 3)); |
388 | 731 | int ImmS = (int)MCOperand_getImm(MCInst_getOperand(MI, 4)); |
389 | | |
390 | 731 | if ((MCOperand_getReg(Op2) == AArch64_WZR || MCOperand_getReg(Op2) == AArch64_XZR) && |
391 | 731 | (ImmR == 0 || ImmS < ImmR)) { |
392 | | // BFC takes precedence over its entire range, sligtly differently to BFI. |
393 | 92 | int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32; |
394 | 92 | int LSB = (BitWidth - ImmR) % BitWidth; |
395 | 92 | int Width = ImmS + 1; |
396 | | |
397 | 92 | SStream_concat(O, "bfc\t%s, ", |
398 | 92 | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName)); |
399 | | |
400 | 92 | printInt32Bang(O, LSB); |
401 | 92 | SStream_concat0(O, ", "); |
402 | 92 | printInt32Bang(O, Width); |
403 | 92 | MCInst_setOpcodePub(MI, AArch64_map_insn("bfc")); |
404 | | |
405 | 92 | if (MI->csh->detail) { |
406 | 92 | #ifndef CAPSTONE_DIET |
407 | 92 | uint8_t access; |
408 | 92 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
409 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
410 | 92 | MI->ac_idx++; |
411 | 92 | #endif |
412 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
413 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
414 | 92 | MI->flat_insn->detail->arm64.op_count++; |
415 | | |
416 | 92 | #ifndef CAPSTONE_DIET |
417 | 92 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
418 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
419 | 92 | MI->ac_idx++; |
420 | 92 | #endif |
421 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
422 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = LSB; |
423 | 92 | MI->flat_insn->detail->arm64.op_count++; |
424 | 92 | #ifndef CAPSTONE_DIET |
425 | 92 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
426 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
427 | 92 | MI->ac_idx++; |
428 | 92 | #endif |
429 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
430 | 92 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Width; |
431 | 92 | MI->flat_insn->detail->arm64.op_count++; |
432 | 92 | } |
433 | | |
434 | 92 | return; |
435 | 639 | } else if (ImmS < ImmR) { |
436 | | // BFI alias |
437 | 277 | int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32; |
438 | 277 | LSB = (BitWidth - ImmR) % BitWidth; |
439 | 277 | Width = ImmS + 1; |
440 | | |
441 | 277 | SStream_concat(O, "bfi\t%s, %s, ", |
442 | 277 | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName), |
443 | 277 | getRegisterName(MCOperand_getReg(Op2), AArch64_NoRegAltName)); |
444 | | |
445 | 277 | printInt32Bang(O, LSB); |
446 | 277 | SStream_concat0(O, ", "); |
447 | 277 | printInt32Bang(O, Width); |
448 | | |
449 | 277 | MCInst_setOpcodePub(MI, AArch64_map_insn("bfi")); |
450 | | |
451 | 277 | if (MI->csh->detail) { |
452 | 277 | #ifndef CAPSTONE_DIET |
453 | 277 | uint8_t access; |
454 | 277 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
455 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
456 | 277 | MI->ac_idx++; |
457 | 277 | #endif |
458 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
459 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
460 | 277 | MI->flat_insn->detail->arm64.op_count++; |
461 | 277 | #ifndef CAPSTONE_DIET |
462 | 277 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
463 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
464 | 277 | MI->ac_idx++; |
465 | 277 | #endif |
466 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
467 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op2); |
468 | 277 | MI->flat_insn->detail->arm64.op_count++; |
469 | 277 | #ifndef CAPSTONE_DIET |
470 | 277 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
471 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
472 | 277 | MI->ac_idx++; |
473 | 277 | #endif |
474 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
475 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = LSB; |
476 | 277 | MI->flat_insn->detail->arm64.op_count++; |
477 | 277 | #ifndef CAPSTONE_DIET |
478 | 277 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
479 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
480 | 277 | MI->ac_idx++; |
481 | 277 | #endif |
482 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
483 | 277 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Width; |
484 | 277 | MI->flat_insn->detail->arm64.op_count++; |
485 | 277 | } |
486 | | |
487 | 277 | return; |
488 | 277 | } |
489 | | |
490 | 362 | LSB = ImmR; |
491 | 362 | Width = ImmS - ImmR + 1; |
492 | | // Otherwise BFXIL the preferred form |
493 | 362 | SStream_concat(O, "bfxil\t%s, %s, ", |
494 | 362 | getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName), |
495 | 362 | getRegisterName(MCOperand_getReg(Op2), AArch64_NoRegAltName)); |
496 | | |
497 | 362 | printInt32Bang(O, LSB); |
498 | 362 | SStream_concat0(O, ", "); |
499 | 362 | printInt32Bang(O, Width); |
500 | | |
501 | 362 | MCInst_setOpcodePub(MI, AArch64_map_insn("bfxil")); |
502 | | |
503 | 362 | if (MI->csh->detail) { |
504 | 362 | #ifndef CAPSTONE_DIET |
505 | 362 | uint8_t access; |
506 | 362 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
507 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
508 | 362 | MI->ac_idx++; |
509 | 362 | #endif |
510 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
511 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0); |
512 | 362 | MI->flat_insn->detail->arm64.op_count++; |
513 | 362 | #ifndef CAPSTONE_DIET |
514 | 362 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
515 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
516 | 362 | MI->ac_idx++; |
517 | 362 | #endif |
518 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
519 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op2); |
520 | 362 | MI->flat_insn->detail->arm64.op_count++; |
521 | 362 | #ifndef CAPSTONE_DIET |
522 | 362 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
523 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
524 | 362 | MI->ac_idx++; |
525 | 362 | #endif |
526 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
527 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = LSB; |
528 | 362 | MI->flat_insn->detail->arm64.op_count++; |
529 | 362 | #ifndef CAPSTONE_DIET |
530 | 362 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
531 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
532 | 362 | MI->ac_idx++; |
533 | 362 | #endif |
534 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
535 | 362 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Width; |
536 | 362 | MI->flat_insn->detail->arm64.op_count++; |
537 | 362 | } |
538 | | |
539 | 362 | return; |
540 | 731 | } |
541 | | |
542 | | // MOVZ, MOVN and "ORR wzr, #imm" instructions are aliases for MOV, but their |
543 | | // domains overlap so they need to be prioritized. The chain is "MOVZ lsl #0 > |
544 | | // MOVZ lsl #N > MOVN lsl #0 > MOVN lsl #N > ORR". The highest instruction |
545 | | // that can represent the move is the MOV alias, and the rest get printed |
546 | | // normally. |
547 | 277k | if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi) && |
548 | 277k | MCOperand_isImm(MCInst_getOperand(MI, 1)) && MCOperand_isImm(MCInst_getOperand(MI, 2))) { |
549 | 1.24k | int RegWidth = Opcode == AArch64_MOVZXi ? 64 : 32; |
550 | 1.24k | int Shift = MCOperand_getImm(MCInst_getOperand(MI, 2)); |
551 | 1.24k | uint64_t Value = (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, 1)) << Shift; |
552 | | |
553 | 1.24k | if (isMOVZMovAlias(Value, Shift, |
554 | 1.24k | Opcode == AArch64_MOVZXi ? 64 : 32)) { |
555 | 1.16k | SStream_concat(O, "mov\t%s, ", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 0)), AArch64_NoRegAltName)); |
556 | | |
557 | 1.16k | printInt64Bang(O, SignExtend64(Value, RegWidth)); |
558 | | |
559 | 1.16k | if (MI->csh->detail) { |
560 | 1.16k | #ifndef CAPSTONE_DIET |
561 | 1.16k | uint8_t access; |
562 | 1.16k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
563 | 1.16k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
564 | 1.16k | MI->ac_idx++; |
565 | 1.16k | #endif |
566 | 1.16k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
567 | 1.16k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0)); |
568 | 1.16k | MI->flat_insn->detail->arm64.op_count++; |
569 | | |
570 | 1.16k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
571 | 1.16k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = SignExtend64(Value, RegWidth); |
572 | 1.16k | MI->flat_insn->detail->arm64.op_count++; |
573 | 1.16k | } |
574 | | |
575 | 1.16k | MCInst_setOpcodePub(MI, AArch64_map_insn("mov")); |
576 | | |
577 | 1.16k | return; |
578 | 1.16k | } |
579 | 1.24k | } |
580 | | |
581 | 276k | if ((Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) && |
582 | 276k | MCOperand_isImm(MCInst_getOperand(MI, 1)) && MCOperand_isImm(MCInst_getOperand(MI, 2))) { |
583 | 2.29k | int RegWidth = Opcode == AArch64_MOVNXi ? 64 : 32; |
584 | 2.29k | int Shift = MCOperand_getImm(MCInst_getOperand(MI, 2)); |
585 | 2.29k | uint64_t Value = ~((uint64_t)MCOperand_getImm(MCInst_getOperand(MI, 1)) << Shift); |
586 | | |
587 | 2.29k | if (RegWidth == 32) |
588 | 1.82k | Value = Value & 0xffffffff; |
589 | | |
590 | 2.29k | if (AArch64_AM_isMOVNMovAlias(Value, Shift, RegWidth)) { |
591 | 1.10k | SStream_concat(O, "mov\t%s, ", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 0)), AArch64_NoRegAltName)); |
592 | | |
593 | 1.10k | printInt64Bang(O, SignExtend64(Value, RegWidth)); |
594 | | |
595 | 1.10k | if (MI->csh->detail) { |
596 | 1.10k | #ifndef CAPSTONE_DIET |
597 | 1.10k | uint8_t access; |
598 | 1.10k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
599 | 1.10k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
600 | 1.10k | MI->ac_idx++; |
601 | 1.10k | #endif |
602 | 1.10k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
603 | 1.10k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0)); |
604 | 1.10k | MI->flat_insn->detail->arm64.op_count++; |
605 | | |
606 | 1.10k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
607 | 1.10k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = SignExtend64(Value, RegWidth); |
608 | 1.10k | MI->flat_insn->detail->arm64.op_count++; |
609 | 1.10k | } |
610 | | |
611 | 1.10k | MCInst_setOpcodePub(MI, AArch64_map_insn("mov")); |
612 | | |
613 | 1.10k | return; |
614 | 1.10k | } |
615 | 2.29k | } |
616 | | |
617 | 275k | if ((Opcode == AArch64_ORRXri || Opcode == AArch64_ORRWri) && |
618 | 275k | (MCOperand_getReg(MCInst_getOperand(MI, 1)) == AArch64_XZR || |
619 | 1.15k | MCOperand_getReg(MCInst_getOperand(MI, 1)) == AArch64_WZR) && |
620 | 275k | MCOperand_isImm(MCInst_getOperand(MI, 2))) { |
621 | 203 | int RegWidth = Opcode == AArch64_ORRXri ? 64 : 32; |
622 | 203 | uint64_t Value = AArch64_AM_decodeLogicalImmediate( |
623 | 203 | MCOperand_getImm(MCInst_getOperand(MI, 2)), RegWidth); |
624 | 203 | SStream_concat(O, "mov\t%s, ", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 0)), AArch64_NoRegAltName)); |
625 | | |
626 | 203 | printInt64Bang(O, SignExtend64(Value, RegWidth)); |
627 | | |
628 | 203 | if (MI->csh->detail) { |
629 | 203 | #ifndef CAPSTONE_DIET |
630 | 203 | uint8_t access; |
631 | 203 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
632 | 203 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
633 | 203 | MI->ac_idx++; |
634 | 203 | #endif |
635 | 203 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
636 | 203 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0)); |
637 | 203 | MI->flat_insn->detail->arm64.op_count++; |
638 | | |
639 | 203 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
640 | 203 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = SignExtend64(Value, RegWidth); |
641 | 203 | MI->flat_insn->detail->arm64.op_count++; |
642 | 203 | } |
643 | | |
644 | 203 | MCInst_setOpcodePub(MI, AArch64_map_insn("mov")); |
645 | | |
646 | 203 | return; |
647 | 203 | } |
648 | | |
649 | | // Instruction TSB is specified as a one operand instruction, but 'csync' is |
650 | | // not encoded, so for printing it is treated as a special case here: |
651 | 275k | if (Opcode == AArch64_TSB) { |
652 | 18 | SStream_concat0(O, "tsb\tcsync"); |
653 | 18 | MCInst_setOpcodePub(MI, AArch64_map_insn("tsb")); |
654 | 18 | return; |
655 | 18 | } |
656 | | |
657 | 275k | MI->MRI = Info; |
658 | | |
659 | 275k | mnem = printAliasInstr(MI, O, (MCRegisterInfo *)Info); |
660 | 275k | if (mnem) { |
661 | 37.3k | MCInst_setOpcodePub(MI, AArch64_map_insn(mnem)); |
662 | 37.3k | cs_mem_free(mnem); |
663 | | |
664 | 37.3k | switch(MCInst_getOpcode(MI)) { |
665 | 23.7k | default: break; |
666 | 23.7k | case AArch64_LD1i8_POST: |
667 | 159 | arm64_op_addImm(MI, 1); |
668 | 159 | break; |
669 | 197 | case AArch64_LD1i16_POST: |
670 | 197 | arm64_op_addImm(MI, 2); |
671 | 197 | break; |
672 | 1.57k | case AArch64_LD1i32_POST: |
673 | 1.57k | arm64_op_addImm(MI, 4); |
674 | 1.57k | break; |
675 | 60 | case AArch64_LD1Onev1d_POST: |
676 | 206 | case AArch64_LD1Onev2s_POST: |
677 | 216 | case AArch64_LD1Onev4h_POST: |
678 | 251 | case AArch64_LD1Onev8b_POST: |
679 | 354 | case AArch64_LD1i64_POST: |
680 | 354 | arm64_op_addImm(MI, 8); |
681 | 354 | break; |
682 | 64 | case AArch64_LD1Onev16b_POST: |
683 | 607 | case AArch64_LD1Onev2d_POST: |
684 | 645 | case AArch64_LD1Onev4s_POST: |
685 | 954 | case AArch64_LD1Onev8h_POST: |
686 | 1.02k | case AArch64_LD1Twov1d_POST: |
687 | 1.08k | case AArch64_LD1Twov2s_POST: |
688 | 1.13k | case AArch64_LD1Twov4h_POST: |
689 | 1.81k | case AArch64_LD1Twov8b_POST: |
690 | 1.81k | arm64_op_addImm(MI, 16); |
691 | 1.81k | break; |
692 | 83 | case AArch64_LD1Threev1d_POST: |
693 | 119 | case AArch64_LD1Threev2s_POST: |
694 | 137 | case AArch64_LD1Threev4h_POST: |
695 | 235 | case AArch64_LD1Threev8b_POST: |
696 | 235 | arm64_op_addImm(MI, 24); |
697 | 235 | break; |
698 | 410 | case AArch64_LD1Fourv1d_POST: |
699 | 486 | case AArch64_LD1Fourv2s_POST: |
700 | 589 | case AArch64_LD1Fourv4h_POST: |
701 | 928 | case AArch64_LD1Fourv8b_POST: |
702 | 964 | case AArch64_LD1Twov16b_POST: |
703 | 974 | case AArch64_LD1Twov2d_POST: |
704 | 1.04k | case AArch64_LD1Twov4s_POST: |
705 | 1.06k | case AArch64_LD1Twov8h_POST: |
706 | 1.06k | arm64_op_addImm(MI, 32); |
707 | 1.06k | break; |
708 | 285 | case AArch64_LD1Threev16b_POST: |
709 | 325 | case AArch64_LD1Threev2d_POST: |
710 | 376 | case AArch64_LD1Threev4s_POST: |
711 | 395 | case AArch64_LD1Threev8h_POST: |
712 | 395 | arm64_op_addImm(MI, 48); |
713 | 395 | break; |
714 | 41 | case AArch64_LD1Fourv16b_POST: |
715 | 213 | case AArch64_LD1Fourv2d_POST: |
716 | 233 | case AArch64_LD1Fourv4s_POST: |
717 | 309 | case AArch64_LD1Fourv8h_POST: |
718 | 309 | arm64_op_addImm(MI, 64); |
719 | 309 | break; |
720 | 95 | case AArch64_UMOVvi64: |
721 | 95 | arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1D); |
722 | 95 | break; |
723 | 10 | case AArch64_UMOVvi32: |
724 | 10 | arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1S); |
725 | 10 | break; |
726 | 227 | case AArch64_INSvi8gpr: |
727 | 246 | case AArch64_DUP_ZI_B: |
728 | 300 | case AArch64_CPY_ZPmI_B: |
729 | 763 | case AArch64_CPY_ZPzI_B: |
730 | 868 | case AArch64_CPY_ZPmV_B: |
731 | 1.16k | case AArch64_CPY_ZPmR_B: |
732 | 1.18k | case AArch64_DUP_ZR_B: |
733 | 1.18k | if (MI->csh->detail) { |
734 | 1.18k | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B; |
735 | 1.18k | } |
736 | 1.18k | break; |
737 | 18 | case AArch64_INSvi16gpr: |
738 | 101 | case AArch64_DUP_ZI_H: |
739 | 136 | case AArch64_CPY_ZPmI_H: |
740 | 243 | case AArch64_CPY_ZPzI_H: |
741 | 256 | case AArch64_CPY_ZPmV_H: |
742 | 325 | case AArch64_CPY_ZPmR_H: |
743 | 1.40k | case AArch64_DUP_ZR_H: |
744 | 1.47k | case AArch64_FCPY_ZPmI_H: |
745 | 1.55k | case AArch64_FDUP_ZI_H: |
746 | 1.55k | if (MI->csh->detail) { |
747 | 1.55k | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H; |
748 | 1.55k | } |
749 | 1.55k | break; |
750 | 33 | case AArch64_INSvi32gpr: |
751 | 99 | case AArch64_DUP_ZI_S: |
752 | 190 | case AArch64_CPY_ZPmI_S: |
753 | 277 | case AArch64_CPY_ZPzI_S: |
754 | 764 | case AArch64_CPY_ZPmV_S: |
755 | 782 | case AArch64_CPY_ZPmR_S: |
756 | 897 | case AArch64_DUP_ZR_S: |
757 | 932 | case AArch64_FCPY_ZPmI_S: |
758 | 969 | case AArch64_FDUP_ZI_S: |
759 | 969 | if (MI->csh->detail) { |
760 | 969 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S; |
761 | 969 | } |
762 | 969 | break; |
763 | 248 | case AArch64_INSvi64gpr: |
764 | 258 | case AArch64_DUP_ZI_D: |
765 | 356 | case AArch64_CPY_ZPmI_D: |
766 | 743 | case AArch64_CPY_ZPzI_D: |
767 | 811 | case AArch64_CPY_ZPmV_D: |
768 | 1.12k | case AArch64_CPY_ZPmR_D: |
769 | 1.30k | case AArch64_DUP_ZR_D: |
770 | 1.33k | case AArch64_FCPY_ZPmI_D: |
771 | 1.37k | case AArch64_FDUP_ZI_D: |
772 | 1.37k | if (MI->csh->detail) { |
773 | 1.37k | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D; |
774 | 1.37k | } |
775 | 1.37k | break; |
776 | 207 | case AArch64_INSvi8lane: |
777 | 275 | case AArch64_ORR_PPzPP: |
778 | 310 | case AArch64_ORRS_PPzPP: |
779 | 310 | if (MI->csh->detail) { |
780 | 310 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B; |
781 | 310 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1B; |
782 | 310 | } |
783 | 310 | break; |
784 | 70 | case AArch64_INSvi16lane: |
785 | 70 | if (MI->csh->detail) { |
786 | 70 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H; |
787 | 70 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1H; |
788 | 70 | } |
789 | 70 | break; |
790 | 22 | case AArch64_INSvi32lane: |
791 | 22 | if (MI->csh->detail) { |
792 | 22 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S; |
793 | 22 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1S; |
794 | 22 | } |
795 | 22 | break; |
796 | 94 | case AArch64_INSvi64lane: |
797 | 112 | case AArch64_ORR_ZZZ: |
798 | 112 | if (MI->csh->detail) { |
799 | 112 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D; |
800 | 112 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1D; |
801 | 112 | } |
802 | 112 | break; |
803 | 20 | case AArch64_ORRv16i8: |
804 | 39 | case AArch64_NOTv16i8: |
805 | 39 | if (MI->csh->detail) { |
806 | 39 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_16B; |
807 | 39 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_16B; |
808 | 39 | } |
809 | 39 | break; |
810 | 34 | case AArch64_ORRv8i8: |
811 | 44 | case AArch64_NOTv8i8: |
812 | 44 | if (MI->csh->detail) { |
813 | 44 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_8B; |
814 | 44 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_8B; |
815 | 44 | } |
816 | 44 | break; |
817 | 20 | case AArch64_AND_PPzPP: |
818 | 30 | case AArch64_ANDS_PPzPP: |
819 | 308 | case AArch64_EOR_PPzPP: |
820 | 342 | case AArch64_EORS_PPzPP: |
821 | 352 | case AArch64_SEL_PPPP: |
822 | 464 | case AArch64_SEL_ZPZZ_B: |
823 | 464 | if (MI->csh->detail) { |
824 | 464 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B; |
825 | 464 | MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1B; |
826 | 464 | } |
827 | 464 | break; |
828 | 35 | case AArch64_SEL_ZPZZ_D: |
829 | 35 | if (MI->csh->detail) { |
830 | 35 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D; |
831 | 35 | MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1D; |
832 | 35 | } |
833 | 35 | break; |
834 | 27 | case AArch64_SEL_ZPZZ_H: |
835 | 27 | if (MI->csh->detail) { |
836 | 27 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H; |
837 | 27 | MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1H; |
838 | 27 | } |
839 | 27 | break; |
840 | 98 | case AArch64_SEL_ZPZZ_S: |
841 | 98 | if (MI->csh->detail) { |
842 | 98 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S; |
843 | 98 | MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1S; |
844 | 98 | } |
845 | 98 | break; |
846 | 76 | case AArch64_DUP_ZZI_B: |
847 | 76 | if (MI->csh->detail) { |
848 | 76 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B; |
849 | 76 | if (MI->flat_insn->detail->arm64.op_count == 1) { |
850 | 0 | arm64_op_addReg(MI, ARM64_REG_B0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0); |
851 | 76 | } else { |
852 | 76 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1B; |
853 | 76 | } |
854 | 76 | } |
855 | 76 | break; |
856 | 72 | case AArch64_DUP_ZZI_D: |
857 | 72 | if (MI->csh->detail) { |
858 | 72 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D; |
859 | 72 | if (MI->flat_insn->detail->arm64.op_count == 1) { |
860 | 0 | arm64_op_addReg(MI, ARM64_REG_D0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0); |
861 | 72 | } else { |
862 | 72 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1D; |
863 | 72 | } |
864 | 72 | } |
865 | 72 | break; |
866 | 11 | case AArch64_DUP_ZZI_H: |
867 | 11 | if (MI->csh->detail) { |
868 | 11 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H; |
869 | 11 | if (MI->flat_insn->detail->arm64.op_count == 1) { |
870 | 0 | arm64_op_addReg(MI, ARM64_REG_H0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0); |
871 | 11 | } else { |
872 | 11 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1H; |
873 | 11 | } |
874 | 11 | } |
875 | 11 | break; |
876 | 538 | case AArch64_DUP_ZZI_Q: |
877 | 538 | if (MI->csh->detail) { |
878 | 538 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1Q; |
879 | 538 | if (MI->flat_insn->detail->arm64.op_count == 1) { |
880 | 0 | arm64_op_addReg(MI, ARM64_REG_Q0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0); |
881 | 538 | } else { |
882 | 538 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1Q; |
883 | 538 | } |
884 | 538 | } |
885 | 538 | break; |
886 | 79 | case AArch64_DUP_ZZI_S: |
887 | 79 | if (MI->csh->detail) { |
888 | 79 | MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S; |
889 | 79 | if (MI->flat_insn->detail->arm64.op_count == 1) { |
890 | 0 | arm64_op_addReg(MI, ARM64_REG_S0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0); |
891 | 79 | } else { |
892 | 79 | MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1S; |
893 | 79 | } |
894 | 79 | } |
895 | 79 | break; |
896 | | // Hacky detail filling of SMSTART and SMSTOP alias' |
897 | 348 | case AArch64_MSRpstatesvcrImm1:{ |
898 | 348 | if(MI->csh->detail){ |
899 | 348 | MI->flat_insn->detail->arm64.op_count = 2; |
900 | 348 | #ifndef CAPSTONE_DIET |
901 | 348 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
902 | 348 | MI->ac_idx++; |
903 | 348 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
904 | 348 | MI->ac_idx++; |
905 | 348 | #endif |
906 | 348 | MI->flat_insn->detail->arm64.operands[0].type = ARM64_OP_SVCR; |
907 | 348 | MI->flat_insn->detail->arm64.operands[0].sys = (unsigned)ARM64_SYSREG_SVCR; |
908 | 348 | MI->flat_insn->detail->arm64.operands[0].svcr = lookupSVCRByEncoding(MCOperand_getImm(MCInst_getOperand(MI, 0)))->Encoding; |
909 | 348 | MI->flat_insn->detail->arm64.operands[1].type = ARM64_OP_IMM; |
910 | 348 | MI->flat_insn->detail->arm64.operands[1].imm = MCOperand_getImm(MCInst_getOperand(MI, 1)); |
911 | 348 | } |
912 | 348 | break; |
913 | 352 | } |
914 | 37.3k | } |
915 | 238k | } else { |
916 | 238k | printInstruction(MI, O); |
917 | 238k | } |
918 | 275k | } |
919 | | |
920 | | static bool printSysAlias(MCInst *MI, SStream *O) |
921 | 1.24k | { |
922 | | // unsigned Opcode = MCInst_getOpcode(MI); |
923 | | //assert(Opcode == AArch64_SYSxt && "Invalid opcode for SYS alias!"); |
924 | | |
925 | 1.24k | const char *Ins; |
926 | 1.24k | uint16_t Encoding; |
927 | 1.24k | bool NeedsReg; |
928 | 1.24k | char Name[64]; |
929 | 1.24k | MCOperand *Op1 = MCInst_getOperand(MI, 0); |
930 | 1.24k | MCOperand *Cn = MCInst_getOperand(MI, 1); |
931 | 1.24k | MCOperand *Cm = MCInst_getOperand(MI, 2); |
932 | 1.24k | MCOperand *Op2 = MCInst_getOperand(MI, 3); |
933 | | |
934 | 1.24k | unsigned Op1Val = (unsigned)MCOperand_getImm(Op1); |
935 | 1.24k | unsigned CnVal = (unsigned)MCOperand_getImm(Cn); |
936 | 1.24k | unsigned CmVal = (unsigned)MCOperand_getImm(Cm); |
937 | 1.24k | unsigned Op2Val = (unsigned)MCOperand_getImm(Op2); |
938 | | |
939 | 1.24k | Encoding = Op2Val; |
940 | 1.24k | Encoding |= CmVal << 3; |
941 | 1.24k | Encoding |= CnVal << 7; |
942 | 1.24k | Encoding |= Op1Val << 11; |
943 | | |
944 | 1.24k | if (CnVal == 7) { |
945 | 1.01k | switch (CmVal) { |
946 | 13 | default: |
947 | 13 | return false; |
948 | | |
949 | | // IC aliases |
950 | 440 | case 1: case 5: { |
951 | 440 | const IC *IC = lookupICByEncoding(Encoding); |
952 | | // if (!IC || !IC->haveFeatures(STI.getFeatureBits())) |
953 | 440 | if (!IC) |
954 | 131 | return false; |
955 | | |
956 | 309 | NeedsReg = IC->NeedsReg; |
957 | 309 | Ins = "ic"; |
958 | 309 | strncpy(Name, IC->Name, sizeof(Name) - 1); |
959 | 309 | } |
960 | 0 | break; |
961 | | |
962 | | // DC aliases |
963 | 379 | case 4: case 6: case 10: case 11: case 12: case 14: { |
964 | 379 | const DC *DC = lookupDCByEncoding(Encoding); |
965 | | // if (!DC || !DC->haveFeatures(STI.getFeatureBits())) |
966 | 379 | if (!DC) |
967 | 244 | return false; |
968 | | |
969 | 135 | NeedsReg = true; |
970 | 135 | Ins = "dc"; |
971 | 135 | strncpy(Name, DC->Name, sizeof(Name) - 1); |
972 | 135 | } |
973 | 0 | break; |
974 | | |
975 | | // AT aliases |
976 | 185 | case 8: case 9: { |
977 | 185 | const AT *AT = lookupATByEncoding(Encoding); |
978 | | // if (!AT || !AT->haveFeatures(STI.getFeatureBits())) |
979 | 185 | if (!AT) |
980 | 80 | return false; |
981 | | |
982 | 105 | NeedsReg = true; |
983 | 105 | Ins = "at"; |
984 | 105 | strncpy(Name, AT->Name, sizeof(Name) - 1); |
985 | 105 | } |
986 | 0 | break; |
987 | 1.01k | } |
988 | 1.01k | } else if (CnVal == 8) { |
989 | | // TLBI aliases |
990 | 72 | const TLBI *TLBI = lookupTLBIByEncoding(Encoding); |
991 | | // if (!TLBI || !TLBI->haveFeatures(STI.getFeatureBits())) |
992 | 72 | if (!TLBI) |
993 | 40 | return false; |
994 | | |
995 | 32 | NeedsReg = TLBI->NeedsReg; |
996 | 32 | Ins = "tlbi"; |
997 | 32 | strncpy(Name, TLBI->Name, sizeof(Name) - 1); |
998 | 32 | } else |
999 | 153 | return false; |
1000 | | |
1001 | 581 | SStream_concat(O, "%s\t%s", Ins, Name); |
1002 | | |
1003 | 581 | if (NeedsReg) { |
1004 | 255 | SStream_concat(O, ", %s", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 4)), AArch64_NoRegAltName)); |
1005 | 255 | } |
1006 | | |
1007 | 581 | MCInst_setOpcodePub(MI, AArch64_map_insn(Ins)); |
1008 | | |
1009 | 581 | if (MI->csh->detail) { |
1010 | | #if 0 |
1011 | | #ifndef CAPSTONE_DIET |
1012 | | uint8_t access; |
1013 | | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1014 | | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1015 | | MI->ac_idx++; |
1016 | | #endif |
1017 | | #endif |
1018 | 581 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
1019 | 581 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = AArch64_map_sys_op(Name); |
1020 | 581 | MI->flat_insn->detail->arm64.op_count++; |
1021 | | |
1022 | 581 | if (NeedsReg) { |
1023 | 255 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1024 | 255 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 4)); |
1025 | 255 | MI->flat_insn->detail->arm64.op_count++; |
1026 | 255 | } |
1027 | 581 | } |
1028 | | |
1029 | 581 | return true; |
1030 | 1.24k | } |
1031 | | |
1032 | | static void printOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1033 | 382k | { |
1034 | 382k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1035 | | |
1036 | 382k | if (MCOperand_isReg(Op)) { |
1037 | 330k | unsigned Reg = MCOperand_getReg(Op); |
1038 | | |
1039 | 330k | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
1040 | | |
1041 | 330k | if (MI->csh->detail) { |
1042 | 330k | if (MI->csh->doing_mem) { |
1043 | 149k | if (MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.base == ARM64_REG_INVALID) { |
1044 | 128k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.base = Reg; |
1045 | 128k | } |
1046 | 21.0k | else if (MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.index == ARM64_REG_INVALID) { |
1047 | 21.0k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.index = Reg; |
1048 | 21.0k | } |
1049 | 181k | } else if (MI->csh->doing_SME_Index) { |
1050 | | // Access op_count-1 as We want to add info to previous operand, not create a new one |
1051 | 4.58k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count-1].sme_index.base = Reg; |
1052 | 176k | } else { |
1053 | 176k | #ifndef CAPSTONE_DIET |
1054 | 176k | uint8_t access; |
1055 | | |
1056 | 176k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1057 | 176k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1058 | 176k | MI->ac_idx++; |
1059 | 176k | #endif |
1060 | 176k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1061 | 176k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
1062 | 176k | MI->flat_insn->detail->arm64.op_count++; |
1063 | 176k | } |
1064 | 330k | } |
1065 | 330k | } else if (MCOperand_isImm(Op)) { |
1066 | 51.1k | int64_t imm = MCOperand_getImm(Op); |
1067 | | |
1068 | 51.1k | if (MI->Opcode == AArch64_ADR) { |
1069 | 2.97k | imm += MI->address; |
1070 | 2.97k | printUInt64Bang(O, imm); |
1071 | 48.1k | } else { |
1072 | 48.1k | if (MI->csh->doing_mem) { |
1073 | 12.8k | if (MI->csh->imm_unsigned) { |
1074 | 0 | printUInt64Bang(O, imm); |
1075 | 12.8k | } else { |
1076 | 12.8k | printInt64Bang(O, imm); |
1077 | 12.8k | } |
1078 | 12.8k | } else |
1079 | 35.2k | printUInt64Bang(O, imm); |
1080 | 48.1k | } |
1081 | | |
1082 | 51.1k | if (MI->csh->detail) { |
1083 | 51.1k | if (MI->csh->doing_mem) { |
1084 | 12.8k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int32_t)imm; |
1085 | 38.2k | } else if (MI->csh->doing_SME_Index) { |
1086 | | // Access op_count-1 as We want to add info to previous operand, not create a new one |
1087 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count-1].sme_index.disp = (int32_t)imm; |
1088 | 38.2k | } else { |
1089 | 38.2k | #ifndef CAPSTONE_DIET |
1090 | 38.2k | uint8_t access; |
1091 | | |
1092 | 38.2k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1093 | 38.2k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1094 | 38.2k | #endif |
1095 | 38.2k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1096 | 38.2k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm; |
1097 | 38.2k | MI->flat_insn->detail->arm64.op_count++; |
1098 | 38.2k | } |
1099 | 51.1k | } |
1100 | 51.1k | } |
1101 | 382k | } |
1102 | | |
1103 | | static void printImm(MCInst *MI, unsigned OpNum, SStream *O) |
1104 | 6.76k | { |
1105 | 6.76k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1106 | 6.76k | printUInt64Bang(O, MCOperand_getImm(Op)); |
1107 | | |
1108 | 6.76k | if (MI->csh->detail) { |
1109 | 6.76k | #ifndef CAPSTONE_DIET |
1110 | 6.76k | uint8_t access; |
1111 | 6.76k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1112 | 6.76k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1113 | 6.76k | MI->ac_idx++; |
1114 | 6.76k | #endif |
1115 | 6.76k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1116 | 6.76k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op); |
1117 | 6.76k | MI->flat_insn->detail->arm64.op_count++; |
1118 | 6.76k | } |
1119 | 6.76k | } |
1120 | | |
1121 | | static void printImmHex(MCInst *MI, unsigned OpNum, SStream *O) |
1122 | 70 | { |
1123 | 70 | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1124 | 70 | printUInt64Bang(O, MCOperand_getImm(Op)); |
1125 | | |
1126 | 70 | if (MI->csh->detail) { |
1127 | 70 | #ifndef CAPSTONE_DIET |
1128 | 70 | uint8_t access; |
1129 | 70 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1130 | 70 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1131 | 70 | MI->ac_idx++; |
1132 | 70 | #endif |
1133 | 70 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1134 | 70 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op); |
1135 | 70 | MI->flat_insn->detail->arm64.op_count++; |
1136 | 70 | } |
1137 | 70 | } |
1138 | | |
1139 | 736 | static void printSImm(MCInst *MI, unsigned OpNo, SStream *O, int Size) { |
1140 | 736 | MCOperand *Op = MCInst_getOperand(MI, OpNo); |
1141 | 736 | if (Size == 8) |
1142 | 625 | printInt64Bang(O, (signed char) MCOperand_getImm(Op)); |
1143 | 111 | else if (Size == 16) |
1144 | 111 | printInt64Bang(O, (signed short) MCOperand_getImm(Op)); |
1145 | 0 | else |
1146 | 0 | printInt64Bang(O, MCOperand_getImm(Op)); |
1147 | | |
1148 | 736 | if (MI->csh->detail) { |
1149 | 736 | #ifndef CAPSTONE_DIET |
1150 | 736 | uint8_t access; |
1151 | 736 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1152 | 736 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1153 | 736 | MI->ac_idx++; |
1154 | 736 | #endif |
1155 | 736 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1156 | 736 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op); |
1157 | 736 | MI->flat_insn->detail->arm64.op_count++; |
1158 | 736 | } |
1159 | 736 | } |
1160 | | |
1161 | | static void printPostIncOperand(MCInst *MI, unsigned OpNum, SStream *O, |
1162 | | unsigned Imm) |
1163 | 29.0k | { |
1164 | 29.0k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1165 | | |
1166 | 29.0k | if (MCOperand_isReg(Op)) { |
1167 | 29.0k | unsigned Reg = MCOperand_getReg(Op); |
1168 | 29.0k | if (Reg == AArch64_XZR) { |
1169 | 0 | printInt32Bang(O, Imm); |
1170 | |
|
1171 | 0 | if (MI->csh->detail) { |
1172 | 0 | #ifndef CAPSTONE_DIET |
1173 | 0 | uint8_t access; |
1174 | |
|
1175 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1176 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1177 | 0 | MI->ac_idx++; |
1178 | 0 | #endif |
1179 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1180 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Imm; |
1181 | 0 | MI->flat_insn->detail->arm64.op_count++; |
1182 | 0 | } |
1183 | 29.0k | } else { |
1184 | 29.0k | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
1185 | | |
1186 | 29.0k | if (MI->csh->detail) { |
1187 | 29.0k | #ifndef CAPSTONE_DIET |
1188 | 29.0k | uint8_t access; |
1189 | | |
1190 | 29.0k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1191 | 29.0k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1192 | 29.0k | MI->ac_idx++; |
1193 | 29.0k | #endif |
1194 | 29.0k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1195 | 29.0k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
1196 | 29.0k | MI->flat_insn->detail->arm64.op_count++; |
1197 | 29.0k | } |
1198 | 29.0k | } |
1199 | 29.0k | } |
1200 | | //llvm_unreachable("unknown operand kind in printPostIncOperand64"); |
1201 | 29.0k | } |
1202 | | |
1203 | | static void printVRegOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1204 | 43.4k | { |
1205 | 43.4k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1206 | | //assert(Op.isReg() && "Non-register vreg operand!"); |
1207 | 43.4k | unsigned Reg = MCOperand_getReg(Op); |
1208 | | |
1209 | 43.4k | SStream_concat0(O, getRegisterName(Reg, AArch64_vreg)); |
1210 | | |
1211 | 43.4k | if (MI->csh->detail) { |
1212 | 43.4k | #ifndef CAPSTONE_DIET |
1213 | 43.4k | uint8_t access; |
1214 | 43.4k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1215 | 43.4k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1216 | 43.4k | MI->ac_idx++; |
1217 | 43.4k | #endif |
1218 | 43.4k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1219 | 43.4k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = AArch64_map_vregister(Reg); |
1220 | 43.4k | MI->flat_insn->detail->arm64.op_count++; |
1221 | 43.4k | } |
1222 | 43.4k | } |
1223 | | |
1224 | | static void printSysCROperand(MCInst *MI, unsigned OpNum, SStream *O) |
1225 | 1.87k | { |
1226 | 1.87k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1227 | | //assert(Op.isImm() && "System instruction C[nm] operands must be immediates!"); |
1228 | 1.87k | SStream_concat(O, "c%u", MCOperand_getImm(Op)); |
1229 | | |
1230 | 1.87k | if (MI->csh->detail) { |
1231 | 1.87k | #ifndef CAPSTONE_DIET |
1232 | 1.87k | uint8_t access; |
1233 | | |
1234 | 1.87k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1235 | 1.87k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1236 | 1.87k | MI->ac_idx++; |
1237 | 1.87k | #endif |
1238 | 1.87k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_CIMM; |
1239 | 1.87k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op); |
1240 | 1.87k | MI->flat_insn->detail->arm64.op_count++; |
1241 | 1.87k | } |
1242 | 1.87k | } |
1243 | | |
1244 | | static void printAddSubImm(MCInst *MI, unsigned OpNum, SStream *O) |
1245 | 2.51k | { |
1246 | 2.51k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1247 | 2.51k | if (MCOperand_isImm(MO)) { |
1248 | 2.51k | unsigned Val = (MCOperand_getImm(MO) & 0xfff); |
1249 | | //assert(Val == MO.getImm() && "Add/sub immediate out of range!"); |
1250 | 2.51k | unsigned Shift = AArch64_AM_getShiftValue((int)MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1))); |
1251 | | |
1252 | 2.51k | printInt32Bang(O, Val); |
1253 | | |
1254 | 2.51k | if (MI->csh->detail) { |
1255 | 2.51k | #ifndef CAPSTONE_DIET |
1256 | 2.51k | uint8_t access; |
1257 | | |
1258 | 2.51k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1259 | 2.51k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1260 | 2.51k | MI->ac_idx++; |
1261 | 2.51k | #endif |
1262 | 2.51k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1263 | 2.51k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val; |
1264 | 2.51k | MI->flat_insn->detail->arm64.op_count++; |
1265 | 2.51k | } |
1266 | | |
1267 | 2.51k | if (Shift != 0) |
1268 | 867 | printShifter(MI, OpNum + 1, O); |
1269 | 2.51k | } |
1270 | 2.51k | } |
1271 | | |
1272 | | static void printLogicalImm32(MCInst *MI, unsigned OpNum, SStream *O) |
1273 | 6.90k | { |
1274 | 6.90k | int64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1275 | | |
1276 | 6.90k | Val = AArch64_AM_decodeLogicalImmediate(Val, 32); |
1277 | 6.90k | printUInt32Bang(O, (int)Val); |
1278 | | |
1279 | 6.90k | if (MI->csh->detail) { |
1280 | 6.90k | #ifndef CAPSTONE_DIET |
1281 | 6.90k | uint8_t access; |
1282 | | |
1283 | 6.90k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1284 | 6.90k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1285 | 6.90k | MI->ac_idx++; |
1286 | 6.90k | #endif |
1287 | 6.90k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1288 | 6.90k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val; |
1289 | 6.90k | MI->flat_insn->detail->arm64.op_count++; |
1290 | 6.90k | } |
1291 | 6.90k | } |
1292 | | |
1293 | | static void printLogicalImm64(MCInst *MI, unsigned OpNum, SStream *O) |
1294 | 5.29k | { |
1295 | 5.29k | int64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1296 | 5.29k | Val = AArch64_AM_decodeLogicalImmediate(Val, 64); |
1297 | | |
1298 | 5.29k | switch(MI->flat_insn->id) { |
1299 | 2.03k | default: |
1300 | 2.03k | printInt64Bang(O, Val); |
1301 | 2.03k | break; |
1302 | | |
1303 | 1.99k | case ARM64_INS_ORR: |
1304 | 3.00k | case ARM64_INS_AND: |
1305 | 3.26k | case ARM64_INS_EOR: |
1306 | 3.26k | case ARM64_INS_TST: |
1307 | | // do not print number in negative form |
1308 | 3.26k | if (Val >= 0 && Val <= HEX_THRESHOLD) |
1309 | 776 | SStream_concat(O, "#%u", (int)Val); |
1310 | 2.48k | else |
1311 | 2.48k | SStream_concat(O, "#0x%"PRIx64, Val); |
1312 | 3.26k | break; |
1313 | 5.29k | } |
1314 | | |
1315 | 5.29k | if (MI->csh->detail) { |
1316 | 5.29k | #ifndef CAPSTONE_DIET |
1317 | 5.29k | uint8_t access; |
1318 | | |
1319 | 5.29k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1320 | 5.29k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1321 | 5.29k | MI->ac_idx++; |
1322 | 5.29k | #endif |
1323 | 5.29k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1324 | 5.29k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int64_t)Val; |
1325 | 5.29k | MI->flat_insn->detail->arm64.op_count++; |
1326 | 5.29k | } |
1327 | 5.29k | } |
1328 | | |
1329 | | static void printShifter(MCInst *MI, unsigned OpNum, SStream *O) |
1330 | 13.8k | { |
1331 | 13.8k | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1332 | | |
1333 | | // LSL #0 should not be printed. |
1334 | 13.8k | if (AArch64_AM_getShiftType(Val) == AArch64_AM_LSL && |
1335 | 13.8k | AArch64_AM_getShiftValue(Val) == 0) |
1336 | 1.46k | return; |
1337 | | |
1338 | 12.4k | SStream_concat(O, ", %s ", AArch64_AM_getShiftExtendName(AArch64_AM_getShiftType(Val))); |
1339 | 12.4k | printInt32BangDec(O, AArch64_AM_getShiftValue(Val)); |
1340 | | |
1341 | 12.4k | if (MI->csh->detail) { |
1342 | 12.4k | arm64_shifter shifter = ARM64_SFT_INVALID; |
1343 | | |
1344 | 12.4k | switch(AArch64_AM_getShiftType(Val)) { |
1345 | 0 | default: // never reach |
1346 | 6.89k | case AArch64_AM_LSL: |
1347 | 6.89k | shifter = ARM64_SFT_LSL; |
1348 | 6.89k | break; |
1349 | | |
1350 | 1.58k | case AArch64_AM_LSR: |
1351 | 1.58k | shifter = ARM64_SFT_LSR; |
1352 | 1.58k | break; |
1353 | | |
1354 | 1.90k | case AArch64_AM_ASR: |
1355 | 1.90k | shifter = ARM64_SFT_ASR; |
1356 | 1.90k | break; |
1357 | | |
1358 | 1.95k | case AArch64_AM_ROR: |
1359 | 1.95k | shifter = ARM64_SFT_ROR; |
1360 | 1.95k | break; |
1361 | | |
1362 | 88 | case AArch64_AM_MSL: |
1363 | 88 | shifter = ARM64_SFT_MSL; |
1364 | 88 | break; |
1365 | 12.4k | } |
1366 | | |
1367 | 12.4k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.type = shifter; |
1368 | 12.4k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.value = AArch64_AM_getShiftValue(Val); |
1369 | 12.4k | } |
1370 | 12.4k | } |
1371 | | |
1372 | | static void printShiftedRegister(MCInst *MI, unsigned OpNum, SStream *O) |
1373 | 8.49k | { |
1374 | 8.49k | SStream_concat0(O, getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, OpNum)), AArch64_NoRegAltName)); |
1375 | | |
1376 | 8.49k | if (MI->csh->detail) { |
1377 | 8.49k | #ifndef CAPSTONE_DIET |
1378 | 8.49k | uint8_t access; |
1379 | 8.49k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1380 | 8.49k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1381 | 8.49k | MI->ac_idx++; |
1382 | 8.49k | #endif |
1383 | 8.49k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1384 | 8.49k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
1385 | 8.49k | MI->flat_insn->detail->arm64.op_count++; |
1386 | 8.49k | } |
1387 | | |
1388 | 8.49k | printShifter(MI, OpNum + 1, O); |
1389 | 8.49k | } |
1390 | | |
1391 | | static void printArithExtend(MCInst *MI, unsigned OpNum, SStream *O) |
1392 | 2.85k | { |
1393 | 2.85k | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1394 | 2.85k | AArch64_AM_ShiftExtendType ExtType = AArch64_AM_getArithExtendType(Val); |
1395 | 2.85k | unsigned ShiftVal = AArch64_AM_getArithShiftValue(Val); |
1396 | | |
1397 | | // If the destination or first source register operand is [W]SP, print |
1398 | | // UXTW/UXTX as LSL, and if the shift amount is also zero, print nothing at |
1399 | | // all. |
1400 | 2.85k | if (ExtType == AArch64_AM_UXTW || ExtType == AArch64_AM_UXTX) { |
1401 | 986 | unsigned Dest = MCOperand_getReg(MCInst_getOperand(MI, 0)); |
1402 | 986 | unsigned Src1 = MCOperand_getReg(MCInst_getOperand(MI, 1)); |
1403 | | |
1404 | 986 | if (((Dest == AArch64_SP || Src1 == AArch64_SP) && |
1405 | 986 | ExtType == AArch64_AM_UXTX) || |
1406 | 986 | ((Dest == AArch64_WSP || Src1 == AArch64_WSP) && |
1407 | 915 | ExtType == AArch64_AM_UXTW)) { |
1408 | 192 | if (ShiftVal != 0) { |
1409 | 192 | SStream_concat0(O, ", lsl "); |
1410 | 192 | printInt32Bang(O, ShiftVal); |
1411 | | |
1412 | 192 | if (MI->csh->detail) { |
1413 | 192 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.type = ARM64_SFT_LSL; |
1414 | 192 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.value = ShiftVal; |
1415 | 192 | } |
1416 | 192 | } |
1417 | | |
1418 | 192 | return; |
1419 | 192 | } |
1420 | 986 | } |
1421 | | |
1422 | 2.66k | SStream_concat(O, ", %s", AArch64_AM_getShiftExtendName(ExtType)); |
1423 | | |
1424 | 2.66k | if (MI->csh->detail) { |
1425 | 2.66k | arm64_extender ext = ARM64_EXT_INVALID; |
1426 | 2.66k | switch(ExtType) { |
1427 | 0 | default: // never reach |
1428 | |
|
1429 | 121 | case AArch64_AM_UXTB: |
1430 | 121 | ext = ARM64_EXT_UXTB; |
1431 | 121 | break; |
1432 | | |
1433 | 787 | case AArch64_AM_UXTH: |
1434 | 787 | ext = ARM64_EXT_UXTH; |
1435 | 787 | break; |
1436 | | |
1437 | 656 | case AArch64_AM_UXTW: |
1438 | 656 | ext = ARM64_EXT_UXTW; |
1439 | 656 | break; |
1440 | | |
1441 | 138 | case AArch64_AM_UXTX: |
1442 | 138 | ext = ARM64_EXT_UXTX; |
1443 | 138 | break; |
1444 | | |
1445 | 103 | case AArch64_AM_SXTB: |
1446 | 103 | ext = ARM64_EXT_SXTB; |
1447 | 103 | break; |
1448 | | |
1449 | 198 | case AArch64_AM_SXTH: |
1450 | 198 | ext = ARM64_EXT_SXTH; |
1451 | 198 | break; |
1452 | | |
1453 | 537 | case AArch64_AM_SXTW: |
1454 | 537 | ext = ARM64_EXT_SXTW; |
1455 | 537 | break; |
1456 | | |
1457 | 125 | case AArch64_AM_SXTX: |
1458 | 125 | ext = ARM64_EXT_SXTX; |
1459 | 125 | break; |
1460 | 2.66k | } |
1461 | | |
1462 | 2.66k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].ext = ext; |
1463 | 2.66k | } |
1464 | | |
1465 | 2.66k | if (ShiftVal != 0) { |
1466 | 2.43k | SStream_concat0(O, " "); |
1467 | 2.43k | printInt32Bang(O, ShiftVal); |
1468 | | |
1469 | 2.43k | if (MI->csh->detail) { |
1470 | 2.43k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.type = ARM64_SFT_LSL; |
1471 | 2.43k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.value = ShiftVal; |
1472 | 2.43k | } |
1473 | 2.43k | } |
1474 | 2.66k | } |
1475 | | |
1476 | | static void printExtendedRegister(MCInst *MI, unsigned OpNum, SStream *O) |
1477 | 2.14k | { |
1478 | 2.14k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
1479 | | |
1480 | 2.14k | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
1481 | | |
1482 | 2.14k | if (MI->csh->detail) { |
1483 | 2.14k | #ifndef CAPSTONE_DIET |
1484 | 2.14k | uint8_t access; |
1485 | 2.14k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1486 | 2.14k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1487 | 2.14k | MI->ac_idx++; |
1488 | 2.14k | #endif |
1489 | 2.14k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1490 | 2.14k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
1491 | 2.14k | MI->flat_insn->detail->arm64.op_count++; |
1492 | 2.14k | } |
1493 | | |
1494 | 2.14k | printArithExtend(MI, OpNum + 1, O); |
1495 | 2.14k | } |
1496 | | |
1497 | | static void printMemExtendImpl(MCInst *MI, bool SignExtend, bool DoShift, unsigned Width, |
1498 | | char SrcRegKind, SStream *O) |
1499 | 19.8k | { |
1500 | | // sxtw, sxtx, uxtw or lsl (== uxtx) |
1501 | 19.8k | bool IsLSL = !SignExtend && SrcRegKind == 'x'; |
1502 | 19.8k | if (IsLSL) { |
1503 | 9.76k | SStream_concat0(O, "lsl"); |
1504 | | |
1505 | 9.76k | if (MI->csh->detail) { |
1506 | 9.76k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].shift.type = ARM64_SFT_LSL; |
1507 | 9.76k | } |
1508 | 10.1k | } else { |
1509 | 10.1k | SStream_concat(O, "%cxt%c", (SignExtend ? 's' : 'u'), SrcRegKind); |
1510 | | |
1511 | 10.1k | if (MI->csh->detail) { |
1512 | 10.1k | if (!SignExtend) { |
1513 | 5.35k | switch(SrcRegKind) { |
1514 | 0 | default: break; |
1515 | 0 | case 'b': |
1516 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_UXTB; |
1517 | 0 | break; |
1518 | 0 | case 'h': |
1519 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_UXTH; |
1520 | 0 | break; |
1521 | 5.35k | case 'w': |
1522 | 5.35k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_UXTW; |
1523 | 5.35k | break; |
1524 | 5.35k | } |
1525 | 5.35k | } else { |
1526 | 4.76k | switch(SrcRegKind) { |
1527 | 0 | default: break; |
1528 | 0 | case 'b': |
1529 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTB; |
1530 | 0 | break; |
1531 | 0 | case 'h': |
1532 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTH; |
1533 | 0 | break; |
1534 | 4.01k | case 'w': |
1535 | 4.01k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTW; |
1536 | 4.01k | break; |
1537 | 751 | case 'x': |
1538 | 751 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTX; |
1539 | 751 | break; |
1540 | 4.76k | } |
1541 | 4.76k | } |
1542 | 10.1k | } |
1543 | 10.1k | } |
1544 | | |
1545 | 19.8k | if (DoShift || IsLSL) { |
1546 | 16.6k | SStream_concat(O, " #%u", Log2_32(Width / 8)); |
1547 | | |
1548 | 16.6k | if (MI->csh->detail) { |
1549 | 16.6k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].shift.type = ARM64_SFT_LSL; |
1550 | 16.6k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].shift.value = Log2_32(Width / 8); |
1551 | 16.6k | } |
1552 | 16.6k | } |
1553 | 19.8k | } |
1554 | | |
1555 | | static void printMemExtend(MCInst *MI, unsigned OpNum, SStream *O, char SrcRegKind, unsigned Width) |
1556 | 2.60k | { |
1557 | 2.60k | unsigned SignExtend = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1558 | 2.60k | unsigned DoShift = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1)); |
1559 | | |
1560 | 2.60k | printMemExtendImpl(MI, SignExtend, DoShift, Width, SrcRegKind, O); |
1561 | 2.60k | } |
1562 | | |
1563 | | static void printRegWithShiftExtend(MCInst *MI, unsigned OpNum, SStream *O, |
1564 | | bool SignExtend, int ExtWidth, |
1565 | | char SrcRegKind, char Suffix) |
1566 | 19.8k | { |
1567 | 19.8k | bool DoShift; |
1568 | | |
1569 | 19.8k | printOperand(MI, OpNum, O); |
1570 | | |
1571 | 19.8k | if (Suffix == 's' || Suffix == 'd') |
1572 | 13.1k | SStream_concat(O, ".%c", Suffix); |
1573 | | |
1574 | 19.8k | DoShift = ExtWidth != 8; |
1575 | 19.8k | if (SignExtend || DoShift || SrcRegKind == 'w') { |
1576 | 17.2k | SStream_concat0(O, ", "); |
1577 | 17.2k | printMemExtendImpl(MI, SignExtend, DoShift, ExtWidth, SrcRegKind, O); |
1578 | 17.2k | } |
1579 | 19.8k | } |
1580 | | |
1581 | | static void printCondCode(MCInst *MI, unsigned OpNum, SStream *O) |
1582 | 3.18k | { |
1583 | 3.18k | AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1584 | 3.18k | SStream_concat0(O, getCondCodeName(CC)); |
1585 | | |
1586 | 3.18k | if (MI->csh->detail) |
1587 | 3.18k | MI->flat_insn->detail->arm64.cc = (arm64_cc)(CC + 1); |
1588 | 3.18k | } |
1589 | | |
1590 | | static void printInverseCondCode(MCInst *MI, unsigned OpNum, SStream *O) |
1591 | 12 | { |
1592 | 12 | AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1593 | 12 | SStream_concat0(O, getCondCodeName(getInvertedCondCode(CC))); |
1594 | | |
1595 | 12 | if (MI->csh->detail) { |
1596 | 12 | MI->flat_insn->detail->arm64.cc = (arm64_cc)(getInvertedCondCode(CC) + 1); |
1597 | 12 | } |
1598 | 12 | } |
1599 | | |
1600 | | static void printImmScale(MCInst *MI, unsigned OpNum, SStream *O, int Scale) |
1601 | 23.3k | { |
1602 | 23.3k | int64_t val = Scale * MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1603 | | |
1604 | 23.3k | printInt64Bang(O, val); |
1605 | | |
1606 | 23.3k | if (MI->csh->detail) { |
1607 | 23.3k | if (MI->csh->doing_mem) { |
1608 | 19.4k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int32_t)val; |
1609 | 19.4k | } else { |
1610 | 3.87k | #ifndef CAPSTONE_DIET |
1611 | 3.87k | uint8_t access; |
1612 | | |
1613 | 3.87k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1614 | 3.87k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1615 | 3.87k | MI->ac_idx++; |
1616 | 3.87k | #endif |
1617 | 3.87k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1618 | 3.87k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = val; |
1619 | 3.87k | MI->flat_insn->detail->arm64.op_count++; |
1620 | 3.87k | } |
1621 | 23.3k | } |
1622 | 23.3k | } |
1623 | | |
1624 | | static void printUImm12Offset(MCInst *MI, unsigned OpNum, SStream *O, unsigned Scale) |
1625 | 6.85k | { |
1626 | 6.85k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1627 | | |
1628 | 6.85k | if (MCOperand_isImm(MO)) { |
1629 | 6.85k | int64_t val = Scale * MCOperand_getImm(MO); |
1630 | 6.85k | printInt64Bang(O, val); |
1631 | | |
1632 | 6.85k | if (MI->csh->detail) { |
1633 | 6.85k | if (MI->csh->doing_mem) { |
1634 | 6.85k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int32_t)val; |
1635 | 6.85k | } else { |
1636 | 0 | #ifndef CAPSTONE_DIET |
1637 | 0 | uint8_t access; |
1638 | |
|
1639 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1640 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1641 | 0 | MI->ac_idx++; |
1642 | 0 | #endif |
1643 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1644 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)val; |
1645 | 0 | MI->flat_insn->detail->arm64.op_count++; |
1646 | 0 | } |
1647 | 6.85k | } |
1648 | 6.85k | } |
1649 | 6.85k | } |
1650 | | |
1651 | | #if 0 |
1652 | | static void printAMIndexedWB(MCInst *MI, unsigned OpNum, SStream *O, unsigned int Scale) |
1653 | | { |
1654 | | MCOperand *MO = MCInst_getOperand(MI, OpNum + 1); |
1655 | | |
1656 | | SStream_concat(O, "[%s", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, OpNum)), AArch64_NoRegAltName)); |
1657 | | |
1658 | | if (MCOperand_isImm(MO)) { |
1659 | | int64_t val = Scale * MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1660 | | printInt64Bang(O, val); |
1661 | | // } else { |
1662 | | // // assert(MO1.isExpr() && "Unexpected operand type!"); |
1663 | | // SStream_concat0(O, ", "); |
1664 | | // MO1.getExpr()->print(O, &MAI); |
1665 | | } |
1666 | | |
1667 | | SStream_concat0(O, "]"); |
1668 | | } |
1669 | | #endif |
1670 | | |
1671 | | // IsSVEPrefetch = false |
1672 | | static void printPrefetchOp(MCInst *MI, unsigned OpNum, SStream *O, bool IsSVEPrefetch) |
1673 | 11.6k | { |
1674 | 11.6k | unsigned prfop = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1675 | | |
1676 | 11.6k | if (IsSVEPrefetch) { |
1677 | 9.74k | const SVEPRFM *PRFM = lookupSVEPRFMByEncoding(prfop); |
1678 | 9.74k | if (PRFM) |
1679 | 8.79k | SStream_concat0(O, PRFM->Name); |
1680 | | |
1681 | 9.74k | return; |
1682 | 9.74k | } else { |
1683 | 1.95k | const PRFM *PRFM = lookupPRFMByEncoding(prfop); |
1684 | 1.95k | if (PRFM) |
1685 | 500 | SStream_concat0(O, PRFM->Name); |
1686 | | |
1687 | 1.95k | return; |
1688 | 1.95k | } |
1689 | | |
1690 | | // FIXME: set OpcodePub? |
1691 | | |
1692 | 0 | printInt32Bang(O, prfop); |
1693 | |
|
1694 | 0 | if (MI->csh->detail) { |
1695 | 0 | #ifndef CAPSTONE_DIET |
1696 | 0 | uint8_t access; |
1697 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1698 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1699 | 0 | MI->ac_idx++; |
1700 | 0 | #endif |
1701 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
1702 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = prfop; |
1703 | 0 | MI->flat_insn->detail->arm64.op_count++; |
1704 | 0 | } |
1705 | 0 | } |
1706 | | |
1707 | | static void printPSBHintOp(MCInst *MI, unsigned OpNum, SStream *O) |
1708 | 209 | { |
1709 | 209 | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1710 | 209 | unsigned int psbhintop = MCOperand_getImm(Op); |
1711 | | |
1712 | 209 | const PSB *PSB = lookupPSBByEncoding(psbhintop); |
1713 | 209 | if (PSB) |
1714 | 209 | SStream_concat0(O, PSB->Name); |
1715 | 0 | else |
1716 | 0 | printUInt32Bang(O, psbhintop); |
1717 | 209 | } |
1718 | | |
1719 | 19 | static void printBTIHintOp(MCInst *MI, unsigned OpNum, SStream *O) { |
1720 | 19 | unsigned btihintop = MCOperand_getImm(MCInst_getOperand(MI, OpNum)) ^ 32; |
1721 | | |
1722 | 19 | const BTI *BTI = lookupBTIByEncoding(btihintop); |
1723 | 19 | if (BTI) |
1724 | 19 | SStream_concat0(O, BTI->Name); |
1725 | 0 | else |
1726 | 0 | printUInt32Bang(O, btihintop); |
1727 | 19 | } |
1728 | | |
1729 | | static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1730 | 585 | { |
1731 | 585 | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1732 | 585 | float FPImm = MCOperand_isFPImm(MO) ? MCOperand_getFPImm(MO) : AArch64_AM_getFPImmFloat((int)MCOperand_getImm(MO)); |
1733 | | |
1734 | | // 8 decimal places are enough to perfectly represent permitted floats. |
1735 | | #if defined(_KERNEL_MODE) |
1736 | | // Issue #681: Windows kernel does not support formatting float point |
1737 | | SStream_concat0(O, "#<float_point_unsupported>"); |
1738 | | #else |
1739 | 585 | SStream_concat(O, "#%.8f", FPImm); |
1740 | 585 | #endif |
1741 | | |
1742 | 585 | if (MI->csh->detail) { |
1743 | 585 | #ifndef CAPSTONE_DIET |
1744 | 585 | uint8_t access; |
1745 | | |
1746 | 585 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1747 | 585 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1748 | 585 | MI->ac_idx++; |
1749 | 585 | #endif |
1750 | 585 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_FP; |
1751 | 585 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].fp = FPImm; |
1752 | 585 | MI->flat_insn->detail->arm64.op_count++; |
1753 | 585 | } |
1754 | 585 | } |
1755 | | |
1756 | | //static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride = 1) |
1757 | | static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride) |
1758 | 157k | { |
1759 | 315k | while (Stride--) { |
1760 | 157k | if (Reg >= AArch64_Q0 && Reg <= AArch64_Q30) // AArch64_Q0 .. AArch64_Q30 |
1761 | 126k | Reg += 1; |
1762 | 30.9k | else if (Reg == AArch64_Q31) // Vector lists can wrap around. |
1763 | 6.90k | Reg = AArch64_Q0; |
1764 | 24.0k | else if (Reg >= AArch64_Z0 && Reg <= AArch64_Z30) // AArch64_Z0 .. AArch64_Z30 |
1765 | 23.4k | Reg += 1; |
1766 | 586 | else if (Reg == AArch64_Z31) // Vector lists can wrap around. |
1767 | 586 | Reg = AArch64_Z0; |
1768 | 157k | } |
1769 | | |
1770 | 157k | return Reg; |
1771 | 157k | } |
1772 | | |
1773 | | static void printGPRSeqPairsClassOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned int size) |
1774 | 622 | { |
1775 | | // static_assert(size == 64 || size == 32, |
1776 | | // "Template parameter must be either 32 or 64"); |
1777 | 622 | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
1778 | 622 | unsigned Sube = (size == 32) ? AArch64_sube32 : AArch64_sube64; |
1779 | 622 | unsigned Subo = (size == 32) ? AArch64_subo32 : AArch64_subo64; |
1780 | 622 | unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); |
1781 | 622 | unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); |
1782 | | |
1783 | 622 | SStream_concat(O, "%s, %s", getRegisterName(Even, AArch64_NoRegAltName), |
1784 | 622 | getRegisterName(Odd, AArch64_NoRegAltName)); |
1785 | | |
1786 | 622 | if (MI->csh->detail) { |
1787 | 622 | #ifndef CAPSTONE_DIET |
1788 | 622 | uint8_t access; |
1789 | | |
1790 | 622 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1791 | 622 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1792 | 622 | MI->ac_idx++; |
1793 | 622 | #endif |
1794 | | |
1795 | 622 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1796 | 622 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Even; |
1797 | 622 | MI->flat_insn->detail->arm64.op_count++; |
1798 | | |
1799 | 622 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1800 | 622 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Odd; |
1801 | 622 | MI->flat_insn->detail->arm64.op_count++; |
1802 | 622 | } |
1803 | 622 | } |
1804 | | |
1805 | | static void printVectorList(MCInst *MI, unsigned OpNum, SStream *O, |
1806 | | char *LayoutSuffix, MCRegisterInfo *MRI, arm64_vas vas) |
1807 | 70.7k | { |
1808 | 1.03M | #define GETREGCLASS_CONTAIN0(_class, _reg) MCRegisterClass_contains(MCRegisterInfo_getRegClass(MRI, _class), _reg) |
1809 | 70.7k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
1810 | 70.7k | unsigned NumRegs = 1, FirstReg, i; |
1811 | | |
1812 | 70.7k | SStream_concat0(O, "{"); |
1813 | | |
1814 | | // Work out how many registers there are in the list (if there is an actual |
1815 | | // list). |
1816 | 70.7k | if (GETREGCLASS_CONTAIN0(AArch64_DDRegClassID , Reg) || |
1817 | 70.7k | GETREGCLASS_CONTAIN0(AArch64_ZPR2RegClassID, Reg) || |
1818 | 70.7k | GETREGCLASS_CONTAIN0(AArch64_QQRegClassID, Reg)) |
1819 | 16.7k | NumRegs = 2; |
1820 | 54.0k | else if (GETREGCLASS_CONTAIN0(AArch64_DDDRegClassID, Reg) || |
1821 | 54.0k | GETREGCLASS_CONTAIN0(AArch64_ZPR3RegClassID, Reg) || |
1822 | 54.0k | GETREGCLASS_CONTAIN0(AArch64_QQQRegClassID, Reg)) |
1823 | 12.7k | NumRegs = 3; |
1824 | 41.2k | else if (GETREGCLASS_CONTAIN0(AArch64_DDDDRegClassID, Reg) || |
1825 | 41.2k | GETREGCLASS_CONTAIN0(AArch64_ZPR4RegClassID, Reg) || |
1826 | 41.2k | GETREGCLASS_CONTAIN0(AArch64_QQQQRegClassID, Reg)) |
1827 | 14.9k | NumRegs = 4; |
1828 | | |
1829 | | // Now forget about the list and find out what the first register is. |
1830 | 70.7k | if ((FirstReg = MCRegisterInfo_getSubReg(MRI, Reg, AArch64_dsub0))) |
1831 | 8.76k | Reg = FirstReg; |
1832 | 61.9k | else if ((FirstReg = MCRegisterInfo_getSubReg(MRI, Reg, AArch64_qsub0))) |
1833 | 31.5k | Reg = FirstReg; |
1834 | 30.3k | else if ((FirstReg = MCRegisterInfo_getSubReg(MRI, Reg, AArch64_zsub0))) |
1835 | 4.04k | Reg = FirstReg; |
1836 | | |
1837 | | // If it's a D-reg, we need to promote it to the equivalent Q-reg before |
1838 | | // printing (otherwise getRegisterName fails). |
1839 | 70.7k | if (GETREGCLASS_CONTAIN0(AArch64_FPR64RegClassID, Reg)) { |
1840 | 11.1k | const MCRegisterClass *FPR128RC = MCRegisterInfo_getRegClass(MRI, AArch64_FPR128RegClassID); |
1841 | 11.1k | Reg = MCRegisterInfo_getMatchingSuperReg(MRI, Reg, AArch64_dsub, FPR128RC); |
1842 | 11.1k | } |
1843 | | |
1844 | 228k | for (i = 0; i < NumRegs; ++i, Reg = getNextVectorRegister(Reg, 1)) { |
1845 | 157k | bool isZReg = GETREGCLASS_CONTAIN0(AArch64_ZPRRegClassID, Reg); |
1846 | 157k | if (isZReg) |
1847 | 24.0k | SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_NoRegAltName), LayoutSuffix); |
1848 | 133k | else |
1849 | 133k | SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_vreg), LayoutSuffix); |
1850 | | |
1851 | 157k | if (MI->csh->detail) { |
1852 | 157k | #ifndef CAPSTONE_DIET |
1853 | 157k | uint8_t access; |
1854 | | |
1855 | 157k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1856 | 157k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
1857 | 157k | MI->ac_idx++; |
1858 | 157k | #endif |
1859 | 157k | unsigned regForDetail = isZReg ? Reg : AArch64_map_vregister(Reg); |
1860 | 157k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
1861 | 157k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = regForDetail; |
1862 | 157k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].vas = vas; |
1863 | 157k | MI->flat_insn->detail->arm64.op_count++; |
1864 | 157k | } |
1865 | | |
1866 | 157k | if (i + 1 != NumRegs) |
1867 | 86.9k | SStream_concat0(O, ", "); |
1868 | 157k | } |
1869 | | |
1870 | 70.7k | SStream_concat0(O, "}"); |
1871 | 70.7k | } |
1872 | | |
1873 | | static void printTypedVectorList(MCInst *MI, unsigned OpNum, SStream *O, unsigned NumLanes, char LaneKind) |
1874 | 70.7k | { |
1875 | 70.7k | char Suffix[32]; |
1876 | 70.7k | arm64_vas vas = 0; |
1877 | | |
1878 | 70.7k | if (NumLanes) { |
1879 | 25.5k | cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, LaneKind); |
1880 | | |
1881 | 25.5k | switch(LaneKind) { |
1882 | 0 | default: break; |
1883 | 9.04k | case 'b': |
1884 | 9.04k | switch(NumLanes) { |
1885 | 0 | default: break; |
1886 | 0 | case 1: |
1887 | 0 | vas = ARM64_VAS_1B; |
1888 | 0 | break; |
1889 | 0 | case 4: |
1890 | 0 | vas = ARM64_VAS_4B; |
1891 | 0 | break; |
1892 | 4.46k | case 8: |
1893 | 4.46k | vas = ARM64_VAS_8B; |
1894 | 4.46k | break; |
1895 | 4.58k | case 16: |
1896 | 4.58k | vas = ARM64_VAS_16B; |
1897 | 4.58k | break; |
1898 | 9.04k | } |
1899 | 9.04k | break; |
1900 | 9.04k | case 'h': |
1901 | 4.27k | switch(NumLanes) { |
1902 | 0 | default: break; |
1903 | 0 | case 1: |
1904 | 0 | vas = ARM64_VAS_1H; |
1905 | 0 | break; |
1906 | 0 | case 2: |
1907 | 0 | vas = ARM64_VAS_2H; |
1908 | 0 | break; |
1909 | 2.18k | case 4: |
1910 | 2.18k | vas = ARM64_VAS_4H; |
1911 | 2.18k | break; |
1912 | 2.09k | case 8: |
1913 | 2.09k | vas = ARM64_VAS_8H; |
1914 | 2.09k | break; |
1915 | 4.27k | } |
1916 | 4.27k | break; |
1917 | 7.33k | case 's': |
1918 | 7.33k | switch(NumLanes) { |
1919 | 0 | default: break; |
1920 | 0 | case 1: |
1921 | 0 | vas = ARM64_VAS_1S; |
1922 | 0 | break; |
1923 | 3.02k | case 2: |
1924 | 3.02k | vas = ARM64_VAS_2S; |
1925 | 3.02k | break; |
1926 | 4.30k | case 4: |
1927 | 4.30k | vas = ARM64_VAS_4S; |
1928 | 4.30k | break; |
1929 | 7.33k | } |
1930 | 7.33k | break; |
1931 | 7.33k | case 'd': |
1932 | 4.87k | switch(NumLanes) { |
1933 | 0 | default: break; |
1934 | 1.49k | case 1: |
1935 | 1.49k | vas = ARM64_VAS_1D; |
1936 | 1.49k | break; |
1937 | 3.38k | case 2: |
1938 | 3.38k | vas = ARM64_VAS_2D; |
1939 | 3.38k | break; |
1940 | 4.87k | } |
1941 | 4.87k | break; |
1942 | 4.87k | case 'q': |
1943 | 0 | switch(NumLanes) { |
1944 | 0 | default: break; |
1945 | 0 | case 1: |
1946 | 0 | vas = ARM64_VAS_1Q; |
1947 | 0 | break; |
1948 | 0 | } |
1949 | 0 | break; |
1950 | 25.5k | } |
1951 | 45.2k | } else { |
1952 | 45.2k | cs_snprintf(Suffix, sizeof(Suffix), ".%c", LaneKind); |
1953 | | |
1954 | 45.2k | switch(LaneKind) { |
1955 | 0 | default: break; |
1956 | 13.9k | case 'b': |
1957 | 13.9k | vas = ARM64_VAS_1B; |
1958 | 13.9k | break; |
1959 | 7.77k | case 'h': |
1960 | 7.77k | vas = ARM64_VAS_1H; |
1961 | 7.77k | break; |
1962 | 10.6k | case 's': |
1963 | 10.6k | vas = ARM64_VAS_1S; |
1964 | 10.6k | break; |
1965 | 12.8k | case 'd': |
1966 | 12.8k | vas = ARM64_VAS_1D; |
1967 | 12.8k | break; |
1968 | 0 | case 'q': |
1969 | 0 | vas = ARM64_VAS_1Q; |
1970 | 0 | break; |
1971 | 45.2k | } |
1972 | 45.2k | } |
1973 | | |
1974 | 70.7k | printVectorList(MI, OpNum, O, Suffix, MI->MRI, vas); |
1975 | 70.7k | } |
1976 | | |
1977 | | static void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O) |
1978 | 36.0k | { |
1979 | 36.0k | SStream_concat0(O, "["); |
1980 | 36.0k | printInt32(O, (int)MCOperand_getImm(MCInst_getOperand(MI, OpNum))); |
1981 | 36.0k | SStream_concat0(O, "]"); |
1982 | | |
1983 | 36.0k | if (MI->csh->detail) { |
1984 | 36.0k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].vector_index = (int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1985 | 36.0k | } |
1986 | 36.0k | } |
1987 | | |
1988 | | static void printAlignedLabel(MCInst *MI, unsigned OpNum, SStream *O) |
1989 | 11.3k | { |
1990 | 11.3k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1991 | | |
1992 | | // If the label has already been resolved to an immediate offset (say, when |
1993 | | // we're running the disassembler), just print the immediate. |
1994 | 11.3k | if (MCOperand_isImm(Op)) { |
1995 | 11.3k | uint64_t imm = (MCOperand_getImm(Op) * 4) + MI->address; |
1996 | 11.3k | printUInt64Bang(O, imm); |
1997 | | |
1998 | 11.3k | if (MI->csh->detail) { |
1999 | 11.3k | #ifndef CAPSTONE_DIET |
2000 | 11.3k | uint8_t access; |
2001 | | |
2002 | 11.3k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2003 | 11.3k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2004 | 11.3k | MI->ac_idx++; |
2005 | 11.3k | #endif |
2006 | 11.3k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
2007 | 11.3k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm; |
2008 | 11.3k | MI->flat_insn->detail->arm64.op_count++; |
2009 | 11.3k | } |
2010 | 11.3k | } |
2011 | 11.3k | } |
2012 | | |
2013 | | static void printAdrpLabel(MCInst *MI, unsigned OpNum, SStream *O) |
2014 | 2.04k | { |
2015 | 2.04k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
2016 | | |
2017 | 2.04k | if (MCOperand_isImm(Op)) { |
2018 | | // ADRP sign extends a 21-bit offset, shifts it left by 12 |
2019 | | // and adds it to the value of the PC with its bottom 12 bits cleared |
2020 | 2.04k | uint64_t imm = (MCOperand_getImm(Op) * 0x1000) + (MI->address & ~0xfff); |
2021 | 2.04k | printUInt64Bang(O, imm); |
2022 | | |
2023 | 2.04k | if (MI->csh->detail) { |
2024 | 2.04k | #ifndef CAPSTONE_DIET |
2025 | 2.04k | uint8_t access; |
2026 | | |
2027 | 2.04k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2028 | 2.04k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2029 | 2.04k | MI->ac_idx++; |
2030 | 2.04k | #endif |
2031 | 2.04k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
2032 | 2.04k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm; |
2033 | 2.04k | MI->flat_insn->detail->arm64.op_count++; |
2034 | 2.04k | } |
2035 | 2.04k | } |
2036 | 2.04k | } |
2037 | | |
2038 | | static void printBarrierOption(MCInst *MI, unsigned OpNum, SStream *O) |
2039 | 73 | { |
2040 | 73 | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2041 | 73 | unsigned Opcode = MCInst_getOpcode(MI); |
2042 | 73 | const char *Name = NULL; |
2043 | | |
2044 | 73 | if (Opcode == AArch64_ISB) { |
2045 | 18 | const ISB *ISB = lookupISBByEncoding(Val); |
2046 | 18 | Name = ISB ? ISB->Name : NULL; |
2047 | 55 | } else if (Opcode == AArch64_TSB) { |
2048 | 0 | const TSB *TSB = lookupTSBByEncoding(Val); |
2049 | 0 | Name = TSB ? TSB->Name : NULL; |
2050 | 55 | } else { |
2051 | 55 | const DB *DB = lookupDBByEncoding(Val); |
2052 | 55 | Name = DB ? DB->Name : NULL; |
2053 | 55 | } |
2054 | | |
2055 | 73 | if (Name) { |
2056 | 21 | SStream_concat0(O, Name); |
2057 | | |
2058 | 21 | if (MI->csh->detail) { |
2059 | 21 | #ifndef CAPSTONE_DIET |
2060 | 21 | uint8_t access; |
2061 | | |
2062 | 21 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2063 | 21 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2064 | 21 | MI->ac_idx++; |
2065 | 21 | #endif |
2066 | 21 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_BARRIER; |
2067 | 21 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].barrier = Val; |
2068 | 21 | MI->flat_insn->detail->arm64.op_count++; |
2069 | 21 | } |
2070 | 52 | } else { |
2071 | 52 | printUInt32Bang(O, Val); |
2072 | | |
2073 | 52 | if (MI->csh->detail) { |
2074 | 52 | #ifndef CAPSTONE_DIET |
2075 | 52 | uint8_t access; |
2076 | | |
2077 | 52 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2078 | 52 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2079 | 52 | MI->ac_idx++; |
2080 | 52 | #endif |
2081 | 52 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
2082 | 52 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val; |
2083 | 52 | MI->flat_insn->detail->arm64.op_count++; |
2084 | 52 | } |
2085 | 52 | } |
2086 | 73 | } |
2087 | | |
2088 | 19 | static void printBarriernXSOption(MCInst *MI, unsigned OpNo, SStream *O) { |
2089 | 19 | unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, OpNo)); |
2090 | | // assert(MI->getOpcode() == AArch64::DSBnXS); |
2091 | | |
2092 | 19 | const char *Name = NULL; |
2093 | 19 | const DBnXS *DB = lookupDBnXSByEncoding(Val); |
2094 | 19 | Name = DB ? DB->Name : NULL; |
2095 | | |
2096 | 19 | if (Name) { |
2097 | 19 | SStream_concat0(O, Name); |
2098 | | |
2099 | 19 | if (MI->csh->detail) { |
2100 | 19 | #ifndef CAPSTONE_DIET |
2101 | 19 | uint8_t access; |
2102 | | |
2103 | 19 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2104 | 19 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2105 | 19 | MI->ac_idx++; |
2106 | 19 | #endif |
2107 | 19 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_BARRIER; |
2108 | 19 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].barrier = Val; |
2109 | 19 | MI->flat_insn->detail->arm64.op_count++; |
2110 | 19 | } |
2111 | 19 | } |
2112 | 0 | else { |
2113 | 0 | printUInt32Bang(O, Val); |
2114 | |
|
2115 | 0 | if (MI->csh->detail) { |
2116 | 0 | #ifndef CAPSTONE_DIET |
2117 | 0 | uint8_t access; |
2118 | |
|
2119 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2120 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2121 | 0 | MI->ac_idx++; |
2122 | 0 | #endif |
2123 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
2124 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val; |
2125 | 0 | MI->flat_insn->detail->arm64.op_count++; |
2126 | 0 | } |
2127 | 0 | } |
2128 | 19 | } |
2129 | | |
2130 | | static void printMRSSystemRegister(MCInst *MI, unsigned OpNum, SStream *O) |
2131 | 1.86k | { |
2132 | 1.86k | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2133 | 1.86k | const SysReg *Reg = lookupSysRegByEncoding(Val); |
2134 | | |
2135 | | // Horrible hack for the one register that has identical encodings but |
2136 | | // different names in MSR and MRS. Because of this, one of MRS and MSR is |
2137 | | // going to get the wrong entry |
2138 | 1.86k | if (Val == ARM64_SYSREG_DBGDTRRX_EL0) { |
2139 | 314 | SStream_concat0(O, "dbgdtrrx_el0"); |
2140 | | |
2141 | 314 | if (MI->csh->detail) { |
2142 | 314 | #ifndef CAPSTONE_DIET |
2143 | 314 | uint8_t access; |
2144 | | |
2145 | 314 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2146 | 314 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2147 | 314 | MI->ac_idx++; |
2148 | 314 | #endif |
2149 | | |
2150 | 314 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
2151 | 314 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val; |
2152 | 314 | MI->flat_insn->detail->arm64.op_count++; |
2153 | 314 | } |
2154 | | |
2155 | 314 | return; |
2156 | 314 | } |
2157 | | |
2158 | | // Another hack for a register which has an alternative name which is not an alias, |
2159 | | // and is not in the Armv9-A documentation. |
2160 | 1.55k | if( Val == ARM64_SYSREG_VSCTLR_EL2){ |
2161 | 18 | SStream_concat0(O, "ttbr0_el2"); |
2162 | | |
2163 | 18 | if (MI->csh->detail) { |
2164 | 18 | #ifndef CAPSTONE_DIET |
2165 | 18 | uint8_t access; |
2166 | | |
2167 | 18 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2168 | 18 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2169 | 18 | MI->ac_idx++; |
2170 | 18 | #endif |
2171 | | |
2172 | 18 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
2173 | 18 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val; |
2174 | 18 | MI->flat_insn->detail->arm64.op_count++; |
2175 | 18 | } |
2176 | | |
2177 | 18 | return; |
2178 | 18 | } |
2179 | | |
2180 | | // if (Reg && Reg->Readable && Reg->haveFeatures(STI.getFeatureBits())) |
2181 | 1.53k | if (Reg && Reg->Readable) { |
2182 | 46 | SStream_concat0(O, Reg->Name); |
2183 | | |
2184 | 46 | if (MI->csh->detail) { |
2185 | 46 | #ifndef CAPSTONE_DIET |
2186 | 46 | uint8_t access; |
2187 | | |
2188 | 46 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2189 | 46 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2190 | 46 | MI->ac_idx++; |
2191 | 46 | #endif |
2192 | | |
2193 | 46 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
2194 | 46 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Reg->Encoding; |
2195 | 46 | MI->flat_insn->detail->arm64.op_count++; |
2196 | 46 | } |
2197 | 1.48k | } else { |
2198 | 1.48k | char result[128]; |
2199 | | |
2200 | 1.48k | AArch64SysReg_genericRegisterString(Val, result); |
2201 | 1.48k | SStream_concat0(O, result); |
2202 | | |
2203 | 1.48k | if (MI->csh->detail) { |
2204 | 1.48k | #ifndef CAPSTONE_DIET |
2205 | 1.48k | uint8_t access; |
2206 | 1.48k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2207 | 1.48k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2208 | 1.48k | MI->ac_idx++; |
2209 | 1.48k | #endif |
2210 | 1.48k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG_MRS; |
2211 | 1.48k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Val; |
2212 | 1.48k | MI->flat_insn->detail->arm64.op_count++; |
2213 | 1.48k | } |
2214 | 1.48k | } |
2215 | 1.53k | } |
2216 | | |
2217 | | static void printMSRSystemRegister(MCInst *MI, unsigned OpNum, SStream *O) |
2218 | 3.68k | { |
2219 | 3.68k | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2220 | 3.68k | const SysReg *Reg = lookupSysRegByEncoding(Val); |
2221 | | |
2222 | | // Horrible hack for the one register that has identical encodings but |
2223 | | // different names in MSR and MRS. Because of this, one of MRS and MSR is |
2224 | | // going to get the wrong entry |
2225 | 3.68k | if (Val == ARM64_SYSREG_DBGDTRTX_EL0) { |
2226 | 34 | SStream_concat0(O, "dbgdtrtx_el0"); |
2227 | | |
2228 | 34 | if (MI->csh->detail) { |
2229 | 34 | #ifndef CAPSTONE_DIET |
2230 | 34 | uint8_t access; |
2231 | | |
2232 | 34 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2233 | 34 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2234 | 34 | MI->ac_idx++; |
2235 | 34 | #endif |
2236 | | |
2237 | 34 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
2238 | 34 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val; |
2239 | 34 | MI->flat_insn->detail->arm64.op_count++; |
2240 | 34 | } |
2241 | | |
2242 | 34 | return; |
2243 | 34 | } |
2244 | | |
2245 | | // Another hack for a register which has an alternative name which is not an alias, |
2246 | | // and is not in the Armv9-A documentation. |
2247 | 3.64k | if( Val == ARM64_SYSREG_VSCTLR_EL2){ |
2248 | 44 | SStream_concat0(O, "ttbr0_el2"); |
2249 | | |
2250 | 44 | if (MI->csh->detail) { |
2251 | 44 | #ifndef CAPSTONE_DIET |
2252 | 44 | uint8_t access; |
2253 | | |
2254 | 44 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2255 | 44 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2256 | 44 | MI->ac_idx++; |
2257 | 44 | #endif |
2258 | | |
2259 | 44 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
2260 | 44 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val; |
2261 | 44 | MI->flat_insn->detail->arm64.op_count++; |
2262 | 44 | } |
2263 | | |
2264 | 44 | return; |
2265 | 44 | } |
2266 | | |
2267 | | // if (Reg && Reg->Writeable && Reg->haveFeatures(STI.getFeatureBits())) |
2268 | 3.60k | if (Reg && Reg->Writeable) { |
2269 | 114 | SStream_concat0(O, Reg->Name); |
2270 | | |
2271 | 114 | if (MI->csh->detail) { |
2272 | 114 | #ifndef CAPSTONE_DIET |
2273 | 114 | uint8_t access; |
2274 | | |
2275 | 114 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2276 | 114 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2277 | 114 | MI->ac_idx++; |
2278 | 114 | #endif |
2279 | | |
2280 | 114 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS; |
2281 | 114 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Reg->Encoding; |
2282 | 114 | MI->flat_insn->detail->arm64.op_count++; |
2283 | 114 | } |
2284 | 3.49k | } else { |
2285 | 3.49k | char result[128]; |
2286 | | |
2287 | 3.49k | AArch64SysReg_genericRegisterString(Val, result); |
2288 | 3.49k | SStream_concat0(O, result); |
2289 | | |
2290 | 3.49k | if (MI->csh->detail) { |
2291 | 3.49k | #ifndef CAPSTONE_DIET |
2292 | 3.49k | uint8_t access; |
2293 | 3.49k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2294 | 3.49k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2295 | 3.49k | MI->ac_idx++; |
2296 | 3.49k | #endif |
2297 | 3.49k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG_MRS; |
2298 | 3.49k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Val; |
2299 | 3.49k | MI->flat_insn->detail->arm64.op_count++; |
2300 | 3.49k | } |
2301 | 3.49k | } |
2302 | 3.60k | } |
2303 | | |
2304 | | static void printSystemPStateField(MCInst *MI, unsigned OpNum, SStream *O) |
2305 | 201 | { |
2306 | 201 | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2307 | | |
2308 | 201 | const PState *PState = lookupPStateByEncoding(Val); |
2309 | | |
2310 | 201 | if (PState) { |
2311 | 201 | SStream_concat0(O, PState->Name); |
2312 | | |
2313 | 201 | if (MI->csh->detail) { |
2314 | 201 | #ifndef CAPSTONE_DIET |
2315 | 201 | uint8_t access; |
2316 | 201 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2317 | 201 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2318 | 201 | MI->ac_idx++; |
2319 | 201 | #endif |
2320 | 201 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_PSTATE; |
2321 | 201 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].pstate = Val; |
2322 | 201 | MI->flat_insn->detail->arm64.op_count++; |
2323 | 201 | } |
2324 | 201 | } else { |
2325 | 0 | printUInt32Bang(O, Val); |
2326 | |
|
2327 | 0 | if (MI->csh->detail) { |
2328 | 0 | #ifndef CAPSTONE_DIET |
2329 | 0 | unsigned char access; |
2330 | |
|
2331 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2332 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2333 | 0 | MI->ac_idx++; |
2334 | 0 | #endif |
2335 | |
|
2336 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
2337 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val; |
2338 | 0 | MI->flat_insn->detail->arm64.op_count++; |
2339 | 0 | } |
2340 | 0 | } |
2341 | 201 | } |
2342 | | |
2343 | | static void printSIMDType10Operand(MCInst *MI, unsigned OpNum, SStream *O) |
2344 | 256 | { |
2345 | 256 | uint8_t RawVal = (uint8_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2346 | 256 | uint64_t Val = AArch64_AM_decodeAdvSIMDModImmType10(RawVal); |
2347 | | |
2348 | 256 | SStream_concat(O, "#%#016llx", Val); |
2349 | | |
2350 | 256 | if (MI->csh->detail) { |
2351 | 256 | #ifndef CAPSTONE_DIET |
2352 | 256 | unsigned char access; |
2353 | | |
2354 | 256 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2355 | 256 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2356 | 256 | MI->ac_idx++; |
2357 | 256 | #endif |
2358 | 256 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM; |
2359 | 256 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val; |
2360 | 256 | MI->flat_insn->detail->arm64.op_count++; |
2361 | 256 | } |
2362 | 256 | } |
2363 | | |
2364 | | static void printComplexRotationOp(MCInst *MI, unsigned OpNum, SStream *O, int64_t Angle, int64_t Remainder) |
2365 | 1.35k | { |
2366 | 1.35k | unsigned int Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2367 | 1.35k | printInt64Bang(O, (Val * Angle) + Remainder); |
2368 | 1.35k | op_addImm(MI, (Val * Angle) + Remainder); |
2369 | 1.35k | } |
2370 | | |
2371 | | static void printSVCROp(MCInst *MI, unsigned OpNum, SStream *O) |
2372 | 0 | { |
2373 | 0 | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
2374 | | // assert(MCOperand_isImm(MO) && "Unexpected operand type!"); |
2375 | 0 | unsigned svcrop = MCOperand_getImm(MO); |
2376 | 0 | const SVCR *svcr = lookupSVCRByEncoding(svcrop); |
2377 | | // assert(svcr && "Unexpected SVCR operand!"); |
2378 | 0 | SStream_concat0(O, svcr->Name); |
2379 | |
|
2380 | 0 | if (MI->csh->detail) { |
2381 | 0 | #ifndef CAPSTONE_DIET |
2382 | 0 | uint8_t access; |
2383 | |
|
2384 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2385 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2386 | 0 | MI->ac_idx++; |
2387 | 0 | #endif |
2388 | |
|
2389 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SVCR; |
2390 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = (unsigned)ARM64_SYSREG_SVCR; |
2391 | 0 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].svcr = svcr->Encoding; |
2392 | 0 | MI->flat_insn->detail->arm64.op_count++; |
2393 | 0 | } |
2394 | 0 | } |
2395 | | |
2396 | | static void printMatrix(MCInst *MI, unsigned OpNum, SStream *O, int EltSize) |
2397 | 109 | { |
2398 | 109 | MCOperand *RegOp = MCInst_getOperand(MI, OpNum); |
2399 | | // assert(MCOperand_isReg(RegOp) && "Unexpected operand type!"); |
2400 | 109 | unsigned Reg = MCOperand_getReg(RegOp); |
2401 | | |
2402 | 109 | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
2403 | 109 | const char *sizeStr = ""; |
2404 | 109 | switch (EltSize) { |
2405 | 109 | case 0: |
2406 | 109 | sizeStr = ""; |
2407 | 109 | break; |
2408 | 0 | case 8: |
2409 | 0 | sizeStr = ".b"; |
2410 | 0 | break; |
2411 | 0 | case 16: |
2412 | 0 | sizeStr = ".h"; |
2413 | 0 | break; |
2414 | 0 | case 32: |
2415 | 0 | sizeStr = ".s"; |
2416 | 0 | break; |
2417 | 0 | case 64: |
2418 | 0 | sizeStr = ".d"; |
2419 | 0 | break; |
2420 | 0 | case 128: |
2421 | 0 | sizeStr = ".q"; |
2422 | 0 | break; |
2423 | 0 | default: |
2424 | 0 | break; |
2425 | | // llvm_unreachable("Unsupported element size"); |
2426 | 109 | } |
2427 | 109 | SStream_concat0(O, sizeStr); |
2428 | | |
2429 | 109 | if (MI->csh->detail) { |
2430 | 109 | #ifndef CAPSTONE_DIET |
2431 | 109 | uint8_t access; |
2432 | | |
2433 | 109 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2434 | 109 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2435 | 109 | MI->ac_idx++; |
2436 | 109 | #endif |
2437 | | |
2438 | 109 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
2439 | 109 | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
2440 | 109 | MI->flat_insn->detail->arm64.op_count++; |
2441 | 109 | } |
2442 | 109 | } |
2443 | | |
2444 | | static void printMatrixIndex(MCInst *MI, unsigned OpNum, SStream *O) |
2445 | 4.58k | { |
2446 | 4.58k | int64_t imm = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2447 | 4.58k | printInt64(O, imm); |
2448 | | |
2449 | 4.58k | if (MI->csh->detail) { |
2450 | 4.58k | if (MI->csh->doing_SME_Index) { |
2451 | | // Access op_count-1 as We want to add info to previous operand, not create a new one |
2452 | 4.58k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count-1].sme_index.disp = imm; |
2453 | 4.58k | } |
2454 | 4.58k | } |
2455 | 4.58k | } |
2456 | | |
2457 | | static void printMatrixTile(MCInst *MI, unsigned OpNum, SStream *O) |
2458 | 1.32k | { |
2459 | 1.32k | MCOperand *RegOp = MCInst_getOperand(MI, OpNum); |
2460 | | // assert(MCOperand_isReg(RegOp) && "Unexpected operand type!"); |
2461 | 1.32k | unsigned Reg = MCOperand_getReg(RegOp); |
2462 | 1.32k | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
2463 | | |
2464 | 1.32k | if (MI->csh->detail) { |
2465 | 1.32k | #ifndef CAPSTONE_DIET |
2466 | 1.32k | uint8_t access; |
2467 | | |
2468 | 1.32k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2469 | 1.32k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2470 | 1.32k | MI->ac_idx++; |
2471 | 1.32k | #endif |
2472 | | |
2473 | 1.32k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
2474 | 1.32k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
2475 | 1.32k | MI->flat_insn->detail->arm64.op_count++; |
2476 | 1.32k | } |
2477 | 1.32k | } |
2478 | | |
2479 | | static void printMatrixTileVector(MCInst *MI, unsigned OpNum, SStream *O, bool IsVertical) |
2480 | 4.21k | { |
2481 | 4.21k | MCOperand *RegOp = MCInst_getOperand(MI, OpNum); |
2482 | | // assert(MCOperand_isReg(RegOp) && "Unexpected operand type!"); |
2483 | 4.21k | unsigned Reg = MCOperand_getReg(RegOp); |
2484 | 4.21k | #ifndef CAPSTONE_DIET |
2485 | 4.21k | const char *RegName = getRegisterName(Reg, AArch64_NoRegAltName); |
2486 | | |
2487 | 4.21k | const size_t strLn = strlen(RegName); |
2488 | | // +2 for extra chars, + 1 for null char \0 |
2489 | 4.21k | char *RegNameNew = cs_mem_malloc(sizeof(char) * (strLn + 2 + 1)); |
2490 | 4.21k | int index = 0, i; |
2491 | 33.8k | for (i = 0; i < (strLn + 2); i++){ |
2492 | 29.6k | if(RegName[i] != '.'){ |
2493 | 25.4k | RegNameNew[index] = RegName[i]; |
2494 | 25.4k | index++; |
2495 | 25.4k | } |
2496 | 4.21k | else{ |
2497 | 4.21k | RegNameNew[index] = IsVertical ? 'v' : 'h'; |
2498 | 4.21k | RegNameNew[index + 1] = '.'; |
2499 | 4.21k | index += 2; |
2500 | 4.21k | } |
2501 | 29.6k | } |
2502 | 4.21k | SStream_concat0(O, RegNameNew); |
2503 | 4.21k | #endif |
2504 | | |
2505 | 4.21k | if (MI->csh->detail) { |
2506 | 4.21k | #ifndef CAPSTONE_DIET |
2507 | 4.21k | uint8_t access; |
2508 | | |
2509 | 4.21k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2510 | 4.21k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2511 | 4.21k | MI->ac_idx++; |
2512 | 4.21k | #endif |
2513 | | |
2514 | 4.21k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
2515 | 4.21k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
2516 | 4.21k | MI->flat_insn->detail->arm64.op_count++; |
2517 | 4.21k | } |
2518 | 4.21k | #ifndef CAPSTONE_DIET |
2519 | 4.21k | cs_mem_free(RegNameNew); |
2520 | 4.21k | #endif |
2521 | 4.21k | } |
2522 | | |
2523 | | static const unsigned MatrixZADRegisterTable[] = { |
2524 | | AArch64_ZAD0, AArch64_ZAD1, AArch64_ZAD2, AArch64_ZAD3, |
2525 | | AArch64_ZAD4, AArch64_ZAD5, AArch64_ZAD6, AArch64_ZAD7 |
2526 | | }; |
2527 | | |
2528 | 556 | static void printMatrixTileList(MCInst *MI, unsigned OpNum, SStream *O){ |
2529 | 556 | unsigned MaxRegs = 8; |
2530 | 556 | unsigned RegMask = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2531 | | |
2532 | 556 | unsigned NumRegs = 0, I; |
2533 | 5.00k | for (I = 0; I < MaxRegs; ++I) |
2534 | 4.44k | if ((RegMask & (1 << I)) != 0) |
2535 | 1.51k | ++NumRegs; |
2536 | | |
2537 | 556 | SStream_concat0(O, "{"); |
2538 | 556 | unsigned Printed = 0, J; |
2539 | 5.00k | for (J = 0; J < MaxRegs; ++J) { |
2540 | 4.44k | unsigned Reg = RegMask & (1 << J); |
2541 | 4.44k | if (Reg == 0) |
2542 | 2.92k | continue; |
2543 | 1.51k | SStream_concat0(O, getRegisterName(MatrixZADRegisterTable[J], AArch64_NoRegAltName)); |
2544 | | |
2545 | 1.51k | if (MI->csh->detail) { |
2546 | 1.51k | #ifndef CAPSTONE_DIET |
2547 | 1.51k | uint8_t access; |
2548 | | |
2549 | 1.51k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2550 | 1.51k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2551 | 1.51k | MI->ac_idx++; |
2552 | 1.51k | #endif |
2553 | | |
2554 | 1.51k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
2555 | 1.51k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MatrixZADRegisterTable[J]; |
2556 | 1.51k | MI->flat_insn->detail->arm64.op_count++; |
2557 | 1.51k | } |
2558 | | |
2559 | 1.51k | if (Printed + 1 != NumRegs) |
2560 | 964 | SStream_concat0(O, ", "); |
2561 | 1.51k | ++Printed; |
2562 | 1.51k | } |
2563 | 556 | SStream_concat0(O, "}"); |
2564 | 556 | } |
2565 | | |
2566 | | static void printSVEPattern(MCInst *MI, unsigned OpNum, SStream *O) |
2567 | 7.43k | { |
2568 | 7.43k | unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2569 | | |
2570 | 7.43k | const SVEPREDPAT *Pat = lookupSVEPREDPATByEncoding(Val); |
2571 | 7.43k | if (Pat) |
2572 | 4.01k | SStream_concat0(O, Pat->Name); |
2573 | 3.41k | else |
2574 | 3.41k | printUInt32Bang(O, Val); |
2575 | 7.43k | } |
2576 | | |
2577 | | // default suffix = 0 |
2578 | | static void printSVERegOp(MCInst *MI, unsigned OpNum, SStream *O, char suffix) |
2579 | 136k | { |
2580 | 136k | unsigned int Reg; |
2581 | | |
2582 | | #if 0 |
2583 | | switch (suffix) { |
2584 | | case 0: |
2585 | | case 'b': |
2586 | | case 'h': |
2587 | | case 's': |
2588 | | case 'd': |
2589 | | case 'q': |
2590 | | break; |
2591 | | default: |
2592 | | // llvm_unreachable("Invalid kind specifier."); |
2593 | | } |
2594 | | #endif |
2595 | | |
2596 | 136k | Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2597 | | |
2598 | 136k | if (MI->csh->detail) { |
2599 | 136k | #ifndef CAPSTONE_DIET |
2600 | 136k | uint8_t access; |
2601 | | |
2602 | 136k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2603 | 136k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2604 | 136k | MI->ac_idx++; |
2605 | 136k | #endif |
2606 | 136k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
2607 | 136k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
2608 | 136k | MI->flat_insn->detail->arm64.op_count++; |
2609 | 136k | } |
2610 | | |
2611 | 136k | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
2612 | | |
2613 | 136k | if (suffix != '\0') |
2614 | 87.9k | SStream_concat(O, ".%c", suffix); |
2615 | 136k | } |
2616 | | |
2617 | | static void printImmSVE16(int16_t Val, SStream *O) |
2618 | 2.11k | { |
2619 | 2.11k | printUInt32Bang(O, Val); |
2620 | 2.11k | } |
2621 | | |
2622 | | static void printImmSVE32(int32_t Val, SStream *O) |
2623 | 1.34k | { |
2624 | 1.34k | printUInt32Bang(O, Val); |
2625 | 1.34k | } |
2626 | | |
2627 | | static void printImmSVE64(int64_t Val, SStream *O) |
2628 | 836 | { |
2629 | 836 | printUInt64Bang(O, Val); |
2630 | 836 | } |
2631 | | |
2632 | | static void printImm8OptLsl32(MCInst *MI, unsigned OpNum, SStream *O) |
2633 | 1.41k | { |
2634 | 1.41k | unsigned UnscaledVal = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2635 | 1.41k | unsigned Shift = MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1)); |
2636 | 1.41k | uint32_t Val; |
2637 | | |
2638 | | // assert(AArch64_AM::getShiftType(Shift) == AArch64_AM::LSL && |
2639 | | // "Unexepected shift type!"); |
2640 | | |
2641 | | // #0 lsl #8 is never pretty printed |
2642 | 1.41k | if ((UnscaledVal == 0) && (AArch64_AM_getShiftValue(Shift) != 0)) { |
2643 | 70 | printUInt32Bang(O, UnscaledVal); |
2644 | 70 | printShifter(MI, OpNum + 1, O); |
2645 | 70 | return; |
2646 | 70 | } |
2647 | | |
2648 | 1.34k | Val = UnscaledVal * (1 << AArch64_AM_getShiftValue(Shift)); |
2649 | 1.34k | printImmSVE32(Val, O); |
2650 | 1.34k | } |
2651 | | |
2652 | | static void printImm8OptLsl64(MCInst *MI, unsigned OpNum, SStream *O) |
2653 | 517 | { |
2654 | 517 | unsigned UnscaledVal = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2655 | 517 | unsigned Shift = MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1)); |
2656 | 517 | uint64_t Val; |
2657 | | |
2658 | | // assert(AArch64_AM::getShiftType(Shift) == AArch64_AM::LSL && |
2659 | | // "Unexepected shift type!"); |
2660 | | |
2661 | | // #0 lsl #8 is never pretty printed |
2662 | 517 | if ((UnscaledVal == 0) && (AArch64_AM_getShiftValue(Shift) != 0)) { |
2663 | 43 | printUInt32Bang(O, UnscaledVal); |
2664 | 43 | printShifter(MI, OpNum + 1, O); |
2665 | 43 | return; |
2666 | 43 | } |
2667 | | |
2668 | 474 | Val = UnscaledVal * (1 << AArch64_AM_getShiftValue(Shift)); |
2669 | 474 | printImmSVE64(Val, O); |
2670 | 474 | } |
2671 | | |
2672 | | static void printSVELogicalImm16(MCInst *MI, unsigned OpNum, SStream *O) |
2673 | 1.75k | { |
2674 | 1.75k | uint64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2675 | 1.75k | uint64_t PrintVal = AArch64_AM_decodeLogicalImmediate(Val, 64); |
2676 | | |
2677 | | // Prefer the default format for 16bit values, hex otherwise. |
2678 | 1.75k | printImmSVE16(PrintVal, O); |
2679 | 1.75k | } |
2680 | | |
2681 | | static void printSVELogicalImm32(MCInst *MI, unsigned OpNum, SStream *O) |
2682 | 775 | { |
2683 | 775 | uint64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2684 | 775 | uint64_t PrintVal = AArch64_AM_decodeLogicalImmediate(Val, 64); |
2685 | | |
2686 | | // Prefer the default format for 16bit values, hex otherwise. |
2687 | 775 | if ((uint16_t)PrintVal == (uint32_t)PrintVal) |
2688 | 362 | printImmSVE16(PrintVal, O); |
2689 | 413 | else |
2690 | 413 | printUInt64Bang(O, PrintVal); |
2691 | 775 | } |
2692 | | |
2693 | | static void printSVELogicalImm64(MCInst *MI, unsigned OpNum, SStream *O) |
2694 | 362 | { |
2695 | 362 | uint64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2696 | 362 | uint64_t PrintVal = AArch64_AM_decodeLogicalImmediate(Val, 64); |
2697 | | |
2698 | 362 | printImmSVE64(PrintVal, O); |
2699 | 362 | } |
2700 | | |
2701 | | static void printZPRasFPR(MCInst *MI, unsigned OpNum, SStream *O, int Width) |
2702 | 1.98k | { |
2703 | 1.98k | unsigned int Base, Reg; |
2704 | | |
2705 | 1.98k | switch (Width) { |
2706 | 0 | default: // llvm_unreachable("Unsupported width"); |
2707 | 142 | case 8: Base = AArch64_B0; break; |
2708 | 518 | case 16: Base = AArch64_H0; break; |
2709 | 1.04k | case 32: Base = AArch64_S0; break; |
2710 | 268 | case 64: Base = AArch64_D0; break; |
2711 | 11 | case 128: Base = AArch64_Q0; break; |
2712 | 1.98k | } |
2713 | | |
2714 | 1.98k | Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) - AArch64_Z0 + Base; |
2715 | | |
2716 | 1.98k | SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName)); |
2717 | | |
2718 | 1.98k | if (MI->csh->detail) { |
2719 | 1.98k | #ifndef CAPSTONE_DIET |
2720 | 1.98k | uint8_t access; |
2721 | | |
2722 | 1.98k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2723 | 1.98k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access; |
2724 | 1.98k | MI->ac_idx++; |
2725 | 1.98k | #endif |
2726 | 1.98k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG; |
2727 | 1.98k | MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg; |
2728 | 1.98k | MI->flat_insn->detail->arm64.op_count++; |
2729 | 1.98k | } |
2730 | 1.98k | } |
2731 | | |
2732 | | static void printExactFPImm(MCInst *MI, unsigned OpNum, SStream *O, unsigned ImmIs0, unsigned ImmIs1) |
2733 | 806 | { |
2734 | 806 | const ExactFPImm *Imm0Desc = lookupExactFPImmByEnum(ImmIs0); |
2735 | 806 | const ExactFPImm *Imm1Desc = lookupExactFPImmByEnum(ImmIs1); |
2736 | 806 | unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2737 | | |
2738 | 806 | SStream_concat0(O, Val ? Imm1Desc->Repr : Imm0Desc->Repr); |
2739 | 806 | } |
2740 | | |
2741 | | static void printGPR64as32(MCInst *MI, unsigned OpNum, SStream *O) |
2742 | 6.51k | { |
2743 | 6.51k | unsigned int Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2744 | | |
2745 | 6.51k | SStream_concat0(O, getRegisterName(getWRegFromXReg(Reg), AArch64_NoRegAltName)); |
2746 | 6.51k | } |
2747 | | |
2748 | | static void printGPR64x8(MCInst *MI, unsigned OpNum, SStream *O) |
2749 | 190 | { |
2750 | 190 | unsigned int Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2751 | | |
2752 | 190 | SStream_concat0(O, getRegisterName(MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_x8sub_0), AArch64_NoRegAltName)); |
2753 | 190 | } |
2754 | | |
2755 | | #define PRINT_ALIAS_INSTR |
2756 | | #include "AArch64GenAsmWriter.inc" |
2757 | | #include "AArch64GenRegisterName.inc" |
2758 | | |
2759 | | void AArch64_post_printer(csh handle, cs_insn *flat_insn, char *insn_asm, MCInst *mci) |
2760 | 284k | { |
2761 | 284k | if (((cs_struct *)handle)->detail != CS_OPT_ON) |
2762 | 0 | return; |
2763 | | |
2764 | 284k | if (mci->csh->detail) { |
2765 | 284k | unsigned opcode = MCInst_getOpcode(mci); |
2766 | | |
2767 | 284k | switch (opcode) { |
2768 | 230k | default: |
2769 | 230k | break; |
2770 | 230k | case AArch64_LD1Fourv16b_POST: |
2771 | 814 | case AArch64_LD1Fourv1d_POST: |
2772 | 1.13k | case AArch64_LD1Fourv2d_POST: |
2773 | 1.40k | case AArch64_LD1Fourv2s_POST: |
2774 | 1.50k | case AArch64_LD1Fourv4h_POST: |
2775 | 1.52k | case AArch64_LD1Fourv4s_POST: |
2776 | 1.86k | case AArch64_LD1Fourv8b_POST: |
2777 | 1.95k | case AArch64_LD1Fourv8h_POST: |
2778 | 2.01k | case AArch64_LD1Onev16b_POST: |
2779 | 2.14k | case AArch64_LD1Onev1d_POST: |
2780 | 2.78k | case AArch64_LD1Onev2d_POST: |
2781 | 2.98k | case AArch64_LD1Onev2s_POST: |
2782 | 2.99k | case AArch64_LD1Onev4h_POST: |
2783 | 3.03k | case AArch64_LD1Onev4s_POST: |
2784 | 3.07k | case AArch64_LD1Onev8b_POST: |
2785 | 3.67k | case AArch64_LD1Onev8h_POST: |
2786 | 3.94k | case AArch64_LD1Rv16b_POST: |
2787 | 4.10k | case AArch64_LD1Rv1d_POST: |
2788 | 4.12k | case AArch64_LD1Rv2d_POST: |
2789 | 4.19k | case AArch64_LD1Rv2s_POST: |
2790 | 4.21k | case AArch64_LD1Rv4h_POST: |
2791 | 4.28k | case AArch64_LD1Rv4s_POST: |
2792 | 4.34k | case AArch64_LD1Rv8b_POST: |
2793 | 4.38k | case AArch64_LD1Rv8h_POST: |
2794 | 4.67k | case AArch64_LD1Threev16b_POST: |
2795 | 4.78k | case AArch64_LD1Threev1d_POST: |
2796 | 4.88k | case AArch64_LD1Threev2d_POST: |
2797 | 4.92k | case AArch64_LD1Threev2s_POST: |
2798 | 4.96k | case AArch64_LD1Threev4h_POST: |
2799 | 5.01k | case AArch64_LD1Threev4s_POST: |
2800 | 5.19k | case AArch64_LD1Threev8b_POST: |
2801 | 5.21k | case AArch64_LD1Threev8h_POST: |
2802 | 5.25k | case AArch64_LD1Twov16b_POST: |
2803 | 5.31k | case AArch64_LD1Twov1d_POST: |
2804 | 5.33k | case AArch64_LD1Twov2d_POST: |
2805 | 5.39k | case AArch64_LD1Twov2s_POST: |
2806 | 5.51k | case AArch64_LD1Twov4h_POST: |
2807 | 5.59k | case AArch64_LD1Twov4s_POST: |
2808 | 6.27k | case AArch64_LD1Twov8b_POST: |
2809 | 6.29k | case AArch64_LD1Twov8h_POST: |
2810 | 6.68k | case AArch64_LD1i16_POST: |
2811 | 8.89k | case AArch64_LD1i32_POST: |
2812 | 9.04k | case AArch64_LD1i64_POST: |
2813 | 9.43k | case AArch64_LD1i8_POST: |
2814 | 9.50k | case AArch64_LD2Rv16b_POST: |
2815 | 9.52k | case AArch64_LD2Rv1d_POST: |
2816 | 9.59k | case AArch64_LD2Rv2d_POST: |
2817 | 9.61k | case AArch64_LD2Rv2s_POST: |
2818 | 9.69k | case AArch64_LD2Rv4h_POST: |
2819 | 9.72k | case AArch64_LD2Rv4s_POST: |
2820 | 9.77k | case AArch64_LD2Rv8b_POST: |
2821 | 9.92k | case AArch64_LD2Rv8h_POST: |
2822 | 9.96k | case AArch64_LD2Twov16b_POST: |
2823 | 10.0k | case AArch64_LD2Twov2d_POST: |
2824 | 10.0k | case AArch64_LD2Twov2s_POST: |
2825 | 10.1k | case AArch64_LD2Twov4h_POST: |
2826 | 10.1k | case AArch64_LD2Twov4s_POST: |
2827 | 10.3k | case AArch64_LD2Twov8b_POST: |
2828 | 10.5k | case AArch64_LD2Twov8h_POST: |
2829 | 11.1k | case AArch64_LD2i16_POST: |
2830 | 11.3k | case AArch64_LD2i32_POST: |
2831 | 11.5k | case AArch64_LD2i64_POST: |
2832 | 12.0k | case AArch64_LD2i8_POST: |
2833 | 12.1k | case AArch64_LD3Rv16b_POST: |
2834 | 12.2k | case AArch64_LD3Rv1d_POST: |
2835 | 12.2k | case AArch64_LD3Rv2d_POST: |
2836 | 12.4k | case AArch64_LD3Rv2s_POST: |
2837 | 12.4k | case AArch64_LD3Rv4h_POST: |
2838 | 12.4k | case AArch64_LD3Rv4s_POST: |
2839 | 12.5k | case AArch64_LD3Rv8b_POST: |
2840 | 12.5k | case AArch64_LD3Rv8h_POST: |
2841 | 12.5k | case AArch64_LD3Threev16b_POST: |
2842 | 12.6k | case AArch64_LD3Threev2d_POST: |
2843 | 12.6k | case AArch64_LD3Threev2s_POST: |
2844 | 12.6k | case AArch64_LD3Threev4h_POST: |
2845 | 12.7k | case AArch64_LD3Threev4s_POST: |
2846 | 12.7k | case AArch64_LD3Threev8b_POST: |
2847 | 12.7k | case AArch64_LD3Threev8h_POST: |
2848 | 13.1k | case AArch64_LD3i16_POST: |
2849 | 13.8k | case AArch64_LD3i32_POST: |
2850 | 14.0k | case AArch64_LD3i64_POST: |
2851 | 15.2k | case AArch64_LD3i8_POST: |
2852 | 15.3k | case AArch64_LD4Fourv16b_POST: |
2853 | 15.4k | case AArch64_LD4Fourv2d_POST: |
2854 | 15.4k | case AArch64_LD4Fourv2s_POST: |
2855 | 15.5k | case AArch64_LD4Fourv4h_POST: |
2856 | 15.5k | case AArch64_LD4Fourv4s_POST: |
2857 | 15.6k | case AArch64_LD4Fourv8b_POST: |
2858 | 15.7k | case AArch64_LD4Fourv8h_POST: |
2859 | 15.7k | case AArch64_LD4Rv16b_POST: |
2860 | 15.8k | case AArch64_LD4Rv1d_POST: |
2861 | 15.8k | case AArch64_LD4Rv2d_POST: |
2862 | 15.8k | case AArch64_LD4Rv2s_POST: |
2863 | 15.8k | case AArch64_LD4Rv4h_POST: |
2864 | 16.0k | case AArch64_LD4Rv4s_POST: |
2865 | 16.0k | case AArch64_LD4Rv8b_POST: |
2866 | 16.1k | case AArch64_LD4Rv8h_POST: |
2867 | 16.8k | case AArch64_LD4i16_POST: |
2868 | 16.9k | case AArch64_LD4i32_POST: |
2869 | 17.0k | case AArch64_LD4i64_POST: |
2870 | 18.0k | case AArch64_LD4i8_POST: |
2871 | 18.0k | case AArch64_LDRBBpost: |
2872 | 18.4k | case AArch64_LDRBpost: |
2873 | 18.5k | case AArch64_LDRDpost: |
2874 | 18.5k | case AArch64_LDRHHpost: |
2875 | 18.6k | case AArch64_LDRHpost: |
2876 | 18.6k | case AArch64_LDRQpost: |
2877 | 18.7k | case AArch64_LDPDpost: |
2878 | 18.9k | case AArch64_LDPQpost: |
2879 | 19.4k | case AArch64_LDPSWpost: |
2880 | 19.6k | case AArch64_LDPSpost: |
2881 | 19.8k | case AArch64_LDPWpost: |
2882 | 19.9k | case AArch64_LDPXpost: |
2883 | 20.1k | case AArch64_ST1Fourv16b_POST: |
2884 | 20.1k | case AArch64_ST1Fourv1d_POST: |
2885 | 20.2k | case AArch64_ST1Fourv2d_POST: |
2886 | 20.9k | case AArch64_ST1Fourv2s_POST: |
2887 | 20.9k | case AArch64_ST1Fourv4h_POST: |
2888 | 22.5k | case AArch64_ST1Fourv4s_POST: |
2889 | 22.6k | case AArch64_ST1Fourv8b_POST: |
2890 | 22.8k | case AArch64_ST1Fourv8h_POST: |
2891 | 22.8k | case AArch64_ST1Onev16b_POST: |
2892 | 22.9k | case AArch64_ST1Onev1d_POST: |
2893 | 23.1k | case AArch64_ST1Onev2d_POST: |
2894 | 23.1k | case AArch64_ST1Onev2s_POST: |
2895 | 23.5k | case AArch64_ST1Onev4h_POST: |
2896 | 23.6k | case AArch64_ST1Onev4s_POST: |
2897 | 24.1k | case AArch64_ST1Onev8b_POST: |
2898 | 24.1k | case AArch64_ST1Onev8h_POST: |
2899 | 24.2k | case AArch64_ST1Threev16b_POST: |
2900 | 24.2k | case AArch64_ST1Threev1d_POST: |
2901 | 24.2k | case AArch64_ST1Threev2d_POST: |
2902 | 24.5k | case AArch64_ST1Threev2s_POST: |
2903 | 24.5k | case AArch64_ST1Threev4h_POST: |
2904 | 24.6k | case AArch64_ST1Threev4s_POST: |
2905 | 25.3k | case AArch64_ST1Threev8b_POST: |
2906 | 25.4k | case AArch64_ST1Threev8h_POST: |
2907 | 25.5k | case AArch64_ST1Twov16b_POST: |
2908 | 25.6k | case AArch64_ST1Twov1d_POST: |
2909 | 25.7k | case AArch64_ST1Twov2d_POST: |
2910 | 25.8k | case AArch64_ST1Twov2s_POST: |
2911 | 25.9k | case AArch64_ST1Twov4h_POST: |
2912 | 27.6k | case AArch64_ST1Twov4s_POST: |
2913 | 27.7k | case AArch64_ST1Twov8b_POST: |
2914 | 28.1k | case AArch64_ST1Twov8h_POST: |
2915 | 28.1k | case AArch64_ST1i16_POST: |
2916 | 29.6k | case AArch64_ST1i32_POST: |
2917 | 30.5k | case AArch64_ST1i64_POST: |
2918 | 31.0k | case AArch64_ST1i8_POST: |
2919 | 31.4k | case AArch64_ST2GPostIndex: |
2920 | 31.4k | case AArch64_ST2Twov16b_POST: |
2921 | 32.0k | case AArch64_ST2Twov2d_POST: |
2922 | 32.0k | case AArch64_ST2Twov2s_POST: |
2923 | 32.2k | case AArch64_ST2Twov4h_POST: |
2924 | 32.2k | case AArch64_ST2Twov4s_POST: |
2925 | 32.5k | case AArch64_ST2Twov8b_POST: |
2926 | 32.5k | case AArch64_ST2Twov8h_POST: |
2927 | 33.2k | case AArch64_ST2i16_POST: |
2928 | 33.4k | case AArch64_ST2i32_POST: |
2929 | 33.9k | case AArch64_ST2i64_POST: |
2930 | 35.6k | case AArch64_ST2i8_POST: |
2931 | 35.6k | case AArch64_ST3Threev16b_POST: |
2932 | 35.7k | case AArch64_ST3Threev2d_POST: |
2933 | 35.7k | case AArch64_ST3Threev2s_POST: |
2934 | 35.8k | case AArch64_ST3Threev4h_POST: |
2935 | 35.9k | case AArch64_ST3Threev4s_POST: |
2936 | 36.0k | case AArch64_ST3Threev8b_POST: |
2937 | 36.0k | case AArch64_ST3Threev8h_POST: |
2938 | 36.5k | case AArch64_ST3i16_POST: |
2939 | 36.6k | case AArch64_ST3i32_POST: |
2940 | 37.4k | case AArch64_ST3i64_POST: |
2941 | 37.9k | case AArch64_ST3i8_POST: |
2942 | 38.5k | case AArch64_ST4Fourv16b_POST: |
2943 | 38.5k | case AArch64_ST4Fourv2d_POST: |
2944 | 38.6k | case AArch64_ST4Fourv2s_POST: |
2945 | 38.7k | case AArch64_ST4Fourv4h_POST: |
2946 | 38.8k | case AArch64_ST4Fourv4s_POST: |
2947 | 39.2k | case AArch64_ST4Fourv8b_POST: |
2948 | 39.3k | case AArch64_ST4Fourv8h_POST: |
2949 | 39.3k | case AArch64_ST4i16_POST: |
2950 | 39.6k | case AArch64_ST4i32_POST: |
2951 | 39.7k | case AArch64_ST4i64_POST: |
2952 | 41.0k | case AArch64_ST4i8_POST: |
2953 | 41.1k | case AArch64_STPDpost: |
2954 | 41.3k | case AArch64_STPQpost: |
2955 | 41.5k | case AArch64_STPSpost: |
2956 | 41.7k | case AArch64_STPWpost: |
2957 | 42.2k | case AArch64_STPXpost: |
2958 | 42.2k | case AArch64_STRBBpost: |
2959 | 42.8k | case AArch64_STRBpost: |
2960 | 42.9k | case AArch64_STRDpost: |
2961 | 43.1k | case AArch64_STRHHpost: |
2962 | 43.1k | case AArch64_STRHpost: |
2963 | 43.1k | case AArch64_STRQpost: |
2964 | 43.3k | case AArch64_STRSpost: |
2965 | 43.4k | case AArch64_STRWpost: |
2966 | 43.6k | case AArch64_STRXpost: |
2967 | 43.6k | case AArch64_STZ2GPostIndex: |
2968 | 43.9k | case AArch64_STZGPostIndex: |
2969 | 43.9k | case AArch64_STGPostIndex: |
2970 | 43.9k | case AArch64_STGPpost: |
2971 | 44.1k | case AArch64_LDRSBWpost: |
2972 | 44.7k | case AArch64_LDRSBXpost: |
2973 | 44.7k | case AArch64_LDRSHWpost: |
2974 | 45.0k | case AArch64_LDRSHXpost: |
2975 | 45.0k | case AArch64_LDRSWpost: |
2976 | 45.1k | case AArch64_LDRSpost: |
2977 | 45.2k | case AArch64_LDRWpost: |
2978 | 45.2k | case AArch64_LDRXpost: |
2979 | 45.2k | flat_insn->detail->arm64.writeback = true; |
2980 | 45.2k | flat_insn->detail->arm64.post_index = true; |
2981 | 45.2k | break; |
2982 | 96 | case AArch64_LDRAAwriteback: |
2983 | 1.93k | case AArch64_LDRABwriteback: |
2984 | 2.26k | case AArch64_ST2GPreIndex: |
2985 | 2.58k | case AArch64_LDPDpre: |
2986 | 2.67k | case AArch64_LDPQpre: |
2987 | 2.92k | case AArch64_LDPSWpre: |
2988 | 3.10k | case AArch64_LDPSpre: |
2989 | 3.16k | case AArch64_LDPWpre: |
2990 | 3.62k | case AArch64_LDPXpre: |
2991 | 3.79k | case AArch64_LDRBBpre: |
2992 | 3.82k | case AArch64_LDRBpre: |
2993 | 3.89k | case AArch64_LDRDpre: |
2994 | 3.96k | case AArch64_LDRHHpre: |
2995 | 4.00k | case AArch64_LDRHpre: |
2996 | 4.15k | case AArch64_LDRQpre: |
2997 | 4.16k | case AArch64_LDRSBWpre: |
2998 | 4.28k | case AArch64_LDRSBXpre: |
2999 | 4.33k | case AArch64_LDRSHWpre: |
3000 | 4.37k | case AArch64_LDRSHXpre: |
3001 | 4.41k | case AArch64_LDRSWpre: |
3002 | 4.63k | case AArch64_LDRSpre: |
3003 | 4.85k | case AArch64_LDRWpre: |
3004 | 4.93k | case AArch64_LDRXpre: |
3005 | 5.08k | case AArch64_STGPreIndex: |
3006 | 5.19k | case AArch64_STPDpre: |
3007 | 5.44k | case AArch64_STPQpre: |
3008 | 5.86k | case AArch64_STPSpre: |
3009 | 6.13k | case AArch64_STPWpre: |
3010 | 7.00k | case AArch64_STPXpre: |
3011 | 7.04k | case AArch64_STRBBpre: |
3012 | 8.38k | case AArch64_STRBpre: |
3013 | 8.42k | case AArch64_STRDpre: |
3014 | 8.71k | case AArch64_STRHHpre: |
3015 | 8.92k | case AArch64_STRHpre: |
3016 | 8.94k | case AArch64_STRQpre: |
3017 | 9.08k | case AArch64_STRSpre: |
3018 | 9.12k | case AArch64_STRWpre: |
3019 | 9.16k | case AArch64_STRXpre: |
3020 | 9.25k | case AArch64_STZ2GPreIndex: |
3021 | 9.41k | case AArch64_STZGPreIndex: |
3022 | 9.41k | case AArch64_STGPpre: |
3023 | 9.41k | flat_insn->detail->arm64.writeback = true; |
3024 | 9.41k | break; |
3025 | 284k | } |
3026 | 284k | } |
3027 | 284k | } |
3028 | | |
3029 | | #endif |