This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Fix x86 disassembler for memory in Intel mode
- From: "H.J. Lu" <hjl at lucon dot org>
- To: Jan Beulich <jbeulich at novell dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Wed, 19 Sep 2007 10:40:14 -0700
- Subject: PATCH: Fix x86 disassembler for memory in Intel mode
- References: <20070917150332.GA17803@lucon.org> <46EEB67C.76E4.0078.0@novell.com>
On Mon, Sep 17, 2007 at 04:16:44PM +0100, Jan Beulich wrote:
> >>> "H.J. Lu" <hjl@lucon.org> 17.09.07 17:03 >>>
> >Memory address is [base + index * scale + offset] in MASM. Is there
> >way to specify [ index + offset ]? Does [ index * 1 + offset ] work
> >in MASM?
>
> Yes, that's exactly the way.
>
We currently display
0: 8b 04 05 00 00 00 00 mov eax,DWORD PTR [eax+0x0]
7: 8b 04 05 00 00 00 00 mov eax,DWORD PTR [eax+0x0]
I am checking in this patch to display
0: 8b 04 05 00 00 00 00 mov eax,DWORD PTR [eax*1+0x0]
7: 8b 04 05 00 00 00 00 mov eax,DWORD PTR [eax*1+0x0]
H.J.
----
gas/testsuite/gas/
2007-09-19 H.J. Lu <hongjiu.lu@intel.com>
* gas/i386/intelok.s: Add tests for memory without base.
* gas/i386/intelok.d: Updated.
* gas/i386/intelok.e: Likewise.
opcodes/
2007-09-19 H.J. Lu <hongjiu.lu@intel.com>
* i386-dis.c (OP_E_extended): Always display scale for
memory.
--- binutils/gas/testsuite/gas/i386/intelok.d.sib 2007-04-26 21:22:14.000000000 -0700
+++ binutils/gas/testsuite/gas/i386/intelok.d 2007-09-19 10:29:23.000000000 -0700
@@ -106,26 +106,29 @@ Disassembly of section .text:
[ ]*[0-9a-f]+: 8b 40 12[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+0x12\]
[ ]*[0-9a-f]+: 8b 04 85 02 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*4\+(0x)?2\]
[ ]*[0-9a-f]+: 8b 04 85 02 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*4\+(0x)?2\]
+[ ]*[0-9a-f]+: 8b 04 05 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*1\+(0x)?0]
+[ ]*[0-9a-f]+: 8b 04 05 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*1\+(0x)?0]
+[ ]*[0-9a-f]+: 8b 04 05 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*1\+(0x)?0]
[ ]*[0-9a-f]+: 8b 04 45 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*2\+(0x)?0]
[ ]*[0-9a-f]+: 8b 04 45 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\*2\+(0x)?0]
[ ]*[0-9a-f]+: 8b 04 8d 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[ecx\*4\+(0x)?0]
[ ]*[0-9a-f]+: 8b 04 8d 00 00 00 00[ ]+mov[ ]+eax,(DWORD PTR )?\[ecx\*4\+(0x)?0]
[ ]*[0-9a-f]+: 8b 40 01[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+(0x)?1\]
[ ]*[0-9a-f]+: 8b 40 01[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+(0x)?1\]
-[ ]*[0-9a-f]+: 8b 44 08 fb[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\-(0x)?5\]
-[ ]*[0-9a-f]+: 8b 44 08 01[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\+(0x)?1\]
-[ ]*[0-9a-f]+: 8b 44 08 0f[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\+0xf\]
+[ ]*[0-9a-f]+: 8b 44 08 fb[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\*1\-(0x)?5\]
+[ ]*[0-9a-f]+: 8b 44 08 01[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ec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DWORD PTR )?\[eax\+ecx\*1\+(0x)?1\]
[ ]*[0-9a-f]+: 8b 00[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\]
-[ ]*[0-9a-f]+: 8b 04 08[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\]
-[ ]*[0-9a-f]+: 8b 04 08[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\]
+[ ]*[0-9a-f]+: 8b 04 08[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\*1\]
+[ ]*[0-9a-f]+: 8b 04 08[ ]+mov[ ]+eax,(DWORD PTR )?\[eax\+ecx\*1\]
[ ]*[0-9a-f]+: 26 8b 00[ ]+mov[ ]+eax,(DWORD PTR )?es:\[eax\]
[ ]*[0-9a-f]+: 6a 01[ ]+push[ ]+0x1
[ ]*[0-9a-f]+: 6a ff[ ]+push[ ]+0xffffffff
--- binutils/gas/testsuite/gas/i386/intelok.e.sib 2005-03-17 04:05:24.000000000 -0800
+++ binutils/gas/testsuite/gas/i386/intelok.e 2007-09-19 10:27:36.000000000 -0700
@@ -1,8 +1,8 @@
.*: Assembler messages:
-.*:170: Warning: .* taken to mean just .*
-.*:177: Warning: Treating .* as memory reference
-.*:178: Warning: .* taken to mean just .*
-.*:178: Warning: Treating .* as memory reference
+.*:173: Warning: .* taken to mean just .*
+.*:180: Warning: Treating .* as memory reference
+.*:181: Warning: .* taken to mean just .*
.*:181: Warning: Treating .* as memory reference
-.*:182: Warning: Treating .* as memory reference
+.*:184: Warning: Treating .* as memory reference
.*:185: Warning: Treating .* as memory reference
+.*:188: Warning: Treating .* as memory reference
--- binutils/gas/testsuite/gas/i386/intelok.s.sib 2005-08-26 08:51:15.000000000 -0700
+++ binutils/gas/testsuite/gas/i386/intelok.s 2007-09-19 10:26:01.000000000 -0700
@@ -114,6 +114,9 @@ start:
mov eax, [word+eax*dword]
mov eax, word[eax*dword]
+ mov eax, [eax*1]
+ mov eax, [eax*+1]
+ mov eax, [+1*eax]
mov eax, [eax*+2]
mov eax, [+2*eax]
mov eax, [ecx*dword]
--- binutils/opcodes/i386-dis.c.sib 2007-09-14 12:23:43.000000000 -0700
+++ binutils/opcodes/i386-dis.c 2007-09-19 10:13:29.000000000 -0700
@@ -6303,12 +6303,14 @@ OP_E_extended (int bytemode, int sizefla
int havedisp;
int havesib;
int havebase;
+ int haveindex;
int base;
int index = 0;
int scale = 0;
havesib = 0;
havebase = 1;
+ haveindex = 0;
base = modrm.rm;
if (base == 4)
@@ -6323,6 +6325,7 @@ OP_E_extended (int bytemode, int sizefla
USED_REX (REX_X);
if (rex & REX_X)
index += 8;
+ haveindex = index != 4;
codep++;
}
base += add;
@@ -6357,7 +6360,7 @@ OP_E_extended (int bytemode, int sizefla
break;
}
- havedisp = havebase || (havesib && (index != 4 || scale != 0));
+ havedisp = havebase || (havesib && (haveindex || scale != 0));
if (!intel_syntax)
if (modrm.mod != 0 || (base & 7) == 5)
@@ -6388,7 +6391,7 @@ OP_E_extended (int bytemode, int sizefla
? names64[base] : names32[base]);
if (havesib)
{
- if (index != 4)
+ if (haveindex)
{
if (!intel_syntax || havebase)
{
@@ -6399,7 +6402,7 @@ OP_E_extended (int bytemode, int sizefla
&& (sizeflag & AFLAG)
? names64[index] : names32[index]);
}
- if (scale != 0 || (!intel_syntax && index != 4))
+ if (scale != 0 || haveindex)
{
*obufp++ = scale_char;
*obufp = '\0';