A Total Overhaul on the Lunaix's Virtual Memory Model (#26)
[lunaix-os.git] / lunaix-os / arch / i386 / exceptions / intr_routines.c
1 #include <sys/interrupts.h>
2
3 #include <lunaix/isrm.h>
4 #include <lunaix/process.h>
5 #include <lunaix/sched.h>
6 #include <lunaix/spike.h>
7 #include <lunaix/syslog.h>
8 #include <lunaix/trace.h>
9
10 #include <klibc/strfmt.h>
11
12 #include <sys/apic.h>
13 #include <sys/i386_intr.h>
14
15 LOG_MODULE("INTR")
16
17 extern void
18 intr_routine_page_fault(const isr_param* param);
19
20 extern u32_t debug_resv;
21
22 void
23 __print_panic_msg(const char* msg, const isr_param* param)
24 {
25     ERROR("panic: %s", msg);
26     trace_printstack_isr(param);
27 }
28
29 void
30 intr_routine_divide_zero(const isr_param* param)
31 {
32     __print_panic_msg("div zero", param);
33
34     spin();
35 }
36
37 void
38 intr_routine_general_protection(const isr_param* param)
39 {
40     __print_panic_msg("general protection", param);
41
42     spin();
43 }
44
45 void
46 intr_routine_sys_panic(const isr_param* param)
47 {
48     __print_panic_msg((char*)(param->registers.edi), param);
49
50     spin();
51 }
52
53 void
54 intr_routine_fallback(const isr_param* param)
55 {
56     __print_panic_msg("unknown interrupt", param);
57
58     spin();
59 }
60
61 /**
62  * @brief ISR for Spurious interrupt
63  *
64  * @param isr_param passed by CPU
65  */
66 void
67 intr_routine_apic_spi(const isr_param* param)
68 {
69     // FUTURE: do nothing for now
70 }
71
72 void
73 intr_routine_apic_error(const isr_param* param)
74 {
75     u32_t error_reg = apic_read_reg(APIC_ESR);
76     char buf[32];
77     ksprintf(buf, "APIC error, ESR=0x%x", error_reg);
78
79     __print_panic_msg(buf, param);
80
81     spin();
82 }
83
84 void
85 intr_routine_sched(const isr_param* param)
86 {
87     schedule();
88 }
89
90 void
91 intr_routine_init()
92 {
93     isrm_bindiv(FAULT_DIVISION_ERROR, intr_routine_divide_zero);
94     isrm_bindiv(FAULT_GENERAL_PROTECTION, intr_routine_general_protection);
95     isrm_bindiv(FAULT_PAGE_FAULT, intr_routine_page_fault);
96     isrm_bindiv(FAULT_STACK_SEG_FAULT, intr_routine_page_fault);
97
98     isrm_bindiv(LUNAIX_SYS_PANIC, intr_routine_sys_panic);
99     isrm_bindiv(LUNAIX_SCHED, intr_routine_sched);
100
101     isrm_bindiv(APIC_SPIV_IV, intr_routine_apic_spi);
102     isrm_bindiv(APIC_ERROR_IV, intr_routine_apic_error);
103 }