[f761f1eb] | 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 | #include <arch/interrupt.h>
|
---|
[204674e] | 30 | #include <syscall/syscall.h>
|
---|
[f761f1eb] | 31 | #include <print.h>
|
---|
[02a99d2] | 32 | #include <debug.h>
|
---|
[f761f1eb] | 33 | #include <panic.h>
|
---|
| 34 | #include <arch/i8259.h>
|
---|
| 35 | #include <func.h>
|
---|
| 36 | #include <cpu.h>
|
---|
| 37 | #include <arch/asm.h>
|
---|
[169587a] | 38 | #include <mm/tlb.h>
|
---|
[20d50a1] | 39 | #include <mm/as.h>
|
---|
[cb4b61d] | 40 | #include <arch.h>
|
---|
[ab08b42] | 41 | #include <symtab.h>
|
---|
[1084a784] | 42 | #include <proc/thread.h>
|
---|
[2382d09] | 43 | #include <proc/task.h>
|
---|
| 44 | #include <synch/spinlock.h>
|
---|
| 45 | #include <arch/ddi/ddi.h>
|
---|
[5626277] | 46 | #include <ipc/sysipc.h>
|
---|
| 47 | #include <interrupt.h>
|
---|
[f761f1eb] | 48 |
|
---|
| 49 | /*
|
---|
| 50 | * Interrupt and exception dispatching.
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | void (* disable_irqs_function)(__u16 irqmask) = NULL;
|
---|
| 54 | void (* enable_irqs_function)(__u16 irqmask) = NULL;
|
---|
| 55 | void (* eoi_function)(void) = NULL;
|
---|
| 56 |
|
---|
[97b64c9] | 57 | static void PRINT_INFO_ERRCODE(istate_t *istate)
|
---|
| 58 | {
|
---|
| 59 | char *symbol = get_symtab_entry(istate->eip);
|
---|
| 60 |
|
---|
| 61 | if (!symbol)
|
---|
| 62 | symbol = "";
|
---|
| 63 |
|
---|
| 64 | if (CPU)
|
---|
| 65 | printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id);
|
---|
| 66 | else
|
---|
| 67 | printf("----------------EXCEPTION OCCURED----------------\n");
|
---|
| 68 |
|
---|
[cf85e24c] | 69 | printf("%%eip: %#x (%s)\n",istate->eip,symbol);
|
---|
| 70 | printf("ERROR_WORD=%#x\n", istate->error_word);
|
---|
| 71 | printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags);
|
---|
| 72 | printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n", istate->eax,istate->ecx,istate->edx,&istate->stack[0]);
|
---|
[53f9821] | 73 | #ifdef CONFIG_DEBUG_ALLREGS
|
---|
[cf85e24c] | 74 | printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n", istate->esi,istate->edi,istate->ebp,istate->ebx);
|
---|
[53f9821] | 75 | #endif
|
---|
[cf85e24c] | 76 | printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]);
|
---|
| 77 | printf(" %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]);
|
---|
[97b64c9] | 78 | }
|
---|
[ab08b42] | 79 |
|
---|
[25d7709] | 80 | void null_interrupt(int n, istate_t *istate)
|
---|
[f761f1eb] | 81 | {
|
---|
[25d7709] | 82 | PRINT_INFO_ERRCODE(istate);
|
---|
| 83 | panic("unserviced interrupt: %d\n", n);
|
---|
[f761f1eb] | 84 | }
|
---|
| 85 |
|
---|
[2382d09] | 86 | /** General Protection Fault. */
|
---|
[25d7709] | 87 | void gp_fault(int n, istate_t *istate)
|
---|
[f761f1eb] | 88 | {
|
---|
[2382d09] | 89 | if (TASK) {
|
---|
| 90 | count_t ver;
|
---|
| 91 |
|
---|
| 92 | spinlock_lock(&TASK->lock);
|
---|
| 93 | ver = TASK->arch.iomapver;
|
---|
| 94 | spinlock_unlock(&TASK->lock);
|
---|
| 95 |
|
---|
| 96 | if (CPU->arch.iomapver_copy != ver) {
|
---|
| 97 | /*
|
---|
| 98 | * This fault can be caused by an early access
|
---|
| 99 | * to I/O port because of an out-dated
|
---|
| 100 | * I/O Permission bitmap installed on CPU.
|
---|
| 101 | * Install the fresh copy and restart
|
---|
| 102 | * the instruction.
|
---|
| 103 | */
|
---|
| 104 | io_perm_bitmap_install();
|
---|
| 105 | return;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[25d7709] | 109 | PRINT_INFO_ERRCODE(istate);
|
---|
[f4a61ef] | 110 | panic("general protection fault\n");
|
---|
[f761f1eb] | 111 | }
|
---|
| 112 |
|
---|
[25d7709] | 113 | void ss_fault(int n, istate_t *istate)
|
---|
[6de2480e] | 114 | {
|
---|
[25d7709] | 115 | PRINT_INFO_ERRCODE(istate);
|
---|
[747a2476] | 116 | panic("stack fault\n");
|
---|
[6de2480e] | 117 | }
|
---|
| 118 |
|
---|
[3b05862f] | 119 | void simd_fp_exception(int n, istate_t *istate)
|
---|
| 120 | {
|
---|
| 121 |
|
---|
| 122 | PRINT_INFO_ERRCODE(istate);
|
---|
| 123 | __u32 mxcsr;
|
---|
| 124 | asm
|
---|
| 125 | (
|
---|
| 126 | "stmxcsr %0;\n"
|
---|
| 127 | :"=m"(mxcsr)
|
---|
| 128 | );
|
---|
[280a27e] | 129 | printf("MXCSR: %#zX\n",(__native)(mxcsr));
|
---|
[3b05862f] | 130 | panic("SIMD FP exception(19)\n");
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[25d7709] | 133 | void nm_fault(int n, istate_t *istate)
|
---|
[6a27d63] | 134 | {
|
---|
[5f85c91] | 135 | #ifdef CONFIG_FPU_LAZY
|
---|
[b49f4ae] | 136 | scheduler_fpu_lazy_request();
|
---|
| 137 | #else
|
---|
| 138 | panic("fpu fault");
|
---|
| 139 | #endif
|
---|
[6a27d63] | 140 | }
|
---|
| 141 |
|
---|
[25d7709] | 142 | void page_fault(int n, istate_t *istate)
|
---|
[f761f1eb] | 143 | {
|
---|
[20d50a1] | 144 | __address page;
|
---|
| 145 |
|
---|
| 146 | page = read_cr2();
|
---|
| 147 | if (!as_page_fault(page)) {
|
---|
[25d7709] | 148 | PRINT_INFO_ERRCODE(istate);
|
---|
[cf85e24c] | 149 | printf("page fault address: %#x\n", page);
|
---|
[20d50a1] | 150 | panic("page fault\n");
|
---|
| 151 | }
|
---|
[f761f1eb] | 152 | }
|
---|
| 153 |
|
---|
[25d7709] | 154 | void syscall(int n, istate_t *istate)
|
---|
[f761f1eb] | 155 | {
|
---|
[53f9821] | 156 | panic("Obsolete syscall handler.");
|
---|
[f761f1eb] | 157 | }
|
---|
| 158 |
|
---|
[25d7709] | 159 | void tlb_shootdown_ipi(int n, istate_t *istate)
|
---|
[169587a] | 160 | {
|
---|
| 161 | trap_virtual_eoi();
|
---|
[b109ebb] | 162 | tlb_shootdown_ipi_recv();
|
---|
[169587a] | 163 | }
|
---|
| 164 |
|
---|
[f761f1eb] | 165 | void trap_virtual_enable_irqs(__u16 irqmask)
|
---|
| 166 | {
|
---|
| 167 | if (enable_irqs_function)
|
---|
| 168 | enable_irqs_function(irqmask);
|
---|
| 169 | else
|
---|
[02a99d2] | 170 | panic("no enable_irqs_function\n");
|
---|
[f761f1eb] | 171 | }
|
---|
| 172 |
|
---|
| 173 | void trap_virtual_disable_irqs(__u16 irqmask)
|
---|
| 174 | {
|
---|
| 175 | if (disable_irqs_function)
|
---|
| 176 | disable_irqs_function(irqmask);
|
---|
| 177 | else
|
---|
[02a99d2] | 178 | panic("no disable_irqs_function\n");
|
---|
[f761f1eb] | 179 | }
|
---|
| 180 |
|
---|
| 181 | void trap_virtual_eoi(void)
|
---|
| 182 | {
|
---|
| 183 | if (eoi_function)
|
---|
| 184 | eoi_function();
|
---|
| 185 | else
|
---|
[02a99d2] | 186 | panic("no eoi_function\n");
|
---|
[f761f1eb] | 187 |
|
---|
| 188 | }
|
---|
[5626277] | 189 |
|
---|
| 190 | static void ipc_int(int n, istate_t *istate)
|
---|
| 191 | {
|
---|
| 192 | trap_virtual_eoi();
|
---|
| 193 | ipc_irq_send_notif(n-IVT_IRQBASE);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | /* Reregister irq to be IPC-ready */
|
---|
| 198 | void irq_ipc_bind_arch(__native irq)
|
---|
| 199 | {
|
---|
| 200 | if (irq == IRQ_CLK)
|
---|
| 201 | return;
|
---|
| 202 | exc_register(IVT_IRQBASE+irq, "ipc_int", ipc_int);
|
---|
| 203 | }
|
---|