diff --git a/src/powerpc.S b/src/powerpc.S index 80f44bf3d9..8bc084f1c8 100644 --- a/src/powerpc.S +++ b/src/powerpc.S @@ -13,6 +13,9 @@ .text #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 #ifdef __APPLE__ @@ -37,6 +40,7 @@ vmNativeCall: // r15 : stack frame size // r16 : temporary // r17 : temporary + // r18 : temporary // save registers used for local variables stw r13,24(r1) @@ -44,6 +48,7 @@ vmNativeCall: stw r15,32(r1) stw r16,36(r1) stw r17,40(r1) + stw r18,44(r1) // allocate stack space stwux r1,r1,r4 @@ -57,7 +62,8 @@ vmNativeCall: LOCAL(loop): lwzx r17,r16,r5 - stwx r17,r16,r1 + addi r18,r16,MEMORY_BASE + stwx r17,r18,r1 addi r16,r16,BYTES_PER_WORD LOCAL(test): @@ -136,6 +142,7 @@ LOCAL(exit): lwz r15,32(r1) lwz r16,36(r1) lwz r17,40(r1) + lwz r18,44(r1) // load return address lwz r0,8(r1) diff --git a/src/powerpc.h b/src/powerpc.h index 002fca65df..00e5488f4e 100644 --- a/src/powerpc.h +++ b/src/powerpc.h @@ -74,28 +74,28 @@ dynamicCall(void* function, uintptr_t* arguments, uint8_t* argumentTypes, } break; case DOUBLE_TYPE: { - if (fprIndex < FprCount) { + if (fprIndex + (8 / BytesPerWord) <= FprCount) { memcpy(fprTable + fprIndex, arguments + ai, 8); ++ fprIndex; - gprIndex += BytesPerWord / 4; - stackSkip += BytesPerWord / 4; + gprIndex += 8 / BytesPerWord; + stackSkip += 8 / BytesPerWord; } else { memcpy(stack + stackIndex, arguments + ai, 8); - stackIndex += BytesPerWord / 4; + stackIndex += 8 / BytesPerWord; } - ai += BytesPerWord / 4; + ai += 8 / BytesPerWord; } break; case INT64_TYPE: { - if (gprIndex + BytesPerWord / 4 <= GprCount) { + if (gprIndex + (8 / BytesPerWord) <= GprCount) { memcpy(gprTable + gprIndex, arguments + ai, 8); - gprIndex += BytesPerWord / 4; - stackSkip += BytesPerWord / 4; + gprIndex += 8 / BytesPerWord; + stackSkip += 8 / BytesPerWord; } else { memcpy(stack + stackIndex, arguments + ai, 8); - stackIndex += BytesPerWord / 4; + stackIndex += 8 / BytesPerWord; } - ai += BytesPerWord / 4; + ai += 8 / BytesPerWord; } break; default: {