Home | History | Annotate | Line # | Download | only in arm32
exception.S revision 1.16.34.2
      1  1.16.34.2     yamt /*	$NetBSD: exception.S,v 1.16.34.2 2014/05/22 11:39:31 yamt 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.16     matt #include "assym.h"
     49       1.16     matt 
     50  1.16.34.2     yamt #include <arm/asm.h>
     51  1.16.34.2     yamt 
     52  1.16.34.2     yamt #include <arm/locore.h>
     53  1.16.34.2     yamt 
     54  1.16.34.2     yamt 	RCSID("$NetBSD: exception.S,v 1.16.34.2 2014/05/22 11:39:31 yamt Exp $")
     55        1.1    chris 
     56        1.1    chris 	.text
     57        1.1    chris 	.align	0
     58        1.1    chris 
     59       1.12      scw AST_ALIGNMENT_FAULT_LOCALS
     60        1.1    chris 
     61        1.1    chris /*
     62        1.3  thorpej  * reset_entry:
     63        1.3  thorpej  *
     64        1.3  thorpej  *	Handler for Reset exception.
     65        1.3  thorpej  */
     66  1.16.34.2     yamt ARM_ASENTRY_NP(reset_entry)
     67  1.16.34.2     yamt 	adr	r0, .Lreset_panicmsg
     68        1.3  thorpej 	mov	r1, lr
     69        1.3  thorpej 	bl	_C_LABEL(panic)
     70        1.3  thorpej 	/* NOTREACHED */
     71  1.16.34.2     yamt .Lreset_panicmsg:
     72        1.3  thorpej 	.asciz	"Reset vector called, LR = 0x%08x"
     73        1.3  thorpej 	.balign	4
     74  1.16.34.2     yamt ASEND(reset_entry)
     75        1.1    chris 
     76        1.3  thorpej /*
     77        1.3  thorpej  * swi_entry
     78        1.3  thorpej  *
     79        1.3  thorpej  *	Handler for the Software Interrupt exception.
     80        1.3  thorpej  */
     81  1.16.34.2     yamt ARM_ASENTRY_NP(swi_entry)
     82        1.3  thorpej 	PUSHFRAME
     83        1.9      scw 	ENABLE_ALIGNMENT_FAULTS
     84        1.9      scw 
     85        1.3  thorpej 	mov	r0, sp			/* Pass the frame to any function */
     86        1.5    bjh21 	bl	_C_LABEL(swi_handler)	/* It's a SWI ! */
     87        1.1    chris 
     88       1.12      scw 	DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
     89        1.3  thorpej 	PULLFRAME
     90        1.3  thorpej 	movs	pc, lr			/* Exit */
     91  1.16.34.2     yamt ASEND(swi_entry)
     92        1.1    chris 
     93        1.3  thorpej /*
     94        1.3  thorpej  * prefetch_abort_entry:
     95        1.3  thorpej  *
     96        1.3  thorpej  *	Handler for the Prefetch Abort exception.
     97        1.3  thorpej  */
     98  1.16.34.2     yamt ARM_ASENTRY_NP(prefetch_abort_entry)
     99       1.13      scw #ifdef __XSCALE__
    100       1.13      scw 	nop				/* Make absolutely sure any pending */
    101       1.13      scw 	nop				/* imprecise aborts have occurred. */
    102       1.13      scw #endif
    103        1.1    chris         sub     lr, lr, #0x00000004     /* Adjust the lr */
    104        1.1    chris 
    105  1.16.34.2     yamt #ifdef _ARM_ARCH_7
    106  1.16.34.2     yamt 	/*
    107  1.16.34.2     yamt 	 * After taking a Data Abort exception, the state of the exclusive
    108  1.16.34.2     yamt 	 * monitors is UNKNOWN. Therefore ARM strongly recommends that the
    109  1.16.34.2     yamt 	 * abort handling software performs a CLREX instruction
    110  1.16.34.2     yamt 	 */
    111  1.16.34.2     yamt 	clrex
    112  1.16.34.2     yamt #endif
    113        1.1    chris 	PUSHFRAMEINSVC
    114        1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    115        1.9      scw 
    116  1.16.34.2     yamt 	ldr	r1, .Lprefetch_abort_handler_address
    117  1.16.34.2     yamt 	adr	lr, .Lexception_exit
    118        1.1    chris  	mov	r0, sp			/* pass the stack pointer as r0 */
    119       1.12      scw 	ldr	pc, [r1]
    120        1.1    chris 
    121  1.16.34.2     yamt .Labortprefetch:
    122  1.16.34.2     yamt         adr     r0, .Labortprefetchmsg
    123  1.16.34.2     yamt 	b	_C_LABEL(panic)
    124  1.16.34.2     yamt 
    125  1.16.34.2     yamt .Lprefetch_abort_handler_address:
    126        1.1    chris 	.word	_C_LABEL(prefetch_abort_handler_address)
    127        1.1    chris 
    128  1.16.34.2     yamt .Labortprefetchmsg:
    129  1.16.34.2     yamt         .asciz  "abortprefetch"
    130  1.16.34.2     yamt         .align  0
    131  1.16.34.2     yamt ASEND(prefetch_abort_entry)
    132  1.16.34.2     yamt 
    133        1.1    chris 	.data
    134  1.16.34.1     yamt 	.p2align 2
    135        1.1    chris 	.global	_C_LABEL(prefetch_abort_handler_address)
    136        1.1    chris _C_LABEL(prefetch_abort_handler_address):
    137  1.16.34.2     yamt 	.word	.Labortprefetch
    138        1.1    chris 
    139        1.1    chris /*
    140        1.3  thorpej  * data_abort_entry:
    141        1.1    chris  *
    142        1.3  thorpej  *	Handler for the Data Abort exception.
    143        1.1    chris  */
    144        1.3  thorpej ASENTRY_NP(data_abort_entry)
    145       1.13      scw #ifdef __XSCALE__
    146       1.13      scw 	nop				/* Make absolutely sure any pending */
    147       1.13      scw 	nop				/* imprecise aborts have occurred. */
    148       1.13      scw #endif
    149        1.3  thorpej         sub     lr, lr, #0x00000008     /* Adjust the lr */
    150        1.1    chris 
    151  1.16.34.2     yamt #ifdef _ARM_ARCH_7
    152  1.16.34.2     yamt 	/*
    153  1.16.34.2     yamt 	 * After taking a Data Abort exception, the state of the exclusive
    154  1.16.34.2     yamt 	 * monitors is UNKNOWN. Therefore ARM strongly recommends that the
    155  1.16.34.2     yamt 	 * abort handling software performs a CLREX instruction
    156  1.16.34.2     yamt 	 */
    157  1.16.34.2     yamt 	clrex
    158  1.16.34.2     yamt #endif
    159        1.3  thorpej 	PUSHFRAMEINSVC			/* Push trap frame and switch */
    160        1.3  thorpej 					/* to SVC32 mode */
    161        1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    162        1.9      scw 
    163  1.16.34.2     yamt 	ldr	r1, .Ldata_abort_handler_address
    164  1.16.34.2     yamt 	adr	lr, .Lexception_exit
    165        1.3  thorpej 	mov	r0, sp			/* pass the stack pointer as r0 */
    166        1.3  thorpej 	ldr	pc, [r1]
    167        1.1    chris 
    168  1.16.34.2     yamt .Ldata_abort_handler_address:
    169        1.3  thorpej 	.word	_C_LABEL(data_abort_handler_address)
    170        1.1    chris 
    171        1.3  thorpej 	.data
    172  1.16.34.1     yamt 	.p2align 2
    173        1.3  thorpej 	.global	_C_LABEL(data_abort_handler_address)
    174        1.3  thorpej _C_LABEL(data_abort_handler_address):
    175  1.16.34.2     yamt 	.word	.Labortdata
    176        1.1    chris 
    177        1.3  thorpej 	.text
    178  1.16.34.2     yamt .Labortdata:
    179  1.16.34.2     yamt         adr     r0, .Labortdatamsg
    180        1.3  thorpej 	b	_C_LABEL(panic)
    181        1.1    chris 
    182  1.16.34.2     yamt .Labortdatamsg:
    183        1.3  thorpej         .asciz  "abortdata"
    184        1.3  thorpej         .align  0
    185  1.16.34.2     yamt ASEND(data_abort_entry)
    186        1.1    chris 
    187        1.3  thorpej /*
    188        1.3  thorpej  * address_exception_entry:
    189        1.3  thorpej  *
    190        1.3  thorpej  *	Handler for the Address Exception exception.
    191        1.3  thorpej  *
    192        1.3  thorpej  *	NOTE: This exception isn't really used on arm32.  We
    193        1.3  thorpej  *	print a warning message to the console and then treat
    194        1.3  thorpej  *	it like a Data Abort.
    195        1.3  thorpej  */
    196        1.3  thorpej ASENTRY_NP(address_exception_entry)
    197  1.16.34.2     yamt #ifdef _ARM_ARCH_7
    198  1.16.34.2     yamt 	/*
    199  1.16.34.2     yamt 	 * After taking a Data Abort exception, the state of the exclusive
    200  1.16.34.2     yamt 	 * monitors is UNKNOWN. Therefore ARM strongly recommends that the
    201  1.16.34.2     yamt 	 * abort handling software performs a CLREX instruction
    202  1.16.34.2     yamt 	 */
    203  1.16.34.2     yamt 	clrex
    204  1.16.34.2     yamt #endif
    205  1.16.34.2     yamt 	push	{r0-r3,ip,lr}
    206  1.16.34.2     yamt 	mrs	r1, cpsr
    207  1.16.34.2     yamt 	mrs	r2, spsr
    208        1.3  thorpej 	mov	r3, lr
    209  1.16.34.2     yamt 	adr	r0, .Laddress_exception_msg
    210        1.3  thorpej 	bl	_C_LABEL(printf)	/* XXX CLOBBERS LR!! */
    211  1.16.34.2     yamt 	pop	{r0-r3,ip,lr}
    212  1.16.34.2     yamt 	b	_ASM_LABEL(data_abort_entry)
    213  1.16.34.2     yamt .Laddress_exception_msg:
    214        1.3  thorpej 	.asciz	"Address Exception CPSR=0x%08x SPSR=0x%08x LR=0x%08x\n"
    215        1.3  thorpej 	.balign	4
    216       1.13      scw 
    217       1.13      scw /*
    218       1.13      scw  * General exception exit handler
    219       1.13      scw  * (Placed here to be within range of all the references to it)
    220       1.13      scw  *
    221       1.13      scw  * It exits straight away if not returning to USR mode.
    222       1.13      scw  * This loops around delivering any pending ASTs.
    223       1.13      scw  * Interrupts are disabled at suitable points to avoid ASTs
    224       1.13      scw  * being posted between testing and exit to user mode.
    225       1.13      scw  *
    226       1.13      scw  * This function uses PULLFRAMEFROMSVCANDEXIT and
    227       1.13      scw  * DO_AST_AND_RESTORE_ALIGNMENT_FAULTS thus should
    228       1.13      scw  * only be called if the exception handler used PUSHFRAMEINSVC
    229       1.13      scw  * followed by ENABLE_ALIGNMENT_FAULTS.
    230       1.13      scw  */
    231       1.13      scw 
    232  1.16.34.2     yamt .Lexception_exit:
    233       1.13      scw 	DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
    234       1.13      scw 	PULLFRAMEFROMSVCANDEXIT
    235  1.16.34.2     yamt ASEND(address_exception_entry)
    236        1.1    chris 
    237        1.1    chris /*
    238        1.3  thorpej  * undefined_entry:
    239        1.3  thorpej  *
    240        1.3  thorpej  *	Handler for the Undefined Instruction exception.
    241        1.3  thorpej  *
    242        1.3  thorpej  *	We indirect the undefined vector via the handler address
    243        1.3  thorpej  *	in the data area.  Entry to the undefined handler must
    244        1.3  thorpej  *	look like direct entry from the vector.
    245        1.1    chris  */
    246        1.1    chris ASENTRY_NP(undefined_entry)
    247  1.16.34.2     yamt 	str	r0, [sp, #-8]!
    248  1.16.34.1     yamt 	GET_CURCPU(r0)
    249  1.16.34.2     yamt 	ldr	r0, [r0, #CI_UNDEFSAVE+8]
    250  1.16.34.2     yamt 	str	r0, [sp, #4]
    251  1.16.34.2     yamt 	pop	{r0, pc}
    252  1.16.34.2     yamt ASEND(undefined_entry)
    253        1.1    chris 
    254        1.1    chris /*
    255        1.1    chris  * assembly bounce code for calling the kernel
    256        1.1    chris  * undefined instruction handler. This uses
    257        1.1    chris  * a standard trap frame and is called in SVC mode.
    258        1.1    chris  */
    259        1.1    chris 
    260        1.1    chris ENTRY_NP(undefinedinstruction_bounce)
    261        1.1    chris 	PUSHFRAMEINSVC
    262        1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    263       1.12      scw 
    264        1.1    chris 	mov	r0, sp
    265  1.16.34.2     yamt 	adr	lr, .Lexception_exit
    266       1.12      scw 	b	_C_LABEL(undefinedinstruction)
    267  1.16.34.2     yamt END(undefinedinstruction_bounce)
    268  1.16.34.2     yamt ASEND(undefined_entry)
    269