2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Change the stack of a task.
9 /******************************************************************************
12 AROS_LH1(void, StackSwap,
15 AROS_LHA(struct StackSwapStruct *, newStack, A0),
18 struct ExecBase *, SysBase, 122, Exec)
21 Change the stack of a task.
24 sss - The description of the new stack
27 There will be a new stack.
30 Calling this routine the first time will change sss and
31 calling it a second time, the changes will be undone.
40 This is a symmetrical routine. If you call it twice, then
41 everything will be as it was before.
45 ******************************************************************************/
51 .globl AROS_SLIB_ENTRY(StackSwap,Exec)
52 .type AROS_SLIB_ENTRY(StackSwap,Exec),@function
54 /* The stack looks like this:
64 AROS_SLIB_ENTRY
(StackSwap
,Exec
):
66 /* Read parameter sss */
70 /* copy new SP into a1 */
71 move.
l stk_Pointer
(%a0
),%a1
73 /* Pop return address and sss from the current stack and copy them
74 onto the one specified in sss */
75 move.
l (%sp
)+,%d0
/* pop Return address */
77 move.
l %d0
,-12(%a1
) /* Push return address on new stack */
78 move.
l (%sp
)+,-8(%a1
) /* pop sss and push on new stack */
80 move.
l %d0
,-(%a1
) /* Push return address on new stack */
84 /* Copy SysBase from the current stack onto the one in sss */
86 move.
l %a6
,-4(%a1
) /* Push SysBase on new stack */
88 /* Calc new start of stack in sss */
92 /* Call Disable() (SysBase is still on the stack) */
95 move.
l (%sp
)+,%a6
/* Remove SysBase from current stack */
98 move.
l %sp
,stk_Pointer
(%a0
) /* Save current SP in sss */
99 movel
%a1
,%sp
/* Load the new stack */
101 move.
l ThisTask
(%a6
),%a1
102 lea.
l tc_SPLower
(%a1
),%a1
/* a1 = &SysBase->ThisTask->tc_SPLower */
104 /* Swap ThisTask->tc_SPLower and sss->stk_Lower */
105 move.
l stk_Lower
(%a0
),%d0
108 move.
l %d1
,stk_Lower
(%a0
)
110 /* Swap tc_SPUpper and sss->stk_Upper, too */
111 move.
l stk_Upper
(%a0
),%d0
114 move.
l %d1
,stk_Upper
(%a0
)
118 move.
l SysBase
(%sp
),%a6
119 move.
l %a6
,-(%sp
) /* push SysBase on new stack */
121 jsr Enable
(%a6
) /* call enable */
123 addq.w
#4,%sp /* Clean stack */
126 /* Note that at this time, the new stack from sss contains the
127 same values as the previous stack */