Skip to contentSkip to conversation

(big) real mode emulation - and ax imm

PATCH Applied Nitin A Kamble 2 participants 4 messages Aug 16, 2007 – Aug 19, 2007 3 messages not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (big) real mode emulation - and ax imm

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

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

commit 16312d9a828af54d3d4ad7dc0a9a1f038de72bf6

Author: Nitin A Kamble <[email protected]>
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)

drivers/kvm/x86_emulate.c +18 -2
index a2d520b..cfdbaa5 100644
@@ -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;

-------------------------------------------------------------------------
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/

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): 1187307885.10269.6.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org

Applied
#2 lore raw
Quoted 5 lines · Nitin A Kamble

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.

Signature · 8 lines
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/

A message that is not in the archive (sent off-list or not yet received): 46C59201.5070901-atKUWr5tajBWk0Htik3J/[email protected]

#4 lore raw

PATCH 1/1 (big) real mode emulation - sorted opcodes

Quoted 6 lines · Avi Kivity

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.

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

commit c609269ebc40e385ec5a82363d5ee4a49388776c

Author: Nitin A Kamble <[email protected]>
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.

drivers/kvm/x86_emulate.c +40 -38
index b4f439c..b196d25 100644
@@ -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;

-------------------------------------------------------------------------
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/

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): 1187388776.9011.9.camel-mpPvwfgnXtFHIUuj5cj4Omt3HXsI98Cx0E9HWUfgJXw@public.gmane.org

#6 lore raw

Re: [Patch] (big) real mode emulation - sorted opcodes

Quoted 9 lines · Nitin A Kamble
Quoted 7 lines · Avi Kivity

Applied, thanks.

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

Quoted 10 lines

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'.

Signature · 8 lines
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/