5544c1b
From 449d4f2cfbdd2b5fd00e3e82c78bf580bd81551d Mon Sep 17 00:00:00 2001
5544c1b
From: Blue Swirl <blauwirbel@gmail.com>
5544c1b
Date: Sun, 2 Sep 2012 08:39:22 +0000
5544c1b
Subject: [PATCH] target-microblaze: switch to AREG0 free mode
5544c1b
5544c1b
Add an explicit CPUState parameter instead of relying on AREG0
5544c1b
and switch to AREG0 free mode.
5544c1b
5544c1b
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
---
5544c1b
 configure                       |   2 +-
5544c1b
 target-microblaze/Makefile.objs |   2 -
5544c1b
 target-microblaze/helper.h      |  48 ++++++++---------
5544c1b
 target-microblaze/op_helper.c   | 115 ++++++++++++++++++----------------------
5544c1b
 target-microblaze/translate.c   |  61 +++++++++++----------
5544c1b
 5 files changed, 110 insertions(+), 118 deletions(-)
5544c1b
5544c1b
diff --git a/configure b/configure
5544c1b
index e8806f0..0b4ef4a 100755
5544c1b
--- a/configure
5544c1b
+++ b/configure
5544c1b
@@ -3839,7 +3839,7 @@ symlink "$source_path/Makefile.target" "$target_dir/Makefile"
5544c1b
 
5544c1b
 
5544c1b
 case "$target_arch2" in
5544c1b
-  alpha | arm* | i386 | lm32 | m68k | or32 | s390x | sparc* | unicore32 | x86_64 | xtensa* | ppc*)
5544c1b
+  alpha | arm* | i386 | lm32 | m68k | microblaze* | or32 | s390x | sparc* | unicore32 | x86_64 | xtensa* | ppc*)
5544c1b
     echo "CONFIG_TCG_PASS_AREG0=y" >> $config_target_mak
5544c1b
   ;;
5544c1b
 esac
5544c1b
diff --git a/target-microblaze/Makefile.objs b/target-microblaze/Makefile.objs
5544c1b
index 4b09e8c..afb87bc 100644
5544c1b
--- a/target-microblaze/Makefile.objs
5544c1b
+++ b/target-microblaze/Makefile.objs
5544c1b
@@ -1,4 +1,2 @@
5544c1b
 obj-y += translate.o op_helper.o helper.o cpu.o
5544c1b
 obj-$(CONFIG_SOFTMMU) += mmu.o machine.o
5544c1b
-
5544c1b
-$(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1b
diff --git a/target-microblaze/helper.h b/target-microblaze/helper.h
5544c1b
index 9dcfb0f..a1a732c 100644
5544c1b
--- a/target-microblaze/helper.h
5544c1b
+++ b/target-microblaze/helper.h
5544c1b
@@ -1,39 +1,39 @@
5544c1b
 #include "def-helper.h"
5544c1b
 
5544c1b
-DEF_HELPER_1(raise_exception, void, i32)
5544c1b
-DEF_HELPER_0(debug, void)
5544c1b
+DEF_HELPER_2(raise_exception, void, env, i32)
5544c1b
+DEF_HELPER_1(debug, void, env)
5544c1b
 DEF_HELPER_FLAGS_3(carry, TCG_CALL_PURE | TCG_CALL_CONST, i32, i32, i32, i32)
5544c1b
 DEF_HELPER_2(cmp, i32, i32, i32)
5544c1b
 DEF_HELPER_2(cmpu, i32, i32, i32)
5544c1b
 DEF_HELPER_FLAGS_1(clz, TCG_CALL_PURE | TCG_CALL_CONST, i32, i32)
5544c1b
 
5544c1b
-DEF_HELPER_2(divs, i32, i32, i32)
5544c1b
-DEF_HELPER_2(divu, i32, i32, i32)
5544c1b
-
5544c1b
-DEF_HELPER_2(fadd, i32, i32, i32)
5544c1b
-DEF_HELPER_2(frsub, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fmul, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fdiv, i32, i32, i32)
5544c1b
-DEF_HELPER_1(flt, i32, i32)
5544c1b
-DEF_HELPER_1(fint, i32, i32)
5544c1b
-DEF_HELPER_1(fsqrt, i32, i32)
5544c1b
-
5544c1b
-DEF_HELPER_2(fcmp_un, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fcmp_lt, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fcmp_eq, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fcmp_le, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fcmp_gt, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fcmp_ne, i32, i32, i32)
5544c1b
-DEF_HELPER_2(fcmp_ge, i32, i32, i32)
5544c1b
+DEF_HELPER_3(divs, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(divu, i32, env, i32, i32)
5544c1b
+
5544c1b
+DEF_HELPER_3(fadd, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(frsub, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fmul, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fdiv, i32, env, i32, i32)
5544c1b
+DEF_HELPER_2(flt, i32, env, i32)
5544c1b
+DEF_HELPER_2(fint, i32, env, i32)
5544c1b
+DEF_HELPER_2(fsqrt, i32, env, i32)
5544c1b
+
5544c1b
+DEF_HELPER_3(fcmp_un, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fcmp_lt, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fcmp_eq, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fcmp_le, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fcmp_gt, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fcmp_ne, i32, env, i32, i32)
5544c1b
+DEF_HELPER_3(fcmp_ge, i32, env, i32, i32)
5544c1b
 
5544c1b
 DEF_HELPER_FLAGS_2(pcmpbf, TCG_CALL_PURE | TCG_CALL_CONST, i32, i32, i32)
5544c1b
 #if !defined(CONFIG_USER_ONLY)
5544c1b
-DEF_HELPER_1(mmu_read, i32, i32)
5544c1b
-DEF_HELPER_2(mmu_write, void, i32, i32)
5544c1b
+DEF_HELPER_2(mmu_read, i32, env, i32)
5544c1b
+DEF_HELPER_3(mmu_write, void, env, i32, i32)
5544c1b
 #endif
5544c1b
 
5544c1b
-DEF_HELPER_4(memalign, void, i32, i32, i32, i32)
5544c1b
-DEF_HELPER_1(stackprot, void, i32)
5544c1b
+DEF_HELPER_5(memalign, void, env, i32, i32, i32, i32)
5544c1b
+DEF_HELPER_2(stackprot, void, env, i32)
5544c1b
 
5544c1b
 DEF_HELPER_2(get, i32, i32, i32)
5544c1b
 DEF_HELPER_3(put, void, i32, i32, i32)
5544c1b
diff --git a/target-microblaze/op_helper.c b/target-microblaze/op_helper.c
5544c1b
index 3b1f072..c9789f4 100644
5544c1b
--- a/target-microblaze/op_helper.c
5544c1b
+++ b/target-microblaze/op_helper.c
5544c1b
@@ -20,7 +20,6 @@
5544c1b
 
5544c1b
 #include <assert.h>
5544c1b
 #include "cpu.h"
5544c1b
-#include "dyngen-exec.h"
5544c1b
 #include "helper.h"
5544c1b
 #include "host-utils.h"
5544c1b
 
5544c1b
@@ -42,17 +41,12 @@
5544c1b
 /* Try to fill the TLB and return an exception if error. If retaddr is
5544c1b
    NULL, it means that the function was called in C code (i.e. not
5544c1b
    from generated code or from helper.c) */
5544c1b
-/* XXX: fix it to restore all registers */
5544c1b
-void tlb_fill(CPUMBState *env1, target_ulong addr, int is_write, int mmu_idx,
5544c1b
+void tlb_fill(CPUMBState *env, target_ulong addr, int is_write, int mmu_idx,
5544c1b
               uintptr_t retaddr)
5544c1b
 {
5544c1b
     TranslationBlock *tb;
5544c1b
-    CPUMBState *saved_env;
5544c1b
     int ret;
5544c1b
 
5544c1b
-    saved_env = env;
5544c1b
-    env = env1;
5544c1b
-
5544c1b
     ret = cpu_mb_handle_mmu_fault(env, addr, is_write, mmu_idx);
5544c1b
     if (unlikely(ret)) {
5544c1b
         if (retaddr) {
5544c1b
@@ -66,7 +60,6 @@ void tlb_fill(CPUMBState *env1, target_ulong addr, int is_write, int mmu_idx,
5544c1b
         }
5544c1b
         cpu_loop_exit(env);
5544c1b
     }
5544c1b
-    env = saved_env;
5544c1b
 }
5544c1b
 #endif
5544c1b
 
5544c1b
@@ -105,13 +98,13 @@ uint32_t helper_get(uint32_t id, uint32_t ctrl)
5544c1b
     return 0xdead0000 | id;
5544c1b
 }
5544c1b
 
5544c1b
-void helper_raise_exception(uint32_t index)
5544c1b
+void helper_raise_exception(CPUMBState *env, uint32_t index)
5544c1b
 {
5544c1b
     env->exception_index = index;
5544c1b
     cpu_loop_exit(env);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_debug(void)
5544c1b
+void helper_debug(CPUMBState *env)
5544c1b
 {
5544c1b
     int i;
5544c1b
 
5544c1b
@@ -176,7 +169,7 @@ uint32_t helper_carry(uint32_t a, uint32_t b, uint32_t cf)
5544c1b
     return ncf;
5544c1b
 }
5544c1b
 
5544c1b
-static inline int div_prepare(uint32_t a, uint32_t b)
5544c1b
+static inline int div_prepare(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     if (b == 0) {
5544c1b
         env->sregs[SR_MSR] |= MSR_DZ;
5544c1b
@@ -184,7 +177,7 @@ static inline int div_prepare(uint32_t a, uint32_t b)
5544c1b
         if ((env->sregs[SR_MSR] & MSR_EE)
5544c1b
             && !(env->pvr.regs[2] & PVR2_DIV_ZERO_EXC_MASK)) {
5544c1b
             env->sregs[SR_ESR] = ESR_EC_DIVZERO;
5544c1b
-            helper_raise_exception(EXCP_HW_EXCP);
5544c1b
+            helper_raise_exception(env, EXCP_HW_EXCP);
5544c1b
         }
5544c1b
         return 0;
5544c1b
     }
5544c1b
@@ -192,28 +185,30 @@ static inline int div_prepare(uint32_t a, uint32_t b)
5544c1b
     return 1;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_divs(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_divs(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
-    if (!div_prepare(a, b))
5544c1b
+    if (!div_prepare(env, a, b)) {
5544c1b
         return 0;
5544c1b
+    }
5544c1b
     return (int32_t)a / (int32_t)b;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_divu(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_divu(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
-    if (!div_prepare(a, b))
5544c1b
+    if (!div_prepare(env, a, b)) {
5544c1b
         return 0;
5544c1b
+    }
5544c1b
     return a / b;
5544c1b
 }
5544c1b
 
5544c1b
 /* raise FPU exception.  */
5544c1b
-static void raise_fpu_exception(void)
5544c1b
+static void raise_fpu_exception(CPUMBState *env)
5544c1b
 {
5544c1b
     env->sregs[SR_ESR] = ESR_EC_FPU;
5544c1b
-    helper_raise_exception(EXCP_HW_EXCP);
5544c1b
+    helper_raise_exception(env, EXCP_HW_EXCP);
5544c1b
 }
5544c1b
 
5544c1b
-static void update_fpu_flags(int flags)
5544c1b
+static void update_fpu_flags(CPUMBState *env, int flags)
5544c1b
 {
5544c1b
     int raise = 0;
5544c1b
 
5544c1b
@@ -236,11 +231,11 @@ static void update_fpu_flags(int flags)
5544c1b
     if (raise
5544c1b
         && (env->pvr.regs[2] & PVR2_FPU_EXC_MASK)
5544c1b
         && (env->sregs[SR_MSR] & MSR_EE)) {
5544c1b
-        raise_fpu_exception();
5544c1b
+        raise_fpu_exception(env);
5544c1b
     }
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fadd(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fadd(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fd, fa, fb;
5544c1b
     int flags;
5544c1b
@@ -251,11 +246,11 @@ uint32_t helper_fadd(uint32_t a, uint32_t b)
5544c1b
     fd.f = float32_add(fa.f, fb.f, &env->fp_status);
5544c1b
 
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags);
5544c1b
+    update_fpu_flags(env, flags);
5544c1b
     return fd.l;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_frsub(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_frsub(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fd, fa, fb;
5544c1b
     int flags;
5544c1b
@@ -265,11 +260,11 @@ uint32_t helper_frsub(uint32_t a, uint32_t b)
5544c1b
     fb.l = b;
5544c1b
     fd.f = float32_sub(fb.f, fa.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags);
5544c1b
+    update_fpu_flags(env, flags);
5544c1b
     return fd.l;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fmul(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fmul(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fd, fa, fb;
5544c1b
     int flags;
5544c1b
@@ -279,12 +274,12 @@ uint32_t helper_fmul(uint32_t a, uint32_t b)
5544c1b
     fb.l = b;
5544c1b
     fd.f = float32_mul(fa.f, fb.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags);
5544c1b
+    update_fpu_flags(env, flags);
5544c1b
 
5544c1b
     return fd.l;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fdiv(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fdiv(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fd, fa, fb;
5544c1b
     int flags;
5544c1b
@@ -294,12 +289,12 @@ uint32_t helper_fdiv(uint32_t a, uint32_t b)
5544c1b
     fb.l = b;
5544c1b
     fd.f = float32_div(fb.f, fa.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags);
5544c1b
+    update_fpu_flags(env, flags);
5544c1b
 
5544c1b
     return fd.l;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_un(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_un(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     uint32_t r = 0;
5544c1b
@@ -308,7 +303,7 @@ uint32_t helper_fcmp_un(uint32_t a, uint32_t b)
5544c1b
     fb.l = b;
5544c1b
 
5544c1b
     if (float32_is_signaling_nan(fa.f) || float32_is_signaling_nan(fb.f)) {
5544c1b
-        update_fpu_flags(float_flag_invalid);
5544c1b
+        update_fpu_flags(env, float_flag_invalid);
5544c1b
         r = 1;
5544c1b
     }
5544c1b
 
5544c1b
@@ -319,7 +314,7 @@ uint32_t helper_fcmp_un(uint32_t a, uint32_t b)
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_lt(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_lt(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     int r;
5544c1b
@@ -330,12 +325,12 @@ uint32_t helper_fcmp_lt(uint32_t a, uint32_t b)
5544c1b
     fb.l = b;
5544c1b
     r = float32_lt(fb.f, fa.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags & float_flag_invalid);
5544c1b
+    update_fpu_flags(env, flags & float_flag_invalid);
5544c1b
 
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_eq(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_eq(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     int flags;
5544c1b
@@ -346,12 +341,12 @@ uint32_t helper_fcmp_eq(uint32_t a, uint32_t b)
5544c1b
     fb.l = b;
5544c1b
     r = float32_eq_quiet(fa.f, fb.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags & float_flag_invalid);
5544c1b
+    update_fpu_flags(env, flags & float_flag_invalid);
5544c1b
 
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_le(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_le(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     int flags;
5544c1b
@@ -362,13 +357,13 @@ uint32_t helper_fcmp_le(uint32_t a, uint32_t b)
5544c1b
     set_float_exception_flags(0, &env->fp_status);
5544c1b
     r = float32_le(fa.f, fb.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags & float_flag_invalid);
5544c1b
+    update_fpu_flags(env, flags & float_flag_invalid);
5544c1b
 
5544c1b
 
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_gt(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_gt(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     int flags, r;
5544c1b
@@ -378,11 +373,11 @@ uint32_t helper_fcmp_gt(uint32_t a, uint32_t b)
5544c1b
     set_float_exception_flags(0, &env->fp_status);
5544c1b
     r = float32_lt(fa.f, fb.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags & float_flag_invalid);
5544c1b
+    update_fpu_flags(env, flags & float_flag_invalid);
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_ne(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_ne(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     int flags, r;
5544c1b
@@ -392,12 +387,12 @@ uint32_t helper_fcmp_ne(uint32_t a, uint32_t b)
5544c1b
     set_float_exception_flags(0, &env->fp_status);
5544c1b
     r = !float32_eq_quiet(fa.f, fb.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags & float_flag_invalid);
5544c1b
+    update_fpu_flags(env, flags & float_flag_invalid);
5544c1b
 
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fcmp_ge(uint32_t a, uint32_t b)
5544c1b
+uint32_t helper_fcmp_ge(CPUMBState *env, uint32_t a, uint32_t b)
5544c1b
 {
5544c1b
     CPU_FloatU fa, fb;
5544c1b
     int flags, r;
5544c1b
@@ -407,12 +402,12 @@ uint32_t helper_fcmp_ge(uint32_t a, uint32_t b)
5544c1b
     set_float_exception_flags(0, &env->fp_status);
5544c1b
     r = !float32_lt(fa.f, fb.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags & float_flag_invalid);
5544c1b
+    update_fpu_flags(env, flags & float_flag_invalid);
5544c1b
 
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_flt(uint32_t a)
5544c1b
+uint32_t helper_flt(CPUMBState *env, uint32_t a)
5544c1b
 {
5544c1b
     CPU_FloatU fd, fa;
5544c1b
 
5544c1b
@@ -421,7 +416,7 @@ uint32_t helper_flt(uint32_t a)
5544c1b
     return fd.l;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fint(uint32_t a)
5544c1b
+uint32_t helper_fint(CPUMBState *env, uint32_t a)
5544c1b
 {
5544c1b
     CPU_FloatU fa;
5544c1b
     uint32_t r;
5544c1b
@@ -431,12 +426,12 @@ uint32_t helper_fint(uint32_t a)
5544c1b
     fa.l = a;
5544c1b
     r = float32_to_int32(fa.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags);
5544c1b
+    update_fpu_flags(env, flags);
5544c1b
 
5544c1b
     return r;
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_fsqrt(uint32_t a)
5544c1b
+uint32_t helper_fsqrt(CPUMBState *env, uint32_t a)
5544c1b
 {
5544c1b
     CPU_FloatU fd, fa;
5544c1b
     int flags;
5544c1b
@@ -445,7 +440,7 @@ uint32_t helper_fsqrt(uint32_t a)
5544c1b
     fa.l = a;
5544c1b
     fd.l = float32_sqrt(fa.f, &env->fp_status);
5544c1b
     flags = get_float_exception_flags(&env->fp_status);
5544c1b
-    update_fpu_flags(flags);
5544c1b
+    update_fpu_flags(env, flags);
5544c1b
 
5544c1b
     return fd.l;
5544c1b
 }
5544c1b
@@ -463,7 +458,8 @@ uint32_t helper_pcmpbf(uint32_t a, uint32_t b)
5544c1b
     return 0;
5544c1b
 }
5544c1b
 
5544c1b
-void helper_memalign(uint32_t addr, uint32_t dr, uint32_t wr, uint32_t mask)
5544c1b
+void helper_memalign(CPUMBState *env, uint32_t addr, uint32_t dr, uint32_t wr,
5544c1b
+                     uint32_t mask)
5544c1b
 {
5544c1b
     if (addr & mask) {
5544c1b
             qemu_log_mask(CPU_LOG_INT,
5544c1b
@@ -478,45 +474,39 @@ void helper_memalign(uint32_t addr, uint32_t dr, uint32_t wr, uint32_t mask)
5544c1b
             if (!(env->sregs[SR_MSR] & MSR_EE)) {
5544c1b
                 return;
5544c1b
             }
5544c1b
-            helper_raise_exception(EXCP_HW_EXCP);
5544c1b
+            helper_raise_exception(env, EXCP_HW_EXCP);
5544c1b
     }
5544c1b
 }
5544c1b
 
5544c1b
-void helper_stackprot(uint32_t addr)
5544c1b
+void helper_stackprot(CPUMBState *env, uint32_t addr)
5544c1b
 {
5544c1b
     if (addr < env->slr || addr > env->shr) {
5544c1b
             qemu_log("Stack protector violation at %x %x %x\n",
5544c1b
                      addr, env->slr, env->shr);
5544c1b
             env->sregs[SR_EAR] = addr;
5544c1b
             env->sregs[SR_ESR] = ESR_EC_STACKPROT;
5544c1b
-            helper_raise_exception(EXCP_HW_EXCP);
5544c1b
+            helper_raise_exception(env, EXCP_HW_EXCP);
5544c1b
     }
5544c1b
 }
5544c1b
 
5544c1b
 #if !defined(CONFIG_USER_ONLY)
5544c1b
 /* Writes/reads to the MMU's special regs end up here.  */
5544c1b
-uint32_t helper_mmu_read(uint32_t rn)
5544c1b
+uint32_t helper_mmu_read(CPUMBState *env, uint32_t rn)
5544c1b
 {
5544c1b
     return mmu_read(env, rn);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_mmu_write(uint32_t rn, uint32_t v)
5544c1b
+void helper_mmu_write(CPUMBState *env, uint32_t rn, uint32_t v)
5544c1b
 {
5544c1b
     mmu_write(env, rn, v);
5544c1b
 }
5544c1b
 
5544c1b
-void cpu_unassigned_access(CPUMBState *env1, target_phys_addr_t addr,
5544c1b
+void cpu_unassigned_access(CPUMBState *env, target_phys_addr_t addr,
5544c1b
                            int is_write, int is_exec, int is_asi, int size)
5544c1b
 {
5544c1b
-    CPUMBState *saved_env;
5544c1b
-
5544c1b
-    saved_env = env;
5544c1b
-    env = env1;
5544c1b
-
5544c1b
     qemu_log_mask(CPU_LOG_INT, "Unassigned " TARGET_FMT_plx " wr=%d exe=%d\n",
5544c1b
              addr, is_write, is_exec);
5544c1b
     if (!(env->sregs[SR_MSR] & MSR_EE)) {
5544c1b
-        env = saved_env;
5544c1b
         return;
5544c1b
     }
5544c1b
 
5544c1b
@@ -524,14 +514,13 @@ void cpu_unassigned_access(CPUMBState *env1, target_phys_addr_t addr,
5544c1b
     if (is_exec) {
5544c1b
         if ((env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) {
5544c1b
             env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
5544c1b
-            helper_raise_exception(EXCP_HW_EXCP);
5544c1b
+            helper_raise_exception(env, EXCP_HW_EXCP);
5544c1b
         }
5544c1b
     } else {
5544c1b
         if ((env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) {
5544c1b
             env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
5544c1b
-            helper_raise_exception(EXCP_HW_EXCP);
5544c1b
+            helper_raise_exception(env, EXCP_HW_EXCP);
5544c1b
         }
5544c1b
     }
5544c1b
-    env = saved_env;
5544c1b
 }
5544c1b
 #endif
5544c1b
diff --git a/target-microblaze/translate.c b/target-microblaze/translate.c
5544c1b
index 7470149..9c7d77f 100644
5544c1b
--- a/target-microblaze/translate.c
5544c1b
+++ b/target-microblaze/translate.c
5544c1b
@@ -126,7 +126,7 @@ static inline void t_gen_raise_exception(DisasContext *dc, uint32_t index)
5544c1b
 
5544c1b
     t_sync_flags(dc);
5544c1b
     tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc);
5544c1b
-    gen_helper_raise_exception(tmp);
5544c1b
+    gen_helper_raise_exception(cpu_env, tmp);
5544c1b
     tcg_temp_free_i32(tmp);
5544c1b
     dc->is_jmp = DISAS_UPDATE;
5544c1b
 }
5544c1b
@@ -503,9 +503,9 @@ static void dec_msr(DisasContext *dc)
5544c1b
         sr &= 7;
5544c1b
         LOG_DIS("m%ss sr%d r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm);
5544c1b
         if (to)
5544c1b
-            gen_helper_mmu_write(tcg_const_tl(sr), cpu_R[dc->ra]);
5544c1b
+            gen_helper_mmu_write(cpu_env, tcg_const_tl(sr), cpu_R[dc->ra]);
5544c1b
         else
5544c1b
-            gen_helper_mmu_read(cpu_R[dc->rd], tcg_const_tl(sr));
5544c1b
+            gen_helper_mmu_read(cpu_R[dc->rd], cpu_env, tcg_const_tl(sr));
5544c1b
         return;
5544c1b
     }
5544c1b
 #endif
5544c1b
@@ -704,9 +704,11 @@ static void dec_div(DisasContext *dc)
5544c1b
     }
5544c1b
 
5544c1b
     if (u)
5544c1b
-        gen_helper_divu(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]);
5544c1b
+        gen_helper_divu(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)),
5544c1b
+                        cpu_R[dc->ra]);
5544c1b
     else
5544c1b
-        gen_helper_divs(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]);
5544c1b
+        gen_helper_divs(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)),
5544c1b
+                        cpu_R[dc->ra]);
5544c1b
     if (!dc->rd)
5544c1b
         tcg_gen_movi_tl(cpu_R[dc->rd], 0);
5544c1b
 }
5544c1b
@@ -912,7 +914,7 @@ static inline TCGv *compute_ldst_addr(DisasContext *dc, TCGv *t)
5544c1b
         tcg_gen_add_tl(*t, cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
 
5544c1b
         if (stackprot) {
5544c1b
-            gen_helper_stackprot(*t);
5544c1b
+            gen_helper_stackprot(cpu_env, *t);
5544c1b
         }
5544c1b
         return t;
5544c1b
     }
5544c1b
@@ -930,7 +932,7 @@ static inline TCGv *compute_ldst_addr(DisasContext *dc, TCGv *t)
5544c1b
     }
5544c1b
 
5544c1b
     if (stackprot) {
5544c1b
-        gen_helper_stackprot(*t);
5544c1b
+        gen_helper_stackprot(cpu_env, *t);
5544c1b
     }
5544c1b
     return t;
5544c1b
 }
5544c1b
@@ -1056,7 +1058,7 @@ static void dec_load(DisasContext *dc)
5544c1b
         gen_load(dc, v, *addr, size);
5544c1b
 
5544c1b
         tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc);
5544c1b
-        gen_helper_memalign(*addr, tcg_const_tl(dc->rd),
5544c1b
+        gen_helper_memalign(cpu_env, *addr, tcg_const_tl(dc->rd),
5544c1b
                             tcg_const_tl(0), tcg_const_tl(size - 1));
5544c1b
         if (dc->rd) {
5544c1b
             if (rev) {
5544c1b
@@ -1218,7 +1220,7 @@ static void dec_store(DisasContext *dc)
5544c1b
          *        the alignment checks in between the probe and the mem
5544c1b
          *        access.
5544c1b
          */
5544c1b
-        gen_helper_memalign(*addr, tcg_const_tl(dc->rd),
5544c1b
+        gen_helper_memalign(cpu_env, *addr, tcg_const_tl(dc->rd),
5544c1b
                             tcg_const_tl(1), tcg_const_tl(size - 1));
5544c1b
     }
5544c1b
 
5544c1b
@@ -1493,49 +1495,53 @@ static void dec_fpu(DisasContext *dc)
5544c1b
 
5544c1b
     switch (fpu_insn) {
5544c1b
         case 0:
5544c1b
-            gen_helper_fadd(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
+            gen_helper_fadd(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
5544c1b
+                            cpu_R[dc->rb]);
5544c1b
             break;
5544c1b
 
5544c1b
         case 1:
5544c1b
-            gen_helper_frsub(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
+            gen_helper_frsub(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
5544c1b
+                             cpu_R[dc->rb]);
5544c1b
             break;
5544c1b
 
5544c1b
         case 2:
5544c1b
-            gen_helper_fmul(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
+            gen_helper_fmul(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
5544c1b
+                            cpu_R[dc->rb]);
5544c1b
             break;
5544c1b
 
5544c1b
         case 3:
5544c1b
-            gen_helper_fdiv(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
+            gen_helper_fdiv(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
5544c1b
+                            cpu_R[dc->rb]);
5544c1b
             break;
5544c1b
 
5544c1b
         case 4:
5544c1b
             switch ((dc->ir >> 4) & 7) {
5544c1b
                 case 0:
5544c1b
-                    gen_helper_fcmp_un(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_un(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 case 1:
5544c1b
-                    gen_helper_fcmp_lt(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_lt(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 case 2:
5544c1b
-                    gen_helper_fcmp_eq(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_eq(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 case 3:
5544c1b
-                    gen_helper_fcmp_le(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_le(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 case 4:
5544c1b
-                    gen_helper_fcmp_gt(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_gt(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 case 5:
5544c1b
-                    gen_helper_fcmp_ne(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_ne(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 case 6:
5544c1b
-                    gen_helper_fcmp_ge(cpu_R[dc->rd],
5544c1b
+                    gen_helper_fcmp_ge(cpu_R[dc->rd], cpu_env,
5544c1b
                                        cpu_R[dc->ra], cpu_R[dc->rb]);
5544c1b
                     break;
5544c1b
                 default:
5544c1b
@@ -1552,21 +1558,21 @@ static void dec_fpu(DisasContext *dc)
5544c1b
             if (!dec_check_fpuv2(dc)) {
5544c1b
                 return;
5544c1b
             }
5544c1b
-            gen_helper_flt(cpu_R[dc->rd], cpu_R[dc->ra]);
5544c1b
+            gen_helper_flt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]);
5544c1b
             break;
5544c1b
 
5544c1b
         case 6:
5544c1b
             if (!dec_check_fpuv2(dc)) {
5544c1b
                 return;
5544c1b
             }
5544c1b
-            gen_helper_fint(cpu_R[dc->rd], cpu_R[dc->ra]);
5544c1b
+            gen_helper_fint(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]);
5544c1b
             break;
5544c1b
 
5544c1b
         case 7:
5544c1b
             if (!dec_check_fpuv2(dc)) {
5544c1b
                 return;
5544c1b
             }
5544c1b
-            gen_helper_fsqrt(cpu_R[dc->rd], cpu_R[dc->ra]);
5544c1b
+            gen_helper_fsqrt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]);
5544c1b
             break;
5544c1b
 
5544c1b
         default:
5544c1b
@@ -1654,15 +1660,14 @@ static struct decoder_info {
5544c1b
     {{0, 0}, dec_null}
5544c1b
 };
5544c1b
 
5544c1b
-static inline void decode(DisasContext *dc)
5544c1b
+static inline void decode(DisasContext *dc, uint32_t ir)
5544c1b
 {
5544c1b
-    uint32_t ir;
5544c1b
     int i;
5544c1b
 
5544c1b
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
5544c1b
         tcg_gen_debug_insn_start(dc->pc);
5544c1b
 
5544c1b
-    dc->ir = ir = ldl_code(dc->pc);
5544c1b
+    dc->ir = ir;
5544c1b
     LOG_DIS("%8.8x\t", dc->ir);
5544c1b
 
5544c1b
     if (dc->ir)
5544c1b
@@ -1796,7 +1801,7 @@ gen_intermediate_code_internal(CPUMBState *env, TranslationBlock *tb,
5544c1b
             gen_io_start();
5544c1b
 
5544c1b
         dc->clear_imm = 1;
5544c1b
-	decode(dc);
5544c1b
+        decode(dc, cpu_ldl_code(env, dc->pc));
5544c1b
         if (dc->clear_imm)
5544c1b
             dc->tb_flags &= ~IMM_FLAG;
5544c1b
         dc->pc += 4;
5544c1b
@@ -1871,7 +1876,7 @@ gen_intermediate_code_internal(CPUMBState *env, TranslationBlock *tb,
5544c1b
         if (dc->is_jmp != DISAS_JUMP) {
5544c1b
             tcg_gen_movi_tl(cpu_SR[SR_PC], npc);
5544c1b
         }
5544c1b
-        gen_helper_raise_exception(tmp);
5544c1b
+        gen_helper_raise_exception(cpu_env, tmp);
5544c1b
         tcg_temp_free_i32(tmp);
5544c1b
     } else {
5544c1b
         switch(dc->is_jmp) {