2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
6 #include <exec/tasks.h>
8 #include <proto/exec.h>
12 #include <aros/debug.h>
15 #define STACK_SIZE 32768
18 #define StackSwapArgs PPCStackSwapArgs
19 #define NewStackSwap NewPPCStackSwap
22 struct StackSwapStruct sss
;
24 int __nocommandline
= 1;
26 void PrintSSS(struct StackSwapStruct
*ss
)
28 print("StackSwapStruct contents:\n");
29 print("Lower: 0x%P, Upper: 0x%P, SP: 0x%P\n", ss
->stk_Lower
, ss
->stk_Upper
, ss
->stk_Pointer
);
32 void PrintTaskStack(void)
34 struct Task
*t
= FindTask(NULL
);
36 print("Current program stack:\n");
37 print("Lower: 0x%P, Upper: 0x%P, SP: 0x%P\n", t
->tc_SPLower
, t
->tc_SPUpper
, AROS_GET_SP
);
40 void Sub(IPTR a1
, IPTR a2
)
42 print("Stack swap done\n");
45 print("Arguments: %08lX, %08lX\n", a1
, a2
);
46 print("Coming back to original stack...\n");
49 /* We keep quiet unless an error occurs to avoid context switches */
50 BOOL
SilentSub(IPTR a1
, IPTR a2
)
54 struct Task
*t
= FindTask(NULL
);
58 print("ERROR: second parameter has incorrect value!\n");
63 if(t
->tc_SPReg
< t
->tc_SPLower
|| t
->tc_SPReg
> t
->tc_SPUpper
64 || sp
< t
->tc_SPLower
|| sp
> t
->tc_SPUpper
)
67 print("ERROR: invalid stack values in user function:\n");
68 print("Lower: 0x%P\tUpper: 0x%P\nSP(struct): 0x%P\tSP(reg): 0x%P\n",
69 t
->tc_SPLower
, t
->tc_SPUpper
, spreg
, sp
);
78 struct StackSwapArgs args
;
80 struct Task
*t
= FindTask(NULL
);
82 sss
.stk_Lower
= AllocMem(STACK_SIZE
, MEMF_ANY
);
85 print("Failed to allocate new stack!\n");
90 sss
.stk_Upper
= sss
.stk_Lower
+ STACK_SIZE
;
91 sss
.stk_Pointer
= sss
.stk_Upper
- sizeof(IPTR
);
95 print("Checking StackSwap()...\n");
98 Sub(0x12345678, 0xC001C0DE);
101 print("Came back from StackSwap()\n");
105 print("Checking NewStackSwap()...\n");
106 args
.Args
[0] = 0x1234ABCD;
107 args
.Args
[1] = 0xC0DEC001;
109 NewStackSwap(&sss
, Sub
, &args
);
110 print("Came back from NewStackSwap()\n");
114 /* Check that stack fields in task structure make sense */
116 print("Checking NewStackSwap() again...\n");
117 args
.Args
[0] = 0x1234ABCD;
118 args
.Args
[1] = (IPTR
)FindTask(NULL
);
121 NewStackSwap(&sss
, SilentSub
, &args
);
124 if(t
->tc_SPReg
< t
->tc_SPLower
|| t
->tc_SPReg
> t
->tc_SPUpper
125 || sp
< t
->tc_SPLower
|| sp
> t
->tc_SPUpper
)
128 print("ERROR: invalid stack values after return from user function:\n");
129 print("Lower: 0x%P\tUpper: 0x%P\nSP(struct): 0x%P\tSP(reg): 0x%P\n",
130 t
->tc_SPLower
, t
->tc_SPUpper
, spreg
, sp
);
134 FreeMem(sss
.stk_Lower
, STACK_SIZE
);