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