home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / gas / config / tc-sparc.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  64KB  |  2,773 lines

  1. /* tc-sparc.c -- Assemble for the SPARC
  2.    Copyright (C) 1989, 90-95, 1996 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public
  17.    License along with GAS; see the file COPYING.  If not, write
  18.    to the Free Software Foundation, 59 Temple Place - Suite 330,
  19.    Boston, MA 02111-1307, USA. */
  20.  
  21. #include <stdio.h>
  22. #include <ctype.h>
  23.  
  24. #include "as.h"
  25. #include "subsegs.h"
  26.  
  27. /* careful, this file includes data *declarations* */
  28. #include "opcode/sparc.h"
  29.  
  30. static void sparc_ip PARAMS ((char *, const struct sparc_opcode **));
  31.  
  32. /* Current architecture.  We don't bump up unless necessary.  */
  33. static enum sparc_opcode_arch_val current_architecture = SPARC_OPCODE_ARCH_V6;
  34.  
  35. /* The maximum architecture level we can bump up to.
  36.    In a 32 bit environment, don't allow bumping up to v9 by default.
  37.    The native assembler works this way. The user is required to pass
  38.    an explicit argument before we'll create v9 object files.  However, if
  39.    we don't see any v9 insns, a v9 object file is not created.  */
  40. #ifdef SPARC_ARCH64
  41. static enum sparc_opcode_arch_val max_architecture = SPARC_OPCODE_ARCH_V9;
  42. #else
  43. /* ??? This should be V8, but sparclite support was added by making it the
  44.    default.  GCC now passes -Asparclite, so maybe sometime in the future
  45.    we can set this to V8.  */
  46. static enum sparc_opcode_arch_val max_architecture = SPARC_OPCODE_ARCH_SPARCLITE;
  47. #endif
  48.  
  49. static int architecture_requested;
  50. static int warn_on_bump;
  51.  
  52. /* If warn_on_bump and the needed architecture is higher than this
  53.    architecture, issue a warning.  */
  54. static enum sparc_opcode_arch_val warn_after_architecture;
  55.  
  56. /* Non-zero if we are generating PIC code.  */
  57. int sparc_pic_code;
  58.  
  59. extern int target_big_endian;
  60.  
  61. /* handle of the OPCODE hash table */
  62. static struct hash_control *op_hash;
  63.  
  64. static void s_data1 PARAMS ((void));
  65. static void s_seg PARAMS ((int));
  66. static void s_proc PARAMS ((int));
  67. static void s_reserve PARAMS ((int));
  68. static void s_common PARAMS ((int));
  69. static void s_empty PARAMS ((int));
  70.  
  71. const pseudo_typeS md_pseudo_table[] =
  72. {
  73.   {"align", s_align_bytes, 0},    /* Defaulting is invalid (0) */
  74.   {"common", s_common, 0},
  75.   {"empty", s_empty, 0},
  76.   {"global", s_globl, 0},
  77.   {"half", cons, 2},
  78.   {"optim", s_ignore, 0},
  79.   {"proc", s_proc, 0},
  80.   {"reserve", s_reserve, 0},
  81.   {"seg", s_seg, 0},
  82.   {"skip", s_space, 0},
  83.   {"word", cons, 4},
  84.   {"xword", cons, 8},
  85. #ifdef OBJ_ELF
  86.   {"uaxword", cons, 8},
  87. #endif
  88. #ifdef OBJ_ELF
  89.   /* these are specific to sparc/svr4 */
  90.   {"pushsection", obj_elf_section, 0},
  91.   {"popsection", obj_elf_previous, 0},
  92.   {"uaword", cons, 4},
  93.   {"uahalf", cons, 2},
  94. #endif
  95.   {NULL, 0, 0},
  96. };
  97.  
  98. const int md_reloc_size = 12;    /* Size of relocation record */
  99.  
  100. /* This array holds the chars that always start a comment.  If the
  101.    pre-processor is disabled, these aren't very useful */
  102. const char comment_chars[] = "!";    /* JF removed '|' from comment_chars */
  103.  
  104. /* This array holds the chars that only start a comment at the beginning of
  105.    a line.  If the line seems to have the form '# 123 filename'
  106.    .line and .file directives will appear in the pre-processed output */
  107. /* Note that input_file.c hand checks for '#' at the beginning of the
  108.    first line of the input file.  This is because the compiler outputs
  109.    #NO_APP at the beginning of its output. */
  110. /* Also note that comments started like this one will always
  111.    work if '/' isn't otherwise defined. */
  112. const char line_comment_chars[] = "#";
  113.  
  114. const char line_separator_chars[] = "";
  115.  
  116. /* Chars that can be used to separate mant from exp in floating point nums */
  117. const char EXP_CHARS[] = "eE";
  118.  
  119. /* Chars that mean this number is a floating point constant */
  120. /* As in 0f12.456 */
  121. /* or    0d1.2345e12 */
  122. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  123.  
  124. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  125.    changed in read.c.  Ideally it shouldn't have to know about it at all,
  126.    but nothing is ideal around here.  */
  127.  
  128. static unsigned char octal[256];
  129. #define isoctal(c)  octal[(unsigned char) (c)]
  130. static unsigned char toHex[256];
  131.  
  132. struct sparc_it
  133.   {
  134.     char *error;
  135.     unsigned long opcode;
  136.     struct nlist *nlistp;
  137.     expressionS exp;
  138.     int pcrel;
  139.     bfd_reloc_code_real_type reloc;
  140.   };
  141.  
  142. struct sparc_it the_insn, set_insn;
  143.  
  144. /* Return non-zero if VAL is in the range -(MAX+1) to MAX.  */
  145.  
  146. static INLINE int
  147. in_signed_range (val, max)
  148.      bfd_signed_vma val, max;
  149. {
  150.   if (max <= 0)
  151.     abort ();
  152.   if (val > max)
  153.     return 0;
  154.   if (val < ~max)
  155.     return 0;
  156.   return 1;
  157. }
  158.  
  159. /* Return non-zero if VAL is in the range -(MAX/2+1) to MAX.
  160.    (e.g. -15 to +31).  */
  161.  
  162. static INLINE int
  163. in_bitfield_range (val, max)
  164.      bfd_signed_vma val, max;
  165. {
  166.   if (max <= 0)
  167.     abort ();
  168.   if (val > max)
  169.     return 0;
  170.   if (val < ~(max >> 1))
  171.     return 0;
  172.   return 1;
  173. }
  174.  
  175. static int
  176. sparc_ffs (mask)
  177.      unsigned int mask;
  178. {
  179.   int i;
  180.  
  181.   if (mask == 0)
  182.     return -1;
  183.  
  184.   for (i = 0; (mask & 1) == 0; ++i)
  185.     mask >>= 1;
  186.   return i;
  187. }
  188.  
  189. #if 0
  190. static void print_insn PARAMS ((struct sparc_it *insn));
  191. #endif
  192. static int getExpression PARAMS ((char *str));
  193.  
  194. static char *expr_end;
  195. static int special_case;
  196.  
  197. /*
  198.  * Instructions that require wierd handling because they're longer than
  199.  * 4 bytes.
  200.  */
  201. #define    SPECIAL_CASE_SET    1
  202. #define    SPECIAL_CASE_FDIV    2
  203.  
  204. /* The last instruction to be assembled.  */
  205. static const struct sparc_opcode *last_insn;
  206.  
  207. /*
  208.  * sort of like s_lcomm
  209.  *
  210.  */
  211. #ifndef OBJ_ELF
  212. static int max_alignment = 15;
  213. #endif
  214.  
  215. static void
  216. s_reserve (ignore)
  217.      int ignore;
  218. {
  219.   char *name;
  220.   char *p;
  221.   char c;
  222.   int align;
  223.   int size;
  224.   int temp;
  225.   symbolS *symbolP;
  226.  
  227.   name = input_line_pointer;
  228.   c = get_symbol_end ();
  229.   p = input_line_pointer;
  230.   *p = c;
  231.   SKIP_WHITESPACE ();
  232.  
  233.   if (*input_line_pointer != ',')
  234.     {
  235.       as_bad ("Expected comma after name");
  236.       ignore_rest_of_line ();
  237.       return;
  238.     }
  239.  
  240.   ++input_line_pointer;
  241.  
  242.   if ((size = get_absolute_expression ()) < 0)
  243.     {
  244.       as_bad ("BSS length (%d.) <0! Ignored.", size);
  245.       ignore_rest_of_line ();
  246.       return;
  247.     }                /* bad length */
  248.  
  249.   *p = 0;
  250.   symbolP = symbol_find_or_make (name);
  251.   *p = c;
  252.  
  253.   if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
  254.       && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
  255.     {
  256.       as_bad ("bad .reserve segment -- expected BSS segment");
  257.       return;
  258.     }
  259.  
  260.   if (input_line_pointer[2] == '.')
  261.     input_line_pointer += 7;
  262.   else
  263.     input_line_pointer += 6;
  264.   SKIP_WHITESPACE ();
  265.  
  266.   if (*input_line_pointer == ',')
  267.     {
  268.       ++input_line_pointer;
  269.  
  270.       SKIP_WHITESPACE ();
  271.       if (*input_line_pointer == '\n')
  272.     {
  273.       as_bad ("Missing alignment");
  274.       return;
  275.     }
  276.  
  277.       align = get_absolute_expression ();
  278. #ifndef OBJ_ELF
  279.       if (align > max_alignment)
  280.     {
  281.       align = max_alignment;
  282.       as_warn ("Alignment too large: %d. assumed.", align);
  283.     }
  284. #endif
  285.       if (align < 0)
  286.     {
  287.       align = 0;
  288.       as_warn ("Alignment negative. 0 assumed.");
  289.     }
  290.  
  291.       record_alignment (bss_section, align);
  292.  
  293.       /* convert to a power of 2 alignment */
  294.       for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
  295.  
  296.       if (align != 1)
  297.     {
  298.       as_bad ("Alignment not a power of 2");
  299.       ignore_rest_of_line ();
  300.       return;
  301.     }            /* not a power of two */
  302.  
  303.       align = temp;
  304.     }                /* if has optional alignment */
  305.   else
  306.     align = 0;
  307.  
  308.   if (!S_IS_DEFINED (symbolP)
  309. #ifdef OBJ_AOUT
  310.       && S_GET_OTHER (symbolP) == 0
  311.       && S_GET_DESC (symbolP) == 0
  312. #endif
  313.       )
  314.     {
  315.       if (! need_pass_2)
  316.     {
  317.       char *pfrag;
  318.       segT current_seg = now_seg;
  319.       subsegT current_subseg = now_subseg;
  320.  
  321.       subseg_set (bss_section, 1); /* switch to bss */
  322.  
  323.       if (align)
  324.         frag_align (align, 0); /* do alignment */
  325.  
  326.       /* detach from old frag */
  327.       if (S_GET_SEGMENT(symbolP) == bss_section)
  328.         symbolP->sy_frag->fr_symbol = NULL;
  329.  
  330.       symbolP->sy_frag = frag_now;
  331.       pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
  332.                 size, (char *)0);
  333.       *pfrag = 0;
  334.  
  335.       S_SET_SEGMENT (symbolP, bss_section);
  336.  
  337.       subseg_set (current_seg, current_subseg);
  338.     }
  339.     }
  340.   else
  341.     {
  342.       as_warn("Ignoring attempt to re-define symbol %s",
  343.           S_GET_NAME (symbolP));
  344.     }                /* if not redefining */
  345.  
  346.   demand_empty_rest_of_line ();
  347. }
  348.  
  349. static void
  350. s_common (ignore)
  351.      int ignore;
  352. {
  353.   char *name;
  354.   char c;
  355.   char *p;
  356.   int temp, size;
  357.   symbolS *symbolP;
  358.  
  359.   name = input_line_pointer;
  360.   c = get_symbol_end ();
  361.   /* just after name is now '\0' */
  362.   p = input_line_pointer;
  363.   *p = c;
  364.   SKIP_WHITESPACE ();
  365.   if (*input_line_pointer != ',')
  366.     {
  367.       as_bad ("Expected comma after symbol-name");
  368.       ignore_rest_of_line ();
  369.       return;
  370.     }
  371.   input_line_pointer++;        /* skip ',' */
  372.   if ((temp = get_absolute_expression ()) < 0)
  373.     {
  374.       as_bad (".COMMon length (%d.) <0! Ignored.", temp);
  375.       ignore_rest_of_line ();
  376.       return;
  377.     }
  378.   size = temp;
  379.   *p = 0;
  380.   symbolP = symbol_find_or_make (name);
  381.   *p = c;
  382.   if (S_IS_DEFINED (symbolP))
  383.     {
  384.       as_bad ("Ignoring attempt to re-define symbol");
  385.       ignore_rest_of_line ();
  386.       return;
  387.     }
  388.   if (S_GET_VALUE (symbolP) != 0)
  389.     {
  390.       if (S_GET_VALUE (symbolP) != size)
  391.     {
  392.       as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
  393.            S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
  394.     }
  395.     }
  396.   else
  397.     {
  398. #ifndef OBJ_ELF
  399.       S_SET_VALUE (symbolP, (valueT) size);
  400.       S_SET_EXTERNAL (symbolP);
  401. #endif
  402.     }
  403.   know (symbolP->sy_frag == &zero_address_frag);
  404.   if (*input_line_pointer != ',')
  405.     {
  406.       as_bad ("Expected comma after common length");
  407.       ignore_rest_of_line ();
  408.       return;
  409.     }
  410.   input_line_pointer++;
  411.   SKIP_WHITESPACE ();
  412.   if (*input_line_pointer != '"')
  413.     {
  414.       temp = get_absolute_expression ();
  415. #ifndef OBJ_ELF
  416.       if (temp > max_alignment)
  417.     {
  418.       temp = max_alignment;
  419.       as_warn ("Common alignment too large: %d. assumed", temp);
  420.     }
  421. #endif
  422.       if (temp < 0)
  423.     {
  424.       temp = 0;
  425.       as_warn ("Common alignment negative; 0 assumed");
  426.     }
  427. #ifdef OBJ_ELF
  428.       if (symbolP->local)
  429.     {
  430.       segT old_sec;
  431.       int old_subsec;
  432.       char *p;
  433.       int align;
  434.  
  435.     allocate_bss:
  436.       old_sec = now_seg;
  437.       old_subsec = now_subseg;
  438.       align = temp;
  439.       record_alignment (bss_section, align);
  440.       subseg_set (bss_section, 0);
  441.       if (align)
  442.         frag_align (align, 0);
  443.       if (S_GET_SEGMENT (symbolP) == bss_section)
  444.         symbolP->sy_frag->fr_symbol = 0;
  445.       symbolP->sy_frag = frag_now;
  446.       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
  447.             (char *) 0);
  448.       *p = 0;
  449.       S_SET_SEGMENT (symbolP, bss_section);
  450.       S_CLEAR_EXTERNAL (symbolP);
  451.       subseg_set (old_sec, old_subsec);
  452.     }
  453.       else
  454. #endif
  455.     {
  456.     allocate_common:
  457.       S_SET_VALUE (symbolP, (valueT) size);
  458. #ifdef OBJ_ELF
  459.       S_SET_ALIGN (symbolP, temp);
  460. #endif
  461.       S_SET_EXTERNAL (symbolP);
  462.       /* should be common, but this is how gas does it for now */
  463.       S_SET_SEGMENT (symbolP, bfd_und_section_ptr);
  464.     }
  465.     }
  466.   else
  467.     {
  468.       input_line_pointer++;
  469.       /* @@ Some use the dot, some don't.  Can we get some consistency??  */
  470.       if (*input_line_pointer == '.')
  471.     input_line_pointer++;
  472.       /* @@ Some say data, some say bss.  */
  473.       if (strncmp (input_line_pointer, "bss\"", 4)
  474.       && strncmp (input_line_pointer, "data\"", 5))
  475.     {
  476.       while (*--input_line_pointer != '"')
  477.         ;
  478.       input_line_pointer--;
  479.       goto bad_common_segment;
  480.     }
  481.       while (*input_line_pointer++ != '"')
  482.     ;
  483.       goto allocate_common;
  484.     }
  485.   demand_empty_rest_of_line ();
  486.   return;
  487.  
  488.   {
  489.   bad_common_segment:
  490.     p = input_line_pointer;
  491.     while (*p && *p != '\n')
  492.       p++;
  493.     c = *p;
  494.     *p = '\0';
  495.     as_bad ("bad .common segment %s", input_line_pointer + 1);
  496.     *p = c;
  497.     input_line_pointer = p;
  498.     ignore_rest_of_line ();
  499.     return;
  500.   }
  501. }
  502.  
  503. /* Handle the .empty pseudo-op.  This supresses the warnings about
  504.    invalid delay slot usage.  */
  505.  
  506. static void
  507. s_empty (ignore)
  508.      int ignore;
  509. {
  510.   /* The easy way to implement is to just forget about the last
  511.      instruction.  */
  512.   last_insn = NULL;
  513. }
  514.  
  515. static void
  516. s_seg (ignore)
  517.      int ignore;
  518. {
  519.  
  520.   if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
  521.     {
  522.       input_line_pointer += 6;
  523.       s_text (0);
  524.       return;
  525.     }
  526.   if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
  527.     {
  528.       input_line_pointer += 6;
  529.       s_data (0);
  530.       return;
  531.     }
  532.   if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
  533.     {
  534.       input_line_pointer += 7;
  535.       s_data1 ();
  536.       return;
  537.     }
  538.   if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
  539.     {
  540.       input_line_pointer += 5;
  541.       /* We only support 2 segments -- text and data -- for now, so
  542.      things in the "bss segment" will have to go into data for now.
  543.      You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
  544.       subseg_set (data_section, 255);    /* FIXME-SOMEDAY */
  545.       return;
  546.     }
  547.   as_bad ("Unknown segment type");
  548.   demand_empty_rest_of_line ();
  549. }
  550.  
  551. static void
  552. s_data1 ()
  553. {
  554.   subseg_set (data_section, 1);
  555.   demand_empty_rest_of_line ();
  556. }
  557.  
  558. static void
  559. s_proc (ignore)
  560.      int ignore;
  561. {
  562.   while (!is_end_of_line[(unsigned char) *input_line_pointer])
  563.     {
  564.       ++input_line_pointer;
  565.     }
  566.   ++input_line_pointer;
  567. }
  568.  
  569. /* We require .word, et. al., to be aligned correctly.  We do it by
  570.    setting up an rs_align_code frag, and checking in HANDLE_ALIGN to
  571.    make sure that no unexpected alignment was introduced.  */
  572.  
  573. void
  574. sparc_cons_align (nbytes)
  575.      int nbytes;
  576. {
  577.   int nalign;
  578.   char *p;
  579.  
  580.   nalign = 0;
  581.   while ((nbytes & 1) == 0)
  582.     {
  583.       ++nalign;
  584.       nbytes >>= 1;
  585.     }
  586.  
  587.   if (nalign == 0)
  588.     return;
  589.  
  590.   if (now_seg == absolute_section)
  591.     {
  592.       if ((abs_section_offset & ((1 << nalign) - 1)) != 0)
  593.     as_bad ("misaligned data");
  594.       return;
  595.     }
  596.  
  597.   p = frag_var (rs_align_code, 1, 1, (relax_substateT) 0,
  598.         (symbolS *) NULL, (long) nalign, (char *) NULL);
  599.  
  600.   record_alignment (now_seg, nalign);
  601. }
  602.  
  603. /* This is where we do the unexpected alignment check.  */
  604.  
  605. void
  606. sparc_handle_align (fragp)
  607.      fragS *fragp;
  608. {
  609.   if (fragp->fr_type == rs_align_code
  610.       && fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix != 0)
  611.     as_bad_where (fragp->fr_file, fragp->fr_line, "misaligned data");
  612. }
  613.  
  614. /* sparc64 priviledged registers */
  615.  
  616. struct priv_reg_entry
  617.   {
  618.     char *name;
  619.     int regnum;
  620.   };
  621.  
  622. struct priv_reg_entry priv_reg_table[] =
  623. {
  624.   {"tpc", 0},
  625.   {"tnpc", 1},
  626.   {"tstate", 2},
  627.   {"tt", 3},
  628.   {"tick", 4},
  629.   {"tba", 5},
  630.   {"pstate", 6},
  631.   {"tl", 7},
  632.   {"pil", 8},
  633.   {"cwp", 9},
  634.   {"cansave", 10},
  635.   {"canrestore", 11},
  636.   {"cleanwin", 12},
  637.   {"otherwin", 13},
  638.   {"wstate", 14},
  639.   {"fq", 15},
  640.   {"ver", 31},
  641.   {"", -1},            /* end marker */
  642. };
  643.  
  644. static int
  645. cmp_reg_entry (p, q)
  646.      struct priv_reg_entry *p, *q;
  647. {
  648.   return strcmp (q->name, p->name);
  649. }
  650.  
  651. /* This function is called once, at assembler startup time.  It should
  652.    set up all the tables, etc. that the MD part of the assembler will need. */
  653.  
  654. void
  655. md_begin ()
  656. {
  657.   register const char *retval = NULL;
  658.   int lose = 0;
  659.   register unsigned int i = 0;
  660.  
  661.   op_hash = hash_new ();
  662.  
  663.   while (i < sparc_num_opcodes)
  664.     {
  665.       const char *name = sparc_opcodes[i].name;
  666.       retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
  667.       if (retval != NULL)
  668.     {
  669.       fprintf (stderr, "internal error: can't hash `%s': %s\n",
  670.            sparc_opcodes[i].name, retval);
  671.       lose = 1;
  672.     }
  673.       do
  674.     {
  675.       if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
  676.         {
  677.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  678.                sparc_opcodes[i].name, sparc_opcodes[i].args);
  679.           lose = 1;
  680.         }
  681.       ++i;
  682.     }
  683.       while (i < sparc_num_opcodes
  684.          && !strcmp (sparc_opcodes[i].name, name));
  685.     }
  686.  
  687.   if (lose)
  688.     as_fatal ("Broken assembler.  No assembly attempted.");
  689.  
  690.   for (i = '0'; i < '8'; ++i)
  691.     octal[i] = 1;
  692.   for (i = '0'; i <= '9'; ++i)
  693.     toHex[i] = i - '0';
  694.   for (i = 'a'; i <= 'f'; ++i)
  695.     toHex[i] = i + 10 - 'a';
  696.   for (i = 'A'; i <= 'F'; ++i)
  697.     toHex[i] = i + 10 - 'A';
  698.  
  699.   qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
  700.      sizeof (priv_reg_table[0]), cmp_reg_entry);
  701.  
  702.   target_big_endian = 1;
  703.  
  704.   /* If -bump, record the architecture level at which we start issuing
  705.      warnings.  The behaviour is different depending upon whether an
  706.      architecture was explicitly specified.  If it wasn't, we issue warnings
  707.      for all upwards bumps.  If it was, we don't start issuing warnings until
  708.      we need to bump beyond the requested architecture or when we bump between
  709.      conflicting architectures.  */
  710.  
  711.   if (warn_on_bump
  712.       && architecture_requested)
  713.     {
  714.       /* `max_architecture' records the requested architecture.
  715.      Issue warnings if we go above it.  */
  716.       warn_after_architecture = max_architecture;
  717.  
  718.       /* Find the highest architecture level that doesn't conflict with
  719.      the requested one.  */
  720.       for (max_architecture = SPARC_OPCODE_ARCH_MAX;
  721.        max_architecture > warn_after_architecture;
  722.        --max_architecture)
  723.     if (! SPARC_OPCODE_CONFLICT_P (max_architecture,
  724.                        warn_after_architecture))
  725.       break;
  726.     }
  727. }
  728.  
  729. /* Called after all assembly has been done.  */
  730.  
  731. void
  732. sparc_md_end ()
  733. {
  734. #ifdef SPARC_ARCH64
  735.   if (current_architecture == SPARC_OPCODE_ARCH_V9A)
  736.     bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v9a);
  737.   else
  738.     bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v9);
  739. #else
  740.   if (current_architecture == SPARC_OPCODE_ARCH_V9)
  741.     bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v8plus);
  742.   else if (current_architecture == SPARC_OPCODE_ARCH_V9A)
  743.     bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_v8plusa);
  744.   else if (current_architecture == SPARC_OPCODE_ARCH_SPARCLET)
  745.     bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc_sparclet);
  746.   else
  747.     {
  748.       /* The sparclite is treated like a normal sparc.  Perhaps it shouldn't
  749.      be but for now it is (since that's the way it's always been
  750.      treated).  */
  751.       bfd_set_arch_mach (stdoutput, bfd_arch_sparc, bfd_mach_sparc);
  752.     }
  753. #endif
  754. }
  755.  
  756. void
  757. md_assemble (str)
  758.      char *str;
  759. {
  760.   const struct sparc_opcode *insn;
  761.   char *toP;
  762.   int rsd;
  763.  
  764.   know (str);
  765.   sparc_ip (str, &insn);
  766.  
  767.   /* We warn about attempts to put a floating point branch in a delay
  768.      slot.  */
  769.   if (insn != NULL
  770.       && last_insn != NULL
  771.       && (insn->flags & F_FBR) != 0
  772.       && (last_insn->flags & F_DELAYED) != 0)
  773.     as_warn ("FP branch in delay slot");
  774.  
  775.   /* SPARC before v9 requires a nop instruction between a floating
  776.      point instruction and a floating point branch.  We insert one
  777.      automatically, with a warning.  */
  778.   if (max_architecture < SPARC_OPCODE_ARCH_V9
  779.       && insn != NULL
  780.       && last_insn != NULL
  781.       && (insn->flags & F_FBR) != 0
  782.       && (last_insn->flags & F_FLOAT) != 0)
  783.     {
  784.       as_warn ("FP branch preceded by FP instruction; NOP inserted");
  785.       toP = frag_more (4);
  786.       md_number_to_chars (toP, (valueT) 0x01000000, 4);
  787.     }
  788.  
  789.   /* See if "set" operand is absolute and small; skip sethi if so. */
  790.   if (special_case == SPECIAL_CASE_SET
  791.       && the_insn.exp.X_op == O_constant)
  792.     {
  793.       if (the_insn.exp.X_add_number >= -(1 << 12)
  794.       && the_insn.exp.X_add_number < (1 << 12))
  795.     {
  796.       the_insn.opcode = 0x80102000    /* or %g0,imm,... */
  797.         | (the_insn.opcode & 0x3E000000)    /* dest reg */
  798.         | (the_insn.exp.X_add_number & 0x1FFF);    /* imm */
  799.       special_case = 0;    /* No longer special */
  800.       the_insn.reloc = BFD_RELOC_NONE;    /* No longer relocated */
  801.     }
  802.     }
  803.  
  804.   toP = frag_more (4);
  805.   /* put out the opcode */
  806.   md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
  807.  
  808.   /* put out the symbol-dependent stuff */
  809.   if (the_insn.reloc != BFD_RELOC_NONE)
  810.     {
  811.       fix_new_exp (frag_now,    /* which frag */
  812.            (toP - frag_now->fr_literal),    /* where */
  813.            4,        /* size */
  814.            &the_insn.exp,
  815.            the_insn.pcrel,
  816.            the_insn.reloc);
  817.     }
  818.  
  819.   last_insn = insn;
  820.  
  821.   switch (special_case)
  822.     {
  823.     case SPECIAL_CASE_SET:
  824.       special_case = 0;
  825.       assert (the_insn.reloc == BFD_RELOC_HI22);
  826.       /* See if "set" operand has no low-order bits; skip OR if so. */
  827.       if (the_insn.exp.X_op == O_constant
  828.       && ((the_insn.exp.X_add_number & 0x3FF) == 0))
  829.     return;
  830.       toP = frag_more (4);
  831.       rsd = (the_insn.opcode >> 25) & 0x1f;
  832.       the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
  833.       md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
  834.       fix_new_exp (frag_now,    /* which frag */
  835.            (toP - frag_now->fr_literal),    /* where */
  836.            4,        /* size */
  837.            &the_insn.exp,
  838.            the_insn.pcrel,
  839.            BFD_RELOC_LO10);
  840.       return;
  841.  
  842.     case SPECIAL_CASE_FDIV:
  843.       /* According to information leaked from Sun, the "fdiv" instructions
  844.      on early SPARC machines would produce incorrect results sometimes.
  845.      The workaround is to add an fmovs of the destination register to
  846.      itself just after the instruction.  This was true on machines
  847.      with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
  848.       special_case = 0;
  849.       assert (the_insn.reloc == BFD_RELOC_NONE);
  850.       toP = frag_more (4);
  851.       rsd = (the_insn.opcode >> 25) & 0x1f;
  852.       the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd;    /* fmovs dest,dest */
  853.       md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
  854.       return;
  855.  
  856.     case 0:
  857.       return;
  858.  
  859.     default:
  860.       as_fatal ("failed sanity check.");
  861.     }
  862. }
  863.  
  864. /* Implement big shift right.  */
  865. static bfd_vma
  866. BSR (val, amount)
  867.      bfd_vma val;
  868.      int amount;
  869. {
  870.   if (sizeof (bfd_vma) <= 4 && amount >= 32)
  871.     as_fatal ("Support for 64-bit arithmetic not compiled in.");
  872.   return val >> amount;
  873. }
  874.  
  875. /* Parse an argument that can be expressed as a keyword.
  876.    (eg: #StoreStore or %ccfr).
  877.    The result is a boolean indicating success.
  878.    If successful, INPUT_POINTER is updated.  */
  879.  
  880. static int
  881. parse_keyword_arg (lookup_fn, input_pointerP, valueP)
  882.      int (*lookup_fn) ();
  883.      char **input_pointerP;
  884.      int *valueP;
  885. {
  886.   int value;
  887.   char c, *p, *q;
  888.  
  889.   p = *input_pointerP;
  890.   for (q = p + (*p == '#' || *p == '%'); isalpha (*q) || *q == '_'; ++q)
  891.     continue;
  892.   c = *q;
  893.   *q = 0;
  894.   value = (*lookup_fn) (p);
  895.   *q = c;
  896.   if (value == -1)
  897.     return 0;
  898.   *valueP = value;
  899.   *input_pointerP = q;
  900.   return 1;
  901. }
  902.  
  903. /* Parse an argument that is a constant expression.
  904.    The result is a boolean indicating success.  */
  905.  
  906. static int
  907. parse_const_expr_arg (input_pointerP, valueP)
  908.      char **input_pointerP;
  909.      int *valueP;
  910. {
  911.   char *save = input_line_pointer;
  912.   expressionS exp;
  913.  
  914.   input_line_pointer = *input_pointerP;
  915.   /* The next expression may be something other than a constant
  916.      (say if we're not processing the right variant of the insn).
  917.      Don't call expression unless we're sure it will succeed as it will
  918.      signal an error (which we want to defer until later).  */
  919.   /* FIXME: It might be better to define md_operand and have it recognize
  920.      things like %asi, etc. but continuing that route through to the end
  921.      is a lot of work.  */
  922.   if (*input_line_pointer == '%')
  923.     {
  924.       input_line_pointer = save;
  925.       return 0;
  926.     }
  927.   expression (&exp);
  928.   *input_pointerP = input_line_pointer;
  929.   input_line_pointer = save;
  930.   if (exp.X_op != O_constant)
  931.     return 0;
  932.   *valueP = exp.X_add_number;
  933.   return 1;
  934. }
  935.  
  936. static void
  937. sparc_ip (str, pinsn)
  938.      char *str;
  939.      const struct sparc_opcode **pinsn;
  940. {
  941.   char *error_message = "";
  942.   char *s;
  943.   const char *args;
  944.   char c;
  945.   const struct sparc_opcode *insn;
  946.   char *argsStart;
  947.   unsigned long opcode;
  948.   unsigned int mask = 0;
  949.   int match = 0;
  950.   int comma = 0;
  951.   long immediate_max = 0;
  952.   int v9_arg_p;
  953.  
  954.   for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
  955.     ;
  956.  
  957.   switch (*s)
  958.     {
  959.     case '\0':
  960.       break;
  961.  
  962.     case ',':
  963.       comma = 1;
  964.  
  965.       /*FALLTHROUGH */
  966.  
  967.     case ' ':
  968.       *s++ = '\0';
  969.       break;
  970.  
  971.     default:
  972.       as_fatal ("Unknown opcode: `%s'", str);
  973.     }
  974.   insn = (struct sparc_opcode *) hash_find (op_hash, str);
  975.   *pinsn = insn;
  976.   if (insn == NULL)
  977.     {
  978.       as_bad ("Unknown opcode: `%s'", str);
  979.       return;
  980.     }
  981.   if (comma)
  982.     {
  983.       *--s = ',';
  984.     }
  985.  
  986.   argsStart = s;
  987.   for (;;)
  988.     {
  989.       opcode = insn->match;
  990.       memset (&the_insn, '\0', sizeof (the_insn));
  991.       the_insn.reloc = BFD_RELOC_NONE;
  992.       v9_arg_p = 0;
  993.  
  994.       /*
  995.        * Build the opcode, checking as we go to make
  996.        * sure that the operands match
  997.        */
  998.       for (args = insn->args;; ++args)
  999.     {
  1000.       switch (*args)
  1001.         {
  1002.         case 'K':
  1003.           {
  1004.         int kmask = 0;
  1005.  
  1006.         /* Parse a series of masks.  */
  1007.         if (*s == '#')
  1008.           {
  1009.             while (*s == '#')
  1010.               {
  1011.             int mask;
  1012.  
  1013.             if (! parse_keyword_arg (sparc_encode_membar, &s,
  1014.                          &mask))
  1015.               {
  1016.                 error_message = ": invalid membar mask name";
  1017.                 goto error;
  1018.               }
  1019.             kmask |= mask;
  1020.             while (*s == ' ') { ++s; continue; }
  1021.             if (*s == '|' || *s == '+')
  1022.               ++s;
  1023.             while (*s == ' ') { ++s; continue; }
  1024.               }
  1025.           }
  1026.         else
  1027.           {
  1028.             if (! parse_const_expr_arg (&s, &kmask))
  1029.               {
  1030.             error_message = ": invalid membar mask expression";
  1031.             goto error;
  1032.               }
  1033.             if (kmask < 0 || kmask > 127)
  1034.               {
  1035.             error_message = ": invalid membar mask number";
  1036.             goto error;
  1037.               }
  1038.           }
  1039.  
  1040.         opcode |= MEMBAR (kmask);
  1041.         continue;
  1042.           }
  1043.  
  1044.         case '*':
  1045.           {
  1046.         int fcn = 0;
  1047.  
  1048.         /* Parse a prefetch function.  */
  1049.         if (*s == '#')
  1050.           {
  1051.             if (! parse_keyword_arg (sparc_encode_prefetch, &s, &fcn))
  1052.               {
  1053.             error_message = ": invalid prefetch function name";
  1054.             goto error;
  1055.               }
  1056.           }
  1057.         else
  1058.           {
  1059.             if (! parse_const_expr_arg (&s, &fcn))
  1060.               {
  1061.             error_message = ": invalid prefetch function expression";
  1062.             goto error;
  1063.               }
  1064.             if (fcn < 0 || fcn > 31)
  1065.               {
  1066.             error_message = ": invalid prefetch function number";
  1067.             goto error;
  1068.               }
  1069.           }
  1070.         opcode |= RD (fcn);
  1071.         continue;
  1072.           }
  1073.  
  1074.         case '!':
  1075.         case '?':
  1076.           /* Parse a sparc64 privileged register.  */
  1077.           if (*s == '%')
  1078.         {
  1079.           struct priv_reg_entry *p = priv_reg_table;
  1080.           unsigned int len = 9999999; /* init to make gcc happy */
  1081.  
  1082.           s += 1;
  1083.           while (p->name[0] > s[0])
  1084.             p++;
  1085.           while (p->name[0] == s[0])
  1086.             {
  1087.               len = strlen (p->name);
  1088.               if (strncmp (p->name, s, len) == 0)
  1089.             break;
  1090.               p++;
  1091.             }
  1092.           if (p->name[0] != s[0])
  1093.             {
  1094.               error_message = ": unrecognizable privileged register";
  1095.               goto error;
  1096.             }
  1097.           if (*args == '?')
  1098.             opcode |= (p->regnum << 14);
  1099.           else
  1100.             opcode |= (p->regnum << 25);
  1101.           s += len;
  1102.           continue;
  1103.         }
  1104.           else
  1105.         {
  1106.           error_message = ": unrecognizable privileged register";
  1107.           goto error;
  1108.         }
  1109.  
  1110.         case 'M':
  1111.         case 'm':
  1112.           if (strncmp (s, "%asr", 4) == 0)
  1113.         {
  1114.           s += 4;
  1115.  
  1116.           if (isdigit (*s))
  1117.             {
  1118.               long num = 0;
  1119.  
  1120.               while (isdigit (*s))
  1121.             {
  1122.               num = num * 10 + *s - '0';
  1123.               ++s;
  1124.             }
  1125.  
  1126.               if (current_architecture >= SPARC_OPCODE_ARCH_V9)
  1127.             {
  1128.               if (num < 16 || 31 < num)
  1129.                 {
  1130.                   error_message = ": asr number must be between 16 and 31";
  1131.                   goto error;
  1132.                 }
  1133.             }
  1134.               else
  1135.             {
  1136.               if (num < 0 || 31 < num)
  1137.                 {
  1138.                   error_message = ": asr number must be between 0 and 31";
  1139.                   goto error;
  1140.                 }
  1141.             }
  1142.  
  1143.               opcode |= (*args == 'M' ? RS1 (num) : RD (num));
  1144.               continue;
  1145.             }
  1146.           else
  1147.             {
  1148.               error_message = ": expecting %asrN";
  1149.               goto error;
  1150.             }
  1151.         } /* if %asr */
  1152.           break;
  1153.  
  1154.         case 'I':
  1155.           the_insn.reloc = BFD_RELOC_SPARC_11;
  1156.           immediate_max = 0x03FF;
  1157.           goto immediate;
  1158.  
  1159.         case 'j':
  1160.           the_insn.reloc = BFD_RELOC_SPARC_10;
  1161.           immediate_max = 0x01FF;
  1162.           goto immediate;
  1163.  
  1164.         case 'X':
  1165.           /* V8 systems don't understand BFD_RELOC_SPARC_5.  */
  1166.           if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
  1167.         the_insn.reloc = BFD_RELOC_SPARC_5;
  1168.           else
  1169.         the_insn.reloc = BFD_RELOC_SPARC13;
  1170.           /* These fields are unsigned, but for upward compatibility,
  1171.          allow negative values as well.  */
  1172.           immediate_max = 0x1f;
  1173.           goto immediate;
  1174.  
  1175.         case 'Y':
  1176.           /* V8 systems don't understand BFD_RELOC_SPARC_6.  */
  1177.           if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
  1178.         the_insn.reloc = BFD_RELOC_SPARC_6;
  1179.           else
  1180.         the_insn.reloc = BFD_RELOC_SPARC13;
  1181.           /* These fields are unsigned, but for upward compatibility,
  1182.          allow negative values as well.  */
  1183.           immediate_max = 0x3f;
  1184.           goto immediate;
  1185.  
  1186.         case 'k':
  1187.           the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
  1188.           the_insn.pcrel = 1;
  1189.           goto immediate;
  1190.  
  1191.         case 'G':
  1192.           the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
  1193.           the_insn.pcrel = 1;
  1194.           goto immediate;
  1195.  
  1196.         case 'N':
  1197.           if (*s == 'p' && s[1] == 'n')
  1198.         {
  1199.           s += 2;
  1200.           continue;
  1201.         }
  1202.           break;
  1203.  
  1204.         case 'T':
  1205.           if (*s == 'p' && s[1] == 't')
  1206.         {
  1207.           s += 2;
  1208.           continue;
  1209.         }
  1210.           break;
  1211.  
  1212.         case 'z':
  1213.           if (*s == ' ')
  1214.         {
  1215.           ++s;
  1216.         }
  1217.           if (strncmp (s, "%icc", 4) == 0)
  1218.         {
  1219.           s += 4;
  1220.           continue;
  1221.         }
  1222.           break;
  1223.  
  1224.         case 'Z':
  1225.           if (*s == ' ')
  1226.         {
  1227.           ++s;
  1228.         }
  1229.           if (strncmp (s, "%xcc", 4) == 0)
  1230.         {
  1231.           s += 4;
  1232.           continue;
  1233.         }
  1234.           break;
  1235.  
  1236.         case '6':
  1237.           if (*s == ' ')
  1238.         {
  1239.           ++s;
  1240.         }
  1241.           if (strncmp (s, "%fcc0", 5) == 0)
  1242.         {
  1243.           s += 5;
  1244.           continue;
  1245.         }
  1246.           break;
  1247.  
  1248.         case '7':
  1249.           if (*s == ' ')
  1250.         {
  1251.           ++s;
  1252.         }
  1253.           if (strncmp (s, "%fcc1", 5) == 0)
  1254.         {
  1255.           s += 5;
  1256.           continue;
  1257.         }
  1258.           break;
  1259.  
  1260.         case '8':
  1261.           if (*s == ' ')
  1262.         {
  1263.           ++s;
  1264.         }
  1265.           if (strncmp (s, "%fcc2", 5) == 0)
  1266.         {
  1267.           s += 5;
  1268.           continue;
  1269.         }
  1270.           break;
  1271.  
  1272.         case '9':
  1273.           if (*s == ' ')
  1274.         {
  1275.           ++s;
  1276.         }
  1277.           if (strncmp (s, "%fcc3", 5) == 0)
  1278.         {
  1279.           s += 5;
  1280.           continue;
  1281.         }
  1282.           break;
  1283.  
  1284.         case 'P':
  1285.           if (strncmp (s, "%pc", 3) == 0)
  1286.         {
  1287.           s += 3;
  1288.           continue;
  1289.         }
  1290.           break;
  1291.  
  1292.         case 'W':
  1293.           if (strncmp (s, "%tick", 5) == 0)
  1294.         {
  1295.           s += 5;
  1296.           continue;
  1297.         }
  1298.           break;
  1299.  
  1300.         case '\0':        /* end of args */
  1301.           if (*s == '\0')
  1302.         {
  1303.           match = 1;
  1304.         }
  1305.           break;
  1306.  
  1307.         case '+':
  1308.           if (*s == '+')
  1309.         {
  1310.           ++s;
  1311.           continue;
  1312.         }
  1313.           if (*s == '-')
  1314.         {
  1315.           continue;
  1316.         }
  1317.           break;
  1318.  
  1319.         case '[':        /* these must match exactly */
  1320.         case ']':
  1321.         case ',':
  1322.         case ' ':
  1323.           if (*s++ == *args)
  1324.         continue;
  1325.           break;
  1326.  
  1327.         case '#':        /* must be at least one digit */
  1328.           if (isdigit (*s++))
  1329.         {
  1330.           while (isdigit (*s))
  1331.             {
  1332.               ++s;
  1333.             }
  1334.           continue;
  1335.         }
  1336.           break;
  1337.  
  1338.         case 'C':        /* coprocessor state register */
  1339.           if (strncmp (s, "%csr", 4) == 0)
  1340.         {
  1341.           s += 4;
  1342.           continue;
  1343.         }
  1344.           break;
  1345.  
  1346.         case 'b':        /* next operand is a coprocessor register */
  1347.         case 'c':
  1348.         case 'D':
  1349.           if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
  1350.         {
  1351.           mask = *s++;
  1352.           if (isdigit (*s))
  1353.             {
  1354.               mask = 10 * (mask - '0') + (*s++ - '0');
  1355.               if (mask >= 32)
  1356.             {
  1357.               break;
  1358.             }
  1359.             }
  1360.           else
  1361.             {
  1362.               mask -= '0';
  1363.             }
  1364.           switch (*args)
  1365.             {
  1366.  
  1367.             case 'b':
  1368.               opcode |= mask << 14;
  1369.               continue;
  1370.  
  1371.             case 'c':
  1372.               opcode |= mask;
  1373.               continue;
  1374.  
  1375.             case 'D':
  1376.               opcode |= mask << 25;
  1377.               continue;
  1378.             }
  1379.         }
  1380.           break;
  1381.  
  1382.         case 'r':        /* next operand must be a register */
  1383.         case 'O':
  1384.         case '1':
  1385.         case '2':
  1386.         case 'd':
  1387.           if (*s++ == '%')
  1388.         {
  1389.           switch (c = *s++)
  1390.             {
  1391.  
  1392.             case 'f':    /* frame pointer */
  1393.               if (*s++ == 'p')
  1394.             {
  1395.               mask = 0x1e;
  1396.               break;
  1397.             }
  1398.               goto error;
  1399.  
  1400.             case 'g':    /* global register */
  1401.               if (isoctal (c = *s++))
  1402.             {
  1403.               mask = c - '0';
  1404.               break;
  1405.             }
  1406.               goto error;
  1407.  
  1408.             case 'i':    /* in register */
  1409.               if (isoctal (c = *s++))
  1410.             {
  1411.               mask = c - '0' + 24;
  1412.               break;
  1413.             }
  1414.               goto error;
  1415.  
  1416.             case 'l':    /* local register */
  1417.               if (isoctal (c = *s++))
  1418.             {
  1419.               mask = (c - '0' + 16);
  1420.               break;
  1421.             }
  1422.               goto error;
  1423.  
  1424.             case 'o':    /* out register */
  1425.               if (isoctal (c = *s++))
  1426.             {
  1427.               mask = (c - '0' + 8);
  1428.               break;
  1429.             }
  1430.               goto error;
  1431.  
  1432.             case 's':    /* stack pointer */
  1433.               if (*s++ == 'p')
  1434.             {
  1435.               mask = 0xe;
  1436.               break;
  1437.             }
  1438.               goto error;
  1439.  
  1440.             case 'r':    /* any register */
  1441.               if (!isdigit (c = *s++))
  1442.             {
  1443.               goto error;
  1444.             }
  1445.               /* FALLTHROUGH */
  1446.             case '0':
  1447.             case '1':
  1448.             case '2':
  1449.             case '3':
  1450.             case '4':
  1451.             case '5':
  1452.             case '6':
  1453.             case '7':
  1454.             case '8':
  1455.             case '9':
  1456.               if (isdigit (*s))
  1457.             {
  1458.               if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
  1459.                 {
  1460.                   goto error;
  1461.                 }
  1462.             }
  1463.               else
  1464.             {
  1465.               c -= '0';
  1466.             }
  1467.               mask = c;
  1468.               break;
  1469.  
  1470.             default:
  1471.               goto error;
  1472.             }
  1473.  
  1474.           /* Got the register, now figure out where
  1475.              it goes in the opcode.  */
  1476.           switch (*args)
  1477.             {
  1478.             case '1':
  1479.               opcode |= mask << 14;
  1480.               continue;
  1481.  
  1482.             case '2':
  1483.               opcode |= mask;
  1484.               continue;
  1485.  
  1486.             case 'd':
  1487.               opcode |= mask << 25;
  1488.               continue;
  1489.  
  1490.             case 'r':
  1491.               opcode |= (mask << 25) | (mask << 14);
  1492.               continue;
  1493.  
  1494.             case 'O':
  1495.               opcode |= (mask << 25) | (mask << 0);
  1496.               continue;
  1497.             }
  1498.         }
  1499.           break;
  1500.  
  1501.         case 'e':        /* next operand is a floating point register */
  1502.         case 'v':
  1503.         case 'V':
  1504.  
  1505.         case 'f':
  1506.         case 'B':
  1507.         case 'R':
  1508.  
  1509.         case 'g':
  1510.         case 'H':
  1511.         case 'J':
  1512.           {
  1513.         char format;
  1514.  
  1515.         if (*s++ == '%'
  1516.             && ((format = *s) == 'f')
  1517.             && isdigit (*++s))
  1518.           {
  1519.             for (mask = 0; isdigit (*s); ++s)
  1520.               {
  1521.             mask = 10 * mask + (*s - '0');
  1522.               }        /* read the number */
  1523.  
  1524.             if ((*args == 'v'
  1525.              || *args == 'B'
  1526.              || *args == 'H')
  1527.             && (mask & 1))
  1528.               {
  1529.             break;
  1530.               }        /* register must be even numbered */
  1531.  
  1532.             if ((*args == 'V'
  1533.              || *args == 'R'
  1534.              || *args == 'J')
  1535.             && (mask & 3))
  1536.               {
  1537.             break;
  1538.               }        /* register must be multiple of 4 */
  1539.  
  1540.             if (mask >= 64)
  1541.               {
  1542.             if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
  1543.               error_message = ": There are only 64 f registers; [0-63]";
  1544.             else
  1545.               error_message = ": There are only 32 f registers; [0-31]";
  1546.             goto error;
  1547.               }    /* on error */
  1548.             else if (mask >= 32)
  1549.               {
  1550.             if (SPARC_OPCODE_ARCH_V9_P (max_architecture))
  1551.               {
  1552.                 v9_arg_p = 1;
  1553.                 mask -= 31;    /* wrap high bit */
  1554.               }
  1555.             else
  1556.               {
  1557.                 error_message = ": There are only 32 f registers; [0-31]";
  1558.                 goto error;
  1559.               }
  1560.               }
  1561.           }
  1562.         else
  1563.           {
  1564.             break;
  1565.           }    /* if not an 'f' register. */
  1566.  
  1567.         switch (*args)
  1568.           {
  1569.           case 'v':
  1570.           case 'V':
  1571.           case 'e':
  1572.             opcode |= RS1 (mask);
  1573.             continue;
  1574.  
  1575.  
  1576.           case 'f':
  1577.           case 'B':
  1578.           case 'R':
  1579.             opcode |= RS2 (mask);
  1580.             continue;
  1581.  
  1582.           case 'g':
  1583.           case 'H':
  1584.           case 'J':
  1585.             opcode |= RD (mask);
  1586.             continue;
  1587.           }        /* pack it in. */
  1588.  
  1589.         know (0);
  1590.         break;
  1591.           }            /* float arg */
  1592.  
  1593.         case 'F':
  1594.           if (strncmp (s, "%fsr", 4) == 0)
  1595.         {
  1596.           s += 4;
  1597.           continue;
  1598.         }
  1599.           break;
  1600.  
  1601.         case 'h':        /* high 22 bits */
  1602.           the_insn.reloc = BFD_RELOC_HI22;
  1603.           goto immediate;
  1604.  
  1605.         case 'l':        /* 22 bit PC relative immediate */
  1606.           the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
  1607.           the_insn.pcrel = 1;
  1608.           goto immediate;
  1609.  
  1610.         case 'L':        /* 30 bit immediate */
  1611.           the_insn.reloc = BFD_RELOC_32_PCREL_S2;
  1612.           the_insn.pcrel = 1;
  1613.           goto immediate;
  1614.  
  1615.         case 'n':        /* 22 bit immediate */
  1616.           the_insn.reloc = BFD_RELOC_SPARC22;
  1617.           goto immediate;
  1618.  
  1619.         case 'i':        /* 13 bit immediate */
  1620.           the_insn.reloc = BFD_RELOC_SPARC13;
  1621.           immediate_max = 0x0FFF;
  1622.  
  1623.           /*FALLTHROUGH */
  1624.  
  1625.         immediate:
  1626.           if (*s == ' ')
  1627.         s++;
  1628.           if (*s == '%')
  1629.         {
  1630.           if ((c = s[1]) == 'h' && s[2] == 'i')
  1631.             {
  1632.               the_insn.reloc = BFD_RELOC_HI22;
  1633.               s += 3;
  1634.             }
  1635.           else if (c == 'l' && s[2] == 'o')
  1636.             {
  1637.               the_insn.reloc = BFD_RELOC_LO10;
  1638.               s += 3;
  1639.             }
  1640.           else if (c == 'u'
  1641.                && s[2] == 'h'
  1642.                && s[3] == 'i')
  1643.             {
  1644.               the_insn.reloc = BFD_RELOC_SPARC_HH22;
  1645.               s += 4;
  1646.               v9_arg_p = 1;
  1647.             }
  1648.           else if (c == 'u'
  1649.                && s[2] == 'l'
  1650.                && s[3] == 'o')
  1651.             {
  1652.               the_insn.reloc = BFD_RELOC_SPARC_HM10;
  1653.               s += 4;
  1654.               v9_arg_p = 1;
  1655.             }
  1656.           else
  1657.             break;
  1658.         }
  1659.           /* Note that if the getExpression() fails, we will still
  1660.          have created U entries in the symbol table for the
  1661.          'symbols' in the input string.  Try not to create U
  1662.          symbols for registers, etc.  */
  1663.           {
  1664.         /* This stuff checks to see if the expression ends in
  1665.            +%reg.  If it does, it removes the register from
  1666.            the expression, and re-sets 's' to point to the
  1667.            right place.  */
  1668.  
  1669.         char *s1;
  1670.  
  1671.         for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
  1672.  
  1673.         if (s1 != s && isdigit (s1[-1]))
  1674.           {
  1675.             if (s1[-2] == '%' && s1[-3] == '+')
  1676.               {
  1677.             s1 -= 3;
  1678.             *s1 = '\0';
  1679.             (void) getExpression (s);
  1680.             *s1 = '+';
  1681.             s = s1;
  1682.             continue;
  1683.               }
  1684.             else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
  1685.               {
  1686.             s1 -= 4;
  1687.             *s1 = '\0';
  1688.             (void) getExpression (s);
  1689.             *s1 = '+';
  1690.             s = s1;
  1691.             continue;
  1692.               }
  1693.           }
  1694.           }
  1695.           (void) getExpression (s);
  1696.           s = expr_end;
  1697.  
  1698.           if (the_insn.exp.X_op == O_constant
  1699.           && the_insn.exp.X_add_symbol == 0
  1700.           && the_insn.exp.X_op_symbol == 0)
  1701.         {
  1702.           /* Handle %uhi/%ulo by moving the upper word to the lower
  1703.              one and pretending it's %hi/%lo.  We also need to watch
  1704.              for %hi/%lo: the top word needs to be zeroed otherwise
  1705.              fixup_segment will complain the value is too big.  */
  1706.           switch (the_insn.reloc)
  1707.             {
  1708.             case BFD_RELOC_SPARC_HH22:
  1709.               the_insn.reloc = BFD_RELOC_HI22;
  1710.               the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
  1711.               break;
  1712.             case BFD_RELOC_SPARC_HM10:
  1713.               the_insn.reloc = BFD_RELOC_LO10;
  1714.               the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
  1715.               break;
  1716.             case BFD_RELOC_HI22:
  1717.             case BFD_RELOC_LO10:
  1718.               the_insn.exp.X_add_number &= 0xffffffff;
  1719.               break;
  1720.             default:
  1721.               break;
  1722.             }
  1723.  
  1724.           /* For pc-relative call instructions, we reject
  1725.              constants to get better code.  */
  1726.           if (the_insn.pcrel
  1727.               && the_insn.reloc == BFD_RELOC_32_PCREL_S2
  1728.               && in_signed_range (the_insn.exp.X_add_number, 0x3fff)
  1729.               )
  1730.             {
  1731.               error_message = ": PC-relative operand can't be a constant";
  1732.               goto error;
  1733.             }
  1734.           /* Check for invalid constant values.  Don't warn if
  1735.              constant was inside %hi or %lo, since these
  1736.              truncate the constant to fit.  */
  1737.           if (immediate_max != 0
  1738.               && the_insn.reloc != BFD_RELOC_LO10
  1739.               && the_insn.reloc != BFD_RELOC_HI22
  1740.               && !in_signed_range (the_insn.exp.X_add_number,
  1741.                        immediate_max)
  1742.               )
  1743.             {
  1744.               if (the_insn.pcrel)
  1745.             /* Who knows?  After relocation, we may be within
  1746.                range.  Let the linker figure it out.  */
  1747.             {
  1748.               the_insn.exp.X_op = O_symbol;
  1749.               the_insn.exp.X_add_symbol = section_symbol (absolute_section);
  1750.             }
  1751.               else
  1752.             /* Immediate value is non-pcrel, and out of
  1753.                            range.  */
  1754.             as_bad ("constant value %ld out of range (%ld .. %ld)",
  1755.                 the_insn.exp.X_add_number,
  1756.                 ~immediate_max, immediate_max);
  1757.             }
  1758.         }
  1759.  
  1760.           /* Reset to prevent extraneous range check.  */
  1761.           immediate_max = 0;
  1762.  
  1763.           continue;
  1764.  
  1765.         case 'a':
  1766.           if (*s++ == 'a')
  1767.         {
  1768.           opcode |= ANNUL;
  1769.           continue;
  1770.         }
  1771.           break;
  1772.  
  1773.         case 'A':
  1774.           {
  1775.         int asi = 0;
  1776.  
  1777.         /* Parse an asi.  */
  1778.         if (*s == '#')
  1779.           {
  1780.             if (! parse_keyword_arg (sparc_encode_asi, &s, &asi))
  1781.               {
  1782.             error_message = ": invalid ASI name";
  1783.             goto error;
  1784.               }
  1785.           }
  1786.         else
  1787.           {
  1788.             if (! parse_const_expr_arg (&s, &asi))
  1789.               {
  1790.             error_message = ": invalid ASI expression";
  1791.             goto error;
  1792.               }
  1793.             if (asi < 0 || asi > 255)
  1794.               {
  1795.             error_message = ": invalid ASI number";
  1796.             goto error;
  1797.               }
  1798.           }
  1799.         opcode |= ASI (asi);
  1800.         continue;
  1801.           }            /* alternate space */
  1802.  
  1803.         case 'p':
  1804.           if (strncmp (s, "%psr", 4) == 0)
  1805.         {
  1806.           s += 4;
  1807.           continue;
  1808.         }
  1809.           break;
  1810.  
  1811.         case 'q':        /* floating point queue */
  1812.           if (strncmp (s, "%fq", 3) == 0)
  1813.         {
  1814.           s += 3;
  1815.           continue;
  1816.         }
  1817.           break;
  1818.  
  1819.         case 'Q':        /* coprocessor queue */
  1820.           if (strncmp (s, "%cq", 3) == 0)
  1821.         {
  1822.           s += 3;
  1823.           continue;
  1824.         }
  1825.           break;
  1826.  
  1827.         case 'S':
  1828.           if (strcmp (str, "set") == 0)
  1829.         {
  1830.           special_case = SPECIAL_CASE_SET;
  1831.           continue;
  1832.         }
  1833.           else if (strncmp (str, "fdiv", 4) == 0)
  1834.         {
  1835.           special_case = SPECIAL_CASE_FDIV;
  1836.           continue;
  1837.         }
  1838.           break;
  1839.  
  1840.         case 'o':
  1841.           if (strncmp (s, "%asi", 4) != 0)
  1842.         break;
  1843.           s += 4;
  1844.           continue;
  1845.  
  1846.         case 's':
  1847.           if (strncmp (s, "%fprs", 5) != 0)
  1848.         break;
  1849.           s += 5;
  1850.           continue;
  1851.  
  1852.         case 'E':
  1853.           if (strncmp (s, "%ccr", 4) != 0)
  1854.         break;
  1855.           s += 4;
  1856.           continue;
  1857.  
  1858.         case 't':
  1859.           if (strncmp (s, "%tbr", 4) != 0)
  1860.         break;
  1861.           s += 4;
  1862.           continue;
  1863.  
  1864.         case 'w':
  1865.           if (strncmp (s, "%wim", 4) != 0)
  1866.         break;
  1867.           s += 4;
  1868.           continue;
  1869.  
  1870.         case 'x':
  1871.           {
  1872.         char *push = input_line_pointer;
  1873.         expressionS e;
  1874.  
  1875.         input_line_pointer = s;
  1876.         expression (&e);
  1877.         if (e.X_op == O_constant)
  1878.           {
  1879.             int n = e.X_add_number;
  1880.             if (n != e.X_add_number || (n & ~0x1ff) != 0)
  1881.               as_bad ("OPF immediate operand out of range (0-0x1ff)");
  1882.             else
  1883.               opcode |= e.X_add_number << 5;
  1884.           }
  1885.         else
  1886.           as_bad ("non-immediate OPF operand, ignored");
  1887.         s = input_line_pointer;
  1888.         input_line_pointer = push;
  1889.         continue;
  1890.           }
  1891.  
  1892.         case 'y':
  1893.           if (strncmp (s, "%y", 2) != 0)
  1894.         break;
  1895.           s += 2;
  1896.           continue;
  1897.  
  1898.         case 'u':
  1899.         case 'U':
  1900.           {
  1901.         /* Parse a sparclet cpreg.  */
  1902.         int cpreg;
  1903.         if (! parse_keyword_arg (sparc_encode_sparclet_cpreg, &s, &cpreg))
  1904.           {
  1905.             error_message = ": invalid cpreg name";
  1906.             goto error;
  1907.           }
  1908.         opcode |= (*args == 'U' ? RS1 (cpreg) : RD (cpreg));
  1909.         continue;
  1910.           }
  1911.  
  1912.         default:
  1913.           as_fatal ("failed sanity check.");
  1914.         }            /* switch on arg code */
  1915.  
  1916.       /* Break out of for() loop.  */
  1917.       break;
  1918.     }            /* for each arg that we expect */
  1919.  
  1920.     error:
  1921.       if (match == 0)
  1922.     {
  1923.       /* Args don't match. */
  1924.       if (((unsigned) (&insn[1] - sparc_opcodes)) < sparc_num_opcodes
  1925.           && (insn->name == insn[1].name
  1926.           || !strcmp (insn->name, insn[1].name)))
  1927.         {
  1928.           ++insn;
  1929.           s = argsStart;
  1930.           continue;
  1931.         }
  1932.       else
  1933.         {
  1934.           as_bad ("Illegal operands%s", error_message);
  1935.           return;
  1936.         }
  1937.     }
  1938.       else
  1939.     {
  1940.       /* We have a match.  Now see if the architecture is ok.  */
  1941.       int needed_arch_mask = insn->architecture;
  1942.  
  1943.       if (v9_arg_p)
  1944.         {
  1945.           needed_arch_mask &= ~ ((1 << SPARC_OPCODE_ARCH_V9)
  1946.                      | (1 << SPARC_OPCODE_ARCH_V9A));
  1947.           needed_arch_mask |= (1 << SPARC_OPCODE_ARCH_V9);
  1948.         }
  1949.  
  1950.       if (needed_arch_mask & SPARC_OPCODE_SUPPORTED (current_architecture))
  1951.         ; /* ok */
  1952.       /* Can we bump up the architecture?  */
  1953.       else if (needed_arch_mask & SPARC_OPCODE_SUPPORTED (max_architecture))
  1954.         {
  1955.           enum sparc_opcode_arch_val needed_architecture =
  1956.         sparc_ffs (SPARC_OPCODE_SUPPORTED (max_architecture)
  1957.                & needed_arch_mask);
  1958.  
  1959.           assert (needed_architecture <= SPARC_OPCODE_ARCH_MAX);
  1960.           if (warn_on_bump
  1961.           && needed_architecture > warn_after_architecture)
  1962.         {
  1963.           as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
  1964.                sparc_opcode_archs[current_architecture].name,
  1965.                sparc_opcode_archs[needed_architecture].name,
  1966.                str);
  1967.           warn_after_architecture = needed_architecture;
  1968.         }
  1969.           current_architecture = needed_architecture;
  1970.         }
  1971.       /* Conflict.  */
  1972.       /* ??? This seems to be a bit fragile.  What if the next entry in
  1973.          the opcode table is the one we want and it is supported?
  1974.          It is possible to arrange the table today so that this can't
  1975.          happen but what about tomorrow?  */
  1976.       else
  1977.         {
  1978.           int arch,printed_one_p = 0;
  1979.           char *p;
  1980.           char required_archs[SPARC_OPCODE_ARCH_MAX * 16];
  1981.  
  1982.           /* Create a list of the architectures that support the insn.  */
  1983.           needed_arch_mask &= ~ SPARC_OPCODE_SUPPORTED (max_architecture);
  1984.           p = required_archs;
  1985.           arch = sparc_ffs (needed_arch_mask);
  1986.           while ((1 << arch) <= needed_arch_mask)
  1987.         {
  1988.           if ((1 << arch) & needed_arch_mask)
  1989.             {
  1990.               if (printed_one_p)
  1991.             *p++ = '|';
  1992.               strcpy (p, sparc_opcode_archs[arch].name);
  1993.               p += strlen (p);
  1994.               printed_one_p = 1;
  1995.             }
  1996.           ++arch;
  1997.         }
  1998.  
  1999.           as_bad ("Architecture mismatch on \"%s\".", str);
  2000.           as_tsktsk (" (Requires %s; requested architecture is %s.)",
  2001.              required_archs,
  2002.              sparc_opcode_archs[max_architecture].name);
  2003.           return;
  2004.         }
  2005.     } /* if no match */
  2006.  
  2007.       break;
  2008.     } /* forever looking for a match */
  2009.  
  2010.   the_insn.opcode = opcode;
  2011. }
  2012.  
  2013. static int
  2014. getExpression (str)
  2015.      char *str;
  2016. {
  2017.   char *save_in;
  2018.   segT seg;
  2019.  
  2020.   save_in = input_line_pointer;
  2021.   input_line_pointer = str;
  2022.   seg = expression (&the_insn.exp);
  2023.   if (seg != absolute_section
  2024.       && seg != text_section
  2025.       && seg != data_section
  2026.       && seg != bss_section
  2027.       && seg != undefined_section)
  2028.     {
  2029.       the_insn.error = "bad segment";
  2030.       expr_end = input_line_pointer;
  2031.       input_line_pointer = save_in;
  2032.       return 1;
  2033.     }
  2034.   expr_end = input_line_pointer;
  2035.   input_line_pointer = save_in;
  2036.   return 0;
  2037. }                /* getExpression() */
  2038.  
  2039.  
  2040. /*
  2041.   This is identical to the md_atof in m68k.c.  I think this is right,
  2042.   but I'm not sure.
  2043.  
  2044.   Turn a string in input_line_pointer into a floating point constant of type
  2045.   type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2046.   emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  2047.   */
  2048.  
  2049. /* Equal to MAX_PRECISION in atof-ieee.c */
  2050. #define MAX_LITTLENUMS 6
  2051.  
  2052. char *
  2053. md_atof (type, litP, sizeP)
  2054.      char type;
  2055.      char *litP;
  2056.      int *sizeP;
  2057. {
  2058.   int prec;
  2059.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2060.   LITTLENUM_TYPE *wordP;
  2061.   char *t;
  2062.   char *atof_ieee ();
  2063.  
  2064.   switch (type)
  2065.     {
  2066.  
  2067.     case 'f':
  2068.     case 'F':
  2069.     case 's':
  2070.     case 'S':
  2071.       prec = 2;
  2072.       break;
  2073.  
  2074.     case 'd':
  2075.     case 'D':
  2076.     case 'r':
  2077.     case 'R':
  2078.       prec = 4;
  2079.       break;
  2080.  
  2081.     case 'x':
  2082.     case 'X':
  2083.       prec = 6;
  2084.       break;
  2085.  
  2086.     case 'p':
  2087.     case 'P':
  2088.       prec = 6;
  2089.       break;
  2090.  
  2091.     default:
  2092.       *sizeP = 0;
  2093.       return "Bad call to MD_ATOF()";
  2094.     }
  2095.   t = atof_ieee (input_line_pointer, type, words);
  2096.   if (t)
  2097.     input_line_pointer = t;
  2098.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  2099.   for (wordP = words; prec--;)
  2100.     {
  2101.       md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
  2102.       litP += sizeof (LITTLENUM_TYPE);
  2103.     }
  2104.   return 0;
  2105. }
  2106.  
  2107. /*
  2108.  * Write out big-endian.
  2109.  */
  2110. void
  2111. md_number_to_chars (buf, val, n)
  2112.      char *buf;
  2113.      valueT val;
  2114.      int n;
  2115. {
  2116.   number_to_chars_bigendian (buf, val, n);
  2117. }
  2118.  
  2119. /* Apply a fixS to the frags, now that we know the value it ought to
  2120.    hold. */
  2121.  
  2122. int
  2123. md_apply_fix (fixP, value)
  2124.      fixS *fixP;
  2125.      valueT *value;
  2126. {
  2127.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  2128.   offsetT val;
  2129.  
  2130.   val = *value;
  2131.  
  2132.   assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  2133.  
  2134.   fixP->fx_addnumber = val;    /* Remember value for emit_reloc */
  2135.  
  2136. #ifdef OBJ_ELF
  2137.   /* FIXME: SPARC ELF relocations don't use an addend in the data
  2138.      field itself.  This whole approach should be somehow combined
  2139.      with the calls to bfd_perform_relocation.  Also, the value passed
  2140.      in by fixup_segment includes the value of a defined symbol.  We
  2141.      don't want to include the value of an externally visible symbol.  */
  2142.   if (fixP->fx_addsy != NULL)
  2143.     {
  2144.       if ((S_IS_EXTERNAL (fixP->fx_addsy)
  2145.        || S_IS_WEAK (fixP->fx_addsy)
  2146.        || (sparc_pic_code && ! fixP->fx_pcrel))
  2147.       && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section
  2148.       && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section
  2149.       && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy)))
  2150.     fixP->fx_addnumber -= S_GET_VALUE (fixP->fx_addsy);
  2151.       return 1;
  2152.     }
  2153. #endif
  2154.  
  2155.   /* This is a hack.  There should be a better way to
  2156.      handle this.  Probably in terms of howto fields, once
  2157.      we can look at these fixups in terms of howtos.  */
  2158.   if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
  2159.     val += fixP->fx_where + fixP->fx_frag->fr_address;
  2160.  
  2161. #ifdef OBJ_AOUT
  2162.   /* FIXME: More ridiculous gas reloc hacking.  If we are going to
  2163.      generate a reloc, then we just want to let the reloc addend set
  2164.      the value.  We do not want to also stuff the addend into the
  2165.      object file.  Including the addend in the object file works when
  2166.      doing a static link, because the linker will ignore the object
  2167.      file contents.  However, the dynamic linker does not ignore the
  2168.      object file contents.  */
  2169.   if (fixP->fx_addsy != NULL
  2170.       && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
  2171.     val = 0;
  2172.  
  2173.   /* When generating PIC code, we do not want an addend for a reloc
  2174.      against a local symbol.  We adjust fx_addnumber to cancel out the
  2175.      value already included in val, and to also cancel out the
  2176.      adjustment which bfd_install_relocation will create.  */
  2177.   if (sparc_pic_code
  2178.       && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2
  2179.       && fixP->fx_addsy != NULL
  2180.       && ! S_IS_COMMON (fixP->fx_addsy)
  2181.       && (fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) == 0)
  2182.     fixP->fx_addnumber -= 2 * S_GET_VALUE (fixP->fx_addsy);
  2183. #endif
  2184.  
  2185.   switch (fixP->fx_r_type)
  2186.     {
  2187.     case BFD_RELOC_16:
  2188.       buf[0] = val >> 8;
  2189.       buf[1] = val;
  2190.       break;
  2191.  
  2192.     case BFD_RELOC_32:
  2193.       buf[0] = val >> 24;
  2194.       buf[1] = val >> 16;
  2195.       buf[2] = val >> 8;
  2196.       buf[3] = val;
  2197.       break;
  2198.  
  2199.     case BFD_RELOC_32_PCREL_S2:
  2200.       val = val >> 2;
  2201.       /* FIXME: This increment-by-one deserves a comment of why it's
  2202.      being done!  */
  2203.       if (! sparc_pic_code
  2204.       || fixP->fx_addsy == NULL
  2205.       || (fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
  2206.     ++val;
  2207.       buf[0] |= (val >> 24) & 0x3f;
  2208.       buf[1] = val >> 16;
  2209.       buf[2] = val >> 8;
  2210.       buf[3] = val;
  2211.       break;
  2212.  
  2213.     case BFD_RELOC_64:
  2214.       {
  2215.     bfd_vma valh = BSR (val, 32);
  2216.     buf[0] = valh >> 24;
  2217.     buf[1] = valh >> 16;
  2218.     buf[2] = valh >> 8;
  2219.     buf[3] = valh;
  2220.     buf[4] = val >> 24;
  2221.     buf[5] = val >> 16;
  2222.     buf[6] = val >> 8;
  2223.     buf[7] = val;
  2224.       }
  2225.       break;
  2226.  
  2227.     case BFD_RELOC_SPARC_11:
  2228.       if (! in_signed_range (val, 0x7ff))
  2229.     as_bad ("relocation overflow.");
  2230.  
  2231.       buf[2] |= (val >> 8) & 0x7;
  2232.       buf[3] = val;
  2233.       break;
  2234.  
  2235.     case BFD_RELOC_SPARC_10:
  2236.       if (! in_signed_range (val, 0x3ff))
  2237.     as_bad ("relocation overflow.");
  2238.  
  2239.       buf[2] |= (val >> 8) & 0x3;
  2240.       buf[3] = val;
  2241.       break;
  2242.  
  2243.     case BFD_RELOC_SPARC_6:
  2244.       if (! in_bitfield_range (val, 0x3f))
  2245.     as_bad ("relocation overflow.");
  2246.  
  2247.       buf[3] |= val & 0x3f;
  2248.       break;
  2249.  
  2250.     case BFD_RELOC_SPARC_5:
  2251.       if (! in_bitfield_range (val, 0x1f))
  2252.     as_bad ("relocation overflow.");
  2253.  
  2254.       buf[3] |= val & 0x1f;
  2255.       break;
  2256.  
  2257.     case BFD_RELOC_SPARC_WDISP16:
  2258.       /* FIXME: simplify */
  2259.       if (((val > 0) && (val & ~0x3fffc))
  2260.       || ((val < 0) && (~(val - 1) & ~0x3fffc)))
  2261.     {
  2262.       as_bad ("relocation overflow.");
  2263.     }
  2264.  
  2265.       /* FIXME: The +1 deserves a comment.  */
  2266.       val = (val >> 2) + 1;
  2267.       buf[1] |= ((val >> 14) & 0x3) << 4;
  2268.       buf[2] |= (val >> 8) & 0x3f;
  2269.       buf[3] = val;
  2270.       break;
  2271.  
  2272.     case BFD_RELOC_SPARC_WDISP19:
  2273.       /* FIXME: simplify */
  2274.       if (((val > 0) && (val & ~0x1ffffc))
  2275.       || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
  2276.     {
  2277.       as_bad ("relocation overflow.");
  2278.     }
  2279.  
  2280.       /* FIXME: The +1 deserves a comment.  */
  2281.       val = (val >> 2) + 1;
  2282.       buf[1] |= (val >> 16) & 0x7;
  2283.       buf[2] = (val >> 8) & 0xff;
  2284.       buf[3] = val;
  2285.       break;
  2286.  
  2287.     case BFD_RELOC_SPARC_HH22:
  2288.       val = BSR (val, 32);
  2289.       /* intentional fallthrough */
  2290.  
  2291.     case BFD_RELOC_SPARC_LM22:
  2292.     case BFD_RELOC_HI22:
  2293.       if (!fixP->fx_addsy)
  2294.     {
  2295.       buf[1] |= (val >> 26) & 0x3f;
  2296.       buf[2] = val >> 18;
  2297.       buf[3] = val >> 10;
  2298.     }
  2299.       else
  2300.     {
  2301.       buf[2] = 0;
  2302.       buf[3] = 0;
  2303.     }
  2304.       break;
  2305.  
  2306.     case BFD_RELOC_SPARC22:
  2307.       if (val & ~0x003fffff)
  2308.     {
  2309.       as_bad ("relocation overflow");
  2310.     }            /* on overflow */
  2311.       buf[1] |= (val >> 16) & 0x3f;
  2312.       buf[2] = val >> 8;
  2313.       buf[3] = val;
  2314.       break;
  2315.  
  2316.     case BFD_RELOC_SPARC_HM10:
  2317.       val = BSR (val, 32);
  2318.       /* intentional fallthrough */
  2319.  
  2320.     case BFD_RELOC_LO10:
  2321.       if (!fixP->fx_addsy)
  2322.     {
  2323.       buf[2] |= (val >> 8) & 0x03;
  2324.       buf[3] = val;
  2325.     }
  2326.       else
  2327.     buf[3] = 0;
  2328.       break;
  2329.  
  2330.     case BFD_RELOC_SPARC13:
  2331.       if (! in_signed_range (val, 0x1fff))
  2332.     as_bad ("relocation overflow");
  2333.  
  2334.       buf[2] |= (val >> 8) & 0x1f;
  2335.       buf[3] = val;
  2336.       break;
  2337.  
  2338.     case BFD_RELOC_SPARC_WDISP22:
  2339.       val = (val >> 2) + 1;
  2340.       /* FALLTHROUGH */
  2341.     case BFD_RELOC_SPARC_BASE22:
  2342.       buf[1] |= (val >> 16) & 0x3f;
  2343.       buf[2] = val >> 8;
  2344.       buf[3] = val;
  2345.       break;
  2346.  
  2347.     case BFD_RELOC_NONE:
  2348.     default:
  2349.       as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
  2350.       break;
  2351.     }
  2352.  
  2353.   /* Are we finished with this relocation now?  */
  2354.   if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
  2355.     fixP->fx_done = 1;
  2356.  
  2357.   return 1;
  2358. }
  2359.  
  2360. /* Translate internal representation of relocation info to BFD target
  2361.    format.  */
  2362. arelent *
  2363. tc_gen_reloc (section, fixp)
  2364.      asection *section;
  2365.      fixS *fixp;
  2366. {
  2367.   arelent *reloc;
  2368.   bfd_reloc_code_real_type code;
  2369.  
  2370.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  2371.   assert (reloc != 0);
  2372.  
  2373.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2374.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2375.  
  2376.   switch (fixp->fx_r_type)
  2377.     {
  2378.     case BFD_RELOC_16:
  2379.     case BFD_RELOC_32:
  2380.     case BFD_RELOC_HI22:
  2381.     case BFD_RELOC_LO10:
  2382.     case BFD_RELOC_32_PCREL_S2:
  2383.     case BFD_RELOC_SPARC13:
  2384.     case BFD_RELOC_SPARC_BASE13:
  2385.     case BFD_RELOC_SPARC_WDISP16:
  2386.     case BFD_RELOC_SPARC_WDISP19:
  2387.     case BFD_RELOC_SPARC_WDISP22:
  2388.     case BFD_RELOC_64:
  2389.     case BFD_RELOC_SPARC_5:
  2390.     case BFD_RELOC_SPARC_6:
  2391.     case BFD_RELOC_SPARC_10:
  2392.     case BFD_RELOC_SPARC_11:
  2393.     case BFD_RELOC_SPARC_HH22:
  2394.     case BFD_RELOC_SPARC_HM10:
  2395.     case BFD_RELOC_SPARC_LM22:
  2396.     case BFD_RELOC_SPARC_PC_HH22:
  2397.     case BFD_RELOC_SPARC_PC_HM10:
  2398.     case BFD_RELOC_SPARC_PC_LM22:
  2399.       code = fixp->fx_r_type;
  2400.       break;
  2401.     default:
  2402.       abort ();
  2403.     }
  2404.  
  2405. #if defined (OBJ_ELF) || defined (OBJ_AOUT)
  2406.   /* If we are generating PIC code, we need to generate a different
  2407.      set of relocs.  */
  2408.  
  2409. #ifdef OBJ_ELF
  2410. #define GOT_NAME "_GLOBAL_OFFSET_TABLE_"
  2411. #else
  2412. #define GOT_NAME "__GLOBAL_OFFSET_TABLE_"
  2413. #endif
  2414.  
  2415.   if (sparc_pic_code)
  2416.     {
  2417.       switch (code)
  2418.     {
  2419.     case BFD_RELOC_32_PCREL_S2:
  2420.       if (! S_IS_DEFINED (fixp->fx_addsy)
  2421.           || S_IS_EXTERNAL (fixp->fx_addsy)
  2422.           || S_IS_WEAK (fixp->fx_addsy))
  2423.         code = BFD_RELOC_SPARC_WPLT30;
  2424.       break;
  2425.     case BFD_RELOC_HI22:
  2426.       if (fixp->fx_addsy != NULL
  2427.           && strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
  2428.         code = BFD_RELOC_SPARC_PC22;
  2429.       else
  2430.         code = BFD_RELOC_SPARC_GOT22;
  2431.       break;
  2432.     case BFD_RELOC_LO10:
  2433.       if (fixp->fx_addsy != NULL
  2434.           && strcmp (S_GET_NAME (fixp->fx_addsy), GOT_NAME) == 0)
  2435.         code = BFD_RELOC_SPARC_PC10;
  2436.       else
  2437.         code = BFD_RELOC_SPARC_GOT10;
  2438.       break;
  2439.     case BFD_RELOC_SPARC13:
  2440.       code = BFD_RELOC_SPARC_GOT13;
  2441.       break;
  2442.     default:
  2443.       break;
  2444.     }
  2445.     }
  2446. #endif /* defined (OBJ_ELF) || defined (OBJ_AOUT) */
  2447.  
  2448.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  2449.   if (reloc->howto == 0)
  2450.     {
  2451.       as_bad_where (fixp->fx_file, fixp->fx_line,
  2452.             "internal error: can't export reloc type %d (`%s')",
  2453.             fixp->fx_r_type, bfd_get_reloc_code_name (code));
  2454.       return 0;
  2455.     }
  2456.  
  2457.   /* @@ Why fx_addnumber sometimes and fx_offset other times?  */
  2458. #ifdef OBJ_AOUT
  2459.  
  2460.   if (reloc->howto->pc_relative == 0
  2461.       || code == BFD_RELOC_SPARC_PC10
  2462.       || code == BFD_RELOC_SPARC_PC22)
  2463.     reloc->addend = fixp->fx_addnumber;
  2464.   else
  2465.     reloc->addend = fixp->fx_offset - reloc->address;
  2466.  
  2467. #else /* elf or coff */
  2468.  
  2469.   if (reloc->howto->pc_relative == 0
  2470.       || code == BFD_RELOC_SPARC_PC10
  2471.       || code == BFD_RELOC_SPARC_PC22)
  2472.     reloc->addend = fixp->fx_addnumber;
  2473.   else if ((fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
  2474.     reloc->addend = (section->vma
  2475.              + fixp->fx_addnumber
  2476.              + md_pcrel_from (fixp));
  2477.   else
  2478.     reloc->addend = fixp->fx_offset;
  2479. #endif
  2480.  
  2481.   return reloc;
  2482. }
  2483.  
  2484.  
  2485. #if 0
  2486. /* for debugging only */
  2487. static void
  2488. print_insn (insn)
  2489.      struct sparc_it *insn;
  2490. {
  2491.   const char *const Reloc[] = {
  2492.     "RELOC_8",
  2493.     "RELOC_16",
  2494.     "RELOC_32",
  2495.     "RELOC_DISP8",
  2496.     "RELOC_DISP16",
  2497.     "RELOC_DISP32",
  2498.     "RELOC_WDISP30",
  2499.     "RELOC_WDISP22",
  2500.     "RELOC_HI22",
  2501.     "RELOC_22",
  2502.     "RELOC_13",
  2503.     "RELOC_LO10",
  2504.     "RELOC_SFA_BASE",
  2505.     "RELOC_SFA_OFF13",
  2506.     "RELOC_BASE10",
  2507.     "RELOC_BASE13",
  2508.     "RELOC_BASE22",
  2509.     "RELOC_PC10",
  2510.     "RELOC_PC22",
  2511.     "RELOC_JMP_TBL",
  2512.     "RELOC_SEGOFF16",
  2513.     "RELOC_GLOB_DAT",
  2514.     "RELOC_JMP_SLOT",
  2515.     "RELOC_RELATIVE",
  2516.     "NO_RELOC"
  2517.   };
  2518.  
  2519.   if (insn->error)
  2520.     fprintf (stderr, "ERROR: %s\n");
  2521.   fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
  2522.   fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
  2523.   fprintf (stderr, "exp = {\n");
  2524.   fprintf (stderr, "\t\tX_add_symbol = %s\n",
  2525.        ((insn->exp.X_add_symbol != NULL)
  2526.         ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
  2527.            ? S_GET_NAME (insn->exp.X_add_symbol)
  2528.            : "???")
  2529.         : "0"));
  2530.   fprintf (stderr, "\t\tX_sub_symbol = %s\n",
  2531.        ((insn->exp.X_op_symbol != NULL)
  2532.         ? (S_GET_NAME (insn->exp.X_op_symbol)
  2533.            ? S_GET_NAME (insn->exp.X_op_symbol)
  2534.            : "???")
  2535.         : "0"));
  2536.   fprintf (stderr, "\t\tX_add_number = %d\n",
  2537.        insn->exp.X_add_number);
  2538.   fprintf (stderr, "}\n");
  2539. }
  2540. #endif
  2541.  
  2542. /*
  2543.  * md_parse_option
  2544.  *    Invocation line includes a switch not recognized by the base assembler.
  2545.  *    See if it's a processor-specific option.  These are:
  2546.  *
  2547.  *    -bump
  2548.  *        Warn on architecture bumps.  See also -A.
  2549.  *
  2550.  *    -Av6, -Av7, -Av8, -Av9, -Av9a, -Asparclite
  2551.  *    -xarch=v8plus, -xarch=v8plusa
  2552.  *        Select the architecture.  Instructions or features not
  2553.  *        supported by the selected architecture cause fatal errors.
  2554.  *
  2555.  *        The default is to start at v6, and bump the architecture up
  2556.  *        whenever an instruction is seen at a higher level.  If 32 bit
  2557.  *        environments, v9 is not bumped up to, the user must pass -Av9.
  2558.  *
  2559.  *        -xarch=v8plus{,a} is for compatibility with the Sun assembler.
  2560.  *
  2561.  *        If -bump is specified, a warning is printing when bumping to
  2562.  *        higher levels.
  2563.  *
  2564.  *        If an architecture is specified, all instructions must match
  2565.  *        that architecture.  Any higher level instructions are flagged
  2566.  *        as errors.  Note that in the 32 bit environment specifying
  2567.  *        -Av9 does not automatically create a v9 object file, a v9
  2568.  *        insn must be seen.
  2569.  *
  2570.  *        If both an architecture and -bump are specified, the
  2571.  *        architecture starts at the specified level, but bumps are
  2572.  *        warnings.  Note that we can't set `current_architecture' to
  2573.  *        the requested level in this case: in the 32 bit environment,
  2574.  *        we still must avoid creating v9 object files unless v9 insns
  2575.  *        are seen.
  2576.  *
  2577.  * Note:
  2578.  *        Bumping between incompatible architectures is always an
  2579.  *        error.  For example, from sparclite to v9.
  2580.  */
  2581.  
  2582. #ifdef OBJ_ELF
  2583. CONST char *md_shortopts = "A:K:VQ:sq";
  2584. #else
  2585. #ifdef OBJ_AOUT
  2586. CONST char *md_shortopts = "A:k";
  2587. #else
  2588. CONST char *md_shortopts = "A:";
  2589. #endif
  2590. #endif
  2591. struct option md_longopts[] = {
  2592. #define OPTION_BUMP (OPTION_MD_BASE)
  2593.   {"bump", no_argument, NULL, OPTION_BUMP},
  2594. #define OPTION_SPARC (OPTION_MD_BASE + 1)
  2595.   {"sparc", no_argument, NULL, OPTION_SPARC},
  2596. #define OPTION_XARCH (OPTION_MD_BASE + 2)
  2597.   {"xarch", required_argument, NULL, OPTION_XARCH},
  2598.   {NULL, no_argument, NULL, 0}
  2599. };
  2600. size_t md_longopts_size = sizeof(md_longopts);
  2601.  
  2602. int
  2603. md_parse_option (c, arg)
  2604.      int c;
  2605.      char *arg;
  2606. {
  2607.   switch (c)
  2608.     {
  2609.     case OPTION_BUMP:
  2610.       warn_on_bump = 1;
  2611.       warn_after_architecture = SPARC_OPCODE_ARCH_V6;
  2612.       break;
  2613.  
  2614.     case OPTION_XARCH:
  2615.       /* ??? We could add v8plus and v8plusa to sparc_opcode_archs.
  2616.      But we might want v8plus to mean something different than v9
  2617.      someday, and we'd recognize more -xarch options than Sun's
  2618.      assembler does (which may lead to a conflict someday).  */
  2619.       if (strcmp (arg, "v8plus") == 0)
  2620.     arg = "v9";
  2621.       else if (strcmp (arg, "v8plusa") == 0)
  2622.     arg = "v9a";
  2623.       else
  2624.     {
  2625.       as_bad ("invalid architecture -xarch=%s", arg);
  2626.       return 0;
  2627.     }
  2628.  
  2629.       /* fall through */
  2630.  
  2631.     case 'A':
  2632.       {
  2633.     enum sparc_opcode_arch_val new_arch = sparc_opcode_lookup_arch (arg);
  2634.  
  2635.     if (new_arch == SPARC_OPCODE_ARCH_BAD)
  2636.       {
  2637.         as_bad ("invalid architecture -A%s", arg);
  2638.         return 0;
  2639.       }
  2640.     else
  2641.       {
  2642.         max_architecture = new_arch;
  2643.         architecture_requested = 1;
  2644.       }
  2645.       }
  2646.       break;
  2647.  
  2648.     case OPTION_SPARC:
  2649.       /* Ignore -sparc, used by SunOS make default .s.o rule.  */
  2650.       break;
  2651.  
  2652. #ifdef OBJ_AOUT
  2653.     case 'k':
  2654.       sparc_pic_code = 1;
  2655.       break;
  2656. #endif
  2657.  
  2658. #ifdef OBJ_ELF
  2659.     case 'V':
  2660.       print_version_id ();
  2661.       break;
  2662.  
  2663.     case 'Q':
  2664.       /* Qy - do emit .comment
  2665.      Qn - do not emit .comment */
  2666.       break;
  2667.  
  2668.     case 's':
  2669.       /* use .stab instead of .stab.excl */
  2670.       break;
  2671.  
  2672.     case 'q':
  2673.       /* quick -- native assembler does fewer checks */
  2674.       break;
  2675.  
  2676.     case 'K':
  2677.       if (strcmp (arg, "PIC") != 0)
  2678.     as_warn ("Unrecognized option following -K");
  2679.       else
  2680.     sparc_pic_code = 1;
  2681.       break;
  2682. #endif
  2683.  
  2684.     default:
  2685.       return 0;
  2686.     }
  2687.  
  2688.   return 1;
  2689. }
  2690.  
  2691. void
  2692. md_show_usage (stream)
  2693.      FILE *stream;
  2694. {
  2695.   const struct sparc_opcode_arch *arch;
  2696.  
  2697.   fprintf(stream, "SPARC options:\n");
  2698.   for (arch = &sparc_opcode_archs[0]; arch->name; arch++)
  2699.     {
  2700.       if (arch != &sparc_opcode_archs[0])
  2701.     fprintf (stream, " | ");
  2702.       fprintf (stream, "-A%s", arch->name);
  2703.     }
  2704.   fprintf (stream, "\n-xarch=v8plus | -xarch=v8plusa\n");
  2705.   fprintf (stream, "\
  2706.             specify variant of SPARC architecture\n\
  2707. -bump            warn when assembler switches architectures\n\
  2708. -sparc            ignored\n");
  2709. #ifdef OBJ_AOUT
  2710.   fprintf (stream, "\
  2711. -k            generate PIC\n");
  2712. #endif
  2713. #ifdef OBJ_ELF
  2714.   fprintf (stream, "\
  2715. -KPIC            generate PIC\n\
  2716. -V            print assembler version number\n\
  2717. -q            ignored\n\
  2718. -Qy, -Qn        ignored\n\
  2719. -s            ignored\n");
  2720. #endif
  2721. }
  2722.  
  2723. /* We have no need to default values of symbols. */
  2724.  
  2725. /* ARGSUSED */
  2726. symbolS *
  2727. md_undefined_symbol (name)
  2728.      char *name;
  2729. {
  2730.   return 0;
  2731. }                /* md_undefined_symbol() */
  2732.  
  2733. /* Round up a section size to the appropriate boundary. */
  2734. valueT
  2735. md_section_align (segment, size)
  2736.      segT segment;
  2737.      valueT size;
  2738. {
  2739. #ifndef OBJ_ELF
  2740.   /* This is not right for ELF; a.out wants it, and COFF will force
  2741.      the alignment anyways.  */
  2742.   valueT align = ((valueT) 1
  2743.           << (valueT) bfd_get_section_alignment (stdoutput, segment));
  2744.   valueT newsize;
  2745.   /* turn alignment value into a mask */
  2746.   align--;
  2747.   newsize = (size + align) & ~align;
  2748.   return newsize;
  2749. #else
  2750.   return size;
  2751. #endif
  2752. }
  2753.  
  2754. /* Exactly what point is a PC-relative offset relative TO?
  2755.    On the sparc, they're relative to the address of the offset, plus
  2756.    its size.  This gets us to the following instruction.
  2757.    (??? Is this right?  FIXME-SOON) */
  2758. long 
  2759. md_pcrel_from (fixP)
  2760.      fixS *fixP;
  2761. {
  2762.   long ret;
  2763.  
  2764.   ret = fixP->fx_where + fixP->fx_frag->fr_address;
  2765.   if (! sparc_pic_code
  2766.       || fixP->fx_addsy == NULL
  2767.       || (fixP->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
  2768.     ret += fixP->fx_size;
  2769.   return ret;
  2770. }
  2771.  
  2772. /* end of tc-sparc.c */
  2773.