4 * Copyright (c) 1994-1997 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
8 * This code is derived from software written for Brini by Mark Brinicombe
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Brini.
21 * 4. The name of the company nor the name of the author may be used to
22 * endorse or promote products derived from this software without specific
23 * prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * RiscBSD kernel project
41 * Low level handlers for exception vectors
45 * Based on kate/display/abort.s
49 #include <machine/asm.h>
50 #include <machine/cpu.h>
51 #include <machine/frame.h>
58 AST_ALIGNMENT_FAULT_LOCALS
63 * Handler for Reset exception.
65 ASENTRY_NP(reset_entry)
66 adr r0, Lreset_panicmsg
71 .asciz "Reset vector called, LR = 0x%08x"
77 * Handler for the Software Interrupt exception.
81 ENABLE_ALIGNMENT_FAULTS
83 mov r0, sp /* Pass the frame to any function */
84 bl _C_LABEL(swi_handler) /* It's a SWI ! */
86 DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
88 movs pc, lr /* Exit */
91 * prefetch_abort_entry:
93 * Handler for the Prefetch Abort exception.
95 ASENTRY_NP(prefetch_abort_entry)
97 nop /* Make absolutely sure any pending */
98 nop /* imprecise aborts have occurred. */
100 sub lr, lr, #0x00000004 /* Adjust the lr */
103 ENABLE_ALIGNMENT_FAULTS
105 ldr r1, Lprefetch_abort_handler_address
106 adr lr, exception_exit
107 mov r0, sp /* pass the stack pointer as r0 */
110 Lprefetch_abort_handler_address:
111 .word _C_LABEL(prefetch_abort_handler_address)
114 .global _C_LABEL(prefetch_abort_handler_address)
116 _C_LABEL(prefetch_abort_handler_address):
121 adr r0, abortprefetchmsg
125 .asciz "abortprefetch"
131 * Handler for the Data Abort exception.
133 ASENTRY_NP(data_abort_entry)
135 nop /* Make absolutely sure any pending */
136 nop /* imprecise aborts have occurred. */
138 sub lr, lr, #0x00000008 /* Adjust the lr */
140 PUSHFRAMEINSVC /* Push trap frame and switch */
142 ENABLE_ALIGNMENT_FAULTS
144 ldr r1, Ldata_abort_handler_address
145 adr lr, exception_exit
146 mov r0, sp /* pass the stack pointer as r0 */
149 Ldata_abort_handler_address:
150 .word _C_LABEL(data_abort_handler_address)
153 .global _C_LABEL(data_abort_handler_address)
154 _C_LABEL(data_abort_handler_address):
167 * address_exception_entry:
169 * Handler for the Address Exception exception.
171 * NOTE: This exception isn't really used on arm32. We
172 * print a warning message to the console and then treat
173 * it like a Data Abort.
175 ASENTRY_NP(address_exception_entry)
179 adr r0, Laddress_exception_msg
180 bl _C_LABEL(printf) /* XXX CLOBBERS LR!! */
182 Laddress_exception_msg:
183 .asciz "Address Exception CPSR=0x%08x SPSR=0x%08x LR=0x%08x\n"
187 * General exception exit handler
188 * (Placed here to be within range of all the references to it)
190 * It exits straight away if not returning to USR mode.
191 * This loops around delivering any pending ASTs.
192 * Interrupts are disabled at suitable points to avoid ASTs
193 * being posted between testing and exit to user mode.
195 * This function uses PULLFRAMEFROMSVCANDEXIT and
196 * DO_AST_AND_RESTORE_ALIGNMENT_FAULTS thus should
197 * only be called if the exception handler used PUSHFRAMEINSVC
198 * followed by ENABLE_ALIGNMENT_FAULTS.
202 DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
203 PULLFRAMEFROMSVCANDEXIT
208 * Handler for the Undefined Instruction exception.
210 * We indirect the undefined vector via the handler address
211 * in the data area. Entry to the undefined handler must
212 * look like direct entry from the vector.
214 ASENTRY_NP(undefined_entry)
216 ldr r0, Lundefined_handler_indirection
217 ldr r1, [sp], #0x0004
218 str r1, [r0, #0x0000]
219 ldr r1, [sp], #0x0004
220 str r1, [r0, #0x0004]
221 ldmia r0, {r0, r1, pc}
223 Lundefined_handler_indirection:
224 .word Lundefined_handler_indirection_data
227 * assembly bounce code for calling the kernel
228 * undefined instruction handler. This uses
229 * a standard trap frame and is called in SVC mode.
232 ENTRY_NP(undefinedinstruction_bounce)
234 ENABLE_ALIGNMENT_FAULTS
237 adr lr, exception_exit
238 b _C_LABEL(undefinedinstruction)
245 * 2 words use for preserving r0 and r1
246 * 3rd word contains the undefined handler address.
249 Lundefined_handler_indirection_data:
253 .global _C_LABEL(undefined_handler_address)
254 _C_LABEL(undefined_handler_address):
255 .word _C_LABEL(undefinedinstruction_bounce)