My Kernel v0.1.0
interrupts.h
Go to the documentation of this file.
1
21#ifndef KERNEL_INTERRUPTS_H
22#define KERNEL_INTERRUPTS_H
23
24#if ARCH == i686
26#endif
27
28#include <kernel/types.h>
29
36
38typedef u32 (*interrupt_handler)(void *);
39
49void interrupts_set_handler(u8 irq, interrupt_handler, void *);
50
60
62static inline bool interrupts_has_been_installed(u8 irq)
63{
64 return interrupts_get_handler(irq, NULL) != NULL;
65}
66
68const char *interrupts_to_str(u8 nr);
69
71#define INTERRUPT_HANDLER(_interrupt) _interrupt##_handler
72
77#define INTERRUPT_HANDLER_FUNCTION(_interrupt) \
78 u32 INTERRUPT_HANDLER(_interrupt)(void *data)
79
81static inline void interrupts_disable(void)
82{
83 arch_interrupts_disable();
84}
85
87static inline void interrupts_enable(void)
88{
89 arch_interrupts_enable();
90}
91
92/* @brief Disable CPU interrupts on the current CPU.
93 * @return \c true if the interrupts where enabled previously.
94 */
95static inline bool interrupts_test_and_disable(void)
96{
97 return arch_interrupts_test_and_disable();
98}
99
104static inline void interrupts_restore(bool enabled)
105{
106 if (enabled)
108}
109
110typedef struct {
111 bool enabled;
112 bool done;
113} scope_irq_off_t;
114
115static inline scope_irq_off_t scope_irq_off_constructor(void)
116{
117 return (scope_irq_off_t){
118 .enabled = interrupts_test_and_disable(),
119 .done = false,
120 };
121}
122
123static inline void scope_irq_off_destructor(scope_irq_off_t *guard)
124{
125 interrupts_restore(guard->enabled);
126}
127
134#define interrupts_disabled_scope() \
135 for (scope_irq_off_t guard CLEANUP(scope_irq_off_destructor) = \
136 scope_irq_off_constructor(); \
137 !guard.done; guard.done = true)
138
141#endif /* KERNEL_INTERRUPTS_H */
x86 specific interrupt interface implementation
static void interrupts_enable(void)
Enable interrupts on the current CPU.
Definition: interrupts.h:87
u32(* interrupt_handler)(void *)
Function pointer to an interrupt handler.
Definition: interrupts.h:38
static void interrupts_disable(void)
Disable interrupts on the current CPU.
Definition: interrupts.h:81
static void interrupts_restore(bool enabled)
Restore the previous interrupt state.
Definition: interrupts.h:104
const char * interrupts_to_str(u8 nr)
Returns the name of an interrupt from its vector number.
Definition: interrupts.c:93
static bool interrupts_has_been_installed(u8 irq)
Return wether a custom interrupt has been installed for the given vector.
Definition: interrupts.h:62
void interrupts_set_handler(u8 irq, interrupt_handler, void *)
Dynamically set an interrupt handler.
Definition: interrupts.c:103
interrupt_handler interrupts_get_handler(u8 irq, void **)
Retreive the current handler for a given IRQ.
Definition: interrupts.c:111
u32 nr
Interrupt number (pushed by our stub)
Definition: interrupts.h:133
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:121