ppc/svp64: introduce SVP64 name parser
[binutils-gdb.git] / gas / config / tc-h8300.c
index 1b075c42298f47d9f3b58d6658c22601e2242afe..ac1dc0722bcc822a969ef9de3902583c3d20839e 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-h8300.c -- Assemble code for the Renesas H8/300
-   Copyright (C) 1991-2016 Free Software Foundation, Inc.
+   Copyright (C) 1991-2022 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
 #define h8_opcodes ops
 #include "opcode/h8300.h"
 #include "safe-ctype.h"
-
-#ifdef OBJ_ELF
 #include "elf/h8.h"
-#endif
 
 const char comment_chars[] = ";";
 const char line_comment_chars[] = "#";
@@ -152,7 +149,7 @@ h8300_elf_section (int push)
   static const char * known_data_sections [] = { ".rodata", ".tdata", ".tbss" };
   static const char * known_data_prefixes [] = { ".debug", ".zdebug", ".gnu.warning" };
   char * saved_ilp = input_line_pointer;
-  char * name;
+  const char * name;
 
   name = obj_elf_section_name ();
   if (name == NULL)
@@ -170,8 +167,7 @@ h8300_elf_section (int push)
 
       if (i < 0)
        for (i = ARRAY_SIZE (known_data_prefixes); i--;)
-         if (strncmp (name, known_data_prefixes[i],
-                      strlen (known_data_prefixes[i])) == 0)
+         if (startswith (name, known_data_prefixes[i]))
            break;
 
       if (i < 0)
@@ -212,12 +208,10 @@ const pseudo_typeS md_pseudo_table[] =
   {"page",    listing_eject, 0},
   {"program", s_ignore, 0},
 
-#ifdef OBJ_ELF
   {"section",   h8300_elf_section, 0},
   {"section.s", h8300_elf_section, 0},
   {"sect",      h8300_elf_section, 0},
   {"sect.s",    h8300_elf_section, 0},
-#endif
 
   {0, 0, 0}
 };
@@ -229,7 +223,7 @@ const char EXP_CHARS[] = "eE";
    or    0d1.2345e12.  */
 const char FLT_CHARS[] = "rRsSfFdDxXpP";
 
-static struct hash_control *opcode_hash_control;       /* Opcode mnemonics.  */
+static htab_t opcode_hash_control;     /* Opcode mnemonics.  */
 
 /* This function is called once, at assembler startup time.  This
    should set up all the tables, etc. that the MD part of the assembler
@@ -241,19 +235,16 @@ md_begin (void)
   unsigned int nopcodes;
   struct h8_opcode *p, *p1;
   struct h8_instruction *pi;
-  char prev_buffer[100];
   int idx = 0;
 
   if (!bfd_set_arch_mach (stdoutput, bfd_arch_h8300, default_mach))
     as_warn (_("could not set architecture and machine"));
 
-  opcode_hash_control = hash_new ();
-  prev_buffer[0] = 0;
+  opcode_hash_control = str_htab_create ();
 
   nopcodes = sizeof (h8_opcodes) / sizeof (struct h8_opcode);
 
-  h8_instructions = (struct h8_instruction *)
-    xmalloc (nopcodes * sizeof (struct h8_instruction));
+  h8_instructions = XNEWVEC (struct h8_instruction, nopcodes);
 
   pi = h8_instructions;
   p1 = h8_opcodes;
@@ -273,7 +264,7 @@ md_begin (void)
        break;
       /* Strip off any . part when inserting the opcode and only enter
         unique codes into the hash table.  */
-      dst = buffer = malloc (strlen (src) + 1);
+      dst = buffer = notes_alloc (strlen (src) + 1);
       while (*src)
        {
          if (*src == '.')
@@ -289,8 +280,7 @@ md_begin (void)
       len = dst - buffer;
       if (cmplen == 0)
        cmplen = len;
-      hash_insert (opcode_hash_control, buffer, (char *) pi);
-      strcpy (prev_buffer, buffer);
+      str_hash_insert (opcode_hash_control, buffer, pi, 0);
       idx++;
 
       for (p = p1; p->name; p++)
@@ -878,10 +868,10 @@ get_operand (char **ptr, struct h8_op *op, int direction)
       *ptr = parse_exp (src + 1, op);
       return;
     }
-  else if (strncmp (src, "mach", 4) == 0 ||
-          strncmp (src, "macl", 4) == 0 ||
-          strncmp (src, "MACH", 4) == 0 ||
-          strncmp (src, "MACL", 4) == 0)
+  else if (startswith (src, "mach") ||
+          startswith (src, "macl") ||
+          startswith (src, "MACH") ||
+          startswith (src, "MACL"))
     {
       op->reg = TOLOWER (src[3]) == 'l';
       op->mode = MACREG;
@@ -1373,7 +1363,6 @@ do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode, cons
          check_operand (operand, 0xffff, t);
          bytes[0] |= operand->exp.X_add_number >> 8;
          bytes[1] |= operand->exp.X_add_number >> 0;
-#ifdef OBJ_ELF
          /* MOVA needs both relocs to relax the second operand properly.  */
          if (relaxmode != 0
              && (OP_KIND(this_try->opcode->how) == O_MOVAB
@@ -1383,7 +1372,6 @@ do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode, cons
              idx = BFD_RELOC_16;
              fix_new_exp (frag_now, offset, 2, &operand->exp, 0, idx);
            }
-#endif
          break;
        case L_24:
          check_operand (operand, 0xffffff, t);
@@ -1400,11 +1388,9 @@ do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode, cons
          bytes[3] |= operand->exp.X_add_number >> 0;
          if (relaxmode != 0)
            {
-#ifdef OBJ_ELF
              if ((operand->mode & MODE) == DISP && relaxmode == 1)
                idx = BFD_RELOC_H8_DISP32A16;
              else
-#endif
                idx = (relaxmode == 2) ? R_MOV24B1 : R_MOVL1;
              fix_new_exp (frag_now, offset, 4, &operand->exp, 0, idx);
            }
@@ -1419,12 +1405,9 @@ do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode, cons
        case L_32:
          size = 4;
          where = (operand->mode & SIZE) == L_24 ? -1 : 0;
-#ifdef OBJ_ELF
          if ((operand->mode & MODE) == DISP && relaxmode == 1)
            idx = BFD_RELOC_H8_DISP32A16;
-         else
-#endif
-         if (relaxmode == 2)
+         else if (relaxmode == 2)
            idx = R_MOV24B1;
          else if (relaxmode == 1)
            idx = R_MOVL1;
@@ -1433,6 +1416,7 @@ do_a_fix_imm (int offset, int nibble, struct h8_op *operand, int relaxmode, cons
          break;
        default:
          as_bad (_("Can't work out size of operand.\n"));
+         /* Fall through.  */
        case L_16:
        case L_16U:
          size = 2;
@@ -1656,17 +1640,9 @@ build_bytes (const struct h8_instruction *this_try, struct h8_op *operand)
       int x_mode = x & MODE;
 
       if (x_mode == IMM || x_mode == DISP)
-       {
-#ifndef OBJ_ELF
-         /* Remove MEMRELAX flag added in h8300.h on mov with
-            addressing mode "register indirect with displacement".  */
-         if (x_mode == DISP)
-           x &= ~MEMRELAX;
-#endif
-         do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2,
-                       op_at[i] & 1, operand + i, (x & MEMRELAX) != 0,
-                       this_try);
-       }
+       do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2,
+                     op_at[i] & 1, operand + i, (x & MEMRELAX) != 0,
+                     this_try);
       else if (x_mode == ABS)
        do_a_fix_imm (output - frag_now->fr_literal + op_at[i] / 2,
                      op_at[i] & 1, operand + i,
@@ -1685,14 +1661,6 @@ build_bytes (const struct h8_instruction *this_try, struct h8_op *operand)
          if (operand[i].exp.X_add_number & 1)
            as_warn (_("branch operand has odd offset (%lx)\n"),
                     (unsigned long) operand->exp.X_add_number);
-#ifndef OBJ_ELF
-         /* The COFF port has always been off by one, changing it
-            now would be an incompatible change, so we leave it as-is.
-
-            We don't want to do this for ELF as we want to be
-            compatible with the proposed ELF format from Hitachi.  */
-         operand[i].exp.X_add_number -= 1;
-#endif
          if (size16)
            {
              operand[i].exp.X_add_number =
@@ -1744,7 +1712,6 @@ build_bytes (const struct h8_instruction *this_try, struct h8_op *operand)
          int where = 0;
          bfd_reloc_code_real_type reloc_type = R_JMPL1;
 
-#ifdef OBJ_ELF
          /* To be compatible with the proposed H8 ELF format, we
             want the relocation's offset to point to the first byte
             that will be modified, not to the start of the instruction.  */
@@ -1756,7 +1723,6 @@ build_bytes (const struct h8_instruction *this_try, struct h8_op *operand)
            }
          else
            where = 1;
-#endif
 
          /* This jmp may be a jump or a branch.  */
 
@@ -1970,7 +1936,7 @@ md_assemble (char *str)
       *slash = TOLOWER (*slash);
 
   instruction = (const struct h8_instruction *)
-    hash_find (opcode_hash_control, op_start);
+    str_hash_find (opcode_hash_control, op_start);
 
   if (instruction == NULL)
     {
@@ -2101,10 +2067,10 @@ md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
 
 /* Various routines to kill one day.  */
 
-char *
+const char *
 md_atof (int type, char *litP, int *sizeP)
 {
-  return ieee_md_atof (type, litP, sizeP, TRUE);
+  return ieee_md_atof (type, litP, sizeP, true);
 }
 \f
 #define OPTION_H_TICK_HEX      (OPTION_MD_BASE)
@@ -2197,7 +2163,7 @@ const struct mach_func mach_table[] =
 };
 
 int
-md_parse_option (int c ATTRIBUTE_UNUSED, char *arg ATTRIBUTE_UNUSED)
+md_parse_option (int c ATTRIBUTE_UNUSED, const char *arg ATTRIBUTE_UNUSED)
 {
   unsigned int i;
   switch (c)
@@ -2255,7 +2221,7 @@ md_convert_frag (bfd *headers ATTRIBUTE_UNUSED,
 valueT
 md_section_align (segT segment, valueT size)
 {
-  int align = bfd_get_section_alignment (stdoutput, segment);
+  int align = bfd_section_alignment (segment);
   return ((size + (1 << align) - 1) & (-1U << align));
 }
 
@@ -2329,14 +2295,13 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
       if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
          || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
        {
-         as_bad_where (fixp->fx_file, fixp->fx_line,
-                       _("Difference of symbols in different sections is not supported"));
+         as_bad_subtract (fixp);
          return NULL;
        }
     }
 
-  rel = xmalloc (sizeof (arelent));
-  rel->sym_ptr_ptr = 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;
   rel->addend = fixp->fx_offset;