1 From c0c62fa4256f805389f16ebfc4a60cf789129b50 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] libffi: fix MIPS softfloat build issue
6 Backported from github.com/libffi/libffi#272
8 Signed-off-by: BangLang Huang <banglang.huang@foxmail.com>
9 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
11 libffi/src/mips/n32.S | 17 +++++++++++++++++
12 libffi/src/mips/o32.S | 17 +++++++++++++++++
13 2 files changed, 34 insertions(+)
15 --- a/libffi/src/mips/n32.S
16 +++ b/libffi/src/mips/n32.S
17 @@ -107,6 +107,16 @@ loadregs:
19 REG_L t6, 3*FFI_SIZEOF_ARG($fp) # load the flags word into t6.
21 +#ifdef __mips_soft_float
22 + REG_L a0, 0*FFI_SIZEOF_ARG(t9)
23 + REG_L a1, 1*FFI_SIZEOF_ARG(t9)
24 + REG_L a2, 2*FFI_SIZEOF_ARG(t9)
25 + REG_L a3, 3*FFI_SIZEOF_ARG(t9)
26 + REG_L a4, 4*FFI_SIZEOF_ARG(t9)
27 + REG_L a5, 5*FFI_SIZEOF_ARG(t9)
28 + REG_L a6, 6*FFI_SIZEOF_ARG(t9)
29 + REG_L a7, 7*FFI_SIZEOF_ARG(t9)
31 and t4, t6, ((1<<FFI_FLAG_BITS)-1)
32 REG_L a0, 0*FFI_SIZEOF_ARG(t9)
34 @@ -193,6 +203,7 @@ arg7_next:
36 l.d $f19, 7*FFI_SIZEOF_ARG(t9)
41 # Load the function pointer
42 @@ -214,6 +225,7 @@ retint:
46 +#ifndef __mips_soft_float
47 bne t6, FFI_TYPE_FLOAT, retdouble
49 REG_L t4, 4*FFI_SIZEOF_ARG($fp)
50 @@ -272,6 +284,7 @@ retstruct_f_d:
57 bne t6, FFI_TYPE_STRUCT_D_SOFT, retstruct_f_soft
58 @@ -429,6 +442,7 @@ ffi_closure_N32:
59 REG_S a6, A6_OFF2($sp)
60 REG_S a7, A7_OFF2($sp)
62 +#ifndef __mips_soft_float
63 # Store all possible float/double registers.
64 s.d $f12, F12_OFF2($sp)
65 s.d $f13, F13_OFF2($sp)
66 @@ -438,6 +452,7 @@ ffi_closure_N32:
67 s.d $f17, F17_OFF2($sp)
68 s.d $f18, F18_OFF2($sp)
69 s.d $f19, F19_OFF2($sp)
72 # Call ffi_closure_mips_inner_N32 to do the real work.
73 LA t9, ffi_closure_mips_inner_N32
74 @@ -458,6 +473,7 @@ cls_retint:
78 +#ifndef __mips_soft_float
79 bne v0, FFI_TYPE_FLOAT, cls_retdouble
82 @@ -500,6 +516,7 @@ cls_retstruct_f_d:
89 REG_L v0, V0_OFF2($sp)
90 --- a/libffi/src/mips/o32.S
91 +++ b/libffi/src/mips/o32.S
92 @@ -82,13 +82,16 @@ sixteen:
94 ADDU $sp, 4 * FFI_SIZEOF_ARG # adjust $sp to new args
96 +#ifndef __mips_soft_float
97 bnez t0, pass_d # make it quick for int
99 REG_L a0, 0*FFI_SIZEOF_ARG($sp) # just go ahead and load the
100 REG_L a1, 1*FFI_SIZEOF_ARG($sp) # four regs.
101 REG_L a2, 2*FFI_SIZEOF_ARG($sp)
102 REG_L a3, 3*FFI_SIZEOF_ARG($sp)
105 +#ifndef __mips_soft_float
107 bne t0, FFI_ARGS_D, pass_f
108 l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
109 @@ -130,6 +133,7 @@ pass_f_d:
110 # bne t0, FFI_ARGS_F_D, call_it
111 l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
112 l.d $f14, 2*FFI_SIZEOF_ARG($sp) # passing double and float
116 # Load the function pointer
117 @@ -158,14 +162,23 @@ retfloat:
118 bne t2, FFI_TYPE_FLOAT, retdouble
120 REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
121 +#ifndef __mips_soft_float
129 bne t2, FFI_TYPE_DOUBLE, noretval
131 REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
132 +#ifndef __mips_soft_float
141 @@ -261,9 +274,11 @@ $LCFI7:
143 bne $16, $13, 1f # Skip fp save if FFI_O32_SOFT_FLOAT
145 +#ifndef __mips_soft_float
146 # Store all possible float/double registers.
147 s.d $f12, FA_0_0_OFF2($fp)
148 s.d $f14, FA_1_0_OFF2($fp)
151 # Call ffi_closure_mips_inner_O32 to do the work.
152 la t9, ffi_closure_mips_inner_O32
153 @@ -281,6 +296,7 @@ $LCFI7:
155 bne $16, $13, 1f # Skip fp restore if FFI_O32_SOFT_FLOAT
157 +#ifndef __mips_soft_float
158 li $9, FFI_TYPE_FLOAT
159 l.s $f0, V0_OFF2($fp)
160 beq $8, $9, closure_done
161 @@ -288,6 +304,7 @@ $LCFI7:
162 li $9, FFI_TYPE_DOUBLE
163 l.d $f0, V0_OFF2($fp)
164 beq $8, $9, closure_done
167 REG_L $3, V1_OFF2($fp)
168 REG_L $2, V0_OFF2($fp)