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/error.h>
29#include <kernel/types.h>
30
31#include <libalgo/linked_list.h>
32
36typedef enum interrupt_return {
40
47
50
51struct interrupt_handler {
53 void *data;
54 node_t this; /* used by interrupt_vector->handlers */
55};
56
59 const char *name;
60 llist_t handlers;
61};
62
63struct interrupt_chip {
64 struct interrupt_vector *interrupts; /* Array of struct interrupt_vector */
65 size_t interrupt_count;
66};
67
74error_t
76
84error_t
85interrupts_install_static_handler(unsigned int nr, struct interrupt_handler *);
86
98interrupt_handler_func_t interrupts_get_handler(unsigned int irq, void **);
99
100error_t interrupt_handle(unsigned int nr);
101const char *interrupt_name(unsigned int nr);
102
104#define INTERRUPT_HANDLER(_interrupt) _interrupt##_handler
105
110#define INTERRUPT_HANDLER_FUNCTION(_interrupt) \
111 interrupt_return_t INTERRUPT_HANDLER(_interrupt)(void *data)
112
114static inline void interrupts_disable(void)
115{
116 arch_interrupts_disable();
117}
118
120static inline void interrupts_enable(void)
121{
122 arch_interrupts_enable();
123}
124
125/* @brief Disable CPU interrupts on the current CPU.
126 * @return \c true if the interrupts where enabled previously.
127 */
128static inline bool interrupts_test_and_disable(void)
129{
130 return arch_interrupts_test_and_disable();
131}
132
133static inline bool interrupts_enabled(void)
134{
135 return arch_interrupts_enabled();
136}
137
142static inline void interrupts_restore(bool enabled)
143{
144 if (enabled)
146}
147
148typedef struct {
149 bool enabled;
150 bool done;
151} scope_irq_off_t;
152
153static inline scope_irq_off_t scope_irq_off_constructor(void)
154{
155 return (scope_irq_off_t){
156 .enabled = interrupts_test_and_disable(),
157 .done = false,
158 };
159}
160
161static inline void scope_irq_off_destructor(scope_irq_off_t *guard)
162{
163 interrupts_restore(guard->enabled);
164}
165
172#define interrupts_disabled_scope() \
173 for (scope_irq_off_t guard CLEANUP(scope_irq_off_destructor) = \
174 scope_irq_off_constructor(); \
175 !guard.done; guard.done = true)
176
177
178/*
179 * Generic interrupt handlers.
180 */
181
182extern struct interrupt_handler division_by_zero;
183extern struct interrupt_handler invalid_instruction;
184
187#endif /* KERNEL_INTERRUPTS_H */
x86 specific interrupt interface implementation
error_t interrupts_install_static_handler(unsigned int nr, struct interrupt_handler *)
Install a pre-configured interrupt handler.
Definition: interrupts.c:122
interrupt_return
Values returned by an interrupt handler.
Definition: interrupts.h:36
error_t interrupts_install_handler(unsigned int irq, interrupt_handler_func_t, void *)
Dynamically set an interrupt handler.
Definition: interrupts.c:131
static void interrupts_enable(void)
Enable interrupts on the current CPU.
Definition: interrupts.h:120
enum interrupt_return interrupt_return_t
Values returned by an interrupt handler.
interrupt_handler_func_t interrupts_get_handler(unsigned int irq, void **)
Retreive the current handler for a given IRQ.
Definition: interrupts.c:153
static void interrupts_disable(void)
Disable interrupts on the current CPU.
Definition: interrupts.h:114
static void interrupts_restore(bool enabled)
Restore the previous interrupt state.
Definition: interrupts.h:142
interrupt_return_t(* interrupt_handler_func_t)(void *)
Function pointer to an interrupt handler.
Definition: interrupts.h:49
@ INTERRUPT_IGNORED
Definition: interrupts.h:38
@ INTERRUPT_HANDLED
Definition: interrupts.h:37
Frame passed onto the interrupt handlers by our stub handler.
Definition: interrupts.h:118
A single hardware IRQ vector.
Definition: interrupts.h:58
The head of a doubly linked list.
Definition: linked_list.h:43
Intrusive doubly-linked list node.
Definition: linked_list.h:27