From patchwork Mon Jun 30 23:09:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 32838 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C9FEF203F4 for ; Tue, 1 Jul 2014 00:58:50 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kq14sf48371070pab.4 for ; Mon, 30 Jun 2014 17:58:49 -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:cc: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=PKBORh8W/mDMzPsBGa8ZwdKKzlhIMn7SJQmkiJdvUTw=; b=dJs8Y034hWbb5G58sdzLZvTnRgw4I6s2dWnG3YqvoTr2TpQz0pnwvmu9NM3bQ0KH41 FoB7FH3pCsftjaIpiEjjpV4mTB9N7Ar0mijpl2dCGFuXfJSd679WlBWsfPzKXuo3t0Fr RhYuYecy7WfOAKSFC05bqIDKGpzPyIGWY2BHt+VZbdjA+cJOUScHPhukwwxSRF1Hbu00 2O8RAhFPoCitIvm/qYjU3Gvdu1oNILylVwtQR/wOqjK8tPQzhM9gBvUmG6TQCx5Y557m tJL+3QSQaOIv6s2IgeCG0paeE7o4yyh0FiVGcVV+qTmyqzJm1JX+G9Qn0eX5i4MmfCrS /12A== X-Gm-Message-State: ALoCoQmtnu0x6mfCQ9JSUuKSrSR/qxNJUMfOYcU9N5KnxTkHX1KzxUSm7aViAQOYVXhMV+sAeXxt X-Received: by 10.66.122.101 with SMTP id lr5mr24121123pab.19.1404176329687; Mon, 30 Jun 2014 17:58:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.107 with SMTP id f98ls528344qge.65.gmail; Mon, 30 Jun 2014 17:58:49 -0700 (PDT) X-Received: by 10.52.163.208 with SMTP id yk16mr5452892vdb.36.1404176329574; Mon, 30 Jun 2014 17:58:49 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id dn3si10797615vcb.40.2014.06.30.17.58.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 17:58:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.178 as permitted sender) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id oy12so8939303veb.37 for ; Mon, 30 Jun 2014 17:58:49 -0700 (PDT) X-Received: by 10.220.59.65 with SMTP id k1mr41100853vch.22.1404176329466; Mon, 30 Jun 2014 17:58:49 -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.221.37.5 with SMTP id tc5csp179557vcb; Mon, 30 Jun 2014 17:58:47 -0700 (PDT) X-Received: by 10.224.12.138 with SMTP id x10mr16449424qax.36.1404176327350; Mon, 30 Jun 2014 17:58:47 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x9si27225798qax.121.2014.06.30.17.58.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Jun 2014 17:58:47 -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]:37079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1knJ-0002Ou-6J for patch@linaro.org; Mon, 30 Jun 2014 19:15:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1kiw-0005rY-3g for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:11:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1kiq-0003N0-Sz for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:58 -0400 Received: from mail-oa0-f51.google.com ([209.85.219.51]:53736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1kiq-0003Mb-NT for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:52 -0400 Received: by mail-oa0-f51.google.com with SMTP id j17so9808882oag.10 for ; Mon, 30 Jun 2014 16:10:52 -0700 (PDT) X-Received: by 10.60.84.233 with SMTP id c9mr10313095oez.0.1404169852382; Mon, 30 Jun 2014 16:10:52 -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 cu7sm76370192oec.12.2014.06.30.16.10.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 16:10:51 -0700 (PDT) From: greg.bellows@linaro.org To: qemu-devel@nongnu.org Date: Mon, 30 Jun 2014 18:09:14 -0500 Message-Id: <1404169773-20264-15-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404169773-20264-1-git-send-email-greg.bellows@linaro.org> References: <1404169773-20264-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.219.51 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, Fabian Aggeler , Greg Bellows , serge.fdrv@gmail.com, edgar.iglesias@gmail.com, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v4 14/33] 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.128.178 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. Signed-off-by: Greg Bellows --- 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 7a878e9..e43545a 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3106,9 +3106,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. @@ -3120,6 +3117,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); }