Home | History | Annotate | Line # | Download | only in arm32
exception.S revision 1.14.50.1
      1 /*	$NetBSD: exception.S,v 1.14.50.1 2008/01/20 16:03:56 chris Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994-1997 Mark Brinicombe.
      5  * Copyright (c) 1994 Brini.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software written for Brini by Mark Brinicombe
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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.
     24  *
     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
     35  * SUCH DAMAGE.
     36  *
     37  * RiscBSD kernel project
     38  *
     39  * exception.S
     40  *
     41  * Low level handlers for exception vectors
     42  *
     43  * Created      : 24/09/94
     44  *
     45  * Based on kate/display/abort.s
     46  */
     47 
     48 #include <machine/asm.h>
     49 #include <machine/cpu.h>
     50 #include <machine/frame.h>
     51 #include "assym.h"
     52 
     53 	.text
     54 	.align	0
     55 
     56 AST_ALIGNMENT_FAULT_LOCALS
     57 
     58 /*
     59  * reset_entry:
     60  *
     61  *	Handler for Reset exception.
     62  */
     63 ASENTRY_NP(reset_entry)
     64 	adr	r0, Lreset_panicmsg
     65 	mov	r1, lr
     66 	bl	_C_LABEL(panic)
     67 	/* NOTREACHED */
     68 Lreset_panicmsg:
     69 	.asciz	"Reset vector called, LR = 0x%08x"
     70 	.balign	4
     71 
     72 /*
     73  * swi_entry
     74  *
     75  *	Handler for the Software Interrupt exception.
     76  */
     77 ASENTRY_NP(swi_entry)
     78 	PUSHFRAME
     79 	ENABLE_ALIGNMENT_FAULTS
     80 
     81 	mov	r0, sp			/* Pass the frame to any function */
     82 	bl	_C_LABEL(swi_handler)	/* It's a SWI ! */
     83 
     84 	DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
     85 	PULLFRAME
     86 	movs	pc, lr			/* Exit */
     87 
     88 /*
     89  * prefetch_abort_entry:
     90  *
     91  *	Handler for the Prefetch Abort exception.
     92  */
     93 ASENTRY_NP(prefetch_abort_entry)
     94 #ifdef __XSCALE__
     95 	nop				/* Make absolutely sure any pending */
     96 	nop				/* imprecise aborts have occurred. */
     97 #endif
     98         sub     lr, lr, #0x00000004     /* Adjust the lr */
     99 
    100 	PUSHFRAMEINSVC
    101 	ENABLE_ALIGNMENT_FAULTS
    102 
    103 	ldr	r1, Lprefetch_abort_handler_address
    104 	adr	lr, exception_exit
    105  	mov	r0, sp			/* pass the stack pointer as r0 */
    106 	ldr	pc, [r1]
    107 
    108 Lprefetch_abort_handler_address:
    109 	.word	_C_LABEL(prefetch_abort_handler_address)
    110 
    111 	.data
    112 	.global	_C_LABEL(prefetch_abort_handler_address)
    113 
    114 _C_LABEL(prefetch_abort_handler_address):
    115 	.word	abortprefetch
    116 
    117 	.text
    118 abortprefetch:
    119         adr     r0, abortprefetchmsg
    120 	b	_C_LABEL(panic)
    121 
    122 abortprefetchmsg:
    123         .asciz  "abortprefetch"
    124         .align  0
    125 
    126 /*
    127  * data_abort_entry:
    128  *
    129  *	Handler for the Data Abort exception.
    130  */
    131 ASENTRY_NP(data_abort_entry)
    132 #ifdef __XSCALE__
    133 	nop				/* Make absolutely sure any pending */
    134 	nop				/* imprecise aborts have occurred. */
    135 #endif
    136         sub     lr, lr, #0x00000008     /* Adjust the lr */
    137 
    138 	PUSHFRAMEINSVC			/* Push trap frame and switch */
    139 					/* to SVC32 mode */
    140 	ENABLE_ALIGNMENT_FAULTS
    141 
    142 	ldr	r1, Ldata_abort_handler_address
    143 	adr	lr, exception_exit
    144 	mov	r0, sp			/* pass the stack pointer as r0 */
    145 	ldr	pc, [r1]
    146 
    147 Ldata_abort_handler_address:
    148 	.word	_C_LABEL(data_abort_handler_address)
    149 
    150 	.data
    151 	.global	_C_LABEL(data_abort_handler_address)
    152 _C_LABEL(data_abort_handler_address):
    153 	.word	abortdata
    154 
    155 	.text
    156 abortdata:
    157         adr     r0, abortdatamsg
    158 	b	_C_LABEL(panic)
    159 
    160 abortdatamsg:
    161         .asciz  "abortdata"
    162         .align  0
    163 
    164 /*
    165  * address_exception_entry:
    166  *
    167  *	Handler for the Address Exception exception.
    168  *
    169  *	NOTE: This exception isn't really used on arm32.  We
    170  *	print a warning message to the console and then treat
    171  *	it like a Data Abort.
    172  */
    173 ASENTRY_NP(address_exception_entry)
    174 	mrs	r1, cpsr_all
    175 	mrs	r2, spsr_all
    176 	mov	r3, lr
    177 	adr	r0, Laddress_exception_msg
    178 	bl	_C_LABEL(printf)	/* XXX CLOBBERS LR!! */
    179 	b	data_abort_entry
    180 Laddress_exception_msg:
    181 	.asciz	"Address Exception CPSR=0x%08x SPSR=0x%08x LR=0x%08x\n"
    182 	.balign	4
    183 
    184 /*
    185  * General exception exit handler
    186  * (Placed here to be within range of all the references to it)
    187  *
    188  * It exits straight away if not returning to USR mode.
    189  * This loops around delivering any pending ASTs.
    190  * Interrupts are disabled at suitable points to avoid ASTs
    191  * being posted between testing and exit to user mode.
    192  *
    193  * This function uses PULLFRAMEFROMSVCANDEXIT and
    194  * DO_AST_AND_RESTORE_ALIGNMENT_FAULTS thus should
    195  * only be called if the exception handler used PUSHFRAMEINSVC
    196  * followed by ENABLE_ALIGNMENT_FAULTS.
    197  */
    198 
    199 exception_exit:
    200 	DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
    201 	PULLFRAMEFROMSVCANDEXIT
    202 
    203 /*
    204  * undefined_entry:
    205  *
    206  *	Handler for the Undefined Instruction exception.
    207  *
    208  *	We indirect the undefined vector via the handler address
    209  *	in the data area.  Entry to the undefined handler must
    210  *	look like direct entry from the vector.
    211  */
    212 ASENTRY_NP(undefined_entry)
    213 	stmfd	sp!, {r0, r1}
    214 	ldr	r0, Lundefined_handler_indirection
    215 	ldr	r1, [sp], #0x0004
    216 	str	r1, [r0, #0x0000]
    217 	ldr	r1, [sp], #0x0004
    218 	str	r1, [r0, #0x0004]
    219 	ldmia	r0, {r0, r1, pc}
    220 
    221 Lundefined_handler_indirection:
    222 	.word	Lundefined_handler_indirection_data
    223 
    224 /*
    225  * assembly bounce code for calling the kernel
    226  * undefined instruction handler. This uses
    227  * a standard trap frame and is called in SVC mode.
    228  */
    229 
    230 ENTRY_NP(undefinedinstruction_bounce)
    231 	PUSHFRAMEINSVC
    232 	ENABLE_ALIGNMENT_FAULTS
    233 
    234 	mov	r0, sp
    235 	adr	lr, exception_exit
    236 	b	_C_LABEL(undefinedinstruction)
    237 
    238 	.data
    239 	.align	0
    240 
    241 /*
    242  * Indirection data
    243  * 2 words use for preserving r0 and r1
    244  * 3rd word contains the undefined handler address.
    245  */
    246 
    247 Lundefined_handler_indirection_data:
    248 	.word	0
    249 	.word	0
    250 
    251 	.global	_C_LABEL(undefined_handler_address)
    252 _C_LABEL(undefined_handler_address):
    253 	.word	_C_LABEL(undefinedinstruction_bounce)
    254