1 From bfeac1b2d18b12c1c3c64a41a09c90f93d0ed4ca Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Mon, 15 Aug 2016 15:00:13 +0800
4 Subject: [PATCH] mips: fix MIPS softfloat build issue
6 The patch for o32.S is taken from OpenWrt packages repo 3a7a4bf "libffi:
7 fix MIPS softfloat build issue with current binutils"
9 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
12 src/mips/n32.S | 17 +++++++++++++++++
13 src/mips/o32.S | 17 +++++++++++++++++
14 2 files changed, 34 insertions(+)
16 diff --git a/src/mips/n32.S b/src/mips/n32.S
17 index c6985d3..8f25994 100644
20 @@ -107,6 +107,16 @@ loadregs:
22 REG_L t6, 3*FFI_SIZEOF_ARG($fp) # load the flags word into t6.
24 +#ifdef __mips_soft_float
25 + REG_L a0, 0*FFI_SIZEOF_ARG(t9)
26 + REG_L a1, 1*FFI_SIZEOF_ARG(t9)
27 + REG_L a2, 2*FFI_SIZEOF_ARG(t9)
28 + REG_L a3, 3*FFI_SIZEOF_ARG(t9)
29 + REG_L a4, 4*FFI_SIZEOF_ARG(t9)
30 + REG_L a5, 5*FFI_SIZEOF_ARG(t9)
31 + REG_L a6, 6*FFI_SIZEOF_ARG(t9)
32 + REG_L a7, 7*FFI_SIZEOF_ARG(t9)
34 and t4, t6, ((1<<FFI_FLAG_BITS)-1)
35 REG_L a0, 0*FFI_SIZEOF_ARG(t9)
37 @@ -193,6 +203,7 @@ arg7_next:
39 l.d $f19, 7*FFI_SIZEOF_ARG(t9)
44 # Load the function pointer
45 @@ -214,6 +225,7 @@ retint:
49 +#ifndef __mips_soft_float
50 bne t6, FFI_TYPE_FLOAT, retdouble
52 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
53 @@ -272,6 +284,7 @@ retstruct_f_d:
60 bne t6, FFI_TYPE_STRUCT_D_SOFT, retstruct_f_soft
61 @@ -429,6 +442,7 @@ ffi_closure_N32:
62 REG_S a6, A6_OFF2($sp)
63 REG_S a7, A7_OFF2($sp)
65 +#ifndef __mips_soft_float
66 # Store all possible float/double registers.
67 s.d $f12, F12_OFF2($sp)
68 s.d $f13, F13_OFF2($sp)
69 @@ -438,6 +452,7 @@ ffi_closure_N32:
70 s.d $f17, F17_OFF2($sp)
71 s.d $f18, F18_OFF2($sp)
72 s.d $f19, F19_OFF2($sp)
75 # Call ffi_closure_mips_inner_N32 to do the real work.
76 LA t9, ffi_closure_mips_inner_N32
77 @@ -458,6 +473,7 @@ cls_retint:
81 +#ifndef __mips_soft_float
82 bne v0, FFI_TYPE_FLOAT, cls_retdouble
85 @@ -500,6 +516,7 @@ cls_retstruct_f_d:
92 REG_L v0, V0_OFF2($sp)
93 diff --git a/src/mips/o32.S b/src/mips/o32.S
94 index eb27981..429dd0a 100644
97 @@ -82,13 +82,16 @@ sixteen:
99 ADDU $sp, 4 * FFI_SIZEOF_ARG # adjust $sp to new args
101 +#ifndef __mips_soft_float
102 bnez t0, pass_d # make it quick for int
104 REG_L a0, 0*FFI_SIZEOF_ARG($sp) # just go ahead and load the
105 REG_L a1, 1*FFI_SIZEOF_ARG($sp) # four regs.
106 REG_L a2, 2*FFI_SIZEOF_ARG($sp)
107 REG_L a3, 3*FFI_SIZEOF_ARG($sp)
110 +#ifndef __mips_soft_float
112 bne t0, FFI_ARGS_D, pass_f
113 l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
114 @@ -130,6 +133,7 @@ pass_f_d:
115 # bne t0, FFI_ARGS_F_D, call_it
116 l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
117 l.d $f14, 2*FFI_SIZEOF_ARG($sp) # passing double and float
121 # Load the function pointer
122 @@ -158,14 +162,23 @@ retfloat:
123 bne t2, FFI_TYPE_FLOAT, retdouble
125 REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
126 +#ifndef __mips_soft_float
134 bne t2, FFI_TYPE_DOUBLE, noretval
136 REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
137 +#ifndef __mips_soft_float
146 @@ -261,9 +274,11 @@ $LCFI7:
148 bne $16, $13, 1f # Skip fp save if FFI_O32_SOFT_FLOAT
150 +#ifndef __mips_soft_float
151 # Store all possible float/double registers.
152 s.d $f12, FA_0_0_OFF2($fp)
153 s.d $f14, FA_1_0_OFF2($fp)
156 # Call ffi_closure_mips_inner_O32 to do the work.
157 la t9, ffi_closure_mips_inner_O32
158 @@ -281,6 +296,7 @@ $LCFI7:
160 bne $16, $13, 1f # Skip fp restore if FFI_O32_SOFT_FLOAT
162 +#ifndef __mips_soft_float
163 li $9, FFI_TYPE_FLOAT
164 l.s $f0, V0_OFF2($fp)
165 beq $8, $9, closure_done
166 @@ -288,6 +304,7 @@ $LCFI7:
167 li $9, FFI_TYPE_DOUBLE
168 l.d $f0, V0_OFF2($fp)
169 beq $8, $9, closure_done
172 REG_L $3, V1_OFF2($fp)
173 REG_L $2, V0_OFF2($fp)