public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86_emulate: Emulate nop (0x90) instruction
@ 2008-06-14 11:50 Mohammed Gamal
  2008-06-14 13:26 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Mohammed Gamal @ 2008-06-14 11:50 UTC (permalink / raw)
  To: kvm; +Cc: avi, riel

While testing FreeDOS under KVM I encountered a vmentry failure
because of a nop instruction.
This patch adds the instruction to the x86 emulator.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
 arch/x86/kvm/x86_emulate.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index b90857c..ef1b7d7 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -141,7 +141,7 @@ static u16 opcode_table[256] = {
 	DstMem | SrcReg | ModRM | Mov, ModRM | DstReg,
 	DstReg | SrcMem | ModRM | Mov, Group | Group1A,
 	/* 0x90 - 0x9F */
-	0, 0, 0, 0, 0, 0, 0, 0,
+	ImplicitOps, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, ImplicitOps | Stack, ImplicitOps | Stack, 0, 0,
 	/* 0xA0 - 0xA7 */
 	ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs,
@@ -1560,6 +1560,9 @@ special_insn:
 		if (rc != 0)
 			goto done;
 		break;
+	case 0x90: /* nop */
+		if(! (c->rex_prefix & 1) )
+			break;
 	case 0x9c: /* pushf */
 		c->src.val =  (unsigned long) ctxt->eflags;
 		emulate_push(ctxt);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86_emulate: Emulate nop (0x90) instruction
  2008-06-14 11:50 [PATCH] x86_emulate: Emulate nop (0x90) instruction Mohammed Gamal
@ 2008-06-14 13:26 ` Andi Kleen
  2008-06-14 13:35   ` Mohammed Gamal
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2008-06-14 13:26 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: kvm, avi, riel

"Mohammed Gamal" <m.gamal005@gmail.com> writes:
>  	ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs,
> @@ -1560,6 +1560,9 @@ special_insn:
>  		if (rc != 0)
>  			goto done;
>  		break;
> +	case 0x90: /* nop */
> +		if(! (c->rex_prefix & 1) )
> +			break;
>  	case 0x9c: /* pushf */
>  		c->src.val =  (unsigned long) ctxt->eflags;
>  		emulate_push(ctxt);

Is falling through to pushf really correct?  And not sure what the if checks.

iirc it should be just

     case 0x90: /* nop */
          break;

BTW there are lots more nop encodings.

-Andi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86_emulate: Emulate nop (0x90) instruction
  2008-06-14 13:26 ` Andi Kleen
@ 2008-06-14 13:35   ` Mohammed Gamal
  2008-06-14 15:08     ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Mohammed Gamal @ 2008-06-14 13:35 UTC (permalink / raw)
  To: Andi Kleen; +Cc: kvm, avi, riel

On Sat, Jun 14, 2008 at 4:26 PM, Andi Kleen <andi@firstfloor.org> wrote:
> "Mohammed Gamal" <m.gamal005@gmail.com> writes:
>>       ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs,
>> @@ -1560,6 +1560,9 @@ special_insn:
>>               if (rc != 0)
>>                       goto done;
>>               break;
>> +     case 0x90: /* nop */
>> +             if(! (c->rex_prefix & 1) )
>> +                     break;
>>       case 0x9c: /* pushf */
>>               c->src.val =  (unsigned long) ctxt->eflags;
>>               emulate_push(ctxt);
>
> Is falling through to pushf really correct?  And not sure what the if checks.
>
> iirc it should be just
>
>     case 0x90: /* nop */
>          break;
>
> BTW there are lots more nop encodings.
>
> -Andi
>

Thanks for pointing this out. 0x90 is also the opcode for xchg r8,rAX
instruction. The code should rather fall to the yet-to-be added xchg
instructions. A patch will be underway ;)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86_emulate: Emulate nop (0x90) instruction
  2008-06-14 13:35   ` Mohammed Gamal
@ 2008-06-14 15:08     ` Andi Kleen
  2008-06-14 15:26       ` Avi Kivity
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2008-06-14 15:08 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: kvm, avi, riel


> Thanks for pointing this out. 0x90 is also the opcode for xchg r8,rAX
> instruction.

But nop doesn't actually need to execute exchange.

-Andi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] x86_emulate: Emulate nop (0x90) instruction
  2008-06-14 15:08     ` Andi Kleen
@ 2008-06-14 15:26       ` Avi Kivity
  0 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2008-06-14 15:26 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Mohammed Gamal, kvm, riel

Andi Kleen wrote:
>> Thanks for pointing this out. 0x90 is also the opcode for xchg r8,rAX
>> instruction.
>>     
>
> But nop doesn't actually need to execute exchange.
>   

The sequence 0x41 0x90 uses the 0x90 opcode but is not a nop.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-06-14 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-14 11:50 [PATCH] x86_emulate: Emulate nop (0x90) instruction Mohammed Gamal
2008-06-14 13:26 ` Andi Kleen
2008-06-14 13:35   ` Mohammed Gamal
2008-06-14 15:08     ` Andi Kleen
2008-06-14 15:26       ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox