# HG changeset patch # User Me # Date 1277232803 25200 # Node ID cb10b58404abc7bfc3fef860e8dab78b7d6f1224 # Parent 65c8fb2821eeb2ec9319a67d148b4796df747b5d 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.. diff -r 65c8fb2821ee -r cb10b58404ab CoreLoop.c --- a/CoreLoop.c Tue Jun 22 11:52:41 2010 -0700 +++ b/CoreLoop.c Tue Jun 22 11:53:23 2010 -0700 @@ -33,17 +33,30 @@ //Designate a core by a 1 in bit-position corresponding to the core SetThreadAffinityMask(GetCurrentThread(),1 << coreLoopThdParams->coreNum); - //for non-gcc, can make macro that does asm that calls dummy that - // pulls addr off the stack and stores it in pointed-to location. - coreLoopThdParams->endThdPt = &&EndCoreLoop; + //Save the stack pointer and frame pointer of this coreLoop's thread +// asm volatile("movl %%ebp, %0; \ + movl %%esp, %1; "\ + /* outputs */ : "=m" (coreLoopThdParams->framePtr), \ + "=m" (coreLoopThdParams->stackPtr) \ + /* inputs */ : \ + ); + + //Save addr of "end core loop" label - jump to it to shut down coreloop + //To get label addr in non-gcc compiler, can trick it by making a call + // to a fn that does asm that pulls the "return" + // addr off the stack and stores it in a pointed-to location. + coreLoopThdParams->endThdPt = &&EndCoreLoop; + _VMSMasterEnv->coreLoopShutDownPt = &&EndCoreLoop; //haven't decided yet + //which way will do shutdown of core loops //Core loop has no values live upon CoreLoopStartPt except workQ // every value in the code is defined by a statement in core loop, - // after the start point, before being used -- with the one exception - // of _VMSWorkQ + // after the start point -- with the one exception of _VMSWorkQ // Get to work! -- virt procr jumps back here when done or suspends + //Note, have to restore the frame-pointer before jump to here, to get + // this code to work right (workQ and so forth are frame-ptr relative) CoreLoopStartPt: //Get virtual processor from queue @@ -52,29 +65,71 @@ workQ = _VMSWorkQ; currPr = (VirtProcr *) readCASQ( workQ ); currPr->coreLoopStartPt = &&CoreLoopStartPt; //just to be sure.. + + currPr->coreAnimatedBy = coreLoopThdParams->coreNum; //switch to virt procr's stack and frame ptr then jump to virt procr - void *stackPtr, *framePtr, *jmpPt; + void *stackPtr, *framePtr, *jmpPt, *jmpPt_saveForLater; stackPtr = currPr->stackPtr; framePtr = currPr->framePtr; jmpPt = currPr->nextInstrPt; - //TODO: careful with this -- use printfs -- in test, thds 0 and 3 have - // SAME STACK PTR!! Might be a something going on -- each thd should - // have its own unique stack.. - asm volatile("movl %0, %%esp; \ - movl %1, %%ebp; \ - jmp %2" - /* outputs */ : - /* inputs */ : "g" (stackPtr), "g" (framePtr), "g" (jmpPt) - /* clobber */ : "memory" /*just in case, Q: tell about esp, ebp?*/ + //Save the core loop's stack and frame pointers into virt procr struct + // then switch to stack ptr and frame ptr of virt procr & jmp to it + //This was a pain to get right because GCC converts the "(jmpPt)" to + // frame-relative mem-op -- so generated machine code first changed the + // frame pointer, then tried to jump to an addr stored on stack, which + // it accessed as an offset from frame-ptr! (wrong frame-ptr now) + //Explicitly loading into eax before changing frame-ptr fixed it + asm volatile("movl %%ebp, %0; \ + movl %%esp, %1; \ + movl %2, %%eax; \ + movl %3, %%esp; \ + movl %4, %%ebp; \ + jmp %%eax" \ + /* outputs */ : "=g"(currPr->coreLoopFramePtr), \ + "=g"(currPr->coreLoopStackPtr) \ + /* inputs */ : "g" (jmpPt), "g" (stackPtr), "g" (framePtr) \ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi", "%esi" \ ); + //======================================================================== - //Note: will only exit when all work done -- so core loop's - // stack, which is the thread's stack, can be safely ignored //jmp to here when want to shut down the VMS system EndCoreLoop: ExitThread( 0 ); } + +void +postJumpTestFn( void *dummy, VirtProcr *animatingPr ) + { + //============== test =============== + //switch to stack ptr and frame ptr of virt procr + void *stackInitData, *stackAnimPr, *framePtr; + + //Get the input params: + //The return addr and the old frame ptr have been pushed, then the new + // frame ptr set to top-of-stack -- so there are 2 values between + // frame ptr and the input params -- offset past those and get the + // input params. + asm volatile("movl 0x8(%%ebp), %0; \ + movl 0xc(%%ebp), %1; \ + movl %%ebp, %2 " \ + /* outputs */ : "=r" (stackInitData), "=r"(stackAnimPr), "=r"(framePtr) \ + /* inputs */ : \ + ); + + + printf( "\njump to function start! | %d | %d | %d \n", (int)stackInitData, + ((VirtProcr *)stackAnimPr)->procrID), + framePtr; + + VMS__suspend_processor( animatingPr ); + + printf( "\n came back from suspend -- wooohooo !\n" ); + + //============== end test ============= + + ExitThread( 0 ); + } \ No newline at end of file