5544c1b
From 25e9a95d0571c40738daa479467d757eb477739e Mon Sep 17 00:00:00 2001
5544c1b
From: Blue Swirl <blauwirbel@gmail.com>
5544c1b
Date: Sun, 2 Sep 2012 06:57:17 +0000
5544c1b
Subject: [PATCH] target-lm32: 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-lm32/Makefile.objs |  2 --
5544c1b
 target-lm32/helper.h      | 20 ++++++++++----------
5544c1b
 target-lm32/op_helper.c   | 29 +++++++++++------------------
5544c1b
 target-lm32/translate.c   | 28 +++++++++++++---------------
5544c1b
 5 files changed, 35 insertions(+), 46 deletions(-)
5544c1b
5544c1b
diff --git a/configure b/configure
5544c1b
index 3ad6f74..1e3ea7f 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 | i386 | or32 | s390x | sparc* | x86_64 | xtensa* | ppc*)
5544c1b
+  alpha | i386 | lm32 | or32 | s390x | sparc* | x86_64 | xtensa* | ppc*)
5544c1b
     echo "CONFIG_TCG_PASS_AREG0=y" >> $config_target_mak
5544c1b
   ;;
5544c1b
 esac
5544c1b
diff --git a/target-lm32/Makefile.objs b/target-lm32/Makefile.objs
5544c1b
index 2e0e093..ca20f21 100644
5544c1b
--- a/target-lm32/Makefile.objs
5544c1b
+++ b/target-lm32/Makefile.objs
5544c1b
@@ -1,4 +1,2 @@
5544c1b
 obj-y += translate.o op_helper.o helper.o cpu.o
5544c1b
 obj-$(CONFIG_SOFTMMU) += machine.o
5544c1b
-
5544c1b
-$(obj)/op_helper.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
5544c1b
diff --git a/target-lm32/helper.h b/target-lm32/helper.h
5544c1b
index 9d335ef..07f5670 100644
5544c1b
--- a/target-lm32/helper.h
5544c1b
+++ b/target-lm32/helper.h
5544c1b
@@ -1,14 +1,14 @@
5544c1b
 #include "def-helper.h"
5544c1b
 
5544c1b
-DEF_HELPER_1(raise_exception, void, i32)
5544c1b
-DEF_HELPER_0(hlt, void)
5544c1b
-DEF_HELPER_1(wcsr_im, void, i32)
5544c1b
-DEF_HELPER_1(wcsr_ip, void, i32)
5544c1b
-DEF_HELPER_1(wcsr_jtx, void, i32)
5544c1b
-DEF_HELPER_1(wcsr_jrx, void, i32)
5544c1b
-DEF_HELPER_0(rcsr_im, i32)
5544c1b
-DEF_HELPER_0(rcsr_ip, i32)
5544c1b
-DEF_HELPER_0(rcsr_jtx, i32)
5544c1b
-DEF_HELPER_0(rcsr_jrx, i32)
5544c1b
+DEF_HELPER_2(raise_exception, void, env, i32)
5544c1b
+DEF_HELPER_1(hlt, void, env)
5544c1b
+DEF_HELPER_2(wcsr_im, void, env, i32)
5544c1b
+DEF_HELPER_2(wcsr_ip, void, env, i32)
5544c1b
+DEF_HELPER_2(wcsr_jtx, void, env, i32)
5544c1b
+DEF_HELPER_2(wcsr_jrx, void, env, i32)
5544c1b
+DEF_HELPER_1(rcsr_im, i32, env)
5544c1b
+DEF_HELPER_1(rcsr_ip, i32, env)
5544c1b
+DEF_HELPER_1(rcsr_jtx, i32, env)
5544c1b
+DEF_HELPER_1(rcsr_jrx, i32, env)
5544c1b
 
5544c1b
 #include "def-helper.h"
5544c1b
diff --git a/target-lm32/op_helper.c b/target-lm32/op_helper.c
5544c1b
index 51edc1a..7b91d8c 100644
5544c1b
--- a/target-lm32/op_helper.c
5544c1b
+++ b/target-lm32/op_helper.c
5544c1b
@@ -1,6 +1,5 @@
5544c1b
 #include <assert.h>
5544c1b
 #include "cpu.h"
5544c1b
-#include "dyngen-exec.h"
5544c1b
 #include "helper.h"
5544c1b
 #include "host-utils.h"
5544c1b
 
5544c1b
@@ -18,55 +17,55 @@
5544c1b
 #define SHIFT 3
5544c1b
 #include "softmmu_template.h"
5544c1b
 
5544c1b
-void helper_raise_exception(uint32_t index)
5544c1b
+void helper_raise_exception(CPULM32State *env, uint32_t index)
5544c1b
 {
5544c1b
     env->exception_index = index;
5544c1b
     cpu_loop_exit(env);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_hlt(void)
5544c1b
+void helper_hlt(CPULM32State *env)
5544c1b
 {
5544c1b
     env->halted = 1;
5544c1b
     env->exception_index = EXCP_HLT;
5544c1b
     cpu_loop_exit(env);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_wcsr_im(uint32_t im)
5544c1b
+void helper_wcsr_im(CPULM32State *env, uint32_t im)
5544c1b
 {
5544c1b
     lm32_pic_set_im(env->pic_state, im);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_wcsr_ip(uint32_t im)
5544c1b
+void helper_wcsr_ip(CPULM32State *env, uint32_t im)
5544c1b
 {
5544c1b
     lm32_pic_set_ip(env->pic_state, im);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_wcsr_jtx(uint32_t jtx)
5544c1b
+void helper_wcsr_jtx(CPULM32State *env, uint32_t jtx)
5544c1b
 {
5544c1b
     lm32_juart_set_jtx(env->juart_state, jtx);
5544c1b
 }
5544c1b
 
5544c1b
-void helper_wcsr_jrx(uint32_t jrx)
5544c1b
+void helper_wcsr_jrx(CPULM32State *env, uint32_t jrx)
5544c1b
 {
5544c1b
     lm32_juart_set_jrx(env->juart_state, jrx);
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_rcsr_im(void)
5544c1b
+uint32_t helper_rcsr_im(CPULM32State *env)
5544c1b
 {
5544c1b
     return lm32_pic_get_im(env->pic_state);
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_rcsr_ip(void)
5544c1b
+uint32_t helper_rcsr_ip(CPULM32State *env)
5544c1b
 {
5544c1b
     return lm32_pic_get_ip(env->pic_state);
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_rcsr_jtx(void)
5544c1b
+uint32_t helper_rcsr_jtx(CPULM32State *env)
5544c1b
 {
5544c1b
     return lm32_juart_get_jtx(env->juart_state);
5544c1b
 }
5544c1b
 
5544c1b
-uint32_t helper_rcsr_jrx(void)
5544c1b
+uint32_t helper_rcsr_jrx(CPULM32State *env)
5544c1b
 {
5544c1b
     return lm32_juart_get_jrx(env->juart_state);
5544c1b
 }
5544c1b
@@ -74,17 +73,12 @@ uint32_t helper_rcsr_jrx(void)
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(CPULM32State *env1, target_ulong addr, int is_write, int mmu_idx,
5544c1b
+void tlb_fill(CPULM32State *env, target_ulong addr, int is_write, int mmu_idx,
5544c1b
               uintptr_t retaddr)
5544c1b
 {
5544c1b
     TranslationBlock *tb;
5544c1b
-    CPULM32State *saved_env;
5544c1b
     int ret;
5544c1b
 
5544c1b
-    saved_env = env;
5544c1b
-    env = env1;
5544c1b
-
5544c1b
     ret = cpu_lm32_handle_mmu_fault(env, addr, is_write, mmu_idx);
5544c1b
     if (unlikely(ret)) {
5544c1b
         if (retaddr) {
5544c1b
@@ -98,7 +92,6 @@ void tlb_fill(CPULM32State *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
diff --git a/target-lm32/translate.c b/target-lm32/translate.c
5544c1b
index 872a2ba..5f6dcba 100644
5544c1b
--- a/target-lm32/translate.c
5544c1b
+++ b/target-lm32/translate.c
5544c1b
@@ -116,7 +116,7 @@ static inline void t_gen_raise_exception(DisasContext *dc, uint32_t index)
5544c1b
 {
5544c1b
     TCGv_i32 tmp = tcg_const_i32(index);
5544c1b
 
5544c1b
-    gen_helper_raise_exception(tmp);
5544c1b
+    gen_helper_raise_exception(cpu_env, tmp);
5544c1b
     tcg_temp_free_i32(tmp);
5544c1b
 }
5544c1b
 
5544c1b
@@ -179,7 +179,7 @@ static void dec_and(DisasContext *dc)
5544c1b
     } else  {
5544c1b
         if (dc->r0 == 0 && dc->r1 == 0 && dc->r2 == 0) {
5544c1b
             tcg_gen_movi_tl(cpu_pc, dc->pc + 4);
5544c1b
-            gen_helper_hlt();
5544c1b
+            gen_helper_hlt(cpu_env);
5544c1b
         } else {
5544c1b
             tcg_gen_and_tl(cpu_R[dc->r2], cpu_R[dc->r0], cpu_R[dc->r1]);
5544c1b
         }
5544c1b
@@ -601,10 +601,10 @@ static void dec_rcsr(DisasContext *dc)
5544c1b
         tcg_gen_mov_tl(cpu_R[dc->r2], cpu_ie);
5544c1b
         break;
5544c1b
     case CSR_IM:
5544c1b
-        gen_helper_rcsr_im(cpu_R[dc->r2]);
5544c1b
+        gen_helper_rcsr_im(cpu_R[dc->r2], cpu_env);
5544c1b
         break;
5544c1b
     case CSR_IP:
5544c1b
-        gen_helper_rcsr_ip(cpu_R[dc->r2]);
5544c1b
+        gen_helper_rcsr_ip(cpu_R[dc->r2], cpu_env);
5544c1b
         break;
5544c1b
     case CSR_CC:
5544c1b
         tcg_gen_mov_tl(cpu_R[dc->r2], cpu_cc);
5544c1b
@@ -622,10 +622,10 @@ static void dec_rcsr(DisasContext *dc)
5544c1b
         tcg_gen_mov_tl(cpu_R[dc->r2], cpu_deba);
5544c1b
         break;
5544c1b
     case CSR_JTX:
5544c1b
-        gen_helper_rcsr_jtx(cpu_R[dc->r2]);
5544c1b
+        gen_helper_rcsr_jtx(cpu_R[dc->r2], cpu_env);
5544c1b
         break;
5544c1b
     case CSR_JRX:
5544c1b
-        gen_helper_rcsr_jrx(cpu_R[dc->r2]);
5544c1b
+        gen_helper_rcsr_jrx(cpu_R[dc->r2], cpu_env);
5544c1b
         break;
5544c1b
     case CSR_ICC:
5544c1b
     case CSR_DCC:
5544c1b
@@ -812,7 +812,7 @@ static void dec_wcsr(DisasContext *dc)
5544c1b
         if (use_icount) {
5544c1b
             gen_io_start();
5544c1b
         }
5544c1b
-        gen_helper_wcsr_im(cpu_R[dc->r1]);
5544c1b
+        gen_helper_wcsr_im(cpu_env, cpu_R[dc->r1]);
5544c1b
         tcg_gen_movi_tl(cpu_pc, dc->pc + 4);
5544c1b
         if (use_icount) {
5544c1b
             gen_io_end();
5544c1b
@@ -824,7 +824,7 @@ static void dec_wcsr(DisasContext *dc)
5544c1b
         if (use_icount) {
5544c1b
             gen_io_start();
5544c1b
         }
5544c1b
-        gen_helper_wcsr_ip(cpu_R[dc->r1]);
5544c1b
+        gen_helper_wcsr_ip(cpu_env, cpu_R[dc->r1]);
5544c1b
         tcg_gen_movi_tl(cpu_pc, dc->pc + 4);
5544c1b
         if (use_icount) {
5544c1b
             gen_io_end();
5544c1b
@@ -844,10 +844,10 @@ static void dec_wcsr(DisasContext *dc)
5544c1b
         tcg_gen_mov_tl(cpu_deba, cpu_R[dc->r1]);
5544c1b
         break;
5544c1b
     case CSR_JTX:
5544c1b
-        gen_helper_wcsr_jtx(cpu_R[dc->r1]);
5544c1b
+        gen_helper_wcsr_jtx(cpu_env, cpu_R[dc->r1]);
5544c1b
         break;
5544c1b
     case CSR_JRX:
5544c1b
-        gen_helper_wcsr_jrx(cpu_R[dc->r1]);
5544c1b
+        gen_helper_wcsr_jrx(cpu_env, cpu_R[dc->r1]);
5544c1b
         break;
5544c1b
     case CSR_DC:
5544c1b
         tcg_gen_mov_tl(cpu_dc, cpu_R[dc->r1]);
5544c1b
@@ -940,15 +940,13 @@ static const DecoderInfo decinfo[] = {
5544c1b
     dec_cmpne
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
-
5544c1b
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
5544c1b
         tcg_gen_debug_insn_start(dc->pc);
5544c1b
     }
5544c1b
 
5544c1b
-    dc->ir = ir = ldl_code(dc->pc);
5544c1b
+    dc->ir = ir;
5544c1b
     LOG_DIS("%8.8x\t", dc->ir);
5544c1b
 
5544c1b
     /* try guessing 'empty' instruction memory, although it may be a valid
5544c1b
@@ -1068,7 +1066,7 @@ static void gen_intermediate_code_internal(CPULM32State *env,
5544c1b
             gen_io_start();
5544c1b
         }
5544c1b
 
5544c1b
-        decode(dc);
5544c1b
+        decode(dc, cpu_ldl_code(env, dc->pc));
5544c1b
         dc->pc += 4;
5544c1b
         num_insns++;
5544c1b