From 128856de79fd9a25c0574e1429aabba9c00905a9 Mon Sep 17 00:00:00 2001 From: Andreas Tobler Date: Sat, 8 Feb 2003 09:04:17 +0100 Subject: [PATCH] darwin_closure.S: Fix alignement bug, allocate 8 bytes for the result. 2003-02-08 Andreas Tobler * libffi/src/powerpc/darwin_closure.S: Fix alignement bug, allocate 8 bytes for the result. * libffi/src/powerpc/aix_closure.S: Likewise. * libffi/src/powerpc/ffi_darwin.c: Update stackframe description for aix/darwin_closure.S. From-SVN: r62574 --- libffi/ChangeLog | 9 ++++ libffi/src/powerpc/aix_closure.S | 37 ++++++++------- libffi/src/powerpc/darwin_closure.S | 74 +++++++++++++++-------------- libffi/src/powerpc/ffi.c | 37 ++++++++------- libffi/src/powerpc/ffi_darwin.c | 49 +++++++++---------- 5 files changed, 112 insertions(+), 94 deletions(-) diff --git a/libffi/ChangeLog b/libffi/ChangeLog index 7cf9711b248d..5dbd1d3a0717 100644 --- a/libffi/ChangeLog +++ b/libffi/ChangeLog @@ -1,3 +1,12 @@ +2003-02-08 Andreas Tobler + + * libffi/src/powerpc/darwin_closure.S: + Fix alignement bug, allocate 8 bytes for the result. + * libffi/src/powerpc/aix_closure.S: + Likewise. + * libffi/src/powerpc/ffi_darwin.c: + Update stackframe description for aix/darwin_closure.S. + 2003-02-07 Andreas Tobler * libffi/src/ffitest.c diff --git a/libffi/src/powerpc/aix_closure.S b/libffi/src/powerpc/aix_closure.S index 7fa96f1fc954..d0d50ca56bde 100644 --- a/libffi/src/powerpc/aix_closure.S +++ b/libffi/src/powerpc/aix_closure.S @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- - aix_closures.S - Copyright (c) 2002 Free Software Foundation, Inc. - based on darwin_closures.S + aix_closure.S - Copyright (c) 2002 2003 Free Software Foundation, Inc. + based on darwin_closure.S PowerPC Assembly glue. @@ -106,24 +106,25 @@ ffi_closure_ASM: /* 24 Bytes (Linkage Area) */ /* 32 Bytes (params) */ /* 104 Bytes (13*8 from FPR) */ - /* 4 Bytes (result) - /* 164 Bytes */ + /* 8 Bytes (result) + /* 168 Bytes */ - stwu r1,-164(r1) /* skip over caller save area */ + stwu r1,-176(r1) /* skip over caller save area + keep stack aligned to 16 */ /* we want to build up an area for the parameters passed */ /* in registers (both floating point and integer) */ - /* we store gpr 3 to gpr 10 (aligned to 4) */ - /* in the parents outgoing area */ - stw r3, 188(r1) - stw r4, 192(r1) - stw r5, 196(r1) - stw r6, 200(r1) - stw r7, 204(r1) - stw r8, 208(r1) - stw r9, 212(r1) - stw r10, 216(r1) + /* we store gpr 3 to gpr 10 (aligned to 4) + in the parents outgoing area */ + stw r3, 200(r1) + stw r4, 204(r1) + stw r5, 208(r1) + stw r6, 212(r1) + stw r7, 216(r1) + stw r8, 220(r1) + stw r9, 224(r1) + stw r10, 228(r1) /* next save fpr 1 to fpr 13 (aligned to 8) */ stfd f1, 56(r1) @@ -148,14 +149,14 @@ ffi_closure_ASM: addi r4,r1,160 /* now load up the pointer to the saved gpr registers */ - addi r5,r1,188 + addi r5,r1,200 /* now load up the pointer to the saved fpr registers */ addi r6,r1,56 /* now load up the pointer to the outgoing parameter */ /* stack in the previous frame */ - addi r7,r1,220 + addi r7,r1,232 /* make the call */ bl .ffi_closure_helper_DARWIN @@ -243,7 +244,7 @@ L..58: /* case void / done */ L..44: - addi r1,r1,164 /* restore stack pointer */ + addi r1,r1,176 /* restore stack pointer */ lwz r0,8(r1) /* get return address */ mtlr r0 /* reset link register */ blr diff --git a/libffi/src/powerpc/darwin_closure.S b/libffi/src/powerpc/darwin_closure.S index 9e54d2231b9e..fbc334affeb0 100644 --- a/libffi/src/powerpc/darwin_closure.S +++ b/libffi/src/powerpc/darwin_closure.S @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------- - darwin_closures.S - Copyright (c) 2002 Free Software Foundation, Inc. - based on ppc_closures.S + darwin_closure.S - Copyright (c) 2002 2003 Free Software Foundation, + Inc. based on ppc_closure.S PowerPC Assembly glue. @@ -37,31 +37,32 @@ .text .align 2 _ffi_closure_ASM: +LFB1: + mflr r0 /* extract return address */ + stw r0, 8(r1) /* save the return address */ +LCFI0: + /* 24 Bytes (Linkage Area) + 32 Bytes (outgoing parameter area, always reserved) + 104 Bytes (13*8 from FPR) + 8 Bytes (result) + 168 Bytes */ - mflr r0 /* extract return address */ - stw r0, 8(r1) /* save the return address */ + stwu r1,-176(r1) /* skip over caller save area + keep stack aligned to 16 */ +LCFI1: + /* we want to build up an area for the parameters passed + in registers (both floating point and integer) */ - /* 24 Bytes (Linkage Area) */ - /* 32 Bytes (outgoing parameter area, always reserved) */ - /* 104 Bytes (13*8 from FPR) */ - /* 4 Bytes (result) - /* 164 Bytes */ - - stwu r1,-164(r1) /* skip over caller save area */ - -/* we want to build up an area for the parameters passed */ -/* in registers (both floating point and integer) */ - - /* we store gpr 3 to gpr 10 (aligned to 4) */ - /* in the parents outgoing area */ - stw r3, 188(r1) - stw r4, 192(r1) - stw r5, 196(r1) - stw r6, 200(r1) - stw r7, 204(r1) - stw r8, 208(r1) - stw r9, 212(r1) - stw r10, 216(r1) + /* we store gpr 3 to gpr 10 (aligned to 4) + in the parents outgoing area */ + stw r3, 200(r1) + stw r4, 204(r1) + stw r5, 208(r1) + stw r6, 212(r1) + stw r7, 216(r1) + stw r8, 220(r1) + stw r9, 224(r1) + stw r10, 228(r1) /* we save fpr 1 to fpr 13 (aligned to 8) */ stfd f1, 56(r1) @@ -85,15 +86,15 @@ _ffi_closure_ASM: /* now load up the pointer to the result storage */ addi r4,r1,160 - /* now load up the pointer to the saved gpr registers */ - addi r5,r1,188 + /* now load up the pointer to the saved gpr registers */ + addi r5,r1,200 /* now load up the pointer to the saved fpr registers */ addi r6,r1,56 - /* now load up the pointer to the outgoing parameter */ - /* stack in the previous frame */ - addi r7,r1,220 + /* now load up the pointer to the outgoing parameter + stack in the previous frame */ + addi r7,r1,232 /* make the call */ bl L(_ffi_closure_helper_DARWIN) @@ -111,7 +112,9 @@ _ffi_closure_ASM: lwzx r3,r4,r3 /* get the contents of that table value */ add r3,r3,r4 /* add contents of table to table address */ mtctr r3 - bctr /* jump to it */ + bctr /* jump to it */ +LFE1: + .align 2 .L60: .long .L44-.L60 /* FFI_TYPE_VOID */ @@ -180,10 +183,9 @@ _ffi_closure_ASM: /* case void / done */ .L44: - addi r1,r1,164 /* restore stack pointer */ - lwz r0,8(r1) /* get return address */ - mtlr r0 /* reset link register */ + addi r1,r1,176 /* restore stack pointer */ + lwz r0,8(r1) /* get return address */ + mtlr r0 /* reset link register */ blr -/* END(ffi_closure_ASM) */ - +/* END(ffi_closure_ASM) */ diff --git a/libffi/src/powerpc/ffi.c b/libffi/src/powerpc/ffi.c index c93aec0ed874..ea1a14e8f65d 100644 --- a/libffi/src/powerpc/ffi.c +++ b/libffi/src/powerpc/ffi.c @@ -137,11 +137,20 @@ void ffi_prep_args(extended_cif *ecif, unsigned *const stack) switch ((*ptr)->type) { case FFI_TYPE_FLOAT: - case FFI_TYPE_DOUBLE: - if ((*ptr)->type == FFI_TYPE_FLOAT) - double_tmp = *(float *)*p_argv; + double_tmp = *(float *)*p_argv; + if (fparg_count >= NUM_FPR_ARG_REGISTERS) + { + *(float *)next_arg = (float)double_tmp; + next_arg += 1; + } else - double_tmp = *(double *)*p_argv; + *fpr_base++ = double_tmp; + fparg_count++; + FFI_ASSERT(flags & FLAG_FP_ARGUMENTS); + break; + + case FFI_TYPE_DOUBLE: + double_tmp = *(double *)*p_argv; if (fparg_count >= NUM_FPR_ARG_REGISTERS) { @@ -320,6 +329,10 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) switch ((*ptr)->type) { case FFI_TYPE_FLOAT: + fparg_count++; + /* floating singles are not 8-aligned on stack */ + break; + case FFI_TYPE_DOUBLE: fparg_count++; /* If this FP arg is going on the stack, it must be @@ -612,20 +625,15 @@ ffi_closure_helper_SYSV (ffi_closure* closure, void * rvalue, case FFI_TYPE_FLOAT: /* unfortunately float values are stored as doubles * in the ffi_closure_SYSV code (since we don't check - * the type in that routine). This is also true - * of floats passed on the outgoing parameter stack. - * Also, on the outgoing stack all values are aligned - * to 8 - * - * Don't you just love the simplicity of this ABI! + * the type in that routine). */ /* there are 8 64bit floating point registers */ if (nf < 8) { - temp = *(double*)pfr; + temp = *(double*)pfr; *(float*)pfr = (float)temp; - avalue[i] = pfr; + avalue[i] = pfr; nf++; pfr+=2; } else { @@ -634,12 +642,9 @@ ffi_closure_helper_SYSV (ffi_closure* closure, void * rvalue, * parameter stack. This is probably a really * naughty thing to do but... */ - if (((long)pst) & 4) pst++; - temp = *(double*)pst; - *(float*)pst = (float)temp; avalue[i] = pst; nf++; - pst+=2; + pst+=1; } break; diff --git a/libffi/src/powerpc/ffi_darwin.c b/libffi/src/powerpc/ffi_darwin.c index 36d83b92a607..3f705275c5f3 100644 --- a/libffi/src/powerpc/ffi_darwin.c +++ b/libffi/src/powerpc/ffi_darwin.c @@ -6,8 +6,6 @@ Darwin ABI support (c) 2001 John Hornkvist AIX ABI support (c) 2002 Free Software Foundation, Inc. - $Id: ffi_darwin.c,v 1.4 2002/03/07 18:24:42 dje Exp $ - 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 @@ -412,38 +410,40 @@ typedef struct aix_fd_struct { +---------------------------------------+ 20 | saved TOC pointer 4 | +---------------------------------------+ 24 - | always reserved 8*4=32 (revious GPRs)| + | always reserved 8*4=32 (previous GPRs)| | according to the linkage convention | - | from AIX | + | from AIX | +---------------------------------------+ 56 - | our FPR area 13*8=104 | - | f1 | - | . | - | f13 | + | our FPR area 13*8=104 | + | f1 | + | . | + | f13 | +---------------------------------------+ 160 - | result area 4 | -SP current --> +---------------------------------------+ 164 <- parent frame - | back chain to caller 4 | + | result area 8 | +---------------------------------------+ 168 + | alignement to the next multiple of 16 | +SP current --> +---------------------------------------+ 176 <- parent frame + | back chain to caller 4 | + +---------------------------------------+ 180 | saved CR 4 | - +---------------------------------------+ 172 + +---------------------------------------+ 184 | saved LR 4 | - +---------------------------------------+ 176 + +---------------------------------------+ 188 | reserved for compilers 4 | - +---------------------------------------+ 180 + +---------------------------------------+ 192 | reserved for binders 4 | - +---------------------------------------+ 184 + +---------------------------------------+ 196 | saved TOC pointer 4 | - +---------------------------------------+ 188 + +---------------------------------------+ 200 | always reserved 8*4=32 we store our | - | GPRs here | - | r3 | - | . | - | r10 | - +---------------------------------------+ 220 - | PST area, overflow part | + | GPRs here | + | r3 | + | . | + | r10 | + +---------------------------------------+ 232 + | PST area, overflow part | +---------------------------------------+ xxx - | ???? | + | ???? | +---------------------------------------+ xxx */ @@ -455,6 +455,7 @@ ffi_prep_closure (ffi_closure* closure, { unsigned int *tramp; struct ffi_aix_trampoline_struct *tramp_aix; + aix_fd *fd; switch (cif->abi) { @@ -486,7 +487,7 @@ ffi_prep_closure (ffi_closure* closure, case FFI_AIX: tramp_aix = (struct ffi_aix_trampoline_struct *) (closure->tramp); - aix_fd *fd = (aix_fd *)(void *)ffi_closure_ASM; + fd = (aix_fd *)(void *)ffi_closure_ASM; FFI_ASSERT (cif->abi == FFI_AIX); -- 2.47.2