From nobody Mon Feb 9 20:30:31 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=1679527874; cv=none; d=zohomail.com; s=zohoarc; b=fg1/X2I/Yjrw0jC5Ru/+8XYNYYF62juGoqm47My27x1RDKv6Dgr/5oo+vZH1ftZC9GPAwWkT3z40FmnQJJpMOXG1AOO/DaY6xjGSaRoTWhBsjtXw/zgFUVtzek7fMqsdoYtzAITv28Fm4qQzXEj24u0i+2QXYaSDzNNCvnTkd4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679527874; 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=edyvksieWPeu1SW2+k+C41ShJ9HM1xvZ3+am3Bxgf3Y=; b=goaeVQrxc02rXhhFcPXB1wDSMhE/+NcVn7byULWDmn/F3V2yyWPkHXyFaE8aaNBoO7cc7rSlRafmqh+G/eDcSBdcxLT+zCx724bn2NdnrPBB/bFBFisVth2ifCJYDx/OyzJGHAPMik0736vnAsAK0Qa3qP3x9Rwjhh2JWbV0ME8= 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 1679527874854905.8716181454389; Wed, 22 Mar 2023 16:31:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pf7AM-0007Xu-33; Wed, 22 Mar 2023 18:42:46 -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 1pf7AL-0007XX-0X for qemu-devel@nongnu.org; Wed, 22 Mar 2023 18:42:45 -0400 Received: from mail-oa1-x36.google.com ([2001:4860:4864:20::36]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pf7AJ-0000PX-C0 for qemu-devel@nongnu.org; Wed, 22 Mar 2023 18:42:44 -0400 Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-17ac5ee3f9cso20881932fac.12 for ; Wed, 22 Mar 2023 15:42:42 -0700 (PDT) Received: from grind.. ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id ax35-20020a05687c022300b0017243edbe5bsm5586817oac.58.2023.03.22.15.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 15:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679524961; 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=edyvksieWPeu1SW2+k+C41ShJ9HM1xvZ3+am3Bxgf3Y=; b=AHug5XSZvvnpxZ4Zz519zSEOGe+4oBKcwOqs0yq59K5h6BKYgqLgWBpDIcRYmX/KRN dJ8l0oPELucxlJcnq3I3dSAq88VH2A6H46aWDepqHvLgt3LvTv52bFigyrh7kYKpMQQL +mMmQJjlTdiFdggZihq0dlNcXV1lommUDYcYo3AdnWOFrr8gv92k4skxCks0qY1XE3sb jdmE0X25cocnP99rmCk+fpJafHj28xo5sxn0NmhsV/8fxtuPGgaZZcPSD3uwUYm4zvzi FZDVoOxOTUXbE2Z8guN06Z7pcZYIbiZHdgSy6JcK7fwbJIKy3W1TDMk6RfzC81NEVNpZ dP3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679524961; 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=edyvksieWPeu1SW2+k+C41ShJ9HM1xvZ3+am3Bxgf3Y=; b=iuVAEaPb2hxnuwBxjApxpnXFvc5MXOR4CLIcM46sCg5fiZDm3A/CCLN/Be4y9sl1H8 dL6kULAr9e7GVkKHylkTkf2YXJxQERi3WP1PJfndRL3w+oKuJuNL/jmBVbgkXOpjxYMF l3Ek8F1xAXv3RLF+6RTA174590LG0aQoZTAdPf4m1EIsBnnWkxPoid95R3J8MUmFU6Qn T4kbzbSxg/LFP7+OHYmv/P3Rh5bA9CVhmXcJLTBNDBsd8EPYCwBUm9xiEiulsexCflVT sXyJHz/1a+BNSaSp7bUih+5qeupftDDpzbkQDdywh0ZMgpEvBYVnu3esNLwEXGHbMaDU fdeQ== X-Gm-Message-State: AAQBX9dY5zo1Ra5ApgFbheNYMH07/Y58CpotfwVXMspawtOIZKeTbkLA QklrhrT2TZwk1rz1TfY3fV5J8DFOYE9RQwPpCSU= X-Google-Smtp-Source: AKy350ZZFwYQnX/fw7UpJ6CRrYAEa67RHv2RpxPDeFeljEtZIzEEDELjfFYTaCpqozhKkuT8o42v9w== X-Received: by 2002:a05:6870:a44b:b0:177:c2ec:1a78 with SMTP id n11-20020a056870a44b00b00177c2ec1a78mr781124oal.36.1679523641168; Wed, 22 Mar 2023 15:20:41 -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 v4 06/25] target/riscv/cpu.c: add riscv_cpu_validate_misa_mxl() Date: Wed, 22 Mar 2023 19:19:45 -0300 Message-Id: <20230322222004.357013-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230322222004.357013-1-dbarboza@ventanamicro.com> References: <20230322222004.357013-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=2001:4860:4864:20::36; envelope-from=dbarboza@ventanamicro.com; helo=mail-oa1-x36.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: 1679527876123100007 Content-Type: text/plain; charset="utf-8" Let's remove more code that is open coded in riscv_cpu_realize() and put it into a helper. Let's also add an error message instead of just asserting out if env->misa_mxl_max !=3D env->misa_mlx. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 51 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 17b301967c..1a298e5e55 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -879,6 +879,33 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCV= CPU *cpu) } } =20 +static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) +{ + RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(cpu); + CPUClass *cc =3D CPU_CLASS(mcc); + CPURISCVState *env =3D &cpu->env; + + /* Validate that MISA_MXL is set properly. */ + switch (env->misa_mxl_max) { +#ifdef TARGET_RISCV64 + case MXL_RV64: + case MXL_RV128: + cc->gdb_core_xml_file =3D "riscv-64bit-cpu.xml"; + break; +#endif + case MXL_RV32: + cc->gdb_core_xml_file =3D "riscv-32bit-cpu.xml"; + break; + default: + g_assert_not_reached(); + } + + if (env->misa_mxl_max !=3D env->misa_mxl) { + error_setg(errp, "misa_mxl_max must be equal to misa_mxl"); + return; + } +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly, doing a set_misa() in the end. @@ -1180,9 +1207,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) { CPUState *cs =3D CPU(dev); RISCVCPU *cpu =3D RISCV_CPU(dev); - CPURISCVState *env =3D &cpu->env; RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); - CPUClass *cc =3D CPU_CLASS(mcc); Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -1197,6 +1222,12 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 + riscv_cpu_validate_misa_mxl(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available @@ -1213,22 +1244,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) } #endif /* CONFIG_USER_ONLY */ =20 - /* Validate that MISA_MXL is set properly. */ - switch (env->misa_mxl_max) { -#ifdef TARGET_RISCV64 - case MXL_RV64: - case MXL_RV128: - cc->gdb_core_xml_file =3D "riscv-64bit-cpu.xml"; - break; -#endif - case MXL_RV32: - cc->gdb_core_xml_file =3D "riscv-32bit-cpu.xml"; - break; - default: - g_assert_not_reached(); - } - assert(env->misa_mxl_max =3D=3D env->misa_mxl); - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); --=20 2.39.2