1 /* aarch64-dis.c -- AArch64 disassembler.
2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
3 Contributed by ARM Ltd.
5 This file is part of the GNU opcodes library.
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)
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.
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/>. */
23 #include "disassemble.h"
24 #include "libiberty.h"
26 #include "aarch64-dis.h"
28 #include "safe-ctype.h"
31 #define obstack_chunk_alloc xmalloc
32 #define obstack_chunk_free free
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 #define STYLE_MARKER_CHAR '\002'
40 /* Cached mapping symbol state. */
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;
54 static int no_aliases
= 0; /* If set disassemble as most general inst. */
55 \fstatic int no_notes
= 1; /* If set do not print disassemble notes in the
56 output as comments. */
58 /* Currently active instruction sequence. */
59 static aarch64_instr_sequence insn_sequence
;
62 set_default_aarch64_dis_options (struct disassemble_info
*info ATTRIBUTE_UNUSED
)
67 parse_aarch64_dis_option (const char *option
, unsigned int len ATTRIBUTE_UNUSED
)
69 /* Try to match options that are simple flags */
70 if (startswith (option
, "no-aliases"))
76 if (startswith (option
, "aliases"))
82 if (startswith (option
, "no-notes"))
88 if (startswith (option
, "notes"))
95 if (startswith (option
, "debug_dump"))
100 #endif /* DEBUG_AARCH64 */
102 /* Invalid option. */
103 opcodes_error_handler (_("unrecognised disassembler option: %s"), option
);
107 parse_aarch64_dis_options (const char *options
)
109 const char *option_end
;
114 while (*options
!= '\0')
116 /* Skip empty options. */
123 /* We know that *options is neither NUL or a comma. */
124 option_end
= options
+ 1;
125 while (*option_end
!= ',' && *option_end
!= '\0')
128 parse_aarch64_dis_option (options
, option_end
- options
);
130 /* Go on to the next one. If option_end points to a comma, it
131 will be skipped above. */
132 options
= option_end
;
136 /* Functions doing the instruction disassembling. */
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.
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. */
149 extract_fields (aarch64_insn code
, aarch64_insn mask
, ...)
152 const aarch64_field
*field
;
153 enum aarch64_field_kind kind
;
157 num
= va_arg (va
, uint32_t);
159 aarch64_insn value
= 0x0;
162 kind
= va_arg (va
, enum aarch64_field_kind
);
163 field
= &fields
[kind
];
164 value
<<= field
->width
;
165 value
|= extract_field (kind
, code
, mask
);
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. */
175 extract_all_fields_after (const aarch64_operand
*self
, unsigned int start
,
180 enum aarch64_field_kind kind
;
184 i
< ARRAY_SIZE (self
->fields
) && self
->fields
[i
] != FLD_NIL
; ++i
)
186 kind
= self
->fields
[i
];
187 value
<<= fields
[kind
].width
;
188 value
|= extract_field (kind
, code
, 0);
193 /* Extract the value of all fields in SELF->fields from instruction CODE.
194 The least significant bit comes from the final field. */
197 extract_all_fields (const aarch64_operand
*self
, aarch64_insn code
)
199 return extract_all_fields_after (self
, 0, code
);
202 /* Sign-extend bit I of VALUE. */
203 static inline uint64_t
204 sign_extend (aarch64_insn value
, unsigned i
)
210 sign
= (uint64_t) 1 << i
;
211 return ((ret
& (sign
+ sign
- 1)) ^ sign
) - sign
;
214 /* N.B. the following inline helpfer functions create a dependency on the
215 order of operand qualifier enumerators. */
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
)
221 enum aarch64_opnd_qualifier qualifier
= AARCH64_OPND_QLF_W
+ value
;
223 && aarch64_get_qualifier_standard_value (qualifier
) == value
)
225 return AARCH64_OPND_QLF_ERR
;
228 /* Given VALUE, return qualifier for a vector register. This does not support
229 decoding instructions that accept the 2H vector type. */
231 static inline enum aarch64_opnd_qualifier
232 get_vreg_qualifier_from_value (aarch64_insn value
)
234 enum aarch64_opnd_qualifier qualifier
= AARCH64_OPND_QLF_V_8B
+ value
;
236 /* Instructions using vector type 2H should not call this function. Skip over
238 if (qualifier
>= AARCH64_OPND_QLF_V_2H
)
242 && aarch64_get_qualifier_standard_value (qualifier
) == value
)
244 return AARCH64_OPND_QLF_ERR
;
247 /* Given VALUE, return qualifier for an FP or AdvSIMD scalar register. */
248 static inline enum aarch64_opnd_qualifier
249 get_sreg_qualifier_from_value (aarch64_insn value
)
251 enum aarch64_opnd_qualifier qualifier
= AARCH64_OPND_QLF_S_B
+ value
;
254 && aarch64_get_qualifier_standard_value (qualifier
) == value
)
256 return AARCH64_OPND_QLF_ERR
;
259 /* Given the instruction in *INST which is probably half way through the
260 decoding and our caller wants to know the expected qualifier for operand
261 I. Return such a qualifier if we can establish it; otherwise return
262 AARCH64_OPND_QLF_NIL. */
264 static aarch64_opnd_qualifier_t
265 get_expected_qualifier (const aarch64_inst
*inst
, int i
)
267 aarch64_opnd_qualifier_seq_t qualifiers
;
268 /* Should not be called if the qualifier is known. */
269 if (inst
->operands
[i
].qualifier
== AARCH64_OPND_QLF_NIL
)
272 if (aarch64_find_best_match (inst
, inst
->opcode
->qualifiers_list
,
273 i
, qualifiers
, &invalid_count
))
274 return qualifiers
[i
];
276 return AARCH64_OPND_QLF_NIL
;
279 return AARCH64_OPND_QLF_ERR
;
282 /* Operand extractors. */
285 aarch64_ext_none (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
286 aarch64_opnd_info
*info ATTRIBUTE_UNUSED
,
287 const aarch64_insn code ATTRIBUTE_UNUSED
,
288 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
289 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
295 aarch64_ext_regno (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
296 const aarch64_insn code
,
297 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
298 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
300 info
->reg
.regno
= (extract_field (self
->fields
[0], code
, 0)
301 + get_operand_specific_data (self
));
306 aarch64_ext_regno_pair (const aarch64_operand
*self ATTRIBUTE_UNUSED
, aarch64_opnd_info
*info
,
307 const aarch64_insn code ATTRIBUTE_UNUSED
,
308 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
309 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
311 assert (info
->idx
== 1
316 unsigned prev_regno
= inst
->operands
[info
->idx
- 1].reg
.regno
;
317 info
->reg
.regno
= (prev_regno
== 0x1f) ? 0x1f
322 /* e.g. IC <ic_op>{, <Xt>}. */
324 aarch64_ext_regrt_sysins (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
325 const aarch64_insn code
,
326 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
327 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
329 info
->reg
.regno
= extract_field (self
->fields
[0], code
, 0);
330 assert (info
->idx
== 1
331 && (aarch64_get_operand_class (inst
->operands
[0].type
)
332 == AARCH64_OPND_CLASS_SYSTEM
));
333 /* This will make the constraint checking happy and more importantly will
334 help the disassembler determine whether this operand is optional or
336 info
->present
= aarch64_sys_ins_reg_has_xt (inst
->operands
[0].sysins_op
);
341 /* e.g. SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>]. */
343 aarch64_ext_reglane (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
344 const aarch64_insn code
,
345 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
346 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
349 info
->reglane
.regno
= extract_field (self
->fields
[0], code
,
352 /* Index and/or type. */
353 if (inst
->opcode
->iclass
== asisdone
354 || inst
->opcode
->iclass
== asimdins
)
356 if (info
->type
== AARCH64_OPND_En
357 && inst
->opcode
->operands
[0] == AARCH64_OPND_Ed
)
360 /* index2 for e.g. INS <Vd>.<Ts>[<index1>], <Vn>.<Ts>[<index2>]. */
361 assert (info
->idx
== 1); /* Vn */
362 aarch64_insn value
= extract_field (FLD_imm4_11
, code
, 0);
363 /* Depend on AARCH64_OPND_Ed to determine the qualifier. */
364 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
365 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
367 shift
= get_logsz (aarch64_get_qualifier_esize (info
->qualifier
));
368 info
->reglane
.index
= value
>> shift
;
372 /* index and type for e.g. DUP <V><d>, <Vn>.<T>[<index>].
380 aarch64_insn value
= extract_field (FLD_imm5
, code
, 0);
381 while (++pos
<= 3 && (value
& 0x1) == 0)
385 info
->qualifier
= get_sreg_qualifier_from_value (pos
);
386 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
388 info
->reglane
.index
= (unsigned) (value
>> 1);
391 else if (inst
->opcode
->iclass
== dotproduct
)
393 /* Need information in other operand(s) to help decoding. */
394 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
395 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
397 switch (info
->qualifier
)
399 case AARCH64_OPND_QLF_S_4B
:
400 case AARCH64_OPND_QLF_S_2H
:
402 info
->reglane
.index
= extract_fields (code
, 0, 2, FLD_H
, FLD_L
);
403 info
->reglane
.regno
&= 0x1f;
405 case AARCH64_OPND_QLF_S_2B
:
407 info
->reglane
.index
= extract_fields (code
, 0, 3, FLD_H
, FLD_L
,
409 info
->reglane
.regno
&= 0xf;
415 else if (inst
->opcode
->iclass
== cryptosm3
)
417 /* index for e.g. SM3TT2A <Vd>.4S, <Vn>.4S, <Vm>S[<imm2>]. */
418 info
->reglane
.index
= extract_field (FLD_SM3_imm2
, code
, 0);
422 /* Index only for e.g. SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>]
423 or SQDMLAL <Va><d>, <Vb><n>, <Vm>.<Ts>[<index>]. */
425 /* Need information in other operand(s) to help decoding. */
426 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
427 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
429 switch (info
->qualifier
)
431 case AARCH64_OPND_QLF_S_B
:
433 info
->reglane
.index
= extract_fields (code
, 0, 2, FLD_H
,
435 info
->reglane
.regno
&= 0x7;
438 case AARCH64_OPND_QLF_S_H
:
439 case AARCH64_OPND_QLF_S_2B
:
440 if (info
->type
== AARCH64_OPND_Em16
)
443 info
->reglane
.index
= extract_fields (code
, 0, 3, FLD_H
, FLD_L
,
445 info
->reglane
.regno
&= 0xf;
450 info
->reglane
.index
= extract_fields (code
, 0, 2, FLD_H
, FLD_L
);
453 case AARCH64_OPND_QLF_S_S
:
454 case AARCH64_OPND_QLF_S_4B
:
456 info
->reglane
.index
= extract_fields (code
, 0, 2, FLD_H
, FLD_L
);
458 case AARCH64_OPND_QLF_S_D
:
460 info
->reglane
.index
= extract_field (FLD_H
, code
, 0);
466 if (inst
->opcode
->op
== OP_FCMLA_ELEM
467 && info
->qualifier
!= AARCH64_OPND_QLF_S_H
)
469 /* Complex operand takes two elements. */
470 if (info
->reglane
.index
& 1)
472 info
->reglane
.index
/= 2;
480 aarch64_ext_reglist (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
481 const aarch64_insn code
,
482 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
483 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
486 info
->reglist
.first_regno
= extract_field (self
->fields
[0], code
, 0);
488 info
->reglist
.num_regs
= extract_field (FLD_len
, code
, 0) + 1;
489 info
->reglist
.stride
= 1;
493 /* Decode Rt and opcode fields of Vt in AdvSIMD load/store instructions. */
495 aarch64_ext_ldst_reglist (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
496 aarch64_opnd_info
*info
, const aarch64_insn code
,
497 const aarch64_inst
*inst
,
498 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
501 /* Number of elements in each structure to be loaded/stored. */
502 unsigned expected_num
= get_opcode_dependent_value (inst
->opcode
);
506 unsigned is_reserved
;
508 unsigned num_elements
;
524 info
->reglist
.first_regno
= extract_field (FLD_Rt
, code
, 0);
526 value
= extract_field (FLD_opcode
, code
, 0);
527 /* PR 21595: Check for a bogus value. */
528 if (value
>= ARRAY_SIZE (data
))
530 if (expected_num
!= data
[value
].num_elements
|| data
[value
].is_reserved
)
532 info
->reglist
.num_regs
= data
[value
].num_regs
;
533 info
->reglist
.stride
= 1;
538 /* Decode Rt and S fields of Vt in AdvSIMD load single structure to all
539 lanes instructions. */
541 aarch64_ext_ldst_reglist_r (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
542 aarch64_opnd_info
*info
, const aarch64_insn code
,
543 const aarch64_inst
*inst
,
544 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
549 info
->reglist
.first_regno
= extract_field (FLD_Rt
, code
, 0);
551 value
= extract_field (FLD_S
, code
, 0);
553 /* Number of registers is equal to the number of elements in
554 each structure to be loaded/stored. */
555 info
->reglist
.num_regs
= get_opcode_dependent_value (inst
->opcode
);
556 assert (info
->reglist
.num_regs
>= 1 && info
->reglist
.num_regs
<= 4);
558 /* Except when it is LD1R. */
559 if (info
->reglist
.num_regs
== 1 && value
== (aarch64_insn
) 1)
560 info
->reglist
.num_regs
= 2;
562 info
->reglist
.stride
= 1;
566 /* Decode AdvSIMD vector register list for AdvSIMD lut instructions.
567 The number of of registers in the list is determined by the opcode
570 aarch64_ext_lut_reglist (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
571 const aarch64_insn code
,
572 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
573 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
575 info
->reglist
.first_regno
= extract_field (self
->fields
[0], code
, 0);
576 info
->reglist
.num_regs
= get_opcode_dependent_value (inst
->opcode
);
577 info
->reglist
.stride
= 1;
581 /* Decode Q, opcode<2:1>, S, size and Rt fields of Vt in AdvSIMD
582 load/store single element instructions. */
584 aarch64_ext_ldst_elemlist (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
585 aarch64_opnd_info
*info
, const aarch64_insn code
,
586 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
587 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
589 aarch64_field field
= {0, 0};
590 aarch64_insn QSsize
; /* fields Q:S:size. */
591 aarch64_insn opcodeh2
; /* opcode<2:1> */
594 info
->reglist
.first_regno
= extract_field (FLD_Rt
, code
, 0);
596 /* Decode the index, opcode<2:1> and size. */
597 gen_sub_field (FLD_asisdlso_opcode
, 1, 2, &field
);
598 opcodeh2
= extract_field_2 (&field
, code
, 0);
599 QSsize
= extract_fields (code
, 0, 3, FLD_Q
, FLD_S
, FLD_vldst_size
);
603 info
->qualifier
= AARCH64_OPND_QLF_S_B
;
604 /* Index encoded in "Q:S:size". */
605 info
->reglist
.index
= QSsize
;
611 info
->qualifier
= AARCH64_OPND_QLF_S_H
;
612 /* Index encoded in "Q:S:size<1>". */
613 info
->reglist
.index
= QSsize
>> 1;
616 if ((QSsize
>> 1) & 0x1)
619 if ((QSsize
& 0x1) == 0)
621 info
->qualifier
= AARCH64_OPND_QLF_S_S
;
622 /* Index encoded in "Q:S". */
623 info
->reglist
.index
= QSsize
>> 2;
627 if (extract_field (FLD_S
, code
, 0))
630 info
->qualifier
= AARCH64_OPND_QLF_S_D
;
631 /* Index encoded in "Q". */
632 info
->reglist
.index
= QSsize
>> 3;
639 info
->reglist
.has_index
= 1;
640 info
->reglist
.num_regs
= 0;
641 info
->reglist
.stride
= 1;
642 /* Number of registers is equal to the number of elements in
643 each structure to be loaded/stored. */
644 info
->reglist
.num_regs
= get_opcode_dependent_value (inst
->opcode
);
645 assert (info
->reglist
.num_regs
>= 1 && info
->reglist
.num_regs
<= 4);
650 /* Decode fields immh:immb and/or Q for e.g.
651 SSHR <Vd>.<T>, <Vn>.<T>, #<shift>
652 or SSHR <V><d>, <V><n>, #<shift>. */
655 aarch64_ext_advsimd_imm_shift (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
656 aarch64_opnd_info
*info
, const aarch64_insn code
,
657 const aarch64_inst
*inst
,
658 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
661 aarch64_insn Q
, imm
, immh
;
662 enum aarch64_insn_class iclass
= inst
->opcode
->iclass
;
664 immh
= extract_field (FLD_immh
, code
, 0);
667 imm
= extract_fields (code
, 0, 2, FLD_immh
, FLD_immb
);
669 /* Get highest set bit in immh. */
670 while (--pos
>= 0 && (immh
& 0x8) == 0)
673 assert ((iclass
== asimdshf
|| iclass
== asisdshf
)
674 && (info
->type
== AARCH64_OPND_IMM_VLSR
675 || info
->type
== AARCH64_OPND_IMM_VLSL
));
677 if (iclass
== asimdshf
)
679 Q
= extract_field (FLD_Q
, code
, 0);
681 0000 x SEE AdvSIMD modified immediate
691 get_vreg_qualifier_from_value ((pos
<< 1) | (int) Q
);
692 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
697 info
->qualifier
= get_sreg_qualifier_from_value (pos
);
698 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
702 if (info
->type
== AARCH64_OPND_IMM_VLSR
)
704 0000 SEE AdvSIMD modified immediate
705 0001 (16-UInt(immh:immb))
706 001x (32-UInt(immh:immb))
707 01xx (64-UInt(immh:immb))
708 1xxx (128-UInt(immh:immb)) */
709 info
->imm
.value
= (16 << pos
) - imm
;
713 0000 SEE AdvSIMD modified immediate
714 0001 (UInt(immh:immb)-8)
715 001x (UInt(immh:immb)-16)
716 01xx (UInt(immh:immb)-32)
717 1xxx (UInt(immh:immb)-64) */
718 info
->imm
.value
= imm
- (8 << pos
);
723 /* Decode shift immediate for e.g. sshr (imm). */
725 aarch64_ext_shll_imm (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
726 aarch64_opnd_info
*info
, const aarch64_insn code
,
727 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
728 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
732 val
= extract_field (FLD_size
, code
, 0);
735 case 0: imm
= 8; break;
736 case 1: imm
= 16; break;
737 case 2: imm
= 32; break;
738 default: return false;
740 info
->imm
.value
= imm
;
744 /* Decode imm for e.g. BFM <Wd>, <Wn>, #<immr>, #<imms>.
745 value in the field(s) will be extracted as unsigned immediate value. */
747 aarch64_ext_imm (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
748 const aarch64_insn code
,
749 const aarch64_inst
*inst
,
750 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
754 imm
= extract_all_fields (self
, code
);
756 if (operand_need_sign_extension (self
))
757 imm
= sign_extend (imm
, get_operand_fields_width (self
) - 1);
759 if (operand_need_shift_by_two (self
))
761 else if (operand_need_shift_by_three (self
))
763 else if (operand_need_shift_by_four (self
))
766 if (info
->type
== AARCH64_OPND_ADDR_ADRP
)
769 if (inst
->operands
[0].type
== AARCH64_OPND_PSTATEFIELD
770 && inst
->operands
[0].sysreg
.flags
& F_IMM_IN_CRM
)
771 imm
&= PSTATE_DECODE_CRM_IMM (inst
->operands
[0].sysreg
.flags
);
773 info
->imm
.value
= imm
;
777 /* Decode imm and its shifter for e.g. MOVZ <Wd>, #<imm16>{, LSL #<shift>}. */
779 aarch64_ext_imm_half (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
780 const aarch64_insn code
,
781 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
782 aarch64_operand_error
*errors
)
784 aarch64_ext_imm (self
, info
, code
, inst
, errors
);
785 info
->shifter
.kind
= AARCH64_MOD_LSL
;
786 info
->shifter
.amount
= extract_field (FLD_hw
, code
, 0) << 4;
790 /* Decode cmode and "a:b:c:d:e:f:g:h" for e.g.
791 MOVI <Vd>.<T>, #<imm8> {, LSL #<amount>}. */
793 aarch64_ext_advsimd_imm_modified (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
794 aarch64_opnd_info
*info
,
795 const aarch64_insn code
,
796 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
797 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
800 enum aarch64_opnd_qualifier opnd0_qualifier
= inst
->operands
[0].qualifier
;
801 aarch64_field field
= {0, 0};
803 assert (info
->idx
== 1);
805 if (info
->type
== AARCH64_OPND_SIMD_FPIMM
)
808 /* a:b:c:d:e:f:g:h */
809 imm
= extract_fields (code
, 0, 2, FLD_abc
, FLD_defgh
);
810 if (!info
->imm
.is_fp
&& aarch64_get_qualifier_esize (opnd0_qualifier
) == 8)
812 /* Either MOVI <Dd>, #<imm>
813 or MOVI <Vd>.2D, #<imm>.
814 <imm> is a 64-bit immediate
815 'aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh',
816 encoded in "a:b:c:d:e:f:g:h". */
818 unsigned abcdefgh
= imm
;
819 for (imm
= 0ull, i
= 0; i
< 8; i
++)
820 if (((abcdefgh
>> i
) & 0x1) != 0)
821 imm
|= 0xffull
<< (8 * i
);
823 info
->imm
.value
= imm
;
826 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
827 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
829 switch (info
->qualifier
)
831 case AARCH64_OPND_QLF_NIL
:
833 info
->shifter
.kind
= AARCH64_MOD_NONE
;
835 case AARCH64_OPND_QLF_LSL
:
837 info
->shifter
.kind
= AARCH64_MOD_LSL
;
838 switch (aarch64_get_qualifier_esize (opnd0_qualifier
))
840 case 4: gen_sub_field (FLD_cmode
, 1, 2, &field
); break; /* per word */
841 case 2: gen_sub_field (FLD_cmode
, 1, 1, &field
); break; /* per half */
842 case 1: gen_sub_field (FLD_cmode
, 1, 0, &field
); break; /* per byte */
843 default: return false;
845 /* 00: 0; 01: 8; 10:16; 11:24. */
846 info
->shifter
.amount
= extract_field_2 (&field
, code
, 0) << 3;
848 case AARCH64_OPND_QLF_MSL
:
850 info
->shifter
.kind
= AARCH64_MOD_MSL
;
851 gen_sub_field (FLD_cmode
, 0, 1, &field
); /* per word */
852 info
->shifter
.amount
= extract_field_2 (&field
, code
, 0) ? 16 : 8;
861 /* Decode an 8-bit floating-point immediate. */
863 aarch64_ext_fpimm (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
864 const aarch64_insn code
,
865 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
866 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
868 info
->imm
.value
= extract_all_fields (self
, code
);
873 /* Decode a 1-bit rotate immediate (#90 or #270). */
875 aarch64_ext_imm_rotate1 (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
876 const aarch64_insn code
,
877 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
878 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
880 uint64_t rot
= extract_field (self
->fields
[0], code
, 0);
882 info
->imm
.value
= rot
* 180 + 90;
886 /* Decode a 2-bit rotate immediate (#0, #90, #180 or #270). */
888 aarch64_ext_imm_rotate2 (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
889 const aarch64_insn code
,
890 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
891 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
893 uint64_t rot
= extract_field (self
->fields
[0], code
, 0);
895 info
->imm
.value
= rot
* 90;
899 /* Decode scale for e.g. SCVTF <Dd>, <Wn>, #<fbits>. */
901 aarch64_ext_fbits (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
902 aarch64_opnd_info
*info
, const aarch64_insn code
,
903 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
904 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
906 info
->imm
.value
= 64- extract_field (FLD_scale
, code
, 0);
910 /* Decode arithmetic immediate for e.g.
911 SUBS <Wd>, <Wn|WSP>, #<imm> {, <shift>}. */
913 aarch64_ext_aimm (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
914 aarch64_opnd_info
*info
, const aarch64_insn code
,
915 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
916 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
920 info
->shifter
.kind
= AARCH64_MOD_LSL
;
922 value
= extract_field (FLD_shift
, code
, 0);
925 info
->shifter
.amount
= value
? 12 : 0;
926 /* imm12 (unsigned) */
927 info
->imm
.value
= extract_field (FLD_imm12
, code
, 0);
932 /* Return true if VALUE is a valid logical immediate encoding, storing the
933 decoded value in *RESULT if so. ESIZE is the number of bytes in the
934 decoded immediate. */
936 decode_limm (uint32_t esize
, aarch64_insn value
, int64_t *result
)
942 /* value is N:immr:imms. */
944 R
= (value
>> 6) & 0x3f;
945 N
= (value
>> 12) & 0x1;
947 /* The immediate value is S+1 bits to 1, left rotated by SIMDsize - R
948 (in other words, right rotated by R), then replicated. */
952 mask
= 0xffffffffffffffffull
;
958 case 0x00 ... 0x1f: /* 0xxxxx */ simd_size
= 32; break;
959 case 0x20 ... 0x2f: /* 10xxxx */ simd_size
= 16; S
&= 0xf; break;
960 case 0x30 ... 0x37: /* 110xxx */ simd_size
= 8; S
&= 0x7; break;
961 case 0x38 ... 0x3b: /* 1110xx */ simd_size
= 4; S
&= 0x3; break;
962 case 0x3c ... 0x3d: /* 11110x */ simd_size
= 2; S
&= 0x1; break;
963 default: return false;
965 mask
= (1ull << simd_size
) - 1;
966 /* Top bits are IGNORED. */
970 if (simd_size
> esize
* 8)
973 /* NOTE: if S = simd_size - 1 we get 0xf..f which is rejected. */
974 if (S
== simd_size
- 1)
976 /* S+1 consecutive bits to 1. */
977 /* NOTE: S can't be 63 due to detection above. */
978 imm
= (1ull << (S
+ 1)) - 1;
979 /* Rotate to the left by simd_size - R. */
981 imm
= ((imm
<< (simd_size
- R
)) & mask
) | (imm
>> R
);
982 /* Replicate the value according to SIMD size. */
985 case 2: imm
= (imm
<< 2) | imm
;
987 case 4: imm
= (imm
<< 4) | imm
;
989 case 8: imm
= (imm
<< 8) | imm
;
991 case 16: imm
= (imm
<< 16) | imm
;
993 case 32: imm
= (imm
<< 32) | imm
;
999 *result
= imm
& ~((uint64_t) -1 << (esize
* 4) << (esize
* 4));
1004 /* Decode a logical immediate for e.g. ORR <Wd|WSP>, <Wn>, #<imm>. */
1006 aarch64_ext_limm (const aarch64_operand
*self
,
1007 aarch64_opnd_info
*info
, const aarch64_insn code
,
1008 const aarch64_inst
*inst
,
1009 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1014 value
= extract_fields (code
, 0, 3, self
->fields
[0], self
->fields
[1],
1016 esize
= aarch64_get_qualifier_esize (inst
->operands
[0].qualifier
);
1017 return decode_limm (esize
, value
, &info
->imm
.value
);
1020 /* Decode a logical immediate for the BIC alias of AND (etc.). */
1022 aarch64_ext_inv_limm (const aarch64_operand
*self
,
1023 aarch64_opnd_info
*info
, const aarch64_insn code
,
1024 const aarch64_inst
*inst
,
1025 aarch64_operand_error
*errors
)
1027 if (!aarch64_ext_limm (self
, info
, code
, inst
, errors
))
1029 info
->imm
.value
= ~info
->imm
.value
;
1033 /* Decode Ft for e.g. STR <Qt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]
1034 or LDP <Qt1>, <Qt2>, [<Xn|SP>], #<imm>. */
1036 aarch64_ext_ft (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1037 aarch64_opnd_info
*info
,
1038 const aarch64_insn code
, const aarch64_inst
*inst
,
1039 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1044 info
->reg
.regno
= extract_field (FLD_Rt
, code
, 0);
1047 value
= extract_field (FLD_ldst_size
, code
, 0);
1048 if (inst
->opcode
->iclass
== ldstpair_indexed
1049 || inst
->opcode
->iclass
== ldstnapair_offs
1050 || inst
->opcode
->iclass
== ldstpair_off
1051 || inst
->opcode
->iclass
== loadlit
)
1053 enum aarch64_opnd_qualifier qualifier
;
1056 case 0: qualifier
= AARCH64_OPND_QLF_S_S
; break;
1057 case 1: qualifier
= AARCH64_OPND_QLF_S_D
; break;
1058 case 2: qualifier
= AARCH64_OPND_QLF_S_Q
; break;
1059 default: return false;
1061 info
->qualifier
= qualifier
;
1066 value
= extract_fields (code
, 0, 2, FLD_opc1
, FLD_ldst_size
);
1069 info
->qualifier
= get_sreg_qualifier_from_value (value
);
1070 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1077 /* Decode the address operand for e.g. STXRB <Ws>, <Wt>, [<Xn|SP>{,#0}]. */
1079 aarch64_ext_addr_simple (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1080 aarch64_opnd_info
*info
,
1082 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1083 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1086 info
->addr
.base_regno
= extract_field (FLD_Rn
, code
, 0);
1090 /* Decode the address operand for rcpc3 instructions with optional load/store
1091 datasize offset, e.g. STILPP <Xs>, <Xt>, [<Xn|SP>{,#-16}]! and
1092 LIDAP <Xs>, <Xt>, [<Xn|SP>]{,#-16}. */
1094 aarch64_ext_rcpc3_addr_opt_offset (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1095 aarch64_opnd_info
*info
,
1097 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1098 aarch64_operand_error
*err ATTRIBUTE_UNUSED
)
1100 info
->addr
.base_regno
= extract_field (FLD_Rn
, code
, 0);
1101 if (!extract_field (FLD_opc2
, code
, 0))
1103 info
->addr
.writeback
= 1;
1105 enum aarch64_opnd type
;
1106 for (int i
= 0; i
< AARCH64_MAX_OPND_NUM
; i
++)
1108 aarch64_opnd_info opnd
= info
[i
];
1110 if (aarch64_operands
[type
].op_class
== AARCH64_OPND_CLASS_ADDRESS
)
1114 assert (aarch64_operands
[type
].op_class
== AARCH64_OPND_CLASS_ADDRESS
);
1115 int offset
= calc_ldst_datasize (inst
->operands
);
1119 case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB
:
1120 case AARCH64_OPND_RCPC3_ADDR_PREIND_WB
:
1121 info
->addr
.offset
.imm
= -offset
;
1122 info
->addr
.preind
= 1;
1124 case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND
:
1125 case AARCH64_OPND_RCPC3_ADDR_POSTIND
:
1126 info
->addr
.offset
.imm
= offset
;
1127 info
->addr
.postind
= 1;
1137 aarch64_ext_rcpc3_addr_offset (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1138 aarch64_opnd_info
*info
,
1140 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1141 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1143 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
1144 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1148 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1151 aarch64_insn imm
= extract_fields (code
, 0, 1, self
->fields
[1]);
1152 info
->addr
.offset
.imm
= sign_extend (imm
, 8);
1156 /* Decode the address operand for e.g.
1157 stlur <Xt>, [<Xn|SP>{, <amount>}]. */
1159 aarch64_ext_addr_offset (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1160 aarch64_opnd_info
*info
,
1161 aarch64_insn code
, const aarch64_inst
*inst
,
1162 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1164 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
1165 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1169 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1172 aarch64_insn imm
= extract_fields (code
, 0, 1, self
->fields
[1]);
1173 info
->addr
.offset
.imm
= sign_extend (imm
, 8);
1174 if (extract_field (self
->fields
[2], code
, 0) == 1) {
1175 info
->addr
.writeback
= 1;
1176 info
->addr
.preind
= 1;
1181 /* Decode the address operand for e.g.
1182 STR <Qt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */
1184 aarch64_ext_addr_regoff (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1185 aarch64_opnd_info
*info
,
1186 aarch64_insn code
, const aarch64_inst
*inst
,
1187 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1189 aarch64_insn S
, value
;
1192 info
->addr
.base_regno
= extract_field (FLD_Rn
, code
, 0);
1194 info
->addr
.offset
.regno
= extract_field (FLD_Rm
, code
, 0);
1196 value
= extract_field (FLD_option
, code
, 0);
1197 info
->shifter
.kind
=
1198 aarch64_get_operand_modifier_from_value (value
, true /* extend_p */);
1199 /* Fix-up the shifter kind; although the table-driven approach is
1200 efficient, it is slightly inflexible, thus needing this fix-up. */
1201 if (info
->shifter
.kind
== AARCH64_MOD_UXTX
)
1202 info
->shifter
.kind
= AARCH64_MOD_LSL
;
1204 S
= extract_field (FLD_S
, code
, 0);
1207 info
->shifter
.amount
= 0;
1208 info
->shifter
.amount_present
= 0;
1213 /* Need information in other operand(s) to help achieve the decoding
1215 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
1216 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1218 /* Get the size of the data element that is accessed, which may be
1219 different from that of the source register size, e.g. in strb/ldrb. */
1220 size
= aarch64_get_qualifier_esize (info
->qualifier
);
1221 info
->shifter
.amount
= get_logsz (size
);
1222 info
->shifter
.amount_present
= 1;
1228 /* Decode the address operand for e.g. LDRSW <Xt>, [<Xn|SP>], #<simm>. */
1230 aarch64_ext_addr_simm (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
1231 aarch64_insn code
, const aarch64_inst
*inst
,
1232 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1235 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
1236 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1240 info
->addr
.base_regno
= extract_field (FLD_Rn
, code
, 0);
1241 /* simm (imm9 or imm7) */
1242 imm
= extract_field (self
->fields
[0], code
, 0);
1243 info
->addr
.offset
.imm
= sign_extend (imm
, fields
[self
->fields
[0]].width
- 1);
1244 if (self
->fields
[0] == FLD_imm7
1245 || info
->qualifier
== AARCH64_OPND_QLF_imm_tag
)
1246 /* scaled immediate in ld/st pair instructions. */
1247 info
->addr
.offset
.imm
*= aarch64_get_qualifier_esize (info
->qualifier
);
1249 if (inst
->opcode
->iclass
== ldst_unscaled
1250 || inst
->opcode
->iclass
== ldstnapair_offs
1251 || inst
->opcode
->iclass
== ldstpair_off
1252 || inst
->opcode
->iclass
== ldst_unpriv
)
1253 info
->addr
.writeback
= 0;
1256 /* pre/post- index */
1257 info
->addr
.writeback
= 1;
1258 if (extract_field (self
->fields
[1], code
, 0) == 1)
1259 info
->addr
.preind
= 1;
1261 info
->addr
.postind
= 1;
1267 /* Decode the address operand for e.g. LDRSW <Xt>, [<Xn|SP>{, #<simm>}]. */
1269 aarch64_ext_addr_uimm12 (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
1271 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1272 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1275 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
1276 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1278 shift
= get_logsz (aarch64_get_qualifier_esize (info
->qualifier
));
1280 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1282 info
->addr
.offset
.imm
= extract_field (self
->fields
[1], code
, 0) << shift
;
1286 /* Decode the address operand for e.g. LDRAA <Xt>, [<Xn|SP>{, #<simm>}]. */
1288 aarch64_ext_addr_simm10 (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
1290 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1291 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1295 info
->qualifier
= get_expected_qualifier (inst
, info
->idx
);
1296 if (info
->qualifier
== AARCH64_OPND_QLF_ERR
)
1299 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1301 imm
= extract_fields (code
, 0, 2, self
->fields
[1], self
->fields
[2]);
1302 info
->addr
.offset
.imm
= sign_extend (imm
, 9) << 3;
1303 if (extract_field (self
->fields
[3], code
, 0) == 1) {
1304 info
->addr
.writeback
= 1;
1305 info
->addr
.preind
= 1;
1310 /* Decode the address operand for e.g.
1311 LD1 {<Vt>.<T>, <Vt2>.<T>, <Vt3>.<T>}, [<Xn|SP>], <Xm|#<amount>>. */
1313 aarch64_ext_simd_addr_post (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1314 aarch64_opnd_info
*info
,
1315 aarch64_insn code
, const aarch64_inst
*inst
,
1316 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1318 /* The opcode dependent area stores the number of elements in
1319 each structure to be loaded/stored. */
1320 int is_ld1r
= get_opcode_dependent_value (inst
->opcode
) == 1;
1323 info
->addr
.base_regno
= extract_field (FLD_Rn
, code
, 0);
1324 /* Rm | #<amount> */
1325 info
->addr
.offset
.regno
= extract_field (FLD_Rm
, code
, 0);
1326 if (info
->addr
.offset
.regno
== 31)
1328 if (inst
->opcode
->operands
[0] == AARCH64_OPND_LVt_AL
)
1329 /* Special handling of loading single structure to all lane. */
1330 info
->addr
.offset
.imm
= (is_ld1r
? 1
1331 : inst
->operands
[0].reglist
.num_regs
)
1332 * aarch64_get_qualifier_esize (inst
->operands
[0].qualifier
);
1334 info
->addr
.offset
.imm
= inst
->operands
[0].reglist
.num_regs
1335 * aarch64_get_qualifier_esize (inst
->operands
[0].qualifier
)
1336 * aarch64_get_qualifier_nelem (inst
->operands
[0].qualifier
);
1339 info
->addr
.offset
.is_reg
= 1;
1340 info
->addr
.writeback
= 1;
1345 /* Decode the condition operand for e.g. CSEL <Xd>, <Xn>, <Xm>, <cond>. */
1347 aarch64_ext_cond (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1348 aarch64_opnd_info
*info
,
1349 aarch64_insn code
, const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1350 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1354 value
= extract_field (FLD_cond
, code
, 0);
1355 info
->cond
= get_cond_from_value (value
);
1359 /* Decode the system register operand for e.g. MRS <Xt>, <systemreg>. */
1361 aarch64_ext_sysreg (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1362 aarch64_opnd_info
*info
,
1364 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1365 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1367 /* op0:op1:CRn:CRm:op2 */
1368 info
->sysreg
.value
= extract_fields (code
, 0, 5, FLD_op0
, FLD_op1
, FLD_CRn
,
1370 info
->sysreg
.flags
= 0;
1372 /* If a system instruction, check which restrictions should be on the register
1373 value during decoding, these will be enforced then. */
1374 if (inst
->opcode
->iclass
== ic_system
)
1376 /* Check to see if it's read-only, else check if it's write only.
1377 if it's both or unspecified don't care. */
1378 if ((inst
->opcode
->flags
& (F_SYS_READ
| F_SYS_WRITE
)) == F_SYS_READ
)
1379 info
->sysreg
.flags
= F_REG_READ
;
1380 else if ((inst
->opcode
->flags
& (F_SYS_READ
| F_SYS_WRITE
))
1382 info
->sysreg
.flags
= F_REG_WRITE
;
1388 /* Decode the PSTATE field operand for e.g. MSR <pstatefield>, #<imm>. */
1390 aarch64_ext_pstatefield (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1391 aarch64_opnd_info
*info
, aarch64_insn code
,
1392 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1393 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1396 aarch64_insn fld_crm
= extract_field (FLD_CRm
, code
, 0);
1398 info
->pstatefield
= extract_fields (code
, 0, 2, FLD_op1
, FLD_op2
);
1399 for (i
= 0; aarch64_pstatefields
[i
].name
!= NULL
; ++i
)
1400 if (aarch64_pstatefields
[i
].value
== (aarch64_insn
)info
->pstatefield
)
1402 /* PSTATEFIELD name can be encoded partially in CRm[3:1]. */
1403 uint32_t flags
= aarch64_pstatefields
[i
].flags
;
1404 if ((flags
& F_REG_IN_CRM
)
1405 && ((fld_crm
& 0xe) != PSTATE_DECODE_CRM (flags
)))
1407 info
->sysreg
.flags
= flags
;
1410 /* Reserved value in <pstatefield>. */
1414 /* Decode the system instruction op operand for e.g. AT <at_op>, <Xt>. */
1416 aarch64_ext_sysins_op (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1417 aarch64_opnd_info
*info
,
1419 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1420 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1424 const aarch64_sys_ins_reg
*sysins_ops
;
1425 /* op0:op1:CRn:CRm:op2 */
1426 value
= extract_fields (code
, 0, 5,
1427 FLD_op0
, FLD_op1
, FLD_CRn
,
1432 case AARCH64_OPND_SYSREG_AT
: sysins_ops
= aarch64_sys_regs_at
; break;
1433 case AARCH64_OPND_SYSREG_DC
: sysins_ops
= aarch64_sys_regs_dc
; break;
1434 case AARCH64_OPND_SYSREG_IC
: sysins_ops
= aarch64_sys_regs_ic
; break;
1435 case AARCH64_OPND_SYSREG_TLBI
: sysins_ops
= aarch64_sys_regs_tlbi
; break;
1436 case AARCH64_OPND_SYSREG_TLBIP
: sysins_ops
= aarch64_sys_regs_tlbi
; break;
1437 case AARCH64_OPND_SYSREG_SR
:
1438 sysins_ops
= aarch64_sys_regs_sr
;
1439 /* Let's remove op2 for rctx. Refer to comments in the definition of
1440 aarch64_sys_regs_sr[]. */
1441 value
= value
& ~(0x7);
1443 default: return false;
1446 for (i
= 0; sysins_ops
[i
].name
!= NULL
; ++i
)
1447 if (sysins_ops
[i
].value
== value
)
1449 info
->sysins_op
= sysins_ops
+ i
;
1450 DEBUG_TRACE ("%s found value: %x, has_xt: %d, i: %d.",
1451 info
->sysins_op
->name
,
1452 (unsigned)info
->sysins_op
->value
,
1453 aarch64_sys_ins_reg_has_xt (info
->sysins_op
), i
);
1460 /* Decode the memory barrier option operand for e.g. DMB <option>|#<imm>. */
1463 aarch64_ext_barrier (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1464 aarch64_opnd_info
*info
,
1466 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1467 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1470 info
->barrier
= aarch64_barrier_options
+ extract_field (FLD_CRm
, code
, 0);
1474 /* Decode the memory barrier option operand for DSB <option>nXS|#<imm>. */
1477 aarch64_ext_barrier_dsb_nxs (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1478 aarch64_opnd_info
*info
,
1480 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1481 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1483 /* For the DSB nXS barrier variant immediate is encoded in 2-bit field. */
1484 aarch64_insn field
= extract_field (FLD_CRm_dsb_nxs
, code
, 0);
1485 info
->barrier
= aarch64_barrier_dsb_nxs_options
+ field
;
1489 /* Decode the prefetch operation option operand for e.g.
1490 PRFM <prfop>, [<Xn|SP>{, #<pimm>}]. */
1493 aarch64_ext_prfop (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1494 aarch64_opnd_info
*info
,
1495 aarch64_insn code
, const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1496 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1499 info
->prfop
= aarch64_prfops
+ extract_field (FLD_Rt
, code
, 0);
1503 /* Decode the hint number for an alias taking an operand. Set info->hint_option
1504 to the matching name/value pair in aarch64_hint_options. */
1507 aarch64_ext_hint (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1508 aarch64_opnd_info
*info
,
1510 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1511 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1514 unsigned hint_number
;
1517 hint_number
= extract_fields (code
, 0, 2, FLD_CRm
, FLD_op2
);
1519 for (i
= 0; aarch64_hint_options
[i
].name
!= NULL
; i
++)
1521 if (hint_number
== HINT_VAL (aarch64_hint_options
[i
].value
))
1523 info
->hint_option
= &(aarch64_hint_options
[i
]);
1531 /* Decode the extended register operand for e.g.
1532 STR <Qt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */
1534 aarch64_ext_reg_extended (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1535 aarch64_opnd_info
*info
,
1537 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1538 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1543 info
->reg
.regno
= extract_field (FLD_Rm
, code
, 0);
1545 value
= extract_field (FLD_option
, code
, 0);
1546 info
->shifter
.kind
=
1547 aarch64_get_operand_modifier_from_value (value
, true /* extend_p */);
1549 info
->shifter
.amount
= extract_field (FLD_imm3_10
, code
, 0);
1551 /* This makes the constraint checking happy. */
1552 info
->shifter
.operator_present
= 1;
1554 /* Assume inst->operands[0].qualifier has been resolved. */
1555 assert (inst
->operands
[0].qualifier
!= AARCH64_OPND_QLF_NIL
);
1556 info
->qualifier
= AARCH64_OPND_QLF_W
;
1557 if (inst
->operands
[0].qualifier
== AARCH64_OPND_QLF_X
1558 && (info
->shifter
.kind
== AARCH64_MOD_UXTX
1559 || info
->shifter
.kind
== AARCH64_MOD_SXTX
))
1560 info
->qualifier
= AARCH64_OPND_QLF_X
;
1565 /* Decode the shifted register operand for e.g.
1566 SUBS <Xd>, <Xn>, <Xm> {, <shift> #<amount>}. */
1568 aarch64_ext_reg_shifted (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1569 aarch64_opnd_info
*info
,
1571 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1572 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1577 info
->reg
.regno
= extract_field (FLD_Rm
, code
, 0);
1579 value
= extract_field (FLD_shift
, code
, 0);
1580 info
->shifter
.kind
=
1581 aarch64_get_operand_modifier_from_value (value
, false /* extend_p */);
1582 if (info
->shifter
.kind
== AARCH64_MOD_ROR
1583 && inst
->opcode
->iclass
!= log_shift
)
1584 /* ROR is not available for the shifted register operand in arithmetic
1588 info
->shifter
.amount
= extract_field (FLD_imm6_10
, code
, 0);
1590 /* This makes the constraint checking happy. */
1591 info
->shifter
.operator_present
= 1;
1596 /* Decode the LSL-shifted register operand for e.g.
1597 ADDPT <Xd|SP>, <Xn|SP>, <Xm>{, LSL #<amount>}. */
1599 aarch64_ext_reg_lsl_shifted (const aarch64_operand
*self ATTRIBUTE_UNUSED
,
1600 aarch64_opnd_info
*info
,
1602 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1603 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1606 info
->reg
.regno
= extract_field (FLD_Rm
, code
, 0);
1608 info
->shifter
.kind
= AARCH64_MOD_LSL
;
1609 info
->shifter
.amount
= extract_field (FLD_imm3_10
, code
, 0);
1613 /* Decode an SVE address [<base>, #<offset>*<factor>, MUL VL],
1614 where <offset> is given by the OFFSET parameter and where <factor> is
1615 1 plus SELF's operand-dependent value. fields[0] specifies the field
1616 that holds <base>. */
1618 aarch64_ext_sve_addr_reg_mul_vl (const aarch64_operand
*self
,
1619 aarch64_opnd_info
*info
, aarch64_insn code
,
1622 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1623 info
->addr
.offset
.imm
= offset
* (1 + get_operand_specific_data (self
));
1624 info
->addr
.offset
.is_reg
= false;
1625 info
->addr
.writeback
= false;
1626 info
->addr
.preind
= true;
1628 info
->shifter
.kind
= AARCH64_MOD_MUL_VL
;
1629 info
->shifter
.amount
= 1;
1630 info
->shifter
.operator_present
= (info
->addr
.offset
.imm
!= 0);
1631 info
->shifter
.amount_present
= false;
1635 /* Decode an SVE address [<base>, #<simm4>*<factor>, MUL VL],
1636 where <simm4> is a 4-bit signed value and where <factor> is 1 plus
1637 SELF's operand-dependent value. fields[0] specifies the field that
1638 holds <base>. <simm4> is encoded in the SVE_imm4 field. */
1640 aarch64_ext_sve_addr_ri_s4xvl (const aarch64_operand
*self
,
1641 aarch64_opnd_info
*info
, aarch64_insn code
,
1642 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1643 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1647 offset
= extract_field (FLD_SVE_imm4
, code
, 0);
1648 offset
= ((offset
+ 8) & 15) - 8;
1649 return aarch64_ext_sve_addr_reg_mul_vl (self
, info
, code
, offset
);
1652 /* Decode an SVE address [<base>, #<simm6>*<factor>, MUL VL],
1653 where <simm6> is a 6-bit signed value and where <factor> is 1 plus
1654 SELF's operand-dependent value. fields[0] specifies the field that
1655 holds <base>. <simm6> is encoded in the SVE_imm6 field. */
1657 aarch64_ext_sve_addr_ri_s6xvl (const aarch64_operand
*self
,
1658 aarch64_opnd_info
*info
, aarch64_insn code
,
1659 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1660 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1664 offset
= extract_field (FLD_SVE_imm6
, code
, 0);
1665 offset
= (((offset
+ 32) & 63) - 32);
1666 return aarch64_ext_sve_addr_reg_mul_vl (self
, info
, code
, offset
);
1669 /* Decode an SVE address [<base>, #<simm9>*<factor>, MUL VL],
1670 where <simm9> is a 9-bit signed value and where <factor> is 1 plus
1671 SELF's operand-dependent value. fields[0] specifies the field that
1672 holds <base>. <simm9> is encoded in the concatenation of the SVE_imm6
1673 and imm3 fields, with imm3 being the less-significant part. */
1675 aarch64_ext_sve_addr_ri_s9xvl (const aarch64_operand
*self
,
1676 aarch64_opnd_info
*info
,
1678 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1679 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1683 offset
= extract_fields (code
, 0, 2, FLD_SVE_imm6
, FLD_imm3_10
);
1684 offset
= (((offset
+ 256) & 511) - 256);
1685 return aarch64_ext_sve_addr_reg_mul_vl (self
, info
, code
, offset
);
1688 /* Decode an SVE address [<base>, #<offset> << <shift>], where <offset>
1689 is given by the OFFSET parameter and where <shift> is SELF's operand-
1690 dependent value. fields[0] specifies the base register field <base>. */
1692 aarch64_ext_sve_addr_reg_imm (const aarch64_operand
*self
,
1693 aarch64_opnd_info
*info
, aarch64_insn code
,
1696 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1697 info
->addr
.offset
.imm
= offset
* (1 << get_operand_specific_data (self
));
1698 info
->addr
.offset
.is_reg
= false;
1699 info
->addr
.writeback
= false;
1700 info
->addr
.preind
= true;
1701 info
->shifter
.operator_present
= false;
1702 info
->shifter
.amount_present
= false;
1706 /* Decode an SVE address [X<n>, #<SVE_imm4> << <shift>], where <SVE_imm4>
1707 is a 4-bit signed number and where <shift> is SELF's operand-dependent
1708 value. fields[0] specifies the base register field. */
1710 aarch64_ext_sve_addr_ri_s4 (const aarch64_operand
*self
,
1711 aarch64_opnd_info
*info
, aarch64_insn code
,
1712 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1713 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1715 int offset
= sign_extend (extract_field (FLD_SVE_imm4
, code
, 0), 3);
1716 return aarch64_ext_sve_addr_reg_imm (self
, info
, code
, offset
);
1719 /* Decode an SVE address [X<n>, #<SVE_imm6> << <shift>], where <SVE_imm6>
1720 is a 6-bit unsigned number and where <shift> is SELF's operand-dependent
1721 value. fields[0] specifies the base register field. */
1723 aarch64_ext_sve_addr_ri_u6 (const aarch64_operand
*self
,
1724 aarch64_opnd_info
*info
, aarch64_insn code
,
1725 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1726 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1728 int offset
= extract_field (FLD_SVE_imm6
, code
, 0);
1729 return aarch64_ext_sve_addr_reg_imm (self
, info
, code
, offset
);
1732 /* Decode an SVE address [X<n>, X<m>{, LSL #<shift>}], where <shift>
1733 is SELF's operand-dependent value. fields[0] specifies the base
1734 register field and fields[1] specifies the offset register field. */
1736 aarch64_ext_sve_addr_rr_lsl (const aarch64_operand
*self
,
1737 aarch64_opnd_info
*info
, aarch64_insn code
,
1738 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1739 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1743 index_regno
= extract_field (self
->fields
[1], code
, 0);
1744 if (index_regno
== 31 && (self
->flags
& OPD_F_NO_ZR
) != 0)
1747 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1748 info
->addr
.offset
.regno
= index_regno
;
1749 info
->addr
.offset
.is_reg
= true;
1750 info
->addr
.writeback
= false;
1751 info
->addr
.preind
= true;
1752 info
->shifter
.kind
= AARCH64_MOD_LSL
;
1753 info
->shifter
.amount
= get_operand_specific_data (self
);
1754 info
->shifter
.operator_present
= (info
->shifter
.amount
!= 0);
1755 info
->shifter
.amount_present
= (info
->shifter
.amount
!= 0);
1759 /* Decode an SVE address [X<n>, Z<m>.<T>, (S|U)XTW {#<shift>}], where
1760 <shift> is SELF's operand-dependent value. fields[0] specifies the
1761 base register field, fields[1] specifies the offset register field and
1762 fields[2] is a single-bit field that selects SXTW over UXTW. */
1764 aarch64_ext_sve_addr_rz_xtw (const aarch64_operand
*self
,
1765 aarch64_opnd_info
*info
, aarch64_insn code
,
1766 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1767 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1769 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1770 info
->addr
.offset
.regno
= extract_field (self
->fields
[1], code
, 0);
1771 info
->addr
.offset
.is_reg
= true;
1772 info
->addr
.writeback
= false;
1773 info
->addr
.preind
= true;
1774 if (extract_field (self
->fields
[2], code
, 0))
1775 info
->shifter
.kind
= AARCH64_MOD_SXTW
;
1777 info
->shifter
.kind
= AARCH64_MOD_UXTW
;
1778 info
->shifter
.amount
= get_operand_specific_data (self
);
1779 info
->shifter
.operator_present
= true;
1780 info
->shifter
.amount_present
= (info
->shifter
.amount
!= 0);
1784 /* Decode an SVE address [Z<n>.<T>, #<imm5> << <shift>], where <imm5> is a
1785 5-bit unsigned number and where <shift> is SELF's operand-dependent value.
1786 fields[0] specifies the base register field. */
1788 aarch64_ext_sve_addr_zi_u5 (const aarch64_operand
*self
,
1789 aarch64_opnd_info
*info
, aarch64_insn code
,
1790 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1791 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1793 int offset
= extract_field (FLD_imm5
, code
, 0);
1794 return aarch64_ext_sve_addr_reg_imm (self
, info
, code
, offset
);
1797 /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>{, <modifier> {#<msz>}}],
1798 where <modifier> is given by KIND and where <msz> is a 2-bit unsigned
1799 number. fields[0] specifies the base register field and fields[1]
1800 specifies the offset register field. */
1802 aarch64_ext_sve_addr_zz (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
1803 aarch64_insn code
, enum aarch64_modifier_kind kind
)
1805 info
->addr
.base_regno
= extract_field (self
->fields
[0], code
, 0);
1806 info
->addr
.offset
.regno
= extract_field (self
->fields
[1], code
, 0);
1807 info
->addr
.offset
.is_reg
= true;
1808 info
->addr
.writeback
= false;
1809 info
->addr
.preind
= true;
1810 info
->shifter
.kind
= kind
;
1811 info
->shifter
.amount
= extract_field (FLD_SVE_msz
, code
, 0);
1812 info
->shifter
.operator_present
= (kind
!= AARCH64_MOD_LSL
1813 || info
->shifter
.amount
!= 0);
1814 info
->shifter
.amount_present
= (info
->shifter
.amount
!= 0);
1818 /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>{, LSL #<msz>}], where
1819 <msz> is a 2-bit unsigned number. fields[0] specifies the base register
1820 field and fields[1] specifies the offset register field. */
1822 aarch64_ext_sve_addr_zz_lsl (const aarch64_operand
*self
,
1823 aarch64_opnd_info
*info
, aarch64_insn code
,
1824 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1825 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1827 return aarch64_ext_sve_addr_zz (self
, info
, code
, AARCH64_MOD_LSL
);
1830 /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>, SXTW {#<msz>}], where
1831 <msz> is a 2-bit unsigned number. fields[0] specifies the base register
1832 field and fields[1] specifies the offset register field. */
1834 aarch64_ext_sve_addr_zz_sxtw (const aarch64_operand
*self
,
1835 aarch64_opnd_info
*info
, aarch64_insn code
,
1836 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1837 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1839 return aarch64_ext_sve_addr_zz (self
, info
, code
, AARCH64_MOD_SXTW
);
1842 /* Decode an SVE address [Z<n>.<T>, Z<m>.<T>, UXTW {#<msz>}], where
1843 <msz> is a 2-bit unsigned number. fields[0] specifies the base register
1844 field and fields[1] specifies the offset register field. */
1846 aarch64_ext_sve_addr_zz_uxtw (const aarch64_operand
*self
,
1847 aarch64_opnd_info
*info
, aarch64_insn code
,
1848 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1849 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1851 return aarch64_ext_sve_addr_zz (self
, info
, code
, AARCH64_MOD_UXTW
);
1854 /* Finish decoding an SVE arithmetic immediate, given that INFO already
1855 has the raw field value and that the low 8 bits decode to VALUE. */
1857 decode_sve_aimm (aarch64_opnd_info
*info
, int64_t value
)
1859 info
->shifter
.kind
= AARCH64_MOD_LSL
;
1860 info
->shifter
.amount
= 0;
1861 if (info
->imm
.value
& 0x100)
1864 /* Decode 0x100 as #0, LSL #8. */
1865 info
->shifter
.amount
= 8;
1869 info
->shifter
.operator_present
= (info
->shifter
.amount
!= 0);
1870 info
->shifter
.amount_present
= (info
->shifter
.amount
!= 0);
1871 info
->imm
.value
= value
;
1875 /* Decode an SVE ADD/SUB immediate. */
1877 aarch64_ext_sve_aimm (const aarch64_operand
*self
,
1878 aarch64_opnd_info
*info
, const aarch64_insn code
,
1879 const aarch64_inst
*inst
,
1880 aarch64_operand_error
*errors
)
1882 return (aarch64_ext_imm (self
, info
, code
, inst
, errors
)
1883 && decode_sve_aimm (info
, (uint8_t) info
->imm
.value
));
1887 aarch64_ext_sve_aligned_reglist (const aarch64_operand
*self
,
1888 aarch64_opnd_info
*info
, aarch64_insn code
,
1889 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1890 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1892 unsigned int num_regs
= get_operand_specific_data (self
);
1893 unsigned int val
= extract_field (self
->fields
[0], code
, 0);
1894 info
->reglist
.first_regno
= val
* num_regs
;
1895 info
->reglist
.num_regs
= num_regs
;
1896 info
->reglist
.stride
= 1;
1900 /* Decode an SVE CPY/DUP immediate. */
1902 aarch64_ext_sve_asimm (const aarch64_operand
*self
,
1903 aarch64_opnd_info
*info
, const aarch64_insn code
,
1904 const aarch64_inst
*inst
,
1905 aarch64_operand_error
*errors
)
1907 return (aarch64_ext_imm (self
, info
, code
, inst
, errors
)
1908 && decode_sve_aimm (info
, (int8_t) info
->imm
.value
));
1911 /* Decode a single-bit immediate that selects between #0.5 and #1.0.
1912 The fields array specifies which field to use. */
1914 aarch64_ext_sve_float_half_one (const aarch64_operand
*self
,
1915 aarch64_opnd_info
*info
, aarch64_insn code
,
1916 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1917 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1919 if (extract_field (self
->fields
[0], code
, 0))
1920 info
->imm
.value
= 0x3f800000;
1922 info
->imm
.value
= 0x3f000000;
1923 info
->imm
.is_fp
= true;
1927 /* Decode a single-bit immediate that selects between #0.5 and #2.0.
1928 The fields array specifies which field to use. */
1930 aarch64_ext_sve_float_half_two (const aarch64_operand
*self
,
1931 aarch64_opnd_info
*info
, aarch64_insn code
,
1932 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1933 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1935 if (extract_field (self
->fields
[0], code
, 0))
1936 info
->imm
.value
= 0x40000000;
1938 info
->imm
.value
= 0x3f000000;
1939 info
->imm
.is_fp
= true;
1943 /* Decode a single-bit immediate that selects between #0.0 and #1.0.
1944 The fields array specifies which field to use. */
1946 aarch64_ext_sve_float_zero_one (const aarch64_operand
*self
,
1947 aarch64_opnd_info
*info
, aarch64_insn code
,
1948 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1949 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1951 if (extract_field (self
->fields
[0], code
, 0))
1952 info
->imm
.value
= 0x3f800000;
1954 info
->imm
.value
= 0x0;
1955 info
->imm
.is_fp
= true;
1959 /* Decode SME instruction such as MOVZA ZA tile slice to vector. */
1961 aarch64_ext_sme_za_tile_to_vec (const aarch64_operand
*self
,
1962 aarch64_opnd_info
*info
, aarch64_insn code
,
1963 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
1964 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
1966 aarch64_insn Qsize
; /* fields Q:S:size. */
1967 int fld_v
= extract_field (self
->fields
[0], code
, 0);
1968 int fld_rv
= extract_field (self
->fields
[1], code
, 0);
1969 int fld_zan_imm
= extract_field (FLD_imm4_5
, code
, 0);
1971 Qsize
= extract_fields (inst
->value
, 0, 2, FLD_SME_size_22
, FLD_SME_Q
);
1975 info
->qualifier
= AARCH64_OPND_QLF_S_B
;
1976 info
->indexed_za
.regno
= 0;
1977 info
->indexed_za
.index
.imm
= fld_zan_imm
;
1980 info
->qualifier
= AARCH64_OPND_QLF_S_H
;
1981 info
->indexed_za
.regno
= fld_zan_imm
>> 3;
1982 info
->indexed_za
.index
.imm
= fld_zan_imm
& 0x07;
1985 info
->qualifier
= AARCH64_OPND_QLF_S_S
;
1986 info
->indexed_za
.regno
= fld_zan_imm
>> 2;
1987 info
->indexed_za
.index
.imm
= fld_zan_imm
& 0x03;
1990 info
->qualifier
= AARCH64_OPND_QLF_S_D
;
1991 info
->indexed_za
.regno
= fld_zan_imm
>> 1;
1992 info
->indexed_za
.index
.imm
= fld_zan_imm
& 0x01;
1995 info
->qualifier
= AARCH64_OPND_QLF_S_Q
;
1996 info
->indexed_za
.regno
= fld_zan_imm
;
2002 info
->indexed_za
.index
.regno
= fld_rv
+ 12;
2003 info
->indexed_za
.v
= fld_v
;
2008 /* Decode ZA tile vector, vector indicator, vector selector, qualifier and
2009 immediate on numerous SME instruction fields such as MOVA. */
2011 aarch64_ext_sme_za_hv_tiles (const aarch64_operand
*self
,
2012 aarch64_opnd_info
*info
, aarch64_insn code
,
2013 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2014 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2016 int fld_size
= extract_field (self
->fields
[0], code
, 0);
2017 int fld_q
= extract_field (self
->fields
[1], code
, 0);
2018 int fld_v
= extract_field (self
->fields
[2], code
, 0);
2019 int fld_rv
= extract_field (self
->fields
[3], code
, 0);
2020 int fld_zan_imm
= extract_field (self
->fields
[4], code
, 0);
2022 /* Deduce qualifier encoded in size and Q fields. */
2025 info
->indexed_za
.regno
= 0;
2026 info
->indexed_za
.index
.imm
= fld_zan_imm
;
2028 else if (fld_size
== 1)
2030 info
->indexed_za
.regno
= fld_zan_imm
>> 3;
2031 info
->indexed_za
.index
.imm
= fld_zan_imm
& 0x07;
2033 else if (fld_size
== 2)
2035 info
->indexed_za
.regno
= fld_zan_imm
>> 2;
2036 info
->indexed_za
.index
.imm
= fld_zan_imm
& 0x03;
2038 else if (fld_size
== 3 && fld_q
== 0)
2040 info
->indexed_za
.regno
= fld_zan_imm
>> 1;
2041 info
->indexed_za
.index
.imm
= fld_zan_imm
& 0x01;
2043 else if (fld_size
== 3 && fld_q
== 1)
2045 info
->indexed_za
.regno
= fld_zan_imm
;
2046 info
->indexed_za
.index
.imm
= 0;
2051 info
->indexed_za
.index
.regno
= fld_rv
+ 12;
2052 info
->indexed_za
.v
= fld_v
;
2058 aarch64_ext_sme_za_hv_tiles_range (const aarch64_operand
*self
,
2059 aarch64_opnd_info
*info
, aarch64_insn code
,
2060 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2061 aarch64_operand_error
*errors
2064 int ebytes
= aarch64_get_qualifier_esize (info
->qualifier
);
2065 int range_size
= get_opcode_dependent_value (inst
->opcode
);
2066 int fld_v
= extract_field (self
->fields
[0], code
, 0);
2067 int fld_rv
= extract_field (self
->fields
[1], code
, 0);
2068 int fld_zan_imm
= extract_field (self
->fields
[2], code
, 0);
2069 int max_value
= 16 / range_size
/ ebytes
;
2074 int regno
= fld_zan_imm
/ max_value
;
2075 if (regno
>= ebytes
)
2078 info
->indexed_za
.regno
= regno
;
2079 info
->indexed_za
.index
.imm
= (fld_zan_imm
% max_value
) * range_size
;
2080 info
->indexed_za
.index
.countm1
= range_size
- 1;
2081 info
->indexed_za
.index
.regno
= fld_rv
+ 12;
2082 info
->indexed_za
.v
= fld_v
;
2087 /* Decode in SME instruction ZERO list of up to eight 64-bit element tile names
2088 separated by commas, encoded in the "imm8" field.
2090 For programmer convenience an assembler must also accept the names of
2091 32-bit, 16-bit and 8-bit element tiles which are converted into the
2092 corresponding set of 64-bit element tiles.
2095 aarch64_ext_sme_za_list (const aarch64_operand
*self
,
2096 aarch64_opnd_info
*info
, aarch64_insn code
,
2097 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2098 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2100 int mask
= extract_field (self
->fields
[0], code
, 0);
2101 info
->imm
.value
= mask
;
2105 /* Decode ZA array vector select register (Rv field), optional vector and
2106 memory offset (imm4_11 field).
2109 aarch64_ext_sme_za_array (const aarch64_operand
*self
,
2110 aarch64_opnd_info
*info
, aarch64_insn code
,
2111 const aarch64_inst
*inst
,
2112 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2114 int regno
= extract_field (self
->fields
[0], code
, 0);
2115 if (info
->type
== AARCH64_OPND_SME_ZA_array_off4
)
2119 int imm
= extract_field (self
->fields
[1], code
, 0);
2120 int num_offsets
= get_operand_specific_data (self
);
2121 if (num_offsets
== 0)
2123 info
->indexed_za
.index
.regno
= regno
;
2124 info
->indexed_za
.index
.imm
= imm
* num_offsets
;
2125 info
->indexed_za
.index
.countm1
= num_offsets
- 1;
2126 info
->indexed_za
.group_size
= get_opcode_dependent_value (inst
->opcode
);
2130 /* Decode two ZA tile slice (V, Rv, off3| ZAn ,off2 | ZAn, ol| ZAn) feilds. */
2132 aarch64_ext_sme_za_vrs1 (const aarch64_operand
*self
,
2133 aarch64_opnd_info
*info
, aarch64_insn code
,
2134 const aarch64_inst
*inst
,
2135 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2137 int v
= extract_field (self
->fields
[0], code
, 0);
2138 int regno
= 12 + extract_field (self
->fields
[1], code
, 0);
2139 int imm
, za_reg
, num_offset
= 2;
2141 switch (info
->qualifier
)
2143 case AARCH64_OPND_QLF_S_B
:
2144 imm
= extract_field (self
->fields
[2], code
, 0);
2145 info
->indexed_za
.index
.imm
= imm
* num_offset
;
2147 case AARCH64_OPND_QLF_S_H
:
2148 case AARCH64_OPND_QLF_S_S
:
2149 za_reg
= extract_field (self
->fields
[2], code
, 0);
2150 imm
= extract_field (self
->fields
[3], code
, 0);
2151 info
->indexed_za
.index
.imm
= imm
* num_offset
;
2152 info
->indexed_za
.regno
= za_reg
;
2154 case AARCH64_OPND_QLF_S_D
:
2155 za_reg
= extract_field (self
->fields
[2], code
, 0);
2156 info
->indexed_za
.regno
= za_reg
;
2162 info
->indexed_za
.index
.regno
= regno
;
2163 info
->indexed_za
.index
.countm1
= num_offset
- 1;
2164 info
->indexed_za
.v
= v
;
2165 info
->indexed_za
.group_size
= get_opcode_dependent_value (inst
->opcode
);
2169 /* Decode four ZA tile slice (V, Rv, off3| ZAn ,off2 | ZAn, ol| ZAn) feilds. */
2171 aarch64_ext_sme_za_vrs2 (const aarch64_operand
*self
,
2172 aarch64_opnd_info
*info
, aarch64_insn code
,
2173 const aarch64_inst
*inst
,
2174 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2176 int v
= extract_field (self
->fields
[0], code
, 0);
2177 int regno
= 12 + extract_field (self
->fields
[1], code
, 0);
2178 int imm
, za_reg
, num_offset
=4;
2180 switch (info
->qualifier
)
2182 case AARCH64_OPND_QLF_S_B
:
2183 imm
= extract_field (self
->fields
[2], code
, 0);
2184 info
->indexed_za
.index
.imm
= imm
* num_offset
;
2186 case AARCH64_OPND_QLF_S_H
:
2187 za_reg
= extract_field (self
->fields
[2], code
, 0);
2188 imm
= extract_field (self
->fields
[3], code
, 0);
2189 info
->indexed_za
.index
.imm
= imm
* num_offset
;
2190 info
->indexed_za
.regno
= za_reg
;
2192 case AARCH64_OPND_QLF_S_S
:
2193 case AARCH64_OPND_QLF_S_D
:
2194 za_reg
= extract_field (self
->fields
[2], code
, 0);
2195 info
->indexed_za
.regno
= za_reg
;
2201 info
->indexed_za
.index
.regno
= regno
;
2202 info
->indexed_za
.index
.countm1
= num_offset
- 1;
2203 info
->indexed_za
.v
= v
;
2204 info
->indexed_za
.group_size
= get_opcode_dependent_value (inst
->opcode
);
2209 aarch64_ext_sme_addr_ri_u4xvl (const aarch64_operand
*self
,
2210 aarch64_opnd_info
*info
, aarch64_insn code
,
2211 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2212 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2214 int regno
= extract_field (self
->fields
[0], code
, 0);
2215 int imm
= extract_field (self
->fields
[1], code
, 0);
2216 info
->addr
.base_regno
= regno
;
2217 info
->addr
.offset
.imm
= imm
;
2218 /* MUL VL operator is always present for this operand. */
2219 info
->shifter
.kind
= AARCH64_MOD_MUL_VL
;
2220 info
->shifter
.operator_present
= (imm
!= 0);
2224 /* Decode {SM|ZA} filed for SMSTART and SMSTOP instructions. */
2226 aarch64_ext_sme_sm_za (const aarch64_operand
*self
,
2227 aarch64_opnd_info
*info
, aarch64_insn code
,
2228 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2229 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2231 info
->pstatefield
= 0x1b;
2232 aarch64_insn fld_crm
= extract_field (self
->fields
[0], code
, 0);
2233 fld_crm
>>= 1; /* CRm[3:1]. */
2236 info
->reg
.regno
= 's';
2237 else if (fld_crm
== 0x2)
2238 info
->reg
.regno
= 'z';
2246 aarch64_ext_sme_pred_reg_with_index (const aarch64_operand
*self
,
2247 aarch64_opnd_info
*info
, aarch64_insn code
,
2248 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2249 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2251 aarch64_insn fld_rm
= extract_field (self
->fields
[0], code
, 0);
2252 aarch64_insn fld_pn
= extract_field (self
->fields
[1], code
, 0);
2253 aarch64_insn fld_i1
= extract_field (self
->fields
[2], code
, 0);
2254 aarch64_insn fld_tszh
= extract_field (self
->fields
[3], code
, 0);
2255 aarch64_insn fld_tszl
= extract_field (self
->fields
[4], code
, 0);
2258 info
->indexed_za
.regno
= fld_pn
;
2259 info
->indexed_za
.index
.regno
= fld_rm
+ 12;
2262 imm
= (fld_i1
<< 3) | (fld_tszh
<< 2) | (fld_tszl
>> 1);
2263 else if (fld_tszl
& 0x2)
2264 imm
= (fld_i1
<< 2) | (fld_tszh
<< 1) | (fld_tszl
>> 2);
2265 else if (fld_tszl
& 0x4)
2266 imm
= (fld_i1
<< 1) | fld_tszh
;
2272 info
->indexed_za
.index
.imm
= imm
;
2276 /* Decode Zn[MM], where MM has a 7-bit triangular encoding. The fields
2277 array specifies which field to use for Zn. MM is encoded in the
2278 concatenation of imm5 and SVE_tszh, with imm5 being the less
2279 significant part. */
2281 aarch64_ext_sve_index (const aarch64_operand
*self
,
2282 aarch64_opnd_info
*info
, aarch64_insn code
,
2283 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2284 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2288 info
->reglane
.regno
= extract_field (self
->fields
[0], code
, 0);
2289 val
= extract_all_fields_after (self
, 1, code
);
2290 if ((val
& 31) == 0)
2292 while ((val
& 1) == 0)
2294 info
->reglane
.index
= val
/ 2;
2298 /* Decode a logical immediate for the MOV alias of SVE DUPM. */
2300 aarch64_ext_sve_limm_mov (const aarch64_operand
*self
,
2301 aarch64_opnd_info
*info
, const aarch64_insn code
,
2302 const aarch64_inst
*inst
,
2303 aarch64_operand_error
*errors
)
2305 int esize
= aarch64_get_qualifier_esize (inst
->operands
[0].qualifier
);
2306 return (aarch64_ext_limm (self
, info
, code
, inst
, errors
)
2307 && aarch64_sve_dupm_mov_immediate_p (info
->imm
.value
, esize
));
2310 /* Decode Zn[MM], where Zn occupies the least-significant part of the field
2311 and where MM occupies the most-significant part. The operand-dependent
2312 value specifies the number of bits in Zn. */
2314 aarch64_ext_sve_quad_index (const aarch64_operand
*self
,
2315 aarch64_opnd_info
*info
, aarch64_insn code
,
2316 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2317 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2319 unsigned int reg_bits
= get_operand_specific_data (self
);
2320 unsigned int val
= extract_all_fields (self
, code
);
2321 info
->reglane
.regno
= val
& ((1 << reg_bits
) - 1);
2322 info
->reglane
.index
= val
>> reg_bits
;
2326 /* Decode {Zn.<T> - Zm.<T>}. The fields array specifies which field
2327 to use for Zn. The opcode-dependent value specifies the number
2328 of registers in the list. */
2330 aarch64_ext_sve_reglist (const aarch64_operand
*self
,
2331 aarch64_opnd_info
*info
, aarch64_insn code
,
2332 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2333 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2335 info
->reglist
.first_regno
= extract_field (self
->fields
[0], code
, 0);
2336 info
->reglist
.num_regs
= get_opcode_dependent_value (inst
->opcode
);
2337 info
->reglist
.stride
= 1;
2341 /* Decode {Zn.<T> , Zm.<T>}. The fields array specifies which field
2342 to use for Zn. The opcode-dependent value specifies the number
2343 of registers in the list. */
2345 aarch64_ext_sve_reglist_zt (const aarch64_operand
*self
,
2346 aarch64_opnd_info
*info
, aarch64_insn code
,
2347 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2348 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2350 info
->reglist
.first_regno
= extract_field (self
->fields
[0], code
, 0);
2351 info
->reglist
.num_regs
= get_operand_specific_data (self
);
2352 info
->reglist
.stride
= 1;
2356 /* Decode a strided register list. The first field holds the top bit
2357 (0 or 16) and the second field holds the lower bits. The stride is
2358 16 divided by the list length. */
2360 aarch64_ext_sve_strided_reglist (const aarch64_operand
*self
,
2361 aarch64_opnd_info
*info
, aarch64_insn code
,
2362 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2363 aarch64_operand_error
*errors
2366 unsigned int upper
= extract_field (self
->fields
[0], code
, 0);
2367 unsigned int lower
= extract_field (self
->fields
[1], code
, 0);
2368 info
->reglist
.first_regno
= upper
* 16 + lower
;
2369 info
->reglist
.num_regs
= get_operand_specific_data (self
);
2370 info
->reglist
.stride
= 16 / info
->reglist
.num_regs
;
2374 /* Decode <pattern>{, MUL #<amount>}. The fields array specifies which
2375 fields to use for <pattern>. <amount> - 1 is encoded in the SVE_imm4
2378 aarch64_ext_sve_scale (const aarch64_operand
*self
,
2379 aarch64_opnd_info
*info
, aarch64_insn code
,
2380 const aarch64_inst
*inst
, aarch64_operand_error
*errors
)
2384 if (!aarch64_ext_imm (self
, info
, code
, inst
, errors
))
2386 val
= extract_field (FLD_SVE_imm4
, code
, 0);
2387 info
->shifter
.kind
= AARCH64_MOD_MUL
;
2388 info
->shifter
.amount
= val
+ 1;
2389 info
->shifter
.operator_present
= (val
!= 0);
2390 info
->shifter
.amount_present
= (val
!= 0);
2394 /* Return the top set bit in VALUE, which is expected to be relatively
2397 get_top_bit (uint64_t value
)
2399 while ((value
& -value
) != value
)
2400 value
-= value
& -value
;
2404 /* Decode an SVE shift-left immediate. */
2406 aarch64_ext_sve_shlimm (const aarch64_operand
*self
,
2407 aarch64_opnd_info
*info
, const aarch64_insn code
,
2408 const aarch64_inst
*inst
, aarch64_operand_error
*errors
)
2410 if (!aarch64_ext_imm (self
, info
, code
, inst
, errors
)
2411 || info
->imm
.value
== 0)
2414 info
->imm
.value
-= get_top_bit (info
->imm
.value
);
2418 /* Decode an SVE shift-right immediate. */
2420 aarch64_ext_sve_shrimm (const aarch64_operand
*self
,
2421 aarch64_opnd_info
*info
, const aarch64_insn code
,
2422 const aarch64_inst
*inst
, aarch64_operand_error
*errors
)
2424 if (!aarch64_ext_imm (self
, info
, code
, inst
, errors
)
2425 || info
->imm
.value
== 0)
2428 info
->imm
.value
= get_top_bit (info
->imm
.value
) * 2 - info
->imm
.value
;
2432 /* Decode X0-X30. Register 31 is unallocated. */
2434 aarch64_ext_x0_to_x30 (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
2435 const aarch64_insn code
,
2436 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2437 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2439 info
->reg
.regno
= extract_field (self
->fields
[0], code
, 0);
2440 return info
->reg
.regno
<= 30;
2443 /* Decode an indexed register, with the first field being the register
2444 number and the remaining fields being the index. */
2446 aarch64_ext_simple_index (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
2447 const aarch64_insn code
,
2448 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2449 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2451 int bias
= get_operand_specific_data (self
);
2452 info
->reglane
.regno
= extract_field (self
->fields
[0], code
, 0) + bias
;
2453 info
->reglane
.index
= extract_all_fields_after (self
, 1, code
);
2457 /* Decode a plain shift-right immediate, when there is only a single
2460 aarch64_ext_plain_shrimm (const aarch64_operand
*self
, aarch64_opnd_info
*info
,
2461 const aarch64_insn code
,
2462 const aarch64_inst
*inst ATTRIBUTE_UNUSED
,
2463 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
2465 unsigned int base
= 1 << get_operand_field_width (self
, 0);
2466 info
->imm
.value
= base
- extract_field (self
->fields
[0], code
, 0);
2470 /* Bitfields that are commonly used to encode certain operands' information
2471 may be partially used as part of the base opcode in some instructions.
2472 For example, the bit 1 of the field 'size' in
2473 FCVTXN <Vb><d>, <Va><n>
2474 is actually part of the base opcode, while only size<0> is available
2475 for encoding the register type. Another example is the AdvSIMD
2476 instruction ORR (register), in which the field 'size' is also used for
2477 the base opcode, leaving only the field 'Q' available to encode the
2478 vector register arrangement specifier '8B' or '16B'.
2480 This function tries to deduce the qualifier from the value of partially
2481 constrained field(s). Given the VALUE of such a field or fields, the
2482 qualifiers CANDIDATES and the MASK (indicating which bits are valid for
2483 operand encoding), the function returns the matching qualifier or
2484 AARCH64_OPND_QLF_NIL if nothing matches.
2486 N.B. CANDIDATES is a group of possible qualifiers that are valid for
2487 one operand; it has a maximum of AARCH64_MAX_QLF_SEQ_NUM qualifiers and
2488 may end with AARCH64_OPND_QLF_NIL. */
2490 static enum aarch64_opnd_qualifier
2491 get_qualifier_from_partial_encoding (aarch64_insn value
,
2492 const enum aarch64_opnd_qualifier
* \
2497 DEBUG_TRACE ("enter with value: %d, mask: %d", (int)value
, (int)mask
);
2498 for (i
= 0; i
< AARCH64_MAX_QLF_SEQ_NUM
; ++i
)
2500 aarch64_insn standard_value
;
2501 if (candidates
[i
] == AARCH64_OPND_QLF_NIL
)
2503 standard_value
= aarch64_get_qualifier_standard_value (candidates
[i
]);
2504 if ((standard_value
& mask
) == (value
& mask
))
2505 return candidates
[i
];
2507 return AARCH64_OPND_QLF_NIL
;
2510 /* Given a list of qualifier sequences, return all possible valid qualifiers
2511 for operand IDX in QUALIFIERS.
2512 Assume QUALIFIERS is an array whose length is large enough. */
2515 get_operand_possible_qualifiers (int idx
,
2516 const aarch64_opnd_qualifier_seq_t
*list
,
2517 enum aarch64_opnd_qualifier
*qualifiers
)
2520 for (i
= 0; i
< AARCH64_MAX_QLF_SEQ_NUM
; ++i
)
2521 if ((qualifiers
[i
] = list
[i
][idx
]) == AARCH64_OPND_QLF_NIL
)
2525 /* Decode the size Q field for e.g. SHADD.
2526 We tag one operand with the qualifer according to the code;
2527 whether the qualifier is valid for this opcode or not, it is the
2528 duty of the semantic checking. */
2531 decode_sizeq (aarch64_inst
*inst
)
2534 enum aarch64_opnd_qualifier qualifier
;
2536 aarch64_insn value
, mask
;
2537 enum aarch64_field_kind fld_sz
;
2538 enum aarch64_opnd_qualifier candidates
[AARCH64_MAX_QLF_SEQ_NUM
];
2540 if (inst
->opcode
->iclass
== asisdlse
2541 || inst
->opcode
->iclass
== asisdlsep
2542 || inst
->opcode
->iclass
== asisdlso
2543 || inst
->opcode
->iclass
== asisdlsop
)
2544 fld_sz
= FLD_vldst_size
;
2549 value
= extract_fields (code
, inst
->opcode
->mask
, 2, fld_sz
, FLD_Q
);
2550 /* Obtain the info that which bits of fields Q and size are actually
2551 available for operand encoding. Opcodes like FMAXNM and FMLA have
2552 size[1] unavailable. */
2553 mask
= extract_fields (~inst
->opcode
->mask
, 0, 2, fld_sz
, FLD_Q
);
2555 /* The index of the operand we are going to tag a qualifier and the qualifer
2556 itself are reasoned from the value of the size and Q fields and the
2557 possible valid qualifier lists. */
2558 idx
= aarch64_select_operand_for_sizeq_field_coding (inst
->opcode
);
2559 DEBUG_TRACE ("key idx: %d", idx
);
2561 /* For most related instruciton, size:Q are fully available for operand
2565 inst
->operands
[idx
].qualifier
= get_vreg_qualifier_from_value (value
);
2566 if (inst
->operands
[idx
].qualifier
== AARCH64_OPND_QLF_ERR
)
2571 get_operand_possible_qualifiers (idx
, inst
->opcode
->qualifiers_list
,
2573 #ifdef DEBUG_AARCH64
2577 for (i
= 0; candidates
[i
] != AARCH64_OPND_QLF_NIL
2578 && i
< AARCH64_MAX_QLF_SEQ_NUM
; ++i
)
2579 DEBUG_TRACE ("qualifier %d: %s", i
,
2580 aarch64_get_qualifier_name(candidates
[i
]));
2581 DEBUG_TRACE ("%d, %d", (int)value
, (int)mask
);
2583 #endif /* DEBUG_AARCH64 */
2585 qualifier
= get_qualifier_from_partial_encoding (value
, candidates
, mask
);
2587 if (qualifier
== AARCH64_OPND_QLF_NIL
)
2590 inst
->operands
[idx
].qualifier
= qualifier
;
2594 /* Decode size[0]:Q, i.e. bit 22 and bit 30, for
2595 e.g. FCVTN<Q> <Vd>.<Tb>, <Vn>.<Ta>. */
2598 decode_asimd_fcvt (aarch64_inst
*inst
)
2600 aarch64_field field
= {0, 0};
2602 enum aarch64_opnd_qualifier qualifier
;
2604 gen_sub_field (FLD_size
, 0, 1, &field
);
2605 value
= extract_field_2 (&field
, inst
->value
, 0);
2606 qualifier
= value
== 0 ? AARCH64_OPND_QLF_V_4S
2607 : AARCH64_OPND_QLF_V_2D
;
2608 switch (inst
->opcode
->op
)
2612 /* FCVTN<Q> <Vd>.<Tb>, <Vn>.<Ta>. */
2613 inst
->operands
[1].qualifier
= qualifier
;
2617 /* FCVTL<Q> <Vd>.<Ta>, <Vn>.<Tb>. */
2618 inst
->operands
[0].qualifier
= qualifier
;
2627 /* Decode size[0], i.e. bit 22, for
2628 e.g. FCVTXN <Vb><d>, <Va><n>. */
2631 decode_asisd_fcvtxn (aarch64_inst
*inst
)
2633 aarch64_field field
= {0, 0};
2634 gen_sub_field (FLD_size
, 0, 1, &field
);
2635 if (!extract_field_2 (&field
, inst
->value
, 0))
2637 inst
->operands
[0].qualifier
= AARCH64_OPND_QLF_S_S
;
2641 /* Decode the 'opc' field for e.g. FCVT <Dd>, <Sn>. */
2643 decode_fcvt (aarch64_inst
*inst
)
2645 enum aarch64_opnd_qualifier qualifier
;
2647 const aarch64_field field
= {15, 2};
2650 value
= extract_field_2 (&field
, inst
->value
, 0);
2653 case 0: qualifier
= AARCH64_OPND_QLF_S_S
; break;
2654 case 1: qualifier
= AARCH64_OPND_QLF_S_D
; break;
2655 case 3: qualifier
= AARCH64_OPND_QLF_S_H
; break;
2658 inst
->operands
[0].qualifier
= qualifier
;
2663 /* Do miscellaneous decodings that are not common enough to be driven by
2667 do_misc_decoding (aarch64_inst
*inst
)
2670 switch (inst
->opcode
->op
)
2673 return decode_fcvt (inst
);
2679 return decode_asimd_fcvt (inst
);
2682 return decode_asisd_fcvtxn (inst
);
2686 value
= extract_field (FLD_SVE_Pn
, inst
->value
, 0);
2687 return (value
== extract_field (FLD_SVE_Pm
, inst
->value
, 0)
2688 && value
== extract_field (FLD_SVE_Pg4_10
, inst
->value
, 0));
2691 return (extract_field (FLD_SVE_Zd
, inst
->value
, 0)
2692 == extract_field (FLD_SVE_Zm_16
, inst
->value
, 0));
2695 /* Index must be zero. */
2696 value
= extract_fields (inst
->value
, 0, 2, FLD_SVE_tszh
, FLD_imm5
);
2697 return value
> 0 && value
<= 16 && value
== (value
& -value
);
2700 return (extract_field (FLD_SVE_Zn
, inst
->value
, 0)
2701 == extract_field (FLD_SVE_Zm_16
, inst
->value
, 0));
2704 /* Index must be nonzero. */
2705 value
= extract_fields (inst
->value
, 0, 2, FLD_SVE_tszh
, FLD_imm5
);
2706 return value
> 0 && value
!= (value
& -value
);
2709 return (extract_field (FLD_SVE_Pd
, inst
->value
, 0)
2710 == extract_field (FLD_SVE_Pm
, inst
->value
, 0));
2712 case OP_MOVZS_P_P_P
:
2714 return (extract_field (FLD_SVE_Pn
, inst
->value
, 0)
2715 == extract_field (FLD_SVE_Pm
, inst
->value
, 0));
2717 case OP_NOTS_P_P_P_Z
:
2718 case OP_NOT_P_P_P_Z
:
2719 return (extract_field (FLD_SVE_Pm
, inst
->value
, 0)
2720 == extract_field (FLD_SVE_Pg4_10
, inst
->value
, 0));
2727 /* Opcodes that have fields shared by multiple operands are usually flagged
2728 with flags. In this function, we detect such flags, decode the related
2729 field(s) and store the information in one of the related operands. The
2730 'one' operand is not any operand but one of the operands that can
2731 accommadate all the information that has been decoded. */
2734 do_special_decoding (aarch64_inst
*inst
)
2738 /* Condition for truly conditional executed instructions, e.g. b.cond. */
2739 if (inst
->opcode
->flags
& F_COND
)
2741 value
= extract_field (FLD_cond2
, inst
->value
, 0);
2742 inst
->cond
= get_cond_from_value (value
);
2745 if (inst
->opcode
->flags
& F_SF
)
2747 idx
= select_operand_for_sf_field_coding (inst
->opcode
);
2748 value
= extract_field (FLD_sf
, inst
->value
, 0);
2749 inst
->operands
[idx
].qualifier
= get_greg_qualifier_from_value (value
);
2750 if (inst
->operands
[idx
].qualifier
== AARCH64_OPND_QLF_ERR
)
2752 if ((inst
->opcode
->flags
& F_N
)
2753 && extract_field (FLD_N
, inst
->value
, 0) != value
)
2757 if (inst
->opcode
->flags
& F_LSE_SZ
)
2759 idx
= select_operand_for_sf_field_coding (inst
->opcode
);
2760 value
= extract_field (FLD_lse_sz
, inst
->value
, 0);
2761 inst
->operands
[idx
].qualifier
= get_greg_qualifier_from_value (value
);
2762 if (inst
->operands
[idx
].qualifier
== AARCH64_OPND_QLF_ERR
)
2765 /* rcpc3 'size' field. */
2766 if (inst
->opcode
->flags
& F_RCPC3_SIZE
)
2768 value
= extract_field (FLD_rcpc3_size
, inst
->value
, 0);
2770 aarch64_operands
[inst
->operands
[i
].type
].op_class
!= AARCH64_OPND_CLASS_ADDRESS
;
2773 if (aarch64_operands
[inst
->operands
[i
].type
].op_class
2774 == AARCH64_OPND_CLASS_INT_REG
)
2776 inst
->operands
[i
].qualifier
= get_greg_qualifier_from_value (value
& 1);
2777 if (inst
->operands
[i
].qualifier
== AARCH64_OPND_QLF_ERR
)
2780 else if (aarch64_operands
[inst
->operands
[i
].type
].op_class
2781 == AARCH64_OPND_CLASS_FP_REG
)
2783 value
+= (extract_field (FLD_opc1
, inst
->value
, 0) << 2);
2784 inst
->operands
[i
].qualifier
= get_sreg_qualifier_from_value (value
);
2785 if (inst
->operands
[i
].qualifier
== AARCH64_OPND_QLF_ERR
)
2791 /* size:Q fields. */
2792 if (inst
->opcode
->flags
& F_SIZEQ
)
2793 return decode_sizeq (inst
);
2795 if (inst
->opcode
->flags
& F_FPTYPE
)
2797 idx
= select_operand_for_fptype_field_coding (inst
->opcode
);
2798 value
= extract_field (FLD_type
, inst
->value
, 0);
2801 case 0: inst
->operands
[idx
].qualifier
= AARCH64_OPND_QLF_S_S
; break;
2802 case 1: inst
->operands
[idx
].qualifier
= AARCH64_OPND_QLF_S_D
; break;
2803 case 3: inst
->operands
[idx
].qualifier
= AARCH64_OPND_QLF_S_H
; break;
2808 if (inst
->opcode
->flags
& F_SSIZE
)
2810 /* N.B. some opcodes like FCMGT <V><d>, <V><n>, #0 have the size[1] as part
2811 of the base opcode. */
2813 enum aarch64_opnd_qualifier candidates
[AARCH64_MAX_QLF_SEQ_NUM
];
2814 idx
= select_operand_for_scalar_size_field_coding (inst
->opcode
);
2815 value
= extract_field (FLD_size
, inst
->value
, inst
->opcode
->mask
);
2816 mask
= extract_field (FLD_size
, ~inst
->opcode
->mask
, 0);
2817 /* For most related instruciton, the 'size' field is fully available for
2818 operand encoding. */
2821 inst
->operands
[idx
].qualifier
= get_sreg_qualifier_from_value (value
);
2822 if (inst
->operands
[idx
].qualifier
== AARCH64_OPND_QLF_ERR
)
2827 get_operand_possible_qualifiers (idx
, inst
->opcode
->qualifiers_list
,
2829 inst
->operands
[idx
].qualifier
2830 = get_qualifier_from_partial_encoding (value
, candidates
, mask
);
2834 if (inst
->opcode
->flags
& F_T
)
2836 /* Num of consecutive '0's on the right side of imm5<3:0>. */
2839 assert (aarch64_get_operand_class (inst
->opcode
->operands
[0])
2840 == AARCH64_OPND_CLASS_SIMD_REG
);
2851 val
= extract_field (FLD_imm5
, inst
->value
, 0);
2852 while ((val
& 0x1) == 0 && ++num
<= 3)
2856 Q
= (unsigned) extract_field (FLD_Q
, inst
->value
, inst
->opcode
->mask
);
2857 inst
->operands
[0].qualifier
=
2858 get_vreg_qualifier_from_value ((num
<< 1) | Q
);
2859 if (inst
->operands
[0].qualifier
== AARCH64_OPND_QLF_ERR
)
2864 if ((inst
->opcode
->flags
& F_OPD_SIZE
) && inst
->opcode
->iclass
== sve2_urqvs
)
2867 size
= (unsigned) extract_field (FLD_size
, inst
->value
,
2868 inst
->opcode
->mask
);
2869 inst
->operands
[0].qualifier
2870 = get_vreg_qualifier_from_value (1 + (size
<< 1));
2871 if (inst
->operands
[0].qualifier
== AARCH64_OPND_QLF_ERR
)
2873 inst
->operands
[2].qualifier
= get_sreg_qualifier_from_value (size
);
2874 if (inst
->operands
[2].qualifier
== AARCH64_OPND_QLF_ERR
)
2878 if (inst
->opcode
->flags
& F_GPRSIZE_IN_Q
)
2880 /* Use Rt to encode in the case of e.g.
2881 STXP <Ws>, <Xt1>, <Xt2>, [<Xn|SP>{,#0}]. */
2882 idx
= aarch64_operand_index (inst
->opcode
->operands
, AARCH64_OPND_Rt
);
2885 /* Otherwise use the result operand, which has to be a integer
2887 assert (aarch64_get_operand_class (inst
->opcode
->operands
[0])
2888 == AARCH64_OPND_CLASS_INT_REG
);
2891 assert (idx
== 0 || idx
== 1);
2892 value
= extract_field (FLD_Q
, inst
->value
, 0);
2893 inst
->operands
[idx
].qualifier
= get_greg_qualifier_from_value (value
);
2894 if (inst
->operands
[idx
].qualifier
== AARCH64_OPND_QLF_ERR
)
2898 if (inst
->opcode
->flags
& F_LDS_SIZE
)
2900 aarch64_field field
= {0, 0};
2901 assert (aarch64_get_operand_class (inst
->opcode
->operands
[0])
2902 == AARCH64_OPND_CLASS_INT_REG
);
2903 gen_sub_field (FLD_opc
, 0, 1, &field
);
2904 value
= extract_field_2 (&field
, inst
->value
, 0);
2905 inst
->operands
[0].qualifier
2906 = value
? AARCH64_OPND_QLF_W
: AARCH64_OPND_QLF_X
;
2909 /* Miscellaneous decoding; done as the last step. */
2910 if (inst
->opcode
->flags
& F_MISC
)
2911 return do_misc_decoding (inst
);
2916 /* Converters converting a real opcode instruction to its alias form. */
2918 /* ROR <Wd>, <Ws>, #<shift>
2920 EXTR <Wd>, <Ws>, <Ws>, #<shift>. */
2922 convert_extr_to_ror (aarch64_inst
*inst
)
2924 if (inst
->operands
[1].reg
.regno
== inst
->operands
[2].reg
.regno
)
2926 copy_operand_info (inst
, 2, 3);
2927 inst
->operands
[3].type
= AARCH64_OPND_NIL
;
2933 /* UXTL<Q> <Vd>.<Ta>, <Vn>.<Tb>
2935 USHLL<Q> <Vd>.<Ta>, <Vn>.<Tb>, #0. */
2937 convert_shll_to_xtl (aarch64_inst
*inst
)
2939 if (inst
->operands
[2].imm
.value
== 0)
2941 inst
->operands
[2].type
= AARCH64_OPND_NIL
;
2948 UBFM <Xd>, <Xn>, #<shift>, #63.
2950 LSR <Xd>, <Xn>, #<shift>. */
2952 convert_bfm_to_sr (aarch64_inst
*inst
)
2956 imms
= inst
->operands
[3].imm
.value
;
2957 val
= inst
->operands
[2].qualifier
== AARCH64_OPND_QLF_imm_0_31
? 31 : 63;
2960 inst
->operands
[3].type
= AARCH64_OPND_NIL
;
2967 /* Convert MOV to ORR. */
2969 convert_orr_to_mov (aarch64_inst
*inst
)
2971 /* MOV <Vd>.<T>, <Vn>.<T>
2973 ORR <Vd>.<T>, <Vn>.<T>, <Vn>.<T>. */
2974 if (inst
->operands
[1].reg
.regno
== inst
->operands
[2].reg
.regno
)
2976 inst
->operands
[2].type
= AARCH64_OPND_NIL
;
2982 /* When <imms> >= <immr>, the instruction written:
2983 SBFX <Xd>, <Xn>, #<lsb>, #<width>
2985 SBFM <Xd>, <Xn>, #<lsb>, #(<lsb>+<width>-1). */
2988 convert_bfm_to_bfx (aarch64_inst
*inst
)
2992 immr
= inst
->operands
[2].imm
.value
;
2993 imms
= inst
->operands
[3].imm
.value
;
2997 inst
->operands
[2].imm
.value
= lsb
;
2998 inst
->operands
[3].imm
.value
= imms
+ 1 - lsb
;
2999 /* The two opcodes have different qualifiers for
3000 the immediate operands; reset to help the checking. */
3001 reset_operand_qualifier (inst
, 2);
3002 reset_operand_qualifier (inst
, 3);
3009 /* When <imms> < <immr>, the instruction written:
3010 SBFIZ <Xd>, <Xn>, #<lsb>, #<width>
3012 SBFM <Xd>, <Xn>, #((64-<lsb>)&0x3f), #(<width>-1). */
3015 convert_bfm_to_bfi (aarch64_inst
*inst
)
3017 int64_t immr
, imms
, val
;
3019 immr
= inst
->operands
[2].imm
.value
;
3020 imms
= inst
->operands
[3].imm
.value
;
3021 val
= inst
->operands
[2].qualifier
== AARCH64_OPND_QLF_imm_0_31
? 32 : 64;
3024 inst
->operands
[2].imm
.value
= (val
- immr
) & (val
- 1);
3025 inst
->operands
[3].imm
.value
= imms
+ 1;
3026 /* The two opcodes have different qualifiers for
3027 the immediate operands; reset to help the checking. */
3028 reset_operand_qualifier (inst
, 2);
3029 reset_operand_qualifier (inst
, 3);
3036 /* The instruction written:
3037 BFC <Xd>, #<lsb>, #<width>
3039 BFM <Xd>, XZR, #((64-<lsb>)&0x3f), #(<width>-1). */
3042 convert_bfm_to_bfc (aarch64_inst
*inst
)
3044 int64_t immr
, imms
, val
;
3046 /* Should have been assured by the base opcode value. */
3047 assert (inst
->operands
[1].reg
.regno
== 0x1f);
3049 immr
= inst
->operands
[2].imm
.value
;
3050 imms
= inst
->operands
[3].imm
.value
;
3051 val
= inst
->operands
[2].qualifier
== AARCH64_OPND_QLF_imm_0_31
? 32 : 64;
3054 /* Drop XZR from the second operand. */
3055 copy_operand_info (inst
, 1, 2);
3056 copy_operand_info (inst
, 2, 3);
3057 inst
->operands
[3].type
= AARCH64_OPND_NIL
;
3059 /* Recalculate the immediates. */
3060 inst
->operands
[1].imm
.value
= (val
- immr
) & (val
- 1);
3061 inst
->operands
[2].imm
.value
= imms
+ 1;
3063 /* The two opcodes have different qualifiers for the operands; reset to
3064 help the checking. */
3065 reset_operand_qualifier (inst
, 1);
3066 reset_operand_qualifier (inst
, 2);
3067 reset_operand_qualifier (inst
, 3);
3075 /* The instruction written:
3076 LSL <Xd>, <Xn>, #<shift>
3078 UBFM <Xd>, <Xn>, #((64-<shift>)&0x3f), #(63-<shift>). */
3081 convert_ubfm_to_lsl (aarch64_inst
*inst
)
3083 int64_t immr
= inst
->operands
[2].imm
.value
;
3084 int64_t imms
= inst
->operands
[3].imm
.value
;
3086 = inst
->operands
[2].qualifier
== AARCH64_OPND_QLF_imm_0_31
? 31 : 63;
3088 if ((immr
== 0 && imms
== val
) || immr
== imms
+ 1)
3090 inst
->operands
[3].type
= AARCH64_OPND_NIL
;
3091 inst
->operands
[2].imm
.value
= val
- imms
;
3098 /* CINC <Wd>, <Wn>, <cond>
3100 CSINC <Wd>, <Wn>, <Wn>, invert(<cond>)
3101 where <cond> is not AL or NV. */
3104 convert_from_csel (aarch64_inst
*inst
)
3106 if (inst
->operands
[1].reg
.regno
== inst
->operands
[2].reg
.regno
3107 && (inst
->operands
[3].cond
->value
& 0xe) != 0xe)
3109 copy_operand_info (inst
, 2, 3);
3110 inst
->operands
[2].cond
= get_inverted_cond (inst
->operands
[3].cond
);
3111 inst
->operands
[3].type
= AARCH64_OPND_NIL
;
3117 /* CSET <Wd>, <cond>
3119 CSINC <Wd>, WZR, WZR, invert(<cond>)
3120 where <cond> is not AL or NV. */
3123 convert_csinc_to_cset (aarch64_inst
*inst
)
3125 if (inst
->operands
[1].reg
.regno
== 0x1f
3126 && inst
->operands
[2].reg
.regno
== 0x1f
3127 && (inst
->operands
[3].cond
->value
& 0xe) != 0xe)
3129 copy_operand_info (inst
, 1, 3);
3130 inst
->operands
[1].cond
= get_inverted_cond (inst
->operands
[3].cond
);
3131 inst
->operands
[3].type
= AARCH64_OPND_NIL
;
3132 inst
->operands
[2].type
= AARCH64_OPND_NIL
;
3140 MOVZ <Wd>, #<imm16_5>, LSL #<shift>.
3142 A disassembler may output ORR, MOVZ and MOVN as a MOV mnemonic, except when
3143 ORR has an immediate that could be generated by a MOVZ or MOVN instruction,
3144 or where a MOVN has an immediate that could be encoded by MOVZ, or where
3145 MOVZ/MOVN #0 have a shift amount other than LSL #0, in which case the
3146 machine-instruction mnemonic must be used. */
3149 convert_movewide_to_mov (aarch64_inst
*inst
)
3151 uint64_t value
= inst
->operands
[1].imm
.value
;
3152 /* MOVZ/MOVN #0 have a shift amount other than LSL #0. */
3153 if (value
== 0 && inst
->operands
[1].shifter
.amount
!= 0)
3155 inst
->operands
[1].type
= AARCH64_OPND_IMM_MOV
;
3156 inst
->operands
[1].shifter
.kind
= AARCH64_MOD_NONE
;
3157 value
<<= inst
->operands
[1].shifter
.amount
;
3158 /* As an alias convertor, it has to be clear that the INST->OPCODE
3159 is the opcode of the real instruction. */
3160 if (inst
->opcode
->op
== OP_MOVN
)
3162 int is32
= inst
->operands
[0].qualifier
== AARCH64_OPND_QLF_W
;
3164 /* A MOVN has an immediate that could be encoded by MOVZ. */
3165 if (aarch64_wide_constant_p (value
, is32
, NULL
))
3168 inst
->operands
[1].imm
.value
= value
;
3169 inst
->operands
[1].shifter
.amount
= 0;
3175 ORR <Wd>, WZR, #<imm>.
3177 A disassembler may output ORR, MOVZ and MOVN as a MOV mnemonic, except when
3178 ORR has an immediate that could be generated by a MOVZ or MOVN instruction,
3179 or where a MOVN has an immediate that could be encoded by MOVZ, or where
3180 MOVZ/MOVN #0 have a shift amount other than LSL #0, in which case the
3181 machine-instruction mnemonic must be used. */
3184 convert_movebitmask_to_mov (aarch64_inst
*inst
)
3189 /* Should have been assured by the base opcode value. */
3190 assert (inst
->operands
[1].reg
.regno
== 0x1f);
3191 copy_operand_info (inst
, 1, 2);
3192 is32
= inst
->operands
[0].qualifier
== AARCH64_OPND_QLF_W
;
3193 inst
->operands
[1].type
= AARCH64_OPND_IMM_MOV
;
3194 value
= inst
->operands
[1].imm
.value
;
3195 /* ORR has an immediate that could be generated by a MOVZ or MOVN
3197 if (inst
->operands
[0].reg
.regno
!= 0x1f
3198 && (aarch64_wide_constant_p (value
, is32
, NULL
)
3199 || aarch64_wide_constant_p (~value
, is32
, NULL
)))
3202 inst
->operands
[2].type
= AARCH64_OPND_NIL
;
3206 /* Some alias opcodes are disassembled by being converted from their real-form.
3207 N.B. INST->OPCODE is the real opcode rather than the alias. */
3210 convert_to_alias (aarch64_inst
*inst
, const aarch64_opcode
*alias
)
3216 return convert_bfm_to_sr (inst
);
3218 return convert_ubfm_to_lsl (inst
);
3222 return convert_from_csel (inst
);
3225 return convert_csinc_to_cset (inst
);
3229 return convert_bfm_to_bfx (inst
);
3233 return convert_bfm_to_bfi (inst
);
3235 return convert_bfm_to_bfc (inst
);
3237 return convert_orr_to_mov (inst
);
3238 case OP_MOV_IMM_WIDE
:
3239 case OP_MOV_IMM_WIDEN
:
3240 return convert_movewide_to_mov (inst
);
3241 case OP_MOV_IMM_LOG
:
3242 return convert_movebitmask_to_mov (inst
);
3244 return convert_extr_to_ror (inst
);
3249 return convert_shll_to_xtl (inst
);
3256 aarch64_opcode_decode (const aarch64_opcode
*, const aarch64_insn
,
3257 aarch64_inst
*, int, aarch64_operand_error
*errors
);
3259 /* Given the instruction information in *INST, check if the instruction has
3260 any alias form that can be used to represent *INST. If the answer is yes,
3261 update *INST to be in the form of the determined alias. */
3263 /* In the opcode description table, the following flags are used in opcode
3264 entries to help establish the relations between the real and alias opcodes:
3266 F_ALIAS: opcode is an alias
3267 F_HAS_ALIAS: opcode has alias(es)
3270 F_P3: Disassembly preference priority 1-3 (the larger the
3271 higher). If nothing is specified, it is the priority
3272 0 by default, i.e. the lowest priority.
3274 Although the relation between the machine and the alias instructions are not
3275 explicitly described, it can be easily determined from the base opcode
3276 values, masks and the flags F_ALIAS and F_HAS_ALIAS in their opcode
3277 description entries:
3279 The mask of an alias opcode must be equal to or a super-set (i.e. more
3280 constrained) of that of the aliased opcode; so is the base opcode value.
3282 if (opcode_has_alias (real) && alias_opcode_p (opcode)
3283 && (opcode->mask & real->mask) == real->mask
3284 && (real->mask & opcode->opcode) == (real->mask & real->opcode))
3285 then OPCODE is an alias of, and only of, the REAL instruction
3287 The alias relationship is forced flat-structured to keep related algorithm
3288 simple; an opcode entry cannot be flagged with both F_ALIAS and F_HAS_ALIAS.
3290 During the disassembling, the decoding decision tree (in
3291 opcodes/aarch64-dis-2.c) always returns an machine instruction opcode entry;
3292 if the decoding of such a machine instruction succeeds (and -Mno-aliases is
3293 not specified), the disassembler will check whether there is any alias
3294 instruction exists for this real instruction. If there is, the disassembler
3295 will try to disassemble the 32-bit binary again using the alias's rule, or
3296 try to convert the IR to the form of the alias. In the case of the multiple
3297 aliases, the aliases are tried one by one from the highest priority
3298 (currently the flag F_P3) to the lowest priority (no priority flag), and the
3299 first succeeds first adopted.
3301 You may ask why there is a need for the conversion of IR from one form to
3302 another in handling certain aliases. This is because on one hand it avoids
3303 adding more operand code to handle unusual encoding/decoding; on other
3304 hand, during the disassembling, the conversion is an effective approach to
3305 check the condition of an alias (as an alias may be adopted only if certain
3306 conditions are met).
3308 In order to speed up the alias opcode lookup, aarch64-gen has preprocessed
3309 aarch64_opcode_table and generated aarch64_find_alias_opcode and
3310 aarch64_find_next_alias_opcode (in opcodes/aarch64-dis-2.c) to help. */
3313 determine_disassembling_preference (struct aarch64_inst
*inst
,
3314 aarch64_operand_error
*errors
)
3316 const aarch64_opcode
*opcode
;
3317 const aarch64_opcode
*alias
;
3319 opcode
= inst
->opcode
;
3321 /* This opcode does not have an alias, so use itself. */
3322 if (!opcode_has_alias (opcode
))
3325 alias
= aarch64_find_alias_opcode (opcode
);
3328 #ifdef DEBUG_AARCH64
3331 const aarch64_opcode
*tmp
= alias
;
3332 printf ("#### LIST orderd: ");
3335 printf ("%s, ", tmp
->name
);
3336 tmp
= aarch64_find_next_alias_opcode (tmp
);
3340 #endif /* DEBUG_AARCH64 */
3342 for (; alias
; alias
= aarch64_find_next_alias_opcode (alias
))
3344 DEBUG_TRACE ("try %s", alias
->name
);
3345 assert (alias_opcode_p (alias
) || opcode_has_alias (opcode
));
3347 /* An alias can be a pseudo opcode which will never be used in the
3348 disassembly, e.g. BIC logical immediate is such a pseudo opcode
3350 if (pseudo_opcode_p (alias
))
3352 DEBUG_TRACE ("skip pseudo %s", alias
->name
);
3356 if ((inst
->value
& alias
->mask
) != alias
->opcode
)
3358 DEBUG_TRACE ("skip %s as base opcode not match", alias
->name
);
3362 if (!AARCH64_CPU_HAS_ALL_FEATURES (arch_variant
, *alias
->avariant
))
3364 DEBUG_TRACE ("skip %s: we're missing features", alias
->name
);
3368 /* No need to do any complicated transformation on operands, if the alias
3369 opcode does not have any operand. */
3370 if (aarch64_num_of_operands (alias
) == 0 && alias
->opcode
== inst
->value
)
3372 DEBUG_TRACE ("succeed with 0-operand opcode %s", alias
->name
);
3373 aarch64_replace_opcode (inst
, alias
);
3376 if (alias
->flags
& F_CONV
)
3379 memcpy (©
, inst
, sizeof (aarch64_inst
));
3380 /* ALIAS is the preference as long as the instruction can be
3381 successfully converted to the form of ALIAS. */
3382 if (convert_to_alias (©
, alias
) == 1)
3384 aarch64_replace_opcode (©
, alias
);
3385 if (aarch64_match_operands_constraint (©
, NULL
) != 1)
3387 DEBUG_TRACE ("FAILED with alias %s ", alias
->name
);
3391 DEBUG_TRACE ("succeed with %s via conversion", alias
->name
);
3392 memcpy (inst
, ©
, sizeof (aarch64_inst
));
3399 /* Directly decode the alias opcode. */
3401 memset (&temp
, '\0', sizeof (aarch64_inst
));
3402 if (aarch64_opcode_decode (alias
, inst
->value
, &temp
, 1, errors
) == 1)
3404 DEBUG_TRACE ("succeed with %s via direct decoding", alias
->name
);
3405 memcpy (inst
, &temp
, sizeof (aarch64_inst
));
3412 /* Some instructions (including all SVE ones) use the instruction class
3413 to describe how a qualifiers_list index is represented in the instruction
3414 encoding. If INST is such an instruction, decode the appropriate fields
3415 and fill in the operand qualifiers accordingly. Return true if no
3416 problems are found. */
3419 aarch64_decode_variant_using_iclass (aarch64_inst
*inst
)
3424 switch (inst
->opcode
->iclass
)
3427 variant
= extract_fields (inst
->value
, 0, 2, FLD_SME_Q
, FLD_SME_size_22
);
3428 if (variant
>= 4 && variant
< 7)
3435 i
= extract_fields (inst
->value
, 0, 2, FLD_SME_tszh
, FLD_SME_tszl
);
3438 while ((i
& 1) == 0)
3446 i
= extract_field (FLD_SVE_tszh
, inst
->value
, 0);
3449 case sme_size_12_bh
:
3450 variant
= extract_field (FLD_S
, inst
->value
, 0);
3455 case sme_size_12_bhs
:
3456 variant
= extract_field (FLD_SME_size_12
, inst
->value
, 0);
3461 case sme_size_12_hs
:
3462 variant
= extract_field (FLD_SME_size_12
, inst
->value
, 0);
3463 if (variant
!= 1 && variant
!= 2)
3469 variant
= extract_field (FLD_SME_size_12
, inst
->value
, 0);
3475 variant
= extract_field (FLD_SME_size_22
, inst
->value
, 0);
3478 case sme_size_22_hsd
:
3479 variant
= extract_field (FLD_SME_size_22
, inst
->value
, 0);
3486 variant
= extract_field (FLD_SME_sz_23
, inst
->value
, 0);
3490 variant
= extract_fields (inst
->value
, 0, 2, FLD_size
, FLD_SVE_M_14
);
3494 i
= extract_field (FLD_imm5
, inst
->value
, 0);
3498 while ((i
& 1) == 0)
3506 /* Pick the smallest applicable element size. */
3507 if ((inst
->value
& 0x20600) == 0x600)
3509 else if ((inst
->value
& 0x20400) == 0x400)
3511 else if ((inst
->value
& 0x20000) == 0)
3518 /* .D is preferred over the other sizes in disassembly. */
3525 /* These instructions have only a single variant. */
3529 variant
= extract_fields (inst
->value
, 0, 2, FLD_size
, FLD_SVE_M_16
);
3533 variant
= extract_field (FLD_SVE_M_4
, inst
->value
, 0);
3536 case sve_shift_pred
:
3537 i
= extract_fields (inst
->value
, 0, 2, FLD_SVE_tszh
, FLD_SVE_tszl_8
);
3548 case sve_shift_unpred
:
3549 i
= extract_fields (inst
->value
, 0, 2, FLD_SVE_tszh
, FLD_SVE_tszl_19
);
3553 variant
= extract_field (FLD_size
, inst
->value
, 0);
3559 variant
= extract_field (FLD_size
, inst
->value
, 0);
3563 i
= extract_field (FLD_size
, inst
->value
, 0);
3573 variant
= extract_field (FLD_SVE_sz
, inst
->value
, 0);
3577 variant
= extract_field (FLD_SVE_sz2
, inst
->value
, 0);
3581 i
= extract_field (FLD_SVE_size
, inst
->value
, 0);
3588 /* Ignore low bit of this field since that is set in the opcode for
3589 instructions of this iclass. */
3590 i
= (extract_field (FLD_size
, inst
->value
, 0) & 2);
3594 case sve_shift_tsz_bhsd
:
3595 i
= extract_fields (inst
->value
, 0, 2, FLD_SVE_tszh
, FLD_SVE_tszl_19
);
3605 case sve_size_tsz_bhs
:
3606 i
= extract_fields (inst
->value
, 0, 2, FLD_SVE_sz
, FLD_SVE_tszl_19
);
3618 case sve_shift_tsz_hsd
:
3619 i
= extract_fields (inst
->value
, 0, 2, FLD_SVE_sz
, FLD_SVE_tszl_19
);
3630 /* No mapping between instruction class and qualifiers. */
3634 for (i
= 0; i
< AARCH64_MAX_OPND_NUM
; ++i
)
3635 inst
->operands
[i
].qualifier
= inst
->opcode
->qualifiers_list
[variant
][i
];
3638 /* Decode the CODE according to OPCODE; fill INST. Return 0 if the decoding
3639 fails, which meanes that CODE is not an instruction of OPCODE; otherwise
3642 If OPCODE has alias(es) and NOALIASES_P is 0, an alias opcode may be
3643 determined and used to disassemble CODE; this is done just before the
3647 aarch64_opcode_decode (const aarch64_opcode
*opcode
, const aarch64_insn code
,
3648 aarch64_inst
*inst
, int noaliases_p
,
3649 aarch64_operand_error
*errors
)
3653 DEBUG_TRACE ("enter with %s", opcode
->name
);
3655 assert (opcode
&& inst
);
3658 memset (inst
, '\0', sizeof (aarch64_inst
));
3660 /* Check the base opcode. */
3661 if ((code
& opcode
->mask
) != (opcode
->opcode
& opcode
->mask
))
3663 DEBUG_TRACE ("base opcode match FAIL");
3667 inst
->opcode
= opcode
;
3670 /* Assign operand codes and indexes. */
3671 for (i
= 0; i
< AARCH64_MAX_OPND_NUM
; ++i
)
3673 if (opcode
->operands
[i
] == AARCH64_OPND_NIL
)
3675 inst
->operands
[i
].type
= opcode
->operands
[i
];
3676 inst
->operands
[i
].idx
= i
;
3679 /* Call the opcode decoder indicated by flags. */
3680 if (opcode_has_special_coder (opcode
) && do_special_decoding (inst
) == 0)
3682 DEBUG_TRACE ("opcode flag-based decoder FAIL");
3686 /* Possibly use the instruction class to determine the correct
3688 if (!aarch64_decode_variant_using_iclass (inst
))
3690 DEBUG_TRACE ("iclass-based decoder FAIL");
3694 /* Call operand decoders. */
3695 for (i
= 0; i
< AARCH64_MAX_OPND_NUM
; ++i
)
3697 const aarch64_operand
*opnd
;
3698 enum aarch64_opnd type
;
3700 type
= opcode
->operands
[i
];
3701 if (type
== AARCH64_OPND_NIL
)
3703 opnd
= &aarch64_operands
[type
];
3704 if (operand_has_extractor (opnd
)
3705 && (! aarch64_extract_operand (opnd
, &inst
->operands
[i
], code
, inst
,
3708 DEBUG_TRACE ("operand decoder FAIL at operand %d", i
);
3713 /* If the opcode has a verifier, then check it now. */
3714 if (opcode
->verifier
3715 && opcode
->verifier (inst
, code
, 0, false, errors
, NULL
) != ERR_OK
)
3717 DEBUG_TRACE ("operand verifier FAIL");
3721 /* Match the qualifiers. */
3722 if (aarch64_match_operands_constraint (inst
, NULL
) == 1)
3724 /* Arriving here, the CODE has been determined as a valid instruction
3725 of OPCODE and *INST has been filled with information of this OPCODE
3726 instruction. Before the return, check if the instruction has any
3727 alias and should be disassembled in the form of its alias instead.
3728 If the answer is yes, *INST will be updated. */
3730 determine_disassembling_preference (inst
, errors
);
3731 DEBUG_TRACE ("SUCCESS");
3736 DEBUG_TRACE ("constraint matching FAIL");
3743 /* This does some user-friendly fix-up to *INST. It is currently focus on
3744 the adjustment of qualifiers to help the printed instruction
3745 recognized/understood more easily. */
3748 user_friendly_fixup (aarch64_inst
*inst
)
3750 switch (inst
->opcode
->iclass
)
3753 /* TBNZ Xn|Wn, #uimm6, label
3754 Test and Branch Not Zero: conditionally jumps to label if bit number
3755 uimm6 in register Xn is not zero. The bit number implies the width of
3756 the register, which may be written and should be disassembled as Wn if
3757 uimm is less than 32. Limited to a branch offset range of +/- 32KiB.
3759 if (inst
->operands
[1].imm
.value
< 32)
3760 inst
->operands
[0].qualifier
= AARCH64_OPND_QLF_W
;
3766 /* Decode INSN and fill in *INST the instruction information. An alias
3767 opcode may be filled in *INSN if NOALIASES_P is FALSE. Return zero on
3771 aarch64_decode_insn (aarch64_insn insn
, aarch64_inst
*inst
,
3773 aarch64_operand_error
*errors
)
3775 const aarch64_opcode
*opcode
= aarch64_opcode_lookup (insn
);
3777 #ifdef DEBUG_AARCH64
3780 const aarch64_opcode
*tmp
= opcode
;
3782 DEBUG_TRACE ("opcode lookup:");
3785 aarch64_verbose (" %s", tmp
->name
);
3786 tmp
= aarch64_find_next_opcode (tmp
);
3789 #endif /* DEBUG_AARCH64 */
3791 /* A list of opcodes may have been found, as aarch64_opcode_lookup cannot
3792 distinguish some opcodes, e.g. SSHR and MOVI, which almost share the same
3793 opcode field and value, apart from the difference that one of them has an
3794 extra field as part of the opcode, but such a field is used for operand
3795 encoding in other opcode(s) ('immh' in the case of the example). */
3796 while (opcode
!= NULL
)
3798 /* But only one opcode can be decoded successfully for, as the
3799 decoding routine will check the constraint carefully. */
3800 if (aarch64_opcode_decode (opcode
, insn
, inst
, noaliases_p
, errors
) == 1)
3802 opcode
= aarch64_find_next_opcode (opcode
);
3808 /* Return a short string to indicate a switch to STYLE. These strings
3809 will be embedded into the disassembled operand text (as produced by
3810 aarch64_print_operand), and then spotted in the print_operands function
3811 so that the disassembler output can be split by style. */
3814 get_style_text (enum disassembler_style style
)
3816 static bool init
= false;
3817 static char formats
[16][4];
3820 /* First time through we build a string for every possible format. This
3821 code relies on there being no more than 16 different styles (there's
3822 an assert below for this). */
3827 for (i
= 0; i
<= 0xf; ++i
)
3829 int res ATTRIBUTE_UNUSED
3830 = snprintf (&formats
[i
][0], sizeof (formats
[i
]), "%c%x%c",
3831 STYLE_MARKER_CHAR
, i
, STYLE_MARKER_CHAR
);
3838 /* Return the string that marks switching to STYLE. */
3839 num
= (unsigned) style
;
3840 assert (style
<= 0xf);
3841 return formats
[num
];
3844 /* Callback used by aarch64_print_operand to apply STYLE to the
3845 disassembler output created from FMT and ARGS. The STYLER object holds
3846 any required state. Must return a pointer to a string (created from FMT
3847 and ARGS) that will continue to be valid until the complete disassembled
3848 instruction has been printed.
3850 We return a string that includes two embedded style markers, the first,
3851 places at the start of the string, indicates a switch to STYLE, and the
3852 second, placed at the end of the string, indicates a switch back to the
3855 Later, when we print the operand text we take care to collapse any
3856 adjacent style markers, and to ignore any style markers that appear at
3857 the very end of a complete operand string. */
3859 static const char *aarch64_apply_style (struct aarch64_styler
*styler
,
3860 enum disassembler_style style
,
3866 struct obstack
*stack
= (struct obstack
*) styler
->state
;
3869 /* These are the two strings for switching styles. */
3870 const char *style_on
= get_style_text (style
);
3871 const char *style_off
= get_style_text (dis_style_text
);
3873 /* Calculate space needed once FMT and ARGS are expanded. */
3875 res
= vsnprintf (NULL
, 0, fmt
, ap
);
3879 /* Allocate space on the obstack for the expanded FMT and ARGS, as well
3880 as the two strings for switching styles, then write all of these
3881 strings onto the obstack. */
3882 ptr
= (char *) obstack_alloc (stack
, res
+ strlen (style_on
)
3883 + strlen (style_off
) + 1);
3884 tmp
= stpcpy (ptr
, style_on
);
3885 res
= vsnprintf (tmp
, (res
+ 1), fmt
, args
);
3888 strcpy (tmp
, style_off
);
3893 /* Print operands. */
3896 print_operands (bfd_vma pc
, const aarch64_opcode
*opcode
,
3897 const aarch64_opnd_info
*opnds
, struct disassemble_info
*info
,
3901 int i
, pcrel_p
, num_printed
;
3902 struct aarch64_styler styler
;
3903 struct obstack content
;
3904 obstack_init (&content
);
3906 styler
.apply_style
= aarch64_apply_style
;
3907 styler
.state
= (void *) &content
;
3909 for (i
= 0, num_printed
= 0; i
< AARCH64_MAX_OPND_NUM
; ++i
)
3914 /* We regard the opcode operand info more, however we also look into
3915 the inst->operands to support the disassembling of the optional
3917 The two operand code should be the same in all cases, apart from
3918 when the operand can be optional. */
3919 if (opcode
->operands
[i
] == AARCH64_OPND_NIL
3920 || opnds
[i
].type
== AARCH64_OPND_NIL
)
3923 /* Generate the operand string in STR. */
3924 aarch64_print_operand (str
, sizeof (str
), pc
, opcode
, opnds
, i
, &pcrel_p
,
3925 &info
->target
, ¬es
, cmt
, sizeof (cmt
),
3926 arch_variant
, &styler
);
3928 /* Print the delimiter (taking account of omitted operand(s)). */
3930 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
, "%s",
3931 num_printed
++ == 0 ? "\t" : ", ");
3933 /* Print the operand. */
3935 (*info
->print_address_func
) (info
->target
, info
);
3938 /* This operand came from aarch64_print_operand, and will include
3939 embedded strings indicating which style each character should
3940 have. In the following code we split the text based on
3941 CURR_STYLE, and call the styled print callback to print each
3942 block of text in the appropriate style. */
3944 enum disassembler_style curr_style
= dis_style_text
;
3950 || (*curr
== STYLE_MARKER_CHAR
3951 && ISXDIGIT (*(curr
+ 1))
3952 && *(curr
+ 2) == STYLE_MARKER_CHAR
))
3954 /* Output content between our START position and CURR. */
3955 int len
= curr
- start
;
3958 if ((*info
->fprintf_styled_func
) (info
->stream
,
3968 /* Skip over the initial STYLE_MARKER_CHAR. */
3971 /* Update the CURR_STYLE. As there are less than 16
3972 styles, it is possible, that if the input is corrupted
3973 in some way, that we might set CURR_STYLE to an
3974 invalid value. Don't worry though, we check for this
3976 if (*curr
>= '0' && *curr
<= '9')
3977 curr_style
= (enum disassembler_style
) (*curr
- '0');
3978 else if (*curr
>= 'a' && *curr
<= 'f')
3979 curr_style
= (enum disassembler_style
) (*curr
- 'a' + 10);
3981 curr_style
= dis_style_text
;
3983 /* Check for an invalid style having been selected. This
3984 should never happen, but it doesn't hurt to be a
3986 if (curr_style
> dis_style_comment_start
)
3987 curr_style
= dis_style_text
;
3989 /* Skip the hex character, and the closing STYLE_MARKER_CHAR. */
3992 /* Reset the START to after the style marker. */
4001 /* Print the comment. This works because only the last operand ever
4002 adds a comment. If that ever changes then we'll need to be
4005 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_comment_start
,
4009 if (notes
&& !no_notes
)
4012 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_comment_start
,
4013 " // note: %s", notes
);
4016 obstack_free (&content
, NULL
);
4019 /* Set NAME to a copy of INST's mnemonic with the "." suffix removed. */
4022 remove_dot_suffix (char *name
, const aarch64_inst
*inst
)
4027 ptr
= strchr (inst
->opcode
->name
, '.');
4028 assert (ptr
&& inst
->cond
);
4029 len
= ptr
- inst
->opcode
->name
;
4031 strncpy (name
, inst
->opcode
->name
, len
);
4035 /* Print the instruction mnemonic name. */
4038 print_mnemonic_name (const aarch64_inst
*inst
, struct disassemble_info
*info
)
4040 if (inst
->opcode
->flags
& F_COND
)
4042 /* For instructions that are truly conditionally executed, e.g. b.cond,
4043 prepare the full mnemonic name with the corresponding condition
4047 remove_dot_suffix (name
, inst
);
4048 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_mnemonic
,
4049 "%s.%s", name
, inst
->cond
->names
[0]);
4052 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_mnemonic
,
4053 "%s", inst
->opcode
->name
);
4056 /* Decide whether we need to print a comment after the operands of
4057 instruction INST. */
4060 print_comment (const aarch64_inst
*inst
, struct disassemble_info
*info
)
4062 if (inst
->opcode
->flags
& F_COND
)
4065 unsigned int i
, num_conds
;
4067 remove_dot_suffix (name
, inst
);
4068 num_conds
= ARRAY_SIZE (inst
->cond
->names
);
4069 for (i
= 1; i
< num_conds
&& inst
->cond
->names
[i
]; ++i
)
4070 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_comment_start
,
4072 i
== 1 ? " //" : ",",
4073 name
, inst
->cond
->names
[i
]);
4077 /* Build notes from verifiers into a string for printing. */
4080 print_verifier_notes (aarch64_operand_error
*detail
,
4081 struct disassemble_info
*info
)
4086 /* The output of the verifier cannot be a fatal error, otherwise the assembly
4087 would not have succeeded. We can safely ignore these. */
4088 assert (detail
->non_fatal
);
4090 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_comment_start
,
4092 switch (detail
->kind
)
4094 case AARCH64_OPDE_A_SHOULD_FOLLOW_B
:
4095 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
,
4096 _("this `%s' should have an immediately"
4098 detail
->data
[0].s
, detail
->data
[1].s
);
4101 case AARCH64_OPDE_EXPECTED_A_AFTER_B
:
4102 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
,
4103 _("expected `%s' after previous `%s'"),
4104 detail
->data
[0].s
, detail
->data
[1].s
);
4108 assert (detail
->error
);
4109 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
,
4110 "%s", detail
->error
);
4111 if (detail
->index
>= 0)
4112 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_text
,
4113 " at operand %d", detail
->index
+ 1);
4118 /* Print the instruction according to *INST. */
4121 print_aarch64_insn (bfd_vma pc
, const aarch64_inst
*inst
,
4122 const aarch64_insn code
,
4123 struct disassemble_info
*info
,
4124 aarch64_operand_error
*mismatch_details
)
4126 bool has_notes
= false;
4128 print_mnemonic_name (inst
, info
);
4129 print_operands (pc
, inst
->opcode
, inst
->operands
, info
, &has_notes
);
4130 print_comment (inst
, info
);
4132 /* We've already printed a note, not enough space to print more so exit.
4133 Usually notes shouldn't overlap so it shouldn't happen that we have a note
4134 from a register and instruction at the same time. */
4138 /* Always run constraint verifiers, this is needed because constraints need to
4139 maintain a global state regardless of whether the instruction has the flag
4141 enum err_type result
= verify_constraints (inst
, code
, pc
, false,
4142 mismatch_details
, &insn_sequence
);
4146 print_verifier_notes (mismatch_details
, info
);
4156 /* Entry-point of the instruction disassembler and printer. */
4159 print_insn_aarch64_word (bfd_vma pc
,
4161 struct disassemble_info
*info
,
4162 aarch64_operand_error
*errors
)
4164 static const char *err_msg
[ERR_NR_ENTRIES
+1] =
4167 [ERR_UND
] = "undefined",
4168 [ERR_UNP
] = "unpredictable",
4175 info
->insn_info_valid
= 1;
4176 info
->branch_delay_insns
= 0;
4177 info
->data_size
= 0;
4181 if (info
->flags
& INSN_HAS_RELOC
)
4182 /* If the instruction has a reloc associated with it, then
4183 the offset field in the instruction will actually be the
4184 addend for the reloc. (If we are using REL type relocs).
4185 In such cases, we can ignore the pc when computing
4186 addresses, since the addend is not currently pc-relative. */
4189 ret
= aarch64_decode_insn (word
, &inst
, no_aliases
, errors
);
4191 if (((word
>> 21) & 0x3ff) == 1)
4193 /* RESERVED for ALES. */
4194 assert (ret
!= ERR_OK
);
4203 /* Handle undefined instructions. */
4204 info
->insn_type
= dis_noninsn
;
4205 (*info
->fprintf_styled_func
) (info
->stream
,
4206 dis_style_assembler_directive
,
4208 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_immediate
,
4210 (*info
->fprintf_styled_func
) (info
->stream
, dis_style_comment_start
,
4211 " ; %s", err_msg
[ret
]);
4214 user_friendly_fixup (&inst
);
4215 if (inst
.opcode
->iclass
== condbranch
4216 || inst
.opcode
->iclass
== testbranch
4217 || inst
.opcode
->iclass
== compbranch
)
4218 info
->insn_type
= dis_condbranch
;
4219 else if (inst
.opcode
->iclass
== branch_imm
)
4220 info
->insn_type
= dis_jsr
;
4221 print_aarch64_insn (pc
, &inst
, word
, info
, errors
);
4228 /* Disallow mapping symbols ($x, $d etc) from
4229 being displayed in symbol relative addresses. */
4232 aarch64_symbol_is_valid (asymbol
* sym
,
4233 struct disassemble_info
* info ATTRIBUTE_UNUSED
)
4240 name
= bfd_asymbol_name (sym
);
4244 || (name
[1] != 'x' && name
[1] != 'd')
4245 || (name
[2] != '\0' && name
[2] != '.'));
4248 /* Print data bytes on INFO->STREAM. */
4251 print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED
,
4253 struct disassemble_info
*info
,
4254 aarch64_operand_error
*errors ATTRIBUTE_UNUSED
)
4256 switch (info
->bytes_per_chunk
)
4259 info
->fprintf_styled_func (info
->stream
, dis_style_assembler_directive
,
4261 info
->fprintf_styled_func (info
->stream
, dis_style_immediate
,
4265 info
->fprintf_styled_func (info
->stream
, dis_style_assembler_directive
,
4267 info
->fprintf_styled_func (info
->stream
, dis_style_immediate
,
4271 info
->fprintf_styled_func (info
->stream
, dis_style_assembler_directive
,
4273 info
->fprintf_styled_func (info
->stream
, dis_style_immediate
,
4281 /* Try to infer the code or data type from a symbol.
4282 Returns nonzero if *MAP_TYPE was set. */
4285 get_sym_code_type (struct disassemble_info
*info
, int n
,
4286 enum map_type
*map_type
)
4289 elf_symbol_type
*es
;
4293 /* If the symbol is in a different section, ignore it. */
4294 if (info
->section
!= NULL
&& info
->section
!= info
->symtab
[n
]->section
)
4297 if (n
>= info
->symtab_size
)
4300 as
= info
->symtab
[n
];
4301 if (bfd_asymbol_flavour (as
) != bfd_target_elf_flavour
)
4303 es
= (elf_symbol_type
*) as
;
4305 type
= ELF_ST_TYPE (es
->internal_elf_sym
.st_info
);
4307 /* If the symbol has function type then use that. */
4308 if (type
== STT_FUNC
)
4310 *map_type
= MAP_INSN
;
4314 /* Check for mapping symbols. */
4315 name
= bfd_asymbol_name(info
->symtab
[n
]);
4317 && (name
[1] == 'x' || name
[1] == 'd')
4318 && (name
[2] == '\0' || name
[2] == '.'))
4320 *map_type
= (name
[1] == 'x' ? MAP_INSN
: MAP_DATA
);
4327 /* Set the feature bits in arch_variant in order to get the correct disassembly
4328 for the chosen architecture variant.
4330 Currently we only restrict disassembly for Armv8-R and otherwise enable all
4331 non-R-profile features. */
4333 select_aarch64_variant (unsigned mach
)
4337 case bfd_mach_aarch64_8R
:
4338 AARCH64_SET_FEATURE (arch_variant
, AARCH64_ARCH_V8R
);
4341 arch_variant
= (aarch64_feature_set
) AARCH64_ALL_FEATURES
;
4342 AARCH64_CLEAR_FEATURE (arch_variant
, arch_variant
, V8R
);
4346 /* Entry-point of the AArch64 disassembler. */
4349 print_insn_aarch64 (bfd_vma pc
,
4350 struct disassemble_info
*info
)
4352 bfd_byte buffer
[INSNLEN
];
4354 void (*printer
) (bfd_vma
, uint32_t, struct disassemble_info
*,
4355 aarch64_operand_error
*);
4357 unsigned int size
= 4;
4359 aarch64_operand_error errors
;
4360 static bool set_features
;
4362 if (info
->disassembler_options
)
4364 set_default_aarch64_dis_options (info
);
4366 parse_aarch64_dis_options (info
->disassembler_options
);
4368 /* To avoid repeated parsing of these options, we remove them here. */
4369 info
->disassembler_options
= NULL
;
4374 select_aarch64_variant (info
->mach
);
4375 set_features
= true;
4378 /* Aarch64 instructions are always little-endian */
4379 info
->endian_code
= BFD_ENDIAN_LITTLE
;
4381 /* Default to DATA. A text section is required by the ABI to contain an
4382 INSN mapping symbol at the start. A data section has no such
4383 requirement, hence if no mapping symbol is found the section must
4384 contain only data. This however isn't very useful if the user has
4385 fully stripped the binaries. If this is the case use the section
4386 attributes to determine the default. If we have no section default to
4387 INSN as well, as we may be disassembling some raw bytes on a baremetal
4388 HEX file or similar. */
4389 enum map_type type
= MAP_DATA
;
4390 if ((info
->section
&& info
->section
->flags
& SEC_CODE
) || !info
->section
)
4393 /* First check the full symtab for a mapping symbol, even if there
4394 are no usable non-mapping symbols for this address. */
4395 if (info
->symtab_size
!= 0
4396 && bfd_asymbol_flavour (*info
->symtab
) == bfd_target_elf_flavour
)
4399 bfd_vma addr
, section_vma
= 0;
4400 bool can_use_search_opt_p
;
4403 if (pc
<= last_mapping_addr
)
4404 last_mapping_sym
= -1;
4406 /* Start scanning at the start of the function, or wherever
4407 we finished last time. */
4408 n
= info
->symtab_pos
+ 1;
4410 /* If the last stop offset is different from the current one it means we
4411 are disassembling a different glob of bytes. As such the optimization
4412 would not be safe and we should start over. */
4413 can_use_search_opt_p
= last_mapping_sym
>= 0
4414 && info
->stop_offset
== last_stop_offset
;
4416 if (n
>= last_mapping_sym
&& can_use_search_opt_p
)
4417 n
= last_mapping_sym
;
4419 /* Look down while we haven't passed the location being disassembled.
4420 The reason for this is that there's no defined order between a symbol
4421 and an mapping symbol that may be at the same address. We may have to
4422 look at least one position ahead. */
4423 for (; n
< info
->symtab_size
; n
++)
4425 addr
= bfd_asymbol_value (info
->symtab
[n
]);
4428 if (get_sym_code_type (info
, n
, &type
))
4437 n
= info
->symtab_pos
;
4438 if (n
>= last_mapping_sym
&& can_use_search_opt_p
)
4439 n
= last_mapping_sym
;
4441 /* No mapping symbol found at this address. Look backwards
4442 for a preceeding one, but don't go pass the section start
4443 otherwise a data section with no mapping symbol can pick up
4444 a text mapping symbol of a preceeding section. The documentation
4445 says section can be NULL, in which case we will seek up all the
4448 section_vma
= info
->section
->vma
;
4452 addr
= bfd_asymbol_value (info
->symtab
[n
]);
4453 if (addr
< section_vma
)
4456 if (get_sym_code_type (info
, n
, &type
))
4465 last_mapping_sym
= last_sym
;
4467 last_stop_offset
= info
->stop_offset
;
4469 /* Look a little bit ahead to see if we should print out
4470 less than four bytes of data. If there's a symbol,
4471 mapping or otherwise, after two bytes then don't
4473 if (last_type
== MAP_DATA
)
4475 size
= 4 - (pc
& 3);
4476 for (n
= last_sym
+ 1; n
< info
->symtab_size
; n
++)
4478 addr
= bfd_asymbol_value (info
->symtab
[n
]);
4481 if (addr
- pc
< size
)
4486 /* If the next symbol is after three bytes, we need to
4487 print only part of the data, so that we can use either
4490 size
= (pc
& 1) ? 1 : 2;
4496 /* PR 10263: Disassemble data if requested to do so by the user. */
4497 if (last_type
== MAP_DATA
&& ((info
->flags
& DISASSEMBLE_DATA
) == 0))
4499 /* size was set above. */
4500 info
->bytes_per_chunk
= size
;
4501 info
->display_endian
= info
->endian
;
4502 printer
= print_insn_data
;
4506 info
->bytes_per_chunk
= size
= INSNLEN
;
4507 info
->display_endian
= info
->endian_code
;
4508 printer
= print_insn_aarch64_word
;
4511 status
= (*info
->read_memory_func
) (pc
, buffer
, size
, info
);
4514 (*info
->memory_error_func
) (status
, pc
, info
);
4518 data
= bfd_get_bits (buffer
, size
* 8,
4519 info
->display_endian
== BFD_ENDIAN_BIG
);
4521 (*printer
) (pc
, data
, info
, &errors
);
4527 print_aarch64_disassembler_options (FILE *stream
)
4529 fprintf (stream
, _("\n\
4530 The following AARCH64 specific disassembler options are supported for use\n\
4531 with the -M switch (multiple options should be separated by commas):\n"));
4533 fprintf (stream
, _("\n\
4534 no-aliases Don't print instruction aliases.\n"));
4536 fprintf (stream
, _("\n\
4537 aliases Do print instruction aliases.\n"));
4539 fprintf (stream
, _("\n\
4540 no-notes Don't print instruction notes.\n"));
4542 fprintf (stream
, _("\n\
4543 notes Do print instruction notes.\n"));
4545 #ifdef DEBUG_AARCH64
4546 fprintf (stream
, _("\n\
4547 debug_dump Temp switch for debug trace.\n"));
4548 #endif /* DEBUG_AARCH64 */
4550 fprintf (stream
, _("\n"));