Correct d10v sanitization errors.
[deliverable/binutils-gdb.git] / opcodes / i386-dis.c
index e30b7fee699df35f4671f067169d8c1c5a0304e5..f5c3aaa6733b5e69066709f89c7834b94f1138e3 100644 (file)
@@ -1,5 +1,5 @@
 /* Print i386 instructions for GDB, the GNU debugger.
-   Copyright (C) 1988, 1989, 1991 Free Software Foundation, Inc.
+   Copyright (C) 1988, 89, 91, 93, 94, 95, 1996 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
@@ -15,7 +15,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /*
  * 80386 instruction printer by Pace Willisson (pace@prep.ai.mit.edu)
@@ -33,12 +33,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  */
 
 #include "dis-asm.h"
+#include "sysdep.h"
 
 #define MAXLEN 20
 
 #include <setjmp.h>
 
-struct private
+struct dis_private
 {
   /* Points to first byte not fetched.  */
   bfd_byte *max_fetched;
@@ -51,7 +52,7 @@ struct private
    to ADDR (exclusive) are valid.  Returns 1 for success, longjmps
    on error.  */
 #define FETCH_DATA(info, addr) \
-  ((addr) <= ((struct private *)(info->private_data))->max_fetched \
+  ((addr) <= ((struct dis_private *)(info->private_data))->max_fetched \
    ? 1 : fetch_data ((info), (addr)))
 
 static int
@@ -60,7 +61,7 @@ fetch_data (info, addr)
      bfd_byte *addr;
 {
   int status;
-  struct private *priv = (struct private *)info->private_data;
+  struct dis_private *priv = (struct dis_private *)info->private_data;
   bfd_vma start = priv->insn_start + (priv->max_fetched - priv->the_buffer);
 
   status = (*info->read_memory_func) (start,
@@ -138,13 +139,19 @@ fetch_data (info, addr)
 #define fs OP_REG, fs_reg
 #define gs OP_REG, gs_reg
 
-int OP_E(), OP_indirE(), OP_G(), OP_I(), OP_sI(), OP_REG();
-int OP_J(), OP_SEG();
-int OP_DIR(), OP_OFF(), OP_DSSI(), OP_ESDI(), OP_ONE(), OP_C();
-int OP_D(), OP_T(), OP_rm();
+typedef int op_rtn PARAMS ((int bytemode, int aflag, int dflag));
 
-static void dofloat (), putop (), append_prefix (), set_op ();
-static int get16 (), get32 ();
+static op_rtn OP_E, OP_G, OP_I, OP_indirE, OP_sI, OP_REG, OP_J, OP_DIR, OP_OFF;
+static op_rtn OP_ESDI, OP_DSSI, OP_SEG, OP_ONE, OP_C, OP_D, OP_T, OP_rm, OP_ST;
+static op_rtn OP_STi;
+
+static void append_prefix PARAMS ((void));
+static void set_op PARAMS ((int op));
+static void putop PARAMS ((char *template, int aflag, int dflag));
+static void dofloat PARAMS ((int aflag, int dflag));
+static int get16 PARAMS ((void));
+static int get32 PARAMS ((void));
+static void ckprefix PARAMS ((void));
 
 #define b_mode 1
 #define v_mode 2
@@ -204,21 +211,22 @@ static int get16 (), get32 ();
 #define GRP6  NULL, NULL, 13
 #define GRP7 NULL, NULL, 14
 #define GRP8 NULL, NULL, 15
+#define GRP9 NULL, NULL, 16
 
 #define FLOATCODE 50
 #define FLOAT NULL, NULL, FLOATCODE
 
 struct dis386 {
   char *name;
-  int (*op1)();
+  op_rtn *op1;
   int bytemode1;
-  int (*op2)();
+  op_rtn *op2;
   int bytemode2;
-  int (*op3)();
+  op_rtn *op3;
   int bytemode3;
 };
 
-struct dis386 dis386[] = {
+static struct dis386 dis386[] = {
   /* 00 */
   { "addb",    Eb, Gb },
   { "addS",    Ev, Gv },
@@ -346,23 +354,23 @@ struct dis386 dis386[] = {
   { "outsb",   indirDX, Xb },
   { "outsS",   indirDX, Xv },
   /* 70 */
-  { "jo",              Jb },
+  { "jo",      Jb },
   { "jno",     Jb },
-  { "jb",              Jb },
+  { "jb",      Jb },
   { "jae",     Jb },
-  { "je",              Jb },
+  { "je",      Jb },
   { "jne",     Jb },
   { "jbe",     Jb },
-  { "ja",              Jb },
+  { "ja",      Jb },
   /* 78 */
-  { "js",              Jb },
+  { "js",      Jb },
   { "jns",     Jb },
-  { "jp",              Jb },
+  { "jp",      Jb },
   { "jnp",     Jb },
-  { "jl",              Jb },
+  { "jl",      Jb },
   { "jnl",     Jb },
   { "jle",     Jb },
-  { "jg",              Jb },
+  { "jg",      Jb },
   /* 80 */
   { GRP1b },
   { GRP1S },
@@ -415,8 +423,8 @@ struct dis386 dis386[] = {
   { "stosS",   Yv, eAX },
   { "lodsb",   AL, Xb },
   { "lodsS",   eAX, Xv },
-  { "scasb",   AL, Xb },
-  { "scasS",   eAX, Xv },
+  { "scasb",   AL, Yb },
+  { "scasS",   eAX, Yv },
   /* b0 */
   { "movb",    AL, Ib },
   { "movb",    CL, Ib },
@@ -509,7 +517,7 @@ struct dis386 dis386[] = {
   { GRP5 },
 };
 
-struct dis386 dis386_twobyte[] = {
+static struct dis386 dis386_twobyte[] = {
   /* 00 */
   { GRP6 },
   { GRP7 },
@@ -522,7 +530,7 @@ struct dis386 dis386_twobyte[] = {
   /* 08 */
   { "invd" },
   { "wbinvd" },
-  { "(bad)" },  { "(bad)" },  
+  { "(bad)" },  { "ud2a" },  
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   /* 10 */
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
@@ -544,17 +552,17 @@ struct dis386 dis386_twobyte[] = {
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   /* 30 */
-  { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
+  { "wrmsr" },  { "rdtsc" },  { "rdmsr" },  { "rdpmc" },  
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   /* 38 */
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   /* 40 */
-  { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
-  { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
+  { "cmovo", Gv,Ev }, { "cmovno", Gv,Ev }, { "cmovb", Gv,Ev }, { "cmovae", Gv,Ev },
+  { "cmove", Gv,Ev }, { "cmovne", Gv,Ev }, { "cmovbe", Gv,Ev }, { "cmova", Gv,Ev },
   /* 48 */
-  { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
-  { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
+  { "cmovs", Gv,Ev }, { "cmovns", Gv,Ev }, { "cmovp", Gv,Ev }, { "cmovnp", Gv,Ev },
+  { "cmovl", Gv,Ev }, { "cmovge", Gv,Ev }, { "cmovle", Gv,Ev }, { "cmovg", Gv,Ev },  
   /* 50 */
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
@@ -612,7 +620,7 @@ struct dis386 dis386_twobyte[] = {
   /* a0 */
   { "pushl", fs },
   { "popl", fs },
-  { "(bad)" },
+  { "cpuid" },
   { "btS", Ev, Gv },  
   { "shldS", Ev, Gv, Ib },
   { "shldS", Ev, Gv, CL },
@@ -621,7 +629,7 @@ struct dis386 dis386_twobyte[] = {
   /* a8 */
   { "pushl", gs },
   { "popl", gs },
-  { "(bad)" },
+  { "rsm" },
   { "btsS", Ev, Gv },  
   { "shrdS", Ev, Gv, Ib },
   { "shrdS", Ev, Gv, CL },
@@ -637,7 +645,7 @@ struct dis386 dis386_twobyte[] = {
   { "movzbS", Gv, Eb },
   { "movzwS", Gv, Ew },  
   /* b8 */
-  { "(bad)" },
+  { "ud2b" },
   { "(bad)" },
   { GRP8 },
   { "btcS", Ev, Gv },  
@@ -648,8 +656,12 @@ struct dis386 dis386_twobyte[] = {
   /* c0 */
   { "xaddb", Eb, Gb },
   { "xaddS", Ev, Gv },
-  { "(bad)" },  { "(bad)" },  
-  { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
+  { "(bad)" },
+  { "(bad)" },  
+  { "(bad)" },
+  { "(bad)" },
+  { "(bad)" },
+  { GRP9 },  
   /* c8 */
   { "bswap", eAX },
   { "bswap", eCX },
@@ -679,6 +691,44 @@ struct dis386 dis386_twobyte[] = {
   { "(bad)" },  { "(bad)" },  { "(bad)" },  { "(bad)" },  
 };
 
+static const unsigned char onebyte_has_modrm[256] = {
+  1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
+  1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
+  1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
+  1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
+  1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1
+};
+
+static const unsigned char twobyte_has_modrm[256] = {
+  1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+  0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,
+  1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,
+  1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+};
+
 static char obuf[100];
 static char *obufp;
 static char scratchbuf[100];
@@ -688,7 +738,7 @@ static disassemble_info *the_info;
 static int mod;
 static int rm;
 static int reg;
-static void oappend ();
+static void oappend PARAMS ((char *s));
 
 static char *names32[]={
   "%eax","%ecx","%edx","%ebx", "%esp","%ebp","%esi","%edi",
@@ -702,8 +752,11 @@ static char *names8[] = {
 static char *names_seg[] = {
   "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
 };
+static char *index16[] = {
+  "bx+si","bx+di","bp+si","bp+di","si","di","bp","bx"
+};
 
-struct dis386 grps[][8] = {
+static struct dis386 grps[][8] = {
   /* GRP1b */
   {
     { "addb",  Eb, Ib },
@@ -879,6 +932,17 @@ struct dis386 grps[][8] = {
     { "btsS",  Ev, Ib },
     { "btrS",  Ev, Ib },
     { "btcS",  Ev, Ib },
+  },
+  /* GRP9 */
+  {
+    { "(bad)" },
+    { "cmpxchg8b", Ev },
+    { "(bad)" },
+    { "(bad)" },
+    { "(bad)" },
+    { "(bad)" },
+    { "(bad)" },
+    { "(bad)" },
   }
 };
 
@@ -949,9 +1013,6 @@ ckprefix ()
     }
 }
 
-static int dflag;
-static int aflag;              
-
 static char op1out[100], op2out[100], op3out[100];
 static int op_address[3], op_ad, op_index[3];
 static int start_pc;
@@ -966,18 +1027,34 @@ static int start_pc;
  * The function returns the length of this instruction in bytes.
  */
 
+int print_insn_x86 PARAMS ((bfd_vma pc, disassemble_info *info, int aflag,
+                           int dflag));
 int
 print_insn_i386 (pc, info)
      bfd_vma pc;
      disassemble_info *info;
+{
+  if (info->mach == bfd_mach_i386_i386)
+    print_insn_x86 (pc, info, 1, 1);
+  else if (info->mach == bfd_mach_i386_i8086)
+    print_insn_x86 (pc, info, 0, 0);
+  else
+    abort ();
+}
+
+int
+print_insn_x86 (pc, info, aflag, dflag)
+     bfd_vma pc;
+     disassemble_info *info;
 {
   struct dis386 *dp;
   int i;
   int enter_instruction;
   char *first, *second, *third;
   int needcomma;
-  
-  struct private priv;
+  unsigned char need_modrm;
+
+  struct dis_private priv;
   bfd_byte *inbuf = priv.the_buffer;
 
   info->private_data = (PTR) &priv;
@@ -1024,10 +1101,6 @@ print_insn_i386 (pc, info)
       return (1);
     }
   
-  /* these would be initialized to 0 if disassembling for 8086 or 286 */
-  dflag = 1;
-  aflag = 1;
-  
   if (prefixes & PREFIX_DATA)
     dflag ^= 1;
   
@@ -1041,40 +1114,48 @@ print_insn_i386 (pc, info)
     {
       FETCH_DATA (info, codep + 2);
       dp = &dis386_twobyte[*++codep];
+      need_modrm = twobyte_has_modrm[*codep];
     }
   else
-    dp = &dis386[*codep];
+    {
+      dp = &dis386[*codep];
+      need_modrm = onebyte_has_modrm[*codep];
+    }
   codep++;
-  FETCH_DATA (info, codep + 1);
-  mod = (*codep >> 6) & 3;
-  reg = (*codep >> 3) & 7;
-  rm = *codep & 7;
-  
+
+  if (need_modrm)
+    {
+      FETCH_DATA (info, codep + 1);
+      mod = (*codep >> 6) & 3;
+      reg = (*codep >> 3) & 7;
+      rm = *codep & 7;
+    }
+
   if (dp->name == NULL && dp->bytemode1 == FLOATCODE)
     {
-      dofloat ();
+      dofloat (aflag, dflag);
     }
   else
     {
       if (dp->name == NULL)
        dp = &grps[dp->bytemode1][reg];
       
-      putop (dp->name);
+      putop (dp->name, aflag, dflag);
       
       obufp = op1out;
       op_ad = 2;
       if (dp->op1)
-       (*dp->op1)(dp->bytemode1);
+       (*dp->op1)(dp->bytemode1, aflag, dflag);
       
       obufp = op2out;
       op_ad = 1;
       if (dp->op2)
-       (*dp->op2)(dp->bytemode2);
+       (*dp->op2)(dp->bytemode2, aflag, dflag);
       
       obufp = op3out;
       op_ad = 0;
       if (dp->op3)
-       (*dp->op3)(dp->bytemode3);
+       (*dp->op3)(dp->bytemode3, aflag, dflag);
     }
   
   obufp = obuf + strlen (obuf);
@@ -1106,7 +1187,7 @@ print_insn_i386 (pc, info)
   if (*first)
     {
       if (op_index[0] != -1)
-       print_address (op_address[op_index[0]], info->stream);
+       (*info->print_address_func) (op_address[op_index[0]], info);
       else
        (*info->fprintf_func) (info->stream, "%s", first);
       needcomma = 1;
@@ -1116,7 +1197,7 @@ print_insn_i386 (pc, info)
       if (needcomma)
        (*info->fprintf_func) (info->stream, ",");
       if (op_index[1] != -1)
-       print_address (op_address[op_index[1]], info->stream);
+       (*info->print_address_func) (op_address[op_index[1]], info);
       else
        (*info->fprintf_func) (info->stream, "%s", second);
       needcomma = 1;
@@ -1126,14 +1207,14 @@ print_insn_i386 (pc, info)
       if (needcomma)
        (*info->fprintf_func) (info->stream, ",");
       if (op_index[2] != -1)
-       print_address (op_address[op_index[2]], info->stream);
+       (*info->print_address_func) (op_address[op_index[2]], info);
       else
        (*info->fprintf_func) (info->stream, "%s", third);
     }
   return (codep - inbuf);
 }
 
-char *float_mem[] = {
+static char *float_mem[] = {
   /* d8 */
   "fadds",
   "fmuls",
@@ -1210,7 +1291,6 @@ char *float_mem[] = {
 
 #define ST OP_ST, 0
 #define STi OP_STi, 0
-int OP_ST(), OP_STi();
 
 #define FGRPd9_2 NULL, NULL, 0
 #define FGRPd9_4 NULL, NULL, 1
@@ -1222,7 +1302,7 @@ int OP_ST(), OP_STi();
 #define FGRPde_3 NULL, NULL, 7
 #define FGRPdf_4 NULL, NULL, 8
 
-struct dis386 float_reg[][8] = {
+static struct dis386 float_reg[][8] = {
   /* d8 */
   {
     { "fadd",  ST, STi },
@@ -1247,10 +1327,10 @@ struct dis386 float_reg[][8] = {
   },
   /* da */
   {
-    { "(bad)" },
-    { "(bad)" },
-    { "(bad)" },
-    { "(bad)" },
+    { "fcmovb",        ST, STi },
+    { "fcmove",        ST, STi },
+    { "fcmovbe",ST, STi },
+    { "fcmovu",        ST, STi },
     { "(bad)" },
     { FGRPda_5 },
     { "(bad)" },
@@ -1258,13 +1338,13 @@ struct dis386 float_reg[][8] = {
   },
   /* db */
   {
-    { "(bad)" },
-    { "(bad)" },
-    { "(bad)" },
-    { "(bad)" },
+    { "fcmovnb",ST, STi },
+    { "fcmovne",ST, STi },
+    { "fcmovnbe",ST, STi },
+    { "fcmovnu",ST, STi },
     { FGRPdb_4 },
-    { "(bad)" },
-    { "(bad)" },
+    { "fucomi",        ST, STi },
+    { "fcomi", ST, STi },
     { "(bad)" },
   },
   /* dc */
@@ -1307,14 +1387,14 @@ struct dis386 float_reg[][8] = {
     { "(bad)" },
     { "(bad)" },
     { FGRPdf_4 },
-    { "(bad)" },
-    { "(bad)" },
+    { "fucomip",ST, STi },
+    { "fcomip", ST, STi },
     { "(bad)" },
   },
 };
 
 
-char *fgrps[][8] = {
+static char *fgrps[][8] = {
   /* d9_2  0 */
   {
     "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
@@ -1363,7 +1443,9 @@ char *fgrps[][8] = {
 };
 
 static void
-dofloat ()
+dofloat (aflag, dflag)
+     int aflag;
+     int dflag;
 {
   struct dis386 *dp;
   unsigned char floatop;
@@ -1372,9 +1454,9 @@ dofloat ()
   
   if (mod != 3)
     {
-      putop (float_mem[(floatop - 0xd8) * 8 + reg]);
+      putop (float_mem[(floatop - 0xd8) * 8 + reg], aflag, dflag);
       obufp = op1out;
-      OP_E (v_mode);
+      OP_E (v_mode, aflag, dflag);
       return;
     }
   codep++;
@@ -1382,7 +1464,7 @@ dofloat ()
   dp = &float_reg[floatop - 0xd8][reg];
   if (dp->name == NULL)
     {
-      putop (fgrps[dp->bytemode1][rm]);
+      putop (fgrps[dp->bytemode1][rm], aflag, dflag);
       /* instruction fnstsw is only one with strange arg */
       if (floatop == 0xdf
          && FETCH_DATA (the_info, codep + 1)
@@ -1391,29 +1473,33 @@ dofloat ()
     }
   else
     {
-      putop (dp->name);
+      putop (dp->name, aflag, dflag);
       obufp = op1out;
       if (dp->op1)
-       (*dp->op1)(dp->bytemode1);
+       (*dp->op1)(dp->bytemode1, aflag, dflag);
       obufp = op2out;
       if (dp->op2)
-       (*dp->op2)(dp->bytemode2);
+       (*dp->op2)(dp->bytemode2, aflag, dflag);
     }
 }
 
 /* ARGSUSED */
-int
-OP_ST (ignore)
+static int
+OP_ST (ignore, aflag, dflag)
      int ignore;
+     int aflag;
+     int dflag;
 {
   oappend ("%st");
   return (0);
 }
 
 /* ARGSUSED */
-int
-OP_STi (ignore)
+static int
+OP_STi (ignore, aflag, dflag)
      int ignore;
+     int aflag;
+     int dflag;
 {
   sprintf (scratchbuf, "%%st(%d)", rm);
   oappend (scratchbuf);
@@ -1423,8 +1509,10 @@ OP_STi (ignore)
 
 /* capital letters in template are macros */
 static void
-putop (template)
+putop (template, aflag, dflag)
      char *template;
+     int aflag;
+     int dflag;
 {
   char *p;
   
@@ -1436,7 +1524,7 @@ putop (template)
          *obufp++ = *p;
          break;
        case 'C':               /* For jcxz/jecxz */
-         if (aflag == 0)
+         if (aflag)
            *obufp++ = 'e';
          break;
        case 'N':
@@ -1481,33 +1569,27 @@ append_prefix ()
     oappend ("%gs:");
 }
 
-int
-OP_indirE (bytemode)
+static int
+OP_indirE (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   oappend ("*");
-  OP_E (bytemode);
-  return (0);
+  return OP_E (bytemode, aflag, dflag);
 }
 
-int
-OP_E (bytemode)
+static int
+OP_E (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   int disp;
-  int havesib;
-  int base;
-  int index;
-  int scale;
-  int havebase;
-  
+
   /* skip mod/rm byte */
   codep++;
-  
-  havesib = 0;
-  havebase = 0;
-  disp = 0;
-  
+
   if (mod == 3)
     {
       switch (bytemode)
@@ -1528,90 +1610,114 @@ OP_E (bytemode)
          oappend ("<bad dis table>");
          break;
        }
-      return (0);
+      return 0;
     }
-  
+
+  disp = 0;
   append_prefix ();
-  if (rm == 4)
+
+  if (aflag) /* 32 bit address mode */
     {
-      havesib = 1;
+      int havesib;
+      int havebase;
+      int base;
+      int index;
+      int scale;
+
+      havesib = 0;
       havebase = 1;
-      FETCH_DATA (the_info, codep + 1);
-      scale = (*codep >> 6) & 3;
-      index = (*codep >> 3) & 7;
-      base = *codep & 7;
-      codep++;
-    }
-  
-  switch (mod)
-    {
-    case 0:
-      switch (rm)
+      base = rm;
+
+      if (base == 4)
        {
-       case 4:
-         /* implies havesib and havebase */
-         if (base == 5) {
-           havebase = 0;
-           disp = get32 ();
-         }
+         havesib = 1;
+         FETCH_DATA (the_info, codep + 1);
+         scale = (*codep >> 6) & 3;
+         index = (*codep >> 3) & 7;
+         base = *codep & 7;
+         codep++;
+       }
+
+      switch (mod)
+       {
+       case 0:
+         if (base == 5)
+           {
+             havebase = 0;
+             disp = get32 ();
+           }
          break;
-       case 5:
-         disp = get32 ();
+       case 1:
+         FETCH_DATA (the_info, codep + 1);
+         disp = *(char *)codep++;
          break;
-       default:
-         havebase = 1;
-         base = rm;
+       case 2:
+         disp = get32 ();
          break;
        }
-      break;
-    case 1:
-      FETCH_DATA (the_info, codep + 1);
-      disp = *(char *)codep++;
-      if (rm != 4)
-       {
-         havebase = 1;
-         base = rm;
-       }
-      break;
-    case 2:
-      disp = get32 ();
-      if (rm != 4)
+
+      if (mod != 0 || base == 5)
        {
-         havebase = 1;
-         base = rm;
+         sprintf (scratchbuf, "0x%x", disp);
+         oappend (scratchbuf);
        }
-      break;
-    }
-  
-  if (mod != 0 || rm == 5 || (havesib && base == 5))
-    {
-      sprintf (scratchbuf, "0x%x", disp);
-      oappend (scratchbuf);
-    }
-  
-  if (havebase || havesib) 
-    {
-      oappend ("(");
-      if (havebase)
-       oappend (names32[base]);
-      if (havesib) 
+
+      if (havebase || (havesib && (index != 4 || scale != 0)))
        {
-         if (index != 4) 
+         oappend ("(");
+         if (havebase)
+           oappend (names32[base]);
+         if (havesib)
            {
-             sprintf (scratchbuf, ",%s", names32[index]);
+             if (index != 4)
+               {
+                 sprintf (scratchbuf, ",%s", names32[index]);
+                 oappend (scratchbuf);
+               }
+             sprintf (scratchbuf, ",%d", 1 << scale);
              oappend (scratchbuf);
            }
-         sprintf (scratchbuf, ",%d", 1 << scale);
+         oappend (")");
+       }
+    }
+  else
+    { /* 16 bit address mode */
+      switch (mod)
+       {
+       case 0:
+         if (rm == 6)
+           disp = (short) get16 ();
+         break;
+       case 1:
+         FETCH_DATA (the_info, codep + 1);
+         disp = *(char *)codep++;
+         break;
+       case 2:
+         disp = (short) get16 ();
+         break;
+       }
+
+      if (mod != 0 || rm == 6)
+       {
+         sprintf (scratchbuf, "0x%x", disp);
          oappend (scratchbuf);
        }
-      oappend (")");
+
+      if (mod != 0 || rm != 6)
+       {
+         oappend ("(");
+         oappend (index16[rm]);
+         oappend (")");
+       }
     }
-  return (0);
+  return 0;
 }
 
-int
-OP_G (bytemode)
+static int
+OP_G (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   switch (bytemode) 
     {
@@ -1669,9 +1775,11 @@ set_op (op)
   op_address[op_ad] = op;
 }
 
-int
-OP_REG (code)
+static int
+OP_REG (code, aflag, dflag)
      int code;
+     int aflag;
+     int dflag;
 {
   char *s;
   
@@ -1705,9 +1813,11 @@ OP_REG (code)
   return (0);
 }
 
-int
-OP_I (bytemode)
+static int
+OP_I (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   int op;
   
@@ -1735,9 +1845,11 @@ OP_I (bytemode)
   return (0);
 }
 
-int
-OP_sI (bytemode)
+static int
+OP_sI (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   int op;
   
@@ -1765,9 +1877,11 @@ OP_sI (bytemode)
   return (0);
 }
 
-int
-OP_J (bytemode)
+static int
+OP_J (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   int disp;
   int mask = -1;
@@ -1802,9 +1916,11 @@ OP_J (bytemode)
 }
 
 /* ARGSUSED */
-int
-OP_SEG (dummy)
+static int
+OP_SEG (dummy, aflag, dflag)
      int dummy;
+     int aflag;
+     int dflag;
 {
   static char *sreg[] = {
     "%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
@@ -1814,9 +1930,11 @@ OP_SEG (dummy)
   return (0);
 }
 
-int
-OP_DIR (size)
+static int
+OP_DIR (size, aflag, dflag)
      int size;
+     int aflag;
+     int dflag;
 {
   int seg, offset;
   
@@ -1855,12 +1973,16 @@ OP_DIR (size)
 }
 
 /* ARGSUSED */
-int
-OP_OFF (bytemode)
+static int
+OP_OFF (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   int off;
-  
+
+  append_prefix ();
+
   if (aflag)
     off = get32 ();
   else
@@ -1872,9 +1994,11 @@ OP_OFF (bytemode)
 }
 
 /* ARGSUSED */
-int
-OP_ESDI (dummy)
-    int dummy;
+static int
+OP_ESDI (dummy, aflag, dflag)
+     int dummy;
+     int aflag;
+     int dflag;
 {
   oappend ("%es:(");
   oappend (aflag ? "%edi" : "%di");
@@ -1883,9 +2007,11 @@ OP_ESDI (dummy)
 }
 
 /* ARGSUSED */
-int
-OP_DSSI (dummy)
-    int dummy;
+static int
+OP_DSSI (dummy, aflag, dflag)
+     int dummy;
+     int aflag;
+     int dflag;
 {
   oappend ("%ds:(");
   oappend (aflag ? "%esi" : "%si");
@@ -1894,18 +2020,22 @@ OP_DSSI (dummy)
 }
 
 /* ARGSUSED */
-int
-OP_ONE (dummy)
-    int dummy;
+static int
+OP_ONE (dummy, aflag, dflag)
+     int dummy;
+     int aflag;
+     int dflag;
 {
   oappend ("1");
   return (0);
 }
 
 /* ARGSUSED */
-int
-OP_C (dummy)
-    int dummy;
+static int
+OP_C (dummy, aflag, dflag)
+     int dummy;
+     int aflag;
+     int dflag;
 {
   codep++; /* skip mod/rm */
   sprintf (scratchbuf, "%%cr%d", reg);
@@ -1914,9 +2044,11 @@ OP_C (dummy)
 }
 
 /* ARGSUSED */
-int
-OP_D (dummy)
-    int dummy;
+static int
+OP_D (dummy, aflag, dflag)
+     int dummy;
+     int aflag;
+     int dflag;
 {
   codep++; /* skip mod/rm */
   sprintf (scratchbuf, "%%db%d", reg);
@@ -1925,9 +2057,11 @@ OP_D (dummy)
 }
 
 /* ARGSUSED */
-int
-OP_T (dummy)
+static int
+OP_T (dummy, aflag, dflag)
      int dummy;
+     int aflag;
+     int dflag;
 {
   codep++; /* skip mod/rm */
   sprintf (scratchbuf, "%%tr%d", reg);
@@ -1935,9 +2069,11 @@ OP_T (dummy)
   return (0);
 }
 
-int
-OP_rm (bytemode)
+static int
+OP_rm (bytemode, aflag, dflag)
      int bytemode;
+     int aflag;
+     int dflag;
 {
   switch (bytemode) 
     {
This page took 0.036926 seconds and 4 git commands to generate.