config: fix build with external compiler by passing the sysroot where needed
[AROS.git] / arch / .unmaintained / m68k-emul / stackswap.s
blob65dde8698deab9c6d9d1e7c1d118f168369c3164
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Change the stack of a task.
6 Lang: english
7 */
9 /******************************************************************************
11 NAME
12 AROS_LH1(void, StackSwap,
14 SYNOPSIS
15 AROS_LHA(struct StackSwapStruct *, newStack, A0),
17 LOCATION
18 struct ExecBase *, SysBase, 122, Exec)
20 FUNCTION
21 Change the stack of a task.
23 INPUTS
24 sss - The description of the new stack
26 RESULT
27 There will be a new stack.
29 NOTES
30 Calling this routine the first time will change sss and
31 calling it a second time, the changes will be undone.
33 EXAMPLE
35 BUGS
37 SEE ALSO
39 INTERNALS
40 This is a symmetrical routine. If you call it twice, then
41 everything will be as it was before.
43 HISTORY
45 ******************************************************************************/
47 #include "machine.i"
49 .text
50 .balign 16
51 .globl AROS_SLIB_ENTRY(StackSwap,Exec)
52 .type AROS_SLIB_ENTRY(StackSwap,Exec),@function
54 /* The stack looks like this:
56 8 SysBase
57 4 sss
58 0 return address
61 #define sss 4
62 #define SysBase 8
64 AROS_SLIB_ENTRY(StackSwap,Exec):
65 #if !UseRegisterArgs
66 /* Read parameter sss */
67 move.l sss(%sp),%a0
68 #endif
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 */
76 #if !UseRegisterArgs
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 */
79 #else
80 move.l %d0,-(%a1) /* Push return address on new stack */
81 #endif
83 #if !UseRegisterArgs
84 /* Copy SysBase from the current stack onto the one in sss */
85 move.l (%sp),%a6
86 move.l %a6,-4(%a1) /* Push SysBase on new stack */
88 /* Calc new start of stack in sss */
89 add.l #-12,%a1
90 #endif
92 /* Call Disable() (SysBase is still on the stack) */
93 jsr Disable(%a6)
94 #if !UseRegisterArgs
95 move.l (%sp)+,%a6 /* Remove SysBase from current stack */
96 #endif
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
106 move.l (%a1),%d1
107 move.l %d0,(%a1)
108 move.l %d1,stk_Lower(%a0)
110 /* Swap tc_SPUpper and sss->stk_Upper, too */
111 move.l stk_Upper(%a0),%d0
112 move.l 4(%a1),%d1
113 move.l %d0,4(%a1)
114 move.l %d1,stk_Upper(%a0)
116 /* Call Enable() */
117 #if !UseRegisterArgs
118 move.l SysBase(%sp),%a6
119 move.l %a6,-(%sp) /* push SysBase on new stack */
120 #endif
121 jsr Enable(%a6) /* call enable */
122 #if !UseRegisterArgs
123 addq.w #4,%sp /* Clean stack */
124 #endif
126 /* Note that at this time, the new stack from sss contains the
127 same values as the previous stack */