From patchwork Wed Jun 14 01:19:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 13279389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D301EB64D7 for ; Wed, 14 Jun 2023 01:26:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q9FCK-0004ia-U5; Tue, 13 Jun 2023 21:21:20 -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 1q9FCJ-0004iS-NT for qemu-devel@nongnu.org; Tue, 13 Jun 2023 21:21:19 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q9FCI-0004W1-0q for qemu-devel@nongnu.org; Tue, 13 Jun 2023 21:21:19 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso4341766a12.3 for ; Tue, 13 Jun 2023 18:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686705676; x=1689297676; 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=jXjMddEkFexM6dIvBhKD1JVBRSaeECHs8plK2ye1DCc=; b=paMy99EHJBj7bVUmhKnJFiCTu0sj+/WWm+bdeflNLPBkb/xAhfzysy17DWm25KmeXL gLXTaeKHpaux4IHUiKJ4i48KyFO4DUtkgA5gGYst7a8uZsm0Jzwkbc2X0wgMz/a/Pq6Y nlDcCJqQu4Rm4zxS62I38DpDljkOXeKzsE01yC4aX+ne8juTT9jWulNzgkGH2pv6KNV6 C01UTaWYPc+o2jWJo2Lqcq7nAVSw9QCpr+s3CXWRtKP/n45LWtrpUgPxTFzhYxG/Drx6 je53nE3lTKdaOrBKD4BxY6v1TMfJSLJgLWPD9Sxp0y9cwcVzd6SehkdUX9++c1M24IQj q0ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686705676; x=1689297676; 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=jXjMddEkFexM6dIvBhKD1JVBRSaeECHs8plK2ye1DCc=; b=cSB6oLzdug7UvB9tK1Q8aBVp8jgR8wR4MTlZ2Jk8jpauoQkly9mlvPdCHcMJozKCRk MQnKPSnB51e9uqAtP0rehlprzNJuQSSpVgf2B2dZUtn9NlwtciLebcNu8ylgBqNT64TQ 9q16K2IrtyFT2AKJV5I2lO2ZnpC0WLwzj6/RfHIhoHJxsCHdrJukxV+W9Mz5dbfjHULP aQadx1dJBQ1ilkUnoS9pWqclT3Jtaf0zEvy8+EmyYYRJsARlCJW0LtKV3kPNR3YG5lii /sqzSz6iQa+OvBz+UY/Kl0gdv9xY03nmAb8jeH4r0wbhH+xXcity+mZJAeveCaag5bh1 TnWA== X-Gm-Message-State: AC+VfDzgenGFNN/goumu35DWk5fXqb1kTvpwyskQ0oEZ6EXw+Auk4ojw k3bBVnVw+6KFl355WsFFfYO2erXmlyYAUA== X-Google-Smtp-Source: ACHHUZ6QsIwm/319+iHH0X/nDMsTTMjXB+irRTwkpHnRFxgA2v6n+TkwYhkcS0nDRBcyUB8Cjdu/wA== X-Received: by 2002:a05:6a21:6811:b0:118:b2e1:9adb with SMTP id wr17-20020a056a21681100b00118b2e19adbmr281223pzb.61.1686705676445; Tue, 13 Jun 2023 18:21:16 -0700 (PDT) Received: from toolbox.wdc.com (2403-580b-97e8-0-321-6fb2-58f1-a1b1.ip6.aussiebb.net. [2403:580b:97e8:0:321:6fb2:58f1:a1b1]) by smtp.gmail.com with ESMTPSA id u1-20020aa78381000000b0064f7c56d8b7sm9112238pfm.219.2023.06.13.18.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 18:21:15 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Daniel Henrique Barboza , LIU Zhiwei , Weiwei Li , Alistair Francis Subject: [PULL 10/60] target/riscv/cpu.c: add riscv_cpu_validate_misa_mxl() Date: Wed, 14 Jun 2023 11:19:27 +1000 Message-Id: <20230614012017.3100663-11-alistair.francis@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230614012017.3100663-1-alistair.francis@wdc.com> References: <20230614012017.3100663-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=alistair23@gmail.com; helo=mail-pg1-x529.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Daniel Henrique Barboza 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 != env->misa_mlx. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis Message-Id: <20230517135714.211809-9-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- target/riscv/cpu.c | 50 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index a0589abb16..89a1a25812 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -910,6 +910,33 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) +{ + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); + CPUClass *cc = CPU_CLASS(mcc); + CPURISCVState *env = &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 = "riscv-64bit-cpu.xml"; + break; +#endif + case MXL_RV32: + cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; + break; + default: + g_assert_not_reached(); + } + + if (env->misa_mxl_max != 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. @@ -1232,7 +1259,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) RISCVCPU *cpu = RISCV_CPU(dev); CPURISCVState *env = &cpu->env; RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); - CPUClass *cc = CPU_CLASS(mcc); Error *local_err = NULL; cpu_exec_realizefn(cs, &local_err); @@ -1241,6 +1267,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) return; } + riscv_cpu_validate_misa_mxl(cpu, &local_err); + if (local_err != NULL) { + error_propagate(errp, local_err); + return; + } + riscv_cpu_validate_priv_spec(cpu, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); @@ -1269,22 +1301,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } #endif /* CONFIG_USER_ONLY */ - /* 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 = "riscv-64bit-cpu.xml"; - break; -#endif - case MXL_RV32: - cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; - break; - default: - g_assert_not_reached(); - } - assert(env->misa_mxl_max == env->misa_mxl); - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err != NULL) { error_propagate(errp, local_err);