move msi-related functionality to generic isrm
[lunaix-os.git] / lunaix-os / arch / x86 / exceptions / interrupts.c
1 #include <asm/hart.h>
2 #include "asm/x86.h"
3
4 #include <lunaix/mm/vmm.h>
5 #include <lunaix/process.h>
6 #include <lunaix/sched.h>
7 #include <lunaix/syslog.h>
8
9 #include <asm/x86_isrm.h>
10
11 LOG_MODULE("INTR")
12
13 static inline void
14 update_thread_context(struct hart_state* state)
15 {
16     if (!current_thread) {
17         return;
18     }
19
20     struct hart_state* parent = current_thread->hstate;
21     hart_push_state(parent, state);
22     current_thread->hstate = state;
23
24     if (parent) {
25         state->depth = parent->depth + 1;
26     }
27 }
28
29 struct hart_state*
30 intr_handler(struct hart_state* state)
31 {
32     update_thread_context(state);
33
34     volatile struct exec_param* execp = state->execp;
35     if (execp->vector <= 255) {
36         isr_cb subscriber = isrm_get(execp->vector);
37         subscriber(state);
38         goto done;
39     }
40
41 done:
42
43     if (execp->vector > IV_BASE_END) {
44         isrm_notify_eoi(0, execp->vector);
45     }
46
47     return state;
48 }