Rev 955 | Rev 959 | 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 | |||
29 | #include <arch/interrupt.h> |
||
712 | decky | 30 | #include <syscall/syscall.h> |
1 | jermar | 31 | #include <print.h> |
68 | decky | 32 | #include <debug.h> |
1 | jermar | 33 | #include <panic.h> |
34 | #include <arch/i8259.h> |
||
35 | #include <func.h> |
||
36 | #include <cpu.h> |
||
37 | #include <arch/asm.h> |
||
5 | jermar | 38 | #include <mm/tlb.h> |
703 | jermar | 39 | #include <mm/as.h> |
22 | jermar | 40 | #include <arch.h> |
268 | palkovsky | 41 | #include <symtab.h> |
391 | jermar | 42 | #include <proc/thread.h> |
1 | jermar | 43 | |
44 | /* |
||
45 | * Interrupt and exception dispatching. |
||
46 | */ |
||
47 | |||
48 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
||
49 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
||
50 | void (* eoi_function)(void) = NULL; |
||
51 | |||
958 | jermar | 52 | #define PRINT_INFO_ERRCODE(istate) do { \ |
53 | char *symbol = get_symtab_entry(istate->eip); \ |
||
268 | palkovsky | 54 | if (!symbol) \ |
55 | symbol = ""; \ |
||
56 | printf("----------------EXCEPTION OCCURED----------------\n"); \ |
||
958 | jermar | 57 | printf("%%eip: %X (%s)\n",istate->eip,symbol); \ |
58 | printf("ERROR_WORD=%X\n", istate->error_word); \ |
||
59 | printf("%%cs=%X,flags=%X\n", istate->cs, istate->eflags); \ |
||
268 | palkovsky | 60 | printf("%%eax=%X, %%ebx=%X, %%ecx=%X, %%edx=%X\n",\ |
958 | jermar | 61 | istate->eax,istate->ebx,istate->ecx,istate->edx); \ |
268 | palkovsky | 62 | printf("%%esi=%X, %%edi=%X, %%ebp=%X, %%esp=%X\n",\ |
958 | jermar | 63 | istate->esi,istate->edi,istate->ebp,istate->esp); \ |
64 | printf("stack: %X, %X, %X, %X\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); \ |
||
65 | printf(" %X, %X, %X, %X\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); \ |
||
66 | } while(0) |
||
268 | palkovsky | 67 | |
958 | jermar | 68 | void null_interrupt(int n, istate_t *istate) |
1 | jermar | 69 | { |
958 | jermar | 70 | PRINT_INFO_ERRCODE(istate); |
71 | panic("unserviced interrupt: %d\n", n); |
||
1 | jermar | 72 | } |
73 | |||
958 | jermar | 74 | void gp_fault(int n, istate_t *istate) |
1 | jermar | 75 | { |
958 | jermar | 76 | PRINT_INFO_ERRCODE(istate); |
168 | jermar | 77 | panic("general protection fault\n"); |
1 | jermar | 78 | } |
79 | |||
958 | jermar | 80 | void ss_fault(int n, istate_t *istate) |
84 | vana | 81 | { |
958 | jermar | 82 | PRINT_INFO_ERRCODE(istate); |
103 | jermar | 83 | panic("stack fault\n"); |
84 | vana | 84 | } |
85 | |||
958 | jermar | 86 | void nm_fault(int n, istate_t *istate) |
73 | vana | 87 | { |
458 | decky | 88 | #ifdef CONFIG_FPU_LAZY |
309 | palkovsky | 89 | scheduler_fpu_lazy_request(); |
90 | #else |
||
91 | panic("fpu fault"); |
||
92 | #endif |
||
73 | vana | 93 | } |
94 | |||
958 | jermar | 95 | void page_fault(int n, istate_t *istate) |
1 | jermar | 96 | { |
703 | jermar | 97 | __address page; |
98 | |||
99 | page = read_cr2(); |
||
100 | if (!as_page_fault(page)) { |
||
958 | jermar | 101 | PRINT_INFO_ERRCODE(istate); |
703 | jermar | 102 | printf("page fault address: %X\n", page); |
103 | panic("page fault\n"); |
||
104 | } |
||
1 | jermar | 105 | } |
106 | |||
958 | jermar | 107 | void syscall(int n, istate_t *istate) |
1 | jermar | 108 | { |
955 | palkovsky | 109 | interrupts_enable(); |
958 | jermar | 110 | if (istate->edx < SYSCALL_END) |
111 | istate->eax = syscall_table[istate->edx](istate->eax, istate->ebx, istate->ecx); |
||
712 | decky | 112 | else |
958 | jermar | 113 | panic("Undefined syscall %d", istate->edx); |
955 | palkovsky | 114 | interrupts_disable(); |
1 | jermar | 115 | } |
116 | |||
958 | jermar | 117 | void tlb_shootdown_ipi(int n, istate_t *istate) |
5 | jermar | 118 | { |
119 | trap_virtual_eoi(); |
||
6 | jermar | 120 | tlb_shootdown_ipi_recv(); |
5 | jermar | 121 | } |
122 | |||
1 | jermar | 123 | void trap_virtual_enable_irqs(__u16 irqmask) |
124 | { |
||
125 | if (enable_irqs_function) |
||
126 | enable_irqs_function(irqmask); |
||
127 | else |
||
68 | decky | 128 | panic("no enable_irqs_function\n"); |
1 | jermar | 129 | } |
130 | |||
131 | void trap_virtual_disable_irqs(__u16 irqmask) |
||
132 | { |
||
133 | if (disable_irqs_function) |
||
134 | disable_irqs_function(irqmask); |
||
135 | else |
||
68 | decky | 136 | panic("no disable_irqs_function\n"); |
1 | jermar | 137 | } |
138 | |||
139 | void trap_virtual_eoi(void) |
||
140 | { |
||
141 | if (eoi_function) |
||
142 | eoi_function(); |
||
143 | else |
||
68 | decky | 144 | panic("no eoi_function\n"); |
1 | jermar | 145 | |
146 | } |