On 3/18/25 17:23, Pierrick Bouvier wrote:
  uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, vaddr pc)
  {
-    uint64_t raw, tgt;
+    uint64_t val;
-    if (translator_ld(env, db, &raw, pc, sizeof(raw))) {
-        tgt = tswap64(raw);
-    } else {
-        tgt = cpu_ldq_code(env, pc);
-        raw = tswap64(tgt);
-        record_save(db, pc, &raw, sizeof(raw));
+    if (!translator_ld(env, db, &val, pc, sizeof(val))) {
+        MemOpIdx oi = make_memop_idx(MO_UQ, db->code_mmuidx);
+        val = cpu_ldq_code_mmu(env, pc, oi, 0);
+        record_save(db, pc, &val, sizeof(val));
      }
-    return tgt;
+    return tswap64(val);
  }
  void translator_fake_ld(DisasContextBase *db, const void *data, size_t len)

If I understand correctly, cpu_ldq_code_mmu performs the tswap call we used to before.

Incorrect: cpu_ldq_code_mmu has no tswap.

It has a conditional bswap, if MO_BSWAP is set, but that's not true for the MO_UQ used here. Therefore both the direct load in translator_ld and the cpu_ld*_code_mmu function call both produce host-endian values.

Therefore the tswap at the end correctly swaps host to target-endianness.


r~

Reply via email to