partial fix for PowerPC build

This commit is contained in:
Joel Dice 2011-01-29 20:04:29 -07:00
parent 8064b702c0
commit 1187613ad0
4 changed files with 170 additions and 30 deletions

View File

@ -24,12 +24,12 @@
# define GLOBAL(x) x # define GLOBAL(x) x
#endif #endif
#define THREAD_STACK 2144 #define THREAD_STACK 2148
#define THREAD_CONTINUATION 2148 #define THREAD_CONTINUATION 2156
#define THREAD_EXCEPTION 44 #define THREAD_EXCEPTION 44
#define THREAD_EXCEPTION_STACK_ADJUSTMENT 2152 #define THREAD_EXCEPTION_STACK_ADJUSTMENT 2160
#define THREAD_EXCEPTION_OFFSET 2156 #define THREAD_EXCEPTION_OFFSET 2164
#define THREAD_EXCEPTION_HANDLER 2160 #define THREAD_EXCEPTION_HANDLER 2168
#define CONTINUATION_NEXT 4 #define CONTINUATION_NEXT 4
#define CONTINUATION_ADDRESS 16 #define CONTINUATION_ADDRESS 16

View File

@ -19,12 +19,13 @@
#define LOCAL(x) L##x #define LOCAL(x) L##x
#ifdef __APPLE__ #ifdef __APPLE__
.globl _vmNativeCall # define GLOBAL(x) _##x
_vmNativeCall:
#else #else
.globl vmNativeCall # define GLOBAL(x) x
vmNativeCall:
#endif #endif
.globl GLOBAL(vmNativeCall)
GLOBAL(vmNativeCall):
// save return address // save return address
mflr r0 mflr r0
stw r0,8(r1) stw r0,8(r1)
@ -151,16 +152,80 @@ LOCAL(exit):
// return // return
blr blr
#ifdef __APPLE__ .globl GLOBAL(vmJump)
.globl _vmJump GLOBAL(vmJump):
_vmJump:
#else
.globl vmJump
vmJump:
#endif
mtlr r3 mtlr r3
mr r1,r5 mr r1,r5
mr r13,r6 mr r13,r6
mr r4,r7 mr r4,r7
mr r3,r8 mr r3,r8
blr blr
#define CHECKPOINT_THREAD 4
#define CHECKPOINT_STACK 24
.globl GLOBAL(vmRun)
GLOBAL(vmRun):
// r3: function
// r4: arguments
// r5: checkpoint
mflr r0
stw r0,8(r1)
stwu r1,-(MEMORY_BASE+80)(r1)
stw r13,MEMORY_BASE+0(r1)
stw r14,MEMORY_BASE+4(r1)
stw r15,MEMORY_BASE+8(r1)
stw r16,MEMORY_BASE+12(r1)
stw r17,MEMORY_BASE+16(r1)
stw r18,MEMORY_BASE+20(r1)
stw r19,MEMORY_BASE+24(r1)
stw r20,MEMORY_BASE+28(r1)
stw r21,MEMORY_BASE+32(r1)
stw r22,MEMORY_BASE+36(r1)
stw r23,MEMORY_BASE+40(r1)
stw r24,MEMORY_BASE+44(r1)
stw r25,MEMORY_BASE+48(r1)
stw r26,MEMORY_BASE+52(r1)
stw r27,MEMORY_BASE+56(r1)
stw r28,MEMORY_BASE+60(r1)
stw r29,MEMORY_BASE+64(r1)
stw r30,MEMORY_BASE+68(r1)
stw r31,MEMORY_BASE+72(r1)
stw r1,CHECKPOINT_STACK(r5)
mr r6,r3
lwz r3,CHECKPOINT_THREAD(r5)
mtctr r6
bctrl
.globl GLOBAL(vmRun_returnAddress)
GLOBAL(vmRun_returnAddress):
lwz r13,MEMORY_BASE+0(r1)
lwz r14,MEMORY_BASE+4(r1)
lwz r15,MEMORY_BASE+8(r1)
lwz r16,MEMORY_BASE+12(r1)
lwz r17,MEMORY_BASE+16(r1)
lwz r18,MEMORY_BASE+20(r1)
lwz r19,MEMORY_BASE+24(r1)
lwz r20,MEMORY_BASE+28(r1)
lwz r21,MEMORY_BASE+32(r1)
lwz r22,MEMORY_BASE+36(r1)
lwz r23,MEMORY_BASE+40(r1)
lwz r24,MEMORY_BASE+44(r1)
lwz r25,MEMORY_BASE+48(r1)
lwz r26,MEMORY_BASE+52(r1)
lwz r27,MEMORY_BASE+56(r1)
lwz r28,MEMORY_BASE+60(r1)
lwz r29,MEMORY_BASE+64(r1)
lwz r30,MEMORY_BASE+68(r1)
lwz r31,MEMORY_BASE+72(r1)
lwz r1,0(r1)
lwz r0,8(r1)
mtlr r0
blr

View File

@ -1691,6 +1691,55 @@ memoryBarrier(Context* c)
// END OPERATION COMPILERS // END OPERATION COMPILERS
unsigned
argumentFootprint(unsigned footprint)
{
return max(pad(footprint, StackAlignmentInWords), StackAlignmentInWords);
}
void
nextFrame(ArchitectureContext* c UNUSED, int32_t* start, unsigned size UNUSED,
unsigned footprint, int32_t*, void* link, void*,
unsigned targetParameterFootprint, void** ip, void** stack)
{
assert(c, *ip >= start);
assert(c, *ip <= start + (size / BytesPerWord));
int32_t* instruction = static_cast<int32_t*>(*ip);
if ((*start >> 26) == 32) {
// skip stack overflow check
start += 3;
}
if (instruction <= start + 2
or *instruction == lwz(0, 1, 8)
or *instruction == mtlr(0)
or *instruction == blr())
{
*ip = link;
return;
}
unsigned offset = footprint;
if (TailCalls) {
if (argumentFootprint(targetParameterFootprint) > StackAlignmentInWords) {
offset += argumentFootprint(targetParameterFootprint)
- StackAlignmentInWords;
}
// check for post-non-tail-call stack adjustment of the form "lwzx
// r0,0(r1); stwux r0,offset(r1)":
// todo
// todo: check for and handle tail calls
}
*ip = static_cast<void**>(*stack)[offset + 2];
*stack = static_cast<void**>(*stack) + offset;
}
void void
populateTables(ArchitectureContext* c) populateTables(ArchitectureContext* c)
@ -1847,7 +1896,11 @@ class MyArchitecture: public Assembler::Architecture {
} }
virtual unsigned argumentFootprint(unsigned footprint) { virtual unsigned argumentFootprint(unsigned footprint) {
return max(pad(footprint, StackAlignmentInWords), StackAlignmentInWords); return ::argumentFootprint(footprint);
}
virtual bool argumentAlignment() {
return false;
} }
virtual unsigned argumentRegisterCount() { virtual unsigned argumentRegisterCount() {
@ -1916,6 +1969,15 @@ class MyArchitecture: public Assembler::Architecture {
return (ceiling(sizeInWords + FrameFooterSize, alignment) * alignment); return (ceiling(sizeInWords + FrameFooterSize, alignment) * alignment);
} }
virtual void nextFrame(void* start, unsigned size, unsigned footprint,
int32_t* frameTable, void* link, void* stackLimit,
unsigned targetParameterFootprint, void** ip,
void** stack)
{
::nextFrame(&c, static_cast<int32_t*>(start), size, footprint, frameTable,
link, stackLimit, targetParameterFootprint, ip, stack);
}
virtual void* frameIp(void* stack) { virtual void* frameIp(void* stack) {
return stack ? static_cast<void**>(stack)[2] : 0; return stack ? static_cast<void**>(stack)[2] : 0;
} }
@ -2141,7 +2203,7 @@ class MyAssembler: public Assembler {
return arch_; return arch_;
} }
virtual void saveFrame(unsigned stackOffset, unsigned) { virtual void saveFrame(unsigned stackOffset) {
Register returnAddress(0); Register returnAddress(0);
emit(&c, mflr(returnAddress.low)); emit(&c, mflr(returnAddress.low));
@ -2206,16 +2268,16 @@ class MyAssembler: public Assembler {
moveAndUpdateRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst); moveAndUpdateRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst);
} }
virtual void adjustFrame(unsigned footprint) { virtual void adjustFrame(unsigned difference) {
Register nextStack(0); Register nextStack(0);
Memory stackSrc(StackRegister, 0); Memory stackSrc(StackRegister, 0);
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &nextStack); moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &nextStack);
Memory stackDst(StackRegister, -footprint * BytesPerWord); Memory stackDst(StackRegister, -difference * BytesPerWord);
moveAndUpdateRM(&c, BytesPerWord, &nextStack, BytesPerWord, &stackDst); moveAndUpdateRM(&c, BytesPerWord, &nextStack, BytesPerWord, &stackDst);
} }
virtual void popFrame() { virtual void popFrame(unsigned) {
Register stack(StackRegister); Register stack(StackRegister);
Memory stackSrc(StackRegister, 0); Memory stackSrc(StackRegister, 0);
moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &stack); moveMR(&c, BytesPerWord, &stackSrc, BytesPerWord, &stack);
@ -2262,15 +2324,17 @@ class MyAssembler: public Assembler {
moveRM(&c, BytesPerWord, &fps, BytesPerWord, &dst); moveRM(&c, BytesPerWord, &fps, BytesPerWord, &dst);
} }
} else { } else {
popFrame(); popFrame(footprint);
} }
} else { } else {
abort(&c); abort(&c);
} }
} }
virtual void popFrameAndPopArgumentsAndReturn(unsigned argumentFootprint) { virtual void popFrameAndPopArgumentsAndReturn(unsigned frameFootprint,
popFrame(); unsigned argumentFootprint)
{
popFrame(frameFootprint);
assert(&c, argumentFootprint >= StackAlignmentInWords); assert(&c, argumentFootprint >= StackAlignmentInWords);
assert(&c, (argumentFootprint % StackAlignmentInWords) == 0); assert(&c, (argumentFootprint % StackAlignmentInWords) == 0);
@ -2289,9 +2353,10 @@ class MyAssembler: public Assembler {
return_(&c); return_(&c);
} }
virtual void popFrameAndUpdateStackAndReturn(unsigned stackOffsetFromThread) virtual void popFrameAndUpdateStackAndReturn(unsigned frameFootprint,
unsigned stackOffsetFromThread)
{ {
popFrame(); popFrame(frameFootprint);
Register tmp1(0); Register tmp1(0);
Memory stackSrc(StackRegister, 0); Memory stackSrc(StackRegister, 0);
@ -2401,6 +2466,14 @@ class MyAssembler: public Assembler {
return c.code.length(); return c.code.length();
} }
virtual unsigned frameEventCount() {
return 0;
}
virtual FrameEvent* firstFrameEvent() {
return 0;
}
virtual void dispose() { virtual void dispose() {
c.code.dispose(); c.code.dispose();
} }

View File

@ -14,20 +14,22 @@
#include "types.h" #include "types.h"
#include "common.h" #include "common.h"
#define VA_LIST(x) (x)
#ifdef __APPLE__ #ifdef __APPLE__
# if __DARWIN_UNIX03 && defined(_STRUCT_PPC_EXCEPTION_STATE) # if __DARWIN_UNIX03 && defined(_STRUCT_PPC_EXCEPTION_STATE)
# define IP_REGISTER(context) (context->uc_mcontext->__ss.__srr0) # define IP_REGISTER(context) (context->uc_mcontext->__ss.__srr0)
# define STACK_REGISTER(context) (context->uc_mcontext->__ss.__r1) # define STACK_REGISTER(context) (context->uc_mcontext->__ss.__r1)
# define THREAD_REGISTER(context) (context->uc_mcontext->__ss.__r13) # define THREAD_REGISTER(context) (context->uc_mcontext->__ss.__r13)
# define LINK_REGISTER(context) (context->uc_mcontext->__ss.__lr)
# else # else
# define IP_REGISTER(context) (context->uc_mcontext->ss.srr0) # define IP_REGISTER(context) (context->uc_mcontext->ss.srr0)
# define STACK_REGISTER(context) (context->uc_mcontext->ss.r1) # define STACK_REGISTER(context) (context->uc_mcontext->ss.r1)
# define THREAD_REGISTER(context) (context->uc_mcontext->ss.r13) # define THREAD_REGISTER(context) (context->uc_mcontext->ss.r13)
# define LINK_REGISTER(context) (context->uc_mcontext->ss.lr)
# endif # endif
#else #else
# define IP_REGISTER(context) (context->uc_mcontext.gregs[32]) # error "non-Apple PowerPC-based platforms not yet supported"
# define STACK_REGISTER(context) (context->uc_mcontext.gregs[1])
# define THREAD_REGISTER(context) (context->uc_mcontext.gregs[13])
#endif #endif
extern "C" uint64_t extern "C" uint64_t