|
|
bd9b18 |
diff -urp libffi-3.0.13/src/powerpc/ffi.c libffi-current/src/powerpc/ffi.c
|
|
|
bd9b18 |
--- libffi-3.0.13/src/powerpc/ffi.c 2013-03-16 22:46:20.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/src/powerpc/ffi.c 2013-11-18 00:48:55.218044221 +1030
|
|
|
bd9b18 |
@@ -48,12 +48,8 @@ enum {
|
|
|
bd9b18 |
|
|
|
bd9b18 |
FLAG_RETURNS_128BITS = 1 << (31-27), /* cr6 */
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- FLAG_SYSV_SMST_R4 = 1 << (31-26), /* use r4 for FFI_SYSV 8 byte
|
|
|
bd9b18 |
- structs. */
|
|
|
bd9b18 |
- FLAG_SYSV_SMST_R3 = 1 << (31-25), /* use r3 for FFI_SYSV 4 byte
|
|
|
bd9b18 |
- structs. */
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
FLAG_ARG_NEEDS_COPY = 1 << (31- 7),
|
|
|
bd9b18 |
+ FLAG_ARG_NEEDS_PSAVE = FLAG_ARG_NEEDS_COPY, /* Used by ELFv2 */
|
|
|
bd9b18 |
#ifndef __NO_FPRS__
|
|
|
bd9b18 |
FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
@@ -132,6 +128,9 @@ ffi_prep_args_SYSV (extended_cif *ecif,
|
|
|
bd9b18 |
|
|
|
bd9b18 |
int i;
|
|
|
bd9b18 |
ffi_type **ptr;
|
|
|
bd9b18 |
+#ifndef __NO_FPRS__
|
|
|
bd9b18 |
+ double double_tmp;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
union {
|
|
|
bd9b18 |
void **v;
|
|
|
bd9b18 |
char **c;
|
|
|
bd9b18 |
@@ -151,7 +150,6 @@ ffi_prep_args_SYSV (extended_cif *ecif,
|
|
|
bd9b18 |
gpr_base.u = stacktop.u - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS;
|
|
|
bd9b18 |
intarg_count = 0;
|
|
|
bd9b18 |
#ifndef __NO_FPRS__
|
|
|
bd9b18 |
- double double_tmp;
|
|
|
bd9b18 |
fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS;
|
|
|
bd9b18 |
fparg_count = 0;
|
|
|
bd9b18 |
copy_space.c = ((flags & FLAG_FP_ARGUMENTS) ? fpr_base.c : gpr_base.c);
|
|
|
bd9b18 |
@@ -374,7 +372,7 @@ ffi_prep_args_SYSV (extended_cif *ecif,
|
|
|
bd9b18 |
FFI_ASSERT (gpr_base.u <= stacktop.u - ASM_NEEDS_REGISTERS);
|
|
|
bd9b18 |
/* The assert below is testing that the number of integer arguments agrees
|
|
|
bd9b18 |
with the number found in ffi_prep_cif_machdep(). However, intarg_count
|
|
|
bd9b18 |
- is incremeneted whenever we place an FP arg on the stack, so account for
|
|
|
bd9b18 |
+ is incremented whenever we place an FP arg on the stack, so account for
|
|
|
bd9b18 |
that before our assert test. */
|
|
|
bd9b18 |
#ifndef __NO_FPRS__
|
|
|
bd9b18 |
if (fparg_count > NUM_FPR_ARG_REGISTERS)
|
|
|
bd9b18 |
@@ -392,6 +390,45 @@ enum {
|
|
|
bd9b18 |
};
|
|
|
bd9b18 |
enum { ASM_NEEDS_REGISTERS64 = 4 };
|
|
|
bd9b18 |
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+static unsigned int
|
|
|
bd9b18 |
+discover_homogeneous_aggregate (const ffi_type *t, unsigned int *elnum)
|
|
|
bd9b18 |
+{
|
|
|
bd9b18 |
+ switch (t->type)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ case FFI_TYPE_FLOAT:
|
|
|
bd9b18 |
+ case FFI_TYPE_DOUBLE:
|
|
|
bd9b18 |
+ *elnum = 1;
|
|
|
bd9b18 |
+ return (int) t->type;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ case FFI_TYPE_STRUCT:;
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ unsigned int base_elt = 0, total_elnum = 0;
|
|
|
bd9b18 |
+ ffi_type **el = t->elements;
|
|
|
bd9b18 |
+ while (*el)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ unsigned int el_elt, el_elnum = 0;
|
|
|
bd9b18 |
+ el_elt = discover_homogeneous_aggregate (*el, &el_elnum);
|
|
|
bd9b18 |
+ if (el_elt == 0
|
|
|
bd9b18 |
+ || (base_elt && base_elt != el_elt))
|
|
|
bd9b18 |
+ return 0;
|
|
|
bd9b18 |
+ base_elt = el_elt;
|
|
|
bd9b18 |
+ total_elnum += el_elnum;
|
|
|
bd9b18 |
+ if (total_elnum > 8)
|
|
|
bd9b18 |
+ return 0;
|
|
|
bd9b18 |
+ el++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ *elnum = total_elnum;
|
|
|
bd9b18 |
+ return base_elt;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ default:
|
|
|
bd9b18 |
+ return 0;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+}
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
/* ffi_prep_args64 is called by the assembly routine once stack space
|
|
|
bd9b18 |
has been allocated for the function's arguments.
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -437,6 +474,7 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
unsigned long *ul;
|
|
|
bd9b18 |
float *f;
|
|
|
bd9b18 |
double *d;
|
|
|
bd9b18 |
+ size_t p;
|
|
|
bd9b18 |
} valp;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* 'stacktop' points at the previous backchain pointer. */
|
|
|
bd9b18 |
@@ -452,9 +490,9 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
/* 'fpr_base' points at the space for fpr3, and grows upwards as
|
|
|
bd9b18 |
we use FPR registers. */
|
|
|
bd9b18 |
valp fpr_base;
|
|
|
bd9b18 |
- int fparg_count;
|
|
|
bd9b18 |
+ unsigned int fparg_count;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- int i, words;
|
|
|
bd9b18 |
+ unsigned int i, words, nargs, nfixedargs;
|
|
|
bd9b18 |
ffi_type **ptr;
|
|
|
bd9b18 |
double double_tmp;
|
|
|
bd9b18 |
union {
|
|
|
bd9b18 |
@@ -471,11 +509,18 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
double **d;
|
|
|
bd9b18 |
} p_argv;
|
|
|
bd9b18 |
unsigned long gprvalue;
|
|
|
bd9b18 |
+#ifdef __STRUCT_PARM_ALIGN__
|
|
|
bd9b18 |
+ unsigned long align;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
stacktop.c = (char *) stack + bytes;
|
|
|
bd9b18 |
gpr_base.ul = stacktop.ul - ASM_NEEDS_REGISTERS64 - NUM_GPR_ARG_REGISTERS64;
|
|
|
bd9b18 |
gpr_end.ul = gpr_base.ul + NUM_GPR_ARG_REGISTERS64;
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ rest.ul = stack + 4 + NUM_GPR_ARG_REGISTERS64;
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
rest.ul = stack + 6 + NUM_GPR_ARG_REGISTERS64;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
fpr_base.d = gpr_base.d - NUM_FPR_ARG_REGISTERS64;
|
|
|
bd9b18 |
fparg_count = 0;
|
|
|
bd9b18 |
next_arg.ul = gpr_base.ul;
|
|
|
bd9b18 |
@@ -491,30 +536,36 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Now for the arguments. */
|
|
|
bd9b18 |
p_argv.v = ecif->avalue;
|
|
|
bd9b18 |
- for (ptr = ecif->cif->arg_types, i = ecif->cif->nargs;
|
|
|
bd9b18 |
- i > 0;
|
|
|
bd9b18 |
- i--, ptr++, p_argv.v++)
|
|
|
bd9b18 |
+ nargs = ecif->cif->nargs;
|
|
|
bd9b18 |
+ nfixedargs = ecif->cif->nfixedargs;
|
|
|
bd9b18 |
+ for (ptr = ecif->cif->arg_types, i = 0;
|
|
|
bd9b18 |
+ i < nargs;
|
|
|
bd9b18 |
+ i++, ptr++, p_argv.v++)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
+ unsigned int elt, elnum;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
switch ((*ptr)->type)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
case FFI_TYPE_FLOAT:
|
|
|
bd9b18 |
double_tmp = **p_argv.f;
|
|
|
bd9b18 |
- *next_arg.f = (float) double_tmp;
|
|
|
bd9b18 |
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
|
|
|
bd9b18 |
+ *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *next_arg.f = (float) double_tmp;
|
|
|
bd9b18 |
if (++next_arg.ul == gpr_end.ul)
|
|
|
bd9b18 |
next_arg.ul = rest.ul;
|
|
|
bd9b18 |
- if (fparg_count < NUM_FPR_ARG_REGISTERS64)
|
|
|
bd9b18 |
- *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
fparg_count++;
|
|
|
bd9b18 |
FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_DOUBLE:
|
|
|
bd9b18 |
double_tmp = **p_argv.d;
|
|
|
bd9b18 |
- *next_arg.d = double_tmp;
|
|
|
bd9b18 |
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
|
|
|
bd9b18 |
+ *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *next_arg.d = double_tmp;
|
|
|
bd9b18 |
if (++next_arg.ul == gpr_end.ul)
|
|
|
bd9b18 |
next_arg.ul = rest.ul;
|
|
|
bd9b18 |
- if (fparg_count < NUM_FPR_ARG_REGISTERS64)
|
|
|
bd9b18 |
- *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
fparg_count++;
|
|
|
bd9b18 |
FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
@@ -522,18 +573,20 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
|
|
bd9b18 |
case FFI_TYPE_LONGDOUBLE:
|
|
|
bd9b18 |
double_tmp = (*p_argv.d)[0];
|
|
|
bd9b18 |
- *next_arg.d = double_tmp;
|
|
|
bd9b18 |
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
|
|
|
bd9b18 |
+ *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *next_arg.d = double_tmp;
|
|
|
bd9b18 |
if (++next_arg.ul == gpr_end.ul)
|
|
|
bd9b18 |
next_arg.ul = rest.ul;
|
|
|
bd9b18 |
- if (fparg_count < NUM_FPR_ARG_REGISTERS64)
|
|
|
bd9b18 |
- *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
fparg_count++;
|
|
|
bd9b18 |
double_tmp = (*p_argv.d)[1];
|
|
|
bd9b18 |
- *next_arg.d = double_tmp;
|
|
|
bd9b18 |
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
|
|
|
bd9b18 |
+ *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *next_arg.d = double_tmp;
|
|
|
bd9b18 |
if (++next_arg.ul == gpr_end.ul)
|
|
|
bd9b18 |
next_arg.ul = rest.ul;
|
|
|
bd9b18 |
- if (fparg_count < NUM_FPR_ARG_REGISTERS64)
|
|
|
bd9b18 |
- *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
fparg_count++;
|
|
|
bd9b18 |
FFI_ASSERT (__LDBL_MANT_DIG__ == 106);
|
|
|
bd9b18 |
FFI_ASSERT (flags & FLAG_FP_ARGUMENTS);
|
|
|
bd9b18 |
@@ -541,27 +594,86 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_STRUCT:
|
|
|
bd9b18 |
- words = ((*ptr)->size + 7) / 8;
|
|
|
bd9b18 |
- if (next_arg.ul >= gpr_base.ul && next_arg.ul + words > gpr_end.ul)
|
|
|
bd9b18 |
- {
|
|
|
bd9b18 |
- size_t first = gpr_end.c - next_arg.c;
|
|
|
bd9b18 |
- memcpy (next_arg.c, *p_argv.c, first);
|
|
|
bd9b18 |
- memcpy (rest.c, *p_argv.c + first, (*ptr)->size - first);
|
|
|
bd9b18 |
- next_arg.c = rest.c + words * 8 - first;
|
|
|
bd9b18 |
+#ifdef __STRUCT_PARM_ALIGN__
|
|
|
bd9b18 |
+ align = (*ptr)->alignment;
|
|
|
bd9b18 |
+ if (align > __STRUCT_PARM_ALIGN__)
|
|
|
bd9b18 |
+ align = __STRUCT_PARM_ALIGN__;
|
|
|
bd9b18 |
+ if (align > 1)
|
|
|
bd9b18 |
+ next_arg.p = ALIGN (next_arg.p, align);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ elt = 0;
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ elt = discover_homogeneous_aggregate (*ptr, &elnum);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ if (elt)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ union {
|
|
|
bd9b18 |
+ void *v;
|
|
|
bd9b18 |
+ float *f;
|
|
|
bd9b18 |
+ double *d;
|
|
|
bd9b18 |
+ } arg;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ arg.v = *p_argv.v;
|
|
|
bd9b18 |
+ if (elt == FFI_TYPE_FLOAT)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ do
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ double_tmp = *arg.f++;
|
|
|
bd9b18 |
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64
|
|
|
bd9b18 |
+ && i < nfixedargs)
|
|
|
bd9b18 |
+ *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *next_arg.f = (float) double_tmp;
|
|
|
bd9b18 |
+ if (++next_arg.f == gpr_end.f)
|
|
|
bd9b18 |
+ next_arg.f = rest.f;
|
|
|
bd9b18 |
+ fparg_count++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ while (--elnum != 0);
|
|
|
bd9b18 |
+ if ((next_arg.p & 3) != 0)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if (++next_arg.f == gpr_end.f)
|
|
|
bd9b18 |
+ next_arg.f = rest.f;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ do
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ double_tmp = *arg.d++;
|
|
|
bd9b18 |
+ if (fparg_count < NUM_FPR_ARG_REGISTERS64 && i < nfixedargs)
|
|
|
bd9b18 |
+ *fpr_base.d++ = double_tmp;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *next_arg.d = double_tmp;
|
|
|
bd9b18 |
+ if (++next_arg.d == gpr_end.d)
|
|
|
bd9b18 |
+ next_arg.d = rest.d;
|
|
|
bd9b18 |
+ fparg_count++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ while (--elnum != 0);
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
else
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
- char *where = next_arg.c;
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
- /* Structures with size less than eight bytes are passed
|
|
|
bd9b18 |
- left-padded. */
|
|
|
bd9b18 |
- if ((*ptr)->size < 8)
|
|
|
bd9b18 |
- where += 8 - (*ptr)->size;
|
|
|
bd9b18 |
+ words = ((*ptr)->size + 7) / 8;
|
|
|
bd9b18 |
+ if (next_arg.ul >= gpr_base.ul && next_arg.ul + words > gpr_end.ul)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ size_t first = gpr_end.c - next_arg.c;
|
|
|
bd9b18 |
+ memcpy (next_arg.c, *p_argv.c, first);
|
|
|
bd9b18 |
+ memcpy (rest.c, *p_argv.c + first, (*ptr)->size - first);
|
|
|
bd9b18 |
+ next_arg.c = rest.c + words * 8 - first;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ char *where = next_arg.c;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- memcpy (where, *p_argv.c, (*ptr)->size);
|
|
|
bd9b18 |
- next_arg.ul += words;
|
|
|
bd9b18 |
- if (next_arg.ul == gpr_end.ul)
|
|
|
bd9b18 |
- next_arg.ul = rest.ul;
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ /* Structures with size less than eight bytes are passed
|
|
|
bd9b18 |
+ left-padded. */
|
|
|
bd9b18 |
+ if ((*ptr)->size < 8)
|
|
|
bd9b18 |
+ where += 8 - (*ptr)->size;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ memcpy (where, *p_argv.c, (*ptr)->size);
|
|
|
bd9b18 |
+ next_arg.ul += words;
|
|
|
bd9b18 |
+ if (next_arg.ul == gpr_end.ul)
|
|
|
bd9b18 |
+ next_arg.ul = rest.ul;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -605,24 +717,22 @@ ffi_prep_args64 (extended_cif *ecif, uns
|
|
|
bd9b18 |
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Perform machine dependent cif processing */
|
|
|
bd9b18 |
-ffi_status
|
|
|
bd9b18 |
-ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
+static ffi_status
|
|
|
bd9b18 |
+ffi_prep_cif_machdep_core (ffi_cif *cif)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
/* All this is for the SYSV and LINUX64 ABI. */
|
|
|
bd9b18 |
- int i;
|
|
|
bd9b18 |
ffi_type **ptr;
|
|
|
bd9b18 |
unsigned bytes;
|
|
|
bd9b18 |
- int fparg_count = 0, intarg_count = 0;
|
|
|
bd9b18 |
- unsigned flags = 0;
|
|
|
bd9b18 |
+ unsigned i, fparg_count = 0, intarg_count = 0;
|
|
|
bd9b18 |
+ unsigned flags = cif->flags;
|
|
|
bd9b18 |
unsigned struct_copy_size = 0;
|
|
|
bd9b18 |
unsigned type = cif->rtype->type;
|
|
|
bd9b18 |
unsigned size = cif->rtype->size;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
+ /* The machine-independent calculation of cif->bytes doesn't work
|
|
|
bd9b18 |
+ for us. Redo the calculation. */
|
|
|
bd9b18 |
if (cif->abi != FFI_LINUX64)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
- /* All the machine-independent calculation of cif->bytes will be wrong.
|
|
|
bd9b18 |
- Redo the calculation for SYSV. */
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
/* Space for the frame pointer, callee's LR, and the asm's temp regs. */
|
|
|
bd9b18 |
bytes = (2 + ASM_NEEDS_REGISTERS) * sizeof (int);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -632,13 +742,20 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
else
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
/* 64-bit ABI. */
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ /* Space for backchain, CR, LR, TOC and the asm's temp regs. */
|
|
|
bd9b18 |
+ bytes = (4 + ASM_NEEDS_REGISTERS64) * sizeof (long);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
+ /* Space for the general registers. */
|
|
|
bd9b18 |
+ bytes += NUM_GPR_ARG_REGISTERS64 * sizeof (long);
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
/* Space for backchain, CR, LR, cc/ld doubleword, TOC and the asm's temp
|
|
|
bd9b18 |
regs. */
|
|
|
bd9b18 |
bytes = (6 + ASM_NEEDS_REGISTERS64) * sizeof (long);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Space for the mandatory parm save area and general registers. */
|
|
|
bd9b18 |
bytes += 2 * NUM_GPR_ARG_REGISTERS64 * sizeof (long);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Return value handling. The rules for SYSV are as follows:
|
|
|
bd9b18 |
@@ -658,19 +775,23 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
- soft-float float/doubles are treated as UINT32/UINT64 respectivley.
|
|
|
bd9b18 |
- soft-float long doubles are returned in gpr3-gpr6. */
|
|
|
bd9b18 |
/* First translate for softfloat/nonlinux */
|
|
|
bd9b18 |
- if (cif->abi == FFI_LINUX_SOFT_FLOAT) {
|
|
|
bd9b18 |
- if (type == FFI_TYPE_FLOAT)
|
|
|
bd9b18 |
- type = FFI_TYPE_UINT32;
|
|
|
bd9b18 |
- if (type == FFI_TYPE_DOUBLE)
|
|
|
bd9b18 |
- type = FFI_TYPE_UINT64;
|
|
|
bd9b18 |
- if (type == FFI_TYPE_LONGDOUBLE)
|
|
|
bd9b18 |
- type = FFI_TYPE_UINT128;
|
|
|
bd9b18 |
- } else if (cif->abi != FFI_LINUX && cif->abi != FFI_LINUX64) {
|
|
|
bd9b18 |
+ if (cif->abi == FFI_LINUX_SOFT_FLOAT)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if (type == FFI_TYPE_FLOAT)
|
|
|
bd9b18 |
+ type = FFI_TYPE_UINT32;
|
|
|
bd9b18 |
+ if (type == FFI_TYPE_DOUBLE)
|
|
|
bd9b18 |
+ type = FFI_TYPE_UINT64;
|
|
|
bd9b18 |
+ if (type == FFI_TYPE_LONGDOUBLE)
|
|
|
bd9b18 |
+ type = FFI_TYPE_UINT128;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else if (cif->abi != FFI_LINUX
|
|
|
bd9b18 |
+ && cif->abi != FFI_LINUX64)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
|
|
bd9b18 |
- if (type == FFI_TYPE_LONGDOUBLE)
|
|
|
bd9b18 |
- type = FFI_TYPE_STRUCT;
|
|
|
bd9b18 |
+ if (type == FFI_TYPE_LONGDOUBLE)
|
|
|
bd9b18 |
+ type = FFI_TYPE_STRUCT;
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
- }
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
|
|
|
bd9b18 |
switch (type)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
@@ -697,35 +818,40 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_STRUCT:
|
|
|
bd9b18 |
- if (cif->abi == FFI_SYSV)
|
|
|
bd9b18 |
+ /*
|
|
|
bd9b18 |
+ * The final SYSV ABI says that structures smaller or equal 8 bytes
|
|
|
bd9b18 |
+ * are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
|
|
|
bd9b18 |
+ * in memory.
|
|
|
bd9b18 |
+ *
|
|
|
bd9b18 |
+ * NOTE: The assembly code can safely assume that it just needs to
|
|
|
bd9b18 |
+ * store both r3 and r4 into a 8-byte word-aligned buffer, as
|
|
|
bd9b18 |
+ * we allocate a temporary buffer in ffi_call() if this flag is
|
|
|
bd9b18 |
+ * set.
|
|
|
bd9b18 |
+ */
|
|
|
bd9b18 |
+ if (cif->abi == FFI_SYSV && size <= 8)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
- /* The final SYSV ABI says that structures smaller or equal 8 bytes
|
|
|
bd9b18 |
- are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
|
|
|
bd9b18 |
- in memory. */
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
- /* Treat structs with size <= 8 bytes. */
|
|
|
bd9b18 |
- if (size <= 8)
|
|
|
bd9b18 |
+ flags |= FLAG_RETURNS_SMST;
|
|
|
bd9b18 |
+ break;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ if (cif->abi == FFI_LINUX64)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ unsigned int elt, elnum;
|
|
|
bd9b18 |
+ elt = discover_homogeneous_aggregate (cif->rtype, &elnum);
|
|
|
bd9b18 |
+ if (elt)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if (elt == FFI_TYPE_DOUBLE)
|
|
|
bd9b18 |
+ flags |= FLAG_RETURNS_64BITS;
|
|
|
bd9b18 |
+ flags |= FLAG_RETURNS_FP | FLAG_RETURNS_SMST;
|
|
|
bd9b18 |
+ break;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ if (size <= 16)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
flags |= FLAG_RETURNS_SMST;
|
|
|
bd9b18 |
- /* These structs are returned in r3. We pack the type and the
|
|
|
bd9b18 |
- precalculated shift value (needed in the sysv.S) into flags.
|
|
|
bd9b18 |
- The same applies for the structs returned in r3/r4. */
|
|
|
bd9b18 |
- if (size <= 4)
|
|
|
bd9b18 |
- {
|
|
|
bd9b18 |
- flags |= FLAG_SYSV_SMST_R3;
|
|
|
bd9b18 |
- flags |= 8 * (4 - size) << 8;
|
|
|
bd9b18 |
- break;
|
|
|
bd9b18 |
- }
|
|
|
bd9b18 |
- /* These structs are returned in r3 and r4. See above. */
|
|
|
bd9b18 |
- if (size <= 8)
|
|
|
bd9b18 |
- {
|
|
|
bd9b18 |
- flags |= FLAG_SYSV_SMST_R3 | FLAG_SYSV_SMST_R4;
|
|
|
bd9b18 |
- flags |= 8 * (8 - size) << 8;
|
|
|
bd9b18 |
- break;
|
|
|
bd9b18 |
- }
|
|
|
bd9b18 |
+ break;
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
intarg_count++;
|
|
|
bd9b18 |
flags |= FLAG_RETVAL_REFERENCE;
|
|
|
bd9b18 |
/* Fall through. */
|
|
|
bd9b18 |
@@ -841,27 +967,54 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
else
|
|
|
bd9b18 |
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
+ unsigned int elt, elnum;
|
|
|
bd9b18 |
+#ifdef __STRUCT_PARM_ALIGN__
|
|
|
bd9b18 |
+ unsigned int align;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
switch ((*ptr)->type)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
|
|
bd9b18 |
case FFI_TYPE_LONGDOUBLE:
|
|
|
bd9b18 |
- if (cif->abi == FFI_LINUX_SOFT_FLOAT)
|
|
|
bd9b18 |
- intarg_count += 4;
|
|
|
bd9b18 |
- else
|
|
|
bd9b18 |
- {
|
|
|
bd9b18 |
- fparg_count += 2;
|
|
|
bd9b18 |
- intarg_count += 2;
|
|
|
bd9b18 |
- }
|
|
|
bd9b18 |
+ fparg_count += 2;
|
|
|
bd9b18 |
+ intarg_count += 2;
|
|
|
bd9b18 |
+ if (fparg_count > NUM_FPR_ARG_REGISTERS)
|
|
|
bd9b18 |
+ flags |= FLAG_ARG_NEEDS_PSAVE;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
case FFI_TYPE_FLOAT:
|
|
|
bd9b18 |
case FFI_TYPE_DOUBLE:
|
|
|
bd9b18 |
fparg_count++;
|
|
|
bd9b18 |
intarg_count++;
|
|
|
bd9b18 |
+ if (fparg_count > NUM_FPR_ARG_REGISTERS)
|
|
|
bd9b18 |
+ flags |= FLAG_ARG_NEEDS_PSAVE;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_STRUCT:
|
|
|
bd9b18 |
+#ifdef __STRUCT_PARM_ALIGN__
|
|
|
bd9b18 |
+ align = (*ptr)->alignment;
|
|
|
bd9b18 |
+ if (align > __STRUCT_PARM_ALIGN__)
|
|
|
bd9b18 |
+ align = __STRUCT_PARM_ALIGN__;
|
|
|
bd9b18 |
+ align = align / 8;
|
|
|
bd9b18 |
+ if (align > 1)
|
|
|
bd9b18 |
+ intarg_count = ALIGN (intarg_count, align);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
intarg_count += ((*ptr)->size + 7) / 8;
|
|
|
bd9b18 |
+ elt = 0;
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ elt = discover_homogeneous_aggregate (*ptr, &elnum);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ if (elt)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ fparg_count += elnum;
|
|
|
bd9b18 |
+ if (fparg_count > NUM_FPR_ARG_REGISTERS)
|
|
|
bd9b18 |
+ flags |= FLAG_ARG_NEEDS_PSAVE;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if (intarg_count > NUM_GPR_ARG_REGISTERS)
|
|
|
bd9b18 |
+ flags |= FLAG_ARG_NEEDS_PSAVE;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_POINTER:
|
|
|
bd9b18 |
@@ -877,9 +1030,11 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
/* Everything else is passed as a 8-byte word in a GPR, either
|
|
|
bd9b18 |
the object itself or a pointer to it. */
|
|
|
bd9b18 |
intarg_count++;
|
|
|
bd9b18 |
+ if (intarg_count > NUM_GPR_ARG_REGISTERS)
|
|
|
bd9b18 |
+ flags |= FLAG_ARG_NEEDS_PSAVE;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
default:
|
|
|
bd9b18 |
- FFI_ASSERT (0);
|
|
|
bd9b18 |
+ FFI_ASSERT (0);
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -917,8 +1072,13 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Stack space. */
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ if ((flags & FLAG_ARG_NEEDS_PSAVE) != 0)
|
|
|
bd9b18 |
+ bytes += intarg_count * sizeof (long);
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
if (intarg_count > NUM_GPR_ARG_REGISTERS64)
|
|
|
bd9b18 |
bytes += (intarg_count - NUM_GPR_ARG_REGISTERS64) * sizeof (long);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* The stack space allocated needs to be a multiple of 16 bytes. */
|
|
|
bd9b18 |
@@ -933,6 +1093,26 @@ ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
return FFI_OK;
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
|
|
|
bd9b18 |
+ffi_status
|
|
|
bd9b18 |
+ffi_prep_cif_machdep (ffi_cif *cif)
|
|
|
bd9b18 |
+{
|
|
|
bd9b18 |
+ cif->nfixedargs = cif->nargs;
|
|
|
bd9b18 |
+ return ffi_prep_cif_machdep_core (cif);
|
|
|
bd9b18 |
+}
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ffi_status
|
|
|
bd9b18 |
+ffi_prep_cif_machdep_var (ffi_cif *cif,
|
|
|
bd9b18 |
+ unsigned int nfixedargs,
|
|
|
bd9b18 |
+ unsigned int ntotalargs MAYBE_UNUSED)
|
|
|
bd9b18 |
+{
|
|
|
bd9b18 |
+ cif->nfixedargs = nfixedargs;
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ if (cif->abi == FFI_LINUX64)
|
|
|
bd9b18 |
+ cif->flags |= FLAG_ARG_NEEDS_PSAVE;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ return ffi_prep_cif_machdep_core (cif);
|
|
|
bd9b18 |
+}
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
extern void ffi_call_SYSV(extended_cif *, unsigned, unsigned, unsigned *,
|
|
|
bd9b18 |
void (*fn)(void));
|
|
|
bd9b18 |
extern void FFI_HIDDEN ffi_call_LINUX64(extended_cif *, unsigned long,
|
|
|
bd9b18 |
@@ -944,30 +1124,28 @@ ffi_call(ffi_cif *cif, void (*fn)(void),
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
/*
|
|
|
bd9b18 |
* The final SYSV ABI says that structures smaller or equal 8 bytes
|
|
|
bd9b18 |
- * are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
|
|
|
bd9b18 |
+ * are returned in r3/r4. The FFI_GCC_SYSV ABI instead returns them
|
|
|
bd9b18 |
* in memory.
|
|
|
bd9b18 |
*
|
|
|
bd9b18 |
- * Just to keep things simple for the assembly code, we will always
|
|
|
bd9b18 |
- * bounce-buffer struct return values less than or equal to 8 bytes.
|
|
|
bd9b18 |
- * This allows the ASM to handle SYSV small structures by directly
|
|
|
bd9b18 |
- * writing r3 and r4 to memory without worrying about struct size.
|
|
|
bd9b18 |
+ * We bounce-buffer SYSV small struct return values so that sysv.S
|
|
|
bd9b18 |
+ * can write r3 and r4 to memory without worrying about struct size.
|
|
|
bd9b18 |
+ *
|
|
|
bd9b18 |
+ * For ELFv2 ABI, use a bounce buffer for homogeneous structs too,
|
|
|
bd9b18 |
+ * for similar reasons.
|
|
|
bd9b18 |
*/
|
|
|
bd9b18 |
- unsigned int smst_buffer[2];
|
|
|
bd9b18 |
+ unsigned long smst_buffer[8];
|
|
|
bd9b18 |
extended_cif ecif;
|
|
|
bd9b18 |
- unsigned int rsize = 0;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
ecif.cif = cif;
|
|
|
bd9b18 |
ecif.avalue = avalue;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- /* Ensure that we have a valid struct return value */
|
|
|
bd9b18 |
ecif.rvalue = rvalue;
|
|
|
bd9b18 |
- if (cif->rtype->type == FFI_TYPE_STRUCT) {
|
|
|
bd9b18 |
- rsize = cif->rtype->size;
|
|
|
bd9b18 |
- if (rsize <= 8)
|
|
|
bd9b18 |
- ecif.rvalue = smst_buffer;
|
|
|
bd9b18 |
- else if (!rvalue)
|
|
|
bd9b18 |
- ecif.rvalue = alloca(rsize);
|
|
|
bd9b18 |
- }
|
|
|
bd9b18 |
+ if ((cif->flags & FLAG_RETURNS_SMST) != 0)
|
|
|
bd9b18 |
+ ecif.rvalue = smst_buffer;
|
|
|
bd9b18 |
+ /* Ensure that we have a valid struct return value.
|
|
|
bd9b18 |
+ FIXME: Isn't this just papering over a user problem? */
|
|
|
bd9b18 |
+ else if (!rvalue && cif->rtype->type == FFI_TYPE_STRUCT)
|
|
|
bd9b18 |
+ ecif.rvalue = alloca (cif->rtype->size);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
switch (cif->abi)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
@@ -992,11 +1170,26 @@ ffi_call(ffi_cif *cif, void (*fn)(void),
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Check for a bounce-buffered return value */
|
|
|
bd9b18 |
if (rvalue && ecif.rvalue == smst_buffer)
|
|
|
bd9b18 |
- memcpy(rvalue, smst_buffer, rsize);
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ unsigned int rsize = cif->rtype->size;
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ /* The SYSV ABI returns a structure of up to 4 bytes in size
|
|
|
bd9b18 |
+ left-padded in r3. */
|
|
|
bd9b18 |
+ if (cif->abi == FFI_SYSV && rsize <= 4)
|
|
|
bd9b18 |
+ memcpy (rvalue, (char *) smst_buffer + 4 - rsize, rsize);
|
|
|
bd9b18 |
+ /* The SYSV ABI returns a structure of up to 8 bytes in size
|
|
|
bd9b18 |
+ left-padded in r3/r4, and the ELFv2 ABI similarly returns a
|
|
|
bd9b18 |
+ structure of up to 8 bytes in size left-padded in r3. */
|
|
|
bd9b18 |
+ else if (rsize <= 8)
|
|
|
bd9b18 |
+ memcpy (rvalue, (char *) smst_buffer + 8 - rsize, rsize);
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ memcpy (rvalue, smst_buffer, rsize);
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
|
|
|
bd9b18 |
|
|
|
bd9b18 |
-#ifndef POWERPC64
|
|
|
bd9b18 |
+#if !defined POWERPC64 || _CALL_ELF == 2
|
|
|
bd9b18 |
#define MIN_CACHE_LINE_SIZE 8
|
|
|
bd9b18 |
|
|
|
bd9b18 |
static void
|
|
|
bd9b18 |
@@ -1020,6 +1213,22 @@ ffi_prep_closure_loc (ffi_closure *closu
|
|
|
bd9b18 |
void *codeloc)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
#ifdef POWERPC64
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ unsigned int *tramp = (unsigned int *) &closure->tramp[0];
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ if (cif->abi != FFI_LINUX64)
|
|
|
bd9b18 |
+ return FFI_BAD_ABI;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ tramp[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
|
|
|
bd9b18 |
+ tramp[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
|
|
|
bd9b18 |
+ tramp[2] = 0x7d8903a6; /* mtctr 12 */
|
|
|
bd9b18 |
+ tramp[3] = 0x4e800420; /* bctr */
|
|
|
bd9b18 |
+ /* 1: .quad function_addr */
|
|
|
bd9b18 |
+ /* 2: .quad context */
|
|
|
bd9b18 |
+ *(void **) &tramp[4] = (void *) ffi_closure_LINUX64;
|
|
|
bd9b18 |
+ *(void **) &tramp[6] = codeloc;
|
|
|
bd9b18 |
+ flush_icache ((char *)tramp, (char *)codeloc, FFI_TRAMPOLINE_SIZE);
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
void **tramp = (void **) &closure->tramp[0];
|
|
|
bd9b18 |
|
|
|
bd9b18 |
if (cif->abi != FFI_LINUX64)
|
|
|
bd9b18 |
@@ -1027,6 +1236,7 @@ ffi_prep_closure_loc (ffi_closure *closu
|
|
|
bd9b18 |
/* Copy function address and TOC from ffi_closure_LINUX64. */
|
|
|
bd9b18 |
memcpy (tramp, (char *) ffi_closure_LINUX64, 16);
|
|
|
bd9b18 |
tramp[2] = codeloc;
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
#else
|
|
|
bd9b18 |
unsigned int *tramp;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -1236,6 +1446,7 @@ ffi_closure_helper_SYSV (ffi_closure *cl
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_SINT8:
|
|
|
bd9b18 |
case FFI_TYPE_UINT8:
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
/* there are 8 gpr registers used to pass values */
|
|
|
bd9b18 |
if (ng < 8)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
@@ -1249,9 +1460,11 @@ ffi_closure_helper_SYSV (ffi_closure *cl
|
|
|
bd9b18 |
pst++;
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_SINT16:
|
|
|
bd9b18 |
case FFI_TYPE_UINT16:
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
/* there are 8 gpr registers used to pass values */
|
|
|
bd9b18 |
if (ng < 8)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
@@ -1265,6 +1478,7 @@ ffi_closure_helper_SYSV (ffi_closure *cl
|
|
|
bd9b18 |
pst++;
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_SINT32:
|
|
|
bd9b18 |
case FFI_TYPE_UINT32:
|
|
|
bd9b18 |
@@ -1369,16 +1583,20 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
|
|
|
bd9b18 |
void **avalue;
|
|
|
bd9b18 |
ffi_type **arg_types;
|
|
|
bd9b18 |
- long i, avn;
|
|
|
bd9b18 |
+ unsigned long i, avn, nfixedargs;
|
|
|
bd9b18 |
ffi_cif *cif;
|
|
|
bd9b18 |
ffi_dblfl *end_pfr = pfr + NUM_FPR_ARG_REGISTERS64;
|
|
|
bd9b18 |
+#ifdef __STRUCT_PARM_ALIGN__
|
|
|
bd9b18 |
+ unsigned long align;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
cif = closure->cif;
|
|
|
bd9b18 |
avalue = alloca (cif->nargs * sizeof (void *));
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- /* Copy the caller's structure return value address so that the closure
|
|
|
bd9b18 |
- returns the data directly to the caller. */
|
|
|
bd9b18 |
- if (cif->rtype->type == FFI_TYPE_STRUCT)
|
|
|
bd9b18 |
+ /* Copy the caller's structure return value address so that the
|
|
|
bd9b18 |
+ closure returns the data directly to the caller. */
|
|
|
bd9b18 |
+ if (cif->rtype->type == FFI_TYPE_STRUCT
|
|
|
bd9b18 |
+ && (cif->flags & FLAG_RETURNS_SMST) == 0)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
rvalue = (void *) *pst;
|
|
|
bd9b18 |
pst++;
|
|
|
bd9b18 |
@@ -1386,30 +1604,39 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
|
|
|
bd9b18 |
i = 0;
|
|
|
bd9b18 |
avn = cif->nargs;
|
|
|
bd9b18 |
+ nfixedargs = cif->nfixedargs;
|
|
|
bd9b18 |
arg_types = cif->arg_types;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Grab the addresses of the arguments from the stack frame. */
|
|
|
bd9b18 |
while (i < avn)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
+ unsigned int elt, elnum;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
switch (arg_types[i]->type)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
case FFI_TYPE_SINT8:
|
|
|
bd9b18 |
case FFI_TYPE_UINT8:
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
avalue[i] = (char *) pst + 7;
|
|
|
bd9b18 |
pst++;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_SINT16:
|
|
|
bd9b18 |
case FFI_TYPE_UINT16:
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
avalue[i] = (char *) pst + 6;
|
|
|
bd9b18 |
pst++;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_SINT32:
|
|
|
bd9b18 |
case FFI_TYPE_UINT32:
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
avalue[i] = (char *) pst + 4;
|
|
|
bd9b18 |
pst++;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_SINT64:
|
|
|
bd9b18 |
case FFI_TYPE_UINT64:
|
|
|
bd9b18 |
@@ -1419,12 +1646,82 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
case FFI_TYPE_STRUCT:
|
|
|
bd9b18 |
- /* Structures with size less than eight bytes are passed
|
|
|
bd9b18 |
- left-padded. */
|
|
|
bd9b18 |
- if (arg_types[i]->size < 8)
|
|
|
bd9b18 |
- avalue[i] = (char *) pst + 8 - arg_types[i]->size;
|
|
|
bd9b18 |
+#ifdef __STRUCT_PARM_ALIGN__
|
|
|
bd9b18 |
+ align = arg_types[i]->alignment;
|
|
|
bd9b18 |
+ if (align > __STRUCT_PARM_ALIGN__)
|
|
|
bd9b18 |
+ align = __STRUCT_PARM_ALIGN__;
|
|
|
bd9b18 |
+ if (align > 1)
|
|
|
bd9b18 |
+ pst = (unsigned long *) ALIGN ((size_t) pst, align);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ elt = 0;
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+ elt = discover_homogeneous_aggregate (arg_types[i], &elnum);
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ if (elt)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ union {
|
|
|
bd9b18 |
+ void *v;
|
|
|
bd9b18 |
+ unsigned long *ul;
|
|
|
bd9b18 |
+ float *f;
|
|
|
bd9b18 |
+ double *d;
|
|
|
bd9b18 |
+ size_t p;
|
|
|
bd9b18 |
+ } to, from;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ /* Repackage the aggregate from its parts. The
|
|
|
bd9b18 |
+ aggregate size is not greater than the space taken by
|
|
|
bd9b18 |
+ the registers so store back to the register/parameter
|
|
|
bd9b18 |
+ save arrays. */
|
|
|
bd9b18 |
+ if (pfr + elnum <= end_pfr)
|
|
|
bd9b18 |
+ to.v = pfr;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ to.v = pst;
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ avalue[i] = to.v;
|
|
|
bd9b18 |
+ from.ul = pst;
|
|
|
bd9b18 |
+ if (elt == FFI_TYPE_FLOAT)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ do
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if (pfr < end_pfr && i < nfixedargs)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ *to.f = (float) pfr->d;
|
|
|
bd9b18 |
+ pfr++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *to.f = *from.f;
|
|
|
bd9b18 |
+ to.f++;
|
|
|
bd9b18 |
+ from.f++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ while (--elnum != 0);
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ do
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if (pfr < end_pfr && i < nfixedargs)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ *to.d = pfr->d;
|
|
|
bd9b18 |
+ pfr++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ *to.d = *from.d;
|
|
|
bd9b18 |
+ to.d++;
|
|
|
bd9b18 |
+ from.d++;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ while (--elnum != 0);
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
else
|
|
|
bd9b18 |
- avalue[i] = pst;
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ /* Structures with size less than eight bytes are passed
|
|
|
bd9b18 |
+ left-padded. */
|
|
|
bd9b18 |
+ if (arg_types[i]->size < 8)
|
|
|
bd9b18 |
+ avalue[i] = (char *) pst + 8 - arg_types[i]->size;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
+ avalue[i] = pst;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
pst += (arg_types[i]->size + 7) / 8;
|
|
|
bd9b18 |
break;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -1436,7 +1733,7 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* there are 13 64bit floating point registers */
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- if (pfr < end_pfr)
|
|
|
bd9b18 |
+ if (pfr < end_pfr && i < nfixedargs)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
double temp = pfr->d;
|
|
|
bd9b18 |
pfr->f = (float) temp;
|
|
|
bd9b18 |
@@ -1452,7 +1749,7 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
/* On the outgoing stack all values are aligned to 8 */
|
|
|
bd9b18 |
/* there are 13 64bit floating point registers */
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- if (pfr < end_pfr)
|
|
|
bd9b18 |
+ if (pfr < end_pfr && i < nfixedargs)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
avalue[i] = pfr;
|
|
|
bd9b18 |
pfr++;
|
|
|
bd9b18 |
@@ -1464,14 +1761,14 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
|
|
|
bd9b18 |
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
|
|
bd9b18 |
case FFI_TYPE_LONGDOUBLE:
|
|
|
bd9b18 |
- if (pfr + 1 < end_pfr)
|
|
|
bd9b18 |
+ if (pfr + 1 < end_pfr && i + 1 < nfixedargs)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
avalue[i] = pfr;
|
|
|
bd9b18 |
pfr += 2;
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
else
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
- if (pfr < end_pfr)
|
|
|
bd9b18 |
+ if (pfr < end_pfr && i < nfixedargs)
|
|
|
bd9b18 |
{
|
|
|
bd9b18 |
/* Passed partly in f13 and partly on the stack.
|
|
|
bd9b18 |
Move it all to the stack. */
|
|
|
bd9b18 |
@@ -1495,5 +1792,14 @@ ffi_closure_helper_LINUX64 (ffi_closure
|
|
|
bd9b18 |
(closure->fun) (cif, rvalue, avalue, closure->user_data);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Tell ffi_closure_LINUX64 how to perform return type promotions. */
|
|
|
bd9b18 |
+ if ((cif->flags & FLAG_RETURNS_SMST) != 0)
|
|
|
bd9b18 |
+ {
|
|
|
bd9b18 |
+ if ((cif->flags & FLAG_RETURNS_FP) == 0)
|
|
|
bd9b18 |
+ return FFI_V2_TYPE_SMALL_STRUCT + cif->rtype->size - 1;
|
|
|
bd9b18 |
+ else if ((cif->flags & FLAG_RETURNS_64BITS) != 0)
|
|
|
bd9b18 |
+ return FFI_V2_TYPE_DOUBLE_HOMOG;
|
|
|
bd9b18 |
+ else
|
|
|
bd9b18 |
+ return FFI_V2_TYPE_FLOAT_HOMOG;
|
|
|
bd9b18 |
+ }
|
|
|
bd9b18 |
return cif->rtype->type;
|
|
|
bd9b18 |
}
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/src/powerpc/ffitarget.h libffi-current/src/powerpc/ffitarget.h
|
|
|
bd9b18 |
--- libffi-3.0.13/src/powerpc/ffitarget.h 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/src/powerpc/ffitarget.h 2013-11-17 09:07:45.433681274 +1030
|
|
|
bd9b18 |
@@ -106,6 +106,10 @@ typedef enum ffi_abi {
|
|
|
bd9b18 |
|
|
|
bd9b18 |
#define FFI_CLOSURES 1
|
|
|
bd9b18 |
#define FFI_NATIVE_RAW_API 0
|
|
|
bd9b18 |
+#if defined (POWERPC) || defined (POWERPC_FREEBSD)
|
|
|
bd9b18 |
+# define FFI_TARGET_SPECIFIC_VARIADIC 1
|
|
|
bd9b18 |
+# define FFI_EXTRA_CIF_FIELDS unsigned nfixedargs
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* For additional types like the below, take care about the order in
|
|
|
bd9b18 |
ppc_closures.S. They must follow after the FFI_TYPE_LAST. */
|
|
|
bd9b18 |
@@ -118,14 +122,23 @@ typedef enum ffi_abi {
|
|
|
bd9b18 |
defined in ffi.c, to determine the exact return type and its size. */
|
|
|
bd9b18 |
#define FFI_SYSV_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 2)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
-#if defined(POWERPC64) || defined(POWERPC_AIX)
|
|
|
bd9b18 |
+/* Used by ELFv2 for homogenous structure returns. */
|
|
|
bd9b18 |
+#define FFI_V2_TYPE_FLOAT_HOMOG (FFI_TYPE_LAST + 1)
|
|
|
bd9b18 |
+#define FFI_V2_TYPE_DOUBLE_HOMOG (FFI_TYPE_LAST + 2)
|
|
|
bd9b18 |
+#define FFI_V2_TYPE_SMALL_STRUCT (FFI_TYPE_LAST + 3)
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+#if _CALL_ELF == 2
|
|
|
bd9b18 |
+# define FFI_TRAMPOLINE_SIZE 32
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
+# if defined(POWERPC64) || defined(POWERPC_AIX)
|
|
|
bd9b18 |
# if defined(POWERPC_DARWIN64)
|
|
|
bd9b18 |
# define FFI_TRAMPOLINE_SIZE 48
|
|
|
bd9b18 |
# else
|
|
|
bd9b18 |
# define FFI_TRAMPOLINE_SIZE 24
|
|
|
bd9b18 |
# endif
|
|
|
bd9b18 |
-#else /* POWERPC || POWERPC_AIX */
|
|
|
bd9b18 |
+# else /* POWERPC || POWERPC_AIX */
|
|
|
bd9b18 |
# define FFI_TRAMPOLINE_SIZE 40
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
#ifndef LIBFFI_ASM
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/src/powerpc/linux64_closure.S libffi-current/src/powerpc/linux64_closure.S
|
|
|
bd9b18 |
--- libffi-3.0.13/src/powerpc/linux64_closure.S 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/src/powerpc/linux64_closure.S 2013-11-17 09:11:54.267742403 +1030
|
|
|
bd9b18 |
@@ -33,15 +33,22 @@
|
|
|
bd9b18 |
#ifdef __powerpc64__
|
|
|
bd9b18 |
FFI_HIDDEN (ffi_closure_LINUX64)
|
|
|
bd9b18 |
.globl ffi_closure_LINUX64
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ .text
|
|
|
bd9b18 |
+ffi_closure_LINUX64:
|
|
|
bd9b18 |
+ addis %r2, %r12, .TOC.-ffi_closure_LINUX64@ha
|
|
|
bd9b18 |
+ addi %r2, %r2, .TOC.-ffi_closure_LINUX64@l
|
|
|
bd9b18 |
+ .localentry ffi_closure_LINUX64, . - ffi_closure_LINUX64
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
.section ".opd","aw"
|
|
|
bd9b18 |
.align 3
|
|
|
bd9b18 |
ffi_closure_LINUX64:
|
|
|
bd9b18 |
-#ifdef _CALL_LINUX
|
|
|
bd9b18 |
+# ifdef _CALL_LINUX
|
|
|
bd9b18 |
.quad .L.ffi_closure_LINUX64,.TOC.@tocbase,0
|
|
|
bd9b18 |
.type ffi_closure_LINUX64,@function
|
|
|
bd9b18 |
.text
|
|
|
bd9b18 |
.L.ffi_closure_LINUX64:
|
|
|
bd9b18 |
-#else
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
FFI_HIDDEN (.ffi_closure_LINUX64)
|
|
|
bd9b18 |
.globl .ffi_closure_LINUX64
|
|
|
bd9b18 |
.quad .ffi_closure_LINUX64,.TOC.@tocbase,0
|
|
|
bd9b18 |
@@ -49,61 +56,103 @@ ffi_closure_LINUX64:
|
|
|
bd9b18 |
.type .ffi_closure_LINUX64,@function
|
|
|
bd9b18 |
.text
|
|
|
bd9b18 |
.ffi_closure_LINUX64:
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+# 32 byte special reg save area + 64 byte parm save area and retval
|
|
|
bd9b18 |
+# + 13*8 fpr save area + round to 16
|
|
|
bd9b18 |
+# define STACKFRAME 208
|
|
|
bd9b18 |
+# define PARMSAVE 32
|
|
|
bd9b18 |
+# No parameter save area is needed for the call to ffi_closure_helper_LINUX64,
|
|
|
bd9b18 |
+# so return value can start there.
|
|
|
bd9b18 |
+# define RETVAL PARMSAVE
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+# 48 bytes special reg save area + 64 bytes parm save area
|
|
|
bd9b18 |
+# + 16 bytes retval area + 13*8 bytes fpr save area + round to 16
|
|
|
bd9b18 |
+# define STACKFRAME 240
|
|
|
bd9b18 |
+# define PARMSAVE 48
|
|
|
bd9b18 |
+# define RETVAL PARMSAVE+64
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
.LFB1:
|
|
|
bd9b18 |
- # save general regs into parm save area
|
|
|
bd9b18 |
- std %r3, 48(%r1)
|
|
|
bd9b18 |
- std %r4, 56(%r1)
|
|
|
bd9b18 |
- std %r5, 64(%r1)
|
|
|
bd9b18 |
- std %r6, 72(%r1)
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ ld %r12, FFI_TRAMPOLINE_SIZE(%r11) # closure->cif
|
|
|
bd9b18 |
+ mflr %r0
|
|
|
bd9b18 |
+ lwz %r12, 28(%r12) # cif->flags
|
|
|
bd9b18 |
+ mtcrf 0x40, %r12
|
|
|
bd9b18 |
+ addi %r12, %r1, PARMSAVE
|
|
|
bd9b18 |
+ bt 7, .Lparmsave
|
|
|
bd9b18 |
+ # Our caller has not allocated a parameter save area.
|
|
|
bd9b18 |
+ # We need to allocate one here and use it to pass gprs to
|
|
|
bd9b18 |
+ # ffi_closure_helper_LINUX64. The return value area will do.
|
|
|
bd9b18 |
+ addi %r12, %r1, -STACKFRAME+RETVAL
|
|
|
bd9b18 |
+.Lparmsave:
|
|
|
bd9b18 |
+ std %r0, 16(%r1)
|
|
|
bd9b18 |
+ # Save general regs into parm save area
|
|
|
bd9b18 |
+ std %r3, 0(%r12)
|
|
|
bd9b18 |
+ std %r4, 8(%r12)
|
|
|
bd9b18 |
+ std %r5, 16(%r12)
|
|
|
bd9b18 |
+ std %r6, 24(%r12)
|
|
|
bd9b18 |
+ std %r7, 32(%r12)
|
|
|
bd9b18 |
+ std %r8, 40(%r12)
|
|
|
bd9b18 |
+ std %r9, 48(%r12)
|
|
|
bd9b18 |
+ std %r10, 56(%r12)
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+ # load up the pointer to the parm save area
|
|
|
bd9b18 |
+ mr %r5, %r12
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
mflr %r0
|
|
|
bd9b18 |
+ # Save general regs into parm save area
|
|
|
bd9b18 |
+ # This is the parameter save area set up by our caller.
|
|
|
bd9b18 |
+ std %r3, PARMSAVE+0(%r1)
|
|
|
bd9b18 |
+ std %r4, PARMSAVE+8(%r1)
|
|
|
bd9b18 |
+ std %r5, PARMSAVE+16(%r1)
|
|
|
bd9b18 |
+ std %r6, PARMSAVE+24(%r1)
|
|
|
bd9b18 |
+ std %r7, PARMSAVE+32(%r1)
|
|
|
bd9b18 |
+ std %r8, PARMSAVE+40(%r1)
|
|
|
bd9b18 |
+ std %r9, PARMSAVE+48(%r1)
|
|
|
bd9b18 |
+ std %r10, PARMSAVE+56(%r1)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- std %r7, 80(%r1)
|
|
|
bd9b18 |
- std %r8, 88(%r1)
|
|
|
bd9b18 |
- std %r9, 96(%r1)
|
|
|
bd9b18 |
- std %r10, 104(%r1)
|
|
|
bd9b18 |
std %r0, 16(%r1)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- # mandatory 48 bytes special reg save area + 64 bytes parm save area
|
|
|
bd9b18 |
- # + 16 bytes retval area + 13*8 bytes fpr save area + round to 16
|
|
|
bd9b18 |
- stdu %r1, -240(%r1)
|
|
|
bd9b18 |
-.LCFI0:
|
|
|
bd9b18 |
+ # load up the pointer to the parm save area
|
|
|
bd9b18 |
+ addi %r5, %r1, PARMSAVE
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# next save fpr 1 to fpr 13
|
|
|
bd9b18 |
- stfd %f1, 128+(0*8)(%r1)
|
|
|
bd9b18 |
- stfd %f2, 128+(1*8)(%r1)
|
|
|
bd9b18 |
- stfd %f3, 128+(2*8)(%r1)
|
|
|
bd9b18 |
- stfd %f4, 128+(3*8)(%r1)
|
|
|
bd9b18 |
- stfd %f5, 128+(4*8)(%r1)
|
|
|
bd9b18 |
- stfd %f6, 128+(5*8)(%r1)
|
|
|
bd9b18 |
- stfd %f7, 128+(6*8)(%r1)
|
|
|
bd9b18 |
- stfd %f8, 128+(7*8)(%r1)
|
|
|
bd9b18 |
- stfd %f9, 128+(8*8)(%r1)
|
|
|
bd9b18 |
- stfd %f10, 128+(9*8)(%r1)
|
|
|
bd9b18 |
- stfd %f11, 128+(10*8)(%r1)
|
|
|
bd9b18 |
- stfd %f12, 128+(11*8)(%r1)
|
|
|
bd9b18 |
- stfd %f13, 128+(12*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f1, -104+(0*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f2, -104+(1*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f3, -104+(2*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f4, -104+(3*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f5, -104+(4*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f6, -104+(5*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f7, -104+(6*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f8, -104+(7*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f9, -104+(8*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f10, -104+(9*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f11, -104+(10*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f12, -104+(11*8)(%r1)
|
|
|
bd9b18 |
+ stfd %f13, -104+(12*8)(%r1)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- # set up registers for the routine that actually does the work
|
|
|
bd9b18 |
- # get the context pointer from the trampoline
|
|
|
bd9b18 |
- mr %r3, %r11
|
|
|
bd9b18 |
+ # load up the pointer to the saved fpr registers */
|
|
|
bd9b18 |
+ addi %r6, %r1, -104
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- # now load up the pointer to the result storage
|
|
|
bd9b18 |
- addi %r4, %r1, 112
|
|
|
bd9b18 |
+ # load up the pointer to the result storage
|
|
|
bd9b18 |
+ addi %r4, %r1, -STACKFRAME+RETVAL
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- # now load up the pointer to the parameter save area
|
|
|
bd9b18 |
- # in the previous frame
|
|
|
bd9b18 |
- addi %r5, %r1, 240 + 48
|
|
|
bd9b18 |
+ stdu %r1, -STACKFRAME(%r1)
|
|
|
bd9b18 |
+.LCFI0:
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- # now load up the pointer to the saved fpr registers */
|
|
|
bd9b18 |
- addi %r6, %r1, 128
|
|
|
bd9b18 |
+ # get the context pointer from the trampoline
|
|
|
bd9b18 |
+ mr %r3, %r11
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# make the call
|
|
|
bd9b18 |
-#ifdef _CALL_LINUX
|
|
|
bd9b18 |
+# if defined _CALL_LINUX || _CALL_ELF == 2
|
|
|
bd9b18 |
bl ffi_closure_helper_LINUX64
|
|
|
bd9b18 |
-#else
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
bl .ffi_closure_helper_LINUX64
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
.Lret:
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# now r3 contains the return type
|
|
|
bd9b18 |
@@ -112,10 +161,12 @@ ffi_closure_LINUX64:
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# look up the proper starting point in table
|
|
|
bd9b18 |
# by using return type as offset
|
|
|
bd9b18 |
+ ld %r0, STACKFRAME+16(%r1)
|
|
|
bd9b18 |
+ cmpldi %r3, FFI_V2_TYPE_SMALL_STRUCT
|
|
|
bd9b18 |
+ bge .Lsmall
|
|
|
bd9b18 |
mflr %r4 # move address of .Lret to r4
|
|
|
bd9b18 |
sldi %r3, %r3, 4 # now multiply return type by 16
|
|
|
bd9b18 |
addi %r4, %r4, .Lret_type0 - .Lret
|
|
|
bd9b18 |
- ld %r0, 240+16(%r1)
|
|
|
bd9b18 |
add %r3, %r3, %r4 # add contents of table to table address
|
|
|
bd9b18 |
mtctr %r3
|
|
|
bd9b18 |
bctr # jump to it
|
|
|
bd9b18 |
@@ -128,89 +179,175 @@ ffi_closure_LINUX64:
|
|
|
bd9b18 |
.Lret_type0:
|
|
|
bd9b18 |
# case FFI_TYPE_VOID
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
nop
|
|
|
bd9b18 |
# case FFI_TYPE_INT
|
|
|
bd9b18 |
- lwa %r3, 112+4(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lwa %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lwa %r3, RETVAL+4(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_FLOAT
|
|
|
bd9b18 |
- lfs %f1, 112+0(%r1)
|
|
|
bd9b18 |
+ lfs %f1, RETVAL+0(%r1)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_DOUBLE
|
|
|
bd9b18 |
- lfd %f1, 112+0(%r1)
|
|
|
bd9b18 |
+ lfd %f1, RETVAL+0(%r1)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_LONGDOUBLE
|
|
|
bd9b18 |
- lfd %f1, 112+0(%r1)
|
|
|
bd9b18 |
+ lfd %f1, RETVAL+0(%r1)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- lfd %f2, 112+8(%r1)
|
|
|
bd9b18 |
+ lfd %f2, RETVAL+8(%r1)
|
|
|
bd9b18 |
b .Lfinish
|
|
|
bd9b18 |
# case FFI_TYPE_UINT8
|
|
|
bd9b18 |
- lbz %r3, 112+7(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lbz %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lbz %r3, RETVAL+7(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_SINT8
|
|
|
bd9b18 |
- lbz %r3, 112+7(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lbz %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lbz %r3, RETVAL+7(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
extsb %r3,%r3
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
b .Lfinish
|
|
|
bd9b18 |
# case FFI_TYPE_UINT16
|
|
|
bd9b18 |
- lhz %r3, 112+6(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lhz %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lhz %r3, RETVAL+6(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
.Lfinish:
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_SINT16
|
|
|
bd9b18 |
- lha %r3, 112+6(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lha %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lha %r3, RETVAL+6(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_UINT32
|
|
|
bd9b18 |
- lwz %r3, 112+4(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lwz %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lwz %r3, RETVAL+4(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_SINT32
|
|
|
bd9b18 |
- lwa %r3, 112+4(%r1)
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lwa %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ lwa %r3, RETVAL+4(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_UINT64
|
|
|
bd9b18 |
- ld %r3, 112+0(%r1)
|
|
|
bd9b18 |
+ ld %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_SINT64
|
|
|
bd9b18 |
- ld %r3, 112+0(%r1)
|
|
|
bd9b18 |
+ ld %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
# case FFI_TYPE_STRUCT
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
nop
|
|
|
bd9b18 |
# case FFI_TYPE_POINTER
|
|
|
bd9b18 |
- ld %r3, 112+0(%r1)
|
|
|
bd9b18 |
+ ld %r3, RETVAL+0(%r1)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
- addi %r1, %r1, 240
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
-# esac
|
|
|
bd9b18 |
+# case FFI_V2_TYPE_FLOAT_HOMOG
|
|
|
bd9b18 |
+ lfs %f1, RETVAL+0(%r1)
|
|
|
bd9b18 |
+ lfs %f2, RETVAL+4(%r1)
|
|
|
bd9b18 |
+ lfs %f3, RETVAL+8(%r1)
|
|
|
bd9b18 |
+ b .Lmorefloat
|
|
|
bd9b18 |
+# case FFI_V2_TYPE_DOUBLE_HOMOG
|
|
|
bd9b18 |
+ lfd %f1, RETVAL+0(%r1)
|
|
|
bd9b18 |
+ lfd %f2, RETVAL+8(%r1)
|
|
|
bd9b18 |
+ lfd %f3, RETVAL+16(%r1)
|
|
|
bd9b18 |
+ lfd %f4, RETVAL+24(%r1)
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ lfd %f5, RETVAL+32(%r1)
|
|
|
bd9b18 |
+ lfd %f6, RETVAL+40(%r1)
|
|
|
bd9b18 |
+ lfd %f7, RETVAL+48(%r1)
|
|
|
bd9b18 |
+ lfd %f8, RETVAL+56(%r1)
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
+ blr
|
|
|
bd9b18 |
+.Lmorefloat:
|
|
|
bd9b18 |
+ lfs %f4, RETVAL+12(%r1)
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ lfs %f5, RETVAL+16(%r1)
|
|
|
bd9b18 |
+ lfs %f6, RETVAL+20(%r1)
|
|
|
bd9b18 |
+ lfs %f7, RETVAL+24(%r1)
|
|
|
bd9b18 |
+ lfs %f8, RETVAL+28(%r1)
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
+ blr
|
|
|
bd9b18 |
+.Lsmall:
|
|
|
bd9b18 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ ld %r3,RETVAL+0(%r1)
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ ld %r4,RETVAL+8(%r1)
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
+ blr
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ # A struct smaller than a dword is returned in the low bits of r3
|
|
|
bd9b18 |
+ # ie. right justified. Larger structs are passed left justified
|
|
|
bd9b18 |
+ # in r3 and r4. The return value area on the stack will have
|
|
|
bd9b18 |
+ # the structs as they are usually stored in memory.
|
|
|
bd9b18 |
+ cmpldi %r3, FFI_V2_TYPE_SMALL_STRUCT + 7 # size 8 bytes?
|
|
|
bd9b18 |
+ neg %r5, %r3
|
|
|
bd9b18 |
+ ld %r3,RETVAL+0(%r1)
|
|
|
bd9b18 |
+ blt .Lsmalldown
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ ld %r4,RETVAL+8(%r1)
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
+ blr
|
|
|
bd9b18 |
+.Lsmalldown:
|
|
|
bd9b18 |
+ addi %r5, %r5, FFI_V2_TYPE_SMALL_STRUCT + 7
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ sldi %r5, %r5, 3
|
|
|
bd9b18 |
+ addi %r1, %r1, STACKFRAME
|
|
|
bd9b18 |
+ srd %r3, %r3, %r5
|
|
|
bd9b18 |
+ blr
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
.LFE1:
|
|
|
bd9b18 |
.long 0
|
|
|
bd9b18 |
.byte 0,12,0,1,128,0,0,0
|
|
|
bd9b18 |
-#ifdef _CALL_LINUX
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ .size ffi_closure_LINUX64,.-ffi_closure_LINUX64
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+# ifdef _CALL_LINUX
|
|
|
bd9b18 |
.size ffi_closure_LINUX64,.-.L.ffi_closure_LINUX64
|
|
|
bd9b18 |
-#else
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
.size .ffi_closure_LINUX64,.-.ffi_closure_LINUX64
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
.section .eh_frame,EH_FRAME_FLAGS,@progbits
|
|
|
bd9b18 |
.Lframe1:
|
|
|
bd9b18 |
@@ -239,14 +376,14 @@ ffi_closure_LINUX64:
|
|
|
bd9b18 |
.byte 0x2 # DW_CFA_advance_loc1
|
|
|
bd9b18 |
.byte .LCFI0-.LFB1
|
|
|
bd9b18 |
.byte 0xe # DW_CFA_def_cfa_offset
|
|
|
bd9b18 |
- .uleb128 240
|
|
|
bd9b18 |
+ .uleb128 STACKFRAME
|
|
|
bd9b18 |
.byte 0x11 # DW_CFA_offset_extended_sf
|
|
|
bd9b18 |
.uleb128 0x41
|
|
|
bd9b18 |
.sleb128 -2
|
|
|
bd9b18 |
.align 3
|
|
|
bd9b18 |
.LEFDE1:
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
-#if defined __ELF__ && defined __linux__
|
|
|
bd9b18 |
+# if defined __ELF__ && defined __linux__
|
|
|
bd9b18 |
.section .note.GNU-stack,"",@progbits
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/src/powerpc/linux64.S libffi-current/src/powerpc/linux64.S
|
|
|
bd9b18 |
--- libffi-3.0.13/src/powerpc/linux64.S 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/src/powerpc/linux64.S 2013-11-17 09:09:09.742314090 +1030
|
|
|
bd9b18 |
@@ -32,15 +32,22 @@
|
|
|
bd9b18 |
#ifdef __powerpc64__
|
|
|
bd9b18 |
.hidden ffi_call_LINUX64
|
|
|
bd9b18 |
.globl ffi_call_LINUX64
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ .text
|
|
|
bd9b18 |
+ffi_call_LINUX64:
|
|
|
bd9b18 |
+ addis %r2, %r12, .TOC.-ffi_call_LINUX64@ha
|
|
|
bd9b18 |
+ addi %r2, %r2, .TOC.-ffi_call_LINUX64@l
|
|
|
bd9b18 |
+ .localentry ffi_call_LINUX64, . - ffi_call_LINUX64
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
.section ".opd","aw"
|
|
|
bd9b18 |
.align 3
|
|
|
bd9b18 |
ffi_call_LINUX64:
|
|
|
bd9b18 |
-#ifdef _CALL_LINUX
|
|
|
bd9b18 |
+# ifdef _CALL_LINUX
|
|
|
bd9b18 |
.quad .L.ffi_call_LINUX64,.TOC.@tocbase,0
|
|
|
bd9b18 |
.type ffi_call_LINUX64,@function
|
|
|
bd9b18 |
.text
|
|
|
bd9b18 |
.L.ffi_call_LINUX64:
|
|
|
bd9b18 |
-#else
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
.hidden .ffi_call_LINUX64
|
|
|
bd9b18 |
.globl .ffi_call_LINUX64
|
|
|
bd9b18 |
.quad .ffi_call_LINUX64,.TOC.@tocbase,0
|
|
|
bd9b18 |
@@ -48,7 +55,8 @@ ffi_call_LINUX64:
|
|
|
bd9b18 |
.type .ffi_call_LINUX64,@function
|
|
|
bd9b18 |
.text
|
|
|
bd9b18 |
.ffi_call_LINUX64:
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
.LFB1:
|
|
|
bd9b18 |
mflr %r0
|
|
|
bd9b18 |
std %r28, -32(%r1)
|
|
|
bd9b18 |
@@ -63,26 +71,35 @@ ffi_call_LINUX64:
|
|
|
bd9b18 |
mr %r31, %r5 /* flags, */
|
|
|
bd9b18 |
mr %r30, %r6 /* rvalue, */
|
|
|
bd9b18 |
mr %r29, %r7 /* function address. */
|
|
|
bd9b18 |
+/* Save toc pointer, not for the ffi_prep_args64 call, but for the later
|
|
|
bd9b18 |
+ bctrl function call. */
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ std %r2, 24(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
std %r2, 40(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Call ffi_prep_args64. */
|
|
|
bd9b18 |
mr %r4, %r1
|
|
|
bd9b18 |
-#ifdef _CALL_LINUX
|
|
|
bd9b18 |
+# if defined _CALL_LINUX || _CALL_ELF == 2
|
|
|
bd9b18 |
bl ffi_prep_args64
|
|
|
bd9b18 |
-#else
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
bl .ffi_prep_args64
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- ld %r0, 0(%r29)
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ mr %r12, %r29
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+ ld %r12, 0(%r29)
|
|
|
bd9b18 |
ld %r2, 8(%r29)
|
|
|
bd9b18 |
ld %r11, 16(%r29)
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
/* Now do the call. */
|
|
|
bd9b18 |
/* Set up cr1 with bits 4-7 of the flags. */
|
|
|
bd9b18 |
mtcrf 0x40, %r31
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Get the address to call into CTR. */
|
|
|
bd9b18 |
- mtctr %r0
|
|
|
bd9b18 |
+ mtctr %r12
|
|
|
bd9b18 |
/* Load all those argument registers. */
|
|
|
bd9b18 |
ld %r3, -32-(8*8)(%r28)
|
|
|
bd9b18 |
ld %r4, -32-(7*8)(%r28)
|
|
|
bd9b18 |
@@ -117,12 +134,17 @@ ffi_call_LINUX64:
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* This must follow the call immediately, the unwinder
|
|
|
bd9b18 |
uses this to find out if r2 has been saved or not. */
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ ld %r2, 24(%r1)
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
ld %r2, 40(%r1)
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Now, deal with the return value. */
|
|
|
bd9b18 |
mtcrf 0x01, %r31
|
|
|
bd9b18 |
- bt- 30, .Ldone_return_value
|
|
|
bd9b18 |
- bt- 29, .Lfp_return_value
|
|
|
bd9b18 |
+ bt 31, .Lstruct_return_value
|
|
|
bd9b18 |
+ bt 30, .Ldone_return_value
|
|
|
bd9b18 |
+ bt 29, .Lfp_return_value
|
|
|
bd9b18 |
std %r3, 0(%r30)
|
|
|
bd9b18 |
/* Fall through... */
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -130,7 +152,7 @@ ffi_call_LINUX64:
|
|
|
bd9b18 |
/* Restore the registers we used and return. */
|
|
|
bd9b18 |
mr %r1, %r28
|
|
|
bd9b18 |
ld %r0, 16(%r28)
|
|
|
bd9b18 |
- ld %r28, -32(%r1)
|
|
|
bd9b18 |
+ ld %r28, -32(%r28)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
ld %r29, -24(%r1)
|
|
|
bd9b18 |
ld %r30, -16(%r1)
|
|
|
bd9b18 |
@@ -147,14 +169,48 @@ ffi_call_LINUX64:
|
|
|
bd9b18 |
.Lfloat_return_value:
|
|
|
bd9b18 |
stfs %f1, 0(%r30)
|
|
|
bd9b18 |
b .Ldone_return_value
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+.Lstruct_return_value:
|
|
|
bd9b18 |
+ bf 29, .Lsmall_struct
|
|
|
bd9b18 |
+ bf 28, .Lfloat_homog_return_value
|
|
|
bd9b18 |
+ stfd %f1, 0(%r30)
|
|
|
bd9b18 |
+ stfd %f2, 8(%r30)
|
|
|
bd9b18 |
+ stfd %f3, 16(%r30)
|
|
|
bd9b18 |
+ stfd %f4, 24(%r30)
|
|
|
bd9b18 |
+ stfd %f5, 32(%r30)
|
|
|
bd9b18 |
+ stfd %f6, 40(%r30)
|
|
|
bd9b18 |
+ stfd %f7, 48(%r30)
|
|
|
bd9b18 |
+ stfd %f8, 56(%r30)
|
|
|
bd9b18 |
+ b .Ldone_return_value
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+.Lfloat_homog_return_value:
|
|
|
bd9b18 |
+ stfs %f1, 0(%r30)
|
|
|
bd9b18 |
+ stfs %f2, 4(%r30)
|
|
|
bd9b18 |
+ stfs %f3, 8(%r30)
|
|
|
bd9b18 |
+ stfs %f4, 12(%r30)
|
|
|
bd9b18 |
+ stfs %f5, 16(%r30)
|
|
|
bd9b18 |
+ stfs %f6, 20(%r30)
|
|
|
bd9b18 |
+ stfs %f7, 24(%r30)
|
|
|
bd9b18 |
+ stfs %f8, 28(%r30)
|
|
|
bd9b18 |
+ b .Ldone_return_value
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
+.Lsmall_struct:
|
|
|
bd9b18 |
+ std %r3, 0(%r30)
|
|
|
bd9b18 |
+ std %r4, 8(%r30)
|
|
|
bd9b18 |
+ b .Ldone_return_value
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
.LFE1:
|
|
|
bd9b18 |
.long 0
|
|
|
bd9b18 |
.byte 0,12,0,1,128,4,0,0
|
|
|
bd9b18 |
-#ifdef _CALL_LINUX
|
|
|
bd9b18 |
+# if _CALL_ELF == 2
|
|
|
bd9b18 |
+ .size ffi_call_LINUX64,.-ffi_call_LINUX64
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
+# ifdef _CALL_LINUX
|
|
|
bd9b18 |
.size ffi_call_LINUX64,.-.L.ffi_call_LINUX64
|
|
|
bd9b18 |
-#else
|
|
|
bd9b18 |
+# else
|
|
|
bd9b18 |
.size .ffi_call_LINUX64,.-.ffi_call_LINUX64
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
.section .eh_frame,EH_FRAME_FLAGS,@progbits
|
|
|
bd9b18 |
.Lframe1:
|
|
|
bd9b18 |
@@ -197,8 +253,8 @@ ffi_call_LINUX64:
|
|
|
bd9b18 |
.uleb128 0x4
|
|
|
bd9b18 |
.align 3
|
|
|
bd9b18 |
.LEFDE1:
|
|
|
bd9b18 |
-#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
-#if defined __ELF__ && defined __linux__
|
|
|
bd9b18 |
+# if (defined __ELF__ && defined __linux__) || _CALL_ELF == 2
|
|
|
bd9b18 |
.section .note.GNU-stack,"",@progbits
|
|
|
bd9b18 |
+# endif
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/src/powerpc/ppc_closure.S libffi-current/src/powerpc/ppc_closure.S
|
|
|
bd9b18 |
--- libffi-3.0.13/src/powerpc/ppc_closure.S 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/src/powerpc/ppc_closure.S 2013-11-17 13:06:22.569393369 +1030
|
|
|
bd9b18 |
@@ -159,25 +159,41 @@ ENTRY(ffi_closure_SYSV)
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_TYPE_UINT8
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lbz %r3,112+0(%r1)
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
lbz %r3,112+3(%r1)
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
addi %r1,%r1,144
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_TYPE_SINT8
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lbz %r3,112+0(%r1)
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
lbz %r3,112+3(%r1)
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
extsb %r3,%r3
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
b .Lfinish
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_TYPE_UINT16
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lhz %r3,112+0(%r1)
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
lhz %r3,112+2(%r1)
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
addi %r1,%r1,144
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_TYPE_SINT16
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ lha %r3,112+0(%r1)
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
lha %r3,112+2(%r1)
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
addi %r1,%r1,144
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
@@ -222,7 +238,7 @@ ENTRY(ffi_closure_SYSV)
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
lwz %r4,112+4(%r1)
|
|
|
bd9b18 |
lwz %r5,112+8(%r1)
|
|
|
bd9b18 |
- bl .Luint128
|
|
|
bd9b18 |
+ b .Luint128
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# The return types below are only used when the ABI type is FFI_SYSV.
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 1. One byte struct.
|
|
|
bd9b18 |
@@ -239,9 +255,15 @@ ENTRY(ffi_closure_SYSV)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 3. Three byte struct.
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ addi %r1,%r1,144
|
|
|
bd9b18 |
+ blr
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
srwi %r3,%r3,8
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
b .Lfinish
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 4. Four byte struct.
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
@@ -252,20 +274,35 @@ ENTRY(ffi_closure_SYSV)
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 5. Five byte struct.
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
lwz %r4,112+4(%r1)
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ b .Lfinish
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
li %r5,24
|
|
|
bd9b18 |
b .Lstruct567
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 6. Six byte struct.
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
lwz %r4,112+4(%r1)
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ b .Lfinish
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
li %r5,16
|
|
|
bd9b18 |
b .Lstruct567
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 7. Seven byte struct.
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
lwz %r4,112+4(%r1)
|
|
|
bd9b18 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
+ mtlr %r0
|
|
|
bd9b18 |
+ b .Lfinish
|
|
|
bd9b18 |
+#else
|
|
|
bd9b18 |
li %r5,8
|
|
|
bd9b18 |
b .Lstruct567
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
# case FFI_SYSV_TYPE_SMALL_STRUCT + 8. Eight byte struct.
|
|
|
bd9b18 |
lwz %r3,112+0(%r1)
|
|
|
bd9b18 |
@@ -273,6 +310,7 @@ ENTRY(ffi_closure_SYSV)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
b .Lfinish
|
|
|
bd9b18 |
|
|
|
bd9b18 |
+#ifndef __LITTLE_ENDIAN__
|
|
|
bd9b18 |
.Lstruct567:
|
|
|
bd9b18 |
subfic %r6,%r5,32
|
|
|
bd9b18 |
srw %r4,%r4,%r5
|
|
|
bd9b18 |
@@ -282,6 +320,7 @@ ENTRY(ffi_closure_SYSV)
|
|
|
bd9b18 |
mtlr %r0
|
|
|
bd9b18 |
addi %r1,%r1,144
|
|
|
bd9b18 |
blr
|
|
|
bd9b18 |
+#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
.Luint128:
|
|
|
bd9b18 |
lwz %r6,112+12(%r1)
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/src/powerpc/sysv.S libffi-current/src/powerpc/sysv.S
|
|
|
bd9b18 |
--- libffi-3.0.13/src/powerpc/sysv.S 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/src/powerpc/sysv.S 2013-11-13 22:36:35.222994628 +1030
|
|
|
bd9b18 |
@@ -142,19 +142,14 @@ L(float_return_value):
|
|
|
bd9b18 |
#endif
|
|
|
bd9b18 |
|
|
|
bd9b18 |
L(small_struct_return_value):
|
|
|
bd9b18 |
- extrwi %r6,%r31,2,19 /* number of bytes padding = shift/8 */
|
|
|
bd9b18 |
- mtcrf 0x02,%r31 /* copy flags to cr[24:27] (cr6) */
|
|
|
bd9b18 |
- extrwi %r5,%r31,5,19 /* r5 <- number of bits of padding */
|
|
|
bd9b18 |
- subfic %r6,%r6,4 /* r6 <- number of useful bytes in r3 */
|
|
|
bd9b18 |
- bf- 25,L(done_return_value) /* struct in r3 ? if not, done. */
|
|
|
bd9b18 |
-/* smst_one_register: */
|
|
|
bd9b18 |
- slw %r3,%r3,%r5 /* Left-justify value in r3 */
|
|
|
bd9b18 |
- mtxer %r6 /* move byte count to XER ... */
|
|
|
bd9b18 |
- stswx %r3,0,%r30 /* ... and store that many bytes */
|
|
|
bd9b18 |
- bf+ 26,L(done_return_value) /* struct in r3:r4 ? */
|
|
|
bd9b18 |
- add %r6,%r6,%r30 /* adjust pointer */
|
|
|
bd9b18 |
- stswi %r4,%r6,4 /* store last four bytes */
|
|
|
bd9b18 |
- b L(done_return_value)
|
|
|
bd9b18 |
+ /*
|
|
|
bd9b18 |
+ * The C code always allocates a properly-aligned 8-byte bounce
|
|
|
bd9b18 |
+ * buffer to make this assembly code very simple. Just write out
|
|
|
bd9b18 |
+ * r3 and r4 to the buffer to allow the C code to handle the rest.
|
|
|
bd9b18 |
+ */
|
|
|
bd9b18 |
+ stw %r3, 0(%r30)
|
|
|
bd9b18 |
+ stw %r4, 4(%r30)
|
|
|
bd9b18 |
+ b L(done_return_value)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
.LFE1:
|
|
|
bd9b18 |
END(ffi_call_SYSV)
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/testsuite/libffi.call/cls_double_va.c libffi-current/testsuite/libffi.call/cls_double_va.c
|
|
|
bd9b18 |
--- libffi-3.0.13/testsuite/libffi.call/cls_double_va.c 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/testsuite/libffi.call/cls_double_va.c 2013-11-13 22:37:13.437459229 +1030
|
|
|
bd9b18 |
@@ -38,7 +38,7 @@ int main (void)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* This printf call is variadic */
|
|
|
bd9b18 |
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint,
|
|
|
bd9b18 |
- arg_types) == FFI_OK);
|
|
|
bd9b18 |
+ arg_types) == FFI_OK);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
args[0] = &format;
|
|
|
bd9b18 |
args[1] = &doubleArg;
|
|
|
bd9b18 |
@@ -49,12 +49,10 @@ int main (void)
|
|
|
bd9b18 |
printf("res: %d\n", (int) res);
|
|
|
bd9b18 |
/* { dg-output "\nres: 4" } */
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- /* The call to cls_double_va_fn is static, so have to use a normal prep_cif */
|
|
|
bd9b18 |
- CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint, arg_types) == FFI_OK);
|
|
|
bd9b18 |
+ CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL,
|
|
|
bd9b18 |
+ code) == FFI_OK);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK);
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
- res = ((int(*)(char*, double))(code))(format, doubleArg);
|
|
|
bd9b18 |
+ res = ((int(*)(char*, ...))(code))(format, doubleArg);
|
|
|
bd9b18 |
/* { dg-output "\n7.0" } */
|
|
|
bd9b18 |
printf("res: %d\n", (int) res);
|
|
|
bd9b18 |
/* { dg-output "\nres: 4" } */
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/testsuite/libffi.call/cls_longdouble_va.c libffi-current/testsuite/libffi.call/cls_longdouble_va.c
|
|
|
bd9b18 |
--- libffi-3.0.13/testsuite/libffi.call/cls_longdouble_va.c 2013-03-16 21:49:39.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/testsuite/libffi.call/cls_longdouble_va.c 2013-11-13 22:37:13.437459229 +1030
|
|
|
bd9b18 |
@@ -38,7 +38,7 @@ int main (void)
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* This printf call is variadic */
|
|
|
bd9b18 |
CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint,
|
|
|
bd9b18 |
- arg_types) == FFI_OK);
|
|
|
bd9b18 |
+ arg_types) == FFI_OK);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
args[0] = &format;
|
|
|
bd9b18 |
args[1] = &ldArg;
|
|
|
bd9b18 |
@@ -49,13 +49,10 @@ int main (void)
|
|
|
bd9b18 |
printf("res: %d\n", (int) res);
|
|
|
bd9b18 |
/* { dg-output "\nres: 4" } */
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- /* The call to cls_longdouble_va_fn is static, so have to use a normal prep_cif */
|
|
|
bd9b18 |
- CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint,
|
|
|
bd9b18 |
- arg_types) == FFI_OK);
|
|
|
bd9b18 |
+ CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL,
|
|
|
bd9b18 |
+ code) == FFI_OK);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL, code) == FFI_OK);
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
- res = ((int(*)(char*, long double))(code))(format, ldArg);
|
|
|
bd9b18 |
+ res = ((int(*)(char*, ...))(code))(format, ldArg);
|
|
|
bd9b18 |
/* { dg-output "\n7.0" } */
|
|
|
bd9b18 |
printf("res: %d\n", (int) res);
|
|
|
bd9b18 |
/* { dg-output "\nres: 4" } */
|
|
|
bd9b18 |
diff -urp libffi-3.0.13/doc/libffi.texi libffi-current/doc/libffi.texi
|
|
|
bd9b18 |
--- libffi-3.0.13/doc/libffi.texi 2013-03-16 22:41:19.000000000 +1030
|
|
|
bd9b18 |
+++ libffi-current/doc/libffi.texi 2013-11-17 09:06:03.209763612 +1030
|
|
|
bd9b18 |
@@ -184,11 +184,11 @@ This calls the function @var{fn} accordi
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@var{rvalue} is a pointer to a chunk of memory that will hold the
|
|
|
bd9b18 |
result of the function call. This must be large enough to hold the
|
|
|
bd9b18 |
-result and must be suitably aligned; it is the caller's responsibility
|
|
|
bd9b18 |
+result, no smaller than the system register size (generally 32 or 64
|
|
|
bd9b18 |
+bits), and must be suitably aligned; it is the caller's responsibility
|
|
|
bd9b18 |
to ensure this. If @var{cif} declares that the function returns
|
|
|
bd9b18 |
@code{void} (using @code{ffi_type_void}), then @var{rvalue} is
|
|
|
bd9b18 |
-ignored. If @var{rvalue} is @samp{NULL}, then the return value is
|
|
|
bd9b18 |
-discarded.
|
|
|
bd9b18 |
+ignored.
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@var{avalues} is a vector of @code{void *} pointers that point to the
|
|
|
bd9b18 |
memory locations holding the argument values for a call. If @var{cif}
|
|
|
bd9b18 |
@@ -214,7 +214,7 @@ int main()
|
|
|
bd9b18 |
ffi_type *args[1];
|
|
|
bd9b18 |
void *values[1];
|
|
|
bd9b18 |
char *s;
|
|
|
bd9b18 |
- int rc;
|
|
|
bd9b18 |
+ ffi_arg rc;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Initialize the argument info vectors */
|
|
|
bd9b18 |
args[0] = &ffi_type_pointer;
|
|
|
bd9b18 |
@@ -222,7 +222,7 @@ int main()
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Initialize the cif */
|
|
|
bd9b18 |
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
|
|
bd9b18 |
- &ffi_type_uint, args) == FFI_OK)
|
|
|
bd9b18 |
+ &ffi_type_sint, args) == FFI_OK)
|
|
|
bd9b18 |
@{
|
|
|
bd9b18 |
s = "Hello World!";
|
|
|
bd9b18 |
ffi_call(&cif, puts, &rc, values);
|
|
|
bd9b18 |
@@ -414,6 +414,7 @@ Here is the corresponding code to descri
|
|
|
bd9b18 |
int i;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
tm_type.size = tm_type.alignment = 0;
|
|
|
bd9b18 |
+ tm_type.type = FFI_TYPE_STRUCT;
|
|
|
bd9b18 |
tm_type.elements = &tm_type_elements;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
for (i = 0; i < 9; i++)
|
|
|
bd9b18 |
@@ -540,21 +541,23 @@ A trivial example that creates a new @co
|
|
|
bd9b18 |
#include <ffi.h>
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Acts like puts with the file given at time of enclosure. */
|
|
|
bd9b18 |
-void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
|
|
|
bd9b18 |
- FILE *stream)
|
|
|
bd9b18 |
+void puts_binding(ffi_cif *cif, void *ret, void* args[],
|
|
|
bd9b18 |
+ void *stream)
|
|
|
bd9b18 |
@{
|
|
|
bd9b18 |
- *ret = fputs(*(char **)args[0], stream);
|
|
|
bd9b18 |
+ *(ffi_arg *)ret = fputs(*(char **)args[0], (FILE *)stream);
|
|
|
bd9b18 |
@}
|
|
|
bd9b18 |
|
|
|
bd9b18 |
+typedef int (*puts_t)(char *);
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
int main()
|
|
|
bd9b18 |
@{
|
|
|
bd9b18 |
ffi_cif cif;
|
|
|
bd9b18 |
ffi_type *args[1];
|
|
|
bd9b18 |
ffi_closure *closure;
|
|
|
bd9b18 |
|
|
|
bd9b18 |
- int (*bound_puts)(char *);
|
|
|
bd9b18 |
+ void *bound_puts;
|
|
|
bd9b18 |
int rc;
|
|
|
bd9b18 |
-
|
|
|
bd9b18 |
+
|
|
|
bd9b18 |
/* Allocate closure and bound_puts */
|
|
|
bd9b18 |
closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
|
|
|
bd9b18 |
|
|
|
bd9b18 |
@@ -565,13 +568,13 @@ int main()
|
|
|
bd9b18 |
|
|
|
bd9b18 |
/* Initialize the cif */
|
|
|
bd9b18 |
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
|
|
bd9b18 |
- &ffi_type_uint, args) == FFI_OK)
|
|
|
bd9b18 |
+ &ffi_type_sint, args) == FFI_OK)
|
|
|
bd9b18 |
@{
|
|
|
bd9b18 |
/* Initialize the closure, setting stream to stdout */
|
|
|
bd9b18 |
- if (ffi_prep_closure_loc(closure, &cif, puts_binding,
|
|
|
bd9b18 |
+ if (ffi_prep_closure_loc(closure, &cif, puts_binding,
|
|
|
bd9b18 |
stdout, bound_puts) == FFI_OK)
|
|
|
bd9b18 |
@{
|
|
|
bd9b18 |
- rc = bound_puts("Hello World!");
|
|
|
bd9b18 |
+ rc = ((puts_t)bound_puts)("Hello World!");
|
|
|
bd9b18 |
/* rc now holds the result of the call to fputs */
|
|
|
bd9b18 |
@}
|
|
|
bd9b18 |
@}
|