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