~ubuntu-branches/debian/sid/gcc-4.8/sid

« back to all changes in this revision

Viewing changes to .svn/pristine/d6/d638bb117ac43ab15aa4cb8e1c0ad5ca7da15e4f.svn-base

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-12-19 19:48:34 UTC
  • Revision ID: package-import@ubuntu.com-20141219194834-4dz1q7rrn5pad823
Tags: 4.8.4-1
* GCC 4.8.4 release.
  - Fix PR target/61407 (darwin), PR middle-end/58624 (ice),
    PR sanitizer/64265 (wrong code).
* Require recent binutils to pass go test failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--- a/src/libffi/configure.ac
 
2
+++ b/src/libffi/configure.ac
 
3
@@ -65,6 +65,7 @@
 
4
 AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
 
5
 
 
6
 TARGETDIR="unknown"
 
7
+HAVE_LONG_DOUBLE_VARIANT=0
 
8
 case "$host" in
 
9
   aarch64*-*-*)
 
10
        TARGET=AARCH64; TARGETDIR=aarch64
 
11
@@ -162,6 +163,7 @@
 
12
 
 
13
   powerpc*-*-linux* | powerpc-*-sysv*)
 
14
        TARGET=POWERPC; TARGETDIR=powerpc
 
15
+       HAVE_LONG_DOUBLE_VARIANT=1
 
16
        ;;
 
17
   powerpc-*-amigaos*)
 
18
        TARGET=POWERPC; TARGETDIR=powerpc
 
19
@@ -177,6 +179,7 @@
 
20
        ;;
 
21
   powerpc-*-freebsd* | powerpc-*-openbsd*)
 
22
        TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
 
23
+       HAVE_LONG_DOUBLE_VARIANT=1
 
24
        ;;
 
25
   powerpc64-*-freebsd*)
 
26
        TARGET=POWERPC; TARGETDIR=powerpc
 
27
@@ -273,14 +276,20 @@
 
28
 # Also AC_SUBST this variable for ffi.h.
 
29
 if test -z "$HAVE_LONG_DOUBLE"; then
 
30
   HAVE_LONG_DOUBLE=0
 
31
-  if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
 
32
-    if test $ac_cv_sizeof_long_double != 0; then
 
33
+  if test $ac_cv_sizeof_long_double != 0; then
 
34
+    if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
 
35
+      AC_DEFINE(HAVE_LONG_DOUBLE_VARIANT, 1, [Define if you support more than one size of the long double type])
 
36
       HAVE_LONG_DOUBLE=1
 
37
-      AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
 
38
+    else
 
39
+      if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
 
40
+        HAVE_LONG_DOUBLE=1
 
41
+        AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
 
42
+      fi
 
43
     fi
 
44
   fi
 
45
 fi
 
46
 AC_SUBST(HAVE_LONG_DOUBLE)
 
47
+AC_SUBST(HAVE_LONG_DOUBLE_VARIANT)
 
48
 
 
49
 AC_C_BIGENDIAN
 
50
 
 
51
--- a/src/libffi/Makefile.am
 
52
+++ b/src/libffi/Makefile.am
 
53
@@ -15,10 +15,12 @@
 
54
         src/ia64/unix.S src/mips/ffi.c src/mips/n32.S src/mips/o32.S   \
 
55
         src/mips/ffitarget.h src/m32r/ffi.c src/m32r/sysv.S            \
 
56
         src/m32r/ffitarget.h src/m68k/ffi.c src/m68k/sysv.S            \
 
57
-        src/m68k/ffitarget.h src/powerpc/ffi.c src/powerpc/sysv.S      \
 
58
-        src/powerpc/linux64.S src/powerpc/linux64_closure.S            \
 
59
-        src/powerpc/ppc_closure.S src/powerpc/asm.h                    \
 
60
-       src/powerpc/aix.S src/powerpc/darwin.S                          \
 
61
+        src/m68k/ffitarget.h                                           \
 
62
+       src/powerpc/ffi.c src/powerpc/ffi_powerpc.h                     \
 
63
+       src/powerpc/ffi_sysv.c src/powerpc/ffi_linux64.c                \
 
64
+       src/powerpc/sysv.S src/powerpc/linux64.S                        \
 
65
+       src/powerpc/linux64_closure.S src/powerpc/ppc_closure.S         \
 
66
+       src/powerpc/asm.h src/powerpc/aix.S src/powerpc/darwin.S        \
 
67
        src/powerpc/aix_closure.S src/powerpc/darwin_closure.S          \
 
68
        src/powerpc/ffi_darwin.c src/powerpc/ffitarget.h                \
 
69
        src/s390/ffi.c src/s390/sysv.S src/s390/ffitarget.h             \
 
70
@@ -179,7 +181,7 @@
 
71
 nodist_libffi_la_SOURCES += src/m68k/ffi.c src/m68k/sysv.S
 
72
 endif
 
73
 if POWERPC
 
74
-nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S
 
75
+nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/ffi_sysv.c src/powerpc/ffi_linux64.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S
 
76
 endif
 
77
 if POWERPC_AIX
 
78
 nodist_libffi_la_SOURCES += src/powerpc/ffi_darwin.c src/powerpc/aix.S src/powerpc/aix_closure.S
 
79
@@ -188,7 +190,7 @@
 
80
 nodist_libffi_la_SOURCES += src/powerpc/ffi_darwin.c src/powerpc/darwin.S src/powerpc/darwin_closure.S
 
81
 endif
 
82
 if POWERPC_FREEBSD
 
83
-nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S
 
84
+nodist_libffi_la_SOURCES += src/powerpc/ffi.c src/powerpc/ffi_sysv.c src/powerpc/sysv.S src/powerpc/ppc_closure.S
 
85
 endif
 
86
 if AARCH64
 
87
 nodist_libffi_la_SOURCES += src/aarch64/sysv.S src/aarch64/ffi.c
 
88
--- a/src/libffi/man/Makefile.in
 
89
+++ b/src/libffi/man/Makefile.in
 
90
@@ -111,6 +111,7 @@
 
91
 FGREP = @FGREP@
 
92
 GREP = @GREP@
 
93
 HAVE_LONG_DOUBLE = @HAVE_LONG_DOUBLE@
 
94
+HAVE_LONG_DOUBLE_VARIANT = @HAVE_LONG_DOUBLE_VARIANT@
 
95
 INSTALL = @INSTALL@
 
96
 INSTALL_DATA = @INSTALL_DATA@
 
97
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 
98
--- a/src/libffi/configure
 
99
+++ b/src/libffi/configure
 
100
@@ -613,6 +613,7 @@
 
101
 FFI_EXEC_TRAMPOLINE_TABLE
 
102
 FFI_EXEC_TRAMPOLINE_TABLE_FALSE
 
103
 FFI_EXEC_TRAMPOLINE_TABLE_TRUE
 
104
+HAVE_LONG_DOUBLE_VARIANT
 
105
 HAVE_LONG_DOUBLE
 
106
 ALLOCA
 
107
 TILE_FALSE
 
108
@@ -10906,7 +10907,7 @@
 
109
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
 
110
   lt_status=$lt_dlunknown
 
111
   cat > conftest.$ac_ext <<_LT_EOF
 
112
-#line 10909 "configure"
 
113
+#line 10910 "configure"
 
114
 #include "confdefs.h"
 
115
 
 
116
 #if HAVE_DLFCN_H
 
117
@@ -11012,7 +11013,7 @@
 
118
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
 
119
   lt_status=$lt_dlunknown
 
120
   cat > conftest.$ac_ext <<_LT_EOF
 
121
-#line 11015 "configure"
 
122
+#line 11016 "configure"
 
123
 #include "confdefs.h"
 
124
 
 
125
 #if HAVE_DLFCN_H
 
126
@@ -11449,6 +11450,7 @@
 
127
 
 
128
 
 
129
 TARGETDIR="unknown"
 
130
+HAVE_LONG_DOUBLE_VARIANT=0
 
131
 case "$host" in
 
132
   aarch64*-*-*)
 
133
        TARGET=AARCH64; TARGETDIR=aarch64
 
134
@@ -11546,6 +11548,7 @@
 
135
 
 
136
   powerpc*-*-linux* | powerpc-*-sysv*)
 
137
        TARGET=POWERPC; TARGETDIR=powerpc
 
138
+       HAVE_LONG_DOUBLE_VARIANT=1
 
139
        ;;
 
140
   powerpc-*-amigaos*)
 
141
        TARGET=POWERPC; TARGETDIR=powerpc
 
142
@@ -11561,6 +11564,7 @@
 
143
        ;;
 
144
   powerpc-*-freebsd* | powerpc-*-openbsd*)
 
145
        TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
 
146
+       HAVE_LONG_DOUBLE_VARIANT=1
 
147
        ;;
 
148
   powerpc64-*-freebsd*)
 
149
        TARGET=POWERPC; TARGETDIR=powerpc
 
150
@@ -12236,17 +12240,25 @@
 
151
 # Also AC_SUBST this variable for ffi.h.
 
152
 if test -z "$HAVE_LONG_DOUBLE"; then
 
153
   HAVE_LONG_DOUBLE=0
 
154
-  if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
 
155
-    if test $ac_cv_sizeof_long_double != 0; then
 
156
+  if test $ac_cv_sizeof_long_double != 0; then
 
157
+    if test $HAVE_LONG_DOUBLE_VARIANT != 0; then
 
158
+
 
159
+$as_echo "#define HAVE_LONG_DOUBLE_VARIANT 1" >>confdefs.h
 
160
+
 
161
       HAVE_LONG_DOUBLE=1
 
162
+    else
 
163
+      if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
 
164
+        HAVE_LONG_DOUBLE=1
 
165
 
 
166
 $as_echo "#define HAVE_LONG_DOUBLE 1" >>confdefs.h
 
167
 
 
168
+      fi
 
169
     fi
 
170
   fi
 
171
 fi
 
172
 
 
173
 
 
174
+
 
175
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
 
176
 $as_echo_n "checking whether byte ordering is bigendian... " >&6; }
 
177
 if test "${ac_cv_c_bigendian+set}" = set; then :
 
178
--- a/src/libffi/Makefile.in
 
179
+++ b/src/libffi/Makefile.in
 
180
@@ -48,10 +48,10 @@
 
181
 @IA64_TRUE@am__append_11 = src/ia64/ffi.c src/ia64/unix.S
 
182
 @M32R_TRUE@am__append_12 = src/m32r/sysv.S src/m32r/ffi.c
 
183
 @M68K_TRUE@am__append_13 = src/m68k/ffi.c src/m68k/sysv.S
 
184
-@POWERPC_TRUE@am__append_14 = src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S
 
185
+@POWERPC_TRUE@am__append_14 = src/powerpc/ffi.c src/powerpc/ffi_sysv.c src/powerpc/ffi_linux64.c src/powerpc/sysv.S src/powerpc/ppc_closure.S src/powerpc/linux64.S src/powerpc/linux64_closure.S
 
186
 @POWERPC_AIX_TRUE@am__append_15 = src/powerpc/ffi_darwin.c src/powerpc/aix.S src/powerpc/aix_closure.S
 
187
 @POWERPC_DARWIN_TRUE@am__append_16 = src/powerpc/ffi_darwin.c src/powerpc/darwin.S src/powerpc/darwin_closure.S
 
188
-@POWERPC_FREEBSD_TRUE@am__append_17 = src/powerpc/ffi.c src/powerpc/sysv.S src/powerpc/ppc_closure.S
 
189
+@POWERPC_FREEBSD_TRUE@am__append_17 = src/powerpc/ffi.c src/powerpc/ffi_sysv.c src/powerpc/sysv.S src/powerpc/ppc_closure.S
 
190
 @AARCH64_TRUE@am__append_18 = src/aarch64/sysv.S src/aarch64/ffi.c
 
191
 @ARM_TRUE@am__append_19 = src/arm/sysv.S src/arm/ffi.c
 
192
 @ARM_TRUE@@FFI_EXEC_TRAMPOLINE_TABLE_TRUE@am__append_20 = src/arm/trampoline.S
 
193
@@ -133,7 +133,9 @@
 
194
 @IA64_TRUE@am__objects_11 = src/ia64/ffi.lo src/ia64/unix.lo
 
195
 @M32R_TRUE@am__objects_12 = src/m32r/sysv.lo src/m32r/ffi.lo
 
196
 @M68K_TRUE@am__objects_13 = src/m68k/ffi.lo src/m68k/sysv.lo
 
197
-@POWERPC_TRUE@am__objects_14 = src/powerpc/ffi.lo src/powerpc/sysv.lo \
 
198
+@POWERPC_TRUE@am__objects_14 = src/powerpc/ffi.lo \
 
199
+@POWERPC_TRUE@ src/powerpc/ffi_sysv.lo \
 
200
+@POWERPC_TRUE@ src/powerpc/ffi_linux64.lo src/powerpc/sysv.lo \
 
201
 @POWERPC_TRUE@ src/powerpc/ppc_closure.lo \
 
202
 @POWERPC_TRUE@ src/powerpc/linux64.lo \
 
203
 @POWERPC_TRUE@ src/powerpc/linux64_closure.lo
 
204
@@ -144,6 +146,7 @@
 
205
 @POWERPC_DARWIN_TRUE@  src/powerpc/darwin.lo \
 
206
 @POWERPC_DARWIN_TRUE@  src/powerpc/darwin_closure.lo
 
207
 @POWERPC_FREEBSD_TRUE@am__objects_17 = src/powerpc/ffi.lo \
 
208
+@POWERPC_FREEBSD_TRUE@ src/powerpc/ffi_sysv.lo \
 
209
 @POWERPC_FREEBSD_TRUE@ src/powerpc/sysv.lo \
 
210
 @POWERPC_FREEBSD_TRUE@ src/powerpc/ppc_closure.lo
 
211
 @AARCH64_TRUE@am__objects_18 = src/aarch64/sysv.lo src/aarch64/ffi.lo
 
212
@@ -278,6 +281,7 @@
 
213
 FGREP = @FGREP@
 
214
 GREP = @GREP@
 
215
 HAVE_LONG_DOUBLE = @HAVE_LONG_DOUBLE@
 
216
+HAVE_LONG_DOUBLE_VARIANT = @HAVE_LONG_DOUBLE_VARIANT@
 
217
 INSTALL = @INSTALL@
 
218
 INSTALL_DATA = @INSTALL_DATA@
 
219
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 
220
@@ -387,10 +391,12 @@
 
221
         src/ia64/unix.S src/mips/ffi.c src/mips/n32.S src/mips/o32.S   \
 
222
         src/mips/ffitarget.h src/m32r/ffi.c src/m32r/sysv.S            \
 
223
         src/m32r/ffitarget.h src/m68k/ffi.c src/m68k/sysv.S            \
 
224
-        src/m68k/ffitarget.h src/powerpc/ffi.c src/powerpc/sysv.S      \
 
225
-        src/powerpc/linux64.S src/powerpc/linux64_closure.S            \
 
226
-        src/powerpc/ppc_closure.S src/powerpc/asm.h                    \
 
227
-       src/powerpc/aix.S src/powerpc/darwin.S                          \
 
228
+        src/m68k/ffitarget.h                                           \
 
229
+       src/powerpc/ffi.c src/powerpc/ffi_powerpc.h                     \
 
230
+       src/powerpc/ffi_sysv.c src/powerpc/ffi_linux64.c                \
 
231
+       src/powerpc/sysv.S src/powerpc/linux64.S                        \
 
232
+       src/powerpc/linux64_closure.S src/powerpc/ppc_closure.S         \
 
233
+       src/powerpc/asm.h src/powerpc/aix.S src/powerpc/darwin.S        \
 
234
        src/powerpc/aix_closure.S src/powerpc/darwin_closure.S          \
 
235
        src/powerpc/ffi_darwin.c src/powerpc/ffitarget.h                \
 
236
        src/s390/ffi.c src/s390/sysv.S src/s390/ffitarget.h             \
 
237
@@ -711,6 +717,10 @@
 
238
        @: > src/powerpc/$(DEPDIR)/$(am__dirstamp)
 
239
 src/powerpc/ffi.lo: src/powerpc/$(am__dirstamp) \
 
240
        src/powerpc/$(DEPDIR)/$(am__dirstamp)
 
241
+src/powerpc/ffi_sysv.lo: src/powerpc/$(am__dirstamp) \
 
242
+       src/powerpc/$(DEPDIR)/$(am__dirstamp)
 
243
+src/powerpc/ffi_linux64.lo: src/powerpc/$(am__dirstamp) \
 
244
+       src/powerpc/$(DEPDIR)/$(am__dirstamp)
 
245
 src/powerpc/sysv.lo: src/powerpc/$(am__dirstamp) \
 
246
        src/powerpc/$(DEPDIR)/$(am__dirstamp)
 
247
 src/powerpc/ppc_closure.lo: src/powerpc/$(am__dirstamp) \
 
248
@@ -912,6 +922,10 @@
 
249
        -rm -f src/powerpc/ffi.lo
 
250
        -rm -f src/powerpc/ffi_darwin.$(OBJEXT)
 
251
        -rm -f src/powerpc/ffi_darwin.lo
 
252
+       -rm -f src/powerpc/ffi_linux64.$(OBJEXT)
 
253
+       -rm -f src/powerpc/ffi_linux64.lo
 
254
+       -rm -f src/powerpc/ffi_sysv.$(OBJEXT)
 
255
+       -rm -f src/powerpc/ffi_sysv.lo
 
256
        -rm -f src/powerpc/linux64.$(OBJEXT)
 
257
        -rm -f src/powerpc/linux64.lo
 
258
        -rm -f src/powerpc/linux64_closure.$(OBJEXT)
 
259
@@ -1009,6 +1023,8 @@
 
260
 @AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/darwin_closure.Plo@am__quote@
 
261
 @AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/ffi.Plo@am__quote@
 
262
 @AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/ffi_darwin.Plo@am__quote@
 
263
+@AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/ffi_linux64.Plo@am__quote@
 
264
+@AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/ffi_sysv.Plo@am__quote@
 
265
 @AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/linux64.Plo@am__quote@
 
266
 @AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/linux64_closure.Plo@am__quote@
 
267
 @AMDEP_TRUE@@am__include@ @am__quote@src/powerpc/$(DEPDIR)/ppc_closure.Plo@am__quote@
 
268
--- a/src/libffi/include/ffi.h.in
 
269
+++ b/src/libffi/include/ffi.h.in
 
270
@@ -207,6 +207,11 @@
 
271
 #endif
 
272
 } ffi_cif;
 
273
 
 
274
+#if HAVE_LONG_DOUBLE_VARIANT
 
275
+/* Used to adjust size/alignment of ffi types.  */
 
276
+void ffi_prep_types (ffi_abi abi);
 
277
+# endif
 
278
+
 
279
 /* Used internally, but overridden by some architectures */
 
280
 ffi_status ffi_prep_cif_core(ffi_cif *cif,
 
281
                             ffi_abi abi,
 
282
--- a/src/libffi/include/Makefile.in
 
283
+++ b/src/libffi/include/Makefile.in
 
284
@@ -113,6 +113,7 @@
 
285
 FGREP = @FGREP@
 
286
 GREP = @GREP@
 
287
 HAVE_LONG_DOUBLE = @HAVE_LONG_DOUBLE@
 
288
+HAVE_LONG_DOUBLE_VARIANT = @HAVE_LONG_DOUBLE_VARIANT@
 
289
 INSTALL = @INSTALL@
 
290
 INSTALL_DATA = @INSTALL_DATA@
 
291
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 
292
--- a/src/libffi/fficonfig.h.in
 
293
+++ b/src/libffi/fficonfig.h.in
 
294
@@ -73,6 +73,9 @@
 
295
 /* Define if you have the long double type and it is bigger than a double */
 
296
 #undef HAVE_LONG_DOUBLE
 
297
 
 
298
+/* Define if you support more than one size of the long double type */
 
299
+#undef HAVE_LONG_DOUBLE_VARIANT
 
300
+
 
301
 /* Define to 1 if you have the `memcpy' function. */
 
302
 #undef HAVE_MEMCPY
 
303
 
 
304
--- a/src/libffi/src/prep_cif.c
 
305
+++ b/src/libffi/src/prep_cif.c
 
306
@@ -126,6 +126,10 @@
 
307
 
 
308
   cif->flags = 0;
 
309
 
 
310
+#if HAVE_LONG_DOUBLE_VARIANT
 
311
+  ffi_prep_types (abi);
 
312
+#endif
 
313
+
 
314
   /* Initialize the return type if necessary */
 
315
   if ((cif->rtype->size == 0) && (initialize_aggregate(cif->rtype) != FFI_OK))
 
316
     return FFI_BAD_TYPEDEF;
 
317
--- a/src/libffi/src/powerpc/ffi.c
 
318
+++ b/src/libffi/src/powerpc/ffi.c
 
319
@@ -1,5 +1,6 @@
 
320
 /* -----------------------------------------------------------------------
 
321
-   ffi.c - Copyright (C) 2011 Anthony Green
 
322
+   ffi.c - Copyright (C) 2013 IBM
 
323
+           Copyright (C) 2011 Anthony Green
 
324
            Copyright (C) 2011 Kyle Moffett
 
325
            Copyright (C) 2008 Red Hat, Inc
 
326
            Copyright (C) 2007, 2008 Free Software Foundation, Inc
 
327
@@ -27,1112 +28,60 @@
 
328
    OTHER DEALINGS IN THE SOFTWARE.
 
329
    ----------------------------------------------------------------------- */
 
330
 
 
331
-#include <ffi.h>
 
332
-#include <ffi_common.h>
 
333
+#include "ffi.h"
 
334
+#include "ffi_common.h"
 
335
+#include "ffi_powerpc.h"
 
336
 
 
337
-#include <stdlib.h>
 
338
-#include <stdio.h>
 
339
-
 
340
-
 
341
-extern void ffi_closure_SYSV (void);
 
342
-extern void FFI_HIDDEN ffi_closure_LINUX64 (void);
 
343
-
 
344
-enum {
 
345
-  /* The assembly depends on these exact flags.  */
 
346
-  FLAG_RETURNS_SMST    = 1 << (31-31), /* Used for FFI_SYSV small structs.  */
 
347
-  FLAG_RETURNS_NOTHING  = 1 << (31-30), /* These go in cr7 */
 
348
-#ifndef __NO_FPRS__
 
349
-  FLAG_RETURNS_FP       = 1 << (31-29),
 
350
-#endif
 
351
-  FLAG_RETURNS_64BITS   = 1 << (31-28),
 
352
-
 
353
-  FLAG_RETURNS_128BITS  = 1 << (31-27), /* cr6  */
 
354
-
 
355
-  FLAG_ARG_NEEDS_COPY   = 1 << (31- 7),
 
356
-  FLAG_ARG_NEEDS_PSAVE  = FLAG_ARG_NEEDS_COPY, /* Used by ELFv2 */
 
357
-#ifndef __NO_FPRS__
 
358
-  FLAG_FP_ARGUMENTS     = 1 << (31- 6), /* cr1.eq; specified by ABI */
 
359
-#endif
 
360
-  FLAG_4_GPR_ARGUMENTS  = 1 << (31- 5),
 
361
-  FLAG_RETVAL_REFERENCE = 1 << (31- 4)
 
362
-};
 
363
-
 
364
-/* About the SYSV ABI.  */
 
365
-#define ASM_NEEDS_REGISTERS 4
 
366
-#define NUM_GPR_ARG_REGISTERS 8
 
367
-#ifndef __NO_FPRS__
 
368
-# define NUM_FPR_ARG_REGISTERS 8
 
369
-#endif
 
370
-
 
371
-/* ffi_prep_args_SYSV is called by the assembly routine once stack space
 
372
-   has been allocated for the function's arguments.
 
373
-
 
374
-   The stack layout we want looks like this:
 
375
-
 
376
-   |   Return address from ffi_call_SYSV 4bytes        |       higher addresses
 
377
-   |--------------------------------------------|
 
378
-   |   Previous backchain pointer      4       |       stack pointer here
 
379
-   |--------------------------------------------|<+ <<<        on entry to
 
380
-   |   Saved r28-r31                   4*4     | |     ffi_call_SYSV
 
381
-   |--------------------------------------------| |
 
382
-   |   GPR registers r3-r10            8*4     | |     ffi_call_SYSV
 
383
-   |--------------------------------------------| |
 
384
-   |   FPR registers f1-f8 (optional)  8*8     | |
 
385
-   |--------------------------------------------| |    stack   |
 
386
-   |   Space for copied structures             | |     grows   |
 
387
-   |--------------------------------------------| |    down    V
 
388
-   |   Parameters that didn't fit in registers  | |
 
389
-   |--------------------------------------------| |    lower addresses
 
390
-   |   Space for callee's LR           4       | |
 
391
-   |--------------------------------------------| |    stack pointer here
 
392
-   |   Current backchain pointer       4       |-/     during
 
393
-   |--------------------------------------------|   <<<        ffi_call_SYSV
 
394
-
 
395
-*/
 
396
-
 
397
-void
 
398
-ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack)
 
399
+#if HAVE_LONG_DOUBLE_VARIANT
 
400
+/* Adjust ffi_type_longdouble.  */
 
401
+void FFI_HIDDEN
 
402
+ffi_prep_types (ffi_abi abi)
 
403
 {
 
404
-  const unsigned bytes = ecif->cif->bytes;
 
405
-  const unsigned flags = ecif->cif->flags;
 
406
-
 
407
-  typedef union {
 
408
-    char *c;
 
409
-    unsigned *u;
 
410
-    long long *ll;
 
411
-    float *f;
 
412
-    double *d;
 
413
-  } valp;
 
414
-
 
415
-  /* 'stacktop' points at the previous backchain pointer.  */
 
416
-  valp stacktop;
 
417
-
 
418
-  /* 'gpr_base' points at the space for gpr3, and grows upwards as
 
419
-     we use GPR registers.  */
 
420
-  valp gpr_base;
 
421
-  int intarg_count;
 
422
-
 
423
-#ifndef __NO_FPRS__
 
424
-  /* 'fpr_base' points at the space for fpr1, and grows upwards as
 
425
-     we use FPR registers.  */
 
426
-  valp fpr_base;
 
427
-  int fparg_count;
 
428
-#endif
 
429
-
 
430
-  /* 'copy_space' grows down as we put structures in it.  It should
 
431
-     stay 16-byte aligned.  */
 
432
-  valp copy_space;
 
433
-
 
434
-  /* 'next_arg' grows up as we put parameters in it.  */
 
435
-  valp next_arg;
 
436
-
 
437
-  int i;
 
438
-  ffi_type **ptr;
 
439
-#ifndef __NO_FPRS__
 
440
-  double double_tmp;
 
441
-#endif
 
442
-  union {
 
443
-    void **v;
 
444
-    char **c;
 
445
-    signed char **sc;
 
446
-    unsigned char **uc;
 
447
-    signed short **ss;
 
448
-    unsigned short **us;
 
449
-    unsigned int **ui;
 
450
-    long long **ll;
 
451
-    float **f;
 
452
-    double **d;
 
453
-  } p_argv;
 
454
-  size_t struct_copy_size;
 
455
-  unsigned gprvalue;
 
456
-
 
457
-  stacktop.c = (char *) stack + bytes;
 
458
-  gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS;
 
459
-  intarg_count = 0;
 
460
-#ifndef __NO_FPRS__
 
461
-  fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS;
 
462
-  fparg_count = 0;
 
463
-  copy_space.c = ((flags & FLAG_FP_ARGUMENTS) ? fpr_base.c : gpr_base.c);
 
464
-#else
 
465
-  copy_space.c = gpr_base.c;
 
466
-#endif
 
467
-  next_arg.u = stack + 2;
 
468
-
 
469
-  /* Check that everything starts aligned properly.  */
 
470
-  FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0);
 
471
-  FFI_ASSERT (((unsigned long) copy_space.c & 0xF) == 0);
 
472
-  FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0);
 
473
-  FFI_ASSERT ((bytes & 0xF) == 0);
 
474
-  FFI_ASSERT (copy_space.c >= next_arg.c);
 
475
-
 
476
-  /* Deal with return values that are actually pass-by-reference.  */
 
477
-  if (flags & FLAG_RETVAL_REFERENCE)
 
478
-    {
 
479
-      *gpr_base.u++ = (unsigned long) (char *) ecif->rvalue;
 
480
-      intarg_count++;
 
481
-    }
 
482
-
 
483
-  /* Now for the arguments.  */
 
484
-  p_argv.v = ecif->avalue;
 
485
-  for (ptr = ecif->cif->arg_types, i = ecif->cif->nargs;
 
486
-       i > 0;
 
487
-       i--, ptr++, p_argv.v++)
 
488
-    {
 
489
-      unsigned short typenum = (*ptr)->type;
 
490
-
 
491
-      /* We may need to handle some values depending on ABI */
 
492
-      if (ecif->cif->abi == FFI_LINUX_SOFT_FLOAT) {
 
493
-               if (typenum == FFI_TYPE_FLOAT)
 
494
-                       typenum = FFI_TYPE_UINT32;
 
495
-               if (typenum == FFI_TYPE_DOUBLE)
 
496
-                       typenum = FFI_TYPE_UINT64;
 
497
-               if (typenum == FFI_TYPE_LONGDOUBLE)
 
498
-                       typenum = FFI_TYPE_UINT128;
 
499
-      } else if (ecif->cif->abi != FFI_LINUX) {
 
500
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
501
-               if (typenum == FFI_TYPE_LONGDOUBLE)
 
502
-                       typenum = FFI_TYPE_STRUCT;
 
503
-#endif
 
504
-      }
 
505
-
 
506
-      /* Now test the translated value */
 
507
-      switch (typenum) {
 
508
-#ifndef __NO_FPRS__
 
509
-       case FFI_TYPE_FLOAT:
 
510
-         /* With FFI_LINUX_SOFT_FLOAT floats are handled like UINT32.  */
 
511
-         double_tmp = **p_argv.f;
 
512
-         if (fparg_count >= NUM_FPR_ARG_REGISTERS)
 
513
-           {
 
514
-             *next_arg.f = (float) double_tmp;
 
515
-             next_arg.u += 1;
 
516
-             intarg_count++;
 
517
-           }
 
518
-         else
 
519
-           *fpr_base.d++ = double_tmp;
 
520
-         fparg_count++;
 
521
-         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
522
-         break;
 
523
-
 
524
-       case FFI_TYPE_DOUBLE:
 
525
-         /* With FFI_LINUX_SOFT_FLOAT doubles are handled like UINT64.  */
 
526
-         double_tmp = **p_argv.d;
 
527
-
 
528
-         if (fparg_count >= NUM_FPR_ARG_REGISTERS)
 
529
-           {
 
530
-             if (intarg_count >= NUM_GPR_ARG_REGISTERS
 
531
-                 && intarg_count % 2 != 0)
 
532
-               {
 
533
-                 intarg_count++;
 
534
-                 next_arg.u++;
 
535
-               }
 
536
-             *next_arg.d = double_tmp;
 
537
-             next_arg.u += 2;
 
538
-           }
 
539
-         else
 
540
-           *fpr_base.d++ = double_tmp;
 
541
-         fparg_count++;
 
542
-         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
543
-         break;
 
544
-
 
545
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
546
-       case FFI_TYPE_LONGDOUBLE:
 
547
-             double_tmp = (*p_argv.d)[0];
 
548
-
 
549
-             if (fparg_count >= NUM_FPR_ARG_REGISTERS - 1)
 
550
-               {
 
551
-                 if (intarg_count >= NUM_GPR_ARG_REGISTERS
 
552
-                     && intarg_count % 2 != 0)
 
553
-                   {
 
554
-                     intarg_count++;
 
555
-                     next_arg.u++;
 
556
-                   }
 
557
-                 *next_arg.d = double_tmp;
 
558
-                 next_arg.u += 2;
 
559
-                 double_tmp = (*p_argv.d)[1];
 
560
-                 *next_arg.d = double_tmp;
 
561
-                 next_arg.u += 2;
 
562
-               }
 
563
-             else
 
564
-               {
 
565
-                 *fpr_base.d++ = double_tmp;
 
566
-                 double_tmp = (*p_argv.d)[1];
 
567
-                 *fpr_base.d++ = double_tmp;
 
568
-               }
 
569
-
 
570
-             fparg_count += 2;
 
571
-             FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
572
-         break;
 
573
-#endif
 
574
-#endif /* have FPRs */
 
575
-
 
576
-       /*
 
577
-        * The soft float ABI for long doubles works like this, a long double
 
578
-        * is passed in four consecutive GPRs if available.  A maximum of 2
 
579
-        * long doubles can be passed in gprs.  If we do not have 4 GPRs
 
580
-        * left, the long double is passed on the stack, 4-byte aligned.
 
581
-        */
 
582
-       case FFI_TYPE_UINT128: {
 
583
-               unsigned int int_tmp = (*p_argv.ui)[0];
 
584
-               unsigned int ii;
 
585
-               if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3) {
 
586
-                       if (intarg_count < NUM_GPR_ARG_REGISTERS)
 
587
-                               intarg_count += NUM_GPR_ARG_REGISTERS - intarg_count;
 
588
-                       *(next_arg.u++) = int_tmp;
 
589
-                       for (ii = 1; ii < 4; ii++) {
 
590
-                               int_tmp = (*p_argv.ui)[ii];
 
591
-                               *(next_arg.u++) = int_tmp;
 
592
-                       }
 
593
-               } else {
 
594
-                       *(gpr_base.u++) = int_tmp;
 
595
-                       for (ii = 1; ii < 4; ii++) {
 
596
-                               int_tmp = (*p_argv.ui)[ii];
 
597
-                               *(gpr_base.u++) = int_tmp;
 
598
-                       }
 
599
-               }
 
600
-               intarg_count += 4;
 
601
-               break;
 
602
-       }
 
603
-
 
604
-       case FFI_TYPE_UINT64:
 
605
-       case FFI_TYPE_SINT64:
 
606
-         if (intarg_count == NUM_GPR_ARG_REGISTERS-1)
 
607
-           intarg_count++;
 
608
-         if (intarg_count >= NUM_GPR_ARG_REGISTERS)
 
609
-           {
 
610
-             if (intarg_count % 2 != 0)
 
611
-               {
 
612
-                 intarg_count++;
 
613
-                 next_arg.u++;
 
614
-               }
 
615
-             *next_arg.ll = **p_argv.ll;
 
616
-             next_arg.u += 2;
 
617
-           }
 
618
-         else
 
619
-           {
 
620
-             /* whoops: abi states only certain register pairs
 
621
-              * can be used for passing long long int
 
622
-              * specifically (r3,r4), (r5,r6), (r7,r8),
 
623
-              * (r9,r10) and if next arg is long long but
 
624
-              * not correct starting register of pair then skip
 
625
-              * until the proper starting register
 
626
-              */
 
627
-             if (intarg_count % 2 != 0)
 
628
-               {
 
629
-                 intarg_count ++;
 
630
-                 gpr_base.u++;
 
631
-               }
 
632
-             *gpr_base.ll++ = **p_argv.ll;
 
633
-           }
 
634
-         intarg_count += 2;
 
635
-         break;
 
636
-
 
637
-       case FFI_TYPE_STRUCT:
 
638
-         struct_copy_size = ((*ptr)->size + 15) & ~0xF;
 
639
-         copy_space.c -= struct_copy_size;
 
640
-         memcpy (copy_space.c, *p_argv.c, (*ptr)->size);
 
641
-
 
642
-         gprvalue = (unsigned long) copy_space.c;
 
643
-
 
644
-         FFI_ASSERT (copy_space.c > next_arg.c);
 
645
-         FFI_ASSERT (flags & FLAG_ARG_NEEDS_COPY);
 
646
-         goto putgpr;
 
647
-
 
648
-       case FFI_TYPE_UINT8:
 
649
-         gprvalue = **p_argv.uc;
 
650
-         goto putgpr;
 
651
-       case FFI_TYPE_SINT8:
 
652
-         gprvalue = **p_argv.sc;
 
653
-         goto putgpr;
 
654
-       case FFI_TYPE_UINT16:
 
655
-         gprvalue = **p_argv.us;
 
656
-         goto putgpr;
 
657
-       case FFI_TYPE_SINT16:
 
658
-         gprvalue = **p_argv.ss;
 
659
-         goto putgpr;
 
660
-
 
661
-       case FFI_TYPE_INT:
 
662
-       case FFI_TYPE_UINT32:
 
663
-       case FFI_TYPE_SINT32:
 
664
-       case FFI_TYPE_POINTER:
 
665
-
 
666
-         gprvalue = **p_argv.ui;
 
667
-
 
668
-       putgpr:
 
669
-         if (intarg_count >= NUM_GPR_ARG_REGISTERS)
 
670
-           *next_arg.u++ = gprvalue;
 
671
-         else
 
672
-           *gpr_base.u++ = gprvalue;
 
673
-         intarg_count++;
 
674
-         break;
 
675
-       }
 
676
-    }
 
677
-
 
678
-  /* Check that we didn't overrun the stack...  */
 
679
-  FFI_ASSERT (copy_space.c >= next_arg.c);
 
680
-  FFI_ASSERT (gpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS);
 
681
-  /* The assert below is testing that the number of integer arguments agrees
 
682
-     with the number found in ffi_prep_cif_machdep().  However, intarg_count
 
683
-     is incremented whenever we place an FP arg on the stack, so account for
 
684
-     that before our assert test.  */
 
685
-#ifndef __NO_FPRS__
 
686
-  if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
687
-    intarg_count -= fparg_count - NUM_FPR_ARG_REGISTERS;
 
688
-  FFI_ASSERT (fpr_base.u
 
689
-             <= stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
 
690
-#endif
 
691
-  FFI_ASSERT (flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
 
692
+# if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
693
+#  ifdef POWERPC64
 
694
+  ffi_prep_types_linux64 (abi);
 
695
+#  else
 
696
+  ffi_prep_types_sysv (abi);
 
697
+#  endif
 
698
+# endif
 
699
 }
 
700
-
 
701
-/* About the LINUX64 ABI.  */
 
702
-enum {
 
703
-  NUM_GPR_ARG_REGISTERS64 = 8,
 
704
-  NUM_FPR_ARG_REGISTERS64 = 13
 
705
-};
 
706
-enum { ASM_NEEDS_REGISTERS64 = 4 };
 
707
-
 
708
-#if _CALL_ELF == 2
 
709
-static unsigned int
 
710
-discover_homogeneous_aggregate (const ffi_type *t, unsigned int *elnum)
 
711
-{
 
712
-  switch (t->type)
 
713
-    {
 
714
-    case FFI_TYPE_FLOAT:
 
715
-    case FFI_TYPE_DOUBLE:
 
716
-      *elnum = 1;
 
717
-      return (int) t->type;
 
718
-
 
719
-    case FFI_TYPE_STRUCT:;
 
720
-      {
 
721
-       unsigned int base_elt = 0, total_elnum = 0;
 
722
-       ffi_type **el = t->elements;
 
723
-       while (*el)
 
724
-         {
 
725
-           unsigned int el_elt, el_elnum = 0;
 
726
-           el_elt = discover_homogeneous_aggregate (*el, &el_elnum);
 
727
-           if (el_elt == 0
 
728
-               || (base_elt && base_elt != el_elt))
 
729
-             return 0;
 
730
-           base_elt = el_elt;
 
731
-           total_elnum += el_elnum;
 
732
-           if (total_elnum > 8)
 
733
-             return 0;
 
734
-           el++;
 
735
-         }
 
736
-       *elnum = total_elnum;
 
737
-       return base_elt;
 
738
-      }
 
739
-
 
740
-    default:
 
741
-      return 0;
 
742
-    }
 
743
-}
 
744
 #endif
 
745
 
 
746
-
 
747
-/* ffi_prep_args64 is called by the assembly routine once stack space
 
748
-   has been allocated for the function's arguments.
 
749
-
 
750
-   The stack layout we want looks like this:
 
751
-
 
752
-   |   Ret addr from ffi_call_LINUX64  8bytes  |       higher addresses
 
753
-   |--------------------------------------------|
 
754
-   |   CR save area                    8bytes  |
 
755
-   |--------------------------------------------|
 
756
-   |   Previous backchain pointer      8       |       stack pointer here
 
757
-   |--------------------------------------------|<+ <<<        on entry to
 
758
-   |   Saved r28-r31                   4*8     | |     ffi_call_LINUX64
 
759
-   |--------------------------------------------| |
 
760
-   |   GPR registers r3-r10            8*8     | |
 
761
-   |--------------------------------------------| |
 
762
-   |   FPR registers f1-f13 (optional) 13*8    | |
 
763
-   |--------------------------------------------| |
 
764
-   |   Parameter save area                     | |
 
765
-   |--------------------------------------------| |
 
766
-   |   TOC save area                   8       | |
 
767
-   |--------------------------------------------| |    stack   |
 
768
-   |   Linker doubleword               8       | |     grows   |
 
769
-   |--------------------------------------------| |    down    V
 
770
-   |   Compiler doubleword             8       | |
 
771
-   |--------------------------------------------| |    lower addresses
 
772
-   |   Space for callee's LR           8       | |
 
773
-   |--------------------------------------------| |
 
774
-   |   CR save area                    8       | |
 
775
-   |--------------------------------------------| |    stack pointer here
 
776
-   |   Current backchain pointer       8       |-/     during
 
777
-   |--------------------------------------------|   <<<        ffi_call_LINUX64
 
778
-
 
779
-*/
 
780
-
 
781
-void FFI_HIDDEN
 
782
-ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
 
783
-{
 
784
-  const unsigned long bytes = ecif->cif->bytes;
 
785
-  const unsigned long flags = ecif->cif->flags;
 
786
-
 
787
-  typedef union {
 
788
-    char *c;
 
789
-    unsigned long *ul;
 
790
-    float *f;
 
791
-    double *d;
 
792
-    size_t p;
 
793
-  } valp;
 
794
-
 
795
-  /* 'stacktop' points at the previous backchain pointer.  */
 
796
-  valp stacktop;
 
797
-
 
798
-  /* 'next_arg' points at the space for gpr3, and grows upwards as
 
799
-     we use GPR registers, then continues at rest.  */
 
800
-  valp gpr_base;
 
801
-  valp gpr_end;
 
802
-  valp rest;
 
803
-  valp next_arg;
 
804
-
 
805
-  /* 'fpr_base' points at the space for fpr3, and grows upwards as
 
806
-     we use FPR registers.  */
 
807
-  valp fpr_base;
 
808
-  unsigned int fparg_count;
 
809
-
 
810
-  unsigned int i, words, nargs, nfixedargs;
 
811
-  ffi_type **ptr;
 
812
-  double double_tmp;
 
813
-  union {
 
814
-    void **v;
 
815
-    char **c;
 
816
-    signed char **sc;
 
817
-    unsigned char **uc;
 
818
-    signed short **ss;
 
819
-    unsigned short **us;
 
820
-    signed int **si;
 
821
-    unsigned int **ui;
 
822
-    unsigned long **ul;
 
823
-    float **f;
 
824
-    double **d;
 
825
-  } p_argv;
 
826
-  unsigned long gprvalue;
 
827
-#ifdef __STRUCT_PARM_ALIGN__
 
828
-  unsigned long align;
 
829
-#endif
 
830
-
 
831
-  stacktop.c = (char *) stack + bytes;
 
832
-  gpr_base.ul = stacktop.ul - ASM_NEEDS_REGISTERS64 - NUM_GPR_ARG_REGISTERS64;
 
833
-  gpr_end.ul = gpr_base.ul + NUM_GPR_ARG_REGISTERS64;
 
834
-#if _CALL_ELF == 2
 
835
-  rest.ul = stack + 4 + NUM_GPR_ARG_REGISTERS64;
 
836
-#else
 
837
-  rest.ul = stack + 6 + NUM_GPR_ARG_REGISTERS64;
 
838
-#endif
 
839
-  fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS64;
 
840
-  fparg_count = 0;
 
841
-  next_arg.ul = gpr_base.ul;
 
842
-
 
843
-  /* Check that everything starts aligned properly.  */
 
844
-  FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0);
 
845
-  FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0);
 
846
-  FFI_ASSERT ((bytes & 0xF) == 0);
 
847
-
 
848
-  /* Deal with return values that are actually pass-by-reference.  */
 
849
-  if (flags & FLAG_RETVAL_REFERENCE)
 
850
-    *next_arg.ul++ = (unsigned long) (char *) ecif->rvalue;
 
851
-
 
852
-  /* Now for the arguments.  */
 
853
-  p_argv.v = ecif->avalue;
 
854
-  nargs = ecif->cif->nargs;
 
855
-  nfixedargs = ecif->cif->nfixedargs;
 
856
-  for (ptr = ecif->cif->arg_types, i = 0;
 
857
-       i < nargs;
 
858
-       i++, ptr++, p_argv.v++)
 
859
-    {
 
860
-      unsigned int elt, elnum;
 
861
-
 
862
-      switch ((*ptr)->type)
 
863
-       {
 
864
-       case FFI_TYPE_FLOAT:
 
865
-         double_tmp = **p_argv.f;
 
866
-         if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
867
-           *fpr_base.d++ = double_tmp;
 
868
-         else
 
869
-           *next_arg.f = (float) double_tmp;
 
870
-         if (++next_arg.ul == gpr_end.ul)
 
871
-           next_arg.ul = rest.ul;
 
872
-         fparg_count++;
 
873
-         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
874
-         break;
 
875
-
 
876
-       case FFI_TYPE_DOUBLE:
 
877
-         double_tmp = **p_argv.d;
 
878
-         if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
879
-           *fpr_base.d++ = double_tmp;
 
880
-         else
 
881
-           *next_arg.d = double_tmp;
 
882
-         if (++next_arg.ul == gpr_end.ul)
 
883
-           next_arg.ul = rest.ul;
 
884
-         fparg_count++;
 
885
-         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
886
-         break;
 
887
-
 
888
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
889
-       case FFI_TYPE_LONGDOUBLE:
 
890
-         double_tmp = (*p_argv.d)[0];
 
891
-         if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
892
-           *fpr_base.d++ = double_tmp;
 
893
-         else
 
894
-           *next_arg.d = double_tmp;
 
895
-         if (++next_arg.ul == gpr_end.ul)
 
896
-           next_arg.ul = rest.ul;
 
897
-         fparg_count++;
 
898
-         double_tmp = (*p_argv.d)[1];
 
899
-         if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
900
-           *fpr_base.d++ = double_tmp;
 
901
-         else
 
902
-           *next_arg.d = double_tmp;
 
903
-         if (++next_arg.ul == gpr_end.ul)
 
904
-           next_arg.ul = rest.ul;
 
905
-         fparg_count++;
 
906
-         FFI_ASSERT (__LDBL_MANT_DIG__ == 106);
 
907
-         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
908
-         break;
 
909
-#endif
 
910
-
 
911
-       case FFI_TYPE_STRUCT:
 
912
-#ifdef __STRUCT_PARM_ALIGN__
 
913
-         align = (*ptr)->alignment;
 
914
-         if (align > __STRUCT_PARM_ALIGN__)
 
915
-           align = __STRUCT_PARM_ALIGN__;
 
916
-         if (align > 1)
 
917
-           next_arg.p = ALIGN (next_arg.p, align);
 
918
-#endif
 
919
-         elt = 0;
 
920
-#if _CALL_ELF == 2
 
921
-         elt = discover_homogeneous_aggregate (*ptr, &elnum);
 
922
-#endif
 
923
-         if (elt)
 
924
-           {
 
925
-             union {
 
926
-               void *v;
 
927
-               float *f;
 
928
-               double *d;
 
929
-             } arg;
 
930
-
 
931
-             arg.v = *p_argv.v;
 
932
-             if (elt == FFI_TYPE_FLOAT)
 
933
-               {
 
934
-                 do
 
935
-                   {
 
936
-                     double_tmp = *arg.f++;
 
937
-                     if (fparg_count < NUM_FPR_ARG_REGISTERS64
 
938
-                         && i < nfixedargs)
 
939
-                       *fpr_base.d++ = double_tmp;
 
940
-                     else
 
941
-                       *next_arg.f = (float) double_tmp;
 
942
-                     if (++next_arg.f == gpr_end.f)
 
943
-                       next_arg.f = rest.f;
 
944
-                     fparg_count++;
 
945
-                   }
 
946
-                 while (--elnum != 0);
 
947
-                 if ((next_arg.p & 3) != 0)
 
948
-                   {
 
949
-                     if (++next_arg.f == gpr_end.f)
 
950
-                       next_arg.f = rest.f;
 
951
-                   }
 
952
-               }
 
953
-             else
 
954
-               do
 
955
-                 {
 
956
-                   double_tmp = *arg.d++;
 
957
-                   if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
958
-                     *fpr_base.d++ = double_tmp;
 
959
-                   else
 
960
-                     *next_arg.d = double_tmp;
 
961
-                   if (++next_arg.d == gpr_end.d)
 
962
-                     next_arg.d = rest.d;
 
963
-                   fparg_count++;
 
964
-                 }
 
965
-               while (--elnum != 0);
 
966
-           }
 
967
-         else
 
968
-           {
 
969
-             words = ((*ptr)->size + 7) / 8;
 
970
-             if (next_arg.ul >= gpr_base.ul && next_arg.ul + words > gpr_end.ul)
 
971
-               {
 
972
-                 size_t first = gpr_end.c - next_arg.c;
 
973
-                 memcpy (next_arg.c, *p_argv.c, first);
 
974
-                 memcpy (rest.c, *p_argv.c + first, (*ptr)->size - first);
 
975
-                 next_arg.c = rest.c + words * 8 - first;
 
976
-               }
 
977
-             else
 
978
-               {
 
979
-                 char *where = next_arg.c;
 
980
-
 
981
-#ifndef __LITTLE_ENDIAN__
 
982
-                 /* Structures with size less than eight bytes are passed
 
983
-                    left-padded.  */
 
984
-                 if ((*ptr)->size < 8)
 
985
-                   where += 8 - (*ptr)->size;
 
986
-#endif
 
987
-                 memcpy (where, *p_argv.c, (*ptr)->size);
 
988
-                 next_arg.ul += words;
 
989
-                 if (next_arg.ul == gpr_end.ul)
 
990
-                   next_arg.ul = rest.ul;
 
991
-               }
 
992
-           }
 
993
-         break;
 
994
-
 
995
-       case FFI_TYPE_UINT8:
 
996
-         gprvalue = **p_argv.uc;
 
997
-         goto putgpr;
 
998
-       case FFI_TYPE_SINT8:
 
999
-         gprvalue = **p_argv.sc;
 
1000
-         goto putgpr;
 
1001
-       case FFI_TYPE_UINT16:
 
1002
-         gprvalue = **p_argv.us;
 
1003
-         goto putgpr;
 
1004
-       case FFI_TYPE_SINT16:
 
1005
-         gprvalue = **p_argv.ss;
 
1006
-         goto putgpr;
 
1007
-       case FFI_TYPE_UINT32:
 
1008
-         gprvalue = **p_argv.ui;
 
1009
-         goto putgpr;
 
1010
-       case FFI_TYPE_INT:
 
1011
-       case FFI_TYPE_SINT32:
 
1012
-         gprvalue = **p_argv.si;
 
1013
-         goto putgpr;
 
1014
-
 
1015
-       case FFI_TYPE_UINT64:
 
1016
-       case FFI_TYPE_SINT64:
 
1017
-       case FFI_TYPE_POINTER:
 
1018
-         gprvalue = **p_argv.ul;
 
1019
-       putgpr:
 
1020
-         *next_arg.ul++ = gprvalue;
 
1021
-         if (next_arg.ul == gpr_end.ul)
 
1022
-           next_arg.ul = rest.ul;
 
1023
-         break;
 
1024
-       }
 
1025
-    }
 
1026
-
 
1027
-  FFI_ASSERT (flags & FLAG_4_GPR_ARGUMENTS
 
1028
-             || (next_arg.ul >= gpr_base.ul
 
1029
-                 && next_arg.ul <= gpr_base.ul + 4));
 
1030
-}
 
1031
-
 
1032
-
 
1033
-
 
1034
 /* Perform machine dependent cif processing */
 
1035
-static ffi_status
 
1036
-ffi_prep_cif_machdep_core (ffi_cif *cif)
 
1037
+ffi_status FFI_HIDDEN
 
1038
+ffi_prep_cif_machdep (ffi_cif *cif)
 
1039
 {
 
1040
-  /* All this is for the SYSV and LINUX64 ABI.  */
 
1041
-  ffi_type **ptr;
 
1042
-  unsigned bytes;
 
1043
-  unsigned i, fparg_count = 0, intarg_count = 0;
 
1044
-  unsigned flags = cif->flags;
 
1045
-  unsigned struct_copy_size = 0;
 
1046
-  unsigned type = cif->rtype->type;
 
1047
-  unsigned size = cif->rtype->size;
 
1048
-
 
1049
-  /* The machine-independent calculation of cif->bytes doesn't work
 
1050
-     for us.  Redo the calculation.  */
 
1051
-  if (cif->abi != FFI_LINUX64)
 
1052
-    {
 
1053
-      /* Space for the frame pointer, callee's LR, and the asm's temp regs.  */
 
1054
-      bytes = (2 + ASM_NEEDS_REGISTERS) * sizeof (int);
 
1055
-
 
1056
-      /* Space for the GPR registers.  */
 
1057
-      bytes += NUM_GPR_ARG_REGISTERS * sizeof (int);
 
1058
-    }
 
1059
-  else
 
1060
-    {
 
1061
-      /* 64-bit ABI.  */
 
1062
-#if _CALL_ELF == 2
 
1063
-      /* Space for backchain, CR, LR, TOC and the asm's temp regs.  */
 
1064
-      bytes = (4 + ASM_NEEDS_REGISTERS64) * sizeof (long);
 
1065
-
 
1066
-      /* Space for the general registers.  */
 
1067
-      bytes += NUM_GPR_ARG_REGISTERS64 * sizeof (long);
 
1068
+#ifdef POWERPC64
 
1069
+  return ffi_prep_cif_linux64 (cif);
 
1070
 #else
 
1071
-      /* Space for backchain, CR, LR, cc/ld doubleword, TOC and the asm's temp
 
1072
-        regs.  */
 
1073
-      bytes = (6 + ASM_NEEDS_REGISTERS64) * sizeof (long);
 
1074
-
 
1075
-      /* Space for the mandatory parm save area and general registers.  */
 
1076
-      bytes += 2 * NUM_GPR_ARG_REGISTERS64 * sizeof (long);
 
1077
+  return ffi_prep_cif_sysv (cif);
 
1078
 #endif
 
1079
-    }
 
1080
-
 
1081
-  /* Return value handling.  The rules for SYSV are as follows:
 
1082
-     - 32-bit (or less) integer values are returned in gpr3;
 
1083
-     - Structures of size <= 4 bytes also returned in gpr3;
 
1084
-     - 64-bit integer values and structures between 5 and 8 bytes are returned
 
1085
-     in gpr3 and gpr4;
 
1086
-     - Single/double FP values are returned in fpr1;
 
1087
-     - Larger structures are allocated space and a pointer is passed as
 
1088
-     the first argument.
 
1089
-     - long doubles (if not equivalent to double) are returned in
 
1090
-     fpr1,fpr2 for Linux and as for large structs for SysV.
 
1091
-     For LINUX64:
 
1092
-     - integer values in gpr3;
 
1093
-     - Structures/Unions by reference;
 
1094
-     - Single/double FP values in fpr1, long double in fpr1,fpr2.
 
1095
-     - soft-float float/doubles are treated as UINT32/UINT64 respectivley.
 
1096
-     - soft-float long doubles are returned in gpr3-gpr6.  */
 
1097
-  /* First translate for softfloat/nonlinux */
 
1098
-  if (cif->abi == FFI_LINUX_SOFT_FLOAT)
 
1099
-    {
 
1100
-      if (type == FFI_TYPE_FLOAT)
 
1101
-       type = FFI_TYPE_UINT32;
 
1102
-      if (type == FFI_TYPE_DOUBLE)
 
1103
-       type = FFI_TYPE_UINT64;
 
1104
-      if (type == FFI_TYPE_LONGDOUBLE)
 
1105
-       type = FFI_TYPE_UINT128;
 
1106
-    }
 
1107
-  else if (cif->abi != FFI_LINUX
 
1108
-          && cif->abi != FFI_LINUX64)
 
1109
-    {
 
1110
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1111
-      if (type == FFI_TYPE_LONGDOUBLE)
 
1112
-       type = FFI_TYPE_STRUCT;
 
1113
-#endif
 
1114
-    }
 
1115
-
 
1116
-  switch (type)
 
1117
-    {
 
1118
-#ifndef __NO_FPRS__
 
1119
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1120
-    case FFI_TYPE_LONGDOUBLE:
 
1121
-      flags |= FLAG_RETURNS_128BITS;
 
1122
-      /* Fall through.  */
 
1123
-#endif
 
1124
-    case FFI_TYPE_DOUBLE:
 
1125
-      flags |= FLAG_RETURNS_64BITS;
 
1126
-      /* Fall through.  */
 
1127
-    case FFI_TYPE_FLOAT:
 
1128
-      flags |= FLAG_RETURNS_FP;
 
1129
-      break;
 
1130
-#endif
 
1131
-
 
1132
-    case FFI_TYPE_UINT128:
 
1133
-      flags |= FLAG_RETURNS_128BITS;
 
1134
-      /* Fall through.  */
 
1135
-    case FFI_TYPE_UINT64:
 
1136
-    case FFI_TYPE_SINT64:
 
1137
-      flags |= FLAG_RETURNS_64BITS;
 
1138
-      break;
 
1139
-
 
1140
-    case FFI_TYPE_STRUCT:
 
1141
-      /*
 
1142
-       * The final SYSV ABI says that structures smaller or equal 8 bytes
 
1143
-       * are returned in r3/r4.  The FFI_GCC_SYSV ABI instead returns them
 
1144
-       * in memory.
 
1145
-       *
 
1146
-       * NOTE: The assembly code can safely assume that it just needs to
 
1147
-       *       store both r3 and r4 into a 8-byte word-aligned buffer, as
 
1148
-       *       we allocate a temporary buffer in ffi_call() if this flag is
 
1149
-       *       set.
 
1150
-       */
 
1151
-      if (cif->abi == FFI_SYSV && size <= 8)
 
1152
-       {
 
1153
-         flags |= FLAG_RETURNS_SMST;
 
1154
-         break;
 
1155
-       }
 
1156
-#if _CALL_ELF == 2
 
1157
-      if (cif->abi == FFI_LINUX64)
 
1158
-       {
 
1159
-         unsigned int elt, elnum;
 
1160
-         elt = discover_homogeneous_aggregate (cif->rtype, &elnum);
 
1161
-         if (elt)
 
1162
-           {
 
1163
-             if (elt == FFI_TYPE_DOUBLE)
 
1164
-               flags |= FLAG_RETURNS_64BITS;
 
1165
-             flags |= FLAG_RETURNS_FP | FLAG_RETURNS_SMST;
 
1166
-             break;
 
1167
-           }
 
1168
-         if (size <= 16)
 
1169
-           {
 
1170
-             flags |= FLAG_RETURNS_SMST;
 
1171
-             break;
 
1172
-           }
 
1173
-       }
 
1174
-#endif
 
1175
-      intarg_count++;
 
1176
-      flags |= FLAG_RETVAL_REFERENCE;
 
1177
-      /* Fall through.  */
 
1178
-    case FFI_TYPE_VOID:
 
1179
-      flags |= FLAG_RETURNS_NOTHING;
 
1180
-      break;
 
1181
-
 
1182
-    default:
 
1183
-      /* Returns 32-bit integer, or similar.  Nothing to do here.  */
 
1184
-      break;
 
1185
-    }
 
1186
-
 
1187
-  if (cif->abi != FFI_LINUX64)
 
1188
-    /* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
 
1189
-       first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
 
1190
-       goes on the stack.  Structures and long doubles (if not equivalent
 
1191
-       to double) are passed as a pointer to a copy of the structure.
 
1192
-       Stuff on the stack needs to keep proper alignment.  */
 
1193
-    for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
 
1194
-      {
 
1195
-       unsigned short typenum = (*ptr)->type;
 
1196
-
 
1197
-       /* We may need to handle some values depending on ABI */
 
1198
-       if (cif->abi == FFI_LINUX_SOFT_FLOAT) {
 
1199
-               if (typenum == FFI_TYPE_FLOAT)
 
1200
-                       typenum = FFI_TYPE_UINT32;
 
1201
-               if (typenum == FFI_TYPE_DOUBLE)
 
1202
-                       typenum = FFI_TYPE_UINT64;
 
1203
-               if (typenum == FFI_TYPE_LONGDOUBLE)
 
1204
-                       typenum = FFI_TYPE_UINT128;
 
1205
-       } else if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX64) {
 
1206
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1207
-               if (typenum == FFI_TYPE_LONGDOUBLE)
 
1208
-                       typenum = FFI_TYPE_STRUCT;
 
1209
-#endif
 
1210
-       }
 
1211
-
 
1212
-       switch (typenum) {
 
1213
-#ifndef __NO_FPRS__
 
1214
-         case FFI_TYPE_FLOAT:
 
1215
-           fparg_count++;
 
1216
-           /* floating singles are not 8-aligned on stack */
 
1217
-           break;
 
1218
-
 
1219
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1220
-         case FFI_TYPE_LONGDOUBLE:
 
1221
-           fparg_count++;
 
1222
-           /* Fall thru */
 
1223
-#endif
 
1224
-         case FFI_TYPE_DOUBLE:
 
1225
-           fparg_count++;
 
1226
-           /* If this FP arg is going on the stack, it must be
 
1227
-              8-byte-aligned.  */
 
1228
-           if (fparg_count > NUM_FPR_ARG_REGISTERS
 
1229
-               && intarg_count >= NUM_GPR_ARG_REGISTERS
 
1230
-               && intarg_count % 2 != 0)
 
1231
-             intarg_count++;
 
1232
-           break;
 
1233
-#endif
 
1234
-         case FFI_TYPE_UINT128:
 
1235
-               /*
 
1236
-                * A long double in FFI_LINUX_SOFT_FLOAT can use only a set
 
1237
-                * of four consecutive gprs. If we do not have enough, we
 
1238
-                * have to adjust the intarg_count value.
 
1239
-                */
 
1240
-               if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3
 
1241
-                               && intarg_count < NUM_GPR_ARG_REGISTERS)
 
1242
-                       intarg_count = NUM_GPR_ARG_REGISTERS;
 
1243
-               intarg_count += 4;
 
1244
-               break;
 
1245
-
 
1246
-         case FFI_TYPE_UINT64:
 
1247
-         case FFI_TYPE_SINT64:
 
1248
-           /* 'long long' arguments are passed as two words, but
 
1249
-              either both words must fit in registers or both go
 
1250
-              on the stack.  If they go on the stack, they must
 
1251
-              be 8-byte-aligned.
 
1252
-
 
1253
-              Also, only certain register pairs can be used for
 
1254
-              passing long long int -- specifically (r3,r4), (r5,r6),
 
1255
-              (r7,r8), (r9,r10).
 
1256
-           */
 
1257
-           if (intarg_count == NUM_GPR_ARG_REGISTERS-1
 
1258
-               || intarg_count % 2 != 0)
 
1259
-             intarg_count++;
 
1260
-           intarg_count += 2;
 
1261
-           break;
 
1262
-
 
1263
-         case FFI_TYPE_STRUCT:
 
1264
-           /* We must allocate space for a copy of these to enforce
 
1265
-              pass-by-value.  Pad the space up to a multiple of 16
 
1266
-              bytes (the maximum alignment required for anything under
 
1267
-              the SYSV ABI).  */
 
1268
-           struct_copy_size += ((*ptr)->size + 15) & ~0xF;
 
1269
-           /* Fall through (allocate space for the pointer).  */
 
1270
-
 
1271
-         case FFI_TYPE_POINTER:
 
1272
-         case FFI_TYPE_INT:
 
1273
-         case FFI_TYPE_UINT32:
 
1274
-         case FFI_TYPE_SINT32:
 
1275
-         case FFI_TYPE_UINT16:
 
1276
-         case FFI_TYPE_SINT16:
 
1277
-         case FFI_TYPE_UINT8:
 
1278
-         case FFI_TYPE_SINT8:
 
1279
-           /* Everything else is passed as a 4-byte word in a GPR, either
 
1280
-              the object itself or a pointer to it.  */
 
1281
-           intarg_count++;
 
1282
-           break;
 
1283
-         default:
 
1284
-               FFI_ASSERT (0);
 
1285
-         }
 
1286
-      }
 
1287
-  else
 
1288
-    for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
 
1289
-      {
 
1290
-       unsigned int elt, elnum;
 
1291
-#ifdef __STRUCT_PARM_ALIGN__
 
1292
-       unsigned int align;
 
1293
-#endif
 
1294
-
 
1295
-       switch ((*ptr)->type)
 
1296
-         {
 
1297
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1298
-         case FFI_TYPE_LONGDOUBLE:
 
1299
-           fparg_count += 2;
 
1300
-           intarg_count += 2;
 
1301
-           if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
1302
-             flags |= FLAG_ARG_NEEDS_PSAVE;
 
1303
-           break;
 
1304
-#endif
 
1305
-         case FFI_TYPE_FLOAT:
 
1306
-         case FFI_TYPE_DOUBLE:
 
1307
-           fparg_count++;
 
1308
-           intarg_count++;
 
1309
-           if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
1310
-             flags |= FLAG_ARG_NEEDS_PSAVE;
 
1311
-           break;
 
1312
-
 
1313
-         case FFI_TYPE_STRUCT:
 
1314
-#ifdef __STRUCT_PARM_ALIGN__
 
1315
-           align = (*ptr)->alignment;
 
1316
-           if (align > __STRUCT_PARM_ALIGN__)
 
1317
-             align = __STRUCT_PARM_ALIGN__;
 
1318
-           align = align / 8;
 
1319
-           if (align > 1)
 
1320
-             intarg_count = ALIGN (intarg_count, align);
 
1321
-#endif
 
1322
-           intarg_count += ((*ptr)->size + 7) / 8;
 
1323
-           elt = 0;
 
1324
-#if _CALL_ELF == 2
 
1325
-           elt = discover_homogeneous_aggregate (*ptr, &elnum);
 
1326
-#endif
 
1327
-           if (elt)
 
1328
-             {
 
1329
-               fparg_count += elnum;
 
1330
-               if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
1331
-                 flags |= FLAG_ARG_NEEDS_PSAVE;
 
1332
-             }
 
1333
-           else
 
1334
-             {
 
1335
-               if (intarg_count > NUM_GPR_ARG_REGISTERS)
 
1336
-                 flags |= FLAG_ARG_NEEDS_PSAVE;
 
1337
-             }
 
1338
-           break;
 
1339
-
 
1340
-         case FFI_TYPE_POINTER:
 
1341
-         case FFI_TYPE_UINT64:
 
1342
-         case FFI_TYPE_SINT64:
 
1343
-         case FFI_TYPE_INT:
 
1344
-         case FFI_TYPE_UINT32:
 
1345
-         case FFI_TYPE_SINT32:
 
1346
-         case FFI_TYPE_UINT16:
 
1347
-         case FFI_TYPE_SINT16:
 
1348
-         case FFI_TYPE_UINT8:
 
1349
-         case FFI_TYPE_SINT8:
 
1350
-           /* Everything else is passed as a 8-byte word in a GPR, either
 
1351
-              the object itself or a pointer to it.  */
 
1352
-           intarg_count++;
 
1353
-           if (intarg_count > NUM_GPR_ARG_REGISTERS)
 
1354
-             flags |= FLAG_ARG_NEEDS_PSAVE;
 
1355
-           break;
 
1356
-         default:
 
1357
-           FFI_ASSERT (0);
 
1358
-         }
 
1359
-      }
 
1360
-
 
1361
-#ifndef __NO_FPRS__
 
1362
-  if (fparg_count != 0)
 
1363
-    flags |= FLAG_FP_ARGUMENTS;
 
1364
-#endif
 
1365
-  if (intarg_count > 4)
 
1366
-    flags |= FLAG_4_GPR_ARGUMENTS;
 
1367
-  if (struct_copy_size != 0)
 
1368
-    flags |= FLAG_ARG_NEEDS_COPY;
 
1369
-
 
1370
-  if (cif->abi != FFI_LINUX64)
 
1371
-    {
 
1372
-#ifndef __NO_FPRS__
 
1373
-      /* Space for the FPR registers, if needed.  */
 
1374
-      if (fparg_count != 0)
 
1375
-       bytes += NUM_FPR_ARG_REGISTERS * sizeof (double);
 
1376
-#endif
 
1377
-
 
1378
-      /* Stack space.  */
 
1379
-      if (intarg_count > NUM_GPR_ARG_REGISTERS)
 
1380
-       bytes += (intarg_count - NUM_GPR_ARG_REGISTERS) * sizeof (int);
 
1381
-#ifndef __NO_FPRS__
 
1382
-      if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
1383
-       bytes += (fparg_count - NUM_FPR_ARG_REGISTERS) * sizeof (double);
 
1384
-#endif
 
1385
-    }
 
1386
-  else
 
1387
-    {
 
1388
-#ifndef __NO_FPRS__
 
1389
-      /* Space for the FPR registers, if needed.  */
 
1390
-      if (fparg_count != 0)
 
1391
-       bytes += NUM_FPR_ARG_REGISTERS64 * sizeof (double);
 
1392
-#endif
 
1393
-
 
1394
-      /* Stack space.  */
 
1395
-#if _CALL_ELF == 2
 
1396
-      if ((flags & FLAG_ARG_NEEDS_PSAVE) != 0)
 
1397
-       bytes += intarg_count * sizeof (long);
 
1398
-#else
 
1399
-      if (intarg_count > NUM_GPR_ARG_REGISTERS64)
 
1400
-       bytes += (intarg_count - NUM_GPR_ARG_REGISTERS64) * sizeof (long);
 
1401
-#endif
 
1402
-    }
 
1403
-
 
1404
-  /* The stack space allocated needs to be a multiple of 16 bytes.  */
 
1405
-  bytes = (bytes + 15) & ~0xF;
 
1406
-
 
1407
-  /* Add in the space for the copied structures.  */
 
1408
-  bytes += struct_copy_size;
 
1409
-
 
1410
-  cif->flags = flags;
 
1411
-  cif->bytes = bytes;
 
1412
-
 
1413
-  return FFI_OK;
 
1414
 }
 
1415
 
 
1416
-ffi_status
 
1417
-ffi_prep_cif_machdep (ffi_cif *cif)
 
1418
-{
 
1419
-  cif->nfixedargs = cif->nargs;
 
1420
-  return ffi_prep_cif_machdep_core (cif);
 
1421
-}
 
1422
-
 
1423
-ffi_status
 
1424
+ffi_status FFI_HIDDEN
 
1425
 ffi_prep_cif_machdep_var (ffi_cif *cif,
 
1426
-                         unsigned int nfixedargs,
 
1427
+                         unsigned int nfixedargs MAYBE_UNUSED,
 
1428
                          unsigned int ntotalargs MAYBE_UNUSED)
 
1429
 {
 
1430
-  cif->nfixedargs = nfixedargs;
 
1431
-#if _CALL_ELF == 2
 
1432
-  if (cif->abi == FFI_LINUX64)
 
1433
-    cif->flags |= FLAG_ARG_NEEDS_PSAVE;
 
1434
+#ifdef POWERPC64
 
1435
+  return ffi_prep_cif_linux64_var (cif, nfixedargs, ntotalargs);
 
1436
+#else
 
1437
+  return ffi_prep_cif_sysv (cif);
 
1438
 #endif
 
1439
-  return ffi_prep_cif_machdep_core (cif);
 
1440
 }
 
1441
 
 
1442
-extern void ffi_call_SYSV(extended_cif *, unsigned, unsigned, unsigned *,
 
1443
-                         void (*fn)(void));
 
1444
-extern void FFI_HIDDEN ffi_call_LINUX64(extended_cif *, unsigned long,
 
1445
-                                       unsigned long, unsigned long *,
 
1446
-                                       void (*fn)(void));
 
1447
-
 
1448
 void
 
1449
 ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 
1450
 {
 
1451
-  /*
 
1452
-   * The final SYSV ABI says that structures smaller or equal 8 bytes
 
1453
-   * are returned in r3/r4.  The FFI_GCC_SYSV ABI instead returns them
 
1454
-   * in memory.
 
1455
-   *
 
1456
-   * We bounce-buffer SYSV small struct return values so that sysv.S
 
1457
-   * can write r3 and r4 to memory without worrying about struct size.
 
1458
-   *
 
1459
-   * For ELFv2 ABI, use a bounce buffer for homogeneous structs too,
 
1460
-   * for similar reasons.
 
1461
-   */
 
1462
+  /* The final SYSV ABI says that structures smaller or equal 8 bytes
 
1463
+     are returned in r3/r4.  A draft ABI used by linux instead returns
 
1464
+     them in memory.
 
1465
+
 
1466
+     We bounce-buffer SYSV small struct return values so that sysv.S
 
1467
+     can write r3 and r4 to memory without worrying about struct size.
 
1468
+   
 
1469
+     For ELFv2 ABI, use a bounce buffer for homogeneous structs too,
 
1470
+     for similar reasons.  */
 
1471
   unsigned long smst_buffer[8];
 
1472
   extended_cif ecif;
 
1473
 
 
1474
@@ -1147,26 +96,11 @@
 
1475
   else if (!rvalue && cif->rtype->type == FFI_TYPE_STRUCT)
 
1476
     ecif.rvalue = alloca (cif->rtype->size);
 
1477
 
 
1478
-  switch (cif->abi)
 
1479
-    {
 
1480
-#ifndef POWERPC64
 
1481
-# ifndef __NO_FPRS__
 
1482
-    case FFI_SYSV:
 
1483
-    case FFI_GCC_SYSV:
 
1484
-    case FFI_LINUX:
 
1485
-# endif
 
1486
-    case FFI_LINUX_SOFT_FLOAT:
 
1487
-      ffi_call_SYSV (&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn);
 
1488
-      break;
 
1489
+#ifdef POWERPC64
 
1490
+  ffi_call_LINUX64 (&ecif, -(long) cif->bytes, cif->flags, ecif.rvalue, fn);
 
1491
 #else
 
1492
-    case FFI_LINUX64:
 
1493
-      ffi_call_LINUX64 (&ecif, -(long) cif->bytes, cif->flags, ecif.rvalue, fn);
 
1494
-      break;
 
1495
+  ffi_call_SYSV (&ecif, -cif->bytes, cif->flags, ecif.rvalue, fn);
 
1496
 #endif
 
1497
-    default:
 
1498
-      FFI_ASSERT (0);
 
1499
-      break;
 
1500
-    }
 
1501
 
 
1502
   /* Check for a bounce-buffered return value */
 
1503
   if (rvalue && ecif.rvalue == smst_buffer)
 
1504
@@ -1175,36 +109,23 @@
 
1505
 #ifndef __LITTLE_ENDIAN__
 
1506
       /* The SYSV ABI returns a structure of up to 4 bytes in size
 
1507
         left-padded in r3.  */
 
1508
-      if (cif->abi == FFI_SYSV && rsize <= 4)
 
1509
+# ifndef POWERPC64
 
1510
+      if (rsize <= 4)
 
1511
        memcpy (rvalue, (char *) smst_buffer + 4 - rsize, rsize);
 
1512
-      /* The SYSV ABI returns a structure of up to 8 bytes in size
 
1513
-        left-padded in r3/r4, and the ELFv2 ABI similarly returns a
 
1514
-        structure of up to 8 bytes in size left-padded in r3.  */
 
1515
-      else if (rsize <= 8)
 
1516
-       memcpy (rvalue, (char *) smst_buffer + 8 - rsize, rsize);
 
1517
       else
 
1518
+# endif
 
1519
+       /* The SYSV ABI returns a structure of up to 8 bytes in size
 
1520
+          left-padded in r3/r4, and the ELFv2 ABI similarly returns a
 
1521
+          structure of up to 8 bytes in size left-padded in r3.  */
 
1522
+       if (rsize <= 8)
 
1523
+         memcpy (rvalue, (char *) smst_buffer + 8 - rsize, rsize);
 
1524
+       else
 
1525
 #endif
 
1526
-       memcpy (rvalue, smst_buffer, rsize);
 
1527
+         memcpy (rvalue, smst_buffer, rsize);
 
1528
     }
 
1529
 }
 
1530
 
 
1531
 
 
1532
-#if !defined POWERPC64 || _CALL_ELF == 2
 
1533
-#define MIN_CACHE_LINE_SIZE 8
 
1534
-
 
1535
-static void
 
1536
-flush_icache (char *wraddr, char *xaddr, int size)
 
1537
-{
 
1538
-  int i;
 
1539
-  for (i = 0; i < size; i += MIN_CACHE_LINE_SIZE)
 
1540
-    __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;"
 
1541
-                     : : "r" (xaddr + i), "r" (wraddr + i) : "memory");
 
1542
-  __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;"
 
1543
-                   : : "r"(xaddr + size - 1), "r"(wraddr + size - 1)
 
1544
-                   : "memory");
 
1545
-}
 
1546
-#endif
 
1547
-
 
1548
 ffi_status
 
1549
 ffi_prep_closure_loc (ffi_closure *closure,
 
1550
                      ffi_cif *cif,
 
1551
@@ -1213,593 +134,8 @@
 
1552
                      void *codeloc)
 
1553
 {
 
1554
 #ifdef POWERPC64
 
1555
-# if _CALL_ELF == 2
 
1556
-  unsigned int *tramp = (unsigned int *) &closure->tramp[0];
 
1557
-
 
1558
-  if (cif->abi != FFI_LINUX64)
 
1559
-    return FFI_BAD_ABI;
 
1560
-
 
1561
-  tramp[0] = 0xe96c0018;       /* 0:   ld      11,2f-0b(12)    */
 
1562
-  tramp[1] = 0xe98c0010;       /*      ld      12,1f-0b(12)    */
 
1563
-  tramp[2] = 0x7d8903a6;       /*      mtctr   12              */
 
1564
-  tramp[3] = 0x4e800420;       /*      bctr                    */
 
1565
-                               /* 1:   .quad   function_addr   */
 
1566
-                               /* 2:   .quad   context         */
 
1567
-  *(void **) &tramp[4] = (void *) ffi_closure_LINUX64;
 
1568
-  *(void **) &tramp[6] = codeloc;
 
1569
-  flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE);
 
1570
-# else
 
1571
-  void **tramp = (void **) &closure->tramp[0];
 
1572
-
 
1573
-  if (cif->abi != FFI_LINUX64)
 
1574
-    return FFI_BAD_ABI;
 
1575
-  /* Copy function address and TOC from ffi_closure_LINUX64.  */
 
1576
-  memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
 
1577
-  tramp[2] = codeloc;
 
1578
-# endif
 
1579
+  return ffi_prep_closure_loc_linux64 (closure, cif, fun, user_data, codeloc);
 
1580
 #else
 
1581
-  unsigned int *tramp;
 
1582
-
 
1583
-  if (! (cif->abi == FFI_GCC_SYSV 
 
1584
-        || cif->abi == FFI_SYSV
 
1585
-        || cif->abi == FFI_LINUX
 
1586
-        || cif->abi == FFI_LINUX_SOFT_FLOAT))
 
1587
-    return FFI_BAD_ABI;
 
1588
-
 
1589
-  tramp = (unsigned int *) &closure->tramp[0];
 
1590
-  tramp[0] = 0x7c0802a6;  /*   mflr    r0 */
 
1591
-  tramp[1] = 0x4800000d;  /*   bl      10 <trampoline_initial+0x10> */
 
1592
-  tramp[4] = 0x7d6802a6;  /*   mflr    r11 */
 
1593
-  tramp[5] = 0x7c0803a6;  /*   mtlr    r0 */
 
1594
-  tramp[6] = 0x800b0000;  /*   lwz     r0,0(r11) */
 
1595
-  tramp[7] = 0x816b0004;  /*   lwz     r11,4(r11) */
 
1596
-  tramp[8] = 0x7c0903a6;  /*   mtctr   r0 */
 
1597
-  tramp[9] = 0x4e800420;  /*   bctr */
 
1598
-  *(void **) &tramp[2] = (void *) ffi_closure_SYSV; /* function */
 
1599
-  *(void **) &tramp[3] = codeloc;                   /* context */
 
1600
-
 
1601
-  /* Flush the icache.  */
 
1602
-  flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE);
 
1603
+  return ffi_prep_closure_loc_sysv (closure, cif, fun, user_data, codeloc);
 
1604
 #endif
 
1605
-
 
1606
-  closure->cif = cif;
 
1607
-  closure->fun = fun;
 
1608
-  closure->user_data = user_data;
 
1609
-
 
1610
-  return FFI_OK;
 
1611
 }
 
1612
-
 
1613
-typedef union
 
1614
-{
 
1615
-  float f;
 
1616
-  double d;
 
1617
-} ffi_dblfl;
 
1618
-
 
1619
-int ffi_closure_helper_SYSV (ffi_closure *, void *, unsigned long *,
 
1620
-                            ffi_dblfl *, unsigned long *);
 
1621
-
 
1622
-/* Basically the trampoline invokes ffi_closure_SYSV, and on
 
1623
- * entry, r11 holds the address of the closure.
 
1624
- * After storing the registers that could possibly contain
 
1625
- * parameters to be passed into the stack frame and setting
 
1626
- * up space for a return value, ffi_closure_SYSV invokes the
 
1627
- * following helper function to do most of the work
 
1628
- */
 
1629
-
 
1630
-int
 
1631
-ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue,
 
1632
-                        unsigned long *pgr, ffi_dblfl *pfr,
 
1633
-                        unsigned long *pst)
 
1634
-{
 
1635
-  /* rvalue is the pointer to space for return value in closure assembly */
 
1636
-  /* pgr is the pointer to where r3-r10 are stored in ffi_closure_SYSV */
 
1637
-  /* pfr is the pointer to where f1-f8 are stored in ffi_closure_SYSV  */
 
1638
-  /* pst is the pointer to outgoing parameter stack in original caller */
 
1639
-
 
1640
-  void **          avalue;
 
1641
-  ffi_type **      arg_types;
 
1642
-  long             i, avn;
 
1643
-#ifndef __NO_FPRS__
 
1644
-  long             nf = 0;   /* number of floating registers already used */
 
1645
-#endif
 
1646
-  long             ng = 0;   /* number of general registers already used */
 
1647
-
 
1648
-  ffi_cif *cif = closure->cif;
 
1649
-  unsigned       size     = cif->rtype->size;
 
1650
-  unsigned short rtypenum = cif->rtype->type;
 
1651
-
 
1652
-  avalue = alloca (cif->nargs * sizeof (void *));
 
1653
-
 
1654
-  /* First translate for softfloat/nonlinux */
 
1655
-  if (cif->abi == FFI_LINUX_SOFT_FLOAT) {
 
1656
-       if (rtypenum == FFI_TYPE_FLOAT)
 
1657
-               rtypenum = FFI_TYPE_UINT32;
 
1658
-       if (rtypenum == FFI_TYPE_DOUBLE)
 
1659
-               rtypenum = FFI_TYPE_UINT64;
 
1660
-       if (rtypenum == FFI_TYPE_LONGDOUBLE)
 
1661
-               rtypenum = FFI_TYPE_UINT128;
 
1662
-  } else if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX64) {
 
1663
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1664
-       if (rtypenum == FFI_TYPE_LONGDOUBLE)
 
1665
-               rtypenum = FFI_TYPE_STRUCT;
 
1666
-#endif
 
1667
-  }
 
1668
-
 
1669
-
 
1670
-  /* Copy the caller's structure return value address so that the closure
 
1671
-     returns the data directly to the caller.
 
1672
-     For FFI_SYSV the result is passed in r3/r4 if the struct size is less
 
1673
-     or equal 8 bytes.  */
 
1674
-  if (rtypenum == FFI_TYPE_STRUCT && ((cif->abi != FFI_SYSV) || (size > 8))) {
 
1675
-      rvalue = (void *) *pgr;
 
1676
-      ng++;
 
1677
-      pgr++;
 
1678
-    }
 
1679
-
 
1680
-  i = 0;
 
1681
-  avn = cif->nargs;
 
1682
-  arg_types = cif->arg_types;
 
1683
-
 
1684
-  /* Grab the addresses of the arguments from the stack frame.  */
 
1685
-  while (i < avn) {
 
1686
-      unsigned short typenum = arg_types[i]->type;
 
1687
-
 
1688
-      /* We may need to handle some values depending on ABI */
 
1689
-      if (cif->abi == FFI_LINUX_SOFT_FLOAT) {
 
1690
-               if (typenum == FFI_TYPE_FLOAT)
 
1691
-                       typenum = FFI_TYPE_UINT32;
 
1692
-               if (typenum == FFI_TYPE_DOUBLE)
 
1693
-                       typenum = FFI_TYPE_UINT64;
 
1694
-               if (typenum == FFI_TYPE_LONGDOUBLE)
 
1695
-                       typenum = FFI_TYPE_UINT128;
 
1696
-      } else if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX64) {
 
1697
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1698
-               if (typenum == FFI_TYPE_LONGDOUBLE)
 
1699
-                       typenum = FFI_TYPE_STRUCT;
 
1700
-#endif
 
1701
-      }
 
1702
-
 
1703
-      switch (typenum) {
 
1704
-#ifndef __NO_FPRS__
 
1705
-       case FFI_TYPE_FLOAT:
 
1706
-         /* unfortunately float values are stored as doubles
 
1707
-          * in the ffi_closure_SYSV code (since we don't check
 
1708
-          * the type in that routine).
 
1709
-          */
 
1710
-
 
1711
-         /* there are 8 64bit floating point registers */
 
1712
-
 
1713
-         if (nf < 8)
 
1714
-           {
 
1715
-             double temp = pfr->d;
 
1716
-             pfr->f = (float) temp;
 
1717
-             avalue[i] = pfr;
 
1718
-             nf++;
 
1719
-             pfr++;
 
1720
-           }
 
1721
-         else
 
1722
-           {
 
1723
-             /* FIXME? here we are really changing the values
 
1724
-              * stored in the original calling routines outgoing
 
1725
-              * parameter stack.  This is probably a really
 
1726
-              * naughty thing to do but...
 
1727
-              */
 
1728
-             avalue[i] = pst;
 
1729
-             pst += 1;
 
1730
-           }
 
1731
-         break;
 
1732
-
 
1733
-       case FFI_TYPE_DOUBLE:
 
1734
-         /* On the outgoing stack all values are aligned to 8 */
 
1735
-         /* there are 8 64bit floating point registers */
 
1736
-
 
1737
-         if (nf < 8)
 
1738
-           {
 
1739
-             avalue[i] = pfr;
 
1740
-             nf++;
 
1741
-             pfr++;
 
1742
-           }
 
1743
-         else
 
1744
-           {
 
1745
-             if (((long) pst) & 4)
 
1746
-               pst++;
 
1747
-             avalue[i] = pst;
 
1748
-             pst += 2;
 
1749
-           }
 
1750
-         break;
 
1751
-
 
1752
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
1753
-       case FFI_TYPE_LONGDOUBLE:
 
1754
-         if (nf < 7)
 
1755
-           {
 
1756
-             avalue[i] = pfr;
 
1757
-             pfr += 2;
 
1758
-             nf += 2;
 
1759
-           }
 
1760
-         else
 
1761
-           {
 
1762
-             if (((long) pst) & 4)
 
1763
-               pst++;
 
1764
-             avalue[i] = pst;
 
1765
-             pst += 4;
 
1766
-             nf = 8;
 
1767
-           }
 
1768
-         break;
 
1769
-#endif
 
1770
-#endif /* have FPRS */
 
1771
-
 
1772
-       case FFI_TYPE_UINT128:
 
1773
-               /*
 
1774
-                * Test if for the whole long double, 4 gprs are available.
 
1775
-                * otherwise the stuff ends up on the stack.
 
1776
-                */
 
1777
-               if (ng < 5) {
 
1778
-                       avalue[i] = pgr;
 
1779
-                       pgr += 4;
 
1780
-                       ng += 4;
 
1781
-               } else {
 
1782
-                       avalue[i] = pst;
 
1783
-                       pst += 4;
 
1784
-                       ng = 8+4;
 
1785
-               }
 
1786
-               break;
 
1787
-
 
1788
-       case FFI_TYPE_SINT8:
 
1789
-       case FFI_TYPE_UINT8:
 
1790
-#ifndef __LITTLE_ENDIAN__
 
1791
-         /* there are 8 gpr registers used to pass values */
 
1792
-         if (ng < 8)
 
1793
-           {
 
1794
-             avalue[i] = (char *) pgr + 3;
 
1795
-             ng++;
 
1796
-             pgr++;
 
1797
-           }
 
1798
-         else
 
1799
-           {
 
1800
-             avalue[i] = (char *) pst + 3;
 
1801
-             pst++;
 
1802
-           }
 
1803
-         break;
 
1804
-#endif
 
1805
-
 
1806
-       case FFI_TYPE_SINT16:
 
1807
-       case FFI_TYPE_UINT16:
 
1808
-#ifndef __LITTLE_ENDIAN__
 
1809
-         /* there are 8 gpr registers used to pass values */
 
1810
-         if (ng < 8)
 
1811
-           {
 
1812
-             avalue[i] = (char *) pgr + 2;
 
1813
-             ng++;
 
1814
-             pgr++;
 
1815
-           }
 
1816
-         else
 
1817
-           {
 
1818
-             avalue[i] = (char *) pst + 2;
 
1819
-             pst++;
 
1820
-           }
 
1821
-         break;
 
1822
-#endif
 
1823
-
 
1824
-       case FFI_TYPE_SINT32:
 
1825
-       case FFI_TYPE_UINT32:
 
1826
-       case FFI_TYPE_POINTER:
 
1827
-         /* there are 8 gpr registers used to pass values */
 
1828
-         if (ng < 8)
 
1829
-           {
 
1830
-             avalue[i] = pgr;
 
1831
-             ng++;
 
1832
-             pgr++;
 
1833
-           }
 
1834
-         else
 
1835
-           {
 
1836
-             avalue[i] = pst;
 
1837
-             pst++;
 
1838
-           }
 
1839
-         break;
 
1840
-
 
1841
-       case FFI_TYPE_STRUCT:
 
1842
-         /* Structs are passed by reference. The address will appear in a
 
1843
-            gpr if it is one of the first 8 arguments.  */
 
1844
-         if (ng < 8)
 
1845
-           {
 
1846
-             avalue[i] = (void *) *pgr;
 
1847
-             ng++;
 
1848
-             pgr++;
 
1849
-           }
 
1850
-         else
 
1851
-           {
 
1852
-             avalue[i] = (void *) *pst;
 
1853
-             pst++;
 
1854
-           }
 
1855
-         break;
 
1856
-
 
1857
-       case FFI_TYPE_SINT64:
 
1858
-       case FFI_TYPE_UINT64:
 
1859
-         /* passing long long ints are complex, they must
 
1860
-          * be passed in suitable register pairs such as
 
1861
-          * (r3,r4) or (r5,r6) or (r6,r7), or (r7,r8) or (r9,r10)
 
1862
-          * and if the entire pair aren't available then the outgoing
 
1863
-          * parameter stack is used for both but an alignment of 8
 
1864
-          * must will be kept.  So we must either look in pgr
 
1865
-          * or pst to find the correct address for this type
 
1866
-          * of parameter.
 
1867
-          */
 
1868
-         if (ng < 7)
 
1869
-           {
 
1870
-             if (ng & 0x01)
 
1871
-               {
 
1872
-                 /* skip r4, r6, r8 as starting points */
 
1873
-                 ng++;
 
1874
-                 pgr++;
 
1875
-               }
 
1876
-             avalue[i] = pgr;
 
1877
-             ng += 2;
 
1878
-             pgr += 2;
 
1879
-           }
 
1880
-         else
 
1881
-           {
 
1882
-             if (((long) pst) & 4)
 
1883
-               pst++;
 
1884
-             avalue[i] = pst;
 
1885
-             pst += 2;
 
1886
-             ng = 8;
 
1887
-           }
 
1888
-         break;
 
1889
-
 
1890
-       default:
 
1891
-               FFI_ASSERT (0);
 
1892
-       }
 
1893
-
 
1894
-      i++;
 
1895
-    }
 
1896
-
 
1897
-
 
1898
-  (closure->fun) (cif, rvalue, avalue, closure->user_data);
 
1899
-
 
1900
-  /* Tell ffi_closure_SYSV how to perform return type promotions.
 
1901
-     Because the FFI_SYSV ABI returns the structures <= 8 bytes in r3/r4
 
1902
-     we have to tell ffi_closure_SYSV how to treat them. We combine the base
 
1903
-     type FFI_SYSV_TYPE_SMALL_STRUCT - 1  with the size of the struct.
 
1904
-     So a one byte struct gets the return type 16. Return type 1 to 15 are
 
1905
-     already used and we never have a struct with size zero. That is the reason
 
1906
-     for the subtraction of 1. See the comment in ffitarget.h about ordering.
 
1907
-  */
 
1908
-  if (cif->abi == FFI_SYSV && rtypenum == FFI_TYPE_STRUCT && size <= 8)
 
1909
-    return (FFI_SYSV_TYPE_SMALL_STRUCT - 1) + size;
 
1910
-  return rtypenum;
 
1911
-}
 
1912
-
 
1913
-int FFI_HIDDEN ffi_closure_helper_LINUX64 (ffi_closure *, void *,
 
1914
-                                          unsigned long *, ffi_dblfl *);
 
1915
-
 
1916
-int FFI_HIDDEN
 
1917
-ffi_closure_helper_LINUX64 (ffi_closure *closure, void *rvalue,
 
1918
-                           unsigned long *pst, ffi_dblfl *pfr)
 
1919
-{
 
1920
-  /* rvalue is the pointer to space for return value in closure assembly */
 
1921
-  /* pst is the pointer to parameter save area
 
1922
-     (r3-r10 are stored into its first 8 slots by ffi_closure_LINUX64) */
 
1923
-  /* pfr is the pointer to where f1-f13 are stored in ffi_closure_LINUX64 */
 
1924
-
 
1925
-  void **avalue;
 
1926
-  ffi_type **arg_types;
 
1927
-  unsigned long i, avn, nfixedargs;
 
1928
-  ffi_cif *cif;
 
1929
-  ffi_dblfl *end_pfr = pfr + NUM_FPR_ARG_REGISTERS64;
 
1930
-#ifdef __STRUCT_PARM_ALIGN__
 
1931
-  unsigned long align;
 
1932
-#endif
 
1933
-
 
1934
-  cif = closure->cif;
 
1935
-  avalue = alloca (cif->nargs * sizeof (void *));
 
1936
-
 
1937
-  /* Copy the caller's structure return value address so that the
 
1938
-     closure returns the data directly to the caller.  */
 
1939
-  if (cif->rtype->type == FFI_TYPE_STRUCT
 
1940
-      && (cif->flags & FLAG_RETURNS_SMST) == 0)
 
1941
-    {
 
1942
-      rvalue = (void *) *pst;
 
1943
-      pst++;
 
1944
-    }
 
1945
-
 
1946
-  i = 0;
 
1947
-  avn = cif->nargs;
 
1948
-  nfixedargs = cif->nfixedargs;
 
1949
-  arg_types = cif->arg_types;
 
1950
-
 
1951
-  /* Grab the addresses of the arguments from the stack frame.  */
 
1952
-  while (i < avn)
 
1953
-    {
 
1954
-      unsigned int elt, elnum;
 
1955
-
 
1956
-      switch (arg_types[i]->type)
 
1957
-       {
 
1958
-       case FFI_TYPE_SINT8:
 
1959
-       case FFI_TYPE_UINT8:
 
1960
-#ifndef __LITTLE_ENDIAN__
 
1961
-         avalue[i] = (char *) pst + 7;
 
1962
-         pst++;
 
1963
-         break;
 
1964
-#endif
 
1965
-
 
1966
-       case FFI_TYPE_SINT16:
 
1967
-       case FFI_TYPE_UINT16:
 
1968
-#ifndef __LITTLE_ENDIAN__
 
1969
-         avalue[i] = (char *) pst + 6;
 
1970
-         pst++;
 
1971
-         break;
 
1972
-#endif
 
1973
-
 
1974
-       case FFI_TYPE_SINT32:
 
1975
-       case FFI_TYPE_UINT32:
 
1976
-#ifndef __LITTLE_ENDIAN__
 
1977
-         avalue[i] = (char *) pst + 4;
 
1978
-         pst++;
 
1979
-         break;
 
1980
-#endif
 
1981
-
 
1982
-       case FFI_TYPE_SINT64:
 
1983
-       case FFI_TYPE_UINT64:
 
1984
-       case FFI_TYPE_POINTER:
 
1985
-         avalue[i] = pst;
 
1986
-         pst++;
 
1987
-         break;
 
1988
-
 
1989
-       case FFI_TYPE_STRUCT:
 
1990
-#ifdef __STRUCT_PARM_ALIGN__
 
1991
-         align = arg_types[i]->alignment;
 
1992
-         if (align > __STRUCT_PARM_ALIGN__)
 
1993
-           align = __STRUCT_PARM_ALIGN__;
 
1994
-         if (align > 1)
 
1995
-           pst = (unsigned long *) ALIGN ((size_t) pst, align);
 
1996
-#endif
 
1997
-         elt = 0;
 
1998
-#if _CALL_ELF == 2
 
1999
-         elt = discover_homogeneous_aggregate (arg_types[i], &elnum);
 
2000
-#endif
 
2001
-         if (elt)
 
2002
-           {
 
2003
-             union {
 
2004
-               void *v;
 
2005
-               unsigned long *ul;
 
2006
-               float *f;
 
2007
-               double *d;
 
2008
-               size_t p;
 
2009
-             } to, from;
 
2010
-
 
2011
-             /* Repackage the aggregate from its parts.  The
 
2012
-                aggregate size is not greater than the space taken by
 
2013
-                the registers so store back to the register/parameter
 
2014
-                save arrays.  */
 
2015
-             if (pfr + elnum <= end_pfr)
 
2016
-               to.v = pfr;
 
2017
-             else
 
2018
-               to.v = pst;
 
2019
-
 
2020
-             avalue[i] = to.v;
 
2021
-             from.ul = pst;
 
2022
-             if (elt == FFI_TYPE_FLOAT)
 
2023
-               {
 
2024
-                 do
 
2025
-                   {
 
2026
-                     if (pfr < end_pfr && i < nfixedargs)
 
2027
-                       {
 
2028
-                         *to.f = (float) pfr->d;
 
2029
-                         pfr++;
 
2030
-                       }
 
2031
-                     else
 
2032
-                       *to.f = *from.f;
 
2033
-                     to.f++;
 
2034
-                     from.f++;
 
2035
-                   }
 
2036
-                 while (--elnum != 0);
 
2037
-               }
 
2038
-             else
 
2039
-               {
 
2040
-                 do
 
2041
-                   {
 
2042
-                     if (pfr < end_pfr && i < nfixedargs)
 
2043
-                       {
 
2044
-                         *to.d = pfr->d;
 
2045
-                         pfr++;
 
2046
-                       }
 
2047
-                     else
 
2048
-                       *to.d = *from.d;
 
2049
-                     to.d++;
 
2050
-                     from.d++;
 
2051
-                   }
 
2052
-                 while (--elnum != 0);
 
2053
-               }
 
2054
-           }
 
2055
-         else
 
2056
-           {
 
2057
-#ifndef __LITTLE_ENDIAN__
 
2058
-             /* Structures with size less than eight bytes are passed
 
2059
-                left-padded.  */
 
2060
-             if (arg_types[i]->size < 8)
 
2061
-               avalue[i] = (char *) pst + 8 - arg_types[i]->size;
 
2062
-             else
 
2063
-#endif
 
2064
-               avalue[i] = pst;
 
2065
-           }
 
2066
-         pst += (arg_types[i]->size + 7) / 8;
 
2067
-         break;
 
2068
-
 
2069
-       case FFI_TYPE_FLOAT:
 
2070
-         /* unfortunately float values are stored as doubles
 
2071
-          * in the ffi_closure_LINUX64 code (since we don't check
 
2072
-          * the type in that routine).
 
2073
-          */
 
2074
-
 
2075
-         /* there are 13 64bit floating point registers */
 
2076
-
 
2077
-         if (pfr < end_pfr && i < nfixedargs)
 
2078
-           {
 
2079
-             double temp = pfr->d;
 
2080
-             pfr->f = (float) temp;
 
2081
-             avalue[i] = pfr;
 
2082
-             pfr++;
 
2083
-           }
 
2084
-         else
 
2085
-           avalue[i] = pst;
 
2086
-         pst++;
 
2087
-         break;
 
2088
-
 
2089
-       case FFI_TYPE_DOUBLE:
 
2090
-         /* On the outgoing stack all values are aligned to 8 */
 
2091
-         /* there are 13 64bit floating point registers */
 
2092
-
 
2093
-         if (pfr < end_pfr && i < nfixedargs)
 
2094
-           {
 
2095
-             avalue[i] = pfr;
 
2096
-             pfr++;
 
2097
-           }
 
2098
-         else
 
2099
-           avalue[i] = pst;
 
2100
-         pst++;
 
2101
-         break;
 
2102
-
 
2103
-#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2104
-       case FFI_TYPE_LONGDOUBLE:
 
2105
-         if (pfr + 1 < end_pfr && i + 1 < nfixedargs)
 
2106
-           {
 
2107
-             avalue[i] = pfr;
 
2108
-             pfr += 2;
 
2109
-           }
 
2110
-         else
 
2111
-           {
 
2112
-             if (pfr < end_pfr && i < nfixedargs)
 
2113
-               {
 
2114
-                 /* Passed partly in f13 and partly on the stack.
 
2115
-                    Move it all to the stack.  */
 
2116
-                 *pst = *(unsigned long *) pfr;
 
2117
-                 pfr++;
 
2118
-               }
 
2119
-             avalue[i] = pst;
 
2120
-           }
 
2121
-         pst += 2;
 
2122
-         break;
 
2123
-#endif
 
2124
-
 
2125
-       default:
 
2126
-         FFI_ASSERT (0);
 
2127
-       }
 
2128
-
 
2129
-      i++;
 
2130
-    }
 
2131
-
 
2132
-
 
2133
-  (closure->fun) (cif, rvalue, avalue, closure->user_data);
 
2134
-
 
2135
-  /* Tell ffi_closure_LINUX64 how to perform return type promotions.  */
 
2136
-  if ((cif->flags & FLAG_RETURNS_SMST) != 0)
 
2137
-    {
 
2138
-      if ((cif->flags & FLAG_RETURNS_FP) == 0)
 
2139
-       return FFI_V2_TYPE_SMALL_STRUCT + cif->rtype->size - 1;
 
2140
-      else if ((cif->flags & FLAG_RETURNS_64BITS) != 0)
 
2141
-       return FFI_V2_TYPE_DOUBLE_HOMOG;
 
2142
-      else
 
2143
-       return FFI_V2_TYPE_FLOAT_HOMOG;
 
2144
-    }
 
2145
-  return cif->rtype->type;
 
2146
-}
 
2147
--- a/src/libffi/src/powerpc/ffi_powerpc.h
 
2148
+++ b/src/libffi/src/powerpc/ffi_powerpc.h
 
2149
@@ -0,0 +1,77 @@
 
2150
+/* -----------------------------------------------------------------------
 
2151
+   ffi_powerpc.h - Copyright (C) 2013 IBM
 
2152
+                   Copyright (C) 2011 Anthony Green
 
2153
+                   Copyright (C) 2011 Kyle Moffett
 
2154
+                   Copyright (C) 2008 Red Hat, Inc
 
2155
+                   Copyright (C) 2007, 2008 Free Software Foundation, Inc
 
2156
+                   Copyright (c) 1998 Geoffrey Keating
 
2157
+
 
2158
+   PowerPC Foreign Function Interface
 
2159
+
 
2160
+   Permission is hereby granted, free of charge, to any person obtaining
 
2161
+   a copy of this software and associated documentation files (the
 
2162
+   ``Software''), to deal in the Software without restriction, including
 
2163
+   without limitation the rights to use, copy, modify, merge, publish,
 
2164
+   distribute, sublicense, and/or sell copies of the Software, and to
 
2165
+   permit persons to whom the Software is furnished to do so, subject to
 
2166
+   the following conditions:
 
2167
+
 
2168
+   The above copyright notice and this permission notice shall be included
 
2169
+   in all copies or substantial portions of the Software.
 
2170
+
 
2171
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
2172
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
2173
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
2174
+   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
2175
+   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
2176
+   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
2177
+   OTHER DEALINGS IN THE SOFTWARE.
 
2178
+   ----------------------------------------------------------------------- */
 
2179
+
 
2180
+enum {
 
2181
+  /* The assembly depends on these exact flags.  */
 
2182
+  /* These go in cr7 */
 
2183
+  FLAG_RETURNS_SMST    = 1 << (31-31), /* Used for FFI_SYSV small structs.  */
 
2184
+  FLAG_RETURNS_NOTHING  = 1 << (31-30),
 
2185
+  FLAG_RETURNS_FP       = 1 << (31-29),
 
2186
+  FLAG_RETURNS_64BITS   = 1 << (31-28),
 
2187
+
 
2188
+  /* This goes in cr6 */
 
2189
+  FLAG_RETURNS_128BITS  = 1 << (31-27),
 
2190
+
 
2191
+  FLAG_COMPAT          = 1 << (31- 8), /* Not used by assembly */
 
2192
+
 
2193
+  /* These go in cr1 */
 
2194
+  FLAG_ARG_NEEDS_COPY   = 1 << (31- 7), /* Used by sysv code */
 
2195
+  FLAG_ARG_NEEDS_PSAVE  = FLAG_ARG_NEEDS_COPY, /* Used by linux64 code */
 
2196
+  FLAG_FP_ARGUMENTS     = 1 << (31- 6), /* cr1.eq; specified by ABI */
 
2197
+  FLAG_4_GPR_ARGUMENTS  = 1 << (31- 5),
 
2198
+  FLAG_RETVAL_REFERENCE = 1 << (31- 4)
 
2199
+};
 
2200
+
 
2201
+typedef union
 
2202
+{
 
2203
+  float f;
 
2204
+  double d;
 
2205
+} ffi_dblfl;
 
2206
+
 
2207
+void FFI_HIDDEN ffi_closure_SYSV (void);
 
2208
+void FFI_HIDDEN ffi_call_SYSV(extended_cif *, unsigned, unsigned, unsigned *,
 
2209
+                             void (*)(void));
 
2210
+
 
2211
+void FFI_HIDDEN ffi_prep_types_sysv (ffi_abi);
 
2212
+ffi_status FFI_HIDDEN ffi_prep_cif_sysv (ffi_cif *);
 
2213
+int FFI_HIDDEN ffi_closure_helper_SYSV (ffi_closure *, void *, unsigned long *,
 
2214
+                                       ffi_dblfl *, unsigned long *);
 
2215
+
 
2216
+void FFI_HIDDEN ffi_call_LINUX64(extended_cif *, unsigned long, unsigned long,
 
2217
+                                unsigned long *, void (*)(void));
 
2218
+void FFI_HIDDEN ffi_closure_LINUX64 (void);
 
2219
+
 
2220
+void FFI_HIDDEN ffi_prep_types_linux64 (ffi_abi);
 
2221
+ffi_status FFI_HIDDEN ffi_prep_cif_linux64 (ffi_cif *);
 
2222
+ffi_status FFI_HIDDEN ffi_prep_cif_linux64_var (ffi_cif *, unsigned int,
 
2223
+                                               unsigned int);
 
2224
+void FFI_HIDDEN ffi_prep_args64 (extended_cif *, unsigned long *const);
 
2225
+int FFI_HIDDEN ffi_closure_helper_LINUX64 (ffi_closure *, void *,
 
2226
+                                          unsigned long *, ffi_dblfl *);
 
2227
--- a/src/libffi/src/powerpc/ffitarget.h
 
2228
+++ b/src/libffi/src/powerpc/ffitarget.h
 
2229
@@ -60,45 +60,76 @@
 
2230
 typedef enum ffi_abi {
 
2231
   FFI_FIRST_ABI = 0,
 
2232
 
 
2233
-#ifdef POWERPC
 
2234
-  FFI_SYSV,
 
2235
-  FFI_GCC_SYSV,
 
2236
-  FFI_LINUX64,
 
2237
-  FFI_LINUX,
 
2238
-  FFI_LINUX_SOFT_FLOAT,
 
2239
-# if defined(POWERPC64)
 
2240
-  FFI_DEFAULT_ABI = FFI_LINUX64,
 
2241
-# elif defined(__NO_FPRS__)
 
2242
-  FFI_DEFAULT_ABI = FFI_LINUX_SOFT_FLOAT,
 
2243
-# elif (__LDBL_MANT_DIG__ == 106)
 
2244
-  FFI_DEFAULT_ABI = FFI_LINUX,
 
2245
-# else
 
2246
-  FFI_DEFAULT_ABI = FFI_GCC_SYSV,
 
2247
-# endif
 
2248
-#endif
 
2249
-
 
2250
-#ifdef POWERPC_AIX
 
2251
+#if defined (POWERPC_AIX)
 
2252
   FFI_AIX,
 
2253
   FFI_DARWIN,
 
2254
   FFI_DEFAULT_ABI = FFI_AIX,
 
2255
-#endif
 
2256
+  FFI_LAST_ABI
 
2257
 
 
2258
-#ifdef POWERPC_DARWIN
 
2259
+#elif defined (POWERPC_DARWIN)
 
2260
   FFI_AIX,
 
2261
   FFI_DARWIN,
 
2262
   FFI_DEFAULT_ABI = FFI_DARWIN,
 
2263
-#endif
 
2264
+  FFI_LAST_ABI
 
2265
 
 
2266
-#ifdef POWERPC_FREEBSD
 
2267
-  FFI_SYSV,
 
2268
-  FFI_GCC_SYSV,
 
2269
-  FFI_LINUX64,
 
2270
-  FFI_LINUX,
 
2271
-  FFI_LINUX_SOFT_FLOAT,
 
2272
-  FFI_DEFAULT_ABI = FFI_SYSV,
 
2273
+#else
 
2274
+  /* The FFI_COMPAT values are used by old code.  Since libffi may be
 
2275
+     a shared library we have to support old values for backwards
 
2276
+     compatibility.  */
 
2277
+  FFI_COMPAT_SYSV,
 
2278
+  FFI_COMPAT_GCC_SYSV,
 
2279
+  FFI_COMPAT_LINUX64,
 
2280
+  FFI_COMPAT_LINUX,
 
2281
+  FFI_COMPAT_LINUX_SOFT_FLOAT,
 
2282
+
 
2283
+# if defined (POWERPC64)
 
2284
+  /* This bit, always set in new code, must not be set in any of the
 
2285
+     old FFI_COMPAT values that might be used for 64-bit linux.  We
 
2286
+     only need worry about FFI_COMPAT_LINUX64, but to be safe avoid
 
2287
+     all old values.  */
 
2288
+  FFI_LINUX = 8,
 
2289
+  /* This and following bits can reuse FFI_COMPAT values.  */
 
2290
+  FFI_LINUX_STRUCT_ALIGN = 1,
 
2291
+  FFI_LINUX_LONG_DOUBLE_128 = 2,
 
2292
+  FFI_DEFAULT_ABI = (FFI_LINUX
 
2293
+#  ifdef __STRUCT_PARM_ALIGN__
 
2294
+                    | FFI_LINUX_STRUCT_ALIGN
 
2295
+#  endif
 
2296
+#  ifdef __LONG_DOUBLE_128__
 
2297
+                    | FFI_LINUX_LONG_DOUBLE_128
 
2298
+#  endif
 
2299
+                    ),
 
2300
+  FFI_LAST_ABI = 12
 
2301
+
 
2302
+# else
 
2303
+  /* This bit, always set in new code, must not be set in any of the
 
2304
+     old FFI_COMPAT values that might be used for 32-bit linux/sysv/bsd.  */
 
2305
+  FFI_SYSV = 8,
 
2306
+  /* This and following bits can reuse FFI_COMPAT values.  */
 
2307
+  FFI_SYSV_SOFT_FLOAT = 1,
 
2308
+  FFI_SYSV_STRUCT_RET = 2,
 
2309
+  FFI_SYSV_IBM_LONG_DOUBLE = 4,
 
2310
+  FFI_SYSV_LONG_DOUBLE_128 = 16,
 
2311
+
 
2312
+  FFI_DEFAULT_ABI = (FFI_SYSV
 
2313
+#  ifdef __NO_FPRS__
 
2314
+                    | FFI_SYSV_SOFT_FLOAT
 
2315
+#  endif
 
2316
+#  if (defined (__SVR4_STRUCT_RETURN)                                  \
 
2317
+       || defined (POWERPC_FREEBSD) && !defined (__AIX_STRUCT_RETURN))
 
2318
+                    | FFI_SYSV_STRUCT_RET
 
2319
+#  endif
 
2320
+#  if __LDBL_MANT_DIG__ == 106
 
2321
+                    | FFI_SYSV_IBM_LONG_DOUBLE
 
2322
+#  endif
 
2323
+#  ifdef __LONG_DOUBLE_128__
 
2324
+                    | FFI_SYSV_LONG_DOUBLE_128
 
2325
+#  endif
 
2326
+                    ),
 
2327
+  FFI_LAST_ABI = 32
 
2328
+# endif
 
2329
 #endif
 
2330
 
 
2331
-  FFI_LAST_ABI
 
2332
 } ffi_abi;
 
2333
 #endif
 
2334
 
 
2335
@@ -117,9 +148,7 @@
 
2336
 /* Needed for soft-float long-double-128 support.  */
 
2337
 #define FFI_TYPE_UINT128 (FFI_TYPE_LAST + 1)
 
2338
 
 
2339
-/* Needed for FFI_SYSV small structure returns.
 
2340
-   We use two flag bits, (FLAG_SYSV_SMST_R3, FLAG_SYSV_SMST_R4) which are
 
2341
-   defined in ffi.c, to determine the exact return type and its size.  */
 
2342
+/* Needed for FFI_SYSV small structure returns.  */
 
2343
 #define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 2)
 
2344
 
 
2345
 /* Used by ELFv2 for homogenous structure returns.  */
 
2346
--- a/src/libffi/src/powerpc/sysv.S
 
2347
+++ b/src/libffi/src/powerpc/sysv.S
 
2348
@@ -30,7 +30,7 @@
 
2349
 #include <ffi.h>
 
2350
 #include <powerpc/asm.h>
 
2351
 
 
2352
-#ifndef __powerpc64__
 
2353
+#ifndef POWERPC64
 
2354
        .globl ffi_prep_args_SYSV
 
2355
 ENTRY(ffi_call_SYSV)
 
2356
 .LFB1:
 
2357
@@ -213,8 +213,8 @@
 
2358
       .uleb128  0x1c
 
2359
       .align 2
 
2360
 .LEFDE1:
 
2361
-#endif
 
2362
 
 
2363
 #if defined __ELF__ && defined __linux__
 
2364
        .section        .note.GNU-stack,"",@progbits
 
2365
 #endif
 
2366
+#endif
 
2367
--- a/src/libffi/src/powerpc/linux64_closure.S
 
2368
+++ b/src/libffi/src/powerpc/linux64_closure.S
 
2369
@@ -30,7 +30,7 @@
 
2370
 
 
2371
        .file   "linux64_closure.S"
 
2372
 
 
2373
-#ifdef __powerpc64__
 
2374
+#ifdef POWERPC64
 
2375
        FFI_HIDDEN (ffi_closure_LINUX64)
 
2376
        .globl  ffi_closure_LINUX64
 
2377
 # if _CALL_ELF == 2
 
2378
@@ -60,13 +60,11 @@
 
2379
 # endif
 
2380
 
 
2381
 # if _CALL_ELF == 2
 
2382
-#  32 byte special reg save area + 64 byte parm save area and retval
 
2383
-#  + 13*8 fpr save area + round to 16
 
2384
-#  define STACKFRAME 208
 
2385
+#  32 byte special reg save area + 64 byte parm save area
 
2386
+#  + 64 byte retval area + 13*8 fpr save area + round to 16
 
2387
+#  define STACKFRAME 272
 
2388
 #  define PARMSAVE 32
 
2389
-#  No parameter save area is needed for the call to ffi_closure_helper_LINUX64,
 
2390
-#  so return value can start there.
 
2391
-#  define RETVAL PARMSAVE
 
2392
+#  define RETVAL PARMSAVE+64
 
2393
 # else
 
2394
 #  48 bytes special reg save area + 64 bytes parm save area
 
2395
 #  + 16 bytes retval area + 13*8 bytes fpr save area + round to 16
 
2396
@@ -85,8 +83,8 @@
 
2397
        bt      7, .Lparmsave
 
2398
        # Our caller has not allocated a parameter save area.
 
2399
        # We need to allocate one here and use it to pass gprs to
 
2400
-       # ffi_closure_helper_LINUX64.  The return value area will do.
 
2401
-       addi    %r12, %r1, -STACKFRAME+RETVAL
 
2402
+       # ffi_closure_helper_LINUX64.
 
2403
+       addi    %r12, %r1, -STACKFRAME+PARMSAVE
 
2404
 .Lparmsave:
 
2405
        std     %r0, 16(%r1)
 
2406
        # Save general regs into parm save area
 
2407
--- a/src/libffi/src/powerpc/ffi_sysv.c
 
2408
+++ b/src/libffi/src/powerpc/ffi_sysv.c
 
2409
@@ -0,0 +1,931 @@
 
2410
+/* -----------------------------------------------------------------------
 
2411
+   ffi_sysv.c - Copyright (C) 2013 IBM
 
2412
+                Copyright (C) 2011 Anthony Green
 
2413
+                Copyright (C) 2011 Kyle Moffett
 
2414
+                Copyright (C) 2008 Red Hat, Inc
 
2415
+                Copyright (C) 2007, 2008 Free Software Foundation, Inc
 
2416
+                Copyright (c) 1998 Geoffrey Keating
 
2417
+
 
2418
+   PowerPC Foreign Function Interface
 
2419
+
 
2420
+   Permission is hereby granted, free of charge, to any person obtaining
 
2421
+   a copy of this software and associated documentation files (the
 
2422
+   ``Software''), to deal in the Software without restriction, including
 
2423
+   without limitation the rights to use, copy, modify, merge, publish,
 
2424
+   distribute, sublicense, and/or sell copies of the Software, and to
 
2425
+   permit persons to whom the Software is furnished to do so, subject to
 
2426
+   the following conditions:
 
2427
+
 
2428
+   The above copyright notice and this permission notice shall be included
 
2429
+   in all copies or substantial portions of the Software.
 
2430
+
 
2431
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
2432
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
2433
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
2434
+   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
2435
+   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
2436
+   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
2437
+   OTHER DEALINGS IN THE SOFTWARE.
 
2438
+   ----------------------------------------------------------------------- */
 
2439
+
 
2440
+#include "ffi.h"
 
2441
+
 
2442
+#ifndef POWERPC64
 
2443
+#include "ffi_common.h"
 
2444
+#include "ffi_powerpc.h"
 
2445
+
 
2446
+
 
2447
+/* About the SYSV ABI.  */
 
2448
+#define ASM_NEEDS_REGISTERS 4
 
2449
+#define NUM_GPR_ARG_REGISTERS 8
 
2450
+#define NUM_FPR_ARG_REGISTERS 8
 
2451
+
 
2452
+
 
2453
+#if HAVE_LONG_DOUBLE_VARIANT && FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2454
+/* Adjust size of ffi_type_longdouble.  */
 
2455
+void FFI_HIDDEN
 
2456
+ffi_prep_types_sysv (ffi_abi abi)
 
2457
+{
 
2458
+  if ((abi & (FFI_SYSV | FFI_SYSV_LONG_DOUBLE_128)) == FFI_SYSV)
 
2459
+    {
 
2460
+      ffi_type_longdouble.size = 8;
 
2461
+      ffi_type_longdouble.alignment = 8;
 
2462
+    }
 
2463
+  else
 
2464
+    {
 
2465
+      ffi_type_longdouble.size = 16;
 
2466
+      ffi_type_longdouble.alignment = 16;
 
2467
+    }
 
2468
+}
 
2469
+#endif
 
2470
+
 
2471
+/* Transform long double, double and float to other types as per abi.  */
 
2472
+static int
 
2473
+translate_float (int abi, int type)
 
2474
+{
 
2475
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2476
+  if (type == FFI_TYPE_LONGDOUBLE
 
2477
+      && (abi & FFI_SYSV_LONG_DOUBLE_128) == 0)
 
2478
+    type = FFI_TYPE_DOUBLE;
 
2479
+#endif
 
2480
+  if ((abi & FFI_SYSV_SOFT_FLOAT) != 0)
 
2481
+    {
 
2482
+      if (type == FFI_TYPE_FLOAT)
 
2483
+       type = FFI_TYPE_UINT32;
 
2484
+      else if (type == FFI_TYPE_DOUBLE)
 
2485
+       type = FFI_TYPE_UINT64;
 
2486
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2487
+      else if (type == FFI_TYPE_LONGDOUBLE)
 
2488
+       type = FFI_TYPE_UINT128;
 
2489
+    }
 
2490
+  else if ((abi & FFI_SYSV_IBM_LONG_DOUBLE) == 0)
 
2491
+    {
 
2492
+      if (type == FFI_TYPE_LONGDOUBLE)
 
2493
+       type = FFI_TYPE_STRUCT;
 
2494
+#endif
 
2495
+    }
 
2496
+  return type;
 
2497
+}
 
2498
+
 
2499
+/* Perform machine dependent cif processing */
 
2500
+static ffi_status
 
2501
+ffi_prep_cif_sysv_core (ffi_cif *cif)
 
2502
+{
 
2503
+  ffi_type **ptr;
 
2504
+  unsigned bytes;
 
2505
+  unsigned i, fparg_count = 0, intarg_count = 0;
 
2506
+  unsigned flags = cif->flags;
 
2507
+  unsigned struct_copy_size = 0;
 
2508
+  unsigned type = cif->rtype->type;
 
2509
+  unsigned size = cif->rtype->size;
 
2510
+
 
2511
+  /* The machine-independent calculation of cif->bytes doesn't work
 
2512
+     for us.  Redo the calculation.  */
 
2513
+
 
2514
+  /* Space for the frame pointer, callee's LR, and the asm's temp regs.  */
 
2515
+  bytes = (2 + ASM_NEEDS_REGISTERS) * sizeof (int);
 
2516
+
 
2517
+  /* Space for the GPR registers.  */
 
2518
+  bytes += NUM_GPR_ARG_REGISTERS * sizeof (int);
 
2519
+
 
2520
+  /* Return value handling.  The rules for SYSV are as follows:
 
2521
+     - 32-bit (or less) integer values are returned in gpr3;
 
2522
+     - Structures of size <= 4 bytes also returned in gpr3;
 
2523
+     - 64-bit integer values and structures between 5 and 8 bytes are returned
 
2524
+     in gpr3 and gpr4;
 
2525
+     - Larger structures are allocated space and a pointer is passed as
 
2526
+     the first argument.
 
2527
+     - Single/double FP values are returned in fpr1;
 
2528
+     - long doubles (if not equivalent to double) are returned in
 
2529
+     fpr1,fpr2 for Linux and as for large structs for SysV.  */
 
2530
+
 
2531
+  type = translate_float (cif->abi, type);
 
2532
+
 
2533
+  switch (type)
 
2534
+    {
 
2535
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2536
+    case FFI_TYPE_LONGDOUBLE:
 
2537
+      flags |= FLAG_RETURNS_128BITS;
 
2538
+      /* Fall through.  */
 
2539
+#endif
 
2540
+    case FFI_TYPE_DOUBLE:
 
2541
+      flags |= FLAG_RETURNS_64BITS;
 
2542
+      /* Fall through.  */
 
2543
+    case FFI_TYPE_FLOAT:
 
2544
+      flags |= FLAG_RETURNS_FP;
 
2545
+#ifdef __NO_FPRS__
 
2546
+      return FFI_BAD_ABI;
 
2547
+#endif
 
2548
+      break;
 
2549
+
 
2550
+    case FFI_TYPE_UINT128:
 
2551
+      flags |= FLAG_RETURNS_128BITS;
 
2552
+      /* Fall through.  */
 
2553
+    case FFI_TYPE_UINT64:
 
2554
+    case FFI_TYPE_SINT64:
 
2555
+      flags |= FLAG_RETURNS_64BITS;
 
2556
+      break;
 
2557
+
 
2558
+    case FFI_TYPE_STRUCT:
 
2559
+      /* The final SYSV ABI says that structures smaller or equal 8 bytes
 
2560
+        are returned in r3/r4.  A draft ABI used by linux instead
 
2561
+        returns them in memory.  */
 
2562
+      if ((cif->abi & FFI_SYSV_STRUCT_RET) != 0 && size <= 8)
 
2563
+       {
 
2564
+         flags |= FLAG_RETURNS_SMST;
 
2565
+         break;
 
2566
+       }
 
2567
+      intarg_count++;
 
2568
+      flags |= FLAG_RETVAL_REFERENCE;
 
2569
+      /* Fall through.  */
 
2570
+    case FFI_TYPE_VOID:
 
2571
+      flags |= FLAG_RETURNS_NOTHING;
 
2572
+      break;
 
2573
+
 
2574
+    default:
 
2575
+      /* Returns 32-bit integer, or similar.  Nothing to do here.  */
 
2576
+      break;
 
2577
+    }
 
2578
+
 
2579
+  /* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
 
2580
+     first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
 
2581
+     goes on the stack.  Structures and long doubles (if not equivalent
 
2582
+     to double) are passed as a pointer to a copy of the structure.
 
2583
+     Stuff on the stack needs to keep proper alignment.  */
 
2584
+  for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
 
2585
+    {
 
2586
+      unsigned short typenum = (*ptr)->type;
 
2587
+
 
2588
+      typenum = translate_float (cif->abi, typenum);
 
2589
+
 
2590
+      switch (typenum)
 
2591
+       {
 
2592
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2593
+       case FFI_TYPE_LONGDOUBLE:
 
2594
+         fparg_count++;
 
2595
+         /* Fall thru */
 
2596
+#endif
 
2597
+       case FFI_TYPE_DOUBLE:
 
2598
+         fparg_count++;
 
2599
+         /* If this FP arg is going on the stack, it must be
 
2600
+            8-byte-aligned.  */
 
2601
+         if (fparg_count > NUM_FPR_ARG_REGISTERS
 
2602
+             && intarg_count >= NUM_GPR_ARG_REGISTERS
 
2603
+             && intarg_count % 2 != 0)
 
2604
+           intarg_count++;
 
2605
+#ifdef __NO_FPRS__
 
2606
+         return FFI_BAD_ABI;
 
2607
+#endif
 
2608
+         break;
 
2609
+
 
2610
+       case FFI_TYPE_FLOAT:
 
2611
+         fparg_count++;
 
2612
+#ifdef __NO_FPRS__
 
2613
+         return FFI_BAD_ABI;
 
2614
+#endif
 
2615
+         break;
 
2616
+
 
2617
+       case FFI_TYPE_UINT128:
 
2618
+         /* A long double in FFI_LINUX_SOFT_FLOAT can use only a set
 
2619
+            of four consecutive gprs. If we do not have enough, we
 
2620
+            have to adjust the intarg_count value.  */
 
2621
+         if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3
 
2622
+             && intarg_count < NUM_GPR_ARG_REGISTERS)
 
2623
+           intarg_count = NUM_GPR_ARG_REGISTERS;
 
2624
+         intarg_count += 4;
 
2625
+         break;
 
2626
+
 
2627
+       case FFI_TYPE_UINT64:
 
2628
+       case FFI_TYPE_SINT64:
 
2629
+         /* 'long long' arguments are passed as two words, but
 
2630
+            either both words must fit in registers or both go
 
2631
+            on the stack.  If they go on the stack, they must
 
2632
+            be 8-byte-aligned.
 
2633
+
 
2634
+            Also, only certain register pairs can be used for
 
2635
+            passing long long int -- specifically (r3,r4), (r5,r6),
 
2636
+            (r7,r8), (r9,r10).  */
 
2637
+         if (intarg_count == NUM_GPR_ARG_REGISTERS-1
 
2638
+             || intarg_count % 2 != 0)
 
2639
+           intarg_count++;
 
2640
+         intarg_count += 2;
 
2641
+         break;
 
2642
+
 
2643
+       case FFI_TYPE_STRUCT:
 
2644
+         /* We must allocate space for a copy of these to enforce
 
2645
+            pass-by-value.  Pad the space up to a multiple of 16
 
2646
+            bytes (the maximum alignment required for anything under
 
2647
+            the SYSV ABI).  */
 
2648
+         struct_copy_size += ((*ptr)->size + 15) & ~0xF;
 
2649
+         /* Fall through (allocate space for the pointer).  */
 
2650
+
 
2651
+       case FFI_TYPE_POINTER:
 
2652
+       case FFI_TYPE_INT:
 
2653
+       case FFI_TYPE_UINT32:
 
2654
+       case FFI_TYPE_SINT32:
 
2655
+       case FFI_TYPE_UINT16:
 
2656
+       case FFI_TYPE_SINT16:
 
2657
+       case FFI_TYPE_UINT8:
 
2658
+       case FFI_TYPE_SINT8:
 
2659
+         /* Everything else is passed as a 4-byte word in a GPR, either
 
2660
+            the object itself or a pointer to it.  */
 
2661
+         intarg_count++;
 
2662
+         break;
 
2663
+
 
2664
+       default:
 
2665
+         FFI_ASSERT (0);
 
2666
+       }
 
2667
+    }
 
2668
+
 
2669
+  if (fparg_count != 0)
 
2670
+    flags |= FLAG_FP_ARGUMENTS;
 
2671
+  if (intarg_count > 4)
 
2672
+    flags |= FLAG_4_GPR_ARGUMENTS;
 
2673
+  if (struct_copy_size != 0)
 
2674
+    flags |= FLAG_ARG_NEEDS_COPY;
 
2675
+
 
2676
+  /* Space for the FPR registers, if needed.  */
 
2677
+  if (fparg_count != 0)
 
2678
+    bytes += NUM_FPR_ARG_REGISTERS * sizeof (double);
 
2679
+
 
2680
+  /* Stack space.  */
 
2681
+  if (intarg_count > NUM_GPR_ARG_REGISTERS)
 
2682
+    bytes += (intarg_count - NUM_GPR_ARG_REGISTERS) * sizeof (int);
 
2683
+  if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
2684
+    bytes += (fparg_count - NUM_FPR_ARG_REGISTERS) * sizeof (double);
 
2685
+
 
2686
+  /* The stack space allocated needs to be a multiple of 16 bytes.  */
 
2687
+  bytes = (bytes + 15) & ~0xF;
 
2688
+
 
2689
+  /* Add in the space for the copied structures.  */
 
2690
+  bytes += struct_copy_size;
 
2691
+
 
2692
+  cif->flags = flags;
 
2693
+  cif->bytes = bytes;
 
2694
+
 
2695
+  return FFI_OK;
 
2696
+}
 
2697
+
 
2698
+ffi_status FFI_HIDDEN
 
2699
+ffi_prep_cif_sysv (ffi_cif *cif)
 
2700
+{
 
2701
+  if ((cif->abi & FFI_SYSV) == 0)
 
2702
+    {
 
2703
+      /* This call is from old code.  Translate to new ABI values.  */
 
2704
+      cif->flags |= FLAG_COMPAT;
 
2705
+      switch (cif->abi)
 
2706
+       {
 
2707
+       default:
 
2708
+         return FFI_BAD_ABI;
 
2709
+
 
2710
+       case FFI_COMPAT_SYSV:
 
2711
+         cif->abi = FFI_SYSV | FFI_SYSV_STRUCT_RET | FFI_SYSV_LONG_DOUBLE_128;
 
2712
+         break;
 
2713
+
 
2714
+       case FFI_COMPAT_GCC_SYSV:
 
2715
+         cif->abi = FFI_SYSV | FFI_SYSV_LONG_DOUBLE_128;
 
2716
+         break;
 
2717
+
 
2718
+       case FFI_COMPAT_LINUX:
 
2719
+         cif->abi = (FFI_SYSV | FFI_SYSV_IBM_LONG_DOUBLE
 
2720
+                     | FFI_SYSV_LONG_DOUBLE_128);
 
2721
+         break;
 
2722
+
 
2723
+       case FFI_COMPAT_LINUX_SOFT_FLOAT:
 
2724
+         cif->abi = (FFI_SYSV | FFI_SYSV_SOFT_FLOAT | FFI_SYSV_IBM_LONG_DOUBLE
 
2725
+                     | FFI_SYSV_LONG_DOUBLE_128);
 
2726
+         break;
 
2727
+       }
 
2728
+    }
 
2729
+  return ffi_prep_cif_sysv_core (cif);
 
2730
+}
 
2731
+
 
2732
+/* ffi_prep_args_SYSV is called by the assembly routine once stack space
 
2733
+   has been allocated for the function's arguments.
 
2734
+
 
2735
+   The stack layout we want looks like this:
 
2736
+
 
2737
+   |   Return address from ffi_call_SYSV 4bytes        |       higher addresses
 
2738
+   |--------------------------------------------|
 
2739
+   |   Previous backchain pointer      4       |       stack pointer here
 
2740
+   |--------------------------------------------|<+ <<<        on entry to
 
2741
+   |   Saved r28-r31                   4*4     | |     ffi_call_SYSV
 
2742
+   |--------------------------------------------| |
 
2743
+   |   GPR registers r3-r10            8*4     | |     ffi_call_SYSV
 
2744
+   |--------------------------------------------| |
 
2745
+   |   FPR registers f1-f8 (optional)  8*8     | |
 
2746
+   |--------------------------------------------| |    stack   |
 
2747
+   |   Space for copied structures             | |     grows   |
 
2748
+   |--------------------------------------------| |    down    V
 
2749
+   |   Parameters that didn't fit in registers  | |
 
2750
+   |--------------------------------------------| |    lower addresses
 
2751
+   |   Space for callee's LR           4       | |
 
2752
+   |--------------------------------------------| |    stack pointer here
 
2753
+   |   Current backchain pointer       4       |-/     during
 
2754
+   |--------------------------------------------|   <<<        ffi_call_SYSV
 
2755
+
 
2756
+*/
 
2757
+
 
2758
+void FFI_HIDDEN
 
2759
+ffi_prep_args_SYSV (extended_cif *ecif, unsigned *const stack)
 
2760
+{
 
2761
+  const unsigned bytes = ecif->cif->bytes;
 
2762
+  const unsigned flags = ecif->cif->flags;
 
2763
+
 
2764
+  typedef union
 
2765
+  {
 
2766
+    char *c;
 
2767
+    unsigned *u;
 
2768
+    long long *ll;
 
2769
+    float *f;
 
2770
+    double *d;
 
2771
+  } valp;
 
2772
+
 
2773
+  /* 'stacktop' points at the previous backchain pointer.  */
 
2774
+  valp stacktop;
 
2775
+
 
2776
+  /* 'gpr_base' points at the space for gpr3, and grows upwards as
 
2777
+     we use GPR registers.  */
 
2778
+  valp gpr_base;
 
2779
+  int intarg_count;
 
2780
+
 
2781
+#ifndef __NO_FPRS__
 
2782
+  /* 'fpr_base' points at the space for fpr1, and grows upwards as
 
2783
+     we use FPR registers.  */
 
2784
+  valp fpr_base;
 
2785
+  int fparg_count;
 
2786
+#endif
 
2787
+
 
2788
+  /* 'copy_space' grows down as we put structures in it.  It should
 
2789
+     stay 16-byte aligned.  */
 
2790
+  valp copy_space;
 
2791
+
 
2792
+  /* 'next_arg' grows up as we put parameters in it.  */
 
2793
+  valp next_arg;
 
2794
+
 
2795
+  int i;
 
2796
+  ffi_type **ptr;
 
2797
+#ifndef __NO_FPRS__
 
2798
+  double double_tmp;
 
2799
+#endif
 
2800
+  union
 
2801
+  {
 
2802
+    void **v;
 
2803
+    char **c;
 
2804
+    signed char **sc;
 
2805
+    unsigned char **uc;
 
2806
+    signed short **ss;
 
2807
+    unsigned short **us;
 
2808
+    unsigned int **ui;
 
2809
+    long long **ll;
 
2810
+    float **f;
 
2811
+    double **d;
 
2812
+  } p_argv;
 
2813
+  size_t struct_copy_size;
 
2814
+  unsigned gprvalue;
 
2815
+
 
2816
+  stacktop.c = (char *) stack + bytes;
 
2817
+  gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS;
 
2818
+  intarg_count = 0;
 
2819
+#ifndef __NO_FPRS__
 
2820
+  fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS;
 
2821
+  fparg_count = 0;
 
2822
+  copy_space.c = ((flags & FLAG_FP_ARGUMENTS) ? fpr_base.c : gpr_base.c);
 
2823
+#else
 
2824
+  copy_space.c = gpr_base.c;
 
2825
+#endif
 
2826
+  next_arg.u = stack + 2;
 
2827
+
 
2828
+  /* Check that everything starts aligned properly.  */
 
2829
+  FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0);
 
2830
+  FFI_ASSERT (((unsigned long) copy_space.c & 0xF) == 0);
 
2831
+  FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0);
 
2832
+  FFI_ASSERT ((bytes & 0xF) == 0);
 
2833
+  FFI_ASSERT (copy_space.c >= next_arg.c);
 
2834
+
 
2835
+  /* Deal with return values that are actually pass-by-reference.  */
 
2836
+  if (flags & FLAG_RETVAL_REFERENCE)
 
2837
+    {
 
2838
+      *gpr_base.u++ = (unsigned long) (char *) ecif->rvalue;
 
2839
+      intarg_count++;
 
2840
+    }
 
2841
+
 
2842
+  /* Now for the arguments.  */
 
2843
+  p_argv.v = ecif->avalue;
 
2844
+  for (ptr = ecif->cif->arg_types, i = ecif->cif->nargs;
 
2845
+       i > 0;
 
2846
+       i--, ptr++, p_argv.v++)
 
2847
+    {
 
2848
+      unsigned int typenum = (*ptr)->type;
 
2849
+
 
2850
+      typenum = translate_float (ecif->cif->abi, typenum);
 
2851
+
 
2852
+      /* Now test the translated value */
 
2853
+      switch (typenum)
 
2854
+       {
 
2855
+#ifndef __NO_FPRS__
 
2856
+# if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
2857
+       case FFI_TYPE_LONGDOUBLE:
 
2858
+         double_tmp = (*p_argv.d)[0];
 
2859
+
 
2860
+         if (fparg_count >= NUM_FPR_ARG_REGISTERS - 1)
 
2861
+           {
 
2862
+             if (intarg_count >= NUM_GPR_ARG_REGISTERS
 
2863
+                 && intarg_count % 2 != 0)
 
2864
+               {
 
2865
+                 intarg_count++;
 
2866
+                 next_arg.u++;
 
2867
+               }
 
2868
+             *next_arg.d = double_tmp;
 
2869
+             next_arg.u += 2;
 
2870
+             double_tmp = (*p_argv.d)[1];
 
2871
+             *next_arg.d = double_tmp;
 
2872
+             next_arg.u += 2;
 
2873
+           }
 
2874
+         else
 
2875
+           {
 
2876
+             *fpr_base.d++ = double_tmp;
 
2877
+             double_tmp = (*p_argv.d)[1];
 
2878
+             *fpr_base.d++ = double_tmp;
 
2879
+           }
 
2880
+
 
2881
+         fparg_count += 2;
 
2882
+         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
2883
+         break;
 
2884
+# endif
 
2885
+       case FFI_TYPE_DOUBLE:
 
2886
+         double_tmp = **p_argv.d;
 
2887
+
 
2888
+         if (fparg_count >= NUM_FPR_ARG_REGISTERS)
 
2889
+           {
 
2890
+             if (intarg_count >= NUM_GPR_ARG_REGISTERS
 
2891
+                 && intarg_count % 2 != 0)
 
2892
+               {
 
2893
+                 intarg_count++;
 
2894
+                 next_arg.u++;
 
2895
+               }
 
2896
+             *next_arg.d = double_tmp;
 
2897
+             next_arg.u += 2;
 
2898
+           }
 
2899
+         else
 
2900
+           *fpr_base.d++ = double_tmp;
 
2901
+         fparg_count++;
 
2902
+         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
2903
+         break;
 
2904
+
 
2905
+       case FFI_TYPE_FLOAT:
 
2906
+         double_tmp = **p_argv.f;
 
2907
+         if (fparg_count >= NUM_FPR_ARG_REGISTERS)
 
2908
+           {
 
2909
+             *next_arg.f = (float) double_tmp;
 
2910
+             next_arg.u += 1;
 
2911
+             intarg_count++;
 
2912
+           }
 
2913
+         else
 
2914
+           *fpr_base.d++ = double_tmp;
 
2915
+         fparg_count++;
 
2916
+         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
2917
+         break;
 
2918
+#endif /* have FPRs */
 
2919
+
 
2920
+       case FFI_TYPE_UINT128:
 
2921
+         /* The soft float ABI for long doubles works like this, a long double
 
2922
+            is passed in four consecutive GPRs if available.  A maximum of 2
 
2923
+            long doubles can be passed in gprs.  If we do not have 4 GPRs
 
2924
+            left, the long double is passed on the stack, 4-byte aligned.  */
 
2925
+         {
 
2926
+           unsigned int int_tmp;
 
2927
+           unsigned int ii;
 
2928
+           if (intarg_count >= NUM_GPR_ARG_REGISTERS - 3)
 
2929
+             {
 
2930
+               if (intarg_count < NUM_GPR_ARG_REGISTERS)
 
2931
+                 intarg_count = NUM_GPR_ARG_REGISTERS;
 
2932
+               for (ii = 0; ii < 4; ii++)
 
2933
+                 {
 
2934
+                   int_tmp = (*p_argv.ui)[ii];
 
2935
+                   *next_arg.u++ = int_tmp;
 
2936
+                 }
 
2937
+             }
 
2938
+           else
 
2939
+             {
 
2940
+               for (ii = 0; ii < 4; ii++)
 
2941
+                 {
 
2942
+                   int_tmp = (*p_argv.ui)[ii];
 
2943
+                   *gpr_base.u++ = int_tmp;
 
2944
+                 }
 
2945
+             }
 
2946
+           intarg_count += 4;
 
2947
+           break;
 
2948
+         }
 
2949
+
 
2950
+       case FFI_TYPE_UINT64:
 
2951
+       case FFI_TYPE_SINT64:
 
2952
+         if (intarg_count == NUM_GPR_ARG_REGISTERS-1)
 
2953
+           intarg_count++;
 
2954
+         if (intarg_count >= NUM_GPR_ARG_REGISTERS)
 
2955
+           {
 
2956
+             if (intarg_count % 2 != 0)
 
2957
+               {
 
2958
+                 intarg_count++;
 
2959
+                 next_arg.u++;
 
2960
+               }
 
2961
+             *next_arg.ll = **p_argv.ll;
 
2962
+             next_arg.u += 2;
 
2963
+           }
 
2964
+         else
 
2965
+           {
 
2966
+             /* The abi states only certain register pairs can be
 
2967
+                used for passing long long int specifically (r3,r4),
 
2968
+                (r5,r6), (r7,r8), (r9,r10).  If next arg is long long
 
2969
+                but not correct starting register of pair then skip
 
2970
+                until the proper starting register.  */
 
2971
+             if (intarg_count % 2 != 0)
 
2972
+               {
 
2973
+                 intarg_count ++;
 
2974
+                 gpr_base.u++;
 
2975
+               }
 
2976
+             *gpr_base.ll++ = **p_argv.ll;
 
2977
+           }
 
2978
+         intarg_count += 2;
 
2979
+         break;
 
2980
+
 
2981
+       case FFI_TYPE_STRUCT:
 
2982
+         struct_copy_size = ((*ptr)->size + 15) & ~0xF;
 
2983
+         copy_space.c -= struct_copy_size;
 
2984
+         memcpy (copy_space.c, *p_argv.c, (*ptr)->size);
 
2985
+
 
2986
+         gprvalue = (unsigned long) copy_space.c;
 
2987
+
 
2988
+         FFI_ASSERT (copy_space.c > next_arg.c);
 
2989
+         FFI_ASSERT (flags & FLAG_ARG_NEEDS_COPY);
 
2990
+         goto putgpr;
 
2991
+
 
2992
+       case FFI_TYPE_UINT8:
 
2993
+         gprvalue = **p_argv.uc;
 
2994
+         goto putgpr;
 
2995
+       case FFI_TYPE_SINT8:
 
2996
+         gprvalue = **p_argv.sc;
 
2997
+         goto putgpr;
 
2998
+       case FFI_TYPE_UINT16:
 
2999
+         gprvalue = **p_argv.us;
 
3000
+         goto putgpr;
 
3001
+       case FFI_TYPE_SINT16:
 
3002
+         gprvalue = **p_argv.ss;
 
3003
+         goto putgpr;
 
3004
+
 
3005
+       case FFI_TYPE_INT:
 
3006
+       case FFI_TYPE_UINT32:
 
3007
+       case FFI_TYPE_SINT32:
 
3008
+       case FFI_TYPE_POINTER:
 
3009
+
 
3010
+         gprvalue = **p_argv.ui;
 
3011
+
 
3012
+       putgpr:
 
3013
+         if (intarg_count >= NUM_GPR_ARG_REGISTERS)
 
3014
+           *next_arg.u++ = gprvalue;
 
3015
+         else
 
3016
+           *gpr_base.u++ = gprvalue;
 
3017
+         intarg_count++;
 
3018
+         break;
 
3019
+       }
 
3020
+    }
 
3021
+
 
3022
+  /* Check that we didn't overrun the stack...  */
 
3023
+  FFI_ASSERT (copy_space.c >= next_arg.c);
 
3024
+  FFI_ASSERT (gpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS);
 
3025
+  /* The assert below is testing that the number of integer arguments agrees
 
3026
+     with the number found in ffi_prep_cif_machdep().  However, intarg_count
 
3027
+     is incremented whenever we place an FP arg on the stack, so account for
 
3028
+     that before our assert test.  */
 
3029
+#ifndef __NO_FPRS__
 
3030
+  if (fparg_count > NUM_FPR_ARG_REGISTERS)
 
3031
+    intarg_count -= fparg_count - NUM_FPR_ARG_REGISTERS;
 
3032
+  FFI_ASSERT (fpr_base.u
 
3033
+             <= stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
 
3034
+#endif
 
3035
+  FFI_ASSERT (flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
 
3036
+}
 
3037
+
 
3038
+#define MIN_CACHE_LINE_SIZE 8
 
3039
+
 
3040
+static void
 
3041
+flush_icache (char *wraddr, char *xaddr, int size)
 
3042
+{
 
3043
+  int i;
 
3044
+  for (i = 0; i < size; i += MIN_CACHE_LINE_SIZE)
 
3045
+    __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;"
 
3046
+                     : : "r" (xaddr + i), "r" (wraddr + i) : "memory");
 
3047
+  __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;"
 
3048
+                   : : "r"(xaddr + size - 1), "r"(wraddr + size - 1)
 
3049
+                   : "memory");
 
3050
+}
 
3051
+
 
3052
+ffi_status FFI_HIDDEN
 
3053
+ffi_prep_closure_loc_sysv (ffi_closure *closure,
 
3054
+                          ffi_cif *cif,
 
3055
+                          void (*fun) (ffi_cif *, void *, void **, void *),
 
3056
+                          void *user_data,
 
3057
+                          void *codeloc)
 
3058
+{
 
3059
+  unsigned int *tramp;
 
3060
+
 
3061
+  if (cif->abi < FFI_SYSV || cif->abi >= FFI_LAST_ABI)
 
3062
+    return FFI_BAD_ABI;
 
3063
+
 
3064
+  tramp = (unsigned int *) &closure->tramp[0];
 
3065
+  tramp[0] = 0x7c0802a6;  /*   mflr    r0 */
 
3066
+  tramp[1] = 0x4800000d;  /*   bl      10 <trampoline_initial+0x10> */
 
3067
+  tramp[4] = 0x7d6802a6;  /*   mflr    r11 */
 
3068
+  tramp[5] = 0x7c0803a6;  /*   mtlr    r0 */
 
3069
+  tramp[6] = 0x800b0000;  /*   lwz     r0,0(r11) */
 
3070
+  tramp[7] = 0x816b0004;  /*   lwz     r11,4(r11) */
 
3071
+  tramp[8] = 0x7c0903a6;  /*   mtctr   r0 */
 
3072
+  tramp[9] = 0x4e800420;  /*   bctr */
 
3073
+  *(void **) &tramp[2] = (void *) ffi_closure_SYSV; /* function */
 
3074
+  *(void **) &tramp[3] = codeloc;                   /* context */
 
3075
+
 
3076
+  /* Flush the icache.  */
 
3077
+  flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE);
 
3078
+
 
3079
+  closure->cif = cif;
 
3080
+  closure->fun = fun;
 
3081
+  closure->user_data = user_data;
 
3082
+
 
3083
+  return FFI_OK;
 
3084
+}
 
3085
+
 
3086
+/* Basically the trampoline invokes ffi_closure_SYSV, and on
 
3087
+   entry, r11 holds the address of the closure.
 
3088
+   After storing the registers that could possibly contain
 
3089
+   parameters to be passed into the stack frame and setting
 
3090
+   up space for a return value, ffi_closure_SYSV invokes the
 
3091
+   following helper function to do most of the work.  */
 
3092
+
 
3093
+int
 
3094
+ffi_closure_helper_SYSV (ffi_closure *closure, void *rvalue,
 
3095
+                        unsigned long *pgr, ffi_dblfl *pfr,
 
3096
+                        unsigned long *pst)
 
3097
+{
 
3098
+  /* rvalue is the pointer to space for return value in closure assembly */
 
3099
+  /* pgr is the pointer to where r3-r10 are stored in ffi_closure_SYSV */
 
3100
+  /* pfr is the pointer to where f1-f8 are stored in ffi_closure_SYSV  */
 
3101
+  /* pst is the pointer to outgoing parameter stack in original caller */
 
3102
+
 
3103
+  void **          avalue;
 
3104
+  ffi_type **      arg_types;
 
3105
+  long             i, avn;
 
3106
+#ifndef __NO_FPRS__
 
3107
+  long             nf = 0;   /* number of floating registers already used */
 
3108
+#endif
 
3109
+  long             ng = 0;   /* number of general registers already used */
 
3110
+
 
3111
+  ffi_cif *cif = closure->cif;
 
3112
+  unsigned       size     = cif->rtype->size;
 
3113
+  unsigned short rtypenum = cif->rtype->type;
 
3114
+
 
3115
+  avalue = alloca (cif->nargs * sizeof (void *));
 
3116
+
 
3117
+  /* First translate for softfloat/nonlinux */
 
3118
+  rtypenum = translate_float (cif->abi, rtypenum);
 
3119
+
 
3120
+  /* Copy the caller's structure return value address so that the closure
 
3121
+     returns the data directly to the caller.
 
3122
+     For FFI_SYSV the result is passed in r3/r4 if the struct size is less
 
3123
+     or equal 8 bytes.  */
 
3124
+  if (rtypenum == FFI_TYPE_STRUCT
 
3125
+      && !((cif->abi & FFI_SYSV_STRUCT_RET) != 0 && size <= 8))
 
3126
+    {
 
3127
+      rvalue = (void *) *pgr;
 
3128
+      ng++;
 
3129
+      pgr++;
 
3130
+    }
 
3131
+
 
3132
+  i = 0;
 
3133
+  avn = cif->nargs;
 
3134
+  arg_types = cif->arg_types;
 
3135
+
 
3136
+  /* Grab the addresses of the arguments from the stack frame.  */
 
3137
+  while (i < avn) {
 
3138
+    unsigned short typenum = arg_types[i]->type;
 
3139
+
 
3140
+    /* We may need to handle some values depending on ABI.  */
 
3141
+    typenum = translate_float (cif->abi, typenum);
 
3142
+
 
3143
+    switch (typenum)
 
3144
+      {
 
3145
+#ifndef __NO_FPRS__
 
3146
+      case FFI_TYPE_FLOAT:
 
3147
+       /* Unfortunately float values are stored as doubles
 
3148
+          in the ffi_closure_SYSV code (since we don't check
 
3149
+          the type in that routine).  */
 
3150
+       if (nf < NUM_FPR_ARG_REGISTERS)
 
3151
+         {
 
3152
+           /* FIXME? here we are really changing the values
 
3153
+              stored in the original calling routines outgoing
 
3154
+              parameter stack.  This is probably a really
 
3155
+              naughty thing to do but...  */
 
3156
+           double temp = pfr->d;
 
3157
+           pfr->f = (float) temp;
 
3158
+           avalue[i] = pfr;
 
3159
+           nf++;
 
3160
+           pfr++;
 
3161
+         }
 
3162
+       else
 
3163
+         {
 
3164
+           avalue[i] = pst;
 
3165
+           pst += 1;
 
3166
+         }
 
3167
+       break;
 
3168
+
 
3169
+      case FFI_TYPE_DOUBLE:
 
3170
+       if (nf < NUM_FPR_ARG_REGISTERS)
 
3171
+         {
 
3172
+           avalue[i] = pfr;
 
3173
+           nf++;
 
3174
+           pfr++;
 
3175
+         }
 
3176
+       else
 
3177
+         {
 
3178
+           if (((long) pst) & 4)
 
3179
+             pst++;
 
3180
+           avalue[i] = pst;
 
3181
+           pst += 2;
 
3182
+         }
 
3183
+       break;
 
3184
+
 
3185
+# if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
3186
+      case FFI_TYPE_LONGDOUBLE:
 
3187
+       if (nf < NUM_FPR_ARG_REGISTERS - 1)
 
3188
+         {
 
3189
+           avalue[i] = pfr;
 
3190
+           pfr += 2;
 
3191
+           nf += 2;
 
3192
+         }
 
3193
+       else
 
3194
+         {
 
3195
+           if (((long) pst) & 4)
 
3196
+             pst++;
 
3197
+           avalue[i] = pst;
 
3198
+           pst += 4;
 
3199
+           nf = 8;
 
3200
+         }
 
3201
+       break;
 
3202
+# endif
 
3203
+#endif
 
3204
+
 
3205
+      case FFI_TYPE_UINT128:
 
3206
+       /* Test if for the whole long double, 4 gprs are available.
 
3207
+          otherwise the stuff ends up on the stack.  */
 
3208
+       if (ng < NUM_GPR_ARG_REGISTERS - 3)
 
3209
+         {
 
3210
+           avalue[i] = pgr;
 
3211
+           pgr += 4;
 
3212
+           ng += 4;
 
3213
+         }
 
3214
+       else
 
3215
+         {
 
3216
+           avalue[i] = pst;
 
3217
+           pst += 4;
 
3218
+           ng = 8+4;
 
3219
+         }
 
3220
+       break;
 
3221
+
 
3222
+      case FFI_TYPE_SINT8:
 
3223
+      case FFI_TYPE_UINT8:
 
3224
+#ifndef __LITTLE_ENDIAN__
 
3225
+       if (ng < NUM_GPR_ARG_REGISTERS)
 
3226
+         {
 
3227
+           avalue[i] = (char *) pgr + 3;
 
3228
+           ng++;
 
3229
+           pgr++;
 
3230
+         }
 
3231
+       else
 
3232
+         {
 
3233
+           avalue[i] = (char *) pst + 3;
 
3234
+           pst++;
 
3235
+         }
 
3236
+       break;
 
3237
+#endif
 
3238
+
 
3239
+      case FFI_TYPE_SINT16:
 
3240
+      case FFI_TYPE_UINT16:
 
3241
+#ifndef __LITTLE_ENDIAN__
 
3242
+       if (ng < NUM_GPR_ARG_REGISTERS)
 
3243
+         {
 
3244
+           avalue[i] = (char *) pgr + 2;
 
3245
+           ng++;
 
3246
+           pgr++;
 
3247
+         }
 
3248
+       else
 
3249
+         {
 
3250
+           avalue[i] = (char *) pst + 2;
 
3251
+           pst++;
 
3252
+         }
 
3253
+       break;
 
3254
+#endif
 
3255
+
 
3256
+      case FFI_TYPE_SINT32:
 
3257
+      case FFI_TYPE_UINT32:
 
3258
+      case FFI_TYPE_POINTER:
 
3259
+       if (ng < NUM_GPR_ARG_REGISTERS)
 
3260
+         {
 
3261
+           avalue[i] = pgr;
 
3262
+           ng++;
 
3263
+           pgr++;
 
3264
+         }
 
3265
+       else
 
3266
+         {
 
3267
+           avalue[i] = pst;
 
3268
+           pst++;
 
3269
+         }
 
3270
+       break;
 
3271
+
 
3272
+      case FFI_TYPE_STRUCT:
 
3273
+       /* Structs are passed by reference. The address will appear in a
 
3274
+          gpr if it is one of the first 8 arguments.  */
 
3275
+       if (ng < NUM_GPR_ARG_REGISTERS)
 
3276
+         {
 
3277
+           avalue[i] = (void *) *pgr;
 
3278
+           ng++;
 
3279
+           pgr++;
 
3280
+         }
 
3281
+       else
 
3282
+         {
 
3283
+           avalue[i] = (void *) *pst;
 
3284
+           pst++;
 
3285
+         }
 
3286
+       break;
 
3287
+
 
3288
+      case FFI_TYPE_SINT64:
 
3289
+      case FFI_TYPE_UINT64:
 
3290
+       /* Passing long long ints are complex, they must
 
3291
+          be passed in suitable register pairs such as
 
3292
+          (r3,r4) or (r5,r6) or (r6,r7), or (r7,r8) or (r9,r10)
 
3293
+          and if the entire pair aren't available then the outgoing
 
3294
+          parameter stack is used for both but an alignment of 8
 
3295
+          must will be kept.  So we must either look in pgr
 
3296
+          or pst to find the correct address for this type
 
3297
+          of parameter.  */
 
3298
+       if (ng < NUM_GPR_ARG_REGISTERS - 1)
 
3299
+         {
 
3300
+           if (ng & 1)
 
3301
+             {
 
3302
+               /* skip r4, r6, r8 as starting points */
 
3303
+               ng++;
 
3304
+               pgr++;
 
3305
+             }
 
3306
+           avalue[i] = pgr;
 
3307
+           ng += 2;
 
3308
+           pgr += 2;
 
3309
+         }
 
3310
+       else
 
3311
+         {
 
3312
+           if (((long) pst) & 4)
 
3313
+             pst++;
 
3314
+           avalue[i] = pst;
 
3315
+           pst += 2;
 
3316
+           ng = NUM_GPR_ARG_REGISTERS;
 
3317
+         }
 
3318
+       break;
 
3319
+
 
3320
+      default:
 
3321
+       FFI_ASSERT (0);
 
3322
+      }
 
3323
+
 
3324
+    i++;
 
3325
+  }
 
3326
+
 
3327
+  (closure->fun) (cif, rvalue, avalue, closure->user_data);
 
3328
+
 
3329
+  /* Tell ffi_closure_SYSV how to perform return type promotions.
 
3330
+     Because the FFI_SYSV ABI returns the structures <= 8 bytes in
 
3331
+     r3/r4 we have to tell ffi_closure_SYSV how to treat them.  We
 
3332
+     combine the base type FFI_SYSV_TYPE_SMALL_STRUCT with the size of
 
3333
+     the struct less one.  We never have a struct with size zero.
 
3334
+     See the comment in ffitarget.h about ordering.  */
 
3335
+  if (rtypenum == FFI_TYPE_STRUCT
 
3336
+      && (cif->abi & FFI_SYSV_STRUCT_RET) != 0 && size <= 8)
 
3337
+    return FFI_SYSV_TYPE_SMALL_STRUCT - 1 + size;
 
3338
+  return rtypenum;
 
3339
+}
 
3340
+#endif
 
3341
--- a/src/libffi/src/powerpc/linux64.S
 
3342
+++ b/src/libffi/src/powerpc/linux64.S
 
3343
@@ -29,7 +29,7 @@
 
3344
 #include <fficonfig.h>
 
3345
 #include <ffi.h>
 
3346
 
 
3347
-#ifdef __powerpc64__
 
3348
+#ifdef POWERPC64
 
3349
        .hidden ffi_call_LINUX64
 
3350
        .globl  ffi_call_LINUX64
 
3351
 # if _CALL_ELF == 2
 
3352
--- a/src/libffi/src/powerpc/ffi_linux64.c
 
3353
+++ b/src/libffi/src/powerpc/ffi_linux64.c
 
3354
@@ -0,0 +1,942 @@
 
3355
+/* -----------------------------------------------------------------------
 
3356
+   ffi_linux64.c - Copyright (C) 2013 IBM
 
3357
+                   Copyright (C) 2011 Anthony Green
 
3358
+                   Copyright (C) 2011 Kyle Moffett
 
3359
+                   Copyright (C) 2008 Red Hat, Inc
 
3360
+                   Copyright (C) 2007, 2008 Free Software Foundation, Inc
 
3361
+                   Copyright (c) 1998 Geoffrey Keating
 
3362
+
 
3363
+   PowerPC Foreign Function Interface
 
3364
+
 
3365
+   Permission is hereby granted, free of charge, to any person obtaining
 
3366
+   a copy of this software and associated documentation files (the
 
3367
+   ``Software''), to deal in the Software without restriction, including
 
3368
+   without limitation the rights to use, copy, modify, merge, publish,
 
3369
+   distribute, sublicense, and/or sell copies of the Software, and to
 
3370
+   permit persons to whom the Software is furnished to do so, subject to
 
3371
+   the following conditions:
 
3372
+
 
3373
+   The above copyright notice and this permission notice shall be included
 
3374
+   in all copies or substantial portions of the Software.
 
3375
+
 
3376
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
3377
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
3378
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
3379
+   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
3380
+   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
3381
+   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
3382
+   OTHER DEALINGS IN THE SOFTWARE.
 
3383
+   ----------------------------------------------------------------------- */
 
3384
+
 
3385
+#include "ffi.h"
 
3386
+
 
3387
+#ifdef POWERPC64
 
3388
+#include "ffi_common.h"
 
3389
+#include "ffi_powerpc.h"
 
3390
+
 
3391
+
 
3392
+/* About the LINUX64 ABI.  */
 
3393
+enum {
 
3394
+  NUM_GPR_ARG_REGISTERS64 = 8,
 
3395
+  NUM_FPR_ARG_REGISTERS64 = 13
 
3396
+};
 
3397
+enum { ASM_NEEDS_REGISTERS64 = 4 };
 
3398
+
 
3399
+
 
3400
+#if HAVE_LONG_DOUBLE_VARIANT && FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
3401
+/* Adjust size of ffi_type_longdouble.  */
 
3402
+void FFI_HIDDEN
 
3403
+ffi_prep_types_linux64 (ffi_abi abi)
 
3404
+{
 
3405
+  if ((abi & (FFI_LINUX | FFI_LINUX_LONG_DOUBLE_128)) == FFI_LINUX)
 
3406
+    {
 
3407
+      ffi_type_longdouble.size = 8;
 
3408
+      ffi_type_longdouble.alignment = 8;
 
3409
+    }
 
3410
+  else
 
3411
+    {
 
3412
+      ffi_type_longdouble.size = 16;
 
3413
+      ffi_type_longdouble.alignment = 16;
 
3414
+    }
 
3415
+}
 
3416
+#endif
 
3417
+
 
3418
+
 
3419
+#if _CALL_ELF == 2
 
3420
+static unsigned int
 
3421
+discover_homogeneous_aggregate (const ffi_type *t, unsigned int *elnum)
 
3422
+{
 
3423
+  switch (t->type)
 
3424
+    {
 
3425
+    case FFI_TYPE_FLOAT:
 
3426
+    case FFI_TYPE_DOUBLE:
 
3427
+      *elnum = 1;
 
3428
+      return (int) t->type;
 
3429
+
 
3430
+    case FFI_TYPE_STRUCT:;
 
3431
+      {
 
3432
+       unsigned int base_elt = 0, total_elnum = 0;
 
3433
+       ffi_type **el = t->elements;
 
3434
+       while (*el)
 
3435
+         {
 
3436
+           unsigned int el_elt, el_elnum = 0;
 
3437
+           el_elt = discover_homogeneous_aggregate (*el, &el_elnum);
 
3438
+           if (el_elt == 0
 
3439
+               || (base_elt && base_elt != el_elt))
 
3440
+             return 0;
 
3441
+           base_elt = el_elt;
 
3442
+           total_elnum += el_elnum;
 
3443
+           if (total_elnum > 8)
 
3444
+             return 0;
 
3445
+           el++;
 
3446
+         }
 
3447
+       *elnum = total_elnum;
 
3448
+       return base_elt;
 
3449
+      }
 
3450
+
 
3451
+    default:
 
3452
+      return 0;
 
3453
+    }
 
3454
+}
 
3455
+#endif
 
3456
+
 
3457
+
 
3458
+/* Perform machine dependent cif processing */
 
3459
+static ffi_status
 
3460
+ffi_prep_cif_linux64_core (ffi_cif *cif)
 
3461
+{
 
3462
+  ffi_type **ptr;
 
3463
+  unsigned bytes;
 
3464
+  unsigned i, fparg_count = 0, intarg_count = 0;
 
3465
+  unsigned flags = cif->flags;
 
3466
+#if _CALL_ELF == 2
 
3467
+  unsigned int elt, elnum;
 
3468
+#endif
 
3469
+
 
3470
+#if FFI_TYPE_LONGDOUBLE == FFI_TYPE_DOUBLE
 
3471
+  /* If compiled without long double support..  */
 
3472
+  if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
 
3473
+    return FFI_BAD_ABI;
 
3474
+#endif
 
3475
+
 
3476
+  /* The machine-independent calculation of cif->bytes doesn't work
 
3477
+     for us.  Redo the calculation.  */
 
3478
+#if _CALL_ELF == 2
 
3479
+  /* Space for backchain, CR, LR, TOC and the asm's temp regs.  */
 
3480
+  bytes = (4 + ASM_NEEDS_REGISTERS64) * sizeof (long);
 
3481
+
 
3482
+  /* Space for the general registers.  */
 
3483
+  bytes += NUM_GPR_ARG_REGISTERS64 * sizeof (long);
 
3484
+#else
 
3485
+  /* Space for backchain, CR, LR, cc/ld doubleword, TOC and the asm's temp
 
3486
+     regs.  */
 
3487
+  bytes = (6 + ASM_NEEDS_REGISTERS64) * sizeof (long);
 
3488
+
 
3489
+  /* Space for the mandatory parm save area and general registers.  */
 
3490
+  bytes += 2 * NUM_GPR_ARG_REGISTERS64 * sizeof (long);
 
3491
+#endif
 
3492
+
 
3493
+  /* Return value handling.  */
 
3494
+  switch (cif->rtype->type)
 
3495
+    {
 
3496
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
3497
+    case FFI_TYPE_LONGDOUBLE:
 
3498
+      if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
 
3499
+       flags |= FLAG_RETURNS_128BITS;
 
3500
+      /* Fall through.  */
 
3501
+#endif
 
3502
+    case FFI_TYPE_DOUBLE:
 
3503
+      flags |= FLAG_RETURNS_64BITS;
 
3504
+      /* Fall through.  */
 
3505
+    case FFI_TYPE_FLOAT:
 
3506
+      flags |= FLAG_RETURNS_FP;
 
3507
+      break;
 
3508
+
 
3509
+    case FFI_TYPE_UINT128:
 
3510
+      flags |= FLAG_RETURNS_128BITS;
 
3511
+      /* Fall through.  */
 
3512
+    case FFI_TYPE_UINT64:
 
3513
+    case FFI_TYPE_SINT64:
 
3514
+      flags |= FLAG_RETURNS_64BITS;
 
3515
+      break;
 
3516
+
 
3517
+    case FFI_TYPE_STRUCT:
 
3518
+#if _CALL_ELF == 2
 
3519
+      elt = discover_homogeneous_aggregate (cif->rtype, &elnum);
 
3520
+      if (elt)
 
3521
+       {
 
3522
+         if (elt == FFI_TYPE_DOUBLE)
 
3523
+           flags |= FLAG_RETURNS_64BITS;
 
3524
+         flags |= FLAG_RETURNS_FP | FLAG_RETURNS_SMST;
 
3525
+         break;
 
3526
+       }
 
3527
+      if (cif->rtype->size <= 16)
 
3528
+       {
 
3529
+         flags |= FLAG_RETURNS_SMST;
 
3530
+         break;
 
3531
+       }
 
3532
+#endif
 
3533
+      intarg_count++;
 
3534
+      flags |= FLAG_RETVAL_REFERENCE;
 
3535
+      /* Fall through.  */
 
3536
+    case FFI_TYPE_VOID:
 
3537
+      flags |= FLAG_RETURNS_NOTHING;
 
3538
+      break;
 
3539
+
 
3540
+    default:
 
3541
+      /* Returns 32-bit integer, or similar.  Nothing to do here.  */
 
3542
+      break;
 
3543
+    }
 
3544
+
 
3545
+  for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
 
3546
+    {
 
3547
+      unsigned int align;
 
3548
+
 
3549
+      switch ((*ptr)->type)
 
3550
+       {
 
3551
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
3552
+       case FFI_TYPE_LONGDOUBLE:
 
3553
+         if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
 
3554
+           {
 
3555
+             fparg_count++;
 
3556
+             intarg_count++;
 
3557
+           }
 
3558
+         /* Fall through.  */
 
3559
+#endif
 
3560
+       case FFI_TYPE_DOUBLE:
 
3561
+       case FFI_TYPE_FLOAT:
 
3562
+         fparg_count++;
 
3563
+         intarg_count++;
 
3564
+         if (fparg_count > NUM_FPR_ARG_REGISTERS64)
 
3565
+           flags |= FLAG_ARG_NEEDS_PSAVE;
 
3566
+         break;
 
3567
+
 
3568
+       case FFI_TYPE_STRUCT:
 
3569
+         if ((cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
 
3570
+           {
 
3571
+             align = (*ptr)->alignment;
 
3572
+             if (align > 16)
 
3573
+               align = 16;
 
3574
+             align = align / 8;
 
3575
+             if (align > 1)
 
3576
+               intarg_count = ALIGN (intarg_count, align);
 
3577
+           }
 
3578
+         intarg_count += ((*ptr)->size + 7) / 8;
 
3579
+#if _CALL_ELF == 2
 
3580
+         elt = discover_homogeneous_aggregate (*ptr, &elnum);
 
3581
+         if (elt)
 
3582
+           {
 
3583
+             fparg_count += elnum;
 
3584
+             if (fparg_count > NUM_FPR_ARG_REGISTERS64)
 
3585
+               flags |= FLAG_ARG_NEEDS_PSAVE;
 
3586
+           }
 
3587
+         else
 
3588
+#endif
 
3589
+           {
 
3590
+             if (intarg_count > NUM_GPR_ARG_REGISTERS64)
 
3591
+               flags |= FLAG_ARG_NEEDS_PSAVE;
 
3592
+           }
 
3593
+         break;
 
3594
+
 
3595
+       case FFI_TYPE_POINTER:
 
3596
+       case FFI_TYPE_UINT64:
 
3597
+       case FFI_TYPE_SINT64:
 
3598
+       case FFI_TYPE_INT:
 
3599
+       case FFI_TYPE_UINT32:
 
3600
+       case FFI_TYPE_SINT32:
 
3601
+       case FFI_TYPE_UINT16:
 
3602
+       case FFI_TYPE_SINT16:
 
3603
+       case FFI_TYPE_UINT8:
 
3604
+       case FFI_TYPE_SINT8:
 
3605
+         /* Everything else is passed as a 8-byte word in a GPR, either
 
3606
+            the object itself or a pointer to it.  */
 
3607
+         intarg_count++;
 
3608
+         if (intarg_count > NUM_GPR_ARG_REGISTERS64)
 
3609
+           flags |= FLAG_ARG_NEEDS_PSAVE;
 
3610
+         break;
 
3611
+       default:
 
3612
+         FFI_ASSERT (0);
 
3613
+       }
 
3614
+    }
 
3615
+
 
3616
+  if (fparg_count != 0)
 
3617
+    flags |= FLAG_FP_ARGUMENTS;
 
3618
+  if (intarg_count > 4)
 
3619
+    flags |= FLAG_4_GPR_ARGUMENTS;
 
3620
+
 
3621
+  /* Space for the FPR registers, if needed.  */
 
3622
+  if (fparg_count != 0)
 
3623
+    bytes += NUM_FPR_ARG_REGISTERS64 * sizeof (double);
 
3624
+
 
3625
+  /* Stack space.  */
 
3626
+#if _CALL_ELF == 2
 
3627
+  if ((flags & FLAG_ARG_NEEDS_PSAVE) != 0)
 
3628
+    bytes += intarg_count * sizeof (long);
 
3629
+#else
 
3630
+  if (intarg_count > NUM_GPR_ARG_REGISTERS64)
 
3631
+    bytes += (intarg_count - NUM_GPR_ARG_REGISTERS64) * sizeof (long);
 
3632
+#endif
 
3633
+
 
3634
+  /* The stack space allocated needs to be a multiple of 16 bytes.  */
 
3635
+  bytes = (bytes + 15) & ~0xF;
 
3636
+
 
3637
+  cif->flags = flags;
 
3638
+  cif->bytes = bytes;
 
3639
+
 
3640
+  return FFI_OK;
 
3641
+}
 
3642
+
 
3643
+ffi_status FFI_HIDDEN
 
3644
+ffi_prep_cif_linux64 (ffi_cif *cif)
 
3645
+{
 
3646
+  if ((cif->abi & FFI_LINUX) != 0)
 
3647
+    cif->nfixedargs = cif->nargs;
 
3648
+#if _CALL_ELF != 2
 
3649
+  else if (cif->abi == FFI_COMPAT_LINUX64)
 
3650
+    {
 
3651
+      /* This call is from old code.  Don't touch cif->nfixedargs
 
3652
+        since old code will be using a smaller cif.  */
 
3653
+      cif->flags |= FLAG_COMPAT;
 
3654
+      /* Translate to new abi value.  */
 
3655
+      cif->abi = FFI_LINUX | FFI_LINUX_LONG_DOUBLE_128;
 
3656
+    }
 
3657
+#endif
 
3658
+  else
 
3659
+    return FFI_BAD_ABI;
 
3660
+  return ffi_prep_cif_linux64_core (cif);
 
3661
+}
 
3662
+
 
3663
+ffi_status FFI_HIDDEN
 
3664
+ffi_prep_cif_linux64_var (ffi_cif *cif,
 
3665
+                         unsigned int nfixedargs,
 
3666
+                         unsigned int ntotalargs MAYBE_UNUSED)
 
3667
+{
 
3668
+  if ((cif->abi & FFI_LINUX) != 0)
 
3669
+    cif->nfixedargs = nfixedargs;
 
3670
+#if _CALL_ELF != 2
 
3671
+  else if (cif->abi == FFI_COMPAT_LINUX64)
 
3672
+    {
 
3673
+      /* This call is from old code.  Don't touch cif->nfixedargs
 
3674
+        since old code will be using a smaller cif.  */
 
3675
+      cif->flags |= FLAG_COMPAT;
 
3676
+      /* Translate to new abi value.  */
 
3677
+      cif->abi = FFI_LINUX | FFI_LINUX_LONG_DOUBLE_128;
 
3678
+    }
 
3679
+#endif
 
3680
+  else
 
3681
+    return FFI_BAD_ABI;
 
3682
+#if _CALL_ELF == 2
 
3683
+  cif->flags |= FLAG_ARG_NEEDS_PSAVE;
 
3684
+#endif
 
3685
+  return ffi_prep_cif_linux64_core (cif);
 
3686
+}
 
3687
+
 
3688
+
 
3689
+/* ffi_prep_args64 is called by the assembly routine once stack space
 
3690
+   has been allocated for the function's arguments.
 
3691
+
 
3692
+   The stack layout we want looks like this:
 
3693
+
 
3694
+   |   Ret addr from ffi_call_LINUX64  8bytes  |       higher addresses
 
3695
+   |--------------------------------------------|
 
3696
+   |   CR save area                    8bytes  |
 
3697
+   |--------------------------------------------|
 
3698
+   |   Previous backchain pointer      8       |       stack pointer here
 
3699
+   |--------------------------------------------|<+ <<<        on entry to
 
3700
+   |   Saved r28-r31                   4*8     | |     ffi_call_LINUX64
 
3701
+   |--------------------------------------------| |
 
3702
+   |   GPR registers r3-r10            8*8     | |
 
3703
+   |--------------------------------------------| |
 
3704
+   |   FPR registers f1-f13 (optional) 13*8    | |
 
3705
+   |--------------------------------------------| |
 
3706
+   |   Parameter save area                     | |
 
3707
+   |--------------------------------------------| |
 
3708
+   |   TOC save area                   8       | |
 
3709
+   |--------------------------------------------| |    stack   |
 
3710
+   |   Linker doubleword               8       | |     grows   |
 
3711
+   |--------------------------------------------| |    down    V
 
3712
+   |   Compiler doubleword             8       | |
 
3713
+   |--------------------------------------------| |    lower addresses
 
3714
+   |   Space for callee's LR           8       | |
 
3715
+   |--------------------------------------------| |
 
3716
+   |   CR save area                    8       | |
 
3717
+   |--------------------------------------------| |    stack pointer here
 
3718
+   |   Current backchain pointer       8       |-/     during
 
3719
+   |--------------------------------------------|   <<<        ffi_call_LINUX64
 
3720
+
 
3721
+*/
 
3722
+
 
3723
+void FFI_HIDDEN
 
3724
+ffi_prep_args64 (extended_cif *ecif, unsigned long *const stack)
 
3725
+{
 
3726
+  const unsigned long bytes = ecif->cif->bytes;
 
3727
+  const unsigned long flags = ecif->cif->flags;
 
3728
+
 
3729
+  typedef union
 
3730
+  {
 
3731
+    char *c;
 
3732
+    unsigned long *ul;
 
3733
+    float *f;
 
3734
+    double *d;
 
3735
+    size_t p;
 
3736
+  } valp;
 
3737
+
 
3738
+  /* 'stacktop' points at the previous backchain pointer.  */
 
3739
+  valp stacktop;
 
3740
+
 
3741
+  /* 'next_arg' points at the space for gpr3, and grows upwards as
 
3742
+     we use GPR registers, then continues at rest.  */
 
3743
+  valp gpr_base;
 
3744
+  valp gpr_end;
 
3745
+  valp rest;
 
3746
+  valp next_arg;
 
3747
+
 
3748
+  /* 'fpr_base' points at the space for fpr3, and grows upwards as
 
3749
+     we use FPR registers.  */
 
3750
+  valp fpr_base;
 
3751
+  unsigned int fparg_count;
 
3752
+
 
3753
+  unsigned int i, words, nargs, nfixedargs;
 
3754
+  ffi_type **ptr;
 
3755
+  double double_tmp;
 
3756
+  union
 
3757
+  {
 
3758
+    void **v;
 
3759
+    char **c;
 
3760
+    signed char **sc;
 
3761
+    unsigned char **uc;
 
3762
+    signed short **ss;
 
3763
+    unsigned short **us;
 
3764
+    signed int **si;
 
3765
+    unsigned int **ui;
 
3766
+    unsigned long **ul;
 
3767
+    float **f;
 
3768
+    double **d;
 
3769
+  } p_argv;
 
3770
+  unsigned long gprvalue;
 
3771
+  unsigned long align;
 
3772
+
 
3773
+  stacktop.c = (char *) stack + bytes;
 
3774
+  gpr_base.ul = stacktop.ul - ASM_NEEDS_REGISTERS64 - NUM_GPR_ARG_REGISTERS64;
 
3775
+  gpr_end.ul = gpr_base.ul + NUM_GPR_ARG_REGISTERS64;
 
3776
+#if _CALL_ELF == 2
 
3777
+  rest.ul = stack + 4 + NUM_GPR_ARG_REGISTERS64;
 
3778
+#else
 
3779
+  rest.ul = stack + 6 + NUM_GPR_ARG_REGISTERS64;
 
3780
+#endif
 
3781
+  fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS64;
 
3782
+  fparg_count = 0;
 
3783
+  next_arg.ul = gpr_base.ul;
 
3784
+
 
3785
+  /* Check that everything starts aligned properly.  */
 
3786
+  FFI_ASSERT (((unsigned long) (char *) stack & 0xF) == 0);
 
3787
+  FFI_ASSERT (((unsigned long) stacktop.c & 0xF) == 0);
 
3788
+  FFI_ASSERT ((bytes & 0xF) == 0);
 
3789
+
 
3790
+  /* Deal with return values that are actually pass-by-reference.  */
 
3791
+  if (flags & FLAG_RETVAL_REFERENCE)
 
3792
+    *next_arg.ul++ = (unsigned long) (char *) ecif->rvalue;
 
3793
+
 
3794
+  /* Now for the arguments.  */
 
3795
+  p_argv.v = ecif->avalue;
 
3796
+  nargs = ecif->cif->nargs;
 
3797
+#if _CALL_ELF != 2
 
3798
+  nfixedargs = (unsigned) -1;
 
3799
+  if ((flags & FLAG_COMPAT) == 0)
 
3800
+#endif
 
3801
+    nfixedargs = ecif->cif->nfixedargs;
 
3802
+  for (ptr = ecif->cif->arg_types, i = 0;
 
3803
+       i < nargs;
 
3804
+       i++, ptr++, p_argv.v++)
 
3805
+    {
 
3806
+#if _CALL_ELF == 2
 
3807
+      unsigned int elt, elnum;
 
3808
+#endif
 
3809
+
 
3810
+      switch ((*ptr)->type)
 
3811
+       {
 
3812
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
3813
+       case FFI_TYPE_LONGDOUBLE:
 
3814
+         if ((ecif->cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
 
3815
+           {
 
3816
+             double_tmp = (*p_argv.d)[0];
 
3817
+             if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
3818
+               {
 
3819
+                 *fpr_base.d++ = double_tmp;
 
3820
+# if _CALL_ELF != 2
 
3821
+                 if ((flags & FLAG_COMPAT) != 0)
 
3822
+                   *next_arg.d = double_tmp;
 
3823
+# endif
 
3824
+               }
 
3825
+             else
 
3826
+               *next_arg.d = double_tmp;
 
3827
+             if (++next_arg.ul == gpr_end.ul)
 
3828
+               next_arg.ul = rest.ul;
 
3829
+             fparg_count++;
 
3830
+             double_tmp = (*p_argv.d)[1];
 
3831
+             if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
3832
+               {
 
3833
+                 *fpr_base.d++ = double_tmp;
 
3834
+# if _CALL_ELF != 2
 
3835
+                 if ((flags & FLAG_COMPAT) != 0)
 
3836
+                   *next_arg.d = double_tmp;
 
3837
+# endif
 
3838
+               }
 
3839
+             else
 
3840
+               *next_arg.d = double_tmp;
 
3841
+             if (++next_arg.ul == gpr_end.ul)
 
3842
+               next_arg.ul = rest.ul;
 
3843
+             fparg_count++;
 
3844
+             FFI_ASSERT (__LDBL_MANT_DIG__ == 106);
 
3845
+             FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
3846
+             break;
 
3847
+           }
 
3848
+         /* Fall through.  */
 
3849
+#endif
 
3850
+       case FFI_TYPE_DOUBLE:
 
3851
+         double_tmp = **p_argv.d;
 
3852
+         if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
3853
+           {
 
3854
+             *fpr_base.d++ = double_tmp;
 
3855
+#if _CALL_ELF != 2
 
3856
+             if ((flags & FLAG_COMPAT) != 0)
 
3857
+               *next_arg.d = double_tmp;
 
3858
+#endif
 
3859
+           }
 
3860
+         else
 
3861
+           *next_arg.d = double_tmp;
 
3862
+         if (++next_arg.ul == gpr_end.ul)
 
3863
+           next_arg.ul = rest.ul;
 
3864
+         fparg_count++;
 
3865
+         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
3866
+         break;
 
3867
+
 
3868
+       case FFI_TYPE_FLOAT:
 
3869
+         double_tmp = **p_argv.f;
 
3870
+         if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
3871
+           {
 
3872
+             *fpr_base.d++ = double_tmp;
 
3873
+#if _CALL_ELF != 2
 
3874
+             if ((flags & FLAG_COMPAT) != 0)
 
3875
+               *next_arg.f = (float) double_tmp;
 
3876
+#endif
 
3877
+           }
 
3878
+         else
 
3879
+           *next_arg.f = (float) double_tmp;
 
3880
+         if (++next_arg.ul == gpr_end.ul)
 
3881
+           next_arg.ul = rest.ul;
 
3882
+         fparg_count++;
 
3883
+         FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
 
3884
+         break;
 
3885
+
 
3886
+       case FFI_TYPE_STRUCT:
 
3887
+         if ((ecif->cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
 
3888
+           {
 
3889
+             align = (*ptr)->alignment;
 
3890
+             if (align > 16)
 
3891
+               align = 16;
 
3892
+             if (align > 1)
 
3893
+               next_arg.p = ALIGN (next_arg.p, align);
 
3894
+           }
 
3895
+#if _CALL_ELF == 2
 
3896
+         elt = discover_homogeneous_aggregate (*ptr, &elnum);
 
3897
+         if (elt)
 
3898
+           {
 
3899
+             union {
 
3900
+               void *v;
 
3901
+               float *f;
 
3902
+               double *d;
 
3903
+             } arg;
 
3904
+
 
3905
+             arg.v = *p_argv.v;
 
3906
+             if (elt == FFI_TYPE_FLOAT)
 
3907
+               {
 
3908
+                 do
 
3909
+                   {
 
3910
+                     double_tmp = *arg.f++;
 
3911
+                     if (fparg_count < NUM_FPR_ARG_REGISTERS64
 
3912
+                         && i < nfixedargs)
 
3913
+                       *fpr_base.d++ = double_tmp;
 
3914
+                     else
 
3915
+                       *next_arg.f = (float) double_tmp;
 
3916
+                     if (++next_arg.f == gpr_end.f)
 
3917
+                       next_arg.f = rest.f;
 
3918
+                     fparg_count++;
 
3919
+                   }
 
3920
+                 while (--elnum != 0);
 
3921
+                 if ((next_arg.p & 3) != 0)
 
3922
+                   {
 
3923
+                     if (++next_arg.f == gpr_end.f)
 
3924
+                       next_arg.f = rest.f;
 
3925
+                   }
 
3926
+               }
 
3927
+             else
 
3928
+               do
 
3929
+                 {
 
3930
+                   double_tmp = *arg.d++;
 
3931
+                   if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
 
3932
+                     *fpr_base.d++ = double_tmp;
 
3933
+                   else
 
3934
+                     *next_arg.d = double_tmp;
 
3935
+                   if (++next_arg.d == gpr_end.d)
 
3936
+                     next_arg.d = rest.d;
 
3937
+                   fparg_count++;
 
3938
+                 }
 
3939
+               while (--elnum != 0);
 
3940
+           }
 
3941
+         else
 
3942
+#endif
 
3943
+           {
 
3944
+             words = ((*ptr)->size + 7) / 8;
 
3945
+             if (next_arg.ul >= gpr_base.ul && next_arg.ul + words > gpr_end.ul)
 
3946
+               {
 
3947
+                 size_t first = gpr_end.c - next_arg.c;
 
3948
+                 memcpy (next_arg.c, *p_argv.c, first);
 
3949
+                 memcpy (rest.c, *p_argv.c + first, (*ptr)->size - first);
 
3950
+                 next_arg.c = rest.c + words * 8 - first;
 
3951
+               }
 
3952
+             else
 
3953
+               {
 
3954
+                 char *where = next_arg.c;
 
3955
+
 
3956
+#ifndef __LITTLE_ENDIAN__
 
3957
+                 /* Structures with size less than eight bytes are passed
 
3958
+                    left-padded.  */
 
3959
+                 if ((*ptr)->size < 8)
 
3960
+                   where += 8 - (*ptr)->size;
 
3961
+#endif
 
3962
+                 memcpy (where, *p_argv.c, (*ptr)->size);
 
3963
+                 next_arg.ul += words;
 
3964
+                 if (next_arg.ul == gpr_end.ul)
 
3965
+                   next_arg.ul = rest.ul;
 
3966
+               }
 
3967
+           }
 
3968
+         break;
 
3969
+
 
3970
+       case FFI_TYPE_UINT8:
 
3971
+         gprvalue = **p_argv.uc;
 
3972
+         goto putgpr;
 
3973
+       case FFI_TYPE_SINT8:
 
3974
+         gprvalue = **p_argv.sc;
 
3975
+         goto putgpr;
 
3976
+       case FFI_TYPE_UINT16:
 
3977
+         gprvalue = **p_argv.us;
 
3978
+         goto putgpr;
 
3979
+       case FFI_TYPE_SINT16:
 
3980
+         gprvalue = **p_argv.ss;
 
3981
+         goto putgpr;
 
3982
+       case FFI_TYPE_UINT32:
 
3983
+         gprvalue = **p_argv.ui;
 
3984
+         goto putgpr;
 
3985
+       case FFI_TYPE_INT:
 
3986
+       case FFI_TYPE_SINT32:
 
3987
+         gprvalue = **p_argv.si;
 
3988
+         goto putgpr;
 
3989
+
 
3990
+       case FFI_TYPE_UINT64:
 
3991
+       case FFI_TYPE_SINT64:
 
3992
+       case FFI_TYPE_POINTER:
 
3993
+         gprvalue = **p_argv.ul;
 
3994
+       putgpr:
 
3995
+         *next_arg.ul++ = gprvalue;
 
3996
+         if (next_arg.ul == gpr_end.ul)
 
3997
+           next_arg.ul = rest.ul;
 
3998
+         break;
 
3999
+       }
 
4000
+    }
 
4001
+
 
4002
+  FFI_ASSERT (flags & FLAG_4_GPR_ARGUMENTS
 
4003
+             || (next_arg.ul >= gpr_base.ul
 
4004
+                 && next_arg.ul <= gpr_base.ul + 4));
 
4005
+}
 
4006
+
 
4007
+
 
4008
+#if _CALL_ELF == 2
 
4009
+#define MIN_CACHE_LINE_SIZE 8
 
4010
+
 
4011
+static void
 
4012
+flush_icache (char *wraddr, char *xaddr, int size)
 
4013
+{
 
4014
+  int i;
 
4015
+  for (i = 0; i < size; i += MIN_CACHE_LINE_SIZE)
 
4016
+    __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;"
 
4017
+                     : : "r" (xaddr + i), "r" (wraddr + i) : "memory");
 
4018
+  __asm__ volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;"
 
4019
+                   : : "r"(xaddr + size - 1), "r"(wraddr + size - 1)
 
4020
+                   : "memory");
 
4021
+}
 
4022
+#endif
 
4023
+
 
4024
+ffi_status
 
4025
+ffi_prep_closure_loc_linux64 (ffi_closure *closure,
 
4026
+                             ffi_cif *cif,
 
4027
+                             void (*fun) (ffi_cif *, void *, void **, void *),
 
4028
+                             void *user_data,
 
4029
+                             void *codeloc)
 
4030
+{
 
4031
+#if _CALL_ELF == 2
 
4032
+  unsigned int *tramp = (unsigned int *) &closure->tramp[0];
 
4033
+
 
4034
+  if (cif->abi < FFI_LINUX || cif->abi >= FFI_LAST_ABI)
 
4035
+    return FFI_BAD_ABI;
 
4036
+
 
4037
+  tramp[0] = 0xe96c0018;       /* 0:   ld      11,2f-0b(12)    */
 
4038
+  tramp[1] = 0xe98c0010;       /*      ld      12,1f-0b(12)    */
 
4039
+  tramp[2] = 0x7d8903a6;       /*      mtctr   12              */
 
4040
+  tramp[3] = 0x4e800420;       /*      bctr                    */
 
4041
+                               /* 1:   .quad   function_addr   */
 
4042
+                               /* 2:   .quad   context         */
 
4043
+  *(void **) &tramp[4] = (void *) ffi_closure_LINUX64;
 
4044
+  *(void **) &tramp[6] = codeloc;
 
4045
+  flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE);
 
4046
+#else
 
4047
+  void **tramp = (void **) &closure->tramp[0];
 
4048
+
 
4049
+  if (cif->abi < FFI_LINUX || cif->abi >= FFI_LAST_ABI)
 
4050
+    return FFI_BAD_ABI;
 
4051
+
 
4052
+  /* Copy function address and TOC from ffi_closure_LINUX64.  */
 
4053
+  memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
 
4054
+  tramp[2] = codeloc;
 
4055
+#endif
 
4056
+
 
4057
+  closure->cif = cif;
 
4058
+  closure->fun = fun;
 
4059
+  closure->user_data = user_data;
 
4060
+
 
4061
+  return FFI_OK;
 
4062
+}
 
4063
+
 
4064
+
 
4065
+int FFI_HIDDEN
 
4066
+ffi_closure_helper_LINUX64 (ffi_closure *closure, void *rvalue,
 
4067
+                           unsigned long *pst, ffi_dblfl *pfr)
 
4068
+{
 
4069
+  /* rvalue is the pointer to space for return value in closure assembly */
 
4070
+  /* pst is the pointer to parameter save area
 
4071
+     (r3-r10 are stored into its first 8 slots by ffi_closure_LINUX64) */
 
4072
+  /* pfr is the pointer to where f1-f13 are stored in ffi_closure_LINUX64 */
 
4073
+
 
4074
+  void **avalue;
 
4075
+  ffi_type **arg_types;
 
4076
+  unsigned long i, avn, nfixedargs;
 
4077
+  ffi_cif *cif;
 
4078
+  ffi_dblfl *end_pfr = pfr + NUM_FPR_ARG_REGISTERS64;
 
4079
+  unsigned long align;
 
4080
+
 
4081
+  cif = closure->cif;
 
4082
+  avalue = alloca (cif->nargs * sizeof (void *));
 
4083
+
 
4084
+  /* Copy the caller's structure return value address so that the
 
4085
+     closure returns the data directly to the caller.  */
 
4086
+  if (cif->rtype->type == FFI_TYPE_STRUCT
 
4087
+      && (cif->flags & FLAG_RETURNS_SMST) == 0)
 
4088
+    {
 
4089
+      rvalue = (void *) *pst;
 
4090
+      pst++;
 
4091
+    }
 
4092
+
 
4093
+  i = 0;
 
4094
+  avn = cif->nargs;
 
4095
+#if _CALL_ELF != 2
 
4096
+  nfixedargs = (unsigned) -1;
 
4097
+  if ((cif->flags & FLAG_COMPAT) == 0)
 
4098
+#endif
 
4099
+    nfixedargs = cif->nfixedargs;
 
4100
+  arg_types = cif->arg_types;
 
4101
+
 
4102
+  /* Grab the addresses of the arguments from the stack frame.  */
 
4103
+  while (i < avn)
 
4104
+    {
 
4105
+      unsigned int elt, elnum;
 
4106
+
 
4107
+      switch (arg_types[i]->type)
 
4108
+       {
 
4109
+       case FFI_TYPE_SINT8:
 
4110
+       case FFI_TYPE_UINT8:
 
4111
+#ifndef __LITTLE_ENDIAN__
 
4112
+         avalue[i] = (char *) pst + 7;
 
4113
+         pst++;
 
4114
+         break;
 
4115
+#endif
 
4116
+
 
4117
+       case FFI_TYPE_SINT16:
 
4118
+       case FFI_TYPE_UINT16:
 
4119
+#ifndef __LITTLE_ENDIAN__
 
4120
+         avalue[i] = (char *) pst + 6;
 
4121
+         pst++;
 
4122
+         break;
 
4123
+#endif
 
4124
+
 
4125
+       case FFI_TYPE_SINT32:
 
4126
+       case FFI_TYPE_UINT32:
 
4127
+#ifndef __LITTLE_ENDIAN__
 
4128
+         avalue[i] = (char *) pst + 4;
 
4129
+         pst++;
 
4130
+         break;
 
4131
+#endif
 
4132
+
 
4133
+       case FFI_TYPE_SINT64:
 
4134
+       case FFI_TYPE_UINT64:
 
4135
+       case FFI_TYPE_POINTER:
 
4136
+         avalue[i] = pst;
 
4137
+         pst++;
 
4138
+         break;
 
4139
+
 
4140
+       case FFI_TYPE_STRUCT:
 
4141
+         if ((cif->abi & FFI_LINUX_STRUCT_ALIGN) != 0)
 
4142
+           {
 
4143
+             align = arg_types[i]->alignment;
 
4144
+             if (align > 16)
 
4145
+               align = 16;
 
4146
+             if (align > 1)
 
4147
+               pst = (unsigned long *) ALIGN ((size_t) pst, align);
 
4148
+           }
 
4149
+         elt = 0;
 
4150
+#if _CALL_ELF == 2
 
4151
+         elt = discover_homogeneous_aggregate (arg_types[i], &elnum);
 
4152
+#endif
 
4153
+         if (elt)
 
4154
+           {
 
4155
+             union {
 
4156
+               void *v;
 
4157
+               unsigned long *ul;
 
4158
+               float *f;
 
4159
+               double *d;
 
4160
+               size_t p;
 
4161
+             } to, from;
 
4162
+
 
4163
+             /* Repackage the aggregate from its parts.  The
 
4164
+                aggregate size is not greater than the space taken by
 
4165
+                the registers so store back to the register/parameter
 
4166
+                save arrays.  */
 
4167
+             if (pfr + elnum <= end_pfr)
 
4168
+               to.v = pfr;
 
4169
+             else
 
4170
+               to.v = pst;
 
4171
+
 
4172
+             avalue[i] = to.v;
 
4173
+             from.ul = pst;
 
4174
+             if (elt == FFI_TYPE_FLOAT)
 
4175
+               {
 
4176
+                 do
 
4177
+                   {
 
4178
+                     if (pfr < end_pfr && i < nfixedargs)
 
4179
+                       {
 
4180
+                         *to.f = (float) pfr->d;
 
4181
+                         pfr++;
 
4182
+                       }
 
4183
+                     else
 
4184
+                       *to.f = *from.f;
 
4185
+                     to.f++;
 
4186
+                     from.f++;
 
4187
+                   }
 
4188
+                 while (--elnum != 0);
 
4189
+               }
 
4190
+             else
 
4191
+               {
 
4192
+                 do
 
4193
+                   {
 
4194
+                     if (pfr < end_pfr && i < nfixedargs)
 
4195
+                       {
 
4196
+                         *to.d = pfr->d;
 
4197
+                         pfr++;
 
4198
+                       }
 
4199
+                     else
 
4200
+                       *to.d = *from.d;
 
4201
+                     to.d++;
 
4202
+                     from.d++;
 
4203
+                   }
 
4204
+                 while (--elnum != 0);
 
4205
+               }
 
4206
+           }
 
4207
+         else
 
4208
+           {
 
4209
+#ifndef __LITTLE_ENDIAN__
 
4210
+             /* Structures with size less than eight bytes are passed
 
4211
+                left-padded.  */
 
4212
+             if (arg_types[i]->size < 8)
 
4213
+               avalue[i] = (char *) pst + 8 - arg_types[i]->size;
 
4214
+             else
 
4215
+#endif
 
4216
+               avalue[i] = pst;
 
4217
+           }
 
4218
+         pst += (arg_types[i]->size + 7) / 8;
 
4219
+         break;
 
4220
+
 
4221
+#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
4222
+       case FFI_TYPE_LONGDOUBLE:
 
4223
+         if ((cif->abi & FFI_LINUX_LONG_DOUBLE_128) != 0)
 
4224
+           {
 
4225
+             if (pfr + 1 < end_pfr && i + 1 < nfixedargs)
 
4226
+               {
 
4227
+                 avalue[i] = pfr;
 
4228
+                 pfr += 2;
 
4229
+               }
 
4230
+             else
 
4231
+               {
 
4232
+                 if (pfr < end_pfr && i < nfixedargs)
 
4233
+                   {
 
4234
+                     /* Passed partly in f13 and partly on the stack.
 
4235
+                        Move it all to the stack.  */
 
4236
+                     *pst = *(unsigned long *) pfr;
 
4237
+                     pfr++;
 
4238
+                   }
 
4239
+                 avalue[i] = pst;
 
4240
+               }
 
4241
+             pst += 2;
 
4242
+             break;
 
4243
+           }
 
4244
+         /* Fall through.  */
 
4245
+#endif
 
4246
+       case FFI_TYPE_DOUBLE:
 
4247
+         /* On the outgoing stack all values are aligned to 8 */
 
4248
+         /* there are 13 64bit floating point registers */
 
4249
+
 
4250
+         if (pfr < end_pfr && i < nfixedargs)
 
4251
+           {
 
4252
+             avalue[i] = pfr;
 
4253
+             pfr++;
 
4254
+           }
 
4255
+         else
 
4256
+           avalue[i] = pst;
 
4257
+         pst++;
 
4258
+         break;
 
4259
+
 
4260
+       case FFI_TYPE_FLOAT:
 
4261
+         if (pfr < end_pfr && i < nfixedargs)
 
4262
+           {
 
4263
+             /* Float values are stored as doubles in the
 
4264
+                ffi_closure_LINUX64 code.  Fix them here.  */
 
4265
+             pfr->f = (float) pfr->d;
 
4266
+             avalue[i] = pfr;
 
4267
+             pfr++;
 
4268
+           }
 
4269
+         else
 
4270
+           avalue[i] = pst;
 
4271
+         pst++;
 
4272
+         break;
 
4273
+
 
4274
+       default:
 
4275
+         FFI_ASSERT (0);
 
4276
+       }
 
4277
+
 
4278
+      i++;
 
4279
+    }
 
4280
+
 
4281
+
 
4282
+  (closure->fun) (cif, rvalue, avalue, closure->user_data);
 
4283
+
 
4284
+  /* Tell ffi_closure_LINUX64 how to perform return type promotions.  */
 
4285
+  if ((cif->flags & FLAG_RETURNS_SMST) != 0)
 
4286
+    {
 
4287
+      if ((cif->flags & FLAG_RETURNS_FP) == 0)
 
4288
+       return FFI_V2_TYPE_SMALL_STRUCT + cif->rtype->size - 1;
 
4289
+      else if ((cif->flags & FLAG_RETURNS_64BITS) != 0)
 
4290
+       return FFI_V2_TYPE_DOUBLE_HOMOG;
 
4291
+      else
 
4292
+       return FFI_V2_TYPE_FLOAT_HOMOG;
 
4293
+    }
 
4294
+  return cif->rtype->type;
 
4295
+}
 
4296
+#endif
 
4297
--- a/src/libffi/src/powerpc/ppc_closure.S
 
4298
+++ b/src/libffi/src/powerpc/ppc_closure.S
 
4299
@@ -31,7 +31,7 @@
 
4300
 
 
4301
        .file   "ppc_closure.S"
 
4302
 
 
4303
-#ifndef __powerpc64__
 
4304
+#ifndef POWERPC64
 
4305
 
 
4306
 ENTRY(ffi_closure_SYSV)
 
4307
 .LFB1:
 
4308
@@ -378,8 +378,7 @@
 
4309
        .align 2
 
4310
 .LEFDE1:
 
4311
 
 
4312
-#endif
 
4313
-
 
4314
 #if defined __ELF__ && defined __linux__
 
4315
        .section        .note.GNU-stack,"",@progbits
 
4316
 #endif
 
4317
+#endif
 
4318
--- a/src/libffi/src/types.c
 
4319
+++ b/src/libffi/src/types.c
 
4320
@@ -44,6 +44,17 @@
 
4321
   id, NULL                                     \
 
4322
 }
 
4323
 
 
4324
+#define FFI_NONCONST_TYPEDEF(name, type, id)   \
 
4325
+struct struct_align_##name {                   \
 
4326
+  char c;                                      \
 
4327
+  type x;                                      \
 
4328
+};                                             \
 
4329
+ffi_type ffi_type_##name = {                   \
 
4330
+  sizeof(type),                                        \
 
4331
+  offsetof(struct struct_align_##name, x),     \
 
4332
+  id, NULL                                     \
 
4333
+}
 
4334
+
 
4335
 /* Size and alignment are fake here. They must not be 0. */
 
4336
 const ffi_type ffi_type_void = {
 
4337
   1, 1, FFI_TYPE_VOID, NULL
 
4338
@@ -73,5 +84,9 @@
 
4339
 # endif
 
4340
 const ffi_type ffi_type_longdouble = { 16, 16, 4, NULL };
 
4341
 #elif FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
4342
+# if HAVE_LONG_DOUBLE_VARIANT
 
4343
+FFI_NONCONST_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE);
 
4344
+# else
 
4345
 FFI_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE);
 
4346
+# endif
 
4347
 #endif
 
4348
--- a/src/libffi/testsuite/Makefile.in
 
4349
+++ b/src/libffi/testsuite/Makefile.in
 
4350
@@ -88,6 +88,7 @@
 
4351
 FGREP = @FGREP@
 
4352
 GREP = @GREP@
 
4353
 HAVE_LONG_DOUBLE = @HAVE_LONG_DOUBLE@
 
4354
+HAVE_LONG_DOUBLE_VARIANT = @HAVE_LONG_DOUBLE_VARIANT@
 
4355
 INSTALL = @INSTALL@
 
4356
 INSTALL_DATA = @INSTALL_DATA@
 
4357
 INSTALL_PROGRAM = @INSTALL_PROGRAM@