diff options
author | Wei Yongjun <yjwei@cn.fujitsu.com> | 2010-08-08 23:34:56 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2010-10-24 04:51:01 -0400 |
commit | 35c843c4857e2a818d1d951d87c40ee2cf5c1be8 (patch) | |
tree | 3af2786b912d11c373c5eed7df590070bce089b3 /arch/x86/kvm/emulate.c | |
parent | 8744aa9aad56be756a58126b429f176898631c3f (diff) |
KVM: x86 emulator: fix negative bit offset BitOp instruction emulation
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>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/emulate.c')
-rw-r--r-- | arch/x86/kvm/emulate.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 175b41690d6f..5fc441c064ba 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c | |||
@@ -723,6 +723,22 @@ done: | |||
723 | return rc; | 723 | return rc; |
724 | } | 724 | } |
725 | 725 | ||
726 | static void fetch_bit_operand(struct decode_cache *c) | ||
727 | { | ||
728 | long sv, mask; | ||
729 | |||
730 | if (c->dst.type == OP_MEM) { | ||
731 | mask = ~(c->dst.bytes * 8 - 1); | ||
732 | |||
733 | if (c->src.bytes == 2) | ||
734 | sv = (s16)c->src.val & (s16)mask; | ||
735 | else if (c->src.bytes == 4) | ||
736 | sv = (s32)c->src.val & (s32)mask; | ||
737 | |||
738 | c->dst.addr.mem += (sv >> 3); | ||
739 | } | ||
740 | } | ||
741 | |||
726 | static int read_emulated(struct x86_emulate_ctxt *ctxt, | 742 | static int read_emulated(struct x86_emulate_ctxt *ctxt, |
727 | struct x86_emulate_ops *ops, | 743 | struct x86_emulate_ops *ops, |
728 | unsigned long addr, void *dest, unsigned size) | 744 | unsigned long addr, void *dest, unsigned size) |
@@ -2638,12 +2654,8 @@ done_prefixes: | |||
2638 | c->dst.bytes = 8; | 2654 | c->dst.bytes = 8; |
2639 | else | 2655 | else |
2640 | c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes; | 2656 | c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes; |
2641 | if (c->dst.type == OP_MEM && (c->d & BitOp)) { | 2657 | if (c->d & BitOp) |
2642 | unsigned long mask = ~(c->dst.bytes * 8 - 1); | 2658 | fetch_bit_operand(c); |
2643 | |||
2644 | c->dst.addr.mem = c->dst.addr.mem + | ||
2645 | (c->src.val & mask) / 8; | ||
2646 | } | ||
2647 | c->dst.orig_val = c->dst.val; | 2659 | c->dst.orig_val = c->dst.val; |
2648 | break; | 2660 | break; |
2649 | case DstAcc: | 2661 | case DstAcc: |