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