From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: [PATCH 3/5][RESEND] move all decoding process to function x86_decode_insn(). Date: Tue, 18 Sep 2007 11:27:19 +0200 Message-ID: <46EF99F7.6010205@bull.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060900050200060606090202" To: kvm-devel Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is a multi-part message in MIME format. --------------060900050200060606090202 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 move all decoding process to function x86_decode_insn(). Signed-off-by: Laurent Vivier --------------060900050200060606090202 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="x86_emulate-decode_insn" Content-Disposition: inline; filename="x86_emulate-decode_insn" Index: kvm/drivers/kvm/x86_emulate.c =================================================================== --- kvm.orig/drivers/kvm/x86_emulate.c 2007-09-18 10:41:06.000000000 +0200 +++ kvm/drivers/kvm/x86_emulate.c 2007-09-18 10:41:40.000000000 +0200 @@ -518,20 +518,16 @@ static int test_cc(unsigned int conditio } int -x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) +x86_decode_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) { struct decode_cache *decode = &ctxt->decode; u8 sib, rex_prefix = 0; unsigned int i; int rc = 0; - unsigned long cr2 = ctxt->cr2; int mode = ctxt->mode; int index_reg = 0, base_reg = 0, scale, rip_relative = 0; - int no_wb = 0; - u64 msr_data; /* Shadow copy of register state. Committed on successful emulation. */ - unsigned long _eflags = ctxt->eflags; memset(decode, 0, sizeof(struct decode_cache)); decode->eip = ctxt->vcpu->rip; @@ -624,8 +620,10 @@ done_prefixes: } /* Unrecognised? */ - if (decode->d == 0) - goto cannot_emulate; + if (decode->d == 0) { + DPRINTF("Cannot emulate %02x\n", decode->b); + return -1; + } } /* ModRM and SIB bytes. */ @@ -789,7 +787,7 @@ done_prefixes: } if (decode->ad_bytes != 8) decode->modrm_ea = (u32)decode->modrm_ea; - cr2 = decode->modrm_ea; + ctxt->cr2 = decode->modrm_ea; modrm_done: ; } @@ -844,13 +842,6 @@ done_prefixes: break; srcmem_common: decode->src.type = OP_MEM; - decode->src.ptr = (unsigned long *)cr2; - decode->src.val = 0; - if ((rc = ops->read_emulated((unsigned long)decode->src.ptr, - &decode->src.val, - decode->src.bytes, ctxt->vcpu)) != 0) - goto done; - decode->src.orig_val = decode->src.val; break; case SrcImm: decode->src.type = OP_IMM; @@ -883,7 +874,7 @@ done_prefixes: switch (decode->d & DstMask) { case ImplicitOps: /* Special instructions do their own operand decoding. */ - goto special_insn; + return 0; case DstReg: decode->dst.type = OP_REG; if ((decode->d & ByteOp) @@ -912,7 +903,44 @@ done_prefixes: break; case DstMem: decode->dst.type = OP_MEM; - decode->dst.ptr = (unsigned long *)cr2; + break; + } + +done: + return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0; +} + +int +x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) +{ + unsigned long cr2 = ctxt->cr2; + int no_wb = 0; + u64 msr_data; + unsigned long _eflags = ctxt->eflags; + struct decode_cache *decode = &ctxt->decode; + int rc; + + rc = x86_decode_insn(ctxt, ops); + if (rc) + return rc; + + if (decode->src.type == OP_MEM) { + decode->src.ptr = (unsigned long *)ctxt->cr2; + decode->src.val = 0; + if ((rc = ops->read_emulated((unsigned long)decode->src.ptr, + &decode->src.val, + decode->src.bytes, + ctxt->vcpu)) != 0) + goto done; + decode->src.orig_val = decode->src.val; + } + + if ((decode->d & DstMask) == ImplicitOps) + goto special_insn; + + + if (decode->dst.type == OP_MEM) { + decode->dst.ptr = (unsigned long *)ctxt->cr2; decode->dst.bytes = (decode->d & ByteOp) ? 1 : decode->op_bytes; decode->dst.val = 0; if (decode->d & BitOp) { @@ -927,7 +955,6 @@ done_prefixes: &decode->dst.val, decode->dst.bytes, ctxt->vcpu)) != 0)) goto done; - break; } decode->dst.orig_val = decode->dst.val; @@ -985,7 +1012,7 @@ done_prefixes: emulate_2op_SrcV("cmp", decode->src, decode->dst, _eflags); break; case 0x63: /* movsxd */ - if (mode != X86EMUL_MODE_PROT64) + if (ctxt->mode != X86EMUL_MODE_PROT64) goto cannot_emulate; decode->dst.val = (s32) decode->src.val; break; @@ -1056,7 +1083,7 @@ push: break; case 0x8f: /* pop (sole member of Grp1a) */ /* 64-bit mode: POP always pops a 64-bit operand. */ - if (mode == X86EMUL_MODE_PROT64) + if (ctxt->mode == X86EMUL_MODE_PROT64) decode->dst.bytes = 8; if ((rc = ops->read_std(register_address( ctxt->ss_base, @@ -1202,7 +1229,7 @@ push: break; case 6: /* push */ /* 64-bit mode: PUSH always pushes a 64-bit operand. */ - if (mode == X86EMUL_MODE_PROT64) { + if (ctxt->mode == X86EMUL_MODE_PROT64) { decode->dst.bytes = 8; if ((rc = ops->read_std( (unsigned long)decode->dst.ptr, --------------060900050200060606090202 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ --------------060900050200060606090202 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --------------060900050200060606090202--