exception.S revision 1.14.50.1 1 1.14.50.1 chris /* $NetBSD: exception.S,v 1.14.50.1 2008/01/20 16:03:56 chris Exp $ */
2 1.1 chris
3 1.1 chris /*
4 1.1 chris * Copyright (c) 1994-1997 Mark Brinicombe.
5 1.1 chris * Copyright (c) 1994 Brini.
6 1.1 chris * All rights reserved.
7 1.1 chris *
8 1.1 chris * This code is derived from software written for Brini by Mark Brinicombe
9 1.1 chris *
10 1.1 chris * Redistribution and use in source and binary forms, with or without
11 1.1 chris * modification, are permitted provided that the following conditions
12 1.1 chris * are met:
13 1.1 chris * 1. Redistributions of source code must retain the above copyright
14 1.1 chris * notice, this list of conditions and the following disclaimer.
15 1.1 chris * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 chris * notice, this list of conditions and the following disclaimer in the
17 1.1 chris * documentation and/or other materials provided with the distribution.
18 1.1 chris * 3. All advertising materials mentioning features or use of this software
19 1.1 chris * must display the following acknowledgement:
20 1.1 chris * This product includes software developed by Brini.
21 1.1 chris * 4. The name of the company nor the name of the author may be used to
22 1.1 chris * endorse or promote products derived from this software without specific
23 1.1 chris * prior written permission.
24 1.1 chris *
25 1.1 chris * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 1.1 chris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 1.1 chris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 1.1 chris * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 1.1 chris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 1.1 chris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 1.1 chris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 chris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 chris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 chris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 chris * SUCH DAMAGE.
36 1.1 chris *
37 1.1 chris * RiscBSD kernel project
38 1.1 chris *
39 1.1 chris * exception.S
40 1.1 chris *
41 1.1 chris * Low level handlers for exception vectors
42 1.1 chris *
43 1.1 chris * Created : 24/09/94
44 1.1 chris *
45 1.1 chris * Based on kate/display/abort.s
46 1.1 chris */
47 1.1 chris
48 1.1 chris #include <machine/asm.h>
49 1.1 chris #include <machine/cpu.h>
50 1.1 chris #include <machine/frame.h>
51 1.1 chris #include "assym.h"
52 1.1 chris
53 1.1 chris .text
54 1.1 chris .align 0
55 1.1 chris
56 1.12 scw AST_ALIGNMENT_FAULT_LOCALS
57 1.1 chris
58 1.1 chris /*
59 1.3 thorpej * reset_entry:
60 1.3 thorpej *
61 1.3 thorpej * Handler for Reset exception.
62 1.3 thorpej */
63 1.3 thorpej ASENTRY_NP(reset_entry)
64 1.3 thorpej adr r0, Lreset_panicmsg
65 1.3 thorpej mov r1, lr
66 1.3 thorpej bl _C_LABEL(panic)
67 1.3 thorpej /* NOTREACHED */
68 1.3 thorpej Lreset_panicmsg:
69 1.3 thorpej .asciz "Reset vector called, LR = 0x%08x"
70 1.3 thorpej .balign 4
71 1.1 chris
72 1.3 thorpej /*
73 1.3 thorpej * swi_entry
74 1.3 thorpej *
75 1.3 thorpej * Handler for the Software Interrupt exception.
76 1.3 thorpej */
77 1.3 thorpej ASENTRY_NP(swi_entry)
78 1.3 thorpej PUSHFRAME
79 1.9 scw ENABLE_ALIGNMENT_FAULTS
80 1.9 scw
81 1.3 thorpej mov r0, sp /* Pass the frame to any function */
82 1.5 bjh21 bl _C_LABEL(swi_handler) /* It's a SWI ! */
83 1.1 chris
84 1.12 scw DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
85 1.3 thorpej PULLFRAME
86 1.3 thorpej movs pc, lr /* Exit */
87 1.1 chris
88 1.3 thorpej /*
89 1.3 thorpej * prefetch_abort_entry:
90 1.3 thorpej *
91 1.3 thorpej * Handler for the Prefetch Abort exception.
92 1.3 thorpej */
93 1.1 chris ASENTRY_NP(prefetch_abort_entry)
94 1.13 scw #ifdef __XSCALE__
95 1.13 scw nop /* Make absolutely sure any pending */
96 1.13 scw nop /* imprecise aborts have occurred. */
97 1.13 scw #endif
98 1.1 chris sub lr, lr, #0x00000004 /* Adjust the lr */
99 1.1 chris
100 1.1 chris PUSHFRAMEINSVC
101 1.9 scw ENABLE_ALIGNMENT_FAULTS
102 1.9 scw
103 1.12 scw ldr r1, Lprefetch_abort_handler_address
104 1.12 scw adr lr, exception_exit
105 1.1 chris mov r0, sp /* pass the stack pointer as r0 */
106 1.12 scw ldr pc, [r1]
107 1.1 chris
108 1.1 chris Lprefetch_abort_handler_address:
109 1.1 chris .word _C_LABEL(prefetch_abort_handler_address)
110 1.1 chris
111 1.1 chris .data
112 1.1 chris .global _C_LABEL(prefetch_abort_handler_address)
113 1.1 chris
114 1.1 chris _C_LABEL(prefetch_abort_handler_address):
115 1.1 chris .word abortprefetch
116 1.1 chris
117 1.1 chris .text
118 1.1 chris abortprefetch:
119 1.7 bjh21 adr r0, abortprefetchmsg
120 1.1 chris b _C_LABEL(panic)
121 1.1 chris
122 1.1 chris abortprefetchmsg:
123 1.1 chris .asciz "abortprefetch"
124 1.1 chris .align 0
125 1.1 chris
126 1.1 chris /*
127 1.3 thorpej * data_abort_entry:
128 1.1 chris *
129 1.3 thorpej * Handler for the Data Abort exception.
130 1.1 chris */
131 1.3 thorpej ASENTRY_NP(data_abort_entry)
132 1.13 scw #ifdef __XSCALE__
133 1.13 scw nop /* Make absolutely sure any pending */
134 1.13 scw nop /* imprecise aborts have occurred. */
135 1.13 scw #endif
136 1.3 thorpej sub lr, lr, #0x00000008 /* Adjust the lr */
137 1.1 chris
138 1.3 thorpej PUSHFRAMEINSVC /* Push trap frame and switch */
139 1.3 thorpej /* to SVC32 mode */
140 1.9 scw ENABLE_ALIGNMENT_FAULTS
141 1.9 scw
142 1.12 scw ldr r1, Ldata_abort_handler_address
143 1.12 scw adr lr, exception_exit
144 1.3 thorpej mov r0, sp /* pass the stack pointer as r0 */
145 1.3 thorpej ldr pc, [r1]
146 1.1 chris
147 1.3 thorpej Ldata_abort_handler_address:
148 1.3 thorpej .word _C_LABEL(data_abort_handler_address)
149 1.1 chris
150 1.3 thorpej .data
151 1.3 thorpej .global _C_LABEL(data_abort_handler_address)
152 1.3 thorpej _C_LABEL(data_abort_handler_address):
153 1.3 thorpej .word abortdata
154 1.1 chris
155 1.3 thorpej .text
156 1.3 thorpej abortdata:
157 1.7 bjh21 adr r0, abortdatamsg
158 1.3 thorpej b _C_LABEL(panic)
159 1.1 chris
160 1.3 thorpej abortdatamsg:
161 1.3 thorpej .asciz "abortdata"
162 1.3 thorpej .align 0
163 1.1 chris
164 1.3 thorpej /*
165 1.3 thorpej * address_exception_entry:
166 1.3 thorpej *
167 1.3 thorpej * Handler for the Address Exception exception.
168 1.3 thorpej *
169 1.3 thorpej * NOTE: This exception isn't really used on arm32. We
170 1.3 thorpej * print a warning message to the console and then treat
171 1.3 thorpej * it like a Data Abort.
172 1.3 thorpej */
173 1.3 thorpej ASENTRY_NP(address_exception_entry)
174 1.3 thorpej mrs r1, cpsr_all
175 1.3 thorpej mrs r2, spsr_all
176 1.3 thorpej mov r3, lr
177 1.3 thorpej adr r0, Laddress_exception_msg
178 1.3 thorpej bl _C_LABEL(printf) /* XXX CLOBBERS LR!! */
179 1.3 thorpej b data_abort_entry
180 1.3 thorpej Laddress_exception_msg:
181 1.3 thorpej .asciz "Address Exception CPSR=0x%08x SPSR=0x%08x LR=0x%08x\n"
182 1.3 thorpej .balign 4
183 1.13 scw
184 1.13 scw /*
185 1.13 scw * General exception exit handler
186 1.13 scw * (Placed here to be within range of all the references to it)
187 1.13 scw *
188 1.13 scw * It exits straight away if not returning to USR mode.
189 1.13 scw * This loops around delivering any pending ASTs.
190 1.13 scw * Interrupts are disabled at suitable points to avoid ASTs
191 1.13 scw * being posted between testing and exit to user mode.
192 1.13 scw *
193 1.13 scw * This function uses PULLFRAMEFROMSVCANDEXIT and
194 1.13 scw * DO_AST_AND_RESTORE_ALIGNMENT_FAULTS thus should
195 1.13 scw * only be called if the exception handler used PUSHFRAMEINSVC
196 1.13 scw * followed by ENABLE_ALIGNMENT_FAULTS.
197 1.13 scw */
198 1.13 scw
199 1.13 scw exception_exit:
200 1.13 scw DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
201 1.13 scw PULLFRAMEFROMSVCANDEXIT
202 1.1 chris
203 1.1 chris /*
204 1.3 thorpej * undefined_entry:
205 1.3 thorpej *
206 1.3 thorpej * Handler for the Undefined Instruction exception.
207 1.3 thorpej *
208 1.3 thorpej * We indirect the undefined vector via the handler address
209 1.3 thorpej * in the data area. Entry to the undefined handler must
210 1.3 thorpej * look like direct entry from the vector.
211 1.1 chris */
212 1.1 chris ASENTRY_NP(undefined_entry)
213 1.1 chris stmfd sp!, {r0, r1}
214 1.1 chris ldr r0, Lundefined_handler_indirection
215 1.1 chris ldr r1, [sp], #0x0004
216 1.1 chris str r1, [r0, #0x0000]
217 1.1 chris ldr r1, [sp], #0x0004
218 1.1 chris str r1, [r0, #0x0004]
219 1.1 chris ldmia r0, {r0, r1, pc}
220 1.1 chris
221 1.1 chris Lundefined_handler_indirection:
222 1.1 chris .word Lundefined_handler_indirection_data
223 1.1 chris
224 1.1 chris /*
225 1.1 chris * assembly bounce code for calling the kernel
226 1.1 chris * undefined instruction handler. This uses
227 1.1 chris * a standard trap frame and is called in SVC mode.
228 1.1 chris */
229 1.1 chris
230 1.1 chris ENTRY_NP(undefinedinstruction_bounce)
231 1.1 chris PUSHFRAMEINSVC
232 1.9 scw ENABLE_ALIGNMENT_FAULTS
233 1.12 scw
234 1.1 chris mov r0, sp
235 1.12 scw adr lr, exception_exit
236 1.12 scw b _C_LABEL(undefinedinstruction)
237 1.1 chris
238 1.1 chris .data
239 1.1 chris .align 0
240 1.1 chris
241 1.1 chris /*
242 1.1 chris * Indirection data
243 1.1 chris * 2 words use for preserving r0 and r1
244 1.1 chris * 3rd word contains the undefined handler address.
245 1.1 chris */
246 1.1 chris
247 1.1 chris Lundefined_handler_indirection_data:
248 1.1 chris .word 0
249 1.1 chris .word 0
250 1.1 chris
251 1.1 chris .global _C_LABEL(undefined_handler_address)
252 1.1 chris _C_LABEL(undefined_handler_address):
253 1.1 chris .word _C_LABEL(undefinedinstruction_bounce)
254