sparc: Rewrite everything
It's impossible to call between v8 and v9 ABIs, because of the stack bias in the v9 ABI. So let's not pretend it's just not implemented yet. Split the v9 code out to a separate file. The register windows prevent ffi_call from setting up the entire stack frame the assembly, but we needn't make an indirect call back to prep_args.
This commit is contained in:
@@ -36,7 +36,7 @@ EXTRA_DIST = LICENSE ChangeLog.v1 ChangeLog.libgcj \
|
|||||||
src/sh/ffi.c src/sh/sysv.S src/sh/ffitarget.h src/sh64/ffi.c \
|
src/sh/ffi.c src/sh/sysv.S src/sh/ffitarget.h src/sh64/ffi.c \
|
||||||
src/sh64/sysv.S src/sh64/ffitarget.h src/sparc/v8.S \
|
src/sh64/sysv.S src/sh64/ffitarget.h src/sparc/v8.S \
|
||||||
src/sparc/v9.S src/sparc/ffitarget.h src/sparc/ffi.c \
|
src/sparc/v9.S src/sparc/ffitarget.h src/sparc/ffi.c \
|
||||||
src/x86/darwin64.S src/x86/ffi.c src/x86/sysv.S \
|
src/sparc/ffi64.c src/x86/darwin64.S src/x86/ffi.c src/x86/sysv.S \
|
||||||
src/x86/darwin.S src/x86/ffiw64.c src/x86/win64.S \
|
src/x86/darwin.S src/x86/ffiw64.c src/x86/win64.S \
|
||||||
src/x86/ffi64.c src/x86/unix64.S \
|
src/x86/ffi64.c src/x86/unix64.S \
|
||||||
src/x86/ffitarget.h src/pa/ffitarget.h src/pa/ffi.c \
|
src/x86/ffitarget.h src/pa/ffitarget.h src/pa/ffi.c \
|
||||||
@@ -141,7 +141,7 @@ if X86_DARWIN
|
|||||||
nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/darwin.S src/x86/ffi64.c src/x86/darwin64.S
|
nodist_libffi_la_SOURCES += src/x86/ffi.c src/x86/darwin.S src/x86/ffi64.c src/x86/darwin64.S
|
||||||
endif
|
endif
|
||||||
if SPARC
|
if SPARC
|
||||||
nodist_libffi_la_SOURCES += src/sparc/ffi.c src/sparc/v8.S src/sparc/v9.S
|
nodist_libffi_la_SOURCES += src/sparc/ffi.c src/sparc/ffi64.c src/sparc/v8.S src/sparc/v9.S
|
||||||
endif
|
endif
|
||||||
if ALPHA
|
if ALPHA
|
||||||
nodist_libffi_la_SOURCES += src/alpha/ffi.c src/alpha/osf.S
|
nodist_libffi_la_SOURCES += src/alpha/ffi.c src/alpha/osf.S
|
||||||
|
|||||||
@@ -147,9 +147,6 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
|
|||||||
#if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
|
#if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
|
||||||
/* Make space for the return structure pointer */
|
/* Make space for the return structure pointer */
|
||||||
if (cif->rtype->type == FFI_TYPE_STRUCT
|
if (cif->rtype->type == FFI_TYPE_STRUCT
|
||||||
#ifdef SPARC
|
|
||||||
&& (cif->abi != FFI_V9 || cif->rtype->size > 32)
|
|
||||||
#endif
|
|
||||||
#ifdef TILE
|
#ifdef TILE
|
||||||
&& (cif->rtype->size > 10 * FFI_SIZEOF_ARG)
|
&& (cif->rtype->size > 10 * FFI_SIZEOF_ARG)
|
||||||
#endif
|
#endif
|
||||||
@@ -179,14 +176,6 @@ ffi_status FFI_HIDDEN ffi_prep_cif_core(ffi_cif *cif, ffi_abi abi,
|
|||||||
FFI_ASSERT_VALID_TYPE(*ptr);
|
FFI_ASSERT_VALID_TYPE(*ptr);
|
||||||
|
|
||||||
#if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
|
#if !defined FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
|
||||||
#ifdef SPARC
|
|
||||||
if (((*ptr)->type == FFI_TYPE_STRUCT
|
|
||||||
&& ((*ptr)->size > 16 || cif->abi != FFI_V9))
|
|
||||||
|| ((*ptr)->type == FFI_TYPE_LONGDOUBLE
|
|
||||||
&& cif->abi != FFI_V9))
|
|
||||||
bytes += sizeof(void*);
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
/* Add any padding if necessary */
|
/* Add any padding if necessary */
|
||||||
if (((*ptr)->alignment - 1) & bytes)
|
if (((*ptr)->alignment - 1) & bytes)
|
||||||
|
|||||||
753
src/sparc/ffi.c
753
src/sparc/ffi.c
@@ -28,6 +28,9 @@
|
|||||||
#include <ffi.h>
|
#include <ffi.h>
|
||||||
#include <ffi_common.h>
|
#include <ffi_common.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
|
#ifndef SPARC64
|
||||||
|
|
||||||
/* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
|
/* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
|
||||||
all further uses in this file will refer to the 128-bit type. */
|
all further uses in this file will refer to the 128-bit type. */
|
||||||
@@ -40,632 +43,310 @@
|
|||||||
# define FFI_TYPE_LONGDOUBLE 4
|
# define FFI_TYPE_LONGDOUBLE 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* ffi_prep_args is called by the assembly routine once stack space
|
|
||||||
has been allocated for the function's arguments */
|
|
||||||
|
|
||||||
void FFI_HIDDEN
|
|
||||||
ffi_prep_args_v8(char *stack, extended_cif *ecif)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
void **p_argv;
|
|
||||||
char *argp;
|
|
||||||
ffi_type **p_arg;
|
|
||||||
|
|
||||||
/* Skip 16 words for the window save area */
|
|
||||||
argp = stack + 16*sizeof(int);
|
|
||||||
|
|
||||||
/* This should only really be done when we are returning a structure,
|
|
||||||
however, it's faster just to do it all the time...
|
|
||||||
|
|
||||||
if ( ecif->cif->rtype->type == FFI_TYPE_STRUCT ) */
|
|
||||||
*(int *) argp = (long)ecif->rvalue;
|
|
||||||
|
|
||||||
/* And 1 word for the structure return value. */
|
|
||||||
argp += sizeof(int);
|
|
||||||
|
|
||||||
#ifdef USING_PURIFY
|
|
||||||
/* Purify will probably complain in our assembly routine, unless we
|
|
||||||
zero out this memory. */
|
|
||||||
|
|
||||||
((int*)argp)[0] = 0;
|
|
||||||
((int*)argp)[1] = 0;
|
|
||||||
((int*)argp)[2] = 0;
|
|
||||||
((int*)argp)[3] = 0;
|
|
||||||
((int*)argp)[4] = 0;
|
|
||||||
((int*)argp)[5] = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
p_argv = ecif->avalue;
|
|
||||||
|
|
||||||
for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; i; i--, p_arg++)
|
|
||||||
{
|
|
||||||
size_t z;
|
|
||||||
|
|
||||||
if ((*p_arg)->type == FFI_TYPE_STRUCT
|
|
||||||
|| (*p_arg)->type == FFI_TYPE_LONGDOUBLE)
|
|
||||||
{
|
|
||||||
*(unsigned int *) argp = (unsigned long)(* p_argv);
|
|
||||||
z = sizeof(int);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
z = (*p_arg)->size;
|
|
||||||
if (z < sizeof(int))
|
|
||||||
{
|
|
||||||
z = sizeof(int);
|
|
||||||
switch ((*p_arg)->type)
|
|
||||||
{
|
|
||||||
case FFI_TYPE_SINT8:
|
|
||||||
*(signed int *) argp = *(SINT8 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_UINT8:
|
|
||||||
*(unsigned int *) argp = *(UINT8 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_SINT16:
|
|
||||||
*(signed int *) argp = *(SINT16 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_UINT16:
|
|
||||||
*(unsigned int *) argp = *(UINT16 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
FFI_ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(argp, *p_argv, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p_argv++;
|
|
||||||
argp += z;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FFI_HIDDEN
|
|
||||||
ffi_prep_args_v9(char *stack, extended_cif *ecif)
|
|
||||||
{
|
|
||||||
int i, ret = 0;
|
|
||||||
int tmp;
|
|
||||||
void **p_argv;
|
|
||||||
char *argp;
|
|
||||||
ffi_type **p_arg;
|
|
||||||
|
|
||||||
tmp = 0;
|
|
||||||
|
|
||||||
/* Skip 16 words for the window save area */
|
|
||||||
argp = stack + 16*sizeof(long long);
|
|
||||||
|
|
||||||
#ifdef USING_PURIFY
|
|
||||||
/* Purify will probably complain in our assembly routine, unless we
|
|
||||||
zero out this memory. */
|
|
||||||
|
|
||||||
((long long*)argp)[0] = 0;
|
|
||||||
((long long*)argp)[1] = 0;
|
|
||||||
((long long*)argp)[2] = 0;
|
|
||||||
((long long*)argp)[3] = 0;
|
|
||||||
((long long*)argp)[4] = 0;
|
|
||||||
((long long*)argp)[5] = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
p_argv = ecif->avalue;
|
|
||||||
|
|
||||||
if (ecif->cif->rtype->type == FFI_TYPE_STRUCT &&
|
|
||||||
ecif->cif->rtype->size > 32)
|
|
||||||
{
|
|
||||||
*(unsigned long long *) argp = (unsigned long)ecif->rvalue;
|
|
||||||
argp += sizeof(long long);
|
|
||||||
tmp = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0, p_arg = ecif->cif->arg_types; i < ecif->cif->nargs;
|
|
||||||
i++, p_arg++)
|
|
||||||
{
|
|
||||||
size_t z;
|
|
||||||
|
|
||||||
z = (*p_arg)->size;
|
|
||||||
switch ((*p_arg)->type)
|
|
||||||
{
|
|
||||||
case FFI_TYPE_STRUCT:
|
|
||||||
if (z > 16)
|
|
||||||
{
|
|
||||||
/* For structures larger than 16 bytes we pass reference. */
|
|
||||||
*(unsigned long long *) argp = (unsigned long)* p_argv;
|
|
||||||
argp += sizeof(long long);
|
|
||||||
tmp++;
|
|
||||||
p_argv++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* FALLTHROUGH */
|
|
||||||
case FFI_TYPE_FLOAT:
|
|
||||||
case FFI_TYPE_DOUBLE:
|
|
||||||
case FFI_TYPE_LONGDOUBLE:
|
|
||||||
ret = 1; /* We should promote into FP regs as well as integer. */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (z < sizeof(long long))
|
|
||||||
{
|
|
||||||
switch ((*p_arg)->type)
|
|
||||||
{
|
|
||||||
case FFI_TYPE_SINT8:
|
|
||||||
*(signed long long *) argp = *(SINT8 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_UINT8:
|
|
||||||
*(unsigned long long *) argp = *(UINT8 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_SINT16:
|
|
||||||
*(signed long long *) argp = *(SINT16 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_UINT16:
|
|
||||||
*(unsigned long long *) argp = *(UINT16 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_SINT32:
|
|
||||||
*(signed long long *) argp = *(SINT32 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_UINT32:
|
|
||||||
*(unsigned long long *) argp = *(UINT32 *)(* p_argv);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_FLOAT:
|
|
||||||
*(float *) (argp + 4) = *(FLOAT32 *)(* p_argv); /* Right justify */
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_STRUCT:
|
|
||||||
memcpy(argp, *p_argv, z);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
FFI_ASSERT(0);
|
|
||||||
}
|
|
||||||
z = sizeof(long long);
|
|
||||||
tmp++;
|
|
||||||
}
|
|
||||||
else if (z == sizeof(long long))
|
|
||||||
{
|
|
||||||
memcpy(argp, *p_argv, z);
|
|
||||||
z = sizeof(long long);
|
|
||||||
tmp++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((tmp & 1) && (*p_arg)->alignment > 8)
|
|
||||||
{
|
|
||||||
tmp++;
|
|
||||||
argp += sizeof(long long);
|
|
||||||
}
|
|
||||||
memcpy(argp, *p_argv, z);
|
|
||||||
z = 2 * sizeof(long long);
|
|
||||||
tmp += 2;
|
|
||||||
}
|
|
||||||
p_argv++;
|
|
||||||
argp += z;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Perform machine dependent cif processing */
|
/* Perform machine dependent cif processing */
|
||||||
ffi_status FFI_HIDDEN
|
ffi_status FFI_HIDDEN
|
||||||
ffi_prep_cif_machdep(ffi_cif *cif)
|
ffi_prep_cif_machdep(ffi_cif *cif)
|
||||||
{
|
{
|
||||||
int wordsize;
|
ffi_type *rtype = cif->rtype;
|
||||||
|
int rtt = rtype->type;
|
||||||
if (cif->abi != FFI_V9)
|
size_t bytes;
|
||||||
{
|
int i, n, flags;
|
||||||
wordsize = 4;
|
|
||||||
|
|
||||||
/* If we are returning a struct, this will already have been added.
|
|
||||||
Otherwise we need to add it because it's always got to be there! */
|
|
||||||
|
|
||||||
if (cif->rtype->type != FFI_TYPE_STRUCT)
|
|
||||||
cif->bytes += wordsize;
|
|
||||||
|
|
||||||
/* sparc call frames require that space is allocated for 6 args,
|
|
||||||
even if they aren't used. Make that space if necessary. */
|
|
||||||
|
|
||||||
if (cif->bytes < 4*6+4)
|
|
||||||
cif->bytes = 4*6+4;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wordsize = 8;
|
|
||||||
|
|
||||||
/* sparc call frames require that space is allocated for 6 args,
|
|
||||||
even if they aren't used. Make that space if necessary. */
|
|
||||||
|
|
||||||
if (cif->bytes < 8*6)
|
|
||||||
cif->bytes = 8*6;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adjust cif->bytes. to include 16 words for the window save area,
|
|
||||||
and maybe the struct/union return pointer area, */
|
|
||||||
|
|
||||||
cif->bytes += 16 * wordsize;
|
|
||||||
|
|
||||||
/* The stack must be 2 word aligned, so round bytes up
|
|
||||||
appropriately. */
|
|
||||||
|
|
||||||
cif->bytes = ALIGN(cif->bytes, 2 * wordsize);
|
|
||||||
|
|
||||||
/* Set the return type flag */
|
/* Set the return type flag */
|
||||||
switch (cif->rtype->type)
|
switch (rtt)
|
||||||
{
|
{
|
||||||
case FFI_TYPE_VOID:
|
case FFI_TYPE_VOID:
|
||||||
|
flags = SPARC_RET_VOID;
|
||||||
|
break;
|
||||||
case FFI_TYPE_FLOAT:
|
case FFI_TYPE_FLOAT:
|
||||||
|
flags = SPARC_RET_FLOAT;
|
||||||
|
break;
|
||||||
case FFI_TYPE_DOUBLE:
|
case FFI_TYPE_DOUBLE:
|
||||||
|
flags = SPARC_RET_DOUBLE;
|
||||||
|
break;
|
||||||
case FFI_TYPE_LONGDOUBLE:
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
cif->flags = cif->rtype->type;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FFI_TYPE_STRUCT:
|
case FFI_TYPE_STRUCT:
|
||||||
if (cif->abi == FFI_V9 && cif->rtype->size > 32)
|
flags = SPARC_RET_STRUCT;
|
||||||
cif->flags = FFI_TYPE_VOID;
|
|
||||||
else
|
|
||||||
cif->flags = FFI_TYPE_STRUCT;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FFI_TYPE_SINT8:
|
case FFI_TYPE_SINT8:
|
||||||
case FFI_TYPE_UINT8:
|
flags = SPARC_RET_SINT8;
|
||||||
case FFI_TYPE_SINT16:
|
break;
|
||||||
case FFI_TYPE_UINT16:
|
case FFI_TYPE_UINT8:
|
||||||
if (cif->abi == FFI_V9)
|
flags = SPARC_RET_UINT8;
|
||||||
cif->flags = FFI_TYPE_INT;
|
break;
|
||||||
else
|
case FFI_TYPE_SINT16:
|
||||||
cif->flags = cif->rtype->type;
|
flags = SPARC_RET_SINT16;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
flags = SPARC_RET_UINT16;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_INT:
|
||||||
|
case FFI_TYPE_SINT32:
|
||||||
|
case FFI_TYPE_UINT32:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
flags = SPARC_RET_UINT32;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FFI_TYPE_SINT64:
|
case FFI_TYPE_SINT64:
|
||||||
case FFI_TYPE_UINT64:
|
case FFI_TYPE_UINT64:
|
||||||
if (cif->abi == FFI_V9)
|
flags = SPARC_RET_INT64;
|
||||||
cif->flags = FFI_TYPE_INT;
|
|
||||||
else
|
|
||||||
cif->flags = FFI_TYPE_SINT64;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cif->flags = FFI_TYPE_INT;
|
abort();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
cif->flags = flags;
|
||||||
|
|
||||||
|
bytes = 0;
|
||||||
|
for (i = 0, n = cif->nargs; i < n; ++i)
|
||||||
|
{
|
||||||
|
ffi_type *ty = cif->arg_types[i];
|
||||||
|
size_t z = ty->size;
|
||||||
|
int tt = ty->type;
|
||||||
|
|
||||||
|
if (tt == FFI_TYPE_STRUCT || tt == FFI_TYPE_LONGDOUBLE)
|
||||||
|
/* Passed by reference. */
|
||||||
|
z = 4;
|
||||||
|
else
|
||||||
|
z = ALIGN(z, 4);
|
||||||
|
bytes += z;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sparc call frames require that space is allocated for 6 args,
|
||||||
|
even if they aren't used. Make that space if necessary. */
|
||||||
|
if (bytes < 6 * 4)
|
||||||
|
bytes = 6 * 4;
|
||||||
|
|
||||||
|
/* The ABI always requires space for the struct return pointer. */
|
||||||
|
bytes += 4;
|
||||||
|
|
||||||
|
/* The stack must be 2 word aligned, so round bytes up appropriately. */
|
||||||
|
bytes = ALIGN(bytes, 2 * 4);
|
||||||
|
|
||||||
|
/* Include the call frame to prep_args. */
|
||||||
|
bytes += 4*16 + 4*8;
|
||||||
|
cif->bytes = bytes;
|
||||||
|
|
||||||
return FFI_OK;
|
return FFI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
extern void ffi_call_v8(ffi_cif *cif, void (*fn)(void), void *rvalue,
|
||||||
ffi_v9_layout_struct(ffi_type *arg, int off, char *ret, char *intg, char *flt)
|
void **avalue, size_t bytes) FFI_HIDDEN;
|
||||||
|
|
||||||
|
int FFI_HIDDEN
|
||||||
|
ffi_prep_args_v8(ffi_cif *cif, unsigned long *argp, void *rvalue, void **avalue)
|
||||||
{
|
{
|
||||||
ffi_type **ptr = &arg->elements[0];
|
ffi_type **p_arg;
|
||||||
|
int flags = cif->flags;
|
||||||
|
int i, nargs;
|
||||||
|
|
||||||
while (*ptr != NULL)
|
if (rvalue == NULL)
|
||||||
{
|
{
|
||||||
if (off & ((*ptr)->alignment - 1))
|
if (flags == SPARC_RET_STRUCT)
|
||||||
off = ALIGN(off, (*ptr)->alignment);
|
{
|
||||||
|
/* Since we pass the pointer to the callee, we need a value.
|
||||||
|
We allowed for this space in ffi_call, before ffi_call_v8
|
||||||
|
alloca'd the space. */
|
||||||
|
rvalue = (char *)argp + cif->bytes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Otherwise, we can ignore the return value. */
|
||||||
|
flags = SPARC_RET_VOID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch ((*ptr)->type)
|
/* This could only really be done when we are returning a structure.
|
||||||
|
However, the space is reserved so we can do it unconditionally. */
|
||||||
|
*argp++ = (unsigned long)rvalue;
|
||||||
|
|
||||||
|
#ifdef USING_PURIFY
|
||||||
|
/* Purify will probably complain in our assembly routine,
|
||||||
|
unless we zero out this memory. */
|
||||||
|
memset(argp, 0, 6*4);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
p_arg = cif->arg_types;
|
||||||
|
for (i = 0, nargs = cif->nargs; i < nargs; i++)
|
||||||
|
{
|
||||||
|
ffi_type *ty = p_arg[i];
|
||||||
|
void *a = avalue[i];
|
||||||
|
|
||||||
|
switch (ty->type)
|
||||||
{
|
{
|
||||||
case FFI_TYPE_STRUCT:
|
case FFI_TYPE_STRUCT:
|
||||||
off = ffi_v9_layout_struct(*ptr, off, ret, intg, flt);
|
|
||||||
off = ALIGN(off, FFI_SIZEOF_ARG);
|
|
||||||
break;
|
|
||||||
case FFI_TYPE_FLOAT:
|
|
||||||
case FFI_TYPE_DOUBLE:
|
|
||||||
case FFI_TYPE_LONGDOUBLE:
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
memmove(ret + off, flt + off, (*ptr)->size);
|
*argp++ = (unsigned long)a;
|
||||||
off += (*ptr)->size;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
case FFI_TYPE_UINT64:
|
||||||
|
case FFI_TYPE_SINT64:
|
||||||
|
memcpy(argp, a, 8);
|
||||||
|
argp += 2;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_INT:
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
case FFI_TYPE_UINT32:
|
||||||
|
case FFI_TYPE_SINT32:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
*argp++ = *(unsigned *)a;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_UINT8:
|
||||||
|
*argp++ = *(UINT8 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_SINT8:
|
||||||
|
*argp++ = *(SINT8 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
*argp++ = *(UINT16 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_SINT16:
|
||||||
|
*argp++ = *(SINT16 *)a;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
memmove(ret + off, intg + off, (*ptr)->size);
|
abort();
|
||||||
off += (*ptr)->size;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
ptr++;
|
|
||||||
}
|
}
|
||||||
return off;
|
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
#ifdef SPARC64
|
ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
||||||
extern int ffi_call_v9(void *, extended_cif *, unsigned,
|
|
||||||
unsigned, unsigned *, void (*fn)(void)) FFI_HIDDEN;
|
|
||||||
#else
|
|
||||||
extern int ffi_call_v8(void *, extended_cif *, unsigned,
|
|
||||||
unsigned, unsigned *, void (*fn)(void)) FFI_HIDDEN;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __GNUC__
|
|
||||||
void ffi_flush_icache (void *, size_t) FFI_HIDDEN;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
|
||||||
{
|
{
|
||||||
extended_cif ecif;
|
size_t bytes = cif->bytes;
|
||||||
void *rval = rvalue;
|
|
||||||
|
|
||||||
ecif.cif = cif;
|
FFI_ASSERT (cif->abi == FFI_V8);
|
||||||
ecif.avalue = avalue;
|
|
||||||
|
|
||||||
/* If the return value is a struct and we don't have a return */
|
/* If we've not got a return value, we need to create one if we've
|
||||||
/* value address then we need to make one */
|
got to pass the return value to the callee. Otherwise ignore it. */
|
||||||
|
if (rvalue == NULL && cif->flags == SPARC_RET_STRUCT)
|
||||||
|
bytes += ALIGN (cif->rtype->size, 8);
|
||||||
|
|
||||||
ecif.rvalue = rvalue;
|
ffi_call_v8(cif, fn, rvalue, avalue, -bytes);
|
||||||
if (cif->rtype->type == FFI_TYPE_STRUCT)
|
|
||||||
{
|
|
||||||
if (cif->rtype->size <= 32)
|
|
||||||
rval = alloca(64);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rval = NULL;
|
|
||||||
if (rvalue == NULL)
|
|
||||||
ecif.rvalue = alloca(cif->rtype->size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (cif->abi)
|
|
||||||
{
|
|
||||||
case FFI_V8:
|
|
||||||
#ifdef SPARC64
|
|
||||||
/* We don't yet support calling 32bit code from 64bit */
|
|
||||||
FFI_ASSERT(0);
|
|
||||||
#else
|
|
||||||
if (rvalue && (cif->rtype->type == FFI_TYPE_STRUCT
|
|
||||||
|| cif->flags == FFI_TYPE_LONGDOUBLE))
|
|
||||||
{
|
|
||||||
/* For v8, we need an "unimp" with size of returning struct */
|
|
||||||
/* behind "call", so we alloc some executable space for it. */
|
|
||||||
/* l7 is used, we need to make sure v8.S doesn't use %l7. */
|
|
||||||
unsigned int *call_struct = NULL;
|
|
||||||
ffi_closure_alloc(32, (void **)&call_struct);
|
|
||||||
if (call_struct)
|
|
||||||
{
|
|
||||||
unsigned long f = (unsigned long)fn;
|
|
||||||
call_struct[0] = 0xae10001f; /* mov %i7, %l7 */
|
|
||||||
call_struct[1] = 0xbe10000f; /* mov %o7, %i7 */
|
|
||||||
call_struct[2] = 0x03000000 | f >> 10; /* sethi %hi(fn), %g1 */
|
|
||||||
call_struct[3] = 0x9fc06000 | (f & 0x3ff); /* jmp %g1+%lo(fn), %o7 */
|
|
||||||
call_struct[4] = 0x01000000; /* nop */
|
|
||||||
if (cif->rtype->size < 0x7f)
|
|
||||||
call_struct[5] = cif->rtype->size; /* unimp */
|
|
||||||
else
|
|
||||||
call_struct[5] = 0x01000000; /* nop */
|
|
||||||
call_struct[6] = 0x81c7e008; /* ret */
|
|
||||||
call_struct[7] = 0xbe100017; /* mov %l7, %i7 */
|
|
||||||
#ifdef __GNUC__
|
|
||||||
asm volatile ("iflush %0; iflush %0+8; iflush %0+16; iflush %0+24" : :
|
|
||||||
"r" (call_struct) : "memory");
|
|
||||||
/* SPARC v8 requires 5 instructions for flush to be visible */
|
|
||||||
asm volatile ("nop; nop; nop; nop; nop");
|
|
||||||
#else
|
|
||||||
ffi_flush_icache (call_struct, 32);
|
|
||||||
#endif
|
|
||||||
ffi_call_v8(ffi_prep_args_v8, &ecif, cif->bytes,
|
|
||||||
cif->flags, rvalue, call_struct);
|
|
||||||
ffi_closure_free(call_struct);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ffi_call_v8(ffi_prep_args_v8, &ecif, cif->bytes,
|
|
||||||
cif->flags, rvalue, fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ffi_call_v8(ffi_prep_args_v8, &ecif, cif->bytes,
|
|
||||||
cif->flags, rvalue, fn);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
case FFI_V9:
|
|
||||||
#ifdef SPARC64
|
|
||||||
ffi_call_v9(ffi_prep_args_v9, &ecif, cif->bytes,
|
|
||||||
cif->flags, rval, fn);
|
|
||||||
if (rvalue && rval && cif->rtype->type == FFI_TYPE_STRUCT)
|
|
||||||
ffi_v9_layout_struct(cif->rtype, 0, (char *)rvalue, (char *)rval, ((char *)rval)+32);
|
|
||||||
#else
|
|
||||||
/* And vice versa */
|
|
||||||
FFI_ASSERT(0);
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FFI_ASSERT(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
#ifdef SPARC64
|
static inline void
|
||||||
extern void ffi_closure_v9(void) FFI_HIDDEN;
|
ffi_flush_icache (void *p)
|
||||||
|
{
|
||||||
|
/* SPARC v8 requires 5 instructions for flush to be visible */
|
||||||
|
asm volatile ("iflush %0; iflush %0+8; nop; nop; nop; nop; nop"
|
||||||
|
: : "r" (p) : "memory");
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
extern void ffi_closure_v8(void) FFI_HIDDEN;
|
extern void ffi_flush_icache (void *) FFI_HIDDEN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern void ffi_closure_v8(void) FFI_HIDDEN;
|
||||||
|
|
||||||
ffi_status
|
ffi_status
|
||||||
ffi_prep_closure_loc (ffi_closure* closure,
|
ffi_prep_closure_loc (ffi_closure *closure,
|
||||||
ffi_cif* cif,
|
ffi_cif *cif,
|
||||||
void (*fun)(ffi_cif*, void*, void**, void*),
|
void (*fun)(ffi_cif*, void*, void**, void*),
|
||||||
void *user_data,
|
void *user_data,
|
||||||
void *codeloc)
|
void *codeloc)
|
||||||
{
|
{
|
||||||
unsigned int *tramp = (unsigned int *) &closure->tramp[0];
|
unsigned int *tramp = (unsigned int *) &closure->tramp[0];
|
||||||
unsigned long fn;
|
unsigned long ctx = (unsigned long) closure;
|
||||||
#ifdef SPARC64
|
unsigned long fn = (unsigned long) ffi_closure_v8;
|
||||||
/* Trampoline address is equal to the closure address. We take advantage
|
|
||||||
of that to reduce the trampoline size by 8 bytes. */
|
|
||||||
if (cif->abi != FFI_V9)
|
|
||||||
return FFI_BAD_ABI;
|
|
||||||
fn = (unsigned long) ffi_closure_v9;
|
|
||||||
tramp[0] = 0x83414000; /* rd %pc, %g1 */
|
|
||||||
tramp[1] = 0xca586010; /* ldx [%g1+16], %g5 */
|
|
||||||
tramp[2] = 0x81c14000; /* jmp %g5 */
|
|
||||||
tramp[3] = 0x01000000; /* nop */
|
|
||||||
*((unsigned long *) &tramp[4]) = fn;
|
|
||||||
#else
|
|
||||||
unsigned long ctx = (unsigned long) codeloc;
|
|
||||||
if (cif->abi != FFI_V8)
|
if (cif->abi != FFI_V8)
|
||||||
return FFI_BAD_ABI;
|
return FFI_BAD_ABI;
|
||||||
fn = (unsigned long) ffi_closure_v8;
|
|
||||||
tramp[0] = 0x03000000 | fn >> 10; /* sethi %hi(fn), %g1 */
|
tramp[0] = 0x03000000 | fn >> 10; /* sethi %hi(fn), %g1 */
|
||||||
tramp[1] = 0x05000000 | ctx >> 10; /* sethi %hi(ctx), %g2 */
|
tramp[1] = 0x05000000 | ctx >> 10; /* sethi %hi(ctx), %g2 */
|
||||||
tramp[2] = 0x81c06000 | (fn & 0x3ff); /* jmp %g1+%lo(fn) */
|
tramp[2] = 0x81c06000 | (fn & 0x3ff); /* jmp %g1+%lo(fn) */
|
||||||
tramp[3] = 0x8410a000 | (ctx & 0x3ff);/* or %g2, %lo(ctx) */
|
tramp[3] = 0x8410a000 | (ctx & 0x3ff);/* or %g2, %lo(ctx) */
|
||||||
#endif
|
|
||||||
|
|
||||||
closure->cif = cif;
|
closure->cif = cif;
|
||||||
closure->fun = fun;
|
closure->fun = fun;
|
||||||
closure->user_data = user_data;
|
closure->user_data = user_data;
|
||||||
|
|
||||||
/* Flush the Icache. closure is 8 bytes aligned. */
|
ffi_flush_icache (closure);
|
||||||
#ifdef __GNUC__
|
|
||||||
#ifdef SPARC64
|
|
||||||
asm volatile ("flush %0; flush %0+8" : : "r" (closure) : "memory");
|
|
||||||
#else
|
|
||||||
asm volatile ("iflush %0; iflush %0+8" : : "r" (closure) : "memory");
|
|
||||||
/* SPARC v8 requires 5 instructions for flush to be visible */
|
|
||||||
asm volatile ("nop; nop; nop; nop; nop");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
ffi_flush_icache (closure, 16);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return FFI_OK;
|
return FFI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FFI_HIDDEN
|
int FFI_HIDDEN
|
||||||
ffi_closure_sparc_inner_v8(ffi_closure *closure, void *rvalue,
|
ffi_closure_sparc_inner_v8(ffi_closure *closure, void *rvalue,
|
||||||
unsigned long *gpr, unsigned long *scratch)
|
unsigned long *argp)
|
||||||
{
|
{
|
||||||
ffi_cif *cif;
|
ffi_cif *cif;
|
||||||
ffi_type **arg_types;
|
ffi_type **arg_types;
|
||||||
void **avalue;
|
void **avalue;
|
||||||
int i, argn;
|
int i, nargs, flags;
|
||||||
|
|
||||||
cif = closure->cif;
|
cif = closure->cif;
|
||||||
arg_types = cif->arg_types;
|
arg_types = cif->arg_types;
|
||||||
avalue = alloca(cif->nargs * sizeof(void *));
|
nargs = cif->nargs;
|
||||||
|
flags = cif->flags;
|
||||||
|
avalue = alloca(nargs * sizeof(void *));
|
||||||
|
|
||||||
/* Copy the caller's structure return address so that the closure
|
/* Copy the caller's structure return address so that the closure
|
||||||
returns the data directly to the caller. */
|
returns the data directly to the caller. */
|
||||||
if (cif->flags == FFI_TYPE_STRUCT || cif->flags == FFI_TYPE_LONGDOUBLE)
|
if (flags == SPARC_RET_STRUCT)
|
||||||
rvalue = (void *) gpr[0];
|
rvalue = (void *)*argp;
|
||||||
|
|
||||||
/* Always skip the structure return address. */
|
/* Always skip the structure return address. */
|
||||||
argn = 1;
|
argp++;
|
||||||
|
|
||||||
/* Grab the addresses of the arguments from the stack frame. */
|
/* Grab the addresses of the arguments from the stack frame. */
|
||||||
for (i = 0; i < cif->nargs; i++)
|
for (i = 0; i < nargs; i++)
|
||||||
{
|
{
|
||||||
if (arg_types[i]->type == FFI_TYPE_STRUCT
|
ffi_type *ty = arg_types[i];
|
||||||
|| arg_types[i]->type == FFI_TYPE_LONGDOUBLE)
|
int tt = ty->type;
|
||||||
|
void *a = argp;
|
||||||
|
|
||||||
|
switch (tt)
|
||||||
{
|
{
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
/* Straight copy of invisible reference. */
|
/* Straight copy of invisible reference. */
|
||||||
avalue[i] = (void *)gpr[argn++];
|
a = (void *)*argp;
|
||||||
}
|
break;
|
||||||
else if ((arg_types[i]->type == FFI_TYPE_DOUBLE
|
|
||||||
|| arg_types[i]->type == FFI_TYPE_SINT64
|
case FFI_TYPE_DOUBLE:
|
||||||
|| arg_types[i]->type == FFI_TYPE_UINT64)
|
case FFI_TYPE_SINT64:
|
||||||
/* gpr is 8-byte aligned. */
|
case FFI_TYPE_UINT64:
|
||||||
&& (argn % 2) != 0)
|
if ((unsigned long)a & 7)
|
||||||
{
|
{
|
||||||
/* Align on a 8-byte boundary. */
|
/* Align on a 8-byte boundary. */
|
||||||
scratch[0] = gpr[argn];
|
UINT64 *tmp = alloca(8);
|
||||||
scratch[1] = gpr[argn+1];
|
*tmp = ((UINT64)argp[0] << 32) | argp[1];
|
||||||
avalue[i] = scratch;
|
a = tmp;
|
||||||
scratch -= 2;
|
}
|
||||||
argn += 2;
|
argp++;
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
case FFI_TYPE_INT:
|
||||||
/* Always right-justify. */
|
case FFI_TYPE_FLOAT:
|
||||||
argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
|
case FFI_TYPE_UINT32:
|
||||||
avalue[i] = ((char *) &gpr[argn]) - arg_types[i]->size;
|
case FFI_TYPE_SINT32:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
case FFI_TYPE_SINT16:
|
||||||
|
a += 2;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT8:
|
||||||
|
case FFI_TYPE_SINT8:
|
||||||
|
a += 3;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
|
argp++;
|
||||||
|
avalue[i] = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invoke the closure. */
|
/* Invoke the closure. */
|
||||||
(closure->fun) (cif, rvalue, avalue, closure->user_data);
|
(closure->fun) (cif, rvalue, avalue, closure->user_data);
|
||||||
|
|
||||||
/* Tell ffi_closure_sparc how to perform return type promotions. */
|
/* Tell ffi_closure_sparc how to perform return type promotions. */
|
||||||
return cif->rtype->type;
|
return flags;
|
||||||
}
|
|
||||||
|
|
||||||
int FFI_HIDDEN
|
|
||||||
ffi_closure_sparc_inner_v9(ffi_closure *closure, void *rvalue,
|
|
||||||
unsigned long *gpr, double *fpr)
|
|
||||||
{
|
|
||||||
ffi_cif *cif;
|
|
||||||
ffi_type **arg_types;
|
|
||||||
void **avalue;
|
|
||||||
int i, argn, fp_slot_max;
|
|
||||||
|
|
||||||
cif = closure->cif;
|
|
||||||
arg_types = cif->arg_types;
|
|
||||||
avalue = alloca(cif->nargs * sizeof(void *));
|
|
||||||
|
|
||||||
/* Copy the caller's structure return address so that the closure
|
|
||||||
returns the data directly to the caller. */
|
|
||||||
if (cif->flags == FFI_TYPE_VOID
|
|
||||||
&& cif->rtype->type == FFI_TYPE_STRUCT)
|
|
||||||
{
|
|
||||||
rvalue = (void *) gpr[0];
|
|
||||||
/* Skip the structure return address. */
|
|
||||||
argn = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
argn = 0;
|
|
||||||
|
|
||||||
fp_slot_max = 16 - argn;
|
|
||||||
|
|
||||||
/* Grab the addresses of the arguments from the stack frame. */
|
|
||||||
for (i = 0; i < cif->nargs; i++)
|
|
||||||
{
|
|
||||||
if (arg_types[i]->type == FFI_TYPE_STRUCT)
|
|
||||||
{
|
|
||||||
if (arg_types[i]->size > 16)
|
|
||||||
{
|
|
||||||
/* Straight copy of invisible reference. */
|
|
||||||
avalue[i] = (void *)gpr[argn++];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Left-justify. */
|
|
||||||
ffi_v9_layout_struct(arg_types[i],
|
|
||||||
0,
|
|
||||||
(char *) &gpr[argn],
|
|
||||||
(char *) &gpr[argn],
|
|
||||||
(char *) &fpr[argn]);
|
|
||||||
avalue[i] = &gpr[argn];
|
|
||||||
argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Right-justify. */
|
|
||||||
argn += ALIGN(arg_types[i]->size, FFI_SIZEOF_ARG) / FFI_SIZEOF_ARG;
|
|
||||||
|
|
||||||
/* Align on a 16-byte boundary. */
|
|
||||||
if (arg_types[i]->type == FFI_TYPE_LONGDOUBLE && (argn % 2) != 0)
|
|
||||||
argn++;
|
|
||||||
if (i < fp_slot_max
|
|
||||||
&& (arg_types[i]->type == FFI_TYPE_FLOAT
|
|
||||||
|| arg_types[i]->type == FFI_TYPE_DOUBLE
|
|
||||||
|| arg_types[i]->type == FFI_TYPE_LONGDOUBLE))
|
|
||||||
avalue[i] = ((char *) &fpr[argn]) - arg_types[i]->size;
|
|
||||||
else
|
|
||||||
avalue[i] = ((char *) &gpr[argn]) - arg_types[i]->size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Invoke the closure. */
|
|
||||||
(closure->fun) (cif, rvalue, avalue, closure->user_data);
|
|
||||||
|
|
||||||
/* Tell ffi_closure_sparc how to perform return type promotions. */
|
|
||||||
return cif->rtype->type;
|
|
||||||
}
|
}
|
||||||
|
#endif /* !SPARC64 */
|
||||||
|
|||||||
433
src/sparc/ffi64.c
Normal file
433
src/sparc/ffi64.c
Normal file
@@ -0,0 +1,433 @@
|
|||||||
|
/* -----------------------------------------------------------------------
|
||||||
|
ffi.c - Copyright (c) 2011, 2013 Anthony Green
|
||||||
|
Copyright (c) 1996, 2003-2004, 2007-2008 Red Hat, Inc.
|
||||||
|
|
||||||
|
SPARC Foreign Function Interface
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
``Software''), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
----------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <ffi.h>
|
||||||
|
#include <ffi_common.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
|
/* Force FFI_TYPE_LONGDOUBLE to be different than FFI_TYPE_DOUBLE;
|
||||||
|
all further uses in this file will refer to the 128-bit type. */
|
||||||
|
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
||||||
|
# if FFI_TYPE_LONGDOUBLE != 4
|
||||||
|
# error FFI_TYPE_LONGDOUBLE out of date
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# undef FFI_TYPE_LONGDOUBLE
|
||||||
|
# define FFI_TYPE_LONGDOUBLE 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SPARC64
|
||||||
|
/* Perform machine dependent cif processing */
|
||||||
|
|
||||||
|
int FFI_HIDDEN
|
||||||
|
ffi_v9_layout_struct (ffi_type *arg, int off, void *d, void *si, void *sf)
|
||||||
|
{
|
||||||
|
ffi_type **elts, *t;
|
||||||
|
|
||||||
|
for (elts = arg->elements; (t = *elts) != NULL; elts++)
|
||||||
|
{
|
||||||
|
size_t z = t->size;
|
||||||
|
void *src = si;
|
||||||
|
|
||||||
|
off = ALIGN(off, t->alignment);
|
||||||
|
switch (t->type)
|
||||||
|
{
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
off = ffi_v9_layout_struct(t, off, d, si, sf);
|
||||||
|
off = ALIGN(off, FFI_SIZEOF_ARG);
|
||||||
|
continue;
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
|
/* Note that closures start with the argument offset,
|
||||||
|
so that we know when to stop looking at fp regs. */
|
||||||
|
if (off < 128)
|
||||||
|
src = sf;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memcpy(d + off, src + off, z);
|
||||||
|
off += z;
|
||||||
|
}
|
||||||
|
|
||||||
|
return off;
|
||||||
|
}
|
||||||
|
|
||||||
|
ffi_status FFI_HIDDEN
|
||||||
|
ffi_prep_cif_machdep(ffi_cif *cif)
|
||||||
|
{
|
||||||
|
ffi_type *rtype = cif->rtype;
|
||||||
|
int rtt = rtype->type;
|
||||||
|
size_t bytes = 0;
|
||||||
|
int i, n, flags;
|
||||||
|
|
||||||
|
/* Set the return type flag */
|
||||||
|
switch (rtt)
|
||||||
|
{
|
||||||
|
case FFI_TYPE_VOID:
|
||||||
|
flags = SPARC_RET_VOID;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
flags = SPARC_RET_FLOAT;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
flags = SPARC_RET_DOUBLE;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
|
flags = SPARC_RET_LDOUBLE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
if (rtype->size > 32)
|
||||||
|
{
|
||||||
|
flags = SPARC_RET_VOID | SPARC_FLAG_RET_IN_MEM;
|
||||||
|
bytes = 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
flags = SPARC_RET_STRUCT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_SINT8:
|
||||||
|
flags = SPARC_RET_SINT8;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT8:
|
||||||
|
flags = SPARC_RET_UINT8;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_SINT16:
|
||||||
|
flags = SPARC_RET_SINT16;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
flags = SPARC_RET_UINT16;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_INT:
|
||||||
|
case FFI_TYPE_SINT32:
|
||||||
|
flags = SPARC_RET_SINT32;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT32:
|
||||||
|
flags = SPARC_RET_UINT32;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_SINT64:
|
||||||
|
case FFI_TYPE_UINT64:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
flags = SPARC_RET_INT64;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes = 0;
|
||||||
|
for (i = 0, n = cif->nargs; i < n; ++i)
|
||||||
|
{
|
||||||
|
ffi_type *ty = cif->arg_types[i];
|
||||||
|
size_t z = ty->size;
|
||||||
|
size_t a = ty->alignment;
|
||||||
|
|
||||||
|
switch (ty->type)
|
||||||
|
{
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
/* Large structs passed by reference. */
|
||||||
|
if (z > 16)
|
||||||
|
{
|
||||||
|
a = z = 8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* ??? FALLTHRU -- check for fp members in the struct. */
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
|
flags |= SPARC_FLAG_FP_ARGS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bytes = ALIGN(bytes, a);
|
||||||
|
bytes += ALIGN(z, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Sparc call frames require that space is allocated for 6 args,
|
||||||
|
even if they aren't used. Make that space if necessary. */
|
||||||
|
if (bytes < 6 * 8)
|
||||||
|
bytes = 6 * 8;
|
||||||
|
|
||||||
|
/* The stack must be 2 word aligned, so round bytes up appropriately. */
|
||||||
|
bytes = ALIGN(bytes, 16);
|
||||||
|
|
||||||
|
/* Include the call frame to prep_args. */
|
||||||
|
bytes += 8*16 + 8*8;
|
||||||
|
|
||||||
|
cif->bytes = bytes;
|
||||||
|
cif->flags = flags;
|
||||||
|
return FFI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void ffi_call_v9(ffi_cif *cif, void (*fn)(void), void *rvalue,
|
||||||
|
void **avalue, size_t bytes) FFI_HIDDEN;
|
||||||
|
|
||||||
|
/* ffi_prep_args is called by the assembly routine once stack space
|
||||||
|
has been allocated for the function's arguments */
|
||||||
|
|
||||||
|
int FFI_HIDDEN
|
||||||
|
ffi_prep_args_v9(ffi_cif *cif, unsigned long *argp, void *rvalue, void **avalue)
|
||||||
|
{
|
||||||
|
ffi_type **p_arg;
|
||||||
|
int flags = cif->flags;
|
||||||
|
int i, nargs;
|
||||||
|
|
||||||
|
if (rvalue == NULL)
|
||||||
|
{
|
||||||
|
if (flags & SPARC_FLAG_RET_IN_MEM)
|
||||||
|
{
|
||||||
|
/* Since we pass the pointer to the callee, we need a value.
|
||||||
|
We allowed for this space in ffi_call, before ffi_call_v8
|
||||||
|
alloca'd the space. */
|
||||||
|
rvalue = (char *)argp + cif->bytes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Otherwise, we can ignore the return value. */
|
||||||
|
flags = SPARC_RET_VOID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USING_PURIFY
|
||||||
|
/* Purify will probably complain in our assembly routine,
|
||||||
|
unless we zero out this memory. */
|
||||||
|
memset(argp, 0, 6*8);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (flags & SPARC_FLAG_RET_IN_MEM)
|
||||||
|
*argp++ = (unsigned long)rvalue;
|
||||||
|
|
||||||
|
p_arg = cif->arg_types;
|
||||||
|
for (i = 0, nargs = cif->nargs; i < nargs; i++)
|
||||||
|
{
|
||||||
|
ffi_type *ty = p_arg[i];
|
||||||
|
void *a = avalue[i];
|
||||||
|
size_t z;
|
||||||
|
|
||||||
|
switch (ty->type)
|
||||||
|
{
|
||||||
|
case FFI_TYPE_SINT8:
|
||||||
|
*argp++ = *(SINT8 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT8:
|
||||||
|
*argp++ = *(UINT8 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_SINT16:
|
||||||
|
*argp++ = *(SINT16 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
*argp++ = *(UINT16 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_INT:
|
||||||
|
case FFI_TYPE_SINT32:
|
||||||
|
*argp++ = *(SINT32 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT32:
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
*argp++ = *(UINT32 *)a;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_SINT64:
|
||||||
|
case FFI_TYPE_UINT64:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
*argp++ = *(UINT64 *)a;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
z = ty->size;
|
||||||
|
if (z > 16)
|
||||||
|
{
|
||||||
|
/* For structures larger than 16 bytes we pass reference. */
|
||||||
|
*argp++ = (unsigned long)a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (((unsigned long)argp & 15) && ty->alignment > 8)
|
||||||
|
argp++;
|
||||||
|
memcpy(argp, a, z);
|
||||||
|
argp += ALIGN(z, 8) / 8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
|
||||||
|
{
|
||||||
|
size_t bytes = cif->bytes;
|
||||||
|
|
||||||
|
FFI_ASSERT (cif->abi == FFI_V9);
|
||||||
|
|
||||||
|
if (rvalue == NULL && (cif->flags & SPARC_FLAG_RET_IN_MEM))
|
||||||
|
bytes += ALIGN (cif->rtype->size, 16);
|
||||||
|
|
||||||
|
ffi_call_v9(cif, fn, rvalue, avalue, -bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
static inline void
|
||||||
|
ffi_flush_icache (void *p)
|
||||||
|
{
|
||||||
|
asm volatile ("flush %0; flush %0+8" : : "r" (p) : "memory");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
extern void ffi_flush_icache (void *) FFI_HIDDEN;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void ffi_closure_v9(void) FFI_HIDDEN;
|
||||||
|
|
||||||
|
ffi_status
|
||||||
|
ffi_prep_closure_loc (ffi_closure* closure,
|
||||||
|
ffi_cif* cif,
|
||||||
|
void (*fun)(ffi_cif*, void*, void**, void*),
|
||||||
|
void *user_data,
|
||||||
|
void *codeloc)
|
||||||
|
{
|
||||||
|
unsigned int *tramp = (unsigned int *) &closure->tramp[0];
|
||||||
|
unsigned long fn;
|
||||||
|
|
||||||
|
if (cif->abi != FFI_V9)
|
||||||
|
return FFI_BAD_ABI;
|
||||||
|
|
||||||
|
/* Trampoline address is equal to the closure address. We take advantage
|
||||||
|
of that to reduce the trampoline size by 8 bytes. */
|
||||||
|
fn = (unsigned long) ffi_closure_v9;
|
||||||
|
tramp[0] = 0x83414000; /* rd %pc, %g1 */
|
||||||
|
tramp[1] = 0xca586010; /* ldx [%g1+16], %g5 */
|
||||||
|
tramp[2] = 0x81c14000; /* jmp %g5 */
|
||||||
|
tramp[3] = 0x01000000; /* nop */
|
||||||
|
*((unsigned long *) &tramp[4]) = fn;
|
||||||
|
|
||||||
|
closure->cif = cif;
|
||||||
|
closure->fun = fun;
|
||||||
|
closure->user_data = user_data;
|
||||||
|
|
||||||
|
ffi_flush_icache (closure);
|
||||||
|
|
||||||
|
return FFI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FFI_HIDDEN
|
||||||
|
ffi_closure_sparc_inner_v9(ffi_closure *closure, void *rvalue,
|
||||||
|
unsigned long *gpr, unsigned long *fpr)
|
||||||
|
{
|
||||||
|
ffi_cif *cif;
|
||||||
|
ffi_type **arg_types;
|
||||||
|
void **avalue;
|
||||||
|
int i, argn, nargs, flags;
|
||||||
|
|
||||||
|
cif = closure->cif;
|
||||||
|
arg_types = cif->arg_types;
|
||||||
|
nargs = cif->nargs;
|
||||||
|
flags = cif->flags;
|
||||||
|
|
||||||
|
avalue = alloca(nargs * sizeof(void *));
|
||||||
|
|
||||||
|
/* Copy the caller's structure return address so that the closure
|
||||||
|
returns the data directly to the caller. */
|
||||||
|
if (flags & SPARC_FLAG_RET_IN_MEM)
|
||||||
|
{
|
||||||
|
rvalue = (void *) gpr[0];
|
||||||
|
/* Skip the structure return address. */
|
||||||
|
argn = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
argn = 0;
|
||||||
|
|
||||||
|
/* Grab the addresses of the arguments from the stack frame. */
|
||||||
|
for (i = 0; i < nargs; i++)
|
||||||
|
{
|
||||||
|
ffi_type *ty = arg_types[i];
|
||||||
|
void *a = &gpr[argn++];
|
||||||
|
size_t z;
|
||||||
|
|
||||||
|
switch (ty->type)
|
||||||
|
{
|
||||||
|
case FFI_TYPE_STRUCT:
|
||||||
|
z = ty->size;
|
||||||
|
if (z > 16)
|
||||||
|
a = *(void **)a;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (--argn < 16)
|
||||||
|
ffi_v9_layout_struct(arg_types[i], 8*argn, gpr, gpr, fpr);
|
||||||
|
argn += ALIGN (z, 8) / 8;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_LONGDOUBLE:
|
||||||
|
if (--argn & 1)
|
||||||
|
argn++;
|
||||||
|
a = (argn < 16 ? fpr : gpr) + argn;
|
||||||
|
argn += 2;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_DOUBLE:
|
||||||
|
if (argn <= 16)
|
||||||
|
a = fpr + argn - 1;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_FLOAT:
|
||||||
|
if (argn <= 16)
|
||||||
|
a = fpr + argn - 1;
|
||||||
|
a += 4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FFI_TYPE_UINT64:
|
||||||
|
case FFI_TYPE_SINT64:
|
||||||
|
case FFI_TYPE_POINTER:
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_INT:
|
||||||
|
case FFI_TYPE_UINT32:
|
||||||
|
case FFI_TYPE_SINT32:
|
||||||
|
a += 4;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT16:
|
||||||
|
case FFI_TYPE_SINT16:
|
||||||
|
a += 6;
|
||||||
|
break;
|
||||||
|
case FFI_TYPE_UINT8:
|
||||||
|
case FFI_TYPE_SINT8:
|
||||||
|
a += 7;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
avalue[i] = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Invoke the closure. */
|
||||||
|
(closure->fun) (cif, rvalue, avalue, closure->user_data);
|
||||||
|
|
||||||
|
/* Tell ffi_closure_sparc how to perform return type promotions. */
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
#endif /* SPARC64 */
|
||||||
@@ -46,18 +46,19 @@ typedef signed long ffi_sarg;
|
|||||||
|
|
||||||
typedef enum ffi_abi {
|
typedef enum ffi_abi {
|
||||||
FFI_FIRST_ABI = 0,
|
FFI_FIRST_ABI = 0,
|
||||||
FFI_V8,
|
|
||||||
FFI_V8PLUS,
|
|
||||||
FFI_V9,
|
|
||||||
FFI_LAST_ABI,
|
|
||||||
#ifdef SPARC64
|
#ifdef SPARC64
|
||||||
FFI_DEFAULT_ABI = FFI_V9
|
FFI_V9,
|
||||||
|
FFI_DEFAULT_ABI = FFI_V9,
|
||||||
#else
|
#else
|
||||||
FFI_DEFAULT_ABI = FFI_V8
|
FFI_V8,
|
||||||
|
FFI_DEFAULT_ABI = FFI_V8,
|
||||||
#endif
|
#endif
|
||||||
|
FFI_LAST_ABI
|
||||||
} ffi_abi;
|
} ffi_abi;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define FFI_TARGET_SPECIFIC_STACK_SPACE_ALLOCATION
|
||||||
|
|
||||||
/* ---- Definitions for closures ----------------------------------------- */
|
/* ---- Definitions for closures ----------------------------------------- */
|
||||||
|
|
||||||
#define FFI_CLOSURES 1
|
#define FFI_CLOSURES 1
|
||||||
|
|||||||
18
src/sparc/internal.h
Normal file
18
src/sparc/internal.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#define SPARC_RET_VOID 0
|
||||||
|
#define SPARC_RET_STRUCT 1
|
||||||
|
#define SPARC_RET_FLOAT 2
|
||||||
|
#define SPARC_RET_DOUBLE 3
|
||||||
|
#define SPARC_RET_UINT8 4
|
||||||
|
#define SPARC_RET_SINT8 5
|
||||||
|
#define SPARC_RET_UINT16 6
|
||||||
|
#define SPARC_RET_SINT16 7
|
||||||
|
#define SPARC_RET_INT64 8
|
||||||
|
#define SPARC_RET_UINT32 9
|
||||||
|
|
||||||
|
/* These two are only used for V9. */
|
||||||
|
#define SPARC_RET_SINT32 10
|
||||||
|
#define SPARC_RET_LDOUBLE 11
|
||||||
|
|
||||||
|
#define SPARC_FLAG_RET_MASK 15
|
||||||
|
#define SPARC_FLAG_RET_IN_MEM 32
|
||||||
|
#define SPARC_FLAG_FP_ARGS 64
|
||||||
301
src/sparc/v8.S
301
src/sparc/v8.S
@@ -29,9 +29,9 @@
|
|||||||
#include <fficonfig.h>
|
#include <fficonfig.h>
|
||||||
#include <ffi.h>
|
#include <ffi.h>
|
||||||
#include <ffi_cfi.h>
|
#include <ffi_cfi.h>
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
#define STACKFRAME 96 /* Minimum stack framesize for SPARC */
|
#ifndef SPARC64
|
||||||
#define ARGS (64+4) /* Offset of register area in frame */
|
|
||||||
|
|
||||||
#define C2(X, Y) X ## Y
|
#define C2(X, Y) X ## Y
|
||||||
#define C1(X, Y) C2(X, Y)
|
#define C1(X, Y) C2(X, Y)
|
||||||
@@ -53,26 +53,24 @@
|
|||||||
|
|
||||||
C(ffi_flush_icache):
|
C(ffi_flush_icache):
|
||||||
cfi_startproc
|
cfi_startproc
|
||||||
add %o0, %o1, %o2
|
|
||||||
#ifdef SPARC64
|
|
||||||
1: flush %o0
|
|
||||||
#else
|
|
||||||
1: iflush %o0
|
1: iflush %o0
|
||||||
#endif
|
iflush %o+8
|
||||||
add %o0, 8, %o0
|
|
||||||
cmp %o0, %o2
|
|
||||||
blt 1b
|
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
retl
|
retl
|
||||||
nop
|
nop
|
||||||
cfi_endproc
|
cfi_endproc
|
||||||
.size C(ffi_flush_icache), . - C(ffi_flush_icache)
|
.size C(ffi_flush_icache), . - C(ffi_flush_icache)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
.macro E index
|
||||||
|
.align 16
|
||||||
|
.org 2b + \index * 16
|
||||||
|
.endm
|
||||||
|
|
||||||
.align 8
|
.align 8
|
||||||
.globl C(ffi_call_v8)
|
.globl C(ffi_call_v8)
|
||||||
.type C(ffi_call_v8),@function
|
.type C(ffi_call_v8),@function
|
||||||
@@ -80,104 +78,104 @@ C(ffi_flush_icache):
|
|||||||
|
|
||||||
C(ffi_call_v8):
|
C(ffi_call_v8):
|
||||||
cfi_startproc
|
cfi_startproc
|
||||||
save %sp, -STACKFRAME, %sp
|
! Allocate a stack frame sized by ffi_call.
|
||||||
|
save %sp, %o4, %sp
|
||||||
cfi_def_cfa_register(%fp)
|
cfi_def_cfa_register(%fp)
|
||||||
cfi_window_save
|
cfi_window_save
|
||||||
|
|
||||||
sub %sp, %i2, %sp ! alloca() space in stack for frame to set up
|
|
||||||
add %sp, STACKFRAME, %l0 ! %l0 has start of
|
|
||||||
! frame to set up
|
|
||||||
|
|
||||||
mov %l0, %o0 ! call routine to set up frame
|
mov %i0, %o0 ! copy cif
|
||||||
call %i0
|
add %sp, 64+32, %o1 ! load args area
|
||||||
mov %i1, %o1 ! (delay)
|
mov %i2, %o2 ! copy rvalue
|
||||||
|
call C(ffi_prep_args_v8)
|
||||||
|
mov %i3, %o3 ! copy avalue
|
||||||
|
|
||||||
ld [%l0+ARGS], %o0 ! call foreign function
|
add %sp, 32, %sp ! deallocate prep frame
|
||||||
ld [%l0+ARGS+4], %o1
|
and %o0, SPARC_FLAG_RET_MASK, %l0 ! save return type
|
||||||
ld [%l0+ARGS+8], %o2
|
ld [%sp+64+4], %o0 ! load all argument registers
|
||||||
ld [%l0+ARGS+12], %o3
|
ld [%sp+64+8], %o1
|
||||||
ld [%l0+ARGS+16], %o4
|
ld [%sp+64+12], %o2
|
||||||
ld [%l0+ARGS+20], %o5
|
ld [%sp+64+16], %o3
|
||||||
call %i5
|
cmp %l0, SPARC_RET_STRUCT ! struct return needs an unimp 4
|
||||||
mov %l0, %sp ! (delay) switch to frame
|
ld [%sp+64+20], %o4
|
||||||
nop ! STRUCT returning functions skip 12 instead of 8 bytes
|
be 8f
|
||||||
|
ld [%sp+64+24], %o5
|
||||||
|
|
||||||
! If the return value pointer is NULL, assume no return value.
|
! Call foreign function
|
||||||
tst %i4
|
call %i1
|
||||||
bz L(done)
|
nop
|
||||||
|
|
||||||
|
0: call 1f ! load pc in %o7
|
||||||
|
sll %l0, 4, %l0
|
||||||
|
1: add %o7, %l0, %o7 ! o7 = 0b + ret_type*16
|
||||||
|
jmp %o7+(2f-0b)
|
||||||
|
nop
|
||||||
|
|
||||||
|
! Note that each entry is 4 insns, enforced by the E macro.
|
||||||
|
.align 16
|
||||||
|
2:
|
||||||
|
E SPARC_RET_VOID
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_STRUCT
|
||||||
|
unimp
|
||||||
|
E SPARC_RET_FLOAT
|
||||||
|
st %f0, [%i2]
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_DOUBLE
|
||||||
|
std %f0, [%i2]
|
||||||
|
ret
|
||||||
|
restore
|
||||||
nop
|
nop
|
||||||
|
E SPARC_RET_UINT8
|
||||||
cmp %i3, FFI_TYPE_INT
|
and %o0, 0xff, %o0
|
||||||
be,a L(done)
|
st %o0, [%i2]
|
||||||
st %o0, [%i4] ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_FLOAT
|
|
||||||
be,a L(done)
|
|
||||||
st %f0, [%i4+0] ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_DOUBLE
|
|
||||||
be,a L(double)
|
|
||||||
st %f0, [%i4+0] ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_SINT8
|
|
||||||
be,a L(sint8)
|
|
||||||
sll %o0, 24, %o0 ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_UINT8
|
|
||||||
be,a L(uint8)
|
|
||||||
sll %o0, 24, %o0 ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_SINT16
|
|
||||||
be,a L(sint16)
|
|
||||||
sll %o0, 16, %o0 ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_UINT16
|
|
||||||
be,a L(uint16)
|
|
||||||
sll %o0, 16, %o0 ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_SINT64
|
|
||||||
be,a L(longlong)
|
|
||||||
st %o0, [%i4+0] ! (delay)
|
|
||||||
|
|
||||||
L(done):
|
|
||||||
ret
|
ret
|
||||||
restore
|
restore
|
||||||
|
E SPARC_RET_SINT8
|
||||||
L(double):
|
sll %o0, 24, %o0
|
||||||
st %f1, [%i4+4]
|
b 7f
|
||||||
|
sra %o0, 24, %o0
|
||||||
|
E SPARC_RET_UINT16
|
||||||
|
sll %o0, 16, %o0
|
||||||
|
b 7f
|
||||||
|
srl %o0, 16, %o0
|
||||||
|
E SPARC_RET_SINT16
|
||||||
|
sll %o0, 16, %o0
|
||||||
|
b 7f
|
||||||
|
sra %o0, 16, %o0
|
||||||
|
E SPARC_RET_INT64
|
||||||
|
std %o0, [%i2]
|
||||||
ret
|
ret
|
||||||
restore
|
restore
|
||||||
|
E SPARC_RET_UINT32
|
||||||
L(sint8):
|
7: st %o0, [%i2]
|
||||||
sra %o0, 24, %o0
|
|
||||||
st %o0, [%i4+0]
|
|
||||||
ret
|
ret
|
||||||
restore
|
restore
|
||||||
|
|
||||||
L(uint8):
|
! Unused entries. Don't allow bad data to do worse things.
|
||||||
srl %o0, 24, %o0
|
E 10
|
||||||
st %o0, [%i4+0]
|
unimp
|
||||||
ret
|
E 11
|
||||||
restore
|
unimp
|
||||||
|
E 12
|
||||||
|
unimp
|
||||||
|
E 13
|
||||||
|
unimp
|
||||||
|
E 14
|
||||||
|
unimp
|
||||||
|
E 15
|
||||||
|
unimp
|
||||||
|
|
||||||
L(sint16):
|
! Struct returning functions expect and skip the unimp here.
|
||||||
sra %o0, 16, %o0
|
.align 8
|
||||||
st %o0, [%i4+0]
|
8: call %i1
|
||||||
|
nop
|
||||||
|
unimp 4
|
||||||
ret
|
ret
|
||||||
restore
|
restore
|
||||||
|
|
||||||
L(uint16):
|
|
||||||
srl %o0, 16, %o0
|
|
||||||
st %o0, [%i4+0]
|
|
||||||
ret
|
|
||||||
restore
|
|
||||||
|
|
||||||
L(longlong):
|
|
||||||
st %o1, [%i4+4]
|
|
||||||
ret
|
|
||||||
restore
|
|
||||||
cfi_endproc
|
cfi_endproc
|
||||||
|
|
||||||
.size C(ffi_call_v8),. - C(ffi_call_v8)
|
.size C(ffi_call_v8),. - C(ffi_call_v8)
|
||||||
|
|
||||||
|
|
||||||
@@ -185,7 +183,8 @@ L(longlong):
|
|||||||
#define STACKFRAME 104 /* 16*4 register window +
|
#define STACKFRAME 104 /* 16*4 register window +
|
||||||
1*4 struct return +
|
1*4 struct return +
|
||||||
6*4 args backing store +
|
6*4 args backing store +
|
||||||
3*4 locals */
|
2*4 return storage +
|
||||||
|
1*4 alignment */
|
||||||
|
|
||||||
/* ffi_closure_v8(...)
|
/* ffi_closure_v8(...)
|
||||||
|
|
||||||
@@ -201,15 +200,7 @@ C(ffi_closure_v8):
|
|||||||
.register %g2, #scratch
|
.register %g2, #scratch
|
||||||
#endif
|
#endif
|
||||||
cfi_startproc
|
cfi_startproc
|
||||||
! Reserve frame space for all arguments in case
|
save %sp, -STACKFRAME, %sp
|
||||||
! we need to align them on a 8-byte boundary.
|
|
||||||
ld [%g2+FFI_TRAMPOLINE_SIZE], %g1
|
|
||||||
ld [%g1+4], %g1
|
|
||||||
sll %g1, 3, %g1
|
|
||||||
add %g1, STACKFRAME, %g1
|
|
||||||
! %g1 == STACKFRAME + 8*nargs
|
|
||||||
neg %g1
|
|
||||||
save %sp, %g1, %sp
|
|
||||||
cfi_def_cfa_register(%fp)
|
cfi_def_cfa_register(%fp)
|
||||||
cfi_window_save
|
cfi_window_save
|
||||||
|
|
||||||
@@ -224,55 +215,75 @@ C(ffi_closure_v8):
|
|||||||
! Call ffi_closure_sparc_inner to do the bulk of the work.
|
! Call ffi_closure_sparc_inner to do the bulk of the work.
|
||||||
mov %g2, %o0
|
mov %g2, %o0
|
||||||
add %fp, -8, %o1
|
add %fp, -8, %o1
|
||||||
add %fp, 64, %o2
|
|
||||||
call ffi_closure_sparc_inner_v8
|
call ffi_closure_sparc_inner_v8
|
||||||
add %fp, -16, %o3
|
add %fp, 64, %o2
|
||||||
|
|
||||||
! Load up the return value in the proper type.
|
0: call 1f
|
||||||
! See ffi_prep_cif_machdep for the list of cases.
|
and %o0, SPARC_FLAG_RET_MASK, %o0
|
||||||
cmp %o0, FFI_TYPE_VOID
|
1: sll %o0, 4, %o0 ! o0 = o0 * 16
|
||||||
be L(done1)
|
add %o7, %o0, %o7 ! o7 = 0b + o0*16
|
||||||
|
jmp %o7+(2f-0b)
|
||||||
|
nop
|
||||||
|
|
||||||
cmp %o0, FFI_TYPE_INT
|
! Note that each entry is 4 insns, enforced by the E macro.
|
||||||
be L(done1)
|
.align 16
|
||||||
ld [%fp-8], %i0
|
2:
|
||||||
|
E SPARC_RET_VOID
|
||||||
cmp %o0, FFI_TYPE_FLOAT
|
ret
|
||||||
be,a L(done1)
|
|
||||||
ld [%fp-8], %f0
|
|
||||||
|
|
||||||
cmp %o0, FFI_TYPE_DOUBLE
|
|
||||||
be,a L(done1)
|
|
||||||
ldd [%fp-8], %f0
|
|
||||||
|
|
||||||
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
|
||||||
cmp %o0, FFI_TYPE_LONGDOUBLE
|
|
||||||
be L(done2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cmp %o0, FFI_TYPE_STRUCT
|
|
||||||
be L(done2)
|
|
||||||
|
|
||||||
cmp %o0, FFI_TYPE_SINT64
|
|
||||||
be,a L(done1)
|
|
||||||
ldd [%fp-8], %i0
|
|
||||||
|
|
||||||
cmp %o0, FFI_TYPE_UINT64
|
|
||||||
be,a L(done1)
|
|
||||||
ldd [%fp-8], %i0
|
|
||||||
|
|
||||||
ld [%fp-8], %i0
|
|
||||||
L(done1):
|
|
||||||
jmp %i7+8
|
|
||||||
restore
|
restore
|
||||||
L(done2):
|
E SPARC_RET_STRUCT
|
||||||
! Skip 'unimp'.
|
|
||||||
jmp %i7+12
|
jmp %i7+12
|
||||||
restore
|
restore
|
||||||
|
E SPARC_RET_FLOAT
|
||||||
|
ld [%fp-8], %f0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_DOUBLE
|
||||||
|
ldd [%fp-8], %f0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_UINT8
|
||||||
|
ldub [%fp-8+3], %i0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_SINT8
|
||||||
|
ldsb [%fp-8+3], %i0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_UINT16
|
||||||
|
lduh [%fp-8+2], %i0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_SINT16
|
||||||
|
ldsh [%fp-8+2], %i0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_INT64
|
||||||
|
ldd [%fp-8], %i0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
E SPARC_RET_UINT32
|
||||||
|
ld [%fp-8], %i0
|
||||||
|
ret
|
||||||
|
restore
|
||||||
|
|
||||||
|
! Unused entries. Don't allow bad data to do worse things.
|
||||||
|
E 10
|
||||||
|
unimp
|
||||||
|
E 11
|
||||||
|
unimp
|
||||||
|
E 12
|
||||||
|
unimp
|
||||||
|
E 13
|
||||||
|
unimp
|
||||||
|
E 14
|
||||||
|
unimp
|
||||||
|
E 15
|
||||||
|
unimp
|
||||||
|
|
||||||
cfi_endproc
|
cfi_endproc
|
||||||
.size C(ffi_closure_v8), . - C(ffi_closure_v8)
|
.size C(ffi_closure_v8), . - C(ffi_closure_v8)
|
||||||
|
#endif /* !SPARC64 */
|
||||||
#if defined __ELF__ && defined __linux__
|
#if defined __ELF__ && defined __linux__
|
||||||
.section .note.GNU-stack,"",@progbits
|
.section .note.GNU-stack,"",@progbits
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
314
src/sparc/v9.S
314
src/sparc/v9.S
@@ -28,10 +28,9 @@
|
|||||||
#include <fficonfig.h>
|
#include <fficonfig.h>
|
||||||
#include <ffi.h>
|
#include <ffi.h>
|
||||||
#include <ffi_cfi.h>
|
#include <ffi_cfi.h>
|
||||||
|
#include "internal.h"
|
||||||
|
|
||||||
#ifdef SPARC64
|
#ifdef SPARC64
|
||||||
/* Only compile this in for 64bit builds, because otherwise the object file
|
|
||||||
will have inproper architecture due to used instructions. */
|
|
||||||
|
|
||||||
#define C2(X, Y) X ## Y
|
#define C2(X, Y) X ## Y
|
||||||
#define C1(X, Y) C2(X, Y)
|
#define C1(X, Y) C2(X, Y)
|
||||||
@@ -43,12 +42,14 @@
|
|||||||
#endif
|
#endif
|
||||||
#define L(Y) C1(.L, Y)
|
#define L(Y) C1(.L, Y)
|
||||||
|
|
||||||
|
.macro E index
|
||||||
|
.align 16
|
||||||
|
.org 2b + \index * 16
|
||||||
|
.endm
|
||||||
|
|
||||||
#define STACKFRAME 176 /* Minimum stack framesize for SPARC 64-bit */
|
|
||||||
#define STACK_BIAS 2047
|
#define STACK_BIAS 2047
|
||||||
#define ARGS (128) /* Offset of register area in frame */
|
|
||||||
|
|
||||||
.text
|
.text
|
||||||
.align 8
|
.align 8
|
||||||
.globl C(ffi_call_v9)
|
.globl C(ffi_call_v9)
|
||||||
.type C(ffi_call_v9),@function
|
.type C(ffi_call_v9),@function
|
||||||
@@ -56,86 +57,135 @@
|
|||||||
|
|
||||||
C(ffi_call_v9):
|
C(ffi_call_v9):
|
||||||
cfi_startproc
|
cfi_startproc
|
||||||
save %sp, -STACKFRAME, %sp
|
save %sp, %o4, %sp
|
||||||
cfi_def_cfa_register(%fp)
|
cfi_def_cfa_register(%fp)
|
||||||
cfi_window_save
|
cfi_window_save
|
||||||
|
|
||||||
sub %sp, %i2, %sp ! alloca() space in stack for frame to set up
|
mov %i0, %o0 ! copy cif
|
||||||
add %sp, STACKFRAME+STACK_BIAS, %l0 ! %l0 has start of
|
add %sp, STACK_BIAS+128+48, %o1 ! load args area
|
||||||
! frame to set up
|
mov %i2, %o2 ! copy rvalue
|
||||||
|
call C(ffi_prep_args_v9)
|
||||||
|
mov %i3, %o3 ! copy avalue
|
||||||
|
|
||||||
mov %l0, %o0 ! call routine to set up frame
|
andcc %o0, SPARC_FLAG_FP_ARGS, %g0 ! need fp regs?
|
||||||
call %i0
|
add %sp, 48, %sp ! deallocate prep frame
|
||||||
mov %i1, %o1 ! (delay)
|
be,pt %xcc, 1f
|
||||||
brz,pt %o0, 1f
|
mov %o0, %l0 ! save flags
|
||||||
ldx [%l0+ARGS], %o0 ! call foreign function
|
|
||||||
|
|
||||||
ldd [%l0+ARGS], %f0
|
ldd [%sp+STACK_BIAS+128], %f0 ! load all fp arg regs
|
||||||
ldd [%l0+ARGS+8], %f2
|
ldd [%sp+STACK_BIAS+128+8], %f2
|
||||||
ldd [%l0+ARGS+16], %f4
|
ldd [%sp+STACK_BIAS+128+16], %f4
|
||||||
ldd [%l0+ARGS+24], %f6
|
ldd [%sp+STACK_BIAS+128+24], %f6
|
||||||
ldd [%l0+ARGS+32], %f8
|
ldd [%sp+STACK_BIAS+128+32], %f8
|
||||||
ldd [%l0+ARGS+40], %f10
|
ldd [%sp+STACK_BIAS+128+40], %f10
|
||||||
ldd [%l0+ARGS+48], %f12
|
ldd [%sp+STACK_BIAS+128+48], %f12
|
||||||
ldd [%l0+ARGS+56], %f14
|
ldd [%sp+STACK_BIAS+128+56], %f14
|
||||||
ldd [%l0+ARGS+64], %f16
|
ldd [%sp+STACK_BIAS+128+64], %f16
|
||||||
ldd [%l0+ARGS+72], %f18
|
ldd [%sp+STACK_BIAS+128+72], %f18
|
||||||
ldd [%l0+ARGS+80], %f20
|
ldd [%sp+STACK_BIAS+128+80], %f20
|
||||||
ldd [%l0+ARGS+88], %f22
|
ldd [%sp+STACK_BIAS+128+88], %f22
|
||||||
ldd [%l0+ARGS+96], %f24
|
ldd [%sp+STACK_BIAS+128+96], %f24
|
||||||
ldd [%l0+ARGS+104], %f26
|
ldd [%sp+STACK_BIAS+128+104], %f26
|
||||||
ldd [%l0+ARGS+112], %f28
|
ldd [%sp+STACK_BIAS+128+112], %f28
|
||||||
ldd [%l0+ARGS+120], %f30
|
ldd [%sp+STACK_BIAS+128+120], %f30
|
||||||
|
|
||||||
1: ldx [%l0+ARGS+8], %o1
|
1: ldx [%sp+STACK_BIAS+128], %o0 ! load all int arg regs
|
||||||
ldx [%l0+ARGS+16], %o2
|
ldx [%sp+STACK_BIAS+128+8], %o1
|
||||||
ldx [%l0+ARGS+24], %o3
|
ldx [%sp+STACK_BIAS+128+16], %o2
|
||||||
ldx [%l0+ARGS+32], %o4
|
ldx [%sp+STACK_BIAS+128+24], %o3
|
||||||
ldx [%l0+ARGS+40], %o5
|
ldx [%sp+STACK_BIAS+128+32], %o4
|
||||||
call %i5
|
call %i1
|
||||||
sub %l0, STACK_BIAS, %sp ! (delay) switch to frame
|
ldx [%sp+STACK_BIAS+128+40], %o5
|
||||||
|
|
||||||
! If the return value pointer is NULL, assume no return value.
|
0: call 1f ! load pc in %o7
|
||||||
brz,pn %i4, L(done)
|
and %l0, SPARC_FLAG_RET_MASK, %l1
|
||||||
|
1: sll %l1, 4, %l1
|
||||||
|
add %o7, %l1, %o7 ! o7 = 0b + ret_type*16
|
||||||
|
jmp %o7+(2f-0b)
|
||||||
nop
|
nop
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_INT
|
.align 16
|
||||||
be,a,pt %icc, L(done)
|
2:
|
||||||
stx %o0, [%i4+0] ! (delay)
|
E SPARC_RET_VOID
|
||||||
|
return %i7+8
|
||||||
cmp %i3, FFI_TYPE_FLOAT
|
|
||||||
be,a,pn %icc, L(done)
|
|
||||||
st %f0, [%i4+0] ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_DOUBLE
|
|
||||||
be,a,pn %icc, L(done)
|
|
||||||
std %f0, [%i4+0] ! (delay)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_STRUCT
|
|
||||||
be,pn %icc, L(dostruct)
|
|
||||||
|
|
||||||
cmp %i3, FFI_TYPE_LONGDOUBLE
|
|
||||||
bne,pt %icc, L(done)
|
|
||||||
nop
|
nop
|
||||||
std %f0, [%i4+0]
|
E SPARC_RET_STRUCT
|
||||||
std %f2, [%i4+8]
|
add %sp, STACK_BIAS-64+128+48, %l2
|
||||||
|
sub %sp, 64, %sp
|
||||||
|
b 8f
|
||||||
|
stx %o0, [%l2]
|
||||||
|
E SPARC_RET_FLOAT
|
||||||
|
return %i7+8
|
||||||
|
st %f0, [%o2]
|
||||||
|
E SPARC_RET_DOUBLE
|
||||||
|
return %i7+8
|
||||||
|
std %f0, [%o2]
|
||||||
|
E SPARC_RET_UINT8
|
||||||
|
and %o0, 0xff, %i0
|
||||||
|
return %i7+8
|
||||||
|
stx %o0, [%o2]
|
||||||
|
E SPARC_RET_SINT8
|
||||||
|
sll %o0, 24, %o0
|
||||||
|
sra %o0, 24, %i0
|
||||||
|
return %i7+8
|
||||||
|
stx %o0, [%o2]
|
||||||
|
E SPARC_RET_UINT16
|
||||||
|
sll %o0, 16, %o0
|
||||||
|
srl %o0, 16, %i0
|
||||||
|
return %i7+8
|
||||||
|
stx %o0, [%o2]
|
||||||
|
E SPARC_RET_SINT16
|
||||||
|
sll %o0, 16, %o0
|
||||||
|
sra %o0, 16, %i0
|
||||||
|
return %i7+8
|
||||||
|
stx %o0, [%o2]
|
||||||
|
E SPARC_RET_INT64
|
||||||
|
stx %o0, [%i2]
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_UINT32
|
||||||
|
srl %o0, 0, %i0
|
||||||
|
return %i7+8
|
||||||
|
stx %o0, [%o2]
|
||||||
|
E SPARC_RET_SINT32
|
||||||
|
sra %o0, 0, %i0
|
||||||
|
return %i7+8
|
||||||
|
stx %o0, [%o2]
|
||||||
|
E SPARC_RET_LDOUBLE
|
||||||
|
std %f0, [%i2]
|
||||||
|
return %i7+8
|
||||||
|
std %f2, [%o2+8]
|
||||||
|
|
||||||
L(done):
|
! Unused entries. Don't allow bad data to do worse things.
|
||||||
ret
|
E 12
|
||||||
restore
|
unimp
|
||||||
|
E 13
|
||||||
|
unimp
|
||||||
|
E 14
|
||||||
|
unimp
|
||||||
|
E 15
|
||||||
|
unimp
|
||||||
|
|
||||||
L(dostruct):
|
! Finish the SPARC_RET_STRUCT sequence.
|
||||||
/* This will not work correctly for unions. */
|
.align 8
|
||||||
stx %o0, [%i4+0]
|
8: stx %o1, [%l2+8]
|
||||||
stx %o1, [%i4+8]
|
stx %o2, [%l2+16]
|
||||||
stx %o2, [%i4+16]
|
stx %o3, [%l2+24]
|
||||||
stx %o3, [%i4+24]
|
std %f0, [%l2+32]
|
||||||
std %f0, [%i4+32]
|
std %f2, [%l2+40]
|
||||||
std %f2, [%i4+40]
|
std %f4, [%l2+48]
|
||||||
std %f4, [%i4+48]
|
std %f6, [%l2+56]
|
||||||
std %f6, [%i4+56]
|
|
||||||
ret
|
! Copy the structure into place.
|
||||||
restore
|
ldx [%i0+16], %o0 ! load rtype from cif
|
||||||
|
mov 0, %o1 ! load off
|
||||||
|
mov %i2, %o2 ! load dst
|
||||||
|
mov %l2, %o3 ! load src_int
|
||||||
|
call C(ffi_v9_layout_struct)
|
||||||
|
add %l2, 32, %o4 ! load src_fp
|
||||||
|
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
|
||||||
cfi_endproc
|
cfi_endproc
|
||||||
.size C(ffi_call_v9), . - C(ffi_call_v9)
|
.size C(ffi_call_v9), . - C(ffi_call_v9)
|
||||||
@@ -195,54 +245,90 @@ C(ffi_closure_v9):
|
|||||||
call C(ffi_closure_sparc_inner_v9)
|
call C(ffi_closure_sparc_inner_v9)
|
||||||
add %fp, STACK_BIAS-128, %o3
|
add %fp, STACK_BIAS-128, %o3
|
||||||
|
|
||||||
! Load up the return value in the proper type.
|
0: call 1f ! load pc in %o7
|
||||||
! See ffi_prep_cif_machdep for the list of cases.
|
and %o0, SPARC_FLAG_RET_MASK, %o0
|
||||||
cmp %o0, FFI_TYPE_VOID
|
1: sll %o0, 4, %o0 ! o2 = i2 * 16
|
||||||
be,pn %icc, L(done1)
|
add %o7, %o0, %o7 ! o7 = 0b + i2*16
|
||||||
|
jmp %o7+(2f-0b)
|
||||||
|
nop
|
||||||
|
|
||||||
cmp %o0, FFI_TYPE_INT
|
! Note that we cannot load the data in the delay slot of
|
||||||
be,pn %icc, L(integer)
|
! the return insn because the data is in the stack frame
|
||||||
|
! that is deallocated by the return.
|
||||||
cmp %o0, FFI_TYPE_FLOAT
|
.align 16
|
||||||
be,a,pn %icc, L(done1)
|
2:
|
||||||
ld [FP-160], %f0
|
E SPARC_RET_VOID
|
||||||
|
return %i7+8
|
||||||
cmp %o0, FFI_TYPE_DOUBLE
|
nop
|
||||||
be,a,pn %icc, L(done1)
|
E SPARC_RET_STRUCT
|
||||||
ldd [FP-160], %f0
|
|
||||||
|
|
||||||
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
|
||||||
cmp %o0, FFI_TYPE_LONGDOUBLE
|
|
||||||
be,a,pn %icc, L(longdouble1)
|
|
||||||
ldd [FP-160], %f0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
! FFI_TYPE_STRUCT
|
|
||||||
ldx [FP-152], %i1
|
|
||||||
ldx [FP-144], %i2
|
|
||||||
ldx [FP-136], %i3
|
|
||||||
ldd [FP-160], %f0
|
|
||||||
ldd [FP-152], %f2
|
|
||||||
ldd [FP-144], %f4
|
|
||||||
ldd [FP-136], %f6
|
|
||||||
|
|
||||||
L(integer):
|
|
||||||
ldx [FP-160], %i0
|
ldx [FP-160], %i0
|
||||||
|
ldd [FP-160], %f0
|
||||||
|
b 8f
|
||||||
|
ldx [FP-152], %i1
|
||||||
|
E SPARC_RET_FLOAT
|
||||||
|
ld [FP-160], %f0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_DOUBLE
|
||||||
|
ldd [FP-160], %f0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_UINT8
|
||||||
|
ldub [FP-160+7], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_SINT8
|
||||||
|
ldsb [FP-160+7], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_UINT16
|
||||||
|
lduh [FP-160+6], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_SINT16
|
||||||
|
ldsh [FP-160+6], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_INT64
|
||||||
|
ldx [FP-160], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_UINT32
|
||||||
|
lduw [FP-160+4], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_SINT32
|
||||||
|
ldsw [FP-160+4], %i0
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
E SPARC_RET_LDOUBLE
|
||||||
|
ldd [FP-160], %f0
|
||||||
|
ldd [FP-160+8], %f2
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
|
||||||
L(done1):
|
! Unused entries. Don't allow bad data to do worse things.
|
||||||
ret
|
E 12
|
||||||
restore
|
unimp
|
||||||
|
E 13
|
||||||
|
unimp
|
||||||
|
E 14
|
||||||
|
unimp
|
||||||
|
E 15
|
||||||
|
unimp
|
||||||
|
|
||||||
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
|
! Finish the SPARC_RET_STRUCT sequence.
|
||||||
L(longdouble1):
|
.align 8
|
||||||
ldd [FP-152], %f2
|
8: ldd [FP-152], %f2
|
||||||
ret
|
ldx [FP-144], %i2
|
||||||
restore
|
ldd [FP-144], %f4
|
||||||
#endif
|
ldx [FP-136], %i3
|
||||||
|
ldd [FP-136], %f6
|
||||||
|
return %i7+8
|
||||||
|
nop
|
||||||
|
|
||||||
cfi_endproc
|
cfi_endproc
|
||||||
.size C(ffi_closure_v9), . - C(ffi_closure_v9)
|
.size C(ffi_closure_v9), . - C(ffi_closure_v9)
|
||||||
|
|
||||||
#endif /* SPARC64 */
|
#endif /* SPARC64 */
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
.section .note.GNU-stack,"",@progbits
|
.section .note.GNU-stack,"",@progbits
|
||||||
|
|||||||
Reference in New Issue
Block a user