ld-tool portability fix: MacOS build experience
[lunaix-os.git] / lunaix-os / arch / i386 / exceptions / interrupts.c
1 #include <sys/cpu.h>
2 #include <sys/i386_intr.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 void
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     ERROR("INT %u: (%x) [%p: %p] Unknown",
45             execp->vector,
46             execp->err_code,
47             execp->cs,
48             execp->eip);
49
50 done:
51
52     if (execp->vector > IV_BASE_END) {
53         isrm_notify_eoi(0, execp->vector);
54     }
55
56     return;
57 }