From patchwork Fri Oct 10 16:03:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 38603 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7A2D9205D8 for ; Fri, 10 Oct 2014 16:10:29 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id cc10sf1023713wib.3 for ; Fri, 10 Oct 2014 09:10:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=+tD/Knw5SLtCV5MMSlSg1/+/Ev20/r5h5IYI1G8cOSE=; b=ej8JiEm+RnuxK9EgCRxM1/XRNcqM3bHiLz2b/6y1OL6oXKeQsGNEFSO3tQHtC8xLnk AOQLIS2AWvUmcC9vu8fLwAHyq15uPqsM3SohbRrIzmouyxLX+cBo53ECy9Qv25NehBm8 BjWkt1biPk3lUdMRCMUPlNAU8pa3uy46BFWQNYkX5jwz9UWP41JqMmbu0hm7vjvcVnkC QXj8Flpa3QAJZQY4p+ieml54b52+6YkFRpyPpAlrrTy0uKP8Mcv8mIU/J65apafIgmZM kF+Ghb9GmvNTu1C6j9pnFIZky6blRHS/88Zb/VyyA09DplAzKsz++vYOMpX9bcgWvV1Z /G3g== X-Gm-Message-State: ALoCoQkzmzAFa41Cd+aY1nc8+1JjTsS5bkaKlGNqW7QFyu/7wS7Kitp2UlHM7hD85rpC82IQGRTV X-Received: by 10.112.74.80 with SMTP id r16mr18444lbv.21.1412957428684; Fri, 10 Oct 2014 09:10:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.39 with SMTP id 7ls262065lar.87.gmail; Fri, 10 Oct 2014 09:10:28 -0700 (PDT) X-Received: by 10.112.189.103 with SMTP id gh7mr5885871lbc.18.1412957428536; Fri, 10 Oct 2014 09:10:28 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by mx.google.com with ESMTPS id ba3si9927101lbc.92.2014.10.10.09.10.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:10:28 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id pv20so3523308lab.6 for ; Fri, 10 Oct 2014 09:10:28 -0700 (PDT) X-Received: by 10.152.22.42 with SMTP id a10mr6030898laf.56.1412957428401; Fri, 10 Oct 2014 09:10:28 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp456715lbz; Fri, 10 Oct 2014 09:10:27 -0700 (PDT) X-Received: by 10.224.72.84 with SMTP id l20mr10124109qaj.93.1412957427091; Fri, 10 Oct 2014 09:10:27 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o7si11691890qai.67.2014.10.10.09.10.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:10:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:49424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xcclt-0007qt-24 for patch@linaro.org; Fri, 10 Oct 2014 12:10:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccfx-00076s-I3 for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xccfq-00084P-VK for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:17 -0400 Received: from mail-oi0-f50.google.com ([209.85.218.50]:60614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccfq-00084K-P7 for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:10 -0400 Received: by mail-oi0-f50.google.com with SMTP id i138so7074042oig.37 for ; Fri, 10 Oct 2014 09:04:10 -0700 (PDT) X-Received: by 10.202.11.72 with SMTP id 69mr5290201oil.40.1412957050359; Fri, 10 Oct 2014 09:04:10 -0700 (PDT) Received: from gbellows-linaro.bellowshome.net (99-179-1-128.lightspeed.austtx.sbcglobal.net. [99.179.1.128]) by mx.google.com with ESMTPSA id d6sm5382455obt.12.2014.10.10.09.04.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:04:09 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch Date: Fri, 10 Oct 2014 11:03:27 -0500 Message-Id: <1412957023-11105-17-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1412957023-11105-1-git-send-email-greg.bellows@linaro.org> References: <1412957023-11105-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.50 Subject: [Qemu-devel] [PATCH v6 16/32] target-arm: respect SCR.FW, SCR.AW and SCTLR.NMFI X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: greg.bellows@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Fabian Aggeler bits when modifying CPSR. Signed-off-by: Fabian Aggeler Signed-off-by: Greg Bellows --------------- v3 -> v4 - Fixed up conditions for ignoring CPSR.A/F updates by isolating to v7 and checking for the existence of EL3 and non-existence of EL2. --- target-arm/helper.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/target-arm/helper.c b/target-arm/helper.c index 760e3f9..6d0f3ec 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3645,9 +3645,6 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) env->GE = (val >> 16) & 0xf; } - env->daif &= ~(CPSR_AIF & mask); - env->daif |= val & CPSR_AIF & mask; - if ((env->uncached_cpsr ^ val) & mask & CPSR_M) { if (bad_mode_switch(env, val & CPSR_M)) { /* Attempt to switch to an invalid mode: this is UNPREDICTABLE. @@ -3659,6 +3656,65 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) switch_mode(env, val & CPSR_M); } } + + /* In a V7 implementation that incldoes the security extensions but does + * not include Virtualization Extensions the SCR.FW and SCR.AW bits control + * whether non-secure software is allowed to change the CPSR_F and CPSR_A + * bits respectively. + * + * In a V8 implementation, it is permitted for privileged software to + * change the CPSR A/F bits regardless of the SCR.AW/FW bits. However, + * when the SPSR is copied to the CPSR, the SCR.AW/FW bits control whether + * the CPSR.A/F bits are copied. + */ + if (!arm_feature(env, ARM_FEATURE_V8)) { + if ((mask & CPSR_A) && + (val & CPSR_A) != (env->uncached_cpsr & CPSR_A) && + arm_feature(env, ARM_FEATURE_EL3) && + !arm_feature(env, ARM_FEATURE_EL2) && + !(env->cp15.scr_el3 & SCR_AW) && !arm_is_secure(env)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Ignoring attempt to switch CPSR_A flag from " + "non-secure world with SCR.AW bit clear\n"); + mask &= ~CPSR_A; + } + + if ((mask & CPSR_F) && + (val & CPSR_F) != (env->uncached_cpsr & CPSR_F)) { + /* + * The existence of the security extension (EL3) and the + * non-existence of the virtualization extension affects whether + * the CPSR.F bit can be modified. + */ + if (arm_feature(env, ARM_FEATURE_EL3) && + !arm_feature(env, ARM_FEATURE_EL2)) { + /* CPSR.F cannot be changed in nonsecure with SCR.FW clear */ + if (!(env->cp15.scr_el3 & SCR_FW) && !arm_is_secure(env)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Ignoring attempt to switch CPSR_F flag from " + "non-secure world with SCR.FW bit clear\n"); + mask &= ~CPSR_F; + } + + /* Check whether non-maskable FIQ (NMFI) support is enabled. + * If this bit is set software is not allowed to mask + * FIQs, but is allowed to set CPSR_F to 0. + */ + if ((A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_NMFI) && + (val & CPSR_F)) { + qemu_log_mask(LOG_GUEST_ERROR, + "Ignoring attempt to enable CPSR_F flag " + "(non-maskable FIQ [NMFI] support " + "enabled)\n"); + mask &= ~CPSR_F; + } + } + } + } + + env->daif &= ~(CPSR_AIF & mask); + env->daif |= val & CPSR_AIF & mask; + mask &= ~CACHED_CPSR_BITS; env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask); }