target/hexagon/cpu_bits.h | 1 + target/hexagon/gen_tcg.h | 18 ++++++++++--- target/hexagon/helper.h | 2 ++ target/hexagon/internal.h | 2 ++ target/hexagon/cpu.c | 15 +++++++++++ target/hexagon/hexswi.c | 1 + target/hexagon/op_helper.c | 33 +++++++++++++++++++++++ tests/functional/hexagon/test_systests.py | 10 ++++--- 8 files changed, 75 insertions(+), 7 deletions(-)
The dcinva, dccleaninva, dccleana and icinva instructions did nothing
in system mode, but the hardware translates their address. A data cache
operation takes a TLB miss exception if the address is unmapped, and a
privilege exception if the mapping can be neither read nor written. The
reads and writes are only probes of the permissions.
The data cache operations probe the address through the normal TLB fill
path, which also reports the packet that faulted.
Link: https://lore.kernel.org/qemu-devel/20261117183629.2002840-7-marco.liebel@oss.qualcomm.com/
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
target/hexagon/cpu_bits.h | 1 +
target/hexagon/gen_tcg.h | 18 ++++++++++---
target/hexagon/helper.h | 2 ++
target/hexagon/internal.h | 2 ++
target/hexagon/cpu.c | 15 +++++++++++
target/hexagon/hexswi.c | 1 +
target/hexagon/op_helper.c | 33 +++++++++++++++++++++++
tests/functional/hexagon/test_systests.py | 10 ++++---
8 files changed, 75 insertions(+), 7 deletions(-)
diff --git a/target/hexagon/cpu_bits.h b/target/hexagon/cpu_bits.h
index 65dda2175d5..a94b94452ae 100644
--- a/target/hexagon/cpu_bits.h
+++ b/target/hexagon/cpu_bits.h
@@ -98,6 +98,7 @@ enum hex_cause {
HEX_CAUSE_IMPRECISE_MULTI_TLB_MATCH = 0x044,
HEX_CAUSE_TLBMISSX_CAUSE_NORMAL = 0x060,
HEX_CAUSE_TLBMISSX_CAUSE_NEXTPAGE = 0x061,
+ HEX_CAUSE_TLBMISSX_CAUSE_ICINVA = 0x062,
HEX_CAUSE_TLBMISSRW_CAUSE_READ = 0x070,
HEX_CAUSE_TLBMISSRW_CAUSE_WRITE = 0x071,
HEX_CAUSE_DEBUG_SINGLESTEP = 0x80,
diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h
index e82f89aee42..e45d09cd8d0 100644
--- a/target/hexagon/gen_tcg.h
+++ b/target/hexagon/gen_tcg.h
@@ -512,23 +512,33 @@
#define fGEN_TCG_Y2_dczeroa(SHORTCODE) SHORTCODE
#define fGEN_TCG_Y2_dczeroa_nt(SHORTCODE) SHORTCODE
-/* In linux-user mode, these are not modelled, suppress compiler warning */
+#ifdef CONFIG_USER_ONLY
+/* In linux-user mode, the data cache is not modelled */
#define fGEN_TCG_Y2_dcinva(SHORTCODE) \
do { RsV = RsV; } while (0)
#define fGEN_TCG_Y2_dccleaninva(SHORTCODE) \
do { RsV = RsV; } while (0)
#define fGEN_TCG_Y2_dccleana(SHORTCODE) \
do { RsV = RsV; } while (0)
-
-#ifdef CONFIG_USER_ONLY
#define fGEN_TCG_Y2_icinva(SHORTCODE) \
gen_helper_insn_cache_op(tcg_env, RsV, \
tcg_constant_tl(insn->slot), \
tcg_constant_tl(ctx->mem_idx), \
tcg_constant_tl(ctx->pkt.pc))
#else
+/*
+ * In system mode the caches are not modelled either, but the operations
+ * translate their address so they can take TLB miss and privilege exceptions.
+ */
+#define fGEN_TCG_Y2_dcinva(SHORTCODE) \
+ gen_helper_data_cache_op(tcg_env, RsV, tcg_constant_i32(ctx->mem_idx))
+#define fGEN_TCG_Y2_dccleaninva(SHORTCODE) \
+ gen_helper_data_cache_op(tcg_env, RsV, tcg_constant_i32(ctx->mem_idx))
+#define fGEN_TCG_Y2_dccleana(SHORTCODE) \
+ gen_helper_data_cache_op(tcg_env, RsV, tcg_constant_i32(ctx->mem_idx))
#define fGEN_TCG_Y2_icinva(SHORTCODE) \
- do { RsV = RsV; } while (0)
+ gen_helper_insn_cache_op_check(tcg_env, RsV, \
+ tcg_constant_i32(ctx->mem_idx))
#endif
#define fGEN_TCG_V2_CHECK_AND_WRITE_VSP(VSP) \
diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h
index e658f8068f4..e7e7ab2c02e 100644
--- a/target/hexagon/helper.h
+++ b/target/hexagon/helper.h
@@ -159,6 +159,8 @@ DEF_HELPER_5(insn_cache_op, void, env, i32, int, int, i32)
#if !defined(CONFIG_USER_ONLY)
DEF_HELPER_4(raise_stack_overflow, void, env, i32, i32, i32)
+DEF_HELPER_3(data_cache_op, void, env, i32, i32)
+DEF_HELPER_3(insn_cache_op_check, void, env, 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/internal.h b/target/hexagon/internal.h
index 6def331a83a..d72f9b70241 100644
--- a/target/hexagon/internal.h
+++ b/target/hexagon/internal.h
@@ -59,6 +59,8 @@ void G_NORETURN do_raise_exception(CPUHexagonState *env,
})
#ifndef CONFIG_USER_ONLY
+void G_NORETURN hexagon_raise_icinva_tlbmiss(CPUHexagonState *env, uint32_t VA,
+ uintptr_t retaddr);
extern const VMStateDescription vmstate_hexagon_cpu;
#endif
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 3575b31d196..87c6b9680d3 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -868,6 +868,21 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,
do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC], retaddr);
}
+/*
+ * A TLB miss due to icinva reports the faulting page, not the address, and
+ * has its own cause code.
+ */
+G_NORETURN void hexagon_raise_icinva_tlbmiss(CPUHexagonState *env, uint32_t VA,
+ uintptr_t retaddr)
+{
+ CPUState *cs = env_cpu(env);
+
+ set_badva_regs(env, VA & TARGET_PAGE_MASK, 0, MMU_INST_FETCH);
+ cs->exception_index = HEX_EVENT_TLB_MISS_X;
+ env->cause_code = HEX_CAUSE_TLBMISSX_CAUSE_ICINVA;
+ do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC], retaddr);
+}
+
#include "hw/core/sysemu-cpu-ops.h"
static const struct SysemuCPUOps hexagon_sysemu_ops = {
diff --git a/target/hexagon/hexswi.c b/target/hexagon/hexswi.c
index 96d4a783ed4..c0698fb0c0f 100644
--- a/target/hexagon/hexswi.c
+++ b/target/hexagon/hexswi.c
@@ -914,6 +914,7 @@ void hexagon_cpu_do_interrupt(CPUState *cs)
switch (env->cause_code) {
case HEX_CAUSE_TLBMISSX_CAUSE_NORMAL:
case HEX_CAUSE_TLBMISSX_CAUSE_NEXTPAGE:
+ case HEX_CAUSE_TLBMISSX_CAUSE_ICINVA:
qemu_log_mask(CPU_LOG_MMU,
"TLB miss EX exception (0x%02" PRIx32 ") caught: "
"Cause code (0x%" PRIx32 ") "
diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
index cdb731160eb..84d1082af8a 100644
--- a/target/hexagon/op_helper.c
+++ b/target/hexagon/op_helper.c
@@ -25,6 +25,7 @@
#include "exec/helper-proto.h"
#include "exec/mmap-lock.h"
#include "exec/target_page.h"
+#include "exec/tlb-flags.h"
#include "exec/translation-block.h"
#include "fpu/softfloat.h"
#include "exec/cpu-interrupt.h"
@@ -1659,6 +1660,38 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV)
}
#ifndef CONFIG_USER_ONLY
+void HELPER(data_cache_op)(CPUHexagonState *env, uint32_t RsV,
+ uint32_t mmu_idx)
+{
+ uintptr_t ra = GETPC();
+ void *host;
+
+ if ((probe_access_flags(env, RsV, 1, MMU_DATA_LOAD, mmu_idx, true,
+ &host, ra) & TLB_INVALID_MASK) &&
+ (probe_access_flags(env, RsV, 1, MMU_DATA_STORE, mmu_idx, true,
+ &host, ra) & TLB_INVALID_MASK)) {
+ /* Not accessible at all, take the exception for a read */
+ probe_read(env, RsV, 1, mmu_idx, ra);
+ }
+}
+
+void HELPER(insn_cache_op_check)(CPUHexagonState *env, uint32_t RsV,
+ uint32_t mmu_idx)
+{
+ hwaddr phys;
+ int prot;
+ uint64_t size;
+ int32_t excp;
+
+ if (!hexagon_cpu_mmu_enabled(env)) {
+ return;
+ }
+ if (!hex_tlb_find_match(env, RsV, MMU_INST_FETCH, &phys, &prot, &size,
+ &excp, mmu_idx)) {
+ hexagon_raise_icinva_tlbmiss(env, RsV, GETPC());
+ }
+}
+
void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
uint32_t badva, uint32_t pc)
{
diff --git a/tests/functional/hexagon/test_systests.py b/tests/functional/hexagon/test_systests.py
index 4130c1b4ee1..e4e172645d2 100755
--- a/tests/functional/hexagon/test_systests.py
+++ b/tests/functional/hexagon/test_systests.py
@@ -22,9 +22,9 @@ class SysTestsStandaloneTests(QemuSystemTest):
ASSET_TARBALL = Asset(
"https://github.com/qualcomm/qemu-hexagon-testing/releases/"
- "download/v0.3.1/systests_standalone.tar.gz",
- "40163fa94d67a63e5ef645fc83682e4e"
- "b56e1d79a9068614055e74f35d4cf70d",
+ "download/v0.3.8/systests_standalone.tar.gz",
+ "b94d391052cdced7a88a9a859da7325e"
+ "d245592976d973e62e10e0d67025a896",
)
def setUp(self):
@@ -92,6 +92,10 @@ def test_framelimit(self):
exception at the allocframe packet."""
self.run_exit_zero("framelimit")
+ def test_mmu_cacheops(self):
+ """Cache operations raise TLB miss and privilege exceptions."""
+ self.run_exit_zero("mmu_cacheops")
+
def test_llsc_on_excp(self):
"""An exception between a load-locked and the store-conditional
clears the reservation."""
--
2.34.1
© 2016 - 2026 Red Hat, Inc.