Build fix, bring in bcopy.
[AROS.git] / arch / ppc-sam440 / kernel / kernel_cpu.c
blobf0ba07b7725b0e2251827d245f6209a417c34862
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <asm/amcc440.h>
7 #include <aros/kernel.h>
8 #include <aros/libcall.h>
9 #include <exec/execbase.h>
10 #include <hardware/intbits.h>
12 #include "etask.h"
14 #include "kernel_intern.h"
15 #include "kernel_cpu.h"
16 #include "kernel_syscall.h"
17 #include "kernel_scheduler.h"
18 #include "kernel_intr.h"
20 #include <strings.h>
23 * Task dispatcher. Basically it may be the same one no matter what scheduling algorithm is used
25 void cpu_Dispatch(context_t *regs)
27 struct ExecBase *SysBase = getSysBase();
28 struct Task *task;
29 uint64_t idle;
30 extern uint64_t idle_time;
32 __asm__ __volatile__("wrteei 0;");
33 idle = mftbu();
35 while (!(task = core_Dispatch())) {
36 /*
37 * Is the list of ready tasks empty? Well, increment the idle switch cound and halt CPU.
38 * It should be extended by some plugin mechanism which would put CPU and whole machine
39 * into some more sophisticated sleep states (ACPI?)
41 wrmsr(rdmsr() | MSR_POW | MSR_EE);
42 __asm__ __volatile__("sync; isync;");
43 __asm__ __volatile__("wrteei 0");
44 if (SysBase->SysFlags & SFF_SoftInt)
45 core_Cause(INTB_SOFTINT, 1l << INTB_SOFTINT);
46 idle_time += mftbu() - idle;
49 /* Handle tasks's flags */
50 if (task->tc_Flags & TF_EXCEPT)
51 Exception();
53 /* Store the launch time */
54 GetIntETask(task)->iet_private1 = mftbu();
56 if (task->tc_Flags & TF_LAUNCH)
58 AROS_UFC1(void, task->tc_Launch,
59 AROS_UFCA(struct ExecBase *, SysBase, A6));
62 /* Restore the task's state */
63 regs = task->tc_UnionETask.tc_ETask->et_RegFrame;
65 if (SysBase->IDNestCnt < 0)
66 regs->cpu.srr1 |= MSR_EE;
68 /* Copy the fpu, mmx, xmm state */
69 // FIXME: Change to the lazy saving of the FPU state!!!!
71 regs->cpu.srr1 &= ~MSR_POW;
74 void cpu_Switch(context_t *regs)
76 struct ExecBase *SysBase = getSysBase();
77 struct Task *task;
79 /* Disable interrupts for a while */
80 __asm__ __volatile__("wrteei 0");
82 task = SysBase->ThisTask;
84 /* Copy current task's context into the ETask structure */
85 bcopy(regs, task->tc_UnionETask.tc_ETask->et_RegFrame, sizeof(context_t));
87 /* Copy the fpu, mmx, xmm state */
88 // FIXME: Change to the lazy saving of the FPU state!!!!
90 task->tc_SPReg = (APTR)regs->cpu.gpr[1];
92 /* And enable interrupts */
93 __asm__ __volatile__("wrteei 1");
95 core_Switch();