Some fixes.
[cake.git] / rom / dos / addprocess.c
blob6df22f111225c0257ebaae427bed54895bbbd147
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Add a new Process
6 Lang: english
7 */
8 #include <dos/dosextens.h>
9 #include <utility/tagitem.h>
10 #include <proto/exec.h>
11 #include <aros/asmcall.h>
12 #include "dos_intern.h"
14 LONG DosEntry (
15 STRPTR argPtr,
16 ULONG argSize,
17 APTR initialPC,
18 struct ExecBase * SysBase)
20 LONG result = AROS_UFC3 (LONG, initialPC,
21 AROS_UFCA (STRPTR, argPtr, A0),
22 AROS_UFCA (ULONG, argSize, D0),
23 AROS_UFCA (struct ExecBase *, SysBase, A6));
25 /* Place the return code in the tc_Userdata field of the Task
26 structure, so that it can be used by pr_ExitCode-
28 tc_UserData is safe to use because at this point we are out of the process'
29 main code
31 FindTask(NULL)->tc_UserData = (APTR)result;
33 return result;
36 struct Process *AddProcess(struct Process *process, STRPTR argPtr,
37 ULONG argSize, APTR initialPC, APTR finalPC,
38 struct DosLibrary *DOSBase)
40 #if 1
41 struct TagItem tags[] =
43 {TASKTAG_ARG1, (IPTR)argPtr },
44 {TASKTAG_ARG2, (IPTR)argSize },
45 {TASKTAG_ARG3, (IPTR)initialPC },
46 {TASKTAG_ARG4, (IPTR)SysBase },
47 {TAG_DONE }
50 #if AROS_STACK_GROWS_DOWNWARDS
51 process->pr_Task.tc_SPReg = (STRPTR)process->pr_Task.tc_SPUpper - SP_OFFSET;
52 #else
53 process->pr_Task.tc_SPReg = (STRPTR)process->pr_Task.tc_SPLower + SP_OFFSET;
54 #endif
56 process->pr_ReturnAddr = (APTR *)process->pr_Task.tc_SPReg - 4; /* ???? */
57 process->pr_Task.tc_Flags |= TF_ETASK;
59 addprocesstoroot(process, DOSBase);
61 return (struct Process *)NewAddTask(&process->pr_Task, (APTR)DosEntry,
62 finalPC, tags);
64 #else
65 APTR *sp = process->pr_Task.tc_SPUpper;
67 *--sp = SysBase;
68 *--sp = initialPC;
69 *--sp = (APTR)argSize;
70 *--sp = argPtr;
72 process->pr_ReturnAddr = sp - 4;
74 process->pr_Task.tc_SPReg = (STRPTR)sp - SP_OFFSET;
75 process->pr_Task.tc_Flags |= TF_ETASK;
77 addprocesstoroot(process, DOSBase);
79 return (struct Process *)AddTask(&process->pr_Task, (APTR)DosEntry,
80 finalPC);
82 #endif
84 } /* AddProcess */