/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 | 74 | { |
53 | 74 | SStream_concat0(O, getRegisterName(Reg)); |
54 | 74 | } |
55 | | |
56 | | static void printOp(MCInst *MI, MCOperand *MC, SStream *O) |
57 | 197k | { |
58 | 197k | if (MCOperand_isReg(MC)) |
59 | 187k | SStream_concat0(O, getRegisterName(MCOperand_getReg(MC))); |
60 | 10.3k | else if (MCOperand_isImm(MC)) |
61 | 10.3k | 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 | 197k | } |
67 | | |
68 | | static void printOperand(MCInst *MI, const int op_num, SStream *O) |
69 | 187k | { |
70 | 187k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Operand, op_num); |
71 | 187k | printOp(MI, MCInst_getOperand(MI, op_num), O); |
72 | 187k | } |
73 | | |
74 | | static inline void printMemOperand(MCInst *MI, int OpNum, SStream *OS) |
75 | 10.3k | { |
76 | 10.3k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_MemOperand, OpNum); |
77 | 10.3k | SStream_concat0(OS, getRegisterName(MCOperand_getReg( |
78 | 10.3k | MCInst_getOperand(MI, (OpNum))))); |
79 | 10.3k | SStream_concat0(OS, ", "); |
80 | 10.3k | printOp(MI, MCInst_getOperand(MI, OpNum + 1), OS); |
81 | 10.3k | } |
82 | | |
83 | | static inline void printBranchTarget(MCInst *MI, int OpNum, SStream *OS) |
84 | 16.6k | { |
85 | 16.6k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_BranchTarget, OpNum); |
86 | 16.6k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
87 | 16.6k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
88 | 16.6k | int64_t Val = MCOperand_getImm(MC) + 4; |
89 | 16.6k | SStream_concat0(OS, ". "); |
90 | 16.6k | if (Val > 0) |
91 | 8.30k | SStream_concat0(OS, "+"); |
92 | | |
93 | 16.6k | printInt64(OS, Val); |
94 | 16.6k | } 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 | 16.6k | } |
99 | | |
100 | | static inline void printLoopTarget(MCInst *MI, int OpNum, SStream *OS) |
101 | 57 | { |
102 | 57 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_LoopTarget, OpNum); |
103 | 57 | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
104 | 57 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
105 | 57 | int64_t Val = MCOperand_getImm(MC) + 4; |
106 | 57 | SStream_concat0(OS, ". "); |
107 | 57 | if (Val > 0) |
108 | 57 | SStream_concat0(OS, "+"); |
109 | | |
110 | 57 | printInt64(OS, Val); |
111 | 57 | } 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 | 57 | } |
116 | | |
117 | | static inline void printJumpTarget(MCInst *MI, int OpNum, SStream *OS) |
118 | 1.54k | { |
119 | 1.54k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_JumpTarget, OpNum); |
120 | 1.54k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
121 | 1.54k | if (MCOperand_isImm(MC)) { |
122 | 1.54k | int64_t Val = MCOperand_getImm(MC) + 4; |
123 | 1.54k | SStream_concat0(OS, ". "); |
124 | 1.54k | if (Val > 0) |
125 | 856 | SStream_concat0(OS, "+"); |
126 | | |
127 | 1.54k | printInt64(OS, Val); |
128 | 1.54k | } 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.54k | ; |
133 | 1.54k | } |
134 | | |
135 | | static inline void printCallOperand(MCInst *MI, int OpNum, SStream *OS) |
136 | 3.48k | { |
137 | 3.48k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_CallOperand, OpNum); |
138 | 3.48k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
139 | 3.48k | if (MCOperand_isImm(MC)) { |
140 | 3.48k | int64_t Val = MCOperand_getImm(MC) + 4; |
141 | 3.48k | SStream_concat0(OS, ". "); |
142 | 3.48k | if (Val > 0) |
143 | 1.99k | SStream_concat0(OS, "+"); |
144 | | |
145 | 3.48k | printInt64(OS, Val); |
146 | 3.48k | } 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.48k | } |
151 | | |
152 | | static inline void printL32RTarget(MCInst *MI, int OpNum, SStream *O) |
153 | 5.82k | { |
154 | 5.82k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_L32RTarget, OpNum); |
155 | 5.82k | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); |
156 | 5.82k | if (MCOperand_isImm(MC)) { |
157 | 5.82k | SStream_concat0(O, ". "); |
158 | 5.82k | printInt64(O, Xtensa_L32R_Value(MI, OpNum)); |
159 | 5.82k | } 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 | 5.82k | } |
164 | | |
165 | | static inline void printImm8_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
166 | 420 | { |
167 | 420 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_AsmOperand, OpNum); |
168 | 420 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
169 | 420 | int64_t Value = |
170 | 420 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
171 | 420 | CS_ASSERT_RET( |
172 | 420 | isIntN(8, Value) && |
173 | 420 | "Invalid argument, value must be in ranges [-128,127]"); |
174 | 420 | printInt64(O, Value); |
175 | 420 | } else { |
176 | 0 | printOperand(MI, OpNum, O); |
177 | 0 | } |
178 | 420 | } |
179 | | |
180 | | static inline void printImm8_sh8_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
181 | 342 | { |
182 | 342 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8_sh8_AsmOperand, OpNum); |
183 | 342 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
184 | 342 | int64_t Value = |
185 | 342 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
186 | 342 | CS_ASSERT_RET( |
187 | 342 | (isIntN(16, Value) && ((Value & 0xFF) == 0)) && |
188 | 342 | "Invalid argument, value must be multiples of 256 in range " |
189 | 342 | "[-32768,32512]"); |
190 | 342 | printInt64(O, Value); |
191 | 342 | } else |
192 | 0 | printOperand(MI, OpNum, O); |
193 | 342 | } |
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 | 345 | { |
211 | 345 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm12m_AsmOperand, OpNum); |
212 | 345 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
213 | 345 | int64_t Value = |
214 | 345 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
215 | 345 | CS_ASSERT_RET( |
216 | 345 | (Value >= -2048 && Value <= 2047) && |
217 | 345 | "Invalid argument, value must be in ranges [-2048,2047]"); |
218 | 345 | printInt64(O, Value); |
219 | 345 | } else |
220 | 0 | printOperand(MI, OpNum, O); |
221 | 345 | } |
222 | | |
223 | | static inline void printUimm4_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
224 | 3.04k | { |
225 | 3.04k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm4_AsmOperand, OpNum); |
226 | 3.04k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
227 | 3.04k | int64_t Value = |
228 | 3.04k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
229 | 3.04k | CS_ASSERT_RET((Value >= 0 && Value <= 15) && |
230 | 3.04k | "Invalid argument"); |
231 | 3.04k | printInt64(O, Value); |
232 | 3.04k | } else |
233 | 0 | printOperand(MI, OpNum, O); |
234 | 3.04k | } |
235 | | |
236 | | static inline void printUimm5_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
237 | 3.29k | { |
238 | 3.29k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Uimm5_AsmOperand, OpNum); |
239 | 3.29k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
240 | 3.29k | int64_t Value = |
241 | 3.29k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
242 | 3.29k | CS_ASSERT_RET((Value >= 0 && Value <= 31) && |
243 | 3.29k | "Invalid argument"); |
244 | 3.29k | printInt64(O, Value); |
245 | 3.29k | } else |
246 | 0 | printOperand(MI, OpNum, O); |
247 | 3.29k | } |
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 | 499 | { |
265 | 499 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Shimm0_31_AsmOperand, OpNum); |
266 | 499 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
267 | 499 | int64_t Value = |
268 | 499 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
269 | 499 | CS_ASSERT_RET( |
270 | 499 | (Value >= 0 && Value <= 31) && |
271 | 499 | "Invalid argument, value must be in range [0,31]"); |
272 | 365 | printInt64(O, Value); |
273 | 365 | } else |
274 | 0 | printOperand(MI, OpNum, O); |
275 | 499 | } |
276 | | |
277 | | static inline void printImm1_16_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
278 | 1.07k | { |
279 | 1.07k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1_16_AsmOperand, OpNum); |
280 | 1.07k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
281 | 1.07k | int64_t Value = |
282 | 1.07k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
283 | 1.07k | CS_ASSERT_RET( |
284 | 1.07k | (Value >= 1 && Value <= 16) && |
285 | 1.07k | "Invalid argument, value must be in range [1,16]"); |
286 | 1.07k | printInt64(O, Value); |
287 | 1.07k | } else |
288 | 0 | printOperand(MI, OpNum, O); |
289 | 1.07k | } |
290 | | |
291 | | static inline void printImm1n_15_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
292 | 4.80k | { |
293 | 4.80k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm1n_15_AsmOperand, OpNum); |
294 | 4.80k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
295 | 4.80k | int64_t Value = |
296 | 4.80k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
297 | 4.80k | CS_ASSERT_RET( |
298 | 4.80k | (Value >= -1 && (Value != 0) && Value <= 15) && |
299 | 4.80k | "Invalid argument, value must be in ranges <-1,-1> or <1,15>"); |
300 | 4.80k | printInt64(O, Value); |
301 | 4.80k | } else |
302 | 0 | printOperand(MI, OpNum, O); |
303 | 4.80k | } |
304 | | |
305 | | static inline void printImm32n_95_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
306 | 1.78k | { |
307 | 1.78k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm32n_95_AsmOperand, OpNum); |
308 | 1.78k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
309 | 1.78k | int64_t Value = |
310 | 1.78k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
311 | 1.78k | CS_ASSERT_RET( |
312 | 1.78k | (Value >= -32 && Value <= 95) && |
313 | 1.78k | "Invalid argument, value must be in ranges <-32,95>"); |
314 | 1.78k | printInt64(O, Value); |
315 | 1.78k | } else |
316 | 0 | printOperand(MI, OpNum, O); |
317 | 1.78k | } |
318 | | |
319 | | static inline void printImm8n_7_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
320 | 846 | { |
321 | 846 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm8n_7_AsmOperand, OpNum); |
322 | 846 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
323 | 846 | int64_t Value = |
324 | 846 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
325 | 846 | CS_ASSERT_RET( |
326 | 846 | (Value >= -8 && Value <= 7) && |
327 | 846 | "Invalid argument, value must be in ranges <-8,7>"); |
328 | 846 | printInt64(O, Value); |
329 | 846 | } else |
330 | 0 | printOperand(MI, OpNum, O); |
331 | 846 | } |
332 | | |
333 | | static inline void printImm64n_4n_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
334 | 96 | { |
335 | 96 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm64n_4n_AsmOperand, OpNum); |
336 | 96 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
337 | 96 | int64_t Value = |
338 | 96 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
339 | 96 | CS_ASSERT_RET( |
340 | 96 | (Value >= -64 && Value <= -4) & ((Value & 0x3) == 0) && |
341 | 96 | "Invalid argument, value must be in ranges <-64,-4>"); |
342 | 96 | printInt64(O, Value); |
343 | 96 | } else |
344 | 0 | printOperand(MI, OpNum, O); |
345 | 96 | } |
346 | | |
347 | | static inline void printOffset8m32_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
348 | 1.17k | { |
349 | 1.17k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset8m32_AsmOperand, |
350 | 1.17k | OpNum); |
351 | 1.17k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
352 | 1.17k | int64_t Value = |
353 | 1.17k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
354 | 1.17k | CS_ASSERT_RET( |
355 | 1.17k | (Value >= 0 && Value <= 1020 && ((Value & 0x3) == 0)) && |
356 | 1.17k | "Invalid argument, value must be multiples of four in range [0,1020]"); |
357 | 1.17k | printInt64(O, Value); |
358 | 1.17k | } else |
359 | 0 | printOperand(MI, OpNum, O); |
360 | 1.17k | } |
361 | | |
362 | | static inline void printEntry_Imm12_AsmOperand(MCInst *MI, int OpNum, |
363 | | SStream *O) |
364 | 363 | { |
365 | 363 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Entry_Imm12_AsmOperand, |
366 | 363 | OpNum); |
367 | 363 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
368 | 363 | int64_t Value = |
369 | 363 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
370 | 363 | CS_ASSERT_RET( |
371 | 363 | (Value >= 0 && Value <= 32760) && |
372 | 363 | "Invalid argument, value must be multiples of eight in range " |
373 | 363 | "<0,32760>"); |
374 | 363 | printInt64(O, Value); |
375 | 363 | } else |
376 | 0 | printOperand(MI, OpNum, O); |
377 | 363 | } |
378 | | |
379 | | static inline void printB4const_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
380 | 4.87k | { |
381 | 4.87k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4const_AsmOperand, OpNum); |
382 | 4.87k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
383 | 4.87k | int64_t Value = |
384 | 4.87k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
385 | | |
386 | 4.87k | switch (Value) { |
387 | 282 | case -1: |
388 | 584 | case 1: |
389 | 860 | case 2: |
390 | 938 | case 3: |
391 | 1.24k | case 4: |
392 | 1.38k | case 5: |
393 | 1.66k | case 6: |
394 | 1.97k | case 7: |
395 | 2.35k | case 8: |
396 | 2.67k | case 10: |
397 | 3.42k | case 12: |
398 | 3.88k | case 16: |
399 | 4.09k | case 32: |
400 | 4.29k | case 64: |
401 | 4.54k | case 128: |
402 | 4.87k | case 256: |
403 | 4.87k | break; |
404 | 0 | default: |
405 | 0 | CS_ASSERT_RET((0) && "Invalid B4const argument"); |
406 | 4.87k | } |
407 | 4.87k | printInt64(O, Value); |
408 | 4.87k | } else |
409 | 0 | printOperand(MI, OpNum, O); |
410 | 4.87k | } |
411 | | |
412 | | static inline void printB4constu_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
413 | 4.54k | { |
414 | 4.54k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_B4constu_AsmOperand, OpNum); |
415 | 4.54k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
416 | 4.54k | int64_t Value = |
417 | 4.54k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
418 | | |
419 | 4.54k | switch (Value) { |
420 | 446 | case 32768: |
421 | 670 | case 65536: |
422 | 782 | case 2: |
423 | 868 | case 3: |
424 | 965 | case 4: |
425 | 1.52k | case 5: |
426 | 1.86k | case 6: |
427 | 2.10k | case 7: |
428 | 2.17k | case 8: |
429 | 2.27k | case 10: |
430 | 2.35k | case 12: |
431 | 3.15k | case 16: |
432 | 3.74k | case 32: |
433 | 3.96k | case 64: |
434 | 4.05k | case 128: |
435 | 4.54k | case 256: |
436 | 4.54k | break; |
437 | 0 | default: |
438 | 0 | CS_ASSERT_RET((0) && "Invalid B4constu argument"); |
439 | 4.54k | } |
440 | 4.54k | printInt64(O, Value); |
441 | 4.54k | } else |
442 | 0 | printOperand(MI, OpNum, O); |
443 | 4.54k | } |
444 | | |
445 | | static inline void printImm7_22_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
446 | 354 | { |
447 | 354 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Imm7_22_AsmOperand, OpNum); |
448 | 354 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
449 | 354 | int64_t Value = |
450 | 354 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
451 | 354 | CS_ASSERT_RET( |
452 | 354 | (Value >= 7 && Value <= 22) && |
453 | 354 | "Invalid argument, value must be in range <7,22>"); |
454 | 354 | printInt64(O, Value); |
455 | 354 | } else |
456 | 0 | printOperand(MI, OpNum, O); |
457 | 354 | } |
458 | | |
459 | | static inline void printSelect_2_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
460 | 1.21k | { |
461 | 1.21k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_2_AsmOperand, OpNum); |
462 | 1.21k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
463 | 1.21k | int64_t Value = |
464 | 1.21k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
465 | 1.21k | CS_ASSERT_RET((Value >= 0 && Value <= 1) && |
466 | 1.21k | "Invalid argument, value must be in range [0,1]"); |
467 | 1.21k | printInt64(O, Value); |
468 | 1.21k | } else |
469 | 0 | printOperand(MI, OpNum, O); |
470 | 1.21k | } |
471 | | |
472 | | static inline void printSelect_4_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
473 | 2.59k | { |
474 | 2.59k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_4_AsmOperand, OpNum); |
475 | 2.59k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
476 | 2.59k | int64_t Value = |
477 | 2.59k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
478 | 2.59k | CS_ASSERT_RET((Value >= 0 && Value <= 3) && |
479 | 2.59k | "Invalid argument, value must be in range [0,3]"); |
480 | 2.59k | printInt64(O, Value); |
481 | 2.59k | } else |
482 | 0 | printOperand(MI, OpNum, O); |
483 | 2.59k | } |
484 | | |
485 | | static inline void printSelect_8_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
486 | 1.42k | { |
487 | 1.42k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_8_AsmOperand, OpNum); |
488 | 1.42k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
489 | 1.42k | int64_t Value = |
490 | 1.42k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
491 | 1.42k | CS_ASSERT_RET((Value >= 0 && Value <= 7) && |
492 | 1.42k | "Invalid argument, value must be in range [0,7]"); |
493 | 1.42k | printInt64(O, Value); |
494 | 1.42k | } else |
495 | 0 | printOperand(MI, OpNum, O); |
496 | 1.42k | } |
497 | | |
498 | | static inline void printSelect_16_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
499 | 463 | { |
500 | 463 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_16_AsmOperand, OpNum); |
501 | 463 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
502 | 463 | int64_t Value = |
503 | 463 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
504 | 463 | CS_ASSERT_RET( |
505 | 463 | (Value >= 0 && Value <= 15) && |
506 | 463 | "Invalid argument, value must be in range [0,15]"); |
507 | 463 | printInt64(O, Value); |
508 | 463 | } else |
509 | 0 | printOperand(MI, OpNum, O); |
510 | 463 | } |
511 | | |
512 | | static inline void printSelect_256_AsmOperand(MCInst *MI, int OpNum, SStream *O) |
513 | 284 | { |
514 | 284 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Select_256_AsmOperand, |
515 | 284 | OpNum); |
516 | 284 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
517 | 284 | int64_t Value = |
518 | 284 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
519 | 284 | CS_ASSERT_RET( |
520 | 284 | (Value >= 0 && Value <= 255) && |
521 | 284 | "Invalid argument, value must be in range [0,255]"); |
522 | 284 | printInt64(O, Value); |
523 | 284 | } else |
524 | 0 | printOperand(MI, OpNum, O); |
525 | 284 | } |
526 | | |
527 | | static inline void printOffset_16_16_AsmOperand(MCInst *MI, int OpNum, |
528 | | SStream *O) |
529 | 780 | { |
530 | 780 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_16_16_AsmOperand, |
531 | 780 | OpNum); |
532 | 780 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
533 | 780 | int64_t Value = |
534 | 780 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
535 | 780 | CS_ASSERT_RET( |
536 | 780 | (Value >= -128 && Value <= 112 && (Value & 0xf) == 0) && |
537 | 780 | "Invalid argument, value must be in range [-128,112], first 4 bits " |
538 | 780 | "should be zero"); |
539 | 304 | printInt64(O, Value); |
540 | 304 | } else { |
541 | 0 | printOperand(MI, OpNum, O); |
542 | 0 | } |
543 | 780 | } |
544 | | |
545 | | static inline void printOffset_256_8_AsmOperand(MCInst *MI, int OpNum, |
546 | | SStream *O) |
547 | 2.51k | { |
548 | 2.51k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_8_AsmOperand, |
549 | 2.51k | OpNum); |
550 | 2.51k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
551 | 2.51k | int64_t Value = |
552 | 2.51k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
553 | 2.51k | CS_ASSERT_RET( |
554 | 2.51k | (Value >= -1024 && Value <= 1016 && |
555 | 2.51k | (Value & 0x7) == 0) && |
556 | 2.51k | "Invalid argument, value must be in range [-1024,1016], first 3 " |
557 | 2.51k | "bits should be zero"); |
558 | 1.07k | printInt64(O, Value); |
559 | 1.07k | } else |
560 | 0 | printOperand(MI, OpNum, O); |
561 | 2.51k | } |
562 | | |
563 | | static inline void printOffset_256_16_AsmOperand(MCInst *MI, int OpNum, |
564 | | SStream *O) |
565 | 1.46k | { |
566 | 1.46k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_16_AsmOperand, |
567 | 1.46k | OpNum); |
568 | 1.46k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
569 | 1.46k | int64_t Value = |
570 | 1.46k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
571 | 1.46k | CS_ASSERT_RET( |
572 | 1.46k | (Value >= -2048 && Value <= 2032 && |
573 | 1.46k | (Value & 0xf) == 0) && |
574 | 1.46k | "Invalid argument, value must be in range [-2048,2032], first 4 " |
575 | 1.46k | "bits should be zero"); |
576 | 1.02k | printInt64(O, Value); |
577 | 1.02k | } else { |
578 | 0 | printOperand(MI, OpNum, O); |
579 | 0 | } |
580 | 1.46k | } |
581 | | |
582 | | static inline void printOffset_256_4_AsmOperand(MCInst *MI, int OpNum, |
583 | | SStream *O) |
584 | 710 | { |
585 | 710 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_256_4_AsmOperand, |
586 | 710 | OpNum); |
587 | 710 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
588 | 710 | int64_t Value = |
589 | 710 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
590 | 710 | CS_ASSERT_RET( |
591 | 710 | (Value >= -512 && Value <= 508 && (Value & 0x3) == 0) && |
592 | 710 | "Invalid argument, value must be in range [-512,508], first 2 bits " |
593 | 710 | "should be zero"); |
594 | 413 | printInt64(O, Value); |
595 | 413 | } else |
596 | 0 | printOperand(MI, OpNum, O); |
597 | 710 | } |
598 | | |
599 | | static inline void printOffset_128_2_AsmOperand(MCInst *MI, int OpNum, |
600 | | SStream *O) |
601 | 699 | { |
602 | 699 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_2_AsmOperand, |
603 | 699 | OpNum); |
604 | 699 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
605 | 699 | int64_t Value = |
606 | 699 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
607 | 699 | CS_ASSERT_RET( |
608 | 699 | (Value >= 0 && Value <= 254 && (Value & 0x1) == 0) && |
609 | 699 | "Invalid argument, value must be in range [0,254], first bit should " |
610 | 699 | "be zero"); |
611 | 699 | printInt64(O, Value); |
612 | 699 | } else |
613 | 0 | printOperand(MI, OpNum, O); |
614 | 699 | } |
615 | | |
616 | | static inline void printOffset_128_1_AsmOperand(MCInst *MI, int OpNum, |
617 | | SStream *O) |
618 | 160 | { |
619 | 160 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_128_1_AsmOperand, |
620 | 160 | OpNum); |
621 | 160 | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
622 | 160 | int64_t Value = |
623 | 160 | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
624 | 160 | CS_ASSERT_RET( |
625 | 160 | (Value >= 0 && Value <= 127) && |
626 | 160 | "Invalid argument, value must be in range [0,127]"); |
627 | 160 | printInt64(O, Value); |
628 | 160 | } else |
629 | 0 | printOperand(MI, OpNum, O); |
630 | 160 | } |
631 | | |
632 | | static inline void printOffset_64_16_AsmOperand(MCInst *MI, int OpNum, |
633 | | SStream *O) |
634 | 3.18k | { |
635 | 3.18k | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_Offset_64_16_AsmOperand, |
636 | 3.18k | OpNum); |
637 | 3.18k | if (MCOperand_isImm(MCInst_getOperand(MI, (OpNum)))) { |
638 | 3.18k | int64_t Value = |
639 | 3.18k | MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); |
640 | 3.18k | CS_ASSERT_RET( |
641 | 3.18k | (Value >= -512 && Value <= 496 && (Value & 0xf) == 0) && |
642 | 3.18k | "Invalid argument, value must be in range [-512,496], first 4 bits " |
643 | 3.18k | "should be zero"); |
644 | 2.15k | printInt64(O, Value); |
645 | 2.15k | } else |
646 | 0 | printOperand(MI, OpNum, O); |
647 | 3.18k | } |
648 | | |
649 | | #define IMPL_printImmOperand(N, L, H, S) \ |
650 | | static void printImmOperand_##N(MCInst *MI, int OpNum, SStream *O) \ |
651 | 107 | { \ |
652 | 107 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \ |
653 | 107 | OpNum); \ |
654 | 107 | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \ |
655 | 107 | if (MCOperand_isImm(MC)) { \ |
656 | 107 | int64_t Value = MCOperand_getImm(MC); \ |
657 | 107 | CS_ASSERT_RET((Value >= L && Value <= H && \ |
658 | 107 | ((Value % S) == 0)) && \ |
659 | 107 | "Invalid argument"); \ |
660 | 107 | printInt64(O, Value); \ |
661 | 54 | } else { \ |
662 | 0 | printOperand(MI, OpNum, O); \ |
663 | 0 | } \ |
664 | 107 | } Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_47_1 Unexecuted instantiation: XtensaInstPrinter.c:printImmOperand_minus16_14_2 XtensaInstPrinter.c:printImmOperand_minus32_28_4 Line | Count | Source | 651 | 96 | { \ | 652 | 96 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \ | 653 | 96 | OpNum); \ | 654 | 96 | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \ | 655 | 96 | if (MCOperand_isImm(MC)) { \ | 656 | 96 | int64_t Value = MCOperand_getImm(MC); \ | 657 | 96 | CS_ASSERT_RET((Value >= L && Value <= H && \ | 658 | 96 | ((Value % S) == 0)) && \ | 659 | 96 | "Invalid argument"); \ | 660 | 96 | printInt64(O, Value); \ | 661 | 54 | } else { \ | 662 | 0 | printOperand(MI, OpNum, O); \ | 663 | 0 | } \ | 664 | 96 | } |
XtensaInstPrinter.c:printImmOperand_minus64_56_8 Line | Count | Source | 651 | 11 | { \ | 652 | 11 | Xtensa_add_cs_detail_0(MI, Xtensa_OP_GROUP_ImmOperand_##N, \ | 653 | 11 | OpNum); \ | 654 | 11 | MCOperand *MC = MCInst_getOperand(MI, (OpNum)); \ | 655 | 11 | if (MCOperand_isImm(MC)) { \ | 656 | 11 | int64_t Value = MCOperand_getImm(MC); \ | 657 | 11 | CS_ASSERT_RET((Value >= L && Value <= H && \ | 658 | 11 | ((Value % S) == 0)) && \ | 659 | 11 | "Invalid argument"); \ | 660 | 11 | printInt64(O, Value); \ | 661 | 0 | } else { \ | 662 | 0 | printOperand(MI, OpNum, O); \ | 663 | 0 | } \ | 664 | 11 | } |
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 | 97.7k | { |
679 | 97.7k | unsigned Opcode = MCInst_getOpcode(MI); |
680 | | |
681 | 97.7k | switch (Opcode) { |
682 | 381 | case Xtensa_WSR: { |
683 | | // INTERRUPT mnemonic is read-only, so use INTSET mnemonic instead |
684 | 381 | Register SR = MCOperand_getReg(MCInst_getOperand(MI, (0))); |
685 | 381 | if (SR == Xtensa_INTERRUPT) { |
686 | 74 | Register Reg = |
687 | 74 | MCOperand_getReg(MCInst_getOperand(MI, (1))); |
688 | 74 | SStream_concat1(O, '\t'); |
689 | 74 | SStream_concat(O, "%s", "wsr"); |
690 | 74 | SStream_concat0(O, "\t"); |
691 | | |
692 | 74 | printRegName(O, Reg); |
693 | 74 | SStream_concat(O, "%s", ", "); |
694 | 74 | SStream_concat0(O, "intset"); |
695 | 74 | ; |
696 | 74 | return; |
697 | 74 | } |
698 | 381 | } |
699 | 97.7k | } |
700 | 97.6k | printInstruction(MI, Address, O); |
701 | 97.6k | } |
702 | | |
703 | | void Xtensa_LLVM_printInstruction(MCInst *MI, uint64_t Address, SStream *O) |
704 | 97.7k | { |
705 | 97.7k | printInst(MI, Address, NULL, O); |
706 | 97.7k | } |
707 | | |
708 | | const char *Xtensa_LLVM_getRegisterName(unsigned RegNo) |
709 | 12.4k | { |
710 | 12.4k | return getRegisterName(RegNo); |
711 | 12.4k | } |