From patchwork Tue Jun 7 20:32:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 579351 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp5513269max; Tue, 7 Jun 2022 14:09:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBRuvz8pKKmYasCKi5gMSur5tExFBwVftwOxCrroncHyrjiCFE9bugIC8ya8pz3mOp1YTM X-Received: by 2002:a05:620a:4507:b0:6a5:95ee:b56f with SMTP id t7-20020a05620a450700b006a595eeb56fmr20956411qkp.197.1654636159072; Tue, 07 Jun 2022 14:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654636159; cv=none; d=google.com; s=arc-20160816; b=fvevxHOvl+JZ7smyl6sfBrBjEwRj0/PR7xb0DRJUVQdRXFGrpTCoFKLLDK//+z4xz/ Q7HQ8cycinDAa9E3GcopF0mbVD0Hw04uAtz/3FZfK8p+CWgXBlE2TnqjwK2ks74zidvh pYf+uT9PZ2chipCYLC+IFPx16NZ1v8NuAGjg1JDvngEcMDRHZC1mhsuz59fNmSucc0Bt 9ngyDvoJtnOkf3LBOCvDiumo9P1xQHYYOW6XiqhcaLgKh6TFVXgtxSRJ1ZUuGB1wyktB VWhOdYVfY9k6RMwzjhlyAtLDzV5Bvx1Lj8E69i+ifvZHzz60eQ8j8c85r23ai9BVFkwk o2QA== 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:cc:to :from:dkim-signature; bh=03rd4A4qLn1D1mjrmymRetC77V7qJ8iA+zPBzz1Ln/A=; b=yT3tk+j6+o3otgDRs3+V1PwP55wwefjjfC7+qHdrIy4kjhhPLXhDekuhW3lqzXipfM K1poTiqsfGPwDl5oiczf8dkkFAbbuFjPxOSBz+QPSDHU/QTaUSlDwjhUN+uRsjV37Qzi tcvy500+cPX/l8s91x6Tv8f7FI0IW7YX70yA1jLCoYjKBkMRDoF5Yyte/XCJ1WXHy3ba 5Zcd20cukIeEhY79TvK4g0y2V8NW7zI0041oc2Le/9dpo0qFiDbLLKv2zNCNgaBG7Ng2 1sKp/9q8O8zLaxLjrHB6R6XFfKNOJ2PYfjxBqHbKoX8Vw6Q2ScU3tQFdgAFW15d6qj5P t0LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AFPsI8EM; 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 ib14-20020a0562141c8e00b0046449aa093csi10388082qvb.522.2022.06.07.14.09.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jun 2022 14:09:19 -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=AFPsI8EM; 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]:34360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nygRy-0004OV-Kn for patch@linaro.org; Tue, 07 Jun 2022 17:09:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyftY-0008Tt-Lm for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:33:44 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:34720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyftQ-0007BX-Nw for qemu-devel@nongnu.org; Tue, 07 Jun 2022 16:33:44 -0400 Received: by mail-pf1-x433.google.com with SMTP id c196so16521128pfb.1 for ; Tue, 07 Jun 2022 13:33:36 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=03rd4A4qLn1D1mjrmymRetC77V7qJ8iA+zPBzz1Ln/A=; b=AFPsI8EMP2OouL7V8nW2DcLpV/7xF6hbSsvSGZZNfAPCl3ifNKm0u1kXZoIhBOl9sD GT7/aX+zj4EKWBC9yLZo1eBvcbkfRVXtj5ak3AyKkhZO4nyqqI2/Rd3jZnnxT7eQtk0u rjGyq7ymexCL8VUMq2CuaktTag6XshuckvdkRZrmIxDCqnKZVEJCfxAY2UWopiv9MoVr 3+WKWjzqfvjM07deFGCC05FlpPj/GoJKvWQ6Im/JBUlqmU6wTrYOkdoRLeTLzVH35HTY GjfbIxzZ2y3zL2DnfBxnBVbq1mXURPGZxjmEbsufuosY5AZvFEiMa7h199kAZJoqJfZb mFwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=03rd4A4qLn1D1mjrmymRetC77V7qJ8iA+zPBzz1Ln/A=; b=ZDGAyqjQQXtgIvcK5h36psyCd7h1GS2GtZGu1ir6a29YajFI//36GVwIM1G7GBYGIF 9Vh85sJna059bCE8wbtA0rG0YakuEV4/tDK4bI7p/AMhZ7fh6XqteX2AtshWSCDDQaWs ZOXmt0eEoIupiaGKCaacq1US5icGvi2G5Vc3vf9UTNmHotPQEkiUheDPZBM9gkVzLV54 IdkHg70R8npgcXZqJC7j20sDA6xIoEO3Z51sYZEt+mx4W/Vl5QDlJ5KjiTlZOUp+BIYO KUvS3toIEGGK2n+ZZk41pQtSJbzfdK9UbZsohfo5cdUDEC0tFm9zcyX7DCxQNx/u5Bbc RKaQ== X-Gm-Message-State: AOAM533zffubVerZJkvjb/AWIib6/ar9Gve/BIJ3lu/7rn9RKhQE79GY uFPYu9brl76kLIgdNOroc7bwCFGzihDxdA== X-Received: by 2002:a63:2b8b:0:b0:3fc:c510:7941 with SMTP id r133-20020a632b8b000000b003fcc5107941mr27669275pgr.47.1654634015606; Tue, 07 Jun 2022 13:33:35 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:3cf2:c634:5b19:25f6]) by smtp.gmail.com with ESMTPSA id s22-20020a17090aba1600b001d9780b7779sm4227856pjr.15.2022.06.07.13.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 13:33:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Subject: [PATCH v2 30/71] target/arm: Implement SMSTART, SMSTOP Date: Tue, 7 Jun 2022 13:32:25 -0700 Message-Id: <20220607203306.657998-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220607203306.657998-1-richard.henderson@linaro.org> References: <20220607203306.657998-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" These two instructions are aliases of MSR (immediate). Use the two helpers to properly implement svcr_write. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- target/arm/cpu.h | 1 + target/arm/helper-sme.h | 21 +++++++++++++ target/arm/helper.h | 1 + target/arm/helper.c | 6 ++-- target/arm/sme_helper.c | 61 ++++++++++++++++++++++++++++++++++++++ target/arm/translate-a64.c | 24 +++++++++++++++ target/arm/meson.build | 1 + 7 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 target/arm/helper-sme.h create mode 100644 target/arm/sme_helper.c diff --git a/target/arm/cpu.h b/target/arm/cpu.h index ef374eefe8..e7ec03a8a7 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1106,6 +1106,7 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, int new_el, bool el0_a64); void aarch64_add_sve_properties(Object *obj); void aarch64_add_pauth_properties(Object *obj); +void arm_reset_sve_state(CPUARMState *env); /* * SVE registers are encoded in KVM's memory in an endianness-invariant format. diff --git a/target/arm/helper-sme.h b/target/arm/helper-sme.h new file mode 100644 index 0000000000..3bd48c235f --- /dev/null +++ b/target/arm/helper-sme.h @@ -0,0 +1,21 @@ +/* + * AArch64 SME specific helper definitions + * + * Copyright (c) 2022 Linaro, Ltd + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +DEF_HELPER_FLAGS_2(set_pstate_sm, TCG_CALL_NO_RWG, void, env, i32) +DEF_HELPER_FLAGS_2(set_pstate_za, TCG_CALL_NO_RWG, void, env, i32) diff --git a/target/arm/helper.h b/target/arm/helper.h index b1334e0c42..5bca7255f1 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -1020,6 +1020,7 @@ DEF_HELPER_FLAGS_6(gvec_bfmlal_idx, TCG_CALL_NO_RWG, #ifdef TARGET_AARCH64 #include "helper-a64.h" #include "helper-sve.h" +#include "helper-sme.h" #endif #include "helper-mve.h" diff --git a/target/arm/helper.c b/target/arm/helper.c index bec7e47b78..e065a1deb8 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6370,9 +6370,9 @@ static CPAccessResult access_esm(CPUARMState *env, const ARMCPRegInfo *ri, static void svcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) { - value &= R_SVCR_SM_MASK | R_SVCR_ZA_MASK; - /* TODO: Side effects. */ - env->svcr = value; + helper_set_pstate_sm(env, FIELD_EX64(value, SVCR, SM)); + helper_set_pstate_za(env, FIELD_EX64(value, SVCR, ZA)); + arm_rebuild_hflags(env); } static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri, diff --git a/target/arm/sme_helper.c b/target/arm/sme_helper.c new file mode 100644 index 0000000000..b215725594 --- /dev/null +++ b/target/arm/sme_helper.c @@ -0,0 +1,61 @@ +/* + * ARM SME Operations + * + * Copyright (c) 2022 Linaro, Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "internals.h" +#include "exec/helper-proto.h" + +/* ResetSVEState */ +void arm_reset_sve_state(CPUARMState *env) +{ + memset(env->vfp.zregs, 0, sizeof(env->vfp.zregs)); + /* Recall that FFR is stored as pregs[16]. */ + memset(env->vfp.pregs, 0, sizeof(env->vfp.pregs)); + vfp_set_fpcr(env, 0x0800009f); +} + +void helper_set_pstate_sm(CPUARMState *env, uint32_t i) +{ + if (i == FIELD_EX64(env->svcr, SVCR, SM)) { + return; + } + env->svcr ^= R_SVCR_SM_MASK; + arm_reset_sve_state(env); +} + +void helper_set_pstate_za(CPUARMState *env, uint32_t i) +{ + if (i == FIELD_EX64(env->svcr, SVCR, ZA)) { + return; + } + env->svcr ^= R_SVCR_ZA_MASK; + + /* + * ResetSMEState. + * + * SetPSTATE_ZA zeros on enable and disable. We can zero this only + * on enable: while disabled, the storage is inaccessible and the + * value does not matter. We're not saving the storage in vmstate + * when disabled either. + */ + if (i) { + memset(env->zarray, 0, sizeof(env->zarray)); + } +} diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index fdc035ad9a..40f2e53983 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -1761,6 +1761,30 @@ static void handle_msr_i(DisasContext *s, uint32_t insn, } break; + case 0x1b: /* SVCR* */ + if (!dc_isar_feature(aa64_sme, s) || crm < 2 || crm > 7) { + goto do_unallocated; + } + if (sme_access_check(s)) { + bool i = crm & 1; + bool changed = false; + + if ((crm & 2) && i != s->pstate_sm) { + gen_helper_set_pstate_sm(cpu_env, tcg_constant_i32(i)); + changed = true; + } + if ((crm & 4) && i != s->pstate_za) { + gen_helper_set_pstate_za(cpu_env, tcg_constant_i32(i)); + changed = true; + } + if (changed) { + gen_rebuild_hflags(s); + } else { + s->base.is_jmp = DISAS_NEXT; + } + } + break; + default: do_unallocated: unallocated_encoding(s); diff --git a/target/arm/meson.build b/target/arm/meson.build index 50f152214a..02c91f72bb 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -47,6 +47,7 @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( 'mte_helper.c', 'pauth_helper.c', 'sve_helper.c', + 'sme_helper.c', 'translate-a64.c', 'translate-sve.c', ))