2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 /*****************************************************************************
10 AROS_LH1(void, StackSwap,
13 AROS_LHA(struct StackSwapStruct *, newStack, A0),
16 struct ExecBase *, SysBase, 122, Exec)
19 This function switches to the new stack given by the parameters in the
20 stackswapstruct structure. The old stack parameters are returned in
21 the same structure so that the stack can be restored later
24 newStack - parameters for the new stack
40 ******************************************************************************/
42 #include "aros/m68k/asm.h"
52 // Here's how the stack looks right now
53 // 0(%sp) : Return Address
56 /* Preserve returnaddress and fix sp */
57 move.l (%sp)+,%d1 // d1 contains return address
58 // now the stack is 'clean'
60 move.l %a6,%sp@- // save contents of %a6
62 /* Get pointer to tc_SPLower in a1 (tc_SPUpper is next) */
63 move.l 0x4,%a6 // execbase to a6
64 move.l %a6@(ThisTask),%a1
66 move.l %d1,%d0 // d0 contains return address now
69 movem.l %d0/%a0/%a1,%sp@- // d0: save return address on stack
70 // a0: param to this function onto stack
71 // a1: address of task to stack
72 /* Just to be sure interrupts always find a good stackframe */
73 jsr Disable(%a6) // disable interrupts
74 movem.l %sp@+,%d0/%a0/%a1 // a1 holds address of task
75 // a0 holds param to this function
76 // d0 holds return address
78 move.l (%sp)+,%a6 // original a6 from stack
80 /* Swap Lower boundaries */
81 move.l %a1@(tc_SPLower),%d1 // d1 holds content of tc_SPLower
82 move.l %a0@,%a1@(tc_SPLower) // write the content of the first param in
83 // the structure to this function to tc_SPLower
84 move.l %d1,%a0@+ // write old tc_SPLower to StackSwap
86 /* Swap higher boundaries */
87 move.l %a1@(tc_SPUpper),%d1 // d1 holds content of tc_SPUpper
88 move.l %a0@,%a1@(tc_SPUpper) // write the content of the 2nd param in
89 // the structure to this function to tc_SPUpper
90 move.l %d1,%a0@+ // write old tc_SPUpper to StackSwap
92 /* Swap stackpointers */
93 move.l %sp,%d1 // current stack pointer to d1
94 move.l %a0@,%sp // desired stack pointer to sp
95 move.l %d1,%a0@ // old stack pointer back into the structure
97 movem.l %d0/%a6,%sp@- // save %d0 onto stack
98 // save %a6 onto stack
100 /* Reenable interrupts. */
101 move.l 0x4,%a6 // get ExecBase
102 jsr Enable(%a6) // Enable interrupts
103 movem.l %sp@+,%d0/%a6 // restore orig. content of %a6 register
104 // restore return address to d0
106 /* Restore returnaddress and return */
107 move.l %d0,%sp@- // return address onto stack
109 // Here's how the stack looks right now
110 // 0(%sp) : Return Address
111 // 4(%sp) : fake pointer to StackSwap structure