1 /* tc-aarch64.c -- Assemble for the AArch64 ISA
3 Copyright (C) 2009-2022 Free Software Foundation, Inc.
4 Contributed by ARM Ltd.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the license, or
11 (at your option) any later version.
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING3. If not,
20 see <http://www.gnu.org/licenses/>. */
27 #include "safe-ctype.h"
32 #include "elf/aarch64.h"
33 #include "dw2gencfi.h"
36 #include "dwarf2dbg.h"
38 /* Types of processor to assemble for. */
40 #define CPU_DEFAULT AARCH64_ARCH_V8
43 #define streq(a, b) (strcmp (a, b) == 0)
45 #define END_OF_INSN '\0'
47 static aarch64_feature_set cpu_variant
;
49 /* Variables that we set while parsing command-line options. Once all
50 options have been read we re-process these values to set the real
52 static const aarch64_feature_set
*mcpu_cpu_opt
= NULL
;
53 static const aarch64_feature_set
*march_cpu_opt
= NULL
;
55 /* Constants for known architecture features. */
56 static const aarch64_feature_set cpu_default
= CPU_DEFAULT
;
58 /* Currently active instruction sequence. */
59 static aarch64_instr_sequence
*insn_sequence
= NULL
;
62 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
63 static symbolS
*GOT_symbol
;
65 /* Which ABI to use. */
74 #define DEFAULT_ARCH "aarch64"
77 /* DEFAULT_ARCH is initialized in gas/configure.tgt. */
78 static const char *default_arch
= DEFAULT_ARCH
;
80 /* AArch64 ABI for the output file. */
81 static enum aarch64_abi_type aarch64_abi
= AARCH64_ABI_NONE
;
83 /* When non-zero, program to a 32-bit model, in which the C data types
84 int, long and all pointer types are 32-bit objects (ILP32); or to a
85 64-bit model, in which the C int type is 32-bits but the C long type
86 and all pointer types are 64-bit objects (LP64). */
87 #define ilp32_p (aarch64_abi == AARCH64_ABI_ILP32)
102 /* SME horizontal or vertical slice indicator, encoded in "V".
113 /* Bits for DEFINED field in vector_type_el. */
114 #define NTA_HASTYPE 1
115 #define NTA_HASINDEX 2
116 #define NTA_HASVARWIDTH 4
118 struct vector_type_el
120 enum vector_el_type type
;
121 unsigned char defined
;
126 #define FIXUP_F_HAS_EXPLICIT_SHIFT 0x00000001
130 bfd_reloc_code_real_type type
;
133 enum aarch64_opnd opnd
;
135 unsigned need_libopcodes_p
: 1;
138 struct aarch64_instruction
140 /* libopcodes structure for instruction intermediate representation. */
142 /* Record assembly errors found during the parsing. */
145 enum aarch64_operand_error_kind kind
;
148 /* The condition that appears in the assembly line. */
150 /* Relocation information (including the GAS internal fixup). */
152 /* Need to generate an immediate in the literal pool. */
153 unsigned gen_lit_pool
: 1;
156 typedef struct aarch64_instruction aarch64_instruction
;
158 static aarch64_instruction inst
;
160 static bool parse_operands (char *, const aarch64_opcode
*);
161 static bool programmer_friendly_fixup (aarch64_instruction
*);
163 /* Diagnostics inline function utilities.
165 These are lightweight utilities which should only be called by parse_operands
166 and other parsers. GAS processes each assembly line by parsing it against
167 instruction template(s), in the case of multiple templates (for the same
168 mnemonic name), those templates are tried one by one until one succeeds or
169 all fail. An assembly line may fail a few templates before being
170 successfully parsed; an error saved here in most cases is not a user error
171 but an error indicating the current template is not the right template.
172 Therefore it is very important that errors can be saved at a low cost during
173 the parsing; we don't want to slow down the whole parsing by recording
174 non-user errors in detail.
176 Remember that the objective is to help GAS pick up the most appropriate
177 error message in the case of multiple templates, e.g. FMOV which has 8
183 inst
.parsing_error
.kind
= AARCH64_OPDE_NIL
;
184 inst
.parsing_error
.error
= NULL
;
190 return inst
.parsing_error
.kind
!= AARCH64_OPDE_NIL
;
193 static inline const char *
194 get_error_message (void)
196 return inst
.parsing_error
.error
;
199 static inline enum aarch64_operand_error_kind
200 get_error_kind (void)
202 return inst
.parsing_error
.kind
;
206 set_error (enum aarch64_operand_error_kind kind
, const char *error
)
208 inst
.parsing_error
.kind
= kind
;
209 inst
.parsing_error
.error
= error
;
213 set_recoverable_error (const char *error
)
215 set_error (AARCH64_OPDE_RECOVERABLE
, error
);
218 /* Use the DESC field of the corresponding aarch64_operand entry to compose
219 the error message. */
221 set_default_error (void)
223 set_error (AARCH64_OPDE_SYNTAX_ERROR
, NULL
);
227 set_syntax_error (const char *error
)
229 set_error (AARCH64_OPDE_SYNTAX_ERROR
, error
);
233 set_first_syntax_error (const char *error
)
236 set_error (AARCH64_OPDE_SYNTAX_ERROR
, error
);
240 set_fatal_syntax_error (const char *error
)
242 set_error (AARCH64_OPDE_FATAL_SYNTAX_ERROR
, error
);
245 /* Return value for certain parsers when the parsing fails; those parsers
246 return the information of the parsed result, e.g. register number, on
248 #define PARSE_FAIL -1
250 /* This is an invalid condition code that means no conditional field is
252 #define COND_ALWAYS 0x10
256 const char *template;
263 bfd_reloc_code_real_type reloc
;
266 /* Macros to define the register types and masks for the purpose
269 #undef AARCH64_REG_TYPES
270 #define AARCH64_REG_TYPES \
271 BASIC_REG_TYPE(R_32) /* w[0-30] */ \
272 BASIC_REG_TYPE(R_64) /* x[0-30] */ \
273 BASIC_REG_TYPE(SP_32) /* wsp */ \
274 BASIC_REG_TYPE(SP_64) /* sp */ \
275 BASIC_REG_TYPE(Z_32) /* wzr */ \
276 BASIC_REG_TYPE(Z_64) /* xzr */ \
277 BASIC_REG_TYPE(FP_B) /* b[0-31] *//* NOTE: keep FP_[BHSDQ] consecutive! */\
278 BASIC_REG_TYPE(FP_H) /* h[0-31] */ \
279 BASIC_REG_TYPE(FP_S) /* s[0-31] */ \
280 BASIC_REG_TYPE(FP_D) /* d[0-31] */ \
281 BASIC_REG_TYPE(FP_Q) /* q[0-31] */ \
282 BASIC_REG_TYPE(VN) /* v[0-31] */ \
283 BASIC_REG_TYPE(ZN) /* z[0-31] */ \
284 BASIC_REG_TYPE(PN) /* p[0-15] */ \
285 BASIC_REG_TYPE(ZA) /* za[0-15] */ \
286 BASIC_REG_TYPE(ZAH) /* za[0-15]h */ \
287 BASIC_REG_TYPE(ZAV) /* za[0-15]v */ \
288 /* Typecheck: any 64-bit int reg (inc SP exc XZR). */ \
289 MULTI_REG_TYPE(R64_SP, REG_TYPE(R_64) | REG_TYPE(SP_64)) \
290 /* Typecheck: same, plus SVE registers. */ \
291 MULTI_REG_TYPE(SVE_BASE, REG_TYPE(R_64) | REG_TYPE(SP_64) \
293 /* Typecheck: x[0-30], w[0-30] or [xw]zr. */ \
294 MULTI_REG_TYPE(R_Z, REG_TYPE(R_32) | REG_TYPE(R_64) \
295 | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \
296 /* Typecheck: same, plus SVE registers. */ \
297 MULTI_REG_TYPE(SVE_OFFSET, REG_TYPE(R_32) | REG_TYPE(R_64) \
298 | REG_TYPE(Z_32) | REG_TYPE(Z_64) \
300 /* Typecheck: x[0-30], w[0-30] or {w}sp. */ \
301 MULTI_REG_TYPE(R_SP, REG_TYPE(R_32) | REG_TYPE(R_64) \
302 | REG_TYPE(SP_32) | REG_TYPE(SP_64)) \
303 /* Typecheck: any int (inc {W}SP inc [WX]ZR). */ \
304 MULTI_REG_TYPE(R_Z_SP, REG_TYPE(R_32) | REG_TYPE(R_64) \
305 | REG_TYPE(SP_32) | REG_TYPE(SP_64) \
306 | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \
307 /* Typecheck: any [BHSDQ]P FP. */ \
308 MULTI_REG_TYPE(BHSDQ, REG_TYPE(FP_B) | REG_TYPE(FP_H) \
309 | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q)) \
310 /* Typecheck: any int or [BHSDQ]P FP or V reg (exc SP inc [WX]ZR). */ \
311 MULTI_REG_TYPE(R_Z_BHSDQ_V, REG_TYPE(R_32) | REG_TYPE(R_64) \
312 | REG_TYPE(Z_32) | REG_TYPE(Z_64) | REG_TYPE(VN) \
313 | REG_TYPE(FP_B) | REG_TYPE(FP_H) \
314 | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q)) \
315 /* Typecheck: as above, but also Zn, Pn, and {W}SP. This should only \
316 be used for SVE instructions, since Zn and Pn are valid symbols \
317 in other contexts. */ \
318 MULTI_REG_TYPE(R_Z_SP_BHSDQ_VZP, REG_TYPE(R_32) | REG_TYPE(R_64) \
319 | REG_TYPE(SP_32) | REG_TYPE(SP_64) \
320 | REG_TYPE(Z_32) | REG_TYPE(Z_64) | REG_TYPE(VN) \
321 | REG_TYPE(FP_B) | REG_TYPE(FP_H) \
322 | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q) \
323 | REG_TYPE(ZN) | REG_TYPE(PN)) \
324 /* Any integer register; used for error messages only. */ \
325 MULTI_REG_TYPE(R_N, REG_TYPE(R_32) | REG_TYPE(R_64) \
326 | REG_TYPE(SP_32) | REG_TYPE(SP_64) \
327 | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \
328 /* Pseudo type to mark the end of the enumerator sequence. */ \
331 #undef BASIC_REG_TYPE
332 #define BASIC_REG_TYPE(T) REG_TYPE_##T,
333 #undef MULTI_REG_TYPE
334 #define MULTI_REG_TYPE(T,V) BASIC_REG_TYPE(T)
336 /* Register type enumerators. */
337 typedef enum aarch64_reg_type_
339 /* A list of REG_TYPE_*. */
343 #undef BASIC_REG_TYPE
344 #define BASIC_REG_TYPE(T) 1 << REG_TYPE_##T,
346 #define REG_TYPE(T) (1 << REG_TYPE_##T)
347 #undef MULTI_REG_TYPE
348 #define MULTI_REG_TYPE(T,V) V,
350 /* Structure for a hash table entry for a register. */
354 unsigned char number
;
355 ENUM_BITFIELD (aarch64_reg_type_
) type
: 8;
356 unsigned char builtin
;
359 /* Values indexed by aarch64_reg_type to assist the type checking. */
360 static const unsigned reg_type_masks
[] =
365 #undef BASIC_REG_TYPE
367 #undef MULTI_REG_TYPE
368 #undef AARCH64_REG_TYPES
370 /* Diagnostics used when we don't get a register of the expected type.
371 Note: this has to synchronized with aarch64_reg_type definitions
374 get_reg_expected_msg (aarch64_reg_type reg_type
)
381 msg
= N_("integer 32-bit register expected");
384 msg
= N_("integer 64-bit register expected");
387 msg
= N_("integer register expected");
389 case REG_TYPE_R64_SP
:
390 msg
= N_("64-bit integer or SP register expected");
392 case REG_TYPE_SVE_BASE
:
393 msg
= N_("base register expected");
396 msg
= N_("integer or zero register expected");
398 case REG_TYPE_SVE_OFFSET
:
399 msg
= N_("offset register expected");
402 msg
= N_("integer or SP register expected");
404 case REG_TYPE_R_Z_SP
:
405 msg
= N_("integer, zero or SP register expected");
408 msg
= N_("8-bit SIMD scalar register expected");
411 msg
= N_("16-bit SIMD scalar or floating-point half precision "
412 "register expected");
415 msg
= N_("32-bit SIMD scalar or floating-point single precision "
416 "register expected");
419 msg
= N_("64-bit SIMD scalar or floating-point double precision "
420 "register expected");
423 msg
= N_("128-bit SIMD scalar or floating-point quad precision "
424 "register expected");
426 case REG_TYPE_R_Z_BHSDQ_V
:
427 case REG_TYPE_R_Z_SP_BHSDQ_VZP
:
428 msg
= N_("register expected");
430 case REG_TYPE_BHSDQ
: /* any [BHSDQ]P FP */
431 msg
= N_("SIMD scalar or floating-point register expected");
433 case REG_TYPE_VN
: /* any V reg */
434 msg
= N_("vector register expected");
437 msg
= N_("SVE vector register expected");
440 msg
= N_("SVE predicate register expected");
443 as_fatal (_("invalid register type %d"), reg_type
);
448 /* Some well known registers that we refer to directly elsewhere. */
452 /* Instructions take 4 bytes in the object file. */
455 static htab_t aarch64_ops_hsh
;
456 static htab_t aarch64_cond_hsh
;
457 static htab_t aarch64_shift_hsh
;
458 static htab_t aarch64_sys_regs_hsh
;
459 static htab_t aarch64_pstatefield_hsh
;
460 static htab_t aarch64_sys_regs_ic_hsh
;
461 static htab_t aarch64_sys_regs_dc_hsh
;
462 static htab_t aarch64_sys_regs_at_hsh
;
463 static htab_t aarch64_sys_regs_tlbi_hsh
;
464 static htab_t aarch64_sys_regs_sr_hsh
;
465 static htab_t aarch64_reg_hsh
;
466 static htab_t aarch64_barrier_opt_hsh
;
467 static htab_t aarch64_nzcv_hsh
;
468 static htab_t aarch64_pldop_hsh
;
469 static htab_t aarch64_hint_opt_hsh
;
471 /* Stuff needed to resolve the label ambiguity
480 static symbolS
*last_label_seen
;
482 /* Literal pool structure. Held on a per-section
483 and per-sub-section basis. */
485 #define MAX_LITERAL_POOL_SIZE 1024
486 typedef struct literal_expression
489 /* If exp.op == O_big then this bignum holds a copy of the global bignum value. */
490 LITTLENUM_TYPE
* bignum
;
491 } literal_expression
;
493 typedef struct literal_pool
495 literal_expression literals
[MAX_LITERAL_POOL_SIZE
];
496 unsigned int next_free_entry
;
502 struct literal_pool
*next
;
505 /* Pointer to a linked list of literal pools. */
506 static literal_pool
*list_of_pools
= NULL
;
510 /* This array holds the chars that always start a comment. If the
511 pre-processor is disabled, these aren't very useful. */
512 const char comment_chars
[] = "";
514 /* This array holds the chars that only start a comment at the beginning of
515 a line. If the line seems to have the form '# 123 filename'
516 .line and .file directives will appear in the pre-processed output. */
517 /* Note that input_file.c hand checks for '#' at the beginning of the
518 first line of the input file. This is because the compiler outputs
519 #NO_APP at the beginning of its output. */
520 /* Also note that comments like this one will always work. */
521 const char line_comment_chars
[] = "#";
523 const char line_separator_chars
[] = ";";
525 /* Chars that can be used to separate mant
526 from exp in floating point numbers. */
527 const char EXP_CHARS
[] = "eE";
529 /* Chars that mean this number is a floating point constant. */
533 const char FLT_CHARS
[] = "rRsSfFdDxXeEpPhHb";
535 /* Prefix character that indicates the start of an immediate value. */
536 #define is_immediate_prefix(C) ((C) == '#')
538 /* Separator character handling. */
540 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
543 skip_past_char (char **str
, char c
)
554 #define skip_past_comma(str) skip_past_char (str, ',')
556 /* Arithmetic expressions (possibly involving symbols). */
558 static bool in_aarch64_get_expression
= false;
560 /* Third argument to aarch64_get_expression. */
561 #define GE_NO_PREFIX false
562 #define GE_OPT_PREFIX true
564 /* Fourth argument to aarch64_get_expression. */
565 #define ALLOW_ABSENT false
566 #define REJECT_ABSENT true
568 /* Return TRUE if the string pointed by *STR is successfully parsed
569 as an valid expression; *EP will be filled with the information of
570 such an expression. Otherwise return FALSE.
572 If ALLOW_IMMEDIATE_PREFIX is true then skip a '#' at the start.
573 If REJECT_ABSENT is true then trat missing expressions as an error. */
576 aarch64_get_expression (expressionS
* ep
,
578 bool allow_immediate_prefix
,
583 bool prefix_present
= false;
585 if (allow_immediate_prefix
)
587 if (is_immediate_prefix (**str
))
590 prefix_present
= true;
594 memset (ep
, 0, sizeof (expressionS
));
596 save_in
= input_line_pointer
;
597 input_line_pointer
= *str
;
598 in_aarch64_get_expression
= true;
599 seg
= expression (ep
);
600 in_aarch64_get_expression
= false;
602 if (ep
->X_op
== O_illegal
|| (reject_absent
&& ep
->X_op
== O_absent
))
604 /* We found a bad expression in md_operand(). */
605 *str
= input_line_pointer
;
606 input_line_pointer
= save_in
;
607 if (prefix_present
&& ! error_p ())
608 set_fatal_syntax_error (_("bad expression"));
610 set_first_syntax_error (_("bad expression"));
615 if (seg
!= absolute_section
616 && seg
!= text_section
617 && seg
!= data_section
618 && seg
!= bss_section
619 && seg
!= undefined_section
)
621 set_syntax_error (_("bad segment"));
622 *str
= input_line_pointer
;
623 input_line_pointer
= save_in
;
630 *str
= input_line_pointer
;
631 input_line_pointer
= save_in
;
635 /* Turn a string in input_line_pointer into a floating point constant
636 of type TYPE, and store the appropriate bytes in *LITP. The number
637 of LITTLENUMS emitted is stored in *SIZEP. An error message is
638 returned, or NULL on OK. */
641 md_atof (int type
, char *litP
, int *sizeP
)
643 return ieee_md_atof (type
, litP
, sizeP
, target_big_endian
);
646 /* We handle all bad expressions here, so that we can report the faulty
647 instruction in the error message. */
649 md_operand (expressionS
* exp
)
651 if (in_aarch64_get_expression
)
652 exp
->X_op
= O_illegal
;
655 /* Immediate values. */
657 /* Errors may be set multiple times during parsing or bit encoding
658 (particularly in the Neon bits), but usually the earliest error which is set
659 will be the most meaningful. Avoid overwriting it with later (cascading)
660 errors by calling this function. */
663 first_error (const char *error
)
666 set_syntax_error (error
);
669 /* Similar to first_error, but this function accepts formatted error
672 first_error_fmt (const char *format
, ...)
677 /* N.B. this single buffer will not cause error messages for different
678 instructions to pollute each other; this is because at the end of
679 processing of each assembly line, error message if any will be
680 collected by as_bad. */
681 static char buffer
[size
];
685 int ret ATTRIBUTE_UNUSED
;
686 va_start (args
, format
);
687 ret
= vsnprintf (buffer
, size
, format
, args
);
688 know (ret
<= size
- 1 && ret
>= 0);
690 set_syntax_error (buffer
);
694 /* Register parsing. */
696 /* Generic register parser which is called by other specialized
698 CCP points to what should be the beginning of a register name.
699 If it is indeed a valid register name, advance CCP over it and
700 return the reg_entry structure; otherwise return NULL.
701 It does not issue diagnostics. */
704 parse_reg (char **ccp
)
710 #ifdef REGISTER_PREFIX
711 if (*start
!= REGISTER_PREFIX
)
717 if (!ISALPHA (*p
) || !is_name_beginner (*p
))
722 while (ISALPHA (*p
) || ISDIGIT (*p
) || *p
== '_');
724 reg
= (reg_entry
*) str_hash_find_n (aarch64_reg_hsh
, start
, p
- start
);
733 /* Return TRUE if REG->TYPE is a valid type of TYPE; otherwise
736 aarch64_check_reg_type (const reg_entry
*reg
, aarch64_reg_type type
)
738 return (reg_type_masks
[type
] & (1 << reg
->type
)) != 0;
741 /* Try to parse a base or offset register. Allow SVE base and offset
742 registers if REG_TYPE includes SVE registers. Return the register
743 entry on success, setting *QUALIFIER to the register qualifier.
744 Return null otherwise.
746 Note that this function does not issue any diagnostics. */
748 static const reg_entry
*
749 aarch64_addr_reg_parse (char **ccp
, aarch64_reg_type reg_type
,
750 aarch64_opnd_qualifier_t
*qualifier
)
753 const reg_entry
*reg
= parse_reg (&str
);
763 *qualifier
= AARCH64_OPND_QLF_W
;
769 *qualifier
= AARCH64_OPND_QLF_X
;
773 if ((reg_type_masks
[reg_type
] & (1 << REG_TYPE_ZN
)) == 0
776 switch (TOLOWER (str
[1]))
779 *qualifier
= AARCH64_OPND_QLF_S_S
;
782 *qualifier
= AARCH64_OPND_QLF_S_D
;
799 /* Try to parse a base or offset register. Return the register entry
800 on success, setting *QUALIFIER to the register qualifier. Return null
803 Note that this function does not issue any diagnostics. */
805 static const reg_entry
*
806 aarch64_reg_parse_32_64 (char **ccp
, aarch64_opnd_qualifier_t
*qualifier
)
808 return aarch64_addr_reg_parse (ccp
, REG_TYPE_R_Z_SP
, qualifier
);
811 /* Parse the qualifier of a vector register or vector element of type
812 REG_TYPE. Fill in *PARSED_TYPE and return TRUE if the parsing
813 succeeds; otherwise return FALSE.
815 Accept only one occurrence of:
816 4b 8b 16b 2h 4h 8h 2s 4s 1d 2d
819 parse_vector_type_for_operand (aarch64_reg_type reg_type
,
820 struct vector_type_el
*parsed_type
, char **str
)
824 unsigned element_size
;
825 enum vector_el_type type
;
828 gas_assert (*ptr
== '.');
831 if (reg_type
== REG_TYPE_ZN
|| reg_type
== REG_TYPE_PN
|| !ISDIGIT (*ptr
))
836 width
= strtoul (ptr
, &ptr
, 10);
837 if (width
!= 1 && width
!= 2 && width
!= 4 && width
!= 8 && width
!= 16)
839 first_error_fmt (_("bad size %d in vector width specifier"), width
);
844 switch (TOLOWER (*ptr
))
863 if (reg_type
== REG_TYPE_ZN
|| width
== 1)
872 first_error_fmt (_("unexpected character `%c' in element size"), *ptr
);
874 first_error (_("missing element size"));
877 if (width
!= 0 && width
* element_size
!= 64
878 && width
* element_size
!= 128
879 && !(width
== 2 && element_size
== 16)
880 && !(width
== 4 && element_size
== 8))
883 ("invalid element size %d and vector size combination %c"),
889 parsed_type
->type
= type
;
890 parsed_type
->width
= width
;
897 /* *STR contains an SVE zero/merge predication suffix. Parse it into
898 *PARSED_TYPE and point *STR at the end of the suffix. */
901 parse_predication_for_operand (struct vector_type_el
*parsed_type
, char **str
)
906 gas_assert (*ptr
== '/');
908 switch (TOLOWER (*ptr
))
911 parsed_type
->type
= NT_zero
;
914 parsed_type
->type
= NT_merge
;
917 if (*ptr
!= '\0' && *ptr
!= ',')
918 first_error_fmt (_("unexpected character `%c' in predication type"),
921 first_error (_("missing predication type"));
924 parsed_type
->width
= 0;
929 /* Parse a register of the type TYPE.
931 Return PARSE_FAIL if the string pointed by *CCP is not a valid register
932 name or the parsed register is not of TYPE.
934 Otherwise return the register number, and optionally fill in the actual
935 type of the register in *RTYPE when multiple alternatives were given, and
936 return the register shape and element index information in *TYPEINFO.
938 IN_REG_LIST should be set with TRUE if the caller is parsing a register
942 parse_typed_reg (char **ccp
, aarch64_reg_type type
, aarch64_reg_type
*rtype
,
943 struct vector_type_el
*typeinfo
, bool in_reg_list
)
946 const reg_entry
*reg
= parse_reg (&str
);
947 struct vector_type_el atype
;
948 struct vector_type_el parsetype
;
949 bool is_typed_vecreg
= false;
952 atype
.type
= NT_invtype
;
960 set_default_error ();
964 if (! aarch64_check_reg_type (reg
, type
))
966 DEBUG_TRACE ("reg type check failed");
967 set_default_error ();
972 if ((type
== REG_TYPE_VN
|| type
== REG_TYPE_ZN
|| type
== REG_TYPE_PN
)
973 && (*str
== '.' || (type
== REG_TYPE_PN
&& *str
== '/')))
977 if (!parse_vector_type_for_operand (type
, &parsetype
, &str
))
982 if (!parse_predication_for_operand (&parsetype
, &str
))
986 /* Register if of the form Vn.[bhsdq]. */
987 is_typed_vecreg
= true;
989 if (type
== REG_TYPE_ZN
|| type
== REG_TYPE_PN
)
991 /* The width is always variable; we don't allow an integer width
993 gas_assert (parsetype
.width
== 0);
994 atype
.defined
|= NTA_HASVARWIDTH
| NTA_HASTYPE
;
996 else if (parsetype
.width
== 0)
997 /* Expect index. In the new scheme we cannot have
998 Vn.[bhsdq] represent a scalar. Therefore any
999 Vn.[bhsdq] should have an index following it.
1000 Except in reglists of course. */
1001 atype
.defined
|= NTA_HASINDEX
;
1003 atype
.defined
|= NTA_HASTYPE
;
1005 atype
.type
= parsetype
.type
;
1006 atype
.width
= parsetype
.width
;
1009 if (skip_past_char (&str
, '['))
1013 /* Reject Sn[index] syntax. */
1014 if (!is_typed_vecreg
)
1016 first_error (_("this type of register can't be indexed"));
1022 first_error (_("index not allowed inside register list"));
1026 atype
.defined
|= NTA_HASINDEX
;
1028 aarch64_get_expression (&exp
, &str
, GE_NO_PREFIX
, REJECT_ABSENT
);
1030 if (exp
.X_op
!= O_constant
)
1032 first_error (_("constant expression required"));
1036 if (! skip_past_char (&str
, ']'))
1039 atype
.index
= exp
.X_add_number
;
1041 else if (!in_reg_list
&& (atype
.defined
& NTA_HASINDEX
) != 0)
1043 /* Indexed vector register expected. */
1044 first_error (_("indexed vector register expected"));
1048 /* A vector reg Vn should be typed or indexed. */
1049 if (type
== REG_TYPE_VN
&& atype
.defined
== 0)
1051 first_error (_("invalid use of vector register"));
1067 Return the register number on success; return PARSE_FAIL otherwise.
1069 If RTYPE is not NULL, return in *RTYPE the (possibly restricted) type of
1070 the register (e.g. NEON double or quad reg when either has been requested).
1072 If this is a NEON vector register with additional type information, fill
1073 in the struct pointed to by VECTYPE (if non-NULL).
1075 This parser does not handle register list. */
1078 aarch64_reg_parse (char **ccp
, aarch64_reg_type type
,
1079 aarch64_reg_type
*rtype
, struct vector_type_el
*vectype
)
1081 struct vector_type_el atype
;
1083 int reg
= parse_typed_reg (&str
, type
, rtype
, &atype
,
1084 /*in_reg_list= */ false);
1086 if (reg
== PARSE_FAIL
)
1098 eq_vector_type_el (struct vector_type_el e1
, struct vector_type_el e2
)
1102 && e1
.defined
== e2
.defined
1103 && e1
.width
== e2
.width
&& e1
.index
== e2
.index
;
1106 /* This function parses a list of vector registers of type TYPE.
1107 On success, it returns the parsed register list information in the
1108 following encoded format:
1110 bit 18-22 | 13-17 | 7-11 | 2-6 | 0-1
1111 4th regno | 3rd regno | 2nd regno | 1st regno | num_of_reg
1113 The information of the register shape and/or index is returned in
1116 It returns PARSE_FAIL if the register list is invalid.
1118 The list contains one to four registers.
1119 Each register can be one of:
1122 All <T> should be identical.
1123 All <index> should be identical.
1124 There are restrictions on <Vt> numbers which are checked later
1125 (by reg_list_valid_p). */
1128 parse_vector_reg_list (char **ccp
, aarch64_reg_type type
,
1129 struct vector_type_el
*vectype
)
1133 struct vector_type_el typeinfo
, typeinfo_first
;
1139 bool expect_index
= false;
1143 set_syntax_error (_("expecting {"));
1149 typeinfo_first
.defined
= 0;
1150 typeinfo_first
.type
= NT_invtype
;
1151 typeinfo_first
.width
= -1;
1152 typeinfo_first
.index
= 0;
1161 str
++; /* skip over '-' */
1164 val
= parse_typed_reg (&str
, type
, NULL
, &typeinfo
,
1165 /*in_reg_list= */ true);
1166 if (val
== PARSE_FAIL
)
1168 set_first_syntax_error (_("invalid vector register in list"));
1172 /* reject [bhsd]n */
1173 if (type
== REG_TYPE_VN
&& typeinfo
.defined
== 0)
1175 set_first_syntax_error (_("invalid scalar register in list"));
1180 if (typeinfo
.defined
& NTA_HASINDEX
)
1181 expect_index
= true;
1185 if (val
< val_range
)
1187 set_first_syntax_error
1188 (_("invalid range in vector register list"));
1197 typeinfo_first
= typeinfo
;
1198 else if (! eq_vector_type_el (typeinfo_first
, typeinfo
))
1200 set_first_syntax_error
1201 (_("type mismatch in vector register list"));
1206 for (i
= val_range
; i
<= val
; i
++)
1208 ret_val
|= i
<< (5 * nb_regs
);
1213 while (skip_past_comma (&str
) || (in_range
= 1, *str
== '-'));
1215 skip_whitespace (str
);
1218 set_first_syntax_error (_("end of vector register list not found"));
1223 skip_whitespace (str
);
1227 if (skip_past_char (&str
, '['))
1231 aarch64_get_expression (&exp
, &str
, GE_NO_PREFIX
, REJECT_ABSENT
);
1232 if (exp
.X_op
!= O_constant
)
1234 set_first_syntax_error (_("constant expression required."));
1237 if (! skip_past_char (&str
, ']'))
1240 typeinfo_first
.index
= exp
.X_add_number
;
1244 set_first_syntax_error (_("expected index"));
1251 set_first_syntax_error (_("too many registers in vector register list"));
1254 else if (nb_regs
== 0)
1256 set_first_syntax_error (_("empty vector register list"));
1262 *vectype
= typeinfo_first
;
1264 return error
? PARSE_FAIL
: (ret_val
<< 2) | (nb_regs
- 1);
1267 /* Directives: register aliases. */
1270 insert_reg_alias (char *str
, int number
, aarch64_reg_type type
)
1275 if ((new = str_hash_find (aarch64_reg_hsh
, str
)) != 0)
1278 as_warn (_("ignoring attempt to redefine built-in register '%s'"),
1281 /* Only warn about a redefinition if it's not defined as the
1283 else if (new->number
!= number
|| new->type
!= type
)
1284 as_warn (_("ignoring redefinition of register alias '%s'"), str
);
1289 name
= xstrdup (str
);
1290 new = XNEW (reg_entry
);
1293 new->number
= number
;
1295 new->builtin
= false;
1297 str_hash_insert (aarch64_reg_hsh
, name
, new, 0);
1302 /* Look for the .req directive. This is of the form:
1304 new_register_name .req existing_register_name
1306 If we find one, or if it looks sufficiently like one that we want to
1307 handle any error here, return TRUE. Otherwise return FALSE. */
1310 create_register_alias (char *newname
, char *p
)
1312 const reg_entry
*old
;
1313 char *oldname
, *nbuf
;
1316 /* The input scrubber ensures that whitespace after the mnemonic is
1317 collapsed to single spaces. */
1319 if (!startswith (oldname
, " .req "))
1323 if (*oldname
== '\0')
1326 old
= str_hash_find (aarch64_reg_hsh
, oldname
);
1329 as_warn (_("unknown register '%s' -- .req ignored"), oldname
);
1333 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1334 the desired alias name, and p points to its end. If not, then
1335 the desired alias name is in the global original_case_string. */
1336 #ifdef TC_CASE_SENSITIVE
1339 newname
= original_case_string
;
1340 nlen
= strlen (newname
);
1343 nbuf
= xmemdup0 (newname
, nlen
);
1345 /* Create aliases under the new name as stated; an all-lowercase
1346 version of the new name; and an all-uppercase version of the new
1348 if (insert_reg_alias (nbuf
, old
->number
, old
->type
) != NULL
)
1350 for (p
= nbuf
; *p
; p
++)
1353 if (strncmp (nbuf
, newname
, nlen
))
1355 /* If this attempt to create an additional alias fails, do not bother
1356 trying to create the all-lower case alias. We will fail and issue
1357 a second, duplicate error message. This situation arises when the
1358 programmer does something like:
1361 The second .req creates the "Foo" alias but then fails to create
1362 the artificial FOO alias because it has already been created by the
1364 if (insert_reg_alias (nbuf
, old
->number
, old
->type
) == NULL
)
1371 for (p
= nbuf
; *p
; p
++)
1374 if (strncmp (nbuf
, newname
, nlen
))
1375 insert_reg_alias (nbuf
, old
->number
, old
->type
);
1382 /* Should never be called, as .req goes between the alias and the
1383 register name, not at the beginning of the line. */
1385 s_req (int a ATTRIBUTE_UNUSED
)
1387 as_bad (_("invalid syntax for .req directive"));
1390 /* The .unreq directive deletes an alias which was previously defined
1391 by .req. For example:
1397 s_unreq (int a ATTRIBUTE_UNUSED
)
1402 name
= input_line_pointer
;
1404 while (*input_line_pointer
!= 0
1405 && *input_line_pointer
!= ' ' && *input_line_pointer
!= '\n')
1406 ++input_line_pointer
;
1408 saved_char
= *input_line_pointer
;
1409 *input_line_pointer
= 0;
1412 as_bad (_("invalid syntax for .unreq directive"));
1415 reg_entry
*reg
= str_hash_find (aarch64_reg_hsh
, name
);
1418 as_bad (_("unknown register alias '%s'"), name
);
1419 else if (reg
->builtin
)
1420 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1427 str_hash_delete (aarch64_reg_hsh
, name
);
1428 free ((char *) reg
->name
);
1431 /* Also locate the all upper case and all lower case versions.
1432 Do not complain if we cannot find one or the other as it
1433 was probably deleted above. */
1435 nbuf
= strdup (name
);
1436 for (p
= nbuf
; *p
; p
++)
1438 reg
= str_hash_find (aarch64_reg_hsh
, nbuf
);
1441 str_hash_delete (aarch64_reg_hsh
, nbuf
);
1442 free ((char *) reg
->name
);
1446 for (p
= nbuf
; *p
; p
++)
1448 reg
= str_hash_find (aarch64_reg_hsh
, nbuf
);
1451 str_hash_delete (aarch64_reg_hsh
, nbuf
);
1452 free ((char *) reg
->name
);
1460 *input_line_pointer
= saved_char
;
1461 demand_empty_rest_of_line ();
1464 /* Directives: Instruction set selection. */
1467 /* This code is to handle mapping symbols as defined in the ARM AArch64 ELF
1468 spec. (See "Mapping symbols", section 4.5.4, ARM AAELF64 version 0.05).
1469 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1470 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1472 /* Create a new mapping symbol for the transition to STATE. */
1475 make_mapping_symbol (enum mstate state
, valueT value
, fragS
* frag
)
1478 const char *symname
;
1485 type
= BSF_NO_FLAGS
;
1489 type
= BSF_NO_FLAGS
;
1495 symbolP
= symbol_new (symname
, now_seg
, frag
, value
);
1496 symbol_get_bfdsym (symbolP
)->flags
|= type
| BSF_LOCAL
;
1498 /* Save the mapping symbols for future reference. Also check that
1499 we do not place two mapping symbols at the same offset within a
1500 frag. We'll handle overlap between frags in
1501 check_mapping_symbols.
1503 If .fill or other data filling directive generates zero sized data,
1504 the mapping symbol for the following code will have the same value
1505 as the one generated for the data filling directive. In this case,
1506 we replace the old symbol with the new one at the same address. */
1509 if (frag
->tc_frag_data
.first_map
!= NULL
)
1511 know (S_GET_VALUE (frag
->tc_frag_data
.first_map
) == 0);
1512 symbol_remove (frag
->tc_frag_data
.first_map
, &symbol_rootP
,
1515 frag
->tc_frag_data
.first_map
= symbolP
;
1517 if (frag
->tc_frag_data
.last_map
!= NULL
)
1519 know (S_GET_VALUE (frag
->tc_frag_data
.last_map
) <=
1520 S_GET_VALUE (symbolP
));
1521 if (S_GET_VALUE (frag
->tc_frag_data
.last_map
) == S_GET_VALUE (symbolP
))
1522 symbol_remove (frag
->tc_frag_data
.last_map
, &symbol_rootP
,
1525 frag
->tc_frag_data
.last_map
= symbolP
;
1528 /* We must sometimes convert a region marked as code to data during
1529 code alignment, if an odd number of bytes have to be padded. The
1530 code mapping symbol is pushed to an aligned address. */
1533 insert_data_mapping_symbol (enum mstate state
,
1534 valueT value
, fragS
* frag
, offsetT bytes
)
1536 /* If there was already a mapping symbol, remove it. */
1537 if (frag
->tc_frag_data
.last_map
!= NULL
1538 && S_GET_VALUE (frag
->tc_frag_data
.last_map
) ==
1539 frag
->fr_address
+ value
)
1541 symbolS
*symp
= frag
->tc_frag_data
.last_map
;
1545 know (frag
->tc_frag_data
.first_map
== symp
);
1546 frag
->tc_frag_data
.first_map
= NULL
;
1548 frag
->tc_frag_data
.last_map
= NULL
;
1549 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1552 make_mapping_symbol (MAP_DATA
, value
, frag
);
1553 make_mapping_symbol (state
, value
+ bytes
, frag
);
1556 static void mapping_state_2 (enum mstate state
, int max_chars
);
1558 /* Set the mapping state to STATE. Only call this when about to
1559 emit some STATE bytes to the file. */
1562 mapping_state (enum mstate state
)
1564 enum mstate mapstate
= seg_info (now_seg
)->tc_segment_info_data
.mapstate
;
1566 if (state
== MAP_INSN
)
1567 /* AArch64 instructions require 4-byte alignment. When emitting
1568 instructions into any section, record the appropriate section
1570 record_alignment (now_seg
, 2);
1572 if (mapstate
== state
)
1573 /* The mapping symbol has already been emitted.
1574 There is nothing else to do. */
1577 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
1578 if (TRANSITION (MAP_UNDEFINED
, MAP_DATA
) && !subseg_text_p (now_seg
))
1579 /* Emit MAP_DATA within executable section in order. Otherwise, it will be
1580 evaluated later in the next else. */
1582 else if (TRANSITION (MAP_UNDEFINED
, MAP_INSN
))
1584 /* Only add the symbol if the offset is > 0:
1585 if we're at the first frag, check it's size > 0;
1586 if we're not at the first frag, then for sure
1587 the offset is > 0. */
1588 struct frag
*const frag_first
= seg_info (now_seg
)->frchainP
->frch_root
;
1589 const int add_symbol
= (frag_now
!= frag_first
)
1590 || (frag_now_fix () > 0);
1593 make_mapping_symbol (MAP_DATA
, (valueT
) 0, frag_first
);
1597 mapping_state_2 (state
, 0);
1600 /* Same as mapping_state, but MAX_CHARS bytes have already been
1601 allocated. Put the mapping symbol that far back. */
1604 mapping_state_2 (enum mstate state
, int max_chars
)
1606 enum mstate mapstate
= seg_info (now_seg
)->tc_segment_info_data
.mapstate
;
1608 if (!SEG_NORMAL (now_seg
))
1611 if (mapstate
== state
)
1612 /* The mapping symbol has already been emitted.
1613 There is nothing else to do. */
1616 seg_info (now_seg
)->tc_segment_info_data
.mapstate
= state
;
1617 make_mapping_symbol (state
, (valueT
) frag_now_fix () - max_chars
, frag_now
);
1620 #define mapping_state(x) /* nothing */
1621 #define mapping_state_2(x, y) /* nothing */
1624 /* Directives: sectioning and alignment. */
1627 s_bss (int ignore ATTRIBUTE_UNUSED
)
1629 /* We don't support putting frags in the BSS segment, we fake it by
1630 marking in_bss, then looking at s_skip for clues. */
1631 subseg_set (bss_section
, 0);
1632 demand_empty_rest_of_line ();
1633 mapping_state (MAP_DATA
);
1637 s_even (int ignore ATTRIBUTE_UNUSED
)
1639 /* Never make frag if expect extra pass. */
1641 frag_align (1, 0, 0);
1643 record_alignment (now_seg
, 1);
1645 demand_empty_rest_of_line ();
1648 /* Directives: Literal pools. */
1650 static literal_pool
*
1651 find_literal_pool (int size
)
1655 for (pool
= list_of_pools
; pool
!= NULL
; pool
= pool
->next
)
1657 if (pool
->section
== now_seg
1658 && pool
->sub_section
== now_subseg
&& pool
->size
== size
)
1665 static literal_pool
*
1666 find_or_make_literal_pool (int size
)
1668 /* Next literal pool ID number. */
1669 static unsigned int latest_pool_num
= 1;
1672 pool
= find_literal_pool (size
);
1676 /* Create a new pool. */
1677 pool
= XNEW (literal_pool
);
1681 /* Currently we always put the literal pool in the current text
1682 section. If we were generating "small" model code where we
1683 knew that all code and initialised data was within 1MB then
1684 we could output literals to mergeable, read-only data
1687 pool
->next_free_entry
= 0;
1688 pool
->section
= now_seg
;
1689 pool
->sub_section
= now_subseg
;
1691 pool
->next
= list_of_pools
;
1692 pool
->symbol
= NULL
;
1694 /* Add it to the list. */
1695 list_of_pools
= pool
;
1698 /* New pools, and emptied pools, will have a NULL symbol. */
1699 if (pool
->symbol
== NULL
)
1701 pool
->symbol
= symbol_create (FAKE_LABEL_NAME
, undefined_section
,
1702 &zero_address_frag
, 0);
1703 pool
->id
= latest_pool_num
++;
1710 /* Add the literal of size SIZE in *EXP to the relevant literal pool.
1711 Return TRUE on success, otherwise return FALSE. */
1713 add_to_lit_pool (expressionS
*exp
, int size
)
1718 pool
= find_or_make_literal_pool (size
);
1720 /* Check if this literal value is already in the pool. */
1721 for (entry
= 0; entry
< pool
->next_free_entry
; entry
++)
1723 expressionS
* litexp
= & pool
->literals
[entry
].exp
;
1725 if ((litexp
->X_op
== exp
->X_op
)
1726 && (exp
->X_op
== O_constant
)
1727 && (litexp
->X_add_number
== exp
->X_add_number
)
1728 && (litexp
->X_unsigned
== exp
->X_unsigned
))
1731 if ((litexp
->X_op
== exp
->X_op
)
1732 && (exp
->X_op
== O_symbol
)
1733 && (litexp
->X_add_number
== exp
->X_add_number
)
1734 && (litexp
->X_add_symbol
== exp
->X_add_symbol
)
1735 && (litexp
->X_op_symbol
== exp
->X_op_symbol
))
1739 /* Do we need to create a new entry? */
1740 if (entry
== pool
->next_free_entry
)
1742 if (entry
>= MAX_LITERAL_POOL_SIZE
)
1744 set_syntax_error (_("literal pool overflow"));
1748 pool
->literals
[entry
].exp
= *exp
;
1749 pool
->next_free_entry
+= 1;
1750 if (exp
->X_op
== O_big
)
1752 /* PR 16688: Bignums are held in a single global array. We must
1753 copy and preserve that value now, before it is overwritten. */
1754 pool
->literals
[entry
].bignum
= XNEWVEC (LITTLENUM_TYPE
,
1756 memcpy (pool
->literals
[entry
].bignum
, generic_bignum
,
1757 CHARS_PER_LITTLENUM
* exp
->X_add_number
);
1760 pool
->literals
[entry
].bignum
= NULL
;
1763 exp
->X_op
= O_symbol
;
1764 exp
->X_add_number
= ((int) entry
) * size
;
1765 exp
->X_add_symbol
= pool
->symbol
;
1770 /* Can't use symbol_new here, so have to create a symbol and then at
1771 a later date assign it a value. That's what these functions do. */
1774 symbol_locate (symbolS
* symbolP
,
1775 const char *name
,/* It is copied, the caller can modify. */
1776 segT segment
, /* Segment identifier (SEG_<something>). */
1777 valueT valu
, /* Symbol value. */
1778 fragS
* frag
) /* Associated fragment. */
1781 char *preserved_copy_of_name
;
1783 name_length
= strlen (name
) + 1; /* +1 for \0. */
1784 obstack_grow (¬es
, name
, name_length
);
1785 preserved_copy_of_name
= obstack_finish (¬es
);
1787 #ifdef tc_canonicalize_symbol_name
1788 preserved_copy_of_name
=
1789 tc_canonicalize_symbol_name (preserved_copy_of_name
);
1792 S_SET_NAME (symbolP
, preserved_copy_of_name
);
1794 S_SET_SEGMENT (symbolP
, segment
);
1795 S_SET_VALUE (symbolP
, valu
);
1796 symbol_clear_list_pointers (symbolP
);
1798 symbol_set_frag (symbolP
, frag
);
1800 /* Link to end of symbol chain. */
1802 extern int symbol_table_frozen
;
1804 if (symbol_table_frozen
)
1808 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1810 obj_symbol_new_hook (symbolP
);
1812 #ifdef tc_symbol_new_hook
1813 tc_symbol_new_hook (symbolP
);
1817 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
1818 #endif /* DEBUG_SYMS */
1823 s_ltorg (int ignored ATTRIBUTE_UNUSED
)
1830 for (align
= 2; align
<= 4; align
++)
1832 int size
= 1 << align
;
1834 pool
= find_literal_pool (size
);
1835 if (pool
== NULL
|| pool
->symbol
== NULL
|| pool
->next_free_entry
== 0)
1838 /* Align pool as you have word accesses.
1839 Only make a frag if we have to. */
1841 frag_align (align
, 0, 0);
1843 mapping_state (MAP_DATA
);
1845 record_alignment (now_seg
, align
);
1847 sprintf (sym_name
, "$$lit_\002%x", pool
->id
);
1849 symbol_locate (pool
->symbol
, sym_name
, now_seg
,
1850 (valueT
) frag_now_fix (), frag_now
);
1851 symbol_table_insert (pool
->symbol
);
1853 for (entry
= 0; entry
< pool
->next_free_entry
; entry
++)
1855 expressionS
* exp
= & pool
->literals
[entry
].exp
;
1857 if (exp
->X_op
== O_big
)
1859 /* PR 16688: Restore the global bignum value. */
1860 gas_assert (pool
->literals
[entry
].bignum
!= NULL
);
1861 memcpy (generic_bignum
, pool
->literals
[entry
].bignum
,
1862 CHARS_PER_LITTLENUM
* exp
->X_add_number
);
1865 /* First output the expression in the instruction to the pool. */
1866 emit_expr (exp
, size
); /* .word|.xword */
1868 if (exp
->X_op
== O_big
)
1870 free (pool
->literals
[entry
].bignum
);
1871 pool
->literals
[entry
].bignum
= NULL
;
1875 /* Mark the pool as empty. */
1876 pool
->next_free_entry
= 0;
1877 pool
->symbol
= NULL
;
1882 /* Forward declarations for functions below, in the MD interface
1884 static fixS
*fix_new_aarch64 (fragS
*, int, short, expressionS
*, int, int);
1885 static struct reloc_table_entry
* find_reloc_table_entry (char **);
1887 /* Directives: Data. */
1888 /* N.B. the support for relocation suffix in this directive needs to be
1889 implemented properly. */
1892 s_aarch64_elf_cons (int nbytes
)
1896 #ifdef md_flush_pending_output
1897 md_flush_pending_output ();
1900 if (is_it_end_of_statement ())
1902 demand_empty_rest_of_line ();
1906 #ifdef md_cons_align
1907 md_cons_align (nbytes
);
1910 mapping_state (MAP_DATA
);
1913 struct reloc_table_entry
*reloc
;
1917 if (exp
.X_op
!= O_symbol
)
1918 emit_expr (&exp
, (unsigned int) nbytes
);
1921 skip_past_char (&input_line_pointer
, '#');
1922 if (skip_past_char (&input_line_pointer
, ':'))
1924 reloc
= find_reloc_table_entry (&input_line_pointer
);
1926 as_bad (_("unrecognized relocation suffix"));
1928 as_bad (_("unimplemented relocation suffix"));
1929 ignore_rest_of_line ();
1933 emit_expr (&exp
, (unsigned int) nbytes
);
1936 while (*input_line_pointer
++ == ',');
1938 /* Put terminator back into stream. */
1939 input_line_pointer
--;
1940 demand_empty_rest_of_line ();
1943 /* Mark symbol that it follows a variant PCS convention. */
1946 s_variant_pcs (int ignored ATTRIBUTE_UNUSED
)
1952 elf_symbol_type
*elfsym
;
1954 c
= get_symbol_name (&name
);
1956 as_bad (_("Missing symbol name in directive"));
1957 sym
= symbol_find_or_make (name
);
1958 restore_line_pointer (c
);
1959 demand_empty_rest_of_line ();
1960 bfdsym
= symbol_get_bfdsym (sym
);
1961 elfsym
= elf_symbol_from (bfdsym
);
1962 gas_assert (elfsym
);
1963 elfsym
->internal_elf_sym
.st_other
|= STO_AARCH64_VARIANT_PCS
;
1965 #endif /* OBJ_ELF */
1967 /* Output a 32-bit word, but mark as an instruction. */
1970 s_aarch64_inst (int ignored ATTRIBUTE_UNUSED
)
1975 #ifdef md_flush_pending_output
1976 md_flush_pending_output ();
1979 if (is_it_end_of_statement ())
1981 demand_empty_rest_of_line ();
1985 /* Sections are assumed to start aligned. In executable section, there is no
1986 MAP_DATA symbol pending. So we only align the address during
1987 MAP_DATA --> MAP_INSN transition.
1988 For other sections, this is not guaranteed. */
1989 enum mstate mapstate
= seg_info (now_seg
)->tc_segment_info_data
.mapstate
;
1990 if (!need_pass_2
&& subseg_text_p (now_seg
) && mapstate
== MAP_DATA
)
1991 frag_align_code (2, 0);
1994 mapping_state (MAP_INSN
);
2000 if (exp
.X_op
!= O_constant
)
2002 as_bad (_("constant expression required"));
2003 ignore_rest_of_line ();
2007 if (target_big_endian
)
2009 unsigned int val
= exp
.X_add_number
;
2010 exp
.X_add_number
= SWAP_32 (val
);
2012 emit_expr (&exp
, INSN_SIZE
);
2015 while (*input_line_pointer
++ == ',');
2017 dwarf2_emit_insn (n
* INSN_SIZE
);
2019 /* Put terminator back into stream. */
2020 input_line_pointer
--;
2021 demand_empty_rest_of_line ();
2025 s_aarch64_cfi_b_key_frame (int ignored ATTRIBUTE_UNUSED
)
2027 demand_empty_rest_of_line ();
2028 struct fde_entry
*fde
= frchain_now
->frch_cfi_data
->cur_fde_data
;
2029 fde
->pauth_key
= AARCH64_PAUTH_KEY_B
;
2033 /* Emit BFD_RELOC_AARCH64_TLSDESC_ADD on the next ADD instruction. */
2036 s_tlsdescadd (int ignored ATTRIBUTE_UNUSED
)
2042 fix_new_aarch64 (frag_now
, frag_more (0) - frag_now
->fr_literal
, 4, &exp
, 0,
2043 BFD_RELOC_AARCH64_TLSDESC_ADD
);
2045 demand_empty_rest_of_line ();
2048 /* Emit BFD_RELOC_AARCH64_TLSDESC_CALL on the next BLR instruction. */
2051 s_tlsdesccall (int ignored ATTRIBUTE_UNUSED
)
2055 /* Since we're just labelling the code, there's no need to define a
2058 /* Make sure there is enough room in this frag for the following
2059 blr. This trick only works if the blr follows immediately after
2060 the .tlsdesc directive. */
2062 fix_new_aarch64 (frag_now
, frag_more (0) - frag_now
->fr_literal
, 4, &exp
, 0,
2063 BFD_RELOC_AARCH64_TLSDESC_CALL
);
2065 demand_empty_rest_of_line ();
2068 /* Emit BFD_RELOC_AARCH64_TLSDESC_LDR on the next LDR instruction. */
2071 s_tlsdescldr (int ignored ATTRIBUTE_UNUSED
)
2077 fix_new_aarch64 (frag_now
, frag_more (0) - frag_now
->fr_literal
, 4, &exp
, 0,
2078 BFD_RELOC_AARCH64_TLSDESC_LDR
);
2080 demand_empty_rest_of_line ();
2082 #endif /* OBJ_ELF */
2084 static void s_aarch64_arch (int);
2085 static void s_aarch64_cpu (int);
2086 static void s_aarch64_arch_extension (int);
2088 /* This table describes all the machine specific pseudo-ops the assembler
2089 has to support. The fields are:
2090 pseudo-op name without dot
2091 function to call to execute this pseudo-op
2092 Integer arg to pass to the function. */
2094 const pseudo_typeS md_pseudo_table
[] = {
2095 /* Never called because '.req' does not start a line. */
2097 {"unreq", s_unreq
, 0},
2099 {"even", s_even
, 0},
2100 {"ltorg", s_ltorg
, 0},
2101 {"pool", s_ltorg
, 0},
2102 {"cpu", s_aarch64_cpu
, 0},
2103 {"arch", s_aarch64_arch
, 0},
2104 {"arch_extension", s_aarch64_arch_extension
, 0},
2105 {"inst", s_aarch64_inst
, 0},
2106 {"cfi_b_key_frame", s_aarch64_cfi_b_key_frame
, 0},
2108 {"tlsdescadd", s_tlsdescadd
, 0},
2109 {"tlsdesccall", s_tlsdesccall
, 0},
2110 {"tlsdescldr", s_tlsdescldr
, 0},
2111 {"word", s_aarch64_elf_cons
, 4},
2112 {"long", s_aarch64_elf_cons
, 4},
2113 {"xword", s_aarch64_elf_cons
, 8},
2114 {"dword", s_aarch64_elf_cons
, 8},
2115 {"variant_pcs", s_variant_pcs
, 0},
2117 {"float16", float_cons
, 'h'},
2118 {"bfloat16", float_cons
, 'b'},
2123 /* Check whether STR points to a register name followed by a comma or the
2124 end of line; REG_TYPE indicates which register types are checked
2125 against. Return TRUE if STR is such a register name; otherwise return
2126 FALSE. The function does not intend to produce any diagnostics, but since
2127 the register parser aarch64_reg_parse, which is called by this function,
2128 does produce diagnostics, we call clear_error to clear any diagnostics
2129 that may be generated by aarch64_reg_parse.
2130 Also, the function returns FALSE directly if there is any user error
2131 present at the function entry. This prevents the existing diagnostics
2132 state from being spoiled.
2133 The function currently serves parse_constant_immediate and
2134 parse_big_immediate only. */
2136 reg_name_p (char *str
, aarch64_reg_type reg_type
)
2140 /* Prevent the diagnostics state from being spoiled. */
2144 reg
= aarch64_reg_parse (&str
, reg_type
, NULL
, NULL
);
2146 /* Clear the parsing error that may be set by the reg parser. */
2149 if (reg
== PARSE_FAIL
)
2152 skip_whitespace (str
);
2153 if (*str
== ',' || is_end_of_line
[(unsigned char) *str
])
2159 /* Parser functions used exclusively in instruction operands. */
2161 /* Parse an immediate expression which may not be constant.
2163 To prevent the expression parser from pushing a register name
2164 into the symbol table as an undefined symbol, firstly a check is
2165 done to find out whether STR is a register of type REG_TYPE followed
2166 by a comma or the end of line. Return FALSE if STR is such a string. */
2169 parse_immediate_expression (char **str
, expressionS
*exp
,
2170 aarch64_reg_type reg_type
)
2172 if (reg_name_p (*str
, reg_type
))
2174 set_recoverable_error (_("immediate operand required"));
2178 aarch64_get_expression (exp
, str
, GE_OPT_PREFIX
, REJECT_ABSENT
);
2180 if (exp
->X_op
== O_absent
)
2182 set_fatal_syntax_error (_("missing immediate expression"));
2189 /* Constant immediate-value read function for use in insn parsing.
2190 STR points to the beginning of the immediate (with the optional
2191 leading #); *VAL receives the value. REG_TYPE says which register
2192 names should be treated as registers rather than as symbolic immediates.
2194 Return TRUE on success; otherwise return FALSE. */
2197 parse_constant_immediate (char **str
, int64_t *val
, aarch64_reg_type reg_type
)
2201 if (! parse_immediate_expression (str
, &exp
, reg_type
))
2204 if (exp
.X_op
!= O_constant
)
2206 set_syntax_error (_("constant expression required"));
2210 *val
= exp
.X_add_number
;
2215 encode_imm_float_bits (uint32_t imm
)
2217 return ((imm
>> 19) & 0x7f) /* b[25:19] -> b[6:0] */
2218 | ((imm
>> (31 - 7)) & 0x80); /* b[31] -> b[7] */
2221 /* Return TRUE if the single-precision floating-point value encoded in IMM
2222 can be expressed in the AArch64 8-bit signed floating-point format with
2223 3-bit exponent and normalized 4 bits of precision; in other words, the
2224 floating-point value must be expressable as
2225 (+/-) n / 16 * power (2, r)
2226 where n and r are integers such that 16 <= n <=31 and -3 <= r <= 4. */
2229 aarch64_imm_float_p (uint32_t imm
)
2231 /* If a single-precision floating-point value has the following bit
2232 pattern, it can be expressed in the AArch64 8-bit floating-point
2235 3 32222222 2221111111111
2236 1 09876543 21098765432109876543210
2237 n Eeeeeexx xxxx0000000000000000000
2239 where n, e and each x are either 0 or 1 independently, with
2244 /* Prepare the pattern for 'Eeeeee'. */
2245 if (((imm
>> 30) & 0x1) == 0)
2246 pattern
= 0x3e000000;
2248 pattern
= 0x40000000;
2250 return (imm
& 0x7ffff) == 0 /* lower 19 bits are 0. */
2251 && ((imm
& 0x7e000000) == pattern
); /* bits 25 - 29 == ~ bit 30. */
2254 /* Return TRUE if the IEEE double value encoded in IMM can be expressed
2255 as an IEEE float without any loss of precision. Store the value in
2259 can_convert_double_to_float (uint64_t imm
, uint32_t *fpword
)
2261 /* If a double-precision floating-point value has the following bit
2262 pattern, it can be expressed in a float:
2264 6 66655555555 5544 44444444 33333333 33222222 22221111 111111
2265 3 21098765432 1098 76543210 98765432 10987654 32109876 54321098 76543210
2266 n E~~~eeeeeee ssss ssssssss ssssssss SSS00000 00000000 00000000 00000000
2268 -----------------------------> nEeeeeee esssssss ssssssss sssssSSS
2269 if Eeee_eeee != 1111_1111
2271 where n, e, s and S are either 0 or 1 independently and where ~ is the
2275 uint32_t high32
= imm
>> 32;
2276 uint32_t low32
= imm
;
2278 /* Lower 29 bits need to be 0s. */
2279 if ((imm
& 0x1fffffff) != 0)
2282 /* Prepare the pattern for 'Eeeeeeeee'. */
2283 if (((high32
>> 30) & 0x1) == 0)
2284 pattern
= 0x38000000;
2286 pattern
= 0x40000000;
2289 if ((high32
& 0x78000000) != pattern
)
2292 /* Check Eeee_eeee != 1111_1111. */
2293 if ((high32
& 0x7ff00000) == 0x47f00000)
2296 *fpword
= ((high32
& 0xc0000000) /* 1 n bit and 1 E bit. */
2297 | ((high32
<< 3) & 0x3ffffff8) /* 7 e and 20 s bits. */
2298 | (low32
>> 29)); /* 3 S bits. */
2302 /* Return true if we should treat OPERAND as a double-precision
2303 floating-point operand rather than a single-precision one. */
2305 double_precision_operand_p (const aarch64_opnd_info
*operand
)
2307 /* Check for unsuffixed SVE registers, which are allowed
2308 for LDR and STR but not in instructions that require an
2309 immediate. We get better error messages if we arbitrarily
2310 pick one size, parse the immediate normally, and then
2311 report the match failure in the normal way. */
2312 return (operand
->qualifier
== AARCH64_OPND_QLF_NIL
2313 || aarch64_get_qualifier_esize (operand
->qualifier
) == 8);
2316 /* Parse a floating-point immediate. Return TRUE on success and return the
2317 value in *IMMED in the format of IEEE754 single-precision encoding.
2318 *CCP points to the start of the string; DP_P is TRUE when the immediate
2319 is expected to be in double-precision (N.B. this only matters when
2320 hexadecimal representation is involved). REG_TYPE says which register
2321 names should be treated as registers rather than as symbolic immediates.
2323 This routine accepts any IEEE float; it is up to the callers to reject
2327 parse_aarch64_imm_float (char **ccp
, int *immed
, bool dp_p
,
2328 aarch64_reg_type reg_type
)
2332 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2334 unsigned fpword
= 0;
2337 skip_past_char (&str
, '#');
2340 skip_whitespace (fpnum
);
2342 if (startswith (fpnum
, "0x"))
2344 /* Support the hexadecimal representation of the IEEE754 encoding.
2345 Double-precision is expected when DP_P is TRUE, otherwise the
2346 representation should be in single-precision. */
2347 if (! parse_constant_immediate (&str
, &val
, reg_type
))
2352 if (!can_convert_double_to_float (val
, &fpword
))
2355 else if ((uint64_t) val
> 0xffffffff)
2362 else if (reg_name_p (str
, reg_type
))
2364 set_recoverable_error (_("immediate operand required"));
2372 if ((str
= atof_ieee (str
, 's', words
)) == NULL
)
2375 /* Our FP word must be 32 bits (single-precision FP). */
2376 for (i
= 0; i
< 32 / LITTLENUM_NUMBER_OF_BITS
; i
++)
2378 fpword
<<= LITTLENUM_NUMBER_OF_BITS
;
2388 set_fatal_syntax_error (_("invalid floating-point constant"));
2392 /* Less-generic immediate-value read function with the possibility of loading
2393 a big (64-bit) immediate, as required by AdvSIMD Modified immediate
2396 To prevent the expression parser from pushing a register name into the
2397 symbol table as an undefined symbol, a check is firstly done to find
2398 out whether STR is a register of type REG_TYPE followed by a comma or
2399 the end of line. Return FALSE if STR is such a register. */
2402 parse_big_immediate (char **str
, int64_t *imm
, aarch64_reg_type reg_type
)
2406 if (reg_name_p (ptr
, reg_type
))
2408 set_syntax_error (_("immediate operand required"));
2412 aarch64_get_expression (&inst
.reloc
.exp
, &ptr
, GE_OPT_PREFIX
, REJECT_ABSENT
);
2414 if (inst
.reloc
.exp
.X_op
== O_constant
)
2415 *imm
= inst
.reloc
.exp
.X_add_number
;
2422 /* Set operand IDX of the *INSTR that needs a GAS internal fixup.
2423 if NEED_LIBOPCODES is non-zero, the fixup will need
2424 assistance from the libopcodes. */
2427 aarch64_set_gas_internal_fixup (struct reloc
*reloc
,
2428 const aarch64_opnd_info
*operand
,
2429 int need_libopcodes_p
)
2431 reloc
->type
= BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP
;
2432 reloc
->opnd
= operand
->type
;
2433 if (need_libopcodes_p
)
2434 reloc
->need_libopcodes_p
= 1;
2437 /* Return TRUE if the instruction needs to be fixed up later internally by
2438 the GAS; otherwise return FALSE. */
2441 aarch64_gas_internal_fixup_p (void)
2443 return inst
.reloc
.type
== BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP
;
2446 /* Assign the immediate value to the relevant field in *OPERAND if
2447 RELOC->EXP is a constant expression; otherwise, flag that *OPERAND
2448 needs an internal fixup in a later stage.
2449 ADDR_OFF_P determines whether it is the field ADDR.OFFSET.IMM or
2450 IMM.VALUE that may get assigned with the constant. */
2452 assign_imm_if_const_or_fixup_later (struct reloc
*reloc
,
2453 aarch64_opnd_info
*operand
,
2455 int need_libopcodes_p
,
2458 if (reloc
->exp
.X_op
== O_constant
)
2461 operand
->addr
.offset
.imm
= reloc
->exp
.X_add_number
;
2463 operand
->imm
.value
= reloc
->exp
.X_add_number
;
2464 reloc
->type
= BFD_RELOC_UNUSED
;
2468 aarch64_set_gas_internal_fixup (reloc
, operand
, need_libopcodes_p
);
2469 /* Tell libopcodes to ignore this operand or not. This is helpful
2470 when one of the operands needs to be fixed up later but we need
2471 libopcodes to check the other operands. */
2472 operand
->skip
= skip_p
;
2476 /* Relocation modifiers. Each entry in the table contains the textual
2477 name for the relocation which may be placed before a symbol used as
2478 a load/store offset, or add immediate. It must be surrounded by a
2479 leading and trailing colon, for example:
2481 ldr x0, [x1, #:rello:varsym]
2482 add x0, x1, #:rello:varsym */
2484 struct reloc_table_entry
2488 bfd_reloc_code_real_type adr_type
;
2489 bfd_reloc_code_real_type adrp_type
;
2490 bfd_reloc_code_real_type movw_type
;
2491 bfd_reloc_code_real_type add_type
;
2492 bfd_reloc_code_real_type ldst_type
;
2493 bfd_reloc_code_real_type ld_literal_type
;
2496 static struct reloc_table_entry reloc_table
[] =
2498 /* Low 12 bits of absolute address: ADD/i and LDR/STR */
2503 BFD_RELOC_AARCH64_ADD_LO12
,
2504 BFD_RELOC_AARCH64_LDST_LO12
,
2507 /* Higher 21 bits of pc-relative page offset: ADRP */
2510 BFD_RELOC_AARCH64_ADR_HI21_PCREL
,
2516 /* Higher 21 bits of pc-relative page offset: ADRP, no check */
2519 BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
,
2525 /* Most significant bits 0-15 of unsigned address/value: MOVZ */
2529 BFD_RELOC_AARCH64_MOVW_G0
,
2534 /* Most significant bits 0-15 of signed address/value: MOVN/Z */
2538 BFD_RELOC_AARCH64_MOVW_G0_S
,
2543 /* Less significant bits 0-15 of address/value: MOVK, no check */
2547 BFD_RELOC_AARCH64_MOVW_G0_NC
,
2552 /* Most significant bits 16-31 of unsigned address/value: MOVZ */
2556 BFD_RELOC_AARCH64_MOVW_G1
,
2561 /* Most significant bits 16-31 of signed address/value: MOVN/Z */
2565 BFD_RELOC_AARCH64_MOVW_G1_S
,
2570 /* Less significant bits 16-31 of address/value: MOVK, no check */
2574 BFD_RELOC_AARCH64_MOVW_G1_NC
,
2579 /* Most significant bits 32-47 of unsigned address/value: MOVZ */
2583 BFD_RELOC_AARCH64_MOVW_G2
,
2588 /* Most significant bits 32-47 of signed address/value: MOVN/Z */
2592 BFD_RELOC_AARCH64_MOVW_G2_S
,
2597 /* Less significant bits 32-47 of address/value: MOVK, no check */
2601 BFD_RELOC_AARCH64_MOVW_G2_NC
,
2606 /* Most significant bits 48-63 of signed/unsigned address/value: MOVZ */
2610 BFD_RELOC_AARCH64_MOVW_G3
,
2615 /* Most significant bits 0-15 of signed/unsigned address/value: MOVZ */
2619 BFD_RELOC_AARCH64_MOVW_PREL_G0
,
2624 /* Most significant bits 0-15 of signed/unsigned address/value: MOVK */
2628 BFD_RELOC_AARCH64_MOVW_PREL_G0_NC
,
2633 /* Most significant bits 16-31 of signed/unsigned address/value: MOVZ */
2637 BFD_RELOC_AARCH64_MOVW_PREL_G1
,
2642 /* Most significant bits 16-31 of signed/unsigned address/value: MOVK */
2646 BFD_RELOC_AARCH64_MOVW_PREL_G1_NC
,
2651 /* Most significant bits 32-47 of signed/unsigned address/value: MOVZ */
2655 BFD_RELOC_AARCH64_MOVW_PREL_G2
,
2660 /* Most significant bits 32-47 of signed/unsigned address/value: MOVK */
2664 BFD_RELOC_AARCH64_MOVW_PREL_G2_NC
,
2669 /* Most significant bits 48-63 of signed/unsigned address/value: MOVZ */
2673 BFD_RELOC_AARCH64_MOVW_PREL_G3
,
2678 /* Get to the page containing GOT entry for a symbol. */
2681 BFD_RELOC_AARCH64_ADR_GOT_PAGE
,
2685 BFD_RELOC_AARCH64_GOT_LD_PREL19
},
2687 /* 12 bit offset into the page containing GOT entry for that symbol. */
2693 BFD_RELOC_AARCH64_LD_GOT_LO12_NC
,
2696 /* 0-15 bits of address/value: MOVk, no check. */
2700 BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
,
2705 /* Most significant bits 16-31 of address/value: MOVZ. */
2709 BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
,
2714 /* 15 bit offset into the page containing GOT entry for that symbol. */
2720 BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
,
2723 /* Get to the page containing GOT TLS entry for a symbol */
2724 {"gottprel_g0_nc", 0,
2727 BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
,
2732 /* Get to the page containing GOT TLS entry for a symbol */
2736 BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
,
2741 /* Get to the page containing GOT TLS entry for a symbol */
2743 BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
, /* adr_type */
2744 BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
,
2750 /* 12 bit offset into the page containing GOT TLS entry for a symbol */
2755 BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
,
2759 /* Lower 16 bits address/value: MOVk. */
2763 BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
,
2768 /* Most significant bits 16-31 of address/value: MOVZ. */
2772 BFD_RELOC_AARCH64_TLSGD_MOVW_G1
,
2777 /* Get to the page containing GOT TLS entry for a symbol */
2779 BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
, /* adr_type */
2780 BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
,
2784 BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
},
2786 /* 12 bit offset into the page containing GOT TLS entry for a symbol */
2791 BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
,
2792 BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC
,
2795 /* Get to the page containing GOT TLS entry for a symbol.
2796 The same as GD, we allocate two consecutive GOT slots
2797 for module index and module offset, the only difference
2798 with GD is the module offset should be initialized to
2799 zero without any outstanding runtime relocation. */
2801 BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
, /* adr_type */
2802 BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
,
2808 /* 12 bit offset into the page containing GOT TLS entry for a symbol */
2809 {"tlsldm_lo12_nc", 0,
2813 BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
,
2817 /* 12 bit offset into the module TLS base address. */
2822 BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
,
2823 BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12
,
2826 /* Same as dtprel_lo12, no overflow check. */
2827 {"dtprel_lo12_nc", 0,
2831 BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
,
2832 BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC
,
2835 /* bits[23:12] of offset to the module TLS base address. */
2840 BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
,
2844 /* bits[15:0] of offset to the module TLS base address. */
2848 BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
,
2853 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */
2857 BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
,
2862 /* bits[31:16] of offset to the module TLS base address. */
2866 BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
,
2871 /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */
2875 BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
,
2880 /* bits[47:32] of offset to the module TLS base address. */
2884 BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
,
2889 /* Lower 16 bit offset into GOT entry for a symbol */
2890 {"tlsdesc_off_g0_nc", 0,
2893 BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
,
2898 /* Higher 16 bit offset into GOT entry for a symbol */
2899 {"tlsdesc_off_g1", 0,
2902 BFD_RELOC_AARCH64_TLSDESC_OFF_G1
,
2907 /* Get to the page containing GOT TLS entry for a symbol */
2910 BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
,
2914 BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
},
2916 /* 12 bit offset into the page containing GOT TLS entry for a symbol */
2917 {"gottprel_lo12", 0,
2922 BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC
,
2925 /* Get tp offset for a symbol. */
2930 BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
,
2934 /* Get tp offset for a symbol. */
2939 BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
,
2940 BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12
,
2943 /* Get tp offset for a symbol. */
2948 BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
,
2952 /* Get tp offset for a symbol. */
2953 {"tprel_lo12_nc", 0,
2957 BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
,
2958 BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC
,
2961 /* Most significant bits 32-47 of address/value: MOVZ. */
2965 BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
,
2970 /* Most significant bits 16-31 of address/value: MOVZ. */
2974 BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
,
2979 /* Most significant bits 16-31 of address/value: MOVZ, no check. */
2983 BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
,
2988 /* Most significant bits 0-15 of address/value: MOVZ. */
2992 BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
,
2997 /* Most significant bits 0-15 of address/value: MOVZ, no check. */
3001 BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
,
3006 /* 15bit offset from got entry to base address of GOT table. */
3012 BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
,
3015 /* 14bit offset from got entry to base address of GOT table. */
3021 BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
,
3025 /* Given the address of a pointer pointing to the textual name of a
3026 relocation as may appear in assembler source, attempt to find its
3027 details in reloc_table. The pointer will be updated to the character
3028 after the trailing colon. On failure, NULL will be returned;
3029 otherwise return the reloc_table_entry. */
3031 static struct reloc_table_entry
*
3032 find_reloc_table_entry (char **str
)
3035 for (i
= 0; i
< ARRAY_SIZE (reloc_table
); i
++)
3037 int length
= strlen (reloc_table
[i
].name
);
3039 if (strncasecmp (reloc_table
[i
].name
, *str
, length
) == 0
3040 && (*str
)[length
] == ':')
3042 *str
+= (length
+ 1);
3043 return &reloc_table
[i
];
3050 /* Returns 0 if the relocation should never be forced,
3051 1 if the relocation must be forced, and -1 if either
3055 aarch64_force_reloc (unsigned int type
)
3059 case BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP
:
3060 /* Perform these "immediate" internal relocations
3061 even if the symbol is extern or weak. */
3064 case BFD_RELOC_AARCH64_LD_GOT_LO12_NC
:
3065 case BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC
:
3066 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC
:
3067 /* Pseudo relocs that need to be fixed up according to
3071 case BFD_RELOC_AARCH64_ADD_LO12
:
3072 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
3073 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
3074 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
3075 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
3076 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
3077 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
3078 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
3079 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
3080 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
3081 case BFD_RELOC_AARCH64_LDST128_LO12
:
3082 case BFD_RELOC_AARCH64_LDST16_LO12
:
3083 case BFD_RELOC_AARCH64_LDST32_LO12
:
3084 case BFD_RELOC_AARCH64_LDST64_LO12
:
3085 case BFD_RELOC_AARCH64_LDST8_LO12
:
3086 case BFD_RELOC_AARCH64_LDST_LO12
:
3087 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
3088 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
3089 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
3090 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
3091 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
3092 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
3093 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
3094 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
3095 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
3096 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
3097 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
3098 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
3099 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
3100 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
3101 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
3102 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
3103 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
3104 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
3105 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
3106 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
3107 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
3108 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
3109 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
3110 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
3111 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
3112 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
3113 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
3114 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
3115 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
3116 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
3117 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
3118 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
3119 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
3120 case BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12
:
3121 case BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC
:
3122 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
3123 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
3124 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
3125 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
3126 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
3127 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12
:
3128 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
:
3129 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12
:
3130 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
:
3131 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12
:
3132 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
:
3133 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12
:
3134 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
:
3135 case BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12
:
3136 case BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC
:
3137 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
3138 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
3139 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
3140 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
3141 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
3142 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
3143 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
3144 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
3145 /* Always leave these relocations for the linker. */
3154 aarch64_force_relocation (struct fix
*fixp
)
3156 int res
= aarch64_force_reloc (fixp
->fx_r_type
);
3159 return generic_force_reloc (fixp
);
3163 /* Mode argument to parse_shift and parser_shifter_operand. */
3164 enum parse_shift_mode
3166 SHIFTED_NONE
, /* no shifter allowed */
3167 SHIFTED_ARITH_IMM
, /* "rn{,lsl|lsr|asl|asr|uxt|sxt #n}" or
3169 SHIFTED_LOGIC_IMM
, /* "rn{,lsl|lsr|asl|asr|ror #n}" or
3171 SHIFTED_LSL
, /* bare "lsl #n" */
3172 SHIFTED_MUL
, /* bare "mul #n" */
3173 SHIFTED_LSL_MSL
, /* "lsl|msl #n" */
3174 SHIFTED_MUL_VL
, /* "mul vl" */
3175 SHIFTED_REG_OFFSET
/* [su]xtw|sxtx {#n} or lsl #n */
3178 /* Parse a <shift> operator on an AArch64 data processing instruction.
3179 Return TRUE on success; otherwise return FALSE. */
3181 parse_shift (char **str
, aarch64_opnd_info
*operand
, enum parse_shift_mode mode
)
3183 const struct aarch64_name_value_pair
*shift_op
;
3184 enum aarch64_modifier_kind kind
;
3190 for (p
= *str
; ISALPHA (*p
); p
++)
3195 set_syntax_error (_("shift expression expected"));
3199 shift_op
= str_hash_find_n (aarch64_shift_hsh
, *str
, p
- *str
);
3201 if (shift_op
== NULL
)
3203 set_syntax_error (_("shift operator expected"));
3207 kind
= aarch64_get_operand_modifier (shift_op
);
3209 if (kind
== AARCH64_MOD_MSL
&& mode
!= SHIFTED_LSL_MSL
)
3211 set_syntax_error (_("invalid use of 'MSL'"));
3215 if (kind
== AARCH64_MOD_MUL
3216 && mode
!= SHIFTED_MUL
3217 && mode
!= SHIFTED_MUL_VL
)
3219 set_syntax_error (_("invalid use of 'MUL'"));
3225 case SHIFTED_LOGIC_IMM
:
3226 if (aarch64_extend_operator_p (kind
))
3228 set_syntax_error (_("extending shift is not permitted"));
3233 case SHIFTED_ARITH_IMM
:
3234 if (kind
== AARCH64_MOD_ROR
)
3236 set_syntax_error (_("'ROR' shift is not permitted"));
3242 if (kind
!= AARCH64_MOD_LSL
)
3244 set_syntax_error (_("only 'LSL' shift is permitted"));
3250 if (kind
!= AARCH64_MOD_MUL
)
3252 set_syntax_error (_("only 'MUL' is permitted"));
3257 case SHIFTED_MUL_VL
:
3258 /* "MUL VL" consists of two separate tokens. Require the first
3259 token to be "MUL" and look for a following "VL". */
3260 if (kind
== AARCH64_MOD_MUL
)
3262 skip_whitespace (p
);
3263 if (strncasecmp (p
, "vl", 2) == 0 && !ISALPHA (p
[2]))
3266 kind
= AARCH64_MOD_MUL_VL
;
3270 set_syntax_error (_("only 'MUL VL' is permitted"));
3273 case SHIFTED_REG_OFFSET
:
3274 if (kind
!= AARCH64_MOD_UXTW
&& kind
!= AARCH64_MOD_LSL
3275 && kind
!= AARCH64_MOD_SXTW
&& kind
!= AARCH64_MOD_SXTX
)
3277 set_fatal_syntax_error
3278 (_("invalid shift for the register offset addressing mode"));
3283 case SHIFTED_LSL_MSL
:
3284 if (kind
!= AARCH64_MOD_LSL
&& kind
!= AARCH64_MOD_MSL
)
3286 set_syntax_error (_("invalid shift operator"));
3295 /* Whitespace can appear here if the next thing is a bare digit. */
3296 skip_whitespace (p
);
3298 /* Parse shift amount. */
3300 if ((mode
== SHIFTED_REG_OFFSET
&& *p
== ']') || kind
== AARCH64_MOD_MUL_VL
)
3301 exp
.X_op
= O_absent
;
3304 if (is_immediate_prefix (*p
))
3309 aarch64_get_expression (&exp
, &p
, GE_NO_PREFIX
, ALLOW_ABSENT
);
3311 if (kind
== AARCH64_MOD_MUL_VL
)
3312 /* For consistency, give MUL VL the same shift amount as an implicit
3314 operand
->shifter
.amount
= 1;
3315 else if (exp
.X_op
== O_absent
)
3317 if (!aarch64_extend_operator_p (kind
) || exp_has_prefix
)
3319 set_syntax_error (_("missing shift amount"));
3322 operand
->shifter
.amount
= 0;
3324 else if (exp
.X_op
!= O_constant
)
3326 set_syntax_error (_("constant shift amount required"));
3329 /* For parsing purposes, MUL #n has no inherent range. The range
3330 depends on the operand and will be checked by operand-specific
3332 else if (kind
!= AARCH64_MOD_MUL
3333 && (exp
.X_add_number
< 0 || exp
.X_add_number
> 63))
3335 set_fatal_syntax_error (_("shift amount out of range 0 to 63"));
3340 operand
->shifter
.amount
= exp
.X_add_number
;
3341 operand
->shifter
.amount_present
= 1;
3344 operand
->shifter
.operator_present
= 1;
3345 operand
->shifter
.kind
= kind
;
3351 /* Parse a <shifter_operand> for a data processing instruction:
3354 #<immediate>, LSL #imm
3356 Validation of immediate operands is deferred to md_apply_fix.
3358 Return TRUE on success; otherwise return FALSE. */
3361 parse_shifter_operand_imm (char **str
, aarch64_opnd_info
*operand
,
3362 enum parse_shift_mode mode
)
3366 if (mode
!= SHIFTED_ARITH_IMM
&& mode
!= SHIFTED_LOGIC_IMM
)
3371 /* Accept an immediate expression. */
3372 if (! aarch64_get_expression (&inst
.reloc
.exp
, &p
, GE_OPT_PREFIX
,
3376 /* Accept optional LSL for arithmetic immediate values. */
3377 if (mode
== SHIFTED_ARITH_IMM
&& skip_past_comma (&p
))
3378 if (! parse_shift (&p
, operand
, SHIFTED_LSL
))
3381 /* Not accept any shifter for logical immediate values. */
3382 if (mode
== SHIFTED_LOGIC_IMM
&& skip_past_comma (&p
)
3383 && parse_shift (&p
, operand
, mode
))
3385 set_syntax_error (_("unexpected shift operator"));
3393 /* Parse a <shifter_operand> for a data processing instruction:
3398 #<immediate>, LSL #imm
3400 where <shift> is handled by parse_shift above, and the last two
3401 cases are handled by the function above.
3403 Validation of immediate operands is deferred to md_apply_fix.
3405 Return TRUE on success; otherwise return FALSE. */
3408 parse_shifter_operand (char **str
, aarch64_opnd_info
*operand
,
3409 enum parse_shift_mode mode
)
3411 const reg_entry
*reg
;
3412 aarch64_opnd_qualifier_t qualifier
;
3413 enum aarch64_operand_class opd_class
3414 = aarch64_get_operand_class (operand
->type
);
3416 reg
= aarch64_reg_parse_32_64 (str
, &qualifier
);
3419 if (opd_class
== AARCH64_OPND_CLASS_IMMEDIATE
)
3421 set_syntax_error (_("unexpected register in the immediate operand"));
3425 if (!aarch64_check_reg_type (reg
, REG_TYPE_R_Z
))
3427 set_syntax_error (_(get_reg_expected_msg (REG_TYPE_R_Z
)));
3431 operand
->reg
.regno
= reg
->number
;
3432 operand
->qualifier
= qualifier
;
3434 /* Accept optional shift operation on register. */
3435 if (! skip_past_comma (str
))
3438 if (! parse_shift (str
, operand
, mode
))
3443 else if (opd_class
== AARCH64_OPND_CLASS_MODIFIED_REG
)
3446 (_("integer register expected in the extended/shifted operand "
3451 /* We have a shifted immediate variable. */
3452 return parse_shifter_operand_imm (str
, operand
, mode
);
3455 /* Return TRUE on success; return FALSE otherwise. */
3458 parse_shifter_operand_reloc (char **str
, aarch64_opnd_info
*operand
,
3459 enum parse_shift_mode mode
)
3463 /* Determine if we have the sequence of characters #: or just :
3464 coming next. If we do, then we check for a :rello: relocation
3465 modifier. If we don't, punt the whole lot to
3466 parse_shifter_operand. */
3468 if ((p
[0] == '#' && p
[1] == ':') || p
[0] == ':')
3470 struct reloc_table_entry
*entry
;
3478 /* Try to parse a relocation. Anything else is an error. */
3479 if (!(entry
= find_reloc_table_entry (str
)))
3481 set_syntax_error (_("unknown relocation modifier"));
3485 if (entry
->add_type
== 0)
3488 (_("this relocation modifier is not allowed on this instruction"));
3492 /* Save str before we decompose it. */
3495 /* Next, we parse the expression. */
3496 if (! aarch64_get_expression (&inst
.reloc
.exp
, str
, GE_NO_PREFIX
,
3500 /* Record the relocation type (use the ADD variant here). */
3501 inst
.reloc
.type
= entry
->add_type
;
3502 inst
.reloc
.pc_rel
= entry
->pc_rel
;
3504 /* If str is empty, we've reached the end, stop here. */
3508 /* Otherwise, we have a shifted reloc modifier, so rewind to
3509 recover the variable name and continue parsing for the shifter. */
3511 return parse_shifter_operand_imm (str
, operand
, mode
);
3514 return parse_shifter_operand (str
, operand
, mode
);
3517 /* Parse all forms of an address expression. Information is written
3518 to *OPERAND and/or inst.reloc.
3520 The A64 instruction set has the following addressing modes:
3523 [base] // in SIMD ld/st structure
3524 [base{,#0}] // in ld/st exclusive
3526 [base,Xm{,LSL #imm}]
3527 [base,Xm,SXTX {#imm}]
3528 [base,Wm,(S|U)XTW {#imm}]
3530 [base]! // in ldraa/ldrab exclusive
3534 [base],Xm // in SIMD ld/st structure
3535 PC-relative (literal)
3539 [base,Zm.D{,LSL #imm}]
3540 [base,Zm.S,(S|U)XTW {#imm}]
3541 [base,Zm.D,(S|U)XTW {#imm}] // ignores top 32 bits of Zm.D elements
3545 [Zn.S,Zm.S{,LSL #imm}] // in ADR
3546 [Zn.D,Zm.D{,LSL #imm}] // in ADR
3547 [Zn.D,Zm.D,(S|U)XTW {#imm}] // in ADR
3549 (As a convenience, the notation "=immediate" is permitted in conjunction
3550 with the pc-relative literal load instructions to automatically place an
3551 immediate value or symbolic address in a nearby literal pool and generate
3552 a hidden label which references it.)
3554 Upon a successful parsing, the address structure in *OPERAND will be
3555 filled in the following way:
3557 .base_regno = <base>
3558 .offset.is_reg // 1 if the offset is a register
3560 .offset.regno = <Rm>
3562 For different addressing modes defined in the A64 ISA:
3565 .pcrel=0; .preind=1; .postind=0; .writeback=0
3567 .pcrel=0; .preind=1; .postind=0; .writeback=1
3569 .pcrel=0; .preind=0; .postind=1; .writeback=1
3570 PC-relative (literal)
3571 .pcrel=1; .preind=1; .postind=0; .writeback=0
3573 The shift/extension information, if any, will be stored in .shifter.
3574 The base and offset qualifiers will be stored in *BASE_QUALIFIER and
3575 *OFFSET_QUALIFIER respectively, with NIL being used if there's no
3576 corresponding register.
3578 BASE_TYPE says which types of base register should be accepted and
3579 OFFSET_TYPE says the same for offset registers. IMM_SHIFT_MODE
3580 is the type of shifter that is allowed for immediate offsets,
3581 or SHIFTED_NONE if none.
3583 In all other respects, it is the caller's responsibility to check
3584 for addressing modes not supported by the instruction, and to set
3588 parse_address_main (char **str
, aarch64_opnd_info
*operand
,
3589 aarch64_opnd_qualifier_t
*base_qualifier
,
3590 aarch64_opnd_qualifier_t
*offset_qualifier
,
3591 aarch64_reg_type base_type
, aarch64_reg_type offset_type
,
3592 enum parse_shift_mode imm_shift_mode
)
3595 const reg_entry
*reg
;
3596 expressionS
*exp
= &inst
.reloc
.exp
;
3598 *base_qualifier
= AARCH64_OPND_QLF_NIL
;
3599 *offset_qualifier
= AARCH64_OPND_QLF_NIL
;
3600 if (! skip_past_char (&p
, '['))
3602 /* =immediate or label. */
3603 operand
->addr
.pcrel
= 1;
3604 operand
->addr
.preind
= 1;
3606 /* #:<reloc_op>:<symbol> */
3607 skip_past_char (&p
, '#');
3608 if (skip_past_char (&p
, ':'))
3610 bfd_reloc_code_real_type ty
;
3611 struct reloc_table_entry
*entry
;
3613 /* Try to parse a relocation modifier. Anything else is
3615 entry
= find_reloc_table_entry (&p
);
3618 set_syntax_error (_("unknown relocation modifier"));
3622 switch (operand
->type
)
3624 case AARCH64_OPND_ADDR_PCREL21
:
3626 ty
= entry
->adr_type
;
3630 ty
= entry
->ld_literal_type
;
3637 (_("this relocation modifier is not allowed on this "
3643 if (! aarch64_get_expression (exp
, &p
, GE_NO_PREFIX
, REJECT_ABSENT
))
3645 set_syntax_error (_("invalid relocation expression"));
3648 /* #:<reloc_op>:<expr> */
3649 /* Record the relocation type. */
3650 inst
.reloc
.type
= ty
;
3651 inst
.reloc
.pc_rel
= entry
->pc_rel
;
3655 if (skip_past_char (&p
, '='))
3656 /* =immediate; need to generate the literal in the literal pool. */
3657 inst
.gen_lit_pool
= 1;
3659 if (!aarch64_get_expression (exp
, &p
, GE_NO_PREFIX
, REJECT_ABSENT
))
3661 set_syntax_error (_("invalid address"));
3672 reg
= aarch64_addr_reg_parse (&p
, base_type
, base_qualifier
);
3673 if (!reg
|| !aarch64_check_reg_type (reg
, base_type
))
3675 set_syntax_error (_(get_reg_expected_msg (base_type
)));
3678 operand
->addr
.base_regno
= reg
->number
;
3681 if (skip_past_comma (&p
))
3684 operand
->addr
.preind
= 1;
3686 reg
= aarch64_addr_reg_parse (&p
, offset_type
, offset_qualifier
);
3689 if (!aarch64_check_reg_type (reg
, offset_type
))
3691 set_syntax_error (_(get_reg_expected_msg (offset_type
)));
3696 operand
->addr
.offset
.regno
= reg
->number
;
3697 operand
->addr
.offset
.is_reg
= 1;
3698 /* Shifted index. */
3699 if (skip_past_comma (&p
))
3702 if (! parse_shift (&p
, operand
, SHIFTED_REG_OFFSET
))
3703 /* Use the diagnostics set in parse_shift, so not set new
3704 error message here. */
3708 [base,Xm] # For vector plus scalar SVE2 indexing.
3709 [base,Xm{,LSL #imm}]
3710 [base,Xm,SXTX {#imm}]
3711 [base,Wm,(S|U)XTW {#imm}] */
3712 if (operand
->shifter
.kind
== AARCH64_MOD_NONE
3713 || operand
->shifter
.kind
== AARCH64_MOD_LSL
3714 || operand
->shifter
.kind
== AARCH64_MOD_SXTX
)
3716 if (*offset_qualifier
== AARCH64_OPND_QLF_W
)
3718 set_syntax_error (_("invalid use of 32-bit register offset"));
3721 if (aarch64_get_qualifier_esize (*base_qualifier
)
3722 != aarch64_get_qualifier_esize (*offset_qualifier
)
3723 && (operand
->type
!= AARCH64_OPND_SVE_ADDR_ZX
3724 || *base_qualifier
!= AARCH64_OPND_QLF_S_S
3725 || *offset_qualifier
!= AARCH64_OPND_QLF_X
))
3727 set_syntax_error (_("offset has different size from base"));
3731 else if (*offset_qualifier
== AARCH64_OPND_QLF_X
)
3733 set_syntax_error (_("invalid use of 64-bit register offset"));
3739 /* [Xn,#:<reloc_op>:<symbol> */
3740 skip_past_char (&p
, '#');
3741 if (skip_past_char (&p
, ':'))
3743 struct reloc_table_entry
*entry
;
3745 /* Try to parse a relocation modifier. Anything else is
3747 if (!(entry
= find_reloc_table_entry (&p
)))
3749 set_syntax_error (_("unknown relocation modifier"));
3753 if (entry
->ldst_type
== 0)
3756 (_("this relocation modifier is not allowed on this "
3761 /* [Xn,#:<reloc_op>: */
3762 /* We now have the group relocation table entry corresponding to
3763 the name in the assembler source. Next, we parse the
3765 if (! aarch64_get_expression (exp
, &p
, GE_NO_PREFIX
, REJECT_ABSENT
))
3767 set_syntax_error (_("invalid relocation expression"));
3771 /* [Xn,#:<reloc_op>:<expr> */
3772 /* Record the load/store relocation type. */
3773 inst
.reloc
.type
= entry
->ldst_type
;
3774 inst
.reloc
.pc_rel
= entry
->pc_rel
;
3778 if (! aarch64_get_expression (exp
, &p
, GE_OPT_PREFIX
, REJECT_ABSENT
))
3780 set_syntax_error (_("invalid expression in the address"));
3784 if (imm_shift_mode
!= SHIFTED_NONE
&& skip_past_comma (&p
))
3785 /* [Xn,<expr>,<shifter> */
3786 if (! parse_shift (&p
, operand
, imm_shift_mode
))
3792 if (! skip_past_char (&p
, ']'))
3794 set_syntax_error (_("']' expected"));
3798 if (skip_past_char (&p
, '!'))
3800 if (operand
->addr
.preind
&& operand
->addr
.offset
.is_reg
)
3802 set_syntax_error (_("register offset not allowed in pre-indexed "
3803 "addressing mode"));
3807 operand
->addr
.writeback
= 1;
3809 else if (skip_past_comma (&p
))
3812 operand
->addr
.postind
= 1;
3813 operand
->addr
.writeback
= 1;
3815 if (operand
->addr
.preind
)
3817 set_syntax_error (_("cannot combine pre- and post-indexing"));
3821 reg
= aarch64_reg_parse_32_64 (&p
, offset_qualifier
);
3825 if (!aarch64_check_reg_type (reg
, REG_TYPE_R_64
))
3827 set_syntax_error (_(get_reg_expected_msg (REG_TYPE_R_64
)));
3831 operand
->addr
.offset
.regno
= reg
->number
;
3832 operand
->addr
.offset
.is_reg
= 1;
3834 else if (! aarch64_get_expression (exp
, &p
, GE_OPT_PREFIX
, REJECT_ABSENT
))
3837 set_syntax_error (_("invalid expression in the address"));
3842 /* If at this point neither .preind nor .postind is set, we have a
3843 bare [Rn]{!}; only accept [Rn]! as a shorthand for [Rn,#0]! for ldraa and
3844 ldrab, accept [Rn] as a shorthand for [Rn,#0].
3845 For SVE2 vector plus scalar offsets, allow [Zn.<T>] as shorthand for
3847 if (operand
->addr
.preind
== 0 && operand
->addr
.postind
== 0)
3849 if (operand
->addr
.writeback
)
3851 if (operand
->type
== AARCH64_OPND_ADDR_SIMM10
)
3853 /* Accept [Rn]! as a shorthand for [Rn,#0]! */
3854 operand
->addr
.offset
.is_reg
= 0;
3855 operand
->addr
.offset
.imm
= 0;
3856 operand
->addr
.preind
= 1;
3861 set_syntax_error (_("missing offset in the pre-indexed address"));
3867 operand
->addr
.preind
= 1;
3868 if (operand
->type
== AARCH64_OPND_SVE_ADDR_ZX
)
3870 operand
->addr
.offset
.is_reg
= 1;
3871 operand
->addr
.offset
.regno
= REG_ZR
;
3872 *offset_qualifier
= AARCH64_OPND_QLF_X
;
3876 inst
.reloc
.exp
.X_op
= O_constant
;
3877 inst
.reloc
.exp
.X_add_number
= 0;
3886 /* Parse a base AArch64 address (as opposed to an SVE one). Return TRUE
3889 parse_address (char **str
, aarch64_opnd_info
*operand
)
3891 aarch64_opnd_qualifier_t base_qualifier
, offset_qualifier
;
3892 return parse_address_main (str
, operand
, &base_qualifier
, &offset_qualifier
,
3893 REG_TYPE_R64_SP
, REG_TYPE_R_Z
, SHIFTED_NONE
);
3896 /* Parse an address in which SVE vector registers and MUL VL are allowed.
3897 The arguments have the same meaning as for parse_address_main.
3898 Return TRUE on success. */
3900 parse_sve_address (char **str
, aarch64_opnd_info
*operand
,
3901 aarch64_opnd_qualifier_t
*base_qualifier
,
3902 aarch64_opnd_qualifier_t
*offset_qualifier
)
3904 return parse_address_main (str
, operand
, base_qualifier
, offset_qualifier
,
3905 REG_TYPE_SVE_BASE
, REG_TYPE_SVE_OFFSET
,
3909 /* Parse a register X0-X30. The register must be 64-bit and register 31
3912 parse_x0_to_x30 (char **str
, aarch64_opnd_info
*operand
)
3914 const reg_entry
*reg
= parse_reg (str
);
3915 if (!reg
|| !aarch64_check_reg_type (reg
, REG_TYPE_R_64
))
3917 set_syntax_error (_(get_reg_expected_msg (REG_TYPE_R_64
)));
3920 operand
->reg
.regno
= reg
->number
;
3921 operand
->qualifier
= AARCH64_OPND_QLF_X
;
3925 /* Parse an operand for a MOVZ, MOVN or MOVK instruction.
3926 Return TRUE on success; otherwise return FALSE. */
3928 parse_half (char **str
, int *internal_fixup_p
)
3932 skip_past_char (&p
, '#');
3934 gas_assert (internal_fixup_p
);
3935 *internal_fixup_p
= 0;
3939 struct reloc_table_entry
*entry
;
3941 /* Try to parse a relocation. Anything else is an error. */
3944 if (!(entry
= find_reloc_table_entry (&p
)))
3946 set_syntax_error (_("unknown relocation modifier"));
3950 if (entry
->movw_type
== 0)
3953 (_("this relocation modifier is not allowed on this instruction"));
3957 inst
.reloc
.type
= entry
->movw_type
;
3960 *internal_fixup_p
= 1;
3962 if (! aarch64_get_expression (&inst
.reloc
.exp
, &p
, GE_NO_PREFIX
, REJECT_ABSENT
))
3969 /* Parse an operand for an ADRP instruction:
3971 Return TRUE on success; otherwise return FALSE. */
3974 parse_adrp (char **str
)
3981 struct reloc_table_entry
*entry
;
3983 /* Try to parse a relocation. Anything else is an error. */
3985 if (!(entry
= find_reloc_table_entry (&p
)))
3987 set_syntax_error (_("unknown relocation modifier"));
3991 if (entry
->adrp_type
== 0)
3994 (_("this relocation modifier is not allowed on this instruction"));
3998 inst
.reloc
.type
= entry
->adrp_type
;
4001 inst
.reloc
.type
= BFD_RELOC_AARCH64_ADR_HI21_PCREL
;
4003 inst
.reloc
.pc_rel
= 1;
4004 if (! aarch64_get_expression (&inst
.reloc
.exp
, &p
, GE_NO_PREFIX
, REJECT_ABSENT
))
4010 /* Miscellaneous. */
4012 /* Parse a symbolic operand such as "pow2" at *STR. ARRAY is an array
4013 of SIZE tokens in which index I gives the token for field value I,
4014 or is null if field value I is invalid. REG_TYPE says which register
4015 names should be treated as registers rather than as symbolic immediates.
4017 Return true on success, moving *STR past the operand and storing the
4018 field value in *VAL. */
4021 parse_enum_string (char **str
, int64_t *val
, const char *const *array
,
4022 size_t size
, aarch64_reg_type reg_type
)
4028 /* Match C-like tokens. */
4030 while (ISALNUM (*q
))
4033 for (i
= 0; i
< size
; ++i
)
4035 && strncasecmp (array
[i
], p
, q
- p
) == 0
4036 && array
[i
][q
- p
] == 0)
4043 if (!parse_immediate_expression (&p
, &exp
, reg_type
))
4046 if (exp
.X_op
== O_constant
4047 && (uint64_t) exp
.X_add_number
< size
)
4049 *val
= exp
.X_add_number
;
4054 /* Use the default error for this operand. */
4058 /* Parse an option for a preload instruction. Returns the encoding for the
4059 option, or PARSE_FAIL. */
4062 parse_pldop (char **str
)
4065 const struct aarch64_name_value_pair
*o
;
4068 while (ISALNUM (*q
))
4071 o
= str_hash_find_n (aarch64_pldop_hsh
, p
, q
- p
);
4079 /* Parse an option for a barrier instruction. Returns the encoding for the
4080 option, or PARSE_FAIL. */
4083 parse_barrier (char **str
)
4086 const struct aarch64_name_value_pair
*o
;
4089 while (ISALPHA (*q
))
4092 o
= str_hash_find_n (aarch64_barrier_opt_hsh
, p
, q
- p
);
4100 /* Parse an operand for a PSB barrier. Set *HINT_OPT to the hint-option record
4101 return 0 if successful. Otherwise return PARSE_FAIL. */
4104 parse_barrier_psb (char **str
,
4105 const struct aarch64_name_value_pair
** hint_opt
)
4108 const struct aarch64_name_value_pair
*o
;
4111 while (ISALPHA (*q
))
4114 o
= str_hash_find_n (aarch64_hint_opt_hsh
, p
, q
- p
);
4117 set_fatal_syntax_error
4118 ( _("unknown or missing option to PSB/TSB"));
4122 if (o
->value
!= 0x11)
4124 /* PSB only accepts option name 'CSYNC'. */
4126 (_("the specified option is not accepted for PSB/TSB"));
4135 /* Parse an operand for BTI. Set *HINT_OPT to the hint-option record
4136 return 0 if successful. Otherwise return PARSE_FAIL. */
4139 parse_bti_operand (char **str
,
4140 const struct aarch64_name_value_pair
** hint_opt
)
4143 const struct aarch64_name_value_pair
*o
;
4146 while (ISALPHA (*q
))
4149 o
= str_hash_find_n (aarch64_hint_opt_hsh
, p
, q
- p
);
4152 set_fatal_syntax_error
4153 ( _("unknown option to BTI"));
4159 /* Valid BTI operands. */
4167 (_("unknown option to BTI"));
4176 /* Parse STR for reg of REG_TYPE and following '.' and QUALIFIER.
4177 Function returns REG_ENTRY struct and QUALIFIER [bhsdq] or NULL
4182 Side effect: Update STR with current parse position of success.
4185 static const reg_entry
*
4186 parse_reg_with_qual (char **str
, aarch64_reg_type reg_type
,
4187 aarch64_opnd_qualifier_t
*qualifier
)
4191 reg_entry
*reg
= parse_reg (str
);
4192 if (reg
!= NULL
&& reg
->type
== reg_type
)
4194 if (!skip_past_char (str
, '.'))
4196 set_syntax_error (_("missing ZA tile element size separator"));
4201 switch (TOLOWER (*q
))
4204 *qualifier
= AARCH64_OPND_QLF_S_B
;
4207 *qualifier
= AARCH64_OPND_QLF_S_H
;
4210 *qualifier
= AARCH64_OPND_QLF_S_S
;
4213 *qualifier
= AARCH64_OPND_QLF_S_D
;
4216 *qualifier
= AARCH64_OPND_QLF_S_Q
;
4230 /* Parse SME ZA tile encoded in <ZAda> assembler symbol.
4231 Function return tile QUALIFIER on success.
4233 Tiles are in example format: za[0-9]\.[bhsd]
4235 Function returns <ZAda> register number or PARSE_FAIL.
4238 parse_sme_zada_operand (char **str
, aarch64_opnd_qualifier_t
*qualifier
)
4241 const reg_entry
*reg
= parse_reg_with_qual (str
, REG_TYPE_ZA
, qualifier
);
4245 regno
= reg
->number
;
4249 case AARCH64_OPND_QLF_S_B
:
4252 set_syntax_error (_("invalid ZA tile register number, expected za0"));
4256 case AARCH64_OPND_QLF_S_H
:
4259 set_syntax_error (_("invalid ZA tile register number, expected za0-za1"));
4263 case AARCH64_OPND_QLF_S_S
:
4266 /* For the 32-bit variant: is the name of the ZA tile ZA0-ZA3. */
4267 set_syntax_error (_("invalid ZA tile register number, expected za0-za3"));
4271 case AARCH64_OPND_QLF_S_D
:
4274 /* For the 64-bit variant: is the name of the ZA tile ZA0-ZA7 */
4275 set_syntax_error (_("invalid ZA tile register number, expected za0-za7"));
4280 set_syntax_error (_("invalid ZA tile element size, allowed b, h, s and d"));
4287 /* Parse STR for unsigned, immediate (1-2 digits) in format:
4292 Function return TRUE if immediate was found, or FALSE.
4295 parse_sme_immediate (char **str
, int64_t *imm
)
4298 if (! parse_constant_immediate (str
, &val
, REG_TYPE_R_N
))
4305 /* Parse index with vector select register and immediate:
4309 where <Wv> is in W12-W15 range and # is optional for immediate.
4311 Function performs extra check for mandatory immediate value if REQUIRE_IMM
4314 On success function returns TRUE and populated VECTOR_SELECT_REGISTER and
4318 parse_sme_za_hv_tiles_operand_index (char **str
,
4319 int *vector_select_register
,
4322 const reg_entry
*reg
;
4324 if (!skip_past_char (str
, '['))
4326 set_syntax_error (_("expected '['"));
4330 /* Vector select register W12-W15 encoded in the 2-bit Rv field. */
4331 reg
= parse_reg (str
);
4332 if (reg
== NULL
|| reg
->type
!= REG_TYPE_R_32
4333 || reg
->number
< 12 || reg
->number
> 15)
4335 set_syntax_error (_("expected vector select register W12-W15"));
4338 *vector_select_register
= reg
->number
;
4340 if (!skip_past_char (str
, ',')) /* Optional index offset immediate. */
4342 set_syntax_error (_("expected ','"));
4346 if (!parse_sme_immediate (str
, imm
))
4348 set_syntax_error (_("index offset immediate expected"));
4352 if (!skip_past_char (str
, ']'))
4354 set_syntax_error (_("expected ']'"));
4361 /* Parse SME ZA horizontal or vertical vector access to tiles.
4362 Function extracts from STR to SLICE_INDICATOR <HV> horizontal (0) or
4363 vertical (1) ZA tile vector orientation. VECTOR_SELECT_REGISTER
4364 contains <Wv> select register and corresponding optional IMMEDIATE.
4365 In addition QUALIFIER is extracted.
4367 Field format examples:
4369 ZA0<HV>.B[<Wv>, #<imm>]
4370 <ZAn><HV>.H[<Wv>, #<imm>]
4371 <ZAn><HV>.S[<Wv>, #<imm>]
4372 <ZAn><HV>.D[<Wv>, #<imm>]
4373 <ZAn><HV>.Q[<Wv>, #<imm>]
4375 Function returns <ZAda> register number or PARSE_FAIL.
4378 parse_sme_za_hv_tiles_operand (char **str
,
4379 enum sme_hv_slice
*slice_indicator
,
4380 int *vector_select_register
,
4382 aarch64_opnd_qualifier_t
*qualifier
)
4389 const reg_entry
*reg
;
4392 if ((reg
= parse_reg_with_qual (&qh
, REG_TYPE_ZAH
, qualifier
)) != NULL
)
4394 *slice_indicator
= HV_horizontal
;
4397 else if ((reg
= parse_reg_with_qual (&qv
, REG_TYPE_ZAV
, qualifier
)) != NULL
)
4399 *slice_indicator
= HV_vertical
;
4404 regno
= reg
->number
;
4408 case AARCH64_OPND_QLF_S_B
:
4412 case AARCH64_OPND_QLF_S_H
:
4416 case AARCH64_OPND_QLF_S_S
:
4420 case AARCH64_OPND_QLF_S_D
:
4424 case AARCH64_OPND_QLF_S_Q
:
4429 set_syntax_error (_("invalid ZA tile element size, allowed b, h, s, d and q"));
4433 /* Check if destination register ZA tile vector is in range for given
4434 instruction variant. */
4435 if (regno
< 0 || regno
> regno_limit
)
4437 set_syntax_error (_("ZA tile vector out of range"));
4441 if (!parse_sme_za_hv_tiles_operand_index (str
, vector_select_register
,
4445 /* Check if optional index offset is in the range for instruction
4447 if (imm_value
< 0 || imm_value
> imm_limit
)
4449 set_syntax_error (_("index offset out of range"));
4460 parse_sme_za_hv_tiles_operand_with_braces (char **str
,
4461 enum sme_hv_slice
*slice_indicator
,
4462 int *vector_select_register
,
4464 aarch64_opnd_qualifier_t
*qualifier
)
4468 if (!skip_past_char (str
, '{'))
4470 set_syntax_error (_("expected '{'"));
4474 regno
= parse_sme_za_hv_tiles_operand (str
, slice_indicator
,
4475 vector_select_register
, imm
,
4478 if (regno
== PARSE_FAIL
)
4481 if (!skip_past_char (str
, '}'))
4483 set_syntax_error (_("expected '}'"));
4490 /* Parse list of up to eight 64-bit element tile names separated by commas in
4491 SME's ZERO instruction:
4495 Function returns <mask>:
4497 an 8-bit list of 64-bit element tiles named ZA0.D to ZA7.D.
4500 parse_sme_zero_mask(char **str
)
4504 aarch64_opnd_qualifier_t qualifier
;
4510 const reg_entry
*reg
= parse_reg_with_qual (&q
, REG_TYPE_ZA
, &qualifier
);
4513 int regno
= reg
->number
;
4514 if (qualifier
== AARCH64_OPND_QLF_S_B
&& regno
== 0)
4516 /* { ZA0.B } is assembled as all-ones immediate. */
4519 else if (qualifier
== AARCH64_OPND_QLF_S_H
&& regno
< 2)
4520 mask
|= 0x55 << regno
;
4521 else if (qualifier
== AARCH64_OPND_QLF_S_S
&& regno
< 4)
4522 mask
|= 0x11 << regno
;
4523 else if (qualifier
== AARCH64_OPND_QLF_S_D
&& regno
< 8)
4524 mask
|= 0x01 << regno
;
4527 set_syntax_error (_("wrong ZA tile element format"));
4532 else if (strncasecmp (q
, "za", 2) == 0
4535 /* { ZA } is assembled as all-ones immediate. */
4542 set_syntax_error (_("wrong ZA tile element format"));
4546 while (skip_past_char (&q
, ','));
4552 /* Wraps in curly braces <mask> operand ZERO instruction:
4556 Function returns value of <mask> bit-field.
4559 parse_sme_list_of_64bit_tiles (char **str
)
4563 if (!skip_past_char (str
, '{'))
4565 set_syntax_error (_("expected '{'"));
4569 /* Empty <mask> list is an all-zeros immediate. */
4570 if (!skip_past_char (str
, '}'))
4572 regno
= parse_sme_zero_mask (str
);
4573 if (regno
== PARSE_FAIL
)
4576 if (!skip_past_char (str
, '}'))
4578 set_syntax_error (_("expected '}'"));
4588 /* Parse ZA array operand used in e.g. STR and LDR instruction.
4594 Function returns <Wv> or PARSE_FAIL.
4597 parse_sme_za_array (char **str
, int *imm
)
4604 while (ISALPHA (*q
))
4607 if ((q
- p
!= 2) || strncasecmp ("za", p
, q
- p
) != 0)
4609 set_syntax_error (_("expected ZA array"));
4613 if (! parse_sme_za_hv_tiles_operand_index (&q
, ®no
, &imm_value
))
4616 if (imm_value
< 0 || imm_value
> 15)
4618 set_syntax_error (_("offset out of range"));
4627 /* Parse streaming mode operand for SMSTART and SMSTOP.
4631 Function returns 's' if SM or 'z' if ZM is parsed. Otherwise PARSE_FAIL.
4634 parse_sme_sm_za (char **str
)
4639 while (ISALPHA (*q
))
4643 || (strncasecmp ("sm", p
, 2) != 0 && strncasecmp ("za", p
, 2) != 0))
4645 set_syntax_error (_("expected SM or ZA operand"));
4650 return TOLOWER (p
[0]);
4653 /* Parse the name of the source scalable predicate register, the index base
4654 register W12-W15 and the element index. Function performs element index
4655 limit checks as well as qualifier type checks.
4657 <Pn>.<T>[<Wv>, <imm>]
4658 <Pn>.<T>[<Wv>, #<imm>]
4660 On success function sets <Wv> to INDEX_BASE_REG, <T> to QUALIFIER and
4662 Function returns <Pn>, or PARSE_FAIL.
4665 parse_sme_pred_reg_with_index(char **str
,
4666 int *index_base_reg
,
4668 aarch64_opnd_qualifier_t
*qualifier
)
4673 const reg_entry
*reg
= parse_reg_with_qual (str
, REG_TYPE_PN
, qualifier
);
4677 regno
= reg
->number
;
4681 case AARCH64_OPND_QLF_S_B
:
4684 case AARCH64_OPND_QLF_S_H
:
4687 case AARCH64_OPND_QLF_S_S
:
4690 case AARCH64_OPND_QLF_S_D
:
4694 set_syntax_error (_("wrong predicate register element size, allowed b, h, s and d"));
4698 if (! parse_sme_za_hv_tiles_operand_index (str
, index_base_reg
, &imm_value
))
4701 if (imm_value
< 0 || imm_value
> imm_limit
)
4703 set_syntax_error (_("element index out of range for given variant"));
4712 /* Parse a system register or a PSTATE field name for an MSR/MRS instruction.
4713 Returns the encoding for the option, or PARSE_FAIL.
4715 If IMPLE_DEFINED_P is non-zero, the function will also try to parse the
4716 implementation defined system register name S<op0>_<op1>_<Cn>_<Cm>_<op2>.
4718 If PSTATEFIELD_P is non-zero, the function will parse the name as a PSTATE
4719 field, otherwise as a system register.
4723 parse_sys_reg (char **str
, htab_t sys_regs
,
4724 int imple_defined_p
, int pstatefield_p
,
4728 char buf
[AARCH64_MAX_SYSREG_NAME_LEN
];
4729 const aarch64_sys_reg
*o
;
4733 for (q
= *str
; ISALNUM (*q
) || *q
== '_'; q
++)
4734 if (p
< buf
+ (sizeof (buf
) - 1))
4735 *p
++ = TOLOWER (*q
);
4738 /* If the name is longer than AARCH64_MAX_SYSREG_NAME_LEN then it cannot be a
4739 valid system register. This is enforced by construction of the hash
4741 if (p
- buf
!= q
- *str
)
4744 o
= str_hash_find (sys_regs
, buf
);
4747 if (!imple_defined_p
)
4751 /* Parse S<op0>_<op1>_<Cn>_<Cm>_<op2>. */
4752 unsigned int op0
, op1
, cn
, cm
, op2
;
4754 if (sscanf (buf
, "s%u_%u_c%u_c%u_%u", &op0
, &op1
, &cn
, &cm
, &op2
)
4757 if (op0
> 3 || op1
> 7 || cn
> 15 || cm
> 15 || op2
> 7)
4759 value
= (op0
<< 14) | (op1
<< 11) | (cn
<< 7) | (cm
<< 3) | op2
;
4766 if (pstatefield_p
&& !aarch64_pstatefield_supported_p (cpu_variant
, o
))
4767 as_bad (_("selected processor does not support PSTATE field "
4770 && !aarch64_sys_ins_reg_supported_p (cpu_variant
, o
->name
,
4771 o
->value
, o
->flags
, o
->features
))
4772 as_bad (_("selected processor does not support system register "
4774 if (aarch64_sys_reg_deprecated_p (o
->flags
))
4775 as_warn (_("system register name '%s' is deprecated and may be "
4776 "removed in a future release"), buf
);
4786 /* Parse a system reg for ic/dc/at/tlbi instructions. Returns the table entry
4787 for the option, or NULL. */
4789 static const aarch64_sys_ins_reg
*
4790 parse_sys_ins_reg (char **str
, htab_t sys_ins_regs
)
4793 char buf
[AARCH64_MAX_SYSREG_NAME_LEN
];
4794 const aarch64_sys_ins_reg
*o
;
4797 for (q
= *str
; ISALNUM (*q
) || *q
== '_'; q
++)
4798 if (p
< buf
+ (sizeof (buf
) - 1))
4799 *p
++ = TOLOWER (*q
);
4802 /* If the name is longer than AARCH64_MAX_SYSREG_NAME_LEN then it cannot be a
4803 valid system register. This is enforced by construction of the hash
4805 if (p
- buf
!= q
- *str
)
4808 o
= str_hash_find (sys_ins_regs
, buf
);
4812 if (!aarch64_sys_ins_reg_supported_p (cpu_variant
,
4813 o
->name
, o
->value
, o
->flags
, 0))
4814 as_bad (_("selected processor does not support system register "
4816 if (aarch64_sys_reg_deprecated_p (o
->flags
))
4817 as_warn (_("system register name '%s' is deprecated and may be "
4818 "removed in a future release"), buf
);
4824 #define po_char_or_fail(chr) do { \
4825 if (! skip_past_char (&str, chr)) \
4829 #define po_reg_or_fail(regtype) do { \
4830 val = aarch64_reg_parse (&str, regtype, &rtype, NULL); \
4831 if (val == PARSE_FAIL) \
4833 set_default_error (); \
4838 #define po_int_reg_or_fail(reg_type) do { \
4839 reg = aarch64_reg_parse_32_64 (&str, &qualifier); \
4840 if (!reg || !aarch64_check_reg_type (reg, reg_type)) \
4842 set_default_error (); \
4845 info->reg.regno = reg->number; \
4846 info->qualifier = qualifier; \
4849 #define po_imm_nc_or_fail() do { \
4850 if (! parse_constant_immediate (&str, &val, imm_reg_type)) \
4854 #define po_imm_or_fail(min, max) do { \
4855 if (! parse_constant_immediate (&str, &val, imm_reg_type)) \
4857 if (val < min || val > max) \
4859 set_fatal_syntax_error (_("immediate value out of range "\
4860 #min " to "#max)); \
4865 #define po_enum_or_fail(array) do { \
4866 if (!parse_enum_string (&str, &val, array, \
4867 ARRAY_SIZE (array), imm_reg_type)) \
4871 #define po_misc_or_fail(expr) do { \
4876 /* encode the 12-bit imm field of Add/sub immediate */
4877 static inline uint32_t
4878 encode_addsub_imm (uint32_t imm
)
4883 /* encode the shift amount field of Add/sub immediate */
4884 static inline uint32_t
4885 encode_addsub_imm_shift_amount (uint32_t cnt
)
4891 /* encode the imm field of Adr instruction */
4892 static inline uint32_t
4893 encode_adr_imm (uint32_t imm
)
4895 return (((imm
& 0x3) << 29) /* [1:0] -> [30:29] */
4896 | ((imm
& (0x7ffff << 2)) << 3)); /* [20:2] -> [23:5] */
4899 /* encode the immediate field of Move wide immediate */
4900 static inline uint32_t
4901 encode_movw_imm (uint32_t imm
)
4906 /* encode the 26-bit offset of unconditional branch */
4907 static inline uint32_t
4908 encode_branch_ofs_26 (uint32_t ofs
)
4910 return ofs
& ((1 << 26) - 1);
4913 /* encode the 19-bit offset of conditional branch and compare & branch */
4914 static inline uint32_t
4915 encode_cond_branch_ofs_19 (uint32_t ofs
)
4917 return (ofs
& ((1 << 19) - 1)) << 5;
4920 /* encode the 19-bit offset of ld literal */
4921 static inline uint32_t
4922 encode_ld_lit_ofs_19 (uint32_t ofs
)
4924 return (ofs
& ((1 << 19) - 1)) << 5;
4927 /* Encode the 14-bit offset of test & branch. */
4928 static inline uint32_t
4929 encode_tst_branch_ofs_14 (uint32_t ofs
)
4931 return (ofs
& ((1 << 14) - 1)) << 5;
4934 /* Encode the 16-bit imm field of svc/hvc/smc. */
4935 static inline uint32_t
4936 encode_svc_imm (uint32_t imm
)
4941 /* Reencode add(s) to sub(s), or sub(s) to add(s). */
4942 static inline uint32_t
4943 reencode_addsub_switch_add_sub (uint32_t opcode
)
4945 return opcode
^ (1 << 30);
4948 static inline uint32_t
4949 reencode_movzn_to_movz (uint32_t opcode
)
4951 return opcode
| (1 << 30);
4954 static inline uint32_t
4955 reencode_movzn_to_movn (uint32_t opcode
)
4957 return opcode
& ~(1 << 30);
4960 /* Overall per-instruction processing. */
4962 /* We need to be able to fix up arbitrary expressions in some statements.
4963 This is so that we can handle symbols that are an arbitrary distance from
4964 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
4965 which returns part of an address in a form which will be valid for
4966 a data instruction. We do this by pushing the expression into a symbol
4967 in the expr_section, and creating a fix for that. */
4970 fix_new_aarch64 (fragS
* frag
,
4985 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pc_rel
, reloc
);
4989 new_fix
= fix_new (frag
, where
, size
, make_expr_symbol (exp
), 0,
4996 /* Diagnostics on operands errors. */
4998 /* By default, output verbose error message.
4999 Disable the verbose error message by -mno-verbose-error. */
5000 static int verbose_error_p
= 1;
5002 #ifdef DEBUG_AARCH64
5003 /* N.B. this is only for the purpose of debugging. */
5004 const char* operand_mismatch_kind_names
[] =
5007 "AARCH64_OPDE_RECOVERABLE",
5008 "AARCH64_OPDE_A_SHOULD_FOLLOW_B",
5009 "AARCH64_OPDE_EXPECTED_A_AFTER_B",
5010 "AARCH64_OPDE_SYNTAX_ERROR",
5011 "AARCH64_OPDE_FATAL_SYNTAX_ERROR",
5012 "AARCH64_OPDE_INVALID_VARIANT",
5013 "AARCH64_OPDE_OUT_OF_RANGE",
5014 "AARCH64_OPDE_UNALIGNED",
5015 "AARCH64_OPDE_REG_LIST",
5016 "AARCH64_OPDE_OTHER_ERROR",
5018 #endif /* DEBUG_AARCH64 */
5020 /* Return TRUE if LHS is of higher severity than RHS, otherwise return FALSE.
5022 When multiple errors of different kinds are found in the same assembly
5023 line, only the error of the highest severity will be picked up for
5024 issuing the diagnostics. */
5027 operand_error_higher_severity_p (enum aarch64_operand_error_kind lhs
,
5028 enum aarch64_operand_error_kind rhs
)
5030 gas_assert (AARCH64_OPDE_RECOVERABLE
> AARCH64_OPDE_NIL
);
5031 gas_assert (AARCH64_OPDE_A_SHOULD_FOLLOW_B
> AARCH64_OPDE_RECOVERABLE
);
5032 gas_assert (AARCH64_OPDE_EXPECTED_A_AFTER_B
> AARCH64_OPDE_RECOVERABLE
);
5033 gas_assert (AARCH64_OPDE_SYNTAX_ERROR
> AARCH64_OPDE_A_SHOULD_FOLLOW_B
);
5034 gas_assert (AARCH64_OPDE_SYNTAX_ERROR
> AARCH64_OPDE_EXPECTED_A_AFTER_B
);
5035 gas_assert (AARCH64_OPDE_FATAL_SYNTAX_ERROR
> AARCH64_OPDE_SYNTAX_ERROR
);
5036 gas_assert (AARCH64_OPDE_INVALID_VARIANT
> AARCH64_OPDE_FATAL_SYNTAX_ERROR
);
5037 gas_assert (AARCH64_OPDE_OUT_OF_RANGE
> AARCH64_OPDE_INVALID_VARIANT
);
5038 gas_assert (AARCH64_OPDE_UNALIGNED
> AARCH64_OPDE_OUT_OF_RANGE
);
5039 gas_assert (AARCH64_OPDE_REG_LIST
> AARCH64_OPDE_UNALIGNED
);
5040 gas_assert (AARCH64_OPDE_OTHER_ERROR
> AARCH64_OPDE_REG_LIST
);
5044 /* Helper routine to get the mnemonic name from the assembly instruction
5045 line; should only be called for the diagnosis purpose, as there is
5046 string copy operation involved, which may affect the runtime
5047 performance if used in elsewhere. */
5050 get_mnemonic_name (const char *str
)
5052 static char mnemonic
[32];
5055 /* Get the first 15 bytes and assume that the full name is included. */
5056 strncpy (mnemonic
, str
, 31);
5057 mnemonic
[31] = '\0';
5059 /* Scan up to the end of the mnemonic, which must end in white space,
5060 '.', or end of string. */
5061 for (ptr
= mnemonic
; is_part_of_name(*ptr
); ++ptr
)
5066 /* Append '...' to the truncated long name. */
5067 if (ptr
- mnemonic
== 31)
5068 mnemonic
[28] = mnemonic
[29] = mnemonic
[30] = '.';
5074 reset_aarch64_instruction (aarch64_instruction
*instruction
)
5076 memset (instruction
, '\0', sizeof (aarch64_instruction
));
5077 instruction
->reloc
.type
= BFD_RELOC_UNUSED
;
5080 /* Data structures storing one user error in the assembly code related to
5083 struct operand_error_record
5085 const aarch64_opcode
*opcode
;
5086 aarch64_operand_error detail
;
5087 struct operand_error_record
*next
;
5090 typedef struct operand_error_record operand_error_record
;
5092 struct operand_errors
5094 operand_error_record
*head
;
5095 operand_error_record
*tail
;
5098 typedef struct operand_errors operand_errors
;
5100 /* Top-level data structure reporting user errors for the current line of
5102 The way md_assemble works is that all opcodes sharing the same mnemonic
5103 name are iterated to find a match to the assembly line. In this data
5104 structure, each of the such opcodes will have one operand_error_record
5105 allocated and inserted. In other words, excessive errors related with
5106 a single opcode are disregarded. */
5107 operand_errors operand_error_report
;
5109 /* Free record nodes. */
5110 static operand_error_record
*free_opnd_error_record_nodes
= NULL
;
5112 /* Initialize the data structure that stores the operand mismatch
5113 information on assembling one line of the assembly code. */
5115 init_operand_error_report (void)
5117 if (operand_error_report
.head
!= NULL
)
5119 gas_assert (operand_error_report
.tail
!= NULL
);
5120 operand_error_report
.tail
->next
= free_opnd_error_record_nodes
;
5121 free_opnd_error_record_nodes
= operand_error_report
.head
;
5122 operand_error_report
.head
= NULL
;
5123 operand_error_report
.tail
= NULL
;
5126 gas_assert (operand_error_report
.tail
== NULL
);
5129 /* Return TRUE if some operand error has been recorded during the
5130 parsing of the current assembly line using the opcode *OPCODE;
5131 otherwise return FALSE. */
5133 opcode_has_operand_error_p (const aarch64_opcode
*opcode
)
5135 operand_error_record
*record
= operand_error_report
.head
;
5136 return record
&& record
->opcode
== opcode
;
5139 /* Add the error record *NEW_RECORD to operand_error_report. The record's
5140 OPCODE field is initialized with OPCODE.
5141 N.B. only one record for each opcode, i.e. the maximum of one error is
5142 recorded for each instruction template. */
5145 add_operand_error_record (const operand_error_record
* new_record
)
5147 const aarch64_opcode
*opcode
= new_record
->opcode
;
5148 operand_error_record
* record
= operand_error_report
.head
;
5150 /* The record may have been created for this opcode. If not, we need
5152 if (! opcode_has_operand_error_p (opcode
))
5154 /* Get one empty record. */
5155 if (free_opnd_error_record_nodes
== NULL
)
5157 record
= XNEW (operand_error_record
);
5161 record
= free_opnd_error_record_nodes
;
5162 free_opnd_error_record_nodes
= record
->next
;
5164 record
->opcode
= opcode
;
5165 /* Insert at the head. */
5166 record
->next
= operand_error_report
.head
;
5167 operand_error_report
.head
= record
;
5168 if (operand_error_report
.tail
== NULL
)
5169 operand_error_report
.tail
= record
;
5171 else if (record
->detail
.kind
!= AARCH64_OPDE_NIL
5172 && record
->detail
.index
<= new_record
->detail
.index
5173 && operand_error_higher_severity_p (record
->detail
.kind
,
5174 new_record
->detail
.kind
))
5176 /* In the case of multiple errors found on operands related with a
5177 single opcode, only record the error of the leftmost operand and
5178 only if the error is of higher severity. */
5179 DEBUG_TRACE ("error %s on operand %d not added to the report due to"
5180 " the existing error %s on operand %d",
5181 operand_mismatch_kind_names
[new_record
->detail
.kind
],
5182 new_record
->detail
.index
,
5183 operand_mismatch_kind_names
[record
->detail
.kind
],
5184 record
->detail
.index
);
5188 record
->detail
= new_record
->detail
;
5192 record_operand_error_info (const aarch64_opcode
*opcode
,
5193 aarch64_operand_error
*error_info
)
5195 operand_error_record record
;
5196 record
.opcode
= opcode
;
5197 record
.detail
= *error_info
;
5198 add_operand_error_record (&record
);
5201 /* Record an error of kind KIND and, if ERROR is not NULL, of the detailed
5202 error message *ERROR, for operand IDX (count from 0). */
5205 record_operand_error (const aarch64_opcode
*opcode
, int idx
,
5206 enum aarch64_operand_error_kind kind
,
5209 aarch64_operand_error info
;
5210 memset(&info
, 0, sizeof (info
));
5214 info
.non_fatal
= false;
5215 record_operand_error_info (opcode
, &info
);
5219 record_operand_error_with_data (const aarch64_opcode
*opcode
, int idx
,
5220 enum aarch64_operand_error_kind kind
,
5221 const char* error
, const int *extra_data
)
5223 aarch64_operand_error info
;
5227 info
.data
[0].i
= extra_data
[0];
5228 info
.data
[1].i
= extra_data
[1];
5229 info
.data
[2].i
= extra_data
[2];
5230 info
.non_fatal
= false;
5231 record_operand_error_info (opcode
, &info
);
5235 record_operand_out_of_range_error (const aarch64_opcode
*opcode
, int idx
,
5236 const char* error
, int lower_bound
,
5239 int data
[3] = {lower_bound
, upper_bound
, 0};
5240 record_operand_error_with_data (opcode
, idx
, AARCH64_OPDE_OUT_OF_RANGE
,
5244 /* Remove the operand error record for *OPCODE. */
5245 static void ATTRIBUTE_UNUSED
5246 remove_operand_error_record (const aarch64_opcode
*opcode
)
5248 if (opcode_has_operand_error_p (opcode
))
5250 operand_error_record
* record
= operand_error_report
.head
;
5251 gas_assert (record
!= NULL
&& operand_error_report
.tail
!= NULL
);
5252 operand_error_report
.head
= record
->next
;
5253 record
->next
= free_opnd_error_record_nodes
;
5254 free_opnd_error_record_nodes
= record
;
5255 if (operand_error_report
.head
== NULL
)
5257 gas_assert (operand_error_report
.tail
== record
);
5258 operand_error_report
.tail
= NULL
;
5263 /* Given the instruction in *INSTR, return the index of the best matched
5264 qualifier sequence in the list (an array) headed by QUALIFIERS_LIST.
5266 Return -1 if there is no qualifier sequence; return the first match
5267 if there is multiple matches found. */
5270 find_best_match (const aarch64_inst
*instr
,
5271 const aarch64_opnd_qualifier_seq_t
*qualifiers_list
)
5273 int i
, num_opnds
, max_num_matched
, idx
;
5275 num_opnds
= aarch64_num_of_operands (instr
->opcode
);
5278 DEBUG_TRACE ("no operand");
5282 max_num_matched
= 0;
5285 /* For each pattern. */
5286 for (i
= 0; i
< AARCH64_MAX_QLF_SEQ_NUM
; ++i
, ++qualifiers_list
)
5289 const aarch64_opnd_qualifier_t
*qualifiers
= *qualifiers_list
;
5291 /* Most opcodes has much fewer patterns in the list. */
5292 if (empty_qualifier_sequence_p (qualifiers
))
5294 DEBUG_TRACE_IF (i
== 0, "empty list of qualifier sequence");
5298 for (j
= 0, num_matched
= 0; j
< num_opnds
; ++j
, ++qualifiers
)
5299 if (*qualifiers
== instr
->operands
[j
].qualifier
)
5302 if (num_matched
> max_num_matched
)
5304 max_num_matched
= num_matched
;
5309 DEBUG_TRACE ("return with %d", idx
);
5313 /* Assign qualifiers in the qualifier sequence (headed by QUALIFIERS) to the
5314 corresponding operands in *INSTR. */
5317 assign_qualifier_sequence (aarch64_inst
*instr
,
5318 const aarch64_opnd_qualifier_t
*qualifiers
)
5321 int num_opnds
= aarch64_num_of_operands (instr
->opcode
);
5322 gas_assert (num_opnds
);
5323 for (i
= 0; i
< num_opnds
; ++i
, ++qualifiers
)
5324 instr
->operands
[i
].qualifier
= *qualifiers
;
5327 /* Print operands for the diagnosis purpose. */
5330 print_operands (char *buf
, const aarch64_opcode
*opcode
,
5331 const aarch64_opnd_info
*opnds
)
5335 for (i
= 0; i
< AARCH64_MAX_OPND_NUM
; ++i
)
5340 /* We regard the opcode operand info more, however we also look into
5341 the inst->operands to support the disassembling of the optional
5343 The two operand code should be the same in all cases, apart from
5344 when the operand can be optional. */
5345 if (opcode
->operands
[i
] == AARCH64_OPND_NIL
5346 || opnds
[i
].type
== AARCH64_OPND_NIL
)
5349 /* Generate the operand string in STR. */
5350 aarch64_print_operand (str
, sizeof (str
), 0, opcode
, opnds
, i
, NULL
, NULL
,
5351 NULL
, cmt
, sizeof (cmt
), cpu_variant
);
5355 strcat (buf
, i
== 0 ? " " : ", ");
5357 /* Append the operand string. */
5360 /* Append a comment. This works because only the last operand ever
5361 adds a comment. If that ever changes then we'll need to be
5365 strcat (buf
, "\t// ");
5371 /* Send to stderr a string as information. */
5374 output_info (const char *format
, ...)
5380 file
= as_where (&line
);
5384 fprintf (stderr
, "%s:%u: ", file
, line
);
5386 fprintf (stderr
, "%s: ", file
);
5388 fprintf (stderr
, _("Info: "));
5389 va_start (args
, format
);
5390 vfprintf (stderr
, format
, args
);
5392 (void) putc ('\n', stderr
);
5395 /* Output one operand error record. */
5398 output_operand_error_record (const operand_error_record
*record
, char *str
)
5400 const aarch64_operand_error
*detail
= &record
->detail
;
5401 int idx
= detail
->index
;
5402 const aarch64_opcode
*opcode
= record
->opcode
;
5403 enum aarch64_opnd opd_code
= (idx
>= 0 ? opcode
->operands
[idx
]
5404 : AARCH64_OPND_NIL
);
5406 typedef void (*handler_t
)(const char *format
, ...);
5407 handler_t handler
= detail
->non_fatal
? as_warn
: as_bad
;
5409 switch (detail
->kind
)
5411 case AARCH64_OPDE_NIL
:
5415 case AARCH64_OPDE_A_SHOULD_FOLLOW_B
:
5416 handler (_("this `%s' should have an immediately preceding `%s'"
5418 detail
->data
[0].s
, detail
->data
[1].s
, str
);
5421 case AARCH64_OPDE_EXPECTED_A_AFTER_B
:
5422 handler (_("the preceding `%s' should be followed by `%s` rather"
5423 " than `%s` -- `%s'"),
5424 detail
->data
[1].s
, detail
->data
[0].s
, opcode
->name
, str
);
5427 case AARCH64_OPDE_SYNTAX_ERROR
:
5428 case AARCH64_OPDE_RECOVERABLE
:
5429 case AARCH64_OPDE_FATAL_SYNTAX_ERROR
:
5430 case AARCH64_OPDE_OTHER_ERROR
:
5431 /* Use the prepared error message if there is, otherwise use the
5432 operand description string to describe the error. */
5433 if (detail
->error
!= NULL
)
5436 handler (_("%s -- `%s'"), detail
->error
, str
);
5438 handler (_("%s at operand %d -- `%s'"),
5439 detail
->error
, idx
+ 1, str
);
5443 gas_assert (idx
>= 0);
5444 handler (_("operand %d must be %s -- `%s'"), idx
+ 1,
5445 aarch64_get_operand_desc (opd_code
), str
);
5449 case AARCH64_OPDE_INVALID_VARIANT
:
5450 handler (_("operand mismatch -- `%s'"), str
);
5451 if (verbose_error_p
)
5453 /* We will try to correct the erroneous instruction and also provide
5454 more information e.g. all other valid variants.
5456 The string representation of the corrected instruction and other
5457 valid variants are generated by
5459 1) obtaining the intermediate representation of the erroneous
5461 2) manipulating the IR, e.g. replacing the operand qualifier;
5462 3) printing out the instruction by calling the printer functions
5463 shared with the disassembler.
5465 The limitation of this method is that the exact input assembly
5466 line cannot be accurately reproduced in some cases, for example an
5467 optional operand present in the actual assembly line will be
5468 omitted in the output; likewise for the optional syntax rules,
5469 e.g. the # before the immediate. Another limitation is that the
5470 assembly symbols and relocation operations in the assembly line
5471 currently cannot be printed out in the error report. Last but not
5472 least, when there is other error(s) co-exist with this error, the
5473 'corrected' instruction may be still incorrect, e.g. given
5474 'ldnp h0,h1,[x0,#6]!'
5475 this diagnosis will provide the version:
5476 'ldnp s0,s1,[x0,#6]!'
5477 which is still not right. */
5478 size_t len
= strlen (get_mnemonic_name (str
));
5482 aarch64_inst
*inst_base
= &inst
.base
;
5483 const aarch64_opnd_qualifier_seq_t
*qualifiers_list
;
5486 reset_aarch64_instruction (&inst
);
5487 inst_base
->opcode
= opcode
;
5489 /* Reset the error report so that there is no side effect on the
5490 following operand parsing. */
5491 init_operand_error_report ();
5494 result
= parse_operands (str
+ len
, opcode
)
5495 && programmer_friendly_fixup (&inst
);
5496 gas_assert (result
);
5497 result
= aarch64_opcode_encode (opcode
, inst_base
, &inst_base
->value
,
5498 NULL
, NULL
, insn_sequence
);
5499 gas_assert (!result
);
5501 /* Find the most matched qualifier sequence. */
5502 qlf_idx
= find_best_match (inst_base
, opcode
->qualifiers_list
);
5503 gas_assert (qlf_idx
> -1);
5505 /* Assign the qualifiers. */
5506 assign_qualifier_sequence (inst_base
,
5507 opcode
->qualifiers_list
[qlf_idx
]);
5509 /* Print the hint. */
5510 output_info (_(" did you mean this?"));
5511 snprintf (buf
, sizeof (buf
), "\t%s", get_mnemonic_name (str
));
5512 print_operands (buf
, opcode
, inst_base
->operands
);
5513 output_info (_(" %s"), buf
);
5515 /* Print out other variant(s) if there is any. */
5517 !empty_qualifier_sequence_p (opcode
->qualifiers_list
[1]))
5518 output_info (_(" other valid variant(s):"));
5520 /* For each pattern. */
5521 qualifiers_list
= opcode
->qualifiers_list
;
5522 for (i
= 0; i
< AARCH64_MAX_QLF_SEQ_NUM
; ++i
, ++qualifiers_list
)
5524 /* Most opcodes has much fewer patterns in the list.
5525 First NIL qualifier indicates the end in the list. */
5526 if (empty_qualifier_sequence_p (*qualifiers_list
))
5531 /* Mnemonics name. */
5532 snprintf (buf
, sizeof (buf
), "\t%s", get_mnemonic_name (str
));
5534 /* Assign the qualifiers. */
5535 assign_qualifier_sequence (inst_base
, *qualifiers_list
);
5537 /* Print instruction. */
5538 print_operands (buf
, opcode
, inst_base
->operands
);
5540 output_info (_(" %s"), buf
);
5546 case AARCH64_OPDE_UNTIED_IMMS
:
5547 handler (_("operand %d must have the same immediate value "
5548 "as operand 1 -- `%s'"),
5549 detail
->index
+ 1, str
);
5552 case AARCH64_OPDE_UNTIED_OPERAND
:
5553 handler (_("operand %d must be the same register as operand 1 -- `%s'"),
5554 detail
->index
+ 1, str
);
5557 case AARCH64_OPDE_OUT_OF_RANGE
:
5558 if (detail
->data
[0].i
!= detail
->data
[1].i
)
5559 handler (_("%s out of range %d to %d at operand %d -- `%s'"),
5560 detail
->error
? detail
->error
: _("immediate value"),
5561 detail
->data
[0].i
, detail
->data
[1].i
, idx
+ 1, str
);
5563 handler (_("%s must be %d at operand %d -- `%s'"),
5564 detail
->error
? detail
->error
: _("immediate value"),
5565 detail
->data
[0].i
, idx
+ 1, str
);
5568 case AARCH64_OPDE_REG_LIST
:
5569 if (detail
->data
[0].i
== 1)
5570 handler (_("invalid number of registers in the list; "
5571 "only 1 register is expected at operand %d -- `%s'"),
5574 handler (_("invalid number of registers in the list; "
5575 "%d registers are expected at operand %d -- `%s'"),
5576 detail
->data
[0].i
, idx
+ 1, str
);
5579 case AARCH64_OPDE_UNALIGNED
:
5580 handler (_("immediate value must be a multiple of "
5581 "%d at operand %d -- `%s'"),
5582 detail
->data
[0].i
, idx
+ 1, str
);
5591 /* Process and output the error message about the operand mismatching.
5593 When this function is called, the operand error information had
5594 been collected for an assembly line and there will be multiple
5595 errors in the case of multiple instruction templates; output the
5596 error message that most closely describes the problem.
5598 The errors to be printed can be filtered on printing all errors
5599 or only non-fatal errors. This distinction has to be made because
5600 the error buffer may already be filled with fatal errors we don't want to
5601 print due to the different instruction templates. */
5604 output_operand_error_report (char *str
, bool non_fatal_only
)
5606 int largest_error_pos
;
5607 const char *msg
= NULL
;
5608 enum aarch64_operand_error_kind kind
;
5609 operand_error_record
*curr
;
5610 operand_error_record
*head
= operand_error_report
.head
;
5611 operand_error_record
*record
= NULL
;
5613 /* No error to report. */
5617 gas_assert (head
!= NULL
&& operand_error_report
.tail
!= NULL
);
5619 /* Only one error. */
5620 if (head
== operand_error_report
.tail
)
5622 /* If the only error is a non-fatal one and we don't want to print it,
5624 if (!non_fatal_only
|| head
->detail
.non_fatal
)
5626 DEBUG_TRACE ("single opcode entry with error kind: %s",
5627 operand_mismatch_kind_names
[head
->detail
.kind
]);
5628 output_operand_error_record (head
, str
);
5633 /* Find the error kind of the highest severity. */
5634 DEBUG_TRACE ("multiple opcode entries with error kind");
5635 kind
= AARCH64_OPDE_NIL
;
5636 for (curr
= head
; curr
!= NULL
; curr
= curr
->next
)
5638 gas_assert (curr
->detail
.kind
!= AARCH64_OPDE_NIL
);
5639 DEBUG_TRACE ("\t%s", operand_mismatch_kind_names
[curr
->detail
.kind
]);
5640 if (operand_error_higher_severity_p (curr
->detail
.kind
, kind
)
5641 && (!non_fatal_only
|| (non_fatal_only
&& curr
->detail
.non_fatal
)))
5642 kind
= curr
->detail
.kind
;
5645 gas_assert (kind
!= AARCH64_OPDE_NIL
|| non_fatal_only
);
5647 /* Pick up one of errors of KIND to report. */
5648 largest_error_pos
= -2; /* Index can be -1 which means unknown index. */
5649 for (curr
= head
; curr
!= NULL
; curr
= curr
->next
)
5651 /* If we don't want to print non-fatal errors then don't consider them
5653 if (curr
->detail
.kind
!= kind
5654 || (non_fatal_only
&& !curr
->detail
.non_fatal
))
5656 /* If there are multiple errors, pick up the one with the highest
5657 mismatching operand index. In the case of multiple errors with
5658 the equally highest operand index, pick up the first one or the
5659 first one with non-NULL error message. */
5660 if (curr
->detail
.index
> largest_error_pos
5661 || (curr
->detail
.index
== largest_error_pos
&& msg
== NULL
5662 && curr
->detail
.error
!= NULL
))
5664 largest_error_pos
= curr
->detail
.index
;
5666 msg
= record
->detail
.error
;
5670 /* The way errors are collected in the back-end is a bit non-intuitive. But
5671 essentially, because each operand template is tried recursively you may
5672 always have errors collected from the previous tried OPND. These are
5673 usually skipped if there is one successful match. However now with the
5674 non-fatal errors we have to ignore those previously collected hard errors
5675 when we're only interested in printing the non-fatal ones. This condition
5676 prevents us from printing errors that are not appropriate, since we did
5677 match a condition, but it also has warnings that it wants to print. */
5678 if (non_fatal_only
&& !record
)
5681 gas_assert (largest_error_pos
!= -2 && record
!= NULL
);
5682 DEBUG_TRACE ("Pick up error kind %s to report",
5683 operand_mismatch_kind_names
[record
->detail
.kind
]);
5686 output_operand_error_record (record
, str
);
5689 /* Write an AARCH64 instruction to buf - always little-endian. */
5691 put_aarch64_insn (char *buf
, uint32_t insn
)
5693 unsigned char *where
= (unsigned char *) buf
;
5695 where
[1] = insn
>> 8;
5696 where
[2] = insn
>> 16;
5697 where
[3] = insn
>> 24;
5701 get_aarch64_insn (char *buf
)
5703 unsigned char *where
= (unsigned char *) buf
;
5705 result
= ((where
[0] | (where
[1] << 8) | (where
[2] << 16)
5706 | ((uint32_t) where
[3] << 24)));
5711 output_inst (struct aarch64_inst
*new_inst
)
5715 to
= frag_more (INSN_SIZE
);
5717 frag_now
->tc_frag_data
.recorded
= 1;
5719 put_aarch64_insn (to
, inst
.base
.value
);
5721 if (inst
.reloc
.type
!= BFD_RELOC_UNUSED
)
5723 fixS
*fixp
= fix_new_aarch64 (frag_now
, to
- frag_now
->fr_literal
,
5724 INSN_SIZE
, &inst
.reloc
.exp
,
5727 DEBUG_TRACE ("Prepared relocation fix up");
5728 /* Don't check the addend value against the instruction size,
5729 that's the job of our code in md_apply_fix(). */
5730 fixp
->fx_no_overflow
= 1;
5731 if (new_inst
!= NULL
)
5732 fixp
->tc_fix_data
.inst
= new_inst
;
5733 if (aarch64_gas_internal_fixup_p ())
5735 gas_assert (inst
.reloc
.opnd
!= AARCH64_OPND_NIL
);
5736 fixp
->tc_fix_data
.opnd
= inst
.reloc
.opnd
;
5737 fixp
->fx_addnumber
= inst
.reloc
.flags
;
5741 dwarf2_emit_insn (INSN_SIZE
);
5744 /* Link together opcodes of the same name. */
5748 const aarch64_opcode
*opcode
;
5749 struct templates
*next
;
5752 typedef struct templates templates
;
5755 lookup_mnemonic (const char *start
, int len
)
5757 templates
*templ
= NULL
;
5759 templ
= str_hash_find_n (aarch64_ops_hsh
, start
, len
);
5763 /* Subroutine of md_assemble, responsible for looking up the primary
5764 opcode from the mnemonic the user wrote. BASE points to the beginning
5765 of the mnemonic, DOT points to the first '.' within the mnemonic
5766 (if any) and END points to the end of the mnemonic. */
5769 opcode_lookup (char *base
, char *dot
, char *end
)
5771 const aarch64_cond
*cond
;
5778 inst
.cond
= COND_ALWAYS
;
5780 /* Handle a possible condition. */
5783 cond
= str_hash_find_n (aarch64_cond_hsh
, dot
+ 1, end
- dot
- 1);
5786 inst
.cond
= cond
->value
;
5792 if (inst
.cond
== COND_ALWAYS
)
5794 /* Look for unaffixed mnemonic. */
5795 return lookup_mnemonic (base
, len
);
5799 /* append ".c" to mnemonic if conditional */
5800 memcpy (condname
, base
, len
);
5801 memcpy (condname
+ len
, ".c", 2);
5804 return lookup_mnemonic (base
, len
);
5810 /* Internal helper routine converting a vector_type_el structure *VECTYPE
5811 to a corresponding operand qualifier. */
5813 static inline aarch64_opnd_qualifier_t
5814 vectype_to_qualifier (const struct vector_type_el
*vectype
)
5816 /* Element size in bytes indexed by vector_el_type. */
5817 const unsigned char ele_size
[5]
5819 const unsigned int ele_base
[5] =
5821 AARCH64_OPND_QLF_V_4B
,
5822 AARCH64_OPND_QLF_V_2H
,
5823 AARCH64_OPND_QLF_V_2S
,
5824 AARCH64_OPND_QLF_V_1D
,
5825 AARCH64_OPND_QLF_V_1Q
5828 if (!vectype
->defined
|| vectype
->type
== NT_invtype
)
5829 goto vectype_conversion_fail
;
5831 if (vectype
->type
== NT_zero
)
5832 return AARCH64_OPND_QLF_P_Z
;
5833 if (vectype
->type
== NT_merge
)
5834 return AARCH64_OPND_QLF_P_M
;
5836 gas_assert (vectype
->type
>= NT_b
&& vectype
->type
<= NT_q
);
5838 if (vectype
->defined
& (NTA_HASINDEX
| NTA_HASVARWIDTH
))
5840 /* Special case S_4B. */
5841 if (vectype
->type
== NT_b
&& vectype
->width
== 4)
5842 return AARCH64_OPND_QLF_S_4B
;
5844 /* Special case S_2H. */
5845 if (vectype
->type
== NT_h
&& vectype
->width
== 2)
5846 return AARCH64_OPND_QLF_S_2H
;
5848 /* Vector element register. */
5849 return AARCH64_OPND_QLF_S_B
+ vectype
->type
;
5853 /* Vector register. */
5854 int reg_size
= ele_size
[vectype
->type
] * vectype
->width
;
5857 if (reg_size
!= 16 && reg_size
!= 8 && reg_size
!= 4)
5858 goto vectype_conversion_fail
;
5860 /* The conversion is by calculating the offset from the base operand
5861 qualifier for the vector type. The operand qualifiers are regular
5862 enough that the offset can established by shifting the vector width by
5863 a vector-type dependent amount. */
5865 if (vectype
->type
== NT_b
)
5867 else if (vectype
->type
== NT_h
|| vectype
->type
== NT_s
)
5869 else if (vectype
->type
>= NT_d
)
5874 offset
= ele_base
[vectype
->type
] + (vectype
->width
>> shift
);
5875 gas_assert (AARCH64_OPND_QLF_V_4B
<= offset
5876 && offset
<= AARCH64_OPND_QLF_V_1Q
);
5880 vectype_conversion_fail
:
5881 first_error (_("bad vector arrangement type"));
5882 return AARCH64_OPND_QLF_NIL
;
5885 /* Process an optional operand that is found omitted from the assembly line.
5886 Fill *OPERAND for such an operand of type TYPE. OPCODE points to the
5887 instruction's opcode entry while IDX is the index of this omitted operand.
5891 process_omitted_operand (enum aarch64_opnd type
, const aarch64_opcode
*opcode
,
5892 int idx
, aarch64_opnd_info
*operand
)
5894 aarch64_insn default_value
= get_optional_operand_default_value (opcode
);
5895 gas_assert (optional_operand_p (opcode
, idx
));
5896 gas_assert (!operand
->present
);
5900 case AARCH64_OPND_Rd
:
5901 case AARCH64_OPND_Rn
:
5902 case AARCH64_OPND_Rm
:
5903 case AARCH64_OPND_Rt
:
5904 case AARCH64_OPND_Rt2
:
5905 case AARCH64_OPND_Rt_LS64
:
5906 case AARCH64_OPND_Rt_SP
:
5907 case AARCH64_OPND_Rs
:
5908 case AARCH64_OPND_Ra
:
5909 case AARCH64_OPND_Rt_SYS
:
5910 case AARCH64_OPND_Rd_SP
:
5911 case AARCH64_OPND_Rn_SP
:
5912 case AARCH64_OPND_Rm_SP
:
5913 case AARCH64_OPND_Fd
:
5914 case AARCH64_OPND_Fn
:
5915 case AARCH64_OPND_Fm
:
5916 case AARCH64_OPND_Fa
:
5917 case AARCH64_OPND_Ft
:
5918 case AARCH64_OPND_Ft2
:
5919 case AARCH64_OPND_Sd
:
5920 case AARCH64_OPND_Sn
:
5921 case AARCH64_OPND_Sm
:
5922 case AARCH64_OPND_Va
:
5923 case AARCH64_OPND_Vd
:
5924 case AARCH64_OPND_Vn
:
5925 case AARCH64_OPND_Vm
:
5926 case AARCH64_OPND_VdD1
:
5927 case AARCH64_OPND_VnD1
:
5928 operand
->reg
.regno
= default_value
;
5931 case AARCH64_OPND_Ed
:
5932 case AARCH64_OPND_En
:
5933 case AARCH64_OPND_Em
:
5934 case AARCH64_OPND_Em16
:
5935 case AARCH64_OPND_SM3_IMM2
:
5936 operand
->reglane
.regno
= default_value
;
5939 case AARCH64_OPND_IDX
:
5940 case AARCH64_OPND_BIT_NUM
:
5941 case AARCH64_OPND_IMMR
:
5942 case AARCH64_OPND_IMMS
:
5943 case AARCH64_OPND_SHLL_IMM
:
5944 case AARCH64_OPND_IMM_VLSL
:
5945 case AARCH64_OPND_IMM_VLSR
:
5946 case AARCH64_OPND_CCMP_IMM
:
5947 case AARCH64_OPND_FBITS
:
5948 case AARCH64_OPND_UIMM4
:
5949 case AARCH64_OPND_UIMM3_OP1
:
5950 case AARCH64_OPND_UIMM3_OP2
:
5951 case AARCH64_OPND_IMM
:
5952 case AARCH64_OPND_IMM_2
:
5953 case AARCH64_OPND_WIDTH
:
5954 case AARCH64_OPND_UIMM7
:
5955 case AARCH64_OPND_NZCV
:
5956 case AARCH64_OPND_SVE_PATTERN
:
5957 case AARCH64_OPND_SVE_PRFOP
:
5958 operand
->imm
.value
= default_value
;
5961 case AARCH64_OPND_SVE_PATTERN_SCALED
:
5962 operand
->imm
.value
= default_value
;
5963 operand
->shifter
.kind
= AARCH64_MOD_MUL
;
5964 operand
->shifter
.amount
= 1;
5967 case AARCH64_OPND_EXCEPTION
:
5968 inst
.reloc
.type
= BFD_RELOC_UNUSED
;
5971 case AARCH64_OPND_BARRIER_ISB
:
5972 operand
->barrier
= aarch64_barrier_options
+ default_value
;
5975 case AARCH64_OPND_BTI_TARGET
:
5976 operand
->hint_option
= aarch64_hint_options
+ default_value
;
5984 /* Process the relocation type for move wide instructions.
5985 Return TRUE on success; otherwise return FALSE. */
5988 process_movw_reloc_info (void)
5993 is32
= inst
.base
.operands
[0].qualifier
== AARCH64_OPND_QLF_W
? 1 : 0;
5995 if (inst
.base
.opcode
->op
== OP_MOVK
)
5996 switch (inst
.reloc
.type
)
5998 case BFD_RELOC_AARCH64_MOVW_G0_S
:
5999 case BFD_RELOC_AARCH64_MOVW_G1_S
:
6000 case BFD_RELOC_AARCH64_MOVW_G2_S
:
6001 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
6002 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
6003 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
6004 case BFD_RELOC_AARCH64_MOVW_PREL_G3
:
6005 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6006 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6007 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6008 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6010 (_("the specified relocation type is not allowed for MOVK"));
6016 switch (inst
.reloc
.type
)
6018 case BFD_RELOC_AARCH64_MOVW_G0
:
6019 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
6020 case BFD_RELOC_AARCH64_MOVW_G0_S
:
6021 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
6022 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
6023 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC
:
6024 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
6025 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
6026 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
6027 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
6028 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
6029 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
6030 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
6033 case BFD_RELOC_AARCH64_MOVW_G1
:
6034 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
6035 case BFD_RELOC_AARCH64_MOVW_G1_S
:
6036 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
6037 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
6038 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC
:
6039 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
6040 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
6041 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
6042 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
6043 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
6044 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
6045 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
6048 case BFD_RELOC_AARCH64_MOVW_G2
:
6049 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
6050 case BFD_RELOC_AARCH64_MOVW_G2_S
:
6051 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
6052 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC
:
6053 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
6054 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
6057 set_fatal_syntax_error
6058 (_("the specified relocation type is not allowed for 32-bit "
6064 case BFD_RELOC_AARCH64_MOVW_G3
:
6065 case BFD_RELOC_AARCH64_MOVW_PREL_G3
:
6068 set_fatal_syntax_error
6069 (_("the specified relocation type is not allowed for 32-bit "
6076 /* More cases should be added when more MOVW-related relocation types
6077 are supported in GAS. */
6078 gas_assert (aarch64_gas_internal_fixup_p ());
6079 /* The shift amount should have already been set by the parser. */
6082 inst
.base
.operands
[1].shifter
.amount
= shift
;
6086 /* A primitive log calculator. */
6088 static inline unsigned int
6089 get_logsz (unsigned int size
)
6091 const unsigned char ls
[16] =
6092 {0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, 4};
6098 gas_assert (ls
[size
- 1] != (unsigned char)-1);
6099 return ls
[size
- 1];
6102 /* Determine and return the real reloc type code for an instruction
6103 with the pseudo reloc type code BFD_RELOC_AARCH64_LDST_LO12. */
6105 static inline bfd_reloc_code_real_type
6106 ldst_lo12_determine_real_reloc_type (void)
6108 unsigned logsz
, max_logsz
;
6109 enum aarch64_opnd_qualifier opd0_qlf
= inst
.base
.operands
[0].qualifier
;
6110 enum aarch64_opnd_qualifier opd1_qlf
= inst
.base
.operands
[1].qualifier
;
6112 const bfd_reloc_code_real_type reloc_ldst_lo12
[5][5] = {
6114 BFD_RELOC_AARCH64_LDST8_LO12
,
6115 BFD_RELOC_AARCH64_LDST16_LO12
,
6116 BFD_RELOC_AARCH64_LDST32_LO12
,
6117 BFD_RELOC_AARCH64_LDST64_LO12
,
6118 BFD_RELOC_AARCH64_LDST128_LO12
6121 BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
,
6122 BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
,
6123 BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
,
6124 BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
,
6125 BFD_RELOC_AARCH64_NONE
6128 BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
,
6129 BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
,
6130 BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
,
6131 BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
,
6132 BFD_RELOC_AARCH64_NONE
6135 BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12
,
6136 BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12
,
6137 BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12
,
6138 BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12
,
6139 BFD_RELOC_AARCH64_NONE
6142 BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
,
6143 BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
,
6144 BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
,
6145 BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
,
6146 BFD_RELOC_AARCH64_NONE
6150 gas_assert (inst
.reloc
.type
== BFD_RELOC_AARCH64_LDST_LO12
6151 || inst
.reloc
.type
== BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12
6153 == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC
)
6155 == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12
)
6157 == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC
));
6158 gas_assert (inst
.base
.opcode
->operands
[1] == AARCH64_OPND_ADDR_UIMM12
);
6160 if (opd1_qlf
== AARCH64_OPND_QLF_NIL
)
6162 aarch64_get_expected_qualifier (inst
.base
.opcode
->qualifiers_list
,
6164 gas_assert (opd1_qlf
!= AARCH64_OPND_QLF_NIL
);
6166 logsz
= get_logsz (aarch64_get_qualifier_esize (opd1_qlf
));
6168 if (inst
.reloc
.type
== BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12
6169 || inst
.reloc
.type
== BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC
6170 || inst
.reloc
.type
== BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12
6171 || inst
.reloc
.type
== BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC
)
6176 if (logsz
> max_logsz
)
6178 /* SEE PR 27904 for an example of this. */
6179 set_fatal_syntax_error
6180 (_("relocation qualifier does not match instruction size"));
6181 return BFD_RELOC_AARCH64_NONE
;
6184 /* In reloc.c, these pseudo relocation types should be defined in similar
6185 order as above reloc_ldst_lo12 array. Because the array index calculation
6186 below relies on this. */
6187 return reloc_ldst_lo12
[inst
.reloc
.type
- BFD_RELOC_AARCH64_LDST_LO12
][logsz
];
6190 /* Check whether a register list REGINFO is valid. The registers must be
6191 numbered in increasing order (modulo 32), in increments of one or two.
6193 If ACCEPT_ALTERNATE is non-zero, the register numbers should be in
6196 Return FALSE if such a register list is invalid, otherwise return TRUE. */
6199 reg_list_valid_p (uint32_t reginfo
, int accept_alternate
)
6201 uint32_t i
, nb_regs
, prev_regno
, incr
;
6203 nb_regs
= 1 + (reginfo
& 0x3);
6205 prev_regno
= reginfo
& 0x1f;
6206 incr
= accept_alternate
? 2 : 1;
6208 for (i
= 1; i
< nb_regs
; ++i
)
6210 uint32_t curr_regno
;
6212 curr_regno
= reginfo
& 0x1f;
6213 if (curr_regno
!= ((prev_regno
+ incr
) & 0x1f))
6215 prev_regno
= curr_regno
;
6221 /* Generic instruction operand parser. This does no encoding and no
6222 semantic validation; it merely squirrels values away in the inst
6223 structure. Returns TRUE or FALSE depending on whether the
6224 specified grammar matched. */
6227 parse_operands (char *str
, const aarch64_opcode
*opcode
)
6230 char *backtrack_pos
= 0;
6231 const enum aarch64_opnd
*operands
= opcode
->operands
;
6232 aarch64_reg_type imm_reg_type
;
6235 skip_whitespace (str
);
6237 if (AARCH64_CPU_HAS_FEATURE (AARCH64_FEATURE_SVE
, *opcode
->avariant
))
6238 imm_reg_type
= REG_TYPE_R_Z_SP_BHSDQ_VZP
;
6240 imm_reg_type
= REG_TYPE_R_Z_BHSDQ_V
;
6242 for (i
= 0; operands
[i
] != AARCH64_OPND_NIL
; i
++)
6245 const reg_entry
*reg
;
6246 int comma_skipped_p
= 0;
6247 aarch64_reg_type rtype
;
6248 struct vector_type_el vectype
;
6249 aarch64_opnd_qualifier_t qualifier
, base_qualifier
, offset_qualifier
;
6250 aarch64_opnd_info
*info
= &inst
.base
.operands
[i
];
6251 aarch64_reg_type reg_type
;
6253 DEBUG_TRACE ("parse operand %d", i
);
6255 /* Assign the operand code. */
6256 info
->type
= operands
[i
];
6258 if (optional_operand_p (opcode
, i
))
6260 /* Remember where we are in case we need to backtrack. */
6261 gas_assert (!backtrack_pos
);
6262 backtrack_pos
= str
;
6265 /* Expect comma between operands; the backtrack mechanism will take
6266 care of cases of omitted optional operand. */
6267 if (i
> 0 && ! skip_past_char (&str
, ','))
6269 set_syntax_error (_("comma expected between operands"));
6273 comma_skipped_p
= 1;
6275 switch (operands
[i
])
6277 case AARCH64_OPND_Rd
:
6278 case AARCH64_OPND_Rn
:
6279 case AARCH64_OPND_Rm
:
6280 case AARCH64_OPND_Rt
:
6281 case AARCH64_OPND_Rt2
:
6282 case AARCH64_OPND_Rs
:
6283 case AARCH64_OPND_Ra
:
6284 case AARCH64_OPND_Rt_LS64
:
6285 case AARCH64_OPND_Rt_SYS
:
6286 case AARCH64_OPND_PAIRREG
:
6287 case AARCH64_OPND_SVE_Rm
:
6288 po_int_reg_or_fail (REG_TYPE_R_Z
);
6290 /* In LS64 load/store instructions Rt register number must be even
6292 if (operands
[i
] == AARCH64_OPND_Rt_LS64
)
6294 /* We've already checked if this is valid register.
6295 This will check if register number (Rt) is not undefined for LS64
6297 if Rt<4:3> == '11' || Rt<0> == '1' then UNDEFINED. */
6298 if ((info
->reg
.regno
& 0x18) == 0x18 || (info
->reg
.regno
& 0x01) == 0x01)
6300 set_syntax_error (_("invalid Rt register number in 64-byte load/store"));
6306 case AARCH64_OPND_Rd_SP
:
6307 case AARCH64_OPND_Rn_SP
:
6308 case AARCH64_OPND_Rt_SP
:
6309 case AARCH64_OPND_SVE_Rn_SP
:
6310 case AARCH64_OPND_Rm_SP
:
6311 po_int_reg_or_fail (REG_TYPE_R_SP
);
6314 case AARCH64_OPND_Rm_EXT
:
6315 case AARCH64_OPND_Rm_SFT
:
6316 po_misc_or_fail (parse_shifter_operand
6317 (&str
, info
, (operands
[i
] == AARCH64_OPND_Rm_EXT
6319 : SHIFTED_LOGIC_IMM
)));
6320 if (!info
->shifter
.operator_present
)
6322 /* Default to LSL if not present. Libopcodes prefers shifter
6323 kind to be explicit. */
6324 gas_assert (info
->shifter
.kind
== AARCH64_MOD_NONE
);
6325 info
->shifter
.kind
= AARCH64_MOD_LSL
;
6326 /* For Rm_EXT, libopcodes will carry out further check on whether
6327 or not stack pointer is used in the instruction (Recall that
6328 "the extend operator is not optional unless at least one of
6329 "Rd" or "Rn" is '11111' (i.e. WSP)"). */
6333 case AARCH64_OPND_Fd
:
6334 case AARCH64_OPND_Fn
:
6335 case AARCH64_OPND_Fm
:
6336 case AARCH64_OPND_Fa
:
6337 case AARCH64_OPND_Ft
:
6338 case AARCH64_OPND_Ft2
:
6339 case AARCH64_OPND_Sd
:
6340 case AARCH64_OPND_Sn
:
6341 case AARCH64_OPND_Sm
:
6342 case AARCH64_OPND_SVE_VZn
:
6343 case AARCH64_OPND_SVE_Vd
:
6344 case AARCH64_OPND_SVE_Vm
:
6345 case AARCH64_OPND_SVE_Vn
:
6346 val
= aarch64_reg_parse (&str
, REG_TYPE_BHSDQ
, &rtype
, NULL
);
6347 if (val
== PARSE_FAIL
)
6349 first_error (_(get_reg_expected_msg (REG_TYPE_BHSDQ
)));
6352 gas_assert (rtype
>= REG_TYPE_FP_B
&& rtype
<= REG_TYPE_FP_Q
);
6354 info
->reg
.regno
= val
;
6355 info
->qualifier
= AARCH64_OPND_QLF_S_B
+ (rtype
- REG_TYPE_FP_B
);
6358 case AARCH64_OPND_SVE_Pd
:
6359 case AARCH64_OPND_SVE_Pg3
:
6360 case AARCH64_OPND_SVE_Pg4_5
:
6361 case AARCH64_OPND_SVE_Pg4_10
:
6362 case AARCH64_OPND_SVE_Pg4_16
:
6363 case AARCH64_OPND_SVE_Pm
:
6364 case AARCH64_OPND_SVE_Pn
:
6365 case AARCH64_OPND_SVE_Pt
:
6366 case AARCH64_OPND_SME_Pm
:
6367 reg_type
= REG_TYPE_PN
;
6370 case AARCH64_OPND_SVE_Za_5
:
6371 case AARCH64_OPND_SVE_Za_16
:
6372 case AARCH64_OPND_SVE_Zd
:
6373 case AARCH64_OPND_SVE_Zm_5
:
6374 case AARCH64_OPND_SVE_Zm_16
:
6375 case AARCH64_OPND_SVE_Zn
:
6376 case AARCH64_OPND_SVE_Zt
:
6377 reg_type
= REG_TYPE_ZN
;
6380 case AARCH64_OPND_Va
:
6381 case AARCH64_OPND_Vd
:
6382 case AARCH64_OPND_Vn
:
6383 case AARCH64_OPND_Vm
:
6384 reg_type
= REG_TYPE_VN
;
6386 val
= aarch64_reg_parse (&str
, reg_type
, NULL
, &vectype
);
6387 if (val
== PARSE_FAIL
)
6389 first_error (_(get_reg_expected_msg (reg_type
)));
6392 if (vectype
.defined
& NTA_HASINDEX
)
6395 info
->reg
.regno
= val
;
6396 if ((reg_type
== REG_TYPE_PN
|| reg_type
== REG_TYPE_ZN
)
6397 && vectype
.type
== NT_invtype
)
6398 /* Unqualified Pn and Zn registers are allowed in certain
6399 contexts. Rely on F_STRICT qualifier checking to catch
6401 info
->qualifier
= AARCH64_OPND_QLF_NIL
;
6404 info
->qualifier
= vectype_to_qualifier (&vectype
);
6405 if (info
->qualifier
== AARCH64_OPND_QLF_NIL
)
6410 case AARCH64_OPND_VdD1
:
6411 case AARCH64_OPND_VnD1
:
6412 val
= aarch64_reg_parse (&str
, REG_TYPE_VN
, NULL
, &vectype
);
6413 if (val
== PARSE_FAIL
)
6415 set_first_syntax_error (_(get_reg_expected_msg (REG_TYPE_VN
)));
6418 if (vectype
.type
!= NT_d
|| vectype
.index
!= 1)
6420 set_fatal_syntax_error
6421 (_("the top half of a 128-bit FP/SIMD register is expected"));
6424 info
->reg
.regno
= val
;
6425 /* N.B: VdD1 and VnD1 are treated as an fp or advsimd scalar register
6426 here; it is correct for the purpose of encoding/decoding since
6427 only the register number is explicitly encoded in the related
6428 instructions, although this appears a bit hacky. */
6429 info
->qualifier
= AARCH64_OPND_QLF_S_D
;
6432 case AARCH64_OPND_SVE_Zm3_INDEX
:
6433 case AARCH64_OPND_SVE_Zm3_22_INDEX
:
6434 case AARCH64_OPND_SVE_Zm3_11_INDEX
:
6435 case AARCH64_OPND_SVE_Zm4_11_INDEX
:
6436 case AARCH64_OPND_SVE_Zm4_INDEX
:
6437 case AARCH64_OPND_SVE_Zn_INDEX
:
6438 reg_type
= REG_TYPE_ZN
;
6439 goto vector_reg_index
;
6441 case AARCH64_OPND_Ed
:
6442 case AARCH64_OPND_En
:
6443 case AARCH64_OPND_Em
:
6444 case AARCH64_OPND_Em16
:
6445 case AARCH64_OPND_SM3_IMM2
:
6446 reg_type
= REG_TYPE_VN
;
6448 val
= aarch64_reg_parse (&str
, reg_type
, NULL
, &vectype
);
6449 if (val
== PARSE_FAIL
)
6451 first_error (_(get_reg_expected_msg (reg_type
)));
6454 if (vectype
.type
== NT_invtype
|| !(vectype
.defined
& NTA_HASINDEX
))
6457 info
->reglane
.regno
= val
;
6458 info
->reglane
.index
= vectype
.index
;
6459 info
->qualifier
= vectype_to_qualifier (&vectype
);
6460 if (info
->qualifier
== AARCH64_OPND_QLF_NIL
)
6464 case AARCH64_OPND_SVE_ZnxN
:
6465 case AARCH64_OPND_SVE_ZtxN
:
6466 reg_type
= REG_TYPE_ZN
;
6467 goto vector_reg_list
;
6469 case AARCH64_OPND_LVn
:
6470 case AARCH64_OPND_LVt
:
6471 case AARCH64_OPND_LVt_AL
:
6472 case AARCH64_OPND_LEt
:
6473 reg_type
= REG_TYPE_VN
;
6475 if (reg_type
== REG_TYPE_ZN
6476 && get_opcode_dependent_value (opcode
) == 1
6479 val
= aarch64_reg_parse (&str
, reg_type
, NULL
, &vectype
);
6480 if (val
== PARSE_FAIL
)
6482 first_error (_(get_reg_expected_msg (reg_type
)));
6485 info
->reglist
.first_regno
= val
;
6486 info
->reglist
.num_regs
= 1;
6490 val
= parse_vector_reg_list (&str
, reg_type
, &vectype
);
6491 if (val
== PARSE_FAIL
)
6494 if (! reg_list_valid_p (val
, /* accept_alternate */ 0))
6496 set_fatal_syntax_error (_("invalid register list"));
6500 if (vectype
.width
!= 0 && *str
!= ',')
6502 set_fatal_syntax_error
6503 (_("expected element type rather than vector type"));
6507 info
->reglist
.first_regno
= (val
>> 2) & 0x1f;
6508 info
->reglist
.num_regs
= (val
& 0x3) + 1;
6510 if (operands
[i
] == AARCH64_OPND_LEt
)
6512 if (!(vectype
.defined
& NTA_HASINDEX
))
6514 info
->reglist
.has_index
= 1;
6515 info
->reglist
.index
= vectype
.index
;
6519 if (vectype
.defined
& NTA_HASINDEX
)
6521 if (!(vectype
.defined
& NTA_HASTYPE
))
6523 if (reg_type
== REG_TYPE_ZN
)
6524 set_fatal_syntax_error (_("missing type suffix"));
6528 info
->qualifier
= vectype_to_qualifier (&vectype
);
6529 if (info
->qualifier
== AARCH64_OPND_QLF_NIL
)
6533 case AARCH64_OPND_CRn
:
6534 case AARCH64_OPND_CRm
:
6536 char prefix
= *(str
++);
6537 if (prefix
!= 'c' && prefix
!= 'C')
6540 po_imm_nc_or_fail ();
6543 set_fatal_syntax_error (_(N_ ("C0 - C15 expected")));
6546 info
->qualifier
= AARCH64_OPND_QLF_CR
;
6547 info
->imm
.value
= val
;
6551 case AARCH64_OPND_SHLL_IMM
:
6552 case AARCH64_OPND_IMM_VLSR
:
6553 po_imm_or_fail (1, 64);
6554 info
->imm
.value
= val
;
6557 case AARCH64_OPND_CCMP_IMM
:
6558 case AARCH64_OPND_SIMM5
:
6559 case AARCH64_OPND_FBITS
:
6560 case AARCH64_OPND_TME_UIMM16
:
6561 case AARCH64_OPND_UIMM4
:
6562 case AARCH64_OPND_UIMM4_ADDG
:
6563 case AARCH64_OPND_UIMM10
:
6564 case AARCH64_OPND_UIMM3_OP1
:
6565 case AARCH64_OPND_UIMM3_OP2
:
6566 case AARCH64_OPND_IMM_VLSL
:
6567 case AARCH64_OPND_IMM
:
6568 case AARCH64_OPND_IMM_2
:
6569 case AARCH64_OPND_WIDTH
:
6570 case AARCH64_OPND_SVE_INV_LIMM
:
6571 case AARCH64_OPND_SVE_LIMM
:
6572 case AARCH64_OPND_SVE_LIMM_MOV
:
6573 case AARCH64_OPND_SVE_SHLIMM_PRED
:
6574 case AARCH64_OPND_SVE_SHLIMM_UNPRED
:
6575 case AARCH64_OPND_SVE_SHLIMM_UNPRED_22
:
6576 case AARCH64_OPND_SVE_SHRIMM_PRED
:
6577 case AARCH64_OPND_SVE_SHRIMM_UNPRED
:
6578 case AARCH64_OPND_SVE_SHRIMM_UNPRED_22
:
6579 case AARCH64_OPND_SVE_SIMM5
:
6580 case AARCH64_OPND_SVE_SIMM5B
:
6581 case AARCH64_OPND_SVE_SIMM6
:
6582 case AARCH64_OPND_SVE_SIMM8
:
6583 case AARCH64_OPND_SVE_UIMM3
:
6584 case AARCH64_OPND_SVE_UIMM7
:
6585 case AARCH64_OPND_SVE_UIMM8
:
6586 case AARCH64_OPND_SVE_UIMM8_53
:
6587 case AARCH64_OPND_IMM_ROT1
:
6588 case AARCH64_OPND_IMM_ROT2
:
6589 case AARCH64_OPND_IMM_ROT3
:
6590 case AARCH64_OPND_SVE_IMM_ROT1
:
6591 case AARCH64_OPND_SVE_IMM_ROT2
:
6592 case AARCH64_OPND_SVE_IMM_ROT3
:
6593 po_imm_nc_or_fail ();
6594 info
->imm
.value
= val
;
6597 case AARCH64_OPND_SVE_AIMM
:
6598 case AARCH64_OPND_SVE_ASIMM
:
6599 po_imm_nc_or_fail ();
6600 info
->imm
.value
= val
;
6601 skip_whitespace (str
);
6602 if (skip_past_comma (&str
))
6603 po_misc_or_fail (parse_shift (&str
, info
, SHIFTED_LSL
));
6605 inst
.base
.operands
[i
].shifter
.kind
= AARCH64_MOD_LSL
;
6608 case AARCH64_OPND_SVE_PATTERN
:
6609 po_enum_or_fail (aarch64_sve_pattern_array
);
6610 info
->imm
.value
= val
;
6613 case AARCH64_OPND_SVE_PATTERN_SCALED
:
6614 po_enum_or_fail (aarch64_sve_pattern_array
);
6615 info
->imm
.value
= val
;
6616 if (skip_past_comma (&str
)
6617 && !parse_shift (&str
, info
, SHIFTED_MUL
))
6619 if (!info
->shifter
.operator_present
)
6621 gas_assert (info
->shifter
.kind
== AARCH64_MOD_NONE
);
6622 info
->shifter
.kind
= AARCH64_MOD_MUL
;
6623 info
->shifter
.amount
= 1;
6627 case AARCH64_OPND_SVE_PRFOP
:
6628 po_enum_or_fail (aarch64_sve_prfop_array
);
6629 info
->imm
.value
= val
;
6632 case AARCH64_OPND_UIMM7
:
6633 po_imm_or_fail (0, 127);
6634 info
->imm
.value
= val
;
6637 case AARCH64_OPND_IDX
:
6638 case AARCH64_OPND_MASK
:
6639 case AARCH64_OPND_BIT_NUM
:
6640 case AARCH64_OPND_IMMR
:
6641 case AARCH64_OPND_IMMS
:
6642 po_imm_or_fail (0, 63);
6643 info
->imm
.value
= val
;
6646 case AARCH64_OPND_IMM0
:
6647 po_imm_nc_or_fail ();
6650 set_fatal_syntax_error (_("immediate zero expected"));
6653 info
->imm
.value
= 0;
6656 case AARCH64_OPND_FPIMM0
:
6659 bool res1
= false, res2
= false;
6660 /* N.B. -0.0 will be rejected; although -0.0 shouldn't be rejected,
6661 it is probably not worth the effort to support it. */
6662 if (!(res1
= parse_aarch64_imm_float (&str
, &qfloat
, false,
6665 || !(res2
= parse_constant_immediate (&str
, &val
,
6668 if ((res1
&& qfloat
== 0) || (res2
&& val
== 0))
6670 info
->imm
.value
= 0;
6671 info
->imm
.is_fp
= 1;
6674 set_fatal_syntax_error (_("immediate zero expected"));
6678 case AARCH64_OPND_IMM_MOV
:
6681 if (reg_name_p (str
, REG_TYPE_R_Z_SP
) ||
6682 reg_name_p (str
, REG_TYPE_VN
))
6685 po_misc_or_fail (aarch64_get_expression (&inst
.reloc
.exp
, &str
,
6686 GE_OPT_PREFIX
, REJECT_ABSENT
));
6687 /* The MOV immediate alias will be fixed up by fix_mov_imm_insn
6688 later. fix_mov_imm_insn will try to determine a machine
6689 instruction (MOVZ, MOVN or ORR) for it and will issue an error
6690 message if the immediate cannot be moved by a single
6692 aarch64_set_gas_internal_fixup (&inst
.reloc
, info
, 1);
6693 inst
.base
.operands
[i
].skip
= 1;
6697 case AARCH64_OPND_SIMD_IMM
:
6698 case AARCH64_OPND_SIMD_IMM_SFT
:
6699 if (! parse_big_immediate (&str
, &val
, imm_reg_type
))
6701 assign_imm_if_const_or_fixup_later (&inst
.reloc
, info
,
6703 /* need_libopcodes_p */ 1,
6706 N.B. although AARCH64_OPND_SIMD_IMM doesn't permit any
6707 shift, we don't check it here; we leave the checking to
6708 the libopcodes (operand_general_constraint_met_p). By
6709 doing this, we achieve better diagnostics. */
6710 if (skip_past_comma (&str
)
6711 && ! parse_shift (&str
, info
, SHIFTED_LSL_MSL
))
6713 if (!info
->shifter
.operator_present
6714 && info
->type
== AARCH64_OPND_SIMD_IMM_SFT
)
6716 /* Default to LSL if not present. Libopcodes prefers shifter
6717 kind to be explicit. */
6718 gas_assert (info
->shifter
.kind
== AARCH64_MOD_NONE
);
6719 info
->shifter
.kind
= AARCH64_MOD_LSL
;
6723 case AARCH64_OPND_FPIMM
:
6724 case AARCH64_OPND_SIMD_FPIMM
:
6725 case AARCH64_OPND_SVE_FPIMM8
:
6730 dp_p
= double_precision_operand_p (&inst
.base
.operands
[0]);
6731 if (!parse_aarch64_imm_float (&str
, &qfloat
, dp_p
, imm_reg_type
)
6732 || !aarch64_imm_float_p (qfloat
))
6735 set_fatal_syntax_error (_("invalid floating-point"
6739 inst
.base
.operands
[i
].imm
.value
= encode_imm_float_bits (qfloat
);
6740 inst
.base
.operands
[i
].imm
.is_fp
= 1;
6744 case AARCH64_OPND_SVE_I1_HALF_ONE
:
6745 case AARCH64_OPND_SVE_I1_HALF_TWO
:
6746 case AARCH64_OPND_SVE_I1_ZERO_ONE
:
6751 dp_p
= double_precision_operand_p (&inst
.base
.operands
[0]);
6752 if (!parse_aarch64_imm_float (&str
, &qfloat
, dp_p
, imm_reg_type
))
6755 set_fatal_syntax_error (_("invalid floating-point"
6759 inst
.base
.operands
[i
].imm
.value
= qfloat
;
6760 inst
.base
.operands
[i
].imm
.is_fp
= 1;
6764 case AARCH64_OPND_LIMM
:
6765 po_misc_or_fail (parse_shifter_operand (&str
, info
,
6766 SHIFTED_LOGIC_IMM
));
6767 if (info
->shifter
.operator_present
)
6769 set_fatal_syntax_error
6770 (_("shift not allowed for bitmask immediate"));
6773 assign_imm_if_const_or_fixup_later (&inst
.reloc
, info
,
6775 /* need_libopcodes_p */ 1,
6779 case AARCH64_OPND_AIMM
:
6780 if (opcode
->op
== OP_ADD
)
6781 /* ADD may have relocation types. */
6782 po_misc_or_fail (parse_shifter_operand_reloc (&str
, info
,
6783 SHIFTED_ARITH_IMM
));
6785 po_misc_or_fail (parse_shifter_operand (&str
, info
,
6786 SHIFTED_ARITH_IMM
));
6787 switch (inst
.reloc
.type
)
6789 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
6790 info
->shifter
.amount
= 12;
6792 case BFD_RELOC_UNUSED
:
6793 aarch64_set_gas_internal_fixup (&inst
.reloc
, info
, 0);
6794 if (info
->shifter
.kind
!= AARCH64_MOD_NONE
)
6795 inst
.reloc
.flags
= FIXUP_F_HAS_EXPLICIT_SHIFT
;
6796 inst
.reloc
.pc_rel
= 0;
6801 info
->imm
.value
= 0;
6802 if (!info
->shifter
.operator_present
)
6804 /* Default to LSL if not present. Libopcodes prefers shifter
6805 kind to be explicit. */
6806 gas_assert (info
->shifter
.kind
== AARCH64_MOD_NONE
);
6807 info
->shifter
.kind
= AARCH64_MOD_LSL
;
6811 case AARCH64_OPND_HALF
:
6813 /* #<imm16> or relocation. */
6814 int internal_fixup_p
;
6815 po_misc_or_fail (parse_half (&str
, &internal_fixup_p
));
6816 if (internal_fixup_p
)
6817 aarch64_set_gas_internal_fixup (&inst
.reloc
, info
, 0);
6818 skip_whitespace (str
);
6819 if (skip_past_comma (&str
))
6821 /* {, LSL #<shift>} */
6822 if (! aarch64_gas_internal_fixup_p ())
6824 set_fatal_syntax_error (_("can't mix relocation modifier "
6825 "with explicit shift"));
6828 po_misc_or_fail (parse_shift (&str
, info
, SHIFTED_LSL
));
6831 inst
.base
.operands
[i
].shifter
.amount
= 0;
6832 inst
.base
.operands
[i
].shifter
.kind
= AARCH64_MOD_LSL
;
6833 inst
.base
.operands
[i
].imm
.value
= 0;
6834 if (! process_movw_reloc_info ())
6839 case AARCH64_OPND_EXCEPTION
:
6840 case AARCH64_OPND_UNDEFINED
:
6841 po_misc_or_fail (parse_immediate_expression (&str
, &inst
.reloc
.exp
,
6843 assign_imm_if_const_or_fixup_later (&inst
.reloc
, info
,
6845 /* need_libopcodes_p */ 0,
6849 case AARCH64_OPND_NZCV
:
6851 const asm_nzcv
*nzcv
= str_hash_find_n (aarch64_nzcv_hsh
, str
, 4);
6855 info
->imm
.value
= nzcv
->value
;
6858 po_imm_or_fail (0, 15);
6859 info
->imm
.value
= val
;
6863 case AARCH64_OPND_COND
:
6864 case AARCH64_OPND_COND1
:
6869 while (ISALPHA (*str
));
6870 info
->cond
= str_hash_find_n (aarch64_cond_hsh
, start
, str
- start
);
6871 if (info
->cond
== NULL
)
6873 set_syntax_error (_("invalid condition"));
6876 else if (operands
[i
] == AARCH64_OPND_COND1
6877 && (info
->cond
->value
& 0xe) == 0xe)
6879 /* Do not allow AL or NV. */
6880 set_default_error ();
6886 case AARCH64_OPND_ADDR_ADRP
:
6887 po_misc_or_fail (parse_adrp (&str
));
6888 /* Clear the value as operand needs to be relocated. */
6889 info
->imm
.value
= 0;
6892 case AARCH64_OPND_ADDR_PCREL14
:
6893 case AARCH64_OPND_ADDR_PCREL19
:
6894 case AARCH64_OPND_ADDR_PCREL21
:
6895 case AARCH64_OPND_ADDR_PCREL26
:
6896 po_misc_or_fail (parse_address (&str
, info
));
6897 if (!info
->addr
.pcrel
)
6899 set_syntax_error (_("invalid pc-relative address"));
6902 if (inst
.gen_lit_pool
6903 && (opcode
->iclass
!= loadlit
|| opcode
->op
== OP_PRFM_LIT
))
6905 /* Only permit "=value" in the literal load instructions.
6906 The literal will be generated by programmer_friendly_fixup. */
6907 set_syntax_error (_("invalid use of \"=immediate\""));
6910 if (inst
.reloc
.exp
.X_op
== O_symbol
&& find_reloc_table_entry (&str
))
6912 set_syntax_error (_("unrecognized relocation suffix"));
6915 if (inst
.reloc
.exp
.X_op
== O_constant
&& !inst
.gen_lit_pool
)
6917 info
->imm
.value
= inst
.reloc
.exp
.X_add_number
;
6918 inst
.reloc
.type
= BFD_RELOC_UNUSED
;
6922 info
->imm
.value
= 0;
6923 if (inst
.reloc
.type
== BFD_RELOC_UNUSED
)
6924 switch (opcode
->iclass
)
6928 /* e.g. CBZ or B.COND */
6929 gas_assert (operands
[i
] == AARCH64_OPND_ADDR_PCREL19
);
6930 inst
.reloc
.type
= BFD_RELOC_AARCH64_BRANCH19
;
6934 gas_assert (operands
[i
] == AARCH64_OPND_ADDR_PCREL14
);
6935 inst
.reloc
.type
= BFD_RELOC_AARCH64_TSTBR14
;
6939 gas_assert (operands
[i
] == AARCH64_OPND_ADDR_PCREL26
);
6941 (opcode
->op
== OP_BL
) ? BFD_RELOC_AARCH64_CALL26
6942 : BFD_RELOC_AARCH64_JUMP26
;
6945 gas_assert (operands
[i
] == AARCH64_OPND_ADDR_PCREL19
);
6946 inst
.reloc
.type
= BFD_RELOC_AARCH64_LD_LO19_PCREL
;
6949 gas_assert (operands
[i
] == AARCH64_OPND_ADDR_PCREL21
);
6950 inst
.reloc
.type
= BFD_RELOC_AARCH64_ADR_LO21_PCREL
;
6956 inst
.reloc
.pc_rel
= 1;
6960 case AARCH64_OPND_ADDR_SIMPLE
:
6961 case AARCH64_OPND_SIMD_ADDR_SIMPLE
:
6963 /* [<Xn|SP>{, #<simm>}] */
6965 /* First use the normal address-parsing routines, to get
6966 the usual syntax errors. */
6967 po_misc_or_fail (parse_address (&str
, info
));
6968 if (info
->addr
.pcrel
|| info
->addr
.offset
.is_reg
6969 || !info
->addr
.preind
|| info
->addr
.postind
6970 || info
->addr
.writeback
)
6972 set_syntax_error (_("invalid addressing mode"));
6976 /* Then retry, matching the specific syntax of these addresses. */
6978 po_char_or_fail ('[');
6979 po_reg_or_fail (REG_TYPE_R64_SP
);
6980 /* Accept optional ", #0". */
6981 if (operands
[i
] == AARCH64_OPND_ADDR_SIMPLE
6982 && skip_past_char (&str
, ','))
6984 skip_past_char (&str
, '#');
6985 if (! skip_past_char (&str
, '0'))
6987 set_fatal_syntax_error
6988 (_("the optional immediate offset can only be 0"));
6992 po_char_or_fail (']');
6996 case AARCH64_OPND_ADDR_REGOFF
:
6997 /* [<Xn|SP>, <R><m>{, <extend> {<amount>}}] */
6998 po_misc_or_fail (parse_address (&str
, info
));
7000 if (info
->addr
.pcrel
|| !info
->addr
.offset
.is_reg
7001 || !info
->addr
.preind
|| info
->addr
.postind
7002 || info
->addr
.writeback
)
7004 set_syntax_error (_("invalid addressing mode"));
7007 if (!info
->shifter
.operator_present
)
7009 /* Default to LSL if not present. Libopcodes prefers shifter
7010 kind to be explicit. */
7011 gas_assert (info
->shifter
.kind
== AARCH64_MOD_NONE
);
7012 info
->shifter
.kind
= AARCH64_MOD_LSL
;
7014 /* Qualifier to be deduced by libopcodes. */
7017 case AARCH64_OPND_ADDR_SIMM7
:
7018 po_misc_or_fail (parse_address (&str
, info
));
7019 if (info
->addr
.pcrel
|| info
->addr
.offset
.is_reg
7020 || (!info
->addr
.preind
&& !info
->addr
.postind
))
7022 set_syntax_error (_("invalid addressing mode"));
7025 if (inst
.reloc
.type
!= BFD_RELOC_UNUSED
)
7027 set_syntax_error (_("relocation not allowed"));
7030 assign_imm_if_const_or_fixup_later (&inst
.reloc
, info
,
7032 /* need_libopcodes_p */ 1,
7036 case AARCH64_OPND_ADDR_SIMM9
:
7037 case AARCH64_OPND_ADDR_SIMM9_2
:
7038 case AARCH64_OPND_ADDR_SIMM11
:
7039 case AARCH64_OPND_ADDR_SIMM13
:
7040 po_misc_or_fail (parse_address (&str
, info
));
7041 if (info
->addr
.pcrel
|| info
->addr
.offset
.is_reg
7042 || (!info
->addr
.preind
&& !info
->addr
.postind
)
7043 || (operands
[i
] == AARCH64_OPND_ADDR_SIMM9_2
7044 && info
->addr
.writeback
))
7046 set_syntax_error (_("invalid addressing mode"));
7049 if (inst
.reloc
.type
!= BFD_RELOC_UNUSED
)
7051 set_syntax_error (_("relocation not allowed"));
7054 assign_imm_if_const_or_fixup_later (&inst
.reloc
, info
,
7056 /* need_libopcodes_p */ 1,
7060 case AARCH64_OPND_ADDR_SIMM10
:
7061 case AARCH64_OPND_ADDR_OFFSET
:
7062 po_misc_or_fail (parse_address (&str
, info
));
7063 if (info
->addr
.pcrel
|| info
->addr
.offset
.is_reg
7064 || !info
->addr
.preind
|| info
->addr
.postind
)
7066 set_syntax_error (_("invalid addressing mode"));
7069 if (inst
.reloc
.type
!= BFD_RELOC_UNUSED
)
7071 set_syntax_error (_("relocation not allowed"));
7074 assign_imm_if_const_or_fixup_later (&inst
.reloc
, info
,
7076 /* need_libopcodes_p */ 1,
7080 case AARCH64_OPND_ADDR_UIMM12
:
7081 po_misc_or_fail (parse_address (&str
, info
));
7082 if (info
->addr
.pcrel
|| info
->addr
.offset
.is_reg
7083 || !info
->addr
.preind
|| info
->addr
.writeback
)
7085 set_syntax_error (_("invalid addressing mode"));
7088 if (inst
.reloc
.type
== BFD_RELOC_UNUSED
)
7089 aarch64_set_gas_internal_fixup (&inst
.reloc
, info
, 1);
7090 else if (inst
.reloc
.type
== BFD_RELOC_AARCH64_LDST_LO12
7092 == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12
)
7094 == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC
)
7096 == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12
)
7098 == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC
))
7099 inst
.reloc
.type
= ldst_lo12_determine_real_reloc_type ();
7100 /* Leave qualifier to be determined by libopcodes. */
7103 case AARCH64_OPND_SIMD_ADDR_POST
:
7104 /* [<Xn|SP>], <Xm|#<amount>> */
7105 po_misc_or_fail (parse_address (&str
, info
));
7106 if (!info
->addr
.postind
|| !info
->addr
.writeback
)
7108 set_syntax_error (_("invalid addressing mode"));
7111 if (!info
->addr
.offset
.is_reg
)
7113 if (inst
.reloc
.exp
.X_op
== O_constant
)
7114 info
->addr
.offset
.imm
= inst
.reloc
.exp
.X_add_number
;
7117 set_fatal_syntax_error
7118 (_("writeback value must be an immediate constant"));
7125 case AARCH64_OPND_SME_SM_ZA
:
7127 if ((val
= parse_sme_sm_za (&str
)) == PARSE_FAIL
)
7129 set_syntax_error (_("unknown or missing PSTATE field name"));
7132 info
->reg
.regno
= val
;
7135 case AARCH64_OPND_SME_PnT_Wm_imm
:
7136 /* <Pn>.<T>[<Wm>, #<imm>] */
7140 val
= parse_sme_pred_reg_with_index (&str
,
7144 if (val
== PARSE_FAIL
)
7147 info
->za_tile_vector
.regno
= val
;
7148 info
->za_tile_vector
.index
.regno
= index_base_reg
;
7149 info
->za_tile_vector
.index
.imm
= imm
;
7150 info
->qualifier
= qualifier
;
7154 case AARCH64_OPND_SVE_ADDR_RI_S4x16
:
7155 case AARCH64_OPND_SVE_ADDR_RI_S4x32
:
7156 case AARCH64_OPND_SVE_ADDR_RI_S4xVL
:
7157 case AARCH64_OPND_SME_ADDR_RI_U4xVL
:
7158 case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL
:
7159 case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL
:
7160 case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL
:
7161 case AARCH64_OPND_SVE_ADDR_RI_S6xVL
:
7162 case AARCH64_OPND_SVE_ADDR_RI_S9xVL
:
7163 case AARCH64_OPND_SVE_ADDR_RI_U6
:
7164 case AARCH64_OPND_SVE_ADDR_RI_U6x2
:
7165 case AARCH64_OPND_SVE_ADDR_RI_U6x4
:
7166 case AARCH64_OPND_SVE_ADDR_RI_U6x8
:
7167 /* [X<n>{, #imm, MUL VL}]
7169 but recognizing SVE registers. */
7170 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7171 &offset_qualifier
));
7172 if (base_qualifier
!= AARCH64_OPND_QLF_X
)
7174 set_syntax_error (_("invalid addressing mode"));
7178 if (info
->addr
.pcrel
|| info
->addr
.offset
.is_reg
7179 || !info
->addr
.preind
|| info
->addr
.writeback
)
7181 set_syntax_error (_("invalid addressing mode"));
7184 if (inst
.reloc
.type
!= BFD_RELOC_UNUSED
7185 || inst
.reloc
.exp
.X_op
!= O_constant
)
7187 /* Make sure this has priority over
7188 "invalid addressing mode". */
7189 set_fatal_syntax_error (_("constant offset required"));
7192 info
->addr
.offset
.imm
= inst
.reloc
.exp
.X_add_number
;
7195 case AARCH64_OPND_SVE_ADDR_R
:
7196 /* [<Xn|SP>{, <R><m>}]
7197 but recognizing SVE registers. */
7198 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7199 &offset_qualifier
));
7200 if (offset_qualifier
== AARCH64_OPND_QLF_NIL
)
7202 offset_qualifier
= AARCH64_OPND_QLF_X
;
7203 info
->addr
.offset
.is_reg
= 1;
7204 info
->addr
.offset
.regno
= 31;
7206 else if (base_qualifier
!= AARCH64_OPND_QLF_X
7207 || offset_qualifier
!= AARCH64_OPND_QLF_X
)
7209 set_syntax_error (_("invalid addressing mode"));
7214 case AARCH64_OPND_SVE_ADDR_RR
:
7215 case AARCH64_OPND_SVE_ADDR_RR_LSL1
:
7216 case AARCH64_OPND_SVE_ADDR_RR_LSL2
:
7217 case AARCH64_OPND_SVE_ADDR_RR_LSL3
:
7218 case AARCH64_OPND_SVE_ADDR_RR_LSL4
:
7219 case AARCH64_OPND_SVE_ADDR_RX
:
7220 case AARCH64_OPND_SVE_ADDR_RX_LSL1
:
7221 case AARCH64_OPND_SVE_ADDR_RX_LSL2
:
7222 case AARCH64_OPND_SVE_ADDR_RX_LSL3
:
7223 /* [<Xn|SP>, <R><m>{, lsl #<amount>}]
7224 but recognizing SVE registers. */
7225 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7226 &offset_qualifier
));
7227 if (base_qualifier
!= AARCH64_OPND_QLF_X
7228 || offset_qualifier
!= AARCH64_OPND_QLF_X
)
7230 set_syntax_error (_("invalid addressing mode"));
7235 case AARCH64_OPND_SVE_ADDR_RZ
:
7236 case AARCH64_OPND_SVE_ADDR_RZ_LSL1
:
7237 case AARCH64_OPND_SVE_ADDR_RZ_LSL2
:
7238 case AARCH64_OPND_SVE_ADDR_RZ_LSL3
:
7239 case AARCH64_OPND_SVE_ADDR_RZ_XTW_14
:
7240 case AARCH64_OPND_SVE_ADDR_RZ_XTW_22
:
7241 case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14
:
7242 case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22
:
7243 case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14
:
7244 case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22
:
7245 case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14
:
7246 case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22
:
7247 /* [<Xn|SP>, Z<m>.D{, LSL #<amount>}]
7248 [<Xn|SP>, Z<m>.<T>, <extend> {#<amount>}] */
7249 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7250 &offset_qualifier
));
7251 if (base_qualifier
!= AARCH64_OPND_QLF_X
7252 || (offset_qualifier
!= AARCH64_OPND_QLF_S_S
7253 && offset_qualifier
!= AARCH64_OPND_QLF_S_D
))
7255 set_syntax_error (_("invalid addressing mode"));
7258 info
->qualifier
= offset_qualifier
;
7261 case AARCH64_OPND_SVE_ADDR_ZX
:
7262 /* [Zn.<T>{, <Xm>}]. */
7263 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7264 &offset_qualifier
));
7266 base_qualifier either S_S or S_D
7267 offset_qualifier must be X
7269 if ((base_qualifier
!= AARCH64_OPND_QLF_S_S
7270 && base_qualifier
!= AARCH64_OPND_QLF_S_D
)
7271 || offset_qualifier
!= AARCH64_OPND_QLF_X
)
7273 set_syntax_error (_("invalid addressing mode"));
7276 info
->qualifier
= base_qualifier
;
7277 if (!info
->addr
.offset
.is_reg
|| info
->addr
.pcrel
7278 || !info
->addr
.preind
|| info
->addr
.writeback
7279 || info
->shifter
.operator_present
!= 0)
7281 set_syntax_error (_("invalid addressing mode"));
7284 info
->shifter
.kind
= AARCH64_MOD_LSL
;
7288 case AARCH64_OPND_SVE_ADDR_ZI_U5
:
7289 case AARCH64_OPND_SVE_ADDR_ZI_U5x2
:
7290 case AARCH64_OPND_SVE_ADDR_ZI_U5x4
:
7291 case AARCH64_OPND_SVE_ADDR_ZI_U5x8
:
7292 /* [Z<n>.<T>{, #imm}] */
7293 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7294 &offset_qualifier
));
7295 if (base_qualifier
!= AARCH64_OPND_QLF_S_S
7296 && base_qualifier
!= AARCH64_OPND_QLF_S_D
)
7298 set_syntax_error (_("invalid addressing mode"));
7301 info
->qualifier
= base_qualifier
;
7304 case AARCH64_OPND_SVE_ADDR_ZZ_LSL
:
7305 case AARCH64_OPND_SVE_ADDR_ZZ_SXTW
:
7306 case AARCH64_OPND_SVE_ADDR_ZZ_UXTW
:
7307 /* [Z<n>.<T>, Z<m>.<T>{, LSL #<amount>}]
7308 [Z<n>.D, Z<m>.D, <extend> {#<amount>}]
7312 [Z<n>.S, Z<m>.S, <extend> {#<amount>}]
7314 here since we get better error messages by leaving it to
7315 the qualifier checking routines. */
7316 po_misc_or_fail (parse_sve_address (&str
, info
, &base_qualifier
,
7317 &offset_qualifier
));
7318 if ((base_qualifier
!= AARCH64_OPND_QLF_S_S
7319 && base_qualifier
!= AARCH64_OPND_QLF_S_D
)
7320 || offset_qualifier
!= base_qualifier
)
7322 set_syntax_error (_("invalid addressing mode"));
7325 info
->qualifier
= base_qualifier
;
7328 case AARCH64_OPND_SYSREG
:
7330 uint32_t sysreg_flags
;
7331 if ((val
= parse_sys_reg (&str
, aarch64_sys_regs_hsh
, 1, 0,
7332 &sysreg_flags
)) == PARSE_FAIL
)
7334 set_syntax_error (_("unknown or missing system register name"));
7337 inst
.base
.operands
[i
].sysreg
.value
= val
;
7338 inst
.base
.operands
[i
].sysreg
.flags
= sysreg_flags
;
7342 case AARCH64_OPND_PSTATEFIELD
:
7344 uint32_t sysreg_flags
;
7345 if ((val
= parse_sys_reg (&str
, aarch64_pstatefield_hsh
, 0, 1,
7346 &sysreg_flags
)) == PARSE_FAIL
)
7348 set_syntax_error (_("unknown or missing PSTATE field name"));
7351 inst
.base
.operands
[i
].pstatefield
= val
;
7352 inst
.base
.operands
[i
].sysreg
.flags
= sysreg_flags
;
7356 case AARCH64_OPND_SYSREG_IC
:
7357 inst
.base
.operands
[i
].sysins_op
=
7358 parse_sys_ins_reg (&str
, aarch64_sys_regs_ic_hsh
);
7361 case AARCH64_OPND_SYSREG_DC
:
7362 inst
.base
.operands
[i
].sysins_op
=
7363 parse_sys_ins_reg (&str
, aarch64_sys_regs_dc_hsh
);
7366 case AARCH64_OPND_SYSREG_AT
:
7367 inst
.base
.operands
[i
].sysins_op
=
7368 parse_sys_ins_reg (&str
, aarch64_sys_regs_at_hsh
);
7371 case AARCH64_OPND_SYSREG_SR
:
7372 inst
.base
.operands
[i
].sysins_op
=
7373 parse_sys_ins_reg (&str
, aarch64_sys_regs_sr_hsh
);
7376 case AARCH64_OPND_SYSREG_TLBI
:
7377 inst
.base
.operands
[i
].sysins_op
=
7378 parse_sys_ins_reg (&str
, aarch64_sys_regs_tlbi_hsh
);
7380 if (inst
.base
.operands
[i
].sysins_op
== NULL
)
7382 set_fatal_syntax_error ( _("unknown or missing operation name"));
7387 case AARCH64_OPND_BARRIER
:
7388 case AARCH64_OPND_BARRIER_ISB
:
7389 val
= parse_barrier (&str
);
7390 if (val
!= PARSE_FAIL
7391 && operands
[i
] == AARCH64_OPND_BARRIER_ISB
&& val
!= 0xf)
7393 /* ISB only accepts options name 'sy'. */
7395 (_("the specified option is not accepted in ISB"));
7396 /* Turn off backtrack as this optional operand is present. */
7400 if (val
!= PARSE_FAIL
7401 && operands
[i
] == AARCH64_OPND_BARRIER
)
7403 /* Regular barriers accept options CRm (C0-C15).
7404 DSB nXS barrier variant accepts values > 15. */
7405 if (val
< 0 || val
> 15)
7407 set_syntax_error (_("the specified option is not accepted in DSB"));
7411 /* This is an extension to accept a 0..15 immediate. */
7412 if (val
== PARSE_FAIL
)
7413 po_imm_or_fail (0, 15);
7414 info
->barrier
= aarch64_barrier_options
+ val
;
7417 case AARCH64_OPND_BARRIER_DSB_NXS
:
7418 val
= parse_barrier (&str
);
7419 if (val
!= PARSE_FAIL
)
7421 /* DSB nXS barrier variant accept only <option>nXS qualifiers. */
7422 if (!(val
== 16 || val
== 20 || val
== 24 || val
== 28))
7424 set_syntax_error (_("the specified option is not accepted in DSB"));
7425 /* Turn off backtrack as this optional operand is present. */
7432 /* DSB nXS barrier variant accept 5-bit unsigned immediate, with
7433 possible values 16, 20, 24 or 28 , encoded as val<3:2>. */
7434 if (! parse_constant_immediate (&str
, &val
, imm_reg_type
))
7436 if (!(val
== 16 || val
== 20 || val
== 24 || val
== 28))
7438 set_syntax_error (_("immediate value must be 16, 20, 24, 28"));
7442 /* Option index is encoded as 2-bit value in val<3:2>. */
7443 val
= (val
>> 2) - 4;
7444 info
->barrier
= aarch64_barrier_dsb_nxs_options
+ val
;
7447 case AARCH64_OPND_PRFOP
:
7448 val
= parse_pldop (&str
);
7449 /* This is an extension to accept a 0..31 immediate. */
7450 if (val
== PARSE_FAIL
)
7451 po_imm_or_fail (0, 31);
7452 inst
.base
.operands
[i
].prfop
= aarch64_prfops
+ val
;
7455 case AARCH64_OPND_BARRIER_PSB
:
7456 val
= parse_barrier_psb (&str
, &(info
->hint_option
));
7457 if (val
== PARSE_FAIL
)
7461 case AARCH64_OPND_BTI_TARGET
:
7462 val
= parse_bti_operand (&str
, &(info
->hint_option
));
7463 if (val
== PARSE_FAIL
)
7467 case AARCH64_OPND_SME_ZAda_2b
:
7468 case AARCH64_OPND_SME_ZAda_3b
:
7469 val
= parse_sme_zada_operand (&str
, &qualifier
);
7470 if (val
== PARSE_FAIL
)
7472 info
->reg
.regno
= val
;
7473 info
->qualifier
= qualifier
;
7476 case AARCH64_OPND_SME_ZA_HV_idx_src
:
7477 case AARCH64_OPND_SME_ZA_HV_idx_dest
:
7478 case AARCH64_OPND_SME_ZA_HV_idx_ldstr
:
7480 enum sme_hv_slice slice_indicator
;
7481 int vector_select_register
;
7484 if (operands
[i
] == AARCH64_OPND_SME_ZA_HV_idx_ldstr
)
7485 val
= parse_sme_za_hv_tiles_operand_with_braces (&str
,
7487 &vector_select_register
,
7491 val
= parse_sme_za_hv_tiles_operand (&str
, &slice_indicator
,
7492 &vector_select_register
,
7495 if (val
== PARSE_FAIL
)
7497 info
->za_tile_vector
.regno
= val
;
7498 info
->za_tile_vector
.index
.regno
= vector_select_register
;
7499 info
->za_tile_vector
.index
.imm
= imm
;
7500 info
->za_tile_vector
.v
= slice_indicator
;
7501 info
->qualifier
= qualifier
;
7505 case AARCH64_OPND_SME_list_of_64bit_tiles
:
7506 val
= parse_sme_list_of_64bit_tiles (&str
);
7507 if (val
== PARSE_FAIL
)
7509 info
->imm
.value
= val
;
7512 case AARCH64_OPND_SME_ZA_array
:
7515 val
= parse_sme_za_array (&str
, &imm
);
7516 if (val
== PARSE_FAIL
)
7518 info
->za_tile_vector
.index
.regno
= val
;
7519 info
->za_tile_vector
.index
.imm
= imm
;
7523 case AARCH64_OPND_MOPS_ADDR_Rd
:
7524 case AARCH64_OPND_MOPS_ADDR_Rs
:
7525 po_char_or_fail ('[');
7526 if (!parse_x0_to_x30 (&str
, info
))
7528 po_char_or_fail (']');
7529 po_char_or_fail ('!');
7532 case AARCH64_OPND_MOPS_WB_Rn
:
7533 if (!parse_x0_to_x30 (&str
, info
))
7535 po_char_or_fail ('!');
7539 as_fatal (_("unhandled operand code %d"), operands
[i
]);
7542 /* If we get here, this operand was successfully parsed. */
7543 inst
.base
.operands
[i
].present
= 1;
7547 /* The parse routine should already have set the error, but in case
7548 not, set a default one here. */
7550 set_default_error ();
7552 if (! backtrack_pos
)
7553 goto parse_operands_return
;
7556 /* We reach here because this operand is marked as optional, and
7557 either no operand was supplied or the operand was supplied but it
7558 was syntactically incorrect. In the latter case we report an
7559 error. In the former case we perform a few more checks before
7560 dropping through to the code to insert the default operand. */
7562 char *tmp
= backtrack_pos
;
7563 char endchar
= END_OF_INSN
;
7565 if (i
!= (aarch64_num_of_operands (opcode
) - 1))
7567 skip_past_char (&tmp
, ',');
7569 if (*tmp
!= endchar
)
7570 /* The user has supplied an operand in the wrong format. */
7571 goto parse_operands_return
;
7573 /* Make sure there is not a comma before the optional operand.
7574 For example the fifth operand of 'sys' is optional:
7576 sys #0,c0,c0,#0, <--- wrong
7577 sys #0,c0,c0,#0 <--- correct. */
7578 if (comma_skipped_p
&& i
&& endchar
== END_OF_INSN
)
7580 set_fatal_syntax_error
7581 (_("unexpected comma before the omitted optional operand"));
7582 goto parse_operands_return
;
7586 /* Reaching here means we are dealing with an optional operand that is
7587 omitted from the assembly line. */
7588 gas_assert (optional_operand_p (opcode
, i
));
7590 process_omitted_operand (operands
[i
], opcode
, i
, info
);
7592 /* Try again, skipping the optional operand at backtrack_pos. */
7593 str
= backtrack_pos
;
7596 /* Clear any error record after the omitted optional operand has been
7597 successfully handled. */
7601 /* Check if we have parsed all the operands. */
7602 if (*str
!= '\0' && ! error_p ())
7604 /* Set I to the index of the last present operand; this is
7605 for the purpose of diagnostics. */
7606 for (i
-= 1; i
>= 0 && !inst
.base
.operands
[i
].present
; --i
)
7608 set_fatal_syntax_error
7609 (_("unexpected characters following instruction"));
7612 parse_operands_return
:
7616 DEBUG_TRACE ("parsing FAIL: %s - %s",
7617 operand_mismatch_kind_names
[get_error_kind ()],
7618 get_error_message ());
7619 /* Record the operand error properly; this is useful when there
7620 are multiple instruction templates for a mnemonic name, so that
7621 later on, we can select the error that most closely describes
7623 record_operand_error (opcode
, i
, get_error_kind (),
7624 get_error_message ());
7629 DEBUG_TRACE ("parsing SUCCESS");
7634 /* It does some fix-up to provide some programmer friendly feature while
7635 keeping the libopcodes happy, i.e. libopcodes only accepts
7636 the preferred architectural syntax.
7637 Return FALSE if there is any failure; otherwise return TRUE. */
7640 programmer_friendly_fixup (aarch64_instruction
*instr
)
7642 aarch64_inst
*base
= &instr
->base
;
7643 const aarch64_opcode
*opcode
= base
->opcode
;
7644 enum aarch64_op op
= opcode
->op
;
7645 aarch64_opnd_info
*operands
= base
->operands
;
7647 DEBUG_TRACE ("enter");
7649 switch (opcode
->iclass
)
7652 /* TBNZ Xn|Wn, #uimm6, label
7653 Test and Branch Not Zero: conditionally jumps to label if bit number
7654 uimm6 in register Xn is not zero. The bit number implies the width of
7655 the register, which may be written and should be disassembled as Wn if
7656 uimm is less than 32. */
7657 if (operands
[0].qualifier
== AARCH64_OPND_QLF_W
)
7659 if (operands
[1].imm
.value
>= 32)
7661 record_operand_out_of_range_error (opcode
, 1, _("immediate value"),
7665 operands
[0].qualifier
= AARCH64_OPND_QLF_X
;
7669 /* LDR Wt, label | =value
7670 As a convenience assemblers will typically permit the notation
7671 "=value" in conjunction with the pc-relative literal load instructions
7672 to automatically place an immediate value or symbolic address in a
7673 nearby literal pool and generate a hidden label which references it.
7674 ISREG has been set to 0 in the case of =value. */
7675 if (instr
->gen_lit_pool
7676 && (op
== OP_LDR_LIT
|| op
== OP_LDRV_LIT
|| op
== OP_LDRSW_LIT
))
7678 int size
= aarch64_get_qualifier_esize (operands
[0].qualifier
);
7679 if (op
== OP_LDRSW_LIT
)
7681 if (instr
->reloc
.exp
.X_op
!= O_constant
7682 && instr
->reloc
.exp
.X_op
!= O_big
7683 && instr
->reloc
.exp
.X_op
!= O_symbol
)
7685 record_operand_error (opcode
, 1,
7686 AARCH64_OPDE_FATAL_SYNTAX_ERROR
,
7687 _("constant expression expected"));
7690 if (! add_to_lit_pool (&instr
->reloc
.exp
, size
))
7692 record_operand_error (opcode
, 1,
7693 AARCH64_OPDE_OTHER_ERROR
,
7694 _("literal pool insertion failed"));
7702 Unsigned Extend Byte|Halfword|Word: UXT[BH] is architectural alias
7703 for UBFM Wd,Wn,#0,#7|15, while UXTW is pseudo instruction which is
7704 encoded using ORR Wd, WZR, Wn (MOV Wd,Wn).
7705 A programmer-friendly assembler should accept a destination Xd in
7706 place of Wd, however that is not the preferred form for disassembly.
7708 if ((op
== OP_UXTB
|| op
== OP_UXTH
|| op
== OP_UXTW
)
7709 && operands
[1].qualifier
== AARCH64_OPND_QLF_W
7710 && operands
[0].qualifier
== AARCH64_OPND_QLF_X
)
7711 operands
[0].qualifier
= AARCH64_OPND_QLF_W
;
7716 /* In the 64-bit form, the final register operand is written as Wm
7717 for all but the (possibly omitted) UXTX/LSL and SXTX
7719 As a programmer-friendly assembler, we accept e.g.
7720 ADDS <Xd>, <Xn|SP>, <Xm>{, UXTB {#<amount>}} and change it to
7721 ADDS <Xd>, <Xn|SP>, <Wm>{, UXTB {#<amount>}}. */
7722 int idx
= aarch64_operand_index (opcode
->operands
,
7723 AARCH64_OPND_Rm_EXT
);
7724 gas_assert (idx
== 1 || idx
== 2);
7725 if (operands
[0].qualifier
== AARCH64_OPND_QLF_X
7726 && operands
[idx
].qualifier
== AARCH64_OPND_QLF_X
7727 && operands
[idx
].shifter
.kind
!= AARCH64_MOD_LSL
7728 && operands
[idx
].shifter
.kind
!= AARCH64_MOD_UXTX
7729 && operands
[idx
].shifter
.kind
!= AARCH64_MOD_SXTX
)
7730 operands
[idx
].qualifier
= AARCH64_OPND_QLF_W
;
7738 DEBUG_TRACE ("exit with SUCCESS");
7742 /* Check for loads and stores that will cause unpredictable behavior. */
7745 warn_unpredictable_ldst (aarch64_instruction
*instr
, char *str
)
7747 aarch64_inst
*base
= &instr
->base
;
7748 const aarch64_opcode
*opcode
= base
->opcode
;
7749 const aarch64_opnd_info
*opnds
= base
->operands
;
7750 switch (opcode
->iclass
)
7757 /* Loading/storing the base register is unpredictable if writeback. */
7758 if ((aarch64_get_operand_class (opnds
[0].type
)
7759 == AARCH64_OPND_CLASS_INT_REG
)
7760 && opnds
[0].reg
.regno
== opnds
[1].addr
.base_regno
7761 && opnds
[1].addr
.base_regno
!= REG_SP
7762 /* Exempt STG/STZG/ST2G/STZ2G. */
7763 && !(opnds
[1].type
== AARCH64_OPND_ADDR_SIMM13
)
7764 && opnds
[1].addr
.writeback
)
7765 as_warn (_("unpredictable transfer with writeback -- `%s'"), str
);
7769 case ldstnapair_offs
:
7770 case ldstpair_indexed
:
7771 /* Loading/storing the base register is unpredictable if writeback. */
7772 if ((aarch64_get_operand_class (opnds
[0].type
)
7773 == AARCH64_OPND_CLASS_INT_REG
)
7774 && (opnds
[0].reg
.regno
== opnds
[2].addr
.base_regno
7775 || opnds
[1].reg
.regno
== opnds
[2].addr
.base_regno
)
7776 && opnds
[2].addr
.base_regno
!= REG_SP
7778 && !(opnds
[2].type
== AARCH64_OPND_ADDR_SIMM11
)
7779 && opnds
[2].addr
.writeback
)
7780 as_warn (_("unpredictable transfer with writeback -- `%s'"), str
);
7781 /* Load operations must load different registers. */
7782 if ((opcode
->opcode
& (1 << 22))
7783 && opnds
[0].reg
.regno
== opnds
[1].reg
.regno
)
7784 as_warn (_("unpredictable load of register pair -- `%s'"), str
);
7788 if ((aarch64_get_operand_class (opnds
[0].type
)
7789 == AARCH64_OPND_CLASS_INT_REG
)
7790 && (aarch64_get_operand_class (opnds
[1].type
)
7791 == AARCH64_OPND_CLASS_INT_REG
))
7793 if ((opcode
->opcode
& (1 << 22)))
7795 /* It is unpredictable if load-exclusive pair with Rt == Rt2. */
7796 if ((opcode
->opcode
& (1 << 21))
7797 && opnds
[0].reg
.regno
== opnds
[1].reg
.regno
)
7798 as_warn (_("unpredictable load of register pair -- `%s'"), str
);
7802 /* Store-Exclusive is unpredictable if Rt == Rs. */
7803 if (opnds
[0].reg
.regno
== opnds
[1].reg
.regno
)
7805 (_("unpredictable: identical transfer and status registers"
7808 if (opnds
[0].reg
.regno
== opnds
[2].reg
.regno
)
7810 if (!(opcode
->opcode
& (1 << 21)))
7811 /* Store-Exclusive is unpredictable if Rn == Rs. */
7813 (_("unpredictable: identical base and status registers"
7816 /* Store-Exclusive pair is unpredictable if Rt2 == Rs. */
7818 (_("unpredictable: "
7819 "identical transfer and status registers"
7823 /* Store-Exclusive pair is unpredictable if Rn == Rs. */
7824 if ((opcode
->opcode
& (1 << 21))
7825 && opnds
[0].reg
.regno
== opnds
[3].reg
.regno
7826 && opnds
[3].reg
.regno
!= REG_SP
)
7827 as_warn (_("unpredictable: identical base and status registers"
7839 force_automatic_sequence_close (void)
7841 struct aarch64_segment_info_type
*tc_seg_info
;
7843 tc_seg_info
= &seg_info (now_seg
)->tc_segment_info_data
;
7844 if (tc_seg_info
->insn_sequence
.instr
)
7846 as_warn_where (tc_seg_info
->last_file
, tc_seg_info
->last_line
,
7847 _("previous `%s' sequence has not been closed"),
7848 tc_seg_info
->insn_sequence
.instr
->opcode
->name
);
7849 init_insn_sequence (NULL
, &tc_seg_info
->insn_sequence
);
7853 /* A wrapper function to interface with libopcodes on encoding and
7854 record the error message if there is any.
7856 Return TRUE on success; otherwise return FALSE. */
7859 do_encode (const aarch64_opcode
*opcode
, aarch64_inst
*instr
,
7862 aarch64_operand_error error_info
;
7863 memset (&error_info
, '\0', sizeof (error_info
));
7864 error_info
.kind
= AARCH64_OPDE_NIL
;
7865 if (aarch64_opcode_encode (opcode
, instr
, code
, NULL
, &error_info
, insn_sequence
)
7866 && !error_info
.non_fatal
)
7869 gas_assert (error_info
.kind
!= AARCH64_OPDE_NIL
);
7870 record_operand_error_info (opcode
, &error_info
);
7871 return error_info
.non_fatal
;
7874 #ifdef DEBUG_AARCH64
7876 dump_opcode_operands (const aarch64_opcode
*opcode
)
7879 while (opcode
->operands
[i
] != AARCH64_OPND_NIL
)
7881 aarch64_verbose ("\t\t opnd%d: %s", i
,
7882 aarch64_get_operand_name (opcode
->operands
[i
])[0] != '\0'
7883 ? aarch64_get_operand_name (opcode
->operands
[i
])
7884 : aarch64_get_operand_desc (opcode
->operands
[i
]));
7888 #endif /* DEBUG_AARCH64 */
7890 /* This is the guts of the machine-dependent assembler. STR points to a
7891 machine dependent instruction. This function is supposed to emit
7892 the frags/bytes it assembles to. */
7895 md_assemble (char *str
)
7897 templates
*template;
7898 const aarch64_opcode
*opcode
;
7899 struct aarch64_segment_info_type
*tc_seg_info
;
7900 aarch64_inst
*inst_base
;
7901 unsigned saved_cond
;
7903 /* Align the previous label if needed. */
7904 if (last_label_seen
!= NULL
)
7906 symbol_set_frag (last_label_seen
, frag_now
);
7907 S_SET_VALUE (last_label_seen
, (valueT
) frag_now_fix ());
7908 S_SET_SEGMENT (last_label_seen
, now_seg
);
7911 /* Update the current insn_sequence from the segment. */
7912 tc_seg_info
= &seg_info (now_seg
)->tc_segment_info_data
;
7913 insn_sequence
= &tc_seg_info
->insn_sequence
;
7914 tc_seg_info
->last_file
= as_where (&tc_seg_info
->last_line
);
7916 inst
.reloc
.type
= BFD_RELOC_UNUSED
;
7918 DEBUG_TRACE ("\n\n");
7919 DEBUG_TRACE ("==============================");
7920 DEBUG_TRACE ("Enter md_assemble with %s", str
);
7922 /* Scan up to the end of the mnemonic, which must end in whitespace,
7923 '.', or end of string. */
7926 for (; is_part_of_name (*p
); p
++)
7927 if (*p
== '.' && !dot
)
7932 as_bad (_("unknown mnemonic -- `%s'"), str
);
7936 if (!dot
&& create_register_alias (str
, p
))
7939 template = opcode_lookup (str
, dot
, p
);
7942 as_bad (_("unknown mnemonic `%s' -- `%s'"), get_mnemonic_name (str
),
7947 skip_whitespace (p
);
7950 as_bad (_("unexpected comma after the mnemonic name `%s' -- `%s'"),
7951 get_mnemonic_name (str
), str
);
7955 init_operand_error_report ();
7957 /* Sections are assumed to start aligned. In executable section, there is no
7958 MAP_DATA symbol pending. So we only align the address during
7959 MAP_DATA --> MAP_INSN transition.
7960 For other sections, this is not guaranteed. */
7961 enum mstate mapstate
= seg_info (now_seg
)->tc_segment_info_data
.mapstate
;
7962 if (!need_pass_2
&& subseg_text_p (now_seg
) && mapstate
== MAP_DATA
)
7963 frag_align_code (2, 0);
7965 saved_cond
= inst
.cond
;
7966 reset_aarch64_instruction (&inst
);
7967 inst
.cond
= saved_cond
;
7969 /* Iterate through all opcode entries with the same mnemonic name. */
7972 opcode
= template->opcode
;
7974 DEBUG_TRACE ("opcode %s found", opcode
->name
);
7975 #ifdef DEBUG_AARCH64
7977 dump_opcode_operands (opcode
);
7978 #endif /* DEBUG_AARCH64 */
7980 mapping_state (MAP_INSN
);
7982 inst_base
= &inst
.base
;
7983 inst_base
->opcode
= opcode
;
7985 /* Truly conditionally executed instructions, e.g. b.cond. */
7986 if (opcode
->flags
& F_COND
)
7988 gas_assert (inst
.cond
!= COND_ALWAYS
);
7989 inst_base
->cond
= get_cond_from_value (inst
.cond
);
7990 DEBUG_TRACE ("condition found %s", inst_base
->cond
->names
[0]);
7992 else if (inst
.cond
!= COND_ALWAYS
)
7994 /* It shouldn't arrive here, where the assembly looks like a
7995 conditional instruction but the found opcode is unconditional. */
8000 if (parse_operands (p
, opcode
)
8001 && programmer_friendly_fixup (&inst
)
8002 && do_encode (inst_base
->opcode
, &inst
.base
, &inst_base
->value
))
8004 /* Check that this instruction is supported for this CPU. */
8005 if (!opcode
->avariant
8006 || !AARCH64_CPU_HAS_ALL_FEATURES (cpu_variant
, *opcode
->avariant
))
8008 as_bad (_("selected processor does not support `%s'"), str
);
8012 warn_unpredictable_ldst (&inst
, str
);
8014 if (inst
.reloc
.type
== BFD_RELOC_UNUSED
8015 || !inst
.reloc
.need_libopcodes_p
)
8019 /* If there is relocation generated for the instruction,
8020 store the instruction information for the future fix-up. */
8021 struct aarch64_inst
*copy
;
8022 gas_assert (inst
.reloc
.type
!= BFD_RELOC_UNUSED
);
8023 copy
= XNEW (struct aarch64_inst
);
8024 memcpy (copy
, &inst
.base
, sizeof (struct aarch64_inst
));
8028 /* Issue non-fatal messages if any. */
8029 output_operand_error_report (str
, true);
8033 template = template->next
;
8034 if (template != NULL
)
8036 reset_aarch64_instruction (&inst
);
8037 inst
.cond
= saved_cond
;
8040 while (template != NULL
);
8042 /* Issue the error messages if any. */
8043 output_operand_error_report (str
, false);
8046 /* Various frobbings of labels and their addresses. */
8049 aarch64_start_line_hook (void)
8051 last_label_seen
= NULL
;
8055 aarch64_frob_label (symbolS
* sym
)
8057 last_label_seen
= sym
;
8059 dwarf2_emit_label (sym
);
8063 aarch64_frob_section (asection
*sec ATTRIBUTE_UNUSED
)
8065 /* Check to see if we have a block to close. */
8066 force_automatic_sequence_close ();
8070 aarch64_data_in_code (void)
8072 if (startswith (input_line_pointer
+ 1, "data:"))
8074 *input_line_pointer
= '/';
8075 input_line_pointer
+= 5;
8076 *input_line_pointer
= 0;
8084 aarch64_canonicalize_symbol_name (char *name
)
8088 if ((len
= strlen (name
)) > 5 && streq (name
+ len
- 5, "/data"))
8089 *(name
+ len
- 5) = 0;
8094 /* Table of all register names defined by default. The user can
8095 define additional names with .req. Note that all register names
8096 should appear in both upper and lowercase variants. Some registers
8097 also have mixed-case names. */
8099 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, true }
8100 #define REGDEF_ALIAS(s, n, t) { #s, n, REG_TYPE_##t, false}
8101 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
8102 #define REGNUMS(p,n,s,t) REGDEF(p##n##s, n, t)
8103 #define REGSET16(p,t) \
8104 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
8105 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
8106 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
8107 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
8108 #define REGSET16S(p,s,t) \
8109 REGNUMS(p, 0,s,t), REGNUMS(p, 1,s,t), REGNUMS(p, 2,s,t), REGNUMS(p, 3,s,t), \
8110 REGNUMS(p, 4,s,t), REGNUMS(p, 5,s,t), REGNUMS(p, 6,s,t), REGNUMS(p, 7,s,t), \
8111 REGNUMS(p, 8,s,t), REGNUMS(p, 9,s,t), REGNUMS(p,10,s,t), REGNUMS(p,11,s,t), \
8112 REGNUMS(p,12,s,t), REGNUMS(p,13,s,t), REGNUMS(p,14,s,t), REGNUMS(p,15,s,t)
8113 #define REGSET31(p,t) \
8115 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
8116 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
8117 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
8118 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t)
8119 #define REGSET(p,t) \
8120 REGSET31(p,t), REGNUM(p,31,t)
8122 /* These go into aarch64_reg_hsh hash-table. */
8123 static const reg_entry reg_names
[] = {
8124 /* Integer registers. */
8125 REGSET31 (x
, R_64
), REGSET31 (X
, R_64
),
8126 REGSET31 (w
, R_32
), REGSET31 (W
, R_32
),
8128 REGDEF_ALIAS (ip0
, 16, R_64
), REGDEF_ALIAS (IP0
, 16, R_64
),
8129 REGDEF_ALIAS (ip1
, 17, R_64
), REGDEF_ALIAS (IP1
, 17, R_64
),
8130 REGDEF_ALIAS (fp
, 29, R_64
), REGDEF_ALIAS (FP
, 29, R_64
),
8131 REGDEF_ALIAS (lr
, 30, R_64
), REGDEF_ALIAS (LR
, 30, R_64
),
8132 REGDEF (wsp
, 31, SP_32
), REGDEF (WSP
, 31, SP_32
),
8133 REGDEF (sp
, 31, SP_64
), REGDEF (SP
, 31, SP_64
),
8135 REGDEF (wzr
, 31, Z_32
), REGDEF (WZR
, 31, Z_32
),
8136 REGDEF (xzr
, 31, Z_64
), REGDEF (XZR
, 31, Z_64
),
8138 /* Floating-point single precision registers. */
8139 REGSET (s
, FP_S
), REGSET (S
, FP_S
),
8141 /* Floating-point double precision registers. */
8142 REGSET (d
, FP_D
), REGSET (D
, FP_D
),
8144 /* Floating-point half precision registers. */
8145 REGSET (h
, FP_H
), REGSET (H
, FP_H
),
8147 /* Floating-point byte precision registers. */
8148 REGSET (b
, FP_B
), REGSET (B
, FP_B
),
8150 /* Floating-point quad precision registers. */
8151 REGSET (q
, FP_Q
), REGSET (Q
, FP_Q
),
8153 /* FP/SIMD registers. */
8154 REGSET (v
, VN
), REGSET (V
, VN
),
8156 /* SVE vector registers. */
8157 REGSET (z
, ZN
), REGSET (Z
, ZN
),
8159 /* SVE predicate registers. */
8160 REGSET16 (p
, PN
), REGSET16 (P
, PN
),
8162 /* SME ZA tile registers. */
8163 REGSET16 (za
, ZA
), REGSET16 (ZA
, ZA
),
8165 /* SME ZA tile registers (horizontal slice). */
8166 REGSET16S (za
, h
, ZAH
), REGSET16S (ZA
, H
, ZAH
),
8168 /* SME ZA tile registers (vertical slice). */
8169 REGSET16S (za
, v
, ZAV
), REGSET16S (ZA
, V
, ZAV
)
8187 #define B(a,b,c,d) (((a) << 3) | ((b) << 2) | ((c) << 1) | (d))
8188 static const asm_nzcv nzcv_names
[] = {
8189 {"nzcv", B (n
, z
, c
, v
)},
8190 {"nzcV", B (n
, z
, c
, V
)},
8191 {"nzCv", B (n
, z
, C
, v
)},
8192 {"nzCV", B (n
, z
, C
, V
)},
8193 {"nZcv", B (n
, Z
, c
, v
)},
8194 {"nZcV", B (n
, Z
, c
, V
)},
8195 {"nZCv", B (n
, Z
, C
, v
)},
8196 {"nZCV", B (n
, Z
, C
, V
)},
8197 {"Nzcv", B (N
, z
, c
, v
)},
8198 {"NzcV", B (N
, z
, c
, V
)},
8199 {"NzCv", B (N
, z
, C
, v
)},
8200 {"NzCV", B (N
, z
, C
, V
)},
8201 {"NZcv", B (N
, Z
, c
, v
)},
8202 {"NZcV", B (N
, Z
, c
, V
)},
8203 {"NZCv", B (N
, Z
, C
, v
)},
8204 {"NZCV", B (N
, Z
, C
, V
)}
8217 /* MD interface: bits in the object file. */
8219 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
8220 for use in the a.out file, and stores them in the array pointed to by buf.
8221 This knows about the endian-ness of the target machine and does
8222 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
8223 2 (short) and 4 (long) Floating numbers are put out as a series of
8224 LITTLENUMS (shorts, here at least). */
8227 md_number_to_chars (char *buf
, valueT val
, int n
)
8229 if (target_big_endian
)
8230 number_to_chars_bigendian (buf
, val
, n
);
8232 number_to_chars_littleendian (buf
, val
, n
);
8235 /* MD interface: Sections. */
8237 /* Estimate the size of a frag before relaxing. Assume everything fits in
8241 md_estimate_size_before_relax (fragS
* fragp
, segT segtype ATTRIBUTE_UNUSED
)
8247 /* Round up a section size to the appropriate boundary. */
8250 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
8255 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
8256 of an rs_align_code fragment.
8258 Here we fill the frag with the appropriate info for padding the
8259 output stream. The resulting frag will consist of a fixed (fr_fix)
8260 and of a repeating (fr_var) part.
8262 The fixed content is always emitted before the repeating content and
8263 these two parts are used as follows in constructing the output:
8264 - the fixed part will be used to align to a valid instruction word
8265 boundary, in case that we start at a misaligned address; as no
8266 executable instruction can live at the misaligned location, we
8267 simply fill with zeros;
8268 - the variable part will be used to cover the remaining padding and
8269 we fill using the AArch64 NOP instruction.
8271 Note that the size of a RS_ALIGN_CODE fragment is always 7 to provide
8272 enough storage space for up to 3 bytes for padding the back to a valid
8273 instruction alignment and exactly 4 bytes to store the NOP pattern. */
8276 aarch64_handle_align (fragS
* fragP
)
8278 /* NOP = d503201f */
8279 /* AArch64 instructions are always little-endian. */
8280 static unsigned char const aarch64_noop
[4] = { 0x1f, 0x20, 0x03, 0xd5 };
8282 int bytes
, fix
, noop_size
;
8285 if (fragP
->fr_type
!= rs_align_code
)
8288 bytes
= fragP
->fr_next
->fr_address
- fragP
->fr_address
- fragP
->fr_fix
;
8289 p
= fragP
->fr_literal
+ fragP
->fr_fix
;
8292 gas_assert (fragP
->tc_frag_data
.recorded
);
8295 noop_size
= sizeof (aarch64_noop
);
8297 fix
= bytes
& (noop_size
- 1);
8301 insert_data_mapping_symbol (MAP_INSN
, fragP
->fr_fix
, fragP
, fix
);
8305 fragP
->fr_fix
+= fix
;
8309 memcpy (p
, aarch64_noop
, noop_size
);
8310 fragP
->fr_var
= noop_size
;
8313 /* Perform target specific initialisation of a frag.
8314 Note - despite the name this initialisation is not done when the frag
8315 is created, but only when its type is assigned. A frag can be created
8316 and used a long time before its type is set, so beware of assuming that
8317 this initialisation is performed first. */
8321 aarch64_init_frag (fragS
* fragP ATTRIBUTE_UNUSED
,
8322 int max_chars ATTRIBUTE_UNUSED
)
8326 #else /* OBJ_ELF is defined. */
8328 aarch64_init_frag (fragS
* fragP
, int max_chars
)
8330 /* Record a mapping symbol for alignment frags. We will delete this
8331 later if the alignment ends up empty. */
8332 if (!fragP
->tc_frag_data
.recorded
)
8333 fragP
->tc_frag_data
.recorded
= 1;
8335 /* PR 21809: Do not set a mapping state for debug sections
8336 - it just confuses other tools. */
8337 if (bfd_section_flags (now_seg
) & SEC_DEBUGGING
)
8340 switch (fragP
->fr_type
)
8344 mapping_state_2 (MAP_DATA
, max_chars
);
8347 /* PR 20364: We can get alignment frags in code sections,
8348 so do not just assume that we should use the MAP_DATA state. */
8349 mapping_state_2 (subseg_text_p (now_seg
) ? MAP_INSN
: MAP_DATA
, max_chars
);
8352 mapping_state_2 (MAP_INSN
, max_chars
);
8359 /* Initialize the DWARF-2 unwind information for this procedure. */
8362 tc_aarch64_frame_initial_instructions (void)
8364 cfi_add_CFA_def_cfa (REG_SP
, 0);
8366 #endif /* OBJ_ELF */
8368 /* Convert REGNAME to a DWARF-2 register number. */
8371 tc_aarch64_regname_to_dw2regnum (char *regname
)
8373 const reg_entry
*reg
= parse_reg (®name
);
8379 case REG_TYPE_SP_32
:
8380 case REG_TYPE_SP_64
:
8390 return reg
->number
+ 64;
8398 /* Implement DWARF2_ADDR_SIZE. */
8401 aarch64_dwarf2_addr_size (void)
8403 #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF)
8407 return bfd_arch_bits_per_address (stdoutput
) / 8;
8410 /* MD interface: Symbol and relocation handling. */
8412 /* Return the address within the segment that a PC-relative fixup is
8413 relative to. For AArch64 PC-relative fixups applied to instructions
8414 are generally relative to the location plus AARCH64_PCREL_OFFSET bytes. */
8417 md_pcrel_from_section (fixS
* fixP
, segT seg
)
8419 offsetT base
= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
8421 /* If this is pc-relative and we are going to emit a relocation
8422 then we just want to put out any pipeline compensation that the linker
8423 will need. Otherwise we want to use the calculated base. */
8425 && ((fixP
->fx_addsy
&& S_GET_SEGMENT (fixP
->fx_addsy
) != seg
)
8426 || aarch64_force_relocation (fixP
)))
8429 /* AArch64 should be consistent for all pc-relative relocations. */
8430 return base
+ AARCH64_PCREL_OFFSET
;
8433 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
8434 Otherwise we have no need to default values of symbols. */
8437 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
8440 if (name
[0] == '_' && name
[1] == 'G'
8441 && streq (name
, GLOBAL_OFFSET_TABLE_NAME
))
8445 if (symbol_find (name
))
8446 as_bad (_("GOT already in the symbol table"));
8448 GOT_symbol
= symbol_new (name
, undefined_section
,
8449 &zero_address_frag
, 0);
8459 /* Return non-zero if the indicated VALUE has overflowed the maximum
8460 range expressible by a unsigned number with the indicated number of
8464 unsigned_overflow (valueT value
, unsigned bits
)
8467 if (bits
>= sizeof (valueT
) * 8)
8469 lim
= (valueT
) 1 << bits
;
8470 return (value
>= lim
);
8474 /* Return non-zero if the indicated VALUE has overflowed the maximum
8475 range expressible by an signed number with the indicated number of
8479 signed_overflow (offsetT value
, unsigned bits
)
8482 if (bits
>= sizeof (offsetT
) * 8)
8484 lim
= (offsetT
) 1 << (bits
- 1);
8485 return (value
< -lim
|| value
>= lim
);
8488 /* Given an instruction in *INST, which is expected to be a scaled, 12-bit,
8489 unsigned immediate offset load/store instruction, try to encode it as
8490 an unscaled, 9-bit, signed immediate offset load/store instruction.
8491 Return TRUE if it is successful; otherwise return FALSE.
8493 As a programmer-friendly assembler, LDUR/STUR instructions can be generated
8494 in response to the standard LDR/STR mnemonics when the immediate offset is
8495 unambiguous, i.e. when it is negative or unaligned. */
8498 try_to_encode_as_unscaled_ldst (aarch64_inst
*instr
)
8501 enum aarch64_op new_op
;
8502 const aarch64_opcode
*new_opcode
;
8504 gas_assert (instr
->opcode
->iclass
== ldst_pos
);
8506 switch (instr
->opcode
->op
)
8508 case OP_LDRB_POS
:new_op
= OP_LDURB
; break;
8509 case OP_STRB_POS
: new_op
= OP_STURB
; break;
8510 case OP_LDRSB_POS
: new_op
= OP_LDURSB
; break;
8511 case OP_LDRH_POS
: new_op
= OP_LDURH
; break;
8512 case OP_STRH_POS
: new_op
= OP_STURH
; break;
8513 case OP_LDRSH_POS
: new_op
= OP_LDURSH
; break;
8514 case OP_LDR_POS
: new_op
= OP_LDUR
; break;
8515 case OP_STR_POS
: new_op
= OP_STUR
; break;
8516 case OP_LDRF_POS
: new_op
= OP_LDURV
; break;
8517 case OP_STRF_POS
: new_op
= OP_STURV
; break;
8518 case OP_LDRSW_POS
: new_op
= OP_LDURSW
; break;
8519 case OP_PRFM_POS
: new_op
= OP_PRFUM
; break;
8520 default: new_op
= OP_NIL
; break;
8523 if (new_op
== OP_NIL
)
8526 new_opcode
= aarch64_get_opcode (new_op
);
8527 gas_assert (new_opcode
!= NULL
);
8529 DEBUG_TRACE ("Check programmer-friendly STURB/LDURB -> STRB/LDRB: %d == %d",
8530 instr
->opcode
->op
, new_opcode
->op
);
8532 aarch64_replace_opcode (instr
, new_opcode
);
8534 /* Clear up the ADDR_SIMM9's qualifier; otherwise the
8535 qualifier matching may fail because the out-of-date qualifier will
8536 prevent the operand being updated with a new and correct qualifier. */
8537 idx
= aarch64_operand_index (instr
->opcode
->operands
,
8538 AARCH64_OPND_ADDR_SIMM9
);
8539 gas_assert (idx
== 1);
8540 instr
->operands
[idx
].qualifier
= AARCH64_OPND_QLF_NIL
;
8542 DEBUG_TRACE ("Found LDURB entry to encode programmer-friendly LDRB");
8544 if (!aarch64_opcode_encode (instr
->opcode
, instr
, &instr
->value
, NULL
, NULL
,
8551 /* Called by fix_insn to fix a MOV immediate alias instruction.
8553 Operand for a generic move immediate instruction, which is an alias
8554 instruction that generates a single MOVZ, MOVN or ORR instruction to loads
8555 a 32-bit/64-bit immediate value into general register. An assembler error
8556 shall result if the immediate cannot be created by a single one of these
8557 instructions. If there is a choice, then to ensure reversability an
8558 assembler must prefer a MOVZ to MOVN, and MOVZ or MOVN to ORR. */
8561 fix_mov_imm_insn (fixS
*fixP
, char *buf
, aarch64_inst
*instr
, offsetT value
)
8563 const aarch64_opcode
*opcode
;
8565 /* Need to check if the destination is SP/ZR. The check has to be done
8566 before any aarch64_replace_opcode. */
8567 int try_mov_wide_p
= !aarch64_stack_pointer_p (&instr
->operands
[0]);
8568 int try_mov_bitmask_p
= !aarch64_zero_register_p (&instr
->operands
[0]);
8570 instr
->operands
[1].imm
.value
= value
;
8571 instr
->operands
[1].skip
= 0;
8575 /* Try the MOVZ alias. */
8576 opcode
= aarch64_get_opcode (OP_MOV_IMM_WIDE
);
8577 aarch64_replace_opcode (instr
, opcode
);
8578 if (aarch64_opcode_encode (instr
->opcode
, instr
,
8579 &instr
->value
, NULL
, NULL
, insn_sequence
))
8581 put_aarch64_insn (buf
, instr
->value
);
8584 /* Try the MOVK alias. */
8585 opcode
= aarch64_get_opcode (OP_MOV_IMM_WIDEN
);
8586 aarch64_replace_opcode (instr
, opcode
);
8587 if (aarch64_opcode_encode (instr
->opcode
, instr
,
8588 &instr
->value
, NULL
, NULL
, insn_sequence
))
8590 put_aarch64_insn (buf
, instr
->value
);
8595 if (try_mov_bitmask_p
)
8597 /* Try the ORR alias. */
8598 opcode
= aarch64_get_opcode (OP_MOV_IMM_LOG
);
8599 aarch64_replace_opcode (instr
, opcode
);
8600 if (aarch64_opcode_encode (instr
->opcode
, instr
,
8601 &instr
->value
, NULL
, NULL
, insn_sequence
))
8603 put_aarch64_insn (buf
, instr
->value
);
8608 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8609 _("immediate cannot be moved by a single instruction"));
8612 /* An instruction operand which is immediate related may have symbol used
8613 in the assembly, e.g.
8616 .set u32, 0x00ffff00
8618 At the time when the assembly instruction is parsed, a referenced symbol,
8619 like 'u32' in the above example may not have been seen; a fixS is created
8620 in such a case and is handled here after symbols have been resolved.
8621 Instruction is fixed up with VALUE using the information in *FIXP plus
8622 extra information in FLAGS.
8624 This function is called by md_apply_fix to fix up instructions that need
8625 a fix-up described above but does not involve any linker-time relocation. */
8628 fix_insn (fixS
*fixP
, uint32_t flags
, offsetT value
)
8632 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
8633 enum aarch64_opnd opnd
= fixP
->tc_fix_data
.opnd
;
8634 aarch64_inst
*new_inst
= fixP
->tc_fix_data
.inst
;
8638 /* Now the instruction is about to be fixed-up, so the operand that
8639 was previously marked as 'ignored' needs to be unmarked in order
8640 to get the encoding done properly. */
8641 idx
= aarch64_operand_index (new_inst
->opcode
->operands
, opnd
);
8642 new_inst
->operands
[idx
].skip
= 0;
8645 gas_assert (opnd
!= AARCH64_OPND_NIL
);
8649 case AARCH64_OPND_EXCEPTION
:
8650 case AARCH64_OPND_UNDEFINED
:
8651 if (unsigned_overflow (value
, 16))
8652 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8653 _("immediate out of range"));
8654 insn
= get_aarch64_insn (buf
);
8655 insn
|= (opnd
== AARCH64_OPND_EXCEPTION
) ? encode_svc_imm (value
) : value
;
8656 put_aarch64_insn (buf
, insn
);
8659 case AARCH64_OPND_AIMM
:
8660 /* ADD or SUB with immediate.
8661 NOTE this assumes we come here with a add/sub shifted reg encoding
8662 3 322|2222|2 2 2 21111 111111
8663 1 098|7654|3 2 1 09876 543210 98765 43210
8664 0b000000 sf 000|1011|shift 0 Rm imm6 Rn Rd ADD
8665 2b000000 sf 010|1011|shift 0 Rm imm6 Rn Rd ADDS
8666 4b000000 sf 100|1011|shift 0 Rm imm6 Rn Rd SUB
8667 6b000000 sf 110|1011|shift 0 Rm imm6 Rn Rd SUBS
8669 3 322|2222|2 2 221111111111
8670 1 098|7654|3 2 109876543210 98765 43210
8671 11000000 sf 001|0001|shift imm12 Rn Rd ADD
8672 31000000 sf 011|0001|shift imm12 Rn Rd ADDS
8673 51000000 sf 101|0001|shift imm12 Rn Rd SUB
8674 71000000 sf 111|0001|shift imm12 Rn Rd SUBS
8675 Fields sf Rn Rd are already set. */
8676 insn
= get_aarch64_insn (buf
);
8680 insn
= reencode_addsub_switch_add_sub (insn
);
8684 if ((flags
& FIXUP_F_HAS_EXPLICIT_SHIFT
) == 0
8685 && unsigned_overflow (value
, 12))
8687 /* Try to shift the value by 12 to make it fit. */
8688 if (((value
>> 12) << 12) == value
8689 && ! unsigned_overflow (value
, 12 + 12))
8692 insn
|= encode_addsub_imm_shift_amount (1);
8696 if (unsigned_overflow (value
, 12))
8697 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8698 _("immediate out of range"));
8700 insn
|= encode_addsub_imm (value
);
8702 put_aarch64_insn (buf
, insn
);
8705 case AARCH64_OPND_SIMD_IMM
:
8706 case AARCH64_OPND_SIMD_IMM_SFT
:
8707 case AARCH64_OPND_LIMM
:
8708 /* Bit mask immediate. */
8709 gas_assert (new_inst
!= NULL
);
8710 idx
= aarch64_operand_index (new_inst
->opcode
->operands
, opnd
);
8711 new_inst
->operands
[idx
].imm
.value
= value
;
8712 if (aarch64_opcode_encode (new_inst
->opcode
, new_inst
,
8713 &new_inst
->value
, NULL
, NULL
, insn_sequence
))
8714 put_aarch64_insn (buf
, new_inst
->value
);
8716 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8717 _("invalid immediate"));
8720 case AARCH64_OPND_HALF
:
8721 /* 16-bit unsigned immediate. */
8722 if (unsigned_overflow (value
, 16))
8723 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8724 _("immediate out of range"));
8725 insn
= get_aarch64_insn (buf
);
8726 insn
|= encode_movw_imm (value
& 0xffff);
8727 put_aarch64_insn (buf
, insn
);
8730 case AARCH64_OPND_IMM_MOV
:
8731 /* Operand for a generic move immediate instruction, which is
8732 an alias instruction that generates a single MOVZ, MOVN or ORR
8733 instruction to loads a 32-bit/64-bit immediate value into general
8734 register. An assembler error shall result if the immediate cannot be
8735 created by a single one of these instructions. If there is a choice,
8736 then to ensure reversability an assembler must prefer a MOVZ to MOVN,
8737 and MOVZ or MOVN to ORR. */
8738 gas_assert (new_inst
!= NULL
);
8739 fix_mov_imm_insn (fixP
, buf
, new_inst
, value
);
8742 case AARCH64_OPND_ADDR_SIMM7
:
8743 case AARCH64_OPND_ADDR_SIMM9
:
8744 case AARCH64_OPND_ADDR_SIMM9_2
:
8745 case AARCH64_OPND_ADDR_SIMM10
:
8746 case AARCH64_OPND_ADDR_UIMM12
:
8747 case AARCH64_OPND_ADDR_SIMM11
:
8748 case AARCH64_OPND_ADDR_SIMM13
:
8749 /* Immediate offset in an address. */
8750 insn
= get_aarch64_insn (buf
);
8752 gas_assert (new_inst
!= NULL
&& new_inst
->value
== insn
);
8753 gas_assert (new_inst
->opcode
->operands
[1] == opnd
8754 || new_inst
->opcode
->operands
[2] == opnd
);
8756 /* Get the index of the address operand. */
8757 if (new_inst
->opcode
->operands
[1] == opnd
)
8758 /* e.g. STR <Xt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */
8761 /* e.g. LDP <Qt1>, <Qt2>, [<Xn|SP>{, #<imm>}]. */
8764 /* Update the resolved offset value. */
8765 new_inst
->operands
[idx
].addr
.offset
.imm
= value
;
8767 /* Encode/fix-up. */
8768 if (aarch64_opcode_encode (new_inst
->opcode
, new_inst
,
8769 &new_inst
->value
, NULL
, NULL
, insn_sequence
))
8771 put_aarch64_insn (buf
, new_inst
->value
);
8774 else if (new_inst
->opcode
->iclass
== ldst_pos
8775 && try_to_encode_as_unscaled_ldst (new_inst
))
8777 put_aarch64_insn (buf
, new_inst
->value
);
8781 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8782 _("immediate offset out of range"));
8787 as_fatal (_("unhandled operand code %d"), opnd
);
8791 /* Apply a fixup (fixP) to segment data, once it has been determined
8792 by our caller that we have all the info we need to fix it up.
8794 Parameter valP is the pointer to the value of the bits. */
8797 md_apply_fix (fixS
* fixP
, valueT
* valP
, segT seg
)
8799 offsetT value
= *valP
;
8801 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
8803 unsigned flags
= fixP
->fx_addnumber
;
8805 DEBUG_TRACE ("\n\n");
8806 DEBUG_TRACE ("~~~~~~~~~~~~~~~~~~~~~~~~~");
8807 DEBUG_TRACE ("Enter md_apply_fix");
8809 gas_assert (fixP
->fx_r_type
<= BFD_RELOC_UNUSED
);
8811 /* Note whether this will delete the relocation. */
8813 if (fixP
->fx_addsy
== 0 && !fixP
->fx_pcrel
8814 && aarch64_force_reloc (fixP
->fx_r_type
) <= 0)
8817 /* Process the relocations. */
8818 switch (fixP
->fx_r_type
)
8820 case BFD_RELOC_NONE
:
8821 /* This will need to go in the object file. */
8826 case BFD_RELOC_8_PCREL
:
8827 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8828 md_number_to_chars (buf
, value
, 1);
8832 case BFD_RELOC_16_PCREL
:
8833 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8834 md_number_to_chars (buf
, value
, 2);
8838 case BFD_RELOC_32_PCREL
:
8839 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8840 md_number_to_chars (buf
, value
, 4);
8844 case BFD_RELOC_64_PCREL
:
8845 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8846 md_number_to_chars (buf
, value
, 8);
8849 case BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP
:
8850 /* We claim that these fixups have been processed here, even if
8851 in fact we generate an error because we do not have a reloc
8852 for them, so tc_gen_reloc() will reject them. */
8854 if (fixP
->fx_addsy
&& !S_IS_DEFINED (fixP
->fx_addsy
))
8856 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8857 _("undefined symbol %s used as an immediate value"),
8858 S_GET_NAME (fixP
->fx_addsy
));
8859 goto apply_fix_return
;
8861 fix_insn (fixP
, flags
, value
);
8864 case BFD_RELOC_AARCH64_LD_LO19_PCREL
:
8865 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8868 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8869 _("pc-relative load offset not word aligned"));
8870 if (signed_overflow (value
, 21))
8871 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8872 _("pc-relative load offset out of range"));
8873 insn
= get_aarch64_insn (buf
);
8874 insn
|= encode_ld_lit_ofs_19 (value
>> 2);
8875 put_aarch64_insn (buf
, insn
);
8879 case BFD_RELOC_AARCH64_ADR_LO21_PCREL
:
8880 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8882 if (signed_overflow (value
, 21))
8883 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8884 _("pc-relative address offset out of range"));
8885 insn
= get_aarch64_insn (buf
);
8886 insn
|= encode_adr_imm (value
);
8887 put_aarch64_insn (buf
, insn
);
8891 case BFD_RELOC_AARCH64_BRANCH19
:
8892 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8895 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8896 _("conditional branch target not word aligned"));
8897 if (signed_overflow (value
, 21))
8898 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8899 _("conditional branch out of range"));
8900 insn
= get_aarch64_insn (buf
);
8901 insn
|= encode_cond_branch_ofs_19 (value
>> 2);
8902 put_aarch64_insn (buf
, insn
);
8906 case BFD_RELOC_AARCH64_TSTBR14
:
8907 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8910 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8911 _("conditional branch target not word aligned"));
8912 if (signed_overflow (value
, 16))
8913 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8914 _("conditional branch out of range"));
8915 insn
= get_aarch64_insn (buf
);
8916 insn
|= encode_tst_branch_ofs_14 (value
>> 2);
8917 put_aarch64_insn (buf
, insn
);
8921 case BFD_RELOC_AARCH64_CALL26
:
8922 case BFD_RELOC_AARCH64_JUMP26
:
8923 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8926 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8927 _("branch target not word aligned"));
8928 if (signed_overflow (value
, 28))
8929 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8930 _("branch out of range"));
8931 insn
= get_aarch64_insn (buf
);
8932 insn
|= encode_branch_ofs_26 (value
>> 2);
8933 put_aarch64_insn (buf
, insn
);
8937 case BFD_RELOC_AARCH64_MOVW_G0
:
8938 case BFD_RELOC_AARCH64_MOVW_G0_NC
:
8939 case BFD_RELOC_AARCH64_MOVW_G0_S
:
8940 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC
:
8941 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
8942 case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC
:
8945 case BFD_RELOC_AARCH64_MOVW_G1
:
8946 case BFD_RELOC_AARCH64_MOVW_G1_NC
:
8947 case BFD_RELOC_AARCH64_MOVW_G1_S
:
8948 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
8949 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
8950 case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC
:
8953 case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC
:
8955 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
8956 /* Should always be exported to object file, see
8957 aarch64_force_relocation(). */
8958 gas_assert (!fixP
->fx_done
);
8959 gas_assert (seg
->use_rela_p
);
8961 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
8963 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
8964 /* Should always be exported to object file, see
8965 aarch64_force_relocation(). */
8966 gas_assert (!fixP
->fx_done
);
8967 gas_assert (seg
->use_rela_p
);
8969 case BFD_RELOC_AARCH64_MOVW_G2
:
8970 case BFD_RELOC_AARCH64_MOVW_G2_NC
:
8971 case BFD_RELOC_AARCH64_MOVW_G2_S
:
8972 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
8973 case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC
:
8976 case BFD_RELOC_AARCH64_MOVW_G3
:
8977 case BFD_RELOC_AARCH64_MOVW_PREL_G3
:
8980 if (fixP
->fx_done
|| !seg
->use_rela_p
)
8982 insn
= get_aarch64_insn (buf
);
8986 /* REL signed addend must fit in 16 bits */
8987 if (signed_overflow (value
, 16))
8988 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
8989 _("offset out of range"));
8993 /* Check for overflow and scale. */
8994 switch (fixP
->fx_r_type
)
8996 case BFD_RELOC_AARCH64_MOVW_G0
:
8997 case BFD_RELOC_AARCH64_MOVW_G1
:
8998 case BFD_RELOC_AARCH64_MOVW_G2
:
8999 case BFD_RELOC_AARCH64_MOVW_G3
:
9000 case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1
:
9001 case BFD_RELOC_AARCH64_TLSDESC_OFF_G1
:
9002 if (unsigned_overflow (value
, scale
+ 16))
9003 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
9004 _("unsigned value out of range"));
9006 case BFD_RELOC_AARCH64_MOVW_G0_S
:
9007 case BFD_RELOC_AARCH64_MOVW_G1_S
:
9008 case BFD_RELOC_AARCH64_MOVW_G2_S
:
9009 case BFD_RELOC_AARCH64_MOVW_PREL_G0
:
9010 case BFD_RELOC_AARCH64_MOVW_PREL_G1
:
9011 case BFD_RELOC_AARCH64_MOVW_PREL_G2
:
9012 /* NOTE: We can only come here with movz or movn. */
9013 if (signed_overflow (value
, scale
+ 16))
9014 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
9015 _("signed value out of range"));
9018 /* Force use of MOVN. */
9020 insn
= reencode_movzn_to_movn (insn
);
9024 /* Force use of MOVZ. */
9025 insn
= reencode_movzn_to_movz (insn
);
9029 /* Unchecked relocations. */
9035 /* Insert value into MOVN/MOVZ/MOVK instruction. */
9036 insn
|= encode_movw_imm (value
& 0xffff);
9038 put_aarch64_insn (buf
, insn
);
9042 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC
:
9043 fixP
->fx_r_type
= (ilp32_p
9044 ? BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
9045 : BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
);
9046 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
9047 /* Should always be exported to object file, see
9048 aarch64_force_relocation(). */
9049 gas_assert (!fixP
->fx_done
);
9050 gas_assert (seg
->use_rela_p
);
9053 case BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC
:
9054 fixP
->fx_r_type
= (ilp32_p
9055 ? BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
9056 : BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
);
9057 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
9058 /* Should always be exported to object file, see
9059 aarch64_force_relocation(). */
9060 gas_assert (!fixP
->fx_done
);
9061 gas_assert (seg
->use_rela_p
);
9064 case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12
:
9065 case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21
:
9066 case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21
:
9067 case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC
:
9068 case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12
:
9069 case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19
:
9070 case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
:
9071 case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21
:
9072 case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
:
9073 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC
:
9074 case BFD_RELOC_AARCH64_TLSGD_MOVW_G1
:
9075 case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
:
9076 case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC
:
9077 case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC
:
9078 case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19
:
9079 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC
:
9080 case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1
:
9081 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12
:
9082 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12
:
9083 case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC
:
9084 case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC
:
9085 case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21
:
9086 case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21
:
9087 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12
:
9088 case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC
:
9089 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12
:
9090 case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC
:
9091 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12
:
9092 case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC
:
9093 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12
:
9094 case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC
:
9095 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0
:
9096 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC
:
9097 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1
:
9098 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC
:
9099 case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2
:
9100 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12
:
9101 case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC
:
9102 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12
:
9103 case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC
:
9104 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12
:
9105 case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC
:
9106 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12
:
9107 case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC
:
9108 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
:
9109 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12
:
9110 case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC
:
9111 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0
:
9112 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
:
9113 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
:
9114 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
:
9115 case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
:
9116 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
9117 /* Should always be exported to object file, see
9118 aarch64_force_relocation(). */
9119 gas_assert (!fixP
->fx_done
);
9120 gas_assert (seg
->use_rela_p
);
9123 case BFD_RELOC_AARCH64_LD_GOT_LO12_NC
:
9124 /* Should always be exported to object file, see
9125 aarch64_force_relocation(). */
9126 fixP
->fx_r_type
= (ilp32_p
9127 ? BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
9128 : BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
);
9129 gas_assert (!fixP
->fx_done
);
9130 gas_assert (seg
->use_rela_p
);
9133 case BFD_RELOC_AARCH64_ADD_LO12
:
9134 case BFD_RELOC_AARCH64_ADR_GOT_PAGE
:
9135 case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL
:
9136 case BFD_RELOC_AARCH64_ADR_HI21_PCREL
:
9137 case BFD_RELOC_AARCH64_GOT_LD_PREL19
:
9138 case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC
:
9139 case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14
:
9140 case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15
:
9141 case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15
:
9142 case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC
:
9143 case BFD_RELOC_AARCH64_LDST128_LO12
:
9144 case BFD_RELOC_AARCH64_LDST16_LO12
:
9145 case BFD_RELOC_AARCH64_LDST32_LO12
:
9146 case BFD_RELOC_AARCH64_LDST64_LO12
:
9147 case BFD_RELOC_AARCH64_LDST8_LO12
:
9148 /* Should always be exported to object file, see
9149 aarch64_force_relocation(). */
9150 gas_assert (!fixP
->fx_done
);
9151 gas_assert (seg
->use_rela_p
);
9154 case BFD_RELOC_AARCH64_TLSDESC_ADD
:
9155 case BFD_RELOC_AARCH64_TLSDESC_CALL
:
9156 case BFD_RELOC_AARCH64_TLSDESC_LDR
:
9159 case BFD_RELOC_UNUSED
:
9160 /* An error will already have been reported. */
9164 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
9165 _("unexpected %s fixup"),
9166 bfd_get_reloc_code_name (fixP
->fx_r_type
));
9171 /* Free the allocated the struct aarch64_inst.
9172 N.B. currently there are very limited number of fix-up types actually use
9173 this field, so the impact on the performance should be minimal . */
9174 free (fixP
->tc_fix_data
.inst
);
9179 /* Translate internal representation of relocation info to BFD target
9183 tc_gen_reloc (asection
* section
, fixS
* fixp
)
9186 bfd_reloc_code_real_type code
;
9188 reloc
= XNEW (arelent
);
9190 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
9191 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
9192 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
9196 if (section
->use_rela_p
)
9197 fixp
->fx_offset
-= md_pcrel_from_section (fixp
, section
);
9199 fixp
->fx_offset
= reloc
->address
;
9201 reloc
->addend
= fixp
->fx_offset
;
9203 code
= fixp
->fx_r_type
;
9208 code
= BFD_RELOC_16_PCREL
;
9213 code
= BFD_RELOC_32_PCREL
;
9218 code
= BFD_RELOC_64_PCREL
;
9225 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
9226 if (reloc
->howto
== NULL
)
9228 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
9230 ("cannot represent %s relocation in this object file format"),
9231 bfd_get_reloc_code_name (code
));
9238 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
9241 cons_fix_new_aarch64 (fragS
* frag
, int where
, int size
, expressionS
* exp
)
9243 bfd_reloc_code_real_type type
;
9247 FIXME: @@ Should look at CPU word size. */
9254 type
= BFD_RELOC_16
;
9257 type
= BFD_RELOC_32
;
9260 type
= BFD_RELOC_64
;
9263 as_bad (_("cannot do %u-byte relocation"), size
);
9264 type
= BFD_RELOC_UNUSED
;
9268 fix_new_exp (frag
, where
, (int) size
, exp
, pcrel
, type
);
9273 /* Implement md_after_parse_args. This is the earliest time we need to decide
9274 ABI. If no -mabi specified, the ABI will be decided by target triplet. */
9277 aarch64_after_parse_args (void)
9279 if (aarch64_abi
!= AARCH64_ABI_NONE
)
9282 /* DEFAULT_ARCH will have ":32" extension if it's configured for ILP32. */
9283 if (strlen (default_arch
) > 7 && strcmp (default_arch
+ 7, ":32") == 0)
9284 aarch64_abi
= AARCH64_ABI_ILP32
;
9286 aarch64_abi
= AARCH64_ABI_LP64
;
9290 elf64_aarch64_target_format (void)
9293 /* FIXME: What to do for ilp32_p ? */
9294 if (target_big_endian
)
9295 return "elf64-bigaarch64-cloudabi";
9297 return "elf64-littleaarch64-cloudabi";
9299 if (target_big_endian
)
9300 return ilp32_p
? "elf32-bigaarch64" : "elf64-bigaarch64";
9302 return ilp32_p
? "elf32-littleaarch64" : "elf64-littleaarch64";
9307 aarch64elf_frob_symbol (symbolS
* symp
, int *puntp
)
9309 elf_frob_symbol (symp
, puntp
);
9313 /* MD interface: Finalization. */
9315 /* A good place to do this, although this was probably not intended
9316 for this kind of use. We need to dump the literal pool before
9317 references are made to a null symbol pointer. */
9320 aarch64_cleanup (void)
9324 for (pool
= list_of_pools
; pool
; pool
= pool
->next
)
9326 /* Put it at the end of the relevant section. */
9327 subseg_set (pool
->section
, pool
->sub_section
);
9333 /* Remove any excess mapping symbols generated for alignment frags in
9334 SEC. We may have created a mapping symbol before a zero byte
9335 alignment; remove it if there's a mapping symbol after the
9338 check_mapping_symbols (bfd
* abfd ATTRIBUTE_UNUSED
, asection
* sec
,
9339 void *dummy ATTRIBUTE_UNUSED
)
9341 segment_info_type
*seginfo
= seg_info (sec
);
9344 if (seginfo
== NULL
|| seginfo
->frchainP
== NULL
)
9347 for (fragp
= seginfo
->frchainP
->frch_root
;
9348 fragp
!= NULL
; fragp
= fragp
->fr_next
)
9350 symbolS
*sym
= fragp
->tc_frag_data
.last_map
;
9351 fragS
*next
= fragp
->fr_next
;
9353 /* Variable-sized frags have been converted to fixed size by
9354 this point. But if this was variable-sized to start with,
9355 there will be a fixed-size frag after it. So don't handle
9357 if (sym
== NULL
|| next
== NULL
)
9360 if (S_GET_VALUE (sym
) < next
->fr_address
)
9361 /* Not at the end of this frag. */
9363 know (S_GET_VALUE (sym
) == next
->fr_address
);
9367 if (next
->tc_frag_data
.first_map
!= NULL
)
9369 /* Next frag starts with a mapping symbol. Discard this
9371 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
9375 if (next
->fr_next
== NULL
)
9377 /* This mapping symbol is at the end of the section. Discard
9379 know (next
->fr_fix
== 0 && next
->fr_var
== 0);
9380 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
9384 /* As long as we have empty frags without any mapping symbols,
9386 /* If the next frag is non-empty and does not start with a
9387 mapping symbol, then this mapping symbol is required. */
9388 if (next
->fr_address
!= next
->fr_next
->fr_address
)
9391 next
= next
->fr_next
;
9393 while (next
!= NULL
);
9398 /* Adjust the symbol table. */
9401 aarch64_adjust_symtab (void)
9404 /* Remove any overlapping mapping symbols generated by alignment frags. */
9405 bfd_map_over_sections (stdoutput
, check_mapping_symbols
, (char *) 0);
9406 /* Now do generic ELF adjustments. */
9407 elf_adjust_symtab ();
9412 checked_hash_insert (htab_t table
, const char *key
, void *value
)
9414 str_hash_insert (table
, key
, value
, 0);
9418 sysreg_hash_insert (htab_t table
, const char *key
, void *value
)
9420 gas_assert (strlen (key
) < AARCH64_MAX_SYSREG_NAME_LEN
);
9421 checked_hash_insert (table
, key
, value
);
9425 fill_instruction_hash_table (void)
9427 const aarch64_opcode
*opcode
= aarch64_opcode_table
;
9429 while (opcode
->name
!= NULL
)
9431 templates
*templ
, *new_templ
;
9432 templ
= str_hash_find (aarch64_ops_hsh
, opcode
->name
);
9434 new_templ
= XNEW (templates
);
9435 new_templ
->opcode
= opcode
;
9436 new_templ
->next
= NULL
;
9439 checked_hash_insert (aarch64_ops_hsh
, opcode
->name
, (void *) new_templ
);
9442 new_templ
->next
= templ
->next
;
9443 templ
->next
= new_templ
;
9450 convert_to_upper (char *dst
, const char *src
, size_t num
)
9453 for (i
= 0; i
< num
&& *src
!= '\0'; ++i
, ++dst
, ++src
)
9454 *dst
= TOUPPER (*src
);
9458 /* Assume STR point to a lower-case string, allocate, convert and return
9459 the corresponding upper-case string. */
9460 static inline const char*
9461 get_upper_str (const char *str
)
9464 size_t len
= strlen (str
);
9465 ret
= XNEWVEC (char, len
+ 1);
9466 convert_to_upper (ret
, str
, len
);
9470 /* MD interface: Initialization. */
9478 aarch64_ops_hsh
= str_htab_create ();
9479 aarch64_cond_hsh
= str_htab_create ();
9480 aarch64_shift_hsh
= str_htab_create ();
9481 aarch64_sys_regs_hsh
= str_htab_create ();
9482 aarch64_pstatefield_hsh
= str_htab_create ();
9483 aarch64_sys_regs_ic_hsh
= str_htab_create ();
9484 aarch64_sys_regs_dc_hsh
= str_htab_create ();
9485 aarch64_sys_regs_at_hsh
= str_htab_create ();
9486 aarch64_sys_regs_tlbi_hsh
= str_htab_create ();
9487 aarch64_sys_regs_sr_hsh
= str_htab_create ();
9488 aarch64_reg_hsh
= str_htab_create ();
9489 aarch64_barrier_opt_hsh
= str_htab_create ();
9490 aarch64_nzcv_hsh
= str_htab_create ();
9491 aarch64_pldop_hsh
= str_htab_create ();
9492 aarch64_hint_opt_hsh
= str_htab_create ();
9494 fill_instruction_hash_table ();
9496 for (i
= 0; aarch64_sys_regs
[i
].name
!= NULL
; ++i
)
9497 sysreg_hash_insert (aarch64_sys_regs_hsh
, aarch64_sys_regs
[i
].name
,
9498 (void *) (aarch64_sys_regs
+ i
));
9500 for (i
= 0; aarch64_pstatefields
[i
].name
!= NULL
; ++i
)
9501 sysreg_hash_insert (aarch64_pstatefield_hsh
,
9502 aarch64_pstatefields
[i
].name
,
9503 (void *) (aarch64_pstatefields
+ i
));
9505 for (i
= 0; aarch64_sys_regs_ic
[i
].name
!= NULL
; i
++)
9506 sysreg_hash_insert (aarch64_sys_regs_ic_hsh
,
9507 aarch64_sys_regs_ic
[i
].name
,
9508 (void *) (aarch64_sys_regs_ic
+ i
));
9510 for (i
= 0; aarch64_sys_regs_dc
[i
].name
!= NULL
; i
++)
9511 sysreg_hash_insert (aarch64_sys_regs_dc_hsh
,
9512 aarch64_sys_regs_dc
[i
].name
,
9513 (void *) (aarch64_sys_regs_dc
+ i
));
9515 for (i
= 0; aarch64_sys_regs_at
[i
].name
!= NULL
; i
++)
9516 sysreg_hash_insert (aarch64_sys_regs_at_hsh
,
9517 aarch64_sys_regs_at
[i
].name
,
9518 (void *) (aarch64_sys_regs_at
+ i
));
9520 for (i
= 0; aarch64_sys_regs_tlbi
[i
].name
!= NULL
; i
++)
9521 sysreg_hash_insert (aarch64_sys_regs_tlbi_hsh
,
9522 aarch64_sys_regs_tlbi
[i
].name
,
9523 (void *) (aarch64_sys_regs_tlbi
+ i
));
9525 for (i
= 0; aarch64_sys_regs_sr
[i
].name
!= NULL
; i
++)
9526 sysreg_hash_insert (aarch64_sys_regs_sr_hsh
,
9527 aarch64_sys_regs_sr
[i
].name
,
9528 (void *) (aarch64_sys_regs_sr
+ i
));
9530 for (i
= 0; i
< ARRAY_SIZE (reg_names
); i
++)
9531 checked_hash_insert (aarch64_reg_hsh
, reg_names
[i
].name
,
9532 (void *) (reg_names
+ i
));
9534 for (i
= 0; i
< ARRAY_SIZE (nzcv_names
); i
++)
9535 checked_hash_insert (aarch64_nzcv_hsh
, nzcv_names
[i
].template,
9536 (void *) (nzcv_names
+ i
));
9538 for (i
= 0; aarch64_operand_modifiers
[i
].name
!= NULL
; i
++)
9540 const char *name
= aarch64_operand_modifiers
[i
].name
;
9541 checked_hash_insert (aarch64_shift_hsh
, name
,
9542 (void *) (aarch64_operand_modifiers
+ i
));
9543 /* Also hash the name in the upper case. */
9544 checked_hash_insert (aarch64_shift_hsh
, get_upper_str (name
),
9545 (void *) (aarch64_operand_modifiers
+ i
));
9548 for (i
= 0; i
< ARRAY_SIZE (aarch64_conds
); i
++)
9551 /* A condition code may have alias(es), e.g. "cc", "lo" and "ul" are
9552 the same condition code. */
9553 for (j
= 0; j
< ARRAY_SIZE (aarch64_conds
[i
].names
); ++j
)
9555 const char *name
= aarch64_conds
[i
].names
[j
];
9558 checked_hash_insert (aarch64_cond_hsh
, name
,
9559 (void *) (aarch64_conds
+ i
));
9560 /* Also hash the name in the upper case. */
9561 checked_hash_insert (aarch64_cond_hsh
, get_upper_str (name
),
9562 (void *) (aarch64_conds
+ i
));
9566 for (i
= 0; i
< ARRAY_SIZE (aarch64_barrier_options
); i
++)
9568 const char *name
= aarch64_barrier_options
[i
].name
;
9569 /* Skip xx00 - the unallocated values of option. */
9572 checked_hash_insert (aarch64_barrier_opt_hsh
, name
,
9573 (void *) (aarch64_barrier_options
+ i
));
9574 /* Also hash the name in the upper case. */
9575 checked_hash_insert (aarch64_barrier_opt_hsh
, get_upper_str (name
),
9576 (void *) (aarch64_barrier_options
+ i
));
9579 for (i
= 0; i
< ARRAY_SIZE (aarch64_barrier_dsb_nxs_options
); i
++)
9581 const char *name
= aarch64_barrier_dsb_nxs_options
[i
].name
;
9582 checked_hash_insert (aarch64_barrier_opt_hsh
, name
,
9583 (void *) (aarch64_barrier_dsb_nxs_options
+ i
));
9584 /* Also hash the name in the upper case. */
9585 checked_hash_insert (aarch64_barrier_opt_hsh
, get_upper_str (name
),
9586 (void *) (aarch64_barrier_dsb_nxs_options
+ i
));
9589 for (i
= 0; i
< ARRAY_SIZE (aarch64_prfops
); i
++)
9591 const char* name
= aarch64_prfops
[i
].name
;
9592 /* Skip the unallocated hint encodings. */
9595 checked_hash_insert (aarch64_pldop_hsh
, name
,
9596 (void *) (aarch64_prfops
+ i
));
9597 /* Also hash the name in the upper case. */
9598 checked_hash_insert (aarch64_pldop_hsh
, get_upper_str (name
),
9599 (void *) (aarch64_prfops
+ i
));
9602 for (i
= 0; aarch64_hint_options
[i
].name
!= NULL
; i
++)
9604 const char* name
= aarch64_hint_options
[i
].name
;
9605 const char* upper_name
= get_upper_str(name
);
9607 checked_hash_insert (aarch64_hint_opt_hsh
, name
,
9608 (void *) (aarch64_hint_options
+ i
));
9610 /* Also hash the name in the upper case if not the same. */
9611 if (strcmp (name
, upper_name
) != 0)
9612 checked_hash_insert (aarch64_hint_opt_hsh
, upper_name
,
9613 (void *) (aarch64_hint_options
+ i
));
9616 /* Set the cpu variant based on the command-line options. */
9618 mcpu_cpu_opt
= march_cpu_opt
;
9621 mcpu_cpu_opt
= &cpu_default
;
9623 cpu_variant
= *mcpu_cpu_opt
;
9625 /* Record the CPU type. */
9626 mach
= ilp32_p
? bfd_mach_aarch64_ilp32
: bfd_mach_aarch64
;
9628 bfd_set_arch_mach (stdoutput
, TARGET_ARCH
, mach
);
9631 /* Command line processing. */
9633 const char *md_shortopts
= "m:";
9635 #ifdef AARCH64_BI_ENDIAN
9636 #define OPTION_EB (OPTION_MD_BASE + 0)
9637 #define OPTION_EL (OPTION_MD_BASE + 1)
9639 #if TARGET_BYTES_BIG_ENDIAN
9640 #define OPTION_EB (OPTION_MD_BASE + 0)
9642 #define OPTION_EL (OPTION_MD_BASE + 1)
9646 struct option md_longopts
[] = {
9648 {"EB", no_argument
, NULL
, OPTION_EB
},
9651 {"EL", no_argument
, NULL
, OPTION_EL
},
9653 {NULL
, no_argument
, NULL
, 0}
9656 size_t md_longopts_size
= sizeof (md_longopts
);
9658 struct aarch64_option_table
9660 const char *option
; /* Option name to match. */
9661 const char *help
; /* Help information. */
9662 int *var
; /* Variable to change. */
9663 int value
; /* What to change it to. */
9664 char *deprecated
; /* If non-null, print this message. */
9667 static struct aarch64_option_table aarch64_opts
[] = {
9668 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian
, 1, NULL
},
9669 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian
, 0,
9671 #ifdef DEBUG_AARCH64
9672 {"mdebug-dump", N_("temporary switch for dumping"), &debug_dump
, 1, NULL
},
9673 #endif /* DEBUG_AARCH64 */
9674 {"mverbose-error", N_("output verbose error messages"), &verbose_error_p
, 1,
9676 {"mno-verbose-error", N_("do not output verbose error messages"),
9677 &verbose_error_p
, 0, NULL
},
9678 {NULL
, NULL
, NULL
, 0, NULL
}
9681 struct aarch64_cpu_option_table
9684 const aarch64_feature_set value
;
9685 /* The canonical name of the CPU, or NULL to use NAME converted to upper
9687 const char *canonical_name
;
9690 /* This list should, at a minimum, contain all the cpu names
9691 recognized by GCC. */
9692 static const struct aarch64_cpu_option_table aarch64_cpus
[] = {
9693 {"all", AARCH64_ANY
, NULL
},
9694 {"cortex-a34", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9695 AARCH64_FEATURE_CRC
), "Cortex-A34"},
9696 {"cortex-a35", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9697 AARCH64_FEATURE_CRC
), "Cortex-A35"},
9698 {"cortex-a53", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9699 AARCH64_FEATURE_CRC
), "Cortex-A53"},
9700 {"cortex-a57", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9701 AARCH64_FEATURE_CRC
), "Cortex-A57"},
9702 {"cortex-a72", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9703 AARCH64_FEATURE_CRC
), "Cortex-A72"},
9704 {"cortex-a73", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9705 AARCH64_FEATURE_CRC
), "Cortex-A73"},
9706 {"cortex-a55", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9707 AARCH64_FEATURE_RCPC
| AARCH64_FEATURE_F16
| AARCH64_FEATURE_DOTPROD
),
9709 {"cortex-a75", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9710 AARCH64_FEATURE_RCPC
| AARCH64_FEATURE_F16
| AARCH64_FEATURE_DOTPROD
),
9712 {"cortex-a76", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9713 AARCH64_FEATURE_RCPC
| AARCH64_FEATURE_F16
| AARCH64_FEATURE_DOTPROD
),
9715 {"cortex-a76ae", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9716 AARCH64_FEATURE_F16
| AARCH64_FEATURE_RCPC
9717 | AARCH64_FEATURE_DOTPROD
9718 | AARCH64_FEATURE_SSBS
),
9720 {"cortex-a77", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9721 AARCH64_FEATURE_F16
| AARCH64_FEATURE_RCPC
9722 | AARCH64_FEATURE_DOTPROD
9723 | AARCH64_FEATURE_SSBS
),
9725 {"cortex-a65", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9726 AARCH64_FEATURE_F16
| AARCH64_FEATURE_RCPC
9727 | AARCH64_FEATURE_DOTPROD
9728 | AARCH64_FEATURE_SSBS
),
9730 {"cortex-a65ae", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9731 AARCH64_FEATURE_F16
| AARCH64_FEATURE_RCPC
9732 | AARCH64_FEATURE_DOTPROD
9733 | AARCH64_FEATURE_SSBS
),
9735 {"cortex-a78", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9737 | AARCH64_FEATURE_RCPC
9738 | AARCH64_FEATURE_DOTPROD
9739 | AARCH64_FEATURE_SSBS
9740 | AARCH64_FEATURE_PROFILE
),
9742 {"cortex-a78ae", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9744 | AARCH64_FEATURE_RCPC
9745 | AARCH64_FEATURE_DOTPROD
9746 | AARCH64_FEATURE_SSBS
9747 | AARCH64_FEATURE_PROFILE
),
9749 {"cortex-a78c", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9750 AARCH64_FEATURE_DOTPROD
9751 | AARCH64_FEATURE_F16
9752 | AARCH64_FEATURE_FLAGM
9753 | AARCH64_FEATURE_PAC
9754 | AARCH64_FEATURE_PROFILE
9755 | AARCH64_FEATURE_RCPC
9756 | AARCH64_FEATURE_SSBS
),
9758 {"cortex-a510", AARCH64_FEATURE (AARCH64_ARCH_V9
,
9759 AARCH64_FEATURE_BFLOAT16
9760 | AARCH64_FEATURE_I8MM
9761 | AARCH64_FEATURE_MEMTAG
9762 | AARCH64_FEATURE_SVE2_BITPERM
),
9764 {"cortex-a710", AARCH64_FEATURE (AARCH64_ARCH_V9
,
9765 AARCH64_FEATURE_BFLOAT16
9766 | AARCH64_FEATURE_I8MM
9767 | AARCH64_FEATURE_MEMTAG
9768 | AARCH64_FEATURE_SVE2_BITPERM
),
9770 {"ares", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9771 AARCH64_FEATURE_RCPC
| AARCH64_FEATURE_F16
9772 | AARCH64_FEATURE_DOTPROD
9773 | AARCH64_FEATURE_PROFILE
),
9775 {"exynos-m1", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9776 AARCH64_FEATURE_CRC
| AARCH64_FEATURE_CRYPTO
),
9777 "Samsung Exynos M1"},
9778 {"falkor", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9779 AARCH64_FEATURE_CRC
| AARCH64_FEATURE_CRYPTO
9780 | AARCH64_FEATURE_RDMA
),
9782 {"neoverse-e1", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9783 AARCH64_FEATURE_RCPC
| AARCH64_FEATURE_F16
9784 | AARCH64_FEATURE_DOTPROD
9785 | AARCH64_FEATURE_SSBS
),
9787 {"neoverse-n1", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9788 AARCH64_FEATURE_RCPC
| AARCH64_FEATURE_F16
9789 | AARCH64_FEATURE_DOTPROD
9790 | AARCH64_FEATURE_PROFILE
),
9792 {"neoverse-n2", AARCH64_FEATURE (AARCH64_ARCH_V8_5
,
9793 AARCH64_FEATURE_BFLOAT16
9794 | AARCH64_FEATURE_I8MM
9795 | AARCH64_FEATURE_F16
9796 | AARCH64_FEATURE_SVE
9797 | AARCH64_FEATURE_SVE2
9798 | AARCH64_FEATURE_SVE2_BITPERM
9799 | AARCH64_FEATURE_MEMTAG
9800 | AARCH64_FEATURE_RNG
),
9802 {"neoverse-v1", AARCH64_FEATURE (AARCH64_ARCH_V8_4
,
9803 AARCH64_FEATURE_PROFILE
9804 | AARCH64_FEATURE_CVADP
9805 | AARCH64_FEATURE_SVE
9806 | AARCH64_FEATURE_SSBS
9807 | AARCH64_FEATURE_RNG
9808 | AARCH64_FEATURE_F16
9809 | AARCH64_FEATURE_BFLOAT16
9810 | AARCH64_FEATURE_I8MM
), "Neoverse V1"},
9811 {"qdf24xx", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9812 AARCH64_FEATURE_CRC
| AARCH64_FEATURE_CRYPTO
9813 | AARCH64_FEATURE_RDMA
),
9814 "Qualcomm QDF24XX"},
9815 {"saphira", AARCH64_FEATURE (AARCH64_ARCH_V8_4
,
9816 AARCH64_FEATURE_CRYPTO
| AARCH64_FEATURE_PROFILE
),
9817 "Qualcomm Saphira"},
9818 {"thunderx", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9819 AARCH64_FEATURE_CRC
| AARCH64_FEATURE_CRYPTO
),
9821 {"vulcan", AARCH64_FEATURE (AARCH64_ARCH_V8_1
,
9822 AARCH64_FEATURE_CRYPTO
),
9824 /* The 'xgene-1' name is an older name for 'xgene1', which was used
9825 in earlier releases and is superseded by 'xgene1' in all
9827 {"xgene-1", AARCH64_ARCH_V8
, "APM X-Gene 1"},
9828 {"xgene1", AARCH64_ARCH_V8
, "APM X-Gene 1"},
9829 {"xgene2", AARCH64_FEATURE (AARCH64_ARCH_V8
,
9830 AARCH64_FEATURE_CRC
), "APM X-Gene 2"},
9831 {"cortex-r82", AARCH64_ARCH_V8_R
, "Cortex-R82"},
9832 {"cortex-x1", AARCH64_FEATURE (AARCH64_ARCH_V8_2
,
9834 | AARCH64_FEATURE_RCPC
9835 | AARCH64_FEATURE_DOTPROD
9836 | AARCH64_FEATURE_SSBS
9837 | AARCH64_FEATURE_PROFILE
),
9839 {"cortex-x2", AARCH64_FEATURE (AARCH64_ARCH_V9
,
9840 AARCH64_FEATURE_BFLOAT16
9841 | AARCH64_FEATURE_I8MM
9842 | AARCH64_FEATURE_MEMTAG
9843 | AARCH64_FEATURE_SVE2_BITPERM
),
9845 {"generic", AARCH64_ARCH_V8
, NULL
},
9847 {NULL
, AARCH64_ARCH_NONE
, NULL
}
9850 struct aarch64_arch_option_table
9853 const aarch64_feature_set value
;
9856 /* This list should, at a minimum, contain all the architecture names
9857 recognized by GCC. */
9858 static const struct aarch64_arch_option_table aarch64_archs
[] = {
9859 {"all", AARCH64_ANY
},
9860 {"armv8-a", AARCH64_ARCH_V8
},
9861 {"armv8.1-a", AARCH64_ARCH_V8_1
},
9862 {"armv8.2-a", AARCH64_ARCH_V8_2
},
9863 {"armv8.3-a", AARCH64_ARCH_V8_3
},
9864 {"armv8.4-a", AARCH64_ARCH_V8_4
},
9865 {"armv8.5-a", AARCH64_ARCH_V8_5
},
9866 {"armv8.6-a", AARCH64_ARCH_V8_6
},
9867 {"armv8.7-a", AARCH64_ARCH_V8_7
},
9868 {"armv8.8-a", AARCH64_ARCH_V8_8
},
9869 {"armv8-r", AARCH64_ARCH_V8_R
},
9870 {"armv9-a", AARCH64_ARCH_V9
},
9871 {"armv9.1-a", AARCH64_ARCH_V9_1
},
9872 {"armv9.2-a", AARCH64_ARCH_V9_2
},
9873 {"armv9.3-a", AARCH64_ARCH_V9_3
},
9874 {NULL
, AARCH64_ARCH_NONE
}
9877 /* ISA extensions. */
9878 struct aarch64_option_cpu_value_table
9881 const aarch64_feature_set value
;
9882 const aarch64_feature_set require
; /* Feature dependencies. */
9885 static const struct aarch64_option_cpu_value_table aarch64_features
[] = {
9886 {"crc", AARCH64_FEATURE (AARCH64_FEATURE_CRC
, 0),
9888 {"crypto", AARCH64_FEATURE (AARCH64_FEATURE_CRYPTO
, 0),
9889 AARCH64_FEATURE (AARCH64_FEATURE_SIMD
, 0)},
9890 {"fp", AARCH64_FEATURE (AARCH64_FEATURE_FP
, 0),
9892 {"lse", AARCH64_FEATURE (AARCH64_FEATURE_LSE
, 0),
9894 {"simd", AARCH64_FEATURE (AARCH64_FEATURE_SIMD
, 0),
9895 AARCH64_FEATURE (AARCH64_FEATURE_FP
, 0)},
9896 {"pan", AARCH64_FEATURE (AARCH64_FEATURE_PAN
, 0),
9898 {"lor", AARCH64_FEATURE (AARCH64_FEATURE_LOR
, 0),
9900 {"ras", AARCH64_FEATURE (AARCH64_FEATURE_RAS
, 0),
9902 {"rdma", AARCH64_FEATURE (AARCH64_FEATURE_RDMA
, 0),
9903 AARCH64_FEATURE (AARCH64_FEATURE_SIMD
, 0)},
9904 {"fp16", AARCH64_FEATURE (AARCH64_FEATURE_F16
, 0),
9905 AARCH64_FEATURE (AARCH64_FEATURE_FP
, 0)},
9906 {"fp16fml", AARCH64_FEATURE (AARCH64_FEATURE_F16_FML
, 0),
9907 AARCH64_FEATURE (AARCH64_FEATURE_FP
9908 | AARCH64_FEATURE_F16
, 0)},
9909 {"profile", AARCH64_FEATURE (AARCH64_FEATURE_PROFILE
, 0),
9911 {"sve", AARCH64_FEATURE (AARCH64_FEATURE_SVE
, 0),
9912 AARCH64_FEATURE (AARCH64_FEATURE_F16
9913 | AARCH64_FEATURE_SIMD
9914 | AARCH64_FEATURE_COMPNUM
, 0)},
9915 {"tme", AARCH64_FEATURE (AARCH64_FEATURE_TME
, 0),
9917 {"compnum", AARCH64_FEATURE (AARCH64_FEATURE_COMPNUM
, 0),
9918 AARCH64_FEATURE (AARCH64_FEATURE_F16
9919 | AARCH64_FEATURE_SIMD
, 0)},
9920 {"rcpc", AARCH64_FEATURE (AARCH64_FEATURE_RCPC
, 0),
9922 {"dotprod", AARCH64_FEATURE (AARCH64_FEATURE_DOTPROD
, 0),
9924 {"sha2", AARCH64_FEATURE (AARCH64_FEATURE_SHA2
, 0),
9926 {"sb", AARCH64_FEATURE (AARCH64_FEATURE_SB
, 0),
9928 {"predres", AARCH64_FEATURE (AARCH64_FEATURE_PREDRES
, 0),
9930 {"aes", AARCH64_FEATURE (AARCH64_FEATURE_AES
, 0),
9932 {"sm4", AARCH64_FEATURE (AARCH64_FEATURE_SM4
, 0),
9934 {"sha3", AARCH64_FEATURE (AARCH64_FEATURE_SHA3
, 0),
9935 AARCH64_FEATURE (AARCH64_FEATURE_SHA2
, 0)},
9936 {"rng", AARCH64_FEATURE (AARCH64_FEATURE_RNG
, 0),
9938 {"ssbs", AARCH64_FEATURE (AARCH64_FEATURE_SSBS
, 0),
9940 {"memtag", AARCH64_FEATURE (AARCH64_FEATURE_MEMTAG
, 0),
9942 {"sve2", AARCH64_FEATURE (AARCH64_FEATURE_SVE2
, 0),
9943 AARCH64_FEATURE (AARCH64_FEATURE_SVE
, 0)},
9944 {"sve2-sm4", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_SM4
, 0),
9945 AARCH64_FEATURE (AARCH64_FEATURE_SVE2
9946 | AARCH64_FEATURE_SM4
, 0)},
9947 {"sve2-aes", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_AES
, 0),
9948 AARCH64_FEATURE (AARCH64_FEATURE_SVE2
9949 | AARCH64_FEATURE_AES
, 0)},
9950 {"sve2-sha3", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_SHA3
, 0),
9951 AARCH64_FEATURE (AARCH64_FEATURE_SVE2
9952 | AARCH64_FEATURE_SHA3
, 0)},
9953 {"sve2-bitperm", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_BITPERM
, 0),
9954 AARCH64_FEATURE (AARCH64_FEATURE_SVE2
, 0)},
9955 {"sme", AARCH64_FEATURE (AARCH64_FEATURE_SME
, 0),
9956 AARCH64_FEATURE (AARCH64_FEATURE_SVE2
9957 | AARCH64_FEATURE_BFLOAT16
, 0)},
9958 {"sme-f64", AARCH64_FEATURE (AARCH64_FEATURE_SME_F64
, 0),
9959 AARCH64_FEATURE (AARCH64_FEATURE_SME
9960 | AARCH64_FEATURE_SVE2
9961 | AARCH64_FEATURE_BFLOAT16
, 0)},
9962 {"sme-i64", AARCH64_FEATURE (AARCH64_FEATURE_SME_I64
, 0),
9963 AARCH64_FEATURE (AARCH64_FEATURE_SME
9964 | AARCH64_FEATURE_SVE2
9965 | AARCH64_FEATURE_BFLOAT16
, 0)},
9966 {"bf16", AARCH64_FEATURE (AARCH64_FEATURE_BFLOAT16
, 0),
9968 {"i8mm", AARCH64_FEATURE (AARCH64_FEATURE_I8MM
, 0),
9970 {"f32mm", AARCH64_FEATURE (AARCH64_FEATURE_F32MM
, 0),
9971 AARCH64_FEATURE (AARCH64_FEATURE_SVE
, 0)},
9972 {"f64mm", AARCH64_FEATURE (AARCH64_FEATURE_F64MM
, 0),
9973 AARCH64_FEATURE (AARCH64_FEATURE_SVE
, 0)},
9974 {"ls64", AARCH64_FEATURE (AARCH64_FEATURE_LS64
, 0),
9976 {"flagm", AARCH64_FEATURE (AARCH64_FEATURE_FLAGM
, 0),
9978 {"pauth", AARCH64_FEATURE (AARCH64_FEATURE_PAC
, 0),
9980 {"mops", AARCH64_FEATURE (AARCH64_FEATURE_MOPS
, 0),
9982 {"hbc", AARCH64_FEATURE (AARCH64_FEATURE_HBC
, 0),
9984 {NULL
, AARCH64_ARCH_NONE
, AARCH64_ARCH_NONE
},
9987 struct aarch64_long_option_table
9989 const char *option
; /* Substring to match. */
9990 const char *help
; /* Help information. */
9991 int (*func
) (const char *subopt
); /* Function to decode sub-option. */
9992 char *deprecated
; /* If non-null, print this message. */
9995 /* Transitive closure of features depending on set. */
9996 static aarch64_feature_set
9997 aarch64_feature_disable_set (aarch64_feature_set set
)
9999 const struct aarch64_option_cpu_value_table
*opt
;
10000 aarch64_feature_set prev
= 0;
10002 while (prev
!= set
) {
10004 for (opt
= aarch64_features
; opt
->name
!= NULL
; opt
++)
10005 if (AARCH64_CPU_HAS_ANY_FEATURES (opt
->require
, set
))
10006 AARCH64_MERGE_FEATURE_SETS (set
, set
, opt
->value
);
10011 /* Transitive closure of dependencies of set. */
10012 static aarch64_feature_set
10013 aarch64_feature_enable_set (aarch64_feature_set set
)
10015 const struct aarch64_option_cpu_value_table
*opt
;
10016 aarch64_feature_set prev
= 0;
10018 while (prev
!= set
) {
10020 for (opt
= aarch64_features
; opt
->name
!= NULL
; opt
++)
10021 if (AARCH64_CPU_HAS_FEATURE (set
, opt
->value
))
10022 AARCH64_MERGE_FEATURE_SETS (set
, set
, opt
->require
);
10028 aarch64_parse_features (const char *str
, const aarch64_feature_set
**opt_p
,
10031 /* We insist on extensions being added before being removed. We achieve
10032 this by using the ADDING_VALUE variable to indicate whether we are
10033 adding an extension (1) or removing it (0) and only allowing it to
10034 change in the order -1 -> 1 -> 0. */
10035 int adding_value
= -1;
10036 aarch64_feature_set
*ext_set
= XNEW (aarch64_feature_set
);
10038 /* Copy the feature set, so that we can modify it. */
10039 *ext_set
= **opt_p
;
10042 while (str
!= NULL
&& *str
!= 0)
10044 const struct aarch64_option_cpu_value_table
*opt
;
10045 const char *ext
= NULL
;
10052 as_bad (_("invalid architectural extension"));
10056 ext
= strchr (++str
, '+');
10060 optlen
= ext
- str
;
10062 optlen
= strlen (str
);
10064 if (optlen
>= 2 && startswith (str
, "no"))
10066 if (adding_value
!= 0)
10071 else if (optlen
> 0)
10073 if (adding_value
== -1)
10075 else if (adding_value
!= 1)
10077 as_bad (_("must specify extensions to add before specifying "
10078 "those to remove"));
10085 as_bad (_("missing architectural extension"));
10089 gas_assert (adding_value
!= -1);
10091 for (opt
= aarch64_features
; opt
->name
!= NULL
; opt
++)
10092 if (strncmp (opt
->name
, str
, optlen
) == 0)
10094 aarch64_feature_set set
;
10096 /* Add or remove the extension. */
10099 set
= aarch64_feature_enable_set (opt
->value
);
10100 AARCH64_MERGE_FEATURE_SETS (*ext_set
, *ext_set
, set
);
10104 set
= aarch64_feature_disable_set (opt
->value
);
10105 AARCH64_CLEAR_FEATURE (*ext_set
, *ext_set
, set
);
10110 if (opt
->name
== NULL
)
10112 as_bad (_("unknown architectural extension `%s'"), str
);
10123 aarch64_parse_cpu (const char *str
)
10125 const struct aarch64_cpu_option_table
*opt
;
10126 const char *ext
= strchr (str
, '+');
10130 optlen
= ext
- str
;
10132 optlen
= strlen (str
);
10136 as_bad (_("missing cpu name `%s'"), str
);
10140 for (opt
= aarch64_cpus
; opt
->name
!= NULL
; opt
++)
10141 if (strlen (opt
->name
) == optlen
&& strncmp (str
, opt
->name
, optlen
) == 0)
10143 mcpu_cpu_opt
= &opt
->value
;
10145 return aarch64_parse_features (ext
, &mcpu_cpu_opt
, false);
10150 as_bad (_("unknown cpu `%s'"), str
);
10155 aarch64_parse_arch (const char *str
)
10157 const struct aarch64_arch_option_table
*opt
;
10158 const char *ext
= strchr (str
, '+');
10162 optlen
= ext
- str
;
10164 optlen
= strlen (str
);
10168 as_bad (_("missing architecture name `%s'"), str
);
10172 for (opt
= aarch64_archs
; opt
->name
!= NULL
; opt
++)
10173 if (strlen (opt
->name
) == optlen
&& strncmp (str
, opt
->name
, optlen
) == 0)
10175 march_cpu_opt
= &opt
->value
;
10177 return aarch64_parse_features (ext
, &march_cpu_opt
, false);
10182 as_bad (_("unknown architecture `%s'\n"), str
);
10187 struct aarch64_option_abi_value_table
10190 enum aarch64_abi_type value
;
10193 static const struct aarch64_option_abi_value_table aarch64_abis
[] = {
10194 {"ilp32", AARCH64_ABI_ILP32
},
10195 {"lp64", AARCH64_ABI_LP64
},
10199 aarch64_parse_abi (const char *str
)
10203 if (str
[0] == '\0')
10205 as_bad (_("missing abi name `%s'"), str
);
10209 for (i
= 0; i
< ARRAY_SIZE (aarch64_abis
); i
++)
10210 if (strcmp (str
, aarch64_abis
[i
].name
) == 0)
10212 aarch64_abi
= aarch64_abis
[i
].value
;
10216 as_bad (_("unknown abi `%s'\n"), str
);
10220 static struct aarch64_long_option_table aarch64_long_opts
[] = {
10222 {"mabi=", N_("<abi name>\t specify for ABI <abi name>"),
10223 aarch64_parse_abi
, NULL
},
10224 #endif /* OBJ_ELF */
10225 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
10226 aarch64_parse_cpu
, NULL
},
10227 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
10228 aarch64_parse_arch
, NULL
},
10229 {NULL
, NULL
, 0, NULL
}
10233 md_parse_option (int c
, const char *arg
)
10235 struct aarch64_option_table
*opt
;
10236 struct aarch64_long_option_table
*lopt
;
10242 target_big_endian
= 1;
10248 target_big_endian
= 0;
10253 /* Listing option. Just ignore these, we don't support additional
10258 for (opt
= aarch64_opts
; opt
->option
!= NULL
; opt
++)
10260 if (c
== opt
->option
[0]
10261 && ((arg
== NULL
&& opt
->option
[1] == 0)
10262 || streq (arg
, opt
->option
+ 1)))
10264 /* If the option is deprecated, tell the user. */
10265 if (opt
->deprecated
!= NULL
)
10266 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c
,
10267 arg
? arg
: "", _(opt
->deprecated
));
10269 if (opt
->var
!= NULL
)
10270 *opt
->var
= opt
->value
;
10276 for (lopt
= aarch64_long_opts
; lopt
->option
!= NULL
; lopt
++)
10278 /* These options are expected to have an argument. */
10279 if (c
== lopt
->option
[0]
10281 && startswith (arg
, lopt
->option
+ 1))
10283 /* If the option is deprecated, tell the user. */
10284 if (lopt
->deprecated
!= NULL
)
10285 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c
, arg
,
10286 _(lopt
->deprecated
));
10288 /* Call the sup-option parser. */
10289 return lopt
->func (arg
+ strlen (lopt
->option
) - 1);
10300 md_show_usage (FILE * fp
)
10302 struct aarch64_option_table
*opt
;
10303 struct aarch64_long_option_table
*lopt
;
10305 fprintf (fp
, _(" AArch64-specific assembler options:\n"));
10307 for (opt
= aarch64_opts
; opt
->option
!= NULL
; opt
++)
10308 if (opt
->help
!= NULL
)
10309 fprintf (fp
, " -%-23s%s\n", opt
->option
, _(opt
->help
));
10311 for (lopt
= aarch64_long_opts
; lopt
->option
!= NULL
; lopt
++)
10312 if (lopt
->help
!= NULL
)
10313 fprintf (fp
, " -%s%s\n", lopt
->option
, _(lopt
->help
));
10317 -EB assemble code for a big-endian cpu\n"));
10322 -EL assemble code for a little-endian cpu\n"));
10326 /* Parse a .cpu directive. */
10329 s_aarch64_cpu (int ignored ATTRIBUTE_UNUSED
)
10331 const struct aarch64_cpu_option_table
*opt
;
10337 name
= input_line_pointer
;
10338 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
10339 input_line_pointer
++;
10340 saved_char
= *input_line_pointer
;
10341 *input_line_pointer
= 0;
10343 ext
= strchr (name
, '+');
10346 optlen
= ext
- name
;
10348 optlen
= strlen (name
);
10350 /* Skip the first "all" entry. */
10351 for (opt
= aarch64_cpus
+ 1; opt
->name
!= NULL
; opt
++)
10352 if (strlen (opt
->name
) == optlen
10353 && strncmp (name
, opt
->name
, optlen
) == 0)
10355 mcpu_cpu_opt
= &opt
->value
;
10357 if (!aarch64_parse_features (ext
, &mcpu_cpu_opt
, false))
10360 cpu_variant
= *mcpu_cpu_opt
;
10362 *input_line_pointer
= saved_char
;
10363 demand_empty_rest_of_line ();
10366 as_bad (_("unknown cpu `%s'"), name
);
10367 *input_line_pointer
= saved_char
;
10368 ignore_rest_of_line ();
10372 /* Parse a .arch directive. */
10375 s_aarch64_arch (int ignored ATTRIBUTE_UNUSED
)
10377 const struct aarch64_arch_option_table
*opt
;
10383 name
= input_line_pointer
;
10384 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
10385 input_line_pointer
++;
10386 saved_char
= *input_line_pointer
;
10387 *input_line_pointer
= 0;
10389 ext
= strchr (name
, '+');
10392 optlen
= ext
- name
;
10394 optlen
= strlen (name
);
10396 /* Skip the first "all" entry. */
10397 for (opt
= aarch64_archs
+ 1; opt
->name
!= NULL
; opt
++)
10398 if (strlen (opt
->name
) == optlen
10399 && strncmp (name
, opt
->name
, optlen
) == 0)
10401 mcpu_cpu_opt
= &opt
->value
;
10403 if (!aarch64_parse_features (ext
, &mcpu_cpu_opt
, false))
10406 cpu_variant
= *mcpu_cpu_opt
;
10408 *input_line_pointer
= saved_char
;
10409 demand_empty_rest_of_line ();
10413 as_bad (_("unknown architecture `%s'\n"), name
);
10414 *input_line_pointer
= saved_char
;
10415 ignore_rest_of_line ();
10418 /* Parse a .arch_extension directive. */
10421 s_aarch64_arch_extension (int ignored ATTRIBUTE_UNUSED
)
10424 char *ext
= input_line_pointer
;;
10426 while (*input_line_pointer
&& !ISSPACE (*input_line_pointer
))
10427 input_line_pointer
++;
10428 saved_char
= *input_line_pointer
;
10429 *input_line_pointer
= 0;
10431 if (!aarch64_parse_features (ext
, &mcpu_cpu_opt
, true))
10434 cpu_variant
= *mcpu_cpu_opt
;
10436 *input_line_pointer
= saved_char
;
10437 demand_empty_rest_of_line ();
10440 /* Copy symbol information. */
10443 aarch64_copy_symbol_attributes (symbolS
* dest
, symbolS
* src
)
10445 AARCH64_GET_FLAG (dest
) = AARCH64_GET_FLAG (src
);
10449 /* Same as elf_copy_symbol_attributes, but without copying st_other.
10450 This is needed so AArch64 specific st_other values can be independently
10451 specified for an IFUNC resolver (that is called by the dynamic linker)
10452 and the symbol it resolves (aliased to the resolver). In particular,
10453 if a function symbol has special st_other value set via directives,
10454 then attaching an IFUNC resolver to that symbol should not override
10455 the st_other setting. Requiring the directive on the IFUNC resolver
10456 symbol would be unexpected and problematic in C code, where the two
10457 symbols appear as two independent function declarations. */
10460 aarch64_elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
10462 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
10463 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
10464 /* If size is unset, copy size from src. Because we don't track whether
10465 .size has been used, we can't differentiate .size dest, 0 from the case
10466 where dest's size is unset. */
10467 if (!destelf
->size
&& S_GET_SIZE (dest
) == 0)
10471 destelf
->size
= XNEW (expressionS
);
10472 *destelf
->size
= *srcelf
->size
;
10474 S_SET_SIZE (dest
, S_GET_SIZE (src
));