Locale changes from Bruno Haible <haible@clisp.cons.org>.
[deliverable/binutils-gdb.git] / gas / config / tc-i960.c
index 936b6621994c50104bb3f23df9d0edd49c980a01..279c2143c024d1053265fb7609c18d74f0af44c5 100644 (file)
@@ -1,5 +1,6 @@
 /* tc-i960.c - All the i80960-specific stuff
-   Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000, 2001
    Free Software Foundation, Inc.
 
    This file is part of GAS.
@@ -19,7 +20,7 @@
    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    02111-1307, USA.  */
 
-/* See comment on md_parse_option for 80960-specific invocation options. */
+/* See comment on md_parse_option for 80960-specific invocation options.  */
 
 /* There are 4 different lengths of (potentially) symbol-based displacements
    in the 80960 instruction set, each of which could require address fix-ups
         a relocation directive.  */
 
 #include <stdio.h>
-#include <ctype.h>
 
 #include "as.h"
 
+#include "safe-ctype.h"
 #include "obstack.h"
 
 #include "opcode/i960.h"
 #define TC_S_FORCE_TO_SYSPROC(s)       (S_SET_STORAGE_CLASS((s), C_SCALL))
 
 #else /* ! OBJ_COFF */
-you lose;
+#ifdef OBJ_ELF
+#define TC_S_IS_SYSPROC(s)     0
+
+#define TC_S_IS_BALNAME(s)     0
+#define TC_S_IS_CALLNAME(s)    0
+#define TC_S_IS_BADPROC(s)     0
+
+#define TC_S_SET_SYSPROC(s, p)
+#define TC_S_GET_SYSPROC(s) 0
+
+#define TC_S_FORCE_TO_BALNAME(s)
+#define TC_S_FORCE_TO_CALLNAME(s)
+#define TC_S_FORCE_TO_SYSPROC(s)
+#else
+ #error COFF, a.out, b.out, and ELF are the only supported formats.
+#endif /* ! OBJ_ELF */
 #endif /* ! OBJ_COFF */
 #endif /* ! OBJ_A/BOUT */
 
@@ -163,11 +179,11 @@ const char comment_chars[] = "#";
    #NO_APP at the beginning of its output.
  */
 
-/* Also note that comments started like this one will always work. */
+/* Also note that comments started like this one will always work.  */
 
-const char line_comment_chars[1];
+const char line_comment_chars[] = "";
 
-const char line_separator_chars[1];
+const char line_separator_chars[] = ";";
 
 /* Chars that can be used to separate mant from exp in floating point nums */
 const char EXP_CHARS[] = "eE";
@@ -177,7 +193,6 @@ const char EXP_CHARS[] = "eE";
  */
 const char FLT_CHARS[] = "fFdDtT";
 
-
 /* Table used by base assembler to relax addresses based on varying length
    instructions.  The fields are:
      1) most positive reach of this state,
@@ -227,13 +242,11 @@ const pseudo_typeS md_pseudo_table[] =
 #define adds(e)        e.X_add_symbol
 #define offs(e)        e.X_add_number
 
-
 /* Branch-prediction bits for CTRL/COBR format opcodes */
 #define BP_MASK                0x00000002      /* Mask for branch-prediction bit */
 #define BP_TAKEN       0x00000000      /* Value to OR in to predict branch */
 #define BP_NOT_TAKEN   0x00000002      /* Value to OR in to predict no branch */
 
-
 /* Some instruction opcodes that we need explicitly */
 #define BE     0x12000000
 #define BG     0x11000000
@@ -253,14 +266,12 @@ const pseudo_typeS md_pseudo_table[] =
 #define CALLS  0x66003800
 #define RET    0x0a000000
 
-
-/* These masks are used to build up a set of MEMB mode bits. */
+/* These masks are used to build up a set of MEMB mode bits.  */
 #define        A_BIT           0x0400
 #define        I_BIT           0x0800
 #define MEMB_BIT       0x1000
 #define        D_BIT           0x2000
 
-
 /* Mask for the only mode bit in a MEMA instruction (if set, abase reg is
    used).  */
 #define MEMA_ABASE     0x2000
@@ -279,7 +290,6 @@ typedef struct
 
 memS;
 
-
 /* The two pieces of info we need to generate a register operand */
 struct regop
   {
@@ -288,7 +298,6 @@ struct regop
     int n;                     /* Register number or literal value */
   };
 
-
 /* Number and assembler mnemonic for all registers that can appear in
    operands.  */
 static const struct
@@ -434,13 +443,11 @@ aregs[] =
   { NULL, 0 },                         /* END OF LIST */
 };
 
-
 /* Hash tables */
 static struct hash_control *op_hash;   /* Opcode mnemonics */
 static struct hash_control *reg_hash;  /* Register name hash table */
 static struct hash_control *areg_hash; /* Abase register hash table */
 
-
 /* Architecture for which we are assembling */
 #define ARCH_ANY       0       /* Default: no architecture checking done */
 #define ARCH_KA                1
@@ -455,7 +462,6 @@ int iclasses_seen;          /* OR of instruction classes (I_* constants)
                                 *      instructions.
                                 */
 
-
 /* BRANCH-PREDICTION INSTRUMENTATION
 
         The following supports generation of branch-prediction instrumentation
@@ -577,7 +583,6 @@ md_assemble (textP)
 
   const char *bp_error_msg = _("branch prediction invalid on this opcode");
 
-
   /* Parse instruction into opcode and operands */
   memset (args, '\0', sizeof (args));
   n_ops = i_scan (textP, args);
@@ -596,8 +601,6 @@ md_assemble (textP)
        }
     }
 
-
-
   /* Check for branch-prediction suffix on opcode mnemonic, strip it off */
   n = strlen (args[0]) - 1;
   branch_predict = 0;
@@ -720,9 +723,8 @@ md_chars_to_number (val, n)
   return retval;
 }
 
-
 #define MAX_LITTLENUMS 6
-#define LNUM_SIZE      sizeof(LITTLENUM_TYPE)
+#define LNUM_SIZE      sizeof (LITTLENUM_TYPE)
 
 /*****************************************************************************
    md_atof:    convert ascii to floating point
@@ -793,7 +795,6 @@ md_atof (type, litP, sizeP)
   return 0;
 }
 
-
 /*****************************************************************************
    md_number_to_imm
 
@@ -807,7 +808,6 @@ md_number_to_imm (buf, val, n)
   md_number_to_chars (buf, val, n);
 }
 
-
 /*****************************************************************************
    md_number_to_disp
 
@@ -903,7 +903,6 @@ md_number_to_field (instrP, val, bfixP)
 
                A table of all such "Labels" is also generated.
 
-
        -AKA, -AKB, -AKC, -ASA, -ASB, -AMC, -ACA:
                Select the 80960 architecture.  Instructions or features not
                supported by the selected architecture cause fatal errors.
@@ -1009,7 +1008,6 @@ md_show_usage (stream)
 }
 \f
 
-#ifndef BFD_ASSEMBLER
 /*****************************************************************************
    md_convert_frag:
        Called by base assembler after address relaxation is finished:  modify
@@ -1023,11 +1021,19 @@ md_show_usage (stream)
        Replace the cobr with a two instructions (a compare and a branch).
 
   *************************************************************************** */
+#ifndef BFD_ASSEMBLER
 void
 md_convert_frag (headers, seg, fragP)
      object_headers *headers;
      segT seg;
      fragS *fragP;
+#else
+void
+md_convert_frag (abfd, sec, fragP)
+     bfd *abfd;
+     segT sec;
+     fragS *fragP;
+#endif
 {
   fixS *fixP;                  /* Structure describing needed address fix */
 
@@ -1082,6 +1088,7 @@ md_estimate_size_before_relax (fragP, segment_type)
   return 0;
 }                              /* md_estimate_size_before_relax() */
 
+#if defined(OBJ_AOUT) | defined(OBJ_BOUT)
 
 /*****************************************************************************
    md_ri_to_chars:
@@ -1096,7 +1103,8 @@ md_estimate_size_before_relax (fragP, segment_type)
        does do the reordering (Ian Taylor 28 Aug 92).
 
   *************************************************************************** */
-void
+
+static void
 md_ri_to_chars (where, ri)
      char *where;
      struct relocation_info *ri;
@@ -1114,7 +1122,8 @@ md_ri_to_chars (where, ri)
              | (ri->r_callj << 6));
 }
 
-#endif /* BFD_ASSEMBLER */
+#endif /* defined(OBJ_AOUT) | defined(OBJ_BOUT) */
+
 \f
 /* FOLLOWING ARE THE LOCAL ROUTINES, IN ALPHABETICAL ORDER  */
 
@@ -1239,7 +1248,6 @@ cobr_fmt (arg, opcode, oP)
       instr |= (regop.n << 14) | regop.special;
     }
 
-
   if (n < 3)
     {
       emit (instr);
@@ -1268,7 +1276,6 @@ cobr_fmt (arg, opcode, oP)
     }
 }                              /* cobr_fmt() */
 
-
 /*****************************************************************************
    ctrl_fmt:   generate a CTRL-format instruction
 
@@ -1284,7 +1291,6 @@ ctrl_fmt (targP, opcode, num_ops)
                                   * how often the branch is taken
                                 */
 
-
   if (num_ops == 0)
     {
       emit (opcode);           /* Output opcode */
@@ -1314,7 +1320,6 @@ ctrl_fmt (targP, opcode, num_ops)
 
 }
 
-
 /*****************************************************************************
    emit:       output instruction binary
 
@@ -1334,7 +1339,6 @@ emit (instr)
   return toP;
 }
 
-
 /*****************************************************************************
    get_args:   break individual arguments out of comma-separated list
 
@@ -1385,8 +1389,8 @@ get_args (p, args)
     {
 
       if (*p == ' '
-         && (! isalnum ((unsigned char) p[1])
-             || ! isalnum ((unsigned char) p[-1])))
+         && (! ISALNUM (p[1])
+             || ! ISALNUM (p[-1])))
        {
          p++;
 
@@ -1414,7 +1418,6 @@ get_args (p, args)
   return n;
 }
 
-
 /*****************************************************************************
    get_cdisp:  handle displacement for a COBR or CTRL instruction.
 
@@ -1504,7 +1507,6 @@ get_cdisp (dispP, ifmtP, instr, numbits, var_frag, callj)
     }
 }
 
-
 /*****************************************************************************
    get_ispec:  parse a memory operand for an index specification
 
@@ -1575,7 +1577,6 @@ get_regnum (regname)
   return (rP == NULL) ? -1 : *rP;
 }
 
-
 /*****************************************************************************
    i_scan:     perform lexical scan of ascii assembler instruction.
 
@@ -1596,7 +1597,7 @@ get_regnum (regname)
   *************************************************************************** */
 static int
 i_scan (iP, args)
-     /* Pointer to ascii instruction;  MUCKED BY US. */
+     /* Pointer to ascii instruction;  MUCKED BY US.  */
      register char *iP;
      /* Output arg: pointers to opcode and operands placed here.  MUST
        ACCOMMODATE 4 ENTRIES.  */
@@ -1627,7 +1628,6 @@ i_scan (iP, args)
   return (get_args (iP, args));
 }                              /* i_scan() */
 
-
 /*****************************************************************************
    mem_fmt:    generate a MEMA- or MEMB-format instruction
 
@@ -1655,7 +1655,7 @@ mem_fmt (args, oP, callx)
   memset (&instr, '\0', sizeof (memS));
   instr.opcode = oP->opcode;
 
-  /* Process operands. */
+  /* Process operands.  */
   for (i = 1; i <= oP->num_ops; i++)
     {
       opdesc = oP->operand[i - 1];
@@ -1746,7 +1746,6 @@ mem_fmt (args, oP, callx)
     }
 }                              /* memfmt() */
 
-
 /*****************************************************************************
    mema_to_memb:       convert a MEMA-format opcode to a MEMB-format opcode.
 
@@ -1779,7 +1778,6 @@ mema_to_memb (opcodeP)
   md_number_to_chars (opcodeP, opcode, 4);
 }                              /* mema_to_memb() */
 
-
 /*****************************************************************************
    parse_expr:         parse an expression
 
@@ -1833,7 +1831,6 @@ parse_expr (textP, expP)
     }
 }
 
-
 /*****************************************************************************
    parse_ldcont:
        Parse and replace a 'ldconst' pseudo-instruction with an appropriate
@@ -1860,7 +1857,6 @@ parse_ldconst (arg)
   static char buf2[5];         /* Literal for second operand */
   expressionS e;               /* Parsed expression */
 
-
   arg[3] = NULL;               /* So we can tell at the end if it got used or not */
 
   parse_expr (arg[1], &e);
@@ -1995,7 +1991,6 @@ parse_memop (memP, argP, optype)
     16                         /* MEM16 */
   };
 
-
   iprel_flag = mode = 0;
 
   /* Any index present? */
@@ -2183,7 +2178,7 @@ parse_po (po_num)
 
   extern char is_end_of_line[];
 
-  /* Advance input pointer to end of line. */
+  /* Advance input pointer to end of line.  */
   p = input_line_pointer;
   while (!is_end_of_line[(unsigned char) *input_line_pointer])
     {
@@ -2333,7 +2328,6 @@ reg_fmt (args, oP)
   struct regop regop;          /* Description of register operand */
   int n_ops;                   /* Number of operands */
 
-
   instr = oP->opcode;
   n_ops = oP->num_ops;
 
@@ -2400,7 +2394,6 @@ reg_fmt (args, oP)
   emit (instr);
 }
 
-
 /*****************************************************************************
    relax_cobr:
        Replace cobr instruction in a code fragment with equivalent branch and
@@ -2487,7 +2480,6 @@ relax_cobr (fragP)
   frag_wane (fragP);
 }
 
-
 /*****************************************************************************
    reloc_callj:        Relocate a 'callj' instruction
 
@@ -2555,7 +2547,6 @@ reloc_callj (fixP)
   /* else Symbol is neither a sysproc nor a leafproc */
 }
 
-
 /*****************************************************************************
    s_leafproc: process .leafproc pseudo-op
 
@@ -2585,7 +2576,7 @@ s_leafproc (n_ops, args)
       return;
     }                          /* Check number of arguments */
 
-  /* Find or create symbol for 'call' entry point. */
+  /* Find or create symbol for 'call' entry point.  */
   callP = symbol_find_or_make (args[1]);
 
   if (TC_S_IS_CALLNAME (callP))
@@ -2613,11 +2604,12 @@ s_leafproc (n_ops, args)
        }
       TC_S_FORCE_TO_BALNAME (balP);
 
+#ifndef OBJ_ELF
       tc_set_bal_of_call (callP, balP);
+#endif
     }                          /* if only one arg, or the args are the same */
 }
 
-
 /*
    s_sysproc: process .sysproc pseudo-op
 
@@ -2643,7 +2635,7 @@ s_sysproc (n_ops, args)
       return;
     }                          /* bad arg count */
 
-  /* Parse "entry_num" argument and check it for validity. */
+  /* Parse "entry_num" argument and check it for validity.  */
   parse_expr (args[2], &exp);
   if (exp.X_op != O_constant
       || (offs (exp) < 0)
@@ -2665,7 +2657,6 @@ s_sysproc (n_ops, args)
   TC_S_FORCE_TO_SYSPROC (symP);
 }
 
-
 /*****************************************************************************
    shift_ok:
        Determine if a "shlo" instruction can be used to implement a "ldconst".
@@ -2702,7 +2693,6 @@ shift_ok (n)
   return shift;
 }
 
-
 /* syntax: issue syntax error */
 
 static void
@@ -2711,7 +2701,6 @@ syntax ()
   as_bad (_("syntax error"));
 }                              /* syntax() */
 
-
 /* targ_has_sfr:
 
    Return TRUE iff the target architecture supports the specified
@@ -2737,7 +2726,6 @@ targ_has_sfr (n)
     }
 }
 
-
 /* targ_has_iclass:
 
    Return TRUE iff the target architecture supports the indicated
@@ -2799,9 +2787,8 @@ s_endian (ignore)
   demand_empty_rest_of_line ();
 }
 
-/* We have no need to default values of symbols. */
+/* We have no need to default values of symbols.  */
 
-/* ARGSUSED */
 symbolS *
 md_undefined_symbol (name)
      char *name;
@@ -2811,7 +2798,7 @@ md_undefined_symbol (name)
 
 /* Exactly what point is a PC-relative offset relative TO?
    On the i960, they're relative to the address of the instruction,
-   which we have set up as the address of the fixup too. */
+   which we have set up as the address of the fixup too.  */
 long
 md_pcrel_from (fixP)
      fixS *fixP;
@@ -2819,25 +2806,42 @@ md_pcrel_from (fixP)
   return fixP->fx_where + fixP->fx_frag->fr_address;
 }
 
+#ifdef BFD_ASSEMBLER
+int
+md_apply_fix (fixP, valp)
+     fixS *fixP;
+     valueT *valp;
+#else
 void
 md_apply_fix (fixP, val)
      fixS *fixP;
      long val;
+#endif
 {
+#ifdef BFD_ASSEMBLER
+  long val = *valp;
+#endif
   char *place = fixP->fx_where + fixP->fx_frag->fr_literal;
 
   if (!fixP->fx_bit_fixP)
     {
+#ifndef BFD_ASSEMBLER
       /* For callx, we always want to write out zero, and emit a
         symbolic relocation.  */
       if (fixP->fx_bsr)
        val = 0;
 
       fixP->fx_addnumber = val;
+#endif
+
       md_number_to_imm (place, val, fixP->fx_size, fixP);
     }
   else
     md_number_to_field (place, val, fixP->fx_bit_fixP);
+
+#ifdef BFD_ASSEMBLER
+  return 0;
+#endif
 }
 
 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
@@ -2896,7 +2900,7 @@ tc_bout_fix_to_chars (where, fixP, segment_address_in_file)
       ri.r_index = S_GET_TYPE (symbolP);
     }
 
-  /* Output the relocation information in machine-dependent form. */
+  /* Output the relocation information in machine-dependent form.  */
   md_ri_to_chars (where, &ri);
 }
 
@@ -2937,8 +2941,14 @@ md_section_align (seg, addr)
      segT seg;
      valueT addr;              /* Address to be rounded up */
 {
-  return ((addr + (1 << section_alignment[(int) seg]) - 1) & (-1 << section_alignment[(int) seg]));
-}                              /* md_section_align() */
+  int align;
+#ifdef BFD_ASSEMBLER
+  align = bfd_get_section_alignment (stdoutput, seg);
+#else
+  align = section_alignment[(int) seg];
+#endif
+  return (addr + (1 << align) - 1) & (-1 << align);
+}
 
 extern int coff_flags;
 
@@ -3007,6 +3017,8 @@ tc_headers_hook (headers)
 
 #endif /* OBJ_COFF */
 
+#ifndef BFD_ASSEMBLER
+
 /* Things going on here:
 
    For bout, We need to assure a couple of simplifying
@@ -3066,6 +3078,8 @@ tc_crawl_symbol_chain (headers)
     }                          /* walk the symbol chain */
 }
 
+#endif /* ! BFD_ASSEMBLER */
+
 /* For aout or bout, the bal immediately follows the call.
 
    For coff, we cheat and store a pointer to the bal symbol in the
@@ -3105,7 +3119,7 @@ tc_set_bal_of_call (callP, balP)
     }                          /* if not in order */
 
 #else /* ! OBJ_ABOUT */
-  (as yet unwritten.);
+  as_fatal ("Only supported for a.out, b.out, or COFF");
 #endif /* ! OBJ_ABOUT */
 #endif /* ! OBJ_COFF */
 }
@@ -3124,7 +3138,7 @@ tc_get_bal_of_call (callP)
 #ifdef OBJ_ABOUT
   retval = symbol_next (callP);
 #else
-  (as yet unwritten.);
+  as_fatal ("Only supported for a.out, b.out, or COFF");
 #endif /* ! OBJ_ABOUT */
 #endif /* ! OBJ_COFF */
 
@@ -3194,7 +3208,7 @@ i960_validate_fix (fixP, this_segment_type, add_symbolPP)
   if (fixP->fx_tcbit && TC_S_IS_CALLNAME (add_symbolP))
     {
       /* Relocation should be done via the associated 'bal'
-         entry point symbol. */
+         entry point symbol.  */
 
       if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP)))
        {
@@ -3219,7 +3233,7 @@ i960_validate_fix (fixP, this_segment_type, add_symbolPP)
           displacement and are only to be used for local branches:
           flag as error, don't generate relocation.  */
        as_bad (_("can't use COBR format with external label"));
-       fixP->fx_addsy = NULL;  /* No relocations please. */
+       fixP->fx_addsy = NULL;  /* No relocations please.  */
        return 1;
       }
   }
@@ -3228,4 +3242,68 @@ i960_validate_fix (fixP, this_segment_type, add_symbolPP)
   return 0;
 }
 
+#ifdef BFD_ASSEMBLER
+
+/* From cgen.c:  */
+
+static short
+tc_bfd_fix2rtype (fixP)
+     fixS *fixP;
+{
+#if 0
+  if (fixP->fx_bsr)
+    abort ();
+#endif
+
+  if (fixP->fx_pcrel == 0 && fixP->fx_size == 4)
+    return BFD_RELOC_32;
+
+  if (fixP->fx_pcrel != 0 && fixP->fx_size == 4)
+    return BFD_RELOC_24_PCREL;
+
+  abort ();
+  return 0;
+}
+
+/* Translate internal representation of relocation info to BFD target
+   format.
+
+   FIXME: To what extent can we get all relevant targets to use this?  */
+
+arelent *
+tc_gen_reloc (section, fixP)
+     asection *section;
+     fixS *fixP;
+{
+  arelent * reloc;
+
+  reloc = (arelent *) xmalloc (sizeof (arelent));
+
+  /* HACK: Is this right? */
+  fixP->fx_r_type = tc_bfd_fix2rtype (fixP);
+
+  reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
+  if (reloc->howto == (reloc_howto_type *) NULL)
+    {
+      as_bad_where (fixP->fx_file, fixP->fx_line,
+                   "internal error: can't export reloc type %d (`%s')",
+                   fixP->fx_r_type,
+                   bfd_get_reloc_code_name (fixP->fx_r_type));
+      return NULL;
+    }
+
+  assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
+
+  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
+  reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
+  reloc->addend = fixP->fx_addnumber;
+
+  return reloc;
+}
+
+/* end from cgen.c */
+
+#endif /* BFD_ASSEMBLER */
+
 /* end of tc-i960.c */
This page took 0.064195 seconds and 4 git commands to generate.