Rev 1050 | Rev 1060 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1050 | Rev 1051 | ||
---|---|---|---|
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 <print.h> |
30 | #include <print.h> |
31 | #include <debug.h> |
31 | #include <debug.h> |
32 | #include <panic.h> |
32 | #include <panic.h> |
33 | #include <arch/i8259.h> |
33 | #include <arch/i8259.h> |
34 | #include <func.h> |
34 | #include <func.h> |
35 | #include <cpu.h> |
35 | #include <cpu.h> |
36 | #include <arch/asm.h> |
36 | #include <arch/asm.h> |
37 | #include <mm/tlb.h> |
37 | #include <mm/tlb.h> |
38 | #include <mm/as.h> |
38 | #include <mm/as.h> |
39 | #include <arch.h> |
39 | #include <arch.h> |
40 | #include <symtab.h> |
40 | #include <symtab.h> |
41 | #include <arch/asm.h> |
41 | #include <arch/asm.h> |
42 | #include <proc/scheduler.h> |
42 | #include <proc/scheduler.h> |
43 | #include <proc/thread.h> |
43 | #include <proc/thread.h> |
44 | 44 | ||
45 | static void print_info_errcode(int n, istate_t *istate) |
45 | void print_info_errcode(int n, istate_t *istate) |
46 | { |
46 | { |
47 | char *symbol; |
47 | char *symbol; |
48 | __u64 *x = &istate->stack[0]; |
48 | __u64 *x = &istate->stack[0]; |
49 | 49 | ||
50 | if (!(symbol=get_symtab_entry(istate->rip))) |
50 | if (!(symbol=get_symtab_entry(istate->rip))) |
51 | symbol = ""; |
51 | symbol = ""; |
52 | 52 | ||
53 | printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n, __FUNCTION__); |
53 | printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n, __FUNCTION__); |
54 | printf("%%rip: %Q (%s)\n",istate->rip, symbol); |
54 | printf("%%rip: %Q (%s)\n",istate->rip, symbol); |
55 | printf("ERROR_WORD=%Q\n", istate->error_word); |
55 | printf("ERROR_WORD=%Q\n", istate->error_word); |
56 | printf("%%rcs=%Q, flags=%Q, %%cr0=%Q\n", istate->cs, istate->rflags,read_cr0()); |
56 | printf("%%rcs=%Q, flags=%Q, %%cr0=%Q\n", istate->cs, istate->rflags,read_cr0()); |
57 | printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",istate->rax,istate->rbx,istate->rcx); |
57 | printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",istate->rax,istate->rbx,istate->rcx); |
58 | printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",istate->rdx,istate->rsi,istate->rdi); |
58 | printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",istate->rdx,istate->rsi,istate->rdi); |
59 | printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",istate->r8,istate->r9,istate->r10); |
59 | printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",istate->r8,istate->r9,istate->r10); |
60 | printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",istate->r11,istate->r12,istate->r13); |
60 | printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",istate->r11,istate->r12,istate->r13); |
61 | printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",istate->r14,istate->r15,&istate->stack[0]); |
61 | printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",istate->r14,istate->r15,&istate->stack[0]); |
62 | printf("%%rbp=%Q\n",istate->rbp); |
62 | printf("%%rbp=%Q\n",istate->rbp); |
63 | printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]); |
63 | printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]); |
64 | printf(" %Q, %Q, %Q\n", x[8], x[9], x[10]); |
64 | printf(" %Q, %Q, %Q\n", x[8], x[9], x[10]); |
65 | printf(" %Q, %Q, %Q\n", x[11], x[12], x[13]); |
65 | printf(" %Q, %Q, %Q\n", x[11], x[12], x[13]); |
66 | printf(" %Q, %Q, %Q\n", x[14], x[15], x[16]); |
66 | printf(" %Q, %Q, %Q\n", x[14], x[15], x[16]); |
67 | } |
67 | } |
68 | 68 | ||
69 | /* |
69 | /* |
70 | * Interrupt and exception dispatching. |
70 | * Interrupt and exception dispatching. |
71 | */ |
71 | */ |
72 | 72 | ||
73 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
73 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
74 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
74 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
75 | void (* eoi_function)(void) = NULL; |
75 | void (* eoi_function)(void) = NULL; |
76 | 76 | ||
77 | void null_interrupt(int n, istate_t *istate) |
77 | void null_interrupt(int n, istate_t *istate) |
78 | { |
78 | { |
79 | print_info_errcode(n, istate); |
79 | print_info_errcode(n, istate); |
80 | panic("unserviced interrupt\n"); |
80 | panic("unserviced interrupt\n"); |
81 | } |
81 | } |
82 | 82 | ||
83 | void gp_fault(int n, istate_t *istate) |
83 | void gp_fault(int n, istate_t *istate) |
84 | { |
84 | { |
85 | print_info_errcode(n, istate); |
85 | print_info_errcode(n, istate); |
86 | panic("general protection fault\n"); |
86 | panic("general protection fault\n"); |
87 | } |
87 | } |
88 | 88 | ||
89 | void ss_fault(int n, istate_t *istate) |
89 | void ss_fault(int n, istate_t *istate) |
90 | { |
90 | { |
91 | print_info_errcode(n, istate); |
91 | print_info_errcode(n, istate); |
92 | panic("stack fault\n"); |
92 | panic("stack fault\n"); |
93 | } |
93 | } |
94 | 94 | ||
95 | - | ||
96 | void nm_fault(int n, istate_t *istate) |
95 | void nm_fault(int n, istate_t *istate) |
97 | { |
96 | { |
98 | #ifdef CONFIG_FPU_LAZY |
97 | #ifdef CONFIG_FPU_LAZY |
99 | scheduler_fpu_lazy_request(); |
98 | scheduler_fpu_lazy_request(); |
100 | #else |
99 | #else |
101 | panic("fpu fault"); |
100 | panic("fpu fault"); |
102 | #endif |
101 | #endif |
103 | } |
102 | } |
104 | - | ||
105 | - | ||
106 | /* Definitions for identic page mapper */ |
- | |
107 | pte_t helper_ptl1[512] __attribute__((aligned (PAGE_SIZE))); |
- | |
108 | pte_t helper_ptl2[512] __attribute__((aligned (PAGE_SIZE))); |
- | |
109 | pte_t helper_ptl3[512] __attribute__((aligned (PAGE_SIZE))); |
- | |
110 | extern pte_t ptl_0; /* From boot.S */ |
- | |
111 | - | ||
112 | #define PTL1_PRESENT(ptl0, page) (!(GET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page)) & PAGE_NOT_PRESENT)) |
- | |
113 | #define PTL2_PRESENT(ptl1, page) (!(GET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page)) & PAGE_NOT_PRESENT)) |
- | |
114 | #define PTL3_PRESENT(ptl2, page) (!(GET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page)) & PAGE_NOT_PRESENT)) |
- | |
115 | - | ||
116 | #define PTL1_ADDR(ptl0, page) ((pte_t *)PA2KA(GET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page)))) |
- | |
117 | #define PTL2_ADDR(ptl1, page) ((pte_t *)PA2KA(GET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page)))) |
- | |
118 | #define PTL3_ADDR(ptl2, page) ((pte_t *)PA2KA(GET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page)))) |
- | |
119 | - | ||
120 | #define SETUP_PTL1(ptl0, page, tgt) { \ |
- | |
121 | SET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page), (__address)KA2PA(tgt)); \ |
- | |
122 | SET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \ |
- | |
123 | } |
- | |
124 | #define SETUP_PTL2(ptl1, page, tgt) { \ |
- | |
125 | SET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page), (__address)KA2PA(tgt)); \ |
- | |
126 | SET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \ |
- | |
127 | } |
- | |
128 | #define SETUP_PTL3(ptl2, page, tgt) { \ |
- | |
129 | SET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page), (__address)KA2PA(tgt)); \ |
- | |
130 | SET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \ |
- | |
131 | } |
- | |
132 | #define SETUP_FRAME(ptl3, page, tgt) { \ |
- | |
133 | SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (__address)KA2PA(tgt)); \ |
- | |
134 | SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \ |
- | |
135 | } |
- | |
136 | - | ||
137 | /** Identic page mapper |
- | |
138 | * |
- | |
139 | * We need to map whole physical memory identically before the page subsystem |
- | |
140 | * is initializaed. This thing clears page table and fills in the specific |
- | |
141 | * items. |
- | |
142 | */ |
- | |
143 | void ident_page_fault(int n, istate_t *istate) |
- | |
144 | { |
- | |
145 | __address page; |
- | |
146 | static __address oldpage = 0; |
- | |
147 | pte_t *aptl_1, *aptl_2, *aptl_3; |
- | |
148 | - | ||
149 | page = read_cr2(); |
- | |
150 | if (oldpage) { |
- | |
151 | /* Unmap old address */ |
- | |
152 | aptl_1 = PTL1_ADDR(&ptl_0, oldpage); |
- | |
153 | aptl_2 = PTL2_ADDR(aptl_1, oldpage); |
- | |
154 | aptl_3 = PTL3_ADDR(aptl_2, oldpage); |
- | |
155 | - | ||
156 | SET_FRAME_FLAGS_ARCH(aptl_3, PTL3_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT); |
- | |
157 | if (aptl_3 == helper_ptl3) |
- | |
158 | SET_PTL3_FLAGS_ARCH(aptl_2, PTL2_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT); |
- | |
159 | if (aptl_2 == helper_ptl2) |
- | |
160 | SET_PTL2_FLAGS_ARCH(aptl_1, PTL1_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT); |
- | |
161 | if (aptl_1 == helper_ptl1) |
- | |
162 | SET_PTL1_FLAGS_ARCH(&ptl_0, PTL0_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT); |
- | |
163 | } |
- | |
164 | if (PTL1_PRESENT(&ptl_0, page)) |
- | |
165 | aptl_1 = PTL1_ADDR(&ptl_0, page); |
- | |
166 | else { |
- | |
167 | SETUP_PTL1(&ptl_0, page, helper_ptl1); |
- | |
168 | aptl_1 = helper_ptl1; |
- | |
169 | } |
- | |
170 | - | ||
171 | if (PTL2_PRESENT(aptl_1, page)) |
- | |
172 | aptl_2 = PTL2_ADDR(aptl_1, page); |
- | |
173 | else { |
- | |
174 | SETUP_PTL2(aptl_1, page, helper_ptl2); |
- | |
175 | aptl_2 = helper_ptl2; |
- | |
176 | } |
- | |
177 | - | ||
178 | if (PTL3_PRESENT(aptl_2, page)) |
- | |
179 | aptl_3 = PTL3_ADDR(aptl_2, page); |
- | |
180 | else { |
- | |
181 | SETUP_PTL3(aptl_2, page, helper_ptl3); |
- | |
182 | aptl_3 = helper_ptl3; |
- | |
183 | } |
- | |
184 | - | ||
185 | SETUP_FRAME(aptl_3, page, page); |
- | |
186 | - | ||
187 | oldpage = page; |
- | |
188 | } |
- | |
189 | - | ||
190 | void page_fault(int n, istate_t *istate) |
- | |
191 | { |
- | |
192 | __address page; |
- | |
193 | - | ||
194 | page = read_cr2(); |
- | |
195 | if (!as_page_fault(page)) { |
- | |
196 | print_info_errcode(n, istate); |
- | |
197 | printf("Page fault address: %Q\n", page); |
- | |
198 | panic("page fault\n"); |
- | |
199 | } |
- | |
200 | } |
- | |
201 | 103 | ||
202 | void tlb_shootdown_ipi(int n, istate_t *istate) |
104 | void tlb_shootdown_ipi(int n, istate_t *istate) |
203 | { |
105 | { |
204 | trap_virtual_eoi(); |
106 | trap_virtual_eoi(); |
205 | tlb_shootdown_ipi_recv(); |
107 | tlb_shootdown_ipi_recv(); |
206 | } |
108 | } |
207 | 109 | ||
208 | void trap_virtual_enable_irqs(__u16 irqmask) |
110 | void trap_virtual_enable_irqs(__u16 irqmask) |
209 | { |
111 | { |
210 | if (enable_irqs_function) |
112 | if (enable_irqs_function) |
211 | enable_irqs_function(irqmask); |
113 | enable_irqs_function(irqmask); |
212 | else |
114 | else |
213 | panic("no enable_irqs_function\n"); |
115 | panic("no enable_irqs_function\n"); |
214 | } |
116 | } |
215 | 117 | ||
216 | void trap_virtual_disable_irqs(__u16 irqmask) |
118 | void trap_virtual_disable_irqs(__u16 irqmask) |
217 | { |
119 | { |
218 | if (disable_irqs_function) |
120 | if (disable_irqs_function) |
219 | disable_irqs_function(irqmask); |
121 | disable_irqs_function(irqmask); |
220 | else |
122 | else |
221 | panic("no disable_irqs_function\n"); |
123 | panic("no disable_irqs_function\n"); |
222 | } |
124 | } |
223 | 125 | ||
224 | void trap_virtual_eoi(void) |
126 | void trap_virtual_eoi(void) |
225 | { |
127 | { |
226 | if (eoi_function) |
128 | if (eoi_function) |
227 | eoi_function(); |
129 | eoi_function(); |
228 | else |
130 | else |
229 | panic("no eoi_function\n"); |
131 | panic("no eoi_function\n"); |
230 | 132 | ||
231 | } |
133 | } |
232 | 134 |