# HG changeset patch # User Me # Date 1277232761 25200 # Node ID 65c8fb2821eeb2ec9319a67d148b4796df747b5d # Parent 4b58b9a2527b943026be7b3a7f8201762024095e 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 4b58b9a2527b -r 65c8fb2821ee VMS.c --- a/VMS.c Sat Jun 19 19:26:49 2010 -0700 +++ b/VMS.c Tue Jun 22 11:52:41 2010 -0700 @@ -105,6 +105,7 @@ VMS__start() { int coreIdx; + //TODO: Save "orig" stack pointer and frame ptr -- restore in VMS__end() //Create the win threads that animate the core loops for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) { @@ -145,13 +146,15 @@ newPr->nextInstrPt = fnPtr; newPr->initialData = initialData; + //fnPtr takes two params -- void *initData & void *animProcr //alloc stack locations, make stackPtr be the highest addr minus room - // for 2 params. Put initData at stackPtr, animatingPr just above + // for 2 params + return addr. Return addr (NULL) is in loc pointed to + // by stackPtr, initData at stackPtr + 4 bytes, animatingPr just above stackLocs = malloc( 0x100000 ); //1 meg stack -- default Win thread's size - stackPtr = ( (char *)stackLocs + 0x100000 - 0x8 ); + stackPtr = ( (char *)stackLocs + 0x100000 - 0x10 ); //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp - *( (int *)stackPtr + 1) = (int) newPr; //rightmost param -- 32bit pointer - *( (int *)stackPtr ) = (int) initialData; //next param to left + *( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer + *( (int *)stackPtr + 1 ) = (int) initialData; //next param to left newPr->stackPtr = stackPtr; //core loop will switch to this, then newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr @@ -183,25 +186,38 @@ */ void VMS__suspend_processor( VirtProcr *callingPr ) - { void *jmpPt, *stackPtr, *framePtr; + { void *jmpPt, *stackPtrAddr, *framePtrAddr, *coreLoopStackPtr; + void *coreLoopFramePtr; + int coreIdx; + //The request to master will cause this suspended virt procr to get + // scheduled again at some future point -- to resume, core loop jumps + // to the resume point (below), which causes restore of saved regs and + // "return" from this call. callingPr->nextInstrPt = &&ResumePt; //return ownership of the virt procr and sched slot to Master virt pr callingPr->schedSlot->workIsDone = TRUE; +// coreIdx = callingPr->coreAnimatedBy; - jmpPt = callingPr->coreLoopStartPt; - stackPtr = &(callingPr->stackPtr); - framePtr = &(callingPr->framePtr); +// stackPtrAddr = &(callingPr->stackPtr); +// framePtrAddr = &(callingPr->framePtr); + + jmpPt = callingPr->coreLoopStartPt; + coreLoopFramePtr = callingPr->coreLoopFramePtr;//need this only + coreLoopStackPtr = callingPr->coreLoopStackPtr; +// coreLoopStackPtr = coreLoopThdParams[ coreIdx ]->stackPtr;//prob dont need - //put all regs in the clobber list to make sure GCC has saved all - // so safe to jump to core loop, where they *will* get clobbered + //Save the virt procr's stack and frame ptrs, restore coreloop's frame + // ptr, then jump back to "start" of core loop asm volatile("movl %%esp, %0; \ movl %%ebp, %1; \ - jmp %2 " - /* outputs */ : "=g" (stackPtr), "=g" (framePtr) - /* inputs */ : "g" (jmpPt) - /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" + movl %3, %%eax; \ + movl %2, %%ebp; \ + jmp %%eax " \ + /* outputs */ : "=g" (callingPr->stackPtr), "=g" (callingPr->framePtr) \ + /* inputs */ : "g"(coreLoopFramePtr), "g" (jmpPt) \ + /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \ ); //list everything as clobbered to force GCC to save all // live vars that are in regs on stack before this // assembly, so that stack pointer is correct, before jmp @@ -229,11 +245,17 @@ void VMS__shutdown() { int coreIdx; + VirtProcr *shutDownPr; - //Create the win threads that animate the core loops + //TODO: restore the "orig" stack pointer and frame ptr saved in VMS__start + //create a "special" virtual processor, one for each core loop that has + // the "loop end" point as its "next instr" point -- when the core loop + // jumps to animate the virt procr, the jump lands it at its own + // shut-down code. for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) { - + shutDownPr = VMS__create_procr( NULL, NULL ); + shutDownPr->nextInstrPt = _VMSMasterEnv->coreLoopShutDownPt; } }