Rev 1937 | Rev 1956 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | jermar | 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 | |||
| 1705 | cejka | 29 | /** @addtogroup ia32interrupt |
| 1702 | cejka | 30 | * @{ |
| 31 | */ |
||
| 32 | /** @file |
||
| 33 | */ |
||
| 34 | |||
| 1 | jermar | 35 | #include <arch/interrupt.h> |
| 712 | decky | 36 | #include <syscall/syscall.h> |
| 1 | jermar | 37 | #include <print.h> |
| 68 | decky | 38 | #include <debug.h> |
| 1 | jermar | 39 | #include <panic.h> |
| 1477 | decky | 40 | #include <arch/drivers/i8259.h> |
| 1 | jermar | 41 | #include <func.h> |
| 42 | #include <cpu.h> |
||
| 43 | #include <arch/asm.h> |
||
| 5 | jermar | 44 | #include <mm/tlb.h> |
| 703 | jermar | 45 | #include <mm/as.h> |
| 22 | jermar | 46 | #include <arch.h> |
| 268 | palkovsky | 47 | #include <symtab.h> |
| 391 | jermar | 48 | #include <proc/thread.h> |
| 1256 | jermar | 49 | #include <proc/task.h> |
| 50 | #include <synch/spinlock.h> |
||
| 51 | #include <arch/ddi/ddi.h> |
||
| 1258 | palkovsky | 52 | #include <ipc/sysipc.h> |
| 53 | #include <interrupt.h> |
||
| 1 | jermar | 54 | |
| 55 | /* |
||
| 56 | * Interrupt and exception dispatching. |
||
| 57 | */ |
||
| 58 | |||
| 1780 | jermar | 59 | void (* disable_irqs_function)(uint16_t irqmask) = NULL; |
| 60 | void (* enable_irqs_function)(uint16_t irqmask) = NULL; |
||
| 1 | jermar | 61 | void (* eoi_function)(void) = NULL; |
| 62 | |||
| 1411 | jermar | 63 | void PRINT_INFO_ERRCODE(istate_t *istate) |
| 1008 | jermar | 64 | { |
| 65 | char *symbol = get_symtab_entry(istate->eip); |
||
| 268 | palkovsky | 66 | |
| 1008 | jermar | 67 | if (!symbol) |
| 68 | symbol = ""; |
||
| 69 | |||
| 70 | if (CPU) |
||
| 71 | printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id); |
||
| 72 | else |
||
| 73 | printf("----------------EXCEPTION OCCURED----------------\n"); |
||
| 74 | |||
| 1221 | decky | 75 | printf("%%eip: %#x (%s)\n",istate->eip,symbol); |
| 76 | printf("ERROR_WORD=%#x\n", istate->error_word); |
||
| 77 | printf("%%cs=%#x,flags=%#x\n", istate->cs, istate->eflags); |
||
| 78 | printf("%%eax=%#x, %%ecx=%#x, %%edx=%#x, %%esp=%#x\n", istate->eax,istate->ecx,istate->edx,&istate->stack[0]); |
||
| 1100 | palkovsky | 79 | #ifdef CONFIG_DEBUG_ALLREGS |
| 1221 | decky | 80 | printf("%%esi=%#x, %%edi=%#x, %%ebp=%#x, %%ebx=%#x\n", istate->esi,istate->edi,istate->ebp,istate->ebx); |
| 1100 | palkovsky | 81 | #endif |
| 1221 | decky | 82 | printf("stack: %#x, %#x, %#x, %#x\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); |
| 83 | printf(" %#x, %#x, %#x, %#x\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); |
||
| 1008 | jermar | 84 | } |
| 85 | |||
| 958 | jermar | 86 | void null_interrupt(int n, istate_t *istate) |
| 1 | jermar | 87 | { |
| 1595 | palkovsky | 88 | fault_if_from_uspace(istate, "unserviced interrupt: %d", n); |
| 89 | |||
| 958 | jermar | 90 | PRINT_INFO_ERRCODE(istate); |
| 91 | panic("unserviced interrupt: %d\n", n); |
||
| 1 | jermar | 92 | } |
| 93 | |||
| 1256 | jermar | 94 | /** General Protection Fault. */ |
| 958 | jermar | 95 | void gp_fault(int n, istate_t *istate) |
| 1 | jermar | 96 | { |
| 1256 | jermar | 97 | if (TASK) { |
| 98 | count_t ver; |
||
| 99 | |||
| 100 | spinlock_lock(&TASK->lock); |
||
| 101 | ver = TASK->arch.iomapver; |
||
| 102 | spinlock_unlock(&TASK->lock); |
||
| 103 | |||
| 104 | if (CPU->arch.iomapver_copy != ver) { |
||
| 105 | /* |
||
| 106 | * This fault can be caused by an early access |
||
| 107 | * to I/O port because of an out-dated |
||
| 108 | * I/O Permission bitmap installed on CPU. |
||
| 109 | * Install the fresh copy and restart |
||
| 110 | * the instruction. |
||
| 111 | */ |
||
| 112 | io_perm_bitmap_install(); |
||
| 113 | return; |
||
| 114 | } |
||
| 1595 | palkovsky | 115 | fault_if_from_uspace(istate, "general protection fault"); |
| 1256 | jermar | 116 | } |
| 117 | |||
| 958 | jermar | 118 | PRINT_INFO_ERRCODE(istate); |
| 168 | jermar | 119 | panic("general protection fault\n"); |
| 1 | jermar | 120 | } |
| 121 | |||
| 958 | jermar | 122 | void ss_fault(int n, istate_t *istate) |
| 84 | vana | 123 | { |
| 1595 | palkovsky | 124 | fault_if_from_uspace(istate, "stack fault"); |
| 125 | |||
| 958 | jermar | 126 | PRINT_INFO_ERRCODE(istate); |
| 103 | jermar | 127 | panic("stack fault\n"); |
| 84 | vana | 128 | } |
| 129 | |||
| 1019 | vana | 130 | void simd_fp_exception(int n, istate_t *istate) |
| 131 | { |
||
| 1780 | jermar | 132 | uint32_t mxcsr; |
| 1019 | vana | 133 | asm |
| 134 | ( |
||
| 135 | "stmxcsr %0;\n" |
||
| 136 | :"=m"(mxcsr) |
||
| 137 | ); |
||
| 1735 | decky | 138 | fault_if_from_uspace(istate, "SIMD FP exception(19), MXCSR: %#zx", |
| 1780 | jermar | 139 | (unative_t)mxcsr); |
| 1595 | palkovsky | 140 | |
| 141 | PRINT_INFO_ERRCODE(istate); |
||
| 1780 | jermar | 142 | printf("MXCSR: %#zx\n",(unative_t)(mxcsr)); |
| 1019 | vana | 143 | panic("SIMD FP exception(19)\n"); |
| 144 | } |
||
| 145 | |||
| 958 | jermar | 146 | void nm_fault(int n, istate_t *istate) |
| 73 | vana | 147 | { |
| 458 | decky | 148 | #ifdef CONFIG_FPU_LAZY |
| 309 | palkovsky | 149 | scheduler_fpu_lazy_request(); |
| 150 | #else |
||
| 1595 | palkovsky | 151 | fault_if_from_uspace(istate, "fpu fault"); |
| 309 | palkovsky | 152 | panic("fpu fault"); |
| 153 | #endif |
||
| 73 | vana | 154 | } |
| 155 | |||
| 958 | jermar | 156 | void syscall(int n, istate_t *istate) |
| 1 | jermar | 157 | { |
| 1100 | palkovsky | 158 | panic("Obsolete syscall handler."); |
| 1 | jermar | 159 | } |
| 160 | |||
| 958 | jermar | 161 | void tlb_shootdown_ipi(int n, istate_t *istate) |
| 5 | jermar | 162 | { |
| 163 | trap_virtual_eoi(); |
||
| 6 | jermar | 164 | tlb_shootdown_ipi_recv(); |
| 5 | jermar | 165 | } |
| 166 | |||
| 1780 | jermar | 167 | void trap_virtual_enable_irqs(uint16_t irqmask) |
| 1 | jermar | 168 | { |
| 169 | if (enable_irqs_function) |
||
| 170 | enable_irqs_function(irqmask); |
||
| 171 | else |
||
| 68 | decky | 172 | panic("no enable_irqs_function\n"); |
| 1 | jermar | 173 | } |
| 174 | |||
| 1780 | jermar | 175 | void trap_virtual_disable_irqs(uint16_t irqmask) |
| 1 | jermar | 176 | { |
| 177 | if (disable_irqs_function) |
||
| 178 | disable_irqs_function(irqmask); |
||
| 179 | else |
||
| 68 | decky | 180 | panic("no disable_irqs_function\n"); |
| 1 | jermar | 181 | } |
| 182 | |||
| 183 | void trap_virtual_eoi(void) |
||
| 184 | { |
||
| 185 | if (eoi_function) |
||
| 186 | eoi_function(); |
||
| 187 | else |
||
| 68 | decky | 188 | panic("no eoi_function\n"); |
| 1 | jermar | 189 | |
| 190 | } |
||
| 1258 | palkovsky | 191 | |
| 1703 | jermar | 192 | /** @} |
| 1702 | cejka | 193 | */ |