Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
changeset 15:cb10b58404ab
Forgot to commit after had working test -- changed stack & frame ptrs in thd params
to be instead in virt procr struc -- stopped working! Saving now, then going back to
way had it..
| author | Me |
|---|---|
| date | Tue, 22 Jun 2010 11:53:23 -0700 |
| parents | 65c8fb2821ee |
| children | c3e6c3fda84e |
| files | CoreLoop.c |
| diffstat | 1 files changed, 72 insertions(+), 17 deletions(-) [+] |
line diff
1.1 --- a/CoreLoop.c Tue Jun 22 11:52:41 2010 -0700 1.2 +++ b/CoreLoop.c Tue Jun 22 11:53:23 2010 -0700 1.3 @@ -33,17 +33,30 @@ 1.4 //Designate a core by a 1 in bit-position corresponding to the core 1.5 SetThreadAffinityMask(GetCurrentThread(),1 << coreLoopThdParams->coreNum); 1.6 1.7 - //for non-gcc, can make macro that does asm that calls dummy that 1.8 - // pulls addr off the stack and stores it in pointed-to location. 1.9 - coreLoopThdParams->endThdPt = &&EndCoreLoop; 1.10 + //Save the stack pointer and frame pointer of this coreLoop's thread 1.11 +// asm volatile("movl %%ebp, %0; \ 1.12 + movl %%esp, %1; "\ 1.13 + /* outputs */ : "=m" (coreLoopThdParams->framePtr), \ 1.14 + "=m" (coreLoopThdParams->stackPtr) \ 1.15 + /* inputs */ : \ 1.16 + ); 1.17 + 1.18 + //Save addr of "end core loop" label - jump to it to shut down coreloop 1.19 + //To get label addr in non-gcc compiler, can trick it by making a call 1.20 + // to a fn that does asm that pulls the "return" 1.21 + // addr off the stack and stores it in a pointed-to location. 1.22 + coreLoopThdParams->endThdPt = &&EndCoreLoop; 1.23 + _VMSMasterEnv->coreLoopShutDownPt = &&EndCoreLoop; //haven't decided yet 1.24 + //which way will do shutdown of core loops 1.25 1.26 //Core loop has no values live upon CoreLoopStartPt except workQ 1.27 // every value in the code is defined by a statement in core loop, 1.28 - // after the start point, before being used -- with the one exception 1.29 - // of _VMSWorkQ 1.30 + // after the start point -- with the one exception of _VMSWorkQ 1.31 1.32 1.33 // Get to work! -- virt procr jumps back here when done or suspends 1.34 + //Note, have to restore the frame-pointer before jump to here, to get 1.35 + // this code to work right (workQ and so forth are frame-ptr relative) 1.36 CoreLoopStartPt: 1.37 1.38 //Get virtual processor from queue 1.39 @@ -52,29 +65,71 @@ 1.40 workQ = _VMSWorkQ; 1.41 currPr = (VirtProcr *) readCASQ( workQ ); 1.42 currPr->coreLoopStartPt = &&CoreLoopStartPt; //just to be sure.. 1.43 + 1.44 + currPr->coreAnimatedBy = coreLoopThdParams->coreNum; 1.45 1.46 //switch to virt procr's stack and frame ptr then jump to virt procr 1.47 - void *stackPtr, *framePtr, *jmpPt; 1.48 + void *stackPtr, *framePtr, *jmpPt, *jmpPt_saveForLater; 1.49 1.50 stackPtr = currPr->stackPtr; 1.51 framePtr = currPr->framePtr; 1.52 jmpPt = currPr->nextInstrPt; 1.53 1.54 - //TODO: careful with this -- use printfs -- in test, thds 0 and 3 have 1.55 - // SAME STACK PTR!! Might be a something going on -- each thd should 1.56 - // have its own unique stack.. 1.57 - asm volatile("movl %0, %%esp; \ 1.58 - movl %1, %%ebp; \ 1.59 - jmp %2" 1.60 - /* outputs */ : 1.61 - /* inputs */ : "g" (stackPtr), "g" (framePtr), "g" (jmpPt) 1.62 - /* clobber */ : "memory" /*just in case, Q: tell about esp, ebp?*/ 1.63 + //Save the core loop's stack and frame pointers into virt procr struct 1.64 + // then switch to stack ptr and frame ptr of virt procr & jmp to it 1.65 + //This was a pain to get right because GCC converts the "(jmpPt)" to 1.66 + // frame-relative mem-op -- so generated machine code first changed the 1.67 + // frame pointer, then tried to jump to an addr stored on stack, which 1.68 + // it accessed as an offset from frame-ptr! (wrong frame-ptr now) 1.69 + //Explicitly loading into eax before changing frame-ptr fixed it 1.70 + asm volatile("movl %%ebp, %0; \ 1.71 + movl %%esp, %1; \ 1.72 + movl %2, %%eax; \ 1.73 + movl %3, %%esp; \ 1.74 + movl %4, %%ebp; \ 1.75 + jmp %%eax" \ 1.76 + /* outputs */ : "=g"(currPr->coreLoopFramePtr), \ 1.77 + "=g"(currPr->coreLoopStackPtr) \ 1.78 + /* inputs */ : "g" (jmpPt), "g" (stackPtr), "g" (framePtr) \ 1.79 + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ 1.80 ); 1.81 + 1.82 //======================================================================== 1.83 1.84 - //Note: will only exit when all work done -- so core loop's 1.85 - // stack, which is the thread's stack, can be safely ignored 1.86 //jmp to here when want to shut down the VMS system 1.87 EndCoreLoop: 1.88 ExitThread( 0 ); 1.89 } 1.90 + 1.91 +void 1.92 +postJumpTestFn( void *dummy, VirtProcr *animatingPr ) 1.93 + { 1.94 + //============== test =============== 1.95 + //switch to stack ptr and frame ptr of virt procr 1.96 + void *stackInitData, *stackAnimPr, *framePtr; 1.97 + 1.98 + //Get the input params: 1.99 + //The return addr and the old frame ptr have been pushed, then the new 1.100 + // frame ptr set to top-of-stack -- so there are 2 values between 1.101 + // frame ptr and the input params -- offset past those and get the 1.102 + // input params. 1.103 + asm volatile("movl 0x8(%%ebp), %0; \ 1.104 + movl 0xc(%%ebp), %1; \ 1.105 + movl %%ebp, %2 " \ 1.106 + /* outputs */ : "=r" (stackInitData), "=r"(stackAnimPr), "=r"(framePtr) \ 1.107 + /* inputs */ : \ 1.108 + ); 1.109 + 1.110 + 1.111 + printf( "\njump to function start! | %d | %d | %d \n", (int)stackInitData, 1.112 + ((VirtProcr *)stackAnimPr)->procrID), 1.113 + framePtr; 1.114 + 1.115 + VMS__suspend_processor( animatingPr ); 1.116 + 1.117 + printf( "\n came back from suspend -- wooohooo !\n" ); 1.118 + 1.119 + //============== end test ============= 1.120 + 1.121 + ExitThread( 0 ); 1.122 + } 1.123 \ No newline at end of file
