From patchwork Thu Oct 24 16:26:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 177559 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp2417335ocf; Thu, 24 Oct 2019 09:55:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvfyiiNseqiqsLg45ZFRfbcWSOcZV2YgN5JAeFMHhPmdP7CzNec+OM25/6lxYEVV6W8Ldz X-Received: by 2002:a37:4b4f:: with SMTP id y76mr2331315qka.488.1571936105001; Thu, 24 Oct 2019 09:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571936104; cv=none; d=google.com; s=arc-20160816; b=j6NGr1R2WRGdhF/YP0j7IaAIZ5UZCZz72aR+8yDBfCyjjE9DuvrMnL/T2JyJ37f1t4 nFNYOMmU+/Stt/KQwWMXuvEkOCGjdQbhc4Tyk6xAs51bcVvBKRQmXRXJYAnyZkHykAuA QKjfgWK4P8/qT3RWvA4BNhhRnotmPXtUavO/VdzOjSlWmpN0hLOuI/S1uoNq+RUDRQme dHOoeoT28dlSTmWOxwweiqvGZZkBAVXOu4f0Hz2qJ5rc8SZDeb0jyZsTxtvOC4i4cFKN 7cm/VcZVuMer70gpUG7Y0wAViG9WPWi1RSbXRLyhU5ezNc1kMe3R4UmJF2WP1Bbf/JsI NvEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=W/AkGYR57m74r9FQYLQ/SGWlTLm2K1Vi5lkbHPvwzOg=; b=w12UlJpWyYHXO4ERkysRdlC3bZT3U5gXguqn70hQVx6v8GmOviYaEmLWcu5qtL1JTX PWCQQ56zoyC3pld4RBMJRFG8rnfJSaV/+8M0cej4UrCqjOlZ/mtYzkRe8lFbCK6C9R6N VlDylpLYpEElOGzeF1bSuwxflad2JcCGsMs4hga1VOvA9jEOdURjI5JXw4fZ0Dc9mmNE 07glgC5JzNwfH3mL/rXzkrnnqoDcLWjurNht11g6RTz0zrnrGmAK/kLCPsOyVmJVvFvY MCKhenfUsTyGj3ZGfkbq7HR+GSBamijukw2AXUudXiep3es8G8oIHBCsflQKhLClFj02 7Zlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v+ohkY56; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e47si25085567qvh.93.2019.10.24.09.55.04 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Oct 2019 09:55:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v+ohkY56; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNgO8-0006Gl-2T for patch@linaro.org; Thu, 24 Oct 2019 12:55:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57720) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNfxZ-00070E-Tf for qemu-devel@nongnu.org; Thu, 24 Oct 2019 12:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNfxY-0000h5-KY for qemu-devel@nongnu.org; Thu, 24 Oct 2019 12:27:37 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:35004) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNfxY-0000gq-DO for qemu-devel@nongnu.org; Thu, 24 Oct 2019 12:27:36 -0400 Received: by mail-wr1-x444.google.com with SMTP id l10so26374937wrb.2 for ; Thu, 24 Oct 2019 09:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=W/AkGYR57m74r9FQYLQ/SGWlTLm2K1Vi5lkbHPvwzOg=; b=v+ohkY56joDiW3D5onCDcauK1bRNVXlblGyike9OipJKNxCByon+MLC49b9eHp5chS wCd/lrU2W8VLl06Q7UyoQAQ/MTxZC+2FdhxyYUGU6On6O9KTFRPy+6DTmhSugLg1XRaw O5T5cUcrW8EGizOgGRGAqZw9PDa/0B+jxsgAm89O52yJDPzHpSoyVVs3yQ1dypQMI3fO 9bs/Q9oOf+3gN74WFKmpfnmABYZmQQjEI/U5hUOZBIPG0iDYNs+hdctQPsloYeVgQOZM D0gsNct2QfJVmgKal6IZ8D8eKHuxjMcB2+M23V9rI7xybkqWlW6mS3IJ+osE4/ryZHLs mcDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W/AkGYR57m74r9FQYLQ/SGWlTLm2K1Vi5lkbHPvwzOg=; b=DMn7PbQ3EgZYTOLaMop9RJJa93YOfqdTRHx8Z8zsQSsHSQCJEKlCzHvNgiPoxBpw+p w+RtVPZevxrAd4VP8y2UzpMsbR/DlwUTQIs5tA8wG5h66CMhNFNT536/KZmx9/LFforM 7VbudEXx9vMPLDk0Ba7E2zHqz2WrU+FSx3ZawjKjtrirx6/ESnPcY3ktTdMhcbNpGOko lViX4DvHGtGG++Y1CC8Zj+mnnculGwd32Cgjq3VSaV0TXa1pyrBG7DII/VvdvzQw3Jg+ 7vbCBTkXfGFNoSN0SJAkm5etKGB92UXuFrEhxuePnD906gVhmx+/lOOjzwT2wKpUyAYo c5qg== X-Gm-Message-State: APjAAAXURX4gT+al6g5EASVugKG58i7sHfp06a7mmQJH0WBShtY89Z+6 hKTVK1IFDyHEk6RaVhucAxNh3lpfE7Y= X-Received: by 2002:adf:a157:: with SMTP id r23mr4447758wrr.51.1571934455075; Thu, 24 Oct 2019 09:27:35 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id r27sm42606124wrc.55.2019.10.24.09.27.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 09:27:34 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 06/51] target/arm: Split arm_cpu_data_is_big_endian Date: Thu, 24 Oct 2019 17:26:39 +0100 Message-Id: <20191024162724.31675-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191024162724.31675-1-peter.maydell@linaro.org> References: <20191024162724.31675-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" From: Richard Henderson Set TBFLAG_ANY.BE_DATA in rebuild_hflags_common_32 and rebuild_hflags_a64 instead of rebuild_hflags_common, where we do not need to re-test is_a64() nor re-compute the various inputs. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Message-id: 20191023150057.25731-5-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/cpu.h | 49 +++++++++++++++++++++++++++------------------ target/arm/helper.c | 16 +++++++++++---- 2 files changed, 42 insertions(+), 23 deletions(-) -- 2.20.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index ad79a6153bb..4d961474ce7 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3108,33 +3108,44 @@ static inline uint64_t arm_sctlr(CPUARMState *env, int el) } } +static inline bool arm_cpu_data_is_big_endian_a32(CPUARMState *env, + bool sctlr_b) +{ +#ifdef CONFIG_USER_ONLY + /* + * In system mode, BE32 is modelled in line with the + * architecture (as word-invariant big-endianness), where loads + * and stores are done little endian but from addresses which + * are adjusted by XORing with the appropriate constant. So the + * endianness to use for the raw data access is not affected by + * SCTLR.B. + * In user mode, however, we model BE32 as byte-invariant + * big-endianness (because user-only code cannot tell the + * difference), and so we need to use a data access endianness + * that depends on SCTLR.B. + */ + if (sctlr_b) { + return true; + } +#endif + /* In 32bit endianness is determined by looking at CPSR's E bit */ + return env->uncached_cpsr & CPSR_E; +} + +static inline bool arm_cpu_data_is_big_endian_a64(int el, uint64_t sctlr) +{ + return sctlr & (el ? SCTLR_EE : SCTLR_E0E); +} /* Return true if the processor is in big-endian mode. */ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) { - /* In 32bit endianness is determined by looking at CPSR's E bit */ if (!is_a64(env)) { - return -#ifdef CONFIG_USER_ONLY - /* In system mode, BE32 is modelled in line with the - * architecture (as word-invariant big-endianness), where loads - * and stores are done little endian but from addresses which - * are adjusted by XORing with the appropriate constant. So the - * endianness to use for the raw data access is not affected by - * SCTLR.B. - * In user mode, however, we model BE32 as byte-invariant - * big-endianness (because user-only code cannot tell the - * difference), and so we need to use a data access endianness - * that depends on SCTLR.B. - */ - arm_sctlr_b(env) || -#endif - ((env->uncached_cpsr & CPSR_E) ? 1 : 0); + return arm_cpu_data_is_big_endian_a32(env, arm_sctlr_b(env)); } else { int cur_el = arm_current_el(env); uint64_t sctlr = arm_sctlr(env, cur_el); - - return (sctlr & (cur_el ? SCTLR_EE : SCTLR_E0E)) != 0; + return arm_cpu_data_is_big_endian_a64(cur_el, sctlr); } } diff --git a/target/arm/helper.c b/target/arm/helper.c index f05d0424745..4c65476d936 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -11061,9 +11061,6 @@ static uint32_t rebuild_hflags_common(CPUARMState *env, int fp_el, flags = FIELD_DP32(flags, TBFLAG_ANY, MMUIDX, arm_to_core_mmu_idx(mmu_idx)); - if (arm_cpu_data_is_big_endian(env)) { - flags = FIELD_DP32(flags, TBFLAG_ANY, BE_DATA, 1); - } if (arm_singlestep_active(env)) { flags = FIELD_DP32(flags, TBFLAG_ANY, SS_ACTIVE, 1); } @@ -11073,7 +11070,14 @@ static uint32_t rebuild_hflags_common(CPUARMState *env, int fp_el, static uint32_t rebuild_hflags_common_32(CPUARMState *env, int fp_el, ARMMMUIdx mmu_idx, uint32_t flags) { - flags = FIELD_DP32(flags, TBFLAG_A32, SCTLR_B, arm_sctlr_b(env)); + bool sctlr_b = arm_sctlr_b(env); + + if (sctlr_b) { + flags = FIELD_DP32(flags, TBFLAG_A32, SCTLR_B, 1); + } + if (arm_cpu_data_is_big_endian_a32(env, sctlr_b)) { + flags = FIELD_DP32(flags, TBFLAG_ANY, BE_DATA, 1); + } flags = FIELD_DP32(flags, TBFLAG_A32, NS, !access_secure_reg(env)); return rebuild_hflags_common(env, fp_el, mmu_idx, flags); @@ -11122,6 +11126,10 @@ static uint32_t rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, sctlr = arm_sctlr(env, el); + if (arm_cpu_data_is_big_endian_a64(el, sctlr)) { + flags = FIELD_DP32(flags, TBFLAG_ANY, BE_DATA, 1); + } + if (cpu_isar_feature(aa64_pauth, env_archcpu(env))) { /* * In order to save space in flags, we record only whether