Mercurial > cgi-bin > hgwebdir.cgi > VMS > VMS_Implementations > VMS_impls > VMS__MC_shared_impl
comparison VMS.c @ 14:65c8fb2821ee
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:52:41 -0700 |
| parents | d801fe740275 |
| children | 734c665500e4 |
comparison
equal
deleted
inserted
replaced
| 3:8f2dd6dd4ccf | 4:b21e0df42f17 |
|---|---|
| 103 */ | 103 */ |
| 104 void | 104 void |
| 105 VMS__start() | 105 VMS__start() |
| 106 { int coreIdx; | 106 { int coreIdx; |
| 107 | 107 |
| 108 //TODO: Save "orig" stack pointer and frame ptr -- restore in VMS__end() | |
| 108 //Create the win threads that animate the core loops | 109 //Create the win threads that animate the core loops |
| 109 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 110 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 110 { | 111 { |
| 111 coreLoopThdParams[coreIdx] = (ThdParams *)malloc( sizeof(ThdParams) ); | 112 coreLoopThdParams[coreIdx] = (ThdParams *)malloc( sizeof(ThdParams) ); |
| 112 coreLoopThdParams[coreIdx]->coreNum = coreIdx; | 113 coreLoopThdParams[coreIdx]->coreNum = coreIdx; |
| 143 newPr = malloc( sizeof(VirtProcr) ); | 144 newPr = malloc( sizeof(VirtProcr) ); |
| 144 newPr->procrID = numProcrsCreated++; | 145 newPr->procrID = numProcrsCreated++; |
| 145 newPr->nextInstrPt = fnPtr; | 146 newPr->nextInstrPt = fnPtr; |
| 146 newPr->initialData = initialData; | 147 newPr->initialData = initialData; |
| 147 | 148 |
| 149 //fnPtr takes two params -- void *initData & void *animProcr | |
| 148 //alloc stack locations, make stackPtr be the highest addr minus room | 150 //alloc stack locations, make stackPtr be the highest addr minus room |
| 149 // for 2 params. Put initData at stackPtr, animatingPr just above | 151 // for 2 params + return addr. Return addr (NULL) is in loc pointed to |
| 152 // by stackPtr, initData at stackPtr + 4 bytes, animatingPr just above | |
| 150 stackLocs = malloc( 0x100000 ); //1 meg stack -- default Win thread's size | 153 stackLocs = malloc( 0x100000 ); //1 meg stack -- default Win thread's size |
| 151 stackPtr = ( (char *)stackLocs + 0x100000 - 0x8 ); | 154 stackPtr = ( (char *)stackLocs + 0x100000 - 0x10 ); |
| 152 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp | 155 //setup __cdecl on stack -- coreloop will switch to stackPtr before jmp |
| 153 *( (int *)stackPtr + 1) = (int) newPr; //rightmost param -- 32bit pointer | 156 *( (int *)stackPtr + 2 ) = (int) newPr; //rightmost param -- 32bit pointer |
| 154 *( (int *)stackPtr ) = (int) initialData; //next param to left | 157 *( (int *)stackPtr + 1 ) = (int) initialData; //next param to left |
| 155 newPr->stackPtr = stackPtr; //core loop will switch to this, then | 158 newPr->stackPtr = stackPtr; //core loop will switch to this, then |
| 156 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr | 159 newPr->framePtr = stackPtr; //suspend loop will save new stack & frame ptr |
| 157 | 160 |
| 158 return newPr; | 161 return newPr; |
| 159 } | 162 } |
| 181 * there, and will get passed along, inside the request handler, to the | 184 * there, and will get passed along, inside the request handler, to the |
| 182 * next work-unit for that procr. | 185 * next work-unit for that procr. |
| 183 */ | 186 */ |
| 184 void | 187 void |
| 185 VMS__suspend_processor( VirtProcr *callingPr ) | 188 VMS__suspend_processor( VirtProcr *callingPr ) |
| 186 { void *jmpPt, *stackPtr, *framePtr; | 189 { void *jmpPt, *stackPtrAddr, *framePtrAddr, *coreLoopStackPtr; |
| 187 | 190 void *coreLoopFramePtr; |
| 191 int coreIdx; | |
| 192 | |
| 193 //The request to master will cause this suspended virt procr to get | |
| 194 // scheduled again at some future point -- to resume, core loop jumps | |
| 195 // to the resume point (below), which causes restore of saved regs and | |
| 196 // "return" from this call. | |
| 188 callingPr->nextInstrPt = &&ResumePt; | 197 callingPr->nextInstrPt = &&ResumePt; |
| 189 | 198 |
| 190 //return ownership of the virt procr and sched slot to Master virt pr | 199 //return ownership of the virt procr and sched slot to Master virt pr |
| 191 callingPr->schedSlot->workIsDone = TRUE; | 200 callingPr->schedSlot->workIsDone = TRUE; |
| 192 | 201 // coreIdx = callingPr->coreAnimatedBy; |
| 193 jmpPt = callingPr->coreLoopStartPt; | 202 |
| 194 stackPtr = &(callingPr->stackPtr); | 203 // stackPtrAddr = &(callingPr->stackPtr); |
| 195 framePtr = &(callingPr->framePtr); | 204 // framePtrAddr = &(callingPr->framePtr); |
| 196 | 205 |
| 197 //put all regs in the clobber list to make sure GCC has saved all | 206 jmpPt = callingPr->coreLoopStartPt; |
| 198 // so safe to jump to core loop, where they *will* get clobbered | 207 coreLoopFramePtr = callingPr->coreLoopFramePtr;//need this only |
| 208 coreLoopStackPtr = callingPr->coreLoopStackPtr; | |
| 209 // coreLoopStackPtr = coreLoopThdParams[ coreIdx ]->stackPtr;//prob dont need | |
| 210 | |
| 211 //Save the virt procr's stack and frame ptrs, restore coreloop's frame | |
| 212 // ptr, then jump back to "start" of core loop | |
| 199 asm volatile("movl %%esp, %0; \ | 213 asm volatile("movl %%esp, %0; \ |
| 200 movl %%ebp, %1; \ | 214 movl %%ebp, %1; \ |
| 201 jmp %2 " | 215 movl %3, %%eax; \ |
| 202 /* outputs */ : "=g" (stackPtr), "=g" (framePtr) | 216 movl %2, %%ebp; \ |
| 203 /* inputs */ : "g" (jmpPt) | 217 jmp %%eax " \ |
| 204 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" | 218 /* outputs */ : "=g" (callingPr->stackPtr), "=g" (callingPr->framePtr) \ |
| 219 /* inputs */ : "g"(coreLoopFramePtr), "g" (jmpPt) \ | |
| 220 /* clobber */ : "memory", "%eax", "%ebx", "%ecx", "%edx", "%edi","%esi" \ | |
| 205 ); //list everything as clobbered to force GCC to save all | 221 ); //list everything as clobbered to force GCC to save all |
| 206 // live vars that are in regs on stack before this | 222 // live vars that are in regs on stack before this |
| 207 // assembly, so that stack pointer is correct, before jmp | 223 // assembly, so that stack pointer is correct, before jmp |
| 208 | 224 |
| 209 ResumePt: | 225 ResumePt: |
| 227 * special virt processor whose next instr pt is the core-end label. | 243 * special virt processor whose next instr pt is the core-end label. |
| 228 */ | 244 */ |
| 229 void | 245 void |
| 230 VMS__shutdown() | 246 VMS__shutdown() |
| 231 { int coreIdx; | 247 { int coreIdx; |
| 248 VirtProcr *shutDownPr; | |
| 232 | 249 |
| 233 //Create the win threads that animate the core loops | 250 //TODO: restore the "orig" stack pointer and frame ptr saved in VMS__start |
| 251 //create a "special" virtual processor, one for each core loop that has | |
| 252 // the "loop end" point as its "next instr" point -- when the core loop | |
| 253 // jumps to animate the virt procr, the jump lands it at its own | |
| 254 // shut-down code. | |
| 234 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) | 255 for( coreIdx=0; coreIdx < NUM_CORES; coreIdx++ ) |
| 235 { | 256 { |
| 236 | 257 shutDownPr = VMS__create_procr( NULL, NULL ); |
| 258 shutDownPr->nextInstrPt = _VMSMasterEnv->coreLoopShutDownPt; | |
| 237 } | 259 } |
| 238 } | 260 } |
| 239 | 261 |
| 240 | 262 |
| 241 | 263 |
