This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: objdump: i386 nasm-like output
On Fri, Jul 27, 2001 at 10:33:47PM +0930, Alan Modra wrote:
> None of the above. I would say your patch consists of bug fixes for
> the current intel syntax mode, and therefore you don't need a new mode
> or an `intel_nasm' variable. Unfortunately, your patch doesn't meet
> http://www.gnu.org/prep/standards_toc.html, and you have neglected to
> provide a ChangeLog entry.
Sorry about that. I sure hope it's ok now.
> I'll highlight some of the coding errors
> below, and also make some other suggestions. Please address these
> problems wherever they occur (I'm only giving you one occurrence of
> each error) and resubmit your patch.
> (...)
The patch below should have the correct syntax.
I furthermore refined the old patch a bit, in that it
(a) handles positive displacements correctly
(i.e. [bp+4] instead of [bp4])
(b) always uses square brackets instead of ()-brackets in
intel mode (exception: coprocessor, e.g. st(0) )
Greetings
Matthias
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/opcodes/ChangeLog,v
retrieving revision 1.304
diff -u -r1.304 ChangeLog
--- ChangeLog 2001/07/25 01:42:14 1.304
+++ ChangeLog 2001/07/27 16:56:12
@@ -1,3 +1,9 @@
+2001-07-27 Matthias Kramm <kramm@quiss.org>
+
+ * i386-dis.c: Change formatting conventions for architecture
+ i386:intel to better match the format of various intel i386
+ assemblers, like nasm, tasm or masm
+
2001-07-24 Alan Modra <amodra@bigpond.net.au>
* Makefile.am: Update dependencies with "make dep-am".
Index: i386-dis.c
===================================================================
RCS file: /cvs/src/src/opcodes/i386-dis.c,v
retrieving revision 1.28
diff -u -r1.28 i386-dis.c
--- i386-dis.c 2001/07/18 13:33:12 1.28
+++ i386-dis.c 2001/07/27 16:56:31
@@ -1132,29 +1132,63 @@
need to update onebyte_has_modrm or twobyte_has_modrm. */
#define MODRM_CHECK if (!need_modrm) abort ()
-static const char *names64[] = {
+static const char **names64;
+static const char **names32;
+static const char **names16;
+static const char **names8;
+static const char **names8rex;
+static const char **names_seg;
+static const char **index16;
+
+static const char *nasm_names64[] = {
+ "rax","rcx","rdx","rbx", "rsp","rbp","rsi","rdi",
+ "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
+};
+static const char *nasm_names32[] = {
+ "eax","ecx","edx","ebx", "esp","ebp","esi","edi",
+ "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"
+};
+static const char *nasm_names16[] = {
+ "ax","cx","dx","bx","sp","bp","si","di",
+ "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"
+};
+static const char *nasm_names8[] = {
+ "al","cl","dl","bl","ah","ch","dh","bh",
+};
+static const char *nasm_names8rex[] = {
+ "al","cl","dl","bl","spl", "bpl", "sil", "dil",
+ "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
+};
+static const char *nasm_names_seg[] = {
+ "es","cs","ss","ds","fs","gs","?","?",
+};
+static const char *nasm_index16[] = {
+ "bx+si","bx+di","bp+si","bp+di","si","di","bp","bx"
+};
+
+static const char *standard_names64[] = {
"%rax","%rcx","%rdx","%rbx", "%rsp","%rbp","%rsi","%rdi",
"%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
};
-static const char *names32[] = {
+static const char *standard_names32[] = {
"%eax","%ecx","%edx","%ebx", "%esp","%ebp","%esi","%edi",
"%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d"
};
-static const char *names16[] = {
+static const char *standard_names16[] = {
"%ax","%cx","%dx","%bx","%sp","%bp","%si","%di",
"%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w"
};
-static const char *names8[] = {
+static const char *standard_names8[] = {
"%al","%cl","%dl","%bl","%ah","%ch","%dh","%bh",
};
-static const char *names8rex[] = {
+static const char *standard_names8rex[] = {
"%al","%cl","%dl","%bl","%spl", "%bpl", "%sil", "%dil",
"%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
};
-static const char *names_seg[] = {
+static const char *standard_names_seg[] = {
"%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
};
-static const char *index16[] = {
+static const char *standard_index16[] = {
"%bx,%si","%bx,%di","%bp,%si","%bp,%di","%si","%di","%bp","%bx"
};
@@ -1812,6 +1846,13 @@
disassemble_info *info;
{
intel_syntax = 0;
+ names64 = standard_names64;
+ names32 = standard_names32;
+ names16 = standard_names16;
+ names8 = standard_names8;
+ names8rex = standard_names8rex;
+ names_seg = standard_names_seg;
+ index16 = standard_index16;
open_char = '(';
close_char = ')';
separator_char = ',';
@@ -1826,6 +1867,13 @@
disassemble_info *info;
{
intel_syntax = 1;
+ names64 = nasm_names64;
+ names32 = nasm_names32;
+ names16 = nasm_names16;
+ names8 = nasm_names8;
+ names8rex = nasm_names8rex;
+ names_seg = nasm_names_seg;
+ index16 = nasm_index16;
open_char = '[';
close_char = ']';
separator_char = '+';
@@ -2449,7 +2497,10 @@
int bytemode ATTRIBUTE_UNUSED;
int sizeflag ATTRIBUTE_UNUSED;
{
- sprintf (scratchbuf, "%%st(%d)", rm);
+ if (intel_syntax)
+ sprintf (scratchbuf, "st(%d)", rm);
+ else
+ sprintf (scratchbuf, "%%st(%d)", rm);
oappend (scratchbuf);
}
@@ -2755,32 +2806,50 @@
{
if (prefixes & PREFIX_CS)
{
- oappend ("%cs:");
+ if (intel_syntax)
+ oappend ("cs:");
+ else
+ oappend ("%cs:");
used_prefixes |= PREFIX_CS;
}
if (prefixes & PREFIX_DS)
{
- oappend ("%ds:");
+ if (intel_syntax)
+ oappend ("ds:");
+ else
+ oappend ("%ds:");
used_prefixes |= PREFIX_DS;
}
if (prefixes & PREFIX_SS)
{
- oappend ("%ss:");
+ if (intel_syntax)
+ oappend ("ss:");
+ else
+ oappend ("%ss:");
used_prefixes |= PREFIX_SS;
}
if (prefixes & PREFIX_ES)
{
- oappend ("%es:");
+ if (intel_syntax)
+ oappend ("es:");
+ else
+ oappend ("%es:");
used_prefixes |= PREFIX_ES;
}
if (prefixes & PREFIX_FS)
{
- oappend ("%fs:");
+ if (intel_syntax)
+ oappend ("fs:");
+ else
+ oappend ("%fs:");
used_prefixes |= PREFIX_FS;
}
if (prefixes & PREFIX_GS)
{
- oappend ("%gs:");
+ if (intel_syntax)
+ oappend ("gs:");
+ else
+ oappend ("%gs:");
used_prefixes |= PREFIX_GS;
}
}
@@ -3060,6 +3129,12 @@
/* Don't print zero displacements */
if (disp != 0)
{
+ if ((int)disp > 0)
+ {
+ *obufp++ = '+';
+ *obufp = '\0';
+ }
+
print_operand_value (scratchbuf, 0, disp);
oappend (scratchbuf);
}
@@ -3269,7 +3344,10 @@
switch (code)
{
case indir_dx_reg:
- s = "(%dx)";
+ if (intel_syntax)
+ s = "[dx]";
+ else
+ s = "(%dx)";
break;
case ax_reg: case cx_reg: case dx_reg: case bx_reg:
case sp_reg: case bp_reg: case si_reg: case di_reg:
@@ -3324,7 +3402,10 @@
switch (code)
{
case indir_dx_reg:
- s = "(%dx)";
+ if (intel_syntax)
+ s = "[dx]";
+ else
+ s = "(%dx)";
break;
case ax_reg: case cx_reg: case dx_reg: case bx_reg:
case sp_reg: case bp_reg: case si_reg: case di_reg:
@@ -3409,8 +3490,8 @@
op &= mask;
scratchbuf[0] = '$';
- print_operand_value (scratchbuf + !intel_syntax, 1, op);
- oappend (scratchbuf);
+ print_operand_value (scratchbuf + 1, 1, op);
+ oappend (scratchbuf + intel_syntax);
scratchbuf[0] = '\0';
}
@@ -3462,8 +3543,8 @@
op &= mask;
scratchbuf[0] = '$';
- print_operand_value (scratchbuf + !intel_syntax, 1, op);
- oappend (scratchbuf);
+ print_operand_value (scratchbuf + 1, 1, op);
+ oappend (scratchbuf + intel_syntax);
scratchbuf[0] = '\0';
}
@@ -3515,7 +3596,7 @@
scratchbuf[0] = '$';
print_operand_value (scratchbuf + 1, 1, op);
- oappend (scratchbuf);
+ oappend (scratchbuf + intel_syntax);
}
static void
@@ -3565,7 +3646,7 @@
"%es","%cs","%ss","%ds","%fs","%gs","%?","%?",
};
- oappend (sreg[reg]);
+ oappend (sreg[reg] + intel_syntax);
}
static void
@@ -3586,7 +3667,10 @@
seg = get16 ();
}
used_prefixes |= (prefixes & PREFIX_DATA);
- sprintf (scratchbuf, "$0x%x,$0x%x", seg, offset);
+ if (intel_syntax)
+ sprintf (scratchbuf, "0x%x,0x%x", seg, offset);
+ else
+ sprintf (scratchbuf, "$0x%x,$0x%x", seg, offset);
oappend (scratchbuf);
}
@@ -3653,7 +3737,11 @@
int sizeflag;
{
const char *s;
- oappend ("(");
+ if(intel_syntax)
+ oappend ("[");
+ else
+ oappend ("(");
+
USED_REX (REX_MODE64);
if (rex & REX_MODE64)
s = names64[code - eAX_reg];
@@ -3662,7 +3750,10 @@
else
s = names16[code - eAX_reg];
oappend (s);
- oappend (")");
+ if(intel_syntax)
+ oappend ("]");
+ else
+ oappend (")");
}
static void
@@ -3670,7 +3761,10 @@
int code;
int sizeflag;
{
- oappend ("%es:");
+ if (intel_syntax)
+ oappend ("es:");
+ else
+ oappend ("%es:");
ptr_reg (code, sizeflag);
}
@@ -3700,7 +3794,10 @@
USED_REX (REX_EXTX);
if (rex & REX_EXTX)
add = 8;
- sprintf (scratchbuf, "%%cr%d", reg+add);
+ if (intel_syntax)
+ sprintf (scratchbuf, "cr%d", reg+add);
+ else
+ sprintf (scratchbuf, "%%cr%d", reg+add);
oappend (scratchbuf);
}
@@ -3713,7 +3810,10 @@
USED_REX (REX_EXTX);
if (rex & REX_EXTX)
add = 8;
- sprintf (scratchbuf, "%%db%d", reg+add);
+ if (intel_syntax)
+ sprintf (scratchbuf, "db%d", reg+add);
+ else
+ sprintf (scratchbuf, "%%db%d", reg+add);
oappend (scratchbuf);
}
@@ -3722,7 +3822,10 @@
int dummy ATTRIBUTE_UNUSED;
int sizeflag ATTRIBUTE_UNUSED;
{
- sprintf (scratchbuf, "%%tr%d", reg);
+ if (intel_syntax)
+ sprintf (scratchbuf, "tr%d", reg);
+ else
+ sprintf (scratchbuf, "%%tr%d", reg);
oappend (scratchbuf);
}
@@ -3748,9 +3851,19 @@
add = 8;
used_prefixes |= (prefixes & PREFIX_DATA);
if (prefixes & PREFIX_DATA)
- sprintf (scratchbuf, "%%xmm%d", reg + add);
+ {
+ if (intel_syntax)
+ sprintf (scratchbuf, "xmm%d", reg + add);
+ else
+ sprintf (scratchbuf, "%%xmm%d", reg + add);
+ }
else
- sprintf (scratchbuf, "%%mm%d", reg + add);
+ {
+ if (intel_syntax)
+ sprintf (scratchbuf, "mm%d", reg + add);
+ else
+ sprintf (scratchbuf, "%%mm%d", reg + add);
+ }
oappend (scratchbuf);
}
@@ -3763,7 +3876,11 @@
USED_REX (REX_EXTX);
if (rex & REX_EXTX)
add = 8;
- sprintf (scratchbuf, "%%xmm%d", reg + add);
+ if (intel_syntax)
+ sprintf (scratchbuf, "xmm%d", reg + add);
+ else
+ sprintf (scratchbuf, "%%xmm%d", reg + add);
+
oappend (scratchbuf);
}
@@ -3787,9 +3904,19 @@
codep++;
used_prefixes |= (prefixes & PREFIX_DATA);
if (prefixes & PREFIX_DATA)
- sprintf (scratchbuf, "%%xmm%d", rm + add);
+ {
+ if (intel_syntax)
+ sprintf (scratchbuf, "xmm%d", rm + add);
+ else
+ sprintf (scratchbuf, "%%xmm%d", rm + add);
+ }
else
- sprintf (scratchbuf, "%%mm%d", rm + add);
+ {
+ if (intel_syntax)
+ sprintf (scratchbuf, "mm%d", rm + add);
+ else
+ sprintf (scratchbuf, "%%mm%d", rm + add);
+ }
oappend (scratchbuf);
}
@@ -3811,7 +3938,10 @@
/* skip mod/rm byte */
MODRM_CHECK;
codep++;
- sprintf (scratchbuf, "%%xmm%d", rm + add);
+ if (intel_syntax)
+ sprintf (scratchbuf, "xmm%d", rm + add);
+ else
+ sprintf (scratchbuf, "%%xmm%d", rm + add);
oappend (scratchbuf);
}