2 Copyright © 1995-2001, 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 "../include/aros/machine.i"
46 .globl AROS_SLIB_ENTRY(StackSwap,Exec)
48 AROS_SLIB_ENTRY(StackSwap,Exec):
51 // r0 contains parameter 'newStack'
52 // r1 contains ExecBase
53 // lr contains the return address
55 mov r3, r0 // newstack to r3
56 bl get_offsetof_ThisTask // result comes in r0
57 ldr r2, [r1, r0] // r2 contains pointer to current task
58 bl get_offsetof_tc_SPLower // result comes in r0
59 add r2, r2, r0 // r2 contains address of tc_SPLower
61 /* Disable interrupts */
62 stmdb sp!, {r0, r1, r2, r3, lr}
64 add r0, r0, #Disable // calculate function
65 mov lr, pc // return address to lr (should add 4?)
66 mov pc, r0 // call Disable()
67 ldmdb sp!, {r0, r1, r2, r3, lr}
69 /* Swap Lower boundaries */
70 ldr r0, [r2] // r0 holds contents of tc_SPLower
71 ldr r1, [r3] // r1 holds new contents of tc_SPLower
72 str r1, [r2], #4 // write new contents and postinc r2
73 str r0, [r3], #4 // save old contents back into passed struct
76 /* Swap higher boundaries */
77 ldr r0, [r2] // r0 hold contents of tc_SPHigher
78 ldr r1, [r3] // r1 holds new contents of tc_SPHigher
79 str r1, [r2] // write new contents
80 str r0, [r3], #4 // save old contents back into passed struct
83 /* Swap stackpointers */
84 mov r0, sp // current stack pointer to r0
85 ldr sp, [r3] // get desired stack pointer
86 str r0, [r3] // save old stack pointer
88 /* Enable interupts */
89 stmdb sp!, {r0, r1, r2, r3, lr}
91 add r1, r1, #Enable // calculate function
92 mov lr, pc // return address to lr (should add 4?)
93 mov pc, r0 // call Enable()
94 ldmdb sp!, {r0, r1, r2, r3, lr}
96 /* Return from this function. There's no 'rts' instruction...*/