From patchwork Sun May 29 13:01:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 827722 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4TD1ev4032215 for ; Sun, 29 May 2011 13:01:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753625Ab1E2NBh (ORCPT ); Sun, 29 May 2011 09:01:37 -0400 Received: from mail-px0-f179.google.com ([209.85.212.179]:34509 "EHLO mail-px0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753560Ab1E2NBh (ORCPT ); Sun, 29 May 2011 09:01:37 -0400 Received: by pxi2 with SMTP id 2so1992459pxi.10 for ; Sun, 29 May 2011 06:01:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding; bh=JWIq28iDCz4Apq+W43Xpbmam0ef7iNhY6QnCuoduUB4=; b=G9L96/2O88Ty5sBoYwze+Jk3EPXLZi9scPclXgR0aK/Ms51dJsqqFytD2aVCuFHY3W pPPt4S30N+K0uSrxg1iPHr8WoF7IW/eFqxoPFwLVqYOOGCbhYiq9XPZ9mlJejwGhz+ge 31O4kMcrfPiYNm5aS8HWrYmUE9vE39aOrib3k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; b=J4ZtcS9zCW2rLsg1/87YmU6yFhj8sZoQOOkGd6cM6OsCy2yUkUONhX1o+uqWJUMtkx 0j1pRwY9R5ODbIyq4kTSd+gDD7qHBHfpunlioKoAKbZYg6uT9jKgRUiwfBUDxMGKtsk/ 7uMj3ELgLOqSa9D0aPs3AtsmDHIQip8kxFMts= Received: by 10.68.17.134 with SMTP id o6mr385912pbd.326.1306674096937; Sun, 29 May 2011 06:01:36 -0700 (PDT) Received: from amd (x096101.dynamic.ppp.asahi-net.or.jp [122.249.96.101]) by mx.google.com with ESMTPS id w2sm2052520pbg.37.2011.05.29.06.01.34 (version=SSLv3 cipher=OTHER); Sun, 29 May 2011 06:01:36 -0700 (PDT) Date: Sun, 29 May 2011 22:01:33 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp, gleb@redhat.com Subject: [PATCH 07/10] KVM: x86 emulator: Use opcode::execute for MOV(8C/8E) Message-Id: <20110529220133.e3ff326b.takuya.yoshikawa@gmail.com> In-Reply-To: <20110529215200.17be7761.takuya.yoshikawa@gmail.com> References: <20110529215200.17be7761.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0 (GTK+ 2.24.4; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 29 May 2011 13:01:47 +0000 (UTC) From: Takuya Yoshikawa Different functions for those which take segment register operands. Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/emulate.c | 59 +++++++++++++++++++++++++---------------------- 1 files changed, 31 insertions(+), 28 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 759ec7c..7a06fb2 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2681,6 +2681,33 @@ static int em_mov(struct x86_emulate_ctxt *ctxt) return X86EMUL_CONTINUE; } +static int em_mov_rm_sreg(struct x86_emulate_ctxt *ctxt) +{ + struct decode_cache *c = &ctxt->decode; + + if (c->modrm_reg > VCPU_SREG_GS) + return emulate_ud(ctxt); + + c->dst.val = get_segment_selector(ctxt, c->modrm_reg); + return X86EMUL_CONTINUE; +} + +static int em_mov_sreg_rm(struct x86_emulate_ctxt *ctxt) +{ + struct decode_cache *c = &ctxt->decode; + u16 sel = c->src.val; + + if (c->modrm_reg == VCPU_SREG_CS || c->modrm_reg > VCPU_SREG_GS) + return emulate_ud(ctxt); + + if (c->modrm_reg == VCPU_SREG_SS) + ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS; + + /* Disable writeback. */ + c->dst.type = OP_NONE; + return load_segment_descriptor(ctxt, sel, c->modrm_reg); +} + static int em_movdqu(struct x86_emulate_ctxt *ctxt) { struct decode_cache *c = &ctxt->decode; @@ -3170,8 +3197,10 @@ static struct opcode opcode_table[256] = { /* 0x88 - 0x8F */ I2bv(DstMem | SrcReg | ModRM | Mov, em_mov), I2bv(DstReg | SrcMem | ModRM | Mov, em_mov), - D(DstMem | SrcNone | ModRM | Mov), D(ModRM | SrcMem | NoAccess | DstReg), - D(ImplicitOps | SrcMem16 | ModRM), G(0, group1A), + I(DstMem | SrcNone | ModRM | Mov, em_mov_rm_sreg), + D(ModRM | SrcMem | NoAccess | DstReg), + I(ImplicitOps | SrcMem16 | ModRM, em_mov_sreg_rm), + G(0, group1A), /* 0x90 - 0x97 */ DI(SrcAcc | DstReg, pause), X7(D(SrcAcc | DstReg)), /* 0x98 - 0x9F */ @@ -3890,35 +3919,9 @@ special_insn: if (test_cc(c->b, ctxt->eflags)) jmp_rel(c, c->src.val); break; - case 0x8c: /* mov r/m, sreg */ - if (c->modrm_reg > VCPU_SREG_GS) { - rc = emulate_ud(ctxt); - goto done; - } - c->dst.val = get_segment_selector(ctxt, c->modrm_reg); - break; case 0x8d: /* lea r16/r32, m */ c->dst.val = c->src.addr.mem.ea; break; - case 0x8e: { /* mov seg, r/m16 */ - uint16_t sel; - - sel = c->src.val; - - if (c->modrm_reg == VCPU_SREG_CS || - c->modrm_reg > VCPU_SREG_GS) { - rc = emulate_ud(ctxt); - goto done; - } - - if (c->modrm_reg == VCPU_SREG_SS) - ctxt->interruptibility = KVM_X86_SHADOW_INT_MOV_SS; - - rc = load_segment_descriptor(ctxt, sel, c->modrm_reg); - - c->dst.type = OP_NONE; /* Disable writeback. */ - break; - } case 0x8f: /* pop (sole member of Grp1a) */ rc = em_grp1a(ctxt); break;