Minor fixes to comments.
[AROS.git] / rom / kernel / addirqhandler.c
blobdebbdad5b9e59d853fc07be03b1597a248b3d7a1
1 #include <aros/kernel.h>
2 #include <aros/libcall.h>
3 #include <proto/exec.h>
5 #include <kernel_base.h>
6 #include <kernel_cpu.h>
7 #include <kernel_debug.h>
8 #include <kernel_interrupts.h>
9 #include <kernel_objects.h>
11 /* We use own implementation of bug(), so we don't need aros/debug.h */
12 #define D(x)
14 /*****************************************************************************
16 NAME */
17 #include <proto/kernel.h>
19 AROS_LH4(void *, KrnAddIRQHandler,
21 /* SYNOPSIS */
22 AROS_LHA(uint8_t, irq, D0),
23 AROS_LHA(irqhandler_t *, handler, A0),
24 AROS_LHA(void *, handlerData, A1),
25 AROS_LHA(void *, handlerData2, A2),
27 /* LOCATION */
28 struct KernelBase *, KernelBase, 7, Kernel)
30 /* FUNCTION
31 Add a raw hardware IRQ handler to the chain of handlers.
33 INPUTS
34 num - hardware-specific IRQ number
35 handler - Pointer to a handler function
36 handlerData,
37 handlerData2 - User-defined data which is passed to the
38 handler.
40 Handler function uses a C calling convention and must be
41 declared as follows:
43 void IRQHandler(void *handlerData, void *handlerData2)
45 handlerData and handlerData2 will be values passed to the
46 KrnAddExceptionHandler() function.
48 There is no return code for the IRQ handler.
50 RESULT
51 An opaque handle that can be used for handler removal or NULL in case
52 of failure (like unsupported exception number).
54 NOTES
56 EXAMPLE
58 BUGS
60 SEE ALSO
61 KrnRemIRQHandler()
63 INTERNALS
65 ******************************************************************************/
67 AROS_LIBFUNC_INIT
69 struct IntrNode *handle = NULL;
71 D(bug("[KRN] KrnAddIRQHandler(%02x, %012p, %012p, %012p):\n", irq, handler, handlerData, handlerData2));
73 if (irq < IRQ_COUNT)
75 /* Go to supervisor mode */
76 (void)goSuper();
78 handle = krnAllocIntrNode();
79 D(bug("[KRN] handle=%012p\n", handle));
81 if (handle)
83 handle->in_Handler = handler;
84 handle->in_HandlerData = handlerData;
85 handle->in_HandlerData2 = handlerData2;
86 handle->in_type = it_interrupt;
87 handle->in_nr = irq;
89 Disable();
91 ADDHEAD(&KernelBase->kb_Interrupts[irq], &handle->in_Node);
93 ictl_enable_irq(irq, KernelBase);
95 Enable();
98 goUser();
101 return handle;
103 AROS_LIBFUNC_EXIT
106 /* Run IRQ handlers */
107 void krnRunIRQHandlers(struct KernelBase *KernelBase, uint8_t irq)
109 struct IntrNode *in, *in2;
111 ForeachNodeSafe(&KernelBase->kb_Interrupts[irq], in, in2)
113 irqhandler_t h = in->in_Handler;
115 h(in->in_HandlerData, in->in_HandlerData2);