Indentation fix, cleanup.
[AROS.git] / arch / arm-all / exec / preparecontext.c
blob93cf46832b3cdb29efc9121ef9feb7caa25f0d34
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: PrepareContext() - Prepare a task context for dispatch, ARM version.
6 Lang: english
7 */
9 #include <exec/execbase.h>
10 #include <exec/memory.h>
11 #include <utility/tagitem.h>
12 #include <proto/arossupport.h>
13 #include <proto/kernel.h>
14 #include <aros/arm/cpucontext.h>
16 #include "exec_intern.h"
17 #include "exec_util.h"
18 #if defined(__AROSEXEC_SMP__)
19 #include "etask.h"
20 #endif
22 BOOL PrepareContext(struct Task *task, APTR entryPoint, APTR fallBack,
23 const struct TagItem *tagList, struct ExecBase *SysBase)
25 struct TagItem *t;
26 struct ExceptionContext *ctx;
27 ULONG args[4] = {0};
28 int numargs = 0;
29 STACKULONG *sp = task->tc_SPReg;
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 /* Set up function arguments */
40 while((t = LibNextTagItem((struct TagItem **)&tagList)))
42 switch(t->ti_Tag)
44 #if defined(__AROSEXEC_SMP__)
45 case TASKTAG_AFFINITY:
46 IntETask(task->tc_UnionETask.tc_ETask)->iet_CpuAffinity = t->ti_Data;
47 break;
48 #endif
49 #define REGARG(x) \
50 case TASKTAG_ARG ## x: \
51 ctx->r[x - 1] = t->ti_Data; \
52 break;
54 #define STACKARG(x) \
55 case TASKTAG_ARG ## x: \
56 args[x - 5] = t->ti_Data; \
57 if (x - 4 > numargs) \
58 numargs = x - 4; \
59 break;
61 REGARG(1)
62 REGARG(2)
63 REGARG(3)
64 REGARG(4)
65 STACKARG(5)
66 STACKARG(6)
67 STACKARG(7)
68 STACKARG(8)
72 /* Last four arguments are put on stack */
73 while (numargs > 0)
74 *--sp = args[--numargs];
76 task->tc_SPReg = sp;
78 /* Now prepare return address */
79 ctx->r[11] = 0;
80 ctx->lr = (ULONG)fallBack;
82 ctx->Flags = 0;
84 /* Then set up the frame to be used by Dispatch() */
85 ctx->sp = (ULONG)task->tc_SPReg;
86 ctx->pc = (ULONG)entryPoint;
88 return TRUE;
89 } /* PrepareContext() */