wip commit. add idle tasks for additional cpu's. cleanup some debug.
[AROS.git] / arch / arm-native / kernel / kernel_execsmp.c
bloba53ab39f84bd5b1aa5b9557ca8f6ad6bd3a76d16
1 /*
2 Copyright © 2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/kernel.h>
7 #include <proto/exec.h>
9 #include <stdio.h>
11 #include "etask.h"
12 #include "exec_intern.h"
14 #define D(x)
16 #if defined(__AROSEXEC_SMP__)
17 extern BOOL Exec_InitETask(struct Task *, struct ExecBase *);
19 struct Task *cpu_InitBootStrap(struct ExecBase *SysBase)
21 struct ExceptionContext *bsctx;
22 struct MemList *ml;
23 struct Task *bstask;
24 uint32_t tmp;
26 asm volatile (" mrc p15, 0, %0, c0, c0, 5 " : "=r" (tmp));
28 if ((bstask = AllocMem(sizeof(struct Task), MEMF_PUBLIC|MEMF_CLEAR)) == NULL)
30 bug("[KRN] CPU #%02d FATAL : Failed to allocate task for bootstrap", (tmp & 0x3));
31 return NULL;
34 if ((ml = AllocMem(sizeof(struct MemList), MEMF_PUBLIC|MEMF_CLEAR)) == NULL)
36 bug("[KRN] CPU #%02d FATAL : Failed to allocate memory for bootstrap task", (tmp & 0x3));
37 FreeMem(bstask, sizeof(struct Task));
38 return NULL;
41 D(bug("[KRN] CPU #%02d Bootstrap task @ 0x%p\n", (tmp & 0x3), bstask));
43 if ((bsctx = KrnCreateContext()) == NULL)
45 bug("[KRN] CPU %d FATAL : Failed to create the boostrap task context\n", (tmp & 0x3));
46 FreeMem(ml, sizeof(struct MemList));
47 FreeMem(bstask, sizeof(struct Task));
48 return NULL;
51 D(bug("[KRN] CPU #%02d cpu ctx @ 0x%p\n", (tmp & 0x3), bsctx));
53 NEWLIST(&bstask->tc_MemEntry);
55 if ((bstask->tc_Node.ln_Name = AllocVec(20, MEMF_CLEAR)) != NULL)
57 sprintf(bstask->tc_Node.ln_Name, "CPU #%02d Bootstrap", (tmp & 0x3));
59 bstask->tc_Node.ln_Type = NT_TASK;
60 bstask->tc_Node.ln_Pri = 0;
61 bstask->tc_State = TS_RUN;
62 bstask->tc_SigAlloc = 0xFFFF;
64 /* Build bootstraps memory list */
65 ml->ml_NumEntries = 1;
66 ml->ml_ME[0].me_Addr = bstask;
67 ml->ml_ME[0].me_Length = sizeof(struct Task);
68 AddHead(&bstask->tc_MemEntry, &ml->ml_Node);
70 /* Create a ETask structure and attach CPU context */
71 if (!Exec_InitETask(bstask, SysBase))
73 bug("[KRN] CPU %d FATAL : Failed to initialize boostrap etask\n", (tmp & 0x3));
74 FreeVec(bstask->tc_Node.ln_Name);
75 FreeMem(ml, sizeof(struct MemList));
76 FreeMem(bstask, sizeof(struct Task));
77 return NULL;
79 bstask->tc_UnionETask.tc_ETask->et_RegFrame = bsctx;
81 /* This Bootstrap task can run only on one of the available cores */
82 IntETask(bstask->tc_UnionETask.tc_ETask)->iet_CpuNumber = (tmp & 0x3);
83 IntETask(bstask->tc_UnionETask.tc_ETask)->iet_CpuAffinity = 1 << (tmp & 0x3);
85 return bstask;
88 void cpu_BootStrap(struct Task *bstask, struct ExecBase *SysBase)
90 SET_THIS_TASK(bstask);
92 #endif