irq.c
Go to the documentation of this file.00001
00041 #include "irq.h"
00042
00043 #include <cfg/module.h>
00044 #include <kern/proc_p.h>
00045 #include <kern/proc.h>
00046
00047 #include "cfg/cfg_proc.h"
00048
00049 #include <unistd.h>
00050
00051
00052 MOD_DEFINE(irq)
00053
00054
00055 static void (*irq_handlers[100])(void);
00056
00057
00058 void irq_entry(int signum)
00059 {
00060 #if CONFIG_KERN_PREEMPT
00061 Process * const old_process = CurrentProcess;
00062 #endif
00063
00064 irq_handlers[signum]();
00065
00066 #if CONFIG_KERN_PREEMPT
00067 ASSERT2(CurrentProcess, "no idle proc?");
00068
00069 if (old_process != CurrentProcess)
00070 {
00071 IRQ_DISABLE;
00072
00073 TRACEMSG("switching from %p:%s to %p:%s",
00074 old_process, old_process ? old_process->monitor.name : "---",
00075 CurrentProcess, proc_currentName());
00076
00077 if (old_process)
00078 swapcontext(&old_process->context, &CurrentProcess->context);
00079 else
00080 setcontext(&CurrentProcess->context);
00081
00082 IRQ_ENABLE;
00083 }
00084 TRACEMSG("resuming %p:%s", CurrentProcess, CurrentProcess->monitor.name);
00085 #endif // CONFIG_KERN_PREEMPT
00086 }
00087
00088 void irq_register(int irq, void (*callback)(void))
00089 {
00090 irq_handlers[irq] = callback;
00091 }
00092
00093 void irq_init(void)
00094 {
00095 struct sigaction act;
00096
00097 act.sa_handler = irq_entry;
00098 sigemptyset(&act.sa_mask);
00099
00100 act.sa_flags = SA_RESTART;
00101
00102 sigaction(SIGUSR1, &act, NULL);
00103 sigaction(SIGALRM, &act, NULL);
00104
00105 MOD_INIT(irq);
00106 }