render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0088-tcg-sparc-Clean-up-cruft-stemming-from-attempts-to-u.patch

5544c1
From 5767c23140f2c92b899d9caeaa8e08711cb63868 Mon Sep 17 00:00:00 2001
5544c1
From: Richard Henderson <rth@twiddle.net>
5544c1
Date: Sun, 25 Mar 2012 21:21:46 +0200
5544c1
Subject: [PATCH] tcg-sparc: Clean up cruft stemming from attempts to use
5544c1
 global registers.
5544c1
5544c1
Don't use -ffixed-gN.  Don't link statically.  Don't save/restore
5544c1
AREG0 around calls.  Don't allocate space on the stack for AREG0 save.
5544c1
5544c1
Signed-off-by: Richard Henderson <rth@twiddle.net>
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 configure              | 12 -----------
5544c1
 tcg/sparc/tcg-target.c | 55 +++++++++++++++++---------------------------------
5544c1
 tcg/sparc/tcg-target.h | 18 +++++++----------
5544c1
 3 files changed, 26 insertions(+), 59 deletions(-)
5544c1
5544c1
diff --git a/configure b/configure
5544c1
index 9139b5c..8ffddf4 100755
5544c1
--- a/configure
5544c1
+++ b/configure
5544c1
@@ -868,19 +868,11 @@ case "$cpu" in
5544c1
     sparc)
5544c1
            LDFLAGS="-m32 $LDFLAGS"
5544c1
            QEMU_CFLAGS="-m32 -mcpu=ultrasparc $QEMU_CFLAGS"
5544c1
-           QEMU_CFLAGS="-ffixed-g2 -ffixed-g3 $QEMU_CFLAGS"
5544c1
-           if test "$solaris" = "no" ; then
5544c1
-             QEMU_CFLAGS="-ffixed-g1 -ffixed-g6 $QEMU_CFLAGS"
5544c1
-           fi
5544c1
            host_guest_base="yes"
5544c1
            ;;
5544c1
     sparc64)
5544c1
            LDFLAGS="-m64 $LDFLAGS"
5544c1
            QEMU_CFLAGS="-m64 -mcpu=ultrasparc $QEMU_CFLAGS"
5544c1
-           QEMU_CFLAGS="-ffixed-g5 -ffixed-g6 -ffixed-g7 $QEMU_CFLAGS"
5544c1
-           if test "$solaris" != "no" ; then
5544c1
-             QEMU_CFLAGS="-ffixed-g1 $QEMU_CFLAGS"
5544c1
-           fi
5544c1
            host_guest_base="yes"
5544c1
            ;;
5544c1
     s390)
5544c1
@@ -4055,10 +4047,6 @@ fi
5544c1
 
5544c1
 if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then
5544c1
   case "$ARCH" in
5544c1
-  sparc)
5544c1
-    # -static is used to avoid g1/g3 usage by the dynamic linker
5544c1
-    ldflags="$linker_script -static $ldflags"
5544c1
-    ;;
5544c1
   alpha | s390x)
5544c1
     # The default placement of the application is fine.
5544c1
     ;;
5544c1
diff --git a/tcg/sparc/tcg-target.c b/tcg/sparc/tcg-target.c
5544c1
index 9ab5746..e625aa3 100644
5544c1
--- a/tcg/sparc/tcg-target.c
5544c1
+++ b/tcg/sparc/tcg-target.c
5544c1
@@ -161,7 +161,6 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
5544c1
         tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0);
5544c1
         tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1);
5544c1
         tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2);
5544c1
-        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O3);
5544c1
         break;
5544c1
     case 'I':
5544c1
         ct->ct |= TCG_CT_CONST_S11;
5544c1
@@ -681,11 +680,22 @@ static void tcg_out_setcond2_i32(TCGContext *s, TCGCond cond, TCGArg ret,
5544c1
 /* Generate global QEMU prologue and epilogue code */
5544c1
 static void tcg_target_qemu_prologue(TCGContext *s)
5544c1
 {
5544c1
-    tcg_set_frame(s, TCG_REG_I6, TCG_TARGET_CALL_STACK_OFFSET,
5544c1
-                  CPU_TEMP_BUF_NLONGS * (int)sizeof(long));
5544c1
+    int tmp_buf_size, frame_size;
5544c1
+
5544c1
+    /* The TCG temp buffer is at the top of the frame, immediately
5544c1
+       below the frame pointer.  */
5544c1
+    tmp_buf_size = CPU_TEMP_BUF_NLONGS * (int)sizeof(long);
5544c1
+    tcg_set_frame(s, TCG_REG_I6, TCG_TARGET_STACK_BIAS - tmp_buf_size,
5544c1
+                  tmp_buf_size);
5544c1
+
5544c1
+    /* TCG_TARGET_CALL_STACK_OFFSET includes the stack bias, but is
5544c1
+       otherwise the minimal frame usable by callees.  */
5544c1
+    frame_size = TCG_TARGET_CALL_STACK_OFFSET - TCG_TARGET_STACK_BIAS;
5544c1
+    frame_size += TCG_STATIC_CALL_ARGS_SIZE + tmp_buf_size;
5544c1
+    frame_size += TCG_TARGET_STACK_ALIGN - 1;
5544c1
+    frame_size &= -TCG_TARGET_STACK_ALIGN;
5544c1
     tcg_out32(s, SAVE | INSN_RD(TCG_REG_O6) | INSN_RS1(TCG_REG_O6) |
5544c1
-              INSN_IMM13(-(TCG_TARGET_STACK_MINFRAME +
5544c1
-                           CPU_TEMP_BUF_NLONGS * (int)sizeof(long))));
5544c1
+              INSN_IMM13(-frame_size));
5544c1
 
5544c1
 #ifdef CONFIG_USE_GUEST_BASE
5544c1
     if (GUEST_BASE != 0) {
5544c1
@@ -698,6 +708,8 @@ static void tcg_target_qemu_prologue(TCGContext *s)
5544c1
               INSN_RS2(TCG_REG_G0));
5544c1
     /* delay slot */
5544c1
     tcg_out_nop(s);
5544c1
+
5544c1
+    /* No epilogue required.  We issue ret + restore directly in the TB.  */
5544c1
 }
5544c1
 
5544c1
 #if defined(CONFIG_SOFTMMU)
5544c1
@@ -880,12 +892,6 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int sizeop)
5544c1
     tcg_out_mov(s, TCG_TYPE_REG, tcg_target_call_iarg_regs[n++],
5544c1
                 args[addrlo_idx]);
5544c1
 
5544c1
-    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
5544c1
-       global registers */
5544c1
-    tcg_out_st(s, TCG_TYPE_REG, TCG_AREG0, TCG_REG_CALL_STACK,
5544c1
-               TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
5544c1
-               sizeof(long));
5544c1
-
5544c1
     /* qemu_ld_helper[s_bits](arg0, arg1) */
5544c1
     tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_ld_helpers[s_bits]
5544c1
                            - (tcg_target_ulong)s->code_ptr) >> 2)
5544c1
@@ -893,11 +899,6 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int sizeop)
5544c1
     /* delay slot */
5544c1
     tcg_out_movi(s, TCG_TYPE_I32, tcg_target_call_iarg_regs[n], memi);
5544c1
 
5544c1
-    /* Reload AREG0.  */
5544c1
-    tcg_out_ld(s, TCG_TYPE_REG, TCG_AREG0, TCG_REG_CALL_STACK,
5544c1
-               TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
5544c1
-               sizeof(long));
5544c1
-
5544c1
     n = tcg_target_call_oarg_regs[0];
5544c1
     /* datalo = sign_extend(arg0) */
5544c1
     switch (sizeop) {
5544c1
@@ -1011,12 +1012,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int sizeop)
5544c1
     }
5544c1
     tcg_out_mov(s, TCG_TYPE_REG, tcg_target_call_iarg_regs[n++], datalo);
5544c1
 
5544c1
-    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
5544c1
-       global registers */
5544c1
-    tcg_out_st(s, TCG_TYPE_REG, TCG_AREG0, TCG_REG_CALL_STACK,
5544c1
-               TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
5544c1
-               sizeof(long));
5544c1
-
5544c1
     /* qemu_st_helper[s_bits](arg0, arg1, arg2) */
5544c1
     tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_st_helpers[sizeop]
5544c1
                            - (tcg_target_ulong)s->code_ptr) >> 2)
5544c1
@@ -1024,11 +1019,6 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int sizeop)
5544c1
     /* delay slot */
5544c1
     tcg_out_movi(s, TCG_TYPE_REG, tcg_target_call_iarg_regs[n], memi);
5544c1
 
5544c1
-    /* Reload AREG0.  */
5544c1
-    tcg_out_ld(s, TCG_TYPE_REG, TCG_AREG0, TCG_REG_CALL_STACK,
5544c1
-               TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
5544c1
-               sizeof(long));
5544c1
-
5544c1
     *label_ptr |= INSN_OFF19((unsigned long)s->code_ptr -
5544c1
                              (unsigned long)label_ptr);
5544c1
 #else
5544c1
@@ -1091,15 +1081,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
5544c1
             tcg_out32(s, JMPL | INSN_RD(TCG_REG_O7) | INSN_RS1(TCG_REG_I5) |
5544c1
                       INSN_RS2(TCG_REG_G0));
5544c1
         }
5544c1
-        /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
5544c1
-           global registers */
5544c1
-        // delay slot
5544c1
-        tcg_out_st(s, TCG_TYPE_REG, TCG_AREG0, TCG_REG_CALL_STACK,
5544c1
-                   TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
5544c1
-                   sizeof(long));
5544c1
-        tcg_out_ld(s, TCG_TYPE_REG, TCG_AREG0, TCG_REG_CALL_STACK,
5544c1
-                   TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
5544c1
-                   sizeof(long));
5544c1
+        /* delay slot */
5544c1
+        tcg_out_nop(s);
5544c1
         break;
5544c1
     case INDEX_op_jmp:
5544c1
     case INDEX_op_br:
5544c1
diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h
5544c1
index ee154d0..6314ffb 100644
5544c1
--- a/tcg/sparc/tcg-target.h
5544c1
+++ b/tcg/sparc/tcg-target.h
5544c1
@@ -66,20 +66,16 @@ typedef enum {
5544c1
 #define TCG_CT_CONST_S13 0x200
5544c1
 
5544c1
 /* used for function call generation */
5544c1
-#define TCG_REG_CALL_STACK TCG_REG_I6
5544c1
+#define TCG_REG_CALL_STACK TCG_REG_O6
5544c1
 
5544c1
 #if TCG_TARGET_REG_BITS == 64
5544c1
-// Reserve space for AREG0
5544c1
-#define TCG_TARGET_STACK_MINFRAME (176 + 4 * (int)sizeof(long) + \
5544c1
-                                   TCG_STATIC_CALL_ARGS_SIZE)
5544c1
-#define TCG_TARGET_CALL_STACK_OFFSET (2047 - 16)
5544c1
-#define TCG_TARGET_STACK_ALIGN 16
5544c1
+#define TCG_TARGET_STACK_BIAS           2047
5544c1
+#define TCG_TARGET_STACK_ALIGN          16
5544c1
+#define TCG_TARGET_CALL_STACK_OFFSET    (128 + 6*8 + TCG_TARGET_STACK_BIAS)
5544c1
 #else
5544c1
-// AREG0 + one word for alignment
5544c1
-#define TCG_TARGET_STACK_MINFRAME (92 + (2 + 1) * (int)sizeof(long) + \
5544c1
-                                   TCG_STATIC_CALL_ARGS_SIZE)
5544c1
-#define TCG_TARGET_CALL_STACK_OFFSET TCG_TARGET_STACK_MINFRAME
5544c1
-#define TCG_TARGET_STACK_ALIGN 8
5544c1
+#define TCG_TARGET_STACK_BIAS           0
5544c1
+#define TCG_TARGET_STACK_ALIGN          8
5544c1
+#define TCG_TARGET_CALL_STACK_OFFSET    (64 + 4 + 6*4)
5544c1
 #endif
5544c1
 
5544c1
 #if TCG_TARGET_REG_BITS == 64
5544c1
-- 
5544c1
1.7.12.1
5544c1