exec.library: LVO mismatch fixes
[AROS.git] / test / exec / stackswap.c
blobbd85298755a3d76ed564e3fd77fde50c5db79db3
1 #include <exec/tasks.h>
2 #include <proto/dos.h>
3 #include <proto/exec.h>
5 #define print Printf
6 /*
7 #include <aros/debug.h>
8 #define print bug
9 */
10 #define STACK_SIZE 32768
12 #ifdef __MORPHOS__
13 #define StackSwapArgs PPCStackSwapArgs
14 #define NewStackSwap NewPPCStackSwap
15 #endif
17 struct StackSwapStruct sss;
19 int __nocommandline = 1;
21 void PrintSSS(struct StackSwapStruct *ss)
23 print("StackSwapStruct contents:\n");
24 print("Lower: 0x%P, Upper: 0x%P, SP: 0x%P\n", ss->stk_Lower, ss->stk_Upper, ss->stk_Pointer);
27 void PrintTaskStack(void)
29 struct Task *t = FindTask(NULL);
31 print("Current program stack:\n");
32 print("Lower: 0x%P, Upper: 0x%P, SP: 0x%P\n", t->tc_SPLower, t->tc_SPUpper, t->tc_SPReg);
35 void Sub(IPTR a1, IPTR a2)
37 print("Stack swap done\n");
38 PrintSSS(&sss);
39 PrintTaskStack();
40 print("Arguments: %08lX, %08lX\n", a1, a2);
41 print("Coming back to original stack...\n");
44 int main(void)
46 struct StackSwapArgs args;
48 sss.stk_Lower = AllocMem(STACK_SIZE, MEMF_ANY);
49 if (!sss.stk_Lower)
51 print("Failed to allocate new stack!\n");
53 return 1;
56 sss.stk_Upper = sss.stk_Lower + STACK_SIZE;
57 sss.stk_Pointer = sss.stk_Upper;
58 PrintSSS(&sss);
59 PrintTaskStack();
61 print("Checking StackSwap()...\n");
62 StackSwap(&sss);
64 Sub(0x12345678, 0xC001C0DE);
66 StackSwap(&sss);
67 print("Came back from StackSwap()\n");
68 PrintSSS(&sss);
69 PrintTaskStack();
71 print("Checking NewStackSwap()...\n");
72 args.Args[0] = 0x1234ABCD;
73 args.Args[1] = 0xC0DEC001;
75 NewStackSwap(&sss, Sub, &args);
76 print("Came back from NewStackSwap()\n");
77 PrintSSS(&sss);
78 PrintTaskStack();
80 FreeMem(sss.stk_Lower, STACK_SIZE);
82 print("Done!\n");
83 return 0;