/src/capstonenext/arch/Xtensa/XtensaInstPrinter.c
Line | Count | Source |
1 | | /* Capstone Disassembly Engine, http://www.capstone-engine.org */ |
2 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */ |
3 | | /* Rot127 <unisono@quyllur.org> 2022-2023 */ |
4 | | /* Automatically translated source file from LLVM. */ |
5 | | |
6 | | /* LLVM-commit: <commit> */ |
7 | | /* LLVM-tag: <tag> */ |
8 | | |
9 | | /* Only small edits allowed. */ |
10 | | /* For multiple similar edits, please create a Patch for the translator. */ |
11 | | |
12 | | /* Capstone's C++ file translator: */ |
13 | | /* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */ |
14 | | |
15 | | //===- XtensaInstPrinter.cpp - Convert Xtensa MCInst to asm syntax --------===// |
16 | | // |
17 | | // The LLVM Compiler Infrastructure |
18 | | // |
19 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
20 | | // See https://llvm.org/LICENSE.txt for license information. |
21 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
22 | | // |
23 | | //===----------------------------------------------------------------------===// |
24 | | // |
25 | | // This class prints an Xtensa MCInst to a .s file. |
26 | | // |
27 | | //===----------------------------------------------------------------------===// |
28 | | |
29 | | #include <stdio.h> |
30 | | #include <string.h> |
31 | | #include <stdlib.h> |
32 | | #include <capstone/platform.h> |
33 | | |
34 | | #include "../../MCInstPrinter.h" |
35 | | #include "../../SStream.h" |
36 | | #include "./priv.h" |
37 | | #include "../../Mapping.h" |
38 | | |
39 | | #include "XtensaMapping.h" |
40 | | #include "../../MathExtras.h" |
41 | | |
42 | | #define CONCAT(a, b) CONCAT_(a, b) |
43 | | #define CONCAT_(a, b) a##_##b |
44 | | |
45 | | #define DEBUG_TYPE "asm-printer" |
46 | | static MnemonicBitsInfo getMnemonic(MCInst *MI, SStream *O); |
47 | | static const char *getRegisterName(unsigned RegNo); |
48 | | |
49 | | typedef MCRegister Register; |
50 | | |
51 | | static void printRegName(SStream *O, MCRegister Reg) |
52 | 233 | { |
53 | 233 | SStream_concat0(O, getRegisterName(Reg)); |
54 | 233 | } |
55 | | |
56 | | static void printOp(MCInst *MI, MCOperand *MC, SStream *O) |
57 | 235k | { |
58 | 235k | if (MCOperand_isReg(MC)) |
59 | 220k | SStream_concat0(O, getRegisterName(MCOperand_getReg(MC))); |
60 | 15.5k | else if (MCOperand_isImm(MC)) |
61 | 15.5k | printInt64(O, MCOperand_getImm(MC)); |
62 | 0 | else if (MCOperand_isExpr(MC)) |
63 | 0 | printExpr(MCOperand_getExpr(MC), O); |
64 | 0 | else |
65 | 0 | CS_ASSERT(0 && "Invalid operand"); |
66 | 235k | } |
67 | | |
68 | | static void printOperand(MCInst *MI, const int op_num, SStream *O) |
69 | 220k | { |
70 | 220k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Operand, op_num); |
71 | 220k | printOp(MI, MCInst_getOperand(MI, op_num), O); |
72 | 220k | } |
73 | | |
74 | | static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS) |
75 | 15.5k | { |
76 | 15.5k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum); |
77 | 15.5k | SStream_concat0(OS, getRegisterName(MCOperand_getReg( |
78 | 15.5k | MCInst_getOperand(MI, (OpNum))))); |
79 | 15.5k | SStream_concat0(OS, ", "); |
80 | 15.5k | printOp(MI, MCInst_getOperand(MI, OpNum + 1), OS); |
81 | 15.5k | } |
82 | | |
83 | | static inline void printBranchTarget(MCInst *MI, int OpNum, SStream *OS) |
84 | 21.5k | { |
85 | 21.5k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_BranchTarget, OpNum); |
86 | 21.5k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
87 | 21.5k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
88 | 21.5k | int64_t Val = MCOperand_getImm(MC) + 4; |
89 | 21.5k | SStream_concat0(OS, ". "); |
90 | 21.5k | if (Val > 0) |
91 | 12.2k | SStream_concat0(OS, "+"); |
92 | | |
93 | 21.5k | printInt64(OS, Val); |
94 | 21.5k | } else if (MCOperand_isExpr(MC)) |
95 | 0 | CS_ASSERT_RET(0 && "unimplemented expr printing"); |
96 | 0 | else |
97 | 0 | CS_ASSERT(0 && "Invalid operand"); |
98 | 21.5k | } |
99 | | |
100 | | static inline void printLoopTarget(MCInst *MI, int OpNum, SStream *OS) |
101 | 128 | { |
102 | 128 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_LoopTarget, OpNum); |
103 | 128 | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
104 | 128 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
105 | 128 | int64_t Val = MCOperand_getImm(MC) + 4; |
106 | 128 | SStream_concat0(OS, ". "); |
107 | 128 | if (Val > 0) |
108 | 128 | SStream_concat0(OS, "+"); |
109 | | |
110 | 128 | printInt64(OS, Val); |
111 | 128 | } else if (MCOperand_isExpr(MC)) |
112 | 0 | CS_ASSERT_RET(0 && "unimplemented expr printing"); |
113 | 0 | else |
114 | 0 | CS_ASSERT(0 && "Invalid operand"); |
115 | 128 | } |
116 | | |
117 | | static inline void printJumpTarget(MCInst *MI, int OpNum, SStream *OS) |
118 | 1.34k | { |
119 | 1.34k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_JumpTarget, OpNum); |
120 | 1.34k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
121 | 1.34k | if (MCOperand_isImm(MC)) { |
122 | 1.34k | int64_t Val = MCOperand_getImm(MC) + 4; |
123 | 1.34k | SStream_concat0(OS, ". "); |
124 | 1.34k | if (Val > 0) |
125 | 800 | SStream_concat0(OS, "+"); |
126 | | |
127 | 1.34k | printInt64(OS, Val); |
128 | 1.34k | } else if (MCOperand_isExpr(MC)) |
129 | 0 | CS_ASSERT_RET(0 && "unimplemented expr printing"); |
130 | 0 | else |
131 | 0 | CS_ASSERT(0 && "Invalid operand"); |
132 | 1.34k | ; |
133 | 1.34k | } |
134 | | |
135 | | static inline void printCallOperand(MCInst *MI, int OpNum, SStream *OS) |
136 | 3.90k | { |
137 | 3.90k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_CallOperand, OpNum); |
138 | 3.90k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
139 | 3.90k | if (MCOperand_isImm(MC)) { |
140 | 3.90k | int64_t Val = MCOperand_getImm(MC) + 4; |
141 | 3.90k | SStream_concat0(OS, ". "); |
142 | 3.90k | if (Val > 0) |
143 | 2.26k | SStream_concat0(OS, "+"); |
144 | | |
145 | 3.90k | printInt64(OS, Val); |
146 | 3.90k | } else if (MCOperand_isExpr(MC)) |
147 | 0 | CS_ASSERT_RET(0 && "unimplemented expr printing"); |
148 | 0 | else |
149 | 0 | CS_ASSERT(0 && "Invalid operand"); |
150 | 3.90k | } |
151 | | |
152 | | static inline void printL32RTarget(MCInst *MI, int OpNum, SStream *O) |
153 | 7.06k | { |
154 | 7.06k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_L32RTarget, OpNum); |
155 | 7.06k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
156 | 7.06k | if (MCOperand_isImm(MC)) { |
157 | 7.06k | SStream_concat0(O, ". "); |
158 | 7.06k | printInt64(O, Xtensa_L32R_Value(MI, OpNum)); |
159 | 7.06k | } else if (MCOperand_isExpr(MC)) |
160 | 0 | CS_ASSERT_RET(0 && "unimplemented expr printing"); |
161 | 0 | else |
162 | 0 | CS_ASSERT(0 && "Invalid operand"); |
163 | 7.06k | } |
164 | | |
165 | | static inline void printImm8_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
166 | 286 | { |
167 | 286 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_AsmOperand, OpNum); |
168 | 286 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
169 | 286 | int64_t Value = |
170 | 286 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
171 | 286 | CS_ASSERT_RET( |
172 | 286 | isIntN(8, Value) && |
173 | 286 | "Invalid argument, value must be in ranges [-128,127]"); |
174 | 286 | printInt64(O, Value); |
175 | 286 | } else { |
176 | 0 | printOperand(MI, OpNum, O); |
177 | 0 | } |
178 | 286 | } |
179 | | |
180 | | static inline void printImm8_sh8_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
181 | 322 | { |
182 | 322 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_sh8_AsmOperand, OpNum); |
183 | 322 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
184 | 322 | int64_t Value = |
185 | 322 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
186 | 322 | CS_ASSERT_RET( |
187 | 322 | (isIntN(16, Value) && ((Value & 0xFF) == 0)) && |
188 | 322 | "Invalid argument, value must be multiples of 256 in range " |
189 | 322 | "[-32768,32512]"); |
190 | 322 | printInt64(O, Value); |
191 | 322 | } else |
192 | 0 | printOperand(MI, OpNum, O); |
193 | 322 | } |
194 | | |
195 | | static inline void printImm12_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
196 | 0 | { |
197 | 0 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12_AsmOperand, OpNum); |
198 | 0 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
199 | 0 | int64_t Value = |
200 | 0 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
201 | 0 | CS_ASSERT_RET( |
202 | 0 | (Value >= -2048 && Value <= 2047) && |
203 | 0 | "Invalid argument, value must be in ranges [-2048,2047]"); |
204 | 0 | printInt64(O, Value); |
205 | 0 | } else |
206 | 0 | printOperand(MI, OpNum, O); |
207 | 0 | } |
208 | | |
209 | | static inline void printImm12m_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
210 | 318 | { |
211 | 318 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12m_AsmOperand, OpNum); |
212 | 318 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
213 | 318 | int64_t Value = |
214 | 318 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
215 | 318 | CS_ASSERT_RET( |
216 | 318 | (Value >= -2048 && Value <= 2047) && |
217 | 318 | "Invalid argument, value must be in ranges [-2048,2047]"); |
218 | 318 | printInt64(O, Value); |
219 | 318 | } else |
220 | 0 | printOperand(MI, OpNum, O); |
221 | 318 | } |
222 | | |
223 | | static inline void printUimm4_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
224 | 3.49k | { |
225 | 3.49k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm4_AsmOperand, OpNum); |
226 | 3.49k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
227 | 3.49k | int64_t Value = |
228 | 3.49k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
229 | 3.49k | CS_ASSERT_RET((Value >= 0 && Value <= 15) && |
230 | 3.49k | "Invalid argument"); |
231 | 3.49k | printInt64(O, Value); |
232 | 3.49k | } else |
233 | 0 | printOperand(MI, OpNum, O); |
234 | 3.49k | } |
235 | | |
236 | | static inline void printUimm5_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
237 | 3.90k | { |
238 | 3.90k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm5_AsmOperand, OpNum); |
239 | 3.90k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
240 | 3.90k | int64_t Value = |
241 | 3.90k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
242 | 3.90k | CS_ASSERT_RET((Value >= 0 && Value <= 31) && |
243 | 3.90k | "Invalid argument"); |
244 | 3.90k | printInt64(O, Value); |
245 | 3.90k | } else |
246 | 0 | printOperand(MI, OpNum, O); |
247 | 3.90k | } |
248 | | |
249 | | static inline void printShimm1_31_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
250 | 0 | { |
251 | 0 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm1_31_AsmOperand, OpNum); |
252 | 0 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
253 | 0 | int64_t Value = |
254 | 0 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
255 | 0 | CS_ASSERT_RET( |
256 | 0 | (Value >= 1 && Value <= 31) && |
257 | 0 | "Invalid argument, value must be in range [1,31]"); |
258 | 0 | printInt64(O, Value); |
259 | 0 | } else |
260 | 0 | printOperand(MI, OpNum, O); |
261 | 0 | } |
262 | | |
263 | | static inline void printShimm0_31_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
264 | 693 | { |
265 | 693 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm0_31_AsmOperand, OpNum); |
266 | 693 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
267 | 693 | int64_t Value = |
268 | 693 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
269 | 693 | CS_ASSERT_RET( |
270 | 693 | (Value >= 0 && Value <= 31) && |
271 | 693 | "Invalid argument, value must be in range [0,31]"); |
272 | 410 | printInt64(O, Value); |
273 | 410 | } else |
274 | 0 | printOperand(MI, OpNum, O); |
275 | 693 | } |
276 | | |
277 | | static inline void printImm1_16_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
278 | 1.57k | { |
279 | 1.57k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1_16_AsmOperand, OpNum); |
280 | 1.57k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
281 | 1.57k | int64_t Value = |
282 | 1.57k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
283 | 1.57k | CS_ASSERT_RET( |
284 | 1.57k | (Value >= 1 && Value <= 16) && |
285 | 1.57k | "Invalid argument, value must be in range [1,16]"); |
286 | 1.57k | printInt64(O, Value); |
287 | 1.57k | } else |
288 | 0 | printOperand(MI, OpNum, O); |
289 | 1.57k | } |
290 | | |
291 | | static inline void printImm1n_15_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
292 | 3.41k | { |
293 | 3.41k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1n_15_AsmOperand, OpNum); |
294 | 3.41k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
295 | 3.41k | int64_t Value = |
296 | 3.41k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
297 | 3.41k | CS_ASSERT_RET( |
298 | 3.41k | (Value >= -1 && (Value != 0) && Value <= 15) && |
299 | 3.41k | "Invalid argument, value must be in ranges <-1,-1> or <1,15>"); |
300 | 3.41k | printInt64(O, Value); |
301 | 3.41k | } else |
302 | 0 | printOperand(MI, OpNum, O); |
303 | 3.41k | } |
304 | | |
305 | | static inline void printImm32n_95_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
306 | 2.05k | { |
307 | 2.05k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm32n_95_AsmOperand, OpNum); |
308 | 2.05k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
309 | 2.05k | int64_t Value = |
310 | 2.05k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
311 | 2.05k | CS_ASSERT_RET( |
312 | 2.05k | (Value >= -32 && Value <= 95) && |
313 | 2.05k | "Invalid argument, value must be in ranges <-32,95>"); |
314 | 2.05k | printInt64(O, Value); |
315 | 2.05k | } else |
316 | 0 | printOperand(MI, OpNum, O); |
317 | 2.05k | } |
318 | | |
319 | | static inline void printImm8n_7_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
320 | 557 | { |
321 | 557 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8n_7_AsmOperand, OpNum); |
322 | 557 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
323 | 557 | int64_t Value = |
324 | 557 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
325 | 557 | CS_ASSERT_RET( |
326 | 557 | (Value >= -8 && Value <= 7) && |
327 | 557 | "Invalid argument, value must be in ranges <-8,7>"); |
328 | 557 | printInt64(O, Value); |
329 | 557 | } else |
330 | 0 | printOperand(MI, OpNum, O); |
331 | 557 | } |
332 | | |
333 | | static inline void printImm64n_4n_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
334 | 202 | { |
335 | 202 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm64n_4n_AsmOperand, OpNum); |
336 | 202 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
337 | 202 | int64_t Value = |
338 | 202 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
339 | 202 | CS_ASSERT_RET( |
340 | 202 | (Value >= -64 && Value <= -4) & ((Value & 0x3) == 0) && |
341 | 202 | "Invalid argument, value must be in ranges <-64,-4>"); |
342 | 202 | printInt64(O, Value); |
343 | 202 | } else |
344 | 0 | printOperand(MI, OpNum, O); |
345 | 202 | } |
346 | | |
347 | | static inline void printOffset8m32_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
348 | 857 | { |
349 | 857 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset8m32_AsmOperand, |
350 | 857 | OpNum); |
351 | 857 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
352 | 857 | int64_t Value = |
353 | 857 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
354 | 857 | CS_ASSERT_RET( |
355 | 857 | (Value >= 0 && Value <= 1020 && ((Value & 0x3) == 0)) && |
356 | 857 | "Invalid argument, value must be multiples of four in range [0,1020]"); |
357 | 857 | printInt64(O, Value); |
358 | 857 | } else |
359 | 0 | printOperand(MI, OpNum, O); |
360 | 857 | } |
361 | | |
362 | | static inline void printEntry_Imm12_AsmOperand(MCInst *MI, int OpNum, |
363 | | SStream *O) |
364 | 766 | { |
365 | 766 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Entry_Imm12_AsmOperand, |
366 | 766 | OpNum); |
367 | 766 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
368 | 766 | int64_t Value = |
369 | 766 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
370 | 766 | CS_ASSERT_RET( |
371 | 766 | (Value >= 0 && Value <= 32760) && |
372 | 766 | "Invalid argument, value must be multiples of eight in range " |
373 | 766 | "<0,32760>"); |
374 | 766 | printInt64(O, Value); |
375 | 766 | } else |
376 | 0 | printOperand(MI, OpNum, O); |
377 | 766 | } |
378 | | |
379 | | static inline void printB4const_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
380 | 6.18k | { |
381 | 6.18k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4const_AsmOperand, OpNum); |
382 | 6.18k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
383 | 6.18k | int64_t Value = |
384 | 6.18k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
385 | | |
386 | 6.18k | switch (Value) { |
387 | 304 | case -1: |
388 | 694 | case 1: |
389 | 1.21k | case 2: |
390 | 1.71k | case 3: |
391 | 2.05k | case 4: |
392 | 2.09k | case 5: |
393 | 3.40k | case 6: |
394 | 3.65k | case 7: |
395 | 3.91k | case 8: |
396 | 4.10k | case 10: |
397 | 4.45k | case 12: |
398 | 5.03k | case 16: |
399 | 5.14k | case 32: |
400 | 5.46k | case 64: |
401 | 5.77k | case 128: |
402 | 6.18k | case 256: |
403 | 6.18k | break; |
404 | 0 | default: |
405 | 0 | CS_ASSERT_RET((0) && "Invalid B4const argument"); |
406 | 6.18k | } |
407 | 6.18k | printInt64(O, Value); |
408 | 6.18k | } else |
409 | 0 | printOperand(MI, OpNum, O); |
410 | 6.18k | } |
411 | | |
412 | | static inline void printB4constu_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
413 | 9.17k | { |
414 | 9.17k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4constu_AsmOperand, OpNum); |
415 | 9.17k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
416 | 9.17k | int64_t Value = |
417 | 9.17k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
418 | | |
419 | 9.17k | switch (Value) { |
420 | 711 | case 32768: |
421 | 1.00k | case 65536: |
422 | 1.21k | case 2: |
423 | 1.53k | case 3: |
424 | 2.18k | case 4: |
425 | 2.63k | case 5: |
426 | 3.31k | case 6: |
427 | 3.95k | case 7: |
428 | 4.09k | case 8: |
429 | 4.74k | case 10: |
430 | 4.85k | case 12: |
431 | 6.48k | case 16: |
432 | 6.68k | case 32: |
433 | 6.79k | case 64: |
434 | 7.44k | case 128: |
435 | 9.17k | case 256: |
436 | 9.17k | break; |
437 | 0 | default: |
438 | 0 | CS_ASSERT_RET((0) && "Invalid B4constu argument"); |
439 | 9.17k | } |
440 | 9.17k | printInt64(O, Value); |
441 | 9.17k | } else |
442 | 0 | printOperand(MI, OpNum, O); |
443 | 9.17k | } |
444 | | |
445 | | static inline void printImm7_22_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
446 | 359 | { |
447 | 359 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm7_22_AsmOperand, OpNum); |
448 | 359 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
449 | 359 | int64_t Value = |
450 | 359 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
451 | 359 | CS_ASSERT_RET( |
452 | 359 | (Value >= 7 && Value <= 22) && |
453 | 359 | "Invalid argument, value must be in range <7,22>"); |
454 | 359 | printInt64(O, Value); |
455 | 359 | } else |
456 | 0 | printOperand(MI, OpNum, O); |
457 | 359 | } |
458 | | |
459 | | static inline void printSelect_2_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
460 | 1.62k | { |
461 | 1.62k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_2_AsmOperand, OpNum); |
462 | 1.62k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
463 | 1.62k | int64_t Value = |
464 | 1.62k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
465 | 1.62k | CS_ASSERT_RET((Value >= 0 && Value <= 1) && |
466 | 1.62k | "Invalid argument, value must be in range [0,1]"); |
467 | 1.62k | printInt64(O, Value); |
468 | 1.62k | } else |
469 | 0 | printOperand(MI, OpNum, O); |
470 | 1.62k | } |
471 | | |
472 | | static inline void printSelect_4_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
473 | 2.23k | { |
474 | 2.23k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_4_AsmOperand, OpNum); |
475 | 2.23k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
476 | 2.23k | int64_t Value = |
477 | 2.23k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
478 | 2.23k | CS_ASSERT_RET((Value >= 0 && Value <= 3) && |
479 | 2.23k | "Invalid argument, value must be in range [0,3]"); |
480 | 2.23k | printInt64(O, Value); |
481 | 2.23k | } else |
482 | 0 | printOperand(MI, OpNum, O); |
483 | 2.23k | } |
484 | | |
485 | | static inline void printSelect_8_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
486 | 1.79k | { |
487 | 1.79k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_8_AsmOperand, OpNum); |
488 | 1.79k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
489 | 1.79k | int64_t Value = |
490 | 1.79k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
491 | 1.79k | CS_ASSERT_RET((Value >= 0 && Value <= 7) && |
492 | 1.79k | "Invalid argument, value must be in range [0,7]"); |
493 | 1.79k | printInt64(O, Value); |
494 | 1.79k | } else |
495 | 0 | printOperand(MI, OpNum, O); |
496 | 1.79k | } |
497 | | |
498 | | static inline void printSelect_16_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
499 | 482 | { |
500 | 482 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_16_AsmOperand, OpNum); |
501 | 482 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
502 | 482 | int64_t Value = |
503 | 482 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
504 | 482 | CS_ASSERT_RET( |
505 | 482 | (Value >= 0 && Value <= 15) && |
506 | 482 | "Invalid argument, value must be in range [0,15]"); |
507 | 482 | printInt64(O, Value); |
508 | 482 | } else |
509 | 0 | printOperand(MI, OpNum, O); |
510 | 482 | } |
511 | | |
512 | | static inline void printSelect_256_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
513 | 95 | { |
514 | 95 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_256_AsmOperand, |
515 | 95 | OpNum); |
516 | 95 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
517 | 95 | int64_t Value = |
518 | 95 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
519 | 95 | CS_ASSERT_RET( |
520 | 95 | (Value >= 0 && Value <= 255) && |
521 | 95 | "Invalid argument, value must be in range [0,255]"); |
522 | 95 | printInt64(O, Value); |
523 | 95 | } else |
524 | 0 | printOperand(MI, OpNum, O); |
525 | 95 | } |
526 | | |
527 | | static inline void printOffset_16_16_AsmOperand(MCInst *MI, int OpNum, |
528 | | SStream *O) |
529 | 781 | { |
530 | 781 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_16_16_AsmOperand, |
531 | 781 | OpNum); |
532 | 781 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
533 | 781 | int64_t Value = |
534 | 781 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
535 | 781 | CS_ASSERT_RET( |
536 | 781 | (Value >= -128 && Value <= 112 && (Value & 0xf) == 0) && |
537 | 781 | "Invalid argument, value must be in range [-128,112], first 4 bits " |
538 | 781 | "should be zero"); |
539 | 448 | printInt64(O, Value); |
540 | 448 | } else { |
541 | 0 | printOperand(MI, OpNum, O); |
542 | 0 | } |
543 | 781 | } |
544 | | |
545 | | static inline void printOffset_256_8_AsmOperand(MCInst *MI, int OpNum, |
546 | | SStream *O) |
547 | 2.55k | { |
548 | 2.55k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_8_AsmOperand, |
549 | 2.55k | OpNum); |
550 | 2.55k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
551 | 2.55k | int64_t Value = |
552 | 2.55k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
553 | 2.55k | CS_ASSERT_RET( |
554 | 2.55k | (Value >= -1024 && Value <= 1016 && |
555 | 2.55k | (Value & 0x7) == 0) && |
556 | 2.55k | "Invalid argument, value must be in range [-1024,1016], first 3 " |
557 | 2.55k | "bits should be zero"); |
558 | 1.94k | printInt64(O, Value); |
559 | 1.94k | } else |
560 | 0 | printOperand(MI, OpNum, O); |
561 | 2.55k | } |
562 | | |
563 | | static inline void printOffset_256_16_AsmOperand(MCInst *MI, int OpNum, |
564 | | SStream *O) |
565 | 2.05k | { |
566 | 2.05k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_16_AsmOperand, |
567 | 2.05k | OpNum); |
568 | 2.05k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
569 | 2.05k | int64_t Value = |
570 | 2.05k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
571 | 2.05k | CS_ASSERT_RET( |
572 | 2.05k | (Value >= -2048 && Value <= 2032 && |
573 | 2.05k | (Value & 0xf) == 0) && |
574 | 2.05k | "Invalid argument, value must be in range [-2048,2032], first 4 " |
575 | 2.05k | "bits should be zero"); |
576 | 1.00k | printInt64(O, Value); |
577 | 1.00k | } else { |
578 | 0 | printOperand(MI, OpNum, O); |
579 | 0 | } |
580 | 2.05k | } |
581 | | |
582 | | static inline void printOffset_256_4_AsmOperand(MCInst *MI, int OpNum, |
583 | | SStream *O) |
584 | 734 | { |
585 | 734 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_4_AsmOperand, |
586 | 734 | OpNum); |
587 | 734 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
588 | 734 | int64_t Value = |
589 | 734 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
590 | 734 | CS_ASSERT_RET( |
591 | 734 | (Value >= -512 && Value <= 508 && (Value & 0x3) == 0) && |
592 | 734 | "Invalid argument, value must be in range [-512,508], first 2 bits " |
593 | 734 | "should be zero"); |
594 | 122 | printInt64(O, Value); |
595 | 122 | } else |
596 | 0 | printOperand(MI, OpNum, O); |
597 | 734 | } |
598 | | |
599 | | static inline void printOffset_128_2_AsmOperand(MCInst *MI, int OpNum, |
600 | | SStream *O) |
601 | 988 | { |
602 | 988 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_2_AsmOperand, |
603 | 988 | OpNum); |
604 | 988 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
605 | 988 | int64_t Value = |
606 | 988 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
607 | 988 | CS_ASSERT_RET( |
608 | 988 | (Value >= 0 && Value <= 254 && (Value & 0x1) == 0) && |
609 | 988 | "Invalid argument, value must be in range [0,254], first bit should " |
610 | 988 | "be zero"); |
611 | 988 | printInt64(O, Value); |
612 | 988 | } else |
613 | 0 | printOperand(MI, OpNum, O); |
614 | 988 | } |
615 | | |
616 | | static inline void printOffset_128_1_AsmOperand(MCInst *MI, int OpNum, |
617 | | SStream *O) |
618 | 99 | { |
619 | 99 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_1_AsmOperand, |
620 | 99 | OpNum); |
621 | 99 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
622 | 99 | int64_t Value = |
623 | 99 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
624 | 99 | CS_ASSERT_RET( |
625 | 99 | (Value >= 0 && Value <= 127) && |
626 | 99 | "Invalid argument, value must be in range [0,127]"); |
627 | 99 | printInt64(O, Value); |
628 | 99 | } else |
629 | 0 | printOperand(MI, OpNum, O); |
630 | 99 | } |
631 | | |
632 | | static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum, |
633 | | SStream *O) |
634 | 4.57k | { |
635 | 4.57k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_64_16_AsmOperand, |
636 | 4.57k | OpNum); |
637 | 4.57k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
638 | 4.57k | int64_t Value = |
639 | 4.57k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
640 | 4.57k | CS_ASSERT_RET( |
641 | 4.57k | (Value >= -512 && Value <= 496 && (Value & 0xf) == 0) && |
642 | 4.57k | "Invalid argument, value must be in range [-512,496], first 4 bits " |
643 | 4.57k | "should be zero"); |
644 | 2.79k | printInt64(O, Value); |
645 | 2.79k | } else |
646 | 0 | printOperand(MI, OpNum, O); |
647 | 4.57k | } |
648 | | |
649 | | #define IMPL_printImmOperand(N, L, H, S) \ |
650 | | static void printImmOperand_##N(MCInst *MI, int OpNum, SStream *O) \ |
651 | 0 | { \ |
652 | 0 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \ |
653 | 0 | OpNum); \ |
654 | 0 | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \ |
655 | 0 | if (MCOperand_isImm(MC)) { \ |
656 | 0 | int64_t Value = MCOperand_getImm(MC); \ |
657 | 0 | CS_ASSERT_RET((Value >= L && Value <= H && \ |
658 | 0 | ((Value % S) == 0)) && \ |
659 | 0 | "Invalid argument"); \ |
660 | 0 | printInt64(O, Value); \ |
661 | 0 | } else { \ |
662 | 0 | printOperand(MI, OpNum, O); \ |
663 | 0 | } \ |
664 | 0 | } Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_47_1 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_14_2 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus32_28_4 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus64_56_8 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_56_8 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_3_1 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_0_63_1 |
665 | | |
666 | | IMPL_printImmOperand(minus64_56_8, -64, 56, 8); |
667 | | IMPL_printImmOperand(minus32_28_4, -32, 28, 4); |
668 | | IMPL_printImmOperand(minus16_47_1, -16, 47, 1); |
669 | | IMPL_printImmOperand(minus16_14_2, -16, 14, 2); |
670 | | IMPL_printImmOperand(0_56_8, 0, 56, 8); |
671 | | IMPL_printImmOperand(0_3_1, 0, 3, 1); |
672 | | IMPL_printImmOperand(0_63_1, 0, 63, 1); |
673 | | |
674 | | #include "XtensaGenAsmWriter.inc" |
675 | | |
676 | | static void printInst(MCInst *MI, uint64_t Address, const char *Annot, |
677 | | SStream *O) |
678 | 115k | { |
679 | 115k | unsigned Opcode = MCInst_getOpcode(MI); |
680 | | |
681 | 115k | switch (Opcode) { |
682 | 541 | case Xtensa_WSR: { |
683 | | // INTERRUPT mnemonic is read-only, so use INTSET mnemonic instead |
684 | 541 | Register SR = MCOperand_getReg(MCInst_getOperand(MI, (0))); |
685 | 541 | if (SR == Xtensa_INTERRUPT) { |
686 | 233 | Register Reg = |
687 | 233 | MCOperand_getReg(MCInst_getOperand(MI, (1))); |
688 | 233 | SStream_concat1(O, '\t'); |
689 | 233 | SStream_concat(O, "%s", "wsr"); |
690 | 233 | SStream_concat0(O, "\t"); |
691 | | |
692 | 233 | printRegName(O, Reg); |
693 | 233 | SStream_concat(O, "%s", ", "); |
694 | 233 | SStream_concat0(O, "intset"); |
695 | 233 | ; |
696 | 233 | return; |
697 | 233 | } |
698 | 541 | } |
699 | 115k | } |
700 | 114k | printInstruction(MI, Address, O); |
701 | 114k | } |
702 | | |
703 | | void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O) |
704 | 115k | { |
705 | 115k | printInst(MI, Address, NULL, O); |
706 | 115k | } |
707 | | |
708 | | const char *Xtensa_LLVM_getRegisterName(unsigned RegNo) |
709 | 17.3k | { |
710 | 17.3k | return getRegisterName(RegNo); |
711 | 17.3k | } |