de-lint
[AROS.git] / arch / ppc-all / exec / newstackswap.c
blob2ac808753a795efa4f2d122fe89f1df8d398e7ac
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: NewStackSwap() - Call a function with swapped stack.
6 Lang: english
7 */
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)
23 AROS_LIBFUNC_INIT
25 ULONG * retptr;
26 ULONG ret;
27 register ULONG real_sp asm("r1");
28 ULONG *sp;
29 ULONG *src;
30 ULONG *dst;
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 */
36 src = (ULONG*)*sp;
38 /* Go one more stack frame up. Now you may copy from src to dst (src - sp) IPTR's */
39 src = (ULONG*)*src;
41 dst = (ULONG*)((IPTR)sss->stk_Upper - SP_OFFSET);
43 /* Copy the two stack frames */
44 while (src != sp)
46 *--dst = *--src;
49 sss->stk_Pointer = dst;
51 retptr = &ret;
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));
56 StackSwap(sss);
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 */
61 if (args != NULL)
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],
65 args->Args[7]);
67 else
68 *retptr = entry();
70 StackSwap(sss);
72 return ret;
74 AROS_LIBFUNC_EXIT
75 } /* NewStackSwap() */