1 /* -----------------------------------------------------------------------
4 Copyright (C) 1998 Geoffrey Keating
5 Copyright (C) 2001 John Hornkvist
6 Copyright (C) 2002, 2006, 2007, 2009 Free Software Foundation, Inc.
8 FFI support for Darwin and AIX.
10 Permission is hereby granted, free of charge, to any person obtaining
11 a copy of this software and associated documentation files (the
12 ``Software''), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sublicense, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice shall be included
19 in all copies or substantial portions of the Software.
21 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 OTHER DEALINGS IN THE SOFTWARE.
28 ----------------------------------------------------------------------- */
31 #include <ffi_common.h>
35 extern void ffi_closure_ASM (void);
38 /* The assembly depends on these exact flags. */
39 FLAG_RETURNS_NOTHING
= 1 << (31-30), /* These go in cr7 */
40 FLAG_RETURNS_FP
= 1 << (31-29),
41 FLAG_RETURNS_64BITS
= 1 << (31-28),
42 FLAG_RETURNS_128BITS
= 1 << (31-31),
44 FLAG_ARG_NEEDS_COPY
= 1 << (31- 7),
45 FLAG_FP_ARGUMENTS
= 1 << (31- 6), /* cr1.eq; specified by ABI */
46 FLAG_4_GPR_ARGUMENTS
= 1 << (31- 5),
47 FLAG_RETVAL_REFERENCE
= 1 << (31- 4)
50 /* About the DARWIN ABI. */
52 NUM_GPR_ARG_REGISTERS
= 8,
53 NUM_FPR_ARG_REGISTERS
= 13
55 enum { ASM_NEEDS_REGISTERS
= 4 };
57 /* ffi_prep_args is called by the assembly routine once stack space
58 has been allocated for the function's arguments.
60 The stack layout we want looks like this:
62 | Return address from ffi_call_DARWIN | higher addresses
63 |--------------------------------------------|
64 | Previous backchain pointer 4 | stack pointer here
65 |--------------------------------------------|<+ <<< on entry to
66 | Saved r28-r31 4*4 | | ffi_call_DARWIN
67 |--------------------------------------------| |
68 | Parameters (at least 8*4=32) | |
69 |--------------------------------------------| |
70 | Space for GPR2 4 | |
71 |--------------------------------------------| | stack |
72 | Reserved 2*4 | | grows |
73 |--------------------------------------------| | down V
74 | Space for callee's LR 4 | |
75 |--------------------------------------------| | lower addresses
77 |--------------------------------------------| | stack pointer here
78 | Current backchain pointer 4 |-/ during
79 |--------------------------------------------| <<< ffi_call_DARWIN
84 ffi_prep_args (extended_cif
*ecif
, unsigned long *const stack
)
86 const unsigned bytes
= ecif
->cif
->bytes
;
87 const unsigned flags
= ecif
->cif
->flags
;
88 const unsigned nargs
= ecif
->cif
->nargs
;
89 const ffi_abi abi
= ecif
->cif
->abi
;
91 /* 'stacktop' points at the previous backchain pointer. */
92 unsigned long *const stacktop
= stack
+ (bytes
/ sizeof(unsigned long));
94 /* 'fpr_base' points at the space for fpr1, and grows upwards as
95 we use FPR registers. */
96 double *fpr_base
= (double *) (stacktop
- ASM_NEEDS_REGISTERS
) - NUM_FPR_ARG_REGISTERS
;
100 /* 'next_arg' grows up as we put parameters in it. */
101 unsigned long *next_arg
= stack
+ 6; /* 6 reserved positions. */
105 void **p_argv
= ecif
->avalue
;
106 unsigned long gprvalue
;
107 ffi_type
** ptr
= ecif
->cif
->arg_types
;
109 unsigned size_al
= 0;
111 /* Check that everything starts aligned properly. */
112 FFI_ASSERT(((unsigned) (char *) stack
& 0xF) == 0);
113 FFI_ASSERT(((unsigned) (char *) stacktop
& 0xF) == 0);
114 FFI_ASSERT((bytes
& 0xF) == 0);
116 /* Deal with return values that are actually pass-by-reference.
118 Return values are referenced by r3, so r4 is the first parameter. */
120 if (flags
& FLAG_RETVAL_REFERENCE
)
121 *next_arg
++ = (unsigned long) (char *) ecif
->rvalue
;
123 /* Now for the arguments. */
124 for (i
= nargs
; i
> 0; i
--, ptr
++, p_argv
++)
126 switch ((*ptr
)->type
)
128 /* If a floating-point parameter appears before all of the general-
129 purpose registers are filled, the corresponding GPRs that match
130 the size of the floating-point parameter are skipped. */
132 double_tmp
= *(float *) *p_argv
;
133 if (fparg_count
>= NUM_FPR_ARG_REGISTERS
)
134 *(double *)next_arg
= double_tmp
;
136 *fpr_base
++ = double_tmp
;
139 FFI_ASSERT(flags
& FLAG_FP_ARGUMENTS
);
142 case FFI_TYPE_DOUBLE
:
143 double_tmp
= *(double *) *p_argv
;
144 if (fparg_count
>= NUM_FPR_ARG_REGISTERS
)
145 *(double *)next_arg
= double_tmp
;
147 *fpr_base
++ = double_tmp
;
154 FFI_ASSERT(flags
& FLAG_FP_ARGUMENTS
);
157 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
159 case FFI_TYPE_LONGDOUBLE
:
161 if (fparg_count
< NUM_FPR_ARG_REGISTERS
)
162 *(long double *) fpr_base
++ = *(long double *) *p_argv
;
164 *(long double *) next_arg
= *(long double *) *p_argv
;
168 double_tmp
= ((double *) *p_argv
)[0];
169 if (fparg_count
< NUM_FPR_ARG_REGISTERS
)
170 *fpr_base
++ = double_tmp
;
172 *(double *) next_arg
= double_tmp
;
176 double_tmp
= ((double *) *p_argv
)[1];
177 if (fparg_count
< NUM_FPR_ARG_REGISTERS
)
178 *fpr_base
++ = double_tmp
;
180 *(double *) next_arg
= double_tmp
;
184 FFI_ASSERT(flags
& FLAG_FP_ARGUMENTS
);
187 case FFI_TYPE_UINT64
:
188 case FFI_TYPE_SINT64
:
190 gprvalue
= *(long long *) *p_argv
;
193 *(long long *) next_arg
= *(long long *) *p_argv
;
197 case FFI_TYPE_POINTER
:
198 gprvalue
= *(unsigned long *) *p_argv
;
201 gprvalue
= *(unsigned char *) *p_argv
;
204 gprvalue
= *(signed char *) *p_argv
;
206 case FFI_TYPE_UINT16
:
207 gprvalue
= *(unsigned short *) *p_argv
;
209 case FFI_TYPE_SINT16
:
210 gprvalue
= *(signed short *) *p_argv
;
213 case FFI_TYPE_STRUCT
:
215 dest_cpy
= (char *) next_arg
;
216 size_al
= (*ptr
)->size
;
217 if ((*ptr
)->elements
[0]->type
== 3)
218 size_al
= ALIGN((*ptr
)->size
, 8);
219 if (size_al
< 3 && abi
== FFI_DARWIN
)
220 dest_cpy
+= 4 - size_al
;
222 memcpy ((char *) dest_cpy
, (char *) *p_argv
, size_al
);
223 next_arg
+= (size_al
+ 7) / 8;
225 dest_cpy
= (char *) next_arg
;
227 /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
228 SI 4 bytes) are aligned as if they were those modes.
229 Structures with 3 byte in size are padded upwards. */
230 size_al
= (*ptr
)->size
;
231 /* If the first member of the struct is a double, then align
232 the struct to double-word. */
233 if ((*ptr
)->elements
[0]->type
== FFI_TYPE_DOUBLE
)
234 size_al
= ALIGN((*ptr
)->size
, 8);
235 if (size_al
< 3 && abi
== FFI_DARWIN
)
236 dest_cpy
+= 4 - size_al
;
238 memcpy((char *) dest_cpy
, (char *) *p_argv
, size_al
);
239 next_arg
+= (size_al
+ 3) / 4;
244 case FFI_TYPE_SINT32
:
245 gprvalue
= *(signed int *) *p_argv
;
248 case FFI_TYPE_UINT32
:
249 gprvalue
= *(unsigned int *) *p_argv
;
251 *next_arg
++ = gprvalue
;
258 /* Check that we didn't overrun the stack... */
259 //FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
260 //FFI_ASSERT((unsigned *)fpr_base
261 // <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
262 //FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
265 /* Adjust the size of S to be correct for Darwin.
266 On Darwin, the first field of a structure has natural alignment. */
269 darwin_adjust_aggregate_sizes (ffi_type
*s
)
273 if (s
->type
!= FFI_TYPE_STRUCT
)
277 for (i
= 0; s
->elements
[i
] != NULL
; i
++)
283 darwin_adjust_aggregate_sizes (p
);
285 && (p
->type
== FFI_TYPE_UINT64
286 || p
->type
== FFI_TYPE_SINT64
287 || p
->type
== FFI_TYPE_DOUBLE
288 || p
->alignment
== 8))
290 else if (p
->alignment
== 16 || p
->alignment
< 4)
291 align
= p
->alignment
;
294 s
->size
= ALIGN(s
->size
, align
) + p
->size
;
297 s
->size
= ALIGN(s
->size
, s
->alignment
);
299 if (s
->elements
[0]->type
== FFI_TYPE_UINT64
300 || s
->elements
[0]->type
== FFI_TYPE_SINT64
301 || s
->elements
[0]->type
== FFI_TYPE_DOUBLE
302 || s
->elements
[0]->alignment
== 8)
303 s
->alignment
= s
->alignment
> 8 ? s
->alignment
: 8;
304 /* Do not add additional tail padding. */
307 /* Adjust the size of S to be correct for AIX.
308 Word-align double unless it is the first member of a structure. */
311 aix_adjust_aggregate_sizes (ffi_type
*s
)
315 if (s
->type
!= FFI_TYPE_STRUCT
)
319 for (i
= 0; s
->elements
[i
] != NULL
; i
++)
325 aix_adjust_aggregate_sizes (p
);
326 align
= p
->alignment
;
327 if (i
!= 0 && p
->type
== FFI_TYPE_DOUBLE
)
329 s
->size
= ALIGN(s
->size
, align
) + p
->size
;
332 s
->size
= ALIGN(s
->size
, s
->alignment
);
334 if (s
->elements
[0]->type
== FFI_TYPE_UINT64
335 || s
->elements
[0]->type
== FFI_TYPE_SINT64
336 || s
->elements
[0]->type
== FFI_TYPE_DOUBLE
337 || s
->elements
[0]->alignment
== 8)
338 s
->alignment
= s
->alignment
> 8 ? s
->alignment
: 8;
339 /* Do not add additional tail padding. */
342 /* Perform machine dependent cif processing. */
344 ffi_prep_cif_machdep (ffi_cif
*cif
)
346 /* All this is for the DARWIN ABI. */
350 int fparg_count
= 0, intarg_count
= 0;
352 unsigned size_al
= 0;
354 /* All the machine-independent calculation of cif->bytes will be wrong.
355 All the calculation of structure sizes will also be wrong.
356 Redo the calculation for DARWIN. */
358 if (cif
->abi
== FFI_DARWIN
)
360 darwin_adjust_aggregate_sizes (cif
->rtype
);
361 for (i
= 0; i
< cif
->nargs
; i
++)
362 darwin_adjust_aggregate_sizes (cif
->arg_types
[i
]);
365 if (cif
->abi
== FFI_AIX
)
367 aix_adjust_aggregate_sizes (cif
->rtype
);
368 for (i
= 0; i
< cif
->nargs
; i
++)
369 aix_adjust_aggregate_sizes (cif
->arg_types
[i
]);
372 /* Space for the frame pointer, callee's LR, CR, etc, and for
373 the asm's temp regs. */
375 bytes
= (6 + ASM_NEEDS_REGISTERS
) * sizeof(long);
377 /* Return value handling. The rules are as follows:
378 - 32-bit (or less) integer values are returned in gpr3;
379 - Structures of size <= 4 bytes also returned in gpr3;
380 - 64-bit integer values and structures between 5 and 8 bytes are returned
382 - Single/double FP values are returned in fpr1;
383 - Long double FP (if not equivalent to double) values are returned in
385 - Larger structures values are allocated space and a pointer is passed
386 as the first argument. */
387 switch (cif
->rtype
->type
)
390 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
391 case FFI_TYPE_LONGDOUBLE
:
392 flags
|= FLAG_RETURNS_128BITS
;
393 flags
|= FLAG_RETURNS_FP
;
397 case FFI_TYPE_DOUBLE
:
398 flags
|= FLAG_RETURNS_64BITS
;
401 flags
|= FLAG_RETURNS_FP
;
404 case FFI_TYPE_UINT64
:
405 case FFI_TYPE_SINT64
:
407 case FFI_TYPE_POINTER
:
409 flags
|= FLAG_RETURNS_64BITS
;
412 case FFI_TYPE_STRUCT
:
413 flags
|= FLAG_RETVAL_REFERENCE
;
414 flags
|= FLAG_RETURNS_NOTHING
;
418 flags
|= FLAG_RETURNS_NOTHING
;
422 /* Returns 32-bit integer, or similar. Nothing to do here. */
426 /* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
427 first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
428 goes on the stack. Structures are passed as a pointer to a copy of
429 the structure. Stuff on the stack needs to keep proper alignment. */
430 for (ptr
= cif
->arg_types
, i
= cif
->nargs
; i
> 0; i
--, ptr
++)
432 switch ((*ptr
)->type
)
435 case FFI_TYPE_DOUBLE
:
437 /* If this FP arg is going on the stack, it must be
439 if (fparg_count
> NUM_FPR_ARG_REGISTERS
440 && intarg_count
%2 != 0)
444 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
446 case FFI_TYPE_LONGDOUBLE
:
448 /* If this FP arg is going on the stack, it must be
450 if (fparg_count
> NUM_FPR_ARG_REGISTERS
451 && intarg_count
%2 != 0)
457 case FFI_TYPE_UINT64
:
458 case FFI_TYPE_SINT64
:
459 /* 'long long' arguments are passed as two words, but
460 either both words must fit in registers or both go
461 on the stack. If they go on the stack, they must
462 be 8-byte-aligned. */
463 if (intarg_count
== NUM_GPR_ARG_REGISTERS
-1
464 || (intarg_count
>= NUM_GPR_ARG_REGISTERS
&& intarg_count
%2 != 0))
469 case FFI_TYPE_STRUCT
:
470 size_al
= (*ptr
)->size
;
471 /* If the first member of the struct is a double, then align
472 the struct to double-word. */
473 if ((*ptr
)->elements
[0]->type
== FFI_TYPE_DOUBLE
)
474 size_al
= ALIGN((*ptr
)->size
, 8);
476 intarg_count
+= (size_al
+ 7) / 8;
478 intarg_count
+= (size_al
+ 3) / 4;
483 /* Everything else is passed as a 4-byte word in a GPR, either
484 the object itself or a pointer to it. */
490 if (fparg_count
!= 0)
491 flags
|= FLAG_FP_ARGUMENTS
;
493 /* Space for the FPR registers, if needed. */
494 if (fparg_count
!= 0)
495 bytes
+= NUM_FPR_ARG_REGISTERS
* sizeof(double);
499 if ((intarg_count
+ fparg_count
) > NUM_GPR_ARG_REGISTERS
)
500 bytes
+= (intarg_count
+ fparg_count
) * sizeof(long);
502 if ((intarg_count
+ 2 * fparg_count
) > NUM_GPR_ARG_REGISTERS
)
503 bytes
+= (intarg_count
+ 2 * fparg_count
) * sizeof(long);
506 bytes
+= NUM_GPR_ARG_REGISTERS
* sizeof(long);
508 /* The stack space allocated needs to be a multiple of 16 bytes. */
509 bytes
= (bytes
+ 15) & ~0xF;
517 extern void ffi_call_AIX(extended_cif
*, long, unsigned, unsigned *,
518 void (*fn
)(void), void (*fn2
)(void));
519 extern void ffi_call_DARWIN(extended_cif
*, long, unsigned, unsigned *,
520 void (*fn
)(void), void (*fn2
)(void));
523 ffi_call (ffi_cif
*cif
, void (*fn
)(void), void *rvalue
, void **avalue
)
528 ecif
.avalue
= avalue
;
530 /* If the return value is a struct and we don't have a return
531 value address then we need to make one. */
533 if ((rvalue
== NULL
) &&
534 (cif
->rtype
->type
== FFI_TYPE_STRUCT
))
536 ecif
.rvalue
= alloca (cif
->rtype
->size
);
539 ecif
.rvalue
= rvalue
;
544 ffi_call_AIX(&ecif
, -(long)cif
->bytes
, cif
->flags
, ecif
.rvalue
, fn
,
548 ffi_call_DARWIN(&ecif
, -(long)cif
->bytes
, cif
->flags
, ecif
.rvalue
, fn
,
557 static void flush_icache(char *);
558 static void flush_range(char *, int);
560 /* The layout of a function descriptor. A C function pointer really
561 points to one of these. */
563 typedef struct aix_fd_struct
{
568 /* here I'd like to add the stack frame layout we use in darwin_closure.S
571 SP previous -> +---------------------------------------+ <--- child frame
572 | back chain to caller 4 |
573 +---------------------------------------+ 4
575 +---------------------------------------+ 8
577 +---------------------------------------+ 12
578 | reserved for compilers 4 |
579 +---------------------------------------+ 16
580 | reserved for binders 4 |
581 +---------------------------------------+ 20
582 | saved TOC pointer 4 |
583 +---------------------------------------+ 24
584 | always reserved 8*4=32 (previous GPRs)|
585 | according to the linkage convention |
587 +---------------------------------------+ 56
588 | our FPR area 13*8=104 |
592 +---------------------------------------+ 160
594 +---------------------------------------+ 168
595 | alignement to the next multiple of 16 |
596 SP current --> +---------------------------------------+ 176 <- parent frame
597 | back chain to caller 4 |
598 +---------------------------------------+ 180
600 +---------------------------------------+ 184
602 +---------------------------------------+ 188
603 | reserved for compilers 4 |
604 +---------------------------------------+ 192
605 | reserved for binders 4 |
606 +---------------------------------------+ 196
607 | saved TOC pointer 4 |
608 +---------------------------------------+ 200
609 | always reserved 8*4=32 we store our |
614 +---------------------------------------+ 232
616 +---------------------------------------+ xxx
618 +---------------------------------------+ xxx
622 ffi_prep_closure_loc (ffi_closure
* closure
,
624 void (*fun
)(ffi_cif
*, void*, void**, void*),
629 struct ffi_aix_trampoline_struct
*tramp_aix
;
636 FFI_ASSERT (cif
->abi
== FFI_DARWIN
);
638 tramp
= (unsigned int *) &closure
->tramp
[0];
639 tramp
[0] = 0x7c0802a6; /* mflr r0 */
640 tramp
[1] = 0x429f000d; /* bcl- 20,4*cr7+so,0x10 */
641 tramp
[4] = 0x7d6802a6; /* mflr r11 */
642 tramp
[5] = 0x818b0000; /* lwz r12,0(r11) function address */
643 tramp
[6] = 0x7c0803a6; /* mtlr r0 */
644 tramp
[7] = 0x7d8903a6; /* mtctr r12 */
645 tramp
[8] = 0x816b0004; /* lwz r11,4(r11) static chain */
646 tramp
[9] = 0x4e800420; /* bctr */
647 tramp
[2] = (unsigned long) ffi_closure_ASM
; /* function */
648 tramp
[3] = (unsigned long) codeloc
; /* context */
652 closure
->user_data
= user_data
;
654 /* Flush the icache. Only necessary on Darwin. */
655 flush_range(codeloc
, FFI_TRAMPOLINE_SIZE
);
661 tramp_aix
= (struct ffi_aix_trampoline_struct
*) (closure
->tramp
);
662 fd
= (aix_fd
*)(void *)ffi_closure_ASM
;
664 FFI_ASSERT (cif
->abi
== FFI_AIX
);
666 tramp_aix
->code_pointer
= fd
->code_pointer
;
667 tramp_aix
->toc
= fd
->toc
;
668 tramp_aix
->static_chain
= codeloc
;
671 closure
->user_data
= user_data
;
682 flush_icache(char *addr
)
691 : : "r"(addr
) : "memory");
696 flush_range(char * addr1
, int size
)
698 #define MIN_LINE_SIZE 32
700 for (i
= 0; i
< size
; i
+= MIN_LINE_SIZE
)
701 flush_icache(addr1
+i
);
702 flush_icache(addr1
+size
-1);
712 ffi_closure_helper_DARWIN (ffi_closure
*, void *,
713 unsigned long *, ffi_dblfl
*);
715 /* Basically the trampoline invokes ffi_closure_ASM, and on
716 entry, r11 holds the address of the closure.
717 After storing the registers that could possibly contain
718 parameters to be passed into the stack frame and setting
719 up space for a return value, ffi_closure_ASM invokes the
720 following helper function to do most of the work. */
723 ffi_closure_helper_DARWIN (ffi_closure
*closure
, void *rvalue
,
724 unsigned long *pgr
, ffi_dblfl
*pfr
)
726 /* rvalue is the pointer to space for return value in closure assembly
727 pgr is the pointer to where r3-r10 are stored in ffi_closure_ASM
728 pfr is the pointer to where f1-f13 are stored in ffi_closure_ASM. */
730 typedef double ldbits
[2];
739 ffi_type
** arg_types
;
742 ffi_dblfl
* end_pfr
= pfr
+ NUM_FPR_ARG_REGISTERS
;
746 avalue
= alloca (cif
->nargs
* sizeof(void *));
748 /* Copy the caller's structure return value address so that the closure
749 returns the data directly to the caller. */
750 if (cif
->rtype
->type
== FFI_TYPE_STRUCT
)
752 rvalue
= (void *) *pgr
;
758 arg_types
= cif
->arg_types
;
760 /* Grab the addresses of the arguments from the stack frame. */
763 switch (arg_types
[i
]->type
)
768 avalue
[i
] = (char *) pgr
+ 7;
770 avalue
[i
] = (char *) pgr
+ 3;
775 case FFI_TYPE_SINT16
:
776 case FFI_TYPE_UINT16
:
778 avalue
[i
] = (char *) pgr
+ 6;
780 avalue
[i
] = (char *) pgr
+ 2;
785 case FFI_TYPE_SINT32
:
786 case FFI_TYPE_UINT32
:
788 avalue
[i
] = (char *) pgr
+ 4;
790 case FFI_TYPE_POINTER
:
796 case FFI_TYPE_STRUCT
:
798 size_al
= arg_types
[i
]->size
;
799 if (arg_types
[i
]->elements
[0]->type
== FFI_TYPE_DOUBLE
)
800 size_al
= ALIGN (arg_types
[i
]->size
, 8);
801 if (size_al
< 3 && cif
->abi
== FFI_DARWIN
)
802 avalue
[i
] = (void *) pgr
+ 8 - size_al
;
804 avalue
[i
] = (void *) pgr
;
805 pgr
+= (size_al
+ 7) / 8;
807 /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
808 SI 4 bytes) are aligned as if they were those modes. */
809 size_al
= arg_types
[i
]->size
;
810 /* If the first member of the struct is a double, then align
811 the struct to double-word. */
812 if (arg_types
[i
]->elements
[0]->type
== FFI_TYPE_DOUBLE
)
813 size_al
= ALIGN(arg_types
[i
]->size
, 8);
814 if (size_al
< 3 && cif
->abi
== FFI_DARWIN
)
815 avalue
[i
] = (void*) pgr
+ 4 - size_al
;
817 avalue
[i
] = (void*) pgr
;
818 pgr
+= (size_al
+ 3) / 4;
822 case FFI_TYPE_SINT64
:
823 case FFI_TYPE_UINT64
:
825 case FFI_TYPE_POINTER
:
830 /* Long long ints are passed in two gpr's. */
837 /* A float value consumes a GPR.
838 There are 13 64bit floating point registers. */
841 double temp
= pfr
->d
;
842 pfr
->f
= (float) temp
;
853 case FFI_TYPE_DOUBLE
:
854 /* A double value consumes two GPRs.
855 There are 13 64bit floating point registers. */
872 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
874 case FFI_TYPE_LONGDOUBLE
:
876 if (pfr
+ 1 < end_pfr
)
885 *pgr
= *(unsigned long *) pfr
;
891 #else /* POWERPC64 */
892 /* A long double value consumes four GPRs and two FPRs.
893 There are 13 64bit floating point registers. */
894 if (pfr
+ 1 < end_pfr
)
899 /* Here we have the situation where one part of the long double
900 is stored in fpr13 and the other part is already on the stack.
901 We use a union to pass the long double to avalue[i]. */
902 else if (pfr
+ 1 == end_pfr
)
905 memcpy (&temp_ld
.lb
[0], pfr
, sizeof(ldbits
));
906 memcpy (&temp_ld
.lb
[1], pgr
+ 2, sizeof(ldbits
));
907 avalue
[i
] = &temp_ld
.ld
;
915 #endif /* POWERPC64 */
924 (closure
->fun
) (cif
, rvalue
, avalue
, closure
->user_data
);
926 /* Tell ffi_closure_ASM to perform return type promotions. */
927 return cif
->rtype
->type
;