1
/* -----------------------------------------------------------------------
4
m68k Foreign Function Interface
5
----------------------------------------------------------------------- */
8
#include <ffi_common.h>
12
/* ffi_prep_args is called by the assembly routine once stack space has
13
been allocated for the function's arguments. */
16
ffi_prep_args (void *stack, extended_cif *ecif)
22
void *struct_value_ptr;
26
if (ecif->cif->rtype->type == FFI_TYPE_STRUCT
27
&& ecif->cif->rtype->size > 8)
28
struct_value_ptr = ecif->rvalue;
30
struct_value_ptr = NULL;
32
p_argv = ecif->avalue;
34
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
40
/* Align if necessary. */
41
if (((*p_arg)->alignment - 1) & (unsigned) argp)
42
argp = (char *) ALIGN (argp, (*p_arg)->alignment);
47
switch ((*p_arg)->type)
50
*(signed int *) argp = (signed int) *(SINT8 *) *p_argv;
54
*(unsigned int *) argp = (unsigned int) *(UINT8 *) *p_argv;
58
*(signed int *) argp = (signed int) *(SINT16 *) *p_argv;
62
*(unsigned int *) argp = (unsigned int) *(UINT16 *) *p_argv;
66
memcpy (argp + sizeof (int) - z, *p_argv, z);
75
memcpy (argp, *p_argv, z);
80
return struct_value_ptr;
83
#define CIF_FLAGS_INT 1
84
#define CIF_FLAGS_DINT 2
85
#define CIF_FLAGS_FLOAT 4
86
#define CIF_FLAGS_DOUBLE 8
87
#define CIF_FLAGS_LDOUBLE 16
88
#define CIF_FLAGS_POINTER 32
89
#define CIF_FLAGS_STRUCT 64
91
/* Perform machine dependent cif processing */
93
ffi_prep_cif_machdep (ffi_cif *cif)
95
/* Set the return type flag */
96
switch (cif->rtype->type)
102
case FFI_TYPE_STRUCT:
103
if (cif->rtype->size > 4 && cif->rtype->size <= 8)
104
cif->flags = CIF_FLAGS_DINT;
105
else if (cif->rtype->size <= 4)
106
cif->flags = CIF_FLAGS_STRUCT;
112
cif->flags = CIF_FLAGS_FLOAT;
115
case FFI_TYPE_DOUBLE:
116
cif->flags = CIF_FLAGS_DOUBLE;
119
case FFI_TYPE_LONGDOUBLE:
120
cif->flags = CIF_FLAGS_LDOUBLE;
123
case FFI_TYPE_POINTER:
124
cif->flags = CIF_FLAGS_POINTER;
127
case FFI_TYPE_SINT64:
128
case FFI_TYPE_UINT64:
129
cif->flags = CIF_FLAGS_DINT;
133
cif->flags = CIF_FLAGS_INT;
140
extern void ffi_call_SYSV (void *(*) (void *, extended_cif *),
142
unsigned, unsigned, unsigned,
143
void *, void (*fn) ());
146
ffi_call (ffi_cif *cif, void (*fn) (), void *rvalue, void **avalue)
151
ecif.avalue = avalue;
153
/* If the return value is a struct and we don't have a return value
154
address then we need to make one. */
157
&& cif->rtype->type == FFI_TYPE_STRUCT
158
&& cif->rtype->size > 8)
159
ecif.rvalue = alloca (cif->rtype->size);
161
ecif.rvalue = rvalue;
167
ffi_call_SYSV (ffi_prep_args, &ecif, cif->bytes,
168
cif->flags, cif->rtype->size * 8,