Home | History | Annotate | Line # | Download | only in config
tc-sparc.c revision 1.3
      1 /* tc-sparc.c -- Assemble for the SPARC
      2    Copyright (C) 1989-2016 Free Software Foundation, Inc.
      3    This file is part of GAS, the GNU Assembler.
      4 
      5    GAS is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3, or (at your option)
      8    any later version.
      9 
     10    GAS is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public
     16    License along with GAS; see the file COPYING.  If not, write
     17    to the Free Software Foundation, 51 Franklin Street - Fifth Floor,
     18    Boston, MA 02110-1301, USA.  */
     19 
     20 #include "as.h"
     21 #include "safe-ctype.h"
     22 #include "subsegs.h"
     23 
     24 #include "opcode/sparc.h"
     25 #include "dw2gencfi.h"
     26 
     27 #ifdef OBJ_ELF
     28 #include "elf/sparc.h"
     29 #include "dwarf2dbg.h"
     30 #endif
     31 
     32 /* Some ancient Sun C compilers would not take such hex constants as
     33    unsigned, and would end up sign-extending them to form an offsetT,
     34    so use these constants instead.  */
     35 #define U0xffffffff ((((unsigned long) 1 << 16) << 16) - 1)
     36 #define U0x80000000 ((((unsigned long) 1 << 16) << 15))
     37 
     38 static int sparc_ip (char *, const struct sparc_opcode **);
     39 static int parse_keyword_arg (int (*) (const char *), char **, int *);
     40 static int parse_const_expr_arg (char **, int *);
     41 static int get_expression (char *);
     42 
     43 /* Default architecture.  */
     44 /* ??? The default value should be V8, but sparclite support was added
     45    by making it the default.  GCC now passes -Asparclite, so maybe sometime in
     46    the future we can set this to V8.  */
     47 #ifndef DEFAULT_ARCH
     48 #define DEFAULT_ARCH "sparclite"
     49 #endif
     50 static const char *default_arch = DEFAULT_ARCH;
     51 
     52 /* Non-zero if the initial values of `max_architecture' and `sparc_arch_size'
     53    have been set.  */
     54 static int default_init_p;
     55 
     56 /* Current architecture.  We don't bump up unless necessary.  */
     57 static enum sparc_opcode_arch_val current_architecture = SPARC_OPCODE_ARCH_V6;
     58 
     59 /* The maximum architecture level we can bump up to.
     60    In a 32 bit environment, don't allow bumping up to v9 by default.
     61    The native assembler works this way.  The user is required to pass
     62    an explicit argument before we'll create v9 object files.  However, if
     63    we don't see any v9 insns, a v8plus object file is not created.  */
     64 static enum sparc_opcode_arch_val max_architecture;
     65 
     66 /* Either 32 or 64, selects file format.  */
     67 static int sparc_arch_size;
     68 /* Initial (default) value, recorded separately in case a user option
     69    changes the value before md_show_usage is called.  */
     70 static int default_arch_size;
     71 
     72 #ifdef OBJ_ELF
     73 /* The currently selected v9 memory model.  Currently only used for
     74    ELF.  */
     75 static enum { MM_TSO, MM_PSO, MM_RMO } sparc_memory_model = MM_RMO;
     76 
     77 #ifndef TE_SOLARIS
     78 /* Bitmask of instruction types seen so far, used to populate the
     79    GNU attributes section with hwcap information.  */
     80 static bfd_uint64_t hwcap_seen;
     81 #endif
     82 #endif
     83 
     84 static bfd_uint64_t hwcap_allowed;
     85 
     86 static int architecture_requested;
     87 static int warn_on_bump;
     88 
     89 /* If warn_on_bump and the needed architecture is higher than this
     90    architecture, issue a warning.  */
     91 static enum sparc_opcode_arch_val warn_after_architecture;
     92 
     93 /* Non-zero if as should generate error if an undeclared g[23] register
     94    has been used in -64.  */
     95 static int no_undeclared_regs;
     96 
     97 /* Non-zero if we should try to relax jumps and calls.  */
     98 static int sparc_relax;
     99 
    100 /* Non-zero if we are generating PIC code.  */
    101 int sparc_pic_code;
    102 
    103 /* Non-zero if we should give an error when misaligned data is seen.  */
    104 static int enforce_aligned_data;
    105 
    106 extern int target_big_endian;
    107 
    108 static int target_little_endian_data;
    109 
    110 /* Symbols for global registers on v9.  */
    111 static symbolS *globals[8];
    112 
    113 /* The dwarf2 data alignment, adjusted for 32 or 64 bit.  */
    114 int sparc_cie_data_alignment;
    115 
    116 /* V9 and 86x have big and little endian data, but instructions are always big
    117    endian.  The sparclet has bi-endian support but both data and insns have
    118    the same endianness.  Global `target_big_endian' is used for data.
    119    The following macro is used for instructions.  */
    120 #ifndef INSN_BIG_ENDIAN
    121 #define INSN_BIG_ENDIAN (target_big_endian \
    122 			 || default_arch_type == sparc86x \
    123 			 || SPARC_OPCODE_ARCH_V9_P (max_architecture))
    124 #endif
    125 
    126 /* Handle of the OPCODE hash table.  */
    127 static struct hash_control *op_hash;
    128 
    129 static void s_data1 (void);
    130 static void s_seg (int);
    131 static void s_proc (int);
    132 static void s_reserve (int);
    133 static void s_common (int);
    134 static void s_empty (int);
    135 static void s_uacons (int);
    136 static void s_ncons (int);
    137 #ifdef OBJ_ELF
    138 static void s_register (int);
    139 #endif
    140 
    141 const pseudo_typeS md_pseudo_table[] =
    142 {
    143   {"align", s_align_bytes, 0},	/* Defaulting is invalid (0).  */
    144   {"common", s_common, 0},
    145   {"empty", s_empty, 0},
    146   {"global", s_globl, 0},
    147   {"half", cons, 2},
    148   {"nword", s_ncons, 0},
    149   {"optim", s_ignore, 0},
    150   {"proc", s_proc, 0},
    151   {"reserve", s_reserve, 0},
    152   {"seg", s_seg, 0},
    153   {"skip", s_space, 0},
    154   {"word", cons, 4},
    155   {"xword", cons, 8},
    156   {"uahalf", s_uacons, 2},
    157   {"uaword", s_uacons, 4},
    158   {"uaxword", s_uacons, 8},
    159 #ifdef OBJ_ELF
    160   /* These are specific to sparc/svr4.  */
    161   {"2byte", s_uacons, 2},
    162   {"4byte", s_uacons, 4},
    163   {"8byte", s_uacons, 8},
    164   {"register", s_register, 0},
    165 #endif
    166   {NULL, 0, 0},
    167 };
    168 
    169 /* This array holds the chars that always start a comment.  If the
    170    pre-processor is disabled, these aren't very useful.  */
    171 const char comment_chars[] = "!";	/* JF removed '|' from
    172                                            comment_chars.  */
    173 
    174 /* This array holds the chars that only start a comment at the beginning of
    175    a line.  If the line seems to have the form '# 123 filename'
    176    .line and .file directives will appear in the pre-processed output.  */
    177 /* Note that input_file.c hand checks for '#' at the beginning of the
    178    first line of the input file.  This is because the compiler outputs
    179    #NO_APP at the beginning of its output.  */
    180 /* Also note that comments started like this one will always
    181    work if '/' isn't otherwise defined.  */
    182 const char line_comment_chars[] = "#";
    183 
    184 const char line_separator_chars[] = ";";
    185 
    186 /* Chars that can be used to separate mant from exp in floating point
    187    nums.  */
    188 const char EXP_CHARS[] = "eE";
    189 
    190 /* Chars that mean this number is a floating point constant.
    191    As in 0f12.456
    192    or    0d1.2345e12  */
    193 const char FLT_CHARS[] = "rRsSfFdDxXpP";
    194 
    195 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
    196    changed in read.c.  Ideally it shouldn't have to know about it at all,
    197    but nothing is ideal around here.  */
    198 
    199 #define isoctal(c)  ((unsigned) ((c) - '0') < 8)
    200 
    201 struct sparc_it
    202   {
    203     const char *error;
    204     unsigned long opcode;
    205     struct nlist *nlistp;
    206     expressionS exp;
    207     expressionS exp2;
    208     int pcrel;
    209     bfd_reloc_code_real_type reloc;
    210   };
    211 
    212 struct sparc_it the_insn, set_insn;
    213 
    214 static void output_insn (const struct sparc_opcode *, struct sparc_it *);
    215 
    216 /* Table of arguments to -A.
    218    The sparc_opcode_arch table in sparc-opc.c is insufficient and incorrect
    219    for this use.  That table is for opcodes only.  This table is for opcodes
    220    and file formats.  */
    221 
    222 enum sparc_arch_types {v6, v7, v8, leon, sparclet, sparclite, sparc86x, v8plus,
    223 		       v8plusa, v9, v9a, v9b, v9_64};
    224 
    225 /* Hardware capability sets, used to keep sparc_arch_table easy to
    226    read.  */
    227 #define HWS_V8 HWCAP_MUL32 | HWCAP_DIV32 | HWCAP_FSMULD
    228 #define HWS_V9 HWS_V8 | HWCAP_POPC
    229 #define HWS_VA HWS_V9 | HWCAP_VIS
    230 #define HWS_VB HWS_VA | HWCAP_VIS2
    231 #define HWS_VC HWS_VB | HWCAP_ASI_BLK_INIT
    232 #define HWS_VD HWS_VC | HWCAP_FMAF | HWCAP_VIS3 | HWCAP_HPC
    233 #define HWS_VE HWS_VD                                                   \
    234   | HWCAP_AES | HWCAP_DES | HWCAP_KASUMI | HWCAP_CAMELLIA               \
    235   | HWCAP_MD5 | HWCAP_SHA1 | HWCAP_SHA256 |HWCAP_SHA512 | HWCAP_MPMUL   \
    236   | HWCAP_MONT | HWCAP_CRC32C | HWCAP_CBCOND | HWCAP_PAUSE
    237 #define HWS_VV HWS_VE | HWCAP_FJFMAU | HWCAP_IMA
    238 #define HWS_VM HWS_VV
    239 
    240 #define HWS2_VM							\
    241   HWCAP2_VIS3B | HWCAP2_ADP | HWCAP2_SPARC5 | HWCAP2_MWAIT	\
    242   | HWCAP2_XMPMUL | HWCAP2_XMONT
    243 
    244 static struct sparc_arch {
    245   const char *name;
    246   const char *opcode_arch;
    247   enum sparc_arch_types arch_type;
    248   /* Default word size, as specified during configuration.
    249      A value of zero means can't be used to specify default architecture.  */
    250   int default_arch_size;
    251   /* Allowable arg to -A?  */
    252   int user_option_p;
    253   int hwcap_allowed;
    254   int hwcap2_allowed;
    255 } sparc_arch_table[] = {
    256   { "v6",         "v6",  v6,  0, 1, 0, 0 },
    257   { "v7",         "v7",  v7,  0, 1, 0, 0 },
    258   { "v8",         "v8",  v8, 32, 1, HWS_V8, 0 },
    259   { "v8a",        "v8",  v8, 32, 1, HWS_V8, 0 },
    260   { "sparc",      "v9",  v9,  0, 1, HWCAP_V8PLUS|HWS_V9, 0 },
    261   { "sparcvis",   "v9a", v9,  0, 1, HWS_VA, 0 },
    262   { "sparcvis2",  "v9b", v9,  0, 1, HWS_VB, 0 },
    263   { "sparcfmaf",  "v9b", v9,  0, 1, HWS_VB|HWCAP_FMAF, 0 },
    264   { "sparcima",   "v9b", v9,  0, 1, HWS_VB|HWCAP_FMAF|HWCAP_IMA, 0 },
    265   { "sparcvis3",  "v9b", v9,  0, 1, HWS_VB|HWCAP_FMAF|HWCAP_VIS3|HWCAP_HPC, 0 },
    266   { "sparcvis3r", "v9b", v9,  0, 1, HWS_VB|HWCAP_FMAF|HWCAP_VIS3|HWCAP_HPC|HWCAP_FJFMAU, 0 },
    267 
    268   { "sparc4",     "v9v", v9,  0, 1, HWS_VV, 0 },
    269   { "sparc5",     "v9m", v9,  0, 1, HWS_VM, HWS2_VM },
    270 
    271   { "leon",      "leon",      leon,      32, 1, HWS_V8, 0 },
    272   { "sparclet",  "sparclet",  sparclet,  32, 1, HWS_V8, 0 },
    273   { "sparclite", "sparclite", sparclite, 32, 1, HWS_V8, 0 },
    274   { "sparc86x",  "sparclite", sparc86x,  32, 1, HWS_V8, 0 },
    275 
    276   { "v8plus",  "v9",  v9,  0, 1, HWCAP_V8PLUS|HWS_V9, 0 },
    277   { "v8plusa", "v9a", v9,  0, 1, HWCAP_V8PLUS|HWS_VA, 0 },
    278   { "v8plusb", "v9b", v9,  0, 1, HWCAP_V8PLUS|HWS_VB, 0 },
    279   { "v8plusc", "v9c", v9,  0, 1, HWCAP_V8PLUS|HWS_VC, 0 },
    280   { "v8plusd", "v9d", v9,  0, 1, HWCAP_V8PLUS|HWS_VD, 0 },
    281   { "v8pluse", "v9e", v9,  0, 1, HWCAP_V8PLUS|HWS_VE, 0 },
    282   { "v8plusv", "v9v", v9,  0, 1, HWCAP_V8PLUS|HWS_VV, 0 },
    283   { "v8plusm", "v9m", v9,  0, 1, HWCAP_V8PLUS|HWS_VM, 0 },
    284 
    285   { "v9",      "v9",  v9,  0, 1, HWS_V9, 0 },
    286   { "v9a",     "v9a", v9,  0, 1, HWS_VA, 0 },
    287   { "v9b",     "v9b", v9,  0, 1, HWS_VB, 0 },
    288   { "v9c",     "v9c", v9,  0, 1, HWS_VC, 0 },
    289   { "v9d",     "v9d", v9,  0, 1, HWS_VD, 0 },
    290   { "v9e",     "v9e", v9,  0, 1, HWS_VE, 0 },
    291   { "v9v",     "v9v", v9,  0, 1, HWS_VV, 0 },
    292   { "v9m",     "v9m", v9,  0, 1, HWS_VM, HWS2_VM },
    293 
    294   /* This exists to allow configure.tgt to pass one
    295      value to specify both the default machine and default word size.  */
    296   { "v9-64",   "v9",  v9, 64, 0, HWS_V9, 0 },
    297   { NULL, NULL, v8, 0, 0, 0, 0 }
    298 };
    299 
    300 /* Variant of default_arch */
    301 static enum sparc_arch_types default_arch_type;
    302 
    303 static struct sparc_arch *
    304 lookup_arch (const char *name)
    305 {
    306   struct sparc_arch *sa;
    307 
    308   for (sa = &sparc_arch_table[0]; sa->name != NULL; sa++)
    309     if (strcmp (sa->name, name) == 0)
    310       break;
    311   if (sa->name == NULL)
    312     return NULL;
    313   return sa;
    314 }
    315 
    316 /* Initialize the default opcode arch and word size from the default
    317    architecture name.  */
    318 
    319 static void
    320 init_default_arch (void)
    321 {
    322   struct sparc_arch *sa = lookup_arch (default_arch);
    323 
    324   if (sa == NULL
    325       || sa->default_arch_size == 0)
    326     as_fatal (_("Invalid default architecture, broken assembler."));
    327 
    328   max_architecture = sparc_opcode_lookup_arch (sa->opcode_arch);
    329   if (max_architecture == SPARC_OPCODE_ARCH_BAD)
    330     as_fatal (_("Bad opcode table, broken assembler."));
    331   default_arch_size = sparc_arch_size = sa->default_arch_size;
    332   default_init_p = 1;
    333   default_arch_type = sa->arch_type;
    334 }
    335 
    336 /* Called by TARGET_FORMAT.  */
    337 
    338 const char *
    339 sparc_target_format (void)
    340 {
    341   /* We don't get a chance to initialize anything before we're called,
    342      so handle that now.  */
    343   if (! default_init_p)
    344     init_default_arch ();
    345 
    346 #ifdef OBJ_AOUT
    347 #ifdef TE_NetBSD
    348   return "a.out-sparc-netbsd";
    349 #else
    350 #ifdef TE_SPARCAOUT
    351   if (target_big_endian)
    352     return "a.out-sunos-big";
    353   else if (default_arch_type == sparc86x && target_little_endian_data)
    354     return "a.out-sunos-big";
    355   else
    356     return "a.out-sparc-little";
    357 #else
    358   return "a.out-sunos-big";
    359 #endif
    360 #endif
    361 #endif
    362 
    363 #ifdef OBJ_BOUT
    364   return "b.out.big";
    365 #endif
    366 
    367 #ifdef OBJ_COFF
    368 #ifdef TE_LYNX
    369   return "coff-sparc-lynx";
    370 #else
    371   return "coff-sparc";
    372 #endif
    373 #endif
    374 
    375 #ifdef TE_VXWORKS
    376   return "elf32-sparc-vxworks";
    377 #endif
    378 
    379 #ifdef OBJ_ELF
    380   return sparc_arch_size == 64 ? ELF64_TARGET_FORMAT : ELF_TARGET_FORMAT;
    381 #endif
    382 
    383   abort ();
    384 }
    385 
    386 /* md_parse_option
    388  *	Invocation line includes a switch not recognized by the base assembler.
    389  *	See if it's a processor-specific option.  These are:
    390  *
    391  *	-bump
    392  *		Warn on architecture bumps.  See also -A.
    393  *
    394  *	-Av6, -Av7, -Av8, -Aleon, -Asparclite, -Asparclet
    395  *		Standard 32 bit architectures.
    396  *	-Av9, -Av9a, -Av9b
    397  *		Sparc64 in either a 32 or 64 bit world (-32/-64 says which).
    398  *		This used to only mean 64 bits, but properly specifying it
    399  *		complicated gcc's ASM_SPECs, so now opcode selection is
    400  *		specified orthogonally to word size (except when specifying
    401  *		the default, but that is an internal implementation detail).
    402  *	-Av8plus, -Av8plusa, -Av8plusb
    403  *		Same as -Av9{,a,b}.
    404  *	-xarch=v8plus, -xarch=v8plusa, -xarch=v8plusb
    405  *		Same as -Av8plus{,a,b} -32, for compatibility with Sun's
    406  *		assembler.
    407  *	-xarch=v9, -xarch=v9a, -xarch=v9b
    408  *		Same as -Av9{,a,b} -64, for compatibility with Sun's
    409  *		assembler.
    410  *
    411  *		Select the architecture and possibly the file format.
    412  *		Instructions or features not supported by the selected
    413  *		architecture cause fatal errors.
    414  *
    415  *		The default is to start at v6, and bump the architecture up
    416  *		whenever an instruction is seen at a higher level.  In 32 bit
    417  *		environments, v9 is not bumped up to, the user must pass
    418  * 		-Av8plus{,a,b}.
    419  *
    420  *		If -bump is specified, a warning is printing when bumping to
    421  *		higher levels.
    422  *
    423  *		If an architecture is specified, all instructions must match
    424  *		that architecture.  Any higher level instructions are flagged
    425  *		as errors.  Note that in the 32 bit environment specifying
    426  *		-Av8plus does not automatically create a v8plus object file, a
    427  *		v9 insn must be seen.
    428  *
    429  *		If both an architecture and -bump are specified, the
    430  *		architecture starts at the specified level, but bumps are
    431  *		warnings.  Note that we can't set `current_architecture' to
    432  *		the requested level in this case: in the 32 bit environment,
    433  *		we still must avoid creating v8plus object files unless v9
    434  * 		insns are seen.
    435  *
    436  * Note:
    437  *		Bumping between incompatible architectures is always an
    438  *		error.  For example, from sparclite to v9.
    439  */
    440 
    441 #ifdef OBJ_ELF
    442 const char *md_shortopts = "A:K:VQ:sq";
    443 #else
    444 #ifdef OBJ_AOUT
    445 const char *md_shortopts = "A:k";
    446 #else
    447 const char *md_shortopts = "A:";
    448 #endif
    449 #endif
    450 struct option md_longopts[] = {
    451 #define OPTION_BUMP (OPTION_MD_BASE)
    452   {"bump", no_argument, NULL, OPTION_BUMP},
    453 #define OPTION_SPARC (OPTION_MD_BASE + 1)
    454   {"sparc", no_argument, NULL, OPTION_SPARC},
    455 #define OPTION_XARCH (OPTION_MD_BASE + 2)
    456   {"xarch", required_argument, NULL, OPTION_XARCH},
    457 #ifdef OBJ_ELF
    458 #define OPTION_32 (OPTION_MD_BASE + 3)
    459   {"32", no_argument, NULL, OPTION_32},
    460 #define OPTION_64 (OPTION_MD_BASE + 4)
    461   {"64", no_argument, NULL, OPTION_64},
    462 #define OPTION_TSO (OPTION_MD_BASE + 5)
    463   {"TSO", no_argument, NULL, OPTION_TSO},
    464 #define OPTION_PSO (OPTION_MD_BASE + 6)
    465   {"PSO", no_argument, NULL, OPTION_PSO},
    466 #define OPTION_RMO (OPTION_MD_BASE + 7)
    467   {"RMO", no_argument, NULL, OPTION_RMO},
    468 #endif
    469 #ifdef SPARC_BIENDIAN
    470 #define OPTION_LITTLE_ENDIAN (OPTION_MD_BASE + 8)
    471   {"EL", no_argument, NULL, OPTION_LITTLE_ENDIAN},
    472 #define OPTION_BIG_ENDIAN (OPTION_MD_BASE + 9)
    473   {"EB", no_argument, NULL, OPTION_BIG_ENDIAN},
    474 #endif
    475 #define OPTION_ENFORCE_ALIGNED_DATA (OPTION_MD_BASE + 10)
    476   {"enforce-aligned-data", no_argument, NULL, OPTION_ENFORCE_ALIGNED_DATA},
    477 #define OPTION_LITTLE_ENDIAN_DATA (OPTION_MD_BASE + 11)
    478   {"little-endian-data", no_argument, NULL, OPTION_LITTLE_ENDIAN_DATA},
    479 #ifdef OBJ_ELF
    480 #define OPTION_NO_UNDECLARED_REGS (OPTION_MD_BASE + 12)
    481   {"no-undeclared-regs", no_argument, NULL, OPTION_NO_UNDECLARED_REGS},
    482 #define OPTION_UNDECLARED_REGS (OPTION_MD_BASE + 13)
    483   {"undeclared-regs", no_argument, NULL, OPTION_UNDECLARED_REGS},
    484 #endif
    485 #define OPTION_RELAX (OPTION_MD_BASE + 14)
    486   {"relax", no_argument, NULL, OPTION_RELAX},
    487 #define OPTION_NO_RELAX (OPTION_MD_BASE + 15)
    488   {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
    489   {NULL, no_argument, NULL, 0}
    490 };
    491 
    492 size_t md_longopts_size = sizeof (md_longopts);
    493 
    494 int
    495 md_parse_option (int c, const char *arg)
    496 {
    497   /* We don't get a chance to initialize anything before we're called,
    498      so handle that now.  */
    499   if (! default_init_p)
    500     init_default_arch ();
    501 
    502   switch (c)
    503     {
    504     case OPTION_BUMP:
    505       warn_on_bump = 1;
    506       warn_after_architecture = SPARC_OPCODE_ARCH_V6;
    507       break;
    508 
    509     case OPTION_XARCH:
    510 #ifdef OBJ_ELF
    511       if (!strncmp (arg, "v9", 2))
    512 	md_parse_option (OPTION_64, NULL);
    513       else
    514 	{
    515 	  if (!strncmp (arg, "v8", 2)
    516 	      || !strncmp (arg, "v7", 2)
    517 	      || !strncmp (arg, "v6", 2)
    518 	      || !strcmp (arg, "sparclet")
    519 	      || !strcmp (arg, "sparclite")
    520 	      || !strcmp (arg, "sparc86x"))
    521 	    md_parse_option (OPTION_32, NULL);
    522 	}
    523 #endif
    524       /* Fall through.  */
    525 
    526     case 'A':
    527       {
    528 	struct sparc_arch *sa;
    529 	enum sparc_opcode_arch_val opcode_arch;
    530 
    531 	sa = lookup_arch (arg);
    532 	if (sa == NULL
    533 	    || ! sa->user_option_p)
    534 	  {
    535 	    if (c == OPTION_XARCH)
    536 	      as_bad (_("invalid architecture -xarch=%s"), arg);
    537 	    else
    538 	      as_bad (_("invalid architecture -A%s"), arg);
    539 	    return 0;
    540 	  }
    541 
    542 	opcode_arch = sparc_opcode_lookup_arch (sa->opcode_arch);
    543 	if (opcode_arch == SPARC_OPCODE_ARCH_BAD)
    544 	  as_fatal (_("Bad opcode table, broken assembler."));
    545 
    546 	if (!architecture_requested
    547 	    || opcode_arch > max_architecture)
    548 	  max_architecture = opcode_arch;
    549 	hwcap_allowed
    550           |= (((bfd_uint64_t) sa->hwcap2_allowed) << 32) | sa->hwcap_allowed;
    551 	architecture_requested = 1;
    552       }
    553       break;
    554 
    555     case OPTION_SPARC:
    556       /* Ignore -sparc, used by SunOS make default .s.o rule.  */
    557       break;
    558 
    559     case OPTION_ENFORCE_ALIGNED_DATA:
    560       enforce_aligned_data = 1;
    561       break;
    562 
    563 #ifdef SPARC_BIENDIAN
    564     case OPTION_LITTLE_ENDIAN:
    565       target_big_endian = 0;
    566       if (default_arch_type != sparclet)
    567 	as_fatal ("This target does not support -EL");
    568       break;
    569     case OPTION_LITTLE_ENDIAN_DATA:
    570       target_little_endian_data = 1;
    571       target_big_endian = 0;
    572       if (default_arch_type != sparc86x
    573 	  && default_arch_type != v9)
    574 	as_fatal ("This target does not support --little-endian-data");
    575       break;
    576     case OPTION_BIG_ENDIAN:
    577       target_big_endian = 1;
    578       break;
    579 #endif
    580 
    581 #ifdef OBJ_AOUT
    582     case 'k':
    583       sparc_pic_code = 1;
    584       break;
    585 #endif
    586 
    587 #ifdef OBJ_ELF
    588     case OPTION_32:
    589     case OPTION_64:
    590       {
    591 	const char **list, **l;
    592 
    593 	sparc_arch_size = c == OPTION_32 ? 32 : 64;
    594 	list = bfd_target_list ();
    595 	for (l = list; *l != NULL; l++)
    596 	  {
    597 	    if (sparc_arch_size == 32)
    598 	      {
    599 		if (CONST_STRNEQ (*l, "elf32-sparc"))
    600 		  break;
    601 	      }
    602 	    else
    603 	      {
    604 		if (CONST_STRNEQ (*l, "elf64-sparc"))
    605 		  break;
    606 	      }
    607 	  }
    608 	if (*l == NULL)
    609 	  as_fatal (_("No compiled in support for %d bit object file format"),
    610 		    sparc_arch_size);
    611 	free (list);
    612 
    613 	if (sparc_arch_size == 64
    614 	    && max_architecture < SPARC_OPCODE_ARCH_V9)
    615 	  max_architecture = SPARC_OPCODE_ARCH_V9;
    616       }
    617       break;
    618 
    619     case OPTION_TSO:
    620       sparc_memory_model = MM_TSO;
    621       break;
    622 
    623     case OPTION_PSO:
    624       sparc_memory_model = MM_PSO;
    625       break;
    626 
    627     case OPTION_RMO:
    628       sparc_memory_model = MM_RMO;
    629       break;
    630 
    631     case 'V':
    632       print_version_id ();
    633       break;
    634 
    635     case 'Q':
    636       /* Qy - do emit .comment
    637 	 Qn - do not emit .comment.  */
    638       break;
    639 
    640     case 's':
    641       /* Use .stab instead of .stab.excl.  */
    642       break;
    643 
    644     case 'q':
    645       /* quick -- Native assembler does fewer checks.  */
    646       break;
    647 
    648     case 'K':
    649       if (strcmp (arg, "PIC") != 0)
    650 	as_warn (_("Unrecognized option following -K"));
    651       else
    652 	sparc_pic_code = 1;
    653       break;
    654 
    655     case OPTION_NO_UNDECLARED_REGS:
    656       no_undeclared_regs = 1;
    657       break;
    658 
    659     case OPTION_UNDECLARED_REGS:
    660       no_undeclared_regs = 0;
    661       break;
    662 #endif
    663 
    664     case OPTION_RELAX:
    665       sparc_relax = 1;
    666       break;
    667 
    668     case OPTION_NO_RELAX:
    669       sparc_relax = 0;
    670       break;
    671 
    672     default:
    673       return 0;
    674     }
    675 
    676   return 1;
    677 }
    678 
    679 void
    680 md_show_usage (FILE *stream)
    681 {
    682   const struct sparc_arch *arch;
    683   int column;
    684 
    685   /* We don't get a chance to initialize anything before we're called,
    686      so handle that now.  */
    687   if (! default_init_p)
    688     init_default_arch ();
    689 
    690   fprintf (stream, _("SPARC options:\n"));
    691   column = 0;
    692   for (arch = &sparc_arch_table[0]; arch->name; arch++)
    693     {
    694       if (!arch->user_option_p)
    695 	continue;
    696       if (arch != &sparc_arch_table[0])
    697 	fprintf (stream, " | ");
    698       if (column + strlen (arch->name) > 70)
    699 	{
    700 	  column = 0;
    701 	  fputc ('\n', stream);
    702 	}
    703       column += 5 + 2 + strlen (arch->name);
    704       fprintf (stream, "-A%s", arch->name);
    705     }
    706   for (arch = &sparc_arch_table[0]; arch->name; arch++)
    707     {
    708       if (!arch->user_option_p)
    709 	continue;
    710       fprintf (stream, " | ");
    711       if (column + strlen (arch->name) > 65)
    712 	{
    713 	  column = 0;
    714 	  fputc ('\n', stream);
    715 	}
    716       column += 5 + 7 + strlen (arch->name);
    717       fprintf (stream, "-xarch=%s", arch->name);
    718     }
    719   fprintf (stream, _("\n\
    720 			specify variant of SPARC architecture\n\
    721 -bump			warn when assembler switches architectures\n\
    722 -sparc			ignored\n\
    723 --enforce-aligned-data	force .long, etc., to be aligned correctly\n\
    724 -relax			relax jumps and branches (default)\n\
    725 -no-relax		avoid changing any jumps and branches\n"));
    726 #ifdef OBJ_AOUT
    727   fprintf (stream, _("\
    728 -k			generate PIC\n"));
    729 #endif
    730 #ifdef OBJ_ELF
    731   fprintf (stream, _("\
    732 -32			create 32 bit object file\n\
    733 -64			create 64 bit object file\n"));
    734   fprintf (stream, _("\
    735 			[default is %d]\n"), default_arch_size);
    736   fprintf (stream, _("\
    737 -TSO			use Total Store Ordering\n\
    738 -PSO			use Partial Store Ordering\n\
    739 -RMO			use Relaxed Memory Ordering\n"));
    740   fprintf (stream, _("\
    741 			[default is %s]\n"), (default_arch_size == 64) ? "RMO" : "TSO");
    742   fprintf (stream, _("\
    743 -KPIC			generate PIC\n\
    744 -V			print assembler version number\n\
    745 -undeclared-regs	ignore application global register usage without\n\
    746 			appropriate .register directive (default)\n\
    747 -no-undeclared-regs	force error on application global register usage\n\
    748 			without appropriate .register directive\n\
    749 -q			ignored\n\
    750 -Qy, -Qn		ignored\n\
    751 -s			ignored\n"));
    752 #endif
    753 #ifdef SPARC_BIENDIAN
    754   fprintf (stream, _("\
    755 -EL			generate code for a little endian machine\n\
    756 -EB			generate code for a big endian machine\n\
    757 --little-endian-data	generate code for a machine having big endian\n\
    758                         instructions and little endian data.\n"));
    759 #endif
    760 }
    761 
    762 /* Native operand size opcode translation.  */
    764 static struct
    765   {
    766     const char *name;
    767     const char *name32;
    768     const char *name64;
    769   } native_op_table[] =
    770 {
    771   {"ldn", "ld", "ldx"},
    772   {"ldna", "lda", "ldxa"},
    773   {"stn", "st", "stx"},
    774   {"stna", "sta", "stxa"},
    775   {"slln", "sll", "sllx"},
    776   {"srln", "srl", "srlx"},
    777   {"sran", "sra", "srax"},
    778   {"casn", "cas", "casx"},
    779   {"casna", "casa", "casxa"},
    780   {"clrn", "clr", "clrx"},
    781   {NULL, NULL, NULL},
    782 };
    783 
    784 /* sparc64 privileged and hyperprivileged registers.  */
    786 
    787 struct priv_reg_entry
    788 {
    789   const char *name;
    790   int regnum;
    791 };
    792 
    793 struct priv_reg_entry priv_reg_table[] =
    794 {
    795   {"tpc", 0},
    796   {"tnpc", 1},
    797   {"tstate", 2},
    798   {"tt", 3},
    799   {"tick", 4},
    800   {"tba", 5},
    801   {"pstate", 6},
    802   {"tl", 7},
    803   {"pil", 8},
    804   {"cwp", 9},
    805   {"cansave", 10},
    806   {"canrestore", 11},
    807   {"cleanwin", 12},
    808   {"otherwin", 13},
    809   {"wstate", 14},
    810   {"fq", 15},
    811   {"gl", 16},
    812   {"pmcdper", 23},
    813   {"ver", 31},
    814   {NULL, -1},			/* End marker.  */
    815 };
    816 
    817 struct priv_reg_entry hpriv_reg_table[] =
    818 {
    819   {"hpstate", 0},
    820   {"htstate", 1},
    821   {"hintp", 3},
    822   {"htba", 5},
    823   {"hver", 6},
    824   {"hmcdper", 23},
    825   {"hmcddfr", 24},
    826   {"hva_mask_nz", 27},
    827   {"hstick_offset", 28},
    828   {"hstick_enable", 29},
    829   {"hstick_cmpr", 31},
    830   {NULL, -1},			/* End marker.  */
    831 };
    832 
    833 /* v9a or later specific ancillary state registers. */
    834 
    835 struct priv_reg_entry v9a_asr_table[] =
    836 {
    837   {"tick_cmpr", 23},
    838   {"sys_tick_cmpr", 25},
    839   {"sys_tick", 24},
    840   {"stick_cmpr", 25},
    841   {"stick", 24},
    842   {"softint_clear", 21},
    843   {"softint_set", 20},
    844   {"softint", 22},
    845   {"set_softint", 20},
    846   {"pause", 27},
    847   {"pic", 17},
    848   {"pcr", 16},
    849   {"mwait", 28},
    850   {"gsr", 19},
    851   {"dcr", 18},
    852   {"cfr", 26},
    853   {"clear_softint", 21},
    854   {NULL, -1},			/* End marker.  */
    855 };
    856 
    857 static int
    858 cmp_reg_entry (const void *parg, const void *qarg)
    859 {
    860   const struct priv_reg_entry *p = (const struct priv_reg_entry *) parg;
    861   const struct priv_reg_entry *q = (const struct priv_reg_entry *) qarg;
    862 
    863   if (p->name == q->name)
    864     return 0;
    865   else if (p->name == NULL)
    866     return 1;
    867   else if (q->name == NULL)
    868     return -1;
    869   else
    870     return strcmp (q->name, p->name);
    871 }
    872 
    873 /* sparc %-pseudo-operations.  */
    875 
    876 
    877 #define F_POP_V9       0x1 /* The pseudo-op is for v9 only.  */
    878 #define F_POP_PCREL    0x2 /* The pseudo-op can be used in pc-relative
    879                               contexts.  */
    880 #define F_POP_TLS_CALL 0x4 /* The pseudo-op marks a tls call.  */
    881 #define F_POP_POSTFIX  0x8 /* The pseudo-op should appear after the
    882                               last operand of an
    883                               instruction. (Generally they can appear
    884                               anywhere an immediate operand is
    885                               expected.  */
    886 struct pop_entry
    887 {
    888   /* The name as it appears in assembler.  */
    889   const char *name;
    890   /* The reloc this pseudo-op translates to.  */
    891   int reloc;
    892   /* Flags.  See F_POP_* above.  */
    893   int flags;
    894 };
    895 
    896 struct pop_entry pop_table[] =
    897 {
    898   { "hix",		BFD_RELOC_SPARC_HIX22,		F_POP_V9 },
    899   { "lox",		BFD_RELOC_SPARC_LOX10, 		F_POP_V9 },
    900   { "hi",		BFD_RELOC_HI22,			F_POP_PCREL },
    901   { "lo",		BFD_RELOC_LO10,			F_POP_PCREL },
    902   { "pc22",		BFD_RELOC_SPARC_PC22,		F_POP_PCREL },
    903   { "pc10",		BFD_RELOC_SPARC_PC10,		F_POP_PCREL },
    904   { "hh",		BFD_RELOC_SPARC_HH22,		F_POP_V9|F_POP_PCREL },
    905   { "hm",		BFD_RELOC_SPARC_HM10,		F_POP_V9|F_POP_PCREL },
    906   { "lm",		BFD_RELOC_SPARC_LM22,		F_POP_V9|F_POP_PCREL },
    907   { "h34",		BFD_RELOC_SPARC_H34,		F_POP_V9 },
    908   { "l34",		BFD_RELOC_SPARC_L44,		F_POP_V9 },
    909   { "h44",		BFD_RELOC_SPARC_H44,		F_POP_V9 },
    910   { "m44",		BFD_RELOC_SPARC_M44,		F_POP_V9 },
    911   { "l44",		BFD_RELOC_SPARC_L44,		F_POP_V9 },
    912   { "uhi",		BFD_RELOC_SPARC_HH22,		F_POP_V9 },
    913   { "ulo",		BFD_RELOC_SPARC_HM10,		F_POP_V9 },
    914   { "tgd_hi22",		BFD_RELOC_SPARC_TLS_GD_HI22, 	0 },
    915   { "tgd_lo10",		BFD_RELOC_SPARC_TLS_GD_LO10, 	0 },
    916   { "tldm_hi22",	BFD_RELOC_SPARC_TLS_LDM_HI22, 	0 },
    917   { "tldm_lo10",	BFD_RELOC_SPARC_TLS_LDM_LO10, 	0 },
    918   { "tldo_hix22",	BFD_RELOC_SPARC_TLS_LDO_HIX22, 	0 },
    919   { "tldo_lox10",	BFD_RELOC_SPARC_TLS_LDO_LOX10, 	0 },
    920   { "tie_hi22",		BFD_RELOC_SPARC_TLS_IE_HI22, 	0 },
    921   { "tie_lo10",		BFD_RELOC_SPARC_TLS_IE_LO10, 	0 },
    922   { "tle_hix22",	BFD_RELOC_SPARC_TLS_LE_HIX22, 	0 },
    923   { "tle_lox10",	BFD_RELOC_SPARC_TLS_LE_LOX10, 	0 },
    924   { "gdop_hix22",	BFD_RELOC_SPARC_GOTDATA_OP_HIX22, 0 },
    925   { "gdop_lox10",	BFD_RELOC_SPARC_GOTDATA_OP_LOX10, 0 },
    926   { "tgd_add", 		BFD_RELOC_SPARC_TLS_GD_ADD,	F_POP_POSTFIX },
    927   { "tgd_call",		BFD_RELOC_SPARC_TLS_GD_CALL, 	F_POP_POSTFIX|F_POP_TLS_CALL },
    928   { "tldm_add",		BFD_RELOC_SPARC_TLS_LDM_ADD, 	F_POP_POSTFIX },
    929   { "tldm_call",	BFD_RELOC_SPARC_TLS_LDM_CALL,	F_POP_POSTFIX|F_POP_TLS_CALL },
    930   { "tldo_add",		BFD_RELOC_SPARC_TLS_LDO_ADD, 	F_POP_POSTFIX },
    931   { "tie_ldx",		BFD_RELOC_SPARC_TLS_IE_LDX, 	F_POP_POSTFIX },
    932   { "tie_ld",		BFD_RELOC_SPARC_TLS_IE_LD,	F_POP_POSTFIX },
    933   { "tie_add",		BFD_RELOC_SPARC_TLS_IE_ADD,	F_POP_POSTFIX },
    934   { "gdop",	 	BFD_RELOC_SPARC_GOTDATA_OP,	F_POP_POSTFIX },
    935   { NULL, 0, 0 },
    936 };
    937 
    938 /* Table of %-names that can appear in a sparc assembly program.  This
    940    table is initialized in md_begin and contains entries for each
    941    privileged/hyperprivileged/alternate register and %-pseudo-op.  */
    942 
    943 enum perc_entry_type
    944 {
    945   perc_entry_none = 0,
    946   perc_entry_reg,
    947   perc_entry_post_pop,
    948   perc_entry_imm_pop
    949 };
    950 
    951 struct perc_entry
    952 {
    953   /* Entry type.  */
    954   enum perc_entry_type type;
    955   /* Name of the %-entity.  */
    956   const char *name;
    957   /* strlen (name).  */
    958   int len;
    959   /* Value.  Either a pop or a reg depending on type.*/
    960   union
    961   {
    962     struct pop_entry *pop;
    963     struct priv_reg_entry *reg;
    964   };
    965 };
    966 
    967 #define NUM_PERC_ENTRIES \
    968   (((sizeof (priv_reg_table) / sizeof (priv_reg_table[0])) - 1)         \
    969    + ((sizeof (hpriv_reg_table) / sizeof (hpriv_reg_table[0])) - 1)     \
    970    + ((sizeof (v9a_asr_table) / sizeof (v9a_asr_table[0])) - 1)         \
    971    + ((sizeof (pop_table) / sizeof (pop_table[0])) - 1) \
    972    + 1)
    973 
    974 struct perc_entry perc_table[NUM_PERC_ENTRIES];
    975 
    976 static int
    977 cmp_perc_entry (const void *parg, const void *qarg)
    978 {
    979   const struct perc_entry *p = (const struct perc_entry *) parg;
    980   const struct perc_entry *q = (const struct perc_entry *) qarg;
    981 
    982   if (p->name == q->name)
    983     return 0;
    984   else if (p->name == NULL)
    985     return 1;
    986   else if (q->name == NULL)
    987     return -1;
    988   else
    989     return strcmp (q->name, p->name);
    990 }
    991 
    992 /* This function is called once, at assembler startup time.  It should
    994    set up all the tables, etc. that the MD part of the assembler will
    995    need.  */
    996 
    997 void
    998 md_begin (void)
    999 {
   1000   const char *retval = NULL;
   1001   int lose = 0;
   1002   unsigned int i = 0;
   1003 
   1004   /* We don't get a chance to initialize anything before md_parse_option
   1005      is called, and it may not be called, so handle default initialization
   1006      now if not already done.  */
   1007   if (! default_init_p)
   1008     init_default_arch ();
   1009 
   1010   sparc_cie_data_alignment = sparc_arch_size == 64 ? -8 : -4;
   1011   op_hash = hash_new ();
   1012 
   1013   while (i < (unsigned int) sparc_num_opcodes)
   1014     {
   1015       const char *name = sparc_opcodes[i].name;
   1016       retval = hash_insert (op_hash, name, (void *) &sparc_opcodes[i]);
   1017       if (retval != NULL)
   1018 	{
   1019 	  as_bad (_("Internal error: can't hash `%s': %s\n"),
   1020 		  sparc_opcodes[i].name, retval);
   1021 	  lose = 1;
   1022 	}
   1023       do
   1024 	{
   1025 	  if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
   1026 	    {
   1027 	      as_bad (_("Internal error: losing opcode: `%s' \"%s\"\n"),
   1028 		      sparc_opcodes[i].name, sparc_opcodes[i].args);
   1029 	      lose = 1;
   1030 	    }
   1031 	  ++i;
   1032 	}
   1033       while (i < (unsigned int) sparc_num_opcodes
   1034 	     && !strcmp (sparc_opcodes[i].name, name));
   1035     }
   1036 
   1037   for (i = 0; native_op_table[i].name; i++)
   1038     {
   1039       const struct sparc_opcode *insn;
   1040       const char *name = ((sparc_arch_size == 32)
   1041 		    ? native_op_table[i].name32
   1042 		    : native_op_table[i].name64);
   1043       insn = (struct sparc_opcode *) hash_find (op_hash, name);
   1044       if (insn == NULL)
   1045 	{
   1046 	  as_bad (_("Internal error: can't find opcode `%s' for `%s'\n"),
   1047 		  name, native_op_table[i].name);
   1048 	  lose = 1;
   1049 	}
   1050       else
   1051 	{
   1052 	  retval = hash_insert (op_hash, native_op_table[i].name,
   1053 				(void *) insn);
   1054 	  if (retval != NULL)
   1055 	    {
   1056 	      as_bad (_("Internal error: can't hash `%s': %s\n"),
   1057 		      sparc_opcodes[i].name, retval);
   1058 	      lose = 1;
   1059 	    }
   1060 	}
   1061     }
   1062 
   1063   if (lose)
   1064     as_fatal (_("Broken assembler.  No assembly attempted."));
   1065 
   1066   qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
   1067 	 sizeof (priv_reg_table[0]), cmp_reg_entry);
   1068   qsort (hpriv_reg_table, sizeof (hpriv_reg_table) / sizeof (hpriv_reg_table[0]),
   1069 	 sizeof (hpriv_reg_table[0]), cmp_reg_entry);
   1070   qsort (v9a_asr_table, sizeof (v9a_asr_table) / sizeof (v9a_asr_table[0]),
   1071 	 sizeof (v9a_asr_table[0]), cmp_reg_entry);
   1072 
   1073   /* If -bump, record the architecture level at which we start issuing
   1074      warnings.  The behaviour is different depending upon whether an
   1075      architecture was explicitly specified.  If it wasn't, we issue warnings
   1076      for all upwards bumps.  If it was, we don't start issuing warnings until
   1077      we need to bump beyond the requested architecture or when we bump between
   1078      conflicting architectures.  */
   1079 
   1080   if (warn_on_bump
   1081       && architecture_requested)
   1082     {
   1083       /* `max_architecture' records the requested architecture.
   1084 	 Issue warnings if we go above it.  */
   1085       warn_after_architecture = max_architecture;
   1086     }
   1087 
   1088   /* Find the highest architecture level that doesn't conflict with
   1089      the requested one.  */
   1090 
   1091   if (warn_on_bump
   1092       || !architecture_requested)
   1093   {
   1094     enum sparc_opcode_arch_val current_max_architecture
   1095       = max_architecture;
   1096 
   1097     for (max_architecture = SPARC_OPCODE_ARCH_MAX;
   1098 	 max_architecture > warn_after_architecture;
   1099 	 --max_architecture)
   1100       if (! SPARC_OPCODE_CONFLICT_P (max_architecture,
   1101 				     current_max_architecture))
   1102 	break;
   1103   }
   1104 
   1105   /* Prepare the tables of %-pseudo-ops.  */
   1106   {
   1107     struct priv_reg_entry *reg_tables[]
   1108       = {priv_reg_table, hpriv_reg_table, v9a_asr_table, NULL};
   1109     struct priv_reg_entry **reg_table;
   1110     int entry = 0;
   1111 
   1112     /* Add registers.  */
   1113     for (reg_table = reg_tables; reg_table[0]; reg_table++)
   1114       {
   1115         struct priv_reg_entry *reg;
   1116         for (reg = *reg_table; reg->name; reg++)
   1117           {
   1118             struct perc_entry *p = &perc_table[entry++];
   1119             p->type = perc_entry_reg;
   1120             p->name = reg->name;
   1121             p->len = strlen (reg->name);
   1122             p->reg = reg;
   1123           }
   1124       }
   1125 
   1126     /* Add %-pseudo-ops.  */
   1127     {
   1128       struct pop_entry *pop;
   1129 
   1130       for (pop = pop_table; pop->name; pop++)
   1131         {
   1132           struct perc_entry *p = &perc_table[entry++];
   1133           p->type = (pop->flags & F_POP_POSTFIX
   1134                      ? perc_entry_post_pop : perc_entry_imm_pop);
   1135           p->name = pop->name;
   1136           p->len = strlen (pop->name);
   1137           p->pop = pop;
   1138         }
   1139     }
   1140 
   1141     /* Last entry is the centinel.  */
   1142     perc_table[entry].type = perc_entry_none;
   1143 
   1144     qsort (perc_table, sizeof (perc_table) / sizeof (perc_table[0]),
   1145            sizeof (perc_table[0]), cmp_perc_entry);
   1146 
   1147   }
   1148 }
   1149 
   1150 /* Called after all assembly has been done.  */
   1151 
   1152 void
   1153 sparc_md_end (void)
   1154 {
   1155   unsigned long mach = bfd_mach_sparc;
   1156 #if defined(OBJ_ELF) && !defined(TE_SOLARIS)
   1157   int hwcaps, hwcaps2;
   1158 #endif
   1159 
   1160   if (sparc_arch_size == 64)
   1161     switch (current_architecture)
   1162       {
   1163       case SPARC_OPCODE_ARCH_V9A: mach = bfd_mach_sparc_v9a; break;
   1164       case SPARC_OPCODE_ARCH_V9B: mach = bfd_mach_sparc_v9b; break;
   1165       case SPARC_OPCODE_ARCH_V9C: mach = bfd_mach_sparc_v9c; break;
   1166       case SPARC_OPCODE_ARCH_V9D: mach = bfd_mach_sparc_v9d; break;
   1167       case SPARC_OPCODE_ARCH_V9E: mach = bfd_mach_sparc_v9e; break;
   1168       case SPARC_OPCODE_ARCH_V9V: mach = bfd_mach_sparc_v9v; break;
   1169       case SPARC_OPCODE_ARCH_V9M: mach = bfd_mach_sparc_v9m; break;
   1170       default: mach = bfd_mach_sparc_v9; break;
   1171       }
   1172   else
   1173     switch (current_architecture)
   1174       {
   1175       case SPARC_OPCODE_ARCH_SPARCLET: mach = bfd_mach_sparc_sparclet; break;
   1176       case SPARC_OPCODE_ARCH_V9: mach = bfd_mach_sparc_v8plus; break;
   1177       case SPARC_OPCODE_ARCH_V9A: mach = bfd_mach_sparc_v8plusa; break;
   1178       case SPARC_OPCODE_ARCH_V9B: mach = bfd_mach_sparc_v8plusb; break;
   1179       case SPARC_OPCODE_ARCH_V9C: mach = bfd_mach_sparc_v8plusc; break;
   1180       case SPARC_OPCODE_ARCH_V9D: mach = bfd_mach_sparc_v8plusd; break;
   1181       case SPARC_OPCODE_ARCH_V9E: mach = bfd_mach_sparc_v8pluse; break;
   1182       case SPARC_OPCODE_ARCH_V9V: mach = bfd_mach_sparc_v8plusv; break;
   1183       case SPARC_OPCODE_ARCH_V9M: mach = bfd_mach_sparc_v8plusm; break;
   1184       /* The sparclite is treated like a normal sparc.  Perhaps it shouldn't
   1185 	 be but for now it is (since that's the way it's always been
   1186 	 treated).  */
   1187       default: break;
   1188       }
   1189   bfd_set_arch_mach (stdoutput, bfd_arch_sparc, mach);
   1190 
   1191 #if defined(OBJ_ELF) && !defined(TE_SOLARIS)
   1192   hwcaps = hwcap_seen & U0xffffffff;
   1193   hwcaps2 = hwcap_seen >> 32;
   1194 
   1195   if (hwcaps)
   1196     bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_GNU, Tag_GNU_Sparc_HWCAPS, hwcaps);
   1197   if (hwcaps2)
   1198     bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_GNU, Tag_GNU_Sparc_HWCAPS2, hwcaps2);
   1199 #endif
   1200 }
   1201 
   1202 /* Return non-zero if VAL is in the range -(MAX+1) to MAX.  */
   1204 
   1205 static inline int
   1206 in_signed_range (bfd_signed_vma val, bfd_signed_vma max)
   1207 {
   1208   if (max <= 0)
   1209     abort ();
   1210   /* Sign-extend the value from the architecture word size, so that
   1211      0xffffffff is always considered -1 on sparc32.  */
   1212   if (sparc_arch_size == 32)
   1213     {
   1214       bfd_signed_vma sign = (bfd_signed_vma) 1 << 31;
   1215       val = ((val & U0xffffffff) ^ sign) - sign;
   1216     }
   1217   if (val > max)
   1218     return 0;
   1219   if (val < ~max)
   1220     return 0;
   1221   return 1;
   1222 }
   1223 
   1224 /* Return non-zero if VAL is in the range 0 to MAX.  */
   1225 
   1226 static inline int
   1227 in_unsigned_range (bfd_vma val, bfd_vma max)
   1228 {
   1229   if (val > max)
   1230     return 0;
   1231   return 1;
   1232 }
   1233 
   1234 /* Return non-zero if VAL is in the range -(MAX/2+1) to MAX.
   1235    (e.g. -15 to +31).  */
   1236 
   1237 static inline int
   1238 in_bitfield_range (bfd_signed_vma val, bfd_signed_vma max)
   1239 {
   1240   if (max <= 0)
   1241     abort ();
   1242   if (val > max)
   1243     return 0;
   1244   if (val < ~(max >> 1))
   1245     return 0;
   1246   return 1;
   1247 }
   1248 
   1249 static int
   1250 sparc_ffs (unsigned int mask)
   1251 {
   1252   int i;
   1253 
   1254   if (mask == 0)
   1255     return -1;
   1256 
   1257   for (i = 0; (mask & 1) == 0; ++i)
   1258     mask >>= 1;
   1259   return i;
   1260 }
   1261 
   1262 /* Implement big shift right.  */
   1263 static bfd_vma
   1264 BSR (bfd_vma val, int amount)
   1265 {
   1266   if (sizeof (bfd_vma) <= 4 && amount >= 32)
   1267     as_fatal (_("Support for 64-bit arithmetic not compiled in."));
   1268   return val >> amount;
   1269 }
   1270 
   1271 /* For communication between sparc_ip and get_expression.  */
   1273 static char *expr_end;
   1274 
   1275 /* Values for `special_case'.
   1276    Instructions that require wierd handling because they're longer than
   1277    4 bytes.  */
   1278 #define SPECIAL_CASE_NONE	0
   1279 #define	SPECIAL_CASE_SET	1
   1280 #define SPECIAL_CASE_SETSW	2
   1281 #define SPECIAL_CASE_SETX	3
   1282 /* FIXME: sparc-opc.c doesn't have necessary "S" trigger to enable this.  */
   1283 #define	SPECIAL_CASE_FDIV	4
   1284 
   1285 /* Bit masks of various insns.  */
   1286 #define NOP_INSN 0x01000000
   1287 #define OR_INSN 0x80100000
   1288 #define XOR_INSN 0x80180000
   1289 #define FMOVS_INSN 0x81A00020
   1290 #define SETHI_INSN 0x01000000
   1291 #define SLLX_INSN 0x81281000
   1292 #define SRA_INSN 0x81380000
   1293 
   1294 /* The last instruction to be assembled.  */
   1295 static const struct sparc_opcode *last_insn;
   1296 /* The assembled opcode of `last_insn'.  */
   1297 static unsigned long last_opcode;
   1298 
   1299 /* Handle the set and setuw synthetic instructions.  */
   1301 
   1302 static void
   1303 synthetize_setuw (const struct sparc_opcode *insn)
   1304 {
   1305   int need_hi22_p = 0;
   1306   int rd = (the_insn.opcode & RD (~0)) >> 25;
   1307 
   1308   if (the_insn.exp.X_op == O_constant)
   1309     {
   1310       if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
   1311 	{
   1312 	  if (sizeof (offsetT) > 4
   1313 	      && (the_insn.exp.X_add_number < 0
   1314 		  || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
   1315 	    as_warn (_("set: number not in 0..4294967295 range"));
   1316 	}
   1317       else
   1318 	{
   1319 	  if (sizeof (offsetT) > 4
   1320 	      && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
   1321 		  || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
   1322 	    as_warn (_("set: number not in -2147483648..4294967295 range"));
   1323 	  the_insn.exp.X_add_number = (int) the_insn.exp.X_add_number;
   1324 	}
   1325     }
   1326 
   1327   /* See if operand is absolute and small; skip sethi if so.  */
   1328   if (the_insn.exp.X_op != O_constant
   1329       || the_insn.exp.X_add_number >= (1 << 12)
   1330       || the_insn.exp.X_add_number < -(1 << 12))
   1331     {
   1332       the_insn.opcode = (SETHI_INSN | RD (rd)
   1333 			 | ((the_insn.exp.X_add_number >> 10)
   1334 			    & (the_insn.exp.X_op == O_constant
   1335 			       ? 0x3fffff : 0)));
   1336       the_insn.reloc = (the_insn.exp.X_op != O_constant
   1337 			? BFD_RELOC_HI22 : BFD_RELOC_NONE);
   1338       output_insn (insn, &the_insn);
   1339       need_hi22_p = 1;
   1340     }
   1341 
   1342   /* See if operand has no low-order bits; skip OR if so.  */
   1343   if (the_insn.exp.X_op != O_constant
   1344       || (need_hi22_p && (the_insn.exp.X_add_number & 0x3FF) != 0)
   1345       || ! need_hi22_p)
   1346     {
   1347       the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (rd) : 0)
   1348 			 | RD (rd) | IMMED
   1349 			 | (the_insn.exp.X_add_number
   1350 			    & (the_insn.exp.X_op != O_constant
   1351 			       ? 0 : need_hi22_p ? 0x3ff : 0x1fff)));
   1352       the_insn.reloc = (the_insn.exp.X_op != O_constant
   1353 			? BFD_RELOC_LO10 : BFD_RELOC_NONE);
   1354       output_insn (insn, &the_insn);
   1355     }
   1356 }
   1357 
   1358 /* Handle the setsw synthetic instruction.  */
   1359 
   1360 static void
   1361 synthetize_setsw (const struct sparc_opcode *insn)
   1362 {
   1363   int low32, rd, opc;
   1364 
   1365   rd = (the_insn.opcode & RD (~0)) >> 25;
   1366 
   1367   if (the_insn.exp.X_op != O_constant)
   1368     {
   1369       synthetize_setuw (insn);
   1370 
   1371       /* Need to sign extend it.  */
   1372       the_insn.opcode = (SRA_INSN | RS1 (rd) | RD (rd));
   1373       the_insn.reloc = BFD_RELOC_NONE;
   1374       output_insn (insn, &the_insn);
   1375       return;
   1376     }
   1377 
   1378   if (sizeof (offsetT) > 4
   1379       && (the_insn.exp.X_add_number < -(offsetT) U0x80000000
   1380 	  || the_insn.exp.X_add_number > (offsetT) U0xffffffff))
   1381     as_warn (_("setsw: number not in -2147483648..4294967295 range"));
   1382 
   1383   low32 = the_insn.exp.X_add_number;
   1384 
   1385   if (low32 >= 0)
   1386     {
   1387       synthetize_setuw (insn);
   1388       return;
   1389     }
   1390 
   1391   opc = OR_INSN;
   1392 
   1393   the_insn.reloc = BFD_RELOC_NONE;
   1394   /* See if operand is absolute and small; skip sethi if so.  */
   1395   if (low32 < -(1 << 12))
   1396     {
   1397       the_insn.opcode = (SETHI_INSN | RD (rd)
   1398 			 | (((~the_insn.exp.X_add_number) >> 10) & 0x3fffff));
   1399       output_insn (insn, &the_insn);
   1400       low32 = 0x1c00 | (low32 & 0x3ff);
   1401       opc = RS1 (rd) | XOR_INSN;
   1402     }
   1403 
   1404   the_insn.opcode = (opc | RD (rd) | IMMED
   1405 		     | (low32 & 0x1fff));
   1406   output_insn (insn, &the_insn);
   1407 }
   1408 
   1409 /* Handle the setx synthetic instruction.  */
   1410 
   1411 static void
   1412 synthetize_setx (const struct sparc_opcode *insn)
   1413 {
   1414   int upper32, lower32;
   1415   int tmpreg = (the_insn.opcode & RS1 (~0)) >> 14;
   1416   int dstreg = (the_insn.opcode & RD (~0)) >> 25;
   1417   int upper_dstreg;
   1418   int need_hh22_p = 0, need_hm10_p = 0, need_hi22_p = 0, need_lo10_p = 0;
   1419   int need_xor10_p = 0;
   1420 
   1421 #define SIGNEXT32(x) ((((x) & U0xffffffff) ^ U0x80000000) - U0x80000000)
   1422   lower32 = SIGNEXT32 (the_insn.exp.X_add_number);
   1423   upper32 = SIGNEXT32 (BSR (the_insn.exp.X_add_number, 32));
   1424 #undef SIGNEXT32
   1425 
   1426   upper_dstreg = tmpreg;
   1427   /* The tmp reg should not be the dst reg.  */
   1428   if (tmpreg == dstreg)
   1429     as_warn (_("setx: temporary register same as destination register"));
   1430 
   1431   /* ??? Obviously there are other optimizations we can do
   1432      (e.g. sethi+shift for 0x1f0000000) and perhaps we shouldn't be
   1433      doing some of these.  Later.  If you do change things, try to
   1434      change all of this to be table driven as well.  */
   1435   /* What to output depends on the number if it's constant.
   1436      Compute that first, then output what we've decided upon.  */
   1437   if (the_insn.exp.X_op != O_constant)
   1438     {
   1439       if (sparc_arch_size == 32)
   1440 	{
   1441 	  /* When arch size is 32, we want setx to be equivalent
   1442 	     to setuw for anything but constants.  */
   1443 	  the_insn.exp.X_add_number &= 0xffffffff;
   1444 	  synthetize_setuw (insn);
   1445 	  return;
   1446 	}
   1447       need_hh22_p = need_hm10_p = need_hi22_p = need_lo10_p = 1;
   1448       lower32 = 0;
   1449       upper32 = 0;
   1450     }
   1451   else
   1452     {
   1453       /* Reset X_add_number, we've extracted it as upper32/lower32.
   1454 	 Otherwise fixup_segment will complain about not being able to
   1455 	 write an 8 byte number in a 4 byte field.  */
   1456       the_insn.exp.X_add_number = 0;
   1457 
   1458       /* Only need hh22 if `or' insn can't handle constant.  */
   1459       if (upper32 < -(1 << 12) || upper32 >= (1 << 12))
   1460 	need_hh22_p = 1;
   1461 
   1462       /* Does bottom part (after sethi) have bits?  */
   1463       if ((need_hh22_p && (upper32 & 0x3ff) != 0)
   1464 	  /* No hh22, but does upper32 still have bits we can't set
   1465 	     from lower32?  */
   1466 	  || (! need_hh22_p && upper32 != 0 && upper32 != -1))
   1467 	need_hm10_p = 1;
   1468 
   1469       /* If the lower half is all zero, we build the upper half directly
   1470 	 into the dst reg.  */
   1471       if (lower32 != 0
   1472 	  /* Need lower half if number is zero or 0xffffffff00000000.  */
   1473 	  || (! need_hh22_p && ! need_hm10_p))
   1474 	{
   1475 	  /* No need for sethi if `or' insn can handle constant.  */
   1476 	  if (lower32 < -(1 << 12) || lower32 >= (1 << 12)
   1477 	      /* Note that we can't use a negative constant in the `or'
   1478 		 insn unless the upper 32 bits are all ones.  */
   1479 	      || (lower32 < 0 && upper32 != -1)
   1480 	      || (lower32 >= 0 && upper32 == -1))
   1481 	    need_hi22_p = 1;
   1482 
   1483 	  if (need_hi22_p && upper32 == -1)
   1484 	    need_xor10_p = 1;
   1485 
   1486 	  /* Does bottom part (after sethi) have bits?  */
   1487 	  else if ((need_hi22_p && (lower32 & 0x3ff) != 0)
   1488 		   /* No sethi.  */
   1489 		   || (! need_hi22_p && (lower32 & 0x1fff) != 0)
   1490 		   /* Need `or' if we didn't set anything else.  */
   1491 		   || (! need_hi22_p && ! need_hh22_p && ! need_hm10_p))
   1492 	    need_lo10_p = 1;
   1493 	}
   1494       else
   1495 	/* Output directly to dst reg if lower 32 bits are all zero.  */
   1496 	upper_dstreg = dstreg;
   1497     }
   1498 
   1499   if (!upper_dstreg && dstreg)
   1500     as_warn (_("setx: illegal temporary register g0"));
   1501 
   1502   if (need_hh22_p)
   1503     {
   1504       the_insn.opcode = (SETHI_INSN | RD (upper_dstreg)
   1505 			 | ((upper32 >> 10) & 0x3fffff));
   1506       the_insn.reloc = (the_insn.exp.X_op != O_constant
   1507 			? BFD_RELOC_SPARC_HH22 : BFD_RELOC_NONE);
   1508       output_insn (insn, &the_insn);
   1509     }
   1510 
   1511   if (need_hi22_p)
   1512     {
   1513       the_insn.opcode = (SETHI_INSN | RD (dstreg)
   1514 			 | (((need_xor10_p ? ~lower32 : lower32)
   1515 			     >> 10) & 0x3fffff));
   1516       the_insn.reloc = (the_insn.exp.X_op != O_constant
   1517 			? BFD_RELOC_SPARC_LM22 : BFD_RELOC_NONE);
   1518       output_insn (insn, &the_insn);
   1519     }
   1520 
   1521   if (need_hm10_p)
   1522     {
   1523       the_insn.opcode = (OR_INSN
   1524 			 | (need_hh22_p ? RS1 (upper_dstreg) : 0)
   1525 			 | RD (upper_dstreg)
   1526 			 | IMMED
   1527 			 | (upper32 & (need_hh22_p ? 0x3ff : 0x1fff)));
   1528       the_insn.reloc = (the_insn.exp.X_op != O_constant
   1529 			? BFD_RELOC_SPARC_HM10 : BFD_RELOC_NONE);
   1530       output_insn (insn, &the_insn);
   1531     }
   1532 
   1533   if (need_lo10_p)
   1534     {
   1535       /* FIXME: One nice optimization to do here is to OR the low part
   1536 	 with the highpart if hi22 isn't needed and the low part is
   1537 	 positive.  */
   1538       the_insn.opcode = (OR_INSN | (need_hi22_p ? RS1 (dstreg) : 0)
   1539 			 | RD (dstreg)
   1540 			 | IMMED
   1541 			 | (lower32 & (need_hi22_p ? 0x3ff : 0x1fff)));
   1542       the_insn.reloc = (the_insn.exp.X_op != O_constant
   1543 			? BFD_RELOC_LO10 : BFD_RELOC_NONE);
   1544       output_insn (insn, &the_insn);
   1545     }
   1546 
   1547   /* If we needed to build the upper part, shift it into place.  */
   1548   if (need_hh22_p || need_hm10_p)
   1549     {
   1550       the_insn.opcode = (SLLX_INSN | RS1 (upper_dstreg) | RD (upper_dstreg)
   1551 			 | IMMED | 32);
   1552       the_insn.reloc = BFD_RELOC_NONE;
   1553       output_insn (insn, &the_insn);
   1554     }
   1555 
   1556   /* To get -1 in upper32, we do sethi %hi(~x), r; xor r, -0x400 | x, r.  */
   1557   if (need_xor10_p)
   1558     {
   1559       the_insn.opcode = (XOR_INSN | RS1 (dstreg) | RD (dstreg) | IMMED
   1560 			 | 0x1c00 | (lower32 & 0x3ff));
   1561       the_insn.reloc = BFD_RELOC_NONE;
   1562       output_insn (insn, &the_insn);
   1563     }
   1564 
   1565   /* If we needed to build both upper and lower parts, OR them together.  */
   1566   else if ((need_hh22_p || need_hm10_p) && (need_hi22_p || need_lo10_p))
   1567     {
   1568       the_insn.opcode = (OR_INSN | RS1 (dstreg) | RS2 (upper_dstreg)
   1569 			 | RD (dstreg));
   1570       the_insn.reloc = BFD_RELOC_NONE;
   1571       output_insn (insn, &the_insn);
   1572     }
   1573 }
   1574 
   1575 /* Main entry point to assemble one instruction.  */
   1577 
   1578 void
   1579 md_assemble (char *str)
   1580 {
   1581   const struct sparc_opcode *insn;
   1582   int special_case;
   1583 
   1584   know (str);
   1585   special_case = sparc_ip (str, &insn);
   1586   if (insn == NULL)
   1587     return;
   1588 
   1589   /* We warn about attempts to put a floating point branch in a delay slot,
   1590      unless the delay slot has been annulled.  */
   1591   if (last_insn != NULL
   1592       && (insn->flags & F_FBR) != 0
   1593       && (last_insn->flags & F_DELAYED) != 0
   1594       /* ??? This test isn't completely accurate.  We assume anything with
   1595 	 F_{UNBR,CONDBR,FBR} set is annullable.  */
   1596       && ((last_insn->flags & (F_UNBR | F_CONDBR | F_FBR)) == 0
   1597 	  || (last_opcode & ANNUL) == 0))
   1598     as_warn (_("FP branch in delay slot"));
   1599 
   1600   /* SPARC before v8 requires a nop instruction between a floating
   1601      point instruction and a floating point branch.  SPARCv8 requires
   1602      a nop only immediately after FPop2 (fcmp*) instructions.
   1603      We insert one automatically, with a warning.
   1604    */
   1605   if (last_insn != NULL
   1606       && (insn->flags & F_FBR) != 0
   1607       && (last_insn->flags & F_FLOAT) != 0
   1608       && (max_architecture < SPARC_OPCODE_ARCH_V8 ||
   1609           (max_architecture < SPARC_OPCODE_ARCH_V9 &&
   1610            strncmp(last_insn->name, "fcmp", 4) == 0)))
   1611     {
   1612       struct sparc_it nop_insn;
   1613 
   1614       nop_insn.opcode = NOP_INSN;
   1615       nop_insn.reloc = BFD_RELOC_NONE;
   1616       output_insn (insn, &nop_insn);
   1617       as_warn (_("FP branch preceded by FP instruction; NOP inserted"));
   1618     }
   1619 
   1620   switch (special_case)
   1621     {
   1622     case SPECIAL_CASE_NONE:
   1623       /* Normal insn.  */
   1624       output_insn (insn, &the_insn);
   1625       break;
   1626 
   1627     case SPECIAL_CASE_SETSW:
   1628       synthetize_setsw (insn);
   1629       break;
   1630 
   1631     case SPECIAL_CASE_SET:
   1632       synthetize_setuw (insn);
   1633       break;
   1634 
   1635     case SPECIAL_CASE_SETX:
   1636       synthetize_setx (insn);
   1637       break;
   1638 
   1639     case SPECIAL_CASE_FDIV:
   1640       {
   1641 	int rd = (the_insn.opcode >> 25) & 0x1f;
   1642 
   1643 	output_insn (insn, &the_insn);
   1644 
   1645 	/* According to information leaked from Sun, the "fdiv" instructions
   1646 	   on early SPARC machines would produce incorrect results sometimes.
   1647 	   The workaround is to add an fmovs of the destination register to
   1648 	   itself just after the instruction.  This was true on machines
   1649 	   with Weitek 1165 float chips, such as the Sun-4/260 and /280.  */
   1650 	gas_assert (the_insn.reloc == BFD_RELOC_NONE);
   1651 	the_insn.opcode = FMOVS_INSN | rd | RD (rd);
   1652 	output_insn (insn, &the_insn);
   1653 	return;
   1654       }
   1655 
   1656     default:
   1657       as_fatal (_("failed special case insn sanity check"));
   1658     }
   1659 }
   1660 
   1661 static const char *
   1662 get_hwcap_name (bfd_uint64_t mask)
   1663 {
   1664   if (mask & HWCAP_MUL32)
   1665     return "mul32";
   1666   if (mask & HWCAP_DIV32)
   1667     return "div32";
   1668   if (mask & HWCAP_FSMULD)
   1669     return "fsmuld";
   1670   if (mask & HWCAP_V8PLUS)
   1671     return "v8plus";
   1672   if (mask & HWCAP_POPC)
   1673     return "popc";
   1674   if (mask & HWCAP_VIS)
   1675     return "vis";
   1676   if (mask & HWCAP_VIS2)
   1677     return "vis2";
   1678   if (mask & HWCAP_ASI_BLK_INIT)
   1679     return "ASIBlkInit";
   1680   if (mask & HWCAP_FMAF)
   1681     return "fmaf";
   1682   if (mask & HWCAP_VIS3)
   1683     return "vis3";
   1684   if (mask & HWCAP_HPC)
   1685     return "hpc";
   1686   if (mask & HWCAP_RANDOM)
   1687     return "random";
   1688   if (mask & HWCAP_TRANS)
   1689     return "trans";
   1690   if (mask & HWCAP_FJFMAU)
   1691     return "fjfmau";
   1692   if (mask & HWCAP_IMA)
   1693     return "ima";
   1694   if (mask & HWCAP_ASI_CACHE_SPARING)
   1695     return "cspare";
   1696   if (mask & HWCAP_AES)
   1697     return "aes";
   1698   if (mask & HWCAP_DES)
   1699     return "des";
   1700   if (mask & HWCAP_KASUMI)
   1701     return "kasumi";
   1702   if (mask & HWCAP_CAMELLIA)
   1703     return "camellia";
   1704   if (mask & HWCAP_MD5)
   1705     return "md5";
   1706   if (mask & HWCAP_SHA1)
   1707     return "sha1";
   1708   if (mask & HWCAP_SHA256)
   1709     return "sha256";
   1710   if (mask & HWCAP_SHA512)
   1711     return "sha512";
   1712   if (mask & HWCAP_MPMUL)
   1713     return "mpmul";
   1714   if (mask & HWCAP_MONT)
   1715     return "mont";
   1716   if (mask & HWCAP_PAUSE)
   1717     return "pause";
   1718   if (mask & HWCAP_CBCOND)
   1719     return "cbcond";
   1720   if (mask & HWCAP_CRC32C)
   1721     return "crc32c";
   1722 
   1723   mask = mask >> 32;
   1724   if (mask & HWCAP2_FJATHPLUS)
   1725     return "fjathplus";
   1726   if (mask & HWCAP2_VIS3B)
   1727     return "vis3b";
   1728   if (mask & HWCAP2_ADP)
   1729     return "adp";
   1730   if (mask & HWCAP2_SPARC5)
   1731     return "sparc5";
   1732   if (mask & HWCAP2_MWAIT)
   1733     return "mwait";
   1734   if (mask & HWCAP2_XMPMUL)
   1735     return "xmpmul";
   1736   if (mask & HWCAP2_XMONT)
   1737     return "xmont";
   1738   if (mask & HWCAP2_NSEC)
   1739     return "nsec";
   1740 
   1741   return "UNKNOWN";
   1742 }
   1743 
   1744 /* Subroutine of md_assemble to do the actual parsing.  */
   1745 
   1746 static int
   1747 sparc_ip (char *str, const struct sparc_opcode **pinsn)
   1748 {
   1749   const char *error_message = "";
   1750   char *s;
   1751   const char *args;
   1752   char c;
   1753   const struct sparc_opcode *insn;
   1754   char *argsStart;
   1755   unsigned long opcode;
   1756   unsigned int mask = 0;
   1757   int match = 0;
   1758   int comma = 0;
   1759   int v9_arg_p;
   1760   int special_case = SPECIAL_CASE_NONE;
   1761 
   1762   s = str;
   1763   if (ISLOWER (*s))
   1764     {
   1765       do
   1766 	++s;
   1767       while (ISLOWER (*s) || ISDIGIT (*s) || *s == '_');
   1768     }
   1769 
   1770   switch (*s)
   1771     {
   1772     case '\0':
   1773       break;
   1774 
   1775     case ',':
   1776       comma = 1;
   1777       /* Fall through.  */
   1778 
   1779     case ' ':
   1780       *s++ = '\0';
   1781       break;
   1782 
   1783     default:
   1784       as_bad (_("Unknown opcode: `%s'"), str);
   1785       *pinsn = NULL;
   1786       return special_case;
   1787     }
   1788   insn = (struct sparc_opcode *) hash_find (op_hash, str);
   1789   *pinsn = insn;
   1790   if (insn == NULL)
   1791     {
   1792       as_bad (_("Unknown opcode: `%s'"), str);
   1793       return special_case;
   1794     }
   1795   if (comma)
   1796     {
   1797       *--s = ',';
   1798     }
   1799 
   1800   argsStart = s;
   1801   for (;;)
   1802     {
   1803       opcode = insn->match;
   1804       memset (&the_insn, '\0', sizeof (the_insn));
   1805       the_insn.reloc = BFD_RELOC_NONE;
   1806       v9_arg_p = 0;
   1807 
   1808       /* Build the opcode, checking as we go to make sure that the
   1809          operands match.  */
   1810       for (args = insn->args;; ++args)
   1811 	{
   1812 	  switch (*args)
   1813 	    {
   1814 	    case 'K':
   1815 	      {
   1816 		int kmask = 0;
   1817 
   1818 		/* Parse a series of masks.  */
   1819 		if (*s == '#')
   1820 		  {
   1821 		    while (*s == '#')
   1822 		      {
   1823 			int jmask;
   1824 
   1825 			if (! parse_keyword_arg (sparc_encode_membar, &s,
   1826 						 &jmask))
   1827 			  {
   1828 			    error_message = _(": invalid membar mask name");
   1829 			    goto error;
   1830 			  }
   1831 			kmask |= jmask;
   1832 			while (*s == ' ')
   1833 			  ++s;
   1834 			if (*s == '|' || *s == '+')
   1835 			  ++s;
   1836 			while (*s == ' ')
   1837 			  ++s;
   1838 		      }
   1839 		  }
   1840 		else
   1841 		  {
   1842 		    if (! parse_const_expr_arg (&s, &kmask))
   1843 		      {
   1844 			error_message = _(": invalid membar mask expression");
   1845 			goto error;
   1846 		      }
   1847 		    if (kmask < 0 || kmask > 127)
   1848 		      {
   1849 			error_message = _(": invalid membar mask number");
   1850 			goto error;
   1851 		      }
   1852 		  }
   1853 
   1854 		opcode |= MEMBAR (kmask);
   1855 		continue;
   1856 	      }
   1857 
   1858 	    case '3':
   1859 	      {
   1860 		int smask = 0;
   1861 
   1862 		if (! parse_const_expr_arg (&s, &smask))
   1863 		  {
   1864 		    error_message = _(": invalid siam mode expression");
   1865 		    goto error;
   1866 		  }
   1867 		if (smask < 0 || smask > 7)
   1868 		  {
   1869 		    error_message = _(": invalid siam mode number");
   1870 		    goto error;
   1871 		  }
   1872 		opcode |= smask;
   1873 		continue;
   1874 	      }
   1875 
   1876 	    case '*':
   1877 	      {
   1878 		int fcn = 0;
   1879 
   1880 		/* Parse a prefetch function.  */
   1881 		if (*s == '#')
   1882 		  {
   1883 		    if (! parse_keyword_arg (sparc_encode_prefetch, &s, &fcn))
   1884 		      {
   1885 			error_message = _(": invalid prefetch function name");
   1886 			goto error;
   1887 		      }
   1888 		  }
   1889 		else
   1890 		  {
   1891 		    if (! parse_const_expr_arg (&s, &fcn))
   1892 		      {
   1893 			error_message = _(": invalid prefetch function expression");
   1894 			goto error;
   1895 		      }
   1896 		    if (fcn < 0 || fcn > 31)
   1897 		      {
   1898 			error_message = _(": invalid prefetch function number");
   1899 			goto error;
   1900 		      }
   1901 		  }
   1902 		opcode |= RD (fcn);
   1903 		continue;
   1904 	      }
   1905 
   1906 	    case '!':
   1907 	    case '?':
   1908 	      /* Parse a sparc64 privileged register.  */
   1909 	      if (*s == '%')
   1910 		{
   1911 		  struct priv_reg_entry *p;
   1912 		  unsigned int len = 9999999; /* Init to make gcc happy.  */
   1913 
   1914 		  s += 1;
   1915                   for (p = priv_reg_table; p->name; p++)
   1916                     if (p->name[0] == s[0])
   1917                       {
   1918                         len = strlen (p->name);
   1919                         if (strncmp (p->name, s, len) == 0)
   1920                           break;
   1921                       }
   1922 
   1923 		  if (!p->name)
   1924 		    {
   1925 		      error_message = _(": unrecognizable privileged register");
   1926 		      goto error;
   1927 		    }
   1928 
   1929                   if (((opcode >> (*args == '?' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
   1930                     {
   1931                       error_message = _(": unrecognizable privileged register");
   1932                       goto error;
   1933                     }
   1934 
   1935 		  s += len;
   1936 		  continue;
   1937 		}
   1938 	      else
   1939 		{
   1940 		  error_message = _(": unrecognizable privileged register");
   1941 		  goto error;
   1942 		}
   1943 
   1944 	    case '$':
   1945 	    case '%':
   1946 	      /* Parse a sparc64 hyperprivileged register.  */
   1947 	      if (*s == '%')
   1948 		{
   1949 		  struct priv_reg_entry *p;
   1950 		  unsigned int len = 9999999; /* Init to make gcc happy.  */
   1951 
   1952 		  s += 1;
   1953                   for (p = hpriv_reg_table; p->name; p++)
   1954                     if (p->name[0] == s[0])
   1955                       {
   1956                         len = strlen (p->name);
   1957                         if (strncmp (p->name, s, len) == 0)
   1958                           break;
   1959                       }
   1960 
   1961 		  if (!p->name)
   1962 		    {
   1963 		      error_message = _(": unrecognizable hyperprivileged register");
   1964 		      goto error;
   1965 		    }
   1966 
   1967                   if (((opcode >> (*args == '$' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
   1968                     {
   1969                       error_message = _(": unrecognizable hyperprivileged register");
   1970                       goto error;
   1971                     }
   1972 
   1973                   s += len;
   1974 		  continue;
   1975 		}
   1976 	      else
   1977 		{
   1978 		  error_message = _(": unrecognizable hyperprivileged register");
   1979 		  goto error;
   1980 		}
   1981 
   1982 	    case '_':
   1983 	    case '/':
   1984 	      /* Parse a v9a or later ancillary state register.  */
   1985 	      if (*s == '%')
   1986 		{
   1987 		  struct priv_reg_entry *p;
   1988 		  unsigned int len = 9999999; /* Init to make gcc happy.  */
   1989 
   1990 		  s += 1;
   1991                   for (p = v9a_asr_table; p->name; p++)
   1992                     if (p->name[0] == s[0])
   1993                       {
   1994                         len = strlen (p->name);
   1995                         if (strncmp (p->name, s, len) == 0)
   1996                           break;
   1997                       }
   1998 
   1999 		  if (!p->name)
   2000 		    {
   2001 		      error_message = _(": unrecognizable ancillary state register");
   2002 		      goto error;
   2003 		    }
   2004 
   2005                   if (((opcode >> (*args == '/' ? 14 : 25)) & 0x1f) != (unsigned) p->regnum)
   2006                      {
   2007                        error_message = _(": unrecognizable ancillary state register");
   2008                        goto error;
   2009                      }
   2010 
   2011 		  s += len;
   2012 		  continue;
   2013 		}
   2014 	      else
   2015 		{
   2016 		  error_message = _(": unrecognizable ancillary state register");
   2017 		  goto error;
   2018 		}
   2019 
   2020 	    case 'M':
   2021 	    case 'm':
   2022 	      if (strncmp (s, "%asr", 4) == 0)
   2023 		{
   2024 		  s += 4;
   2025 
   2026 		  if (ISDIGIT (*s))
   2027 		    {
   2028 		      long num = 0;
   2029 
   2030 		      while (ISDIGIT (*s))
   2031 			{
   2032 			  num = num * 10 + *s - '0';
   2033 			  ++s;
   2034 			}
   2035 
   2036                       /* We used to check here for the asr number to
   2037                          be between 16 and 31 in V9 and later, as
   2038                          mandated by the section C.1.1 "Register
   2039                          Names" in the SPARC spec.  However, we
   2040                          decided to remove this restriction as a) it
   2041                          introduces problems when new V9 asr registers
   2042                          are introduced, b) the Solaris assembler
   2043                          doesn't implement this restriction and c) the
   2044                          restriction will go away in future revisions
   2045                          of the Oracle SPARC Architecture.  */
   2046 
   2047                       if (num < 0 || 31 < num)
   2048                         {
   2049                           error_message = _(": asr number must be between 0 and 31");
   2050                           goto error;
   2051                         }
   2052 
   2053 		      opcode |= (*args == 'M' ? RS1 (num) : RD (num));
   2054 		      continue;
   2055 		    }
   2056 		  else
   2057 		    {
   2058 		      error_message = _(": expecting %asrN");
   2059 		      goto error;
   2060 		    }
   2061 		} /* if %asr  */
   2062 	      break;
   2063 
   2064 	    case 'I':
   2065 	      the_insn.reloc = BFD_RELOC_SPARC_11;
   2066 	      goto immediate;
   2067 
   2068 	    case 'j':
   2069 	      the_insn.reloc = BFD_RELOC_SPARC_10;
   2070 	      goto immediate;
   2071 
   2072 	    case ')':
   2073 	      if (*s == ' ')
   2074 		s++;
   2075 	      if ((s[0] == '0' && s[1] == 'x' && ISXDIGIT (s[2]))
   2076 		  || ISDIGIT (*s))
   2077 		{
   2078 		  long num = 0;
   2079 
   2080 		  if (s[0] == '0' && s[1] == 'x')
   2081 		    {
   2082 		      s += 2;
   2083 		      while (ISXDIGIT (*s))
   2084 			{
   2085 			  num <<= 4;
   2086 			  num |= hex_value (*s);
   2087 			  ++s;
   2088 			}
   2089 		    }
   2090 		  else
   2091 		    {
   2092 		      while (ISDIGIT (*s))
   2093 			{
   2094 			  num = num * 10 + *s - '0';
   2095 			  ++s;
   2096 			}
   2097 		    }
   2098 		  if (num < 0 || num > 31)
   2099 		    {
   2100 		      error_message = _(": crypto immediate must be between 0 and 31");
   2101 		      goto error;
   2102 		    }
   2103 
   2104 		  opcode |= RS3 (num);
   2105 		  continue;
   2106 		}
   2107 	      else
   2108 		{
   2109 		  error_message = _(": expecting crypto immediate");
   2110 		  goto error;
   2111 		}
   2112 
   2113 	    case 'X':
   2114 	      /* V8 systems don't understand BFD_RELOC_SPARC_5.  */
   2115 	      if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
   2116 		the_insn.reloc = BFD_RELOC_SPARC_5;
   2117 	      else
   2118 		the_insn.reloc = BFD_RELOC_SPARC13;
   2119 	      /* These fields are unsigned, but for upward compatibility,
   2120 		 allow negative values as well.  */
   2121 	      goto immediate;
   2122 
   2123 	    case 'Y':
   2124 	      /* V8 systems don't understand BFD_RELOC_SPARC_6.  */
   2125 	      if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
   2126 		the_insn.reloc = BFD_RELOC_SPARC_6;
   2127 	      else
   2128 		the_insn.reloc = BFD_RELOC_SPARC13;
   2129 	      /* These fields are unsigned, but for upward compatibility,
   2130 		 allow negative values as well.  */
   2131 	      goto immediate;
   2132 
   2133 	    case 'k':
   2134 	      the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
   2135 	      the_insn.pcrel = 1;
   2136 	      goto immediate;
   2137 
   2138 	    case '=':
   2139 	      the_insn.reloc = /* RELOC_WDISP2_8 */ BFD_RELOC_SPARC_WDISP10;
   2140 	      the_insn.pcrel = 1;
   2141 	      goto immediate;
   2142 
   2143 	    case 'G':
   2144 	      the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
   2145 	      the_insn.pcrel = 1;
   2146 	      goto immediate;
   2147 
   2148 	    case 'N':
   2149 	      if (*s == 'p' && s[1] == 'n')
   2150 		{
   2151 		  s += 2;
   2152 		  continue;
   2153 		}
   2154 	      break;
   2155 
   2156 	    case 'T':
   2157 	      if (*s == 'p' && s[1] == 't')
   2158 		{
   2159 		  s += 2;
   2160 		  continue;
   2161 		}
   2162 	      break;
   2163 
   2164 	    case 'z':
   2165 	      if (*s == ' ')
   2166 		{
   2167 		  ++s;
   2168 		}
   2169 	      if ((strncmp (s, "%icc", 4) == 0)
   2170                   || (sparc_arch_size == 32 && strncmp (s, "%ncc", 4) == 0))
   2171 		{
   2172 		  s += 4;
   2173 		  continue;
   2174 		}
   2175 	      break;
   2176 
   2177 	    case 'Z':
   2178 	      if (*s == ' ')
   2179 		{
   2180 		  ++s;
   2181 		}
   2182               if ((strncmp (s, "%xcc", 4) == 0)
   2183                   || (sparc_arch_size == 64 && strncmp (s, "%ncc", 4) == 0))
   2184 		{
   2185 		  s += 4;
   2186 		  continue;
   2187 		}
   2188 	      break;
   2189 
   2190 	    case '6':
   2191 	      if (*s == ' ')
   2192 		{
   2193 		  ++s;
   2194 		}
   2195 	      if (strncmp (s, "%fcc0", 5) == 0)
   2196 		{
   2197 		  s += 5;
   2198 		  continue;
   2199 		}
   2200 	      break;
   2201 
   2202 	    case '7':
   2203 	      if (*s == ' ')
   2204 		{
   2205 		  ++s;
   2206 		}
   2207 	      if (strncmp (s, "%fcc1", 5) == 0)
   2208 		{
   2209 		  s += 5;
   2210 		  continue;
   2211 		}
   2212 	      break;
   2213 
   2214 	    case '8':
   2215 	      if (*s == ' ')
   2216 		{
   2217 		  ++s;
   2218 		}
   2219 	      if (strncmp (s, "%fcc2", 5) == 0)
   2220 		{
   2221 		  s += 5;
   2222 		  continue;
   2223 		}
   2224 	      break;
   2225 
   2226 	    case '9':
   2227 	      if (*s == ' ')
   2228 		{
   2229 		  ++s;
   2230 		}
   2231 	      if (strncmp (s, "%fcc3", 5) == 0)
   2232 		{
   2233 		  s += 5;
   2234 		  continue;
   2235 		}
   2236 	      break;
   2237 
   2238 	    case 'P':
   2239 	      if (strncmp (s, "%pc", 3) == 0)
   2240 		{
   2241 		  s += 3;
   2242 		  continue;
   2243 		}
   2244 	      break;
   2245 
   2246 	    case 'W':
   2247 	      if (strncmp (s, "%tick", 5) == 0)
   2248 		{
   2249 		  s += 5;
   2250 		  continue;
   2251 		}
   2252 	      break;
   2253 
   2254 	    case '\0':		/* End of args.  */
   2255 	      if (s[0] == ',' && s[1] == '%')
   2256 		{
   2257 		  char *s1;
   2258 		  int npar = 0;
   2259                   const struct perc_entry *p;
   2260 
   2261                   for (p = perc_table; p->type != perc_entry_none; p++)
   2262                     if ((p->type == perc_entry_post_pop || p->type == perc_entry_reg)
   2263                         && strncmp (s + 2, p->name, p->len) == 0)
   2264                       break;
   2265                   if (p->type == perc_entry_none || p->type == perc_entry_reg)
   2266                     break;
   2267 
   2268 		  if (s[p->len + 2] != '(')
   2269 		    {
   2270 		      as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
   2271 		      return special_case;
   2272 		    }
   2273 
   2274 		  if (! (p->pop->flags & F_POP_TLS_CALL)
   2275                       && the_insn.reloc != BFD_RELOC_NONE)
   2276 		    {
   2277 		      as_bad (_("Illegal operands: %%%s cannot be used together with other relocs in the insn ()"),
   2278 			      p->name);
   2279 		      return special_case;
   2280 		    }
   2281 
   2282 		  if ((p->pop->flags & F_POP_TLS_CALL)
   2283 		      && (the_insn.reloc != BFD_RELOC_32_PCREL_S2
   2284 			  || the_insn.exp.X_add_number != 0
   2285 			  || the_insn.exp.X_add_symbol
   2286 			     != symbol_find_or_make ("__tls_get_addr")))
   2287 		    {
   2288 		      as_bad (_("Illegal operands: %%%s can be only used with call __tls_get_addr"),
   2289 			      p->name);
   2290 		      return special_case;
   2291 		    }
   2292 
   2293 		  the_insn.reloc = p->pop->reloc;
   2294 		  memset (&the_insn.exp, 0, sizeof (the_insn.exp));
   2295 		  s += p->len + 3;
   2296 
   2297 		  for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
   2298 		    if (*s1 == '(')
   2299 		      npar++;
   2300 		    else if (*s1 == ')')
   2301 		      {
   2302 			if (!npar)
   2303 			  break;
   2304 			npar--;
   2305 		      }
   2306 
   2307 		  if (*s1 != ')')
   2308 		    {
   2309 		      as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
   2310 		      return special_case;
   2311 		    }
   2312 
   2313 		  *s1 = '\0';
   2314 		  (void) get_expression (s);
   2315 		  *s1 = ')';
   2316 		  s = s1 + 1;
   2317 		}
   2318 	      if (*s == '\0')
   2319 		match = 1;
   2320 	      break;
   2321 
   2322 	    case '+':
   2323 	      if (*s == '+')
   2324 		{
   2325 		  ++s;
   2326 		  continue;
   2327 		}
   2328 	      if (*s == '-')
   2329 		{
   2330 		  continue;
   2331 		}
   2332 	      break;
   2333 
   2334 	    case '[':		/* These must match exactly.  */
   2335 	    case ']':
   2336 	    case ',':
   2337 	    case ' ':
   2338 	      if (*s++ == *args)
   2339 		continue;
   2340 	      break;
   2341 
   2342 	    case '#':		/* Must be at least one digit.  */
   2343 	      if (ISDIGIT (*s++))
   2344 		{
   2345 		  while (ISDIGIT (*s))
   2346 		    {
   2347 		      ++s;
   2348 		    }
   2349 		  continue;
   2350 		}
   2351 	      break;
   2352 
   2353 	    case 'C':		/* Coprocessor state register.  */
   2354 	      if (strncmp (s, "%csr", 4) == 0)
   2355 		{
   2356 		  s += 4;
   2357 		  continue;
   2358 		}
   2359 	      break;
   2360 
   2361 	    case 'b':		/* Next operand is a coprocessor register.  */
   2362 	    case 'c':
   2363 	    case 'D':
   2364 	      if (*s++ == '%' && *s++ == 'c' && ISDIGIT (*s))
   2365 		{
   2366 		  mask = *s++;
   2367 		  if (ISDIGIT (*s))
   2368 		    {
   2369 		      mask = 10 * (mask - '0') + (*s++ - '0');
   2370 		      if (mask >= 32)
   2371 			{
   2372 			  break;
   2373 			}
   2374 		    }
   2375 		  else
   2376 		    {
   2377 		      mask -= '0';
   2378 		    }
   2379 		  switch (*args)
   2380 		    {
   2381 
   2382 		    case 'b':
   2383 		      opcode |= mask << 14;
   2384 		      continue;
   2385 
   2386 		    case 'c':
   2387 		      opcode |= mask;
   2388 		      continue;
   2389 
   2390 		    case 'D':
   2391 		      opcode |= mask << 25;
   2392 		      continue;
   2393 		    }
   2394 		}
   2395 	      break;
   2396 
   2397 	    case 'r':		/* next operand must be a register */
   2398 	    case 'O':
   2399 	    case '1':
   2400 	    case '2':
   2401 	    case 'd':
   2402 	      if (*s++ == '%')
   2403 		{
   2404 		  switch (c = *s++)
   2405 		    {
   2406 
   2407 		    case 'f':	/* frame pointer */
   2408 		      if (*s++ == 'p')
   2409 			{
   2410 			  mask = 0x1e;
   2411 			  break;
   2412 			}
   2413 		      goto error;
   2414 
   2415 		    case 'g':	/* global register */
   2416 		      c = *s++;
   2417 		      if (isoctal (c))
   2418 			{
   2419 			  mask = c - '0';
   2420 			  break;
   2421 			}
   2422 		      goto error;
   2423 
   2424 		    case 'i':	/* in register */
   2425 		      c = *s++;
   2426 		      if (isoctal (c))
   2427 			{
   2428 			  mask = c - '0' + 24;
   2429 			  break;
   2430 			}
   2431 		      goto error;
   2432 
   2433 		    case 'l':	/* local register */
   2434 		      c = *s++;
   2435 		      if (isoctal (c))
   2436 			{
   2437 			  mask = (c - '0' + 16);
   2438 			  break;
   2439 			}
   2440 		      goto error;
   2441 
   2442 		    case 'o':	/* out register */
   2443 		      c = *s++;
   2444 		      if (isoctal (c))
   2445 			{
   2446 			  mask = (c - '0' + 8);
   2447 			  break;
   2448 			}
   2449 		      goto error;
   2450 
   2451 		    case 's':	/* stack pointer */
   2452 		      if (*s++ == 'p')
   2453 			{
   2454 			  mask = 0xe;
   2455 			  break;
   2456 			}
   2457 		      goto error;
   2458 
   2459 		    case 'r':	/* any register */
   2460 		      if (!ISDIGIT ((c = *s++)))
   2461 			{
   2462 			  goto error;
   2463 			}
   2464 		      /* FALLTHROUGH */
   2465 		    case '0':
   2466 		    case '1':
   2467 		    case '2':
   2468 		    case '3':
   2469 		    case '4':
   2470 		    case '5':
   2471 		    case '6':
   2472 		    case '7':
   2473 		    case '8':
   2474 		    case '9':
   2475 		      if (ISDIGIT (*s))
   2476 			{
   2477 			  if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
   2478 			    {
   2479 			      goto error;
   2480 			    }
   2481 			}
   2482 		      else
   2483 			{
   2484 			  c -= '0';
   2485 			}
   2486 		      mask = c;
   2487 		      break;
   2488 
   2489 		    default:
   2490 		      goto error;
   2491 		    }
   2492 
   2493 		  if ((mask & ~1) == 2 && sparc_arch_size == 64
   2494 		      && no_undeclared_regs && ! globals[mask])
   2495 		    as_bad (_("detected global register use not covered by .register pseudo-op"));
   2496 
   2497 		  /* Got the register, now figure out where
   2498 		     it goes in the opcode.  */
   2499 		  switch (*args)
   2500 		    {
   2501 		    case '1':
   2502 		      opcode |= mask << 14;
   2503 		      continue;
   2504 
   2505 		    case '2':
   2506 		      opcode |= mask;
   2507 		      continue;
   2508 
   2509 		    case 'd':
   2510 		      opcode |= mask << 25;
   2511 		      continue;
   2512 
   2513 		    case 'r':
   2514 		      opcode |= (mask << 25) | (mask << 14);
   2515 		      continue;
   2516 
   2517 		    case 'O':
   2518 		      opcode |= (mask << 25) | (mask << 0);
   2519 		      continue;
   2520 		    }
   2521 		}
   2522 	      break;
   2523 
   2524 	    case 'e':		/* next operand is a floating point register */
   2525 	    case 'v':
   2526 	    case 'V':
   2527 
   2528 	    case 'f':
   2529 	    case 'B':
   2530 	    case 'R':
   2531 
   2532 	    case '4':
   2533 	    case '5':
   2534 
   2535 	    case 'g':
   2536 	    case 'H':
   2537 	    case 'J':
   2538 	    case '}':
   2539 	      {
   2540 		char format;
   2541 
   2542 		if (*s++ == '%'
   2543 		    && ((format = *s) == 'f'
   2544                         || format == 'd'
   2545                         || format == 'q')
   2546 		    && ISDIGIT (*++s))
   2547 		  {
   2548 		    for (mask = 0; ISDIGIT (*s); ++s)
   2549 		      {
   2550 			mask = 10 * mask + (*s - '0');
   2551 		      }		/* read the number */
   2552 
   2553 		    if ((*args == 'v'
   2554 			 || *args == 'B'
   2555 			 || *args == '5'
   2556 			 || *args == 'H'
   2557 			 || format == 'd')
   2558 			&& (mask & 1))
   2559 		      {
   2560                         /* register must be even numbered */
   2561 			break;
   2562 		      }
   2563 
   2564 		    if ((*args == 'V'
   2565 			 || *args == 'R'
   2566 			 || *args == 'J'
   2567 			 || format == 'q')
   2568 			&& (mask & 3))
   2569 		      {
   2570                         /* register must be multiple of 4 */
   2571 			break;
   2572 		      }
   2573 
   2574 		    if (mask >= 64)
   2575 		      {
   2576 			if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
   2577 			  error_message = _(": There are only 64 f registers; [0-63]");
   2578 			else
   2579 			  error_message = _(": There are only 32 f registers; [0-31]");
   2580 			goto error;
   2581 		      }	/* on error */
   2582 		    else if (mask >= 32)
   2583 		      {
   2584 			if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
   2585 			  {
   2586 			    if (*args == 'e' || *args == 'f' || *args == 'g')
   2587 			      {
   2588 				error_message
   2589 				  = _(": There are only 32 single precision f registers; [0-31]");
   2590 				goto error;
   2591 			      }
   2592 			    v9_arg_p = 1;
   2593 			    mask -= 31;	/* wrap high bit */
   2594 			  }
   2595 			else
   2596 			  {
   2597 			    error_message = _(": There are only 32 f registers; [0-31]");
   2598 			    goto error;
   2599 			  }
   2600 		      }
   2601 		  }
   2602 		else
   2603 		  {
   2604 		    break;
   2605 		  }	/* if not an 'f' register.  */
   2606 
   2607 		if (*args == '}' && mask != RS2 (opcode))
   2608 		  {
   2609 		    error_message
   2610 		      = _(": Instruction requires frs2 and frsd must be the same register");
   2611 		    goto error;
   2612 		  }
   2613 
   2614 		switch (*args)
   2615 		  {
   2616 		  case 'v':
   2617 		  case 'V':
   2618 		  case 'e':
   2619 		    opcode |= RS1 (mask);
   2620 		    continue;
   2621 
   2622 		  case 'f':
   2623 		  case 'B':
   2624 		  case 'R':
   2625 		    opcode |= RS2 (mask);
   2626 		    continue;
   2627 
   2628 		  case '4':
   2629 		  case '5':
   2630 		    opcode |= RS3 (mask);
   2631 		    continue;
   2632 
   2633 		  case 'g':
   2634 		  case 'H':
   2635 		  case 'J':
   2636 		  case '}':
   2637 		    opcode |= RD (mask);
   2638 		    continue;
   2639 		  }		/* Pack it in.  */
   2640 
   2641 		know (0);
   2642 		break;
   2643 	      }			/* float arg  */
   2644 
   2645 	    case 'F':
   2646 	      if (strncmp (s, "%fsr", 4) == 0)
   2647 		{
   2648 		  s += 4;
   2649 		  continue;
   2650 		}
   2651 	      break;
   2652 
   2653 	    case '(':
   2654 	      if (strncmp (s, "%efsr", 5) == 0)
   2655 		{
   2656 		  s += 5;
   2657 		  continue;
   2658 		}
   2659 	      break;
   2660 
   2661 	    case '0':		/* 64 bit immediate (set, setsw, setx insn)  */
   2662 	      the_insn.reloc = BFD_RELOC_NONE; /* reloc handled elsewhere  */
   2663 	      goto immediate;
   2664 
   2665 	    case 'l':		/* 22 bit PC relative immediate  */
   2666 	      the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
   2667 	      the_insn.pcrel = 1;
   2668 	      goto immediate;
   2669 
   2670 	    case 'L':		/* 30 bit immediate  */
   2671 	      the_insn.reloc = BFD_RELOC_32_PCREL_S2;
   2672 	      the_insn.pcrel = 1;
   2673 	      goto immediate;
   2674 
   2675 	    case 'h':
   2676 	    case 'n':		/* 22 bit immediate  */
   2677 	      the_insn.reloc = BFD_RELOC_SPARC22;
   2678 	      goto immediate;
   2679 
   2680 	    case 'i':		/* 13 bit immediate  */
   2681 	      the_insn.reloc = BFD_RELOC_SPARC13;
   2682 
   2683 	      /* fallthrough */
   2684 
   2685 	    immediate:
   2686 	      if (*s == ' ')
   2687 		s++;
   2688 
   2689 	      {
   2690 		char *s1;
   2691 		const char *op_arg = NULL;
   2692 		static expressionS op_exp;
   2693 		bfd_reloc_code_real_type old_reloc = the_insn.reloc;
   2694 
   2695 		/* Check for %hi, etc.  */
   2696 		if (*s == '%')
   2697 		  {
   2698                     const struct perc_entry *p;
   2699 
   2700                     for (p = perc_table; p->type != perc_entry_none; p++)
   2701                       if ((p->type == perc_entry_imm_pop || p->type == perc_entry_reg)
   2702                           && strncmp (s + 1, p->name, p->len) == 0)
   2703                         break;
   2704                     if (p->type == perc_entry_none || p->type == perc_entry_reg)
   2705                       break;
   2706 
   2707 		    if (s[p->len + 1] != '(')
   2708 		      {
   2709 			as_bad (_("Illegal operands: %%%s requires arguments in ()"), p->name);
   2710 			return special_case;
   2711 		      }
   2712 
   2713 		    op_arg = p->name;
   2714 		    the_insn.reloc = p->pop->reloc;
   2715 		    s += p->len + 2;
   2716 		    v9_arg_p = p->pop->flags & F_POP_V9;
   2717 		  }
   2718 
   2719 		/* Note that if the get_expression() fails, we will still
   2720 		   have created U entries in the symbol table for the
   2721 		   'symbols' in the input string.  Try not to create U
   2722 		   symbols for registers, etc.  */
   2723 
   2724 		/* This stuff checks to see if the expression ends in
   2725 		   +%reg.  If it does, it removes the register from
   2726 		   the expression, and re-sets 's' to point to the
   2727 		   right place.  */
   2728 
   2729 		if (op_arg)
   2730 		  {
   2731 		    int npar = 0;
   2732 
   2733 		    for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
   2734 		      if (*s1 == '(')
   2735 			npar++;
   2736 		      else if (*s1 == ')')
   2737 			{
   2738 			  if (!npar)
   2739 			    break;
   2740 			  npar--;
   2741 			}
   2742 
   2743 		    if (*s1 != ')')
   2744 		      {
   2745 			as_bad (_("Illegal operands: %%%s requires arguments in ()"), op_arg);
   2746 			return special_case;
   2747 		      }
   2748 
   2749 		    *s1 = '\0';
   2750 		    (void) get_expression (s);
   2751 		    *s1 = ')';
   2752 		    if (expr_end != s1)
   2753 		      {
   2754 			as_bad (_("Expression inside %%%s could not be parsed"), op_arg);
   2755 			return special_case;
   2756 		      }
   2757 		    s = s1 + 1;
   2758 		    if (*s == ',' || *s == ']' || !*s)
   2759 		      continue;
   2760 		    if (*s != '+' && *s != '-')
   2761 		      {
   2762 			as_bad (_("Illegal operands: Can't do arithmetics other than + and - involving %%%s()"), op_arg);
   2763 			return special_case;
   2764 		      }
   2765 		    *s1 = '0';
   2766 		    s = s1;
   2767 		    op_exp = the_insn.exp;
   2768 		    memset (&the_insn.exp, 0, sizeof (the_insn.exp));
   2769 		  }
   2770 
   2771 		for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++)
   2772 		  ;
   2773 
   2774 		if (s1 != s && ISDIGIT (s1[-1]))
   2775 		  {
   2776 		    if (s1[-2] == '%' && s1[-3] == '+')
   2777 		      s1 -= 3;
   2778 		    else if (strchr ("golir0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
   2779 		      s1 -= 4;
   2780 		    else if (s1[-3] == 'r' && s1[-4] == '%' && s1[-5] == '+')
   2781 		      s1 -= 5;
   2782 		    else
   2783 		      s1 = NULL;
   2784 		    if (s1)
   2785 		      {
   2786 			*s1 = '\0';
   2787 			if (op_arg && s1 == s + 1)
   2788 			  the_insn.exp.X_op = O_absent;
   2789 			else
   2790 			  (void) get_expression (s);
   2791 			*s1 = '+';
   2792 			if (op_arg)
   2793 			  *s = ')';
   2794 			s = s1;
   2795 		      }
   2796 		  }
   2797 		else
   2798 		  s1 = NULL;
   2799 
   2800 		if (!s1)
   2801 		  {
   2802 		    (void) get_expression (s);
   2803 		    if (op_arg)
   2804 		      *s = ')';
   2805 		    s = expr_end;
   2806 		  }
   2807 
   2808 		if (op_arg)
   2809 		  {
   2810 		    the_insn.exp2 = the_insn.exp;
   2811 		    the_insn.exp = op_exp;
   2812 		    if (the_insn.exp2.X_op == O_absent)
   2813 		      the_insn.exp2.X_op = O_illegal;
   2814 		    else if (the_insn.exp.X_op == O_absent)
   2815 		      {
   2816 			the_insn.exp = the_insn.exp2;
   2817 			the_insn.exp2.X_op = O_illegal;
   2818 		      }
   2819 		    else if (the_insn.exp.X_op == O_constant)
   2820 		      {
   2821 			valueT val = the_insn.exp.X_add_number;
   2822 			switch (the_insn.reloc)
   2823 			  {
   2824 			  default:
   2825 			    break;
   2826 
   2827 			  case BFD_RELOC_SPARC_HH22:
   2828 			    val = BSR (val, 32);
   2829 			    /* Fall through.  */
   2830 
   2831 			  case BFD_RELOC_SPARC_LM22:
   2832 			  case BFD_RELOC_HI22:
   2833 			    val = (val >> 10) & 0x3fffff;
   2834 			    break;
   2835 
   2836 			  case BFD_RELOC_SPARC_HM10:
   2837 			    val = BSR (val, 32);
   2838 			    /* Fall through.  */
   2839 
   2840 			  case BFD_RELOC_LO10:
   2841 			    val &= 0x3ff;
   2842 			    break;
   2843 
   2844 			  case BFD_RELOC_SPARC_H34:
   2845 			    val >>= 12;
   2846 			    val &= 0x3fffff;
   2847 			    break;
   2848 
   2849 			  case BFD_RELOC_SPARC_H44:
   2850 			    val >>= 22;
   2851 			    val &= 0x3fffff;
   2852 			    break;
   2853 
   2854 			  case BFD_RELOC_SPARC_M44:
   2855 			    val >>= 12;
   2856 			    val &= 0x3ff;
   2857 			    break;
   2858 
   2859 			  case BFD_RELOC_SPARC_L44:
   2860 			    val &= 0xfff;
   2861 			    break;
   2862 
   2863 			  case BFD_RELOC_SPARC_HIX22:
   2864 			    val = ~val;
   2865 			    val = (val >> 10) & 0x3fffff;
   2866 			    break;
   2867 
   2868 			  case BFD_RELOC_SPARC_LOX10:
   2869 			    val = (val & 0x3ff) | 0x1c00;
   2870 			    break;
   2871 			  }
   2872 			the_insn.exp = the_insn.exp2;
   2873 			the_insn.exp.X_add_number += val;
   2874 			the_insn.exp2.X_op = O_illegal;
   2875 			the_insn.reloc = old_reloc;
   2876 		      }
   2877 		    else if (the_insn.exp2.X_op != O_constant)
   2878 		      {
   2879 			as_bad (_("Illegal operands: Can't add non-constant expression to %%%s()"), op_arg);
   2880 			return special_case;
   2881 		      }
   2882 		    else
   2883 		      {
   2884 			if (old_reloc != BFD_RELOC_SPARC13
   2885 			    || the_insn.reloc != BFD_RELOC_LO10
   2886 			    || sparc_arch_size != 64
   2887 			    || sparc_pic_code)
   2888 			  {
   2889 			    as_bad (_("Illegal operands: Can't do arithmetics involving %%%s() of a relocatable symbol"), op_arg);
   2890 			    return special_case;
   2891 			  }
   2892 			the_insn.reloc = BFD_RELOC_SPARC_OLO10;
   2893 		      }
   2894 		  }
   2895 	      }
   2896 	      /* Check for constants that don't require emitting a reloc.  */
   2897 	      if (the_insn.exp.X_op == O_constant
   2898 		  && the_insn.exp.X_add_symbol == 0
   2899 		  && the_insn.exp.X_op_symbol == 0)
   2900 		{
   2901 		  /* For pc-relative call instructions, we reject
   2902 		     constants to get better code.  */
   2903 		  if (the_insn.pcrel
   2904 		      && the_insn.reloc == BFD_RELOC_32_PCREL_S2
   2905 		      && in_signed_range (the_insn.exp.X_add_number, 0x3fff))
   2906 		    {
   2907 		      error_message = _(": PC-relative operand can't be a constant");
   2908 		      goto error;
   2909 		    }
   2910 
   2911 		  if (the_insn.reloc >= BFD_RELOC_SPARC_TLS_GD_HI22
   2912 		      && the_insn.reloc <= BFD_RELOC_SPARC_TLS_TPOFF64)
   2913 		    {
   2914 		      error_message = _(": TLS operand can't be a constant");
   2915 		      goto error;
   2916 		    }
   2917 
   2918 		  /* Constants that won't fit are checked in md_apply_fix
   2919 		     and bfd_install_relocation.
   2920 		     ??? It would be preferable to install the constants
   2921 		     into the insn here and save having to create a fixS
   2922 		     for each one.  There already exists code to handle
   2923 		     all the various cases (e.g. in md_apply_fix and
   2924 		     bfd_install_relocation) so duplicating all that code
   2925 		     here isn't right.  */
   2926 
   2927 		  /* This is a special case to handle cbcond instructions
   2928 		     properly, which can need two relocations.  The first
   2929 		     one is for the 5-bit immediate field and the latter
   2930 		     is going to be for the WDISP10 branch part.  We
   2931 		     handle the R_SPARC_5 immediate directly here so that
   2932 		     we don't need to add support for multiple relocations
   2933 		     in one instruction just yet.  */
   2934 		  if (the_insn.reloc == BFD_RELOC_SPARC_5)
   2935 		    {
   2936 		      valueT val = the_insn.exp.X_add_number;
   2937 
   2938 		      if (! in_bitfield_range (val, 0x1f))
   2939 			{
   2940 			  error_message = _(": Immediate value in cbcond is out of range.");
   2941 			  goto error;
   2942 			}
   2943 		      opcode |= val & 0x1f;
   2944 		      the_insn.reloc = BFD_RELOC_NONE;
   2945 		    }
   2946 		}
   2947 
   2948 	      continue;
   2949 
   2950 	    case 'a':
   2951 	      if (*s++ == 'a')
   2952 		{
   2953 		  opcode |= ANNUL;
   2954 		  continue;
   2955 		}
   2956 	      break;
   2957 
   2958 	    case 'A':
   2959 	      {
   2960 		int asi = 0;
   2961 
   2962 		/* Parse an asi.  */
   2963 		if (*s == '#')
   2964 		  {
   2965 		    if (! parse_keyword_arg (sparc_encode_asi, &s, &asi))
   2966 		      {
   2967 			error_message = _(": invalid ASI name");
   2968 			goto error;
   2969 		      }
   2970 		  }
   2971 		else
   2972 		  {
   2973 		    if (! parse_const_expr_arg (&s, &asi))
   2974 		      {
   2975 			error_message = _(": invalid ASI expression");
   2976 			goto error;
   2977 		      }
   2978 		    if (asi < 0 || asi > 255)
   2979 		      {
   2980 			error_message = _(": invalid ASI number");
   2981 			goto error;
   2982 		      }
   2983 		  }
   2984 		opcode |= ASI (asi);
   2985 		continue;
   2986 	      }			/* Alternate space.  */
   2987 
   2988 	    case 'p':
   2989 	      if (strncmp (s, "%psr", 4) == 0)
   2990 		{
   2991 		  s += 4;
   2992 		  continue;
   2993 		}
   2994 	      break;
   2995 
   2996 	    case 'q':		/* Floating point queue.  */
   2997 	      if (strncmp (s, "%fq", 3) == 0)
   2998 		{
   2999 		  s += 3;
   3000 		  continue;
   3001 		}
   3002 	      break;
   3003 
   3004 	    case 'Q':		/* Coprocessor queue.  */
   3005 	      if (strncmp (s, "%cq", 3) == 0)
   3006 		{
   3007 		  s += 3;
   3008 		  continue;
   3009 		}
   3010 	      break;
   3011 
   3012 	    case 'S':
   3013 	      if (strcmp (str, "set") == 0
   3014 		  || strcmp (str, "setuw") == 0)
   3015 		{
   3016 		  special_case = SPECIAL_CASE_SET;
   3017 		  continue;
   3018 		}
   3019 	      else if (strcmp (str, "setsw") == 0)
   3020 		{
   3021 		  special_case = SPECIAL_CASE_SETSW;
   3022 		  continue;
   3023 		}
   3024 	      else if (strcmp (str, "setx") == 0)
   3025 		{
   3026 		  special_case = SPECIAL_CASE_SETX;
   3027 		  continue;
   3028 		}
   3029 	      else if (strncmp (str, "fdiv", 4) == 0)
   3030 		{
   3031 		  special_case = SPECIAL_CASE_FDIV;
   3032 		  continue;
   3033 		}
   3034 	      break;
   3035 
   3036 	    case 'o':
   3037 	      if (strncmp (s, "%asi", 4) != 0)
   3038 		break;
   3039 	      s += 4;
   3040 	      continue;
   3041 
   3042 	    case 's':
   3043 	      if (strncmp (s, "%fprs", 5) != 0)
   3044 		break;
   3045 	      s += 5;
   3046 	      continue;
   3047 
   3048 	    case '{':
   3049 	      if (strncmp (s, "%mcdper",7) != 0)
   3050 		break;
   3051 	      s += 7;
   3052 	      continue;
   3053 
   3054 	    case 'E':
   3055 	      if (strncmp (s, "%ccr", 4) != 0)
   3056 		break;
   3057 	      s += 4;
   3058 	      continue;
   3059 
   3060 	    case 't':
   3061 	      if (strncmp (s, "%tbr", 4) != 0)
   3062 		break;
   3063 	      s += 4;
   3064 	      continue;
   3065 
   3066 	    case 'w':
   3067 	      if (strncmp (s, "%wim", 4) != 0)
   3068 		break;
   3069 	      s += 4;
   3070 	      continue;
   3071 
   3072 	    case 'x':
   3073 	      {
   3074 		char *push = input_line_pointer;
   3075 		expressionS e;
   3076 
   3077 		input_line_pointer = s;
   3078 		expression (&e);
   3079 		if (e.X_op == O_constant)
   3080 		  {
   3081 		    int n = e.X_add_number;
   3082 		    if (n != e.X_add_number || (n & ~0x1ff) != 0)
   3083 		      as_bad (_("OPF immediate operand out of range (0-0x1ff)"));
   3084 		    else
   3085 		      opcode |= e.X_add_number << 5;
   3086 		  }
   3087 		else
   3088 		  as_bad (_("non-immediate OPF operand, ignored"));
   3089 		s = input_line_pointer;
   3090 		input_line_pointer = push;
   3091 		continue;
   3092 	      }
   3093 
   3094 	    case 'y':
   3095 	      if (strncmp (s, "%y", 2) != 0)
   3096 		break;
   3097 	      s += 2;
   3098 	      continue;
   3099 
   3100 	    case 'u':
   3101 	    case 'U':
   3102 	      {
   3103 		/* Parse a sparclet cpreg.  */
   3104 		int cpreg;
   3105 		if (! parse_keyword_arg (sparc_encode_sparclet_cpreg, &s, &cpreg))
   3106 		  {
   3107 		    error_message = _(": invalid cpreg name");
   3108 		    goto error;
   3109 		  }
   3110 		opcode |= (*args == 'U' ? RS1 (cpreg) : RD (cpreg));
   3111 		continue;
   3112 	      }
   3113 
   3114 	    default:
   3115 	      as_fatal (_("failed sanity check."));
   3116 	    }			/* switch on arg code.  */
   3117 
   3118 	  /* Break out of for() loop.  */
   3119 	  break;
   3120 	}			/* For each arg that we expect.  */
   3121 
   3122     error:
   3123       if (match == 0)
   3124 	{
   3125 	  /* Args don't match.  */
   3126 	  if (&insn[1] - sparc_opcodes < sparc_num_opcodes
   3127 	      && (insn->name == insn[1].name
   3128 		  || !strcmp (insn->name, insn[1].name)))
   3129 	    {
   3130 	      ++insn;
   3131 	      s = argsStart;
   3132 	      continue;
   3133 	    }
   3134 	  else
   3135 	    {
   3136 	      as_bad (_("Illegal operands%s"), error_message);
   3137 	      return special_case;
   3138 	    }
   3139 	}
   3140       else
   3141 	{
   3142 	  /* We have a match.  Now see if the architecture is OK.  */
   3143 	  int needed_arch_mask = insn->architecture;
   3144 	  bfd_uint64_t hwcaps
   3145 	    = (((bfd_uint64_t) insn->hwcaps2) << 32) | insn->hwcaps;
   3146 
   3147 #if defined(OBJ_ELF) && !defined(TE_SOLARIS)
   3148 	  if (hwcaps)
   3149 		  hwcap_seen |= hwcaps;
   3150 #endif
   3151 	  if (v9_arg_p)
   3152 	    {
   3153 	      needed_arch_mask &=
   3154 		~(SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9) - 1);
   3155 	      if (! needed_arch_mask)
   3156 		needed_arch_mask =
   3157 		  SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9);
   3158 	    }
   3159 
   3160 	  if (needed_arch_mask
   3161 	      & SPARC_OPCODE_SUPPORTED (current_architecture))
   3162 	    /* OK.  */
   3163 	    ;
   3164 	  /* Can we bump up the architecture?  */
   3165 	  else if (needed_arch_mask
   3166 		   & SPARC_OPCODE_SUPPORTED (max_architecture))
   3167 	    {
   3168 	      enum sparc_opcode_arch_val needed_architecture =
   3169 		sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture)
   3170 			   & needed_arch_mask);
   3171 
   3172 	      gas_assert (needed_architecture <= SPARC_OPCODE_ARCH_MAX);
   3173 	      if (warn_on_bump
   3174 		  && needed_architecture > warn_after_architecture)
   3175 		{
   3176 		  as_warn (_("architecture bumped from \"%s\" to \"%s\" on \"%s\""),
   3177 			   sparc_opcode_archs[current_architecture].name,
   3178 			   sparc_opcode_archs[needed_architecture].name,
   3179 			   str);
   3180 		  warn_after_architecture = needed_architecture;
   3181 		}
   3182 	      current_architecture = needed_architecture;
   3183 	      hwcap_allowed |= hwcaps;
   3184 	    }
   3185 	  /* Conflict.  */
   3186 	  /* ??? This seems to be a bit fragile.  What if the next entry in
   3187 	     the opcode table is the one we want and it is supported?
   3188 	     It is possible to arrange the table today so that this can't
   3189 	     happen but what about tomorrow?  */
   3190 	  else
   3191 	    {
   3192 	      int arch, printed_one_p = 0;
   3193 	      char *p;
   3194 	      char required_archs[SPARC_OPCODE_ARCH_MAX * 16];
   3195 
   3196 	      /* Create a list of the architectures that support the insn.  */
   3197 	      needed_arch_mask &= ~SPARC_OPCODE_SUPPORTED (max_architecture);
   3198 	      p = required_archs;
   3199 	      arch = sparc_ffs (needed_arch_mask);
   3200 	      while ((1 << arch) <= needed_arch_mask)
   3201 		{
   3202 		  if ((1 << arch) & needed_arch_mask)
   3203 		    {
   3204 		      if (printed_one_p)
   3205 			*p++ = '|';
   3206 		      strcpy (p, sparc_opcode_archs[arch].name);
   3207 		      p += strlen (p);
   3208 		      printed_one_p = 1;
   3209 		    }
   3210 		  ++arch;
   3211 		}
   3212 
   3213 	      as_bad (_("Architecture mismatch on \"%s\"."), str);
   3214 	      as_tsktsk (_(" (Requires %s; requested architecture is %s.)"),
   3215 			 required_archs,
   3216 			 sparc_opcode_archs[max_architecture].name);
   3217 	      return special_case;
   3218 	    }
   3219 
   3220 	  /* Make sure the hwcaps used by the instruction are
   3221 	     currently enabled.  */
   3222 	  if (hwcaps & ~hwcap_allowed)
   3223 	    {
   3224 	      const char *hwcap_name = get_hwcap_name(hwcaps & ~hwcap_allowed);
   3225 
   3226 	      as_bad (_("Hardware capability \"%s\" not enabled for \"%s\"."),
   3227 		      hwcap_name, str);
   3228 	      return special_case;
   3229 	    }
   3230 	} /* If no match.  */
   3231 
   3232       break;
   3233     } /* Forever looking for a match.  */
   3234 
   3235   the_insn.opcode = opcode;
   3236   return special_case;
   3237 }
   3238 
   3239 /* Parse an argument that can be expressed as a keyword.
   3240    (eg: #StoreStore or %ccfr).
   3241    The result is a boolean indicating success.
   3242    If successful, INPUT_POINTER is updated.  */
   3243 
   3244 static int
   3245 parse_keyword_arg (int (*lookup_fn) (const char *),
   3246 		   char **input_pointerP,
   3247 		   int *valueP)
   3248 {
   3249   int value;
   3250   char c, *p, *q;
   3251 
   3252   p = *input_pointerP;
   3253   for (q = p + (*p == '#' || *p == '%');
   3254        ISALNUM (*q) || *q == '_';
   3255        ++q)
   3256     continue;
   3257   c = *q;
   3258   *q = 0;
   3259   value = (*lookup_fn) (p);
   3260   *q = c;
   3261   if (value == -1)
   3262     return 0;
   3263   *valueP = value;
   3264   *input_pointerP = q;
   3265   return 1;
   3266 }
   3267 
   3268 /* Parse an argument that is a constant expression.
   3269    The result is a boolean indicating success.  */
   3270 
   3271 static int
   3272 parse_const_expr_arg (char **input_pointerP, int *valueP)
   3273 {
   3274   char *save = input_line_pointer;
   3275   expressionS exp;
   3276 
   3277   input_line_pointer = *input_pointerP;
   3278   /* The next expression may be something other than a constant
   3279      (say if we're not processing the right variant of the insn).
   3280      Don't call expression unless we're sure it will succeed as it will
   3281      signal an error (which we want to defer until later).  */
   3282   /* FIXME: It might be better to define md_operand and have it recognize
   3283      things like %asi, etc. but continuing that route through to the end
   3284      is a lot of work.  */
   3285   if (*input_line_pointer == '%')
   3286     {
   3287       input_line_pointer = save;
   3288       return 0;
   3289     }
   3290   expression (&exp);
   3291   *input_pointerP = input_line_pointer;
   3292   input_line_pointer = save;
   3293   if (exp.X_op != O_constant)
   3294     return 0;
   3295   *valueP = exp.X_add_number;
   3296   return 1;
   3297 }
   3298 
   3299 /* Subroutine of sparc_ip to parse an expression.  */
   3300 
   3301 static int
   3302 get_expression (char *str)
   3303 {
   3304   char *save_in;
   3305   segT seg;
   3306 
   3307   save_in = input_line_pointer;
   3308   input_line_pointer = str;
   3309   seg = expression (&the_insn.exp);
   3310   if (seg != absolute_section
   3311       && seg != text_section
   3312       && seg != data_section
   3313       && seg != bss_section
   3314       && seg != undefined_section)
   3315     {
   3316       the_insn.error = _("bad segment");
   3317       expr_end = input_line_pointer;
   3318       input_line_pointer = save_in;
   3319       return 1;
   3320     }
   3321   expr_end = input_line_pointer;
   3322   input_line_pointer = save_in;
   3323   return 0;
   3324 }
   3325 
   3326 /* Subroutine of md_assemble to output one insn.  */
   3327 
   3328 static void
   3329 output_insn (const struct sparc_opcode *insn, struct sparc_it *theinsn)
   3330 {
   3331   char *toP = frag_more (4);
   3332 
   3333   /* Put out the opcode.  */
   3334   if (INSN_BIG_ENDIAN)
   3335     number_to_chars_bigendian (toP, (valueT) theinsn->opcode, 4);
   3336   else
   3337     number_to_chars_littleendian (toP, (valueT) theinsn->opcode, 4);
   3338 
   3339   /* Put out the symbol-dependent stuff.  */
   3340   if (theinsn->reloc != BFD_RELOC_NONE)
   3341     {
   3342       fixS *fixP =  fix_new_exp (frag_now,	/* Which frag.  */
   3343 				 (toP - frag_now->fr_literal),	/* Where.  */
   3344 				 4,		/* Size.  */
   3345 				 &theinsn->exp,
   3346 				 theinsn->pcrel,
   3347 				 theinsn->reloc);
   3348       /* Turn off overflow checking in fixup_segment.  We'll do our
   3349 	 own overflow checking in md_apply_fix.  This is necessary because
   3350 	 the insn size is 4 and fixup_segment will signal an overflow for
   3351 	 large 8 byte quantities.  */
   3352       fixP->fx_no_overflow = 1;
   3353       if (theinsn->reloc == BFD_RELOC_SPARC_OLO10)
   3354 	fixP->tc_fix_data = theinsn->exp2.X_add_number;
   3355     }
   3356 
   3357   last_insn = insn;
   3358   last_opcode = theinsn->opcode;
   3359 
   3360 #ifdef OBJ_ELF
   3361   dwarf2_emit_insn (4);
   3362 #endif
   3363 }
   3364 
   3365 const char *
   3367 md_atof (int type, char *litP, int *sizeP)
   3368 {
   3369   return ieee_md_atof (type, litP, sizeP, target_big_endian);
   3370 }
   3371 
   3372 /* Write a value out to the object file, using the appropriate
   3373    endianness.  */
   3374 
   3375 void
   3376 md_number_to_chars (char *buf, valueT val, int n)
   3377 {
   3378   if (target_big_endian)
   3379     number_to_chars_bigendian (buf, val, n);
   3380   else if (target_little_endian_data
   3381 	   && ((n == 4 || n == 2) && ~now_seg->flags & SEC_ALLOC))
   3382     /* Output debug words, which are not in allocated sections, as big
   3383        endian.  */
   3384     number_to_chars_bigendian (buf, val, n);
   3385   else if (target_little_endian_data || ! target_big_endian)
   3386     number_to_chars_littleendian (buf, val, n);
   3387 }
   3388 
   3389 /* Apply a fixS to the frags, now that we know the value it ought to
   3391    hold.  */
   3392 
   3393 void
   3394 md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED)
   3395 {
   3396   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
   3397   offsetT val = * (offsetT *) valP;
   3398   long insn;
   3399 
   3400   gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
   3401 
   3402   fixP->fx_addnumber = val;	/* Remember value for emit_reloc.  */
   3403 
   3404 #ifdef OBJ_ELF
   3405   /* SPARC ELF relocations don't use an addend in the data field.  */
   3406   if (fixP->fx_addsy != NULL)
   3407     {
   3408       switch (fixP->fx_r_type)
   3409 	{
   3410 	case BFD_RELOC_SPARC_TLS_GD_HI22:
   3411 	case BFD_RELOC_SPARC_TLS_GD_LO10:
   3412 	case BFD_RELOC_SPARC_TLS_GD_ADD:
   3413 	case BFD_RELOC_SPARC_TLS_GD_CALL:
   3414 	case BFD_RELOC_SPARC_TLS_LDM_HI22:
   3415 	case BFD_RELOC_SPARC_TLS_LDM_LO10:
   3416 	case BFD_RELOC_SPARC_TLS_LDM_ADD:
   3417 	case BFD_RELOC_SPARC_TLS_LDM_CALL:
   3418 	case BFD_RELOC_SPARC_TLS_LDO_HIX22:
   3419 	case BFD_RELOC_SPARC_TLS_LDO_LOX10:
   3420 	case BFD_RELOC_SPARC_TLS_LDO_ADD:
   3421 	case BFD_RELOC_SPARC_TLS_IE_HI22:
   3422 	case BFD_RELOC_SPARC_TLS_IE_LO10:
   3423 	case BFD_RELOC_SPARC_TLS_IE_LD:
   3424 	case BFD_RELOC_SPARC_TLS_IE_LDX:
   3425 	case BFD_RELOC_SPARC_TLS_IE_ADD:
   3426 	case BFD_RELOC_SPARC_TLS_LE_HIX22:
   3427 	case BFD_RELOC_SPARC_TLS_LE_LOX10:
   3428 	case BFD_RELOC_SPARC_TLS_DTPMOD32:
   3429 	case BFD_RELOC_SPARC_TLS_DTPMOD64:
   3430 	case BFD_RELOC_SPARC_TLS_DTPOFF32:
   3431 	case BFD_RELOC_SPARC_TLS_DTPOFF64:
   3432 	case BFD_RELOC_SPARC_TLS_TPOFF32:
   3433 	case BFD_RELOC_SPARC_TLS_TPOFF64:
   3434 	  S_SET_THREAD_LOCAL (fixP->fx_addsy);
   3435 
   3436 	default:
   3437 	  break;
   3438 	}
   3439 
   3440       return;
   3441     }
   3442 #endif
   3443 
   3444   /* This is a hack.  There should be a better way to
   3445      handle this.  Probably in terms of howto fields, once
   3446      we can look at these fixups in terms of howtos.  */
   3447   if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
   3448     val += fixP->fx_where + fixP->fx_frag->fr_address;
   3449 
   3450 #ifdef OBJ_AOUT
   3451   /* FIXME: More ridiculous gas reloc hacking.  If we are going to
   3452      generate a reloc, then we just want to let the reloc addend set
   3453      the value.  We do not want to also stuff the addend into the
   3454      object file.  Including the addend in the object file works when
   3455      doing a static link, because the linker will ignore the object
   3456      file contents.  However, the dynamic linker does not ignore the
   3457      object file contents.  */
   3458   if (fixP->fx_addsy != NULL
   3459       && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
   3460     val = 0;
   3461 
   3462   /* When generating PIC code, we do not want an addend for a reloc
   3463      against a local symbol.  We adjust fx_addnumber to cancel out the
   3464      value already included in val, and to also cancel out the
   3465      adjustment which bfd_install_relocation will create.  */
   3466   if (sparc_pic_code
   3467       && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2
   3468       && fixP->fx_addsy != NULL
   3469       && ! S_IS_COMMON (fixP->fx_addsy)
   3470       && symbol_section_p (fixP->fx_addsy))
   3471     fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy);
   3472 
   3473   /* When generating PIC code, we need to fiddle to get
   3474      bfd_install_relocation to do the right thing for a PC relative
   3475      reloc against a local symbol which we are going to keep.  */
   3476   if (sparc_pic_code
   3477       && fixP->fx_r_type == BFD_RELOC_32_PCREL_S2
   3478       && fixP->fx_addsy != NULL
   3479       && (S_IS_EXTERNAL (fixP->fx_addsy)
   3480 	  || S_IS_WEAK (fixP->fx_addsy))
   3481       && S_IS_DEFINED (fixP->fx_addsy)
   3482       && ! S_IS_COMMON (fixP->fx_addsy))
   3483     {
   3484       val = 0;
   3485       fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy);
   3486     }
   3487 #endif
   3488 
   3489   /* If this is a data relocation, just output VAL.  */
   3490 
   3491   if (fixP->fx_r_type == BFD_RELOC_8)
   3492     {
   3493       md_number_to_chars (buf, val, 1);
   3494     }
   3495   else if (fixP->fx_r_type == BFD_RELOC_16
   3496 	   || fixP->fx_r_type == BFD_RELOC_SPARC_UA16)
   3497     {
   3498       md_number_to_chars (buf, val, 2);
   3499     }
   3500   else if (fixP->fx_r_type == BFD_RELOC_32
   3501 	   || fixP->fx_r_type == BFD_RELOC_SPARC_UA32
   3502 	   || fixP->fx_r_type == BFD_RELOC_SPARC_REV32)
   3503     {
   3504       md_number_to_chars (buf, val, 4);
   3505     }
   3506   else if (fixP->fx_r_type == BFD_RELOC_64
   3507 	   || fixP->fx_r_type == BFD_RELOC_SPARC_UA64)
   3508     {
   3509       md_number_to_chars (buf, val, 8);
   3510     }
   3511   else if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
   3512            || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
   3513     {
   3514       fixP->fx_done = 0;
   3515       return;
   3516     }
   3517   else
   3518     {
   3519       /* It's a relocation against an instruction.  */
   3520 
   3521       if (INSN_BIG_ENDIAN)
   3522 	insn = bfd_getb32 ((unsigned char *) buf);
   3523       else
   3524 	insn = bfd_getl32 ((unsigned char *) buf);
   3525 
   3526       switch (fixP->fx_r_type)
   3527 	{
   3528 	case BFD_RELOC_32_PCREL_S2:
   3529 	  val = val >> 2;
   3530 	  /* FIXME: This increment-by-one deserves a comment of why it's
   3531 	     being done!  */
   3532 	  if (! sparc_pic_code
   3533 	      || fixP->fx_addsy == NULL
   3534 	      || symbol_section_p (fixP->fx_addsy))
   3535 	    ++val;
   3536 
   3537 	  insn |= val & 0x3fffffff;
   3538 
   3539 	  /* See if we have a delay slot.  */
   3540 	  if (sparc_relax && fixP->fx_where + 8 <= fixP->fx_frag->fr_fix)
   3541 	    {
   3542 #define G0		0
   3543 #define O7		15
   3544 #define XCC		(2 << 20)
   3545 #define COND(x)		(((x)&0xf)<<25)
   3546 #define CONDA		COND(0x8)
   3547 #define INSN_BPA	(F2(0,1) | CONDA | BPRED | XCC)
   3548 #define INSN_BA		(F2(0,2) | CONDA)
   3549 #define INSN_OR		F3(2, 0x2, 0)
   3550 #define INSN_NOP	F2(0,4)
   3551 
   3552 	      long delay;
   3553 
   3554 	      /* If the instruction is a call with either:
   3555 		 restore
   3556 		 arithmetic instruction with rd == %o7
   3557 		 where rs1 != %o7 and rs2 if it is register != %o7
   3558 		 then we can optimize if the call destination is near
   3559 		 by changing the call into a branch always.  */
   3560 	      if (INSN_BIG_ENDIAN)
   3561 		delay = bfd_getb32 ((unsigned char *) buf + 4);
   3562 	      else
   3563 		delay = bfd_getl32 ((unsigned char *) buf + 4);
   3564 	      if ((insn & OP (~0)) != OP (1) || (delay & OP (~0)) != OP (2))
   3565 		break;
   3566 	      if ((delay & OP3 (~0)) != OP3 (0x3d) /* Restore.  */
   3567 		  && ((delay & OP3 (0x28)) != 0 /* Arithmetic.  */
   3568 		      || ((delay & RD (~0)) != RD (O7))))
   3569 		break;
   3570 	      if ((delay & RS1 (~0)) == RS1 (O7)
   3571 		  || ((delay & F3I (~0)) == 0
   3572 		      && (delay & RS2 (~0)) == RS2 (O7)))
   3573 		break;
   3574 	      /* Ensure the branch will fit into simm22.  */
   3575 	      if ((val & 0x3fe00000)
   3576 		  && (val & 0x3fe00000) != 0x3fe00000)
   3577 		break;
   3578 	      /* Check if the arch is v9 and branch will fit
   3579 		 into simm19.  */
   3580 	      if (((val & 0x3c0000) == 0
   3581 		   || (val & 0x3c0000) == 0x3c0000)
   3582 		  && (sparc_arch_size == 64
   3583 		      || current_architecture >= SPARC_OPCODE_ARCH_V9))
   3584 		/* ba,pt %xcc  */
   3585 		insn = INSN_BPA | (val & 0x7ffff);
   3586 	      else
   3587 		/* ba  */
   3588 		insn = INSN_BA | (val & 0x3fffff);
   3589 	      if (fixP->fx_where >= 4
   3590 		  && ((delay & (0xffffffff ^ RS1 (~0)))
   3591 		      == (INSN_OR | RD (O7) | RS2 (G0))))
   3592 		{
   3593 		  long setter;
   3594 		  int reg;
   3595 
   3596 		  if (INSN_BIG_ENDIAN)
   3597 		    setter = bfd_getb32 ((unsigned char *) buf - 4);
   3598 		  else
   3599 		    setter = bfd_getl32 ((unsigned char *) buf - 4);
   3600 		  if ((setter & (0xffffffff ^ RD (~0)))
   3601 		      != (INSN_OR | RS1 (O7) | RS2 (G0)))
   3602 		    break;
   3603 		  /* The sequence was
   3604 		     or %o7, %g0, %rN
   3605 		     call foo
   3606 		     or %rN, %g0, %o7
   3607 
   3608 		     If call foo was replaced with ba, replace
   3609 		     or %rN, %g0, %o7 with nop.  */
   3610 		  reg = (delay & RS1 (~0)) >> 14;
   3611 		  if (reg != ((setter & RD (~0)) >> 25)
   3612 		      || reg == G0 || reg == O7)
   3613 		    break;
   3614 
   3615 		  if (INSN_BIG_ENDIAN)
   3616 		    bfd_putb32 (INSN_NOP, (unsigned char *) buf + 4);
   3617 		  else
   3618 		    bfd_putl32 (INSN_NOP, (unsigned char *) buf + 4);
   3619 		}
   3620 	    }
   3621 	  break;
   3622 
   3623 	case BFD_RELOC_SPARC_11:
   3624 	  if (! in_signed_range (val, 0x7ff))
   3625 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3626 			  _("relocation overflow"));
   3627 	  insn |= val & 0x7ff;
   3628 	  break;
   3629 
   3630 	case BFD_RELOC_SPARC_10:
   3631 	  if (! in_signed_range (val, 0x3ff))
   3632 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3633 			  _("relocation overflow"));
   3634 	  insn |= val & 0x3ff;
   3635 	  break;
   3636 
   3637 	case BFD_RELOC_SPARC_7:
   3638 	  if (! in_bitfield_range (val, 0x7f))
   3639 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3640 			  _("relocation overflow"));
   3641 	  insn |= val & 0x7f;
   3642 	  break;
   3643 
   3644 	case BFD_RELOC_SPARC_6:
   3645 	  if (! in_bitfield_range (val, 0x3f))
   3646 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3647 			  _("relocation overflow"));
   3648 	  insn |= val & 0x3f;
   3649 	  break;
   3650 
   3651 	case BFD_RELOC_SPARC_5:
   3652 	  if (! in_bitfield_range (val, 0x1f))
   3653 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3654 			  _("relocation overflow"));
   3655 	  insn |= val & 0x1f;
   3656 	  break;
   3657 
   3658 	case BFD_RELOC_SPARC_WDISP10:
   3659 	  if ((val & 3)
   3660 	      || val >= 0x007fc
   3661 	      || val <= -(offsetT) 0x808)
   3662 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3663 			  _("relocation overflow"));
   3664 	  /* FIXME: The +1 deserves a comment.  */
   3665 	  val = (val >> 2) + 1;
   3666 	  insn |= ((val & 0x300) << 11)
   3667 	    | ((val & 0xff) << 5);
   3668 	  break;
   3669 
   3670 	case BFD_RELOC_SPARC_WDISP16:
   3671 	  if ((val & 3)
   3672 	      || val >= 0x1fffc
   3673 	      || val <= -(offsetT) 0x20008)
   3674 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3675 			  _("relocation overflow"));
   3676 	  /* FIXME: The +1 deserves a comment.  */
   3677 	  val = (val >> 2) + 1;
   3678 	  insn |= ((val & 0xc000) << 6) | (val & 0x3fff);
   3679 	  break;
   3680 
   3681 	case BFD_RELOC_SPARC_WDISP19:
   3682 	  if ((val & 3)
   3683 	      || val >= 0xffffc
   3684 	      || val <= -(offsetT) 0x100008)
   3685 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3686 			  _("relocation overflow"));
   3687 	  /* FIXME: The +1 deserves a comment.  */
   3688 	  val = (val >> 2) + 1;
   3689 	  insn |= val & 0x7ffff;
   3690 	  break;
   3691 
   3692 	case BFD_RELOC_SPARC_HH22:
   3693 	  val = BSR (val, 32);
   3694 	  /* Fall through.  */
   3695 
   3696 	case BFD_RELOC_SPARC_LM22:
   3697 	case BFD_RELOC_HI22:
   3698 	  if (!fixP->fx_addsy)
   3699 	    insn |= (val >> 10) & 0x3fffff;
   3700 	  else
   3701 	    /* FIXME: Need comment explaining why we do this.  */
   3702 	    insn &= ~0xffff;
   3703 	  break;
   3704 
   3705 	case BFD_RELOC_SPARC22:
   3706 	  if (val & ~0x003fffff)
   3707 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3708 			  _("relocation overflow"));
   3709 	  insn |= (val & 0x3fffff);
   3710 	  break;
   3711 
   3712 	case BFD_RELOC_SPARC_HM10:
   3713 	  val = BSR (val, 32);
   3714 	  /* Fall through.  */
   3715 
   3716 	case BFD_RELOC_LO10:
   3717 	  if (!fixP->fx_addsy)
   3718 	    insn |= val & 0x3ff;
   3719 	  else
   3720 	    /* FIXME: Need comment explaining why we do this.  */
   3721 	    insn &= ~0xff;
   3722 	  break;
   3723 
   3724 	case BFD_RELOC_SPARC_OLO10:
   3725 	  val &= 0x3ff;
   3726 	  val += fixP->tc_fix_data;
   3727 	  /* Fall through.  */
   3728 
   3729 	case BFD_RELOC_SPARC13:
   3730 	  if (! in_signed_range (val, 0x1fff))
   3731 	    as_bad_where (fixP->fx_file, fixP->fx_line,
   3732 			  _("relocation overflow"));
   3733 	  insn |= val & 0x1fff;
   3734 	  break;
   3735 
   3736 	case BFD_RELOC_SPARC_WDISP22:
   3737 	  val = (val >> 2) + 1;
   3738 	  /* Fall through.  */
   3739 	case BFD_RELOC_SPARC_BASE22:
   3740 	  insn |= val & 0x3fffff;
   3741 	  break;
   3742 
   3743 	case BFD_RELOC_SPARC_H34:
   3744 	  if (!fixP->fx_addsy)
   3745 	    {
   3746 	      bfd_vma tval = val;
   3747 	      tval >>= 12;
   3748 	      insn |= tval & 0x3fffff;
   3749 	    }
   3750 	  break;
   3751 
   3752 	case BFD_RELOC_SPARC_H44:
   3753 	  if (!fixP->fx_addsy)
   3754 	    {
   3755 	      bfd_vma tval = val;
   3756 	      tval >>= 22;
   3757 	      insn |= tval & 0x3fffff;
   3758 	    }
   3759 	  break;
   3760 
   3761 	case BFD_RELOC_SPARC_M44:
   3762 	  if (!fixP->fx_addsy)
   3763 	    insn |= (val >> 12) & 0x3ff;
   3764 	  break;
   3765 
   3766 	case BFD_RELOC_SPARC_L44:
   3767 	  if (!fixP->fx_addsy)
   3768 	    insn |= val & 0xfff;
   3769 	  break;
   3770 
   3771 	case BFD_RELOC_SPARC_HIX22:
   3772 	  if (!fixP->fx_addsy)
   3773 	    {
   3774 	      val ^= ~(offsetT) 0;
   3775 	      insn |= (val >> 10) & 0x3fffff;
   3776 	    }
   3777 	  break;
   3778 
   3779 	case BFD_RELOC_SPARC_LOX10:
   3780 	  if (!fixP->fx_addsy)
   3781 	    insn |= 0x1c00 | (val & 0x3ff);
   3782 	  break;
   3783 
   3784 	case BFD_RELOC_NONE:
   3785 	default:
   3786 	  as_bad_where (fixP->fx_file, fixP->fx_line,
   3787 			_("bad or unhandled relocation type: 0x%02x"),
   3788 			fixP->fx_r_type);
   3789 	  break;
   3790 	}
   3791 
   3792       if (INSN_BIG_ENDIAN)
   3793 	bfd_putb32 (insn, (unsigned char *) buf);
   3794       else
   3795 	bfd_putl32 (insn, (unsigned char *) buf);
   3796     }
   3797 
   3798   /* Are we finished with this relocation now?  */
   3799   if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
   3800     fixP->fx_done = 1;
   3801 }
   3802 
   3803 /* Translate internal representation of relocation info to BFD target
   3804    format.  */
   3805 
   3806 arelent **
   3807 tc_gen_reloc (asection *section, fixS *fixp)
   3808 {
   3809   static arelent *relocs[3];
   3810   arelent *reloc;
   3811   bfd_reloc_code_real_type code;
   3812 
   3813   relocs[0] = reloc = XNEW (arelent);
   3814   relocs[1] = NULL;
   3815 
   3816   reloc->sym_ptr_ptr = XNEW (asymbol *);
   3817   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   3818   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
   3819 
   3820   switch (fixp->fx_r_type)
   3821     {
   3822     case BFD_RELOC_16:
   3823     case BFD_RELOC_32:
   3824     case BFD_RELOC_HI22:
   3825     case BFD_RELOC_LO10:
   3826     case BFD_RELOC_32_PCREL_S2:
   3827     case BFD_RELOC_SPARC13:
   3828     case BFD_RELOC_SPARC22:
   3829     case BFD_RELOC_SPARC_PC22:
   3830     case BFD_RELOC_SPARC_PC10:
   3831     case BFD_RELOC_SPARC_BASE13:
   3832     case BFD_RELOC_SPARC_WDISP10:
   3833     case BFD_RELOC_SPARC_WDISP16:
   3834     case BFD_RELOC_SPARC_WDISP19:
   3835     case BFD_RELOC_SPARC_WDISP22:
   3836     case BFD_RELOC_64:
   3837     case BFD_RELOC_SPARC_5:
   3838     case BFD_RELOC_SPARC_6:
   3839     case BFD_RELOC_SPARC_7:
   3840     case BFD_RELOC_SPARC_10:
   3841     case BFD_RELOC_SPARC_11:
   3842     case BFD_RELOC_SPARC_HH22:
   3843     case BFD_RELOC_SPARC_HM10:
   3844     case BFD_RELOC_SPARC_LM22:
   3845     case BFD_RELOC_SPARC_PC_HH22:
   3846     case BFD_RELOC_SPARC_PC_HM10:
   3847     case BFD_RELOC_SPARC_PC_LM22:
   3848     case BFD_RELOC_SPARC_H34:
   3849     case BFD_RELOC_SPARC_H44:
   3850     case BFD_RELOC_SPARC_M44:
   3851     case BFD_RELOC_SPARC_L44:
   3852     case BFD_RELOC_SPARC_HIX22:
   3853     case BFD_RELOC_SPARC_LOX10:
   3854     case BFD_RELOC_SPARC_REV32:
   3855     case BFD_RELOC_SPARC_OLO10:
   3856     case BFD_RELOC_SPARC_UA16:
   3857     case BFD_RELOC_SPARC_UA32:
   3858     case BFD_RELOC_SPARC_UA64:
   3859     case BFD_RELOC_8_PCREL:
   3860     case BFD_RELOC_16_PCREL:
   3861     case BFD_RELOC_32_PCREL:
   3862     case BFD_RELOC_64_PCREL:
   3863     case BFD_RELOC_SPARC_PLT32:
   3864     case BFD_RELOC_SPARC_PLT64:
   3865     case BFD_RELOC_VTABLE_ENTRY:
   3866     case BFD_RELOC_VTABLE_INHERIT:
   3867     case BFD_RELOC_SPARC_TLS_GD_HI22:
   3868     case BFD_RELOC_SPARC_TLS_GD_LO10:
   3869     case BFD_RELOC_SPARC_TLS_GD_ADD:
   3870     case BFD_RELOC_SPARC_TLS_GD_CALL:
   3871     case BFD_RELOC_SPARC_TLS_LDM_HI22:
   3872     case BFD_RELOC_SPARC_TLS_LDM_LO10:
   3873     case BFD_RELOC_SPARC_TLS_LDM_ADD:
   3874     case BFD_RELOC_SPARC_TLS_LDM_CALL:
   3875     case BFD_RELOC_SPARC_TLS_LDO_HIX22:
   3876     case BFD_RELOC_SPARC_TLS_LDO_LOX10:
   3877     case BFD_RELOC_SPARC_TLS_LDO_ADD:
   3878     case BFD_RELOC_SPARC_TLS_IE_HI22:
   3879     case BFD_RELOC_SPARC_TLS_IE_LO10:
   3880     case BFD_RELOC_SPARC_TLS_IE_LD:
   3881     case BFD_RELOC_SPARC_TLS_IE_LDX:
   3882     case BFD_RELOC_SPARC_TLS_IE_ADD:
   3883     case BFD_RELOC_SPARC_TLS_LE_HIX22:
   3884     case BFD_RELOC_SPARC_TLS_LE_LOX10:
   3885     case BFD_RELOC_SPARC_TLS_DTPOFF32:
   3886     case BFD_RELOC_SPARC_TLS_DTPOFF64:
   3887     case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
   3888     case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
   3889     case BFD_RELOC_SPARC_GOTDATA_OP:
   3890       code = fixp->fx_r_type;
   3891       break;
   3892     default:
   3893       abort ();
   3894       return NULL;
   3895     }
   3896 
   3897 #if defined (OBJ_ELF) || defined (OBJ_AOUT)
   3898   /* If we are generating PIC code, we need to generate a different
   3899      set of relocs.  */
   3900 
   3901 #ifdef OBJ_ELF
   3902 #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
   3903 #else
   3904 #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
   3905 #endif
   3906 #ifdef TE_VXWORKS
   3907 #define GOTT_BASE "__GOTT_BASE__"
   3908 #define GOTT_INDEX "__GOTT_INDEX__"
   3909 #endif
   3910 
   3911   /* This code must be parallel to the OBJ_ELF tc_fix_adjustable.  */
   3912 
   3913   if (sparc_pic_code)
   3914     {
   3915       switch (code)
   3916 	{
   3917 	case BFD_RELOC_32_PCREL_S2:
   3918 	  if (generic_force_reloc (fixp))
   3919 	    code = BFD_RELOC_SPARC_WPLT30;
   3920 	  break;
   3921 	case BFD_RELOC_HI22:
   3922 	  code = BFD_RELOC_SPARC_GOT22;
   3923 	  if (fixp->fx_addsy != NULL)
   3924 	    {
   3925 	      if (strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
   3926 		code = BFD_RELOC_SPARC_PC22;
   3927 #ifdef TE_VXWORKS
   3928 	      if (strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_BASE) == 0
   3929 		  || strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_INDEX) == 0)
   3930 		code = BFD_RELOC_HI22; /* Unchanged.  */
   3931 #endif
   3932 	    }
   3933 	  break;
   3934 	case BFD_RELOC_LO10:
   3935 	  code = BFD_RELOC_SPARC_GOT10;
   3936 	  if (fixp->fx_addsy != NULL)
   3937 	    {
   3938 	      if (strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
   3939 		code = BFD_RELOC_SPARC_PC10;
   3940 #ifdef TE_VXWORKS
   3941 	      if (strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_BASE) == 0
   3942 		  || strcmp (S_GET_NAME (fixp->fx_addsy), GOTT_INDEX) == 0)
   3943 		code = BFD_RELOC_LO10; /* Unchanged.  */
   3944 #endif
   3945 	    }
   3946 	  break;
   3947 	case BFD_RELOC_SPARC13:
   3948 	  code = BFD_RELOC_SPARC_GOT13;
   3949 	  break;
   3950 	default:
   3951 	  break;
   3952 	}
   3953     }
   3954 #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT)  */
   3955 
   3956   /* Nothing is aligned in DWARF debugging sections.  */
   3957   if (bfd_get_section_flags (stdoutput, section) & SEC_DEBUGGING)
   3958     switch (code)
   3959       {
   3960       case BFD_RELOC_16: code = BFD_RELOC_SPARC_UA16; break;
   3961       case BFD_RELOC_32: code = BFD_RELOC_SPARC_UA32; break;
   3962       case BFD_RELOC_64: code = BFD_RELOC_SPARC_UA64; break;
   3963       default: break;
   3964       }
   3965 
   3966   if (code == BFD_RELOC_SPARC_OLO10)
   3967     reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_LO10);
   3968   else
   3969     reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
   3970   if (reloc->howto == 0)
   3971     {
   3972       as_bad_where (fixp->fx_file, fixp->fx_line,
   3973 		    _("internal error: can't export reloc type %d (`%s')"),
   3974 		    fixp->fx_r_type, bfd_get_reloc_code_name (code));
   3975       xfree (reloc);
   3976       relocs[0] = NULL;
   3977       return relocs;
   3978     }
   3979 
   3980   /* @@ Why fx_addnumber sometimes and fx_offset other times?  */
   3981 #ifdef OBJ_AOUT
   3982 
   3983   if (reloc->howto->pc_relative == 0
   3984       || code == BFD_RELOC_SPARC_PC10
   3985       || code == BFD_RELOC_SPARC_PC22)
   3986     reloc->addend = fixp->fx_addnumber;
   3987   else if (sparc_pic_code
   3988 	   && fixp->fx_r_type == BFD_RELOC_32_PCREL_S2
   3989 	   && fixp->fx_addsy != NULL
   3990 	   && (S_IS_EXTERNAL (fixp->fx_addsy)
   3991 	       || S_IS_WEAK (fixp->fx_addsy))
   3992 	   && S_IS_DEFINED (fixp->fx_addsy)
   3993 	   && ! S_IS_COMMON (fixp->fx_addsy))
   3994     reloc->addend = fixp->fx_addnumber;
   3995   else
   3996     reloc->addend = fixp->fx_offset - reloc->address;
   3997 
   3998 #else /* elf or coff  */
   3999 
   4000   if (code != BFD_RELOC_32_PCREL_S2
   4001       && code != BFD_RELOC_SPARC_WDISP22
   4002       && code != BFD_RELOC_SPARC_WDISP16
   4003       && code != BFD_RELOC_SPARC_WDISP19
   4004       && code != BFD_RELOC_SPARC_WDISP10
   4005       && code != BFD_RELOC_SPARC_WPLT30
   4006       && code != BFD_RELOC_SPARC_TLS_GD_CALL
   4007       && code != BFD_RELOC_SPARC_TLS_LDM_CALL)
   4008     reloc->addend = fixp->fx_addnumber;
   4009   else if (symbol_section_p (fixp->fx_addsy))
   4010     reloc->addend = (section->vma
   4011 		     + fixp->fx_addnumber
   4012 		     + md_pcrel_from (fixp));
   4013   else
   4014     reloc->addend = fixp->fx_offset;
   4015 #endif
   4016 
   4017   /* We expand R_SPARC_OLO10 to R_SPARC_LO10 and R_SPARC_13
   4018      on the same location.  */
   4019   if (code == BFD_RELOC_SPARC_OLO10)
   4020     {
   4021       relocs[1] = reloc = XNEW (arelent);
   4022       relocs[2] = NULL;
   4023 
   4024       reloc->sym_ptr_ptr = XNEW (asymbol *);
   4025       *reloc->sym_ptr_ptr
   4026 	= symbol_get_bfdsym (section_symbol (absolute_section));
   4027       reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
   4028       reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_SPARC13);
   4029       reloc->addend = fixp->tc_fix_data;
   4030     }
   4031 
   4032   return relocs;
   4033 }
   4034 
   4035 /* We have no need to default values of symbols.  */
   4037 
   4038 symbolS *
   4039 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
   4040 {
   4041   return 0;
   4042 }
   4043 
   4044 /* Round up a section size to the appropriate boundary.  */
   4045 
   4046 valueT
   4047 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
   4048 {
   4049 #ifndef OBJ_ELF
   4050   /* This is not right for ELF; a.out wants it, and COFF will force
   4051      the alignment anyways.  */
   4052   valueT align = ((valueT) 1
   4053 		  << (valueT) bfd_get_section_alignment (stdoutput, segment));
   4054   valueT newsize;
   4055 
   4056   /* Turn alignment value into a mask.  */
   4057   align--;
   4058   newsize = (size + align) & ~align;
   4059   return newsize;
   4060 #else
   4061   return size;
   4062 #endif
   4063 }
   4064 
   4065 /* Exactly what point is a PC-relative offset relative TO?
   4066    On the sparc, they're relative to the address of the offset, plus
   4067    its size.  This gets us to the following instruction.
   4068    (??? Is this right?  FIXME-SOON)  */
   4069 long
   4070 md_pcrel_from (fixS *fixP)
   4071 {
   4072   long ret;
   4073 
   4074   ret = fixP->fx_where + fixP->fx_frag->fr_address;
   4075   if (! sparc_pic_code
   4076       || fixP->fx_addsy == NULL
   4077       || symbol_section_p (fixP->fx_addsy))
   4078     ret += fixP->fx_size;
   4079   return ret;
   4080 }
   4081 
   4082 /* Return log2 (VALUE), or -1 if VALUE is not an exact positive power
   4084    of two.  */
   4085 
   4086 static int
   4087 mylog2 (int value)
   4088 {
   4089   int shift;
   4090 
   4091   if (value <= 0)
   4092     return -1;
   4093 
   4094   for (shift = 0; (value & 1) == 0; value >>= 1)
   4095     ++shift;
   4096 
   4097   return (value == 1) ? shift : -1;
   4098 }
   4099 
   4100 /* Sort of like s_lcomm.  */
   4101 
   4102 #ifndef OBJ_ELF
   4103 static int max_alignment = 15;
   4104 #endif
   4105 
   4106 static void
   4107 s_reserve (int ignore ATTRIBUTE_UNUSED)
   4108 {
   4109   char *name;
   4110   char *p;
   4111   char c;
   4112   int align;
   4113   int size;
   4114   int temp;
   4115   symbolS *symbolP;
   4116 
   4117   c = get_symbol_name (&name);
   4118   p = input_line_pointer;
   4119   *p = c;
   4120   SKIP_WHITESPACE_AFTER_NAME ();
   4121 
   4122   if (*input_line_pointer != ',')
   4123     {
   4124       as_bad (_("Expected comma after name"));
   4125       ignore_rest_of_line ();
   4126       return;
   4127     }
   4128 
   4129   ++input_line_pointer;
   4130 
   4131   if ((size = get_absolute_expression ()) < 0)
   4132     {
   4133       as_bad (_("BSS length (%d.) <0! Ignored."), size);
   4134       ignore_rest_of_line ();
   4135       return;
   4136     }				/* Bad length.  */
   4137 
   4138   *p = 0;
   4139   symbolP = symbol_find_or_make (name);
   4140   *p = c;
   4141 
   4142   if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
   4143       && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
   4144     {
   4145       as_bad (_("bad .reserve segment -- expected BSS segment"));
   4146       return;
   4147     }
   4148 
   4149   if (input_line_pointer[2] == '.')
   4150     input_line_pointer += 7;
   4151   else
   4152     input_line_pointer += 6;
   4153   SKIP_WHITESPACE ();
   4154 
   4155   if (*input_line_pointer == ',')
   4156     {
   4157       ++input_line_pointer;
   4158 
   4159       SKIP_WHITESPACE ();
   4160       if (*input_line_pointer == '\n')
   4161 	{
   4162 	  as_bad (_("missing alignment"));
   4163 	  ignore_rest_of_line ();
   4164 	  return;
   4165 	}
   4166 
   4167       align = (int) get_absolute_expression ();
   4168 
   4169 #ifndef OBJ_ELF
   4170       if (align > max_alignment)
   4171 	{
   4172 	  align = max_alignment;
   4173 	  as_warn (_("alignment too large; assuming %d"), align);
   4174 	}
   4175 #endif
   4176 
   4177       if (align < 0)
   4178 	{
   4179 	  as_bad (_("negative alignment"));
   4180 	  ignore_rest_of_line ();
   4181 	  return;
   4182 	}
   4183 
   4184       if (align != 0)
   4185 	{
   4186 	  temp = mylog2 (align);
   4187 	  if (temp < 0)
   4188 	    {
   4189 	      as_bad (_("alignment not a power of 2"));
   4190 	      ignore_rest_of_line ();
   4191 	      return;
   4192 	    }
   4193 
   4194 	  align = temp;
   4195 	}
   4196 
   4197       record_alignment (bss_section, align);
   4198     }
   4199   else
   4200     align = 0;
   4201 
   4202   if (!S_IS_DEFINED (symbolP)
   4203 #ifdef OBJ_AOUT
   4204       && S_GET_OTHER (symbolP) == 0
   4205       && S_GET_DESC (symbolP) == 0
   4206 #endif
   4207       )
   4208     {
   4209       if (! need_pass_2)
   4210 	{
   4211 	  char *pfrag;
   4212 	  segT current_seg = now_seg;
   4213 	  subsegT current_subseg = now_subseg;
   4214 
   4215 	  /* Switch to bss.  */
   4216 	  subseg_set (bss_section, 1);
   4217 
   4218 	  if (align)
   4219 	    /* Do alignment.  */
   4220 	    frag_align (align, 0, 0);
   4221 
   4222 	  /* Detach from old frag.  */
   4223 	  if (S_GET_SEGMENT (symbolP) == bss_section)
   4224 	    symbol_get_frag (symbolP)->fr_symbol = NULL;
   4225 
   4226 	  symbol_set_frag (symbolP, frag_now);
   4227 	  pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
   4228 			    (offsetT) size, (char *) 0);
   4229 	  *pfrag = 0;
   4230 
   4231 	  S_SET_SEGMENT (symbolP, bss_section);
   4232 
   4233 	  subseg_set (current_seg, current_subseg);
   4234 
   4235 #ifdef OBJ_ELF
   4236 	  S_SET_SIZE (symbolP, size);
   4237 #endif
   4238 	}
   4239     }
   4240   else
   4241     {
   4242       as_warn (_("Ignoring attempt to re-define symbol %s"),
   4243 	       S_GET_NAME (symbolP));
   4244     }
   4245 
   4246   demand_empty_rest_of_line ();
   4247 }
   4248 
   4249 static void
   4250 s_common (int ignore ATTRIBUTE_UNUSED)
   4251 {
   4252   char *name;
   4253   char c;
   4254   char *p;
   4255   offsetT temp, size;
   4256   symbolS *symbolP;
   4257 
   4258   c = get_symbol_name (&name);
   4259   /* Just after name is now '\0'.  */
   4260   p = input_line_pointer;
   4261   *p = c;
   4262   SKIP_WHITESPACE_AFTER_NAME ();
   4263   if (*input_line_pointer != ',')
   4264     {
   4265       as_bad (_("Expected comma after symbol-name"));
   4266       ignore_rest_of_line ();
   4267       return;
   4268     }
   4269 
   4270   /* Skip ','.  */
   4271   input_line_pointer++;
   4272 
   4273   if ((temp = get_absolute_expression ()) < 0)
   4274     {
   4275       as_bad (_(".COMMon length (%lu) out of range ignored"),
   4276 	      (unsigned long) temp);
   4277       ignore_rest_of_line ();
   4278       return;
   4279     }
   4280   size = temp;
   4281   *p = 0;
   4282   symbolP = symbol_find_or_make (name);
   4283   *p = c;
   4284   if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
   4285     {
   4286       as_bad (_("Ignoring attempt to re-define symbol"));
   4287       ignore_rest_of_line ();
   4288       return;
   4289     }
   4290   if (S_GET_VALUE (symbolP) != 0)
   4291     {
   4292       if (S_GET_VALUE (symbolP) != (valueT) size)
   4293 	{
   4294 	  as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
   4295 		   S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), (long) size);
   4296 	}
   4297     }
   4298   else
   4299     {
   4300 #ifndef OBJ_ELF
   4301       S_SET_VALUE (symbolP, (valueT) size);
   4302       S_SET_EXTERNAL (symbolP);
   4303 #endif
   4304     }
   4305   know (symbol_get_frag (symbolP) == &zero_address_frag);
   4306   if (*input_line_pointer != ',')
   4307     {
   4308       as_bad (_("Expected comma after common length"));
   4309       ignore_rest_of_line ();
   4310       return;
   4311     }
   4312   input_line_pointer++;
   4313   SKIP_WHITESPACE ();
   4314   if (*input_line_pointer != '"')
   4315     {
   4316       temp = get_absolute_expression ();
   4317 
   4318 #ifndef OBJ_ELF
   4319       if (temp > max_alignment)
   4320 	{
   4321 	  temp = max_alignment;
   4322 	  as_warn (_("alignment too large; assuming %ld"), (long) temp);
   4323 	}
   4324 #endif
   4325 
   4326       if (temp < 0)
   4327 	{
   4328 	  as_bad (_("negative alignment"));
   4329 	  ignore_rest_of_line ();
   4330 	  return;
   4331 	}
   4332 
   4333 #ifdef OBJ_ELF
   4334       if (symbol_get_obj (symbolP)->local)
   4335 	{
   4336 	  segT old_sec;
   4337 	  int old_subsec;
   4338 	  int align;
   4339 
   4340 	  old_sec = now_seg;
   4341 	  old_subsec = now_subseg;
   4342 
   4343 	  if (temp == 0)
   4344 	    align = 0;
   4345 	  else
   4346 	    align = mylog2 (temp);
   4347 
   4348 	  if (align < 0)
   4349 	    {
   4350 	      as_bad (_("alignment not a power of 2"));
   4351 	      ignore_rest_of_line ();
   4352 	      return;
   4353 	    }
   4354 
   4355 	  record_alignment (bss_section, align);
   4356 	  subseg_set (bss_section, 0);
   4357 	  if (align)
   4358 	    frag_align (align, 0, 0);
   4359 	  if (S_GET_SEGMENT (symbolP) == bss_section)
   4360 	    symbol_get_frag (symbolP)->fr_symbol = 0;
   4361 	  symbol_set_frag (symbolP, frag_now);
   4362 	  p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
   4363 			(offsetT) size, (char *) 0);
   4364 	  *p = 0;
   4365 	  S_SET_SEGMENT (symbolP, bss_section);
   4366 	  S_CLEAR_EXTERNAL (symbolP);
   4367 	  S_SET_SIZE (symbolP, size);
   4368 	  subseg_set (old_sec, old_subsec);
   4369 	}
   4370       else
   4371 #endif /* OBJ_ELF  */
   4372 	{
   4373 	allocate_common:
   4374 	  S_SET_VALUE (symbolP, (valueT) size);
   4375 #ifdef OBJ_ELF
   4376 	  S_SET_ALIGN (symbolP, temp);
   4377 	  S_SET_SIZE (symbolP, size);
   4378 #endif
   4379 	  S_SET_EXTERNAL (symbolP);
   4380 	  S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
   4381 	}
   4382     }
   4383   else
   4384     {
   4385       input_line_pointer++;
   4386       /* @@ Some use the dot, some don't.  Can we get some consistency??  */
   4387       if (*input_line_pointer == '.')
   4388 	input_line_pointer++;
   4389       /* @@ Some say data, some say bss.  */
   4390       if (strncmp (input_line_pointer, "bss\"", 4)
   4391 	  && strncmp (input_line_pointer, "data\"", 5))
   4392 	{
   4393 	  while (*--input_line_pointer != '"')
   4394 	    ;
   4395 	  input_line_pointer--;
   4396 	  goto bad_common_segment;
   4397 	}
   4398       while (*input_line_pointer++ != '"')
   4399 	;
   4400       goto allocate_common;
   4401     }
   4402 
   4403   symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
   4404 
   4405   demand_empty_rest_of_line ();
   4406   return;
   4407 
   4408   {
   4409   bad_common_segment:
   4410     p = input_line_pointer;
   4411     while (*p && *p != '\n')
   4412       p++;
   4413     c = *p;
   4414     *p = '\0';
   4415     as_bad (_("bad .common segment %s"), input_line_pointer + 1);
   4416     *p = c;
   4417     input_line_pointer = p;
   4418     ignore_rest_of_line ();
   4419     return;
   4420   }
   4421 }
   4422 
   4423 /* Handle the .empty pseudo-op.  This suppresses the warnings about
   4424    invalid delay slot usage.  */
   4425 
   4426 static void
   4427 s_empty (int ignore ATTRIBUTE_UNUSED)
   4428 {
   4429   /* The easy way to implement is to just forget about the last
   4430      instruction.  */
   4431   last_insn = NULL;
   4432 }
   4433 
   4434 static void
   4435 s_seg (int ignore ATTRIBUTE_UNUSED)
   4436 {
   4437 
   4438   if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
   4439     {
   4440       input_line_pointer += 6;
   4441       s_text (0);
   4442       return;
   4443     }
   4444   if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
   4445     {
   4446       input_line_pointer += 6;
   4447       s_data (0);
   4448       return;
   4449     }
   4450   if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
   4451     {
   4452       input_line_pointer += 7;
   4453       s_data1 ();
   4454       return;
   4455     }
   4456   if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
   4457     {
   4458       input_line_pointer += 5;
   4459       /* We only support 2 segments -- text and data -- for now, so
   4460 	 things in the "bss segment" will have to go into data for now.
   4461 	 You can still allocate SEG_BSS stuff with .lcomm or .reserve.  */
   4462       subseg_set (data_section, 255);	/* FIXME-SOMEDAY.  */
   4463       return;
   4464     }
   4465   as_bad (_("Unknown segment type"));
   4466   demand_empty_rest_of_line ();
   4467 }
   4468 
   4469 static void
   4470 s_data1 (void)
   4471 {
   4472   subseg_set (data_section, 1);
   4473   demand_empty_rest_of_line ();
   4474 }
   4475 
   4476 static void
   4477 s_proc (int ignore ATTRIBUTE_UNUSED)
   4478 {
   4479   while (!is_end_of_line[(unsigned char) *input_line_pointer])
   4480     {
   4481       ++input_line_pointer;
   4482     }
   4483   ++input_line_pointer;
   4484 }
   4485 
   4486 /* This static variable is set by s_uacons to tell sparc_cons_align
   4487    that the expression does not need to be aligned.  */
   4488 
   4489 static int sparc_no_align_cons = 0;
   4490 
   4491 /* This handles the unaligned space allocation pseudo-ops, such as
   4492    .uaword.  .uaword is just like .word, but the value does not need
   4493    to be aligned.  */
   4494 
   4495 static void
   4496 s_uacons (int bytes)
   4497 {
   4498   /* Tell sparc_cons_align not to align this value.  */
   4499   sparc_no_align_cons = 1;
   4500   cons (bytes);
   4501   sparc_no_align_cons = 0;
   4502 }
   4503 
   4504 /* This handles the native word allocation pseudo-op .nword.
   4505    For sparc_arch_size 32 it is equivalent to .word,  for
   4506    sparc_arch_size 64 it is equivalent to .xword.  */
   4507 
   4508 static void
   4509 s_ncons (int bytes ATTRIBUTE_UNUSED)
   4510 {
   4511   cons (sparc_arch_size == 32 ? 4 : 8);
   4512 }
   4513 
   4514 #ifdef OBJ_ELF
   4515 /* Handle the SPARC ELF .register pseudo-op.  This sets the binding of a
   4516    global register.
   4517    The syntax is:
   4518 
   4519    .register %g[2367],{#scratch|symbolname|#ignore}
   4520 */
   4521 
   4522 static void
   4523 s_register (int ignore ATTRIBUTE_UNUSED)
   4524 {
   4525   char c;
   4526   int reg;
   4527   int flags;
   4528   char *regname;
   4529 
   4530   if (input_line_pointer[0] != '%'
   4531       || input_line_pointer[1] != 'g'
   4532       || ((input_line_pointer[2] & ~1) != '2'
   4533 	  && (input_line_pointer[2] & ~1) != '6')
   4534       || input_line_pointer[3] != ',')
   4535     as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
   4536   reg = input_line_pointer[2] - '0';
   4537   input_line_pointer += 4;
   4538 
   4539   if (*input_line_pointer == '#')
   4540     {
   4541       ++input_line_pointer;
   4542       c = get_symbol_name (&regname);
   4543       if (strcmp (regname, "scratch") && strcmp (regname, "ignore"))
   4544 	as_bad (_("register syntax is .register %%g[2367],{#scratch|symbolname|#ignore}"));
   4545       if (regname[0] == 'i')
   4546 	regname = NULL;
   4547       else
   4548 	regname = (char *) "";
   4549     }
   4550   else
   4551     {
   4552       c = get_symbol_name (&regname);
   4553     }
   4554 
   4555   if (sparc_arch_size == 64)
   4556     {
   4557       if (globals[reg])
   4558 	{
   4559 	  if ((regname && globals[reg] != (symbolS *) 1
   4560 	       && strcmp (S_GET_NAME (globals[reg]), regname))
   4561 	      || ((regname != NULL) ^ (globals[reg] != (symbolS *) 1)))
   4562 	    as_bad (_("redefinition of global register"));
   4563 	}
   4564       else
   4565 	{
   4566 	  if (regname == NULL)
   4567 	    globals[reg] = (symbolS *) 1;
   4568 	  else
   4569 	    {
   4570 	      if (*regname)
   4571 		{
   4572 		  if (symbol_find (regname))
   4573 		    as_bad (_("Register symbol %s already defined."),
   4574 			    regname);
   4575 		}
   4576 	      globals[reg] = symbol_make (regname);
   4577 	      flags = symbol_get_bfdsym (globals[reg])->flags;
   4578 	      if (! *regname)
   4579 		flags = flags & ~(BSF_GLOBAL|BSF_LOCAL|BSF_WEAK);
   4580 	      if (! (flags & (BSF_GLOBAL|BSF_LOCAL|BSF_WEAK)))
   4581 		flags |= BSF_GLOBAL;
   4582 	      symbol_get_bfdsym (globals[reg])->flags = flags;
   4583 	      S_SET_VALUE (globals[reg], (valueT) reg);
   4584 	      S_SET_ALIGN (globals[reg], reg);
   4585 	      S_SET_SIZE (globals[reg], 0);
   4586 	      /* Although we actually want undefined_section here,
   4587 		 we have to use absolute_section, because otherwise
   4588 		 generic as code will make it a COM section.
   4589 		 We fix this up in sparc_adjust_symtab.  */
   4590 	      S_SET_SEGMENT (globals[reg], absolute_section);
   4591 	      S_SET_OTHER (globals[reg], 0);
   4592 	      elf_symbol (symbol_get_bfdsym (globals[reg]))
   4593 		->internal_elf_sym.st_info =
   4594 		  ELF_ST_INFO(STB_GLOBAL, STT_REGISTER);
   4595 	      elf_symbol (symbol_get_bfdsym (globals[reg]))
   4596 		->internal_elf_sym.st_shndx = SHN_UNDEF;
   4597 	    }
   4598 	}
   4599     }
   4600 
   4601   (void) restore_line_pointer (c);
   4602 
   4603   demand_empty_rest_of_line ();
   4604 }
   4605 
   4606 /* Adjust the symbol table.  We set undefined sections for STT_REGISTER
   4607    symbols which need it.  */
   4608 
   4609 void
   4610 sparc_adjust_symtab (void)
   4611 {
   4612   symbolS *sym;
   4613 
   4614   for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
   4615     {
   4616       if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym))
   4617 		       ->internal_elf_sym.st_info) != STT_REGISTER)
   4618 	continue;
   4619 
   4620       if (ELF_ST_TYPE (elf_symbol (symbol_get_bfdsym (sym))
   4621 		       ->internal_elf_sym.st_shndx != SHN_UNDEF))
   4622 	continue;
   4623 
   4624       S_SET_SEGMENT (sym, undefined_section);
   4625     }
   4626 }
   4627 #endif
   4628 
   4629 /* If the --enforce-aligned-data option is used, we require .word,
   4630    et. al., to be aligned correctly.  We do it by setting up an
   4631    rs_align_code frag, and checking in HANDLE_ALIGN to make sure that
   4632    no unexpected alignment was introduced.
   4633 
   4634    The SunOS and Solaris native assemblers enforce aligned data by
   4635    default.  We don't want to do that, because gcc can deliberately
   4636    generate misaligned data if the packed attribute is used.  Instead,
   4637    we permit misaligned data by default, and permit the user to set an
   4638    option to check for it.  */
   4639 
   4640 void
   4641 sparc_cons_align (int nbytes)
   4642 {
   4643   int nalign;
   4644 
   4645   /* Only do this if we are enforcing aligned data.  */
   4646   if (! enforce_aligned_data)
   4647     return;
   4648 
   4649   /* Don't align if this is an unaligned pseudo-op.  */
   4650   if (sparc_no_align_cons)
   4651     return;
   4652 
   4653   nalign = mylog2 (nbytes);
   4654   if (nalign == 0)
   4655     return;
   4656 
   4657   gas_assert (nalign > 0);
   4658 
   4659   if (now_seg == absolute_section)
   4660     {
   4661       if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
   4662 	as_bad (_("misaligned data"));
   4663       return;
   4664     }
   4665 
   4666   frag_var (rs_align_test, 1, 1, (relax_substateT) 0,
   4667 	    (symbolS *) NULL, (offsetT) nalign, (char *) NULL);
   4668 
   4669   record_alignment (now_seg, nalign);
   4670 }
   4671 
   4672 /* This is called from HANDLE_ALIGN in tc-sparc.h.  */
   4673 
   4674 void
   4675 sparc_handle_align (fragS *fragp)
   4676 {
   4677   int count, fix;
   4678   char *p;
   4679 
   4680   count = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
   4681 
   4682   switch (fragp->fr_type)
   4683     {
   4684     case rs_align_test:
   4685       if (count != 0)
   4686 	as_bad_where (fragp->fr_file, fragp->fr_line, _("misaligned data"));
   4687       break;
   4688 
   4689     case rs_align_code:
   4690       p = fragp->fr_literal + fragp->fr_fix;
   4691       fix = 0;
   4692 
   4693       if (count & 3)
   4694 	{
   4695 	  fix = count & 3;
   4696 	  memset (p, 0, fix);
   4697 	  p += fix;
   4698 	  count -= fix;
   4699 	}
   4700 
   4701       if (SPARC_OPCODE_ARCH_V9_P (max_architecture) && count > 8)
   4702 	{
   4703 	  unsigned wval = (0x30680000 | count >> 2); /* ba,a,pt %xcc, 1f  */
   4704 	  if (INSN_BIG_ENDIAN)
   4705 	    number_to_chars_bigendian (p, wval, 4);
   4706 	  else
   4707 	    number_to_chars_littleendian (p, wval, 4);
   4708 	  p += 4;
   4709 	  count -= 4;
   4710 	  fix += 4;
   4711 	}
   4712 
   4713       if (INSN_BIG_ENDIAN)
   4714 	number_to_chars_bigendian (p, 0x01000000, 4);
   4715       else
   4716 	number_to_chars_littleendian (p, 0x01000000, 4);
   4717 
   4718       fragp->fr_fix += fix;
   4719       fragp->fr_var = 4;
   4720       break;
   4721 
   4722     default:
   4723       break;
   4724     }
   4725 }
   4726 
   4727 #ifdef OBJ_ELF
   4728 /* Some special processing for a Sparc ELF file.  */
   4729 
   4730 void
   4731 sparc_elf_final_processing (void)
   4732 {
   4733   /* Set the Sparc ELF flag bits.  FIXME: There should probably be some
   4734      sort of BFD interface for this.  */
   4735   if (sparc_arch_size == 64)
   4736     {
   4737       switch (sparc_memory_model)
   4738 	{
   4739 	case MM_RMO:
   4740 	  elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_RMO;
   4741 	  break;
   4742 	case MM_PSO:
   4743 	  elf_elfheader (stdoutput)->e_flags |= EF_SPARCV9_PSO;
   4744 	  break;
   4745 	default:
   4746 	  break;
   4747 	}
   4748     }
   4749   else if (current_architecture >= SPARC_OPCODE_ARCH_V9)
   4750     elf_elfheader (stdoutput)->e_flags |= EF_SPARC_32PLUS;
   4751   if (current_architecture == SPARC_OPCODE_ARCH_V9A)
   4752     elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1;
   4753   else if (current_architecture == SPARC_OPCODE_ARCH_V9B)
   4754     elf_elfheader (stdoutput)->e_flags |= EF_SPARC_SUN_US1|EF_SPARC_SUN_US3;
   4755 }
   4756 
   4757 const char *
   4758 sparc_cons (expressionS *exp, int size)
   4759 {
   4760   char *save;
   4761   const char *sparc_cons_special_reloc = NULL;
   4762 
   4763   SKIP_WHITESPACE ();
   4764   save = input_line_pointer;
   4765   if (input_line_pointer[0] == '%'
   4766       && input_line_pointer[1] == 'r'
   4767       && input_line_pointer[2] == '_')
   4768     {
   4769       if (strncmp (input_line_pointer + 3, "disp", 4) == 0)
   4770 	{
   4771 	  input_line_pointer += 7;
   4772 	  sparc_cons_special_reloc = "disp";
   4773 	}
   4774       else if (strncmp (input_line_pointer + 3, "plt", 3) == 0)
   4775 	{
   4776 	  if (size != 4 && size != 8)
   4777 	    as_bad (_("Illegal operands: %%r_plt in %d-byte data field"), size);
   4778 	  else
   4779 	    {
   4780 	      input_line_pointer += 6;
   4781 	      sparc_cons_special_reloc = "plt";
   4782 	    }
   4783 	}
   4784       else if (strncmp (input_line_pointer + 3, "tls_dtpoff", 10) == 0)
   4785 	{
   4786 	  if (size != 4 && size != 8)
   4787 	    as_bad (_("Illegal operands: %%r_tls_dtpoff in %d-byte data field"), size);
   4788 	  else
   4789 	    {
   4790 	      input_line_pointer += 13;
   4791 	      sparc_cons_special_reloc = "tls_dtpoff";
   4792 	    }
   4793 	}
   4794       if (sparc_cons_special_reloc)
   4795 	{
   4796 	  int bad = 0;
   4797 
   4798 	  switch (size)
   4799 	    {
   4800 	    case 1:
   4801 	      if (*input_line_pointer != '8')
   4802 		bad = 1;
   4803 	      input_line_pointer--;
   4804 	      break;
   4805 	    case 2:
   4806 	      if (input_line_pointer[0] != '1' || input_line_pointer[1] != '6')
   4807 		bad = 1;
   4808 	      break;
   4809 	    case 4:
   4810 	      if (input_line_pointer[0] != '3' || input_line_pointer[1] != '2')
   4811 		bad = 1;
   4812 	      break;
   4813 	    case 8:
   4814 	      if (input_line_pointer[0] != '6' || input_line_pointer[1] != '4')
   4815 		bad = 1;
   4816 	      break;
   4817 	    default:
   4818 	      bad = 1;
   4819 	      break;
   4820 	    }
   4821 
   4822 	  if (bad)
   4823 	    {
   4824 	      as_bad (_("Illegal operands: Only %%r_%s%d allowed in %d-byte data fields"),
   4825 		      sparc_cons_special_reloc, size * 8, size);
   4826 	    }
   4827 	  else
   4828 	    {
   4829 	      input_line_pointer += 2;
   4830 	      if (*input_line_pointer != '(')
   4831 		{
   4832 		  as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
   4833 			  sparc_cons_special_reloc, size * 8);
   4834 		  bad = 1;
   4835 		}
   4836 	    }
   4837 
   4838 	  if (bad)
   4839 	    {
   4840 	      input_line_pointer = save;
   4841 	      sparc_cons_special_reloc = NULL;
   4842 	    }
   4843 	  else
   4844 	    {
   4845 	      int c;
   4846 	      char *end = ++input_line_pointer;
   4847 	      int npar = 0;
   4848 
   4849 	      while (! is_end_of_line[(c = *end)])
   4850 		{
   4851 		  if (c == '(')
   4852 	  	    npar++;
   4853 		  else if (c == ')')
   4854 	  	    {
   4855 		      if (!npar)
   4856 	      		break;
   4857 		      npar--;
   4858 		    }
   4859 	    	  end++;
   4860 		}
   4861 
   4862 	      if (c != ')')
   4863 		as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
   4864 			sparc_cons_special_reloc, size * 8);
   4865 	      else
   4866 		{
   4867 		  *end = '\0';
   4868 		  expression (exp);
   4869 		  *end = c;
   4870 		  if (input_line_pointer != end)
   4871 		    {
   4872 		      as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
   4873 			      sparc_cons_special_reloc, size * 8);
   4874 		    }
   4875 		  else
   4876 		    {
   4877 		      input_line_pointer++;
   4878 		      SKIP_WHITESPACE ();
   4879 		      c = *input_line_pointer;
   4880 		      if (! is_end_of_line[c] && c != ',')
   4881 			as_bad (_("Illegal operands: garbage after %%r_%s%d()"),
   4882 			        sparc_cons_special_reloc, size * 8);
   4883 		    }
   4884 		}
   4885 	    }
   4886 	}
   4887     }
   4888   if (sparc_cons_special_reloc == NULL)
   4889     expression (exp);
   4890   return sparc_cons_special_reloc;
   4891 }
   4892 
   4893 #endif
   4894 
   4895 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
   4896    reloc for a cons.  We could use the definition there, except that
   4897    we want to handle little endian relocs specially.  */
   4898 
   4899 void
   4900 cons_fix_new_sparc (fragS *frag,
   4901 		    int where,
   4902 		    unsigned int nbytes,
   4903 		    expressionS *exp,
   4904 		    const char *sparc_cons_special_reloc)
   4905 {
   4906   bfd_reloc_code_real_type r;
   4907 
   4908   r = (nbytes == 1 ? BFD_RELOC_8 :
   4909        (nbytes == 2 ? BFD_RELOC_16 :
   4910 	(nbytes == 4 ? BFD_RELOC_32 : BFD_RELOC_64)));
   4911 
   4912   if (target_little_endian_data
   4913       && nbytes == 4
   4914       && now_seg->flags & SEC_ALLOC)
   4915     r = BFD_RELOC_SPARC_REV32;
   4916 
   4917   if (sparc_cons_special_reloc)
   4918     {
   4919       if (*sparc_cons_special_reloc == 'd')
   4920 	switch (nbytes)
   4921 	  {
   4922 	  case 1: r = BFD_RELOC_8_PCREL; break;
   4923 	  case 2: r = BFD_RELOC_16_PCREL; break;
   4924 	  case 4: r = BFD_RELOC_32_PCREL; break;
   4925 	  case 8: r = BFD_RELOC_64_PCREL; break;
   4926 	  default: abort ();
   4927 	  }
   4928       else if (*sparc_cons_special_reloc == 'p')
   4929 	switch (nbytes)
   4930 	  {
   4931 	  case 4: r = BFD_RELOC_SPARC_PLT32; break;
   4932 	  case 8: r = BFD_RELOC_SPARC_PLT64; break;
   4933 	  }
   4934       else
   4935 	switch (nbytes)
   4936 	  {
   4937 	  case 4: r = BFD_RELOC_SPARC_TLS_DTPOFF32; break;
   4938 	  case 8: r = BFD_RELOC_SPARC_TLS_DTPOFF64; break;
   4939 	  }
   4940     }
   4941   else if (sparc_no_align_cons)
   4942     {
   4943       switch (nbytes)
   4944 	{
   4945 	case 2: r = BFD_RELOC_SPARC_UA16; break;
   4946 	case 4: r = BFD_RELOC_SPARC_UA32; break;
   4947 	case 8: r = BFD_RELOC_SPARC_UA64; break;
   4948 	default: abort ();
   4949 	}
   4950    }
   4951 
   4952   fix_new_exp (frag, where, (int) nbytes, exp, 0, r);
   4953 }
   4954 
   4955 void
   4956 sparc_cfi_frame_initial_instructions (void)
   4957 {
   4958   cfi_add_CFA_def_cfa (14, sparc_arch_size == 64 ? 0x7ff : 0);
   4959 }
   4960 
   4961 int
   4962 sparc_regname_to_dw2regnum (char *regname)
   4963 {
   4964   char *q;
   4965   int i;
   4966 
   4967   if (!regname[0])
   4968     return -1;
   4969 
   4970   switch (regname[0])
   4971     {
   4972     case 'g': i = 0; break;
   4973     case 'o': i = 1; break;
   4974     case 'l': i = 2; break;
   4975     case 'i': i = 3; break;
   4976     default: i = -1; break;
   4977     }
   4978   if (i != -1)
   4979     {
   4980       if (regname[1] < '0' || regname[1] > '8' || regname[2])
   4981 	return -1;
   4982       return i * 8 + regname[1] - '0';
   4983     }
   4984   if (regname[0] == 's' && regname[1] == 'p' && !regname[2])
   4985     return 14;
   4986   if (regname[0] == 'f' && regname[1] == 'p' && !regname[2])
   4987     return 30;
   4988   if (regname[0] == 'f' || regname[0] == 'r')
   4989     {
   4990       unsigned int regnum;
   4991 
   4992       regnum = strtoul (regname + 1, &q, 10);
   4993       if (q == NULL || *q)
   4994         return -1;
   4995       if (regnum >= ((regname[0] == 'f'
   4996 		      && SPARC_OPCODE_ARCH_V9_P (max_architecture))
   4997 		     ? 64 : 32))
   4998 	return -1;
   4999       if (regname[0] == 'f')
   5000 	{
   5001           regnum += 32;
   5002           if (regnum >= 64 && (regnum & 1))
   5003 	    return -1;
   5004         }
   5005       return regnum;
   5006     }
   5007   return -1;
   5008 }
   5009 
   5010 void
   5011 sparc_cfi_emit_pcrel_expr (expressionS *exp, unsigned int nbytes)
   5012 {
   5013   sparc_no_align_cons = 1;
   5014   emit_expr_with_reloc (exp, nbytes, "disp");
   5015   sparc_no_align_cons = 0;
   5016 }
   5017