2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
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>
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"
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();
30 extern uint64_t idle_time
;
32 __asm__
__volatile__("wrteei 0;");
35 while (!(task
= core_Dispatch())) {
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
)
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();
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");