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