x86: adjust/correct VFRCZ{P,S}{S,D} decoding
[deliverable/binutils-gdb.git] / opcodes / i386-dis.c
index 3133d8eee62cfee8ed054b6138ff1114bc447f8f..da5af426a424449353012de642929dd6cb680dd1 100644 (file)
@@ -1814,8 +1814,8 @@ enum
   VEX_LEN_0FXOP_08_ED,
   VEX_LEN_0FXOP_08_EE,
   VEX_LEN_0FXOP_08_EF,
-  VEX_LEN_0FXOP_09_80,
-  VEX_LEN_0FXOP_09_81
+  VEX_LEN_0FXOP_09_82_W_0,
+  VEX_LEN_0FXOP_09_83_W_0,
 };
 
 enum
@@ -1956,6 +1956,11 @@ enum
   VEX_W_0F3ACE_P_2,
   VEX_W_0F3ACF_P_2,
 
+  VEX_W_0FXOP_09_80,
+  VEX_W_0FXOP_09_81,
+  VEX_W_0FXOP_09_82,
+  VEX_W_0FXOP_09_83,
+
   EVEX_W_0F10_P_1,
   EVEX_W_0F10_P_3,
   EVEX_W_0F11_P_1,
@@ -2071,26 +2076,19 @@ enum
   EVEX_W_0F3835_P_1,
   EVEX_W_0F3835_P_2,
   EVEX_W_0F3837_P_2,
-  EVEX_W_0F3838_P_1,
-  EVEX_W_0F3839_P_1,
   EVEX_W_0F383A_P_1,
-  EVEX_W_0F3840_P_2,
   EVEX_W_0F3852_P_1,
   EVEX_W_0F3854_P_2,
-  EVEX_W_0F3855_P_2,
   EVEX_W_0F3859_P_2,
   EVEX_W_0F385A_P_2,
   EVEX_W_0F385B_P_2,
   EVEX_W_0F3862_P_2,
   EVEX_W_0F3863_P_2,
   EVEX_W_0F3866_P_2,
-  EVEX_W_0F3868_P_3,
   EVEX_W_0F3870_P_2,
-  EVEX_W_0F3871_P_2,
   EVEX_W_0F3872_P_1,
   EVEX_W_0F3872_P_2,
   EVEX_W_0F3872_P_3,
-  EVEX_W_0F3873_P_2,
   EVEX_W_0F3875_P_2,
   EVEX_W_0F387A_P_2,
   EVEX_W_0F387B_P_2,
@@ -2127,16 +2125,8 @@ enum
   EVEX_W_0F3A3F_P_2,
   EVEX_W_0F3A42_P_2,
   EVEX_W_0F3A43_P_2,
-  EVEX_W_0F3A50_P_2,
-  EVEX_W_0F3A51_P_2,
-  EVEX_W_0F3A56_P_2,
-  EVEX_W_0F3A57_P_2,
-  EVEX_W_0F3A66_P_2,
-  EVEX_W_0F3A67_P_2,
   EVEX_W_0F3A70_P_2,
-  EVEX_W_0F3A71_P_2,
   EVEX_W_0F3A72_P_2,
-  EVEX_W_0F3A73_P_2,
 };
 
 typedef void (*op_rtn) (int bytemode, int sizeflag);
@@ -7877,10 +7867,10 @@ static const struct dis386 xop_table[][256] = {
     { Bad_Opcode },
     { Bad_Opcode },
     /* 80 */
-    { VEX_LEN_TABLE (VEX_LEN_0FXOP_09_80) },
-    { VEX_LEN_TABLE (VEX_LEN_0FXOP_09_81) },
-    { "vfrczss",       { XM, EXd }, 0 },
-    { "vfrczsd",       { XM, EXq }, 0 },
+    { VEX_W_TABLE (VEX_W_0FXOP_09_80) },
+    { VEX_W_TABLE (VEX_W_0FXOP_09_81) },
+    { VEX_W_TABLE (VEX_W_0FXOP_09_82) },
+    { VEX_W_TABLE (VEX_W_0FXOP_09_83) },
     { Bad_Opcode },
     { Bad_Opcode },
     { Bad_Opcode },
@@ -9741,16 +9731,14 @@ static const struct dis386 vex_len_table[][2] = {
      { "vpcomuq",      { XM, Vex128, EXx, VPCOM }, 0 },
   },
 
-  /* VEX_LEN_0FXOP_09_80 */
+  /* VEX_LEN_0FXOP_09_82_W_0 */
   {
-    { "vfrczps",       { XM, EXxmm }, 0 },
-    { "vfrczps",       { XM, EXymmq }, 0 },
+    { "vfrczss",       { XM, EXd }, 0 },
   },
 
-  /* VEX_LEN_0FXOP_09_81 */
+  /* VEX_LEN_0FXOP_09_83_W_0 */
   {
-    { "vfrczpd",       { XM, EXxmm }, 0 },
-    { "vfrczpd",       { XM, EXymmq }, 0 },
+    { "vfrczsd",       { XM, EXq }, 0 },
   },
 };
 
@@ -10078,6 +10066,22 @@ static const struct dis386 vex_w_table[][2] = {
     { Bad_Opcode },
     { "vgf2p8affineinvqb",  { XM, Vex, EXx, Ib }, 0 },
   },
+  /* VEX_W_0FXOP_09_80 */
+  {
+    { "vfrczps",       { XM, EXx }, 0 },
+  },
+  /* VEX_W_0FXOP_09_81 */
+  {
+    { "vfrczpd",       { XM, EXx }, 0 },
+  },
+  /* VEX_W_0FXOP_09_82 */
+  {
+    { VEX_LEN_TABLE (VEX_LEN_0FXOP_09_82_W_0) },
+  },
+  /* VEX_W_0FXOP_09_83 */
+  {
+    { VEX_LEN_TABLE (VEX_LEN_0FXOP_09_83_W_0) },
+  },
 
 #include "i386-dis-evex-w.h"
 };
@@ -11490,6 +11494,11 @@ get_valid_dis386 (const struct dis386 *dp, disassemble_info *info)
       modrm.mod = (*codep >> 6) & 3;
       modrm.reg = (*codep >> 3) & 7;
       modrm.rm = *codep & 7;
+
+      /* No XOP encoding so far allows for a non-zero embedded prefix. Avoid
+        having to decode the bits for every otherwise valid encoding.  */
+      if (vex.prefix)
+       return &bad_opcode;
       break;
 
     case USE_VEX_C4_TABLE:
@@ -12626,17 +12635,18 @@ putop (const char *in_template, int sizeflag)
   const char *p;
   int alt = 0;
   int cond = 1;
-  unsigned int l = 0, len = 1;
+  unsigned int l = 0, len = 0;
   char last[4];
 
-#define SAVE_LAST(c)                   \
-  if (l < len && l < sizeof (last))    \
-    last[l++] = c;                     \
-  else                                 \
-    abort ();
-
   for (p = in_template; *p; p++)
     {
+      if (len > l)
+       {
+         if (l >= sizeof (last) || !ISUPPER (*p))
+           abort ();
+         last[l++] = *p;
+         continue;
+       }
       switch (*p)
        {
        default:
@@ -12674,7 +12684,7 @@ putop (const char *in_template, int sizeflag)
            *obufp++ = 'b';
          break;
        case 'B':
-         if (l == 0 && len == 1)
+         if (l == 0)
            {
            case_B:
              if (intel_syntax)
@@ -12682,16 +12692,8 @@ putop (const char *in_template, int sizeflag)
              if (sizeflag & SUFFIX_ALWAYS)
                *obufp++ = 'b';
            }
-         else
+         else if (l == 1 && last[0] == 'L')
            {
-             if (l != 1
-                 || len != 2
-                 || last[0] != 'L')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
-
              if (address_mode == mode_64bit
                  && !(prefixes & PREFIX_ADDR))
                {
@@ -12702,6 +12704,8 @@ putop (const char *in_template, int sizeflag)
 
              goto case_B;
            }
+         else
+           abort ();
          break;
        case 'C':
          if (intel_syntax && !alt)
@@ -12793,13 +12797,10 @@ putop (const char *in_template, int sizeflag)
            *obufp++ = 'd';
          break;
        case 'Z':
-         if (l != 0 || len != 1)
+         if (l != 0)
            {
-             if (l != 1 || len != 2 || last[0] != 'X')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
+             if (l != 1 || last[0] != 'X')
+               abort ();
              if (!need_vex || !vex.evex)
                abort ();
              if (intel_syntax
@@ -12831,11 +12832,8 @@ putop (const char *in_template, int sizeflag)
          /* Fall through.  */
          goto case_L;
        case 'L':
-         if (l != 0 || len != 1)
-           {
-             SAVE_LAST (*p);
-             break;
-           }
+         if (l != 0)
+           abort ();
        case_L:
          if (intel_syntax)
            break;
@@ -12883,7 +12881,7 @@ putop (const char *in_template, int sizeflag)
          /* Fall through.  */
          goto case_P;
        case 'P':
-         if (l == 0 && len == 1)
+         if (l == 0)
            {
            case_P:
              if (intel_syntax)
@@ -12914,14 +12912,8 @@ putop (const char *in_template, int sizeflag)
                    }
                }
            }
-         else
+         else if (l == 1 && last[0] == 'L')
            {
-             if (l != 1 || len != 2 || last[0] != 'L')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
-
              if ((prefixes & PREFIX_DATA)
                  || (rex & REX_W)
                  || (sizeflag & SUFFIX_ALWAYS))
@@ -12939,6 +12931,8 @@ putop (const char *in_template, int sizeflag)
                    }
                }
            }
+         else
+           abort ();
          break;
        case 'U':
          if (intel_syntax)
@@ -12953,7 +12947,7 @@ putop (const char *in_template, int sizeflag)
          /* Fall through.  */
          goto case_Q;
        case 'Q':
-         if (l == 0 && len == 1)
+         if (l == 0)
            {
            case_Q:
              if (intel_syntax && !alt)
@@ -12973,13 +12967,8 @@ putop (const char *in_template, int sizeflag)
                    }
                }
            }
-         else
+         else if (l == 1 && last[0] == 'L')
            {
-             if (l != 1 || len != 2 || last[0] != 'L')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
              if ((intel_syntax && need_modrm)
                  || (modrm.mod == 3 && !(sizeflag & SUFFIX_ALWAYS)))
                break;
@@ -12992,6 +12981,8 @@ putop (const char *in_template, int sizeflag)
                      || (sizeflag & SUFFIX_ALWAYS))
                *obufp++ = intel_syntax? 'd' : 'l';
            }
+         else
+           abort ();
          break;
        case 'R':
          USED_REX (REX_W);
@@ -13013,7 +13004,7 @@ putop (const char *in_template, int sizeflag)
            used_prefixes |= (prefixes & PREFIX_DATA);
          break;
        case 'V':
-         if (l == 0 && len == 1)
+         if (l == 0)
            {
              if (intel_syntax)
                break;
@@ -13025,16 +13016,8 @@ putop (const char *in_template, int sizeflag)
                  break;
                }
            }
-         else
+         else if (l == 1 && last[0] == 'L')
            {
-             if (l != 1
-                 || len != 2
-                 || last[0] != 'L')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
-
              if (rex & REX_W)
                {
                  *obufp++ = 'a';
@@ -13042,10 +13025,12 @@ putop (const char *in_template, int sizeflag)
                  *obufp++ = 's';
                }
            }
+         else
+           abort ();
          /* Fall through.  */
          goto case_S;
        case 'S':
-         if (l == 0 && len == 1)
+         if (l == 0)
            {
            case_S:
              if (intel_syntax)
@@ -13064,16 +13049,8 @@ putop (const char *in_template, int sizeflag)
                    }
                }
            }
-         else
+         else if (l == 1 && last[0] == 'L')
            {
-             if (l != 1
-                 || len != 2
-                 || last[0] != 'L')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
-
              if (address_mode == mode_64bit
                  && !(prefixes & PREFIX_ADDR))
                {
@@ -13084,13 +13061,12 @@ putop (const char *in_template, int sizeflag)
 
              goto case_S;
            }
+         else
+           abort ();
          break;
        case 'X':
-         if (l != 0 || len != 1)
-           {
-             SAVE_LAST (*p);
-             break;
-           }
+         if (l != 0)
+           abort ();
          if (need_vex
              ? vex.prefix == DATA_PREFIX_OPCODE
              : prefixes & PREFIX_DATA)
@@ -13102,15 +13078,8 @@ putop (const char *in_template, int sizeflag)
            *obufp++ = 's';
          break;
        case 'Y':
-         if (l == 0 && len == 1)
-           abort ();
-         else
+         if (l == 1 && last[0] == 'X')
            {
-             if (l != 1 || len != 2 || last[0] != 'X')
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
              if (!need_vex)
                abort ();
              if (intel_syntax
@@ -13130,9 +13099,11 @@ putop (const char *in_template, int sizeflag)
                    abort ();
                }
            }
+         else
+           abort ();
          break;
        case 'W':
-         if (l == 0 && len == 1)
+         if (l == 0)
            {
              /* operand size flag for cwtl, cbtw */
              USED_REX (REX_W);
@@ -13150,23 +13121,19 @@ putop (const char *in_template, int sizeflag)
              if (!(rex & REX_W))
                used_prefixes |= (prefixes & PREFIX_DATA);
            }
-         else
+         else if (l == 1)
            {
-             if (l != 1
-                 || len != 2
-                 || (last[0] != 'X'
-                     && last[0] != 'L'))
-               {
-                 SAVE_LAST (*p);
-                 break;
-               }
              if (!need_vex)
                abort ();
              if (last[0] == 'X')
                *obufp++ = vex.w ? 'd': 's';
-             else
+             else if (last[0] == 'L')
                *obufp++ = vex.w ? 'q': 'd';
+             else
+               abort ();
            }
+         else
+           abort ();
          break;
        case '^':
          if (intel_syntax)
@@ -13201,6 +13168,9 @@ putop (const char *in_template, int sizeflag)
            }
          break;
        }
+
+      if (len == l)
+       len = l = 0;
     }
   *obufp = 0;
   mnemonicendp = obufp;
This page took 0.035468 seconds and 4 git commands to generate.