Rev 3022 | Rev 4156 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2007 Petr Stepan |
2 | * Copyright (c) 2007 Petr Stepan |
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 | /** @addtogroup arm32 |
29 | /** @addtogroup arm32 |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | * @brief Exception handlers and exception initialization routines. |
33 | * @brief Exception handlers and exception initialization routines. |
34 | */ |
34 | */ |
35 | 35 | ||
36 | #include <arch/exception.h> |
36 | #include <arch/exception.h> |
37 | #include <arch/debug/print.h> |
37 | #include <arch/debug/print.h> |
38 | #include <arch/memstr.h> |
38 | #include <arch/memstr.h> |
39 | #include <arch/regutils.h> |
39 | #include <arch/regutils.h> |
40 | #include <interrupt.h> |
40 | #include <interrupt.h> |
41 | #include <arch/machine.h> |
41 | #include <arch/machine.h> |
42 | #include <arch/mm/page_fault.h> |
42 | #include <arch/mm/page_fault.h> |
- | 43 | #include <arch/barrier.h> |
|
43 | #include <print.h> |
44 | #include <print.h> |
44 | #include <syscall/syscall.h> |
45 | #include <syscall/syscall.h> |
45 | 46 | ||
46 | /** Offset used in calculation of exception handler's relative address. |
47 | /** Offset used in calculation of exception handler's relative address. |
47 | * |
48 | * |
48 | * @see install_handler() |
49 | * @see install_handler() |
49 | */ |
50 | */ |
50 | #define PREFETCH_OFFSET 0x8 |
51 | #define PREFETCH_OFFSET 0x8 |
51 | 52 | ||
52 | /** LDR instruction's code */ |
53 | /** LDR instruction's code */ |
53 | #define LDR_OPCODE 0xe59ff000 |
54 | #define LDR_OPCODE 0xe59ff000 |
54 | 55 | ||
55 | /** Number of exception vectors. */ |
56 | /** Number of exception vectors. */ |
56 | #define EXC_VECTORS 8 |
57 | #define EXC_VECTORS 8 |
57 | 58 | ||
58 | /** Size of memory block occupied by exception vectors. */ |
59 | /** Size of memory block occupied by exception vectors. */ |
59 | #define EXC_VECTORS_SIZE (EXC_VECTORS * 4) |
60 | #define EXC_VECTORS_SIZE (EXC_VECTORS * 4) |
60 | 61 | ||
61 | /** Switches to kernel stack and saves all registers there. |
62 | /** Switches to kernel stack and saves all registers there. |
62 | * |
63 | * |
63 | * Temporary exception stack is used to save a few registers |
64 | * Temporary exception stack is used to save a few registers |
64 | * before stack switch takes place. |
65 | * before stack switch takes place. |
- | 66 | * |
|
65 | */ |
67 | */ |
66 | inline static void setup_stack_and_save_regs() |
68 | inline static void setup_stack_and_save_regs() |
67 | { |
69 | { |
68 | asm volatile( |
70 | asm volatile ( |
69 | "ldr r13, =exc_stack \n" |
71 | "ldr r13, =exc_stack\n" |
70 | "stmfd r13!, {r0} \n" |
72 | "stmfd r13!, {r0}\n" |
71 | "mrs r0, spsr \n" |
73 | "mrs r0, spsr\n" |
72 | "and r0, r0, #0x1f \n" |
74 | "and r0, r0, #0x1f\n" |
73 | "cmp r0, #0x10 \n" |
75 | "cmp r0, #0x10\n" |
74 | "bne 1f \n" |
76 | "bne 1f\n" |
75 | 77 | ||
76 | /* prev mode was usermode */ |
78 | /* prev mode was usermode */ |
77 | "ldmfd r13!, {r0} \n" |
79 | "ldmfd r13!, {r0}\n" |
78 | "ldr r13, =supervisor_sp \n" |
80 | "ldr r13, =supervisor_sp\n" |
79 | "ldr r13, [r13] \n" |
81 | "ldr r13, [r13]\n" |
80 | "stmfd r13!, {lr} \n" |
82 | "stmfd r13!, {lr}\n" |
81 | "stmfd r13!, {r0-r12} \n" |
83 | "stmfd r13!, {r0-r12}\n" |
82 | "stmfd r13!, {r13, lr}^ \n" |
84 | "stmfd r13!, {r13, lr}^\n" |
83 | "mrs r0, spsr \n" |
85 | "mrs r0, spsr\n" |
84 | "stmfd r13!, {r0} \n" |
86 | "stmfd r13!, {r0}\n" |
85 | "b 2f \n" |
87 | "b 2f\n" |
86 | 88 | ||
87 | /* mode was not usermode */ |
89 | /* mode was not usermode */ |
88 | "1:\n" |
90 | "1:\n" |
89 | "stmfd r13!, {r1, r2, r3} \n" |
91 | "stmfd r13!, {r1, r2, r3}\n" |
90 | "mrs r1, cpsr \n" |
92 | "mrs r1, cpsr\n" |
91 | "mov r2, lr \n" |
93 | "mov r2, lr\n" |
92 | "bic r1, r1, #0x1f \n" |
94 | "bic r1, r1, #0x1f\n" |
93 | "orr r1, r1, r0 \n" |
95 | "orr r1, r1, r0\n" |
94 | "mrs r0, cpsr \n" |
96 | "mrs r0, cpsr\n" |
95 | "msr cpsr_c, r1 \n" |
97 | "msr cpsr_c, r1\n" |
96 | 98 | ||
97 | "mov r3, r13 \n" |
99 | "mov r3, r13\n" |
98 | "stmfd r13!, {r2} \n" |
100 | "stmfd r13!, {r2}\n" |
99 | "mov r2, lr \n" |
101 | "mov r2, lr\n" |
100 | "stmfd r13!, {r4-r12} \n" |
102 | "stmfd r13!, {r4-r12}\n" |
101 | "mov r1, r13 \n" |
103 | "mov r1, r13\n" |
- | 104 | ||
102 | /* the following two lines are for debugging */ |
105 | /* the following two lines are for debugging */ |
103 | "mov sp, #0 \n" |
106 | "mov sp, #0\n" |
104 | "mov lr, #0 \n" |
107 | "mov lr, #0\n" |
105 | "msr cpsr_c, r0 \n" |
108 | "msr cpsr_c, r0\n" |
106 | 109 | ||
107 | "ldmfd r13!, {r4, r5, r6, r7} \n" |
110 | "ldmfd r13!, {r4, r5, r6, r7}\n" |
108 | "stmfd r1!, {r4, r5, r6} \n" |
111 | "stmfd r1!, {r4, r5, r6}\n" |
109 | "stmfd r1!, {r7} \n" |
112 | "stmfd r1!, {r7}\n" |
110 | "stmfd r1!, {r2} \n" |
113 | "stmfd r1!, {r2}\n" |
111 | "stmfd r1!, {r3} \n" |
114 | "stmfd r1!, {r3}\n" |
112 | "mrs r0, spsr \n" |
115 | "mrs r0, spsr\n" |
113 | "stmfd r1!, {r0} \n" |
116 | "stmfd r1!, {r0}\n" |
114 | "mov r13, r1 \n" |
117 | "mov r13, r1\n" |
- | 118 | ||
115 | "2:\n" |
119 | "2:\n" |
116 | ); |
120 | ); |
117 | } |
121 | } |
118 | 122 | ||
119 | /** Returns from exception mode. |
123 | /** Returns from exception mode. |
120 | * |
124 | * |
121 | * Previously saved state of registers (including control register) |
125 | * Previously saved state of registers (including control register) |
122 | * is restored from the stack. |
126 | * is restored from the stack. |
123 | */ |
127 | */ |
124 | inline static void load_regs() |
128 | inline static void load_regs() |
125 | { |
129 | { |
126 | asm volatile( |
130 | asm volatile( |
127 | "ldmfd r13!, {r0} \n" |
131 | "ldmfd r13!, {r0} \n" |
128 | "msr spsr, r0 \n" |
132 | "msr spsr, r0 \n" |
129 | "and r0, r0, #0x1f \n" |
133 | "and r0, r0, #0x1f \n" |
130 | "cmp r0, #0x10 \n" |
134 | "cmp r0, #0x10 \n" |
131 | "bne 1f \n" |
135 | "bne 1f \n" |
132 | 136 | ||
133 | /* return to user mode */ |
137 | /* return to user mode */ |
134 | "ldmfd r13!, {r13, lr}^ \n" |
138 | "ldmfd r13!, {r13, lr}^ \n" |
135 | "b 2f \n" |
139 | "b 2f \n" |
136 | 140 | ||
137 | /* return to non-user mode */ |
141 | /* return to non-user mode */ |
138 | "1:\n" |
142 | "1:\n" |
139 | "ldmfd r13!, {r1, r2} \n" |
143 | "ldmfd r13!, {r1, r2} \n" |
140 | "mrs r3, cpsr \n" |
144 | "mrs r3, cpsr \n" |
141 | "bic r3, r3, #0x1f \n" |
145 | "bic r3, r3, #0x1f \n" |
142 | "orr r3, r3, r0 \n" |
146 | "orr r3, r3, r0 \n" |
143 | "mrs r0, cpsr \n" |
147 | "mrs r0, cpsr \n" |
144 | "msr cpsr_c, r3 \n" |
148 | "msr cpsr_c, r3 \n" |
145 | 149 | ||
146 | "mov r13, r1 \n" |
150 | "mov r13, r1 \n" |
147 | "mov lr, r2 \n" |
151 | "mov lr, r2 \n" |
148 | "msr cpsr_c, r0 \n" |
152 | "msr cpsr_c, r0 \n" |
149 | 153 | ||
150 | /* actual return */ |
154 | /* actual return */ |
151 | "2:\n" |
155 | "2:\n" |
152 | "ldmfd r13, {r0-r12, pc}^\n" |
156 | "ldmfd r13, {r0-r12, pc}^\n" |
153 | ); |
157 | ); |
154 | } |
158 | } |
155 | 159 | ||
156 | 160 | ||
157 | /** Switch CPU to mode in which interrupts are serviced (currently it |
161 | /** Switch CPU to mode in which interrupts are serviced (currently it |
158 | * is Undefined mode). |
162 | * is Undefined mode). |
159 | * |
163 | * |
160 | * The default mode for interrupt servicing (Interrupt Mode) |
164 | * The default mode for interrupt servicing (Interrupt Mode) |
161 | * can not be used because of nested interrupts (which can occur |
165 | * can not be used because of nested interrupts (which can occur |
162 | * because interrupts are enabled in higher levels of interrupt handler). |
166 | * because interrupts are enabled in higher levels of interrupt handler). |
163 | */ |
167 | */ |
164 | inline static void switch_to_irq_servicing_mode() |
168 | inline static void switch_to_irq_servicing_mode() |
165 | { |
169 | { |
166 | /* switch to Undefined mode */ |
170 | /* switch to Undefined mode */ |
167 | asm volatile( |
171 | asm volatile( |
168 | /* save regs used during switching */ |
172 | /* save regs used during switching */ |
169 | "stmfd sp!, {r0-r3} \n" |
173 | "stmfd sp!, {r0-r3} \n" |
170 | 174 | ||
171 | /* save stack pointer and link register to r1, r2 */ |
175 | /* save stack pointer and link register to r1, r2 */ |
172 | "mov r1, sp \n" |
176 | "mov r1, sp \n" |
173 | "mov r2, lr \n" |
177 | "mov r2, lr \n" |
174 | 178 | ||
175 | /* mode switch */ |
179 | /* mode switch */ |
176 | "mrs r0, cpsr \n" |
180 | "mrs r0, cpsr \n" |
177 | "bic r0, r0, #0x1f \n" |
181 | "bic r0, r0, #0x1f \n" |
178 | "orr r0, r0, #0x1b \n" |
182 | "orr r0, r0, #0x1b \n" |
179 | "msr cpsr_c, r0 \n" |
183 | "msr cpsr_c, r0 \n" |
180 | 184 | ||
181 | /* restore saved sp and lr */ |
185 | /* restore saved sp and lr */ |
182 | "mov sp, r1 \n" |
186 | "mov sp, r1 \n" |
183 | "mov lr, r2 \n" |
187 | "mov lr, r2 \n" |
184 | 188 | ||
185 | /* restore original regs */ |
189 | /* restore original regs */ |
186 | "ldmfd sp!, {r0-r3} \n" |
190 | "ldmfd sp!, {r0-r3} \n" |
187 | ); |
191 | ); |
188 | } |
192 | } |
189 | 193 | ||
190 | /** Calls exception dispatch routine. */ |
194 | /** Calls exception dispatch routine. */ |
191 | #define CALL_EXC_DISPATCH(exception) \ |
195 | #define CALL_EXC_DISPATCH(exception) \ |
- | 196 | asm volatile ( \ |
|
192 | asm("mov r0, %0" : : "i" (exception)); \ |
197 | "mov r0, %[exc]\n" \ |
193 | asm("mov r1, r13"); \ |
198 | "mov r1, r13\n" \ |
194 | asm("bl exc_dispatch"); |
199 | "bl exc_dispatch\n" \ |
- | 200 | :: [exc] "i" (exception) \ |
|
- | 201 | );\ |
|
195 | 202 | ||
196 | /** General exception handler. |
203 | /** General exception handler. |
197 | * |
204 | * |
198 | * Stores registers, dispatches the exception, |
205 | * Stores registers, dispatches the exception, |
199 | * and finally restores registers and returns from exception processing. |
206 | * and finally restores registers and returns from exception processing. |
200 | * |
207 | * |
201 | * @param exception Exception number. |
208 | * @param exception Exception number. |
202 | */ |
209 | */ |
203 | #define PROCESS_EXCEPTION(exception) \ |
210 | #define PROCESS_EXCEPTION(exception) \ |
204 | setup_stack_and_save_regs(); \ |
211 | setup_stack_and_save_regs(); \ |
205 | CALL_EXC_DISPATCH(exception) \ |
212 | CALL_EXC_DISPATCH(exception) \ |
206 | load_regs(); |
213 | load_regs(); |
207 | 214 | ||
208 | /** Updates specified exception vector to jump to given handler. |
215 | /** Updates specified exception vector to jump to given handler. |
209 | * |
216 | * |
210 | * Addresses of handlers are stored in memory following exception vectors. |
217 | * Addresses of handlers are stored in memory following exception vectors. |
211 | */ |
218 | */ |
212 | static void install_handler (unsigned handler_addr, unsigned* vector) |
219 | static void install_handler(unsigned handler_addr, unsigned *vector) |
213 | { |
220 | { |
214 | /* relative address (related to exc. vector) of the word |
221 | /* relative address (related to exc. vector) of the word |
215 | * where handler's address is stored |
222 | * where handler's address is stored |
216 | */ |
223 | */ |
217 | volatile uint32_t handler_address_ptr = EXC_VECTORS_SIZE - |
224 | volatile uint32_t handler_address_ptr = EXC_VECTORS_SIZE - |
218 | PREFETCH_OFFSET; |
225 | PREFETCH_OFFSET; |
219 | 226 | ||
220 | /* make it LDR instruction and store at exception vector */ |
227 | /* make it LDR instruction and store at exception vector */ |
221 | *vector = handler_address_ptr | LDR_OPCODE; |
228 | *vector = handler_address_ptr | LDR_OPCODE; |
- | 229 | smc_coherence(*vector); |
|
222 | 230 | ||
223 | /* store handler's address */ |
231 | /* store handler's address */ |
224 | *(vector + EXC_VECTORS) = handler_addr; |
232 | *(vector + EXC_VECTORS) = handler_addr; |
225 | 233 | ||
226 | } |
234 | } |
227 | 235 | ||
228 | /** Low-level Reset Exception handler. */ |
236 | /** Low-level Reset Exception handler. */ |
229 | static void reset_exception_entry() |
237 | static void reset_exception_entry(void) |
230 | { |
238 | { |
231 | PROCESS_EXCEPTION(EXC_RESET); |
239 | PROCESS_EXCEPTION(EXC_RESET); |
232 | } |
240 | } |
233 | 241 | ||
234 | /** Low-level Software Interrupt Exception handler. */ |
242 | /** Low-level Software Interrupt Exception handler. */ |
235 | static void swi_exception_entry() |
243 | static void swi_exception_entry(void) |
236 | { |
244 | { |
237 | PROCESS_EXCEPTION(EXC_SWI); |
245 | PROCESS_EXCEPTION(EXC_SWI); |
238 | } |
246 | } |
239 | 247 | ||
240 | /** Low-level Undefined Instruction Exception handler. */ |
248 | /** Low-level Undefined Instruction Exception handler. */ |
241 | static void undef_instr_exception_entry() |
249 | static void undef_instr_exception_entry(void) |
242 | { |
250 | { |
243 | PROCESS_EXCEPTION(EXC_UNDEF_INSTR); |
251 | PROCESS_EXCEPTION(EXC_UNDEF_INSTR); |
244 | } |
252 | } |
245 | 253 | ||
246 | /** Low-level Fast Interrupt Exception handler. */ |
254 | /** Low-level Fast Interrupt Exception handler. */ |
247 | static void fiq_exception_entry() |
255 | static void fiq_exception_entry(void) |
248 | { |
256 | { |
249 | PROCESS_EXCEPTION(EXC_FIQ); |
257 | PROCESS_EXCEPTION(EXC_FIQ); |
250 | } |
258 | } |
251 | 259 | ||
252 | /** Low-level Prefetch Abort Exception handler. */ |
260 | /** Low-level Prefetch Abort Exception handler. */ |
253 | static void prefetch_abort_exception_entry() |
261 | static void prefetch_abort_exception_entry(void) |
254 | { |
262 | { |
255 | asm("sub lr, lr, #4"); |
263 | asm("sub lr, lr, #4"); |
256 | PROCESS_EXCEPTION(EXC_PREFETCH_ABORT); |
264 | PROCESS_EXCEPTION(EXC_PREFETCH_ABORT); |
257 | } |
265 | } |
258 | 266 | ||
259 | /** Low-level Data Abort Exception handler. */ |
267 | /** Low-level Data Abort Exception handler. */ |
260 | static void data_abort_exception_entry() |
268 | static void data_abort_exception_entry(void) |
261 | { |
269 | { |
262 | asm("sub lr, lr, #8"); |
270 | asm("sub lr, lr, #8"); |
263 | PROCESS_EXCEPTION(EXC_DATA_ABORT); |
271 | PROCESS_EXCEPTION(EXC_DATA_ABORT); |
264 | } |
272 | } |
265 | 273 | ||
266 | /** Low-level Interrupt Exception handler. |
274 | /** Low-level Interrupt Exception handler. |
267 | * |
275 | * |
268 | * CPU is switched to Undefined mode before further interrupt processing |
276 | * CPU is switched to Undefined mode before further interrupt processing |
269 | * because of possible occurence of nested interrupt exception, which |
277 | * because of possible occurence of nested interrupt exception, which |
270 | * would overwrite (and thus spoil) stack pointer. |
278 | * would overwrite (and thus spoil) stack pointer. |
271 | */ |
279 | */ |
272 | static void irq_exception_entry() |
280 | static void irq_exception_entry(void) |
273 | { |
281 | { |
274 | asm("sub lr, lr, #4"); |
282 | asm("sub lr, lr, #4"); |
275 | setup_stack_and_save_regs(); |
283 | setup_stack_and_save_regs(); |
276 | 284 | ||
277 | switch_to_irq_servicing_mode(); |
285 | switch_to_irq_servicing_mode(); |
278 | 286 | ||
279 | CALL_EXC_DISPATCH(EXC_IRQ) |
287 | CALL_EXC_DISPATCH(EXC_IRQ) |
280 | 288 | ||
281 | load_regs(); |
289 | load_regs(); |
282 | } |
290 | } |
283 | 291 | ||
284 | /** Software Interrupt handler. |
292 | /** Software Interrupt handler. |
285 | * |
293 | * |
286 | * Dispatches the syscall. |
294 | * Dispatches the syscall. |
287 | */ |
295 | */ |
288 | static void swi_exception(int exc_no, istate_t *istate) |
296 | static void swi_exception(int exc_no, istate_t *istate) |
289 | { |
297 | { |
290 | istate->r0 = syscall_handler(istate->r0, istate->r1, istate->r2, |
298 | istate->r0 = syscall_handler(istate->r0, istate->r1, istate->r2, |
291 | istate->r3, istate->r4, istate->r5, istate->r6); |
299 | istate->r3, istate->r4, istate->r5, istate->r6); |
292 | } |
300 | } |
293 | 301 | ||
294 | /** Interrupt Exception handler. |
302 | /** Interrupt Exception handler. |
295 | * |
303 | * |
296 | * Determines the sources of interrupt and calls their handlers. |
304 | * Determines the sources of interrupt and calls their handlers. |
297 | */ |
305 | */ |
298 | static void irq_exception(int exc_no, istate_t *istate) |
306 | static void irq_exception(int exc_no, istate_t *istate) |
299 | { |
307 | { |
300 | machine_irq_exception(exc_no, istate); |
308 | machine_irq_exception(exc_no, istate); |
301 | } |
309 | } |
302 | 310 | ||
303 | /** Fills exception vectors with appropriate exception handlers. */ |
311 | /** Fills exception vectors with appropriate exception handlers. */ |
304 | void install_exception_handlers(void) |
312 | void install_exception_handlers(void) |
305 | { |
313 | { |
306 | install_handler((unsigned) reset_exception_entry, |
314 | install_handler((unsigned) reset_exception_entry, |
307 | (unsigned *) EXC_RESET_VEC); |
315 | (unsigned *) EXC_RESET_VEC); |
308 | 316 | ||
309 | install_handler((unsigned) undef_instr_exception_entry, |
317 | install_handler((unsigned) undef_instr_exception_entry, |
310 | (unsigned *) EXC_UNDEF_INSTR_VEC); |
318 | (unsigned *) EXC_UNDEF_INSTR_VEC); |
311 | 319 | ||
312 | install_handler((unsigned) swi_exception_entry, |
320 | install_handler((unsigned) swi_exception_entry, |
313 | (unsigned *) EXC_SWI_VEC); |
321 | (unsigned *) EXC_SWI_VEC); |
314 | 322 | ||
315 | install_handler((unsigned) prefetch_abort_exception_entry, |
323 | install_handler((unsigned) prefetch_abort_exception_entry, |
316 | (unsigned *) EXC_PREFETCH_ABORT_VEC); |
324 | (unsigned *) EXC_PREFETCH_ABORT_VEC); |
317 | 325 | ||
318 | install_handler((unsigned) data_abort_exception_entry, |
326 | install_handler((unsigned) data_abort_exception_entry, |
319 | (unsigned *) EXC_DATA_ABORT_VEC); |
327 | (unsigned *) EXC_DATA_ABORT_VEC); |
320 | 328 | ||
321 | install_handler((unsigned) irq_exception_entry, |
329 | install_handler((unsigned) irq_exception_entry, |
322 | (unsigned *) EXC_IRQ_VEC); |
330 | (unsigned *) EXC_IRQ_VEC); |
323 | 331 | ||
324 | install_handler((unsigned)fiq_exception_entry, |
332 | install_handler((unsigned)fiq_exception_entry, |
325 | (unsigned *) EXC_FIQ_VEC); |
333 | (unsigned *) EXC_FIQ_VEC); |
326 | } |
334 | } |
327 | 335 | ||
328 | #ifdef HIGH_EXCEPTION_VECTORS |
336 | #ifdef HIGH_EXCEPTION_VECTORS |
329 | /** Activates use of high exception vectors addresses. */ |
337 | /** Activates use of high exception vectors addresses. */ |
330 | static void high_vectors(void) |
338 | static void high_vectors(void) |
331 | { |
339 | { |
332 | uint32_t control_reg; |
340 | uint32_t control_reg; |
333 | 341 | ||
- | 342 | asm volatile ( |
|
- | 343 | "mrc p15, 0, %[control_reg], c1, c1" |
|
334 | asm volatile("mrc p15, 0, %0, c1, c1" : "=r" (control_reg)); |
344 | : [control_reg] "=r" (control_reg) |
- | 345 | ); |
|
335 | 346 | ||
336 | /* switch on the high vectors bit */ |
347 | /* switch on the high vectors bit */ |
337 | control_reg |= CP15_R1_HIGH_VECTORS_BIT; |
348 | control_reg |= CP15_R1_HIGH_VECTORS_BIT; |
338 | 349 | ||
- | 350 | asm volatile ( |
|
- | 351 | "mcr p15, 0, %[control_reg], c1, c1" |
|
339 | asm volatile("mcr p15, 0, %0, c1, c1" : : "r" (control_reg)); |
352 | :: [control_reg] "r" (control_reg) |
- | 353 | ); |
|
340 | } |
354 | } |
341 | #endif |
355 | #endif |
342 | 356 | ||
343 | /** Initializes exception handling. |
357 | /** Initializes exception handling. |
344 | * |
358 | * |
345 | * Installs low-level exception handlers and then registers |
359 | * Installs low-level exception handlers and then registers |
346 | * exceptions and their handlers to kernel exception dispatcher. |
360 | * exceptions and their handlers to kernel exception dispatcher. |
347 | */ |
361 | */ |
348 | void exception_init(void) |
362 | void exception_init(void) |
349 | { |
363 | { |
350 | #ifdef HIGH_EXCEPTION_VECTORS |
364 | #ifdef HIGH_EXCEPTION_VECTORS |
351 | high_vectors(); |
365 | high_vectors(); |
352 | #endif |
366 | #endif |
353 | install_exception_handlers(); |
367 | install_exception_handlers(); |
354 | 368 | ||
355 | exc_register(EXC_IRQ, "interrupt", (iroutine) irq_exception); |
369 | exc_register(EXC_IRQ, "interrupt", (iroutine) irq_exception); |
356 | exc_register(EXC_PREFETCH_ABORT, "prefetch abort", |
370 | exc_register(EXC_PREFETCH_ABORT, "prefetch abort", |
357 | (iroutine) prefetch_abort); |
371 | (iroutine) prefetch_abort); |
358 | exc_register(EXC_DATA_ABORT, "data abort", (iroutine) data_abort); |
372 | exc_register(EXC_DATA_ABORT, "data abort", (iroutine) data_abort); |
359 | exc_register(EXC_SWI, "software interrupt", (iroutine) swi_exception); |
373 | exc_register(EXC_SWI, "software interrupt", (iroutine) swi_exception); |
360 | } |
374 | } |
361 | 375 | ||
362 | /** Prints #istate_t structure content. |
376 | /** Prints #istate_t structure content. |
363 | * |
377 | * |
364 | * @param istate Structure to be printed. |
378 | * @param istate Structure to be printed. |
365 | */ |
379 | */ |
366 | void print_istate(istate_t *istate) |
380 | void print_istate(istate_t *istate) |
367 | { |
381 | { |
368 | dprintf("istate dump:\n"); |
382 | dprintf("istate dump:\n"); |
369 | 383 | ||
370 | dprintf(" r0: %x r1: %x r2: %x r3: %x\n", |
384 | dprintf(" r0: %x r1: %x r2: %x r3: %x\n", |
371 | istate->r0, istate->r1, istate->r2, istate->r3); |
385 | istate->r0, istate->r1, istate->r2, istate->r3); |
372 | dprintf(" r4: %x r5: %x r6: %x r7: %x\n", |
386 | dprintf(" r4: %x r5: %x r6: %x r7: %x\n", |
373 | istate->r4, istate->r5, istate->r6, istate->r7); |
387 | istate->r4, istate->r5, istate->r6, istate->r7); |
374 | dprintf(" r8: %x r8: %x r10: %x r11: %x\n", |
388 | dprintf(" r8: %x r8: %x r10: %x r11: %x\n", |
375 | istate->r8, istate->r9, istate->r10, istate->r11); |
389 | istate->r8, istate->r9, istate->r10, istate->r11); |
376 | dprintf(" r12: %x sp: %x lr: %x spsr: %x\n", |
390 | dprintf(" r12: %x sp: %x lr: %x spsr: %x\n", |
377 | istate->r12, istate->sp, istate->lr, istate->spsr); |
391 | istate->r12, istate->sp, istate->lr, istate->spsr); |
378 | 392 | ||
379 | dprintf(" pc: %x\n", istate->pc); |
393 | dprintf(" pc: %x\n", istate->pc); |
380 | } |
394 | } |
381 | 395 | ||
382 | /** @} |
396 | /** @} |
383 | */ |
397 | */ |
384 | 398 |