x86: fold individual Jump* attributes into a single Jump one
[deliverable/binutils-gdb.git] / gas / config / tc-m32c.c
index 8194a673084a91158d8f7bc34d6b92713080a31d..3ea3e5997407ee93a1d3841b2e738dc8f3dc1c9b 100644 (file)
@@ -1,12 +1,12 @@
 /* tc-m32c.c -- Assembler for the Renesas M32C.
-   Copyright (C) 2005, 2006 Free Software Foundation.
+   Copyright (C) 2005-2019 Free Software Foundation, Inc.
    Contributed by RedHat.
 
    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,
    GNU General Public License for more details.
 
    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.  */
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 #include "as.h"
-#include "subsegs.h"     
+#include "subsegs.h"
 #include "symcat.h"
 #include "opcodes/m32c-desc.h"
 #include "opcodes/m32c-opc.h"
 #include "cgen.h"
 #include "elf/common.h"
 #include "elf/m32c.h"
-#include "libbfd.h"
 #include "safe-ctype.h"
 
 /* Structure to hold all of the different components
@@ -68,12 +67,14 @@ const char * md_shortopts = M32C_SHORTOPTS;
 #define OPTION_CPU_M16C               (OPTION_MD_BASE)
 #define OPTION_CPU_M32C        (OPTION_MD_BASE + 1)
 #define OPTION_LINKRELAX       (OPTION_MD_BASE + 2)
+#define OPTION_H_TICK_HEX      (OPTION_MD_BASE + 3)
 
 struct option md_longopts[] =
 {
   { "m16c",       no_argument,       NULL, OPTION_CPU_M16C   },
   { "m32c",       no_argument,       NULL, OPTION_CPU_M32C   },
   { "relax",      no_argument,       NULL, OPTION_LINKRELAX   },
+  { "h-tick-hex", no_argument,       NULL, OPTION_H_TICK_HEX  },
   {NULL, no_argument, NULL, 0}
 };
 size_t md_longopts_size = sizeof (md_longopts);
@@ -85,7 +86,6 @@ size_t md_longopts_size = sizeof (md_longopts);
 
 static unsigned long m32c_mach = bfd_mach_m16c;
 static int cpu_mach = (1 << MACH_M16C);
-static int insn_size;
 static int m32c_relax = 0;
 
 /* Flags to set in the elf header */
@@ -103,7 +103,7 @@ set_isa (enum isa_attr isa_num)
 static void s_bss (int);
 
 int
-md_parse_option (int c, char * arg ATTRIBUTE_UNUSED)
+md_parse_option (int c, const char * arg ATTRIBUTE_UNUSED)
 {
   switch (c)
     {
@@ -125,6 +125,10 @@ md_parse_option (int c, char * arg ATTRIBUTE_UNUSED)
       m32c_relax = 1;
       break;
 
+    case OPTION_H_TICK_HEX:
+      enable_h_tick_hex = 1;
+      break;
+
     default:
       return 0;
     }
@@ -135,7 +139,7 @@ void
 md_show_usage (FILE * stream)
 {
   fprintf (stream, _(" M32C specific command line options:\n"));
-} 
+}
 
 static void
 s_bss (int ignore ATTRIBUTE_UNUSED)
@@ -180,22 +184,6 @@ md_begin (void)
 
   /* Set the machine type */
   bfd_default_set_arch_mach (stdoutput, bfd_arch_m32c, m32c_mach);
-
-  insn_size = 0;
-}
-
-void
-m32c_md_end (void)
-{
-  int i, n_nops;
-
-  if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
-    {
-      /* Pad with nops for objdump.  */
-      n_nops = (32 - ((insn_size) % 32)) / 8;
-      for (i = 1; i <= n_nops; i++)
-       md_assemble ("nop");
-    }
 }
 
 void
@@ -255,21 +243,21 @@ m32c_indirect_operand (char *str)
       if (s[0] == '[' && s[1] == '[')
        indirection[operand] = relative;
     }
-   
+
   if (indirection[1] == none && indirection[2] == none)
     return FALSE;
-  
+
   operand = 1;
   ns_len = strlen (str);
-  new_str = (char*) xmalloc (ns_len);
+  new_str = XNEWVEC (char, ns_len);
   ns = new_str;
   ns_end = ns + ns_len;
+
   for (s = str; *s; s++)
     {
       if (s[0] == ',')
        operand = 2;
+
       if (s[0] == '[' && ! brace_n[operand])
        {
          brace_n[operand] += 1;
@@ -277,7 +265,7 @@ m32c_indirect_operand (char *str)
          if (indirection[operand] != none)
            continue;
        }
+
       else if (s[0] == '[' && brace_n[operand])
        {
          brace_n[operand] += 1;
@@ -309,13 +297,13 @@ m32c_indirect_operand (char *str)
       {
        fprintf (stderr, "Unmatched [[operand-%d]] %d\n", operand, brace_n[operand]);
       }
-       
+
   if (indirection[1] != none && indirection[2] != none)
-    md_assemble ("src-dest-indirect");
+    md_assemble ((char *) "src-dest-indirect");
   else if (indirection[1] != none)
-    md_assemble ("src-indirect");
+    md_assemble ((char *) "src-indirect");
   else if (indirection[2] != none)
-    md_assemble ("dest-indirect");
+    md_assemble ((char *) "dest-indirect");
 
   md_assemble (new_str);
   free (new_str);
@@ -330,6 +318,7 @@ md_assemble (char * str)
   char *    errmsg;
   finished_insnS results;
   int rl_type;
+  int insn_size;
 
   if (m32c_mach == bfd_mach_m32c && m32c_indirect_operand (str))
     return;
@@ -339,7 +328,7 @@ md_assemble (char * str)
 
   insn.insn = m32c_cgen_assemble_insn
     (gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg);
-  
+
   if (!insn.insn)
     {
       as_bad ("%s", errmsg);
@@ -353,6 +342,7 @@ md_assemble (char * str)
 
   last_insn_had_delay_slot
     = CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_DELAY_SLOT);
+  (void) last_insn_had_delay_slot;
   insn_size = CGEN_INSN_BITSIZE(insn.insn);
 
   rl_type = rl_for (insn);
@@ -391,7 +381,7 @@ md_assemble (char * str)
 /* The syntax in the manual says constants begin with '#'.
    We just ignore it.  */
 
-void 
+void
 md_operand (expressionS * exp)
 {
   /* In case of a syntax error, escape back to try next syntax combo. */
@@ -402,8 +392,8 @@ md_operand (expressionS * exp)
 valueT
 md_section_align (segT segment, valueT size)
 {
-  int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  int align = bfd_section_alignment (segment);
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
@@ -468,7 +458,7 @@ enum {
   M32C_MACRO_ADJNZ_3,
   M32C_MACRO_ADJNZ_4,
   M32C_MACRO_ADJNZ_5,
-} M32C_Macros;
+};
 
 static struct {
   int insn;
@@ -588,7 +578,7 @@ md_estimate_size_before_relax (fragS * fragP, segT segment ATTRIBUTE_UNUSED)
     }
 
   return subtype_mappings[fragP->fr_subtype].bytes - (fragP->fr_fix - where);
-} 
+}
 
 /* *fragP has been relaxed to its final size, and now needs to have
    the bytes inside it modified to conform to the new size.
@@ -617,27 +607,20 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
 {
   int addend;
   int operand;
-  int new_insn;
   int where = fragP->fr_opcode - fragP->fr_literal;
   int rl_where = fragP->fr_opcode - fragP->fr_literal;
   unsigned char *op = (unsigned char *)fragP->fr_opcode;
-  int op_base = 0;
-  int op_op = 0;
   int rl_addend = 0;
 
   addend = target_address_for (fragP) - (fragP->fr_address + where);
-  new_insn = subtype_mappings[fragP->fr_subtype].insn;
 
   fragP->fr_fix = where + subtype_mappings[fragP->fr_subtype].bytes;
 
-  op_base = 0;
-
   switch (subtype_mappings[fragP->fr_subtype].insn)
     {
     case M32C_INSN_JCND16_5:
       op[1] = addend - 1;
       operand = M32C_OPERAND_LAB_8_8;
-      op_op = 1;
       rl_addend = 0x21;
       break;
 
@@ -649,9 +632,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[4] = (addend - 3) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
       where += 2;
-      new_insn = M32C_INSN_JMP16_W;
-      op_base = 2;
-      op_op = 3;
       rl_addend = 0x51;
       break;
 
@@ -661,9 +641,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[2] = 0xfc;
       operand = M32C_OPERAND_LAB_8_24;
       where += 2;
-      new_insn = M32C_INSN_JMP16_A;
-      op_base = 2;
-      op_op = 3;
       rl_addend = 0x61;
       break;
 
@@ -671,8 +648,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
     case M32C_INSN_JCND16:
       op[2] = addend - 2;
       operand = M32C_OPERAND_LAB_16_8;
-      op_base = 0;
-      op_op = 2;
       rl_addend = 0x31;
       break;
 
@@ -684,9 +659,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[5] = (addend - 4) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
       where += 3;
-      new_insn = M32C_INSN_JMP16_W;
-      op_base = 3;
-      op_op = 4;
       rl_addend = 0x61;
       break;
 
@@ -696,17 +668,12 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[3] = 0xfc;
       operand = M32C_OPERAND_LAB_8_24;
       where += 3;
-      new_insn = M32C_INSN_JMP16_A;
-      op_base = 3;
-      op_op = 4;
       rl_addend = 0x71;
       break;
 
     case M32C_INSN_JMP16_S:
       op[0] = 0x60 | ((addend-2) & 0x07);
       operand = M32C_OPERAND_LAB_5_3;
-      op_base = 0;
-      op_op = 0;
       rl_addend = 0x10;
       break;
 
@@ -714,8 +681,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[0] = 0xfe;
       op[1] = addend - 1;
       operand = M32C_OPERAND_LAB_8_8;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x21;
       break;
 
@@ -724,8 +689,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[1] = addend - 1;
       op[2] = (addend - 1) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x31;
       break;
 
@@ -735,16 +698,12 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[2] = 0;
       op[3] = 0;
       operand = M32C_OPERAND_LAB_8_24;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x41;
       break;
 
     case M32C_INSN_JCND32:
       op[1] = addend - 1;
       operand = M32C_OPERAND_LAB_8_8;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x21;
       break;
 
@@ -756,9 +715,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[4] = (addend - 3) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
       where += 2;
-      new_insn = M32C_INSN_JMP32_W;
-      op_base = 2;
-      op_op = 3;
       rl_addend = 0x51;
       break;
 
@@ -768,20 +724,13 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[2] = 0xcc;
       operand = M32C_OPERAND_LAB_8_24;
       where += 2;
-      new_insn = M32C_INSN_JMP32_A;
-      op_base = 2;
-      op_op = 3;
       rl_addend = 0x61;
       break;
 
-
-
     case M32C_INSN_JMP32_S:
       addend = ((addend-2) & 0x07);
       op[0] = 0x4a | (addend & 0x01) | ((addend << 3) & 0x30);
       operand = M32C_OPERAND_LAB32_JMP_S;
-      op_base = 0;
-      op_op = 0;
       rl_addend = 0x10;
       break;
 
@@ -789,8 +738,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[0] = 0xbb;
       op[1] = addend - 1;
       operand = M32C_OPERAND_LAB_8_8;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x21;
       break;
 
@@ -799,8 +746,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[1] = addend - 1;
       op[2] = (addend - 1) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x31;
       break;
 
@@ -810,8 +755,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[2] = 0;
       op[3] = 0;
       operand = M32C_OPERAND_LAB_8_24;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x41;
       break;
 
@@ -821,8 +764,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[1] = addend - 1;
       op[2] = (addend - 1) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x31;
       break;
 
@@ -832,8 +773,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[2] = 0;
       op[3] = 0;
       operand = M32C_OPERAND_LAB_8_24;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x41;
       break;
 
@@ -842,8 +781,6 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[1] = addend - 1;
       op[2] = (addend - 1) >> 8;
       operand = M32C_OPERAND_LAB_8_16;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x31;
       break;
 
@@ -853,33 +790,30 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       op[2] = 0;
       op[3] = 0;
       operand = M32C_OPERAND_LAB_8_24;
-      op_base = 0;
-      op_op = 1;
       rl_addend = 0x41;
       break;
 
     case -M32C_MACRO_ADJNZ_2:
       rl_addend = 0x31;
-      op[2] = addend;
+      op[2] = addend - 2;
       operand = M32C_OPERAND_LAB_16_8;
       break;
     case -M32C_MACRO_ADJNZ_3:
       rl_addend = 0x41;
-      op[3] = addend;
+      op[3] = addend - 2;
       operand = M32C_OPERAND_LAB_24_8;
       break;
     case -M32C_MACRO_ADJNZ_4:
       rl_addend = 0x51;
-      op[4] = addend;
+      op[4] = addend - 2;
       operand = M32C_OPERAND_LAB_32_8;
       break;
     case -M32C_MACRO_ADJNZ_5:
       rl_addend = 0x61;
-      op[5] = addend;
+      op[5] = addend - 2;
       operand = M32C_OPERAND_LAB_40_8;
       break;
 
-
     default:
       printf("\nHey!  Need more opcode converters! missing: %d %s\n\n",
             fragP->fr_subtype,
@@ -903,16 +837,16 @@ md_convert_frag (bfd *   abfd ATTRIBUTE_UNUSED,
       || (m32c_relax && (operand != M32C_OPERAND_LAB_5_3
                         && operand != M32C_OPERAND_LAB32_JMP_S)))
     {
-      fixS *fixP;
-      assert (fragP->fr_cgen.insn != 0);
-      fixP = gas_cgen_record_fixup (fragP,
-                                   where,
-                                   fragP->fr_cgen.insn,
-                                   (fragP->fr_fix - where) * 8,
-                                   cgen_operand_lookup_by_num (gas_cgen_cpu_desc,
-                                                               operand),
-                                   fragP->fr_cgen.opinfo,
-                                   fragP->fr_symbol, fragP->fr_offset);
+      gas_assert (fragP->fr_cgen.insn != 0);
+      gas_cgen_record_fixup (fragP,
+                            where,
+                            fragP->fr_cgen.insn,
+                            (fragP->fr_fix - where) * 8,
+                            cgen_operand_lookup_by_num (gas_cgen_cpu_desc,
+                                                        operand),
+                            fragP->fr_cgen.opinfo,
+                            fragP->fr_symbol,
+                            fragP->fr_offset);
     }
 }
 \f
@@ -1068,10 +1002,9 @@ void
 m32c_cons_fix_new (fragS *     frag,
                   int          where,
                   int          size,
-                  expressionS *exp)
+                  expressionS *exp,
+                  bfd_reloc_code_real_type type)
 {
-  bfd_reloc_code_real_type type;
-
   switch (size)
     {
     case 1:
@@ -1113,10 +1046,10 @@ tc_gen_reloc (asection *sec, fixS *fx)
       || fx->fx_r_type == BFD_RELOC_M32C_RL_2ADDR)
     {
       arelent * reloc;
-      reloc = xmalloc (sizeof (* reloc));
-      reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
+
+      reloc = XNEW (arelent);
+
+      reloc->sym_ptr_ptr = XNEW (asymbol *);
       *reloc->sym_ptr_ptr = symbol_get_bfdsym (fx->fx_addsy);
       reloc->address = fx->fx_frag->fr_address + fx->fx_where;
       reloc->howto = bfd_reloc_type_lookup (stdoutput, fx->fx_r_type);
@@ -1202,53 +1135,10 @@ md_number_to_chars (char * buf, valueT val, int n)
    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.  */
 
-/* Equal to MAX_PRECISION in atof-ieee.c.  */
-#define MAX_LITTLENUMS 6
-
-char *
+const char *
 md_atof (int type, char * litP, int * sizeP)
 {
-  int              i;
-  int              prec;
-  LITTLENUM_TYPE   words [MAX_LITTLENUMS];
-  char *           t;
-
-  switch (type)
-    {
-    case 'f':
-    case 'F':
-    case 's':
-    case 'S':
-      prec = 2;
-      break;
-
-    case 'd':
-    case 'D':
-    case 'r':
-    case 'R':
-      prec = 4;
-      break;
-
-   /* FIXME: Some targets allow other format chars for bigger sizes here.  */
-
-    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 * sizeof (LITTLENUM_TYPE);
-
-  for (i = 0; i < prec; i++)
-    {
-      md_number_to_chars (litP, (valueT) words[i],
-                         sizeof (LITTLENUM_TYPE));
-      litP += sizeof (LITTLENUM_TYPE);
-    }
-     
-  return 0;
+  return ieee_md_atof (type, litP, sizeP, TRUE);
 }
 
 bfd_boolean
@@ -1337,21 +1227,16 @@ m32c_fix_adjustable (fixS * fixP)
 }
 
 /* Worker function for m32c_is_colon_insn().  */
-static char restore_colon PARAMS ((int));
-
-static char
-restore_colon (int advance_i_l_p_by)
+static int
+restore_colon (char *next_i_l_p, char *nul_char)
 {
-  char c;
-
   /* Restore the colon, and advance input_line_pointer to
      the end of the new symbol.  */
-  * input_line_pointer = ':';
-  input_line_pointer += advance_i_l_p_by;
-  c = * input_line_pointer;
-  * input_line_pointer = 0;
-
-  return c;
+  *input_line_pointer = *nul_char;
+  input_line_pointer = next_i_l_p;
+  *nul_char = *next_i_l_p;
+  *next_i_l_p = 0;
+  return 1;
 }
 
 /* Determines if the symbol starting at START and ending in
@@ -1359,28 +1244,31 @@ restore_colon (int advance_i_l_p_by)
    (but which has now been replaced bu a NUL) is in fact an
    :Z, :S, :Q, or :G suffix.
    If it is, then it restores the colon, advances INPUT_LINE_POINTER
-   to the real end of the instruction/symbol, and returns the character
-   that really terminated the symbol.  Otherwise it returns 0.  */
-char
-m32c_is_colon_insn (char *start ATTRIBUTE_UNUSED)
+   to the real end of the instruction/symbol, saves the char there to
+   NUL_CHAR and pokes a NUL, and returns 1.  Otherwise it returns 0.  */
+int
+m32c_is_colon_insn (char *start ATTRIBUTE_UNUSED, char *nul_char)
 {
   char * i_l_p = input_line_pointer;
 
+  if (*nul_char == '"')
+    ++i_l_p;
+
   /* Check to see if the text following the colon is 'G' */
   if (TOLOWER (i_l_p[1]) == 'g' && (i_l_p[2] == ' ' || i_l_p[2] == '\t'))
-    return restore_colon (2);
+    return restore_colon (i_l_p + 2, nul_char);
 
   /* Check to see if the text following the colon is 'Q' */
   if (TOLOWER (i_l_p[1]) == 'q' && (i_l_p[2] == ' ' || i_l_p[2] == '\t'))
-    return restore_colon (2);
+    return restore_colon (i_l_p + 2, nul_char);
 
   /* Check to see if the text following the colon is 'S' */
   if (TOLOWER (i_l_p[1]) == 's' && (i_l_p[2] == ' ' || i_l_p[2] == '\t'))
-    return restore_colon (2);
+    return restore_colon (i_l_p + 2, nul_char);
 
   /* Check to see if the text following the colon is 'Z' */
   if (TOLOWER (i_l_p[1]) == 'z' && (i_l_p[2] == ' ' || i_l_p[2] == '\t'))
-    return restore_colon (2);
+    return restore_colon (i_l_p + 2, nul_char);
 
   return 0;
 }
This page took 0.03538 seconds and 4 git commands to generate.