2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
6 #include <aros/armeb/asm.h>
10 .globl AROS_SLIB_ENTRY(StackSwap,Exec,122)
12 AROS_SLIB_ENTRY(StackSwap,Exec,122):
14 // r0 contains parameter 'newStack'
15 // r1 contains ExecBase
16 // lr contains the return address
18 stmfd sp!, {r0, r1, lr} // save some useful registers
20 ldr ip, [r1, #-196] // Call FindTask(NULL)
22 mov r2, r0 // copy result to r2 register
23 ldmfd sp!, {r0, r1, lr} // restore r0, r1 and lr
24 mov r3, r0 // newstack to r3
26 /* Disable interrupts */
27 stmfd sp!, {r0, r1, r2, r3, lr}
28 ldr ip, [r1, Disable] // ip = GETVECADDR(Disable)
29 mov r0, r1 // One argument = SysBase
31 ldmfd sp!, {r0, r1, r2, r3, lr}
33 /* Swap Lower boundaries, use ip as scratch register (r1 holds SysBase!!!!) */
34 ldr r0, [r2, tc_SPLower] // r0 holds old contents of tc_SPLower
35 ldr ip, [r3, stk_Lower] // ip holds new contents of tc_SPLower
36 str ip, [r2, tc_SPLower] // write new contents
37 str r0, [r3, stk_Lower] // save old contents back into passed struct
40 /* Swap higher boundaries */
41 ldr r0, [r2, tc_SPUpper] // r0 holds old contents of tc_SPHigher
42 ldr ip, [r3, stk_Upper] // ip holds new contents of tc_SPHigher
43 str ip, [r2, tc_SPUpper] // write new contents
44 str r0, [r3, stk_Upper] // save old contents back into passed struct
46 /* Swap stackpointers */
47 mov r0, sp // current stack pointer to r0
48 ldr sp, [r3, stk_Pointer] // get desired stack pointer
49 str r0, [r3, stk_Pointer] // save old stack pointer
51 /* Enable interupts */
52 stmfd sp!, {r0, r1, lr}
53 ldr ip, [r1, Enable] // ip = GETVECADDR(Enable)
54 mov r0, r1 // One argument = SysBase
56 ldmfd sp!, {r0, r1, lr}
58 /* Return from this function. There's no 'rts' instruction...*/