1 | /*
|
---|
2 | * Copyright (c) 2005 Jakub Jermar
|
---|
3 | * Copyright (c) 2005 Jakub Vana
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup ia64interrupt
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <arch/interrupt.h>
|
---|
37 | #include <interrupt.h>
|
---|
38 | #include <ddi/irq.h>
|
---|
39 | #include <panic.h>
|
---|
40 | #include <print.h>
|
---|
41 | #include <debug.h>
|
---|
42 | #include <console/console.h>
|
---|
43 | #include <typedefs.h>
|
---|
44 | #include <arch/asm.h>
|
---|
45 | #include <arch/barrier.h>
|
---|
46 | #include <arch/register.h>
|
---|
47 | #include <arch.h>
|
---|
48 | #include <syscall/syscall.h>
|
---|
49 | #include <print.h>
|
---|
50 | #include <proc/scheduler.h>
|
---|
51 | #include <ipc/sysipc.h>
|
---|
52 | #include <ipc/irq.h>
|
---|
53 | #include <ipc/ipc.h>
|
---|
54 | #include <synch/spinlock.h>
|
---|
55 | #include <mm/tlb.h>
|
---|
56 | #include <symtab.h>
|
---|
57 | #include <putchar.h>
|
---|
58 |
|
---|
59 | #define VECTORS_64_BUNDLE 20
|
---|
60 | #define VECTORS_16_BUNDLE 48
|
---|
61 | #define VECTORS_16_BUNDLE_START 0x5000
|
---|
62 | #define VECTOR_MAX 0x7f00
|
---|
63 |
|
---|
64 | #define BUNDLE_SIZE 16
|
---|
65 |
|
---|
66 | static const char *vector_names_64_bundle[VECTORS_64_BUNDLE] = {
|
---|
67 | "VHPT Translation vector",
|
---|
68 | "Instruction TLB vector",
|
---|
69 | "Data TLB vector",
|
---|
70 | "Alternate Instruction TLB vector",
|
---|
71 | "Alternate Data TLB vector",
|
---|
72 | "Data Nested TLB vector",
|
---|
73 | "Instruction Key Miss vector",
|
---|
74 | "Data Key Miss vector",
|
---|
75 | "Dirty-Bit vector",
|
---|
76 | "Instruction Access-Bit vector",
|
---|
77 | "Data Access-Bit vector"
|
---|
78 | "Break Instruction vector",
|
---|
79 | "External Interrupt vector"
|
---|
80 | "Reserved",
|
---|
81 | "Reserved",
|
---|
82 | "Reserved",
|
---|
83 | "Reserved",
|
---|
84 | "Reserved",
|
---|
85 | "Reserved",
|
---|
86 | "Reserved"
|
---|
87 | };
|
---|
88 |
|
---|
89 | static const char *vector_names_16_bundle[VECTORS_16_BUNDLE] = {
|
---|
90 | "Page Not Present vector",
|
---|
91 | "Key Permission vector",
|
---|
92 | "Instruction Access rights vector",
|
---|
93 | "Data Access Rights vector",
|
---|
94 | "General Exception vector",
|
---|
95 | "Disabled FP-Register vector",
|
---|
96 | "NaT Consumption vector",
|
---|
97 | "Speculation vector",
|
---|
98 | "Reserved",
|
---|
99 | "Debug vector",
|
---|
100 | "Unaligned Reference vector",
|
---|
101 | "Unsupported Data Reference vector",
|
---|
102 | "Floating-point Fault vector",
|
---|
103 | "Floating-point Trap vector",
|
---|
104 | "Lower-Privilege Transfer Trap vector",
|
---|
105 | "Taken Branch Trap vector",
|
---|
106 | "Single Step Trap vector",
|
---|
107 | "Reserved",
|
---|
108 | "Reserved",
|
---|
109 | "Reserved",
|
---|
110 | "Reserved",
|
---|
111 | "Reserved",
|
---|
112 | "Reserved",
|
---|
113 | "Reserved",
|
---|
114 | "Reserved",
|
---|
115 | "IA-32 Exception vector",
|
---|
116 | "IA-32 Intercept vector",
|
---|
117 | "IA-32 Interrupt vector",
|
---|
118 | "Reserved",
|
---|
119 | "Reserved",
|
---|
120 | "Reserved"
|
---|
121 | };
|
---|
122 |
|
---|
123 | static const char *vector_to_string(uint16_t vector)
|
---|
124 | {
|
---|
125 | ASSERT(vector <= VECTOR_MAX);
|
---|
126 |
|
---|
127 | if (vector >= VECTORS_16_BUNDLE_START)
|
---|
128 | return vector_names_16_bundle[(vector -
|
---|
129 | VECTORS_16_BUNDLE_START) / (16 * BUNDLE_SIZE)];
|
---|
130 | else
|
---|
131 | return vector_names_64_bundle[vector / (64 * BUNDLE_SIZE)];
|
---|
132 | }
|
---|
133 |
|
---|
134 | static void dump_interrupted_context(istate_t *istate)
|
---|
135 | {
|
---|
136 | const char *ifa = symtab_fmt_name_lookup(istate->cr_ifa);
|
---|
137 | const char *iipa = symtab_fmt_name_lookup(istate->cr_iipa);
|
---|
138 | const char *iip = symtab_fmt_name_lookup(istate->cr_iip);
|
---|
139 |
|
---|
140 | putchar('\n');
|
---|
141 | printf("Interrupted context dump:\n");
|
---|
142 | printf("ar.bsp=%p\tar.bspstore=%p\n", istate->ar_bsp,
|
---|
143 | istate->ar_bspstore);
|
---|
144 | printf("ar.rnat=%#018llx\tar.rsc=%#018llx\n", istate->ar_rnat,
|
---|
145 | istate->ar_rsc);
|
---|
146 | printf("ar.ifs=%#018llx\tar.pfs=%#018llx\n", istate->ar_ifs,
|
---|
147 | istate->ar_pfs);
|
---|
148 | printf("cr.isr=%#018llx\tcr.ipsr=%#018llx\t\n", istate->cr_isr.value,
|
---|
149 | istate->cr_ipsr);
|
---|
150 |
|
---|
151 | printf("cr.iip=%#018llx, #%d\t(%s)\n", istate->cr_iip,
|
---|
152 | istate->cr_isr.ei, iip);
|
---|
153 | printf("cr.iipa=%#018llx\t(%s)\n", istate->cr_iipa, iipa);
|
---|
154 | printf("cr.ifa=%#018llx\t(%s)\n", istate->cr_ifa, ifa);
|
---|
155 | }
|
---|
156 |
|
---|
157 | void general_exception(uint64_t vector, istate_t *istate)
|
---|
158 | {
|
---|
159 | const char *desc;
|
---|
160 |
|
---|
161 | switch (istate->cr_isr.ge_code) {
|
---|
162 | case GE_ILLEGALOP:
|
---|
163 | desc = "Illegal Operation fault";
|
---|
164 | break;
|
---|
165 | case GE_PRIVOP:
|
---|
166 | desc = "Privileged Operation fault";
|
---|
167 | break;
|
---|
168 | case GE_PRIVREG:
|
---|
169 | desc = "Privileged Register fault";
|
---|
170 | break;
|
---|
171 | case GE_RESREGFLD:
|
---|
172 | desc = "Reserved Register/Field fault";
|
---|
173 | break;
|
---|
174 | case GE_DISBLDISTRAN:
|
---|
175 | desc = "Disabled Instruction Set Transition fault";
|
---|
176 | break;
|
---|
177 | case GE_ILLEGALDEP:
|
---|
178 | desc = "Illegal Dependency fault";
|
---|
179 | break;
|
---|
180 | default:
|
---|
181 | desc = "unknown";
|
---|
182 | break;
|
---|
183 | }
|
---|
184 |
|
---|
185 | fault_if_from_uspace(istate, "General Exception (%s).", desc);
|
---|
186 |
|
---|
187 | dump_interrupted_context(istate);
|
---|
188 | panic("General Exception (%s).", desc);
|
---|
189 | }
|
---|
190 |
|
---|
191 | void disabled_fp_register(uint64_t vector, istate_t *istate)
|
---|
192 | {
|
---|
193 | #ifdef CONFIG_FPU_LAZY
|
---|
194 | scheduler_fpu_lazy_request();
|
---|
195 | #else
|
---|
196 | fault_if_from_uspace(istate, "Interruption: %#hx (%s).",
|
---|
197 | (uint16_t) vector, vector_to_string(vector));
|
---|
198 | dump_interrupted_context(istate);
|
---|
199 | panic("Interruption: %#hx (%s).", (uint16_t) vector,
|
---|
200 | vector_to_string(vector));
|
---|
201 | #endif
|
---|
202 | }
|
---|
203 |
|
---|
204 | void nop_handler(uint64_t vector, istate_t *istate)
|
---|
205 | {
|
---|
206 | }
|
---|
207 |
|
---|
208 | /** Handle syscall. */
|
---|
209 | int break_instruction(uint64_t vector, istate_t *istate)
|
---|
210 | {
|
---|
211 | /*
|
---|
212 | * Move to next instruction after BREAK.
|
---|
213 | */
|
---|
214 | if (istate->cr_ipsr.ri == 2) {
|
---|
215 | istate->cr_ipsr.ri = 0;
|
---|
216 | istate->cr_iip += 16;
|
---|
217 | } else {
|
---|
218 | istate->cr_ipsr.ri++;
|
---|
219 | }
|
---|
220 |
|
---|
221 | return syscall_handler(istate->in0, istate->in1, istate->in2,
|
---|
222 | istate->in3, istate->in4, istate->in5, istate->in6);
|
---|
223 | }
|
---|
224 |
|
---|
225 | void universal_handler(uint64_t vector, istate_t *istate)
|
---|
226 | {
|
---|
227 | fault_if_from_uspace(istate, "Interruption: %#hx (%s).",
|
---|
228 | (uint16_t) vector, vector_to_string(vector));
|
---|
229 | dump_interrupted_context(istate);
|
---|
230 | panic("Interruption: %#hx (%s).", (uint16_t) vector,
|
---|
231 | vector_to_string(vector));
|
---|
232 | }
|
---|
233 |
|
---|
234 | static void end_of_local_irq(void)
|
---|
235 | {
|
---|
236 | asm volatile ("mov cr.eoi=r0;;");
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | void external_interrupt(uint64_t vector, istate_t *istate)
|
---|
241 | {
|
---|
242 | cr_ivr_t ivr;
|
---|
243 | irq_t *irq;
|
---|
244 |
|
---|
245 | ivr.value = ivr_read();
|
---|
246 | srlz_d();
|
---|
247 |
|
---|
248 | switch (ivr.vector) {
|
---|
249 | case INTERRUPT_SPURIOUS:
|
---|
250 | #ifdef CONFIG_DEBUG
|
---|
251 | printf("cpu%d: spurious interrupt\n", CPU->id);
|
---|
252 | #endif
|
---|
253 | break;
|
---|
254 |
|
---|
255 | #ifdef CONFIG_SMP
|
---|
256 | case VECTOR_TLB_SHOOTDOWN_IPI:
|
---|
257 | tlb_shootdown_ipi_recv();
|
---|
258 | end_of_local_irq();
|
---|
259 | break;
|
---|
260 | #endif
|
---|
261 |
|
---|
262 | case INTERRUPT_TIMER:
|
---|
263 | irq = irq_dispatch_and_lock(ivr.vector);
|
---|
264 | if (irq) {
|
---|
265 | irq->handler(irq);
|
---|
266 | spinlock_unlock(&irq->lock);
|
---|
267 | } else {
|
---|
268 | panic("Unhandled Internal Timer Interrupt (%d).",
|
---|
269 | ivr.vector);
|
---|
270 | }
|
---|
271 | break;
|
---|
272 | default:
|
---|
273 | irq = irq_dispatch_and_lock(ivr.vector);
|
---|
274 | if (irq) {
|
---|
275 | /*
|
---|
276 | * The IRQ handler was found.
|
---|
277 | */
|
---|
278 | if (irq->preack) {
|
---|
279 | /* Send EOI before processing the interrupt */
|
---|
280 | end_of_local_irq();
|
---|
281 | }
|
---|
282 | irq->handler(irq);
|
---|
283 | if (!irq->preack)
|
---|
284 | end_of_local_irq();
|
---|
285 | spinlock_unlock(&irq->lock);
|
---|
286 | } else {
|
---|
287 | /*
|
---|
288 | * Unhandled interrupt.
|
---|
289 | */
|
---|
290 | end_of_local_irq();
|
---|
291 | #ifdef CONFIG_DEBUG
|
---|
292 | printf("\nUnhandled External Interrupt Vector %d\n",
|
---|
293 | ivr.vector);
|
---|
294 | #endif
|
---|
295 | }
|
---|
296 | break;
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | void trap_virtual_enable_irqs(uint16_t irqmask)
|
---|
301 | {
|
---|
302 | }
|
---|
303 |
|
---|
304 | /** @}
|
---|
305 | */
|
---|