Fixes to comments and properties.
[AROS.git] / arch / i386-all / exec / preparecontext.c
blob303565b26ca4f2cf8d91ebdc53340c97aa68e49e
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: PrepareContext() - Prepare a task context for dispatch, i386 version
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 <proto/alib.h>
14 #include <proto/kernel.h>
15 #include <aros/i386/cpucontext.h>
17 #include "exec_intern.h"
18 #include "exec_util.h"
20 #define _PUSH(sp, val) *--sp = (IPTR)val
22 BOOL PrepareContext(struct Task *task, APTR entryPoint, APTR fallBack,
23 const struct TagItem *tagList, struct ExecBase *SysBase)
25 IPTR args[8] = {0};
26 WORD numargs = 0;
27 IPTR *sp = task->tc_SPReg;
28 struct TagItem *t;
29 struct ExceptionContext *ctx;
31 if (!(task->tc_Flags & TF_ETASK) )
32 return FALSE;
34 ctx = KrnCreateContext();
35 task->tc_UnionETask.tc_ETask->et_RegFrame = ctx;
36 if (!ctx)
37 return FALSE;
39 while((t = LibNextTagItem((struct TagItem **)&tagList)))
41 switch(t->ti_Tag)
44 #define HANDLEARG(x) \
45 case TASKTAG_ARG ## x: \
46 args[x - 1] = t->ti_Data; \
47 if (x > numargs) numargs = x; \
48 break;
50 HANDLEARG(1)
51 HANDLEARG(2)
52 HANDLEARG(3)
53 HANDLEARG(4)
54 HANDLEARG(5)
55 HANDLEARG(6)
56 HANDLEARG(7)
57 HANDLEARG(8)
62 There is not much to do here, or at least that is how it
63 appears. Most of the work is done in the kernel_cpu.h macros.
66 if (numargs)
68 /* On i386 C function gets all param on stack */
69 while(numargs--)
71 _PUSH(sp, args[numargs]);
75 /* First we push the return address */
76 _PUSH(sp, fallBack);
78 /* Then set up the frame to be used by Dispatch() */
79 ctx->ebp = 0;
80 ctx->eip = (IPTR)entryPoint;
81 ctx->esp = (IPTR)sp;
83 /* We return the new stack pointer back to the caller. */
84 task->tc_SPReg = sp;
86 return TRUE;
87 } /* PrepareContext() */