On 11/26/25 14:21, Philippe Mathieu-Daudé wrote:
Pass a full MemOpIdx at translation, then recover the
MMU index calling get_mmuidx() in the helper.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
  target/mips/tcg/ldst_helper.c | 4 +++-
  target/mips/tcg/translate.c   | 9 +++++----
  2 files changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <[email protected]>


r~


diff --git a/target/mips/tcg/ldst_helper.c b/target/mips/tcg/ldst_helper.c
index c1c4a60cf3f..013cd825dac 100644
--- a/target/mips/tcg/ldst_helper.c
+++ b/target/mips/tcg/ldst_helper.c
@@ -30,8 +30,10 @@
  #ifndef CONFIG_USER_ONLY
#define HELPER_LD_ATOMIC(name, almask, cpu_load) \
-target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx)  \
+target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int memop_idx)\
  {                                                                             
\
+    MemOpIdx oi = memop_idx;                                                  \
+    unsigned mem_idx = get_mmuidx(oi);                                        \
      if (arg & almask) {                                                       
\
          if (!(env->hflags & MIPS_HFLAG_DM)) {                                 
\
              env->CP0_BadVAddr = arg;                                          
\
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index 54849e9ff1a..c476271d6d5 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -1932,16 +1932,17 @@ static inline void op_ld_##insn(TCGv ret, TCGv arg1, 
int mem_idx,          \
      tcg_gen_st_tl(ret, tcg_env, offsetof(CPUMIPSState, llval));            \
  }
  #else
-#define OP_LD_ATOMIC(insn, ignored_memop)                                  \
+#define OP_LD_ATOMIC(insn, mop)                                            \
  static inline void op_ld_##insn(TCGv ret, TCGv arg1, int mem_idx,          \
                                  DisasContext *ctx)                         \
  {                                                                          \
-    gen_helper_##insn(ret, tcg_env, arg1, tcg_constant_i32(mem_idx));      \
+    MemOpIdx oi = make_memop_idx(mop | mo_endian(ctx), mem_idx);           \
+    gen_helper_##insn(ret, tcg_env, arg1, tcg_constant_i32(oi));           \
  }
  #endif
-OP_LD_ATOMIC(ll, mo_endian(ctx) | MO_SL);
+OP_LD_ATOMIC(ll, MO_SL);
  #if defined(TARGET_MIPS64)
-OP_LD_ATOMIC(lld, mo_endian(ctx) | MO_UQ);
+OP_LD_ATOMIC(lld, MO_UQ);
  #endif
  #undef OP_LD_ATOMIC


Reply via email to