fix powerpc native call bugs

This commit is contained in:
Joel Dice 2009-02-15 14:24:20 -07:00
parent de6388a719
commit 773e229112
2 changed files with 18 additions and 11 deletions

View File

@ -13,6 +13,9 @@
.text .text
#define BYTES_PER_WORD 4 #define BYTES_PER_WORD 4
#define LINKAGE_AREA 6
#define GPR_COUNT 8
#define MEMORY_BASE BYTES_PER_WORD * (LINKAGE_AREA + GPR_COUNT)
#define LOCAL(x) L##x #define LOCAL(x) L##x
#ifdef __APPLE__ #ifdef __APPLE__
@ -37,6 +40,7 @@ vmNativeCall:
// r15 : stack frame size // r15 : stack frame size
// r16 : temporary // r16 : temporary
// r17 : temporary // r17 : temporary
// r18 : temporary
// save registers used for local variables // save registers used for local variables
stw r13,24(r1) stw r13,24(r1)
@ -44,6 +48,7 @@ vmNativeCall:
stw r15,32(r1) stw r15,32(r1)
stw r16,36(r1) stw r16,36(r1)
stw r17,40(r1) stw r17,40(r1)
stw r18,44(r1)
// allocate stack space // allocate stack space
stwux r1,r1,r4 stwux r1,r1,r4
@ -57,7 +62,8 @@ vmNativeCall:
LOCAL(loop): LOCAL(loop):
lwzx r17,r16,r5 lwzx r17,r16,r5
stwx r17,r16,r1 addi r18,r16,MEMORY_BASE
stwx r17,r18,r1
addi r16,r16,BYTES_PER_WORD addi r16,r16,BYTES_PER_WORD
LOCAL(test): LOCAL(test):
@ -136,6 +142,7 @@ LOCAL(exit):
lwz r15,32(r1) lwz r15,32(r1)
lwz r16,36(r1) lwz r16,36(r1)
lwz r17,40(r1) lwz r17,40(r1)
lwz r18,44(r1)
// load return address // load return address
lwz r0,8(r1) lwz r0,8(r1)

View File

@ -74,28 +74,28 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes,
} break; } break;
case DOUBLE_TYPE: { case DOUBLE_TYPE: {
if (fprIndex < FprCount) { if (fprIndex + (8 / BytesPerWord) <= FprCount) {
memcpy(fprTable + fprIndex, arguments + ai, 8); memcpy(fprTable + fprIndex, arguments + ai, 8);
++ fprIndex; ++ fprIndex;
gprIndex += BytesPerWord / 4; gprIndex += 8 / BytesPerWord;
stackSkip += BytesPerWord / 4; stackSkip += 8 / BytesPerWord;
} else { } else {
memcpy(stack + stackIndex, arguments + ai, 8); memcpy(stack + stackIndex, arguments + ai, 8);
stackIndex += BytesPerWord / 4; stackIndex += 8 / BytesPerWord;
} }
ai += BytesPerWord / 4; ai += 8 / BytesPerWord;
} break; } break;
case INT64_TYPE: { case INT64_TYPE: {
if (gprIndex + BytesPerWord / 4 <= GprCount) { if (gprIndex + (8 / BytesPerWord) <= GprCount) {
memcpy(gprTable + gprIndex, arguments + ai, 8); memcpy(gprTable + gprIndex, arguments + ai, 8);
gprIndex += BytesPerWord / 4; gprIndex += 8 / BytesPerWord;
stackSkip += BytesPerWord / 4; stackSkip += 8 / BytesPerWord;
} else { } else {
memcpy(stack + stackIndex, arguments + ai, 8); memcpy(stack + stackIndex, arguments + ai, 8);
stackIndex += BytesPerWord / 4; stackIndex += 8 / BytesPerWord;
} }
ai += BytesPerWord / 4; ai += 8 / BytesPerWord;
} break; } break;
default: { default: {