Commit 6b3546465e for qemu.org
commit 6b3546465e645456be75a54661b91d028799e79e
Author: Brian Cain <brian.cain@oss.qualcomm.com>
Date: Tue Nov 24 11:03:11 2026 -0800
target/hexagon: deliver floating point exceptions after the packet
An unmasked floating point exception used to take the exception in the
middle of the packet, with whatever PC was last written. The
architecture takes it after the packet commits, like trap0, so pend it
the way the TLB pends an imprecise exception and raise it at the end of
the packet. Report ELR as the last word of the packet so that a handler
resumes at the next packet by advancing ELR by one word.
This enables the float_excp 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/arch.c b/target/hexagon/arch.c
index 5ee87b320b..ddbcba9cdd 100644
--- a/target/hexagon/arch.c
+++ b/target/hexagon/arch.c
@@ -214,13 +214,14 @@ void arch_fpop_start(CPUHexagonState *env)
*/
#define RAISE_FP_EXCEPTION do {} while (0)
#else
+/*
+ * Floating point exceptions are taken after the packet that caused them
+ * commits, so pend this one for check_imprecise_exception().
+ */
#define RAISE_FP_EXCEPTION \
do { \
- CPUState *cs = env_cpu(env); \
- cs->exception_index = HEX_EVENT_FPTRAP; \
+ env->imprecise_exception = HEX_EVENT_FPTRAP; \
env->cause_code = HEX_CAUSE_FPTRAP_CAUSE_BADFLOAT; \
- do_raise_exception(env, cs->exception_index, \
- env->gpr[HEX_REG_PC], 0); \
} while (0)
#endif
diff --git a/target/hexagon/hexswi.c b/target/hexagon/hexswi.c
index acc68aa6c2..96d4a783ed 100644
--- a/target/hexagon/hexswi.c
+++ b/target/hexagon/hexswi.c
@@ -972,6 +972,7 @@ void hexagon_cpu_do_interrupt(CPUState *cs)
break;
case HEX_EVENT_FPTRAP:
+ env->imprecise_exception = 0;
if (event_to_guest(env, CCR_GEE)) {
guest_event_entry(env, env->cause_code, env->gpr[HEX_REG_PC],
HEX_GEVB_HW_FPTRAP, false);
diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
index 796d32bff9..2461b0064a 100644
--- a/target/hexagon/translate.c
+++ b/target/hexagon/translate.c
@@ -1345,11 +1345,17 @@ static void update_exec_counters(DisasContext *ctx)
#ifndef CONFIG_USER_ONLY
/*
* A tlbp instruction may detect multiple TLB matches and set a pending
- * imprecise exception. Raise it after the packet that ran the tlbp.
+ * imprecise exception, and a floating point instruction may set a pending
+ * floating point exception. Raise them after the packet that caused them.
+ *
+ * A floating point exception establishes the exception point after the
+ * packet, like trap0. ELR is the last word of the packet, so a handler
+ * resumes at the next packet by advancing ELR by one word.
*/
static void check_imprecise_exception(DisasContext *ctx)
{
- TCGv PC = tcg_constant_tl(ctx->pkt.pc);
+ TCGv PC = tcg_constant_tl(check_for_attrib(&ctx->pkt, A_FPOP) ?
+ ctx->next_PC - 4 : ctx->pkt.pc);
TCGLabel *label = gen_new_label();
tcg_gen_brcondi_tl(TCG_COND_EQ, hex_imprecise_exception, 0, label);
diff --git a/tests/functional/hexagon/test_systests.py b/tests/functional/hexagon/test_systests.py
index 76e2480c1d..606567230b 100755
--- a/tests/functional/hexagon/test_systests.py
+++ b/tests/functional/hexagon/test_systests.py
@@ -82,6 +82,11 @@ def test_ftrunc(self):
self.assertEqual(os.path.getsize(ftrunc_path), 1,
"_testfile_ftrunc should be 1 byte after ftrunc")
+ def test_float_excp(self):
+ """Unmasked floating point exceptions are taken after the packet
+ that caused them commits."""
+ self.run_exit_zero("float_excp")
+
def test_access(self):
"""access checks R_OK|W_OK on _testfile_access."""
testfile = self.scratch_file("_testfile_access")