Home | History | Annotate | Line # | Download | only in arm32
exception.S revision 1.9
      1  1.9      scw /*	$NetBSD: exception.S,v 1.9 2003/10/25 19:44:42 scw 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 "opt_ipkdb.h"
     49  1.9      scw #include "opt_compat_netbsd.h"
     50  1.9      scw #include "opt_execfmt.h"
     51  1.9      scw #include "opt_multiprocessor.h"
     52  1.1    chris #include <machine/asm.h>
     53  1.1    chris #include <machine/cpu.h>
     54  1.1    chris #include <machine/frame.h>
     55  1.1    chris #include "assym.h"
     56  1.1    chris 
     57  1.1    chris 	.text
     58  1.1    chris 	.align	0
     59  1.1    chris 
     60  1.9      scw .Lastpending:
     61  1.9      scw 	.word	_C_LABEL(astpending)
     62  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
     63  1.9      scw .Lcpufuncs:
     64  1.9      scw 	.word	_C_LABEL(cpufuncs)
     65  1.9      scw #ifndef MULTIPROCESSOR
     66  1.9      scw .Lcurpcb:
     67  1.9      scw 	.word	_C_LABEL(curpcb)
     68  1.9      scw .Lcpu_info_store:
     69  1.9      scw 	.word	_C_LABEL(cpu_info_store)
     70  1.9      scw #define	GET_CURPCB							\
     71  1.9      scw 	ldr	r1, .Lcurpcb						;\
     72  1.9      scw 	ldr	r1, [r1]
     73  1.9      scw #define	GET_CPUINFO							\
     74  1.9      scw 	ldr	r0, .Lcpu_info_store
     75  1.9      scw #else
     76  1.9      scw .Lcpu_info:
     77  1.9      scw 	.word	_C_LABEL(cpu_info)
     78  1.9      scw #define	GET_CURPCB							\
     79  1.9      scw 	ldr	r4, .Lcpu_info						;\
     80  1.9      scw 	bl	_C_LABEL(cpu_number)					;\
     81  1.9      scw 	ldr	r0, [r4, r0, lsl #2]					;\
     82  1.9      scw 	ldr	r1, [r0, #CI_CURPCB]
     83  1.9      scw #define	GET_CPUINFO	/* nothing to do */
     84  1.9      scw #endif
     85  1.9      scw #define	ENABLE_ALIGNMENT_FAULTS						\
     86  1.9      scw 	GET_CURPCB							;\
     87  1.9      scw 	ldr	r1, [r1, #PCB_FLAGS]	/* Fetch curpcb->pcb_flags */	;\
     88  1.9      scw 	tst	r1, #PCB_NOALIGNFLT					;\
     89  1.9      scw 	beq	1f		/* Alignment faults already enabled */	;\
     90  1.9      scw 	GET_CPUINFO							;\
     91  1.9      scw 	ldr	r2, .Lcpufuncs						;\
     92  1.9      scw 	ldr	r1, [r0, #CI_CTRL]	/* Fetch control register */	;\
     93  1.9      scw 	mov	r0, #-1							;\
     94  1.9      scw 	mov	lr, pc							;\
     95  1.9      scw 	ldr	pc, [r2, #CF_CONTROL]	/* Enable alignment faults */	;\
     96  1.9      scw 1:
     97  1.9      scw #endif /* COMPAT_15 && EXEC_AOUT */
     98  1.9      scw 
     99  1.1    chris 
    100  1.1    chris /*
    101  1.1    chris  * General exception exit handler
    102  1.1    chris  *
    103  1.1    chris  * It exits straight away if not returning to USR mode.
    104  1.1    chris  * This loops around delivering any pending ASTs.
    105  1.1    chris  * Interrupts are disabled at suitable points to avoid ASTs
    106  1.1    chris  * being posted between testing and exit to user mode.
    107  1.1    chris  *
    108  1.1    chris  * This function uses PULLFRAMEFROMSVCANDEXIT thus should
    109  1.1    chris  * only be called if the exception handler used PUSHFRAMEINSVC
    110  1.1    chris  */
    111  1.1    chris 
    112  1.1    chris exception_exit:
    113  1.6   briggs 	mrs     r4, cpsr		/* Get CPSR */
    114  1.1    chris 
    115  1.1    chris 	ldr	r0, [sp]		/* Get the SPSR from stack */
    116  1.1    chris 	and	r0, r0, #(PSR_MODE)	/* Test for USR32 mode before the AST */
    117  1.1    chris 	teq	r0, #(PSR_USR32_MODE)
    118  1.6   briggs 	bne	.Ldo_exit		/* Not USR mode so no AST delivery */
    119  1.1    chris 
    120  1.9      scw 	ldr	r5, .Lastpending	/* Get address of astpending */
    121  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT) && !defined(MULTIPROCESSOR)
    122  1.9      scw 	ldr	r6, .Lcurpcb
    123  1.9      scw 	ldr	r7, .Lcpu_info_store
    124  1.9      scw #endif
    125  1.1    chris 
    126  1.1    chris Lexception_exit_loop:
    127  1.1    chris 	orr     r0, r4, #(I32_bit)	/* Block IRQs */
    128  1.1    chris 	msr     cpsr_all, r0
    129  1.1    chris 
    130  1.1    chris 	ldr	r1, [r5]		/* Do we have an AST pending */
    131  1.1    chris 	teq	r1, #0x00000000
    132  1.6   briggs 	bne	.Ldo_ast
    133  1.1    chris 
    134  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    135  1.9      scw 	/* Disable alignment faults for the process, if necessary. */
    136  1.9      scw #ifdef MULTIPROCESSOR
    137  1.9      scw 	ldr	r7, .Lcpu_info
    138  1.9      scw 	bl	_C_LABEL(cpu_number)
    139  1.9      scw 	ldr	r7, [r7, r0, lsl #2]
    140  1.9      scw 	ldr	r1, [r7, #CI_CURPCB]
    141  1.9      scw #else
    142  1.9      scw 	ldr	r1, [r6]
    143  1.9      scw #endif
    144  1.9      scw 	ldr	r1, [r1, #PCB_FLAGS]	/* Fetch curpcb->pcb_flags */
    145  1.9      scw 	tst	r1, #PCB_NOALIGNFLT
    146  1.9      scw 	beq	1f			/* Keep alignment faults enabled */
    147  1.9      scw 	ldr	r1, [r7, #CI_CTRL]	/* Fetch control register */
    148  1.9      scw 	ldr	r2, .Lcpufuncs
    149  1.9      scw 	mov	r0, #-1
    150  1.9      scw 	bic	r1, r1, #CPU_CONTROL_AFLT_ENABLE  /* Disable alignment faults */
    151  1.9      scw 	mov	lr, pc
    152  1.9      scw 	ldr	pc, [r2, #CF_CONTROL]	/* Set the new control register value */
    153  1.9      scw 1:
    154  1.9      scw #endif
    155  1.9      scw 
    156  1.1    chris 	PULLFRAMEFROMSVCANDEXIT		/* No AST so exit */
    157  1.1    chris 
    158  1.6   briggs .Ldo_ast:
    159  1.1    chris 	mov	r1, #0x00000000		/* Clear ast pending */
    160  1.1    chris 	str	r1, [r5]
    161  1.1    chris 
    162  1.2  thorpej 	msr     cpsr_all, r4		/* Restore interrupts */
    163  1.2  thorpej 
    164  1.1    chris 	mov	r0, sp			/* arg 0 = trap frame */
    165  1.1    chris 	bl	_C_LABEL(ast)		/* call the AST handler */
    166  1.1    chris 	b	Lexception_exit_loop	/* Try and exit again */
    167  1.1    chris 
    168  1.6   briggs .Ldo_exit:
    169  1.8      wiz 	orr     r0, r4, #(I32_bit)	/* Disable interrupts */
    170  1.1    chris 	msr     cpsr_all, r0
    171  1.1    chris 
    172  1.1    chris 	PULLFRAMEFROMSVCANDEXIT		/* Restore the trap frame and exit */
    173  1.1    chris 
    174  1.3  thorpej /*
    175  1.3  thorpej  * reset_entry:
    176  1.3  thorpej  *
    177  1.3  thorpej  *	Handler for Reset exception.
    178  1.3  thorpej  */
    179  1.3  thorpej ASENTRY_NP(reset_entry)
    180  1.3  thorpej 	adr	r0, Lreset_panicmsg
    181  1.3  thorpej 	mov	r1, lr
    182  1.3  thorpej 	bl	_C_LABEL(panic)
    183  1.3  thorpej 	/* NOTREACHED */
    184  1.3  thorpej Lreset_panicmsg:
    185  1.3  thorpej 	.asciz	"Reset vector called, LR = 0x%08x"
    186  1.3  thorpej 	.balign	4
    187  1.1    chris 
    188  1.3  thorpej /*
    189  1.3  thorpej  * swi_entry
    190  1.3  thorpej  *
    191  1.3  thorpej  *	Handler for the Software Interrupt exception.
    192  1.3  thorpej  */
    193  1.3  thorpej ASENTRY_NP(swi_entry)
    194  1.3  thorpej 	PUSHFRAME
    195  1.3  thorpej 
    196  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    197  1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    198  1.9      scw #endif
    199  1.9      scw 
    200  1.3  thorpej 	mov	r0, sp			/* Pass the frame to any function */
    201  1.1    chris 
    202  1.5    bjh21 	bl	_C_LABEL(swi_handler)	/* It's a SWI ! */
    203  1.1    chris 
    204  1.9      scw 	ldr	r5, .Lastpending	/* Get address of astpending */
    205  1.6   briggs 	mrs     r4, cpsr		/* Get CPSR */
    206  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT) && !defined(MULTIPROCESSOR)
    207  1.9      scw 	ldr	r6, .Lcurpcb
    208  1.9      scw 	ldr	r7, .Lcpu_info_store
    209  1.9      scw #endif
    210  1.1    chris 
    211  1.6   briggs .Lswi_exit_loop:
    212  1.3  thorpej 	orr     r0, r4, #(I32_bit)	/* Disable IRQs */
    213  1.3  thorpej 	msr     cpsr_all, r0
    214  1.1    chris 
    215  1.3  thorpej 	ldr	r1, [r5]		/* Do we have an AST pending */
    216  1.3  thorpej 	teq	r1, #0x00000000
    217  1.6   briggs 	bne	.Ldo_swi_ast
    218  1.1    chris 
    219  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    220  1.9      scw 	/* Disable alignment faults for the process, if necessary. */
    221  1.9      scw #ifdef MULTIPROCESSOR
    222  1.9      scw 	ldr	r7, .Lcpu_info
    223  1.9      scw 	bl	_C_LABEL(cpu_number)
    224  1.9      scw 	ldr	r7, [r7, r0, lsl #2]
    225  1.9      scw 	ldr	r1, [r7, #CI_CURPCB]
    226  1.9      scw #else
    227  1.9      scw 	ldr	r1, [r6]
    228  1.9      scw #endif
    229  1.9      scw 	ldr	r1, [r1, #PCB_FLAGS]	/* Fetch curpcb->pcb_flags */
    230  1.9      scw 	tst	r1, #PCB_NOALIGNFLT
    231  1.9      scw 	beq	1f			/* Keep alignment faults enabled */
    232  1.9      scw 	ldr	r1, [r7, #CI_CTRL]	/* Fetch control register */
    233  1.9      scw 	ldr	r2, .Lcpufuncs
    234  1.9      scw 	mov	r0, #-1
    235  1.9      scw 	bic	r1, r1, #CPU_CONTROL_AFLT_ENABLE  /* Disable alignment faults */
    236  1.9      scw 	mov	lr, pc
    237  1.9      scw 	ldr	pc, [r2, #CF_CONTROL]	/* Set the new control register value */
    238  1.9      scw 1:
    239  1.9      scw #endif
    240  1.3  thorpej 	PULLFRAME
    241  1.3  thorpej 	movs	pc, lr			/* Exit */
    242  1.1    chris 
    243  1.6   briggs .Ldo_swi_ast:
    244  1.3  thorpej 	mov	r1, #0x00000000		/* Clear ast pending */
    245  1.3  thorpej 	str	r1, [r5]
    246  1.1    chris 
    247  1.3  thorpej 	msr     cpsr_all, r4		/* Restore interrupts */
    248  1.1    chris 
    249  1.3  thorpej 	mov	r0, sp			/* arg 0 = trap frame */
    250  1.3  thorpej 	bl	_C_LABEL(ast)		/* call the AST handler */
    251  1.6   briggs 	b	.Lswi_exit_loop		/* Try and exit again */
    252  1.1    chris 
    253  1.3  thorpej /*
    254  1.3  thorpej  * prefetch_abort_entry:
    255  1.3  thorpej  *
    256  1.3  thorpej  *	Handler for the Prefetch Abort exception.
    257  1.3  thorpej  */
    258  1.1    chris ASENTRY_NP(prefetch_abort_entry)
    259  1.1    chris         sub     lr, lr, #0x00000004     /* Adjust the lr */
    260  1.1    chris 
    261  1.1    chris 	PUSHFRAMEINSVC
    262  1.1    chris 
    263  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    264  1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    265  1.9      scw #endif
    266  1.9      scw 
    267  1.1    chris  	mov	r0, sp			/* pass the stack pointer as r0 */
    268  1.1    chris 
    269  1.7    bjh21 	adr	lr, exception_exit
    270  1.1    chris 	ldr	r1, Lprefetch_abort_handler_address
    271  1.1    chris 	ldr	pc, [r1]
    272  1.1    chris 
    273  1.1    chris Lprefetch_abort_handler_address:
    274  1.1    chris 	.word	_C_LABEL(prefetch_abort_handler_address)
    275  1.1    chris 
    276  1.1    chris 	.data
    277  1.1    chris 	.global	_C_LABEL(prefetch_abort_handler_address)
    278  1.1    chris 
    279  1.1    chris _C_LABEL(prefetch_abort_handler_address):
    280  1.1    chris 	.word	abortprefetch
    281  1.1    chris 
    282  1.1    chris 	.text
    283  1.1    chris abortprefetch:
    284  1.7    bjh21         adr     r0, abortprefetchmsg
    285  1.1    chris 	b	_C_LABEL(panic)
    286  1.1    chris 
    287  1.1    chris abortprefetchmsg:
    288  1.1    chris         .asciz  "abortprefetch"
    289  1.1    chris         .align  0
    290  1.1    chris 
    291  1.1    chris /*
    292  1.3  thorpej  * data_abort_entry:
    293  1.1    chris  *
    294  1.3  thorpej  *	Handler for the Data Abort exception.
    295  1.1    chris  */
    296  1.3  thorpej ASENTRY_NP(data_abort_entry)
    297  1.3  thorpej         sub     lr, lr, #0x00000008     /* Adjust the lr */
    298  1.1    chris 
    299  1.3  thorpej 	PUSHFRAMEINSVC			/* Push trap frame and switch */
    300  1.3  thorpej 					/* to SVC32 mode */
    301  1.1    chris 
    302  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    303  1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    304  1.9      scw #endif
    305  1.9      scw 
    306  1.3  thorpej 	mov	r0, sp			/* pass the stack pointer as r0 */
    307  1.1    chris 
    308  1.7    bjh21 	adr	lr, exception_exit
    309  1.3  thorpej 	ldr	r1, Ldata_abort_handler_address
    310  1.3  thorpej 	ldr	pc, [r1]
    311  1.1    chris 
    312  1.3  thorpej Ldata_abort_handler_address:
    313  1.3  thorpej 	.word	_C_LABEL(data_abort_handler_address)
    314  1.1    chris 
    315  1.3  thorpej 	.data
    316  1.3  thorpej 	.global	_C_LABEL(data_abort_handler_address)
    317  1.3  thorpej _C_LABEL(data_abort_handler_address):
    318  1.3  thorpej 	.word	abortdata
    319  1.1    chris 
    320  1.3  thorpej 	.text
    321  1.3  thorpej abortdata:
    322  1.7    bjh21         adr     r0, abortdatamsg
    323  1.3  thorpej 	b	_C_LABEL(panic)
    324  1.1    chris 
    325  1.3  thorpej abortdatamsg:
    326  1.3  thorpej         .asciz  "abortdata"
    327  1.3  thorpej         .align  0
    328  1.1    chris 
    329  1.3  thorpej /*
    330  1.3  thorpej  * address_exception_entry:
    331  1.3  thorpej  *
    332  1.3  thorpej  *	Handler for the Address Exception exception.
    333  1.3  thorpej  *
    334  1.3  thorpej  *	NOTE: This exception isn't really used on arm32.  We
    335  1.3  thorpej  *	print a warning message to the console and then treat
    336  1.3  thorpej  *	it like a Data Abort.
    337  1.3  thorpej  */
    338  1.3  thorpej ASENTRY_NP(address_exception_entry)
    339  1.3  thorpej 	mrs	r1, cpsr_all
    340  1.3  thorpej 	mrs	r2, spsr_all
    341  1.3  thorpej 	mov	r3, lr
    342  1.3  thorpej 	adr	r0, Laddress_exception_msg
    343  1.3  thorpej 	bl	_C_LABEL(printf)	/* XXX CLOBBERS LR!! */
    344  1.3  thorpej 	b	data_abort_entry
    345  1.3  thorpej Laddress_exception_msg:
    346  1.3  thorpej 	.asciz	"Address Exception CPSR=0x%08x SPSR=0x%08x LR=0x%08x\n"
    347  1.3  thorpej 	.balign	4
    348  1.1    chris 
    349  1.1    chris /*
    350  1.3  thorpej  * undefined_entry:
    351  1.3  thorpej  *
    352  1.3  thorpej  *	Handler for the Undefined Instruction exception.
    353  1.3  thorpej  *
    354  1.3  thorpej  *	We indirect the undefined vector via the handler address
    355  1.3  thorpej  *	in the data area.  Entry to the undefined handler must
    356  1.3  thorpej  *	look like direct entry from the vector.
    357  1.1    chris  */
    358  1.1    chris ASENTRY_NP(undefined_entry)
    359  1.1    chris #ifdef IPKDB
    360  1.1    chris /*
    361  1.1    chris  * IPKDB must be hooked in at the earliest possible entry point.
    362  1.1    chris  *
    363  1.1    chris  */
    364  1.1    chris /*
    365  1.1    chris  * Make room for all registers saving real r0-r7 and r15.
    366  1.1    chris  * The remaining registers are updated later.
    367  1.1    chris  */
    368  1.1    chris 	stmfd	sp!, {r0,r1}		/* psr & spsr */
    369  1.1    chris 	stmfd	sp!, {lr}		/* pc */
    370  1.1    chris 	stmfd	sp!, {r0-r14}		/* r0-r7, r8-r14 */
    371  1.1    chris /*
    372  1.1    chris  * Get previous psr.
    373  1.1    chris  */
    374  1.1    chris 	mrs	r7, cpsr_all
    375  1.1    chris 	mrs	r0, spsr_all
    376  1.1    chris 	str	r0, [sp, #(16*4)]
    377  1.1    chris /*
    378  1.1    chris  * Test for user mode.
    379  1.1    chris  */
    380  1.1    chris 	tst	r0, #0xf
    381  1.6   briggs 	bne	.Lprenotuser_push
    382  1.1    chris 	add	r1, sp, #(8*4)
    383  1.1    chris 	stmia	r1,{r8-r14}^		/* store user mode r8-r14*/
    384  1.6   briggs 	b	.Lgoipkdb
    385  1.1    chris /*
    386  1.1    chris  * Switch to previous mode to get r8-r13.
    387  1.1    chris  */
    388  1.6   briggs .Lprenotuser_push:
    389  1.1    chris 	orr	r0, r0, #(I32_bit) /* disable interrupts */
    390  1.1    chris 	msr	cpsr_all, r0
    391  1.1    chris 	mov	r1, r8
    392  1.1    chris 	mov	r2, r9
    393  1.1    chris 	mov	r3, r10
    394  1.1    chris 	mov	r4, r11
    395  1.1    chris 	mov	r5, r12
    396  1.1    chris 	mov	r6, r13
    397  1.1    chris 	msr	cpsr_all, r7		/* back to undefined mode */
    398  1.1    chris 	add	r8, sp, #(8*4)
    399  1.1    chris 	stmia	r8, {r1-r6}		/* r8-r13 */
    400  1.1    chris /*
    401  1.1    chris  * Now back to previous mode to get r14 and spsr.
    402  1.1    chris  */
    403  1.1    chris 	msr	cpsr_all, r0
    404  1.1    chris 	mov	r1, r14
    405  1.1    chris 	mrs	r2, spsr
    406  1.1    chris 	msr	cpsr_all, r7		/* back to undefined mode */
    407  1.1    chris 	str	r1, [sp, #(14*4)]	/* r14 */
    408  1.1    chris 	str	r2, [sp, #(17*4)]	/* spsr */
    409  1.1    chris /*
    410  1.1    chris  * Now to IPKDB.
    411  1.1    chris  */
    412  1.6   briggs .Lgoipkdb:
    413  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    414  1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    415  1.9      scw #endif
    416  1.1    chris 	mov	r0, sp
    417  1.1    chris 	bl	_C_LABEL(ipkdb_trap_glue)
    418  1.6   briggs 	ldr	r1, .Lipkdb_trap_return
    419  1.1    chris 	str	r0,[r1]
    420  1.9      scw 
    421  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    422  1.9      scw #ifdef MULTIPROCESSOR
    423  1.9      scw 	ldr	r7, .Lcpu_info
    424  1.9      scw 	bl	_C_LABEL(cpu_number)
    425  1.9      scw 	ldr	r7, [r7, r0, lsl #2]
    426  1.9      scw 	ldr	r1, [r7, #CI_CURPCB]
    427  1.9      scw #else
    428  1.9      scw 	ldr	r6, .Lcurpcb
    429  1.9      scw 	ldr	r7, .Lcpu_info_store
    430  1.9      scw 	ldr	r1, [r6]
    431  1.9      scw #endif
    432  1.9      scw 	ldr	r1, [r1, #PCB_FLAGS]	/* Fetch curpcb->pcb_flags */
    433  1.9      scw 	tst	r1, #PCB_NOALIGNFLT
    434  1.9      scw 	beq	1f			/* Keep alignment faults enabled */
    435  1.9      scw 	ldr	r1, [r7, #CI_CTRL]	/* Fetch control register */
    436  1.9      scw 	ldr	r2, .Lcpufuncs
    437  1.9      scw 	mov	r0, #-1
    438  1.9      scw 	bic	r1, r1, #CPU_CONTROL_AFLT_ENABLE  /* Disable alignment faults */
    439  1.9      scw 	mov	lr, pc
    440  1.9      scw 	ldr	pc, [r2, #CF_CONTROL]	/* Set the new control register value */
    441  1.9      scw 1:
    442  1.9      scw #endif
    443  1.9      scw 
    444  1.1    chris /*
    445  1.1    chris  * Have to load all registers from the stack.
    446  1.1    chris  *
    447  1.1    chris  * Start with spsr and pc.
    448  1.1    chris  */
    449  1.1    chris 	ldr	r0, [sp, #(16*4)]	/* spsr */
    450  1.1    chris 	ldr	r1, [sp, #(15*4)]	/* r15 */
    451  1.1    chris 	msr	spsr_all, r0
    452  1.1    chris 	mov	r14, r1
    453  1.1    chris /*
    454  1.1    chris  * Test for user mode.
    455  1.1    chris  */
    456  1.1    chris 	tst	r0, #0xf
    457  1.6   briggs 	bne	.Lprenotuser_pull
    458  1.1    chris 	add	r1, sp, #(8*4)
    459  1.1    chris 	ldmia	r1, {r8-r14}^		/* load user mode r8-r14 */
    460  1.6   briggs 	b	.Lpull_r0r7
    461  1.6   briggs .Lprenotuser_pull:
    462  1.1    chris /*
    463  1.1    chris  * Now previous mode spsr and r14.
    464  1.1    chris  */
    465  1.1    chris 	ldr	r1, [sp, #(17*4)]		/* spsr */
    466  1.1    chris 	ldr	r2, [sp, #(14*4)]		/* r14 */
    467  1.1    chris 	orr	r0, r0, #(I32_bit)
    468  1.1    chris 	msr	cpsr_all, r0			/* switch to previous mode */
    469  1.1    chris 	msr	spsr_all, r1
    470  1.1    chris 	mov	r14, r2
    471  1.1    chris 	msr	cpsr_all, r7			/* back to undefined mode */
    472  1.1    chris /*
    473  1.1    chris  * Now r8-r13.
    474  1.1    chris  */
    475  1.1    chris 	add	r8, sp, #(8*4)
    476  1.1    chris 	ldmia	r8, {r1-r6}		/* r8-r13 */
    477  1.1    chris 	msr	cpsr_all, r0
    478  1.1    chris 	mov	r8, r1
    479  1.1    chris 	mov	r9, r2
    480  1.1    chris 	mov	r10, r3
    481  1.1    chris 	mov	r11, r4
    482  1.1    chris 	mov	r12, r5
    483  1.1    chris 	mov	r13, r6
    484  1.1    chris 	msr	cpsr_all, r7
    485  1.6   briggs .Lpull_r0r7:
    486  1.1    chris /*
    487  1.1    chris  * Now the rest of the registers.
    488  1.1    chris  */
    489  1.1    chris 	ldr	r1,Lipkdb_trap_return
    490  1.1    chris 	ldr	r0,[r1]
    491  1.1    chris 	tst	r0,r0
    492  1.1    chris 	ldmfd	sp!, {r0-r7}		/* r0-r7 */
    493  1.1    chris 	add	sp, sp, #(10*4)		/* adjust sp */
    494  1.1    chris 
    495  1.1    chris /*
    496  1.1    chris  * Did IPKDB handle it?
    497  1.1    chris  */
    498  1.1    chris 	movnes	pc, lr			/* return */
    499  1.1    chris 
    500  1.1    chris #endif
    501  1.1    chris 	stmfd	sp!, {r0, r1}
    502  1.1    chris 	ldr	r0, Lundefined_handler_indirection
    503  1.1    chris 	ldr	r1, [sp], #0x0004
    504  1.1    chris 	str	r1, [r0, #0x0000]
    505  1.1    chris 	ldr	r1, [sp], #0x0004
    506  1.1    chris 	str	r1, [r0, #0x0004]
    507  1.1    chris 	ldmia	r0, {r0, r1, pc}
    508  1.1    chris 
    509  1.1    chris #ifdef IPKDB
    510  1.1    chris Lipkdb_trap_return:
    511  1.1    chris 	.word	Lipkdb_trap_return_data
    512  1.1    chris #endif
    513  1.1    chris 
    514  1.1    chris Lundefined_handler_indirection:
    515  1.1    chris 	.word	Lundefined_handler_indirection_data
    516  1.1    chris 
    517  1.1    chris /*
    518  1.1    chris  * assembly bounce code for calling the kernel
    519  1.1    chris  * undefined instruction handler. This uses
    520  1.1    chris  * a standard trap frame and is called in SVC mode.
    521  1.1    chris  */
    522  1.1    chris 
    523  1.1    chris ENTRY_NP(undefinedinstruction_bounce)
    524  1.1    chris 	PUSHFRAMEINSVC
    525  1.9      scw #if defined(COMPAT_15) && defined(EXEC_AOUT)
    526  1.9      scw 	ENABLE_ALIGNMENT_FAULTS
    527  1.9      scw #endif
    528  1.1    chris 	mov	r0, sp
    529  1.1    chris 	bl	_C_LABEL(undefinedinstruction)
    530  1.1    chris 
    531  1.1    chris 	b	exception_exit
    532  1.1    chris 
    533  1.1    chris 	.data
    534  1.1    chris 	.align	0
    535  1.1    chris 
    536  1.1    chris #ifdef IPKDB
    537  1.1    chris Lipkdb_trap_return_data:
    538  1.1    chris 	.word	0
    539  1.1    chris #endif
    540  1.1    chris 
    541  1.1    chris /*
    542  1.1    chris  * Indirection data
    543  1.1    chris  * 2 words use for preserving r0 and r1
    544  1.1    chris  * 3rd word contains the undefined handler address.
    545  1.1    chris  */
    546  1.1    chris 
    547  1.1    chris Lundefined_handler_indirection_data:
    548  1.1    chris 	.word	0
    549  1.1    chris 	.word	0
    550  1.1    chris 
    551  1.1    chris 	.global	_C_LABEL(undefined_handler_address)
    552  1.1    chris _C_LABEL(undefined_handler_address):
    553  1.1    chris 	.word	_C_LABEL(undefinedinstruction_bounce)
    554