2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #include <aros/atomic.h>
7 #include <exec/execbase.h>
8 #include <hardware/intbits.h>
9 #include <proto/exec.h>
11 #include <kernel_base.h>
12 #include <kernel_interrupts.h>
13 #include <kernel_intr.h>
14 #include <kernel_globals.h>
15 #include <kernel_scheduler.h>
16 #include <kernel_syscall.h>
17 #include "kernel_intern.h"
18 #include "kernel_unix.h"
21 * Leave the interrupt. This function receives the interrupt register frame
22 * and runs task scheduler if needed.
24 * You should call it only if you're returning to user mode (i.e. not from
25 * within nested interrupt).
27 * It relies on CPU-specific cpu_Switch() and cpu_Dispatch() implementations
28 * which save and restore CPU context. cpu_Dispatch() is allowed just to
29 * jump to the saved context and not return here.
31 void core_ExitInterrupt(regs_t
*regs
)
33 /* Soft interrupt requested? It's high time to do it */
34 if (SysBase
->SysFlags
& SFF_SoftInt
)
35 core_Cause(INTB_SOFTINT
, 1L << INTB_SOFTINT
);
37 /* If task switching is disabled, do nothing */
38 if (SysBase
->TDNestCnt
< 0)
41 * Do not disturb task if it's not necessary.
42 * Reschedule only if switch pending flag is set. Exit otherwise.
44 if (SysBase
->AttnResched
& ARF_AttnSwitch
)
46 /* Run task scheduling sequence */
57 * We do not have enough user-defined signals to map
58 * them to four required syscalls (CAUSE, SCHEDULE,
59 * SWITCH, DISPATCH). We get around this by assigning
60 * CAUSE to SIGUSR2 and others to SIGUSR1.
62 * What action is to be taken upon SIGUSR1 can be
63 * figured out by looking at caller task's state.
64 * exec.library calls KrnDispatch() only after task
65 * has been actually disposed, with state set to TS_REMOVED.
66 * Similarly, KrnSwitch() is called only in Wait(), after
67 * setting state to TS_WAIT. In other cases it's KrnSchedule().
69 void core_SysCall(int sig
, regs_t
*regs
)
71 struct KernelBase
*KernelBase
= getKernelBase();
72 struct Task
*task
= SysBase
->ThisTask
;
76 krnRunIRQHandlers(KernelBase
, sig
);
78 switch(task
->tc_State
)
80 /* A running task needs to be put into TaskReady list first. It's SC_SCHEDULE. */
85 /* If the task is already in some list with appropriate state, it's SC_SWITCH */
90 /* If the task is removed, it's simply SC_DISPATCH */
95 /* Special state is used for returning from exception */
97 cpu_DispatchContext(task
, regs
, KernelBase
->kb_PlatformData
);