]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gas/config/tc-pj.c
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / gas / config / tc-pj.c
index a16971d1408b54c58ef851b91c91ede1daf84ac6..4127ffd4d67203e770d93bec386cde6388365354 100644 (file)
@@ -1,12 +1,11 @@
-/*-
-   tc-pj.c -- Assemble code for Pico Java
-   Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+/* tc-pj.c -- Assemble code for Pico Java
+   Copyright (C) 1999-2021 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
    GAS is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
+   the Free Software Foundation; either version 3, or (at your option)
    any later version.
 
    GAS is distributed in the hope that it will be useful,
@@ -16,8 +15,8 @@
 
    You should have received a copy of the GNU General Public License
    along with GAS; see the file COPYING.  If not, write to
-   the Free Software Foundation, 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 /* Contributed by Steve Chamberlain of Transmeta <sac@pobox.com>.  */
 
 
 extern const pj_opc_info_t pj_opc_info[512];
 
-const char comment_chars[] = "!/";
+const char comment_chars[]        = "!/";
 const char line_separator_chars[] = ";";
-const char line_comment_chars[] = "/!#";
+const char line_comment_chars[]   = "/!#";
 
 static int pending_reloc;
-static struct hash_control *opcode_hash_control;
+static htab_t opcode_hash_control;
 
 static void
-little (ignore)
-     int ignore ATTRIBUTE_UNUSED;
+little (int ignore ATTRIBUTE_UNUSED)
 {
   target_big_endian = 0;
 }
 
 static void
-big (ignore)
-     int ignore ATTRIBUTE_UNUSED;
+big (int ignore ATTRIBUTE_UNUSED)
 {
   target_big_endian = 1;
 }
 
-const pseudo_typeS md_pseudo_table[] = {
+const pseudo_typeS md_pseudo_table[] =
+{
   {"ml",    little, 0},
   {"mb",    big,    0},
   {0, 0, 0}
@@ -58,8 +56,7 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP";
 const char EXP_CHARS[] = "eE";
 
 void
-md_operand (op)
-     expressionS *op;
+md_operand (expressionS *op)
 {
   if (strncmp (input_line_pointer, "%hi16", 5) == 0)
     {
@@ -69,6 +66,7 @@ md_operand (op)
       input_line_pointer += 5;
       expression (op);
     }
+
   if (strncmp (input_line_pointer, "%lo16", 5) == 0)
     {
       if (pending_reloc)
@@ -82,11 +80,10 @@ md_operand (op)
 /* Parse an expression and then restore the input line pointer.  */
 
 static char *
-parse_exp_save_ilp (s, op)
-     char *s;
-     expressionS *op;
+parse_exp_save_ilp (char *s, expressionS *op)
 {
   char *save = input_line_pointer;
+
   input_line_pointer = s;
   expression (op);
   s = input_line_pointer;
@@ -99,11 +96,8 @@ parse_exp_save_ilp (s, op)
    we want to handle magic pending reloc expressions specially.  */
 
 void
-pj_cons_fix_new_pj (frag, where, nbytes, exp)
-     fragS *frag;
-     int where;
-     int nbytes;
-     expressionS *exp;
+pj_cons_fix_new_pj (fragS *frag, int where, int nbytes, expressionS *exp,
+                   bfd_reloc_code_real_type r ATTRIBUTE_UNUSED)
 {
   static int rv[5][2] =
   { { 0, 0 },
@@ -123,8 +117,7 @@ pj_cons_fix_new_pj (frag, where, nbytes, exp)
    code which BFD can handle.  */
 
 static int
-c_to_r (x)
-     char x;
+c_to_r (int x)
 {
   switch (x)
     {
@@ -151,19 +144,19 @@ c_to_r (x)
    turns ipush <foo> into sipush lo16<foo>, sethi hi16<foo>.  */
 
 static void
-ipush_code (opcode, str)
-     pj_opc_info_t *opcode ATTRIBUTE_UNUSED;
-     char *str;
+ipush_code (pj_opc_info_t *opcode ATTRIBUTE_UNUSED, char *str)
 {
-  int mod = 0;
   char *b = frag_more (6);
   expressionS arg;
 
   b[0] = 0x11;
   b[3] = 0xed;
-  parse_exp_save_ilp (str + 1, &arg, &mod);
-  if (mod)
-    as_bad (_("can't have relocation for ipush"));
+  parse_exp_save_ilp (str + 1, &arg);
+  if (pending_reloc)
+    {
+      as_bad (_("can't have relocation for ipush"));
+      pending_reloc = 0;
+    }
 
   fix_new_exp (frag_now, b - frag_now->fr_literal + 1, 2,
               &arg, 0, BFD_RELOC_PJ_CODE_DIR16);
@@ -172,31 +165,28 @@ ipush_code (opcode, str)
 }
 
 /* Insert names into the opcode table which are really mini macros,
-   not opcodes.  The fakeness is inidicated with an opcode of -1.  */
+   not opcodes.  The fakeness is indicated with an opcode of -1.  */
 
 static void
-fake_opcode (name, func)
-     const char *name;
-     void (*func) ();
+fake_opcode (const char *name,
+            void (*func) (struct pj_opc_info_t *, char *))
 {
-  pj_opc_info_t *fake = (pj_opc_info_t *) xmalloc (sizeof (pj_opc_info_t));
+  pj_opc_info_t * fake = XNEW (pj_opc_info_t);
 
   fake->opcode = -1;
   fake->opcode_next = -1;
-  fake->name = (const char *) func;
-  hash_insert (opcode_hash_control, name, (char *) fake);
+  fake->u.func = func;
+  str_hash_insert (opcode_hash_control, name, fake, 0);
 }
 
 /* Enter another entry into the opcode hash table so the same opcode
    can have another name.  */
 
 static void
-alias (new, old)
-     const char *new;
-     const char *old;
+alias (const char *new_name, const char *old)
 {
-  hash_insert (opcode_hash_control, new,
-              (char *) hash_find (opcode_hash_control, old));
+  str_hash_insert (opcode_hash_control, new_name,
+                  str_hash_find (opcode_hash_control, old), 0);
 }
 
 /* This function is called once, at assembler startup time.  It sets
@@ -204,14 +194,14 @@ alias (new, old)
    some aliases for compatibility with other assemblers.  */
 
 void
-md_begin ()
+md_begin (void)
 {
   const pj_opc_info_t *opcode;
-  opcode_hash_control = hash_new ();
+  opcode_hash_control = str_htab_create ();
 
   /* Insert names into hash table.  */
-  for (opcode = pj_opc_info; opcode->name; opcode++)
-    hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
+  for (opcode = pj_opc_info; opcode->u.name; opcode++)
+    str_hash_insert (opcode_hash_control, opcode->u.name, opcode, 0);
 
   /* Insert the only fake opcode.  */
   fake_opcode ("ipush", ipush_code);
@@ -233,15 +223,11 @@ md_begin ()
    the frags/bytes it assembles to.  */
 
 void
-md_assemble (str)
-     char *str;
+md_assemble (char *str)
 {
-  unsigned char *op_start;
-  unsigned char *op_end;
+  char *op_start;
+  char *op_end;
 
-#if 0
-  pj_operan_info operand[3];
-#endif
   pj_opc_info_t *opcode;
   char *output;
   int idx = 0;
@@ -254,8 +240,9 @@ md_assemble (str)
     str++;
 
   /* Find the op code end.  */
-  for (op_start = op_end = (unsigned char *) (str);
-       *op_end && !is_end_of_line[*op_end] && *op_end != ' ';
+  op_start = str;
+  for (op_end = str;
+       *op_end && !is_end_of_line[*op_end & 0xff] && *op_end != ' ';
        op_end++)
     nlen++;
 
@@ -265,7 +252,7 @@ md_assemble (str)
   if (nlen == 0)
     as_bad (_("can't find opcode "));
 
-  opcode = (pj_opc_info_t *) hash_find (opcode_hash_control, op_start);
+  opcode = (pj_opc_info_t *) str_hash_find (opcode_hash_control, op_start);
   *op_end = pend;
 
   if (opcode == NULL)
@@ -274,15 +261,16 @@ md_assemble (str)
       return;
     }
 
+  dwarf2_emit_insn (0);
   if (opcode->opcode == -1)
     {
       /* It's a fake opcode.  Dig out the args and pretend that was
          what we were passed.  */
-      ((void (*) ()) opcode->name) (opcode, op_end);
+      (*opcode->u.func) (opcode, op_end);
     }
   else
     {
-      int an;
+      unsigned int an;
 
       output = frag_more (opcode->len);
       output[idx++] = opcode->opcode;
@@ -290,7 +278,7 @@ md_assemble (str)
       if (opcode->opcode_next != -1)
        output[idx++] = opcode->opcode_next;
 
-      for (an = 0; opcode->arg[an]; an++)
+      for (an = 0; an < ARRAY_SIZE (opcode->arg) && opcode->arg[an]; an++)
        {
          expressionS arg;
 
@@ -298,7 +286,7 @@ md_assemble (str)
            op_end++;
 
          if (*op_end == 0)
-           as_bad ("expected expresssion");
+           as_bad (_("expected expression"));
 
          op_end = parse_exp_save_ilp (op_end, &arg);
 
@@ -317,76 +305,24 @@ md_assemble (str)
        op_end++;
 
       if (*op_end != 0)
-       as_warn ("extra stuff on line ignored");
+       as_warn (_("extra stuff on line ignored"));
 
     }
 
   if (pending_reloc)
-    as_bad ("Something forgot to clean up\n");
-
+    as_bad (_("Something forgot to clean up\n"));
 }
 
-/* Turn a string in input_line_pointer into a floating point constant
-   of type type, and store the appropriate bytes in *LITP.  The number
-   of LITTLENUMS emitted is stored in *SIZEP .  An error message is
-   returned, or NULL on OK.  */
-
-char *
-md_atof (type, litP, sizeP)
-     int type;
-     char *litP;
-     int *sizeP;
+const char *
+md_atof (int type, char *litP, int *sizeP)
 {
-  int prec;
-  LITTLENUM_TYPE words[4];
-  char *t;
-  int i;
-
-  switch (type)
-    {
-    case 'f':
-      prec = 2;
-      break;
-
-    case 'd':
-      prec = 4;
-      break;
-
-    default:
-      *sizeP = 0;
-      return _("bad call to md_atof");
-    }
-
-  t = atof_ieee (input_line_pointer, type, words);
-  if (t)
-    input_line_pointer = t;
-
-  *sizeP = prec * 2;
-
-  if (!target_big_endian)
-    {
-      for (i = prec - 1; i >= 0; i--)
-       {
-         md_number_to_chars (litP, (valueT) words[i], 2);
-         litP += 2;
-       }
-    }
-  else
-    {
-      for (i = 0; i < prec; i++)
-       {
-         md_number_to_chars (litP, (valueT) words[i], 2);
-         litP += 2;
-       }
-    }
-
-  return NULL;
+  return ieee_md_atof (type, litP, sizeP, target_big_endian);
 }
 \f
 const char *md_shortopts = "";
 
-struct option md_longopts[] = {
-
+struct option md_longopts[] =
+{
 #define OPTION_LITTLE (OPTION_MD_BASE)
 #define OPTION_BIG    (OPTION_LITTLE + 1)
 
@@ -397,17 +333,15 @@ struct option md_longopts[] = {
 size_t md_longopts_size = sizeof (md_longopts);
 
 int
-md_parse_option (c, arg)
-     int c;
-     char *arg ATTRIBUTE_UNUSED;
+md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
 {
   switch (c)
     {
     case OPTION_LITTLE:
-      little ();
+      little (0);
       break;
     case OPTION_BIG:
-      big ();
+      big (0);
       break;
     default:
       return 0;
@@ -416,8 +350,7 @@ md_parse_option (c, arg)
 }
 
 void
-md_show_usage (stream)
-     FILE *stream;
+md_show_usage (FILE *stream)
 {
   fprintf (stream, _("\
 PJ options:\n\
@@ -428,18 +361,13 @@ PJ options:\n\
 /* Apply a fixup to the object file.  */
 
 void
-md_apply_fix3 (fixP, valP, seg)
-     fixS *fixP;
-     valueT * valP;
-     segT seg ATTRIBUTE_UNUSED;
+md_apply_fix (fixS *fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
 {
   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
   long val = *valP;
   long max, min;
-  int shift;
 
   max = min = 0;
-  shift = 0;
   switch (fixP->fx_r_type)
     {
     case BFD_RELOC_VTABLE_INHERIT:
@@ -512,6 +440,10 @@ md_apply_fix3 (fixP, valP, seg)
        }
       break;
 
+    case BFD_RELOC_PJ_CODE_REL32:
+      fixP->fx_done = 0;
+      return;
+
     default:
       abort ();
     }
@@ -527,10 +459,7 @@ md_apply_fix3 (fixP, valP, seg)
    executable section into big endian order.  */
 
 void
-md_number_to_chars (ptr, use, nbytes)
-     char *ptr;
-     valueT use;
-     int nbytes;
+md_number_to_chars (char *ptr, valueT use, int nbytes)
 {
   if (target_big_endian || now_seg->flags & SEC_CODE)
     number_to_chars_bigendian (ptr, use, nbytes);
@@ -542,15 +471,13 @@ md_number_to_chars (ptr, use, nbytes)
    format.  */
 
 arelent *
-tc_gen_reloc (section, fixp)
-     asection *section ATTRIBUTE_UNUSED;
-     fixS *fixp;
+tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
 {
   arelent *rel;
   bfd_reloc_code_real_type r_type;
 
-  rel = (arelent *) xmalloc (sizeof (arelent));
-  rel->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  rel = XNEW (arelent);
+  rel->sym_ptr_ptr = XNEW (asymbol *);
   *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
 
@@ -565,7 +492,7 @@ tc_gen_reloc (section, fixp)
                    bfd_get_reloc_code_name (r_type));
       /* Set howto to a garbage value so that we can keep going.  */
       rel->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32);
-      assert (rel->howto != NULL);
+      gas_assert (rel->howto != NULL);
     }
 
   return rel;