diff mbox

[v3,04/22] target-arm: Add arm_el_to_mmu_idx()

Message ID 1400491383-6725-5-git-send-email-edgar.iglesias@gmail.com
State New
Headers show

Commit Message

Edgar E. Iglesias May 19, 2014, 9:22 a.m. UTC
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Maps a given EL to the corresponding MMU index.

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 target-arm/cpu.h           | 22 +++++++++++++++++++++-
 target-arm/translate-a64.c |  8 ++------
 2 files changed, 23 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 11b7a0b..b6ad913 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -1083,9 +1083,29 @@  static inline CPUARMState *cpu_init(const char *cpu_model)
 #define MMU_MODE0_SUFFIX _kernel
 #define MMU_MODE1_SUFFIX _user
 #define MMU_USER_IDX 1
+
+static inline int arm_el_to_mmu_idx(int current_el)
+{
+#ifdef CONFIG_USER_ONLY
+    return MMU_USER_IDX;
+#else
+    switch (current_el) {
+    case 0:
+        return MMU_USER_IDX;
+    case 1:
+        return 0;
+    default:
+        /* Unsupported EL.  */
+        assert(0);
+        return 0;
+    }
+#endif
+}
+
 static inline int cpu_mmu_index (CPUARMState *env)
 {
-    return arm_current_pl(env) ? 0 : 1;
+    int cur_el = arm_current_pl(env);
+    return arm_el_to_mmu_idx(cur_el);
 }
 
 #include "exec/cpu-all.h"
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index b62db4d..7fce05f 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -162,13 +162,9 @@  void aarch64_cpu_dump_state(CPUState *cs, FILE *f,
     }
 }
 
-static int get_mem_index(DisasContext *s)
+static inline int get_mem_index(DisasContext *s)
 {
-#ifdef CONFIG_USER_ONLY
-    return 1;
-#else
-    return s->user;
-#endif
+    return arm_el_to_mmu_idx(s->current_pl);
 }
 
 void gen_a64_set_pc_im(uint64_t val)