source: mainline/kernel/arch/amd64/src/interrupt.c@ f1380b7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1380b7 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 6.7 KB
RevLine 
[db3341e]1/*
[df4ed85]2 * Copyright (c) 2001-2004 Jakub Jermar
[db3341e]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
[06e1e95]29/** @addtogroup amd64interrupt
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[db3341e]35#include <arch/interrupt.h>
[63e27ef]36#include <assert.h>
[db3341e]37#include <print.h>
[b2fa1204]38#include <log.h>
[db3341e]39#include <panic.h>
[80d31883]40#include <arch/drivers/i8259.h>
[b2e121a]41#include <halt.h>
[db3341e]42#include <cpu.h>
43#include <arch/asm.h>
44#include <mm/tlb.h>
[20d50a1]45#include <mm/as.h>
[db3341e]46#include <arch.h>
[b49f4ae]47#include <proc/scheduler.h>
[1084a784]48#include <proc/thread.h>
[2382d09]49#include <proc/task.h>
50#include <synch/spinlock.h>
51#include <arch/ddi/ddi.h>
[5626277]52#include <interrupt.h>
[8607db8]53#include <ddi/irq.h>
[e2b762ec]54#include <symtab.h>
[304342e]55#include <stacktrace.h>
[2ee1ccc]56#include <smp/smp_call.h>
[e2b762ec]57
[8607db8]58/*
59 * Interrupt and exception dispatching.
60 */
61
62void (* disable_irqs_function)(uint16_t irqmask) = NULL;
63void (* enable_irqs_function)(uint16_t irqmask) = NULL;
64void (* eoi_function)(void) = NULL;
[acc7ce4]65const char *irqs_info = NULL;
[8607db8]66
[22a28a69]67void istate_decode(istate_t *istate)
[8ec9bae]68{
[b2fa1204]69 log_printf("cs =%0#18" PRIx64 "\trip=%0#18" PRIx64 "\t"
[2438fa6]70 "rfl=%0#18" PRIx64 "\terr=%0#18" PRIx64 "\n",
71 istate->cs, istate->rip, istate->rflags, istate->error_word);
[a35b458]72
[9171f12]73 if (istate_from_uspace(istate))
[b2fa1204]74 log_printf("ss =%0#18" PRIx64 "\n", istate->ss);
[a35b458]75
[b2fa1204]76 log_printf("rax=%0#18" PRIx64 "\trbx=%0#18" PRIx64 "\t"
[2438fa6]77 "rcx=%0#18" PRIx64 "\trdx=%0#18" PRIx64 "\n",
[9171f12]78 istate->rax, istate->rbx, istate->rcx, istate->rdx);
[a35b458]79
[b2fa1204]80 log_printf("rsi=%0#18" PRIx64 "\trdi=%0#18" PRIx64 "\t"
[2438fa6]81 "rbp=%0#18" PRIx64 "\trsp=%0#18" PRIx64 "\n",
82 istate->rsi, istate->rdi, istate->rbp,
83 istate_from_uspace(istate) ? istate->rsp :
84 (uintptr_t) &istate->rsp);
[a35b458]85
[b2fa1204]86 log_printf("r8 =%0#18" PRIx64 "\tr9 =%0#18" PRIx64 "\t"
[2438fa6]87 "r10=%0#18" PRIx64 "\tr11=%0#18" PRIx64 "\n",
[9171f12]88 istate->r8, istate->r9, istate->r10, istate->r11);
[a35b458]89
[b2fa1204]90 log_printf("r12=%0#18" PRIx64 "\tr13=%0#18" PRIx64 "\t"
[2438fa6]91 "r14=%0#18" PRIx64 "\tr15=%0#18" PRIx64 "\n",
[9171f12]92 istate->r12, istate->r13, istate->r14, istate->r15);
[8ec9bae]93}
[db3341e]94
[8607db8]95static void trap_virtual_eoi(void)
96{
97 if (eoi_function)
98 eoi_function();
99 else
[f651e80]100 panic("No eoi_function.");
[db3341e]101
[8607db8]102}
[db3341e]103
[214ec25c]104static void null_interrupt(unsigned int n, istate_t *istate)
[db3341e]105{
[214ec25c]106 fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n);
[a043e39]107 panic_badtrap(istate, n, "Unserviced interrupt.");
[db3341e]108}
109
[214ec25c]110static void de_fault(unsigned int n, istate_t *istate)
[4491338]111{
112 fault_if_from_uspace(istate, "Divide error.");
[a043e39]113 panic_badtrap(istate, n, "Divide error.");
[4491338]114}
115
[da1bafb]116/** General Protection Fault.
117 *
118 */
[214ec25c]119static void gp_fault(unsigned int n, istate_t *istate)
[db3341e]120{
[2382d09]121 if (TASK) {
[da1bafb]122 irq_spinlock_lock(&TASK->lock, false);
123 size_t ver = TASK->arch.iomapver;
124 irq_spinlock_unlock(&TASK->lock, false);
[a35b458]125
[2382d09]126 if (CPU->arch.iomapver_copy != ver) {
127 /*
128 * This fault can be caused by an early access
129 * to I/O port because of an out-dated
130 * I/O Permission bitmap installed on CPU.
131 * Install the fresh copy and restart
132 * the instruction.
133 */
134 io_perm_bitmap_install();
135 return;
136 }
[f651e80]137 fault_if_from_uspace(istate, "General protection fault.");
[2382d09]138 }
[a043e39]139 panic_badtrap(istate, n, "General protection fault.");
[db3341e]140}
141
[214ec25c]142static void ss_fault(unsigned int n, istate_t *istate)
[db3341e]143{
[f651e80]144 fault_if_from_uspace(istate, "Stack fault.");
[a043e39]145 panic_badtrap(istate, n, "Stack fault.");
[db3341e]146}
147
[214ec25c]148static void nm_fault(unsigned int n, istate_t *istate)
[db3341e]149{
[6da1013f]150#ifdef CONFIG_FPU_LAZY
[b49f4ae]151 scheduler_fpu_lazy_request();
152#else
[f651e80]153 fault_if_from_uspace(istate, "FPU fault.");
154 panic("FPU fault.");
[b49f4ae]155#endif
[db3341e]156}
157
[cbc8ac6]158#ifdef CONFIG_SMP
[214ec25c]159static void tlb_shootdown_ipi(unsigned int n, istate_t *istate)
[db3341e]160{
161 trap_virtual_eoi();
162 tlb_shootdown_ipi_recv();
163}
[2ee1ccc]164
165static void arch_smp_call_ipi_recv(unsigned int n, istate_t *istate)
166{
167 trap_virtual_eoi();
168 smp_call_ipi_recv();
169}
[cbc8ac6]170#endif
[db3341e]171
[da1bafb]172/** Handler of IRQ exceptions.
173 *
174 */
[214ec25c]175static void irq_interrupt(unsigned int n, istate_t *istate)
[8607db8]176{
[63e27ef]177 assert(n >= IVT_IRQBASE);
[a35b458]178
[214ec25c]179 unsigned int inum = n - IVT_IRQBASE;
[7bcfbbc]180 bool ack = false;
[63e27ef]181 assert(inum < IRQ_COUNT);
182 assert((inum != IRQ_PIC_SPUR) && (inum != IRQ_PIC1));
[a35b458]183
[8607db8]184 irq_t *irq = irq_dispatch_and_lock(inum);
185 if (irq) {
186 /*
187 * The IRQ handler was found.
188 */
[a35b458]189
[7bcfbbc]190 if (irq->preack) {
191 /* Send EOI before processing the interrupt */
192 trap_virtual_eoi();
193 ack = true;
194 }
[6cd9aa6]195 irq->handler(irq);
[da1bafb]196 irq_spinlock_unlock(&irq->lock, false);
[8607db8]197 } else {
198 /*
199 * Spurious interrupt.
200 */
201#ifdef CONFIG_DEBUG
[b2fa1204]202 log(LF_ARCH, LVL_DEBUG, "cpu%u: spurious interrupt (inum=%u)",
203 CPU->id, inum);
[8607db8]204#endif
205 }
[a35b458]206
[7bcfbbc]207 if (!ack)
208 trap_virtual_eoi();
[8607db8]209}
210
211void interrupt_init(void)
212{
[b3b7e14a]213 unsigned int i;
[a35b458]214
[8607db8]215 for (i = 0; i < IVT_ITEMS; i++)
[b3b7e14a]216 exc_register(i, "null", false, (iroutine_t) null_interrupt);
[a35b458]217
[8607db8]218 for (i = 0; i < IRQ_COUNT; i++) {
219 if ((i != IRQ_PIC_SPUR) && (i != IRQ_PIC1))
[b3b7e14a]220 exc_register(IVT_IRQBASE + i, "irq", true,
221 (iroutine_t) irq_interrupt);
[8607db8]222 }
[a35b458]223
[4b0206c]224 exc_register(VECTOR_DE, "de_fault", true, (iroutine_t) de_fault);
225 exc_register(VECTOR_NM, "nm_fault", true, (iroutine_t) nm_fault);
226 exc_register(VECTOR_SS, "ss_fault", true, (iroutine_t) ss_fault);
227 exc_register(VECTOR_GP, "gp_fault", true, (iroutine_t) gp_fault);
[a35b458]228
[8607db8]229#ifdef CONFIG_SMP
[b3b7e14a]230 exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", true,
231 (iroutine_t) tlb_shootdown_ipi);
[1b20da0]232 exc_register(VECTOR_SMP_CALL_IPI, "smp_call", true,
[2ee1ccc]233 (iroutine_t) arch_smp_call_ipi_recv);
[8607db8]234#endif
235}
236
[7f1c620]237void trap_virtual_enable_irqs(uint16_t irqmask)
[db3341e]238{
239 if (enable_irqs_function)
240 enable_irqs_function(irqmask);
241 else
[f651e80]242 panic("No enable_irqs_function.");
[db3341e]243}
244
[7f1c620]245void trap_virtual_disable_irqs(uint16_t irqmask)
[db3341e]246{
247 if (disable_irqs_function)
248 disable_irqs_function(irqmask);
249 else
[f651e80]250 panic("No disable_irqs_function.");
[db3341e]251}
252
[06e1e95]253/** @}
[b45c443]254 */
Note: See TracBrowser for help on using the repository browser.