Rev 1702 | Rev 1705 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | jermar | 1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1703 | jermar | 29 | /** @addtogroup ia32interrupt ia32 |
1702 | cejka | 30 | * @ingroup interrupt |
31 | * @{ |
||
32 | */ |
||
33 | /** @file |
||
34 | */ |
||
35 | |||
1 | jermar | 36 | #include <arch/interrupt.h> |
712 | decky | 37 | #include <syscall/syscall.h> |
1 | jermar | 38 | #include <print.h> |
68 | decky | 39 | #include <debug.h> |
1 | jermar | 40 | #include <panic.h> |
1477 | decky | 41 | #include <arch/drivers/i8259.h> |
1 | jermar | 42 | #include <func.h> |
43 | #include <cpu.h> |
||
44 | #include <arch/asm.h> |
||
5 | jermar | 45 | #include <mm/tlb.h> |
703 | jermar | 46 | #include <mm/as.h> |
22 | jermar | 47 | #include <arch.h> |
268 | palkovsky | 48 | #include <symtab.h> |
391 | jermar | 49 | #include <proc/thread.h> |
1256 | jermar | 50 | #include <proc/task.h> |
51 | #include <synch/spinlock.h> |
||
52 | #include <arch/ddi/ddi.h> |
||
1258 | palkovsky | 53 | #include <ipc/sysipc.h> |
54 | #include <interrupt.h> |
||
1 | jermar | 55 | |
56 | /* |
||
57 | * Interrupt and exception dispatching. |
||
58 | */ |
||
59 | |||
60 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
||
61 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
||
62 | void (* eoi_function)(void) = NULL; |
||
63 | |||
1411 | jermar | 64 | void PRINT_INFO_ERRCODE(istate_t *istate) |
1008 | jermar | 65 | { |
66 | char *symbol = get_symtab_entry(istate->eip); |
||
268 | palkovsky | 67 | |
1008 | jermar | 68 | if (!symbol) |
69 | symbol = ""; |
||
70 | |||
71 | if (CPU) |
||
72 | printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id); |
||
73 | else |
||
74 | printf("----------------EXCEPTION OCCURED----------------\n"); |
||
75 | |||
1221 | decky | 76 | printf("%%eip: %#x (%s)\n",istate->eip,symbol); |
77 | printf("ERROR_WORD=%#x\n", istate->error_word); |
||
78 | printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags); |
||
79 | printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n", istate->eax,istate->ecx,istate->edx,&istate->stack[0]); |
||
1100 | palkovsky | 80 | #ifdef CONFIG_DEBUG_ALLREGS |
1221 | decky | 81 | printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n", istate->esi,istate->edi,istate->ebp,istate->ebx); |
1100 | palkovsky | 82 | #endif |
1221 | decky | 83 | printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); |
84 | printf(" %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); |
||
1008 | jermar | 85 | } |
86 | |||
958 | jermar | 87 | void null_interrupt(int n, istate_t *istate) |
1 | jermar | 88 | { |
1595 | palkovsky | 89 | fault_if_from_uspace(istate, "unserviced interrupt: %d", n); |
90 | |||
958 | jermar | 91 | PRINT_INFO_ERRCODE(istate); |
92 | panic("unserviced interrupt: %d\n", n); |
||
1 | jermar | 93 | } |
94 | |||
1256 | jermar | 95 | /** General Protection Fault. */ |
958 | jermar | 96 | void gp_fault(int n, istate_t *istate) |
1 | jermar | 97 | { |
1256 | jermar | 98 | if (TASK) { |
99 | count_t ver; |
||
100 | |||
101 | spinlock_lock(&TASK->lock); |
||
102 | ver = TASK->arch.iomapver; |
||
103 | spinlock_unlock(&TASK->lock); |
||
104 | |||
105 | if (CPU->arch.iomapver_copy != ver) { |
||
106 | /* |
||
107 | * This fault can be caused by an early access |
||
108 | * to I/O port because of an out-dated |
||
109 | * I/O Permission bitmap installed on CPU. |
||
110 | * Install the fresh copy and restart |
||
111 | * the instruction. |
||
112 | */ |
||
113 | io_perm_bitmap_install(); |
||
114 | return; |
||
115 | } |
||
1595 | palkovsky | 116 | fault_if_from_uspace(istate, "general protection fault"); |
1256 | jermar | 117 | } |
118 | |||
958 | jermar | 119 | PRINT_INFO_ERRCODE(istate); |
168 | jermar | 120 | panic("general protection fault\n"); |
1 | jermar | 121 | } |
122 | |||
958 | jermar | 123 | void ss_fault(int n, istate_t *istate) |
84 | vana | 124 | { |
1595 | palkovsky | 125 | fault_if_from_uspace(istate, "stack fault"); |
126 | |||
958 | jermar | 127 | PRINT_INFO_ERRCODE(istate); |
103 | jermar | 128 | panic("stack fault\n"); |
84 | vana | 129 | } |
130 | |||
1019 | vana | 131 | void simd_fp_exception(int n, istate_t *istate) |
132 | { |
||
133 | __u32 mxcsr; |
||
134 | asm |
||
135 | ( |
||
136 | "stmxcsr %0;\n" |
||
137 | :"=m"(mxcsr) |
||
138 | ); |
||
1595 | palkovsky | 139 | fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zX", |
140 | (__native)mxcsr); |
||
141 | |||
142 | PRINT_INFO_ERRCODE(istate); |
||
1196 | cejka | 143 | printf("MXCSR: %#zX\n",(__native)(mxcsr)); |
1019 | vana | 144 | panic("SIMD FP exception(19)\n"); |
145 | } |
||
146 | |||
958 | jermar | 147 | void nm_fault(int n, istate_t *istate) |
73 | vana | 148 | { |
458 | decky | 149 | #ifdef CONFIG_FPU_LAZY |
309 | palkovsky | 150 | scheduler_fpu_lazy_request(); |
151 | #else |
||
1595 | palkovsky | 152 | fault_if_from_uspace(istate, "fpu fault"); |
309 | palkovsky | 153 | panic("fpu fault"); |
154 | #endif |
||
73 | vana | 155 | } |
156 | |||
958 | jermar | 157 | void syscall(int n, istate_t *istate) |
1 | jermar | 158 | { |
1100 | palkovsky | 159 | panic("Obsolete syscall handler."); |
1 | jermar | 160 | } |
161 | |||
958 | jermar | 162 | void tlb_shootdown_ipi(int n, istate_t *istate) |
5 | jermar | 163 | { |
164 | trap_virtual_eoi(); |
||
6 | jermar | 165 | tlb_shootdown_ipi_recv(); |
5 | jermar | 166 | } |
167 | |||
1 | jermar | 168 | void trap_virtual_enable_irqs(__u16 irqmask) |
169 | { |
||
170 | if (enable_irqs_function) |
||
171 | enable_irqs_function(irqmask); |
||
172 | else |
||
68 | decky | 173 | panic("no enable_irqs_function\n"); |
1 | jermar | 174 | } |
175 | |||
176 | void trap_virtual_disable_irqs(__u16 irqmask) |
||
177 | { |
||
178 | if (disable_irqs_function) |
||
179 | disable_irqs_function(irqmask); |
||
180 | else |
||
68 | decky | 181 | panic("no disable_irqs_function\n"); |
1 | jermar | 182 | } |
183 | |||
184 | void trap_virtual_eoi(void) |
||
185 | { |
||
186 | if (eoi_function) |
||
187 | eoi_function(); |
||
188 | else |
||
68 | decky | 189 | panic("no eoi_function\n"); |
1 | jermar | 190 | |
191 | } |
||
1258 | palkovsky | 192 | |
193 | static void ipc_int(int n, istate_t *istate) |
||
194 | { |
||
1690 | palkovsky | 195 | ipc_irq_send_notif(n-IVT_IRQBASE); |
1258 | palkovsky | 196 | trap_virtual_eoi(); |
197 | } |
||
198 | |||
199 | |||
200 | /* Reregister irq to be IPC-ready */ |
||
201 | void irq_ipc_bind_arch(__native irq) |
||
202 | { |
||
203 | if (irq == IRQ_CLK) |
||
204 | return; |
||
1690 | palkovsky | 205 | trap_virtual_enable_irqs(1 << irq); |
1258 | palkovsky | 206 | exc_register(IVT_IRQBASE+irq, "ipc_int", ipc_int); |
207 | } |
||
1702 | cejka | 208 | |
1703 | jermar | 209 | /** @} |
1702 | cejka | 210 | */ |
211 |