/src/binutils-gdb/opcodes/aarch64-dis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* aarch64-dis.c -- AArch64 disassembler. |
2 | | Copyright (C) 2009-2023 Free Software Foundation, Inc. |
3 | | Contributed by ARM Ltd. |
4 | | |
5 | | This file is part of the GNU opcodes library. |
6 | | |
7 | | This library is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3, or (at your option) |
10 | | any later version. |
11 | | |
12 | | It is distributed in the hope that it will be useful, but WITHOUT |
13 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
15 | | License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with this program; see the file COPYING3. If not, |
19 | | see <http://www.gnu.org/licenses/>. */ |
20 | | |
21 | | #include "sysdep.h" |
22 | | #include <stdint.h> |
23 | | #include "disassemble.h" |
24 | | #include "libiberty.h" |
25 | | #include "opintl.h" |
26 | | #include "aarch64-dis.h" |
27 | | #include "elf-bfd.h" |
28 | | #include "safe-ctype.h" |
29 | | #include "obstack.h" |
30 | | |
31 | | #define obstack_chunk_alloc xmalloc |
32 | | #define obstack_chunk_free free |
33 | | |
34 | 15.0M | #define INSNLEN 4 |
35 | | |
36 | | /* This character is used to encode style information within the output |
37 | | buffers. See get_style_text and print_operands for more details. */ |
38 | 215M | #define STYLE_MARKER_CHAR '\002' |
39 | | |
40 | | /* Cached mapping symbol state. */ |
41 | | enum map_type |
42 | | { |
43 | | MAP_INSN, |
44 | | MAP_DATA |
45 | | }; |
46 | | |
47 | | static aarch64_feature_set arch_variant; /* See select_aarch64_variant. */ |
48 | | static enum map_type last_type; |
49 | | static int last_mapping_sym = -1; |
50 | | static bfd_vma last_stop_offset = 0; |
51 | | static bfd_vma last_mapping_addr = 0; |
52 | | |
53 | | /* Other options */ |
54 | | static int no_aliases = 0; /* If set disassemble as most general inst. */ |
55 | | static int no_notes = 1; /* If set do not print disassemble notes in the |
56 | | output as comments. */ |
57 | | |
58 | | /* Currently active instruction sequence. */ |
59 | | static aarch64_instr_sequence insn_sequence; |
60 | | |
61 | | static void |
62 | | set_default_aarch64_dis_options (struct disassemble_info *info ATTRIBUTE_UNUSED) |
63 | 0 | { |
64 | 0 | } |
65 | | |
66 | | static void |
67 | | parse_aarch64_dis_option (const char *option, unsigned int len ATTRIBUTE_UNUSED) |
68 | 0 | { |
69 | | /* Try to match options that are simple flags */ |
70 | 0 | if (startswith (option, "no-aliases")) |
71 | 0 | { |
72 | 0 | no_aliases = 1; |
73 | 0 | return; |
74 | 0 | } |
75 | | |
76 | 0 | if (startswith (option, "aliases")) |
77 | 0 | { |
78 | 0 | no_aliases = 0; |
79 | 0 | return; |
80 | 0 | } |
81 | | |
82 | 0 | if (startswith (option, "no-notes")) |
83 | 0 | { |
84 | 0 | no_notes = 1; |
85 | 0 | return; |
86 | 0 | } |
87 | | |
88 | 0 | if (startswith (option, "notes")) |
89 | 0 | { |
90 | 0 | no_notes = 0; |
91 | 0 | return; |
92 | 0 | } |
93 | | |
94 | | #ifdef DEBUG_AARCH64 |
95 | | if (startswith (option, "debug_dump")) |
96 | | { |
97 | | debug_dump = 1; |
98 | | return; |
99 | | } |
100 | | #endif /* DEBUG_AARCH64 */ |
101 | | |
102 | | /* Invalid option. */ |
103 | 0 | opcodes_error_handler (_("unrecognised disassembler option: %s"), option); |
104 | 0 | } |
105 | | |
106 | | static void |
107 | | parse_aarch64_dis_options (const char *options) |
108 | 0 | { |
109 | 0 | const char *option_end; |
110 | |
|
111 | 0 | if (options == NULL) |
112 | 0 | return; |
113 | | |
114 | 0 | while (*options != '\0') |
115 | 0 | { |
116 | | /* Skip empty options. */ |
117 | 0 | if (*options == ',') |
118 | 0 | { |
119 | 0 | options++; |
120 | 0 | continue; |
121 | 0 | } |
122 | | |
123 | | /* We know that *options is neither NUL or a comma. */ |
124 | 0 | option_end = options + 1; |
125 | 0 | while (*option_end != ',' && *option_end != '\0') |
126 | 0 | option_end++; |
127 | |
|
128 | 0 | parse_aarch64_dis_option (options, option_end - options); |
129 | | |
130 | | /* Go on to the next one. If option_end points to a comma, it |
131 | | will be skipped above. */ |
132 | 0 | options = option_end; |
133 | 0 | } |
134 | 0 | } |
135 | | |
136 | | /* Functions doing the instruction disassembling. */ |
137 | | |
138 | | /* The unnamed arguments consist of the number of fields and information about |
139 | | these fields where the VALUE will be extracted from CODE and returned. |
140 | | MASK can be zero or the base mask of the opcode. |
141 | | |
142 | | N.B. the fields are required to be in such an order than the most signficant |
143 | | field for VALUE comes the first, e.g. the <index> in |
144 | | SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>] |
145 | | is encoded in H:L:M in some cases, the fields H:L:M should be passed in |
146 | | the order of H, L, M. */ |
147 | | |
148 | | aarch64_insn |
149 | | extract_fields (aarch64_insn code, aarch64_insn mask, ...) |
150 | 1.44M | { |
151 | 1.44M | uint32_t num; |
152 | 1.44M | const aarch64_field *field; |
153 | 1.44M | enum aarch64_field_kind kind; |
154 | 1.44M | va_list va; |
155 | | |
156 | 1.44M | va_start (va, mask); |
157 | 1.44M | num = va_arg (va, uint32_t); |
158 | 1.44M | assert (num <= 5); |
159 | 1.44M | aarch64_insn value = 0x0; |
160 | 4.77M | while (num--) |
161 | 3.33M | { |
162 | 3.33M | kind = va_arg (va, enum aarch64_field_kind); |
163 | 3.33M | field = &fields[kind]; |
164 | 3.33M | value <<= field->width; |
165 | 3.33M | value |= extract_field (kind, code, mask); |
166 | 3.33M | } |
167 | 1.44M | va_end (va); |
168 | 1.44M | return value; |
169 | 1.44M | } |
170 | | |
171 | | /* Extract the value of all fields in SELF->fields after START from |
172 | | instruction CODE. The least significant bit comes from the final field. */ |
173 | | |
174 | | static aarch64_insn |
175 | | extract_all_fields_after (const aarch64_operand *self, unsigned int start, |
176 | | aarch64_insn code) |
177 | 3.53M | { |
178 | 3.53M | aarch64_insn value; |
179 | 3.53M | unsigned int i; |
180 | 3.53M | enum aarch64_field_kind kind; |
181 | | |
182 | 3.53M | value = 0; |
183 | 3.53M | for (i = start; |
184 | 7.83M | i < ARRAY_SIZE (self->fields) && self->fields[i] != FLD_NIL; ++i) |
185 | 4.29M | { |
186 | 4.29M | kind = self->fields[i]; |
187 | 4.29M | value <<= fields[kind].width; |
188 | 4.29M | value |= extract_field (kind, code, 0); |
189 | 4.29M | } |
190 | 3.53M | return value; |
191 | 3.53M | } |
192 | | |
193 | | /* Extract the value of all fields in SELF->fields from instruction CODE. |
194 | | The least significant bit comes from the final field. */ |
195 | | |
196 | | static aarch64_insn |
197 | | extract_all_fields (const aarch64_operand *self, aarch64_insn code) |
198 | 3.52M | { |
199 | 3.52M | return extract_all_fields_after (self, 0, code); |
200 | 3.52M | } |
201 | | |
202 | | /* Sign-extend bit I of VALUE. */ |
203 | | static inline uint64_t |
204 | | sign_extend (aarch64_insn value, unsigned i) |
205 | 2.32M | { |
206 | 2.32M | uint64_t ret, sign; |
207 | | |
208 | 2.32M | assert (i < 32); |
209 | 2.32M | ret = value; |
210 | 2.32M | sign = (uint64_t) 1 << i; |
211 | 2.32M | return ((ret & (sign + sign - 1)) ^ sign) - sign; |
212 | 2.32M | } |
213 | | |
214 | | /* N.B. the following inline helpfer functions create a dependency on the |
215 | | order of operand qualifier enumerators. */ |
216 | | |
217 | | /* Given VALUE, return qualifier for a general purpose register. */ |
218 | | static inline enum aarch64_opnd_qualifier |
219 | | get_greg_qualifier_from_value (aarch64_insn value) |
220 | 2.79M | { |
221 | 2.79M | enum aarch64_opnd_qualifier qualifier = AARCH64_OPND_QLF_W + value; |
222 | 2.79M | assert (value <= 0x1 |
223 | 2.79M | && aarch64_get_qualifier_standard_value (qualifier) == value); |
224 | 2.79M | return qualifier; |
225 | 2.79M | } |
226 | | |
227 | | /* Given VALUE, return qualifier for a vector register. This does not support |
228 | | decoding instructions that accept the 2H vector type. */ |
229 | | |
230 | | static inline enum aarch64_opnd_qualifier |
231 | | get_vreg_qualifier_from_value (aarch64_insn value) |
232 | 216k | { |
233 | 216k | enum aarch64_opnd_qualifier qualifier = AARCH64_OPND_QLF_V_8B + value; |
234 | | |
235 | | /* Instructions using vector type 2H should not call this function. Skip over |
236 | | the 2H qualifier. */ |
237 | 216k | if (qualifier >= AARCH64_OPND_QLF_V_2H) |
238 | 161k | qualifier += 1; |
239 | | |
240 | 216k | assert (value <= 0x8 |
241 | 216k | && aarch64_get_qualifier_standard_value (qualifier) == value); |
242 | 216k | return qualifier; |
243 | 216k | } |
244 | | |
245 | | /* Given VALUE, return qualifier for an FP or AdvSIMD scalar register. */ |
246 | | static inline enum aarch64_opnd_qualifier |
247 | | get_sreg_qualifier_from_value (aarch64_insn value) |
248 | 188k | { |
249 | 188k | enum aarch64_opnd_qualifier qualifier = AARCH64_OPND_QLF_S_B + value; |
250 | | |
251 | 188k | assert (value <= 0x4 |
252 | 188k | && aarch64_get_qualifier_standard_value (qualifier) == value); |
253 | 188k | return qualifier; |
254 | 188k | } |
255 | | |
256 | | /* Given the instruction in *INST which is probably half way through the |
257 | | decoding and our caller wants to know the expected qualifier for operand |
258 | | I. Return such a qualifier if we can establish it; otherwise return |
259 | | AARCH64_OPND_QLF_NIL. */ |
260 | | |
261 | | static aarch64_opnd_qualifier_t |
262 | | get_expected_qualifier (const aarch64_inst *inst, int i) |
263 | 1.13M | { |
264 | 1.13M | aarch64_opnd_qualifier_seq_t qualifiers; |
265 | | /* Should not be called if the qualifier is known. */ |
266 | 1.13M | assert (inst->operands[i].qualifier == AARCH64_OPND_QLF_NIL); |
267 | 1.13M | int invalid_count; |
268 | 1.13M | if (aarch64_find_best_match (inst, inst->opcode->qualifiers_list, |
269 | 1.13M | i, qualifiers, &invalid_count)) |
270 | 1.10M | return qualifiers[i]; |
271 | 27.2k | else |
272 | 27.2k | return AARCH64_OPND_QLF_NIL; |
273 | 1.13M | } |
274 | | |
275 | | /* Operand extractors. */ |
276 | | |
277 | | bool |
278 | | aarch64_ext_none (const aarch64_operand *self ATTRIBUTE_UNUSED, |
279 | | aarch64_opnd_info *info ATTRIBUTE_UNUSED, |
280 | | const aarch64_insn code ATTRIBUTE_UNUSED, |
281 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
282 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
283 | 132 | { |
284 | 132 | return true; |
285 | 132 | } |
286 | | |
287 | | bool |
288 | | aarch64_ext_regno (const aarch64_operand *self, aarch64_opnd_info *info, |
289 | | const aarch64_insn code, |
290 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
291 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
292 | 9.27M | { |
293 | 9.27M | info->reg.regno = (extract_field (self->fields[0], code, 0) |
294 | 9.27M | + get_operand_specific_data (self)); |
295 | 9.27M | return true; |
296 | 9.27M | } |
297 | | |
298 | | bool |
299 | | aarch64_ext_regno_pair (const aarch64_operand *self ATTRIBUTE_UNUSED, aarch64_opnd_info *info, |
300 | | const aarch64_insn code ATTRIBUTE_UNUSED, |
301 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
302 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
303 | 2.96k | { |
304 | 2.96k | assert (info->idx == 1 |
305 | 2.96k | || info->idx ==3); |
306 | 2.96k | info->reg.regno = inst->operands[info->idx - 1].reg.regno + 1; |
307 | 2.96k | return true; |
308 | 2.96k | } |
309 | | |
310 | | /* e.g. IC <ic_op>{, <Xt>}. */ |
311 | | bool |
312 | | aarch64_ext_regrt_sysins (const aarch64_operand *self, aarch64_opnd_info *info, |
313 | | const aarch64_insn code, |
314 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
315 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
316 | 5 | { |
317 | 5 | info->reg.regno = extract_field (self->fields[0], code, 0); |
318 | 5 | assert (info->idx == 1 |
319 | 5 | && (aarch64_get_operand_class (inst->operands[0].type) |
320 | 5 | == AARCH64_OPND_CLASS_SYSTEM)); |
321 | | /* This will make the constraint checking happy and more importantly will |
322 | | help the disassembler determine whether this operand is optional or |
323 | | not. */ |
324 | 5 | info->present = aarch64_sys_ins_reg_has_xt (inst->operands[0].sysins_op); |
325 | | |
326 | 5 | return true; |
327 | 5 | } |
328 | | |
329 | | /* e.g. SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>]. */ |
330 | | bool |
331 | | aarch64_ext_reglane (const aarch64_operand *self, aarch64_opnd_info *info, |
332 | | const aarch64_insn code, |
333 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
334 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
335 | 87.3k | { |
336 | | /* regno */ |
337 | 87.3k | info->reglane.regno = extract_field (self->fields[0], code, |
338 | 87.3k | inst->opcode->mask); |
339 | | |
340 | | /* Index and/or type. */ |
341 | 87.3k | if (inst->opcode->iclass == asisdone |
342 | 87.3k | || inst->opcode->iclass == asimdins) |
343 | 5.42k | { |
344 | 5.42k | if (info->type == AARCH64_OPND_En |
345 | 5.42k | && inst->opcode->operands[0] == AARCH64_OPND_Ed) |
346 | 1.95k | { |
347 | 1.95k | unsigned shift; |
348 | | /* index2 for e.g. INS <Vd>.<Ts>[<index1>], <Vn>.<Ts>[<index2>]. */ |
349 | 1.95k | assert (info->idx == 1); /* Vn */ |
350 | 1.95k | aarch64_insn value = extract_field (FLD_imm4_11, code, 0); |
351 | | /* Depend on AARCH64_OPND_Ed to determine the qualifier. */ |
352 | 1.95k | info->qualifier = get_expected_qualifier (inst, info->idx); |
353 | 1.95k | shift = get_logsz (aarch64_get_qualifier_esize (info->qualifier)); |
354 | 1.95k | info->reglane.index = value >> shift; |
355 | 1.95k | } |
356 | 3.46k | else |
357 | 3.46k | { |
358 | | /* index and type for e.g. DUP <V><d>, <Vn>.<T>[<index>]. |
359 | | imm5<3:0> <V> |
360 | | 0000 RESERVED |
361 | | xxx1 B |
362 | | xx10 H |
363 | | x100 S |
364 | | 1000 D */ |
365 | 3.46k | int pos = -1; |
366 | 3.46k | aarch64_insn value = extract_field (FLD_imm5, code, 0); |
367 | 7.85k | while (++pos <= 3 && (value & 0x1) == 0) |
368 | 4.38k | value >>= 1; |
369 | 3.46k | if (pos > 3) |
370 | 630 | return false; |
371 | 2.83k | info->qualifier = get_sreg_qualifier_from_value (pos); |
372 | 2.83k | info->reglane.index = (unsigned) (value >> 1); |
373 | 2.83k | } |
374 | 5.42k | } |
375 | 81.9k | else if (inst->opcode->iclass == dotproduct) |
376 | 6.55k | { |
377 | | /* Need information in other operand(s) to help decoding. */ |
378 | 6.55k | info->qualifier = get_expected_qualifier (inst, info->idx); |
379 | 6.55k | switch (info->qualifier) |
380 | 6.55k | { |
381 | 3.26k | case AARCH64_OPND_QLF_S_4B: |
382 | 3.58k | case AARCH64_OPND_QLF_S_2H: |
383 | | /* L:H */ |
384 | 3.58k | info->reglane.index = extract_fields (code, 0, 2, FLD_H, FLD_L); |
385 | 3.58k | info->reglane.regno &= 0x1f; |
386 | 3.58k | break; |
387 | 2.96k | default: |
388 | 2.96k | return false; |
389 | 6.55k | } |
390 | 6.55k | } |
391 | 75.3k | else if (inst->opcode->iclass == cryptosm3) |
392 | 1.22k | { |
393 | | /* index for e.g. SM3TT2A <Vd>.4S, <Vn>.4S, <Vm>S[<imm2>]. */ |
394 | 1.22k | info->reglane.index = extract_field (FLD_SM3_imm2, code, 0); |
395 | 1.22k | } |
396 | 74.1k | else |
397 | 74.1k | { |
398 | | /* Index only for e.g. SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>] |
399 | | or SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>]. */ |
400 | | |
401 | | /* Need information in other operand(s) to help decoding. */ |
402 | 74.1k | info->qualifier = get_expected_qualifier (inst, info->idx); |
403 | 74.1k | switch (info->qualifier) |
404 | 74.1k | { |
405 | 33.1k | case AARCH64_OPND_QLF_S_H: |
406 | 33.1k | if (info->type == AARCH64_OPND_Em16) |
407 | 26.0k | { |
408 | | /* h:l:m */ |
409 | 26.0k | info->reglane.index = extract_fields (code, 0, 3, FLD_H, FLD_L, |
410 | 26.0k | FLD_M); |
411 | 26.0k | info->reglane.regno &= 0xf; |
412 | 26.0k | } |
413 | 7.13k | else |
414 | 7.13k | { |
415 | | /* h:l */ |
416 | 7.13k | info->reglane.index = extract_fields (code, 0, 2, FLD_H, FLD_L); |
417 | 7.13k | } |
418 | 33.1k | break; |
419 | 14.7k | case AARCH64_OPND_QLF_S_S: |
420 | | /* h:l */ |
421 | 14.7k | info->reglane.index = extract_fields (code, 0, 2, FLD_H, FLD_L); |
422 | 14.7k | break; |
423 | 1.93k | case AARCH64_OPND_QLF_S_D: |
424 | | /* H */ |
425 | 1.93k | info->reglane.index = extract_field (FLD_H, code, 0); |
426 | 1.93k | break; |
427 | 24.3k | default: |
428 | 24.3k | return false; |
429 | 74.1k | } |
430 | | |
431 | 49.8k | if (inst->opcode->op == OP_FCMLA_ELEM |
432 | 49.8k | && info->qualifier != AARCH64_OPND_QLF_S_H) |
433 | 1.45k | { |
434 | | /* Complex operand takes two elements. */ |
435 | 1.45k | if (info->reglane.index & 1) |
436 | 860 | return false; |
437 | 599 | info->reglane.index /= 2; |
438 | 599 | } |
439 | 49.8k | } |
440 | | |
441 | 58.5k | return true; |
442 | 87.3k | } |
443 | | |
444 | | bool |
445 | | aarch64_ext_reglist (const aarch64_operand *self, aarch64_opnd_info *info, |
446 | | const aarch64_insn code, |
447 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
448 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
449 | 11.7k | { |
450 | | /* R */ |
451 | 11.7k | info->reglist.first_regno = extract_field (self->fields[0], code, 0); |
452 | | /* len */ |
453 | 11.7k | info->reglist.num_regs = extract_field (FLD_len, code, 0) + 1; |
454 | 11.7k | info->reglist.stride = 1; |
455 | 11.7k | return true; |
456 | 11.7k | } |
457 | | |
458 | | /* Decode Rt and opcode fields of Vt in AdvSIMD load/store instructions. */ |
459 | | bool |
460 | | aarch64_ext_ldst_reglist (const aarch64_operand *self ATTRIBUTE_UNUSED, |
461 | | aarch64_opnd_info *info, const aarch64_insn code, |
462 | | const aarch64_inst *inst, |
463 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
464 | 88.2k | { |
465 | 88.2k | aarch64_insn value; |
466 | | /* Number of elements in each structure to be loaded/stored. */ |
467 | 88.2k | unsigned expected_num = get_opcode_dependent_value (inst->opcode); |
468 | | |
469 | 88.2k | struct |
470 | 88.2k | { |
471 | 88.2k | unsigned is_reserved; |
472 | 88.2k | unsigned num_regs; |
473 | 88.2k | unsigned num_elements; |
474 | 88.2k | } data [] = |
475 | 88.2k | { {0, 4, 4}, |
476 | 88.2k | {1, 4, 4}, |
477 | 88.2k | {0, 4, 1}, |
478 | 88.2k | {0, 4, 2}, |
479 | 88.2k | {0, 3, 3}, |
480 | 88.2k | {1, 3, 3}, |
481 | 88.2k | {0, 3, 1}, |
482 | 88.2k | {0, 1, 1}, |
483 | 88.2k | {0, 2, 2}, |
484 | 88.2k | {1, 2, 2}, |
485 | 88.2k | {0, 2, 1}, |
486 | 88.2k | }; |
487 | | |
488 | | /* Rt */ |
489 | 88.2k | info->reglist.first_regno = extract_field (FLD_Rt, code, 0); |
490 | | /* opcode */ |
491 | 88.2k | value = extract_field (FLD_opcode, code, 0); |
492 | | /* PR 21595: Check for a bogus value. */ |
493 | 88.2k | if (value >= ARRAY_SIZE (data)) |
494 | 33.1k | return false; |
495 | 55.0k | if (expected_num != data[value].num_elements || data[value].is_reserved) |
496 | 35.5k | return false; |
497 | 19.5k | info->reglist.num_regs = data[value].num_regs; |
498 | 19.5k | info->reglist.stride = 1; |
499 | | |
500 | 19.5k | return true; |
501 | 55.0k | } |
502 | | |
503 | | /* Decode Rt and S fields of Vt in AdvSIMD load single structure to all |
504 | | lanes instructions. */ |
505 | | bool |
506 | | aarch64_ext_ldst_reglist_r (const aarch64_operand *self ATTRIBUTE_UNUSED, |
507 | | aarch64_opnd_info *info, const aarch64_insn code, |
508 | | const aarch64_inst *inst, |
509 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
510 | 2.14k | { |
511 | 2.14k | aarch64_insn value; |
512 | | |
513 | | /* Rt */ |
514 | 2.14k | info->reglist.first_regno = extract_field (FLD_Rt, code, 0); |
515 | | /* S */ |
516 | 2.14k | value = extract_field (FLD_S, code, 0); |
517 | | |
518 | | /* Number of registers is equal to the number of elements in |
519 | | each structure to be loaded/stored. */ |
520 | 2.14k | info->reglist.num_regs = get_opcode_dependent_value (inst->opcode); |
521 | 2.14k | assert (info->reglist.num_regs >= 1 && info->reglist.num_regs <= 4); |
522 | | |
523 | | /* Except when it is LD1R. */ |
524 | 2.14k | if (info->reglist.num_regs == 1 && value == (aarch64_insn) 1) |
525 | 0 | info->reglist.num_regs = 2; |
526 | | |
527 | 2.14k | info->reglist.stride = 1; |
528 | 2.14k | return true; |
529 | 2.14k | } |
530 | | |
531 | | /* Decode Q, opcode<2:1>, S, size and Rt fields of Vt in AdvSIMD |
532 | | load/store single element instructions. */ |
533 | | bool |
534 | | aarch64_ext_ldst_elemlist (const aarch64_operand *self ATTRIBUTE_UNUSED, |
535 | | aarch64_opnd_info *info, const aarch64_insn code, |
536 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
537 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
538 | 50.8k | { |
539 | 50.8k | aarch64_field field = {0, 0}; |
540 | 50.8k | aarch64_insn QSsize; /* fields Q:S:size. */ |
541 | 50.8k | aarch64_insn opcodeh2; /* opcode<2:1> */ |
542 | | |
543 | | /* Rt */ |
544 | 50.8k | info->reglist.first_regno = extract_field (FLD_Rt, code, 0); |
545 | | |
546 | | /* Decode the index, opcode<2:1> and size. */ |
547 | 50.8k | gen_sub_field (FLD_asisdlso_opcode, 1, 2, &field); |
548 | 50.8k | opcodeh2 = extract_field_2 (&field, code, 0); |
549 | 50.8k | QSsize = extract_fields (code, 0, 3, FLD_Q, FLD_S, FLD_vldst_size); |
550 | 50.8k | switch (opcodeh2) |
551 | 50.8k | { |
552 | 18.0k | case 0x0: |
553 | 18.0k | info->qualifier = AARCH64_OPND_QLF_S_B; |
554 | | /* Index encoded in "Q:S:size". */ |
555 | 18.0k | info->reglist.index = QSsize; |
556 | 18.0k | break; |
557 | 13.5k | case 0x1: |
558 | 13.5k | if (QSsize & 0x1) |
559 | | /* UND. */ |
560 | 4.66k | return false; |
561 | 8.87k | info->qualifier = AARCH64_OPND_QLF_S_H; |
562 | | /* Index encoded in "Q:S:size<1>". */ |
563 | 8.87k | info->reglist.index = QSsize >> 1; |
564 | 8.87k | break; |
565 | 8.99k | case 0x2: |
566 | 8.99k | if ((QSsize >> 1) & 0x1) |
567 | | /* UND. */ |
568 | 4.75k | return false; |
569 | 4.24k | if ((QSsize & 0x1) == 0) |
570 | 1.95k | { |
571 | 1.95k | info->qualifier = AARCH64_OPND_QLF_S_S; |
572 | | /* Index encoded in "Q:S". */ |
573 | 1.95k | info->reglist.index = QSsize >> 2; |
574 | 1.95k | } |
575 | 2.28k | else |
576 | 2.28k | { |
577 | 2.28k | if (extract_field (FLD_S, code, 0)) |
578 | | /* UND */ |
579 | 900 | return false; |
580 | 1.38k | info->qualifier = AARCH64_OPND_QLF_S_D; |
581 | | /* Index encoded in "Q". */ |
582 | 1.38k | info->reglist.index = QSsize >> 3; |
583 | 1.38k | } |
584 | 3.34k | break; |
585 | 10.2k | default: |
586 | 10.2k | return false; |
587 | 50.8k | } |
588 | | |
589 | 30.3k | info->reglist.has_index = 1; |
590 | 30.3k | info->reglist.num_regs = 0; |
591 | 30.3k | info->reglist.stride = 1; |
592 | | /* Number of registers is equal to the number of elements in |
593 | | each structure to be loaded/stored. */ |
594 | 30.3k | info->reglist.num_regs = get_opcode_dependent_value (inst->opcode); |
595 | 30.3k | assert (info->reglist.num_regs >= 1 && info->reglist.num_regs <= 4); |
596 | | |
597 | 30.3k | return true; |
598 | 30.3k | } |
599 | | |
600 | | /* Decode fields immh:immb and/or Q for e.g. |
601 | | SSHR <Vd>.<T>, <Vn>.<T>, #<shift> |
602 | | or SSHR <V><d>, <V><n>, #<shift>. */ |
603 | | |
604 | | bool |
605 | | aarch64_ext_advsimd_imm_shift (const aarch64_operand *self ATTRIBUTE_UNUSED, |
606 | | aarch64_opnd_info *info, const aarch64_insn code, |
607 | | const aarch64_inst *inst, |
608 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
609 | 34.8k | { |
610 | 34.8k | int pos; |
611 | 34.8k | aarch64_insn Q, imm, immh; |
612 | 34.8k | enum aarch64_insn_class iclass = inst->opcode->iclass; |
613 | | |
614 | 34.8k | immh = extract_field (FLD_immh, code, 0); |
615 | 34.8k | if (immh == 0) |
616 | 1.88k | return false; |
617 | 32.9k | imm = extract_fields (code, 0, 2, FLD_immh, FLD_immb); |
618 | 32.9k | pos = 4; |
619 | | /* Get highest set bit in immh. */ |
620 | 55.5k | while (--pos >= 0 && (immh & 0x8) == 0) |
621 | 22.5k | immh <<= 1; |
622 | | |
623 | 32.9k | assert ((iclass == asimdshf || iclass == asisdshf) |
624 | 32.9k | && (info->type == AARCH64_OPND_IMM_VLSR |
625 | 32.9k | || info->type == AARCH64_OPND_IMM_VLSL)); |
626 | | |
627 | 32.9k | if (iclass == asimdshf) |
628 | 22.8k | { |
629 | 22.8k | Q = extract_field (FLD_Q, code, 0); |
630 | | /* immh Q <T> |
631 | | 0000 x SEE AdvSIMD modified immediate |
632 | | 0001 0 8B |
633 | | 0001 1 16B |
634 | | 001x 0 4H |
635 | | 001x 1 8H |
636 | | 01xx 0 2S |
637 | | 01xx 1 4S |
638 | | 1xxx 0 RESERVED |
639 | | 1xxx 1 2D */ |
640 | 22.8k | info->qualifier = |
641 | 22.8k | get_vreg_qualifier_from_value ((pos << 1) | (int) Q); |
642 | 22.8k | } |
643 | 10.1k | else |
644 | 10.1k | info->qualifier = get_sreg_qualifier_from_value (pos); |
645 | | |
646 | 32.9k | if (info->type == AARCH64_OPND_IMM_VLSR) |
647 | | /* immh <shift> |
648 | | 0000 SEE AdvSIMD modified immediate |
649 | | 0001 (16-UInt(immh:immb)) |
650 | | 001x (32-UInt(immh:immb)) |
651 | | 01xx (64-UInt(immh:immb)) |
652 | | 1xxx (128-UInt(immh:immb)) */ |
653 | 21.4k | info->imm.value = (16 << pos) - imm; |
654 | 11.4k | else |
655 | | /* immh:immb |
656 | | immh <shift> |
657 | | 0000 SEE AdvSIMD modified immediate |
658 | | 0001 (UInt(immh:immb)-8) |
659 | | 001x (UInt(immh:immb)-16) |
660 | | 01xx (UInt(immh:immb)-32) |
661 | | 1xxx (UInt(immh:immb)-64) */ |
662 | 11.4k | info->imm.value = imm - (8 << pos); |
663 | | |
664 | 32.9k | return true; |
665 | 32.9k | } |
666 | | |
667 | | /* Decode shift immediate for e.g. sshr (imm). */ |
668 | | bool |
669 | | aarch64_ext_shll_imm (const aarch64_operand *self ATTRIBUTE_UNUSED, |
670 | | aarch64_opnd_info *info, const aarch64_insn code, |
671 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
672 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
673 | 30 | { |
674 | 30 | int64_t imm; |
675 | 30 | aarch64_insn val; |
676 | 30 | val = extract_field (FLD_size, code, 0); |
677 | 30 | switch (val) |
678 | 30 | { |
679 | 4 | case 0: imm = 8; break; |
680 | 3 | case 1: imm = 16; break; |
681 | 23 | case 2: imm = 32; break; |
682 | 0 | default: return false; |
683 | 30 | } |
684 | 30 | info->imm.value = imm; |
685 | 30 | return true; |
686 | 30 | } |
687 | | |
688 | | /* Decode imm for e.g. BFM <Wd>, <Wn>, #<immr>, #<imms>. |
689 | | value in the field(s) will be extracted as unsigned immediate value. */ |
690 | | bool |
691 | | aarch64_ext_imm (const aarch64_operand *self, aarch64_opnd_info *info, |
692 | | const aarch64_insn code, |
693 | | const aarch64_inst *inst, |
694 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
695 | 3.51M | { |
696 | 3.51M | uint64_t imm; |
697 | | |
698 | 3.51M | imm = extract_all_fields (self, code); |
699 | | |
700 | 3.51M | if (operand_need_sign_extension (self)) |
701 | 1.60M | imm = sign_extend (imm, get_operand_fields_width (self) - 1); |
702 | | |
703 | 3.51M | if (operand_need_shift_by_two (self)) |
704 | 1.06M | imm <<= 2; |
705 | 2.44M | else if (operand_need_shift_by_three (self)) |
706 | 0 | imm <<= 3; |
707 | 2.44M | else if (operand_need_shift_by_four (self)) |
708 | 4.82k | imm <<= 4; |
709 | | |
710 | 3.51M | if (info->type == AARCH64_OPND_ADDR_ADRP) |
711 | 203k | imm <<= 12; |
712 | | |
713 | 3.51M | if (inst->operands[0].type == AARCH64_OPND_PSTATEFIELD |
714 | 3.51M | && inst->operands[0].sysreg.flags & F_IMM_IN_CRM) |
715 | 0 | imm &= PSTATE_DECODE_CRM_IMM (inst->operands[0].sysreg.flags); |
716 | | |
717 | 3.51M | info->imm.value = imm; |
718 | 3.51M | return true; |
719 | 3.51M | } |
720 | | |
721 | | /* Decode imm and its shifter for e.g. MOVZ <Wd>, #<imm16>{, LSL #<shift>}. */ |
722 | | bool |
723 | | aarch64_ext_imm_half (const aarch64_operand *self, aarch64_opnd_info *info, |
724 | | const aarch64_insn code, |
725 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
726 | | aarch64_operand_error *errors) |
727 | 129k | { |
728 | 129k | aarch64_ext_imm (self, info, code, inst, errors); |
729 | 129k | info->shifter.kind = AARCH64_MOD_LSL; |
730 | 129k | info->shifter.amount = extract_field (FLD_hw, code, 0) << 4; |
731 | 129k | return true; |
732 | 129k | } |
733 | | |
734 | | /* Decode cmode and "a:b:c:d:e:f:g:h" for e.g. |
735 | | MOVI <Vd>.<T>, #<imm8> {, LSL #<amount>}. */ |
736 | | bool |
737 | | aarch64_ext_advsimd_imm_modified (const aarch64_operand *self ATTRIBUTE_UNUSED, |
738 | | aarch64_opnd_info *info, |
739 | | const aarch64_insn code, |
740 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
741 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
742 | 2.05k | { |
743 | 2.05k | uint64_t imm; |
744 | 2.05k | enum aarch64_opnd_qualifier opnd0_qualifier = inst->operands[0].qualifier; |
745 | 2.05k | aarch64_field field = {0, 0}; |
746 | | |
747 | 2.05k | assert (info->idx == 1); |
748 | | |
749 | 2.05k | if (info->type == AARCH64_OPND_SIMD_FPIMM) |
750 | 194 | info->imm.is_fp = 1; |
751 | | |
752 | | /* a:b:c:d:e:f:g:h */ |
753 | 2.05k | imm = extract_fields (code, 0, 2, FLD_abc, FLD_defgh); |
754 | 2.05k | if (!info->imm.is_fp && aarch64_get_qualifier_esize (opnd0_qualifier) == 8) |
755 | 29 | { |
756 | | /* Either MOVI <Dd>, #<imm> |
757 | | or MOVI <Vd>.2D, #<imm>. |
758 | | <imm> is a 64-bit immediate |
759 | | 'aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh', |
760 | | encoded in "a:b:c:d:e:f:g:h". */ |
761 | 29 | int i; |
762 | 29 | unsigned abcdefgh = imm; |
763 | 261 | for (imm = 0ull, i = 0; i < 8; i++) |
764 | 232 | if (((abcdefgh >> i) & 0x1) != 0) |
765 | 104 | imm |= 0xffull << (8 * i); |
766 | 29 | } |
767 | 2.05k | info->imm.value = imm; |
768 | | |
769 | | /* cmode */ |
770 | 2.05k | info->qualifier = get_expected_qualifier (inst, info->idx); |
771 | 2.05k | switch (info->qualifier) |
772 | 2.05k | { |
773 | 223 | case AARCH64_OPND_QLF_NIL: |
774 | | /* no shift */ |
775 | 223 | info->shifter.kind = AARCH64_MOD_NONE; |
776 | 223 | return 1; |
777 | 1.72k | case AARCH64_OPND_QLF_LSL: |
778 | | /* shift zeros */ |
779 | 1.72k | info->shifter.kind = AARCH64_MOD_LSL; |
780 | 1.72k | switch (aarch64_get_qualifier_esize (opnd0_qualifier)) |
781 | 1.72k | { |
782 | 1.07k | case 4: gen_sub_field (FLD_cmode, 1, 2, &field); break; /* per word */ |
783 | 608 | case 2: gen_sub_field (FLD_cmode, 1, 1, &field); break; /* per half */ |
784 | 40 | case 1: gen_sub_field (FLD_cmode, 1, 0, &field); break; /* per byte */ |
785 | 0 | default: return false; |
786 | 1.72k | } |
787 | | /* 00: 0; 01: 8; 10:16; 11:24. */ |
788 | 1.72k | info->shifter.amount = extract_field_2 (&field, code, 0) << 3; |
789 | 1.72k | break; |
790 | 108 | case AARCH64_OPND_QLF_MSL: |
791 | | /* shift ones */ |
792 | 108 | info->shifter.kind = AARCH64_MOD_MSL; |
793 | 108 | gen_sub_field (FLD_cmode, 0, 1, &field); /* per word */ |
794 | 108 | info->shifter.amount = extract_field_2 (&field, code, 0) ? 16 : 8; |
795 | 108 | break; |
796 | 0 | default: |
797 | 0 | return false; |
798 | 2.05k | } |
799 | | |
800 | 1.82k | return true; |
801 | 2.05k | } |
802 | | |
803 | | /* Decode an 8-bit floating-point immediate. */ |
804 | | bool |
805 | | aarch64_ext_fpimm (const aarch64_operand *self, aarch64_opnd_info *info, |
806 | | const aarch64_insn code, |
807 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
808 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
809 | 2.16k | { |
810 | 2.16k | info->imm.value = extract_all_fields (self, code); |
811 | 2.16k | info->imm.is_fp = 1; |
812 | 2.16k | return true; |
813 | 2.16k | } |
814 | | |
815 | | /* Decode a 1-bit rotate immediate (#90 or #270). */ |
816 | | bool |
817 | | aarch64_ext_imm_rotate1 (const aarch64_operand *self, aarch64_opnd_info *info, |
818 | | const aarch64_insn code, |
819 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
820 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
821 | 1.70k | { |
822 | 1.70k | uint64_t rot = extract_field (self->fields[0], code, 0); |
823 | 1.70k | assert (rot < 2U); |
824 | 1.70k | info->imm.value = rot * 180 + 90; |
825 | 1.70k | return true; |
826 | 1.70k | } |
827 | | |
828 | | /* Decode a 2-bit rotate immediate (#0, #90, #180 or #270). */ |
829 | | bool |
830 | | aarch64_ext_imm_rotate2 (const aarch64_operand *self, aarch64_opnd_info *info, |
831 | | const aarch64_insn code, |
832 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
833 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
834 | 23.2k | { |
835 | 23.2k | uint64_t rot = extract_field (self->fields[0], code, 0); |
836 | 23.2k | assert (rot < 4U); |
837 | 23.2k | info->imm.value = rot * 90; |
838 | 23.2k | return true; |
839 | 23.2k | } |
840 | | |
841 | | /* Decode scale for e.g. SCVTF <Dd>, <Wn>, #<fbits>. */ |
842 | | bool |
843 | | aarch64_ext_fbits (const aarch64_operand *self ATTRIBUTE_UNUSED, |
844 | | aarch64_opnd_info *info, const aarch64_insn code, |
845 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
846 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
847 | 4.99k | { |
848 | 4.99k | info->imm.value = 64- extract_field (FLD_scale, code, 0); |
849 | 4.99k | return true; |
850 | 4.99k | } |
851 | | |
852 | | /* Decode arithmetic immediate for e.g. |
853 | | SUBS <Wd>, <Wn|WSP>, #<imm> {, <shift>}. */ |
854 | | bool |
855 | | aarch64_ext_aimm (const aarch64_operand *self ATTRIBUTE_UNUSED, |
856 | | aarch64_opnd_info *info, const aarch64_insn code, |
857 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
858 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
859 | 513k | { |
860 | 513k | aarch64_insn value; |
861 | | |
862 | 513k | info->shifter.kind = AARCH64_MOD_LSL; |
863 | | /* shift */ |
864 | 513k | value = extract_field (FLD_shift, code, 0); |
865 | 513k | if (value >= 2) |
866 | 149k | return false; |
867 | 364k | info->shifter.amount = value ? 12 : 0; |
868 | | /* imm12 (unsigned) */ |
869 | 364k | info->imm.value = extract_field (FLD_imm12, code, 0); |
870 | | |
871 | 364k | return true; |
872 | 513k | } |
873 | | |
874 | | /* Return true if VALUE is a valid logical immediate encoding, storing the |
875 | | decoded value in *RESULT if so. ESIZE is the number of bytes in the |
876 | | decoded immediate. */ |
877 | | static bool |
878 | | decode_limm (uint32_t esize, aarch64_insn value, int64_t *result) |
879 | 348k | { |
880 | 348k | uint64_t imm, mask; |
881 | 348k | uint32_t N, R, S; |
882 | 348k | unsigned simd_size; |
883 | | |
884 | | /* value is N:immr:imms. */ |
885 | 348k | S = value & 0x3f; |
886 | 348k | R = (value >> 6) & 0x3f; |
887 | 348k | N = (value >> 12) & 0x1; |
888 | | |
889 | | /* The immediate value is S+1 bits to 1, left rotated by SIMDsize - R |
890 | | (in other words, right rotated by R), then replicated. */ |
891 | 348k | if (N != 0) |
892 | 145k | { |
893 | 145k | simd_size = 64; |
894 | 145k | mask = 0xffffffffffffffffull; |
895 | 145k | } |
896 | 202k | else |
897 | 202k | { |
898 | 202k | switch (S) |
899 | 202k | { |
900 | 140k | case 0x00 ... 0x1f: /* 0xxxxx */ simd_size = 32; break; |
901 | 34.0k | case 0x20 ... 0x2f: /* 10xxxx */ simd_size = 16; S &= 0xf; break; |
902 | 15.1k | case 0x30 ... 0x37: /* 110xxx */ simd_size = 8; S &= 0x7; break; |
903 | 8.22k | case 0x38 ... 0x3b: /* 1110xx */ simd_size = 4; S &= 0x3; break; |
904 | 1.93k | case 0x3c ... 0x3d: /* 11110x */ simd_size = 2; S &= 0x1; break; |
905 | 3.47k | default: return false; |
906 | 202k | } |
907 | 199k | mask = (1ull << simd_size) - 1; |
908 | | /* Top bits are IGNORED. */ |
909 | 199k | R &= simd_size - 1; |
910 | 199k | } |
911 | | |
912 | 344k | if (simd_size > esize * 8) |
913 | 78.0k | return false; |
914 | | |
915 | | /* NOTE: if S = simd_size - 1 we get 0xf..f which is rejected. */ |
916 | 266k | if (S == simd_size - 1) |
917 | 5.90k | return false; |
918 | | /* S+1 consecutive bits to 1. */ |
919 | | /* NOTE: S can't be 63 due to detection above. */ |
920 | 260k | imm = (1ull << (S + 1)) - 1; |
921 | | /* Rotate to the left by simd_size - R. */ |
922 | 260k | if (R != 0) |
923 | 221k | imm = ((imm << (simd_size - R)) & mask) | (imm >> R); |
924 | | /* Replicate the value according to SIMD size. */ |
925 | 260k | switch (simd_size) |
926 | 260k | { |
927 | 965 | case 2: imm = (imm << 2) | imm; |
928 | | /* Fall through. */ |
929 | 8.11k | case 4: imm = (imm << 4) | imm; |
930 | | /* Fall through. */ |
931 | 22.3k | case 8: imm = (imm << 8) | imm; |
932 | | /* Fall through. */ |
933 | 55.4k | case 16: imm = (imm << 16) | imm; |
934 | | /* Fall through. */ |
935 | 194k | case 32: imm = (imm << 32) | imm; |
936 | | /* Fall through. */ |
937 | 260k | case 64: break; |
938 | 0 | default: return 0; |
939 | 260k | } |
940 | | |
941 | 260k | *result = imm & ~((uint64_t) -1 << (esize * 4) << (esize * 4)); |
942 | | |
943 | 260k | return true; |
944 | 260k | } |
945 | | |
946 | | /* Decode a logical immediate for e.g. ORR <Wd|WSP>, <Wn>, #<imm>. */ |
947 | | bool |
948 | | aarch64_ext_limm (const aarch64_operand *self, |
949 | | aarch64_opnd_info *info, const aarch64_insn code, |
950 | | const aarch64_inst *inst, |
951 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
952 | 348k | { |
953 | 348k | uint32_t esize; |
954 | 348k | aarch64_insn value; |
955 | | |
956 | 348k | value = extract_fields (code, 0, 3, self->fields[0], self->fields[1], |
957 | 348k | self->fields[2]); |
958 | 348k | esize = aarch64_get_qualifier_esize (inst->operands[0].qualifier); |
959 | 348k | return decode_limm (esize, value, &info->imm.value); |
960 | 348k | } |
961 | | |
962 | | /* Decode a logical immediate for the BIC alias of AND (etc.). */ |
963 | | bool |
964 | | aarch64_ext_inv_limm (const aarch64_operand *self, |
965 | | aarch64_opnd_info *info, const aarch64_insn code, |
966 | | const aarch64_inst *inst, |
967 | | aarch64_operand_error *errors) |
968 | 0 | { |
969 | 0 | if (!aarch64_ext_limm (self, info, code, inst, errors)) |
970 | 0 | return false; |
971 | 0 | info->imm.value = ~info->imm.value; |
972 | 0 | return true; |
973 | 0 | } |
974 | | |
975 | | /* Decode Ft for e.g. STR <Qt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}] |
976 | | or LDP <Qt1>, <Qt2>, [<Xn|SP>], #<imm>. */ |
977 | | bool |
978 | | aarch64_ext_ft (const aarch64_operand *self ATTRIBUTE_UNUSED, |
979 | | aarch64_opnd_info *info, |
980 | | const aarch64_insn code, const aarch64_inst *inst, |
981 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
982 | 788k | { |
983 | 788k | aarch64_insn value; |
984 | | |
985 | | /* Rt */ |
986 | 788k | info->reg.regno = extract_field (FLD_Rt, code, 0); |
987 | | |
988 | | /* size */ |
989 | 788k | value = extract_field (FLD_ldst_size, code, 0); |
990 | 788k | if (inst->opcode->iclass == ldstpair_indexed |
991 | 788k | || inst->opcode->iclass == ldstnapair_offs |
992 | 788k | || inst->opcode->iclass == ldstpair_off |
993 | 788k | || inst->opcode->iclass == loadlit) |
994 | 524k | { |
995 | 524k | enum aarch64_opnd_qualifier qualifier; |
996 | 524k | switch (value) |
997 | 524k | { |
998 | 125k | case 0: qualifier = AARCH64_OPND_QLF_S_S; break; |
999 | 172k | case 1: qualifier = AARCH64_OPND_QLF_S_D; break; |
1000 | 115k | case 2: qualifier = AARCH64_OPND_QLF_S_Q; break; |
1001 | 111k | default: return false; |
1002 | 524k | } |
1003 | 413k | info->qualifier = qualifier; |
1004 | 413k | } |
1005 | 263k | else |
1006 | 263k | { |
1007 | | /* opc1:size */ |
1008 | 263k | value = extract_fields (code, 0, 2, FLD_opc1, FLD_ldst_size); |
1009 | 263k | if (value > 0x4) |
1010 | 102k | return false; |
1011 | 161k | info->qualifier = get_sreg_qualifier_from_value (value); |
1012 | 161k | } |
1013 | | |
1014 | 574k | return true; |
1015 | 788k | } |
1016 | | |
1017 | | /* Decode the address operand for e.g. STXRB <Ws>, <Wt>, [<Xn|SP>{,#0}]. */ |
1018 | | bool |
1019 | | aarch64_ext_addr_simple (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1020 | | aarch64_opnd_info *info, |
1021 | | aarch64_insn code, |
1022 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1023 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1024 | 222k | { |
1025 | | /* Rn */ |
1026 | 222k | info->addr.base_regno = extract_field (FLD_Rn, code, 0); |
1027 | 222k | return true; |
1028 | 222k | } |
1029 | | |
1030 | | /* Decode the address operand for e.g. |
1031 | | stlur <Xt>, [<Xn|SP>{, <amount>}]. */ |
1032 | | bool |
1033 | | aarch64_ext_addr_offset (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1034 | | aarch64_opnd_info *info, |
1035 | | aarch64_insn code, const aarch64_inst *inst, |
1036 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1037 | 18.5k | { |
1038 | 18.5k | info->qualifier = get_expected_qualifier (inst, info->idx); |
1039 | | |
1040 | | /* Rn */ |
1041 | 18.5k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1042 | | |
1043 | | /* simm9 */ |
1044 | 18.5k | aarch64_insn imm = extract_fields (code, 0, 1, self->fields[1]); |
1045 | 18.5k | info->addr.offset.imm = sign_extend (imm, 8); |
1046 | 18.5k | if (extract_field (self->fields[2], code, 0) == 1) { |
1047 | 0 | info->addr.writeback = 1; |
1048 | 0 | info->addr.preind = 1; |
1049 | 0 | } |
1050 | 18.5k | return true; |
1051 | 18.5k | } |
1052 | | |
1053 | | /* Decode the address operand for e.g. |
1054 | | STR <Qt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */ |
1055 | | bool |
1056 | | aarch64_ext_addr_regoff (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1057 | | aarch64_opnd_info *info, |
1058 | | aarch64_insn code, const aarch64_inst *inst, |
1059 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1060 | 39.1k | { |
1061 | 39.1k | aarch64_insn S, value; |
1062 | | |
1063 | | /* Rn */ |
1064 | 39.1k | info->addr.base_regno = extract_field (FLD_Rn, code, 0); |
1065 | | /* Rm */ |
1066 | 39.1k | info->addr.offset.regno = extract_field (FLD_Rm, code, 0); |
1067 | | /* option */ |
1068 | 39.1k | value = extract_field (FLD_option, code, 0); |
1069 | 39.1k | info->shifter.kind = |
1070 | 39.1k | aarch64_get_operand_modifier_from_value (value, true /* extend_p */); |
1071 | | /* Fix-up the shifter kind; although the table-driven approach is |
1072 | | efficient, it is slightly inflexible, thus needing this fix-up. */ |
1073 | 39.1k | if (info->shifter.kind == AARCH64_MOD_UXTX) |
1074 | 6.65k | info->shifter.kind = AARCH64_MOD_LSL; |
1075 | | /* S */ |
1076 | 39.1k | S = extract_field (FLD_S, code, 0); |
1077 | 39.1k | if (S == 0) |
1078 | 18.1k | { |
1079 | 18.1k | info->shifter.amount = 0; |
1080 | 18.1k | info->shifter.amount_present = 0; |
1081 | 18.1k | } |
1082 | 20.9k | else |
1083 | 20.9k | { |
1084 | 20.9k | int size; |
1085 | | /* Need information in other operand(s) to help achieve the decoding |
1086 | | from 'S' field. */ |
1087 | 20.9k | info->qualifier = get_expected_qualifier (inst, info->idx); |
1088 | | /* Get the size of the data element that is accessed, which may be |
1089 | | different from that of the source register size, e.g. in strb/ldrb. */ |
1090 | 20.9k | size = aarch64_get_qualifier_esize (info->qualifier); |
1091 | 20.9k | info->shifter.amount = get_logsz (size); |
1092 | 20.9k | info->shifter.amount_present = 1; |
1093 | 20.9k | } |
1094 | | |
1095 | 39.1k | return true; |
1096 | 39.1k | } |
1097 | | |
1098 | | /* Decode the address operand for e.g. LDRSW <Xt>, [<Xn|SP>], #<simm>. */ |
1099 | | bool |
1100 | | aarch64_ext_addr_simm (const aarch64_operand *self, aarch64_opnd_info *info, |
1101 | | aarch64_insn code, const aarch64_inst *inst, |
1102 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1103 | 696k | { |
1104 | 696k | aarch64_insn imm; |
1105 | 696k | info->qualifier = get_expected_qualifier (inst, info->idx); |
1106 | | |
1107 | | /* Rn */ |
1108 | 696k | info->addr.base_regno = extract_field (FLD_Rn, code, 0); |
1109 | | /* simm (imm9 or imm7) */ |
1110 | 696k | imm = extract_field (self->fields[0], code, 0); |
1111 | 696k | info->addr.offset.imm = sign_extend (imm, fields[self->fields[0]].width - 1); |
1112 | 696k | if (self->fields[0] == FLD_imm7 |
1113 | 696k | || info->qualifier == AARCH64_OPND_QLF_imm_tag) |
1114 | | /* scaled immediate in ld/st pair instructions. */ |
1115 | 559k | info->addr.offset.imm *= aarch64_get_qualifier_esize (info->qualifier); |
1116 | | /* qualifier */ |
1117 | 696k | if (inst->opcode->iclass == ldst_unscaled |
1118 | 696k | || inst->opcode->iclass == ldstnapair_offs |
1119 | 696k | || inst->opcode->iclass == ldstpair_off |
1120 | 696k | || inst->opcode->iclass == ldst_unpriv) |
1121 | 395k | info->addr.writeback = 0; |
1122 | 300k | else |
1123 | 300k | { |
1124 | | /* pre/post- index */ |
1125 | 300k | info->addr.writeback = 1; |
1126 | 300k | if (extract_field (self->fields[1], code, 0) == 1) |
1127 | 149k | info->addr.preind = 1; |
1128 | 151k | else |
1129 | 151k | info->addr.postind = 1; |
1130 | 300k | } |
1131 | | |
1132 | 696k | return true; |
1133 | 696k | } |
1134 | | |
1135 | | /* Decode the address operand for e.g. LDRSW <Xt>, [<Xn|SP>{, #<simm>}]. */ |
1136 | | bool |
1137 | | aarch64_ext_addr_uimm12 (const aarch64_operand *self, aarch64_opnd_info *info, |
1138 | | aarch64_insn code, |
1139 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1140 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1141 | 304k | { |
1142 | 304k | int shift; |
1143 | 304k | info->qualifier = get_expected_qualifier (inst, info->idx); |
1144 | 304k | shift = get_logsz (aarch64_get_qualifier_esize (info->qualifier)); |
1145 | | /* Rn */ |
1146 | 304k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1147 | | /* uimm12 */ |
1148 | 304k | info->addr.offset.imm = extract_field (self->fields[1], code, 0) << shift; |
1149 | 304k | return true; |
1150 | 304k | } |
1151 | | |
1152 | | /* Decode the address operand for e.g. LDRAA <Xt>, [<Xn|SP>{, #<simm>}]. */ |
1153 | | bool |
1154 | | aarch64_ext_addr_simm10 (const aarch64_operand *self, aarch64_opnd_info *info, |
1155 | | aarch64_insn code, |
1156 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1157 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1158 | 11.1k | { |
1159 | 11.1k | aarch64_insn imm; |
1160 | | |
1161 | 11.1k | info->qualifier = get_expected_qualifier (inst, info->idx); |
1162 | | /* Rn */ |
1163 | 11.1k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1164 | | /* simm10 */ |
1165 | 11.1k | imm = extract_fields (code, 0, 2, self->fields[1], self->fields[2]); |
1166 | 11.1k | info->addr.offset.imm = sign_extend (imm, 9) << 3; |
1167 | 11.1k | if (extract_field (self->fields[3], code, 0) == 1) { |
1168 | 6.08k | info->addr.writeback = 1; |
1169 | 6.08k | info->addr.preind = 1; |
1170 | 6.08k | } |
1171 | 11.1k | return true; |
1172 | 11.1k | } |
1173 | | |
1174 | | /* Decode the address operand for e.g. |
1175 | | LD1 {<Vt>.<T>, <Vt2>.<T>, <Vt3>.<T>}, [<Xn|SP>], <Xm|#<amount>>. */ |
1176 | | bool |
1177 | | aarch64_ext_simd_addr_post (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1178 | | aarch64_opnd_info *info, |
1179 | | aarch64_insn code, const aarch64_inst *inst, |
1180 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1181 | 35.5k | { |
1182 | | /* The opcode dependent area stores the number of elements in |
1183 | | each structure to be loaded/stored. */ |
1184 | 35.5k | int is_ld1r = get_opcode_dependent_value (inst->opcode) == 1; |
1185 | | |
1186 | | /* Rn */ |
1187 | 35.5k | info->addr.base_regno = extract_field (FLD_Rn, code, 0); |
1188 | | /* Rm | #<amount> */ |
1189 | 35.5k | info->addr.offset.regno = extract_field (FLD_Rm, code, 0); |
1190 | 35.5k | if (info->addr.offset.regno == 31) |
1191 | 1.11k | { |
1192 | 1.11k | if (inst->opcode->operands[0] == AARCH64_OPND_LVt_AL) |
1193 | | /* Special handling of loading single structure to all lane. */ |
1194 | 27 | info->addr.offset.imm = (is_ld1r ? 1 |
1195 | 27 | : inst->operands[0].reglist.num_regs) |
1196 | 27 | * aarch64_get_qualifier_esize (inst->operands[0].qualifier); |
1197 | 1.08k | else |
1198 | 1.08k | info->addr.offset.imm = inst->operands[0].reglist.num_regs |
1199 | 1.08k | * aarch64_get_qualifier_esize (inst->operands[0].qualifier) |
1200 | 1.08k | * aarch64_get_qualifier_nelem (inst->operands[0].qualifier); |
1201 | 1.11k | } |
1202 | 34.4k | else |
1203 | 34.4k | info->addr.offset.is_reg = 1; |
1204 | 35.5k | info->addr.writeback = 1; |
1205 | | |
1206 | 35.5k | return true; |
1207 | 35.5k | } |
1208 | | |
1209 | | /* Decode the condition operand for e.g. CSEL <Xd>, <Xn>, <Xm>, <cond>. */ |
1210 | | bool |
1211 | | aarch64_ext_cond (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1212 | | aarch64_opnd_info *info, |
1213 | | aarch64_insn code, const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1214 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1215 | 28.7k | { |
1216 | 28.7k | aarch64_insn value; |
1217 | | /* cond */ |
1218 | 28.7k | value = extract_field (FLD_cond, code, 0); |
1219 | 28.7k | info->cond = get_cond_from_value (value); |
1220 | 28.7k | return true; |
1221 | 28.7k | } |
1222 | | |
1223 | | /* Decode the system register operand for e.g. MRS <Xt>, <systemreg>. */ |
1224 | | bool |
1225 | | aarch64_ext_sysreg (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1226 | | aarch64_opnd_info *info, |
1227 | | aarch64_insn code, |
1228 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1229 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1230 | 7.03k | { |
1231 | | /* op0:op1:CRn:CRm:op2 */ |
1232 | 7.03k | info->sysreg.value = extract_fields (code, 0, 5, FLD_op0, FLD_op1, FLD_CRn, |
1233 | 7.03k | FLD_CRm, FLD_op2); |
1234 | 7.03k | info->sysreg.flags = 0; |
1235 | | |
1236 | | /* If a system instruction, check which restrictions should be on the register |
1237 | | value during decoding, these will be enforced then. */ |
1238 | 7.03k | if (inst->opcode->iclass == ic_system) |
1239 | 7.03k | { |
1240 | | /* Check to see if it's read-only, else check if it's write only. |
1241 | | if it's both or unspecified don't care. */ |
1242 | 7.03k | if ((inst->opcode->flags & (F_SYS_READ | F_SYS_WRITE)) == F_SYS_READ) |
1243 | 3.51k | info->sysreg.flags = F_REG_READ; |
1244 | 3.52k | else if ((inst->opcode->flags & (F_SYS_READ | F_SYS_WRITE)) |
1245 | 3.52k | == F_SYS_WRITE) |
1246 | 3.52k | info->sysreg.flags = F_REG_WRITE; |
1247 | 7.03k | } |
1248 | | |
1249 | 7.03k | return true; |
1250 | 7.03k | } |
1251 | | |
1252 | | /* Decode the PSTATE field operand for e.g. MSR <pstatefield>, #<imm>. */ |
1253 | | bool |
1254 | | aarch64_ext_pstatefield (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1255 | | aarch64_opnd_info *info, aarch64_insn code, |
1256 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1257 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1258 | 0 | { |
1259 | 0 | int i; |
1260 | 0 | aarch64_insn fld_crm = extract_field (FLD_CRm, code, 0); |
1261 | | /* op1:op2 */ |
1262 | 0 | info->pstatefield = extract_fields (code, 0, 2, FLD_op1, FLD_op2); |
1263 | 0 | for (i = 0; aarch64_pstatefields[i].name != NULL; ++i) |
1264 | 0 | if (aarch64_pstatefields[i].value == (aarch64_insn)info->pstatefield) |
1265 | 0 | { |
1266 | | /* PSTATEFIELD name can be encoded partially in CRm[3:1]. */ |
1267 | 0 | uint32_t flags = aarch64_pstatefields[i].flags; |
1268 | 0 | if ((flags & F_REG_IN_CRM) |
1269 | 0 | && ((fld_crm & 0xe) != PSTATE_DECODE_CRM (flags))) |
1270 | 0 | continue; |
1271 | 0 | info->sysreg.flags = flags; |
1272 | 0 | return true; |
1273 | 0 | } |
1274 | | /* Reserved value in <pstatefield>. */ |
1275 | 0 | return false; |
1276 | 0 | } |
1277 | | |
1278 | | /* Decode the system instruction op operand for e.g. AT <at_op>, <Xt>. */ |
1279 | | bool |
1280 | | aarch64_ext_sysins_op (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1281 | | aarch64_opnd_info *info, |
1282 | | aarch64_insn code, |
1283 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1284 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1285 | 2.63k | { |
1286 | 2.63k | int i; |
1287 | 2.63k | aarch64_insn value; |
1288 | 2.63k | const aarch64_sys_ins_reg *sysins_ops; |
1289 | | /* op0:op1:CRn:CRm:op2 */ |
1290 | 2.63k | value = extract_fields (code, 0, 5, |
1291 | 2.63k | FLD_op0, FLD_op1, FLD_CRn, |
1292 | 2.63k | FLD_CRm, FLD_op2); |
1293 | | |
1294 | 2.63k | switch (info->type) |
1295 | 2.63k | { |
1296 | 655 | case AARCH64_OPND_SYSREG_AT: sysins_ops = aarch64_sys_regs_at; break; |
1297 | 657 | case AARCH64_OPND_SYSREG_DC: sysins_ops = aarch64_sys_regs_dc; break; |
1298 | 657 | case AARCH64_OPND_SYSREG_IC: sysins_ops = aarch64_sys_regs_ic; break; |
1299 | 662 | case AARCH64_OPND_SYSREG_TLBI: sysins_ops = aarch64_sys_regs_tlbi; break; |
1300 | 0 | case AARCH64_OPND_SYSREG_SR: |
1301 | 0 | sysins_ops = aarch64_sys_regs_sr; |
1302 | | /* Let's remove op2 for rctx. Refer to comments in the definition of |
1303 | | aarch64_sys_regs_sr[]. */ |
1304 | 0 | value = value & ~(0x7); |
1305 | 0 | break; |
1306 | 0 | default: return false; |
1307 | 2.63k | } |
1308 | | |
1309 | 87.3k | for (i = 0; sysins_ops[i].name != NULL; ++i) |
1310 | 84.7k | if (sysins_ops[i].value == value) |
1311 | 17 | { |
1312 | 17 | info->sysins_op = sysins_ops + i; |
1313 | 17 | DEBUG_TRACE ("%s found value: %x, has_xt: %d, i: %d.", |
1314 | 17 | info->sysins_op->name, |
1315 | 17 | (unsigned)info->sysins_op->value, |
1316 | 17 | aarch64_sys_ins_reg_has_xt (info->sysins_op), i); |
1317 | 17 | return true; |
1318 | 17 | } |
1319 | | |
1320 | 2.61k | return false; |
1321 | 2.63k | } |
1322 | | |
1323 | | /* Decode the memory barrier option operand for e.g. DMB <option>|#<imm>. */ |
1324 | | |
1325 | | bool |
1326 | | aarch64_ext_barrier (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1327 | | aarch64_opnd_info *info, |
1328 | | aarch64_insn code, |
1329 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1330 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1331 | 0 | { |
1332 | | /* CRm */ |
1333 | 0 | info->barrier = aarch64_barrier_options + extract_field (FLD_CRm, code, 0); |
1334 | 0 | return true; |
1335 | 0 | } |
1336 | | |
1337 | | /* Decode the memory barrier option operand for DSB <option>nXS|#<imm>. */ |
1338 | | |
1339 | | bool |
1340 | | aarch64_ext_barrier_dsb_nxs (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1341 | | aarch64_opnd_info *info, |
1342 | | aarch64_insn code, |
1343 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1344 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1345 | 0 | { |
1346 | | /* For the DSB nXS barrier variant immediate is encoded in 2-bit field. */ |
1347 | 0 | aarch64_insn field = extract_field (FLD_CRm_dsb_nxs, code, 0); |
1348 | 0 | info->barrier = aarch64_barrier_dsb_nxs_options + field; |
1349 | 0 | return true; |
1350 | 0 | } |
1351 | | |
1352 | | /* Decode the prefetch operation option operand for e.g. |
1353 | | PRFM <prfop>, [<Xn|SP>{, #<pimm>}]. */ |
1354 | | |
1355 | | bool |
1356 | | aarch64_ext_prfop (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1357 | | aarch64_opnd_info *info, |
1358 | | aarch64_insn code, const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1359 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1360 | 53.5k | { |
1361 | | /* prfop in Rt */ |
1362 | 53.5k | info->prfop = aarch64_prfops + extract_field (FLD_Rt, code, 0); |
1363 | 53.5k | return true; |
1364 | 53.5k | } |
1365 | | |
1366 | | /* Decode the hint number for an alias taking an operand. Set info->hint_option |
1367 | | to the matching name/value pair in aarch64_hint_options. */ |
1368 | | |
1369 | | bool |
1370 | | aarch64_ext_hint (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1371 | | aarch64_opnd_info *info, |
1372 | | aarch64_insn code, |
1373 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1374 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1375 | 0 | { |
1376 | | /* CRm:op2. */ |
1377 | 0 | unsigned hint_number; |
1378 | 0 | int i; |
1379 | |
|
1380 | 0 | hint_number = extract_fields (code, 0, 2, FLD_CRm, FLD_op2); |
1381 | |
|
1382 | 0 | for (i = 0; aarch64_hint_options[i].name != NULL; i++) |
1383 | 0 | { |
1384 | 0 | if (hint_number == HINT_VAL (aarch64_hint_options[i].value)) |
1385 | 0 | { |
1386 | 0 | info->hint_option = &(aarch64_hint_options[i]); |
1387 | 0 | return true; |
1388 | 0 | } |
1389 | 0 | } |
1390 | | |
1391 | 0 | return false; |
1392 | 0 | } |
1393 | | |
1394 | | /* Decode the extended register operand for e.g. |
1395 | | STR <Qt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */ |
1396 | | bool |
1397 | | aarch64_ext_reg_extended (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1398 | | aarch64_opnd_info *info, |
1399 | | aarch64_insn code, |
1400 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1401 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1402 | 54.7k | { |
1403 | 54.7k | aarch64_insn value; |
1404 | | |
1405 | | /* Rm */ |
1406 | 54.7k | info->reg.regno = extract_field (FLD_Rm, code, 0); |
1407 | | /* option */ |
1408 | 54.7k | value = extract_field (FLD_option, code, 0); |
1409 | 54.7k | info->shifter.kind = |
1410 | 54.7k | aarch64_get_operand_modifier_from_value (value, true /* extend_p */); |
1411 | | /* imm3 */ |
1412 | 54.7k | info->shifter.amount = extract_field (FLD_imm3_10, code, 0); |
1413 | | |
1414 | | /* This makes the constraint checking happy. */ |
1415 | 54.7k | info->shifter.operator_present = 1; |
1416 | | |
1417 | | /* Assume inst->operands[0].qualifier has been resolved. */ |
1418 | 54.7k | assert (inst->operands[0].qualifier != AARCH64_OPND_QLF_NIL); |
1419 | 54.7k | info->qualifier = AARCH64_OPND_QLF_W; |
1420 | 54.7k | if (inst->operands[0].qualifier == AARCH64_OPND_QLF_X |
1421 | 54.7k | && (info->shifter.kind == AARCH64_MOD_UXTX |
1422 | 23.7k | || info->shifter.kind == AARCH64_MOD_SXTX)) |
1423 | 6.83k | info->qualifier = AARCH64_OPND_QLF_X; |
1424 | | |
1425 | 54.7k | return true; |
1426 | 54.7k | } |
1427 | | |
1428 | | /* Decode the shifted register operand for e.g. |
1429 | | SUBS <Xd>, <Xn>, <Xm> {, <shift> #<amount>}. */ |
1430 | | bool |
1431 | | aarch64_ext_reg_shifted (const aarch64_operand *self ATTRIBUTE_UNUSED, |
1432 | | aarch64_opnd_info *info, |
1433 | | aarch64_insn code, |
1434 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1435 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1436 | 771k | { |
1437 | 771k | aarch64_insn value; |
1438 | | |
1439 | | /* Rm */ |
1440 | 771k | info->reg.regno = extract_field (FLD_Rm, code, 0); |
1441 | | /* shift */ |
1442 | 771k | value = extract_field (FLD_shift, code, 0); |
1443 | 771k | info->shifter.kind = |
1444 | 771k | aarch64_get_operand_modifier_from_value (value, false /* extend_p */); |
1445 | 771k | if (info->shifter.kind == AARCH64_MOD_ROR |
1446 | 771k | && inst->opcode->iclass != log_shift) |
1447 | | /* ROR is not available for the shifted register operand in arithmetic |
1448 | | instructions. */ |
1449 | 37.3k | return false; |
1450 | | /* imm6 */ |
1451 | 734k | info->shifter.amount = extract_field (FLD_imm6_10, code, 0); |
1452 | | |
1453 | | /* This makes the constraint checking happy. */ |
1454 | 734k | info->shifter.operator_present = 1; |
1455 | | |
1456 | 734k | return true; |
1457 | 771k | } |
1458 | | |
1459 | | /* Decode an SVE address [<base>, #<offset>*<factor>, MUL VL], |
1460 | | where <offset> is given by the OFFSET parameter and where <factor> is |
1461 | | 1 plus SELF's operand-dependent value. fields[0] specifies the field |
1462 | | that holds <base>. */ |
1463 | | static bool |
1464 | | aarch64_ext_sve_addr_reg_mul_vl (const aarch64_operand *self, |
1465 | | aarch64_opnd_info *info, aarch64_insn code, |
1466 | | int64_t offset) |
1467 | 58.9k | { |
1468 | 58.9k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1469 | 58.9k | info->addr.offset.imm = offset * (1 + get_operand_specific_data (self)); |
1470 | 58.9k | info->addr.offset.is_reg = false; |
1471 | 58.9k | info->addr.writeback = false; |
1472 | 58.9k | info->addr.preind = true; |
1473 | 58.9k | if (offset != 0) |
1474 | 56.4k | info->shifter.kind = AARCH64_MOD_MUL_VL; |
1475 | 58.9k | info->shifter.amount = 1; |
1476 | 58.9k | info->shifter.operator_present = (info->addr.offset.imm != 0); |
1477 | 58.9k | info->shifter.amount_present = false; |
1478 | 58.9k | return true; |
1479 | 58.9k | } |
1480 | | |
1481 | | /* Decode an SVE address [<base>, #<simm4>*<factor>, MUL VL], |
1482 | | where <simm4> is a 4-bit signed value and where <factor> is 1 plus |
1483 | | SELF's operand-dependent value. fields[0] specifies the field that |
1484 | | holds <base>. <simm4> is encoded in the SVE_imm4 field. */ |
1485 | | bool |
1486 | | aarch64_ext_sve_addr_ri_s4xvl (const aarch64_operand *self, |
1487 | | aarch64_opnd_info *info, aarch64_insn code, |
1488 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1489 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1490 | 48.1k | { |
1491 | 48.1k | int offset; |
1492 | | |
1493 | 48.1k | offset = extract_field (FLD_SVE_imm4, code, 0); |
1494 | 48.1k | offset = ((offset + 8) & 15) - 8; |
1495 | 48.1k | return aarch64_ext_sve_addr_reg_mul_vl (self, info, code, offset); |
1496 | 48.1k | } |
1497 | | |
1498 | | /* Decode an SVE address [<base>, #<simm6>*<factor>, MUL VL], |
1499 | | where <simm6> is a 6-bit signed value and where <factor> is 1 plus |
1500 | | SELF's operand-dependent value. fields[0] specifies the field that |
1501 | | holds <base>. <simm6> is encoded in the SVE_imm6 field. */ |
1502 | | bool |
1503 | | aarch64_ext_sve_addr_ri_s6xvl (const aarch64_operand *self, |
1504 | | aarch64_opnd_info *info, aarch64_insn code, |
1505 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1506 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1507 | 2.86k | { |
1508 | 2.86k | int offset; |
1509 | | |
1510 | 2.86k | offset = extract_field (FLD_SVE_imm6, code, 0); |
1511 | 2.86k | offset = (((offset + 32) & 63) - 32); |
1512 | 2.86k | return aarch64_ext_sve_addr_reg_mul_vl (self, info, code, offset); |
1513 | 2.86k | } |
1514 | | |
1515 | | /* Decode an SVE address [<base>, #<simm9>*<factor>, MUL VL], |
1516 | | where <simm9> is a 9-bit signed value and where <factor> is 1 plus |
1517 | | SELF's operand-dependent value. fields[0] specifies the field that |
1518 | | holds <base>. <simm9> is encoded in the concatenation of the SVE_imm6 |
1519 | | and imm3 fields, with imm3 being the less-significant part. */ |
1520 | | bool |
1521 | | aarch64_ext_sve_addr_ri_s9xvl (const aarch64_operand *self, |
1522 | | aarch64_opnd_info *info, |
1523 | | aarch64_insn code, |
1524 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1525 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1526 | 7.89k | { |
1527 | 7.89k | int offset; |
1528 | | |
1529 | 7.89k | offset = extract_fields (code, 0, 2, FLD_SVE_imm6, FLD_imm3_10); |
1530 | 7.89k | offset = (((offset + 256) & 511) - 256); |
1531 | 7.89k | return aarch64_ext_sve_addr_reg_mul_vl (self, info, code, offset); |
1532 | 7.89k | } |
1533 | | |
1534 | | /* Decode an SVE address [<base>, #<offset> << <shift>], where <offset> |
1535 | | is given by the OFFSET parameter and where <shift> is SELF's operand- |
1536 | | dependent value. fields[0] specifies the base register field <base>. */ |
1537 | | static bool |
1538 | | aarch64_ext_sve_addr_reg_imm (const aarch64_operand *self, |
1539 | | aarch64_opnd_info *info, aarch64_insn code, |
1540 | | int64_t offset) |
1541 | 48.3k | { |
1542 | 48.3k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1543 | 48.3k | info->addr.offset.imm = offset * (1 << get_operand_specific_data (self)); |
1544 | 48.3k | info->addr.offset.is_reg = false; |
1545 | 48.3k | info->addr.writeback = false; |
1546 | 48.3k | info->addr.preind = true; |
1547 | 48.3k | info->shifter.operator_present = false; |
1548 | 48.3k | info->shifter.amount_present = false; |
1549 | 48.3k | return true; |
1550 | 48.3k | } |
1551 | | |
1552 | | /* Decode an SVE address [X<n>, #<SVE_imm4> << <shift>], where <SVE_imm4> |
1553 | | is a 4-bit signed number and where <shift> is SELF's operand-dependent |
1554 | | value. fields[0] specifies the base register field. */ |
1555 | | bool |
1556 | | aarch64_ext_sve_addr_ri_s4 (const aarch64_operand *self, |
1557 | | aarch64_opnd_info *info, aarch64_insn code, |
1558 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1559 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1560 | 2.09k | { |
1561 | 2.09k | int offset = sign_extend (extract_field (FLD_SVE_imm4, code, 0), 3); |
1562 | 2.09k | return aarch64_ext_sve_addr_reg_imm (self, info, code, offset); |
1563 | 2.09k | } |
1564 | | |
1565 | | /* Decode an SVE address [X<n>, #<SVE_imm6> << <shift>], where <SVE_imm6> |
1566 | | is a 6-bit unsigned number and where <shift> is SELF's operand-dependent |
1567 | | value. fields[0] specifies the base register field. */ |
1568 | | bool |
1569 | | aarch64_ext_sve_addr_ri_u6 (const aarch64_operand *self, |
1570 | | aarch64_opnd_info *info, aarch64_insn code, |
1571 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1572 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1573 | 26.5k | { |
1574 | 26.5k | int offset = extract_field (FLD_SVE_imm6, code, 0); |
1575 | 26.5k | return aarch64_ext_sve_addr_reg_imm (self, info, code, offset); |
1576 | 26.5k | } |
1577 | | |
1578 | | /* Decode an SVE address [X<n>, X<m>{, LSL #<shift>}], where <shift> |
1579 | | is SELF's operand-dependent value. fields[0] specifies the base |
1580 | | register field and fields[1] specifies the offset register field. */ |
1581 | | bool |
1582 | | aarch64_ext_sve_addr_rr_lsl (const aarch64_operand *self, |
1583 | | aarch64_opnd_info *info, aarch64_insn code, |
1584 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1585 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1586 | 143k | { |
1587 | 143k | int index_regno; |
1588 | | |
1589 | 143k | index_regno = extract_field (self->fields[1], code, 0); |
1590 | 143k | if (index_regno == 31 && (self->flags & OPD_F_NO_ZR) != 0) |
1591 | 1.85k | return false; |
1592 | | |
1593 | 141k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1594 | 141k | info->addr.offset.regno = index_regno; |
1595 | 141k | info->addr.offset.is_reg = true; |
1596 | 141k | info->addr.writeback = false; |
1597 | 141k | info->addr.preind = true; |
1598 | 141k | info->shifter.kind = AARCH64_MOD_LSL; |
1599 | 141k | info->shifter.amount = get_operand_specific_data (self); |
1600 | 141k | info->shifter.operator_present = (info->shifter.amount != 0); |
1601 | 141k | info->shifter.amount_present = (info->shifter.amount != 0); |
1602 | 141k | return true; |
1603 | 143k | } |
1604 | | |
1605 | | /* Decode an SVE address [X<n>, Z<m>.<T>, (S|U)XTW {#<shift>}], where |
1606 | | <shift> is SELF's operand-dependent value. fields[0] specifies the |
1607 | | base register field, fields[1] specifies the offset register field and |
1608 | | fields[2] is a single-bit field that selects SXTW over UXTW. */ |
1609 | | bool |
1610 | | aarch64_ext_sve_addr_rz_xtw (const aarch64_operand *self, |
1611 | | aarch64_opnd_info *info, aarch64_insn code, |
1612 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1613 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1614 | 82.6k | { |
1615 | 82.6k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1616 | 82.6k | info->addr.offset.regno = extract_field (self->fields[1], code, 0); |
1617 | 82.6k | info->addr.offset.is_reg = true; |
1618 | 82.6k | info->addr.writeback = false; |
1619 | 82.6k | info->addr.preind = true; |
1620 | 82.6k | if (extract_field (self->fields[2], code, 0)) |
1621 | 40.1k | info->shifter.kind = AARCH64_MOD_SXTW; |
1622 | 42.5k | else |
1623 | 42.5k | info->shifter.kind = AARCH64_MOD_UXTW; |
1624 | 82.6k | info->shifter.amount = get_operand_specific_data (self); |
1625 | 82.6k | info->shifter.operator_present = true; |
1626 | 82.6k | info->shifter.amount_present = (info->shifter.amount != 0); |
1627 | 82.6k | return true; |
1628 | 82.6k | } |
1629 | | |
1630 | | /* Decode an SVE address [Z<n>.<T>, #<imm5> << <shift>], where <imm5> is a |
1631 | | 5-bit unsigned number and where <shift> is SELF's operand-dependent value. |
1632 | | fields[0] specifies the base register field. */ |
1633 | | bool |
1634 | | aarch64_ext_sve_addr_zi_u5 (const aarch64_operand *self, |
1635 | | aarch64_opnd_info *info, aarch64_insn code, |
1636 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1637 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1638 | 19.7k | { |
1639 | 19.7k | int offset = extract_field (FLD_imm5, code, 0); |
1640 | 19.7k | return aarch64_ext_sve_addr_reg_imm (self, info, code, offset); |
1641 | 19.7k | } |
1642 | | |
1643 | | /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>{, <modifier> {#<msz>}}], |
1644 | | where <modifier> is given by KIND and where <msz> is a 2-bit unsigned |
1645 | | number. fields[0] specifies the base register field and fields[1] |
1646 | | specifies the offset register field. */ |
1647 | | static bool |
1648 | | aarch64_ext_sve_addr_zz (const aarch64_operand *self, aarch64_opnd_info *info, |
1649 | | aarch64_insn code, enum aarch64_modifier_kind kind) |
1650 | 1.20k | { |
1651 | 1.20k | info->addr.base_regno = extract_field (self->fields[0], code, 0); |
1652 | 1.20k | info->addr.offset.regno = extract_field (self->fields[1], code, 0); |
1653 | 1.20k | info->addr.offset.is_reg = true; |
1654 | 1.20k | info->addr.writeback = false; |
1655 | 1.20k | info->addr.preind = true; |
1656 | 1.20k | info->shifter.kind = kind; |
1657 | 1.20k | info->shifter.amount = extract_field (FLD_SVE_msz, code, 0); |
1658 | 1.20k | info->shifter.operator_present = (kind != AARCH64_MOD_LSL |
1659 | 1.20k | || info->shifter.amount != 0); |
1660 | 1.20k | info->shifter.amount_present = (info->shifter.amount != 0); |
1661 | 1.20k | return true; |
1662 | 1.20k | } |
1663 | | |
1664 | | /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>{, LSL #<msz>}], where |
1665 | | <msz> is a 2-bit unsigned number. fields[0] specifies the base register |
1666 | | field and fields[1] specifies the offset register field. */ |
1667 | | bool |
1668 | | aarch64_ext_sve_addr_zz_lsl (const aarch64_operand *self, |
1669 | | aarch64_opnd_info *info, aarch64_insn code, |
1670 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1671 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1672 | 864 | { |
1673 | 864 | return aarch64_ext_sve_addr_zz (self, info, code, AARCH64_MOD_LSL); |
1674 | 864 | } |
1675 | | |
1676 | | /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>, SXTW {#<msz>}], where |
1677 | | <msz> is a 2-bit unsigned number. fields[0] specifies the base register |
1678 | | field and fields[1] specifies the offset register field. */ |
1679 | | bool |
1680 | | aarch64_ext_sve_addr_zz_sxtw (const aarch64_operand *self, |
1681 | | aarch64_opnd_info *info, aarch64_insn code, |
1682 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1683 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1684 | 192 | { |
1685 | 192 | return aarch64_ext_sve_addr_zz (self, info, code, AARCH64_MOD_SXTW); |
1686 | 192 | } |
1687 | | |
1688 | | /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>, UXTW {#<msz>}], where |
1689 | | <msz> is a 2-bit unsigned number. fields[0] specifies the base register |
1690 | | field and fields[1] specifies the offset register field. */ |
1691 | | bool |
1692 | | aarch64_ext_sve_addr_zz_uxtw (const aarch64_operand *self, |
1693 | | aarch64_opnd_info *info, aarch64_insn code, |
1694 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1695 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1696 | 151 | { |
1697 | 151 | return aarch64_ext_sve_addr_zz (self, info, code, AARCH64_MOD_UXTW); |
1698 | 151 | } |
1699 | | |
1700 | | /* Finish decoding an SVE arithmetic immediate, given that INFO already |
1701 | | has the raw field value and that the low 8 bits decode to VALUE. */ |
1702 | | static bool |
1703 | | decode_sve_aimm (aarch64_opnd_info *info, int64_t value) |
1704 | 29.5k | { |
1705 | 29.5k | info->shifter.kind = AARCH64_MOD_LSL; |
1706 | 29.5k | info->shifter.amount = 0; |
1707 | 29.5k | if (info->imm.value & 0x100) |
1708 | 3.38k | { |
1709 | 3.38k | if (value == 0) |
1710 | | /* Decode 0x100 as #0, LSL #8. */ |
1711 | 1 | info->shifter.amount = 8; |
1712 | 3.38k | else |
1713 | 3.38k | value *= 256; |
1714 | 3.38k | } |
1715 | 29.5k | info->shifter.operator_present = (info->shifter.amount != 0); |
1716 | 29.5k | info->shifter.amount_present = (info->shifter.amount != 0); |
1717 | 29.5k | info->imm.value = value; |
1718 | 29.5k | return true; |
1719 | 29.5k | } |
1720 | | |
1721 | | /* Decode an SVE ADD/SUB immediate. */ |
1722 | | bool |
1723 | | aarch64_ext_sve_aimm (const aarch64_operand *self, |
1724 | | aarch64_opnd_info *info, const aarch64_insn code, |
1725 | | const aarch64_inst *inst, |
1726 | | aarch64_operand_error *errors) |
1727 | 870 | { |
1728 | 870 | return (aarch64_ext_imm (self, info, code, inst, errors) |
1729 | 870 | && decode_sve_aimm (info, (uint8_t) info->imm.value)); |
1730 | 870 | } |
1731 | | |
1732 | | bool |
1733 | | aarch64_ext_sve_aligned_reglist (const aarch64_operand *self, |
1734 | | aarch64_opnd_info *info, aarch64_insn code, |
1735 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1736 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1737 | 24.6k | { |
1738 | 24.6k | unsigned int num_regs = get_operand_specific_data (self); |
1739 | 24.6k | unsigned int val = extract_field (self->fields[0], code, 0); |
1740 | 24.6k | info->reglist.first_regno = val * num_regs; |
1741 | 24.6k | info->reglist.num_regs = num_regs; |
1742 | 24.6k | info->reglist.stride = 1; |
1743 | 24.6k | return true; |
1744 | 24.6k | } |
1745 | | |
1746 | | /* Decode an SVE CPY/DUP immediate. */ |
1747 | | bool |
1748 | | aarch64_ext_sve_asimm (const aarch64_operand *self, |
1749 | | aarch64_opnd_info *info, const aarch64_insn code, |
1750 | | const aarch64_inst *inst, |
1751 | | aarch64_operand_error *errors) |
1752 | 28.6k | { |
1753 | 28.6k | return (aarch64_ext_imm (self, info, code, inst, errors) |
1754 | 28.6k | && decode_sve_aimm (info, (int8_t) info->imm.value)); |
1755 | 28.6k | } |
1756 | | |
1757 | | /* Decode a single-bit immediate that selects between #0.5 and #1.0. |
1758 | | The fields array specifies which field to use. */ |
1759 | | bool |
1760 | | aarch64_ext_sve_float_half_one (const aarch64_operand *self, |
1761 | | aarch64_opnd_info *info, aarch64_insn code, |
1762 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1763 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1764 | 0 | { |
1765 | 0 | if (extract_field (self->fields[0], code, 0)) |
1766 | 0 | info->imm.value = 0x3f800000; |
1767 | 0 | else |
1768 | 0 | info->imm.value = 0x3f000000; |
1769 | 0 | info->imm.is_fp = true; |
1770 | 0 | return true; |
1771 | 0 | } |
1772 | | |
1773 | | /* Decode a single-bit immediate that selects between #0.5 and #2.0. |
1774 | | The fields array specifies which field to use. */ |
1775 | | bool |
1776 | | aarch64_ext_sve_float_half_two (const aarch64_operand *self, |
1777 | | aarch64_opnd_info *info, aarch64_insn code, |
1778 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1779 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1780 | 1 | { |
1781 | 1 | if (extract_field (self->fields[0], code, 0)) |
1782 | 1 | info->imm.value = 0x40000000; |
1783 | 0 | else |
1784 | 0 | info->imm.value = 0x3f000000; |
1785 | 1 | info->imm.is_fp = true; |
1786 | 1 | return true; |
1787 | 1 | } |
1788 | | |
1789 | | /* Decode a single-bit immediate that selects between #0.0 and #1.0. |
1790 | | The fields array specifies which field to use. */ |
1791 | | bool |
1792 | | aarch64_ext_sve_float_zero_one (const aarch64_operand *self, |
1793 | | aarch64_opnd_info *info, aarch64_insn code, |
1794 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1795 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1796 | 0 | { |
1797 | 0 | if (extract_field (self->fields[0], code, 0)) |
1798 | 0 | info->imm.value = 0x3f800000; |
1799 | 0 | else |
1800 | 0 | info->imm.value = 0x0; |
1801 | 0 | info->imm.is_fp = true; |
1802 | 0 | return true; |
1803 | 0 | } |
1804 | | |
1805 | | /* Decode ZA tile vector, vector indicator, vector selector, qualifier and |
1806 | | immediate on numerous SME instruction fields such as MOVA. */ |
1807 | | bool |
1808 | | aarch64_ext_sme_za_hv_tiles (const aarch64_operand *self, |
1809 | | aarch64_opnd_info *info, aarch64_insn code, |
1810 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1811 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1812 | 41.4k | { |
1813 | 41.4k | int fld_size = extract_field (self->fields[0], code, 0); |
1814 | 41.4k | int fld_q = extract_field (self->fields[1], code, 0); |
1815 | 41.4k | int fld_v = extract_field (self->fields[2], code, 0); |
1816 | 41.4k | int fld_rv = extract_field (self->fields[3], code, 0); |
1817 | 41.4k | int fld_zan_imm = extract_field (self->fields[4], code, 0); |
1818 | | |
1819 | | /* Deduce qualifier encoded in size and Q fields. */ |
1820 | 41.4k | if (fld_size == 0) |
1821 | 12.5k | { |
1822 | 12.5k | info->indexed_za.regno = 0; |
1823 | 12.5k | info->indexed_za.index.imm = fld_zan_imm; |
1824 | 12.5k | } |
1825 | 28.9k | else if (fld_size == 1) |
1826 | 5.12k | { |
1827 | 5.12k | info->indexed_za.regno = fld_zan_imm >> 3; |
1828 | 5.12k | info->indexed_za.index.imm = fld_zan_imm & 0x07; |
1829 | 5.12k | } |
1830 | 23.8k | else if (fld_size == 2) |
1831 | 5.44k | { |
1832 | 5.44k | info->indexed_za.regno = fld_zan_imm >> 2; |
1833 | 5.44k | info->indexed_za.index.imm = fld_zan_imm & 0x03; |
1834 | 5.44k | } |
1835 | 18.3k | else if (fld_size == 3 && fld_q == 0) |
1836 | 13.7k | { |
1837 | 13.7k | info->indexed_za.regno = fld_zan_imm >> 1; |
1838 | 13.7k | info->indexed_za.index.imm = fld_zan_imm & 0x01; |
1839 | 13.7k | } |
1840 | 4.63k | else if (fld_size == 3 && fld_q == 1) |
1841 | 4.63k | { |
1842 | 4.63k | info->indexed_za.regno = fld_zan_imm; |
1843 | 4.63k | info->indexed_za.index.imm = 0; |
1844 | 4.63k | } |
1845 | 0 | else |
1846 | 0 | return false; |
1847 | | |
1848 | 41.4k | info->indexed_za.index.regno = fld_rv + 12; |
1849 | 41.4k | info->indexed_za.v = fld_v; |
1850 | | |
1851 | 41.4k | return true; |
1852 | 41.4k | } |
1853 | | |
1854 | | bool |
1855 | | aarch64_ext_sme_za_hv_tiles_range (const aarch64_operand *self, |
1856 | | aarch64_opnd_info *info, aarch64_insn code, |
1857 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1858 | | aarch64_operand_error *errors |
1859 | | ATTRIBUTE_UNUSED) |
1860 | 666 | { |
1861 | 666 | int ebytes = aarch64_get_qualifier_esize (info->qualifier); |
1862 | 666 | int range_size = get_opcode_dependent_value (inst->opcode); |
1863 | 666 | int fld_v = extract_field (self->fields[0], code, 0); |
1864 | 666 | int fld_rv = extract_field (self->fields[1], code, 0); |
1865 | 666 | int fld_zan_imm = extract_field (self->fields[2], code, 0); |
1866 | 666 | int max_value = 16 / range_size / ebytes; |
1867 | | |
1868 | 666 | if (max_value == 0) |
1869 | 0 | max_value = 1; |
1870 | | |
1871 | 666 | int regno = fld_zan_imm / max_value; |
1872 | 666 | if (regno >= ebytes) |
1873 | 0 | return false; |
1874 | | |
1875 | 666 | info->indexed_za.regno = regno; |
1876 | 666 | info->indexed_za.index.imm = (fld_zan_imm % max_value) * range_size; |
1877 | 666 | info->indexed_za.index.countm1 = range_size - 1; |
1878 | 666 | info->indexed_za.index.regno = fld_rv + 12; |
1879 | 666 | info->indexed_za.v = fld_v; |
1880 | | |
1881 | 666 | return true; |
1882 | 666 | } |
1883 | | |
1884 | | /* Decode in SME instruction ZERO list of up to eight 64-bit element tile names |
1885 | | separated by commas, encoded in the "imm8" field. |
1886 | | |
1887 | | For programmer convenience an assembler must also accept the names of |
1888 | | 32-bit, 16-bit and 8-bit element tiles which are converted into the |
1889 | | corresponding set of 64-bit element tiles. |
1890 | | */ |
1891 | | bool |
1892 | | aarch64_ext_sme_za_list (const aarch64_operand *self, |
1893 | | aarch64_opnd_info *info, aarch64_insn code, |
1894 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1895 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1896 | 0 | { |
1897 | 0 | int mask = extract_field (self->fields[0], code, 0); |
1898 | 0 | info->imm.value = mask; |
1899 | 0 | return true; |
1900 | 0 | } |
1901 | | |
1902 | | /* Decode ZA array vector select register (Rv field), optional vector and |
1903 | | memory offset (imm4_11 field). |
1904 | | */ |
1905 | | bool |
1906 | | aarch64_ext_sme_za_array (const aarch64_operand *self, |
1907 | | aarch64_opnd_info *info, aarch64_insn code, |
1908 | | const aarch64_inst *inst, |
1909 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1910 | 13.8k | { |
1911 | 13.8k | int regno = extract_field (self->fields[0], code, 0); |
1912 | 13.8k | if (info->type == AARCH64_OPND_SME_ZA_array_off4) |
1913 | 144 | regno += 12; |
1914 | 13.7k | else |
1915 | 13.7k | regno += 8; |
1916 | 13.8k | int imm = extract_field (self->fields[1], code, 0); |
1917 | 13.8k | int num_offsets = get_operand_specific_data (self); |
1918 | 13.8k | if (num_offsets == 0) |
1919 | 3.18k | num_offsets = 1; |
1920 | 13.8k | info->indexed_za.index.regno = regno; |
1921 | 13.8k | info->indexed_za.index.imm = imm * num_offsets; |
1922 | 13.8k | info->indexed_za.index.countm1 = num_offsets - 1; |
1923 | 13.8k | info->indexed_za.group_size = get_opcode_dependent_value (inst->opcode); |
1924 | 13.8k | return true; |
1925 | 13.8k | } |
1926 | | |
1927 | | bool |
1928 | | aarch64_ext_sme_addr_ri_u4xvl (const aarch64_operand *self, |
1929 | | aarch64_opnd_info *info, aarch64_insn code, |
1930 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1931 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1932 | 144 | { |
1933 | 144 | int regno = extract_field (self->fields[0], code, 0); |
1934 | 144 | int imm = extract_field (self->fields[1], code, 0); |
1935 | 144 | info->addr.base_regno = regno; |
1936 | 144 | info->addr.offset.imm = imm; |
1937 | | /* MUL VL operator is always present for this operand. */ |
1938 | 144 | info->shifter.kind = AARCH64_MOD_MUL_VL; |
1939 | 144 | info->shifter.operator_present = (imm != 0); |
1940 | 144 | return true; |
1941 | 144 | } |
1942 | | |
1943 | | /* Decode {SM|ZA} filed for SMSTART and SMSTOP instructions. */ |
1944 | | bool |
1945 | | aarch64_ext_sme_sm_za (const aarch64_operand *self, |
1946 | | aarch64_opnd_info *info, aarch64_insn code, |
1947 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1948 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1949 | 0 | { |
1950 | 0 | info->pstatefield = 0x1b; |
1951 | 0 | aarch64_insn fld_crm = extract_field (self->fields[0], code, 0); |
1952 | 0 | fld_crm >>= 1; /* CRm[3:1]. */ |
1953 | |
|
1954 | 0 | if (fld_crm == 0x1) |
1955 | 0 | info->reg.regno = 's'; |
1956 | 0 | else if (fld_crm == 0x2) |
1957 | 0 | info->reg.regno = 'z'; |
1958 | 0 | else |
1959 | 0 | return false; |
1960 | | |
1961 | 0 | return true; |
1962 | 0 | } |
1963 | | |
1964 | | bool |
1965 | | aarch64_ext_sme_pred_reg_with_index (const aarch64_operand *self, |
1966 | | aarch64_opnd_info *info, aarch64_insn code, |
1967 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
1968 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
1969 | 797 | { |
1970 | 797 | aarch64_insn fld_rm = extract_field (self->fields[0], code, 0); |
1971 | 797 | aarch64_insn fld_pn = extract_field (self->fields[1], code, 0); |
1972 | 797 | aarch64_insn fld_i1 = extract_field (self->fields[2], code, 0); |
1973 | 797 | aarch64_insn fld_tszh = extract_field (self->fields[3], code, 0); |
1974 | 797 | aarch64_insn fld_tszl = extract_field (self->fields[4], code, 0); |
1975 | 797 | int imm; |
1976 | | |
1977 | 797 | info->indexed_za.regno = fld_pn; |
1978 | 797 | info->indexed_za.index.regno = fld_rm + 12; |
1979 | | |
1980 | 797 | if (fld_tszl & 0x1) |
1981 | 350 | imm = (fld_i1 << 3) | (fld_tszh << 2) | (fld_tszl >> 1); |
1982 | 447 | else if (fld_tszl & 0x2) |
1983 | 353 | imm = (fld_i1 << 2) | (fld_tszh << 1) | (fld_tszl >> 2); |
1984 | 94 | else if (fld_tszl & 0x4) |
1985 | 89 | imm = (fld_i1 << 1) | fld_tszh; |
1986 | 5 | else if (fld_tszh) |
1987 | 5 | imm = fld_i1; |
1988 | 0 | else |
1989 | 0 | return false; |
1990 | | |
1991 | 797 | info->indexed_za.index.imm = imm; |
1992 | 797 | return true; |
1993 | 797 | } |
1994 | | |
1995 | | /* Decode Zn[MM], where MM has a 7-bit triangular encoding. The fields |
1996 | | array specifies which field to use for Zn. MM is encoded in the |
1997 | | concatenation of imm5 and SVE_tszh, with imm5 being the less |
1998 | | significant part. */ |
1999 | | bool |
2000 | | aarch64_ext_sve_index (const aarch64_operand *self, |
2001 | | aarch64_opnd_info *info, aarch64_insn code, |
2002 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2003 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
2004 | 550 | { |
2005 | 550 | int val; |
2006 | | |
2007 | 550 | info->reglane.regno = extract_field (self->fields[0], code, 0); |
2008 | 550 | val = extract_fields (code, 0, 2, FLD_SVE_tszh, FLD_imm5); |
2009 | 550 | if ((val & 31) == 0) |
2010 | 0 | return 0; |
2011 | 1.34k | while ((val & 1) == 0) |
2012 | 796 | val /= 2; |
2013 | 550 | info->reglane.index = val / 2; |
2014 | 550 | return true; |
2015 | 550 | } |
2016 | | |
2017 | | /* Decode a logical immediate for the MOV alias of SVE DUPM. */ |
2018 | | bool |
2019 | | aarch64_ext_sve_limm_mov (const aarch64_operand *self, |
2020 | | aarch64_opnd_info *info, const aarch64_insn code, |
2021 | | const aarch64_inst *inst, |
2022 | | aarch64_operand_error *errors) |
2023 | 582 | { |
2024 | 582 | int esize = aarch64_get_qualifier_esize (inst->operands[0].qualifier); |
2025 | 582 | return (aarch64_ext_limm (self, info, code, inst, errors) |
2026 | 582 | && aarch64_sve_dupm_mov_immediate_p (info->imm.value, esize)); |
2027 | 582 | } |
2028 | | |
2029 | | /* Decode Zn[MM], where Zn occupies the least-significant part of the field |
2030 | | and where MM occupies the most-significant part. The operand-dependent |
2031 | | value specifies the number of bits in Zn. */ |
2032 | | bool |
2033 | | aarch64_ext_sve_quad_index (const aarch64_operand *self, |
2034 | | aarch64_opnd_info *info, aarch64_insn code, |
2035 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2036 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
2037 | 14.0k | { |
2038 | 14.0k | unsigned int reg_bits = get_operand_specific_data (self); |
2039 | 14.0k | unsigned int val = extract_all_fields (self, code); |
2040 | 14.0k | info->reglane.regno = val & ((1 << reg_bits) - 1); |
2041 | 14.0k | info->reglane.index = val >> reg_bits; |
2042 | 14.0k | return true; |
2043 | 14.0k | } |
2044 | | |
2045 | | /* Decode {Zn.<T> - Zm.<T>}. The fields array specifies which field |
2046 | | to use for Zn. The opcode-dependent value specifies the number |
2047 | | of registers in the list. */ |
2048 | | bool |
2049 | | aarch64_ext_sve_reglist (const aarch64_operand *self, |
2050 | | aarch64_opnd_info *info, aarch64_insn code, |
2051 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2052 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
2053 | 241k | { |
2054 | 241k | info->reglist.first_regno = extract_field (self->fields[0], code, 0); |
2055 | 241k | info->reglist.num_regs = get_opcode_dependent_value (inst->opcode); |
2056 | 241k | info->reglist.stride = 1; |
2057 | 241k | return true; |
2058 | 241k | } |
2059 | | |
2060 | | /* Decode a strided register list. The first field holds the top bit |
2061 | | (0 or 16) and the second field holds the lower bits. The stride is |
2062 | | 16 divided by the list length. */ |
2063 | | bool |
2064 | | aarch64_ext_sve_strided_reglist (const aarch64_operand *self, |
2065 | | aarch64_opnd_info *info, aarch64_insn code, |
2066 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2067 | | aarch64_operand_error *errors |
2068 | | ATTRIBUTE_UNUSED) |
2069 | 10.0k | { |
2070 | 10.0k | unsigned int upper = extract_field (self->fields[0], code, 0); |
2071 | 10.0k | unsigned int lower = extract_field (self->fields[1], code, 0); |
2072 | 10.0k | info->reglist.first_regno = upper * 16 + lower; |
2073 | 10.0k | info->reglist.num_regs = get_operand_specific_data (self); |
2074 | 10.0k | info->reglist.stride = 16 / info->reglist.num_regs; |
2075 | 10.0k | return true; |
2076 | 10.0k | } |
2077 | | |
2078 | | /* Decode <pattern>{, MUL #<amount>}. The fields array specifies which |
2079 | | fields to use for <pattern>. <amount> - 1 is encoded in the SVE_imm4 |
2080 | | field. */ |
2081 | | bool |
2082 | | aarch64_ext_sve_scale (const aarch64_operand *self, |
2083 | | aarch64_opnd_info *info, aarch64_insn code, |
2084 | | const aarch64_inst *inst, aarch64_operand_error *errors) |
2085 | 3.35k | { |
2086 | 3.35k | int val; |
2087 | | |
2088 | 3.35k | if (!aarch64_ext_imm (self, info, code, inst, errors)) |
2089 | 0 | return false; |
2090 | 3.35k | val = extract_field (FLD_SVE_imm4, code, 0); |
2091 | 3.35k | info->shifter.kind = AARCH64_MOD_MUL; |
2092 | 3.35k | info->shifter.amount = val + 1; |
2093 | 3.35k | info->shifter.operator_present = (val != 0); |
2094 | 3.35k | info->shifter.amount_present = (val != 0); |
2095 | 3.35k | return true; |
2096 | 3.35k | } |
2097 | | |
2098 | | /* Return the top set bit in VALUE, which is expected to be relatively |
2099 | | small. */ |
2100 | | static uint64_t |
2101 | | get_top_bit (uint64_t value) |
2102 | 11.7k | { |
2103 | 46.7k | while ((value & -value) != value) |
2104 | 35.0k | value -= value & -value; |
2105 | 11.7k | return value; |
2106 | 11.7k | } |
2107 | | |
2108 | | /* Decode an SVE shift-left immediate. */ |
2109 | | bool |
2110 | | aarch64_ext_sve_shlimm (const aarch64_operand *self, |
2111 | | aarch64_opnd_info *info, const aarch64_insn code, |
2112 | | const aarch64_inst *inst, aarch64_operand_error *errors) |
2113 | 1.47k | { |
2114 | 1.47k | if (!aarch64_ext_imm (self, info, code, inst, errors) |
2115 | 1.47k | || info->imm.value == 0) |
2116 | 0 | return false; |
2117 | | |
2118 | 1.47k | info->imm.value -= get_top_bit (info->imm.value); |
2119 | 1.47k | return true; |
2120 | 1.47k | } |
2121 | | |
2122 | | /* Decode an SVE shift-right immediate. */ |
2123 | | bool |
2124 | | aarch64_ext_sve_shrimm (const aarch64_operand *self, |
2125 | | aarch64_opnd_info *info, const aarch64_insn code, |
2126 | | const aarch64_inst *inst, aarch64_operand_error *errors) |
2127 | 10.2k | { |
2128 | 10.2k | if (!aarch64_ext_imm (self, info, code, inst, errors) |
2129 | 10.2k | || info->imm.value == 0) |
2130 | 0 | return false; |
2131 | | |
2132 | 10.2k | info->imm.value = get_top_bit (info->imm.value) * 2 - info->imm.value; |
2133 | 10.2k | return true; |
2134 | 10.2k | } |
2135 | | |
2136 | | /* Decode X0-X30. Register 31 is unallocated. */ |
2137 | | bool |
2138 | | aarch64_ext_x0_to_x30 (const aarch64_operand *self, aarch64_opnd_info *info, |
2139 | | const aarch64_insn code, |
2140 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2141 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
2142 | 28.2k | { |
2143 | 28.2k | info->reg.regno = extract_field (self->fields[0], code, 0); |
2144 | 28.2k | return info->reg.regno <= 30; |
2145 | 28.2k | } |
2146 | | |
2147 | | /* Decode an indexed register, with the first field being the register |
2148 | | number and the remaining fields being the index. */ |
2149 | | bool |
2150 | | aarch64_ext_simple_index (const aarch64_operand *self, aarch64_opnd_info *info, |
2151 | | const aarch64_insn code, |
2152 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2153 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
2154 | 10.4k | { |
2155 | 10.4k | int bias = get_operand_specific_data (self); |
2156 | 10.4k | info->reglane.regno = extract_field (self->fields[0], code, 0) + bias; |
2157 | 10.4k | info->reglane.index = extract_all_fields_after (self, 1, code); |
2158 | 10.4k | return true; |
2159 | 10.4k | } |
2160 | | |
2161 | | /* Decode a plain shift-right immediate, when there is only a single |
2162 | | element size. */ |
2163 | | bool |
2164 | | aarch64_ext_plain_shrimm (const aarch64_operand *self, aarch64_opnd_info *info, |
2165 | | const aarch64_insn code, |
2166 | | const aarch64_inst *inst ATTRIBUTE_UNUSED, |
2167 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
2168 | 90 | { |
2169 | 90 | unsigned int base = 1 << get_operand_field_width (self, 0); |
2170 | 90 | info->imm.value = base - extract_field (self->fields[0], code, 0); |
2171 | 90 | return true; |
2172 | 90 | } |
2173 | | |
2174 | | /* Bitfields that are commonly used to encode certain operands' information |
2175 | | may be partially used as part of the base opcode in some instructions. |
2176 | | For example, the bit 1 of the field 'size' in |
2177 | | FCVTXN <Vb><d>, <Va><n> |
2178 | | is actually part of the base opcode, while only size<0> is available |
2179 | | for encoding the register type. Another example is the AdvSIMD |
2180 | | instruction ORR (register), in which the field 'size' is also used for |
2181 | | the base opcode, leaving only the field 'Q' available to encode the |
2182 | | vector register arrangement specifier '8B' or '16B'. |
2183 | | |
2184 | | This function tries to deduce the qualifier from the value of partially |
2185 | | constrained field(s). Given the VALUE of such a field or fields, the |
2186 | | qualifiers CANDIDATES and the MASK (indicating which bits are valid for |
2187 | | operand encoding), the function returns the matching qualifier or |
2188 | | AARCH64_OPND_QLF_NIL if nothing matches. |
2189 | | |
2190 | | N.B. CANDIDATES is a group of possible qualifiers that are valid for |
2191 | | one operand; it has a maximum of AARCH64_MAX_QLF_SEQ_NUM qualifiers and |
2192 | | may end with AARCH64_OPND_QLF_NIL. */ |
2193 | | |
2194 | | static enum aarch64_opnd_qualifier |
2195 | | get_qualifier_from_partial_encoding (aarch64_insn value, |
2196 | | const enum aarch64_opnd_qualifier* \ |
2197 | | candidates, |
2198 | | aarch64_insn mask) |
2199 | 109k | { |
2200 | 109k | int i; |
2201 | 109k | DEBUG_TRACE ("enter with value: %d, mask: %d", (int)value, (int)mask); |
2202 | 207k | for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i) |
2203 | 207k | { |
2204 | 207k | aarch64_insn standard_value; |
2205 | 207k | if (candidates[i] == AARCH64_OPND_QLF_NIL) |
2206 | 23.5k | break; |
2207 | 183k | standard_value = aarch64_get_qualifier_standard_value (candidates[i]); |
2208 | 183k | if ((standard_value & mask) == (value & mask)) |
2209 | 86.2k | return candidates[i]; |
2210 | 183k | } |
2211 | 23.5k | return AARCH64_OPND_QLF_NIL; |
2212 | 109k | } |
2213 | | |
2214 | | /* Given a list of qualifier sequences, return all possible valid qualifiers |
2215 | | for operand IDX in QUALIFIERS. |
2216 | | Assume QUALIFIERS is an array whose length is large enough. */ |
2217 | | |
2218 | | static void |
2219 | | get_operand_possible_qualifiers (int idx, |
2220 | | const aarch64_opnd_qualifier_seq_t *list, |
2221 | | enum aarch64_opnd_qualifier *qualifiers) |
2222 | 109k | { |
2223 | 109k | int i; |
2224 | 363k | for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i) |
2225 | 363k | if ((qualifiers[i] = list[i][idx]) == AARCH64_OPND_QLF_NIL) |
2226 | 109k | break; |
2227 | 109k | } |
2228 | | |
2229 | | /* Decode the size Q field for e.g. SHADD. |
2230 | | We tag one operand with the qualifer according to the code; |
2231 | | whether the qualifier is valid for this opcode or not, it is the |
2232 | | duty of the semantic checking. */ |
2233 | | |
2234 | | static int |
2235 | | decode_sizeq (aarch64_inst *inst) |
2236 | 296k | { |
2237 | 296k | int idx; |
2238 | 296k | enum aarch64_opnd_qualifier qualifier; |
2239 | 296k | aarch64_insn code; |
2240 | 296k | aarch64_insn value, mask; |
2241 | 296k | enum aarch64_field_kind fld_sz; |
2242 | 296k | enum aarch64_opnd_qualifier candidates[AARCH64_MAX_QLF_SEQ_NUM]; |
2243 | | |
2244 | 296k | if (inst->opcode->iclass == asisdlse |
2245 | 296k | || inst->opcode->iclass == asisdlsep |
2246 | 296k | || inst->opcode->iclass == asisdlso |
2247 | 296k | || inst->opcode->iclass == asisdlsop) |
2248 | 90.3k | fld_sz = FLD_vldst_size; |
2249 | 206k | else |
2250 | 206k | fld_sz = FLD_size; |
2251 | | |
2252 | 296k | code = inst->value; |
2253 | 296k | value = extract_fields (code, inst->opcode->mask, 2, fld_sz, FLD_Q); |
2254 | | /* Obtain the info that which bits of fields Q and size are actually |
2255 | | available for operand encoding. Opcodes like FMAXNM and FMLA have |
2256 | | size[1] unavailable. */ |
2257 | 296k | mask = extract_fields (~inst->opcode->mask, 0, 2, fld_sz, FLD_Q); |
2258 | | |
2259 | | /* The index of the operand we are going to tag a qualifier and the qualifer |
2260 | | itself are reasoned from the value of the size and Q fields and the |
2261 | | possible valid qualifier lists. */ |
2262 | 296k | idx = aarch64_select_operand_for_sizeq_field_coding (inst->opcode); |
2263 | 296k | DEBUG_TRACE ("key idx: %d", idx); |
2264 | | |
2265 | | /* For most related instruciton, size:Q are fully available for operand |
2266 | | encoding. */ |
2267 | 296k | if (mask == 0x7) |
2268 | 193k | { |
2269 | 193k | inst->operands[idx].qualifier = get_vreg_qualifier_from_value (value); |
2270 | 193k | return 1; |
2271 | 193k | } |
2272 | | |
2273 | 103k | get_operand_possible_qualifiers (idx, inst->opcode->qualifiers_list, |
2274 | 103k | candidates); |
2275 | | #ifdef DEBUG_AARCH64 |
2276 | | if (debug_dump) |
2277 | | { |
2278 | | int i; |
2279 | | for (i = 0; candidates[i] != AARCH64_OPND_QLF_NIL |
2280 | | && i < AARCH64_MAX_QLF_SEQ_NUM; ++i) |
2281 | | DEBUG_TRACE ("qualifier %d: %s", i, |
2282 | | aarch64_get_qualifier_name(candidates[i])); |
2283 | | DEBUG_TRACE ("%d, %d", (int)value, (int)mask); |
2284 | | } |
2285 | | #endif /* DEBUG_AARCH64 */ |
2286 | | |
2287 | 103k | qualifier = get_qualifier_from_partial_encoding (value, candidates, mask); |
2288 | | |
2289 | 103k | if (qualifier == AARCH64_OPND_QLF_NIL) |
2290 | 23.5k | return 0; |
2291 | | |
2292 | 79.8k | inst->operands[idx].qualifier = qualifier; |
2293 | 79.8k | return 1; |
2294 | 103k | } |
2295 | | |
2296 | | /* Decode size[0]:Q, i.e. bit 22 and bit 30, for |
2297 | | e.g. FCVTN<Q> <Vd>.<Tb>, <Vn>.<Ta>. */ |
2298 | | |
2299 | | static int |
2300 | | decode_asimd_fcvt (aarch64_inst *inst) |
2301 | 2 | { |
2302 | 2 | aarch64_field field = {0, 0}; |
2303 | 2 | aarch64_insn value; |
2304 | 2 | enum aarch64_opnd_qualifier qualifier; |
2305 | | |
2306 | 2 | gen_sub_field (FLD_size, 0, 1, &field); |
2307 | 2 | value = extract_field_2 (&field, inst->value, 0); |
2308 | 2 | qualifier = value == 0 ? AARCH64_OPND_QLF_V_4S |
2309 | 2 | : AARCH64_OPND_QLF_V_2D; |
2310 | 2 | switch (inst->opcode->op) |
2311 | 2 | { |
2312 | 0 | case OP_FCVTN: |
2313 | 0 | case OP_FCVTN2: |
2314 | | /* FCVTN<Q> <Vd>.<Tb>, <Vn>.<Ta>. */ |
2315 | 0 | inst->operands[1].qualifier = qualifier; |
2316 | 0 | break; |
2317 | 0 | case OP_FCVTL: |
2318 | 2 | case OP_FCVTL2: |
2319 | | /* FCVTL<Q> <Vd>.<Ta>, <Vn>.<Tb>. */ |
2320 | 2 | inst->operands[0].qualifier = qualifier; |
2321 | 2 | break; |
2322 | 0 | default: |
2323 | 0 | return 0; |
2324 | 2 | } |
2325 | | |
2326 | 2 | return 1; |
2327 | 2 | } |
2328 | | |
2329 | | /* Decode size[0], i.e. bit 22, for |
2330 | | e.g. FCVTXN <Vb><d>, <Va><n>. */ |
2331 | | |
2332 | | static int |
2333 | | decode_asisd_fcvtxn (aarch64_inst *inst) |
2334 | 5 | { |
2335 | 5 | aarch64_field field = {0, 0}; |
2336 | 5 | gen_sub_field (FLD_size, 0, 1, &field); |
2337 | 5 | if (!extract_field_2 (&field, inst->value, 0)) |
2338 | 0 | return 0; |
2339 | 5 | inst->operands[0].qualifier = AARCH64_OPND_QLF_S_S; |
2340 | 5 | return 1; |
2341 | 5 | } |
2342 | | |
2343 | | /* Decode the 'opc' field for e.g. FCVT <Dd>, <Sn>. */ |
2344 | | static int |
2345 | | decode_fcvt (aarch64_inst *inst) |
2346 | 8 | { |
2347 | 8 | enum aarch64_opnd_qualifier qualifier; |
2348 | 8 | aarch64_insn value; |
2349 | 8 | const aarch64_field field = {15, 2}; |
2350 | | |
2351 | | /* opc dstsize */ |
2352 | 8 | value = extract_field_2 (&field, inst->value, 0); |
2353 | 8 | switch (value) |
2354 | 8 | { |
2355 | 1 | case 0: qualifier = AARCH64_OPND_QLF_S_S; break; |
2356 | 3 | case 1: qualifier = AARCH64_OPND_QLF_S_D; break; |
2357 | 4 | case 3: qualifier = AARCH64_OPND_QLF_S_H; break; |
2358 | 0 | default: return 0; |
2359 | 8 | } |
2360 | 8 | inst->operands[0].qualifier = qualifier; |
2361 | | |
2362 | 8 | return 1; |
2363 | 8 | } |
2364 | | |
2365 | | /* Do miscellaneous decodings that are not common enough to be driven by |
2366 | | flags. */ |
2367 | | |
2368 | | static int |
2369 | | do_misc_decoding (aarch64_inst *inst) |
2370 | 8.43k | { |
2371 | 8.43k | unsigned int value; |
2372 | 8.43k | switch (inst->opcode->op) |
2373 | 8.43k | { |
2374 | 8 | case OP_FCVT: |
2375 | 8 | return decode_fcvt (inst); |
2376 | | |
2377 | 0 | case OP_FCVTN: |
2378 | 0 | case OP_FCVTN2: |
2379 | 0 | case OP_FCVTL: |
2380 | 2 | case OP_FCVTL2: |
2381 | 2 | return decode_asimd_fcvt (inst); |
2382 | | |
2383 | 5 | case OP_FCVTXN_S: |
2384 | 5 | return decode_asisd_fcvtxn (inst); |
2385 | | |
2386 | 425 | case OP_MOV_P_P: |
2387 | 682 | case OP_MOVS_P_P: |
2388 | 682 | value = extract_field (FLD_SVE_Pn, inst->value, 0); |
2389 | 682 | return (value == extract_field (FLD_SVE_Pm, inst->value, 0) |
2390 | 682 | && value == extract_field (FLD_SVE_Pg4_10, inst->value, 0)); |
2391 | | |
2392 | 6.13k | case OP_MOV_Z_P_Z: |
2393 | 6.13k | return (extract_field (FLD_SVE_Zd, inst->value, 0) |
2394 | 6.13k | == extract_field (FLD_SVE_Zm_16, inst->value, 0)); |
2395 | | |
2396 | 20 | case OP_MOV_Z_V: |
2397 | | /* Index must be zero. */ |
2398 | 20 | value = extract_fields (inst->value, 0, 2, FLD_SVE_tszh, FLD_imm5); |
2399 | 20 | return value > 0 && value <= 16 && value == (value & -value); |
2400 | | |
2401 | 79 | case OP_MOV_Z_Z: |
2402 | 79 | return (extract_field (FLD_SVE_Zn, inst->value, 0) |
2403 | 79 | == extract_field (FLD_SVE_Zm_16, inst->value, 0)); |
2404 | | |
2405 | 285 | case OP_MOV_Z_Zi: |
2406 | | /* Index must be nonzero. */ |
2407 | 285 | value = extract_fields (inst->value, 0, 2, FLD_SVE_tszh, FLD_imm5); |
2408 | 285 | return value > 0 && value != (value & -value); |
2409 | | |
2410 | 117 | case OP_MOVM_P_P_P: |
2411 | 117 | return (extract_field (FLD_SVE_Pd, inst->value, 0) |
2412 | 117 | == extract_field (FLD_SVE_Pm, inst->value, 0)); |
2413 | | |
2414 | 197 | case OP_MOVZS_P_P_P: |
2415 | 354 | case OP_MOVZ_P_P_P: |
2416 | 354 | return (extract_field (FLD_SVE_Pn, inst->value, 0) |
2417 | 354 | == extract_field (FLD_SVE_Pm, inst->value, 0)); |
2418 | | |
2419 | 100 | case OP_NOTS_P_P_P_Z: |
2420 | 321 | case OP_NOT_P_P_P_Z: |
2421 | 321 | return (extract_field (FLD_SVE_Pm, inst->value, 0) |
2422 | 321 | == extract_field (FLD_SVE_Pg4_10, inst->value, 0)); |
2423 | | |
2424 | 425 | default: |
2425 | 425 | return 0; |
2426 | 8.43k | } |
2427 | 8.43k | } |
2428 | | |
2429 | | /* Opcodes that have fields shared by multiple operands are usually flagged |
2430 | | with flags. In this function, we detect such flags, decode the related |
2431 | | field(s) and store the information in one of the related operands. The |
2432 | | 'one' operand is not any operand but one of the operands that can |
2433 | | accommadate all the information that has been decoded. */ |
2434 | | |
2435 | | static int |
2436 | | do_special_decoding (aarch64_inst *inst) |
2437 | 3.32M | { |
2438 | 3.32M | int idx; |
2439 | 3.32M | aarch64_insn value; |
2440 | | /* Condition for truly conditional executed instructions, e.g. b.cond. */ |
2441 | 3.32M | if (inst->opcode->flags & F_COND) |
2442 | 60.7k | { |
2443 | 60.7k | value = extract_field (FLD_cond2, inst->value, 0); |
2444 | 60.7k | inst->cond = get_cond_from_value (value); |
2445 | 60.7k | } |
2446 | | /* 'sf' field. */ |
2447 | 3.32M | if (inst->opcode->flags & F_SF) |
2448 | 2.51M | { |
2449 | 2.51M | idx = select_operand_for_sf_field_coding (inst->opcode); |
2450 | 2.51M | value = extract_field (FLD_sf, inst->value, 0); |
2451 | 2.51M | inst->operands[idx].qualifier = get_greg_qualifier_from_value (value); |
2452 | 2.51M | if ((inst->opcode->flags & F_N) |
2453 | 2.51M | && extract_field (FLD_N, inst->value, 0) != value) |
2454 | 103k | return 0; |
2455 | 2.51M | } |
2456 | | /* 'sf' field. */ |
2457 | 3.21M | if (inst->opcode->flags & F_LSE_SZ) |
2458 | 10.6k | { |
2459 | 10.6k | idx = select_operand_for_sf_field_coding (inst->opcode); |
2460 | 10.6k | value = extract_field (FLD_lse_sz, inst->value, 0); |
2461 | 10.6k | inst->operands[idx].qualifier = get_greg_qualifier_from_value (value); |
2462 | 10.6k | } |
2463 | | /* size:Q fields. */ |
2464 | 3.21M | if (inst->opcode->flags & F_SIZEQ) |
2465 | 296k | return decode_sizeq (inst); |
2466 | | |
2467 | 2.92M | if (inst->opcode->flags & F_FPTYPE) |
2468 | 85.9k | { |
2469 | 85.9k | idx = select_operand_for_fptype_field_coding (inst->opcode); |
2470 | 85.9k | value = extract_field (FLD_type, inst->value, 0); |
2471 | 85.9k | switch (value) |
2472 | 85.9k | { |
2473 | 21.9k | case 0: inst->operands[idx].qualifier = AARCH64_OPND_QLF_S_S; break; |
2474 | 14.2k | case 1: inst->operands[idx].qualifier = AARCH64_OPND_QLF_S_D; break; |
2475 | 25.2k | case 3: inst->operands[idx].qualifier = AARCH64_OPND_QLF_S_H; break; |
2476 | 24.5k | default: return 0; |
2477 | 85.9k | } |
2478 | 85.9k | } |
2479 | | |
2480 | 2.89M | if (inst->opcode->flags & F_SSIZE) |
2481 | 21.1k | { |
2482 | | /* N.B. some opcodes like FCMGT <V><d>, <V><n>, #0 have the size[1] as part |
2483 | | of the base opcode. */ |
2484 | 21.1k | aarch64_insn mask; |
2485 | 21.1k | enum aarch64_opnd_qualifier candidates[AARCH64_MAX_QLF_SEQ_NUM]; |
2486 | 21.1k | idx = select_operand_for_scalar_size_field_coding (inst->opcode); |
2487 | 21.1k | value = extract_field (FLD_size, inst->value, inst->opcode->mask); |
2488 | 21.1k | mask = extract_field (FLD_size, ~inst->opcode->mask, 0); |
2489 | | /* For most related instruciton, the 'size' field is fully available for |
2490 | | operand encoding. */ |
2491 | 21.1k | if (mask == 0x3) |
2492 | 14.7k | inst->operands[idx].qualifier = get_sreg_qualifier_from_value (value); |
2493 | 6.40k | else |
2494 | 6.40k | { |
2495 | 6.40k | get_operand_possible_qualifiers (idx, inst->opcode->qualifiers_list, |
2496 | 6.40k | candidates); |
2497 | 6.40k | inst->operands[idx].qualifier |
2498 | 6.40k | = get_qualifier_from_partial_encoding (value, candidates, mask); |
2499 | 6.40k | } |
2500 | 21.1k | } |
2501 | | |
2502 | 2.89M | if (inst->opcode->flags & F_T) |
2503 | 1.42k | { |
2504 | | /* Num of consecutive '0's on the right side of imm5<3:0>. */ |
2505 | 1.42k | int num = 0; |
2506 | 1.42k | unsigned val, Q; |
2507 | 1.42k | assert (aarch64_get_operand_class (inst->opcode->operands[0]) |
2508 | 1.42k | == AARCH64_OPND_CLASS_SIMD_REG); |
2509 | | /* imm5<3:0> q <t> |
2510 | | 0000 x reserved |
2511 | | xxx1 0 8b |
2512 | | xxx1 1 16b |
2513 | | xx10 0 4h |
2514 | | xx10 1 8h |
2515 | | x100 0 2s |
2516 | | x100 1 4s |
2517 | | 1000 0 reserved |
2518 | | 1000 1 2d */ |
2519 | 1.42k | val = extract_field (FLD_imm5, inst->value, 0); |
2520 | 4.19k | while ((val & 0x1) == 0 && ++num <= 3) |
2521 | 2.77k | val >>= 1; |
2522 | 1.42k | if (num > 3) |
2523 | 718 | return 0; |
2524 | 706 | Q = (unsigned) extract_field (FLD_Q, inst->value, inst->opcode->mask); |
2525 | 706 | inst->operands[0].qualifier = |
2526 | 706 | get_vreg_qualifier_from_value ((num << 1) | Q); |
2527 | 706 | } |
2528 | | |
2529 | 2.89M | if (inst->opcode->flags & F_GPRSIZE_IN_Q) |
2530 | 269k | { |
2531 | | /* Use Rt to encode in the case of e.g. |
2532 | | STXP <Ws>, <Xt1>, <Xt2>, [<Xn|SP>{,#0}]. */ |
2533 | 269k | idx = aarch64_operand_index (inst->opcode->operands, AARCH64_OPND_Rt); |
2534 | 269k | if (idx == -1) |
2535 | 411 | { |
2536 | | /* Otherwise use the result operand, which has to be a integer |
2537 | | register. */ |
2538 | 411 | assert (aarch64_get_operand_class (inst->opcode->operands[0]) |
2539 | 411 | == AARCH64_OPND_CLASS_INT_REG); |
2540 | 411 | idx = 0; |
2541 | 411 | } |
2542 | 269k | assert (idx == 0 || idx == 1); |
2543 | 269k | value = extract_field (FLD_Q, inst->value, 0); |
2544 | 269k | inst->operands[idx].qualifier = get_greg_qualifier_from_value (value); |
2545 | 269k | } |
2546 | | |
2547 | 2.89M | if (inst->opcode->flags & F_LDS_SIZE) |
2548 | 62.9k | { |
2549 | 62.9k | aarch64_field field = {0, 0}; |
2550 | 62.9k | assert (aarch64_get_operand_class (inst->opcode->operands[0]) |
2551 | 62.9k | == AARCH64_OPND_CLASS_INT_REG); |
2552 | 62.9k | gen_sub_field (FLD_opc, 0, 1, &field); |
2553 | 62.9k | value = extract_field_2 (&field, inst->value, 0); |
2554 | 62.9k | inst->operands[0].qualifier |
2555 | 62.9k | = value ? AARCH64_OPND_QLF_W : AARCH64_OPND_QLF_X; |
2556 | 62.9k | } |
2557 | | |
2558 | | /* Miscellaneous decoding; done as the last step. */ |
2559 | 2.89M | if (inst->opcode->flags & F_MISC) |
2560 | 8.43k | return do_misc_decoding (inst); |
2561 | | |
2562 | 2.88M | return 1; |
2563 | 2.89M | } |
2564 | | |
2565 | | /* Converters converting a real opcode instruction to its alias form. */ |
2566 | | |
2567 | | /* ROR <Wd>, <Ws>, #<shift> |
2568 | | is equivalent to: |
2569 | | EXTR <Wd>, <Ws>, <Ws>, #<shift>. */ |
2570 | | static int |
2571 | | convert_extr_to_ror (aarch64_inst *inst) |
2572 | 5.85k | { |
2573 | 5.85k | if (inst->operands[1].reg.regno == inst->operands[2].reg.regno) |
2574 | 278 | { |
2575 | 278 | copy_operand_info (inst, 2, 3); |
2576 | 278 | inst->operands[3].type = AARCH64_OPND_NIL; |
2577 | 278 | return 1; |
2578 | 278 | } |
2579 | 5.57k | return 0; |
2580 | 5.85k | } |
2581 | | |
2582 | | /* UXTL<Q> <Vd>.<Ta>, <Vn>.<Tb> |
2583 | | is equivalent to: |
2584 | | USHLL<Q> <Vd>.<Ta>, <Vn>.<Tb>, #0. */ |
2585 | | static int |
2586 | | convert_shll_to_xtl (aarch64_inst *inst) |
2587 | 59 | { |
2588 | 59 | if (inst->operands[2].imm.value == 0) |
2589 | 44 | { |
2590 | 44 | inst->operands[2].type = AARCH64_OPND_NIL; |
2591 | 44 | return 1; |
2592 | 44 | } |
2593 | 15 | return 0; |
2594 | 59 | } |
2595 | | |
2596 | | /* Convert |
2597 | | UBFM <Xd>, <Xn>, #<shift>, #63. |
2598 | | to |
2599 | | LSR <Xd>, <Xn>, #<shift>. */ |
2600 | | static int |
2601 | | convert_bfm_to_sr (aarch64_inst *inst) |
2602 | 59.7k | { |
2603 | 59.7k | int64_t imms, val; |
2604 | | |
2605 | 59.7k | imms = inst->operands[3].imm.value; |
2606 | 59.7k | val = inst->operands[2].qualifier == AARCH64_OPND_QLF_imm_0_31 ? 31 : 63; |
2607 | 59.7k | if (imms == val) |
2608 | 1.08k | { |
2609 | 1.08k | inst->operands[3].type = AARCH64_OPND_NIL; |
2610 | 1.08k | return 1; |
2611 | 1.08k | } |
2612 | | |
2613 | 58.6k | return 0; |
2614 | 59.7k | } |
2615 | | |
2616 | | /* Convert MOV to ORR. */ |
2617 | | static int |
2618 | | convert_orr_to_mov (aarch64_inst *inst) |
2619 | 235 | { |
2620 | | /* MOV <Vd>.<T>, <Vn>.<T> |
2621 | | is equivalent to: |
2622 | | ORR <Vd>.<T>, <Vn>.<T>, <Vn>.<T>. */ |
2623 | 235 | if (inst->operands[1].reg.regno == inst->operands[2].reg.regno) |
2624 | 2 | { |
2625 | 2 | inst->operands[2].type = AARCH64_OPND_NIL; |
2626 | 2 | return 1; |
2627 | 2 | } |
2628 | 233 | return 0; |
2629 | 235 | } |
2630 | | |
2631 | | /* When <imms> >= <immr>, the instruction written: |
2632 | | SBFX <Xd>, <Xn>, #<lsb>, #<width> |
2633 | | is equivalent to: |
2634 | | SBFM <Xd>, <Xn>, #<lsb>, #(<lsb>+<width>-1). */ |
2635 | | |
2636 | | static int |
2637 | | convert_bfm_to_bfx (aarch64_inst *inst) |
2638 | 70.2k | { |
2639 | 70.2k | int64_t immr, imms; |
2640 | | |
2641 | 70.2k | immr = inst->operands[2].imm.value; |
2642 | 70.2k | imms = inst->operands[3].imm.value; |
2643 | 70.2k | if (imms >= immr) |
2644 | 22.2k | { |
2645 | 22.2k | int64_t lsb = immr; |
2646 | 22.2k | inst->operands[2].imm.value = lsb; |
2647 | 22.2k | inst->operands[3].imm.value = imms + 1 - lsb; |
2648 | | /* The two opcodes have different qualifiers for |
2649 | | the immediate operands; reset to help the checking. */ |
2650 | 22.2k | reset_operand_qualifier (inst, 2); |
2651 | 22.2k | reset_operand_qualifier (inst, 3); |
2652 | 22.2k | return 1; |
2653 | 22.2k | } |
2654 | | |
2655 | 48.0k | return 0; |
2656 | 70.2k | } |
2657 | | |
2658 | | /* When <imms> < <immr>, the instruction written: |
2659 | | SBFIZ <Xd>, <Xn>, #<lsb>, #<width> |
2660 | | is equivalent to: |
2661 | | SBFM <Xd>, <Xn>, #((64-<lsb>)&0x3f), #(<width>-1). */ |
2662 | | |
2663 | | static int |
2664 | | convert_bfm_to_bfi (aarch64_inst *inst) |
2665 | 48.0k | { |
2666 | 48.0k | int64_t immr, imms, val; |
2667 | | |
2668 | 48.0k | immr = inst->operands[2].imm.value; |
2669 | 48.0k | imms = inst->operands[3].imm.value; |
2670 | 48.0k | val = inst->operands[2].qualifier == AARCH64_OPND_QLF_imm_0_31 ? 32 : 64; |
2671 | 48.0k | if (imms < immr) |
2672 | 48.0k | { |
2673 | 48.0k | inst->operands[2].imm.value = (val - immr) & (val - 1); |
2674 | 48.0k | inst->operands[3].imm.value = imms + 1; |
2675 | | /* The two opcodes have different qualifiers for |
2676 | | the immediate operands; reset to help the checking. */ |
2677 | 48.0k | reset_operand_qualifier (inst, 2); |
2678 | 48.0k | reset_operand_qualifier (inst, 3); |
2679 | 48.0k | return 1; |
2680 | 48.0k | } |
2681 | | |
2682 | 0 | return 0; |
2683 | 48.0k | } |
2684 | | |
2685 | | /* The instruction written: |
2686 | | BFC <Xd>, #<lsb>, #<width> |
2687 | | is equivalent to: |
2688 | | BFM <Xd>, XZR, #((64-<lsb>)&0x3f), #(<width>-1). */ |
2689 | | |
2690 | | static int |
2691 | | convert_bfm_to_bfc (aarch64_inst *inst) |
2692 | 442 | { |
2693 | 442 | int64_t immr, imms, val; |
2694 | | |
2695 | | /* Should have been assured by the base opcode value. */ |
2696 | 442 | assert (inst->operands[1].reg.regno == 0x1f); |
2697 | | |
2698 | 442 | immr = inst->operands[2].imm.value; |
2699 | 442 | imms = inst->operands[3].imm.value; |
2700 | 442 | val = inst->operands[2].qualifier == AARCH64_OPND_QLF_imm_0_31 ? 32 : 64; |
2701 | 442 | if (imms < immr) |
2702 | 247 | { |
2703 | | /* Drop XZR from the second operand. */ |
2704 | 247 | copy_operand_info (inst, 1, 2); |
2705 | 247 | copy_operand_info (inst, 2, 3); |
2706 | 247 | inst->operands[3].type = AARCH64_OPND_NIL; |
2707 | | |
2708 | | /* Recalculate the immediates. */ |
2709 | 247 | inst->operands[1].imm.value = (val - immr) & (val - 1); |
2710 | 247 | inst->operands[2].imm.value = imms + 1; |
2711 | | |
2712 | | /* The two opcodes have different qualifiers for the operands; reset to |
2713 | | help the checking. */ |
2714 | 247 | reset_operand_qualifier (inst, 1); |
2715 | 247 | reset_operand_qualifier (inst, 2); |
2716 | 247 | reset_operand_qualifier (inst, 3); |
2717 | | |
2718 | 247 | return 1; |
2719 | 247 | } |
2720 | | |
2721 | 195 | return 0; |
2722 | 442 | } |
2723 | | |
2724 | | /* The instruction written: |
2725 | | LSL <Xd>, <Xn>, #<shift> |
2726 | | is equivalent to: |
2727 | | UBFM <Xd>, <Xn>, #((64-<shift>)&0x3f), #(63-<shift>). */ |
2728 | | |
2729 | | static int |
2730 | | convert_ubfm_to_lsl (aarch64_inst *inst) |
2731 | 12.3k | { |
2732 | 12.3k | int64_t immr = inst->operands[2].imm.value; |
2733 | 12.3k | int64_t imms = inst->operands[3].imm.value; |
2734 | 12.3k | int64_t val |
2735 | 12.3k | = inst->operands[2].qualifier == AARCH64_OPND_QLF_imm_0_31 ? 31 : 63; |
2736 | | |
2737 | 12.3k | if ((immr == 0 && imms == val) || immr == imms + 1) |
2738 | 434 | { |
2739 | 434 | inst->operands[3].type = AARCH64_OPND_NIL; |
2740 | 434 | inst->operands[2].imm.value = val - imms; |
2741 | 434 | return 1; |
2742 | 434 | } |
2743 | | |
2744 | 11.9k | return 0; |
2745 | 12.3k | } |
2746 | | |
2747 | | /* CINC <Wd>, <Wn>, <cond> |
2748 | | is equivalent to: |
2749 | | CSINC <Wd>, <Wn>, <Wn>, invert(<cond>) |
2750 | | where <cond> is not AL or NV. */ |
2751 | | |
2752 | | static int |
2753 | | convert_from_csel (aarch64_inst *inst) |
2754 | 5.51k | { |
2755 | 5.51k | if (inst->operands[1].reg.regno == inst->operands[2].reg.regno |
2756 | 5.51k | && (inst->operands[3].cond->value & 0xe) != 0xe) |
2757 | 230 | { |
2758 | 230 | copy_operand_info (inst, 2, 3); |
2759 | 230 | inst->operands[2].cond = get_inverted_cond (inst->operands[3].cond); |
2760 | 230 | inst->operands[3].type = AARCH64_OPND_NIL; |
2761 | 230 | return 1; |
2762 | 230 | } |
2763 | 5.28k | return 0; |
2764 | 5.51k | } |
2765 | | |
2766 | | /* CSET <Wd>, <cond> |
2767 | | is equivalent to: |
2768 | | CSINC <Wd>, WZR, WZR, invert(<cond>) |
2769 | | where <cond> is not AL or NV. */ |
2770 | | |
2771 | | static int |
2772 | | convert_csinc_to_cset (aarch64_inst *inst) |
2773 | 661 | { |
2774 | 661 | if (inst->operands[1].reg.regno == 0x1f |
2775 | 661 | && inst->operands[2].reg.regno == 0x1f |
2776 | 661 | && (inst->operands[3].cond->value & 0xe) != 0xe) |
2777 | 661 | { |
2778 | 661 | copy_operand_info (inst, 1, 3); |
2779 | 661 | inst->operands[1].cond = get_inverted_cond (inst->operands[3].cond); |
2780 | 661 | inst->operands[3].type = AARCH64_OPND_NIL; |
2781 | 661 | inst->operands[2].type = AARCH64_OPND_NIL; |
2782 | 661 | return 1; |
2783 | 661 | } |
2784 | 0 | return 0; |
2785 | 661 | } |
2786 | | |
2787 | | /* MOV <Wd>, #<imm> |
2788 | | is equivalent to: |
2789 | | MOVZ <Wd>, #<imm16_5>, LSL #<shift>. |
2790 | | |
2791 | | A disassembler may output ORR, MOVZ and MOVN as a MOV mnemonic, except when |
2792 | | ORR has an immediate that could be generated by a MOVZ or MOVN instruction, |
2793 | | or where a MOVN has an immediate that could be encoded by MOVZ, or where |
2794 | | MOVZ/MOVN #0 have a shift amount other than LSL #0, in which case the |
2795 | | machine-instruction mnemonic must be used. */ |
2796 | | |
2797 | | static int |
2798 | | convert_movewide_to_mov (aarch64_inst *inst) |
2799 | 71.8k | { |
2800 | 71.8k | uint64_t value = inst->operands[1].imm.value; |
2801 | | /* MOVZ/MOVN #0 have a shift amount other than LSL #0. */ |
2802 | 71.8k | if (value == 0 && inst->operands[1].shifter.amount != 0) |
2803 | 18 | return 0; |
2804 | 71.8k | inst->operands[1].type = AARCH64_OPND_IMM_MOV; |
2805 | 71.8k | inst->operands[1].shifter.kind = AARCH64_MOD_NONE; |
2806 | 71.8k | value <<= inst->operands[1].shifter.amount; |
2807 | | /* As an alias convertor, it has to be clear that the INST->OPCODE |
2808 | | is the opcode of the real instruction. */ |
2809 | 71.8k | if (inst->opcode->op == OP_MOVN) |
2810 | 30.9k | { |
2811 | 30.9k | int is32 = inst->operands[0].qualifier == AARCH64_OPND_QLF_W; |
2812 | 30.9k | value = ~value; |
2813 | | /* A MOVN has an immediate that could be encoded by MOVZ. */ |
2814 | 30.9k | if (aarch64_wide_constant_p (value, is32, NULL)) |
2815 | 0 | return 0; |
2816 | 30.9k | } |
2817 | 71.8k | inst->operands[1].imm.value = value; |
2818 | 71.8k | inst->operands[1].shifter.amount = 0; |
2819 | 71.8k | return 1; |
2820 | 71.8k | } |
2821 | | |
2822 | | /* MOV <Wd>, #<imm> |
2823 | | is equivalent to: |
2824 | | ORR <Wd>, WZR, #<imm>. |
2825 | | |
2826 | | A disassembler may output ORR, MOVZ and MOVN as a MOV mnemonic, except when |
2827 | | ORR has an immediate that could be generated by a MOVZ or MOVN instruction, |
2828 | | or where a MOVN has an immediate that could be encoded by MOVZ, or where |
2829 | | MOVZ/MOVN #0 have a shift amount other than LSL #0, in which case the |
2830 | | machine-instruction mnemonic must be used. */ |
2831 | | |
2832 | | static int |
2833 | | convert_movebitmask_to_mov (aarch64_inst *inst) |
2834 | 957 | { |
2835 | 957 | int is32; |
2836 | 957 | uint64_t value; |
2837 | | |
2838 | | /* Should have been assured by the base opcode value. */ |
2839 | 957 | assert (inst->operands[1].reg.regno == 0x1f); |
2840 | 957 | copy_operand_info (inst, 1, 2); |
2841 | 957 | is32 = inst->operands[0].qualifier == AARCH64_OPND_QLF_W; |
2842 | 957 | inst->operands[1].type = AARCH64_OPND_IMM_MOV; |
2843 | 957 | value = inst->operands[1].imm.value; |
2844 | | /* ORR has an immediate that could be generated by a MOVZ or MOVN |
2845 | | instruction. */ |
2846 | 957 | if (inst->operands[0].reg.regno != 0x1f |
2847 | 957 | && (aarch64_wide_constant_p (value, is32, NULL) |
2848 | 780 | || aarch64_wide_constant_p (~value, is32, NULL))) |
2849 | 168 | return 0; |
2850 | | |
2851 | 789 | inst->operands[2].type = AARCH64_OPND_NIL; |
2852 | 789 | return 1; |
2853 | 957 | } |
2854 | | |
2855 | | /* Some alias opcodes are disassembled by being converted from their real-form. |
2856 | | N.B. INST->OPCODE is the real opcode rather than the alias. */ |
2857 | | |
2858 | | static int |
2859 | | convert_to_alias (aarch64_inst *inst, const aarch64_opcode *alias) |
2860 | 276k | { |
2861 | 276k | switch (alias->op) |
2862 | 276k | { |
2863 | 47.0k | case OP_ASR_IMM: |
2864 | 59.7k | case OP_LSR_IMM: |
2865 | 59.7k | return convert_bfm_to_sr (inst); |
2866 | 12.3k | case OP_LSL_IMM: |
2867 | 12.3k | return convert_ubfm_to_lsl (inst); |
2868 | 1.67k | case OP_CINC: |
2869 | 3.61k | case OP_CINV: |
2870 | 5.51k | case OP_CNEG: |
2871 | 5.51k | return convert_from_csel (inst); |
2872 | 653 | case OP_CSET: |
2873 | 661 | case OP_CSETM: |
2874 | 661 | return convert_csinc_to_cset (inst); |
2875 | 11.9k | case OP_UBFX: |
2876 | 23.9k | case OP_BFXIL: |
2877 | 70.2k | case OP_SBFX: |
2878 | 70.2k | return convert_bfm_to_bfx (inst); |
2879 | 37.0k | case OP_SBFIZ: |
2880 | 42.4k | case OP_BFI: |
2881 | 48.0k | case OP_UBFIZ: |
2882 | 48.0k | return convert_bfm_to_bfi (inst); |
2883 | 442 | case OP_BFC: |
2884 | 442 | return convert_bfm_to_bfc (inst); |
2885 | 235 | case OP_MOV_V: |
2886 | 235 | return convert_orr_to_mov (inst); |
2887 | 40.9k | case OP_MOV_IMM_WIDE: |
2888 | 71.8k | case OP_MOV_IMM_WIDEN: |
2889 | 71.8k | return convert_movewide_to_mov (inst); |
2890 | 957 | case OP_MOV_IMM_LOG: |
2891 | 957 | return convert_movebitmask_to_mov (inst); |
2892 | 5.85k | case OP_ROR_IMM: |
2893 | 5.85k | return convert_extr_to_ror (inst); |
2894 | 36 | case OP_SXTL: |
2895 | 46 | case OP_SXTL2: |
2896 | 52 | case OP_UXTL: |
2897 | 59 | case OP_UXTL2: |
2898 | 59 | return convert_shll_to_xtl (inst); |
2899 | 0 | default: |
2900 | 0 | return 0; |
2901 | 276k | } |
2902 | 276k | } |
2903 | | |
2904 | | static bool |
2905 | | aarch64_opcode_decode (const aarch64_opcode *, const aarch64_insn, |
2906 | | aarch64_inst *, int, aarch64_operand_error *errors); |
2907 | | |
2908 | | /* Given the instruction information in *INST, check if the instruction has |
2909 | | any alias form that can be used to represent *INST. If the answer is yes, |
2910 | | update *INST to be in the form of the determined alias. */ |
2911 | | |
2912 | | /* In the opcode description table, the following flags are used in opcode |
2913 | | entries to help establish the relations between the real and alias opcodes: |
2914 | | |
2915 | | F_ALIAS: opcode is an alias |
2916 | | F_HAS_ALIAS: opcode has alias(es) |
2917 | | F_P1 |
2918 | | F_P2 |
2919 | | F_P3: Disassembly preference priority 1-3 (the larger the |
2920 | | higher). If nothing is specified, it is the priority |
2921 | | 0 by default, i.e. the lowest priority. |
2922 | | |
2923 | | Although the relation between the machine and the alias instructions are not |
2924 | | explicitly described, it can be easily determined from the base opcode |
2925 | | values, masks and the flags F_ALIAS and F_HAS_ALIAS in their opcode |
2926 | | description entries: |
2927 | | |
2928 | | The mask of an alias opcode must be equal to or a super-set (i.e. more |
2929 | | constrained) of that of the aliased opcode; so is the base opcode value. |
2930 | | |
2931 | | if (opcode_has_alias (real) && alias_opcode_p (opcode) |
2932 | | && (opcode->mask & real->mask) == real->mask |
2933 | | && (real->mask & opcode->opcode) == (real->mask & real->opcode)) |
2934 | | then OPCODE is an alias of, and only of, the REAL instruction |
2935 | | |
2936 | | The alias relationship is forced flat-structured to keep related algorithm |
2937 | | simple; an opcode entry cannot be flagged with both F_ALIAS and F_HAS_ALIAS. |
2938 | | |
2939 | | During the disassembling, the decoding decision tree (in |
2940 | | opcodes/aarch64-dis-2.c) always returns an machine instruction opcode entry; |
2941 | | if the decoding of such a machine instruction succeeds (and -Mno-aliases is |
2942 | | not specified), the disassembler will check whether there is any alias |
2943 | | instruction exists for this real instruction. If there is, the disassembler |
2944 | | will try to disassemble the 32-bit binary again using the alias's rule, or |
2945 | | try to convert the IR to the form of the alias. In the case of the multiple |
2946 | | aliases, the aliases are tried one by one from the highest priority |
2947 | | (currently the flag F_P3) to the lowest priority (no priority flag), and the |
2948 | | first succeeds first adopted. |
2949 | | |
2950 | | You may ask why there is a need for the conversion of IR from one form to |
2951 | | another in handling certain aliases. This is because on one hand it avoids |
2952 | | adding more operand code to handle unusual encoding/decoding; on other |
2953 | | hand, during the disassembling, the conversion is an effective approach to |
2954 | | check the condition of an alias (as an alias may be adopted only if certain |
2955 | | conditions are met). |
2956 | | |
2957 | | In order to speed up the alias opcode lookup, aarch64-gen has preprocessed |
2958 | | aarch64_opcode_table and generated aarch64_find_alias_opcode and |
2959 | | aarch64_find_next_alias_opcode (in opcodes/aarch64-dis-2.c) to help. */ |
2960 | | |
2961 | | static void |
2962 | | determine_disassembling_preference (struct aarch64_inst *inst, |
2963 | | aarch64_operand_error *errors) |
2964 | 6.00M | { |
2965 | 6.00M | const aarch64_opcode *opcode; |
2966 | 6.00M | const aarch64_opcode *alias; |
2967 | | |
2968 | 6.00M | opcode = inst->opcode; |
2969 | | |
2970 | | /* This opcode does not have an alias, so use itself. */ |
2971 | 6.00M | if (!opcode_has_alias (opcode)) |
2972 | 5.26M | return; |
2973 | | |
2974 | 735k | alias = aarch64_find_alias_opcode (opcode); |
2975 | 735k | assert (alias); |
2976 | | |
2977 | | #ifdef DEBUG_AARCH64 |
2978 | | if (debug_dump) |
2979 | | { |
2980 | | const aarch64_opcode *tmp = alias; |
2981 | | printf ("#### LIST orderd: "); |
2982 | | while (tmp) |
2983 | | { |
2984 | | printf ("%s, ", tmp->name); |
2985 | | tmp = aarch64_find_next_alias_opcode (tmp); |
2986 | | } |
2987 | | printf ("\n"); |
2988 | | } |
2989 | | #endif /* DEBUG_AARCH64 */ |
2990 | | |
2991 | 1.66M | for (; alias; alias = aarch64_find_next_alias_opcode (alias)) |
2992 | 1.66M | { |
2993 | 1.66M | DEBUG_TRACE ("try %s", alias->name); |
2994 | 1.66M | assert (alias_opcode_p (alias) || opcode_has_alias (opcode)); |
2995 | | |
2996 | | /* An alias can be a pseudo opcode which will never be used in the |
2997 | | disassembly, e.g. BIC logical immediate is such a pseudo opcode |
2998 | | aliasing AND. */ |
2999 | 1.66M | if (pseudo_opcode_p (alias)) |
3000 | 133k | { |
3001 | 133k | DEBUG_TRACE ("skip pseudo %s", alias->name); |
3002 | 133k | continue; |
3003 | 133k | } |
3004 | | |
3005 | 1.52M | if ((inst->value & alias->mask) != alias->opcode) |
3006 | 650k | { |
3007 | 650k | DEBUG_TRACE ("skip %s as base opcode not match", alias->name); |
3008 | 650k | continue; |
3009 | 650k | } |
3010 | | |
3011 | 877k | if (!AARCH64_CPU_HAS_FEATURE (arch_variant, *alias->avariant)) |
3012 | 0 | { |
3013 | 0 | DEBUG_TRACE ("skip %s: we're missing features", alias->name); |
3014 | 0 | continue; |
3015 | 0 | } |
3016 | | |
3017 | | /* No need to do any complicated transformation on operands, if the alias |
3018 | | opcode does not have any operand. */ |
3019 | 877k | if (aarch64_num_of_operands (alias) == 0 && alias->opcode == inst->value) |
3020 | 27 | { |
3021 | 27 | DEBUG_TRACE ("succeed with 0-operand opcode %s", alias->name); |
3022 | 27 | aarch64_replace_opcode (inst, alias); |
3023 | 27 | return; |
3024 | 27 | } |
3025 | 877k | if (alias->flags & F_CONV) |
3026 | 276k | { |
3027 | 276k | aarch64_inst copy; |
3028 | 276k | memcpy (©, inst, sizeof (aarch64_inst)); |
3029 | | /* ALIAS is the preference as long as the instruction can be |
3030 | | successfully converted to the form of ALIAS. */ |
3031 | 276k | if (convert_to_alias (©, alias) == 1) |
3032 | 145k | { |
3033 | 145k | aarch64_replace_opcode (©, alias); |
3034 | 145k | if (aarch64_match_operands_constraint (©, NULL) != 1) |
3035 | 0 | { |
3036 | 0 | DEBUG_TRACE ("FAILED with alias %s ", alias->name); |
3037 | 0 | } |
3038 | 145k | else |
3039 | 145k | { |
3040 | 145k | DEBUG_TRACE ("succeed with %s via conversion", alias->name); |
3041 | 145k | memcpy (inst, ©, sizeof (aarch64_inst)); |
3042 | 145k | } |
3043 | 145k | return; |
3044 | 145k | } |
3045 | 276k | } |
3046 | 601k | else |
3047 | 601k | { |
3048 | | /* Directly decode the alias opcode. */ |
3049 | 601k | aarch64_inst temp; |
3050 | 601k | memset (&temp, '\0', sizeof (aarch64_inst)); |
3051 | 601k | if (aarch64_opcode_decode (alias, inst->value, &temp, 1, errors) == 1) |
3052 | 589k | { |
3053 | 589k | DEBUG_TRACE ("succeed with %s via direct decoding", alias->name); |
3054 | 589k | memcpy (inst, &temp, sizeof (aarch64_inst)); |
3055 | 589k | return; |
3056 | 589k | } |
3057 | 601k | } |
3058 | 877k | } |
3059 | 735k | } |
3060 | | |
3061 | | /* Some instructions (including all SVE ones) use the instruction class |
3062 | | to describe how a qualifiers_list index is represented in the instruction |
3063 | | encoding. If INST is such an instruction, decode the appropriate fields |
3064 | | and fill in the operand qualifiers accordingly. Return true if no |
3065 | | problems are found. */ |
3066 | | |
3067 | | static bool |
3068 | | aarch64_decode_variant_using_iclass (aarch64_inst *inst) |
3069 | 7.55M | { |
3070 | 7.55M | int i, variant; |
3071 | | |
3072 | 7.55M | variant = 0; |
3073 | 7.55M | switch (inst->opcode->iclass) |
3074 | 7.55M | { |
3075 | 7.42k | case sme_mov: |
3076 | 7.42k | variant = extract_fields (inst->value, 0, 2, FLD_SME_Q, FLD_SME_size_22); |
3077 | 7.42k | if (variant >= 4 && variant < 7) |
3078 | 2.85k | return false; |
3079 | 4.56k | if (variant == 7) |
3080 | 119 | variant = 4; |
3081 | 4.56k | break; |
3082 | | |
3083 | 1.67k | case sme_psel: |
3084 | 1.67k | i = extract_fields (inst->value, 0, 2, FLD_SME_tszh, FLD_SME_tszl); |
3085 | 1.67k | if (i == 0) |
3086 | 878 | return false; |
3087 | 1.34k | while ((i & 1) == 0) |
3088 | 546 | { |
3089 | 546 | i >>= 1; |
3090 | 546 | variant += 1; |
3091 | 546 | } |
3092 | 797 | break; |
3093 | | |
3094 | 178 | case sme_shift: |
3095 | 178 | i = extract_field (FLD_SVE_tszh, inst->value, 0); |
3096 | 178 | goto sve_shift; |
3097 | | |
3098 | 154 | case sme_size_12_bhs: |
3099 | 154 | variant = extract_field (FLD_SME_size_12, inst->value, 0); |
3100 | 154 | if (variant >= 3) |
3101 | 22 | return false; |
3102 | 132 | break; |
3103 | | |
3104 | 132 | case sme_size_12_hs: |
3105 | 33 | variant = extract_field (FLD_SME_size_12, inst->value, 0); |
3106 | 33 | if (variant != 1 && variant != 2) |
3107 | 33 | return false; |
3108 | 0 | variant -= 1; |
3109 | 0 | break; |
3110 | | |
3111 | 3.87k | case sme_size_22: |
3112 | 3.87k | variant = extract_field (FLD_SME_size_22, inst->value, 0); |
3113 | 3.87k | break; |
3114 | | |
3115 | 770 | case sme_size_22_hsd: |
3116 | 770 | variant = extract_field (FLD_SME_size_22, inst->value, 0); |
3117 | 770 | if (variant < 1) |
3118 | 180 | return false; |
3119 | 590 | variant -= 1; |
3120 | 590 | break; |
3121 | | |
3122 | 0 | case sme_sz_23: |
3123 | 0 | variant = extract_field (FLD_SME_sz_23, inst->value, 0); |
3124 | 0 | break; |
3125 | | |
3126 | 28.4k | case sve_cpy: |
3127 | 28.4k | variant = extract_fields (inst->value, 0, 2, FLD_size, FLD_SVE_M_14); |
3128 | 28.4k | break; |
3129 | | |
3130 | 571 | case sve_index: |
3131 | 571 | i = extract_fields (inst->value, 0, 2, FLD_SVE_tszh, FLD_imm5); |
3132 | 571 | if ((i & 31) == 0) |
3133 | 1 | return false; |
3134 | 1.38k | while ((i & 1) == 0) |
3135 | 816 | { |
3136 | 816 | i >>= 1; |
3137 | 816 | variant += 1; |
3138 | 816 | } |
3139 | 570 | break; |
3140 | | |
3141 | 33.4k | case sve_limm: |
3142 | | /* Pick the smallest applicable element size. */ |
3143 | 33.4k | if ((inst->value & 0x20600) == 0x600) |
3144 | 2.76k | variant = 0; |
3145 | 30.6k | else if ((inst->value & 0x20400) == 0x400) |
3146 | 3.51k | variant = 1; |
3147 | 27.1k | else if ((inst->value & 0x20000) == 0) |
3148 | 22.9k | variant = 2; |
3149 | 4.20k | else |
3150 | 4.20k | variant = 3; |
3151 | 33.4k | break; |
3152 | | |
3153 | 35 | case sme2_mov: |
3154 | | /* .D is preferred over the other sizes in disassembly. */ |
3155 | 35 | variant = 3; |
3156 | 35 | break; |
3157 | | |
3158 | 48.5k | case sme_misc: |
3159 | 416k | case sve_misc: |
3160 | | /* These instructions have only a single variant. */ |
3161 | 416k | break; |
3162 | | |
3163 | 157 | case sve_movprfx: |
3164 | 157 | variant = extract_fields (inst->value, 0, 2, FLD_size, FLD_SVE_M_16); |
3165 | 157 | break; |
3166 | | |
3167 | 3 | case sve_pred_zm: |
3168 | 3 | variant = extract_field (FLD_SVE_M_4, inst->value, 0); |
3169 | 3 | break; |
3170 | | |
3171 | 3.27k | case sve_shift_pred: |
3172 | 3.27k | i = extract_fields (inst->value, 0, 2, FLD_SVE_tszh, FLD_SVE_tszl_8); |
3173 | 4.71k | sve_shift: |
3174 | 4.71k | if (i == 0) |
3175 | 865 | return false; |
3176 | 10.6k | while (i != 1) |
3177 | 6.84k | { |
3178 | 6.84k | i >>= 1; |
3179 | 6.84k | variant += 1; |
3180 | 6.84k | } |
3181 | 3.84k | break; |
3182 | | |
3183 | 1.25k | case sve_shift_unpred: |
3184 | 1.25k | i = extract_fields (inst->value, 0, 2, FLD_SVE_tszh, FLD_SVE_tszl_19); |
3185 | 1.25k | goto sve_shift; |
3186 | | |
3187 | 16.1k | case sve_size_bhs: |
3188 | 16.1k | variant = extract_field (FLD_size, inst->value, 0); |
3189 | 16.1k | if (variant >= 3) |
3190 | 3.81k | return false; |
3191 | 12.3k | break; |
3192 | | |
3193 | 164k | case sve_size_bhsd: |
3194 | 164k | variant = extract_field (FLD_size, inst->value, 0); |
3195 | 164k | break; |
3196 | | |
3197 | 117k | case sve_size_hsd: |
3198 | 117k | i = extract_field (FLD_size, inst->value, 0); |
3199 | 117k | if (i < 1) |
3200 | 34.0k | return false; |
3201 | 83.3k | variant = i - 1; |
3202 | 83.3k | break; |
3203 | | |
3204 | 154 | case sme_fp_sd: |
3205 | 1.77k | case sme_int_sd: |
3206 | 3.40k | case sve_size_bh: |
3207 | 7.94k | case sve_size_sd: |
3208 | 7.94k | variant = extract_field (FLD_SVE_sz, inst->value, 0); |
3209 | 7.94k | break; |
3210 | | |
3211 | 3.16k | case sve_size_sd2: |
3212 | 3.16k | variant = extract_field (FLD_SVE_sz2, inst->value, 0); |
3213 | 3.16k | break; |
3214 | | |
3215 | 14 | case sve_size_hsd2: |
3216 | 14 | i = extract_field (FLD_SVE_size, inst->value, 0); |
3217 | 14 | if (i < 1) |
3218 | 0 | return false; |
3219 | 14 | variant = i - 1; |
3220 | 14 | break; |
3221 | | |
3222 | 1.57k | case sve_size_13: |
3223 | | /* Ignore low bit of this field since that is set in the opcode for |
3224 | | instructions of this iclass. */ |
3225 | 1.57k | i = (extract_field (FLD_size, inst->value, 0) & 2); |
3226 | 1.57k | variant = (i >> 1); |
3227 | 1.57k | break; |
3228 | | |
3229 | 2.49k | case sve_shift_tsz_bhsd: |
3230 | 2.49k | i = extract_fields (inst->value, 0, 2, FLD_SVE_tszh, FLD_SVE_tszl_19); |
3231 | 2.49k | if (i == 0) |
3232 | 425 | return false; |
3233 | 6.29k | while (i != 1) |
3234 | 4.22k | { |
3235 | 4.22k | i >>= 1; |
3236 | 4.22k | variant += 1; |
3237 | 4.22k | } |
3238 | 2.07k | break; |
3239 | | |
3240 | 167 | case sve_size_tsz_bhs: |
3241 | 167 | i = extract_fields (inst->value, 0, 2, FLD_SVE_sz, FLD_SVE_tszl_19); |
3242 | 167 | if (i == 0) |
3243 | 0 | return false; |
3244 | 248 | while (i != 1) |
3245 | 171 | { |
3246 | 171 | if (i & 1) |
3247 | 90 | return false; |
3248 | 81 | i >>= 1; |
3249 | 81 | variant += 1; |
3250 | 81 | } |
3251 | 77 | break; |
3252 | | |
3253 | 6.31k | case sve_shift_tsz_hsd: |
3254 | 6.31k | i = extract_fields (inst->value, 0, 2, FLD_SVE_sz, FLD_SVE_tszl_19); |
3255 | 6.31k | if (i == 0) |
3256 | 500 | return false; |
3257 | 16.0k | while (i != 1) |
3258 | 10.2k | { |
3259 | 10.2k | i >>= 1; |
3260 | 10.2k | variant += 1; |
3261 | 10.2k | } |
3262 | 5.81k | break; |
3263 | | |
3264 | 6.73M | default: |
3265 | | /* No mapping between instruction class and qualifiers. */ |
3266 | 6.73M | return true; |
3267 | 7.55M | } |
3268 | | |
3269 | 5.41M | for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) |
3270 | 4.64M | inst->operands[i].qualifier = inst->opcode->qualifiers_list[variant][i]; |
3271 | 773k | return true; |
3272 | 7.55M | } |
3273 | | /* Decode the CODE according to OPCODE; fill INST. Return 0 if the decoding |
3274 | | fails, which meanes that CODE is not an instruction of OPCODE; otherwise |
3275 | | return 1. |
3276 | | |
3277 | | If OPCODE has alias(es) and NOALIASES_P is 0, an alias opcode may be |
3278 | | determined and used to disassemble CODE; this is done just before the |
3279 | | return. */ |
3280 | | |
3281 | | static bool |
3282 | | aarch64_opcode_decode (const aarch64_opcode *opcode, const aarch64_insn code, |
3283 | | aarch64_inst *inst, int noaliases_p, |
3284 | | aarch64_operand_error *errors) |
3285 | 18.3M | { |
3286 | 18.3M | int i; |
3287 | | |
3288 | 18.3M | DEBUG_TRACE ("enter with %s", opcode->name); |
3289 | | |
3290 | 18.3M | assert (opcode && inst); |
3291 | | |
3292 | | /* Clear inst. */ |
3293 | 18.3M | memset (inst, '\0', sizeof (aarch64_inst)); |
3294 | | |
3295 | | /* Check the base opcode. */ |
3296 | 18.3M | if ((code & opcode->mask) != (opcode->opcode & opcode->mask)) |
3297 | 10.6M | { |
3298 | 10.6M | DEBUG_TRACE ("base opcode match FAIL"); |
3299 | 10.6M | goto decode_fail; |
3300 | 10.6M | } |
3301 | | |
3302 | 7.71M | inst->opcode = opcode; |
3303 | 7.71M | inst->value = code; |
3304 | | |
3305 | | /* Assign operand codes and indexes. */ |
3306 | 26.5M | for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) |
3307 | 26.5M | { |
3308 | 26.5M | if (opcode->operands[i] == AARCH64_OPND_NIL) |
3309 | 7.71M | break; |
3310 | 18.8M | inst->operands[i].type = opcode->operands[i]; |
3311 | 18.8M | inst->operands[i].idx = i; |
3312 | 18.8M | } |
3313 | | |
3314 | | /* Call the opcode decoder indicated by flags. */ |
3315 | 7.71M | if (opcode_has_special_coder (opcode) && do_special_decoding (inst) == 0) |
3316 | 159k | { |
3317 | 159k | DEBUG_TRACE ("opcode flag-based decoder FAIL"); |
3318 | 159k | goto decode_fail; |
3319 | 159k | } |
3320 | | |
3321 | | /* Possibly use the instruction class to determine the correct |
3322 | | qualifier. */ |
3323 | 7.55M | if (!aarch64_decode_variant_using_iclass (inst)) |
3324 | 43.7k | { |
3325 | 43.7k | DEBUG_TRACE ("iclass-based decoder FAIL"); |
3326 | 43.7k | goto decode_fail; |
3327 | 43.7k | } |
3328 | | |
3329 | | /* Call operand decoders. */ |
3330 | 24.6M | for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) |
3331 | 24.6M | { |
3332 | 24.6M | const aarch64_operand *opnd; |
3333 | 24.6M | enum aarch64_opnd type; |
3334 | | |
3335 | 24.6M | type = opcode->operands[i]; |
3336 | 24.6M | if (type == AARCH64_OPND_NIL) |
3337 | 6.89M | break; |
3338 | 17.7M | opnd = &aarch64_operands[type]; |
3339 | 17.7M | if (operand_has_extractor (opnd) |
3340 | 17.7M | && (! aarch64_extract_operand (opnd, &inst->operands[i], code, inst, |
3341 | 17.7M | errors))) |
3342 | 613k | { |
3343 | 613k | DEBUG_TRACE ("operand decoder FAIL at operand %d", i); |
3344 | 613k | goto decode_fail; |
3345 | 613k | } |
3346 | 17.7M | } |
3347 | | |
3348 | | /* If the opcode has a verifier, then check it now. */ |
3349 | 6.89M | if (opcode->verifier |
3350 | 6.89M | && opcode->verifier (inst, code, 0, false, errors, NULL) != ERR_OK) |
3351 | 4.71k | { |
3352 | 4.71k | DEBUG_TRACE ("operand verifier FAIL"); |
3353 | 4.71k | goto decode_fail; |
3354 | 4.71k | } |
3355 | | |
3356 | | /* Match the qualifiers. */ |
3357 | 6.88M | if (aarch64_match_operands_constraint (inst, NULL) == 1) |
3358 | 6.59M | { |
3359 | | /* Arriving here, the CODE has been determined as a valid instruction |
3360 | | of OPCODE and *INST has been filled with information of this OPCODE |
3361 | | instruction. Before the return, check if the instruction has any |
3362 | | alias and should be disassembled in the form of its alias instead. |
3363 | | If the answer is yes, *INST will be updated. */ |
3364 | 6.59M | if (!noaliases_p) |
3365 | 6.00M | determine_disassembling_preference (inst, errors); |
3366 | 6.59M | DEBUG_TRACE ("SUCCESS"); |
3367 | 6.59M | return true; |
3368 | 6.59M | } |
3369 | 296k | else |
3370 | 296k | { |
3371 | 296k | DEBUG_TRACE ("constraint matching FAIL"); |
3372 | 296k | } |
3373 | | |
3374 | 11.8M | decode_fail: |
3375 | 11.8M | return false; |
3376 | 6.88M | } |
3377 | | |
3378 | | /* This does some user-friendly fix-up to *INST. It is currently focus on |
3379 | | the adjustment of qualifiers to help the printed instruction |
3380 | | recognized/understood more easily. */ |
3381 | | |
3382 | | static void |
3383 | | user_friendly_fixup (aarch64_inst *inst) |
3384 | 6.00M | { |
3385 | 6.00M | switch (inst->opcode->iclass) |
3386 | 6.00M | { |
3387 | 191k | case testbranch: |
3388 | | /* TBNZ Xn|Wn, #uimm6, label |
3389 | | Test and Branch Not Zero: conditionally jumps to label if bit number |
3390 | | uimm6 in register Xn is not zero. The bit number implies the width of |
3391 | | the register, which may be written and should be disassembled as Wn if |
3392 | | uimm is less than 32. Limited to a branch offset range of +/- 32KiB. |
3393 | | */ |
3394 | 191k | if (inst->operands[1].imm.value < 32) |
3395 | 116k | inst->operands[0].qualifier = AARCH64_OPND_QLF_W; |
3396 | 191k | break; |
3397 | 5.81M | default: break; |
3398 | 6.00M | } |
3399 | 6.00M | } |
3400 | | |
3401 | | /* Decode INSN and fill in *INST the instruction information. An alias |
3402 | | opcode may be filled in *INSN if NOALIASES_P is FALSE. Return zero on |
3403 | | success. */ |
3404 | | |
3405 | | enum err_type |
3406 | | aarch64_decode_insn (aarch64_insn insn, aarch64_inst *inst, |
3407 | | bool noaliases_p, |
3408 | | aarch64_operand_error *errors) |
3409 | 15.0M | { |
3410 | 15.0M | const aarch64_opcode *opcode = aarch64_opcode_lookup (insn); |
3411 | | |
3412 | | #ifdef DEBUG_AARCH64 |
3413 | | if (debug_dump) |
3414 | | { |
3415 | | const aarch64_opcode *tmp = opcode; |
3416 | | printf ("\n"); |
3417 | | DEBUG_TRACE ("opcode lookup:"); |
3418 | | while (tmp != NULL) |
3419 | | { |
3420 | | aarch64_verbose (" %s", tmp->name); |
3421 | | tmp = aarch64_find_next_opcode (tmp); |
3422 | | } |
3423 | | } |
3424 | | #endif /* DEBUG_AARCH64 */ |
3425 | | |
3426 | | /* A list of opcodes may have been found, as aarch64_opcode_lookup cannot |
3427 | | distinguish some opcodes, e.g. SSHR and MOVI, which almost share the same |
3428 | | opcode field and value, apart from the difference that one of them has an |
3429 | | extra field as part of the opcode, but such a field is used for operand |
3430 | | encoding in other opcode(s) ('immh' in the case of the example). */ |
3431 | 26.7M | while (opcode != NULL) |
3432 | 17.7M | { |
3433 | | /* But only one opcode can be decoded successfully for, as the |
3434 | | decoding routine will check the constraint carefully. */ |
3435 | 17.7M | if (aarch64_opcode_decode (opcode, insn, inst, noaliases_p, errors) == 1) |
3436 | 6.00M | return ERR_OK; |
3437 | 11.7M | opcode = aarch64_find_next_opcode (opcode); |
3438 | 11.7M | } |
3439 | | |
3440 | 8.99M | return ERR_UND; |
3441 | 15.0M | } |
3442 | | |
3443 | | /* Return a short string to indicate a switch to STYLE. These strings |
3444 | | will be embedded into the disassembled operand text (as produced by |
3445 | | aarch64_print_operand), and then spotted in the print_operands function |
3446 | | so that the disassembler output can be split by style. */ |
3447 | | |
3448 | | static const char * |
3449 | | get_style_text (enum disassembler_style style) |
3450 | 33.5M | { |
3451 | 33.5M | static bool init = false; |
3452 | 33.5M | static char formats[16][4]; |
3453 | 33.5M | unsigned num; |
3454 | | |
3455 | | /* First time through we build a string for every possible format. This |
3456 | | code relies on there being no more than 16 different styles (there's |
3457 | | an assert below for this). */ |
3458 | 33.5M | if (!init) |
3459 | 1 | { |
3460 | 1 | int i; |
3461 | | |
3462 | 17 | for (i = 0; i <= 0xf; ++i) |
3463 | 16 | { |
3464 | 16 | int res = snprintf (&formats[i][0], sizeof (formats[i]), "%c%x%c", |
3465 | 16 | STYLE_MARKER_CHAR, i, STYLE_MARKER_CHAR); |
3466 | 16 | assert (res == 3); |
3467 | 16 | } |
3468 | | |
3469 | 1 | init = true; |
3470 | 1 | } |
3471 | | |
3472 | | /* Return the string that marks switching to STYLE. */ |
3473 | 33.5M | num = (unsigned) style; |
3474 | 33.5M | assert (style <= 0xf); |
3475 | 33.5M | return formats[num]; |
3476 | 33.5M | } |
3477 | | |
3478 | | /* Callback used by aarch64_print_operand to apply STYLE to the |
3479 | | disassembler output created from FMT and ARGS. The STYLER object holds |
3480 | | any required state. Must return a pointer to a string (created from FMT |
3481 | | and ARGS) that will continue to be valid until the complete disassembled |
3482 | | instruction has been printed. |
3483 | | |
3484 | | We return a string that includes two embedded style markers, the first, |
3485 | | places at the start of the string, indicates a switch to STYLE, and the |
3486 | | second, placed at the end of the string, indicates a switch back to the |
3487 | | default text style. |
3488 | | |
3489 | | Later, when we print the operand text we take care to collapse any |
3490 | | adjacent style markers, and to ignore any style markers that appear at |
3491 | | the very end of a complete operand string. */ |
3492 | | |
3493 | | static const char *aarch64_apply_style (struct aarch64_styler *styler, |
3494 | | enum disassembler_style style, |
3495 | | const char *fmt, |
3496 | | va_list args) |
3497 | 16.7M | { |
3498 | 16.7M | int res; |
3499 | 16.7M | char *ptr, *tmp; |
3500 | 16.7M | struct obstack *stack = (struct obstack *) styler->state; |
3501 | 16.7M | va_list ap; |
3502 | | |
3503 | | /* These are the two strings for switching styles. */ |
3504 | 16.7M | const char *style_on = get_style_text (style); |
3505 | 16.7M | const char *style_off = get_style_text (dis_style_text); |
3506 | | |
3507 | | /* Calculate space needed once FMT and ARGS are expanded. */ |
3508 | 16.7M | va_copy (ap, args); |
3509 | 16.7M | res = vsnprintf (NULL, 0, fmt, ap); |
3510 | 16.7M | va_end (ap); |
3511 | 16.7M | assert (res >= 0); |
3512 | | |
3513 | | /* Allocate space on the obstack for the expanded FMT and ARGS, as well |
3514 | | as the two strings for switching styles, then write all of these |
3515 | | strings onto the obstack. */ |
3516 | 16.7M | ptr = (char *) obstack_alloc (stack, res + strlen (style_on) |
3517 | 16.7M | + strlen (style_off) + 1); |
3518 | 16.7M | tmp = stpcpy (ptr, style_on); |
3519 | 16.7M | res = vsnprintf (tmp, (res + 1), fmt, args); |
3520 | 16.7M | assert (res >= 0); |
3521 | 16.7M | tmp += res; |
3522 | 16.7M | strcpy (tmp, style_off); |
3523 | | |
3524 | 16.7M | return ptr; |
3525 | 16.7M | } |
3526 | | |
3527 | | /* Print operands. */ |
3528 | | |
3529 | | static void |
3530 | | print_operands (bfd_vma pc, const aarch64_opcode *opcode, |
3531 | | const aarch64_opnd_info *opnds, struct disassemble_info *info, |
3532 | | bool *has_notes) |
3533 | 6.00M | { |
3534 | 6.00M | char *notes = NULL; |
3535 | 6.00M | int i, pcrel_p, num_printed; |
3536 | 6.00M | struct aarch64_styler styler; |
3537 | 6.00M | struct obstack content; |
3538 | 6.00M | obstack_init (&content); |
3539 | | |
3540 | 6.00M | styler.apply_style = aarch64_apply_style; |
3541 | 6.00M | styler.state = (void *) &content; |
3542 | | |
3543 | 19.6M | for (i = 0, num_printed = 0; i < AARCH64_MAX_OPND_NUM; ++i) |
3544 | 19.6M | { |
3545 | 19.6M | char str[128]; |
3546 | 19.6M | char cmt[128]; |
3547 | | |
3548 | | /* We regard the opcode operand info more, however we also look into |
3549 | | the inst->operands to support the disassembling of the optional |
3550 | | operand. |
3551 | | The two operand code should be the same in all cases, apart from |
3552 | | when the operand can be optional. */ |
3553 | 19.6M | if (opcode->operands[i] == AARCH64_OPND_NIL |
3554 | 19.6M | || opnds[i].type == AARCH64_OPND_NIL) |
3555 | 6.00M | break; |
3556 | | |
3557 | | /* Generate the operand string in STR. */ |
3558 | 13.6M | aarch64_print_operand (str, sizeof (str), pc, opcode, opnds, i, &pcrel_p, |
3559 | 13.6M | &info->target, ¬es, cmt, sizeof (cmt), |
3560 | 13.6M | arch_variant, &styler); |
3561 | | |
3562 | | /* Print the delimiter (taking account of omitted operand(s)). */ |
3563 | 13.6M | if (str[0] != '\0') |
3564 | 13.6M | (*info->fprintf_styled_func) (info->stream, dis_style_text, "%s", |
3565 | 13.6M | num_printed++ == 0 ? "\t" : ", "); |
3566 | | |
3567 | | /* Print the operand. */ |
3568 | 13.6M | if (pcrel_p) |
3569 | 1.58M | (*info->print_address_func) (info->target, info); |
3570 | 12.0M | else |
3571 | 12.0M | { |
3572 | | /* This operand came from aarch64_print_operand, and will include |
3573 | | embedded strings indicating which style each character should |
3574 | | have. In the following code we split the text based on |
3575 | | CURR_STYLE, and call the styled print callback to print each |
3576 | | block of text in the appropriate style. */ |
3577 | 12.0M | char *start, *curr; |
3578 | 12.0M | enum disassembler_style curr_style = dis_style_text; |
3579 | | |
3580 | 12.0M | start = curr = str; |
3581 | 12.0M | do |
3582 | 104M | { |
3583 | 104M | if (*curr == '\0' |
3584 | 104M | || (*curr == STYLE_MARKER_CHAR |
3585 | 92.5M | && ISXDIGIT (*(curr + 1)) |
3586 | 92.5M | && *(curr + 2) == STYLE_MARKER_CHAR)) |
3587 | 42.4M | { |
3588 | | /* Output content between our START position and CURR. */ |
3589 | 42.4M | int len = curr - start; |
3590 | 42.4M | if (len > 0) |
3591 | 22.2M | { |
3592 | 22.2M | if ((*info->fprintf_styled_func) (info->stream, |
3593 | 22.2M | curr_style, |
3594 | 22.2M | "%.*s", |
3595 | 22.2M | len, start) < 0) |
3596 | 0 | break; |
3597 | 22.2M | } |
3598 | | |
3599 | 42.4M | if (*curr == '\0') |
3600 | 12.0M | break; |
3601 | | |
3602 | | /* Skip over the initial STYLE_MARKER_CHAR. */ |
3603 | 30.3M | ++curr; |
3604 | | |
3605 | | /* Update the CURR_STYLE. As there are less than 16 |
3606 | | styles, it is possible, that if the input is corrupted |
3607 | | in some way, that we might set CURR_STYLE to an |
3608 | | invalid value. Don't worry though, we check for this |
3609 | | situation. */ |
3610 | 30.3M | if (*curr >= '0' && *curr <= '9') |
3611 | 30.3M | curr_style = (enum disassembler_style) (*curr - '0'); |
3612 | 0 | else if (*curr >= 'a' && *curr <= 'f') |
3613 | 0 | curr_style = (enum disassembler_style) (*curr - 'a' + 10); |
3614 | 0 | else |
3615 | 0 | curr_style = dis_style_text; |
3616 | | |
3617 | | /* Check for an invalid style having been selected. This |
3618 | | should never happen, but it doesn't hurt to be a |
3619 | | little paranoid. */ |
3620 | 30.3M | if (curr_style > dis_style_comment_start) |
3621 | 0 | curr_style = dis_style_text; |
3622 | | |
3623 | | /* Skip the hex character, and the closing STYLE_MARKER_CHAR. */ |
3624 | 30.3M | curr += 2; |
3625 | | |
3626 | | /* Reset the START to after the style marker. */ |
3627 | 30.3M | start = curr; |
3628 | 30.3M | } |
3629 | 62.2M | else |
3630 | 62.2M | ++curr; |
3631 | 104M | } |
3632 | 12.0M | while (true); |
3633 | 12.0M | } |
3634 | | |
3635 | | /* Print the comment. This works because only the last operand ever |
3636 | | adds a comment. If that ever changes then we'll need to be |
3637 | | smarter here. */ |
3638 | 13.6M | if (cmt[0] != '\0') |
3639 | 86.8k | (*info->fprintf_styled_func) (info->stream, dis_style_comment_start, |
3640 | 86.8k | "\t// %s", cmt); |
3641 | 13.6M | } |
3642 | | |
3643 | 6.00M | if (notes && !no_notes) |
3644 | 0 | { |
3645 | 0 | *has_notes = true; |
3646 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_comment_start, |
3647 | 0 | " // note: %s", notes); |
3648 | 0 | } |
3649 | | |
3650 | 6.00M | obstack_free (&content, NULL); |
3651 | 6.00M | } |
3652 | | |
3653 | | /* Set NAME to a copy of INST's mnemonic with the "." suffix removed. */ |
3654 | | |
3655 | | static void |
3656 | | remove_dot_suffix (char *name, const aarch64_inst *inst) |
3657 | 121k | { |
3658 | 121k | char *ptr; |
3659 | 121k | size_t len; |
3660 | | |
3661 | 121k | ptr = strchr (inst->opcode->name, '.'); |
3662 | 121k | assert (ptr && inst->cond); |
3663 | 121k | len = ptr - inst->opcode->name; |
3664 | 121k | assert (len < 8); |
3665 | 121k | strncpy (name, inst->opcode->name, len); |
3666 | 121k | name[len] = '\0'; |
3667 | 121k | } |
3668 | | |
3669 | | /* Print the instruction mnemonic name. */ |
3670 | | |
3671 | | static void |
3672 | | print_mnemonic_name (const aarch64_inst *inst, struct disassemble_info *info) |
3673 | 6.00M | { |
3674 | 6.00M | if (inst->opcode->flags & F_COND) |
3675 | 60.7k | { |
3676 | | /* For instructions that are truly conditionally executed, e.g. b.cond, |
3677 | | prepare the full mnemonic name with the corresponding condition |
3678 | | suffix. */ |
3679 | 60.7k | char name[8]; |
3680 | | |
3681 | 60.7k | remove_dot_suffix (name, inst); |
3682 | 60.7k | (*info->fprintf_styled_func) (info->stream, dis_style_mnemonic, |
3683 | 60.7k | "%s.%s", name, inst->cond->names[0]); |
3684 | 60.7k | } |
3685 | 5.94M | else |
3686 | 5.94M | (*info->fprintf_styled_func) (info->stream, dis_style_mnemonic, |
3687 | 5.94M | "%s", inst->opcode->name); |
3688 | 6.00M | } |
3689 | | |
3690 | | /* Decide whether we need to print a comment after the operands of |
3691 | | instruction INST. */ |
3692 | | |
3693 | | static void |
3694 | | print_comment (const aarch64_inst *inst, struct disassemble_info *info) |
3695 | 6.00M | { |
3696 | 6.00M | if (inst->opcode->flags & F_COND) |
3697 | 60.7k | { |
3698 | 60.7k | char name[8]; |
3699 | 60.7k | unsigned int i, num_conds; |
3700 | | |
3701 | 60.7k | remove_dot_suffix (name, inst); |
3702 | 60.7k | num_conds = ARRAY_SIZE (inst->cond->names); |
3703 | 110k | for (i = 1; i < num_conds && inst->cond->names[i]; ++i) |
3704 | 49.5k | (*info->fprintf_styled_func) (info->stream, dis_style_comment_start, |
3705 | 49.5k | "%s %s.%s", |
3706 | 49.5k | i == 1 ? " //" : ",", |
3707 | 49.5k | name, inst->cond->names[i]); |
3708 | 60.7k | } |
3709 | 6.00M | } |
3710 | | |
3711 | | /* Build notes from verifiers into a string for printing. */ |
3712 | | |
3713 | | static void |
3714 | | print_verifier_notes (aarch64_operand_error *detail, |
3715 | | struct disassemble_info *info) |
3716 | 9.12k | { |
3717 | 9.12k | if (no_notes) |
3718 | 9.12k | return; |
3719 | | |
3720 | | /* The output of the verifier cannot be a fatal error, otherwise the assembly |
3721 | | would not have succeeded. We can safely ignore these. */ |
3722 | 0 | assert (detail->non_fatal); |
3723 | | |
3724 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_comment_start, |
3725 | 0 | " // note: "); |
3726 | 0 | switch (detail->kind) |
3727 | 0 | { |
3728 | 0 | case AARCH64_OPDE_A_SHOULD_FOLLOW_B: |
3729 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
3730 | 0 | _("this `%s' should have an immediately" |
3731 | 0 | " preceding `%s'"), |
3732 | 0 | detail->data[0].s, detail->data[1].s); |
3733 | 0 | break; |
3734 | | |
3735 | 0 | case AARCH64_OPDE_EXPECTED_A_AFTER_B: |
3736 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
3737 | 0 | _("expected `%s' after previous `%s'"), |
3738 | 0 | detail->data[0].s, detail->data[1].s); |
3739 | 0 | break; |
3740 | | |
3741 | 0 | default: |
3742 | 0 | assert (detail->error); |
3743 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
3744 | 0 | "%s", detail->error); |
3745 | 0 | if (detail->index >= 0) |
3746 | 0 | (*info->fprintf_styled_func) (info->stream, dis_style_text, |
3747 | 0 | " at operand %d", detail->index + 1); |
3748 | 0 | break; |
3749 | 0 | } |
3750 | 0 | } |
3751 | | |
3752 | | /* Print the instruction according to *INST. */ |
3753 | | |
3754 | | static void |
3755 | | print_aarch64_insn (bfd_vma pc, const aarch64_inst *inst, |
3756 | | const aarch64_insn code, |
3757 | | struct disassemble_info *info, |
3758 | | aarch64_operand_error *mismatch_details) |
3759 | 6.00M | { |
3760 | 6.00M | bool has_notes = false; |
3761 | | |
3762 | 6.00M | print_mnemonic_name (inst, info); |
3763 | 6.00M | print_operands (pc, inst->opcode, inst->operands, info, &has_notes); |
3764 | 6.00M | print_comment (inst, info); |
3765 | | |
3766 | | /* We've already printed a note, not enough space to print more so exit. |
3767 | | Usually notes shouldn't overlap so it shouldn't happen that we have a note |
3768 | | from a register and instruction at the same time. */ |
3769 | 6.00M | if (has_notes) |
3770 | 0 | return; |
3771 | | |
3772 | | /* Always run constraint verifiers, this is needed because constraints need to |
3773 | | maintain a global state regardless of whether the instruction has the flag |
3774 | | set or not. */ |
3775 | 6.00M | enum err_type result = verify_constraints (inst, code, pc, false, |
3776 | 6.00M | mismatch_details, &insn_sequence); |
3777 | 6.00M | switch (result) |
3778 | 6.00M | { |
3779 | 9.12k | case ERR_VFI: |
3780 | 9.12k | print_verifier_notes (mismatch_details, info); |
3781 | 9.12k | break; |
3782 | 0 | case ERR_UND: |
3783 | 0 | case ERR_UNP: |
3784 | 0 | case ERR_NYI: |
3785 | 5.99M | default: |
3786 | 5.99M | break; |
3787 | 6.00M | } |
3788 | 6.00M | } |
3789 | | |
3790 | | /* Entry-point of the instruction disassembler and printer. */ |
3791 | | |
3792 | | static void |
3793 | | print_insn_aarch64_word (bfd_vma pc, |
3794 | | uint32_t word, |
3795 | | struct disassemble_info *info, |
3796 | | aarch64_operand_error *errors) |
3797 | 15.0M | { |
3798 | 15.0M | static const char *err_msg[ERR_NR_ENTRIES+1] = |
3799 | 15.0M | { |
3800 | 15.0M | [ERR_OK] = "_", |
3801 | 15.0M | [ERR_UND] = "undefined", |
3802 | 15.0M | [ERR_UNP] = "unpredictable", |
3803 | 15.0M | [ERR_NYI] = "NYI" |
3804 | 15.0M | }; |
3805 | | |
3806 | 15.0M | enum err_type ret; |
3807 | 15.0M | aarch64_inst inst; |
3808 | | |
3809 | 15.0M | info->insn_info_valid = 1; |
3810 | 15.0M | info->branch_delay_insns = 0; |
3811 | 15.0M | info->data_size = 0; |
3812 | 15.0M | info->target = 0; |
3813 | 15.0M | info->target2 = 0; |
3814 | | |
3815 | 15.0M | if (info->flags & INSN_HAS_RELOC) |
3816 | | /* If the instruction has a reloc associated with it, then |
3817 | | the offset field in the instruction will actually be the |
3818 | | addend for the reloc. (If we are using REL type relocs). |
3819 | | In such cases, we can ignore the pc when computing |
3820 | | addresses, since the addend is not currently pc-relative. */ |
3821 | 1 | pc = 0; |
3822 | | |
3823 | 15.0M | ret = aarch64_decode_insn (word, &inst, no_aliases, errors); |
3824 | | |
3825 | 15.0M | if (((word >> 21) & 0x3ff) == 1) |
3826 | 91.9k | { |
3827 | | /* RESERVED for ALES. */ |
3828 | 91.9k | assert (ret != ERR_OK); |
3829 | 91.9k | ret = ERR_NYI; |
3830 | 91.9k | } |
3831 | | |
3832 | 15.0M | switch (ret) |
3833 | 15.0M | { |
3834 | 8.90M | case ERR_UND: |
3835 | 8.90M | case ERR_UNP: |
3836 | 8.99M | case ERR_NYI: |
3837 | | /* Handle undefined instructions. */ |
3838 | 8.99M | info->insn_type = dis_noninsn; |
3839 | 8.99M | (*info->fprintf_styled_func) (info->stream, |
3840 | 8.99M | dis_style_assembler_directive, |
3841 | 8.99M | ".inst\t"); |
3842 | 8.99M | (*info->fprintf_styled_func) (info->stream, dis_style_immediate, |
3843 | 8.99M | "0x%08x", word); |
3844 | 8.99M | (*info->fprintf_styled_func) (info->stream, dis_style_comment_start, |
3845 | 8.99M | " ; %s", err_msg[ret]); |
3846 | 8.99M | break; |
3847 | 6.00M | case ERR_OK: |
3848 | 6.00M | user_friendly_fixup (&inst); |
3849 | 6.00M | print_aarch64_insn (pc, &inst, word, info, errors); |
3850 | 6.00M | break; |
3851 | 0 | default: |
3852 | 0 | abort (); |
3853 | 15.0M | } |
3854 | 15.0M | } |
3855 | | |
3856 | | /* Disallow mapping symbols ($x, $d etc) from |
3857 | | being displayed in symbol relative addresses. */ |
3858 | | |
3859 | | bool |
3860 | | aarch64_symbol_is_valid (asymbol * sym, |
3861 | | struct disassemble_info * info ATTRIBUTE_UNUSED) |
3862 | 103k | { |
3863 | 103k | const char * name; |
3864 | | |
3865 | 103k | if (sym == NULL) |
3866 | 0 | return false; |
3867 | | |
3868 | 103k | name = bfd_asymbol_name (sym); |
3869 | | |
3870 | 103k | return name |
3871 | 103k | && (name[0] != '$' |
3872 | 103k | || (name[1] != 'x' && name[1] != 'd') |
3873 | 103k | || (name[2] != '\0' && name[2] != '.')); |
3874 | 103k | } |
3875 | | |
3876 | | /* Print data bytes on INFO->STREAM. */ |
3877 | | |
3878 | | static void |
3879 | | print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED, |
3880 | | uint32_t word, |
3881 | | struct disassemble_info *info, |
3882 | | aarch64_operand_error *errors ATTRIBUTE_UNUSED) |
3883 | 0 | { |
3884 | 0 | switch (info->bytes_per_chunk) |
3885 | 0 | { |
3886 | 0 | case 1: |
3887 | 0 | info->fprintf_styled_func (info->stream, dis_style_assembler_directive, |
3888 | 0 | ".byte\t"); |
3889 | 0 | info->fprintf_styled_func (info->stream, dis_style_immediate, |
3890 | 0 | "0x%02x", word); |
3891 | 0 | break; |
3892 | 0 | case 2: |
3893 | 0 | info->fprintf_styled_func (info->stream, dis_style_assembler_directive, |
3894 | 0 | ".short\t"); |
3895 | 0 | info->fprintf_styled_func (info->stream, dis_style_immediate, |
3896 | 0 | "0x%04x", word); |
3897 | 0 | break; |
3898 | 0 | case 4: |
3899 | 0 | info->fprintf_styled_func (info->stream, dis_style_assembler_directive, |
3900 | 0 | ".word\t"); |
3901 | 0 | info->fprintf_styled_func (info->stream, dis_style_immediate, |
3902 | 0 | "0x%08x", word); |
3903 | 0 | break; |
3904 | 0 | default: |
3905 | 0 | abort (); |
3906 | 0 | } |
3907 | 0 | } |
3908 | | |
3909 | | /* Try to infer the code or data type from a symbol. |
3910 | | Returns nonzero if *MAP_TYPE was set. */ |
3911 | | |
3912 | | static int |
3913 | | get_sym_code_type (struct disassemble_info *info, int n, |
3914 | | enum map_type *map_type) |
3915 | 3.21M | { |
3916 | 3.21M | asymbol * as; |
3917 | 3.21M | elf_symbol_type *es; |
3918 | 3.21M | unsigned int type; |
3919 | 3.21M | const char *name; |
3920 | | |
3921 | | /* If the symbol is in a different section, ignore it. */ |
3922 | 3.21M | if (info->section != NULL && info->section != info->symtab[n]->section) |
3923 | 877k | return false; |
3924 | | |
3925 | 2.34M | if (n >= info->symtab_size) |
3926 | 0 | return false; |
3927 | | |
3928 | 2.34M | as = info->symtab[n]; |
3929 | 2.34M | if (bfd_asymbol_flavour (as) != bfd_target_elf_flavour) |
3930 | 82.0k | return false; |
3931 | 2.25M | es = (elf_symbol_type *) as; |
3932 | | |
3933 | 2.25M | type = ELF_ST_TYPE (es->internal_elf_sym.st_info); |
3934 | | |
3935 | | /* If the symbol has function type then use that. */ |
3936 | 2.25M | if (type == STT_FUNC) |
3937 | 144k | { |
3938 | 144k | *map_type = MAP_INSN; |
3939 | 144k | return true; |
3940 | 144k | } |
3941 | | |
3942 | | /* Check for mapping symbols. */ |
3943 | 2.11M | name = bfd_asymbol_name(info->symtab[n]); |
3944 | 2.11M | if (name[0] == '$' |
3945 | 2.11M | && (name[1] == 'x' || name[1] == 'd') |
3946 | 2.11M | && (name[2] == '\0' || name[2] == '.')) |
3947 | 0 | { |
3948 | 0 | *map_type = (name[1] == 'x' ? MAP_INSN : MAP_DATA); |
3949 | 0 | return true; |
3950 | 0 | } |
3951 | | |
3952 | 2.11M | return false; |
3953 | 2.11M | } |
3954 | | |
3955 | | /* Set the feature bits in arch_variant in order to get the correct disassembly |
3956 | | for the chosen architecture variant. |
3957 | | |
3958 | | Currently we only restrict disassembly for Armv8-R and otherwise enable all |
3959 | | non-R-profile features. */ |
3960 | | static void |
3961 | | select_aarch64_variant (unsigned mach) |
3962 | 1 | { |
3963 | 1 | switch (mach) |
3964 | 1 | { |
3965 | 0 | case bfd_mach_aarch64_8R: |
3966 | 0 | arch_variant = AARCH64_ARCH_V8R; |
3967 | 0 | break; |
3968 | 1 | default: |
3969 | 1 | arch_variant = AARCH64_ANY & ~(AARCH64_FEATURE_V8R); |
3970 | 1 | } |
3971 | 1 | } |
3972 | | |
3973 | | /* Entry-point of the AArch64 disassembler. */ |
3974 | | |
3975 | | int |
3976 | | print_insn_aarch64 (bfd_vma pc, |
3977 | | struct disassemble_info *info) |
3978 | 15.0M | { |
3979 | 15.0M | bfd_byte buffer[INSNLEN]; |
3980 | 15.0M | int status; |
3981 | 15.0M | void (*printer) (bfd_vma, uint32_t, struct disassemble_info *, |
3982 | 15.0M | aarch64_operand_error *); |
3983 | 15.0M | bool found = false; |
3984 | 15.0M | unsigned int size = 4; |
3985 | 15.0M | unsigned long data; |
3986 | 15.0M | aarch64_operand_error errors; |
3987 | 15.0M | static bool set_features; |
3988 | | |
3989 | 15.0M | if (info->disassembler_options) |
3990 | 0 | { |
3991 | 0 | set_default_aarch64_dis_options (info); |
3992 | |
|
3993 | 0 | parse_aarch64_dis_options (info->disassembler_options); |
3994 | | |
3995 | | /* To avoid repeated parsing of these options, we remove them here. */ |
3996 | 0 | info->disassembler_options = NULL; |
3997 | 0 | } |
3998 | | |
3999 | 15.0M | if (!set_features) |
4000 | 1 | { |
4001 | 1 | select_aarch64_variant (info->mach); |
4002 | 1 | set_features = true; |
4003 | 1 | } |
4004 | | |
4005 | | /* Aarch64 instructions are always little-endian */ |
4006 | 15.0M | info->endian_code = BFD_ENDIAN_LITTLE; |
4007 | | |
4008 | | /* Default to DATA. A text section is required by the ABI to contain an |
4009 | | INSN mapping symbol at the start. A data section has no such |
4010 | | requirement, hence if no mapping symbol is found the section must |
4011 | | contain only data. This however isn't very useful if the user has |
4012 | | fully stripped the binaries. If this is the case use the section |
4013 | | attributes to determine the default. If we have no section default to |
4014 | | INSN as well, as we may be disassembling some raw bytes on a baremetal |
4015 | | HEX file or similar. */ |
4016 | 15.0M | enum map_type type = MAP_DATA; |
4017 | 15.0M | if ((info->section && info->section->flags & SEC_CODE) || !info->section) |
4018 | 6.34M | type = MAP_INSN; |
4019 | | |
4020 | | /* First check the full symtab for a mapping symbol, even if there |
4021 | | are no usable non-mapping symbols for this address. */ |
4022 | 15.0M | if (info->symtab_size != 0 |
4023 | 15.0M | && bfd_asymbol_flavour (*info->symtab) == bfd_target_elf_flavour) |
4024 | 202k | { |
4025 | 202k | int last_sym = -1; |
4026 | 202k | bfd_vma addr, section_vma = 0; |
4027 | 202k | bool can_use_search_opt_p; |
4028 | 202k | int n; |
4029 | | |
4030 | 202k | if (pc <= last_mapping_addr) |
4031 | 1 | last_mapping_sym = -1; |
4032 | | |
4033 | | /* Start scanning at the start of the function, or wherever |
4034 | | we finished last time. */ |
4035 | 202k | n = info->symtab_pos + 1; |
4036 | | |
4037 | | /* If the last stop offset is different from the current one it means we |
4038 | | are disassembling a different glob of bytes. As such the optimization |
4039 | | would not be safe and we should start over. */ |
4040 | 202k | can_use_search_opt_p = last_mapping_sym >= 0 |
4041 | 202k | && info->stop_offset == last_stop_offset; |
4042 | | |
4043 | 202k | if (n >= last_mapping_sym && can_use_search_opt_p) |
4044 | 142k | n = last_mapping_sym; |
4045 | | |
4046 | | /* Look down while we haven't passed the location being disassembled. |
4047 | | The reason for this is that there's no defined order between a symbol |
4048 | | and an mapping symbol that may be at the same address. We may have to |
4049 | | look at least one position ahead. */ |
4050 | 1.22M | for (; n < info->symtab_size; n++) |
4051 | 1.22M | { |
4052 | 1.22M | addr = bfd_asymbol_value (info->symtab[n]); |
4053 | 1.22M | if (addr > pc) |
4054 | 202k | break; |
4055 | 1.02M | if (get_sym_code_type (info, n, &type)) |
4056 | 142k | { |
4057 | 142k | last_sym = n; |
4058 | 142k | found = true; |
4059 | 142k | } |
4060 | 1.02M | } |
4061 | | |
4062 | 202k | if (!found) |
4063 | 59.8k | { |
4064 | 59.8k | n = info->symtab_pos; |
4065 | 59.8k | if (n >= last_mapping_sym && can_use_search_opt_p) |
4066 | 0 | n = last_mapping_sym; |
4067 | | |
4068 | | /* No mapping symbol found at this address. Look backwards |
4069 | | for a preceeding one, but don't go pass the section start |
4070 | | otherwise a data section with no mapping symbol can pick up |
4071 | | a text mapping symbol of a preceeding section. The documentation |
4072 | | says section can be NULL, in which case we will seek up all the |
4073 | | way to the top. */ |
4074 | 59.8k | if (info->section) |
4075 | 59.8k | section_vma = info->section->vma; |
4076 | | |
4077 | 2.25M | for (; n >= 0; n--) |
4078 | 2.22M | { |
4079 | 2.22M | addr = bfd_asymbol_value (info->symtab[n]); |
4080 | 2.22M | if (addr < section_vma) |
4081 | 30.5k | break; |
4082 | | |
4083 | 2.19M | if (get_sym_code_type (info, n, &type)) |
4084 | 1.39k | { |
4085 | 1.39k | last_sym = n; |
4086 | 1.39k | found = true; |
4087 | 1.39k | break; |
4088 | 1.39k | } |
4089 | 2.19M | } |
4090 | 59.8k | } |
4091 | | |
4092 | 202k | last_mapping_sym = last_sym; |
4093 | 202k | last_type = type; |
4094 | 202k | last_stop_offset = info->stop_offset; |
4095 | | |
4096 | | /* Look a little bit ahead to see if we should print out |
4097 | | less than four bytes of data. If there's a symbol, |
4098 | | mapping or otherwise, after two bytes then don't |
4099 | | print more. */ |
4100 | 202k | if (last_type == MAP_DATA) |
4101 | 57.4k | { |
4102 | 57.4k | size = 4 - (pc & 3); |
4103 | 50.7M | for (n = last_sym + 1; n < info->symtab_size; n++) |
4104 | 50.7M | { |
4105 | 50.7M | addr = bfd_asymbol_value (info->symtab[n]); |
4106 | 50.7M | if (addr > pc) |
4107 | 57.4k | { |
4108 | 57.4k | if (addr - pc < size) |
4109 | 1 | size = addr - pc; |
4110 | 57.4k | break; |
4111 | 57.4k | } |
4112 | 50.7M | } |
4113 | | /* If the next symbol is after three bytes, we need to |
4114 | | print only part of the data, so that we can use either |
4115 | | .byte or .short. */ |
4116 | 57.4k | if (size == 3) |
4117 | 2 | size = (pc & 1) ? 1 : 2; |
4118 | 57.4k | } |
4119 | 202k | } |
4120 | 14.8M | else |
4121 | 14.8M | last_type = type; |
4122 | | |
4123 | | /* PR 10263: Disassemble data if requested to do so by the user. */ |
4124 | 15.0M | if (last_type == MAP_DATA && ((info->flags & DISASSEMBLE_DATA) == 0)) |
4125 | 0 | { |
4126 | | /* size was set above. */ |
4127 | 0 | info->bytes_per_chunk = size; |
4128 | 0 | info->display_endian = info->endian; |
4129 | 0 | printer = print_insn_data; |
4130 | 0 | } |
4131 | 15.0M | else |
4132 | 15.0M | { |
4133 | 15.0M | info->bytes_per_chunk = size = INSNLEN; |
4134 | 15.0M | info->display_endian = info->endian_code; |
4135 | 15.0M | printer = print_insn_aarch64_word; |
4136 | 15.0M | } |
4137 | | |
4138 | 15.0M | status = (*info->read_memory_func) (pc, buffer, size, info); |
4139 | 15.0M | if (status != 0) |
4140 | 5.05k | { |
4141 | 5.05k | (*info->memory_error_func) (status, pc, info); |
4142 | 5.05k | return -1; |
4143 | 5.05k | } |
4144 | | |
4145 | 15.0M | data = bfd_get_bits (buffer, size * 8, |
4146 | 15.0M | info->display_endian == BFD_ENDIAN_BIG); |
4147 | | |
4148 | 15.0M | (*printer) (pc, data, info, &errors); |
4149 | | |
4150 | 15.0M | return size; |
4151 | 15.0M | } |
4152 | | |
4153 | | void |
4154 | | print_aarch64_disassembler_options (FILE *stream) |
4155 | 0 | { |
4156 | 0 | fprintf (stream, _("\n\ |
4157 | 0 | The following AARCH64 specific disassembler options are supported for use\n\ |
4158 | 0 | with the -M switch (multiple options should be separated by commas):\n")); |
4159 | |
|
4160 | 0 | fprintf (stream, _("\n\ |
4161 | 0 | no-aliases Don't print instruction aliases.\n")); |
4162 | |
|
4163 | 0 | fprintf (stream, _("\n\ |
4164 | 0 | aliases Do print instruction aliases.\n")); |
4165 | |
|
4166 | 0 | fprintf (stream, _("\n\ |
4167 | 0 | no-notes Don't print instruction notes.\n")); |
4168 | |
|
4169 | 0 | fprintf (stream, _("\n\ |
4170 | 0 | notes Do print instruction notes.\n")); |
4171 | |
|
4172 | | #ifdef DEBUG_AARCH64 |
4173 | | fprintf (stream, _("\n\ |
4174 | | debug_dump Temp switch for debug trace.\n")); |
4175 | | #endif /* DEBUG_AARCH64 */ |
4176 | |
|
4177 | 0 | fprintf (stream, _("\n")); |
4178 | 0 | } |