From patchwork Thu Jul 19 07:40:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 1215701 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 8E146E006E for ; Thu, 19 Jul 2012 07:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753263Ab2GSHlV (ORCPT ); Thu, 19 Jul 2012 03:41:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13577 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752088Ab2GSHlB (ORCPT ); Thu, 19 Jul 2012 03:41:01 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6J7f0af003588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Jul 2012 03:41:00 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-4-26.tlv.redhat.com [10.35.4.26]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6J7exN6023292; Thu, 19 Jul 2012 03:41:00 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 7343E18D47F; Thu, 19 Jul 2012 10:40:59 +0300 (IDT) From: Gleb Natapov To: kvm@vger.kernel.org Cc: avi@redhat.com, mtosatti@redhat.com Subject: [PATCHv4 3/5] KVM: emulator: move some address manipulation function out of emulator code. Date: Thu, 19 Jul 2012 10:40:51 +0300 Message-Id: <1342683653-32114-4-git-send-email-gleb@redhat.com> In-Reply-To: <1342683653-32114-1-git-send-email-gleb@redhat.com> References: <1342683653-32114-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The functions will be used outside of the emulator. Signed-off-by: Gleb Natapov --- arch/x86/include/asm/kvm_host.h | 25 +++++++++++++++++++++++++ arch/x86/kvm/emulate.c | 15 ++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index de2aff8..6212575 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -980,4 +980,29 @@ int kvm_pmu_read_pmc(struct kvm_vcpu *vcpu, unsigned pmc, u64 *data); void kvm_handle_pmu_event(struct kvm_vcpu *vcpu); void kvm_deliver_pmi(struct kvm_vcpu *vcpu); +static inline unsigned long kvm_ad_mask(u8 ad_bytes) +{ + return (1UL << (ad_bytes << 3)) - 1; +} + +/* Access/update address held in a register, based on addressing mode. */ +static inline unsigned long +kvm_address_mask(u8 ad_bytes, unsigned long reg) +{ + if (ad_bytes == sizeof(unsigned long)) + return reg; + else + return reg & kvm_ad_mask(ad_bytes); +} + +static inline void +kvm_register_address_increment(u8 ad_bytes, unsigned long *reg, int inc) +{ + if (ad_bytes == sizeof(unsigned long)) + *reg += inc; + else + *reg = (*reg & ~kvm_ad_mask(ad_bytes)) | + ((*reg + inc) & kvm_ad_mask(ad_bytes)); +} + #endif /* _ASM_X86_KVM_HOST_H */ diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 79899df..e317588 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -433,19 +433,11 @@ static int emulator_check_intercept(struct x86_emulate_ctxt *ctxt, return ctxt->ops->intercept(ctxt, &info, stage); } -static inline unsigned long ad_mask(struct x86_emulate_ctxt *ctxt) -{ - return (1UL << (ctxt->ad_bytes << 3)) - 1; -} - /* Access/update address held in a register, based on addressing mode. */ static inline unsigned long address_mask(struct x86_emulate_ctxt *ctxt, unsigned long reg) { - if (ctxt->ad_bytes == sizeof(unsigned long)) - return reg; - else - return reg & ad_mask(ctxt); + return kvm_address_mask(ctxt->ad_bytes, reg); } static inline unsigned long @@ -457,10 +449,7 @@ register_address(struct x86_emulate_ctxt *ctxt, unsigned long reg) static inline void register_address_increment(struct x86_emulate_ctxt *ctxt, unsigned long *reg, int inc) { - if (ctxt->ad_bytes == sizeof(unsigned long)) - *reg += inc; - else - *reg = (*reg & ~ad_mask(ctxt)) | ((*reg + inc) & ad_mask(ctxt)); + return kvm_register_address_increment(ctxt->ad_bytes, reg, inc); } static inline void jmp_rel(struct x86_emulate_ctxt *ctxt, int rel)