2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: NewStackSwap() - Call a function with swapped stack.
9 #define __AROS_GIMME_DEPRECATED_STACKSWAP__
11 #include <aros/debug.h>
12 #include <exec/tasks.h>
13 #include <proto/exec.h>
15 /* See rom/exec/newstackswap.c for documentation */
17 AROS_LH3(IPTR
, NewStackSwap
,
18 AROS_LHA(struct StackSwapStruct
*, sss
, A0
),
19 AROS_LHA(LONG_FUNC
, entry
, A1
),
20 AROS_LHA(struct StackSwapArgs
*, args
, A2
),
21 struct ExecBase
*, SysBase
, 134, Exec
)
27 register ULONG real_sp
asm("r1");
32 /* Get the real stack pointer */
33 asm volatile ("mr %0,%1":"=r"(sp
):"r"(real_sp
));
35 /* Go one stack frame upper - now src points to the stackframe of caller */
38 /* Go one more stack frame up. Now you may copy from src to dst (src - sp) IPTR's */
41 dst
= (ULONG
*)((IPTR
)sss
->stk_Upper
- SP_OFFSET
);
43 /* Copy the two stack frames */
49 sss
->stk_Pointer
= dst
;
53 D(bug("In NewStackSwap() entry=%lx, *entry=%lx\n", (IPTR
)entry
, (IPTR
)*entry
));
54 D(bug("[sss] %08x %08x %08x\n", sss
->stk_Lower
, sss
->stk_Pointer
, sss
->stk_Upper
));
58 D(bug("[sss] %08x %08x %08x\n", sss
->stk_Lower
, sss
->stk_Pointer
, sss
->stk_Upper
));
60 /* Call the function with the new stack */
63 *retptr
= entry(args
->Args
[0], args
->Args
[1], args
->Args
[2],
64 args
->Args
[3], args
->Args
[4], args
->Args
[5], args
->Args
[6],
75 } /* NewStackSwap() */