Fixed a few warnings.
[tangerine.git] / arch / ppc-sam440 / dos / runprocess.c
blob185361749de6857e96dc753175448fed657f2c61
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: RunProcess() - Run a process from an entry point with args
6 Lang: english
7 */
9 #define DEBUG 0
10 #include <aros/asmcall.h> /* LONG_FUNC */
11 #include <dos/dosextens.h>
12 #include <proto/exec.h>
13 #include <aros/debug.h>
14 #include <string.h>
16 /**************************************************************************
18 NAME */
19 LONG AROS_SLIB_ENTRY(RunProcess,Dos) (
21 /* SYNOPSIS */
22 struct Process * proc,
23 struct StackSwapStruct * sss,
24 STRPTR argptr,
25 ULONG argsize,
26 LONG_FUNC entry,
27 struct DosLibrary * DOSBase)
29 /* FUNCTION
30 Sets the stack as specified and calls the routine with the given
31 arguments.
33 INPUTS
34 proc - Process context
35 sss - New Stack
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
41 RESULT
42 The return value of (*entry)();
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
52 INTERNALS
54 **************************************************************************/
56 ULONG * retptr;
57 ULONG ret;
58 APTR oldReturnAddr;
59 register ULONG real_sp asm("r1");
60 ULONG *sp;
61 ULONG *src;
62 ULONG *dst;
63 void *tmp;
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 */
69 src = (ULONG*)*sp;
71 /* Go one more stack frame up. Now you may copy from src to dst (src - sp) IPTR's */
72 src = (ULONG*)*src;
74 dst = (ULONG*)((IPTR)sss->stk_Upper - SP_OFFSET);
76 /* Rewind the dst pointer too. */
77 //dst += (src - sp);
79 /* Copy the two stack frames */
80 while (src != sp)
82 *--dst = *--src;
85 sss->stk_Pointer = dst;
87 retptr = &ret;
89 oldReturnAddr = proc->pr_ReturnAddr;
91 /* Compute argsize automatically */
92 if (argsize == -1)
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));
101 StackSwap(sss);
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
109 not work.
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)
121 StackSwap(sss);
123 D(bug("[sss] %08x %08x %08x\n", sss->stk_Lower, sss->stk_Pointer, sss->stk_Upper));
125 proc->pr_ReturnAddr = oldReturnAddr;
127 return ret;