From patchwork Sun Jun 22 21:23:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 4396611 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 34C739F383 for ; Sun, 22 Jun 2014 21:24:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC7C52021A for ; Sun, 22 Jun 2014 21:24:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C874C201DE for ; Sun, 22 Jun 2014 21:24:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752496AbaFVVX7 (ORCPT ); Sun, 22 Jun 2014 17:23:59 -0400 Received: from cantor2.suse.de ([195.135.220.15]:33349 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211AbaFVVXo (ORCPT ); Sun, 22 Jun 2014 17:23:44 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4F9BBAD6E; 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 21/33] KVM: PPC: Add and instruction emulation Date: Sun, 22 Jun 2014 23:23:25 +0200 Message-Id: <1403472217-22263-22-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 and instruction in its normal as well as the Rc extended form. Signed-off-by: Alexander Graf --- arch/powerpc/include/asm/ppc-opcode.h | 1 + arch/powerpc/kvm/emulate.c | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h index a92c0e3..d3ff899 100644 --- a/arch/powerpc/include/asm/ppc-opcode.h +++ b/arch/powerpc/include/asm/ppc-opcode.h @@ -88,6 +88,7 @@ #define OP_31_XOP_TRAP 4 #define OP_31_XOP_MFCR 19 #define OP_31_XOP_LWZX 23 +#define OP_31_XOP_AND 28 #define OP_31_XOP_DCBST 54 #define OP_31_XOP_LWZUX 55 #define OP_31_XOP_TRAP_64 68 diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c index 0437d3f..cfe0bf6 100644 --- a/arch/powerpc/kvm/emulate.c +++ b/arch/powerpc/kvm/emulate.c @@ -434,12 +434,52 @@ static int kvmppc_emulate_load(struct kvm_vcpu *vcpu, ulong addr, u64 *value, return r; } +static int kvmppc_emulate_cmp(struct kvm_vcpu *vcpu, u64 value0, u64 value1, + bool cmp_signed, int crf, bool is_32bit) +{ + bool lt, gt, eq; + u32 cr = 0; + u32 cr_mask; + + if (cmp_signed) { + s64 signed0 = value0; + s64 signed1 = value1; + + if (is_32bit) { + signed0 = (s64)(s32)signed0; + signed1 = (s64)(s32)signed1; + } + lt = signed0 < signed1; + gt = signed0 > signed1; + eq = signed0 == signed1; + } else { + if (is_32bit) { + value0 = (u32)value0; + value1 = (u32)value1; + } + lt = value0 < value1; + gt = value0 > value1; + eq = value0 == value1; + } + + if (lt) cr |= 0x8; + if (gt) cr |= 0x4; + if (eq) cr |= 0x2; + cr <<= ((7 - crf) * 4); + cr_mask = 0xf << ((7 - crf) * 4); + cr |= kvmppc_get_cr(vcpu) & ~cr_mask; + kvmppc_set_cr(vcpu, cr); + + return EMULATE_DONE; +} + /* Emulates privileged and non-privileged instructions */ int kvmppc_emulate_any_instruction(struct kvm_vcpu *vcpu) { u32 inst = kvmppc_get_last_inst(vcpu); ulong addr; u64 value; + bool is_32bit = !(kvmppc_get_msr(vcpu) & MSR_SF); enum emulation_result emulated = EMULATE_DONE; int advance = 1; @@ -490,6 +530,14 @@ 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_AND: + value = kvmppc_get_gpr(vcpu, get_rs(inst)); + value &= kvmppc_get_gpr(vcpu, get_rb(inst)); + kvmppc_set_gpr(vcpu, get_ra(inst), value); + if (get_rc(inst)) + kvmppc_emulate_cmp(vcpu, value, 0, true, 0, + is_32bit); + break; default: emulated = EMULATE_FAIL; break;