arm: Deref ffi_put_arg arguments
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
diff --git a/src/arm/ffi.c b/src/arm/ffi.c
index 7d86e94..5e5ad0a 100644
--- a/src/arm/ffi.c
+++ b/src/arm/ffi.c
@@ -56,58 +56,46 @@ ffi_align (ffi_type *ty, void *p)
}
static size_t
-ffi_put_arg (ffi_type **arg_type, void **arg, char *stack)
+ffi_put_arg (ffi_type *ty, void *src, void *dst)
{
- register char *argp = stack;
- register ffi_type **p_arg = arg_type;
- register void **p_argv = arg;
- register size_t z = (*p_arg)->size;
+ size_t z = ty->size;
- if (z < sizeof (int))
+ switch (ty->type)
{
- z = sizeof (int);
- switch ((*p_arg)->type)
- {
- case FFI_TYPE_SINT8:
- *(signed int *) argp = (signed int) *(SINT8 *) (*p_argv);
- break;
-
- case FFI_TYPE_UINT8:
- *(unsigned int *) argp = (unsigned int) *(UINT8 *) (*p_argv);
- break;
-
- case FFI_TYPE_SINT16:
- *(signed int *) argp = (signed int) *(SINT16 *) (*p_argv);
- break;
+ case FFI_TYPE_SINT8:
+ *(UINT32 *)dst = *(SINT8 *)src;
+ break;
+ case FFI_TYPE_UINT8:
+ *(UINT32 *)dst = *(UINT8 *)src;
+ break;
+ case FFI_TYPE_SINT16:
+ *(UINT32 *)dst = *(SINT16 *)src;
+ break;
+ case FFI_TYPE_UINT16:
+ *(UINT32 *)dst = *(UINT16 *)src;
+ break;
- case FFI_TYPE_UINT16:
- *(unsigned int *) argp = (unsigned int) *(UINT16 *) (*p_argv);
- break;
+ case FFI_TYPE_INT:
+ case FFI_TYPE_SINT32:
+ case FFI_TYPE_UINT32:
+ case FFI_TYPE_POINTER:
+ case FFI_TYPE_FLOAT:
+ *(UINT32 *)dst = *(UINT32 *)src;
+ break;
- case FFI_TYPE_STRUCT:
- memcpy (argp, *p_argv, (*p_arg)->size);
- break;
+ case FFI_TYPE_SINT64:
+ case FFI_TYPE_UINT64:
+ case FFI_TYPE_DOUBLE:
+ *(UINT64 *)dst = *(UINT64 *)src;
+ break;
- default:
- FFI_ASSERT (0);
- }
- }
- else if (z == sizeof (int))
- {
- if ((*p_arg)->type == FFI_TYPE_FLOAT)
- *(float *) argp = *(float *) (*p_argv);
- else
- *(unsigned int *) argp = (unsigned int) *(UINT32 *) (*p_argv);
- }
- else if (z == sizeof (double) && (*p_arg)->type == FFI_TYPE_DOUBLE)
- {
- *(double *) argp = *(double *) (*p_argv);
- }
- else
- {
- memcpy (argp, *p_argv, z);
+ case FFI_TYPE_STRUCT:
+ default:
+ memcpy (dst, src, z);
+ break;
}
- return z;
+
+ return ALIGN (z, 4);
}
/* ffi_prep_args is called by the assembly routine once stack space
@@ -138,7 +126,7 @@ ffi_prep_args_SYSV (char *stack, extended_cif *ecif, float *vfp_space)
(i != 0); i--, p_arg++, p_argv++)
{
argp = ffi_align (*p_arg, argp);
- argp += ffi_put_arg (p_arg, p_argv, argp);
+ argp += ffi_put_arg (*p_arg, *p_argv, argp);
}
return 0;
@@ -182,7 +170,7 @@ ffi_prep_args_VFP (char *stack, extended_cif * ecif, float *vfp_space)
if (vi < ecif->cif->vfp_nargs && is_vfp_type)
{
char *vfp_slot = (char *) (vfp_space + ecif->cif->vfp_args[vi++]);
- ffi_put_arg (p_arg, p_argv, vfp_slot);
+ ffi_put_arg (*p_arg, *p_argv, vfp_slot);
continue;
}
/* Try allocating in core registers. */
@@ -195,7 +183,7 @@ ffi_prep_args_VFP (char *stack, extended_cif * ecif, float *vfp_space)
area to place the argument. */
if (tregp + size <= eo_regp)
{
- regp = tregp + ffi_put_arg (p_arg, p_argv, tregp);
+ regp = tregp + ffi_put_arg (*p_arg, *p_argv, tregp);
done_with_regs = (regp == argp);
// ensure we did not write into the stack area
FFI_ASSERT (regp <= argp);
@@ -208,7 +196,7 @@ ffi_prep_args_VFP (char *stack, extended_cif * ecif, float *vfp_space)
{
stack_used = 1;
done_with_regs = 1;
- argp = tregp + ffi_put_arg (p_arg, p_argv, tregp);
+ argp = tregp + ffi_put_arg (*p_arg, *p_argv, tregp);
FFI_ASSERT (eo_regp < argp);
continue;
}
@@ -216,7 +204,7 @@ ffi_prep_args_VFP (char *stack, extended_cif * ecif, float *vfp_space)
/* Base case, arguments are passed on the stack */
stack_used = 1;
argp = ffi_align (*p_arg, argp);
- argp += ffi_put_arg (p_arg, p_argv, argp);
+ argp += ffi_put_arg (*p_arg, *p_argv, argp);
}
/* Indicate the VFP registers used. */
return ecif->cif->vfp_used;