fix OS X PowerPC parameter passing

We were not always placing parameters in the correct stack positions
in the PowerPC implementations of dynamicCall and vmNativeCall.  In
particular, the first stack slot used to hold a parameter depends on
the sizes and types of the preceding parameters which are passed in
registers.
This commit is contained in:
Joel Dice 2011-03-15 17:20:44 -06:00
parent 93b3d3d8a6
commit 51c8d7511a
2 changed files with 40 additions and 38 deletions

View File

@ -36,13 +36,14 @@ GLOBAL(vmNativeCall):
mflr r0 mflr r0
stw r0,RETURN_ADDRESS_OFFSET(r1) stw r0,RETURN_ADDRESS_OFFSET(r1)
// r3 aka r13: function // r3 aka r13: function
// r4 : stackTotal // r4 : stackTotal
// r5 : memoryTable // r5 : memoryTable
// r6 : memoryCount // r6 : memoryCount
// r7 : gprTable // r7 : memoryBase
// r8 : fprTable // r8 : gprTable
// r9 aka r14: returnType // r9 : fprTable
// r10 aka r14: returnType
// r15 : stack frame size // r15 : stack frame size
// r16 : temporary // r16 : temporary
@ -51,34 +52,34 @@ GLOBAL(vmNativeCall):
// allocate stack space, adding room for callee-saved registers and // allocate stack space, adding room for callee-saved registers and
// scratch space for copying a FP return value into GPRs // scratch space for copying a FP return value into GPRs
subfic r10,r4,-48 subfic r11,r4,-48
stwux r1,r1,r10 stwux r1,r1,r11
// save callee-saved registers used for local variables // save callee-saved registers used for local variables
add r10,r4,r1 add r11,r4,r1
// save registers used for local variables // save registers used for local variables
stw r13,0(r10) stw r13,0(r11)
stw r14,4(r10) stw r14,4(r11)
stw r15,8(r10) stw r15,8(r11)
stw r16,12(r10) stw r16,12(r11)
stw r17,16(r10) stw r17,16(r11)
stw r18,20(r10) stw r18,20(r11)
stw r19,24(r10) stw r19,24(r11)
// remember where we saved the local variables // remember where we saved the local variables
mr r19,r10 mr r19,r11
// save our argument registers so we can clobber them // save our argument registers so we can clobber them
mr r13,r3 mr r13,r3
mr r14,r9 mr r14,r10
li r16,0 li r16,0
b LOCAL(test) b LOCAL(test)
LOCAL(loop): LOCAL(loop):
lwzx r17,r16,r5 lwzx r17,r16,r5
addi r18,r16,MEMORY_BASE add r18,r16,r7
stwx r17,r18,r1 stwx r17,r18,r1
addi r16,r16,BYTES_PER_WORD addi r16,r16,BYTES_PER_WORD
@ -87,33 +88,33 @@ LOCAL(test):
blt LOCAL(loop) blt LOCAL(loop)
// do we need to load the floating point registers? // do we need to load the floating point registers?
cmpwi r8,0 cmpwi r9,0
beq LOCAL(gpr) beq LOCAL(gpr)
// yes, we do // yes, we do
lfd f1,0(r8) lfd f1,0(r9)
lfd f2,8(r8) lfd f2,8(r9)
lfd f3,16(r8) lfd f3,16(r9)
lfd f4,24(r8) lfd f4,24(r9)
lfd f5,32(r8) lfd f5,32(r9)
lfd f6,40(r8) lfd f6,40(r9)
lfd f7,48(r8) lfd f7,48(r9)
lfd f8,56(r8) lfd f8,56(r9)
#ifdef __APPLE__ #ifdef __APPLE__
lfd f9,64(r8) lfd f9,64(r9)
lfd f10,72(r8) lfd f10,72(r9)
lfd f11,80(r8) lfd f11,80(r9)
lfd f12,88(r8) lfd f12,88(r9)
lfd f13,96(r8) lfd f13,96(r9)
#endif #endif
LOCAL(gpr): LOCAL(gpr):
// do we need to load the general-purpose registers? // do we need to load the general-purpose registers?
cmpwi r7,0 cmpwi r8,0
beq LOCAL(call) beq LOCAL(call)
// yes, we do // yes, we do
mr r16,r7 mr r16,r8
lwz r3,0(r16) lwz r3,0(r16)
lwz r4,4(r16) lwz r4,4(r16)
lwz r5,8(r16) lwz r5,8(r16)

View File

@ -57,8 +57,8 @@
extern "C" uint64_t extern "C" uint64_t
vmNativeCall(void* function, unsigned stackTotal, void* memoryTable, vmNativeCall(void* function, unsigned stackTotal, void* memoryTable,
unsigned memoryCount, void* gprTable, void* fprTable, unsigned memoryCount, unsigned memoryBase,
unsigned returnType); void* gprTable, void* fprTable, unsigned returnType);
namespace vm { namespace vm {
@ -239,6 +239,7 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
(function, (function,
(((1 + stackSkip + stackIndex) * BytesPerWord) + LinkageArea + 15) & -16, (((1 + stackSkip + stackIndex) * BytesPerWord) + LinkageArea + 15) & -16,
stack, stackIndex * BytesPerWord, stack, stackIndex * BytesPerWord,
LinkageArea + (stackSkip * BytesPerWord),
(gprIndex ? gprTable : 0), (gprIndex ? gprTable : 0),
(fprIndex ? fprTable : 0), returnType); (fprIndex ? fprTable : 0), returnType);
} }