From patchwork Sun May 1 17:30:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 746262 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p41HUuTc013022 for ; Sun, 1 May 2011 17:30:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755128Ab1EARay (ORCPT ); Sun, 1 May 2011 13:30:54 -0400 Received: from mail-pw0-f46.google.com ([209.85.160.46]:63818 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753305Ab1EARax (ORCPT ); Sun, 1 May 2011 13:30:53 -0400 Received: by pwi15 with SMTP id 15so2400042pwi.19 for ; Sun, 01 May 2011 10:30:53 -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=hF2/FAnF3AQ/CP6hgDCAP+0k/VcRwSzBWyykzOq2WE4=; b=MBnpnIcvL6twDVNlsaS+e8hotE9JQQ08iyn/YOEzi49809Y+NLSORnojUFwNpWavuX QfbEvBnHXuo+jREMyHrfYyQktG77VY3yMd10S5JgPN0w588C08zB60cKchNlDcq2dkql dGn3Z7BGnqQZVeZYI53Rj/Nhu13bxbdDfNcec= 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=gAXO+AOTAiaUnYUAxExhtR+9walYHE2ywG8wJdbe87Kj5AFpi+jhsFZHcr0lc2sNGL iH9PudruPUIvrx43RzDGUBkc3Z8926cQ217SyjLHkYvTFTYA0TzK5/D+mer8tHGHxlDz zT+0jdaTER9390/DwhRCyVt8yoXkOHzqZ/L8Y= Received: by 10.142.250.15 with SMTP id x15mr2941188wfh.187.1304271053058; Sun, 01 May 2011 10:30:53 -0700 (PDT) Received: from amd (s198099.dynamic.ppp.asahi-net.or.jp [220.157.198.99]) by mx.google.com with ESMTPS id k7sm5981979wfa.2.2011.05.01.10.30.50 (version=SSLv3 cipher=OTHER); Sun, 01 May 2011 10:30:52 -0700 (PDT) Date: Mon, 2 May 2011 02:30:48 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp Subject: [PATCH 6/6] KVM: x86 emulator: Make jmp far emulation into a separate function Message-Id: <20110502023048.0ad2f271.takuya.yoshikawa@gmail.com> In-Reply-To: <20110502022143.0ef5d756.takuya.yoshikawa@gmail.com> References: <20110502022143.0ef5d756.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0beta2 (GTK+ 2.22.0; 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 (demeter2.kernel.org [140.211.167.43]); Sun, 01 May 2011 17:30:56 +0000 (UTC) From: Takuya Yoshikawa We introduce em_jmp_far(). We also call this from em_grp45() to stop treating modrm_reg == 5 case separately in the group 5 emulation. Signed-off-by: Takuya Yoshikawa --- arch/x86/kvm/emulate.c | 36 ++++++++++++++++++++++-------------- 1 files changed, 22 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index cd2f89d..291c872 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -1687,6 +1687,23 @@ static inline int emulate_iret(struct x86_emulate_ctxt *ctxt, } } +static int em_jmp_far(struct x86_emulate_ctxt *ctxt) +{ + struct decode_cache *c = &ctxt->decode; + int rc; + unsigned short sel; + + memcpy(&sel, c->src.valptr + c->op_bytes, 2); + + rc = load_segment_descriptor(ctxt, ctxt->ops, sel, VCPU_SREG_CS); + if (rc != X86EMUL_CONTINUE) + return rc; + + c->eip = 0; + memcpy(&c->eip, c->src.valptr, c->op_bytes); + return X86EMUL_CONTINUE; +} + static int em_grp1a(struct x86_emulate_ctxt *ctxt) { struct decode_cache *c = &ctxt->decode; @@ -1786,6 +1803,9 @@ static int em_grp45(struct x86_emulate_ctxt *ctxt) case 4: /* jmp abs */ c->eip = c->src.val; break; + case 5: /* jmp far */ + rc = em_jmp_far(ctxt); + break; case 6: /* push */ rc = em_push(ctxt); break; @@ -3997,19 +4017,9 @@ special_insn: } case 0xe9: /* jmp rel */ goto jmp; - case 0xea: { /* jmp far */ - unsigned short sel; - jump_far: - memcpy(&sel, c->src.valptr + c->op_bytes, 2); - - rc = load_segment_descriptor(ctxt, ops, sel, VCPU_SREG_CS); - if (rc != X86EMUL_CONTINUE) - goto done; - - c->eip = 0; - memcpy(&c->eip, c->src.valptr, c->op_bytes); + case 0xea: /* jmp far */ + rc = em_jmp_far(ctxt); break; - } case 0xeb: jmp: /* jmp rel short */ jmp_rel(c, c->src.val); @@ -4073,8 +4083,6 @@ special_insn: rc = em_grp45(ctxt); break; case 0xff: /* Grp5 */ - if (c->modrm_reg == 5) - goto jump_far; rc = em_grp45(ctxt); break; default: