2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: RunProcess() - Run a process from an entry point with args
10 #include <aros/asmcall.h> /* LONG_FUNC */
11 #include <dos/dosextens.h>
12 #include <proto/exec.h>
13 #include <aros/debug.h>
16 /**************************************************************************
19 LONG
AROS_SLIB_ENTRY(RunProcess
,Dos
) (
22 struct Process
* proc
,
23 struct StackSwapStruct
* sss
,
27 struct DosLibrary
* DOSBase
)
30 Sets the stack as specified and calls the routine with the given
34 proc - Process context
36 argptr - Pointer to argument string
37 argsize - Size of the argument string
38 entry - The entry point of the function
39 DOSBase - Pointer to dos.library structure
42 The return value of (*entry)();
54 **************************************************************************/
59 register ULONG real_sp
asm("r1");
65 /* Get the real stack pointer */
66 asm volatile ("mr %0,%1":"=r"(sp
):"r"(real_sp
));
68 /* Go one stack frame upper - now src points to the stackframe of caller */
71 /* Go one more stack frame up. Now you may copy from src to dst (src - sp) IPTR's */
74 dst
= (ULONG
*)((IPTR
)sss
->stk_Upper
- SP_OFFSET
);
76 /* Rewind the dst pointer too. */
79 /* Copy the two stack frames */
85 sss
->stk_Pointer
= dst
;
89 oldReturnAddr
= proc
->pr_ReturnAddr
;
91 /* Compute argsize automatically */
94 argsize
= strlen(argptr
);
97 D(bug("In RunProcess() entry=%lx, *entry=%lx\n", (IPTR
)entry
, (IPTR
)*entry
));
99 D(bug("[sss] %08x %08x %08x\n", sss
->stk_Lower
, sss
->stk_Pointer
, sss
->stk_Upper
));
103 D(bug("[sss] %08x %08x %08x\n", sss
->stk_Lower
, sss
->stk_Pointer
, sss
->stk_Upper
));
105 /* Call the function with the new stack */
107 We have to set the pr_ReturnAddr pointer to the correct value
108 before we call the entry() otherwise some startup code will
111 This can be done rather more easily on the m68k than elsewhere.
114 *retptr
= AROS_UFC3R(ULONG
, entry
,
115 AROS_UFCA(STRPTR
, argptr
, A0
),
116 AROS_UFCA(ULONG
, argsize
, D0
),
117 AROS_UFCA(struct ExecBase
*, SysBase
, A6
),
118 &proc
->pr_ReturnAddr
, (sss
->stk_Upper
- (ULONG
)sss
->stk_Lower
)
123 D(bug("[sss] %08x %08x %08x\n", sss
->stk_Lower
, sss
->stk_Pointer
, sss
->stk_Upper
));
125 proc
->pr_ReturnAddr
= oldReturnAddr
;