make microblaze build with -Wwrite-strings
[deliverable/binutils-gdb.git] / gas / config / tc-xgate.c
index 752eaee8273c60621e3c9360c693236be180d5ec..70554fe028b36761ce92967051fc2b22141a743c 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-2016 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,7 +103,7 @@ 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 []);
@@ -289,7 +291,7 @@ 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;
@@ -351,7 +353,7 @@ md_begin (void)
 
   if (flag_print_opcodes)
     {
-      print_opcode_list ();
+      xgate_print_table ();
       exit (EXIT_SUCCESS);
     }
 }
@@ -467,7 +469,7 @@ valueT
 md_section_align (asection * seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
@@ -479,7 +481,7 @@ 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];
@@ -501,10 +503,10 @@ 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)
        {
@@ -552,13 +554,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);
-
                }
            }
        }
@@ -905,8 +905,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 +913,84 @@ 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
@@ -948,7 +1021,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,51 +1046,9 @@ 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.
@@ -1158,7 +1189,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);
This page took 0.026762 seconds and 4 git commands to generate.