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