From patchwork Sun May 29 12:59:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 827702 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 p4TCxGZA031080 for ; Sun, 29 May 2011 12:59:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753687Ab1E2M7O (ORCPT ); Sun, 29 May 2011 08:59:14 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:46296 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753606Ab1E2M7N (ORCPT ); Sun, 29 May 2011 08:59:13 -0400 Received: by pvg12 with SMTP id 12so1296752pvg.19 for ; Sun, 29 May 2011 05:59:12 -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=e7Ote2sNJrV1jTtV2F0G1IzmuGpe7q23OtFXax1jND4=; b=Uc1c+M48V+NqyElfcm8seRcShDCmWxWh7uSy2xkJ8xSew5HKNu7XMOAq5N1nE09ERR C+boe4ZOoOqtLgaYzVqk6Z9OYJt1Yady2NfDLIqQ1U9i/JGuhbFsG/vCVINcMwzjPDAe FjmiwJ2dJ8Flr3NyinjPJay5eP8hdl+uiXXUA= 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=vV1X56EveLo0gpcDHRn2tUQVsE8ZHej8CXUYVoV7u/22tVDfPJ/eX/oQhDlrM+YOxY SI9xd6Y7IuuqHzJmuQLFjdzJtw7lDPJtQ+AL4gaTZwPtPantaSiyI9zOjTQx1fSMsep/ LUHO6XKUbsY1WIP2J9Meg51igBlmnqPNqDMDA= Received: by 10.68.21.129 with SMTP id v1mr1596490pbe.413.1306673952876; Sun, 29 May 2011 05:59:12 -0700 (PDT) Received: from amd (x096101.dynamic.ppp.asahi-net.or.jp [122.249.96.101]) by mx.google.com with ESMTPS id a6sm2051367pbo.15.2011.05.29.05.59.10 (version=SSLv3 cipher=OTHER); Sun, 29 May 2011 05:59:12 -0700 (PDT) Date: Sun, 29 May 2011 21:59:09 +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 05/10] KVM: x86 emulator: Use opcode::execute for XCHG(86/87) Message-Id: <20110529215909.047f6a2a.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 12:59:25 +0000 (UTC) From: Takuya Yoshikawa In addition, replace one "goto xchg" with an em_xchg() call. Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/emulate.c | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2e2e87f..16c7507 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2611,6 +2611,20 @@ static int em_test(struct x86_emulate_ctxt *ctxt) return X86EMUL_CONTINUE; } +static int em_xchg(struct x86_emulate_ctxt *ctxt) +{ + struct decode_cache *c = &ctxt->decode; + + /* Write back the register source. */ + c->src.val = c->dst.val; + write_register_operand(&c->src); + + /* Write back the memory destination with implicit LOCK prefix. */ + c->dst.val = c->src.orig_val; + c->lock_prefix = 1; + return X86EMUL_CONTINUE; +} + static int em_imul(struct x86_emulate_ctxt *ctxt) { struct decode_cache *c = &ctxt->decode; @@ -3142,7 +3156,7 @@ static struct opcode opcode_table[256] = { G(ByteOp | DstMem | SrcImm | ModRM | No64 | Group, group1), G(DstMem | SrcImmByte | ModRM | Group, group1), I2bv(DstMem | SrcReg | ModRM, em_test), - D2bv(DstMem | SrcReg | ModRM | Lock), + I2bv(DstMem | SrcReg | ModRM | Lock, em_xchg), /* 0x88 - 0x8F */ I2bv(DstMem | SrcReg | ModRM | Mov, em_mov), I2bv(DstReg | SrcMem | ModRM | Mov, em_mov), @@ -3866,18 +3880,6 @@ special_insn: if (test_cc(c->b, ctxt->eflags)) jmp_rel(c, c->src.val); break; - case 0x86 ... 0x87: /* xchg */ - xchg: - /* Write back the register source. */ - c->src.val = c->dst.val; - write_register_operand(&c->src); - /* - * Write back the memory destination with implicit LOCK - * prefix. - */ - c->dst.val = c->src.orig_val; - c->lock_prefix = 1; - break; case 0x8c: /* mov r/m, sreg */ if (c->modrm_reg > VCPU_SREG_GS) { rc = emulate_ud(ctxt); @@ -3913,7 +3915,8 @@ special_insn: case 0x90 ... 0x97: /* nop / xchg reg, rax */ if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX]) break; - goto xchg; + rc = em_xchg(ctxt); + break; case 0x98: /* cbw/cwde/cdqe */ switch (c->op_bytes) { case 2: c->dst.val = (s8)c->dst.val; break;