public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH 1/5] change ctxt.*_base to an array ctxt.base[X86EMUL_BASE_*]
Date: Wed, 01 Aug 2007 11:09:42 +0200	[thread overview]
Message-ID: <46B04DD6.7010702@bull.net> (raw)
In-Reply-To: <46B04CCA.2010503-6ktuUTfB/bM@public.gmane.org>


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

To be able to extract easily prefix decoding from x86_emulate_memop(), change
ctxt.*_base to an array ctxt.base[X86EMUL_BASE_*]

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
-- 
------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org  --------------
          "Software is hard" - Donald Knuth

[-- Attachment #1.1.2: x86_ctxt_segment_array --]
[-- Type: text/plain, Size: 7271 bytes --]

Index: kvm/drivers/kvm/kvm_main.c
===================================================================
--- kvm.orig/drivers/kvm/kvm_main.c	2007-07-31 15:09:01.000000000 +0200
+++ kvm/drivers/kvm/kvm_main.c	2007-07-31 15:12:47.000000000 +0200
@@ -1236,19 +1236,25 @@
 		? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
 
 	if (emulate_ctxt.mode == X86EMUL_MODE_PROT64) {
-		emulate_ctxt.cs_base = 0;
-		emulate_ctxt.ds_base = 0;
-		emulate_ctxt.es_base = 0;
-		emulate_ctxt.ss_base = 0;
+		emulate_ctxt.base[X86EMUL_BASE_CS] = 0;
+		emulate_ctxt.base[X86EMUL_BASE_DS] = 0;
+		emulate_ctxt.base[X86EMUL_BASE_ES] = 0;
+		emulate_ctxt.base[X86EMUL_BASE_SS] = 0;
 	} else {
-		emulate_ctxt.cs_base = get_segment_base(vcpu, VCPU_SREG_CS);
-		emulate_ctxt.ds_base = get_segment_base(vcpu, VCPU_SREG_DS);
-		emulate_ctxt.es_base = get_segment_base(vcpu, VCPU_SREG_ES);
-		emulate_ctxt.ss_base = get_segment_base(vcpu, VCPU_SREG_SS);
+		emulate_ctxt.base[X86EMUL_BASE_CS] =
+					get_segment_base(vcpu, VCPU_SREG_CS);
+		emulate_ctxt.base[X86EMUL_BASE_DS] =
+					get_segment_base(vcpu, VCPU_SREG_DS);
+		emulate_ctxt.base[X86EMUL_BASE_ES] =
+					get_segment_base(vcpu, VCPU_SREG_ES);
+		emulate_ctxt.base[X86EMUL_BASE_SS] =
+					get_segment_base(vcpu, VCPU_SREG_SS);
 	}
 
-	emulate_ctxt.gs_base = get_segment_base(vcpu, VCPU_SREG_GS);
-	emulate_ctxt.fs_base = get_segment_base(vcpu, VCPU_SREG_FS);
+	emulate_ctxt.base[X86EMUL_BASE_GS] =
+					get_segment_base(vcpu, VCPU_SREG_GS);
+	emulate_ctxt.base[X86EMUL_BASE_FS] =
+					get_segment_base(vcpu, VCPU_SREG_FS);
 
 	vcpu->mmio_is_write = 0;
 	r = x86_emulate_memop(&emulate_ctxt, &emulate_ops);
Index: kvm/drivers/kvm/x86_emulate.c
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.c	2007-07-31 15:09:01.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.c	2007-07-31 17:01:52.000000000 +0200
@@ -419,7 +419,8 @@
 /* Fetch next part of the instruction being emulated. */
 #define insn_fetch(_type, _size, _eip)                                  \
 ({	unsigned long _x;						\
-	rc = ops->read_std((unsigned long)(_eip) + ctxt->cs_base, &_x,	\
+	rc = ops->read_std((unsigned long)(_eip) + 			\
+			   ctxt->base[X86EMUL_BASE_CS], &_x,		\
                                                   (_size), ctxt->vcpu); \
 	if ( rc != 0 )							\
 		goto done;						\
@@ -484,7 +485,7 @@
 	unsigned d;
 	u8 b, sib, twobyte = 0, rex_prefix = 0;
 	u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
-	unsigned long *override_base = NULL;
+	int override_base = -1;
 	unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i;
 	int rc = 0;
 	struct operand src, dst;
@@ -533,22 +534,22 @@
 				ad_bytes ^= 6;	/* switch between 2/4 bytes */
 			break;
 		case 0x2e:	/* CS override */
-			override_base = &ctxt->cs_base;
+			override_base = X86EMUL_BASE_CS;
 			break;
 		case 0x3e:	/* DS override */
-			override_base = &ctxt->ds_base;
+			override_base = X86EMUL_BASE_DS;
 			break;
 		case 0x26:	/* ES override */
-			override_base = &ctxt->es_base;
+			override_base = X86EMUL_BASE_ES;
 			break;
 		case 0x64:	/* FS override */
-			override_base = &ctxt->fs_base;
+			override_base = X86EMUL_BASE_FS;
 			break;
 		case 0x65:	/* GS override */
-			override_base = &ctxt->gs_base;
+			override_base = X86EMUL_BASE_GS;
 			break;
 		case 0x36:	/* SS override */
-			override_base = &ctxt->ss_base;
+			override_base = X86EMUL_BASE_SS;
 			break;
 		case 0xf0:	/* LOCK */
 			lock_prefix = 1;
@@ -654,8 +655,8 @@
 			}
 			if (modrm_rm == 2 || modrm_rm == 3 ||
 			    (modrm_rm == 6 && modrm_mod != 0))
-				if (!override_base)
-					override_base = &ctxt->ss_base;
+				if (override_base == -1)
+					override_base = X86EMUL_BASE_SS;
 			modrm_ea = (u16)modrm_ea;
 		} else {
 			/* 32/64-bit ModR/M decode. */
@@ -708,15 +709,15 @@
 				break;
 			}
 		}
-		if (!override_base)
-			override_base = &ctxt->ds_base;
+		if (override_base == -1)
+			override_base = X86EMUL_BASE_DS;
 		if (mode == X86EMUL_MODE_PROT64 &&
-		    override_base != &ctxt->fs_base &&
-		    override_base != &ctxt->gs_base)
-			override_base = NULL;
+		    override_base != X86EMUL_BASE_FS &&
+		    override_base != X86EMUL_BASE_GS)
+			override_base = -1;
 
-		if (override_base)
-			modrm_ea += *override_base;
+		if (override_base != -1)
+			modrm_ea += ctxt->base[override_base];
 
 		if (rip_relative) {
 			modrm_ea += _eip;
@@ -963,8 +964,9 @@
 		/* 64-bit mode: POP always pops a 64-bit operand. */
 		if (mode == X86EMUL_MODE_PROT64)
 			dst.bytes = 8;
-		if ((rc = ops->read_std(register_address(ctxt->ss_base,
-							 _regs[VCPU_REGS_RSP]),
+		if ((rc = ops->read_std(
+				register_address(ctxt->base[X86EMUL_BASE_SS],
+					_regs[VCPU_REGS_RSP]),
 					&dst.val, dst.bytes, ctxt->vcpu)) != 0)
 			goto done;
 		register_address_increment(_regs[VCPU_REGS_RSP], dst.bytes);
@@ -1056,8 +1058,8 @@
 			register_address_increment(_regs[VCPU_REGS_RSP],
 						   -dst.bytes);
 			if ((rc = ops->write_std(
-				     register_address(ctxt->ss_base,
-						      _regs[VCPU_REGS_RSP]),
+				register_address(ctxt->base[X86EMUL_BASE_SS],
+						 _regs[VCPU_REGS_RSP]),
 				     &dst.val, dst.bytes, ctxt->vcpu)) != 0)
 				goto done;
 			no_wb = 1;
@@ -1128,10 +1130,12 @@
 	case 0xa4 ... 0xa5:	/* movs */
 		dst.type = OP_MEM;
 		dst.bytes = (d & ByteOp) ? 1 : op_bytes;
-		dst.ptr = (unsigned long *)register_address(ctxt->es_base,
+		dst.ptr = (unsigned long *)register_address(
+						ctxt->base[X86EMUL_BASE_ES],
 							_regs[VCPU_REGS_RDI]);
 		if ((rc = ops->read_emulated(register_address(
-		      override_base ? *override_base : ctxt->ds_base,
+		      (override_base != -1) ?
+		      	ctxt->base[override_base] : ctxt->base[X86EMUL_BASE_DS],
 		      _regs[VCPU_REGS_RSI]), &dst.val, dst.bytes, ctxt->vcpu)) != 0)
 			goto done;
 		register_address_increment(_regs[VCPU_REGS_RSI],
@@ -1173,7 +1177,8 @@
 		dst.ptr = (unsigned long *)&_regs[b & 0x7];
 
 pop_instruction:
-		if ((rc = ops->read_std(register_address(ctxt->ss_base,
+		if ((rc = ops->read_std(
+			register_address(ctxt->base[X86EMUL_BASE_SS],
 			_regs[VCPU_REGS_RSP]), dst.ptr, op_bytes, ctxt->vcpu))
 			!= 0)
 			goto done;
Index: kvm/drivers/kvm/x86_emulate.h
===================================================================
--- kvm.orig/drivers/kvm/x86_emulate.h	2007-07-31 15:09:01.000000000 +0200
+++ kvm/drivers/kvm/x86_emulate.h	2007-07-31 17:00:22.000000000 +0200
@@ -112,6 +112,16 @@
 
 };
 
+enum {
+	X86EMUL_BASE_CS,
+	X86EMUL_BASE_DS,
+	X86EMUL_BASE_ES,
+	X86EMUL_BASE_SS,
+	X86EMUL_BASE_GS,
+	X86EMUL_BASE_FS,
+	X86EMUL_BASE_SIZE
+};
+
 struct x86_emulate_ctxt {
 	/* Register state before/after emulation. */
 	struct kvm_vcpu *vcpu;
@@ -122,13 +132,7 @@
 
 	/* Emulated execution mode, represented by an X86EMUL_MODE value. */
 	int mode;
-
-	unsigned long cs_base;
-	unsigned long ds_base;
-	unsigned long es_base;
-	unsigned long ss_base;
-	unsigned long gs_base;
-	unsigned long fs_base;
+	unsigned long base[X86EMUL_BASE_SIZE];
 };
 
 /* Execution mode, passed to the emulator. */

[-- Attachment #1.2: OpenPGP digital signature --]
[-- 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

  parent reply	other threads:[~2007-08-01  9:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-01  9:05 PATCH 0/5] Consolidate the insb/outsb emulation into x86_emulate.c Laurent Vivier
     [not found] ` <46B04CCA.2010503-6ktuUTfB/bM@public.gmane.org>
2007-08-01  9:09   ` Laurent Vivier [this message]
     [not found]     ` <46B04DD6.7010702-6ktuUTfB/bM@public.gmane.org>
2007-08-01  9:13       ` [PATCH 2/5] group all prefix decoding results in a structure called x86_prefix Laurent Vivier
     [not found]         ` <46B04EB9.5010103-6ktuUTfB/bM@public.gmane.org>
2007-08-01  9:16           ` [PATCH 3/5] extract prefix decoding part from x86_emulate_memop() to x86_decode_prefix() Laurent Vivier
     [not found]             ` <46B04F56.60607-6ktuUTfB/bM@public.gmane.org>
2007-08-01  9:19               ` [PATCH 4/5] vmx.c uses x86_decode_prefix() instead of get_io_count() Laurent Vivier
     [not found]                 ` <46B0501C.6060409-6ktuUTfB/bM@public.gmane.org>
2007-08-01  9:22                   ` [PATCH 5/5] svm.c uses x86_decode_prefix() instead of io_address() and io_get_override() Laurent Vivier
2007-08-02  8:48                   ` [PATCH 4/5] vmx.c uses x86_decode_prefix() instead of get_io_count() Avi Kivity
     [not found]                     ` <46B19A7B.2030109-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-02  9:34                       ` Laurent Vivier
     [not found]                         ` <46B1A51C.2040104-6ktuUTfB/bM@public.gmane.org>
2007-08-02  9:41                           ` Avi Kivity
     [not found]                             ` <46B1A6B8.7020404-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-08-02 16:46                               ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46B04DD6.7010702@bull.net \
    --to=laurent.vivier-6ktuutfb/bm@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox