This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Feature request: Set the direction flag on x86/x64 register->register operations
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: "Stefan Dösinger" <stefan at codeweavers dot com>
- Cc: binutils at sourceware dot org, "Joey Ye" <joey dot ye at intel dot com>, "Xuepeng Guo" <xuepeng dot guo at intel dot com>, "Weiliang Lin" <weiliang dot lin at intel dot com>
- Date: Sat, 29 Nov 2008 07:40:30 -0800
- Subject: Re: Feature request: Set the direction flag on x86/x64 register->register operations
- References: <00b801c94ef8$abe5f480$03b1dd80$@com>
On Tue, Nov 25, 2008 at 4:23 AM, Stefan Dösinger <stefan@codeweavers.com> wrote:
> Hello,
>
> I have a patch attached for discussion that adds an option to make gas set
> the direction inversion flag on register to register operation. The main
> intended effect is that "mov %esp, %ebp" is assembled to "8b ec" instead of
> "89 e5".
>
> I am working on Wine, a software to run unmodified Windows Applications on
> Linux and other Unixes(www.winehq.org). We use gcc and gas to compile our
> replacement DLLs. There are a few popular applications like Steam or
> Teamspeak that attempt to inject some of their code into other Win32
> processes by hooking Win32 API calls by modifying the first 5 bytes of the
> function. Usually those 5 bytes look like this on Windows:
>
> 8b ff mov %edi, %edi
> 55 push %ebp
> 8b ec mov %esp, %ebp
>
> My problem is that those apps do not know the "89 e5" gas generates, as the
> apps are quite stubborn. (The mov %edi, %edi is something I have to fix in
> gcc).
>
> I have attached a patch that adds an option to the assembler to generate
> Windows-Style opcodes. I don't know if it is ready to be committed as-is,
> but I have a few questions:
>
> Is such a feature acceptable at all, or should I maintain this in my private
> builds?
>
> Is this safe? So far I haven't run the gas testsuite yet
>
> The code change seems ugly to me, I don't like the way the code changes the
> indices. I am not familiar with the structures there, so I don't see any way
> to make it look nicer
>
Many x86 instructions have more than one encodings. like size of displacement
as well as direction bit. Some instructions don't have direction bit:
movdqu, 2, 0xf30f6f, None, 2, CpuSSE2,
Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_ldSuf, {
Xmmword|Unspecified|BaseIndex|Disp8|Disp16|Disp32|Disp32S|RegXMM,
RegXMM }
movdqu, 2, 0xf30f7f, None, 2, CpuSSE2,
Modrm|IgnoreSize|No_bSuf|No_wSuf|No_lSuf|No_sSuf|No_qSuf|No_ldSuf, {
RegXMM, Xmmword|Unspecified|BaseIndex|Disp8|Disp16|Disp32|Disp32S|RegXMM
}
As you stated here, one may want one particular encoding. I'd like to see:
1. Allow a suffix in mnemonic, like mov.dn, mov.db, mov.dd. mov.dw
2. Add assembler switches if necessary.
Thanks.
--
H.J.