| 1 | /* tc-aarch64.c -- Assemble for the AArch64 ISA |
| 2 | |
| 3 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
| 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" |
| 30 | |
| 31 | #ifdef OBJ_ELF |
| 32 | #include "elf/aarch64.h" |
| 33 | #include "dw2gencfi.h" |
| 34 | #endif |
| 35 | |
| 36 | #include "dwarf2dbg.h" |
| 37 | |
| 38 | /* Types of processor to assemble for. */ |
| 39 | #ifndef CPU_DEFAULT |
| 40 | #define CPU_DEFAULT AARCH64_ARCH_V8 |
| 41 | #endif |
| 42 | |
| 43 | #define streq(a, b) (strcmp (a, b) == 0) |
| 44 | |
| 45 | #define END_OF_INSN '\0' |
| 46 | |
| 47 | static aarch64_feature_set cpu_variant; |
| 48 | |
| 49 | /* Variables that we set while parsing command-line options. Once all |
| 50 | options have been read we re-process these values to set the real |
| 51 | assembly flags. */ |
| 52 | static const aarch64_feature_set *mcpu_cpu_opt = NULL; |
| 53 | static const aarch64_feature_set *march_cpu_opt = NULL; |
| 54 | |
| 55 | /* Constants for known architecture features. */ |
| 56 | static const aarch64_feature_set cpu_default = CPU_DEFAULT; |
| 57 | |
| 58 | #ifdef OBJ_ELF |
| 59 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
| 60 | static symbolS *GOT_symbol; |
| 61 | |
| 62 | /* Which ABI to use. */ |
| 63 | enum aarch64_abi_type |
| 64 | { |
| 65 | AARCH64_ABI_LP64 = 0, |
| 66 | AARCH64_ABI_ILP32 = 1 |
| 67 | }; |
| 68 | |
| 69 | /* AArch64 ABI for the output file. */ |
| 70 | static enum aarch64_abi_type aarch64_abi = AARCH64_ABI_LP64; |
| 71 | |
| 72 | /* When non-zero, program to a 32-bit model, in which the C data types |
| 73 | int, long and all pointer types are 32-bit objects (ILP32); or to a |
| 74 | 64-bit model, in which the C int type is 32-bits but the C long type |
| 75 | and all pointer types are 64-bit objects (LP64). */ |
| 76 | #define ilp32_p (aarch64_abi == AARCH64_ABI_ILP32) |
| 77 | #endif |
| 78 | |
| 79 | enum neon_el_type |
| 80 | { |
| 81 | NT_invtype = -1, |
| 82 | NT_b, |
| 83 | NT_h, |
| 84 | NT_s, |
| 85 | NT_d, |
| 86 | NT_q |
| 87 | }; |
| 88 | |
| 89 | /* Bits for DEFINED field in neon_type_el. */ |
| 90 | #define NTA_HASTYPE 1 |
| 91 | #define NTA_HASINDEX 2 |
| 92 | |
| 93 | struct neon_type_el |
| 94 | { |
| 95 | enum neon_el_type type; |
| 96 | unsigned char defined; |
| 97 | unsigned width; |
| 98 | int64_t index; |
| 99 | }; |
| 100 | |
| 101 | #define FIXUP_F_HAS_EXPLICIT_SHIFT 0x00000001 |
| 102 | |
| 103 | struct reloc |
| 104 | { |
| 105 | bfd_reloc_code_real_type type; |
| 106 | expressionS exp; |
| 107 | int pc_rel; |
| 108 | enum aarch64_opnd opnd; |
| 109 | uint32_t flags; |
| 110 | unsigned need_libopcodes_p : 1; |
| 111 | }; |
| 112 | |
| 113 | struct aarch64_instruction |
| 114 | { |
| 115 | /* libopcodes structure for instruction intermediate representation. */ |
| 116 | aarch64_inst base; |
| 117 | /* Record assembly errors found during the parsing. */ |
| 118 | struct |
| 119 | { |
| 120 | enum aarch64_operand_error_kind kind; |
| 121 | const char *error; |
| 122 | } parsing_error; |
| 123 | /* The condition that appears in the assembly line. */ |
| 124 | int cond; |
| 125 | /* Relocation information (including the GAS internal fixup). */ |
| 126 | struct reloc reloc; |
| 127 | /* Need to generate an immediate in the literal pool. */ |
| 128 | unsigned gen_lit_pool : 1; |
| 129 | }; |
| 130 | |
| 131 | typedef struct aarch64_instruction aarch64_instruction; |
| 132 | |
| 133 | static aarch64_instruction inst; |
| 134 | |
| 135 | static bfd_boolean parse_operands (char *, const aarch64_opcode *); |
| 136 | static bfd_boolean programmer_friendly_fixup (aarch64_instruction *); |
| 137 | |
| 138 | /* Diagnostics inline function utilites. |
| 139 | |
| 140 | These are lightweight utlities which should only be called by parse_operands |
| 141 | and other parsers. GAS processes each assembly line by parsing it against |
| 142 | instruction template(s), in the case of multiple templates (for the same |
| 143 | mnemonic name), those templates are tried one by one until one succeeds or |
| 144 | all fail. An assembly line may fail a few templates before being |
| 145 | successfully parsed; an error saved here in most cases is not a user error |
| 146 | but an error indicating the current template is not the right template. |
| 147 | Therefore it is very important that errors can be saved at a low cost during |
| 148 | the parsing; we don't want to slow down the whole parsing by recording |
| 149 | non-user errors in detail. |
| 150 | |
| 151 | Remember that the objective is to help GAS pick up the most approapriate |
| 152 | error message in the case of multiple templates, e.g. FMOV which has 8 |
| 153 | templates. */ |
| 154 | |
| 155 | static inline void |
| 156 | clear_error (void) |
| 157 | { |
| 158 | inst.parsing_error.kind = AARCH64_OPDE_NIL; |
| 159 | inst.parsing_error.error = NULL; |
| 160 | } |
| 161 | |
| 162 | static inline bfd_boolean |
| 163 | error_p (void) |
| 164 | { |
| 165 | return inst.parsing_error.kind != AARCH64_OPDE_NIL; |
| 166 | } |
| 167 | |
| 168 | static inline const char * |
| 169 | get_error_message (void) |
| 170 | { |
| 171 | return inst.parsing_error.error; |
| 172 | } |
| 173 | |
| 174 | static inline enum aarch64_operand_error_kind |
| 175 | get_error_kind (void) |
| 176 | { |
| 177 | return inst.parsing_error.kind; |
| 178 | } |
| 179 | |
| 180 | static inline void |
| 181 | set_error (enum aarch64_operand_error_kind kind, const char *error) |
| 182 | { |
| 183 | inst.parsing_error.kind = kind; |
| 184 | inst.parsing_error.error = error; |
| 185 | } |
| 186 | |
| 187 | static inline void |
| 188 | set_recoverable_error (const char *error) |
| 189 | { |
| 190 | set_error (AARCH64_OPDE_RECOVERABLE, error); |
| 191 | } |
| 192 | |
| 193 | /* Use the DESC field of the corresponding aarch64_operand entry to compose |
| 194 | the error message. */ |
| 195 | static inline void |
| 196 | set_default_error (void) |
| 197 | { |
| 198 | set_error (AARCH64_OPDE_SYNTAX_ERROR, NULL); |
| 199 | } |
| 200 | |
| 201 | static inline void |
| 202 | set_syntax_error (const char *error) |
| 203 | { |
| 204 | set_error (AARCH64_OPDE_SYNTAX_ERROR, error); |
| 205 | } |
| 206 | |
| 207 | static inline void |
| 208 | set_first_syntax_error (const char *error) |
| 209 | { |
| 210 | if (! error_p ()) |
| 211 | set_error (AARCH64_OPDE_SYNTAX_ERROR, error); |
| 212 | } |
| 213 | |
| 214 | static inline void |
| 215 | set_fatal_syntax_error (const char *error) |
| 216 | { |
| 217 | set_error (AARCH64_OPDE_FATAL_SYNTAX_ERROR, error); |
| 218 | } |
| 219 | \f |
| 220 | /* Number of littlenums required to hold an extended precision number. */ |
| 221 | #define MAX_LITTLENUMS 6 |
| 222 | |
| 223 | /* Return value for certain parsers when the parsing fails; those parsers |
| 224 | return the information of the parsed result, e.g. register number, on |
| 225 | success. */ |
| 226 | #define PARSE_FAIL -1 |
| 227 | |
| 228 | /* This is an invalid condition code that means no conditional field is |
| 229 | present. */ |
| 230 | #define COND_ALWAYS 0x10 |
| 231 | |
| 232 | typedef struct |
| 233 | { |
| 234 | const char *template; |
| 235 | unsigned long value; |
| 236 | } asm_barrier_opt; |
| 237 | |
| 238 | typedef struct |
| 239 | { |
| 240 | const char *template; |
| 241 | uint32_t value; |
| 242 | } asm_nzcv; |
| 243 | |
| 244 | struct reloc_entry |
| 245 | { |
| 246 | char *name; |
| 247 | bfd_reloc_code_real_type reloc; |
| 248 | }; |
| 249 | |
| 250 | /* Structure for a hash table entry for a register. */ |
| 251 | typedef struct |
| 252 | { |
| 253 | const char *name; |
| 254 | unsigned char number; |
| 255 | unsigned char type; |
| 256 | unsigned char builtin; |
| 257 | } reg_entry; |
| 258 | |
| 259 | /* Macros to define the register types and masks for the purpose |
| 260 | of parsing. */ |
| 261 | |
| 262 | #undef AARCH64_REG_TYPES |
| 263 | #define AARCH64_REG_TYPES \ |
| 264 | BASIC_REG_TYPE(R_32) /* w[0-30] */ \ |
| 265 | BASIC_REG_TYPE(R_64) /* x[0-30] */ \ |
| 266 | BASIC_REG_TYPE(SP_32) /* wsp */ \ |
| 267 | BASIC_REG_TYPE(SP_64) /* sp */ \ |
| 268 | BASIC_REG_TYPE(Z_32) /* wzr */ \ |
| 269 | BASIC_REG_TYPE(Z_64) /* xzr */ \ |
| 270 | BASIC_REG_TYPE(FP_B) /* b[0-31] *//* NOTE: keep FP_[BHSDQ] consecutive! */\ |
| 271 | BASIC_REG_TYPE(FP_H) /* h[0-31] */ \ |
| 272 | BASIC_REG_TYPE(FP_S) /* s[0-31] */ \ |
| 273 | BASIC_REG_TYPE(FP_D) /* d[0-31] */ \ |
| 274 | BASIC_REG_TYPE(FP_Q) /* q[0-31] */ \ |
| 275 | BASIC_REG_TYPE(CN) /* c[0-7] */ \ |
| 276 | BASIC_REG_TYPE(VN) /* v[0-31] */ \ |
| 277 | /* Typecheck: any 64-bit int reg (inc SP exc XZR) */ \ |
| 278 | MULTI_REG_TYPE(R64_SP, REG_TYPE(R_64) | REG_TYPE(SP_64)) \ |
| 279 | /* Typecheck: any int (inc {W}SP inc [WX]ZR) */ \ |
| 280 | MULTI_REG_TYPE(R_Z_SP, REG_TYPE(R_32) | REG_TYPE(R_64) \ |
| 281 | | REG_TYPE(SP_32) | REG_TYPE(SP_64) \ |
| 282 | | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \ |
| 283 | /* Typecheck: any [BHSDQ]P FP. */ \ |
| 284 | MULTI_REG_TYPE(BHSDQ, REG_TYPE(FP_B) | REG_TYPE(FP_H) \ |
| 285 | | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q)) \ |
| 286 | /* Typecheck: any int or [BHSDQ]P FP or V reg (exc SP inc [WX]ZR) */ \ |
| 287 | MULTI_REG_TYPE(R_Z_BHSDQ_V, REG_TYPE(R_32) | REG_TYPE(R_64) \ |
| 288 | | REG_TYPE(Z_32) | REG_TYPE(Z_64) | REG_TYPE(VN) \ |
| 289 | | REG_TYPE(FP_B) | REG_TYPE(FP_H) \ |
| 290 | | REG_TYPE(FP_S) | REG_TYPE(FP_D) | REG_TYPE(FP_Q)) \ |
| 291 | /* Any integer register; used for error messages only. */ \ |
| 292 | MULTI_REG_TYPE(R_N, REG_TYPE(R_32) | REG_TYPE(R_64) \ |
| 293 | | REG_TYPE(SP_32) | REG_TYPE(SP_64) \ |
| 294 | | REG_TYPE(Z_32) | REG_TYPE(Z_64)) \ |
| 295 | /* Pseudo type to mark the end of the enumerator sequence. */ \ |
| 296 | BASIC_REG_TYPE(MAX) |
| 297 | |
| 298 | #undef BASIC_REG_TYPE |
| 299 | #define BASIC_REG_TYPE(T) REG_TYPE_##T, |
| 300 | #undef MULTI_REG_TYPE |
| 301 | #define MULTI_REG_TYPE(T,V) BASIC_REG_TYPE(T) |
| 302 | |
| 303 | /* Register type enumerators. */ |
| 304 | typedef enum |
| 305 | { |
| 306 | /* A list of REG_TYPE_*. */ |
| 307 | AARCH64_REG_TYPES |
| 308 | } aarch64_reg_type; |
| 309 | |
| 310 | #undef BASIC_REG_TYPE |
| 311 | #define BASIC_REG_TYPE(T) 1 << REG_TYPE_##T, |
| 312 | #undef REG_TYPE |
| 313 | #define REG_TYPE(T) (1 << REG_TYPE_##T) |
| 314 | #undef MULTI_REG_TYPE |
| 315 | #define MULTI_REG_TYPE(T,V) V, |
| 316 | |
| 317 | /* Values indexed by aarch64_reg_type to assist the type checking. */ |
| 318 | static const unsigned reg_type_masks[] = |
| 319 | { |
| 320 | AARCH64_REG_TYPES |
| 321 | }; |
| 322 | |
| 323 | #undef BASIC_REG_TYPE |
| 324 | #undef REG_TYPE |
| 325 | #undef MULTI_REG_TYPE |
| 326 | #undef AARCH64_REG_TYPES |
| 327 | |
| 328 | /* Diagnostics used when we don't get a register of the expected type. |
| 329 | Note: this has to synchronized with aarch64_reg_type definitions |
| 330 | above. */ |
| 331 | static const char * |
| 332 | get_reg_expected_msg (aarch64_reg_type reg_type) |
| 333 | { |
| 334 | const char *msg; |
| 335 | |
| 336 | switch (reg_type) |
| 337 | { |
| 338 | case REG_TYPE_R_32: |
| 339 | msg = N_("integer 32-bit register expected"); |
| 340 | break; |
| 341 | case REG_TYPE_R_64: |
| 342 | msg = N_("integer 64-bit register expected"); |
| 343 | break; |
| 344 | case REG_TYPE_R_N: |
| 345 | msg = N_("integer register expected"); |
| 346 | break; |
| 347 | case REG_TYPE_R_Z_SP: |
| 348 | msg = N_("integer, zero or SP register expected"); |
| 349 | break; |
| 350 | case REG_TYPE_FP_B: |
| 351 | msg = N_("8-bit SIMD scalar register expected"); |
| 352 | break; |
| 353 | case REG_TYPE_FP_H: |
| 354 | msg = N_("16-bit SIMD scalar or floating-point half precision " |
| 355 | "register expected"); |
| 356 | break; |
| 357 | case REG_TYPE_FP_S: |
| 358 | msg = N_("32-bit SIMD scalar or floating-point single precision " |
| 359 | "register expected"); |
| 360 | break; |
| 361 | case REG_TYPE_FP_D: |
| 362 | msg = N_("64-bit SIMD scalar or floating-point double precision " |
| 363 | "register expected"); |
| 364 | break; |
| 365 | case REG_TYPE_FP_Q: |
| 366 | msg = N_("128-bit SIMD scalar or floating-point quad precision " |
| 367 | "register expected"); |
| 368 | break; |
| 369 | case REG_TYPE_CN: |
| 370 | msg = N_("C0 - C15 expected"); |
| 371 | break; |
| 372 | case REG_TYPE_R_Z_BHSDQ_V: |
| 373 | msg = N_("register expected"); |
| 374 | break; |
| 375 | case REG_TYPE_BHSDQ: /* any [BHSDQ]P FP */ |
| 376 | msg = N_("SIMD scalar or floating-point register expected"); |
| 377 | break; |
| 378 | case REG_TYPE_VN: /* any V reg */ |
| 379 | msg = N_("vector register expected"); |
| 380 | break; |
| 381 | default: |
| 382 | as_fatal (_("invalid register type %d"), reg_type); |
| 383 | } |
| 384 | return msg; |
| 385 | } |
| 386 | |
| 387 | /* Some well known registers that we refer to directly elsewhere. */ |
| 388 | #define REG_SP 31 |
| 389 | |
| 390 | /* Instructions take 4 bytes in the object file. */ |
| 391 | #define INSN_SIZE 4 |
| 392 | |
| 393 | /* Define some common error messages. */ |
| 394 | #define BAD_SP _("SP not allowed here") |
| 395 | |
| 396 | static struct hash_control *aarch64_ops_hsh; |
| 397 | static struct hash_control *aarch64_cond_hsh; |
| 398 | static struct hash_control *aarch64_shift_hsh; |
| 399 | static struct hash_control *aarch64_sys_regs_hsh; |
| 400 | static struct hash_control *aarch64_pstatefield_hsh; |
| 401 | static struct hash_control *aarch64_sys_regs_ic_hsh; |
| 402 | static struct hash_control *aarch64_sys_regs_dc_hsh; |
| 403 | static struct hash_control *aarch64_sys_regs_at_hsh; |
| 404 | static struct hash_control *aarch64_sys_regs_tlbi_hsh; |
| 405 | static struct hash_control *aarch64_reg_hsh; |
| 406 | static struct hash_control *aarch64_barrier_opt_hsh; |
| 407 | static struct hash_control *aarch64_nzcv_hsh; |
| 408 | static struct hash_control *aarch64_pldop_hsh; |
| 409 | |
| 410 | /* Stuff needed to resolve the label ambiguity |
| 411 | As: |
| 412 | ... |
| 413 | label: <insn> |
| 414 | may differ from: |
| 415 | ... |
| 416 | label: |
| 417 | <insn> */ |
| 418 | |
| 419 | static symbolS *last_label_seen; |
| 420 | |
| 421 | /* Literal pool structure. Held on a per-section |
| 422 | and per-sub-section basis. */ |
| 423 | |
| 424 | #define MAX_LITERAL_POOL_SIZE 1024 |
| 425 | typedef struct literal_expression |
| 426 | { |
| 427 | expressionS exp; |
| 428 | /* If exp.op == O_big then this bignum holds a copy of the global bignum value. */ |
| 429 | LITTLENUM_TYPE * bignum; |
| 430 | } literal_expression; |
| 431 | |
| 432 | typedef struct literal_pool |
| 433 | { |
| 434 | literal_expression literals[MAX_LITERAL_POOL_SIZE]; |
| 435 | unsigned int next_free_entry; |
| 436 | unsigned int id; |
| 437 | symbolS *symbol; |
| 438 | segT section; |
| 439 | subsegT sub_section; |
| 440 | int size; |
| 441 | struct literal_pool *next; |
| 442 | } literal_pool; |
| 443 | |
| 444 | /* Pointer to a linked list of literal pools. */ |
| 445 | static literal_pool *list_of_pools = NULL; |
| 446 | \f |
| 447 | /* Pure syntax. */ |
| 448 | |
| 449 | /* This array holds the chars that always start a comment. If the |
| 450 | pre-processor is disabled, these aren't very useful. */ |
| 451 | const char comment_chars[] = ""; |
| 452 | |
| 453 | /* This array holds the chars that only start a comment at the beginning of |
| 454 | a line. If the line seems to have the form '# 123 filename' |
| 455 | .line and .file directives will appear in the pre-processed output. */ |
| 456 | /* Note that input_file.c hand checks for '#' at the beginning of the |
| 457 | first line of the input file. This is because the compiler outputs |
| 458 | #NO_APP at the beginning of its output. */ |
| 459 | /* Also note that comments like this one will always work. */ |
| 460 | const char line_comment_chars[] = "#"; |
| 461 | |
| 462 | const char line_separator_chars[] = ";"; |
| 463 | |
| 464 | /* Chars that can be used to separate mant |
| 465 | from exp in floating point numbers. */ |
| 466 | const char EXP_CHARS[] = "eE"; |
| 467 | |
| 468 | /* Chars that mean this number is a floating point constant. */ |
| 469 | /* As in 0f12.456 */ |
| 470 | /* or 0d1.2345e12 */ |
| 471 | |
| 472 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
| 473 | |
| 474 | /* Prefix character that indicates the start of an immediate value. */ |
| 475 | #define is_immediate_prefix(C) ((C) == '#') |
| 476 | |
| 477 | /* Separator character handling. */ |
| 478 | |
| 479 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) |
| 480 | |
| 481 | static inline bfd_boolean |
| 482 | skip_past_char (char **str, char c) |
| 483 | { |
| 484 | if (**str == c) |
| 485 | { |
| 486 | (*str)++; |
| 487 | return TRUE; |
| 488 | } |
| 489 | else |
| 490 | return FALSE; |
| 491 | } |
| 492 | |
| 493 | #define skip_past_comma(str) skip_past_char (str, ',') |
| 494 | |
| 495 | /* Arithmetic expressions (possibly involving symbols). */ |
| 496 | |
| 497 | static bfd_boolean in_my_get_expression_p = FALSE; |
| 498 | |
| 499 | /* Third argument to my_get_expression. */ |
| 500 | #define GE_NO_PREFIX 0 |
| 501 | #define GE_OPT_PREFIX 1 |
| 502 | |
| 503 | /* Return TRUE if the string pointed by *STR is successfully parsed |
| 504 | as an valid expression; *EP will be filled with the information of |
| 505 | such an expression. Otherwise return FALSE. */ |
| 506 | |
| 507 | static bfd_boolean |
| 508 | my_get_expression (expressionS * ep, char **str, int prefix_mode, |
| 509 | int reject_absent) |
| 510 | { |
| 511 | char *save_in; |
| 512 | segT seg; |
| 513 | int prefix_present_p = 0; |
| 514 | |
| 515 | switch (prefix_mode) |
| 516 | { |
| 517 | case GE_NO_PREFIX: |
| 518 | break; |
| 519 | case GE_OPT_PREFIX: |
| 520 | if (is_immediate_prefix (**str)) |
| 521 | { |
| 522 | (*str)++; |
| 523 | prefix_present_p = 1; |
| 524 | } |
| 525 | break; |
| 526 | default: |
| 527 | abort (); |
| 528 | } |
| 529 | |
| 530 | memset (ep, 0, sizeof (expressionS)); |
| 531 | |
| 532 | save_in = input_line_pointer; |
| 533 | input_line_pointer = *str; |
| 534 | in_my_get_expression_p = TRUE; |
| 535 | seg = expression (ep); |
| 536 | in_my_get_expression_p = FALSE; |
| 537 | |
| 538 | if (ep->X_op == O_illegal || (reject_absent && ep->X_op == O_absent)) |
| 539 | { |
| 540 | /* We found a bad expression in md_operand(). */ |
| 541 | *str = input_line_pointer; |
| 542 | input_line_pointer = save_in; |
| 543 | if (prefix_present_p && ! error_p ()) |
| 544 | set_fatal_syntax_error (_("bad expression")); |
| 545 | else |
| 546 | set_first_syntax_error (_("bad expression")); |
| 547 | return FALSE; |
| 548 | } |
| 549 | |
| 550 | #ifdef OBJ_AOUT |
| 551 | if (seg != absolute_section |
| 552 | && seg != text_section |
| 553 | && seg != data_section |
| 554 | && seg != bss_section && seg != undefined_section) |
| 555 | { |
| 556 | set_syntax_error (_("bad segment")); |
| 557 | *str = input_line_pointer; |
| 558 | input_line_pointer = save_in; |
| 559 | return FALSE; |
| 560 | } |
| 561 | #else |
| 562 | (void) seg; |
| 563 | #endif |
| 564 | |
| 565 | *str = input_line_pointer; |
| 566 | input_line_pointer = save_in; |
| 567 | return TRUE; |
| 568 | } |
| 569 | |
| 570 | /* Turn a string in input_line_pointer into a floating point constant |
| 571 | of type TYPE, and store the appropriate bytes in *LITP. The number |
| 572 | of LITTLENUMS emitted is stored in *SIZEP. An error message is |
| 573 | returned, or NULL on OK. */ |
| 574 | |
| 575 | char * |
| 576 | md_atof (int type, char *litP, int *sizeP) |
| 577 | { |
| 578 | return ieee_md_atof (type, litP, sizeP, target_big_endian); |
| 579 | } |
| 580 | |
| 581 | /* We handle all bad expressions here, so that we can report the faulty |
| 582 | instruction in the error message. */ |
| 583 | void |
| 584 | md_operand (expressionS * exp) |
| 585 | { |
| 586 | if (in_my_get_expression_p) |
| 587 | exp->X_op = O_illegal; |
| 588 | } |
| 589 | |
| 590 | /* Immediate values. */ |
| 591 | |
| 592 | /* Errors may be set multiple times during parsing or bit encoding |
| 593 | (particularly in the Neon bits), but usually the earliest error which is set |
| 594 | will be the most meaningful. Avoid overwriting it with later (cascading) |
| 595 | errors by calling this function. */ |
| 596 | |
| 597 | static void |
| 598 | first_error (const char *error) |
| 599 | { |
| 600 | if (! error_p ()) |
| 601 | set_syntax_error (error); |
| 602 | } |
| 603 | |
| 604 | /* Similiar to first_error, but this function accepts formatted error |
| 605 | message. */ |
| 606 | static void |
| 607 | first_error_fmt (const char *format, ...) |
| 608 | { |
| 609 | va_list args; |
| 610 | enum |
| 611 | { size = 100 }; |
| 612 | /* N.B. this single buffer will not cause error messages for different |
| 613 | instructions to pollute each other; this is because at the end of |
| 614 | processing of each assembly line, error message if any will be |
| 615 | collected by as_bad. */ |
| 616 | static char buffer[size]; |
| 617 | |
| 618 | if (! error_p ()) |
| 619 | { |
| 620 | int ret ATTRIBUTE_UNUSED; |
| 621 | va_start (args, format); |
| 622 | ret = vsnprintf (buffer, size, format, args); |
| 623 | know (ret <= size - 1 && ret >= 0); |
| 624 | va_end (args); |
| 625 | set_syntax_error (buffer); |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | /* Register parsing. */ |
| 630 | |
| 631 | /* Generic register parser which is called by other specialized |
| 632 | register parsers. |
| 633 | CCP points to what should be the beginning of a register name. |
| 634 | If it is indeed a valid register name, advance CCP over it and |
| 635 | return the reg_entry structure; otherwise return NULL. |
| 636 | It does not issue diagnostics. */ |
| 637 | |
| 638 | static reg_entry * |
| 639 | parse_reg (char **ccp) |
| 640 | { |
| 641 | char *start = *ccp; |
| 642 | char *p; |
| 643 | reg_entry *reg; |
| 644 | |
| 645 | #ifdef REGISTER_PREFIX |
| 646 | if (*start != REGISTER_PREFIX) |
| 647 | return NULL; |
| 648 | start++; |
| 649 | #endif |
| 650 | |
| 651 | p = start; |
| 652 | if (!ISALPHA (*p) || !is_name_beginner (*p)) |
| 653 | return NULL; |
| 654 | |
| 655 | do |
| 656 | p++; |
| 657 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); |
| 658 | |
| 659 | reg = (reg_entry *) hash_find_n (aarch64_reg_hsh, start, p - start); |
| 660 | |
| 661 | if (!reg) |
| 662 | return NULL; |
| 663 | |
| 664 | *ccp = p; |
| 665 | return reg; |
| 666 | } |
| 667 | |
| 668 | /* Return TRUE if REG->TYPE is a valid type of TYPE; otherwise |
| 669 | return FALSE. */ |
| 670 | static bfd_boolean |
| 671 | aarch64_check_reg_type (const reg_entry *reg, aarch64_reg_type type) |
| 672 | { |
| 673 | if (reg->type == type) |
| 674 | return TRUE; |
| 675 | |
| 676 | switch (type) |
| 677 | { |
| 678 | case REG_TYPE_R64_SP: /* 64-bit integer reg (inc SP exc XZR). */ |
| 679 | case REG_TYPE_R_Z_SP: /* Integer reg (inc {X}SP inc [WX]ZR). */ |
| 680 | case REG_TYPE_R_Z_BHSDQ_V: /* Any register apart from Cn. */ |
| 681 | case REG_TYPE_BHSDQ: /* Any [BHSDQ]P FP or SIMD scalar register. */ |
| 682 | case REG_TYPE_VN: /* Vector register. */ |
| 683 | gas_assert (reg->type < REG_TYPE_MAX && type < REG_TYPE_MAX); |
| 684 | return ((reg_type_masks[reg->type] & reg_type_masks[type]) |
| 685 | == reg_type_masks[reg->type]); |
| 686 | default: |
| 687 | as_fatal ("unhandled type %d", type); |
| 688 | abort (); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /* Parse a register and return PARSE_FAIL if the register is not of type R_Z_SP. |
| 693 | Return the register number otherwise. *ISREG32 is set to one if the |
| 694 | register is 32-bit wide; *ISREGZERO is set to one if the register is |
| 695 | of type Z_32 or Z_64. |
| 696 | Note that this function does not issue any diagnostics. */ |
| 697 | |
| 698 | static int |
| 699 | aarch64_reg_parse_32_64 (char **ccp, int reject_sp, int reject_rz, |
| 700 | int *isreg32, int *isregzero) |
| 701 | { |
| 702 | char *str = *ccp; |
| 703 | const reg_entry *reg = parse_reg (&str); |
| 704 | |
| 705 | if (reg == NULL) |
| 706 | return PARSE_FAIL; |
| 707 | |
| 708 | if (! aarch64_check_reg_type (reg, REG_TYPE_R_Z_SP)) |
| 709 | return PARSE_FAIL; |
| 710 | |
| 711 | switch (reg->type) |
| 712 | { |
| 713 | case REG_TYPE_SP_32: |
| 714 | case REG_TYPE_SP_64: |
| 715 | if (reject_sp) |
| 716 | return PARSE_FAIL; |
| 717 | *isreg32 = reg->type == REG_TYPE_SP_32; |
| 718 | *isregzero = 0; |
| 719 | break; |
| 720 | case REG_TYPE_R_32: |
| 721 | case REG_TYPE_R_64: |
| 722 | *isreg32 = reg->type == REG_TYPE_R_32; |
| 723 | *isregzero = 0; |
| 724 | break; |
| 725 | case REG_TYPE_Z_32: |
| 726 | case REG_TYPE_Z_64: |
| 727 | if (reject_rz) |
| 728 | return PARSE_FAIL; |
| 729 | *isreg32 = reg->type == REG_TYPE_Z_32; |
| 730 | *isregzero = 1; |
| 731 | break; |
| 732 | default: |
| 733 | return PARSE_FAIL; |
| 734 | } |
| 735 | |
| 736 | *ccp = str; |
| 737 | |
| 738 | return reg->number; |
| 739 | } |
| 740 | |
| 741 | /* Parse the qualifier of a SIMD vector register or a SIMD vector element. |
| 742 | Fill in *PARSED_TYPE and return TRUE if the parsing succeeds; |
| 743 | otherwise return FALSE. |
| 744 | |
| 745 | Accept only one occurrence of: |
| 746 | 8b 16b 4h 8h 2s 4s 1d 2d |
| 747 | b h s d q */ |
| 748 | static bfd_boolean |
| 749 | parse_neon_type_for_operand (struct neon_type_el *parsed_type, char **str) |
| 750 | { |
| 751 | char *ptr = *str; |
| 752 | unsigned width; |
| 753 | unsigned element_size; |
| 754 | enum neon_el_type type; |
| 755 | |
| 756 | /* skip '.' */ |
| 757 | ptr++; |
| 758 | |
| 759 | if (!ISDIGIT (*ptr)) |
| 760 | { |
| 761 | width = 0; |
| 762 | goto elt_size; |
| 763 | } |
| 764 | width = strtoul (ptr, &ptr, 10); |
| 765 | if (width != 1 && width != 2 && width != 4 && width != 8 && width != 16) |
| 766 | { |
| 767 | first_error_fmt (_("bad size %d in vector width specifier"), width); |
| 768 | return FALSE; |
| 769 | } |
| 770 | |
| 771 | elt_size: |
| 772 | switch (TOLOWER (*ptr)) |
| 773 | { |
| 774 | case 'b': |
| 775 | type = NT_b; |
| 776 | element_size = 8; |
| 777 | break; |
| 778 | case 'h': |
| 779 | type = NT_h; |
| 780 | element_size = 16; |
| 781 | break; |
| 782 | case 's': |
| 783 | type = NT_s; |
| 784 | element_size = 32; |
| 785 | break; |
| 786 | case 'd': |
| 787 | type = NT_d; |
| 788 | element_size = 64; |
| 789 | break; |
| 790 | case 'q': |
| 791 | if (width == 1) |
| 792 | { |
| 793 | type = NT_q; |
| 794 | element_size = 128; |
| 795 | break; |
| 796 | } |
| 797 | /* fall through. */ |
| 798 | default: |
| 799 | if (*ptr != '\0') |
| 800 | first_error_fmt (_("unexpected character `%c' in element size"), *ptr); |
| 801 | else |
| 802 | first_error (_("missing element size")); |
| 803 | return FALSE; |
| 804 | } |
| 805 | if (width != 0 && width * element_size != 64 && width * element_size != 128) |
| 806 | { |
| 807 | first_error_fmt (_ |
| 808 | ("invalid element size %d and vector size combination %c"), |
| 809 | width, *ptr); |
| 810 | return FALSE; |
| 811 | } |
| 812 | ptr++; |
| 813 | |
| 814 | parsed_type->type = type; |
| 815 | parsed_type->width = width; |
| 816 | |
| 817 | *str = ptr; |
| 818 | |
| 819 | return TRUE; |
| 820 | } |
| 821 | |
| 822 | /* Parse a single type, e.g. ".8b", leading period included. |
| 823 | Only applicable to Vn registers. |
| 824 | |
| 825 | Return TRUE on success; otherwise return FALSE. */ |
| 826 | static bfd_boolean |
| 827 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) |
| 828 | { |
| 829 | char *str = *ccp; |
| 830 | |
| 831 | if (*str == '.') |
| 832 | { |
| 833 | if (! parse_neon_type_for_operand (vectype, &str)) |
| 834 | { |
| 835 | first_error (_("vector type expected")); |
| 836 | return FALSE; |
| 837 | } |
| 838 | } |
| 839 | else |
| 840 | return FALSE; |
| 841 | |
| 842 | *ccp = str; |
| 843 | |
| 844 | return TRUE; |
| 845 | } |
| 846 | |
| 847 | /* Parse a register of the type TYPE. |
| 848 | |
| 849 | Return PARSE_FAIL if the string pointed by *CCP is not a valid register |
| 850 | name or the parsed register is not of TYPE. |
| 851 | |
| 852 | Otherwise return the register number, and optionally fill in the actual |
| 853 | type of the register in *RTYPE when multiple alternatives were given, and |
| 854 | return the register shape and element index information in *TYPEINFO. |
| 855 | |
| 856 | IN_REG_LIST should be set with TRUE if the caller is parsing a register |
| 857 | list. */ |
| 858 | |
| 859 | static int |
| 860 | parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, |
| 861 | struct neon_type_el *typeinfo, bfd_boolean in_reg_list) |
| 862 | { |
| 863 | char *str = *ccp; |
| 864 | const reg_entry *reg = parse_reg (&str); |
| 865 | struct neon_type_el atype; |
| 866 | struct neon_type_el parsetype; |
| 867 | bfd_boolean is_typed_vecreg = FALSE; |
| 868 | |
| 869 | atype.defined = 0; |
| 870 | atype.type = NT_invtype; |
| 871 | atype.width = -1; |
| 872 | atype.index = 0; |
| 873 | |
| 874 | if (reg == NULL) |
| 875 | { |
| 876 | if (typeinfo) |
| 877 | *typeinfo = atype; |
| 878 | set_default_error (); |
| 879 | return PARSE_FAIL; |
| 880 | } |
| 881 | |
| 882 | if (! aarch64_check_reg_type (reg, type)) |
| 883 | { |
| 884 | DEBUG_TRACE ("reg type check failed"); |
| 885 | set_default_error (); |
| 886 | return PARSE_FAIL; |
| 887 | } |
| 888 | type = reg->type; |
| 889 | |
| 890 | if (type == REG_TYPE_VN |
| 891 | && parse_neon_operand_type (&parsetype, &str)) |
| 892 | { |
| 893 | /* Register if of the form Vn.[bhsdq]. */ |
| 894 | is_typed_vecreg = TRUE; |
| 895 | |
| 896 | if (parsetype.width == 0) |
| 897 | /* Expect index. In the new scheme we cannot have |
| 898 | Vn.[bhsdq] represent a scalar. Therefore any |
| 899 | Vn.[bhsdq] should have an index following it. |
| 900 | Except in reglists ofcourse. */ |
| 901 | atype.defined |= NTA_HASINDEX; |
| 902 | else |
| 903 | atype.defined |= NTA_HASTYPE; |
| 904 | |
| 905 | atype.type = parsetype.type; |
| 906 | atype.width = parsetype.width; |
| 907 | } |
| 908 | |
| 909 | if (skip_past_char (&str, '[')) |
| 910 | { |
| 911 | expressionS exp; |
| 912 | |
| 913 | /* Reject Sn[index] syntax. */ |
| 914 | if (!is_typed_vecreg) |
| 915 | { |
| 916 | first_error (_("this type of register can't be indexed")); |
| 917 | return PARSE_FAIL; |
| 918 | } |
| 919 | |
| 920 | if (in_reg_list == TRUE) |
| 921 | { |
| 922 | first_error (_("index not allowed inside register list")); |
| 923 | return PARSE_FAIL; |
| 924 | } |
| 925 | |
| 926 | atype.defined |= NTA_HASINDEX; |
| 927 | |
| 928 | my_get_expression (&exp, &str, GE_NO_PREFIX, 1); |
| 929 | |
| 930 | if (exp.X_op != O_constant) |
| 931 | { |
| 932 | first_error (_("constant expression required")); |
| 933 | return PARSE_FAIL; |
| 934 | } |
| 935 | |
| 936 | if (! skip_past_char (&str, ']')) |
| 937 | return PARSE_FAIL; |
| 938 | |
| 939 | atype.index = exp.X_add_number; |
| 940 | } |
| 941 | else if (!in_reg_list && (atype.defined & NTA_HASINDEX) != 0) |
| 942 | { |
| 943 | /* Indexed vector register expected. */ |
| 944 | first_error (_("indexed vector register expected")); |
| 945 | return PARSE_FAIL; |
| 946 | } |
| 947 | |
| 948 | /* A vector reg Vn should be typed or indexed. */ |
| 949 | if (type == REG_TYPE_VN && atype.defined == 0) |
| 950 | { |
| 951 | first_error (_("invalid use of vector register")); |
| 952 | } |
| 953 | |
| 954 | if (typeinfo) |
| 955 | *typeinfo = atype; |
| 956 | |
| 957 | if (rtype) |
| 958 | *rtype = type; |
| 959 | |
| 960 | *ccp = str; |
| 961 | |
| 962 | return reg->number; |
| 963 | } |
| 964 | |
| 965 | /* Parse register. |
| 966 | |
| 967 | Return the register number on success; return PARSE_FAIL otherwise. |
| 968 | |
| 969 | If RTYPE is not NULL, return in *RTYPE the (possibly restricted) type of |
| 970 | the register (e.g. NEON double or quad reg when either has been requested). |
| 971 | |
| 972 | If this is a NEON vector register with additional type information, fill |
| 973 | in the struct pointed to by VECTYPE (if non-NULL). |
| 974 | |
| 975 | This parser does not handle register list. */ |
| 976 | |
| 977 | static int |
| 978 | aarch64_reg_parse (char **ccp, aarch64_reg_type type, |
| 979 | aarch64_reg_type *rtype, struct neon_type_el *vectype) |
| 980 | { |
| 981 | struct neon_type_el atype; |
| 982 | char *str = *ccp; |
| 983 | int reg = parse_typed_reg (&str, type, rtype, &atype, |
| 984 | /*in_reg_list= */ FALSE); |
| 985 | |
| 986 | if (reg == PARSE_FAIL) |
| 987 | return PARSE_FAIL; |
| 988 | |
| 989 | if (vectype) |
| 990 | *vectype = atype; |
| 991 | |
| 992 | *ccp = str; |
| 993 | |
| 994 | return reg; |
| 995 | } |
| 996 | |
| 997 | static inline bfd_boolean |
| 998 | eq_neon_type_el (struct neon_type_el e1, struct neon_type_el e2) |
| 999 | { |
| 1000 | return |
| 1001 | e1.type == e2.type |
| 1002 | && e1.defined == e2.defined |
| 1003 | && e1.width == e2.width && e1.index == e2.index; |
| 1004 | } |
| 1005 | |
| 1006 | /* This function parses the NEON register list. On success, it returns |
| 1007 | the parsed register list information in the following encoded format: |
| 1008 | |
| 1009 | bit 18-22 | 13-17 | 7-11 | 2-6 | 0-1 |
| 1010 | 4th regno | 3rd regno | 2nd regno | 1st regno | num_of_reg |
| 1011 | |
| 1012 | The information of the register shape and/or index is returned in |
| 1013 | *VECTYPE. |
| 1014 | |
| 1015 | It returns PARSE_FAIL if the register list is invalid. |
| 1016 | |
| 1017 | The list contains one to four registers. |
| 1018 | Each register can be one of: |
| 1019 | <Vt>.<T>[<index>] |
| 1020 | <Vt>.<T> |
| 1021 | All <T> should be identical. |
| 1022 | All <index> should be identical. |
| 1023 | There are restrictions on <Vt> numbers which are checked later |
| 1024 | (by reg_list_valid_p). */ |
| 1025 | |
| 1026 | static int |
| 1027 | parse_neon_reg_list (char **ccp, struct neon_type_el *vectype) |
| 1028 | { |
| 1029 | char *str = *ccp; |
| 1030 | int nb_regs; |
| 1031 | struct neon_type_el typeinfo, typeinfo_first; |
| 1032 | int val, val_range; |
| 1033 | int in_range; |
| 1034 | int ret_val; |
| 1035 | int i; |
| 1036 | bfd_boolean error = FALSE; |
| 1037 | bfd_boolean expect_index = FALSE; |
| 1038 | |
| 1039 | if (*str != '{') |
| 1040 | { |
| 1041 | set_syntax_error (_("expecting {")); |
| 1042 | return PARSE_FAIL; |
| 1043 | } |
| 1044 | str++; |
| 1045 | |
| 1046 | nb_regs = 0; |
| 1047 | typeinfo_first.defined = 0; |
| 1048 | typeinfo_first.type = NT_invtype; |
| 1049 | typeinfo_first.width = -1; |
| 1050 | typeinfo_first.index = 0; |
| 1051 | ret_val = 0; |
| 1052 | val = -1; |
| 1053 | val_range = -1; |
| 1054 | in_range = 0; |
| 1055 | do |
| 1056 | { |
| 1057 | if (in_range) |
| 1058 | { |
| 1059 | str++; /* skip over '-' */ |
| 1060 | val_range = val; |
| 1061 | } |
| 1062 | val = parse_typed_reg (&str, REG_TYPE_VN, NULL, &typeinfo, |
| 1063 | /*in_reg_list= */ TRUE); |
| 1064 | if (val == PARSE_FAIL) |
| 1065 | { |
| 1066 | set_first_syntax_error (_("invalid vector register in list")); |
| 1067 | error = TRUE; |
| 1068 | continue; |
| 1069 | } |
| 1070 | /* reject [bhsd]n */ |
| 1071 | if (typeinfo.defined == 0) |
| 1072 | { |
| 1073 | set_first_syntax_error (_("invalid scalar register in list")); |
| 1074 | error = TRUE; |
| 1075 | continue; |
| 1076 | } |
| 1077 | |
| 1078 | if (typeinfo.defined & NTA_HASINDEX) |
| 1079 | expect_index = TRUE; |
| 1080 | |
| 1081 | if (in_range) |
| 1082 | { |
| 1083 | if (val < val_range) |
| 1084 | { |
| 1085 | set_first_syntax_error |
| 1086 | (_("invalid range in vector register list")); |
| 1087 | error = TRUE; |
| 1088 | } |
| 1089 | val_range++; |
| 1090 | } |
| 1091 | else |
| 1092 | { |
| 1093 | val_range = val; |
| 1094 | if (nb_regs == 0) |
| 1095 | typeinfo_first = typeinfo; |
| 1096 | else if (! eq_neon_type_el (typeinfo_first, typeinfo)) |
| 1097 | { |
| 1098 | set_first_syntax_error |
| 1099 | (_("type mismatch in vector register list")); |
| 1100 | error = TRUE; |
| 1101 | } |
| 1102 | } |
| 1103 | if (! error) |
| 1104 | for (i = val_range; i <= val; i++) |
| 1105 | { |
| 1106 | ret_val |= i << (5 * nb_regs); |
| 1107 | nb_regs++; |
| 1108 | } |
| 1109 | in_range = 0; |
| 1110 | } |
| 1111 | while (skip_past_comma (&str) || (in_range = 1, *str == '-')); |
| 1112 | |
| 1113 | skip_whitespace (str); |
| 1114 | if (*str != '}') |
| 1115 | { |
| 1116 | set_first_syntax_error (_("end of vector register list not found")); |
| 1117 | error = TRUE; |
| 1118 | } |
| 1119 | str++; |
| 1120 | |
| 1121 | skip_whitespace (str); |
| 1122 | |
| 1123 | if (expect_index) |
| 1124 | { |
| 1125 | if (skip_past_char (&str, '[')) |
| 1126 | { |
| 1127 | expressionS exp; |
| 1128 | |
| 1129 | my_get_expression (&exp, &str, GE_NO_PREFIX, 1); |
| 1130 | if (exp.X_op != O_constant) |
| 1131 | { |
| 1132 | set_first_syntax_error (_("constant expression required.")); |
| 1133 | error = TRUE; |
| 1134 | } |
| 1135 | if (! skip_past_char (&str, ']')) |
| 1136 | error = TRUE; |
| 1137 | else |
| 1138 | typeinfo_first.index = exp.X_add_number; |
| 1139 | } |
| 1140 | else |
| 1141 | { |
| 1142 | set_first_syntax_error (_("expected index")); |
| 1143 | error = TRUE; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | if (nb_regs > 4) |
| 1148 | { |
| 1149 | set_first_syntax_error (_("too many registers in vector register list")); |
| 1150 | error = TRUE; |
| 1151 | } |
| 1152 | else if (nb_regs == 0) |
| 1153 | { |
| 1154 | set_first_syntax_error (_("empty vector register list")); |
| 1155 | error = TRUE; |
| 1156 | } |
| 1157 | |
| 1158 | *ccp = str; |
| 1159 | if (! error) |
| 1160 | *vectype = typeinfo_first; |
| 1161 | |
| 1162 | return error ? PARSE_FAIL : (ret_val << 2) | (nb_regs - 1); |
| 1163 | } |
| 1164 | |
| 1165 | /* Directives: register aliases. */ |
| 1166 | |
| 1167 | static reg_entry * |
| 1168 | insert_reg_alias (char *str, int number, aarch64_reg_type type) |
| 1169 | { |
| 1170 | reg_entry *new; |
| 1171 | const char *name; |
| 1172 | |
| 1173 | if ((new = hash_find (aarch64_reg_hsh, str)) != 0) |
| 1174 | { |
| 1175 | if (new->builtin) |
| 1176 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), |
| 1177 | str); |
| 1178 | |
| 1179 | /* Only warn about a redefinition if it's not defined as the |
| 1180 | same register. */ |
| 1181 | else if (new->number != number || new->type != type) |
| 1182 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
| 1183 | |
| 1184 | return NULL; |
| 1185 | } |
| 1186 | |
| 1187 | name = xstrdup (str); |
| 1188 | new = xmalloc (sizeof (reg_entry)); |
| 1189 | |
| 1190 | new->name = name; |
| 1191 | new->number = number; |
| 1192 | new->type = type; |
| 1193 | new->builtin = FALSE; |
| 1194 | |
| 1195 | if (hash_insert (aarch64_reg_hsh, name, (void *) new)) |
| 1196 | abort (); |
| 1197 | |
| 1198 | return new; |
| 1199 | } |
| 1200 | |
| 1201 | /* Look for the .req directive. This is of the form: |
| 1202 | |
| 1203 | new_register_name .req existing_register_name |
| 1204 | |
| 1205 | If we find one, or if it looks sufficiently like one that we want to |
| 1206 | handle any error here, return TRUE. Otherwise return FALSE. */ |
| 1207 | |
| 1208 | static bfd_boolean |
| 1209 | create_register_alias (char *newname, char *p) |
| 1210 | { |
| 1211 | const reg_entry *old; |
| 1212 | char *oldname, *nbuf; |
| 1213 | size_t nlen; |
| 1214 | |
| 1215 | /* The input scrubber ensures that whitespace after the mnemonic is |
| 1216 | collapsed to single spaces. */ |
| 1217 | oldname = p; |
| 1218 | if (strncmp (oldname, " .req ", 6) != 0) |
| 1219 | return FALSE; |
| 1220 | |
| 1221 | oldname += 6; |
| 1222 | if (*oldname == '\0') |
| 1223 | return FALSE; |
| 1224 | |
| 1225 | old = hash_find (aarch64_reg_hsh, oldname); |
| 1226 | if (!old) |
| 1227 | { |
| 1228 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
| 1229 | return TRUE; |
| 1230 | } |
| 1231 | |
| 1232 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
| 1233 | the desired alias name, and p points to its end. If not, then |
| 1234 | the desired alias name is in the global original_case_string. */ |
| 1235 | #ifdef TC_CASE_SENSITIVE |
| 1236 | nlen = p - newname; |
| 1237 | #else |
| 1238 | newname = original_case_string; |
| 1239 | nlen = strlen (newname); |
| 1240 | #endif |
| 1241 | |
| 1242 | nbuf = alloca (nlen + 1); |
| 1243 | memcpy (nbuf, newname, nlen); |
| 1244 | nbuf[nlen] = '\0'; |
| 1245 | |
| 1246 | /* Create aliases under the new name as stated; an all-lowercase |
| 1247 | version of the new name; and an all-uppercase version of the new |
| 1248 | name. */ |
| 1249 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
| 1250 | { |
| 1251 | for (p = nbuf; *p; p++) |
| 1252 | *p = TOUPPER (*p); |
| 1253 | |
| 1254 | if (strncmp (nbuf, newname, nlen)) |
| 1255 | { |
| 1256 | /* If this attempt to create an additional alias fails, do not bother |
| 1257 | trying to create the all-lower case alias. We will fail and issue |
| 1258 | a second, duplicate error message. This situation arises when the |
| 1259 | programmer does something like: |
| 1260 | foo .req r0 |
| 1261 | Foo .req r1 |
| 1262 | The second .req creates the "Foo" alias but then fails to create |
| 1263 | the artificial FOO alias because it has already been created by the |
| 1264 | first .req. */ |
| 1265 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) |
| 1266 | return TRUE; |
| 1267 | } |
| 1268 | |
| 1269 | for (p = nbuf; *p; p++) |
| 1270 | *p = TOLOWER (*p); |
| 1271 | |
| 1272 | if (strncmp (nbuf, newname, nlen)) |
| 1273 | insert_reg_alias (nbuf, old->number, old->type); |
| 1274 | } |
| 1275 | |
| 1276 | return TRUE; |
| 1277 | } |
| 1278 | |
| 1279 | /* Should never be called, as .req goes between the alias and the |
| 1280 | register name, not at the beginning of the line. */ |
| 1281 | static void |
| 1282 | s_req (int a ATTRIBUTE_UNUSED) |
| 1283 | { |
| 1284 | as_bad (_("invalid syntax for .req directive")); |
| 1285 | } |
| 1286 | |
| 1287 | /* The .unreq directive deletes an alias which was previously defined |
| 1288 | by .req. For example: |
| 1289 | |
| 1290 | my_alias .req r11 |
| 1291 | .unreq my_alias */ |
| 1292 | |
| 1293 | static void |
| 1294 | s_unreq (int a ATTRIBUTE_UNUSED) |
| 1295 | { |
| 1296 | char *name; |
| 1297 | char saved_char; |
| 1298 | |
| 1299 | name = input_line_pointer; |
| 1300 | |
| 1301 | while (*input_line_pointer != 0 |
| 1302 | && *input_line_pointer != ' ' && *input_line_pointer != '\n') |
| 1303 | ++input_line_pointer; |
| 1304 | |
| 1305 | saved_char = *input_line_pointer; |
| 1306 | *input_line_pointer = 0; |
| 1307 | |
| 1308 | if (!*name) |
| 1309 | as_bad (_("invalid syntax for .unreq directive")); |
| 1310 | else |
| 1311 | { |
| 1312 | reg_entry *reg = hash_find (aarch64_reg_hsh, name); |
| 1313 | |
| 1314 | if (!reg) |
| 1315 | as_bad (_("unknown register alias '%s'"), name); |
| 1316 | else if (reg->builtin) |
| 1317 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), |
| 1318 | name); |
| 1319 | else |
| 1320 | { |
| 1321 | char *p; |
| 1322 | char *nbuf; |
| 1323 | |
| 1324 | hash_delete (aarch64_reg_hsh, name, FALSE); |
| 1325 | free ((char *) reg->name); |
| 1326 | free (reg); |
| 1327 | |
| 1328 | /* Also locate the all upper case and all lower case versions. |
| 1329 | Do not complain if we cannot find one or the other as it |
| 1330 | was probably deleted above. */ |
| 1331 | |
| 1332 | nbuf = strdup (name); |
| 1333 | for (p = nbuf; *p; p++) |
| 1334 | *p = TOUPPER (*p); |
| 1335 | reg = hash_find (aarch64_reg_hsh, nbuf); |
| 1336 | if (reg) |
| 1337 | { |
| 1338 | hash_delete (aarch64_reg_hsh, nbuf, FALSE); |
| 1339 | free ((char *) reg->name); |
| 1340 | free (reg); |
| 1341 | } |
| 1342 | |
| 1343 | for (p = nbuf; *p; p++) |
| 1344 | *p = TOLOWER (*p); |
| 1345 | reg = hash_find (aarch64_reg_hsh, nbuf); |
| 1346 | if (reg) |
| 1347 | { |
| 1348 | hash_delete (aarch64_reg_hsh, nbuf, FALSE); |
| 1349 | free ((char *) reg->name); |
| 1350 | free (reg); |
| 1351 | } |
| 1352 | |
| 1353 | free (nbuf); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | *input_line_pointer = saved_char; |
| 1358 | demand_empty_rest_of_line (); |
| 1359 | } |
| 1360 | |
| 1361 | /* Directives: Instruction set selection. */ |
| 1362 | |
| 1363 | #ifdef OBJ_ELF |
| 1364 | /* This code is to handle mapping symbols as defined in the ARM AArch64 ELF |
| 1365 | spec. (See "Mapping symbols", section 4.5.4, ARM AAELF64 version 0.05). |
| 1366 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), |
| 1367 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ |
| 1368 | |
| 1369 | /* Create a new mapping symbol for the transition to STATE. */ |
| 1370 | |
| 1371 | static void |
| 1372 | make_mapping_symbol (enum mstate state, valueT value, fragS * frag) |
| 1373 | { |
| 1374 | symbolS *symbolP; |
| 1375 | const char *symname; |
| 1376 | int type; |
| 1377 | |
| 1378 | switch (state) |
| 1379 | { |
| 1380 | case MAP_DATA: |
| 1381 | symname = "$d"; |
| 1382 | type = BSF_NO_FLAGS; |
| 1383 | break; |
| 1384 | case MAP_INSN: |
| 1385 | symname = "$x"; |
| 1386 | type = BSF_NO_FLAGS; |
| 1387 | break; |
| 1388 | default: |
| 1389 | abort (); |
| 1390 | } |
| 1391 | |
| 1392 | symbolP = symbol_new (symname, now_seg, value, frag); |
| 1393 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
| 1394 | |
| 1395 | /* Save the mapping symbols for future reference. Also check that |
| 1396 | we do not place two mapping symbols at the same offset within a |
| 1397 | frag. We'll handle overlap between frags in |
| 1398 | check_mapping_symbols. |
| 1399 | |
| 1400 | If .fill or other data filling directive generates zero sized data, |
| 1401 | the mapping symbol for the following code will have the same value |
| 1402 | as the one generated for the data filling directive. In this case, |
| 1403 | we replace the old symbol with the new one at the same address. */ |
| 1404 | if (value == 0) |
| 1405 | { |
| 1406 | if (frag->tc_frag_data.first_map != NULL) |
| 1407 | { |
| 1408 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); |
| 1409 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, |
| 1410 | &symbol_lastP); |
| 1411 | } |
| 1412 | frag->tc_frag_data.first_map = symbolP; |
| 1413 | } |
| 1414 | if (frag->tc_frag_data.last_map != NULL) |
| 1415 | { |
| 1416 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= |
| 1417 | S_GET_VALUE (symbolP)); |
| 1418 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
| 1419 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, |
| 1420 | &symbol_lastP); |
| 1421 | } |
| 1422 | frag->tc_frag_data.last_map = symbolP; |
| 1423 | } |
| 1424 | |
| 1425 | /* We must sometimes convert a region marked as code to data during |
| 1426 | code alignment, if an odd number of bytes have to be padded. The |
| 1427 | code mapping symbol is pushed to an aligned address. */ |
| 1428 | |
| 1429 | static void |
| 1430 | insert_data_mapping_symbol (enum mstate state, |
| 1431 | valueT value, fragS * frag, offsetT bytes) |
| 1432 | { |
| 1433 | /* If there was already a mapping symbol, remove it. */ |
| 1434 | if (frag->tc_frag_data.last_map != NULL |
| 1435 | && S_GET_VALUE (frag->tc_frag_data.last_map) == |
| 1436 | frag->fr_address + value) |
| 1437 | { |
| 1438 | symbolS *symp = frag->tc_frag_data.last_map; |
| 1439 | |
| 1440 | if (value == 0) |
| 1441 | { |
| 1442 | know (frag->tc_frag_data.first_map == symp); |
| 1443 | frag->tc_frag_data.first_map = NULL; |
| 1444 | } |
| 1445 | frag->tc_frag_data.last_map = NULL; |
| 1446 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); |
| 1447 | } |
| 1448 | |
| 1449 | make_mapping_symbol (MAP_DATA, value, frag); |
| 1450 | make_mapping_symbol (state, value + bytes, frag); |
| 1451 | } |
| 1452 | |
| 1453 | static void mapping_state_2 (enum mstate state, int max_chars); |
| 1454 | |
| 1455 | /* Set the mapping state to STATE. Only call this when about to |
| 1456 | emit some STATE bytes to the file. */ |
| 1457 | |
| 1458 | void |
| 1459 | mapping_state (enum mstate state) |
| 1460 | { |
| 1461 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
| 1462 | |
| 1463 | if (state == MAP_INSN) |
| 1464 | /* AArch64 instructions require 4-byte alignment. When emitting |
| 1465 | instructions into any section, record the appropriate section |
| 1466 | alignment. */ |
| 1467 | record_alignment (now_seg, 2); |
| 1468 | |
| 1469 | if (mapstate == state) |
| 1470 | /* The mapping symbol has already been emitted. |
| 1471 | There is nothing else to do. */ |
| 1472 | return; |
| 1473 | |
| 1474 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
| 1475 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA) && !subseg_text_p (now_seg)) |
| 1476 | /* Emit MAP_DATA within executable section in order. Otherwise, it will be |
| 1477 | evaluated later in the next else. */ |
| 1478 | return; |
| 1479 | else if (TRANSITION (MAP_UNDEFINED, MAP_INSN)) |
| 1480 | { |
| 1481 | /* Only add the symbol if the offset is > 0: |
| 1482 | if we're at the first frag, check it's size > 0; |
| 1483 | if we're not at the first frag, then for sure |
| 1484 | the offset is > 0. */ |
| 1485 | struct frag *const frag_first = seg_info (now_seg)->frchainP->frch_root; |
| 1486 | const int add_symbol = (frag_now != frag_first) |
| 1487 | || (frag_now_fix () > 0); |
| 1488 | |
| 1489 | if (add_symbol) |
| 1490 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); |
| 1491 | } |
| 1492 | #undef TRANSITION |
| 1493 | |
| 1494 | mapping_state_2 (state, 0); |
| 1495 | } |
| 1496 | |
| 1497 | /* Same as mapping_state, but MAX_CHARS bytes have already been |
| 1498 | allocated. Put the mapping symbol that far back. */ |
| 1499 | |
| 1500 | static void |
| 1501 | mapping_state_2 (enum mstate state, int max_chars) |
| 1502 | { |
| 1503 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
| 1504 | |
| 1505 | if (!SEG_NORMAL (now_seg)) |
| 1506 | return; |
| 1507 | |
| 1508 | if (mapstate == state) |
| 1509 | /* The mapping symbol has already been emitted. |
| 1510 | There is nothing else to do. */ |
| 1511 | return; |
| 1512 | |
| 1513 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
| 1514 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); |
| 1515 | } |
| 1516 | #else |
| 1517 | #define mapping_state(x) /* nothing */ |
| 1518 | #define mapping_state_2(x, y) /* nothing */ |
| 1519 | #endif |
| 1520 | |
| 1521 | /* Directives: sectioning and alignment. */ |
| 1522 | |
| 1523 | static void |
| 1524 | s_bss (int ignore ATTRIBUTE_UNUSED) |
| 1525 | { |
| 1526 | /* We don't support putting frags in the BSS segment, we fake it by |
| 1527 | marking in_bss, then looking at s_skip for clues. */ |
| 1528 | subseg_set (bss_section, 0); |
| 1529 | demand_empty_rest_of_line (); |
| 1530 | mapping_state (MAP_DATA); |
| 1531 | } |
| 1532 | |
| 1533 | static void |
| 1534 | s_even (int ignore ATTRIBUTE_UNUSED) |
| 1535 | { |
| 1536 | /* Never make frag if expect extra pass. */ |
| 1537 | if (!need_pass_2) |
| 1538 | frag_align (1, 0, 0); |
| 1539 | |
| 1540 | record_alignment (now_seg, 1); |
| 1541 | |
| 1542 | demand_empty_rest_of_line (); |
| 1543 | } |
| 1544 | |
| 1545 | /* Directives: Literal pools. */ |
| 1546 | |
| 1547 | static literal_pool * |
| 1548 | find_literal_pool (int size) |
| 1549 | { |
| 1550 | literal_pool *pool; |
| 1551 | |
| 1552 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
| 1553 | { |
| 1554 | if (pool->section == now_seg |
| 1555 | && pool->sub_section == now_subseg && pool->size == size) |
| 1556 | break; |
| 1557 | } |
| 1558 | |
| 1559 | return pool; |
| 1560 | } |
| 1561 | |
| 1562 | static literal_pool * |
| 1563 | find_or_make_literal_pool (int size) |
| 1564 | { |
| 1565 | /* Next literal pool ID number. */ |
| 1566 | static unsigned int latest_pool_num = 1; |
| 1567 | literal_pool *pool; |
| 1568 | |
| 1569 | pool = find_literal_pool (size); |
| 1570 | |
| 1571 | if (pool == NULL) |
| 1572 | { |
| 1573 | /* Create a new pool. */ |
| 1574 | pool = xmalloc (sizeof (*pool)); |
| 1575 | if (!pool) |
| 1576 | return NULL; |
| 1577 | |
| 1578 | /* Currently we always put the literal pool in the current text |
| 1579 | section. If we were generating "small" model code where we |
| 1580 | knew that all code and initialised data was within 1MB then |
| 1581 | we could output literals to mergeable, read-only data |
| 1582 | sections. */ |
| 1583 | |
| 1584 | pool->next_free_entry = 0; |
| 1585 | pool->section = now_seg; |
| 1586 | pool->sub_section = now_subseg; |
| 1587 | pool->size = size; |
| 1588 | pool->next = list_of_pools; |
| 1589 | pool->symbol = NULL; |
| 1590 | |
| 1591 | /* Add it to the list. */ |
| 1592 | list_of_pools = pool; |
| 1593 | } |
| 1594 | |
| 1595 | /* New pools, and emptied pools, will have a NULL symbol. */ |
| 1596 | if (pool->symbol == NULL) |
| 1597 | { |
| 1598 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
| 1599 | (valueT) 0, &zero_address_frag); |
| 1600 | pool->id = latest_pool_num++; |
| 1601 | } |
| 1602 | |
| 1603 | /* Done. */ |
| 1604 | return pool; |
| 1605 | } |
| 1606 | |
| 1607 | /* Add the literal of size SIZE in *EXP to the relevant literal pool. |
| 1608 | Return TRUE on success, otherwise return FALSE. */ |
| 1609 | static bfd_boolean |
| 1610 | add_to_lit_pool (expressionS *exp, int size) |
| 1611 | { |
| 1612 | literal_pool *pool; |
| 1613 | unsigned int entry; |
| 1614 | |
| 1615 | pool = find_or_make_literal_pool (size); |
| 1616 | |
| 1617 | /* Check if this literal value is already in the pool. */ |
| 1618 | for (entry = 0; entry < pool->next_free_entry; entry++) |
| 1619 | { |
| 1620 | expressionS * litexp = & pool->literals[entry].exp; |
| 1621 | |
| 1622 | if ((litexp->X_op == exp->X_op) |
| 1623 | && (exp->X_op == O_constant) |
| 1624 | && (litexp->X_add_number == exp->X_add_number) |
| 1625 | && (litexp->X_unsigned == exp->X_unsigned)) |
| 1626 | break; |
| 1627 | |
| 1628 | if ((litexp->X_op == exp->X_op) |
| 1629 | && (exp->X_op == O_symbol) |
| 1630 | && (litexp->X_add_number == exp->X_add_number) |
| 1631 | && (litexp->X_add_symbol == exp->X_add_symbol) |
| 1632 | && (litexp->X_op_symbol == exp->X_op_symbol)) |
| 1633 | break; |
| 1634 | } |
| 1635 | |
| 1636 | /* Do we need to create a new entry? */ |
| 1637 | if (entry == pool->next_free_entry) |
| 1638 | { |
| 1639 | if (entry >= MAX_LITERAL_POOL_SIZE) |
| 1640 | { |
| 1641 | set_syntax_error (_("literal pool overflow")); |
| 1642 | return FALSE; |
| 1643 | } |
| 1644 | |
| 1645 | pool->literals[entry].exp = *exp; |
| 1646 | pool->next_free_entry += 1; |
| 1647 | if (exp->X_op == O_big) |
| 1648 | { |
| 1649 | /* PR 16688: Bignums are held in a single global array. We must |
| 1650 | copy and preserve that value now, before it is overwritten. */ |
| 1651 | pool->literals[entry].bignum = xmalloc (CHARS_PER_LITTLENUM * exp->X_add_number); |
| 1652 | memcpy (pool->literals[entry].bignum, generic_bignum, |
| 1653 | CHARS_PER_LITTLENUM * exp->X_add_number); |
| 1654 | } |
| 1655 | else |
| 1656 | pool->literals[entry].bignum = NULL; |
| 1657 | } |
| 1658 | |
| 1659 | exp->X_op = O_symbol; |
| 1660 | exp->X_add_number = ((int) entry) * size; |
| 1661 | exp->X_add_symbol = pool->symbol; |
| 1662 | |
| 1663 | return TRUE; |
| 1664 | } |
| 1665 | |
| 1666 | /* Can't use symbol_new here, so have to create a symbol and then at |
| 1667 | a later date assign it a value. Thats what these functions do. */ |
| 1668 | |
| 1669 | static void |
| 1670 | symbol_locate (symbolS * symbolP, |
| 1671 | const char *name,/* It is copied, the caller can modify. */ |
| 1672 | segT segment, /* Segment identifier (SEG_<something>). */ |
| 1673 | valueT valu, /* Symbol value. */ |
| 1674 | fragS * frag) /* Associated fragment. */ |
| 1675 | { |
| 1676 | size_t name_length; |
| 1677 | char *preserved_copy_of_name; |
| 1678 | |
| 1679 | name_length = strlen (name) + 1; /* +1 for \0. */ |
| 1680 | obstack_grow (¬es, name, name_length); |
| 1681 | preserved_copy_of_name = obstack_finish (¬es); |
| 1682 | |
| 1683 | #ifdef tc_canonicalize_symbol_name |
| 1684 | preserved_copy_of_name = |
| 1685 | tc_canonicalize_symbol_name (preserved_copy_of_name); |
| 1686 | #endif |
| 1687 | |
| 1688 | S_SET_NAME (symbolP, preserved_copy_of_name); |
| 1689 | |
| 1690 | S_SET_SEGMENT (symbolP, segment); |
| 1691 | S_SET_VALUE (symbolP, valu); |
| 1692 | symbol_clear_list_pointers (symbolP); |
| 1693 | |
| 1694 | symbol_set_frag (symbolP, frag); |
| 1695 | |
| 1696 | /* Link to end of symbol chain. */ |
| 1697 | { |
| 1698 | extern int symbol_table_frozen; |
| 1699 | |
| 1700 | if (symbol_table_frozen) |
| 1701 | abort (); |
| 1702 | } |
| 1703 | |
| 1704 | symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); |
| 1705 | |
| 1706 | obj_symbol_new_hook (symbolP); |
| 1707 | |
| 1708 | #ifdef tc_symbol_new_hook |
| 1709 | tc_symbol_new_hook (symbolP); |
| 1710 | #endif |
| 1711 | |
| 1712 | #ifdef DEBUG_SYMS |
| 1713 | verify_symbol_chain (symbol_rootP, symbol_lastP); |
| 1714 | #endif /* DEBUG_SYMS */ |
| 1715 | } |
| 1716 | |
| 1717 | |
| 1718 | static void |
| 1719 | s_ltorg (int ignored ATTRIBUTE_UNUSED) |
| 1720 | { |
| 1721 | unsigned int entry; |
| 1722 | literal_pool *pool; |
| 1723 | char sym_name[20]; |
| 1724 | int align; |
| 1725 | |
| 1726 | for (align = 2; align <= 4; align++) |
| 1727 | { |
| 1728 | int size = 1 << align; |
| 1729 | |
| 1730 | pool = find_literal_pool (size); |
| 1731 | if (pool == NULL || pool->symbol == NULL || pool->next_free_entry == 0) |
| 1732 | continue; |
| 1733 | |
| 1734 | mapping_state (MAP_DATA); |
| 1735 | |
| 1736 | /* Align pool as you have word accesses. |
| 1737 | Only make a frag if we have to. */ |
| 1738 | if (!need_pass_2) |
| 1739 | frag_align (align, 0, 0); |
| 1740 | |
| 1741 | record_alignment (now_seg, align); |
| 1742 | |
| 1743 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
| 1744 | |
| 1745 | symbol_locate (pool->symbol, sym_name, now_seg, |
| 1746 | (valueT) frag_now_fix (), frag_now); |
| 1747 | symbol_table_insert (pool->symbol); |
| 1748 | |
| 1749 | for (entry = 0; entry < pool->next_free_entry; entry++) |
| 1750 | { |
| 1751 | expressionS * exp = & pool->literals[entry].exp; |
| 1752 | |
| 1753 | if (exp->X_op == O_big) |
| 1754 | { |
| 1755 | /* PR 16688: Restore the global bignum value. */ |
| 1756 | gas_assert (pool->literals[entry].bignum != NULL); |
| 1757 | memcpy (generic_bignum, pool->literals[entry].bignum, |
| 1758 | CHARS_PER_LITTLENUM * exp->X_add_number); |
| 1759 | } |
| 1760 | |
| 1761 | /* First output the expression in the instruction to the pool. */ |
| 1762 | emit_expr (exp, size); /* .word|.xword */ |
| 1763 | |
| 1764 | if (exp->X_op == O_big) |
| 1765 | { |
| 1766 | free (pool->literals[entry].bignum); |
| 1767 | pool->literals[entry].bignum = NULL; |
| 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | /* Mark the pool as empty. */ |
| 1772 | pool->next_free_entry = 0; |
| 1773 | pool->symbol = NULL; |
| 1774 | } |
| 1775 | } |
| 1776 | |
| 1777 | #ifdef OBJ_ELF |
| 1778 | /* Forward declarations for functions below, in the MD interface |
| 1779 | section. */ |
| 1780 | static fixS *fix_new_aarch64 (fragS *, int, short, expressionS *, int, int); |
| 1781 | static struct reloc_table_entry * find_reloc_table_entry (char **); |
| 1782 | |
| 1783 | /* Directives: Data. */ |
| 1784 | /* N.B. the support for relocation suffix in this directive needs to be |
| 1785 | implemented properly. */ |
| 1786 | |
| 1787 | static void |
| 1788 | s_aarch64_elf_cons (int nbytes) |
| 1789 | { |
| 1790 | expressionS exp; |
| 1791 | |
| 1792 | #ifdef md_flush_pending_output |
| 1793 | md_flush_pending_output (); |
| 1794 | #endif |
| 1795 | |
| 1796 | if (is_it_end_of_statement ()) |
| 1797 | { |
| 1798 | demand_empty_rest_of_line (); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | #ifdef md_cons_align |
| 1803 | md_cons_align (nbytes); |
| 1804 | #endif |
| 1805 | |
| 1806 | mapping_state (MAP_DATA); |
| 1807 | do |
| 1808 | { |
| 1809 | struct reloc_table_entry *reloc; |
| 1810 | |
| 1811 | expression (&exp); |
| 1812 | |
| 1813 | if (exp.X_op != O_symbol) |
| 1814 | emit_expr (&exp, (unsigned int) nbytes); |
| 1815 | else |
| 1816 | { |
| 1817 | skip_past_char (&input_line_pointer, '#'); |
| 1818 | if (skip_past_char (&input_line_pointer, ':')) |
| 1819 | { |
| 1820 | reloc = find_reloc_table_entry (&input_line_pointer); |
| 1821 | if (reloc == NULL) |
| 1822 | as_bad (_("unrecognized relocation suffix")); |
| 1823 | else |
| 1824 | as_bad (_("unimplemented relocation suffix")); |
| 1825 | ignore_rest_of_line (); |
| 1826 | return; |
| 1827 | } |
| 1828 | else |
| 1829 | emit_expr (&exp, (unsigned int) nbytes); |
| 1830 | } |
| 1831 | } |
| 1832 | while (*input_line_pointer++ == ','); |
| 1833 | |
| 1834 | /* Put terminator back into stream. */ |
| 1835 | input_line_pointer--; |
| 1836 | demand_empty_rest_of_line (); |
| 1837 | } |
| 1838 | |
| 1839 | #endif /* OBJ_ELF */ |
| 1840 | |
| 1841 | /* Output a 32-bit word, but mark as an instruction. */ |
| 1842 | |
| 1843 | static void |
| 1844 | s_aarch64_inst (int ignored ATTRIBUTE_UNUSED) |
| 1845 | { |
| 1846 | expressionS exp; |
| 1847 | |
| 1848 | #ifdef md_flush_pending_output |
| 1849 | md_flush_pending_output (); |
| 1850 | #endif |
| 1851 | |
| 1852 | if (is_it_end_of_statement ()) |
| 1853 | { |
| 1854 | demand_empty_rest_of_line (); |
| 1855 | return; |
| 1856 | } |
| 1857 | |
| 1858 | /* Sections are assumed to start aligned. In executable section, there is no |
| 1859 | MAP_DATA symbol pending. So we only align the address during |
| 1860 | MAP_DATA --> MAP_INSN transition. |
| 1861 | For other sections, this is not guaranteed. */ |
| 1862 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
| 1863 | if (!need_pass_2 && subseg_text_p (now_seg) && mapstate == MAP_DATA) |
| 1864 | frag_align_code (2, 0); |
| 1865 | |
| 1866 | #ifdef OBJ_ELF |
| 1867 | mapping_state (MAP_INSN); |
| 1868 | #endif |
| 1869 | |
| 1870 | do |
| 1871 | { |
| 1872 | expression (&exp); |
| 1873 | if (exp.X_op != O_constant) |
| 1874 | { |
| 1875 | as_bad (_("constant expression required")); |
| 1876 | ignore_rest_of_line (); |
| 1877 | return; |
| 1878 | } |
| 1879 | |
| 1880 | if (target_big_endian) |
| 1881 | { |
| 1882 | unsigned int val = exp.X_add_number; |
| 1883 | exp.X_add_number = SWAP_32 (val); |
| 1884 | } |
| 1885 | emit_expr (&exp, 4); |
| 1886 | } |
| 1887 | while (*input_line_pointer++ == ','); |
| 1888 | |
| 1889 | /* Put terminator back into stream. */ |
| 1890 | input_line_pointer--; |
| 1891 | demand_empty_rest_of_line (); |
| 1892 | } |
| 1893 | |
| 1894 | #ifdef OBJ_ELF |
| 1895 | /* Emit BFD_RELOC_AARCH64_TLSDESC_CALL on the next BLR instruction. */ |
| 1896 | |
| 1897 | static void |
| 1898 | s_tlsdesccall (int ignored ATTRIBUTE_UNUSED) |
| 1899 | { |
| 1900 | expressionS exp; |
| 1901 | |
| 1902 | /* Since we're just labelling the code, there's no need to define a |
| 1903 | mapping symbol. */ |
| 1904 | expression (&exp); |
| 1905 | /* Make sure there is enough room in this frag for the following |
| 1906 | blr. This trick only works if the blr follows immediately after |
| 1907 | the .tlsdesc directive. */ |
| 1908 | frag_grow (4); |
| 1909 | fix_new_aarch64 (frag_now, frag_more (0) - frag_now->fr_literal, 4, &exp, 0, |
| 1910 | BFD_RELOC_AARCH64_TLSDESC_CALL); |
| 1911 | |
| 1912 | demand_empty_rest_of_line (); |
| 1913 | } |
| 1914 | #endif /* OBJ_ELF */ |
| 1915 | |
| 1916 | static void s_aarch64_arch (int); |
| 1917 | static void s_aarch64_cpu (int); |
| 1918 | static void s_aarch64_arch_extension (int); |
| 1919 | |
| 1920 | /* This table describes all the machine specific pseudo-ops the assembler |
| 1921 | has to support. The fields are: |
| 1922 | pseudo-op name without dot |
| 1923 | function to call to execute this pseudo-op |
| 1924 | Integer arg to pass to the function. */ |
| 1925 | |
| 1926 | const pseudo_typeS md_pseudo_table[] = { |
| 1927 | /* Never called because '.req' does not start a line. */ |
| 1928 | {"req", s_req, 0}, |
| 1929 | {"unreq", s_unreq, 0}, |
| 1930 | {"bss", s_bss, 0}, |
| 1931 | {"even", s_even, 0}, |
| 1932 | {"ltorg", s_ltorg, 0}, |
| 1933 | {"pool", s_ltorg, 0}, |
| 1934 | {"cpu", s_aarch64_cpu, 0}, |
| 1935 | {"arch", s_aarch64_arch, 0}, |
| 1936 | {"arch_extension", s_aarch64_arch_extension, 0}, |
| 1937 | {"inst", s_aarch64_inst, 0}, |
| 1938 | #ifdef OBJ_ELF |
| 1939 | {"tlsdesccall", s_tlsdesccall, 0}, |
| 1940 | {"word", s_aarch64_elf_cons, 4}, |
| 1941 | {"long", s_aarch64_elf_cons, 4}, |
| 1942 | {"xword", s_aarch64_elf_cons, 8}, |
| 1943 | {"dword", s_aarch64_elf_cons, 8}, |
| 1944 | #endif |
| 1945 | {0, 0, 0} |
| 1946 | }; |
| 1947 | \f |
| 1948 | |
| 1949 | /* Check whether STR points to a register name followed by a comma or the |
| 1950 | end of line; REG_TYPE indicates which register types are checked |
| 1951 | against. Return TRUE if STR is such a register name; otherwise return |
| 1952 | FALSE. The function does not intend to produce any diagnostics, but since |
| 1953 | the register parser aarch64_reg_parse, which is called by this function, |
| 1954 | does produce diagnostics, we call clear_error to clear any diagnostics |
| 1955 | that may be generated by aarch64_reg_parse. |
| 1956 | Also, the function returns FALSE directly if there is any user error |
| 1957 | present at the function entry. This prevents the existing diagnostics |
| 1958 | state from being spoiled. |
| 1959 | The function currently serves parse_constant_immediate and |
| 1960 | parse_big_immediate only. */ |
| 1961 | static bfd_boolean |
| 1962 | reg_name_p (char *str, aarch64_reg_type reg_type) |
| 1963 | { |
| 1964 | int reg; |
| 1965 | |
| 1966 | /* Prevent the diagnostics state from being spoiled. */ |
| 1967 | if (error_p ()) |
| 1968 | return FALSE; |
| 1969 | |
| 1970 | reg = aarch64_reg_parse (&str, reg_type, NULL, NULL); |
| 1971 | |
| 1972 | /* Clear the parsing error that may be set by the reg parser. */ |
| 1973 | clear_error (); |
| 1974 | |
| 1975 | if (reg == PARSE_FAIL) |
| 1976 | return FALSE; |
| 1977 | |
| 1978 | skip_whitespace (str); |
| 1979 | if (*str == ',' || is_end_of_line[(unsigned int) *str]) |
| 1980 | return TRUE; |
| 1981 | |
| 1982 | return FALSE; |
| 1983 | } |
| 1984 | |
| 1985 | /* Parser functions used exclusively in instruction operands. */ |
| 1986 | |
| 1987 | /* Parse an immediate expression which may not be constant. |
| 1988 | |
| 1989 | To prevent the expression parser from pushing a register name |
| 1990 | into the symbol table as an undefined symbol, firstly a check is |
| 1991 | done to find out whether STR is a valid register name followed |
| 1992 | by a comma or the end of line. Return FALSE if STR is such a |
| 1993 | string. */ |
| 1994 | |
| 1995 | static bfd_boolean |
| 1996 | parse_immediate_expression (char **str, expressionS *exp) |
| 1997 | { |
| 1998 | if (reg_name_p (*str, REG_TYPE_R_Z_BHSDQ_V)) |
| 1999 | { |
| 2000 | set_recoverable_error (_("immediate operand required")); |
| 2001 | return FALSE; |
| 2002 | } |
| 2003 | |
| 2004 | my_get_expression (exp, str, GE_OPT_PREFIX, 1); |
| 2005 | |
| 2006 | if (exp->X_op == O_absent) |
| 2007 | { |
| 2008 | set_fatal_syntax_error (_("missing immediate expression")); |
| 2009 | return FALSE; |
| 2010 | } |
| 2011 | |
| 2012 | return TRUE; |
| 2013 | } |
| 2014 | |
| 2015 | /* Constant immediate-value read function for use in insn parsing. |
| 2016 | STR points to the beginning of the immediate (with the optional |
| 2017 | leading #); *VAL receives the value. |
| 2018 | |
| 2019 | Return TRUE on success; otherwise return FALSE. */ |
| 2020 | |
| 2021 | static bfd_boolean |
| 2022 | parse_constant_immediate (char **str, int64_t * val) |
| 2023 | { |
| 2024 | expressionS exp; |
| 2025 | |
| 2026 | if (! parse_immediate_expression (str, &exp)) |
| 2027 | return FALSE; |
| 2028 | |
| 2029 | if (exp.X_op != O_constant) |
| 2030 | { |
| 2031 | set_syntax_error (_("constant expression required")); |
| 2032 | return FALSE; |
| 2033 | } |
| 2034 | |
| 2035 | *val = exp.X_add_number; |
| 2036 | return TRUE; |
| 2037 | } |
| 2038 | |
| 2039 | static uint32_t |
| 2040 | encode_imm_float_bits (uint32_t imm) |
| 2041 | { |
| 2042 | return ((imm >> 19) & 0x7f) /* b[25:19] -> b[6:0] */ |
| 2043 | | ((imm >> (31 - 7)) & 0x80); /* b[31] -> b[7] */ |
| 2044 | } |
| 2045 | |
| 2046 | /* Return TRUE if the single-precision floating-point value encoded in IMM |
| 2047 | can be expressed in the AArch64 8-bit signed floating-point format with |
| 2048 | 3-bit exponent and normalized 4 bits of precision; in other words, the |
| 2049 | floating-point value must be expressable as |
| 2050 | (+/-) n / 16 * power (2, r) |
| 2051 | where n and r are integers such that 16 <= n <=31 and -3 <= r <= 4. */ |
| 2052 | |
| 2053 | static bfd_boolean |
| 2054 | aarch64_imm_float_p (uint32_t imm) |
| 2055 | { |
| 2056 | /* If a single-precision floating-point value has the following bit |
| 2057 | pattern, it can be expressed in the AArch64 8-bit floating-point |
| 2058 | format: |
| 2059 | |
| 2060 | 3 32222222 2221111111111 |
| 2061 | 1 09876543 21098765432109876543210 |
| 2062 | n Eeeeeexx xxxx0000000000000000000 |
| 2063 | |
| 2064 | where n, e and each x are either 0 or 1 independently, with |
| 2065 | E == ~ e. */ |
| 2066 | |
| 2067 | uint32_t pattern; |
| 2068 | |
| 2069 | /* Prepare the pattern for 'Eeeeee'. */ |
| 2070 | if (((imm >> 30) & 0x1) == 0) |
| 2071 | pattern = 0x3e000000; |
| 2072 | else |
| 2073 | pattern = 0x40000000; |
| 2074 | |
| 2075 | return (imm & 0x7ffff) == 0 /* lower 19 bits are 0. */ |
| 2076 | && ((imm & 0x7e000000) == pattern); /* bits 25 - 29 == ~ bit 30. */ |
| 2077 | } |
| 2078 | |
| 2079 | /* Like aarch64_imm_float_p but for a double-precision floating-point value. |
| 2080 | |
| 2081 | Return TRUE if the value encoded in IMM can be expressed in the AArch64 |
| 2082 | 8-bit signed floating-point format with 3-bit exponent and normalized 4 |
| 2083 | bits of precision (i.e. can be used in an FMOV instruction); return the |
| 2084 | equivalent single-precision encoding in *FPWORD. |
| 2085 | |
| 2086 | Otherwise return FALSE. */ |
| 2087 | |
| 2088 | static bfd_boolean |
| 2089 | aarch64_double_precision_fmovable (uint64_t imm, uint32_t *fpword) |
| 2090 | { |
| 2091 | /* If a double-precision floating-point value has the following bit |
| 2092 | pattern, it can be expressed in the AArch64 8-bit floating-point |
| 2093 | format: |
| 2094 | |
| 2095 | 6 66655555555 554444444...21111111111 |
| 2096 | 3 21098765432 109876543...098765432109876543210 |
| 2097 | n Eeeeeeeeexx xxxx00000...000000000000000000000 |
| 2098 | |
| 2099 | where n, e and each x are either 0 or 1 independently, with |
| 2100 | E == ~ e. */ |
| 2101 | |
| 2102 | uint32_t pattern; |
| 2103 | uint32_t high32 = imm >> 32; |
| 2104 | |
| 2105 | /* Lower 32 bits need to be 0s. */ |
| 2106 | if ((imm & 0xffffffff) != 0) |
| 2107 | return FALSE; |
| 2108 | |
| 2109 | /* Prepare the pattern for 'Eeeeeeeee'. */ |
| 2110 | if (((high32 >> 30) & 0x1) == 0) |
| 2111 | pattern = 0x3fc00000; |
| 2112 | else |
| 2113 | pattern = 0x40000000; |
| 2114 | |
| 2115 | if ((high32 & 0xffff) == 0 /* bits 32 - 47 are 0. */ |
| 2116 | && (high32 & 0x7fc00000) == pattern) /* bits 54 - 61 == ~ bit 62. */ |
| 2117 | { |
| 2118 | /* Convert to the single-precision encoding. |
| 2119 | i.e. convert |
| 2120 | n Eeeeeeeeexx xxxx00000...000000000000000000000 |
| 2121 | to |
| 2122 | n Eeeeeexx xxxx0000000000000000000. */ |
| 2123 | *fpword = ((high32 & 0xfe000000) /* nEeeeee. */ |
| 2124 | | (((high32 >> 16) & 0x3f) << 19)); /* xxxxxx. */ |
| 2125 | return TRUE; |
| 2126 | } |
| 2127 | else |
| 2128 | return FALSE; |
| 2129 | } |
| 2130 | |
| 2131 | /* Parse a floating-point immediate. Return TRUE on success and return the |
| 2132 | value in *IMMED in the format of IEEE754 single-precision encoding. |
| 2133 | *CCP points to the start of the string; DP_P is TRUE when the immediate |
| 2134 | is expected to be in double-precision (N.B. this only matters when |
| 2135 | hexadecimal representation is involved). |
| 2136 | |
| 2137 | N.B. 0.0 is accepted by this function. */ |
| 2138 | |
| 2139 | static bfd_boolean |
| 2140 | parse_aarch64_imm_float (char **ccp, int *immed, bfd_boolean dp_p) |
| 2141 | { |
| 2142 | char *str = *ccp; |
| 2143 | char *fpnum; |
| 2144 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
| 2145 | int found_fpchar = 0; |
| 2146 | int64_t val = 0; |
| 2147 | unsigned fpword = 0; |
| 2148 | bfd_boolean hex_p = FALSE; |
| 2149 | |
| 2150 | skip_past_char (&str, '#'); |
| 2151 | |
| 2152 | fpnum = str; |
| 2153 | skip_whitespace (fpnum); |
| 2154 | |
| 2155 | if (strncmp (fpnum, "0x", 2) == 0) |
| 2156 | { |
| 2157 | /* Support the hexadecimal representation of the IEEE754 encoding. |
| 2158 | Double-precision is expected when DP_P is TRUE, otherwise the |
| 2159 | representation should be in single-precision. */ |
| 2160 | if (! parse_constant_immediate (&str, &val)) |
| 2161 | goto invalid_fp; |
| 2162 | |
| 2163 | if (dp_p) |
| 2164 | { |
| 2165 | if (! aarch64_double_precision_fmovable (val, &fpword)) |
| 2166 | goto invalid_fp; |
| 2167 | } |
| 2168 | else if ((uint64_t) val > 0xffffffff) |
| 2169 | goto invalid_fp; |
| 2170 | else |
| 2171 | fpword = val; |
| 2172 | |
| 2173 | hex_p = TRUE; |
| 2174 | } |
| 2175 | else |
| 2176 | { |
| 2177 | /* We must not accidentally parse an integer as a floating-point number. |
| 2178 | Make sure that the value we parse is not an integer by checking for |
| 2179 | special characters '.' or 'e'. */ |
| 2180 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) |
| 2181 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
| 2182 | { |
| 2183 | found_fpchar = 1; |
| 2184 | break; |
| 2185 | } |
| 2186 | |
| 2187 | if (!found_fpchar) |
| 2188 | return FALSE; |
| 2189 | } |
| 2190 | |
| 2191 | if (! hex_p) |
| 2192 | { |
| 2193 | int i; |
| 2194 | |
| 2195 | if ((str = atof_ieee (str, 's', words)) == NULL) |
| 2196 | goto invalid_fp; |
| 2197 | |
| 2198 | /* Our FP word must be 32 bits (single-precision FP). */ |
| 2199 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) |
| 2200 | { |
| 2201 | fpword <<= LITTLENUM_NUMBER_OF_BITS; |
| 2202 | fpword |= words[i]; |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | if (aarch64_imm_float_p (fpword) || (fpword & 0x7fffffff) == 0) |
| 2207 | { |
| 2208 | *immed = fpword; |
| 2209 | *ccp = str; |
| 2210 | return TRUE; |
| 2211 | } |
| 2212 | |
| 2213 | invalid_fp: |
| 2214 | set_fatal_syntax_error (_("invalid floating-point constant")); |
| 2215 | return FALSE; |
| 2216 | } |
| 2217 | |
| 2218 | /* Less-generic immediate-value read function with the possibility of loading |
| 2219 | a big (64-bit) immediate, as required by AdvSIMD Modified immediate |
| 2220 | instructions. |
| 2221 | |
| 2222 | To prevent the expression parser from pushing a register name into the |
| 2223 | symbol table as an undefined symbol, a check is firstly done to find |
| 2224 | out whether STR is a valid register name followed by a comma or the end |
| 2225 | of line. Return FALSE if STR is such a register. */ |
| 2226 | |
| 2227 | static bfd_boolean |
| 2228 | parse_big_immediate (char **str, int64_t *imm) |
| 2229 | { |
| 2230 | char *ptr = *str; |
| 2231 | |
| 2232 | if (reg_name_p (ptr, REG_TYPE_R_Z_BHSDQ_V)) |
| 2233 | { |
| 2234 | set_syntax_error (_("immediate operand required")); |
| 2235 | return FALSE; |
| 2236 | } |
| 2237 | |
| 2238 | my_get_expression (&inst.reloc.exp, &ptr, GE_OPT_PREFIX, 1); |
| 2239 | |
| 2240 | if (inst.reloc.exp.X_op == O_constant) |
| 2241 | *imm = inst.reloc.exp.X_add_number; |
| 2242 | |
| 2243 | *str = ptr; |
| 2244 | |
| 2245 | return TRUE; |
| 2246 | } |
| 2247 | |
| 2248 | /* Set operand IDX of the *INSTR that needs a GAS internal fixup. |
| 2249 | if NEED_LIBOPCODES is non-zero, the fixup will need |
| 2250 | assistance from the libopcodes. */ |
| 2251 | |
| 2252 | static inline void |
| 2253 | aarch64_set_gas_internal_fixup (struct reloc *reloc, |
| 2254 | const aarch64_opnd_info *operand, |
| 2255 | int need_libopcodes_p) |
| 2256 | { |
| 2257 | reloc->type = BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP; |
| 2258 | reloc->opnd = operand->type; |
| 2259 | if (need_libopcodes_p) |
| 2260 | reloc->need_libopcodes_p = 1; |
| 2261 | }; |
| 2262 | |
| 2263 | /* Return TRUE if the instruction needs to be fixed up later internally by |
| 2264 | the GAS; otherwise return FALSE. */ |
| 2265 | |
| 2266 | static inline bfd_boolean |
| 2267 | aarch64_gas_internal_fixup_p (void) |
| 2268 | { |
| 2269 | return inst.reloc.type == BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP; |
| 2270 | } |
| 2271 | |
| 2272 | /* Assign the immediate value to the relavant field in *OPERAND if |
| 2273 | RELOC->EXP is a constant expression; otherwise, flag that *OPERAND |
| 2274 | needs an internal fixup in a later stage. |
| 2275 | ADDR_OFF_P determines whether it is the field ADDR.OFFSET.IMM or |
| 2276 | IMM.VALUE that may get assigned with the constant. */ |
| 2277 | static inline void |
| 2278 | assign_imm_if_const_or_fixup_later (struct reloc *reloc, |
| 2279 | aarch64_opnd_info *operand, |
| 2280 | int addr_off_p, |
| 2281 | int need_libopcodes_p, |
| 2282 | int skip_p) |
| 2283 | { |
| 2284 | if (reloc->exp.X_op == O_constant) |
| 2285 | { |
| 2286 | if (addr_off_p) |
| 2287 | operand->addr.offset.imm = reloc->exp.X_add_number; |
| 2288 | else |
| 2289 | operand->imm.value = reloc->exp.X_add_number; |
| 2290 | reloc->type = BFD_RELOC_UNUSED; |
| 2291 | } |
| 2292 | else |
| 2293 | { |
| 2294 | aarch64_set_gas_internal_fixup (reloc, operand, need_libopcodes_p); |
| 2295 | /* Tell libopcodes to ignore this operand or not. This is helpful |
| 2296 | when one of the operands needs to be fixed up later but we need |
| 2297 | libopcodes to check the other operands. */ |
| 2298 | operand->skip = skip_p; |
| 2299 | } |
| 2300 | } |
| 2301 | |
| 2302 | /* Relocation modifiers. Each entry in the table contains the textual |
| 2303 | name for the relocation which may be placed before a symbol used as |
| 2304 | a load/store offset, or add immediate. It must be surrounded by a |
| 2305 | leading and trailing colon, for example: |
| 2306 | |
| 2307 | ldr x0, [x1, #:rello:varsym] |
| 2308 | add x0, x1, #:rello:varsym */ |
| 2309 | |
| 2310 | struct reloc_table_entry |
| 2311 | { |
| 2312 | const char *name; |
| 2313 | int pc_rel; |
| 2314 | bfd_reloc_code_real_type adr_type; |
| 2315 | bfd_reloc_code_real_type adrp_type; |
| 2316 | bfd_reloc_code_real_type movw_type; |
| 2317 | bfd_reloc_code_real_type add_type; |
| 2318 | bfd_reloc_code_real_type ldst_type; |
| 2319 | bfd_reloc_code_real_type ld_literal_type; |
| 2320 | }; |
| 2321 | |
| 2322 | static struct reloc_table_entry reloc_table[] = { |
| 2323 | /* Low 12 bits of absolute address: ADD/i and LDR/STR */ |
| 2324 | {"lo12", 0, |
| 2325 | 0, /* adr_type */ |
| 2326 | 0, |
| 2327 | 0, |
| 2328 | BFD_RELOC_AARCH64_ADD_LO12, |
| 2329 | BFD_RELOC_AARCH64_LDST_LO12, |
| 2330 | 0}, |
| 2331 | |
| 2332 | /* Higher 21 bits of pc-relative page offset: ADRP */ |
| 2333 | {"pg_hi21", 1, |
| 2334 | 0, /* adr_type */ |
| 2335 | BFD_RELOC_AARCH64_ADR_HI21_PCREL, |
| 2336 | 0, |
| 2337 | 0, |
| 2338 | 0, |
| 2339 | 0}, |
| 2340 | |
| 2341 | /* Higher 21 bits of pc-relative page offset: ADRP, no check */ |
| 2342 | {"pg_hi21_nc", 1, |
| 2343 | 0, /* adr_type */ |
| 2344 | BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL, |
| 2345 | 0, |
| 2346 | 0, |
| 2347 | 0, |
| 2348 | 0}, |
| 2349 | |
| 2350 | /* Most significant bits 0-15 of unsigned address/value: MOVZ */ |
| 2351 | {"abs_g0", 0, |
| 2352 | 0, /* adr_type */ |
| 2353 | 0, |
| 2354 | BFD_RELOC_AARCH64_MOVW_G0, |
| 2355 | 0, |
| 2356 | 0, |
| 2357 | 0}, |
| 2358 | |
| 2359 | /* Most significant bits 0-15 of signed address/value: MOVN/Z */ |
| 2360 | {"abs_g0_s", 0, |
| 2361 | 0, /* adr_type */ |
| 2362 | 0, |
| 2363 | BFD_RELOC_AARCH64_MOVW_G0_S, |
| 2364 | 0, |
| 2365 | 0, |
| 2366 | 0}, |
| 2367 | |
| 2368 | /* Less significant bits 0-15 of address/value: MOVK, no check */ |
| 2369 | {"abs_g0_nc", 0, |
| 2370 | 0, /* adr_type */ |
| 2371 | 0, |
| 2372 | BFD_RELOC_AARCH64_MOVW_G0_NC, |
| 2373 | 0, |
| 2374 | 0, |
| 2375 | 0}, |
| 2376 | |
| 2377 | /* Most significant bits 16-31 of unsigned address/value: MOVZ */ |
| 2378 | {"abs_g1", 0, |
| 2379 | 0, /* adr_type */ |
| 2380 | 0, |
| 2381 | BFD_RELOC_AARCH64_MOVW_G1, |
| 2382 | 0, |
| 2383 | 0, |
| 2384 | 0}, |
| 2385 | |
| 2386 | /* Most significant bits 16-31 of signed address/value: MOVN/Z */ |
| 2387 | {"abs_g1_s", 0, |
| 2388 | 0, /* adr_type */ |
| 2389 | 0, |
| 2390 | BFD_RELOC_AARCH64_MOVW_G1_S, |
| 2391 | 0, |
| 2392 | 0, |
| 2393 | 0}, |
| 2394 | |
| 2395 | /* Less significant bits 16-31 of address/value: MOVK, no check */ |
| 2396 | {"abs_g1_nc", 0, |
| 2397 | 0, /* adr_type */ |
| 2398 | 0, |
| 2399 | BFD_RELOC_AARCH64_MOVW_G1_NC, |
| 2400 | 0, |
| 2401 | 0, |
| 2402 | 0}, |
| 2403 | |
| 2404 | /* Most significant bits 32-47 of unsigned address/value: MOVZ */ |
| 2405 | {"abs_g2", 0, |
| 2406 | 0, /* adr_type */ |
| 2407 | 0, |
| 2408 | BFD_RELOC_AARCH64_MOVW_G2, |
| 2409 | 0, |
| 2410 | 0, |
| 2411 | 0}, |
| 2412 | |
| 2413 | /* Most significant bits 32-47 of signed address/value: MOVN/Z */ |
| 2414 | {"abs_g2_s", 0, |
| 2415 | 0, /* adr_type */ |
| 2416 | 0, |
| 2417 | BFD_RELOC_AARCH64_MOVW_G2_S, |
| 2418 | 0, |
| 2419 | 0, |
| 2420 | 0}, |
| 2421 | |
| 2422 | /* Less significant bits 32-47 of address/value: MOVK, no check */ |
| 2423 | {"abs_g2_nc", 0, |
| 2424 | 0, /* adr_type */ |
| 2425 | 0, |
| 2426 | BFD_RELOC_AARCH64_MOVW_G2_NC, |
| 2427 | 0, |
| 2428 | 0, |
| 2429 | 0}, |
| 2430 | |
| 2431 | /* Most significant bits 48-63 of signed/unsigned address/value: MOVZ */ |
| 2432 | {"abs_g3", 0, |
| 2433 | 0, /* adr_type */ |
| 2434 | 0, |
| 2435 | BFD_RELOC_AARCH64_MOVW_G3, |
| 2436 | 0, |
| 2437 | 0, |
| 2438 | 0}, |
| 2439 | |
| 2440 | /* Get to the page containing GOT entry for a symbol. */ |
| 2441 | {"got", 1, |
| 2442 | 0, /* adr_type */ |
| 2443 | BFD_RELOC_AARCH64_ADR_GOT_PAGE, |
| 2444 | 0, |
| 2445 | 0, |
| 2446 | 0, |
| 2447 | BFD_RELOC_AARCH64_GOT_LD_PREL19}, |
| 2448 | |
| 2449 | /* 12 bit offset into the page containing GOT entry for that symbol. */ |
| 2450 | {"got_lo12", 0, |
| 2451 | 0, /* adr_type */ |
| 2452 | 0, |
| 2453 | 0, |
| 2454 | 0, |
| 2455 | BFD_RELOC_AARCH64_LD_GOT_LO12_NC, |
| 2456 | 0}, |
| 2457 | |
| 2458 | /* 15 bit offset into the page containing GOT entry for that symbol. */ |
| 2459 | {"gotoff_lo15", 0, |
| 2460 | 0, /* adr_type */ |
| 2461 | 0, |
| 2462 | 0, |
| 2463 | 0, |
| 2464 | BFD_RELOC_AARCH64_LD64_GOTOFF_LO15, |
| 2465 | 0}, |
| 2466 | |
| 2467 | /* Get to the page containing GOT TLS entry for a symbol */ |
| 2468 | {"tlsgd", 0, |
| 2469 | BFD_RELOC_AARCH64_TLSGD_ADR_PREL21, /* adr_type */ |
| 2470 | BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21, |
| 2471 | 0, |
| 2472 | 0, |
| 2473 | 0, |
| 2474 | 0}, |
| 2475 | |
| 2476 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ |
| 2477 | {"tlsgd_lo12", 0, |
| 2478 | 0, /* adr_type */ |
| 2479 | 0, |
| 2480 | 0, |
| 2481 | BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC, |
| 2482 | 0, |
| 2483 | 0}, |
| 2484 | |
| 2485 | /* Get to the page containing GOT TLS entry for a symbol */ |
| 2486 | {"tlsdesc", 0, |
| 2487 | BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21, /* adr_type */ |
| 2488 | BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21, |
| 2489 | 0, |
| 2490 | 0, |
| 2491 | 0, |
| 2492 | BFD_RELOC_AARCH64_TLSDESC_LD_PREL19}, |
| 2493 | |
| 2494 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ |
| 2495 | {"tlsdesc_lo12", 0, |
| 2496 | 0, /* adr_type */ |
| 2497 | 0, |
| 2498 | 0, |
| 2499 | BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC, |
| 2500 | BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC, |
| 2501 | 0}, |
| 2502 | |
| 2503 | /* Get to the page containing GOT TLS entry for a symbol. |
| 2504 | The same as GD, we allocate two consecutive GOT slots |
| 2505 | for module index and module offset, the only difference |
| 2506 | with GD is the module offset should be intialized to |
| 2507 | zero without any outstanding runtime relocation. */ |
| 2508 | {"tlsldm", 0, |
| 2509 | BFD_RELOC_AARCH64_TLSLD_ADR_PREL21, /* adr_type */ |
| 2510 | BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21, |
| 2511 | 0, |
| 2512 | 0, |
| 2513 | 0, |
| 2514 | 0}, |
| 2515 | |
| 2516 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ |
| 2517 | {"tlsldm_lo12_nc", 0, |
| 2518 | 0, /* adr_type */ |
| 2519 | 0, |
| 2520 | 0, |
| 2521 | BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC, |
| 2522 | 0, |
| 2523 | 0}, |
| 2524 | |
| 2525 | /* 12 bit offset into the module TLS base address. */ |
| 2526 | {"dtprel_lo12", 0, |
| 2527 | 0, /* adr_type */ |
| 2528 | 0, |
| 2529 | 0, |
| 2530 | BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12, |
| 2531 | 0, |
| 2532 | 0}, |
| 2533 | |
| 2534 | /* Same as dtprel_lo12, no overflow check. */ |
| 2535 | {"dtprel_lo12_nc", 0, |
| 2536 | 0, /* adr_type */ |
| 2537 | 0, |
| 2538 | 0, |
| 2539 | BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC, |
| 2540 | 0, |
| 2541 | 0}, |
| 2542 | |
| 2543 | /* bits[23:12] of offset to the module TLS base address. */ |
| 2544 | {"dtprel_hi12", 0, |
| 2545 | 0, /* adr_type */ |
| 2546 | 0, |
| 2547 | 0, |
| 2548 | BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12, |
| 2549 | 0, |
| 2550 | 0}, |
| 2551 | |
| 2552 | /* bits[15:0] of offset to the module TLS base address. */ |
| 2553 | {"dtprel_g0", 0, |
| 2554 | 0, /* adr_type */ |
| 2555 | 0, |
| 2556 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0, |
| 2557 | 0, |
| 2558 | 0, |
| 2559 | 0}, |
| 2560 | |
| 2561 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0. */ |
| 2562 | {"dtprel_g0_nc", 0, |
| 2563 | 0, /* adr_type */ |
| 2564 | 0, |
| 2565 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC, |
| 2566 | 0, |
| 2567 | 0, |
| 2568 | 0}, |
| 2569 | |
| 2570 | /* bits[31:16] of offset to the module TLS base address. */ |
| 2571 | {"dtprel_g1", 0, |
| 2572 | 0, /* adr_type */ |
| 2573 | 0, |
| 2574 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1, |
| 2575 | 0, |
| 2576 | 0, |
| 2577 | 0}, |
| 2578 | |
| 2579 | /* No overflow check version of BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1. */ |
| 2580 | {"dtprel_g1_nc", 0, |
| 2581 | 0, /* adr_type */ |
| 2582 | 0, |
| 2583 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC, |
| 2584 | 0, |
| 2585 | 0, |
| 2586 | 0}, |
| 2587 | |
| 2588 | /* bits[47:32] of offset to the module TLS base address. */ |
| 2589 | {"dtprel_g2", 0, |
| 2590 | 0, /* adr_type */ |
| 2591 | 0, |
| 2592 | BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2, |
| 2593 | 0, |
| 2594 | 0, |
| 2595 | 0}, |
| 2596 | |
| 2597 | /* Get to the page containing GOT TLS entry for a symbol */ |
| 2598 | {"gottprel", 0, |
| 2599 | 0, /* adr_type */ |
| 2600 | BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, |
| 2601 | 0, |
| 2602 | 0, |
| 2603 | 0, |
| 2604 | BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19}, |
| 2605 | |
| 2606 | /* 12 bit offset into the page containing GOT TLS entry for a symbol */ |
| 2607 | {"gottprel_lo12", 0, |
| 2608 | 0, /* adr_type */ |
| 2609 | 0, |
| 2610 | 0, |
| 2611 | 0, |
| 2612 | BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC, |
| 2613 | 0}, |
| 2614 | |
| 2615 | /* Get tp offset for a symbol. */ |
| 2616 | {"tprel", 0, |
| 2617 | 0, /* adr_type */ |
| 2618 | 0, |
| 2619 | 0, |
| 2620 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12, |
| 2621 | 0, |
| 2622 | 0}, |
| 2623 | |
| 2624 | /* Get tp offset for a symbol. */ |
| 2625 | {"tprel_lo12", 0, |
| 2626 | 0, /* adr_type */ |
| 2627 | 0, |
| 2628 | 0, |
| 2629 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12, |
| 2630 | 0, |
| 2631 | 0}, |
| 2632 | |
| 2633 | /* Get tp offset for a symbol. */ |
| 2634 | {"tprel_hi12", 0, |
| 2635 | 0, /* adr_type */ |
| 2636 | 0, |
| 2637 | 0, |
| 2638 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12, |
| 2639 | 0, |
| 2640 | 0}, |
| 2641 | |
| 2642 | /* Get tp offset for a symbol. */ |
| 2643 | {"tprel_lo12_nc", 0, |
| 2644 | 0, /* adr_type */ |
| 2645 | 0, |
| 2646 | 0, |
| 2647 | BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC, |
| 2648 | 0, |
| 2649 | 0}, |
| 2650 | |
| 2651 | /* Most significant bits 32-47 of address/value: MOVZ. */ |
| 2652 | {"tprel_g2", 0, |
| 2653 | 0, /* adr_type */ |
| 2654 | 0, |
| 2655 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2, |
| 2656 | 0, |
| 2657 | 0, |
| 2658 | 0}, |
| 2659 | |
| 2660 | /* Most significant bits 16-31 of address/value: MOVZ. */ |
| 2661 | {"tprel_g1", 0, |
| 2662 | 0, /* adr_type */ |
| 2663 | 0, |
| 2664 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1, |
| 2665 | 0, |
| 2666 | 0, |
| 2667 | 0}, |
| 2668 | |
| 2669 | /* Most significant bits 16-31 of address/value: MOVZ, no check. */ |
| 2670 | {"tprel_g1_nc", 0, |
| 2671 | 0, /* adr_type */ |
| 2672 | 0, |
| 2673 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC, |
| 2674 | 0, |
| 2675 | 0, |
| 2676 | 0}, |
| 2677 | |
| 2678 | /* Most significant bits 0-15 of address/value: MOVZ. */ |
| 2679 | {"tprel_g0", 0, |
| 2680 | 0, /* adr_type */ |
| 2681 | 0, |
| 2682 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0, |
| 2683 | 0, |
| 2684 | 0, |
| 2685 | 0}, |
| 2686 | |
| 2687 | /* Most significant bits 0-15 of address/value: MOVZ, no check. */ |
| 2688 | {"tprel_g0_nc", 0, |
| 2689 | 0, /* adr_type */ |
| 2690 | 0, |
| 2691 | BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC, |
| 2692 | 0, |
| 2693 | 0, |
| 2694 | 0}, |
| 2695 | |
| 2696 | /* 15bit offset from got entry to base address of GOT table. */ |
| 2697 | {"gotpage_lo15", 0, |
| 2698 | 0, |
| 2699 | 0, |
| 2700 | 0, |
| 2701 | 0, |
| 2702 | BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15, |
| 2703 | 0}, |
| 2704 | |
| 2705 | /* 14bit offset from got entry to base address of GOT table. */ |
| 2706 | {"gotpage_lo14", 0, |
| 2707 | 0, |
| 2708 | 0, |
| 2709 | 0, |
| 2710 | 0, |
| 2711 | BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14, |
| 2712 | 0}, |
| 2713 | }; |
| 2714 | |
| 2715 | /* Given the address of a pointer pointing to the textual name of a |
| 2716 | relocation as may appear in assembler source, attempt to find its |
| 2717 | details in reloc_table. The pointer will be updated to the character |
| 2718 | after the trailing colon. On failure, NULL will be returned; |
| 2719 | otherwise return the reloc_table_entry. */ |
| 2720 | |
| 2721 | static struct reloc_table_entry * |
| 2722 | find_reloc_table_entry (char **str) |
| 2723 | { |
| 2724 | unsigned int i; |
| 2725 | for (i = 0; i < ARRAY_SIZE (reloc_table); i++) |
| 2726 | { |
| 2727 | int length = strlen (reloc_table[i].name); |
| 2728 | |
| 2729 | if (strncasecmp (reloc_table[i].name, *str, length) == 0 |
| 2730 | && (*str)[length] == ':') |
| 2731 | { |
| 2732 | *str += (length + 1); |
| 2733 | return &reloc_table[i]; |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | return NULL; |
| 2738 | } |
| 2739 | |
| 2740 | /* Mode argument to parse_shift and parser_shifter_operand. */ |
| 2741 | enum parse_shift_mode |
| 2742 | { |
| 2743 | SHIFTED_ARITH_IMM, /* "rn{,lsl|lsr|asl|asr|uxt|sxt #n}" or |
| 2744 | "#imm{,lsl #n}" */ |
| 2745 | SHIFTED_LOGIC_IMM, /* "rn{,lsl|lsr|asl|asr|ror #n}" or |
| 2746 | "#imm" */ |
| 2747 | SHIFTED_LSL, /* bare "lsl #n" */ |
| 2748 | SHIFTED_LSL_MSL, /* "lsl|msl #n" */ |
| 2749 | SHIFTED_REG_OFFSET /* [su]xtw|sxtx {#n} or lsl #n */ |
| 2750 | }; |
| 2751 | |
| 2752 | /* Parse a <shift> operator on an AArch64 data processing instruction. |
| 2753 | Return TRUE on success; otherwise return FALSE. */ |
| 2754 | static bfd_boolean |
| 2755 | parse_shift (char **str, aarch64_opnd_info *operand, enum parse_shift_mode mode) |
| 2756 | { |
| 2757 | const struct aarch64_name_value_pair *shift_op; |
| 2758 | enum aarch64_modifier_kind kind; |
| 2759 | expressionS exp; |
| 2760 | int exp_has_prefix; |
| 2761 | char *s = *str; |
| 2762 | char *p = s; |
| 2763 | |
| 2764 | for (p = *str; ISALPHA (*p); p++) |
| 2765 | ; |
| 2766 | |
| 2767 | if (p == *str) |
| 2768 | { |
| 2769 | set_syntax_error (_("shift expression expected")); |
| 2770 | return FALSE; |
| 2771 | } |
| 2772 | |
| 2773 | shift_op = hash_find_n (aarch64_shift_hsh, *str, p - *str); |
| 2774 | |
| 2775 | if (shift_op == NULL) |
| 2776 | { |
| 2777 | set_syntax_error (_("shift operator expected")); |
| 2778 | return FALSE; |
| 2779 | } |
| 2780 | |
| 2781 | kind = aarch64_get_operand_modifier (shift_op); |
| 2782 | |
| 2783 | if (kind == AARCH64_MOD_MSL && mode != SHIFTED_LSL_MSL) |
| 2784 | { |
| 2785 | set_syntax_error (_("invalid use of 'MSL'")); |
| 2786 | return FALSE; |
| 2787 | } |
| 2788 | |
| 2789 | switch (mode) |
| 2790 | { |
| 2791 | case SHIFTED_LOGIC_IMM: |
| 2792 | if (aarch64_extend_operator_p (kind) == TRUE) |
| 2793 | { |
| 2794 | set_syntax_error (_("extending shift is not permitted")); |
| 2795 | return FALSE; |
| 2796 | } |
| 2797 | break; |
| 2798 | |
| 2799 | case SHIFTED_ARITH_IMM: |
| 2800 | if (kind == AARCH64_MOD_ROR) |
| 2801 | { |
| 2802 | set_syntax_error (_("'ROR' shift is not permitted")); |
| 2803 | return FALSE; |
| 2804 | } |
| 2805 | break; |
| 2806 | |
| 2807 | case SHIFTED_LSL: |
| 2808 | if (kind != AARCH64_MOD_LSL) |
| 2809 | { |
| 2810 | set_syntax_error (_("only 'LSL' shift is permitted")); |
| 2811 | return FALSE; |
| 2812 | } |
| 2813 | break; |
| 2814 | |
| 2815 | case SHIFTED_REG_OFFSET: |
| 2816 | if (kind != AARCH64_MOD_UXTW && kind != AARCH64_MOD_LSL |
| 2817 | && kind != AARCH64_MOD_SXTW && kind != AARCH64_MOD_SXTX) |
| 2818 | { |
| 2819 | set_fatal_syntax_error |
| 2820 | (_("invalid shift for the register offset addressing mode")); |
| 2821 | return FALSE; |
| 2822 | } |
| 2823 | break; |
| 2824 | |
| 2825 | case SHIFTED_LSL_MSL: |
| 2826 | if (kind != AARCH64_MOD_LSL && kind != AARCH64_MOD_MSL) |
| 2827 | { |
| 2828 | set_syntax_error (_("invalid shift operator")); |
| 2829 | return FALSE; |
| 2830 | } |
| 2831 | break; |
| 2832 | |
| 2833 | default: |
| 2834 | abort (); |
| 2835 | } |
| 2836 | |
| 2837 | /* Whitespace can appear here if the next thing is a bare digit. */ |
| 2838 | skip_whitespace (p); |
| 2839 | |
| 2840 | /* Parse shift amount. */ |
| 2841 | exp_has_prefix = 0; |
| 2842 | if (mode == SHIFTED_REG_OFFSET && *p == ']') |
| 2843 | exp.X_op = O_absent; |
| 2844 | else |
| 2845 | { |
| 2846 | if (is_immediate_prefix (*p)) |
| 2847 | { |
| 2848 | p++; |
| 2849 | exp_has_prefix = 1; |
| 2850 | } |
| 2851 | my_get_expression (&exp, &p, GE_NO_PREFIX, 0); |
| 2852 | } |
| 2853 | if (exp.X_op == O_absent) |
| 2854 | { |
| 2855 | if (aarch64_extend_operator_p (kind) == FALSE || exp_has_prefix) |
| 2856 | { |
| 2857 | set_syntax_error (_("missing shift amount")); |
| 2858 | return FALSE; |
| 2859 | } |
| 2860 | operand->shifter.amount = 0; |
| 2861 | } |
| 2862 | else if (exp.X_op != O_constant) |
| 2863 | { |
| 2864 | set_syntax_error (_("constant shift amount required")); |
| 2865 | return FALSE; |
| 2866 | } |
| 2867 | else if (exp.X_add_number < 0 || exp.X_add_number > 63) |
| 2868 | { |
| 2869 | set_fatal_syntax_error (_("shift amount out of range 0 to 63")); |
| 2870 | return FALSE; |
| 2871 | } |
| 2872 | else |
| 2873 | { |
| 2874 | operand->shifter.amount = exp.X_add_number; |
| 2875 | operand->shifter.amount_present = 1; |
| 2876 | } |
| 2877 | |
| 2878 | operand->shifter.operator_present = 1; |
| 2879 | operand->shifter.kind = kind; |
| 2880 | |
| 2881 | *str = p; |
| 2882 | return TRUE; |
| 2883 | } |
| 2884 | |
| 2885 | /* Parse a <shifter_operand> for a data processing instruction: |
| 2886 | |
| 2887 | #<immediate> |
| 2888 | #<immediate>, LSL #imm |
| 2889 | |
| 2890 | Validation of immediate operands is deferred to md_apply_fix. |
| 2891 | |
| 2892 | Return TRUE on success; otherwise return FALSE. */ |
| 2893 | |
| 2894 | static bfd_boolean |
| 2895 | parse_shifter_operand_imm (char **str, aarch64_opnd_info *operand, |
| 2896 | enum parse_shift_mode mode) |
| 2897 | { |
| 2898 | char *p; |
| 2899 | |
| 2900 | if (mode != SHIFTED_ARITH_IMM && mode != SHIFTED_LOGIC_IMM) |
| 2901 | return FALSE; |
| 2902 | |
| 2903 | p = *str; |
| 2904 | |
| 2905 | /* Accept an immediate expression. */ |
| 2906 | if (! my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX, 1)) |
| 2907 | return FALSE; |
| 2908 | |
| 2909 | /* Accept optional LSL for arithmetic immediate values. */ |
| 2910 | if (mode == SHIFTED_ARITH_IMM && skip_past_comma (&p)) |
| 2911 | if (! parse_shift (&p, operand, SHIFTED_LSL)) |
| 2912 | return FALSE; |
| 2913 | |
| 2914 | /* Not accept any shifter for logical immediate values. */ |
| 2915 | if (mode == SHIFTED_LOGIC_IMM && skip_past_comma (&p) |
| 2916 | && parse_shift (&p, operand, mode)) |
| 2917 | { |
| 2918 | set_syntax_error (_("unexpected shift operator")); |
| 2919 | return FALSE; |
| 2920 | } |
| 2921 | |
| 2922 | *str = p; |
| 2923 | return TRUE; |
| 2924 | } |
| 2925 | |
| 2926 | /* Parse a <shifter_operand> for a data processing instruction: |
| 2927 | |
| 2928 | <Rm> |
| 2929 | <Rm>, <shift> |
| 2930 | #<immediate> |
| 2931 | #<immediate>, LSL #imm |
| 2932 | |
| 2933 | where <shift> is handled by parse_shift above, and the last two |
| 2934 | cases are handled by the function above. |
| 2935 | |
| 2936 | Validation of immediate operands is deferred to md_apply_fix. |
| 2937 | |
| 2938 | Return TRUE on success; otherwise return FALSE. */ |
| 2939 | |
| 2940 | static bfd_boolean |
| 2941 | parse_shifter_operand (char **str, aarch64_opnd_info *operand, |
| 2942 | enum parse_shift_mode mode) |
| 2943 | { |
| 2944 | int reg; |
| 2945 | int isreg32, isregzero; |
| 2946 | enum aarch64_operand_class opd_class |
| 2947 | = aarch64_get_operand_class (operand->type); |
| 2948 | |
| 2949 | if ((reg = |
| 2950 | aarch64_reg_parse_32_64 (str, 0, 0, &isreg32, &isregzero)) != PARSE_FAIL) |
| 2951 | { |
| 2952 | if (opd_class == AARCH64_OPND_CLASS_IMMEDIATE) |
| 2953 | { |
| 2954 | set_syntax_error (_("unexpected register in the immediate operand")); |
| 2955 | return FALSE; |
| 2956 | } |
| 2957 | |
| 2958 | if (!isregzero && reg == REG_SP) |
| 2959 | { |
| 2960 | set_syntax_error (BAD_SP); |
| 2961 | return FALSE; |
| 2962 | } |
| 2963 | |
| 2964 | operand->reg.regno = reg; |
| 2965 | operand->qualifier = isreg32 ? AARCH64_OPND_QLF_W : AARCH64_OPND_QLF_X; |
| 2966 | |
| 2967 | /* Accept optional shift operation on register. */ |
| 2968 | if (! skip_past_comma (str)) |
| 2969 | return TRUE; |
| 2970 | |
| 2971 | if (! parse_shift (str, operand, mode)) |
| 2972 | return FALSE; |
| 2973 | |
| 2974 | return TRUE; |
| 2975 | } |
| 2976 | else if (opd_class == AARCH64_OPND_CLASS_MODIFIED_REG) |
| 2977 | { |
| 2978 | set_syntax_error |
| 2979 | (_("integer register expected in the extended/shifted operand " |
| 2980 | "register")); |
| 2981 | return FALSE; |
| 2982 | } |
| 2983 | |
| 2984 | /* We have a shifted immediate variable. */ |
| 2985 | return parse_shifter_operand_imm (str, operand, mode); |
| 2986 | } |
| 2987 | |
| 2988 | /* Return TRUE on success; return FALSE otherwise. */ |
| 2989 | |
| 2990 | static bfd_boolean |
| 2991 | parse_shifter_operand_reloc (char **str, aarch64_opnd_info *operand, |
| 2992 | enum parse_shift_mode mode) |
| 2993 | { |
| 2994 | char *p = *str; |
| 2995 | |
| 2996 | /* Determine if we have the sequence of characters #: or just : |
| 2997 | coming next. If we do, then we check for a :rello: relocation |
| 2998 | modifier. If we don't, punt the whole lot to |
| 2999 | parse_shifter_operand. */ |
| 3000 | |
| 3001 | if ((p[0] == '#' && p[1] == ':') || p[0] == ':') |
| 3002 | { |
| 3003 | struct reloc_table_entry *entry; |
| 3004 | |
| 3005 | if (p[0] == '#') |
| 3006 | p += 2; |
| 3007 | else |
| 3008 | p++; |
| 3009 | *str = p; |
| 3010 | |
| 3011 | /* Try to parse a relocation. Anything else is an error. */ |
| 3012 | if (!(entry = find_reloc_table_entry (str))) |
| 3013 | { |
| 3014 | set_syntax_error (_("unknown relocation modifier")); |
| 3015 | return FALSE; |
| 3016 | } |
| 3017 | |
| 3018 | if (entry->add_type == 0) |
| 3019 | { |
| 3020 | set_syntax_error |
| 3021 | (_("this relocation modifier is not allowed on this instruction")); |
| 3022 | return FALSE; |
| 3023 | } |
| 3024 | |
| 3025 | /* Save str before we decompose it. */ |
| 3026 | p = *str; |
| 3027 | |
| 3028 | /* Next, we parse the expression. */ |
| 3029 | if (! my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX, 1)) |
| 3030 | return FALSE; |
| 3031 | |
| 3032 | /* Record the relocation type (use the ADD variant here). */ |
| 3033 | inst.reloc.type = entry->add_type; |
| 3034 | inst.reloc.pc_rel = entry->pc_rel; |
| 3035 | |
| 3036 | /* If str is empty, we've reached the end, stop here. */ |
| 3037 | if (**str == '\0') |
| 3038 | return TRUE; |
| 3039 | |
| 3040 | /* Otherwise, we have a shifted reloc modifier, so rewind to |
| 3041 | recover the variable name and continue parsing for the shifter. */ |
| 3042 | *str = p; |
| 3043 | return parse_shifter_operand_imm (str, operand, mode); |
| 3044 | } |
| 3045 | |
| 3046 | return parse_shifter_operand (str, operand, mode); |
| 3047 | } |
| 3048 | |
| 3049 | /* Parse all forms of an address expression. Information is written |
| 3050 | to *OPERAND and/or inst.reloc. |
| 3051 | |
| 3052 | The A64 instruction set has the following addressing modes: |
| 3053 | |
| 3054 | Offset |
| 3055 | [base] // in SIMD ld/st structure |
| 3056 | [base{,#0}] // in ld/st exclusive |
| 3057 | [base{,#imm}] |
| 3058 | [base,Xm{,LSL #imm}] |
| 3059 | [base,Xm,SXTX {#imm}] |
| 3060 | [base,Wm,(S|U)XTW {#imm}] |
| 3061 | Pre-indexed |
| 3062 | [base,#imm]! |
| 3063 | Post-indexed |
| 3064 | [base],#imm |
| 3065 | [base],Xm // in SIMD ld/st structure |
| 3066 | PC-relative (literal) |
| 3067 | label |
| 3068 | =immediate |
| 3069 | |
| 3070 | (As a convenience, the notation "=immediate" is permitted in conjunction |
| 3071 | with the pc-relative literal load instructions to automatically place an |
| 3072 | immediate value or symbolic address in a nearby literal pool and generate |
| 3073 | a hidden label which references it.) |
| 3074 | |
| 3075 | Upon a successful parsing, the address structure in *OPERAND will be |
| 3076 | filled in the following way: |
| 3077 | |
| 3078 | .base_regno = <base> |
| 3079 | .offset.is_reg // 1 if the offset is a register |
| 3080 | .offset.imm = <imm> |
| 3081 | .offset.regno = <Rm> |
| 3082 | |
| 3083 | For different addressing modes defined in the A64 ISA: |
| 3084 | |
| 3085 | Offset |
| 3086 | .pcrel=0; .preind=1; .postind=0; .writeback=0 |
| 3087 | Pre-indexed |
| 3088 | .pcrel=0; .preind=1; .postind=0; .writeback=1 |
| 3089 | Post-indexed |
| 3090 | .pcrel=0; .preind=0; .postind=1; .writeback=1 |
| 3091 | PC-relative (literal) |
| 3092 | .pcrel=1; .preind=1; .postind=0; .writeback=0 |
| 3093 | |
| 3094 | The shift/extension information, if any, will be stored in .shifter. |
| 3095 | |
| 3096 | It is the caller's responsibility to check for addressing modes not |
| 3097 | supported by the instruction, and to set inst.reloc.type. */ |
| 3098 | |
| 3099 | static bfd_boolean |
| 3100 | parse_address_main (char **str, aarch64_opnd_info *operand, int reloc, |
| 3101 | int accept_reg_post_index) |
| 3102 | { |
| 3103 | char *p = *str; |
| 3104 | int reg; |
| 3105 | int isreg32, isregzero; |
| 3106 | expressionS *exp = &inst.reloc.exp; |
| 3107 | |
| 3108 | if (! skip_past_char (&p, '[')) |
| 3109 | { |
| 3110 | /* =immediate or label. */ |
| 3111 | operand->addr.pcrel = 1; |
| 3112 | operand->addr.preind = 1; |
| 3113 | |
| 3114 | /* #:<reloc_op>:<symbol> */ |
| 3115 | skip_past_char (&p, '#'); |
| 3116 | if (reloc && skip_past_char (&p, ':')) |
| 3117 | { |
| 3118 | bfd_reloc_code_real_type ty; |
| 3119 | struct reloc_table_entry *entry; |
| 3120 | |
| 3121 | /* Try to parse a relocation modifier. Anything else is |
| 3122 | an error. */ |
| 3123 | entry = find_reloc_table_entry (&p); |
| 3124 | if (! entry) |
| 3125 | { |
| 3126 | set_syntax_error (_("unknown relocation modifier")); |
| 3127 | return FALSE; |
| 3128 | } |
| 3129 | |
| 3130 | switch (operand->type) |
| 3131 | { |
| 3132 | case AARCH64_OPND_ADDR_PCREL21: |
| 3133 | /* adr */ |
| 3134 | ty = entry->adr_type; |
| 3135 | break; |
| 3136 | |
| 3137 | default: |
| 3138 | ty = entry->ld_literal_type; |
| 3139 | break; |
| 3140 | } |
| 3141 | |
| 3142 | if (ty == 0) |
| 3143 | { |
| 3144 | set_syntax_error |
| 3145 | (_("this relocation modifier is not allowed on this " |
| 3146 | "instruction")); |
| 3147 | return FALSE; |
| 3148 | } |
| 3149 | |
| 3150 | /* #:<reloc_op>: */ |
| 3151 | if (! my_get_expression (exp, &p, GE_NO_PREFIX, 1)) |
| 3152 | { |
| 3153 | set_syntax_error (_("invalid relocation expression")); |
| 3154 | return FALSE; |
| 3155 | } |
| 3156 | |
| 3157 | /* #:<reloc_op>:<expr> */ |
| 3158 | /* Record the relocation type. */ |
| 3159 | inst.reloc.type = ty; |
| 3160 | inst.reloc.pc_rel = entry->pc_rel; |
| 3161 | } |
| 3162 | else |
| 3163 | { |
| 3164 | |
| 3165 | if (skip_past_char (&p, '=')) |
| 3166 | /* =immediate; need to generate the literal in the literal pool. */ |
| 3167 | inst.gen_lit_pool = 1; |
| 3168 | |
| 3169 | if (!my_get_expression (exp, &p, GE_NO_PREFIX, 1)) |
| 3170 | { |
| 3171 | set_syntax_error (_("invalid address")); |
| 3172 | return FALSE; |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | *str = p; |
| 3177 | return TRUE; |
| 3178 | } |
| 3179 | |
| 3180 | /* [ */ |
| 3181 | |
| 3182 | /* Accept SP and reject ZR */ |
| 3183 | reg = aarch64_reg_parse_32_64 (&p, 0, 1, &isreg32, &isregzero); |
| 3184 | if (reg == PARSE_FAIL || isreg32) |
| 3185 | { |
| 3186 | set_syntax_error (_(get_reg_expected_msg (REG_TYPE_R_64))); |
| 3187 | return FALSE; |
| 3188 | } |
| 3189 | operand->addr.base_regno = reg; |
| 3190 | |
| 3191 | /* [Xn */ |
| 3192 | if (skip_past_comma (&p)) |
| 3193 | { |
| 3194 | /* [Xn, */ |
| 3195 | operand->addr.preind = 1; |
| 3196 | |
| 3197 | /* Reject SP and accept ZR */ |
| 3198 | reg = aarch64_reg_parse_32_64 (&p, 1, 0, &isreg32, &isregzero); |
| 3199 | if (reg != PARSE_FAIL) |
| 3200 | { |
| 3201 | /* [Xn,Rm */ |
| 3202 | operand->addr.offset.regno = reg; |
| 3203 | operand->addr.offset.is_reg = 1; |
| 3204 | /* Shifted index. */ |
| 3205 | if (skip_past_comma (&p)) |
| 3206 | { |
| 3207 | /* [Xn,Rm, */ |
| 3208 | if (! parse_shift (&p, operand, SHIFTED_REG_OFFSET)) |
| 3209 | /* Use the diagnostics set in parse_shift, so not set new |
| 3210 | error message here. */ |
| 3211 | return FALSE; |
| 3212 | } |
| 3213 | /* We only accept: |
| 3214 | [base,Xm{,LSL #imm}] |
| 3215 | [base,Xm,SXTX {#imm}] |
| 3216 | [base,Wm,(S|U)XTW {#imm}] */ |
| 3217 | if (operand->shifter.kind == AARCH64_MOD_NONE |
| 3218 | || operand->shifter.kind == AARCH64_MOD_LSL |
| 3219 | || operand->shifter.kind == AARCH64_MOD_SXTX) |
| 3220 | { |
| 3221 | if (isreg32) |
| 3222 | { |
| 3223 | set_syntax_error (_("invalid use of 32-bit register offset")); |
| 3224 | return FALSE; |
| 3225 | } |
| 3226 | } |
| 3227 | else if (!isreg32) |
| 3228 | { |
| 3229 | set_syntax_error (_("invalid use of 64-bit register offset")); |
| 3230 | return FALSE; |
| 3231 | } |
| 3232 | } |
| 3233 | else |
| 3234 | { |
| 3235 | /* [Xn,#:<reloc_op>:<symbol> */ |
| 3236 | skip_past_char (&p, '#'); |
| 3237 | if (reloc && skip_past_char (&p, ':')) |
| 3238 | { |
| 3239 | struct reloc_table_entry *entry; |
| 3240 | |
| 3241 | /* Try to parse a relocation modifier. Anything else is |
| 3242 | an error. */ |
| 3243 | if (!(entry = find_reloc_table_entry (&p))) |
| 3244 | { |
| 3245 | set_syntax_error (_("unknown relocation modifier")); |
| 3246 | return FALSE; |
| 3247 | } |
| 3248 | |
| 3249 | if (entry->ldst_type == 0) |
| 3250 | { |
| 3251 | set_syntax_error |
| 3252 | (_("this relocation modifier is not allowed on this " |
| 3253 | "instruction")); |
| 3254 | return FALSE; |
| 3255 | } |
| 3256 | |
| 3257 | /* [Xn,#:<reloc_op>: */ |
| 3258 | /* We now have the group relocation table entry corresponding to |
| 3259 | the name in the assembler source. Next, we parse the |
| 3260 | expression. */ |
| 3261 | if (! my_get_expression (exp, &p, GE_NO_PREFIX, 1)) |
| 3262 | { |
| 3263 | set_syntax_error (_("invalid relocation expression")); |
| 3264 | return FALSE; |
| 3265 | } |
| 3266 | |
| 3267 | /* [Xn,#:<reloc_op>:<expr> */ |
| 3268 | /* Record the load/store relocation type. */ |
| 3269 | inst.reloc.type = entry->ldst_type; |
| 3270 | inst.reloc.pc_rel = entry->pc_rel; |
| 3271 | } |
| 3272 | else if (! my_get_expression (exp, &p, GE_OPT_PREFIX, 1)) |
| 3273 | { |
| 3274 | set_syntax_error (_("invalid expression in the address")); |
| 3275 | return FALSE; |
| 3276 | } |
| 3277 | /* [Xn,<expr> */ |
| 3278 | } |
| 3279 | } |
| 3280 | |
| 3281 | if (! skip_past_char (&p, ']')) |
| 3282 | { |
| 3283 | set_syntax_error (_("']' expected")); |
| 3284 | return FALSE; |
| 3285 | } |
| 3286 | |
| 3287 | if (skip_past_char (&p, '!')) |
| 3288 | { |
| 3289 | if (operand->addr.preind && operand->addr.offset.is_reg) |
| 3290 | { |
| 3291 | set_syntax_error (_("register offset not allowed in pre-indexed " |
| 3292 | "addressing mode")); |
| 3293 | return FALSE; |
| 3294 | } |
| 3295 | /* [Xn]! */ |
| 3296 | operand->addr.writeback = 1; |
| 3297 | } |
| 3298 | else if (skip_past_comma (&p)) |
| 3299 | { |
| 3300 | /* [Xn], */ |
| 3301 | operand->addr.postind = 1; |
| 3302 | operand->addr.writeback = 1; |
| 3303 | |
| 3304 | if (operand->addr.preind) |
| 3305 | { |
| 3306 | set_syntax_error (_("cannot combine pre- and post-indexing")); |
| 3307 | return FALSE; |
| 3308 | } |
| 3309 | |
| 3310 | if (accept_reg_post_index |
| 3311 | && (reg = aarch64_reg_parse_32_64 (&p, 1, 1, &isreg32, |
| 3312 | &isregzero)) != PARSE_FAIL) |
| 3313 | { |
| 3314 | /* [Xn],Xm */ |
| 3315 | if (isreg32) |
| 3316 | { |
| 3317 | set_syntax_error (_("invalid 32-bit register offset")); |
| 3318 | return FALSE; |
| 3319 | } |
| 3320 | operand->addr.offset.regno = reg; |
| 3321 | operand->addr.offset.is_reg = 1; |
| 3322 | } |
| 3323 | else if (! my_get_expression (exp, &p, GE_OPT_PREFIX, 1)) |
| 3324 | { |
| 3325 | /* [Xn],#expr */ |
| 3326 | set_syntax_error (_("invalid expression in the address")); |
| 3327 | return FALSE; |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | /* If at this point neither .preind nor .postind is set, we have a |
| 3332 | bare [Rn]{!}; reject [Rn]! but accept [Rn] as a shorthand for [Rn,#0]. */ |
| 3333 | if (operand->addr.preind == 0 && operand->addr.postind == 0) |
| 3334 | { |
| 3335 | if (operand->addr.writeback) |
| 3336 | { |
| 3337 | /* Reject [Rn]! */ |
| 3338 | set_syntax_error (_("missing offset in the pre-indexed address")); |
| 3339 | return FALSE; |
| 3340 | } |
| 3341 | operand->addr.preind = 1; |
| 3342 | inst.reloc.exp.X_op = O_constant; |
| 3343 | inst.reloc.exp.X_add_number = 0; |
| 3344 | } |
| 3345 | |
| 3346 | *str = p; |
| 3347 | return TRUE; |
| 3348 | } |
| 3349 | |
| 3350 | /* Return TRUE on success; otherwise return FALSE. */ |
| 3351 | static bfd_boolean |
| 3352 | parse_address (char **str, aarch64_opnd_info *operand, |
| 3353 | int accept_reg_post_index) |
| 3354 | { |
| 3355 | return parse_address_main (str, operand, 0, accept_reg_post_index); |
| 3356 | } |
| 3357 | |
| 3358 | /* Return TRUE on success; otherwise return FALSE. */ |
| 3359 | static bfd_boolean |
| 3360 | parse_address_reloc (char **str, aarch64_opnd_info *operand) |
| 3361 | { |
| 3362 | return parse_address_main (str, operand, 1, 0); |
| 3363 | } |
| 3364 | |
| 3365 | /* Parse an operand for a MOVZ, MOVN or MOVK instruction. |
| 3366 | Return TRUE on success; otherwise return FALSE. */ |
| 3367 | static bfd_boolean |
| 3368 | parse_half (char **str, int *internal_fixup_p) |
| 3369 | { |
| 3370 | char *p, *saved; |
| 3371 | int dummy; |
| 3372 | |
| 3373 | p = *str; |
| 3374 | skip_past_char (&p, '#'); |
| 3375 | |
| 3376 | gas_assert (internal_fixup_p); |
| 3377 | *internal_fixup_p = 0; |
| 3378 | |
| 3379 | if (*p == ':') |
| 3380 | { |
| 3381 | struct reloc_table_entry *entry; |
| 3382 | |
| 3383 | /* Try to parse a relocation. Anything else is an error. */ |
| 3384 | ++p; |
| 3385 | if (!(entry = find_reloc_table_entry (&p))) |
| 3386 | { |
| 3387 | set_syntax_error (_("unknown relocation modifier")); |
| 3388 | return FALSE; |
| 3389 | } |
| 3390 | |
| 3391 | if (entry->movw_type == 0) |
| 3392 | { |
| 3393 | set_syntax_error |
| 3394 | (_("this relocation modifier is not allowed on this instruction")); |
| 3395 | return FALSE; |
| 3396 | } |
| 3397 | |
| 3398 | inst.reloc.type = entry->movw_type; |
| 3399 | } |
| 3400 | else |
| 3401 | *internal_fixup_p = 1; |
| 3402 | |
| 3403 | /* Avoid parsing a register as a general symbol. */ |
| 3404 | saved = p; |
| 3405 | if (aarch64_reg_parse_32_64 (&p, 0, 0, &dummy, &dummy) != PARSE_FAIL) |
| 3406 | return FALSE; |
| 3407 | p = saved; |
| 3408 | |
| 3409 | if (! my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX, 1)) |
| 3410 | return FALSE; |
| 3411 | |
| 3412 | *str = p; |
| 3413 | return TRUE; |
| 3414 | } |
| 3415 | |
| 3416 | /* Parse an operand for an ADRP instruction: |
| 3417 | ADRP <Xd>, <label> |
| 3418 | Return TRUE on success; otherwise return FALSE. */ |
| 3419 | |
| 3420 | static bfd_boolean |
| 3421 | parse_adrp (char **str) |
| 3422 | { |
| 3423 | char *p; |
| 3424 | |
| 3425 | p = *str; |
| 3426 | if (*p == ':') |
| 3427 | { |
| 3428 | struct reloc_table_entry *entry; |
| 3429 | |
| 3430 | /* Try to parse a relocation. Anything else is an error. */ |
| 3431 | ++p; |
| 3432 | if (!(entry = find_reloc_table_entry (&p))) |
| 3433 | { |
| 3434 | set_syntax_error (_("unknown relocation modifier")); |
| 3435 | return FALSE; |
| 3436 | } |
| 3437 | |
| 3438 | if (entry->adrp_type == 0) |
| 3439 | { |
| 3440 | set_syntax_error |
| 3441 | (_("this relocation modifier is not allowed on this instruction")); |
| 3442 | return FALSE; |
| 3443 | } |
| 3444 | |
| 3445 | inst.reloc.type = entry->adrp_type; |
| 3446 | } |
| 3447 | else |
| 3448 | inst.reloc.type = BFD_RELOC_AARCH64_ADR_HI21_PCREL; |
| 3449 | |
| 3450 | inst.reloc.pc_rel = 1; |
| 3451 | |
| 3452 | if (! my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX, 1)) |
| 3453 | return FALSE; |
| 3454 | |
| 3455 | *str = p; |
| 3456 | return TRUE; |
| 3457 | } |
| 3458 | |
| 3459 | /* Miscellaneous. */ |
| 3460 | |
| 3461 | /* Parse an option for a preload instruction. Returns the encoding for the |
| 3462 | option, or PARSE_FAIL. */ |
| 3463 | |
| 3464 | static int |
| 3465 | parse_pldop (char **str) |
| 3466 | { |
| 3467 | char *p, *q; |
| 3468 | const struct aarch64_name_value_pair *o; |
| 3469 | |
| 3470 | p = q = *str; |
| 3471 | while (ISALNUM (*q)) |
| 3472 | q++; |
| 3473 | |
| 3474 | o = hash_find_n (aarch64_pldop_hsh, p, q - p); |
| 3475 | if (!o) |
| 3476 | return PARSE_FAIL; |
| 3477 | |
| 3478 | *str = q; |
| 3479 | return o->value; |
| 3480 | } |
| 3481 | |
| 3482 | /* Parse an option for a barrier instruction. Returns the encoding for the |
| 3483 | option, or PARSE_FAIL. */ |
| 3484 | |
| 3485 | static int |
| 3486 | parse_barrier (char **str) |
| 3487 | { |
| 3488 | char *p, *q; |
| 3489 | const asm_barrier_opt *o; |
| 3490 | |
| 3491 | p = q = *str; |
| 3492 | while (ISALPHA (*q)) |
| 3493 | q++; |
| 3494 | |
| 3495 | o = hash_find_n (aarch64_barrier_opt_hsh, p, q - p); |
| 3496 | if (!o) |
| 3497 | return PARSE_FAIL; |
| 3498 | |
| 3499 | *str = q; |
| 3500 | return o->value; |
| 3501 | } |
| 3502 | |
| 3503 | /* Parse a system register or a PSTATE field name for an MSR/MRS instruction. |
| 3504 | Returns the encoding for the option, or PARSE_FAIL. |
| 3505 | |
| 3506 | If IMPLE_DEFINED_P is non-zero, the function will also try to parse the |
| 3507 | implementation defined system register name S<op0>_<op1>_<Cn>_<Cm>_<op2>. |
| 3508 | |
| 3509 | If PSTATEFIELD_P is non-zero, the function will parse the name as a PSTATE |
| 3510 | field, otherwise as a system register. |
| 3511 | */ |
| 3512 | |
| 3513 | static int |
| 3514 | parse_sys_reg (char **str, struct hash_control *sys_regs, |
| 3515 | int imple_defined_p, int pstatefield_p) |
| 3516 | { |
| 3517 | char *p, *q; |
| 3518 | char buf[32]; |
| 3519 | const aarch64_sys_reg *o; |
| 3520 | int value; |
| 3521 | |
| 3522 | p = buf; |
| 3523 | for (q = *str; ISALNUM (*q) || *q == '_'; q++) |
| 3524 | if (p < buf + 31) |
| 3525 | *p++ = TOLOWER (*q); |
| 3526 | *p = '\0'; |
| 3527 | /* Assert that BUF be large enough. */ |
| 3528 | gas_assert (p - buf == q - *str); |
| 3529 | |
| 3530 | o = hash_find (sys_regs, buf); |
| 3531 | if (!o) |
| 3532 | { |
| 3533 | if (!imple_defined_p) |
| 3534 | return PARSE_FAIL; |
| 3535 | else |
| 3536 | { |
| 3537 | /* Parse S<op0>_<op1>_<Cn>_<Cm>_<op2>. */ |
| 3538 | unsigned int op0, op1, cn, cm, op2; |
| 3539 | |
| 3540 | if (sscanf (buf, "s%u_%u_c%u_c%u_%u", &op0, &op1, &cn, &cm, &op2) |
| 3541 | != 5) |
| 3542 | return PARSE_FAIL; |
| 3543 | if (op0 > 3 || op1 > 7 || cn > 15 || cm > 15 || op2 > 7) |
| 3544 | return PARSE_FAIL; |
| 3545 | value = (op0 << 14) | (op1 << 11) | (cn << 7) | (cm << 3) | op2; |
| 3546 | } |
| 3547 | } |
| 3548 | else |
| 3549 | { |
| 3550 | if (pstatefield_p && !aarch64_pstatefield_supported_p (cpu_variant, o)) |
| 3551 | as_bad (_("selected processor does not support PSTATE field " |
| 3552 | "name '%s'"), buf); |
| 3553 | if (!pstatefield_p && !aarch64_sys_reg_supported_p (cpu_variant, o)) |
| 3554 | as_bad (_("selected processor does not support system register " |
| 3555 | "name '%s'"), buf); |
| 3556 | if (aarch64_sys_reg_deprecated_p (o)) |
| 3557 | as_warn (_("system register name '%s' is deprecated and may be " |
| 3558 | "removed in a future release"), buf); |
| 3559 | value = o->value; |
| 3560 | } |
| 3561 | |
| 3562 | *str = q; |
| 3563 | return value; |
| 3564 | } |
| 3565 | |
| 3566 | /* Parse a system reg for ic/dc/at/tlbi instructions. Returns the table entry |
| 3567 | for the option, or NULL. */ |
| 3568 | |
| 3569 | static const aarch64_sys_ins_reg * |
| 3570 | parse_sys_ins_reg (char **str, struct hash_control *sys_ins_regs) |
| 3571 | { |
| 3572 | char *p, *q; |
| 3573 | char buf[32]; |
| 3574 | const aarch64_sys_ins_reg *o; |
| 3575 | |
| 3576 | p = buf; |
| 3577 | for (q = *str; ISALNUM (*q) || *q == '_'; q++) |
| 3578 | if (p < buf + 31) |
| 3579 | *p++ = TOLOWER (*q); |
| 3580 | *p = '\0'; |
| 3581 | |
| 3582 | o = hash_find (sys_ins_regs, buf); |
| 3583 | if (!o) |
| 3584 | return NULL; |
| 3585 | |
| 3586 | *str = q; |
| 3587 | return o; |
| 3588 | } |
| 3589 | \f |
| 3590 | #define po_char_or_fail(chr) do { \ |
| 3591 | if (! skip_past_char (&str, chr)) \ |
| 3592 | goto failure; \ |
| 3593 | } while (0) |
| 3594 | |
| 3595 | #define po_reg_or_fail(regtype) do { \ |
| 3596 | val = aarch64_reg_parse (&str, regtype, &rtype, NULL); \ |
| 3597 | if (val == PARSE_FAIL) \ |
| 3598 | { \ |
| 3599 | set_default_error (); \ |
| 3600 | goto failure; \ |
| 3601 | } \ |
| 3602 | } while (0) |
| 3603 | |
| 3604 | #define po_int_reg_or_fail(reject_sp, reject_rz) do { \ |
| 3605 | val = aarch64_reg_parse_32_64 (&str, reject_sp, reject_rz, \ |
| 3606 | &isreg32, &isregzero); \ |
| 3607 | if (val == PARSE_FAIL) \ |
| 3608 | { \ |
| 3609 | set_default_error (); \ |
| 3610 | goto failure; \ |
| 3611 | } \ |
| 3612 | info->reg.regno = val; \ |
| 3613 | if (isreg32) \ |
| 3614 | info->qualifier = AARCH64_OPND_QLF_W; \ |
| 3615 | else \ |
| 3616 | info->qualifier = AARCH64_OPND_QLF_X; \ |
| 3617 | } while (0) |
| 3618 | |
| 3619 | #define po_imm_nc_or_fail() do { \ |
| 3620 | if (! parse_constant_immediate (&str, &val)) \ |
| 3621 | goto failure; \ |
| 3622 | } while (0) |
| 3623 | |
| 3624 | #define po_imm_or_fail(min, max) do { \ |
| 3625 | if (! parse_constant_immediate (&str, &val)) \ |
| 3626 | goto failure; \ |
| 3627 | if (val < min || val > max) \ |
| 3628 | { \ |
| 3629 | set_fatal_syntax_error (_("immediate value out of range "\ |
| 3630 | #min " to "#max)); \ |
| 3631 | goto failure; \ |
| 3632 | } \ |
| 3633 | } while (0) |
| 3634 | |
| 3635 | #define po_misc_or_fail(expr) do { \ |
| 3636 | if (!expr) \ |
| 3637 | goto failure; \ |
| 3638 | } while (0) |
| 3639 | \f |
| 3640 | /* encode the 12-bit imm field of Add/sub immediate */ |
| 3641 | static inline uint32_t |
| 3642 | encode_addsub_imm (uint32_t imm) |
| 3643 | { |
| 3644 | return imm << 10; |
| 3645 | } |
| 3646 | |
| 3647 | /* encode the shift amount field of Add/sub immediate */ |
| 3648 | static inline uint32_t |
| 3649 | encode_addsub_imm_shift_amount (uint32_t cnt) |
| 3650 | { |
| 3651 | return cnt << 22; |
| 3652 | } |
| 3653 | |
| 3654 | |
| 3655 | /* encode the imm field of Adr instruction */ |
| 3656 | static inline uint32_t |
| 3657 | encode_adr_imm (uint32_t imm) |
| 3658 | { |
| 3659 | return (((imm & 0x3) << 29) /* [1:0] -> [30:29] */ |
| 3660 | | ((imm & (0x7ffff << 2)) << 3)); /* [20:2] -> [23:5] */ |
| 3661 | } |
| 3662 | |
| 3663 | /* encode the immediate field of Move wide immediate */ |
| 3664 | static inline uint32_t |
| 3665 | encode_movw_imm (uint32_t imm) |
| 3666 | { |
| 3667 | return imm << 5; |
| 3668 | } |
| 3669 | |
| 3670 | /* encode the 26-bit offset of unconditional branch */ |
| 3671 | static inline uint32_t |
| 3672 | encode_branch_ofs_26 (uint32_t ofs) |
| 3673 | { |
| 3674 | return ofs & ((1 << 26) - 1); |
| 3675 | } |
| 3676 | |
| 3677 | /* encode the 19-bit offset of conditional branch and compare & branch */ |
| 3678 | static inline uint32_t |
| 3679 | encode_cond_branch_ofs_19 (uint32_t ofs) |
| 3680 | { |
| 3681 | return (ofs & ((1 << 19) - 1)) << 5; |
| 3682 | } |
| 3683 | |
| 3684 | /* encode the 19-bit offset of ld literal */ |
| 3685 | static inline uint32_t |
| 3686 | encode_ld_lit_ofs_19 (uint32_t ofs) |
| 3687 | { |
| 3688 | return (ofs & ((1 << 19) - 1)) << 5; |
| 3689 | } |
| 3690 | |
| 3691 | /* Encode the 14-bit offset of test & branch. */ |
| 3692 | static inline uint32_t |
| 3693 | encode_tst_branch_ofs_14 (uint32_t ofs) |
| 3694 | { |
| 3695 | return (ofs & ((1 << 14) - 1)) << 5; |
| 3696 | } |
| 3697 | |
| 3698 | /* Encode the 16-bit imm field of svc/hvc/smc. */ |
| 3699 | static inline uint32_t |
| 3700 | encode_svc_imm (uint32_t imm) |
| 3701 | { |
| 3702 | return imm << 5; |
| 3703 | } |
| 3704 | |
| 3705 | /* Reencode add(s) to sub(s), or sub(s) to add(s). */ |
| 3706 | static inline uint32_t |
| 3707 | reencode_addsub_switch_add_sub (uint32_t opcode) |
| 3708 | { |
| 3709 | return opcode ^ (1 << 30); |
| 3710 | } |
| 3711 | |
| 3712 | static inline uint32_t |
| 3713 | reencode_movzn_to_movz (uint32_t opcode) |
| 3714 | { |
| 3715 | return opcode | (1 << 30); |
| 3716 | } |
| 3717 | |
| 3718 | static inline uint32_t |
| 3719 | reencode_movzn_to_movn (uint32_t opcode) |
| 3720 | { |
| 3721 | return opcode & ~(1 << 30); |
| 3722 | } |
| 3723 | |
| 3724 | /* Overall per-instruction processing. */ |
| 3725 | |
| 3726 | /* We need to be able to fix up arbitrary expressions in some statements. |
| 3727 | This is so that we can handle symbols that are an arbitrary distance from |
| 3728 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), |
| 3729 | which returns part of an address in a form which will be valid for |
| 3730 | a data instruction. We do this by pushing the expression into a symbol |
| 3731 | in the expr_section, and creating a fix for that. */ |
| 3732 | |
| 3733 | static fixS * |
| 3734 | fix_new_aarch64 (fragS * frag, |
| 3735 | int where, |
| 3736 | short int size, expressionS * exp, int pc_rel, int reloc) |
| 3737 | { |
| 3738 | fixS *new_fix; |
| 3739 | |
| 3740 | switch (exp->X_op) |
| 3741 | { |
| 3742 | case O_constant: |
| 3743 | case O_symbol: |
| 3744 | case O_add: |
| 3745 | case O_subtract: |
| 3746 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); |
| 3747 | break; |
| 3748 | |
| 3749 | default: |
| 3750 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, |
| 3751 | pc_rel, reloc); |
| 3752 | break; |
| 3753 | } |
| 3754 | return new_fix; |
| 3755 | } |
| 3756 | \f |
| 3757 | /* Diagnostics on operands errors. */ |
| 3758 | |
| 3759 | /* By default, output verbose error message. |
| 3760 | Disable the verbose error message by -mno-verbose-error. */ |
| 3761 | static int verbose_error_p = 1; |
| 3762 | |
| 3763 | #ifdef DEBUG_AARCH64 |
| 3764 | /* N.B. this is only for the purpose of debugging. */ |
| 3765 | const char* operand_mismatch_kind_names[] = |
| 3766 | { |
| 3767 | "AARCH64_OPDE_NIL", |
| 3768 | "AARCH64_OPDE_RECOVERABLE", |
| 3769 | "AARCH64_OPDE_SYNTAX_ERROR", |
| 3770 | "AARCH64_OPDE_FATAL_SYNTAX_ERROR", |
| 3771 | "AARCH64_OPDE_INVALID_VARIANT", |
| 3772 | "AARCH64_OPDE_OUT_OF_RANGE", |
| 3773 | "AARCH64_OPDE_UNALIGNED", |
| 3774 | "AARCH64_OPDE_REG_LIST", |
| 3775 | "AARCH64_OPDE_OTHER_ERROR", |
| 3776 | }; |
| 3777 | #endif /* DEBUG_AARCH64 */ |
| 3778 | |
| 3779 | /* Return TRUE if LHS is of higher severity than RHS, otherwise return FALSE. |
| 3780 | |
| 3781 | When multiple errors of different kinds are found in the same assembly |
| 3782 | line, only the error of the highest severity will be picked up for |
| 3783 | issuing the diagnostics. */ |
| 3784 | |
| 3785 | static inline bfd_boolean |
| 3786 | operand_error_higher_severity_p (enum aarch64_operand_error_kind lhs, |
| 3787 | enum aarch64_operand_error_kind rhs) |
| 3788 | { |
| 3789 | gas_assert (AARCH64_OPDE_RECOVERABLE > AARCH64_OPDE_NIL); |
| 3790 | gas_assert (AARCH64_OPDE_SYNTAX_ERROR > AARCH64_OPDE_RECOVERABLE); |
| 3791 | gas_assert (AARCH64_OPDE_FATAL_SYNTAX_ERROR > AARCH64_OPDE_SYNTAX_ERROR); |
| 3792 | gas_assert (AARCH64_OPDE_INVALID_VARIANT > AARCH64_OPDE_FATAL_SYNTAX_ERROR); |
| 3793 | gas_assert (AARCH64_OPDE_OUT_OF_RANGE > AARCH64_OPDE_INVALID_VARIANT); |
| 3794 | gas_assert (AARCH64_OPDE_UNALIGNED > AARCH64_OPDE_OUT_OF_RANGE); |
| 3795 | gas_assert (AARCH64_OPDE_REG_LIST > AARCH64_OPDE_UNALIGNED); |
| 3796 | gas_assert (AARCH64_OPDE_OTHER_ERROR > AARCH64_OPDE_REG_LIST); |
| 3797 | return lhs > rhs; |
| 3798 | } |
| 3799 | |
| 3800 | /* Helper routine to get the mnemonic name from the assembly instruction |
| 3801 | line; should only be called for the diagnosis purpose, as there is |
| 3802 | string copy operation involved, which may affect the runtime |
| 3803 | performance if used in elsewhere. */ |
| 3804 | |
| 3805 | static const char* |
| 3806 | get_mnemonic_name (const char *str) |
| 3807 | { |
| 3808 | static char mnemonic[32]; |
| 3809 | char *ptr; |
| 3810 | |
| 3811 | /* Get the first 15 bytes and assume that the full name is included. */ |
| 3812 | strncpy (mnemonic, str, 31); |
| 3813 | mnemonic[31] = '\0'; |
| 3814 | |
| 3815 | /* Scan up to the end of the mnemonic, which must end in white space, |
| 3816 | '.', or end of string. */ |
| 3817 | for (ptr = mnemonic; is_part_of_name(*ptr); ++ptr) |
| 3818 | ; |
| 3819 | |
| 3820 | *ptr = '\0'; |
| 3821 | |
| 3822 | /* Append '...' to the truncated long name. */ |
| 3823 | if (ptr - mnemonic == 31) |
| 3824 | mnemonic[28] = mnemonic[29] = mnemonic[30] = '.'; |
| 3825 | |
| 3826 | return mnemonic; |
| 3827 | } |
| 3828 | |
| 3829 | static void |
| 3830 | reset_aarch64_instruction (aarch64_instruction *instruction) |
| 3831 | { |
| 3832 | memset (instruction, '\0', sizeof (aarch64_instruction)); |
| 3833 | instruction->reloc.type = BFD_RELOC_UNUSED; |
| 3834 | } |
| 3835 | |
| 3836 | /* Data strutures storing one user error in the assembly code related to |
| 3837 | operands. */ |
| 3838 | |
| 3839 | struct operand_error_record |
| 3840 | { |
| 3841 | const aarch64_opcode *opcode; |
| 3842 | aarch64_operand_error detail; |
| 3843 | struct operand_error_record *next; |
| 3844 | }; |
| 3845 | |
| 3846 | typedef struct operand_error_record operand_error_record; |
| 3847 | |
| 3848 | struct operand_errors |
| 3849 | { |
| 3850 | operand_error_record *head; |
| 3851 | operand_error_record *tail; |
| 3852 | }; |
| 3853 | |
| 3854 | typedef struct operand_errors operand_errors; |
| 3855 | |
| 3856 | /* Top-level data structure reporting user errors for the current line of |
| 3857 | the assembly code. |
| 3858 | The way md_assemble works is that all opcodes sharing the same mnemonic |
| 3859 | name are iterated to find a match to the assembly line. In this data |
| 3860 | structure, each of the such opcodes will have one operand_error_record |
| 3861 | allocated and inserted. In other words, excessive errors related with |
| 3862 | a single opcode are disregarded. */ |
| 3863 | operand_errors operand_error_report; |
| 3864 | |
| 3865 | /* Free record nodes. */ |
| 3866 | static operand_error_record *free_opnd_error_record_nodes = NULL; |
| 3867 | |
| 3868 | /* Initialize the data structure that stores the operand mismatch |
| 3869 | information on assembling one line of the assembly code. */ |
| 3870 | static void |
| 3871 | init_operand_error_report (void) |
| 3872 | { |
| 3873 | if (operand_error_report.head != NULL) |
| 3874 | { |
| 3875 | gas_assert (operand_error_report.tail != NULL); |
| 3876 | operand_error_report.tail->next = free_opnd_error_record_nodes; |
| 3877 | free_opnd_error_record_nodes = operand_error_report.head; |
| 3878 | operand_error_report.head = NULL; |
| 3879 | operand_error_report.tail = NULL; |
| 3880 | return; |
| 3881 | } |
| 3882 | gas_assert (operand_error_report.tail == NULL); |
| 3883 | } |
| 3884 | |
| 3885 | /* Return TRUE if some operand error has been recorded during the |
| 3886 | parsing of the current assembly line using the opcode *OPCODE; |
| 3887 | otherwise return FALSE. */ |
| 3888 | static inline bfd_boolean |
| 3889 | opcode_has_operand_error_p (const aarch64_opcode *opcode) |
| 3890 | { |
| 3891 | operand_error_record *record = operand_error_report.head; |
| 3892 | return record && record->opcode == opcode; |
| 3893 | } |
| 3894 | |
| 3895 | /* Add the error record *NEW_RECORD to operand_error_report. The record's |
| 3896 | OPCODE field is initialized with OPCODE. |
| 3897 | N.B. only one record for each opcode, i.e. the maximum of one error is |
| 3898 | recorded for each instruction template. */ |
| 3899 | |
| 3900 | static void |
| 3901 | add_operand_error_record (const operand_error_record* new_record) |
| 3902 | { |
| 3903 | const aarch64_opcode *opcode = new_record->opcode; |
| 3904 | operand_error_record* record = operand_error_report.head; |
| 3905 | |
| 3906 | /* The record may have been created for this opcode. If not, we need |
| 3907 | to prepare one. */ |
| 3908 | if (! opcode_has_operand_error_p (opcode)) |
| 3909 | { |
| 3910 | /* Get one empty record. */ |
| 3911 | if (free_opnd_error_record_nodes == NULL) |
| 3912 | { |
| 3913 | record = xmalloc (sizeof (operand_error_record)); |
| 3914 | if (record == NULL) |
| 3915 | abort (); |
| 3916 | } |
| 3917 | else |
| 3918 | { |
| 3919 | record = free_opnd_error_record_nodes; |
| 3920 | free_opnd_error_record_nodes = record->next; |
| 3921 | } |
| 3922 | record->opcode = opcode; |
| 3923 | /* Insert at the head. */ |
| 3924 | record->next = operand_error_report.head; |
| 3925 | operand_error_report.head = record; |
| 3926 | if (operand_error_report.tail == NULL) |
| 3927 | operand_error_report.tail = record; |
| 3928 | } |
| 3929 | else if (record->detail.kind != AARCH64_OPDE_NIL |
| 3930 | && record->detail.index <= new_record->detail.index |
| 3931 | && operand_error_higher_severity_p (record->detail.kind, |
| 3932 | new_record->detail.kind)) |
| 3933 | { |
| 3934 | /* In the case of multiple errors found on operands related with a |
| 3935 | single opcode, only record the error of the leftmost operand and |
| 3936 | only if the error is of higher severity. */ |
| 3937 | DEBUG_TRACE ("error %s on operand %d not added to the report due to" |
| 3938 | " the existing error %s on operand %d", |
| 3939 | operand_mismatch_kind_names[new_record->detail.kind], |
| 3940 | new_record->detail.index, |
| 3941 | operand_mismatch_kind_names[record->detail.kind], |
| 3942 | record->detail.index); |
| 3943 | return; |
| 3944 | } |
| 3945 | |
| 3946 | record->detail = new_record->detail; |
| 3947 | } |
| 3948 | |
| 3949 | static inline void |
| 3950 | record_operand_error_info (const aarch64_opcode *opcode, |
| 3951 | aarch64_operand_error *error_info) |
| 3952 | { |
| 3953 | operand_error_record record; |
| 3954 | record.opcode = opcode; |
| 3955 | record.detail = *error_info; |
| 3956 | add_operand_error_record (&record); |
| 3957 | } |
| 3958 | |
| 3959 | /* Record an error of kind KIND and, if ERROR is not NULL, of the detailed |
| 3960 | error message *ERROR, for operand IDX (count from 0). */ |
| 3961 | |
| 3962 | static void |
| 3963 | record_operand_error (const aarch64_opcode *opcode, int idx, |
| 3964 | enum aarch64_operand_error_kind kind, |
| 3965 | const char* error) |
| 3966 | { |
| 3967 | aarch64_operand_error info; |
| 3968 | memset(&info, 0, sizeof (info)); |
| 3969 | info.index = idx; |
| 3970 | info.kind = kind; |
| 3971 | info.error = error; |
| 3972 | record_operand_error_info (opcode, &info); |
| 3973 | } |
| 3974 | |
| 3975 | static void |
| 3976 | record_operand_error_with_data (const aarch64_opcode *opcode, int idx, |
| 3977 | enum aarch64_operand_error_kind kind, |
| 3978 | const char* error, const int *extra_data) |
| 3979 | { |
| 3980 | aarch64_operand_error info; |
| 3981 | info.index = idx; |
| 3982 | info.kind = kind; |
| 3983 | info.error = error; |
| 3984 | info.data[0] = extra_data[0]; |
| 3985 | info.data[1] = extra_data[1]; |
| 3986 | info.data[2] = extra_data[2]; |
| 3987 | record_operand_error_info (opcode, &info); |
| 3988 | } |
| 3989 | |
| 3990 | static void |
| 3991 | record_operand_out_of_range_error (const aarch64_opcode *opcode, int idx, |
| 3992 | const char* error, int lower_bound, |
| 3993 | int upper_bound) |
| 3994 | { |
| 3995 | int data[3] = {lower_bound, upper_bound, 0}; |
| 3996 | record_operand_error_with_data (opcode, idx, AARCH64_OPDE_OUT_OF_RANGE, |
| 3997 | error, data); |
| 3998 | } |
| 3999 | |
| 4000 | /* Remove the operand error record for *OPCODE. */ |
| 4001 | static void ATTRIBUTE_UNUSED |
| 4002 | remove_operand_error_record (const aarch64_opcode *opcode) |
| 4003 | { |
| 4004 | if (opcode_has_operand_error_p (opcode)) |
| 4005 | { |
| 4006 | operand_error_record* record = operand_error_report.head; |
| 4007 | gas_assert (record != NULL && operand_error_report.tail != NULL); |
| 4008 | operand_error_report.head = record->next; |
| 4009 | record->next = free_opnd_error_record_nodes; |
| 4010 | free_opnd_error_record_nodes = record; |
| 4011 | if (operand_error_report.head == NULL) |
| 4012 | { |
| 4013 | gas_assert (operand_error_report.tail == record); |
| 4014 | operand_error_report.tail = NULL; |
| 4015 | } |
| 4016 | } |
| 4017 | } |
| 4018 | |
| 4019 | /* Given the instruction in *INSTR, return the index of the best matched |
| 4020 | qualifier sequence in the list (an array) headed by QUALIFIERS_LIST. |
| 4021 | |
| 4022 | Return -1 if there is no qualifier sequence; return the first match |
| 4023 | if there is multiple matches found. */ |
| 4024 | |
| 4025 | static int |
| 4026 | find_best_match (const aarch64_inst *instr, |
| 4027 | const aarch64_opnd_qualifier_seq_t *qualifiers_list) |
| 4028 | { |
| 4029 | int i, num_opnds, max_num_matched, idx; |
| 4030 | |
| 4031 | num_opnds = aarch64_num_of_operands (instr->opcode); |
| 4032 | if (num_opnds == 0) |
| 4033 | { |
| 4034 | DEBUG_TRACE ("no operand"); |
| 4035 | return -1; |
| 4036 | } |
| 4037 | |
| 4038 | max_num_matched = 0; |
| 4039 | idx = -1; |
| 4040 | |
| 4041 | /* For each pattern. */ |
| 4042 | for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list) |
| 4043 | { |
| 4044 | int j, num_matched; |
| 4045 | const aarch64_opnd_qualifier_t *qualifiers = *qualifiers_list; |
| 4046 | |
| 4047 | /* Most opcodes has much fewer patterns in the list. */ |
| 4048 | if (empty_qualifier_sequence_p (qualifiers) == TRUE) |
| 4049 | { |
| 4050 | DEBUG_TRACE_IF (i == 0, "empty list of qualifier sequence"); |
| 4051 | if (i != 0 && idx == -1) |
| 4052 | /* If nothing has been matched, return the 1st sequence. */ |
| 4053 | idx = 0; |
| 4054 | break; |
| 4055 | } |
| 4056 | |
| 4057 | for (j = 0, num_matched = 0; j < num_opnds; ++j, ++qualifiers) |
| 4058 | if (*qualifiers == instr->operands[j].qualifier) |
| 4059 | ++num_matched; |
| 4060 | |
| 4061 | if (num_matched > max_num_matched) |
| 4062 | { |
| 4063 | max_num_matched = num_matched; |
| 4064 | idx = i; |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | DEBUG_TRACE ("return with %d", idx); |
| 4069 | return idx; |
| 4070 | } |
| 4071 | |
| 4072 | /* Assign qualifiers in the qualifier seqence (headed by QUALIFIERS) to the |
| 4073 | corresponding operands in *INSTR. */ |
| 4074 | |
| 4075 | static inline void |
| 4076 | assign_qualifier_sequence (aarch64_inst *instr, |
| 4077 | const aarch64_opnd_qualifier_t *qualifiers) |
| 4078 | { |
| 4079 | int i = 0; |
| 4080 | int num_opnds = aarch64_num_of_operands (instr->opcode); |
| 4081 | gas_assert (num_opnds); |
| 4082 | for (i = 0; i < num_opnds; ++i, ++qualifiers) |
| 4083 | instr->operands[i].qualifier = *qualifiers; |
| 4084 | } |
| 4085 | |
| 4086 | /* Print operands for the diagnosis purpose. */ |
| 4087 | |
| 4088 | static void |
| 4089 | print_operands (char *buf, const aarch64_opcode *opcode, |
| 4090 | const aarch64_opnd_info *opnds) |
| 4091 | { |
| 4092 | int i; |
| 4093 | |
| 4094 | for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i) |
| 4095 | { |
| 4096 | const size_t size = 128; |
| 4097 | char str[size]; |
| 4098 | |
| 4099 | /* We regard the opcode operand info more, however we also look into |
| 4100 | the inst->operands to support the disassembling of the optional |
| 4101 | operand. |
| 4102 | The two operand code should be the same in all cases, apart from |
| 4103 | when the operand can be optional. */ |
| 4104 | if (opcode->operands[i] == AARCH64_OPND_NIL |
| 4105 | || opnds[i].type == AARCH64_OPND_NIL) |
| 4106 | break; |
| 4107 | |
| 4108 | /* Generate the operand string in STR. */ |
| 4109 | aarch64_print_operand (str, size, 0, opcode, opnds, i, NULL, NULL); |
| 4110 | |
| 4111 | /* Delimiter. */ |
| 4112 | if (str[0] != '\0') |
| 4113 | strcat (buf, i == 0 ? " " : ","); |
| 4114 | |
| 4115 | /* Append the operand string. */ |
| 4116 | strcat (buf, str); |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | /* Send to stderr a string as information. */ |
| 4121 | |
| 4122 | static void |
| 4123 | output_info (const char *format, ...) |
| 4124 | { |
| 4125 | char *file; |
| 4126 | unsigned int line; |
| 4127 | va_list args; |
| 4128 | |
| 4129 | as_where (&file, &line); |
| 4130 | if (file) |
| 4131 | { |
| 4132 | if (line != 0) |
| 4133 | fprintf (stderr, "%s:%u: ", file, line); |
| 4134 | else |
| 4135 | fprintf (stderr, "%s: ", file); |
| 4136 | } |
| 4137 | fprintf (stderr, _("Info: ")); |
| 4138 | va_start (args, format); |
| 4139 | vfprintf (stderr, format, args); |
| 4140 | va_end (args); |
| 4141 | (void) putc ('\n', stderr); |
| 4142 | } |
| 4143 | |
| 4144 | /* Output one operand error record. */ |
| 4145 | |
| 4146 | static void |
| 4147 | output_operand_error_record (const operand_error_record *record, char *str) |
| 4148 | { |
| 4149 | const aarch64_operand_error *detail = &record->detail; |
| 4150 | int idx = detail->index; |
| 4151 | const aarch64_opcode *opcode = record->opcode; |
| 4152 | enum aarch64_opnd opd_code = (idx >= 0 ? opcode->operands[idx] |
| 4153 | : AARCH64_OPND_NIL); |
| 4154 | |
| 4155 | switch (detail->kind) |
| 4156 | { |
| 4157 | case AARCH64_OPDE_NIL: |
| 4158 | gas_assert (0); |
| 4159 | break; |
| 4160 | |
| 4161 | case AARCH64_OPDE_SYNTAX_ERROR: |
| 4162 | case AARCH64_OPDE_RECOVERABLE: |
| 4163 | case AARCH64_OPDE_FATAL_SYNTAX_ERROR: |
| 4164 | case AARCH64_OPDE_OTHER_ERROR: |
| 4165 | /* Use the prepared error message if there is, otherwise use the |
| 4166 | operand description string to describe the error. */ |
| 4167 | if (detail->error != NULL) |
| 4168 | { |
| 4169 | if (idx < 0) |
| 4170 | as_bad (_("%s -- `%s'"), detail->error, str); |
| 4171 | else |
| 4172 | as_bad (_("%s at operand %d -- `%s'"), |
| 4173 | detail->error, idx + 1, str); |
| 4174 | } |
| 4175 | else |
| 4176 | { |
| 4177 | gas_assert (idx >= 0); |
| 4178 | as_bad (_("operand %d should be %s -- `%s'"), idx + 1, |
| 4179 | aarch64_get_operand_desc (opd_code), str); |
| 4180 | } |
| 4181 | break; |
| 4182 | |
| 4183 | case AARCH64_OPDE_INVALID_VARIANT: |
| 4184 | as_bad (_("operand mismatch -- `%s'"), str); |
| 4185 | if (verbose_error_p) |
| 4186 | { |
| 4187 | /* We will try to correct the erroneous instruction and also provide |
| 4188 | more information e.g. all other valid variants. |
| 4189 | |
| 4190 | The string representation of the corrected instruction and other |
| 4191 | valid variants are generated by |
| 4192 | |
| 4193 | 1) obtaining the intermediate representation of the erroneous |
| 4194 | instruction; |
| 4195 | 2) manipulating the IR, e.g. replacing the operand qualifier; |
| 4196 | 3) printing out the instruction by calling the printer functions |
| 4197 | shared with the disassembler. |
| 4198 | |
| 4199 | The limitation of this method is that the exact input assembly |
| 4200 | line cannot be accurately reproduced in some cases, for example an |
| 4201 | optional operand present in the actual assembly line will be |
| 4202 | omitted in the output; likewise for the optional syntax rules, |
| 4203 | e.g. the # before the immediate. Another limitation is that the |
| 4204 | assembly symbols and relocation operations in the assembly line |
| 4205 | currently cannot be printed out in the error report. Last but not |
| 4206 | least, when there is other error(s) co-exist with this error, the |
| 4207 | 'corrected' instruction may be still incorrect, e.g. given |
| 4208 | 'ldnp h0,h1,[x0,#6]!' |
| 4209 | this diagnosis will provide the version: |
| 4210 | 'ldnp s0,s1,[x0,#6]!' |
| 4211 | which is still not right. */ |
| 4212 | size_t len = strlen (get_mnemonic_name (str)); |
| 4213 | int i, qlf_idx; |
| 4214 | bfd_boolean result; |
| 4215 | const size_t size = 2048; |
| 4216 | char buf[size]; |
| 4217 | aarch64_inst *inst_base = &inst.base; |
| 4218 | const aarch64_opnd_qualifier_seq_t *qualifiers_list; |
| 4219 | |
| 4220 | /* Init inst. */ |
| 4221 | reset_aarch64_instruction (&inst); |
| 4222 | inst_base->opcode = opcode; |
| 4223 | |
| 4224 | /* Reset the error report so that there is no side effect on the |
| 4225 | following operand parsing. */ |
| 4226 | init_operand_error_report (); |
| 4227 | |
| 4228 | /* Fill inst. */ |
| 4229 | result = parse_operands (str + len, opcode) |
| 4230 | && programmer_friendly_fixup (&inst); |
| 4231 | gas_assert (result); |
| 4232 | result = aarch64_opcode_encode (opcode, inst_base, &inst_base->value, |
| 4233 | NULL, NULL); |
| 4234 | gas_assert (!result); |
| 4235 | |
| 4236 | /* Find the most matched qualifier sequence. */ |
| 4237 | qlf_idx = find_best_match (inst_base, opcode->qualifiers_list); |
| 4238 | gas_assert (qlf_idx > -1); |
| 4239 | |
| 4240 | /* Assign the qualifiers. */ |
| 4241 | assign_qualifier_sequence (inst_base, |
| 4242 | opcode->qualifiers_list[qlf_idx]); |
| 4243 | |
| 4244 | /* Print the hint. */ |
| 4245 | output_info (_(" did you mean this?")); |
| 4246 | snprintf (buf, size, "\t%s", get_mnemonic_name (str)); |
| 4247 | print_operands (buf, opcode, inst_base->operands); |
| 4248 | output_info (_(" %s"), buf); |
| 4249 | |
| 4250 | /* Print out other variant(s) if there is any. */ |
| 4251 | if (qlf_idx != 0 || |
| 4252 | !empty_qualifier_sequence_p (opcode->qualifiers_list[1])) |
| 4253 | output_info (_(" other valid variant(s):")); |
| 4254 | |
| 4255 | /* For each pattern. */ |
| 4256 | qualifiers_list = opcode->qualifiers_list; |
| 4257 | for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list) |
| 4258 | { |
| 4259 | /* Most opcodes has much fewer patterns in the list. |
| 4260 | First NIL qualifier indicates the end in the list. */ |
| 4261 | if (empty_qualifier_sequence_p (*qualifiers_list) == TRUE) |
| 4262 | break; |
| 4263 | |
| 4264 | if (i != qlf_idx) |
| 4265 | { |
| 4266 | /* Mnemonics name. */ |
| 4267 | snprintf (buf, size, "\t%s", get_mnemonic_name (str)); |
| 4268 | |
| 4269 | /* Assign the qualifiers. */ |
| 4270 | assign_qualifier_sequence (inst_base, *qualifiers_list); |
| 4271 | |
| 4272 | /* Print instruction. */ |
| 4273 | print_operands (buf, opcode, inst_base->operands); |
| 4274 | |
| 4275 | output_info (_(" %s"), buf); |
| 4276 | } |
| 4277 | } |
| 4278 | } |
| 4279 | break; |
| 4280 | |
| 4281 | case AARCH64_OPDE_OUT_OF_RANGE: |
| 4282 | if (detail->data[0] != detail->data[1]) |
| 4283 | as_bad (_("%s out of range %d to %d at operand %d -- `%s'"), |
| 4284 | detail->error ? detail->error : _("immediate value"), |
| 4285 | detail->data[0], detail->data[1], idx + 1, str); |
| 4286 | else |
| 4287 | as_bad (_("%s expected to be %d at operand %d -- `%s'"), |
| 4288 | detail->error ? detail->error : _("immediate value"), |
| 4289 | detail->data[0], idx + 1, str); |
| 4290 | break; |
| 4291 | |
| 4292 | case AARCH64_OPDE_REG_LIST: |
| 4293 | if (detail->data[0] == 1) |
| 4294 | as_bad (_("invalid number of registers in the list; " |
| 4295 | "only 1 register is expected at operand %d -- `%s'"), |
| 4296 | idx + 1, str); |
| 4297 | else |
| 4298 | as_bad (_("invalid number of registers in the list; " |
| 4299 | "%d registers are expected at operand %d -- `%s'"), |
| 4300 | detail->data[0], idx + 1, str); |
| 4301 | break; |
| 4302 | |
| 4303 | case AARCH64_OPDE_UNALIGNED: |
| 4304 | as_bad (_("immediate value should be a multiple of " |
| 4305 | "%d at operand %d -- `%s'"), |
| 4306 | detail->data[0], idx + 1, str); |
| 4307 | break; |
| 4308 | |
| 4309 | default: |
| 4310 | gas_assert (0); |
| 4311 | break; |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | /* Process and output the error message about the operand mismatching. |
| 4316 | |
| 4317 | When this function is called, the operand error information had |
| 4318 | been collected for an assembly line and there will be multiple |
| 4319 | errors in the case of mulitple instruction templates; output the |
| 4320 | error message that most closely describes the problem. */ |
| 4321 | |
| 4322 | static void |
| 4323 | output_operand_error_report (char *str) |
| 4324 | { |
| 4325 | int largest_error_pos; |
| 4326 | const char *msg = NULL; |
| 4327 | enum aarch64_operand_error_kind kind; |
| 4328 | operand_error_record *curr; |
| 4329 | operand_error_record *head = operand_error_report.head; |
| 4330 | operand_error_record *record = NULL; |
| 4331 | |
| 4332 | /* No error to report. */ |
| 4333 | if (head == NULL) |
| 4334 | return; |
| 4335 | |
| 4336 | gas_assert (head != NULL && operand_error_report.tail != NULL); |
| 4337 | |
| 4338 | /* Only one error. */ |
| 4339 | if (head == operand_error_report.tail) |
| 4340 | { |
| 4341 | DEBUG_TRACE ("single opcode entry with error kind: %s", |
| 4342 | operand_mismatch_kind_names[head->detail.kind]); |
| 4343 | output_operand_error_record (head, str); |
| 4344 | return; |
| 4345 | } |
| 4346 | |
| 4347 | /* Find the error kind of the highest severity. */ |
| 4348 | DEBUG_TRACE ("multiple opcode entres with error kind"); |
| 4349 | kind = AARCH64_OPDE_NIL; |
| 4350 | for (curr = head; curr != NULL; curr = curr->next) |
| 4351 | { |
| 4352 | gas_assert (curr->detail.kind != AARCH64_OPDE_NIL); |
| 4353 | DEBUG_TRACE ("\t%s", operand_mismatch_kind_names[curr->detail.kind]); |
| 4354 | if (operand_error_higher_severity_p (curr->detail.kind, kind)) |
| 4355 | kind = curr->detail.kind; |
| 4356 | } |
| 4357 | gas_assert (kind != AARCH64_OPDE_NIL); |
| 4358 | |
| 4359 | /* Pick up one of errors of KIND to report. */ |
| 4360 | largest_error_pos = -2; /* Index can be -1 which means unknown index. */ |
| 4361 | for (curr = head; curr != NULL; curr = curr->next) |
| 4362 | { |
| 4363 | if (curr->detail.kind != kind) |
| 4364 | continue; |
| 4365 | /* If there are multiple errors, pick up the one with the highest |
| 4366 | mismatching operand index. In the case of multiple errors with |
| 4367 | the equally highest operand index, pick up the first one or the |
| 4368 | first one with non-NULL error message. */ |
| 4369 | if (curr->detail.index > largest_error_pos |
| 4370 | || (curr->detail.index == largest_error_pos && msg == NULL |
| 4371 | && curr->detail.error != NULL)) |
| 4372 | { |
| 4373 | largest_error_pos = curr->detail.index; |
| 4374 | record = curr; |
| 4375 | msg = record->detail.error; |
| 4376 | } |
| 4377 | } |
| 4378 | |
| 4379 | gas_assert (largest_error_pos != -2 && record != NULL); |
| 4380 | DEBUG_TRACE ("Pick up error kind %s to report", |
| 4381 | operand_mismatch_kind_names[record->detail.kind]); |
| 4382 | |
| 4383 | /* Output. */ |
| 4384 | output_operand_error_record (record, str); |
| 4385 | } |
| 4386 | \f |
| 4387 | /* Write an AARCH64 instruction to buf - always little-endian. */ |
| 4388 | static void |
| 4389 | put_aarch64_insn (char *buf, uint32_t insn) |
| 4390 | { |
| 4391 | unsigned char *where = (unsigned char *) buf; |
| 4392 | where[0] = insn; |
| 4393 | where[1] = insn >> 8; |
| 4394 | where[2] = insn >> 16; |
| 4395 | where[3] = insn >> 24; |
| 4396 | } |
| 4397 | |
| 4398 | static uint32_t |
| 4399 | get_aarch64_insn (char *buf) |
| 4400 | { |
| 4401 | unsigned char *where = (unsigned char *) buf; |
| 4402 | uint32_t result; |
| 4403 | result = (where[0] | (where[1] << 8) | (where[2] << 16) | (where[3] << 24)); |
| 4404 | return result; |
| 4405 | } |
| 4406 | |
| 4407 | static void |
| 4408 | output_inst (struct aarch64_inst *new_inst) |
| 4409 | { |
| 4410 | char *to = NULL; |
| 4411 | |
| 4412 | to = frag_more (INSN_SIZE); |
| 4413 | |
| 4414 | frag_now->tc_frag_data.recorded = 1; |
| 4415 | |
| 4416 | put_aarch64_insn (to, inst.base.value); |
| 4417 | |
| 4418 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
| 4419 | { |
| 4420 | fixS *fixp = fix_new_aarch64 (frag_now, to - frag_now->fr_literal, |
| 4421 | INSN_SIZE, &inst.reloc.exp, |
| 4422 | inst.reloc.pc_rel, |
| 4423 | inst.reloc.type); |
| 4424 | DEBUG_TRACE ("Prepared relocation fix up"); |
| 4425 | /* Don't check the addend value against the instruction size, |
| 4426 | that's the job of our code in md_apply_fix(). */ |
| 4427 | fixp->fx_no_overflow = 1; |
| 4428 | if (new_inst != NULL) |
| 4429 | fixp->tc_fix_data.inst = new_inst; |
| 4430 | if (aarch64_gas_internal_fixup_p ()) |
| 4431 | { |
| 4432 | gas_assert (inst.reloc.opnd != AARCH64_OPND_NIL); |
| 4433 | fixp->tc_fix_data.opnd = inst.reloc.opnd; |
| 4434 | fixp->fx_addnumber = inst.reloc.flags; |
| 4435 | } |
| 4436 | } |
| 4437 | |
| 4438 | dwarf2_emit_insn (INSN_SIZE); |
| 4439 | } |
| 4440 | |
| 4441 | /* Link together opcodes of the same name. */ |
| 4442 | |
| 4443 | struct templates |
| 4444 | { |
| 4445 | aarch64_opcode *opcode; |
| 4446 | struct templates *next; |
| 4447 | }; |
| 4448 | |
| 4449 | typedef struct templates templates; |
| 4450 | |
| 4451 | static templates * |
| 4452 | lookup_mnemonic (const char *start, int len) |
| 4453 | { |
| 4454 | templates *templ = NULL; |
| 4455 | |
| 4456 | templ = hash_find_n (aarch64_ops_hsh, start, len); |
| 4457 | return templ; |
| 4458 | } |
| 4459 | |
| 4460 | /* Subroutine of md_assemble, responsible for looking up the primary |
| 4461 | opcode from the mnemonic the user wrote. STR points to the |
| 4462 | beginning of the mnemonic. */ |
| 4463 | |
| 4464 | static templates * |
| 4465 | opcode_lookup (char **str) |
| 4466 | { |
| 4467 | char *end, *base; |
| 4468 | const aarch64_cond *cond; |
| 4469 | char condname[16]; |
| 4470 | int len; |
| 4471 | |
| 4472 | /* Scan up to the end of the mnemonic, which must end in white space, |
| 4473 | '.', or end of string. */ |
| 4474 | for (base = end = *str; is_part_of_name(*end); end++) |
| 4475 | if (*end == '.') |
| 4476 | break; |
| 4477 | |
| 4478 | if (end == base) |
| 4479 | return 0; |
| 4480 | |
| 4481 | inst.cond = COND_ALWAYS; |
| 4482 | |
| 4483 | /* Handle a possible condition. */ |
| 4484 | if (end[0] == '.') |
| 4485 | { |
| 4486 | cond = hash_find_n (aarch64_cond_hsh, end + 1, 2); |
| 4487 | if (cond) |
| 4488 | { |
| 4489 | inst.cond = cond->value; |
| 4490 | *str = end + 3; |
| 4491 | } |
| 4492 | else |
| 4493 | { |
| 4494 | *str = end; |
| 4495 | return 0; |
| 4496 | } |
| 4497 | } |
| 4498 | else |
| 4499 | *str = end; |
| 4500 | |
| 4501 | len = end - base; |
| 4502 | |
| 4503 | if (inst.cond == COND_ALWAYS) |
| 4504 | { |
| 4505 | /* Look for unaffixed mnemonic. */ |
| 4506 | return lookup_mnemonic (base, len); |
| 4507 | } |
| 4508 | else if (len <= 13) |
| 4509 | { |
| 4510 | /* append ".c" to mnemonic if conditional */ |
| 4511 | memcpy (condname, base, len); |
| 4512 | memcpy (condname + len, ".c", 2); |
| 4513 | base = condname; |
| 4514 | len += 2; |
| 4515 | return lookup_mnemonic (base, len); |
| 4516 | } |
| 4517 | |
| 4518 | return NULL; |
| 4519 | } |
| 4520 | |
| 4521 | /* Internal helper routine converting a vector neon_type_el structure |
| 4522 | *VECTYPE to a corresponding operand qualifier. */ |
| 4523 | |
| 4524 | static inline aarch64_opnd_qualifier_t |
| 4525 | vectype_to_qualifier (const struct neon_type_el *vectype) |
| 4526 | { |
| 4527 | /* Element size in bytes indexed by neon_el_type. */ |
| 4528 | const unsigned char ele_size[5] |
| 4529 | = {1, 2, 4, 8, 16}; |
| 4530 | |
| 4531 | if (!vectype->defined || vectype->type == NT_invtype) |
| 4532 | goto vectype_conversion_fail; |
| 4533 | |
| 4534 | gas_assert (vectype->type >= NT_b && vectype->type <= NT_q); |
| 4535 | |
| 4536 | if (vectype->defined & NTA_HASINDEX) |
| 4537 | /* Vector element register. */ |
| 4538 | return AARCH64_OPND_QLF_S_B + vectype->type; |
| 4539 | else |
| 4540 | { |
| 4541 | /* Vector register. */ |
| 4542 | int reg_size = ele_size[vectype->type] * vectype->width; |
| 4543 | unsigned offset; |
| 4544 | if (reg_size != 16 && reg_size != 8) |
| 4545 | goto vectype_conversion_fail; |
| 4546 | /* The conversion is calculated based on the relation of the order of |
| 4547 | qualifiers to the vector element size and vector register size. */ |
| 4548 | offset = (vectype->type == NT_q) |
| 4549 | ? 8 : (vectype->type << 1) + (reg_size >> 4); |
| 4550 | gas_assert (offset <= 8); |
| 4551 | return AARCH64_OPND_QLF_V_8B + offset; |
| 4552 | } |
| 4553 | |
| 4554 | vectype_conversion_fail: |
| 4555 | first_error (_("bad vector arrangement type")); |
| 4556 | return AARCH64_OPND_QLF_NIL; |
| 4557 | } |
| 4558 | |
| 4559 | /* Process an optional operand that is found omitted from the assembly line. |
| 4560 | Fill *OPERAND for such an operand of type TYPE. OPCODE points to the |
| 4561 | instruction's opcode entry while IDX is the index of this omitted operand. |
| 4562 | */ |
| 4563 | |
| 4564 | static void |
| 4565 | process_omitted_operand (enum aarch64_opnd type, const aarch64_opcode *opcode, |
| 4566 | int idx, aarch64_opnd_info *operand) |
| 4567 | { |
| 4568 | aarch64_insn default_value = get_optional_operand_default_value (opcode); |
| 4569 | gas_assert (optional_operand_p (opcode, idx)); |
| 4570 | gas_assert (!operand->present); |
| 4571 | |
| 4572 | switch (type) |
| 4573 | { |
| 4574 | case AARCH64_OPND_Rd: |
| 4575 | case AARCH64_OPND_Rn: |
| 4576 | case AARCH64_OPND_Rm: |
| 4577 | case AARCH64_OPND_Rt: |
| 4578 | case AARCH64_OPND_Rt2: |
| 4579 | case AARCH64_OPND_Rs: |
| 4580 | case AARCH64_OPND_Ra: |
| 4581 | case AARCH64_OPND_Rt_SYS: |
| 4582 | case AARCH64_OPND_Rd_SP: |
| 4583 | case AARCH64_OPND_Rn_SP: |
| 4584 | case AARCH64_OPND_Fd: |
| 4585 | case AARCH64_OPND_Fn: |
| 4586 | case AARCH64_OPND_Fm: |
| 4587 | case AARCH64_OPND_Fa: |
| 4588 | case AARCH64_OPND_Ft: |
| 4589 | case AARCH64_OPND_Ft2: |
| 4590 | case AARCH64_OPND_Sd: |
| 4591 | case AARCH64_OPND_Sn: |
| 4592 | case AARCH64_OPND_Sm: |
| 4593 | case AARCH64_OPND_Vd: |
| 4594 | case AARCH64_OPND_Vn: |
| 4595 | case AARCH64_OPND_Vm: |
| 4596 | case AARCH64_OPND_VdD1: |
| 4597 | case AARCH64_OPND_VnD1: |
| 4598 | operand->reg.regno = default_value; |
| 4599 | break; |
| 4600 | |
| 4601 | case AARCH64_OPND_Ed: |
| 4602 | case AARCH64_OPND_En: |
| 4603 | case AARCH64_OPND_Em: |
| 4604 | operand->reglane.regno = default_value; |
| 4605 | break; |
| 4606 | |
| 4607 | case AARCH64_OPND_IDX: |
| 4608 | case AARCH64_OPND_BIT_NUM: |
| 4609 | case AARCH64_OPND_IMMR: |
| 4610 | case AARCH64_OPND_IMMS: |
| 4611 | case AARCH64_OPND_SHLL_IMM: |
| 4612 | case AARCH64_OPND_IMM_VLSL: |
| 4613 | case AARCH64_OPND_IMM_VLSR: |
| 4614 | case AARCH64_OPND_CCMP_IMM: |
| 4615 | case AARCH64_OPND_FBITS: |
| 4616 | case AARCH64_OPND_UIMM4: |
| 4617 | case AARCH64_OPND_UIMM3_OP1: |
| 4618 | case AARCH64_OPND_UIMM3_OP2: |
| 4619 | case AARCH64_OPND_IMM: |
| 4620 | case AARCH64_OPND_WIDTH: |
| 4621 | case AARCH64_OPND_UIMM7: |
| 4622 | case AARCH64_OPND_NZCV: |
| 4623 | operand->imm.value = default_value; |
| 4624 | break; |
| 4625 | |
| 4626 | case AARCH64_OPND_EXCEPTION: |
| 4627 | inst.reloc.type = BFD_RELOC_UNUSED; |
| 4628 | break; |
| 4629 | |
| 4630 | case AARCH64_OPND_BARRIER_ISB: |
| 4631 | operand->barrier = aarch64_barrier_options + default_value; |
| 4632 | |
| 4633 | default: |
| 4634 | break; |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | /* Process the relocation type for move wide instructions. |
| 4639 | Return TRUE on success; otherwise return FALSE. */ |
| 4640 | |
| 4641 | static bfd_boolean |
| 4642 | process_movw_reloc_info (void) |
| 4643 | { |
| 4644 | int is32; |
| 4645 | unsigned shift; |
| 4646 | |
| 4647 | is32 = inst.base.operands[0].qualifier == AARCH64_OPND_QLF_W ? 1 : 0; |
| 4648 | |
| 4649 | if (inst.base.opcode->op == OP_MOVK) |
| 4650 | switch (inst.reloc.type) |
| 4651 | { |
| 4652 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
| 4653 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
| 4654 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
| 4655 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
| 4656 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
| 4657 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
| 4658 | set_syntax_error |
| 4659 | (_("the specified relocation type is not allowed for MOVK")); |
| 4660 | return FALSE; |
| 4661 | default: |
| 4662 | break; |
| 4663 | } |
| 4664 | |
| 4665 | switch (inst.reloc.type) |
| 4666 | { |
| 4667 | case BFD_RELOC_AARCH64_MOVW_G0: |
| 4668 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
| 4669 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
| 4670 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
| 4671 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: |
| 4672 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
| 4673 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: |
| 4674 | shift = 0; |
| 4675 | break; |
| 4676 | case BFD_RELOC_AARCH64_MOVW_G1: |
| 4677 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
| 4678 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
| 4679 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: |
| 4680 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: |
| 4681 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
| 4682 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: |
| 4683 | shift = 16; |
| 4684 | break; |
| 4685 | case BFD_RELOC_AARCH64_MOVW_G2: |
| 4686 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
| 4687 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
| 4688 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: |
| 4689 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
| 4690 | if (is32) |
| 4691 | { |
| 4692 | set_fatal_syntax_error |
| 4693 | (_("the specified relocation type is not allowed for 32-bit " |
| 4694 | "register")); |
| 4695 | return FALSE; |
| 4696 | } |
| 4697 | shift = 32; |
| 4698 | break; |
| 4699 | case BFD_RELOC_AARCH64_MOVW_G3: |
| 4700 | if (is32) |
| 4701 | { |
| 4702 | set_fatal_syntax_error |
| 4703 | (_("the specified relocation type is not allowed for 32-bit " |
| 4704 | "register")); |
| 4705 | return FALSE; |
| 4706 | } |
| 4707 | shift = 48; |
| 4708 | break; |
| 4709 | default: |
| 4710 | /* More cases should be added when more MOVW-related relocation types |
| 4711 | are supported in GAS. */ |
| 4712 | gas_assert (aarch64_gas_internal_fixup_p ()); |
| 4713 | /* The shift amount should have already been set by the parser. */ |
| 4714 | return TRUE; |
| 4715 | } |
| 4716 | inst.base.operands[1].shifter.amount = shift; |
| 4717 | return TRUE; |
| 4718 | } |
| 4719 | |
| 4720 | /* A primitive log caculator. */ |
| 4721 | |
| 4722 | static inline unsigned int |
| 4723 | get_logsz (unsigned int size) |
| 4724 | { |
| 4725 | const unsigned char ls[16] = |
| 4726 | {0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, 4}; |
| 4727 | if (size > 16) |
| 4728 | { |
| 4729 | gas_assert (0); |
| 4730 | return -1; |
| 4731 | } |
| 4732 | gas_assert (ls[size - 1] != (unsigned char)-1); |
| 4733 | return ls[size - 1]; |
| 4734 | } |
| 4735 | |
| 4736 | /* Determine and return the real reloc type code for an instruction |
| 4737 | with the pseudo reloc type code BFD_RELOC_AARCH64_LDST_LO12. */ |
| 4738 | |
| 4739 | static inline bfd_reloc_code_real_type |
| 4740 | ldst_lo12_determine_real_reloc_type (void) |
| 4741 | { |
| 4742 | int logsz; |
| 4743 | enum aarch64_opnd_qualifier opd0_qlf = inst.base.operands[0].qualifier; |
| 4744 | enum aarch64_opnd_qualifier opd1_qlf = inst.base.operands[1].qualifier; |
| 4745 | |
| 4746 | const bfd_reloc_code_real_type reloc_ldst_lo12[5] = { |
| 4747 | BFD_RELOC_AARCH64_LDST8_LO12, BFD_RELOC_AARCH64_LDST16_LO12, |
| 4748 | BFD_RELOC_AARCH64_LDST32_LO12, BFD_RELOC_AARCH64_LDST64_LO12, |
| 4749 | BFD_RELOC_AARCH64_LDST128_LO12 |
| 4750 | }; |
| 4751 | |
| 4752 | gas_assert (inst.reloc.type == BFD_RELOC_AARCH64_LDST_LO12); |
| 4753 | gas_assert (inst.base.opcode->operands[1] == AARCH64_OPND_ADDR_UIMM12); |
| 4754 | |
| 4755 | if (opd1_qlf == AARCH64_OPND_QLF_NIL) |
| 4756 | opd1_qlf = |
| 4757 | aarch64_get_expected_qualifier (inst.base.opcode->qualifiers_list, |
| 4758 | 1, opd0_qlf, 0); |
| 4759 | gas_assert (opd1_qlf != AARCH64_OPND_QLF_NIL); |
| 4760 | |
| 4761 | logsz = get_logsz (aarch64_get_qualifier_esize (opd1_qlf)); |
| 4762 | gas_assert (logsz >= 0 && logsz <= 4); |
| 4763 | |
| 4764 | return reloc_ldst_lo12[logsz]; |
| 4765 | } |
| 4766 | |
| 4767 | /* Check whether a register list REGINFO is valid. The registers must be |
| 4768 | numbered in increasing order (modulo 32), in increments of one or two. |
| 4769 | |
| 4770 | If ACCEPT_ALTERNATE is non-zero, the register numbers should be in |
| 4771 | increments of two. |
| 4772 | |
| 4773 | Return FALSE if such a register list is invalid, otherwise return TRUE. */ |
| 4774 | |
| 4775 | static bfd_boolean |
| 4776 | reg_list_valid_p (uint32_t reginfo, int accept_alternate) |
| 4777 | { |
| 4778 | uint32_t i, nb_regs, prev_regno, incr; |
| 4779 | |
| 4780 | nb_regs = 1 + (reginfo & 0x3); |
| 4781 | reginfo >>= 2; |
| 4782 | prev_regno = reginfo & 0x1f; |
| 4783 | incr = accept_alternate ? 2 : 1; |
| 4784 | |
| 4785 | for (i = 1; i < nb_regs; ++i) |
| 4786 | { |
| 4787 | uint32_t curr_regno; |
| 4788 | reginfo >>= 5; |
| 4789 | curr_regno = reginfo & 0x1f; |
| 4790 | if (curr_regno != ((prev_regno + incr) & 0x1f)) |
| 4791 | return FALSE; |
| 4792 | prev_regno = curr_regno; |
| 4793 | } |
| 4794 | |
| 4795 | return TRUE; |
| 4796 | } |
| 4797 | |
| 4798 | /* Generic instruction operand parser. This does no encoding and no |
| 4799 | semantic validation; it merely squirrels values away in the inst |
| 4800 | structure. Returns TRUE or FALSE depending on whether the |
| 4801 | specified grammar matched. */ |
| 4802 | |
| 4803 | static bfd_boolean |
| 4804 | parse_operands (char *str, const aarch64_opcode *opcode) |
| 4805 | { |
| 4806 | int i; |
| 4807 | char *backtrack_pos = 0; |
| 4808 | const enum aarch64_opnd *operands = opcode->operands; |
| 4809 | |
| 4810 | clear_error (); |
| 4811 | skip_whitespace (str); |
| 4812 | |
| 4813 | for (i = 0; operands[i] != AARCH64_OPND_NIL; i++) |
| 4814 | { |
| 4815 | int64_t val; |
| 4816 | int isreg32, isregzero; |
| 4817 | int comma_skipped_p = 0; |
| 4818 | aarch64_reg_type rtype; |
| 4819 | struct neon_type_el vectype; |
| 4820 | aarch64_opnd_info *info = &inst.base.operands[i]; |
| 4821 | |
| 4822 | DEBUG_TRACE ("parse operand %d", i); |
| 4823 | |
| 4824 | /* Assign the operand code. */ |
| 4825 | info->type = operands[i]; |
| 4826 | |
| 4827 | if (optional_operand_p (opcode, i)) |
| 4828 | { |
| 4829 | /* Remember where we are in case we need to backtrack. */ |
| 4830 | gas_assert (!backtrack_pos); |
| 4831 | backtrack_pos = str; |
| 4832 | } |
| 4833 | |
| 4834 | /* Expect comma between operands; the backtrack mechanizm will take |
| 4835 | care of cases of omitted optional operand. */ |
| 4836 | if (i > 0 && ! skip_past_char (&str, ',')) |
| 4837 | { |
| 4838 | set_syntax_error (_("comma expected between operands")); |
| 4839 | goto failure; |
| 4840 | } |
| 4841 | else |
| 4842 | comma_skipped_p = 1; |
| 4843 | |
| 4844 | switch (operands[i]) |
| 4845 | { |
| 4846 | case AARCH64_OPND_Rd: |
| 4847 | case AARCH64_OPND_Rn: |
| 4848 | case AARCH64_OPND_Rm: |
| 4849 | case AARCH64_OPND_Rt: |
| 4850 | case AARCH64_OPND_Rt2: |
| 4851 | case AARCH64_OPND_Rs: |
| 4852 | case AARCH64_OPND_Ra: |
| 4853 | case AARCH64_OPND_Rt_SYS: |
| 4854 | case AARCH64_OPND_PAIRREG: |
| 4855 | po_int_reg_or_fail (1, 0); |
| 4856 | break; |
| 4857 | |
| 4858 | case AARCH64_OPND_Rd_SP: |
| 4859 | case AARCH64_OPND_Rn_SP: |
| 4860 | po_int_reg_or_fail (0, 1); |
| 4861 | break; |
| 4862 | |
| 4863 | case AARCH64_OPND_Rm_EXT: |
| 4864 | case AARCH64_OPND_Rm_SFT: |
| 4865 | po_misc_or_fail (parse_shifter_operand |
| 4866 | (&str, info, (operands[i] == AARCH64_OPND_Rm_EXT |
| 4867 | ? SHIFTED_ARITH_IMM |
| 4868 | : SHIFTED_LOGIC_IMM))); |
| 4869 | if (!info->shifter.operator_present) |
| 4870 | { |
| 4871 | /* Default to LSL if not present. Libopcodes prefers shifter |
| 4872 | kind to be explicit. */ |
| 4873 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); |
| 4874 | info->shifter.kind = AARCH64_MOD_LSL; |
| 4875 | /* For Rm_EXT, libopcodes will carry out further check on whether |
| 4876 | or not stack pointer is used in the instruction (Recall that |
| 4877 | "the extend operator is not optional unless at least one of |
| 4878 | "Rd" or "Rn" is '11111' (i.e. WSP)"). */ |
| 4879 | } |
| 4880 | break; |
| 4881 | |
| 4882 | case AARCH64_OPND_Fd: |
| 4883 | case AARCH64_OPND_Fn: |
| 4884 | case AARCH64_OPND_Fm: |
| 4885 | case AARCH64_OPND_Fa: |
| 4886 | case AARCH64_OPND_Ft: |
| 4887 | case AARCH64_OPND_Ft2: |
| 4888 | case AARCH64_OPND_Sd: |
| 4889 | case AARCH64_OPND_Sn: |
| 4890 | case AARCH64_OPND_Sm: |
| 4891 | val = aarch64_reg_parse (&str, REG_TYPE_BHSDQ, &rtype, NULL); |
| 4892 | if (val == PARSE_FAIL) |
| 4893 | { |
| 4894 | first_error (_(get_reg_expected_msg (REG_TYPE_BHSDQ))); |
| 4895 | goto failure; |
| 4896 | } |
| 4897 | gas_assert (rtype >= REG_TYPE_FP_B && rtype <= REG_TYPE_FP_Q); |
| 4898 | |
| 4899 | info->reg.regno = val; |
| 4900 | info->qualifier = AARCH64_OPND_QLF_S_B + (rtype - REG_TYPE_FP_B); |
| 4901 | break; |
| 4902 | |
| 4903 | case AARCH64_OPND_Vd: |
| 4904 | case AARCH64_OPND_Vn: |
| 4905 | case AARCH64_OPND_Vm: |
| 4906 | val = aarch64_reg_parse (&str, REG_TYPE_VN, NULL, &vectype); |
| 4907 | if (val == PARSE_FAIL) |
| 4908 | { |
| 4909 | first_error (_(get_reg_expected_msg (REG_TYPE_VN))); |
| 4910 | goto failure; |
| 4911 | } |
| 4912 | if (vectype.defined & NTA_HASINDEX) |
| 4913 | goto failure; |
| 4914 | |
| 4915 | info->reg.regno = val; |
| 4916 | info->qualifier = vectype_to_qualifier (&vectype); |
| 4917 | if (info->qualifier == AARCH64_OPND_QLF_NIL) |
| 4918 | goto failure; |
| 4919 | break; |
| 4920 | |
| 4921 | case AARCH64_OPND_VdD1: |
| 4922 | case AARCH64_OPND_VnD1: |
| 4923 | val = aarch64_reg_parse (&str, REG_TYPE_VN, NULL, &vectype); |
| 4924 | if (val == PARSE_FAIL) |
| 4925 | { |
| 4926 | set_first_syntax_error (_(get_reg_expected_msg (REG_TYPE_VN))); |
| 4927 | goto failure; |
| 4928 | } |
| 4929 | if (vectype.type != NT_d || vectype.index != 1) |
| 4930 | { |
| 4931 | set_fatal_syntax_error |
| 4932 | (_("the top half of a 128-bit FP/SIMD register is expected")); |
| 4933 | goto failure; |
| 4934 | } |
| 4935 | info->reg.regno = val; |
| 4936 | /* N.B: VdD1 and VnD1 are treated as an fp or advsimd scalar register |
| 4937 | here; it is correct for the purpose of encoding/decoding since |
| 4938 | only the register number is explicitly encoded in the related |
| 4939 | instructions, although this appears a bit hacky. */ |
| 4940 | info->qualifier = AARCH64_OPND_QLF_S_D; |
| 4941 | break; |
| 4942 | |
| 4943 | case AARCH64_OPND_Ed: |
| 4944 | case AARCH64_OPND_En: |
| 4945 | case AARCH64_OPND_Em: |
| 4946 | val = aarch64_reg_parse (&str, REG_TYPE_VN, NULL, &vectype); |
| 4947 | if (val == PARSE_FAIL) |
| 4948 | { |
| 4949 | first_error (_(get_reg_expected_msg (REG_TYPE_VN))); |
| 4950 | goto failure; |
| 4951 | } |
| 4952 | if (vectype.type == NT_invtype || !(vectype.defined & NTA_HASINDEX)) |
| 4953 | goto failure; |
| 4954 | |
| 4955 | info->reglane.regno = val; |
| 4956 | info->reglane.index = vectype.index; |
| 4957 | info->qualifier = vectype_to_qualifier (&vectype); |
| 4958 | if (info->qualifier == AARCH64_OPND_QLF_NIL) |
| 4959 | goto failure; |
| 4960 | break; |
| 4961 | |
| 4962 | case AARCH64_OPND_LVn: |
| 4963 | case AARCH64_OPND_LVt: |
| 4964 | case AARCH64_OPND_LVt_AL: |
| 4965 | case AARCH64_OPND_LEt: |
| 4966 | if ((val = parse_neon_reg_list (&str, &vectype)) == PARSE_FAIL) |
| 4967 | goto failure; |
| 4968 | if (! reg_list_valid_p (val, /* accept_alternate */ 0)) |
| 4969 | { |
| 4970 | set_fatal_syntax_error (_("invalid register list")); |
| 4971 | goto failure; |
| 4972 | } |
| 4973 | info->reglist.first_regno = (val >> 2) & 0x1f; |
| 4974 | info->reglist.num_regs = (val & 0x3) + 1; |
| 4975 | if (operands[i] == AARCH64_OPND_LEt) |
| 4976 | { |
| 4977 | if (!(vectype.defined & NTA_HASINDEX)) |
| 4978 | goto failure; |
| 4979 | info->reglist.has_index = 1; |
| 4980 | info->reglist.index = vectype.index; |
| 4981 | } |
| 4982 | else if (!(vectype.defined & NTA_HASTYPE)) |
| 4983 | goto failure; |
| 4984 | info->qualifier = vectype_to_qualifier (&vectype); |
| 4985 | if (info->qualifier == AARCH64_OPND_QLF_NIL) |
| 4986 | goto failure; |
| 4987 | break; |
| 4988 | |
| 4989 | case AARCH64_OPND_Cn: |
| 4990 | case AARCH64_OPND_Cm: |
| 4991 | po_reg_or_fail (REG_TYPE_CN); |
| 4992 | if (val > 15) |
| 4993 | { |
| 4994 | set_fatal_syntax_error (_(get_reg_expected_msg (REG_TYPE_CN))); |
| 4995 | goto failure; |
| 4996 | } |
| 4997 | inst.base.operands[i].reg.regno = val; |
| 4998 | break; |
| 4999 | |
| 5000 | case AARCH64_OPND_SHLL_IMM: |
| 5001 | case AARCH64_OPND_IMM_VLSR: |
| 5002 | po_imm_or_fail (1, 64); |
| 5003 | info->imm.value = val; |
| 5004 | break; |
| 5005 | |
| 5006 | case AARCH64_OPND_CCMP_IMM: |
| 5007 | case AARCH64_OPND_FBITS: |
| 5008 | case AARCH64_OPND_UIMM4: |
| 5009 | case AARCH64_OPND_UIMM3_OP1: |
| 5010 | case AARCH64_OPND_UIMM3_OP2: |
| 5011 | case AARCH64_OPND_IMM_VLSL: |
| 5012 | case AARCH64_OPND_IMM: |
| 5013 | case AARCH64_OPND_WIDTH: |
| 5014 | po_imm_nc_or_fail (); |
| 5015 | info->imm.value = val; |
| 5016 | break; |
| 5017 | |
| 5018 | case AARCH64_OPND_UIMM7: |
| 5019 | po_imm_or_fail (0, 127); |
| 5020 | info->imm.value = val; |
| 5021 | break; |
| 5022 | |
| 5023 | case AARCH64_OPND_IDX: |
| 5024 | case AARCH64_OPND_BIT_NUM: |
| 5025 | case AARCH64_OPND_IMMR: |
| 5026 | case AARCH64_OPND_IMMS: |
| 5027 | po_imm_or_fail (0, 63); |
| 5028 | info->imm.value = val; |
| 5029 | break; |
| 5030 | |
| 5031 | case AARCH64_OPND_IMM0: |
| 5032 | po_imm_nc_or_fail (); |
| 5033 | if (val != 0) |
| 5034 | { |
| 5035 | set_fatal_syntax_error (_("immediate zero expected")); |
| 5036 | goto failure; |
| 5037 | } |
| 5038 | info->imm.value = 0; |
| 5039 | break; |
| 5040 | |
| 5041 | case AARCH64_OPND_FPIMM0: |
| 5042 | { |
| 5043 | int qfloat; |
| 5044 | bfd_boolean res1 = FALSE, res2 = FALSE; |
| 5045 | /* N.B. -0.0 will be rejected; although -0.0 shouldn't be rejected, |
| 5046 | it is probably not worth the effort to support it. */ |
| 5047 | if (!(res1 = parse_aarch64_imm_float (&str, &qfloat, FALSE)) |
| 5048 | && !(res2 = parse_constant_immediate (&str, &val))) |
| 5049 | goto failure; |
| 5050 | if ((res1 && qfloat == 0) || (res2 && val == 0)) |
| 5051 | { |
| 5052 | info->imm.value = 0; |
| 5053 | info->imm.is_fp = 1; |
| 5054 | break; |
| 5055 | } |
| 5056 | set_fatal_syntax_error (_("immediate zero expected")); |
| 5057 | goto failure; |
| 5058 | } |
| 5059 | |
| 5060 | case AARCH64_OPND_IMM_MOV: |
| 5061 | { |
| 5062 | char *saved = str; |
| 5063 | if (reg_name_p (str, REG_TYPE_R_Z_SP) || |
| 5064 | reg_name_p (str, REG_TYPE_VN)) |
| 5065 | goto failure; |
| 5066 | str = saved; |
| 5067 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, |
| 5068 | GE_OPT_PREFIX, 1)); |
| 5069 | /* The MOV immediate alias will be fixed up by fix_mov_imm_insn |
| 5070 | later. fix_mov_imm_insn will try to determine a machine |
| 5071 | instruction (MOVZ, MOVN or ORR) for it and will issue an error |
| 5072 | message if the immediate cannot be moved by a single |
| 5073 | instruction. */ |
| 5074 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 1); |
| 5075 | inst.base.operands[i].skip = 1; |
| 5076 | } |
| 5077 | break; |
| 5078 | |
| 5079 | case AARCH64_OPND_SIMD_IMM: |
| 5080 | case AARCH64_OPND_SIMD_IMM_SFT: |
| 5081 | if (! parse_big_immediate (&str, &val)) |
| 5082 | goto failure; |
| 5083 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
| 5084 | /* addr_off_p */ 0, |
| 5085 | /* need_libopcodes_p */ 1, |
| 5086 | /* skip_p */ 1); |
| 5087 | /* Parse shift. |
| 5088 | N.B. although AARCH64_OPND_SIMD_IMM doesn't permit any |
| 5089 | shift, we don't check it here; we leave the checking to |
| 5090 | the libopcodes (operand_general_constraint_met_p). By |
| 5091 | doing this, we achieve better diagnostics. */ |
| 5092 | if (skip_past_comma (&str) |
| 5093 | && ! parse_shift (&str, info, SHIFTED_LSL_MSL)) |
| 5094 | goto failure; |
| 5095 | if (!info->shifter.operator_present |
| 5096 | && info->type == AARCH64_OPND_SIMD_IMM_SFT) |
| 5097 | { |
| 5098 | /* Default to LSL if not present. Libopcodes prefers shifter |
| 5099 | kind to be explicit. */ |
| 5100 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); |
| 5101 | info->shifter.kind = AARCH64_MOD_LSL; |
| 5102 | } |
| 5103 | break; |
| 5104 | |
| 5105 | case AARCH64_OPND_FPIMM: |
| 5106 | case AARCH64_OPND_SIMD_FPIMM: |
| 5107 | { |
| 5108 | int qfloat; |
| 5109 | bfd_boolean dp_p |
| 5110 | = (aarch64_get_qualifier_esize (inst.base.operands[0].qualifier) |
| 5111 | == 8); |
| 5112 | if (! parse_aarch64_imm_float (&str, &qfloat, dp_p)) |
| 5113 | goto failure; |
| 5114 | if (qfloat == 0) |
| 5115 | { |
| 5116 | set_fatal_syntax_error (_("invalid floating-point constant")); |
| 5117 | goto failure; |
| 5118 | } |
| 5119 | inst.base.operands[i].imm.value = encode_imm_float_bits (qfloat); |
| 5120 | inst.base.operands[i].imm.is_fp = 1; |
| 5121 | } |
| 5122 | break; |
| 5123 | |
| 5124 | case AARCH64_OPND_LIMM: |
| 5125 | po_misc_or_fail (parse_shifter_operand (&str, info, |
| 5126 | SHIFTED_LOGIC_IMM)); |
| 5127 | if (info->shifter.operator_present) |
| 5128 | { |
| 5129 | set_fatal_syntax_error |
| 5130 | (_("shift not allowed for bitmask immediate")); |
| 5131 | goto failure; |
| 5132 | } |
| 5133 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
| 5134 | /* addr_off_p */ 0, |
| 5135 | /* need_libopcodes_p */ 1, |
| 5136 | /* skip_p */ 1); |
| 5137 | break; |
| 5138 | |
| 5139 | case AARCH64_OPND_AIMM: |
| 5140 | if (opcode->op == OP_ADD) |
| 5141 | /* ADD may have relocation types. */ |
| 5142 | po_misc_or_fail (parse_shifter_operand_reloc (&str, info, |
| 5143 | SHIFTED_ARITH_IMM)); |
| 5144 | else |
| 5145 | po_misc_or_fail (parse_shifter_operand (&str, info, |
| 5146 | SHIFTED_ARITH_IMM)); |
| 5147 | switch (inst.reloc.type) |
| 5148 | { |
| 5149 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
| 5150 | info->shifter.amount = 12; |
| 5151 | break; |
| 5152 | case BFD_RELOC_UNUSED: |
| 5153 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 0); |
| 5154 | if (info->shifter.kind != AARCH64_MOD_NONE) |
| 5155 | inst.reloc.flags = FIXUP_F_HAS_EXPLICIT_SHIFT; |
| 5156 | inst.reloc.pc_rel = 0; |
| 5157 | break; |
| 5158 | default: |
| 5159 | break; |
| 5160 | } |
| 5161 | info->imm.value = 0; |
| 5162 | if (!info->shifter.operator_present) |
| 5163 | { |
| 5164 | /* Default to LSL if not present. Libopcodes prefers shifter |
| 5165 | kind to be explicit. */ |
| 5166 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); |
| 5167 | info->shifter.kind = AARCH64_MOD_LSL; |
| 5168 | } |
| 5169 | break; |
| 5170 | |
| 5171 | case AARCH64_OPND_HALF: |
| 5172 | { |
| 5173 | /* #<imm16> or relocation. */ |
| 5174 | int internal_fixup_p; |
| 5175 | po_misc_or_fail (parse_half (&str, &internal_fixup_p)); |
| 5176 | if (internal_fixup_p) |
| 5177 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 0); |
| 5178 | skip_whitespace (str); |
| 5179 | if (skip_past_comma (&str)) |
| 5180 | { |
| 5181 | /* {, LSL #<shift>} */ |
| 5182 | if (! aarch64_gas_internal_fixup_p ()) |
| 5183 | { |
| 5184 | set_fatal_syntax_error (_("can't mix relocation modifier " |
| 5185 | "with explicit shift")); |
| 5186 | goto failure; |
| 5187 | } |
| 5188 | po_misc_or_fail (parse_shift (&str, info, SHIFTED_LSL)); |
| 5189 | } |
| 5190 | else |
| 5191 | inst.base.operands[i].shifter.amount = 0; |
| 5192 | inst.base.operands[i].shifter.kind = AARCH64_MOD_LSL; |
| 5193 | inst.base.operands[i].imm.value = 0; |
| 5194 | if (! process_movw_reloc_info ()) |
| 5195 | goto failure; |
| 5196 | } |
| 5197 | break; |
| 5198 | |
| 5199 | case AARCH64_OPND_EXCEPTION: |
| 5200 | po_misc_or_fail (parse_immediate_expression (&str, &inst.reloc.exp)); |
| 5201 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
| 5202 | /* addr_off_p */ 0, |
| 5203 | /* need_libopcodes_p */ 0, |
| 5204 | /* skip_p */ 1); |
| 5205 | break; |
| 5206 | |
| 5207 | case AARCH64_OPND_NZCV: |
| 5208 | { |
| 5209 | const asm_nzcv *nzcv = hash_find_n (aarch64_nzcv_hsh, str, 4); |
| 5210 | if (nzcv != NULL) |
| 5211 | { |
| 5212 | str += 4; |
| 5213 | info->imm.value = nzcv->value; |
| 5214 | break; |
| 5215 | } |
| 5216 | po_imm_or_fail (0, 15); |
| 5217 | info->imm.value = val; |
| 5218 | } |
| 5219 | break; |
| 5220 | |
| 5221 | case AARCH64_OPND_COND: |
| 5222 | case AARCH64_OPND_COND1: |
| 5223 | info->cond = hash_find_n (aarch64_cond_hsh, str, 2); |
| 5224 | str += 2; |
| 5225 | if (info->cond == NULL) |
| 5226 | { |
| 5227 | set_syntax_error (_("invalid condition")); |
| 5228 | goto failure; |
| 5229 | } |
| 5230 | else if (operands[i] == AARCH64_OPND_COND1 |
| 5231 | && (info->cond->value & 0xe) == 0xe) |
| 5232 | { |
| 5233 | /* Not allow AL or NV. */ |
| 5234 | set_default_error (); |
| 5235 | goto failure; |
| 5236 | } |
| 5237 | break; |
| 5238 | |
| 5239 | case AARCH64_OPND_ADDR_ADRP: |
| 5240 | po_misc_or_fail (parse_adrp (&str)); |
| 5241 | /* Clear the value as operand needs to be relocated. */ |
| 5242 | info->imm.value = 0; |
| 5243 | break; |
| 5244 | |
| 5245 | case AARCH64_OPND_ADDR_PCREL14: |
| 5246 | case AARCH64_OPND_ADDR_PCREL19: |
| 5247 | case AARCH64_OPND_ADDR_PCREL21: |
| 5248 | case AARCH64_OPND_ADDR_PCREL26: |
| 5249 | po_misc_or_fail (parse_address_reloc (&str, info)); |
| 5250 | if (!info->addr.pcrel) |
| 5251 | { |
| 5252 | set_syntax_error (_("invalid pc-relative address")); |
| 5253 | goto failure; |
| 5254 | } |
| 5255 | if (inst.gen_lit_pool |
| 5256 | && (opcode->iclass != loadlit || opcode->op == OP_PRFM_LIT)) |
| 5257 | { |
| 5258 | /* Only permit "=value" in the literal load instructions. |
| 5259 | The literal will be generated by programmer_friendly_fixup. */ |
| 5260 | set_syntax_error (_("invalid use of \"=immediate\"")); |
| 5261 | goto failure; |
| 5262 | } |
| 5263 | if (inst.reloc.exp.X_op == O_symbol && find_reloc_table_entry (&str)) |
| 5264 | { |
| 5265 | set_syntax_error (_("unrecognized relocation suffix")); |
| 5266 | goto failure; |
| 5267 | } |
| 5268 | if (inst.reloc.exp.X_op == O_constant && !inst.gen_lit_pool) |
| 5269 | { |
| 5270 | info->imm.value = inst.reloc.exp.X_add_number; |
| 5271 | inst.reloc.type = BFD_RELOC_UNUSED; |
| 5272 | } |
| 5273 | else |
| 5274 | { |
| 5275 | info->imm.value = 0; |
| 5276 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
| 5277 | switch (opcode->iclass) |
| 5278 | { |
| 5279 | case compbranch: |
| 5280 | case condbranch: |
| 5281 | /* e.g. CBZ or B.COND */ |
| 5282 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL19); |
| 5283 | inst.reloc.type = BFD_RELOC_AARCH64_BRANCH19; |
| 5284 | break; |
| 5285 | case testbranch: |
| 5286 | /* e.g. TBZ */ |
| 5287 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL14); |
| 5288 | inst.reloc.type = BFD_RELOC_AARCH64_TSTBR14; |
| 5289 | break; |
| 5290 | case branch_imm: |
| 5291 | /* e.g. B or BL */ |
| 5292 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL26); |
| 5293 | inst.reloc.type = |
| 5294 | (opcode->op == OP_BL) ? BFD_RELOC_AARCH64_CALL26 |
| 5295 | : BFD_RELOC_AARCH64_JUMP26; |
| 5296 | break; |
| 5297 | case loadlit: |
| 5298 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL19); |
| 5299 | inst.reloc.type = BFD_RELOC_AARCH64_LD_LO19_PCREL; |
| 5300 | break; |
| 5301 | case pcreladdr: |
| 5302 | gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL21); |
| 5303 | inst.reloc.type = BFD_RELOC_AARCH64_ADR_LO21_PCREL; |
| 5304 | break; |
| 5305 | default: |
| 5306 | gas_assert (0); |
| 5307 | abort (); |
| 5308 | } |
| 5309 | inst.reloc.pc_rel = 1; |
| 5310 | } |
| 5311 | break; |
| 5312 | |
| 5313 | case AARCH64_OPND_ADDR_SIMPLE: |
| 5314 | case AARCH64_OPND_SIMD_ADDR_SIMPLE: |
| 5315 | /* [<Xn|SP>{, #<simm>}] */ |
| 5316 | po_char_or_fail ('['); |
| 5317 | po_reg_or_fail (REG_TYPE_R64_SP); |
| 5318 | /* Accept optional ", #0". */ |
| 5319 | if (operands[i] == AARCH64_OPND_ADDR_SIMPLE |
| 5320 | && skip_past_char (&str, ',')) |
| 5321 | { |
| 5322 | skip_past_char (&str, '#'); |
| 5323 | if (! skip_past_char (&str, '0')) |
| 5324 | { |
| 5325 | set_fatal_syntax_error |
| 5326 | (_("the optional immediate offset can only be 0")); |
| 5327 | goto failure; |
| 5328 | } |
| 5329 | } |
| 5330 | po_char_or_fail (']'); |
| 5331 | info->addr.base_regno = val; |
| 5332 | break; |
| 5333 | |
| 5334 | case AARCH64_OPND_ADDR_REGOFF: |
| 5335 | /* [<Xn|SP>, <R><m>{, <extend> {<amount>}}] */ |
| 5336 | po_misc_or_fail (parse_address (&str, info, 0)); |
| 5337 | if (info->addr.pcrel || !info->addr.offset.is_reg |
| 5338 | || !info->addr.preind || info->addr.postind |
| 5339 | || info->addr.writeback) |
| 5340 | { |
| 5341 | set_syntax_error (_("invalid addressing mode")); |
| 5342 | goto failure; |
| 5343 | } |
| 5344 | if (!info->shifter.operator_present) |
| 5345 | { |
| 5346 | /* Default to LSL if not present. Libopcodes prefers shifter |
| 5347 | kind to be explicit. */ |
| 5348 | gas_assert (info->shifter.kind == AARCH64_MOD_NONE); |
| 5349 | info->shifter.kind = AARCH64_MOD_LSL; |
| 5350 | } |
| 5351 | /* Qualifier to be deduced by libopcodes. */ |
| 5352 | break; |
| 5353 | |
| 5354 | case AARCH64_OPND_ADDR_SIMM7: |
| 5355 | po_misc_or_fail (parse_address (&str, info, 0)); |
| 5356 | if (info->addr.pcrel || info->addr.offset.is_reg |
| 5357 | || (!info->addr.preind && !info->addr.postind)) |
| 5358 | { |
| 5359 | set_syntax_error (_("invalid addressing mode")); |
| 5360 | goto failure; |
| 5361 | } |
| 5362 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
| 5363 | /* addr_off_p */ 1, |
| 5364 | /* need_libopcodes_p */ 1, |
| 5365 | /* skip_p */ 0); |
| 5366 | break; |
| 5367 | |
| 5368 | case AARCH64_OPND_ADDR_SIMM9: |
| 5369 | case AARCH64_OPND_ADDR_SIMM9_2: |
| 5370 | po_misc_or_fail (parse_address_reloc (&str, info)); |
| 5371 | if (info->addr.pcrel || info->addr.offset.is_reg |
| 5372 | || (!info->addr.preind && !info->addr.postind) |
| 5373 | || (operands[i] == AARCH64_OPND_ADDR_SIMM9_2 |
| 5374 | && info->addr.writeback)) |
| 5375 | { |
| 5376 | set_syntax_error (_("invalid addressing mode")); |
| 5377 | goto failure; |
| 5378 | } |
| 5379 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
| 5380 | { |
| 5381 | set_syntax_error (_("relocation not allowed")); |
| 5382 | goto failure; |
| 5383 | } |
| 5384 | assign_imm_if_const_or_fixup_later (&inst.reloc, info, |
| 5385 | /* addr_off_p */ 1, |
| 5386 | /* need_libopcodes_p */ 1, |
| 5387 | /* skip_p */ 0); |
| 5388 | break; |
| 5389 | |
| 5390 | case AARCH64_OPND_ADDR_UIMM12: |
| 5391 | po_misc_or_fail (parse_address_reloc (&str, info)); |
| 5392 | if (info->addr.pcrel || info->addr.offset.is_reg |
| 5393 | || !info->addr.preind || info->addr.writeback) |
| 5394 | { |
| 5395 | set_syntax_error (_("invalid addressing mode")); |
| 5396 | goto failure; |
| 5397 | } |
| 5398 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
| 5399 | aarch64_set_gas_internal_fixup (&inst.reloc, info, 1); |
| 5400 | else if (inst.reloc.type == BFD_RELOC_AARCH64_LDST_LO12) |
| 5401 | inst.reloc.type = ldst_lo12_determine_real_reloc_type (); |
| 5402 | /* Leave qualifier to be determined by libopcodes. */ |
| 5403 | break; |
| 5404 | |
| 5405 | case AARCH64_OPND_SIMD_ADDR_POST: |
| 5406 | /* [<Xn|SP>], <Xm|#<amount>> */ |
| 5407 | po_misc_or_fail (parse_address (&str, info, 1)); |
| 5408 | if (!info->addr.postind || !info->addr.writeback) |
| 5409 | { |
| 5410 | set_syntax_error (_("invalid addressing mode")); |
| 5411 | goto failure; |
| 5412 | } |
| 5413 | if (!info->addr.offset.is_reg) |
| 5414 | { |
| 5415 | if (inst.reloc.exp.X_op == O_constant) |
| 5416 | info->addr.offset.imm = inst.reloc.exp.X_add_number; |
| 5417 | else |
| 5418 | { |
| 5419 | set_fatal_syntax_error |
| 5420 | (_("writeback value should be an immediate constant")); |
| 5421 | goto failure; |
| 5422 | } |
| 5423 | } |
| 5424 | /* No qualifier. */ |
| 5425 | break; |
| 5426 | |
| 5427 | case AARCH64_OPND_SYSREG: |
| 5428 | if ((val = parse_sys_reg (&str, aarch64_sys_regs_hsh, 1, 0)) |
| 5429 | == PARSE_FAIL) |
| 5430 | { |
| 5431 | set_syntax_error (_("unknown or missing system register name")); |
| 5432 | goto failure; |
| 5433 | } |
| 5434 | inst.base.operands[i].sysreg = val; |
| 5435 | break; |
| 5436 | |
| 5437 | case AARCH64_OPND_PSTATEFIELD: |
| 5438 | if ((val = parse_sys_reg (&str, aarch64_pstatefield_hsh, 0, 1)) |
| 5439 | == PARSE_FAIL) |
| 5440 | { |
| 5441 | set_syntax_error (_("unknown or missing PSTATE field name")); |
| 5442 | goto failure; |
| 5443 | } |
| 5444 | inst.base.operands[i].pstatefield = val; |
| 5445 | break; |
| 5446 | |
| 5447 | case AARCH64_OPND_SYSREG_IC: |
| 5448 | inst.base.operands[i].sysins_op = |
| 5449 | parse_sys_ins_reg (&str, aarch64_sys_regs_ic_hsh); |
| 5450 | goto sys_reg_ins; |
| 5451 | case AARCH64_OPND_SYSREG_DC: |
| 5452 | inst.base.operands[i].sysins_op = |
| 5453 | parse_sys_ins_reg (&str, aarch64_sys_regs_dc_hsh); |
| 5454 | goto sys_reg_ins; |
| 5455 | case AARCH64_OPND_SYSREG_AT: |
| 5456 | inst.base.operands[i].sysins_op = |
| 5457 | parse_sys_ins_reg (&str, aarch64_sys_regs_at_hsh); |
| 5458 | goto sys_reg_ins; |
| 5459 | case AARCH64_OPND_SYSREG_TLBI: |
| 5460 | inst.base.operands[i].sysins_op = |
| 5461 | parse_sys_ins_reg (&str, aarch64_sys_regs_tlbi_hsh); |
| 5462 | sys_reg_ins: |
| 5463 | if (inst.base.operands[i].sysins_op == NULL) |
| 5464 | { |
| 5465 | set_fatal_syntax_error ( _("unknown or missing operation name")); |
| 5466 | goto failure; |
| 5467 | } |
| 5468 | break; |
| 5469 | |
| 5470 | case AARCH64_OPND_BARRIER: |
| 5471 | case AARCH64_OPND_BARRIER_ISB: |
| 5472 | val = parse_barrier (&str); |
| 5473 | if (val != PARSE_FAIL |
| 5474 | && operands[i] == AARCH64_OPND_BARRIER_ISB && val != 0xf) |
| 5475 | { |
| 5476 | /* ISB only accepts options name 'sy'. */ |
| 5477 | set_syntax_error |
| 5478 | (_("the specified option is not accepted in ISB")); |
| 5479 | /* Turn off backtrack as this optional operand is present. */ |
| 5480 | backtrack_pos = 0; |
| 5481 | goto failure; |
| 5482 | } |
| 5483 | /* This is an extension to accept a 0..15 immediate. */ |
| 5484 | if (val == PARSE_FAIL) |
| 5485 | po_imm_or_fail (0, 15); |
| 5486 | info->barrier = aarch64_barrier_options + val; |
| 5487 | break; |
| 5488 | |
| 5489 | case AARCH64_OPND_PRFOP: |
| 5490 | val = parse_pldop (&str); |
| 5491 | /* This is an extension to accept a 0..31 immediate. */ |
| 5492 | if (val == PARSE_FAIL) |
| 5493 | po_imm_or_fail (0, 31); |
| 5494 | inst.base.operands[i].prfop = aarch64_prfops + val; |
| 5495 | break; |
| 5496 | |
| 5497 | default: |
| 5498 | as_fatal (_("unhandled operand code %d"), operands[i]); |
| 5499 | } |
| 5500 | |
| 5501 | /* If we get here, this operand was successfully parsed. */ |
| 5502 | inst.base.operands[i].present = 1; |
| 5503 | continue; |
| 5504 | |
| 5505 | failure: |
| 5506 | /* The parse routine should already have set the error, but in case |
| 5507 | not, set a default one here. */ |
| 5508 | if (! error_p ()) |
| 5509 | set_default_error (); |
| 5510 | |
| 5511 | if (! backtrack_pos) |
| 5512 | goto parse_operands_return; |
| 5513 | |
| 5514 | { |
| 5515 | /* We reach here because this operand is marked as optional, and |
| 5516 | either no operand was supplied or the operand was supplied but it |
| 5517 | was syntactically incorrect. In the latter case we report an |
| 5518 | error. In the former case we perform a few more checks before |
| 5519 | dropping through to the code to insert the default operand. */ |
| 5520 | |
| 5521 | char *tmp = backtrack_pos; |
| 5522 | char endchar = END_OF_INSN; |
| 5523 | |
| 5524 | if (i != (aarch64_num_of_operands (opcode) - 1)) |
| 5525 | endchar = ','; |
| 5526 | skip_past_char (&tmp, ','); |
| 5527 | |
| 5528 | if (*tmp != endchar) |
| 5529 | /* The user has supplied an operand in the wrong format. */ |
| 5530 | goto parse_operands_return; |
| 5531 | |
| 5532 | /* Make sure there is not a comma before the optional operand. |
| 5533 | For example the fifth operand of 'sys' is optional: |
| 5534 | |
| 5535 | sys #0,c0,c0,#0, <--- wrong |
| 5536 | sys #0,c0,c0,#0 <--- correct. */ |
| 5537 | if (comma_skipped_p && i && endchar == END_OF_INSN) |
| 5538 | { |
| 5539 | set_fatal_syntax_error |
| 5540 | (_("unexpected comma before the omitted optional operand")); |
| 5541 | goto parse_operands_return; |
| 5542 | } |
| 5543 | } |
| 5544 | |
| 5545 | /* Reaching here means we are dealing with an optional operand that is |
| 5546 | omitted from the assembly line. */ |
| 5547 | gas_assert (optional_operand_p (opcode, i)); |
| 5548 | info->present = 0; |
| 5549 | process_omitted_operand (operands[i], opcode, i, info); |
| 5550 | |
| 5551 | /* Try again, skipping the optional operand at backtrack_pos. */ |
| 5552 | str = backtrack_pos; |
| 5553 | backtrack_pos = 0; |
| 5554 | |
| 5555 | /* Clear any error record after the omitted optional operand has been |
| 5556 | successfully handled. */ |
| 5557 | clear_error (); |
| 5558 | } |
| 5559 | |
| 5560 | /* Check if we have parsed all the operands. */ |
| 5561 | if (*str != '\0' && ! error_p ()) |
| 5562 | { |
| 5563 | /* Set I to the index of the last present operand; this is |
| 5564 | for the purpose of diagnostics. */ |
| 5565 | for (i -= 1; i >= 0 && !inst.base.operands[i].present; --i) |
| 5566 | ; |
| 5567 | set_fatal_syntax_error |
| 5568 | (_("unexpected characters following instruction")); |
| 5569 | } |
| 5570 | |
| 5571 | parse_operands_return: |
| 5572 | |
| 5573 | if (error_p ()) |
| 5574 | { |
| 5575 | DEBUG_TRACE ("parsing FAIL: %s - %s", |
| 5576 | operand_mismatch_kind_names[get_error_kind ()], |
| 5577 | get_error_message ()); |
| 5578 | /* Record the operand error properly; this is useful when there |
| 5579 | are multiple instruction templates for a mnemonic name, so that |
| 5580 | later on, we can select the error that most closely describes |
| 5581 | the problem. */ |
| 5582 | record_operand_error (opcode, i, get_error_kind (), |
| 5583 | get_error_message ()); |
| 5584 | return FALSE; |
| 5585 | } |
| 5586 | else |
| 5587 | { |
| 5588 | DEBUG_TRACE ("parsing SUCCESS"); |
| 5589 | return TRUE; |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | /* It does some fix-up to provide some programmer friendly feature while |
| 5594 | keeping the libopcodes happy, i.e. libopcodes only accepts |
| 5595 | the preferred architectural syntax. |
| 5596 | Return FALSE if there is any failure; otherwise return TRUE. */ |
| 5597 | |
| 5598 | static bfd_boolean |
| 5599 | programmer_friendly_fixup (aarch64_instruction *instr) |
| 5600 | { |
| 5601 | aarch64_inst *base = &instr->base; |
| 5602 | const aarch64_opcode *opcode = base->opcode; |
| 5603 | enum aarch64_op op = opcode->op; |
| 5604 | aarch64_opnd_info *operands = base->operands; |
| 5605 | |
| 5606 | DEBUG_TRACE ("enter"); |
| 5607 | |
| 5608 | switch (opcode->iclass) |
| 5609 | { |
| 5610 | case testbranch: |
| 5611 | /* TBNZ Xn|Wn, #uimm6, label |
| 5612 | Test and Branch Not Zero: conditionally jumps to label if bit number |
| 5613 | uimm6 in register Xn is not zero. The bit number implies the width of |
| 5614 | the register, which may be written and should be disassembled as Wn if |
| 5615 | uimm is less than 32. */ |
| 5616 | if (operands[0].qualifier == AARCH64_OPND_QLF_W) |
| 5617 | { |
| 5618 | if (operands[1].imm.value >= 32) |
| 5619 | { |
| 5620 | record_operand_out_of_range_error (opcode, 1, _("immediate value"), |
| 5621 | 0, 31); |
| 5622 | return FALSE; |
| 5623 | } |
| 5624 | operands[0].qualifier = AARCH64_OPND_QLF_X; |
| 5625 | } |
| 5626 | break; |
| 5627 | case loadlit: |
| 5628 | /* LDR Wt, label | =value |
| 5629 | As a convenience assemblers will typically permit the notation |
| 5630 | "=value" in conjunction with the pc-relative literal load instructions |
| 5631 | to automatically place an immediate value or symbolic address in a |
| 5632 | nearby literal pool and generate a hidden label which references it. |
| 5633 | ISREG has been set to 0 in the case of =value. */ |
| 5634 | if (instr->gen_lit_pool |
| 5635 | && (op == OP_LDR_LIT || op == OP_LDRV_LIT || op == OP_LDRSW_LIT)) |
| 5636 | { |
| 5637 | int size = aarch64_get_qualifier_esize (operands[0].qualifier); |
| 5638 | if (op == OP_LDRSW_LIT) |
| 5639 | size = 4; |
| 5640 | if (instr->reloc.exp.X_op != O_constant |
| 5641 | && instr->reloc.exp.X_op != O_big |
| 5642 | && instr->reloc.exp.X_op != O_symbol) |
| 5643 | { |
| 5644 | record_operand_error (opcode, 1, |
| 5645 | AARCH64_OPDE_FATAL_SYNTAX_ERROR, |
| 5646 | _("constant expression expected")); |
| 5647 | return FALSE; |
| 5648 | } |
| 5649 | if (! add_to_lit_pool (&instr->reloc.exp, size)) |
| 5650 | { |
| 5651 | record_operand_error (opcode, 1, |
| 5652 | AARCH64_OPDE_OTHER_ERROR, |
| 5653 | _("literal pool insertion failed")); |
| 5654 | return FALSE; |
| 5655 | } |
| 5656 | } |
| 5657 | break; |
| 5658 | case log_shift: |
| 5659 | case bitfield: |
| 5660 | /* UXT[BHW] Wd, Wn |
| 5661 | Unsigned Extend Byte|Halfword|Word: UXT[BH] is architectural alias |
| 5662 | for UBFM Wd,Wn,#0,#7|15, while UXTW is pseudo instruction which is |
| 5663 | encoded using ORR Wd, WZR, Wn (MOV Wd,Wn). |
| 5664 | A programmer-friendly assembler should accept a destination Xd in |
| 5665 | place of Wd, however that is not the preferred form for disassembly. |
| 5666 | */ |
| 5667 | if ((op == OP_UXTB || op == OP_UXTH || op == OP_UXTW) |
| 5668 | && operands[1].qualifier == AARCH64_OPND_QLF_W |
| 5669 | && operands[0].qualifier == AARCH64_OPND_QLF_X) |
| 5670 | operands[0].qualifier = AARCH64_OPND_QLF_W; |
| 5671 | break; |
| 5672 | |
| 5673 | case addsub_ext: |
| 5674 | { |
| 5675 | /* In the 64-bit form, the final register operand is written as Wm |
| 5676 | for all but the (possibly omitted) UXTX/LSL and SXTX |
| 5677 | operators. |
| 5678 | As a programmer-friendly assembler, we accept e.g. |
| 5679 | ADDS <Xd>, <Xn|SP>, <Xm>{, UXTB {#<amount>}} and change it to |
| 5680 | ADDS <Xd>, <Xn|SP>, <Wm>{, UXTB {#<amount>}}. */ |
| 5681 | int idx = aarch64_operand_index (opcode->operands, |
| 5682 | AARCH64_OPND_Rm_EXT); |
| 5683 | gas_assert (idx == 1 || idx == 2); |
| 5684 | if (operands[0].qualifier == AARCH64_OPND_QLF_X |
| 5685 | && operands[idx].qualifier == AARCH64_OPND_QLF_X |
| 5686 | && operands[idx].shifter.kind != AARCH64_MOD_LSL |
| 5687 | && operands[idx].shifter.kind != AARCH64_MOD_UXTX |
| 5688 | && operands[idx].shifter.kind != AARCH64_MOD_SXTX) |
| 5689 | operands[idx].qualifier = AARCH64_OPND_QLF_W; |
| 5690 | } |
| 5691 | break; |
| 5692 | |
| 5693 | default: |
| 5694 | break; |
| 5695 | } |
| 5696 | |
| 5697 | DEBUG_TRACE ("exit with SUCCESS"); |
| 5698 | return TRUE; |
| 5699 | } |
| 5700 | |
| 5701 | /* Check for loads and stores that will cause unpredictable behavior. */ |
| 5702 | |
| 5703 | static void |
| 5704 | warn_unpredictable_ldst (aarch64_instruction *instr, char *str) |
| 5705 | { |
| 5706 | aarch64_inst *base = &instr->base; |
| 5707 | const aarch64_opcode *opcode = base->opcode; |
| 5708 | const aarch64_opnd_info *opnds = base->operands; |
| 5709 | switch (opcode->iclass) |
| 5710 | { |
| 5711 | case ldst_pos: |
| 5712 | case ldst_imm9: |
| 5713 | case ldst_unscaled: |
| 5714 | case ldst_unpriv: |
| 5715 | /* Loading/storing the base register is unpredictable if writeback. */ |
| 5716 | if ((aarch64_get_operand_class (opnds[0].type) |
| 5717 | == AARCH64_OPND_CLASS_INT_REG) |
| 5718 | && opnds[0].reg.regno == opnds[1].addr.base_regno |
| 5719 | && opnds[1].addr.base_regno != REG_SP |
| 5720 | && opnds[1].addr.writeback) |
| 5721 | as_warn (_("unpredictable transfer with writeback -- `%s'"), str); |
| 5722 | break; |
| 5723 | case ldstpair_off: |
| 5724 | case ldstnapair_offs: |
| 5725 | case ldstpair_indexed: |
| 5726 | /* Loading/storing the base register is unpredictable if writeback. */ |
| 5727 | if ((aarch64_get_operand_class (opnds[0].type) |
| 5728 | == AARCH64_OPND_CLASS_INT_REG) |
| 5729 | && (opnds[0].reg.regno == opnds[2].addr.base_regno |
| 5730 | || opnds[1].reg.regno == opnds[2].addr.base_regno) |
| 5731 | && opnds[2].addr.base_regno != REG_SP |
| 5732 | && opnds[2].addr.writeback) |
| 5733 | as_warn (_("unpredictable transfer with writeback -- `%s'"), str); |
| 5734 | /* Load operations must load different registers. */ |
| 5735 | if ((opcode->opcode & (1 << 22)) |
| 5736 | && opnds[0].reg.regno == opnds[1].reg.regno) |
| 5737 | as_warn (_("unpredictable load of register pair -- `%s'"), str); |
| 5738 | break; |
| 5739 | default: |
| 5740 | break; |
| 5741 | } |
| 5742 | } |
| 5743 | |
| 5744 | /* A wrapper function to interface with libopcodes on encoding and |
| 5745 | record the error message if there is any. |
| 5746 | |
| 5747 | Return TRUE on success; otherwise return FALSE. */ |
| 5748 | |
| 5749 | static bfd_boolean |
| 5750 | do_encode (const aarch64_opcode *opcode, aarch64_inst *instr, |
| 5751 | aarch64_insn *code) |
| 5752 | { |
| 5753 | aarch64_operand_error error_info; |
| 5754 | error_info.kind = AARCH64_OPDE_NIL; |
| 5755 | if (aarch64_opcode_encode (opcode, instr, code, NULL, &error_info)) |
| 5756 | return TRUE; |
| 5757 | else |
| 5758 | { |
| 5759 | gas_assert (error_info.kind != AARCH64_OPDE_NIL); |
| 5760 | record_operand_error_info (opcode, &error_info); |
| 5761 | return FALSE; |
| 5762 | } |
| 5763 | } |
| 5764 | |
| 5765 | #ifdef DEBUG_AARCH64 |
| 5766 | static inline void |
| 5767 | dump_opcode_operands (const aarch64_opcode *opcode) |
| 5768 | { |
| 5769 | int i = 0; |
| 5770 | while (opcode->operands[i] != AARCH64_OPND_NIL) |
| 5771 | { |
| 5772 | aarch64_verbose ("\t\t opnd%d: %s", i, |
| 5773 | aarch64_get_operand_name (opcode->operands[i])[0] != '\0' |
| 5774 | ? aarch64_get_operand_name (opcode->operands[i]) |
| 5775 | : aarch64_get_operand_desc (opcode->operands[i])); |
| 5776 | ++i; |
| 5777 | } |
| 5778 | } |
| 5779 | #endif /* DEBUG_AARCH64 */ |
| 5780 | |
| 5781 | /* This is the guts of the machine-dependent assembler. STR points to a |
| 5782 | machine dependent instruction. This function is supposed to emit |
| 5783 | the frags/bytes it assembles to. */ |
| 5784 | |
| 5785 | void |
| 5786 | md_assemble (char *str) |
| 5787 | { |
| 5788 | char *p = str; |
| 5789 | templates *template; |
| 5790 | aarch64_opcode *opcode; |
| 5791 | aarch64_inst *inst_base; |
| 5792 | unsigned saved_cond; |
| 5793 | |
| 5794 | /* Align the previous label if needed. */ |
| 5795 | if (last_label_seen != NULL) |
| 5796 | { |
| 5797 | symbol_set_frag (last_label_seen, frag_now); |
| 5798 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); |
| 5799 | S_SET_SEGMENT (last_label_seen, now_seg); |
| 5800 | } |
| 5801 | |
| 5802 | inst.reloc.type = BFD_RELOC_UNUSED; |
| 5803 | |
| 5804 | DEBUG_TRACE ("\n\n"); |
| 5805 | DEBUG_TRACE ("=============================="); |
| 5806 | DEBUG_TRACE ("Enter md_assemble with %s", str); |
| 5807 | |
| 5808 | template = opcode_lookup (&p); |
| 5809 | if (!template) |
| 5810 | { |
| 5811 | /* It wasn't an instruction, but it might be a register alias of |
| 5812 | the form alias .req reg directive. */ |
| 5813 | if (!create_register_alias (str, p)) |
| 5814 | as_bad (_("unknown mnemonic `%s' -- `%s'"), get_mnemonic_name (str), |
| 5815 | str); |
| 5816 | return; |
| 5817 | } |
| 5818 | |
| 5819 | skip_whitespace (p); |
| 5820 | if (*p == ',') |
| 5821 | { |
| 5822 | as_bad (_("unexpected comma after the mnemonic name `%s' -- `%s'"), |
| 5823 | get_mnemonic_name (str), str); |
| 5824 | return; |
| 5825 | } |
| 5826 | |
| 5827 | init_operand_error_report (); |
| 5828 | |
| 5829 | /* Sections are assumed to start aligned. In executable section, there is no |
| 5830 | MAP_DATA symbol pending. So we only align the address during |
| 5831 | MAP_DATA --> MAP_INSN transition. |
| 5832 | For other sections, this is not guaranteed. */ |
| 5833 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
| 5834 | if (!need_pass_2 && subseg_text_p (now_seg) && mapstate == MAP_DATA) |
| 5835 | frag_align_code (2, 0); |
| 5836 | |
| 5837 | saved_cond = inst.cond; |
| 5838 | reset_aarch64_instruction (&inst); |
| 5839 | inst.cond = saved_cond; |
| 5840 | |
| 5841 | /* Iterate through all opcode entries with the same mnemonic name. */ |
| 5842 | do |
| 5843 | { |
| 5844 | opcode = template->opcode; |
| 5845 | |
| 5846 | DEBUG_TRACE ("opcode %s found", opcode->name); |
| 5847 | #ifdef DEBUG_AARCH64 |
| 5848 | if (debug_dump) |
| 5849 | dump_opcode_operands (opcode); |
| 5850 | #endif /* DEBUG_AARCH64 */ |
| 5851 | |
| 5852 | mapping_state (MAP_INSN); |
| 5853 | |
| 5854 | inst_base = &inst.base; |
| 5855 | inst_base->opcode = opcode; |
| 5856 | |
| 5857 | /* Truly conditionally executed instructions, e.g. b.cond. */ |
| 5858 | if (opcode->flags & F_COND) |
| 5859 | { |
| 5860 | gas_assert (inst.cond != COND_ALWAYS); |
| 5861 | inst_base->cond = get_cond_from_value (inst.cond); |
| 5862 | DEBUG_TRACE ("condition found %s", inst_base->cond->names[0]); |
| 5863 | } |
| 5864 | else if (inst.cond != COND_ALWAYS) |
| 5865 | { |
| 5866 | /* It shouldn't arrive here, where the assembly looks like a |
| 5867 | conditional instruction but the found opcode is unconditional. */ |
| 5868 | gas_assert (0); |
| 5869 | continue; |
| 5870 | } |
| 5871 | |
| 5872 | if (parse_operands (p, opcode) |
| 5873 | && programmer_friendly_fixup (&inst) |
| 5874 | && do_encode (inst_base->opcode, &inst.base, &inst_base->value)) |
| 5875 | { |
| 5876 | /* Check that this instruction is supported for this CPU. */ |
| 5877 | if (!opcode->avariant |
| 5878 | || !AARCH64_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)) |
| 5879 | { |
| 5880 | as_bad (_("selected processor does not support `%s'"), str); |
| 5881 | return; |
| 5882 | } |
| 5883 | |
| 5884 | warn_unpredictable_ldst (&inst, str); |
| 5885 | |
| 5886 | if (inst.reloc.type == BFD_RELOC_UNUSED |
| 5887 | || !inst.reloc.need_libopcodes_p) |
| 5888 | output_inst (NULL); |
| 5889 | else |
| 5890 | { |
| 5891 | /* If there is relocation generated for the instruction, |
| 5892 | store the instruction information for the future fix-up. */ |
| 5893 | struct aarch64_inst *copy; |
| 5894 | gas_assert (inst.reloc.type != BFD_RELOC_UNUSED); |
| 5895 | if ((copy = xmalloc (sizeof (struct aarch64_inst))) == NULL) |
| 5896 | abort (); |
| 5897 | memcpy (copy, &inst.base, sizeof (struct aarch64_inst)); |
| 5898 | output_inst (copy); |
| 5899 | } |
| 5900 | return; |
| 5901 | } |
| 5902 | |
| 5903 | template = template->next; |
| 5904 | if (template != NULL) |
| 5905 | { |
| 5906 | reset_aarch64_instruction (&inst); |
| 5907 | inst.cond = saved_cond; |
| 5908 | } |
| 5909 | } |
| 5910 | while (template != NULL); |
| 5911 | |
| 5912 | /* Issue the error messages if any. */ |
| 5913 | output_operand_error_report (str); |
| 5914 | } |
| 5915 | |
| 5916 | /* Various frobbings of labels and their addresses. */ |
| 5917 | |
| 5918 | void |
| 5919 | aarch64_start_line_hook (void) |
| 5920 | { |
| 5921 | last_label_seen = NULL; |
| 5922 | } |
| 5923 | |
| 5924 | void |
| 5925 | aarch64_frob_label (symbolS * sym) |
| 5926 | { |
| 5927 | last_label_seen = sym; |
| 5928 | |
| 5929 | dwarf2_emit_label (sym); |
| 5930 | } |
| 5931 | |
| 5932 | int |
| 5933 | aarch64_data_in_code (void) |
| 5934 | { |
| 5935 | if (!strncmp (input_line_pointer + 1, "data:", 5)) |
| 5936 | { |
| 5937 | *input_line_pointer = '/'; |
| 5938 | input_line_pointer += 5; |
| 5939 | *input_line_pointer = 0; |
| 5940 | return 1; |
| 5941 | } |
| 5942 | |
| 5943 | return 0; |
| 5944 | } |
| 5945 | |
| 5946 | char * |
| 5947 | aarch64_canonicalize_symbol_name (char *name) |
| 5948 | { |
| 5949 | int len; |
| 5950 | |
| 5951 | if ((len = strlen (name)) > 5 && streq (name + len - 5, "/data")) |
| 5952 | *(name + len - 5) = 0; |
| 5953 | |
| 5954 | return name; |
| 5955 | } |
| 5956 | \f |
| 5957 | /* Table of all register names defined by default. The user can |
| 5958 | define additional names with .req. Note that all register names |
| 5959 | should appear in both upper and lowercase variants. Some registers |
| 5960 | also have mixed-case names. */ |
| 5961 | |
| 5962 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE } |
| 5963 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
| 5964 | #define REGSET31(p,t) \ |
| 5965 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ |
| 5966 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ |
| 5967 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ |
| 5968 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t), \ |
| 5969 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ |
| 5970 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ |
| 5971 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ |
| 5972 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t) |
| 5973 | #define REGSET(p,t) \ |
| 5974 | REGSET31(p,t), REGNUM(p,31,t) |
| 5975 | |
| 5976 | /* These go into aarch64_reg_hsh hash-table. */ |
| 5977 | static const reg_entry reg_names[] = { |
| 5978 | /* Integer registers. */ |
| 5979 | REGSET31 (x, R_64), REGSET31 (X, R_64), |
| 5980 | REGSET31 (w, R_32), REGSET31 (W, R_32), |
| 5981 | |
| 5982 | REGDEF (wsp, 31, SP_32), REGDEF (WSP, 31, SP_32), |
| 5983 | REGDEF (sp, 31, SP_64), REGDEF (SP, 31, SP_64), |
| 5984 | |
| 5985 | REGDEF (wzr, 31, Z_32), REGDEF (WZR, 31, Z_32), |
| 5986 | REGDEF (xzr, 31, Z_64), REGDEF (XZR, 31, Z_64), |
| 5987 | |
| 5988 | /* Coprocessor register numbers. */ |
| 5989 | REGSET (c, CN), REGSET (C, CN), |
| 5990 | |
| 5991 | /* Floating-point single precision registers. */ |
| 5992 | REGSET (s, FP_S), REGSET (S, FP_S), |
| 5993 | |
| 5994 | /* Floating-point double precision registers. */ |
| 5995 | REGSET (d, FP_D), REGSET (D, FP_D), |
| 5996 | |
| 5997 | /* Floating-point half precision registers. */ |
| 5998 | REGSET (h, FP_H), REGSET (H, FP_H), |
| 5999 | |
| 6000 | /* Floating-point byte precision registers. */ |
| 6001 | REGSET (b, FP_B), REGSET (B, FP_B), |
| 6002 | |
| 6003 | /* Floating-point quad precision registers. */ |
| 6004 | REGSET (q, FP_Q), REGSET (Q, FP_Q), |
| 6005 | |
| 6006 | /* FP/SIMD registers. */ |
| 6007 | REGSET (v, VN), REGSET (V, VN), |
| 6008 | }; |
| 6009 | |
| 6010 | #undef REGDEF |
| 6011 | #undef REGNUM |
| 6012 | #undef REGSET |
| 6013 | |
| 6014 | #define N 1 |
| 6015 | #define n 0 |
| 6016 | #define Z 1 |
| 6017 | #define z 0 |
| 6018 | #define C 1 |
| 6019 | #define c 0 |
| 6020 | #define V 1 |
| 6021 | #define v 0 |
| 6022 | #define B(a,b,c,d) (((a) << 3) | ((b) << 2) | ((c) << 1) | (d)) |
| 6023 | static const asm_nzcv nzcv_names[] = { |
| 6024 | {"nzcv", B (n, z, c, v)}, |
| 6025 | {"nzcV", B (n, z, c, V)}, |
| 6026 | {"nzCv", B (n, z, C, v)}, |
| 6027 | {"nzCV", B (n, z, C, V)}, |
| 6028 | {"nZcv", B (n, Z, c, v)}, |
| 6029 | {"nZcV", B (n, Z, c, V)}, |
| 6030 | {"nZCv", B (n, Z, C, v)}, |
| 6031 | {"nZCV", B (n, Z, C, V)}, |
| 6032 | {"Nzcv", B (N, z, c, v)}, |
| 6033 | {"NzcV", B (N, z, c, V)}, |
| 6034 | {"NzCv", B (N, z, C, v)}, |
| 6035 | {"NzCV", B (N, z, C, V)}, |
| 6036 | {"NZcv", B (N, Z, c, v)}, |
| 6037 | {"NZcV", B (N, Z, c, V)}, |
| 6038 | {"NZCv", B (N, Z, C, v)}, |
| 6039 | {"NZCV", B (N, Z, C, V)} |
| 6040 | }; |
| 6041 | |
| 6042 | #undef N |
| 6043 | #undef n |
| 6044 | #undef Z |
| 6045 | #undef z |
| 6046 | #undef C |
| 6047 | #undef c |
| 6048 | #undef V |
| 6049 | #undef v |
| 6050 | #undef B |
| 6051 | \f |
| 6052 | /* MD interface: bits in the object file. */ |
| 6053 | |
| 6054 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
| 6055 | for use in the a.out file, and stores them in the array pointed to by buf. |
| 6056 | This knows about the endian-ness of the target machine and does |
| 6057 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) |
| 6058 | 2 (short) and 4 (long) Floating numbers are put out as a series of |
| 6059 | LITTLENUMS (shorts, here at least). */ |
| 6060 | |
| 6061 | void |
| 6062 | md_number_to_chars (char *buf, valueT val, int n) |
| 6063 | { |
| 6064 | if (target_big_endian) |
| 6065 | number_to_chars_bigendian (buf, val, n); |
| 6066 | else |
| 6067 | number_to_chars_littleendian (buf, val, n); |
| 6068 | } |
| 6069 | |
| 6070 | /* MD interface: Sections. */ |
| 6071 | |
| 6072 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
| 6073 | 4 bytes. */ |
| 6074 | |
| 6075 | int |
| 6076 | md_estimate_size_before_relax (fragS * fragp, segT segtype ATTRIBUTE_UNUSED) |
| 6077 | { |
| 6078 | fragp->fr_var = 4; |
| 6079 | return 4; |
| 6080 | } |
| 6081 | |
| 6082 | /* Round up a section size to the appropriate boundary. */ |
| 6083 | |
| 6084 | valueT |
| 6085 | md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size) |
| 6086 | { |
| 6087 | return size; |
| 6088 | } |
| 6089 | |
| 6090 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
| 6091 | of an rs_align_code fragment. |
| 6092 | |
| 6093 | Here we fill the frag with the appropriate info for padding the |
| 6094 | output stream. The resulting frag will consist of a fixed (fr_fix) |
| 6095 | and of a repeating (fr_var) part. |
| 6096 | |
| 6097 | The fixed content is always emitted before the repeating content and |
| 6098 | these two parts are used as follows in constructing the output: |
| 6099 | - the fixed part will be used to align to a valid instruction word |
| 6100 | boundary, in case that we start at a misaligned address; as no |
| 6101 | executable instruction can live at the misaligned location, we |
| 6102 | simply fill with zeros; |
| 6103 | - the variable part will be used to cover the remaining padding and |
| 6104 | we fill using the AArch64 NOP instruction. |
| 6105 | |
| 6106 | Note that the size of a RS_ALIGN_CODE fragment is always 7 to provide |
| 6107 | enough storage space for up to 3 bytes for padding the back to a valid |
| 6108 | instruction alignment and exactly 4 bytes to store the NOP pattern. */ |
| 6109 | |
| 6110 | void |
| 6111 | aarch64_handle_align (fragS * fragP) |
| 6112 | { |
| 6113 | /* NOP = d503201f */ |
| 6114 | /* AArch64 instructions are always little-endian. */ |
| 6115 | static char const aarch64_noop[4] = { 0x1f, 0x20, 0x03, 0xd5 }; |
| 6116 | |
| 6117 | int bytes, fix, noop_size; |
| 6118 | char *p; |
| 6119 | |
| 6120 | if (fragP->fr_type != rs_align_code) |
| 6121 | return; |
| 6122 | |
| 6123 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
| 6124 | p = fragP->fr_literal + fragP->fr_fix; |
| 6125 | |
| 6126 | #ifdef OBJ_ELF |
| 6127 | gas_assert (fragP->tc_frag_data.recorded); |
| 6128 | #endif |
| 6129 | |
| 6130 | noop_size = sizeof (aarch64_noop); |
| 6131 | |
| 6132 | fix = bytes & (noop_size - 1); |
| 6133 | if (fix) |
| 6134 | { |
| 6135 | #ifdef OBJ_ELF |
| 6136 | insert_data_mapping_symbol (MAP_INSN, fragP->fr_fix, fragP, fix); |
| 6137 | #endif |
| 6138 | memset (p, 0, fix); |
| 6139 | p += fix; |
| 6140 | fragP->fr_fix += fix; |
| 6141 | } |
| 6142 | |
| 6143 | if (noop_size) |
| 6144 | memcpy (p, aarch64_noop, noop_size); |
| 6145 | fragP->fr_var = noop_size; |
| 6146 | } |
| 6147 | |
| 6148 | /* Perform target specific initialisation of a frag. |
| 6149 | Note - despite the name this initialisation is not done when the frag |
| 6150 | is created, but only when its type is assigned. A frag can be created |
| 6151 | and used a long time before its type is set, so beware of assuming that |
| 6152 | this initialisationis performed first. */ |
| 6153 | |
| 6154 | #ifndef OBJ_ELF |
| 6155 | void |
| 6156 | aarch64_init_frag (fragS * fragP ATTRIBUTE_UNUSED, |
| 6157 | int max_chars ATTRIBUTE_UNUSED) |
| 6158 | { |
| 6159 | } |
| 6160 | |
| 6161 | #else /* OBJ_ELF is defined. */ |
| 6162 | void |
| 6163 | aarch64_init_frag (fragS * fragP, int max_chars) |
| 6164 | { |
| 6165 | /* Record a mapping symbol for alignment frags. We will delete this |
| 6166 | later if the alignment ends up empty. */ |
| 6167 | if (!fragP->tc_frag_data.recorded) |
| 6168 | fragP->tc_frag_data.recorded = 1; |
| 6169 | |
| 6170 | switch (fragP->fr_type) |
| 6171 | { |
| 6172 | case rs_align: |
| 6173 | case rs_align_test: |
| 6174 | case rs_fill: |
| 6175 | mapping_state_2 (MAP_DATA, max_chars); |
| 6176 | break; |
| 6177 | case rs_align_code: |
| 6178 | mapping_state_2 (MAP_INSN, max_chars); |
| 6179 | break; |
| 6180 | default: |
| 6181 | break; |
| 6182 | } |
| 6183 | } |
| 6184 | \f |
| 6185 | /* Initialize the DWARF-2 unwind information for this procedure. */ |
| 6186 | |
| 6187 | void |
| 6188 | tc_aarch64_frame_initial_instructions (void) |
| 6189 | { |
| 6190 | cfi_add_CFA_def_cfa (REG_SP, 0); |
| 6191 | } |
| 6192 | #endif /* OBJ_ELF */ |
| 6193 | |
| 6194 | /* Convert REGNAME to a DWARF-2 register number. */ |
| 6195 | |
| 6196 | int |
| 6197 | tc_aarch64_regname_to_dw2regnum (char *regname) |
| 6198 | { |
| 6199 | const reg_entry *reg = parse_reg (®name); |
| 6200 | if (reg == NULL) |
| 6201 | return -1; |
| 6202 | |
| 6203 | switch (reg->type) |
| 6204 | { |
| 6205 | case REG_TYPE_SP_32: |
| 6206 | case REG_TYPE_SP_64: |
| 6207 | case REG_TYPE_R_32: |
| 6208 | case REG_TYPE_R_64: |
| 6209 | return reg->number; |
| 6210 | |
| 6211 | case REG_TYPE_FP_B: |
| 6212 | case REG_TYPE_FP_H: |
| 6213 | case REG_TYPE_FP_S: |
| 6214 | case REG_TYPE_FP_D: |
| 6215 | case REG_TYPE_FP_Q: |
| 6216 | return reg->number + 64; |
| 6217 | |
| 6218 | default: |
| 6219 | break; |
| 6220 | } |
| 6221 | return -1; |
| 6222 | } |
| 6223 | |
| 6224 | /* Implement DWARF2_ADDR_SIZE. */ |
| 6225 | |
| 6226 | int |
| 6227 | aarch64_dwarf2_addr_size (void) |
| 6228 | { |
| 6229 | #if defined (OBJ_MAYBE_ELF) || defined (OBJ_ELF) |
| 6230 | if (ilp32_p) |
| 6231 | return 4; |
| 6232 | #endif |
| 6233 | return bfd_arch_bits_per_address (stdoutput) / 8; |
| 6234 | } |
| 6235 | |
| 6236 | /* MD interface: Symbol and relocation handling. */ |
| 6237 | |
| 6238 | /* Return the address within the segment that a PC-relative fixup is |
| 6239 | relative to. For AArch64 PC-relative fixups applied to instructions |
| 6240 | are generally relative to the location plus AARCH64_PCREL_OFFSET bytes. */ |
| 6241 | |
| 6242 | long |
| 6243 | md_pcrel_from_section (fixS * fixP, segT seg) |
| 6244 | { |
| 6245 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
| 6246 | |
| 6247 | /* If this is pc-relative and we are going to emit a relocation |
| 6248 | then we just want to put out any pipeline compensation that the linker |
| 6249 | will need. Otherwise we want to use the calculated base. */ |
| 6250 | if (fixP->fx_pcrel |
| 6251 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
| 6252 | || aarch64_force_relocation (fixP))) |
| 6253 | base = 0; |
| 6254 | |
| 6255 | /* AArch64 should be consistent for all pc-relative relocations. */ |
| 6256 | return base + AARCH64_PCREL_OFFSET; |
| 6257 | } |
| 6258 | |
| 6259 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
| 6260 | Otherwise we have no need to default values of symbols. */ |
| 6261 | |
| 6262 | symbolS * |
| 6263 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
| 6264 | { |
| 6265 | #ifdef OBJ_ELF |
| 6266 | if (name[0] == '_' && name[1] == 'G' |
| 6267 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) |
| 6268 | { |
| 6269 | if (!GOT_symbol) |
| 6270 | { |
| 6271 | if (symbol_find (name)) |
| 6272 | as_bad (_("GOT already in the symbol table")); |
| 6273 | |
| 6274 | GOT_symbol = symbol_new (name, undefined_section, |
| 6275 | (valueT) 0, &zero_address_frag); |
| 6276 | } |
| 6277 | |
| 6278 | return GOT_symbol; |
| 6279 | } |
| 6280 | #endif |
| 6281 | |
| 6282 | return 0; |
| 6283 | } |
| 6284 | |
| 6285 | /* Return non-zero if the indicated VALUE has overflowed the maximum |
| 6286 | range expressible by a unsigned number with the indicated number of |
| 6287 | BITS. */ |
| 6288 | |
| 6289 | static bfd_boolean |
| 6290 | unsigned_overflow (valueT value, unsigned bits) |
| 6291 | { |
| 6292 | valueT lim; |
| 6293 | if (bits >= sizeof (valueT) * 8) |
| 6294 | return FALSE; |
| 6295 | lim = (valueT) 1 << bits; |
| 6296 | return (value >= lim); |
| 6297 | } |
| 6298 | |
| 6299 | |
| 6300 | /* Return non-zero if the indicated VALUE has overflowed the maximum |
| 6301 | range expressible by an signed number with the indicated number of |
| 6302 | BITS. */ |
| 6303 | |
| 6304 | static bfd_boolean |
| 6305 | signed_overflow (offsetT value, unsigned bits) |
| 6306 | { |
| 6307 | offsetT lim; |
| 6308 | if (bits >= sizeof (offsetT) * 8) |
| 6309 | return FALSE; |
| 6310 | lim = (offsetT) 1 << (bits - 1); |
| 6311 | return (value < -lim || value >= lim); |
| 6312 | } |
| 6313 | |
| 6314 | /* Given an instruction in *INST, which is expected to be a scaled, 12-bit, |
| 6315 | unsigned immediate offset load/store instruction, try to encode it as |
| 6316 | an unscaled, 9-bit, signed immediate offset load/store instruction. |
| 6317 | Return TRUE if it is successful; otherwise return FALSE. |
| 6318 | |
| 6319 | As a programmer-friendly assembler, LDUR/STUR instructions can be generated |
| 6320 | in response to the standard LDR/STR mnemonics when the immediate offset is |
| 6321 | unambiguous, i.e. when it is negative or unaligned. */ |
| 6322 | |
| 6323 | static bfd_boolean |
| 6324 | try_to_encode_as_unscaled_ldst (aarch64_inst *instr) |
| 6325 | { |
| 6326 | int idx; |
| 6327 | enum aarch64_op new_op; |
| 6328 | const aarch64_opcode *new_opcode; |
| 6329 | |
| 6330 | gas_assert (instr->opcode->iclass == ldst_pos); |
| 6331 | |
| 6332 | switch (instr->opcode->op) |
| 6333 | { |
| 6334 | case OP_LDRB_POS:new_op = OP_LDURB; break; |
| 6335 | case OP_STRB_POS: new_op = OP_STURB; break; |
| 6336 | case OP_LDRSB_POS: new_op = OP_LDURSB; break; |
| 6337 | case OP_LDRH_POS: new_op = OP_LDURH; break; |
| 6338 | case OP_STRH_POS: new_op = OP_STURH; break; |
| 6339 | case OP_LDRSH_POS: new_op = OP_LDURSH; break; |
| 6340 | case OP_LDR_POS: new_op = OP_LDUR; break; |
| 6341 | case OP_STR_POS: new_op = OP_STUR; break; |
| 6342 | case OP_LDRF_POS: new_op = OP_LDURV; break; |
| 6343 | case OP_STRF_POS: new_op = OP_STURV; break; |
| 6344 | case OP_LDRSW_POS: new_op = OP_LDURSW; break; |
| 6345 | case OP_PRFM_POS: new_op = OP_PRFUM; break; |
| 6346 | default: new_op = OP_NIL; break; |
| 6347 | } |
| 6348 | |
| 6349 | if (new_op == OP_NIL) |
| 6350 | return FALSE; |
| 6351 | |
| 6352 | new_opcode = aarch64_get_opcode (new_op); |
| 6353 | gas_assert (new_opcode != NULL); |
| 6354 | |
| 6355 | DEBUG_TRACE ("Check programmer-friendly STURB/LDURB -> STRB/LDRB: %d == %d", |
| 6356 | instr->opcode->op, new_opcode->op); |
| 6357 | |
| 6358 | aarch64_replace_opcode (instr, new_opcode); |
| 6359 | |
| 6360 | /* Clear up the ADDR_SIMM9's qualifier; otherwise the |
| 6361 | qualifier matching may fail because the out-of-date qualifier will |
| 6362 | prevent the operand being updated with a new and correct qualifier. */ |
| 6363 | idx = aarch64_operand_index (instr->opcode->operands, |
| 6364 | AARCH64_OPND_ADDR_SIMM9); |
| 6365 | gas_assert (idx == 1); |
| 6366 | instr->operands[idx].qualifier = AARCH64_OPND_QLF_NIL; |
| 6367 | |
| 6368 | DEBUG_TRACE ("Found LDURB entry to encode programmer-friendly LDRB"); |
| 6369 | |
| 6370 | if (!aarch64_opcode_encode (instr->opcode, instr, &instr->value, NULL, NULL)) |
| 6371 | return FALSE; |
| 6372 | |
| 6373 | return TRUE; |
| 6374 | } |
| 6375 | |
| 6376 | /* Called by fix_insn to fix a MOV immediate alias instruction. |
| 6377 | |
| 6378 | Operand for a generic move immediate instruction, which is an alias |
| 6379 | instruction that generates a single MOVZ, MOVN or ORR instruction to loads |
| 6380 | a 32-bit/64-bit immediate value into general register. An assembler error |
| 6381 | shall result if the immediate cannot be created by a single one of these |
| 6382 | instructions. If there is a choice, then to ensure reversability an |
| 6383 | assembler must prefer a MOVZ to MOVN, and MOVZ or MOVN to ORR. */ |
| 6384 | |
| 6385 | static void |
| 6386 | fix_mov_imm_insn (fixS *fixP, char *buf, aarch64_inst *instr, offsetT value) |
| 6387 | { |
| 6388 | const aarch64_opcode *opcode; |
| 6389 | |
| 6390 | /* Need to check if the destination is SP/ZR. The check has to be done |
| 6391 | before any aarch64_replace_opcode. */ |
| 6392 | int try_mov_wide_p = !aarch64_stack_pointer_p (&instr->operands[0]); |
| 6393 | int try_mov_bitmask_p = !aarch64_zero_register_p (&instr->operands[0]); |
| 6394 | |
| 6395 | instr->operands[1].imm.value = value; |
| 6396 | instr->operands[1].skip = 0; |
| 6397 | |
| 6398 | if (try_mov_wide_p) |
| 6399 | { |
| 6400 | /* Try the MOVZ alias. */ |
| 6401 | opcode = aarch64_get_opcode (OP_MOV_IMM_WIDE); |
| 6402 | aarch64_replace_opcode (instr, opcode); |
| 6403 | if (aarch64_opcode_encode (instr->opcode, instr, |
| 6404 | &instr->value, NULL, NULL)) |
| 6405 | { |
| 6406 | put_aarch64_insn (buf, instr->value); |
| 6407 | return; |
| 6408 | } |
| 6409 | /* Try the MOVK alias. */ |
| 6410 | opcode = aarch64_get_opcode (OP_MOV_IMM_WIDEN); |
| 6411 | aarch64_replace_opcode (instr, opcode); |
| 6412 | if (aarch64_opcode_encode (instr->opcode, instr, |
| 6413 | &instr->value, NULL, NULL)) |
| 6414 | { |
| 6415 | put_aarch64_insn (buf, instr->value); |
| 6416 | return; |
| 6417 | } |
| 6418 | } |
| 6419 | |
| 6420 | if (try_mov_bitmask_p) |
| 6421 | { |
| 6422 | /* Try the ORR alias. */ |
| 6423 | opcode = aarch64_get_opcode (OP_MOV_IMM_LOG); |
| 6424 | aarch64_replace_opcode (instr, opcode); |
| 6425 | if (aarch64_opcode_encode (instr->opcode, instr, |
| 6426 | &instr->value, NULL, NULL)) |
| 6427 | { |
| 6428 | put_aarch64_insn (buf, instr->value); |
| 6429 | return; |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6434 | _("immediate cannot be moved by a single instruction")); |
| 6435 | } |
| 6436 | |
| 6437 | /* An instruction operand which is immediate related may have symbol used |
| 6438 | in the assembly, e.g. |
| 6439 | |
| 6440 | mov w0, u32 |
| 6441 | .set u32, 0x00ffff00 |
| 6442 | |
| 6443 | At the time when the assembly instruction is parsed, a referenced symbol, |
| 6444 | like 'u32' in the above example may not have been seen; a fixS is created |
| 6445 | in such a case and is handled here after symbols have been resolved. |
| 6446 | Instruction is fixed up with VALUE using the information in *FIXP plus |
| 6447 | extra information in FLAGS. |
| 6448 | |
| 6449 | This function is called by md_apply_fix to fix up instructions that need |
| 6450 | a fix-up described above but does not involve any linker-time relocation. */ |
| 6451 | |
| 6452 | static void |
| 6453 | fix_insn (fixS *fixP, uint32_t flags, offsetT value) |
| 6454 | { |
| 6455 | int idx; |
| 6456 | uint32_t insn; |
| 6457 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 6458 | enum aarch64_opnd opnd = fixP->tc_fix_data.opnd; |
| 6459 | aarch64_inst *new_inst = fixP->tc_fix_data.inst; |
| 6460 | |
| 6461 | if (new_inst) |
| 6462 | { |
| 6463 | /* Now the instruction is about to be fixed-up, so the operand that |
| 6464 | was previously marked as 'ignored' needs to be unmarked in order |
| 6465 | to get the encoding done properly. */ |
| 6466 | idx = aarch64_operand_index (new_inst->opcode->operands, opnd); |
| 6467 | new_inst->operands[idx].skip = 0; |
| 6468 | } |
| 6469 | |
| 6470 | gas_assert (opnd != AARCH64_OPND_NIL); |
| 6471 | |
| 6472 | switch (opnd) |
| 6473 | { |
| 6474 | case AARCH64_OPND_EXCEPTION: |
| 6475 | if (unsigned_overflow (value, 16)) |
| 6476 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6477 | _("immediate out of range")); |
| 6478 | insn = get_aarch64_insn (buf); |
| 6479 | insn |= encode_svc_imm (value); |
| 6480 | put_aarch64_insn (buf, insn); |
| 6481 | break; |
| 6482 | |
| 6483 | case AARCH64_OPND_AIMM: |
| 6484 | /* ADD or SUB with immediate. |
| 6485 | NOTE this assumes we come here with a add/sub shifted reg encoding |
| 6486 | 3 322|2222|2 2 2 21111 111111 |
| 6487 | 1 098|7654|3 2 1 09876 543210 98765 43210 |
| 6488 | 0b000000 sf 000|1011|shift 0 Rm imm6 Rn Rd ADD |
| 6489 | 2b000000 sf 010|1011|shift 0 Rm imm6 Rn Rd ADDS |
| 6490 | 4b000000 sf 100|1011|shift 0 Rm imm6 Rn Rd SUB |
| 6491 | 6b000000 sf 110|1011|shift 0 Rm imm6 Rn Rd SUBS |
| 6492 | -> |
| 6493 | 3 322|2222|2 2 221111111111 |
| 6494 | 1 098|7654|3 2 109876543210 98765 43210 |
| 6495 | 11000000 sf 001|0001|shift imm12 Rn Rd ADD |
| 6496 | 31000000 sf 011|0001|shift imm12 Rn Rd ADDS |
| 6497 | 51000000 sf 101|0001|shift imm12 Rn Rd SUB |
| 6498 | 71000000 sf 111|0001|shift imm12 Rn Rd SUBS |
| 6499 | Fields sf Rn Rd are already set. */ |
| 6500 | insn = get_aarch64_insn (buf); |
| 6501 | if (value < 0) |
| 6502 | { |
| 6503 | /* Add <-> sub. */ |
| 6504 | insn = reencode_addsub_switch_add_sub (insn); |
| 6505 | value = -value; |
| 6506 | } |
| 6507 | |
| 6508 | if ((flags & FIXUP_F_HAS_EXPLICIT_SHIFT) == 0 |
| 6509 | && unsigned_overflow (value, 12)) |
| 6510 | { |
| 6511 | /* Try to shift the value by 12 to make it fit. */ |
| 6512 | if (((value >> 12) << 12) == value |
| 6513 | && ! unsigned_overflow (value, 12 + 12)) |
| 6514 | { |
| 6515 | value >>= 12; |
| 6516 | insn |= encode_addsub_imm_shift_amount (1); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | if (unsigned_overflow (value, 12)) |
| 6521 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6522 | _("immediate out of range")); |
| 6523 | |
| 6524 | insn |= encode_addsub_imm (value); |
| 6525 | |
| 6526 | put_aarch64_insn (buf, insn); |
| 6527 | break; |
| 6528 | |
| 6529 | case AARCH64_OPND_SIMD_IMM: |
| 6530 | case AARCH64_OPND_SIMD_IMM_SFT: |
| 6531 | case AARCH64_OPND_LIMM: |
| 6532 | /* Bit mask immediate. */ |
| 6533 | gas_assert (new_inst != NULL); |
| 6534 | idx = aarch64_operand_index (new_inst->opcode->operands, opnd); |
| 6535 | new_inst->operands[idx].imm.value = value; |
| 6536 | if (aarch64_opcode_encode (new_inst->opcode, new_inst, |
| 6537 | &new_inst->value, NULL, NULL)) |
| 6538 | put_aarch64_insn (buf, new_inst->value); |
| 6539 | else |
| 6540 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6541 | _("invalid immediate")); |
| 6542 | break; |
| 6543 | |
| 6544 | case AARCH64_OPND_HALF: |
| 6545 | /* 16-bit unsigned immediate. */ |
| 6546 | if (unsigned_overflow (value, 16)) |
| 6547 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6548 | _("immediate out of range")); |
| 6549 | insn = get_aarch64_insn (buf); |
| 6550 | insn |= encode_movw_imm (value & 0xffff); |
| 6551 | put_aarch64_insn (buf, insn); |
| 6552 | break; |
| 6553 | |
| 6554 | case AARCH64_OPND_IMM_MOV: |
| 6555 | /* Operand for a generic move immediate instruction, which is |
| 6556 | an alias instruction that generates a single MOVZ, MOVN or ORR |
| 6557 | instruction to loads a 32-bit/64-bit immediate value into general |
| 6558 | register. An assembler error shall result if the immediate cannot be |
| 6559 | created by a single one of these instructions. If there is a choice, |
| 6560 | then to ensure reversability an assembler must prefer a MOVZ to MOVN, |
| 6561 | and MOVZ or MOVN to ORR. */ |
| 6562 | gas_assert (new_inst != NULL); |
| 6563 | fix_mov_imm_insn (fixP, buf, new_inst, value); |
| 6564 | break; |
| 6565 | |
| 6566 | case AARCH64_OPND_ADDR_SIMM7: |
| 6567 | case AARCH64_OPND_ADDR_SIMM9: |
| 6568 | case AARCH64_OPND_ADDR_SIMM9_2: |
| 6569 | case AARCH64_OPND_ADDR_UIMM12: |
| 6570 | /* Immediate offset in an address. */ |
| 6571 | insn = get_aarch64_insn (buf); |
| 6572 | |
| 6573 | gas_assert (new_inst != NULL && new_inst->value == insn); |
| 6574 | gas_assert (new_inst->opcode->operands[1] == opnd |
| 6575 | || new_inst->opcode->operands[2] == opnd); |
| 6576 | |
| 6577 | /* Get the index of the address operand. */ |
| 6578 | if (new_inst->opcode->operands[1] == opnd) |
| 6579 | /* e.g. STR <Xt>, [<Xn|SP>, <R><m>{, <extend> {<amount>}}]. */ |
| 6580 | idx = 1; |
| 6581 | else |
| 6582 | /* e.g. LDP <Qt1>, <Qt2>, [<Xn|SP>{, #<imm>}]. */ |
| 6583 | idx = 2; |
| 6584 | |
| 6585 | /* Update the resolved offset value. */ |
| 6586 | new_inst->operands[idx].addr.offset.imm = value; |
| 6587 | |
| 6588 | /* Encode/fix-up. */ |
| 6589 | if (aarch64_opcode_encode (new_inst->opcode, new_inst, |
| 6590 | &new_inst->value, NULL, NULL)) |
| 6591 | { |
| 6592 | put_aarch64_insn (buf, new_inst->value); |
| 6593 | break; |
| 6594 | } |
| 6595 | else if (new_inst->opcode->iclass == ldst_pos |
| 6596 | && try_to_encode_as_unscaled_ldst (new_inst)) |
| 6597 | { |
| 6598 | put_aarch64_insn (buf, new_inst->value); |
| 6599 | break; |
| 6600 | } |
| 6601 | |
| 6602 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6603 | _("immediate offset out of range")); |
| 6604 | break; |
| 6605 | |
| 6606 | default: |
| 6607 | gas_assert (0); |
| 6608 | as_fatal (_("unhandled operand code %d"), opnd); |
| 6609 | } |
| 6610 | } |
| 6611 | |
| 6612 | /* Apply a fixup (fixP) to segment data, once it has been determined |
| 6613 | by our caller that we have all the info we need to fix it up. |
| 6614 | |
| 6615 | Parameter valP is the pointer to the value of the bits. */ |
| 6616 | |
| 6617 | void |
| 6618 | md_apply_fix (fixS * fixP, valueT * valP, segT seg) |
| 6619 | { |
| 6620 | offsetT value = *valP; |
| 6621 | uint32_t insn; |
| 6622 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 6623 | int scale; |
| 6624 | unsigned flags = fixP->fx_addnumber; |
| 6625 | |
| 6626 | DEBUG_TRACE ("\n\n"); |
| 6627 | DEBUG_TRACE ("~~~~~~~~~~~~~~~~~~~~~~~~~"); |
| 6628 | DEBUG_TRACE ("Enter md_apply_fix"); |
| 6629 | |
| 6630 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
| 6631 | |
| 6632 | /* Note whether this will delete the relocation. */ |
| 6633 | |
| 6634 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
| 6635 | fixP->fx_done = 1; |
| 6636 | |
| 6637 | /* Process the relocations. */ |
| 6638 | switch (fixP->fx_r_type) |
| 6639 | { |
| 6640 | case BFD_RELOC_NONE: |
| 6641 | /* This will need to go in the object file. */ |
| 6642 | fixP->fx_done = 0; |
| 6643 | break; |
| 6644 | |
| 6645 | case BFD_RELOC_8: |
| 6646 | case BFD_RELOC_8_PCREL: |
| 6647 | if (fixP->fx_done || !seg->use_rela_p) |
| 6648 | md_number_to_chars (buf, value, 1); |
| 6649 | break; |
| 6650 | |
| 6651 | case BFD_RELOC_16: |
| 6652 | case BFD_RELOC_16_PCREL: |
| 6653 | if (fixP->fx_done || !seg->use_rela_p) |
| 6654 | md_number_to_chars (buf, value, 2); |
| 6655 | break; |
| 6656 | |
| 6657 | case BFD_RELOC_32: |
| 6658 | case BFD_RELOC_32_PCREL: |
| 6659 | if (fixP->fx_done || !seg->use_rela_p) |
| 6660 | md_number_to_chars (buf, value, 4); |
| 6661 | break; |
| 6662 | |
| 6663 | case BFD_RELOC_64: |
| 6664 | case BFD_RELOC_64_PCREL: |
| 6665 | if (fixP->fx_done || !seg->use_rela_p) |
| 6666 | md_number_to_chars (buf, value, 8); |
| 6667 | break; |
| 6668 | |
| 6669 | case BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP: |
| 6670 | /* We claim that these fixups have been processed here, even if |
| 6671 | in fact we generate an error because we do not have a reloc |
| 6672 | for them, so tc_gen_reloc() will reject them. */ |
| 6673 | fixP->fx_done = 1; |
| 6674 | if (fixP->fx_addsy && !S_IS_DEFINED (fixP->fx_addsy)) |
| 6675 | { |
| 6676 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6677 | _("undefined symbol %s used as an immediate value"), |
| 6678 | S_GET_NAME (fixP->fx_addsy)); |
| 6679 | goto apply_fix_return; |
| 6680 | } |
| 6681 | fix_insn (fixP, flags, value); |
| 6682 | break; |
| 6683 | |
| 6684 | case BFD_RELOC_AARCH64_LD_LO19_PCREL: |
| 6685 | if (fixP->fx_done || !seg->use_rela_p) |
| 6686 | { |
| 6687 | if (value & 3) |
| 6688 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6689 | _("pc-relative load offset not word aligned")); |
| 6690 | if (signed_overflow (value, 21)) |
| 6691 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6692 | _("pc-relative load offset out of range")); |
| 6693 | insn = get_aarch64_insn (buf); |
| 6694 | insn |= encode_ld_lit_ofs_19 (value >> 2); |
| 6695 | put_aarch64_insn (buf, insn); |
| 6696 | } |
| 6697 | break; |
| 6698 | |
| 6699 | case BFD_RELOC_AARCH64_ADR_LO21_PCREL: |
| 6700 | if (fixP->fx_done || !seg->use_rela_p) |
| 6701 | { |
| 6702 | if (signed_overflow (value, 21)) |
| 6703 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6704 | _("pc-relative address offset out of range")); |
| 6705 | insn = get_aarch64_insn (buf); |
| 6706 | insn |= encode_adr_imm (value); |
| 6707 | put_aarch64_insn (buf, insn); |
| 6708 | } |
| 6709 | break; |
| 6710 | |
| 6711 | case BFD_RELOC_AARCH64_BRANCH19: |
| 6712 | if (fixP->fx_done || !seg->use_rela_p) |
| 6713 | { |
| 6714 | if (value & 3) |
| 6715 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6716 | _("conditional branch target not word aligned")); |
| 6717 | if (signed_overflow (value, 21)) |
| 6718 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6719 | _("conditional branch out of range")); |
| 6720 | insn = get_aarch64_insn (buf); |
| 6721 | insn |= encode_cond_branch_ofs_19 (value >> 2); |
| 6722 | put_aarch64_insn (buf, insn); |
| 6723 | } |
| 6724 | break; |
| 6725 | |
| 6726 | case BFD_RELOC_AARCH64_TSTBR14: |
| 6727 | if (fixP->fx_done || !seg->use_rela_p) |
| 6728 | { |
| 6729 | if (value & 3) |
| 6730 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6731 | _("conditional branch target not word aligned")); |
| 6732 | if (signed_overflow (value, 16)) |
| 6733 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6734 | _("conditional branch out of range")); |
| 6735 | insn = get_aarch64_insn (buf); |
| 6736 | insn |= encode_tst_branch_ofs_14 (value >> 2); |
| 6737 | put_aarch64_insn (buf, insn); |
| 6738 | } |
| 6739 | break; |
| 6740 | |
| 6741 | case BFD_RELOC_AARCH64_CALL26: |
| 6742 | case BFD_RELOC_AARCH64_JUMP26: |
| 6743 | if (fixP->fx_done || !seg->use_rela_p) |
| 6744 | { |
| 6745 | if (value & 3) |
| 6746 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6747 | _("branch target not word aligned")); |
| 6748 | if (signed_overflow (value, 28)) |
| 6749 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6750 | _("branch out of range")); |
| 6751 | insn = get_aarch64_insn (buf); |
| 6752 | insn |= encode_branch_ofs_26 (value >> 2); |
| 6753 | put_aarch64_insn (buf, insn); |
| 6754 | } |
| 6755 | break; |
| 6756 | |
| 6757 | case BFD_RELOC_AARCH64_MOVW_G0: |
| 6758 | case BFD_RELOC_AARCH64_MOVW_G0_NC: |
| 6759 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
| 6760 | scale = 0; |
| 6761 | goto movw_common; |
| 6762 | case BFD_RELOC_AARCH64_MOVW_G1: |
| 6763 | case BFD_RELOC_AARCH64_MOVW_G1_NC: |
| 6764 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
| 6765 | scale = 16; |
| 6766 | goto movw_common; |
| 6767 | case BFD_RELOC_AARCH64_MOVW_G2: |
| 6768 | case BFD_RELOC_AARCH64_MOVW_G2_NC: |
| 6769 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
| 6770 | scale = 32; |
| 6771 | goto movw_common; |
| 6772 | case BFD_RELOC_AARCH64_MOVW_G3: |
| 6773 | scale = 48; |
| 6774 | movw_common: |
| 6775 | if (fixP->fx_done || !seg->use_rela_p) |
| 6776 | { |
| 6777 | insn = get_aarch64_insn (buf); |
| 6778 | |
| 6779 | if (!fixP->fx_done) |
| 6780 | { |
| 6781 | /* REL signed addend must fit in 16 bits */ |
| 6782 | if (signed_overflow (value, 16)) |
| 6783 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6784 | _("offset out of range")); |
| 6785 | } |
| 6786 | else |
| 6787 | { |
| 6788 | /* Check for overflow and scale. */ |
| 6789 | switch (fixP->fx_r_type) |
| 6790 | { |
| 6791 | case BFD_RELOC_AARCH64_MOVW_G0: |
| 6792 | case BFD_RELOC_AARCH64_MOVW_G1: |
| 6793 | case BFD_RELOC_AARCH64_MOVW_G2: |
| 6794 | case BFD_RELOC_AARCH64_MOVW_G3: |
| 6795 | if (unsigned_overflow (value, scale + 16)) |
| 6796 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6797 | _("unsigned value out of range")); |
| 6798 | break; |
| 6799 | case BFD_RELOC_AARCH64_MOVW_G0_S: |
| 6800 | case BFD_RELOC_AARCH64_MOVW_G1_S: |
| 6801 | case BFD_RELOC_AARCH64_MOVW_G2_S: |
| 6802 | /* NOTE: We can only come here with movz or movn. */ |
| 6803 | if (signed_overflow (value, scale + 16)) |
| 6804 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6805 | _("signed value out of range")); |
| 6806 | if (value < 0) |
| 6807 | { |
| 6808 | /* Force use of MOVN. */ |
| 6809 | value = ~value; |
| 6810 | insn = reencode_movzn_to_movn (insn); |
| 6811 | } |
| 6812 | else |
| 6813 | { |
| 6814 | /* Force use of MOVZ. */ |
| 6815 | insn = reencode_movzn_to_movz (insn); |
| 6816 | } |
| 6817 | break; |
| 6818 | default: |
| 6819 | /* Unchecked relocations. */ |
| 6820 | break; |
| 6821 | } |
| 6822 | value >>= scale; |
| 6823 | } |
| 6824 | |
| 6825 | /* Insert value into MOVN/MOVZ/MOVK instruction. */ |
| 6826 | insn |= encode_movw_imm (value & 0xffff); |
| 6827 | |
| 6828 | put_aarch64_insn (buf, insn); |
| 6829 | } |
| 6830 | break; |
| 6831 | |
| 6832 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC: |
| 6833 | fixP->fx_r_type = (ilp32_p |
| 6834 | ? BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC |
| 6835 | : BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC); |
| 6836 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
| 6837 | /* Should always be exported to object file, see |
| 6838 | aarch64_force_relocation(). */ |
| 6839 | gas_assert (!fixP->fx_done); |
| 6840 | gas_assert (seg->use_rela_p); |
| 6841 | break; |
| 6842 | |
| 6843 | case BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC: |
| 6844 | fixP->fx_r_type = (ilp32_p |
| 6845 | ? BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC |
| 6846 | : BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC); |
| 6847 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
| 6848 | /* Should always be exported to object file, see |
| 6849 | aarch64_force_relocation(). */ |
| 6850 | gas_assert (!fixP->fx_done); |
| 6851 | gas_assert (seg->use_rela_p); |
| 6852 | break; |
| 6853 | |
| 6854 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC: |
| 6855 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
| 6856 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
| 6857 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
| 6858 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
| 6859 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
| 6860 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
| 6861 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
| 6862 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
| 6863 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
| 6864 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
| 6865 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
| 6866 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
| 6867 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
| 6868 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
| 6869 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
| 6870 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
| 6871 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
| 6872 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
| 6873 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
| 6874 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: |
| 6875 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: |
| 6876 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: |
| 6877 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: |
| 6878 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
| 6879 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: |
| 6880 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: |
| 6881 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
| 6882 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: |
| 6883 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
| 6884 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: |
| 6885 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
| 6886 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
| 6887 | /* Should always be exported to object file, see |
| 6888 | aarch64_force_relocation(). */ |
| 6889 | gas_assert (!fixP->fx_done); |
| 6890 | gas_assert (seg->use_rela_p); |
| 6891 | break; |
| 6892 | |
| 6893 | case BFD_RELOC_AARCH64_LD_GOT_LO12_NC: |
| 6894 | /* Should always be exported to object file, see |
| 6895 | aarch64_force_relocation(). */ |
| 6896 | fixP->fx_r_type = (ilp32_p |
| 6897 | ? BFD_RELOC_AARCH64_LD32_GOT_LO12_NC |
| 6898 | : BFD_RELOC_AARCH64_LD64_GOT_LO12_NC); |
| 6899 | gas_assert (!fixP->fx_done); |
| 6900 | gas_assert (seg->use_rela_p); |
| 6901 | break; |
| 6902 | |
| 6903 | case BFD_RELOC_AARCH64_ADD_LO12: |
| 6904 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
| 6905 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
| 6906 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
| 6907 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
| 6908 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
| 6909 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
| 6910 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
| 6911 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
| 6912 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
| 6913 | case BFD_RELOC_AARCH64_LDST128_LO12: |
| 6914 | case BFD_RELOC_AARCH64_LDST16_LO12: |
| 6915 | case BFD_RELOC_AARCH64_LDST32_LO12: |
| 6916 | case BFD_RELOC_AARCH64_LDST64_LO12: |
| 6917 | case BFD_RELOC_AARCH64_LDST8_LO12: |
| 6918 | /* Should always be exported to object file, see |
| 6919 | aarch64_force_relocation(). */ |
| 6920 | gas_assert (!fixP->fx_done); |
| 6921 | gas_assert (seg->use_rela_p); |
| 6922 | break; |
| 6923 | |
| 6924 | case BFD_RELOC_AARCH64_TLSDESC_ADD: |
| 6925 | case BFD_RELOC_AARCH64_TLSDESC_CALL: |
| 6926 | case BFD_RELOC_AARCH64_TLSDESC_LDR: |
| 6927 | break; |
| 6928 | |
| 6929 | case BFD_RELOC_UNUSED: |
| 6930 | /* An error will already have been reported. */ |
| 6931 | break; |
| 6932 | |
| 6933 | default: |
| 6934 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 6935 | _("unexpected %s fixup"), |
| 6936 | bfd_get_reloc_code_name (fixP->fx_r_type)); |
| 6937 | break; |
| 6938 | } |
| 6939 | |
| 6940 | apply_fix_return: |
| 6941 | /* Free the allocated the struct aarch64_inst. |
| 6942 | N.B. currently there are very limited number of fix-up types actually use |
| 6943 | this field, so the impact on the performance should be minimal . */ |
| 6944 | if (fixP->tc_fix_data.inst != NULL) |
| 6945 | free (fixP->tc_fix_data.inst); |
| 6946 | |
| 6947 | return; |
| 6948 | } |
| 6949 | |
| 6950 | /* Translate internal representation of relocation info to BFD target |
| 6951 | format. */ |
| 6952 | |
| 6953 | arelent * |
| 6954 | tc_gen_reloc (asection * section, fixS * fixp) |
| 6955 | { |
| 6956 | arelent *reloc; |
| 6957 | bfd_reloc_code_real_type code; |
| 6958 | |
| 6959 | reloc = xmalloc (sizeof (arelent)); |
| 6960 | |
| 6961 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
| 6962 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
| 6963 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
| 6964 | |
| 6965 | if (fixp->fx_pcrel) |
| 6966 | { |
| 6967 | if (section->use_rela_p) |
| 6968 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); |
| 6969 | else |
| 6970 | fixp->fx_offset = reloc->address; |
| 6971 | } |
| 6972 | reloc->addend = fixp->fx_offset; |
| 6973 | |
| 6974 | code = fixp->fx_r_type; |
| 6975 | switch (code) |
| 6976 | { |
| 6977 | case BFD_RELOC_16: |
| 6978 | if (fixp->fx_pcrel) |
| 6979 | code = BFD_RELOC_16_PCREL; |
| 6980 | break; |
| 6981 | |
| 6982 | case BFD_RELOC_32: |
| 6983 | if (fixp->fx_pcrel) |
| 6984 | code = BFD_RELOC_32_PCREL; |
| 6985 | break; |
| 6986 | |
| 6987 | case BFD_RELOC_64: |
| 6988 | if (fixp->fx_pcrel) |
| 6989 | code = BFD_RELOC_64_PCREL; |
| 6990 | break; |
| 6991 | |
| 6992 | default: |
| 6993 | break; |
| 6994 | } |
| 6995 | |
| 6996 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
| 6997 | if (reloc->howto == NULL) |
| 6998 | { |
| 6999 | as_bad_where (fixp->fx_file, fixp->fx_line, |
| 7000 | _ |
| 7001 | ("cannot represent %s relocation in this object file format"), |
| 7002 | bfd_get_reloc_code_name (code)); |
| 7003 | return NULL; |
| 7004 | } |
| 7005 | |
| 7006 | return reloc; |
| 7007 | } |
| 7008 | |
| 7009 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
| 7010 | |
| 7011 | void |
| 7012 | cons_fix_new_aarch64 (fragS * frag, int where, int size, expressionS * exp) |
| 7013 | { |
| 7014 | bfd_reloc_code_real_type type; |
| 7015 | int pcrel = 0; |
| 7016 | |
| 7017 | /* Pick a reloc. |
| 7018 | FIXME: @@ Should look at CPU word size. */ |
| 7019 | switch (size) |
| 7020 | { |
| 7021 | case 1: |
| 7022 | type = BFD_RELOC_8; |
| 7023 | break; |
| 7024 | case 2: |
| 7025 | type = BFD_RELOC_16; |
| 7026 | break; |
| 7027 | case 4: |
| 7028 | type = BFD_RELOC_32; |
| 7029 | break; |
| 7030 | case 8: |
| 7031 | type = BFD_RELOC_64; |
| 7032 | break; |
| 7033 | default: |
| 7034 | as_bad (_("cannot do %u-byte relocation"), size); |
| 7035 | type = BFD_RELOC_UNUSED; |
| 7036 | break; |
| 7037 | } |
| 7038 | |
| 7039 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
| 7040 | } |
| 7041 | |
| 7042 | int |
| 7043 | aarch64_force_relocation (struct fix *fixp) |
| 7044 | { |
| 7045 | switch (fixp->fx_r_type) |
| 7046 | { |
| 7047 | case BFD_RELOC_AARCH64_GAS_INTERNAL_FIXUP: |
| 7048 | /* Perform these "immediate" internal relocations |
| 7049 | even if the symbol is extern or weak. */ |
| 7050 | return 0; |
| 7051 | |
| 7052 | case BFD_RELOC_AARCH64_LD_GOT_LO12_NC: |
| 7053 | case BFD_RELOC_AARCH64_TLSDESC_LD_LO12_NC: |
| 7054 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_LO12_NC: |
| 7055 | /* Pseudo relocs that need to be fixed up according to |
| 7056 | ilp32_p. */ |
| 7057 | return 0; |
| 7058 | |
| 7059 | case BFD_RELOC_AARCH64_ADD_LO12: |
| 7060 | case BFD_RELOC_AARCH64_ADR_GOT_PAGE: |
| 7061 | case BFD_RELOC_AARCH64_ADR_HI21_NC_PCREL: |
| 7062 | case BFD_RELOC_AARCH64_ADR_HI21_PCREL: |
| 7063 | case BFD_RELOC_AARCH64_GOT_LD_PREL19: |
| 7064 | case BFD_RELOC_AARCH64_LD32_GOT_LO12_NC: |
| 7065 | case BFD_RELOC_AARCH64_LD32_GOTPAGE_LO14: |
| 7066 | case BFD_RELOC_AARCH64_LD64_GOTOFF_LO15: |
| 7067 | case BFD_RELOC_AARCH64_LD64_GOTPAGE_LO15: |
| 7068 | case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC: |
| 7069 | case BFD_RELOC_AARCH64_LDST128_LO12: |
| 7070 | case BFD_RELOC_AARCH64_LDST16_LO12: |
| 7071 | case BFD_RELOC_AARCH64_LDST32_LO12: |
| 7072 | case BFD_RELOC_AARCH64_LDST64_LO12: |
| 7073 | case BFD_RELOC_AARCH64_LDST8_LO12: |
| 7074 | case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC: |
| 7075 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: |
| 7076 | case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: |
| 7077 | case BFD_RELOC_AARCH64_TLSDESC_LD32_LO12_NC: |
| 7078 | case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC: |
| 7079 | case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: |
| 7080 | case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: |
| 7081 | case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: |
| 7082 | case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: |
| 7083 | case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: |
| 7084 | case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC: |
| 7085 | case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: |
| 7086 | case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: |
| 7087 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_HI12: |
| 7088 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12: |
| 7089 | case BFD_RELOC_AARCH64_TLSLD_ADD_DTPREL_LO12_NC: |
| 7090 | case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: |
| 7091 | case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: |
| 7092 | case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: |
| 7093 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0: |
| 7094 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G0_NC: |
| 7095 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1: |
| 7096 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G1_NC: |
| 7097 | case BFD_RELOC_AARCH64_TLSLD_MOVW_DTPREL_G2: |
| 7098 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12: |
| 7099 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12: |
| 7100 | case BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_LO12_NC: |
| 7101 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0: |
| 7102 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC: |
| 7103 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1: |
| 7104 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC: |
| 7105 | case BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2: |
| 7106 | /* Always leave these relocations for the linker. */ |
| 7107 | return 1; |
| 7108 | |
| 7109 | default: |
| 7110 | break; |
| 7111 | } |
| 7112 | |
| 7113 | return generic_force_reloc (fixp); |
| 7114 | } |
| 7115 | |
| 7116 | #ifdef OBJ_ELF |
| 7117 | |
| 7118 | const char * |
| 7119 | elf64_aarch64_target_format (void) |
| 7120 | { |
| 7121 | if (target_big_endian) |
| 7122 | return ilp32_p ? "elf32-bigaarch64" : "elf64-bigaarch64"; |
| 7123 | else |
| 7124 | return ilp32_p ? "elf32-littleaarch64" : "elf64-littleaarch64"; |
| 7125 | } |
| 7126 | |
| 7127 | void |
| 7128 | aarch64elf_frob_symbol (symbolS * symp, int *puntp) |
| 7129 | { |
| 7130 | elf_frob_symbol (symp, puntp); |
| 7131 | } |
| 7132 | #endif |
| 7133 | |
| 7134 | /* MD interface: Finalization. */ |
| 7135 | |
| 7136 | /* A good place to do this, although this was probably not intended |
| 7137 | for this kind of use. We need to dump the literal pool before |
| 7138 | references are made to a null symbol pointer. */ |
| 7139 | |
| 7140 | void |
| 7141 | aarch64_cleanup (void) |
| 7142 | { |
| 7143 | literal_pool *pool; |
| 7144 | |
| 7145 | for (pool = list_of_pools; pool; pool = pool->next) |
| 7146 | { |
| 7147 | /* Put it at the end of the relevant section. */ |
| 7148 | subseg_set (pool->section, pool->sub_section); |
| 7149 | s_ltorg (0); |
| 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | #ifdef OBJ_ELF |
| 7154 | /* Remove any excess mapping symbols generated for alignment frags in |
| 7155 | SEC. We may have created a mapping symbol before a zero byte |
| 7156 | alignment; remove it if there's a mapping symbol after the |
| 7157 | alignment. */ |
| 7158 | static void |
| 7159 | check_mapping_symbols (bfd * abfd ATTRIBUTE_UNUSED, asection * sec, |
| 7160 | void *dummy ATTRIBUTE_UNUSED) |
| 7161 | { |
| 7162 | segment_info_type *seginfo = seg_info (sec); |
| 7163 | fragS *fragp; |
| 7164 | |
| 7165 | if (seginfo == NULL || seginfo->frchainP == NULL) |
| 7166 | return; |
| 7167 | |
| 7168 | for (fragp = seginfo->frchainP->frch_root; |
| 7169 | fragp != NULL; fragp = fragp->fr_next) |
| 7170 | { |
| 7171 | symbolS *sym = fragp->tc_frag_data.last_map; |
| 7172 | fragS *next = fragp->fr_next; |
| 7173 | |
| 7174 | /* Variable-sized frags have been converted to fixed size by |
| 7175 | this point. But if this was variable-sized to start with, |
| 7176 | there will be a fixed-size frag after it. So don't handle |
| 7177 | next == NULL. */ |
| 7178 | if (sym == NULL || next == NULL) |
| 7179 | continue; |
| 7180 | |
| 7181 | if (S_GET_VALUE (sym) < next->fr_address) |
| 7182 | /* Not at the end of this frag. */ |
| 7183 | continue; |
| 7184 | know (S_GET_VALUE (sym) == next->fr_address); |
| 7185 | |
| 7186 | do |
| 7187 | { |
| 7188 | if (next->tc_frag_data.first_map != NULL) |
| 7189 | { |
| 7190 | /* Next frag starts with a mapping symbol. Discard this |
| 7191 | one. */ |
| 7192 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); |
| 7193 | break; |
| 7194 | } |
| 7195 | |
| 7196 | if (next->fr_next == NULL) |
| 7197 | { |
| 7198 | /* This mapping symbol is at the end of the section. Discard |
| 7199 | it. */ |
| 7200 | know (next->fr_fix == 0 && next->fr_var == 0); |
| 7201 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); |
| 7202 | break; |
| 7203 | } |
| 7204 | |
| 7205 | /* As long as we have empty frags without any mapping symbols, |
| 7206 | keep looking. */ |
| 7207 | /* If the next frag is non-empty and does not start with a |
| 7208 | mapping symbol, then this mapping symbol is required. */ |
| 7209 | if (next->fr_address != next->fr_next->fr_address) |
| 7210 | break; |
| 7211 | |
| 7212 | next = next->fr_next; |
| 7213 | } |
| 7214 | while (next != NULL); |
| 7215 | } |
| 7216 | } |
| 7217 | #endif |
| 7218 | |
| 7219 | /* Adjust the symbol table. */ |
| 7220 | |
| 7221 | void |
| 7222 | aarch64_adjust_symtab (void) |
| 7223 | { |
| 7224 | #ifdef OBJ_ELF |
| 7225 | /* Remove any overlapping mapping symbols generated by alignment frags. */ |
| 7226 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); |
| 7227 | /* Now do generic ELF adjustments. */ |
| 7228 | elf_adjust_symtab (); |
| 7229 | #endif |
| 7230 | } |
| 7231 | |
| 7232 | static void |
| 7233 | checked_hash_insert (struct hash_control *table, const char *key, void *value) |
| 7234 | { |
| 7235 | const char *hash_err; |
| 7236 | |
| 7237 | hash_err = hash_insert (table, key, value); |
| 7238 | if (hash_err) |
| 7239 | printf ("Internal Error: Can't hash %s\n", key); |
| 7240 | } |
| 7241 | |
| 7242 | static void |
| 7243 | fill_instruction_hash_table (void) |
| 7244 | { |
| 7245 | aarch64_opcode *opcode = aarch64_opcode_table; |
| 7246 | |
| 7247 | while (opcode->name != NULL) |
| 7248 | { |
| 7249 | templates *templ, *new_templ; |
| 7250 | templ = hash_find (aarch64_ops_hsh, opcode->name); |
| 7251 | |
| 7252 | new_templ = (templates *) xmalloc (sizeof (templates)); |
| 7253 | new_templ->opcode = opcode; |
| 7254 | new_templ->next = NULL; |
| 7255 | |
| 7256 | if (!templ) |
| 7257 | checked_hash_insert (aarch64_ops_hsh, opcode->name, (void *) new_templ); |
| 7258 | else |
| 7259 | { |
| 7260 | new_templ->next = templ->next; |
| 7261 | templ->next = new_templ; |
| 7262 | } |
| 7263 | ++opcode; |
| 7264 | } |
| 7265 | } |
| 7266 | |
| 7267 | static inline void |
| 7268 | convert_to_upper (char *dst, const char *src, size_t num) |
| 7269 | { |
| 7270 | unsigned int i; |
| 7271 | for (i = 0; i < num && *src != '\0'; ++i, ++dst, ++src) |
| 7272 | *dst = TOUPPER (*src); |
| 7273 | *dst = '\0'; |
| 7274 | } |
| 7275 | |
| 7276 | /* Assume STR point to a lower-case string, allocate, convert and return |
| 7277 | the corresponding upper-case string. */ |
| 7278 | static inline const char* |
| 7279 | get_upper_str (const char *str) |
| 7280 | { |
| 7281 | char *ret; |
| 7282 | size_t len = strlen (str); |
| 7283 | if ((ret = xmalloc (len + 1)) == NULL) |
| 7284 | abort (); |
| 7285 | convert_to_upper (ret, str, len); |
| 7286 | return ret; |
| 7287 | } |
| 7288 | |
| 7289 | /* MD interface: Initialization. */ |
| 7290 | |
| 7291 | void |
| 7292 | md_begin (void) |
| 7293 | { |
| 7294 | unsigned mach; |
| 7295 | unsigned int i; |
| 7296 | |
| 7297 | if ((aarch64_ops_hsh = hash_new ()) == NULL |
| 7298 | || (aarch64_cond_hsh = hash_new ()) == NULL |
| 7299 | || (aarch64_shift_hsh = hash_new ()) == NULL |
| 7300 | || (aarch64_sys_regs_hsh = hash_new ()) == NULL |
| 7301 | || (aarch64_pstatefield_hsh = hash_new ()) == NULL |
| 7302 | || (aarch64_sys_regs_ic_hsh = hash_new ()) == NULL |
| 7303 | || (aarch64_sys_regs_dc_hsh = hash_new ()) == NULL |
| 7304 | || (aarch64_sys_regs_at_hsh = hash_new ()) == NULL |
| 7305 | || (aarch64_sys_regs_tlbi_hsh = hash_new ()) == NULL |
| 7306 | || (aarch64_reg_hsh = hash_new ()) == NULL |
| 7307 | || (aarch64_barrier_opt_hsh = hash_new ()) == NULL |
| 7308 | || (aarch64_nzcv_hsh = hash_new ()) == NULL |
| 7309 | || (aarch64_pldop_hsh = hash_new ()) == NULL) |
| 7310 | as_fatal (_("virtual memory exhausted")); |
| 7311 | |
| 7312 | fill_instruction_hash_table (); |
| 7313 | |
| 7314 | for (i = 0; aarch64_sys_regs[i].name != NULL; ++i) |
| 7315 | checked_hash_insert (aarch64_sys_regs_hsh, aarch64_sys_regs[i].name, |
| 7316 | (void *) (aarch64_sys_regs + i)); |
| 7317 | |
| 7318 | for (i = 0; aarch64_pstatefields[i].name != NULL; ++i) |
| 7319 | checked_hash_insert (aarch64_pstatefield_hsh, |
| 7320 | aarch64_pstatefields[i].name, |
| 7321 | (void *) (aarch64_pstatefields + i)); |
| 7322 | |
| 7323 | for (i = 0; aarch64_sys_regs_ic[i].template != NULL; i++) |
| 7324 | checked_hash_insert (aarch64_sys_regs_ic_hsh, |
| 7325 | aarch64_sys_regs_ic[i].template, |
| 7326 | (void *) (aarch64_sys_regs_ic + i)); |
| 7327 | |
| 7328 | for (i = 0; aarch64_sys_regs_dc[i].template != NULL; i++) |
| 7329 | checked_hash_insert (aarch64_sys_regs_dc_hsh, |
| 7330 | aarch64_sys_regs_dc[i].template, |
| 7331 | (void *) (aarch64_sys_regs_dc + i)); |
| 7332 | |
| 7333 | for (i = 0; aarch64_sys_regs_at[i].template != NULL; i++) |
| 7334 | checked_hash_insert (aarch64_sys_regs_at_hsh, |
| 7335 | aarch64_sys_regs_at[i].template, |
| 7336 | (void *) (aarch64_sys_regs_at + i)); |
| 7337 | |
| 7338 | for (i = 0; aarch64_sys_regs_tlbi[i].template != NULL; i++) |
| 7339 | checked_hash_insert (aarch64_sys_regs_tlbi_hsh, |
| 7340 | aarch64_sys_regs_tlbi[i].template, |
| 7341 | (void *) (aarch64_sys_regs_tlbi + i)); |
| 7342 | |
| 7343 | for (i = 0; i < ARRAY_SIZE (reg_names); i++) |
| 7344 | checked_hash_insert (aarch64_reg_hsh, reg_names[i].name, |
| 7345 | (void *) (reg_names + i)); |
| 7346 | |
| 7347 | for (i = 0; i < ARRAY_SIZE (nzcv_names); i++) |
| 7348 | checked_hash_insert (aarch64_nzcv_hsh, nzcv_names[i].template, |
| 7349 | (void *) (nzcv_names + i)); |
| 7350 | |
| 7351 | for (i = 0; aarch64_operand_modifiers[i].name != NULL; i++) |
| 7352 | { |
| 7353 | const char *name = aarch64_operand_modifiers[i].name; |
| 7354 | checked_hash_insert (aarch64_shift_hsh, name, |
| 7355 | (void *) (aarch64_operand_modifiers + i)); |
| 7356 | /* Also hash the name in the upper case. */ |
| 7357 | checked_hash_insert (aarch64_shift_hsh, get_upper_str (name), |
| 7358 | (void *) (aarch64_operand_modifiers + i)); |
| 7359 | } |
| 7360 | |
| 7361 | for (i = 0; i < ARRAY_SIZE (aarch64_conds); i++) |
| 7362 | { |
| 7363 | unsigned int j; |
| 7364 | /* A condition code may have alias(es), e.g. "cc", "lo" and "ul" are |
| 7365 | the same condition code. */ |
| 7366 | for (j = 0; j < ARRAY_SIZE (aarch64_conds[i].names); ++j) |
| 7367 | { |
| 7368 | const char *name = aarch64_conds[i].names[j]; |
| 7369 | if (name == NULL) |
| 7370 | break; |
| 7371 | checked_hash_insert (aarch64_cond_hsh, name, |
| 7372 | (void *) (aarch64_conds + i)); |
| 7373 | /* Also hash the name in the upper case. */ |
| 7374 | checked_hash_insert (aarch64_cond_hsh, get_upper_str (name), |
| 7375 | (void *) (aarch64_conds + i)); |
| 7376 | } |
| 7377 | } |
| 7378 | |
| 7379 | for (i = 0; i < ARRAY_SIZE (aarch64_barrier_options); i++) |
| 7380 | { |
| 7381 | const char *name = aarch64_barrier_options[i].name; |
| 7382 | /* Skip xx00 - the unallocated values of option. */ |
| 7383 | if ((i & 0x3) == 0) |
| 7384 | continue; |
| 7385 | checked_hash_insert (aarch64_barrier_opt_hsh, name, |
| 7386 | (void *) (aarch64_barrier_options + i)); |
| 7387 | /* Also hash the name in the upper case. */ |
| 7388 | checked_hash_insert (aarch64_barrier_opt_hsh, get_upper_str (name), |
| 7389 | (void *) (aarch64_barrier_options + i)); |
| 7390 | } |
| 7391 | |
| 7392 | for (i = 0; i < ARRAY_SIZE (aarch64_prfops); i++) |
| 7393 | { |
| 7394 | const char* name = aarch64_prfops[i].name; |
| 7395 | /* Skip the unallocated hint encodings. */ |
| 7396 | if (name == NULL) |
| 7397 | continue; |
| 7398 | checked_hash_insert (aarch64_pldop_hsh, name, |
| 7399 | (void *) (aarch64_prfops + i)); |
| 7400 | /* Also hash the name in the upper case. */ |
| 7401 | checked_hash_insert (aarch64_pldop_hsh, get_upper_str (name), |
| 7402 | (void *) (aarch64_prfops + i)); |
| 7403 | } |
| 7404 | |
| 7405 | /* Set the cpu variant based on the command-line options. */ |
| 7406 | if (!mcpu_cpu_opt) |
| 7407 | mcpu_cpu_opt = march_cpu_opt; |
| 7408 | |
| 7409 | if (!mcpu_cpu_opt) |
| 7410 | mcpu_cpu_opt = &cpu_default; |
| 7411 | |
| 7412 | cpu_variant = *mcpu_cpu_opt; |
| 7413 | |
| 7414 | /* Record the CPU type. */ |
| 7415 | mach = ilp32_p ? bfd_mach_aarch64_ilp32 : bfd_mach_aarch64; |
| 7416 | |
| 7417 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); |
| 7418 | } |
| 7419 | |
| 7420 | /* Command line processing. */ |
| 7421 | |
| 7422 | const char *md_shortopts = "m:"; |
| 7423 | |
| 7424 | #ifdef AARCH64_BI_ENDIAN |
| 7425 | #define OPTION_EB (OPTION_MD_BASE + 0) |
| 7426 | #define OPTION_EL (OPTION_MD_BASE + 1) |
| 7427 | #else |
| 7428 | #if TARGET_BYTES_BIG_ENDIAN |
| 7429 | #define OPTION_EB (OPTION_MD_BASE + 0) |
| 7430 | #else |
| 7431 | #define OPTION_EL (OPTION_MD_BASE + 1) |
| 7432 | #endif |
| 7433 | #endif |
| 7434 | |
| 7435 | struct option md_longopts[] = { |
| 7436 | #ifdef OPTION_EB |
| 7437 | {"EB", no_argument, NULL, OPTION_EB}, |
| 7438 | #endif |
| 7439 | #ifdef OPTION_EL |
| 7440 | {"EL", no_argument, NULL, OPTION_EL}, |
| 7441 | #endif |
| 7442 | {NULL, no_argument, NULL, 0} |
| 7443 | }; |
| 7444 | |
| 7445 | size_t md_longopts_size = sizeof (md_longopts); |
| 7446 | |
| 7447 | struct aarch64_option_table |
| 7448 | { |
| 7449 | char *option; /* Option name to match. */ |
| 7450 | char *help; /* Help information. */ |
| 7451 | int *var; /* Variable to change. */ |
| 7452 | int value; /* What to change it to. */ |
| 7453 | char *deprecated; /* If non-null, print this message. */ |
| 7454 | }; |
| 7455 | |
| 7456 | static struct aarch64_option_table aarch64_opts[] = { |
| 7457 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, |
| 7458 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, |
| 7459 | NULL}, |
| 7460 | #ifdef DEBUG_AARCH64 |
| 7461 | {"mdebug-dump", N_("temporary switch for dumping"), &debug_dump, 1, NULL}, |
| 7462 | #endif /* DEBUG_AARCH64 */ |
| 7463 | {"mverbose-error", N_("output verbose error messages"), &verbose_error_p, 1, |
| 7464 | NULL}, |
| 7465 | {"mno-verbose-error", N_("do not output verbose error messages"), |
| 7466 | &verbose_error_p, 0, NULL}, |
| 7467 | {NULL, NULL, NULL, 0, NULL} |
| 7468 | }; |
| 7469 | |
| 7470 | struct aarch64_cpu_option_table |
| 7471 | { |
| 7472 | char *name; |
| 7473 | const aarch64_feature_set value; |
| 7474 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
| 7475 | case. */ |
| 7476 | const char *canonical_name; |
| 7477 | }; |
| 7478 | |
| 7479 | /* This list should, at a minimum, contain all the cpu names |
| 7480 | recognized by GCC. */ |
| 7481 | static const struct aarch64_cpu_option_table aarch64_cpus[] = { |
| 7482 | {"all", AARCH64_ANY, NULL}, |
| 7483 | {"cortex-a53", AARCH64_FEATURE (AARCH64_ARCH_V8, |
| 7484 | AARCH64_FEATURE_CRC), "Cortex-A53"}, |
| 7485 | {"cortex-a57", AARCH64_FEATURE (AARCH64_ARCH_V8, |
| 7486 | AARCH64_FEATURE_CRC), "Cortex-A57"}, |
| 7487 | {"cortex-a72", AARCH64_FEATURE (AARCH64_ARCH_V8, |
| 7488 | AARCH64_FEATURE_CRC), "Cortex-A72"}, |
| 7489 | {"exynos-m1", AARCH64_FEATURE (AARCH64_ARCH_V8, |
| 7490 | AARCH64_FEATURE_CRC | AARCH64_FEATURE_CRYPTO), |
| 7491 | "Samsung Exynos M1"}, |
| 7492 | {"thunderx", AARCH64_FEATURE (AARCH64_ARCH_V8, |
| 7493 | AARCH64_FEATURE_CRC | AARCH64_FEATURE_CRYPTO), |
| 7494 | "Cavium ThunderX"}, |
| 7495 | /* The 'xgene-1' name is an older name for 'xgene1', which was used |
| 7496 | in earlier releases and is superseded by 'xgene1' in all |
| 7497 | tools. */ |
| 7498 | {"xgene-1", AARCH64_ARCH_V8, "APM X-Gene 1"}, |
| 7499 | {"xgene1", AARCH64_ARCH_V8, "APM X-Gene 1"}, |
| 7500 | {"xgene2", AARCH64_FEATURE (AARCH64_ARCH_V8, |
| 7501 | AARCH64_FEATURE_CRC), "APM X-Gene 2"}, |
| 7502 | {"generic", AARCH64_ARCH_V8, NULL}, |
| 7503 | |
| 7504 | {NULL, AARCH64_ARCH_NONE, NULL} |
| 7505 | }; |
| 7506 | |
| 7507 | struct aarch64_arch_option_table |
| 7508 | { |
| 7509 | char *name; |
| 7510 | const aarch64_feature_set value; |
| 7511 | }; |
| 7512 | |
| 7513 | /* This list should, at a minimum, contain all the architecture names |
| 7514 | recognized by GCC. */ |
| 7515 | static const struct aarch64_arch_option_table aarch64_archs[] = { |
| 7516 | {"all", AARCH64_ANY}, |
| 7517 | {"armv8-a", AARCH64_ARCH_V8}, |
| 7518 | {"armv8.1-a", AARCH64_ARCH_V8_1}, |
| 7519 | {NULL, AARCH64_ARCH_NONE} |
| 7520 | }; |
| 7521 | |
| 7522 | /* ISA extensions. */ |
| 7523 | struct aarch64_option_cpu_value_table |
| 7524 | { |
| 7525 | char *name; |
| 7526 | const aarch64_feature_set value; |
| 7527 | }; |
| 7528 | |
| 7529 | static const struct aarch64_option_cpu_value_table aarch64_features[] = { |
| 7530 | {"crc", AARCH64_FEATURE (AARCH64_FEATURE_CRC, 0)}, |
| 7531 | {"crypto", AARCH64_FEATURE (AARCH64_FEATURE_CRYPTO, 0)}, |
| 7532 | {"fp", AARCH64_FEATURE (AARCH64_FEATURE_FP, 0)}, |
| 7533 | {"lse", AARCH64_FEATURE (AARCH64_FEATURE_LSE, 0)}, |
| 7534 | {"simd", AARCH64_FEATURE (AARCH64_FEATURE_SIMD, 0)}, |
| 7535 | {"pan", AARCH64_FEATURE (AARCH64_FEATURE_PAN, 0)}, |
| 7536 | {"lor", AARCH64_FEATURE (AARCH64_FEATURE_LOR, 0)}, |
| 7537 | {"rdma", AARCH64_FEATURE (AARCH64_FEATURE_SIMD |
| 7538 | | AARCH64_FEATURE_RDMA, 0)}, |
| 7539 | {NULL, AARCH64_ARCH_NONE} |
| 7540 | }; |
| 7541 | |
| 7542 | struct aarch64_long_option_table |
| 7543 | { |
| 7544 | char *option; /* Substring to match. */ |
| 7545 | char *help; /* Help information. */ |
| 7546 | int (*func) (char *subopt); /* Function to decode sub-option. */ |
| 7547 | char *deprecated; /* If non-null, print this message. */ |
| 7548 | }; |
| 7549 | |
| 7550 | static int |
| 7551 | aarch64_parse_features (char *str, const aarch64_feature_set **opt_p, |
| 7552 | bfd_boolean ext_only) |
| 7553 | { |
| 7554 | /* We insist on extensions being added before being removed. We achieve |
| 7555 | this by using the ADDING_VALUE variable to indicate whether we are |
| 7556 | adding an extension (1) or removing it (0) and only allowing it to |
| 7557 | change in the order -1 -> 1 -> 0. */ |
| 7558 | int adding_value = -1; |
| 7559 | aarch64_feature_set *ext_set = xmalloc (sizeof (aarch64_feature_set)); |
| 7560 | |
| 7561 | /* Copy the feature set, so that we can modify it. */ |
| 7562 | *ext_set = **opt_p; |
| 7563 | *opt_p = ext_set; |
| 7564 | |
| 7565 | while (str != NULL && *str != 0) |
| 7566 | { |
| 7567 | const struct aarch64_option_cpu_value_table *opt; |
| 7568 | char *ext = NULL; |
| 7569 | int optlen; |
| 7570 | |
| 7571 | if (!ext_only) |
| 7572 | { |
| 7573 | if (*str != '+') |
| 7574 | { |
| 7575 | as_bad (_("invalid architectural extension")); |
| 7576 | return 0; |
| 7577 | } |
| 7578 | |
| 7579 | ext = strchr (++str, '+'); |
| 7580 | } |
| 7581 | |
| 7582 | if (ext != NULL) |
| 7583 | optlen = ext - str; |
| 7584 | else |
| 7585 | optlen = strlen (str); |
| 7586 | |
| 7587 | if (optlen >= 2 && strncmp (str, "no", 2) == 0) |
| 7588 | { |
| 7589 | if (adding_value != 0) |
| 7590 | adding_value = 0; |
| 7591 | optlen -= 2; |
| 7592 | str += 2; |
| 7593 | } |
| 7594 | else if (optlen > 0) |
| 7595 | { |
| 7596 | if (adding_value == -1) |
| 7597 | adding_value = 1; |
| 7598 | else if (adding_value != 1) |
| 7599 | { |
| 7600 | as_bad (_("must specify extensions to add before specifying " |
| 7601 | "those to remove")); |
| 7602 | return FALSE; |
| 7603 | } |
| 7604 | } |
| 7605 | |
| 7606 | if (optlen == 0) |
| 7607 | { |
| 7608 | as_bad (_("missing architectural extension")); |
| 7609 | return 0; |
| 7610 | } |
| 7611 | |
| 7612 | gas_assert (adding_value != -1); |
| 7613 | |
| 7614 | for (opt = aarch64_features; opt->name != NULL; opt++) |
| 7615 | if (strncmp (opt->name, str, optlen) == 0) |
| 7616 | { |
| 7617 | /* Add or remove the extension. */ |
| 7618 | if (adding_value) |
| 7619 | AARCH64_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
| 7620 | else |
| 7621 | AARCH64_CLEAR_FEATURE (*ext_set, *ext_set, opt->value); |
| 7622 | break; |
| 7623 | } |
| 7624 | |
| 7625 | if (opt->name == NULL) |
| 7626 | { |
| 7627 | as_bad (_("unknown architectural extension `%s'"), str); |
| 7628 | return 0; |
| 7629 | } |
| 7630 | |
| 7631 | str = ext; |
| 7632 | }; |
| 7633 | |
| 7634 | return 1; |
| 7635 | } |
| 7636 | |
| 7637 | static int |
| 7638 | aarch64_parse_cpu (char *str) |
| 7639 | { |
| 7640 | const struct aarch64_cpu_option_table *opt; |
| 7641 | char *ext = strchr (str, '+'); |
| 7642 | size_t optlen; |
| 7643 | |
| 7644 | if (ext != NULL) |
| 7645 | optlen = ext - str; |
| 7646 | else |
| 7647 | optlen = strlen (str); |
| 7648 | |
| 7649 | if (optlen == 0) |
| 7650 | { |
| 7651 | as_bad (_("missing cpu name `%s'"), str); |
| 7652 | return 0; |
| 7653 | } |
| 7654 | |
| 7655 | for (opt = aarch64_cpus; opt->name != NULL; opt++) |
| 7656 | if (strlen (opt->name) == optlen && strncmp (str, opt->name, optlen) == 0) |
| 7657 | { |
| 7658 | mcpu_cpu_opt = &opt->value; |
| 7659 | if (ext != NULL) |
| 7660 | return aarch64_parse_features (ext, &mcpu_cpu_opt, FALSE); |
| 7661 | |
| 7662 | return 1; |
| 7663 | } |
| 7664 | |
| 7665 | as_bad (_("unknown cpu `%s'"), str); |
| 7666 | return 0; |
| 7667 | } |
| 7668 | |
| 7669 | static int |
| 7670 | aarch64_parse_arch (char *str) |
| 7671 | { |
| 7672 | const struct aarch64_arch_option_table *opt; |
| 7673 | char *ext = strchr (str, '+'); |
| 7674 | size_t optlen; |
| 7675 | |
| 7676 | if (ext != NULL) |
| 7677 | optlen = ext - str; |
| 7678 | else |
| 7679 | optlen = strlen (str); |
| 7680 | |
| 7681 | if (optlen == 0) |
| 7682 | { |
| 7683 | as_bad (_("missing architecture name `%s'"), str); |
| 7684 | return 0; |
| 7685 | } |
| 7686 | |
| 7687 | for (opt = aarch64_archs; opt->name != NULL; opt++) |
| 7688 | if (strlen (opt->name) == optlen && strncmp (str, opt->name, optlen) == 0) |
| 7689 | { |
| 7690 | march_cpu_opt = &opt->value; |
| 7691 | if (ext != NULL) |
| 7692 | return aarch64_parse_features (ext, &march_cpu_opt, FALSE); |
| 7693 | |
| 7694 | return 1; |
| 7695 | } |
| 7696 | |
| 7697 | as_bad (_("unknown architecture `%s'\n"), str); |
| 7698 | return 0; |
| 7699 | } |
| 7700 | |
| 7701 | /* ABIs. */ |
| 7702 | struct aarch64_option_abi_value_table |
| 7703 | { |
| 7704 | char *name; |
| 7705 | enum aarch64_abi_type value; |
| 7706 | }; |
| 7707 | |
| 7708 | static const struct aarch64_option_abi_value_table aarch64_abis[] = { |
| 7709 | {"ilp32", AARCH64_ABI_ILP32}, |
| 7710 | {"lp64", AARCH64_ABI_LP64}, |
| 7711 | {NULL, 0} |
| 7712 | }; |
| 7713 | |
| 7714 | static int |
| 7715 | aarch64_parse_abi (char *str) |
| 7716 | { |
| 7717 | const struct aarch64_option_abi_value_table *opt; |
| 7718 | size_t optlen = strlen (str); |
| 7719 | |
| 7720 | if (optlen == 0) |
| 7721 | { |
| 7722 | as_bad (_("missing abi name `%s'"), str); |
| 7723 | return 0; |
| 7724 | } |
| 7725 | |
| 7726 | for (opt = aarch64_abis; opt->name != NULL; opt++) |
| 7727 | if (strlen (opt->name) == optlen && strncmp (str, opt->name, optlen) == 0) |
| 7728 | { |
| 7729 | aarch64_abi = opt->value; |
| 7730 | return 1; |
| 7731 | } |
| 7732 | |
| 7733 | as_bad (_("unknown abi `%s'\n"), str); |
| 7734 | return 0; |
| 7735 | } |
| 7736 | |
| 7737 | static struct aarch64_long_option_table aarch64_long_opts[] = { |
| 7738 | #ifdef OBJ_ELF |
| 7739 | {"mabi=", N_("<abi name>\t specify for ABI <abi name>"), |
| 7740 | aarch64_parse_abi, NULL}, |
| 7741 | #endif /* OBJ_ELF */ |
| 7742 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), |
| 7743 | aarch64_parse_cpu, NULL}, |
| 7744 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), |
| 7745 | aarch64_parse_arch, NULL}, |
| 7746 | {NULL, NULL, 0, NULL} |
| 7747 | }; |
| 7748 | |
| 7749 | int |
| 7750 | md_parse_option (int c, char *arg) |
| 7751 | { |
| 7752 | struct aarch64_option_table *opt; |
| 7753 | struct aarch64_long_option_table *lopt; |
| 7754 | |
| 7755 | switch (c) |
| 7756 | { |
| 7757 | #ifdef OPTION_EB |
| 7758 | case OPTION_EB: |
| 7759 | target_big_endian = 1; |
| 7760 | break; |
| 7761 | #endif |
| 7762 | |
| 7763 | #ifdef OPTION_EL |
| 7764 | case OPTION_EL: |
| 7765 | target_big_endian = 0; |
| 7766 | break; |
| 7767 | #endif |
| 7768 | |
| 7769 | case 'a': |
| 7770 | /* Listing option. Just ignore these, we don't support additional |
| 7771 | ones. */ |
| 7772 | return 0; |
| 7773 | |
| 7774 | default: |
| 7775 | for (opt = aarch64_opts; opt->option != NULL; opt++) |
| 7776 | { |
| 7777 | if (c == opt->option[0] |
| 7778 | && ((arg == NULL && opt->option[1] == 0) |
| 7779 | || streq (arg, opt->option + 1))) |
| 7780 | { |
| 7781 | /* If the option is deprecated, tell the user. */ |
| 7782 | if (opt->deprecated != NULL) |
| 7783 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
| 7784 | arg ? arg : "", _(opt->deprecated)); |
| 7785 | |
| 7786 | if (opt->var != NULL) |
| 7787 | *opt->var = opt->value; |
| 7788 | |
| 7789 | return 1; |
| 7790 | } |
| 7791 | } |
| 7792 | |
| 7793 | for (lopt = aarch64_long_opts; lopt->option != NULL; lopt++) |
| 7794 | { |
| 7795 | /* These options are expected to have an argument. */ |
| 7796 | if (c == lopt->option[0] |
| 7797 | && arg != NULL |
| 7798 | && strncmp (arg, lopt->option + 1, |
| 7799 | strlen (lopt->option + 1)) == 0) |
| 7800 | { |
| 7801 | /* If the option is deprecated, tell the user. */ |
| 7802 | if (lopt->deprecated != NULL) |
| 7803 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
| 7804 | _(lopt->deprecated)); |
| 7805 | |
| 7806 | /* Call the sup-option parser. */ |
| 7807 | return lopt->func (arg + strlen (lopt->option) - 1); |
| 7808 | } |
| 7809 | } |
| 7810 | |
| 7811 | return 0; |
| 7812 | } |
| 7813 | |
| 7814 | return 1; |
| 7815 | } |
| 7816 | |
| 7817 | void |
| 7818 | md_show_usage (FILE * fp) |
| 7819 | { |
| 7820 | struct aarch64_option_table *opt; |
| 7821 | struct aarch64_long_option_table *lopt; |
| 7822 | |
| 7823 | fprintf (fp, _(" AArch64-specific assembler options:\n")); |
| 7824 | |
| 7825 | for (opt = aarch64_opts; opt->option != NULL; opt++) |
| 7826 | if (opt->help != NULL) |
| 7827 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); |
| 7828 | |
| 7829 | for (lopt = aarch64_long_opts; lopt->option != NULL; lopt++) |
| 7830 | if (lopt->help != NULL) |
| 7831 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); |
| 7832 | |
| 7833 | #ifdef OPTION_EB |
| 7834 | fprintf (fp, _("\ |
| 7835 | -EB assemble code for a big-endian cpu\n")); |
| 7836 | #endif |
| 7837 | |
| 7838 | #ifdef OPTION_EL |
| 7839 | fprintf (fp, _("\ |
| 7840 | -EL assemble code for a little-endian cpu\n")); |
| 7841 | #endif |
| 7842 | } |
| 7843 | |
| 7844 | /* Parse a .cpu directive. */ |
| 7845 | |
| 7846 | static void |
| 7847 | s_aarch64_cpu (int ignored ATTRIBUTE_UNUSED) |
| 7848 | { |
| 7849 | const struct aarch64_cpu_option_table *opt; |
| 7850 | char saved_char; |
| 7851 | char *name; |
| 7852 | char *ext; |
| 7853 | size_t optlen; |
| 7854 | |
| 7855 | name = input_line_pointer; |
| 7856 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
| 7857 | input_line_pointer++; |
| 7858 | saved_char = *input_line_pointer; |
| 7859 | *input_line_pointer = 0; |
| 7860 | |
| 7861 | ext = strchr (name, '+'); |
| 7862 | |
| 7863 | if (ext != NULL) |
| 7864 | optlen = ext - name; |
| 7865 | else |
| 7866 | optlen = strlen (name); |
| 7867 | |
| 7868 | /* Skip the first "all" entry. */ |
| 7869 | for (opt = aarch64_cpus + 1; opt->name != NULL; opt++) |
| 7870 | if (strlen (opt->name) == optlen |
| 7871 | && strncmp (name, opt->name, optlen) == 0) |
| 7872 | { |
| 7873 | mcpu_cpu_opt = &opt->value; |
| 7874 | if (ext != NULL) |
| 7875 | if (!aarch64_parse_features (ext, &mcpu_cpu_opt, FALSE)) |
| 7876 | return; |
| 7877 | |
| 7878 | cpu_variant = *mcpu_cpu_opt; |
| 7879 | |
| 7880 | *input_line_pointer = saved_char; |
| 7881 | demand_empty_rest_of_line (); |
| 7882 | return; |
| 7883 | } |
| 7884 | as_bad (_("unknown cpu `%s'"), name); |
| 7885 | *input_line_pointer = saved_char; |
| 7886 | ignore_rest_of_line (); |
| 7887 | } |
| 7888 | |
| 7889 | |
| 7890 | /* Parse a .arch directive. */ |
| 7891 | |
| 7892 | static void |
| 7893 | s_aarch64_arch (int ignored ATTRIBUTE_UNUSED) |
| 7894 | { |
| 7895 | const struct aarch64_arch_option_table *opt; |
| 7896 | char saved_char; |
| 7897 | char *name; |
| 7898 | char *ext; |
| 7899 | size_t optlen; |
| 7900 | |
| 7901 | name = input_line_pointer; |
| 7902 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
| 7903 | input_line_pointer++; |
| 7904 | saved_char = *input_line_pointer; |
| 7905 | *input_line_pointer = 0; |
| 7906 | |
| 7907 | ext = strchr (name, '+'); |
| 7908 | |
| 7909 | if (ext != NULL) |
| 7910 | optlen = ext - name; |
| 7911 | else |
| 7912 | optlen = strlen (name); |
| 7913 | |
| 7914 | /* Skip the first "all" entry. */ |
| 7915 | for (opt = aarch64_archs + 1; opt->name != NULL; opt++) |
| 7916 | if (strlen (opt->name) == optlen |
| 7917 | && strncmp (name, opt->name, optlen) == 0) |
| 7918 | { |
| 7919 | mcpu_cpu_opt = &opt->value; |
| 7920 | if (ext != NULL) |
| 7921 | if (!aarch64_parse_features (ext, &mcpu_cpu_opt, FALSE)) |
| 7922 | return; |
| 7923 | |
| 7924 | cpu_variant = *mcpu_cpu_opt; |
| 7925 | |
| 7926 | *input_line_pointer = saved_char; |
| 7927 | demand_empty_rest_of_line (); |
| 7928 | return; |
| 7929 | } |
| 7930 | |
| 7931 | as_bad (_("unknown architecture `%s'\n"), name); |
| 7932 | *input_line_pointer = saved_char; |
| 7933 | ignore_rest_of_line (); |
| 7934 | } |
| 7935 | |
| 7936 | /* Parse a .arch_extension directive. */ |
| 7937 | |
| 7938 | static void |
| 7939 | s_aarch64_arch_extension (int ignored ATTRIBUTE_UNUSED) |
| 7940 | { |
| 7941 | char saved_char; |
| 7942 | char *ext = input_line_pointer;; |
| 7943 | |
| 7944 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
| 7945 | input_line_pointer++; |
| 7946 | saved_char = *input_line_pointer; |
| 7947 | *input_line_pointer = 0; |
| 7948 | |
| 7949 | if (!aarch64_parse_features (ext, &mcpu_cpu_opt, TRUE)) |
| 7950 | return; |
| 7951 | |
| 7952 | cpu_variant = *mcpu_cpu_opt; |
| 7953 | |
| 7954 | *input_line_pointer = saved_char; |
| 7955 | demand_empty_rest_of_line (); |
| 7956 | } |
| 7957 | |
| 7958 | /* Copy symbol information. */ |
| 7959 | |
| 7960 | void |
| 7961 | aarch64_copy_symbol_attributes (symbolS * dest, symbolS * src) |
| 7962 | { |
| 7963 | AARCH64_GET_FLAG (dest) = AARCH64_GET_FLAG (src); |
| 7964 | } |