Rev 609 | Rev 614 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 609 | Rev 610 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2003-2004 Jakub Jermar |
2 | * Copyright (C) 2003-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/exception.h> |
29 | #include <arch/exception.h> |
30 | #include <arch/interrupt.h> |
30 | #include <arch/interrupt.h> |
31 | #include <panic.h> |
31 | #include <panic.h> |
32 | #include <arch/cp0.h> |
32 | #include <arch/cp0.h> |
33 | #include <arch/types.h> |
33 | #include <arch/types.h> |
34 | #include <arch.h> |
34 | #include <arch.h> |
35 | #include <debug.h> |
35 | #include <debug.h> |
36 | #include <proc/thread.h> |
36 | #include <proc/thread.h> |
37 | #include <symtab.h> |
37 | #include <symtab.h> |
38 | #include <print.h> |
38 | #include <print.h> |
39 | #include <interrupt.h> |
39 | #include <interrupt.h> |
40 | #include <func.h> |
40 | #include <func.h> |
41 | #include <console/kconsole.h> |
41 | #include <console/kconsole.h> |
42 | 42 | ||
43 | static char * exctable[] = { |
43 | static char * exctable[] = { |
44 | "Interrupt","TLB Modified","TLB Invalid","TLB Invalid Store", |
44 | "Interrupt","TLB Modified","TLB Invalid","TLB Invalid Store", |
45 | "Address Error - load/instr. fetch", |
45 | "Address Error - load/instr. fetch", |
46 | "Address Error - store", |
46 | "Address Error - store", |
47 | "Bus Error - fetch instruction", |
47 | "Bus Error - fetch instruction", |
48 | "Bus Error - data reference", |
48 | "Bus Error - data reference", |
49 | "Syscall", |
49 | "Syscall", |
50 | "BreakPoint", |
50 | "BreakPoint", |
51 | "Reserved Instruction", |
51 | "Reserved Instruction", |
52 | "Coprocessor Unusable", |
52 | "Coprocessor Unusable", |
53 | "Arithmetic Overflow", |
53 | "Arithmetic Overflow", |
54 | "Trap", |
54 | "Trap", |
55 | "Virtual Coherency - instruction", |
55 | "Virtual Coherency - instruction", |
56 | "Floating Point", |
56 | "Floating Point", |
57 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
57 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
58 | "WatchHi/WatchLo", /* 23 */ |
58 | "WatchHi/WatchLo", /* 23 */ |
59 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
59 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
60 | "Virtual Coherency - data", |
60 | "Virtual Coherency - data", |
61 | }; |
61 | }; |
62 | 62 | ||
63 | static void print_regdump(struct exception_regdump *pstate) |
63 | static void print_regdump(struct exception_regdump *pstate) |
64 | { |
64 | { |
65 | char *pcsymbol = ""; |
65 | char *pcsymbol = ""; |
66 | char *rasymbol = ""; |
66 | char *rasymbol = ""; |
67 | 67 | ||
68 | char *s = get_symtab_entry(pstate->epc); |
68 | char *s = get_symtab_entry(pstate->epc); |
69 | if (s) |
69 | if (s) |
70 | pcsymbol = s; |
70 | pcsymbol = s; |
71 | s = get_symtab_entry(pstate->ra); |
71 | s = get_symtab_entry(pstate->ra); |
72 | if (s) |
72 | if (s) |
73 | rasymbol = s; |
73 | rasymbol = s; |
74 | 74 | ||
75 | printf("PC: %X(%s) RA: %X(%s)\n",pstate->epc,pcsymbol, |
75 | printf("PC: %X(%s) RA: %X(%s)\n",pstate->epc,pcsymbol, |
76 | pstate->ra,rasymbol); |
76 | pstate->ra,rasymbol); |
77 | } |
77 | } |
78 | 78 | ||
79 | static void unhandled_exception(int n, void *data) |
79 | static void unhandled_exception(int n, void *data) |
80 | { |
80 | { |
81 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
81 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
82 | 82 | ||
83 | print_regdump(pstate); |
83 | print_regdump(pstate); |
84 | panic("unhandled exception %s\n", exctable[n]); |
84 | panic("unhandled exception %s\n", exctable[n]); |
85 | } |
85 | } |
86 | 86 | ||
87 | static void breakpoint_exception(int n, void *data) |
87 | static void breakpoint_exception(int n, void *data) |
88 | { |
88 | { |
89 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
89 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
90 | char *symbol = get_symtab_entry(pstate->epc); |
90 | char *symbol = get_symtab_entry(pstate->epc); |
91 | 91 | ||
92 | #ifdef CONFIG_DEBUG |
92 | #ifdef CONFIG_DEBUG |
93 | printf("***Breakpoint %p in %s.\n", pstate->epc, symbol); |
93 | printf("***Breakpoint %p in %s.\n", pstate->epc, symbol); |
94 | printf("***Type 'exit' to exit kconsole.\n"); |
94 | printf("***Type 'exit' to exit kconsole.\n"); |
95 | /* Umm..we should rather set some 'debugstate' here */ |
95 | /* Umm..we should rather set some 'debugstate' here */ |
96 | haltstate = 1; |
96 | haltstate = 1; |
97 | kconsole("debug"); |
97 | kconsole("debug"); |
98 | haltstate = 0; |
98 | haltstate = 0; |
99 | #endif |
99 | #endif |
100 | 100 | ||
101 | /* it is necessary to not re-execute BREAK instruction after |
101 | /* it is necessary to not re-execute BREAK instruction after |
102 | returning from Exception handler |
102 | returning from Exception handler |
103 | (see page 138 in R4000 Manual for more information) */ |
103 | (see page 138 in R4000 Manual for more information) */ |
104 | pstate->epc += 4; |
104 | pstate->epc += 4; |
105 | } |
105 | } |
106 | 106 | ||
107 | static void tlbmod_exception(int n, void *data) |
107 | static void tlbmod_exception(int n, void *data) |
108 | { |
108 | { |
109 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
109 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
110 | tlb_modified(pstate); |
110 | tlb_modified(pstate); |
111 | } |
111 | } |
112 | 112 | ||
113 | static void tlbinv_exception(int n, void *data) |
113 | static void tlbinv_exception(int n, void *data) |
114 | { |
114 | { |
115 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
115 | struct exception_regdump *pstate = (struct exception_regdump *)data; |
116 | tlb_invalid(pstate); |
116 | tlb_invalid(pstate); |
117 | } |
117 | } |
118 | 118 | ||
119 | static void cpuns_exception(int n, void *data) |
119 | static void cpuns_exception(int n, void *data) |
120 | { |
120 | { |
121 | if (cp0_cause_coperr(cp0_cause_read()) == fpu_cop_id) |
121 | if (cp0_cause_coperr(cp0_cause_read()) == fpu_cop_id) |
122 | scheduler_fpu_lazy_request(); |
122 | scheduler_fpu_lazy_request(); |
123 | else |
123 | else |
124 | panic("unhandled Coprocessor Unusable Exception\n"); |
124 | panic("unhandled Coprocessor Unusable Exception\n"); |
125 | } |
125 | } |
126 | 126 | ||
127 | static void interrupt_exception(int n, void *pstate) |
127 | static void interrupt_exception(int n, void *pstate) |
128 | { |
128 | { |
129 | __u32 cause; |
129 | __u32 cause; |
130 | int i; |
130 | int i; |
131 | 131 | ||
132 | /* decode interrupt number and process the interrupt */ |
132 | /* decode interrupt number and process the interrupt */ |
133 | cause = (cp0_cause_read() >> 8) &0xff; |
133 | cause = (cp0_cause_read() >> 8) &0xff; |
134 | 134 | ||
135 | for (i = 0; i < 8; i++) |
135 | for (i = 0; i < 8; i++) |
136 | if (cause & (1 << i)) |
136 | if (cause & (1 << i)) |
137 | exc_dispatch(i+INT_OFFSET, pstate); |
137 | exc_dispatch(i+INT_OFFSET, pstate); |
138 | } |
138 | } |
139 | 139 | ||
140 | 140 | ||
141 | void exception(struct exception_regdump *pstate) |
141 | void exception(struct exception_regdump *pstate) |
142 | { |
142 | { |
143 | int cause; |
143 | int cause; |
144 | int excno; |
144 | int excno; |
145 | __u32 epc_shift = 0; |
- | |
146 | 145 | ||
147 | ASSERT(CPU != NULL); |
146 | ASSERT(CPU != NULL); |
148 | 147 | ||
149 | /* |
148 | /* |
150 | * NOTE ON OPERATION ORDERING |
149 | * NOTE ON OPERATION ORDERING |
151 | * |
150 | * |
152 | * On entry, interrupts_disable() must be called before |
151 | * On entry, interrupts_disable() must be called before |
153 | * exception bit is cleared. |
152 | * exception bit is cleared. |
154 | */ |
153 | */ |
155 | 154 | ||
156 | interrupts_disable(); |
155 | interrupts_disable(); |
157 | cp0_status_write(cp0_status_read() & ~ (cp0_status_exl_exception_bit | |
156 | cp0_status_write(cp0_status_read() & ~ (cp0_status_exl_exception_bit | |
158 | cp0_status_um_bit)); |
157 | cp0_status_um_bit)); |
159 | 158 | ||
160 | /* Save pstate so that the threads can access it */ |
159 | /* Save pstate so that the threads can access it */ |
161 | /* If THREAD->pstate is set, this is nested exception, |
160 | /* If THREAD->pstate is set, this is nested exception, |
162 | * do not rewrite it |
161 | * do not rewrite it |
163 | */ |
162 | */ |
164 | if (THREAD && !THREAD->pstate) |
163 | if (THREAD && !THREAD->pstate) |
165 | THREAD->pstate = pstate; |
164 | THREAD->pstate = pstate; |
166 | 165 | ||
167 | cause = cp0_cause_read(); |
166 | cause = cp0_cause_read(); |
168 | excno = cp0_cause_excno(cause); |
167 | excno = cp0_cause_excno(cause); |
169 | /* Dispatch exception */ |
168 | /* Dispatch exception */ |
170 | exc_dispatch(excno, pstate); |
169 | exc_dispatch(excno, pstate); |
171 | 170 | ||
172 | /* Set to NULL, so that we can still support nested |
171 | /* Set to NULL, so that we can still support nested |
173 | * exceptions |
172 | * exceptions |
174 | * TODO: We should probably set EXL bit before this command, |
173 | * TODO: We should probably set EXL bit before this command, |
175 | * nesting. On the other hand, if some exception occurs between |
174 | * nesting. On the other hand, if some exception occurs between |
176 | * here and ERET, it won't set anything on the pstate anyway. |
175 | * here and ERET, it won't set anything on the pstate anyway. |
177 | */ |
176 | */ |
178 | if (THREAD) |
177 | if (THREAD) |
179 | THREAD->pstate = NULL; |
178 | THREAD->pstate = NULL; |
180 | } |
179 | } |
181 | 180 | ||
182 | void exception_init(void) |
181 | void exception_init(void) |
183 | { |
182 | { |
184 | int i; |
183 | int i; |
185 | 184 | ||
186 | /* Clear exception table */ |
185 | /* Clear exception table */ |
187 | for (i=0;i < IVT_ITEMS; i++) |
186 | for (i=0;i < IVT_ITEMS; i++) |
188 | exc_register(i, "undef", unhandled_exception); |
187 | exc_register(i, "undef", unhandled_exception); |
189 | exc_register(EXC_Bp, "bkpoint", breakpoint_exception); |
188 | exc_register(EXC_Bp, "bkpoint", breakpoint_exception); |
190 | exc_register(EXC_Mod, "tlb_mod", tlbmod_exception); |
189 | exc_register(EXC_Mod, "tlb_mod", tlbmod_exception); |
191 | exc_register(EXC_TLBL, "tlbinvl", tlbinv_exception); |
190 | exc_register(EXC_TLBL, "tlbinvl", tlbinv_exception); |
192 | exc_register(EXC_TLBS, "tlbinvl", tlbinv_exception); |
191 | exc_register(EXC_TLBS, "tlbinvl", tlbinv_exception); |
193 | exc_register(EXC_Int, "interrupt", interrupt_exception); |
192 | exc_register(EXC_Int, "interrupt", interrupt_exception); |
194 | #ifdef CONFIG_FPU_LAZY |
193 | #ifdef CONFIG_FPU_LAZY |
195 | exc_register(EXC_CpU, "cpunus", cpuns_exception); |
194 | exc_register(EXC_CpU, "cpunus", cpuns_exception); |
196 | #endif |
195 | #endif |
197 | } |
196 | } |
198 | 197 |