2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 Desc: NewStackSwap() - Call a function with swapped stack.
8 /*****************************************************************************
11 #include <exec/tasks.h>
12 #include <proto/exec.h>
14 AROS_LH3(IPTR, NewStackSwap,
17 AROS_LHA(struct StackSwapStruct *, sss, A0),
18 AROS_LHA(LONG_FUNC, entry, A1),
19 AROS_LHA(struct StackSwapArgs *, args, A2),
22 struct ExecBase *, SysBase, 134, Exec)
25 Calls a function with a new stack.
28 sss - A structure containing the values for the upper, lower
29 and current bounds of the stack you wish to use.
30 entry - Address of the function to call.
31 args - A structure (actually an array) containing up to 8
32 function arguments. The function is called using C calling
33 convention (no AROS_UHFx macro needed).
36 A value actually returned by your function. The function will be
37 running on a new stack.
44 Do not attempt to pass in a prebuilt stack - it will be erased.
50 This function is be replaced in $(ARCH).
52 ******************************************************************************/
53 #include "aros/m68k/asm.h"
57 .globl AROS_SLIB_ENTRY(NewStackSwap,Exec,134)
58 AROS_SLIB_ENTRY(NewStackSwap,Exec,134):
59 /* Stackswap will clobber %d0, %d1, %a0, and %a1,
60 * so we need to save %a0/%a1 in %a3/%a4
68 move.l %a2@(7*4),%sp@- // Put the C arguments on the stack
69 move.l %a2@(6*4),%sp@-
70 move.l %a2@(5*4),%sp@-
71 move.l %a2@(4*4),%sp@-
72 move.l %a2@(3*4),%sp@-
73 move.l %a2@(2*4),%sp@-
74 move.l %a2@(1*4),%sp@-
75 move.l %a2@(0*4),%sp@-
77 jsr %a4@ // Call the C function
79 lea.l %sp@(8*4),%sp // Remove the C arguments
81 move.l %d0,%a4 // save C function returncode
86 /* Now we can restore %a3/%a4