From nobody Mon Feb 9 17:04:56 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=1678812908; cv=none; d=zohomail.com; s=zohoarc; b=Z7bVNCn35jwo9PqhmWc97D4O6znlt1DHiq2DXZsGeYjaQbgcg/NaES5Jl93Ikeh3rB+OP30CgGdMg9nyPBUsfqKAfOMCShhCZlSBblo9v/Z+im4zfsB+BQEVyN9DH9aShB5Byi33fDNuJZ3PjiQvSb0Hv1FpP8thbyJ/YKDPL9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678812908; 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=n1KnuQqgygOO2YMozmY3X/7U/lNxPcvXX1UiChgZSKA=; b=PMhHiMQCg+mrnoEntCFC6xywEVhcH18sCOMjjgZTjvwOQqBCaw3Uv3rvJn28cZHCVIytXrzhQGk7P6ickXL4BeA00ClPHGAW19MH5avkNtIR4/3QeNfucuYOLNhaVS2rjPlfWhoOSu8RwxwMBo6Mz1+PACADEokeN6O6OvjKjXQ= 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 167881290841391.68693900948278; Tue, 14 Mar 2023 09:55:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pc7r6-0005ls-4P; Tue, 14 Mar 2023 12:50:32 -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 1pc7r4-0005lG-Re for qemu-devel@nongnu.org; Tue, 14 Mar 2023 12:50:30 -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 1pc7r3-0002tn-4k for qemu-devel@nongnu.org; Tue, 14 Mar 2023 12:50:30 -0400 Received: by mail-ot1-x334.google.com with SMTP id p13-20020a9d744d000000b0069438f0db7eso8752887otk.3 for ; Tue, 14 Mar 2023 09:50:28 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 09:50:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1678812627; 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=n1KnuQqgygOO2YMozmY3X/7U/lNxPcvXX1UiChgZSKA=; b=DaoPeFH5NyIpgc9gQtfxzqs1cG+4y9U9QGI06mj/tsjmDMMUaKm6r0SB2Z8e5Rc4W8 VXY4kIUUmkd9XVEmtBV70sEgjfwISkUn8SpQrKWLocbEoeQACxCB57kj5bjkUp+WaU2c EFfPOvbbjJyRfHD9HpNvO0eeTumxA/Bbfy3xHHSiPCQXzkgDncncUxezNRFHvWA6KdKZ jvLyvpndoT82A/Q6z1n0CJuHgj/H4YJWQEkxR68I04GVOtwWOWFDQHBwk0li3mOghiEL JSIg8saxPXLEsZc05PHiXl2RmuUg/BoZ7fSa2H7k3JEYOP8fyAq0dnGWuHXidcnL0+Zd 2+2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678812627; 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=n1KnuQqgygOO2YMozmY3X/7U/lNxPcvXX1UiChgZSKA=; b=Nlan69mjP6/F182idp8f4t3tbOb2TIKyIFkS43J60HqXFMjHxXLk2vun8BWKJYLmHS sTWCS7XyYbDrgQ+vmroFdVQpAZcZX2IdVw9wYPO4UpcNVS7k/MAxo4TQsf09DS36VmTy +wUmw1ffCFuvAwFZMJjj45SZB6Gx1t6aOdaqDG+pRSOdo5IJfuMI/hpsd1vsaya3aClv yDtOiHv5cLedmWXGLRzkctd7JJkwEBzqmcYiNnD9MPKIpAGhtvA7lkl7gMCq3iBjpidN Qp4+3OSOeg3Agh0aZulP6qKPCH8xfD/gpFPOmxtQCoI56T9BQ9kg68YxInHQK09AbAFC Ha7g== X-Gm-Message-State: AO0yUKVgtHDRkjFv02tohpuhre7kBxtlDNsDbYaEIWC0ML5gP2iJvaSn svwWldJpoc+ppwXqNHnZWnUHNHpIpSDHhGGEAKw= X-Google-Smtp-Source: AK7set+1HaF5LMbRnzuvZfjiOtl0SQjMNrrRQ4cDaJ4lD5zdFgzspwQlvkxasec2EfcKmJDKJC6NwA== X-Received: by 2002:a05:6830:912:b0:693:d263:5976 with SMTP id v18-20020a056830091200b00693d2635976mr11251364ott.1.1678812627734; Tue, 14 Mar 2023 09:50:27 -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 11/26] target/riscv/cpu.c: set cpu config in set_misa() Date: Tue, 14 Mar 2023 13:49:33 -0300 Message-Id: <20230314164948.539135-12-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: 1678812908738100005 Content-Type: text/plain; charset="utf-8" set_misa() is setting all 'misa' related env states and nothing else. But other functions, namely riscv_cpu_validate_set_extensions(), uses the config object to do its job. This creates a need to set the single letter extensions in the cfg object to keep both in sync. At this moment this is being done by register_cpu_props(), forcing every CPU to do a call to this function. Let's beef up set_misa() and make the function do the sync for us. This will relieve named CPUs to having to call register_cpu_props(), which will then be redesigned to a more specialized role next. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 40 ++++++++++++++++++++++++++++++++-------- target/riscv/cpu.h | 4 ++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 36c55abda0..7841676473 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -236,8 +236,40 @@ const char *riscv_cpu_get_trap_name(target_ulong cause= , bool async) =20 static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) { + RISCVCPU *cpu; + env->misa_mxl_max =3D env->misa_mxl =3D mxl; env->misa_ext_mask =3D env->misa_ext =3D ext; + + /* + * ext =3D 0 will only be a thing during cpu_init() functions + * as a way of setting an extension-agnostic CPU. We do + * not support clearing misa_ext* and the ext_N flags in + * RISCVCPUConfig in regular circunstances. + */ + if (ext =3D=3D 0) { + return; + } + + /* + * 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; } =20 #ifndef CONFIG_USER_ONLY @@ -340,7 +372,6 @@ static void riscv_any_cpu_init(Object *obj) #endif =20 env->priv_ver =3D PRIV_VERSION_LATEST; - register_cpu_props(obj); =20 /* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei =3D true; @@ -368,7 +399,6 @@ static void rv64_sifive_u_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39); @@ -387,7 +417,6 @@ static void rv64_sifive_e_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -472,8 +501,6 @@ static void rv32_sifive_u_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); @@ -492,7 +519,6 @@ static void rv32_sifive_e_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -510,7 +536,6 @@ static void rv32_ibex_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_11_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -529,7 +554,6 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 76f81c6b68..ebe0fff668 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -66,8 +66,8 @@ #define RV(x) ((target_ulong)1 << (x - 'A')) =20 /* - * Consider updating register_cpu_props() when adding - * new MISA bits here. + * Consider updating set_misa() when adding new + * MISA bits here. */ #define RVI RV('I') #define RVE RV('E') /* E and I are mutually exclusive */ --=20 2.39.2