Rev 1196 | Rev 1258 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1196 | Rev 1256 | ||
---|---|---|---|
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 | #include <proc/task.h> |
|
- | 45 | #include <synch/spinlock.h> |
|
- | 46 | #include <arch/ddi/ddi.h> |
|
44 | 47 | ||
45 | void print_info_errcode(int n, istate_t *istate) |
48 | void print_info_errcode(int n, istate_t *istate) |
46 | { |
49 | { |
47 | char *symbol; |
50 | char *symbol; |
48 | /* __u64 *x = &istate->stack[0]; */ |
51 | /* __u64 *x = &istate->stack[0]; */ |
49 | 52 | ||
50 | if (!(symbol=get_symtab_entry(istate->rip))) |
53 | if (!(symbol=get_symtab_entry(istate->rip))) |
51 | symbol = ""; |
54 | symbol = ""; |
52 | 55 | ||
53 | printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n, __FUNCTION__); |
56 | printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n, __FUNCTION__); |
54 | printf("%%rip: %#llX (%s)\n",istate->rip, symbol); |
57 | printf("%%rip: %#llX (%s)\n",istate->rip, symbol); |
55 | printf("ERROR_WORD=%#llX\n", istate->error_word); |
58 | printf("ERROR_WORD=%#llX\n", istate->error_word); |
56 | printf("%%rcs=%#llX, flags=%#llX, %%cr0=%#llX\n", istate->cs, istate->rflags,read_cr0()); |
59 | printf("%%rcs=%#llX, flags=%#llX, %%cr0=%#llX\n", istate->cs, istate->rflags,read_cr0()); |
57 | printf("%%rax=%#llX, %%rcx=%#llX, %%rdx=%#llX\n",istate->rax,istate->rcx,istate->rdx); |
60 | printf("%%rax=%#llX, %%rcx=%#llX, %%rdx=%#llX\n",istate->rax,istate->rcx,istate->rdx); |
58 | printf("%%rsi=%#llX, %%rdi=%#llX, %%r8 =%#llX\n",istate->rsi,istate->rdi,istate->r8); |
61 | printf("%%rsi=%#llX, %%rdi=%#llX, %%r8 =%#llX\n",istate->rsi,istate->rdi,istate->r8); |
59 | printf("%%r9 =%#llX, %%r10 =%#llX, %%r11=%#llX\n",istate->r9,istate->r10,istate->r11); |
62 | printf("%%r9 =%#llX, %%r10 =%#llX, %%r11=%#llX\n",istate->r9,istate->r10,istate->r11); |
60 | #ifdef CONFIG_DEBUG_ALLREGS |
63 | #ifdef CONFIG_DEBUG_ALLREGS |
61 | printf("%%r12=%#llX, %%r13=%#llX, %%r14=%#llX\n",istate->r12,istate->r13,istate->r14); |
64 | printf("%%r12=%#llX, %%r13=%#llX, %%r14=%#llX\n",istate->r12,istate->r13,istate->r14); |
62 | printf("%%r15=%#llX, %%rbx=%#llX, %%rbp=%#llX\n",istate->r15,istate->rbx,&istate->rbp); |
65 | printf("%%r15=%#llX, %%rbx=%#llX, %%rbp=%#llX\n",istate->r15,istate->rbx,&istate->rbp); |
63 | #endif |
66 | #endif |
64 | printf("%%rsp=%#llX\n",&istate->stack[0]); |
67 | printf("%%rsp=%#llX\n",&istate->stack[0]); |
65 | } |
68 | } |
66 | 69 | ||
67 | /* |
70 | /* |
68 | * Interrupt and exception dispatching. |
71 | * Interrupt and exception dispatching. |
69 | */ |
72 | */ |
70 | 73 | ||
71 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
74 | void (* disable_irqs_function)(__u16 irqmask) = NULL; |
72 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
75 | void (* enable_irqs_function)(__u16 irqmask) = NULL; |
73 | void (* eoi_function)(void) = NULL; |
76 | void (* eoi_function)(void) = NULL; |
74 | 77 | ||
75 | void null_interrupt(int n, istate_t *istate) |
78 | void null_interrupt(int n, istate_t *istate) |
76 | { |
79 | { |
77 | print_info_errcode(n, istate); |
80 | print_info_errcode(n, istate); |
78 | panic("unserviced interrupt\n"); |
81 | panic("unserviced interrupt\n"); |
79 | } |
82 | } |
80 | 83 | ||
- | 84 | /** General Protection Fault. */ |
|
81 | void gp_fault(int n, istate_t *istate) |
85 | void gp_fault(int n, istate_t *istate) |
82 | { |
86 | { |
- | 87 | if (TASK) { |
|
- | 88 | count_t ver; |
|
- | 89 | ||
- | 90 | spinlock_lock(&TASK->lock); |
|
- | 91 | ver = TASK->arch.iomapver; |
|
- | 92 | spinlock_unlock(&TASK->lock); |
|
- | 93 | ||
- | 94 | if (CPU->arch.iomapver_copy != ver) { |
|
- | 95 | /* |
|
- | 96 | * This fault can be caused by an early access |
|
- | 97 | * to I/O port because of an out-dated |
|
- | 98 | * I/O Permission bitmap installed on CPU. |
|
- | 99 | * Install the fresh copy and restart |
|
- | 100 | * the instruction. |
|
- | 101 | */ |
|
- | 102 | io_perm_bitmap_install(); |
|
- | 103 | return; |
|
- | 104 | } |
|
- | 105 | } |
|
- | 106 | ||
83 | print_info_errcode(n, istate); |
107 | print_info_errcode(n, istate); |
84 | panic("general protection fault\n"); |
108 | panic("general protection fault\n"); |
85 | } |
109 | } |
86 | 110 | ||
87 | void ss_fault(int n, istate_t *istate) |
111 | void ss_fault(int n, istate_t *istate) |
88 | { |
112 | { |
89 | print_info_errcode(n, istate); |
113 | print_info_errcode(n, istate); |
90 | panic("stack fault\n"); |
114 | panic("stack fault\n"); |
91 | } |
115 | } |
92 | 116 | ||
93 | void nm_fault(int n, istate_t *istate) |
117 | void nm_fault(int n, istate_t *istate) |
94 | { |
118 | { |
95 | #ifdef CONFIG_FPU_LAZY |
119 | #ifdef CONFIG_FPU_LAZY |
96 | scheduler_fpu_lazy_request(); |
120 | scheduler_fpu_lazy_request(); |
97 | #else |
121 | #else |
98 | panic("fpu fault"); |
122 | panic("fpu fault"); |
99 | #endif |
123 | #endif |
100 | } |
124 | } |
101 | 125 | ||
102 | void tlb_shootdown_ipi(int n, istate_t *istate) |
126 | void tlb_shootdown_ipi(int n, istate_t *istate) |
103 | { |
127 | { |
104 | trap_virtual_eoi(); |
128 | trap_virtual_eoi(); |
105 | tlb_shootdown_ipi_recv(); |
129 | tlb_shootdown_ipi_recv(); |
106 | } |
130 | } |
107 | 131 | ||
108 | void trap_virtual_enable_irqs(__u16 irqmask) |
132 | void trap_virtual_enable_irqs(__u16 irqmask) |
109 | { |
133 | { |
110 | if (enable_irqs_function) |
134 | if (enable_irqs_function) |
111 | enable_irqs_function(irqmask); |
135 | enable_irqs_function(irqmask); |
112 | else |
136 | else |
113 | panic("no enable_irqs_function\n"); |
137 | panic("no enable_irqs_function\n"); |
114 | } |
138 | } |
115 | 139 | ||
116 | void trap_virtual_disable_irqs(__u16 irqmask) |
140 | void trap_virtual_disable_irqs(__u16 irqmask) |
117 | { |
141 | { |
118 | if (disable_irqs_function) |
142 | if (disable_irqs_function) |
119 | disable_irqs_function(irqmask); |
143 | disable_irqs_function(irqmask); |
120 | else |
144 | else |
121 | panic("no disable_irqs_function\n"); |
145 | panic("no disable_irqs_function\n"); |
122 | } |
146 | } |
123 | 147 | ||
124 | void trap_virtual_eoi(void) |
148 | void trap_virtual_eoi(void) |
125 | { |
149 | { |
126 | if (eoi_function) |
150 | if (eoi_function) |
127 | eoi_function(); |
151 | eoi_function(); |
128 | else |
152 | else |
129 | panic("no eoi_function\n"); |
153 | panic("no eoi_function\n"); |
130 | 154 | ||
131 | } |
155 | } |
132 | 156 |