hexagon_get_tb_cpu_state() detects a misaligned PC and raises an exception, but it passed HEX_CAUSE_PC_NOT_ALIGNED (a cause code) as the event argument to hexagon_raise_exception_err(), whose second parameter is the event index (it ends up in cs->exception_index). This causes an infinite reboot loop when we reache a misaligned PC.
Similarly, gen_exception_decode_fail() is called with a cause code (HEX_CAUSE_INVALID_PACKET) but unconditionally routes it through gen_exception(), which treats its argument as an event index and stores it directly in cs->exception_index. Signed-off-by: Matheus Tavares Bernardino <[email protected]> --- target/hexagon/cpu.c | 3 ++- target/hexagon/translate.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 42d93e5da47..eac355497d8 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -320,7 +320,8 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs) hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP, 1); } if (pc & PCALIGN_MASK) { - hexagon_raise_exception_err(env, HEX_CAUSE_PC_NOT_ALIGNED, 0); + env->cause_code = HEX_CAUSE_PC_NOT_ALIGNED; + hexagon_raise_exception_err(env, HEX_EVENT_PRECISE, (uint32_t)pc); } #ifndef CONFIG_USER_ONLY diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index 77235916f4b..341842c6af1 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -238,7 +238,11 @@ static void gen_exception_decode_fail(DisasContext *ctx, int nwords, int excp) gen_exec_counters(ctx); tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], fail_pc); +#ifdef CONFIG_USER_ONLY gen_exception(excp, fail_pc); +#else + gen_precise_exception(excp, fail_pc); +#endif ctx->base.is_jmp = DISAS_NORETURN; ctx->base.pc_next = fail_pc; } -- 2.37.2
