/src/capstonev5/arch/ARM/ARMInstPrinter.c
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- ARMInstPrinter.cpp - Convert ARM 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 ARM MCInst to a .s file. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | /* Capstone Disassembly Engine */ |
15 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */ |
16 | | |
17 | | #ifdef CAPSTONE_HAS_ARM |
18 | | |
19 | | #include <stdio.h> // DEBUG |
20 | | #include <stdlib.h> |
21 | | #include <string.h> |
22 | | #include <capstone/platform.h> |
23 | | |
24 | | #include "ARMInstPrinter.h" |
25 | | #include "ARMAddressingModes.h" |
26 | | #include "ARMBaseInfo.h" |
27 | | #include "ARMDisassembler.h" |
28 | | #include "../../MCInst.h" |
29 | | #include "../../SStream.h" |
30 | | #include "../../MCRegisterInfo.h" |
31 | | #include "../../utils.h" |
32 | | #include "ARMMapping.h" |
33 | | |
34 | | #define GET_SUBTARGETINFO_ENUM |
35 | | #include "ARMGenSubtargetInfo.inc" |
36 | | |
37 | | #include "ARMGenSystemRegister.inc" |
38 | | |
39 | | static void printRegName(cs_struct *h, SStream *OS, unsigned RegNo); |
40 | | |
41 | | // Autogenerated by tblgen. |
42 | | static void printInstruction(MCInst *MI, SStream *O); |
43 | | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O); |
44 | | static void printSORegRegOperand(MCInst *MI, unsigned OpNum, SStream *O); |
45 | | static void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
46 | | |
47 | | static void printAddrModeTBB(MCInst *MI, unsigned OpNum, SStream *O); |
48 | | static void printAddrModeTBH(MCInst *MI, unsigned OpNum, SStream *O); |
49 | | static void printAddrMode2Operand(MCInst *MI, unsigned OpNum, SStream *O); |
50 | | static void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned OpNum, SStream *O); |
51 | | static void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O); |
52 | | static void printAddrMode3Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0); |
53 | | static void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O); |
54 | | static void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op, SStream *O, bool AlwaysPrintImm0); |
55 | | static void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum, SStream *O); |
56 | | static void printPostIdxRegOperand(MCInst *MI, unsigned OpNum, SStream *O); |
57 | | static void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum, SStream *O); |
58 | | static void printAddrMode5Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0); |
59 | | static void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O); |
60 | | static void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O); |
61 | | static void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O); |
62 | | |
63 | | static void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
64 | | static void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O); |
65 | | static void printShiftImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
66 | | static void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O); |
67 | | static void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O); |
68 | | static void printAdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned); |
69 | | static void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
70 | | static void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O); |
71 | | static void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O); |
72 | | static void printThumbAddrModeRROperand(MCInst *MI, unsigned OpNum, SStream *O); |
73 | | static void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned Scale); |
74 | | static void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned OpNum, SStream *O); |
75 | | static void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned OpNum, SStream *O); |
76 | | static void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned OpNum, SStream *O); |
77 | | static void printThumbAddrModeSPOperand(MCInst *MI, unsigned OpNum, SStream *O); |
78 | | static void printT2SOOperand(MCInst *MI, unsigned OpNum, SStream *O); |
79 | | static void printAddrModeImm12Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0); |
80 | | static void printT2AddrModeImm8Operand(MCInst *MI, unsigned OpNum, SStream *O, bool); |
81 | | static void printT2AddrModeImm8s4Operand(MCInst *MI, unsigned OpNum, SStream *O, bool); |
82 | | static void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum, SStream *O); |
83 | | static void printT2AddrModeImm8OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O); |
84 | | static void printT2AddrModeImm8s4OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O); |
85 | | static void printT2AddrModeSoRegOperand(MCInst *MI, unsigned OpNum, SStream *O); |
86 | | static void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O); |
87 | | static void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O); |
88 | | static void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O); |
89 | | static void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O); |
90 | | static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O); |
91 | | static void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O); |
92 | | static void printSBitModifierOperand(MCInst *MI, unsigned OpNum, SStream *O); |
93 | | static void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O); |
94 | | static void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O); |
95 | | static void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O); |
96 | | static void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O); |
97 | | static void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O); |
98 | | static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
99 | | static void printNEONModImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
100 | | static void printImmPlusOneOperand(MCInst *MI, unsigned OpNum, SStream *O); |
101 | | static void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
102 | | static void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O); |
103 | | static void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O); |
104 | | static void printFBits16(MCInst *MI, unsigned OpNum, SStream *O); |
105 | | static void printFBits32(MCInst *MI, unsigned OpNum, SStream *O); |
106 | | static void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O); |
107 | | static void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O); |
108 | | static void printVectorListTwo(MCInst *MI, unsigned OpNum, SStream *O); |
109 | | static void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum, SStream *O); |
110 | | static void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O); |
111 | | static void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O); |
112 | | static void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
113 | | static void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
114 | | static void printVectorListThreeAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
115 | | static void printVectorListFourAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
116 | | static void printVectorListTwoSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
117 | | static void printVectorListThreeSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
118 | | static void printVectorListFourSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O); |
119 | | static void printVectorListThreeSpaced(MCInst *MI, unsigned OpNum, SStream *O); |
120 | | static void printVectorListFourSpaced(MCInst *MI, unsigned OpNum, SStream *O); |
121 | | static void printBankedRegOperand(MCInst *MI, unsigned OpNum, SStream *O); |
122 | | static void printModImmOperand(MCInst *MI, unsigned OpNum, SStream *O); |
123 | | |
124 | | static void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O); |
125 | | static void printTraceSyncBOption(MCInst *MI, unsigned OpNum, SStream *O); |
126 | | static void printComplexRotationOp(MCInst *MI, unsigned OpNo, SStream *O, int64_t Angle, int64_t Remainder); |
127 | | static void printAddrMode5FP16Operand(MCInst *MI, unsigned OpNum, SStream *O, bool AlwaysPrintImm0); |
128 | | |
129 | | |
130 | | #ifndef CAPSTONE_DIET |
131 | | // copy & normalize access info |
132 | | static uint8_t get_op_access(cs_struct *h, unsigned int id, unsigned int index) |
133 | 2.31M | { |
134 | 2.31M | const uint8_t *arr = ARM_get_op_access(h, id); |
135 | | |
136 | 2.31M | if (!arr || arr[index] == CS_AC_IGNORE) |
137 | 5.61k | return 0; |
138 | | |
139 | 2.31M | return arr[index]; |
140 | 2.31M | } |
141 | | #endif |
142 | | |
143 | | static void set_mem_access(MCInst *MI, bool status) |
144 | 876k | { |
145 | 876k | if (MI->csh->detail != CS_OPT_ON) |
146 | 0 | return; |
147 | | |
148 | 876k | MI->csh->doing_mem = status; |
149 | 876k | if (status) { |
150 | 438k | #ifndef CAPSTONE_DIET |
151 | 438k | uint8_t access; |
152 | 438k | #endif |
153 | | |
154 | 438k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM; |
155 | 438k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = ARM_REG_INVALID; |
156 | 438k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID; |
157 | 438k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1; |
158 | 438k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = 0; |
159 | | |
160 | 438k | #ifndef CAPSTONE_DIET |
161 | 438k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
162 | 438k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
163 | 438k | MI->ac_idx++; |
164 | 438k | #endif |
165 | 438k | } else { |
166 | | // done, create the next operand slot |
167 | 438k | MI->flat_insn->detail->arm.op_count++; |
168 | 438k | } |
169 | 876k | } |
170 | | |
171 | | static void op_addImm(MCInst *MI, int v) |
172 | 1.99k | { |
173 | 1.99k | if (MI->csh->detail) { |
174 | 1.99k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
175 | 1.99k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = v; |
176 | 1.99k | MI->flat_insn->detail->arm.op_count++; |
177 | 1.99k | } |
178 | 1.99k | } |
179 | | |
180 | | #define GET_INSTRINFO_ENUM |
181 | | #include "ARMGenInstrInfo.inc" |
182 | | |
183 | | static void printCustomAliasOperand(MCInst *MI, |
184 | | unsigned OpIdx, unsigned PrintMethodIdx, SStream *OS); |
185 | | |
186 | | #define PRINT_ALIAS_INSTR |
187 | | #include "ARMGenAsmWriter.inc" |
188 | | #include "ARMGenRegisterName.inc" |
189 | | #include "ARMGenRegisterName_digit.inc" |
190 | | |
191 | | void ARM_getRegName(cs_struct *handle, int value) |
192 | 8.45k | { |
193 | 8.45k | if (value == CS_OPT_SYNTAX_NOREGNAME) { |
194 | 0 | handle->get_regname = getRegisterName_digit; |
195 | 0 | handle->reg_name = ARM_reg_name2; |
196 | 8.45k | } else { |
197 | 8.45k | handle->get_regname = getRegisterName; |
198 | 8.45k | handle->reg_name = ARM_reg_name; |
199 | 8.45k | } |
200 | 8.45k | } |
201 | | |
202 | | /// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing. |
203 | | /// |
204 | | /// getSORegOffset returns an integer from 0-31, representing '32' as 0. |
205 | | static unsigned translateShiftImm(unsigned imm) |
206 | 67.2k | { |
207 | | // lsr #32 and asr #32 exist, but should be encoded as a 0. |
208 | | //assert((imm & ~0x1f) == 0 && "Invalid shift encoding"); |
209 | 67.2k | if (imm == 0) |
210 | 3.15k | return 32; |
211 | 64.1k | return imm; |
212 | 67.2k | } |
213 | | |
214 | | /// Prints the shift value with an immediate value. |
215 | | static void printRegImmShift(MCInst *MI, SStream *O, ARM_AM_ShiftOpc ShOpc, unsigned ShImm) |
216 | 35.8k | { |
217 | 35.8k | if (ShOpc == ARM_AM_no_shift || (ShOpc == ARM_AM_lsl && !ShImm)) |
218 | 745 | return; |
219 | | |
220 | 35.0k | SStream_concat0(O, ", "); |
221 | | |
222 | | //assert (!(ShOpc == ARM_AM_ror && !ShImm) && "Cannot have ror #0"); |
223 | 35.0k | SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc)); |
224 | | |
225 | 35.0k | if (MI->csh->detail) { |
226 | 35.0k | if (MI->csh->doing_mem) |
227 | 4.99k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = (arm_shifter)ShOpc; |
228 | 30.1k | else |
229 | 30.1k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = (arm_shifter)ShOpc; |
230 | 35.0k | } |
231 | | |
232 | 35.0k | if (ShOpc != ARM_AM_rrx) { |
233 | 33.4k | SStream_concat0(O, " "); |
234 | 33.4k | SStream_concat(O, "#%u", translateShiftImm(ShImm)); |
235 | 33.4k | if (MI->csh->detail) { |
236 | 33.4k | if (MI->csh->doing_mem) |
237 | 4.91k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = translateShiftImm(ShImm); |
238 | 28.4k | else |
239 | 28.4k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = translateShiftImm(ShImm); |
240 | 33.4k | } |
241 | 33.4k | } |
242 | 35.0k | } |
243 | | |
244 | | static void printRegName(cs_struct *h, SStream *OS, unsigned RegNo) |
245 | 5.63M | { |
246 | 5.63M | #ifndef CAPSTONE_DIET |
247 | 5.63M | SStream_concat0(OS, h->get_regname(RegNo)); |
248 | 5.63M | #endif |
249 | 5.63M | } |
250 | | |
251 | | // TODO |
252 | | static const name_map insn_update_flgs[] = { |
253 | | { ARM_INS_CMN, "cmn" }, |
254 | | { ARM_INS_CMP, "cmp" }, |
255 | | { ARM_INS_TEQ, "teq" }, |
256 | | { ARM_INS_TST, "tst" }, |
257 | | |
258 | | { ARM_INS_ADC, "adcs" }, |
259 | | { ARM_INS_ADD, "adds" }, |
260 | | { ARM_INS_AND, "ands" }, |
261 | | { ARM_INS_ASR, "asrs" }, |
262 | | { ARM_INS_BIC, "bics" }, |
263 | | { ARM_INS_EOR, "eors" }, |
264 | | { ARM_INS_LSL, "lsls" }, |
265 | | { ARM_INS_LSR, "lsrs" }, |
266 | | { ARM_INS_MLA, "mlas" }, |
267 | | { ARM_INS_MOV, "movs" }, |
268 | | { ARM_INS_MUL, "muls" }, |
269 | | { ARM_INS_MVN, "mvns" }, |
270 | | { ARM_INS_ORN, "orns" }, |
271 | | { ARM_INS_ORR, "orrs" }, |
272 | | { ARM_INS_ROR, "rors" }, |
273 | | { ARM_INS_RRX, "rrxs" }, |
274 | | { ARM_INS_RSB, "rsbs" }, |
275 | | { ARM_INS_RSC, "rscs" }, |
276 | | { ARM_INS_SBC, "sbcs" }, |
277 | | { ARM_INS_SMLAL, "smlals" }, |
278 | | { ARM_INS_SMULL, "smulls" }, |
279 | | { ARM_INS_SUB, "subs" }, |
280 | | { ARM_INS_UMLAL, "umlals" }, |
281 | | { ARM_INS_UMULL, "umulls" }, |
282 | | |
283 | | { ARM_INS_UADD8, "uadd8" }, |
284 | | }; |
285 | | |
286 | | void ARM_post_printer(csh ud, cs_insn *insn, char *insn_asm, MCInst *mci) |
287 | 1.37M | { |
288 | 1.37M | if (((cs_struct *)ud)->detail != CS_OPT_ON) |
289 | 0 | return; |
290 | | |
291 | | // check if this insn requests write-back |
292 | 1.37M | if (mci->writeback || (strrchr(insn_asm, '!')) != NULL) { |
293 | 86.3k | insn->detail->arm.writeback = true; |
294 | 1.29M | } else if (mci->csh->mode & CS_MODE_THUMB) { |
295 | | // handle some special instructions with writeback |
296 | | //printf(">> Opcode = %u\n", mci->Opcode); |
297 | 1.11M | switch(mci->Opcode) { |
298 | 1.10M | default: |
299 | 1.10M | break; |
300 | 1.10M | case ARM_t2LDC2L_PRE: |
301 | 0 | case ARM_t2LDC2_PRE: |
302 | 0 | case ARM_t2LDCL_PRE: |
303 | 0 | case ARM_t2LDC_PRE: |
304 | |
|
305 | 0 | case ARM_t2LDRB_PRE: |
306 | 0 | case ARM_t2LDRD_PRE: |
307 | 0 | case ARM_t2LDRH_PRE: |
308 | 0 | case ARM_t2LDRSB_PRE: |
309 | 0 | case ARM_t2LDRSH_PRE: |
310 | 0 | case ARM_t2LDR_PRE: |
311 | |
|
312 | 0 | case ARM_t2STC2L_PRE: |
313 | 0 | case ARM_t2STC2_PRE: |
314 | 0 | case ARM_t2STCL_PRE: |
315 | 0 | case ARM_t2STC_PRE: |
316 | |
|
317 | 0 | case ARM_t2STRB_PRE: |
318 | 0 | case ARM_t2STRD_PRE: |
319 | 0 | case ARM_t2STRH_PRE: |
320 | 0 | case ARM_t2STR_PRE: |
321 | 0 | insn->detail->arm.writeback = true; |
322 | 0 | break; |
323 | 1.46k | case ARM_t2LDC2L_POST: |
324 | 1.80k | case ARM_t2LDC2_POST: |
325 | 3.19k | case ARM_t2LDCL_POST: |
326 | 3.35k | case ARM_t2LDC_POST: |
327 | | |
328 | 3.46k | case ARM_t2LDRB_POST: |
329 | 4.39k | case ARM_t2LDRD_POST: |
330 | 4.48k | case ARM_t2LDRH_POST: |
331 | 4.60k | case ARM_t2LDRSB_POST: |
332 | 5.04k | case ARM_t2LDRSH_POST: |
333 | 5.07k | case ARM_t2LDR_POST: |
334 | | |
335 | 6.37k | case ARM_t2STC2L_POST: |
336 | 7.27k | case ARM_t2STC2_POST: |
337 | 8.00k | case ARM_t2STCL_POST: |
338 | 8.14k | case ARM_t2STC_POST: |
339 | | |
340 | 8.37k | case ARM_t2STRB_POST: |
341 | 10.4k | case ARM_t2STRD_POST: |
342 | 10.6k | case ARM_t2STRH_POST: |
343 | 10.7k | case ARM_t2STR_POST: |
344 | 10.7k | insn->detail->arm.writeback = true; |
345 | 10.7k | insn->detail->arm.post_index = true; |
346 | 10.7k | break; |
347 | 1.11M | } |
348 | 1.11M | } else { // ARM mode |
349 | | // handle some special instructions with writeback |
350 | | //printf(">> Opcode = %u\n", mci->Opcode); |
351 | 180k | switch(mci->Opcode) { |
352 | 167k | default: |
353 | 167k | break; |
354 | 167k | case ARM_LDC2L_PRE: |
355 | 0 | case ARM_LDC2_PRE: |
356 | 0 | case ARM_LDCL_PRE: |
357 | 0 | case ARM_LDC_PRE: |
358 | |
|
359 | 0 | case ARM_LDRD_PRE: |
360 | 0 | case ARM_LDRH_PRE: |
361 | 0 | case ARM_LDRSB_PRE: |
362 | 0 | case ARM_LDRSH_PRE: |
363 | |
|
364 | 0 | case ARM_STC2L_PRE: |
365 | 0 | case ARM_STC2_PRE: |
366 | 0 | case ARM_STCL_PRE: |
367 | 0 | case ARM_STC_PRE: |
368 | |
|
369 | 0 | case ARM_STRD_PRE: |
370 | 0 | case ARM_STRH_PRE: |
371 | 0 | insn->detail->arm.writeback = true; |
372 | 0 | break; |
373 | 745 | case ARM_LDC2L_POST: |
374 | 805 | case ARM_LDC2_POST: |
375 | 2.20k | case ARM_LDCL_POST: |
376 | 3.09k | case ARM_LDC_POST: |
377 | | |
378 | 3.09k | case ARM_LDRBT_POST: |
379 | 3.09k | case ARM_LDRD_POST: |
380 | 3.09k | case ARM_LDRH_POST: |
381 | 3.09k | case ARM_LDRSB_POST: |
382 | 3.09k | case ARM_LDRSH_POST: |
383 | | |
384 | 3.23k | case ARM_STC2L_POST: |
385 | 3.53k | case ARM_STC2_POST: |
386 | 4.39k | case ARM_STCL_POST: |
387 | 5.11k | case ARM_STC_POST: |
388 | | |
389 | 5.11k | case ARM_STRBT_POST: |
390 | 5.11k | case ARM_STRD_POST: |
391 | 5.11k | case ARM_STRH_POST: |
392 | | |
393 | 6.07k | case ARM_LDRB_POST_IMM: |
394 | 7.35k | case ARM_LDR_POST_IMM: |
395 | 7.51k | case ARM_LDR_POST_REG: |
396 | 9.10k | case ARM_STRB_POST_IMM: |
397 | | |
398 | 11.4k | case ARM_STR_POST_IMM: |
399 | 12.4k | case ARM_STR_POST_REG: |
400 | 12.4k | insn->detail->arm.writeback = true; |
401 | 12.4k | insn->detail->arm.post_index = true; |
402 | 12.4k | break; |
403 | 180k | } |
404 | 180k | } |
405 | | |
406 | | // check if this insn requests update flags |
407 | 1.37M | if (insn->detail->arm.update_flags == false) { |
408 | | // some insn still update flags, regardless of tabgen info |
409 | 873k | unsigned int i, j; |
410 | | |
411 | 26.1M | for (i = 0; i < ARR_SIZE(insn_update_flgs); i++) { |
412 | 25.3M | if (insn->id == insn_update_flgs[i].id && |
413 | 25.3M | !strncmp(insn_asm, insn_update_flgs[i].name, |
414 | 87.9k | strlen(insn_update_flgs[i].name))) { |
415 | 21 | insn->detail->arm.update_flags = true; |
416 | | // we have to update regs_write array as well |
417 | 21 | for (j = 0; j < ARR_SIZE(insn->detail->regs_write); j++) { |
418 | 21 | if (insn->detail->regs_write[j] == 0) { |
419 | 21 | insn->detail->regs_write[j] = ARM_REG_CPSR; |
420 | 21 | break; |
421 | 21 | } |
422 | 21 | } |
423 | 21 | break; |
424 | 21 | } |
425 | 25.3M | } |
426 | 873k | } |
427 | | |
428 | | // instruction should not have invalid CC |
429 | 1.37M | if (insn->detail->arm.cc == ARM_CC_INVALID) { |
430 | 187k | insn->detail->arm.cc = ARM_CC_AL; |
431 | 187k | } |
432 | | |
433 | | // manual fix for some special instructions |
434 | | // printf(">>> id: %u, mcid: %u\n", insn->id, mci->Opcode); |
435 | 1.37M | switch(mci->Opcode) { |
436 | 1.37M | default: |
437 | 1.37M | break; |
438 | 1.37M | case ARM_MOVPCLR: |
439 | 69 | insn->detail->arm.operands[0].type = ARM_OP_REG; |
440 | 69 | insn->detail->arm.operands[0].reg = ARM_REG_PC; |
441 | 69 | insn->detail->arm.operands[0].access = CS_AC_WRITE; |
442 | 69 | insn->detail->arm.operands[1].type = ARM_OP_REG; |
443 | 69 | insn->detail->arm.operands[1].reg = ARM_REG_LR; |
444 | 69 | insn->detail->arm.operands[1].access = CS_AC_READ; |
445 | 69 | insn->detail->arm.op_count = 2; |
446 | 69 | break; |
447 | 1.37M | } |
448 | 1.37M | } |
449 | | |
450 | | void ARM_printInst(MCInst *MI, SStream *O, void *Info) |
451 | 1.37M | { |
452 | 1.37M | MCRegisterInfo *MRI = (MCRegisterInfo *)Info; |
453 | 1.37M | unsigned Opcode = MCInst_getOpcode(MI), tmp, i; |
454 | | |
455 | | //printf(">>> Opcode = %u\n", Opcode); |
456 | 1.37M | switch (Opcode) { |
457 | | // Check for MOVs and print canonical forms, instead. |
458 | 408 | case ARM_MOVsr: { |
459 | | // FIXME: Thumb variants? |
460 | 408 | unsigned int opc; |
461 | 408 | MCOperand *Dst = MCInst_getOperand(MI, 0); |
462 | 408 | MCOperand *MO1 = MCInst_getOperand(MI, 1); |
463 | 408 | MCOperand *MO2 = MCInst_getOperand(MI, 2); |
464 | 408 | MCOperand *MO3 = MCInst_getOperand(MI, 3); |
465 | | |
466 | 408 | opc = ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO3)); |
467 | 408 | SStream_concat0(O, ARM_AM_getShiftOpcStr(opc)); |
468 | | |
469 | 408 | switch (opc) { |
470 | 0 | default: break; |
471 | 56 | case ARM_AM_asr: |
472 | 56 | MCInst_setOpcodePub(MI, ARM_INS_ASR); |
473 | 56 | break; |
474 | 20 | case ARM_AM_lsl: |
475 | 20 | MCInst_setOpcodePub(MI, ARM_INS_LSL); |
476 | 20 | break; |
477 | 295 | case ARM_AM_lsr: |
478 | 295 | MCInst_setOpcodePub(MI, ARM_INS_LSR); |
479 | 295 | break; |
480 | 37 | case ARM_AM_ror: |
481 | 37 | MCInst_setOpcodePub(MI, ARM_INS_ROR); |
482 | 37 | break; |
483 | 0 | case ARM_AM_rrx: |
484 | 0 | MCInst_setOpcodePub(MI, ARM_INS_RRX); |
485 | 0 | break; |
486 | 408 | } |
487 | | |
488 | 408 | printSBitModifierOperand(MI, 6, O); |
489 | 408 | printPredicateOperand(MI, 4, O); |
490 | | |
491 | 408 | SStream_concat0(O, "\t"); |
492 | 408 | printRegName(MI->csh, O, MCOperand_getReg(Dst)); |
493 | | |
494 | 408 | if (MI->csh->detail) { |
495 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
496 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(Dst); |
497 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_WRITE; |
498 | 408 | MI->flat_insn->detail->arm.op_count++; |
499 | 408 | } |
500 | | |
501 | 408 | SStream_concat0(O, ", "); |
502 | 408 | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
503 | | |
504 | 408 | if (MI->csh->detail) { |
505 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
506 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
507 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
508 | 408 | MI->flat_insn->detail->arm.op_count++; |
509 | 408 | } |
510 | | |
511 | 408 | SStream_concat0(O, ", "); |
512 | 408 | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
513 | | |
514 | 408 | if (MI->csh->detail) { |
515 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
516 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO2); |
517 | 408 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
518 | 408 | MI->flat_insn->detail->arm.op_count++; |
519 | 408 | } |
520 | | |
521 | 408 | return; |
522 | 408 | } |
523 | | |
524 | 908 | case ARM_MOVsi: { |
525 | | // FIXME: Thumb variants? |
526 | 908 | unsigned int opc; |
527 | 908 | MCOperand *Dst = MCInst_getOperand(MI, 0); |
528 | 908 | MCOperand *MO1 = MCInst_getOperand(MI, 1); |
529 | 908 | MCOperand *MO2 = MCInst_getOperand(MI, 2); |
530 | | |
531 | 908 | opc = ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2)); |
532 | 908 | SStream_concat0(O, ARM_AM_getShiftOpcStr(opc)); |
533 | | |
534 | 908 | switch(opc) { |
535 | 0 | default: |
536 | 0 | break; |
537 | 70 | case ARM_AM_asr: |
538 | 70 | MCInst_setOpcodePub(MI, ARM_INS_ASR); |
539 | 70 | break; |
540 | 150 | case ARM_AM_lsl: |
541 | 150 | MCInst_setOpcodePub(MI, ARM_INS_LSL); |
542 | 150 | break; |
543 | 59 | case ARM_AM_lsr: |
544 | 59 | MCInst_setOpcodePub(MI, ARM_INS_LSR); |
545 | 59 | break; |
546 | 195 | case ARM_AM_ror: |
547 | 195 | MCInst_setOpcodePub(MI, ARM_INS_ROR); |
548 | 195 | break; |
549 | 434 | case ARM_AM_rrx: |
550 | 434 | MCInst_setOpcodePub(MI, ARM_INS_RRX); |
551 | 434 | break; |
552 | 908 | } |
553 | | |
554 | 908 | printSBitModifierOperand(MI, 5, O); |
555 | 908 | printPredicateOperand(MI, 3, O); |
556 | | |
557 | 908 | SStream_concat0(O, "\t"); |
558 | 908 | printRegName(MI->csh, O, MCOperand_getReg(Dst)); |
559 | | |
560 | 908 | if (MI->csh->detail) { |
561 | 908 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
562 | 908 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(Dst); |
563 | 908 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_WRITE; |
564 | 908 | MI->flat_insn->detail->arm.op_count++; |
565 | 908 | } |
566 | | |
567 | 908 | SStream_concat0(O, ", "); |
568 | 908 | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
569 | 908 | if (MI->csh->detail) { |
570 | 908 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
571 | 908 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
572 | 908 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
573 | 908 | MI->flat_insn->detail->arm.op_count++; |
574 | 908 | } |
575 | | |
576 | 908 | if (opc == ARM_AM_rrx) { |
577 | | //printAnnotation(O, Annot); |
578 | 434 | return; |
579 | 434 | } |
580 | | |
581 | 474 | SStream_concat0(O, ", "); |
582 | 474 | tmp = translateShiftImm(getSORegOffset((unsigned int)MCOperand_getImm(MO2))); |
583 | 474 | printUInt32Bang(O, tmp); |
584 | 474 | if (MI->csh->detail) { |
585 | 474 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = |
586 | 474 | (arm_shifter)opc; |
587 | 474 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = tmp; |
588 | 474 | } |
589 | | |
590 | 474 | return; |
591 | 908 | } |
592 | | |
593 | | // A8.6.123 PUSH |
594 | 317 | case ARM_STMDB_UPD: |
595 | 430 | case ARM_t2STMDB_UPD: |
596 | 430 | if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP && |
597 | 430 | MCInst_getNumOperands(MI) > 5) { |
598 | | // Should only print PUSH if there are at least two registers in the list. |
599 | 111 | SStream_concat0(O, "push"); |
600 | 111 | MCInst_setOpcodePub(MI, ARM_INS_PUSH); |
601 | 111 | printPredicateOperand(MI, 2, O); |
602 | | |
603 | 111 | if (Opcode == ARM_t2STMDB_UPD) |
604 | 28 | SStream_concat0(O, ".w"); |
605 | | |
606 | 111 | SStream_concat0(O, "\t"); |
607 | | |
608 | 111 | if (MI->csh->detail) { |
609 | 111 | MI->flat_insn->detail->regs_read[MI->flat_insn->detail->regs_read_count] = ARM_REG_SP; |
610 | 111 | MI->flat_insn->detail->regs_read_count++; |
611 | 111 | MI->flat_insn->detail->regs_write[MI->flat_insn->detail->regs_write_count] = ARM_REG_SP; |
612 | 111 | MI->flat_insn->detail->regs_write_count++; |
613 | 111 | } |
614 | | |
615 | 111 | printRegisterList(MI, 4, O); |
616 | 111 | return; |
617 | 111 | } else |
618 | 319 | break; |
619 | | |
620 | 1.08k | case ARM_STR_PRE_IMM: |
621 | 1.08k | if (MCOperand_getReg(MCInst_getOperand(MI, 2)) == ARM_SP && |
622 | 1.08k | MCOperand_getImm(MCInst_getOperand(MI, 3)) == -4) { |
623 | 0 | SStream_concat0(O, "push"); |
624 | 0 | MCInst_setOpcodePub(MI, ARM_INS_PUSH); |
625 | |
|
626 | 0 | printPredicateOperand(MI, 4, O); |
627 | |
|
628 | 0 | SStream_concat0(O, "\t{"); |
629 | |
|
630 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, 1))); |
631 | |
|
632 | 0 | if (MI->csh->detail) { |
633 | 0 | #ifndef CAPSTONE_DIET |
634 | 0 | uint8_t access; |
635 | 0 | #endif |
636 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
637 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 1)); |
638 | 0 | #ifndef CAPSTONE_DIET |
639 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
640 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
641 | 0 | MI->ac_idx++; |
642 | 0 | #endif |
643 | 0 | MI->flat_insn->detail->arm.op_count++; |
644 | 0 | } |
645 | |
|
646 | 0 | SStream_concat0(O, "}"); |
647 | |
|
648 | 0 | return; |
649 | 0 | } else |
650 | 1.08k | break; |
651 | | |
652 | | // A8.6.122 POP |
653 | 447 | case ARM_LDMIA_UPD: |
654 | 872 | case ARM_t2LDMIA_UPD: |
655 | 872 | if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP && |
656 | 872 | MCInst_getNumOperands(MI) > 5) { |
657 | | // Should only print POP if there are at least two registers in the list. |
658 | 156 | SStream_concat0(O, "pop"); |
659 | 156 | MCInst_setOpcodePub(MI, ARM_INS_POP); |
660 | | |
661 | 156 | printPredicateOperand(MI, 2, O); |
662 | 156 | if (Opcode == ARM_t2LDMIA_UPD) |
663 | 136 | SStream_concat0(O, ".w"); |
664 | | |
665 | 156 | SStream_concat0(O, "\t"); |
666 | | |
667 | | // unlike LDM, POP only write to registers, so skip the 1st access code |
668 | 156 | MI->ac_idx = 1; |
669 | 156 | if (MI->csh->detail) { |
670 | 156 | MI->flat_insn->detail->regs_read[MI->flat_insn->detail->regs_read_count] = ARM_REG_SP; |
671 | 156 | MI->flat_insn->detail->regs_read_count++; |
672 | 156 | MI->flat_insn->detail->regs_write[MI->flat_insn->detail->regs_write_count] = ARM_REG_SP; |
673 | 156 | MI->flat_insn->detail->regs_write_count++; |
674 | 156 | } |
675 | | |
676 | 156 | printRegisterList(MI, 4, O); |
677 | | |
678 | 156 | return; |
679 | 156 | } |
680 | 716 | break; |
681 | | |
682 | 1.27k | case ARM_LDR_POST_IMM: |
683 | 1.27k | if (MCOperand_getReg(MCInst_getOperand(MI, 2)) == ARM_SP) { |
684 | 243 | MCOperand *MO2 = MCInst_getOperand(MI, 4); |
685 | | |
686 | 243 | if (getAM2Offset((unsigned int)MCOperand_getImm(MO2)) == 4) { |
687 | 128 | SStream_concat0(O, "pop"); |
688 | 128 | MCInst_setOpcodePub(MI, ARM_INS_POP); |
689 | 128 | printPredicateOperand(MI, 5, O); |
690 | 128 | SStream_concat0(O, "\t{"); |
691 | | |
692 | 128 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, 0))); |
693 | | |
694 | 128 | if (MI->csh->detail) { |
695 | 128 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
696 | 128 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0)); |
697 | 128 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_WRITE; |
698 | 128 | MI->flat_insn->detail->arm.op_count++; |
699 | | // this instruction implicitly read/write SP register |
700 | 128 | MI->flat_insn->detail->regs_read[MI->flat_insn->detail->regs_read_count] = ARM_REG_SP; |
701 | 128 | MI->flat_insn->detail->regs_read_count++; |
702 | 128 | MI->flat_insn->detail->regs_write[MI->flat_insn->detail->regs_write_count] = ARM_REG_SP; |
703 | 128 | MI->flat_insn->detail->regs_write_count++; |
704 | 128 | } |
705 | 128 | SStream_concat0(O, "}"); |
706 | 128 | return; |
707 | 128 | } |
708 | 243 | } |
709 | 1.14k | break; |
710 | | |
711 | | // A8.6.355 VPUSH |
712 | 1.14k | case ARM_VSTMSDB_UPD: |
713 | 918 | case ARM_VSTMDDB_UPD: |
714 | 918 | if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP) { |
715 | 769 | SStream_concat0(O, "vpush"); |
716 | 769 | MCInst_setOpcodePub(MI, ARM_INS_VPUSH); |
717 | 769 | printPredicateOperand(MI, 2, O); |
718 | 769 | SStream_concat0(O, "\t"); |
719 | 769 | printRegisterList(MI, 4, O); |
720 | 769 | return; |
721 | 769 | } |
722 | 149 | break; |
723 | | |
724 | | // A8.6.354 VPOP |
725 | 149 | case ARM_VLDMSIA_UPD: |
726 | 308 | case ARM_VLDMDIA_UPD: |
727 | 308 | if (MCOperand_getReg(MCInst_getOperand(MI, 0)) == ARM_SP) { |
728 | 195 | SStream_concat0(O, "vpop"); |
729 | 195 | MCInst_setOpcodePub(MI, ARM_INS_VPOP); |
730 | 195 | printPredicateOperand(MI, 2, O); |
731 | 195 | SStream_concat0(O, "\t"); |
732 | 195 | printRegisterList(MI, 4, O); |
733 | 195 | return; |
734 | 195 | } |
735 | 113 | break; |
736 | | |
737 | 11.9k | case ARM_tLDMIA: { |
738 | 11.9k | bool Writeback = true; |
739 | 11.9k | unsigned BaseReg = MCOperand_getReg(MCInst_getOperand(MI, 0)); |
740 | 11.9k | unsigned i; |
741 | | |
742 | 61.2k | for (i = 3; i < MCInst_getNumOperands(MI); ++i) { |
743 | 49.3k | if (MCOperand_getReg(MCInst_getOperand(MI, i)) == BaseReg) |
744 | 5.13k | Writeback = false; |
745 | 49.3k | } |
746 | | |
747 | 11.9k | SStream_concat0(O, "ldm"); |
748 | 11.9k | MCInst_setOpcodePub(MI, ARM_INS_LDM); |
749 | | |
750 | 11.9k | printPredicateOperand(MI, 1, O); |
751 | 11.9k | SStream_concat0(O, "\t"); |
752 | 11.9k | printRegName(MI->csh, O, BaseReg); |
753 | 11.9k | if (MI->csh->detail) { |
754 | 11.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
755 | 11.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = BaseReg; |
756 | 11.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ | CS_AC_WRITE; |
757 | 11.9k | MI->flat_insn->detail->arm.op_count++; |
758 | 11.9k | } |
759 | | |
760 | 11.9k | if (Writeback) { |
761 | 6.80k | MI->writeback = true; |
762 | 6.80k | SStream_concat0(O, "!"); |
763 | 6.80k | } |
764 | | |
765 | 11.9k | SStream_concat0(O, ", "); |
766 | 11.9k | printRegisterList(MI, 3, O); |
767 | 11.9k | return; |
768 | 308 | } |
769 | | |
770 | | // Combine 2 GPRs from disassember into a GPRPair to match with instr def. |
771 | | // ldrexd/strexd require even/odd GPR pair. To enforce this constraint, |
772 | | // a single GPRPair reg operand is used in the .td file to replace the two |
773 | | // GPRs. However, when decoding them, the two GRPs cannot be automatically |
774 | | // expressed as a GPRPair, so we have to manually merge them. |
775 | | // FIXME: We would really like to be able to tablegen'erate this. |
776 | 60 | case ARM_LDREXD: |
777 | 537 | case ARM_STREXD: |
778 | 571 | case ARM_LDAEXD: |
779 | 674 | case ARM_STLEXD: { |
780 | 674 | const MCRegisterClass *MRC = MCRegisterInfo_getRegClass(MRI, ARM_GPRRegClassID); |
781 | 674 | bool isStore = Opcode == ARM_STREXD || Opcode == ARM_STLEXD; |
782 | 674 | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, isStore ? 1 : 0)); |
783 | | |
784 | 674 | if (MCRegisterClass_contains(MRC, Reg)) { |
785 | 0 | MCInst NewMI; |
786 | |
|
787 | 0 | MCInst_Init(&NewMI); |
788 | 0 | MCInst_setOpcode(&NewMI, Opcode); |
789 | |
|
790 | 0 | if (isStore) |
791 | 0 | MCInst_addOperand2(&NewMI, MCInst_getOperand(MI, 0)); |
792 | |
|
793 | 0 | MCOperand_CreateReg0(&NewMI, MCRegisterInfo_getMatchingSuperReg(MRI, Reg, ARM_gsub_0, |
794 | 0 | MCRegisterInfo_getRegClass(MRI, ARM_GPRPairRegClassID))); |
795 | | |
796 | | // Copy the rest operands into NewMI. |
797 | 0 | for(i = isStore ? 3 : 2; i < MCInst_getNumOperands(MI); ++i) |
798 | 0 | MCInst_addOperand2(&NewMI, MCInst_getOperand(MI, i)); |
799 | |
|
800 | 0 | printInstruction(&NewMI, O); |
801 | 0 | return; |
802 | 0 | } |
803 | 674 | break; |
804 | 674 | } |
805 | | |
806 | 674 | case ARM_TSB: |
807 | 103 | case ARM_t2TSB: |
808 | 103 | SStream_concat0(O, "tsb\tcsync"); |
809 | 103 | MCInst_setOpcodePub(MI, ARM_INS_TSB); |
810 | | // TODO: add csync to operands[]? |
811 | 103 | return; |
812 | 1.37M | } |
813 | | |
814 | 1.36M | MI->MRI = MRI; |
815 | | |
816 | 1.36M | if (!printAliasInstr(MI, O)) { |
817 | 1.35M | printInstruction(MI, O); |
818 | 1.35M | } |
819 | 1.36M | } |
820 | | |
821 | | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O) |
822 | 2.19M | { |
823 | 2.19M | int32_t imm; |
824 | 2.19M | MCOperand *Op = MCInst_getOperand(MI, OpNo); |
825 | | |
826 | 2.19M | if (MCOperand_isReg(Op)) { |
827 | 1.79M | unsigned Reg = MCOperand_getReg(Op); |
828 | | |
829 | 1.79M | printRegName(MI->csh, O, Reg); |
830 | | |
831 | 1.79M | if (MI->csh->detail) { |
832 | 1.79M | if (MI->csh->doing_mem) { |
833 | 0 | if (MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base == ARM_REG_INVALID) |
834 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = Reg; |
835 | 0 | else |
836 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = Reg; |
837 | 1.79M | } else { |
838 | 1.79M | #ifndef CAPSTONE_DIET |
839 | 1.79M | uint8_t access; |
840 | 1.79M | #endif |
841 | | |
842 | 1.79M | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
843 | 1.79M | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg; |
844 | 1.79M | #ifndef CAPSTONE_DIET |
845 | 1.79M | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
846 | 1.79M | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
847 | 1.79M | MI->ac_idx++; |
848 | 1.79M | #endif |
849 | 1.79M | MI->flat_insn->detail->arm.op_count++; |
850 | 1.79M | } |
851 | 1.79M | } |
852 | 1.79M | } else if (MCOperand_isImm(Op)) { |
853 | 402k | unsigned int opc = MCInst_getOpcode(MI); |
854 | | |
855 | 402k | imm = (int32_t)MCOperand_getImm(Op); |
856 | | |
857 | | // relative branch only has relative offset, so we have to update it |
858 | | // to reflect absolute address. |
859 | | // Note: in ARM, PC is always 2 instructions ahead, so we have to |
860 | | // add 8 in ARM mode, or 4 in Thumb mode |
861 | | // printf(">> opcode: %u\n", MCInst_getOpcode(MI)); |
862 | 402k | if (ARM_rel_branch(MI->csh, opc)) { |
863 | 85.1k | uint32_t address; |
864 | | |
865 | | // only do this for relative branch |
866 | 85.1k | if (MI->csh->mode & CS_MODE_THUMB) { |
867 | 69.6k | address = (uint32_t)MI->address + 4; |
868 | 69.6k | if (ARM_blx_to_arm_mode(MI->csh, opc)) { |
869 | | // here need to align down to the nearest 4-byte address |
870 | 324 | #define _ALIGN_DOWN(v, align_width) ((v/align_width)*align_width) |
871 | 324 | address = _ALIGN_DOWN(address, 4); |
872 | 324 | #undef _ALIGN_DOWN |
873 | 324 | } |
874 | 69.6k | } else { |
875 | 15.5k | address = (uint32_t)MI->address + 8; |
876 | 15.5k | } |
877 | | |
878 | 85.1k | imm += address; |
879 | 85.1k | printUInt32Bang(O, imm); |
880 | 317k | } else { |
881 | 317k | switch(MI->flat_insn->id) { |
882 | 314k | default: |
883 | 314k | if (MI->csh->imm_unsigned) |
884 | 0 | printUInt32Bang(O, imm); |
885 | 314k | else |
886 | 314k | printInt32Bang(O, imm); |
887 | 314k | break; |
888 | 1.20k | case ARM_INS_AND: |
889 | 1.65k | case ARM_INS_ORR: |
890 | 2.20k | case ARM_INS_EOR: |
891 | 2.62k | case ARM_INS_BIC: |
892 | 2.95k | case ARM_INS_MVN: |
893 | | // do not print number in negative form |
894 | 2.95k | printUInt32Bang(O, imm); |
895 | 2.95k | break; |
896 | 317k | } |
897 | 317k | } |
898 | | |
899 | 402k | if (MI->csh->detail) { |
900 | 402k | if (MI->csh->doing_mem) |
901 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = imm; |
902 | 402k | else { |
903 | 402k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
904 | 402k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = imm; |
905 | 402k | MI->flat_insn->detail->arm.op_count++; |
906 | 402k | } |
907 | 402k | } |
908 | 402k | } |
909 | 2.19M | } |
910 | | |
911 | | static void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O) |
912 | 31.9k | { |
913 | 31.9k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
914 | 31.9k | int32_t OffImm; |
915 | 31.9k | bool isSub; |
916 | 31.9k | SStream_concat0(O, "[pc, "); |
917 | | |
918 | 31.9k | OffImm = (int32_t)MCOperand_getImm(MO1); |
919 | 31.9k | isSub = OffImm < 0; |
920 | | |
921 | | // Special value for #-0. All others are normal. |
922 | 31.9k | if (OffImm == INT32_MIN) |
923 | 150 | OffImm = 0; |
924 | | |
925 | 31.9k | if (isSub) { |
926 | 5.97k | SStream_concat(O, "#-0x%x", -OffImm); |
927 | 25.9k | } else { |
928 | 25.9k | printUInt32Bang(O, OffImm); |
929 | 25.9k | } |
930 | | |
931 | 31.9k | SStream_concat0(O, "]"); |
932 | | |
933 | 31.9k | if (MI->csh->detail) { |
934 | 31.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM; |
935 | 31.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = ARM_REG_PC; |
936 | 31.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID; |
937 | 31.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1; |
938 | 31.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm; |
939 | 31.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
940 | 31.9k | MI->flat_insn->detail->arm.op_count++; |
941 | 31.9k | } |
942 | 31.9k | } |
943 | | |
944 | | // so_reg is a 4-operand unit corresponding to register forms of the A5.1 |
945 | | // "Addressing Mode 1 - Data-processing operands" forms. This includes: |
946 | | // REG 0 0 - e.g. R5 |
947 | | // REG REG 0,SH_OPC - e.g. R5, ROR R3 |
948 | | // REG 0 IMM,SH_OPC - e.g. R5, LSL #3 |
949 | | static void printSORegRegOperand(MCInst *MI, unsigned OpNum, SStream *O) |
950 | 10.3k | { |
951 | 10.3k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
952 | 10.3k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
953 | 10.3k | MCOperand *MO3 = MCInst_getOperand(MI, OpNum + 2); |
954 | 10.3k | ARM_AM_ShiftOpc ShOpc; |
955 | | |
956 | 10.3k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
957 | | |
958 | 10.3k | if (MI->csh->detail) { |
959 | 10.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
960 | 10.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
961 | 10.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
962 | | |
963 | 10.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = (MCOperand_getImm(MO3) & 7) + ARM_SFT_ASR_REG - 1; |
964 | 10.3k | MI->flat_insn->detail->arm.op_count++; |
965 | 10.3k | } |
966 | | |
967 | | // Print the shift opc. |
968 | 10.3k | ShOpc = ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO3)); |
969 | 10.3k | SStream_concat0(O, ", "); |
970 | 10.3k | SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc)); |
971 | 10.3k | if (ShOpc == ARM_AM_rrx) |
972 | 0 | return; |
973 | | |
974 | 10.3k | SStream_concat0(O, " "); |
975 | | |
976 | 10.3k | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
977 | | |
978 | 10.3k | if (MI->csh->detail) |
979 | 10.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = MCOperand_getReg(MO2); |
980 | 10.3k | } |
981 | | |
982 | | static void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
983 | 18.7k | { |
984 | 18.7k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
985 | 18.7k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
986 | | |
987 | 18.7k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
988 | | |
989 | 18.7k | if (MI->csh->detail) { |
990 | 18.7k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
991 | 18.7k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
992 | 18.7k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
993 | 18.7k | MI->flat_insn->detail->arm.op_count++; |
994 | 18.7k | } |
995 | | |
996 | | // Print the shift opc. |
997 | 18.7k | printRegImmShift(MI, O, ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2)), |
998 | 18.7k | getSORegOffset((unsigned int)MCOperand_getImm(MO2))); |
999 | 18.7k | } |
1000 | | |
1001 | | //===--------------------------------------------------------------------===// |
1002 | | // Addressing Mode #2 |
1003 | | //===--------------------------------------------------------------------===// |
1004 | | |
1005 | | static void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned Op, SStream *O) |
1006 | 5.26k | { |
1007 | 5.26k | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
1008 | 5.26k | MCOperand *MO2 = MCInst_getOperand(MI, Op + 1); |
1009 | 5.26k | MCOperand *MO3 = MCInst_getOperand(MI, Op + 2); |
1010 | 5.26k | unsigned int imm3 = (unsigned int)MCOperand_getImm(MO3); |
1011 | 5.26k | ARM_AM_AddrOpc subtracted = getAM2Op((unsigned int)MCOperand_getImm(MO3)); |
1012 | | |
1013 | 5.26k | SStream_concat0(O, "["); |
1014 | 5.26k | set_mem_access(MI, true); |
1015 | | |
1016 | 5.26k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1017 | 5.26k | if (MI->csh->detail) { |
1018 | 5.26k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1019 | 5.26k | } |
1020 | | |
1021 | 5.26k | if (!MCOperand_getReg(MO2)) { |
1022 | 0 | unsigned tmp = getAM2Offset(imm3); |
1023 | 0 | if (tmp) { // Don't print +0. |
1024 | 0 | subtracted = getAM2Op(imm3); |
1025 | |
|
1026 | 0 | SStream_concat0(O, ", "); |
1027 | 0 | if (tmp > HEX_THRESHOLD) |
1028 | 0 | SStream_concat(O, "#%s0x%x", ARM_AM_getAddrOpcStr(subtracted), tmp); |
1029 | 0 | else |
1030 | 0 | SStream_concat(O, "#%s%u", ARM_AM_getAddrOpcStr(subtracted), tmp); |
1031 | 0 | if (MI->csh->detail) { |
1032 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = (arm_shifter)getAM2Op(imm3); |
1033 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = tmp; |
1034 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = subtracted == ARM_AM_sub; |
1035 | 0 | } |
1036 | 0 | } |
1037 | |
|
1038 | 0 | SStream_concat0(O, "]"); |
1039 | 0 | set_mem_access(MI, false); |
1040 | |
|
1041 | 0 | return; |
1042 | 0 | } |
1043 | | |
1044 | 5.26k | SStream_concat0(O, ", "); |
1045 | 5.26k | SStream_concat0(O, ARM_AM_getAddrOpcStr(subtracted)); |
1046 | 5.26k | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
1047 | 5.26k | if (MI->csh->detail) { |
1048 | 5.26k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2); |
1049 | 5.26k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = subtracted == ARM_AM_sub; |
1050 | 5.26k | } |
1051 | | |
1052 | 5.26k | printRegImmShift(MI, O, getAM2ShiftOpc(imm3), getAM2Offset(imm3)); |
1053 | 5.26k | SStream_concat0(O, "]"); |
1054 | 5.26k | set_mem_access(MI, false); |
1055 | 5.26k | } |
1056 | | |
1057 | | static void printAddrModeTBB(MCInst *MI, unsigned Op, SStream *O) |
1058 | 63 | { |
1059 | 63 | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
1060 | 63 | MCOperand *MO2 = MCInst_getOperand(MI, Op + 1); |
1061 | | |
1062 | 63 | SStream_concat0(O, "["); |
1063 | 63 | set_mem_access(MI, true); |
1064 | | |
1065 | 63 | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1066 | | |
1067 | 63 | if (MI->csh->detail) |
1068 | 63 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1069 | | |
1070 | 63 | SStream_concat0(O, ", "); |
1071 | 63 | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
1072 | | |
1073 | 63 | if (MI->csh->detail) |
1074 | 63 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2); |
1075 | | |
1076 | 63 | SStream_concat0(O, "]"); |
1077 | 63 | set_mem_access(MI, false); |
1078 | 63 | } |
1079 | | |
1080 | | static void printAddrModeTBH(MCInst *MI, unsigned Op, SStream *O) |
1081 | 395 | { |
1082 | 395 | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
1083 | 395 | MCOperand *MO2 = MCInst_getOperand(MI, Op + 1); |
1084 | | |
1085 | 395 | SStream_concat0(O, "["); |
1086 | 395 | set_mem_access(MI, true); |
1087 | | |
1088 | 395 | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1089 | | |
1090 | 395 | if (MI->csh->detail) |
1091 | 395 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1092 | | |
1093 | 395 | SStream_concat0(O, ", "); |
1094 | 395 | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
1095 | | |
1096 | 395 | if (MI->csh->detail) |
1097 | 395 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2); |
1098 | | |
1099 | 395 | SStream_concat0(O, ", lsl #1]"); |
1100 | | |
1101 | 395 | if (MI->csh->detail) { |
1102 | 395 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = ARM_SFT_LSL; |
1103 | 395 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = 1; |
1104 | 395 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.lshift = 1; |
1105 | 395 | } |
1106 | | |
1107 | 395 | set_mem_access(MI, false); |
1108 | 395 | } |
1109 | | |
1110 | | static void printAddrMode2Operand(MCInst *MI, unsigned Op, SStream *O) |
1111 | 5.26k | { |
1112 | 5.26k | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
1113 | | |
1114 | 5.26k | if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right. |
1115 | 0 | printOperand(MI, Op, O); |
1116 | 0 | return; |
1117 | 0 | } |
1118 | | |
1119 | | //#ifndef NDEBUG |
1120 | | // const MCOperand &MO3 = MI->getOperand(Op + 2); |
1121 | | // unsigned IdxMode = ARM_AM::getAM2IdxMode(MO3.getImm()); |
1122 | | // assert(IdxMode != ARMII::IndexModePost && "Should be pre or offset index op"); |
1123 | | //#endif |
1124 | | |
1125 | 5.26k | printAM2PreOrOffsetIndexOp(MI, Op, O); |
1126 | 5.26k | } |
1127 | | |
1128 | | static void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1129 | 18.1k | { |
1130 | 18.1k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1131 | 18.1k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
1132 | 18.1k | ARM_AM_AddrOpc subtracted = getAM2Op((unsigned int)MCOperand_getImm(MO2)); |
1133 | | |
1134 | 18.1k | if (!MCOperand_getReg(MO1)) { |
1135 | 11.6k | unsigned ImmOffs = getAM2Offset((unsigned int)MCOperand_getImm(MO2)); |
1136 | 11.6k | if (ImmOffs > HEX_THRESHOLD) |
1137 | 11.0k | SStream_concat(O, "#%s0x%x", |
1138 | 11.0k | ARM_AM_getAddrOpcStr(subtracted), ImmOffs); |
1139 | 575 | else |
1140 | 575 | SStream_concat(O, "#%s%u", |
1141 | 575 | ARM_AM_getAddrOpcStr(subtracted), ImmOffs); |
1142 | | |
1143 | 11.6k | if (MI->csh->detail) { |
1144 | 11.6k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1145 | 11.6k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = ImmOffs; |
1146 | 11.6k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = subtracted == ARM_AM_sub; |
1147 | 11.6k | MI->flat_insn->detail->arm.op_count++; |
1148 | 11.6k | } |
1149 | 11.6k | return; |
1150 | 11.6k | } |
1151 | | |
1152 | 6.48k | SStream_concat0(O, ARM_AM_getAddrOpcStr(subtracted)); |
1153 | 6.48k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1154 | | |
1155 | 6.48k | if (MI->csh->detail) { |
1156 | 6.48k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1157 | 6.48k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
1158 | 6.48k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
1159 | 6.48k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = subtracted == ARM_AM_sub; |
1160 | 6.48k | MI->flat_insn->detail->arm.op_count++; |
1161 | 6.48k | } |
1162 | | |
1163 | 6.48k | printRegImmShift(MI, O, getAM2ShiftOpc((unsigned int)MCOperand_getImm(MO2)), |
1164 | 6.48k | getAM2Offset((unsigned int)MCOperand_getImm(MO2))); |
1165 | 6.48k | } |
1166 | | |
1167 | | //===--------------------------------------------------------------------===// |
1168 | | // Addressing Mode #3 |
1169 | | //===--------------------------------------------------------------------===// |
1170 | | |
1171 | | static void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op, SStream *O, |
1172 | | bool AlwaysPrintImm0) |
1173 | 5.86k | { |
1174 | 5.86k | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
1175 | 5.86k | MCOperand *MO2 = MCInst_getOperand(MI, Op+1); |
1176 | 5.86k | MCOperand *MO3 = MCInst_getOperand(MI, Op+2); |
1177 | 5.86k | ARM_AM_AddrOpc sign = getAM3Op((unsigned int)MCOperand_getImm(MO3)); |
1178 | 5.86k | unsigned ImmOffs; |
1179 | | |
1180 | 5.86k | SStream_concat0(O, "["); |
1181 | 5.86k | set_mem_access(MI, true); |
1182 | | |
1183 | 5.86k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1184 | | |
1185 | 5.86k | if (MI->csh->detail) |
1186 | 5.86k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1187 | | |
1188 | 5.86k | if (MCOperand_getReg(MO2)) { |
1189 | 3.28k | SStream_concat0(O, ", "); |
1190 | 3.28k | SStream_concat0(O, ARM_AM_getAddrOpcStr(sign)); |
1191 | | |
1192 | 3.28k | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
1193 | | |
1194 | 3.28k | if (MI->csh->detail) { |
1195 | 3.28k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2); |
1196 | 3.28k | if (sign == ARM_AM_sub) { |
1197 | 1.20k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = -1; |
1198 | 1.20k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = true; |
1199 | 1.20k | } |
1200 | 3.28k | } |
1201 | | |
1202 | 3.28k | SStream_concat0(O, "]"); |
1203 | 3.28k | set_mem_access(MI, false); |
1204 | | |
1205 | 3.28k | return; |
1206 | 3.28k | } |
1207 | | |
1208 | | // If the op is sub we have to print the immediate even if it is 0 |
1209 | 2.57k | ImmOffs = getAM3Offset((unsigned int)MCOperand_getImm(MO3)); |
1210 | | |
1211 | 2.57k | if (AlwaysPrintImm0 || ImmOffs || (sign == ARM_AM_sub)) { |
1212 | 2.49k | if (ImmOffs > HEX_THRESHOLD) |
1213 | 2.01k | SStream_concat(O, ", #%s0x%x", ARM_AM_getAddrOpcStr(sign), ImmOffs); |
1214 | 474 | else |
1215 | 474 | SStream_concat(O, ", #%s%u", ARM_AM_getAddrOpcStr(sign), ImmOffs); |
1216 | 2.49k | } |
1217 | | |
1218 | 2.57k | if (MI->csh->detail) { |
1219 | 2.57k | if (sign == ARM_AM_sub) { |
1220 | 774 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = -(int)ImmOffs; |
1221 | 774 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = true; |
1222 | 774 | } else |
1223 | 1.80k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = (int)ImmOffs; |
1224 | 2.57k | } |
1225 | | |
1226 | 2.57k | SStream_concat0(O, "]"); |
1227 | 2.57k | set_mem_access(MI, false); |
1228 | 2.57k | } |
1229 | | |
1230 | | static void printAddrMode3Operand(MCInst *MI, unsigned Op, SStream *O, |
1231 | | bool AlwaysPrintImm0) |
1232 | 5.86k | { |
1233 | 5.86k | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
1234 | | |
1235 | 5.86k | if (!MCOperand_isReg(MO1)) { // For label symbolic references. |
1236 | 0 | printOperand(MI, Op, O); |
1237 | 0 | return; |
1238 | 0 | } |
1239 | | |
1240 | 5.86k | printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); |
1241 | 5.86k | } |
1242 | | |
1243 | | static void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1244 | 4.63k | { |
1245 | 4.63k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1246 | 4.63k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
1247 | 4.63k | ARM_AM_AddrOpc subtracted = getAM3Op((unsigned int)MCOperand_getImm(MO2)); |
1248 | 4.63k | unsigned ImmOffs; |
1249 | | |
1250 | 4.63k | if (MCOperand_getReg(MO1)) { |
1251 | 2.71k | SStream_concat0(O, ARM_AM_getAddrOpcStr(subtracted)); |
1252 | 2.71k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1253 | | |
1254 | 2.71k | if (MI->csh->detail) { |
1255 | 2.71k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1256 | 2.71k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
1257 | 2.71k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
1258 | 2.71k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = subtracted == ARM_AM_sub; |
1259 | 2.71k | MI->flat_insn->detail->arm.op_count++; |
1260 | 2.71k | } |
1261 | | |
1262 | 2.71k | return; |
1263 | 2.71k | } |
1264 | | |
1265 | 1.92k | ImmOffs = getAM3Offset((unsigned int)MCOperand_getImm(MO2)); |
1266 | 1.92k | if (ImmOffs > HEX_THRESHOLD) |
1267 | 853 | SStream_concat(O, "#%s0x%x", ARM_AM_getAddrOpcStr(subtracted), ImmOffs); |
1268 | 1.07k | else |
1269 | 1.07k | SStream_concat(O, "#%s%u", ARM_AM_getAddrOpcStr(subtracted), ImmOffs); |
1270 | | |
1271 | 1.92k | if (MI->csh->detail) { |
1272 | 1.92k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1273 | 1.92k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = ImmOffs; |
1274 | 1.92k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].subtracted = subtracted == ARM_AM_sub; |
1275 | 1.92k | MI->flat_insn->detail->arm.op_count++; |
1276 | 1.92k | } |
1277 | 1.92k | } |
1278 | | |
1279 | | static void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum, SStream *O) |
1280 | 1.29k | { |
1281 | 1.29k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1282 | 1.29k | unsigned Imm = (unsigned int)MCOperand_getImm(MO); |
1283 | | |
1284 | 1.29k | if ((Imm & 0xff) > HEX_THRESHOLD) |
1285 | 1.12k | SStream_concat(O, "#%s0x%x", ((Imm & 256) ? "" : "-"), (Imm & 0xff)); |
1286 | 168 | else |
1287 | 168 | SStream_concat(O, "#%s%u", ((Imm & 256) ? "" : "-"), (Imm & 0xff)); |
1288 | | |
1289 | 1.29k | if (MI->csh->detail) { |
1290 | 1.29k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1291 | 1.29k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Imm & 0xff; |
1292 | 1.29k | MI->flat_insn->detail->arm.op_count++; |
1293 | 1.29k | } |
1294 | 1.29k | } |
1295 | | |
1296 | | static void printPostIdxRegOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1297 | 2.41k | { |
1298 | 2.41k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1299 | 2.41k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
1300 | | |
1301 | 2.41k | SStream_concat0(O, (MCOperand_getImm(MO2) ? "" : "-")); |
1302 | 2.41k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1303 | | |
1304 | 2.41k | if (MI->csh->detail) { |
1305 | 2.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1306 | 2.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO1); |
1307 | 2.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
1308 | 2.41k | MI->flat_insn->detail->arm.op_count++; |
1309 | 2.41k | } |
1310 | 2.41k | } |
1311 | | |
1312 | | static void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum, SStream *O) |
1313 | 11.5k | { |
1314 | 11.5k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1315 | 11.5k | int Imm = (int)MCOperand_getImm(MO); |
1316 | | |
1317 | 11.5k | if (((Imm & 0xff) << 2) > HEX_THRESHOLD) { |
1318 | 10.3k | SStream_concat(O, "#%s0x%x", ((Imm & 256) ? "" : "-"), ((Imm & 0xff) << 2)); |
1319 | 10.3k | } else { |
1320 | 1.20k | SStream_concat(O, "#%s%u", ((Imm & 256) ? "" : "-"), ((Imm & 0xff) << 2)); |
1321 | 1.20k | } |
1322 | | |
1323 | 11.5k | if (MI->csh->detail) { |
1324 | 11.5k | int v = (Imm & 256) ? ((Imm & 0xff) << 2) : -((Imm & 0xff) << 2); |
1325 | 11.5k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1326 | 11.5k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = v; |
1327 | 11.5k | MI->flat_insn->detail->arm.op_count++; |
1328 | 11.5k | } |
1329 | 11.5k | } |
1330 | | |
1331 | | static void printAddrMode5Operand(MCInst *MI, unsigned OpNum, SStream *O, |
1332 | | bool AlwaysPrintImm0) |
1333 | 25.8k | { |
1334 | 25.8k | unsigned ImmOffs; |
1335 | 25.8k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1336 | 25.8k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
1337 | 25.8k | ARM_AM_AddrOpc Op = ARM_AM_getAM5Op((unsigned int)MCOperand_getImm(MO2)); |
1338 | | |
1339 | 25.8k | if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right. |
1340 | 0 | printOperand(MI, OpNum, O); |
1341 | 0 | return; |
1342 | 0 | } |
1343 | | |
1344 | 25.8k | SStream_concat0(O, "["); |
1345 | 25.8k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1346 | | |
1347 | 25.8k | if (MI->csh->detail) { |
1348 | 25.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM; |
1349 | 25.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1350 | 25.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID; |
1351 | 25.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1; |
1352 | 25.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = 0; |
1353 | 25.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
1354 | 25.8k | } |
1355 | | |
1356 | 25.8k | ImmOffs = ARM_AM_getAM5Offset((unsigned int)MCOperand_getImm(MO2)); |
1357 | 25.8k | if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { |
1358 | 25.1k | if (ImmOffs * 4 > HEX_THRESHOLD) |
1359 | 23.0k | SStream_concat(O, ", #%s0x%x", |
1360 | 23.0k | ARM_AM_getAddrOpcStr(Op), |
1361 | 23.0k | ImmOffs * 4); |
1362 | 2.11k | else |
1363 | 2.11k | SStream_concat(O, ", #%s%u", |
1364 | 2.11k | ARM_AM_getAddrOpcStr(Op), |
1365 | 2.11k | ImmOffs * 4); |
1366 | | |
1367 | 25.1k | if (MI->csh->detail) { |
1368 | 25.1k | if (Op) |
1369 | 10.8k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = ImmOffs * 4; |
1370 | 14.3k | else |
1371 | 14.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = -(int)ImmOffs * 4; |
1372 | 25.1k | } |
1373 | 25.1k | } |
1374 | | |
1375 | 25.8k | SStream_concat0(O, "]"); |
1376 | | |
1377 | 25.8k | if (MI->csh->detail) { |
1378 | 25.8k | MI->flat_insn->detail->arm.op_count++; |
1379 | 25.8k | } |
1380 | 25.8k | } |
1381 | | |
1382 | | static void printAddrMode5FP16Operand(MCInst *MI, unsigned OpNum, SStream *O, |
1383 | | bool AlwaysPrintImm0) |
1384 | 317 | { |
1385 | 317 | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1386 | 317 | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
1387 | 317 | unsigned ImmOffs = getAM5FP16Offset((unsigned)MCOperand_getImm(MO2)); |
1388 | 317 | unsigned Op = getAM5FP16Op((unsigned)MCOperand_getImm(MO2)); |
1389 | | |
1390 | 317 | if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right. |
1391 | 0 | printOperand(MI, OpNum, O); |
1392 | 0 | return; |
1393 | 0 | } |
1394 | | |
1395 | 317 | SStream_concat0(O, "["); |
1396 | 317 | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1397 | | |
1398 | 317 | if (MI->csh->detail) { |
1399 | 317 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_MEM; |
1400 | 317 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1401 | 317 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = ARM_REG_INVALID; |
1402 | 317 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.scale = 1; |
1403 | 317 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = 0; |
1404 | 317 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
1405 | 317 | } |
1406 | | |
1407 | 317 | if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { |
1408 | 262 | if (ImmOffs * 2 > HEX_THRESHOLD) |
1409 | 198 | SStream_concat(O, ", #%s0x%x", ARM_AM_getAddrOpcStr(Op), ImmOffs * 2); |
1410 | 64 | else |
1411 | 64 | SStream_concat(O, ", #%s%u", ARM_AM_getAddrOpcStr(Op), ImmOffs * 2); |
1412 | | |
1413 | 262 | if (MI->csh->detail) { |
1414 | 262 | if (Op) |
1415 | 104 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = ImmOffs * 2; |
1416 | 158 | else |
1417 | 158 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = -(int)ImmOffs * 2; |
1418 | 262 | } |
1419 | 262 | } |
1420 | | |
1421 | 317 | SStream_concat0(O, "]"); |
1422 | | |
1423 | 317 | if (MI->csh->detail) { |
1424 | 317 | MI->flat_insn->detail->arm.op_count++; |
1425 | 317 | } |
1426 | 317 | } |
1427 | | |
1428 | | static void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O) |
1429 | 47.9k | { |
1430 | 47.9k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1431 | 47.9k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
1432 | 47.9k | unsigned tmp; |
1433 | | |
1434 | 47.9k | SStream_concat0(O, "["); |
1435 | 47.9k | set_mem_access(MI, true); |
1436 | | |
1437 | 47.9k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1438 | | |
1439 | 47.9k | if (MI->csh->detail) |
1440 | 47.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1441 | | |
1442 | 47.9k | tmp = (unsigned int)MCOperand_getImm(MO2); |
1443 | 47.9k | if (tmp) { |
1444 | 17.9k | if (tmp << 3 > HEX_THRESHOLD) |
1445 | 17.9k | SStream_concat(O, ":0x%x", (tmp << 3)); |
1446 | 0 | else |
1447 | 0 | SStream_concat(O, ":%u", (tmp << 3)); |
1448 | | |
1449 | 17.9k | if (MI->csh->detail) |
1450 | 17.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp << 3; |
1451 | 17.9k | } |
1452 | | |
1453 | 47.9k | SStream_concat0(O, "]"); |
1454 | 47.9k | set_mem_access(MI, false); |
1455 | 47.9k | } |
1456 | | |
1457 | | static void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O) |
1458 | 50.2k | { |
1459 | 50.2k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
1460 | | |
1461 | 50.2k | SStream_concat0(O, "["); |
1462 | 50.2k | set_mem_access(MI, true); |
1463 | | |
1464 | 50.2k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
1465 | | |
1466 | 50.2k | if (MI->csh->detail) |
1467 | 50.2k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
1468 | | |
1469 | 50.2k | SStream_concat0(O, "]"); |
1470 | 50.2k | set_mem_access(MI, false); |
1471 | 50.2k | } |
1472 | | |
1473 | | static void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1474 | 14.8k | { |
1475 | 14.8k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1476 | | |
1477 | 14.8k | if (MCOperand_getReg(MO) == 0) { |
1478 | 5.41k | MI->writeback = true; |
1479 | 5.41k | SStream_concat0(O, "!"); |
1480 | 9.41k | } else { |
1481 | 9.41k | SStream_concat0(O, ", "); |
1482 | 9.41k | printRegName(MI->csh, O, MCOperand_getReg(MO)); |
1483 | | |
1484 | 9.41k | if (MI->csh->detail) { |
1485 | 9.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1486 | 9.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MO); |
1487 | 9.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
1488 | 9.41k | MI->flat_insn->detail->arm.op_count++; |
1489 | 9.41k | } |
1490 | 9.41k | } |
1491 | 14.8k | } |
1492 | | |
1493 | | static void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1494 | 1.35k | { |
1495 | 1.35k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1496 | 1.35k | uint32_t v = ~(uint32_t)MCOperand_getImm(MO); |
1497 | 1.35k | int32_t lsb = CountTrailingZeros_32(v); |
1498 | 1.35k | int32_t width = (32 - CountLeadingZeros_32 (v)) - lsb; |
1499 | | |
1500 | | //assert(MO.isImm() && "Not a valid bf_inv_mask_imm value!"); |
1501 | 1.35k | printUInt32Bang(O, lsb); |
1502 | | |
1503 | 1.35k | if (width > HEX_THRESHOLD) |
1504 | 441 | SStream_concat(O, ", #0x%x", width); |
1505 | 912 | else |
1506 | 912 | SStream_concat(O, ", #%u", width); |
1507 | | |
1508 | 1.35k | if (MI->csh->detail) { |
1509 | 1.35k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1510 | 1.35k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = lsb; |
1511 | 1.35k | MI->flat_insn->detail->arm.op_count++; |
1512 | 1.35k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1513 | 1.35k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = width; |
1514 | 1.35k | MI->flat_insn->detail->arm.op_count++; |
1515 | 1.35k | } |
1516 | 1.35k | } |
1517 | | |
1518 | | static void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O) |
1519 | 1.39k | { |
1520 | 1.39k | unsigned val = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1521 | 1.39k | SStream_concat0(O, ARM_MB_MemBOptToString(val, |
1522 | 1.39k | ARM_getFeatureBits(MI->csh->mode, ARM_HasV8Ops))); |
1523 | | |
1524 | 1.39k | if (MI->csh->detail) { |
1525 | 1.39k | MI->flat_insn->detail->arm.mem_barrier = (arm_mem_barrier)(val + 1); |
1526 | 1.39k | } |
1527 | 1.39k | } |
1528 | | |
1529 | | static void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O) |
1530 | 725 | { |
1531 | 725 | unsigned val = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1532 | 725 | SStream_concat0(O, ARM_ISB_InstSyncBOptToString(val)); |
1533 | 725 | } |
1534 | | |
1535 | | static void printTraceSyncBOption(MCInst *MI, unsigned OpNum, SStream *O) |
1536 | 0 | { |
1537 | 0 | unsigned val = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1538 | 0 | SStream_concat0(O, ARM_TSB_TraceSyncBOptToString(val)); |
1539 | | // TODO: add to detail? |
1540 | 0 | } |
1541 | | |
1542 | | static void printShiftImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1543 | 2.43k | { |
1544 | 2.43k | unsigned ShiftOp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1545 | 2.43k | bool isASR = (ShiftOp & (1 << 5)) != 0; |
1546 | 2.43k | unsigned Amt = ShiftOp & 0x1f; |
1547 | | |
1548 | 2.43k | if (isASR) { |
1549 | 924 | unsigned tmp = Amt == 0 ? 32 : Amt; |
1550 | 924 | if (tmp > HEX_THRESHOLD) |
1551 | 514 | SStream_concat(O, ", asr #0x%x", tmp); |
1552 | 410 | else |
1553 | 410 | SStream_concat(O, ", asr #%u", tmp); |
1554 | | |
1555 | 924 | if (MI->csh->detail) { |
1556 | 924 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_ASR; |
1557 | 924 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = tmp; |
1558 | 924 | } |
1559 | 1.51k | } else if (Amt) { |
1560 | 1.13k | if (Amt > HEX_THRESHOLD) |
1561 | 771 | SStream_concat(O, ", lsl #0x%x", Amt); |
1562 | 364 | else |
1563 | 364 | SStream_concat(O, ", lsl #%u", Amt); |
1564 | | |
1565 | 1.13k | if (MI->csh->detail) { |
1566 | 1.13k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_LSL; |
1567 | 1.13k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Amt; |
1568 | 1.13k | } |
1569 | 1.13k | } |
1570 | 2.43k | } |
1571 | | |
1572 | | static void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O) |
1573 | 1.00k | { |
1574 | 1.00k | unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1575 | | |
1576 | 1.00k | if (Imm == 0) |
1577 | 95 | return; |
1578 | | |
1579 | | //assert(Imm > 0 && Imm < 32 && "Invalid PKH shift immediate value!"); |
1580 | 906 | if (Imm > HEX_THRESHOLD) |
1581 | 732 | SStream_concat(O, ", lsl #0x%x", Imm); |
1582 | 174 | else |
1583 | 174 | SStream_concat(O, ", lsl #%u", Imm); |
1584 | | |
1585 | 906 | if (MI->csh->detail) { |
1586 | 906 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_LSL; |
1587 | 906 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Imm; |
1588 | 906 | } |
1589 | 906 | } |
1590 | | |
1591 | | static void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O) |
1592 | 465 | { |
1593 | 465 | unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1594 | | |
1595 | | // A shift amount of 32 is encoded as 0. |
1596 | 465 | if (Imm == 0) |
1597 | 19 | Imm = 32; |
1598 | | |
1599 | | //assert(Imm > 0 && Imm <= 32 && "Invalid PKH shift immediate value!"); |
1600 | 465 | if (Imm > HEX_THRESHOLD) |
1601 | 247 | SStream_concat(O, ", asr #0x%x", Imm); |
1602 | 218 | else |
1603 | 218 | SStream_concat(O, ", asr #%u", Imm); |
1604 | | |
1605 | 465 | if (MI->csh->detail) { |
1606 | 465 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_ASR; |
1607 | 465 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Imm; |
1608 | 465 | } |
1609 | 465 | } |
1610 | | |
1611 | | // FIXME: push {r1, r2, r3, ...} can exceed the number of operands in MCInst struct |
1612 | | static void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O) |
1613 | 56.0k | { |
1614 | 56.0k | unsigned i, e; |
1615 | 56.0k | #ifndef CAPSTONE_DIET |
1616 | 56.0k | uint8_t access = 0; |
1617 | 56.0k | #endif |
1618 | | |
1619 | 56.0k | SStream_concat0(O, "{"); |
1620 | | |
1621 | 56.0k | #ifndef CAPSTONE_DIET |
1622 | 56.0k | if (MI->csh->detail) { |
1623 | 56.0k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
1624 | 56.0k | } |
1625 | 56.0k | #endif |
1626 | | |
1627 | 359k | for (i = OpNum, e = MCInst_getNumOperands(MI); i != e; ++i) { |
1628 | 303k | if (i != OpNum) |
1629 | 247k | SStream_concat0(O, ", "); |
1630 | | |
1631 | 303k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, i))); |
1632 | | |
1633 | 303k | if (MI->csh->detail) { |
1634 | 303k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1635 | 303k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, i)); |
1636 | 303k | #ifndef CAPSTONE_DIET |
1637 | 303k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
1638 | 303k | #endif |
1639 | 303k | MI->flat_insn->detail->arm.op_count++; |
1640 | 303k | } |
1641 | 303k | } |
1642 | | |
1643 | 56.0k | SStream_concat0(O, "}"); |
1644 | | |
1645 | 56.0k | #ifndef CAPSTONE_DIET |
1646 | 56.0k | if (MI->csh->detail) { |
1647 | 56.0k | MI->ac_idx++; |
1648 | 56.0k | } |
1649 | 56.0k | #endif |
1650 | 56.0k | } |
1651 | | |
1652 | | static void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1653 | 674 | { |
1654 | 674 | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
1655 | | |
1656 | 674 | printRegName(MI->csh, O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_0)); |
1657 | | |
1658 | 674 | if (MI->csh->detail) { |
1659 | 674 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1660 | 674 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_0); |
1661 | 674 | MI->flat_insn->detail->arm.op_count++; |
1662 | 674 | } |
1663 | | |
1664 | 674 | SStream_concat0(O, ", "); |
1665 | | |
1666 | 674 | printRegName(MI->csh, O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_1)); |
1667 | | |
1668 | 674 | if (MI->csh->detail) { |
1669 | 674 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
1670 | 674 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_1); |
1671 | 674 | MI->flat_insn->detail->arm.op_count++; |
1672 | 674 | } |
1673 | 674 | } |
1674 | | |
1675 | | // SETEND BE/LE |
1676 | | static void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1677 | 169 | { |
1678 | 169 | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1679 | | |
1680 | 169 | if (MCOperand_getImm(Op)) { |
1681 | 117 | SStream_concat0(O, "be"); |
1682 | | |
1683 | 117 | if (MI->csh->detail) { |
1684 | 117 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_SETEND; |
1685 | 117 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].setend = ARM_SETEND_BE; |
1686 | 117 | MI->flat_insn->detail->arm.op_count++; |
1687 | 117 | } |
1688 | 117 | } else { |
1689 | 52 | SStream_concat0(O, "le"); |
1690 | | |
1691 | 52 | if (MI->csh->detail) { |
1692 | 52 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_SETEND; |
1693 | 52 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].setend = ARM_SETEND_LE; |
1694 | 52 | MI->flat_insn->detail->arm.op_count++; |
1695 | 52 | } |
1696 | 52 | } |
1697 | 169 | } |
1698 | | |
1699 | | static void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O) |
1700 | 489 | { |
1701 | 489 | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1702 | 489 | unsigned int mode = (unsigned int)MCOperand_getImm(Op); |
1703 | | |
1704 | 489 | SStream_concat0(O, ARM_PROC_IModToString(mode)); |
1705 | | |
1706 | 489 | if (MI->csh->detail) { |
1707 | 489 | MI->flat_insn->detail->arm.cps_mode = mode; |
1708 | 489 | } |
1709 | 489 | } |
1710 | | |
1711 | | static void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O) |
1712 | 489 | { |
1713 | 489 | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1714 | 489 | unsigned IFlags = (unsigned int)MCOperand_getImm(Op); |
1715 | 489 | int i; |
1716 | | |
1717 | 1.95k | for (i = 2; i >= 0; --i) |
1718 | 1.46k | if (IFlags & (1 << i)) { |
1719 | 468 | SStream_concat0(O, ARM_PROC_IFlagsToString(1 << i)); |
1720 | 468 | } |
1721 | | |
1722 | 489 | if (IFlags == 0) { |
1723 | 239 | SStream_concat0(O, "none"); |
1724 | 239 | IFlags = ARM_CPSFLAG_NONE; |
1725 | 239 | } |
1726 | | |
1727 | 489 | if (MI->csh->detail) { |
1728 | 489 | MI->flat_insn->detail->arm.cps_flag = IFlags; |
1729 | 489 | } |
1730 | 489 | } |
1731 | | |
1732 | | static void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1733 | 7.50k | { |
1734 | 7.50k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
1735 | 7.50k | unsigned SpecRegRBit = (unsigned)MCOperand_getImm(Op) >> 4; |
1736 | 7.50k | unsigned Mask = (unsigned)MCOperand_getImm(Op) & 0xf; |
1737 | 7.50k | unsigned reg; |
1738 | | |
1739 | 7.50k | if (ARM_getFeatureBits(MI->csh->mode, ARM_FeatureMClass)) { |
1740 | 5.90k | const MClassSysReg *TheReg; |
1741 | 5.90k | unsigned SYSm = (unsigned)MCOperand_getImm(Op) & 0xFFF; // 12-bit SYMm |
1742 | 5.90k | unsigned Opcode = MCInst_getOpcode(MI); |
1743 | | |
1744 | 5.90k | if (Opcode == ARM_t2MSR_M && ARM_getFeatureBits(MI->csh->mode, ARM_FeatureDSP)) { |
1745 | 4.62k | TheReg = lookupMClassSysRegBy12bitSYSmValue(SYSm); |
1746 | 4.62k | if (TheReg && MClassSysReg_isInRequiredFeatures(TheReg, ARM_FeatureDSP)) { |
1747 | 959 | SStream_concat0(O, TheReg->Name); |
1748 | 959 | ARM_addSysReg(MI, TheReg->sysreg); |
1749 | 959 | return; |
1750 | 959 | } |
1751 | 4.62k | } |
1752 | | |
1753 | | // Handle the basic 8-bit mask. |
1754 | 4.94k | SYSm &= 0xff; |
1755 | 4.94k | if (Opcode == ARM_t2MSR_M && ARM_getFeatureBits(MI->csh->mode, ARM_HasV7Ops)) { |
1756 | | // ARMv7-M deprecates using MSR APSR without a _<bits> qualifier as an |
1757 | | // alias for MSR APSR_nzcvq. |
1758 | 3.66k | TheReg = lookupMClassSysRegAPSRNonDeprecated(SYSm); |
1759 | 3.66k | if (TheReg) { |
1760 | 1.32k | SStream_concat0(O, TheReg->Name); |
1761 | 1.32k | ARM_addSysReg(MI, TheReg->sysreg); |
1762 | 1.32k | return; |
1763 | 1.32k | } |
1764 | 3.66k | } |
1765 | | |
1766 | 3.62k | TheReg = lookupMClassSysRegBy8bitSYSmValue(SYSm); |
1767 | 3.62k | if (TheReg) { |
1768 | 3.11k | SStream_concat0(O, TheReg->Name); |
1769 | 3.11k | ARM_addSysReg(MI, TheReg->sysreg); |
1770 | 3.11k | return; |
1771 | 3.11k | } |
1772 | | |
1773 | 506 | if (SYSm > HEX_THRESHOLD) |
1774 | 450 | SStream_concat(O, "%x", SYSm); |
1775 | 56 | else |
1776 | 56 | SStream_concat(O, "%u", SYSm); |
1777 | | |
1778 | 506 | if (MI->csh->detail) |
1779 | 506 | MCOperand_CreateImm0(MI, SYSm); |
1780 | | |
1781 | 506 | return; |
1782 | 3.62k | } |
1783 | | |
1784 | | // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as |
1785 | | // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively. |
1786 | 1.59k | if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) { |
1787 | 860 | SStream_concat0(O, "apsr_"); |
1788 | 860 | switch (Mask) { |
1789 | 0 | default: // llvm_unreachable("Unexpected mask value!"); |
1790 | 30 | case 4: SStream_concat0(O, "g"); ARM_addSysReg(MI, ARM_SYSREG_APSR_G); return; |
1791 | 540 | case 8: SStream_concat0(O, "nzcvq"); ARM_addSysReg(MI, ARM_SYSREG_APSR_NZCVQ); return; |
1792 | 290 | case 12: SStream_concat0(O, "nzcvqg"); ARM_addSysReg(MI, ARM_SYSREG_APSR_NZCVQG); return; |
1793 | 860 | } |
1794 | 860 | } |
1795 | | |
1796 | 739 | if (SpecRegRBit) { |
1797 | 264 | SStream_concat0(O, "spsr"); |
1798 | 475 | } else { |
1799 | 475 | SStream_concat0(O, "cpsr"); |
1800 | 475 | } |
1801 | | |
1802 | 739 | reg = 0; |
1803 | 739 | if (Mask) { |
1804 | 633 | SStream_concat0(O, "_"); |
1805 | | |
1806 | 633 | if (Mask & 8) { |
1807 | 444 | SStream_concat0(O, "f"); |
1808 | 444 | reg += SpecRegRBit ? ARM_SYSREG_SPSR_F : ARM_SYSREG_CPSR_F; |
1809 | 444 | } |
1810 | | |
1811 | 633 | if (Mask & 4) { |
1812 | 427 | SStream_concat0(O, "s"); |
1813 | 427 | reg += SpecRegRBit ? ARM_SYSREG_SPSR_S : ARM_SYSREG_CPSR_S; |
1814 | 427 | } |
1815 | | |
1816 | 633 | if (Mask & 2) { |
1817 | 538 | SStream_concat0(O, "x"); |
1818 | 538 | reg += SpecRegRBit ? ARM_SYSREG_SPSR_X : ARM_SYSREG_CPSR_X; |
1819 | 538 | } |
1820 | | |
1821 | 633 | if (Mask & 1) { |
1822 | 239 | SStream_concat0(O, "c"); |
1823 | 239 | reg += SpecRegRBit ? ARM_SYSREG_SPSR_C : ARM_SYSREG_CPSR_C; |
1824 | 239 | } |
1825 | | |
1826 | 633 | ARM_addSysReg(MI, reg); |
1827 | 633 | } |
1828 | 739 | } |
1829 | | |
1830 | | static void printBankedRegOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1831 | 731 | { |
1832 | 731 | uint32_t Banked = (uint32_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1833 | 731 | const BankedReg *TheReg = lookupBankedRegByEncoding(Banked); |
1834 | | |
1835 | 731 | SStream_concat0(O, TheReg->Name); |
1836 | 731 | ARM_addSysReg(MI, TheReg->sysreg); |
1837 | 731 | } |
1838 | | |
1839 | | static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1840 | 1.16M | { |
1841 | 1.16M | ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1842 | | // Handle the undefined 15 CC value here for printing so we don't abort(). |
1843 | 1.16M | if ((unsigned)CC == 15) { |
1844 | 203 | SStream_concat0(O, "<und>"); |
1845 | | |
1846 | 203 | if (MI->csh->detail) |
1847 | 203 | MI->flat_insn->detail->arm.cc = ARM_CC_INVALID; |
1848 | 1.16M | } else { |
1849 | 1.16M | if (CC != ARMCC_AL) { |
1850 | 230k | SStream_concat0(O, ARMCC_ARMCondCodeToString(CC)); |
1851 | 230k | } |
1852 | | |
1853 | 1.16M | if (MI->csh->detail) |
1854 | 1.16M | MI->flat_insn->detail->arm.cc = CC + 1; |
1855 | 1.16M | } |
1856 | 1.16M | } |
1857 | | |
1858 | | static void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1859 | 20.6k | { |
1860 | 20.6k | ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1861 | 20.6k | SStream_concat0(O, ARMCC_ARMCondCodeToString(CC)); |
1862 | | |
1863 | 20.6k | if (MI->csh->detail) |
1864 | 20.6k | MI->flat_insn->detail->arm.cc = CC + 1; |
1865 | 20.6k | } |
1866 | | |
1867 | | static void printSBitModifierOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1868 | 357k | { |
1869 | 357k | if (MCOperand_getReg(MCInst_getOperand(MI, OpNum))) { |
1870 | | //assert(MCOperand_getReg(MCInst_getOperand(MI, OpNum)) == ARM_CPSR && |
1871 | | // "Expect ARM CPSR register!"); |
1872 | 305k | SStream_concat0(O, "s"); |
1873 | | |
1874 | 305k | if (MI->csh->detail) |
1875 | 305k | MI->flat_insn->detail->arm.update_flags = true; |
1876 | 305k | } |
1877 | 357k | } |
1878 | | |
1879 | | static void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O) |
1880 | 26.6k | { |
1881 | 26.6k | unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1882 | | |
1883 | 26.6k | printUInt32(O, tmp); |
1884 | | |
1885 | 26.6k | if (MI->csh->detail) { |
1886 | 26.6k | if (MI->csh->doing_mem) { |
1887 | 26.6k | MI->flat_insn->detail->arm.op_count--; |
1888 | 26.6k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].neon_lane = (int8_t)tmp; |
1889 | 26.6k | MI->ac_idx--; // consecutive operands share the same access right |
1890 | 26.6k | } else { |
1891 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1892 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
1893 | 0 | MI->flat_insn->detail->arm.op_count++; |
1894 | 0 | } |
1895 | 26.6k | } |
1896 | 26.6k | } |
1897 | | |
1898 | | static void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O) |
1899 | 61.3k | { |
1900 | 61.3k | unsigned imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1901 | | |
1902 | 61.3k | SStream_concat(O, "p%u", imm); |
1903 | | |
1904 | 61.3k | if (MI->csh->detail) { |
1905 | 61.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_PIMM; |
1906 | 61.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = imm; |
1907 | 61.3k | MI->flat_insn->detail->arm.op_count++; |
1908 | 61.3k | } |
1909 | 61.3k | } |
1910 | | |
1911 | | static void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O) |
1912 | 86.7k | { |
1913 | 86.7k | unsigned imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1914 | | |
1915 | 86.7k | SStream_concat(O, "c%u", imm); |
1916 | | |
1917 | 86.7k | if (MI->csh->detail) { |
1918 | 86.7k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_CIMM; |
1919 | 86.7k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = imm; |
1920 | 86.7k | MI->flat_insn->detail->arm.op_count++; |
1921 | 86.7k | } |
1922 | 86.7k | } |
1923 | | |
1924 | | static void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O) |
1925 | 5.09k | { |
1926 | 5.09k | unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1927 | 5.09k | if (tmp > HEX_THRESHOLD) |
1928 | 4.36k | SStream_concat(O, "{0x%x}", tmp); |
1929 | 725 | else |
1930 | 725 | SStream_concat(O, "{%u}", tmp); |
1931 | | |
1932 | 5.09k | if (MI->csh->detail) { |
1933 | 5.09k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1934 | 5.09k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
1935 | 5.09k | MI->flat_insn->detail->arm.op_count++; |
1936 | 5.09k | } |
1937 | 5.09k | } |
1938 | | |
1939 | | static void printAdrLabelOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned scale) |
1940 | 24.3k | { |
1941 | 24.3k | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
1942 | | |
1943 | 24.3k | int32_t OffImm = (int32_t)MCOperand_getImm(MO) << scale; |
1944 | | |
1945 | 24.3k | if (OffImm == INT32_MIN) { |
1946 | 0 | SStream_concat0(O, "#-0"); |
1947 | |
|
1948 | 0 | if (MI->csh->detail) { |
1949 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1950 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = 0; |
1951 | 0 | MI->flat_insn->detail->arm.op_count++; |
1952 | 0 | } |
1953 | 24.3k | } else { |
1954 | 24.3k | if (OffImm < 0) |
1955 | 0 | SStream_concat(O, "#-0x%x", -OffImm); |
1956 | 24.3k | else { |
1957 | 24.3k | if (OffImm > HEX_THRESHOLD) |
1958 | 22.1k | SStream_concat(O, "#0x%x", OffImm); |
1959 | 2.13k | else |
1960 | 2.13k | SStream_concat(O, "#%u", OffImm); |
1961 | 24.3k | } |
1962 | | |
1963 | 24.3k | if (MI->csh->detail) { |
1964 | 24.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1965 | 24.3k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = OffImm; |
1966 | 24.3k | MI->flat_insn->detail->arm.op_count++; |
1967 | 24.3k | } |
1968 | 24.3k | } |
1969 | 24.3k | } |
1970 | | |
1971 | | static void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
1972 | 31.0k | { |
1973 | 31.0k | unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)) * 4; |
1974 | | |
1975 | 31.0k | printUInt32Bang(O, tmp); |
1976 | | |
1977 | 31.0k | if (MI->csh->detail) { |
1978 | 31.0k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1979 | 31.0k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
1980 | 31.0k | MI->flat_insn->detail->arm.op_count++; |
1981 | 31.0k | } |
1982 | 31.0k | } |
1983 | | |
1984 | | static void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O) |
1985 | 67.9k | { |
1986 | 67.9k | unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
1987 | 67.9k | unsigned tmp = Imm == 0 ? 32 : Imm; |
1988 | | |
1989 | 67.9k | printUInt32Bang(O, tmp); |
1990 | | |
1991 | 67.9k | if (MI->csh->detail) { |
1992 | 67.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
1993 | 67.9k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
1994 | 67.9k | MI->flat_insn->detail->arm.op_count++; |
1995 | 67.9k | } |
1996 | 67.9k | } |
1997 | | |
1998 | | static void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O) |
1999 | 20.6k | { |
2000 | | // (3 - the number of trailing zeros) is the number of then / else. |
2001 | 20.6k | unsigned Mask = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2002 | 20.6k | unsigned Firstcond = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum - 1)); |
2003 | 20.6k | unsigned CondBit0 = Firstcond & 1; |
2004 | 20.6k | unsigned NumTZ = CountTrailingZeros_32(Mask); |
2005 | | //assert(NumTZ <= 3 && "Invalid IT mask!"); |
2006 | 20.6k | unsigned Pos, e; |
2007 | | |
2008 | 78.9k | for (Pos = 3, e = NumTZ; Pos > e; --Pos) { |
2009 | 58.3k | bool T = ((Mask >> Pos) & 1) == CondBit0; |
2010 | 58.3k | if (T) |
2011 | 48.4k | SStream_concat0(O, "t"); |
2012 | 9.95k | else |
2013 | 9.95k | SStream_concat0(O, "e"); |
2014 | | // TODO: detail for this t/e |
2015 | 58.3k | } |
2016 | 20.6k | } |
2017 | | |
2018 | | static void printThumbAddrModeRROperand(MCInst *MI, unsigned Op, SStream *O) |
2019 | 37.4k | { |
2020 | 37.4k | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
2021 | 37.4k | MCOperand *MO2 = MCInst_getOperand(MI, Op + 1); |
2022 | 37.4k | unsigned RegNum; |
2023 | | |
2024 | 37.4k | if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right. |
2025 | 0 | printOperand(MI, Op, O); |
2026 | 0 | return; |
2027 | 0 | } |
2028 | | |
2029 | 37.4k | SStream_concat0(O, "["); |
2030 | 37.4k | set_mem_access(MI, true); |
2031 | | |
2032 | 37.4k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2033 | | |
2034 | 37.4k | if (MI->csh->detail) |
2035 | 37.4k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2036 | | |
2037 | 37.4k | RegNum = MCOperand_getReg(MO2); |
2038 | 37.4k | if (RegNum) { |
2039 | 37.4k | SStream_concat0(O, ", "); |
2040 | 37.4k | printRegName(MI->csh, O, RegNum); |
2041 | | |
2042 | 37.4k | if (MI->csh->detail) |
2043 | 37.4k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = RegNum; |
2044 | 37.4k | } |
2045 | | |
2046 | 37.4k | SStream_concat0(O, "]"); |
2047 | 37.4k | set_mem_access(MI, false); |
2048 | 37.4k | } |
2049 | | |
2050 | | static void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned Op, SStream *O, |
2051 | | unsigned Scale) |
2052 | 231k | { |
2053 | 231k | MCOperand *MO1 = MCInst_getOperand(MI, Op); |
2054 | 231k | MCOperand *MO2 = MCInst_getOperand(MI, Op + 1); |
2055 | 231k | unsigned ImmOffs, tmp; |
2056 | | |
2057 | 231k | if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right. |
2058 | 0 | printOperand(MI, Op, O); |
2059 | 0 | return; |
2060 | 0 | } |
2061 | | |
2062 | 231k | SStream_concat0(O, "["); |
2063 | 231k | set_mem_access(MI, true); |
2064 | | |
2065 | 231k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2066 | | |
2067 | 231k | if (MI->csh->detail) |
2068 | 231k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2069 | | |
2070 | 231k | ImmOffs = (unsigned int)MCOperand_getImm(MO2); |
2071 | 231k | if (ImmOffs) { |
2072 | 221k | tmp = ImmOffs * Scale; |
2073 | 221k | SStream_concat0(O, ", "); |
2074 | 221k | printUInt32Bang(O, tmp); |
2075 | | |
2076 | 221k | if (MI->csh->detail) |
2077 | 221k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp; |
2078 | 221k | } |
2079 | | |
2080 | 231k | SStream_concat0(O, "]"); |
2081 | 231k | set_mem_access(MI, false); |
2082 | 231k | } |
2083 | | |
2084 | | static void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned Op, SStream *O) |
2085 | 57.3k | { |
2086 | 57.3k | printThumbAddrModeImm5SOperand(MI, Op, O, 1); |
2087 | 57.3k | } |
2088 | | |
2089 | | static void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned Op, SStream *O) |
2090 | 57.5k | { |
2091 | 57.5k | printThumbAddrModeImm5SOperand(MI, Op, O, 2); |
2092 | 57.5k | } |
2093 | | |
2094 | | static void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned Op, SStream *O) |
2095 | 79.2k | { |
2096 | 79.2k | printThumbAddrModeImm5SOperand(MI, Op, O, 4); |
2097 | 79.2k | } |
2098 | | |
2099 | | static void printThumbAddrModeSPOperand(MCInst *MI, unsigned Op, SStream *O) |
2100 | 37.6k | { |
2101 | 37.6k | printThumbAddrModeImm5SOperand(MI, Op, O, 4); |
2102 | 37.6k | } |
2103 | | |
2104 | | // Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2 |
2105 | | // register with shift forms. |
2106 | | // REG 0 0 - e.g. R5 |
2107 | | // REG IMM, SH_OPC - e.g. R5, LSL #3 |
2108 | | static void printT2SOOperand(MCInst *MI, unsigned OpNum, SStream *O) |
2109 | 5.34k | { |
2110 | 5.34k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2111 | 5.34k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
2112 | 5.34k | unsigned Reg = MCOperand_getReg(MO1); |
2113 | | |
2114 | 5.34k | printRegName(MI->csh, O, Reg); |
2115 | | |
2116 | 5.34k | if (MI->csh->detail) { |
2117 | 5.34k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2118 | 5.34k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg; |
2119 | 5.34k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = CS_AC_READ; |
2120 | 5.34k | MI->flat_insn->detail->arm.op_count++; |
2121 | 5.34k | } |
2122 | | |
2123 | | // Print the shift opc. |
2124 | | //assert(MO2.isImm() && "Not a valid t2_so_reg value!"); |
2125 | 5.34k | printRegImmShift(MI, O, ARM_AM_getSORegShOp((unsigned int)MCOperand_getImm(MO2)), |
2126 | 5.34k | getSORegOffset((unsigned int)MCOperand_getImm(MO2))); |
2127 | 5.34k | } |
2128 | | |
2129 | | static void printAddrModeImm12Operand(MCInst *MI, unsigned OpNum, |
2130 | | SStream *O, bool AlwaysPrintImm0) |
2131 | 12.6k | { |
2132 | 12.6k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2133 | 12.6k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1); |
2134 | 12.6k | int32_t OffImm; |
2135 | 12.6k | bool isSub; |
2136 | | |
2137 | 12.6k | if (!MCOperand_isReg(MO1)) { // FIXME: This is for CP entries, but isn't right. |
2138 | 0 | printOperand(MI, OpNum, O); |
2139 | 0 | return; |
2140 | 0 | } |
2141 | | |
2142 | 12.6k | SStream_concat0(O, "["); |
2143 | 12.6k | set_mem_access(MI, true); |
2144 | | |
2145 | 12.6k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2146 | | |
2147 | 12.6k | if (MI->csh->detail) |
2148 | 12.6k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2149 | | |
2150 | 12.6k | OffImm = (int32_t)MCOperand_getImm(MO2); |
2151 | 12.6k | isSub = OffImm < 0; |
2152 | | |
2153 | | // Special value for #-0. All others are normal. |
2154 | 12.6k | if (OffImm == INT32_MIN) |
2155 | 361 | OffImm = 0; |
2156 | | |
2157 | 12.6k | if (isSub) { |
2158 | 5.04k | if (OffImm < -HEX_THRESHOLD) |
2159 | 4.60k | SStream_concat(O, ", #-0x%x", -OffImm); |
2160 | 439 | else |
2161 | 439 | SStream_concat(O, ", #-%u", -OffImm); |
2162 | 7.63k | } else if (AlwaysPrintImm0 || OffImm > 0) { |
2163 | 7.42k | if (OffImm >= 0) { |
2164 | 7.42k | if (OffImm > HEX_THRESHOLD) |
2165 | 7.20k | SStream_concat(O, ", #0x%x", OffImm); |
2166 | 217 | else |
2167 | 217 | SStream_concat(O, ", #%u", OffImm); |
2168 | 7.42k | } else { |
2169 | 0 | if (OffImm < -HEX_THRESHOLD) |
2170 | 0 | SStream_concat(O, ", #-0x%x", -OffImm); |
2171 | 0 | else |
2172 | 0 | SStream_concat(O, ", #-%u", -OffImm); |
2173 | 0 | } |
2174 | 7.42k | } |
2175 | | |
2176 | 12.6k | if (MI->csh->detail) |
2177 | 12.6k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm; |
2178 | | |
2179 | 12.6k | SStream_concat0(O, "]"); |
2180 | 12.6k | set_mem_access(MI, false); |
2181 | 12.6k | } |
2182 | | |
2183 | | static void printT2AddrModeImm8Operand(MCInst *MI, unsigned OpNum, SStream *O, |
2184 | | bool AlwaysPrintImm0) |
2185 | 4.27k | { |
2186 | 4.27k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2187 | 4.27k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1); |
2188 | 4.27k | int32_t OffImm; |
2189 | 4.27k | bool isSub; |
2190 | | |
2191 | 4.27k | SStream_concat0(O, "["); |
2192 | 4.27k | set_mem_access(MI, true); |
2193 | | |
2194 | 4.27k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2195 | | |
2196 | 4.27k | if (MI->csh->detail) |
2197 | 4.27k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2198 | | |
2199 | 4.27k | OffImm = (int32_t)MCOperand_getImm(MO2); |
2200 | 4.27k | isSub = OffImm < 0; |
2201 | | |
2202 | | // Don't print +0. |
2203 | 4.27k | if (OffImm == INT32_MIN) |
2204 | 181 | OffImm = 0; |
2205 | | |
2206 | 4.27k | if (isSub) |
2207 | 1.80k | SStream_concat(O, ", #-0x%x", -OffImm); |
2208 | 2.47k | else if (AlwaysPrintImm0 || OffImm > 0) { |
2209 | 2.20k | if (OffImm > HEX_THRESHOLD) |
2210 | 1.72k | SStream_concat(O, ", #0x%x", OffImm); |
2211 | 476 | else |
2212 | 476 | SStream_concat(O, ", #%u", OffImm); |
2213 | 2.20k | } |
2214 | | |
2215 | 4.27k | if (MI->csh->detail) |
2216 | 4.27k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm; |
2217 | | |
2218 | 4.27k | SStream_concat0(O, "]"); |
2219 | 4.27k | set_mem_access(MI, false); |
2220 | 4.27k | } |
2221 | | |
2222 | | static void printT2AddrModeImm8s4Operand(MCInst *MI, |
2223 | | unsigned OpNum, SStream *O, bool AlwaysPrintImm0) |
2224 | 13.2k | { |
2225 | 13.2k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2226 | 13.2k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
2227 | 13.2k | int32_t OffImm; |
2228 | 13.2k | bool isSub; |
2229 | | |
2230 | 13.2k | if (!MCOperand_isReg(MO1)) { // For label symbolic references. |
2231 | 0 | printOperand(MI, OpNum, O); |
2232 | 0 | return; |
2233 | 0 | } |
2234 | | |
2235 | 13.2k | SStream_concat0(O, "["); |
2236 | 13.2k | set_mem_access(MI, true); |
2237 | | |
2238 | 13.2k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2239 | | |
2240 | 13.2k | if (MI->csh->detail) |
2241 | 13.2k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2242 | | |
2243 | 13.2k | OffImm = (int32_t)MCOperand_getImm(MO2); |
2244 | 13.2k | isSub = OffImm < 0; |
2245 | | |
2246 | | //assert(((OffImm & 0x3) == 0) && "Not a valid immediate!"); |
2247 | | |
2248 | | // Don't print +0. |
2249 | 13.2k | if (OffImm == INT32_MIN) |
2250 | 738 | OffImm = 0; |
2251 | | |
2252 | 13.2k | if (isSub) { |
2253 | 5.63k | SStream_concat(O, ", #-0x%x", -OffImm); |
2254 | 7.65k | } else if (AlwaysPrintImm0 || OffImm > 0) { |
2255 | 7.44k | if (OffImm > HEX_THRESHOLD) |
2256 | 4.56k | SStream_concat(O, ", #0x%x", OffImm); |
2257 | 2.88k | else |
2258 | 2.88k | SStream_concat(O, ", #%u", OffImm); |
2259 | 7.44k | } |
2260 | | |
2261 | 13.2k | if (MI->csh->detail) |
2262 | 13.2k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = OffImm; |
2263 | | |
2264 | 13.2k | SStream_concat0(O, "]"); |
2265 | 13.2k | set_mem_access(MI, false); |
2266 | 13.2k | } |
2267 | | |
2268 | | static void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum, SStream *O) |
2269 | 1.32k | { |
2270 | 1.32k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2271 | 1.32k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum + 1); |
2272 | 1.32k | unsigned tmp; |
2273 | | |
2274 | 1.32k | SStream_concat0(O, "["); |
2275 | 1.32k | set_mem_access(MI, true); |
2276 | | |
2277 | 1.32k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2278 | | |
2279 | 1.32k | if (MI->csh->detail) |
2280 | 1.32k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2281 | | |
2282 | 1.32k | if (MCOperand_getImm(MO2)) { |
2283 | 1.16k | SStream_concat0(O, ", "); |
2284 | 1.16k | tmp = (unsigned int)MCOperand_getImm(MO2) * 4; |
2285 | 1.16k | printUInt32Bang(O, tmp); |
2286 | | |
2287 | 1.16k | if (MI->csh->detail) |
2288 | 1.16k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.disp = tmp; |
2289 | 1.16k | } |
2290 | | |
2291 | 1.32k | SStream_concat0(O, "]"); |
2292 | 1.32k | set_mem_access(MI, false); |
2293 | 1.32k | } |
2294 | | |
2295 | | static void printT2AddrModeImm8OffsetOperand(MCInst *MI, |
2296 | | unsigned OpNum, SStream *O) |
2297 | 1.30k | { |
2298 | 1.30k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2299 | 1.30k | int32_t OffImm = (int32_t)MCOperand_getImm(MO1); |
2300 | | |
2301 | 1.30k | SStream_concat0(O, ", "); |
2302 | 1.30k | if (OffImm == INT32_MIN) { |
2303 | 82 | SStream_concat0(O, "#-0"); |
2304 | | |
2305 | 82 | if (MI->csh->detail) { |
2306 | 82 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2307 | 82 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = 0; |
2308 | 82 | MI->flat_insn->detail->arm.op_count++; |
2309 | 82 | } |
2310 | 1.21k | } else { |
2311 | 1.21k | printInt32Bang(O, OffImm); |
2312 | | |
2313 | 1.21k | if (MI->csh->detail) { |
2314 | 1.21k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2315 | 1.21k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = OffImm; |
2316 | 1.21k | MI->flat_insn->detail->arm.op_count++; |
2317 | 1.21k | } |
2318 | 1.21k | } |
2319 | 1.30k | } |
2320 | | |
2321 | | static void printT2AddrModeImm8s4OffsetOperand(MCInst *MI, |
2322 | | unsigned OpNum, SStream *O) |
2323 | 3.04k | { |
2324 | 3.04k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2325 | 3.04k | int32_t OffImm = (int32_t)MCOperand_getImm(MO1); |
2326 | | |
2327 | | //assert(((OffImm & 0x3) == 0) && "Not a valid immediate!"); |
2328 | | |
2329 | 3.04k | SStream_concat0(O, ", "); |
2330 | | |
2331 | 3.04k | if (OffImm == INT32_MIN) { |
2332 | 204 | SStream_concat0(O, "#-0"); |
2333 | | |
2334 | 204 | if (MI->csh->detail) { |
2335 | 204 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2336 | 204 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = 0; |
2337 | 204 | MI->flat_insn->detail->arm.op_count++; |
2338 | 204 | } |
2339 | 2.84k | } else { |
2340 | 2.84k | printInt32Bang(O, OffImm); |
2341 | | |
2342 | 2.84k | if (MI->csh->detail) { |
2343 | 2.84k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2344 | 2.84k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = OffImm; |
2345 | 2.84k | MI->flat_insn->detail->arm.op_count++; |
2346 | 2.84k | } |
2347 | 2.84k | } |
2348 | 3.04k | } |
2349 | | |
2350 | | static void printT2AddrModeSoRegOperand(MCInst *MI, |
2351 | | unsigned OpNum, SStream *O) |
2352 | 1.28k | { |
2353 | 1.28k | MCOperand *MO1 = MCInst_getOperand(MI, OpNum); |
2354 | 1.28k | MCOperand *MO2 = MCInst_getOperand(MI, OpNum+1); |
2355 | 1.28k | MCOperand *MO3 = MCInst_getOperand(MI, OpNum+2); |
2356 | 1.28k | unsigned ShAmt; |
2357 | | |
2358 | 1.28k | SStream_concat0(O, "["); |
2359 | 1.28k | set_mem_access(MI, true); |
2360 | | |
2361 | 1.28k | printRegName(MI->csh, O, MCOperand_getReg(MO1)); |
2362 | | |
2363 | 1.28k | if (MI->csh->detail) |
2364 | 1.28k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.base = MCOperand_getReg(MO1); |
2365 | | |
2366 | | //assert(MCOperand_getReg(MO2.getReg() && "Invalid so_reg load / store address!"); |
2367 | 1.28k | SStream_concat0(O, ", "); |
2368 | 1.28k | printRegName(MI->csh, O, MCOperand_getReg(MO2)); |
2369 | | |
2370 | 1.28k | if (MI->csh->detail) |
2371 | 1.28k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].mem.index = MCOperand_getReg(MO2); |
2372 | | |
2373 | 1.28k | ShAmt = (unsigned int)MCOperand_getImm(MO3); |
2374 | 1.28k | if (ShAmt) { |
2375 | | //assert(ShAmt <= 3 && "Not a valid Thumb2 addressing mode!"); |
2376 | 848 | SStream_concat0(O, ", lsl "); |
2377 | 848 | SStream_concat(O, "#%u", ShAmt); |
2378 | | |
2379 | 848 | if (MI->csh->detail) { |
2380 | 848 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.type = ARM_SFT_LSL; |
2381 | 848 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].shift.value = ShAmt; |
2382 | 848 | } |
2383 | 848 | } |
2384 | | |
2385 | 1.28k | SStream_concat0(O, "]"); |
2386 | 1.28k | set_mem_access(MI, false); |
2387 | 1.28k | } |
2388 | | |
2389 | | static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
2390 | 573 | { |
2391 | 573 | MCOperand *MO = MCInst_getOperand(MI, OpNum); |
2392 | | |
2393 | | #if defined(_KERNEL_MODE) |
2394 | | // Issue #681: Windows kernel does not support formatting float point |
2395 | | SStream_concat(O, "#<float_point_unsupported>"); |
2396 | | #else |
2397 | 573 | SStream_concat(O, "#%e", getFPImmFloat((unsigned int)MCOperand_getImm(MO))); |
2398 | 573 | #endif |
2399 | | |
2400 | 573 | if (MI->csh->detail) { |
2401 | 573 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_FP; |
2402 | 573 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].fp = getFPImmFloat((unsigned int)MCOperand_getImm(MO)); |
2403 | 573 | MI->flat_insn->detail->arm.op_count++; |
2404 | 573 | } |
2405 | 573 | } |
2406 | | |
2407 | | static void printNEONModImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
2408 | 2.30k | { |
2409 | 2.30k | unsigned EncodedImm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2410 | 2.30k | unsigned EltBits; |
2411 | 2.30k | uint64_t Val = ARM_AM_decodeNEONModImm(EncodedImm, &EltBits); |
2412 | | |
2413 | 2.30k | if (Val > HEX_THRESHOLD) |
2414 | 2.18k | SStream_concat(O, "#0x%"PRIx64, Val); |
2415 | 121 | else |
2416 | 121 | SStream_concat(O, "#%"PRIu64, Val); |
2417 | | |
2418 | 2.30k | if (MI->csh->detail) { |
2419 | 2.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2420 | 2.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = (unsigned int)Val; |
2421 | 2.30k | MI->flat_insn->detail->arm.op_count++; |
2422 | 2.30k | } |
2423 | 2.30k | } |
2424 | | |
2425 | | static void printImmPlusOneOperand(MCInst *MI, unsigned OpNum, SStream *O) |
2426 | 1.69k | { |
2427 | 1.69k | unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2428 | | |
2429 | 1.69k | printUInt32Bang(O, Imm + 1); |
2430 | | |
2431 | 1.69k | if (MI->csh->detail) { |
2432 | 1.69k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2433 | 1.69k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Imm + 1; |
2434 | 1.69k | MI->flat_insn->detail->arm.op_count++; |
2435 | 1.69k | } |
2436 | 1.69k | } |
2437 | | |
2438 | | static void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
2439 | 2.89k | { |
2440 | 2.89k | unsigned Imm = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2441 | | |
2442 | 2.89k | if (Imm == 0) |
2443 | 484 | return; |
2444 | | |
2445 | 2.41k | SStream_concat0(O, ", ror #"); |
2446 | | |
2447 | 2.41k | switch (Imm) { |
2448 | 0 | default: //assert (0 && "illegal ror immediate!"); |
2449 | 720 | case 1: SStream_concat0(O, "8"); break; |
2450 | 513 | case 2: SStream_concat0(O, "16"); break; |
2451 | 1.17k | case 3: SStream_concat0(O, "24"); break; |
2452 | 2.41k | } |
2453 | | |
2454 | 2.41k | if (MI->csh->detail) { |
2455 | 2.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.type = ARM_SFT_ROR; |
2456 | 2.41k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].shift.value = Imm * 8; |
2457 | 2.41k | } |
2458 | 2.41k | } |
2459 | | |
2460 | | static void printModImmOperand(MCInst *MI, unsigned OpNum, SStream *O) |
2461 | 13.9k | { |
2462 | 13.9k | MCOperand *Op = MCInst_getOperand(MI, OpNum); |
2463 | 13.9k | unsigned Bits = MCOperand_getImm(Op) & 0xFF; |
2464 | 13.9k | unsigned Rot = (MCOperand_getImm(Op) & 0xF00) >> 7; |
2465 | 13.9k | int32_t Rotated; |
2466 | 13.9k | bool PrintUnsigned = false; |
2467 | | |
2468 | 13.9k | switch (MCInst_getOpcode(MI)) { |
2469 | 76 | case ARM_MOVi: |
2470 | | // Movs to PC should be treated unsigned |
2471 | 76 | PrintUnsigned = (MCOperand_getReg(MCInst_getOperand(MI, OpNum - 1)) == ARM_PC); |
2472 | 76 | break; |
2473 | 309 | case ARM_MSRi: |
2474 | | // Movs to special registers should be treated unsigned |
2475 | 309 | PrintUnsigned = true; |
2476 | 309 | break; |
2477 | 13.9k | } |
2478 | | |
2479 | 13.9k | Rotated = rotr32(Bits, Rot); |
2480 | 13.9k | if (getSOImmVal(Rotated) == MCOperand_getImm(Op)) { |
2481 | | // #rot has the least possible value |
2482 | 11.0k | if (PrintUnsigned) { |
2483 | 197 | if (Rotated > HEX_THRESHOLD || Rotated < -HEX_THRESHOLD) |
2484 | 99 | SStream_concat(O, "#0x%x", Rotated); |
2485 | 98 | else |
2486 | 98 | SStream_concat(O, "#%u", Rotated); |
2487 | 10.8k | } else if (Rotated >= 0) { |
2488 | 9.25k | if (Rotated > HEX_THRESHOLD) |
2489 | 8.51k | SStream_concat(O, "#0x%x", Rotated); |
2490 | 736 | else |
2491 | 736 | SStream_concat(O, "#%u", Rotated); |
2492 | 9.25k | } else { |
2493 | 1.58k | SStream_concat(O, "#0x%x", Rotated); |
2494 | 1.58k | } |
2495 | | |
2496 | 11.0k | if (MI->csh->detail) { |
2497 | 11.0k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2498 | 11.0k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Rotated; |
2499 | 11.0k | MI->flat_insn->detail->arm.op_count++; |
2500 | 11.0k | } |
2501 | | |
2502 | 11.0k | return; |
2503 | 11.0k | } |
2504 | | |
2505 | | // Explicit #bits, #rot implied |
2506 | 2.94k | SStream_concat(O, "#%u, #%u", Bits, Rot); |
2507 | | |
2508 | 2.94k | if (MI->csh->detail) { |
2509 | 2.94k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2510 | 2.94k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Bits; |
2511 | 2.94k | MI->flat_insn->detail->arm.op_count++; |
2512 | 2.94k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2513 | 2.94k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = Rot; |
2514 | 2.94k | MI->flat_insn->detail->arm.op_count++; |
2515 | 2.94k | } |
2516 | 2.94k | } |
2517 | | |
2518 | | static void printFBits16(MCInst *MI, unsigned OpNum, SStream *O) |
2519 | 1.07k | { |
2520 | 1.07k | unsigned tmp; |
2521 | | |
2522 | 1.07k | tmp = 16 - (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2523 | | |
2524 | 1.07k | printUInt32Bang(O, tmp); |
2525 | | |
2526 | 1.07k | if (MI->csh->detail) { |
2527 | 1.07k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2528 | 1.07k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
2529 | 1.07k | MI->flat_insn->detail->arm.op_count++; |
2530 | 1.07k | } |
2531 | 1.07k | } |
2532 | | |
2533 | | static void printFBits32(MCInst *MI, unsigned OpNum, SStream *O) |
2534 | 445 | { |
2535 | 445 | unsigned tmp; |
2536 | | |
2537 | 445 | tmp = 32 - (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2538 | | |
2539 | 445 | printUInt32Bang(O, tmp); |
2540 | | |
2541 | 445 | if (MI->csh->detail) { |
2542 | 445 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
2543 | 445 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
2544 | 445 | MI->flat_insn->detail->arm.op_count++; |
2545 | 445 | } |
2546 | 445 | } |
2547 | | |
2548 | | static void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O) |
2549 | 4.76k | { |
2550 | 4.76k | unsigned tmp = (unsigned int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)); |
2551 | | |
2552 | 4.76k | if (tmp > HEX_THRESHOLD) |
2553 | 0 | SStream_concat(O, "[0x%x]", tmp); |
2554 | 4.76k | else |
2555 | 4.76k | SStream_concat(O, "[%u]", tmp); |
2556 | | |
2557 | 4.76k | if (MI->csh->detail) { |
2558 | 4.76k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count - 1].vector_index = tmp; |
2559 | 4.76k | } |
2560 | 4.76k | } |
2561 | | |
2562 | | static void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O) |
2563 | 2.99k | { |
2564 | 2.99k | SStream_concat0(O, "{"); |
2565 | | |
2566 | 2.99k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
2567 | | |
2568 | 2.99k | if (MI->csh->detail) { |
2569 | 2.99k | #ifndef CAPSTONE_DIET |
2570 | 2.99k | uint8_t access; |
2571 | | |
2572 | 2.99k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2573 | 2.99k | #endif |
2574 | | |
2575 | 2.99k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2576 | 2.99k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2577 | 2.99k | #ifndef CAPSTONE_DIET |
2578 | 2.99k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2579 | 2.99k | #endif |
2580 | 2.99k | MI->flat_insn->detail->arm.op_count++; |
2581 | | |
2582 | 2.99k | #ifndef CAPSTONE_DIET |
2583 | 2.99k | MI->ac_idx++; |
2584 | 2.99k | #endif |
2585 | 2.99k | } |
2586 | | |
2587 | 2.99k | SStream_concat0(O, "}"); |
2588 | 2.99k | } |
2589 | | |
2590 | | static void printVectorListTwo(MCInst *MI, unsigned OpNum, SStream *O) |
2591 | 8.89k | { |
2592 | 8.89k | #ifndef CAPSTONE_DIET |
2593 | 8.89k | uint8_t access; |
2594 | 8.89k | #endif |
2595 | 8.89k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2596 | 8.89k | unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0); |
2597 | 8.89k | unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1); |
2598 | | |
2599 | 8.89k | #ifndef CAPSTONE_DIET |
2600 | 8.89k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2601 | 8.89k | #endif |
2602 | | |
2603 | 8.89k | SStream_concat0(O, "{"); |
2604 | | |
2605 | 8.89k | printRegName(MI->csh, O, Reg0); |
2606 | | |
2607 | 8.89k | if (MI->csh->detail) { |
2608 | 8.89k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2609 | 8.89k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0; |
2610 | 8.89k | #ifndef CAPSTONE_DIET |
2611 | 8.89k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2612 | 8.89k | #endif |
2613 | 8.89k | MI->flat_insn->detail->arm.op_count++; |
2614 | 8.89k | } |
2615 | | |
2616 | 8.89k | SStream_concat0(O, ", "); |
2617 | | |
2618 | 8.89k | printRegName(MI->csh, O, Reg1); |
2619 | | |
2620 | 8.89k | if (MI->csh->detail) { |
2621 | 8.89k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2622 | 8.89k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1; |
2623 | 8.89k | #ifndef CAPSTONE_DIET |
2624 | 8.89k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2625 | 8.89k | #endif |
2626 | 8.89k | MI->flat_insn->detail->arm.op_count++; |
2627 | 8.89k | } |
2628 | | |
2629 | 8.89k | SStream_concat0(O, "}"); |
2630 | | |
2631 | 8.89k | #ifndef CAPSTONE_DIET |
2632 | 8.89k | MI->ac_idx++; |
2633 | 8.89k | #endif |
2634 | 8.89k | } |
2635 | | |
2636 | | static void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum, SStream *O) |
2637 | 4.30k | { |
2638 | 4.30k | #ifndef CAPSTONE_DIET |
2639 | 4.30k | uint8_t access; |
2640 | 4.30k | #endif |
2641 | 4.30k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2642 | 4.30k | unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0); |
2643 | 4.30k | unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2); |
2644 | | |
2645 | 4.30k | #ifndef CAPSTONE_DIET |
2646 | 4.30k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2647 | 4.30k | #endif |
2648 | | |
2649 | 4.30k | SStream_concat0(O, "{"); |
2650 | | |
2651 | 4.30k | printRegName(MI->csh, O, Reg0); |
2652 | | |
2653 | 4.30k | if (MI->csh->detail) { |
2654 | 4.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2655 | 4.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0; |
2656 | 4.30k | #ifndef CAPSTONE_DIET |
2657 | 4.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2658 | 4.30k | #endif |
2659 | 4.30k | MI->flat_insn->detail->arm.op_count++; |
2660 | 4.30k | } |
2661 | | |
2662 | 4.30k | SStream_concat0(O, ", "); |
2663 | | |
2664 | 4.30k | printRegName(MI->csh, O, Reg1); |
2665 | | |
2666 | 4.30k | if (MI->csh->detail) { |
2667 | 4.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2668 | 4.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1; |
2669 | 4.30k | #ifndef CAPSTONE_DIET |
2670 | 4.30k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2671 | 4.30k | #endif |
2672 | 4.30k | MI->flat_insn->detail->arm.op_count++; |
2673 | 4.30k | } |
2674 | | |
2675 | 4.30k | SStream_concat0(O, "}"); |
2676 | | |
2677 | 4.30k | #ifndef CAPSTONE_DIET |
2678 | 4.30k | MI->ac_idx++; |
2679 | 4.30k | #endif |
2680 | 4.30k | } |
2681 | | |
2682 | | static void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O) |
2683 | 3.08k | { |
2684 | 3.08k | #ifndef CAPSTONE_DIET |
2685 | 3.08k | uint8_t access; |
2686 | | |
2687 | 3.08k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2688 | 3.08k | #endif |
2689 | | |
2690 | | // Normally, it's not safe to use register enum values directly with |
2691 | | // addition to get the next register, but for VFP registers, the |
2692 | | // sort order is guaranteed because they're all of the form D<n>. |
2693 | 3.08k | SStream_concat0(O, "{"); |
2694 | | |
2695 | 3.08k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
2696 | | |
2697 | 3.08k | if (MI->csh->detail) { |
2698 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2699 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2700 | 3.08k | #ifndef CAPSTONE_DIET |
2701 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2702 | 3.08k | #endif |
2703 | 3.08k | MI->flat_insn->detail->arm.op_count++; |
2704 | 3.08k | } |
2705 | | |
2706 | 3.08k | SStream_concat0(O, ", "); |
2707 | | |
2708 | 3.08k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1); |
2709 | | |
2710 | 3.08k | if (MI->csh->detail) { |
2711 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2712 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1; |
2713 | 3.08k | #ifndef CAPSTONE_DIET |
2714 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2715 | 3.08k | #endif |
2716 | 3.08k | MI->flat_insn->detail->arm.op_count++; |
2717 | 3.08k | } |
2718 | | |
2719 | 3.08k | SStream_concat0(O, ", "); |
2720 | | |
2721 | 3.08k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
2722 | | |
2723 | 3.08k | if (MI->csh->detail) { |
2724 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2725 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
2726 | 3.08k | #ifndef CAPSTONE_DIET |
2727 | 3.08k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2728 | 3.08k | #endif |
2729 | 3.08k | MI->flat_insn->detail->arm.op_count++; |
2730 | 3.08k | } |
2731 | | |
2732 | 3.08k | SStream_concat0(O, "}"); |
2733 | | |
2734 | 3.08k | #ifndef CAPSTONE_DIET |
2735 | 3.08k | MI->ac_idx++; |
2736 | 3.08k | #endif |
2737 | 3.08k | } |
2738 | | |
2739 | | static void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O) |
2740 | 6.25k | { |
2741 | 6.25k | #ifndef CAPSTONE_DIET |
2742 | 6.25k | uint8_t access; |
2743 | | |
2744 | 6.25k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2745 | 6.25k | #endif |
2746 | | |
2747 | | // Normally, it's not safe to use register enum values directly with |
2748 | | // addition to get the next register, but for VFP registers, the |
2749 | | // sort order is guaranteed because they're all of the form D<n>. |
2750 | 6.25k | SStream_concat0(O, "{"); |
2751 | | |
2752 | 6.25k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
2753 | | |
2754 | 6.25k | if (MI->csh->detail) { |
2755 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2756 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2757 | 6.25k | #ifndef CAPSTONE_DIET |
2758 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2759 | 6.25k | #endif |
2760 | 6.25k | MI->flat_insn->detail->arm.op_count++; |
2761 | 6.25k | } |
2762 | | |
2763 | 6.25k | SStream_concat0(O, ", "); |
2764 | | |
2765 | 6.25k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1); |
2766 | | |
2767 | 6.25k | if (MI->csh->detail) { |
2768 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2769 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1; |
2770 | 6.25k | #ifndef CAPSTONE_DIET |
2771 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2772 | 6.25k | #endif |
2773 | 6.25k | MI->flat_insn->detail->arm.op_count++; |
2774 | 6.25k | } |
2775 | | |
2776 | 6.25k | SStream_concat0(O, ", "); |
2777 | | |
2778 | 6.25k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
2779 | | |
2780 | 6.25k | if (MI->csh->detail) { |
2781 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2782 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
2783 | 6.25k | #ifndef CAPSTONE_DIET |
2784 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2785 | 6.25k | #endif |
2786 | 6.25k | MI->flat_insn->detail->arm.op_count++; |
2787 | 6.25k | } |
2788 | | |
2789 | 6.25k | SStream_concat0(O, ", "); |
2790 | | |
2791 | 6.25k | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3); |
2792 | | |
2793 | 6.25k | if (MI->csh->detail) { |
2794 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2795 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3; |
2796 | 6.25k | #ifndef CAPSTONE_DIET |
2797 | 6.25k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2798 | 6.25k | #endif |
2799 | 6.25k | MI->flat_insn->detail->arm.op_count++; |
2800 | 6.25k | } |
2801 | | |
2802 | 6.25k | SStream_concat0(O, "}"); |
2803 | | |
2804 | 6.25k | #ifndef CAPSTONE_DIET |
2805 | 6.25k | MI->ac_idx++; |
2806 | 6.25k | #endif |
2807 | 6.25k | } |
2808 | | |
2809 | | static void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum, SStream *O) |
2810 | 226 | { |
2811 | 226 | #ifndef CAPSTONE_DIET |
2812 | 226 | uint8_t access; |
2813 | | |
2814 | 226 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2815 | 226 | #endif |
2816 | | |
2817 | 226 | SStream_concat0(O, "{"); |
2818 | | |
2819 | 226 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
2820 | | |
2821 | 226 | if (MI->csh->detail) { |
2822 | 226 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2823 | 226 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2824 | 226 | #ifndef CAPSTONE_DIET |
2825 | 226 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2826 | 226 | #endif |
2827 | 226 | MI->flat_insn->detail->arm.op_count++; |
2828 | 226 | } |
2829 | | |
2830 | 226 | SStream_concat0(O, "[]}"); |
2831 | | |
2832 | 226 | #ifndef CAPSTONE_DIET |
2833 | 226 | MI->ac_idx++; |
2834 | 226 | #endif |
2835 | 226 | } |
2836 | | |
2837 | | static void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum, SStream *O) |
2838 | 1.40k | { |
2839 | 1.40k | #ifndef CAPSTONE_DIET |
2840 | 1.40k | uint8_t access; |
2841 | 1.40k | #endif |
2842 | 1.40k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2843 | 1.40k | unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0); |
2844 | 1.40k | unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1); |
2845 | | |
2846 | 1.40k | #ifndef CAPSTONE_DIET |
2847 | 1.40k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2848 | 1.40k | #endif |
2849 | | |
2850 | 1.40k | SStream_concat0(O, "{"); |
2851 | | |
2852 | 1.40k | printRegName(MI->csh, O, Reg0); |
2853 | | |
2854 | 1.40k | if (MI->csh->detail) { |
2855 | 1.40k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2856 | 1.40k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0; |
2857 | 1.40k | #ifndef CAPSTONE_DIET |
2858 | 1.40k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2859 | 1.40k | #endif |
2860 | 1.40k | MI->flat_insn->detail->arm.op_count++; |
2861 | 1.40k | } |
2862 | | |
2863 | 1.40k | SStream_concat0(O, "[], "); |
2864 | | |
2865 | 1.40k | printRegName(MI->csh, O, Reg1); |
2866 | | |
2867 | 1.40k | if (MI->csh->detail) { |
2868 | 1.40k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2869 | 1.40k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1; |
2870 | 1.40k | #ifndef CAPSTONE_DIET |
2871 | 1.40k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2872 | 1.40k | #endif |
2873 | 1.40k | MI->flat_insn->detail->arm.op_count++; |
2874 | 1.40k | } |
2875 | | |
2876 | 1.40k | SStream_concat0(O, "[]}"); |
2877 | | |
2878 | 1.40k | #ifndef CAPSTONE_DIET |
2879 | 1.40k | MI->ac_idx++; |
2880 | 1.40k | #endif |
2881 | 1.40k | } |
2882 | | |
2883 | | static void printVectorListThreeAllLanes(MCInst *MI, unsigned OpNum, SStream *O) |
2884 | 0 | { |
2885 | 0 | #ifndef CAPSTONE_DIET |
2886 | 0 | uint8_t access; |
2887 | |
|
2888 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2889 | 0 | #endif |
2890 | | |
2891 | | // Normally, it's not safe to use register enum values directly with |
2892 | | // addition to get the next register, but for VFP registers, the |
2893 | | // sort order is guaranteed because they're all of the form D<n>. |
2894 | 0 | SStream_concat0(O, "{"); |
2895 | |
|
2896 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
2897 | |
|
2898 | 0 | if (MI->csh->detail) { |
2899 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2900 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2901 | 0 | #ifndef CAPSTONE_DIET |
2902 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2903 | 0 | #endif |
2904 | 0 | MI->flat_insn->detail->arm.op_count++; |
2905 | 0 | } |
2906 | |
|
2907 | 0 | SStream_concat0(O, "[], "); |
2908 | |
|
2909 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1); |
2910 | |
|
2911 | 0 | if (MI->csh->detail) { |
2912 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2913 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1; |
2914 | 0 | #ifndef CAPSTONE_DIET |
2915 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2916 | 0 | #endif |
2917 | 0 | MI->flat_insn->detail->arm.op_count++; |
2918 | 0 | } |
2919 | |
|
2920 | 0 | SStream_concat0(O, "[], "); |
2921 | |
|
2922 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
2923 | |
|
2924 | 0 | if (MI->csh->detail) { |
2925 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2926 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
2927 | 0 | #ifndef CAPSTONE_DIET |
2928 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2929 | 0 | #endif |
2930 | 0 | MI->flat_insn->detail->arm.op_count++; |
2931 | 0 | } |
2932 | |
|
2933 | 0 | SStream_concat0(O, "[]}"); |
2934 | |
|
2935 | 0 | #ifndef CAPSTONE_DIET |
2936 | 0 | MI->ac_idx++; |
2937 | 0 | #endif |
2938 | 0 | } |
2939 | | |
2940 | | static void printVectorListFourAllLanes(MCInst *MI, unsigned OpNum, SStream *O) |
2941 | 0 | { |
2942 | 0 | #ifndef CAPSTONE_DIET |
2943 | 0 | uint8_t access; |
2944 | |
|
2945 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
2946 | 0 | #endif |
2947 | | |
2948 | | // Normally, it's not safe to use register enum values directly with |
2949 | | // addition to get the next register, but for VFP registers, the |
2950 | | // sort order is guaranteed because they're all of the form D<n>. |
2951 | 0 | SStream_concat0(O, "{"); |
2952 | |
|
2953 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
2954 | |
|
2955 | 0 | if (MI->csh->detail) { |
2956 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2957 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
2958 | 0 | #ifndef CAPSTONE_DIET |
2959 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2960 | 0 | #endif |
2961 | 0 | MI->flat_insn->detail->arm.op_count++; |
2962 | 0 | } |
2963 | |
|
2964 | 0 | SStream_concat0(O, "[], "); |
2965 | |
|
2966 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1); |
2967 | |
|
2968 | 0 | if (MI->csh->detail) { |
2969 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2970 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 1; |
2971 | 0 | #ifndef CAPSTONE_DIET |
2972 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2973 | 0 | #endif |
2974 | 0 | MI->flat_insn->detail->arm.op_count++; |
2975 | 0 | } |
2976 | |
|
2977 | 0 | SStream_concat0(O, "[], "); |
2978 | |
|
2979 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
2980 | |
|
2981 | 0 | if (MI->csh->detail) { |
2982 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2983 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
2984 | 0 | #ifndef CAPSTONE_DIET |
2985 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2986 | 0 | #endif |
2987 | 0 | MI->flat_insn->detail->arm.op_count++; |
2988 | 0 | } |
2989 | |
|
2990 | 0 | SStream_concat0(O, "[], "); |
2991 | |
|
2992 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3); |
2993 | |
|
2994 | 0 | if (MI->csh->detail) { |
2995 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
2996 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 3; |
2997 | 0 | #ifndef CAPSTONE_DIET |
2998 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
2999 | 0 | #endif |
3000 | 0 | MI->flat_insn->detail->arm.op_count++; |
3001 | 0 | } |
3002 | |
|
3003 | 0 | SStream_concat0(O, "[]}"); |
3004 | |
|
3005 | 0 | #ifndef CAPSTONE_DIET |
3006 | 0 | MI->ac_idx++; |
3007 | 0 | #endif |
3008 | 0 | } |
3009 | | |
3010 | | static void printVectorListTwoSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O) |
3011 | 1.14k | { |
3012 | 1.14k | #ifndef CAPSTONE_DIET |
3013 | 1.14k | uint8_t access; |
3014 | 1.14k | #endif |
3015 | 1.14k | unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
3016 | 1.14k | unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0); |
3017 | 1.14k | unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2); |
3018 | | |
3019 | 1.14k | #ifndef CAPSTONE_DIET |
3020 | 1.14k | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
3021 | 1.14k | #endif |
3022 | | |
3023 | 1.14k | SStream_concat0(O, "{"); |
3024 | | |
3025 | 1.14k | printRegName(MI->csh, O, Reg0); |
3026 | | |
3027 | 1.14k | if (MI->csh->detail) { |
3028 | 1.14k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3029 | 1.14k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg0; |
3030 | 1.14k | #ifndef CAPSTONE_DIET |
3031 | 1.14k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3032 | 1.14k | #endif |
3033 | 1.14k | MI->flat_insn->detail->arm.op_count++; |
3034 | 1.14k | } |
3035 | | |
3036 | 1.14k | SStream_concat0(O, "[], "); |
3037 | | |
3038 | 1.14k | printRegName(MI->csh, O, Reg1); |
3039 | | |
3040 | 1.14k | if (MI->csh->detail) { |
3041 | 1.14k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3042 | 1.14k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = Reg1; |
3043 | 1.14k | #ifndef CAPSTONE_DIET |
3044 | 1.14k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3045 | 1.14k | #endif |
3046 | 1.14k | MI->flat_insn->detail->arm.op_count++; |
3047 | 1.14k | } |
3048 | | |
3049 | 1.14k | SStream_concat0(O, "[]}"); |
3050 | | |
3051 | 1.14k | #ifndef CAPSTONE_DIET |
3052 | 1.14k | MI->ac_idx++; |
3053 | 1.14k | #endif |
3054 | 1.14k | } |
3055 | | |
3056 | | static void printVectorListThreeSpacedAllLanes(MCInst *MI, |
3057 | | unsigned OpNum, SStream *O) |
3058 | 0 | { |
3059 | 0 | #ifndef CAPSTONE_DIET |
3060 | 0 | uint8_t access; |
3061 | |
|
3062 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
3063 | 0 | #endif |
3064 | | |
3065 | | // Normally, it's not safe to use register enum values directly with |
3066 | | // addition to get the next register, but for VFP registers, the |
3067 | | // sort order is guaranteed because they're all of the form D<n>. |
3068 | 0 | SStream_concat0(O, "{"); |
3069 | |
|
3070 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
3071 | |
|
3072 | 0 | if (MI->csh->detail) { |
3073 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3074 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
3075 | 0 | #ifndef CAPSTONE_DIET |
3076 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3077 | 0 | #endif |
3078 | 0 | MI->flat_insn->detail->arm.op_count++; |
3079 | 0 | } |
3080 | |
|
3081 | 0 | SStream_concat0(O, "[], "); |
3082 | |
|
3083 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
3084 | |
|
3085 | 0 | if (MI->csh->detail) { |
3086 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3087 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
3088 | 0 | #ifndef CAPSTONE_DIET |
3089 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3090 | 0 | #endif |
3091 | 0 | MI->flat_insn->detail->arm.op_count++; |
3092 | 0 | } |
3093 | |
|
3094 | 0 | SStream_concat0(O, "[], "); |
3095 | |
|
3096 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4); |
3097 | |
|
3098 | 0 | if (MI->csh->detail) { |
3099 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3100 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4; |
3101 | 0 | #ifndef CAPSTONE_DIET |
3102 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3103 | 0 | #endif |
3104 | 0 | MI->flat_insn->detail->arm.op_count++; |
3105 | 0 | } |
3106 | |
|
3107 | 0 | SStream_concat0(O, "[]}"); |
3108 | |
|
3109 | 0 | #ifndef CAPSTONE_DIET |
3110 | 0 | MI->ac_idx++; |
3111 | 0 | #endif |
3112 | 0 | } |
3113 | | |
3114 | | static void printVectorListFourSpacedAllLanes(MCInst *MI, |
3115 | | unsigned OpNum, SStream *O) |
3116 | 0 | { |
3117 | 0 | #ifndef CAPSTONE_DIET |
3118 | 0 | uint8_t access; |
3119 | |
|
3120 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
3121 | 0 | #endif |
3122 | | |
3123 | | // Normally, it's not safe to use register enum values directly with |
3124 | | // addition to get the next register, but for VFP registers, the |
3125 | | // sort order is guaranteed because they're all of the form D<n>. |
3126 | 0 | SStream_concat0(O, "{"); |
3127 | |
|
3128 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
3129 | |
|
3130 | 0 | if (MI->csh->detail) { |
3131 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3132 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
3133 | 0 | #ifndef CAPSTONE_DIET |
3134 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3135 | 0 | #endif |
3136 | 0 | MI->flat_insn->detail->arm.op_count++; |
3137 | 0 | } |
3138 | |
|
3139 | 0 | SStream_concat0(O, "[], "); |
3140 | |
|
3141 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
3142 | |
|
3143 | 0 | if (MI->csh->detail) { |
3144 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3145 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
3146 | 0 | #ifndef CAPSTONE_DIET |
3147 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3148 | 0 | #endif |
3149 | 0 | MI->flat_insn->detail->arm.op_count++; |
3150 | 0 | } |
3151 | |
|
3152 | 0 | SStream_concat0(O, "[], "); |
3153 | |
|
3154 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4); |
3155 | |
|
3156 | 0 | if (MI->csh->detail) { |
3157 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3158 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4; |
3159 | 0 | #ifndef CAPSTONE_DIET |
3160 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3161 | 0 | #endif |
3162 | 0 | MI->flat_insn->detail->arm.op_count++; |
3163 | 0 | } |
3164 | |
|
3165 | 0 | SStream_concat0(O, "[], "); |
3166 | |
|
3167 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6); |
3168 | |
|
3169 | 0 | if (MI->csh->detail) { |
3170 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3171 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6; |
3172 | 0 | #ifndef CAPSTONE_DIET |
3173 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3174 | 0 | #endif |
3175 | 0 | MI->flat_insn->detail->arm.op_count++; |
3176 | 0 | } |
3177 | |
|
3178 | 0 | SStream_concat0(O, "[]}"); |
3179 | |
|
3180 | 0 | #ifndef CAPSTONE_DIET |
3181 | 0 | MI->ac_idx++; |
3182 | 0 | #endif |
3183 | 0 | } |
3184 | | |
3185 | | static void printVectorListThreeSpaced(MCInst *MI, unsigned OpNum, SStream *O) |
3186 | 0 | { |
3187 | 0 | #ifndef CAPSTONE_DIET |
3188 | 0 | uint8_t access; |
3189 | |
|
3190 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
3191 | 0 | #endif |
3192 | | |
3193 | | // Normally, it's not safe to use register enum values directly with |
3194 | | // addition to get the next register, but for VFP registers, the |
3195 | | // sort order is guaranteed because they're all of the form D<n>. |
3196 | 0 | SStream_concat0(O, "{"); |
3197 | |
|
3198 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
3199 | |
|
3200 | 0 | if (MI->csh->detail) { |
3201 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3202 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
3203 | 0 | #ifndef CAPSTONE_DIET |
3204 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3205 | 0 | #endif |
3206 | 0 | MI->flat_insn->detail->arm.op_count++; |
3207 | 0 | } |
3208 | |
|
3209 | 0 | SStream_concat0(O, ", "); |
3210 | |
|
3211 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
3212 | |
|
3213 | 0 | if (MI->csh->detail) { |
3214 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3215 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
3216 | 0 | #ifndef CAPSTONE_DIET |
3217 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3218 | 0 | #endif |
3219 | 0 | MI->flat_insn->detail->arm.op_count++; |
3220 | 0 | } |
3221 | |
|
3222 | 0 | SStream_concat0(O, ", "); |
3223 | |
|
3224 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4); |
3225 | |
|
3226 | 0 | if (MI->csh->detail) { |
3227 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3228 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4; |
3229 | 0 | #ifndef CAPSTONE_DIET |
3230 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3231 | 0 | #endif |
3232 | 0 | MI->flat_insn->detail->arm.op_count++; |
3233 | 0 | } |
3234 | |
|
3235 | 0 | SStream_concat0(O, "}"); |
3236 | |
|
3237 | 0 | #ifndef CAPSTONE_DIET |
3238 | 0 | MI->ac_idx++; |
3239 | 0 | #endif |
3240 | 0 | } |
3241 | | |
3242 | | static void printVectorListFourSpaced(MCInst *MI, unsigned OpNum, SStream *O) |
3243 | 0 | { |
3244 | 0 | #ifndef CAPSTONE_DIET |
3245 | 0 | uint8_t access; |
3246 | |
|
3247 | 0 | access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx); |
3248 | 0 | #endif |
3249 | | |
3250 | | // Normally, it's not safe to use register enum values directly with |
3251 | | // addition to get the next register, but for VFP registers, the |
3252 | | // sort order is guaranteed because they're all of the form D<n>. |
3253 | 0 | SStream_concat0(O, "{"); |
3254 | |
|
3255 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum))); |
3256 | |
|
3257 | 0 | if (MI->csh->detail) { |
3258 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3259 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)); |
3260 | 0 | #ifndef CAPSTONE_DIET |
3261 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3262 | 0 | #endif |
3263 | 0 | MI->flat_insn->detail->arm.op_count++; |
3264 | 0 | } |
3265 | |
|
3266 | 0 | SStream_concat0(O, ", "); |
3267 | |
|
3268 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2); |
3269 | |
|
3270 | 0 | if (MI->csh->detail) { |
3271 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3272 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 2; |
3273 | 0 | #ifndef CAPSTONE_DIET |
3274 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3275 | 0 | #endif |
3276 | 0 | MI->flat_insn->detail->arm.op_count++; |
3277 | 0 | } |
3278 | |
|
3279 | 0 | SStream_concat0(O, ", "); |
3280 | |
|
3281 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4); |
3282 | |
|
3283 | 0 | if (MI->csh->detail) { |
3284 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3285 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 4; |
3286 | 0 | #ifndef CAPSTONE_DIET |
3287 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3288 | 0 | #endif |
3289 | 0 | MI->flat_insn->detail->arm.op_count++; |
3290 | 0 | } |
3291 | |
|
3292 | 0 | SStream_concat0(O, ", "); |
3293 | |
|
3294 | 0 | printRegName(MI->csh, O, MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6); |
3295 | |
|
3296 | 0 | if (MI->csh->detail) { |
3297 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3298 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) + 6; |
3299 | 0 | #ifndef CAPSTONE_DIET |
3300 | 0 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].access = access; |
3301 | 0 | #endif |
3302 | 0 | MI->flat_insn->detail->arm.op_count++; |
3303 | 0 | } |
3304 | |
|
3305 | 0 | SStream_concat0(O, "}"); |
3306 | |
|
3307 | 0 | #ifndef CAPSTONE_DIET |
3308 | 0 | MI->ac_idx++; |
3309 | 0 | #endif |
3310 | 0 | } |
3311 | | |
3312 | | static void printComplexRotationOp(MCInst *MI, unsigned OpNo, SStream *O, int64_t Angle, int64_t Remainder) |
3313 | 349 | { |
3314 | 349 | unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNo)); |
3315 | 349 | unsigned tmp = (unsigned)((Val * Angle) + Remainder); |
3316 | | |
3317 | 349 | printUInt32Bang(O, tmp); |
3318 | 349 | if (MI->csh->detail) { |
3319 | 349 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_IMM; |
3320 | 349 | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].imm = tmp; |
3321 | 349 | MI->flat_insn->detail->arm.op_count++; |
3322 | 349 | } |
3323 | 349 | } |
3324 | | |
3325 | | void ARM_addVectorDataType(MCInst *MI, arm_vectordata_type vd) |
3326 | 22.6k | { |
3327 | 22.6k | if (MI->csh->detail) { |
3328 | 22.6k | MI->flat_insn->detail->arm.vector_data = vd; |
3329 | 22.6k | } |
3330 | 22.6k | } |
3331 | | |
3332 | | void ARM_addVectorDataSize(MCInst *MI, int size) |
3333 | 53.3k | { |
3334 | 53.3k | if (MI->csh->detail) { |
3335 | 53.3k | MI->flat_insn->detail->arm.vector_size = size; |
3336 | 53.3k | } |
3337 | 53.3k | } |
3338 | | |
3339 | | void ARM_addReg(MCInst *MI, int reg) |
3340 | 5.15k | { |
3341 | 5.15k | if (MI->csh->detail) { |
3342 | 5.15k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_REG; |
3343 | 5.15k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = reg; |
3344 | 5.15k | MI->flat_insn->detail->arm.op_count++; |
3345 | 5.15k | } |
3346 | 5.15k | } |
3347 | | |
3348 | | void ARM_addUserMode(MCInst *MI) |
3349 | 8.01k | { |
3350 | 8.01k | if (MI->csh->detail) { |
3351 | 8.01k | MI->flat_insn->detail->arm.usermode = true; |
3352 | 8.01k | } |
3353 | 8.01k | } |
3354 | | |
3355 | | void ARM_addSysReg(MCInst *MI, arm_sysreg reg) |
3356 | 7.62k | { |
3357 | 7.62k | if (MI->csh->detail) { |
3358 | 7.62k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].type = ARM_OP_SYSREG; |
3359 | 7.62k | MI->flat_insn->detail->arm.operands[MI->flat_insn->detail->arm.op_count].reg = reg; |
3360 | 7.62k | MI->flat_insn->detail->arm.op_count++; |
3361 | 7.62k | } |
3362 | 7.62k | } |
3363 | | |
3364 | | #endif |