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