From patchwork Sun Jun 22 21:23:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 4396701 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 29E5EBEECB for ; Sun, 22 Jun 2014 21:24:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BFF3201DE for ; Sun, 22 Jun 2014 21:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74D1D2021A for ; Sun, 22 Jun 2014 21:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752569AbaFVVYl (ORCPT ); Sun, 22 Jun 2014 17:24:41 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33362 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbaFVVXp (ORCPT ); Sun, 22 Jun 2014 17:23:45 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 615C1AD75; Sun, 22 Jun 2014 21:23:38 +0000 (UTC) From: Alexander Graf To: kvm-ppc@vger.kernel.org Cc: kvm@vger.kernel.org Subject: [PATCH 26/33] KVM: PPC: Add mtcrf instruction emulation Date: Sun, 22 Jun 2014 23:23:30 +0200 Message-Id: <1403472217-22263-27-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1403472217-22263-1-git-send-email-agraf@suse.de> References: <1403472217-22263-1-git-send-email-agraf@suse.de> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds emulation support for the mtcrf instruction. Signed-off-by: Alexander Graf --- arch/powerpc/include/asm/ppc-opcode.h | 1 + arch/powerpc/kvm/emulate.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h index e130156..86c510e 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -94,6 +94,7 @@ #define OP_31_XOP_TRAP_64 68 #define OP_31_XOP_DCBF 86 #define OP_31_XOP_LBZX 87 +#define OP_31_XOP_MTCRF 144 #define OP_31_XOP_STWX 151 #define OP_31_XOP_STBX 215 #define OP_31_XOP_LBZUX 119 diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index aeadc30..d6e0e4b 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -521,6 +521,28 @@ int kvmppc_emulate_bc(struct kvm_vcpu *vcpu, u32 inst, bool is_32bit) return EMULATE_AGAIN; } +int kvmppc_emulate_mtcrf(struct kvm_vcpu *vcpu, u32 inst) +{ + u32 value = kvmppc_get_cr(vcpu); + u32 new_cr = kvmppc_get_gpr(vcpu, get_rs(inst)); + u32 mask = 0; + int fxm = (inst >> 12) & 0xff; + + if (fxm & 0x80) mask |= 0xf0000000; + if (fxm & 0x40) mask |= 0x0f000000; + if (fxm & 0x20) mask |= 0x00f00000; + if (fxm & 0x10) mask |= 0x000f0000; + if (fxm & 0x08) mask |= 0x0000f000; + if (fxm & 0x04) mask |= 0x00000f00; + if (fxm & 0x02) mask |= 0x000000f0; + if (fxm & 0x01) mask |= 0x0000000f; + + value = value & ~mask; + value |= new_cr & mask; + kvmppc_set_cr(vcpu, value); + return EMULATE_DONE; +} + /* Emulates privileged and non-privileged instructions */ int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu) { @@ -592,6 +614,9 @@ int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu) case OP_31_XOP_MFCR: kvmppc_set_gpr(vcpu, get_rt(inst), kvmppc_get_cr(vcpu)); break; + case OP_31_XOP_MTCRF: + emulated = kvmppc_emulate_mtcrf(vcpu, inst); + break; case OP_31_XOP_AND: value = kvmppc_get_gpr(vcpu, get_rs(inst)); value &= kvmppc_get_gpr(vcpu, get_rb(inst));