From patchwork Tue Jan 23 03:53:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 125473 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1519260ljf; Mon, 22 Jan 2018 19:56:49 -0800 (PST) X-Google-Smtp-Source: AH8x224CXp3eKZlC2tR6Mlf4HdLXuhm/TQuVNSBJsXCUCGhFkU71/iD7eJmX+HpjT38MAYZB1iO/ X-Received: by 10.129.111.65 with SMTP id k62mr1035666ywc.343.1516679809880; Mon, 22 Jan 2018 19:56:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516679809; cv=none; d=google.com; s=arc-20160816; b=ZipKzl8/bXVZ6X2D+a33nFhjATBPLK1AmviG2d+MNzwFXY5wa/D9ei+IfbVLc2Mhuy NDmX2nsz3Sx0rmv0Ef1eI0dA4vOxW2tcA4vHtGWsiTyg+DPrbEodY/n6wt898MdnfzKj sm2MD/JdyJZsdsa0GYdA1u2rfkD34I7oQCl3W5Rm6fFL22xRuifQKvwj0IDpflorJmpY ZA+ojyDKdFnX/BRaI6+V7tfYxVznmmPhnXH5ZGZbOOZ01FCidUlhxAT3FsYBiH7IyzeD RvxEA2nEfBYY1zHly7QStlotTAr30XTaMB/u1LTrkbXzIFT03J2STC78hzW9wSSInekR iloQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=deRFjHrW5yt+nLGpFx/cXpvMsC03NLZLiLHoyaTRKKg=; b=OBlofvCjWKESQKE5cu2LRozq07J52nAvHImgspu3FWfZU5m/CUhlHg2shWkyPBH8Ro TwOfwZ/zYHDeZqXj/6f+nJnVJXzLJI7faj1pFhEM0INVuDXdJSa+LgdSm83Z70vm/AEO e9EwU76KVi0MQ22bZ2y7ylSmv6ZZKAmCpjFg403eYQTCHSsmvmH58h6jQYwekge2bJHe j9XKXAX4R2xtp50VsSRfJCPP1dR0815OsNZnAXxTxYjlo9SmYbFY5LS2OqfCYMmC0IOf 354rk5B51hZ6oo4IperMLeZO8IoDj1uGR0wj4TBf21EaChdhs8t7zj7n2pAzzUZMawaF pzAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q9LJQcXp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k127si327569ywg.165.2018.01.22.19.56.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 22 Jan 2018 19:56:49 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Q9LJQcXp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edphZ-0003Fl-99 for patch@linaro.org; Mon, 22 Jan 2018 22:56:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1edper-0001tt-4x for qemu-devel@nongnu.org; Mon, 22 Jan 2018 22:54:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1edpep-00049X-UQ for qemu-devel@nongnu.org; Mon, 22 Jan 2018 22:54:01 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:42050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1edpep-00048T-LS for qemu-devel@nongnu.org; Mon, 22 Jan 2018 22:53:59 -0500 Received: by mail-pf0-x243.google.com with SMTP id b25so8755872pfd.9 for ; Mon, 22 Jan 2018 19:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=deRFjHrW5yt+nLGpFx/cXpvMsC03NLZLiLHoyaTRKKg=; b=Q9LJQcXpkQV2btUCDOqRcpZ4bnr8pugKpUW1Y+NhFkRnGT+ku3vMhQ9BUBm2HTi5s9 MlVdTFKGau16RBoJA/FgNSDDZyu6/es5GYHl/hqCMl0AmrGMJBAMFAadVRTsrT9QghyS vRIs96tRZ7J6SS+VwM3EuEX3MpGoSQuzf+e68= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=deRFjHrW5yt+nLGpFx/cXpvMsC03NLZLiLHoyaTRKKg=; b=fQ+6lfMWHUCZtTxAKPOtZtIcLBKiyc6vD0XvZXLikj1ZyM3cGT94e8w9Bbv9OjVcC9 TlOzwG2MohYixcIgC/Y1Ko1Q8j2CcnO3Simv+cFzIJQhv/t0p74MQp4fPZSPYXmcD/pI o3AZUkoT+yjs/lpTC+l6Uhy5TuKugNyWglcSv99xy7YaZMCjqfgahbsQ6y+e1fLlsxAx KSBt1JUuJkd/1m3oZEFowc+HtdSF6ISku8m3qTjkoJS4KCVkkgCxHat1TTg2BHYVPl16 OCPGcQce/HJr0GgOlP+0tudit2ugIimNYMyIhs4X/myFa4w+r2PIIxUUbi4pDfHNSsz5 knnQ== X-Gm-Message-State: AKwxytd7ayezJvvNPhAeRbI1haK9ZaccE8JhjAbzsmNcW55zl1rIKbkd m1RywIhGRRyV5F75Wf9CF5AyWpRhtZY= X-Received: by 10.101.67.193 with SMTP id n1mr7989282pgp.116.1516679638301; Mon, 22 Jan 2018 19:53:58 -0800 (PST) Received: from cloudburst.twiddle.net (174-21-6-47.tukw.qwest.net. [174.21.6.47]) by smtp.gmail.com with ESMTPSA id t1sm3444680pfj.21.2018.01.22.19.53.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jan 2018 19:53:57 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 22 Jan 2018 19:53:48 -0800 Message-Id: <20180123035349.24538-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180123035349.24538-1-richard.henderson@linaro.org> References: <20180123035349.24538-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH v3 4/5] target/arm: Add ZCR_ELx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Define ZCR_EL[1-3]. Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 ++ target/arm/helper.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) -- 2.14.3 Reviewed-by: Peter Maydell diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 3f4f6b6144..17955ad3ef 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -549,6 +549,9 @@ typedef struct CPUARMState { */ float_status fp_status; float_status standard_fp_status; + + /* ZCR_EL[1-3] */ + uint64_t zcr_el[4]; } vfp; uint64_t exclusive_addr; uint64_t exclusive_val; @@ -923,6 +926,8 @@ void pmccntr_sync(CPUARMState *env); #define CPTR_TCPAC (1U << 31) #define CPTR_TTA (1U << 20) #define CPTR_TFP (1U << 10) +#define CPTR_TZ (1U << 8) /* CPTR_EL2 */ +#define CPTR_EZ (1U << 8) /* CPTR_EL3 */ #define MDCR_EPMAD (1U << 21) #define MDCR_EDAD (1U << 20) diff --git a/target/arm/helper.c b/target/arm/helper.c index bfce09643b..db67e8ac72 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -4266,6 +4266,125 @@ static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { REGINFO_SENTINEL }; +/* Return the exception level to which SVE-disabled exceptions should + * be taken, or 0 if SVE is enabled. + */ +static int sve_exception_el(CPUARMState *env) +{ +#ifndef CONFIG_USER_ONLY + unsigned current_el = arm_current_el(env); + + /* The CPACR.ZEN controls traps to EL1: + * 0, 2 : trap EL0 and EL1 accesses + * 1 : trap only EL0 accesses + * 3 : trap no accesses + */ + switch (extract32(env->cp15.cpacr_el1, 16, 2)) { + default: + if (current_el <= 1) { + /* Trap to PL1, which might be EL1 or EL3 */ + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { + return 3; + } + return 1; + } + break; + case 1: + if (current_el == 0) { + return 1; + } + break; + case 3: + break; + } + + /* Similarly for CPACR.FPEN, after having checked ZEN. */ + switch (extract32(env->cp15.cpacr_el1, 20, 2)) { + default: + if (current_el <= 1) { + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { + return 3; + } + return 1; + } + break; + case 1: + if (current_el == 0) { + return 1; + } + break; + case 3: + break; + } + + /* CPTR_EL2. Check both TZ and TFP. */ + if (current_el <= 2 + && (env->cp15.cptr_el[2] & (CPTR_TFP | CPTR_TZ)) + && !arm_is_secure_below_el3(env)) { + return 2; + } + + /* CPTR_EL3. Check both EZ and TFP. */ + if (!(env->cp15.cptr_el[3] & CPTR_EZ) + || (env->cp15.cptr_el[3] & CPTR_TFP)) { + return 3; + } +#endif + return 0; +} + +static CPAccessResult zcr_access(CPUARMState *env, const ARMCPRegInfo *ri, + bool isread) +{ + switch (sve_exception_el(env)) { + case 3: + return CP_ACCESS_TRAP_EL3; + case 2: + return CP_ACCESS_TRAP_EL2; + case 1: + return CP_ACCESS_TRAP; + } + return CP_ACCESS_OK; +} + +static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, + uint64_t value) +{ + /* Bits other than [3:0] are RAZ/WI. */ + raw_write(env, ri, value & 0xf); +} + +static const ARMCPRegInfo zcr_el1_reginfo = { + .name = "ZCR_EL1", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 0, + .access = PL1_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[1]), + .writefn = zcr_write, .raw_writefn = raw_write +}; + +static const ARMCPRegInfo zcr_el2_reginfo = { + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, + .access = PL2_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[2]), + .writefn = zcr_write, .raw_writefn = raw_write +}; + +static const ARMCPRegInfo zcr_no_el2_reginfo = { + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, + .access = PL2_RW, .type = ARM_CP_64BIT, + .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore +}; + +static const ARMCPRegInfo zcr_el3_reginfo = { + .name = "ZCR_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 2, .opc2 = 0, + .access = PL3_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[3]), + .writefn = zcr_write, .raw_writefn = raw_write +}; + void hw_watchpoint_update(ARMCPU *cpu, int n) { CPUARMState *env = &cpu->env; @@ -5332,6 +5451,18 @@ void register_cp_regs_for_features(ARMCPU *cpu) } define_one_arm_cp_reg(cpu, &sctlr); } + + if (arm_feature(env, ARM_FEATURE_SVE)) { + define_one_arm_cp_reg(cpu, &zcr_el1_reginfo); + if (arm_feature(env, ARM_FEATURE_EL2)) { + define_one_arm_cp_reg(cpu, &zcr_el2_reginfo); + } else { + define_one_arm_cp_reg(cpu, &zcr_no_el2_reginfo); + } + if (arm_feature(env, ARM_FEATURE_EL3)) { + define_one_arm_cp_reg(cpu, &zcr_el3_reginfo); + } + } } void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu)