public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [Patch] (big) real mode emulation - and ax imm
@ 2007-08-16 23:44 Nitin A Kamble
       [not found] ` <1187307885.10269.6.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Nitin A Kamble @ 2007-08-16 23:44 UTC (permalink / raw)
  To: Avi Kivity; +Cc: Yu, Wilfred, kvm-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 353 bytes --]

Hi Avi,
 Attached is the patch to implement "and al imm8", "and ax imm16" & "
and eax imm32" instructions.
  Please apply or comment.
-- 
Thanks & Regards,
Nitin
Open Source Technology Center, Intel Corporation
-----------------------------------------------------------------
The mind is like a parachute; it works much better when it's open

[-- Attachment #1.1.2: and_al_ax_eax_imm.patch --]
[-- Type: text/x-patch, Size: 1594 bytes --]

commit 16312d9a828af54d3d4ad7dc0a9a1f038de72bf6
Author: Nitin A Kamble <nitin.a.kamble@intel.com>
Date:   Thu Aug 16 19:19:44 2007 -0700

    Implement emulation of instruction
    	and al imm8 (opcode 0x24)
    	and ax/eax imm16/imm32 (opcode 0x25)
    
    Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index a2d520b..cfdbaa5 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -83,7 +83,7 @@ static u8 opcode_table[256] = {
 	/* 0x20 - 0x27 */
 	ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
 	ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
-	0, 0, 0, 0,
+	SrcImmByte, SrcImm, 0, 0,
 	/* 0x28 - 0x2F */
 	ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
 	ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
@@ -890,7 +890,23 @@ done_prefixes:
 	      sbb:		/* sbb */
 		emulate_2op_SrcV("sbb", src, dst, _eflags);
 		break;
-	case 0x20 ... 0x25:
+	case 0x24:              /* and al imm8 */
+		dst.type = OP_REG;
+		dst.ptr = &_regs[VCPU_REGS_RAX];
+		dst.val = *(u8 *)dst.ptr;
+		dst.bytes = 1;
+		dst.orig_val = dst.val;
+		goto and;
+	case 0x25:              /* and ax imm16, or eax imm32 */
+		dst.type = OP_REG;
+		dst.bytes = op_bytes;
+		dst.ptr = &_regs[VCPU_REGS_RAX];
+		if (op_bytes == 2)
+			dst.val = *(u16 *)dst.ptr;
+		else
+			dst.val = *(u32 *)dst.ptr;
+		dst.orig_val = dst.val;
+	case 0x20 ... 0x23:
 	      and:		/* and */
 		emulate_2op_SrcV("and", src, dst, _eflags);
 		break;

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 315 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

[-- Attachment #3: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* Re: [Patch] (big) real mode emulation - and ax imm
       [not found] ` <1187307885.10269.6.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
@ 2007-08-17 12:18   ` Avi Kivity
       [not found]     ` <46C59201.5070901-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Avi Kivity @ 2007-08-17 12:18 UTC (permalink / raw)
  To: nitin.a.kamble-ral2JQCrhuEAvxtiuMwx3w; +Cc: Yu, Wilfred, kvm-devel

Nitin A Kamble wrote:
> Hi Avi,
>  Attached is the patch to implement "and al imm8", "and ax imm16" & "
> and eax imm32" instructions.
>   Please apply or comment.
>   

Applied, thanks.

Please keep opcodes in sorted order, and don't post patches in dos format.


-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

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

* [Patch] (big) real mode emulation - sorted opcodes
       [not found]     ` <46C59201.5070901-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
@ 2007-08-17 22:12       ` Nitin A Kamble
       [not found]         ` <1187388776.9011.9.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Nitin A Kamble @ 2007-08-17 22:12 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 817 bytes --]

On Fri, 2007-08-17 at 05:18 -0700, Avi Kivity wrote:
> Applied, thanks.
> 
> Please keep opcodes in sorted order, and don't post patches in dos
> format.
> 
> 
Hi Avi,
  Attached is the patch, doing code cleanup. It keeps the emulation of
op-codes in sorted order. Also removes the white-space before labels.

  I don't see any reason for it to reach you in the dos format. I use
evolution to send email, and I am sending it from my Linux desktop. Only
thing is I have to go through the Exchange server to send email. Can you
send back one of my patch? I will check what is happening.

-- 
Thanks & Regards,
Nitin
Open Source Technology Center, Intel Corporation
-----------------------------------------------------------------
The mind is like a parachute; it works much better when it's open

[-- Attachment #1.1.2: opcodes_sorted.patch --]
[-- Type: text/x-patch, Size: 5452 bytes --]

commit c609269ebc40e385ec5a82363d5ee4a49388776c
Author: Nitin A Kamble <nitin.a.kamble@intel.com>
Date:   Fri Aug 17 18:21:08 2007 -0700

    Rearrange the emulation code so that opcodes stay in sorted order.
    And rearrange the lables as per the kernel requirements.
    
     Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>

diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index b4f439c..b196d25 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -782,7 +782,7 @@ done_prefixes:
 		goto srcmem_common;
 	case SrcMem:
 		src.bytes = (d & ByteOp) ? 1 : op_bytes;
-	      srcmem_common:
+srcmem_common:
 		src.type = OP_MEM;
 		src.ptr = (unsigned long *)cr2;
 		if ((rc = ops->read_emulated((unsigned long)src.ptr,
@@ -898,6 +898,18 @@ done_prefixes:
 	      cmp:		/* cmp */
 		emulate_2op_SrcV("cmp", src, dst, _eflags);
 		break;
+	case 0x58 ... 0x5f: 	/* pop reg */
+		dst.ptr = (unsigned long *)&_regs[b & 0x7];
+
+pop_instruction:
+		if ((rc = ops->read_std(register_address(ctxt->ss_base,
+			_regs[VCPU_REGS_RSP]), dst.ptr, op_bytes, ctxt->vcpu))
+			!= 0)
+			goto done;
+
+		register_address_increment(_regs[VCPU_REGS_RSP], op_bytes);
+		no_wb = 1; /* Disable writeback. */
+		break;
 	case 0x63:		/* movsxd */
 		if (mode != X86EMUL_MODE_PROT64)
 			goto cannot_emulate;
@@ -924,7 +936,7 @@ done_prefixes:
 		}
 		break;
 	case 0x84 ... 0x85:
-	      test:		/* test */
+test:		/* test */
 		emulate_2op_SrcV("test", src, dst, _eflags);
 		break;
 	case 0x86 ... 0x87:	/* xchg */
@@ -960,7 +972,7 @@ done_prefixes:
 		_eip += ad_bytes;	/* skip dst displacement */
 		break;
 	case 0x88 ... 0x8b:	/* mov */
-	case 0xc6 ... 0xc7:	/* mov (sole member of Grp11) */
+mov:
 		dst.val = src.val;
 		break;
 	case 0x8f:		/* pop (sole member of Grp1a) */
@@ -974,7 +986,7 @@ done_prefixes:
 		register_address_increment(_regs[VCPU_REGS_RSP], dst.bytes);
 		break;
 	case 0xc0 ... 0xc1:
-	      grp2:		/* Grp2 */
+grp2:		/* Grp2 */
 		switch (modrm_reg) {
 		case 0:	/* rol */
 			emulate_2op_SrcB("rol", src, dst, _eflags);
@@ -1000,6 +1012,8 @@ done_prefixes:
 			break;
 		}
 		break;
+	case 0xc6 ... 0xc7:	/* mov (sole member of Grp11) */
+		goto mov;
 	case 0xd0 ... 0xd1:	/* Grp2 */
 		src.val = 1;
 		goto grp2;
@@ -1200,24 +1214,12 @@ special_insn:
 	case 0xae ... 0xaf:	/* scas */
 		DPRINTF("Urk! I don't handle SCAS.\n");
 		goto cannot_emulate;
-	case 0xf4:              /* hlt */
-		ctxt->vcpu->halt_request = 1;
-		goto done;
 	case 0xc3: /* ret */
 		dst.ptr = &_eip;
 		goto pop_instruction;
-	case 0x58 ... 0x5f: /* pop reg */
-		dst.ptr = (unsigned long *)&_regs[b & 0x7];
-
-pop_instruction:
-		if ((rc = ops->read_std(register_address(ctxt->ss_base,
-			_regs[VCPU_REGS_RSP]), dst.ptr, op_bytes, ctxt->vcpu))
-			!= 0)
-			goto done;
-
-		register_address_increment(_regs[VCPU_REGS_RSP], op_bytes);
-		no_wb = 1; /* Disable writeback. */
-		break;
+	case 0xf4:              /* hlt */
+		ctxt->vcpu->halt_request = 1;
+		goto done;
 	}
 	goto writeback;
 
@@ -1311,6 +1313,16 @@ twobyte_insn:
 		/* Odd cmov opcodes (lsb == 1) have inverted sense. */
 		no_wb ^= b & 1;
 		break;
+	case 0xa3:
+bt:		/* bt */
+		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
+		emulate_2op_SrcV_nobyte("bt", src, dst, _eflags);
+		break;
+	case 0xab:
+bts:		/* bts */
+		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
+		emulate_2op_SrcV_nobyte("bts", src, dst, _eflags);
+		break;
 	case 0xb0 ... 0xb1:	/* cmpxchg */
 		/*
 		 * Save real source value, then compare EAX against
@@ -1328,30 +1340,15 @@ twobyte_insn:
 			dst.ptr = (unsigned long *)&_regs[VCPU_REGS_RAX];
 		}
 		break;
-	case 0xa3:
-	      bt:		/* bt */
-		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
-		emulate_2op_SrcV_nobyte("bt", src, dst, _eflags);
-		break;
 	case 0xb3:
-	      btr:		/* btr */
+btr:		/* btr */
 		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
 		emulate_2op_SrcV_nobyte("btr", src, dst, _eflags);
 		break;
-	case 0xab:
-	      bts:		/* bts */
-		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
-		emulate_2op_SrcV_nobyte("bts", src, dst, _eflags);
-		break;
 	case 0xb6 ... 0xb7:	/* movzx */
 		dst.bytes = op_bytes;
 		dst.val = (d & ByteOp) ? (u8) src.val : (u16) src.val;
 		break;
-	case 0xbb:
-	      btc:		/* btc */
-		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
-		emulate_2op_SrcV_nobyte("btc", src, dst, _eflags);
-		break;
 	case 0xba:		/* Grp8 */
 		switch (modrm_reg & 3) {
 		case 0:
@@ -1364,6 +1361,11 @@ twobyte_insn:
 			goto btc;
 		}
 		break;
+	case 0xbb:
+btc:		/* btc */
+		src.val &= (dst.bytes << 3) - 1; /* only subword offset */
+		emulate_2op_SrcV_nobyte("btc", src, dst, _eflags);
+		break;
 	case 0xbe ... 0xbf:	/* movsx */
 		dst.bytes = op_bytes;
 		dst.val = (d & ByteOp) ? (s8) src.val : (s16) src.val;
@@ -1375,14 +1377,14 @@ twobyte_special_insn:
 	/* Disable writeback. */
 	no_wb = 1;
 	switch (b) {
+	case 0x06:
+		emulate_clts(ctxt->vcpu);
+		break;
 	case 0x09:		/* wbinvd */
 		break;
 	case 0x0d:		/* GrpP (prefetch) */
 	case 0x18:		/* Grp16 (prefetch/nop) */
 		break;
-	case 0x06:
-		emulate_clts(ctxt->vcpu);
-		break;
 	case 0x20: /* mov cr, reg */
 		if (modrm_mod != 3)
 			goto cannot_emulate;

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 315 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

[-- Attachment #3: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

* Re: [Patch] (big) real mode emulation - sorted opcodes
       [not found]         ` <1187388776.9011.9.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
@ 2007-08-19  7:56           ` Avi Kivity
  0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-08-19  7:56 UTC (permalink / raw)
  To: nitin.a.kamble-ral2JQCrhuEAvxtiuMwx3w; +Cc: kvm-devel

Nitin A Kamble wrote:
> On Fri, 2007-08-17 at 05:18 -0700, Avi Kivity wrote:
>   
>> Applied, thanks.
>>
>> Please keep opcodes in sorted order, and don't post patches in dos
>> format.
>>
>>
>>     
> Hi Avi,
>   Attached is the patch, doing code cleanup. It keeps the emulation of
> op-codes in sorted order. Also removes the white-space before labels.
>
>   I don't see any reason for it to reach you in the dos format. I use
> evolution to send email, and I am sending it from my Linux desktop. Only
> thing is I have to go through the Exchange server to send email. Can you
> send back one of my patch? I will check what is happening.
>
>   

Actually it unindents the labels too much... the convention is to 
unindent labels just one level.  Not that it is imporant.

Anyway, this patch got translated into DOS format as well:

[avi@cleopatra linux-2.6 (master)]$ od -t x1  ~/opcodes_sorted.patch  | head
0000000 63 6f 6d 6d 69 74 20 63 36 30 39 32 36 39 65 62
0000020 63 34 30 65 33 38 35 65 63 35 61 38 32 33 36 33
0000040 64 35 65 65 34 61 34 39 33 38 38 37 37 36 63 0d
0000060 0a 41 75 74 68 6f 72 3a 20 4e 69 74 69 6e 20 41
0000100 20 4b 61 6d 62 6c 65 20 3c 6e 69 74 69 6e 2e 61
0000120 2e 6b 61 6d 62 6c 65 40 69 6e 74 65 6c 2e 63 6f
0000140 6d 3e 0d 0a 44 61 74 65 3a 20 20 20 46 72 69 20
0000160 41 75 67 20 31 37 20 31 38 3a 32 31 3a 30 38 20
0000200 32 30 30 37 20 2d 30 37 30 30 0d 0a 0d 0a 20 20
0000220 20 20 52 65 61 72 72 61 6e 67 65 20 74 68 65 20


Note the sequences of '0d 0a'.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

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

end of thread, other threads:[~2007-08-19  7:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-16 23:44 [Patch] (big) real mode emulation - and ax imm Nitin A Kamble
     [not found] ` <1187307885.10269.6.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
2007-08-17 12:18   ` Avi Kivity
     [not found]     ` <46C59201.5070901-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-17 22:12       ` [Patch] (big) real mode emulation - sorted opcodes Nitin A Kamble
     [not found]         ` <1187388776.9011.9.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org>
2007-08-19  7:56           ` Avi Kivity

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