basic process support and some syscalls
[lunaix-os.git] / lunaix-os / kernel / asm / x86 / intr_routines.c
1 #include <arch/x86/interrupts.h>
2 #include <lunaix/tty/tty.h>
3 #include <lunaix/spike.h>
4 #include <lunaix/syslog.h>
5
6 #include <klibc/stdio.h>
7
8 #include <hal/apic.h>
9
10 LOG_MODULE("INTR")
11
12 extern void
13 intr_routine_page_fault (const isr_param* param);
14
15 void 
16 __print_panic_msg(const char* msg, const isr_param* param) 
17 {
18     kprint_panic("  INT %u: (%x) [%p: %p] %s",
19             param->vector,
20             param->err_code,
21             param->cs,
22             param->eip,
23             msg);
24 }
25
26 void
27 intr_routine_divide_zero (const isr_param* param) 
28 {
29     __print_panic_msg("Divide by zero!", param);
30     spin();
31 }
32
33 void
34 intr_routine_general_protection (const isr_param* param) 
35 {
36     __print_panic_msg("General Protection", param);
37     spin();
38 }
39
40 void
41 intr_routine_sys_panic (const isr_param* param) 
42 {
43     __print_panic_msg((char*)(param->registers.edi), param);
44     spin();
45 }
46
47 void
48 intr_routine_fallback (const isr_param* param) 
49 {
50     __print_panic_msg("Unknown Interrupt", param);
51     spin();
52 }
53
54 /**
55  * @brief ISR for Spurious interrupt
56  * 
57  * @param isr_param passed by CPU
58  */
59 void
60 intr_routine_apic_spi (const isr_param* param)
61 {
62     // FUTURE: do nothing for now
63 }
64
65 void 
66 intr_routine_apic_error (const isr_param* param)
67 {
68     uint32_t error_reg = apic_read_reg(APIC_ESR);
69     char buf[32];
70     sprintf(buf, "APIC error, ESR=0x%x", error_reg);
71     __print_panic_msg(buf, param);
72     spin();
73 }
74
75 void
76 intr_routine_init() 
77 {
78     intr_subscribe(FAULT_DIVISION_ERROR,     intr_routine_divide_zero);
79     intr_subscribe(FAULT_GENERAL_PROTECTION, intr_routine_general_protection);
80     intr_subscribe(FAULT_PAGE_FAULT,         intr_routine_page_fault);
81     intr_subscribe(LUNAIX_SYS_PANIC,         intr_routine_sys_panic);
82     intr_subscribe(APIC_SPIV_IV,             intr_routine_apic_spi);
83     intr_subscribe(APIC_ERROR_IV,            intr_routine_apic_error);
84
85     intr_set_fallback_handler(intr_set_fallback_handler);
86 }