From patchwork Tue Oct 21 16:55:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 39186 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7E3542039B for ; Tue, 21 Oct 2014 17:10:23 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id b57sf672119eek.8 for ; Tue, 21 Oct 2014 10:10:22 -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=iRsH254fNTE4Fga3t3AXwJAqMTJXqQVsWxvLXonk4Es=; b=OaseticMsk47qMM7bDSzBlFzgNCXmTgyfL1V1MGnP/qV8O9Jz8aqLUZA1Ab7tZh+Bs fpjVQxmC38DrWa0Lf7km9FY0EyLBi6kFkPSfivxT98RcZ7jkARiKRkcL/Yvt+tjBmNRC AnlV/elT3A3an9h+aywhMPBhkkc1uFp6u8C+48XF6U8wcA7C14rV+emEeHjt12dzrh3q ecrziq5sMcibLs5INjzddcYnQN8XXyCSe8UVFynr/0ms8qh1w0eYktjD1KKnRZu/mg81 UXBkX2C9HtfHYgR/EoIsnT0L26y3Ph4ycEQjqrsybFaM/QdJlwou7mCEeMnUP35L1683 /4Fw== X-Gm-Message-State: ALoCoQm86jr8B7VmpDnhyAWbez+fa5hItOk42iwRBp2tluByXGloIsTaDKwWJXk+V7OXZjJb+l7T X-Received: by 10.180.186.142 with SMTP id fk14mr3784781wic.4.1413911422220; Tue, 21 Oct 2014 10:10:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.44.169 with SMTP id f9ls81950lam.11.gmail; Tue, 21 Oct 2014 10:10:21 -0700 (PDT) X-Received: by 10.152.206.11 with SMTP id lk11mr36891307lac.42.1413911421844; Tue, 21 Oct 2014 10:10:21 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id jo7si12069431lbc.39.2014.10.21.10.10.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 21 Oct 2014 10:10:21 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so1415821lbv.10 for ; Tue, 21 Oct 2014 10:10:21 -0700 (PDT) X-Received: by 10.153.8.164 with SMTP id dl4mr36235354lad.29.1413911421599; Tue, 21 Oct 2014 10:10:21 -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 c5csp543282lbz; Tue, 21 Oct 2014 10:10:20 -0700 (PDT) X-Received: by 10.229.124.9 with SMTP id s9mr47843825qcr.15.1413911420316; Tue, 21 Oct 2014 10:10:20 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e6si23501646qar.66.2014.10.21.10.10.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 21 Oct 2014 10:10:18 -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]:52514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgcwr-0003lc-4l for patch@linaro.org; Tue, 21 Oct 2014 13:10:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgcjE-0006og-K2 for qemu-devel@nongnu.org; Tue, 21 Oct 2014 12:56:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgcj9-0006tN-Gy for qemu-devel@nongnu.org; Tue, 21 Oct 2014 12:56:12 -0400 Received: from mail-qg0-f48.google.com ([209.85.192.48]:57042) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgcj9-0006tC-CL for qemu-devel@nongnu.org; Tue, 21 Oct 2014 12:56:07 -0400 Received: by mail-qg0-f48.google.com with SMTP id i50so1194653qgf.35 for ; Tue, 21 Oct 2014 09:56:07 -0700 (PDT) X-Received: by 10.224.97.10 with SMTP id j10mr15117157qan.103.1413910566432; Tue, 21 Oct 2014 09:56:06 -0700 (PDT) Received: from gbellows-linaro.qualcomm.com ([67.52.129.61]) by mx.google.com with ESMTPSA id a3sm11122116qaa.49.2014.10.21.09.56.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 21 Oct 2014 09:56:06 -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: Tue, 21 Oct 2014 11:55:28 -0500 Message-Id: <1413910544-20150-17-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1413910544-20150-1-git-send-email-greg.bellows@linaro.org> References: <1413910544-20150-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.192.48 Cc: greg.bellows@linaro.org Subject: [Qemu-devel] [PATCH v7 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.217.179 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 a22fcb2..2af8fbb 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); }