annotate ProcrContext.c @ 134:a9b72021f053

Distributed memory management w/o free requests working
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 16 Sep 2011 16:19:24 +0200
parents 521c75d64cef
children
rev   line source
msach@77 1 /*
msach@77 2 * This File contains all hardware dependent C code.
msach@77 3 */
msach@77 4
msach@77 5
msach@77 6 #include "VMS.h"
msach@134 7 #include "ProcrContext.h"
msach@77 8
msach@77 9 /*Create stack, then create __cdecl structure on it and put initialData and
msach@77 10 * pointer to the new structure instance into the parameter positions on
msach@77 11 * the stack
msach@77 12 *Then put function pointer into nextInstrPt -- the stack is setup in std
msach@77 13 * call structure, so jumping to function ptr is same as a GCC generated
msach@77 14 * function call
msach@77 15 *No need to save registers on old stack frame, because there's no old
msach@77 16 * animator state to return to --
msach@77 17 *
msach@77 18 */
msach@77 19 inline VirtProcr *
msach@77 20 create_procr_helper( VirtProcr *newPr, VirtProcrFnPtr fnPtr,
msach@77 21 void *initialData, void *stackLocs )
msach@77 22 {
msach@77 23 void *stackPtr;
msach@77 24
msach@77 25 newPr->startOfStack = stackLocs;
msach@77 26 newPr->procrID = _VMSMasterEnv->numProcrsCreated++;
msach@77 27 newPr->initialData = initialData;
msach@77 28 newPr->requests = NULL;
msach@77 29 newPr->schedSlot = NULL;
msach@77 30
msach@77 31 /*
msach@77 32 * Hardware dependent part
msach@77 33 */
msach@77 34 //instead of calling the function directly, call a wrapper function to fetch
msach@77 35 //arguments from stack
msach@77 36 newPr->nextInstrPt = (VirtProcrFnPtr)&startVirtProcrFn;
msach@77 37
msach@77 38 //fnPtr takes two params -- void *initData & void *animProcr
msach@77 39 //alloc stack locations, make stackPtr be the highest addr minus room
msach@77 40 // for 2 params + return addr. Return addr (NULL) is in loc pointed to
msach@77 41 // by stackPtr, initData at stackPtr + 8 bytes, animatingPr just above
msach@77 42 stackPtr = ( (void *)stackLocs + VIRT_PROCR_STACK_SIZE - 4*sizeof(void*));
msach@77 43
msach@77 44 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp
msach@77 45 *((VirtProcr**)stackPtr + 2 ) = newPr; //rightmost param
msach@77 46 *((void**)stackPtr + 1 ) = initialData; //next param to left
msach@77 47 *((void**)stackPtr) = (void*)fnPtr;
msach@77 48
msach@77 49 /*
msach@77 50 * end of Hardware dependent part
msach@77 51 */
msach@77 52
msach@77 53 newPr->stackPtr = stackPtr; //core loop will switch to this, then
msach@77 54 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr
msach@77 55
msach@77 56 //============================= MEASUREMENT STUFF ========================
msach@77 57 #ifdef STATS__TURN_ON_PROBES
msach@78 58 //struct timeval timeStamp;
msach@78 59 //gettimeofday( &(timeStamp), NULL);
msach@78 60 //newPr->createPtInSecs = timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0) -
msach@78 61 // _VMSMasterEnv->createPtInSecs;
msach@77 62 #endif
msach@77 63 //========================================================================
msach@77 64
msach@77 65 return newPr;
msach@77 66 }