Fresh pull from upstream (stable) package feed
[librecmc/package-feed.git] / libs / libffi / patches / 100-fix_mips_softfloat.patch
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
5
6 The patch for o32.S is taken from OpenWrt packages repo 3a7a4bf "libffi:
7 fix MIPS softfloat build issue with current binutils"
8
9 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
10 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
11 ---
12  src/mips/n32.S | 17 +++++++++++++++++
13  src/mips/o32.S | 17 +++++++++++++++++
14  2 files changed, 34 insertions(+)
15
16 diff --git a/src/mips/n32.S b/src/mips/n32.S
17 index c6985d3..8f25994 100644
18 --- a/src/mips/n32.S
19 +++ b/src/mips/n32.S
20 @@ -107,6 +107,16 @@ loadregs:
21  
22         REG_L   t6, 3*FFI_SIZEOF_ARG($fp)  # load the flags word into t6.
23  
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)
33 +#else
34         and     t4, t6, ((1<<FFI_FLAG_BITS)-1)
35         REG_L   a0, 0*FFI_SIZEOF_ARG(t9)
36         beqz    t4, arg1_next
37 @@ -193,6 +203,7 @@ arg7_next:
38  arg8_doublep:  
39         l.d     $f19, 7*FFI_SIZEOF_ARG(t9)      
40  arg8_next:     
41 +#endif
42  
43  callit:                
44         # Load the function pointer
45 @@ -214,6 +225,7 @@ retint:
46         b       epilogue
47  
48  retfloat:
49 +#ifndef __mips_soft_float
50         bne     t6, FFI_TYPE_FLOAT, retdouble
51         jal     t9
52         REG_L   t4, 4*FFI_SIZEOF_ARG($fp)
53 @@ -272,6 +284,7 @@ retstruct_f_d:
54         s.s     $f0, 0(t4)
55         s.d     $f2, 8(t4)
56         b       epilogue
57 +#endif
58  
59  retstruct_d_soft:
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)
64  
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)
73 +#endif
74  
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:
78         b       cls_epilogue
79  
80  cls_retfloat:
81 +#ifndef __mips_soft_float
82         bne     v0, FFI_TYPE_FLOAT, cls_retdouble
83         l.s     $f0, V0_OFF2($sp)
84         b       cls_epilogue
85 @@ -500,6 +516,7 @@ cls_retstruct_f_d:
86         l.s     $f0, V0_OFF2($sp)
87         l.d     $f2, V1_OFF2($sp)
88         b       cls_epilogue
89 +#endif
90         
91  cls_retstruct_small2:  
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
95 --- a/src/mips/o32.S
96 +++ b/src/mips/o32.S
97 @@ -82,13 +82,16 @@ sixteen:
98                 
99         ADDU    $sp, 4 * FFI_SIZEOF_ARG         # adjust $sp to new args
100  
101 +#ifndef __mips_soft_float
102         bnez    t0, pass_d                      # make it quick for int
103 +#endif
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)
108         b       call_it
109  
110 +#ifndef __mips_soft_float
111  pass_d:
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
118 +#endif
119  
120  call_it:       
121         # Load the function pointer
122 @@ -158,14 +162,23 @@ retfloat:
123         bne     t2, FFI_TYPE_FLOAT, retdouble
124         jalr    t9
125         REG_L   t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
126 +#ifndef __mips_soft_float
127         s.s     $f0, 0(t0)
128 +#else
129 +       REG_S   v0, 0(t0)
130 +#endif
131         b       epilogue
132  
133  retdouble:     
134         bne     t2, FFI_TYPE_DOUBLE, noretval
135         jalr    t9
136         REG_L   t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
137 +#ifndef __mips_soft_float
138         s.d     $f0, 0(t0)
139 +#else
140 +       REG_S   v1, 4(t0)
141 +       REG_S   v0, 0(t0)
142 +#endif
143         b       epilogue
144         
145  noretval:      
146 @@ -261,9 +274,11 @@ $LCFI7:
147         li      $13, 1          # FFI_O32
148         bne     $16, $13, 1f    # Skip fp save if FFI_O32_SOFT_FLOAT
149         
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)
154 +#endif
155  1:     
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:
159         li      $13, 1          # FFI_O32
160         bne     $16, $13, 1f    # Skip fp restore if FFI_O32_SOFT_FLOAT
161  
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
170 +#endif
171  1:     
172         REG_L   $3, V1_OFF2($fp)
173         REG_L   $2, V0_OFF2($fp)
174 -- 
175 2.6.4
176