Rev 955 | Rev 959 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 955 | Rev 958 | ||
---|---|---|---|
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 | #define PRINT_INFO_ERRCODE(st) { \ |
52 | #define PRINT_INFO_ERRCODE(istate) do { \ |
53 | __native *x = (__native *) st; \ |
- | |
54 | char *symbol = get_symtab_entry(x[1]); \ |
53 | char *symbol = get_symtab_entry(istate->eip); \ |
55 | if (!symbol) \ |
54 | if (!symbol) \ |
56 | symbol = ""; \ |
55 | symbol = ""; \ |
57 | printf("----------------EXCEPTION OCCURED----------------\n"); \ |
56 | printf("----------------EXCEPTION OCCURED----------------\n"); \ |
58 | printf("%%eip: %X (%s)\n",x[1],symbol); \ |
57 | printf("%%eip: %X (%s)\n",istate->eip,symbol); \ |
59 | printf("ERROR_WORD=%X\n", x[0]); \ |
58 | printf("ERROR_WORD=%X\n", istate->error_word); \ |
60 | printf("%%cs=%X,flags=%X\n", x[2], x[3]); \ |
59 | printf("%%cs=%X,flags=%X\n", istate->cs, istate->eflags); \ |
61 | printf("%%eax=%X, %%ebx=%X, %%ecx=%X, %%edx=%X\n",\ |
60 | printf("%%eax=%X, %%ebx=%X, %%ecx=%X, %%edx=%X\n",\ |
62 | x[-2],x[-5],x[-3],x[-4]); \ |
61 | istate->eax,istate->ebx,istate->ecx,istate->edx); \ |
63 | printf("%%esi=%X, %%edi=%X, %%ebp=%X, %%esp=%X\n",\ |
62 | printf("%%esi=%X, %%edi=%X, %%ebp=%X, %%esp=%X\n",\ |
64 | x[-8],x[-9],x[-1],x); \ |
63 | istate->esi,istate->edi,istate->ebp,istate->esp); \ |
65 | printf("stack: %X, %X, %X, %X\n", x[4], x[5], x[6], x[7]); \ |
64 | printf("stack: %X, %X, %X, %X\n", istate->stack[0], istate->stack[1], istate->stack[2], istate->stack[3]); \ |
66 | printf(" %X, %X, %X, %X\n", x[8], x[9], x[10], x[11]); \ |
65 | printf(" %X, %X, %X, %X\n", istate->stack[4], istate->stack[5], istate->stack[6], istate->stack[7]); \ |
67 | } |
66 | } while(0) |
68 | 67 | ||
69 | void null_interrupt(int n, void *st) |
68 | void null_interrupt(int n, istate_t *istate) |
70 | { |
69 | { |
71 | __native *stack = (__native *) st; |
70 | PRINT_INFO_ERRCODE(istate); |
72 | - | ||
73 | printf("int %d: null_interrupt\n", n); |
- | |
74 | printf("stack: %L, %L, %L, %L\n", stack[0], stack[1], stack[2], stack[3]); |
- | |
75 | panic("unserviced interrupt\n"); |
71 | panic("unserviced interrupt: %d\n", n); |
76 | } |
72 | } |
77 | 73 | ||
78 | void gp_fault(int n, void *stack) |
74 | void gp_fault(int n, istate_t *istate) |
79 | { |
75 | { |
80 | PRINT_INFO_ERRCODE(stack); |
76 | PRINT_INFO_ERRCODE(istate); |
81 | panic("general protection fault\n"); |
77 | panic("general protection fault\n"); |
82 | } |
78 | } |
83 | 79 | ||
84 | void ss_fault(int n, void *stack) |
80 | void ss_fault(int n, istate_t *istate) |
85 | { |
81 | { |
86 | PRINT_INFO_ERRCODE(stack); |
82 | PRINT_INFO_ERRCODE(istate); |
87 | panic("stack fault\n"); |
83 | panic("stack fault\n"); |
88 | } |
84 | } |
89 | 85 | ||
90 | - | ||
91 | void nm_fault(int n, void *stack) |
86 | void nm_fault(int n, istate_t *istate) |
92 | { |
87 | { |
93 | #ifdef CONFIG_FPU_LAZY |
88 | #ifdef CONFIG_FPU_LAZY |
94 | scheduler_fpu_lazy_request(); |
89 | scheduler_fpu_lazy_request(); |
95 | #else |
90 | #else |
96 | panic("fpu fault"); |
91 | panic("fpu fault"); |
97 | #endif |
92 | #endif |
98 | } |
93 | } |
99 | 94 | ||
100 | - | ||
101 | - | ||
102 | void page_fault(int n, void *stack) |
95 | void page_fault(int n, istate_t *istate) |
103 | { |
96 | { |
104 | __address page; |
97 | __address page; |
105 | 98 | ||
106 | page = read_cr2(); |
99 | page = read_cr2(); |
107 | if (!as_page_fault(page)) { |
100 | if (!as_page_fault(page)) { |
108 | PRINT_INFO_ERRCODE(stack); |
101 | PRINT_INFO_ERRCODE(istate); |
109 | printf("page fault address: %X\n", page); |
102 | printf("page fault address: %X\n", page); |
110 | panic("page fault\n"); |
103 | panic("page fault\n"); |
111 | } |
104 | } |
112 | } |
105 | } |
113 | 106 | ||
114 | void syscall(int n, void *st) |
107 | void syscall(int n, istate_t *istate) |
115 | { |
108 | { |
116 | __native *stack = (__native *) st; |
- | |
117 | - | ||
118 | interrupts_enable(); |
109 | interrupts_enable(); |
119 | if (stack[-2] < SYSCALL_END) |
110 | if (istate->edx < SYSCALL_END) |
120 | stack[-2] = syscall_table[stack[-2]](stack[-5], stack[-3], stack[-4]); |
111 | istate->eax = syscall_table[istate->edx](istate->eax, istate->ebx, istate->ecx); |
121 | else |
112 | else |
122 | panic("Undefined syscall %d", stack[-2]); |
113 | panic("Undefined syscall %d", istate->edx); |
123 | interrupts_disable(); |
114 | interrupts_disable(); |
124 | } |
115 | } |
125 | 116 | ||
126 | void tlb_shootdown_ipi(int n, void *stack) |
117 | void tlb_shootdown_ipi(int n, istate_t *istate) |
127 | { |
118 | { |
128 | trap_virtual_eoi(); |
119 | trap_virtual_eoi(); |
129 | tlb_shootdown_ipi_recv(); |
120 | tlb_shootdown_ipi_recv(); |
130 | } |
121 | } |
131 | 122 | ||
132 | void trap_virtual_enable_irqs(__u16 irqmask) |
123 | void trap_virtual_enable_irqs(__u16 irqmask) |
133 | { |
124 | { |
134 | if (enable_irqs_function) |
125 | if (enable_irqs_function) |
135 | enable_irqs_function(irqmask); |
126 | enable_irqs_function(irqmask); |
136 | else |
127 | else |
137 | panic("no enable_irqs_function\n"); |
128 | panic("no enable_irqs_function\n"); |
138 | } |
129 | } |
139 | 130 | ||
140 | void trap_virtual_disable_irqs(__u16 irqmask) |
131 | void trap_virtual_disable_irqs(__u16 irqmask) |
141 | { |
132 | { |
142 | if (disable_irqs_function) |
133 | if (disable_irqs_function) |
143 | disable_irqs_function(irqmask); |
134 | disable_irqs_function(irqmask); |
144 | else |
135 | else |
145 | panic("no disable_irqs_function\n"); |
136 | panic("no disable_irqs_function\n"); |
146 | } |
137 | } |
147 | 138 | ||
148 | void trap_virtual_eoi(void) |
139 | void trap_virtual_eoi(void) |
149 | { |
140 | { |
150 | if (eoi_function) |
141 | if (eoi_function) |
151 | eoi_function(); |
142 | eoi_function(); |
152 | else |
143 | else |
153 | panic("no eoi_function\n"); |
144 | panic("no eoi_function\n"); |
154 | 145 | ||
155 | } |
146 | } |
156 | 147 |