* alpha-opc.c: Remove ARGSUSED.
[deliverable/binutils-gdb.git] / gas / config / tc-xstormy16.c
index 446ac389c564a36bbf78e79b5dacb52b5dc268a0..83ae94d382aa9b3f678fa444402f76fd96112098 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-xstormy16.c -- Assembler for the Sanyo XSTORMY16.
-   Copyright (C) 2000, 2001, 2002 Free Software Foundation.
+   Copyright 2000, 2001, 2002, 2003 Free Software Foundation.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -20,7 +20,7 @@
 
 #include <stdio.h>
 #include "as.h"
-#include "subsegs.h"     
+#include "subsegs.h"
 #include "symcat.h"
 #include "opcodes/xstormy16-desc.h"
 #include "opcodes/xstormy16-opc.h"
@@ -78,7 +78,7 @@ md_show_usage (stream)
   FILE * stream;
 {
   fprintf (stream, _(" XSTORMY16 specific command line options:\n"));
-} 
+}
 
 /* The target specific pseudo-ops which we support.  */
 const pseudo_typeS md_pseudo_table[] =
@@ -92,7 +92,7 @@ void
 md_begin ()
 {
   /* Initialize the `cgen' interface.  */
-  
+
   /* Set the machine number and endian.  */
   gas_cgen_cpu_desc = xstormy16_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
                                          CGEN_CPU_OPEN_ENDIAN,
@@ -104,6 +104,8 @@ md_begin ()
   cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);
 }
 
+static bfd_boolean skipping_fptr = FALSE;
+
 void
 md_assemble (str)
      char * str;
@@ -111,12 +113,16 @@ md_assemble (str)
   xstormy16_insn insn;
   char *    errmsg;
 
+  /* Make sure that if we had an erroneous input line which triggered
+     the skipping_fptr boolean that it does not affect following lines.  */
+  skipping_fptr = FALSE;
+
   /* Initialize GAS's cgen interface for a new instruction.  */
   gas_cgen_init_parse ();
 
   insn.insn = xstormy16_cgen_assemble_insn
     (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg);
-  
+
   if (!insn.insn)
     {
       as_bad (errmsg);
@@ -128,14 +134,14 @@ md_assemble (str)
                        CGEN_FIELDS_BITSIZE (& insn.fields), 0, NULL);
 }
 
-void 
+void
 md_operand (e)
      expressionS * e;
 {
   if (*input_line_pointer != '@')
     return;
 
-  if (strncmp (input_line_pointer+1, "fptr", 4) == 0)
+  if (strncmp (input_line_pointer + 1, "fptr", 4) == 0)
     {
       input_line_pointer += 5;
       SKIP_WHITESPACE ();
@@ -154,9 +160,28 @@ md_operand (e)
          goto err;
        }
       input_line_pointer++;
+      SKIP_WHITESPACE ();
 
       if (e->X_op != O_symbol)
        as_bad ("Not a symbolic expression");
+      else if (* input_line_pointer == '-')
+       /* We are computing the difference of two function pointers
+          like this:
+
+           .hword  @fptr (foo) - @fptr (bar)
+
+         In this situation we do not want to generate O_fptr_symbol
+         operands because the result is an absolute value, not a
+         function pointer.
+
+         We need to make the check here, rather than when the fixup
+         is generated as the function names (foo & bar in the above
+         example) might be local symbols and we want the expression
+         to be evaluated now.  This kind of thing can happen when
+         gcc is generating computed gotos.  */
+       skipping_fptr = TRUE;
+      else if (skipping_fptr)
+       skipping_fptr = FALSE;
       else
         e->X_op = O_fptr_symbol;
     }
@@ -204,7 +229,7 @@ xstormy16_cons_fix_new (f, where, nbytes, exp)
   fix = fix_new_exp (f, where, nbytes, exp, 0, code);
 }
 
-/* Called while parsing an instruction to create a fixup. 
+/* Called while parsing an instruction to create a fixup.
    Create BFD_RELOC_XSTORMY16_FPTR16 relocations.  */
 
 fixS *
@@ -219,7 +244,7 @@ xstormy16_cgen_record_fixup_exp (frag, where, insn, length, operand, opinfo, exp
 {
   fixS *fixP;
   operatorT op = exp->X_op;
-  
+
   if (op == O_fptr_symbol)
     exp->X_op = O_symbol;
 
@@ -274,7 +299,7 @@ md_estimate_size_before_relax (fragP, segment)
 {
   /* No assembler relaxation is defined (or necessary) for this port.  */
   abort ();
-} 
+}
 
 /* *fragP has been relaxed to its final size, and now needs to have
    the bytes inside it modified to conform to the new size.
@@ -305,12 +330,13 @@ md_pcrel_from_section (fixP, sec)
 {
   if (fixP->fx_addsy != (symbolS *) NULL
       && (! S_IS_DEFINED (fixP->fx_addsy)
-         || S_GET_SEGMENT (fixP->fx_addsy) != sec))
-    {
-      /* The symbol is undefined (or is defined but not in this section).
-        Let the linker figure it out.  */
-      return 0;
-    }
+         || S_GET_SEGMENT (fixP->fx_addsy) != sec)
+          || xstormy16_force_relocation (fixP))
+    /* The symbol is undefined,
+       or it is defined but not in this section,
+       or the relocation will be relative to this symbol not the section symbol.        
+       Let the linker figure it out.  */
+    return 0;
 
   return fixP->fx_frag->fr_address + fixP->fx_where;
 }
@@ -331,30 +357,39 @@ md_cgen_lookup_reloc (insn, operand, fixP)
     case XSTORMY16_OPERAND_IMM3:
     case XSTORMY16_OPERAND_IMM3B:
     case XSTORMY16_OPERAND_IMM4:
-    case XSTORMY16_OPERAND_IMM12:
     case XSTORMY16_OPERAND_HMEM8:
       return BFD_RELOC_NONE;
-      
+
+    case XSTORMY16_OPERAND_IMM12:
+      fixP->fx_where += 2;
+      return BFD_RELOC_XSTORMY16_12;
+
     case XSTORMY16_OPERAND_IMM8:
     case XSTORMY16_OPERAND_LMEM8:
       return fixP->fx_pcrel ? BFD_RELOC_8_PCREL : BFD_RELOC_8;
-      
+
     case XSTORMY16_OPERAND_IMM16:
+      /* This might have been processed at parse time.  */
       fixP->fx_where += 2;
+      if (fixP->fx_cgen.opinfo && fixP->fx_cgen.opinfo != BFD_RELOC_NONE)
+       return fixP->fx_cgen.opinfo;
       return fixP->fx_pcrel ? BFD_RELOC_16_PCREL : BFD_RELOC_16;
 
     case XSTORMY16_OPERAND_ABS24:
       return BFD_RELOC_XSTORMY16_24;
 
-    case XSTORMY16_OPERAND_REL8_2:
     case XSTORMY16_OPERAND_REL8_4:
+      fixP->fx_addnumber -= 2;
+    case XSTORMY16_OPERAND_REL8_2:
+      fixP->fx_addnumber -= 2;
       fixP->fx_pcrel = 1;
       return BFD_RELOC_8_PCREL;
 
     case XSTORMY16_OPERAND_REL12:
       fixP->fx_where += 2;
-      /* Fall through... */
+      /* Fall through...  */
     case XSTORMY16_OPERAND_REL12A:
+      fixP->fx_addnumber -= 2;
       fixP->fx_pcrel = 1;
       return BFD_RELOC_XSTORMY16_REL_12;
 
@@ -371,41 +406,28 @@ int
 xstormy16_force_relocation (fix)
      fixS * fix;
 {
-  switch (fix->fx_r_type)
-    {
-    case BFD_RELOC_XSTORMY16_FPTR16:
-    case BFD_RELOC_VTABLE_INHERIT:
-    case BFD_RELOC_VTABLE_ENTRY:
-      return 1;
+  if (fix->fx_r_type == BFD_RELOC_XSTORMY16_FPTR16)
+    return 1;
 
-    default:
-      return 0;
-    }
+  return generic_force_reloc (fix);
 }
 
 /* Return true if a relocation against a symbol may be replaced with
    a relocation against section+offset.  */
 
-boolean
+bfd_boolean
 xstormy16_fix_adjustable (fixP)
    fixS * fixP;
 {
-  if (fixP->fx_addsy == NULL)
-    return 1;
-  
-  /* Prevent all adjustments to global symbols. */
-  if (S_IS_EXTERN (fixP->fx_addsy))
-    return 0;
-  
-  if (S_IS_WEAK (fixP->fx_addsy))
-    return 0;
-  
   /* We need the symbol name for the VTABLE entries.  */
-  if (   fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
+  if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
     return 0;
 
-  return ! xstormy16_force_relocation (fixP);
+  if (fixP->fx_r_type == BFD_RELOC_XSTORMY16_FPTR16)
+    return 0;
+
+  return 1;
 }
 
 /* This is a copy of gas_cgen_md_apply_fix3, with some enhancements to
@@ -418,10 +440,16 @@ xstormy16_md_apply_fix3 (fixP, valueP, seg)
      segT     seg ATTRIBUTE_UNUSED;
 {
   char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
-  valueT value;
+  valueT value = *valueP;
   /* Canonical name, since used a lot.  */
   CGEN_CPU_DESC cd = gas_cgen_cpu_desc;
 
+  /* md_cgen_lookup_reloc() will adjust this to compensate for where
+     in the opcode the relocation happens, for pcrel relocations.  We
+     have no other way of keeping track of what this offset needs to
+     be.  */
+  fixP->fx_addnumber = 0;
+
   /* This port has pc-relative relocs and DIFF_EXPR_OK defined, so
      it must deal with turning a BFD_RELOC_{8,16,32,64} into a
      BFD_RELOC_*_PCREL for the case of
@@ -446,40 +474,13 @@ xstormy16_md_apply_fix3 (fixP, valueP, seg)
       default:
        break;
       }
-  
-  /* FIXME FIXME FIXME: The value we are passed in *valuep includes
-     the symbol values.  Since we are using BFD_ASSEMBLER, if we are
-     doing this relocation the code in write.c is going to call
-     bfd_install_relocation, which is also going to use the symbol
-     value.  That means that if the reloc is fully resolved we want to
-     use *valuep since bfd_install_relocation is not being used.
-     However, if the reloc is not fully resolved we do not want to use
-     *valuep, and must use fx_offset instead.  However, if the reloc
-     is PC relative, we do want to use *valuep since it includes the
-     result of md_pcrel_from.  This is confusing.  */
 
   if (fixP->fx_addsy == (symbolS *) NULL)
-    {
-      value = *valueP;
-      fixP->fx_done = 1;
-    }
-  else if (fixP->fx_pcrel)
-    value = *valueP;
-  else
-    {
-      value = fixP->fx_offset;
-      if (fixP->fx_subsy != (symbolS *) NULL)
-       {
-         if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section)
-           value -= S_GET_VALUE (fixP->fx_subsy);
-         else
-           {
-             /* We don't actually support subtracting a symbol.  */
-             as_bad_where (fixP->fx_file, fixP->fx_line,
-                           _("expression too complex"));
-           }
-       }
-    }
+    fixP->fx_done = 1;
+
+  /* We don't actually support subtracting a symbol.  */
+  if (fixP->fx_subsy != (symbolS *) NULL)
+    as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
 
   if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
     {
@@ -523,7 +524,7 @@ xstormy16_md_apply_fix3 (fixP, valueP, seg)
       /* The operand isn't fully resolved.  Determine a BFD reloc value
         based on the operand information and leave it to
         bfd_install_relocation.  Note that this doesn't work when
-        partial_inplace == false.  */
+        !partial_inplace.  */
 
       reloc_type = md_cgen_lookup_reloc (insn, operand, fixP);
       if (reloc_type != BFD_RELOC_NONE)
@@ -571,9 +572,9 @@ xstormy16_md_apply_fix3 (fixP, valueP, seg)
   /* This is a RELA port.  Thus, it does not need to store a
      value if it is going to make a reloc.  What's more, when
      assembling a line like
-     
+
      .byte global-0x7f00
-     
+
      we'll get a spurious error message if we try to stuff 0x7f00 into
      the byte.  */
   if (! fixP->fx_done)
@@ -582,7 +583,7 @@ xstormy16_md_apply_fix3 (fixP, valueP, seg)
   /* Tuck `value' away for use by tc_gen_reloc.
      See the comment describing fx_addnumber in write.h.
      This field is misnamed (or misused :-).  */
-  fixP->fx_addnumber = value;
+  fixP->fx_addnumber += value;
 }
 
 \f
@@ -648,6 +649,6 @@ md_atof (type, litP, sizeP)
       md_number_to_chars (litP, (valueT) (*wordP--), sizeof (LITTLENUM_TYPE));
       litP += sizeof (LITTLENUM_TYPE);
     }
-     
+
   return 0;
 }
This page took 0.026425 seconds and 4 git commands to generate.