# HG changeset patch # User Some Random Person # Date 1331440705 28800 # Node ID ecbdb74cad970b205c06999b082f24331f619fa9 # Parent 712218cdc4ba46a217d65d143fe099aaf6d26237 Made separate Hardware_Dependent directory and moved primitives to there diff -r 712218cdc4ba -r ecbdb74cad97 Hardware_Dependent/VMS__HW_measurement.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware_Dependent/VMS__HW_measurement.h Sat Mar 10 20:38:25 2012 -0800 @@ -0,0 +1,49 @@ +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _VMS__HW_MEASUREMENT_H +#define _VMS__HW_MEASUREMENT_H +#define _GNU_SOURCE + +//=================== Macros to Capture Measurements ====================== +// +//===== RDTSC wrapper ===== +//Also runs with x86_64 code +#define saveTSCLowHigh(lowHighIn) \ + asm volatile("RDTSC; \ + movl %%eax, %0; \ + movl %%edx, %1;" \ + /* outputs */ : "=m" (lowHighIn.lowHigh[0]), "=m" (lowHighIn.lowHigh[1])\ + /* inputs */ : \ + /* clobber */ : "%eax", "%edx" \ + ); + +#define saveTimeStampCountInto(low, high) \ + asm volatile("RDTSC; \ + movl %%eax, %0; \ + movl %%edx, %1;" \ + /* outputs */ : "=m" (low), "=m" (high)\ + /* inputs */ : \ + /* clobber */ : "%eax", "%edx" \ + ); + +#define saveLowTimeStampCountInto(low) \ + asm volatile("RDTSC; \ + movl %%eax, %0;" \ + /* outputs */ : "=m" (low) \ + /* inputs */ : \ + /* clobber */ : "%eax", "%edx" \ + ); + + //For code that calculates normalization-offset between TSC counts of + // different cores. +//#define NUM_TSC_ROUND_TRIPS 10 + + +#endif /* */ + diff -r 712218cdc4ba -r ecbdb74cad97 Hardware_Dependent/VMS__primitives.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware_Dependent/VMS__primitives.c Sat Mar 10 20:38:25 2012 -0800 @@ -0,0 +1,53 @@ +/* + * This File contains all hardware dependent C code. + */ + + +#include "../VMS.h" + +/*Set up the stack with __cdecl structure on it + * Except doing a trick for 64 bits, where put top-level fn pointer on + * stack, then call an assembly helper that copies it into a reg and + * jumps to it. So, set the resumeInstrPtr to the helper-assembly. + *No need to save registers on old stack frame, because there's no old + * animator state to return to + * + *This was factored into separate function because it's used stand-alone in + * some wrapper-libraries (but only "int" version, to warn users to check + * carefully that it's safe) + */ +inline void +VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr, + void *dataParam) + { void *stackPtr; + +// Start of Hardware dependent part + + //Set slave's instr pointer to a helper Fn that copies params from stack + slaveVP->resumeInstrPtr = (TopLevelFnPtr)&startUpTopLevelFn; + + //fnPtr takes two params -- void *dataParam & void *animSlv + // Stack grows *down*, so start it at highest stack addr, minus room + // for 2 params + return addr. + stackPtr = + (void *)slaveVP->startOfStack + VIRT_PROCR_STACK_SIZE - 4*sizeof(void*); + + //setup __cdecl on stack + //Normally, return Addr is in loc pointed to by stackPtr, but doing a + // trick for 64 bit arch, where put ptr to top-level fn there instead, + // and set resumeInstrPtr to a helper-fn that copies the top-level + // fn ptr and params into registers. + //Then, dataParam is at stackPtr + 8 bytes, & animating SlaveVP above + *((SlaveVP**)stackPtr + 2 ) = slaveVP; //rightmost param + *((void**)stackPtr + 1 ) = dataParam; //next param to left + *((void**)stackPtr) = (void*)fnPtr; //copied to reg by helper Fn + + +// end of Hardware dependent part + + //core controller will switch to stack & frame pointers stored in slave, + // suspend will save processor's stack and frame into slave + slaveVP->stackPtr = slaveVP->startOfStack; + slaveVP->framePtr = slaveVP->startOfStack; + } + diff -r 712218cdc4ba -r ecbdb74cad97 Hardware_Dependent/VMS__primitives.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware_Dependent/VMS__primitives.h Sat Mar 10 20:38:25 2012 -0800 @@ -0,0 +1,41 @@ +/* + * Copyright 2009 OpenSourceStewardshipFoundation.org + * Licensed under GNU General Public License version 2 + * + * Author: seanhalle@yahoo.com + * + */ + +#ifndef _VMS__PRIMITIVES_H +#define _VMS__PRIMITIVES_H +#define _GNU_SOURCE + +void +recordCoreCtlrReturnLabelAddr(void **returnAddress); + +void +switchToSlv(SlaveVP *nextSlave); + +void +switchToCoreCtlr(SlaveVP *nextSlave); + +void +masterSwitchToCoreCtlr(SlaveVP *nextSlave); + +void +startUpTopLevelFn(); + +void * +asmTerminateCoreCtlr(SlaveVP *currSlv); + +#define flushRegisters() \ + asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15") + +void +VMS_int__save_return_into_ptd_to_loc_then_do_ret(void *ptdToLoc); + +void +VMS_int__return_to_addr_in_ptd_to_loc(void *ptdToLoc); + +#endif /* _VMS__HW_DEPENDENT_H */ + diff -r 712218cdc4ba -r ecbdb74cad97 Hardware_Dependent/VMS__primitives.s --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware_Dependent/VMS__primitives.s Sat Mar 10 20:38:25 2012 -0800 @@ -0,0 +1,167 @@ +.data + + +.text + +//Save return label address for the coreCtlr to pointer +//Arguments: Pointer to variable holding address +.globl recordCoreCtlrReturnLabelAddr +recordCoreCtlrReturnLabelAddr: + movq $coreCtlrReturn, %rcx #load label address + movq %rcx, (%rdi) #save address to pointer + ret + + +//Trick for 64 bit arch -- copies args from stack into regs, then does jmp to +// the top-level function, which was pointed to by the stack-ptr +.globl startUpTopLevelFn +startUpTopLevelFn: + movq %rdi , %rsi #get second argument from first argument of switchSlv + movq 0x08(%rsp), %rdi #get first argument from stack + movq (%rsp) , %rax #get top-level function's addr from stack + jmp *%rax #jump to the top-level function + +//Switches form CoreCtlr to either a normal Slv VP or the Master VP +//switch to VP's stack and frame ptr then jump to VP's next-instr-ptr +/* SlaveVP offsets: + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 resumeInstrPtr + * 0x30 coreCtlrFramePtr + * 0x38 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x48 coreCtlrReturnPt + * 0x54 masterLock + */ +.globl switchToSlv +switchToSlv: + #SlaveVP in %rdi + movq %rsp , 0x38(%rdi) #save core ctlr stack pointer + movq %rbp , 0x30(%rdi) #save core ctlr frame pointer + movq 0x10(%rdi), %rsp #restore stack pointer + movq 0x18(%rdi), %rbp #restore frame pointer + movq 0x20(%rdi), %rax #get jmp pointer + jmp *%rax #jmp to Slv +coreCtlrReturn: + ret + + +//switches to core controller. saves return address +/* SlaveVP offsets: + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 resumeInstrPtr + * 0x30 coreCtlrFramePtr + * 0x38 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x48 coreCtlrReturnPt + * 0x54 masterLock + */ +.globl switchToCoreCtlr +switchToCoreCtlr: + #SlaveVP in %rdi + movq $SlvReturn, 0x20(%rdi) #store return address + movq %rsp , 0x10(%rdi) #save stack pointer + movq %rbp , 0x18(%rdi) #save frame pointer + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx) , %rcx + movq 0x48(%rcx), %rax #get CoreCtlrStartPt + jmp *%rax #jmp to CoreCtlr +SlvReturn: + ret + + + +//switches to core controller from master. saves return address +//Releases masterLock so the next MasterLoop can be executed +/* SlaveVP offsets: + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 resumeInstrPtr + * 0x30 coreCtlrFramePtr + * 0x38 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x48 coreCtlrReturnPt + * 0x54 masterLock + */ +.globl masterSwitchToCoreCtlr +masterSwitchToCoreCtlr: + #SlaveVP in %rdi + movq $MasterReturn, 0x20(%rdi) #store return address + movq %rsp , 0x10(%rdi) #save stack pointer + movq %rbp , 0x18(%rdi) #save frame pointer + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx) , %rcx + movq 0x48(%rcx), %rax #get CoreCtlr return pt + movl $0x0 , 0x54(%rcx) #release lock + jmp *%rax #jmp to CoreCtlr +MasterReturn: + ret + + +//Switch to terminateCoreCtlr +//therefor switch to coreCtlr context from master context +// no need to call because the stack is already set up for switchSlv +// and Slv is in %rdi +// and both functions have the same argument. +// do not save register of Slv because this function will never return +/* SlaveVP offsets: + * 0x10 stackPtr + * 0x18 framePtr + * 0x20 resumeInstrPtr + * 0x30 coreCtlrFramePtr + * 0x38 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x48 coreCtlrReturnPt + * 0x58 masterLock + */ +.globl asmTerminateCoreCtlr +asmTerminateCoreCtlr: + #SlaveVP in %rdi + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + movq $terminateCoreCtlr, %rax + jmp *%rax #jmp to CoreCtlr + + +/* + * This one for the sequential version is special. It discards the current stack + * and returns directly from the coreCtlr after VMS_WL__dissipate_slaveVP was called + */ +.globl asmTerminateCoreCtlrSeq +asmTerminateCoreCtlrSeq: + #SlaveVP in %rdi + movq 0x38(%rdi), %rsp #restore stack pointer + movq 0x30(%rdi), %rbp #restore frame pointer + #argument is in %rdi + call VMS_int__dissipate_slaveVP + movq %rbp , %rsp #goto the coreCtlrs stack + pop %rbp #restore the old framepointer + ret #return from core controller + + +//Takes the return addr off the stack and saves into the loc pointed to by +// by the parameter passed in via rdi. Return addr is at 0x8(%rbp) for 64bit +.globl VMS_int__save_return_into_ptd_to_loc_then_do_ret +VMS_int__save_return_into_ptd_to_loc_then_do_ret: + movq 0x8(%rbp), %rax #get ret address, rbp is the same as in the calling function + movq %rax, (%rdi) #write ret addr into addr passed as param field + ret + + +//Assembly code changes the return addr on the stack to the one +// pointed to by the parameter, then returns. Stack's return addr is at 0x8(%rbp) +.globl VMS_int__return_to_addr_in_ptd_to_loc +VMS_int__return_to_addr_in_ptd_to_loc: + movq (%rdi), %rax #get return addr from addr passed as param + movq %rax, 0x8(%rbp) #write return addr to the stack of the caller + ret + diff -r 712218cdc4ba -r ecbdb74cad97 VMS__HW_dependent.c --- a/VMS__HW_dependent.c Sat Mar 10 20:35:38 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * This File contains all hardware dependent C code. - */ - - -#include "VMS.h" - -/*Set up the stack with __cdecl structure on it - * Except doing a trick for 64 bits, where put top-level fn pointer on - * stack, then call an assembly helper that copies it into a reg and - * jumps to it. So, set the resumeInstrPtr to the helper-assembly. - *No need to save registers on old stack frame, because there's no old - * animator state to return to - * - *This was factored into separate function because it's used stand-alone in - * some wrapper-libraries (but only "int" version, to warn users to check - * carefully that it's safe) - */ -inline void -VMS_int__point_slaveVP_to_Fn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr, - void *dataParam) - { void *stackPtr; - -// Start of Hardware dependent part - - //Set slave's instr pointer to a helper Fn that copies params from stack - slaveVP->resumeInstrPtr = (TopLevelFnPtr)&startUpTopLevelFn; - - //fnPtr takes two params -- void *dataParam & void *animSlv - // Stack grows *down*, so start it at highest stack addr, minus room - // for 2 params + return addr. - stackPtr = - (void *)slaveVP->startOfStack + VIRT_PROCR_STACK_SIZE - 4*sizeof(void*); - - //setup __cdecl on stack - //Normally, return Addr is in loc pointed to by stackPtr, but doing a - // trick for 64 bit arch, where put ptr to top-level fn there instead, - // and set resumeInstrPtr to a helper-fn that copies the top-level - // fn ptr and params into registers. - //Then, dataParam is at stackPtr + 8 bytes, & animating SlaveVP above - *((SlaveVP**)stackPtr + 2 ) = slaveVP; //rightmost param - *((void**)stackPtr + 1 ) = dataParam; //next param to left - *((void**)stackPtr) = (void*)fnPtr; //copied to reg by helper Fn - - -// end of Hardware dependent part - - //core loop will switch to stack & frame pointers stored in slave, - // suspend will save processor's stack and frame into slave - slaveVP->stackPtr = slaveVP->startOfStack; - slaveVP->framePtr = slaveVP->startOfStack; - } - diff -r 712218cdc4ba -r ecbdb74cad97 VMS__HW_dependent.h --- a/VMS__HW_dependent.h Sat Mar 10 20:35:38 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * Copyright 2009 OpenSourceStewardshipFoundation.org - * Licensed under GNU General Public License version 2 - * - * Author: seanhalle@yahoo.com - * - */ - -#ifndef _VMS__HW_DEPENDENT_H -#define _VMS__HW_DEPENDENT_H -#define _GNU_SOURCE - -void -recordCoreLoopReturnLabelAddr(void **returnAddress); - -void -switchToSlv(SlaveVP *nextSlave); - -void -switchToCoreLoop(SlaveVP *nextSlave); - -void -masterSwitchToCoreLoop(SlaveVP *nextSlave); - -void -startUpTopLevelFn(); - -void * -asmTerminateCoreLoop(SlaveVP *currSlv); - -#define flushRegisters() \ - asm volatile ("":::"%rbx", "%r12", "%r13","%r14","%r15") - -void -VMS_int__save_return_into_ptd_to_loc_then_do_ret(void *ptdToLoc); - -void -VMS_int__return_to_addr_in_ptd_to_loc(void *ptdToLoc); - -//=================== Macros to Capture Measurements ====================== -// -//===== RDTSC wrapper ===== -//Also runs with x86_64 code -#define saveTSCLowHigh(lowHighIn) \ - asm volatile("RDTSC; \ - movl %%eax, %0; \ - movl %%edx, %1;" \ - /* outputs */ : "=m" (lowHighIn.lowHigh[0]), "=m" (lowHighIn.lowHigh[1])\ - /* inputs */ : \ - /* clobber */ : "%eax", "%edx" \ - ); - -#define saveTimeStampCountInto(low, high) \ - asm volatile("RDTSC; \ - movl %%eax, %0; \ - movl %%edx, %1;" \ - /* outputs */ : "=m" (low), "=m" (high)\ - /* inputs */ : \ - /* clobber */ : "%eax", "%edx" \ - ); - -#define saveLowTimeStampCountInto(low) \ - asm volatile("RDTSC; \ - movl %%eax, %0;" \ - /* outputs */ : "=m" (low) \ - /* inputs */ : \ - /* clobber */ : "%eax", "%edx" \ - ); - - //For code that calculates normalization-offset between TSC counts of - // different cores. -//#define NUM_TSC_ROUND_TRIPS 10 - - -#endif /* _VMS__HW_DEPENDENT_H */ - diff -r 712218cdc4ba -r ecbdb74cad97 VMS__HW_dependent.s --- a/VMS__HW_dependent.s Sat Mar 10 20:35:38 2012 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -.data - - -.text - -//Save return label address for the coreLoop to pointer -//Arguments: Pointer to variable holding address -.globl saveCoreLoopReturnAddr -recordCoreLoopReturnLabelAddr: - movq $coreLoopReturn, %rcx #load label address - movq %rcx, (%rdi) #save address to pointer - ret - - -//Trick for 64 bit arch -- copies args from stack into regs, then does jmp to -// the top-level function, which was pointed to by the stack-ptr -.globl startUpTopLevelFn -startUpTopLevelFn: - movq %rdi , %rsi #get second argument from first argument of switchSlv - movq 0x08(%rsp), %rdi #get first argument from stack - movq (%rsp) , %rax #get top-level function's addr from stack - jmp *%rax #jump to the top-level function - -//Switches form CoreLoop to either a normal Slv VP or the Master VP -//switch to VP's stack and frame ptr then jump to VP's next-instr-ptr -/* SlaveVP offsets: - * 0x10 stackPtr - * 0x18 framePtr - * 0x20 resumeInstrPtr - * 0x30 coreLoopFramePtr - * 0x38 coreLoopStackPtr - * - * _VMSMasterEnv offsets: - * 0x48 coreLoopReturnPt - * 0x54 masterLock - */ -.globl switchToSlv -switchToSlv: - #SlaveVP in %rdi - movq %rsp , 0x38(%rdi) #save core loop stack pointer - movq %rbp , 0x30(%rdi) #save core loop frame pointer - movq 0x10(%rdi), %rsp #restore stack pointer - movq 0x18(%rdi), %rbp #restore frame pointer - movq 0x20(%rdi), %rax #get jmp pointer - jmp *%rax #jmp to Slv -coreLoopReturn: - ret - - -//switches to core loop. saves return address -/* SlaveVP offsets: - * 0x10 stackPtr - * 0x18 framePtr - * 0x20 resumeInstrPtr - * 0x30 coreLoopFramePtr - * 0x38 coreLoopStackPtr - * - * _VMSMasterEnv offsets: - * 0x48 coreLoopReturnPt - * 0x54 masterLock - */ -.globl switchToCoreLoop -switchToCoreLoop: - #SlaveVP in %rdi - movq $SlvReturn, 0x20(%rdi) #store return address - movq %rsp , 0x10(%rdi) #save stack pointer - movq %rbp , 0x18(%rdi) #save frame pointer - movq 0x38(%rdi), %rsp #restore stack pointer - movq 0x30(%rdi), %rbp #restore frame pointer - movq $_VMSMasterEnv, %rcx - movq (%rcx) , %rcx - movq 0x48(%rcx), %rax #get CoreLoopStartPt - jmp *%rax #jmp to CoreLoop -SlvReturn: - ret - - - -//switches to core loop from master. saves return address -//Releases masterLock so the next MasterLoop can be executed -/* SlaveVP offsets: - * 0x10 stackPtr - * 0x18 framePtr - * 0x20 resumeInstrPtr - * 0x30 coreLoopFramePtr - * 0x38 coreLoopStackPtr - * - * _VMSMasterEnv offsets: - * 0x48 coreLoopReturnPt - * 0x54 masterLock - */ -.globl masterSwitchToCoreLoop -masterSwitchToCoreLoop: - #SlaveVP in %rdi - movq $MasterReturn, 0x20(%rdi) #store return address - movq %rsp , 0x10(%rdi) #save stack pointer - movq %rbp , 0x18(%rdi) #save frame pointer - movq 0x38(%rdi), %rsp #restore stack pointer - movq 0x30(%rdi), %rbp #restore frame pointer - movq $_VMSMasterEnv, %rcx - movq (%rcx) , %rcx - movq 0x48(%rcx), %rax #get CoreLoopStartPt - movl $0x0 , 0x54(%rcx) #release lock - jmp *%rax #jmp to CoreLoop -MasterReturn: - ret - - -//Switch to terminateCoreLoop -//therefor switch to coreLoop context from master context -// no need to call because the stack is already set up for switchSlv -// and Slv is in %rdi -// and both functions have the same argument. -// do not save register of Slv because this function will never return -/* SlaveVP offsets: - * 0x10 stackPtr - * 0x18 framePtr - * 0x20 resumeInstrPtr - * 0x30 coreLoopFramePtr - * 0x38 coreLoopStackPtr - * - * _VMSMasterEnv offsets: - * 0x48 coreLoopReturnPt - * 0x58 masterLock - */ -.globl asmTerminateCoreLoop -asmTerminateCoreLoop: - #SlaveVP in %rdi - movq 0x38(%rdi), %rsp #restore stack pointer - movq 0x30(%rdi), %rbp #restore frame pointer - movq $terminateCoreLoop, %rax - jmp *%rax #jmp to CoreLoop - - -/* - * This one for the sequential version is special. It discards the current stack - * and returns directly from the coreLoop after VMS_WL__dissipate_slaveVP was called - */ -.globl asmTerminateCoreLoopSeq -asmTerminateCoreLoopSeq: - #SlaveVP in %rdi - movq 0x38(%rdi), %rsp #restore stack pointer - movq 0x30(%rdi), %rbp #restore frame pointer - #argument is in %rdi - call VMS_int__dissipate_slaveVP - movq %rbp , %rsp #goto the coreLoops stack - pop %rbp #restore the old framepointer - ret #return from core loop - - -//Takes the return addr off the stack and saves into the loc pointed to by -// by the parameter passed in via rdi. Return addr is at 0x8(%rbp) for 64bit -.globl VMS_int__save_return_into_ptd_to_loc_then_do_ret -VMS_int__save_return_into_ptd_to_loc_then_do_ret: - movq 0x8(%rbp), %rax #get ret address, rbp is the same as in the calling function - movq %rax, (%rdi) #write ret addr into addr passed as param field - ret - - -//Assembly code changes the return addr on the stack to the one -// pointed to by the parameter, then returns. Stack's return addr is at 0x8(%rbp) -.globl VMS_int__return_to_addr_in_ptd_to_loc -VMS_int__return_to_addr_in_ptd_to_loc: - movq (%rdi), %rax #get return addr from addr passed as param - movq %rax, 0x8(%rbp) #write return addr to the stack of the caller - ret -