arch/m68k-amiga: KrnDispatch should disable CPU, not Paula, interrupts
[AROS.git] / arch / m68k-amiga / kernel / dispatch.c
blob3712f1e08bdf0396f1b5f1d42e85c63c57f903f3
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)
12 #define D(x) x
13 #else
14 #define D(x)
15 #endif
17 /*****************************************************************************
19 NAME */
20 #include <proto/kernel.h>
22 AROS_LH0(void, KrnDispatch,
24 /* SYNOPSIS */
26 /* LOCATION */
27 struct KernelBase *, KernelBase, 4, Kernel)
29 /* FUNCTION
31 INPUTS
33 RESULT
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
43 INTERNALS
45 ******************************************************************************/
47 AROS_LIBFUNC_INIT
49 struct Task *next;
51 for (;;) {
52 asm volatile ("move #0x2700, %sr\n"); // Disable CPU interrupts
53 next = (struct Task *)RemHead(&SysBase->TaskReady);
54 if (next != NULL)
55 break;
56 SysBase->IdleCount++;
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));
67 SysBase->DispCount++;
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)
76 KrnSti();
77 else
78 KrnCli();
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 */
90 Exception();
91 #if 0
92 /* Some MAGIC goes here, I guess, to get back to
93 * the user process?
95 #endif
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
101 * Supervisor mode.
103 asm volatile (
104 " move.l %0,%%usp\n"
105 " btst #0,%1\n" // Are we a 68010/68020?
106 " beq.s 0f\n" // Nope!
107 " move.w #0x0020,%%sp@-\n" // Yep!
108 "0:\n"
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
112 " rte\n"
114 : "a" (next->tc_SPReg),
115 "r" ((SysBase->AttnFlags & (AFB_68010 | AFB_68020)) ? 1 : 0)
116 : );
118 /* NOTE: We should never get here! */
119 D(bug("[KrnDispatch] Oh noes! Unpossible code executed!\n"));
121 AROS_LIBFUNC_EXIT