# HG changeset patch # User Some Random Person # Date 1333313626 25200 # Node ID 1cfcf49dc7ab67b9bb18b52d60c74027cadb6360 # Parent 7ed97c9619019c5edb0fb2c0f45970a0abd147ef renamed Hardware_Dependent dir to HW_Dependent_Primitives diff -r 7ed97c961901 -r 1cfcf49dc7ab HW_Dependent_Primitives/VMS__HW_measurement.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HW_Dependent_Primitives/VMS__HW_measurement.c Sun Apr 01 13:53:46 2012 -0700 @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "../VMS.h" + +void setup_perf_counters(){ +#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS + struct perf_event_attr hw_event; + memset(&hw_event,0,sizeof(hw_event)); + hw_event.type = PERF_TYPE_HARDWARE; + hw_event.size = sizeof(hw_event); + hw_event.disabled = 1; + hw_event.freq = 0; + hw_event.inherit = 1; /* children inherit it */ + hw_event.pinned = 1; /* must always be on PMU */ + hw_event.exclusive = 0; /* only group on PMU */ + hw_event.exclude_user = 0; /* don't count user */ + hw_event.exclude_kernel = 0; /* ditto kernel */ + hw_event.exclude_hv = 0; /* ditto hypervisor */ + hw_event.exclude_idle = 0; /* don't count when idle */ + hw_event.mmap = 0; /* include mmap data */ + hw_event.comm = 0; /* include comm data */ + + int coreIdx; + for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) + { + hw_event.config = 0x0000000000000000; //cycles + _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, + 0,//pid_t pid, + coreIdx,//int cpu, + -1,//int group_fd, + 0//unsigned long flags + ); + if (_VMSMasterEnv->cycles_counter_fd[coreIdx]<0){ + fprintf(stderr,"On core %d: ",coreIdx); + perror("Failed to open cycles counter"); + } + hw_event.config = 0x0000000000000001; //instrs + _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, + 0,//pid_t pid, + coreIdx,//int cpu, + -1,//int group_fd, + 0//unsigned long flags + ); + if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){ + fprintf(stderr,"On core %d: ",coreIdx); + perror("Failed to open instrs counter"); + } + } + + prctl(PR_TASK_PERF_EVENTS_ENABLE); +#endif +} + +__inline__ uint64_t rdtsc(){ + uint32_t lo, hi; + __asm__ __volatile__ ( // serialize + "xorl %%eax,%%eax \n cpuid" + ::: "%rax", "%rbx", "%rcx", "%rdx"); + __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); + /* asm volatile("RDTSC;" + "movl %%eax, %0;" + "movl %%edx, %1;" + : "=m" (lo), "=m" (hi) + : + : "%eax", "%edx" + ); */ + return (uint64_t)hi << 32 | lo; +} \ No newline at end of file diff -r 7ed97c961901 -r 1cfcf49dc7ab HW_Dependent_Primitives/VMS__HW_measurement.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HW_Dependent_Primitives/VMS__HW_measurement.h Sun Apr 01 13:53:46 2012 -0700 @@ -0,0 +1,63 @@ +/* + * 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 ====================== + +typedef union + { uint32 lowHigh[2]; + uint64 longVal; + } +TSCountLowHigh; + + +//=================== 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" \ + ); + +inline TSCount getTSCount(); + + + //For code that calculates normalization-offset between TSC counts of + // different cores. +//#define NUM_TSC_ROUND_TRIPS 10 + +void setup_perf_counters(); +uint64_t rdtsc(void); +#endif /* */ + diff -r 7ed97c961901 -r 1cfcf49dc7ab HW_Dependent_Primitives/VMS__primitives.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HW_Dependent_Primitives/VMS__primitives.c Sun Apr 01 13:53:46 2012 -0700 @@ -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 = stackPtr; + slaveVP->framePtr = stackPtr; + } + diff -r 7ed97c961901 -r 1cfcf49dc7ab HW_Dependent_Primitives/VMS__primitives.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HW_Dependent_Primitives/VMS__primitives.h Sun Apr 01 13:53:46 2012 -0700 @@ -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 7ed97c961901 -r 1cfcf49dc7ab HW_Dependent_Primitives/VMS__primitives_asm.s --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HW_Dependent_Primitives/VMS__primitives_asm.s Sun Apr 01 13:53:46 2012 -0700 @@ -0,0 +1,168 @@ +.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: + * 0x00 stackPtr + * 0x08 framePtr + * 0x10 resumeInstrPtr + * 0x18 coreCtlrFramePtr + * 0x20 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x00 coreCtlrReturnPt + * 0x100 masterLock + */ +.globl switchToSlv +switchToSlv: + #SlaveVP in %rdi + movq %rsp , 0x20(%rdi) #save core ctlr stack pointer + movq %rbp , 0x18(%rdi) #save core ctlr frame pointer + movq 0x00(%rdi), %rsp #restore stack pointer + movq 0x08(%rdi), %rbp #restore frame pointer + movq 0x10(%rdi), %rax #get jmp pointer + jmp *%rax #jmp to Slv +coreCtlrReturn: + ret + + +//switches to core controller. saves return address +/* SlaveVP offsets: + * 0x00 stackPtr + * 0x08 framePtr + * 0x10 resumeInstrPtr + * 0x18 coreCtlrFramePtr + * 0x20 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x00 coreCtlrReturnPt + * 0x100 masterLock + */ +.globl switchToCoreCtlr +switchToCoreCtlr: + #SlaveVP in %rdi + movq $SlvReturn, 0x10(%rdi) #store return address + movq %rsp , 0x00(%rdi) #save stack pointer + movq %rbp , 0x08(%rdi) #save frame pointer + movq 0x20(%rdi), %rsp #restore stack pointer + movq 0x18(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx), %rcx #_VMSMasterEnv is pointer to struct + movq 0x00(%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 AnimationMaster can be executed +/* SlaveVP offsets: + * 0x00 stackPtr + * 0x08 framePtr + * 0x10 resumeInstrPtr + * 0x18 coreCtlrFramePtr + * 0x20 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x00 coreCtlrReturnPt + * 0x100 masterLock + */ +.globl masterSwitchToCoreCtlr +masterSwitchToCoreCtlr: + #SlaveVP in %rdi + movq $MasterReturn, 0x10(%rdi) #store return address + movq %rsp , 0x00(%rdi) #save stack pointer + movq %rbp , 0x08(%rdi) #save frame pointer + movq 0x20(%rdi), %rsp #restore stack pointer + movq 0x18(%rdi), %rbp #restore frame pointer + movq $_VMSMasterEnv, %rcx + movq (%rcx), %rcx #_VMSMasterEnv is pointer to struct + movq 0x00(%rcx), %rax #get CoreCtlr return pt + movl $0x0 , 0x100(%rcx) #release lock + jmp *%rax #jmp to CoreCtlr +MasterReturn: + ret + + +/*Switch to terminateCoreCtlr + *This is called by endOSThreadFn, which is the top-level function given + * to a shutdown slave. When such a slave gets switched to, by the core + * controller, it runs the top-level function, which calls this, which + * then calls terminateCoreCtlr, which ends the pthread. Note, when get + * here, stack is already set up for switchSlv and Slv ptr is in %rdi. + *Do not save registers of Slv because this function will never return + * + * SlaveVP offsets: + * 0x00 stackPtr + * 0x08 framePtr + * 0x10 resumeInstrPtr + * 0x18 coreCtlrFramePtr + * 0x20 coreCtlrStackPtr + * + * _VMSMasterEnv offsets: + * 0x00 coreCtlrReturnPt + * 0x100 masterLock + */ +.globl asmTerminateCoreCtlr +asmTerminateCoreCtlr: #SlaveVP ptr is in %rdi + movq 0x20(%rdi), %rsp #restore stack pointer + movq 0x18(%rdi), %rbp #restore frame pointer + movq $terminateCoreCtlr, %rax + jmp *%rax #jmp to fn that ends the pthread + + +/* + * 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 0x20(%rdi), %rsp #restore stack pointer + movq 0x18(%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 0x08(%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, 0x08(%rbp) #write return addr to the stack of the caller + ret + diff -r 7ed97c961901 -r 1cfcf49dc7ab Hardware_Dependent/VMS__HW_measurement.c --- a/Hardware_Dependent/VMS__HW_measurement.c Wed Mar 28 18:01:44 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "../VMS.h" - -void setup_perf_counters(){ -#ifdef HOLISTIC__TURN_ON_PERF_COUNTERS - struct perf_event_attr hw_event; - memset(&hw_event,0,sizeof(hw_event)); - hw_event.type = PERF_TYPE_HARDWARE; - hw_event.size = sizeof(hw_event); - hw_event.disabled = 1; - hw_event.freq = 0; - hw_event.inherit = 1; /* children inherit it */ - hw_event.pinned = 1; /* must always be on PMU */ - hw_event.exclusive = 0; /* only group on PMU */ - hw_event.exclude_user = 0; /* don't count user */ - hw_event.exclude_kernel = 0; /* ditto kernel */ - hw_event.exclude_hv = 0; /* ditto hypervisor */ - hw_event.exclude_idle = 0; /* don't count when idle */ - hw_event.mmap = 0; /* include mmap data */ - hw_event.comm = 0; /* include comm data */ - - int coreIdx; - for( coreIdx = 0; coreIdx < NUM_CORES; coreIdx++ ) - { - hw_event.config = 0x0000000000000000; //cycles - _VMSMasterEnv->cycles_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, - 0,//pid_t pid, - coreIdx,//int cpu, - -1,//int group_fd, - 0//unsigned long flags - ); - if (_VMSMasterEnv->cycles_counter_fd[coreIdx]<0){ - fprintf(stderr,"On core %d: ",coreIdx); - perror("Failed to open cycles counter"); - } - hw_event.config = 0x0000000000000001; //instrs - _VMSMasterEnv->instrs_counter_fd[coreIdx] = syscall(__NR_perf_event_open, &hw_event, - 0,//pid_t pid, - coreIdx,//int cpu, - -1,//int group_fd, - 0//unsigned long flags - ); - if (_VMSMasterEnv->instrs_counter_fd[coreIdx]<0){ - fprintf(stderr,"On core %d: ",coreIdx); - perror("Failed to open instrs counter"); - } - } - - prctl(PR_TASK_PERF_EVENTS_ENABLE); -#endif -} - -__inline__ uint64_t rdtsc(){ - uint32_t lo, hi; - __asm__ __volatile__ ( // serialize - "xorl %%eax,%%eax \n cpuid" - ::: "%rax", "%rbx", "%rcx", "%rdx"); - __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi)); - /* asm volatile("RDTSC;" - "movl %%eax, %0;" - "movl %%edx, %1;" - : "=m" (lo), "=m" (hi) - : - : "%eax", "%edx" - ); */ - return (uint64_t)hi << 32 | lo; -} \ No newline at end of file diff -r 7ed97c961901 -r 1cfcf49dc7ab Hardware_Dependent/VMS__HW_measurement.h --- a/Hardware_Dependent/VMS__HW_measurement.h Wed Mar 28 18:01:44 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * 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 ====================== - -typedef union - { uint32 lowHigh[2]; - uint64 longVal; - } -TSCountLowHigh; - - -//=================== 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" \ - ); - -inline TSCount getTSCount(); - - - //For code that calculates normalization-offset between TSC counts of - // different cores. -//#define NUM_TSC_ROUND_TRIPS 10 - -void setup_perf_counters(); -uint64_t rdtsc(void); -#endif /* */ - diff -r 7ed97c961901 -r 1cfcf49dc7ab Hardware_Dependent/VMS__primitives.c --- a/Hardware_Dependent/VMS__primitives.c Wed Mar 28 18:01:44 2012 +0200 +++ /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 controller will switch to stack & frame pointers stored in slave, - // suspend will save processor's stack and frame into slave - slaveVP->stackPtr = stackPtr; - slaveVP->framePtr = stackPtr; - } - diff -r 7ed97c961901 -r 1cfcf49dc7ab Hardware_Dependent/VMS__primitives.h --- a/Hardware_Dependent/VMS__primitives.h Wed Mar 28 18:01:44 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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 7ed97c961901 -r 1cfcf49dc7ab Hardware_Dependent/VMS__primitives_asm.s --- a/Hardware_Dependent/VMS__primitives_asm.s Wed Mar 28 18:01:44 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -.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: - * 0x00 stackPtr - * 0x08 framePtr - * 0x10 resumeInstrPtr - * 0x18 coreCtlrFramePtr - * 0x20 coreCtlrStackPtr - * - * _VMSMasterEnv offsets: - * 0x00 coreCtlrReturnPt - * 0x100 masterLock - */ -.globl switchToSlv -switchToSlv: - #SlaveVP in %rdi - movq %rsp , 0x20(%rdi) #save core ctlr stack pointer - movq %rbp , 0x18(%rdi) #save core ctlr frame pointer - movq 0x00(%rdi), %rsp #restore stack pointer - movq 0x08(%rdi), %rbp #restore frame pointer - movq 0x10(%rdi), %rax #get jmp pointer - jmp *%rax #jmp to Slv -coreCtlrReturn: - ret - - -//switches to core controller. saves return address -/* SlaveVP offsets: - * 0x00 stackPtr - * 0x08 framePtr - * 0x10 resumeInstrPtr - * 0x18 coreCtlrFramePtr - * 0x20 coreCtlrStackPtr - * - * _VMSMasterEnv offsets: - * 0x00 coreCtlrReturnPt - * 0x100 masterLock - */ -.globl switchToCoreCtlr -switchToCoreCtlr: - #SlaveVP in %rdi - movq $SlvReturn, 0x10(%rdi) #store return address - movq %rsp , 0x00(%rdi) #save stack pointer - movq %rbp , 0x08(%rdi) #save frame pointer - movq 0x20(%rdi), %rsp #restore stack pointer - movq 0x18(%rdi), %rbp #restore frame pointer - movq $_VMSMasterEnv, %rcx - movq (%rcx), %rcx #_VMSMasterEnv is pointer to struct - movq 0x00(%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 AnimationMaster can be executed -/* SlaveVP offsets: - * 0x00 stackPtr - * 0x08 framePtr - * 0x10 resumeInstrPtr - * 0x18 coreCtlrFramePtr - * 0x20 coreCtlrStackPtr - * - * _VMSMasterEnv offsets: - * 0x00 coreCtlrReturnPt - * 0x100 masterLock - */ -.globl masterSwitchToCoreCtlr -masterSwitchToCoreCtlr: - #SlaveVP in %rdi - movq $MasterReturn, 0x10(%rdi) #store return address - movq %rsp , 0x00(%rdi) #save stack pointer - movq %rbp , 0x08(%rdi) #save frame pointer - movq 0x20(%rdi), %rsp #restore stack pointer - movq 0x18(%rdi), %rbp #restore frame pointer - movq $_VMSMasterEnv, %rcx - movq (%rcx), %rcx #_VMSMasterEnv is pointer to struct - movq 0x00(%rcx), %rax #get CoreCtlr return pt - movl $0x0 , 0x100(%rcx) #release lock - jmp *%rax #jmp to CoreCtlr -MasterReturn: - ret - - -/*Switch to terminateCoreCtlr - *This is called by endOSThreadFn, which is the top-level function given - * to a shutdown slave. When such a slave gets switched to, by the core - * controller, it runs the top-level function, which calls this, which - * then calls terminateCoreCtlr, which ends the pthread. Note, when get - * here, stack is already set up for switchSlv and Slv ptr is in %rdi. - *Do not save registers of Slv because this function will never return - * - * SlaveVP offsets: - * 0x00 stackPtr - * 0x08 framePtr - * 0x10 resumeInstrPtr - * 0x18 coreCtlrFramePtr - * 0x20 coreCtlrStackPtr - * - * _VMSMasterEnv offsets: - * 0x00 coreCtlrReturnPt - * 0x100 masterLock - */ -.globl asmTerminateCoreCtlr -asmTerminateCoreCtlr: #SlaveVP ptr is in %rdi - movq 0x20(%rdi), %rsp #restore stack pointer - movq 0x18(%rdi), %rbp #restore frame pointer - movq $terminateCoreCtlr, %rax - jmp *%rax #jmp to fn that ends the pthread - - -/* - * 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 0x20(%rdi), %rsp #restore stack pointer - movq 0x18(%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 0x08(%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, 0x08(%rbp) #write return addr to the stack of the caller - ret -