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