1 #include <aros/kernel.h>
3 #include <exec/alerts.h>
4 #include <exec/execbase.h>
5 #include <proto/exec.h>
7 #include <kernel_base.h>
8 #include <kernel_syscall.h>
9 #include <kernel_debug.h>
11 #if defined(DEBUG) && (DEBUG == 1)
17 /*****************************************************************************
20 #include <proto/kernel.h>
22 AROS_LH0(void, KrnDispatch
,
27 struct KernelBase
*, KernelBase
, 4, Kernel
)
45 ******************************************************************************/
52 asm volatile ("move #0x2700, %sr\n"); // Disable CPU interrupts
53 next
= (struct Task
*)RemHead(&SysBase
->TaskReady
);
57 SysBase
->AttnFlags
|= ARF_AttnSwitch
;
58 D(bug("-- IDLE HALT --\n"));
59 asm volatile ("stop #0x2000\n"); // Wait for an interrupt
62 D(bug(" Dispatch (%s) Task=%p, SP=%p (0x%04x, %p), TDnc=%d, IDnc=%d\n",
63 next
->tc_Node
.ln_Name
, next
, next
->tc_SPReg
, *(UWORD
*)(next
->tc_SPReg
- 6),
64 *(ULONG
*)(next
->tc_SPReg
- 4),
65 next
->tc_TDNestCnt
,next
->tc_IDNestCnt
));
69 SysBase
->IDNestCnt
= next
->tc_IDNestCnt
;
70 SysBase
->ThisTask
= next
;
71 SysBase
->Elapsed
= SysBase
->Quantum
;
72 SysBase
->SysFlags
&= ~SFF_QuantumOver
;
73 next
->tc_State
= TS_RUN
;
75 if (SysBase
->IDNestCnt
< 0)
80 if (next
->tc_Flags
& TF_LAUNCH
) {
81 D(bug("%s:%d task->Launch called for %p\n", __func__
, __LINE__
, next
->tc_Launch
));
82 AROS_UFC0(void, next
->tc_Launch
);
85 if (next
->tc_Flags
& TF_EXCEPT
) {
86 D(bug("%s:%d task exception - what to do?\n"));
87 extern int breakpoint(void); breakpoint();
89 /* Call Exec/Exception to handle the exception */
92 /* Some MAGIC goes here, I guess, to get back to
98 /* Copy from the user stack to the supervisor stack,
99 * then 'rte' to the original frame, which should
100 * be in Switch(), which can only be called from
105 " btst #0,%1\n" // Are we a 68010/68020?
106 " beq.s 0f\n" // Nope!
107 " move.w #0x0020,%%sp@-\n" // Yep!
109 " move.l %0@(-(4)),%%sp@-\n" // Return PC
110 " move.w %0@(-(4+2)),%%sp@-\n" // %sr
111 " movem.l %0@(-(4+2+15*4)),%%d0-%%d7/%%a0-%%a6\n" // restore everything
114 : "a" (next
->tc_SPReg
),
115 "r" ((SysBase
->AttnFlags
& (AFB_68010
| AFB_68020
)) ? 1 : 0)
118 /* NOTE: We should never get here! */
119 D(bug("[KrnDispatch] Oh noes! Unpossible code executed!\n"));