Merge from gcc

This commit is contained in:
green
2008-01-29 12:28:15 +00:00
parent e680ecfbfc
commit ccabd2b16b
119 changed files with 9458 additions and 9444 deletions

View File

@@ -2,7 +2,6 @@
ffi.c - (c) 2003-2004 Randolph Chung <tausq@debian.org>
HPPA Foreign Function Interface
HP-UX PA ABI support (c) 2006 Free Software Foundation, Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -31,19 +30,15 @@
#include <stdio.h>
#define ROUND_UP(v, a) (((size_t)(v) + (a) - 1) & ~((a) - 1))
#define ROUND_DOWN(v, a) (((size_t)(v) - (a) + 1) & ~((a) - 1))
#define MIN_STACK_SIZE 64
#define FIRST_ARG_SLOT 9
#define DEBUG_LEVEL 0
#define fldw(addr, fpreg) \
__asm__ volatile ("fldw 0(%0), %%" #fpreg "L" : : "r"(addr) : #fpreg)
#define fstw(fpreg, addr) \
__asm__ volatile ("fstw %%" #fpreg "L, 0(%0)" : : "r"(addr))
#define fldd(addr, fpreg) \
__asm__ volatile ("fldd 0(%0), %%" #fpreg : : "r"(addr) : #fpreg)
#define fstd(fpreg, addr) \
__asm__ volatile ("fstd %%" #fpreg "L, 0(%0)" : : "r"(addr))
#define fldw(addr, fpreg) asm volatile ("fldw 0(%0), %%" #fpreg "L" : : "r"(addr) : #fpreg)
#define fstw(fpreg, addr) asm volatile ("fstw %%" #fpreg "L, 0(%0)" : : "r"(addr))
#define fldd(addr, fpreg) asm volatile ("fldd 0(%0), %%" #fpreg : : "r"(addr) : #fpreg)
#define fstd(fpreg, addr) asm volatile ("fstd %%" #fpreg "L, 0(%0)" : : "r"(addr))
#define debug(lvl, x...) do { if (lvl <= DEBUG_LEVEL) { printf(x); } } while (0)
@@ -52,19 +47,16 @@ static inline int ffi_struct_type(ffi_type *t)
size_t sz = t->size;
/* Small structure results are passed in registers,
larger ones are passed by pointer. Note that
small structures of size 2, 4 and 8 differ from
the corresponding integer types in that they have
different alignment requirements. */
larger ones are passed by pointer. */
if (sz <= 1)
return FFI_TYPE_UINT8;
else if (sz == 2)
return FFI_TYPE_SMALL_STRUCT2;
return FFI_TYPE_UINT16;
else if (sz == 3)
return FFI_TYPE_SMALL_STRUCT3;
else if (sz == 4)
return FFI_TYPE_SMALL_STRUCT4;
return FFI_TYPE_UINT32;
else if (sz == 5)
return FFI_TYPE_SMALL_STRUCT5;
else if (sz == 6)
@@ -72,80 +64,61 @@ static inline int ffi_struct_type(ffi_type *t)
else if (sz == 7)
return FFI_TYPE_SMALL_STRUCT7;
else if (sz <= 8)
return FFI_TYPE_SMALL_STRUCT8;
return FFI_TYPE_UINT64;
else
return FFI_TYPE_STRUCT; /* else, we pass it by pointer. */
}
/* PA has a downward growing stack, which looks like this:
Offset
[ Variable args ]
[ Variable args ]
SP = (4*(n+9)) arg word N
...
SP-52 arg word 4
[ Fixed args ]
[ Fixed args ]
SP-48 arg word 3
SP-44 arg word 2
SP-40 arg word 1
SP-36 arg word 0
[ Frame marker ]
[ Frame marker ]
...
SP-20 RP
SP-4 previous SP
The first four argument words on the stack are reserved for use by
the callee. Instead, the general and floating registers replace
the first four argument slots. Non FP arguments are passed solely
in the general registers. FP arguments are passed in both general
and floating registers when using libffi.
Non-FP 32-bit args are passed in gr26, gr25, gr24 and gr23.
Non-FP 64-bit args are passed in register pairs, starting
on an odd numbered register (i.e. r25+r26 and r23+r24).
FP 32-bit arguments are passed in fr4L, fr5L, fr6L and fr7L.
FP 64-bit arguments are passed in fr5 and fr7.
The registers are allocated in the same manner as stack slots.
This allows the callee to save its arguments on the stack if
necessary:
arg word 3 -> gr23 or fr7L
arg word 2 -> gr24 or fr6L or fr7R
arg word 1 -> gr25 or fr5L
arg word 0 -> gr26 or fr4L or fr5R
Note that fr4R and fr6R are never used for arguments (i.e.,
doubles are not passed in fr4 or fr6).
The rest of the arguments are passed on the stack starting at SP-52,
but 64-bit arguments need to be aligned to an 8-byte boundary
First 4 non-FP 32-bit args are passed in gr26, gr25, gr24 and gr23
First 2 non-FP 64-bit args are passed in register pairs, starting
on an even numbered register (i.e. r26/r25 and r24+r23)
First 4 FP 32-bit arguments are passed in fr4L, fr5L, fr6L and fr7L
First 2 FP 64-bit arguments are passed in fr5 and fr7
The rest are passed on the stack starting at SP-52, but 64-bit
arguments need to be aligned to an 8-byte boundary
This means we can have holes either in the register allocation,
or in the stack. */
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments
The following code will put everything into the stack frame
(which was allocated by the asm routine), and on return
the asm routine will load the arguments that should be
passed by register into the appropriate registers
NOTE: We load floating point args in this function... that means we
assume gcc will not mess with fp regs in here. */
void ffi_prep_args_pa32(UINT32 *stack, extended_cif *ecif, unsigned bytes)
/*@-exportheader@*/
void ffi_prep_args_LINUX(UINT32 *stack, extended_cif *ecif, unsigned bytes)
/*@=exportheader@*/
{
register unsigned int i;
register ffi_type **p_arg;
register void **p_argv;
unsigned int slot = FIRST_ARG_SLOT;
unsigned int slot = FIRST_ARG_SLOT - 1;
char *dest_cpy;
size_t len;
debug(1, "%s: stack = %p, ecif = %p, bytes = %u\n", __FUNCTION__, stack,
ecif, bytes);
debug(1, "%s: stack = %p, ecif = %p, bytes = %u\n", __FUNCTION__, stack, ecif, bytes);
p_arg = ecif->cif->arg_types;
p_argv = ecif->avalue;
@@ -157,105 +130,116 @@ void ffi_prep_args_pa32(UINT32 *stack, extended_cif *ecif, unsigned bytes)
switch (type)
{
case FFI_TYPE_SINT8:
slot++;
*(SINT32 *)(stack - slot) = *(SINT8 *)(*p_argv);
break;
case FFI_TYPE_UINT8:
slot++;
*(UINT32 *)(stack - slot) = *(UINT8 *)(*p_argv);
break;
case FFI_TYPE_SINT16:
slot++;
*(SINT32 *)(stack - slot) = *(SINT16 *)(*p_argv);
break;
case FFI_TYPE_UINT16:
slot++;
*(UINT32 *)(stack - slot) = *(UINT16 *)(*p_argv);
break;
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
case FFI_TYPE_POINTER:
debug(3, "Storing UINT32 %u in slot %u\n", *(UINT32 *)(*p_argv),
slot);
slot++;
debug(3, "Storing UINT32 %u in slot %u\n", *(UINT32 *)(*p_argv), slot);
*(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
/* Align slot for 64-bit type. */
slot += (slot & 1) ? 1 : 2;
*(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
slot += 2;
if (slot & 1)
slot++;
*(UINT32 *)(stack - slot) = (*(UINT64 *)(*p_argv)) >> 32;
*(UINT32 *)(stack - slot + 1) = (*(UINT64 *)(*p_argv)) & 0xffffffffUL;
break;
case FFI_TYPE_FLOAT:
/* First 4 args go in fr4L - fr7L. */
debug(3, "Storing UINT32(float) in slot %u\n", slot);
*(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
/* First 4 args go in fr4L - fr7L */
slot++;
switch (slot - FIRST_ARG_SLOT)
{
/* First 4 args go in fr4L - fr7L. */
case 0: fldw(stack - slot, fr4); break;
case 1: fldw(stack - slot, fr5); break;
case 2: fldw(stack - slot, fr6); break;
case 3: fldw(stack - slot, fr7); break;
case 0: fldw(*p_argv, fr4); break;
case 1: fldw(*p_argv, fr5); break;
case 2: fldw(*p_argv, fr6); break;
case 3: fldw(*p_argv, fr7); break;
default:
/* Other ones are just passed on the stack. */
debug(3, "Storing UINT32(float) in slot %u\n", slot);
*(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
break;
}
break;
break;
case FFI_TYPE_DOUBLE:
/* Align slot for 64-bit type. */
slot += (slot & 1) ? 1 : 2;
debug(3, "Storing UINT64(double) at slot %u\n", slot);
*(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
switch (slot - FIRST_ARG_SLOT)
slot += 2;
if (slot & 1)
slot++;
switch (slot - FIRST_ARG_SLOT + 1)
{
/* First 2 args go in fr5, fr7. */
case 1: fldd(stack - slot, fr5); break;
case 3: fldd(stack - slot, fr7); break;
/* First 2 args go in fr5, fr7 */
case 2: fldd(*p_argv, fr5); break;
case 4: fldd(*p_argv, fr7); break;
default:
debug(3, "Storing UINT64(double) at slot %u\n", slot);
*(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
break;
}
break;
#ifdef PA_HPUX
case FFI_TYPE_LONGDOUBLE:
/* Long doubles are passed in the same manner as structures
larger than 8 bytes. */
*(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
break;
#endif
case FFI_TYPE_STRUCT:
/* Structs smaller or equal than 4 bytes are passed in one
register. Structs smaller or equal 8 bytes are passed in two
registers. Larger structures are passed by pointer. */
len = (*p_arg)->size;
if (len <= 4)
if((*p_arg)->size <= 4)
{
dest_cpy = (char *)(stack - slot) + 4 - len;
memcpy(dest_cpy, (char *)*p_argv, len);
slot++;
dest_cpy = (char *)(stack - slot);
dest_cpy += 4 - (*p_arg)->size;
memcpy((char *)dest_cpy, (char *)*p_argv, (*p_arg)->size);
}
else if (len <= 8)
else if ((*p_arg)->size <= 8)
{
slot += (slot & 1) ? 1 : 2;
dest_cpy = (char *)(stack - slot) + 8 - len;
memcpy(dest_cpy, (char *)*p_argv, len);
slot += 2;
if (slot & 1)
slot++;
dest_cpy = (char *)(stack - slot);
dest_cpy += 8 - (*p_arg)->size;
memcpy((char *)dest_cpy, (char *)*p_argv, (*p_arg)->size);
}
else
{
slot++;
*(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
}
else
*(UINT32 *)(stack - slot) = (UINT32)(*p_argv);
break;
default:
FFI_ASSERT(0);
}
slot++;
p_arg++;
p_argv++;
}
/* Make sure we didn't mess up and scribble on the stack. */
{
unsigned int n;
int n;
debug(5, "Stack setup:\n");
for (n = 0; n < (bytes + 3) / 4; n++)
@@ -271,7 +255,7 @@ void ffi_prep_args_pa32(UINT32 *stack, extended_cif *ecif, unsigned bytes)
return;
}
static void ffi_size_stack_pa32(ffi_cif *cif)
static void ffi_size_stack_LINUX(ffi_cif *cif)
{
ffi_type **ptr;
int i;
@@ -289,9 +273,6 @@ static void ffi_size_stack_pa32(ffi_cif *cif)
z += 2 + (z & 1); /* must start on even regs, so we may waste one */
break;
#ifdef PA_HPUX
case FFI_TYPE_LONGDOUBLE:
#endif
case FFI_TYPE_STRUCT:
z += 1; /* pass by ptr, callee will copy */
break;
@@ -323,13 +304,6 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
cif->flags = (unsigned) cif->rtype->type;
break;
#ifdef PA_HPUX
case FFI_TYPE_LONGDOUBLE:
/* Long doubles are treated like a structure. */
cif->flags = FFI_TYPE_STRUCT;
break;
#endif
case FFI_TYPE_STRUCT:
/* For the return type we have to check the size of the structures.
If the size is smaller or equal 4 bytes, the result is given back
@@ -353,8 +327,8 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
own stack sizing. */
switch (cif->abi)
{
case FFI_PA32:
ffi_size_stack_pa32(cif);
case FFI_LINUX:
ffi_size_stack_LINUX(cif);
break;
default:
@@ -365,11 +339,20 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
return FFI_OK;
}
extern void ffi_call_pa32(void (*)(UINT32 *, extended_cif *, unsigned),
extended_cif *, unsigned, unsigned, unsigned *,
void (*fn)());
/*@-declundef@*/
/*@-exportheader@*/
extern void ffi_call_LINUX(void (*)(UINT32 *, extended_cif *, unsigned),
/*@out@*/ extended_cif *,
unsigned, unsigned,
/*@out@*/ unsigned *,
void (*fn)());
/*@=declundef@*/
/*@=exportheader@*/
void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
void ffi_call(/*@dependent@*/ ffi_cif *cif,
void (*fn)(),
/*@out@*/ void *rvalue,
/*@dependent@*/ void **avalue)
{
extended_cif ecif;
@@ -379,15 +362,12 @@ void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
/* If the return value is a struct and we don't have a return
value address then we need to make one. */
if (rvalue == NULL
#ifdef PA_HPUX
&& (cif->rtype->type == FFI_TYPE_STRUCT
|| cif->rtype->type == FFI_TYPE_LONGDOUBLE))
#else
&& cif->rtype->type == FFI_TYPE_STRUCT)
#endif
if ((rvalue == NULL) &&
(cif->rtype->type == FFI_TYPE_STRUCT))
{
/*@-sysunrecog@*/
ecif.rvalue = alloca(cif->rtype->size);
/*@=sysunrecog@*/
}
else
ecif.rvalue = rvalue;
@@ -395,10 +375,12 @@ void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
switch (cif->abi)
{
case FFI_PA32:
debug(3, "Calling ffi_call_pa32: ecif=%p, bytes=%u, flags=%u, rvalue=%p, fn=%p\n", &ecif, cif->bytes, cif->flags, ecif.rvalue, (void *)fn);
ffi_call_pa32(ffi_prep_args_pa32, &ecif, cif->bytes,
case FFI_LINUX:
/*@-usedef@*/
debug(2, "Calling ffi_call_LINUX: ecif=%p, bytes=%u, flags=%u, rvalue=%p, fn=%p\n", &ecif, cif->bytes, cif->flags, ecif.rvalue, (void *)fn);
ffi_call_LINUX(ffi_prep_args_LINUX, &ecif, cif->bytes,
cif->flags, ecif.rvalue, fn);
/*@=usedef@*/
break;
default:
@@ -412,7 +394,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
the stack, and we need to fill them into a cif structure and invoke
the user function. This really ought to be in asm to make sure
the compiler doesn't do things we don't expect. */
ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
UINT32 ffi_closure_inner_LINUX(ffi_closure *closure, UINT32 *stack)
{
ffi_cif *cif;
void **avalue;
@@ -420,8 +402,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
UINT32 ret[2]; /* function can return up to 64-bits in registers */
ffi_type **p_arg;
char *tmp;
int i, avn;
unsigned int slot = FIRST_ARG_SLOT;
int i, avn, slot = FIRST_ARG_SLOT - 1;
register UINT32 r28 asm("r28");
cif = closure->cif;
@@ -449,23 +430,20 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
case FFI_TYPE_POINTER:
slot++;
avalue[i] = (char *)(stack - slot) + sizeof(UINT32) - (*p_arg)->size;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
slot += (slot & 1) ? 1 : 2;
slot += 2;
if (slot & 1)
slot++;
avalue[i] = (void *)(stack - slot);
break;
case FFI_TYPE_FLOAT:
#ifdef PA_LINUX
/* The closure call is indirect. In Linux, floating point
arguments in indirect calls with a prototype are passed
in the floating point registers instead of the general
registers. So, we need to replace what was previously
stored in the current slot with the value in the
corresponding floating point register. */
slot++;
switch (slot - FIRST_ARG_SLOT)
{
case 0: fstw(fr4, (void *)(stack - slot)); break;
@@ -473,20 +451,18 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
case 2: fstw(fr6, (void *)(stack - slot)); break;
case 3: fstw(fr7, (void *)(stack - slot)); break;
}
#endif
avalue[i] = (void *)(stack - slot);
break;
case FFI_TYPE_DOUBLE:
slot += (slot & 1) ? 1 : 2;
#ifdef PA_LINUX
/* See previous comment for FFI_TYPE_FLOAT. */
switch (slot - FIRST_ARG_SLOT)
slot += 2;
if (slot & 1)
slot++;
switch (slot - FIRST_ARG_SLOT + 1)
{
case 1: fstd(fr5, (void *)(stack - slot)); break;
case 3: fstd(fr7, (void *)(stack - slot)); break;
case 2: fstd(fr5, (void *)(stack - slot)); break;
case 4: fstd(fr7, (void *)(stack - slot)); break;
}
#endif
avalue[i] = (void *)(stack - slot);
break;
@@ -494,36 +470,35 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
/* Structs smaller or equal than 4 bytes are passed in one
register. Structs smaller or equal 8 bytes are passed in two
registers. Larger structures are passed by pointer. */
if((*p_arg)->size <= 4)
{
avalue[i] = (void *)(stack - slot) + sizeof(UINT32) -
(*p_arg)->size;
}
else if ((*p_arg)->size <= 8)
{
slot += (slot & 1) ? 1 : 2;
avalue[i] = (void *)(stack - slot) + sizeof(UINT64) -
(*p_arg)->size;
}
else
if((*p_arg)->size <= 4) {
slot++;
avalue[i] = (void *)(stack - slot) + sizeof(UINT32) -
(*p_arg)->size;
} else if ((*p_arg)->size <= 8) {
slot += 2;
if (slot & 1)
slot++;
avalue[i] = (void *)(stack - slot) + sizeof(UINT64) -
(*p_arg)->size;
} else {
slot++;
avalue[i] = (void *) *(stack - slot);
}
break;
default:
FFI_ASSERT(0);
}
slot++;
p_arg++;
}
/* Invoke the closure. */
(closure->fun) (cif, rvalue, avalue, closure->user_data);
debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0],
ret[1]);
debug(3, "after calling function, ret[0] = %08x, ret[1] = %08x\n", ret[0], ret[1]);
/* Store the result using the lower 2 bytes of the flags. */
/* Store the result */
switch (cif->flags)
{
case FFI_TYPE_UINT8:
@@ -561,9 +536,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
/* Don't need a return value, done by caller. */
break;
case FFI_TYPE_SMALL_STRUCT2:
case FFI_TYPE_SMALL_STRUCT3:
case FFI_TYPE_SMALL_STRUCT4:
tmp = (void*)(stack - FIRST_ARG_SLOT);
tmp += 4 - cif->rtype->size;
memcpy((void*)tmp, &ret[0], cif->rtype->size);
@@ -572,7 +545,6 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
case FFI_TYPE_SMALL_STRUCT5:
case FFI_TYPE_SMALL_STRUCT6:
case FFI_TYPE_SMALL_STRUCT7:
case FFI_TYPE_SMALL_STRUCT8:
{
unsigned int ret2[2];
int off;
@@ -610,7 +582,7 @@ ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
cif specifies the argument and result types for fun.
The cif must already be prep'ed. */
extern void ffi_closure_pa32(void);
void ffi_closure_LINUX(void);
ffi_status
ffi_prep_closure (ffi_closure* closure,
@@ -619,83 +591,30 @@ ffi_prep_closure (ffi_closure* closure,
void *user_data)
{
UINT32 *tramp = (UINT32 *)(closure->tramp);
#ifdef PA_HPUX
UINT32 *tmp;
#endif
FFI_ASSERT (cif->abi == FFI_PA32);
FFI_ASSERT (cif->abi == FFI_LINUX);
/* Make a small trampoline that will branch to our
handler function. Use PC-relative addressing. */
#ifdef PA_LINUX
tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */
tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */
tramp[2] = 0x4aa10028; /* ldw 20(%r21),%r1 ; load plabel */
tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */
tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */
tramp[5] = 0xeac0c000; /* bv%r0(%r22) ; branch to handler */
tramp[6] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */
tramp[7] = ((UINT32)(ffi_closure_pa32) & ~2);
tramp[0] = 0xeaa00000; /* b,l .+8, %r21 ; %r21 <- pc+8 */
tramp[1] = 0xd6a01c1e; /* depi 0,31,2, %r21 ; mask priv bits */
tramp[2] = 0x4aa10028; /* ldw 20(%r21), %r1 ; load plabel */
tramp[3] = 0x36b53ff1; /* ldo -8(%r21), %r21 ; get closure addr */
tramp[4] = 0x0c201096; /* ldw 0(%r1), %r22 ; address of handler */
tramp[5] = 0xeac0c000; /* bv %r0(%r22) ; branch to handler */
tramp[6] = 0x0c281093; /* ldw 4(%r1), %r19 ; GP of handler */
tramp[7] = ((UINT32)(ffi_closure_LINUX) & ~2);
/* Flush d/icache -- have to flush up 2 two lines because of
alignment. */
__asm__ volatile(
"fdc 0(%0)\n\t"
"fdc %1(%0)\n\t"
"fic 0(%%sr4, %0)\n\t"
"fic %1(%%sr4, %0)\n\t"
"sync\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n"
:
: "r"((unsigned long)tramp & ~31),
"r"(32 /* stride */)
: "memory");
#endif
#ifdef PA_HPUX
tramp[0] = 0xeaa00000; /* b,l .+8,%r21 ; %r21 <- pc+8 */
tramp[1] = 0xd6a01c1e; /* depi 0,31,2,%r21 ; mask priv bits */
tramp[2] = 0x4aa10038; /* ldw 28(%r21),%r1 ; load plabel */
tramp[3] = 0x36b53ff1; /* ldo -8(%r21),%r21 ; get closure addr */
tramp[4] = 0x0c201096; /* ldw 0(%r1),%r22 ; address of handler */
tramp[5] = 0x02c010b4; /* ldsid (%r22),%r20 ; load space id */
tramp[6] = 0x00141820; /* mtsp %r20,%sr0 ; into %sr0 */
tramp[7] = 0xe2c00000; /* be 0(%sr0,%r22) ; branch to handler */
tramp[8] = 0x0c281093; /* ldw 4(%r1),%r19 ; GP of handler */
tramp[9] = ((UINT32)(ffi_closure_pa32) & ~2);
/* Flush d/icache -- have to flush three lines because of alignment. */
__asm__ volatile(
"copy %1,%0\n\t"
"fdc,m %2(%0)\n\t"
"fdc,m %2(%0)\n\t"
"fdc,m %2(%0)\n\t"
"ldsid (%1),%0\n\t"
"mtsp %0,%%sr0\n\t"
"copy %1,%0\n\t"
"fic,m %2(%%sr0,%0)\n\t"
"fic,m %2(%%sr0,%0)\n\t"
"fic,m %2(%%sr0,%0)\n\t"
"sync\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n"
: "=&r" ((unsigned long)tmp)
: "r" ((unsigned long)tramp & ~31),
"r" (32/* stride */)
: "memory");
#endif
asm volatile (
"fdc 0(%0)\n"
"fdc %1(%0)\n"
"fic 0(%%sr4, %0)\n"
"fic %1(%%sr4, %0)\n"
"sync\n"
: : "r"((unsigned long)tramp & ~31), "r"(32 /* stride */));
closure->cif = cif;
closure->user_data = user_data;

View File

@@ -35,20 +35,9 @@ typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
#ifdef PA_LINUX
FFI_PA32,
FFI_DEFAULT_ABI = FFI_PA32,
#endif
#ifdef PA_HPUX
FFI_PA32,
FFI_DEFAULT_ABI = FFI_PA32,
#endif
#ifdef PA64_HPUX
#error "PA64_HPUX FFI is not yet implemented"
FFI_PA64,
FFI_DEFAULT_ABI = FFI_PA64,
#ifdef PA
FFI_LINUX,
FFI_DEFAULT_ABI = FFI_LINUX,
#endif
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
@@ -60,17 +49,11 @@ typedef enum ffi_abi {
#define FFI_CLOSURES 1
#define FFI_NATIVE_RAW_API 0
#ifdef PA_LINUX
#define FFI_TRAMPOLINE_SIZE 32
#else
#define FFI_TRAMPOLINE_SIZE 40
#define FFI_TYPE_SMALL_STRUCT3 -1
#define FFI_TYPE_SMALL_STRUCT5 -2
#define FFI_TYPE_SMALL_STRUCT6 -3
#define FFI_TYPE_SMALL_STRUCT7 -4
#endif
#define FFI_TYPE_SMALL_STRUCT2 -1
#define FFI_TYPE_SMALL_STRUCT3 -2
#define FFI_TYPE_SMALL_STRUCT4 -3
#define FFI_TYPE_SMALL_STRUCT5 -4
#define FFI_TYPE_SMALL_STRUCT6 -5
#define FFI_TYPE_SMALL_STRUCT7 -6
#define FFI_TYPE_SMALL_STRUCT8 -7
#endif

View File

@@ -31,7 +31,7 @@
.level 1.1
.align 4
/* void ffi_call_pa32(void (*)(char *, extended_cif *),
/* void ffi_call_LINUX(void (*)(char *, extended_cif *),
extended_cif *ecif,
unsigned bytes,
unsigned flags,
@@ -39,12 +39,12 @@
void (*fn)());
*/
.export ffi_call_pa32,code
.import ffi_prep_args_pa32,code
.export ffi_call_LINUX,code
.import ffi_prep_args_LINUX,code
.type ffi_call_pa32, @function
.type ffi_call_LINUX, @function
.LFB1:
ffi_call_pa32:
ffi_call_LINUX:
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
.entry
@@ -63,7 +63,7 @@ ffi_call_pa32:
[ 64-bytes register save area ] <- %r4
[ Stack space for actual call, passed as ] <- %arg0
[ arg0 to ffi_prep_args_pa32 ]
[ arg0 to ffi_prep_args_LINUX ]
[ Stack for calling prep_args ] <- %sp
*/
@@ -73,14 +73,14 @@ ffi_call_pa32:
.LCFI13:
copy %sp, %r4
addl %arg2, %r4, %arg0 /* arg stack */
stw %arg3, -48(%r3) /* save flags; we need it later */
addl %arg2, %r4, %arg0 /* arg stack */
stw %arg3, -48(%r3) /* save flags; we need it later */
/* Call prep_args:
%arg0(stack) -- set up above
%arg1(ecif) -- same as incoming param
%arg2(bytes) -- same as incoming param */
bl ffi_prep_args_pa32,%r2
bl ffi_prep_args_LINUX,%r2
ldo 64(%arg0), %sp
ldo -64(%sp), %sp
@@ -106,139 +106,90 @@ ffi_call_pa32:
/* Store the result according to the return type. */
.Lcheckint:
comib,<>,n FFI_TYPE_INT, %r21, .Lcheckint8
b .Ldone
stw %ret0, 0(%r20)
checksmst3:
comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, checksmst567
/* 3-byte structs are returned in ret0 as ??xxyyzz. Shift
left 8 bits to write to the result structure. */
zdep %ret0, 23, 24, %r22
b done
stw %r22, 0(%r20)
.Lcheckint8:
comib,<>,n FFI_TYPE_UINT8, %r21, .Lcheckint16
b .Ldone
stb %ret0, 0(%r20)
.Lcheckint16:
comib,<>,n FFI_TYPE_UINT16, %r21, .Lcheckdbl
b .Ldone
sth %ret0, 0(%r20)
.Lcheckdbl:
comib,<>,n FFI_TYPE_DOUBLE, %r21, .Lcheckfloat
b .Ldone
fstd %fr4,0(%r20)
.Lcheckfloat:
comib,<>,n FFI_TYPE_FLOAT, %r21, .Lcheckll
b .Ldone
fstw %fr4L,0(%r20)
.Lcheckll:
comib,<>,n FFI_TYPE_UINT64, %r21, .Lchecksmst2
stw %ret0, 0(%r20)
b .Ldone
stw %ret1, 4(%r20)
.Lchecksmst2:
comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, .Lchecksmst3
/* 2-byte structs are returned in ret0 as ????xxyy. */
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret0, 0(%r20)
.Lchecksmst3:
comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, .Lchecksmst4
/* 3-byte structs are returned in ret0 as ??xxyyzz. */
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret0, 0(%r20)
.Lchecksmst4:
comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, .Lchecksmst5
/* 4-byte structs are returned in ret0 as wwxxyyzz. */
extru %ret0, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret0, 0(%r20)
.Lchecksmst5:
comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, .Lchecksmst6
/* 5 byte values are returned right justified:
checksmst567:
/* 5-7 byte values are returned right justified:
ret0 ret1
5: ??????aa bbccddee */
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret1, 0(%r20)
5: ??????aa bbccddee
6: ????aabb ccddeeff
7: ??aabbcc ddeeffgg
.Lchecksmst6:
comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, .Lchecksmst7
/* 6 byte values are returned right justified:
ret0 ret1
6: ????aabb ccddeeff */
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret1, 0(%r20)
To store this in the result, write the first 4 bytes into a temp
register using shrpw (t1 = aabbccdd), followed by a rotation of
ret1:
.Lchecksmst7:
comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, .Lchecksmst8
/* 7 byte values are returned right justified:
ret0 ret1
7: ??aabbcc ddeeffgg */
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
b .Ldone
stb %ret1, 0(%r20)
ret0 ret1 ret1
5: ??????aa bbccddee -> eebbccdd (rotate 8)
6: ????aabb ccddeeff -> eeffccdd (rotate 16)
7: ??aabbcc ddeeffgg -> eeffggdd (rotate 24)
.Lchecksmst8:
comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, .Ldone
/* 8 byte values are returned right justified:
ret0 ret1
8: aabbccdd eeffgghh */
extru %ret0, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret0, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stbs,ma %ret0, 1(%r20)
extru %ret1, 7, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 15, 8, %r22
stbs,ma %r22, 1(%r20)
extru %ret1, 23, 8, %r22
stbs,ma %r22, 1(%r20)
stb %ret1, 0(%r20)
then we write (t1, ret1) into the result. */
.Ldone:
addi,<> -FFI_TYPE_SMALL_STRUCT5,%r21,%r0
ldi 8, %r22
addi,<> -FFI_TYPE_SMALL_STRUCT6,%r21,%r0
ldi 16, %r22
addi,<> -FFI_TYPE_SMALL_STRUCT7,%r21,%r0
ldi 24, %r22
/* This relies on all the FFI_TYPE_*_STRUCT* defines being <0 */
cmpib,<=,n 0, %r21, checkint8
mtsar %r22
shrpw %ret0, %ret1, %sar, %ret0 /* ret0 = aabbccdd */
shrpw %ret1, %ret1, %sar, %ret1 /* rotate ret1 */
stw %ret0, 0(%r20)
b done
stw %ret1, 4(%r20)
checkint8:
comib,<>,n FFI_TYPE_UINT8, %r21, checkint16
b done
stb %ret0, 0(%r20)
checkint16:
comib,<>,n FFI_TYPE_UINT16, %r21, checkint32
b done
sth %ret0, 0(%r20)
checkint32:
comib,<>,n FFI_TYPE_UINT32, %r21, checkint
b done
stw %ret0, 0(%r20)
checkint:
comib,<>,n FFI_TYPE_INT, %r21, checkll
b done
stw %ret0, 0(%r20)
checkll:
comib,<>,n FFI_TYPE_UINT64, %r21, checkdbl
stw %ret0, 0(%r20)
b done
stw %ret1, 4(%r20)
checkdbl:
comib,<>,n FFI_TYPE_DOUBLE, %r21, checkfloat
b done
fstd %fr4,0(%r20)
checkfloat:
comib,<>,n FFI_TYPE_FLOAT, %r21, done
fstw %fr4L,0(%r20)
/* structure returns are either handled by one of the
INT/UINT64 cases above, or, if passed by pointer,
is handled by the callee. */
done:
/* all done, return */
copy %r4, %sp /* pop arg stack */
ldw 12(%r3), %r4
@@ -250,14 +201,14 @@ ffi_call_pa32:
.procend
.LFE1:
/* void ffi_closure_pa32(void);
/* void ffi_closure_LINUX(void);
Called with closure argument in %r21 */
.export ffi_closure_pa32,code
.import ffi_closure_inner_pa32,code
.export ffi_closure_LINUX,code
.import ffi_closure_inner_LINUX,code
.type ffi_closure_pa32, @function
.type ffi_closure_LINUX, @function
.LFB2:
ffi_closure_pa32:
ffi_closure_LINUX:
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
.entry
@@ -277,7 +228,7 @@ ffi_closure_pa32:
stw %arg3, -48(%r3)
copy %r21, %arg0
bl ffi_closure_inner_pa32, %r2
bl ffi_closure_inner_LINUX, %r2
copy %r3, %arg1
ldwm -64(%sp), %r3
@@ -348,7 +299,7 @@ ffi_closure_pa32:
.sleb128 -5
.byte 0x4 ;# DW_CFA_advance_loc4
.word .LCFI22-.LCFI21
.word .LCFI12-.LCFI11
.byte 0xd ;# DW_CFA_def_cfa_register = r3
.uleb128 0x3