5544c1b
From cf873edf4227be439a9ffa5abb3da61ff1fd6527 Mon Sep 17 00:00:00 2001
5544c1b
From: Richard Henderson <rth@twiddle.net>
5544c1b
Date: Fri, 21 Sep 2012 10:34:21 -0700
5544c1b
Subject: [PATCH] tcg-sparc: Assume v9 cpu always, i.e. force v8plus in 32-bit
5544c1b
 mode.
5544c1b
5544c1b
Current code doesn't actually work in 32-bit mode at all.  Since
5544c1b
no one really noticed, drop the complication of v7 and v8 cpus.
5544c1b
Eliminate the --sparc_cpu configure option and standardize macro
5544c1b
testing on TCG_TARGET_REG_BITS / HOST_LONG_BITS
5544c1b
5544c1b
Signed-off-by: Richard Henderson <rth@twiddle.net>
5544c1b
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1b
---
5544c1b
 configure              | 40 ++++------------------------------------
5544c1b
 disas.c                |  2 --
5544c1b
 exec.c                 |  6 +++---
5544c1b
 qemu-timer.h           |  8 +++++---
5544c1b
 tcg/sparc/tcg-target.c | 20 +++++---------------
5544c1b
 tcg/sparc/tcg-target.h |  7 ++++---
5544c1b
 tcg/tcg.c              |  3 ++-
5544c1b
 7 files changed, 23 insertions(+), 63 deletions(-)
5544c1b
5544c1b
diff --git a/configure b/configure
5544c1b
index 816f0f9..0590f16 100755
5544c1b
--- a/configure
5544c1b
+++ b/configure
5544c1b
@@ -111,7 +111,6 @@ source_path=`dirname "$0"`
5544c1b
 cpu=""
5544c1b
 interp_prefix="/usr/gnemul/qemu-%M"
5544c1b
 static="no"
5544c1b
-sparc_cpu=""
5544c1b
 cross_prefix=""
5544c1b
 audio_drv_list=""
5544c1b
 audio_card_list="ac97 es1370 sb16 hda"
5544c1b
@@ -249,21 +248,6 @@ for opt do
5544c1b
   ;;
5544c1b
   --disable-debug-info) debug_info="no"
5544c1b
   ;;
5544c1b
-  --sparc_cpu=*)
5544c1b
-    sparc_cpu="$optarg"
5544c1b
-    case $sparc_cpu in
5544c1b
-    v7|v8|v8plus|v8plusa)
5544c1b
-      cpu="sparc"
5544c1b
-    ;;
5544c1b
-    v9)
5544c1b
-      cpu="sparc64"
5544c1b
-    ;;
5544c1b
-    *)
5544c1b
-      echo "undefined SPARC architecture. Exiting";
5544c1b
-      exit 1
5544c1b
-    ;;
5544c1b
-    esac
5544c1b
-  ;;
5544c1b
   esac
5544c1b
 done
5544c1b
 # OS specific
5544c1b
@@ -351,8 +335,6 @@ elif check_define __i386__ ; then
5544c1b
 elif check_define __x86_64__ ; then
5544c1b
   cpu="x86_64"
5544c1b
 elif check_define __sparc__ ; then
5544c1b
-  # We can't check for 64 bit (when gcc is biarch) or V8PLUSA
5544c1b
-  # They must be specified using --sparc_cpu
5544c1b
   if check_define __arch64__ ; then
5544c1b
     cpu="sparc64"
5544c1b
   else
5544c1b
@@ -798,8 +780,6 @@ for opt do
5544c1b
   ;;
5544c1b
   --enable-uname-release=*) uname_release="$optarg"
5544c1b
   ;;
5544c1b
-  --sparc_cpu=*)
5544c1b
-  ;;
5544c1b
   --enable-werror) werror="yes"
5544c1b
   ;;
5544c1b
   --disable-werror) werror="no"
5544c1b
@@ -883,31 +863,19 @@ for opt do
5544c1b
   esac
5544c1b
 done
5544c1b
 
5544c1b
-#
5544c1b
-# If cpu ~= sparc and  sparc_cpu hasn't been defined, plug in the right
5544c1b
-# QEMU_CFLAGS/LDFLAGS (assume sparc_v8plus for 32-bit and sparc_v9 for 64-bit)
5544c1b
-#
5544c1b
 host_guest_base="no"
5544c1b
 case "$cpu" in
5544c1b
-    sparc) case $sparc_cpu in
5544c1b
-           v7|v8)
5544c1b
-             QEMU_CFLAGS="-mcpu=${sparc_cpu} -D__sparc_${sparc_cpu}__ $QEMU_CFLAGS"
5544c1b
-           ;;
5544c1b
-           v8plus|v8plusa)
5544c1b
-             QEMU_CFLAGS="-mcpu=ultrasparc -D__sparc_${sparc_cpu}__ $QEMU_CFLAGS"
5544c1b
-           ;;
5544c1b
-           *) # sparc_cpu not defined in the command line
5544c1b
-             QEMU_CFLAGS="-mcpu=ultrasparc -D__sparc_v8plus__ $QEMU_CFLAGS"
5544c1b
-           esac
5544c1b
+    sparc)
5544c1b
            LDFLAGS="-m32 $LDFLAGS"
5544c1b
-           QEMU_CFLAGS="-m32 -ffixed-g2 -ffixed-g3 $QEMU_CFLAGS"
5544c1b
+           QEMU_CFLAGS="-m32 -mcpu=ultrasparc $QEMU_CFLAGS"
5544c1b
+           QEMU_CFLAGS="-ffixed-g2 -ffixed-g3 $QEMU_CFLAGS"
5544c1b
            if test "$solaris" = "no" ; then
5544c1b
              QEMU_CFLAGS="-ffixed-g1 -ffixed-g6 $QEMU_CFLAGS"
5544c1b
            fi
5544c1b
            ;;
5544c1b
     sparc64)
5544c1b
-           QEMU_CFLAGS="-m64 -mcpu=ultrasparc -D__sparc_v9__ $QEMU_CFLAGS"
5544c1b
            LDFLAGS="-m64 $LDFLAGS"
5544c1b
+           QEMU_CFLAGS="-m64 -mcpu=ultrasparc $QEMU_CFLAGS"
5544c1b
            QEMU_CFLAGS="-ffixed-g5 -ffixed-g6 -ffixed-g7 $QEMU_CFLAGS"
5544c1b
            if test "$solaris" != "no" ; then
5544c1b
              QEMU_CFLAGS="-ffixed-g1 $QEMU_CFLAGS"
5544c1b
diff --git a/disas.c b/disas.c
5544c1b
index 7b2acc9..b801c8f 100644
5544c1b
--- a/disas.c
5544c1b
+++ b/disas.c
5544c1b
@@ -316,9 +316,7 @@ void disas(FILE *out, void *code, unsigned long size)
5544c1b
     print_insn = print_insn_alpha;
5544c1b
 #elif defined(__sparc__)
5544c1b
     print_insn = print_insn_sparc;
5544c1b
-#if defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
5544c1b
     disasm_info.mach = bfd_mach_sparc_v9b;
5544c1b
-#endif
5544c1b
 #elif defined(__arm__)
5544c1b
     print_insn = print_insn_arm;
5544c1b
 #elif defined(__MIPSEB__)
5544c1b
diff --git a/exec.c b/exec.c
5544c1b
index 871a68a..ad175db 100644
5544c1b
--- a/exec.c
5544c1b
+++ b/exec.c
5544c1b
@@ -86,7 +86,7 @@ static int nb_tbs;
5544c1b
 /* any access to the tbs or the page table must use this lock */
5544c1b
 spinlock_t tb_lock = SPIN_LOCK_UNLOCKED;
5544c1b
 
5544c1b
-#if defined(__arm__) || defined(__sparc_v9__)
5544c1b
+#if defined(__arm__) || defined(__sparc__)
5544c1b
 /* The prologue must be reachable with a direct jump. ARM and Sparc64
5544c1b
  have limited branch ranges (possibly also PPC) so place it in a
5544c1b
  section close to code segment. */
5544c1b
@@ -541,7 +541,7 @@ static void code_gen_alloc(unsigned long tb_size)
5544c1b
         /* Cannot map more than that */
5544c1b
         if (code_gen_buffer_size > (800 * 1024 * 1024))
5544c1b
             code_gen_buffer_size = (800 * 1024 * 1024);
5544c1b
-#elif defined(__sparc_v9__)
5544c1b
+#elif defined(__sparc__) && HOST_LONG_BITS == 64
5544c1b
         // Map the buffer below 2G, so we can use direct calls and branches
5544c1b
         start = (void *) 0x40000000UL;
5544c1b
         if (code_gen_buffer_size > (512 * 1024 * 1024))
5544c1b
@@ -581,7 +581,7 @@ static void code_gen_alloc(unsigned long tb_size)
5544c1b
         /* Cannot map more than that */
5544c1b
         if (code_gen_buffer_size > (800 * 1024 * 1024))
5544c1b
             code_gen_buffer_size = (800 * 1024 * 1024);
5544c1b
-#elif defined(__sparc_v9__)
5544c1b
+#elif defined(__sparc__) && HOST_LONG_BITS == 64
5544c1b
         // Map the buffer below 2G, so we can use direct calls and branches
5544c1b
         addr = (void *) 0x40000000UL;
5544c1b
         if (code_gen_buffer_size > (512 * 1024 * 1024)) {
5544c1b
diff --git a/qemu-timer.h b/qemu-timer.h
5544c1b
index f8af595..da7e97c 100644
5544c1b
--- a/qemu-timer.h
5544c1b
+++ b/qemu-timer.h
5544c1b
@@ -218,7 +218,7 @@ static inline int64_t cpu_get_real_ticks(void)
5544c1b
     return val;
5544c1b
 }
5544c1b
 
5544c1b
-#elif defined(__sparc_v8plus__) || defined(__sparc_v8plusa__) || defined(__sparc_v9__)
5544c1b
+#elif defined(__sparc__)
5544c1b
 
5544c1b
 static inline int64_t cpu_get_real_ticks (void)
5544c1b
 {
5544c1b
@@ -227,6 +227,8 @@ static inline int64_t cpu_get_real_ticks (void)
5544c1b
     asm volatile("rd %%tick,%0" : "=r"(rval));
5544c1b
     return rval;
5544c1b
 #else
5544c1b
+    /* We need an %o or %g register for this.  For recent enough gcc
5544c1b
+       there is an "h" constraint for that.  Don't bother with that.  */
5544c1b
     union {
5544c1b
         uint64_t i64;
5544c1b
         struct {
5544c1b
@@ -234,8 +236,8 @@ static inline int64_t cpu_get_real_ticks (void)
5544c1b
             uint32_t low;
5544c1b
         }       i32;
5544c1b
     } rval;
5544c1b
-    asm volatile("rd %%tick,%1; srlx %1,32,%0"
5544c1b
-                 : "=r"(rval.i32.high), "=r"(rval.i32.low));
5544c1b
+    asm volatile("rd %%tick,%%g1; srlx %%g1,32,%0; mov %%g1,%1"
5544c1b
+                 : "=r"(rval.i32.high), "=r"(rval.i32.low) : : "g1");
5544c1b
     return rval.i64;
5544c1b
 #endif
5544c1b
 }
5544c1b
diff --git a/tcg/sparc/tcg-target.c b/tcg/sparc/tcg-target.c
5544c1b
index 0a19313..23c2fda 100644
5544c1b
--- a/tcg/sparc/tcg-target.c
5544c1b
+++ b/tcg/sparc/tcg-target.c
5544c1b
@@ -621,18 +621,10 @@ static void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGArg ret,
5544c1b
 
5544c1b
     default:
5544c1b
         tcg_out_cmp(s, c1, c2, c2const);
5544c1b
-#if defined(__sparc_v9__) || defined(__sparc_v8plus__)
5544c1b
         tcg_out_movi_imm13(s, ret, 0);
5544c1b
-        tcg_out32 (s, ARITH_MOVCC | INSN_RD(ret)
5544c1b
-                   | INSN_RS1(tcg_cond_to_bcond[cond])
5544c1b
-                   | MOVCC_ICC | INSN_IMM11(1));
5544c1b
-#else
5544c1b
-        t = gen_new_label();
5544c1b
-        tcg_out_branch_i32(s, INSN_COND(tcg_cond_to_bcond[cond], 1), t);
5544c1b
-        tcg_out_movi_imm13(s, ret, 1);
5544c1b
-        tcg_out_movi_imm13(s, ret, 0);
5544c1b
-        tcg_out_label(s, t, s->code_ptr);
5544c1b
-#endif
5544c1b
+        tcg_out32(s, ARITH_MOVCC | INSN_RD(ret)
5544c1b
+                  | INSN_RS1(tcg_cond_to_bcond[cond])
5544c1b
+                  | MOVCC_ICC | INSN_IMM11(1));
5544c1b
         return;
5544c1b
     }
5544c1b
 
5544c1b
@@ -742,7 +734,7 @@ static const void * const qemu_st_helpers[4] = {
5544c1b
 #endif
5544c1b
 #endif
5544c1b
 
5544c1b
-#ifdef __arch64__
5544c1b
+#if TCG_TARGET_REG_BITS == 64
5544c1b
 #define HOST_LD_OP LDX
5544c1b
 #define HOST_ST_OP STX
5544c1b
 #define HOST_SLL_OP SHIFT_SLLX
5544c1b
@@ -1600,11 +1592,9 @@ static void tcg_target_init(TCGContext *s)
5544c1b
 
5544c1b
 #if TCG_TARGET_REG_BITS == 64
5544c1b
 # define ELF_HOST_MACHINE  EM_SPARCV9
5544c1b
-#elif defined(__sparc_v8plus__)
5544c1b
+#else
5544c1b
 # define ELF_HOST_MACHINE  EM_SPARC32PLUS
5544c1b
 # define ELF_HOST_FLAGS    EF_SPARC_32PLUS
5544c1b
-#else
5544c1b
-# define ELF_HOST_MACHINE  EM_SPARC
5544c1b
 #endif
5544c1b
 
5544c1b
 typedef struct {
5544c1b
diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h
5544c1b
index d762574..adca1d2 100644
5544c1b
--- a/tcg/sparc/tcg-target.h
5544c1b
+++ b/tcg/sparc/tcg-target.h
5544c1b
@@ -67,7 +67,8 @@ typedef enum {
5544c1b
 
5544c1b
 /* used for function call generation */
5544c1b
 #define TCG_REG_CALL_STACK TCG_REG_I6
5544c1b
-#ifdef __arch64__
5544c1b
+
5544c1b
+#if TCG_TARGET_REG_BITS == 64
5544c1b
 // Reserve space for AREG0
5544c1b
 #define TCG_TARGET_STACK_MINFRAME (176 + 4 * (int)sizeof(long) + \
5544c1b
                                    TCG_STATIC_CALL_ARGS_SIZE)
5544c1b
@@ -81,7 +82,7 @@ typedef enum {
5544c1b
 #define TCG_TARGET_STACK_ALIGN 8
5544c1b
 #endif
5544c1b
 
5544c1b
-#ifdef __arch64__
5544c1b
+#if TCG_TARGET_REG_BITS == 64
5544c1b
 #define TCG_TARGET_EXTEND_ARGS 1
5544c1b
 #endif
5544c1b
 
5544c1b
@@ -129,7 +130,7 @@ typedef enum {
5544c1b
 
5544c1b
 #ifdef CONFIG_SOLARIS
5544c1b
 #define TCG_AREG0 TCG_REG_G2
5544c1b
-#elif defined(__sparc_v9__)
5544c1b
+#elif HOST_LONG_BITS == 64
5544c1b
 #define TCG_AREG0 TCG_REG_G5
5544c1b
 #else
5544c1b
 #define TCG_AREG0 TCG_REG_G6
5544c1b
diff --git a/tcg/tcg.c b/tcg/tcg.c
5544c1b
index 93421cd..16c4e1d 100644
5544c1b
--- a/tcg/tcg.c
5544c1b
+++ b/tcg/tcg.c
5544c1b
@@ -1450,7 +1450,8 @@ static void temp_allocate_frame(TCGContext *s, int temp)
5544c1b
 {
5544c1b
     TCGTemp *ts;
5544c1b
     ts = &s->temps[temp];
5544c1b
-#ifndef __sparc_v9__ /* Sparc64 stack is accessed with offset of 2047 */
5544c1b
+#if !(defined(__sparc__) && TCG_TARGET_REG_BITS == 64)
5544c1b
+    /* Sparc64 stack is accessed with offset of 2047 */
5544c1b
     s->current_frame_offset = (s->current_frame_offset +
5544c1b
                                (tcg_target_long)sizeof(tcg_target_long) - 1) &
5544c1b
         ~(sizeof(tcg_target_long) - 1);