From patchwork Sat Aug 14 00:19:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mohammed Gamal X-Patchwork-Id: 119533 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o7E0K5h8002760 for ; Sat, 14 Aug 2010 00:20:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756458Ab0HNATy (ORCPT ); Fri, 13 Aug 2010 20:19:54 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:49407 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754313Ab0HNATy (ORCPT ); Fri, 13 Aug 2010 20:19:54 -0400 Received: by wyb32 with SMTP id 32so3231606wyb.19 for ; Fri, 13 Aug 2010 17:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=UAwFB706RVEgtUZVun311WAt/oDQJt5irl/qaC/KMYI=; b=wSWp28EWLlddixt3SPtrogKrZh7imukf0KUiqKRN6OhfUS91J0unC1SjlrIeRA6uts NIMPT8kOBaCC+szatAFUuhJ4fdR+lj8Ywj90fZPGvKBnoYBdDa+OhvsEYl5gcLjVcvDW dajWmlaxmZf2bqpj9qxa5W/l+eTstQlA/hjgg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=aoar+A6MVFrqqI0/sAFb+JthRxhPCfPaQbLkuo82luTX+gwCH0q0rRM8/7ZRn/SmRL zMlEeDgKHFRN6BI/EEtz0XhT3qOdhY8dpnCYSN0ZJvjxLICCTo+SWZseGe9JW08WTvhz tTpyM5k3mvoaKh44eCnrSTNxOJxo/eDnq18Cc= Received: by 10.216.50.18 with SMTP id y18mr90248web.113.1281745193133; Fri, 13 Aug 2010 17:19:53 -0700 (PDT) Received: from localhost.localdomain ([188.55.88.49]) by mx.google.com with ESMTPS id v44sm1915180weq.28.2010.08.13.17.19.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 13 Aug 2010 17:19:52 -0700 (PDT) From: Mohammed Gamal To: avi@redhat.com Cc: mtosatti@redhat.com, kvm@vger.kernel.org, Mohammed Gamal Subject: [RFC PATCH v2 2/4] x86: Add inject_realmode_interrupt() wrapper Date: Sat, 14 Aug 2010 03:19:39 +0300 Message-Id: <1281745181-4426-1-git-send-email-m.gamal005@gmail.com> X-Mailer: git-send-email 1.7.0.4 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.3 (demeter.kernel.org [140.211.167.41]); Sat, 14 Aug 2010 00:20:05 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1722d37..d3ba1c3 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3936,6 +3936,39 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu) kvm_queue_exception(vcpu, ctxt->exception); } +int inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq) +{ + struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode; + int cs_db, cs_l, ret; + cache_all_regs(vcpu); + + kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l); + + vcpu->arch.emulate_ctxt.vcpu = vcpu; + vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu); + vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu); + vcpu->arch.emulate_ctxt.mode = + (!is_protmode(vcpu)) ? X86EMUL_MODE_REAL : + (vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM) + ? X86EMUL_MODE_VM86 : cs_l + ? X86EMUL_MODE_PROT64 : cs_db + ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16; + memset(c, 0, sizeof(struct decode_cache)); + memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); + + ret = emulate_int_real(&vcpu->arch.emulate_ctxt, &emulate_ops, irq); + + if (ret != X86EMUL_CONTINUE) + return EMULATE_FAIL; + + memcpy(vcpu->arch.regs, c->regs, sizeof c->regs); + kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip); + kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags); + + return EMULATE_DONE; +} +EXPORT_SYMBOL_GPL(inject_realmode_interrupt); + static int handle_emulation_failure(struct kvm_vcpu *vcpu) { ++vcpu->stat.insn_emulation_fail; diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index b7a4047..c6e8a4d 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -67,5 +67,6 @@ static inline int is_paging(struct kvm_vcpu *vcpu) void kvm_before_handle_nmi(struct kvm_vcpu *vcpu); void kvm_after_handle_nmi(struct kvm_vcpu *vcpu); +int inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq); #endif