Commit 7ce1c6dd50 for qemu.org
commit 7ce1c6dd50c3b8ec0c835a2ceb9597c3ed572d56
Author: Brian Cain <brian.cain@oss.qualcomm.com>
Date: Tue Nov 24 11:03:12 2026 -0800
target/hexagon: report the faulting packet for stack limit exceptions
The stack limit check raised the exception from a helper without
updating the PC register, which is not kept current while a packet runs.
The exception's ELR was whatever PC was last written, so a handler that
skipped the faulting allocframe resumed at an earlier packet and took
the same exception forever. Pass the packet's PC to the helper.
This enables the framelimit systest.
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c
index 52615628e3..90b71ebc01 100644
--- a/target/hexagon/genptr.c
+++ b/target/hexagon/genptr.c
@@ -1156,7 +1156,8 @@ void gen_framecheck(DisasContext *ctx, TCGv_i32 addr, TCGv_i32 ea)
TCGLabel *ok = gen_new_label();
tcg_gen_brcond_i32(TCG_COND_GEU, addr, hex_gpr[HEX_REG_FRAMELIMIT], ok);
gen_helper_raise_stack_overflow(tcg_env,
- tcg_constant_i32(ctx->insn->slot), ea);
+ tcg_constant_i32(ctx->insn->slot), ea,
+ tcg_constant_i32(ctx->pkt.pc));
gen_set_label(ok);
#endif
}
diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h
index 292ca8eb7c..e658f8068f 100644
--- a/target/hexagon/helper.h
+++ b/target/hexagon/helper.h
@@ -158,7 +158,7 @@ DEF_HELPER_5(insn_cache_op, void, env, i32, int, int, i32)
#endif
#if !defined(CONFIG_USER_ONLY)
-DEF_HELPER_3(raise_stack_overflow, void, env, i32, i32)
+DEF_HELPER_4(raise_stack_overflow, void, env, i32, i32, i32)
DEF_HELPER_2(swi, void, env, i32)
DEF_HELPER_2(cswi, void, env, i32)
DEF_HELPER_2(ciad, void, env, i32)
diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
index 71b27ef07f..cdb731160e 100644
--- a/target/hexagon/op_helper.c
+++ b/target/hexagon/op_helper.c
@@ -1660,7 +1660,7 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV)
#ifndef CONFIG_USER_ONLY
void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
- uint32_t badva)
+ uint32_t badva, uint32_t pc)
{
/*
* Per section 7.3.1 of the V67 Programmer's Reference,
@@ -1677,6 +1677,8 @@ void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
cs = env_cpu(env);
cs->exception_index = HEX_EVENT_PRECISE;
env->cause_code = HEX_CAUSE_STACK_LIMIT;
+ /* The PC register is not kept current, ELR is the faulting packet */
+ env->gpr[HEX_REG_PC] = pc;
if (slot == 0) {
env->t_sreg[HEX_SREG_BADVA0] = badva;
diff --git a/tests/functional/hexagon/test_systests.py b/tests/functional/hexagon/test_systests.py
index 606567230b..f997563bac 100755
--- a/tests/functional/hexagon/test_systests.py
+++ b/tests/functional/hexagon/test_systests.py
@@ -87,6 +87,11 @@ def test_float_excp(self):
that caused them commits."""
self.run_exit_zero("float_excp")
+ def test_framelimit(self):
+ """allocframe past FRAMELIMIT in user mode raises the stack limit
+ exception at the allocframe packet."""
+ self.run_exit_zero("framelimit")
+
def test_access(self):
"""access checks R_OK|W_OK on _testfile_access."""
testfile = self.scratch_file("_testfile_access")