]>
Commit | Line | Data |
---|---|---|
a06ea964 NC |
1 | /* tc-aarch64.c -- Assemble for the AArch64 ISA |
2 | ||
b3adc24a | 3 | Copyright (C) 2009-2020 Free Software Foundation, Inc. |
a06ea964 NC |
4 | Contributed by ARM Ltd. |
5 | ||
6 | This file is part of GAS. | |
7 | ||
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. | |
12 | ||
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. | |
17 | ||
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/>. */ | |
21 | ||
22 | #include "as.h" | |
23 | #include <limits.h> | |
24 | #include <stdarg.h> | |
25 | #include "bfd_stdint.h" | |
26 | #define NO_RELOC 0 | |
27 | #include "safe-ctype.h" | |
28 | #include "subsegs.h" | |
29 | #include "obstack.h" | |
8b21361b | 30 | #include "cpu-aarch64.h" |
a06ea964 NC |
31 | |
32 | #ifdef OBJ_ELF | |
33 | #include "elf/aarch64.h" | |
34 | #include "dw2gencfi.h" | |
35 | #endif | |
36 | ||
37 | #include "dwarf2dbg.h" | |
38 | ||
39 | /* Types of processor to assemble for. */ | |
40 | #ifndef CPU_DEFAULT | |
41 | #define CPU_DEFAULT AARCH64_ARCH_V8 | |
42 | #endif | |
43 | ||
44 | #define streq(a, b) (strcmp (a, b) == 0) | |
45 | ||
f4c51f60 JW |
46 | #define END_OF_INSN '\0' |
47 | ||
3979cf50 SP |
48 | #define MAP_CUR_INSN (AARCH64_CPU_HAS_FEATURE (cpu_variant, \ |
49 | AARCH64_FEATURE_C64) \ | |
50 | ? MAP_C64 : MAP_INSN) | |
51 | ||
8b21361b SP |
52 | #define IS_C64 (AARCH64_CPU_HAS_FEATURE (cpu_variant, AARCH64_FEATURE_C64) \ |
53 | ? 1 : 0) | |
54 | ||
a06ea964 NC |
55 | static aarch64_feature_set cpu_variant; |
56 | ||
57 | /* Variables that we set while parsing command-line options. Once all | |
58 | options have been read we re-process these values to set the real | |
59 | assembly flags. */ | |
60 | static const aarch64_feature_set *mcpu_cpu_opt = NULL; | |
61 | static const aarch64_feature_set *march_cpu_opt = NULL; | |
62 | ||
63 | /* Constants for known architecture features. */ | |
64 | static const aarch64_feature_set cpu_default = CPU_DEFAULT; | |
65 | ||
7e84b55d TC |
66 | /* Currently active instruction sequence. */ |
67 | static aarch64_instr_sequence *insn_sequence = NULL; | |
68 | ||
a06ea964 NC |
69 | #ifdef OBJ_ELF |
70 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ | |
71 | static symbolS *GOT_symbol; | |
cec5225b | 72 | |
69091a2c YZ |
73 | /* Which ABI to use. */ |
74 | enum aarch64_abi_type | |
75 | { | |
3c0367d0 JW |
76 | AARCH64_ABI_NONE = 0, |
77 | AARCH64_ABI_LP64 = 1, | |
78 | AARCH64_ABI_ILP32 = 2 | |
69091a2c YZ |
79 | }; |
80 | ||
3c0367d0 JW |
81 | #ifndef DEFAULT_ARCH |
82 | #define DEFAULT_ARCH "aarch64" | |
83 | #endif | |
84 | ||
85 | /* DEFAULT_ARCH is initialized in gas/configure.tgt. */ | |
86 | static const char *default_arch = DEFAULT_ARCH; | |
87 | ||
69091a2c | 88 | /* AArch64 ABI for the output file. */ |
3c0367d0 | 89 | static enum aarch64_abi_type aarch64_abi = AARCH64_ABI_NONE; |
69091a2c | 90 | |
cec5225b YZ |
91 | /* When non-zero, program to a 32-bit model, in which the C data types |
92 | int, long and all pointer types are 32-bit objects (ILP32); or to a | |
93 | 64-bit model, in which the C int type is 32-bits but the C long type | |
94 | and all pointer types are 64-bit objects (LP64). */ | |
69091a2c | 95 | #define ilp32_p (aarch64_abi == AARCH64_ABI_ILP32) |
a06ea964 NC |
96 | #endif |
97 | ||
f06935a5 | 98 | enum vector_el_type |
a06ea964 NC |
99 | { |
100 | NT_invtype = -1, | |
101 | NT_b, | |
102 | NT_h, | |
103 | NT_s, | |
104 | NT_d, | |
d50c751e RS |
105 | NT_q, |
106 | NT_zero, | |
107 | NT_merge | |
a06ea964 NC |
108 | }; |
109 | ||
8f9a77af | 110 | /* Bits for DEFINED field in vector_type_el. */ |
f11ad6bc RS |
111 | #define NTA_HASTYPE 1 |
112 | #define NTA_HASINDEX 2 | |
113 | #define NTA_HASVARWIDTH 4 | |
a06ea964 | 114 | |
8f9a77af | 115 | struct vector_type_el |
a06ea964 | 116 | { |
f06935a5 | 117 | enum vector_el_type type; |
a06ea964 NC |
118 | unsigned char defined; |
119 | unsigned width; | |
120 | int64_t index; | |
121 | }; | |
122 | ||
123 | #define FIXUP_F_HAS_EXPLICIT_SHIFT 0x00000001 | |
f0070c1e | 124 | #define FIXUP_F_C64 0x00000002 |
a06ea964 NC |
125 | |
126 | struct reloc | |
127 | { | |
128 | bfd_reloc_code_real_type type; | |
129 | expressionS exp; | |
130 | int pc_rel; | |
131 | enum aarch64_opnd opnd; | |
132 | uint32_t flags; | |
133 | unsigned need_libopcodes_p : 1; | |
134 | }; | |
135 | ||
136 | struct aarch64_instruction | |
137 | { | |
138 | /* libopcodes structure for instruction intermediate representation. */ | |
139 | aarch64_inst base; | |
140 | /* Record assembly errors found during the parsing. */ | |
141 | struct | |
142 | { | |
143 | enum aarch64_operand_error_kind kind; | |
144 | const char *error; | |
145 | } parsing_error; | |
146 | /* The condition that appears in the assembly line. */ | |
147 | int cond; | |
148 | /* Relocation information (including the GAS internal fixup). */ | |
149 | struct reloc reloc; | |
150 | /* Need to generate an immediate in the literal pool. */ | |
151 | unsigned gen_lit_pool : 1; | |
152 | }; | |
153 | ||
154 | typedef struct aarch64_instruction aarch64_instruction; | |
155 | ||
156 | static aarch64_instruction inst; | |
157 | ||
158 | static bfd_boolean parse_operands (char *, const aarch64_opcode *); | |
159 | static bfd_boolean programmer_friendly_fixup (aarch64_instruction *); | |
160 | ||
7e84b55d TC |
161 | #ifdef OBJ_ELF |
162 | # define now_instr_sequence seg_info \ | |
163 | (now_seg)->tc_segment_info_data.insn_sequence | |
164 | #else | |
165 | static struct aarch64_instr_sequence now_instr_sequence; | |
166 | #endif | |
167 | ||
33eaf5de | 168 | /* Diagnostics inline function utilities. |
a06ea964 | 169 | |
33eaf5de | 170 | These are lightweight utilities which should only be called by parse_operands |
a06ea964 NC |
171 | and other parsers. GAS processes each assembly line by parsing it against |
172 | instruction template(s), in the case of multiple templates (for the same | |
173 | mnemonic name), those templates are tried one by one until one succeeds or | |
174 | all fail. An assembly line may fail a few templates before being | |
175 | successfully parsed; an error saved here in most cases is not a user error | |
176 | but an error indicating the current template is not the right template. | |
177 | Therefore it is very important that errors can be saved at a low cost during | |
178 | the parsing; we don't want to slow down the whole parsing by recording | |
179 | non-user errors in detail. | |
180 | ||
33eaf5de | 181 | Remember that the objective is to help GAS pick up the most appropriate |
a06ea964 NC |
182 | error message in the case of multiple templates, e.g. FMOV which has 8 |
183 | templates. */ | |
184 | ||
185 | static inline void | |
186 | clear_error (void) | |
187 | { | |
188 | inst.parsing_error.kind = AARCH64_OPDE_NIL; | |
189 | inst.parsing_error.error = NULL; | |
190 | } | |
191 | ||
192 | static inline bfd_boolean | |
193 | error_p (void) | |
194 | { | |
195 | return inst.parsing_error.kind != AARCH64_OPDE_NIL; | |
196 | } | |
197 | ||
198 | static inline const char * | |
199 | get_error_message (void) | |
200 | { | |
201 | return inst.parsing_error.error; | |
202 | } | |
203 | ||
a06ea964 NC |
204 | static inline enum aarch64_operand_error_kind |
205 | get_error_kind (void) | |
206 | { | |
207 | return inst.parsing_error.kind; | |
208 | } | |
209 | ||
a06ea964 NC |
210 | static inline void |
211 | set_error (enum aarch64_operand_error_kind kind, const char *error) | |
212 | { | |
213 | inst.parsing_error.kind = kind; | |
214 | inst.parsing_error.error = error; | |
215 | } | |
216 | ||
217 | static inline void | |
218 | set_recoverable_error (const char *error) | |
219 | { | |
220 | set_error (AARCH64_OPDE_RECOVERABLE, error); | |
221 | } | |
222 | ||
223 | /* Use the DESC field of the corresponding aarch64_operand entry to compose | |
224 | the error message. */ | |
225 | static inline void | |
226 | set_default_error (void) | |
227 | { | |
228 | set_error (AARCH64_OPDE_SYNTAX_ERROR, NULL); | |
229 | } | |
230 | ||
231 | static inline void | |
232 | set_syntax_error (const char *error) | |
233 | { | |
234 | set_error (AARCH64_OPDE_SYNTAX_ERROR, error); | |
235 | } | |
236 | ||
237 | static inline void | |
238 | set_first_syntax_error (const char *error) | |
239 | { | |
240 | if (! error_p ()) | |
241 | set_error (AARCH64_OPDE_SYNTAX_ERROR, error); | |
242 | } | |
243 | ||
244 | static inline void | |
245 | set_fatal_syntax_error (const char *error) | |
246 | { | |
247 | set_error (AARCH64_OPDE_FATAL_SYNTAX_ERROR, error); | |
248 | } | |
249 | \f | |
a06ea964 NC |
250 | /* Return value for certain parsers when the parsing fails; those parsers |
251 | return the information of the parsed result, e.g. register number, on | |
252 | success. */ | |
253 | #define PARSE_FAIL -1 | |
254 | ||
255 | /* This is an invalid condition code that means no conditional field is | |
256 | present. */ | |
257 | #define COND_ALWAYS 0x10 | |
258 | ||
a06ea964 NC |
259 | typedef struct |
260 | { | |
261 | const char *template; | |
262 | uint32_t value; | |
263 | } asm_nzcv; | |
264 | ||
265 | struct reloc_entry | |
266 | { | |
267 | char *name; | |
268 | bfd_reloc_code_real_type reloc; | |
269 | }; | |
270 | ||
a06ea964 NC |
271 | /* Macros to define the register types and masks for the purpose |
272 | of parsing. */ | |
273 | ||
274 | #undef AARCH64_REG_TYPES | |
275 | #define AARCH64_REG_TYPES \ | |
276 | BASIC_REG_TYPE(R_32) /* w[0-30] */ \ | |
277 | BASIC_REG_TYPE(R_64) /* x[0-30] */ \ | |
278 | BASIC_REG_TYPE(SP_32) /* wsp */ \ | |
279 | BASIC_REG_TYPE(SP_64) /* sp */ \ | |
280 | BASIC_REG_TYPE(Z_32) /* wzr */ \ | |
281 | BASIC_REG_TYPE(Z_64) /* xzr */ \ | |
282 | BASIC_REG_TYPE(FP_B) /* b[0-31] *//* NOTE: keep FP_[BHSDQ] consecutive! */\ | |
283 | BASIC_REG_TYPE(FP_H) /* h[0-31] */ \ | |
284 | BASIC_REG_TYPE(FP_S) /* s[0-31] */ \ | |
285 | BASIC_REG_TYPE(FP_D) /* d[0-31] */ \ | |
286 | BASIC_REG_TYPE(FP_Q) /* q[0-31] */ \ | |
3493da5c SP |
287 | BASIC_REG_TYPE(CA_N) /* c[0-30] */ \ |
288 | BASIC_REG_TYPE(CA_SP) /* csp */ \ | |
289 | BASIC_REG_TYPE(CA_Z) /* czr */ \ | |
290 | BASIC_REG_TYPE(CA_D) /* ddc */ \ | |
a06ea964 | 291 | BASIC_REG_TYPE(VN) /* v[0-31] */ \ |
f11ad6bc RS |
292 | BASIC_REG_TYPE(ZN) /* z[0-31] */ \ |
293 | BASIC_REG_TYPE(PN) /* p[0-15] */ \ | |
e1b988bb | 294 | /* Typecheck: any 64-bit int reg (inc SP exc XZR). */ \ |
a06ea964 | 295 | MULTI_REG_TYPE(R64_SP, REG_TYPE(R_64) | REG_TYPE(SP_64)) \ |
4df068de RS |
296 | /* Typecheck: same, plus SVE registers. */ \ |
297 | MULTI_REG_TYPE(SVE_BASE, REG_TYPE(R_64) | REG_TYPE(SP_64) \ | |
298 | | REG_TYPE(ZN)) \ | |
e1b988bb RS |
299 | /* Typecheck: x[0-30], w[0-30] or [xw]zr. */ \ |
300 | MULTI_REG_TYPE(R_Z, REG_TYPE(R_32) | REG_TYPE(R_64) \ | |
301 | | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \ | |
4df068de RS |
302 | /* Typecheck: same, plus SVE registers. */ \ |
303 | MULTI_REG_TYPE(SVE_OFFSET, REG_TYPE(R_32) | REG_TYPE(R_64) \ | |
304 | | REG_TYPE(Z_32) | REG_TYPE(Z_64) \ | |
305 | | REG_TYPE(ZN)) \ | |
e1b988bb RS |
306 | /* Typecheck: x[0-30], w[0-30] or {w}sp. */ \ |
307 | MULTI_REG_TYPE(R_SP, REG_TYPE(R_32) | REG_TYPE(R_64) \ | |
308 | | REG_TYPE(SP_32) | REG_TYPE(SP_64)) \ | |
309 | /* Typecheck: any int (inc {W}SP inc [WX]ZR). */ \ | |
a06ea964 NC |
310 | MULTI_REG_TYPE(R_Z_SP, REG_TYPE(R_32) | REG_TYPE(R_64) \ |
311 | | REG_TYPE(SP_32) | REG_TYPE(SP_64) \ | |
312 | | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \ | |
313 | /* Typecheck: any [BHSDQ]P FP. */ \ | |
314 | MULTI_REG_TYPE(BHSDQ, REG_TYPE(FP_B) | REG_TYPE(FP_H) \ | |
315 | | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q)) \ | |
e1b988bb | 316 | /* Typecheck: any int or [BHSDQ]P FP or V reg (exc SP inc [WX]ZR). */ \ |
a06ea964 NC |
317 | MULTI_REG_TYPE(R_Z_BHSDQ_V, REG_TYPE(R_32) | REG_TYPE(R_64) \ |
318 | | REG_TYPE(Z_32) | REG_TYPE(Z_64) | REG_TYPE(VN) \ | |
319 | | REG_TYPE(FP_B) | REG_TYPE(FP_H) \ | |
320 | | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q)) \ | |
5b2b928e JB |
321 | /* Typecheck: as above, but also Zn, Pn, and {W}SP. This should only \ |
322 | be used for SVE instructions, since Zn and Pn are valid symbols \ | |
c0890d26 | 323 | in other contexts. */ \ |
5b2b928e JB |
324 | MULTI_REG_TYPE(R_Z_SP_BHSDQ_VZP, REG_TYPE(R_32) | REG_TYPE(R_64) \ |
325 | | REG_TYPE(SP_32) | REG_TYPE(SP_64) \ | |
c0890d26 RS |
326 | | REG_TYPE(Z_32) | REG_TYPE(Z_64) | REG_TYPE(VN) \ |
327 | | REG_TYPE(FP_B) | REG_TYPE(FP_H) \ | |
328 | | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q) \ | |
329 | | REG_TYPE(ZN) | REG_TYPE(PN)) \ | |
a06ea964 NC |
330 | /* Any integer register; used for error messages only. */ \ |
331 | MULTI_REG_TYPE(R_N, REG_TYPE(R_32) | REG_TYPE(R_64) \ | |
332 | | REG_TYPE(SP_32) | REG_TYPE(SP_64) \ | |
333 | | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \ | |
3493da5c SP |
334 | /* Typecheck: any capability register (inc CSP) */ \ |
335 | MULTI_REG_TYPE(CA_N_SP, REG_TYPE(CA_N) | REG_TYPE(CA_SP)) \ | |
336 | MULTI_REG_TYPE(CA_N_Z, REG_TYPE(CA_N) | REG_TYPE(CA_Z)) \ | |
a06ea964 NC |
337 | /* Pseudo type to mark the end of the enumerator sequence. */ \ |
338 | BASIC_REG_TYPE(MAX) | |
339 | ||
340 | #undef BASIC_REG_TYPE | |
341 | #define BASIC_REG_TYPE(T) REG_TYPE_##T, | |
342 | #undef MULTI_REG_TYPE | |
343 | #define MULTI_REG_TYPE(T,V) BASIC_REG_TYPE(T) | |
344 | ||
345 | /* Register type enumerators. */ | |
8a0b252a | 346 | typedef enum aarch64_reg_type_ |
a06ea964 NC |
347 | { |
348 | /* A list of REG_TYPE_*. */ | |
349 | AARCH64_REG_TYPES | |
350 | } aarch64_reg_type; | |
351 | ||
352 | #undef BASIC_REG_TYPE | |
353 | #define BASIC_REG_TYPE(T) 1 << REG_TYPE_##T, | |
354 | #undef REG_TYPE | |
355 | #define REG_TYPE(T) (1 << REG_TYPE_##T) | |
356 | #undef MULTI_REG_TYPE | |
357 | #define MULTI_REG_TYPE(T,V) V, | |
358 | ||
8a0b252a TS |
359 | /* Structure for a hash table entry for a register. */ |
360 | typedef struct | |
361 | { | |
362 | const char *name; | |
363 | unsigned char number; | |
364 | ENUM_BITFIELD (aarch64_reg_type_) type : 8; | |
365 | unsigned char builtin; | |
366 | } reg_entry; | |
367 | ||
a06ea964 NC |
368 | /* Values indexed by aarch64_reg_type to assist the type checking. */ |
369 | static const unsigned reg_type_masks[] = | |
370 | { | |
371 | AARCH64_REG_TYPES | |
372 | }; | |
373 | ||
374 | #undef BASIC_REG_TYPE | |
375 | #undef REG_TYPE | |
376 | #undef MULTI_REG_TYPE | |
377 | #undef AARCH64_REG_TYPES | |
378 | ||
379 | /* Diagnostics used when we don't get a register of the expected type. | |
380 | Note: this has to synchronized with aarch64_reg_type definitions | |
381 | above. */ | |
382 | static const char * | |
383 | get_reg_expected_msg (aarch64_reg_type reg_type) | |
384 | { | |
385 | const char *msg; | |
386 | ||
387 | switch (reg_type) | |
388 | { | |
389 | case REG_TYPE_R_32: | |
390 | msg = N_("integer 32-bit register expected"); | |
391 | break; | |
392 | case REG_TYPE_R_64: | |
393 | msg = N_("integer 64-bit register expected"); | |
394 | break; | |
395 | case REG_TYPE_R_N: | |
396 | msg = N_("integer register expected"); | |
397 | break; | |
e1b988bb RS |
398 | case REG_TYPE_R64_SP: |
399 | msg = N_("64-bit integer or SP register expected"); | |
400 | break; | |
4df068de RS |
401 | case REG_TYPE_SVE_BASE: |
402 | msg = N_("base register expected"); | |
403 | break; | |
e1b988bb RS |
404 | case REG_TYPE_R_Z: |
405 | msg = N_("integer or zero register expected"); | |
406 | break; | |
4df068de RS |
407 | case REG_TYPE_SVE_OFFSET: |
408 | msg = N_("offset register expected"); | |
409 | break; | |
e1b988bb RS |
410 | case REG_TYPE_R_SP: |
411 | msg = N_("integer or SP register expected"); | |
412 | break; | |
a06ea964 NC |
413 | case REG_TYPE_R_Z_SP: |
414 | msg = N_("integer, zero or SP register expected"); | |
415 | break; | |
416 | case REG_TYPE_FP_B: | |
417 | msg = N_("8-bit SIMD scalar register expected"); | |
418 | break; | |
419 | case REG_TYPE_FP_H: | |
420 | msg = N_("16-bit SIMD scalar or floating-point half precision " | |
421 | "register expected"); | |
422 | break; | |
423 | case REG_TYPE_FP_S: | |
424 | msg = N_("32-bit SIMD scalar or floating-point single precision " | |
425 | "register expected"); | |
426 | break; | |
427 | case REG_TYPE_FP_D: | |
428 | msg = N_("64-bit SIMD scalar or floating-point double precision " | |
429 | "register expected"); | |
430 | break; | |
431 | case REG_TYPE_FP_Q: | |
432 | msg = N_("128-bit SIMD scalar or floating-point quad precision " | |
433 | "register expected"); | |
434 | break; | |
a06ea964 | 435 | case REG_TYPE_R_Z_BHSDQ_V: |
5b2b928e | 436 | case REG_TYPE_R_Z_SP_BHSDQ_VZP: |
a06ea964 NC |
437 | msg = N_("register expected"); |
438 | break; | |
439 | case REG_TYPE_BHSDQ: /* any [BHSDQ]P FP */ | |
440 | msg = N_("SIMD scalar or floating-point register expected"); | |
441 | break; | |
442 | case REG_TYPE_VN: /* any V reg */ | |
443 | msg = N_("vector register expected"); | |
444 | break; | |
f11ad6bc RS |
445 | case REG_TYPE_ZN: |
446 | msg = N_("SVE vector register expected"); | |
447 | break; | |
448 | case REG_TYPE_PN: | |
449 | msg = N_("SVE predicate register expected"); | |
450 | break; | |
3493da5c SP |
451 | case REG_TYPE_CA_N: |
452 | msg = N_("Capability register C0 - C30 expected"); | |
453 | break; | |
454 | case REG_TYPE_CA_SP: | |
455 | msg = N_("Capability register CSP expected"); | |
456 | break; | |
457 | case REG_TYPE_CA_N_SP: | |
458 | msg = N_("Capability register C0 - C30 or CSP expected"); | |
459 | break; | |
460 | case REG_TYPE_CA_Z: | |
461 | msg = N_("Capability register CZR expected"); | |
462 | break; | |
a06ea964 NC |
463 | default: |
464 | as_fatal (_("invalid register type %d"), reg_type); | |
465 | } | |
466 | return msg; | |
467 | } | |
468 | ||
469 | /* Some well known registers that we refer to directly elsewhere. */ | |
470 | #define REG_SP 31 | |
c469c864 | 471 | #define REG_ZR 31 |
a06ea964 NC |
472 | |
473 | /* Instructions take 4 bytes in the object file. */ | |
474 | #define INSN_SIZE 4 | |
475 | ||
629310ab ML |
476 | static htab_t aarch64_ops_hsh; |
477 | static htab_t aarch64_cond_hsh; | |
478 | static htab_t aarch64_shift_hsh; | |
479 | static htab_t aarch64_sys_regs_hsh; | |
480 | static htab_t aarch64_pstatefield_hsh; | |
481 | static htab_t aarch64_sys_regs_ic_hsh; | |
482 | static htab_t aarch64_sys_regs_dc_hsh; | |
483 | static htab_t aarch64_sys_regs_at_hsh; | |
484 | static htab_t aarch64_sys_regs_tlbi_hsh; | |
485 | static htab_t aarch64_sys_regs_sr_hsh; | |
486 | static htab_t aarch64_reg_hsh; | |
487 | static htab_t aarch64_barrier_opt_hsh; | |
488 | static htab_t aarch64_nzcv_hsh; | |
489 | static htab_t aarch64_pldop_hsh; | |
490 | static htab_t aarch64_hint_opt_hsh; | |
a06ea964 NC |
491 | |
492 | /* Stuff needed to resolve the label ambiguity | |
493 | As: | |
494 | ... | |
495 | label: <insn> | |
496 | may differ from: | |
497 | ... | |
498 | label: | |
499 | <insn> */ | |
500 | ||
501 | static symbolS *last_label_seen; | |
502 | ||
503 | /* Literal pool structure. Held on a per-section | |
504 | and per-sub-section basis. */ | |
505 | ||
506 | #define MAX_LITERAL_POOL_SIZE 1024 | |
55d9b4c1 NC |
507 | typedef struct literal_expression |
508 | { | |
509 | expressionS exp; | |
510 | /* If exp.op == O_big then this bignum holds a copy of the global bignum value. */ | |
511 | LITTLENUM_TYPE * bignum; | |
512 | } literal_expression; | |
513 | ||
a06ea964 NC |
514 | typedef struct literal_pool |
515 | { | |
55d9b4c1 | 516 | literal_expression literals[MAX_LITERAL_POOL_SIZE]; |
a06ea964 NC |
517 | unsigned int next_free_entry; |
518 | unsigned int id; | |
519 | symbolS *symbol; | |
520 | segT section; | |
521 | subsegT sub_section; | |
522 | int size; | |
523 | struct literal_pool *next; | |
524 | } literal_pool; | |
525 | ||
526 | /* Pointer to a linked list of literal pools. */ | |
527 | static literal_pool *list_of_pools = NULL; | |
528 | \f | |
529 | /* Pure syntax. */ | |
530 | ||
531 | /* This array holds the chars that always start a comment. If the | |
532 | pre-processor is disabled, these aren't very useful. */ | |
533 | const char comment_chars[] = ""; | |
534 | ||
535 | /* This array holds the chars that only start a comment at the beginning of | |
536 | a line. If the line seems to have the form '# 123 filename' | |
537 | .line and .file directives will appear in the pre-processed output. */ | |
538 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
539 | first line of the input file. This is because the compiler outputs | |
540 | #NO_APP at the beginning of its output. */ | |
541 | /* Also note that comments like this one will always work. */ | |
542 | const char line_comment_chars[] = "#"; | |
543 | ||
544 | const char line_separator_chars[] = ";"; | |
545 | ||
546 | /* Chars that can be used to separate mant | |
547 | from exp in floating point numbers. */ | |
548 | const char EXP_CHARS[] = "eE"; | |
549 | ||
550 | /* Chars that mean this number is a floating point constant. */ | |
551 | /* As in 0f12.456 */ | |
552 | /* or 0d1.2345e12 */ | |
553 | ||
b20d3859 | 554 | const char FLT_CHARS[] = "rRsSfFdDxXeEpPhH"; |
a06ea964 NC |
555 | |
556 | /* Prefix character that indicates the start of an immediate value. */ | |
557 | #define is_immediate_prefix(C) ((C) == '#') | |
558 | ||
559 | /* Separator character handling. */ | |
560 | ||
561 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
562 | ||
563 | static inline bfd_boolean | |
564 | skip_past_char (char **str, char c) | |
565 | { | |
566 | if (**str == c) | |
567 | { | |
568 | (*str)++; | |
569 | return TRUE; | |
570 | } | |
571 | else | |
572 | return FALSE; | |
573 | } | |
574 | ||
575 | #define skip_past_comma(str) skip_past_char (str, ',') | |
576 | ||
577 | /* Arithmetic expressions (possibly involving symbols). */ | |
578 | ||
a06ea964 NC |
579 | static bfd_boolean in_my_get_expression_p = FALSE; |
580 | ||
581 | /* Third argument to my_get_expression. */ | |
582 | #define GE_NO_PREFIX 0 | |
583 | #define GE_OPT_PREFIX 1 | |
584 | ||
585 | /* Return TRUE if the string pointed by *STR is successfully parsed | |
586 | as an valid expression; *EP will be filled with the information of | |
587 | such an expression. Otherwise return FALSE. */ | |
588 | ||
589 | static bfd_boolean | |
590 | my_get_expression (expressionS * ep, char **str, int prefix_mode, | |
591 | int reject_absent) | |
592 | { | |
593 | char *save_in; | |
594 | segT seg; | |
595 | int prefix_present_p = 0; | |
596 | ||
597 | switch (prefix_mode) | |
598 | { | |
599 | case GE_NO_PREFIX: | |
600 | break; | |
601 | case GE_OPT_PREFIX: | |
602 | if (is_immediate_prefix (**str)) | |
603 | { | |
604 | (*str)++; | |
605 | prefix_present_p = 1; | |
606 | } | |
607 | break; | |
608 | default: | |
609 | abort (); | |
610 | } | |
611 | ||
612 | memset (ep, 0, sizeof (expressionS)); | |
613 | ||
614 | save_in = input_line_pointer; | |
615 | input_line_pointer = *str; | |
616 | in_my_get_expression_p = TRUE; | |
617 | seg = expression (ep); | |
618 | in_my_get_expression_p = FALSE; | |
619 | ||
620 | if (ep->X_op == O_illegal || (reject_absent && ep->X_op == O_absent)) | |
621 | { | |
622 | /* We found a bad expression in md_operand(). */ | |
623 | *str = input_line_pointer; | |
624 | input_line_pointer = save_in; | |
625 | if (prefix_present_p && ! error_p ()) | |
626 | set_fatal_syntax_error (_("bad expression")); | |
627 | else | |
628 | set_first_syntax_error (_("bad expression")); | |
629 | return FALSE; | |
630 | } | |
631 | ||
632 | #ifdef OBJ_AOUT | |
633 | if (seg != absolute_section | |
634 | && seg != text_section | |
635 | && seg != data_section | |
636 | && seg != bss_section && seg != undefined_section) | |
637 | { | |
638 | set_syntax_error (_("bad segment")); | |
639 | *str = input_line_pointer; | |
640 | input_line_pointer = save_in; | |
641 | return FALSE; | |
642 | } | |
643 | #else | |
644 | (void) seg; | |
645 | #endif | |
646 | ||
a06ea964 NC |
647 | *str = input_line_pointer; |
648 | input_line_pointer = save_in; | |
649 | return TRUE; | |
650 | } | |
651 | ||
652 | /* Turn a string in input_line_pointer into a floating point constant | |
653 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
654 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
655 | returned, or NULL on OK. */ | |
656 | ||
6d4af3c2 | 657 | const char * |
a06ea964 NC |
658 | md_atof (int type, char *litP, int *sizeP) |
659 | { | |
eb5bbc48 MM |
660 | /* If this is a bfloat16 type, then parse it slightly differently - |
661 | as it does not follow the IEEE standard exactly. */ | |
662 | if (type == 'b') | |
663 | { | |
664 | char * t; | |
665 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
666 | FLONUM_TYPE generic_float; | |
667 | ||
668 | t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float); | |
669 | ||
670 | if (t) | |
671 | input_line_pointer = t; | |
672 | else | |
673 | return _("invalid floating point number"); | |
674 | ||
675 | switch (generic_float.sign) | |
676 | { | |
677 | /* Is +Inf. */ | |
678 | case 'P': | |
679 | words[0] = 0x7f80; | |
680 | break; | |
681 | ||
682 | /* Is -Inf. */ | |
683 | case 'N': | |
684 | words[0] = 0xff80; | |
685 | break; | |
686 | ||
687 | /* Is NaN. */ | |
688 | /* bfloat16 has two types of NaN - quiet and signalling. | |
689 | Quiet NaN has bit[6] == 1 && faction != 0, whereas | |
690 | signalling Nan's have bit[0] == 0 && fraction != 0. | |
691 | Chose this specific encoding as it is the same form | |
692 | as used by other IEEE 754 encodings in GAS. */ | |
693 | case 0: | |
694 | words[0] = 0x7fff; | |
695 | break; | |
696 | ||
697 | default: | |
698 | break; | |
699 | } | |
700 | ||
701 | *sizeP = 2; | |
702 | ||
703 | md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE)); | |
704 | ||
705 | return NULL; | |
706 | } | |
707 | ||
a06ea964 NC |
708 | return ieee_md_atof (type, litP, sizeP, target_big_endian); |
709 | } | |
710 | ||
711 | /* We handle all bad expressions here, so that we can report the faulty | |
712 | instruction in the error message. */ | |
713 | void | |
714 | md_operand (expressionS * exp) | |
715 | { | |
716 | if (in_my_get_expression_p) | |
717 | exp->X_op = O_illegal; | |
718 | } | |
719 | ||
720 | /* Immediate values. */ | |
721 | ||
722 | /* Errors may be set multiple times during parsing or bit encoding | |
723 | (particularly in the Neon bits), but usually the earliest error which is set | |
724 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
725 | errors by calling this function. */ | |
726 | ||
727 | static void | |
728 | first_error (const char *error) | |
729 | { | |
730 | if (! error_p ()) | |
731 | set_syntax_error (error); | |
732 | } | |
733 | ||
2b0f3761 | 734 | /* Similar to first_error, but this function accepts formatted error |
a06ea964 NC |
735 | message. */ |
736 | static void | |
737 | first_error_fmt (const char *format, ...) | |
738 | { | |
739 | va_list args; | |
740 | enum | |
741 | { size = 100 }; | |
742 | /* N.B. this single buffer will not cause error messages for different | |
743 | instructions to pollute each other; this is because at the end of | |
744 | processing of each assembly line, error message if any will be | |
745 | collected by as_bad. */ | |
746 | static char buffer[size]; | |
747 | ||
748 | if (! error_p ()) | |
749 | { | |
3e0baa28 | 750 | int ret ATTRIBUTE_UNUSED; |
a06ea964 NC |
751 | va_start (args, format); |
752 | ret = vsnprintf (buffer, size, format, args); | |
753 | know (ret <= size - 1 && ret >= 0); | |
754 | va_end (args); | |
755 | set_syntax_error (buffer); | |
756 | } | |
757 | } | |
758 | ||
759 | /* Register parsing. */ | |
760 | ||
761 | /* Generic register parser which is called by other specialized | |
762 | register parsers. | |
763 | CCP points to what should be the beginning of a register name. | |
764 | If it is indeed a valid register name, advance CCP over it and | |
765 | return the reg_entry structure; otherwise return NULL. | |
766 | It does not issue diagnostics. */ | |
767 | ||
768 | static reg_entry * | |
769 | parse_reg (char **ccp) | |
770 | { | |
771 | char *start = *ccp; | |
772 | char *p; | |
773 | reg_entry *reg; | |
774 | ||
775 | #ifdef REGISTER_PREFIX | |
776 | if (*start != REGISTER_PREFIX) | |
777 | return NULL; | |
778 | start++; | |
779 | #endif | |
780 | ||
781 | p = start; | |
782 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
783 | return NULL; | |
784 | ||
785 | do | |
786 | p++; | |
787 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
788 | ||
629310ab | 789 | reg = (reg_entry *) str_hash_find_n (aarch64_reg_hsh, start, p - start); |
a06ea964 NC |
790 | |
791 | if (!reg) | |
792 | return NULL; | |
793 | ||
794 | *ccp = p; | |
795 | return reg; | |
796 | } | |
797 | ||
798 | /* Return TRUE if REG->TYPE is a valid type of TYPE; otherwise | |
799 | return FALSE. */ | |
800 | static bfd_boolean | |
801 | aarch64_check_reg_type (const reg_entry *reg, aarch64_reg_type type) | |
802 | { | |
e1b988bb | 803 | return (reg_type_masks[type] & (1 << reg->type)) != 0; |
a06ea964 NC |
804 | } |
805 | ||
4df068de RS |
806 | /* Try to parse a base or offset register. Allow SVE base and offset |
807 | registers if REG_TYPE includes SVE registers. Return the register | |
808 | entry on success, setting *QUALIFIER to the register qualifier. | |
809 | Return null otherwise. | |
e1b988bb | 810 | |
a06ea964 NC |
811 | Note that this function does not issue any diagnostics. */ |
812 | ||
e1b988bb | 813 | static const reg_entry * |
4df068de RS |
814 | aarch64_addr_reg_parse (char **ccp, aarch64_reg_type reg_type, |
815 | aarch64_opnd_qualifier_t *qualifier) | |
a06ea964 NC |
816 | { |
817 | char *str = *ccp; | |
818 | const reg_entry *reg = parse_reg (&str); | |
819 | ||
820 | if (reg == NULL) | |
e1b988bb | 821 | return NULL; |
a06ea964 NC |
822 | |
823 | switch (reg->type) | |
824 | { | |
e1b988bb | 825 | case REG_TYPE_R_32: |
a06ea964 | 826 | case REG_TYPE_SP_32: |
e1b988bb RS |
827 | case REG_TYPE_Z_32: |
828 | *qualifier = AARCH64_OPND_QLF_W; | |
a06ea964 | 829 | break; |
e1b988bb | 830 | |
a06ea964 | 831 | case REG_TYPE_R_64: |
e1b988bb | 832 | case REG_TYPE_SP_64: |
a06ea964 | 833 | case REG_TYPE_Z_64: |
e1b988bb | 834 | *qualifier = AARCH64_OPND_QLF_X; |
a06ea964 | 835 | break; |
e1b988bb | 836 | |
4df068de RS |
837 | case REG_TYPE_ZN: |
838 | if ((reg_type_masks[reg_type] & (1 << REG_TYPE_ZN)) == 0 | |
839 | || str[0] != '.') | |
840 | return NULL; | |
841 | switch (TOLOWER (str[1])) | |
842 | { | |
843 | case 's': | |
844 | *qualifier = AARCH64_OPND_QLF_S_S; | |
845 | break; | |
846 | case 'd': | |
847 | *qualifier = AARCH64_OPND_QLF_S_D; | |
848 | break; | |
849 | default: | |
850 | return NULL; | |
851 | } | |
852 | str += 2; | |
853 | break; | |
854 | ||
3493da5c SP |
855 | case REG_TYPE_CA_N: |
856 | case REG_TYPE_CA_SP: | |
857 | *qualifier = AARCH64_OPND_QLF_CA; | |
858 | break; | |
859 | ||
a06ea964 | 860 | default: |
e1b988bb | 861 | return NULL; |
a06ea964 NC |
862 | } |
863 | ||
864 | *ccp = str; | |
865 | ||
e1b988bb | 866 | return reg; |
a06ea964 NC |
867 | } |
868 | ||
4df068de RS |
869 | /* Try to parse a base or offset register. Return the register entry |
870 | on success, setting *QUALIFIER to the register qualifier. Return null | |
871 | otherwise. | |
872 | ||
873 | Note that this function does not issue any diagnostics. */ | |
874 | ||
875 | static const reg_entry * | |
876 | aarch64_reg_parse_32_64 (char **ccp, aarch64_opnd_qualifier_t *qualifier) | |
877 | { | |
878 | return aarch64_addr_reg_parse (ccp, REG_TYPE_R_Z_SP, qualifier); | |
879 | } | |
880 | ||
f11ad6bc RS |
881 | /* Parse the qualifier of a vector register or vector element of type |
882 | REG_TYPE. Fill in *PARSED_TYPE and return TRUE if the parsing | |
883 | succeeds; otherwise return FALSE. | |
a06ea964 NC |
884 | |
885 | Accept only one occurrence of: | |
65a55fbb | 886 | 4b 8b 16b 2h 4h 8h 2s 4s 1d 2d |
a06ea964 NC |
887 | b h s d q */ |
888 | static bfd_boolean | |
f11ad6bc RS |
889 | parse_vector_type_for_operand (aarch64_reg_type reg_type, |
890 | struct vector_type_el *parsed_type, char **str) | |
a06ea964 NC |
891 | { |
892 | char *ptr = *str; | |
893 | unsigned width; | |
894 | unsigned element_size; | |
f06935a5 | 895 | enum vector_el_type type; |
a06ea964 NC |
896 | |
897 | /* skip '.' */ | |
d50c751e | 898 | gas_assert (*ptr == '.'); |
a06ea964 NC |
899 | ptr++; |
900 | ||
f11ad6bc | 901 | if (reg_type == REG_TYPE_ZN || reg_type == REG_TYPE_PN || !ISDIGIT (*ptr)) |
a06ea964 NC |
902 | { |
903 | width = 0; | |
904 | goto elt_size; | |
905 | } | |
906 | width = strtoul (ptr, &ptr, 10); | |
907 | if (width != 1 && width != 2 && width != 4 && width != 8 && width != 16) | |
908 | { | |
909 | first_error_fmt (_("bad size %d in vector width specifier"), width); | |
910 | return FALSE; | |
911 | } | |
912 | ||
dc1e8a47 | 913 | elt_size: |
a06ea964 NC |
914 | switch (TOLOWER (*ptr)) |
915 | { | |
916 | case 'b': | |
917 | type = NT_b; | |
918 | element_size = 8; | |
919 | break; | |
920 | case 'h': | |
921 | type = NT_h; | |
922 | element_size = 16; | |
923 | break; | |
924 | case 's': | |
925 | type = NT_s; | |
926 | element_size = 32; | |
927 | break; | |
928 | case 'd': | |
929 | type = NT_d; | |
930 | element_size = 64; | |
931 | break; | |
932 | case 'q': | |
582e12bf | 933 | if (reg_type == REG_TYPE_ZN || width == 1) |
a06ea964 NC |
934 | { |
935 | type = NT_q; | |
936 | element_size = 128; | |
937 | break; | |
938 | } | |
939 | /* fall through. */ | |
940 | default: | |
941 | if (*ptr != '\0') | |
942 | first_error_fmt (_("unexpected character `%c' in element size"), *ptr); | |
943 | else | |
944 | first_error (_("missing element size")); | |
945 | return FALSE; | |
946 | } | |
65a55fbb TC |
947 | if (width != 0 && width * element_size != 64 |
948 | && width * element_size != 128 | |
949 | && !(width == 2 && element_size == 16) | |
950 | && !(width == 4 && element_size == 8)) | |
a06ea964 NC |
951 | { |
952 | first_error_fmt (_ | |
953 | ("invalid element size %d and vector size combination %c"), | |
954 | width, *ptr); | |
955 | return FALSE; | |
956 | } | |
957 | ptr++; | |
958 | ||
959 | parsed_type->type = type; | |
960 | parsed_type->width = width; | |
961 | ||
962 | *str = ptr; | |
963 | ||
964 | return TRUE; | |
965 | } | |
966 | ||
d50c751e RS |
967 | /* *STR contains an SVE zero/merge predication suffix. Parse it into |
968 | *PARSED_TYPE and point *STR at the end of the suffix. */ | |
969 | ||
970 | static bfd_boolean | |
971 | parse_predication_for_operand (struct vector_type_el *parsed_type, char **str) | |
972 | { | |
973 | char *ptr = *str; | |
974 | ||
975 | /* Skip '/'. */ | |
976 | gas_assert (*ptr == '/'); | |
977 | ptr++; | |
978 | switch (TOLOWER (*ptr)) | |
979 | { | |
980 | case 'z': | |
981 | parsed_type->type = NT_zero; | |
982 | break; | |
983 | case 'm': | |
984 | parsed_type->type = NT_merge; | |
985 | break; | |
986 | default: | |
987 | if (*ptr != '\0' && *ptr != ',') | |
988 | first_error_fmt (_("unexpected character `%c' in predication type"), | |
989 | *ptr); | |
990 | else | |
991 | first_error (_("missing predication type")); | |
992 | return FALSE; | |
993 | } | |
994 | parsed_type->width = 0; | |
995 | *str = ptr + 1; | |
996 | return TRUE; | |
997 | } | |
998 | ||
a06ea964 NC |
999 | /* Parse a register of the type TYPE. |
1000 | ||
1001 | Return PARSE_FAIL if the string pointed by *CCP is not a valid register | |
1002 | name or the parsed register is not of TYPE. | |
1003 | ||
1004 | Otherwise return the register number, and optionally fill in the actual | |
1005 | type of the register in *RTYPE when multiple alternatives were given, and | |
1006 | return the register shape and element index information in *TYPEINFO. | |
1007 | ||
1008 | IN_REG_LIST should be set with TRUE if the caller is parsing a register | |
1009 | list. */ | |
1010 | ||
1011 | static int | |
1012 | parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, | |
8f9a77af | 1013 | struct vector_type_el *typeinfo, bfd_boolean in_reg_list) |
a06ea964 NC |
1014 | { |
1015 | char *str = *ccp; | |
1016 | const reg_entry *reg = parse_reg (&str); | |
8f9a77af RS |
1017 | struct vector_type_el atype; |
1018 | struct vector_type_el parsetype; | |
a06ea964 NC |
1019 | bfd_boolean is_typed_vecreg = FALSE; |
1020 | ||
1021 | atype.defined = 0; | |
1022 | atype.type = NT_invtype; | |
1023 | atype.width = -1; | |
1024 | atype.index = 0; | |
1025 | ||
1026 | if (reg == NULL) | |
1027 | { | |
1028 | if (typeinfo) | |
1029 | *typeinfo = atype; | |
1030 | set_default_error (); | |
1031 | return PARSE_FAIL; | |
1032 | } | |
1033 | ||
1034 | if (! aarch64_check_reg_type (reg, type)) | |
1035 | { | |
1036 | DEBUG_TRACE ("reg type check failed"); | |
1037 | set_default_error (); | |
1038 | return PARSE_FAIL; | |
1039 | } | |
1040 | type = reg->type; | |
1041 | ||
f11ad6bc | 1042 | if ((type == REG_TYPE_VN || type == REG_TYPE_ZN || type == REG_TYPE_PN) |
d50c751e | 1043 | && (*str == '.' || (type == REG_TYPE_PN && *str == '/'))) |
a06ea964 | 1044 | { |
d50c751e RS |
1045 | if (*str == '.') |
1046 | { | |
1047 | if (!parse_vector_type_for_operand (type, &parsetype, &str)) | |
1048 | return PARSE_FAIL; | |
1049 | } | |
1050 | else | |
1051 | { | |
1052 | if (!parse_predication_for_operand (&parsetype, &str)) | |
1053 | return PARSE_FAIL; | |
1054 | } | |
a235d3ae | 1055 | |
a06ea964 NC |
1056 | /* Register if of the form Vn.[bhsdq]. */ |
1057 | is_typed_vecreg = TRUE; | |
1058 | ||
f11ad6bc RS |
1059 | if (type == REG_TYPE_ZN || type == REG_TYPE_PN) |
1060 | { | |
1061 | /* The width is always variable; we don't allow an integer width | |
1062 | to be specified. */ | |
1063 | gas_assert (parsetype.width == 0); | |
1064 | atype.defined |= NTA_HASVARWIDTH | NTA_HASTYPE; | |
1065 | } | |
1066 | else if (parsetype.width == 0) | |
a06ea964 NC |
1067 | /* Expect index. In the new scheme we cannot have |
1068 | Vn.[bhsdq] represent a scalar. Therefore any | |
1069 | Vn.[bhsdq] should have an index following it. | |
33eaf5de | 1070 | Except in reglists of course. */ |
a06ea964 NC |
1071 | atype.defined |= NTA_HASINDEX; |
1072 | else | |
1073 | atype.defined |= NTA_HASTYPE; | |
1074 | ||
1075 | atype.type = parsetype.type; | |
1076 | atype.width = parsetype.width; | |
1077 | } | |
1078 | ||
1079 | if (skip_past_char (&str, '[')) | |
1080 | { | |
1081 | expressionS exp; | |
1082 | ||
1083 | /* Reject Sn[index] syntax. */ | |
1084 | if (!is_typed_vecreg) | |
1085 | { | |
1086 | first_error (_("this type of register can't be indexed")); | |
1087 | return PARSE_FAIL; | |
1088 | } | |
1089 | ||
535b785f | 1090 | if (in_reg_list) |
a06ea964 NC |
1091 | { |
1092 | first_error (_("index not allowed inside register list")); | |
1093 | return PARSE_FAIL; | |
1094 | } | |
1095 | ||
1096 | atype.defined |= NTA_HASINDEX; | |
1097 | ||
1098 | my_get_expression (&exp, &str, GE_NO_PREFIX, 1); | |
1099 | ||
1100 | if (exp.X_op != O_constant) | |
1101 | { | |
1102 | first_error (_("constant expression required")); | |
1103 | return PARSE_FAIL; | |
1104 | } | |
1105 | ||
1106 | if (! skip_past_char (&str, ']')) | |
1107 | return PARSE_FAIL; | |
1108 | ||
1109 | atype.index = exp.X_add_number; | |
1110 | } | |
1111 | else if (!in_reg_list && (atype.defined & NTA_HASINDEX) != 0) | |
1112 | { | |
1113 | /* Indexed vector register expected. */ | |
1114 | first_error (_("indexed vector register expected")); | |
1115 | return PARSE_FAIL; | |
1116 | } | |
1117 | ||
1118 | /* A vector reg Vn should be typed or indexed. */ | |
1119 | if (type == REG_TYPE_VN && atype.defined == 0) | |
1120 | { | |
1121 | first_error (_("invalid use of vector register")); | |
1122 | } | |
1123 | ||
1124 | if (typeinfo) | |
1125 | *typeinfo = atype; | |
1126 | ||
1127 | if (rtype) | |
1128 | *rtype = type; | |
1129 | ||
1130 | *ccp = str; | |
1131 | ||
1132 | return reg->number; | |
1133 | } | |
1134 | ||
1135 | /* Parse register. | |
1136 | ||
1137 | Return the register number on success; return PARSE_FAIL otherwise. | |
1138 | ||
1139 | If RTYPE is not NULL, return in *RTYPE the (possibly restricted) type of | |
1140 | the register (e.g. NEON double or quad reg when either has been requested). | |
1141 | ||
1142 | If this is a NEON vector register with additional type information, fill | |
1143 | in the struct pointed to by VECTYPE (if non-NULL). | |
1144 | ||
1145 | This parser does not handle register list. */ | |
1146 | ||
1147 | static int | |
1148 | aarch64_reg_parse (char **ccp, aarch64_reg_type type, | |
8f9a77af | 1149 | aarch64_reg_type *rtype, struct vector_type_el *vectype) |
a06ea964 | 1150 | { |
8f9a77af | 1151 | struct vector_type_el atype; |
a06ea964 NC |
1152 | char *str = *ccp; |
1153 | int reg = parse_typed_reg (&str, type, rtype, &atype, | |
1154 | /*in_reg_list= */ FALSE); | |
1155 | ||
1156 | if (reg == PARSE_FAIL) | |
1157 | return PARSE_FAIL; | |
1158 | ||
1159 | if (vectype) | |
1160 | *vectype = atype; | |
1161 | ||
1162 | *ccp = str; | |
1163 | ||
1164 | return reg; | |
1165 | } | |
1166 | ||
1167 | static inline bfd_boolean | |
8f9a77af | 1168 | eq_vector_type_el (struct vector_type_el e1, struct vector_type_el e2) |
a06ea964 NC |
1169 | { |
1170 | return | |
1171 | e1.type == e2.type | |
1172 | && e1.defined == e2.defined | |
1173 | && e1.width == e2.width && e1.index == e2.index; | |
1174 | } | |
1175 | ||
10d76650 RS |
1176 | /* This function parses a list of vector registers of type TYPE. |
1177 | On success, it returns the parsed register list information in the | |
1178 | following encoded format: | |
a06ea964 NC |
1179 | |
1180 | bit 18-22 | 13-17 | 7-11 | 2-6 | 0-1 | |
1181 | 4th regno | 3rd regno | 2nd regno | 1st regno | num_of_reg | |
1182 | ||
1183 | The information of the register shape and/or index is returned in | |
1184 | *VECTYPE. | |
1185 | ||
1186 | It returns PARSE_FAIL if the register list is invalid. | |
1187 | ||
1188 | The list contains one to four registers. | |
1189 | Each register can be one of: | |
1190 | <Vt>.<T>[<index>] | |
1191 | <Vt>.<T> | |
1192 | All <T> should be identical. | |
1193 | All <index> should be identical. | |
1194 | There are restrictions on <Vt> numbers which are checked later | |
1195 | (by reg_list_valid_p). */ | |
1196 | ||
1197 | static int | |
10d76650 RS |
1198 | parse_vector_reg_list (char **ccp, aarch64_reg_type type, |
1199 | struct vector_type_el *vectype) | |
a06ea964 NC |
1200 | { |
1201 | char *str = *ccp; | |
1202 | int nb_regs; | |
8f9a77af | 1203 | struct vector_type_el typeinfo, typeinfo_first; |
a06ea964 NC |
1204 | int val, val_range; |
1205 | int in_range; | |
1206 | int ret_val; | |
1207 | int i; | |
1208 | bfd_boolean error = FALSE; | |
1209 | bfd_boolean expect_index = FALSE; | |
1210 | ||
1211 | if (*str != '{') | |
1212 | { | |
1213 | set_syntax_error (_("expecting {")); | |
1214 | return PARSE_FAIL; | |
1215 | } | |
1216 | str++; | |
1217 | ||
1218 | nb_regs = 0; | |
1219 | typeinfo_first.defined = 0; | |
1220 | typeinfo_first.type = NT_invtype; | |
1221 | typeinfo_first.width = -1; | |
1222 | typeinfo_first.index = 0; | |
1223 | ret_val = 0; | |
1224 | val = -1; | |
1225 | val_range = -1; | |
1226 | in_range = 0; | |
1227 | do | |
1228 | { | |
1229 | if (in_range) | |
1230 | { | |
1231 | str++; /* skip over '-' */ | |
1232 | val_range = val; | |
1233 | } | |
10d76650 | 1234 | val = parse_typed_reg (&str, type, NULL, &typeinfo, |
a06ea964 NC |
1235 | /*in_reg_list= */ TRUE); |
1236 | if (val == PARSE_FAIL) | |
1237 | { | |
1238 | set_first_syntax_error (_("invalid vector register in list")); | |
1239 | error = TRUE; | |
1240 | continue; | |
1241 | } | |
1242 | /* reject [bhsd]n */ | |
f11ad6bc | 1243 | if (type == REG_TYPE_VN && typeinfo.defined == 0) |
a06ea964 NC |
1244 | { |
1245 | set_first_syntax_error (_("invalid scalar register in list")); | |
1246 | error = TRUE; | |
1247 | continue; | |
1248 | } | |
1249 | ||
1250 | if (typeinfo.defined & NTA_HASINDEX) | |
1251 | expect_index = TRUE; | |
1252 | ||
1253 | if (in_range) | |
1254 | { | |
1255 | if (val < val_range) | |
1256 | { | |
1257 | set_first_syntax_error | |
1258 | (_("invalid range in vector register list")); | |
1259 | error = TRUE; | |
1260 | } | |
1261 | val_range++; | |
1262 | } | |
1263 | else | |
1264 | { | |
1265 | val_range = val; | |
1266 | if (nb_regs == 0) | |
1267 | typeinfo_first = typeinfo; | |
8f9a77af | 1268 | else if (! eq_vector_type_el (typeinfo_first, typeinfo)) |
a06ea964 NC |
1269 | { |
1270 | set_first_syntax_error | |
1271 | (_("type mismatch in vector register list")); | |
1272 | error = TRUE; | |
1273 | } | |
1274 | } | |
1275 | if (! error) | |
1276 | for (i = val_range; i <= val; i++) | |
1277 | { | |
1278 | ret_val |= i << (5 * nb_regs); | |
1279 | nb_regs++; | |
1280 | } | |
1281 | in_range = 0; | |
1282 | } | |
1283 | while (skip_past_comma (&str) || (in_range = 1, *str == '-')); | |
1284 | ||
1285 | skip_whitespace (str); | |
1286 | if (*str != '}') | |
1287 | { | |
1288 | set_first_syntax_error (_("end of vector register list not found")); | |
1289 | error = TRUE; | |
1290 | } | |
1291 | str++; | |
1292 | ||
1293 | skip_whitespace (str); | |
1294 | ||
1295 | if (expect_index) | |
1296 | { | |
1297 | if (skip_past_char (&str, '[')) | |
1298 | { | |
1299 | expressionS exp; | |
1300 | ||
1301 | my_get_expression (&exp, &str, GE_NO_PREFIX, 1); | |
1302 | if (exp.X_op != O_constant) | |
1303 | { | |
1304 | set_first_syntax_error (_("constant expression required.")); | |
1305 | error = TRUE; | |
1306 | } | |
1307 | if (! skip_past_char (&str, ']')) | |
1308 | error = TRUE; | |
1309 | else | |
1310 | typeinfo_first.index = exp.X_add_number; | |
1311 | } | |
1312 | else | |
1313 | { | |
1314 | set_first_syntax_error (_("expected index")); | |
1315 | error = TRUE; | |
1316 | } | |
1317 | } | |
1318 | ||
1319 | if (nb_regs > 4) | |
1320 | { | |
1321 | set_first_syntax_error (_("too many registers in vector register list")); | |
1322 | error = TRUE; | |
1323 | } | |
1324 | else if (nb_regs == 0) | |
1325 | { | |
1326 | set_first_syntax_error (_("empty vector register list")); | |
1327 | error = TRUE; | |
1328 | } | |
1329 | ||
1330 | *ccp = str; | |
1331 | if (! error) | |
1332 | *vectype = typeinfo_first; | |
1333 | ||
1334 | return error ? PARSE_FAIL : (ret_val << 2) | (nb_regs - 1); | |
1335 | } | |
1336 | ||
1337 | /* Directives: register aliases. */ | |
1338 | ||
1339 | static reg_entry * | |
1340 | insert_reg_alias (char *str, int number, aarch64_reg_type type) | |
1341 | { | |
1342 | reg_entry *new; | |
1343 | const char *name; | |
1344 | ||
629310ab | 1345 | if ((new = str_hash_find (aarch64_reg_hsh, str)) != 0) |
a06ea964 NC |
1346 | { |
1347 | if (new->builtin) | |
1348 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), | |
1349 | str); | |
1350 | ||
1351 | /* Only warn about a redefinition if it's not defined as the | |
1352 | same register. */ | |
1353 | else if (new->number != number || new->type != type) | |
1354 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
1355 | ||
1356 | return NULL; | |
1357 | } | |
1358 | ||
1359 | name = xstrdup (str); | |
add39d23 | 1360 | new = XNEW (reg_entry); |
a06ea964 NC |
1361 | |
1362 | new->name = name; | |
1363 | new->number = number; | |
1364 | new->type = type; | |
1365 | new->builtin = FALSE; | |
1366 | ||
fe0e921f | 1367 | str_hash_insert (aarch64_reg_hsh, name, new, 0); |
a06ea964 NC |
1368 | |
1369 | return new; | |
1370 | } | |
1371 | ||
1372 | /* Look for the .req directive. This is of the form: | |
1373 | ||
1374 | new_register_name .req existing_register_name | |
1375 | ||
1376 | If we find one, or if it looks sufficiently like one that we want to | |
1377 | handle any error here, return TRUE. Otherwise return FALSE. */ | |
1378 | ||
1379 | static bfd_boolean | |
1380 | create_register_alias (char *newname, char *p) | |
1381 | { | |
1382 | const reg_entry *old; | |
1383 | char *oldname, *nbuf; | |
1384 | size_t nlen; | |
1385 | ||
1386 | /* The input scrubber ensures that whitespace after the mnemonic is | |
1387 | collapsed to single spaces. */ | |
1388 | oldname = p; | |
1389 | if (strncmp (oldname, " .req ", 6) != 0) | |
1390 | return FALSE; | |
1391 | ||
1392 | oldname += 6; | |
1393 | if (*oldname == '\0') | |
1394 | return FALSE; | |
1395 | ||
629310ab | 1396 | old = str_hash_find (aarch64_reg_hsh, oldname); |
a06ea964 NC |
1397 | if (!old) |
1398 | { | |
1399 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); | |
1400 | return TRUE; | |
1401 | } | |
1402 | ||
1403 | /* If TC_CASE_SENSITIVE is defined, then newname already points to | |
1404 | the desired alias name, and p points to its end. If not, then | |
1405 | the desired alias name is in the global original_case_string. */ | |
1406 | #ifdef TC_CASE_SENSITIVE | |
1407 | nlen = p - newname; | |
1408 | #else | |
1409 | newname = original_case_string; | |
1410 | nlen = strlen (newname); | |
1411 | #endif | |
1412 | ||
29a2809e | 1413 | nbuf = xmemdup0 (newname, nlen); |
a06ea964 NC |
1414 | |
1415 | /* Create aliases under the new name as stated; an all-lowercase | |
1416 | version of the new name; and an all-uppercase version of the new | |
1417 | name. */ | |
1418 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) | |
1419 | { | |
1420 | for (p = nbuf; *p; p++) | |
1421 | *p = TOUPPER (*p); | |
1422 | ||
1423 | if (strncmp (nbuf, newname, nlen)) | |
1424 | { | |
1425 | /* If this attempt to create an additional alias fails, do not bother | |
1426 | trying to create the all-lower case alias. We will fail and issue | |
1427 | a second, duplicate error message. This situation arises when the | |
1428 | programmer does something like: | |
1429 | foo .req r0 | |
1430 | Foo .req r1 | |
1431 | The second .req creates the "Foo" alias but then fails to create | |
1432 | the artificial FOO alias because it has already been created by the | |
1433 | first .req. */ | |
1434 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
e1fa0163 NC |
1435 | { |
1436 | free (nbuf); | |
1437 | return TRUE; | |
1438 | } | |
a06ea964 NC |
1439 | } |
1440 | ||
1441 | for (p = nbuf; *p; p++) | |
1442 | *p = TOLOWER (*p); | |
1443 | ||
1444 | if (strncmp (nbuf, newname, nlen)) | |
1445 | insert_reg_alias (nbuf, old->number, old->type); | |
1446 | } | |
1447 | ||
e1fa0163 | 1448 | free (nbuf); |
a06ea964 NC |
1449 | return TRUE; |
1450 | } | |
1451 | ||
1452 | /* Should never be called, as .req goes between the alias and the | |
1453 | register name, not at the beginning of the line. */ | |
1454 | static void | |
1455 | s_req (int a ATTRIBUTE_UNUSED) | |
1456 | { | |
1457 | as_bad (_("invalid syntax for .req directive")); | |
1458 | } | |
1459 | ||
1460 | /* The .unreq directive deletes an alias which was previously defined | |
1461 | by .req. For example: | |
1462 | ||
1463 | my_alias .req r11 | |
1464 | .unreq my_alias */ | |
1465 | ||
1466 | static void | |
1467 | s_unreq (int a ATTRIBUTE_UNUSED) | |
1468 | { | |
1469 | char *name; | |
1470 | char saved_char; | |
1471 | ||
1472 | name = input_line_pointer; | |
1473 | ||
1474 | while (*input_line_pointer != 0 | |
1475 | && *input_line_pointer != ' ' && *input_line_pointer != '\n') | |
1476 | ++input_line_pointer; | |
1477 | ||
1478 | saved_char = *input_line_pointer; | |
1479 | *input_line_pointer = 0; | |
1480 | ||
1481 | if (!*name) | |
1482 | as_bad (_("invalid syntax for .unreq directive")); | |
1483 | else | |
1484 | { | |
629310ab | 1485 | reg_entry *reg = str_hash_find (aarch64_reg_hsh, name); |
a06ea964 NC |
1486 | |
1487 | if (!reg) | |
1488 | as_bad (_("unknown register alias '%s'"), name); | |
1489 | else if (reg->builtin) | |
1490 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
1491 | name); | |
1492 | else | |
1493 | { | |
1494 | char *p; | |
1495 | char *nbuf; | |
1496 | ||
629310ab | 1497 | str_hash_delete (aarch64_reg_hsh, name); |
a06ea964 NC |
1498 | free ((char *) reg->name); |
1499 | free (reg); | |
1500 | ||
1501 | /* Also locate the all upper case and all lower case versions. | |
1502 | Do not complain if we cannot find one or the other as it | |
1503 | was probably deleted above. */ | |
1504 | ||
1505 | nbuf = strdup (name); | |
1506 | for (p = nbuf; *p; p++) | |
1507 | *p = TOUPPER (*p); | |
629310ab | 1508 | reg = str_hash_find (aarch64_reg_hsh, nbuf); |
a06ea964 NC |
1509 | if (reg) |
1510 | { | |
629310ab | 1511 | str_hash_delete (aarch64_reg_hsh, nbuf); |
a06ea964 NC |
1512 | free ((char *) reg->name); |
1513 | free (reg); | |
1514 | } | |
1515 | ||
1516 | for (p = nbuf; *p; p++) | |
1517 | *p = TOLOWER (*p); | |
629310ab | 1518 | reg = str_hash_find (aarch64_reg_hsh, nbuf); |
a06ea964 NC |
1519 | if (reg) |
1520 | { | |
629310ab | 1521 | str_hash_delete (aarch64_reg_hsh, nbuf); |
a06ea964 NC |
1522 | free ((char *) reg->name); |
1523 | free (reg); | |
1524 | } | |
1525 | ||
1526 | free (nbuf); | |
1527 | } | |
1528 | } | |
1529 | ||
1530 | *input_line_pointer = saved_char; | |
1531 | demand_empty_rest_of_line (); | |
1532 | } | |
1533 | ||
1534 | /* Directives: Instruction set selection. */ | |
1535 | ||
1536 | #ifdef OBJ_ELF | |
1537 | /* This code is to handle mapping symbols as defined in the ARM AArch64 ELF | |
1538 | spec. (See "Mapping symbols", section 4.5.4, ARM AAELF64 version 0.05). | |
1539 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
1540 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
1541 | ||
1542 | /* Create a new mapping symbol for the transition to STATE. */ | |
1543 | ||
1544 | static void | |
1545 | make_mapping_symbol (enum mstate state, valueT value, fragS * frag) | |
1546 | { | |
1547 | symbolS *symbolP; | |
1548 | const char *symname; | |
1549 | int type; | |
1550 | ||
1551 | switch (state) | |
1552 | { | |
1553 | case MAP_DATA: | |
1554 | symname = "$d"; | |
1555 | type = BSF_NO_FLAGS; | |
1556 | break; | |
1557 | case MAP_INSN: | |
1558 | symname = "$x"; | |
1559 | type = BSF_NO_FLAGS; | |
1560 | break; | |
3979cf50 SP |
1561 | case MAP_C64: |
1562 | symname = "$c"; | |
1563 | type = BSF_NO_FLAGS; | |
1564 | break; | |
a06ea964 NC |
1565 | default: |
1566 | abort (); | |
1567 | } | |
1568 | ||
e01e1cee | 1569 | symbolP = symbol_new (symname, now_seg, frag, value); |
a06ea964 NC |
1570 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
1571 | ||
8b21361b SP |
1572 | if (state == MAP_C64) |
1573 | AARCH64_SET_C64 (symbolP, 1); | |
1574 | else if (state == MAP_INSN) | |
1575 | AARCH64_SET_C64 (symbolP, 0); | |
1576 | ||
a06ea964 NC |
1577 | /* Save the mapping symbols for future reference. Also check that |
1578 | we do not place two mapping symbols at the same offset within a | |
1579 | frag. We'll handle overlap between frags in | |
1580 | check_mapping_symbols. | |
1581 | ||
1582 | If .fill or other data filling directive generates zero sized data, | |
1583 | the mapping symbol for the following code will have the same value | |
1584 | as the one generated for the data filling directive. In this case, | |
1585 | we replace the old symbol with the new one at the same address. */ | |
1586 | if (value == 0) | |
1587 | { | |
1588 | if (frag->tc_frag_data.first_map != NULL) | |
1589 | { | |
1590 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
1591 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, | |
1592 | &symbol_lastP); | |
1593 | } | |
1594 | frag->tc_frag_data.first_map = symbolP; | |
1595 | } | |
1596 | if (frag->tc_frag_data.last_map != NULL) | |
1597 | { | |
1598 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= | |
1599 | S_GET_VALUE (symbolP)); | |
1600 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) | |
1601 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, | |
1602 | &symbol_lastP); | |
1603 | } | |
1604 | frag->tc_frag_data.last_map = symbolP; | |
1605 | } | |
1606 | ||
1607 | /* We must sometimes convert a region marked as code to data during | |
1608 | code alignment, if an odd number of bytes have to be padded. The | |
1609 | code mapping symbol is pushed to an aligned address. */ | |
1610 | ||
1611 | static void | |
1612 | insert_data_mapping_symbol (enum mstate state, | |
1613 | valueT value, fragS * frag, offsetT bytes) | |
1614 | { | |
1615 | /* If there was already a mapping symbol, remove it. */ | |
1616 | if (frag->tc_frag_data.last_map != NULL | |
1617 | && S_GET_VALUE (frag->tc_frag_data.last_map) == | |
1618 | frag->fr_address + value) | |
1619 | { | |
1620 | symbolS *symp = frag->tc_frag_data.last_map; | |
1621 | ||
1622 | if (value == 0) | |
1623 | { | |
1624 | know (frag->tc_frag_data.first_map == symp); | |
1625 | frag->tc_frag_data.first_map = NULL; | |
1626 | } | |
1627 | frag->tc_frag_data.last_map = NULL; | |
1628 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
1629 | } | |
1630 | ||
1631 | make_mapping_symbol (MAP_DATA, value, frag); | |
1632 | make_mapping_symbol (state, value + bytes, frag); | |
1633 | } | |
1634 | ||
1635 | static void mapping_state_2 (enum mstate state, int max_chars); | |
1636 | ||
1637 | /* Set the mapping state to STATE. Only call this when about to | |
1638 | emit some STATE bytes to the file. */ | |
1639 | ||
1640 | void | |
1641 | mapping_state (enum mstate state) | |
1642 | { | |
1643 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; | |
1644 | ||
3979cf50 | 1645 | if (state == MAP_CUR_INSN) |
a578ef7e JW |
1646 | /* AArch64 instructions require 4-byte alignment. When emitting |
1647 | instructions into any section, record the appropriate section | |
1648 | alignment. */ | |
1649 | record_alignment (now_seg, 2); | |
1650 | ||
448eb63d RL |
1651 | if (mapstate == state) |
1652 | /* The mapping symbol has already been emitted. | |
1653 | There is nothing else to do. */ | |
1654 | return; | |
1655 | ||
c1baaddf | 1656 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
a97902de RL |
1657 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA) && !subseg_text_p (now_seg)) |
1658 | /* Emit MAP_DATA within executable section in order. Otherwise, it will be | |
c1baaddf | 1659 | evaluated later in the next else. */ |
a06ea964 | 1660 | return; |
3979cf50 | 1661 | else if (TRANSITION (MAP_UNDEFINED, MAP_CUR_INSN)) |
c1baaddf RL |
1662 | { |
1663 | /* Only add the symbol if the offset is > 0: | |
1664 | if we're at the first frag, check it's size > 0; | |
1665 | if we're not at the first frag, then for sure | |
1666 | the offset is > 0. */ | |
1667 | struct frag *const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
1668 | const int add_symbol = (frag_now != frag_first) | |
1669 | || (frag_now_fix () > 0); | |
1670 | ||
1671 | if (add_symbol) | |
1672 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
1673 | } | |
1674 | #undef TRANSITION | |
a06ea964 NC |
1675 | |
1676 | mapping_state_2 (state, 0); | |
a06ea964 NC |
1677 | } |
1678 | ||
1679 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
1680 | allocated. Put the mapping symbol that far back. */ | |
1681 | ||
1682 | static void | |
1683 | mapping_state_2 (enum mstate state, int max_chars) | |
1684 | { | |
1685 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; | |
1686 | ||
1687 | if (!SEG_NORMAL (now_seg)) | |
1688 | return; | |
1689 | ||
1690 | if (mapstate == state) | |
1691 | /* The mapping symbol has already been emitted. | |
1692 | There is nothing else to do. */ | |
1693 | return; | |
1694 | ||
1695 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; | |
1696 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
1697 | } | |
1698 | #else | |
1699 | #define mapping_state(x) /* nothing */ | |
1700 | #define mapping_state_2(x, y) /* nothing */ | |
1701 | #endif | |
1702 | ||
1703 | /* Directives: sectioning and alignment. */ | |
1704 | ||
1705 | static void | |
1706 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
1707 | { | |
1708 | /* We don't support putting frags in the BSS segment, we fake it by | |
1709 | marking in_bss, then looking at s_skip for clues. */ | |
1710 | subseg_set (bss_section, 0); | |
1711 | demand_empty_rest_of_line (); | |
1712 | mapping_state (MAP_DATA); | |
1713 | } | |
1714 | ||
1715 | static void | |
1716 | s_even (int ignore ATTRIBUTE_UNUSED) | |
1717 | { | |
1718 | /* Never make frag if expect extra pass. */ | |
1719 | if (!need_pass_2) | |
1720 | frag_align (1, 0, 0); | |
1721 | ||
1722 | record_alignment (now_seg, 1); | |
1723 | ||
1724 | demand_empty_rest_of_line (); | |
1725 | } | |
1726 | ||
1727 | /* Directives: Literal pools. */ | |
1728 | ||
1729 | static literal_pool * | |
1730 | find_literal_pool (int size) | |
1731 | { | |
1732 | literal_pool *pool; | |
1733 | ||
1734 | for (pool = list_of_pools; pool != NULL; pool = pool->next) | |
1735 | { | |
1736 | if (pool->section == now_seg | |
1737 | && pool->sub_section == now_subseg && pool->size == size) | |
1738 | break; | |
1739 | } | |
1740 | ||
1741 | return pool; | |
1742 | } | |
1743 | ||
1744 | static literal_pool * | |
1745 | find_or_make_literal_pool (int size) | |
1746 | { | |
1747 | /* Next literal pool ID number. */ | |
1748 | static unsigned int latest_pool_num = 1; | |
1749 | literal_pool *pool; | |
1750 | ||
1751 | pool = find_literal_pool (size); | |
1752 | ||
1753 | if (pool == NULL) | |
1754 | { | |
1755 | /* Create a new pool. */ | |
add39d23 | 1756 | pool = XNEW (literal_pool); |
a06ea964 NC |
1757 | if (!pool) |
1758 | return NULL; | |
1759 | ||
1760 | /* Currently we always put the literal pool in the current text | |
1761 | section. If we were generating "small" model code where we | |
1762 | knew that all code and initialised data was within 1MB then | |
1763 | we could output literals to mergeable, read-only data | |
1764 | sections. */ | |
1765 | ||
1766 | pool->next_free_entry = 0; | |
1767 | pool->section = now_seg; | |
1768 | pool->sub_section = now_subseg; | |
1769 | pool->size = size; | |
1770 | pool->next = list_of_pools; | |
1771 | pool->symbol = NULL; | |
1772 | ||
1773 | /* Add it to the list. */ | |
1774 | list_of_pools = pool; | |
1775 | } | |
1776 | ||
1777 | /* New pools, and emptied pools, will have a NULL symbol. */ | |
1778 | if (pool->symbol == NULL) | |
1779 | { | |
1780 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, | |
e01e1cee | 1781 | &zero_address_frag, 0); |
a06ea964 NC |
1782 | pool->id = latest_pool_num++; |
1783 | } | |
1784 | ||
1785 | /* Done. */ | |
1786 | return pool; | |
1787 | } | |
1788 | ||
1789 | /* Add the literal of size SIZE in *EXP to the relevant literal pool. | |
1790 | Return TRUE on success, otherwise return FALSE. */ | |
1791 | static bfd_boolean | |
1792 | add_to_lit_pool (expressionS *exp, int size) | |
1793 | { | |
1794 | literal_pool *pool; | |
1795 | unsigned int entry; | |
1796 | ||
1797 | pool = find_or_make_literal_pool (size); | |
1798 | ||
1799 | /* Check if this literal value is already in the pool. */ | |
1800 | for (entry = 0; entry < pool->next_free_entry; entry++) | |
1801 | { | |
55d9b4c1 NC |
1802 | expressionS * litexp = & pool->literals[entry].exp; |
1803 | ||
1804 | if ((litexp->X_op == exp->X_op) | |
a06ea964 | 1805 | && (exp->X_op == O_constant) |
55d9b4c1 NC |
1806 | && (litexp->X_add_number == exp->X_add_number) |
1807 | && (litexp->X_unsigned == exp->X_unsigned)) | |
a06ea964 NC |
1808 | break; |
1809 | ||
55d9b4c1 | 1810 | if ((litexp->X_op == exp->X_op) |
a06ea964 | 1811 | && (exp->X_op == O_symbol) |
55d9b4c1 NC |
1812 | && (litexp->X_add_number == exp->X_add_number) |
1813 | && (litexp->X_add_symbol == exp->X_add_symbol) | |
1814 | && (litexp->X_op_symbol == exp->X_op_symbol)) | |
a06ea964 NC |
1815 | break; |
1816 | } | |
1817 | ||
1818 | /* Do we need to create a new entry? */ | |
1819 | if (entry == pool->next_free_entry) | |
1820 | { | |
1821 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
1822 | { | |
1823 | set_syntax_error (_("literal pool overflow")); | |
1824 | return FALSE; | |
1825 | } | |
1826 | ||
55d9b4c1 | 1827 | pool->literals[entry].exp = *exp; |
a06ea964 | 1828 | pool->next_free_entry += 1; |
55d9b4c1 NC |
1829 | if (exp->X_op == O_big) |
1830 | { | |
1831 | /* PR 16688: Bignums are held in a single global array. We must | |
1832 | copy and preserve that value now, before it is overwritten. */ | |
add39d23 TS |
1833 | pool->literals[entry].bignum = XNEWVEC (LITTLENUM_TYPE, |
1834 | exp->X_add_number); | |
55d9b4c1 NC |
1835 | memcpy (pool->literals[entry].bignum, generic_bignum, |
1836 | CHARS_PER_LITTLENUM * exp->X_add_number); | |
1837 | } | |
1838 | else | |
1839 | pool->literals[entry].bignum = NULL; | |
a06ea964 NC |
1840 | } |
1841 | ||
1842 | exp->X_op = O_symbol; | |
1843 | exp->X_add_number = ((int) entry) * size; | |
1844 | exp->X_add_symbol = pool->symbol; | |
1845 | ||
1846 | return TRUE; | |
1847 | } | |
1848 | ||
1849 | /* Can't use symbol_new here, so have to create a symbol and then at | |
33eaf5de | 1850 | a later date assign it a value. That's what these functions do. */ |
a06ea964 NC |
1851 | |
1852 | static void | |
1853 | symbol_locate (symbolS * symbolP, | |
1854 | const char *name,/* It is copied, the caller can modify. */ | |
1855 | segT segment, /* Segment identifier (SEG_<something>). */ | |
1856 | valueT valu, /* Symbol value. */ | |
1857 | fragS * frag) /* Associated fragment. */ | |
1858 | { | |
e57e6ddc | 1859 | size_t name_length; |
a06ea964 NC |
1860 | char *preserved_copy_of_name; |
1861 | ||
1862 | name_length = strlen (name) + 1; /* +1 for \0. */ | |
1863 | obstack_grow (¬es, name, name_length); | |
1864 | preserved_copy_of_name = obstack_finish (¬es); | |
1865 | ||
1866 | #ifdef tc_canonicalize_symbol_name | |
1867 | preserved_copy_of_name = | |
1868 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
1869 | #endif | |
1870 | ||
1871 | S_SET_NAME (symbolP, preserved_copy_of_name); | |
1872 | ||
1873 | S_SET_SEGMENT (symbolP, segment); | |
1874 | S_SET_VALUE (symbolP, valu); | |
1875 | symbol_clear_list_pointers (symbolP); | |
1876 | ||
1877 | symbol_set_frag (symbolP, frag); | |
1878 | ||
1879 | /* Link to end of symbol chain. */ | |
1880 | { | |
1881 | extern int symbol_table_frozen; | |
1882 | ||
1883 | if (symbol_table_frozen) | |
1884 | abort (); | |
1885 | } | |
1886 | ||
1887 | symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
1888 | ||
1889 | obj_symbol_new_hook (symbolP); | |
1890 | ||
1891 | #ifdef tc_symbol_new_hook | |
1892 | tc_symbol_new_hook (symbolP); | |
1893 | #endif | |
1894 | ||
1895 | #ifdef DEBUG_SYMS | |
1896 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
1897 | #endif /* DEBUG_SYMS */ | |
1898 | } | |
1899 | ||
1900 | ||
1901 | static void | |
1902 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
1903 | { | |
1904 | unsigned int entry; | |
1905 | literal_pool *pool; | |
1906 | char sym_name[20]; | |
1907 | int align; | |
1908 | ||
67a32447 | 1909 | for (align = 2; align <= 4; align++) |
a06ea964 NC |
1910 | { |
1911 | int size = 1 << align; | |
1912 | ||
1913 | pool = find_literal_pool (size); | |
1914 | if (pool == NULL || pool->symbol == NULL || pool->next_free_entry == 0) | |
1915 | continue; | |
1916 | ||
a06ea964 NC |
1917 | /* Align pool as you have word accesses. |
1918 | Only make a frag if we have to. */ | |
1919 | if (!need_pass_2) | |
1920 | frag_align (align, 0, 0); | |
1921 | ||
7ea12e5c NC |
1922 | mapping_state (MAP_DATA); |
1923 | ||
a06ea964 NC |
1924 | record_alignment (now_seg, align); |
1925 | ||
1926 | sprintf (sym_name, "$$lit_\002%x", pool->id); | |
1927 | ||
1928 | symbol_locate (pool->symbol, sym_name, now_seg, | |
1929 | (valueT) frag_now_fix (), frag_now); | |
1930 | symbol_table_insert (pool->symbol); | |
1931 | ||
1932 | for (entry = 0; entry < pool->next_free_entry; entry++) | |
55d9b4c1 NC |
1933 | { |
1934 | expressionS * exp = & pool->literals[entry].exp; | |
1935 | ||
1936 | if (exp->X_op == O_big) | |
1937 | { | |
1938 | /* PR 16688: Restore the global bignum value. */ | |
1939 | gas_assert (pool->literals[entry].bignum != NULL); | |
1940 | memcpy (generic_bignum, pool->literals[entry].bignum, | |
1941 | CHARS_PER_LITTLENUM * exp->X_add_number); | |
1942 | } | |
1943 | ||
1944 | /* First output the expression in the instruction to the pool. */ | |
1945 | emit_expr (exp, size); /* .word|.xword */ | |
1946 | ||
1947 | if (exp->X_op == O_big) | |
1948 | { | |
1949 | free (pool->literals[entry].bignum); | |
1950 | pool->literals[entry].bignum = NULL; | |
1951 | } | |
1952 | } | |
a06ea964 NC |
1953 | |
1954 | /* Mark the pool as empty. */ | |
1955 | pool->next_free_entry = 0; | |
1956 | pool->symbol = NULL; | |
1957 | } | |
1958 | } | |
1959 | ||
1960 | #ifdef OBJ_ELF | |
1961 | /* Forward declarations for functions below, in the MD interface | |
1962 | section. */ | |
1963 | static fixS *fix_new_aarch64 (fragS *, int, short, expressionS *, int, int); | |
1964 | static struct reloc_table_entry * find_reloc_table_entry (char **); | |
1965 | ||
1966 | /* Directives: Data. */ | |
1967 | /* N.B. the support for relocation suffix in this directive needs to be | |
1968 | implemented properly. */ | |
1969 | ||
1970 | static void | |
1971 | s_aarch64_elf_cons (int nbytes) | |
1972 | { | |
1973 | expressionS exp; | |
1974 | ||
1975 | #ifdef md_flush_pending_output | |
1976 | md_flush_pending_output (); | |
1977 | #endif | |
1978 | ||
1979 | if (is_it_end_of_statement ()) | |
1980 | { | |
1981 | demand_empty_rest_of_line (); | |
1982 | return; | |
1983 | } | |
1984 | ||
1985 | #ifdef md_cons_align | |
1986 | md_cons_align (nbytes); | |
1987 | #endif | |
1988 | ||
1989 | mapping_state (MAP_DATA); | |
1990 | do | |
1991 | { | |
1992 | struct reloc_table_entry *reloc; | |
1993 | ||
1994 | expression (&exp); | |
1995 | ||
1996 | if (exp.X_op != O_symbol) | |
1997 | emit_expr (&exp, (unsigned int) nbytes); | |
1998 | else | |
1999 | { | |
2000 | skip_past_char (&input_line_pointer, '#'); | |
2001 | if (skip_past_char (&input_line_pointer, ':')) | |
2002 | { | |
2003 | reloc = find_reloc_table_entry (&input_line_pointer); | |
2004 | if (reloc == NULL) | |
2005 | as_bad (_("unrecognized relocation suffix")); | |
2006 | else | |
2007 | as_bad (_("unimplemented relocation suffix")); | |
2008 | ignore_rest_of_line (); | |
2009 | return; | |
2010 | } | |
2011 | else | |
2012 | emit_expr (&exp, (unsigned int) nbytes); | |
2013 | } | |
2014 | } | |
2015 | while (*input_line_pointer++ == ','); | |
2016 | ||
2017 | /* Put terminator back into stream. */ | |
2018 | input_line_pointer--; | |
2019 | demand_empty_rest_of_line (); | |
2020 | } | |
2021 | ||
f166ae01 SN |
2022 | /* Mark symbol that it follows a variant PCS convention. */ |
2023 | ||
2024 | static void | |
2025 | s_variant_pcs (int ignored ATTRIBUTE_UNUSED) | |
2026 | { | |
2027 | char *name; | |
2028 | char c; | |
2029 | symbolS *sym; | |
2030 | asymbol *bfdsym; | |
2031 | elf_symbol_type *elfsym; | |
2032 | ||
2033 | c = get_symbol_name (&name); | |
2034 | if (!*name) | |
2035 | as_bad (_("Missing symbol name in directive")); | |
2036 | sym = symbol_find_or_make (name); | |
2037 | restore_line_pointer (c); | |
2038 | demand_empty_rest_of_line (); | |
2039 | bfdsym = symbol_get_bfdsym (sym); | |
c1229f84 | 2040 | elfsym = elf_symbol_from (bfdsym); |
f166ae01 SN |
2041 | gas_assert (elfsym); |
2042 | elfsym->internal_elf_sym.st_other |= STO_AARCH64_VARIANT_PCS; | |
2043 | } | |
a06ea964 NC |
2044 | #endif /* OBJ_ELF */ |
2045 | ||
2046 | /* Output a 32-bit word, but mark as an instruction. */ | |
2047 | ||
2048 | static void | |
2049 | s_aarch64_inst (int ignored ATTRIBUTE_UNUSED) | |
2050 | { | |
2051 | expressionS exp; | |
2052 | ||
2053 | #ifdef md_flush_pending_output | |
2054 | md_flush_pending_output (); | |
2055 | #endif | |
2056 | ||
2057 | if (is_it_end_of_statement ()) | |
2058 | { | |
2059 | demand_empty_rest_of_line (); | |
2060 | return; | |
2061 | } | |
2062 | ||
a97902de | 2063 | /* Sections are assumed to start aligned. In executable section, there is no |
c1baaddf | 2064 | MAP_DATA symbol pending. So we only align the address during |
3979cf50 | 2065 | MAP_DATA --> MAP_CUR_INSN transition. |
eb9d6cc9 | 2066 | For other sections, this is not guaranteed. */ |
c1baaddf | 2067 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
eb9d6cc9 | 2068 | if (!need_pass_2 && subseg_text_p (now_seg) && mapstate == MAP_DATA) |
a06ea964 | 2069 | frag_align_code (2, 0); |
c1baaddf | 2070 | |
a06ea964 | 2071 | #ifdef OBJ_ELF |
3979cf50 | 2072 | mapping_state (MAP_CUR_INSN); |
a06ea964 NC |
2073 | #endif |
2074 | ||
2075 | do | |
2076 | { | |
2077 | expression (&exp); | |
2078 | if (exp.X_op != O_constant) | |
2079 | { | |
2080 | as_bad (_("constant expression required")); | |
2081 | ignore_rest_of_line (); | |
2082 | return; | |
2083 | } | |
2084 | ||
2085 | if (target_big_endian) | |
2086 | { | |
2087 | unsigned int val = exp.X_add_number; | |
2088 | exp.X_add_number = SWAP_32 (val); | |
2089 | } | |
2090 | emit_expr (&exp, 4); | |
2091 | } | |
2092 | while (*input_line_pointer++ == ','); | |
2093 | ||
2094 | /* Put terminator back into stream. */ | |
2095 | input_line_pointer--; | |
2096 | demand_empty_rest_of_line (); | |
2097 | } | |
2098 | ||
3a67e1a6 ST |
2099 | static void |
2100 | s_aarch64_cfi_b_key_frame (int ignored ATTRIBUTE_UNUSED) | |
2101 | { | |
2102 | demand_empty_rest_of_line (); | |
2103 | struct fde_entry *fde = frchain_now->frch_cfi_data->cur_fde_data; | |
2104 | fde->pauth_key = AARCH64_PAUTH_KEY_B; | |
2105 | } | |
2106 | ||
a06ea964 | 2107 | #ifdef OBJ_ELF |
43a357f9 RL |
2108 | /* Emit BFD_RELOC_AARCH64_TLSDESC_ADD on the next ADD instruction. */ |
2109 | ||
2110 | static void | |
2111 | s_tlsdescadd (int ignored ATTRIBUTE_UNUSED) | |
2112 | { | |
2113 | expressionS exp; | |
2114 | ||
2115 | expression (&exp); | |
2116 | frag_grow (4); | |
2117 | fix_new_aarch64 (frag_now, frag_more (0) - frag_now->fr_literal, 4, &exp, 0, | |
2118 | BFD_RELOC_AARCH64_TLSDESC_ADD); | |
2119 | ||
2120 | demand_empty_rest_of_line (); | |
2121 | } | |
2122 | ||
a06ea964 NC |
2123 | /* Emit BFD_RELOC_AARCH64_TLSDESC_CALL on the next BLR instruction. */ |
2124 | ||
2125 | static void | |
2126 | s_tlsdesccall (int ignored ATTRIBUTE_UNUSED) | |
2127 | { | |
2128 | expressionS exp; | |
2129 | ||
2130 | /* Since we're just labelling the code, there's no need to define a | |
2131 | mapping symbol. */ | |
2132 | expression (&exp); | |
2133 | /* Make sure there is enough room in this frag for the following | |
2134 | blr. This trick only works if the blr follows immediately after | |
2135 | the .tlsdesc directive. */ | |
2136 | frag_grow (4); | |
2137 | fix_new_aarch64 (frag_now, frag_more (0) - frag_now->fr_literal, 4, &exp, 0, | |
2138 | BFD_RELOC_AARCH64_TLSDESC_CALL); | |
2139 | ||
2140 | demand_empty_rest_of_line (); | |
2141 | } | |
43a357f9 RL |
2142 | |
2143 | /* Emit BFD_RELOC_AARCH64_TLSDESC_LDR on the next LDR instruction. */ | |
2144 | ||
2145 | static void | |
2146 | s_tlsdescldr (int ignored ATTRIBUTE_UNUSED) | |
2147 | { | |
2148 | expressionS exp; | |
2149 | ||
2150 | expression (&exp); | |
2151 | frag_grow (4); | |
2152 | fix_new_aarch64 (frag_now, frag_more (0) - frag_now->fr_literal, 4, &exp, 0, | |
2153 | BFD_RELOC_AARCH64_TLSDESC_LDR); | |
2154 | ||
2155 | demand_empty_rest_of_line (); | |
2156 | } | |
a06ea964 NC |
2157 | #endif /* OBJ_ELF */ |
2158 | ||
2159 | static void s_aarch64_arch (int); | |
2160 | static void s_aarch64_cpu (int); | |
ae527cd8 | 2161 | static void s_aarch64_arch_extension (int); |
a06ea964 NC |
2162 | |
2163 | /* This table describes all the machine specific pseudo-ops the assembler | |
2164 | has to support. The fields are: | |
2165 | pseudo-op name without dot | |
2166 | function to call to execute this pseudo-op | |
2167 | Integer arg to pass to the function. */ | |
2168 | ||
2169 | const pseudo_typeS md_pseudo_table[] = { | |
2170 | /* Never called because '.req' does not start a line. */ | |
2171 | {"req", s_req, 0}, | |
2172 | {"unreq", s_unreq, 0}, | |
2173 | {"bss", s_bss, 0}, | |
2174 | {"even", s_even, 0}, | |
2175 | {"ltorg", s_ltorg, 0}, | |
2176 | {"pool", s_ltorg, 0}, | |
2177 | {"cpu", s_aarch64_cpu, 0}, | |
2178 | {"arch", s_aarch64_arch, 0}, | |
ae527cd8 | 2179 | {"arch_extension", s_aarch64_arch_extension, 0}, |
a06ea964 | 2180 | {"inst", s_aarch64_inst, 0}, |
3a67e1a6 | 2181 | {"cfi_b_key_frame", s_aarch64_cfi_b_key_frame, 0}, |
a06ea964 | 2182 | #ifdef OBJ_ELF |
43a357f9 | 2183 | {"tlsdescadd", s_tlsdescadd, 0}, |
a06ea964 | 2184 | {"tlsdesccall", s_tlsdesccall, 0}, |
43a357f9 | 2185 | {"tlsdescldr", s_tlsdescldr, 0}, |
a06ea964 NC |
2186 | {"word", s_aarch64_elf_cons, 4}, |
2187 | {"long", s_aarch64_elf_cons, 4}, | |
2188 | {"xword", s_aarch64_elf_cons, 8}, | |
2189 | {"dword", s_aarch64_elf_cons, 8}, | |
f166ae01 | 2190 | {"variant_pcs", s_variant_pcs, 0}, |
a06ea964 | 2191 | #endif |
b20d3859 | 2192 | {"float16", float_cons, 'h'}, |
eb5bbc48 | 2193 | {"bfloat16", float_cons, 'b'}, |
a06ea964 NC |
2194 | {0, 0, 0} |
2195 | }; | |
2196 | \f | |
2197 | ||
2198 | /* Check whether STR points to a register name followed by a comma or the | |
2199 | end of line; REG_TYPE indicates which register types are checked | |
2200 | against. Return TRUE if STR is such a register name; otherwise return | |
2201 | FALSE. The function does not intend to produce any diagnostics, but since | |
2202 | the register parser aarch64_reg_parse, which is called by this function, | |
2203 | does produce diagnostics, we call clear_error to clear any diagnostics | |
2204 | that may be generated by aarch64_reg_parse. | |
2205 | Also, the function returns FALSE directly if there is any user error | |
2206 | present at the function entry. This prevents the existing diagnostics | |
2207 | state from being spoiled. | |
2208 | The function currently serves parse_constant_immediate and | |
2209 | parse_big_immediate only. */ | |
2210 | static bfd_boolean | |
2211 | reg_name_p (char *str, aarch64_reg_type reg_type) | |
2212 | { | |
2213 | int reg; | |
2214 | ||
2215 | /* Prevent the diagnostics state from being spoiled. */ | |
2216 | if (error_p ()) | |
2217 | return FALSE; | |
2218 | ||
2219 | reg = aarch64_reg_parse (&str, reg_type, NULL, NULL); | |
2220 | ||
2221 | /* Clear the parsing error that may be set by the reg parser. */ | |
2222 | clear_error (); | |
2223 | ||
2224 | if (reg == PARSE_FAIL) | |
2225 | return FALSE; | |
2226 | ||
2227 | skip_whitespace (str); | |
f405494f | 2228 | if (*str == ',' || is_end_of_line[(unsigned char) *str]) |
a06ea964 NC |
2229 | return TRUE; |
2230 | ||
2231 | return FALSE; | |
2232 | } | |
2233 | ||
2234 | /* Parser functions used exclusively in instruction operands. */ | |
2235 | ||
2236 | /* Parse an immediate expression which may not be constant. | |
2237 | ||
2238 | To prevent the expression parser from pushing a register name | |
2239 | into the symbol table as an undefined symbol, firstly a check is | |
1799c0d0 RS |
2240 | done to find out whether STR is a register of type REG_TYPE followed |
2241 | by a comma or the end of line. Return FALSE if STR is such a string. */ | |
a06ea964 NC |
2242 | |
2243 | static bfd_boolean | |
1799c0d0 RS |
2244 | parse_immediate_expression (char **str, expressionS *exp, |
2245 | aarch64_reg_type reg_type) | |
a06ea964 | 2246 | { |
1799c0d0 | 2247 | if (reg_name_p (*str, reg_type)) |
a06ea964 NC |
2248 | { |
2249 | set_recoverable_error (_("immediate operand required")); | |
2250 | return FALSE; | |
2251 | } | |
2252 | ||
2253 | my_get_expression (exp, str, GE_OPT_PREFIX, 1); | |
2254 | ||
2255 | if (exp->X_op == O_absent) | |
2256 | { | |
2257 | set_fatal_syntax_error (_("missing immediate expression")); | |
2258 | return FALSE; | |
2259 | } | |
2260 | ||
2261 | return TRUE; | |
2262 | } | |
2263 | ||
2264 | /* Constant immediate-value read function for use in insn parsing. | |
2265 | STR points to the beginning of the immediate (with the optional | |
1799c0d0 RS |
2266 | leading #); *VAL receives the value. REG_TYPE says which register |
2267 | names should be treated as registers rather than as symbolic immediates. | |
a06ea964 NC |
2268 | |
2269 | Return TRUE on success; otherwise return FALSE. */ | |
2270 | ||
2271 | static bfd_boolean | |
1799c0d0 | 2272 | parse_constant_immediate (char **str, int64_t *val, aarch64_reg_type reg_type) |
a06ea964 NC |
2273 | { |
2274 | expressionS exp; | |
2275 | ||
1799c0d0 | 2276 | if (! parse_immediate_expression (str, &exp, reg_type)) |
a06ea964 NC |
2277 | return FALSE; |
2278 | ||
2279 | if (exp.X_op != O_constant) | |
2280 | { | |
2281 | set_syntax_error (_("constant expression required")); | |
2282 | return FALSE; | |
2283 | } | |
2284 | ||
2285 | *val = exp.X_add_number; | |
2286 | return TRUE; | |
2287 | } | |
2288 | ||
2289 | static uint32_t | |
2290 | encode_imm_float_bits (uint32_t imm) | |
2291 | { | |
2292 | return ((imm >> 19) & 0x7f) /* b[25:19] -> b[6:0] */ | |
2293 | | ((imm >> (31 - 7)) & 0x80); /* b[31] -> b[7] */ | |
2294 | } | |
2295 | ||
62b0d0d5 YZ |
2296 | /* Return TRUE if the single-precision floating-point value encoded in IMM |
2297 | can be expressed in the AArch64 8-bit signed floating-point format with | |
2298 | 3-bit exponent and normalized 4 bits of precision; in other words, the | |
2299 | floating-point value must be expressable as | |
2300 | (+/-) n / 16 * power (2, r) | |
2301 | where n and r are integers such that 16 <= n <=31 and -3 <= r <= 4. */ | |
2302 | ||
a06ea964 NC |
2303 | static bfd_boolean |
2304 | aarch64_imm_float_p (uint32_t imm) | |
2305 | { | |
62b0d0d5 YZ |
2306 | /* If a single-precision floating-point value has the following bit |
2307 | pattern, it can be expressed in the AArch64 8-bit floating-point | |
2308 | format: | |
2309 | ||
2310 | 3 32222222 2221111111111 | |
a06ea964 | 2311 | 1 09876543 21098765432109876543210 |
62b0d0d5 YZ |
2312 | n Eeeeeexx xxxx0000000000000000000 |
2313 | ||
2314 | where n, e and each x are either 0 or 1 independently, with | |
2315 | E == ~ e. */ | |
a06ea964 | 2316 | |
62b0d0d5 YZ |
2317 | uint32_t pattern; |
2318 | ||
2319 | /* Prepare the pattern for 'Eeeeee'. */ | |
2320 | if (((imm >> 30) & 0x1) == 0) | |
2321 | pattern = 0x3e000000; | |
a06ea964 | 2322 | else |
62b0d0d5 YZ |
2323 | pattern = 0x40000000; |
2324 | ||
2325 | return (imm & 0x7ffff) == 0 /* lower 19 bits are 0. */ | |
2326 | && ((imm & 0x7e000000) == pattern); /* bits 25 - 29 == ~ bit 30. */ | |
a06ea964 NC |
2327 | } |
2328 | ||
04a3379a RS |
2329 | /* Return TRUE if the IEEE double value encoded in IMM can be expressed |
2330 | as an IEEE float without any loss of precision. Store the value in | |
2331 | *FPWORD if so. */ | |
62b0d0d5 | 2332 | |
a06ea964 | 2333 | static bfd_boolean |
04a3379a | 2334 | can_convert_double_to_float (uint64_t imm, uint32_t *fpword) |
62b0d0d5 YZ |
2335 | { |
2336 | /* If a double-precision floating-point value has the following bit | |
04a3379a | 2337 | pattern, it can be expressed in a float: |
62b0d0d5 | 2338 | |
04a3379a RS |
2339 | 6 66655555555 5544 44444444 33333333 33222222 22221111 111111 |
2340 | 3 21098765432 1098 76543210 98765432 10987654 32109876 54321098 76543210 | |
2341 | n E~~~eeeeeee ssss ssssssss ssssssss SSS00000 00000000 00000000 00000000 | |
62b0d0d5 | 2342 | |
04a3379a RS |
2343 | -----------------------------> nEeeeeee esssssss ssssssss sssssSSS |
2344 | if Eeee_eeee != 1111_1111 | |
2345 | ||
2346 | where n, e, s and S are either 0 or 1 independently and where ~ is the | |
2347 | inverse of E. */ | |
62b0d0d5 YZ |
2348 | |
2349 | uint32_t pattern; | |
2350 | uint32_t high32 = imm >> 32; | |
04a3379a | 2351 | uint32_t low32 = imm; |
62b0d0d5 | 2352 | |
04a3379a RS |
2353 | /* Lower 29 bits need to be 0s. */ |
2354 | if ((imm & 0x1fffffff) != 0) | |
62b0d0d5 YZ |
2355 | return FALSE; |
2356 | ||
2357 | /* Prepare the pattern for 'Eeeeeeeee'. */ | |
2358 | if (((high32 >> 30) & 0x1) == 0) | |
04a3379a | 2359 | pattern = 0x38000000; |
62b0d0d5 YZ |
2360 | else |
2361 | pattern = 0x40000000; | |
2362 | ||
04a3379a RS |
2363 | /* Check E~~~. */ |
2364 | if ((high32 & 0x78000000) != pattern) | |
62b0d0d5 | 2365 | return FALSE; |
04a3379a RS |
2366 | |
2367 | /* Check Eeee_eeee != 1111_1111. */ | |
2368 | if ((high32 & 0x7ff00000) == 0x47f00000) | |
2369 | return FALSE; | |
2370 | ||
2371 | *fpword = ((high32 & 0xc0000000) /* 1 n bit and 1 E bit. */ | |
2372 | | ((high32 << 3) & 0x3ffffff8) /* 7 e and 20 s bits. */ | |
2373 | | (low32 >> 29)); /* 3 S bits. */ | |
2374 | return TRUE; | |
62b0d0d5 YZ |
2375 | } |
2376 | ||
165d4950 RS |
2377 | /* Return true if we should treat OPERAND as a double-precision |
2378 | floating-point operand rather than a single-precision one. */ | |
2379 | static bfd_boolean | |
2380 | double_precision_operand_p (const aarch64_opnd_info *operand) | |
2381 | { | |
2382 | /* Check for unsuffixed SVE registers, which are allowed | |
2383 | for LDR and STR but not in instructions that require an | |
2384 | immediate. We get better error messages if we arbitrarily | |
2385 | pick one size, parse the immediate normally, and then | |
2386 | report the match failure in the normal way. */ | |
2387 | return (operand->qualifier == AARCH64_OPND_QLF_NIL | |
2388 | || aarch64_get_qualifier_esize (operand->qualifier) == 8); | |
2389 | } | |
2390 | ||
62b0d0d5 YZ |
2391 | /* Parse a floating-point immediate. Return TRUE on success and return the |
2392 | value in *IMMED in the format of IEEE754 single-precision encoding. | |
2393 | *CCP points to the start of the string; DP_P is TRUE when the immediate | |
2394 | is expected to be in double-precision (N.B. this only matters when | |
1799c0d0 RS |
2395 | hexadecimal representation is involved). REG_TYPE says which register |
2396 | names should be treated as registers rather than as symbolic immediates. | |
62b0d0d5 | 2397 | |
874d7e6e RS |
2398 | This routine accepts any IEEE float; it is up to the callers to reject |
2399 | invalid ones. */ | |
62b0d0d5 YZ |
2400 | |
2401 | static bfd_boolean | |
1799c0d0 RS |
2402 | parse_aarch64_imm_float (char **ccp, int *immed, bfd_boolean dp_p, |
2403 | aarch64_reg_type reg_type) | |
a06ea964 NC |
2404 | { |
2405 | char *str = *ccp; | |
2406 | char *fpnum; | |
2407 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
62b0d0d5 YZ |
2408 | int64_t val = 0; |
2409 | unsigned fpword = 0; | |
2410 | bfd_boolean hex_p = FALSE; | |
a06ea964 NC |
2411 | |
2412 | skip_past_char (&str, '#'); | |
2413 | ||
a06ea964 NC |
2414 | fpnum = str; |
2415 | skip_whitespace (fpnum); | |
2416 | ||
2417 | if (strncmp (fpnum, "0x", 2) == 0) | |
62b0d0d5 YZ |
2418 | { |
2419 | /* Support the hexadecimal representation of the IEEE754 encoding. | |
2420 | Double-precision is expected when DP_P is TRUE, otherwise the | |
2421 | representation should be in single-precision. */ | |
1799c0d0 | 2422 | if (! parse_constant_immediate (&str, &val, reg_type)) |
62b0d0d5 YZ |
2423 | goto invalid_fp; |
2424 | ||
2425 | if (dp_p) | |
2426 | { | |
04a3379a | 2427 | if (!can_convert_double_to_float (val, &fpword)) |
62b0d0d5 YZ |
2428 | goto invalid_fp; |
2429 | } | |
2430 | else if ((uint64_t) val > 0xffffffff) | |
2431 | goto invalid_fp; | |
2432 | else | |
2433 | fpword = val; | |
2434 | ||
2435 | hex_p = TRUE; | |
2436 | } | |
66881839 TC |
2437 | else if (reg_name_p (str, reg_type)) |
2438 | { | |
2439 | set_recoverable_error (_("immediate operand required")); | |
2440 | return FALSE; | |
a06ea964 NC |
2441 | } |
2442 | ||
62b0d0d5 | 2443 | if (! hex_p) |
a06ea964 | 2444 | { |
a06ea964 NC |
2445 | int i; |
2446 | ||
62b0d0d5 YZ |
2447 | if ((str = atof_ieee (str, 's', words)) == NULL) |
2448 | goto invalid_fp; | |
2449 | ||
a06ea964 NC |
2450 | /* Our FP word must be 32 bits (single-precision FP). */ |
2451 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
2452 | { | |
2453 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
2454 | fpword |= words[i]; | |
2455 | } | |
62b0d0d5 | 2456 | } |
a06ea964 | 2457 | |
874d7e6e RS |
2458 | *immed = fpword; |
2459 | *ccp = str; | |
2460 | return TRUE; | |
a06ea964 | 2461 | |
dc1e8a47 | 2462 | invalid_fp: |
a06ea964 NC |
2463 | set_fatal_syntax_error (_("invalid floating-point constant")); |
2464 | return FALSE; | |
2465 | } | |
2466 | ||
2467 | /* Less-generic immediate-value read function with the possibility of loading | |
2468 | a big (64-bit) immediate, as required by AdvSIMD Modified immediate | |
2469 | instructions. | |
2470 | ||
2471 | To prevent the expression parser from pushing a register name into the | |
2472 | symbol table as an undefined symbol, a check is firstly done to find | |
1799c0d0 RS |
2473 | out whether STR is a register of type REG_TYPE followed by a comma or |
2474 | the end of line. Return FALSE if STR is such a register. */ | |
a06ea964 NC |
2475 | |
2476 | static bfd_boolean | |
1799c0d0 | 2477 | parse_big_immediate (char **str, int64_t *imm, aarch64_reg_type reg_type) |
a06ea964 NC |
2478 | { |
2479 | char *ptr = *str; | |
2480 | ||
1799c0d0 | 2481 | if (reg_name_p (ptr, reg_type)) |
a06ea964 NC |
2482 | { |
2483 | set_syntax_error (_("immediate operand required")); | |
2484 | return FALSE; | |
2485 | } | |
2486 | ||
2487 | my_get_expression (&inst.reloc.exp, &ptr, GE_OPT_PREFIX, 1); | |
2488 | ||
2489 | if (inst.reloc.exp.X_op == O_constant) | |
2490 | *imm = inst.reloc.exp.X_add_number; | |
2491 | ||
2492 | *str = ptr; | |
2493 | ||
2494 | return TRUE; | |
2495 | } | |
2496 | ||
2497 | /* Set operand IDX of the *INSTR that needs a GAS internal fixup. | |
2498 | if NEED_LIBOPCODES is non-zero, the fixup will need | |
2499 | assistance from the libopcodes. */ | |
2500 | ||
2501 | static inline void | |
2502 | aarch64_set_gas_internal_fixup (struct reloc *reloc, | |
2503 | const aarch64_opnd_info *operand, | |
2504 | int need_libopcodes_p) | |
2505 | { | |
2506 | reloc->type = BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP; | |
2507 | reloc->opnd = operand->type; | |
2508 | if (need_libopcodes_p) | |
2509 | reloc->need_libopcodes_p = 1; | |
2510 | }; | |
2511 | ||
2512 | /* Return TRUE if the instruction needs to be fixed up later internally by | |
2513 | the GAS; otherwise return FALSE. */ | |
2514 | ||
2515 | static inline bfd_boolean | |
2516 | aarch64_gas_internal_fixup_p (void) | |
2517 | { | |
2518 | return inst.reloc.type == BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP; | |
2519 | } | |
2520 | ||
33eaf5de | 2521 | /* Assign the immediate value to the relevant field in *OPERAND if |
a06ea964 NC |
2522 | RELOC->EXP is a constant expression; otherwise, flag that *OPERAND |
2523 | needs an internal fixup in a later stage. | |
2524 | ADDR_OFF_P determines whether it is the field ADDR.OFFSET.IMM or | |
2525 | IMM.VALUE that may get assigned with the constant. */ | |
2526 | static inline void | |
2527 | assign_imm_if_const_or_fixup_later (struct reloc *reloc, | |
2528 | aarch64_opnd_info *operand, | |
2529 | int addr_off_p, | |
2530 | int need_libopcodes_p, | |
2531 | int skip_p) | |
2532 | { | |
2533 | if (reloc->exp.X_op == O_constant) | |
2534 | { | |
2535 | if (addr_off_p) | |
2536 | operand->addr.offset.imm = reloc->exp.X_add_number; | |
2537 | else | |
2538 | operand->imm.value = reloc->exp.X_add_number; | |
2539 | reloc->type = BFD_RELOC_UNUSED; | |
2540 | } | |
2541 | else | |
2542 | { | |
2543 | aarch64_set_gas_internal_fixup (reloc, operand, need_libopcodes_p); | |
2544 | /* Tell libopcodes to ignore this operand or not. This is helpful | |
2545 | when one of the operands needs to be fixed up later but we need | |
2546 | libopcodes to check the other operands. */ | |
2547 | operand->skip = skip_p; | |
2548 | } | |
2549 | } | |
2550 | ||
2551 | /* Relocation modifiers. Each entry in the table contains the textual | |
2552 | name for the relocation which may be placed before a symbol used as | |
2553 | a load/store offset, or add immediate. It must be surrounded by a | |
2554 | leading and trailing colon, for example: | |
2555 | ||
2556 | ldr x0, [x1, #:rello:varsym] | |
2557 | add x0, x1, #:rello:varsym */ | |
2558 | ||
2559 | struct reloc_table_entry | |
2560 | { | |
2561 | const char *name; | |
2562 | int pc_rel; | |
6f4a313b | 2563 | bfd_reloc_code_real_type adr_type; |
a06ea964 NC |
2564 | bfd_reloc_code_real_type adrp_type; |
2565 | bfd_reloc_code_real_type movw_type; | |
2566 | bfd_reloc_code_real_type add_type; | |
2567 | bfd_reloc_code_real_type ldst_type; | |
74ad790c | 2568 | bfd_reloc_code_real_type ld_literal_type; |
a06ea964 NC |
2569 | }; |
2570 | ||
2571 | static struct reloc_table_entry reloc_table[] = { | |
2572 | /* Low 12 bits of absolute address: ADD/i and LDR/STR */ | |
2573 | {"lo12", 0, | |
6f4a313b | 2574 | 0, /* adr_type */ |
a06ea964 NC |
2575 | 0, |
2576 | 0, | |
2577 | BFD_RELOC_AARCH64_ADD_LO12, | |
74ad790c MS |
2578 | BFD_RELOC_AARCH64_LDST_LO12, |
2579 | 0}, | |
a06ea964 NC |
2580 | |
2581 | /* Higher 21 bits of pc-relative page offset: ADRP */ | |
2582 | {"pg_hi21", 1, | |
6f4a313b | 2583 | 0, /* adr_type */ |
a06ea964 NC |
2584 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
2585 | 0, | |
2586 | 0, | |
74ad790c | 2587 | 0, |
a06ea964 NC |
2588 | 0}, |
2589 | ||
2590 | /* Higher 21 bits of pc-relative page offset: ADRP, no check */ | |
2591 | {"pg_hi21_nc", 1, | |
6f4a313b | 2592 | 0, /* adr_type */ |
a06ea964 NC |
2593 | BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL, |
2594 | 0, | |
2595 | 0, | |
74ad790c | 2596 | 0, |
a06ea964 NC |
2597 | 0}, |
2598 | ||
2599 | /* Most significant bits 0-15 of unsigned address/value: MOVZ */ | |
2600 | {"abs_g0", 0, | |
6f4a313b | 2601 | 0, /* adr_type */ |
a06ea964 NC |
2602 | 0, |
2603 | BFD_RELOC_AARCH64_MOVW_G0, | |
2604 | 0, | |
74ad790c | 2605 | 0, |
a06ea964 NC |
2606 | 0}, |
2607 | ||
2608 | /* Most significant bits 0-15 of signed address/value: MOVN/Z */ | |
2609 | {"abs_g0_s", 0, | |
6f4a313b | 2610 | 0, /* adr_type */ |
a06ea964 NC |
2611 | 0, |
2612 | BFD_RELOC_AARCH64_MOVW_G0_S, | |
2613 | 0, | |
74ad790c | 2614 | 0, |
a06ea964 NC |
2615 | 0}, |
2616 | ||
2617 | /* Less significant bits 0-15 of address/value: MOVK, no check */ | |
2618 | {"abs_g0_nc", 0, | |
6f4a313b | 2619 | 0, /* adr_type */ |
a06ea964 NC |
2620 | 0, |
2621 | BFD_RELOC_AARCH64_MOVW_G0_NC, | |
2622 | 0, | |
74ad790c | 2623 | 0, |
a06ea964 NC |
2624 | 0}, |
2625 | ||
2626 | /* Most significant bits 16-31 of unsigned address/value: MOVZ */ | |
2627 | {"abs_g1", 0, | |
6f4a313b | 2628 | 0, /* adr_type */ |
a06ea964 NC |
2629 | 0, |
2630 | BFD_RELOC_AARCH64_MOVW_G1, | |
2631 | 0, | |
74ad790c | 2632 | 0, |
a06ea964 NC |
2633 | 0}, |
2634 | ||
2635 | /* Most significant bits 16-31 of signed address/value: MOVN/Z */ | |
2636 | {"abs_g1_s", 0, | |
6f4a313b | 2637 | 0, /* adr_type */ |
a06ea964 NC |
2638 | 0, |
2639 | BFD_RELOC_AARCH64_MOVW_G1_S, | |
2640 | 0, | |
74ad790c | 2641 | 0, |
a06ea964 NC |
2642 | 0}, |
2643 | ||
2644 | /* Less significant bits 16-31 of address/value: MOVK, no check */ | |
2645 | {"abs_g1_nc", 0, | |
6f4a313b | 2646 | 0, /* adr_type */ |
a06ea964 NC |
2647 | 0, |
2648 | BFD_RELOC_AARCH64_MOVW_G1_NC, | |
2649 | 0, | |
74ad790c | 2650 | 0, |
a06ea964 NC |
2651 | 0}, |
2652 | ||
2653 | /* Most significant bits 32-47 of unsigned address/value: MOVZ */ | |
2654 | {"abs_g2", 0, | |
6f4a313b | 2655 | 0, /* adr_type */ |
a06ea964 NC |
2656 | 0, |
2657 | BFD_RELOC_AARCH64_MOVW_G2, | |
2658 | 0, | |
74ad790c | 2659 | 0, |
a06ea964 NC |
2660 | 0}, |
2661 | ||
2662 | /* Most significant bits 32-47 of signed address/value: MOVN/Z */ | |
2663 | {"abs_g2_s", 0, | |
6f4a313b | 2664 | 0, /* adr_type */ |
a06ea964 NC |
2665 | 0, |
2666 | BFD_RELOC_AARCH64_MOVW_G2_S, | |
2667 | 0, | |
74ad790c | 2668 | 0, |
a06ea964 NC |
2669 | 0}, |
2670 | ||
2671 | /* Less significant bits 32-47 of address/value: MOVK, no check */ | |
2672 | {"abs_g2_nc", 0, | |
6f4a313b | 2673 | 0, /* adr_type */ |
a06ea964 NC |
2674 | 0, |
2675 | BFD_RELOC_AARCH64_MOVW_G2_NC, | |
2676 | 0, | |
74ad790c | 2677 | 0, |
a06ea964 NC |
2678 | 0}, |
2679 | ||
2680 | /* Most significant bits 48-63 of signed/unsigned address/value: MOVZ */ | |
2681 | {"abs_g3", 0, | |
6f4a313b | 2682 | 0, /* adr_type */ |
a06ea964 NC |
2683 | 0, |
2684 | BFD_RELOC_AARCH64_MOVW_G3, | |
2685 | 0, | |
74ad790c | 2686 | 0, |
a06ea964 | 2687 | 0}, |
4aa2c5e2 | 2688 | |
32247401 RL |
2689 | /* Most significant bits 0-15 of signed/unsigned address/value: MOVZ */ |
2690 | {"prel_g0", 1, | |
2691 | 0, /* adr_type */ | |
2692 | 0, | |
2693 | BFD_RELOC_AARCH64_MOVW_PREL_G0, | |
2694 | 0, | |
2695 | 0, | |
2696 | 0}, | |
2697 | ||
2698 | /* Most significant bits 0-15 of signed/unsigned address/value: MOVK */ | |
2699 | {"prel_g0_nc", 1, | |
2700 | 0, /* adr_type */ | |
2701 | 0, | |
2702 | BFD_RELOC_AARCH64_MOVW_PREL_G0_NC, | |
2703 | 0, | |
2704 | 0, | |
2705 | 0}, | |
2706 | ||
2707 | /* Most significant bits 16-31 of signed/unsigned address/value: MOVZ */ | |
2708 | {"prel_g1", 1, | |
2709 | 0, /* adr_type */ | |
2710 | 0, | |
2711 | BFD_RELOC_AARCH64_MOVW_PREL_G1, | |
2712 | 0, | |
2713 | 0, | |
2714 | 0}, | |
2715 | ||
2716 | /* Most significant bits 16-31 of signed/unsigned address/value: MOVK */ | |
2717 | {"prel_g1_nc", 1, | |
2718 | 0, /* adr_type */ | |
2719 | 0, | |
2720 | BFD_RELOC_AARCH64_MOVW_PREL_G1_NC, | |
2721 | 0, | |
2722 | 0, | |
2723 | 0}, | |
2724 | ||
2725 | /* Most significant bits 32-47 of signed/unsigned address/value: MOVZ */ | |
2726 | {"prel_g2", 1, | |
2727 | 0, /* adr_type */ | |
2728 | 0, | |
2729 | BFD_RELOC_AARCH64_MOVW_PREL_G2, | |
2730 | 0, | |
2731 | 0, | |
2732 | 0}, | |
2733 | ||
2734 | /* Most significant bits 32-47 of signed/unsigned address/value: MOVK */ | |
2735 | {"prel_g2_nc", 1, | |
2736 | 0, /* adr_type */ | |
2737 | 0, | |
2738 | BFD_RELOC_AARCH64_MOVW_PREL_G2_NC, | |
2739 | 0, | |
2740 | 0, | |
2741 | 0}, | |
2742 | ||
2743 | /* Most significant bits 48-63 of signed/unsigned address/value: MOVZ */ | |
2744 | {"prel_g3", 1, | |
2745 | 0, /* adr_type */ | |
2746 | 0, | |
2747 | BFD_RELOC_AARCH64_MOVW_PREL_G3, | |
2748 | 0, | |
2749 | 0, | |
2750 | 0}, | |
2751 | ||
a06ea964 NC |
2752 | /* Get to the page containing GOT entry for a symbol. */ |
2753 | {"got", 1, | |
6f4a313b | 2754 | 0, /* adr_type */ |
a06ea964 NC |
2755 | BFD_RELOC_AARCH64_ADR_GOT_PAGE, |
2756 | 0, | |
2757 | 0, | |
74ad790c | 2758 | 0, |
4aa2c5e2 MS |
2759 | BFD_RELOC_AARCH64_GOT_LD_PREL19}, |
2760 | ||
a06ea964 NC |
2761 | /* 12 bit offset into the page containing GOT entry for that symbol. */ |
2762 | {"got_lo12", 0, | |
6f4a313b | 2763 | 0, /* adr_type */ |
a06ea964 NC |
2764 | 0, |
2765 | 0, | |
2766 | 0, | |
74ad790c MS |
2767 | BFD_RELOC_AARCH64_LD_GOT_LO12_NC, |
2768 | 0}, | |
a06ea964 | 2769 | |
ca632371 RL |
2770 | /* 0-15 bits of address/value: MOVk, no check. */ |
2771 | {"gotoff_g0_nc", 0, | |
2772 | 0, /* adr_type */ | |
2773 | 0, | |
2774 | BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC, | |
2775 | 0, | |
2776 | 0, | |
2777 | 0}, | |
2778 | ||
654248e7 RL |
2779 | /* Most significant bits 16-31 of address/value: MOVZ. */ |
2780 | {"gotoff_g1", 0, | |
2781 | 0, /* adr_type */ | |
2782 | 0, | |
2783 | BFD_RELOC_AARCH64_MOVW_GOTOFF_G1, | |
2784 | 0, | |
2785 | 0, | |
2786 | 0}, | |
2787 | ||
87f5fbcc RL |
2788 | /* 15 bit offset into the page containing GOT entry for that symbol. */ |
2789 | {"gotoff_lo15", 0, | |
2790 | 0, /* adr_type */ | |
2791 | 0, | |
2792 | 0, | |
2793 | 0, | |
2794 | BFD_RELOC_AARCH64_LD64_GOTOFF_LO15, | |
2795 | 0}, | |
2796 | ||
3b957e5b RL |
2797 | /* Get to the page containing GOT TLS entry for a symbol */ |
2798 | {"gottprel_g0_nc", 0, | |
2799 | 0, /* adr_type */ | |
2800 | 0, | |
2801 | BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, | |
2802 | 0, | |
2803 | 0, | |
2804 | 0}, | |
2805 | ||
2806 | /* Get to the page containing GOT TLS entry for a symbol */ | |
2807 | {"gottprel_g1", 0, | |
2808 | 0, /* adr_type */ | |
2809 | 0, | |
2810 | BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1, | |
2811 | 0, | |
2812 | 0, | |
2813 | 0}, | |
2814 | ||
a06ea964 NC |
2815 | /* Get to the page containing GOT TLS entry for a symbol */ |
2816 | {"tlsgd", 0, | |
3c12b054 | 2817 | BFD_RELOC_AARCH64_TLSGD_ADR_PREL21, /* adr_type */ |
a06ea964 NC |
2818 | BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21, |
2819 | 0, | |
2820 | 0, | |
74ad790c | 2821 | 0, |
a06ea964 NC |
2822 | 0}, |
2823 | ||
2824 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ | |
2825 | {"tlsgd_lo12", 0, | |
6f4a313b | 2826 | 0, /* adr_type */ |
a06ea964 NC |
2827 | 0, |
2828 | 0, | |
2829 | BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC, | |
74ad790c | 2830 | 0, |
a06ea964 NC |
2831 | 0}, |
2832 | ||
3e8286c0 RL |
2833 | /* Lower 16 bits address/value: MOVk. */ |
2834 | {"tlsgd_g0_nc", 0, | |
2835 | 0, /* adr_type */ | |
2836 | 0, | |
2837 | BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC, | |
2838 | 0, | |
2839 | 0, | |
2840 | 0}, | |
2841 | ||
1aa66fb1 RL |
2842 | /* Most significant bits 16-31 of address/value: MOVZ. */ |
2843 | {"tlsgd_g1", 0, | |
2844 | 0, /* adr_type */ | |
2845 | 0, | |
2846 | BFD_RELOC_AARCH64_TLSGD_MOVW_G1, | |
2847 | 0, | |
2848 | 0, | |
2849 | 0}, | |
2850 | ||
a06ea964 NC |
2851 | /* Get to the page containing GOT TLS entry for a symbol */ |
2852 | {"tlsdesc", 0, | |
389b8029 | 2853 | BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21, /* adr_type */ |
418009c2 | 2854 | BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21, |
a06ea964 NC |
2855 | 0, |
2856 | 0, | |
74ad790c | 2857 | 0, |
1ada945d | 2858 | BFD_RELOC_AARCH64_TLSDESC_LD_PREL19}, |
a06ea964 NC |
2859 | |
2860 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ | |
2861 | {"tlsdesc_lo12", 0, | |
6f4a313b | 2862 | 0, /* adr_type */ |
a06ea964 NC |
2863 | 0, |
2864 | 0, | |
f955cccf | 2865 | BFD_RELOC_AARCH64_TLSDESC_ADD_LO12, |
74ad790c MS |
2866 | BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC, |
2867 | 0}, | |
a06ea964 | 2868 | |
6c37fedc JW |
2869 | /* Get to the page containing GOT TLS entry for a symbol. |
2870 | The same as GD, we allocate two consecutive GOT slots | |
2871 | for module index and module offset, the only difference | |
33eaf5de | 2872 | with GD is the module offset should be initialized to |
6c37fedc JW |
2873 | zero without any outstanding runtime relocation. */ |
2874 | {"tlsldm", 0, | |
2875 | BFD_RELOC_AARCH64_TLSLD_ADR_PREL21, /* adr_type */ | |
1107e076 | 2876 | BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21, |
6c37fedc JW |
2877 | 0, |
2878 | 0, | |
2879 | 0, | |
2880 | 0}, | |
2881 | ||
a12fad50 JW |
2882 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ |
2883 | {"tlsldm_lo12_nc", 0, | |
2884 | 0, /* adr_type */ | |
2885 | 0, | |
2886 | 0, | |
2887 | BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC, | |
2888 | 0, | |
2889 | 0}, | |
2890 | ||
70151fb5 JW |
2891 | /* 12 bit offset into the module TLS base address. */ |
2892 | {"dtprel_lo12", 0, | |
2893 | 0, /* adr_type */ | |
2894 | 0, | |
2895 | 0, | |
2896 | BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12, | |
4c562523 | 2897 | BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12, |
70151fb5 JW |
2898 | 0}, |
2899 | ||
13289c10 JW |
2900 | /* Same as dtprel_lo12, no overflow check. */ |
2901 | {"dtprel_lo12_nc", 0, | |
2902 | 0, /* adr_type */ | |
2903 | 0, | |
2904 | 0, | |
2905 | BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC, | |
4c562523 | 2906 | BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC, |
13289c10 JW |
2907 | 0}, |
2908 | ||
49df5539 JW |
2909 | /* bits[23:12] of offset to the module TLS base address. */ |
2910 | {"dtprel_hi12", 0, | |
2911 | 0, /* adr_type */ | |
2912 | 0, | |
2913 | 0, | |
2914 | BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12, | |
2915 | 0, | |
2916 | 0}, | |
2917 | ||
2918 | /* bits[15:0] of offset to the module TLS base address. */ | |
2919 | {"dtprel_g0", 0, | |
2920 | 0, /* adr_type */ | |
2921 | 0, | |
2922 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0, | |
2923 | 0, | |
2924 | 0, | |
2925 | 0}, | |
2926 | ||
2927 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */ | |
2928 | {"dtprel_g0_nc", 0, | |
2929 | 0, /* adr_type */ | |
2930 | 0, | |
2931 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC, | |
2932 | 0, | |
2933 | 0, | |
2934 | 0}, | |
2935 | ||
2936 | /* bits[31:16] of offset to the module TLS base address. */ | |
2937 | {"dtprel_g1", 0, | |
2938 | 0, /* adr_type */ | |
2939 | 0, | |
2940 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1, | |
2941 | 0, | |
2942 | 0, | |
2943 | 0}, | |
2944 | ||
2945 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */ | |
2946 | {"dtprel_g1_nc", 0, | |
2947 | 0, /* adr_type */ | |
2948 | 0, | |
2949 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC, | |
2950 | 0, | |
2951 | 0, | |
2952 | 0}, | |
2953 | ||
2954 | /* bits[47:32] of offset to the module TLS base address. */ | |
2955 | {"dtprel_g2", 0, | |
2956 | 0, /* adr_type */ | |
2957 | 0, | |
2958 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2, | |
2959 | 0, | |
2960 | 0, | |
2961 | 0}, | |
2962 | ||
43a357f9 RL |
2963 | /* Lower 16 bit offset into GOT entry for a symbol */ |
2964 | {"tlsdesc_off_g0_nc", 0, | |
2965 | 0, /* adr_type */ | |
2966 | 0, | |
2967 | BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC, | |
2968 | 0, | |
2969 | 0, | |
2970 | 0}, | |
2971 | ||
2972 | /* Higher 16 bit offset into GOT entry for a symbol */ | |
2973 | {"tlsdesc_off_g1", 0, | |
2974 | 0, /* adr_type */ | |
2975 | 0, | |
2976 | BFD_RELOC_AARCH64_TLSDESC_OFF_G1, | |
2977 | 0, | |
2978 | 0, | |
2979 | 0}, | |
2980 | ||
a06ea964 NC |
2981 | /* Get to the page containing GOT TLS entry for a symbol */ |
2982 | {"gottprel", 0, | |
6f4a313b | 2983 | 0, /* adr_type */ |
a06ea964 NC |
2984 | BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, |
2985 | 0, | |
2986 | 0, | |
74ad790c | 2987 | 0, |
043bf05a | 2988 | BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19}, |
a06ea964 NC |
2989 | |
2990 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ | |
2991 | {"gottprel_lo12", 0, | |
6f4a313b | 2992 | 0, /* adr_type */ |
a06ea964 NC |
2993 | 0, |
2994 | 0, | |
2995 | 0, | |
74ad790c MS |
2996 | BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC, |
2997 | 0}, | |
a06ea964 NC |
2998 | |
2999 | /* Get tp offset for a symbol. */ | |
3000 | {"tprel", 0, | |
6f4a313b | 3001 | 0, /* adr_type */ |
a06ea964 NC |
3002 | 0, |
3003 | 0, | |
3004 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12, | |
74ad790c | 3005 | 0, |
a06ea964 NC |
3006 | 0}, |
3007 | ||
3008 | /* Get tp offset for a symbol. */ | |
3009 | {"tprel_lo12", 0, | |
6f4a313b | 3010 | 0, /* adr_type */ |
a06ea964 NC |
3011 | 0, |
3012 | 0, | |
3013 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12, | |
84f1b9fb | 3014 | BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12, |
a06ea964 NC |
3015 | 0}, |
3016 | ||
3017 | /* Get tp offset for a symbol. */ | |
3018 | {"tprel_hi12", 0, | |
6f4a313b | 3019 | 0, /* adr_type */ |
a06ea964 NC |
3020 | 0, |
3021 | 0, | |
3022 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12, | |
74ad790c | 3023 | 0, |
a06ea964 NC |
3024 | 0}, |
3025 | ||
3026 | /* Get tp offset for a symbol. */ | |
3027 | {"tprel_lo12_nc", 0, | |
6f4a313b | 3028 | 0, /* adr_type */ |
a06ea964 NC |
3029 | 0, |
3030 | 0, | |
3031 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC, | |
84f1b9fb | 3032 | BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC, |
a06ea964 NC |
3033 | 0}, |
3034 | ||
3035 | /* Most significant bits 32-47 of address/value: MOVZ. */ | |
3036 | {"tprel_g2", 0, | |
6f4a313b | 3037 | 0, /* adr_type */ |
a06ea964 NC |
3038 | 0, |
3039 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2, | |
3040 | 0, | |
74ad790c | 3041 | 0, |
a06ea964 NC |
3042 | 0}, |
3043 | ||
3044 | /* Most significant bits 16-31 of address/value: MOVZ. */ | |
3045 | {"tprel_g1", 0, | |
6f4a313b | 3046 | 0, /* adr_type */ |
a06ea964 NC |
3047 | 0, |
3048 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1, | |
3049 | 0, | |
74ad790c | 3050 | 0, |
a06ea964 NC |
3051 | 0}, |
3052 | ||
3053 | /* Most significant bits 16-31 of address/value: MOVZ, no check. */ | |
3054 | {"tprel_g1_nc", 0, | |
6f4a313b | 3055 | 0, /* adr_type */ |
a06ea964 NC |
3056 | 0, |
3057 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC, | |
3058 | 0, | |
74ad790c | 3059 | 0, |
a06ea964 NC |
3060 | 0}, |
3061 | ||
3062 | /* Most significant bits 0-15 of address/value: MOVZ. */ | |
3063 | {"tprel_g0", 0, | |
6f4a313b | 3064 | 0, /* adr_type */ |
a06ea964 NC |
3065 | 0, |
3066 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0, | |
3067 | 0, | |
74ad790c | 3068 | 0, |
a06ea964 NC |
3069 | 0}, |
3070 | ||
3071 | /* Most significant bits 0-15 of address/value: MOVZ, no check. */ | |
3072 | {"tprel_g0_nc", 0, | |
6f4a313b | 3073 | 0, /* adr_type */ |
a06ea964 NC |
3074 | 0, |
3075 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC, | |
3076 | 0, | |
74ad790c | 3077 | 0, |
a06ea964 | 3078 | 0}, |
a921b5bd JW |
3079 | |
3080 | /* 15bit offset from got entry to base address of GOT table. */ | |
3081 | {"gotpage_lo15", 0, | |
3082 | 0, | |
3083 | 0, | |
3084 | 0, | |
3085 | 0, | |
3086 | BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15, | |
3087 | 0}, | |
3d715ce4 JW |
3088 | |
3089 | /* 14bit offset from got entry to base address of GOT table. */ | |
3090 | {"gotpage_lo14", 0, | |
3091 | 0, | |
3092 | 0, | |
3093 | 0, | |
3094 | 0, | |
3095 | BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14, | |
3096 | 0}, | |
a06ea964 NC |
3097 | }; |
3098 | ||
3099 | /* Given the address of a pointer pointing to the textual name of a | |
3100 | relocation as may appear in assembler source, attempt to find its | |
3101 | details in reloc_table. The pointer will be updated to the character | |
3102 | after the trailing colon. On failure, NULL will be returned; | |
3103 | otherwise return the reloc_table_entry. */ | |
3104 | ||
3105 | static struct reloc_table_entry * | |
3106 | find_reloc_table_entry (char **str) | |
3107 | { | |
3108 | unsigned int i; | |
3109 | for (i = 0; i < ARRAY_SIZE (reloc_table); i++) | |
3110 | { | |
3111 | int length = strlen (reloc_table[i].name); | |
3112 | ||
3113 | if (strncasecmp (reloc_table[i].name, *str, length) == 0 | |
3114 | && (*str)[length] == ':') | |
3115 | { | |
3116 | *str += (length + 1); | |
3117 | return &reloc_table[i]; | |
3118 | } | |
3119 | } | |
3120 | ||
3121 | return NULL; | |
3122 | } | |
3123 | ||
3124 | /* Mode argument to parse_shift and parser_shifter_operand. */ | |
3125 | enum parse_shift_mode | |
3126 | { | |
98907a70 | 3127 | SHIFTED_NONE, /* no shifter allowed */ |
a06ea964 NC |
3128 | SHIFTED_ARITH_IMM, /* "rn{,lsl|lsr|asl|asr|uxt|sxt #n}" or |
3129 | "#imm{,lsl #n}" */ | |
3130 | SHIFTED_LOGIC_IMM, /* "rn{,lsl|lsr|asl|asr|ror #n}" or | |
3131 | "#imm" */ | |
3132 | SHIFTED_LSL, /* bare "lsl #n" */ | |
2442d846 | 3133 | SHIFTED_MUL, /* bare "mul #n" */ |
a06ea964 | 3134 | SHIFTED_LSL_MSL, /* "lsl|msl #n" */ |
98907a70 | 3135 | SHIFTED_MUL_VL, /* "mul vl" */ |
a06ea964 NC |
3136 | SHIFTED_REG_OFFSET /* [su]xtw|sxtx {#n} or lsl #n */ |
3137 | }; | |
3138 | ||
3139 | /* Parse a <shift> operator on an AArch64 data processing instruction. | |
3140 | Return TRUE on success; otherwise return FALSE. */ | |
3141 | static bfd_boolean | |
3142 | parse_shift (char **str, aarch64_opnd_info *operand, enum parse_shift_mode mode) | |
3143 | { | |
3144 | const struct aarch64_name_value_pair *shift_op; | |
3145 | enum aarch64_modifier_kind kind; | |
3146 | expressionS exp; | |
3147 | int exp_has_prefix; | |
3148 | char *s = *str; | |
3149 | char *p = s; | |
3150 | ||
3151 | for (p = *str; ISALPHA (*p); p++) | |
3152 | ; | |
3153 | ||
3154 | if (p == *str) | |
3155 | { | |
3156 | set_syntax_error (_("shift expression expected")); | |
3157 | return FALSE; | |
3158 | } | |
3159 | ||
629310ab | 3160 | shift_op = str_hash_find_n (aarch64_shift_hsh, *str, p - *str); |
a06ea964 NC |
3161 | |
3162 | if (shift_op == NULL) | |
3163 | { | |
3164 | set_syntax_error (_("shift operator expected")); | |
3165 | return FALSE; | |
3166 | } | |
3167 | ||
3168 | kind = aarch64_get_operand_modifier (shift_op); | |
3169 | ||
3170 | if (kind == AARCH64_MOD_MSL && mode != SHIFTED_LSL_MSL) | |
3171 | { | |
3172 | set_syntax_error (_("invalid use of 'MSL'")); | |
3173 | return FALSE; | |
3174 | } | |
3175 | ||
2442d846 | 3176 | if (kind == AARCH64_MOD_MUL |
98907a70 RS |
3177 | && mode != SHIFTED_MUL |
3178 | && mode != SHIFTED_MUL_VL) | |
2442d846 RS |
3179 | { |
3180 | set_syntax_error (_("invalid use of 'MUL'")); | |
3181 | return FALSE; | |
3182 | } | |
3183 | ||
a06ea964 NC |
3184 | switch (mode) |
3185 | { | |
3186 | case SHIFTED_LOGIC_IMM: | |
535b785f | 3187 | if (aarch64_extend_operator_p (kind)) |
a06ea964 NC |
3188 | { |
3189 | set_syntax_error (_("extending shift is not permitted")); | |
3190 | return FALSE; | |
3191 | } | |
3192 | break; | |
3193 | ||
3194 | case SHIFTED_ARITH_IMM: | |
3195 | if (kind == AARCH64_MOD_ROR) | |
3196 | { | |
3197 | set_syntax_error (_("'ROR' shift is not permitted")); | |
3198 | return FALSE; | |
3199 | } | |
3200 | break; | |
3201 | ||
3202 | case SHIFTED_LSL: | |
3203 | if (kind != AARCH64_MOD_LSL) | |
3204 | { | |
3205 | set_syntax_error (_("only 'LSL' shift is permitted")); | |
3206 | return FALSE; | |
3207 | } | |
3208 | break; | |
3209 | ||
2442d846 RS |
3210 | case SHIFTED_MUL: |
3211 | if (kind != AARCH64_MOD_MUL) | |
3212 | { | |
3213 | set_syntax_error (_("only 'MUL' is permitted")); | |
3214 | return FALSE; | |
3215 | } | |
3216 | break; | |
3217 | ||
98907a70 RS |
3218 | case SHIFTED_MUL_VL: |
3219 | /* "MUL VL" consists of two separate tokens. Require the first | |
3220 | token to be "MUL" and look for a following "VL". */ | |
3221 | if (kind == AARCH64_MOD_MUL) | |
3222 | { | |
3223 | skip_whitespace (p); | |
3224 | if (strncasecmp (p, "vl", 2) == 0 && !ISALPHA (p[2])) | |
3225 | { | |
3226 | p += 2; | |
3227 | kind = AARCH64_MOD_MUL_VL; | |
3228 | break; | |
3229 | } | |
3230 | } | |
3231 | set_syntax_error (_("only 'MUL VL' is permitted")); | |
3232 | return FALSE; | |
3233 | ||
a06ea964 NC |
3234 | case SHIFTED_REG_OFFSET: |
3235 | if (kind != AARCH64_MOD_UXTW && kind != AARCH64_MOD_LSL | |
3236 | && kind != AARCH64_MOD_SXTW && kind != AARCH64_MOD_SXTX) | |
3237 | { | |
3238 | set_fatal_syntax_error | |
3239 | (_("invalid shift for the register offset addressing mode")); | |
3240 | return FALSE; | |
3241 | } | |
3242 | break; | |
3243 | ||
3244 | case SHIFTED_LSL_MSL: | |
3245 | if (kind != AARCH64_MOD_LSL && kind != AARCH64_MOD_MSL) | |
3246 | { | |
3247 | set_syntax_error (_("invalid shift operator")); | |
3248 | return FALSE; | |
3249 | } | |
3250 | break; | |
3251 | ||
3252 | default: | |
3253 | abort (); | |
3254 | } | |
3255 | ||
3256 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
3257 | skip_whitespace (p); | |
3258 | ||
3259 | /* Parse shift amount. */ | |
3260 | exp_has_prefix = 0; | |
98907a70 | 3261 | if ((mode == SHIFTED_REG_OFFSET && *p == ']') || kind == AARCH64_MOD_MUL_VL) |
a06ea964 NC |
3262 | exp.X_op = O_absent; |
3263 | else | |
3264 | { | |
3265 | if (is_immediate_prefix (*p)) | |
3266 | { | |
3267 | p++; | |
3268 | exp_has_prefix = 1; | |
3269 | } | |
3270 | my_get_expression (&exp, &p, GE_NO_PREFIX, 0); | |
3271 | } | |
98907a70 RS |
3272 | if (kind == AARCH64_MOD_MUL_VL) |
3273 | /* For consistency, give MUL VL the same shift amount as an implicit | |
3274 | MUL #1. */ | |
3275 | operand->shifter.amount = 1; | |
3276 | else if (exp.X_op == O_absent) | |
a06ea964 | 3277 | { |
535b785f | 3278 | if (!aarch64_extend_operator_p (kind) || exp_has_prefix) |
a06ea964 NC |
3279 | { |
3280 | set_syntax_error (_("missing shift amount")); | |
3281 | return FALSE; | |
3282 | } | |
3283 | operand->shifter.amount = 0; | |
3284 | } | |
3285 | else if (exp.X_op != O_constant) | |
3286 | { | |
3287 | set_syntax_error (_("constant shift amount required")); | |
3288 | return FALSE; | |
3289 | } | |
2442d846 RS |
3290 | /* For parsing purposes, MUL #n has no inherent range. The range |
3291 | depends on the operand and will be checked by operand-specific | |
3292 | routines. */ | |
3293 | else if (kind != AARCH64_MOD_MUL | |
3294 | && (exp.X_add_number < 0 || exp.X_add_number > 63)) | |
a06ea964 NC |
3295 | { |
3296 | set_fatal_syntax_error (_("shift amount out of range 0 to 63")); | |
3297 | return FALSE; | |
3298 | } | |
3299 | else | |
3300 | { | |
3301 | operand->shifter.amount = exp.X_add_number; | |
3302 | operand->shifter.amount_present = 1; | |
3303 | } | |
3304 | ||
3305 | operand->shifter.operator_present = 1; | |
3306 | operand->shifter.kind = kind; | |
3307 | ||
3308 | *str = p; | |
3309 | return TRUE; | |
3310 | } | |
3311 | ||
3312 | /* Parse a <shifter_operand> for a data processing instruction: | |
3313 | ||
3314 | #<immediate> | |
3315 | #<immediate>, LSL #imm | |
3316 | ||
3317 | Validation of immediate operands is deferred to md_apply_fix. | |
3318 | ||
3319 | Return TRUE on success; otherwise return FALSE. */ | |
3320 | ||
3321 | static bfd_boolean | |
3322 | parse_shifter_operand_imm (char **str, aarch64_opnd_info *operand, | |
3323 | enum parse_shift_mode mode) | |
3324 | { | |
3325 | char *p; | |
3326 | ||
3327 | if (mode != SHIFTED_ARITH_IMM && mode != SHIFTED_LOGIC_IMM) | |
3328 | return FALSE; | |
3329 | ||
3330 | p = *str; | |
3331 | ||
3332 | /* Accept an immediate expression. */ | |
3333 | if (! my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX, 1)) | |
3334 | return FALSE; | |
3335 | ||
3336 | /* Accept optional LSL for arithmetic immediate values. */ | |
3337 | if (mode == SHIFTED_ARITH_IMM && skip_past_comma (&p)) | |
3338 | if (! parse_shift (&p, operand, SHIFTED_LSL)) | |
3339 | return FALSE; | |
3340 | ||
3341 | /* Not accept any shifter for logical immediate values. */ | |
3342 | if (mode == SHIFTED_LOGIC_IMM && skip_past_comma (&p) | |
3343 | && parse_shift (&p, operand, mode)) | |
3344 | { | |
3345 | set_syntax_error (_("unexpected shift operator")); | |
3346 | return FALSE; | |
3347 | } | |
3348 | ||
3349 | *str = p; | |
3350 | return TRUE; | |
3351 | } | |
3352 | ||
3353 | /* Parse a <shifter_operand> for a data processing instruction: | |
3354 | ||
3355 | <Rm> | |
3356 | <Rm>, <shift> | |
3357 | #<immediate> | |
3358 | #<immediate>, LSL #imm | |
3359 | ||
3360 | where <shift> is handled by parse_shift above, and the last two | |
3361 | cases are handled by the function above. | |
3362 | ||
3363 | Validation of immediate operands is deferred to md_apply_fix. | |
3364 | ||
3365 | Return TRUE on success; otherwise return FALSE. */ | |
3366 | ||
3367 | static bfd_boolean | |
3368 | parse_shifter_operand (char **str, aarch64_opnd_info *operand, | |
3369 | enum parse_shift_mode mode) | |
3370 | { | |
e1b988bb RS |
3371 | const reg_entry *reg; |
3372 | aarch64_opnd_qualifier_t qualifier; | |
a06ea964 NC |
3373 | enum aarch64_operand_class opd_class |
3374 | = aarch64_get_operand_class (operand->type); | |
3375 | ||
e1b988bb RS |
3376 | reg = aarch64_reg_parse_32_64 (str, &qualifier); |
3377 | if (reg) | |
a06ea964 NC |
3378 | { |
3379 | if (opd_class == AARCH64_OPND_CLASS_IMMEDIATE) | |
3380 | { | |
3381 | set_syntax_error (_("unexpected register in the immediate operand")); | |
3382 | return FALSE; | |
3383 | } | |
3384 | ||
e1b988bb | 3385 | if (!aarch64_check_reg_type (reg, REG_TYPE_R_Z)) |
a06ea964 | 3386 | { |
e1b988bb | 3387 | set_syntax_error (_(get_reg_expected_msg (REG_TYPE_R_Z))); |
a06ea964 NC |
3388 | return FALSE; |
3389 | } | |
3390 | ||
e1b988bb RS |
3391 | operand->reg.regno = reg->number; |
3392 | operand->qualifier = qualifier; | |
a06ea964 NC |
3393 | |
3394 | /* Accept optional shift operation on register. */ | |
3395 | if (! skip_past_comma (str)) | |
3396 | return TRUE; | |
3397 | ||
3398 | if (! parse_shift (str, operand, mode)) | |
3399 | return FALSE; | |
3400 | ||
3401 | return TRUE; | |
3402 | } | |
3403 | else if (opd_class == AARCH64_OPND_CLASS_MODIFIED_REG) | |
3404 | { | |
3405 | set_syntax_error | |
3406 | (_("integer register expected in the extended/shifted operand " | |
3407 | "register")); | |
3408 | return FALSE; | |
3409 | } | |
3410 | ||
3411 | /* We have a shifted immediate variable. */ | |
3412 | return parse_shifter_operand_imm (str, operand, mode); | |
3413 | } | |
3414 | ||
3415 | /* Return TRUE on success; return FALSE otherwise. */ | |
3416 | ||
3417 | static bfd_boolean | |
3418 | parse_shifter_operand_reloc (char **str, aarch64_opnd_info *operand, | |
3419 | enum parse_shift_mode mode) | |
3420 | { | |
3421 | char *p = *str; | |
3422 | ||
3423 | /* Determine if we have the sequence of characters #: or just : | |
3424 | coming next. If we do, then we check for a :rello: relocation | |
3425 | modifier. If we don't, punt the whole lot to | |
3426 | parse_shifter_operand. */ | |
3427 | ||
3428 | if ((p[0] == '#' && p[1] == ':') || p[0] == ':') | |
3429 | { | |
3430 | struct reloc_table_entry *entry; | |
3431 | ||
3432 | if (p[0] == '#') | |
3433 | p += 2; | |
3434 | else | |
3435 | p++; | |
3436 | *str = p; | |
3437 | ||
3438 | /* Try to parse a relocation. Anything else is an error. */ | |
3439 | if (!(entry = find_reloc_table_entry (str))) | |
3440 | { | |
3441 | set_syntax_error (_("unknown relocation modifier")); | |
3442 | return FALSE; | |
3443 | } | |
3444 | ||
3445 | if (entry->add_type == 0) | |
3446 | { | |
3447 | set_syntax_error | |
3448 | (_("this relocation modifier is not allowed on this instruction")); | |
3449 | return FALSE; | |
3450 | } | |
3451 | ||
3452 | /* Save str before we decompose it. */ | |
3453 | p = *str; | |
3454 | ||
3455 | /* Next, we parse the expression. */ | |
3456 | if (! my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX, 1)) | |
3457 | return FALSE; | |
3458 | ||
3459 | /* Record the relocation type (use the ADD variant here). */ | |
3460 | inst.reloc.type = entry->add_type; | |
3461 | inst.reloc.pc_rel = entry->pc_rel; | |
3462 | ||
3463 | /* If str is empty, we've reached the end, stop here. */ | |
3464 | if (**str == '\0') | |
3465 | return TRUE; | |
3466 | ||
55d9b4c1 | 3467 | /* Otherwise, we have a shifted reloc modifier, so rewind to |
a06ea964 NC |
3468 | recover the variable name and continue parsing for the shifter. */ |
3469 | *str = p; | |
3470 | return parse_shifter_operand_imm (str, operand, mode); | |
3471 | } | |
3472 | ||
3473 | return parse_shifter_operand (str, operand, mode); | |
3474 | } | |
3475 | ||
3476 | /* Parse all forms of an address expression. Information is written | |
3477 | to *OPERAND and/or inst.reloc. | |
3478 | ||
3479 | The A64 instruction set has the following addressing modes: | |
3480 | ||
3481 | Offset | |
4df068de RS |
3482 | [base] // in SIMD ld/st structure |
3483 | [base{,#0}] // in ld/st exclusive | |
a06ea964 NC |
3484 | [base{,#imm}] |
3485 | [base,Xm{,LSL #imm}] | |
3486 | [base,Xm,SXTX {#imm}] | |
3487 | [base,Wm,(S|U)XTW {#imm}] | |
3488 | Pre-indexed | |
1820262b | 3489 | [base]! // in ldraa/ldrab exclusive |
a06ea964 NC |
3490 | [base,#imm]! |
3491 | Post-indexed | |
3492 | [base],#imm | |
4df068de | 3493 | [base],Xm // in SIMD ld/st structure |
a06ea964 NC |
3494 | PC-relative (literal) |
3495 | label | |
4df068de | 3496 | SVE: |
98907a70 | 3497 | [base,#imm,MUL VL] |
4df068de RS |
3498 | [base,Zm.D{,LSL #imm}] |
3499 | [base,Zm.S,(S|U)XTW {#imm}] | |
3500 | [base,Zm.D,(S|U)XTW {#imm}] // ignores top 32 bits of Zm.D elements | |
3501 | [Zn.S,#imm] | |
3502 | [Zn.D,#imm] | |
c469c864 | 3503 | [Zn.S{, Xm}] |
4df068de RS |
3504 | [Zn.S,Zm.S{,LSL #imm}] // in ADR |
3505 | [Zn.D,Zm.D{,LSL #imm}] // in ADR | |
3506 | [Zn.D,Zm.D,(S|U)XTW {#imm}] // in ADR | |
a06ea964 NC |
3507 | |
3508 | (As a convenience, the notation "=immediate" is permitted in conjunction | |
3509 | with the pc-relative literal load instructions to automatically place an | |
3510 | immediate value or symbolic address in a nearby literal pool and generate | |
3511 | a hidden label which references it.) | |
3512 | ||
3513 | Upon a successful parsing, the address structure in *OPERAND will be | |
3514 | filled in the following way: | |
3515 | ||
3516 | .base_regno = <base> | |
3517 | .offset.is_reg // 1 if the offset is a register | |
3518 | .offset.imm = <imm> | |
3519 | .offset.regno = <Rm> | |
3520 | ||
3521 | For different addressing modes defined in the A64 ISA: | |
3522 | ||
3523 | Offset | |
3524 | .pcrel=0; .preind=1; .postind=0; .writeback=0 | |
3525 | Pre-indexed | |
3526 | .pcrel=0; .preind=1; .postind=0; .writeback=1 | |
3527 | Post-indexed | |
3528 | .pcrel=0; .preind=0; .postind=1; .writeback=1 | |
3529 | PC-relative (literal) | |
3530 | .pcrel=1; .preind=1; .postind=0; .writeback=0 | |
3531 | ||
3532 | The shift/extension information, if any, will be stored in .shifter. | |
4df068de RS |
3533 | The base and offset qualifiers will be stored in *BASE_QUALIFIER and |
3534 | *OFFSET_QUALIFIER respectively, with NIL being used if there's no | |
3535 | corresponding register. | |
a06ea964 | 3536 | |
4df068de | 3537 | BASE_TYPE says which types of base register should be accepted and |
98907a70 RS |
3538 | OFFSET_TYPE says the same for offset registers. IMM_SHIFT_MODE |
3539 | is the type of shifter that is allowed for immediate offsets, | |
3540 | or SHIFTED_NONE if none. | |
3541 | ||
3542 | In all other respects, it is the caller's responsibility to check | |
3543 | for addressing modes not supported by the instruction, and to set | |
3544 | inst.reloc.type. */ | |
a06ea964 NC |
3545 | |
3546 | static bfd_boolean | |
4df068de RS |
3547 | parse_address_main (char **str, aarch64_opnd_info *operand, |
3548 | aarch64_opnd_qualifier_t *base_qualifier, | |
3549 | aarch64_opnd_qualifier_t *offset_qualifier, | |
98907a70 RS |
3550 | aarch64_reg_type base_type, aarch64_reg_type offset_type, |
3551 | enum parse_shift_mode imm_shift_mode) | |
a06ea964 NC |
3552 | { |
3553 | char *p = *str; | |
e1b988bb | 3554 | const reg_entry *reg; |
a06ea964 NC |
3555 | expressionS *exp = &inst.reloc.exp; |
3556 | ||
4df068de RS |
3557 | *base_qualifier = AARCH64_OPND_QLF_NIL; |
3558 | *offset_qualifier = AARCH64_OPND_QLF_NIL; | |
a06ea964 NC |
3559 | if (! skip_past_char (&p, '[')) |
3560 | { | |
3561 | /* =immediate or label. */ | |
3562 | operand->addr.pcrel = 1; | |
3563 | operand->addr.preind = 1; | |
3564 | ||
f41aef5f RE |
3565 | /* #:<reloc_op>:<symbol> */ |
3566 | skip_past_char (&p, '#'); | |
73866052 | 3567 | if (skip_past_char (&p, ':')) |
f41aef5f | 3568 | { |
6f4a313b | 3569 | bfd_reloc_code_real_type ty; |
f41aef5f RE |
3570 | struct reloc_table_entry *entry; |
3571 | ||
3572 | /* Try to parse a relocation modifier. Anything else is | |
3573 | an error. */ | |
3574 | entry = find_reloc_table_entry (&p); | |
3575 | if (! entry) | |
3576 | { | |
3577 | set_syntax_error (_("unknown relocation modifier")); | |
3578 | return FALSE; | |
3579 | } | |
3580 | ||
6f4a313b MS |
3581 | switch (operand->type) |
3582 | { | |
3583 | case AARCH64_OPND_ADDR_PCREL21: | |
3584 | /* adr */ | |
3585 | ty = entry->adr_type; | |
3586 | break; | |
3587 | ||
3588 | default: | |
74ad790c | 3589 | ty = entry->ld_literal_type; |
6f4a313b MS |
3590 | break; |
3591 | } | |
3592 | ||
3593 | if (ty == 0) | |
f41aef5f RE |
3594 | { |
3595 | set_syntax_error | |
3596 | (_("this relocation modifier is not allowed on this " | |
3597 | "instruction")); | |
3598 | return FALSE; | |
3599 | } | |
3600 | ||
3601 | /* #:<reloc_op>: */ | |
3602 | if (! my_get_expression (exp, &p, GE_NO_PREFIX, 1)) | |
3603 | { | |
3604 | set_syntax_error (_("invalid relocation expression")); | |
3605 | return FALSE; | |
3606 | } | |
a06ea964 | 3607 | |
f41aef5f | 3608 | /* #:<reloc_op>:<expr> */ |
6f4a313b MS |
3609 | /* Record the relocation type. */ |
3610 | inst.reloc.type = ty; | |
f41aef5f RE |
3611 | inst.reloc.pc_rel = entry->pc_rel; |
3612 | } | |
3613 | else | |
a06ea964 | 3614 | { |
f41aef5f RE |
3615 | |
3616 | if (skip_past_char (&p, '=')) | |
3617 | /* =immediate; need to generate the literal in the literal pool. */ | |
3618 | inst.gen_lit_pool = 1; | |
3619 | ||
3620 | if (!my_get_expression (exp, &p, GE_NO_PREFIX, 1)) | |
3621 | { | |
3622 | set_syntax_error (_("invalid address")); | |
3623 | return FALSE; | |
3624 | } | |
a06ea964 NC |
3625 | } |
3626 | ||
3627 | *str = p; | |
3628 | return TRUE; | |
3629 | } | |
3630 | ||
3631 | /* [ */ | |
3632 | ||
4df068de RS |
3633 | reg = aarch64_addr_reg_parse (&p, base_type, base_qualifier); |
3634 | if (!reg || !aarch64_check_reg_type (reg, base_type)) | |
a06ea964 | 3635 | { |
4df068de | 3636 | set_syntax_error (_(get_reg_expected_msg (base_type))); |
a06ea964 NC |
3637 | return FALSE; |
3638 | } | |
e1b988bb | 3639 | operand->addr.base_regno = reg->number; |
a06ea964 NC |
3640 | |
3641 | /* [Xn */ | |
3642 | if (skip_past_comma (&p)) | |
3643 | { | |
3644 | /* [Xn, */ | |
3645 | operand->addr.preind = 1; | |
3646 | ||
4df068de | 3647 | reg = aarch64_addr_reg_parse (&p, offset_type, offset_qualifier); |
e1b988bb | 3648 | if (reg) |
a06ea964 | 3649 | { |
4df068de | 3650 | if (!aarch64_check_reg_type (reg, offset_type)) |
e1b988bb | 3651 | { |
4df068de | 3652 | set_syntax_error (_(get_reg_expected_msg (offset_type))); |
e1b988bb RS |
3653 | return FALSE; |
3654 | } | |
3655 | ||
a06ea964 | 3656 | /* [Xn,Rm */ |
e1b988bb | 3657 | operand->addr.offset.regno = reg->number; |
a06ea964 NC |
3658 | operand->addr.offset.is_reg = 1; |
3659 | /* Shifted index. */ | |
3660 | if (skip_past_comma (&p)) | |
3661 | { | |
3662 | /* [Xn,Rm, */ | |
3663 | if (! parse_shift (&p, operand, SHIFTED_REG_OFFSET)) | |
3664 | /* Use the diagnostics set in parse_shift, so not set new | |
3665 | error message here. */ | |
3666 | return FALSE; | |
3667 | } | |
3668 | /* We only accept: | |
c469c864 | 3669 | [base,Xm] # For vector plus scalar SVE2 indexing. |
a06ea964 NC |
3670 | [base,Xm{,LSL #imm}] |
3671 | [base,Xm,SXTX {#imm}] | |
3672 | [base,Wm,(S|U)XTW {#imm}] */ | |
3673 | if (operand->shifter.kind == AARCH64_MOD_NONE | |
3674 | || operand->shifter.kind == AARCH64_MOD_LSL | |
3675 | || operand->shifter.kind == AARCH64_MOD_SXTX) | |
3676 | { | |
4df068de | 3677 | if (*offset_qualifier == AARCH64_OPND_QLF_W) |
a06ea964 NC |
3678 | { |
3679 | set_syntax_error (_("invalid use of 32-bit register offset")); | |
3680 | return FALSE; | |
3681 | } | |
4df068de | 3682 | if (aarch64_get_qualifier_esize (*base_qualifier) |
c469c864 MM |
3683 | != aarch64_get_qualifier_esize (*offset_qualifier) |
3684 | && (operand->type != AARCH64_OPND_SVE_ADDR_ZX | |
3685 | || *base_qualifier != AARCH64_OPND_QLF_S_S | |
3686 | || *offset_qualifier != AARCH64_OPND_QLF_X)) | |
4df068de RS |
3687 | { |
3688 | set_syntax_error (_("offset has different size from base")); | |
3689 | return FALSE; | |
3690 | } | |
a06ea964 | 3691 | } |
4df068de | 3692 | else if (*offset_qualifier == AARCH64_OPND_QLF_X) |
a06ea964 NC |
3693 | { |
3694 | set_syntax_error (_("invalid use of 64-bit register offset")); | |
3695 | return FALSE; | |
3696 | } | |
3697 | } | |
3698 | else | |
3699 | { | |
3700 | /* [Xn,#:<reloc_op>:<symbol> */ | |
3701 | skip_past_char (&p, '#'); | |
73866052 | 3702 | if (skip_past_char (&p, ':')) |
a06ea964 NC |
3703 | { |
3704 | struct reloc_table_entry *entry; | |
3705 | ||
3706 | /* Try to parse a relocation modifier. Anything else is | |
3707 | an error. */ | |
3708 | if (!(entry = find_reloc_table_entry (&p))) | |
3709 | { | |
3710 | set_syntax_error (_("unknown relocation modifier")); | |
3711 | return FALSE; | |
3712 | } | |
3713 | ||
3714 | if (entry->ldst_type == 0) | |
3715 | { | |
3716 | set_syntax_error | |
3717 | (_("this relocation modifier is not allowed on this " | |
3718 | "instruction")); | |
3719 | return FALSE; | |
3720 | } | |
3721 | ||
3722 | /* [Xn,#:<reloc_op>: */ | |
3723 | /* We now have the group relocation table entry corresponding to | |
3724 | the name in the assembler source. Next, we parse the | |
3725 | expression. */ | |
3726 | if (! my_get_expression (exp, &p, GE_NO_PREFIX, 1)) | |
3727 | { | |
3728 | set_syntax_error (_("invalid relocation expression")); | |
3729 | return FALSE; | |
3730 | } | |
3731 | ||
3732 | /* [Xn,#:<reloc_op>:<expr> */ | |
3733 | /* Record the load/store relocation type. */ | |
3734 | inst.reloc.type = entry->ldst_type; | |
3735 | inst.reloc.pc_rel = entry->pc_rel; | |
3736 | } | |
98907a70 | 3737 | else |
a06ea964 | 3738 | { |
98907a70 RS |
3739 | if (! my_get_expression (exp, &p, GE_OPT_PREFIX, 1)) |
3740 | { | |
3741 | set_syntax_error (_("invalid expression in the address")); | |
3742 | return FALSE; | |
3743 | } | |
3744 | /* [Xn,<expr> */ | |
3745 | if (imm_shift_mode != SHIFTED_NONE && skip_past_comma (&p)) | |
3746 | /* [Xn,<expr>,<shifter> */ | |
3747 | if (! parse_shift (&p, operand, imm_shift_mode)) | |
3748 | return FALSE; | |
a06ea964 | 3749 | } |
a06ea964 NC |
3750 | } |
3751 | } | |
3752 | ||
3753 | if (! skip_past_char (&p, ']')) | |
3754 | { | |
3755 | set_syntax_error (_("']' expected")); | |
3756 | return FALSE; | |
3757 | } | |
3758 | ||
3759 | if (skip_past_char (&p, '!')) | |
3760 | { | |
3761 | if (operand->addr.preind && operand->addr.offset.is_reg) | |
3762 | { | |
3763 | set_syntax_error (_("register offset not allowed in pre-indexed " | |
3764 | "addressing mode")); | |
3765 | return FALSE; | |
3766 | } | |
3767 | /* [Xn]! */ | |
3768 | operand->addr.writeback = 1; | |
3769 | } | |
3770 | else if (skip_past_comma (&p)) | |
3771 | { | |
3772 | /* [Xn], */ | |
3773 | operand->addr.postind = 1; | |
3774 | operand->addr.writeback = 1; | |
3775 | ||
3776 | if (operand->addr.preind) | |
3777 | { | |
3778 | set_syntax_error (_("cannot combine pre- and post-indexing")); | |
3779 | return FALSE; | |
3780 | } | |
3781 | ||
4df068de | 3782 | reg = aarch64_reg_parse_32_64 (&p, offset_qualifier); |
73866052 | 3783 | if (reg) |
a06ea964 NC |
3784 | { |
3785 | /* [Xn],Xm */ | |
e1b988bb | 3786 | if (!aarch64_check_reg_type (reg, REG_TYPE_R_64)) |
a06ea964 | 3787 | { |
e1b988bb | 3788 | set_syntax_error (_(get_reg_expected_msg (REG_TYPE_R_64))); |
a06ea964 NC |
3789 | return FALSE; |
3790 | } | |
e1b988bb RS |
3791 | |
3792 | operand->addr.offset.regno = reg->number; | |
a06ea964 NC |
3793 | operand->addr.offset.is_reg = 1; |
3794 | } | |
3795 | else if (! my_get_expression (exp, &p, GE_OPT_PREFIX, 1)) | |
3796 | { | |
3797 | /* [Xn],#expr */ | |
3798 | set_syntax_error (_("invalid expression in the address")); | |
3799 | return FALSE; | |
3800 | } | |
3801 | } | |
3802 | ||
3803 | /* If at this point neither .preind nor .postind is set, we have a | |
1820262b DB |
3804 | bare [Rn]{!}; only accept [Rn]! as a shorthand for [Rn,#0]! for ldraa and |
3805 | ldrab, accept [Rn] as a shorthand for [Rn,#0]. | |
c469c864 MM |
3806 | For SVE2 vector plus scalar offsets, allow [Zn.<T>] as shorthand for |
3807 | [Zn.<T>, xzr]. */ | |
a06ea964 NC |
3808 | if (operand->addr.preind == 0 && operand->addr.postind == 0) |
3809 | { | |
550fd7bf | 3810 | if (operand->addr.writeback) |
a06ea964 | 3811 | { |
1820262b DB |
3812 | if (operand->type == AARCH64_OPND_ADDR_SIMM10) |
3813 | { | |
3814 | /* Accept [Rn]! as a shorthand for [Rn,#0]! */ | |
3815 | operand->addr.offset.is_reg = 0; | |
3816 | operand->addr.offset.imm = 0; | |
3817 | operand->addr.preind = 1; | |
3818 | } | |
3819 | else | |
3820 | { | |
3821 | /* Reject [Rn]! */ | |
3822 | set_syntax_error (_("missing offset in the pre-indexed address")); | |
3823 | return FALSE; | |
3824 | } | |
a06ea964 | 3825 | } |
1820262b | 3826 | else |
c469c864 | 3827 | { |
1820262b DB |
3828 | operand->addr.preind = 1; |
3829 | if (operand->type == AARCH64_OPND_SVE_ADDR_ZX) | |
3830 | { | |
3831 | operand->addr.offset.is_reg = 1; | |
3832 | operand->addr.offset.regno = REG_ZR; | |
3833 | *offset_qualifier = AARCH64_OPND_QLF_X; | |
3834 | } | |
3835 | else | |
3836 | { | |
3837 | inst.reloc.exp.X_op = O_constant; | |
3838 | inst.reloc.exp.X_add_number = 0; | |
3839 | } | |
c469c864 | 3840 | } |
a06ea964 NC |
3841 | } |
3842 | ||
3843 | *str = p; | |
3844 | return TRUE; | |
3845 | } | |
3846 | ||
73866052 RS |
3847 | /* Parse a base AArch64 address (as opposed to an SVE one). Return TRUE |
3848 | on success. */ | |
a06ea964 | 3849 | static bfd_boolean |
73866052 | 3850 | parse_address (char **str, aarch64_opnd_info *operand) |
a06ea964 | 3851 | { |
4df068de | 3852 | aarch64_opnd_qualifier_t base_qualifier, offset_qualifier; |
3493da5c SP |
3853 | |
3854 | aarch64_reg_type base; | |
3855 | ||
3856 | if (AARCH64_CPU_HAS_FEATURE (cpu_variant, AARCH64_FEATURE_C64)) | |
3857 | base = REG_TYPE_CA_N_SP; | |
3858 | else | |
3859 | base = REG_TYPE_R64_SP; | |
3860 | ||
4df068de | 3861 | return parse_address_main (str, operand, &base_qualifier, &offset_qualifier, |
3493da5c | 3862 | base, REG_TYPE_R_Z, SHIFTED_NONE); |
4df068de RS |
3863 | } |
3864 | ||
98907a70 | 3865 | /* Parse an address in which SVE vector registers and MUL VL are allowed. |
4df068de RS |
3866 | The arguments have the same meaning as for parse_address_main. |
3867 | Return TRUE on success. */ | |
3868 | static bfd_boolean | |
3869 | parse_sve_address (char **str, aarch64_opnd_info *operand, | |
3870 | aarch64_opnd_qualifier_t *base_qualifier, | |
3871 | aarch64_opnd_qualifier_t *offset_qualifier) | |
3872 | { | |
3873 | return parse_address_main (str, operand, base_qualifier, offset_qualifier, | |
98907a70 RS |
3874 | REG_TYPE_SVE_BASE, REG_TYPE_SVE_OFFSET, |
3875 | SHIFTED_MUL_VL); | |
a06ea964 NC |
3876 | } |
3877 | ||
3878 | /* Parse an operand for a MOVZ, MOVN or MOVK instruction. | |
3879 | Return TRUE on success; otherwise return FALSE. */ | |
3880 | static bfd_boolean | |
3881 | parse_half (char **str, int *internal_fixup_p) | |
3882 | { | |
671eeb28 | 3883 | char *p = *str; |
a06ea964 | 3884 | |
a06ea964 NC |
3885 | skip_past_char (&p, '#'); |
3886 | ||
3887 | gas_assert (internal_fixup_p); | |
3888 | *internal_fixup_p = 0; | |
3889 | ||
3890 | if (*p == ':') | |
3891 | { | |
3892 | struct reloc_table_entry *entry; | |
3893 | ||
3894 | /* Try to parse a relocation. Anything else is an error. */ | |
3895 | ++p; | |
3896 | if (!(entry = find_reloc_table_entry (&p))) | |
3897 | { | |
3898 | set_syntax_error (_("unknown relocation modifier")); | |
3899 | return FALSE; | |
3900 | } | |
3901 | ||
3902 | if (entry->movw_type == 0) | |
3903 | { | |
3904 | set_syntax_error | |
3905 | (_("this relocation modifier is not allowed on this instruction")); | |
3906 | return FALSE; | |
3907 | } | |
3908 | ||
3909 | inst.reloc.type = entry->movw_type; | |
3910 | } | |
3911 | else | |
3912 | *internal_fixup_p = 1; | |
3913 | ||
a06ea964 NC |
3914 | if (! my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX, 1)) |
3915 | return FALSE; | |
3916 | ||
3917 | *str = p; | |
3918 | return TRUE; | |
3919 | } | |
3920 | ||
3921 | /* Parse an operand for an ADRP instruction: | |
3922 | ADRP <Xd>, <label> | |
3923 | Return TRUE on success; otherwise return FALSE. */ | |
3924 | ||
3925 | static bfd_boolean | |
3926 | parse_adrp (char **str) | |
3927 | { | |
3928 | char *p; | |
3929 | ||
3930 | p = *str; | |
3931 | if (*p == ':') | |
3932 | { | |
3933 | struct reloc_table_entry *entry; | |
3934 | ||
3935 | /* Try to parse a relocation. Anything else is an error. */ | |
3936 | ++p; | |
3937 | if (!(entry = find_reloc_table_entry (&p))) | |
3938 | { | |
3939 | set_syntax_error (_("unknown relocation modifier")); | |
3940 | return FALSE; | |
3941 | } | |
3942 | ||
3943 | if (entry->adrp_type == 0) | |
3944 | { | |
3945 | set_syntax_error | |
3946 | (_("this relocation modifier is not allowed on this instruction")); | |
3947 | return FALSE; | |
3948 | } | |
3949 | ||
3950 | inst.reloc.type = entry->adrp_type; | |
3951 | } | |
3952 | else | |
3953 | inst.reloc.type = BFD_RELOC_AARCH64_ADR_HI21_PCREL; | |
3954 | ||
3955 | inst.reloc.pc_rel = 1; | |
3956 | ||
3957 | if (! my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX, 1)) | |
3958 | return FALSE; | |
3959 | ||
3960 | *str = p; | |
3961 | return TRUE; | |
3962 | } | |
3963 | ||
3964 | /* Miscellaneous. */ | |
3965 | ||
245d2e3f RS |
3966 | /* Parse a symbolic operand such as "pow2" at *STR. ARRAY is an array |
3967 | of SIZE tokens in which index I gives the token for field value I, | |
3968 | or is null if field value I is invalid. REG_TYPE says which register | |
3969 | names should be treated as registers rather than as symbolic immediates. | |
3970 | ||
3971 | Return true on success, moving *STR past the operand and storing the | |
3972 | field value in *VAL. */ | |
3973 | ||
3974 | static int | |
3975 | parse_enum_string (char **str, int64_t *val, const char *const *array, | |
3976 | size_t size, aarch64_reg_type reg_type) | |
3977 | { | |
3978 | expressionS exp; | |
3979 | char *p, *q; | |
3980 | size_t i; | |
3981 | ||
3982 | /* Match C-like tokens. */ | |
3983 | p = q = *str; | |
3984 | while (ISALNUM (*q)) | |
3985 | q++; | |
3986 | ||
3987 | for (i = 0; i < size; ++i) | |
3988 | if (array[i] | |
3989 | && strncasecmp (array[i], p, q - p) == 0 | |
3990 | && array[i][q - p] == 0) | |
3991 | { | |
3992 | *val = i; | |
3993 | *str = q; | |
3994 | return TRUE; | |
3995 | } | |
3996 | ||
3997 | if (!parse_immediate_expression (&p, &exp, reg_type)) | |
3998 | return FALSE; | |
3999 | ||
4000 | if (exp.X_op == O_constant | |
4001 | && (uint64_t) exp.X_add_number < size) | |
4002 | { | |
4003 | *val = exp.X_add_number; | |
4004 | *str = p; | |
4005 | return TRUE; | |
4006 | } | |
4007 | ||
4008 | /* Use the default error for this operand. */ | |
4009 | return FALSE; | |
4010 | } | |
4011 | ||
a06ea964 NC |
4012 | /* Parse an option for a preload instruction. Returns the encoding for the |
4013 | option, or PARSE_FAIL. */ | |
4014 | ||
4015 | static int | |
4016 | parse_pldop (char **str) | |
4017 | { | |
4018 | char *p, *q; | |
4019 | const struct aarch64_name_value_pair *o; | |
4020 | ||
4021 | p = q = *str; | |
4022 | while (ISALNUM (*q)) | |
4023 | q++; | |
4024 | ||
629310ab | 4025 | o = str_hash_find_n (aarch64_pldop_hsh, p, q - p); |
a06ea964 NC |
4026 | if (!o) |
4027 | return PARSE_FAIL; | |
4028 | ||
4029 | *str = q; | |
4030 | return o->value; | |
4031 | } | |
4032 | ||
4033 | /* Parse an option for a barrier instruction. Returns the encoding for the | |
4034 | option, or PARSE_FAIL. */ | |
4035 | ||
4036 | static int | |
4037 | parse_barrier (char **str) | |
4038 | { | |
4039 | char *p, *q; | |
05cfb0d8 | 4040 | const struct aarch64_name_value_pair *o; |
a06ea964 NC |
4041 | |
4042 | p = q = *str; | |
4043 | while (ISALPHA (*q)) | |
4044 | q++; | |
4045 | ||
629310ab | 4046 | o = str_hash_find_n (aarch64_barrier_opt_hsh, p, q - p); |
a06ea964 NC |
4047 | if (!o) |
4048 | return PARSE_FAIL; | |
4049 | ||
4050 | *str = q; | |
4051 | return o->value; | |
4052 | } | |
4053 | ||
1e6f4800 MW |
4054 | /* Parse an operand for a PSB barrier. Set *HINT_OPT to the hint-option record |
4055 | return 0 if successful. Otherwise return PARSE_FAIL. */ | |
4056 | ||
4057 | static int | |
4058 | parse_barrier_psb (char **str, | |
4059 | const struct aarch64_name_value_pair ** hint_opt) | |
4060 | { | |
4061 | char *p, *q; | |
4062 | const struct aarch64_name_value_pair *o; | |
4063 | ||
4064 | p = q = *str; | |
4065 | while (ISALPHA (*q)) | |
4066 | q++; | |
4067 | ||
629310ab | 4068 | o = str_hash_find_n (aarch64_hint_opt_hsh, p, q - p); |
1e6f4800 MW |
4069 | if (!o) |
4070 | { | |
4071 | set_fatal_syntax_error | |
c2e5c986 | 4072 | ( _("unknown or missing option to PSB/TSB")); |
1e6f4800 MW |
4073 | return PARSE_FAIL; |
4074 | } | |
4075 | ||
4076 | if (o->value != 0x11) | |
4077 | { | |
4078 | /* PSB only accepts option name 'CSYNC'. */ | |
4079 | set_syntax_error | |
c2e5c986 | 4080 | (_("the specified option is not accepted for PSB/TSB")); |
1e6f4800 MW |
4081 | return PARSE_FAIL; |
4082 | } | |
4083 | ||
4084 | *str = q; | |
4085 | *hint_opt = o; | |
4086 | return 0; | |
4087 | } | |
4088 | ||
ff605452 SD |
4089 | /* Parse an operand for BTI. Set *HINT_OPT to the hint-option record |
4090 | return 0 if successful. Otherwise return PARSE_FAIL. */ | |
4091 | ||
4092 | static int | |
4093 | parse_bti_operand (char **str, | |
4094 | const struct aarch64_name_value_pair ** hint_opt) | |
4095 | { | |
4096 | char *p, *q; | |
4097 | const struct aarch64_name_value_pair *o; | |
4098 | ||
4099 | p = q = *str; | |
4100 | while (ISALPHA (*q)) | |
4101 | q++; | |
4102 | ||
629310ab | 4103 | o = str_hash_find_n (aarch64_hint_opt_hsh, p, q - p); |
ff605452 SD |
4104 | if (!o) |
4105 | { | |
4106 | set_fatal_syntax_error | |
4107 | ( _("unknown option to BTI")); | |
4108 | return PARSE_FAIL; | |
4109 | } | |
4110 | ||
4111 | switch (o->value) | |
4112 | { | |
4113 | /* Valid BTI operands. */ | |
4114 | case HINT_OPD_C: | |
4115 | case HINT_OPD_J: | |
4116 | case HINT_OPD_JC: | |
4117 | break; | |
4118 | ||
4119 | default: | |
4120 | set_syntax_error | |
4121 | (_("unknown option to BTI")); | |
4122 | return PARSE_FAIL; | |
4123 | } | |
4124 | ||
4125 | *str = q; | |
4126 | *hint_opt = o; | |
4127 | return 0; | |
4128 | } | |
4129 | ||
a06ea964 | 4130 | /* Parse a system register or a PSTATE field name for an MSR/MRS instruction. |
a203d9b7 | 4131 | Returns the encoding for the option, or PARSE_FAIL. |
a06ea964 NC |
4132 | |
4133 | If IMPLE_DEFINED_P is non-zero, the function will also try to parse the | |
72ca8fad MW |
4134 | implementation defined system register name S<op0>_<op1>_<Cn>_<Cm>_<op2>. |
4135 | ||
4136 | If PSTATEFIELD_P is non-zero, the function will parse the name as a PSTATE | |
4137 | field, otherwise as a system register. | |
4138 | */ | |
a06ea964 NC |
4139 | |
4140 | static int | |
629310ab | 4141 | parse_sys_reg (char **str, htab_t sys_regs, |
561a72d4 TC |
4142 | int imple_defined_p, int pstatefield_p, |
4143 | uint32_t* flags) | |
a06ea964 NC |
4144 | { |
4145 | char *p, *q; | |
fa63795f | 4146 | char buf[AARCH64_MAX_SYSREG_NAME_LEN]; |
49eec193 | 4147 | const aarch64_sys_reg *o; |
a06ea964 NC |
4148 | int value; |
4149 | ||
4150 | p = buf; | |
4151 | for (q = *str; ISALNUM (*q) || *q == '_'; q++) | |
fa63795f | 4152 | if (p < buf + (sizeof (buf) - 1)) |
a06ea964 NC |
4153 | *p++ = TOLOWER (*q); |
4154 | *p = '\0'; | |
fa63795f AC |
4155 | |
4156 | /* If the name is longer than AARCH64_MAX_SYSREG_NAME_LEN then it cannot be a | |
4157 | valid system register. This is enforced by construction of the hash | |
4158 | table. */ | |
4159 | if (p - buf != q - *str) | |
4160 | return PARSE_FAIL; | |
a06ea964 | 4161 | |
629310ab | 4162 | o = str_hash_find (sys_regs, buf); |
a06ea964 NC |
4163 | if (!o) |
4164 | { | |
4165 | if (!imple_defined_p) | |
4166 | return PARSE_FAIL; | |
4167 | else | |
4168 | { | |
df7b4545 | 4169 | /* Parse S<op0>_<op1>_<Cn>_<Cm>_<op2>. */ |
a06ea964 | 4170 | unsigned int op0, op1, cn, cm, op2; |
df7b4545 JW |
4171 | |
4172 | if (sscanf (buf, "s%u_%u_c%u_c%u_%u", &op0, &op1, &cn, &cm, &op2) | |
4173 | != 5) | |
a06ea964 | 4174 | return PARSE_FAIL; |
df7b4545 | 4175 | if (op0 > 3 || op1 > 7 || cn > 15 || cm > 15 || op2 > 7) |
a06ea964 NC |
4176 | return PARSE_FAIL; |
4177 | value = (op0 << 14) | (op1 << 11) | (cn << 7) | (cm << 3) | op2; | |
561a72d4 TC |
4178 | if (flags) |
4179 | *flags = 0; | |
a06ea964 NC |
4180 | } |
4181 | } | |
4182 | else | |
49eec193 | 4183 | { |
72ca8fad MW |
4184 | if (pstatefield_p && !aarch64_pstatefield_supported_p (cpu_variant, o)) |
4185 | as_bad (_("selected processor does not support PSTATE field " | |
4186 | "name '%s'"), buf); | |
f7cb161e | 4187 | if (!pstatefield_p |
38cf07a6 AC |
4188 | && !aarch64_sys_ins_reg_supported_p (cpu_variant, o->name, |
4189 | o->value, o->flags, o->features)) | |
72ca8fad MW |
4190 | as_bad (_("selected processor does not support system register " |
4191 | "name '%s'"), buf); | |
f7cb161e | 4192 | if (aarch64_sys_reg_deprecated_p (o->flags)) |
49eec193 | 4193 | as_warn (_("system register name '%s' is deprecated and may be " |
72ca8fad | 4194 | "removed in a future release"), buf); |
49eec193 | 4195 | value = o->value; |
561a72d4 TC |
4196 | if (flags) |
4197 | *flags = o->flags; | |
49eec193 | 4198 | } |
a06ea964 NC |
4199 | |
4200 | *str = q; | |
4201 | return value; | |
4202 | } | |
4203 | ||
4204 | /* Parse a system reg for ic/dc/at/tlbi instructions. Returns the table entry | |
4205 | for the option, or NULL. */ | |
4206 | ||
4207 | static const aarch64_sys_ins_reg * | |
629310ab | 4208 | parse_sys_ins_reg (char **str, htab_t sys_ins_regs) |
a06ea964 NC |
4209 | { |
4210 | char *p, *q; | |
fa63795f | 4211 | char buf[AARCH64_MAX_SYSREG_NAME_LEN]; |
a06ea964 NC |
4212 | const aarch64_sys_ins_reg *o; |
4213 | ||
4214 | p = buf; | |
4215 | for (q = *str; ISALNUM (*q) || *q == '_'; q++) | |
fa63795f | 4216 | if (p < buf + (sizeof (buf) - 1)) |
a06ea964 NC |
4217 | *p++ = TOLOWER (*q); |
4218 | *p = '\0'; | |
4219 | ||
fa63795f AC |
4220 | /* If the name is longer than AARCH64_MAX_SYSREG_NAME_LEN then it cannot be a |
4221 | valid system register. This is enforced by construction of the hash | |
4222 | table. */ | |
4223 | if (p - buf != q - *str) | |
4224 | return NULL; | |
4225 | ||
629310ab | 4226 | o = str_hash_find (sys_ins_regs, buf); |
a06ea964 NC |
4227 | if (!o) |
4228 | return NULL; | |
4229 | ||
38cf07a6 AC |
4230 | if (!aarch64_sys_ins_reg_supported_p (cpu_variant, |
4231 | o->name, o->value, o->flags, 0)) | |
d6bf7ce6 MW |
4232 | as_bad (_("selected processor does not support system register " |
4233 | "name '%s'"), buf); | |
f7cb161e PW |
4234 | if (aarch64_sys_reg_deprecated_p (o->flags)) |
4235 | as_warn (_("system register name '%s' is deprecated and may be " | |
4236 | "removed in a future release"), buf); | |
d6bf7ce6 | 4237 | |
a06ea964 NC |
4238 | *str = q; |
4239 | return o; | |
4240 | } | |
4241 | \f | |
4242 | #define po_char_or_fail(chr) do { \ | |
4243 | if (! skip_past_char (&str, chr)) \ | |
4244 | goto failure; \ | |
4245 | } while (0) | |
4246 | ||
4247 | #define po_reg_or_fail(regtype) do { \ | |
4248 | val = aarch64_reg_parse (&str, regtype, &rtype, NULL); \ | |
4249 | if (val == PARSE_FAIL) \ | |
4250 | { \ | |
4251 | set_default_error (); \ | |
4252 | goto failure; \ | |
4253 | } \ | |
4254 | } while (0) | |
4255 | ||
e1b988bb RS |
4256 | #define po_int_reg_or_fail(reg_type) do { \ |
4257 | reg = aarch64_reg_parse_32_64 (&str, &qualifier); \ | |
4258 | if (!reg || !aarch64_check_reg_type (reg, reg_type)) \ | |
a06ea964 NC |
4259 | { \ |
4260 | set_default_error (); \ | |
4261 | goto failure; \ | |
4262 | } \ | |
e1b988bb RS |
4263 | info->reg.regno = reg->number; \ |
4264 | info->qualifier = qualifier; \ | |
a06ea964 NC |
4265 | } while (0) |
4266 | ||
4267 | #define po_imm_nc_or_fail() do { \ | |
1799c0d0 | 4268 | if (! parse_constant_immediate (&str, &val, imm_reg_type)) \ |
a06ea964 NC |
4269 | goto failure; \ |
4270 | } while (0) | |
4271 | ||
4272 | #define po_imm_or_fail(min, max) do { \ | |
1799c0d0 | 4273 | if (! parse_constant_immediate (&str, &val, imm_reg_type)) \ |
a06ea964 NC |
4274 | goto failure; \ |
4275 | if (val < min || val > max) \ | |
4276 | { \ | |
4277 | set_fatal_syntax_error (_("immediate value out of range "\ | |
4278 | #min " to "#max)); \ | |
4279 | goto failure; \ | |
4280 | } \ | |
4281 | } while (0) | |
4282 | ||
245d2e3f RS |
4283 | #define po_enum_or_fail(array) do { \ |
4284 | if (!parse_enum_string (&str, &val, array, \ | |
4285 | ARRAY_SIZE (array), imm_reg_type)) \ | |
4286 | goto failure; \ | |
4287 | } while (0) | |
4288 | ||
a06ea964 NC |
4289 | #define po_misc_or_fail(expr) do { \ |
4290 | if (!expr) \ | |
4291 | goto failure; \ | |
4292 | } while (0) | |
4293 | \f | |
4294 | /* encode the 12-bit imm field of Add/sub immediate */ | |
4295 | static inline uint32_t | |
4296 | encode_addsub_imm (uint32_t imm) | |
4297 | { | |
4298 | return imm << 10; | |
4299 | } | |
4300 | ||
4301 | /* encode the shift amount field of Add/sub immediate */ | |
4302 | static inline uint32_t | |
4303 | encode_addsub_imm_shift_amount (uint32_t cnt) | |
4304 | { | |
4305 | return cnt << 22; | |
4306 | } | |
4307 | ||
4308 | ||
4309 | /* encode the imm field of Adr instruction */ | |
4310 | static inline uint32_t | |
4311 | encode_adr_imm (uint32_t imm) | |
4312 | { | |
4313 | return (((imm & 0x3) << 29) /* [1:0] -> [30:29] */ | |
4314 | | ((imm & (0x7ffff << 2)) << 3)); /* [20:2] -> [23:5] */ | |
4315 | } | |
4316 | ||
4317 | /* encode the immediate field of Move wide immediate */ | |
4318 | static inline uint32_t | |
4319 | encode_movw_imm (uint32_t imm) | |
4320 | { | |
4321 | return imm << 5; | |
4322 | } | |
4323 | ||
4324 | /* encode the 26-bit offset of unconditional branch */ | |
4325 | static inline uint32_t | |
4326 | encode_branch_ofs_26 (uint32_t ofs) | |
4327 | { | |
4328 | return ofs & ((1 << 26) - 1); | |
4329 | } | |
4330 | ||
4331 | /* encode the 19-bit offset of conditional branch and compare & branch */ | |
4332 | static inline uint32_t | |
4333 | encode_cond_branch_ofs_19 (uint32_t ofs) | |
4334 | { | |
4335 | return (ofs & ((1 << 19) - 1)) << 5; | |
4336 | } | |
4337 | ||
4338 | /* encode the 19-bit offset of ld literal */ | |
4339 | static inline uint32_t | |
4340 | encode_ld_lit_ofs_19 (uint32_t ofs) | |
4341 | { | |
4342 | return (ofs & ((1 << 19) - 1)) << 5; | |
4343 | } | |
4344 | ||
4345 | /* Encode the 14-bit offset of test & branch. */ | |
4346 | static inline uint32_t | |
4347 | encode_tst_branch_ofs_14 (uint32_t ofs) | |
4348 | { | |
4349 | return (ofs & ((1 << 14) - 1)) << 5; | |
4350 | } | |
4351 | ||
4352 | /* Encode the 16-bit imm field of svc/hvc/smc. */ | |
4353 | static inline uint32_t | |
4354 | encode_svc_imm (uint32_t imm) | |
4355 | { | |
4356 | return imm << 5; | |
4357 | } | |
4358 | ||
4359 | /* Reencode add(s) to sub(s), or sub(s) to add(s). */ | |
4360 | static inline uint32_t | |
4361 | reencode_addsub_switch_add_sub (uint32_t opcode) | |
4362 | { | |
4363 | return opcode ^ (1 << 30); | |
4364 | } | |
4365 | ||
4366 | static inline uint32_t | |
4367 | reencode_movzn_to_movz (uint32_t opcode) | |
4368 | { | |
4369 | return opcode | (1 << 30); | |
4370 | } | |
4371 | ||
4372 | static inline uint32_t | |
4373 | reencode_movzn_to_movn (uint32_t opcode) | |
4374 | { | |
4375 | return opcode & ~(1 << 30); | |
4376 | } | |
4377 | ||
4378 | /* Overall per-instruction processing. */ | |
4379 | ||
4380 | /* We need to be able to fix up arbitrary expressions in some statements. | |
4381 | This is so that we can handle symbols that are an arbitrary distance from | |
4382 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
4383 | which returns part of an address in a form which will be valid for | |
4384 | a data instruction. We do this by pushing the expression into a symbol | |
4385 | in the expr_section, and creating a fix for that. */ | |
4386 | ||
4387 | static fixS * | |
4388 | fix_new_aarch64 (fragS * frag, | |
4389 | int where, | |
f7cb161e PW |
4390 | short int size, |
4391 | expressionS * exp, | |
4392 | int pc_rel, | |
4393 | int reloc) | |
a06ea964 NC |
4394 | { |
4395 | fixS *new_fix; | |
4396 | ||
4397 | switch (exp->X_op) | |
4398 | { | |
4399 | case O_constant: | |
4400 | case O_symbol: | |
4401 | case O_add: | |
4402 | case O_subtract: | |
4403 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
4404 | break; | |
4405 | ||
4406 | default: | |
4407 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
4408 | pc_rel, reloc); | |
4409 | break; | |
4410 | } | |
4411 | return new_fix; | |
4412 | } | |
4413 | \f | |
4414 | /* Diagnostics on operands errors. */ | |
4415 | ||
a52e6fd3 YZ |
4416 | /* By default, output verbose error message. |
4417 | Disable the verbose error message by -mno-verbose-error. */ | |
4418 | static int verbose_error_p = 1; | |
a06ea964 NC |
4419 | |
4420 | #ifdef DEBUG_AARCH64 | |
4421 | /* N.B. this is only for the purpose of debugging. */ | |
4422 | const char* operand_mismatch_kind_names[] = | |
4423 | { | |
4424 | "AARCH64_OPDE_NIL", | |
4425 | "AARCH64_OPDE_RECOVERABLE", | |
4426 | "AARCH64_OPDE_SYNTAX_ERROR", | |
4427 | "AARCH64_OPDE_FATAL_SYNTAX_ERROR", | |
4428 | "AARCH64_OPDE_INVALID_VARIANT", | |
4429 | "AARCH64_OPDE_OUT_OF_RANGE", | |
4430 | "AARCH64_OPDE_UNALIGNED", | |
4431 | "AARCH64_OPDE_REG_LIST", | |
4432 | "AARCH64_OPDE_OTHER_ERROR", | |
4433 | }; | |
4434 | #endif /* DEBUG_AARCH64 */ | |
4435 | ||
4436 | /* Return TRUE if LHS is of higher severity than RHS, otherwise return FALSE. | |
4437 | ||
4438 | When multiple errors of different kinds are found in the same assembly | |
4439 | line, only the error of the highest severity will be picked up for | |
4440 | issuing the diagnostics. */ | |
4441 | ||
4442 | static inline bfd_boolean | |
4443 | operand_error_higher_severity_p (enum aarch64_operand_error_kind lhs, | |
4444 | enum aarch64_operand_error_kind rhs) | |
4445 | { | |
4446 | gas_assert (AARCH64_OPDE_RECOVERABLE > AARCH64_OPDE_NIL); | |
4447 | gas_assert (AARCH64_OPDE_SYNTAX_ERROR > AARCH64_OPDE_RECOVERABLE); | |
4448 | gas_assert (AARCH64_OPDE_FATAL_SYNTAX_ERROR > AARCH64_OPDE_SYNTAX_ERROR); | |
4449 | gas_assert (AARCH64_OPDE_INVALID_VARIANT > AARCH64_OPDE_FATAL_SYNTAX_ERROR); | |
4450 | gas_assert (AARCH64_OPDE_OUT_OF_RANGE > AARCH64_OPDE_INVALID_VARIANT); | |
4451 | gas_assert (AARCH64_OPDE_UNALIGNED > AARCH64_OPDE_OUT_OF_RANGE); | |
4452 | gas_assert (AARCH64_OPDE_REG_LIST > AARCH64_OPDE_UNALIGNED); | |
4453 | gas_assert (AARCH64_OPDE_OTHER_ERROR > AARCH64_OPDE_REG_LIST); | |
4454 | return lhs > rhs; | |
4455 | } | |
4456 | ||
4457 | /* Helper routine to get the mnemonic name from the assembly instruction | |
4458 | line; should only be called for the diagnosis purpose, as there is | |
4459 | string copy operation involved, which may affect the runtime | |
4460 | performance if used in elsewhere. */ | |
4461 | ||
4462 | static const char* | |
4463 | get_mnemonic_name (const char *str) | |
4464 | { | |
4465 | static char mnemonic[32]; | |
4466 | char *ptr; | |
4467 | ||
4468 | /* Get the first 15 bytes and assume that the full name is included. */ | |
4469 | strncpy (mnemonic, str, 31); | |
4470 | mnemonic[31] = '\0'; | |
4471 | ||
4472 | /* Scan up to the end of the mnemonic, which must end in white space, | |
4473 | '.', or end of string. */ | |
4474 | for (ptr = mnemonic; is_part_of_name(*ptr); ++ptr) | |
4475 | ; | |
4476 | ||
4477 | *ptr = '\0'; | |
4478 | ||
4479 | /* Append '...' to the truncated long name. */ | |
4480 | if (ptr - mnemonic == 31) | |
4481 | mnemonic[28] = mnemonic[29] = mnemonic[30] = '.'; | |
4482 | ||
4483 | return mnemonic; | |
4484 | } | |
4485 | ||
4486 | static void | |
4487 | reset_aarch64_instruction (aarch64_instruction *instruction) | |
4488 | { | |
4489 | memset (instruction, '\0', sizeof (aarch64_instruction)); | |
4490 | instruction->reloc.type = BFD_RELOC_UNUSED; | |
4491 | } | |
4492 | ||
33eaf5de | 4493 | /* Data structures storing one user error in the assembly code related to |
a06ea964 NC |
4494 | operands. */ |
4495 | ||
4496 | struct operand_error_record | |
4497 | { | |
4498 | const aarch64_opcode *opcode; | |
4499 | aarch64_operand_error detail; | |
4500 | struct operand_error_record *next; | |
4501 | }; | |
4502 | ||
4503 | typedef struct operand_error_record operand_error_record; | |
4504 | ||
4505 | struct operand_errors | |
4506 | { | |
4507 | operand_error_record *head; | |
4508 | operand_error_record *tail; | |
4509 | }; | |
4510 | ||
4511 | typedef struct operand_errors operand_errors; | |
4512 | ||
4513 | /* Top-level data structure reporting user errors for the current line of | |
4514 | the assembly code. | |
4515 | The way md_assemble works is that all opcodes sharing the same mnemonic | |
4516 | name are iterated to find a match to the assembly line. In this data | |
4517 | structure, each of the such opcodes will have one operand_error_record | |
4518 | allocated and inserted. In other words, excessive errors related with | |
4519 | a single opcode are disregarded. */ | |
4520 | operand_errors operand_error_report; | |
4521 | ||
4522 | /* Free record nodes. */ | |
4523 | static operand_error_record *free_opnd_error_record_nodes = NULL; | |
4524 | ||
4525 | /* Initialize the data structure that stores the operand mismatch | |
4526 | information on assembling one line of the assembly code. */ | |
4527 | static void | |
4528 | init_operand_error_report (void) | |
4529 | { | |
4530 | if (operand_error_report.head != NULL) | |
4531 | { | |
4532 | gas_assert (operand_error_report.tail != NULL); | |
4533 | operand_error_report.tail->next = free_opnd_error_record_nodes; | |
4534 | free_opnd_error_record_nodes = operand_error_report.head; | |
4535 | operand_error_report.head = NULL; | |
4536 | operand_error_report.tail = NULL; | |
4537 | return; | |
4538 | } | |
4539 | gas_assert (operand_error_report.tail == NULL); | |
4540 | } | |
4541 | ||
4542 | /* Return TRUE if some operand error has been recorded during the | |
4543 | parsing of the current assembly line using the opcode *OPCODE; | |
4544 | otherwise return FALSE. */ | |
4545 | static inline bfd_boolean | |
4546 | opcode_has_operand_error_p (const aarch64_opcode *opcode) | |
4547 | { | |
4548 | operand_error_record *record = operand_error_report.head; | |
4549 | return record && record->opcode == opcode; | |
4550 | } | |
4551 | ||
4552 | /* Add the error record *NEW_RECORD to operand_error_report. The record's | |
4553 | OPCODE field is initialized with OPCODE. | |
4554 | N.B. only one record for each opcode, i.e. the maximum of one error is | |
4555 | recorded for each instruction template. */ | |
4556 | ||
4557 | static void | |
4558 | add_operand_error_record (const operand_error_record* new_record) | |
4559 | { | |
4560 | const aarch64_opcode *opcode = new_record->opcode; | |
4561 | operand_error_record* record = operand_error_report.head; | |
4562 | ||
4563 | /* The record may have been created for this opcode. If not, we need | |
4564 | to prepare one. */ | |
4565 | if (! opcode_has_operand_error_p (opcode)) | |
4566 | { | |
4567 | /* Get one empty record. */ | |
4568 | if (free_opnd_error_record_nodes == NULL) | |
4569 | { | |
325801bd | 4570 | record = XNEW (operand_error_record); |
a06ea964 NC |
4571 | } |
4572 | else | |
4573 | { | |
4574 | record = free_opnd_error_record_nodes; | |
4575 | free_opnd_error_record_nodes = record->next; | |
4576 | } | |
4577 | record->opcode = opcode; | |
4578 | /* Insert at the head. */ | |
4579 | record->next = operand_error_report.head; | |
4580 | operand_error_report.head = record; | |
4581 | if (operand_error_report.tail == NULL) | |
4582 | operand_error_report.tail = record; | |
4583 | } | |
4584 | else if (record->detail.kind != AARCH64_OPDE_NIL | |
4585 | && record->detail.index <= new_record->detail.index | |
4586 | && operand_error_higher_severity_p (record->detail.kind, | |
4587 | new_record->detail.kind)) | |
4588 | { | |
4589 | /* In the case of multiple errors found on operands related with a | |
4590 | single opcode, only record the error of the leftmost operand and | |
4591 | only if the error is of higher severity. */ | |
4592 | DEBUG_TRACE ("error %s on operand %d not added to the report due to" | |
4593 | " the existing error %s on operand %d", | |
4594 | operand_mismatch_kind_names[new_record->detail.kind], | |
4595 | new_record->detail.index, | |
4596 | operand_mismatch_kind_names[record->detail.kind], | |
4597 | record->detail.index); | |
4598 | return; | |
4599 | } | |
4600 | ||
4601 | record->detail = new_record->detail; | |
4602 | } | |
4603 | ||
4604 | static inline void | |
4605 | record_operand_error_info (const aarch64_opcode *opcode, | |
4606 | aarch64_operand_error *error_info) | |
4607 | { | |
4608 | operand_error_record record; | |
4609 | record.opcode = opcode; | |
4610 | record.detail = *error_info; | |
4611 | add_operand_error_record (&record); | |
4612 | } | |
4613 | ||
4614 | /* Record an error of kind KIND and, if ERROR is not NULL, of the detailed | |
4615 | error message *ERROR, for operand IDX (count from 0). */ | |
4616 | ||
4617 | static void | |
4618 | record_operand_error (const aarch64_opcode *opcode, int idx, | |
4619 | enum aarch64_operand_error_kind kind, | |
4620 | const char* error) | |
4621 | { | |
4622 | aarch64_operand_error info; | |
4623 | memset(&info, 0, sizeof (info)); | |
4624 | info.index = idx; | |
4625 | info.kind = kind; | |
4626 | info.error = error; | |
2a9b2c1a | 4627 | info.non_fatal = FALSE; |
a06ea964 NC |
4628 | record_operand_error_info (opcode, &info); |
4629 | } | |
4630 | ||
4631 | static void | |
4632 | record_operand_error_with_data (const aarch64_opcode *opcode, int idx, | |
4633 | enum aarch64_operand_error_kind kind, | |
4634 | const char* error, const int *extra_data) | |
4635 | { | |
4636 | aarch64_operand_error info; | |
4637 | info.index = idx; | |
4638 | info.kind = kind; | |
4639 | info.error = error; | |
4640 | info.data[0] = extra_data[0]; | |
4641 | info.data[1] = extra_data[1]; | |
4642 | info.data[2] = extra_data[2]; | |
2a9b2c1a | 4643 | info.non_fatal = FALSE; |
a06ea964 NC |
4644 | record_operand_error_info (opcode, &info); |
4645 | } | |
4646 | ||
4647 | static void | |
4648 | record_operand_out_of_range_error (const aarch64_opcode *opcode, int idx, | |
4649 | const char* error, int lower_bound, | |
4650 | int upper_bound) | |
4651 | { | |
4652 | int data[3] = {lower_bound, upper_bound, 0}; | |
4653 | record_operand_error_with_data (opcode, idx, AARCH64_OPDE_OUT_OF_RANGE, | |
4654 | error, data); | |
4655 | } | |
4656 | ||
4657 | /* Remove the operand error record for *OPCODE. */ | |
4658 | static void ATTRIBUTE_UNUSED | |
4659 | remove_operand_error_record (const aarch64_opcode *opcode) | |
4660 | { | |
4661 | if (opcode_has_operand_error_p (opcode)) | |
4662 | { | |
4663 | operand_error_record* record = operand_error_report.head; | |
4664 | gas_assert (record != NULL && operand_error_report.tail != NULL); | |
4665 | operand_error_report.head = record->next; | |
4666 | record->next = free_opnd_error_record_nodes; | |
4667 | free_opnd_error_record_nodes = record; | |
4668 | if (operand_error_report.head == NULL) | |
4669 | { | |
4670 | gas_assert (operand_error_report.tail == record); | |
4671 | operand_error_report.tail = NULL; | |
4672 | } | |
4673 | } | |
4674 | } | |
4675 | ||
4676 | /* Given the instruction in *INSTR, return the index of the best matched | |
4677 | qualifier sequence in the list (an array) headed by QUALIFIERS_LIST. | |
4678 | ||
4679 | Return -1 if there is no qualifier sequence; return the first match | |
4680 | if there is multiple matches found. */ | |
4681 | ||
4682 | static int | |
4683 | find_best_match (const aarch64_inst *instr, | |
4684 | const aarch64_opnd_qualifier_seq_t *qualifiers_list) | |
4685 | { | |
4686 | int i, num_opnds, max_num_matched, idx; | |
4687 | ||
4688 | num_opnds = aarch64_num_of_operands (instr->opcode); | |
4689 | if (num_opnds == 0) | |
4690 | { | |
4691 | DEBUG_TRACE ("no operand"); | |
4692 | return -1; | |
4693 | } | |
4694 | ||
4695 | max_num_matched = 0; | |
4989adac | 4696 | idx = 0; |
a06ea964 NC |
4697 | |
4698 | /* For each pattern. */ | |
4699 | for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list) | |
4700 | { | |
4701 | int j, num_matched; | |
4702 | const aarch64_opnd_qualifier_t *qualifiers = *qualifiers_list; | |
4703 | ||
4704 | /* Most opcodes has much fewer patterns in the list. */ | |
535b785f | 4705 | if (empty_qualifier_sequence_p (qualifiers)) |
a06ea964 NC |
4706 | { |
4707 | DEBUG_TRACE_IF (i == 0, "empty list of qualifier sequence"); | |
a06ea964 NC |
4708 | break; |
4709 | } | |
4710 | ||
4711 | for (j = 0, num_matched = 0; j < num_opnds; ++j, ++qualifiers) | |
4712 | if (*qualifiers == instr->operands[j].qualifier) | |
4713 | ++num_matched; | |
4714 | ||
4715 | if (num_matched > max_num_matched) | |
4716 | { | |
4717 | max_num_matched = num_matched; | |
4718 | idx = i; | |
4719 | } | |
4720 | } | |
4721 | ||
4722 | DEBUG_TRACE ("return with %d", idx); | |
4723 | return idx; | |
4724 | } | |
4725 | ||
33eaf5de | 4726 | /* Assign qualifiers in the qualifier sequence (headed by QUALIFIERS) to the |
a06ea964 NC |
4727 | corresponding operands in *INSTR. */ |
4728 | ||
4729 | static inline void | |
4730 | assign_qualifier_sequence (aarch64_inst *instr, | |
4731 | const aarch64_opnd_qualifier_t *qualifiers) | |
4732 | { | |
4733 | int i = 0; | |
4734 | int num_opnds = aarch64_num_of_operands (instr->opcode); | |
4735 | gas_assert (num_opnds); | |
4736 | for (i = 0; i < num_opnds; ++i, ++qualifiers) | |
4737 | instr->operands[i].qualifier = *qualifiers; | |
4738 | } | |
4739 | ||
4740 | /* Print operands for the diagnosis purpose. */ | |
4741 | ||
4742 | static void | |
4743 | print_operands (char *buf, const aarch64_opcode *opcode, | |
4744 | const aarch64_opnd_info *opnds) | |
4745 | { | |
4746 | int i; | |
4747 | ||
4748 | for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) | |
4749 | { | |
08d3b0cc | 4750 | char str[128]; |
a06ea964 NC |
4751 | |
4752 | /* We regard the opcode operand info more, however we also look into | |
4753 | the inst->operands to support the disassembling of the optional | |
4754 | operand. | |
4755 | The two operand code should be the same in all cases, apart from | |
4756 | when the operand can be optional. */ | |
4757 | if (opcode->operands[i] == AARCH64_OPND_NIL | |
4758 | || opnds[i].type == AARCH64_OPND_NIL) | |
4759 | break; | |
4760 | ||
4761 | /* Generate the operand string in STR. */ | |
7d02540a | 4762 | aarch64_print_operand (str, sizeof (str), 0, opcode, opnds, i, NULL, NULL, |
38cf07a6 | 4763 | NULL, cpu_variant); |
a06ea964 NC |
4764 | |
4765 | /* Delimiter. */ | |
4766 | if (str[0] != '\0') | |
ad43e107 | 4767 | strcat (buf, i == 0 ? " " : ", "); |
a06ea964 NC |
4768 | |
4769 | /* Append the operand string. */ | |
4770 | strcat (buf, str); | |
4771 | } | |
4772 | } | |
4773 | ||
4774 | /* Send to stderr a string as information. */ | |
4775 | ||
4776 | static void | |
4777 | output_info (const char *format, ...) | |
4778 | { | |
3b4dbbbf | 4779 | const char *file; |
a06ea964 NC |
4780 | unsigned int line; |
4781 | va_list args; | |
4782 | ||
3b4dbbbf | 4783 | file = as_where (&line); |
a06ea964 NC |
4784 | if (file) |
4785 | { | |
4786 | if (line != 0) | |
4787 | fprintf (stderr, "%s:%u: ", file, line); | |
4788 | else | |
4789 | fprintf (stderr, "%s: ", file); | |
4790 | } | |
4791 | fprintf (stderr, _("Info: ")); | |
4792 | va_start (args, format); | |
4793 | vfprintf (stderr, format, args); | |
4794 | va_end (args); | |
4795 | (void) putc ('\n', stderr); | |
4796 | } | |
4797 | ||
4798 | /* Output one operand error record. */ | |
4799 | ||
4800 | static void | |
4801 | output_operand_error_record (const operand_error_record *record, char *str) | |
4802 | { | |
28f013d5 JB |
4803 | const aarch64_operand_error *detail = &record->detail; |
4804 | int idx = detail->index; | |
a06ea964 | 4805 | const aarch64_opcode *opcode = record->opcode; |
28f013d5 | 4806 | enum aarch64_opnd opd_code = (idx >= 0 ? opcode->operands[idx] |
a06ea964 | 4807 | : AARCH64_OPND_NIL); |
a06ea964 | 4808 | |
7d02540a TC |
4809 | typedef void (*handler_t)(const char *format, ...); |
4810 | handler_t handler = detail->non_fatal ? as_warn : as_bad; | |
4811 | ||
a06ea964 NC |
4812 | switch (detail->kind) |
4813 | { | |
4814 | case AARCH64_OPDE_NIL: | |
4815 | gas_assert (0); | |
4816 | break; | |
a06ea964 NC |
4817 | case AARCH64_OPDE_SYNTAX_ERROR: |
4818 | case AARCH64_OPDE_RECOVERABLE: | |
4819 | case AARCH64_OPDE_FATAL_SYNTAX_ERROR: | |
4820 | case AARCH64_OPDE_OTHER_ERROR: | |
a06ea964 NC |
4821 | /* Use the prepared error message if there is, otherwise use the |
4822 | operand description string to describe the error. */ | |
4823 | if (detail->error != NULL) | |
4824 | { | |
28f013d5 | 4825 | if (idx < 0) |
7d02540a | 4826 | handler (_("%s -- `%s'"), detail->error, str); |
a06ea964 | 4827 | else |
7d02540a TC |
4828 | handler (_("%s at operand %d -- `%s'"), |
4829 | detail->error, idx + 1, str); | |
a06ea964 NC |
4830 | } |
4831 | else | |
28f013d5 JB |
4832 | { |
4833 | gas_assert (idx >= 0); | |
7d02540a TC |
4834 | handler (_("operand %d must be %s -- `%s'"), idx + 1, |
4835 | aarch64_get_operand_desc (opd_code), str); | |
28f013d5 | 4836 | } |
a06ea964 NC |
4837 | break; |
4838 | ||
4839 | case AARCH64_OPDE_INVALID_VARIANT: | |
7d02540a | 4840 | handler (_("operand mismatch -- `%s'"), str); |
a06ea964 NC |
4841 | if (verbose_error_p) |
4842 | { | |
4843 | /* We will try to correct the erroneous instruction and also provide | |
4844 | more information e.g. all other valid variants. | |
4845 | ||
4846 | The string representation of the corrected instruction and other | |
4847 | valid variants are generated by | |
4848 | ||
4849 | 1) obtaining the intermediate representation of the erroneous | |
4850 | instruction; | |
4851 | 2) manipulating the IR, e.g. replacing the operand qualifier; | |
4852 | 3) printing out the instruction by calling the printer functions | |
4853 | shared with the disassembler. | |
4854 | ||
4855 | The limitation of this method is that the exact input assembly | |
4856 | line cannot be accurately reproduced in some cases, for example an | |
4857 | optional operand present in the actual assembly line will be | |
4858 | omitted in the output; likewise for the optional syntax rules, | |
4859 | e.g. the # before the immediate. Another limitation is that the | |
4860 | assembly symbols and relocation operations in the assembly line | |
4861 | currently cannot be printed out in the error report. Last but not | |
4862 | least, when there is other error(s) co-exist with this error, the | |
4863 | 'corrected' instruction may be still incorrect, e.g. given | |
4864 | 'ldnp h0,h1,[x0,#6]!' | |
4865 | this diagnosis will provide the version: | |
4866 | 'ldnp s0,s1,[x0,#6]!' | |
4867 | which is still not right. */ | |
4868 | size_t len = strlen (get_mnemonic_name (str)); | |
4869 | int i, qlf_idx; | |
4870 | bfd_boolean result; | |
08d3b0cc | 4871 | char buf[2048]; |
a06ea964 NC |
4872 | aarch64_inst *inst_base = &inst.base; |
4873 | const aarch64_opnd_qualifier_seq_t *qualifiers_list; | |
4874 | ||
4875 | /* Init inst. */ | |
4876 | reset_aarch64_instruction (&inst); | |
4877 | inst_base->opcode = opcode; | |
4878 | ||
4879 | /* Reset the error report so that there is no side effect on the | |
4880 | following operand parsing. */ | |
4881 | init_operand_error_report (); | |
4882 | ||
4883 | /* Fill inst. */ | |
4884 | result = parse_operands (str + len, opcode) | |
4885 | && programmer_friendly_fixup (&inst); | |
4886 | gas_assert (result); | |
3979cf50 SP |
4887 | result = aarch64_opcode_encode (cpu_variant, opcode, inst_base, |
4888 | &inst_base->value, NULL, NULL, | |
4889 | insn_sequence); | |
a06ea964 NC |
4890 | gas_assert (!result); |
4891 | ||
4892 | /* Find the most matched qualifier sequence. */ | |
4893 | qlf_idx = find_best_match (inst_base, opcode->qualifiers_list); | |
4894 | gas_assert (qlf_idx > -1); | |
4895 | ||
4896 | /* Assign the qualifiers. */ | |
4897 | assign_qualifier_sequence (inst_base, | |
4898 | opcode->qualifiers_list[qlf_idx]); | |
4899 | ||
4900 | /* Print the hint. */ | |
4901 | output_info (_(" did you mean this?")); | |
08d3b0cc | 4902 | snprintf (buf, sizeof (buf), "\t%s", get_mnemonic_name (str)); |
a06ea964 NC |
4903 | print_operands (buf, opcode, inst_base->operands); |
4904 | output_info (_(" %s"), buf); | |
4905 | ||
4906 | /* Print out other variant(s) if there is any. */ | |
4907 | if (qlf_idx != 0 || | |
4908 | !empty_qualifier_sequence_p (opcode->qualifiers_list[1])) | |
4909 | output_info (_(" other valid variant(s):")); | |
4910 | ||
4911 | /* For each pattern. */ | |
4912 | qualifiers_list = opcode->qualifiers_list; | |
4913 | for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list) | |
4914 | { | |
4915 | /* Most opcodes has much fewer patterns in the list. | |
4916 | First NIL qualifier indicates the end in the list. */ | |
535b785f | 4917 | if (empty_qualifier_sequence_p (*qualifiers_list)) |
a06ea964 NC |
4918 | break; |
4919 | ||
4920 | if (i != qlf_idx) | |
4921 | { | |
4922 | /* Mnemonics name. */ | |
08d3b0cc | 4923 | snprintf (buf, sizeof (buf), "\t%s", get_mnemonic_name (str)); |
a06ea964 NC |
4924 | |
4925 | /* Assign the qualifiers. */ | |
4926 | assign_qualifier_sequence (inst_base, *qualifiers_list); | |
4927 | ||
4928 | /* Print instruction. */ | |
4929 | print_operands (buf, opcode, inst_base->operands); | |
4930 | ||
4931 | output_info (_(" %s"), buf); | |
4932 | } | |
4933 | } | |
4934 | } | |
4935 | break; | |
4936 | ||
0c608d6b | 4937 | case AARCH64_OPDE_UNTIED_OPERAND: |
7d02540a TC |
4938 | handler (_("operand %d must be the same register as operand 1 -- `%s'"), |
4939 | detail->index + 1, str); | |
0c608d6b RS |
4940 | break; |
4941 | ||
a06ea964 | 4942 | case AARCH64_OPDE_OUT_OF_RANGE: |
f5555712 | 4943 | if (detail->data[0] != detail->data[1]) |
7d02540a TC |
4944 | handler (_("%s out of range %d to %d at operand %d -- `%s'"), |
4945 | detail->error ? detail->error : _("immediate value"), | |
4946 | detail->data[0], detail->data[1], idx + 1, str); | |
f5555712 | 4947 | else |
7d02540a TC |
4948 | handler (_("%s must be %d at operand %d -- `%s'"), |
4949 | detail->error ? detail->error : _("immediate value"), | |
4950 | detail->data[0], idx + 1, str); | |
a06ea964 NC |
4951 | break; |
4952 | ||
4953 | case AARCH64_OPDE_REG_LIST: | |
4954 | if (detail->data[0] == 1) | |
7d02540a TC |
4955 | handler (_("invalid number of registers in the list; " |
4956 | "only 1 register is expected at operand %d -- `%s'"), | |
4957 | idx + 1, str); | |
a06ea964 | 4958 | else |
7d02540a TC |
4959 | handler (_("invalid number of registers in the list; " |
4960 | "%d registers are expected at operand %d -- `%s'"), | |
4961 | detail->data[0], idx + 1, str); | |
a06ea964 NC |
4962 | break; |
4963 | ||
4964 | case AARCH64_OPDE_UNALIGNED: | |
7d02540a TC |
4965 | handler (_("immediate value must be a multiple of " |
4966 | "%d at operand %d -- `%s'"), | |
4967 | detail->data[0], idx + 1, str); | |
a06ea964 NC |
4968 | break; |
4969 | ||
4970 | default: | |
4971 | gas_assert (0); | |
4972 | break; | |
4973 | } | |
4974 | } | |
4975 | ||
4976 | /* Process and output the error message about the operand mismatching. | |
4977 | ||
4978 | When this function is called, the operand error information had | |
4979 | been collected for an assembly line and there will be multiple | |
33eaf5de | 4980 | errors in the case of multiple instruction templates; output the |
7d02540a TC |
4981 | error message that most closely describes the problem. |
4982 | ||
4983 | The errors to be printed can be filtered on printing all errors | |
4984 | or only non-fatal errors. This distinction has to be made because | |
4985 | the error buffer may already be filled with fatal errors we don't want to | |
4986 | print due to the different instruction templates. */ | |
a06ea964 NC |
4987 | |
4988 | static void | |
7d02540a | 4989 | output_operand_error_report (char *str, bfd_boolean non_fatal_only) |
a06ea964 | 4990 | { |
261dde89 SP |
4991 | int largest_error_pos, largest_error_pos2; |
4992 | const char *msg = NULL, *msg2 = NULL; | |
a06ea964 NC |
4993 | enum aarch64_operand_error_kind kind; |
4994 | operand_error_record *curr; | |
4995 | operand_error_record *head = operand_error_report.head; | |
261dde89 | 4996 | operand_error_record *record = NULL, *record2 = NULL; |
a06ea964 NC |
4997 | |
4998 | /* No error to report. */ | |
4999 | if (head == NULL) | |
5000 | return; | |
5001 | ||
5002 | gas_assert (head != NULL && operand_error_report.tail != NULL); | |
5003 | ||
5004 | /* Only one error. */ | |
5005 | if (head == operand_error_report.tail) | |
5006 | { | |
7d02540a TC |
5007 | /* If the only error is a non-fatal one and we don't want to print it, |
5008 | just exit. */ | |
5009 | if (!non_fatal_only || head->detail.non_fatal) | |
5010 | { | |
5011 | DEBUG_TRACE ("single opcode entry with error kind: %s", | |
5012 | operand_mismatch_kind_names[head->detail.kind]); | |
5013 | output_operand_error_record (head, str); | |
5014 | } | |
a06ea964 NC |
5015 | return; |
5016 | } | |
5017 | ||
5018 | /* Find the error kind of the highest severity. */ | |
33eaf5de | 5019 | DEBUG_TRACE ("multiple opcode entries with error kind"); |
a06ea964 NC |
5020 | kind = AARCH64_OPDE_NIL; |
5021 | for (curr = head; curr != NULL; curr = curr->next) | |
5022 | { | |
5023 | gas_assert (curr->detail.kind != AARCH64_OPDE_NIL); | |
5024 | DEBUG_TRACE ("\t%s", operand_mismatch_kind_names[curr->detail.kind]); | |
a68f4cd2 TC |
5025 | if (operand_error_higher_severity_p (curr->detail.kind, kind) |
5026 | && (!non_fatal_only || (non_fatal_only && curr->detail.non_fatal))) | |
a06ea964 NC |
5027 | kind = curr->detail.kind; |
5028 | } | |
a68f4cd2 TC |
5029 | |
5030 | gas_assert (kind != AARCH64_OPDE_NIL || non_fatal_only); | |
a06ea964 NC |
5031 | |
5032 | /* Pick up one of errors of KIND to report. */ | |
5033 | largest_error_pos = -2; /* Index can be -1 which means unknown index. */ | |
261dde89 | 5034 | largest_error_pos2 = -2; /* Index can be -1 which means unknown index. */ |
a06ea964 NC |
5035 | for (curr = head; curr != NULL; curr = curr->next) |
5036 | { | |
7d02540a TC |
5037 | /* If we don't want to print non-fatal errors then don't consider them |
5038 | at all. */ | |
5039 | if (curr->detail.kind != kind | |
af81c43b | 5040 | || (non_fatal_only && !curr->detail.non_fatal)) |
a06ea964 NC |
5041 | continue; |
5042 | /* If there are multiple errors, pick up the one with the highest | |
5043 | mismatching operand index. In the case of multiple errors with | |
5044 | the equally highest operand index, pick up the first one or the | |
5045 | first one with non-NULL error message. */ | |
261dde89 | 5046 | if (AARCH64_CPU_HAS_FEATURE (cpu_variant, *curr->opcode->avariant)) |
a06ea964 | 5047 | { |
261dde89 SP |
5048 | if (curr->detail.index > largest_error_pos |
5049 | || (curr->detail.index == largest_error_pos && msg == NULL | |
5050 | && curr->detail.error != NULL)) | |
5051 | { | |
5052 | largest_error_pos = curr->detail.index; | |
5053 | record = curr; | |
5054 | msg = record->detail.error; | |
5055 | } | |
5056 | } | |
5057 | else | |
5058 | { | |
5059 | if (curr->detail.index > largest_error_pos2 | |
5060 | || (curr->detail.index == largest_error_pos2 && msg2 == NULL | |
5061 | && curr->detail.error != NULL)) | |
5062 | { | |
5063 | largest_error_pos2 = curr->detail.index; | |
5064 | record2 = curr; | |
5065 | msg2 = record2->detail.error; | |
5066 | } | |
a06ea964 NC |
5067 | } |
5068 | } | |
5069 | ||
261dde89 SP |
5070 | /* No errors in enabled cpu feature variants, look for errors in the disabled |
5071 | ones. XXX we should do this segregation when prioritizing too. */ | |
5072 | if (!record) | |
5073 | { | |
5074 | largest_error_pos = largest_error_pos2; | |
5075 | record = record2; | |
5076 | msg = msg2; | |
5077 | } | |
5078 | ||
7d02540a TC |
5079 | /* The way errors are collected in the back-end is a bit non-intuitive. But |
5080 | essentially, because each operand template is tried recursively you may | |
5081 | always have errors collected from the previous tried OPND. These are | |
5082 | usually skipped if there is one successful match. However now with the | |
5083 | non-fatal errors we have to ignore those previously collected hard errors | |
5084 | when we're only interested in printing the non-fatal ones. This condition | |
5085 | prevents us from printing errors that are not appropriate, since we did | |
5086 | match a condition, but it also has warnings that it wants to print. */ | |
5087 | if (non_fatal_only && !record) | |
5088 | return; | |
5089 | ||
a06ea964 NC |
5090 | gas_assert (largest_error_pos != -2 && record != NULL); |
5091 | DEBUG_TRACE ("Pick up error kind %s to report", | |
5092 | operand_mismatch_kind_names[record->detail.kind]); | |
5093 | ||
5094 | /* Output. */ | |
5095 | output_operand_error_record (record, str); | |
5096 | } | |
5097 | \f | |
5098 | /* Write an AARCH64 instruction to buf - always little-endian. */ | |
5099 | static void | |
5100 | put_aarch64_insn (char *buf, uint32_t insn) | |
5101 | { | |
5102 | unsigned char *where = (unsigned char *) buf; | |
5103 | where[0] = insn; | |
5104 | where[1] = insn >> 8; | |
5105 | where[2] = insn >> 16; | |
5106 | where[3] = insn >> 24; | |
5107 | } | |
5108 | ||
5109 | static uint32_t | |
5110 | get_aarch64_insn (char *buf) | |
5111 | { | |
5112 | unsigned char *where = (unsigned char *) buf; | |
5113 | uint32_t result; | |
4f7cc141 AM |
5114 | result = ((where[0] | (where[1] << 8) | (where[2] << 16) |
5115 | | ((uint32_t) where[3] << 24))); | |
a06ea964 NC |
5116 | return result; |
5117 | } | |
5118 | ||
5119 | static void | |
5120 | output_inst (struct aarch64_inst *new_inst) | |
5121 | { | |
5122 | char *to = NULL; | |
5123 | ||
5124 | to = frag_more (INSN_SIZE); | |
5125 | ||
5126 | frag_now->tc_frag_data.recorded = 1; | |
5127 | ||
5128 | put_aarch64_insn (to, inst.base.value); | |
5129 | ||
5130 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5131 | { | |
5132 | fixS *fixp = fix_new_aarch64 (frag_now, to - frag_now->fr_literal, | |
5133 | INSN_SIZE, &inst.reloc.exp, | |
5134 | inst.reloc.pc_rel, | |
5135 | inst.reloc.type); | |
5136 | DEBUG_TRACE ("Prepared relocation fix up"); | |
5137 | /* Don't check the addend value against the instruction size, | |
5138 | that's the job of our code in md_apply_fix(). */ | |
5139 | fixp->fx_no_overflow = 1; | |
5140 | if (new_inst != NULL) | |
5141 | fixp->tc_fix_data.inst = new_inst; | |
5142 | if (aarch64_gas_internal_fixup_p ()) | |
5143 | { | |
5144 | gas_assert (inst.reloc.opnd != AARCH64_OPND_NIL); | |
5145 | fixp->tc_fix_data.opnd = inst.reloc.opnd; | |
5146 | fixp->fx_addnumber = inst.reloc.flags; | |
5147 | } | |
f0070c1e SP |
5148 | if (inst.reloc.flags & FIXUP_F_C64) |
5149 | fixp->tc_fix_data.c64 = TRUE; | |
a06ea964 NC |
5150 | } |
5151 | ||
5152 | dwarf2_emit_insn (INSN_SIZE); | |
5153 | } | |
5154 | ||
5155 | /* Link together opcodes of the same name. */ | |
5156 | ||
5157 | struct templates | |
5158 | { | |
5159 | aarch64_opcode *opcode; | |
5160 | struct templates *next; | |
5161 | }; | |
5162 | ||
5163 | typedef struct templates templates; | |
5164 | ||
5165 | static templates * | |
5166 | lookup_mnemonic (const char *start, int len) | |
5167 | { | |
5168 | templates *templ = NULL; | |
5169 | ||
629310ab | 5170 | templ = str_hash_find_n (aarch64_ops_hsh, start, len); |
a06ea964 NC |
5171 | return templ; |
5172 | } | |
5173 | ||
5174 | /* Subroutine of md_assemble, responsible for looking up the primary | |
5175 | opcode from the mnemonic the user wrote. STR points to the | |
5176 | beginning of the mnemonic. */ | |
5177 | ||
5178 | static templates * | |
5179 | opcode_lookup (char **str) | |
5180 | { | |
bb7eff52 | 5181 | char *end, *base, *dot; |
a06ea964 NC |
5182 | const aarch64_cond *cond; |
5183 | char condname[16]; | |
5184 | int len; | |
5185 | ||
5186 | /* Scan up to the end of the mnemonic, which must end in white space, | |
5187 | '.', or end of string. */ | |
bb7eff52 | 5188 | dot = 0; |
a06ea964 | 5189 | for (base = end = *str; is_part_of_name(*end); end++) |
bb7eff52 RS |
5190 | if (*end == '.' && !dot) |
5191 | dot = end; | |
a06ea964 | 5192 | |
bb7eff52 | 5193 | if (end == base || dot == base) |
a06ea964 NC |
5194 | return 0; |
5195 | ||
5196 | inst.cond = COND_ALWAYS; | |
5197 | ||
5198 | /* Handle a possible condition. */ | |
bb7eff52 | 5199 | if (dot) |
a06ea964 | 5200 | { |
629310ab | 5201 | cond = str_hash_find_n (aarch64_cond_hsh, dot + 1, end - dot - 1); |
a06ea964 NC |
5202 | if (cond) |
5203 | { | |
5204 | inst.cond = cond->value; | |
bb7eff52 | 5205 | *str = end; |
a06ea964 NC |
5206 | } |
5207 | else | |
5208 | { | |
bb7eff52 | 5209 | *str = dot; |
a06ea964 NC |
5210 | return 0; |
5211 | } | |
bb7eff52 | 5212 | len = dot - base; |
a06ea964 NC |
5213 | } |
5214 | else | |
bb7eff52 RS |
5215 | { |
5216 | *str = end; | |
5217 | len = end - base; | |
5218 | } | |
a06ea964 NC |
5219 | |
5220 | if (inst.cond == COND_ALWAYS) | |
5221 | { | |
5222 | /* Look for unaffixed mnemonic. */ | |
5223 | return lookup_mnemonic (base, len); | |
5224 | } | |
5225 | else if (len <= 13) | |
5226 | { | |
5227 | /* append ".c" to mnemonic if conditional */ | |
5228 | memcpy (condname, base, len); | |
5229 | memcpy (condname + len, ".c", 2); | |
5230 | base = condname; | |
5231 | len += 2; | |
5232 | return lookup_mnemonic (base, len); | |
5233 | } | |
5234 | ||
5235 | return NULL; | |
5236 | } | |
5237 | ||
8f9a77af RS |
5238 | /* Internal helper routine converting a vector_type_el structure *VECTYPE |
5239 | to a corresponding operand qualifier. */ | |
a06ea964 NC |
5240 | |
5241 | static inline aarch64_opnd_qualifier_t | |
8f9a77af | 5242 | vectype_to_qualifier (const struct vector_type_el *vectype) |
a06ea964 | 5243 | { |
f06935a5 | 5244 | /* Element size in bytes indexed by vector_el_type. */ |
a06ea964 NC |
5245 | const unsigned char ele_size[5] |
5246 | = {1, 2, 4, 8, 16}; | |
65f2205d MW |
5247 | const unsigned int ele_base [5] = |
5248 | { | |
a3b3345a | 5249 | AARCH64_OPND_QLF_V_4B, |
3067d3b9 | 5250 | AARCH64_OPND_QLF_V_2H, |
65f2205d MW |
5251 | AARCH64_OPND_QLF_V_2S, |
5252 | AARCH64_OPND_QLF_V_1D, | |
5253 | AARCH64_OPND_QLF_V_1Q | |
5254 | }; | |
a06ea964 NC |
5255 | |
5256 | if (!vectype->defined || vectype->type == NT_invtype) | |
5257 | goto vectype_conversion_fail; | |
5258 | ||
d50c751e RS |
5259 | if (vectype->type == NT_zero) |
5260 | return AARCH64_OPND_QLF_P_Z; | |
5261 | if (vectype->type == NT_merge) | |
5262 | return AARCH64_OPND_QLF_P_M; | |
5263 | ||
a06ea964 NC |
5264 | gas_assert (vectype->type >= NT_b && vectype->type <= NT_q); |
5265 | ||
f11ad6bc | 5266 | if (vectype->defined & (NTA_HASINDEX | NTA_HASVARWIDTH)) |
00c2093f TC |
5267 | { |
5268 | /* Special case S_4B. */ | |
5269 | if (vectype->type == NT_b && vectype->width == 4) | |
5270 | return AARCH64_OPND_QLF_S_4B; | |
5271 | ||
df678013 MM |
5272 | /* Special case S_2H. */ |
5273 | if (vectype->type == NT_h && vectype->width == 2) | |
5274 | return AARCH64_OPND_QLF_S_2H; | |
5275 | ||
00c2093f TC |
5276 | /* Vector element register. */ |
5277 | return AARCH64_OPND_QLF_S_B + vectype->type; | |
5278 | } | |
a06ea964 NC |
5279 | else |
5280 | { | |
5281 | /* Vector register. */ | |
5282 | int reg_size = ele_size[vectype->type] * vectype->width; | |
5283 | unsigned offset; | |
65f2205d | 5284 | unsigned shift; |
3067d3b9 | 5285 | if (reg_size != 16 && reg_size != 8 && reg_size != 4) |
a06ea964 | 5286 | goto vectype_conversion_fail; |
65f2205d MW |
5287 | |
5288 | /* The conversion is by calculating the offset from the base operand | |
5289 | qualifier for the vector type. The operand qualifiers are regular | |
5290 | enough that the offset can established by shifting the vector width by | |
5291 | a vector-type dependent amount. */ | |
5292 | shift = 0; | |
5293 | if (vectype->type == NT_b) | |
a3b3345a | 5294 | shift = 3; |
3067d3b9 | 5295 | else if (vectype->type == NT_h || vectype->type == NT_s) |
65f2205d MW |
5296 | shift = 2; |
5297 | else if (vectype->type >= NT_d) | |
5298 | shift = 1; | |
5299 | else | |
5300 | gas_assert (0); | |
5301 | ||
5302 | offset = ele_base [vectype->type] + (vectype->width >> shift); | |
a3b3345a | 5303 | gas_assert (AARCH64_OPND_QLF_V_4B <= offset |
65f2205d MW |
5304 | && offset <= AARCH64_OPND_QLF_V_1Q); |
5305 | return offset; | |
a06ea964 NC |
5306 | } |
5307 | ||
dc1e8a47 | 5308 | vectype_conversion_fail: |
a06ea964 NC |
5309 | first_error (_("bad vector arrangement type")); |
5310 | return AARCH64_OPND_QLF_NIL; | |
5311 | } | |
5312 | ||
5313 | /* Process an optional operand that is found omitted from the assembly line. | |
5314 | Fill *OPERAND for such an operand of type TYPE. OPCODE points to the | |
5315 | instruction's opcode entry while IDX is the index of this omitted operand. | |
5316 | */ | |
5317 | ||
5318 | static void | |
5319 | process_omitted_operand (enum aarch64_opnd type, const aarch64_opcode *opcode, | |
5320 | int idx, aarch64_opnd_info *operand) | |
5321 | { | |
5322 | aarch64_insn default_value = get_optional_operand_default_value (opcode); | |
5323 | gas_assert (optional_operand_p (opcode, idx)); | |
5324 | gas_assert (!operand->present); | |
5325 | ||
5326 | switch (type) | |
5327 | { | |
5328 | case AARCH64_OPND_Rd: | |
5329 | case AARCH64_OPND_Rn: | |
5330 | case AARCH64_OPND_Rm: | |
5331 | case AARCH64_OPND_Rt: | |
5332 | case AARCH64_OPND_Rt2: | |
bd7ceb8d | 5333 | case AARCH64_OPND_Rt_SP: |
a06ea964 NC |
5334 | case AARCH64_OPND_Rs: |
5335 | case AARCH64_OPND_Ra: | |
5336 | case AARCH64_OPND_Rt_SYS: | |
5337 | case AARCH64_OPND_Rd_SP: | |
5338 | case AARCH64_OPND_Rn_SP: | |
c84364ec | 5339 | case AARCH64_OPND_Rm_SP: |
a06ea964 NC |
5340 | case AARCH64_OPND_Fd: |
5341 | case AARCH64_OPND_Fn: | |
5342 | case AARCH64_OPND_Fm: | |
5343 | case AARCH64_OPND_Fa: | |
5344 | case AARCH64_OPND_Ft: | |
5345 | case AARCH64_OPND_Ft2: | |
5346 | case AARCH64_OPND_Sd: | |
5347 | case AARCH64_OPND_Sn: | |
5348 | case AARCH64_OPND_Sm: | |
f42f1a1d | 5349 | case AARCH64_OPND_Va: |
a06ea964 NC |
5350 | case AARCH64_OPND_Vd: |
5351 | case AARCH64_OPND_Vn: | |
5352 | case AARCH64_OPND_Vm: | |
5353 | case AARCH64_OPND_VdD1: | |
5354 | case AARCH64_OPND_VnD1: | |
5355 | operand->reg.regno = default_value; | |
5356 | break; | |
5357 | ||
5358 | case AARCH64_OPND_Ed: | |
5359 | case AARCH64_OPND_En: | |
5360 | case AARCH64_OPND_Em: | |
369c9167 | 5361 | case AARCH64_OPND_Em16: |
f42f1a1d | 5362 | case AARCH64_OPND_SM3_IMM2: |
a06ea964 NC |
5363 | operand->reglane.regno = default_value; |
5364 | break; | |
5365 | ||
5366 | case AARCH64_OPND_IDX: | |
5367 | case AARCH64_OPND_BIT_NUM: | |
5368 | case AARCH64_OPND_IMMR: | |
5369 | case AARCH64_OPND_IMMS: | |
5370 | case AARCH64_OPND_SHLL_IMM: | |
5371 | case AARCH64_OPND_IMM_VLSL: | |
5372 | case AARCH64_OPND_IMM_VLSR: | |
5373 | case AARCH64_OPND_CCMP_IMM: | |
5374 | case AARCH64_OPND_FBITS: | |
5375 | case AARCH64_OPND_UIMM4: | |
5376 | case AARCH64_OPND_UIMM3_OP1: | |
5377 | case AARCH64_OPND_UIMM3_OP2: | |
5378 | case AARCH64_OPND_IMM: | |
f42f1a1d | 5379 | case AARCH64_OPND_IMM_2: |
a06ea964 NC |
5380 | case AARCH64_OPND_WIDTH: |
5381 | case AARCH64_OPND_UIMM7: | |
5382 | case AARCH64_OPND_NZCV: | |
245d2e3f RS |
5383 | case AARCH64_OPND_SVE_PATTERN: |
5384 | case AARCH64_OPND_SVE_PRFOP: | |
a06ea964 NC |
5385 | operand->imm.value = default_value; |
5386 | break; | |
5387 | ||
2442d846 RS |
5388 | case AARCH64_OPND_SVE_PATTERN_SCALED: |
5389 | operand->imm.value = default_value; | |
5390 | operand->shifter.kind = AARCH64_MOD_MUL; | |
5391 | operand->shifter.amount = 1; | |
5392 | break; | |
5393 | ||
a06ea964 NC |
5394 | case AARCH64_OPND_EXCEPTION: |
5395 | inst.reloc.type = BFD_RELOC_UNUSED; | |
5396 | break; | |
5397 | ||
5398 | case AARCH64_OPND_BARRIER_ISB: | |
5399 | operand->barrier = aarch64_barrier_options + default_value; | |
ff605452 SD |
5400 | break; |
5401 | ||
5402 | case AARCH64_OPND_BTI_TARGET: | |
5403 | operand->hint_option = aarch64_hint_options + default_value; | |
5404 | break; | |
a06ea964 NC |
5405 | |
5406 | default: | |
5407 | break; | |
5408 | } | |
5409 | } | |
5410 | ||
5411 | /* Process the relocation type for move wide instructions. | |
5412 | Return TRUE on success; otherwise return FALSE. */ | |
5413 | ||
5414 | static bfd_boolean | |
5415 | process_movw_reloc_info (void) | |
5416 | { | |
5417 | int is32; | |
5418 | unsigned shift; | |
5419 | ||
5420 | is32 = inst.base.operands[0].qualifier == AARCH64_OPND_QLF_W ? 1 : 0; | |
5421 | ||
5422 | if (inst.base.opcode->op == OP_MOVK) | |
5423 | switch (inst.reloc.type) | |
5424 | { | |
5425 | case BFD_RELOC_AARCH64_MOVW_G0_S: | |
5426 | case BFD_RELOC_AARCH64_MOVW_G1_S: | |
5427 | case BFD_RELOC_AARCH64_MOVW_G2_S: | |
32247401 RL |
5428 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
5429 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: | |
5430 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: | |
5431 | case BFD_RELOC_AARCH64_MOVW_PREL_G3: | |
1aa66fb1 | 5432 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
a06ea964 | 5433 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
a06ea964 | 5434 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
a06ea964 NC |
5435 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
5436 | set_syntax_error | |
5437 | (_("the specified relocation type is not allowed for MOVK")); | |
5438 | return FALSE; | |
5439 | default: | |
5440 | break; | |
5441 | } | |
5442 | ||
5443 | switch (inst.reloc.type) | |
5444 | { | |
5445 | case BFD_RELOC_AARCH64_MOVW_G0: | |
a06ea964 | 5446 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
f09c556a | 5447 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
ca632371 | 5448 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
32247401 RL |
5449 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
5450 | case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC: | |
43a357f9 | 5451 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
3e8286c0 | 5452 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
3b957e5b | 5453 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
49df5539 JW |
5454 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
5455 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: | |
a06ea964 NC |
5456 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
5457 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: | |
5458 | shift = 0; | |
5459 | break; | |
5460 | case BFD_RELOC_AARCH64_MOVW_G1: | |
a06ea964 | 5461 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
f09c556a | 5462 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
654248e7 | 5463 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
32247401 RL |
5464 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: |
5465 | case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC: | |
43a357f9 | 5466 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
1aa66fb1 | 5467 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
3b957e5b | 5468 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: |
49df5539 JW |
5469 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: |
5470 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: | |
a06ea964 NC |
5471 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
5472 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: | |
5473 | shift = 16; | |
5474 | break; | |
5475 | case BFD_RELOC_AARCH64_MOVW_G2: | |
a06ea964 | 5476 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
f09c556a | 5477 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
32247401 RL |
5478 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: |
5479 | case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC: | |
49df5539 | 5480 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: |
a06ea964 NC |
5481 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
5482 | if (is32) | |
5483 | { | |
5484 | set_fatal_syntax_error | |
5485 | (_("the specified relocation type is not allowed for 32-bit " | |
5486 | "register")); | |
5487 | return FALSE; | |
5488 | } | |
5489 | shift = 32; | |
5490 | break; | |
5491 | case BFD_RELOC_AARCH64_MOVW_G3: | |
32247401 | 5492 | case BFD_RELOC_AARCH64_MOVW_PREL_G3: |
a06ea964 NC |
5493 | if (is32) |
5494 | { | |
5495 | set_fatal_syntax_error | |
5496 | (_("the specified relocation type is not allowed for 32-bit " | |
5497 | "register")); | |
5498 | return FALSE; | |
5499 | } | |
5500 | shift = 48; | |
5501 | break; | |
5502 | default: | |
5503 | /* More cases should be added when more MOVW-related relocation types | |
5504 | are supported in GAS. */ | |
5505 | gas_assert (aarch64_gas_internal_fixup_p ()); | |
5506 | /* The shift amount should have already been set by the parser. */ | |
5507 | return TRUE; | |
5508 | } | |
5509 | inst.base.operands[1].shifter.amount = shift; | |
5510 | return TRUE; | |
5511 | } | |
5512 | ||
33eaf5de | 5513 | /* A primitive log calculator. */ |
a06ea964 NC |
5514 | |
5515 | static inline unsigned int | |
5516 | get_logsz (unsigned int size) | |
5517 | { | |
5518 | const unsigned char ls[16] = | |
5519 | {0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, 4}; | |
5520 | if (size > 16) | |
5521 | { | |
5522 | gas_assert (0); | |
5523 | return -1; | |
5524 | } | |
5525 | gas_assert (ls[size - 1] != (unsigned char)-1); | |
5526 | return ls[size - 1]; | |
5527 | } | |
5528 | ||
5529 | /* Determine and return the real reloc type code for an instruction | |
5530 | with the pseudo reloc type code BFD_RELOC_AARCH64_LDST_LO12. */ | |
5531 | ||
5532 | static inline bfd_reloc_code_real_type | |
5533 | ldst_lo12_determine_real_reloc_type (void) | |
5534 | { | |
4c562523 | 5535 | unsigned logsz; |
a06ea964 NC |
5536 | enum aarch64_opnd_qualifier opd0_qlf = inst.base.operands[0].qualifier; |
5537 | enum aarch64_opnd_qualifier opd1_qlf = inst.base.operands[1].qualifier; | |
5538 | ||
84f1b9fb | 5539 | const bfd_reloc_code_real_type reloc_ldst_lo12[5][5] = { |
4c562523 JW |
5540 | { |
5541 | BFD_RELOC_AARCH64_LDST8_LO12, | |
5542 | BFD_RELOC_AARCH64_LDST16_LO12, | |
5543 | BFD_RELOC_AARCH64_LDST32_LO12, | |
5544 | BFD_RELOC_AARCH64_LDST64_LO12, | |
a06ea964 | 5545 | BFD_RELOC_AARCH64_LDST128_LO12 |
4c562523 JW |
5546 | }, |
5547 | { | |
5548 | BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12, | |
5549 | BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12, | |
5550 | BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12, | |
5551 | BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12, | |
5552 | BFD_RELOC_AARCH64_NONE | |
5553 | }, | |
5554 | { | |
5555 | BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, | |
5556 | BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, | |
5557 | BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, | |
5558 | BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, | |
5559 | BFD_RELOC_AARCH64_NONE | |
84f1b9fb RL |
5560 | }, |
5561 | { | |
5562 | BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12, | |
5563 | BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12, | |
5564 | BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12, | |
5565 | BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12, | |
5566 | BFD_RELOC_AARCH64_NONE | |
5567 | }, | |
5568 | { | |
5569 | BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC, | |
5570 | BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC, | |
5571 | BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC, | |
5572 | BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC, | |
5573 | BFD_RELOC_AARCH64_NONE | |
4c562523 | 5574 | } |
a06ea964 NC |
5575 | }; |
5576 | ||
4c562523 JW |
5577 | gas_assert (inst.reloc.type == BFD_RELOC_AARCH64_LDST_LO12 |
5578 | || inst.reloc.type == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12 | |
5579 | || (inst.reloc.type | |
84f1b9fb RL |
5580 | == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC) |
5581 | || (inst.reloc.type | |
5582 | == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12) | |
5583 | || (inst.reloc.type | |
5584 | == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC)); | |
a06ea964 NC |
5585 | gas_assert (inst.base.opcode->operands[1] == AARCH64_OPND_ADDR_UIMM12); |
5586 | ||
5587 | if (opd1_qlf == AARCH64_OPND_QLF_NIL) | |
5588 | opd1_qlf = | |
5589 | aarch64_get_expected_qualifier (inst.base.opcode->qualifiers_list, | |
5590 | 1, opd0_qlf, 0); | |
5591 | gas_assert (opd1_qlf != AARCH64_OPND_QLF_NIL); | |
5592 | ||
5593 | logsz = get_logsz (aarch64_get_qualifier_esize (opd1_qlf)); | |
4c562523 | 5594 | if (inst.reloc.type == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12 |
84f1b9fb RL |
5595 | || inst.reloc.type == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC |
5596 | || inst.reloc.type == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12 | |
5597 | || inst.reloc.type == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC) | |
4c562523 JW |
5598 | gas_assert (logsz <= 3); |
5599 | else | |
5600 | gas_assert (logsz <= 4); | |
a06ea964 | 5601 | |
4c562523 | 5602 | /* In reloc.c, these pseudo relocation types should be defined in similar |
33eaf5de | 5603 | order as above reloc_ldst_lo12 array. Because the array index calculation |
4c562523 JW |
5604 | below relies on this. */ |
5605 | return reloc_ldst_lo12[inst.reloc.type - BFD_RELOC_AARCH64_LDST_LO12][logsz]; | |
a06ea964 NC |
5606 | } |
5607 | ||
5608 | /* Check whether a register list REGINFO is valid. The registers must be | |
5609 | numbered in increasing order (modulo 32), in increments of one or two. | |
5610 | ||
5611 | If ACCEPT_ALTERNATE is non-zero, the register numbers should be in | |
5612 | increments of two. | |
5613 | ||
5614 | Return FALSE if such a register list is invalid, otherwise return TRUE. */ | |
5615 | ||
5616 | static bfd_boolean | |
5617 | reg_list_valid_p (uint32_t reginfo, int accept_alternate) | |
5618 | { | |
5619 | uint32_t i, nb_regs, prev_regno, incr; | |
5620 | ||
5621 | nb_regs = 1 + (reginfo & 0x3); | |
5622 | reginfo >>= 2; | |
5623 | prev_regno = reginfo & 0x1f; | |
5624 | incr = accept_alternate ? 2 : 1; | |
5625 | ||
5626 | for (i = 1; i < nb_regs; ++i) | |
5627 | { | |
5628 | uint32_t curr_regno; | |
5629 | reginfo >>= 5; | |
5630 | curr_regno = reginfo & 0x1f; | |
5631 | if (curr_regno != ((prev_regno + incr) & 0x1f)) | |
5632 | return FALSE; | |
5633 | prev_regno = curr_regno; | |
5634 | } | |
5635 | ||
5636 | return TRUE; | |
5637 | } | |
5638 | ||
5639 | /* Generic instruction operand parser. This does no encoding and no | |
5640 | semantic validation; it merely squirrels values away in the inst | |
5641 | structure. Returns TRUE or FALSE depending on whether the | |
5642 | specified grammar matched. */ | |
5643 | ||
5644 | static bfd_boolean | |
5645 | parse_operands (char *str, const aarch64_opcode *opcode) | |
5646 | { | |
5647 | int i; | |
5648 | char *backtrack_pos = 0; | |
5649 | const enum aarch64_opnd *operands = opcode->operands; | |
1799c0d0 | 5650 | aarch64_reg_type imm_reg_type; |
a06ea964 NC |
5651 | |
5652 | clear_error (); | |
5653 | skip_whitespace (str); | |
5654 | ||
c0890d26 | 5655 | if (AARCH64_CPU_HAS_FEATURE (AARCH64_FEATURE_SVE, *opcode->avariant)) |
5b2b928e | 5656 | imm_reg_type = REG_TYPE_R_Z_SP_BHSDQ_VZP; |
c0890d26 RS |
5657 | else |
5658 | imm_reg_type = REG_TYPE_R_Z_BHSDQ_V; | |
1799c0d0 | 5659 | |
a06ea964 NC |
5660 | for (i = 0; operands[i] != AARCH64_OPND_NIL; i++) |
5661 | { | |
5662 | int64_t val; | |
e1b988bb | 5663 | const reg_entry *reg; |
a06ea964 NC |
5664 | int comma_skipped_p = 0; |
5665 | aarch64_reg_type rtype; | |
8f9a77af | 5666 | struct vector_type_el vectype; |
4df068de | 5667 | aarch64_opnd_qualifier_t qualifier, base_qualifier, offset_qualifier; |
a06ea964 | 5668 | aarch64_opnd_info *info = &inst.base.operands[i]; |
f11ad6bc | 5669 | aarch64_reg_type reg_type; |
a06ea964 NC |
5670 | |
5671 | DEBUG_TRACE ("parse operand %d", i); | |
5672 | ||
5673 | /* Assign the operand code. */ | |
5674 | info->type = operands[i]; | |
5675 | ||
5676 | if (optional_operand_p (opcode, i)) | |
5677 | { | |
5678 | /* Remember where we are in case we need to backtrack. */ | |
5679 | gas_assert (!backtrack_pos); | |
5680 | backtrack_pos = str; | |
5681 | } | |
5682 | ||
33eaf5de | 5683 | /* Expect comma between operands; the backtrack mechanism will take |
a06ea964 NC |
5684 | care of cases of omitted optional operand. */ |
5685 | if (i > 0 && ! skip_past_char (&str, ',')) | |
5686 | { | |
5687 | set_syntax_error (_("comma expected between operands")); | |
5688 | goto failure; | |
5689 | } | |
5690 | else | |
5691 | comma_skipped_p = 1; | |
5692 | ||
5693 | switch (operands[i]) | |
5694 | { | |
5695 | case AARCH64_OPND_Rd: | |
5696 | case AARCH64_OPND_Rn: | |
5697 | case AARCH64_OPND_Rm: | |
5698 | case AARCH64_OPND_Rt: | |
5699 | case AARCH64_OPND_Rt2: | |
5700 | case AARCH64_OPND_Rs: | |
5701 | case AARCH64_OPND_Ra: | |
5702 | case AARCH64_OPND_Rt_SYS: | |
ee804238 | 5703 | case AARCH64_OPND_PAIRREG: |
047cd301 | 5704 | case AARCH64_OPND_SVE_Rm: |
e1b988bb | 5705 | po_int_reg_or_fail (REG_TYPE_R_Z); |
a06ea964 NC |
5706 | break; |
5707 | ||
5708 | case AARCH64_OPND_Rd_SP: | |
5709 | case AARCH64_OPND_Rn_SP: | |
bd7ceb8d | 5710 | case AARCH64_OPND_Rt_SP: |
047cd301 | 5711 | case AARCH64_OPND_SVE_Rn_SP: |
c84364ec | 5712 | case AARCH64_OPND_Rm_SP: |
e1b988bb | 5713 | po_int_reg_or_fail (REG_TYPE_R_SP); |
a06ea964 NC |
5714 | break; |
5715 | ||
dc64c2ba | 5716 | case AARCH64_OPND_A64C_Rm_EXT: |
a06ea964 NC |
5717 | case AARCH64_OPND_Rm_EXT: |
5718 | case AARCH64_OPND_Rm_SFT: | |
5719 | po_misc_or_fail (parse_shifter_operand | |
dc64c2ba SP |
5720 | (&str, info, (operands[i] == AARCH64_OPND_Rm_SFT |
5721 | ? SHIFTED_LOGIC_IMM | |
5722 | : SHIFTED_ARITH_IMM))); | |
a06ea964 NC |
5723 | if (!info->shifter.operator_present) |
5724 | { | |
5725 | /* Default to LSL if not present. Libopcodes prefers shifter | |
5726 | kind to be explicit. */ | |
5727 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); | |
5728 | info->shifter.kind = AARCH64_MOD_LSL; | |
5729 | /* For Rm_EXT, libopcodes will carry out further check on whether | |
5730 | or not stack pointer is used in the instruction (Recall that | |
5731 | "the extend operator is not optional unless at least one of | |
5732 | "Rd" or "Rn" is '11111' (i.e. WSP)"). */ | |
5733 | } | |
5734 | break; | |
5735 | ||
5736 | case AARCH64_OPND_Fd: | |
5737 | case AARCH64_OPND_Fn: | |
5738 | case AARCH64_OPND_Fm: | |
5739 | case AARCH64_OPND_Fa: | |
5740 | case AARCH64_OPND_Ft: | |
5741 | case AARCH64_OPND_Ft2: | |
5742 | case AARCH64_OPND_Sd: | |
5743 | case AARCH64_OPND_Sn: | |
5744 | case AARCH64_OPND_Sm: | |
047cd301 RS |
5745 | case AARCH64_OPND_SVE_VZn: |
5746 | case AARCH64_OPND_SVE_Vd: | |
5747 | case AARCH64_OPND_SVE_Vm: | |
5748 | case AARCH64_OPND_SVE_Vn: | |
a06ea964 NC |
5749 | val = aarch64_reg_parse (&str, REG_TYPE_BHSDQ, &rtype, NULL); |
5750 | if (val == PARSE_FAIL) | |
5751 | { | |
5752 | first_error (_(get_reg_expected_msg (REG_TYPE_BHSDQ))); | |
5753 | goto failure; | |
5754 | } | |
5755 | gas_assert (rtype >= REG_TYPE_FP_B && rtype <= REG_TYPE_FP_Q); | |
5756 | ||
5757 | info->reg.regno = val; | |
5758 | info->qualifier = AARCH64_OPND_QLF_S_B + (rtype - REG_TYPE_FP_B); | |
5759 | break; | |
5760 | ||
f11ad6bc RS |
5761 | case AARCH64_OPND_SVE_Pd: |
5762 | case AARCH64_OPND_SVE_Pg3: | |
5763 | case AARCH64_OPND_SVE_Pg4_5: | |
5764 | case AARCH64_OPND_SVE_Pg4_10: | |
5765 | case AARCH64_OPND_SVE_Pg4_16: | |
5766 | case AARCH64_OPND_SVE_Pm: | |
5767 | case AARCH64_OPND_SVE_Pn: | |
5768 | case AARCH64_OPND_SVE_Pt: | |
5769 | reg_type = REG_TYPE_PN; | |
5770 | goto vector_reg; | |
5771 | ||
5772 | case AARCH64_OPND_SVE_Za_5: | |
5773 | case AARCH64_OPND_SVE_Za_16: | |
5774 | case AARCH64_OPND_SVE_Zd: | |
5775 | case AARCH64_OPND_SVE_Zm_5: | |
5776 | case AARCH64_OPND_SVE_Zm_16: | |
5777 | case AARCH64_OPND_SVE_Zn: | |
5778 | case AARCH64_OPND_SVE_Zt: | |
5779 | reg_type = REG_TYPE_ZN; | |
5780 | goto vector_reg; | |
5781 | ||
f42f1a1d | 5782 | case AARCH64_OPND_Va: |
a06ea964 NC |
5783 | case AARCH64_OPND_Vd: |
5784 | case AARCH64_OPND_Vn: | |
5785 | case AARCH64_OPND_Vm: | |
f11ad6bc RS |
5786 | reg_type = REG_TYPE_VN; |
5787 | vector_reg: | |
5788 | val = aarch64_reg_parse (&str, reg_type, NULL, &vectype); | |
a06ea964 NC |
5789 | if (val == PARSE_FAIL) |
5790 | { | |
f11ad6bc | 5791 | first_error (_(get_reg_expected_msg (reg_type))); |
a06ea964 NC |
5792 | goto failure; |
5793 | } | |
5794 | if (vectype.defined & NTA_HASINDEX) | |
5795 | goto failure; | |
5796 | ||
5797 | info->reg.regno = val; | |
f11ad6bc RS |
5798 | if ((reg_type == REG_TYPE_PN || reg_type == REG_TYPE_ZN) |
5799 | && vectype.type == NT_invtype) | |
5800 | /* Unqualified Pn and Zn registers are allowed in certain | |
5801 | contexts. Rely on F_STRICT qualifier checking to catch | |
5802 | invalid uses. */ | |
5803 | info->qualifier = AARCH64_OPND_QLF_NIL; | |
5804 | else | |
5805 | { | |
5806 | info->qualifier = vectype_to_qualifier (&vectype); | |
5807 | if (info->qualifier == AARCH64_OPND_QLF_NIL) | |
5808 | goto failure; | |
5809 | } | |
a06ea964 NC |
5810 | break; |
5811 | ||
5812 | case AARCH64_OPND_VdD1: | |
5813 | case AARCH64_OPND_VnD1: | |
5814 | val = aarch64_reg_parse (&str, REG_TYPE_VN, NULL, &vectype); | |
5815 | if (val == PARSE_FAIL) | |
5816 | { | |
5817 | set_first_syntax_error (_(get_reg_expected_msg (REG_TYPE_VN))); | |
5818 | goto failure; | |
5819 | } | |
5820 | if (vectype.type != NT_d || vectype.index != 1) | |
5821 | { | |
5822 | set_fatal_syntax_error | |
5823 | (_("the top half of a 128-bit FP/SIMD register is expected")); | |
5824 | goto failure; | |
5825 | } | |
5826 | info->reg.regno = val; | |
5827 | /* N.B: VdD1 and VnD1 are treated as an fp or advsimd scalar register | |
5828 | here; it is correct for the purpose of encoding/decoding since | |
5829 | only the register number is explicitly encoded in the related | |
5830 | instructions, although this appears a bit hacky. */ | |
5831 | info->qualifier = AARCH64_OPND_QLF_S_D; | |
5832 | break; | |
5833 | ||
582e12bf RS |
5834 | case AARCH64_OPND_SVE_Zm3_INDEX: |
5835 | case AARCH64_OPND_SVE_Zm3_22_INDEX: | |
116adc27 | 5836 | case AARCH64_OPND_SVE_Zm3_11_INDEX: |
31e36ab3 | 5837 | case AARCH64_OPND_SVE_Zm4_11_INDEX: |
582e12bf | 5838 | case AARCH64_OPND_SVE_Zm4_INDEX: |
f11ad6bc RS |
5839 | case AARCH64_OPND_SVE_Zn_INDEX: |
5840 | reg_type = REG_TYPE_ZN; | |
5841 | goto vector_reg_index; | |
5842 | ||
a06ea964 NC |
5843 | case AARCH64_OPND_Ed: |
5844 | case AARCH64_OPND_En: | |
5845 | case AARCH64_OPND_Em: | |
369c9167 | 5846 | case AARCH64_OPND_Em16: |
f42f1a1d | 5847 | case AARCH64_OPND_SM3_IMM2: |
f11ad6bc RS |
5848 | reg_type = REG_TYPE_VN; |
5849 | vector_reg_index: | |
5850 | val = aarch64_reg_parse (&str, reg_type, NULL, &vectype); | |
a06ea964 NC |
5851 | if (val == PARSE_FAIL) |
5852 | { | |
f11ad6bc | 5853 | first_error (_(get_reg_expected_msg (reg_type))); |
a06ea964 NC |
5854 | goto failure; |
5855 | } | |
5856 | if (vectype.type == NT_invtype || !(vectype.defined & NTA_HASINDEX)) | |
5857 | goto failure; | |
5858 | ||
5859 | info->reglane.regno = val; | |
5860 | info->reglane.index = vectype.index; | |
5861 | info->qualifier = vectype_to_qualifier (&vectype); | |
5862 | if (info->qualifier == AARCH64_OPND_QLF_NIL) | |
5863 | goto failure; | |
5864 | break; | |
5865 | ||
f11ad6bc RS |
5866 | case AARCH64_OPND_SVE_ZnxN: |
5867 | case AARCH64_OPND_SVE_ZtxN: | |
5868 | reg_type = REG_TYPE_ZN; | |
5869 | goto vector_reg_list; | |
5870 | ||
a06ea964 NC |
5871 | case AARCH64_OPND_LVn: |
5872 | case AARCH64_OPND_LVt: | |
5873 | case AARCH64_OPND_LVt_AL: | |
5874 | case AARCH64_OPND_LEt: | |
f11ad6bc RS |
5875 | reg_type = REG_TYPE_VN; |
5876 | vector_reg_list: | |
5877 | if (reg_type == REG_TYPE_ZN | |
5878 | && get_opcode_dependent_value (opcode) == 1 | |
5879 | && *str != '{') | |
a06ea964 | 5880 | { |
f11ad6bc RS |
5881 | val = aarch64_reg_parse (&str, reg_type, NULL, &vectype); |
5882 | if (val == PARSE_FAIL) | |
5883 | { | |
5884 | first_error (_(get_reg_expected_msg (reg_type))); | |
5885 | goto failure; | |
5886 | } | |
5887 | info->reglist.first_regno = val; | |
5888 | info->reglist.num_regs = 1; | |
5889 | } | |
5890 | else | |
5891 | { | |
5892 | val = parse_vector_reg_list (&str, reg_type, &vectype); | |
5893 | if (val == PARSE_FAIL) | |
5894 | goto failure; | |
163b2c58 | 5895 | |
f11ad6bc RS |
5896 | if (! reg_list_valid_p (val, /* accept_alternate */ 0)) |
5897 | { | |
5898 | set_fatal_syntax_error (_("invalid register list")); | |
5899 | goto failure; | |
5900 | } | |
163b2c58 BW |
5901 | |
5902 | if (vectype.width != 0 && *str != ',') | |
5903 | { | |
5904 | set_fatal_syntax_error | |
5905 | (_("expected element type rather than vector type")); | |
5906 | goto failure; | |
5907 | } | |
5908 | ||
f11ad6bc RS |
5909 | info->reglist.first_regno = (val >> 2) & 0x1f; |
5910 | info->reglist.num_regs = (val & 0x3) + 1; | |
a06ea964 | 5911 | } |
a06ea964 NC |
5912 | if (operands[i] == AARCH64_OPND_LEt) |
5913 | { | |
5914 | if (!(vectype.defined & NTA_HASINDEX)) | |
5915 | goto failure; | |
5916 | info->reglist.has_index = 1; | |
5917 | info->reglist.index = vectype.index; | |
5918 | } | |
f11ad6bc RS |
5919 | else |
5920 | { | |
5921 | if (vectype.defined & NTA_HASINDEX) | |
5922 | goto failure; | |
5923 | if (!(vectype.defined & NTA_HASTYPE)) | |
5924 | { | |
5925 | if (reg_type == REG_TYPE_ZN) | |
5926 | set_fatal_syntax_error (_("missing type suffix")); | |
5927 | goto failure; | |
5928 | } | |
5929 | } | |
a06ea964 NC |
5930 | info->qualifier = vectype_to_qualifier (&vectype); |
5931 | if (info->qualifier == AARCH64_OPND_QLF_NIL) | |
5932 | goto failure; | |
5933 | break; | |
5934 | ||
ec145252 SP |
5935 | case AARCH64_OPND_Can: |
5936 | case AARCH64_OPND_Cam: | |
5937 | case AARCH64_OPND_Cas: | |
5938 | case AARCH64_OPND_Cad: | |
5939 | case AARCH64_OPND_Cat: | |
5940 | case AARCH64_OPND_Cat2: | |
5941 | po_reg_or_fail (REG_TYPE_CA_N_Z); | |
5942 | if (opcode->op == OP_MOV_C_ZR && operands[i] == AARCH64_OPND_Can | |
5943 | && val != 31) | |
5944 | { | |
5945 | set_fatal_syntax_error (_(get_reg_expected_msg (REG_TYPE_CA_Z))); | |
5946 | goto failure; | |
5947 | } | |
5948 | if (val > 31) | |
5949 | { | |
5950 | set_fatal_syntax_error (_(get_reg_expected_msg (REG_TYPE_CA_N))); | |
5951 | goto failure; | |
5952 | } | |
5953 | info->reg.regno = val; | |
5954 | info->qualifier = AARCH64_OPND_QLF_CA; | |
5955 | break; | |
5956 | ||
5957 | case AARCH64_OPND_Can_SP: | |
5958 | case AARCH64_OPND_Cad_SP: | |
5959 | po_reg_or_fail (REG_TYPE_CA_N_SP); | |
5960 | info->reg.regno = val; | |
5961 | info->qualifier = AARCH64_OPND_QLF_CA; | |
5962 | break; | |
5963 | ||
a6a51754 RL |
5964 | case AARCH64_OPND_CRn: |
5965 | case AARCH64_OPND_CRm: | |
a06ea964 | 5966 | { |
a6a51754 RL |
5967 | char prefix = *(str++); |
5968 | if (prefix != 'c' && prefix != 'C') | |
5969 | goto failure; | |
5970 | ||
5971 | po_imm_nc_or_fail (); | |
5972 | if (val > 15) | |
5973 | { | |
5974 | set_fatal_syntax_error (_(N_ ("C0 - C15 expected"))); | |
5975 | goto failure; | |
5976 | } | |
5977 | info->qualifier = AARCH64_OPND_QLF_CR; | |
5978 | info->imm.value = val; | |
5979 | break; | |
a06ea964 | 5980 | } |
a06ea964 NC |
5981 | |
5982 | case AARCH64_OPND_SHLL_IMM: | |
5983 | case AARCH64_OPND_IMM_VLSR: | |
5984 | po_imm_or_fail (1, 64); | |
5985 | info->imm.value = val; | |
5986 | break; | |
5987 | ||
5988 | case AARCH64_OPND_CCMP_IMM: | |
e950b345 | 5989 | case AARCH64_OPND_SIMM5: |
a06ea964 | 5990 | case AARCH64_OPND_FBITS: |
b83b4b13 | 5991 | case AARCH64_OPND_TME_UIMM16: |
a06ea964 | 5992 | case AARCH64_OPND_UIMM4: |
193614f2 SD |
5993 | case AARCH64_OPND_UIMM4_ADDG: |
5994 | case AARCH64_OPND_UIMM10: | |
a06ea964 NC |
5995 | case AARCH64_OPND_UIMM3_OP1: |
5996 | case AARCH64_OPND_UIMM3_OP2: | |
5997 | case AARCH64_OPND_IMM_VLSL: | |
5998 | case AARCH64_OPND_IMM: | |
f42f1a1d | 5999 | case AARCH64_OPND_IMM_2: |
a06ea964 | 6000 | case AARCH64_OPND_WIDTH: |
e950b345 RS |
6001 | case AARCH64_OPND_SVE_INV_LIMM: |
6002 | case AARCH64_OPND_SVE_LIMM: | |
6003 | case AARCH64_OPND_SVE_LIMM_MOV: | |
6004 | case AARCH64_OPND_SVE_SHLIMM_PRED: | |
6005 | case AARCH64_OPND_SVE_SHLIMM_UNPRED: | |
28ed815a | 6006 | case AARCH64_OPND_SVE_SHLIMM_UNPRED_22: |
e950b345 RS |
6007 | case AARCH64_OPND_SVE_SHRIMM_PRED: |
6008 | case AARCH64_OPND_SVE_SHRIMM_UNPRED: | |
3c17238b | 6009 | case AARCH64_OPND_SVE_SHRIMM_UNPRED_22: |
e950b345 RS |
6010 | case AARCH64_OPND_SVE_SIMM5: |
6011 | case AARCH64_OPND_SVE_SIMM5B: | |
6012 | case AARCH64_OPND_SVE_SIMM6: | |
6013 | case AARCH64_OPND_SVE_SIMM8: | |
6014 | case AARCH64_OPND_SVE_UIMM3: | |
6015 | case AARCH64_OPND_SVE_UIMM7: | |
6016 | case AARCH64_OPND_SVE_UIMM8: | |
6017 | case AARCH64_OPND_SVE_UIMM8_53: | |
c2c4ff8d SN |
6018 | case AARCH64_OPND_IMM_ROT1: |
6019 | case AARCH64_OPND_IMM_ROT2: | |
6020 | case AARCH64_OPND_IMM_ROT3: | |
582e12bf RS |
6021 | case AARCH64_OPND_SVE_IMM_ROT1: |
6022 | case AARCH64_OPND_SVE_IMM_ROT2: | |
adccc507 | 6023 | case AARCH64_OPND_SVE_IMM_ROT3: |
a06ea964 NC |
6024 | po_imm_nc_or_fail (); |
6025 | info->imm.value = val; | |
6026 | break; | |
6027 | ||
e950b345 RS |
6028 | case AARCH64_OPND_SVE_AIMM: |
6029 | case AARCH64_OPND_SVE_ASIMM: | |
6030 | po_imm_nc_or_fail (); | |
6031 | info->imm.value = val; | |
6032 | skip_whitespace (str); | |
6033 | if (skip_past_comma (&str)) | |
6034 | po_misc_or_fail (parse_shift (&str, info, SHIFTED_LSL)); | |
6035 | else | |
6036 | inst.base.operands[i].shifter.kind = AARCH64_MOD_LSL; | |
6037 | break; | |
6038 | ||
245d2e3f RS |
6039 | case AARCH64_OPND_SVE_PATTERN: |
6040 | po_enum_or_fail (aarch64_sve_pattern_array); | |
6041 | info->imm.value = val; | |
6042 | break; | |
6043 | ||
2442d846 RS |
6044 | case AARCH64_OPND_SVE_PATTERN_SCALED: |
6045 | po_enum_or_fail (aarch64_sve_pattern_array); | |
6046 | info->imm.value = val; | |
6047 | if (skip_past_comma (&str) | |
6048 | && !parse_shift (&str, info, SHIFTED_MUL)) | |
6049 | goto failure; | |
6050 | if (!info->shifter.operator_present) | |
6051 | { | |
6052 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); | |
6053 | info->shifter.kind = AARCH64_MOD_MUL; | |
6054 | info->shifter.amount = 1; | |
6055 | } | |
6056 | break; | |
6057 | ||
245d2e3f RS |
6058 | case AARCH64_OPND_SVE_PRFOP: |
6059 | po_enum_or_fail (aarch64_sve_prfop_array); | |
6060 | info->imm.value = val; | |
6061 | break; | |
6062 | ||
a06ea964 NC |
6063 | case AARCH64_OPND_UIMM7: |
6064 | po_imm_or_fail (0, 127); | |
6065 | info->imm.value = val; | |
6066 | break; | |
6067 | ||
6068 | case AARCH64_OPND_IDX: | |
f42f1a1d | 6069 | case AARCH64_OPND_MASK: |
a06ea964 NC |
6070 | case AARCH64_OPND_BIT_NUM: |
6071 | case AARCH64_OPND_IMMR: | |
6072 | case AARCH64_OPND_IMMS: | |
6073 | po_imm_or_fail (0, 63); | |
6074 | info->imm.value = val; | |
6075 | break; | |
6076 | ||
6077 | case AARCH64_OPND_IMM0: | |
6078 | po_imm_nc_or_fail (); | |
6079 | if (val != 0) | |
6080 | { | |
6081 | set_fatal_syntax_error (_("immediate zero expected")); | |
6082 | goto failure; | |
6083 | } | |
6084 | info->imm.value = 0; | |
6085 | break; | |
6086 | ||
6087 | case AARCH64_OPND_FPIMM0: | |
6088 | { | |
6089 | int qfloat; | |
6090 | bfd_boolean res1 = FALSE, res2 = FALSE; | |
6091 | /* N.B. -0.0 will be rejected; although -0.0 shouldn't be rejected, | |
6092 | it is probably not worth the effort to support it. */ | |
1799c0d0 RS |
6093 | if (!(res1 = parse_aarch64_imm_float (&str, &qfloat, FALSE, |
6094 | imm_reg_type)) | |
6a9deabe RS |
6095 | && (error_p () |
6096 | || !(res2 = parse_constant_immediate (&str, &val, | |
6097 | imm_reg_type)))) | |
a06ea964 NC |
6098 | goto failure; |
6099 | if ((res1 && qfloat == 0) || (res2 && val == 0)) | |
6100 | { | |
6101 | info->imm.value = 0; | |
6102 | info->imm.is_fp = 1; | |
6103 | break; | |
6104 | } | |
6105 | set_fatal_syntax_error (_("immediate zero expected")); | |
6106 | goto failure; | |
6107 | } | |
6108 | ||
6109 | case AARCH64_OPND_IMM_MOV: | |
6110 | { | |
6111 | char *saved = str; | |
8db49cc2 WN |
6112 | if (reg_name_p (str, REG_TYPE_R_Z_SP) || |
6113 | reg_name_p (str, REG_TYPE_VN)) | |
a06ea964 NC |
6114 | goto failure; |
6115 | str = saved; | |
6116 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6117 | GE_OPT_PREFIX, 1)); | |
6118 | /* The MOV immediate alias will be fixed up by fix_mov_imm_insn | |
6119 | later. fix_mov_imm_insn will try to determine a machine | |
6120 | instruction (MOVZ, MOVN or ORR) for it and will issue an error | |
6121 | message if the immediate cannot be moved by a single | |
6122 | instruction. */ | |
6123 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 1); | |
6124 | inst.base.operands[i].skip = 1; | |
6125 | } | |
6126 | break; | |
6127 | ||
6128 | case AARCH64_OPND_SIMD_IMM: | |
6129 | case AARCH64_OPND_SIMD_IMM_SFT: | |
1799c0d0 | 6130 | if (! parse_big_immediate (&str, &val, imm_reg_type)) |
a06ea964 NC |
6131 | goto failure; |
6132 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, | |
6133 | /* addr_off_p */ 0, | |
6134 | /* need_libopcodes_p */ 1, | |
6135 | /* skip_p */ 1); | |
6136 | /* Parse shift. | |
6137 | N.B. although AARCH64_OPND_SIMD_IMM doesn't permit any | |
6138 | shift, we don't check it here; we leave the checking to | |
6139 | the libopcodes (operand_general_constraint_met_p). By | |
6140 | doing this, we achieve better diagnostics. */ | |
6141 | if (skip_past_comma (&str) | |
6142 | && ! parse_shift (&str, info, SHIFTED_LSL_MSL)) | |
6143 | goto failure; | |
6144 | if (!info->shifter.operator_present | |
6145 | && info->type == AARCH64_OPND_SIMD_IMM_SFT) | |
6146 | { | |
6147 | /* Default to LSL if not present. Libopcodes prefers shifter | |
6148 | kind to be explicit. */ | |
6149 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); | |
6150 | info->shifter.kind = AARCH64_MOD_LSL; | |
6151 | } | |
6152 | break; | |
6153 | ||
6154 | case AARCH64_OPND_FPIMM: | |
6155 | case AARCH64_OPND_SIMD_FPIMM: | |
165d4950 | 6156 | case AARCH64_OPND_SVE_FPIMM8: |
a06ea964 NC |
6157 | { |
6158 | int qfloat; | |
165d4950 RS |
6159 | bfd_boolean dp_p; |
6160 | ||
6161 | dp_p = double_precision_operand_p (&inst.base.operands[0]); | |
6a9deabe | 6162 | if (!parse_aarch64_imm_float (&str, &qfloat, dp_p, imm_reg_type) |
874d7e6e | 6163 | || !aarch64_imm_float_p (qfloat)) |
a06ea964 | 6164 | { |
6a9deabe RS |
6165 | if (!error_p ()) |
6166 | set_fatal_syntax_error (_("invalid floating-point" | |
6167 | " constant")); | |
a06ea964 NC |
6168 | goto failure; |
6169 | } | |
6170 | inst.base.operands[i].imm.value = encode_imm_float_bits (qfloat); | |
6171 | inst.base.operands[i].imm.is_fp = 1; | |
6172 | } | |
6173 | break; | |
6174 | ||
165d4950 RS |
6175 | case AARCH64_OPND_SVE_I1_HALF_ONE: |
6176 | case AARCH64_OPND_SVE_I1_HALF_TWO: | |
6177 | case AARCH64_OPND_SVE_I1_ZERO_ONE: | |
6178 | { | |
6179 | int qfloat; | |
6180 | bfd_boolean dp_p; | |
6181 | ||
6182 | dp_p = double_precision_operand_p (&inst.base.operands[0]); | |
6183 | if (!parse_aarch64_imm_float (&str, &qfloat, dp_p, imm_reg_type)) | |
6184 | { | |
6185 | if (!error_p ()) | |
6186 | set_fatal_syntax_error (_("invalid floating-point" | |
6187 | " constant")); | |
6188 | goto failure; | |
6189 | } | |
6190 | inst.base.operands[i].imm.value = qfloat; | |
6191 | inst.base.operands[i].imm.is_fp = 1; | |
6192 | } | |
6193 | break; | |
6194 | ||
a06ea964 NC |
6195 | case AARCH64_OPND_LIMM: |
6196 | po_misc_or_fail (parse_shifter_operand (&str, info, | |
6197 | SHIFTED_LOGIC_IMM)); | |
6198 | if (info->shifter.operator_present) | |
6199 | { | |
6200 | set_fatal_syntax_error | |
6201 | (_("shift not allowed for bitmask immediate")); | |
6202 | goto failure; | |
6203 | } | |
6204 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, | |
6205 | /* addr_off_p */ 0, | |
6206 | /* need_libopcodes_p */ 1, | |
6207 | /* skip_p */ 1); | |
6208 | break; | |
6209 | ||
6210 | case AARCH64_OPND_AIMM: | |
dc64c2ba SP |
6211 | case AARCH64_OPND_A64C_AIMM: |
6212 | if (opcode->op == OP_ADD || opcode->op == OP_A64C_ADD) | |
a06ea964 NC |
6213 | /* ADD may have relocation types. */ |
6214 | po_misc_or_fail (parse_shifter_operand_reloc (&str, info, | |
6215 | SHIFTED_ARITH_IMM)); | |
6216 | else | |
6217 | po_misc_or_fail (parse_shifter_operand (&str, info, | |
6218 | SHIFTED_ARITH_IMM)); | |
6219 | switch (inst.reloc.type) | |
6220 | { | |
6221 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: | |
6222 | info->shifter.amount = 12; | |
6223 | break; | |
6224 | case BFD_RELOC_UNUSED: | |
6225 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 0); | |
6226 | if (info->shifter.kind != AARCH64_MOD_NONE) | |
6227 | inst.reloc.flags = FIXUP_F_HAS_EXPLICIT_SHIFT; | |
6228 | inst.reloc.pc_rel = 0; | |
6229 | break; | |
6230 | default: | |
6231 | break; | |
6232 | } | |
6233 | info->imm.value = 0; | |
6234 | if (!info->shifter.operator_present) | |
6235 | { | |
6236 | /* Default to LSL if not present. Libopcodes prefers shifter | |
6237 | kind to be explicit. */ | |
6238 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); | |
6239 | info->shifter.kind = AARCH64_MOD_LSL; | |
6240 | } | |
6241 | break; | |
6242 | ||
6243 | case AARCH64_OPND_HALF: | |
6244 | { | |
6245 | /* #<imm16> or relocation. */ | |
6246 | int internal_fixup_p; | |
6247 | po_misc_or_fail (parse_half (&str, &internal_fixup_p)); | |
6248 | if (internal_fixup_p) | |
6249 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 0); | |
6250 | skip_whitespace (str); | |
6251 | if (skip_past_comma (&str)) | |
6252 | { | |
6253 | /* {, LSL #<shift>} */ | |
6254 | if (! aarch64_gas_internal_fixup_p ()) | |
6255 | { | |
6256 | set_fatal_syntax_error (_("can't mix relocation modifier " | |
6257 | "with explicit shift")); | |
6258 | goto failure; | |
6259 | } | |
6260 | po_misc_or_fail (parse_shift (&str, info, SHIFTED_LSL)); | |
6261 | } | |
6262 | else | |
6263 | inst.base.operands[i].shifter.amount = 0; | |
6264 | inst.base.operands[i].shifter.kind = AARCH64_MOD_LSL; | |
6265 | inst.base.operands[i].imm.value = 0; | |
6266 | if (! process_movw_reloc_info ()) | |
6267 | goto failure; | |
6268 | } | |
6269 | break; | |
6270 | ||
6271 | case AARCH64_OPND_EXCEPTION: | |
09c1e68a | 6272 | case AARCH64_OPND_UNDEFINED: |
1799c0d0 RS |
6273 | po_misc_or_fail (parse_immediate_expression (&str, &inst.reloc.exp, |
6274 | imm_reg_type)); | |
a06ea964 NC |
6275 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
6276 | /* addr_off_p */ 0, | |
6277 | /* need_libopcodes_p */ 0, | |
6278 | /* skip_p */ 1); | |
6279 | break; | |
6280 | ||
6281 | case AARCH64_OPND_NZCV: | |
6282 | { | |
629310ab | 6283 | const asm_nzcv *nzcv = str_hash_find_n (aarch64_nzcv_hsh, str, 4); |
a06ea964 NC |
6284 | if (nzcv != NULL) |
6285 | { | |
6286 | str += 4; | |
6287 | info->imm.value = nzcv->value; | |
6288 | break; | |
6289 | } | |
6290 | po_imm_or_fail (0, 15); | |
6291 | info->imm.value = val; | |
6292 | } | |
6293 | break; | |
6294 | ||
6295 | case AARCH64_OPND_COND: | |
68a64283 | 6296 | case AARCH64_OPND_COND1: |
bb7eff52 RS |
6297 | { |
6298 | char *start = str; | |
6299 | do | |
6300 | str++; | |
6301 | while (ISALPHA (*str)); | |
629310ab | 6302 | info->cond = str_hash_find_n (aarch64_cond_hsh, start, str - start); |
bb7eff52 RS |
6303 | if (info->cond == NULL) |
6304 | { | |
6305 | set_syntax_error (_("invalid condition")); | |
6306 | goto failure; | |
6307 | } | |
6308 | else if (operands[i] == AARCH64_OPND_COND1 | |
6309 | && (info->cond->value & 0xe) == 0xe) | |
6310 | { | |
6311 | /* Do not allow AL or NV. */ | |
6312 | set_default_error (); | |
6313 | goto failure; | |
6314 | } | |
6315 | } | |
a06ea964 NC |
6316 | break; |
6317 | ||
6318 | case AARCH64_OPND_ADDR_ADRP: | |
6319 | po_misc_or_fail (parse_adrp (&str)); | |
6320 | /* Clear the value as operand needs to be relocated. */ | |
6321 | info->imm.value = 0; | |
6322 | break; | |
6323 | ||
6324 | case AARCH64_OPND_ADDR_PCREL14: | |
6325 | case AARCH64_OPND_ADDR_PCREL19: | |
6326 | case AARCH64_OPND_ADDR_PCREL21: | |
6327 | case AARCH64_OPND_ADDR_PCREL26: | |
73866052 | 6328 | po_misc_or_fail (parse_address (&str, info)); |
a06ea964 NC |
6329 | if (!info->addr.pcrel) |
6330 | { | |
6331 | set_syntax_error (_("invalid pc-relative address")); | |
6332 | goto failure; | |
6333 | } | |
6334 | if (inst.gen_lit_pool | |
6335 | && (opcode->iclass != loadlit || opcode->op == OP_PRFM_LIT)) | |
6336 | { | |
6337 | /* Only permit "=value" in the literal load instructions. | |
6338 | The literal will be generated by programmer_friendly_fixup. */ | |
6339 | set_syntax_error (_("invalid use of \"=immediate\"")); | |
6340 | goto failure; | |
6341 | } | |
6342 | if (inst.reloc.exp.X_op == O_symbol && find_reloc_table_entry (&str)) | |
6343 | { | |
6344 | set_syntax_error (_("unrecognized relocation suffix")); | |
6345 | goto failure; | |
6346 | } | |
6347 | if (inst.reloc.exp.X_op == O_constant && !inst.gen_lit_pool) | |
6348 | { | |
6349 | info->imm.value = inst.reloc.exp.X_add_number; | |
6350 | inst.reloc.type = BFD_RELOC_UNUSED; | |
6351 | } | |
6352 | else | |
6353 | { | |
f0070c1e SP |
6354 | bfd_boolean c64 = AARCH64_CPU_HAS_FEATURE (cpu_variant, |
6355 | AARCH64_FEATURE_C64); | |
6356 | ||
a06ea964 | 6357 | info->imm.value = 0; |
f41aef5f RE |
6358 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
6359 | switch (opcode->iclass) | |
6360 | { | |
6361 | case compbranch: | |
6362 | case condbranch: | |
6363 | /* e.g. CBZ or B.COND */ | |
6364 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL19); | |
6365 | inst.reloc.type = BFD_RELOC_AARCH64_BRANCH19; | |
6366 | break; | |
6367 | case testbranch: | |
6368 | /* e.g. TBZ */ | |
6369 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL14); | |
6370 | inst.reloc.type = BFD_RELOC_AARCH64_TSTBR14; | |
6371 | break; | |
6372 | case branch_imm: | |
6373 | /* e.g. B or BL */ | |
6374 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL26); | |
6375 | inst.reloc.type = | |
6376 | (opcode->op == OP_BL) ? BFD_RELOC_AARCH64_CALL26 | |
6377 | : BFD_RELOC_AARCH64_JUMP26; | |
6378 | break; | |
6379 | case loadlit: | |
6380 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL19); | |
6381 | inst.reloc.type = BFD_RELOC_AARCH64_LD_LO19_PCREL; | |
6382 | break; | |
6383 | case pcreladdr: | |
6384 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL21); | |
6385 | inst.reloc.type = BFD_RELOC_AARCH64_ADR_LO21_PCREL; | |
8b21361b SP |
6386 | if (inst.reloc.exp.X_op == O_symbol |
6387 | && inst.reloc.exp.X_add_symbol != NULL) | |
6388 | { | |
6389 | symbolS *sym = inst.reloc.exp.X_add_symbol; | |
6390 | ||
6391 | /* We set LSB for C64 local functions. We do not do | |
6392 | this for local labels even in code section because | |
6393 | it could be embedded data. */ | |
6394 | if (S_IS_DEFINED (sym) && AARCH64_IS_C64 (sym) | |
6395 | && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)) | |
6396 | { | |
6397 | inst.reloc.exp.X_add_number += 1; | |
6398 | } | |
6399 | } | |
6400 | ||
f41aef5f RE |
6401 | break; |
6402 | default: | |
6403 | gas_assert (0); | |
6404 | abort (); | |
6405 | } | |
f0070c1e SP |
6406 | if (c64) |
6407 | inst.reloc.flags = FIXUP_F_C64; | |
a06ea964 NC |
6408 | inst.reloc.pc_rel = 1; |
6409 | } | |
6410 | break; | |
6411 | ||
6412 | case AARCH64_OPND_ADDR_SIMPLE: | |
6413 | case AARCH64_OPND_SIMD_ADDR_SIMPLE: | |
e1b988bb RS |
6414 | { |
6415 | /* [<Xn|SP>{, #<simm>}] */ | |
6416 | char *start = str; | |
6417 | /* First use the normal address-parsing routines, to get | |
6418 | the usual syntax errors. */ | |
73866052 | 6419 | po_misc_or_fail (parse_address (&str, info)); |
e1b988bb RS |
6420 | if (info->addr.pcrel || info->addr.offset.is_reg |
6421 | || !info->addr.preind || info->addr.postind | |
550fd7bf | 6422 | || info->addr.writeback) |
e1b988bb RS |
6423 | { |
6424 | set_syntax_error (_("invalid addressing mode")); | |
6425 | goto failure; | |
6426 | } | |
6427 | ||
6428 | /* Then retry, matching the specific syntax of these addresses. */ | |
6429 | str = start; | |
6430 | po_char_or_fail ('['); | |
3493da5c SP |
6431 | po_reg_or_fail (AARCH64_CPU_HAS_FEATURE (cpu_variant, |
6432 | AARCH64_FEATURE_C64) | |
6433 | ? REG_TYPE_CA_N_SP : REG_TYPE_R64_SP); | |
6434 | ||
e1b988bb RS |
6435 | /* Accept optional ", #0". */ |
6436 | if (operands[i] == AARCH64_OPND_ADDR_SIMPLE | |
6437 | && skip_past_char (&str, ',')) | |
6438 | { | |
6439 | skip_past_char (&str, '#'); | |
6440 | if (! skip_past_char (&str, '0')) | |
6441 | { | |
6442 | set_fatal_syntax_error | |
6443 | (_("the optional immediate offset can only be 0")); | |
6444 | goto failure; | |
6445 | } | |
6446 | } | |
6447 | po_char_or_fail (']'); | |
6448 | break; | |
6449 | } | |
a06ea964 NC |
6450 | |
6451 | case AARCH64_OPND_ADDR_REGOFF: | |
6452 | /* [<Xn|SP>, <R><m>{, <extend> {<amount>}}] */ | |
73866052 | 6453 | po_misc_or_fail (parse_address (&str, info)); |
4df068de | 6454 | regoff_addr: |
a06ea964 NC |
6455 | if (info->addr.pcrel || !info->addr.offset.is_reg |
6456 | || !info->addr.preind || info->addr.postind | |
6457 | || info->addr.writeback) | |
6458 | { | |
6459 | set_syntax_error (_("invalid addressing mode")); | |
6460 | goto failure; | |
6461 | } | |
6462 | if (!info->shifter.operator_present) | |
6463 | { | |
6464 | /* Default to LSL if not present. Libopcodes prefers shifter | |
6465 | kind to be explicit. */ | |
6466 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); | |
6467 | info->shifter.kind = AARCH64_MOD_LSL; | |
6468 | } | |
6469 | /* Qualifier to be deduced by libopcodes. */ | |
6470 | break; | |
6471 | ||
6472 | case AARCH64_OPND_ADDR_SIMM7: | |
73866052 | 6473 | po_misc_or_fail (parse_address (&str, info)); |
a06ea964 NC |
6474 | if (info->addr.pcrel || info->addr.offset.is_reg |
6475 | || (!info->addr.preind && !info->addr.postind)) | |
6476 | { | |
6477 | set_syntax_error (_("invalid addressing mode")); | |
6478 | goto failure; | |
6479 | } | |
73866052 RS |
6480 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
6481 | { | |
6482 | set_syntax_error (_("relocation not allowed")); | |
6483 | goto failure; | |
6484 | } | |
a06ea964 NC |
6485 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
6486 | /* addr_off_p */ 1, | |
6487 | /* need_libopcodes_p */ 1, | |
6488 | /* skip_p */ 0); | |
6489 | break; | |
6490 | ||
6491 | case AARCH64_OPND_ADDR_SIMM9: | |
6492 | case AARCH64_OPND_ADDR_SIMM9_2: | |
fb3265b3 SD |
6493 | case AARCH64_OPND_ADDR_SIMM11: |
6494 | case AARCH64_OPND_ADDR_SIMM13: | |
73866052 | 6495 | po_misc_or_fail (parse_address (&str, info)); |
a06ea964 NC |
6496 | if (info->addr.pcrel || info->addr.offset.is_reg |
6497 | || (!info->addr.preind && !info->addr.postind) | |
6498 | || (operands[i] == AARCH64_OPND_ADDR_SIMM9_2 | |
6499 | && info->addr.writeback)) | |
6500 | { | |
6501 | set_syntax_error (_("invalid addressing mode")); | |
6502 | goto failure; | |
6503 | } | |
6504 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
6505 | { | |
6506 | set_syntax_error (_("relocation not allowed")); | |
6507 | goto failure; | |
6508 | } | |
6509 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, | |
6510 | /* addr_off_p */ 1, | |
6511 | /* need_libopcodes_p */ 1, | |
6512 | /* skip_p */ 0); | |
6513 | break; | |
6514 | ||
3f06e550 | 6515 | case AARCH64_OPND_ADDR_SIMM10: |
f42f1a1d | 6516 | case AARCH64_OPND_ADDR_OFFSET: |
3f06e550 SN |
6517 | po_misc_or_fail (parse_address (&str, info)); |
6518 | if (info->addr.pcrel || info->addr.offset.is_reg | |
6519 | || !info->addr.preind || info->addr.postind) | |
6520 | { | |
6521 | set_syntax_error (_("invalid addressing mode")); | |
6522 | goto failure; | |
6523 | } | |
6524 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
6525 | { | |
6526 | set_syntax_error (_("relocation not allowed")); | |
6527 | goto failure; | |
6528 | } | |
6529 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, | |
6530 | /* addr_off_p */ 1, | |
6531 | /* need_libopcodes_p */ 1, | |
6532 | /* skip_p */ 0); | |
6533 | break; | |
6534 | ||
a06ea964 | 6535 | case AARCH64_OPND_ADDR_UIMM12: |
73866052 | 6536 | po_misc_or_fail (parse_address (&str, info)); |
a06ea964 NC |
6537 | if (info->addr.pcrel || info->addr.offset.is_reg |
6538 | || !info->addr.preind || info->addr.writeback) | |
6539 | { | |
6540 | set_syntax_error (_("invalid addressing mode")); | |
6541 | goto failure; | |
6542 | } | |
6543 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
6544 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 1); | |
4c562523 JW |
6545 | else if (inst.reloc.type == BFD_RELOC_AARCH64_LDST_LO12 |
6546 | || (inst.reloc.type | |
6547 | == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12) | |
6548 | || (inst.reloc.type | |
84f1b9fb RL |
6549 | == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC) |
6550 | || (inst.reloc.type | |
6551 | == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12) | |
6552 | || (inst.reloc.type | |
6553 | == BFD_RELOC_AARCH64_TLSLE_LDST_TPREL_LO12_NC)) | |
a06ea964 NC |
6554 | inst.reloc.type = ldst_lo12_determine_real_reloc_type (); |
6555 | /* Leave qualifier to be determined by libopcodes. */ | |
6556 | break; | |
6557 | ||
6558 | case AARCH64_OPND_SIMD_ADDR_POST: | |
6559 | /* [<Xn|SP>], <Xm|#<amount>> */ | |
73866052 | 6560 | po_misc_or_fail (parse_address (&str, info)); |
a06ea964 NC |
6561 | if (!info->addr.postind || !info->addr.writeback) |
6562 | { | |
6563 | set_syntax_error (_("invalid addressing mode")); | |
6564 | goto failure; | |
6565 | } | |
6566 | if (!info->addr.offset.is_reg) | |
6567 | { | |
6568 | if (inst.reloc.exp.X_op == O_constant) | |
6569 | info->addr.offset.imm = inst.reloc.exp.X_add_number; | |
6570 | else | |
6571 | { | |
6572 | set_fatal_syntax_error | |
ab3b8fcf | 6573 | (_("writeback value must be an immediate constant")); |
a06ea964 NC |
6574 | goto failure; |
6575 | } | |
6576 | } | |
6577 | /* No qualifier. */ | |
6578 | break; | |
6579 | ||
582e12bf | 6580 | case AARCH64_OPND_SVE_ADDR_RI_S4x16: |
8382113f | 6581 | case AARCH64_OPND_SVE_ADDR_RI_S4x32: |
98907a70 RS |
6582 | case AARCH64_OPND_SVE_ADDR_RI_S4xVL: |
6583 | case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL: | |
6584 | case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL: | |
6585 | case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL: | |
6586 | case AARCH64_OPND_SVE_ADDR_RI_S6xVL: | |
6587 | case AARCH64_OPND_SVE_ADDR_RI_S9xVL: | |
4df068de RS |
6588 | case AARCH64_OPND_SVE_ADDR_RI_U6: |
6589 | case AARCH64_OPND_SVE_ADDR_RI_U6x2: | |
6590 | case AARCH64_OPND_SVE_ADDR_RI_U6x4: | |
6591 | case AARCH64_OPND_SVE_ADDR_RI_U6x8: | |
98907a70 RS |
6592 | /* [X<n>{, #imm, MUL VL}] |
6593 | [X<n>{, #imm}] | |
4df068de RS |
6594 | but recognizing SVE registers. */ |
6595 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6596 | &offset_qualifier)); | |
6597 | if (base_qualifier != AARCH64_OPND_QLF_X) | |
6598 | { | |
6599 | set_syntax_error (_("invalid addressing mode")); | |
6600 | goto failure; | |
6601 | } | |
6602 | sve_regimm: | |
6603 | if (info->addr.pcrel || info->addr.offset.is_reg | |
6604 | || !info->addr.preind || info->addr.writeback) | |
6605 | { | |
6606 | set_syntax_error (_("invalid addressing mode")); | |
6607 | goto failure; | |
6608 | } | |
6609 | if (inst.reloc.type != BFD_RELOC_UNUSED | |
6610 | || inst.reloc.exp.X_op != O_constant) | |
6611 | { | |
6612 | /* Make sure this has priority over | |
6613 | "invalid addressing mode". */ | |
6614 | set_fatal_syntax_error (_("constant offset required")); | |
6615 | goto failure; | |
6616 | } | |
6617 | info->addr.offset.imm = inst.reloc.exp.X_add_number; | |
6618 | break; | |
6619 | ||
c8d59609 NC |
6620 | case AARCH64_OPND_SVE_ADDR_R: |
6621 | /* [<Xn|SP>{, <R><m>}] | |
6622 | but recognizing SVE registers. */ | |
6623 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6624 | &offset_qualifier)); | |
6625 | if (offset_qualifier == AARCH64_OPND_QLF_NIL) | |
6626 | { | |
6627 | offset_qualifier = AARCH64_OPND_QLF_X; | |
6628 | info->addr.offset.is_reg = 1; | |
6629 | info->addr.offset.regno = 31; | |
6630 | } | |
6631 | else if (base_qualifier != AARCH64_OPND_QLF_X | |
6632 | || offset_qualifier != AARCH64_OPND_QLF_X) | |
6633 | { | |
6634 | set_syntax_error (_("invalid addressing mode")); | |
6635 | goto failure; | |
6636 | } | |
6637 | goto regoff_addr; | |
6638 | ||
4df068de RS |
6639 | case AARCH64_OPND_SVE_ADDR_RR: |
6640 | case AARCH64_OPND_SVE_ADDR_RR_LSL1: | |
6641 | case AARCH64_OPND_SVE_ADDR_RR_LSL2: | |
6642 | case AARCH64_OPND_SVE_ADDR_RR_LSL3: | |
6643 | case AARCH64_OPND_SVE_ADDR_RX: | |
6644 | case AARCH64_OPND_SVE_ADDR_RX_LSL1: | |
6645 | case AARCH64_OPND_SVE_ADDR_RX_LSL2: | |
6646 | case AARCH64_OPND_SVE_ADDR_RX_LSL3: | |
6647 | /* [<Xn|SP>, <R><m>{, lsl #<amount>}] | |
6648 | but recognizing SVE registers. */ | |
6649 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6650 | &offset_qualifier)); | |
6651 | if (base_qualifier != AARCH64_OPND_QLF_X | |
6652 | || offset_qualifier != AARCH64_OPND_QLF_X) | |
6653 | { | |
6654 | set_syntax_error (_("invalid addressing mode")); | |
6655 | goto failure; | |
6656 | } | |
6657 | goto regoff_addr; | |
6658 | ||
6659 | case AARCH64_OPND_SVE_ADDR_RZ: | |
6660 | case AARCH64_OPND_SVE_ADDR_RZ_LSL1: | |
6661 | case AARCH64_OPND_SVE_ADDR_RZ_LSL2: | |
6662 | case AARCH64_OPND_SVE_ADDR_RZ_LSL3: | |
6663 | case AARCH64_OPND_SVE_ADDR_RZ_XTW_14: | |
6664 | case AARCH64_OPND_SVE_ADDR_RZ_XTW_22: | |
6665 | case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14: | |
6666 | case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22: | |
6667 | case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14: | |
6668 | case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22: | |
6669 | case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14: | |
6670 | case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22: | |
6671 | /* [<Xn|SP>, Z<m>.D{, LSL #<amount>}] | |
6672 | [<Xn|SP>, Z<m>.<T>, <extend> {#<amount>}] */ | |
6673 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6674 | &offset_qualifier)); | |
6675 | if (base_qualifier != AARCH64_OPND_QLF_X | |
6676 | || (offset_qualifier != AARCH64_OPND_QLF_S_S | |
6677 | && offset_qualifier != AARCH64_OPND_QLF_S_D)) | |
6678 | { | |
6679 | set_syntax_error (_("invalid addressing mode")); | |
6680 | goto failure; | |
6681 | } | |
6682 | info->qualifier = offset_qualifier; | |
6683 | goto regoff_addr; | |
6684 | ||
c469c864 MM |
6685 | case AARCH64_OPND_SVE_ADDR_ZX: |
6686 | /* [Zn.<T>{, <Xm>}]. */ | |
6687 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6688 | &offset_qualifier)); | |
6689 | /* Things to check: | |
6690 | base_qualifier either S_S or S_D | |
6691 | offset_qualifier must be X | |
6692 | */ | |
6693 | if ((base_qualifier != AARCH64_OPND_QLF_S_S | |
6694 | && base_qualifier != AARCH64_OPND_QLF_S_D) | |
6695 | || offset_qualifier != AARCH64_OPND_QLF_X) | |
6696 | { | |
6697 | set_syntax_error (_("invalid addressing mode")); | |
6698 | goto failure; | |
6699 | } | |
6700 | info->qualifier = base_qualifier; | |
6701 | if (!info->addr.offset.is_reg || info->addr.pcrel | |
6702 | || !info->addr.preind || info->addr.writeback | |
6703 | || info->shifter.operator_present != 0) | |
6704 | { | |
6705 | set_syntax_error (_("invalid addressing mode")); | |
6706 | goto failure; | |
6707 | } | |
6708 | info->shifter.kind = AARCH64_MOD_LSL; | |
6709 | break; | |
6710 | ||
6711 | ||
4df068de RS |
6712 | case AARCH64_OPND_SVE_ADDR_ZI_U5: |
6713 | case AARCH64_OPND_SVE_ADDR_ZI_U5x2: | |
6714 | case AARCH64_OPND_SVE_ADDR_ZI_U5x4: | |
6715 | case AARCH64_OPND_SVE_ADDR_ZI_U5x8: | |
6716 | /* [Z<n>.<T>{, #imm}] */ | |
6717 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6718 | &offset_qualifier)); | |
6719 | if (base_qualifier != AARCH64_OPND_QLF_S_S | |
6720 | && base_qualifier != AARCH64_OPND_QLF_S_D) | |
6721 | { | |
6722 | set_syntax_error (_("invalid addressing mode")); | |
6723 | goto failure; | |
6724 | } | |
6725 | info->qualifier = base_qualifier; | |
6726 | goto sve_regimm; | |
6727 | ||
6728 | case AARCH64_OPND_SVE_ADDR_ZZ_LSL: | |
6729 | case AARCH64_OPND_SVE_ADDR_ZZ_SXTW: | |
6730 | case AARCH64_OPND_SVE_ADDR_ZZ_UXTW: | |
6731 | /* [Z<n>.<T>, Z<m>.<T>{, LSL #<amount>}] | |
6732 | [Z<n>.D, Z<m>.D, <extend> {#<amount>}] | |
6733 | ||
6734 | We don't reject: | |
6735 | ||
6736 | [Z<n>.S, Z<m>.S, <extend> {#<amount>}] | |
6737 | ||
6738 | here since we get better error messages by leaving it to | |
6739 | the qualifier checking routines. */ | |
6740 | po_misc_or_fail (parse_sve_address (&str, info, &base_qualifier, | |
6741 | &offset_qualifier)); | |
6742 | if ((base_qualifier != AARCH64_OPND_QLF_S_S | |
6743 | && base_qualifier != AARCH64_OPND_QLF_S_D) | |
6744 | || offset_qualifier != base_qualifier) | |
6745 | { | |
6746 | set_syntax_error (_("invalid addressing mode")); | |
6747 | goto failure; | |
6748 | } | |
6749 | info->qualifier = base_qualifier; | |
6750 | goto regoff_addr; | |
6751 | ||
a06ea964 | 6752 | case AARCH64_OPND_SYSREG: |
7d02540a TC |
6753 | { |
6754 | uint32_t sysreg_flags; | |
6755 | if ((val = parse_sys_reg (&str, aarch64_sys_regs_hsh, 1, 0, | |
6756 | &sysreg_flags)) == PARSE_FAIL) | |
6757 | { | |
6758 | set_syntax_error (_("unknown or missing system register name")); | |
6759 | goto failure; | |
6760 | } | |
6761 | inst.base.operands[i].sysreg.value = val; | |
6762 | inst.base.operands[i].sysreg.flags = sysreg_flags; | |
6763 | break; | |
6764 | } | |
a06ea964 NC |
6765 | |
6766 | case AARCH64_OPND_PSTATEFIELD: | |
561a72d4 | 6767 | if ((val = parse_sys_reg (&str, aarch64_pstatefield_hsh, 0, 1, NULL)) |
a3251895 | 6768 | == PARSE_FAIL) |
a06ea964 NC |
6769 | { |
6770 | set_syntax_error (_("unknown or missing PSTATE field name")); | |
6771 | goto failure; | |
6772 | } | |
6773 | inst.base.operands[i].pstatefield = val; | |
6774 | break; | |
6775 | ||
6776 | case AARCH64_OPND_SYSREG_IC: | |
6777 | inst.base.operands[i].sysins_op = | |
6778 | parse_sys_ins_reg (&str, aarch64_sys_regs_ic_hsh); | |
6779 | goto sys_reg_ins; | |
2ac435d4 | 6780 | |
a06ea964 NC |
6781 | case AARCH64_OPND_SYSREG_DC: |
6782 | inst.base.operands[i].sysins_op = | |
6783 | parse_sys_ins_reg (&str, aarch64_sys_regs_dc_hsh); | |
6784 | goto sys_reg_ins; | |
2ac435d4 | 6785 | |
a06ea964 NC |
6786 | case AARCH64_OPND_SYSREG_AT: |
6787 | inst.base.operands[i].sysins_op = | |
6788 | parse_sys_ins_reg (&str, aarch64_sys_regs_at_hsh); | |
6789 | goto sys_reg_ins; | |
2ac435d4 SD |
6790 | |
6791 | case AARCH64_OPND_SYSREG_SR: | |
6792 | inst.base.operands[i].sysins_op = | |
6793 | parse_sys_ins_reg (&str, aarch64_sys_regs_sr_hsh); | |
6794 | goto sys_reg_ins; | |
6795 | ||
a06ea964 NC |
6796 | case AARCH64_OPND_SYSREG_TLBI: |
6797 | inst.base.operands[i].sysins_op = | |
6798 | parse_sys_ins_reg (&str, aarch64_sys_regs_tlbi_hsh); | |
dc1e8a47 | 6799 | sys_reg_ins: |
a06ea964 NC |
6800 | if (inst.base.operands[i].sysins_op == NULL) |
6801 | { | |
6802 | set_fatal_syntax_error ( _("unknown or missing operation name")); | |
6803 | goto failure; | |
6804 | } | |
6805 | break; | |
6806 | ||
6807 | case AARCH64_OPND_BARRIER: | |
6808 | case AARCH64_OPND_BARRIER_ISB: | |
6809 | val = parse_barrier (&str); | |
6810 | if (val != PARSE_FAIL | |
6811 | && operands[i] == AARCH64_OPND_BARRIER_ISB && val != 0xf) | |
6812 | { | |
6813 | /* ISB only accepts options name 'sy'. */ | |
6814 | set_syntax_error | |
6815 | (_("the specified option is not accepted in ISB")); | |
6816 | /* Turn off backtrack as this optional operand is present. */ | |
6817 | backtrack_pos = 0; | |
6818 | goto failure; | |
6819 | } | |
6820 | /* This is an extension to accept a 0..15 immediate. */ | |
6821 | if (val == PARSE_FAIL) | |
6822 | po_imm_or_fail (0, 15); | |
6823 | info->barrier = aarch64_barrier_options + val; | |
6824 | break; | |
6825 | ||
6826 | case AARCH64_OPND_PRFOP: | |
6827 | val = parse_pldop (&str); | |
6828 | /* This is an extension to accept a 0..31 immediate. */ | |
6829 | if (val == PARSE_FAIL) | |
6830 | po_imm_or_fail (0, 31); | |
6831 | inst.base.operands[i].prfop = aarch64_prfops + val; | |
6832 | break; | |
6833 | ||
1e6f4800 MW |
6834 | case AARCH64_OPND_BARRIER_PSB: |
6835 | val = parse_barrier_psb (&str, &(info->hint_option)); | |
6836 | if (val == PARSE_FAIL) | |
6837 | goto failure; | |
6838 | break; | |
6839 | ||
ff605452 SD |
6840 | case AARCH64_OPND_BTI_TARGET: |
6841 | val = parse_bti_operand (&str, &(info->hint_option)); | |
6842 | if (val == PARSE_FAIL) | |
6843 | goto failure; | |
6844 | break; | |
6845 | ||
a06ea964 NC |
6846 | default: |
6847 | as_fatal (_("unhandled operand code %d"), operands[i]); | |
6848 | } | |
6849 | ||
6850 | /* If we get here, this operand was successfully parsed. */ | |
6851 | inst.base.operands[i].present = 1; | |
6852 | continue; | |
6853 | ||
dc1e8a47 | 6854 | failure: |
a06ea964 NC |
6855 | /* The parse routine should already have set the error, but in case |
6856 | not, set a default one here. */ | |
6857 | if (! error_p ()) | |
6858 | set_default_error (); | |
6859 | ||
6860 | if (! backtrack_pos) | |
6861 | goto parse_operands_return; | |
6862 | ||
f4c51f60 JW |
6863 | { |
6864 | /* We reach here because this operand is marked as optional, and | |
6865 | either no operand was supplied or the operand was supplied but it | |
6866 | was syntactically incorrect. In the latter case we report an | |
6867 | error. In the former case we perform a few more checks before | |
6868 | dropping through to the code to insert the default operand. */ | |
6869 | ||
6870 | char *tmp = backtrack_pos; | |
6871 | char endchar = END_OF_INSN; | |
6872 | ||
6873 | if (i != (aarch64_num_of_operands (opcode) - 1)) | |
6874 | endchar = ','; | |
6875 | skip_past_char (&tmp, ','); | |
6876 | ||
6877 | if (*tmp != endchar) | |
6878 | /* The user has supplied an operand in the wrong format. */ | |
6879 | goto parse_operands_return; | |
6880 | ||
6881 | /* Make sure there is not a comma before the optional operand. | |
6882 | For example the fifth operand of 'sys' is optional: | |
6883 | ||
6884 | sys #0,c0,c0,#0, <--- wrong | |
6885 | sys #0,c0,c0,#0 <--- correct. */ | |
6886 | if (comma_skipped_p && i && endchar == END_OF_INSN) | |
6887 | { | |
6888 | set_fatal_syntax_error | |
6889 | (_("unexpected comma before the omitted optional operand")); | |
6890 | goto parse_operands_return; | |
6891 | } | |
6892 | } | |
6893 | ||
a06ea964 NC |
6894 | /* Reaching here means we are dealing with an optional operand that is |
6895 | omitted from the assembly line. */ | |
6896 | gas_assert (optional_operand_p (opcode, i)); | |
6897 | info->present = 0; | |
6898 | process_omitted_operand (operands[i], opcode, i, info); | |
6899 | ||
6900 | /* Try again, skipping the optional operand at backtrack_pos. */ | |
6901 | str = backtrack_pos; | |
6902 | backtrack_pos = 0; | |
6903 | ||
a06ea964 NC |
6904 | /* Clear any error record after the omitted optional operand has been |
6905 | successfully handled. */ | |
6906 | clear_error (); | |
6907 | } | |
6908 | ||
6909 | /* Check if we have parsed all the operands. */ | |
6910 | if (*str != '\0' && ! error_p ()) | |
6911 | { | |
6912 | /* Set I to the index of the last present operand; this is | |
6913 | for the purpose of diagnostics. */ | |
6914 | for (i -= 1; i >= 0 && !inst.base.operands[i].present; --i) | |
6915 | ; | |
6916 | set_fatal_syntax_error | |
6917 | (_("unexpected characters following instruction")); | |
6918 | } | |
6919 | ||
dc1e8a47 | 6920 | parse_operands_return: |
a06ea964 NC |
6921 | |
6922 | if (error_p ()) | |
6923 | { | |
6924 | DEBUG_TRACE ("parsing FAIL: %s - %s", | |
6925 | operand_mismatch_kind_names[get_error_kind ()], | |
6926 | get_error_message ()); | |
6927 | /* Record the operand error properly; this is useful when there | |
6928 | are multiple instruction templates for a mnemonic name, so that | |
6929 | later on, we can select the error that most closely describes | |
6930 | the problem. */ | |
6931 | record_operand_error (opcode, i, get_error_kind (), | |
6932 | get_error_message ()); | |
6933 | return FALSE; | |
6934 | } | |
6935 | else | |
6936 | { | |
6937 | DEBUG_TRACE ("parsing SUCCESS"); | |
6938 | return TRUE; | |
6939 | } | |
6940 | } | |
6941 | ||
6942 | /* It does some fix-up to provide some programmer friendly feature while | |
6943 | keeping the libopcodes happy, i.e. libopcodes only accepts | |
6944 | the preferred architectural syntax. | |
6945 | Return FALSE if there is any failure; otherwise return TRUE. */ | |
6946 | ||
6947 | static bfd_boolean | |
6948 | programmer_friendly_fixup (aarch64_instruction *instr) | |
6949 | { | |
6950 | aarch64_inst *base = &instr->base; | |
6951 | const aarch64_opcode *opcode = base->opcode; | |
6952 | enum aarch64_op op = opcode->op; | |
6953 | aarch64_opnd_info *operands = base->operands; | |
6954 | ||
6955 | DEBUG_TRACE ("enter"); | |
6956 | ||
6957 | switch (opcode->iclass) | |
6958 | { | |
6959 | case testbranch: | |
6960 | /* TBNZ Xn|Wn, #uimm6, label | |
6961 | Test and Branch Not Zero: conditionally jumps to label if bit number | |
6962 | uimm6 in register Xn is not zero. The bit number implies the width of | |
6963 | the register, which may be written and should be disassembled as Wn if | |
6964 | uimm is less than 32. */ | |
6965 | if (operands[0].qualifier == AARCH64_OPND_QLF_W) | |
6966 | { | |
6967 | if (operands[1].imm.value >= 32) | |
6968 | { | |
6969 | record_operand_out_of_range_error (opcode, 1, _("immediate value"), | |
6970 | 0, 31); | |
6971 | return FALSE; | |
6972 | } | |
6973 | operands[0].qualifier = AARCH64_OPND_QLF_X; | |
6974 | } | |
6975 | break; | |
6976 | case loadlit: | |
6977 | /* LDR Wt, label | =value | |
6978 | As a convenience assemblers will typically permit the notation | |
6979 | "=value" in conjunction with the pc-relative literal load instructions | |
6980 | to automatically place an immediate value or symbolic address in a | |
6981 | nearby literal pool and generate a hidden label which references it. | |
6982 | ISREG has been set to 0 in the case of =value. */ | |
6983 | if (instr->gen_lit_pool | |
6984 | && (op == OP_LDR_LIT || op == OP_LDRV_LIT || op == OP_LDRSW_LIT)) | |
6985 | { | |
6986 | int size = aarch64_get_qualifier_esize (operands[0].qualifier); | |
6987 | if (op == OP_LDRSW_LIT) | |
6988 | size = 4; | |
6989 | if (instr->reloc.exp.X_op != O_constant | |
67a32447 | 6990 | && instr->reloc.exp.X_op != O_big |
a06ea964 NC |
6991 | && instr->reloc.exp.X_op != O_symbol) |
6992 | { | |
6993 | record_operand_error (opcode, 1, | |
6994 | AARCH64_OPDE_FATAL_SYNTAX_ERROR, | |
6995 | _("constant expression expected")); | |
6996 | return FALSE; | |
6997 | } | |
6998 | if (! add_to_lit_pool (&instr->reloc.exp, size)) | |
6999 | { | |
7000 | record_operand_error (opcode, 1, | |
7001 | AARCH64_OPDE_OTHER_ERROR, | |
7002 | _("literal pool insertion failed")); | |
7003 | return FALSE; | |
7004 | } | |
7005 | } | |
7006 | break; | |
a06ea964 NC |
7007 | case log_shift: |
7008 | case bitfield: | |
7009 | /* UXT[BHW] Wd, Wn | |
7010 | Unsigned Extend Byte|Halfword|Word: UXT[BH] is architectural alias | |
7011 | for UBFM Wd,Wn,#0,#7|15, while UXTW is pseudo instruction which is | |
7012 | encoded using ORR Wd, WZR, Wn (MOV Wd,Wn). | |
7013 | A programmer-friendly assembler should accept a destination Xd in | |
7014 | place of Wd, however that is not the preferred form for disassembly. | |
7015 | */ | |
7016 | if ((op == OP_UXTB || op == OP_UXTH || op == OP_UXTW) | |
7017 | && operands[1].qualifier == AARCH64_OPND_QLF_W | |
7018 | && operands[0].qualifier == AARCH64_OPND_QLF_X) | |
7019 | operands[0].qualifier = AARCH64_OPND_QLF_W; | |
7020 | break; | |
7021 | ||
7022 | case addsub_ext: | |
7023 | { | |
7024 | /* In the 64-bit form, the final register operand is written as Wm | |
7025 | for all but the (possibly omitted) UXTX/LSL and SXTX | |
7026 | operators. | |
7027 | As a programmer-friendly assembler, we accept e.g. | |
7028 | ADDS <Xd>, <Xn|SP>, <Xm>{, UXTB {#<amount>}} and change it to | |
7029 | ADDS <Xd>, <Xn|SP>, <Wm>{, UXTB {#<amount>}}. */ | |
7030 | int idx = aarch64_operand_index (opcode->operands, | |
7031 | AARCH64_OPND_Rm_EXT); | |
7032 | gas_assert (idx == 1 || idx == 2); | |
7033 | if (operands[0].qualifier == AARCH64_OPND_QLF_X | |
7034 | && operands[idx].qualifier == AARCH64_OPND_QLF_X | |
7035 | && operands[idx].shifter.kind != AARCH64_MOD_LSL | |
7036 | && operands[idx].shifter.kind != AARCH64_MOD_UXTX | |
7037 | && operands[idx].shifter.kind != AARCH64_MOD_SXTX) | |
7038 | operands[idx].qualifier = AARCH64_OPND_QLF_W; | |
7039 | } | |
7040 | break; | |
7041 | ||
7042 | default: | |
7043 | break; | |
7044 | } | |
7045 | ||
7046 | DEBUG_TRACE ("exit with SUCCESS"); | |
7047 | return TRUE; | |
7048 | } | |
7049 | ||
5c47e525 | 7050 | /* Check for loads and stores that will cause unpredictable behavior. */ |
54a28c4c JW |
7051 | |
7052 | static void | |
7053 | warn_unpredictable_ldst (aarch64_instruction *instr, char *str) | |
7054 | { | |
7055 | aarch64_inst *base = &instr->base; | |
7056 | const aarch64_opcode *opcode = base->opcode; | |
7057 | const aarch64_opnd_info *opnds = base->operands; | |
7058 | switch (opcode->iclass) | |
7059 | { | |
7060 | case ldst_pos: | |
7061 | case ldst_imm9: | |
3f06e550 | 7062 | case ldst_imm10: |
54a28c4c JW |
7063 | case ldst_unscaled: |
7064 | case ldst_unpriv: | |
5c47e525 RE |
7065 | /* Loading/storing the base register is unpredictable if writeback. */ |
7066 | if ((aarch64_get_operand_class (opnds[0].type) | |
7067 | == AARCH64_OPND_CLASS_INT_REG) | |
7068 | && opnds[0].reg.regno == opnds[1].addr.base_regno | |
4bf8c6e8 | 7069 | && opnds[1].addr.base_regno != REG_SP |
69105ce4 SD |
7070 | /* Exempt STG/STZG/ST2G/STZ2G. */ |
7071 | && !(opnds[1].type == AARCH64_OPND_ADDR_SIMM13) | |
54a28c4c | 7072 | && opnds[1].addr.writeback) |
5c47e525 | 7073 | as_warn (_("unpredictable transfer with writeback -- `%s'"), str); |
54a28c4c | 7074 | break; |
503ba600 | 7075 | |
54a28c4c JW |
7076 | case ldstpair_off: |
7077 | case ldstnapair_offs: | |
7078 | case ldstpair_indexed: | |
5c47e525 RE |
7079 | /* Loading/storing the base register is unpredictable if writeback. */ |
7080 | if ((aarch64_get_operand_class (opnds[0].type) | |
7081 | == AARCH64_OPND_CLASS_INT_REG) | |
7082 | && (opnds[0].reg.regno == opnds[2].addr.base_regno | |
7083 | || opnds[1].reg.regno == opnds[2].addr.base_regno) | |
4bf8c6e8 | 7084 | && opnds[2].addr.base_regno != REG_SP |
fb3265b3 SD |
7085 | /* Exempt STGP. */ |
7086 | && !(opnds[2].type == AARCH64_OPND_ADDR_SIMM11) | |
54a28c4c | 7087 | && opnds[2].addr.writeback) |
5c47e525 RE |
7088 | as_warn (_("unpredictable transfer with writeback -- `%s'"), str); |
7089 | /* Load operations must load different registers. */ | |
54a28c4c JW |
7090 | if ((opcode->opcode & (1 << 22)) |
7091 | && opnds[0].reg.regno == opnds[1].reg.regno) | |
7092 | as_warn (_("unpredictable load of register pair -- `%s'"), str); | |
7093 | break; | |
ee943970 RR |
7094 | |
7095 | case ldstexcl: | |
7096 | /* It is unpredictable if the destination and status registers are the | |
7097 | same. */ | |
7098 | if ((aarch64_get_operand_class (opnds[0].type) | |
7099 | == AARCH64_OPND_CLASS_INT_REG) | |
7100 | && (aarch64_get_operand_class (opnds[1].type) | |
7101 | == AARCH64_OPND_CLASS_INT_REG) | |
7102 | && (opnds[0].reg.regno == opnds[1].reg.regno | |
7103 | || opnds[0].reg.regno == opnds[2].reg.regno)) | |
7104 | as_warn (_("unpredictable: identical transfer and status registers" | |
7105 | " --`%s'"), | |
7106 | str); | |
7107 | ||
7108 | break; | |
7109 | ||
54a28c4c JW |
7110 | default: |
7111 | break; | |
7112 | } | |
7113 | } | |
7114 | ||
4f5d2536 TC |
7115 | static void |
7116 | force_automatic_sequence_close (void) | |
7117 | { | |
7118 | if (now_instr_sequence.instr) | |
7119 | { | |
7120 | as_warn (_("previous `%s' sequence has not been closed"), | |
7121 | now_instr_sequence.instr->opcode->name); | |
7122 | init_insn_sequence (NULL, &now_instr_sequence); | |
7123 | } | |
7124 | } | |
7125 | ||
a06ea964 NC |
7126 | /* A wrapper function to interface with libopcodes on encoding and |
7127 | record the error message if there is any. | |
7128 | ||
7129 | Return TRUE on success; otherwise return FALSE. */ | |
7130 | ||
7131 | static bfd_boolean | |
7132 | do_encode (const aarch64_opcode *opcode, aarch64_inst *instr, | |
7133 | aarch64_insn *code) | |
7134 | { | |
7135 | aarch64_operand_error error_info; | |
7d02540a | 7136 | memset (&error_info, '\0', sizeof (error_info)); |
a06ea964 | 7137 | error_info.kind = AARCH64_OPDE_NIL; |
3979cf50 SP |
7138 | if (aarch64_opcode_encode (cpu_variant, opcode, instr, code, NULL, |
7139 | &error_info, insn_sequence) | |
7d02540a | 7140 | && !error_info.non_fatal) |
a06ea964 | 7141 | return TRUE; |
7d02540a TC |
7142 | |
7143 | gas_assert (error_info.kind != AARCH64_OPDE_NIL); | |
7144 | record_operand_error_info (opcode, &error_info); | |
7145 | return error_info.non_fatal; | |
a06ea964 NC |
7146 | } |
7147 | ||
7148 | #ifdef DEBUG_AARCH64 | |
7149 | static inline void | |
7150 | dump_opcode_operands (const aarch64_opcode *opcode) | |
7151 | { | |
7152 | int i = 0; | |
7153 | while (opcode->operands[i] != AARCH64_OPND_NIL) | |
7154 | { | |
7155 | aarch64_verbose ("\t\t opnd%d: %s", i, | |
7156 | aarch64_get_operand_name (opcode->operands[i])[0] != '\0' | |
7157 | ? aarch64_get_operand_name (opcode->operands[i]) | |
7158 | : aarch64_get_operand_desc (opcode->operands[i])); | |
7159 | ++i; | |
7160 | } | |
7161 | } | |
7162 | #endif /* DEBUG_AARCH64 */ | |
7163 | ||
7164 | /* This is the guts of the machine-dependent assembler. STR points to a | |
7165 | machine dependent instruction. This function is supposed to emit | |
7166 | the frags/bytes it assembles to. */ | |
7167 | ||
7168 | void | |
7169 | md_assemble (char *str) | |
7170 | { | |
7171 | char *p = str; | |
7172 | templates *template; | |
7173 | aarch64_opcode *opcode; | |
7174 | aarch64_inst *inst_base; | |
7175 | unsigned saved_cond; | |
7176 | ||
7177 | /* Align the previous label if needed. */ | |
7178 | if (last_label_seen != NULL) | |
7179 | { | |
7180 | symbol_set_frag (last_label_seen, frag_now); | |
7181 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
7182 | S_SET_SEGMENT (last_label_seen, now_seg); | |
7183 | } | |
7184 | ||
7e84b55d TC |
7185 | /* Update the current insn_sequence from the segment. */ |
7186 | insn_sequence = &seg_info (now_seg)->tc_segment_info_data.insn_sequence; | |
7187 | ||
a06ea964 NC |
7188 | inst.reloc.type = BFD_RELOC_UNUSED; |
7189 | ||
7190 | DEBUG_TRACE ("\n\n"); | |
7191 | DEBUG_TRACE ("=============================="); | |
7192 | DEBUG_TRACE ("Enter md_assemble with %s", str); | |
7193 | ||
7194 | template = opcode_lookup (&p); | |
7195 | if (!template) | |
7196 | { | |
7197 | /* It wasn't an instruction, but it might be a register alias of | |
7198 | the form alias .req reg directive. */ | |
7199 | if (!create_register_alias (str, p)) | |
7200 | as_bad (_("unknown mnemonic `%s' -- `%s'"), get_mnemonic_name (str), | |
7201 | str); | |
7202 | return; | |
7203 | } | |
7204 | ||
7205 | skip_whitespace (p); | |
7206 | if (*p == ',') | |
7207 | { | |
7208 | as_bad (_("unexpected comma after the mnemonic name `%s' -- `%s'"), | |
7209 | get_mnemonic_name (str), str); | |
7210 | return; | |
7211 | } | |
7212 | ||
7213 | init_operand_error_report (); | |
7214 | ||
eb9d6cc9 RL |
7215 | /* Sections are assumed to start aligned. In executable section, there is no |
7216 | MAP_DATA symbol pending. So we only align the address during | |
3979cf50 | 7217 | MAP_DATA --> MAP_CUR_INSN transition. |
eb9d6cc9 RL |
7218 | For other sections, this is not guaranteed. */ |
7219 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; | |
7220 | if (!need_pass_2 && subseg_text_p (now_seg) && mapstate == MAP_DATA) | |
7221 | frag_align_code (2, 0); | |
7222 | ||
a06ea964 NC |
7223 | saved_cond = inst.cond; |
7224 | reset_aarch64_instruction (&inst); | |
7225 | inst.cond = saved_cond; | |
7226 | ||
7227 | /* Iterate through all opcode entries with the same mnemonic name. */ | |
7228 | do | |
7229 | { | |
7230 | opcode = template->opcode; | |
7231 | ||
7232 | DEBUG_TRACE ("opcode %s found", opcode->name); | |
7233 | #ifdef DEBUG_AARCH64 | |
7234 | if (debug_dump) | |
7235 | dump_opcode_operands (opcode); | |
7236 | #endif /* DEBUG_AARCH64 */ | |
7237 | ||
3979cf50 | 7238 | mapping_state (MAP_CUR_INSN); |
a06ea964 NC |
7239 | |
7240 | inst_base = &inst.base; | |
7241 | inst_base->opcode = opcode; | |
7242 | ||
7243 | /* Truly conditionally executed instructions, e.g. b.cond. */ | |
7244 | if (opcode->flags & F_COND) | |
7245 | { | |
7246 | gas_assert (inst.cond != COND_ALWAYS); | |
7247 | inst_base->cond = get_cond_from_value (inst.cond); | |
7248 | DEBUG_TRACE ("condition found %s", inst_base->cond->names[0]); | |
7249 | } | |
7250 | else if (inst.cond != COND_ALWAYS) | |
7251 | { | |
7252 | /* It shouldn't arrive here, where the assembly looks like a | |
7253 | conditional instruction but the found opcode is unconditional. */ | |
7254 | gas_assert (0); | |
7255 | continue; | |
7256 | } | |
7257 | ||
7258 | if (parse_operands (p, opcode) | |
7259 | && programmer_friendly_fixup (&inst) | |
7260 | && do_encode (inst_base->opcode, &inst.base, &inst_base->value)) | |
7261 | { | |
3f06bfce YZ |
7262 | /* Check that this instruction is supported for this CPU. */ |
7263 | if (!opcode->avariant | |
93d8990c | 7264 | || !AARCH64_CPU_HAS_ALL_FEATURES (cpu_variant, *opcode->avariant)) |
3f06bfce YZ |
7265 | { |
7266 | as_bad (_("selected processor does not support `%s'"), str); | |
7267 | return; | |
7268 | } | |
7269 | ||
54a28c4c JW |
7270 | warn_unpredictable_ldst (&inst, str); |
7271 | ||
a06ea964 NC |
7272 | if (inst.reloc.type == BFD_RELOC_UNUSED |
7273 | || !inst.reloc.need_libopcodes_p) | |
7274 | output_inst (NULL); | |
7275 | else | |
7276 | { | |
7277 | /* If there is relocation generated for the instruction, | |
7278 | store the instruction information for the future fix-up. */ | |
7279 | struct aarch64_inst *copy; | |
7280 | gas_assert (inst.reloc.type != BFD_RELOC_UNUSED); | |
325801bd | 7281 | copy = XNEW (struct aarch64_inst); |
a06ea964 NC |
7282 | memcpy (copy, &inst.base, sizeof (struct aarch64_inst)); |
7283 | output_inst (copy); | |
7284 | } | |
7d02540a TC |
7285 | |
7286 | /* Issue non-fatal messages if any. */ | |
7287 | output_operand_error_report (str, TRUE); | |
a06ea964 NC |
7288 | return; |
7289 | } | |
7290 | ||
7291 | template = template->next; | |
7292 | if (template != NULL) | |
7293 | { | |
7294 | reset_aarch64_instruction (&inst); | |
7295 | inst.cond = saved_cond; | |
7296 | } | |
7297 | } | |
7298 | while (template != NULL); | |
7299 | ||
7300 | /* Issue the error messages if any. */ | |
7d02540a | 7301 | output_operand_error_report (str, FALSE); |
a06ea964 NC |
7302 | } |
7303 | ||
7304 | /* Various frobbings of labels and their addresses. */ | |
7305 | ||
7306 | void | |
7307 | aarch64_start_line_hook (void) | |
7308 | { | |
7309 | last_label_seen = NULL; | |
7310 | } | |
7311 | ||
7312 | void | |
7313 | aarch64_frob_label (symbolS * sym) | |
7314 | { | |
7315 | last_label_seen = sym; | |
7316 | ||
8b21361b SP |
7317 | AARCH64_SET_C64 (sym, IS_C64); |
7318 | ||
a06ea964 NC |
7319 | dwarf2_emit_label (sym); |
7320 | } | |
7321 | ||
4f5d2536 TC |
7322 | void |
7323 | aarch64_frob_section (asection *sec ATTRIBUTE_UNUSED) | |
7324 | { | |
7325 | /* Check to see if we have a block to close. */ | |
7326 | force_automatic_sequence_close (); | |
7327 | } | |
7328 | ||
a06ea964 NC |
7329 | int |
7330 | aarch64_data_in_code (void) | |
7331 | { | |
7332 | if (!strncmp (input_line_pointer + 1, "data:", 5)) | |
7333 | { | |
7334 | *input_line_pointer = '/'; | |
7335 | input_line_pointer += 5; | |
7336 | *input_line_pointer = 0; | |
7337 | return 1; | |
7338 | } | |
7339 | ||
7340 | return 0; | |
7341 | } | |
7342 | ||
7343 | char * | |
7344 | aarch64_canonicalize_symbol_name (char *name) | |
7345 | { | |
7346 | int len; | |
7347 | ||
7348 | if ((len = strlen (name)) > 5 && streq (name + len - 5, "/data")) | |
7349 | *(name + len - 5) = 0; | |
7350 | ||
7351 | return name; | |
7352 | } | |
7353 | \f | |
7354 | /* Table of all register names defined by default. The user can | |
7355 | define additional names with .req. Note that all register names | |
7356 | should appear in both upper and lowercase variants. Some registers | |
7357 | also have mixed-case names. */ | |
7358 | ||
7359 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE } | |
8975f864 | 7360 | #define REGDEF_ALIAS(s, n, t) { #s, n, REG_TYPE_##t, FALSE} |
a06ea964 | 7361 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
f11ad6bc | 7362 | #define REGSET16(p,t) \ |
a06ea964 NC |
7363 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ |
7364 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
7365 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
f11ad6bc RS |
7366 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) |
7367 | #define REGSET31(p,t) \ | |
7368 | REGSET16(p, t), \ | |
a06ea964 NC |
7369 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ |
7370 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
7371 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
7372 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t) | |
7373 | #define REGSET(p,t) \ | |
7374 | REGSET31(p,t), REGNUM(p,31,t) | |
7375 | ||
7376 | /* These go into aarch64_reg_hsh hash-table. */ | |
7377 | static const reg_entry reg_names[] = { | |
7378 | /* Integer registers. */ | |
7379 | REGSET31 (x, R_64), REGSET31 (X, R_64), | |
7380 | REGSET31 (w, R_32), REGSET31 (W, R_32), | |
7381 | ||
8975f864 | 7382 | REGDEF_ALIAS (ip0, 16, R_64), REGDEF_ALIAS (IP0, 16, R_64), |
f10e937a | 7383 | REGDEF_ALIAS (ip1, 17, R_64), REGDEF_ALIAS (IP1, 17, R_64), |
8975f864 RR |
7384 | REGDEF_ALIAS (fp, 29, R_64), REGDEF_ALIAS (FP, 29, R_64), |
7385 | REGDEF_ALIAS (lr, 30, R_64), REGDEF_ALIAS (LR, 30, R_64), | |
a06ea964 NC |
7386 | REGDEF (wsp, 31, SP_32), REGDEF (WSP, 31, SP_32), |
7387 | REGDEF (sp, 31, SP_64), REGDEF (SP, 31, SP_64), | |
7388 | ||
7389 | REGDEF (wzr, 31, Z_32), REGDEF (WZR, 31, Z_32), | |
7390 | REGDEF (xzr, 31, Z_64), REGDEF (XZR, 31, Z_64), | |
7391 | ||
3493da5c SP |
7392 | /* Capability Registers. */ |
7393 | REGSET31 (c, CA_N), REGSET31 (C, CA_N), | |
7394 | REGDEF (csp, 31, CA_SP), REGDEF (CSP, 31, CA_SP), | |
7395 | REGDEF (czr, 31, CA_Z), REGDEF (CZR, 31, CA_Z), | |
7396 | REGDEF (ddc, 33, CA_D), REGDEF (DDC, 33, CA_D), | |
7397 | REGDEF_ALIAS (clr, 30, CA_N), REGDEF_ALIAS (CLR, 30, CA_N), | |
7398 | ||
a06ea964 NC |
7399 | /* Floating-point single precision registers. */ |
7400 | REGSET (s, FP_S), REGSET (S, FP_S), | |
7401 | ||
7402 | /* Floating-point double precision registers. */ | |
7403 | REGSET (d, FP_D), REGSET (D, FP_D), | |
7404 | ||
7405 | /* Floating-point half precision registers. */ | |
7406 | REGSET (h, FP_H), REGSET (H, FP_H), | |
7407 | ||
7408 | /* Floating-point byte precision registers. */ | |
7409 | REGSET (b, FP_B), REGSET (B, FP_B), | |
7410 | ||
7411 | /* Floating-point quad precision registers. */ | |
7412 | REGSET (q, FP_Q), REGSET (Q, FP_Q), | |
7413 | ||
7414 | /* FP/SIMD registers. */ | |
7415 | REGSET (v, VN), REGSET (V, VN), | |
f11ad6bc RS |
7416 | |
7417 | /* SVE vector registers. */ | |
7418 | REGSET (z, ZN), REGSET (Z, ZN), | |
7419 | ||
7420 | /* SVE predicate registers. */ | |
7421 | REGSET16 (p, PN), REGSET16 (P, PN) | |
a06ea964 NC |
7422 | }; |
7423 | ||
7424 | #undef REGDEF | |
8975f864 | 7425 | #undef REGDEF_ALIAS |
a06ea964 | 7426 | #undef REGNUM |
f11ad6bc RS |
7427 | #undef REGSET16 |
7428 | #undef REGSET31 | |
a06ea964 NC |
7429 | #undef REGSET |
7430 | ||
7431 | #define N 1 | |
7432 | #define n 0 | |
7433 | #define Z 1 | |
7434 | #define z 0 | |
7435 | #define C 1 | |
7436 | #define c 0 | |
7437 | #define V 1 | |
7438 | #define v 0 | |
7439 | #define B(a,b,c,d) (((a) << 3) | ((b) << 2) | ((c) << 1) | (d)) | |
7440 | static const asm_nzcv nzcv_names[] = { | |
7441 | {"nzcv", B (n, z, c, v)}, | |
7442 | {"nzcV", B (n, z, c, V)}, | |
7443 | {"nzCv", B (n, z, C, v)}, | |
7444 | {"nzCV", B (n, z, C, V)}, | |
7445 | {"nZcv", B (n, Z, c, v)}, | |
7446 | {"nZcV", B (n, Z, c, V)}, | |
7447 | {"nZCv", B (n, Z, C, v)}, | |
7448 | {"nZCV", B (n, Z, C, V)}, | |
7449 | {"Nzcv", B (N, z, c, v)}, | |
7450 | {"NzcV", B (N, z, c, V)}, | |
7451 | {"NzCv", B (N, z, C, v)}, | |
7452 | {"NzCV", B (N, z, C, V)}, | |
7453 | {"NZcv", B (N, Z, c, v)}, | |
7454 | {"NZcV", B (N, Z, c, V)}, | |
7455 | {"NZCv", B (N, Z, C, v)}, | |
7456 | {"NZCV", B (N, Z, C, V)} | |
7457 | }; | |
7458 | ||
7459 | #undef N | |
7460 | #undef n | |
7461 | #undef Z | |
7462 | #undef z | |
7463 | #undef C | |
7464 | #undef c | |
7465 | #undef V | |
7466 | #undef v | |
7467 | #undef B | |
7468 | \f | |
7469 | /* MD interface: bits in the object file. */ | |
7470 | ||
7471 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate | |
7472 | for use in the a.out file, and stores them in the array pointed to by buf. | |
7473 | This knows about the endian-ness of the target machine and does | |
7474 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
7475 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
7476 | LITTLENUMS (shorts, here at least). */ | |
7477 | ||
7478 | void | |
7479 | md_number_to_chars (char *buf, valueT val, int n) | |
7480 | { | |
7481 | if (target_big_endian) | |
7482 | number_to_chars_bigendian (buf, val, n); | |
7483 | else | |
7484 | number_to_chars_littleendian (buf, val, n); | |
7485 | } | |
7486 | ||
7487 | /* MD interface: Sections. */ | |
7488 | ||
7489 | /* Estimate the size of a frag before relaxing. Assume everything fits in | |
7490 | 4 bytes. */ | |
7491 | ||
7492 | int | |
7493 | md_estimate_size_before_relax (fragS * fragp, segT segtype ATTRIBUTE_UNUSED) | |
7494 | { | |
7495 | fragp->fr_var = 4; | |
7496 | return 4; | |
7497 | } | |
7498 | ||
7499 | /* Round up a section size to the appropriate boundary. */ | |
7500 | ||
7501 | valueT | |
7502 | md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size) | |
7503 | { | |
7504 | return size; | |
7505 | } | |
7506 | ||
7507 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents | |
f803aa8e DPT |
7508 | of an rs_align_code fragment. |
7509 | ||
7510 | Here we fill the frag with the appropriate info for padding the | |
7511 | output stream. The resulting frag will consist of a fixed (fr_fix) | |
7512 | and of a repeating (fr_var) part. | |
7513 | ||
7514 | The fixed content is always emitted before the repeating content and | |
7515 | these two parts are used as follows in constructing the output: | |
7516 | - the fixed part will be used to align to a valid instruction word | |
7517 | boundary, in case that we start at a misaligned address; as no | |
7518 | executable instruction can live at the misaligned location, we | |
7519 | simply fill with zeros; | |
7520 | - the variable part will be used to cover the remaining padding and | |
7521 | we fill using the AArch64 NOP instruction. | |
7522 | ||
7523 | Note that the size of a RS_ALIGN_CODE fragment is always 7 to provide | |
7524 | enough storage space for up to 3 bytes for padding the back to a valid | |
7525 | instruction alignment and exactly 4 bytes to store the NOP pattern. */ | |
a06ea964 NC |
7526 | |
7527 | void | |
7528 | aarch64_handle_align (fragS * fragP) | |
7529 | { | |
7530 | /* NOP = d503201f */ | |
7531 | /* AArch64 instructions are always little-endian. */ | |
d9235011 | 7532 | static unsigned char const aarch64_noop[4] = { 0x1f, 0x20, 0x03, 0xd5 }; |
a06ea964 NC |
7533 | |
7534 | int bytes, fix, noop_size; | |
7535 | char *p; | |
a06ea964 NC |
7536 | |
7537 | if (fragP->fr_type != rs_align_code) | |
7538 | return; | |
7539 | ||
7540 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; | |
7541 | p = fragP->fr_literal + fragP->fr_fix; | |
a06ea964 NC |
7542 | |
7543 | #ifdef OBJ_ELF | |
7544 | gas_assert (fragP->tc_frag_data.recorded); | |
7545 | #endif | |
7546 | ||
a06ea964 | 7547 | noop_size = sizeof (aarch64_noop); |
a06ea964 | 7548 | |
f803aa8e DPT |
7549 | fix = bytes & (noop_size - 1); |
7550 | if (fix) | |
a06ea964 | 7551 | { |
a06ea964 | 7552 | #ifdef OBJ_ELF |
3979cf50 | 7553 | insert_data_mapping_symbol (MAP_CUR_INSN, fragP->fr_fix, fragP, fix); |
a06ea964 NC |
7554 | #endif |
7555 | memset (p, 0, fix); | |
7556 | p += fix; | |
f803aa8e | 7557 | fragP->fr_fix += fix; |
a06ea964 NC |
7558 | } |
7559 | ||
f803aa8e DPT |
7560 | if (noop_size) |
7561 | memcpy (p, aarch64_noop, noop_size); | |
7562 | fragP->fr_var = noop_size; | |
a06ea964 NC |
7563 | } |
7564 | ||
7565 | /* Perform target specific initialisation of a frag. | |
7566 | Note - despite the name this initialisation is not done when the frag | |
7567 | is created, but only when its type is assigned. A frag can be created | |
7568 | and used a long time before its type is set, so beware of assuming that | |
33eaf5de | 7569 | this initialisation is performed first. */ |
a06ea964 NC |
7570 | |
7571 | #ifndef OBJ_ELF | |
7572 | void | |
7573 | aarch64_init_frag (fragS * fragP ATTRIBUTE_UNUSED, | |
7574 | int max_chars ATTRIBUTE_UNUSED) | |
7575 | { | |
7576 | } | |
7577 | ||
7578 | #else /* OBJ_ELF is defined. */ | |
7579 | void | |
7580 | aarch64_init_frag (fragS * fragP, int max_chars) | |
7581 | { | |
7582 | /* Record a mapping symbol for alignment frags. We will delete this | |
7583 | later if the alignment ends up empty. */ | |
7584 | if (!fragP->tc_frag_data.recorded) | |
c7ad08e6 RL |
7585 | fragP->tc_frag_data.recorded = 1; |
7586 | ||
e8d84ca1 NC |
7587 | /* PR 21809: Do not set a mapping state for debug sections |
7588 | - it just confuses other tools. */ | |
fd361982 | 7589 | if (bfd_section_flags (now_seg) & SEC_DEBUGGING) |
e8d84ca1 NC |
7590 | return; |
7591 | ||
c7ad08e6 | 7592 | switch (fragP->fr_type) |
a06ea964 | 7593 | { |
c7ad08e6 RL |
7594 | case rs_align_test: |
7595 | case rs_fill: | |
7596 | mapping_state_2 (MAP_DATA, max_chars); | |
7597 | break; | |
7ea12e5c NC |
7598 | case rs_align: |
7599 | /* PR 20364: We can get alignment frags in code sections, | |
7600 | so do not just assume that we should use the MAP_DATA state. */ | |
3979cf50 | 7601 | mapping_state_2 (subseg_text_p (now_seg) ? MAP_CUR_INSN : MAP_DATA, max_chars); |
7ea12e5c | 7602 | break; |
c7ad08e6 | 7603 | case rs_align_code: |
3979cf50 | 7604 | mapping_state_2 (MAP_CUR_INSN, max_chars); |
c7ad08e6 RL |
7605 | break; |
7606 | default: | |
7607 | break; | |
a06ea964 NC |
7608 | } |
7609 | } | |
7610 | \f | |
7611 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
7612 | ||
7613 | void | |
7614 | tc_aarch64_frame_initial_instructions (void) | |
7615 | { | |
7616 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
7617 | } | |
7618 | #endif /* OBJ_ELF */ | |
7619 | ||
7620 | /* Convert REGNAME to a DWARF-2 register number. */ | |
7621 | ||
7622 | int | |
7623 | tc_aarch64_regname_to_dw2regnum (char *regname) | |
7624 | { | |
7625 | const reg_entry *reg = parse_reg (®name); | |
7626 | if (reg == NULL) | |
7627 | return -1; | |
7628 | ||
7629 | switch (reg->type) | |
7630 | { | |
7631 | case REG_TYPE_SP_32: | |
7632 | case REG_TYPE_SP_64: | |
7633 | case REG_TYPE_R_32: | |
7634 | case REG_TYPE_R_64: | |
a2cac51c RH |
7635 | return reg->number; |
7636 | ||
a06ea964 NC |
7637 | case REG_TYPE_FP_B: |
7638 | case REG_TYPE_FP_H: | |
7639 | case REG_TYPE_FP_S: | |
7640 | case REG_TYPE_FP_D: | |
7641 | case REG_TYPE_FP_Q: | |
a2cac51c RH |
7642 | return reg->number + 64; |
7643 | ||
a06ea964 NC |
7644 | default: |
7645 | break; | |
7646 | } | |
7647 | return -1; | |
7648 | } | |
7649 | ||
cec5225b YZ |
7650 | /* Implement DWARF2_ADDR_SIZE. */ |
7651 | ||
7652 | int | |
7653 | aarch64_dwarf2_addr_size (void) | |
7654 | { | |
7655 | #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) | |
7656 | if (ilp32_p) | |
7657 | return 4; | |
7658 | #endif | |
7659 | return bfd_arch_bits_per_address (stdoutput) / 8; | |
7660 | } | |
7661 | ||
a06ea964 NC |
7662 | /* MD interface: Symbol and relocation handling. */ |
7663 | ||
7664 | /* Return the address within the segment that a PC-relative fixup is | |
7665 | relative to. For AArch64 PC-relative fixups applied to instructions | |
7666 | are generally relative to the location plus AARCH64_PCREL_OFFSET bytes. */ | |
7667 | ||
7668 | long | |
7669 | md_pcrel_from_section (fixS * fixP, segT seg) | |
7670 | { | |
7671 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; | |
7672 | ||
7673 | /* If this is pc-relative and we are going to emit a relocation | |
7674 | then we just want to put out any pipeline compensation that the linker | |
7675 | will need. Otherwise we want to use the calculated base. */ | |
7676 | if (fixP->fx_pcrel | |
7677 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
7678 | || aarch64_force_relocation (fixP))) | |
7679 | base = 0; | |
7680 | ||
7681 | /* AArch64 should be consistent for all pc-relative relocations. */ | |
7682 | return base + AARCH64_PCREL_OFFSET; | |
7683 | } | |
7684 | ||
7685 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. | |
7686 | Otherwise we have no need to default values of symbols. */ | |
7687 | ||
7688 | symbolS * | |
7689 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) | |
7690 | { | |
7691 | #ifdef OBJ_ELF | |
7692 | if (name[0] == '_' && name[1] == 'G' | |
7693 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
7694 | { | |
7695 | if (!GOT_symbol) | |
7696 | { | |
7697 | if (symbol_find (name)) | |
7698 | as_bad (_("GOT already in the symbol table")); | |
7699 | ||
7700 | GOT_symbol = symbol_new (name, undefined_section, | |
e01e1cee | 7701 | &zero_address_frag, 0); |
a06ea964 NC |
7702 | } |
7703 | ||
7704 | return GOT_symbol; | |
7705 | } | |
7706 | #endif | |
7707 | ||
7708 | return 0; | |
7709 | } | |
7710 | ||
7711 | /* Return non-zero if the indicated VALUE has overflowed the maximum | |
7712 | range expressible by a unsigned number with the indicated number of | |
7713 | BITS. */ | |
7714 | ||
7715 | static bfd_boolean | |
7716 | unsigned_overflow (valueT value, unsigned bits) | |
7717 | { | |
7718 | valueT lim; | |
7719 | if (bits >= sizeof (valueT) * 8) | |
7720 | return FALSE; | |
7721 | lim = (valueT) 1 << bits; | |
7722 | return (value >= lim); | |
7723 | } | |
7724 | ||
7725 | ||
7726 | /* Return non-zero if the indicated VALUE has overflowed the maximum | |
7727 | range expressible by an signed number with the indicated number of | |
7728 | BITS. */ | |
7729 | ||
7730 | static bfd_boolean | |
7731 | signed_overflow (offsetT value, unsigned bits) | |
7732 | { | |
7733 | offsetT lim; | |
7734 | if (bits >= sizeof (offsetT) * 8) | |
7735 | return FALSE; | |
7736 | lim = (offsetT) 1 << (bits - 1); | |
7737 | return (value < -lim || value >= lim); | |
7738 | } | |
7739 | ||
7740 | /* Given an instruction in *INST, which is expected to be a scaled, 12-bit, | |
7741 | unsigned immediate offset load/store instruction, try to encode it as | |
7742 | an unscaled, 9-bit, signed immediate offset load/store instruction. | |
7743 | Return TRUE if it is successful; otherwise return FALSE. | |
7744 | ||
7745 | As a programmer-friendly assembler, LDUR/STUR instructions can be generated | |
7746 | in response to the standard LDR/STR mnemonics when the immediate offset is | |
7747 | unambiguous, i.e. when it is negative or unaligned. */ | |
7748 | ||
7749 | static bfd_boolean | |
7750 | try_to_encode_as_unscaled_ldst (aarch64_inst *instr) | |
7751 | { | |
7752 | int idx; | |
7753 | enum aarch64_op new_op; | |
7754 | const aarch64_opcode *new_opcode; | |
7755 | ||
7756 | gas_assert (instr->opcode->iclass == ldst_pos); | |
7757 | ||
7758 | switch (instr->opcode->op) | |
7759 | { | |
7760 | case OP_LDRB_POS:new_op = OP_LDURB; break; | |
7761 | case OP_STRB_POS: new_op = OP_STURB; break; | |
7762 | case OP_LDRSB_POS: new_op = OP_LDURSB; break; | |
7763 | case OP_LDRH_POS: new_op = OP_LDURH; break; | |
7764 | case OP_STRH_POS: new_op = OP_STURH; break; | |
7765 | case OP_LDRSH_POS: new_op = OP_LDURSH; break; | |
7766 | case OP_LDR_POS: new_op = OP_LDUR; break; | |
7767 | case OP_STR_POS: new_op = OP_STUR; break; | |
7768 | case OP_LDRF_POS: new_op = OP_LDURV; break; | |
7769 | case OP_STRF_POS: new_op = OP_STURV; break; | |
7770 | case OP_LDRSW_POS: new_op = OP_LDURSW; break; | |
7771 | case OP_PRFM_POS: new_op = OP_PRFUM; break; | |
7772 | default: new_op = OP_NIL; break; | |
7773 | } | |
7774 | ||
7775 | if (new_op == OP_NIL) | |
7776 | return FALSE; | |
7777 | ||
7778 | new_opcode = aarch64_get_opcode (new_op); | |
7779 | gas_assert (new_opcode != NULL); | |
7780 | ||
7781 | DEBUG_TRACE ("Check programmer-friendly STURB/LDURB -> STRB/LDRB: %d == %d", | |
7782 | instr->opcode->op, new_opcode->op); | |
7783 | ||
7784 | aarch64_replace_opcode (instr, new_opcode); | |
7785 | ||
7786 | /* Clear up the ADDR_SIMM9's qualifier; otherwise the | |
7787 | qualifier matching may fail because the out-of-date qualifier will | |
7788 | prevent the operand being updated with a new and correct qualifier. */ | |
7789 | idx = aarch64_operand_index (instr->opcode->operands, | |
7790 | AARCH64_OPND_ADDR_SIMM9); | |
7791 | gas_assert (idx == 1); | |
7792 | instr->operands[idx].qualifier = AARCH64_OPND_QLF_NIL; | |
7793 | ||
7794 | DEBUG_TRACE ("Found LDURB entry to encode programmer-friendly LDRB"); | |
7795 | ||
3979cf50 SP |
7796 | if (!aarch64_opcode_encode (cpu_variant, instr->opcode, instr, &instr->value, |
7797 | NULL, NULL, insn_sequence)) | |
a06ea964 NC |
7798 | return FALSE; |
7799 | ||
7800 | return TRUE; | |
7801 | } | |
7802 | ||
7803 | /* Called by fix_insn to fix a MOV immediate alias instruction. | |
7804 | ||
7805 | Operand for a generic move immediate instruction, which is an alias | |
7806 | instruction that generates a single MOVZ, MOVN or ORR instruction to loads | |
7807 | a 32-bit/64-bit immediate value into general register. An assembler error | |
7808 | shall result if the immediate cannot be created by a single one of these | |
7809 | instructions. If there is a choice, then to ensure reversability an | |
7810 | assembler must prefer a MOVZ to MOVN, and MOVZ or MOVN to ORR. */ | |
7811 | ||
7812 | static void | |
7813 | fix_mov_imm_insn (fixS *fixP, char *buf, aarch64_inst *instr, offsetT value) | |
7814 | { | |
7815 | const aarch64_opcode *opcode; | |
7816 | ||
7817 | /* Need to check if the destination is SP/ZR. The check has to be done | |
7818 | before any aarch64_replace_opcode. */ | |
7819 | int try_mov_wide_p = !aarch64_stack_pointer_p (&instr->operands[0]); | |
7820 | int try_mov_bitmask_p = !aarch64_zero_register_p (&instr->operands[0]); | |
7821 | ||
7822 | instr->operands[1].imm.value = value; | |
7823 | instr->operands[1].skip = 0; | |
7824 | ||
7825 | if (try_mov_wide_p) | |
7826 | { | |
7827 | /* Try the MOVZ alias. */ | |
7828 | opcode = aarch64_get_opcode (OP_MOV_IMM_WIDE); | |
7829 | aarch64_replace_opcode (instr, opcode); | |
3979cf50 | 7830 | if (aarch64_opcode_encode (cpu_variant, instr->opcode, instr, |
7e84b55d | 7831 | &instr->value, NULL, NULL, insn_sequence)) |
a06ea964 NC |
7832 | { |
7833 | put_aarch64_insn (buf, instr->value); | |
7834 | return; | |
7835 | } | |
7836 | /* Try the MOVK alias. */ | |
7837 | opcode = aarch64_get_opcode (OP_MOV_IMM_WIDEN); | |
7838 | aarch64_replace_opcode (instr, opcode); | |
3979cf50 | 7839 | if (aarch64_opcode_encode (cpu_variant, instr->opcode, instr, |
7e84b55d | 7840 | &instr->value, NULL, NULL, insn_sequence)) |
a06ea964 NC |
7841 | { |
7842 | put_aarch64_insn (buf, instr->value); | |
7843 | return; | |
7844 | } | |
7845 | } | |
7846 | ||
7847 | if (try_mov_bitmask_p) | |
7848 | { | |
7849 | /* Try the ORR alias. */ | |
7850 | opcode = aarch64_get_opcode (OP_MOV_IMM_LOG); | |
7851 | aarch64_replace_opcode (instr, opcode); | |
3979cf50 | 7852 | if (aarch64_opcode_encode (cpu_variant, instr->opcode, instr, |
7e84b55d | 7853 | &instr->value, NULL, NULL, insn_sequence)) |
a06ea964 NC |
7854 | { |
7855 | put_aarch64_insn (buf, instr->value); | |
7856 | return; | |
7857 | } | |
7858 | } | |
7859 | ||
7860 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
7861 | _("immediate cannot be moved by a single instruction")); | |
7862 | } | |
7863 | ||
7864 | /* An instruction operand which is immediate related may have symbol used | |
7865 | in the assembly, e.g. | |
7866 | ||
7867 | mov w0, u32 | |
7868 | .set u32, 0x00ffff00 | |
7869 | ||
7870 | At the time when the assembly instruction is parsed, a referenced symbol, | |
7871 | like 'u32' in the above example may not have been seen; a fixS is created | |
7872 | in such a case and is handled here after symbols have been resolved. | |
7873 | Instruction is fixed up with VALUE using the information in *FIXP plus | |
7874 | extra information in FLAGS. | |
7875 | ||
7876 | This function is called by md_apply_fix to fix up instructions that need | |
7877 | a fix-up described above but does not involve any linker-time relocation. */ | |
7878 | ||
7879 | static void | |
7880 | fix_insn (fixS *fixP, uint32_t flags, offsetT value) | |
7881 | { | |
7882 | int idx; | |
7883 | uint32_t insn; | |
7884 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
7885 | enum aarch64_opnd opnd = fixP->tc_fix_data.opnd; | |
7886 | aarch64_inst *new_inst = fixP->tc_fix_data.inst; | |
7887 | ||
7888 | if (new_inst) | |
7889 | { | |
7890 | /* Now the instruction is about to be fixed-up, so the operand that | |
7891 | was previously marked as 'ignored' needs to be unmarked in order | |
7892 | to get the encoding done properly. */ | |
7893 | idx = aarch64_operand_index (new_inst->opcode->operands, opnd); | |
7894 | new_inst->operands[idx].skip = 0; | |
7895 | } | |
7896 | ||
7897 | gas_assert (opnd != AARCH64_OPND_NIL); | |
7898 | ||
7899 | switch (opnd) | |
7900 | { | |
7901 | case AARCH64_OPND_EXCEPTION: | |
09c1e68a | 7902 | case AARCH64_OPND_UNDEFINED: |
a06ea964 NC |
7903 | if (unsigned_overflow (value, 16)) |
7904 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
7905 | _("immediate out of range")); | |
7906 | insn = get_aarch64_insn (buf); | |
09c1e68a | 7907 | insn |= (opnd == AARCH64_OPND_EXCEPTION) ? encode_svc_imm (value) : value; |
a06ea964 NC |
7908 | put_aarch64_insn (buf, insn); |
7909 | break; | |
7910 | ||
7911 | case AARCH64_OPND_AIMM: | |
dc64c2ba | 7912 | case AARCH64_OPND_A64C_AIMM: |
a06ea964 NC |
7913 | /* ADD or SUB with immediate. |
7914 | NOTE this assumes we come here with a add/sub shifted reg encoding | |
7915 | 3 322|2222|2 2 2 21111 111111 | |
7916 | 1 098|7654|3 2 1 09876 543210 98765 43210 | |
7917 | 0b000000 sf 000|1011|shift 0 Rm imm6 Rn Rd ADD | |
7918 | 2b000000 sf 010|1011|shift 0 Rm imm6 Rn Rd ADDS | |
7919 | 4b000000 sf 100|1011|shift 0 Rm imm6 Rn Rd SUB | |
7920 | 6b000000 sf 110|1011|shift 0 Rm imm6 Rn Rd SUBS | |
7921 | -> | |
7922 | 3 322|2222|2 2 221111111111 | |
7923 | 1 098|7654|3 2 109876543210 98765 43210 | |
7924 | 11000000 sf 001|0001|shift imm12 Rn Rd ADD | |
7925 | 31000000 sf 011|0001|shift imm12 Rn Rd ADDS | |
7926 | 51000000 sf 101|0001|shift imm12 Rn Rd SUB | |
7927 | 71000000 sf 111|0001|shift imm12 Rn Rd SUBS | |
7928 | Fields sf Rn Rd are already set. */ | |
7929 | insn = get_aarch64_insn (buf); | |
7930 | if (value < 0) | |
7931 | { | |
7932 | /* Add <-> sub. */ | |
7933 | insn = reencode_addsub_switch_add_sub (insn); | |
7934 | value = -value; | |
7935 | } | |
7936 | ||
7937 | if ((flags & FIXUP_F_HAS_EXPLICIT_SHIFT) == 0 | |
7938 | && unsigned_overflow (value, 12)) | |
7939 | { | |
7940 | /* Try to shift the value by 12 to make it fit. */ | |
7941 | if (((value >> 12) << 12) == value | |
7942 | && ! unsigned_overflow (value, 12 + 12)) | |
7943 | { | |
7944 | value >>= 12; | |
7945 | insn |= encode_addsub_imm_shift_amount (1); | |
7946 | } | |
7947 | } | |
7948 | ||
7949 | if (unsigned_overflow (value, 12)) | |
7950 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
7951 | _("immediate out of range")); | |
7952 | ||
7953 | insn |= encode_addsub_imm (value); | |
7954 | ||
7955 | put_aarch64_insn (buf, insn); | |
7956 | break; | |
7957 | ||
7958 | case AARCH64_OPND_SIMD_IMM: | |
7959 | case AARCH64_OPND_SIMD_IMM_SFT: | |
7960 | case AARCH64_OPND_LIMM: | |
7961 | /* Bit mask immediate. */ | |
7962 | gas_assert (new_inst != NULL); | |
7963 | idx = aarch64_operand_index (new_inst->opcode->operands, opnd); | |
7964 | new_inst->operands[idx].imm.value = value; | |
3979cf50 | 7965 | if (aarch64_opcode_encode (cpu_variant, new_inst->opcode, new_inst, |
7e84b55d | 7966 | &new_inst->value, NULL, NULL, insn_sequence)) |
a06ea964 NC |
7967 | put_aarch64_insn (buf, new_inst->value); |
7968 | else | |
7969 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
7970 | _("invalid immediate")); | |
7971 | break; | |
7972 | ||
7973 | case AARCH64_OPND_HALF: | |
7974 | /* 16-bit unsigned immediate. */ | |
7975 | if (unsigned_overflow (value, 16)) | |
7976 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
7977 | _("immediate out of range")); | |
7978 | insn = get_aarch64_insn (buf); | |
7979 | insn |= encode_movw_imm (value & 0xffff); | |
7980 | put_aarch64_insn (buf, insn); | |
7981 | break; | |
7982 | ||
7983 | case AARCH64_OPND_IMM_MOV: | |
7984 | /* Operand for a generic move immediate instruction, which is | |
7985 | an alias instruction that generates a single MOVZ, MOVN or ORR | |
7986 | instruction to loads a 32-bit/64-bit immediate value into general | |
7987 | register. An assembler error shall result if the immediate cannot be | |
7988 | created by a single one of these instructions. If there is a choice, | |
7989 | then to ensure reversability an assembler must prefer a MOVZ to MOVN, | |
7990 | and MOVZ or MOVN to ORR. */ | |
7991 | gas_assert (new_inst != NULL); | |
7992 | fix_mov_imm_insn (fixP, buf, new_inst, value); | |
7993 | break; | |
7994 | ||
7995 | case AARCH64_OPND_ADDR_SIMM7: | |
7996 | case AARCH64_OPND_ADDR_SIMM9: | |
7997 | case AARCH64_OPND_ADDR_SIMM9_2: | |
3f06e550 | 7998 | case AARCH64_OPND_ADDR_SIMM10: |
a06ea964 | 7999 | case AARCH64_OPND_ADDR_UIMM12: |
fb3265b3 SD |
8000 | case AARCH64_OPND_ADDR_SIMM11: |
8001 | case AARCH64_OPND_ADDR_SIMM13: | |
a06ea964 NC |
8002 | /* Immediate offset in an address. */ |
8003 | insn = get_aarch64_insn (buf); | |
8004 | ||
8005 | gas_assert (new_inst != NULL && new_inst->value == insn); | |
8006 | gas_assert (new_inst->opcode->operands[1] == opnd | |
8007 | || new_inst->opcode->operands[2] == opnd); | |
8008 | ||
8009 | /* Get the index of the address operand. */ | |
8010 | if (new_inst->opcode->operands[1] == opnd) | |
8011 | /* e.g. STR <Xt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */ | |
8012 | idx = 1; | |
8013 | else | |
8014 | /* e.g. LDP <Qt1>, <Qt2>, [<Xn|SP>{, #<imm>}]. */ | |
8015 | idx = 2; | |
8016 | ||
8017 | /* Update the resolved offset value. */ | |
8018 | new_inst->operands[idx].addr.offset.imm = value; | |
8019 | ||
8020 | /* Encode/fix-up. */ | |
3979cf50 | 8021 | if (aarch64_opcode_encode (cpu_variant, new_inst->opcode, new_inst, |
7e84b55d | 8022 | &new_inst->value, NULL, NULL, insn_sequence)) |
a06ea964 NC |
8023 | { |
8024 | put_aarch64_insn (buf, new_inst->value); | |
8025 | break; | |
8026 | } | |
8027 | else if (new_inst->opcode->iclass == ldst_pos | |
8028 | && try_to_encode_as_unscaled_ldst (new_inst)) | |
8029 | { | |
8030 | put_aarch64_insn (buf, new_inst->value); | |
8031 | break; | |
8032 | } | |
8033 | ||
8034 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8035 | _("immediate offset out of range")); | |
8036 | break; | |
8037 | ||
8038 | default: | |
8039 | gas_assert (0); | |
8040 | as_fatal (_("unhandled operand code %d"), opnd); | |
8041 | } | |
8042 | } | |
8043 | ||
8044 | /* Apply a fixup (fixP) to segment data, once it has been determined | |
8045 | by our caller that we have all the info we need to fix it up. | |
8046 | ||
8047 | Parameter valP is the pointer to the value of the bits. */ | |
8048 | ||
8049 | void | |
8050 | md_apply_fix (fixS * fixP, valueT * valP, segT seg) | |
8051 | { | |
8052 | offsetT value = *valP; | |
8053 | uint32_t insn; | |
8054 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
8055 | int scale; | |
8056 | unsigned flags = fixP->fx_addnumber; | |
8057 | ||
8058 | DEBUG_TRACE ("\n\n"); | |
8059 | DEBUG_TRACE ("~~~~~~~~~~~~~~~~~~~~~~~~~"); | |
8060 | DEBUG_TRACE ("Enter md_apply_fix"); | |
8061 | ||
8062 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); | |
8063 | ||
8064 | /* Note whether this will delete the relocation. */ | |
8065 | ||
8066 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) | |
8067 | fixP->fx_done = 1; | |
8068 | ||
8069 | /* Process the relocations. */ | |
8070 | switch (fixP->fx_r_type) | |
8071 | { | |
8072 | case BFD_RELOC_NONE: | |
8073 | /* This will need to go in the object file. */ | |
8074 | fixP->fx_done = 0; | |
8075 | break; | |
8076 | ||
8077 | case BFD_RELOC_8: | |
8078 | case BFD_RELOC_8_PCREL: | |
8079 | if (fixP->fx_done || !seg->use_rela_p) | |
8080 | md_number_to_chars (buf, value, 1); | |
8081 | break; | |
8082 | ||
8083 | case BFD_RELOC_16: | |
8084 | case BFD_RELOC_16_PCREL: | |
8085 | if (fixP->fx_done || !seg->use_rela_p) | |
8086 | md_number_to_chars (buf, value, 2); | |
8087 | break; | |
8088 | ||
8089 | case BFD_RELOC_32: | |
8090 | case BFD_RELOC_32_PCREL: | |
8091 | if (fixP->fx_done || !seg->use_rela_p) | |
8092 | md_number_to_chars (buf, value, 4); | |
8093 | break; | |
8094 | ||
8095 | case BFD_RELOC_64: | |
8096 | case BFD_RELOC_64_PCREL: | |
8097 | if (fixP->fx_done || !seg->use_rela_p) | |
8098 | md_number_to_chars (buf, value, 8); | |
8099 | break; | |
8100 | ||
8101 | case BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP: | |
8102 | /* We claim that these fixups have been processed here, even if | |
8103 | in fact we generate an error because we do not have a reloc | |
8104 | for them, so tc_gen_reloc() will reject them. */ | |
8105 | fixP->fx_done = 1; | |
8106 | if (fixP->fx_addsy && !S_IS_DEFINED (fixP->fx_addsy)) | |
8107 | { | |
8108 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8109 | _("undefined symbol %s used as an immediate value"), | |
8110 | S_GET_NAME (fixP->fx_addsy)); | |
8111 | goto apply_fix_return; | |
8112 | } | |
8113 | fix_insn (fixP, flags, value); | |
8114 | break; | |
8115 | ||
8116 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: | |
a06ea964 NC |
8117 | if (fixP->fx_done || !seg->use_rela_p) |
8118 | { | |
89d2a2a3 MS |
8119 | if (value & 3) |
8120 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8121 | _("pc-relative load offset not word aligned")); | |
8122 | if (signed_overflow (value, 21)) | |
8123 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8124 | _("pc-relative load offset out of range")); | |
a06ea964 NC |
8125 | insn = get_aarch64_insn (buf); |
8126 | insn |= encode_ld_lit_ofs_19 (value >> 2); | |
8127 | put_aarch64_insn (buf, insn); | |
8128 | } | |
8129 | break; | |
8130 | ||
8131 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: | |
a06ea964 NC |
8132 | if (fixP->fx_done || !seg->use_rela_p) |
8133 | { | |
89d2a2a3 MS |
8134 | if (signed_overflow (value, 21)) |
8135 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8136 | _("pc-relative address offset out of range")); | |
a06ea964 NC |
8137 | insn = get_aarch64_insn (buf); |
8138 | insn |= encode_adr_imm (value); | |
8139 | put_aarch64_insn (buf, insn); | |
8140 | } | |
8141 | break; | |
8142 | ||
8143 | case BFD_RELOC_AARCH64_BRANCH19: | |
a06ea964 NC |
8144 | if (fixP->fx_done || !seg->use_rela_p) |
8145 | { | |
89d2a2a3 MS |
8146 | if (value & 3) |
8147 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8148 | _("conditional branch target not word aligned")); | |
8149 | if (signed_overflow (value, 21)) | |
8150 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8151 | _("conditional branch out of range")); | |
a06ea964 NC |
8152 | insn = get_aarch64_insn (buf); |
8153 | insn |= encode_cond_branch_ofs_19 (value >> 2); | |
8154 | put_aarch64_insn (buf, insn); | |
8155 | } | |
8156 | break; | |
8157 | ||
8158 | case BFD_RELOC_AARCH64_TSTBR14: | |
a06ea964 NC |
8159 | if (fixP->fx_done || !seg->use_rela_p) |
8160 | { | |
89d2a2a3 MS |
8161 | if (value & 3) |
8162 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8163 | _("conditional branch target not word aligned")); | |
8164 | if (signed_overflow (value, 16)) | |
8165 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8166 | _("conditional branch out of range")); | |
a06ea964 NC |
8167 | insn = get_aarch64_insn (buf); |
8168 | insn |= encode_tst_branch_ofs_14 (value >> 2); | |
8169 | put_aarch64_insn (buf, insn); | |
8170 | } | |
8171 | break; | |
8172 | ||
a06ea964 | 8173 | case BFD_RELOC_AARCH64_CALL26: |
f09c556a | 8174 | case BFD_RELOC_AARCH64_JUMP26: |
a06ea964 NC |
8175 | if (fixP->fx_done || !seg->use_rela_p) |
8176 | { | |
89d2a2a3 MS |
8177 | if (value & 3) |
8178 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8179 | _("branch target not word aligned")); | |
8180 | if (signed_overflow (value, 28)) | |
8181 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8182 | _("branch out of range")); | |
a06ea964 NC |
8183 | insn = get_aarch64_insn (buf); |
8184 | insn |= encode_branch_ofs_26 (value >> 2); | |
8185 | put_aarch64_insn (buf, insn); | |
8186 | } | |
8187 | break; | |
8188 | ||
8189 | case BFD_RELOC_AARCH64_MOVW_G0: | |
a06ea964 | 8190 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
f09c556a | 8191 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
ca632371 | 8192 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC: |
32247401 RL |
8193 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
8194 | case BFD_RELOC_AARCH64_MOVW_PREL_G0_NC: | |
a06ea964 NC |
8195 | scale = 0; |
8196 | goto movw_common; | |
8197 | case BFD_RELOC_AARCH64_MOVW_G1: | |
a06ea964 | 8198 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
f09c556a | 8199 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
654248e7 | 8200 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
32247401 RL |
8201 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: |
8202 | case BFD_RELOC_AARCH64_MOVW_PREL_G1_NC: | |
a06ea964 NC |
8203 | scale = 16; |
8204 | goto movw_common; | |
43a357f9 RL |
8205 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
8206 | scale = 0; | |
8207 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
8208 | /* Should always be exported to object file, see | |
8209 | aarch64_force_relocation(). */ | |
8210 | gas_assert (!fixP->fx_done); | |
8211 | gas_assert (seg->use_rela_p); | |
8212 | goto movw_common; | |
8213 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
8214 | scale = 16; | |
8215 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
8216 | /* Should always be exported to object file, see | |
8217 | aarch64_force_relocation(). */ | |
8218 | gas_assert (!fixP->fx_done); | |
8219 | gas_assert (seg->use_rela_p); | |
8220 | goto movw_common; | |
a06ea964 | 8221 | case BFD_RELOC_AARCH64_MOVW_G2: |
a06ea964 | 8222 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
f09c556a | 8223 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
32247401 RL |
8224 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: |
8225 | case BFD_RELOC_AARCH64_MOVW_PREL_G2_NC: | |
a06ea964 NC |
8226 | scale = 32; |
8227 | goto movw_common; | |
8228 | case BFD_RELOC_AARCH64_MOVW_G3: | |
32247401 | 8229 | case BFD_RELOC_AARCH64_MOVW_PREL_G3: |
a06ea964 NC |
8230 | scale = 48; |
8231 | movw_common: | |
8232 | if (fixP->fx_done || !seg->use_rela_p) | |
8233 | { | |
8234 | insn = get_aarch64_insn (buf); | |
8235 | ||
8236 | if (!fixP->fx_done) | |
8237 | { | |
8238 | /* REL signed addend must fit in 16 bits */ | |
8239 | if (signed_overflow (value, 16)) | |
8240 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8241 | _("offset out of range")); | |
8242 | } | |
8243 | else | |
8244 | { | |
8245 | /* Check for overflow and scale. */ | |
8246 | switch (fixP->fx_r_type) | |
8247 | { | |
8248 | case BFD_RELOC_AARCH64_MOVW_G0: | |
8249 | case BFD_RELOC_AARCH64_MOVW_G1: | |
8250 | case BFD_RELOC_AARCH64_MOVW_G2: | |
8251 | case BFD_RELOC_AARCH64_MOVW_G3: | |
654248e7 | 8252 | case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1: |
43a357f9 | 8253 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: |
a06ea964 NC |
8254 | if (unsigned_overflow (value, scale + 16)) |
8255 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8256 | _("unsigned value out of range")); | |
8257 | break; | |
8258 | case BFD_RELOC_AARCH64_MOVW_G0_S: | |
8259 | case BFD_RELOC_AARCH64_MOVW_G1_S: | |
8260 | case BFD_RELOC_AARCH64_MOVW_G2_S: | |
32247401 RL |
8261 | case BFD_RELOC_AARCH64_MOVW_PREL_G0: |
8262 | case BFD_RELOC_AARCH64_MOVW_PREL_G1: | |
8263 | case BFD_RELOC_AARCH64_MOVW_PREL_G2: | |
a06ea964 NC |
8264 | /* NOTE: We can only come here with movz or movn. */ |
8265 | if (signed_overflow (value, scale + 16)) | |
8266 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8267 | _("signed value out of range")); | |
8268 | if (value < 0) | |
8269 | { | |
8270 | /* Force use of MOVN. */ | |
8271 | value = ~value; | |
8272 | insn = reencode_movzn_to_movn (insn); | |
8273 | } | |
8274 | else | |
8275 | { | |
8276 | /* Force use of MOVZ. */ | |
8277 | insn = reencode_movzn_to_movz (insn); | |
8278 | } | |
8279 | break; | |
8280 | default: | |
8281 | /* Unchecked relocations. */ | |
8282 | break; | |
8283 | } | |
8284 | value >>= scale; | |
8285 | } | |
8286 | ||
8287 | /* Insert value into MOVN/MOVZ/MOVK instruction. */ | |
8288 | insn |= encode_movw_imm (value & 0xffff); | |
8289 | ||
8290 | put_aarch64_insn (buf, insn); | |
8291 | } | |
8292 | break; | |
8293 | ||
a6bb11b2 YZ |
8294 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC: |
8295 | fixP->fx_r_type = (ilp32_p | |
8296 | ? BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC | |
8297 | : BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC); | |
8298 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
8299 | /* Should always be exported to object file, see | |
8300 | aarch64_force_relocation(). */ | |
8301 | gas_assert (!fixP->fx_done); | |
8302 | gas_assert (seg->use_rela_p); | |
8303 | break; | |
8304 | ||
8305 | case BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC: | |
8306 | fixP->fx_r_type = (ilp32_p | |
8307 | ? BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC | |
f955cccf | 8308 | : BFD_RELOC_AARCH64_TLSDESC_LD64_LO12); |
a6bb11b2 YZ |
8309 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
8310 | /* Should always be exported to object file, see | |
8311 | aarch64_force_relocation(). */ | |
8312 | gas_assert (!fixP->fx_done); | |
8313 | gas_assert (seg->use_rela_p); | |
8314 | break; | |
8315 | ||
f955cccf | 8316 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
2c0a3565 | 8317 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 8318 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
2c0a3565 | 8319 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 8320 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 8321 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
a06ea964 | 8322 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
2c0a3565 | 8323 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 8324 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
3e8286c0 | 8325 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
1aa66fb1 | 8326 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
a06ea964 | 8327 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 8328 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
2c0a3565 | 8329 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 8330 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
8331 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
8332 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
49df5539 | 8333 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
70151fb5 | 8334 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
13289c10 | 8335 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
a12fad50 | 8336 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
1107e076 | 8337 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
6c37fedc | 8338 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
4c562523 JW |
8339 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12: |
8340 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC: | |
8341 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12: | |
8342 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC: | |
8343 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12: | |
8344 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC: | |
8345 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12: | |
8346 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC: | |
49df5539 JW |
8347 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
8348 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: | |
8349 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: | |
8350 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: | |
8351 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: | |
84f1b9fb RL |
8352 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12: |
8353 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC: | |
8354 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12: | |
8355 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC: | |
8356 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12: | |
8357 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC: | |
8358 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12: | |
8359 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC: | |
a06ea964 | 8360 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
2c0a3565 | 8361 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: |
a06ea964 | 8362 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: |
a06ea964 NC |
8363 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
8364 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: | |
2c0a3565 MS |
8365 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
8366 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: | |
8367 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: | |
a06ea964 NC |
8368 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
8369 | /* Should always be exported to object file, see | |
8370 | aarch64_force_relocation(). */ | |
8371 | gas_assert (!fixP->fx_done); | |
8372 | gas_assert (seg->use_rela_p); | |
8373 | break; | |
8374 | ||
a6bb11b2 YZ |
8375 | case BFD_RELOC_AARCH64_LD_GOT_LO12_NC: |
8376 | /* Should always be exported to object file, see | |
8377 | aarch64_force_relocation(). */ | |
8378 | fixP->fx_r_type = (ilp32_p | |
8379 | ? BFD_RELOC_AARCH64_LD32_GOT_LO12_NC | |
8380 | : BFD_RELOC_AARCH64_LD64_GOT_LO12_NC); | |
8381 | gas_assert (!fixP->fx_done); | |
8382 | gas_assert (seg->use_rela_p); | |
8383 | break; | |
8384 | ||
a06ea964 | 8385 | case BFD_RELOC_AARCH64_ADD_LO12: |
f09c556a JW |
8386 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
8387 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: | |
8388 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
8389 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: | |
8390 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: | |
3d715ce4 | 8391 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
87f5fbcc | 8392 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
a921b5bd | 8393 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
f09c556a JW |
8394 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
8395 | case BFD_RELOC_AARCH64_LDST128_LO12: | |
a06ea964 NC |
8396 | case BFD_RELOC_AARCH64_LDST16_LO12: |
8397 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
8398 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
f09c556a | 8399 | case BFD_RELOC_AARCH64_LDST8_LO12: |
a06ea964 NC |
8400 | /* Should always be exported to object file, see |
8401 | aarch64_force_relocation(). */ | |
8402 | gas_assert (!fixP->fx_done); | |
8403 | gas_assert (seg->use_rela_p); | |
8404 | break; | |
8405 | ||
8406 | case BFD_RELOC_AARCH64_TLSDESC_ADD: | |
a06ea964 | 8407 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
f09c556a | 8408 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
a06ea964 NC |
8409 | break; |
8410 | ||
b97e87cc NC |
8411 | case BFD_RELOC_UNUSED: |
8412 | /* An error will already have been reported. */ | |
8413 | break; | |
8414 | ||
a06ea964 NC |
8415 | default: |
8416 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
8417 | _("unexpected %s fixup"), | |
8418 | bfd_get_reloc_code_name (fixP->fx_r_type)); | |
8419 | break; | |
8420 | } | |
8421 | ||
dc1e8a47 | 8422 | apply_fix_return: |
a06ea964 NC |
8423 | /* Free the allocated the struct aarch64_inst. |
8424 | N.B. currently there are very limited number of fix-up types actually use | |
8425 | this field, so the impact on the performance should be minimal . */ | |
9fbb53c7 | 8426 | free (fixP->tc_fix_data.inst); |
a06ea964 NC |
8427 | |
8428 | return; | |
8429 | } | |
8430 | ||
8431 | /* Translate internal representation of relocation info to BFD target | |
8432 | format. */ | |
8433 | ||
8434 | arelent * | |
8435 | tc_gen_reloc (asection * section, fixS * fixp) | |
8436 | { | |
8437 | arelent *reloc; | |
8438 | bfd_reloc_code_real_type code; | |
8439 | ||
325801bd | 8440 | reloc = XNEW (arelent); |
a06ea964 | 8441 | |
325801bd | 8442 | reloc->sym_ptr_ptr = XNEW (asymbol *); |
a06ea964 NC |
8443 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
8444 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
8445 | ||
8446 | if (fixp->fx_pcrel) | |
8447 | { | |
8448 | if (section->use_rela_p) | |
8449 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
8450 | else | |
8451 | fixp->fx_offset = reloc->address; | |
8452 | } | |
8453 | reloc->addend = fixp->fx_offset; | |
8454 | ||
8455 | code = fixp->fx_r_type; | |
8456 | switch (code) | |
8457 | { | |
8458 | case BFD_RELOC_16: | |
8459 | if (fixp->fx_pcrel) | |
8460 | code = BFD_RELOC_16_PCREL; | |
8461 | break; | |
8462 | ||
8463 | case BFD_RELOC_32: | |
8464 | if (fixp->fx_pcrel) | |
8465 | code = BFD_RELOC_32_PCREL; | |
8466 | break; | |
8467 | ||
8468 | case BFD_RELOC_64: | |
8469 | if (fixp->fx_pcrel) | |
8470 | code = BFD_RELOC_64_PCREL; | |
8471 | break; | |
8472 | ||
8473 | default: | |
8474 | break; | |
8475 | } | |
8476 | ||
8477 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
8478 | if (reloc->howto == NULL) | |
8479 | { | |
8480 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
8481 | _ | |
8482 | ("cannot represent %s relocation in this object file format"), | |
8483 | bfd_get_reloc_code_name (code)); | |
8484 | return NULL; | |
8485 | } | |
8486 | ||
8487 | return reloc; | |
8488 | } | |
8489 | ||
8490 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ | |
8491 | ||
8492 | void | |
8493 | cons_fix_new_aarch64 (fragS * frag, int where, int size, expressionS * exp) | |
8494 | { | |
8495 | bfd_reloc_code_real_type type; | |
8496 | int pcrel = 0; | |
8497 | ||
8498 | /* Pick a reloc. | |
8499 | FIXME: @@ Should look at CPU word size. */ | |
8500 | switch (size) | |
8501 | { | |
8502 | case 1: | |
8503 | type = BFD_RELOC_8; | |
8504 | break; | |
8505 | case 2: | |
8506 | type = BFD_RELOC_16; | |
8507 | break; | |
8508 | case 4: | |
8509 | type = BFD_RELOC_32; | |
8510 | break; | |
8511 | case 8: | |
8512 | type = BFD_RELOC_64; | |
8513 | break; | |
8514 | default: | |
8515 | as_bad (_("cannot do %u-byte relocation"), size); | |
8516 | type = BFD_RELOC_UNUSED; | |
8517 | break; | |
8518 | } | |
8519 | ||
8520 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); | |
8521 | } | |
8522 | ||
8523 | int | |
8524 | aarch64_force_relocation (struct fix *fixp) | |
8525 | { | |
8526 | switch (fixp->fx_r_type) | |
8527 | { | |
8528 | case BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP: | |
8529 | /* Perform these "immediate" internal relocations | |
8530 | even if the symbol is extern or weak. */ | |
8531 | return 0; | |
8532 | ||
a6bb11b2 | 8533 | case BFD_RELOC_AARCH64_LD_GOT_LO12_NC: |
f09c556a JW |
8534 | case BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC: |
8535 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC: | |
a6bb11b2 YZ |
8536 | /* Pseudo relocs that need to be fixed up according to |
8537 | ilp32_p. */ | |
8538 | return 0; | |
8539 | ||
2c0a3565 MS |
8540 | case BFD_RELOC_AARCH64_ADD_LO12: |
8541 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: | |
8542 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: | |
8543 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: | |
8544 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: | |
8545 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: | |
3d715ce4 | 8546 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
87f5fbcc | 8547 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
a921b5bd | 8548 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
2c0a3565 MS |
8549 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
8550 | case BFD_RELOC_AARCH64_LDST128_LO12: | |
8551 | case BFD_RELOC_AARCH64_LDST16_LO12: | |
8552 | case BFD_RELOC_AARCH64_LDST32_LO12: | |
8553 | case BFD_RELOC_AARCH64_LDST64_LO12: | |
8554 | case BFD_RELOC_AARCH64_LDST8_LO12: | |
f955cccf | 8555 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12: |
2c0a3565 | 8556 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
389b8029 | 8557 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
2c0a3565 | 8558 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
f955cccf | 8559 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12: |
1ada945d | 8560 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
43a357f9 RL |
8561 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: |
8562 | case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: | |
a06ea964 | 8563 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
2c0a3565 | 8564 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
3c12b054 | 8565 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
3e8286c0 | 8566 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: |
1aa66fb1 | 8567 | case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: |
a06ea964 | 8568 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
a6bb11b2 | 8569 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
2c0a3565 | 8570 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
043bf05a | 8571 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
3b957e5b RL |
8572 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC: |
8573 | case BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1: | |
8574 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: | |
70151fb5 | 8575 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
13289c10 | 8576 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
a12fad50 | 8577 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
1107e076 | 8578 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
6c37fedc | 8579 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
4c562523 JW |
8580 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12: |
8581 | case BFD_RELOC_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC: | |
8582 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12: | |
8583 | case BFD_RELOC_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC: | |
8584 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12: | |
8585 | case BFD_RELOC_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC: | |
8586 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12: | |
8587 | case BFD_RELOC_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC: | |
49df5539 JW |
8588 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
8589 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: | |
8590 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: | |
8591 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: | |
8592 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: | |
84f1b9fb RL |
8593 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12: |
8594 | case BFD_RELOC_AARCH64_TLSLE_LDST16_TPREL_LO12_NC: | |
8595 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12: | |
8596 | case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12_NC: | |
8597 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12: | |
8598 | case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12_NC: | |
8599 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12: | |
8600 | case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12_NC: | |
a06ea964 | 8601 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
2c0a3565 | 8602 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: |
a06ea964 | 8603 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: |
a06ea964 NC |
8604 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
8605 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: | |
2c0a3565 MS |
8606 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
8607 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: | |
8608 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: | |
a06ea964 NC |
8609 | /* Always leave these relocations for the linker. */ |
8610 | return 1; | |
8611 | ||
f0070c1e SP |
8612 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
8613 | case BFD_RELOC_AARCH64_BRANCH19: | |
8614 | case BFD_RELOC_AARCH64_TSTBR14: | |
8615 | case BFD_RELOC_AARCH64_CALL26: | |
8616 | case BFD_RELOC_AARCH64_JUMP26: | |
8617 | gas_assert (fixp->fx_addsy != NULL); | |
8618 | ||
8619 | /* A jump/call destination will get adjusted to section+offset only | |
8620 | if both caller and callee are of the same type. */ | |
8621 | if (symbol_section_p (fixp->fx_addsy)) | |
8622 | break; | |
8623 | ||
8624 | if ((fixp->tc_fix_data.c64 | |
8625 | && !AARCH64_IS_C64 (fixp->fx_addsy)) | |
8626 | || (!fixp->tc_fix_data.c64 | |
8627 | && AARCH64_IS_C64 (fixp->fx_addsy))) | |
8628 | return 1; | |
8629 | ||
8630 | break; | |
8631 | ||
a06ea964 NC |
8632 | default: |
8633 | break; | |
8634 | } | |
8635 | ||
8636 | return generic_force_reloc (fixp); | |
8637 | } | |
8638 | ||
8639 | #ifdef OBJ_ELF | |
8640 | ||
3c0367d0 JW |
8641 | /* Implement md_after_parse_args. This is the earliest time we need to decide |
8642 | ABI. If no -mabi specified, the ABI will be decided by target triplet. */ | |
8643 | ||
8644 | void | |
8645 | aarch64_after_parse_args (void) | |
8646 | { | |
8647 | if (aarch64_abi != AARCH64_ABI_NONE) | |
8648 | return; | |
8649 | ||
8650 | /* DEFAULT_ARCH will have ":32" extension if it's configured for ILP32. */ | |
8651 | if (strlen (default_arch) > 7 && strcmp (default_arch + 7, ":32") == 0) | |
8652 | aarch64_abi = AARCH64_ABI_ILP32; | |
8653 | else | |
8654 | aarch64_abi = AARCH64_ABI_LP64; | |
8655 | } | |
8656 | ||
a06ea964 NC |
8657 | const char * |
8658 | elf64_aarch64_target_format (void) | |
8659 | { | |
12400dcc AM |
8660 | #ifdef TE_CLOUDABI |
8661 | /* FIXME: What to do for ilp32_p ? */ | |
8662 | if (target_big_endian) | |
8663 | return "elf64-bigaarch64-cloudabi"; | |
8664 | else | |
8665 | return "elf64-littleaarch64-cloudabi"; | |
8666 | #else | |
a06ea964 | 8667 | if (target_big_endian) |
cec5225b | 8668 | return ilp32_p ? "elf32-bigaarch64" : "elf64-bigaarch64"; |
a06ea964 | 8669 | else |
cec5225b | 8670 | return ilp32_p ? "elf32-littleaarch64" : "elf64-littleaarch64"; |
12400dcc | 8671 | #endif |
a06ea964 NC |
8672 | } |
8673 | ||
8674 | void | |
8675 | aarch64elf_frob_symbol (symbolS * symp, int *puntp) | |
8676 | { | |
8677 | elf_frob_symbol (symp, puntp); | |
8678 | } | |
8679 | #endif | |
8680 | ||
8681 | /* MD interface: Finalization. */ | |
8682 | ||
8683 | /* A good place to do this, although this was probably not intended | |
8684 | for this kind of use. We need to dump the literal pool before | |
8685 | references are made to a null symbol pointer. */ | |
8686 | ||
8687 | void | |
8688 | aarch64_cleanup (void) | |
8689 | { | |
8690 | literal_pool *pool; | |
8691 | ||
8692 | for (pool = list_of_pools; pool; pool = pool->next) | |
8693 | { | |
8694 | /* Put it at the end of the relevant section. */ | |
8695 | subseg_set (pool->section, pool->sub_section); | |
8696 | s_ltorg (0); | |
8697 | } | |
8698 | } | |
8699 | ||
8700 | #ifdef OBJ_ELF | |
8701 | /* Remove any excess mapping symbols generated for alignment frags in | |
8702 | SEC. We may have created a mapping symbol before a zero byte | |
8703 | alignment; remove it if there's a mapping symbol after the | |
8704 | alignment. */ | |
8705 | static void | |
8706 | check_mapping_symbols (bfd * abfd ATTRIBUTE_UNUSED, asection * sec, | |
8707 | void *dummy ATTRIBUTE_UNUSED) | |
8708 | { | |
8709 | segment_info_type *seginfo = seg_info (sec); | |
8710 | fragS *fragp; | |
8711 | ||
8712 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
8713 | return; | |
8714 | ||
8715 | for (fragp = seginfo->frchainP->frch_root; | |
8716 | fragp != NULL; fragp = fragp->fr_next) | |
8717 | { | |
8718 | symbolS *sym = fragp->tc_frag_data.last_map; | |
8719 | fragS *next = fragp->fr_next; | |
8720 | ||
8721 | /* Variable-sized frags have been converted to fixed size by | |
8722 | this point. But if this was variable-sized to start with, | |
8723 | there will be a fixed-size frag after it. So don't handle | |
8724 | next == NULL. */ | |
8725 | if (sym == NULL || next == NULL) | |
8726 | continue; | |
8727 | ||
8728 | if (S_GET_VALUE (sym) < next->fr_address) | |
8729 | /* Not at the end of this frag. */ | |
8730 | continue; | |
8731 | know (S_GET_VALUE (sym) == next->fr_address); | |
8732 | ||
8733 | do | |
8734 | { | |
8735 | if (next->tc_frag_data.first_map != NULL) | |
8736 | { | |
8737 | /* Next frag starts with a mapping symbol. Discard this | |
8738 | one. */ | |
8739 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
8740 | break; | |
8741 | } | |
8742 | ||
8743 | if (next->fr_next == NULL) | |
8744 | { | |
8745 | /* This mapping symbol is at the end of the section. Discard | |
8746 | it. */ | |
8747 | know (next->fr_fix == 0 && next->fr_var == 0); | |
8748 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
8749 | break; | |
8750 | } | |
8751 | ||
8752 | /* As long as we have empty frags without any mapping symbols, | |
8753 | keep looking. */ | |
8754 | /* If the next frag is non-empty and does not start with a | |
8755 | mapping symbol, then this mapping symbol is required. */ | |
8756 | if (next->fr_address != next->fr_next->fr_address) | |
8757 | break; | |
8758 | ||
8759 | next = next->fr_next; | |
8760 | } | |
8761 | while (next != NULL); | |
8762 | } | |
8763 | } | |
8764 | #endif | |
8765 | ||
8b21361b SP |
8766 | /* Avoid relocations from using section symbols in some cases. */ |
8767 | bfd_boolean | |
8768 | aarch64_fix_adjustable (struct fix *fixP) | |
8769 | { | |
8770 | switch (fixP->fx_r_type) | |
8771 | { | |
f0070c1e SP |
8772 | /* We need to retain symbol information when jumping between A64 and C64 |
8773 | states or between two C64 functions. In the C64 -> C64 situation it's | |
8774 | really only a corner case that breaks when symbols get replaced with | |
8775 | section symbols; this is when the jump distance is longer than what a | |
8776 | branch instruction can handle and we want to branch through a stub. | |
8777 | In such a case, the linker needs to know the symbol types of the | |
8778 | source and the destination and section symbols are an unreliable | |
8779 | source of this information. */ | |
8b21361b SP |
8780 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
8781 | case BFD_RELOC_AARCH64_ADD_LO12: | |
8782 | case BFD_RELOC_AARCH64_BRANCH19: | |
8783 | case BFD_RELOC_AARCH64_TSTBR14: | |
8784 | case BFD_RELOC_AARCH64_JUMP26: | |
8785 | case BFD_RELOC_AARCH64_CALL26: | |
f0070c1e | 8786 | if (fixP->tc_fix_data.c64 || AARCH64_IS_C64 (fixP->fx_addsy)) |
8b21361b SP |
8787 | return FALSE; |
8788 | break; | |
8789 | default: | |
8790 | break; | |
8791 | } | |
8792 | ||
8793 | return TRUE; | |
8794 | } | |
8795 | ||
a06ea964 NC |
8796 | /* Adjust the symbol table. */ |
8797 | ||
8798 | void | |
8799 | aarch64_adjust_symtab (void) | |
8800 | { | |
8801 | #ifdef OBJ_ELF | |
8b21361b SP |
8802 | symbolS * sym; |
8803 | ||
8804 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) | |
8805 | { | |
8806 | if (AARCH64_IS_C64 (sym) | |
8807 | && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)) | |
8808 | { | |
8809 | elf_symbol_type * elf_sym; | |
8810 | ||
8811 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); | |
8812 | ||
8813 | if (!bfd_is_aarch64_special_symbol_name | |
8814 | (elf_sym->symbol.name, BFD_AARCH64_SPECIAL_SYM_TYPE_ANY)) | |
8815 | elf_sym->internal_elf_sym.st_target_internal = ST_BRANCH_TO_C64; | |
8816 | } | |
8817 | } | |
8818 | ||
a06ea964 NC |
8819 | /* Remove any overlapping mapping symbols generated by alignment frags. */ |
8820 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
8821 | /* Now do generic ELF adjustments. */ | |
8822 | elf_adjust_symtab (); | |
8823 | #endif | |
8824 | } | |
8825 | ||
8826 | static void | |
629310ab | 8827 | checked_hash_insert (htab_t table, const char *key, void *value) |
a06ea964 | 8828 | { |
fe0e921f | 8829 | str_hash_insert (table, key, value, 0); |
a06ea964 NC |
8830 | } |
8831 | ||
fa63795f | 8832 | static void |
629310ab | 8833 | sysreg_hash_insert (htab_t table, const char *key, void *value) |
fa63795f AC |
8834 | { |
8835 | gas_assert (strlen (key) < AARCH64_MAX_SYSREG_NAME_LEN); | |
8836 | checked_hash_insert (table, key, value); | |
8837 | } | |
8838 | ||
a06ea964 NC |
8839 | static void |
8840 | fill_instruction_hash_table (void) | |
8841 | { | |
8842 | aarch64_opcode *opcode = aarch64_opcode_table; | |
8843 | ||
8844 | while (opcode->name != NULL) | |
8845 | { | |
8846 | templates *templ, *new_templ; | |
629310ab | 8847 | templ = str_hash_find (aarch64_ops_hsh, opcode->name); |
a06ea964 | 8848 | |
add39d23 | 8849 | new_templ = XNEW (templates); |
a06ea964 NC |
8850 | new_templ->opcode = opcode; |
8851 | new_templ->next = NULL; | |
8852 | ||
8853 | if (!templ) | |
8854 | checked_hash_insert (aarch64_ops_hsh, opcode->name, (void *) new_templ); | |
8855 | else | |
8856 | { | |
8857 | new_templ->next = templ->next; | |
8858 | templ->next = new_templ; | |
8859 | } | |
8860 | ++opcode; | |
8861 | } | |
8862 | } | |
8863 | ||
8864 | static inline void | |
8865 | convert_to_upper (char *dst, const char *src, size_t num) | |
8866 | { | |
8867 | unsigned int i; | |
8868 | for (i = 0; i < num && *src != '\0'; ++i, ++dst, ++src) | |
8869 | *dst = TOUPPER (*src); | |
8870 | *dst = '\0'; | |
8871 | } | |
8872 | ||
8873 | /* Assume STR point to a lower-case string, allocate, convert and return | |
8874 | the corresponding upper-case string. */ | |
8875 | static inline const char* | |
8876 | get_upper_str (const char *str) | |
8877 | { | |
8878 | char *ret; | |
8879 | size_t len = strlen (str); | |
325801bd | 8880 | ret = XNEWVEC (char, len + 1); |
a06ea964 NC |
8881 | convert_to_upper (ret, str, len); |
8882 | return ret; | |
8883 | } | |
8884 | ||
8885 | /* MD interface: Initialization. */ | |
8886 | ||
8887 | void | |
8888 | md_begin (void) | |
8889 | { | |
8890 | unsigned mach; | |
8891 | unsigned int i; | |
8892 | ||
f16c3d4f AM |
8893 | aarch64_ops_hsh = str_htab_create (); |
8894 | aarch64_cond_hsh = str_htab_create (); | |
8895 | aarch64_shift_hsh = str_htab_create (); | |
8896 | aarch64_sys_regs_hsh = str_htab_create (); | |
8897 | aarch64_pstatefield_hsh = str_htab_create (); | |
8898 | aarch64_sys_regs_ic_hsh = str_htab_create (); | |
8899 | aarch64_sys_regs_dc_hsh = str_htab_create (); | |
8900 | aarch64_sys_regs_at_hsh = str_htab_create (); | |
8901 | aarch64_sys_regs_tlbi_hsh = str_htab_create (); | |
8902 | aarch64_sys_regs_sr_hsh = str_htab_create (); | |
8903 | aarch64_reg_hsh = str_htab_create (); | |
8904 | aarch64_barrier_opt_hsh = str_htab_create (); | |
8905 | aarch64_nzcv_hsh = str_htab_create (); | |
8906 | aarch64_pldop_hsh = str_htab_create (); | |
8907 | aarch64_hint_opt_hsh = str_htab_create (); | |
a06ea964 NC |
8908 | |
8909 | fill_instruction_hash_table (); | |
8910 | ||
8911 | for (i = 0; aarch64_sys_regs[i].name != NULL; ++i) | |
fa63795f | 8912 | sysreg_hash_insert (aarch64_sys_regs_hsh, aarch64_sys_regs[i].name, |
a06ea964 NC |
8913 | (void *) (aarch64_sys_regs + i)); |
8914 | ||
8915 | for (i = 0; aarch64_pstatefields[i].name != NULL; ++i) | |
fa63795f | 8916 | sysreg_hash_insert (aarch64_pstatefield_hsh, |
a06ea964 NC |
8917 | aarch64_pstatefields[i].name, |
8918 | (void *) (aarch64_pstatefields + i)); | |
8919 | ||
875880c6 | 8920 | for (i = 0; aarch64_sys_regs_ic[i].name != NULL; i++) |
fa63795f | 8921 | sysreg_hash_insert (aarch64_sys_regs_ic_hsh, |
875880c6 | 8922 | aarch64_sys_regs_ic[i].name, |
a06ea964 NC |
8923 | (void *) (aarch64_sys_regs_ic + i)); |
8924 | ||
875880c6 | 8925 | for (i = 0; aarch64_sys_regs_dc[i].name != NULL; i++) |
fa63795f | 8926 | sysreg_hash_insert (aarch64_sys_regs_dc_hsh, |
875880c6 | 8927 | aarch64_sys_regs_dc[i].name, |
a06ea964 NC |
8928 | (void *) (aarch64_sys_regs_dc + i)); |
8929 | ||
875880c6 | 8930 | for (i = 0; aarch64_sys_regs_at[i].name != NULL; i++) |
fa63795f | 8931 | sysreg_hash_insert (aarch64_sys_regs_at_hsh, |
875880c6 | 8932 | aarch64_sys_regs_at[i].name, |
a06ea964 NC |
8933 | (void *) (aarch64_sys_regs_at + i)); |
8934 | ||
875880c6 | 8935 | for (i = 0; aarch64_sys_regs_tlbi[i].name != NULL; i++) |
fa63795f | 8936 | sysreg_hash_insert (aarch64_sys_regs_tlbi_hsh, |
875880c6 | 8937 | aarch64_sys_regs_tlbi[i].name, |
a06ea964 NC |
8938 | (void *) (aarch64_sys_regs_tlbi + i)); |
8939 | ||
2ac435d4 | 8940 | for (i = 0; aarch64_sys_regs_sr[i].name != NULL; i++) |
fa63795f | 8941 | sysreg_hash_insert (aarch64_sys_regs_sr_hsh, |
2ac435d4 SD |
8942 | aarch64_sys_regs_sr[i].name, |
8943 | (void *) (aarch64_sys_regs_sr + i)); | |
8944 | ||
a06ea964 NC |
8945 | for (i = 0; i < ARRAY_SIZE (reg_names); i++) |
8946 | checked_hash_insert (aarch64_reg_hsh, reg_names[i].name, | |
8947 | (void *) (reg_names + i)); | |
8948 | ||
8949 | for (i = 0; i < ARRAY_SIZE (nzcv_names); i++) | |
8950 | checked_hash_insert (aarch64_nzcv_hsh, nzcv_names[i].template, | |
8951 | (void *) (nzcv_names + i)); | |
8952 | ||
8953 | for (i = 0; aarch64_operand_modifiers[i].name != NULL; i++) | |
8954 | { | |
8955 | const char *name = aarch64_operand_modifiers[i].name; | |
8956 | checked_hash_insert (aarch64_shift_hsh, name, | |
8957 | (void *) (aarch64_operand_modifiers + i)); | |
8958 | /* Also hash the name in the upper case. */ | |
8959 | checked_hash_insert (aarch64_shift_hsh, get_upper_str (name), | |
8960 | (void *) (aarch64_operand_modifiers + i)); | |
8961 | } | |
8962 | ||
8963 | for (i = 0; i < ARRAY_SIZE (aarch64_conds); i++) | |
8964 | { | |
8965 | unsigned int j; | |
8966 | /* A condition code may have alias(es), e.g. "cc", "lo" and "ul" are | |
8967 | the same condition code. */ | |
8968 | for (j = 0; j < ARRAY_SIZE (aarch64_conds[i].names); ++j) | |
8969 | { | |
8970 | const char *name = aarch64_conds[i].names[j]; | |
8971 | if (name == NULL) | |
8972 | break; | |
8973 | checked_hash_insert (aarch64_cond_hsh, name, | |
8974 | (void *) (aarch64_conds + i)); | |
8975 | /* Also hash the name in the upper case. */ | |
8976 | checked_hash_insert (aarch64_cond_hsh, get_upper_str (name), | |
8977 | (void *) (aarch64_conds + i)); | |
8978 | } | |
8979 | } | |
8980 | ||
8981 | for (i = 0; i < ARRAY_SIZE (aarch64_barrier_options); i++) | |
8982 | { | |
8983 | const char *name = aarch64_barrier_options[i].name; | |
8984 | /* Skip xx00 - the unallocated values of option. */ | |
8985 | if ((i & 0x3) == 0) | |
8986 | continue; | |
8987 | checked_hash_insert (aarch64_barrier_opt_hsh, name, | |
8988 | (void *) (aarch64_barrier_options + i)); | |
8989 | /* Also hash the name in the upper case. */ | |
8990 | checked_hash_insert (aarch64_barrier_opt_hsh, get_upper_str (name), | |
8991 | (void *) (aarch64_barrier_options + i)); | |
8992 | } | |
8993 | ||
8994 | for (i = 0; i < ARRAY_SIZE (aarch64_prfops); i++) | |
8995 | { | |
8996 | const char* name = aarch64_prfops[i].name; | |
a1ccaec9 YZ |
8997 | /* Skip the unallocated hint encodings. */ |
8998 | if (name == NULL) | |
a06ea964 NC |
8999 | continue; |
9000 | checked_hash_insert (aarch64_pldop_hsh, name, | |
9001 | (void *) (aarch64_prfops + i)); | |
9002 | /* Also hash the name in the upper case. */ | |
9003 | checked_hash_insert (aarch64_pldop_hsh, get_upper_str (name), | |
9004 | (void *) (aarch64_prfops + i)); | |
9005 | } | |
9006 | ||
1e6f4800 MW |
9007 | for (i = 0; aarch64_hint_options[i].name != NULL; i++) |
9008 | { | |
9009 | const char* name = aarch64_hint_options[i].name; | |
0a821c4f | 9010 | const char* upper_name = get_upper_str(name); |
1e6f4800 MW |
9011 | |
9012 | checked_hash_insert (aarch64_hint_opt_hsh, name, | |
9013 | (void *) (aarch64_hint_options + i)); | |
0a821c4f AP |
9014 | |
9015 | /* Also hash the name in the upper case if not the same. */ | |
9016 | if (strcmp (name, upper_name) != 0) | |
9017 | checked_hash_insert (aarch64_hint_opt_hsh, upper_name, | |
9018 | (void *) (aarch64_hint_options + i)); | |
1e6f4800 MW |
9019 | } |
9020 | ||
a06ea964 NC |
9021 | /* Set the cpu variant based on the command-line options. */ |
9022 | if (!mcpu_cpu_opt) | |
9023 | mcpu_cpu_opt = march_cpu_opt; | |
9024 | ||
9025 | if (!mcpu_cpu_opt) | |
9026 | mcpu_cpu_opt = &cpu_default; | |
9027 | ||
9028 | cpu_variant = *mcpu_cpu_opt; | |
9029 | ||
9030 | /* Record the CPU type. */ | |
cec5225b | 9031 | mach = ilp32_p ? bfd_mach_aarch64_ilp32 : bfd_mach_aarch64; |
a06ea964 NC |
9032 | |
9033 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
9034 | } | |
9035 | ||
9036 | /* Command line processing. */ | |
9037 | ||
9038 | const char *md_shortopts = "m:"; | |
9039 | ||
9040 | #ifdef AARCH64_BI_ENDIAN | |
9041 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
9042 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
9043 | #else | |
9044 | #if TARGET_BYTES_BIG_ENDIAN | |
9045 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
9046 | #else | |
9047 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
9048 | #endif | |
9049 | #endif | |
9050 | ||
9051 | struct option md_longopts[] = { | |
9052 | #ifdef OPTION_EB | |
9053 | {"EB", no_argument, NULL, OPTION_EB}, | |
9054 | #endif | |
9055 | #ifdef OPTION_EL | |
9056 | {"EL", no_argument, NULL, OPTION_EL}, | |
9057 | #endif | |
9058 | {NULL, no_argument, NULL, 0} | |
9059 | }; | |
9060 | ||
9061 | size_t md_longopts_size = sizeof (md_longopts); | |
9062 | ||
9063 | struct aarch64_option_table | |
9064 | { | |
e0471c16 TS |
9065 | const char *option; /* Option name to match. */ |
9066 | const char *help; /* Help information. */ | |
a06ea964 NC |
9067 | int *var; /* Variable to change. */ |
9068 | int value; /* What to change it to. */ | |
9069 | char *deprecated; /* If non-null, print this message. */ | |
9070 | }; | |
9071 | ||
9072 | static struct aarch64_option_table aarch64_opts[] = { | |
9073 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
9074 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
9075 | NULL}, | |
9076 | #ifdef DEBUG_AARCH64 | |
9077 | {"mdebug-dump", N_("temporary switch for dumping"), &debug_dump, 1, NULL}, | |
9078 | #endif /* DEBUG_AARCH64 */ | |
9079 | {"mverbose-error", N_("output verbose error messages"), &verbose_error_p, 1, | |
9080 | NULL}, | |
a52e6fd3 YZ |
9081 | {"mno-verbose-error", N_("do not output verbose error messages"), |
9082 | &verbose_error_p, 0, NULL}, | |
a06ea964 NC |
9083 | {NULL, NULL, NULL, 0, NULL} |
9084 | }; | |
9085 | ||
9086 | struct aarch64_cpu_option_table | |
9087 | { | |
e0471c16 | 9088 | const char *name; |
a06ea964 NC |
9089 | const aarch64_feature_set value; |
9090 | /* The canonical name of the CPU, or NULL to use NAME converted to upper | |
9091 | case. */ | |
9092 | const char *canonical_name; | |
9093 | }; | |
9094 | ||
9095 | /* This list should, at a minimum, contain all the cpu names | |
9096 | recognized by GCC. */ | |
9097 | static const struct aarch64_cpu_option_table aarch64_cpus[] = { | |
9098 | {"all", AARCH64_ANY, NULL}, | |
546053ac DZ |
9099 | {"cortex-a34", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9100 | AARCH64_FEATURE_CRC), "Cortex-A34"}, | |
9c352f1c JG |
9101 | {"cortex-a35", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9102 | AARCH64_FEATURE_CRC), "Cortex-A35"}, | |
aa31c464 JW |
9103 | {"cortex-a53", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9104 | AARCH64_FEATURE_CRC), "Cortex-A53"}, | |
9105 | {"cortex-a57", AARCH64_FEATURE (AARCH64_ARCH_V8, | |
9106 | AARCH64_FEATURE_CRC), "Cortex-A57"}, | |
2abdd192 JW |
9107 | {"cortex-a72", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9108 | AARCH64_FEATURE_CRC), "Cortex-A72"}, | |
1aa70332 KT |
9109 | {"cortex-a73", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9110 | AARCH64_FEATURE_CRC), "Cortex-A73"}, | |
1e292627 | 9111 | {"cortex-a55", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
1c5c938a | 9112 | AARCH64_FEATURE_RCPC | AARCH64_FEATURE_F16 | AARCH64_FEATURE_DOTPROD), |
1e292627 JG |
9113 | "Cortex-A55"}, |
9114 | {"cortex-a75", AARCH64_FEATURE (AARCH64_ARCH_V8_2, | |
1c5c938a | 9115 | AARCH64_FEATURE_RCPC | AARCH64_FEATURE_F16 | AARCH64_FEATURE_DOTPROD), |
1e292627 | 9116 | "Cortex-A75"}, |
c2a0f929 | 9117 | {"cortex-a76", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
9118 | AARCH64_FEATURE_RCPC | AARCH64_FEATURE_F16 | AARCH64_FEATURE_DOTPROD), | |
9119 | "Cortex-A76"}, | |
546053ac DZ |
9120 | {"cortex-a76ae", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
9121 | AARCH64_FEATURE_F16 | AARCH64_FEATURE_RCPC | |
9122 | | AARCH64_FEATURE_DOTPROD | |
9123 | | AARCH64_FEATURE_SSBS), | |
9124 | "Cortex-A76AE"}, | |
9125 | {"cortex-a77", AARCH64_FEATURE (AARCH64_ARCH_V8_2, | |
9126 | AARCH64_FEATURE_F16 | AARCH64_FEATURE_RCPC | |
9127 | | AARCH64_FEATURE_DOTPROD | |
9128 | | AARCH64_FEATURE_SSBS), | |
9129 | "Cortex-A77"}, | |
9130 | {"cortex-a65", AARCH64_FEATURE (AARCH64_ARCH_V8_2, | |
9131 | AARCH64_FEATURE_F16 | AARCH64_FEATURE_RCPC | |
9132 | | AARCH64_FEATURE_DOTPROD | |
9133 | | AARCH64_FEATURE_SSBS), | |
9134 | "Cortex-A65"}, | |
9135 | {"cortex-a65ae", AARCH64_FEATURE (AARCH64_ARCH_V8_2, | |
9136 | AARCH64_FEATURE_F16 | AARCH64_FEATURE_RCPC | |
9137 | | AARCH64_FEATURE_DOTPROD | |
9138 | | AARCH64_FEATURE_SSBS), | |
9139 | "Cortex-A65AE"}, | |
77718e5b PW |
9140 | {"cortex-a78", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
9141 | AARCH64_FEATURE_F16 | |
9142 | | AARCH64_FEATURE_RCPC | |
9143 | | AARCH64_FEATURE_DOTPROD | |
9144 | | AARCH64_FEATURE_SSBS | |
9145 | | AARCH64_FEATURE_PROFILE), | |
9146 | "Cortex-A78"}, | |
9147 | {"cortex-a78ae", AARCH64_FEATURE (AARCH64_ARCH_V8_2, | |
9148 | AARCH64_FEATURE_F16 | |
9149 | | AARCH64_FEATURE_RCPC | |
9150 | | AARCH64_FEATURE_DOTPROD | |
9151 | | AARCH64_FEATURE_SSBS | |
9152 | | AARCH64_FEATURE_PROFILE), | |
9153 | "Cortex-A78AE"}, | |
c8fcc360 KT |
9154 | {"ares", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
9155 | AARCH64_FEATURE_RCPC | AARCH64_FEATURE_F16 | |
9156 | | AARCH64_FEATURE_DOTPROD | |
9157 | | AARCH64_FEATURE_PROFILE), | |
9158 | "Ares"}, | |
2412d878 EM |
9159 | {"exynos-m1", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9160 | AARCH64_FEATURE_CRC | AARCH64_FEATURE_CRYPTO), | |
9161 | "Samsung Exynos M1"}, | |
2fe9c2a0 | 9162 | {"falkor", AARCH64_FEATURE (AARCH64_ARCH_V8, |
e58ff055 JW |
9163 | AARCH64_FEATURE_CRC | AARCH64_FEATURE_CRYPTO |
9164 | | AARCH64_FEATURE_RDMA), | |
2fe9c2a0 | 9165 | "Qualcomm Falkor"}, |
516dbc44 KT |
9166 | {"neoverse-e1", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
9167 | AARCH64_FEATURE_RCPC | AARCH64_FEATURE_F16 | |
9168 | | AARCH64_FEATURE_DOTPROD | |
9169 | | AARCH64_FEATURE_SSBS), | |
9170 | "Neoverse E1"}, | |
38e75bf2 KT |
9171 | {"neoverse-n1", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
9172 | AARCH64_FEATURE_RCPC | AARCH64_FEATURE_F16 | |
9173 | | AARCH64_FEATURE_DOTPROD | |
9174 | | AARCH64_FEATURE_PROFILE), | |
9175 | "Neoverse N1"}, | |
990e5268 AC |
9176 | {"neoverse-n2", AARCH64_FEATURE (AARCH64_ARCH_V8_5, |
9177 | AARCH64_FEATURE_BFLOAT16 | |
9178 | | AARCH64_FEATURE_I8MM | |
9179 | | AARCH64_FEATURE_F16 | |
9180 | | AARCH64_FEATURE_SVE | |
9181 | | AARCH64_FEATURE_SVE2 | |
9182 | | AARCH64_FEATURE_SVE2_BITPERM | |
9183 | | AARCH64_FEATURE_MEMTAG | |
9184 | | AARCH64_FEATURE_RNG), | |
9185 | "Neoverse N2"}, | |
c769fd6a AC |
9186 | {"neoverse-v1", AARCH64_FEATURE (AARCH64_ARCH_V8_4, |
9187 | AARCH64_FEATURE_PROFILE | |
9188 | | AARCH64_FEATURE_CVADP | |
9189 | | AARCH64_FEATURE_SVE | |
9190 | | AARCH64_FEATURE_SSBS | |
9191 | | AARCH64_FEATURE_RNG | |
9192 | | AARCH64_FEATURE_F16 | |
9193 | | AARCH64_FEATURE_BFLOAT16 | |
9194 | | AARCH64_FEATURE_I8MM), "Neoverse V1"}, | |
6b21c2bf | 9195 | {"qdf24xx", AARCH64_FEATURE (AARCH64_ARCH_V8, |
e58ff055 JW |
9196 | AARCH64_FEATURE_CRC | AARCH64_FEATURE_CRYPTO |
9197 | | AARCH64_FEATURE_RDMA), | |
6b21c2bf | 9198 | "Qualcomm QDF24XX"}, |
eb5c42e5 | 9199 | {"saphira", AARCH64_FEATURE (AARCH64_ARCH_V8_4, |
7605d944 SP |
9200 | AARCH64_FEATURE_CRYPTO | AARCH64_FEATURE_PROFILE), |
9201 | "Qualcomm Saphira"}, | |
faade851 JW |
9202 | {"thunderx", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9203 | AARCH64_FEATURE_CRC | AARCH64_FEATURE_CRYPTO), | |
9204 | "Cavium ThunderX"}, | |
9f99c22e VP |
9205 | {"vulcan", AARCH64_FEATURE (AARCH64_ARCH_V8_1, |
9206 | AARCH64_FEATURE_CRYPTO), | |
0a8be2fe | 9207 | "Broadcom Vulcan"}, |
070cb956 PT |
9208 | /* The 'xgene-1' name is an older name for 'xgene1', which was used |
9209 | in earlier releases and is superseded by 'xgene1' in all | |
9210 | tools. */ | |
9877c63c | 9211 | {"xgene-1", AARCH64_ARCH_V8, "APM X-Gene 1"}, |
070cb956 | 9212 | {"xgene1", AARCH64_ARCH_V8, "APM X-Gene 1"}, |
aa31c464 JW |
9213 | {"xgene2", AARCH64_FEATURE (AARCH64_ARCH_V8, |
9214 | AARCH64_FEATURE_CRC), "APM X-Gene 2"}, | |
f1363b0f | 9215 | {"cortex-r82", AARCH64_ARCH_V8_R, "Cortex-R82"}, |
47e1f9de | 9216 | {"cortex-x1", AARCH64_FEATURE (AARCH64_ARCH_V8_2, |
f9b1d75e PW |
9217 | AARCH64_FEATURE_F16 |
9218 | | AARCH64_FEATURE_RCPC | |
9219 | | AARCH64_FEATURE_DOTPROD | |
9220 | | AARCH64_FEATURE_SSBS | |
9221 | | AARCH64_FEATURE_PROFILE), | |
9222 | "Cortex-X1"}, | |
a06ea964 NC |
9223 | {"generic", AARCH64_ARCH_V8, NULL}, |
9224 | ||
a06ea964 NC |
9225 | {NULL, AARCH64_ARCH_NONE, NULL} |
9226 | }; | |
9227 | ||
9228 | struct aarch64_arch_option_table | |
9229 | { | |
e0471c16 | 9230 | const char *name; |
a06ea964 NC |
9231 | const aarch64_feature_set value; |
9232 | }; | |
9233 | ||
9234 | /* This list should, at a minimum, contain all the architecture names | |
9235 | recognized by GCC. */ | |
9236 | static const struct aarch64_arch_option_table aarch64_archs[] = { | |
9237 | {"all", AARCH64_ANY}, | |
5a1ad39d | 9238 | {"armv8-a", AARCH64_ARCH_V8}, |
88f0ea34 | 9239 | {"armv8.1-a", AARCH64_ARCH_V8_1}, |
acb787b0 | 9240 | {"armv8.2-a", AARCH64_ARCH_V8_2}, |
1924ff75 | 9241 | {"armv8.3-a", AARCH64_ARCH_V8_3}, |
b6b9ca0c | 9242 | {"armv8.4-a", AARCH64_ARCH_V8_4}, |
70d56181 | 9243 | {"armv8.5-a", AARCH64_ARCH_V8_5}, |
8ae2d3d9 | 9244 | {"armv8.6-a", AARCH64_ARCH_V8_6}, |
95830c98 | 9245 | {"armv8-r", AARCH64_ARCH_V8_R}, |
3493da5c | 9246 | {"morello", AARCH64_ARCH_MORELLO}, |
a06ea964 NC |
9247 | {NULL, AARCH64_ARCH_NONE} |
9248 | }; | |
9249 | ||
9250 | /* ISA extensions. */ | |
9251 | struct aarch64_option_cpu_value_table | |
9252 | { | |
e0471c16 | 9253 | const char *name; |
a06ea964 | 9254 | const aarch64_feature_set value; |
93d8990c | 9255 | const aarch64_feature_set require; /* Feature dependencies. */ |
a06ea964 NC |
9256 | }; |
9257 | ||
9258 | static const struct aarch64_option_cpu_value_table aarch64_features[] = { | |
93d8990c SN |
9259 | {"crc", AARCH64_FEATURE (AARCH64_FEATURE_CRC, 0), |
9260 | AARCH64_ARCH_NONE}, | |
2dc4b12f | 9261 | {"crypto", AARCH64_FEATURE (AARCH64_FEATURE_CRYPTO, 0), |
fa09f4ea | 9262 | AARCH64_FEATURE (AARCH64_FEATURE_SIMD, 0)}, |
93d8990c SN |
9263 | {"fp", AARCH64_FEATURE (AARCH64_FEATURE_FP, 0), |
9264 | AARCH64_ARCH_NONE}, | |
9265 | {"lse", AARCH64_FEATURE (AARCH64_FEATURE_LSE, 0), | |
9266 | AARCH64_ARCH_NONE}, | |
9267 | {"simd", AARCH64_FEATURE (AARCH64_FEATURE_SIMD, 0), | |
fa09f4ea | 9268 | AARCH64_FEATURE (AARCH64_FEATURE_FP, 0)}, |
93d8990c SN |
9269 | {"pan", AARCH64_FEATURE (AARCH64_FEATURE_PAN, 0), |
9270 | AARCH64_ARCH_NONE}, | |
9271 | {"lor", AARCH64_FEATURE (AARCH64_FEATURE_LOR, 0), | |
9272 | AARCH64_ARCH_NONE}, | |
9273 | {"ras", AARCH64_FEATURE (AARCH64_FEATURE_RAS, 0), | |
9274 | AARCH64_ARCH_NONE}, | |
9275 | {"rdma", AARCH64_FEATURE (AARCH64_FEATURE_RDMA, 0), | |
9276 | AARCH64_FEATURE (AARCH64_FEATURE_SIMD, 0)}, | |
9277 | {"fp16", AARCH64_FEATURE (AARCH64_FEATURE_F16, 0), | |
9278 | AARCH64_FEATURE (AARCH64_FEATURE_FP, 0)}, | |
d0f7791c TC |
9279 | {"fp16fml", AARCH64_FEATURE (AARCH64_FEATURE_F16_FML, 0), |
9280 | AARCH64_FEATURE (AARCH64_FEATURE_FP | |
9281 | | AARCH64_FEATURE_F16, 0)}, | |
93d8990c SN |
9282 | {"profile", AARCH64_FEATURE (AARCH64_FEATURE_PROFILE, 0), |
9283 | AARCH64_ARCH_NONE}, | |
c0890d26 | 9284 | {"sve", AARCH64_FEATURE (AARCH64_FEATURE_SVE, 0), |
582e12bf RS |
9285 | AARCH64_FEATURE (AARCH64_FEATURE_F16 |
9286 | | AARCH64_FEATURE_SIMD | |
9287 | | AARCH64_FEATURE_COMPNUM, 0)}, | |
b83b4b13 SD |
9288 | {"tme", AARCH64_FEATURE (AARCH64_FEATURE_TME, 0), |
9289 | AARCH64_ARCH_NONE}, | |
f482d304 RS |
9290 | {"compnum", AARCH64_FEATURE (AARCH64_FEATURE_COMPNUM, 0), |
9291 | AARCH64_FEATURE (AARCH64_FEATURE_F16 | |
9292 | | AARCH64_FEATURE_SIMD, 0)}, | |
d74d4880 SN |
9293 | {"rcpc", AARCH64_FEATURE (AARCH64_FEATURE_RCPC, 0), |
9294 | AARCH64_ARCH_NONE}, | |
65a55fbb TC |
9295 | {"dotprod", AARCH64_FEATURE (AARCH64_FEATURE_DOTPROD, 0), |
9296 | AARCH64_ARCH_NONE}, | |
c0e7cef7 NC |
9297 | {"sha2", AARCH64_FEATURE (AARCH64_FEATURE_SHA2, 0), |
9298 | AARCH64_ARCH_NONE}, | |
68dfbb92 SD |
9299 | {"sb", AARCH64_FEATURE (AARCH64_FEATURE_SB, 0), |
9300 | AARCH64_ARCH_NONE}, | |
2ac435d4 SD |
9301 | {"predres", AARCH64_FEATURE (AARCH64_FEATURE_PREDRES, 0), |
9302 | AARCH64_ARCH_NONE}, | |
c0e7cef7 NC |
9303 | {"aes", AARCH64_FEATURE (AARCH64_FEATURE_AES, 0), |
9304 | AARCH64_ARCH_NONE}, | |
b6b9ca0c TC |
9305 | {"sm4", AARCH64_FEATURE (AARCH64_FEATURE_SM4, 0), |
9306 | AARCH64_ARCH_NONE}, | |
d4340f89 JB |
9307 | {"sha3", AARCH64_FEATURE (AARCH64_FEATURE_SHA3, 0), |
9308 | AARCH64_FEATURE (AARCH64_FEATURE_SHA2, 0)}, | |
af4bcb4c SD |
9309 | {"rng", AARCH64_FEATURE (AARCH64_FEATURE_RNG, 0), |
9310 | AARCH64_ARCH_NONE}, | |
104fefee SD |
9311 | {"ssbs", AARCH64_FEATURE (AARCH64_FEATURE_SSBS, 0), |
9312 | AARCH64_ARCH_NONE}, | |
73b605ec SD |
9313 | {"memtag", AARCH64_FEATURE (AARCH64_FEATURE_MEMTAG, 0), |
9314 | AARCH64_ARCH_NONE}, | |
7ce2460a MM |
9315 | {"sve2", AARCH64_FEATURE (AARCH64_FEATURE_SVE2, 0), |
9316 | AARCH64_FEATURE (AARCH64_FEATURE_SVE, 0)}, | |
9317 | {"sve2-sm4", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_SM4, 0), | |
9318 | AARCH64_FEATURE (AARCH64_FEATURE_SVE2 | |
9319 | | AARCH64_FEATURE_SM4, 0)}, | |
9320 | {"sve2-aes", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_AES, 0), | |
9321 | AARCH64_FEATURE (AARCH64_FEATURE_SVE2 | |
9322 | | AARCH64_FEATURE_AES, 0)}, | |
9323 | {"sve2-sha3", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_SHA3, 0), | |
9324 | AARCH64_FEATURE (AARCH64_FEATURE_SVE2 | |
9325 | | AARCH64_FEATURE_SHA3, 0)}, | |
ccbdd22f | 9326 | {"sve2-bitperm", AARCH64_FEATURE (AARCH64_FEATURE_SVE2_BITPERM, 0), |
7ce2460a | 9327 | AARCH64_FEATURE (AARCH64_FEATURE_SVE2, 0)}, |
df678013 MM |
9328 | {"bf16", AARCH64_FEATURE (AARCH64_FEATURE_BFLOAT16, 0), |
9329 | AARCH64_ARCH_NONE}, | |
8382113f MM |
9330 | {"i8mm", AARCH64_FEATURE (AARCH64_FEATURE_I8MM, 0), |
9331 | AARCH64_ARCH_NONE}, | |
9332 | {"f32mm", AARCH64_FEATURE (AARCH64_FEATURE_F32MM, 0), | |
82e9597c | 9333 | AARCH64_FEATURE (AARCH64_FEATURE_SVE, 0)}, |
8382113f | 9334 | {"f64mm", AARCH64_FEATURE (AARCH64_FEATURE_F64MM, 0), |
82e9597c | 9335 | AARCH64_FEATURE (AARCH64_FEATURE_SVE, 0)}, |
3493da5c SP |
9336 | {"a64c", AARCH64_FEATURE (AARCH64_FEATURE_A64C, 0), |
9337 | AARCH64_ARCH_NONE}, | |
9338 | {"c64", AARCH64_FEATURE (AARCH64_FEATURE_C64, 0), | |
9339 | AARCH64_FEATURE (AARCH64_FEATURE_A64C, 0)}, | |
93d8990c | 9340 | {NULL, AARCH64_ARCH_NONE, AARCH64_ARCH_NONE}, |
a06ea964 NC |
9341 | }; |
9342 | ||
9343 | struct aarch64_long_option_table | |
9344 | { | |
e0471c16 TS |
9345 | const char *option; /* Substring to match. */ |
9346 | const char *help; /* Help information. */ | |
17b9d67d | 9347 | int (*func) (const char *subopt); /* Function to decode sub-option. */ |
a06ea964 NC |
9348 | char *deprecated; /* If non-null, print this message. */ |
9349 | }; | |
9350 | ||
93d8990c SN |
9351 | /* Transitive closure of features depending on set. */ |
9352 | static aarch64_feature_set | |
9353 | aarch64_feature_disable_set (aarch64_feature_set set) | |
9354 | { | |
9355 | const struct aarch64_option_cpu_value_table *opt; | |
9356 | aarch64_feature_set prev = 0; | |
9357 | ||
9358 | while (prev != set) { | |
9359 | prev = set; | |
9360 | for (opt = aarch64_features; opt->name != NULL; opt++) | |
9361 | if (AARCH64_CPU_HAS_ANY_FEATURES (opt->require, set)) | |
9362 | AARCH64_MERGE_FEATURE_SETS (set, set, opt->value); | |
9363 | } | |
9364 | return set; | |
9365 | } | |
9366 | ||
9367 | /* Transitive closure of dependencies of set. */ | |
9368 | static aarch64_feature_set | |
9369 | aarch64_feature_enable_set (aarch64_feature_set set) | |
9370 | { | |
9371 | const struct aarch64_option_cpu_value_table *opt; | |
9372 | aarch64_feature_set prev = 0; | |
9373 | ||
9374 | while (prev != set) { | |
9375 | prev = set; | |
9376 | for (opt = aarch64_features; opt->name != NULL; opt++) | |
9377 | if (AARCH64_CPU_HAS_FEATURE (set, opt->value)) | |
9378 | AARCH64_MERGE_FEATURE_SETS (set, set, opt->require); | |
9379 | } | |
9380 | return set; | |
9381 | } | |
9382 | ||
a06ea964 | 9383 | static int |
82b8a785 | 9384 | aarch64_parse_features (const char *str, const aarch64_feature_set **opt_p, |
ae527cd8 | 9385 | bfd_boolean ext_only) |
a06ea964 NC |
9386 | { |
9387 | /* We insist on extensions being added before being removed. We achieve | |
9388 | this by using the ADDING_VALUE variable to indicate whether we are | |
9389 | adding an extension (1) or removing it (0) and only allowing it to | |
9390 | change in the order -1 -> 1 -> 0. */ | |
9391 | int adding_value = -1; | |
325801bd | 9392 | aarch64_feature_set *ext_set = XNEW (aarch64_feature_set); |
a06ea964 NC |
9393 | |
9394 | /* Copy the feature set, so that we can modify it. */ | |
9395 | *ext_set = **opt_p; | |
9396 | *opt_p = ext_set; | |
9397 | ||
9398 | while (str != NULL && *str != 0) | |
9399 | { | |
9400 | const struct aarch64_option_cpu_value_table *opt; | |
82b8a785 | 9401 | const char *ext = NULL; |
a06ea964 NC |
9402 | int optlen; |
9403 | ||
ae527cd8 | 9404 | if (!ext_only) |
a06ea964 | 9405 | { |
ae527cd8 JB |
9406 | if (*str != '+') |
9407 | { | |
9408 | as_bad (_("invalid architectural extension")); | |
9409 | return 0; | |
9410 | } | |
a06ea964 | 9411 | |
ae527cd8 JB |
9412 | ext = strchr (++str, '+'); |
9413 | } | |
a06ea964 NC |
9414 | |
9415 | if (ext != NULL) | |
9416 | optlen = ext - str; | |
9417 | else | |
9418 | optlen = strlen (str); | |
9419 | ||
9420 | if (optlen >= 2 && strncmp (str, "no", 2) == 0) | |
9421 | { | |
9422 | if (adding_value != 0) | |
9423 | adding_value = 0; | |
9424 | optlen -= 2; | |
9425 | str += 2; | |
9426 | } | |
9427 | else if (optlen > 0) | |
9428 | { | |
9429 | if (adding_value == -1) | |
9430 | adding_value = 1; | |
9431 | else if (adding_value != 1) | |
9432 | { | |
9433 | as_bad (_("must specify extensions to add before specifying " | |
9434 | "those to remove")); | |
9435 | return FALSE; | |
9436 | } | |
9437 | } | |
9438 | ||
9439 | if (optlen == 0) | |
9440 | { | |
9441 | as_bad (_("missing architectural extension")); | |
9442 | return 0; | |
9443 | } | |
9444 | ||
9445 | gas_assert (adding_value != -1); | |
9446 | ||
9447 | for (opt = aarch64_features; opt->name != NULL; opt++) | |
9448 | if (strncmp (opt->name, str, optlen) == 0) | |
9449 | { | |
93d8990c SN |
9450 | aarch64_feature_set set; |
9451 | ||
a06ea964 NC |
9452 | /* Add or remove the extension. */ |
9453 | if (adding_value) | |
93d8990c SN |
9454 | { |
9455 | set = aarch64_feature_enable_set (opt->value); | |
9456 | AARCH64_MERGE_FEATURE_SETS (*ext_set, *ext_set, set); | |
9457 | } | |
a06ea964 | 9458 | else |
93d8990c SN |
9459 | { |
9460 | set = aarch64_feature_disable_set (opt->value); | |
9461 | AARCH64_CLEAR_FEATURE (*ext_set, *ext_set, set); | |
9462 | } | |
a06ea964 NC |
9463 | break; |
9464 | } | |
9465 | ||
9466 | if (opt->name == NULL) | |
9467 | { | |
9468 | as_bad (_("unknown architectural extension `%s'"), str); | |
9469 | return 0; | |
9470 | } | |
9471 | ||
9472 | str = ext; | |
9473 | }; | |
9474 | ||
9475 | return 1; | |
9476 | } | |
9477 | ||
9478 | static int | |
17b9d67d | 9479 | aarch64_parse_cpu (const char *str) |
a06ea964 NC |
9480 | { |
9481 | const struct aarch64_cpu_option_table *opt; | |
82b8a785 | 9482 | const char *ext = strchr (str, '+'); |
a06ea964 NC |
9483 | size_t optlen; |
9484 | ||
9485 | if (ext != NULL) | |
9486 | optlen = ext - str; | |
9487 | else | |
9488 | optlen = strlen (str); | |
9489 | ||
9490 | if (optlen == 0) | |
9491 | { | |
9492 | as_bad (_("missing cpu name `%s'"), str); | |
9493 | return 0; | |
9494 | } | |
9495 | ||
9496 | for (opt = aarch64_cpus; opt->name != NULL; opt++) | |
9497 | if (strlen (opt->name) == optlen && strncmp (str, opt->name, optlen) == 0) | |
9498 | { | |
9499 | mcpu_cpu_opt = &opt->value; | |
9500 | if (ext != NULL) | |
ae527cd8 | 9501 | return aarch64_parse_features (ext, &mcpu_cpu_opt, FALSE); |
a06ea964 NC |
9502 | |
9503 | return 1; | |
9504 | } | |
9505 | ||
9506 | as_bad (_("unknown cpu `%s'"), str); | |
9507 | return 0; | |
9508 | } | |
9509 | ||
9510 | static int | |
17b9d67d | 9511 | aarch64_parse_arch (const char *str) |
a06ea964 NC |
9512 | { |
9513 | const struct aarch64_arch_option_table *opt; | |
82b8a785 | 9514 | const char *ext = strchr (str, '+'); |
a06ea964 NC |
9515 | size_t optlen; |
9516 | ||
9517 | if (ext != NULL) | |
9518 | optlen = ext - str; | |
9519 | else | |
9520 | optlen = strlen (str); | |
9521 | ||
9522 | if (optlen == 0) | |
9523 | { | |
9524 | as_bad (_("missing architecture name `%s'"), str); | |
9525 | return 0; | |
9526 | } | |
9527 | ||
9528 | for (opt = aarch64_archs; opt->name != NULL; opt++) | |
9529 | if (strlen (opt->name) == optlen && strncmp (str, opt->name, optlen) == 0) | |
9530 | { | |
9531 | march_cpu_opt = &opt->value; | |
9532 | if (ext != NULL) | |
ae527cd8 | 9533 | return aarch64_parse_features (ext, &march_cpu_opt, FALSE); |
a06ea964 NC |
9534 | |
9535 | return 1; | |
9536 | } | |
9537 | ||
9538 | as_bad (_("unknown architecture `%s'\n"), str); | |
9539 | return 0; | |
9540 | } | |
9541 | ||
69091a2c YZ |
9542 | /* ABIs. */ |
9543 | struct aarch64_option_abi_value_table | |
9544 | { | |
e0471c16 | 9545 | const char *name; |
69091a2c YZ |
9546 | enum aarch64_abi_type value; |
9547 | }; | |
9548 | ||
9549 | static const struct aarch64_option_abi_value_table aarch64_abis[] = { | |
9550 | {"ilp32", AARCH64_ABI_ILP32}, | |
9551 | {"lp64", AARCH64_ABI_LP64}, | |
69091a2c YZ |
9552 | }; |
9553 | ||
9554 | static int | |
17b9d67d | 9555 | aarch64_parse_abi (const char *str) |
69091a2c | 9556 | { |
5703197e | 9557 | unsigned int i; |
69091a2c | 9558 | |
5703197e | 9559 | if (str[0] == '\0') |
69091a2c YZ |
9560 | { |
9561 | as_bad (_("missing abi name `%s'"), str); | |
9562 | return 0; | |
9563 | } | |
9564 | ||
5703197e TS |
9565 | for (i = 0; i < ARRAY_SIZE (aarch64_abis); i++) |
9566 | if (strcmp (str, aarch64_abis[i].name) == 0) | |
69091a2c | 9567 | { |
5703197e | 9568 | aarch64_abi = aarch64_abis[i].value; |
69091a2c YZ |
9569 | return 1; |
9570 | } | |
9571 | ||
9572 | as_bad (_("unknown abi `%s'\n"), str); | |
9573 | return 0; | |
9574 | } | |
9575 | ||
a06ea964 | 9576 | static struct aarch64_long_option_table aarch64_long_opts[] = { |
69091a2c YZ |
9577 | #ifdef OBJ_ELF |
9578 | {"mabi=", N_("<abi name>\t specify for ABI <abi name>"), | |
9579 | aarch64_parse_abi, NULL}, | |
9580 | #endif /* OBJ_ELF */ | |
a06ea964 NC |
9581 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), |
9582 | aarch64_parse_cpu, NULL}, | |
9583 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
9584 | aarch64_parse_arch, NULL}, | |
9585 | {NULL, NULL, 0, NULL} | |
9586 | }; | |
9587 | ||
9588 | int | |
17b9d67d | 9589 | md_parse_option (int c, const char *arg) |
a06ea964 NC |
9590 | { |
9591 | struct aarch64_option_table *opt; | |
9592 | struct aarch64_long_option_table *lopt; | |
9593 | ||
9594 | switch (c) | |
9595 | { | |
9596 | #ifdef OPTION_EB | |
9597 | case OPTION_EB: | |
9598 | target_big_endian = 1; | |
9599 | break; | |
9600 | #endif | |
9601 | ||
9602 | #ifdef OPTION_EL | |
9603 | case OPTION_EL: | |
9604 | target_big_endian = 0; | |
9605 | break; | |
9606 | #endif | |
9607 | ||
9608 | case 'a': | |
9609 | /* Listing option. Just ignore these, we don't support additional | |
9610 | ones. */ | |
9611 | return 0; | |
9612 | ||
9613 | default: | |
9614 | for (opt = aarch64_opts; opt->option != NULL; opt++) | |
9615 | { | |
9616 | if (c == opt->option[0] | |
9617 | && ((arg == NULL && opt->option[1] == 0) | |
9618 | || streq (arg, opt->option + 1))) | |
9619 | { | |
9620 | /* If the option is deprecated, tell the user. */ | |
9621 | if (opt->deprecated != NULL) | |
9622 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
9623 | arg ? arg : "", _(opt->deprecated)); | |
9624 | ||
9625 | if (opt->var != NULL) | |
9626 | *opt->var = opt->value; | |
9627 | ||
9628 | return 1; | |
9629 | } | |
9630 | } | |
9631 | ||
9632 | for (lopt = aarch64_long_opts; lopt->option != NULL; lopt++) | |
9633 | { | |
9634 | /* These options are expected to have an argument. */ | |
9635 | if (c == lopt->option[0] | |
9636 | && arg != NULL | |
9637 | && strncmp (arg, lopt->option + 1, | |
9638 | strlen (lopt->option + 1)) == 0) | |
9639 | { | |
9640 | /* If the option is deprecated, tell the user. */ | |
9641 | if (lopt->deprecated != NULL) | |
9642 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, | |
9643 | _(lopt->deprecated)); | |
9644 | ||
9645 | /* Call the sup-option parser. */ | |
9646 | return lopt->func (arg + strlen (lopt->option) - 1); | |
9647 | } | |
9648 | } | |
9649 | ||
9650 | return 0; | |
9651 | } | |
9652 | ||
9653 | return 1; | |
9654 | } | |
9655 | ||
9656 | void | |
9657 | md_show_usage (FILE * fp) | |
9658 | { | |
9659 | struct aarch64_option_table *opt; | |
9660 | struct aarch64_long_option_table *lopt; | |
9661 | ||
9662 | fprintf (fp, _(" AArch64-specific assembler options:\n")); | |
9663 | ||
9664 | for (opt = aarch64_opts; opt->option != NULL; opt++) | |
9665 | if (opt->help != NULL) | |
9666 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
9667 | ||
9668 | for (lopt = aarch64_long_opts; lopt->option != NULL; lopt++) | |
9669 | if (lopt->help != NULL) | |
9670 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
9671 | ||
9672 | #ifdef OPTION_EB | |
9673 | fprintf (fp, _("\ | |
9674 | -EB assemble code for a big-endian cpu\n")); | |
9675 | #endif | |
9676 | ||
9677 | #ifdef OPTION_EL | |
9678 | fprintf (fp, _("\ | |
9679 | -EL assemble code for a little-endian cpu\n")); | |
9680 | #endif | |
9681 | } | |
9682 | ||
9683 | /* Parse a .cpu directive. */ | |
9684 | ||
9685 | static void | |
9686 | s_aarch64_cpu (int ignored ATTRIBUTE_UNUSED) | |
9687 | { | |
9688 | const struct aarch64_cpu_option_table *opt; | |
9689 | char saved_char; | |
9690 | char *name; | |
9691 | char *ext; | |
9692 | size_t optlen; | |
9693 | ||
9694 | name = input_line_pointer; | |
9695 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
9696 | input_line_pointer++; | |
9697 | saved_char = *input_line_pointer; | |
9698 | *input_line_pointer = 0; | |
9699 | ||
9700 | ext = strchr (name, '+'); | |
9701 | ||
9702 | if (ext != NULL) | |
9703 | optlen = ext - name; | |
9704 | else | |
9705 | optlen = strlen (name); | |
9706 | ||
9707 | /* Skip the first "all" entry. */ | |
9708 | for (opt = aarch64_cpus + 1; opt->name != NULL; opt++) | |
9709 | if (strlen (opt->name) == optlen | |
9710 | && strncmp (name, opt->name, optlen) == 0) | |
9711 | { | |
9712 | mcpu_cpu_opt = &opt->value; | |
9713 | if (ext != NULL) | |
ae527cd8 | 9714 | if (!aarch64_parse_features (ext, &mcpu_cpu_opt, FALSE)) |
a06ea964 NC |
9715 | return; |
9716 | ||
9717 | cpu_variant = *mcpu_cpu_opt; | |
9718 | ||
9719 | *input_line_pointer = saved_char; | |
9720 | demand_empty_rest_of_line (); | |
9721 | return; | |
9722 | } | |
9723 | as_bad (_("unknown cpu `%s'"), name); | |
9724 | *input_line_pointer = saved_char; | |
9725 | ignore_rest_of_line (); | |
9726 | } | |
9727 | ||
9728 | ||
9729 | /* Parse a .arch directive. */ | |
9730 | ||
9731 | static void | |
9732 | s_aarch64_arch (int ignored ATTRIBUTE_UNUSED) | |
9733 | { | |
9734 | const struct aarch64_arch_option_table *opt; | |
9735 | char saved_char; | |
9736 | char *name; | |
9737 | char *ext; | |
9738 | size_t optlen; | |
9739 | ||
9740 | name = input_line_pointer; | |
9741 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
9742 | input_line_pointer++; | |
9743 | saved_char = *input_line_pointer; | |
9744 | *input_line_pointer = 0; | |
9745 | ||
9746 | ext = strchr (name, '+'); | |
9747 | ||
9748 | if (ext != NULL) | |
9749 | optlen = ext - name; | |
9750 | else | |
9751 | optlen = strlen (name); | |
9752 | ||
9753 | /* Skip the first "all" entry. */ | |
9754 | for (opt = aarch64_archs + 1; opt->name != NULL; opt++) | |
9755 | if (strlen (opt->name) == optlen | |
9756 | && strncmp (name, opt->name, optlen) == 0) | |
9757 | { | |
9758 | mcpu_cpu_opt = &opt->value; | |
9759 | if (ext != NULL) | |
ae527cd8 | 9760 | if (!aarch64_parse_features (ext, &mcpu_cpu_opt, FALSE)) |
a06ea964 NC |
9761 | return; |
9762 | ||
9763 | cpu_variant = *mcpu_cpu_opt; | |
9764 | ||
9765 | *input_line_pointer = saved_char; | |
9766 | demand_empty_rest_of_line (); | |
9767 | return; | |
9768 | } | |
9769 | ||
9770 | as_bad (_("unknown architecture `%s'\n"), name); | |
9771 | *input_line_pointer = saved_char; | |
9772 | ignore_rest_of_line (); | |
9773 | } | |
9774 | ||
ae527cd8 JB |
9775 | /* Parse a .arch_extension directive. */ |
9776 | ||
9777 | static void | |
9778 | s_aarch64_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
9779 | { | |
9780 | char saved_char; | |
9781 | char *ext = input_line_pointer;; | |
9782 | ||
9783 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
9784 | input_line_pointer++; | |
9785 | saved_char = *input_line_pointer; | |
9786 | *input_line_pointer = 0; | |
9787 | ||
9788 | if (!aarch64_parse_features (ext, &mcpu_cpu_opt, TRUE)) | |
9789 | return; | |
9790 | ||
9791 | cpu_variant = *mcpu_cpu_opt; | |
9792 | ||
9793 | *input_line_pointer = saved_char; | |
9794 | demand_empty_rest_of_line (); | |
9795 | } | |
9796 | ||
a06ea964 NC |
9797 | /* Copy symbol information. */ |
9798 | ||
9799 | void | |
9800 | aarch64_copy_symbol_attributes (symbolS * dest, symbolS * src) | |
9801 | { | |
9802 | AARCH64_GET_FLAG (dest) = AARCH64_GET_FLAG (src); | |
9803 | } | |
0b4eac57 SN |
9804 | |
9805 | #ifdef OBJ_ELF | |
9806 | /* Same as elf_copy_symbol_attributes, but without copying st_other. | |
9807 | This is needed so AArch64 specific st_other values can be independently | |
9808 | specified for an IFUNC resolver (that is called by the dynamic linker) | |
9809 | and the symbol it resolves (aliased to the resolver). In particular, | |
9810 | if a function symbol has special st_other value set via directives, | |
9811 | then attaching an IFUNC resolver to that symbol should not override | |
9812 | the st_other setting. Requiring the directive on the IFUNC resolver | |
9813 | symbol would be unexpected and problematic in C code, where the two | |
9814 | symbols appear as two independent function declarations. */ | |
9815 | ||
9816 | void | |
9817 | aarch64_elf_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
9818 | { | |
9819 | struct elf_obj_sy *srcelf = symbol_get_obj (src); | |
9820 | struct elf_obj_sy *destelf = symbol_get_obj (dest); | |
9821 | if (srcelf->size) | |
9822 | { | |
9823 | if (destelf->size == NULL) | |
9824 | destelf->size = XNEW (expressionS); | |
9825 | *destelf->size = *srcelf->size; | |
9826 | } | |
9827 | else | |
9828 | { | |
9fbb53c7 | 9829 | free (destelf->size); |
0b4eac57 SN |
9830 | destelf->size = NULL; |
9831 | } | |
9832 | S_SET_SIZE (dest, S_GET_SIZE (src)); | |
9833 | } | |
9834 | #endif |