gas: Adjust x86 tests for PECOFF
[deliverable/binutils-gdb.git] / gas / config / tc-xgate.c
index 1a4b11590886b7e580796ba62930ddf5d180206a..488ee4c39bbbb815760120885a6f360e2fb8ea0a 100644 (file)
@@ -1,6 +1,5 @@
 /* tc-xgate.c -- Assembler code for Freescale XGATE
-   Copyright 2010, 2011, 2012
-   Free Software Foundation, Inc.
+   Copyright (C) 2010-2020 Free Software Foundation, Inc.
    Contributed by Sean Keys <skeys@ipdatasys.com>
 
    This file is part of GAS, the GNU Assembler.
@@ -33,6 +32,9 @@ const char line_separator_chars[] = "";
 const char EXP_CHARS[] = "eE";
 const char FLT_CHARS[] = "dD";
 
+/* Max opcodes per opcode handle.  */
+#define MAX_OPCODES     0x05
+
 #define SIXTEENTH_BIT          0x8000
 #define N_BITS_IN_WORD         16
 #define MAX_NUM_OPERANDS       3
@@ -101,12 +103,12 @@ static inline char *skip_whitespace (char *);
 static void get_default_target (void);
 static char *extract_word (char *, char *, int);
 static struct xgate_opcode *xgate_find_match (struct xgate_opcode_handle *,
-                                             int, unsigned int);
+                                             int, s_operand [], unsigned int);
 static int cmp_opcode (struct xgate_opcode *, struct xgate_opcode *);
 static void xgate_print_table (void);
 static unsigned int xgate_get_operands (char *, s_operand []);
 static register_id reg_name_search (char *);
-static op_modifiers xgate_determine_modifiers(char **);
+static op_modifiers xgate_determine_modifiers (char **);
 static void xgate_scan_operands (struct xgate_opcode *opcode, s_operand []);
 static unsigned int xgate_parse_operand (struct xgate_opcode *, int *, int,
                                         char **, s_operand);
@@ -189,16 +191,16 @@ struct option md_longopts[] =
   { NULL, no_argument, NULL, 0 }
 };
 
-size_t md_longopts_size = sizeof(md_longopts);
+size_t md_longopts_size = sizeof (md_longopts);
 
-char *
+const char *
 md_atof (int type, char *litP, int *sizeP)
 {
   return ieee_md_atof (type, litP, sizeP, TRUE);
 }
 
 int
-md_parse_option (int c, char *arg)
+md_parse_option (int c, const char *arg)
 {
   switch (c)
     {
@@ -210,7 +212,7 @@ md_parse_option (int c, char *arg)
       else if (strcasecmp (arg, "v3") == 0)
        current_architecture = XGATE_V3;
       else
-       as_bad (_(" architecture variant invalid"));
+       as_bad (_("architecture variant invalid"));
       break;
 
     case OPTION_PRINT_INSN_SYNTAX:
@@ -289,24 +291,23 @@ md_begin (void)
   struct xgate_opcode *xgate_opcode_ptr = NULL;
   struct xgate_opcode *xgate_op_table = NULL;
   struct xgate_opcode_handle *op_handles = 0;
-  char *prev_op_name = 0;
+  const char *prev_op_name = 0;
   int handle_enum = 0;
   int number_of_op_handles = 0;
   int i, j = 0;
 
   /* Create a local copy of our opcode table
      including an extra line for NULL termination.  */
-  xgate_op_table = (struct xgate_opcode *)
-    xmalloc ((xgate_num_opcodes) * sizeof (struct xgate_opcode));
+  xgate_op_table = XNEWVEC (struct xgate_opcode, xgate_num_opcodes);
 
   memset (xgate_op_table, 0,
-         sizeof(struct xgate_opcode) * (xgate_num_opcodes));
+         sizeof (struct xgate_opcode) * (xgate_num_opcodes));
 
   for (xgate_opcode_ptr = (struct xgate_opcode*) xgate_opcodes, i = 0;
        i < xgate_num_opcodes; i++)
     xgate_op_table[i] = xgate_opcode_ptr[i];
 
-  qsort (xgate_op_table, xgate_num_opcodes, sizeof(struct xgate_opcode),
+  qsort (xgate_op_table, xgate_num_opcodes, sizeof (struct xgate_opcode),
         (int (*)(const void *, const void *)) cmp_opcode);
 
   /* Calculate number of handles since this will be
@@ -320,8 +321,7 @@ md_begin (void)
       prev_op_name = xgate_opcode_ptr->name;
     }
 
-  op_handles = (struct xgate_opcode_handle *)
-    xmalloc (sizeof(struct xgate_opcode_handle) * (number_of_op_handles));
+  op_handles = XNEWVEC (struct xgate_opcode_handle, number_of_op_handles);
 
   /* Insert unique opcode names into hash table, aliasing duplicates.  */
   xgate_hash = hash_new ();
@@ -373,7 +373,7 @@ Freescale XGATE co-processor options:\n\
   -mlong                  use 32-bit int ABI\n\
   -mshort-double          use 32-bit double ABI\n\
   -mlong-double           use 64-bit double ABI (default)\n\
-  --mxgate                specify the processor variant[default %s]\n\
+  --mxgate                specify the processor variant [default %s]\n\
   --print-insn-syntax     print the syntax of instruction in case of error\n\
   --print-opcodes         print the list of instructions with syntax\n\
   --generate-example      generate an example of each instruction"),
@@ -457,7 +457,7 @@ xgate_listing_header (void)
 symbolS *
 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
 {
-  return 0;
+  return NULL;
 }
 
 /* GAS will call this function for each section at the end of the assembly,
@@ -466,8 +466,8 @@ md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
 valueT
 md_section_align (asection * seg, valueT addr)
 {
-  int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  int align = bfd_section_alignment (seg);
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
@@ -479,14 +479,14 @@ md_assemble (char *input_line)
   /* Caller expects it to be returned as it was passed.  */
   char *saved_input_line = input_line;
   char op_name[9] =  { 0 };
-  unsigned int sh_format = 0;
+  unsigned int operandCount = 0;
   char *p = 0;
 
   s_operand new_operands[MAX_NUM_OPERANDS];
 
   fixup_required = 0;
   oper_check = 0; /* set error flags */
-  input_line = extract_word (input_line, op_name, sizeof(op_name));
+  input_line = extract_word (input_line, op_name, sizeof (op_name));
 
   /* Check to make sure we are not reading a bogus line.  */
   if (!op_name[0])
@@ -501,14 +501,14 @@ md_assemble (char *input_line)
     {
       /* Parse operands so we can find the proper opcode bin.  */
 
-      sh_format = xgate_get_operands(input_line, new_operands);
+      operandCount = xgate_get_operands (input_line, new_operands);
 
       opcode = xgate_find_match (opcode_handle, opcode_handle->number_of_modes,
-                                sh_format);
+                                new_operands, operandCount);
 
       if (!opcode)
        {
-         as_bad (_("matching operands to opcode "));
+         as_bad (_("matching operands to opcode"));
          xgate_print_syntax (opcode_handle->opc0[0]->name);
        }
       else if (opcode->size == 2)
@@ -552,13 +552,11 @@ md_assemble (char *input_line)
                }
              else
                {
-                 sh_format = xgate_get_operands(input_line, new_operands);
-                 macro_opcode
-                   = xgate_find_match (opcode_handle,
-                                       opcode_handle->number_of_modes,
-                                       sh_format);
+                 operandCount = xgate_get_operands (input_line, new_operands);
+                 macro_opcode = xgate_find_match (opcode_handle,
+                                                  opcode_handle->number_of_modes, new_operands,
+                                                  operandCount);
                  xgate_scan_operands (macro_opcode, new_operands);
-
                }
            }
        }
@@ -616,8 +614,8 @@ tc_gen_reloc (asection * section ATTRIBUTE_UNUSED, fixS * fixp)
 {
   arelent * reloc;
 
-  reloc = (arelent *) xmalloc (sizeof(arelent));
-  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof(asymbol *));
+  reloc = XNEW (arelent);
+  reloc->sym_ptr_ptr = XNEW (asymbol *);
   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
 
@@ -670,7 +668,7 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
 
   switch (fixP->fx_r_type)
     {
-    case R_XGATE_PCREL_9:
+    case BFD_RELOC_XGATE_PCREL_9:
       if (value < -512 || value > 511)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value %ld too large for 9-bit PC-relative branch."),
@@ -687,7 +685,7 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg ATTRIBUTE_UNUSED)
       value &= mask;
       number_to_chars_bigendian (where, (opcode | value), 2);
       break;
-    case R_XGATE_PCREL_10:
+    case BFD_RELOC_XGATE_PCREL_10:
       if (value < -1024 || value > 1023)
        as_bad_where (fixP->fx_file, fixP->fx_line,
                      _("Value %ld too large for 10-bit PC-relative branch."),
@@ -891,7 +889,8 @@ static char *
 xgate_parse_exp (char *s, expressionS * op)
 {
   input_line_pointer = s;
-  expression(op);
+
+  expression (op);
   if (op->X_op == O_absent)
     as_bad (_("missing operand"));
   return input_line_pointer;
@@ -905,8 +904,7 @@ cmp_opcode (struct xgate_opcode *op1, struct xgate_opcode *op2)
 
 static struct xgate_opcode *
 xgate_find_match (struct xgate_opcode_handle *opcode_handle,
-                 int numberOfModes,
-                 unsigned int sh_format)
+                 int numberOfModes, s_operand oprs[], unsigned int operandCount)
 {
   int i;
 
@@ -914,10 +912,88 @@ xgate_find_match (struct xgate_opcode_handle *opcode_handle,
     return opcode_handle->opc0[0];
 
   for (i = 0; i <= numberOfModes; i++)
-    if (opcode_handle->opc0[i]->sh_format & sh_format)
-      return opcode_handle->opc0[i];
-
-  return NULL;
+    {
+      switch (operandCount)
+        {
+      case 0:
+        if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_INH))
+          return opcode_handle->opc0[i];
+        break;
+      case 1:
+        if (oprs[0].reg >= REG_R0 && oprs[0].reg <= REG_R7)
+         {
+           if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_MON))
+             return opcode_handle->opc0[i];
+           if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_DYA_MON))
+             return opcode_handle->opc0[i];
+         }
+        if (oprs[0].reg == REG_NONE)
+          if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_IMM3))
+            return opcode_handle->opc0[i];
+        break;
+      case 2:
+        if (oprs[0].reg >= REG_R0 && oprs[0].reg <= REG_R7)
+          {
+            if (oprs[1].reg >= REG_R0 && oprs[1].reg <= REG_R7)
+             {
+               if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_DYA))
+                 return opcode_handle->opc0[i];
+             }
+            if (oprs[1].reg == REG_CCR)
+              if (!strcmp (opcode_handle->opc0[i]->constraints,
+                  XGATE_OP_MON_R_C))
+                return opcode_handle->opc0[i];
+            if (oprs[1].reg == REG_PC)
+              if (!strcmp (opcode_handle->opc0[i]->constraints,
+                  XGATE_OP_MON_R_P))
+                return opcode_handle->opc0[i];
+            if (oprs[1].reg == REG_NONE)
+              if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_IMM16)
+                  || !strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_IMM8)
+                  || !strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_IMM4)
+                  || !strcmp (opcode_handle->opc0[i]->constraints,
+                      XGATE_OP_IMM16mADD)
+                  || !strcmp (opcode_handle->opc0[i]->constraints,
+                      XGATE_OP_IMM16mAND)
+                  || !strcmp (opcode_handle->opc0[i]->constraints,
+                      XGATE_OP_IMM16mCPC)
+                  || !strcmp (opcode_handle->opc0[i]->constraints,
+                      XGATE_OP_IMM16mSUB)
+                  || !strcmp (opcode_handle->opc0[i]->constraints,
+                      XGATE_OP_IMM16mLDW))
+                return opcode_handle->opc0[i];
+          }
+        if (oprs[0].reg == REG_CCR)
+          if (!strcmp (opcode_handle->opc0[i]->constraints, XGATE_OP_MON_C_R))
+            return opcode_handle->opc0[i];
+        break;
+      case 3:
+        if (oprs[0].reg >= REG_R0 && oprs[0].reg <= REG_R7)
+          {
+            if (oprs[1].reg >= REG_R0 && oprs[1].reg <= REG_R7)
+              {
+                if (oprs[2].reg >= REG_R0 && oprs[2].reg <= REG_R7)
+                  {
+                    if (!strcmp (opcode_handle->opc0[i]->constraints,
+                        XGATE_OP_IDR)
+                        || !strcmp (opcode_handle->opc0[i]->constraints,
+                            XGATE_OP_TRI))
+                      return opcode_handle->opc0[i];
+                  }
+
+                if (oprs[2].reg == REG_NONE)
+                  if (!strcmp (opcode_handle->opc0[i]->constraints,
+                      XGATE_OP_IDO5))
+                    return opcode_handle->opc0[i];
+              }
+          }
+        break;
+      default:
+        as_bad (_("unknown operand count"));
+        break;
+        }
+    }
+  return NULL ;
 }
 
 /* Because we are dealing with two different core that view the system
@@ -933,7 +1009,7 @@ xgate_frob_symbol (symbolS *sym)
   bfdsym = symbol_get_bfdsym (sym);
   elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym);
 
-  gas_assert(elfsym);
+  gas_assert (elfsym);
 
   /* Mark the symbol as being *from XGATE  */
   elfsym->internal_elf_sym.st_target_internal = 1;
@@ -948,7 +1024,7 @@ xgate_get_operands (char *line, s_operand oprs[])
 
   /* If there are no operands, then it must be inherent.  */
   if (*line == 0 || *line == '\n' || *line == '\r')
-    return XG_INH;
+    return 0;
 
   for (num_operands = 0; strlen (line) && (num_operands < MAX_NUM_OPERANDS);
        num_operands++)
@@ -973,55 +1049,14 @@ xgate_get_operands (char *line, s_operand oprs[])
          line++;
        }
     }
-
   if (num_operands > MAX_NUM_OPERANDS)
     return 0;
-
-  switch (num_operands)
-    {
-    case 1:
-      if (oprs[0].reg >= REG_R0 && oprs[0].reg <= REG_R7)
-       return XG_R;
-      if (oprs[0].reg == REG_NONE)
-       return XG_I;
-      break;
-    case 2:
-      if (oprs[0].reg >= REG_R0 && oprs[0].reg <= REG_R7)
-       {
-         if (oprs[1].reg >= REG_R0 && oprs[1].reg <= REG_R7)
-           return XG_R_R;
-         if (oprs[1].reg == REG_CCR)
-           return XG_R_C;
-         if (oprs[1].reg == REG_PC)
-           return XG_R_P;
-         if (oprs[1].reg == REG_NONE)
-           return XG_R_I;
-       }
-      if (oprs[0].reg == REG_CCR)
-       return XG_C_R;
-      break;
-    case 3:
-      if (oprs[0].reg >= REG_R0 && oprs[0].reg <= REG_R7)
-       {
-         if (oprs[1].reg >= REG_R0 && oprs[1].reg <= REG_R7)
-           {
-             if (oprs[2].reg >= REG_R0 && oprs[2].reg <= REG_R7)
-               return XG_R_R_R;
-             if (oprs[2].reg >= REG_NONE)
-               return XG_R_R_I;
-           }
-       }
-      break;
-    default:
-      as_bad (_("unknown operand format"));
-      break;
-    }
-
-  return 0;
+  return num_operands;
 }
 
 /* reg_name_search() finds the register number given its name.
    Returns the register number or REG_NONE on failure.  */
+
 static register_id
 reg_name_search (char *name)
 {
@@ -1051,7 +1086,7 @@ reg_name_search (char *name)
 /* Parse operand modifiers such as inc/dec/hi/low.  */
 
 static op_modifiers
-xgate_determine_modifiers(char **line)
+xgate_determine_modifiers (char **line)
 {
   char *local_line = line[0];
 
@@ -1120,7 +1155,7 @@ xgate_scan_operands (struct xgate_opcode *opcode, s_operand oprs[])
       ++op;
       bin = xgate_apply_operand (operand, &oper_mask, bin, operand_bit_length);
 
-      if(first_operand_equals_second)
+      if (first_operand_equals_second)
        bin = xgate_apply_operand (operand, &oper_mask, bin,
                                   operand_bit_length);
       /* Parse second operand.  */
@@ -1158,7 +1193,8 @@ xgate_scan_operands (struct xgate_opcode *opcode, s_operand oprs[])
     {
       bfd_putl16 (bin, frag);
     }
-  else if ((opcode->sh_format & XG_PCREL))
+  else if ( !strcmp (opcode->constraints, XGATE_OP_REL9)
+      || !strcmp (opcode->constraints, XGATE_OP_REL10))
     {
       /* Write our data to a frag for further processing.  */
       bfd_putl16 (opcode->bin_opcode, frag);
@@ -1199,9 +1235,9 @@ xgate_parse_operand (struct xgate_opcode *opcode,
       if (operand.reg == REG_NONE)
        as_bad (_(": expected register name r0-r7 ") );
       op_mask = operand.reg;
-      if(operand.mod == MOD_POSTINC)
+      if (operand.mod == MOD_POSTINC)
        pp_fix = INCREMENT;
-      if(operand.mod == MOD_PREDEC)
+      if (operand.mod == MOD_PREDEC)
        pp_fix = DECREMENT;
       op_mask <<= 2;
       op_mask |= pp_fix;
@@ -1300,10 +1336,10 @@ xgate_parse_operand (struct xgate_opcode *opcode,
        {
          if (*op_constraint == '9')
            fix_new_exp (frag_now, where, 2, &operand.exp, TRUE,
-                        R_XGATE_PCREL_9);
+                        BFD_RELOC_XGATE_PCREL_9);
          else if (*op_constraint == 'a')
            fix_new_exp (frag_now, where, 2, &operand.exp, TRUE,
-                        R_XGATE_PCREL_10);
+                        BFD_RELOC_XGATE_PCREL_10);
        }
       else
        as_fatal (_("Operand `%x' not recognized in fixup8."),
This page took 0.042032 seconds and 4 git commands to generate.