From nobody Wed May 15 22:57:08 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 1711002739038733.9127803996436; Wed, 20 Mar 2024 23:32:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnBxN-0000e2-PI; Thu, 21 Mar 2024 02:31:17 -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 1rnBxL-0000dt-Ma for qemu-devel@nongnu.org; Thu, 21 Mar 2024 02:31:15 -0400 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rnBxJ-0001I0-8C for qemu-devel@nongnu.org; Thu, 21 Mar 2024 02:31:15 -0400 Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxXesr1Ptlt7YbAA--.675S3; Thu, 21 Mar 2024 14:31:07 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxTRMq1PtlXY5fAA--.54450S2; Thu, 21 Mar 2024 14:31:06 +0800 (CST) From: Song Gao To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, philmd@linaro.org, maobibo@loongson.cn Subject: [PATCH v2] target/loongarch: Fix qemu-system-loongarch64 assert failed with the option '-d int' Date: Thu, 21 Mar 2024 14:31:06 +0800 Message-Id: <20240321063106.1700330-1-gaosong@loongson.cn> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8AxTRMq1PtlXY5fAA--.54450S2 X-CM-SenderInfo: 5jdr20tqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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=114.242.206.163; envelope-from=gaosong@loongson.cn; helo=mail.loongson.cn 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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1711002741992100003 Content-Type: text/plain; charset="utf-8" qemu-system-loongarch64 assert failed with the option '-d int', the helper_idle() raise an exception EXCP_HLT, but the exception name is un= defined. Signed-off-by: Song Gao --- target/loongarch/cpu.c | 76 +++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index f6ffb3aadb..c56e606d28 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -45,33 +45,47 @@ const char * const fregnames[32] =3D { "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", }; =20 -static const char * const excp_names[] =3D { - [EXCCODE_INT] =3D "Interrupt", - [EXCCODE_PIL] =3D "Page invalid exception for load", - [EXCCODE_PIS] =3D "Page invalid exception for store", - [EXCCODE_PIF] =3D "Page invalid exception for fetch", - [EXCCODE_PME] =3D "Page modified exception", - [EXCCODE_PNR] =3D "Page Not Readable exception", - [EXCCODE_PNX] =3D "Page Not Executable exception", - [EXCCODE_PPI] =3D "Page Privilege error", - [EXCCODE_ADEF] =3D "Address error for instruction fetch", - [EXCCODE_ADEM] =3D "Address error for Memory access", - [EXCCODE_SYS] =3D "Syscall", - [EXCCODE_BRK] =3D "Break", - [EXCCODE_INE] =3D "Instruction Non-Existent", - [EXCCODE_IPE] =3D "Instruction privilege error", - [EXCCODE_FPD] =3D "Floating Point Disabled", - [EXCCODE_FPE] =3D "Floating Point Exception", - [EXCCODE_DBP] =3D "Debug breakpoint", - [EXCCODE_BCE] =3D "Bound Check Exception", - [EXCCODE_SXD] =3D "128 bit vector instructions Disable exception", - [EXCCODE_ASXD] =3D "256 bit vector instructions Disable exception", +struct TypeExcp { + int32_t exccode; + const char *name; +}; + +static const struct TypeExcp excp_names[] =3D { + {EXCCODE_INT, "Interrupt"}, + {EXCCODE_PIL, "Page invalid exception for load"}, + {EXCCODE_PIS, "Page invalid exception for store"}, + {EXCCODE_PIF, "Page invalid exception for fetch"}, + {EXCCODE_PME, "Page modified exception"}, + {EXCCODE_PNR, "Page Not Readable exception"}, + {EXCCODE_PNX, "Page Not Executable exception"}, + {EXCCODE_PPI, "Page Privilege error"}, + {EXCCODE_ADEF, "Address error for instruction fetch"}, + {EXCCODE_ADEM, "Address error for Memory access"}, + {EXCCODE_SYS, "Syscall"}, + {EXCCODE_BRK, "Break"}, + {EXCCODE_INE, "Instruction Non-Existent"}, + {EXCCODE_IPE, "Instruction privilege error"}, + {EXCCODE_FPD, "Floating Point Disabled"}, + {EXCCODE_FPE, "Floating Point Exception"}, + {EXCCODE_DBP, "Debug breakpoint"}, + {EXCCODE_BCE, "Bound Check Exception"}, + {EXCCODE_SXD, "128 bit vector instructions Disable exception"}, + {EXCCODE_ASXD, "256 bit vector instructions Disable exception"}, + {EXCP_HLT, "EXCP_HLT"}, }; =20 const char *loongarch_exception_name(int32_t exception) { - assert(excp_names[exception]); - return excp_names[exception]; + int i; + const char *name =3D NULL; + + for (i =3D 0; i < ARRAY_SIZE(excp_names); i++) { + if (excp_names[i].exccode =3D=3D exception) { + name =3D excp_names[i].name; + break; + } + } + return name; } =20 void G_NORETURN do_raise_exception(CPULoongArchState *env, @@ -80,7 +94,7 @@ void G_NORETURN do_raise_exception(CPULoongArchState *env, { CPUState *cs =3D env_cpu(env); =20 - qemu_log_mask(CPU_LOG_INT, "%s: %d (%s)\n", + qemu_log_mask(CPU_LOG_INT, "%s: expection: %d (%s)\n", __func__, exception, loongarch_exception_name(exception)); @@ -154,22 +168,16 @@ static void loongarch_cpu_do_interrupt(CPUState *cs) CPULoongArchState *env =3D cpu_env(cs); bool update_badinstr =3D 1; int cause =3D -1; - const char *name; bool tlbfill =3D FIELD_EX64(env->CSR_TLBRERA, CSR_TLBRERA, ISTLBR); uint32_t vec_size =3D FIELD_EX64(env->CSR_ECFG, CSR_ECFG, VS); =20 if (cs->exception_index !=3D EXCCODE_INT) { - if (cs->exception_index < 0 || - cs->exception_index >=3D ARRAY_SIZE(excp_names)) { - name =3D "unknown"; - } else { - name =3D excp_names[cs->exception_index]; - } - qemu_log_mask(CPU_LOG_INT, "%s enter: pc " TARGET_FMT_lx " ERA " TARGET_FMT_lx - " TLBRERA " TARGET_FMT_lx " %s exception\n", __func__, - env->pc, env->CSR_ERA, env->CSR_TLBRERA, name); + " TLBRERA " TARGET_FMT_lx " exception: %d (%s)\n", + __func__, env->pc, env->CSR_ERA, env->CSR_TLBRERA, + cs->exception_index, + loongarch_exception_name(cs->exception_index)); } =20 switch (cs->exception_index) { --=20 2.25.1