All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] KVM: x86 emulator: fix negative bit offset BitOp instruction emulation
@ 2010-08-06  7:17 Wei Yongjun
  2010-08-06  7:20 ` PATCH 2/3] KVM: x86 emulator: do not adjust the address for immediate source Wei Yongjun
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Wei Yongjun @ 2010-08-06  7:17 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

If bit offset operands is a negative number, BitOp instruction
will return wrong value. This patch fix it.

Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
---
 arch/x86/kvm/emulate.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 0e360c6..470c7eb 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -724,6 +724,30 @@ done:
 	return rc;
 }
 
+static void fetch_bit_operand(struct decode_cache *c)
+{
+	unsigned long mask, byte_offset;
+
+	if (c->dst.type == OP_MEM) {
+		if (c->src.bytes == 2)
+			c->src.val = (s16)c->src.val;
+		else if (c->src.bytes == 4)
+			c->src.val = (s32)c->src.val;
+
+		mask = ~(c->dst.bytes * 8 - 1);
+
+		if ((long)c->src.val < 0) {
+			/* negative bit offset */
+			byte_offset = c->dst.bytes +
+				      ((-c->src.val - 1) & mask) / 8;
+			c->dst.addr.mem -= byte_offset;
+		} else {
+			/* positive bit offset */
+			c->dst.addr.mem += (c->src.val & mask) / 8;
+		}
+	}
+}
+
 static int read_emulated(struct x86_emulate_ctxt *ctxt,
 			 struct x86_emulate_ops *ops,
 			 unsigned long addr, void *dest, unsigned size)
@@ -2646,12 +2670,8 @@ done_prefixes:
 			c->dst.bytes = 8;
 		else
 			c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
-		if (c->dst.type == OP_MEM && (c->d & BitOp)) {
-			unsigned long mask = ~(c->dst.bytes * 8 - 1);
-
-			c->dst.addr.mem = c->dst.addr.mem +
-						   (c->src.val & mask) / 8;
-		}
+		if (c->d & BitOp)
+			fetch_bit_operand(c);
 		c->dst.orig_val = c->dst.val;
 		break;
 	case DstAcc:
-- 
1.7.0.4



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

end of thread, other threads:[~2010-08-10  2:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-06  7:17 [PATCH 1/3] KVM: x86 emulator: fix negative bit offset BitOp instruction emulation Wei Yongjun
2010-08-06  7:20 ` PATCH 2/3] KVM: x86 emulator: do not adjust the address for immediate source Wei Yongjun
2010-08-06  7:26   ` [PATCH 2/3 v2] " Wei Yongjun
2010-08-06  7:21 ` [PATCH 3/3] KVM: x86 emulator: mask group 8 instruction as BitOp Wei Yongjun
2010-08-06  8:10 ` [PATCH 1/3] KVM: x86 emulator: fix negative bit offset BitOp instruction emulation Paolo Bonzini
2010-08-08 20:28 ` Avi Kivity
2010-08-09  3:34   ` [PATCH 1/3 v2] " Wei Yongjun
2010-08-09  3:37     ` [PATCH 2/3 v2] KVM: x86 emulator: do not adjust the address for immediate source Wei Yongjun
2010-08-09  3:39       ` [PATCH 3/3 v2] KVM: x86 emulator: mask group 8 instruction as BitOp Wei Yongjun
2010-08-10  2:46     ` [PATCH 1/3 v2] KVM: x86 emulator: fix negative bit offset BitOp instruction emulation Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.