update the freetype2 'demos' to 2.10.0 also.
[AROS.git] / arch / i386-all / exec / preparecontext.c
blobd15f36b02dff746529270f1a64052650286d9a56
1 /*
2 Copyright © 1995-2017, 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 <aros/i386/cpucontext.h>
16 #include "exec_intern.h"
17 #include "exec_util.h"
18 #if defined(__AROSEXEC_SMP__)
19 #include "etask.h"
20 #endif
22 #define _PUSH(sp, val) *--sp = (IPTR)val
24 BOOL PrepareContext(struct Task *task, APTR entryPoint, APTR fallBack,
25 const struct TagItem *tagList, struct ExecBase *SysBase)
27 IPTR args[8] = {0};
28 WORD numargs = 0;
29 IPTR *sp = task->tc_SPReg;
30 struct TagItem *t;
31 struct ExceptionContext *ctx;
33 if (!(task->tc_Flags & TF_ETASK) )
34 return FALSE;
36 ctx = KrnCreateContext();
37 task->tc_UnionETask.tc_ETask->et_RegFrame = ctx;
38 if (!ctx)
39 return FALSE;
41 while((t = LibNextTagItem((struct TagItem **)&tagList)))
43 switch(t->ti_Tag)
45 #if defined(__AROSEXEC_SMP__)
46 case TASKTAG_AFFINITY:
47 IntETask(task->tc_UnionETask.tc_ETask)->iet_CpuAffinity = t->ti_Data;
48 break;
49 #endif
51 #define HANDLEARG(x) \
52 case TASKTAG_ARG ## x: \
53 args[x - 1] = t->ti_Data; \
54 if (x > numargs) numargs = x; \
55 break;
57 HANDLEARG(1)
58 HANDLEARG(2)
59 HANDLEARG(3)
60 HANDLEARG(4)
61 HANDLEARG(5)
62 HANDLEARG(6)
63 HANDLEARG(7)
64 HANDLEARG(8)
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 kernel_cpu.h macros.
73 if (numargs)
75 /* On i386 C function gets all param on stack */
76 while(numargs--)
78 _PUSH(sp, args[numargs]);
82 /* First we push the return address */
83 _PUSH(sp, fallBack);
85 /* Then set up the frame to be used by Dispatch() */
86 ctx->ebp = 0;
87 ctx->eip = (IPTR)entryPoint;
88 ctx->esp = (IPTR)sp;
90 /* We return the new stack pointer back to the caller. */
91 task->tc_SPReg = sp;
93 return TRUE;
94 } /* PrepareContext() */