source: mainline/kernel/arch/ia32/src/interrupt.c@ 22a28a69

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 22a28a69 was 22a28a69, checked in by Jakub Jermar <jakub@…>, 15 years ago

Rename decode_istate() to istate_decode() and declare it only once in
the generic interrupt.h.

  • Property mode set to 100644
File size: 6.2 KB
Line 
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
29/** @addtogroup ia32interrupt
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/interrupt.h>
36#include <syscall/syscall.h>
37#include <print.h>
38#include <debug.h>
39#include <panic.h>
40#include <arch/drivers/i8259.h>
41#include <func.h>
42#include <cpu.h>
43#include <arch/asm.h>
44#include <mm/tlb.h>
45#include <mm/as.h>
46#include <arch.h>
47#include <proc/thread.h>
48#include <proc/task.h>
49#include <synch/spinlock.h>
50#include <arch/ddi/ddi.h>
51#include <ipc/sysipc.h>
52#include <interrupt.h>
53#include <ddi/irq.h>
54#include <symtab.h>
55#include <stacktrace.h>
56
57/*
58 * Interrupt and exception dispatching.
59 */
60
61void (* disable_irqs_function)(uint16_t irqmask) = NULL;
62void (* enable_irqs_function)(uint16_t irqmask) = NULL;
63void (* eoi_function)(void) = NULL;
64
65void istate_decode(istate_t *istate)
66{
67 printf("error_word=%#lx\n", istate->error_word);
68 printf("cs =%#0.8lx\teflags=%#0.8lx\n", istate->cs, istate->eflags);
69 printf("eax=%#0.8lx\tecx=%#0.8lx\tedx=%#0.8lx\n",
70 istate->eax, istate->ecx, istate->edx);
71}
72
73static void trap_virtual_eoi(void)
74{
75 if (eoi_function)
76 eoi_function();
77 else
78 panic("No eoi_function.");
79
80}
81
82static void null_interrupt(unsigned int n, istate_t *istate)
83{
84 fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n);
85 panic_badtrap(istate, n, "Unserviced interrupt: %u.", n);
86}
87
88static void de_fault(unsigned int n, istate_t *istate)
89{
90 fault_if_from_uspace(istate, "Divide error.");
91 panic_badtrap(istate, n, "Divide error.");
92}
93
94/** General Protection Fault. */
95static void gp_fault(unsigned int n __attribute__((unused)), istate_t *istate)
96{
97 if (TASK) {
98 irq_spinlock_lock(&TASK->lock, false);
99 size_t ver = TASK->arch.iomapver;
100 irq_spinlock_unlock(&TASK->lock, false);
101
102 if (CPU->arch.iomapver_copy != ver) {
103 /*
104 * This fault can be caused by an early access
105 * to I/O port because of an out-dated
106 * I/O Permission bitmap installed on CPU.
107 * Install the fresh copy and restart
108 * the instruction.
109 */
110 io_perm_bitmap_install();
111 return;
112 }
113 fault_if_from_uspace(istate, "General protection fault.");
114 }
115 panic_badtrap(istate, n, "General protection fault.");
116}
117
118static void ss_fault(unsigned int n __attribute__((unused)), istate_t *istate)
119{
120 fault_if_from_uspace(istate, "Stack fault.");
121 panic_badtrap(istate, n, "Stack fault.");
122}
123
124static void simd_fp_exception(unsigned int n __attribute__((unused)), istate_t *istate)
125{
126 uint32_t mxcsr;
127 asm volatile (
128 "stmxcsr %[mxcsr]\n"
129 : [mxcsr] "=m" (mxcsr)
130 );
131
132 fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR=%#0.8x.",
133 (unative_t) mxcsr);
134 panic_badtrap(istate, n, "SIMD FP exception, MXCSR=%#0.8x");
135}
136
137static void nm_fault(unsigned int n __attribute__((unused)),
138 istate_t *istate __attribute__((unused)))
139{
140#ifdef CONFIG_FPU_LAZY
141 scheduler_fpu_lazy_request();
142#else
143 fault_if_from_uspace(istate, "FPU fault.");
144 panic_badtrap(istate, n, "FPU fault.");
145#endif
146}
147
148#ifdef CONFIG_SMP
149static void tlb_shootdown_ipi(unsigned int n __attribute__((unused)),
150 istate_t *istate __attribute__((unused)))
151{
152 trap_virtual_eoi();
153 tlb_shootdown_ipi_recv();
154}
155#endif
156
157/** Handler of IRQ exceptions */
158static void irq_interrupt(unsigned int n, istate_t *istate __attribute__((unused)))
159{
160 ASSERT(n >= IVT_IRQBASE);
161
162 unsigned int inum = n - IVT_IRQBASE;
163 bool ack = false;
164 ASSERT(inum < IRQ_COUNT);
165 ASSERT((inum != IRQ_PIC_SPUR) && (inum != IRQ_PIC1));
166
167 irq_t *irq = irq_dispatch_and_lock(inum);
168 if (irq) {
169 /*
170 * The IRQ handler was found.
171 */
172
173 if (irq->preack) {
174 /* Send EOI before processing the interrupt */
175 trap_virtual_eoi();
176 ack = true;
177 }
178 irq->handler(irq);
179 irq_spinlock_unlock(&irq->lock, false);
180 } else {
181 /*
182 * Spurious interrupt.
183 */
184#ifdef CONFIG_DEBUG
185 printf("cpu%u: spurious interrupt (inum=%u)\n", CPU->id, inum);
186#endif
187 }
188
189 if (!ack)
190 trap_virtual_eoi();
191}
192
193void interrupt_init(void)
194{
195 unsigned int i;
196
197 for (i = 0; i < IVT_ITEMS; i++)
198 exc_register(i, "null", false, (iroutine_t) null_interrupt);
199
200 for (i = 0; i < IRQ_COUNT; i++) {
201 if ((i != IRQ_PIC_SPUR) && (i != IRQ_PIC1))
202 exc_register(IVT_IRQBASE + i, "irq", true,
203 (iroutine_t) irq_interrupt);
204 }
205
206 exc_register(0, "de_fault", true, (iroutine_t) de_fault);
207 exc_register(7, "nm_fault", true, (iroutine_t) nm_fault);
208 exc_register(12, "ss_fault", true, (iroutine_t) ss_fault);
209 exc_register(13, "gp_fault", true, (iroutine_t) gp_fault);
210 exc_register(19, "simd_fp", true, (iroutine_t) simd_fp_exception);
211
212#ifdef CONFIG_SMP
213 exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", true,
214 (iroutine_t) tlb_shootdown_ipi);
215#endif
216}
217
218void trap_virtual_enable_irqs(uint16_t irqmask)
219{
220 if (enable_irqs_function)
221 enable_irqs_function(irqmask);
222 else
223 panic("No enable_irqs_function.");
224}
225
226void trap_virtual_disable_irqs(uint16_t irqmask)
227{
228 if (disable_irqs_function)
229 disable_irqs_function(irqmask);
230 else
231 panic("No disable_irqs_function.");
232}
233
234/** @}
235 */
Note: See TracBrowser for help on using the repository browser.