Convert unmaintained files over to ISO-C90 and fix formatting.
[platform/upstream/binutils.git] / gas / config / tc-or32.c
index 44cbfc8..6943731 100644 (file)
@@ -1,5 +1,5 @@
 /* Assembly backend for the OpenRISC 1000.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
    Contributed by Damjan Lampret <lampret@opencores.org>.
    Modified bu Johan Rydberg, <johan.rydberg@netinsight.se>.
    Based upon a29k port.
 static struct hash_control *op_hash = NULL;
 
 struct machine_it
-  {
-    char *          error;
-    unsigned long   opcode;
-    struct nlist *  nlistp;
-    expressionS     exp;
-    int             pcrel;
-    int             reloc_offset;   /* Offset of reloc within insn.  */
-    int             reloc;
-  }
+{
+  char *          error;
+  unsigned long   opcode;
+  struct nlist *  nlistp;
+  expressionS     exp;
+  int             pcrel;
+  int             reloc_offset;   /* Offset of reloc within insn.  */
+  int             reloc;
+}
 the_insn;
 
-static void machine_ip PARAMS ((char *));
-
 const pseudo_typeS md_pseudo_table[] =
-  {
-    {"align",   s_align_bytes,  4 },
-    {"space",   s_space,        0 },
-    {"cputype", s_ignore,       0 },
-    {"reg",     s_lsym,         0 },  /* Register equate, same as equ.  */
-    {"sect",    s_ignore,       0 },  /* Creation of coff sections.  */
-    {"proc",    s_ignore,       0 },  /* Start of a function.  */
-    {"endproc", s_ignore,       0 },  /* Function end.  */
-    {"word",    cons,           4 },
-    {NULL,      0,              0 },
-  };
+{
+  {"align",   s_align_bytes,  4 },
+  {"space",   s_space,        0 },
+  {"cputype", s_ignore,       0 },
+  {"reg",     s_lsym,         0 },  /* Register equate, same as equ.  */
+  {"sect",    s_ignore,       0 },  /* Creation of coff sections.  */
+  {"proc",    s_ignore,       0 },  /* Start of a function.  */
+  {"endproc", s_ignore,       0 },  /* Function end.  */
+  {"word",    cons,           4 },
+  {NULL,      0,              0 },
+};
 
 int md_short_jump_size  = 4;
 int md_long_jump_size   = 4;
@@ -114,22 +112,17 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP";
 /* "l.jalr r9" precalculated opcode.  */
 static unsigned long jalr_r9_opcode;
 
+static void machine_ip (char *);
 
-static int check_invalid_opcode PARAMS ((unsigned long));
-static void encode PARAMS ((const struct machine_opcode *, unsigned long *, signed long, char));
-#ifdef BFD_ASSEMBLER
-static char * parse_operand PARAMS ((char *, expressionS *, int));
-#endif
 
 /* Set bits in machine opcode according to insn->encoding
    description and passed operand.  */
 
 static void
-encode (insn, opcode, param_val, param_ch)
-     const struct machine_opcode *insn;
-     unsigned long *opcode;
-     signed long param_val;
-     char param_ch;
+encode (const struct machine_opcode *insn,
+       unsigned long *opcode,
+       signed long param_val,
+       char param_ch)
 {
   int opc_pos = 0;
   int param_pos = 0;
@@ -197,7 +190,7 @@ encode (insn, opcode, param_val, param_ch)
    need.  */
 
 void
-md_begin ()
+md_begin (void)
 {
   const char *retval = NULL;
   int lose = 0;
@@ -217,7 +210,7 @@ md_begin ()
           continue;
         }
 
-      retval = hash_insert (op_hash, name, (PTR) &machine_opcodes[i]);
+      retval = hash_insert (op_hash, name, (void *) &machine_opcodes[i]);
       if (retval != NULL)
         {
           fprintf (stderr, "internal error: can't hash `%s': %s\n",
@@ -232,11 +225,10 @@ md_begin ()
   encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B');
 }
 
-/* Returs non zero if instruction is to be used.  */
+/* Returns non zero if instruction is to be used.  */
 
 static int
-check_invalid_opcode (opcode)
-     unsigned long opcode;
+check_invalid_opcode (unsigned long opcode)
 {
   return opcode == jalr_r9_opcode;
 }
@@ -246,8 +238,7 @@ check_invalid_opcode (opcode)
    produce the bytes of data and relocation.  */
 
 void
-md_assemble (str)
-     char *str;
+md_assemble (char *str)
 {
   char *toP;
 
@@ -285,10 +276,7 @@ static int mask_or_shift = 0;
 
 #ifdef BFD_ASSEMBLER
 static char *
-parse_operand (s, operandp, opt)
-     char *s;
-     expressionS *operandp;
-     int opt;
+parse_operand (char *s, expressionS *operandp, int opt)
 {
   char *save = input_line_pointer;
   char *new;
@@ -352,11 +340,8 @@ parse_operand (s, operandp, opt)
 }
 #else
 
-char *
-parse_operand (s, operandp, opt)
-     char *s;
-     expressionS *operandp;
-     int opt;
+static char *
+parse_operand (char *s, expressionS *operandp, int opt)
 {
   char *save = input_line_pointer;
   char *new;
@@ -383,7 +368,6 @@ parse_operand (s, operandp, opt)
   else
     mask_or_shift = 0;
 
-
   expression (operandp);
 
   if (operandp->X_op == O_absent)
@@ -432,8 +416,7 @@ parse_operand (s, operandp, opt)
 
 #ifdef BFD_ASSEMBLER
 static void
-machine_ip (str)
-     char *str;
+machine_ip (char *str)
 {
   char *s;
   const char *args;
@@ -487,10 +470,8 @@ machine_ip (str)
      If an operand matches, we modify the_insn or opcode appropriately,
      and do a "continue".  If an operand fails to match, we "break".  */
   if (insn->args[0] != '\0')
-    {
-      /* Prime the pump.  */
-      s = parse_operand (s, operand, insn->args[0] == 'I');
-    }
+    /* Prime the pump.  */
+    s = parse_operand (s, operand, insn->args[0] == 'I');
 
   for (args = insn->args;; ++args)
     {
@@ -581,13 +562,7 @@ machine_ip (str)
             }
 
           if (*s == '(')
-            {
-              operand->X_op = O_constant;
-#if 0
-              operand->X_add_number = 0; /* ??? if enabled load/store offsets
-                                           are zero.  */
-#endif
-            }
+           operand->X_op = O_constant;
           else if (*s == ')')
             s += 1;
 #if DEBUG
@@ -647,8 +622,7 @@ machine_ip (str)
 #else
 
 static void
-machine_ip (str)
-     char *str;
+machine_ip (char *str)
 {
   char *s;
   const char *args;
@@ -796,13 +770,7 @@ machine_ip (str)
             }
 
           if (*s == '(')
-            {
-              operand->X_op = O_constant;
-#if 0
-              operand->X_add_number = 0; /* ??? if enabled load/store offsets
-                                           are zero.  */
-#endif
-            }
+           operand->X_op = O_constant;
           else if (*s == ')')
             s += 1;
 #if DEBUG
@@ -871,10 +839,7 @@ machine_ip (str)
 #define MAX_LITTLENUMS 6
 
 char *
-md_atof (type, litP, sizeP)
-     char   type;
-     char * litP;
-     int *  sizeP;
+md_atof (int type, char * litP, int *  sizeP)
 {
   int prec;
   LITTLENUM_TYPE words[MAX_LITTLENUMS];
@@ -930,20 +895,14 @@ md_atof (type, litP, sizeP)
 /* Write out big-endian.  */
 
 void
-md_number_to_chars (buf, val, n)
-     char *buf;
-     valueT val;
-     int n;
+md_number_to_chars (char *buf, valueT val, int n)
 {
   number_to_chars_bigendian (buf, val, n);
 }
 
 #ifdef BFD_ASSEMBLER
 void
-md_apply_fix3 (fixP, val, seg)
-     fixS *   fixP;
-     valueT * val;
-     segT     seg ATTRIBUTE_UNUSED;
+md_apply_fix3 (fixS * fixP, valueT * val, segT seg ATTRIBUTE_UNUSED)
 {
   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
   long t_val;
@@ -1004,20 +963,7 @@ md_apply_fix3 (fixP, val, seg)
 
     case BFD_RELOC_32_GOT_PCREL:  /* 0000XXXX pattern in a word.  */
       if (!fixP->fx_done)
-        {
-          /* The linker tries to support both AMD and old GNU style
-             R_IREL relocs.  That means that if the addend is exactly
-             the negative of the address within the section, the
-             linker will not handle it correctly.  */
-#if 0
-          if (fixP->fx_pcrel
-              && t_val != 0
-              && t_val == - (fixP->fx_frag->fr_address + fixP->fx_where))
-            as_bad_where
-              (fixP->fx_file, fixP->fx_line,
-               _("the linker will not handle this relocation correctly (1)"));
-#endif
-        }
+        ;
       else if (fixP->fx_pcrel)
         {
           long v = t_val >> 28;
@@ -1052,12 +998,9 @@ md_apply_fix3 (fixP, val, seg)
 }
 #else
 void
-md_apply_fix3 (fixP, valP, seg)
-     fixS *fixP;
-     valueT *valP;
-     segT seg ATTRIBUTE_UNUSED;
+md_apply_fix3 (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 {
-  long val = *(long*)valP;
+  long val = *valP;
   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
 
 #if DEBUG
@@ -1087,7 +1030,7 @@ md_apply_fix3 (fixP, valP, seg)
       break;
 
     case RELOC_WDISP30:
-      val = (val >>= 2) + 1;
+      val = (val >> 2) + 1;
       buf[0] |= (val >> 24) & 0x3f;
       buf[1] = (val >> 16);
       buf[2] = val >> 8;
@@ -1111,7 +1054,7 @@ md_apply_fix3 (fixP, valP, seg)
       break;
 
     case RELOC_WDISP22:
-      val = (val >>= 2) + 1;
+      val = (val >> 2) + 1;
       /* FALLTHROUGH */
     case RELOC_BASE22:
       buf[1] |= (val >> 16) & 0x3f;
@@ -1126,23 +1069,13 @@ md_apply_fix3 (fixP, valP, seg)
              R_IREL relocs.  That means that if the addend is exactly
              the negative of the address within the section, the
              linker will not handle it correctly.  */
-#if 0
-          if (fixP->fx_pcrel
-              && val != 0
-              && val == - (fixP->fx_frag->fr_address + fixP->fx_where))
-            as_bad_where
-              (fixP->fx_file, fixP->fx_line,
-               _("the linker will not handle this relocation correctly (1)"));
-#endif
         }
       else if (fixP->fx_pcrel)
         {
           long v = val >> 28;
-#if 1
           if (v != 0 && v != -1)
             as_bad_where (fixP->fx_file, fixP->fx_line,
                           _("call/jmp target out of range (2)"));
-#endif
         }
       else
         /* This case was supposed to be handled in machine_ip.  */
@@ -1188,8 +1121,7 @@ md_apply_fix3 (fixP, valP, seg)
 
 #ifdef OBJ_COFF
 short
-tc_coff_fix2rtype (fixP)
-     fixS *fixP;
+tc_coff_fix2rtype (fixS *fixP)
 {
 #if DEBUG
   printf ("tc_coff_fix2rtype\n");
@@ -1197,16 +1129,11 @@ tc_coff_fix2rtype (fixP)
 
   switch (fixP->fx_r_type)
     {
-    case RELOC_32:
-      return (R_WORD);
-    case RELOC_8:
-      return (R_BYTE);
-    case RELOC_CONST:
-      return (R_ILOHALF);
-    case RELOC_CONSTH:
-      return (R_IHIHALF);
-    case RELOC_JUMPTARG:
-      return (R_IREL);
+    case RELOC_32:        return R_WORD;
+    case RELOC_8:         return R_BYTE;
+    case RELOC_CONST:     return R_ILOHALF;
+    case RELOC_CONSTH:    return R_IHIHALF;
+    case RELOC_JUMPTARG:  return R_IREL;
     default:
       printf ("need %d\n", fixP->fx_r_type);
       abort ();
@@ -1220,12 +1147,11 @@ tc_coff_fix2rtype (fixP)
 /* Should never be called for or32.  */
 
 void
-md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
-     char *    ptr       ATTRIBUTE_UNUSED;
-     addressT  from_addr ATTRIBUTE_UNUSED;
-     addressT  to_addr   ATTRIBUTE_UNUSED;
-     fragS *   frag      ATTRIBUTE_UNUSED;
-     symbolS * to_symbol ATTRIBUTE_UNUSED;
+md_create_short_jump (char *    ptr       ATTRIBUTE_UNUSED,
+                     addressT  from_addr ATTRIBUTE_UNUSED,
+                     addressT  to_addr   ATTRIBUTE_UNUSED,
+                     fragS *   frag      ATTRIBUTE_UNUSED,
+                     symbolS * to_symbol ATTRIBUTE_UNUSED)
 {
   as_fatal ("or32_create_short_jmp\n");
 }
@@ -1234,20 +1160,18 @@ md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
 
 #ifndef BFD_ASSEMBLER
 void
-md_convert_frag (headers, seg, fragP)
-     object_headers * headers ATTRIBUTE_UNUSED;
-     segT             seg     ATTRIBUTE_UNUSED;
-     register fragS * fragP   ATTRIBUTE_UNUSED;
+md_convert_frag (object_headers * headers ATTRIBUTE_UNUSED,
+                segT             seg     ATTRIBUTE_UNUSED,
+                register fragS * fragP   ATTRIBUTE_UNUSED)
 {
   as_fatal ("or32_convert_frag\n");
 }
 
 #else
 void
-md_convert_frag (headers, seg, fragP)
-     bfd *   headers ATTRIBUTE_UNUSED;
-     segT    seg     ATTRIBUTE_UNUSED;
-     fragS * fragP   ATTRIBUTE_UNUSED;
+md_convert_frag (bfd *   headers ATTRIBUTE_UNUSED,
+                segT    seg     ATTRIBUTE_UNUSED,
+                fragS * fragP   ATTRIBUTE_UNUSED)
 {
   as_fatal ("or32_convert_frag\n");
 }
@@ -1256,12 +1180,11 @@ md_convert_frag (headers, seg, fragP)
 /* Should never be called for or32.  */
 
 void
-md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
-     char *    ptr       ATTRIBUTE_UNUSED;
-     addressT  from_addr ATTRIBUTE_UNUSED;
-     addressT  to_addr   ATTRIBUTE_UNUSED;
-     fragS *   frag      ATTRIBUTE_UNUSED;
-     symbolS * to_symbol ATTRIBUTE_UNUSED;
+md_create_long_jump (char *    ptr       ATTRIBUTE_UNUSED,
+                    addressT  from_addr ATTRIBUTE_UNUSED,
+                    addressT  to_addr   ATTRIBUTE_UNUSED,
+                    fragS *   frag      ATTRIBUTE_UNUSED,
+                    symbolS * to_symbol ATTRIBUTE_UNUSED)
 {
   as_fatal ("or32_create_long_jump\n");
 }
@@ -1269,9 +1192,8 @@ md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
 /* Should never be called for or32.  */
 
 int
-md_estimate_size_before_relax (fragP, segtype)
-     fragS * fragP   ATTRIBUTE_UNUSED;
-     segT    segtype ATTRIBUTE_UNUSED;
+md_estimate_size_before_relax (fragS * fragP   ATTRIBUTE_UNUSED,
+                              segT    segtype ATTRIBUTE_UNUSED)
 {
   as_fatal ("or32_estimate_size_before_relax\n");
   return 0;
@@ -1287,10 +1209,9 @@ md_estimate_size_before_relax (fragP, segtype)
 
 #ifdef OBJ_AOUT
 void
-tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
-     char *where;
-     fixS *fixP;
-     relax_addressT segment_address_in_file;
+tc_aout_fix_to_chars (char *where,
+                     fixS *fixP,
+                     relax_addressT segment_address_in_file)
 {
   long r_symbolnum;
 
@@ -1324,22 +1245,19 @@ tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
 const char *md_shortopts = "";
 
 struct option md_longopts[] =
-  {
-    { NULL, no_argument, NULL, 0 }
-  };
+{
+  { NULL, no_argument, NULL, 0 }
+};
 size_t md_longopts_size = sizeof (md_longopts);
 
 int
-md_parse_option (c, arg)
-     int    c   ATTRIBUTE_UNUSED;
-     char * arg ATTRIBUTE_UNUSED;
+md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
 {
   return 0;
 }
 
 void
-md_show_usage (stream)
-     FILE * stream ATTRIBUTE_UNUSED;
+md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
 {
 }
 \f
@@ -1347,8 +1265,7 @@ md_show_usage (stream)
    definitions of or32 style local labels.  */
 
 int
-or32_unrecognized_line (c)
-     int c;
+or32_unrecognized_line (int c)
 {
   int lab;
   char *s;
@@ -1383,38 +1300,12 @@ or32_unrecognized_line (c)
   return 1;
 }
 
-#ifndef BFD_ASSEMBLER
-/* Record a fixup for a cons expression.  */
-/*
-  void
-or32_cons_fix_new (frag, where, nbytes, exp)
-     fragS *frag;
-     int where;
-     int nbytes;
-     expressionS *exp;
-{
-  fix_new_exp (frag, where, nbytes, exp, 0,
-                  nbytes == 5 ? RELOC_32
-                   : nbytes == 2 ? RELOC_16
-                  : RELOC_8);
-}
-void
-tc_aout_pre_write_hook ()
-{
-#if DEBUG
-  printf ("In tc_aout_pre_write_hook()\n");
-#endif
-}
-*/
-#endif
-
 /* Default the values of symbols known that should be "predefined".  We
    don't bother to predefine them unless you actually use one, since there
    are a lot of them.  */
 
 symbolS *
-md_undefined_symbol (name)
-     char *name ATTRIBUTE_UNUSED;
+md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
 {
 #ifndef BFD_ASSEMBLER
   long regnum;
@@ -1427,8 +1318,6 @@ md_undefined_symbol (name)
   /* Register name.  */
   if (name[0] == 'r' || name[0] == 'R' || name[0] == 'a' || name[0] == 'b')
     {
-      long maxreg;
-
       /* Parse the number, make sure it has no extra zeroes or
          trailing chars.  */
       regnum = atol (& name[1]);
@@ -1452,8 +1341,7 @@ md_undefined_symbol (name)
 /* Parse an operand that is machine-specific.  */
 
 void
-md_operand (expressionP)
-     expressionS *expressionP;
+md_operand (expressionS *expressionP)
 {
 #if DEBUG
   printf ("  md_operand(input_line_pointer = %s)\n", input_line_pointer);
@@ -1581,9 +1469,7 @@ md_operand (expressionP)
 /* Round up a section size to the appropriate boundary.  */
 
 valueT
-md_section_align (segment, size)
-     segT segment ATTRIBUTE_UNUSED;
-     valueT size ATTRIBUTE_UNUSED;
+md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size ATTRIBUTE_UNUSED)
 {
   return size;      /* Byte alignment is fine.  */
 }
@@ -1593,8 +1479,7 @@ md_section_align (segment, size)
    which we have set up as the address of the fixup too.  */
 
 long
-md_pcrel_from (fixP)
-     fixS *fixP;
+md_pcrel_from (fixS *fixP)
 {
   return fixP->fx_where + fixP->fx_frag->fr_address;
 }
@@ -1603,14 +1488,12 @@ md_pcrel_from (fixP)
 
 #ifdef BFD_ASSEMBLER
 arelent *
-tc_gen_reloc (seg, fixp)
-     asection *seg ATTRIBUTE_UNUSED;
-     fixS *fixp;
+tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
 {
   arelent *reloc;
 
-  reloc = (arelent *) xmalloc (sizeof (arelent));
-  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  reloc = xmalloc (sizeof (arelent));
+  reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
   /*  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
@@ -1624,13 +1507,10 @@ tc_gen_reloc (seg, fixp)
       return NULL;
     }
 
-  if (   fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
-      || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
-    reloc->addend = fixp->fx_offset;
-  else
-  reloc->addend = fixp->fx_addnumber;
+  if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
+    reloc->address = fixp->fx_offset;
 
+  reloc->addend = fixp->fx_addnumber;
   return reloc;
 }
 #endif
-