changeset 71:5ff1631c26ed

working O3 version
author Merten Sach <msach@mailbox.tu-berlin.de>
date Mon, 30 May 2011 18:28:41 +0200
parents 11bfe9d136ed
children d8f12351f7cc
files CoreLoop.c MasterLoop.c SwitchAnimators.h VMS.c VMS.h contextSwitch.s
diffstat 6 files changed, 177 insertions(+), 251 deletions(-) [+]
line diff
     1.1 --- a/CoreLoop.c	Wed May 11 16:13:24 2011 +0200
     1.2 +++ b/CoreLoop.c	Mon May 30 18:28:41 2011 +0200
     1.3 @@ -14,6 +14,7 @@
     1.4  #include <pthread.h>
     1.5  #include <sched.h>
     1.6  
     1.7 +void *terminateCoreLoop(VirtProcr *currPr);
     1.8  
     1.9  /*This is the loop that runs in the OS Thread pinned to each core
    1.10   *Get virt procr from queue,
    1.11 @@ -78,8 +79,7 @@
    1.12        //To get label addr in non-gcc compiler, can trick it by making a call
    1.13        // to a fn that does asm that pulls the "return"
    1.14        // addr off the stack and stores it in a pointed-to location.
    1.15 -   _VMSMasterEnv->coreLoopEndPt   = &&CoreLoopEndPt;
    1.16 -   _VMSMasterEnv->coreLoopStartPt = &&CoreLoopStartPt;
    1.17 +   saveCoreLoopReturnAddr(&(_VMSMasterEnv->coreLoopStartPt));
    1.18     
    1.19        //Core loop has no values live upon CoreLoopStartPt except
    1.20        // _VMSMasterEnv
    1.21 @@ -90,7 +90,8 @@
    1.22        // Get to work!  --  virt procr jumps back here when suspends
    1.23        //Note, have to restore the frame-pointer before jump to here, to get
    1.24        // this code to work right (readyToAnimateQ and so forth are frame-ptr relative)
    1.25 -CoreLoopStartPt:
    1.26 +   
    1.27 +   while(1){
    1.28     
    1.29        //Get virtual processor from queue
    1.30        //The Q must be a global, static volatile var, so not kept in reg,
    1.31 @@ -159,19 +160,21 @@
    1.32      }
    1.33  
    1.34     
    1.35 -   SwitchToVP( currPr )
    1.36 +   switchToVP(currPr);
    1.37 +   flushRegisters();
    1.38 +   }//CoreLoop      
    1.39 + }
    1.40  
    1.41 -
    1.42 -   //=========== jmp to here when want to shut down the VMS system ==========
    1.43 -   CoreLoopEndPt:
    1.44 -      //first free shutdown VP that jumped here -- it first restores the
    1.45 -      // coreloop's stack, so addr of currPr in stack frame is still correct
    1.46 +void *
    1.47 +terminateCoreLoop(VirtProcr *currPr){
    1.48 +   //first free shutdown VP that jumped here -- it first restores the
    1.49 +   // coreloop's stack, so addr of currPr in stack frame is still correct
    1.50     VMS__dissipate_procr( currPr );
    1.51     pthread_exit( NULL );
    1.52 - }
    1.53 +}
    1.54  
    1.55  
    1.56 -
    1.57 +#ifdef SEQUENTIAL
    1.58  
    1.59  //===========================================================================
    1.60  /*This sequential version is exact same as threaded, except doesn't do the
    1.61 @@ -237,3 +240,5 @@
    1.62     VMS__dissipate_procr( currPr ); //free shutdown pr, that jmpd here
    1.63     return;
    1.64   }
    1.65 +
    1.66 +#endif
     2.1 --- a/MasterLoop.c	Wed May 11 16:13:24 2011 +0200
     2.2 +++ b/MasterLoop.c	Mon May 30 18:28:41 2011 +0200
     2.3 @@ -10,6 +10,7 @@
     2.4  #include <stddef.h>
     2.5  
     2.6  #include "VMS.h"
     2.7 +#include "SwitchAnimators.h"
     2.8  
     2.9  
    2.10  //===========================================================================
    2.11 @@ -93,7 +94,7 @@
    2.12        // of setup code.. (VP creator sets up the stack as if this function
    2.13        // was called normally, but actually get here by jmp)
    2.14        //So, setup values about stack ptr, jmp pt and all that
    2.15 -   masterPr->nextInstrPt = &&masterLoopStartPt;
    2.16 +   //masterPr->nextInstrPt = &&masterLoopStartPt;
    2.17  
    2.18  
    2.19        //Note, got rid of writing the stack and frame ptr up here, because
    2.20 @@ -104,7 +105,9 @@
    2.21        //Also got rid of the busy-wait.
    2.22  
    2.23     
    2.24 -   masterLoopStartPt:
    2.25 +   //masterLoopStartPt:
    2.26 +   while(1){
    2.27 +       
    2.28     //============================= MEASUREMENT STUFF ========================
    2.29     #ifdef MEAS__TIME_MASTER
    2.30        //Total Master time includes one coreloop time -- just assume the core
    2.31 @@ -185,35 +188,11 @@
    2.32     saveLowTimeStampCountInto( masterPr->endMasterTSCLow );
    2.33     #endif
    2.34  
    2.35 +   masterSwitchToCoreLoop(animatingPr);
    2.36 +   flushRegisters();
    2.37 +   }//MasterLoop
    2.38  
    2.39  
    2.40 -/* VirtProcr  offsets:
    2.41 - * 0xc  stackPtr
    2.42 - * 0x10 framePtr
    2.43 - * 0x14 nextInstrPt
    2.44 - * 0x1c coreLoopFramePtr
    2.45 - * 0x20 coreLoopStackPtr
    2.46 - *
    2.47 - * _VMSMasterEnv  offsets:
    2.48 - * 0x24 coreLoopStartPt
    2.49 - * 0x28 coreLoopEndPt
    2.50 - * 0x30 masterLock
    2.51 - */
    2.52 -//   masterSwitchToCoreLoop( masterPr )
    2.53 -   asm volatile("movl         %0,       %%ebx;  \
    2.54 -                 movl         %1,       %%ecx;  \
    2.55 -                 movl      %%esp,  0x0c(%%ecx); \
    2.56 -                 movl      %%ebp,  0x10(%%ecx); \
    2.57 -                 movl 0x24(%%ebx),      %%eax;  \
    2.58 -                 movl 0x20(%%ecx),      %%esp;  \
    2.59 -                 movl 0x1c(%%ecx),      %%ebp;  \
    2.60 -                 movl $0x0,        0x30(%%ebx); \
    2.61 -                 jmp                    %%eax"  \
    2.62 -   /* outputs */ :                              \
    2.63 -   /* inputs  */ : "g"(_VMSMasterEnv), "g"(masterPr)                        \
    2.64 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
    2.65 -                );
    2.66 -
    2.67   }
    2.68  
    2.69  
     3.1 --- a/SwitchAnimators.h	Wed May 11 16:13:24 2011 +0200
     3.2 +++ b/SwitchAnimators.h	Mon May 30 18:28:41 2011 +0200
     3.3 @@ -10,6 +10,17 @@
     3.4  #define	_SwitchAnimators_H
     3.5  #define __USE_GNU
     3.6  
     3.7 +void saveCoreLoopReturnAddr(void *returnAddress);
     3.8 +
     3.9 +void switchToVP(VirtProcr *nextProcr);
    3.10 +
    3.11 +void switchToCoreLoop(VirtProcr *nextProcr);
    3.12 +
    3.13 +void masterSwitchToCoreLoop(VirtProcr *nextProcr);
    3.14 +
    3.15 +#define flushRegisters() \
    3.16 +        asm volatile ("":::"%eax","%ebx", "%ecx", "%edx","%edi","%esi")
    3.17 +
    3.18  /*Isolating code for switching between animators within these macros -- at
    3.19   * some point will make switches to compile for 32 bit or for 64 bit, which
    3.20   * having these isolated will make cleaner
    3.21 @@ -63,113 +74,11 @@
    3.22   *%%ebp is the frame-ptr register and %%esp is the stack-ptr register
    3.23   */
    3.24  
    3.25 -//=========================== MasterVP to CoreLoop ==========================
    3.26 -//
    3.27 -      //Save stack ptr and frame, restore CoreLoop's stack and frame,
    3.28 -      // and clear the MasterLock
    3.29 -      //GCC's -O3 messes with this -- go through generated -- protect somehow
    3.30 -      //
    3.31 -#define masterSwitchToCoreLoop( masterPr )   \
    3.32 -   void           *stackPtrAddr, *framePtrAddr; \
    3.33 -   volatile void *masterLockAddr; \
    3.34 -   void           *jmpPt, *coreLoopFramePtr, *coreLoopStackPtr;  \
    3.35 -\
    3.36 -   masterLockAddr    = &(_VMSMasterEnv->masterLock); \
    3.37 -\
    3.38 -   jmpPt             = _VMSMasterEnv->coreLoopStartPt; \
    3.39 -   coreLoopStackPtr  = masterPr->coreLoopStackPtr; \
    3.40 -   coreLoopFramePtr  = masterPr->coreLoopFramePtr; \
    3.41 -\
    3.42 -   asm volatile("mov  %0,     %%ecx;  \
    3.43 -                 mov  %1,     %%ebx;  \
    3.44 -                 mov  %%ebx,  %%eax;  \
    3.45 -                 add  $0x10,  %%eax;  \
    3.46 -                 movl %%esp, (%%eax); \
    3.47 -                 mov  %%ebx,  %%eax;  \
    3.48 -                 add  $0x14,  %%eax;  \
    3.49 -                 movl %%ebp, (%%eax); \
    3.50 -                 movl %2, %%eax;      \
    3.51 -                 movl %3, %%esp;      \
    3.52 -                 movl %4, %%ebp;      \
    3.53 -                 movl $0x0, (%%ecx);  \
    3.54 -                 jmp  %%eax"          \
    3.55 -   /* outputs */ : "=g"(masterLockAddr)                \
    3.56 -   /* inputs  */ : "g"(masterPr), "g" (jmpPt), "g" (coreLoopStackPtr), \
    3.57 -                   "g" (coreLoopFramePtr) \
    3.58 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
    3.59 -                );
    3.60 -
    3.61 -//   asm volatile("movl %0,     %%eax;  \
    3.62 -                 movl %%esp, (%%eax); \
    3.63 -                 movl %1,     %%eax;  \
    3.64 -                 movl %%ebp, (%%eax); \
    3.65 -                 movl %2, %%ebx;      \
    3.66 -                 movl %3, %%eax;      \
    3.67 -                 movl %4, %%esp;      \
    3.68 -                 movl %5, %%ebp;      \
    3.69 -                 movl $0x0, (%%ebx);  \
    3.70 -                 jmp  %%eax;"         \
    3.71 -   /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr),                \
    3.72 -                   "=g"(masterLockAddr)                                     \
    3.73 -   /* inputs  */ : "g" (jmpPt), "g"(coreLoopStackPtr), "g"(coreLoopFramePtr)\
    3.74 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
    3.75 -                );//can probably make clobber list empty -- but safe for now
    3.76  
    3.77  
    3.78  //=========================== SlaveVP to CoreLoop ===========================
    3.79  //
    3.80  
    3.81 -#define    SwitchToCoreLoop( animatingPr ) \
    3.82 -   void *jmpPt, *coreLoopStackPtr; \
    3.83 -   void *coreLoopFramePtr; \
    3.84 -\
    3.85 -   jmpPt             = _VMSMasterEnv->coreLoopStartPt; \
    3.86 -   coreLoopStackPtr  = animatingPr->coreLoopStackPtr; \
    3.87 -   coreLoopFramePtr  = animatingPr->coreLoopFramePtr; \
    3.88 -\
    3.89 -   asm volatile("mov  %0,%%ebx;       \
    3.90 -                 mov  %%ebx, %%eax;   \
    3.91 -                 add  $0x10, %%eax;   \
    3.92 -                 movl %%esp, (%%eax); \
    3.93 -                 mov  %%ebx, %%eax;   \
    3.94 -                 add  $0x14, %%eax;   \
    3.95 -                 movl %%ebp, (%%eax); \
    3.96 -                 movl %1, %%eax;      \
    3.97 -                 movl %2, %%esp;      \
    3.98 -                 movl %3, %%ebp;      \
    3.99 -                 jmp  %%eax"          \
   3.100 -   /* outputs */ :                    \
   3.101 -   /* inputs  */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \
   3.102 -                   "g" (coreLoopFramePtr) \
   3.103 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   3.104 -                );
   3.105 -
   3.106 -      /*Save the virt procr's stack and frame ptrs*/ \
   3.107 -//   asm volatile("movl %0,     %%eax;  \
   3.108 -                 movl %%esp, (%%eax); \
   3.109 -                 movl %1,     %%eax;  \
   3.110 -                 movl %%ebp, (%%eax) "\
   3.111 -   /* outputs */ : "=g" (stackPtrAddr), "=g" (framePtrAddr) \
   3.112 -   /* inputs  */ :        \
   3.113 -   /* clobber */ : "%eax" \
   3.114 -                ); \
   3.115 -\
   3.116 -     /*restore coreloop's frame ptr, then jump back to "start" of core loop*/\
   3.117 -     /*Note, GCC compiles to assembly that saves esp and ebp in the stack*/ \
   3.118 -     /* frame -- so have to explicitly do assembly that saves to memory*/ \
   3.119 -   asm volatile("movl %0, %%eax;      \
   3.120 -                 movl %1, %%esp;      \
   3.121 -                 movl %2, %%ebp;      \
   3.122 -                 jmp  %%eax    "      \
   3.123 -   /* outputs */ :                    \
   3.124 -   /* inputs  */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
   3.125 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi"  \
   3.126 -                );
   3.127 - //list everything as clobbered to force GCC to save all
   3.128 - // live vars that are in regs on stack before this
   3.129 - // assembly, so that stack pointer is correct, before jmp
   3.130 -
   3.131 -
   3.132  
   3.133  //============================== CoreLoop to VP =============================
   3.134  //
   3.135 @@ -184,53 +93,6 @@
   3.136        // stack, so "movl %%ebp, %0" saves to the temp, NOT the data-struc!
   3.137  
   3.138  
   3.139 -      //switch to virt procr's stack and frame ptr then jump to virt procr fn
   3.140 -/* VirtProcr  offsets:
   3.141 - * 0xc  stackPtr
   3.142 - * 0x10 framePtr
   3.143 - * 0x14 nextInstrPt
   3.144 - * 0x1c coreLoopFramePtr
   3.145 - * 0x20 coreLoopStackPtr
   3.146 - *
   3.147 - * _VMSMasterEnv  offsets:
   3.148 - * 0x24 coreLoopStartPt
   3.149 - * 0x28 coreLoopEndPt
   3.150 - * 0x30 masterLock
   3.151 - */
   3.152 -#define SwitchToVP( currPr ) \
   3.153 -   asm volatile("movl         %0,      %%ebx;  \
   3.154 -                 movl      %%esp, 0x20(%%ebx); \
   3.155 -                 movl      %%ebp, 0x1c(%%ebx); \
   3.156 -                 movl 0x14(%%ebx),     %%eax;  \
   3.157 -                 movl 0x0c(%%ebx),     %%esp;  \
   3.158 -                 movl 0x10(%%ebx),     %%ebp;  \
   3.159 -                 jmp                  *%%eax"  \
   3.160 -   /* outputs */ :                             \
   3.161 -   /* inputs  */ : "g"(currPr)                 \
   3.162 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   3.163 -                );
   3.164 -
   3.165 -//   void *stackPtr, *framePtr, *jmpPt; \
   3.166 -\
   3.167 -   stackPtr = currPr->stackPtr; \
   3.168 -   framePtr = currPr->framePtr; \
   3.169 -   jmpPt    = currPr->nextInstrPt; \
   3.170 -\
   3.171 -   asm volatile("mov  %0,%%ebx;       \
   3.172 -                 mov  %%ebx, %%eax;   \
   3.173 -                 add  $0x1c, %%eax;   \
   3.174 -                 movl %%esp, (%%eax); \
   3.175 -                 mov  %%ebx, %%eax;   \
   3.176 -                 add  $0x20, %%eax;   \
   3.177 -                 movl %%ebp, (%%eax); \
   3.178 -                 movl %1, %%eax;      \
   3.179 -                 movl %2, %%esp;      \
   3.180 -                 movl %3, %%ebp;      \
   3.181 -                 jmp  %%eax"          \
   3.182 -   /* outputs */ :                    \
   3.183 -   /* inputs  */ : "g"(currPr), "g" (jmpPt), "g" (stackPtr), "g" (framePtr) \
   3.184 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   3.185 -                );
   3.186  
   3.187     
   3.188  #endif	/* _SwitchAnimators_H */
     4.1 --- a/VMS.c	Wed May 11 16:13:24 2011 +0200
     4.2 +++ b/VMS.c	Mon May 30 18:28:41 2011 +0200
     4.3 @@ -11,6 +11,7 @@
     4.4  #include <sys/time.h>
     4.5  
     4.6  #include "VMS.h"
     4.7 +#include "SwitchAnimators.h"
     4.8  #include "Queue_impl/BlockingQueue.h"
     4.9  #include "Histogram/Histogram.h"
    4.10  
    4.11 @@ -76,6 +77,8 @@
    4.12     create_the_coreLoop_OS_threads();
    4.13   }
    4.14  
    4.15 +#ifdef SEQUENTIAL
    4.16 +
    4.17  /*To initialize the sequential version, just don't create the threads
    4.18   */
    4.19  void
    4.20 @@ -84,6 +87,8 @@
    4.21     create_masterEnv();
    4.22   }
    4.23  
    4.24 +#endif
    4.25 +
    4.26  void
    4.27  create_masterEnv()
    4.28   { MasterEnv       *masterEnv;
    4.29 @@ -261,6 +266,7 @@
    4.30        // the Master env and rest of VMS locations
    4.31   }
    4.32  
    4.33 +#ifdef SEQUENTIAL
    4.34  /*Only difference between version with an OS thread pinned to each core and
    4.35   * the sequential version of VMS is VMS__init_Seq, this, and coreLoop_Seq.
    4.36   */
    4.37 @@ -272,8 +278,7 @@
    4.38        coreLoop_Seq( NULL );
    4.39  
    4.40   }
    4.41 -
    4.42 -
    4.43 +#endif
    4.44  
    4.45  /*Create stack, then create __cdecl structure on it and put initialData and
    4.46   * pointer to the new structure instance into the parameter positions on
    4.47 @@ -378,7 +383,7 @@
    4.48        // scheduled again at some future point -- to resume, core loop jumps
    4.49        // to the resume point (below), which causes restore of saved regs and
    4.50        // "return" from this call.
    4.51 -   animatingPr->nextInstrPt = &&ResumePt;
    4.52 +   //animatingPr->nextInstrPt = &&ResumePt;
    4.53  
    4.54        //return ownership of the virt procr and sched slot to Master virt pr
    4.55     animatingPr->schedSlot->workIsDone = TRUE;
    4.56 @@ -390,51 +395,11 @@
    4.57     #endif
    4.58     //=======================================================================
    4.59  
    4.60 -/* VirtProcr  offsets:
    4.61 - * 0xc  stackPtr
    4.62 - * 0x10 framePtr
    4.63 - * 0x14 nextInstrPt
    4.64 - * 0x1c coreLoopFramePtr
    4.65 - * 0x20 coreLoopStackPtr
    4.66 - *
    4.67 - * _VMSMasterEnv  offsets:
    4.68 - * 0x24 coreLoopStartPt
    4.69 - * 0x28 coreLoopEndPt
    4.70 - * 0x30 masterLock
    4.71 - */
    4.72 -//   SwitchToCoreLoop( animatingPr )
    4.73 -   asm volatile("movl         %0,       %%ebx;  \
    4.74 -                 movl         %1,       %%ecx;  \
    4.75 -                 movl      %%esp,  0x0c(%%ecx); \
    4.76 -                 movl      %%ebp,  0x10(%%ecx); \
    4.77 -                 movl 0x24(%%ebx),      %%eax;  \
    4.78 -                 movl 0x20(%%ecx),      %%esp;  \
    4.79 -                 movl 0x1c(%%ecx),      %%ebp;  \
    4.80 -                 jmp                    %%eax"  \
    4.81 -   /* outputs */ :                              \
    4.82 -   /* inputs  */ : "g"(_VMSMasterEnv), "g"(animatingPr)                     \
    4.83 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
    4.84 -                );
    4.85 -
    4.86 -//  asm volatile("mov  %0,%%ebx;       \
    4.87 -                 mov  %%ebx, %%eax;   \
    4.88 -                 add  $0xc,  %%eax;   \
    4.89 -                 movl %%esp, (%%eax); \
    4.90 -                 mov  %%ebx, %%eax;   \
    4.91 -                 add  $0x10, %%eax;   \
    4.92 -                 movl %%ebp, (%%eax); \
    4.93 -                 movl %1, %%eax;      \
    4.94 -                 movl %2, %%esp;      \
    4.95 -                 movl %3, %%ebp;      \
    4.96 -                 jmp  %%eax"          \
    4.97 -   /* outputs */ :                    \
    4.98 -   /* inputs  */ : "g"(animatingPr), "g" (jmpPt), "g" (coreLoopStackPtr), \
    4.99 -                   "g" (coreLoopFramePtr) \
   4.100 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \
   4.101 -                );
   4.102 +   switchToCoreLoop(animatingPr);
   4.103 +   flushRegisters();
   4.104  
   4.105     //=======================================================================
   4.106 -ResumePt:
   4.107 +
   4.108     #ifdef MEAS__TIME_STAMP_SUSP
   4.109        //NOTE: only take low part of count -- do sanity check when take diff
   4.110     saveLowTimeStampCountInto( animatingPr->postSuspTSCLow );
   4.111 @@ -738,21 +703,8 @@
   4.112   */
   4.113  void
   4.114  endOSThreadFn( void *initData, VirtProcr *animatingPr )
   4.115 - { void *jmpPt, *coreLoopStackPtr, *coreLoopFramePtr;
   4.116 -
   4.117 -   jmpPt             = _VMSMasterEnv->coreLoopEndPt;
   4.118 -   coreLoopStackPtr  = animatingPr->coreLoopStackPtr;
   4.119 -   coreLoopFramePtr  = animatingPr->coreLoopFramePtr;
   4.120 -
   4.121 -
   4.122 -   asm volatile("movl %0, %%eax;      \
   4.123 -                 movl %1, %%esp;      \
   4.124 -                 movl %2, %%ebp;      \
   4.125 -                 jmp  %%eax    "      \
   4.126 -   /* outputs */ :                    \
   4.127 -   /* inputs  */ : "m" (jmpPt), "m"(coreLoopStackPtr), "m"(coreLoopFramePtr)\
   4.128 -   /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi"  \
   4.129 -                );
   4.130 + { 
   4.131 +    asmTerminateCoreLoop(animatingPr);
   4.132   }
   4.133  
   4.134  
     5.1 --- a/VMS.h	Wed May 11 16:13:24 2011 +0200
     5.2 +++ b/VMS.h	Mon May 30 18:28:41 2011 +0200
     5.3 @@ -229,7 +229,7 @@
     5.4     void            *coreLoopEndPt;  //addr to jump to to shut down a coreLoop
     5.5  
     5.6     int32            setupComplete;
     5.7 -   int32            masterLock;
     5.8 +   volatile int32   masterLock;
     5.9  
    5.10     int32            numMasterInARow[NUM_CORES];//detect back-to-back masterVP
    5.11     GateStruc       *workStealingGates[ NUM_CORES ]; //concurrent work-steal
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/contextSwitch.s	Mon May 30 18:28:41 2011 +0200
     6.3 @@ -0,0 +1,128 @@
     6.4 +#include "VMS.h"
     6.5 +
     6.6 +.data
     6.7 +
     6.8 +
     6.9 +.text
    6.10 +
    6.11 +//Save return label address for the coreLoop to pointer
    6.12 +//Arguments: Pointer to variable holding address
    6.13 +.globl saveCoreLoopReturnAddr
    6.14 +saveCoreLoopReturnAddr:
    6.15 +    movl    0x4(%esp) , %eax       #load pointer
    6.16 +    movl    $coreLoopReturn, %ecx   #load label address
    6.17 +    movl    %ecx, (%eax)           #save address
    6.18 +    ret
    6.19 +
    6.20 +
    6.21 +
    6.22 +//Switches form CoreLoop to VP ether normal VP or the Master Loop
    6.23 +//switch to virt procr's stack and frame ptr then jump to virt procr fn
    6.24 +/* VirtProcr  offsets:
    6.25 + * 0xc  stackPtr
    6.26 + * 0x10 framePtr
    6.27 + * 0x14 nextInstrPt
    6.28 + * 0x1c coreLoopFramePtr
    6.29 + * 0x20 coreLoopStackPtr
    6.30 + *
    6.31 + * _VMSMasterEnv  offsets:
    6.32 + * 0x24 coreLoopStartPt
    6.33 + * 0x28 coreLoopEndPt
    6.34 + * 0x30 masterLock
    6.35 + */
    6.36 +.globl switchToVP
    6.37 +switchToVP:
    6.38 +    movl    0x4(%esp) , %ecx         #get VirtProcr
    6.39 +    movl    %esp      , 0x20(%ecx)   #save core loop stack pointer 
    6.40 +    movl    %ebp      , 0x1c(%ecx)   #save core loop frame pointer
    6.41 +    movl    0x0c(%ecx), %esp         #restore stack pointer
    6.42 +    movl    0x10(%ecx), %ebp         #restore frame pointer
    6.43 +    movl    0x14(%ecx), %eax         #get jmp pointer
    6.44 +    jmp     *%eax                    #jmp to VP
    6.45 +coreLoopReturn:
    6.46 +    ret
    6.47 +
    6.48 +    
    6.49 +//switches to core loop. saves return address
    6.50 +/* VirtProcr  offsets:
    6.51 + * 0xc  stackPtr
    6.52 + * 0x10 framePtr
    6.53 + * 0x14 nextInstrPt
    6.54 + * 0x1c coreLoopFramePtr
    6.55 + * 0x20 coreLoopStackPtr
    6.56 + *
    6.57 + * _VMSMasterEnv  offsets:
    6.58 + * 0x24 coreLoopStartPt
    6.59 + * 0x28 coreLoopEndPt
    6.60 + * 0x30 masterLock
    6.61 + */
    6.62 +.globl switchToCoreLoop
    6.63 +switchToCoreLoop:
    6.64 +    movl    0x4(%esp) , %ecx         #get VirtProcr
    6.65 +    movl    $VPReturn , 0x14(%ecx)   #store return address
    6.66 +    movl    %esp      , 0x0c(%ecx)   #save stack pointer 
    6.67 +    movl    %ebp      , 0x10(%ecx)   #save frame pointer
    6.68 +    movl    0x20(%ecx), %esp         #restore stack pointer
    6.69 +    movl    0x1c(%ecx), %ebp         #restore frame pointer
    6.70 +    movl    $_VMSMasterEnv, %ecx
    6.71 +    movl    (%ecx)    , %ecx
    6.72 +    movl    0x24(%ecx), %eax         #get CoreLoopStartPt
    6.73 +    jmp     *%eax                    #jmp to CoreLoop
    6.74 +VPReturn:
    6.75 +    ret
    6.76 +
    6.77 +
    6.78 +
    6.79 +//switches to core loop from master. saves return address
    6.80 +/* VirtProcr  offsets:
    6.81 + * 0xc  stackPtr
    6.82 + * 0x10 framePtr
    6.83 + * 0x14 nextInstrPt
    6.84 + * 0x1c coreLoopFramePtr
    6.85 + * 0x20 coreLoopStackPtr
    6.86 + *
    6.87 + * _VMSMasterEnv  offsets:
    6.88 + * 0x24 coreLoopStartPt
    6.89 + * 0x28 coreLoopEndPt
    6.90 + * 0x30 masterLock
    6.91 + */
    6.92 +.globl masterSwitchToCoreLoop
    6.93 +masterSwitchToCoreLoop:
    6.94 +    movl    0x4(%esp) , %ecx         #get VirtProcr
    6.95 +    movl    $MasterReturn, 0x14(%ecx)   #store return address
    6.96 +    movl    %esp      , 0x0c(%ecx)   #save stack pointer 
    6.97 +    movl    %ebp      , 0x10(%ecx)   #save frame pointer
    6.98 +    movl    0x20(%ecx), %esp         #restore stack pointer
    6.99 +    movl    0x1c(%ecx), %ebp         #restore frame pointer
   6.100 +    movl    $_VMSMasterEnv, %ecx
   6.101 +    movl    (%ecx)    , %ecx
   6.102 +    movl    0x24(%ecx), %eax         #get CoreLoopStartPt
   6.103 +    movl    $0x0      , 0x30(%ecx)   #release lock
   6.104 +    jmp     *%eax                    #jmp to CoreLoop
   6.105 +MasterReturn:
   6.106 +    ret
   6.107 +
   6.108 +
   6.109 +//Switch to terminateCoreLoop
   6.110 +//no need to call because the stack is already set up for switchVP
   6.111 +//do not save register of VP because this function will never return
   6.112 +/* VirtProcr  offsets:
   6.113 + * 0xc  stackPtr
   6.114 + * 0x10 framePtr
   6.115 + * 0x14 nextInstrPt
   6.116 + * 0x1c coreLoopFramePtr
   6.117 + * 0x20 coreLoopStackPtr
   6.118 + *
   6.119 + * _VMSMasterEnv  offsets:
   6.120 + * 0x24 coreLoopStartPt
   6.121 + * 0x28 coreLoopEndPt
   6.122 + * 0x30 masterLock
   6.123 + */
   6.124 +.globl asmTerminateCoreLoop
   6.125 +asmTerminateCoreLoop:
   6.126 +    movl    0x4(%esp) , %ecx         #get VirtProcr
   6.127 +    movl    0x20(%ecx), %esp         #restore stack pointer
   6.128 +    movl    0x1c(%ecx), %ebp         #restore frame pointer
   6.129 +    movl    $terminateCoreLoop, %eax
   6.130 +    jmp     *%eax                    #jmp to CoreLoop 
   6.131 +