Message Edited by flashtoo on 2007-03-1907:36 AM
/*************************************************** * tk_switch * * Called with the new task pointer as the first * address on the stack. All registers are copied * to the stack. Interrupts are masked on entry * and returned to previous state on exit. * */ _tk_switch:tk_switch: move.w %sr, %d1 /* Preserve sr */ move.w #0x2700, %sr /* Disable interrupts */ link %a6, #-44 /* Push a6 and reserve space for the other registers */ /* a6 = sp - 4, sp = sp - 48 */ movem.l %d2-%d7/%a1-%a5, (%sp) /* Push d2 to d7 and a1 to a5 onto the stack */ /* Now we have stacked all the registers that matter */ move.l 12(%a6), %d0 /* Get the task pointer that was passed to the function */ /* This will be the first 4 bytes on the stack after the */ /* return address */ movea.l (tk_cur), %a1 /* Get a pointer to the current task */ move.l %a7, tk_fp(%a1) /* Save sp (a7) in the task struct */ move.l %d0, tk_cur /* Install new (passed) task */ movea.l %d0, %a1 /* Address new task */ movea.l tk_fp(%a1), %a7 /* Install new task's stack */ movem.l (%sp), %d2-%d7/%a1-%a5 /* Pop registers from the new stack */ lea 44(%sp), %a6 /* Adjust a6 based on the new task's sp */ unlk %a6 /* Pop a6 from the new task's stack */ move.w %d1, %sr /* Restore old sr */ rts /* Return in new task context */
. = ALIGN(0x04); #Add this line ___SP_END = .; . = . + (0x1000); ___SP_INIT = .;
FlashToo
_tk_frame: move.w SR, D1 /* Preserve sr */ move.w #0x2700, SR /* Disable interrupts */ link A6,#-4 /* Create frame and get local memory */ movem.l D2,(SP) /* Save D2 */ move.l 8(A6),A0 /* get passed task */ move.l tk_stack(A0),D2 /* get it's stack base */ add.l tk_size(A0),D2 /* add stack size - top of new stack */ move.l #52,D0 sub.l D0,D2 /* deduct room for frame */ move.l 12(A6),D0 /* get passed function pointer */ move.l D2,A0 /* address stack (FP) for new task */ move.l D0,48(A0) /* Install it in task's stack */ move.l D2,D0 /* return task->fp */ movem.l (SP),D2 /* restore D2 */ unlk A6 move.w D1, SR /* Restore old sr */ rts
_tk_getsp: move.l A7,D0 /* return stack pointer */// add what calling this function uses too add.l #4,D0 rts