From nobody Fri Mar 29 01:35:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.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 1550502511759473.53385927145894; Mon, 18 Feb 2019 07:08:31 -0800 (PST) Received: from localhost ([127.0.0.1]:60158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvkWu-00028S-JQ for importer@patchew.org; Mon, 18 Feb 2019 10:08:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvjwz-0005h5-Dx for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:31:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvjwq-0002ec-8V for qemu-devel@nongnu.org; Mon, 18 Feb 2019 09:31:15 -0500 Received: from ozlabs.org ([203.11.71.1]:49475) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gvjwp-0002bX-EY; Mon, 18 Feb 2019 09:31:08 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 4435rg2sT9z9sQm; Tue, 19 Feb 2019 01:30:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1550500259; bh=E+JxlrJ/pDFyS5PHraRA/utYy+hjrBoU1vKR/rjy2sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZQQnQhB5UVAMVePcFnZ9aUzxz0j0frIQg8bnQeiY5/9Zmlgb/sgrCsJw542RMGv3I yRutQIRvjKcKttDV4IfFWLyR18Ju3lI/IWfKrbssd4jdVx074TLI0ARyYU8PRANkrg sgsXbN9m+GhZtnD5GTp++B2NQecCQMogv+hoks3A= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 19 Feb 2019 01:30:16 +1100 Message-Id: <20190218143049.17142-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218143049.17142-1-david@gibson.dropbear.id.au> References: <20190218143049.17142-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 10/43] ppc: fix crash during branch stepping X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kapl , groug@kaod.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Roman Kapl The PPC BRANCH exception could bubble up, but this is an QEMU internal exce= ption and QEMU then crased. Instead it should trigger TRACE exception, according = to PPC 2.07 book. It could happen only when using branch stepping, which is not commonly used. Change gen_prep_dbgex do do trigger TRACE. The excp, argument is now remove= d, since the type of exception can be inferred from the singlestep_enabled fla= gs. removed the guards around gen_exception, since they are unnecessary. Fixes: 0e3bf48909 ("ppc: add DBCR based debugging"). Signed-off-by: Roman Kapl Message-Id: <20190212121255.2279-1-rka@sysgo.com> Signed-off-by: David Gibson --- target/ppc/translate.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 5429ceb1ab..d5f29d3536 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -287,26 +287,22 @@ static void gen_exception_nip(DisasContext *ctx, uint= 32_t excp, ctx->exception =3D (excp); } =20 -/* Translates the EXCP_TRACE/BRANCH exceptions used on most PowerPCs to - * EXCP_DEBUG, if we are running on cores using the debug enable bit (e.g. - * BookE). +/* + * Tells the caller what is the appropriate exception to generate and prep= ares + * SPR registers for this exception. + * + * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or + * POWERPC_EXCP_DEBUG (on BookE). */ -static uint32_t gen_prep_dbgex(DisasContext *ctx, uint32_t excp) +static uint32_t gen_prep_dbgex(DisasContext *ctx) { - if ((ctx->singlestep_enabled & CPU_SINGLE_STEP) - && (excp =3D=3D POWERPC_EXCP_BRANCH)) { - /* Trace excpt. has priority */ - excp =3D POWERPC_EXCP_TRACE; - } if (ctx->flags & POWERPC_FLAG_DE) { target_ulong dbsr =3D 0; - switch (excp) { - case POWERPC_EXCP_TRACE: + if (ctx->singlestep_enabled & CPU_SINGLE_STEP) { dbsr =3D DBCR0_ICMP; - break; - case POWERPC_EXCP_BRANCH: + } else { + /* Must have been branch */ dbsr =3D DBCR0_BRT; - break; } TCGv t0 =3D tcg_temp_new(); gen_load_spr(t0, SPR_BOOKE_DBSR); @@ -315,7 +311,7 @@ static uint32_t gen_prep_dbgex(DisasContext *ctx, uint3= 2_t excp) tcg_temp_free(t0); return POWERPC_EXCP_DEBUG; } else { - return excp; + return POWERPC_EXCP_TRACE; } } =20 @@ -3652,10 +3648,8 @@ static void gen_lookup_and_goto_ptr(DisasContext *ct= x) if (sse & GDBSTUB_SINGLE_STEP) { gen_debug_exception(ctx); } else if (sse & (CPU_SINGLE_STEP | CPU_BRANCH_STEP)) { - uint32_t excp =3D gen_prep_dbgex(ctx, POWERPC_EXCP_BRANCH); - if (excp !=3D POWERPC_EXCP_NONE) { - gen_exception(ctx, excp); - } + uint32_t excp =3D gen_prep_dbgex(ctx); + gen_exception(ctx, excp); } tcg_gen_exit_tb(NULL, 0); } else { @@ -7790,9 +7784,8 @@ static void ppc_tr_translate_insn(DisasContextBase *d= cbase, CPUState *cs) ctx->exception !=3D POWERPC_SYSCALL && ctx->exception !=3D POWERPC_EXCP_TRAP && ctx->exception !=3D POWERPC_EXCP_BRANCH)) { - uint32_t excp =3D gen_prep_dbgex(ctx, POWERPC_EXCP_TRACE); - if (excp !=3D POWERPC_EXCP_NONE) - gen_exception_nip(ctx, excp, ctx->base.pc_next); + uint32_t excp =3D gen_prep_dbgex(ctx); + gen_exception_nip(ctx, excp, ctx->base.pc_next); } =20 if (tcg_check_temp_count()) { --=20 2.20.1