Rev 1008 | Rev 1100 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1008 | Rev 1019 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
2 | * Copyright (C) 2001-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <arch/interrupt.h> |
29 | #include <arch/interrupt.h> |
30 | #include <syscall/syscall.h> |
30 | #include <syscall/syscall.h> |
31 | #include <print.h> |
31 | #include <print.h> |
32 | #include <debug.h> |
32 | #include <debug.h> |
33 | #include <panic.h> |
33 | #include <panic.h> |
34 | #include <arch/i8259.h> |
34 | #include <arch/i8259.h> |
35 | #include <func.h> |
35 | #include <func.h> |
36 | #include <cpu.h> |
36 | #include <cpu.h> |
37 | #include <arch/asm.h> |
37 | #include <arch/asm.h> |
38 | #include <mm/tlb.h> |
38 | #include <mm/tlb.h> |
39 | #include <mm/as.h> |
39 | #include <mm/as.h> |
40 | #include <arch.h> |
40 | #include <arch.h> |
41 | #include <symtab.h> |
41 | #include <symtab.h> |
42 | #include <proc/thread.h> |
42 | #include <proc/thread.h> |
43 | 43 | ||
44 | /* |
44 | /* |
45 | * Interrupt and exception dispatching. |
45 | * Interrupt and exception dispatching. |
46 | */ |
46 | */ |
47 | 47 | ||
48 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
48 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
49 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
49 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
50 | void (* eoi_function)(void) = NULL; |
50 | void (* eoi_function)(void) = NULL; |
51 | 51 | ||
52 | static void PRINT_INFO_ERRCODE(istate_t *istate) |
52 | static void PRINT_INFO_ERRCODE(istate_t *istate) |
53 | { |
53 | { |
54 | char *symbol = get_symtab_entry(istate->eip); |
54 | char *symbol = get_symtab_entry(istate->eip); |
55 | 55 | ||
56 | if (!symbol) |
56 | if (!symbol) |
57 | symbol = ""; |
57 | symbol = ""; |
58 | 58 | ||
59 | if (CPU) |
59 | if (CPU) |
60 | printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id); |
60 | printf("----------------EXCEPTION OCCURED (cpu%d)----------------\n", CPU->id); |
61 | else |
61 | else |
62 | printf("----------------EXCEPTION OCCURED----------------\n"); |
62 | printf("----------------EXCEPTION OCCURED----------------\n"); |
63 | 63 | ||
64 | printf("%%eip: %X (%s)\n",istate->eip,symbol); |
64 | printf("%%eip: %X (%s)\n",istate->eip,symbol); |
65 | printf("ERROR_WORD=%X\n", istate->error_word); |
65 | printf("ERROR_WORD=%X\n", istate->error_word); |
66 | printf("%%cs=%X,flags=%X\n", istate->cs, istate->eflags); |
66 | printf("%%cs=%X,flags=%X\n", istate->cs, istate->eflags); |
67 | printf("%%eax=%X, %%ebx=%X, %%ecx=%X, %%edx=%X\n", istate->eax,istate->ebx,istate->ecx,istate->edx); |
67 | printf("%%eax=%X, %%ebx=%X, %%ecx=%X, %%edx=%X\n", istate->eax,istate->ebx,istate->ecx,istate->edx); |
68 | printf("%%esi=%X, %%edi=%X, %%ebp=%X, %%esp=%X\n", istate->esi,istate->edi,istate->ebp,istate->esp); |
68 | printf("%%esi=%X, %%edi=%X, %%ebp=%X, %%esp=%X\n", istate->esi,istate->edi,istate->ebp,istate->esp); |
69 | printf("stack: %X, %X, %X, %X\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); |
69 | printf("stack: %X, %X, %X, %X\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); |
70 | printf(" %X, %X, %X, %X\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); |
70 | printf(" %X, %X, %X, %X\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); |
71 | } |
71 | } |
72 | 72 | ||
73 | void null_interrupt(int n, istate_t *istate) |
73 | void null_interrupt(int n, istate_t *istate) |
74 | { |
74 | { |
75 | PRINT_INFO_ERRCODE(istate); |
75 | PRINT_INFO_ERRCODE(istate); |
76 | panic("unserviced interrupt: %d\n", n); |
76 | panic("unserviced interrupt: %d\n", n); |
77 | } |
77 | } |
78 | 78 | ||
79 | void gp_fault(int n, istate_t *istate) |
79 | void gp_fault(int n, istate_t *istate) |
80 | { |
80 | { |
81 | PRINT_INFO_ERRCODE(istate); |
81 | PRINT_INFO_ERRCODE(istate); |
82 | panic("general protection fault\n"); |
82 | panic("general protection fault\n"); |
83 | } |
83 | } |
84 | 84 | ||
85 | void ss_fault(int n, istate_t *istate) |
85 | void ss_fault(int n, istate_t *istate) |
86 | { |
86 | { |
87 | PRINT_INFO_ERRCODE(istate); |
87 | PRINT_INFO_ERRCODE(istate); |
88 | panic("stack fault\n"); |
88 | panic("stack fault\n"); |
89 | } |
89 | } |
90 | 90 | ||
- | 91 | void simd_fp_exception(int n, istate_t *istate) |
|
- | 92 | { |
|
- | 93 | ||
- | 94 | PRINT_INFO_ERRCODE(istate); |
|
- | 95 | __u32 mxcsr; |
|
- | 96 | asm |
|
- | 97 | ( |
|
- | 98 | "stmxcsr %0;\n" |
|
- | 99 | :"=m"(mxcsr) |
|
- | 100 | ); |
|
- | 101 | printf("MXCSR: %X\n",(__native)(mxcsr)); |
|
- | 102 | panic("SIMD FP exception(19)\n"); |
|
- | 103 | } |
|
- | 104 | ||
91 | void nm_fault(int n, istate_t *istate) |
105 | void nm_fault(int n, istate_t *istate) |
92 | { |
106 | { |
93 | #ifdef CONFIG_FPU_LAZY |
107 | #ifdef CONFIG_FPU_LAZY |
94 | scheduler_fpu_lazy_request(); |
108 | scheduler_fpu_lazy_request(); |
95 | #else |
109 | #else |
96 | panic("fpu fault"); |
110 | panic("fpu fault"); |
97 | #endif |
111 | #endif |
98 | } |
112 | } |
99 | 113 | ||
100 | void page_fault(int n, istate_t *istate) |
114 | void page_fault(int n, istate_t *istate) |
101 | { |
115 | { |
102 | __address page; |
116 | __address page; |
103 | 117 | ||
104 | page = read_cr2(); |
118 | page = read_cr2(); |
105 | if (!as_page_fault(page)) { |
119 | if (!as_page_fault(page)) { |
106 | PRINT_INFO_ERRCODE(istate); |
120 | PRINT_INFO_ERRCODE(istate); |
107 | printf("page fault address: %X\n", page); |
121 | printf("page fault address: %X\n", page); |
108 | panic("page fault\n"); |
122 | panic("page fault\n"); |
109 | } |
123 | } |
110 | } |
124 | } |
111 | 125 | ||
112 | void syscall(int n, istate_t *istate) |
126 | void syscall(int n, istate_t *istate) |
113 | { |
127 | { |
114 | interrupts_enable(); |
128 | interrupts_enable(); |
115 | if (istate->esi < SYSCALL_END) |
129 | if (istate->esi < SYSCALL_END) |
116 | istate->eax = syscall_table[istate->esi](istate->eax, istate->ebx, istate->ecx, istate->edx); |
130 | istate->eax = syscall_table[istate->esi](istate->eax, istate->ebx, istate->ecx, istate->edx); |
117 | else |
131 | else |
118 | panic("Undefined syscall %d", istate->esi); |
132 | panic("Undefined syscall %d", istate->esi); |
119 | interrupts_disable(); |
133 | interrupts_disable(); |
120 | } |
134 | } |
121 | 135 | ||
122 | void tlb_shootdown_ipi(int n, istate_t *istate) |
136 | void tlb_shootdown_ipi(int n, istate_t *istate) |
123 | { |
137 | { |
124 | trap_virtual_eoi(); |
138 | trap_virtual_eoi(); |
125 | tlb_shootdown_ipi_recv(); |
139 | tlb_shootdown_ipi_recv(); |
126 | } |
140 | } |
127 | 141 | ||
128 | void trap_virtual_enable_irqs(__u16 irqmask) |
142 | void trap_virtual_enable_irqs(__u16 irqmask) |
129 | { |
143 | { |
130 | if (enable_irqs_function) |
144 | if (enable_irqs_function) |
131 | enable_irqs_function(irqmask); |
145 | enable_irqs_function(irqmask); |
132 | else |
146 | else |
133 | panic("no enable_irqs_function\n"); |
147 | panic("no enable_irqs_function\n"); |
134 | } |
148 | } |
135 | 149 | ||
136 | void trap_virtual_disable_irqs(__u16 irqmask) |
150 | void trap_virtual_disable_irqs(__u16 irqmask) |
137 | { |
151 | { |
138 | if (disable_irqs_function) |
152 | if (disable_irqs_function) |
139 | disable_irqs_function(irqmask); |
153 | disable_irqs_function(irqmask); |
140 | else |
154 | else |
141 | panic("no disable_irqs_function\n"); |
155 | panic("no disable_irqs_function\n"); |
142 | } |
156 | } |
143 | 157 | ||
144 | void trap_virtual_eoi(void) |
158 | void trap_virtual_eoi(void) |
145 | { |
159 | { |
146 | if (eoi_function) |
160 | if (eoi_function) |
147 | eoi_function(); |
161 | eoi_function(); |
148 | else |
162 | else |
149 | panic("no eoi_function\n"); |
163 | panic("no eoi_function\n"); |
150 | 164 | ||
151 | } |
165 | } |
152 | 166 |