Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / ppc-chrp / exec / preparecontext.c
blob083ef845dec8f9f194d42b8c871ddecbb91c7978
1 #include <exec/types.h>
2 #include <exec/execbase.h>
3 #include <exec/memory.h>
4 #include <utility/tagitem.h>
5 #include <asm/mpc5200b.h>
6 #include <proto/kernel.h>
7 #include "etask.h"
8 #include "exec_util.h"
10 #define DEBUG 0
12 #include <aros/libcall.h>
13 #include <aros/debug.h>
15 #define Regs(t) ((struct regs_t *)(GetIntETask(t)->iet_Context))
17 extern void *priv_KernelBase;
19 static UQUAD *PrepareContext_Common(struct Task *task, APTR entryPoint, APTR fallBack,
20 struct TagItem *tagList, struct ExecBase *SysBase)
22 context_t *ctx;
23 int i;
24 IPTR *sp=(IPTR *)((IPTR)task->tc_SPReg & 0xfffffff0);
25 IPTR args[8] = {0};
26 WORD numargs = 0;
28 void *KernelBase = priv_KernelBase;
30 while(tagList)
32 switch(tagList->ti_Tag)
34 case TAG_MORE:
35 tagList = (struct TagItem *)tagList->ti_Data;
36 continue;
38 case TAG_SKIP:
39 tagList += tagList->ti_Data;
40 break;
42 case TAG_DONE:
43 tagList = NULL;
44 break;
46 #define HANDLEARG(x) \
47 case TASKTAG_ARG ## x: \
48 args[x - 1] = (IPTR)tagList->ti_Data; \
49 if (x > numargs) numargs = x; \
50 break;
52 HANDLEARG(1)
53 HANDLEARG(2)
54 HANDLEARG(3)
55 HANDLEARG(4)
56 HANDLEARG(5)
57 HANDLEARG(6)
58 HANDLEARG(7)
59 HANDLEARG(8)
61 #undef HANDLEARG
64 if (tagList) tagList++;
67 if (!(task->tc_Flags & TF_ETASK) )
68 return NULL;
70 /* Get the memory for CPU context. Alloc it with MEMF_CLEAR flag */
71 GetIntETask (task)->iet_Context = KrnCreateContext();
73 D(bug("[exec] PrepareContext: iet_Context = %012p\n", GetIntETask (task)->iet_Context));
75 if (!(ctx = (context_t *)GetIntETask (task)->iet_Context))
76 return NULL;
78 SuperState();
79 if (numargs)
81 switch (numargs)
83 case 8:
84 ctx->cpu.gpr[10] = args[7];
85 case 7:
86 ctx->cpu.gpr[9] = args[6];
87 case 6:
88 ctx->cpu.gpr[8] = args[5];
89 case 5:
90 ctx->cpu.gpr[7] = args[4];
91 case 4:
92 ctx->cpu.gpr[6] = args[3];
93 case 3:
94 ctx->cpu.gpr[5] = args[2];
95 case 2:
96 ctx->cpu.gpr[4] = args[1];
97 case 1:
98 ctx->cpu.gpr[3] = args[0];
99 break;
103 /* Push fallBack address */
104 ctx->cpu.lr = fallBack;
106 * Task will be started upon interrupt resume. Push entrypoint into SRR0
107 * and the MSR register into SRR1. Enable FPU at the beginning
109 ctx->cpu.srr0 = (IPTR)entryPoint;
110 ctx->cpu.srr1 = MSR_PR | MSR_EE | MSR_ME | MSR_IS | MSR_DS;
111 ctx->cpu.srr1 |= MSR_FP;
112 ctx->cpu.gpr[1] = sp;
114 task->tc_SPReg = sp;
116 sp[0] = 0;
117 sp[1] = 0;
119 D(bug("[exec] New context:\n[exec] SRR0=%08x, SRR1=%08x\n",ctx->cpu.srr0, ctx->cpu.srr1));
120 D(bug("[exec] GPR00=%08x GPR01=%08x GPR02=%08x GPR03=%08x\n",
121 ctx->cpu.gpr[0],ctx->cpu.gpr[1],ctx->cpu.gpr[2],ctx->cpu.gpr[3]));
122 D(bug("[exec] GPR04=%08x GPR05=%08x GPR06=%08x GPR07=%08x\n",
123 ctx->cpu.gpr[4],ctx->cpu.gpr[5],ctx->cpu.gpr[6],ctx->cpu.gpr[7]));
124 D(bug("[exec] GPR08=%08x GPR09=%08x GPR10=%08x GPR11=%08x\n",
125 ctx->cpu.gpr[8],ctx->cpu.gpr[9],ctx->cpu.gpr[10],ctx->cpu.gpr[11]));
126 D(bug("[exec] GPR12=%08x GPR13=%08x GPR14=%08x GPR15=%08x\n",
127 ctx->cpu.gpr[12],ctx->cpu.gpr[13],ctx->cpu.gpr[14],ctx->cpu.gpr[15]));
129 D(bug("[exec] GPR16=%08x GPR17=%08x GPR18=%08x GPR19=%08x\n",
130 ctx->cpu.gpr[16],ctx->cpu.gpr[17],ctx->cpu.gpr[18],ctx->cpu.gpr[19]));
131 D(bug("[exec] GPR20=%08x GPR21=%08x GPR22=%08x GPR23=%08x\n",
132 ctx->cpu.gpr[20],ctx->cpu.gpr[21],ctx->cpu.gpr[22],ctx->cpu.gpr[23]));
133 D(bug("[exec] GPR24=%08x GPR25=%08x GPR26=%08x GPR27=%08x\n",
134 ctx->cpu.gpr[24],ctx->cpu.gpr[25],ctx->cpu.gpr[26],ctx->cpu.gpr[27]));
135 D(bug("[exec] GPR28=%08x GPR29=%08x GPR30=%08x GPR31=%08x\n",
136 ctx->cpu.gpr[28],ctx->cpu.gpr[29],ctx->cpu.gpr[30],ctx->cpu.gpr[31]));
138 UserState(NULL);
140 return sp;
143 AROS_LH4(BOOL, PrepareContext,
144 AROS_LHA(struct Task *, task, A0),
145 AROS_LHA(APTR, entryPoint, A1),
146 AROS_LHA(APTR, fallBack, A2),
147 AROS_LHA(struct TagItem *, tagList, A3),
148 struct ExecBase *, SysBase, 6, Exec)
150 AROS_LIBFUNC_INIT
152 return PrepareContext_Common(task, entryPoint, fallBack, tagList, SysBase) ? TRUE : FALSE;
154 AROS_LIBFUNC_EXIT