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