changeset 281:b58fb1343377 Common_Ancestor

remove need for end_thread()
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Fri, 17 May 2013 17:49:35 +0200
parents 67b684afa736
children 7aa806812466
files HW_Dependent_Primitives/VMS__primitives.c HW_Dependent_Primitives/VMS__primitives_asm.s VMS.h VMS__int.c
diffstat 4 files changed, 88 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/HW_Dependent_Primitives/VMS__primitives.c	Wed May 15 15:21:46 2013 +0200
     1.2 +++ b/HW_Dependent_Primitives/VMS__primitives.c	Fri May 17 17:49:35 2013 +0200
     1.3 @@ -52,7 +52,41 @@
     1.4     slaveVP->stackPtr = stackPtr; 
     1.5     slaveVP->framePtr = 0; 
     1.6   }
     1.7 +void
     1.8 +VMS_int__reset_slaveVP_to_TopLvlFnWrapper( SlaveVP *slaveVP, TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr,
     1.9 +                              void    *dataParam){
    1.10 +    void  *stackPtr;
    1.11  
    1.12 +// Start of Hardware dependent part           
    1.13 +   
    1.14 +    //Set slave's instr pointer to a helper Fn that copies params from stack
    1.15 +   slaveVP->resumeInstrPtr  = (TopLevelFnPtr)&startUpTopLevelFn;
    1.16 +   
    1.17 +    //fnPtr takes two params -- void *dataParam & void *animSlv
    1.18 +    // Stack grows *down*, so start it at highest stack addr, minus room
    1.19 +    // for 2 params + return addr. Do ptr arith in terms of bytes..
    1.20 +   stackPtr = 
    1.21 +     (uint8 *)slaveVP->startOfStack + VIRT_PROCR_STACK_SIZE - 3*sizeof(void*);
    1.22 +  
    1.23 +    //setup __cdecl on stack
    1.24 +    //Normally, return Addr is in loc pointed to by stackPtr, but doing a
    1.25 +    // trick for 64 bit arch, where put ptr to top-level fn there instead,
    1.26 +    // and set resumeInstrPtr to a helper-fn that copies the top-level
    1.27 +    // fn ptr and params into registers.
    1.28 +    //Then, dataParam is at stackPtr + 8 bytes, & animating SlaveVP above
    1.29 +    //Do ptr arith in terms of pointers
    1.30 +   *((void**)stackPtr + 2 ) = dataParam; //rightmost param
    1.31 +   *((void**)stackPtr + 1 ) = fnPtr;  //next  param to left
    1.32 +   *((void**)stackPtr) = (void*)fnWrapper;    //copied to reg by helper Fn
    1.33 +   
    1.34 +  
    1.35 +// end of Hardware dependent part           
    1.36 +   
    1.37 +      //core controller will switch to stack & frame pointers stored in slave,
    1.38 +      // can't use this fn if have state on stack that needs preserving.
    1.39 +   slaveVP->stackPtr = stackPtr; 
    1.40 +   slaveVP->framePtr = 0; 
    1.41 +}
    1.42  
    1.43  /*Preserve the stack, pushing the __cdecl structure onto it
    1.44   * For 64 bits, params passed in regs, so point slave to helper assembly
     2.1 --- a/HW_Dependent_Primitives/VMS__primitives_asm.s	Wed May 15 15:21:46 2013 +0200
     2.2 +++ b/HW_Dependent_Primitives/VMS__primitives_asm.s	Fri May 17 17:49:35 2013 +0200
     2.3 @@ -16,7 +16,7 @@
     2.4  // the top-level function, which was pointed to by the stack-ptr
     2.5  .globl startUpTopLevelFn
     2.6  startUpTopLevelFn:
     2.7 -    movq    %rdi      , %rsi #get second argument from first argument of switchSlv
     2.8 +    movq    0x10(%rsp), %rsi #get second argument from stack
     2.9      movq    0x08(%rsp), %rdi #get first argument from stack
    2.10      movq    (%rsp)    , %rax #get top-level function's addr from stack
    2.11      jmp     *%rax            #jump to the top-level function
     3.1 --- a/VMS.h	Wed May 15 15:21:46 2013 +0200
     3.2 +++ b/VMS.h	Fri May 17 17:49:35 2013 +0200
     3.3 @@ -45,6 +45,7 @@
     3.4  typedef SlaveVP *(*SlaveAssigner)  ( void *, AnimSlot*); //semEnv, slot for HW info
     3.5  typedef void     (*RequestHandler) ( SlaveVP *, void * ); //prWReqst, semEnv
     3.6  typedef void     (*TopLevelFnPtr)  ( void * ); //initData, animSlv
     3.7 +typedef void     (*TopLevelFnWrapper)( TopLevelFnPtr, void*); //(*fn)(arg)
     3.8  typedef void       TopLevelFn      ( void * ); //initData, animSlv
     3.9  typedef void     (*ResumeSlvFnPtr) ( SlaveVP *, void * );
    3.10        //=========== MEASUREMENT STUFF ==========
    3.11 @@ -293,6 +294,9 @@
    3.12  #define VMS_PI__create_slaveVP VMS_int__create_slaveVP
    3.13  #define VMS_WL__create_slaveVP VMS_int__create_slaveVP
    3.14  
    3.15 +SlaveVP *
    3.16 +VMS_int__create_slaveVP_with_wrapper( TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr, void *dataParam );
    3.17 +
    3.18     //Use this to create processor inside entry point & other places outside
    3.19     // the VMS system boundary (IE, don't animate with a SlaveVP or MasterVP)
    3.20  SlaveVP *
    3.21 @@ -302,6 +306,10 @@
    3.22  VMS_int__create_slaveVP_helper( SlaveVP *newSlv,       TopLevelFnPtr  fnPtr,
    3.23                                  void      *dataParam, void           *stackLocs );
    3.24  
    3.25 +SlaveVP *
    3.26 +VMS_int__create_slaveVP_helper_with_wrapper( SlaveVP *newSlv, TopLevelFnWrapper fnWrapper, TopLevelFnPtr  fnPtr,
    3.27 +                     void    *dataParam, void          *stackLocs );
    3.28 +
    3.29  void
    3.30  VMS_int__reset_slaveVP_to_TopLvlFn( SlaveVP *slaveVP, TopLevelFnPtr fnPtr,
    3.31                                void    *dataParam);
    3.32 @@ -315,6 +323,10 @@
    3.33                                void    *param1, void *param2);
    3.34  
    3.35  void
    3.36 +VMS_int__reset_slaveVP_to_TopLvlFnWrapper( SlaveVP *slaveVP, TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr,
    3.37 +                              void    *dataParam);
    3.38 +
    3.39 +void
    3.40  VMS_int__dissipate_slaveVP( SlaveVP *slaveToDissipate );
    3.41  #define VMS_PI__dissipate_slaveVP VMS_int__dissipate_slaveVP
    3.42  //WL: dissipate a SlaveVP by sending a request
     4.1 --- a/VMS__int.c	Wed May 15 15:21:46 2013 +0200
     4.2 +++ b/VMS__int.c	Fri May 17 17:49:35 2013 +0200
     4.3 @@ -42,6 +42,21 @@
     4.4     return VMS_int__create_slaveVP_helper( newSlv, fnPtr, dataParam, stackLocs );
     4.5   }
     4.6  
     4.7 +SlaveVP *
     4.8 +VMS_int__create_slaveVP_with_wrapper( TopLevelFnWrapper fnWrapper, TopLevelFnPtr fnPtr, void *dataParam )
     4.9 + { SlaveVP *newSlv;
    4.10 +   void      *stackLocs;
    4.11 +
    4.12 +   newSlv      = VMS_int__malloc( sizeof(SlaveVP) );
    4.13 +   stackLocs   = memalign(16, VIRT_PROCR_STACK_SIZE );
    4.14 +   if( stackLocs == 0 )
    4.15 +    { perror("VMS_int__malloc stack"); exit(1); }
    4.16 +
    4.17 +   _VMSMasterEnv->numSlavesAlive += 1;
    4.18 +
    4.19 +   return VMS_int__create_slaveVP_helper_with_wrapper( newSlv, fnWrapper, fnPtr, dataParam, stackLocs );
    4.20 + }
    4.21 +
    4.22  /* "ext" designates that it's for use outside the VMS system -- should only
    4.23   * be called from main thread or other thread -- never from code animated by
    4.24   * a VMS virtual processor.
    4.25 @@ -205,6 +220,32 @@
    4.26     return newSlv;
    4.27   }
    4.28  
    4.29 +SlaveVP *
    4.30 +VMS_int__create_slaveVP_helper_with_wrapper( SlaveVP *newSlv, TopLevelFnWrapper fnWrapper, TopLevelFnPtr  fnPtr,
    4.31 +                     void    *dataParam, void          *stackLocs )
    4.32 + {
    4.33 +   newSlv->startOfStack = stackLocs;
    4.34 +   newSlv->slaveID      = _VMSMasterEnv->numSlavesCreated++;
    4.35 +   newSlv->requests     = NULL;
    4.36 +   newSlv->animSlotAssignedTo    = NULL;
    4.37 +   newSlv->typeOfVP     = Slave;
    4.38 +   newSlv->assignCount  = 0;
    4.39 +
    4.40 +   VMS_int__reset_slaveVP_to_TopLvlFnWrapper( newSlv, fnWrapper, fnPtr, dataParam );
    4.41 +           
    4.42 +   //============================= MEASUREMENT STUFF ========================
    4.43 +   #ifdef SERVICE__TURN_ON_STATS_PROBES
    4.44 +   //TODO: make this TSCHiLow or generic equivalent
    4.45 +   //struct timeval timeStamp;
    4.46 +   //gettimeofday( &(timeStamp), NULL);
    4.47 +   //newSlv->createPtInSecs = timeStamp.tv_sec +(timeStamp.tv_usec/1000000.0) -
    4.48 +   //                                           _VMSMasterEnv->createPtInSecs;
    4.49 +   #endif
    4.50 +   //========================================================================
    4.51 +
    4.52 +   return newSlv;
    4.53 + }
    4.54 +
    4.55  
    4.56  /*Later, improve this -- for now, just exits the application after printing
    4.57   * the error message.