1 /* -----------------------------------------------------------------------
2 ffi_linux64.c - Copyright (C) 2013 IBM
3 Copyright (C) 2011 Anthony Green
4 Copyright (C) 2011 Kyle Moffett
5 Copyright (C) 2008 Red Hat, Inc
6 Copyright (C) 2007, 2008 Free Software Foundation, Inc
7 Copyright (c) 1998 Geoffrey Keating
9 PowerPC Foreign Function Interface
11 Permission is hereby granted, free of charge, to any person obtaining
12 a copy of this software and associated documentation files (the
13 ``Software''), to deal in the Software without restriction, including
14 without limitation the rights to use, copy, modify, merge, publish,
15 distribute, sublicense, and/or sell copies of the Software, and to
16 permit persons to whom the Software is furnished to do so, subject to
17 the following conditions:
19 The above copyright notice and this permission notice shall be included
20 in all copies or substantial portions of the Software.
22 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 OTHER DEALINGS IN THE SOFTWARE.
29 ----------------------------------------------------------------------- */
34 #include "ffi_common.h"
35 #include "ffi_powerpc.h"
38 /* About the LINUX64 ABI. */
40 NUM_GPR_ARG_REGISTERS64
= 8,
41 NUM_FPR_ARG_REGISTERS64
= 13
43 enum { ASM_NEEDS_REGISTERS64
= 4 };
46 #if HAVE_LONG_DOUBLE_VARIANT && FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
47 /* Adjust size of ffi_type_longdouble. */
49 ffi_prep_types_linux64 (ffi_abi abi
)
51 if ((abi
& (FFI_LINUX
| FFI_LINUX_LONG_DOUBLE_128
)) == FFI_LINUX
)
53 ffi_type_longdouble
.size
= 8;
54 ffi_type_longdouble
.alignment
= 8;
58 ffi_type_longdouble
.size
= 16;
59 ffi_type_longdouble
.alignment
= 16;
67 discover_homogeneous_aggregate (const ffi_type
*t
, unsigned int *elnum
)
76 case FFI_TYPE_STRUCT
:;
78 unsigned int base_elt
= 0, total_elnum
= 0;
79 ffi_type
**el
= t
->elements
;
82 unsigned int el_elt
, el_elnum
= 0;
83 el_elt
= discover_homogeneous_aggregate (*el
, &el_elnum
);
85 || (base_elt
&& base_elt
!= el_elt
))
88 total_elnum
+= el_elnum
;
104 /* Perform machine dependent cif processing */
106 ffi_prep_cif_linux64_core (ffi_cif
*cif
)
110 unsigned i
, fparg_count
= 0, intarg_count
= 0;
111 unsigned flags
= cif
->flags
;
113 unsigned int elt
, elnum
;
116 #if FFI_TYPE_LONGDOUBLE == FFI_TYPE_DOUBLE
117 /* If compiled without long double support.. */
118 if ((cif
->abi
& FFI_LINUX_LONG_DOUBLE_128
) != 0)
122 /* The machine-independent calculation of cif->bytes doesn't work
123 for us. Redo the calculation. */
125 /* Space for backchain, CR, LR, TOC and the asm's temp regs. */
126 bytes
= (4 + ASM_NEEDS_REGISTERS64
) * sizeof (long);
128 /* Space for the general registers. */
129 bytes
+= NUM_GPR_ARG_REGISTERS64
* sizeof (long);
131 /* Space for backchain, CR, LR, cc/ld doubleword, TOC and the asm's temp
133 bytes
= (6 + ASM_NEEDS_REGISTERS64
) * sizeof (long);
135 /* Space for the mandatory parm save area and general registers. */
136 bytes
+= 2 * NUM_GPR_ARG_REGISTERS64
* sizeof (long);
139 /* Return value handling. */
140 switch (cif
->rtype
->type
)
142 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
143 case FFI_TYPE_LONGDOUBLE
:
144 if ((cif
->abi
& FFI_LINUX_LONG_DOUBLE_128
) != 0)
145 flags
|= FLAG_RETURNS_128BITS
;
148 case FFI_TYPE_DOUBLE
:
149 flags
|= FLAG_RETURNS_64BITS
;
152 flags
|= FLAG_RETURNS_FP
;
155 case FFI_TYPE_UINT128
:
156 flags
|= FLAG_RETURNS_128BITS
;
158 case FFI_TYPE_UINT64
:
159 case FFI_TYPE_SINT64
:
160 flags
|= FLAG_RETURNS_64BITS
;
163 case FFI_TYPE_STRUCT
:
165 elt
= discover_homogeneous_aggregate (cif
->rtype
, &elnum
);
168 if (elt
== FFI_TYPE_DOUBLE
)
169 flags
|= FLAG_RETURNS_64BITS
;
170 flags
|= FLAG_RETURNS_FP
| FLAG_RETURNS_SMST
;
173 if (cif
->rtype
->size
<= 16)
175 flags
|= FLAG_RETURNS_SMST
;
180 flags
|= FLAG_RETVAL_REFERENCE
;
183 flags
|= FLAG_RETURNS_NOTHING
;
187 /* Returns 32-bit integer, or similar. Nothing to do here. */
191 for (ptr
= cif
->arg_types
, i
= cif
->nargs
; i
> 0; i
--, ptr
++)
195 switch ((*ptr
)->type
)
197 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
198 case FFI_TYPE_LONGDOUBLE
:
199 if ((cif
->abi
& FFI_LINUX_LONG_DOUBLE_128
) != 0)
206 case FFI_TYPE_DOUBLE
:
210 if (fparg_count
> NUM_FPR_ARG_REGISTERS64
)
211 flags
|= FLAG_ARG_NEEDS_PSAVE
;
214 case FFI_TYPE_STRUCT
:
215 if ((cif
->abi
& FFI_LINUX_STRUCT_ALIGN
) != 0)
217 align
= (*ptr
)->alignment
;
222 intarg_count
= ALIGN (intarg_count
, align
);
224 intarg_count
+= ((*ptr
)->size
+ 7) / 8;
226 elt
= discover_homogeneous_aggregate (*ptr
, &elnum
);
229 fparg_count
+= elnum
;
230 if (fparg_count
> NUM_FPR_ARG_REGISTERS64
)
231 flags
|= FLAG_ARG_NEEDS_PSAVE
;
236 if (intarg_count
> NUM_GPR_ARG_REGISTERS64
)
237 flags
|= FLAG_ARG_NEEDS_PSAVE
;
241 case FFI_TYPE_POINTER
:
242 case FFI_TYPE_UINT64
:
243 case FFI_TYPE_SINT64
:
245 case FFI_TYPE_UINT32
:
246 case FFI_TYPE_SINT32
:
247 case FFI_TYPE_UINT16
:
248 case FFI_TYPE_SINT16
:
251 /* Everything else is passed as a 8-byte word in a GPR, either
252 the object itself or a pointer to it. */
254 if (intarg_count
> NUM_GPR_ARG_REGISTERS64
)
255 flags
|= FLAG_ARG_NEEDS_PSAVE
;
262 if (fparg_count
!= 0)
263 flags
|= FLAG_FP_ARGUMENTS
;
264 if (intarg_count
> 4)
265 flags
|= FLAG_4_GPR_ARGUMENTS
;
267 /* Space for the FPR registers, if needed. */
268 if (fparg_count
!= 0)
269 bytes
+= NUM_FPR_ARG_REGISTERS64
* sizeof (double);
273 if ((flags
& FLAG_ARG_NEEDS_PSAVE
) != 0)
274 bytes
+= intarg_count
* sizeof (long);
276 if (intarg_count
> NUM_GPR_ARG_REGISTERS64
)
277 bytes
+= (intarg_count
- NUM_GPR_ARG_REGISTERS64
) * sizeof (long);
280 /* The stack space allocated needs to be a multiple of 16 bytes. */
281 bytes
= (bytes
+ 15) & ~0xF;
289 ffi_status FFI_HIDDEN
290 ffi_prep_cif_linux64 (ffi_cif
*cif
)
292 if ((cif
->abi
& FFI_LINUX
) != 0)
293 cif
->nfixedargs
= cif
->nargs
;
295 else if (cif
->abi
== FFI_COMPAT_LINUX64
)
297 /* This call is from old code. Don't touch cif->nfixedargs
298 since old code will be using a smaller cif. */
299 cif
->flags
|= FLAG_COMPAT
;
300 /* Translate to new abi value. */
301 cif
->abi
= FFI_LINUX
| FFI_LINUX_LONG_DOUBLE_128
;
306 return ffi_prep_cif_linux64_core (cif
);
309 ffi_status FFI_HIDDEN
310 ffi_prep_cif_linux64_var (ffi_cif
*cif
,
311 unsigned int nfixedargs
,
312 unsigned int ntotalargs MAYBE_UNUSED
)
314 if ((cif
->abi
& FFI_LINUX
) != 0)
315 cif
->nfixedargs
= nfixedargs
;
317 else if (cif
->abi
== FFI_COMPAT_LINUX64
)
319 /* This call is from old code. Don't touch cif->nfixedargs
320 since old code will be using a smaller cif. */
321 cif
->flags
|= FLAG_COMPAT
;
322 /* Translate to new abi value. */
323 cif
->abi
= FFI_LINUX
| FFI_LINUX_LONG_DOUBLE_128
;
329 cif
->flags
|= FLAG_ARG_NEEDS_PSAVE
;
331 return ffi_prep_cif_linux64_core (cif
);
335 /* ffi_prep_args64 is called by the assembly routine once stack space
336 has been allocated for the function's arguments.
338 The stack layout we want looks like this:
340 | Ret addr from ffi_call_LINUX64 8bytes | higher addresses
341 |--------------------------------------------|
342 | CR save area 8bytes |
343 |--------------------------------------------|
344 | Previous backchain pointer 8 | stack pointer here
345 |--------------------------------------------|<+ <<< on entry to
346 | Saved r28-r31 4*8 | | ffi_call_LINUX64
347 |--------------------------------------------| |
348 | GPR registers r3-r10 8*8 | |
349 |--------------------------------------------| |
350 | FPR registers f1-f13 (optional) 13*8 | |
351 |--------------------------------------------| |
352 | Parameter save area | |
353 |--------------------------------------------| |
354 | TOC save area 8 | |
355 |--------------------------------------------| | stack |
356 | Linker doubleword 8 | | grows |
357 |--------------------------------------------| | down V
358 | Compiler doubleword 8 | |
359 |--------------------------------------------| | lower addresses
360 | Space for callee's LR 8 | |
361 |--------------------------------------------| |
363 |--------------------------------------------| | stack pointer here
364 | Current backchain pointer 8 |-/ during
365 |--------------------------------------------| <<< ffi_call_LINUX64
370 ffi_prep_args64 (extended_cif
*ecif
, unsigned long *const stack
)
372 const unsigned long bytes
= ecif
->cif
->bytes
;
373 const unsigned long flags
= ecif
->cif
->flags
;
384 /* 'stacktop' points at the previous backchain pointer. */
387 /* 'next_arg' points at the space for gpr3, and grows upwards as
388 we use GPR registers, then continues at rest. */
394 /* 'fpr_base' points at the space for fpr3, and grows upwards as
395 we use FPR registers. */
397 unsigned int fparg_count
;
399 unsigned int i
, words
, nargs
, nfixedargs
;
416 unsigned long gprvalue
;
419 stacktop
.c
= (char *) stack
+ bytes
;
420 gpr_base
.ul
= stacktop
.ul
- ASM_NEEDS_REGISTERS64
- NUM_GPR_ARG_REGISTERS64
;
421 gpr_end
.ul
= gpr_base
.ul
+ NUM_GPR_ARG_REGISTERS64
;
423 rest
.ul
= stack
+ 4 + NUM_GPR_ARG_REGISTERS64
;
425 rest
.ul
= stack
+ 6 + NUM_GPR_ARG_REGISTERS64
;
427 fpr_base
.d
= gpr_base
.d
- NUM_FPR_ARG_REGISTERS64
;
429 next_arg
.ul
= gpr_base
.ul
;
431 /* Check that everything starts aligned properly. */
432 FFI_ASSERT (((unsigned long) (char *) stack
& 0xF) == 0);
433 FFI_ASSERT (((unsigned long) stacktop
.c
& 0xF) == 0);
434 FFI_ASSERT ((bytes
& 0xF) == 0);
436 /* Deal with return values that are actually pass-by-reference. */
437 if (flags
& FLAG_RETVAL_REFERENCE
)
438 *next_arg
.ul
++ = (unsigned long) (char *) ecif
->rvalue
;
440 /* Now for the arguments. */
441 p_argv
.v
= ecif
->avalue
;
442 nargs
= ecif
->cif
->nargs
;
444 nfixedargs
= (unsigned) -1;
445 if ((flags
& FLAG_COMPAT
) == 0)
447 nfixedargs
= ecif
->cif
->nfixedargs
;
448 for (ptr
= ecif
->cif
->arg_types
, i
= 0;
450 i
++, ptr
++, p_argv
.v
++)
453 unsigned int elt
, elnum
;
456 switch ((*ptr
)->type
)
458 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
459 case FFI_TYPE_LONGDOUBLE
:
460 if ((ecif
->cif
->abi
& FFI_LINUX_LONG_DOUBLE_128
) != 0)
462 double_tmp
= (*p_argv
.d
)[0];
463 if (fparg_count
< NUM_FPR_ARG_REGISTERS64
&& i
< nfixedargs
)
465 *fpr_base
.d
++ = double_tmp
;
467 if ((flags
& FLAG_COMPAT
) != 0)
468 *next_arg
.d
= double_tmp
;
472 *next_arg
.d
= double_tmp
;
473 if (++next_arg
.ul
== gpr_end
.ul
)
474 next_arg
.ul
= rest
.ul
;
476 double_tmp
= (*p_argv
.d
)[1];
477 if (fparg_count
< NUM_FPR_ARG_REGISTERS64
&& i
< nfixedargs
)
479 *fpr_base
.d
++ = double_tmp
;
481 if ((flags
& FLAG_COMPAT
) != 0)
482 *next_arg
.d
= double_tmp
;
486 *next_arg
.d
= double_tmp
;
487 if (++next_arg
.ul
== gpr_end
.ul
)
488 next_arg
.ul
= rest
.ul
;
490 FFI_ASSERT (__LDBL_MANT_DIG__
== 106);
491 FFI_ASSERT (flags
& FLAG_FP_ARGUMENTS
);
496 case FFI_TYPE_DOUBLE
:
497 double_tmp
= **p_argv
.d
;
498 if (fparg_count
< NUM_FPR_ARG_REGISTERS64
&& i
< nfixedargs
)
500 *fpr_base
.d
++ = double_tmp
;
502 if ((flags
& FLAG_COMPAT
) != 0)
503 *next_arg
.d
= double_tmp
;
507 *next_arg
.d
= double_tmp
;
508 if (++next_arg
.ul
== gpr_end
.ul
)
509 next_arg
.ul
= rest
.ul
;
511 FFI_ASSERT (flags
& FLAG_FP_ARGUMENTS
);
515 double_tmp
= **p_argv
.f
;
516 if (fparg_count
< NUM_FPR_ARG_REGISTERS64
&& i
< nfixedargs
)
518 *fpr_base
.d
++ = double_tmp
;
520 if ((flags
& FLAG_COMPAT
) != 0)
521 *next_arg
.f
= (float) double_tmp
;
525 *next_arg
.f
= (float) double_tmp
;
526 if (++next_arg
.ul
== gpr_end
.ul
)
527 next_arg
.ul
= rest
.ul
;
529 FFI_ASSERT (flags
& FLAG_FP_ARGUMENTS
);
532 case FFI_TYPE_STRUCT
:
533 if ((ecif
->cif
->abi
& FFI_LINUX_STRUCT_ALIGN
) != 0)
535 align
= (*ptr
)->alignment
;
539 next_arg
.p
= ALIGN (next_arg
.p
, align
);
542 elt
= discover_homogeneous_aggregate (*ptr
, &elnum
);
552 if (elt
== FFI_TYPE_FLOAT
)
556 double_tmp
= *arg
.f
++;
557 if (fparg_count
< NUM_FPR_ARG_REGISTERS64
559 *fpr_base
.d
++ = double_tmp
;
561 *next_arg
.f
= (float) double_tmp
;
562 if (++next_arg
.f
== gpr_end
.f
)
566 while (--elnum
!= 0);
567 if ((next_arg
.p
& 3) != 0)
569 if (++next_arg
.f
== gpr_end
.f
)
576 double_tmp
= *arg
.d
++;
577 if (fparg_count
< NUM_FPR_ARG_REGISTERS64
&& i
< nfixedargs
)
578 *fpr_base
.d
++ = double_tmp
;
580 *next_arg
.d
= double_tmp
;
581 if (++next_arg
.d
== gpr_end
.d
)
585 while (--elnum
!= 0);
590 words
= ((*ptr
)->size
+ 7) / 8;
591 if (next_arg
.ul
>= gpr_base
.ul
&& next_arg
.ul
+ words
> gpr_end
.ul
)
593 size_t first
= gpr_end
.c
- next_arg
.c
;
594 memcpy (next_arg
.c
, *p_argv
.c
, first
);
595 memcpy (rest
.c
, *p_argv
.c
+ first
, (*ptr
)->size
- first
);
596 next_arg
.c
= rest
.c
+ words
* 8 - first
;
600 char *where
= next_arg
.c
;
602 #ifndef __LITTLE_ENDIAN__
603 /* Structures with size less than eight bytes are passed
605 if ((*ptr
)->size
< 8)
606 where
+= 8 - (*ptr
)->size
;
608 memcpy (where
, *p_argv
.c
, (*ptr
)->size
);
609 next_arg
.ul
+= words
;
610 if (next_arg
.ul
== gpr_end
.ul
)
611 next_arg
.ul
= rest
.ul
;
617 gprvalue
= **p_argv
.uc
;
620 gprvalue
= **p_argv
.sc
;
622 case FFI_TYPE_UINT16
:
623 gprvalue
= **p_argv
.us
;
625 case FFI_TYPE_SINT16
:
626 gprvalue
= **p_argv
.ss
;
628 case FFI_TYPE_UINT32
:
629 gprvalue
= **p_argv
.ui
;
632 case FFI_TYPE_SINT32
:
633 gprvalue
= **p_argv
.si
;
636 case FFI_TYPE_UINT64
:
637 case FFI_TYPE_SINT64
:
638 case FFI_TYPE_POINTER
:
639 gprvalue
= **p_argv
.ul
;
641 *next_arg
.ul
++ = gprvalue
;
642 if (next_arg
.ul
== gpr_end
.ul
)
643 next_arg
.ul
= rest
.ul
;
648 FFI_ASSERT (flags
& FLAG_4_GPR_ARGUMENTS
649 || (next_arg
.ul
>= gpr_base
.ul
650 && next_arg
.ul
<= gpr_base
.ul
+ 4));
655 #define MIN_CACHE_LINE_SIZE 8
658 flush_icache (char *wraddr
, char *xaddr
, int size
)
661 for (i
= 0; i
< size
; i
+= MIN_CACHE_LINE_SIZE
)
662 __asm__
volatile ("icbi 0,%0;" "dcbf 0,%1;"
663 : : "r" (xaddr
+ i
), "r" (wraddr
+ i
) : "memory");
664 __asm__
volatile ("icbi 0,%0;" "dcbf 0,%1;" "sync;" "isync;"
665 : : "r"(xaddr
+ size
- 1), "r"(wraddr
+ size
- 1)
671 ffi_prep_closure_loc_linux64 (ffi_closure
*closure
,
673 void (*fun
) (ffi_cif
*, void *, void **, void *),
678 unsigned int *tramp
= (unsigned int *) &closure
->tramp
[0];
680 if (cif
->abi
< FFI_LINUX
|| cif
->abi
>= FFI_LAST_ABI
)
683 tramp
[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
684 tramp
[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
685 tramp
[2] = 0x7d8903a6; /* mtctr 12 */
686 tramp
[3] = 0x4e800420; /* bctr */
687 /* 1: .quad function_addr */
688 /* 2: .quad context */
689 *(void **) &tramp
[4] = (void *) ffi_closure_LINUX64
;
690 *(void **) &tramp
[6] = codeloc
;
691 flush_icache ((char *)tramp
, (char *)codeloc
, FFI_TRAMPOLINE_SIZE
);
693 void **tramp
= (void **) &closure
->tramp
[0];
695 if (cif
->abi
< FFI_LINUX
|| cif
->abi
>= FFI_LAST_ABI
)
698 /* Copy function address and TOC from ffi_closure_LINUX64. */
699 memcpy (tramp
, (char *) ffi_closure_LINUX64
, 16);
705 closure
->user_data
= user_data
;
712 ffi_closure_helper_LINUX64 (ffi_closure
*closure
, void *rvalue
,
713 unsigned long *pst
, ffi_dblfl
*pfr
)
715 /* rvalue is the pointer to space for return value in closure assembly */
716 /* pst is the pointer to parameter save area
717 (r3-r10 are stored into its first 8 slots by ffi_closure_LINUX64) */
718 /* pfr is the pointer to where f1-f13 are stored in ffi_closure_LINUX64 */
721 ffi_type
**arg_types
;
722 unsigned long i
, avn
, nfixedargs
;
724 ffi_dblfl
*end_pfr
= pfr
+ NUM_FPR_ARG_REGISTERS64
;
728 avalue
= alloca (cif
->nargs
* sizeof (void *));
730 /* Copy the caller's structure return value address so that the
731 closure returns the data directly to the caller. */
732 if (cif
->rtype
->type
== FFI_TYPE_STRUCT
733 && (cif
->flags
& FLAG_RETURNS_SMST
) == 0)
735 rvalue
= (void *) *pst
;
742 nfixedargs
= (unsigned) -1;
743 if ((cif
->flags
& FLAG_COMPAT
) == 0)
745 nfixedargs
= cif
->nfixedargs
;
746 arg_types
= cif
->arg_types
;
748 /* Grab the addresses of the arguments from the stack frame. */
751 unsigned int elt
, elnum
;
753 switch (arg_types
[i
]->type
)
757 #ifndef __LITTLE_ENDIAN__
758 avalue
[i
] = (char *) pst
+ 7;
763 case FFI_TYPE_SINT16
:
764 case FFI_TYPE_UINT16
:
765 #ifndef __LITTLE_ENDIAN__
766 avalue
[i
] = (char *) pst
+ 6;
771 case FFI_TYPE_SINT32
:
772 case FFI_TYPE_UINT32
:
773 #ifndef __LITTLE_ENDIAN__
774 avalue
[i
] = (char *) pst
+ 4;
779 case FFI_TYPE_SINT64
:
780 case FFI_TYPE_UINT64
:
781 case FFI_TYPE_POINTER
:
786 case FFI_TYPE_STRUCT
:
787 if ((cif
->abi
& FFI_LINUX_STRUCT_ALIGN
) != 0)
789 align
= arg_types
[i
]->alignment
;
793 pst
= (unsigned long *) ALIGN ((size_t) pst
, align
);
797 elt
= discover_homogeneous_aggregate (arg_types
[i
], &elnum
);
809 /* Repackage the aggregate from its parts. The
810 aggregate size is not greater than the space taken by
811 the registers so store back to the register/parameter
813 if (pfr
+ elnum
<= end_pfr
)
820 if (elt
== FFI_TYPE_FLOAT
)
824 if (pfr
< end_pfr
&& i
< nfixedargs
)
826 *to
.f
= (float) pfr
->d
;
834 while (--elnum
!= 0);
840 if (pfr
< end_pfr
&& i
< nfixedargs
)
850 while (--elnum
!= 0);
855 #ifndef __LITTLE_ENDIAN__
856 /* Structures with size less than eight bytes are passed
858 if (arg_types
[i
]->size
< 8)
859 avalue
[i
] = (char *) pst
+ 8 - arg_types
[i
]->size
;
864 pst
+= (arg_types
[i
]->size
+ 7) / 8;
867 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
868 case FFI_TYPE_LONGDOUBLE
:
869 if ((cif
->abi
& FFI_LINUX_LONG_DOUBLE_128
) != 0)
871 if (pfr
+ 1 < end_pfr
&& i
+ 1 < nfixedargs
)
878 if (pfr
< end_pfr
&& i
< nfixedargs
)
880 /* Passed partly in f13 and partly on the stack.
881 Move it all to the stack. */
882 *pst
= *(unsigned long *) pfr
;
892 case FFI_TYPE_DOUBLE
:
893 /* On the outgoing stack all values are aligned to 8 */
894 /* there are 13 64bit floating point registers */
896 if (pfr
< end_pfr
&& i
< nfixedargs
)
907 if (pfr
< end_pfr
&& i
< nfixedargs
)
909 /* Float values are stored as doubles in the
910 ffi_closure_LINUX64 code. Fix them here. */
911 pfr
->f
= (float) pfr
->d
;
928 (closure
->fun
) (cif
, rvalue
, avalue
, closure
->user_data
);
930 /* Tell ffi_closure_LINUX64 how to perform return type promotions. */
931 if ((cif
->flags
& FLAG_RETURNS_SMST
) != 0)
933 if ((cif
->flags
& FLAG_RETURNS_FP
) == 0)
934 return FFI_V2_TYPE_SMALL_STRUCT
+ cif
->rtype
->size
- 1;
935 else if ((cif
->flags
& FLAG_RETURNS_64BITS
) != 0)
936 return FFI_V2_TYPE_DOUBLE_HOMOG
;
938 return FFI_V2_TYPE_FLOAT_HOMOG
;
940 return cif
->rtype
->type
;