4 INCLUDE "exec/funcdef.i"
5 INCLUDE "exec/exec_lib.i"
7 INCLUDE "dos/dosextens.i"
8 INCLUDE "libraries/reqtools.i"
9 INCLUDE "lvo/reqtools_lib.i"
11 * This function will make sure there are at least
4096 bytes free on
12 * the stack. If
this is
not the case it will allocate a new stack
and
13 * use
this for your function.
15 * Usage of CheckStackCallFunc
():
16 * Push your real functions
' address on the stack.
17 * Call CheckStackCallFunc()
18 * (note that you CANNOT pass arguments on the stack to your function
19 * because it is possible your function will run with a newly allocated
24 XDEF _CheckStackCallFunc
27 movem.l d0-d7/a0-a6,-(a7) ; push all regs
29 move.l ThisTask(a6),a3
31 ; move.l pr_CLI(a3),d0
35 ; move.l cli_DefaultStack(a0),d1
40 cmp.l TC_SPUPPER(a3),a7
43 cmp.l TC_SPLOWER(a3),a7
47 sub.l TC_SPLOWER(a3),d1
53 moveq #StackSwapStruct_SIZEOF,d0
54 add.l d7,d0 ; room for stackswap struct
63 move.l d0,stk_Lower(a4) ; lower bound
64 move.l a4,stk_Upper(a4) ; upper bound
68 move.l d0,-(a2) ; push address of new stack on new stack
69 lea returnaddr2(PC),a0
70 move.l a0,-(a2) ; push returnaddr2 on new stack
73 move.l d0,-(a2) ; push function address on new stack
75 lea 60(a7),a1 ; copy over regs from old to new stack
81 move.l a2,stk_Pointer(a4) ; current stack pointer
85 movem.l (a7)+,d0-d7/a0-a6
86 rts ; call function, return to returnaddr2
89 move.l (a7)+,a4 ; get address of new stack
94 jsr _LVOStackSwap(a6) ; swap back old stack
98 addq.l #4,a7 ; purge old d0
99 movem.l (a7)+,d1-d7/a0-a6
103 movem.l (a7)+,d0-d7/a0-a6
104 pea endcheckstack(PC)
105 move.l 8(a7),-(a7) ; push function's address
109 movem.l
(a7
)+,d0
-d7
/a0
-a6