From ba4e2a6582cce530b9e64dcaabc9b662cb31c4b4 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 16 Feb 2009 08:21:12 -0700 Subject: [PATCH] rename compile.S to compile-x86.S and add compile-powerpc.S --- makefile | 2 +- src/compile-powerpc.S | 121 +++++++++++++++++++++++++++++++ src/{compile.S => compile-x86.S} | 2 + 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/compile-powerpc.S rename src/{compile.S => compile-x86.S} (95%) diff --git a/makefile b/makefile index 9bc47fbbbc..c1730ac85f 100644 --- a/makefile +++ b/makefile @@ -224,7 +224,7 @@ ifeq ($(process),compile) $(src)/compiler.cpp \ $(src)/$(asm).cpp - vm-asm-sources += $(src)/compile.S + vm-asm-sources += $(src)/compile-$(asm).S endif vm-cpp-objects = $(call cpp-objects,$(vm-sources),$(src),$(native-build)) diff --git a/src/compile-powerpc.S b/src/compile-powerpc.S new file mode 100644 index 0000000000..c7a1f54512 --- /dev/null +++ b/src/compile-powerpc.S @@ -0,0 +1,121 @@ +/* Copyright (c) 2009, Avian Contributors + + Permission to use, copy, modify, and/or distribute this software + for any purpose with or without fee is hereby granted, provided + that the above copyright notice and this permission notice appear + in all copies. + + There is NO WARRANTY for this software. See license.txt for + details. */ + +#include "types.h" + +.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__ +.globl _vmInvoke +_vmInvoke: +#else +.globl vmInvoke +vmInvoke: +#endif + // save return address + mflr r0 + stw r0,8(r1) + + // r3: thread + // r4: function + // r5: parameters + // r6: parameterCount + // r7: frameSize + // r8: returnType (ignored) + + // r9: temporary + + // allocate stack space, adding room for callee-saved registers + addi r9,r7,80 + stwux r1,r1,r9 + + // save callee-saved registers + add r9,r7,r1 + + stw r13,0(r9) + stw r14,4(r9) + stw r15,8(r9) + stw r16,12(r9) + stw r17,16(r9) + stw r18,20(r9) + stw r19,24(r9) + stw r20,28(r9) + stw r21,32(r9) + stw r22,36(r9) + stw r23,40(r9) + stw r24,44(r9) + stw r25,48(r9) + stw r26,52(r9) + stw r27,56(r9) + stw r28,60(r9) + stw r29,64(r9) + stw r30,68(r9) + stw r31,72(r9) + + // we use r13 to hold the thread pointer, by convention + mr r13,r3 + + // copy arguments into place + li r16,0 + b LOCAL(test) + +LOCAL(loop): + lwzx r17,r16,r5 + addi r18,r16,MEMORY_BASE + stwx r17,r18,r1 + addi r16,r16,BYTES_PER_WORD + +LOCAL(test): + cmplw r16,r6 + blt LOCAL(loop) + + // load and call function address + mtctr r4 + bctrl + + // restore stack pointer + lwz r1,0(r1) + + // restore callee-saved registers + subi r9,r1,80 + + lwz r13,0(r9) + lwz r14,4(r9) + lwz r15,8(r9) + lwz r16,12(r9) + lwz r17,16(r9) + lwz r18,20(r9) + lwz r19,24(r9) + lwz r20,28(r9) + lwz r21,32(r9) + lwz r22,36(r9) + lwz r23,40(r9) + lwz r24,44(r9) + lwz r25,48(r9) + lwz r26,52(r9) + lwz r27,56(r9) + lwz r28,60(r9) + lwz r29,64(r9) + lwz r30,68(r9) + lwz r31,72(r9) + + // load return address + lwz r0,8(r1) + mtlr r0 + + // return + blr diff --git a/src/compile.S b/src/compile-x86.S similarity index 95% rename from src/compile.S rename to src/compile-x86.S index 9da3957912..73e08b4bd1 100644 --- a/src/compile.S +++ b/src/compile-x86.S @@ -34,6 +34,7 @@ vmInvoke: // %rcx: stackSize // %r8 : returnType + // we use rbx to hold the thread pointer, by convention mov %rdi,%rbx // copy arguments into place @@ -94,6 +95,7 @@ vmInvoke: // 20(%ebp): stackSize // 24(%ebp): returnType + // we use ebx to hold the thread pointer, by convention mov 8(%ebp),%ebx // copy arguments into place