Blame 0030-target-unicore32-switch-to-AREG0-free-mode.patch

5544c1
From 23ff6fa6a883d210aab33e09d0bb9470df5083fc Mon Sep 17 00:00:00 2001
5544c1
From: Blue Swirl <blauwirbel@gmail.com>
5544c1
Date: Sun, 2 Sep 2012 07:42:33 +0000
5544c1
Subject: [PATCH] target-unicore32: switch to AREG0 free mode
5544c1
5544c1
Add an explicit CPUState parameter instead of relying on AREG0
5544c1
and switch to AREG0 free mode.
5544c1
5544c1
Tested-by: Guan Xuetao <gxt@mprc.pku.edu.cn>
5544c1
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 configure                      |  2 +-
5544c1
 target-unicore32/Makefile.objs |  2 --
5544c1
 target-unicore32/helper.h      | 26 ++++++++---------
5544c1
 target-unicore32/op_helper.c   | 65 ++++++++++++++++--------------------------
5544c1
 target-unicore32/translate.c   | 38 ++++++++++++------------
5544c1
 5 files changed, 58 insertions(+), 75 deletions(-)
5544c1
5544c1
diff --git a/configure b/configure
5544c1
index af03942..a8827ba 100755
5544c1
--- a/configure
5544c1
+++ b/configure
5544c1
@@ -3839,7 +3839,7 @@ symlink "$source_path/Makefile.target" "$target_dir/Makefile"
5544c1
 
5544c1
 
5544c1
 case "$target_arch2" in
5544c1
-  alpha | i386 | lm32 | m68k | or32 | s390x | sparc* | x86_64 | xtensa* | ppc*)
5544c1
+  alpha | i386 | lm32 | m68k | or32 | s390x | sparc* | unicore32 | x86_64 | xtensa* | ppc*)
5544c1
     echo "CONFIG_TCG_PASS_AREG0=y" >> $config_target_mak
5544c1
   ;;
5544c1
 esac
5544c1
diff --git a/target-unicore32/Makefile.objs b/target-unicore32/Makefile.objs
5544c1
index 777f01f..8e143da 100644
5544c1
--- a/target-unicore32/Makefile.objs
5544c1
+++ b/target-unicore32/Makefile.objs
5544c1
@@ -2,5 +2,3 @@ obj-y += translate.o op_helper.o helper.o cpu.o
5544c1
 obj-y += ucf64_helper.o
5544c1
 
5544c1
 obj-$(CONFIG_SOFTMMU) += machine.o softmmu.o
5544c1
-
5544c1
-$(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1
diff --git a/target-unicore32/helper.h b/target-unicore32/helper.h
5544c1
index 305318a..a4b8149 100644
5544c1
--- a/target-unicore32/helper.h
5544c1
+++ b/target-unicore32/helper.h
5544c1
@@ -17,26 +17,26 @@ DEF_HELPER_1(cp1_putc, void, i32)
5544c1
 DEF_HELPER_1(clz, i32, i32)
5544c1
 DEF_HELPER_1(clo, i32, i32)
5544c1
 
5544c1
-DEF_HELPER_1(exception, void, i32)
5544c1
+DEF_HELPER_2(exception, void, env, i32)
5544c1
 
5544c1
-DEF_HELPER_2(asr_write, void, i32, i32)
5544c1
-DEF_HELPER_0(asr_read, i32)
5544c1
+DEF_HELPER_3(asr_write, void, env, i32, i32)
5544c1
+DEF_HELPER_1(asr_read, i32, env)
5544c1
 
5544c1
-DEF_HELPER_1(get_user_reg, i32, i32)
5544c1
-DEF_HELPER_2(set_user_reg, void, i32, i32)
5544c1
+DEF_HELPER_2(get_user_reg, i32, env, i32)
5544c1
+DEF_HELPER_3(set_user_reg, void, env, i32, i32)
5544c1
 
5544c1
-DEF_HELPER_2(add_cc, i32, i32, i32)
5544c1
-DEF_HELPER_2(adc_cc, i32, i32, i32)
5544c1
-DEF_HELPER_2(sub_cc, i32, i32, i32)
5544c1
-DEF_HELPER_2(sbc_cc, i32, i32, i32)
5544c1
+DEF_HELPER_3(add_cc, i32, env, i32, i32)
5544c1
+DEF_HELPER_3(adc_cc, i32, env, i32, i32)
5544c1
+DEF_HELPER_3(sub_cc, i32, env, i32, i32)
5544c1
+DEF_HELPER_3(sbc_cc, i32, env, i32, i32)
5544c1
 
5544c1
 DEF_HELPER_2(shl, i32, i32, i32)
5544c1
 DEF_HELPER_2(shr, i32, i32, i32)
5544c1
 DEF_HELPER_2(sar, i32, i32, i32)
5544c1
-DEF_HELPER_2(shl_cc, i32, i32, i32)
5544c1
-DEF_HELPER_2(shr_cc, i32, i32, i32)
5544c1
-DEF_HELPER_2(sar_cc, i32, i32, i32)
5544c1
-DEF_HELPER_2(ror_cc, i32, i32, i32)
5544c1
+DEF_HELPER_3(shl_cc, i32, env, i32, i32)
5544c1
+DEF_HELPER_3(shr_cc, i32, env, i32, i32)
5544c1
+DEF_HELPER_3(sar_cc, i32, env, i32, i32)
5544c1
+DEF_HELPER_3(ror_cc, i32, env, i32, i32)
5544c1
 
5544c1
 DEF_HELPER_1(ucf64_get_fpscr, i32, env)
5544c1
 DEF_HELPER_2(ucf64_set_fpscr, void, env, i32)
5544c1
diff --git a/target-unicore32/op_helper.c b/target-unicore32/op_helper.c
5544c1
index c63789d..f474d1b 100644
5544c1
--- a/target-unicore32/op_helper.c
5544c1
+++ b/target-unicore32/op_helper.c
5544c1
@@ -9,19 +9,18 @@
5544c1
  * later version. See the COPYING file in the top-level directory.
5544c1
  */
5544c1
 #include "cpu.h"
5544c1
-#include "dyngen-exec.h"
5544c1
 #include "helper.h"
5544c1
 
5544c1
 #define SIGNBIT (uint32_t)0x80000000
5544c1
 #define SIGNBIT64 ((uint64_t)1 << 63)
5544c1
 
5544c1
-void HELPER(exception)(uint32_t excp)
5544c1
+void HELPER(exception)(CPUUniCore32State *env, uint32_t excp)
5544c1
 {
5544c1
     env->exception_index = excp;
5544c1
     cpu_loop_exit(env);
5544c1
 }
5544c1
 
5544c1
-static target_ulong asr_read(void)
5544c1
+static target_ulong asr_read(CPUUniCore32State *env)
5544c1
 {
5544c1
     int ZF;
5544c1
     ZF = (env->ZF == 0);
5544c1
@@ -29,24 +28,18 @@ static target_ulong asr_read(void)
5544c1
         (env->CF << 29) | ((env->VF & 0x80000000) >> 3);
5544c1
 }
5544c1
 
5544c1
-target_ulong cpu_asr_read(CPUUniCore32State *env1)
5544c1
+target_ulong cpu_asr_read(CPUUniCore32State *env)
5544c1
 {
5544c1
-    CPUUniCore32State *saved_env;
5544c1
-    target_ulong ret;
5544c1
-
5544c1
-    saved_env = env;
5544c1
-    env = env1;
5544c1
-    ret = asr_read();
5544c1
-    env = saved_env;
5544c1
-    return ret;
5544c1
+    return asr_read(env);
5544c1
 }
5544c1
 
5544c1
-target_ulong HELPER(asr_read)(void)
5544c1
+target_ulong HELPER(asr_read)(CPUUniCore32State *env)
5544c1
 {
5544c1
-    return asr_read();
5544c1
+    return asr_read(env);
5544c1
 }
5544c1
 
5544c1
-static void asr_write(target_ulong val, target_ulong mask)
5544c1
+static void asr_write(CPUUniCore32State *env, target_ulong val,
5544c1
+                      target_ulong mask)
5544c1
 {
5544c1
     if (mask & ASR_NZCV) {
5544c1
         env->ZF = (~val) & ASR_Z;
5544c1
@@ -62,23 +55,19 @@ static void asr_write(target_ulong val, target_ulong mask)
5544c1
     env->uncached_asr = (env->uncached_asr & ~mask) | (val & mask);
5544c1
 }
5544c1
 
5544c1
-void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)
5544c1
+void cpu_asr_write(CPUUniCore32State *env, target_ulong val, target_ulong mask)
5544c1
 {
5544c1
-    CPUUniCore32State *saved_env;
5544c1
-
5544c1
-    saved_env = env;
5544c1
-    env = env1;
5544c1
-    asr_write(val, mask);
5544c1
-    env = saved_env;
5544c1
+    asr_write(env, val, mask);
5544c1
 }
5544c1
 
5544c1
-void HELPER(asr_write)(target_ulong val, target_ulong mask)
5544c1
+void HELPER(asr_write)(CPUUniCore32State *env, target_ulong val,
5544c1
+                       target_ulong mask)
5544c1
 {
5544c1
-    asr_write(val, mask);
5544c1
+    asr_write(env, val, mask);
5544c1
 }
5544c1
 
5544c1
 /* Access to user mode registers from privileged modes.  */
5544c1
-uint32_t HELPER(get_user_reg)(uint32_t regno)
5544c1
+uint32_t HELPER(get_user_reg)(CPUUniCore32State *env, uint32_t regno)
5544c1
 {
5544c1
     uint32_t val;
5544c1
 
5544c1
@@ -92,7 +81,7 @@ uint32_t HELPER(get_user_reg)(uint32_t regno)
5544c1
     return val;
5544c1
 }
5544c1
 
5544c1
-void HELPER(set_user_reg)(uint32_t regno, uint32_t val)
5544c1
+void HELPER(set_user_reg)(CPUUniCore32State *env, uint32_t regno, uint32_t val)
5544c1
 {
5544c1
     if (regno == 29) {
5544c1
         env->banked_r29[0] = val;
5544c1
@@ -107,7 +96,7 @@ void HELPER(set_user_reg)(uint32_t regno, uint32_t val)
5544c1
    The only way to do that in TCG is a conditional branch, which clobbers
5544c1
    all our temporaries.  For now implement these as helper functions.  */
5544c1
 
5544c1
-uint32_t HELPER(add_cc)(uint32_t a, uint32_t b)
5544c1
+uint32_t HELPER(add_cc)(CPUUniCore32State *env, uint32_t a, uint32_t b)
5544c1
 {
5544c1
     uint32_t result;
5544c1
     result = a + b;
5544c1
@@ -117,7 +106,7 @@ uint32_t HELPER(add_cc)(uint32_t a, uint32_t b)
5544c1
     return result;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(adc_cc)(uint32_t a, uint32_t b)
5544c1
+uint32_t HELPER(adc_cc)(CPUUniCore32State *env, uint32_t a, uint32_t b)
5544c1
 {
5544c1
     uint32_t result;
5544c1
     if (!env->CF) {
5544c1
@@ -132,7 +121,7 @@ uint32_t HELPER(adc_cc)(uint32_t a, uint32_t b)
5544c1
     return result;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(sub_cc)(uint32_t a, uint32_t b)
5544c1
+uint32_t HELPER(sub_cc)(CPUUniCore32State *env, uint32_t a, uint32_t b)
5544c1
 {
5544c1
     uint32_t result;
5544c1
     result = a - b;
5544c1
@@ -142,7 +131,7 @@ uint32_t HELPER(sub_cc)(uint32_t a, uint32_t b)
5544c1
     return result;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(sbc_cc)(uint32_t a, uint32_t b)
5544c1
+uint32_t HELPER(sbc_cc)(CPUUniCore32State *env, uint32_t a, uint32_t b)
5544c1
 {
5544c1
     uint32_t result;
5544c1
     if (!env->CF) {
5544c1
@@ -186,7 +175,7 @@ uint32_t HELPER(sar)(uint32_t x, uint32_t i)
5544c1
     return (int32_t)x >> shift;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(shl_cc)(uint32_t x, uint32_t i)
5544c1
+uint32_t HELPER(shl_cc)(CPUUniCore32State *env, uint32_t x, uint32_t i)
5544c1
 {
5544c1
     int shift = i & 0xff;
5544c1
     if (shift >= 32) {
5544c1
@@ -203,7 +192,7 @@ uint32_t HELPER(shl_cc)(uint32_t x, uint32_t i)
5544c1
     return x;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(shr_cc)(uint32_t x, uint32_t i)
5544c1
+uint32_t HELPER(shr_cc)(CPUUniCore32State *env, uint32_t x, uint32_t i)
5544c1
 {
5544c1
     int shift = i & 0xff;
5544c1
     if (shift >= 32) {
5544c1
@@ -220,7 +209,7 @@ uint32_t HELPER(shr_cc)(uint32_t x, uint32_t i)
5544c1
     return x;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(sar_cc)(uint32_t x, uint32_t i)
5544c1
+uint32_t HELPER(sar_cc)(CPUUniCore32State *env, uint32_t x, uint32_t i)
5544c1
 {
5544c1
     int shift = i & 0xff;
5544c1
     if (shift >= 32) {
5544c1
@@ -233,7 +222,7 @@ uint32_t HELPER(sar_cc)(uint32_t x, uint32_t i)
5544c1
     return x;
5544c1
 }
5544c1
 
5544c1
-uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)
5544c1
+uint32_t HELPER(ror_cc)(CPUUniCore32State *env, uint32_t x, uint32_t i)
5544c1
 {
5544c1
     int shift1, shift;
5544c1
     shift1 = i & 0xff;
5544c1
@@ -264,16 +253,13 @@ uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)
5544c1
 #define SHIFT 3
5544c1
 #include "softmmu_template.h"
5544c1
 
5544c1
-void tlb_fill(CPUUniCore32State *env1, target_ulong addr, int is_write,
5544c1
-        int mmu_idx, uintptr_t retaddr)
5544c1
+void tlb_fill(CPUUniCore32State *env, target_ulong addr, int is_write,
5544c1
+              int mmu_idx, uintptr_t retaddr)
5544c1
 {
5544c1
     TranslationBlock *tb;
5544c1
-    CPUUniCore32State *saved_env;
5544c1
     unsigned long pc;
5544c1
     int ret;
5544c1
 
5544c1
-    saved_env = env;
5544c1
-    env = env1;
5544c1
     ret = uc32_cpu_handle_mmu_fault(env, addr, is_write, mmu_idx);
5544c1
     if (unlikely(ret)) {
5544c1
         if (retaddr) {
5544c1
@@ -287,6 +273,5 @@ void tlb_fill(CPUUniCore32State *env1, target_ulong addr, int is_write,
5544c1
         }
5544c1
         cpu_loop_exit(env);
5544c1
     }
5544c1
-    env = saved_env;
5544c1
 }
5544c1
 #endif
5544c1
diff --git a/target-unicore32/translate.c b/target-unicore32/translate.c
5544c1
index 188bf8c..b786a6b 100644
5544c1
--- a/target-unicore32/translate.c
5544c1
+++ b/target-unicore32/translate.c
5544c1
@@ -253,7 +253,7 @@ static void disas_ocd_insn(CPUUniCore32State *env, DisasContext *s,
5544c1
 static inline void gen_set_asr(TCGv var, uint32_t mask)
5544c1
 {
5544c1
     TCGv tmp_mask = tcg_const_i32(mask);
5544c1
-    gen_helper_asr_write(var, tmp_mask);
5544c1
+    gen_helper_asr_write(cpu_env, var, tmp_mask);
5544c1
     tcg_temp_free_i32(tmp_mask);
5544c1
 }
5544c1
 /* Set NZCV flags from the high 4 bits of var.  */
5544c1
@@ -263,7 +263,7 @@ static void gen_exception(int excp)
5544c1
 {
5544c1
     TCGv tmp = new_tmp();
5544c1
     tcg_gen_movi_i32(tmp, excp);
5544c1
-    gen_helper_exception(tmp);
5544c1
+    gen_helper_exception(cpu_env, tmp);
5544c1
     dead_tmp(tmp);
5544c1
 }
5544c1
 
5544c1
@@ -416,16 +416,16 @@ static inline void gen_uc32_shift_reg(TCGv var, int shiftop,
5544c1
     if (flags) {
5544c1
         switch (shiftop) {
5544c1
         case 0:
5544c1
-            gen_helper_shl_cc(var, var, shift);
5544c1
+            gen_helper_shl_cc(var, cpu_env, var, shift);
5544c1
             break;
5544c1
         case 1:
5544c1
-            gen_helper_shr_cc(var, var, shift);
5544c1
+            gen_helper_shr_cc(var, cpu_env, var, shift);
5544c1
             break;
5544c1
         case 2:
5544c1
-            gen_helper_sar_cc(var, var, shift);
5544c1
+            gen_helper_sar_cc(var, cpu_env, var, shift);
5544c1
             break;
5544c1
         case 3:
5544c1
-            gen_helper_ror_cc(var, var, shift);
5544c1
+            gen_helper_ror_cc(var, cpu_env, var, shift);
5544c1
             break;
5544c1
         }
5544c1
     } else {
5544c1
@@ -1323,11 +1323,11 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
             if (IS_USER(s)) {
5544c1
                 ILLEGAL;
5544c1
             }
5544c1
-            gen_helper_sub_cc(tmp, tmp, tmp2);
5544c1
+            gen_helper_sub_cc(tmp, cpu_env, tmp, tmp2);
5544c1
             gen_exception_return(s, tmp);
5544c1
         } else {
5544c1
             if (UCOP_SET_S) {
5544c1
-                gen_helper_sub_cc(tmp, tmp, tmp2);
5544c1
+                gen_helper_sub_cc(tmp, cpu_env, tmp, tmp2);
5544c1
             } else {
5544c1
                 tcg_gen_sub_i32(tmp, tmp, tmp2);
5544c1
             }
5544c1
@@ -1336,7 +1336,7 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
         break;
5544c1
     case 0x03:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_sub_cc(tmp, tmp2, tmp);
5544c1
+            gen_helper_sub_cc(tmp, cpu_env, tmp2, tmp);
5544c1
         } else {
5544c1
             tcg_gen_sub_i32(tmp, tmp2, tmp);
5544c1
         }
5544c1
@@ -1344,7 +1344,7 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
         break;
5544c1
     case 0x04:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_add_cc(tmp, tmp, tmp2);
5544c1
+            gen_helper_add_cc(tmp, cpu_env, tmp, tmp2);
5544c1
         } else {
5544c1
             tcg_gen_add_i32(tmp, tmp, tmp2);
5544c1
         }
5544c1
@@ -1352,7 +1352,7 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
         break;
5544c1
     case 0x05:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_adc_cc(tmp, tmp, tmp2);
5544c1
+            gen_helper_adc_cc(tmp, cpu_env, tmp, tmp2);
5544c1
         } else {
5544c1
             gen_add_carry(tmp, tmp, tmp2);
5544c1
         }
5544c1
@@ -1360,7 +1360,7 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
         break;
5544c1
     case 0x06:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_sbc_cc(tmp, tmp, tmp2);
5544c1
+            gen_helper_sbc_cc(tmp, cpu_env, tmp, tmp2);
5544c1
         } else {
5544c1
             gen_sub_carry(tmp, tmp, tmp2);
5544c1
         }
5544c1
@@ -1368,7 +1368,7 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
         break;
5544c1
     case 0x07:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_sbc_cc(tmp, tmp2, tmp);
5544c1
+            gen_helper_sbc_cc(tmp, cpu_env, tmp2, tmp);
5544c1
         } else {
5544c1
             gen_sub_carry(tmp, tmp2, tmp);
5544c1
         }
5544c1
@@ -1390,13 +1390,13 @@ static void do_datap(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
         break;
5544c1
     case 0x0a:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_sub_cc(tmp, tmp, tmp2);
5544c1
+            gen_helper_sub_cc(tmp, cpu_env, tmp, tmp2);
5544c1
         }
5544c1
         dead_tmp(tmp);
5544c1
         break;
5544c1
     case 0x0b:
5544c1
         if (UCOP_SET_S) {
5544c1
-            gen_helper_add_cc(tmp, tmp, tmp2);
5544c1
+            gen_helper_add_cc(tmp, cpu_env, tmp, tmp2);
5544c1
         }
5544c1
         dead_tmp(tmp);
5544c1
         break;
5544c1
@@ -1536,7 +1536,7 @@ static void do_misc(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
             tmp = load_cpu_field(bsr);
5544c1
         } else {
5544c1
             tmp = new_tmp();
5544c1
-            gen_helper_asr_read(tmp);
5544c1
+            gen_helper_asr_read(tmp, cpu_env);
5544c1
         }
5544c1
         store_reg(s, UCOP_REG_D, tmp);
5544c1
         return;
5544c1
@@ -1760,7 +1760,7 @@ static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
                     gen_bx(s, tmp);
5544c1
                 } else if (user) {
5544c1
                     tmp2 = tcg_const_i32(reg);
5544c1
-                    gen_helper_set_user_reg(tmp2, tmp);
5544c1
+                    gen_helper_set_user_reg(cpu_env, tmp2, tmp);
5544c1
                     tcg_temp_free_i32(tmp2);
5544c1
                     dead_tmp(tmp);
5544c1
                 } else if (reg == UCOP_REG_N) {
5544c1
@@ -1778,7 +1778,7 @@ static void do_ldst_m(CPUUniCore32State *env, DisasContext *s, uint32_t insn)
5544c1
                 } else if (user) {
5544c1
                     tmp = new_tmp();
5544c1
                     tmp2 = tcg_const_i32(reg);
5544c1
-                    gen_helper_get_user_reg(tmp, tmp2);
5544c1
+                    gen_helper_get_user_reg(tmp, cpu_env, tmp2);
5544c1
                     tcg_temp_free_i32(tmp2);
5544c1
                 } else {
5544c1
                     tmp = load_reg(s, reg);
5544c1
@@ -1861,7 +1861,7 @@ static void disas_uc32_insn(CPUUniCore32State *env, DisasContext *s)
5544c1
 {
5544c1
     unsigned int insn;
5544c1
 
5544c1
-    insn = ldl_code(s->pc);
5544c1
+    insn = cpu_ldl_code(env, s->pc);
5544c1
     s->pc += 4;
5544c1
 
5544c1
     /* UniCore instructions class:
5544c1
-- 
5544c1
1.7.12.1
5544c1