1 From 2b46f9187b6f994fc450628a7cd97fc703dd23e0 Mon Sep 17 00:00:00 2001
2 From: BangLang Huang <banglang.huang@foxmail.com>
3 Date: Wed, 9 Nov 2016 10:36:49 +0800
4 Subject: [PATCH] fix MIPS softfloat build issue
6 This patch is backport from github/libffi #272
8 Signed-off-by: BangLang Huang <banglang.huang@foxmail.com>
10 libffi/src/mips/n32.S | 17 +++++++++++++++++
11 libffi/src/mips/o32.S | 17 +++++++++++++++++
12 2 files changed, 34 insertions(+)
14 diff --git a/libffi/src/mips/n32.S b/libffi/src/mips/n32.S
15 index c6985d3..8f25994 100644
16 --- a/libffi/src/mips/n32.S
17 +++ b/libffi/src/mips/n32.S
18 @@ -107,6 +107,16 @@ loadregs:
20 REG_L t6, 3*FFI_SIZEOF_ARG($fp) # load the flags word into t6.
22 +#ifdef __mips_soft_float
23 + REG_L a0, 0*FFI_SIZEOF_ARG(t9)
24 + REG_L a1, 1*FFI_SIZEOF_ARG(t9)
25 + REG_L a2, 2*FFI_SIZEOF_ARG(t9)
26 + REG_L a3, 3*FFI_SIZEOF_ARG(t9)
27 + REG_L a4, 4*FFI_SIZEOF_ARG(t9)
28 + REG_L a5, 5*FFI_SIZEOF_ARG(t9)
29 + REG_L a6, 6*FFI_SIZEOF_ARG(t9)
30 + REG_L a7, 7*FFI_SIZEOF_ARG(t9)
32 and t4, t6, ((1<<FFI_FLAG_BITS)-1)
33 REG_L a0, 0*FFI_SIZEOF_ARG(t9)
35 @@ -193,6 +203,7 @@ arg7_next:
37 l.d $f19, 7*FFI_SIZEOF_ARG(t9)
42 # Load the function pointer
43 @@ -214,6 +225,7 @@ retint:
47 +#ifndef __mips_soft_float
48 bne t6, FFI_TYPE_FLOAT, retdouble
50 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
51 @@ -272,6 +284,7 @@ retstruct_f_d:
58 bne t6, FFI_TYPE_STRUCT_D_SOFT, retstruct_f_soft
59 @@ -429,6 +442,7 @@ ffi_closure_N32:
60 REG_S a6, A6_OFF2($sp)
61 REG_S a7, A7_OFF2($sp)
63 +#ifndef __mips_soft_float
64 # Store all possible float/double registers.
65 s.d $f12, F12_OFF2($sp)
66 s.d $f13, F13_OFF2($sp)
67 @@ -438,6 +452,7 @@ ffi_closure_N32:
68 s.d $f17, F17_OFF2($sp)
69 s.d $f18, F18_OFF2($sp)
70 s.d $f19, F19_OFF2($sp)
73 # Call ffi_closure_mips_inner_N32 to do the real work.
74 LA t9, ffi_closure_mips_inner_N32
75 @@ -458,6 +473,7 @@ cls_retint:
79 +#ifndef __mips_soft_float
80 bne v0, FFI_TYPE_FLOAT, cls_retdouble
83 @@ -500,6 +516,7 @@ cls_retstruct_f_d:
90 REG_L v0, V0_OFF2($sp)
91 diff --git a/libffi/src/mips/o32.S b/libffi/src/mips/o32.S
92 index eb27981..1aff4b1 100644
93 --- a/libffi/src/mips/o32.S
94 +++ b/libffi/src/mips/o32.S
95 @@ -82,13 +82,16 @@ sixteen:
97 ADDU $sp, 4 * FFI_SIZEOF_ARG # adjust $sp to new args
99 +#ifndef __mips_soft_float
100 bnez t0, pass_d # make it quick for int
102 REG_L a0, 0*FFI_SIZEOF_ARG($sp) # just go ahead and load the
103 REG_L a1, 1*FFI_SIZEOF_ARG($sp) # four regs.
104 REG_L a2, 2*FFI_SIZEOF_ARG($sp)
105 REG_L a3, 3*FFI_SIZEOF_ARG($sp)
108 +#ifndef __mips_soft_float
110 bne t0, FFI_ARGS_D, pass_f
111 l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
112 @@ -130,6 +133,7 @@ pass_f_d:
113 # bne t0, FFI_ARGS_F_D, call_it
114 l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
115 l.d $f14, 2*FFI_SIZEOF_ARG($sp) # passing double and float
119 # Load the function pointer
120 @@ -158,14 +162,23 @@ retfloat:
121 bne t2, FFI_TYPE_FLOAT, retdouble
123 REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
124 +#ifndef __mips_soft_float
132 bne t2, FFI_TYPE_DOUBLE, noretval
134 REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
135 +#ifndef __mips_soft_float
144 @@ -261,9 +274,11 @@ $LCFI7:
146 bne $16, $13, 1f # Skip fp save if FFI_O32_SOFT_FLOAT
148 +#ifndef __mips_soft_float
149 # Store all possible float/double registers.
150 s.d $f12, FA_0_0_OFF2($fp)
151 s.d $f14, FA_1_0_OFF2($fp)
154 # Call ffi_closure_mips_inner_O32 to do the work.
155 la t9, ffi_closure_mips_inner_O32
156 @@ -281,6 +296,7 @@ $LCFI7:
158 bne $16, $13, 1f # Skip fp restore if FFI_O32_SOFT_FLOAT
160 +#ifndef __mips_soft_float
161 li $9, FFI_TYPE_FLOAT
162 l.s $f0, V0_OFF2($fp)
163 beq $8, $9, closure_done
164 @@ -288,6 +304,7 @@ $LCFI7:
165 li $9, FFI_TYPE_DOUBLE
166 l.d $f0, V0_OFF2($fp)
167 beq $8, $9, closure_done
170 REG_L $3, V1_OFF2($fp)
171 REG_L $2, V0_OFF2($fp)