Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HaYCw-00083s-25 for qemu-devel@nongnu.org; Sun, 08 Apr 2007 10:17:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HaYCu-000814-Hy for qemu-devel@nongnu.org; Sun, 08 Apr 2007 10:17:28 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HaYCu-000811-Cn for qemu-devel@nongnu.org; Sun, 08 Apr 2007 10:17:28 -0400 Received: from nz-out-0506.google.com ([64.233.162.227]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HaY9B-00044P-Fj for qemu-devel@nongnu.org; Sun, 08 Apr 2007 10:13:37 -0400 Received: by nz-out-0506.google.com with SMTP id i11so2082344nzi for ; Sun, 08 Apr 2007 07:13:36 -0700 (PDT) Message-ID: <83a4d4ca0704080713t596e4d83lbd1c495d92eda581@mail.gmail.com> Date: Sun, 8 Apr 2007 16:13:31 +0200 From: "Eduardo Felipe" Subject: Re: [Qemu-devel] Re: Detecting an assembly instruction in QEMU In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_24795_14791196.1176041611136" References: <83a4d4ca0704060515l172d6f9ep59b6467c6e49f250@mail.gmail.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org ------=_Part_24795_14791196.1176041611136 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Atif, In target-i386/translate.c, there are many variants of mov i.e. > case 0x89: /* mov Gv, Ev */ > case 0xc7: /* mov Ev, Iv */ > case 0x8b: /* mov Ev, Gv */ > case 0x8e: /* mov seg, Gv */ That's true. I forgot the fact that mov %eax,%eax can be both: 0x89 0xC0 0x8B 0xC0 It's up to the compiler to choose which one to use. which one do you think will be called when "mov %eax, %eax" instruction is > translated. > I printed the value of modrm inside the case 0x89 but the value remains > the same whether I use %eax or %ebx. > > Secondly, How can I extract the source and destination registers from > modrm. modrm is the byte following the 0x89 or 0x8B opcode. After modrm = ldub_code(s->pc++); you can decode it this way (in binary): XXYYYZZZ XX --> Indexing mode YYY --> Destination register ZZZ --> Source register 0xC0 is the value you are looking for 11 000 000 --> (no indexing)(%eax)(%eax). You can find more information here: http://pdos.csail.mit.edu/6.828/2005/readings/i386/s17_02.htm One more thing: you may want to check operand size. It's on "ot" variable, and its meaning (from translate.c): enum { OT_BYTE = 0, OT_WORD, OT_LONG, OT_QUAD, }; being 8, 16, 32 and 64 bits respectively. Regards, Eduardo ------=_Part_24795_14791196.1176041611136 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Atif,

In target-i386/translate.c, there are many variants of mov i.e.
 case 0x89: /* mov Gv, Ev */
 case 0xc7: /* mov Ev, Iv */
 case 0x8b: /* mov Ev, Gv */
 case 0x8e: /* mov seg, Gv */

That's true. I forgot the fact that mov %eax,%eax can be both:

0x89 0xC0
0x8B 0xC0

It's up to the compiler to choose which one to use.

which one do you think will be called when "mov %eax, %eax" instruction is translated.
I printed the value of modrm inside the case 0x89 but the value remains the same whether I use %eax or %ebx.

Secondly, How can I extract the source and destination registers from modrm.

modrm is the byte following the 0x89 or 0x8B opcode. After

modrm = ldub_code(s->pc++);

you can decode it this way (in binary):
XXYYYZZZ

XX --> Indexing mode
YYY --> Destination register
ZZZ --> Source register

0xC0 is the value you are looking for 11 000 000 --> (no indexing)(%eax)(%eax).

You can find more information here:
http://pdos.csail.mit.edu/6.828/2005/readings/i386/s17_02.htm

One more thing: you may want to check operand size. It's on "ot" variable, and its meaning (from translate.c):
enum {
    OT_BYTE = 0,
    OT_WORD,
    OT_LONG,
    OT_QUAD,
};

being 8, 16, 32 and 64 bits respectively.

Regards,
Eduardo

------=_Part_24795_14791196.1176041611136--