added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / all-unix / exec / preparecontext.c
blob4fdd0a4a78bee790dec1416e1f145af90b4d68ea
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: i386unix version of PrepareContext().
6 Lang: english
7 */
9 #include <exec/types.h>
10 #include <exec/execbase.h>
11 #include <exec/memory.h>
12 #include <utility/tagitem.h>
13 #include <sigcore.h>
14 #include "etask.h"
15 #include "exec_util.h"
17 #include <aros/libcall.h>
19 AROS_LH4(BOOL, PrepareContext,
20 AROS_LHA(struct Task *, task, A0),
21 AROS_LHA(APTR, entryPoint, A1),
22 AROS_LHA(APTR, fallBack, A2),
23 AROS_LHA(struct TagItem *, tagList, A3),
24 struct ExecBase *, SysBase, 6, Exec)
26 AROS_LIBFUNC_INIT
28 IPTR args[8] = {0};
29 WORD numargs = 0;
31 while(tagList)
33 switch(tagList->ti_Tag)
35 case TAG_MORE:
36 tagList = (struct TagItem *)tagList->ti_Data;
37 continue;
39 case TAG_SKIP:
40 tagList += tagList->ti_Data;
41 break;
43 case TAG_DONE:
44 tagList = NULL;
45 break;
47 #define HANDLEARG(x) \
48 case TASKTAG_ARG ## x: \
49 args[x - 1] = (IPTR)tagList->ti_Data; \
50 if (x > numargs) numargs = x; \
51 break;
53 HANDLEARG(1)
54 HANDLEARG(2)
55 HANDLEARG(3)
56 HANDLEARG(4)
57 HANDLEARG(5)
58 HANDLEARG(6)
59 HANDLEARG(7)
60 HANDLEARG(8)
62 #undef HANDLEARG
65 if (tagList) tagList++;
69 There is not much to do here, or at least that is how it
70 appears. Most of the work is done in the sigcore.h macros.
73 if (!(task->tc_Flags & TF_ETASK) )
74 return FALSE;
76 GetIntETask (task)->iet_Context = AllocTaskMem (task
77 , SIZEOF_ALL_REGISTERS
78 , MEMF_PUBLIC|MEMF_CLEAR
81 if (!GetIntETask (task)->iet_Context)
82 return FALSE;
84 if (numargs)
86 #ifdef PREPARE_INITIAL_ARGS
88 PREPARE_INITIAL_ARGS(task, args, numargs);
90 #else
92 /* Assume C function gets all param on stack */
94 while(numargs--)
96 _PUSH(GetSP(task), args[numargs]);
99 #endif
102 #ifdef PREPARE_RETURN_ADDRESS
104 PREPARE_RETURN_ADDRESS(task, fallBack);
106 #else
108 /* First we push the return address */
109 _PUSH(GetSP(task), fallBack);
111 #endif
113 /* Then set up the frame to be used by Dispatch() */
114 PREPARE_INITIAL_FRAME(GetSP(task), entryPoint);
115 PREPARE_INITIAL_CONTEXT(task, entryPoint);
117 /* We return the new stack pointer back to the caller. */
118 return TRUE;
120 AROS_LIBFUNC_EXIT