aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/hw/core/cpu.h11
-rw-r--r--tcg/tcg.c3
2 files changed, 12 insertions, 2 deletions
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 22a78c9..c9f40c2 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -603,9 +603,18 @@ static inline CPUArchState *cpu_env(CPUState *cpu)
}
#ifdef CONFIG_TCG
+/*
+ * Invert the index order of the CPUTLBDescFast array so that lower
+ * mmu_idx have offsets from env with smaller magnitude.
+ */
+static inline int mmuidx_to_fast_index(int mmu_idx)
+{
+ return NB_MMU_MODES - 1 - mmu_idx;
+}
+
static inline CPUTLBDescFast *cpu_tlb_fast(CPUState *cpu, int mmu_idx)
{
- return &cpu->neg.tlb.f[mmu_idx];
+ return &cpu->neg.tlb.f[mmuidx_to_fast_index(mmu_idx)];
}
#endif
diff --git a/tcg/tcg.c b/tcg/tcg.c
index afac55a..294762c 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -425,7 +425,8 @@ static uintptr_t G_GNUC_UNUSED get_jmp_target_addr(TCGContext *s, int which)
static int __attribute__((unused))
tlb_mask_table_ofs(TCGContext *s, int which)
{
- return (offsetof(CPUNegativeOffsetState, tlb.f[which]) -
+ int fi = mmuidx_to_fast_index(which);
+ return (offsetof(CPUNegativeOffsetState, tlb.f[fi]) -
sizeof(CPUNegativeOffsetState));
}