OSDN Git Service

2003-09-18 Andreas Tobler <a.tobler@schweiz.ch>
[pf3gnuchains/gcc-fork.git] / libffi / src / powerpc / ffi_darwin.c
1 /* -----------------------------------------------------------------------
2    ffi.c - Copyright (c) 1998 Geoffrey Keating
3
4    PowerPC Foreign Function Interface
5
6    Darwin ABI support (c) 2001 John Hornkvist
7    AIX ABI support (c) 2002 Free Software Foundation, Inc.
8
9    Permission is hereby granted, free of charge, to any person obtaining
10    a copy of this software and associated documentation files (the
11    ``Software''), to deal in the Software without restriction, including
12    without limitation the rights to use, copy, modify, merge, publish,
13    distribute, sublicense, and/or sell copies of the Software, and to
14    permit persons to whom the Software is furnished to do so, subject to
15    the following conditions:
16
17    The above copyright notice and this permission notice shall be included
18    in all copies or substantial portions of the Software.
19
20    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
21    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
24    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26    OTHER DEALINGS IN THE SOFTWARE.
27    ----------------------------------------------------------------------- */
28 #include <ffi.h>
29 #include <ffi_common.h>
30
31 #include <stdlib.h>
32
33 extern void ffi_closure_ASM(void);
34
35 enum {
36   /* The assembly depends on these exact flags.  */
37   FLAG_RETURNS_NOTHING  = 1 << (31-30), /* These go in cr7  */
38   FLAG_RETURNS_FP       = 1 << (31-29),
39   FLAG_RETURNS_64BITS   = 1 << (31-28),
40
41   FLAG_ARG_NEEDS_COPY   = 1 << (31- 7),
42   FLAG_FP_ARGUMENTS     = 1 << (31- 6), /* cr1.eq; specified by ABI  */
43   FLAG_4_GPR_ARGUMENTS  = 1 << (31- 5),
44   FLAG_RETVAL_REFERENCE = 1 << (31- 4)
45 };
46
47 /* About the DARWIN ABI.  */
48 enum {
49   NUM_GPR_ARG_REGISTERS = 8,
50   NUM_FPR_ARG_REGISTERS = 13
51 };
52 enum { ASM_NEEDS_REGISTERS = 4 };
53
54 /* ffi_prep_args is called by the assembly routine once stack space
55    has been allocated for the function's arguments.
56
57    The stack layout we want looks like this:
58
59    |   Return address from ffi_call_DARWIN      |       higher addresses
60    |--------------------------------------------|
61    |   Previous backchain pointer       4       |       stack pointer here
62    |--------------------------------------------|<+ <<< on entry to
63    |   Saved r28-r31                    4*4     | |     ffi_call_DARWIN
64    |--------------------------------------------| |
65    |   Parameters             (at least 8*4=32) | |
66    |--------------------------------------------| |
67    |   Space for GPR2                   4       | |
68    |--------------------------------------------| |     stack   |
69    |   Reserved                       2*4       | |     grows   |
70    |--------------------------------------------| |     down    V
71    |   Space for callee's LR            4       | |
72    |--------------------------------------------| |     lower addresses
73    |   Saved CR                         4       | |
74    |--------------------------------------------| |     stack pointer here
75    |   Current backchain pointer        4       |-/     during
76    |--------------------------------------------|   <<< ffi_call_DARWIN
77
78    */
79
80 /*@-exportheader@*/
81 void ffi_prep_args(extended_cif *ecif, unsigned *const stack)
82 /*@=exportheader@*/
83 {
84   const unsigned flags = ecif->cif->flags;
85
86   /* 'stacktop' points at the previous backchain pointer.  */
87   unsigned *const stacktop = stack + (ecif->cif->bytes / sizeof(unsigned));
88
89   /* 'fpr_base' points at the space for fpr1, and grows upwards as
90      we use FPR registers.  */
91   double *fpr_base = (double*) (stacktop - ASM_NEEDS_REGISTERS) - NUM_FPR_ARG_REGISTERS;
92   int fparg_count = 0;
93
94
95   /* 'next_arg' grows up as we put parameters in it.  */
96   unsigned *next_arg = stack + 6; /* 6 reserved posistions.  */
97
98   int i = ecif->cif->nargs;
99   double double_tmp;
100   void **p_argv = ecif->avalue;
101   unsigned gprvalue;
102   ffi_type** ptr = ecif->cif->arg_types;
103   char *dest_cpy;
104   unsigned size_al = 0;
105
106   /* Check that everything starts aligned properly.  */
107   FFI_ASSERT(((unsigned)(char *)stack & 0xF) == 0);
108   FFI_ASSERT(((unsigned)(char *)stacktop & 0xF) == 0);
109   FFI_ASSERT((bytes & 0xF) == 0);
110
111   /* Deal with return values that are actually pass-by-reference.
112      Rule:
113      Return values are referenced by r3, so r4 is the first parameter.  */
114
115   if (flags & FLAG_RETVAL_REFERENCE)
116     *next_arg++ = (unsigned)(char *)ecif->rvalue;
117
118   /* Now for the arguments.  */
119   for (;
120        i > 0;
121        i--, ptr++, p_argv++)
122     {
123       switch ((*ptr)->type)
124         {
125         /* If a floating-point parameter appears before all of the general-
126            purpose registers are filled, the corresponding GPRs that match
127            the size of the floating-point parameter are skipped.  */
128         case FFI_TYPE_FLOAT:
129           double_tmp = *(float *)*p_argv;
130           if (fparg_count >= NUM_FPR_ARG_REGISTERS)
131             *(double *)next_arg = double_tmp;
132           else
133             *fpr_base++ = double_tmp;
134           next_arg++;
135           fparg_count++;
136           FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
137           break;
138         case FFI_TYPE_DOUBLE:
139           double_tmp = *(double *)*p_argv;
140           if (fparg_count >= NUM_FPR_ARG_REGISTERS)
141             *(double *)next_arg = double_tmp;
142           else
143             *fpr_base++ = double_tmp;
144           next_arg += 2;
145           fparg_count++;
146           FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
147           break;
148
149         case FFI_TYPE_UINT64:
150         case FFI_TYPE_SINT64:
151           *(long long *)next_arg = *(long long *)*p_argv;
152           next_arg+=2;
153           break;
154         case FFI_TYPE_UINT8:
155           gprvalue = *(unsigned char *)*p_argv;
156           goto putgpr;
157         case FFI_TYPE_SINT8:
158           gprvalue = *(signed char *)*p_argv;
159           goto putgpr;
160         case FFI_TYPE_UINT16:
161           gprvalue = *(unsigned short *)*p_argv;
162           goto putgpr;
163         case FFI_TYPE_SINT16:
164           gprvalue = *(signed short *)*p_argv;
165           goto putgpr;
166
167         case FFI_TYPE_STRUCT:
168
169 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
170         case FFI_TYPE_LONGDOUBLE:
171 #endif
172           dest_cpy = (char *) next_arg;
173
174           /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
175              SI 4 bytes) are aligned as if they were those modes.
176              Structures with 3 byte in size are padded upwards.  */
177           size_al = (*ptr)->size;
178           /* If the first member of the struct is a double, then align
179              the struct to double-word.
180              Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3.  */
181           if ((*ptr)->elements[0]->type == 3)
182             size_al = ALIGN((*ptr)->size, 8);
183           if (size_al < 3 && ecif->cif->abi == FFI_DARWIN)
184             dest_cpy += 4 - size_al;
185
186           memcpy((char *)dest_cpy, (char *)*p_argv, size_al);
187           next_arg += (size_al + 3) / 4;
188           break;
189
190         case FFI_TYPE_INT:
191         case FFI_TYPE_UINT32:
192         case FFI_TYPE_SINT32:
193         case FFI_TYPE_POINTER:
194           gprvalue = *(unsigned *)*p_argv;
195         putgpr:
196           *next_arg++ = gprvalue;
197           break;
198         default:
199           break;
200         }
201     }
202
203   /* Check that we didn't overrun the stack...  */
204   //FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
205   //FFI_ASSERT((unsigned *)fpr_base
206   //         <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
207   //FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
208 }
209
210 /* Perform machine dependent cif processing.  */
211 ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
212 {
213   /* All this is for the DARWIN ABI.  */
214   int i;
215   ffi_type **ptr;
216   unsigned bytes;
217   int fparg_count = 0, intarg_count = 0;
218   unsigned flags = 0;
219   unsigned size_al = 0;
220
221   /* All the machine-independent calculation of cif->bytes will be wrong.
222      Redo the calculation for DARWIN.  */
223
224   /* Space for the frame pointer, callee's LR, CR, etc, and for
225      the asm's temp regs.  */
226
227   bytes = (6 + ASM_NEEDS_REGISTERS) * sizeof(long);
228
229   /* Return value handling.  The rules are as follows:
230      - 32-bit (or less) integer values are returned in gpr3;
231      - Structures of size <= 4 bytes also returned in gpr3;
232      - 64-bit integer values and structures between 5 and 8 bytes are returned
233        in gpr3 and gpr4;
234      - Single/double FP values are returned in fpr1;
235      - Long double FP (if not equivalent to double) values are returned in
236        fpr1 and fpr2;
237      - Larger structures values are allocated space and a pointer is passed
238        as the first argument.  */
239   switch (cif->rtype->type)
240     {
241 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
242     case FFI_TYPE_LONGDOUBLE:
243 #endif
244       /* Fall through.  */
245     case FFI_TYPE_DOUBLE:
246       flags |= FLAG_RETURNS_64BITS;
247       /* Fall through.  */
248     case FFI_TYPE_FLOAT:
249       flags |= FLAG_RETURNS_FP;
250       break;
251
252     case FFI_TYPE_UINT64:
253     case FFI_TYPE_SINT64:
254       flags |= FLAG_RETURNS_64BITS;
255       break;
256
257     case FFI_TYPE_STRUCT:
258       flags |= FLAG_RETVAL_REFERENCE;
259       flags |= FLAG_RETURNS_NOTHING;
260       intarg_count++;
261       break;
262     case FFI_TYPE_VOID:
263       flags |= FLAG_RETURNS_NOTHING;
264       break;
265
266     default:
267       /* Returns 32-bit integer, or similar.  Nothing to do here.  */
268       break;
269     }
270
271   /* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
272      first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
273      goes on the stack.  Structures and long doubles (if not equivalent
274      to double) are passed as a pointer to a copy of the structure.
275      Stuff on the stack needs to keep proper alignment.  */
276   for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
277     {
278       switch ((*ptr)->type)
279         {
280         case FFI_TYPE_FLOAT:
281         case FFI_TYPE_DOUBLE:
282           fparg_count++;
283           /* If this FP arg is going on the stack, it must be
284              8-byte-aligned.  */
285           if (fparg_count > NUM_FPR_ARG_REGISTERS
286               && intarg_count%2 != 0)
287             intarg_count++;
288           break;
289
290         case FFI_TYPE_UINT64:
291         case FFI_TYPE_SINT64:
292           /* 'long long' arguments are passed as two words, but
293              either both words must fit in registers or both go
294              on the stack.  If they go on the stack, they must
295              be 8-byte-aligned.  */
296           if (intarg_count == NUM_GPR_ARG_REGISTERS-1
297               || (intarg_count >= NUM_GPR_ARG_REGISTERS && intarg_count%2 != 0))
298             intarg_count++;
299           intarg_count += 2;
300           break;
301
302         case FFI_TYPE_STRUCT:
303 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
304         case FFI_TYPE_LONGDOUBLE:
305 #endif
306           size_al = (*ptr)->size;
307           /* If the first member of the struct is a double, then align
308              the struct to double-word.
309              Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3.  */
310           if ((*ptr)->elements[0]->type == 3)
311             size_al = ALIGN((*ptr)->size, 8);
312           intarg_count += (size_al + 3) / 4;
313           break;
314
315         default:
316           /* Everything else is passed as a 4-byte word in a GPR, either
317              the object itself or a pointer to it.  */
318           intarg_count++;
319           break;
320         }
321     }
322
323   if (fparg_count != 0)
324     flags |= FLAG_FP_ARGUMENTS;
325
326   /* Space for the FPR registers, if needed.  */
327   if (fparg_count != 0)
328     bytes += NUM_FPR_ARG_REGISTERS * sizeof(double);
329
330   /* Stack space.  */
331   if ((intarg_count + 2 * fparg_count) > NUM_GPR_ARG_REGISTERS)
332     bytes += (intarg_count + 2 * fparg_count) * sizeof(long);
333   else
334     bytes += NUM_GPR_ARG_REGISTERS * sizeof(long);
335
336   /* The stack space allocated needs to be a multiple of 16 bytes.  */
337   bytes = (bytes + 15) & ~0xF;
338
339   cif->flags = flags;
340   cif->bytes = bytes;
341
342   return FFI_OK;
343 }
344
345 /*@-declundef@*/
346 /*@-exportheader@*/
347 extern void ffi_call_AIX(/*@out@*/ extended_cif *,
348                          unsigned, unsigned,
349                          /*@out@*/ unsigned *,
350                          void (*fn)(),
351                          void (*fn2)());
352 extern void ffi_call_DARWIN(/*@out@*/ extended_cif *,
353                             unsigned, unsigned,
354                             /*@out@*/ unsigned *,
355                             void (*fn)(),
356                             void (*fn2)());
357 /*@=declundef@*/
358 /*@=exportheader@*/
359
360 void ffi_call(/*@dependent@*/ ffi_cif *cif,
361               void (*fn)(),
362               /*@out@*/ void *rvalue,
363               /*@dependent@*/ void **avalue)
364 {
365   extended_cif ecif;
366
367   ecif.cif = cif;
368   ecif.avalue = avalue;
369
370   /* If the return value is a struct and we don't have a return
371      value address then we need to make one.  */
372
373   if ((rvalue == NULL) &&
374       (cif->rtype->type == FFI_TYPE_STRUCT))
375     {
376       /*@-sysunrecog@*/
377       ecif.rvalue = alloca(cif->rtype->size);
378       /*@=sysunrecog@*/
379     }
380   else
381     ecif.rvalue = rvalue;
382
383   switch (cif->abi)
384     {
385     case FFI_AIX:
386       /*@-usedef@*/
387       ffi_call_AIX(&ecif, -cif->bytes,
388                    cif->flags, ecif.rvalue, fn, ffi_prep_args);
389       /*@=usedef@*/
390       break;
391     case FFI_DARWIN:
392       /*@-usedef@*/
393       ffi_call_DARWIN(&ecif, -cif->bytes,
394                       cif->flags, ecif.rvalue, fn, ffi_prep_args);
395       /*@=usedef@*/
396       break;
397     default:
398       FFI_ASSERT(0);
399       break;
400     }
401 }
402
403 static void flush_icache(char *);
404 static void flush_range(char *, int);
405
406 /* The layout of a function descriptor.  A C function pointer really
407    points to one of these.  */
408
409 typedef struct aix_fd_struct {
410     void *code_pointer;
411     void *toc;
412 } aix_fd;
413
414 /* here I'd like to add the stack frame layout we use in darwin_closure.S
415    and aix_clsoure.S
416
417    SP previous -> +---------------------------------------+ <--- child frame
418                   | back chain to caller 4                |
419                   +---------------------------------------+ 4
420                   | saved CR 4                            |
421                   +---------------------------------------+ 8
422                   | saved LR 4                            |
423                   +---------------------------------------+ 12
424                   | reserved for compilers 4              |
425                   +---------------------------------------+ 16
426                   | reserved for binders 4                |
427                   +---------------------------------------+ 20
428                   | saved TOC pointer 4                   |
429                   +---------------------------------------+ 24
430                   | always reserved 8*4=32 (previous GPRs)|
431                   | according to the linkage convention   |
432                   | from AIX                              |
433                   +---------------------------------------+ 56
434                   | our FPR area 13*8=104                 |
435                   | f1                                    |
436                   | .                                     |
437                   | f13                                   |
438                   +---------------------------------------+ 160
439                   | result area 8                         |
440                   +---------------------------------------+ 168
441                   | alignement to the next multiple of 16 |
442 SP current -->    +---------------------------------------+ 176 <- parent frame
443                   | back chain to caller 4                |
444                   +---------------------------------------+ 180
445                   | saved CR 4                            |
446                   +---------------------------------------+ 184
447                   | saved LR 4                            |
448                   +---------------------------------------+ 188
449                   | reserved for compilers 4              |
450                   +---------------------------------------+ 192
451                   | reserved for binders 4                |
452                   +---------------------------------------+ 196
453                   | saved TOC pointer 4                   |
454                   +---------------------------------------+ 200
455                   | always reserved 8*4=32  we store our  |
456                   | GPRs here                             |
457                   | r3                                    |
458                   | .                                     |
459                   | r10                                   |
460                   +---------------------------------------+ 232
461                   | overflow part                         |
462                   +---------------------------------------+ xxx
463                   | ????                                  |
464                   +---------------------------------------+ xxx
465
466 */
467 ffi_status
468 ffi_prep_closure (ffi_closure* closure,
469                   ffi_cif* cif,
470                   void (*fun)(ffi_cif*, void*, void**, void*),
471                   void *user_data)
472 {
473   unsigned int *tramp;
474   struct ffi_aix_trampoline_struct *tramp_aix;
475   aix_fd *fd;
476
477   switch (cif->abi)
478     {
479     case FFI_DARWIN:
480
481       FFI_ASSERT (cif->abi == FFI_DARWIN);
482
483       tramp = (unsigned int *) &closure->tramp[0];
484       tramp[0] = 0x7c0802a6;  /*   mflr    r0  */
485       tramp[1] = 0x429f000d;  /*   bcl-    20,4*cr7+so,0x10  */
486       tramp[4] = 0x7d6802a6;  /*   mflr    r11  */
487       tramp[5] = 0x818b0000;  /*   lwz     r12,0(r11) function address  */
488       tramp[6] = 0x7c0803a6;  /*   mtlr    r0   */
489       tramp[7] = 0x7d8903a6;  /*   mtctr   r12  */
490       tramp[8] = 0x816b0004;  /*   lwz     r11,4(r11) static chain  */
491       tramp[9] = 0x4e800420;  /*   bctr  */
492       tramp[2] = (unsigned long) ffi_closure_ASM; /* function  */
493       tramp[3] = (unsigned long) closure; /* context  */
494
495       closure->cif = cif;
496       closure->fun = fun;
497       closure->user_data = user_data;
498
499       /* Flush the icache. Only necessary on Darwin.  */
500       flush_range(&closure->tramp[0],FFI_TRAMPOLINE_SIZE);
501
502       break;
503
504     case FFI_AIX:
505
506       tramp_aix = (struct ffi_aix_trampoline_struct *) (closure->tramp);
507       fd = (aix_fd *)(void *)ffi_closure_ASM;
508
509       FFI_ASSERT (cif->abi == FFI_AIX);
510
511       tramp_aix->code_pointer = fd->code_pointer;
512       tramp_aix->toc = fd->toc;
513       tramp_aix->static_chain = closure;
514       closure->cif = cif;
515       closure->fun = fun;
516       closure->user_data = user_data;
517
518     default:
519
520       FFI_ASSERT(0);
521       break;
522     }
523   return FFI_OK;
524 }
525
526 static void
527 flush_icache(char *addr)
528 {
529 #ifndef _AIX
530   __asm__ volatile (
531                 "dcbf 0,%0;"
532                 "sync;"
533                 "icbi 0,%0;"
534                 "sync;"
535                 "isync;"
536                 : : "r"(addr) : "memory");
537 #endif
538 }
539
540 static void
541 flush_range(char * addr1, int size)
542 {
543 #define MIN_LINE_SIZE 32
544   int i;
545   for (i = 0; i < size; i += MIN_LINE_SIZE)
546     flush_icache(addr1+i);
547   flush_icache(addr1+size-1);
548 }
549
550 typedef union
551 {
552   float f;
553   double d;
554 } ffi_dblfl;
555
556 int ffi_closure_helper_DARWIN (ffi_closure*, void*,
557                                unsigned long*, ffi_dblfl*);
558
559 /* Basically the trampoline invokes ffi_closure_ASM, and on
560    entry, r11 holds the address of the closure.
561    After storing the registers that could possibly contain
562    parameters to be passed into the stack frame and setting
563    up space for a return value, ffi_closure_ASM invokes the
564    following helper function to do most of the work.  */
565
566 int ffi_closure_helper_DARWIN (ffi_closure* closure, void * rvalue,
567                                unsigned long * pgr, ffi_dblfl * pfr)
568 {
569   /* rvalue is the pointer to space for return value in closure assembly
570      pgr is the pointer to where r3-r10 are stored in ffi_closure_ASM
571      pfr is the pointer to where f1-f13 are stored in ffi_closure_ASM.  */
572
573
574   void **          avalue;
575   ffi_type **      arg_types;
576   long             i, avn;
577   long             nf;   /* number of floating registers already used.  */
578   long             ng;   /* number of general registers already used.  */
579   ffi_cif *        cif;
580   double           temp;
581   unsigned         size_al;
582
583   cif = closure->cif;
584   avalue = alloca(cif->nargs * sizeof(void *));
585
586   nf = 0;
587   ng = 0;
588
589   /* Copy the caller's structure return value address so that the closure
590      returns the data directly to the caller.  */
591   if (cif->rtype->type == FFI_TYPE_STRUCT)
592     {
593       rvalue = (void *) *pgr;
594       pgr++;
595       ng++;
596     }
597
598   i = 0;
599   avn = cif->nargs;
600   arg_types = cif->arg_types;
601
602   /* Grab the addresses of the arguments from the stack frame.  */
603   while (i < avn)
604     {
605       switch (arg_types[i]->type)
606         {
607         case FFI_TYPE_SINT8:
608         case FFI_TYPE_UINT8:
609           avalue[i] = (char *) pgr + 3;
610           ng++;
611           pgr++;
612           break;
613
614         case FFI_TYPE_SINT16:
615         case FFI_TYPE_UINT16:
616           avalue[i] = (char *) pgr + 2;
617           ng++;
618           pgr++;
619           break;
620
621         case FFI_TYPE_SINT32:
622         case FFI_TYPE_UINT32:
623         case FFI_TYPE_POINTER:
624           avalue[i] = pgr;
625           ng++;
626           pgr++;
627           break;
628
629         case FFI_TYPE_STRUCT:
630           /* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
631              SI 4 bytes) are aligned as if they were those modes.  */
632           size_al = arg_types[i]->size;
633           /* If the first member of the struct is a double, then align
634              the struct to double-word.
635              Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3.  */
636           if (arg_types[i]->elements[0]->type == 3)
637             size_al = ALIGN(arg_types[i]->size, 8);
638           if (size_al < 3 && cif->abi == FFI_DARWIN)
639             avalue[i] = (void*) pgr + 4 - size_al;
640           else
641             avalue[i] = (void*) pgr;
642           ng += (size_al + 3) / 4;
643           pgr += (size_al + 3) / 4;
644           break;
645
646         case FFI_TYPE_SINT64:
647         case FFI_TYPE_UINT64:
648           /* Long long ints are passed in two gpr's.  */
649           avalue[i] = pgr;
650           ng += 2;
651           pgr += 2;
652           break;
653
654         case FFI_TYPE_FLOAT:
655           /* A float value consumes a GPR.
656              There are 13 64bit floating point registers.  */
657           if (nf < NUM_FPR_ARG_REGISTERS)
658             {
659               temp = pfr->d;
660               pfr->f = (float)temp;
661               avalue[i] = pfr;
662               pfr++;
663             }
664           else
665             {
666               avalue[i] = pgr;
667             }
668           nf++;
669           ng++;
670           pgr++;
671           break;
672
673         case FFI_TYPE_DOUBLE:
674           /* A double value consumes two GPRs.
675              There are 13 64bit floating point registers.  */
676           if (nf < NUM_FPR_ARG_REGISTERS)
677             {
678               avalue[i] = pfr;
679               pfr++;
680             }
681           else
682             {
683               avalue[i] = pgr;
684             }
685           nf++;
686           ng += 2;
687           pgr += 2;
688           break;
689
690         default:
691           FFI_ASSERT(0);
692         }
693       i++;
694     }
695
696   (closure->fun) (cif, rvalue, avalue, closure->user_data);
697
698   /* Tell ffi_closure_ASM to perform return type promotions.  */
699   return cif->rtype->type;
700 }