From nobody Mon Feb 9 17:04:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1678812695; cv=none; d=zohomail.com; s=zohoarc; b=BvLtlb5O++KHuYbfPrd0UXXN5KM7fE4jet+izg2HFC+DpAiF0jFmemAxT2skr8t5O1EcArawJQD7dYSt33RGtbKbhZkNy8IkQQqJfn0zYmGhUVlvnaOQhhBw2E4rOHGz6ae4xhikJvIP8/ULl8Z7tlJU0aA4zCqOeheTP/jsw7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678812695; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oYMlE/F1S0n9ko7FKmrIGnYN/pdSAseR81vgrE7fIjY=; b=Cq/uSbLOhnec2MuFFA1ImjeuxLebN85EdGoIYIMA9SVoIHHUsxfItY/YTQVuTGkg3/SU8xTbb8Z0AX1uWXoCGwBtbGgoVqbiZE0LS5AWclo9bAbnmVuWoKpZB5L0gn8V/sZhtMeinShYcCIUqnKNJ+rkDxrkHFD6iFfPTzSe13s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1678812695874346.3738144222692; Tue, 14 Mar 2023 09:51:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pc7rC-0005oO-BG; Tue, 14 Mar 2023 12:50:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pc7rA-0005na-FD for qemu-devel@nongnu.org; Tue, 14 Mar 2023 12:50:36 -0400 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pc7r8-0002tn-O9 for qemu-devel@nongnu.org; Tue, 14 Mar 2023 12:50:36 -0400 Received: by mail-ot1-x334.google.com with SMTP id p13-20020a9d744d000000b0069438f0db7eso8753030otk.3 for ; Tue, 14 Mar 2023 09:50:34 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id 96-20020a9d04e9000000b0069451a9274bsm348689otm.28.2023.03.14.09.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 09:50:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1678812633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oYMlE/F1S0n9ko7FKmrIGnYN/pdSAseR81vgrE7fIjY=; b=iz6Q/HzY9A8Iq0JiWP3kdbgXLdhRbKgy0wC7PSxZtR/9uYNJyIrU+xw1QhpYdbNl3R zLayJC5ceEvHiWlE+n49j23AQyRCzI1yUCPxYClzQg083ts4OhaylyRcEXonNoct5hsV q7fLRBS7eaXSrdaJK9hMEoZDaqLSMvVuevytn1dVGwhSVetIY/4yPRNq2bsYazElIftW 2ShQzj2N+zULcnCi5xObZVYtTq306M2uPKAbUgWXyHFad0BZIE2JdIO9buLiRF4hbzxU 5d1WmzzbwLdVJTigvBivspTddtExKXfjUyfF0jjpjZDrhNGQZN75FykN8kq/Wtedo9Ph UyMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678812633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oYMlE/F1S0n9ko7FKmrIGnYN/pdSAseR81vgrE7fIjY=; b=ie397kxC8JVlUy85iPX7925K/4Q8WpoEQbIne9Ge5Ni3p9UOTn6m8RrKJudu+hno65 ZFCO4qHKgHRKtNZnMPrOAG/AnlIdNIU2UVFtDhWQveYwifmnUSlBd77nzSw+yMvXPqS9 kXhVNi6BKpK8WXuhD9adfZgvtjHMOps83cYI7XJ/T0ADcrQu+KCxpGXR0PxbuArjt7Rx YG9+E0Y5X+rD6P2HgTXlnIxogua7gpeVO8Wtq54IF2qcw5RC9w/lKbH4jykHWzpUmo/U n+ab/+1/9EDIdw0Ar9VZjjWdiiS9QusP2c5vYYhMVqv4gw5XzaoOBaSN0JWkY2T777Ae KgxQ== X-Gm-Message-State: AO0yUKUQ2HEP3yHkk+m3qtUMiTDqWTEUzwcoPW2C9Kijqc2tc7bQLxyd 5HlwxkzWOrSWVKNPdhBH8fm6TULcDyYm7MHxJ8A= X-Google-Smtp-Source: AK7set9YNR3zbPeh6kI/YAfAtPUldmbDTsFwaC5vTo2gzE9x25WXJK5pQbzRkUxVaKC+OI6lgS4ZuA== X-Received: by 2002:a9d:5f9d:0:b0:694:2f51:129b with SMTP id g29-20020a9d5f9d000000b006942f51129bmr17465901oti.24.1678812633643; Tue, 14 Mar 2023 09:50:33 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH for-8.1 v2 13/26] target/riscv: put env->misa_ext <-> cpu->cfg code into helpers Date: Tue, 14 Mar 2023 13:49:35 -0300 Message-Id: <20230314164948.539135-14-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314164948.539135-1-dbarboza@ventanamicro.com> References: <20230314164948.539135-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::334; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x334.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 autolearn=unavailable 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1678812697370100003 Content-Type: text/plain; charset="utf-8" The extremely tedious code that sets cpu->cfg based on misa_ext, and vice-versa, is scattered around riscv_cpu_validate_set_extensions() and set_misa(). Introduce helpers to do this work, cleaning up the logic of both functions a bit. While we're at it, add a note in cpu.h informing that any future change in MISA RV* bits should also be reflected in the helpers as well. We'll want to keep env->misa_ext changes in sync with cpu->cfg during realize() in the next patches, and both helpers will have a role to play in that. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 120 ++++++++++++++++++++++++--------------------- target/riscv/cpu.h | 3 +- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 6b5096d25e..28d4c5f768 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -234,10 +234,69 @@ const char *riscv_cpu_get_trap_name(target_ulong caus= e, bool async) } } =20 -static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) +static uint32_t riscv_get_misa_ext_with_cpucfg(RISCVCPUConfig *cfg) { - RISCVCPU *cpu; + uint32_t ext =3D 0; =20 + if (cfg->ext_i) { + ext |=3D RVI; + } + if (cfg->ext_e) { + ext |=3D RVE; + } + if (cfg->ext_m) { + ext |=3D RVM; + } + if (cfg->ext_a) { + ext |=3D RVA; + } + if (cfg->ext_f) { + ext |=3D RVF; + } + if (cfg->ext_d) { + ext |=3D RVD; + } + if (cfg->ext_c) { + ext |=3D RVC; + } + if (cfg->ext_s) { + ext |=3D RVS; + } + if (cfg->ext_u) { + ext |=3D RVU; + } + if (cfg->ext_h) { + ext |=3D RVH; + } + if (cfg->ext_v) { + ext |=3D RVV; + } + if (cfg->ext_j) { + ext |=3D RVJ; + } + + return ext; +} + +static void riscv_set_cpucfg_with_misa(RISCVCPUConfig *cfg, + uint32_t misa_ext) +{ + cfg->ext_i =3D misa_ext & RVI; + cfg->ext_e =3D misa_ext & RVE; + cfg->ext_m =3D misa_ext & RVM; + cfg->ext_a =3D misa_ext & RVA; + cfg->ext_f =3D misa_ext & RVF; + cfg->ext_d =3D misa_ext & RVD; + cfg->ext_v =3D misa_ext & RVV; + cfg->ext_c =3D misa_ext & RVC; + cfg->ext_s =3D misa_ext & RVS; + cfg->ext_u =3D misa_ext & RVU; + cfg->ext_h =3D misa_ext & RVH; + cfg->ext_j =3D misa_ext & RVJ; +} + +static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) +{ env->misa_mxl_max =3D env->misa_mxl =3D mxl; env->misa_ext_mask =3D env->misa_ext =3D ext; =20 @@ -251,25 +310,7 @@ static void set_misa(CPURISCVState *env, RISCVMXL mxl,= uint32_t ext) return; } =20 - /* - * We can't use riscv_cpu_cfg() in this case because it is - * a read-only inline and we're going to change the values - * of cpu->cfg. - */ - cpu =3D env_archcpu(env); - - cpu->cfg.ext_i =3D ext & RVI; - cpu->cfg.ext_e =3D ext & RVE; - cpu->cfg.ext_m =3D ext & RVM; - cpu->cfg.ext_a =3D ext & RVA; - cpu->cfg.ext_f =3D ext & RVF; - cpu->cfg.ext_d =3D ext & RVD; - cpu->cfg.ext_v =3D ext & RVV; - cpu->cfg.ext_c =3D ext & RVC; - cpu->cfg.ext_s =3D ext & RVS; - cpu->cfg.ext_u =3D ext & RVU; - cpu->cfg.ext_h =3D ext & RVH; - cpu->cfg.ext_j =3D ext & RVJ; + riscv_set_cpucfg_with_misa(&env_archcpu(env)->cfg, ext); } =20 #ifndef CONFIG_USER_ONLY @@ -1156,42 +1197,7 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) */ riscv_cpu_disable_priv_spec_isa_exts(cpu); =20 - if (cpu->cfg.ext_i) { - ext |=3D RVI; - } - if (cpu->cfg.ext_e) { - ext |=3D RVE; - } - if (cpu->cfg.ext_m) { - ext |=3D RVM; - } - if (cpu->cfg.ext_a) { - ext |=3D RVA; - } - if (cpu->cfg.ext_f) { - ext |=3D RVF; - } - if (cpu->cfg.ext_d) { - ext |=3D RVD; - } - if (cpu->cfg.ext_c) { - ext |=3D RVC; - } - if (cpu->cfg.ext_s) { - ext |=3D RVS; - } - if (cpu->cfg.ext_u) { - ext |=3D RVU; - } - if (cpu->cfg.ext_h) { - ext |=3D RVH; - } - if (cpu->cfg.ext_v) { - ext |=3D RVV; - } - if (cpu->cfg.ext_j) { - ext |=3D RVJ; - } + ext =3D riscv_get_misa_ext_with_cpucfg(&cpu->cfg); =20 env->misa_ext_mask =3D env->misa_ext =3D ext; } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ebe0fff668..2263629332 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -66,7 +66,8 @@ #define RV(x) ((target_ulong)1 << (x - 'A')) =20 /* - * Consider updating set_misa() when adding new + * Consider updating riscv_get_misa_ext_with_cpucfg() + * and riscv_set_cpucfg_with_misa() when adding new * MISA bits here. */ #define RVI RV('I') --=20 2.39.2