summaryrefslogtreecommitdiffstats
path: root/libffi/src/pa
diff options
context:
space:
mode:
authorandreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4>2006-04-05 21:26:34 +0000
committerandreast <andreast@138bc75d-0d04-0410-961f-82ee72b054a4>2006-04-05 21:26:34 +0000
commit1a82d6f60260b289de17b62680ac6b6fc4bd2bf3 (patch)
treee38e6b7b7e9fa8cdd32350f91446780dab010fc2 /libffi/src/pa
parent8f5efc80bb67188446f501baf4ddefc8bebb3ddc (diff)
downloadppe42-gcc-1a82d6f60260b289de17b62680ac6b6fc4bd2bf3.tar.gz
ppe42-gcc-1a82d6f60260b289de17b62680ac6b6fc4bd2bf3.zip
2006-04-05 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
Andreas Tobler <a.tobler@schweiz.ch> * Makefile.am: Add PA_HPUX port. * Makefile.in: Regenerate. * include/Makefile.in: Likewise. * testsuite/Makefile.in: Likewise. * configure.ac: Add PA_HPUX rules. * configure: Regenerate. * src/pa/ffitarget.h: Rename linux target to PA_LINUX. Add PA_HPUX and PA64_HPUX. Rename FFI_LINUX ABI to FFI_PA32 ABI. (FFI_TRAMPOLINE_SIZE): Define for 32-bit HP-UX targets. (FFI_TYPE_SMALL_STRUCT2): Define. (FFI_TYPE_SMALL_STRUCT4): Likewise. (FFI_TYPE_SMALL_STRUCT8): Likewise. (FFI_TYPE_SMALL_STRUCT3): Redefine. (FFI_TYPE_SMALL_STRUCT5): Likewise. (FFI_TYPE_SMALL_STRUCT6): Likewise. (FFI_TYPE_SMALL_STRUCT7): Likewise. * src/pa/ffi.c (ROUND_DOWN): Delete. (fldw, fstw, fldd, fstd): Use '__asm__'. (ffi_struct_type): Add support for FFI_TYPE_SMALL_STRUCT2, FFI_TYPE_SMALL_STRUCT4 and FFI_TYPE_SMALL_STRUCT8. (ffi_prep_args_LINUX): Rename to ffi_prep_args_pa32. Update comment. Simplify incrementing of stack slot variable. Change type of local 'n' to unsigned int. (ffi_size_stack_LINUX): Rename to ffi_size_stack_pa32. Handle long double on PA_HPUX. (ffi_prep_cif_machdep): Likewise. (ffi_call): Likewise. (ffi_closure_inner_LINUX): Rename to ffi_closure_inner_pa32. Change return type to ffi_status. Simplify incrementing of stack slot variable. Only copy floating point argument registers when PA_LINUX is true. Reformat debug statement. Add support for FFI_TYPE_SMALL_STRUCT2, FFI_TYPE_SMALL_STRUCT4 and FFI_TYPE_SMALL_STRUCT8. (ffi_closure_LINUX): Rename to ffi_closure_pa32. Add 'extern' to declaration. (ffi_prep_closure): Make linux trampoline conditional on PA_LINUX. Add nops to cache flush. Add trampoline for PA_HPUX. * src/pa/hpux32.S: New file. * src/pa/linux.S (ffi_call_LINUX): Rename to ffi_call_pa32. Rename ffi_prep_args_LINUX to ffi_prep_args_pa32. Localize labels. Add support for 2, 4 and 8-byte small structs. Handle unaligned destinations in 3, 5, 6 and 7-byte small structs. Order argument type checks so that common argument types appear first. (ffi_closure_LINUX): Rename to ffi_closure_pa32. Rename ffi_closure_inner_LINUX to ffi_closure_inner_pa32. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@112719 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libffi/src/pa')
-rw-r--r--libffi/src/pa/ffi.c356
-rw-r--r--libffi/src/pa/ffitarget.h33
-rw-r--r--libffi/src/pa/hpux32.S367
-rw-r--r--libffi/src/pa/linux.S245
4 files changed, 765 insertions, 236 deletions
diff --git a/libffi/src/pa/ffi.c b/libffi/src/pa/ffi.c
index f6264dbc5e9..65f958ff2c1 100644
--- a/libffi/src/pa/ffi.c
+++ b/libffi/src/pa/ffi.c
@@ -2,6 +2,7 @@
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
@@ -30,15 +31,19 @@
#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)
@@ -47,16 +52,19 @@ 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. */
+ 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. */
if (sz <= 1)
return FFI_TYPE_UINT8;
else if (sz == 2)
- return FFI_TYPE_UINT16;
+ return FFI_TYPE_SMALL_STRUCT2;
else if (sz == 3)
return FFI_TYPE_SMALL_STRUCT3;
else if (sz == 4)
- return FFI_TYPE_UINT32;
+ return FFI_TYPE_SMALL_STRUCT4;
else if (sz == 5)
return FFI_TYPE_SMALL_STRUCT5;
else if (sz == 6)
@@ -64,61 +72,82 @@ 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_UINT64;
+ return FFI_TYPE_SMALL_STRUCT8;
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
-
- 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
-
+
+ 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
+
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. */
/*@-exportheader@*/
-void ffi_prep_args_LINUX(UINT32 *stack, extended_cif *ecif, unsigned bytes)
+void ffi_prep_args_pa32(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 - 1;
+ unsigned int slot = FIRST_ARG_SLOT;
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;
@@ -130,116 +159,105 @@ void ffi_prep_args_LINUX(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:
- slot++;
- debug(3, "Storing UINT32 %u in slot %u\n", *(UINT32 *)(*p_argv), 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:
- slot += 2;
- if (slot & 1)
- slot++;
-
- *(UINT32 *)(stack - slot) = (*(UINT64 *)(*p_argv)) >> 32;
- *(UINT32 *)(stack - slot + 1) = (*(UINT64 *)(*p_argv)) & 0xffffffffUL;
+ /* Align slot for 64-bit type. */
+ slot += (slot & 1) ? 1 : 2;
+ *(UINT64 *)(stack - slot) = *(UINT64 *)(*p_argv);
break;
case FFI_TYPE_FLOAT:
- /* First 4 args go in fr4L - fr7L */
- slot++;
+ /* First 4 args go in fr4L - fr7L. */
+ debug(3, "Storing UINT32(float) in slot %u\n", slot);
+ *(UINT32 *)(stack - slot) = *(UINT32 *)(*p_argv);
switch (slot - FIRST_ARG_SLOT)
{
+ /* First 4 args go in fr4L - fr7L. */
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:
- slot += 2;
- if (slot & 1)
- slot++;
- switch (slot - FIRST_ARG_SLOT + 1)
+ /* 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)
{
- /* 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;
+ /* First 2 args go in fr5, fr7. */
+ case 1: fldd(*p_argv, fr5); break;
+ case 3: fldd(*p_argv, fr7); 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. */
- if((*p_arg)->size <= 4)
+ len = (*p_arg)->size;
+ if (len <= 4)
{
- slot++;
- dest_cpy = (char *)(stack - slot);
- dest_cpy += 4 - (*p_arg)->size;
- memcpy((char *)dest_cpy, (char *)*p_argv, (*p_arg)->size);
+ dest_cpy = (char *)(stack - slot) + 4 - len;
+ memcpy(dest_cpy, (char *)*p_argv, len);
}
- else if ((*p_arg)->size <= 8)
+ else if (len <= 8)
{
- 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);
+ slot += (slot & 1) ? 1 : 2;
+ dest_cpy = (char *)(stack - slot) + 8 - len;
+ memcpy(dest_cpy, (char *)*p_argv, len);
}
+ 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. */
{
- int n;
+ unsigned int n;
debug(5, "Stack setup:\n");
for (n = 0; n < (bytes + 3) / 4; n++)
@@ -255,7 +273,7 @@ void ffi_prep_args_LINUX(UINT32 *stack, extended_cif *ecif, unsigned bytes)
return;
}
-static void ffi_size_stack_LINUX(ffi_cif *cif)
+static void ffi_size_stack_pa32(ffi_cif *cif)
{
ffi_type **ptr;
int i;
@@ -273,6 +291,9 @@ static void ffi_size_stack_LINUX(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;
@@ -304,6 +325,13 @@ 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
@@ -327,8 +355,8 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
own stack sizing. */
switch (cif->abi)
{
- case FFI_LINUX:
- ffi_size_stack_LINUX(cif);
+ case FFI_PA32:
+ ffi_size_stack_pa32(cif);
break;
default:
@@ -341,7 +369,7 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
/*@-declundef@*/
/*@-exportheader@*/
-extern void ffi_call_LINUX(void (*)(UINT32 *, extended_cif *, unsigned),
+extern void ffi_call_pa32(void (*)(UINT32 *, extended_cif *, unsigned),
/*@out@*/ extended_cif *,
unsigned, unsigned,
/*@out@*/ unsigned *,
@@ -362,8 +390,13 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
/* 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) &&
- (cif->rtype->type == FFI_TYPE_STRUCT))
+ 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
{
/*@-sysunrecog@*/
ecif.rvalue = alloca(cif->rtype->size);
@@ -375,10 +408,10 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
switch (cif->abi)
{
- case FFI_LINUX:
+ case FFI_PA32:
/*@-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,
+ 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,
cif->flags, ecif.rvalue, fn);
/*@=usedef@*/
break;
@@ -394,7 +427,7 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
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. */
-UINT32 ffi_closure_inner_LINUX(ffi_closure *closure, UINT32 *stack)
+ffi_status ffi_closure_inner_pa32(ffi_closure *closure, UINT32 *stack)
{
ffi_cif *cif;
void **avalue;
@@ -402,7 +435,8 @@ UINT32 ffi_closure_inner_LINUX(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, slot = FIRST_ARG_SLOT - 1;
+ int i, avn;
+ unsigned int slot = FIRST_ARG_SLOT;
register UINT32 r28 asm("r28");
cif = closure->cif;
@@ -430,20 +464,23 @@ UINT32 ffi_closure_inner_LINUX(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 += 2;
- if (slot & 1)
- slot++;
+ slot += (slot & 1) ? 1 : 2;
avalue[i] = (void *)(stack - slot);
break;
case FFI_TYPE_FLOAT:
- slot++;
+#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. */
switch (slot - FIRST_ARG_SLOT)
{
case 0: fstw(fr4, (void *)(stack - slot)); break;
@@ -451,18 +488,20 @@ UINT32 ffi_closure_inner_LINUX(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 += 2;
- if (slot & 1)
- slot++;
- switch (slot - FIRST_ARG_SLOT + 1)
+ slot += (slot & 1) ? 1 : 2;
+#ifdef PA_LINUX
+ /* See previous comment for FFI_TYPE_FLOAT. */
+ switch (slot - FIRST_ARG_SLOT)
{
- case 2: fstd(fr5, (void *)(stack - slot)); break;
- case 4: fstd(fr7, (void *)(stack - slot)); break;
+ case 1: fstd(fr5, (void *)(stack - slot)); break;
+ case 3: fstd(fr7, (void *)(stack - slot)); break;
}
+#endif
avalue[i] = (void *)(stack - slot);
break;
@@ -470,35 +509,36 @@ UINT32 ffi_closure_inner_LINUX(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) {
- 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++;
+ 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
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 */
+ /* Store the result using the lower 2 bytes of the flags. */
switch (cif->flags)
{
case FFI_TYPE_UINT8:
@@ -536,7 +576,9 @@ UINT32 ffi_closure_inner_LINUX(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);
@@ -545,6 +587,7 @@ UINT32 ffi_closure_inner_LINUX(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;
@@ -582,7 +625,7 @@ UINT32 ffi_closure_inner_LINUX(ffi_closure *closure, UINT32 *stack)
cif specifies the argument and result types for fun.
The cif must already be prep'ed. */
-void ffi_closure_LINUX(void);
+extern void ffi_closure_pa32(void);
ffi_status
ffi_prep_closure (ffi_closure* closure,
@@ -591,30 +634,83 @@ 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_LINUX);
+ FFI_ASSERT (cif->abi == FFI_PA32);
/* Make a small trampoline that will branch to our
handler function. Use PC-relative addressing. */
- 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);
+#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);
/* Flush d/icache -- have to flush up 2 two lines because of
alignment. */
- 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 */));
+ __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
closure->cif = cif;
closure->user_data = user_data;
diff --git a/libffi/src/pa/ffitarget.h b/libffi/src/pa/ffitarget.h
index 56206962397..95ac48060c6 100644
--- a/libffi/src/pa/ffitarget.h
+++ b/libffi/src/pa/ffitarget.h
@@ -35,9 +35,20 @@ typedef signed long ffi_sarg;
typedef enum ffi_abi {
FFI_FIRST_ABI = 0,
-#ifdef PA
- FFI_LINUX,
- FFI_DEFAULT_ABI = FFI_LINUX,
+#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,
#endif
FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
@@ -49,11 +60,17 @@ typedef enum ffi_abi {
#define FFI_CLOSURES 1
#define FFI_NATIVE_RAW_API 0
+#ifdef PA_LINUX
#define FFI_TRAMPOLINE_SIZE 32
-
-#define FFI_TYPE_SMALL_STRUCT3 -1
-#define FFI_TYPE_SMALL_STRUCT5 -2
-#define FFI_TYPE_SMALL_STRUCT6 -3
-#define FFI_TYPE_SMALL_STRUCT7 -4
+#else
+#define FFI_TRAMPOLINE_SIZE 40
#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
diff --git a/libffi/src/pa/hpux32.S b/libffi/src/pa/hpux32.S
new file mode 100644
index 00000000000..4c4470fbf9b
--- /dev/null
+++ b/libffi/src/pa/hpux32.S
@@ -0,0 +1,367 @@
+/* -----------------------------------------------------------------------
+ hpux32.S - Copyright (c) 2006 Free Software Foundation, Inc.
+ based on src/pa/linux.S
+
+ HP-UX PA 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 AUTHOR 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.
+ ----------------------------------------------------------------------- */
+
+#define LIBFFI_ASM
+#include <fficonfig.h>
+#include <ffi.h>
+
+ .LEVEL 1.1
+ .SPACE $PRIVATE$
+ .IMPORT $global$,DATA
+ .IMPORT $$dyncall,MILLICODE
+ .SUBSPA $DATA$
+ .align 4
+
+ /* void ffi_call_pa32(void (*)(char *, extended_cif *),
+ extended_cif *ecif,
+ unsigned bytes,
+ unsigned flags,
+ unsigned *rvalue,
+ void (*fn)());
+ */
+
+ .export ffi_call_pa32,ENTRY,PRIV_LEV=3
+ .import ffi_prep_args_pa32,CODE
+
+ .SPACE $TEXT$
+ .SUBSPA $CODE$
+ .align 4
+
+L$FB1
+ffi_call_pa32
+ .proc
+ .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
+ .entry
+ stw %rp, -20(%sp)
+ copy %r3, %r1
+L$CFI11
+ copy %sp, %r3
+L$CFI12
+
+ /* Setup the stack for calling prep_args...
+ We want the stack to look like this:
+
+ [ Previous stack ] <- %r3
+
+ [ 64-bytes register save area ] <- %r4
+
+ [ Stack space for actual call, passed as ] <- %arg0
+ [ arg0 to ffi_prep_args_pa32 ]
+
+ [ Stack for calling prep_args ] <- %sp
+ */
+
+ stwm %r1, 64(%sp)
+ stw %r4, 12(%r3)
+L$CFI13
+ copy %sp, %r4
+
+ 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
+ ldo 64(%arg0), %sp
+ ldo -64(%sp), %sp
+
+ /* now %sp should point where %arg0 was pointing. */
+
+ /* Load the arguments that should be passed in registers
+ The fp args are loaded by the prep_args function. */
+ ldw -36(%sp), %arg0
+ ldw -40(%sp), %arg1
+ ldw -44(%sp), %arg2
+ ldw -48(%sp), %arg3
+
+ /* in case the function is going to return a structure
+ we need to give it a place to put the result. */
+ ldw -52(%r3), %ret0 ; %ret0 <- rvalue
+ ldw -56(%r3), %r22 ; %r22 <- function to call
+ bl $$dyncall, %r31 ; Call the user function
+ copy %r31, %rp
+
+ /* Prepare to store the result; we need to recover flags and rvalue. */
+ ldw -48(%r3), %r21 ; r21 <- flags
+ ldw -52(%r3), %r20 ; r20 <- rvalue
+
+ /* Store the result according to the return type. The most
+ likely types should come first. */
+
+L$checkint
+ comib,<>,n FFI_TYPE_INT, %r21, L$checkint8
+ b L$done
+ stw %ret0, 0(%r20)
+
+L$checkint8
+ comib,<>,n FFI_TYPE_UINT8, %r21, L$checkint16
+ b L$done
+ stb %ret0, 0(%r20)
+
+L$checkint16
+ comib,<>,n FFI_TYPE_UINT16, %r21, L$checkdbl
+ b L$done
+ sth %ret0, 0(%r20)
+
+L$checkdbl
+ comib,<>,n FFI_TYPE_DOUBLE, %r21, L$checkfloat
+ b L$done
+ fstd %fr4,0(%r20)
+
+L$checkfloat
+ comib,<>,n FFI_TYPE_FLOAT, %r21, L$checkll
+ b L$done
+ fstw %fr4L,0(%r20)
+
+L$checkll
+ comib,<>,n FFI_TYPE_UINT64, %r21, L$checksmst2
+ stw %ret0, 0(%r20)
+ b L$done
+ stw %ret1, 4(%r20)
+
+L$checksmst2
+ comib,<>,n FFI_TYPE_SMALL_STRUCT2, %r21, L$checksmst3
+ /* 2-byte structs are returned in ret0 as ????xxyy. */
+ extru %ret0, 23, 8, %r22
+ stbs,ma %r22, 1(%r20)
+ b L$done
+ stb %ret0, 0(%r20)
+
+L$checksmst3
+ comib,<>,n FFI_TYPE_SMALL_STRUCT3, %r21, L$checksmst4
+ /* 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 L$done
+ stb %ret0, 0(%r20)
+
+L$checksmst4
+ comib,<>,n FFI_TYPE_SMALL_STRUCT4, %r21, L$checksmst5
+ /* 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 L$done
+ stb %ret0, 0(%r20)
+
+L$checksmst5
+ comib,<>,n FFI_TYPE_SMALL_STRUCT5, %r21, L$checksmst6
+ /* 5 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 L$done
+ stb %ret1, 0(%r20)
+
+L$checksmst6
+ comib,<>,n FFI_TYPE_SMALL_STRUCT6, %r21, L$checksmst7
+ /* 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 L$done
+ stb %ret1, 0(%r20)
+
+L$checksmst7
+ comib,<>,n FFI_TYPE_SMALL_STRUCT7, %r21, L$checksmst8
+ /* 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 L$done
+ stb %ret1, 0(%r20)
+
+L$checksmst8
+ comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, L$done
+ /* 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)
+
+L$done
+ /* all done, return */
+ copy %r4, %sp ; pop arg stack
+ ldw 12(%r3), %r4
+ ldwm -64(%sp), %r3 ; .. and pop stack
+ ldw -20(%sp), %rp
+ bv %r0(%rp)
+ nop
+ .exit
+ .procend
+L$FE1
+
+ /* void ffi_closure_pa32(void);
+ Called with closure argument in %r21 */
+
+ .SPACE $TEXT$
+ .SUBSPA $CODE$
+ .export ffi_closure_pa32,ENTRY,PRIV_LEV=3,RTNVAL=GR
+ .import ffi_closure_inner_pa32,CODE
+ .align 4
+L$FB2
+ffi_closure_pa32
+ .proc
+ .callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
+ .entry
+
+ stw %rp, -20(%sp)
+ copy %r3, %r1
+L$CFI21
+ copy %sp, %r3
+L$CFI22
+ stwm %r1, 64(%sp)
+
+ /* Put arguments onto the stack and call ffi_closure_inner. */
+ stw %arg0, -36(%r3)
+ stw %arg1, -40(%r3)
+ stw %arg2, -44(%r3)
+ stw %arg3, -48(%r3)
+
+ copy %r21, %arg0
+ bl ffi_closure_inner_pa32, %r2
+ copy %r3, %arg1
+ ldwm -64(%sp), %r3
+ ldw -20(%sp), %rp
+ ldw -36(%sp), %ret0
+ bv %r0(%rp)
+ ldw -40(%sp), %ret1
+ .exit
+ .procend
+L$FE2:
+
+ .SPACE $PRIVATE$
+ .SUBSPA $DATA$
+
+ .align 4
+ .EXPORT _GLOBAL__F_ffi_call_pa32,DATA
+_GLOBAL__F_ffi_call_pa32
+L$frame1:
+ .word L$ECIE1-L$SCIE1 ;# Length of Common Information Entry
+L$SCIE1:
+ .word 0x0 ;# CIE Identifier Tag
+ .byte 0x1 ;# CIE Version
+ .ascii "\0" ;# CIE Augmentation
+ .uleb128 0x1 ;# CIE Code Alignment Factor
+ .sleb128 4 ;# CIE Data Alignment Factor
+ .byte 0x2 ;# CIE RA Column
+ .byte 0xc ;# DW_CFA_def_cfa
+ .uleb128 0x1e
+ .uleb128 0x0
+ .align 4
+L$ECIE1:
+L$SFDE1:
+ .word L$EFDE1-L$ASFDE1 ;# FDE Length
+L$ASFDE1:
+ .word L$ASFDE1-L$frame1 ;# FDE CIE offset
+ .word L$FB1 ;# FDE initial location
+ .word L$FE1-L$FB1 ;# FDE address range
+
+ .byte 0x4 ;# DW_CFA_advance_loc4
+ .word L$CFI11-L$FB1
+ .byte 0x83 ;# DW_CFA_offset, column 0x3
+ .uleb128 0x0
+ .byte 0x11 ;# DW_CFA_offset_extended_sf; save r2 at [r30-20]
+ .uleb128 0x2
+ .sleb128 -5
+
+ .byte 0x4 ;# DW_CFA_advance_loc4
+ .word L$CFI12-L$CFI11
+ .byte 0xd ;# DW_CFA_def_cfa_register = r3
+ .uleb128 0x3
+
+ .byte 0x4 ;# DW_CFA_advance_loc4
+ .word L$CFI13-L$CFI12
+ .byte 0x84 ;# DW_CFA_offset, column 0x4
+ .uleb128 0x3
+
+ .align 4
+L$EFDE1:
+
+L$SFDE2:
+ .word L$EFDE2-L$ASFDE2 ;# FDE Length
+L$ASFDE2:
+ .word L$ASFDE2-L$frame1 ;# FDE CIE offset
+ .word L$FB2 ;# FDE initial location
+ .word L$FE2-L$FB2 ;# FDE address range
+ .byte 0x4 ;# DW_CFA_advance_loc4
+ .word L$CFI21-L$FB2
+ .byte 0x83 ;# DW_CFA_offset, column 0x3
+ .uleb128 0x0
+ .byte 0x11 ;# DW_CFA_offset_extended_sf
+ .uleb128 0x2
+ .sleb128 -5
+
+ .byte 0x4 ;# DW_CFA_advance_loc4
+ .word L$CFI12-L$CFI11
+ .byte 0xd ;# DW_CFA_def_cfa_register = r3
+ .uleb128 0x3
+
+ .align 4
+L$EFDE2:
diff --git a/libffi/src/pa/linux.S b/libffi/src/pa/linux.S
index 267cff7b802..322ceb3e7ee 100644
--- a/libffi/src/pa/linux.S
+++ b/libffi/src/pa/linux.S
@@ -31,7 +31,7 @@
.level 1.1
.align 4
- /* void ffi_call_LINUX(void (*)(char *, extended_cif *),
+ /* void ffi_call_pa32(void (*)(char *, extended_cif *),
extended_cif *ecif,
unsigned bytes,
unsigned flags,
@@ -39,12 +39,12 @@
void (*fn)());
*/
- .export ffi_call_LINUX,code
- .import ffi_prep_args_LINUX,code
+ .export ffi_call_pa32,code
+ .import ffi_prep_args_pa32,code
- .type ffi_call_LINUX, @function
+ .type ffi_call_pa32, @function
.LFB1:
-ffi_call_LINUX:
+ffi_call_pa32:
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=4
.entry
@@ -63,7 +63,7 @@ ffi_call_LINUX:
[ 64-bytes register save area ] <- %r4
[ Stack space for actual call, passed as ] <- %arg0
- [ arg0 to ffi_prep_args_LINUX ]
+ [ arg0 to ffi_prep_args_pa32 ]
[ Stack for calling prep_args ] <- %sp
*/
@@ -73,14 +73,14 @@ ffi_call_LINUX:
.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_LINUX,%r2
+ bl ffi_prep_args_pa32,%r2
ldo 64(%arg0), %sp
ldo -64(%sp), %sp
@@ -106,90 +106,139 @@ ffi_call_LINUX:
/* Store the result according to the return type. */
-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)
-
-checksmst567:
- /* 5-7 byte values are returned right justified:
+.Lcheckint:
+ comib,<>,n FFI_TYPE_INT, %r21, .Lcheckint8
+ b .Ldone
+ stw %ret0, 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:
+ 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)
+
+.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)
+
+.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)
+
+.Lchecksmst8:
+ comib,<>,n FFI_TYPE_SMALL_STRUCT8, %r21, .Ldone
+ /* 8 byte values are returned right justified:
ret0 ret1
- 5: ??????aa bbccddee
- 6: ????aabb ccddeeff
- 7: ??aabbcc ddeeffgg
-
- 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:
-
- ret0 ret1 ret1
- 5: ??????aa bbccddee -> eebbccdd (rotate 8)
- 6: ????aabb ccddeeff -> eeffccdd (rotate 16)
- 7: ??aabbcc ddeeffgg -> eeffggdd (rotate 24)
-
- then we write (t1, ret1) into the result. */
-
- 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:
+ 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)
+
+.Ldone:
/* all done, return */
copy %r4, %sp /* pop arg stack */
ldw 12(%r3), %r4
@@ -201,14 +250,14 @@ done:
.procend
.LFE1:
- /* void ffi_closure_LINUX(void);
+ /* void ffi_closure_pa32(void);
Called with closure argument in %r21 */
- .export ffi_closure_LINUX,code
- .import ffi_closure_inner_LINUX,code
+ .export ffi_closure_pa32,code
+ .import ffi_closure_inner_pa32,code
- .type ffi_closure_LINUX, @function
+ .type ffi_closure_pa32, @function
.LFB2:
-ffi_closure_LINUX:
+ffi_closure_pa32:
.proc
.callinfo FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
.entry
@@ -228,7 +277,7 @@ ffi_closure_LINUX:
stw %arg3, -48(%r3)
copy %r21, %arg0
- bl ffi_closure_inner_LINUX, %r2
+ bl ffi_closure_inner_pa32, %r2
copy %r3, %arg1
ldwm -64(%sp), %r3
OpenPOWER on IntegriCloud