merge from gcc
[deliverable/binutils-gdb.git] / opcodes / i386-gen.c
index bdd4ae65d234720ceef1ddcd499c0080c2ea9584..a54d633c5196a6c2785afdf5393d403932d619c2 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright 2007, 2008  Free Software Foundation, Inc.
+/* Copyright 2007, 2008, 2009
+   Free Software Foundation, Inc.
 
    This file is part of the GNU opcodes library.
 
@@ -39,14 +40,14 @@ typedef struct initializer
   const char *init;
 } initializer;
 
-static initializer cpu_flag_init [] =
+static initializer cpu_flag_init[] =
 {
   { "CPU_UNKNOWN_FLAGS",
     "unknown" },
   { "CPU_GENERIC32_FLAGS",
     "Cpu186|Cpu286|Cpu386" },
   { "CPU_GENERIC64_FLAGS", 
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuLM" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuMMX|CpuSSE|CpuSSE2|CpuLM" },
   { "CPU_NONE_FLAGS",
    "0" },
   { "CPU_I186_FLAGS",
@@ -58,31 +59,45 @@ static initializer cpu_flag_init [] =
   { "CPU_I486_FLAGS",
     "Cpu186|Cpu286|Cpu386|Cpu486" },
   { "CPU_I586_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu387" },
   { "CPU_I686_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687" },
   { "CPU_P2_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuMMX" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687|CpuMMX" },
   { "CPU_P3_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuMMX|CpuSSE" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|Cpu387|Cpu687|CpuMMX|CpuSSE" },
   { "CPU_P4_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuMMX|CpuSSE|CpuSSE2" },
   { "CPU_NOCONA_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuLM" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuLM" },
   { "CPU_CORE_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3" },
   { "CPU_CORE2_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuP4|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuLM" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuLM" },
+  { "CPU_COREI7_FLAGS",
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuClflush|Cpu387|Cpu687|CpuFISTTP|CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuRdtscp|CpuLM" },
   { "CPU_K6_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuK6|CpuMMX" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuSYSCALL|Cpu387|CpuMMX" },
   { "CPU_K6_2_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuK6|CpuMMX|Cpu3dnow" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|CpuSYSCALL|Cpu387|CpuMMX|Cpu3dnow" },
   { "CPU_ATHLON_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuMMX|Cpu3dnow|Cpu3dnowA" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|Cpu387|Cpu687|CpuMMX|Cpu3dnow|Cpu3dnowA" },
   { "CPU_K8_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuK8|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuLM" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuLM" },
   { "CPU_AMDFAM10_FLAGS",
-    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuK6|CpuK8|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM" },
+    "Cpu186|Cpu286|Cpu386|Cpu486|Cpu586|Cpu686|CpuSYSCALL|CpuRdtscp|Cpu387|Cpu687|CpuFISTTP|CpuMMX|Cpu3dnow|Cpu3dnowA|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuLM" },
+  { "CPU_8087_FLAGS",
+    "Cpu8087" },
+  { "CPU_287_FLAGS",
+    "Cpu287" },
+  { "CPU_387_FLAGS",
+    "Cpu387" },
+  { "CPU_ANY87_FLAGS",
+    "Cpu8087|Cpu287|Cpu387|Cpu687|CpuFISTTP" },
+  { "CPU_CLFLUSH_FLAGS",
+    "CpuClflush" },
+  { "CPU_SYSCALL_FLAGS",
+    "CpuSYSCALL" },
   { "CPU_MMX_FLAGS",
     "CpuMMX" },
   { "CPU_SSE_FLAGS",
@@ -97,6 +112,8 @@ static initializer cpu_flag_init [] =
     "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1" },
   { "CPU_SSE4_2_FLAGS",
     "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2" },
+  { "CPU_ANY_SSE_FLAGS",
+    "CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuSSE4a|CpuAVX" },
   { "CPU_VMX_FLAGS",
     "CpuVMX" },
   { "CPU_SMX_FLAGS",
@@ -109,8 +126,12 @@ static initializer cpu_flag_init [] =
     "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuPCLMUL" },
   { "CPU_FMA_FLAGS",
     "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA" },
+  { "CPU_FMA4_FLAGS",
+    "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX|CpuFMA4" },
   { "CPU_MOVBE_FLAGS",
     "CpuMovbe" },
+  { "CPU_RDTSCP_FLAGS",
+    "CpuRdtscp" },
   { "CPU_EPT_FLAGS",
     "CpuEPT" },
   { "CPU_3DNOW_FLAGS",
@@ -125,13 +146,13 @@ static initializer cpu_flag_init [] =
     "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a" },
   { "CPU_ABM_FLAGS",
     "CpuABM" },
-  { "CPU_SSE5_FLAGS",
-    "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSE4a|CpuABM|CpuSSE5"},
   { "CPU_AVX_FLAGS",
     "CpuMMX|CpuSSE|CpuSSE2|CpuSSE3|CpuSSSE3|CpuSSE4_1|CpuSSE4_2|CpuAVX" },
+  { "CPU_ANY_AVX_FLAGS",
+    "CpuAVX" },
 };
 
-static initializer operand_type_init [] =
+static initializer operand_type_init[] =
 {
   { "OPERAND_TYPE_NONE",
     "0" },
@@ -225,8 +246,6 @@ static initializer operand_type_init [] =
     "Imm32|Imm32S|Imm64|Disp32" },
   { "OPERAND_TYPE_IMM32_32S_64_DISP32_64",
     "Imm32|Imm32S|Imm64|Disp32|Disp64" },
-  { "OPERAND_TYPE_VEX_IMM4",
-    "VEX_Imm4" },
 };
 
 typedef struct bitfield
@@ -246,9 +265,13 @@ static bitfield cpu_flags[] =
   BITFIELD (Cpu486),
   BITFIELD (Cpu586),
   BITFIELD (Cpu686),
-  BITFIELD (CpuP4),
-  BITFIELD (CpuK6),
-  BITFIELD (CpuK8),
+  BITFIELD (CpuClflush),
+  BITFIELD (CpuSYSCALL),
+  BITFIELD (Cpu8087),
+  BITFIELD (Cpu287),
+  BITFIELD (Cpu387),
+  BITFIELD (Cpu687),
+  BITFIELD (CpuFISTTP),
   BITFIELD (CpuMMX),
   BITFIELD (CpuSSE),
   BITFIELD (CpuSSE2),
@@ -258,7 +281,6 @@ static bitfield cpu_flags[] =
   BITFIELD (CpuSSE4_2),
   BITFIELD (CpuAVX),
   BITFIELD (CpuSSE4a),
-  BITFIELD (CpuSSE5),
   BITFIELD (Cpu3dnow),
   BITFIELD (Cpu3dnowA),
   BITFIELD (CpuPadLock),
@@ -270,9 +292,11 @@ static bitfield cpu_flags[] =
   BITFIELD (CpuAES),
   BITFIELD (CpuPCLMUL),
   BITFIELD (CpuFMA),
+  BITFIELD (CpuFMA4),  
   BITFIELD (CpuLM),
   BITFIELD (CpuMovbe),
   BITFIELD (CpuEPT),
+  BITFIELD (CpuRdtscp),
   BITFIELD (Cpu64),
   BITFIELD (CpuNo64),
 #ifdef CpuUnused
@@ -284,6 +308,7 @@ static bitfield opcode_modifiers[] =
 {
   BITFIELD (D),
   BITFIELD (W),
+  BITFIELD (S),
   BITFIELD (Modrm),
   BITFIELD (ShortForm),
   BITFIELD (Jump),
@@ -318,9 +343,6 @@ static bitfield opcode_modifiers[] =
   BITFIELD (NoRex64),
   BITFIELD (Rex64),
   BITFIELD (Ugh),
-  BITFIELD (Drex),
-  BITFIELD (Drexv),
-  BITFIELD (Drexc),
   BITFIELD (Vex),
   BITFIELD (Vex256),
   BITFIELD (VexNDS),
@@ -386,13 +408,11 @@ static bitfield operand_types[] =
   BITFIELD (Ymmword),
   BITFIELD (Unspecified),
   BITFIELD (Anysize),
-  BITFIELD (Vex_Imm4),
 #ifdef OTUnused
   BITFIELD (OTUnused),
 #endif
 };
 
-static int lineno;
 static const char *filename;
 
 static int
@@ -419,7 +439,8 @@ static void
 process_copyright (FILE *fp)
 {
   fprintf (fp, "/* This file is automatically generated by i386-gen.  Do not edit!  */\n\
-/* Copyright 2007, 2008  Free Software Foundation, Inc.\n\
+/* Copyright 2007, 2008, 2009\n\
+   Free Software Foundation, Inc.\n\
 \n\
    This file is part of the GNU opcodes library.\n\
 \n\
@@ -493,12 +514,16 @@ next_field (char *str, char sep, char **next, char *last)
 }
 
 static void
-set_bitfield (const char *f, bitfield *array, unsigned int size)
+set_bitfield (const char *f, bitfield *array, unsigned int size, int lineno)
 {
   unsigned int i;
 
-  if (strcmp (f, "CpuSledgehammer") == 0)
-    f= "CpuK8";
+  if (strcmp (f, "CpuFP") == 0)
+    {
+      set_bitfield("Cpu387", array, size, lineno);
+      set_bitfield("Cpu287", array, size, lineno);
+      f = "Cpu8087";
+    }
   else if (strcmp (f, "Mmword") == 0)
     f= "Qword";
   else if (strcmp (f, "Oword") == 0)
@@ -511,7 +536,10 @@ set_bitfield (const char *f, bitfield *array, unsigned int size)
        return;
       }
 
-  fail (_("%s: %d: Unknown bitfield: %s\n"), filename, lineno, f);
+  if (lineno != -1)
+    fail (_("%s: %d: Unknown bitfield: %s\n"), filename, lineno, f);
+  else
+    fail (_("Unknown bitfield: %s\n"), f);
 }
 
 static void
@@ -540,7 +568,8 @@ output_cpu_flags (FILE *table, bitfield *flags, unsigned int size,
 
 static void
 process_i386_cpu_flag (FILE *table, char *flag, int macro,
-                      const char *comma, const char *indent)
+                      const char *comma, const char *indent,
+                      int lineno)
 {
   char *str, *next, *last;
   bitfield flags [ARRAY_SIZE (cpu_flags)];
@@ -565,7 +594,7 @@ process_i386_cpu_flag (FILE *table, char *flag, int macro,
        {
          str = next_field (next, '|', &next, last);
          if (str)
-           set_bitfield (str, flags, ARRAY_SIZE (flags));
+           set_bitfield (str, flags, ARRAY_SIZE (flags), lineno);
        }
     }
 
@@ -591,7 +620,7 @@ output_opcode_modifier (FILE *table, bitfield *modifier, unsigned int size)
 }
 
 static void
-process_i386_opcode_modifier (FILE *table, char *mod)
+process_i386_opcode_modifier (FILE *table, char *mod, int lineno)
 {
   char *str, *next, *last;
   bitfield modifiers [ARRAY_SIZE (opcode_modifiers)];
@@ -606,7 +635,7 @@ process_i386_opcode_modifier (FILE *table, char *mod)
        {
          str = next_field (next, '|', &next, last);
          if (str)
-           set_bitfield (str, modifiers, ARRAY_SIZE (modifiers));
+           set_bitfield (str, modifiers, ARRAY_SIZE (modifiers), lineno);
        }
     }
   output_opcode_modifier (table, modifiers, ARRAY_SIZE (modifiers));
@@ -638,7 +667,7 @@ output_operand_type (FILE *table, bitfield *types, unsigned int size,
 
 static void
 process_i386_operand_type (FILE *table, char *op, int macro,
-                          const char *indent)
+                          const char *indent, int lineno)
 {
   char *str, *next, *last;
   bitfield types [ARRAY_SIZE (operand_types)];
@@ -653,7 +682,7 @@ process_i386_operand_type (FILE *table, char *op, int macro,
        {
          str = next_field (next, '|', &next, last);
          if (str)
-           set_bitfield (str, types, ARRAY_SIZE (types));
+           set_bitfield (str, types, ARRAY_SIZE (types), lineno);
        }
     }
   output_operand_type (table, types, ARRAY_SIZE (types), macro,
@@ -662,7 +691,7 @@ process_i386_operand_type (FILE *table, char *op, int macro,
 
 static void
 output_i386_opcode (FILE *table, const char *name, char *str,
-                   char *last)
+                   char *last, int lineno)
 {
   unsigned int i;
   char *operands, *base_opcode, *extension_opcode, *opcode_length;
@@ -733,9 +762,9 @@ output_i386_opcode (FILE *table, const char *name, char *str,
           name, operands, base_opcode, extension_opcode,
           opcode_length);
 
-  process_i386_cpu_flag (table, cpu_flags, 0, ",", "    ");
+  process_i386_cpu_flag (table, cpu_flags, 0, ",", "    ", lineno);
 
-  process_i386_opcode_modifier (table, opcode_modifier);
+  process_i386_opcode_modifier (table, opcode_modifier, lineno);
 
   fprintf (table, "    { ");
 
@@ -744,7 +773,7 @@ output_i386_opcode (FILE *table, const char *name, char *str,
       if (operand_types[i] == NULL || *operand_types[i] == '0')
        {
          if (i == 0)
-           process_i386_operand_type (table, "0", 0, "\t  ");
+           process_i386_operand_type (table, "0", 0, "\t  ", lineno);
          break;
        }
 
@@ -752,7 +781,7 @@ output_i386_opcode (FILE *table, const char *name, char *str,
        fprintf (table, ",\n      ");
 
       process_i386_operand_type (table, operand_types[i], 0,
-                                "\t  ");
+                                "\t  ", lineno);
     }
   fprintf (table, " } },\n");
 }
@@ -762,6 +791,7 @@ struct opcode_hash_entry
   struct opcode_hash_entry *next;
   char *name;
   char *opcode;
+  int lineno;
 };
 
 /* Calculate the hash value of an opcode hash entry P.  */
@@ -794,6 +824,7 @@ process_i386_opcodes (FILE *table)
   htab_t opcode_hash_table;
   struct opcode_hash_entry **opcode_array;
   unsigned int opcode_array_size = 1024;
+  int lineno = 0;
 
   filename = "i386-opc.tbl";
   fp = fopen (filename, "r");
@@ -870,6 +901,7 @@ process_i386_opcodes (FILE *table)
          opcode_array[i]->next = NULL;
          opcode_array[i]->name = xstrdup (name);
          opcode_array[i]->opcode = xstrdup (str);
+         opcode_array[i]->lineno = lineno;
          *hash_slot = opcode_array[i];
          i++;
        }
@@ -884,6 +916,7 @@ process_i386_opcodes (FILE *table)
          (*entry)->next = NULL;
          (*entry)->name = (*hash_slot)->name;
          (*entry)->opcode = xstrdup (str);
+         (*entry)->lineno = lineno;
        }
     }
 
@@ -894,8 +927,9 @@ process_i386_opcodes (FILE *table)
        {
          name = next->name;
          str = next->opcode;
+         lineno = next->lineno;
          last = str + strlen (str);
-         output_i386_opcode (table, name, str, last);
+         output_i386_opcode (table, name, str, last, lineno);
        }
     }
 
@@ -903,12 +937,12 @@ process_i386_opcodes (FILE *table)
 
   fprintf (table, "  { NULL, 0, 0, 0, 0,\n");
 
-  process_i386_cpu_flag (table, "0", 0, ",", "    ");
+  process_i386_cpu_flag (table, "0", 0, ",", "    ", -1);
 
-  process_i386_opcode_modifier (table, "0");
+  process_i386_opcode_modifier (table, "0", -1);
  
   fprintf (table, "    { ");
-  process_i386_operand_type (table, "0", 0, "\t  ");
+  process_i386_operand_type (table, "0", 0, "\t  ", -1);
   fprintf (table, " } }\n");
 
   fprintf (table, "};\n");
@@ -922,6 +956,7 @@ process_i386_registers (FILE *table)
   char *str, *p, *last;
   char *reg_name, *reg_type, *reg_flags, *reg_num;
   char *dw2_32_num, *dw2_64_num;
+  int lineno = 0;
 
   filename = "i386-reg.tbl";
   fp = fopen (filename, "r");
@@ -976,7 +1011,7 @@ process_i386_registers (FILE *table)
 
       fprintf (table, "  { \"%s\",\n    ", reg_name);
 
-      process_i386_operand_type (table, reg_type, 0, "\t");
+      process_i386_operand_type (table, reg_type, 0, "\t", lineno);
 
       /* Find 32-bit Dwarf2 register number.  */
       dw2_32_num = next_field (str, ',', &str, last);
@@ -1012,7 +1047,7 @@ process_i386_initializers (void)
     {
       fprintf (fp, "\n#define %s \\\n", cpu_flag_init[i].name);
       init = xstrdup (cpu_flag_init[i].init);
-      process_i386_cpu_flag (fp, init, 1, "", "  ");
+      process_i386_cpu_flag (fp, init, 1, "", "  ", -1);
       free (init);
     }
 
@@ -1020,7 +1055,7 @@ process_i386_initializers (void)
     {
       fprintf (fp, "\n\n#define %s \\\n  ", operand_type_init[i].name);
       init = xstrdup (operand_type_init[i].init);
-      process_i386_operand_type (fp, init, 1, "      ");
+      process_i386_operand_type (fp, init, 1, "      ", -1);
       free (init);
     }
   fprintf (fp, "\n");
This page took 0.029065 seconds and 4 git commands to generate.