folow the ARM hard-float ABI in ffi_prep_incoming_args_VFP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/src/arm/ffi.c b/src/arm/ffi.c
index 0165d64..4c3b146 100644
--- a/src/arm/ffi.c
+++ b/src/arm/ffi.c
@@ -446,38 +446,75 @@ ffi_prep_incoming_args_VFP(char *stack, void **rvalue,
{
register unsigned int i, vi = 0;
register void **p_argv;
- register char *argp;
+ register char *argp, *regp, *eo_regp;
register ffi_type **p_arg;
+ char done_with_regs = 0;
+ char stack_used = 0;
+ char is_vfp_type;
- argp = stack;
+ FFI_ASSERT(cif->abi == FFI_VFP);
+ regp = stack;
+ eo_regp = argp = regp + 16;
if ( cif->flags == FFI_TYPE_STRUCT ) {
- *rvalue = *(void **) argp;
- argp += 4;
+ *rvalue = *(void **) regp;
+ regp += 4;
}
p_argv = avalue;
for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
{
- size_t z;
-
- if (cif->abi == FFI_VFP
- && vi < cif->vfp_nargs && vfp_type_p (*p_arg))
- {
- *p_argv++ = (void*)(vfp_stack + cif->vfp_args[vi++]);
- continue;
- }
- argp = ffi_align(p_arg, argp);
+ size_t z;
+ is_vfp_type = vfp_type_p (*p_arg);
- z = (*p_arg)->size;
+ if(vi < cif->vfp_nargs && is_vfp_type)
+ {
+ *p_argv++ = (void*)(vfp_stack + cif->vfp_args[vi++]);
+ continue;
+ }
+ else if (!done_with_regs && !is_vfp_type)
+ {
+ char* tregp = ffi_align(p_arg, regp);
- /* because we're little endian, this is what it turns into. */
+ z = (*p_arg)->size;
+ z = (z < 4)? 4 : z; // pad
+
+ /* if the arguments either fits into the registers or uses registers
+ * and stack, while we haven't read other things from the stack */
+ if(tregp + z <= eo_regp || !stack_used)
+ {
+ /* because we're little endian, this is what it turns into. */
+ *p_argv = (void*) tregp;
+
+ p_argv++;
+ regp = tregp + z;
+ /* if regp points above the end of the register area */
+ if(regp >= eo_regp)
+ {
+ /* sanity check that we haven't read from the stack area before
+ * reaching this point */
+ FFI_ASSERT(argp <= regp);
+ FFI_ASSERT(argp == stack + 16);
+ argp = regp;
+ done_with_regs = 1;
+ stack_used = 1;
+ }
+ continue;
+ }
+ }
+ stack_used = 1;
- *p_argv = (void*) argp;
+ argp = ffi_align(p_arg, argp);
- p_argv++;
- argp += z;
+ z = (*p_arg)->size;
+
+ /* because we're little endian, this is what it turns into. */
+
+ *p_argv = (void*) argp;
+
+ p_argv++;
+ argp += z;
}
return;