use USER_CPPFLAGS
[AROS.git] / arch / m68k-all / exec / preparecontext.c
blob4df5abe1a0b23bba910dd64f582b5e5aeb1d67e7
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: PrepareContext() - Prepare a task context for dispatch, m68k version
6 Lang: english
7 */
9 #include <exec/execbase.h>
10 #include <exec/memory.h>
11 #include <utility/tagitem.h>
12 #include <aros/m68k/cpucontext.h>
13 #include <proto/kernel.h>
15 #include "exec_intern.h"
16 #include "exec_util.h"
18 #define _PUSH(sp, val) *--sp = (IPTR)val
20 BOOL PrepareContext(struct Task *task, APTR entryPoint, APTR fallBack,
21 const struct TagItem *tagList, struct ExecBase *SysBase)
23 IPTR args[8] = {0};
24 WORD numargs = 0;
25 IPTR *sp = task->tc_SPReg;
26 struct ExceptionContext *ctx;
28 if (!(task->tc_Flags & TF_ETASK))
29 return FALSE;
31 ctx = KrnCreateContext();
32 task->tc_UnionETask.tc_ETask->et_RegFrame = ctx;
33 if (!ctx)
34 return FALSE;
36 while(tagList)
38 switch(tagList->ti_Tag)
40 case TAG_MORE:
41 tagList = (const struct TagItem *)tagList->ti_Data;
42 continue;
44 case TAG_SKIP:
45 tagList += tagList->ti_Data;
46 break;
48 case TAG_DONE:
49 tagList = NULL;
50 break;
52 #define HANDLEARG(x) \
53 case TASKTAG_ARG ## x: \
54 args[x - 1] = (IPTR)tagList->ti_Data; \
55 if (x > numargs) numargs = x; \
56 break;
58 HANDLEARG(1)
59 HANDLEARG(2)
60 HANDLEARG(3)
61 HANDLEARG(4)
62 HANDLEARG(5)
63 HANDLEARG(6)
64 HANDLEARG(7)
65 HANDLEARG(8)
68 if (tagList) tagList++;
72 There is not much to do here, or at least that is how it
73 appears. Most of the work is done in the kernel_cpu.h macros.
76 if (numargs)
78 /* On m68k C function gets all param on stack */
79 while(numargs--)
81 _PUSH(sp, args[numargs]);
85 /* First we push the return address */
86 _PUSH(sp, fallBack);
88 /* Then set up the frame to be used by Dispatch() */
89 ctx->pc = (IPTR)entryPoint;
90 ctx->a[7] = (IPTR)sp;
91 ctx->sr = 0x0000;
93 /* We return the new stack pointer back to the caller. */
94 task->tc_SPReg = sp;
96 return TRUE;
97 } /* PrepareContext() */