Home | History | Annotate | Line # | Download | only in ibm4xx
trap_subr.S revision 1.12.2.1
      1  1.12.2.1   jruoho /*	$NetBSD: trap_subr.S,v 1.12.2.1 2011/06/06 09:06:27 jruoho Exp $	*/
      2       1.1   simonb 
      3       1.1   simonb /*
      4       1.1   simonb  * Copyright 2001 Wasabi Systems, Inc.
      5       1.1   simonb  * All rights reserved.
      6       1.1   simonb  *
      7       1.1   simonb  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8       1.1   simonb  *
      9       1.1   simonb  * Redistribution and use in source and binary forms, with or without
     10       1.1   simonb  * modification, are permitted provided that the following conditions
     11       1.1   simonb  * are met:
     12       1.1   simonb  * 1. Redistributions of source code must retain the above copyright
     13       1.1   simonb  *    notice, this list of conditions and the following disclaimer.
     14       1.1   simonb  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1   simonb  *    notice, this list of conditions and the following disclaimer in the
     16       1.1   simonb  *    documentation and/or other materials provided with the distribution.
     17       1.1   simonb  * 3. All advertising materials mentioning features or use of this software
     18       1.1   simonb  *    must display the following acknowledgement:
     19       1.1   simonb  *      This product includes software developed for the NetBSD Project by
     20       1.1   simonb  *      Wasabi Systems, Inc.
     21       1.1   simonb  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.1   simonb  *    or promote products derived from this software without specific prior
     23       1.1   simonb  *    written permission.
     24       1.1   simonb  *
     25       1.1   simonb  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.1   simonb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.1   simonb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.1   simonb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.1   simonb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.1   simonb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.1   simonb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.1   simonb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.1   simonb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.1   simonb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.1   simonb  * POSSIBILITY OF SUCH DAMAGE.
     36       1.1   simonb  */
     37       1.1   simonb 
     38       1.1   simonb /*
     39       1.1   simonb  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     40       1.1   simonb  * Copyright (C) 1995, 1996 TooLs GmbH.
     41       1.1   simonb  * All rights reserved.
     42       1.1   simonb  *
     43       1.1   simonb  * Redistribution and use in source and binary forms, with or without
     44       1.1   simonb  * modification, are permitted provided that the following conditions
     45       1.1   simonb  * are met:
     46       1.1   simonb  * 1. Redistributions of source code must retain the above copyright
     47       1.1   simonb  *    notice, this list of conditions and the following disclaimer.
     48       1.1   simonb  * 2. Redistributions in binary form must reproduce the above copyright
     49       1.1   simonb  *    notice, this list of conditions and the following disclaimer in the
     50       1.1   simonb  *    documentation and/or other materials provided with the distribution.
     51       1.1   simonb  * 3. All advertising materials mentioning features or use of this software
     52       1.1   simonb  *    must display the following acknowledgement:
     53       1.1   simonb  *	This product includes software developed by TooLs GmbH.
     54       1.1   simonb  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55       1.1   simonb  *    derived from this software without specific prior written permission.
     56       1.1   simonb  *
     57       1.1   simonb  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58       1.1   simonb  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59       1.1   simonb  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60       1.1   simonb  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61       1.1   simonb  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62       1.1   simonb  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63       1.1   simonb  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64       1.1   simonb  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65       1.1   simonb  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66       1.1   simonb  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67       1.1   simonb  */
     68       1.1   simonb 
     69       1.1   simonb /*
     70       1.1   simonb  * NOTICE: This is not a standalone file.  to use it, #include it in
     71       1.1   simonb  * your port's locore.S, like so:
     72       1.1   simonb  *
     73       1.5      chs  *	#include <powerpc/ibm4xx/trap_subr.S>
     74       1.1   simonb  */
     75       1.1   simonb 
     76       1.1   simonb /*
     77       1.1   simonb  * XXX Interrupt and spill stacks need to be per-CPU.
     78       1.1   simonb  */
     79       1.1   simonb 
     80       1.4   simonb #define	GET_PCB(rX)	\
     81       1.1   simonb 	GET_CPUINFO(rX);	\
     82       1.1   simonb 	lwz	rX,CI_CURPCB(rX)
     83       1.1   simonb 
     84       1.1   simonb #define	STANDARD_PROLOG(savearea)	\
     85      1.12     matt 	mtsprg1	%r1;			/* save SP */ 		\
     86  1.12.2.1   jruoho 	GET_CPUINFO(%r1);					\
     87  1.12.2.1   jruoho 	stmw	%r28,(savearea+CPUSAVE_R28)(%r1); /* free r28-r31 */	\
     88      1.12     matt 	mflr	%r28;			/* save LR */		\
     89      1.12     matt 	mfcr	%r29;			/* save CR */		\
     90  1.12.2.1   jruoho 	mfsrr0	%r30;						\
     91  1.12.2.1   jruoho 	mfsrr1	%r31; /* Test whether we already had PR set */	\
     92  1.12.2.1   jruoho 	stmw	%r30,(savearea+CPUSAVE_SRR0)(%r1); /* save srr0/srr1 */	\
     93  1.12.2.1   jruoho 	mfsprg1	%r1;			/* restore SP */ 	\
     94  1.12.2.1   jruoho 	mtcr	%r31;						\
     95  1.12.2.1   jruoho 	bf	MSR_PR,1f;		/* branch if MSR[PR] is clear */ \
     96  1.12.2.1   jruoho 	GET_PCB(%r1);						\
     97  1.12.2.1   jruoho 	addi	%r1,%r1,USPACE-CALLFRAMELEN; /* stack is top of user struct */ \
     98  1.12.2.1   jruoho 1:
     99  1.12.2.1   jruoho 
    100  1.12.2.1   jruoho #define	ACCESS_PROLOG(savearea)					\
    101  1.12.2.1   jruoho 	mtsprg1	%r1;			/* save SP temporalily */	\
    102  1.12.2.1   jruoho 	GET_CPUINFO(%r1);					\
    103  1.12.2.1   jruoho 	stmw	%r28,(savearea+CPUSAVE_R28)(%r1); /* free r28-r31 */	\
    104  1.12.2.1   jruoho 	mflr	%r28;			/* save LR */		\
    105  1.12.2.1   jruoho 	mfcr	%r29;			/* save CR */		\
    106  1.12.2.1   jruoho 	mfdear	%r30;						\
    107  1.12.2.1   jruoho 	mfesr	%r31;						\
    108  1.12.2.1   jruoho 	stmw	%r30,(savearea+CPUSAVE_DEAR)(%r1);		\
    109  1.12.2.1   jruoho 	mfsrr0	%r30;						\
    110      1.12     matt 	mfsrr1	%r31; /* Test whether we already had PR set */	\
    111  1.12.2.1   jruoho 	stmw	%r30,(savearea+CPUSAVE_SRR0)(%r1); /* save srr0/srr1 */	\
    112  1.12.2.1   jruoho 	mfsprg1	%r1;			/* restore SP */ 	\
    113      1.12     matt 	mtcr	%r31;						\
    114  1.12.2.1   jruoho 	bf	MSR_PR,1f;		/* branch if MSR[PR] is clear */ \
    115      1.12     matt 	GET_PCB(%r1);						\
    116  1.12.2.1   jruoho 	addi	%r1,%r1,USPACE-CALLFRAMELEN; /* stack is top of user struct */ \
    117       1.1   simonb 1:
    118       1.4   simonb 
    119  1.12.2.1   jruoho #define	CRITICAL_PROLOG(savearea)				\
    120      1.12     matt 	mtsprg1	%r1;			/* save SP */ 		\
    121  1.12.2.1   jruoho 	GET_CPUINFO(%r1);					\
    122  1.12.2.1   jruoho 	stmw	%r28,(savearea+CPUSAVE_R28)(%r1); /* free r28-r31 */	\
    123      1.12     matt 	mflr	%r28;			/* save LR */		\
    124      1.12     matt 	mfcr	%r29;			/* save CR */		\
    125      1.12     matt 	mfsrr2	%r30; /* Fake a standard trap */		\
    126      1.12     matt 	mfsrr3	%r31; /* Test whether we already had PR set */	\
    127  1.12.2.1   jruoho 	stmw	%r30,(savearea+CPUSAVE_SRR0)(%r1); /* save srr0/srr1 */	\
    128  1.12.2.1   jruoho 	mfsprg1	%r1;			/* restore SP */ 	\
    129      1.12     matt 	mtcr	%r31;						\
    130  1.12.2.1   jruoho 	bf	MSR_PR,1f;		/* branch if MSR[PR] is clear */ \
    131      1.12     matt 	GET_PCB(%r1);						\
    132  1.12.2.1   jruoho 	addi	%r1,%r1,USPACE-CALLFRAMELEN; /* stack is top of user struct */ \
    133       1.1   simonb 1:
    134       1.1   simonb 
    135       1.1   simonb 
    136       1.4   simonb /* Standard handler saves r1,r28-31,LR,CR, sets up the stack and calls s_trap */
    137       1.1   simonb #define STANDARD_EXC_HANDLER(name)\
    138       1.1   simonb 	.globl	_C_LABEL(name ## trap),_C_LABEL(name ## size) ;	\
    139       1.1   simonb _C_LABEL(name ## trap):						\
    140  1.12.2.1   jruoho 	STANDARD_PROLOG(CI_TEMPSAVE);				\
    141       1.1   simonb 	bla	s_trap  ;					\
    142       1.1   simonb _C_LABEL(name ## size) = .-_C_LABEL(name ## trap)
    143       1.1   simonb 
    144       1.4   simonb /* Access exceptions also need DEAR and ESR saved */
    145       1.1   simonb #define ACCESS_EXC_HANDLER(name)\
    146       1.1   simonb 	.globl	_C_LABEL(name ## trap),_C_LABEL(name ## size) ;	\
    147       1.1   simonb _C_LABEL(name ## trap):						\
    148  1.12.2.1   jruoho 	ACCESS_PROLOG(CI_TEMPSAVE);				\
    149       1.1   simonb 	bla	s_trap  ;					\
    150       1.1   simonb _C_LABEL(name ## size) = .-_C_LABEL(name ## trap)
    151       1.1   simonb 
    152       1.1   simonb /* Maybe this should call ddb.... */
    153       1.1   simonb #define CRITICAL_EXC_HANDLER(name)\
    154       1.1   simonb 	.globl	_C_LABEL(name ## trap),_C_LABEL(name ## size) ;	\
    155       1.1   simonb _C_LABEL(name ## trap):						\
    156  1.12.2.1   jruoho 	CRITICAL_PROLOG(CI_TEMPSAVE);				\
    157       1.1   simonb 	bla	s_trap  ;					\
    158       1.1   simonb _C_LABEL(name ## size) = .-_C_LABEL(name ## trap)
    159       1.4   simonb 
    160  1.12.2.1   jruoho #define	INTR_PROLOG(tempsave)					\
    161  1.12.2.1   jruoho 	mtsprg1	%r1;			/* save SP */		\
    162  1.12.2.1   jruoho 	GET_CPUINFO(%r1);					\
    163  1.12.2.1   jruoho 	stmw	%r28,(tempsave+CPUSAVE_R28)(%r1); /* free r28-r31 */ \
    164  1.12.2.1   jruoho 	mflr	%r28;			/* save LR */		\
    165  1.12.2.1   jruoho 	mfcr	%r29;			/* save CR */		\
    166  1.12.2.1   jruoho 	mfxer	%r30;			/* save XER */		\
    167  1.12.2.1   jruoho 	lwz	%r31,CI_IDEPTH(%r1);	/* already running on intstk? */ \
    168  1.12.2.1   jruoho 	addic.	%r31,%r31,1;					\
    169  1.12.2.1   jruoho 	stw	%r31,CI_IDEPTH(%r1);				\
    170  1.12.2.1   jruoho 	lwz	%r1,CI_INTSTK(%r1);	/* get intstk */	\
    171  1.12.2.1   jruoho 	beq	1f;						\
    172  1.12.2.1   jruoho 	mfsprg1	%r1;			/* yes, get old SP */	\
    173  1.12.2.1   jruoho 1:
    174  1.12.2.1   jruoho 
    175       1.1   simonb /*
    176       1.1   simonb  * This code gets copied to all the trap vectors
    177       1.4   simonb  * (except ISI/DSI, ALI, the interrupts, and possibly the debugging
    178       1.1   simonb  * traps when using IPKDB).
    179       1.1   simonb  */
    180       1.1   simonb 	.text
    181       1.1   simonb 	STANDARD_EXC_HANDLER(default)
    182       1.1   simonb 	ACCESS_EXC_HANDLER(ali)
    183       1.1   simonb 	ACCESS_EXC_HANDLER(dsi)
    184       1.1   simonb 	ACCESS_EXC_HANDLER(isi)
    185       1.1   simonb 	STANDARD_EXC_HANDLER(debug)
    186       1.3      eeh 	CRITICAL_EXC_HANDLER(mchk)
    187       1.1   simonb 
    188       1.1   simonb /*
    189       1.1   simonb  * This one for the external interrupt handler.
    190       1.1   simonb  */
    191       1.1   simonb 	.globl	_C_LABEL(extint),_C_LABEL(extsize)
    192       1.1   simonb _C_LABEL(extint):
    193  1.12.2.1   jruoho 	INTR_PROLOG(CI_TEMPSAVE)
    194       1.1   simonb 	ba	extintr
    195       1.1   simonb _C_LABEL(extsize) = .-_C_LABEL(extint)
    196       1.1   simonb 
    197       1.4   simonb 
    198      1.11  garbled #if defined(DDB) || defined(KGDB)
    199       1.1   simonb /*
    200       1.1   simonb  * In case of DDB we want a separate trap catcher for it
    201       1.1   simonb  */
    202  1.12.2.1   jruoho 	.lcomm	ddbstk,INTSTK,16	/* ddb stack */
    203       1.1   simonb 
    204       1.1   simonb 	.globl	_C_LABEL(ddblow),_C_LABEL(ddbsize)
    205       1.1   simonb _C_LABEL(ddblow):
    206      1.12     matt 	mtsprg1	%r1			/* save SP */
    207  1.12.2.1   jruoho 	GET_CPUINFO(%r1)
    208  1.12.2.1   jruoho 	stmw	%r28,CI_DDBSAVE(%r1)	/* free r28-r31 */
    209      1.12     matt 	mflr	%r28			/* save LR */
    210      1.12     matt 	mfcr	%r29			/* save CR */
    211  1.12.2.1   jruoho 	lis	%r1,ddbstk+INTSTK-CALLFRAMELEN@ha	/* get new SP */
    212  1.12.2.1   jruoho 	addi	%r1,%r1,ddbstk+INTSTK-CALLFRAMELEN@l
    213       1.1   simonb 	bla	ddbtrap
    214       1.1   simonb _C_LABEL(ddbsize) = .-_C_LABEL(ddblow)
    215      1.11  garbled #endif	/* DDB || KGDB */
    216       1.1   simonb 
    217       1.1   simonb #ifdef IPKDB
    218       1.1   simonb /*
    219       1.1   simonb  * In case of IPKDB we want a separate trap catcher for it
    220       1.1   simonb  */
    221       1.1   simonb 
    222  1.12.2.1   jruoho 	.lcomm	ipkdbstk,INTSTK,16	/* ipkdb stack */
    223       1.1   simonb 
    224       1.1   simonb 	.globl	_C_LABEL(ipkdblow),_C_LABEL(ipkdbsize)
    225       1.1   simonb _C_LABEL(ipkdblow):
    226      1.12     matt 	mtsprg1	%r1			/* save SP */
    227  1.12.2.1   jruoho 	GET_CPUINFO(%r1)
    228  1.12.2.1   jruoho 	stmw	%r28,CI_IPKDBSAVE(%r1)	/* free r28-r31 */
    229      1.12     matt 	mflr	%r28			/* save LR */
    230      1.12     matt 	mfcr	%r29			/* save CR */
    231  1.12.2.1   jruoho 	lis	%r1,ipkdbstk+INTSTK-CALLFRAMELEN@ha	/* get new SP */
    232  1.12.2.1   jruoho 	addi	%r1,%r1,ipkdbstk+INTSTK-CALLFRAMELEN@l
    233       1.1   simonb 	bla	ipkdbtrap
    234       1.1   simonb _C_LABEL(ipkdbsize) = .-_C_LABEL(ipkdblow)
    235       1.1   simonb #endif	/* IPKDB */
    236       1.1   simonb 
    237       1.1   simonb #ifdef DEBUG
    238       1.1   simonb #define TRAP_IF_ZERO(r)	tweqi	r,0
    239       1.1   simonb #else
    240       1.1   simonb #define TRAP_IF_ZERO(r)
    241       1.1   simonb #endif
    242       1.4   simonb 
    243  1.12.2.1   jruoho #define	ENABLE_TRANSLATION(pidreg,tmpreg)				\
    244  1.12.2.1   jruoho 	mfpid	pidreg;							\
    245  1.12.2.1   jruoho 	li	tmpreg, KERNEL_PID;					\
    246  1.12.2.1   jruoho 	mtpid	tmpreg;							\
    247  1.12.2.1   jruoho 	mfmsr	tmpreg;							\
    248  1.12.2.1   jruoho 	ori	tmpreg,tmpreg,(PSL_DR|PSL_IR)@l;			\
    249  1.12.2.1   jruoho 	mtmsr	tmpreg;							\
    250  1.12.2.1   jruoho 	isync
    251  1.12.2.1   jruoho 
    252       1.1   simonb /*
    253       1.1   simonb  * FRAME_SETUP assumes:
    254      1.12     matt  *	SPRG1		SP (r1)
    255  1.12.2.1   jruoho  *	savearea	r28-r31,DEAR,ESR,SRR0,SRR1 (DEAR & ESR only for DSI traps)
    256  1.12.2.1   jruoho  *	%r28		LR
    257  1.12.2.1   jruoho  *	%r29		CR
    258  1.12.2.1   jruoho  *	%r1		kernel stack
    259       1.1   simonb  *	LR		trap type
    260       1.1   simonb  */
    261       1.1   simonb #define	FRAME_SETUP(savearea)						\
    262       1.1   simonb /* Have to enable translation to allow access of kernel stack: */	\
    263  1.12.2.1   jruoho 	ENABLE_TRANSLATION(%r30,%r31);					\
    264      1.12     matt 	mfsprg1	%r31;							\
    265      1.12     matt 	stwu	%r31,-FRAMELEN(%r1);					\
    266  1.12.2.1   jruoho 	stw	%r30,FRAME_PID(%r1);					\
    267  1.12.2.1   jruoho 	stw	%r0,FRAME_R0(%r1);					\
    268  1.12.2.1   jruoho 	stw	%r31,FRAME_R1(%r1);					\
    269  1.12.2.1   jruoho 	stw	%r2,FRAME_R2(%r1);					\
    270  1.12.2.1   jruoho 	GET_CPUINFO(%r2);						\
    271  1.12.2.1   jruoho 	stw	%r28,FRAME_LR(%r1);					\
    272  1.12.2.1   jruoho 	stw	%r29,FRAME_CR(%r1);					\
    273  1.12.2.1   jruoho 	lmw	%r28,(savearea+CPUSAVE_R28)(%r2);			\
    274  1.12.2.1   jruoho 	stmw	%r3,FRAME_R3(%r1);					\
    275  1.12.2.1   jruoho 	lmw	%r28,(savearea+CPUSAVE_DEAR)(%r2);			\
    276  1.12.2.1   jruoho 	lwz	%r13,CI_CURLWP(%r2);					\
    277      1.12     matt 	mfxer	%r3;							\
    278      1.12     matt 	mfctr	%r4;							\
    279      1.12     matt 	mflr	%r5;							\
    280      1.12     matt 	andi.	%r5,%r5,0xff00;						\
    281  1.12.2.1   jruoho 	stw	%r3,FRAME_XER(%r1);					\
    282  1.12.2.1   jruoho 	stw	%r4,FRAME_CTR(%r1);					\
    283  1.12.2.1   jruoho 	stw	%r5,FRAME_EXC(%r1);					\
    284  1.12.2.1   jruoho 	stw	%r28,FRAME_DEAR(%r1);					\
    285  1.12.2.1   jruoho 	stw	%r29,FRAME_ESR(%r1);					\
    286  1.12.2.1   jruoho 	stw	%r30,FRAME_SRR0(%r1);					\
    287  1.12.2.1   jruoho 	stw	%r31,FRAME_SRR1(%r1)
    288  1.12.2.1   jruoho 
    289  1.12.2.1   jruoho #define	FRAME_SAVE_CALLEE						\
    290  1.12.2.1   jruoho 	stmw	%r13, FRAME_R13(%r1)
    291  1.12.2.1   jruoho 
    292  1.12.2.1   jruoho #define	FRAME_RESTORE							\
    293  1.12.2.1   jruoho 	lwz	%r6,FRAME_LR(%r1);					\
    294  1.12.2.1   jruoho 	lwz	%r7,FRAME_CR(%r1);					\
    295  1.12.2.1   jruoho 	lwz	%r8,FRAME_XER(%r1);					\
    296  1.12.2.1   jruoho 	lwz	%r9,FRAME_CTR(%r1);					\
    297  1.12.2.1   jruoho 	lwz	%r10,FRAME_SRR0(%r1);					\
    298  1.12.2.1   jruoho 	lwz	%r11,FRAME_SRR1(%r1);					\
    299  1.12.2.1   jruoho 	mtlr	%r6;							\
    300  1.12.2.1   jruoho 	mtcr	%r7;							\
    301  1.12.2.1   jruoho 	mtxer	%r8;							\
    302  1.12.2.1   jruoho 	mtctr	%r9;							\
    303  1.12.2.1   jruoho 	mtsrr0	%r10;							\
    304  1.12.2.1   jruoho 	mtsrr1	%r11;							\
    305  1.12.2.1   jruoho 	lwz	%r13,FRAME_R13(%r1);					\
    306  1.12.2.1   jruoho 	lwz	%r12,FRAME_R12(%r1);					\
    307  1.12.2.1   jruoho 	lwz	%r11,FRAME_R11(%r1);					\
    308  1.12.2.1   jruoho 	lwz	%r10,FRAME_R10(%r1);					\
    309  1.12.2.1   jruoho 	lwz	%r9,FRAME_R9(%r1);					\
    310  1.12.2.1   jruoho 	lwz	%r8,FRAME_R8(%r1);					\
    311  1.12.2.1   jruoho 	lwz	%r7,FRAME_R7(%r1);					\
    312  1.12.2.1   jruoho 	lwz	%r6,FRAME_R6(%r1);					\
    313  1.12.2.1   jruoho 	lwz	%r5,FRAME_R5(%r1);					\
    314  1.12.2.1   jruoho 	lwz	%r4,FRAME_R4(%r1);					\
    315  1.12.2.1   jruoho 	lwz	%r3,FRAME_R3(%r1);					\
    316  1.12.2.1   jruoho 	lwz	%r2,FRAME_R2(%r1);					\
    317  1.12.2.1   jruoho 	lwz	%r0,FRAME_R1(%r1);					\
    318  1.12.2.1   jruoho 	mtsprg1	%r0;							\
    319  1.12.2.1   jruoho 	lwz	%r0,FRAME_R0(%r1)
    320  1.12.2.1   jruoho 
    321       1.1   simonb /*
    322       1.1   simonb  * Now the common trap catching code.
    323       1.1   simonb  */
    324       1.1   simonb s_trap:
    325  1.12.2.1   jruoho 	FRAME_SETUP(CI_TEMPSAVE)
    326  1.12.2.1   jruoho 	/* R31 = SRR1 */
    327       1.1   simonb /* Now we can recover interrupts again: */
    328       1.1   simonb trapagain:
    329  1.12.2.1   jruoho 	wrtee	%r31			/* reenable interrupts */
    330       1.1   simonb /* Call C trap code: */
    331  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_TF
    332       1.1   simonb 	bl	_C_LABEL(trap)
    333       1.2   simonb 	.globl	_C_LABEL(trapexit)
    334       1.2   simonb _C_LABEL(trapexit):
    335       1.1   simonb 	/* Disable interrupts: */
    336       1.1   simonb 	wrteei	0
    337  1.12.2.1   jruoho 
    338       1.1   simonb 	/* Test AST pending: */
    339  1.12.2.1   jruoho 	mtcr	%r31
    340  1.12.2.1   jruoho 	bf	MSR_PR,trapleave_to_kernel /* branch if MSR[PR] is false */
    341  1.12.2.1   jruoho 
    342  1.12.2.1   jruoho 	lwz	%r4,L_MD_ASTPENDING(%r13)
    343      1.12     matt 	andi.	%r4,%r4,1
    344  1.12.2.1   jruoho 	beq	trapleave_to_user
    345  1.12.2.1   jruoho 
    346      1.12     matt 	li	%r6,EXC_AST
    347  1.12.2.1   jruoho 	stw	%r6,FRAME_EXC(%r1)
    348       1.1   simonb 	b	trapagain
    349  1.12.2.1   jruoho 
    350  1.12.2.1   jruoho trapleave_to_kernel:
    351  1.12.2.1   jruoho 	lmw	%r14, FRAME_R14(%r1)	/* restore callee registers */
    352  1.12.2.1   jruoho 
    353  1.12.2.1   jruoho intrleave_to_kernel:
    354  1.12.2.1   jruoho 	FRAME_RESTORE		/* old SP is now in sprg1 */
    355  1.12.2.1   jruoho 	/*
    356  1.12.2.1   jruoho 	 * Now that we are done with the trapframe, we can load the original SP
    357  1.12.2.1   jruoho 	 */
    358  1.12.2.1   jruoho 	mfsprg1	%r1
    359       1.1   simonb 	rfi
    360  1.12.2.1   jruoho 	ba	.		/* Protect against prefetch */
    361  1.12.2.1   jruoho 
    362  1.12.2.1   jruoho trapleave_to_user:
    363  1.12.2.1   jruoho 	lmw	%r13, FRAME_R13(%r1)	/* restore callee registers */
    364       1.5      chs 
    365  1.12.2.1   jruoho intrleave_to_user:
    366  1.12.2.1   jruoho /* Now restore regs: */
    367  1.12.2.1   jruoho 	lwz	%r3,FRAME_PID(%r1)
    368  1.12.2.1   jruoho 	lwz	%r4,FRAME_SRR1(%r1)
    369  1.12.2.1   jruoho 	bl	_C_LABEL(ctx_setup)
    370  1.12.2.1   jruoho 	TRAP_IF_ZERO(%r3)
    371  1.12.2.1   jruoho 	stw	%r3,FRAME_PID(%r1)
    372  1.12.2.1   jruoho 
    373  1.12.2.1   jruoho 	FRAME_RESTORE		/* old SP is now in sprg1 */
    374  1.12.2.1   jruoho 
    375  1.12.2.1   jruoho 	/*
    376  1.12.2.1   jruoho 	 * We are returning to userspace so we need to switch PIDs.
    377  1.12.2.1   jruoho 	 * Since the kernel executes out of what would be userspace,
    378  1.12.2.1   jruoho 	 * we need to turn off translation before we set the PID.
    379  1.12.2.1   jruoho 	 *
    380  1.12.2.1   jruoho 	 * Alterantively, we could map a kernel page at 0xfffff000
    381  1.12.2.1   jruoho 	 * that had the mtpid code in it and branch to it and avoid
    382  1.12.2.1   jruoho 	 * all this.  (ba foo; foo: mtpid %r31; mfsprg3 %r31; rfi;)
    383  1.12.2.1   jruoho 	 */
    384  1.12.2.1   jruoho 	mfmsr	%r30
    385  1.12.2.1   jruoho 	li	%r31,(PSL_DR|PSL_IR)@l
    386  1.12.2.1   jruoho 	andc	%r30,%r30,%r31
    387  1.12.2.1   jruoho 	lwz	%r31,FRAME_PID(%r1)
    388  1.12.2.1   jruoho 	TRAP_IF_ZERO(%r31)
    389  1.12.2.1   jruoho 	/*
    390  1.12.2.1   jruoho 	 * Now that we are done with the trapframe, we can load the original SP
    391  1.12.2.1   jruoho 	 */
    392  1.12.2.1   jruoho 	mfsprg1	%r1
    393  1.12.2.1   jruoho 	mtmsr	%r30	/* disable translation */
    394  1.12.2.1   jruoho 	isync
    395  1.12.2.1   jruoho 	mtpid	%r31
    396  1.12.2.1   jruoho 	mfsprg3	%r31
    397  1.12.2.1   jruoho 	mfsprg2	%r30
    398  1.12.2.1   jruoho 	rfi
    399  1.12.2.1   jruoho 	ba	.	/* Protect against prefetch */
    400       1.5      chs 
    401       1.5      chs 
    402       1.8     matt 	.globl	_C_LABEL(sctrap),_C_LABEL(scsize),_C_LABEL(sctrapexit)
    403       1.5      chs _C_LABEL(sctrap):
    404  1.12.2.1   jruoho 	STANDARD_PROLOG(CI_TEMPSAVE)
    405       1.5      chs 	bla	s_sctrap
    406       1.5      chs _C_LABEL(scsize) = .-_C_LABEL(sctrap)
    407       1.5      chs 
    408       1.5      chs s_sctrap:
    409  1.12.2.1   jruoho 	FRAME_SETUP(CI_TEMPSAVE)
    410       1.5      chs /* Now we can recover interrupts again: */
    411       1.5      chs 	wrteei	1			/* Enable interrupts */
    412       1.5      chs /* Call the appropriate syscall handler: */
    413  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_TF
    414  1.12.2.1   jruoho 	lwz	%r4,L_PROC(%r13)
    415      1.12     matt 	lwz	%r4,P_MD_SYSCALL(%r4)
    416      1.12     matt 	mtctr	%r4
    417       1.5      chs 	bctrl
    418       1.8     matt _C_LABEL(sctrapexit):
    419  1.12.2.1   jruoho 	b	trapexit
    420       1.5      chs 
    421       1.1   simonb /*
    422       1.1   simonb  * External interrupt second level handler
    423       1.1   simonb  */
    424       1.4   simonb 
    425  1.12.2.1   jruoho #define	INTR_SAVE(tempsave)						\
    426       1.1   simonb /* Save non-volatile registers: */					\
    427  1.12.2.1   jruoho 	stwu	%r1,-FRAMELEN(%r1);	/* temporarily */		\
    428  1.12.2.1   jruoho 	stw	%r0,FRAME_R0(%r1);					\
    429      1.12     matt 	mfsprg1	%r0;			/* get original SP */		\
    430  1.12.2.1   jruoho 	stw	%r0,FRAME_R1(%r1);	/* and store it */		\
    431  1.12.2.1   jruoho 	stw	%r2,FRAME_R2(%r1);					\
    432  1.12.2.1   jruoho 	stw	%r3,FRAME_R3(%r1);					\
    433  1.12.2.1   jruoho 	stw	%r4,FRAME_R4(%r1);					\
    434  1.12.2.1   jruoho 	stw	%r5,FRAME_R5(%r1);					\
    435  1.12.2.1   jruoho 	stw	%r6,FRAME_R6(%r1);					\
    436  1.12.2.1   jruoho 	stw	%r7,FRAME_R7(%r1);					\
    437  1.12.2.1   jruoho 	stw	%r8,FRAME_R8(%r1);					\
    438  1.12.2.1   jruoho 	stw	%r9,FRAME_R9(%r1);					\
    439  1.12.2.1   jruoho 	stw	%r10,FRAME_R10(%r1);					\
    440  1.12.2.1   jruoho 	stw	%r11,FRAME_R11(%r1);					\
    441  1.12.2.1   jruoho 	stw	%r12,FRAME_R12(%r1);					\
    442  1.12.2.1   jruoho 	mfctr	%r31;							\
    443  1.12.2.1   jruoho 	stmw	%r28,FRAME_LR(%r1);	/* save LR, CR, XER, CTR */	\
    444      1.12     matt 	GET_CPUINFO(%r5);						\
    445  1.12.2.1   jruoho 	lmw	%r28,(tempsave+CPUSAVE_R28)(%r5); /* restore r28-r31 */	\
    446  1.12.2.1   jruoho 	lwz	%r13,CI_CURLWP(%r5);					\
    447  1.12.2.1   jruoho 	lwz	%r5,CI_IDEPTH(%r5);					\
    448      1.12     matt 	mfsrr0	%r4;							\
    449      1.12     matt 	mfsrr1	%r3;							\
    450  1.12.2.1   jruoho 	stw	%r5,FRAME_IDEPTH(%r1);					\
    451  1.12.2.1   jruoho 	stw	%r4,FRAME_SRR0(%r1);					\
    452  1.12.2.1   jruoho 	stw	%r3,FRAME_SRR1(%r1);					\
    453       1.1   simonb /* interrupts are recoverable here, and enable translation */		\
    454  1.12.2.1   jruoho 	ENABLE_TRANSLATION(%r0,%r5);					\
    455  1.12.2.1   jruoho 	stw	%r0,FRAME_PID(%r1);					\
    456       1.1   simonb 
    457       1.1   simonb 	.globl	_C_LABEL(extint_call)
    458       1.1   simonb extintr:
    459  1.12.2.1   jruoho 	INTR_SAVE(CI_TEMPSAVE)
    460       1.1   simonb _C_LABEL(extint_call):
    461       1.1   simonb 	bl	_C_LABEL(extint_call)	/* to be filled in later */
    462       1.1   simonb 
    463       1.1   simonb intr_exit:
    464  1.12.2.1   jruoho /* Disable interrupts */
    465       1.1   simonb 	wrteei	0
    466       1.1   simonb 	isync
    467      1.12     matt 	GET_CPUINFO(%r5)
    468  1.12.2.1   jruoho 	lwz	%r4,CI_IDEPTH(%r5)
    469      1.12     matt 	addi	%r4,%r4,-1		/* adjust reentrancy count */
    470  1.12.2.1   jruoho 	stw	%r4,CI_IDEPTH(%r5)
    471  1.12.2.1   jruoho 
    472  1.12.2.1   jruoho 	lwz	%r4,FRAME_SRR1(%r1)
    473  1.12.2.1   jruoho /* Returning to user mode? */
    474  1.12.2.1   jruoho 	mtcr	%r4			/* saved SRR1 */
    475  1.12.2.1   jruoho 	bf	MSR_PR,intrleave_to_kernel /* branch if MSR[PR] is false */
    476  1.12.2.1   jruoho 
    477  1.12.2.1   jruoho 	lwz	%r4,L_MD_ASTPENDING(%r13)/* Test AST pending */
    478  1.12.2.1   jruoho 	andi.	%r4,%r4,1
    479  1.12.2.1   jruoho 	beq	intrleave_to_user
    480  1.12.2.1   jruoho 
    481  1.12.2.1   jruoho 	FRAME_SAVE_CALLEE		/* save rest of callee registers */
    482      1.12     matt 	li	%r6,EXC_AST
    483  1.12.2.1   jruoho 	stw	%r6,FRAME_EXC(%r1)
    484  1.12.2.1   jruoho 	mr	%r31,%r5		/* move SRR1 to R31 */
    485  1.12.2.1   jruoho 	b	trapagain
    486       1.4   simonb 
    487       1.1   simonb /*
    488       1.1   simonb  * PIT interrupt handler.
    489       1.1   simonb  */
    490       1.1   simonb 	.align	5
    491       1.1   simonb _C_LABEL(pitint):
    492  1.12.2.1   jruoho 	INTR_PROLOG(CI_TEMPSAVE)
    493  1.12.2.1   jruoho 	INTR_SAVE(CI_TEMPSAVE)
    494  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_CF	/* intr frame */
    495       1.1   simonb 	bl	_C_LABEL(decr_intr)
    496       1.1   simonb 	b	intr_exit
    497       1.1   simonb 
    498       1.1   simonb /*
    499       1.1   simonb  * FIT interrupt handler.
    500       1.1   simonb  */
    501       1.1   simonb 	.align	5
    502  1.12.2.1   jruoho _C_LABEL(fitint):
    503  1.12.2.1   jruoho 	INTR_PROLOG(CI_TEMPSAVE)
    504  1.12.2.1   jruoho 	INTR_SAVE(CI_TEMPSAVE)
    505  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_TF	/* intr frame */
    506       1.1   simonb 	bl	_C_LABEL(stat_intr)
    507       1.1   simonb 	b	intr_exit
    508       1.1   simonb 
    509      1.11  garbled #if defined(DDB) || defined(KGDB)
    510       1.1   simonb /*
    511       1.1   simonb  * Deliberate entry to ddbtrap
    512       1.1   simonb  */
    513       1.1   simonb 	.globl	_C_LABEL(ddb_trap)
    514       1.1   simonb _C_LABEL(ddb_trap):
    515      1.12     matt 	mtsprg1	%r1
    516  1.12.2.1   jruoho 	GET_CPUINFO(%r4)
    517      1.12     matt 	mfmsr	%r3
    518  1.12.2.1   jruoho 	stw	%r3,CI_DDBSAVE+CPUSAVE_SRR1(%r4)
    519       1.1   simonb 	wrteei	0			/* disable interrupts */
    520       1.1   simonb 	isync
    521  1.12.2.1   jruoho 	stmw	%r28,CI_DDBSAVE(%r1)
    522      1.12     matt 	mflr	%r28
    523  1.12.2.1   jruoho 	stw	%r28,CI_DDBSAVE+CPUSAVE_SRR0(%r4)
    524      1.12     matt 	li	%r29,EXC_BPT
    525      1.12     matt 	mtlr	%r29
    526      1.12     matt 	mfcr	%r29
    527       1.1   simonb 
    528       1.1   simonb /*
    529      1.11  garbled  * Now the ddb/kgdb trap catching code.
    530       1.1   simonb  */
    531       1.1   simonb ddbtrap:
    532  1.12.2.1   jruoho 	FRAME_SETUP(CI_DDBSAVE)
    533       1.1   simonb /* Call C trap code: */
    534  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_TF
    535       1.1   simonb 	bl	_C_LABEL(ddb_trap_glue)
    536      1.12     matt 	or.	%r3,%r3,%r3
    537  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_TF
    538  1.12.2.1   jruoho 	beq	trapagain
    539  1.12.2.1   jruoho 	b	trapexit
    540      1.11  garbled #endif /* DDB || KGDB */
    541       1.1   simonb 
    542       1.1   simonb #ifdef IPKDB
    543       1.1   simonb /*
    544       1.1   simonb  * Deliberate entry to ipkdbtrap
    545       1.1   simonb  */
    546       1.1   simonb 	.globl	_C_LABEL(ipkdb_trap)
    547       1.1   simonb _C_LABEL(ipkdb_trap):
    548      1.12     matt 	mtsprg1	%r1
    549  1.12.2.1   jruoho 	GET_CPUINFO(%r4)
    550      1.12     matt 	mfmsr	%r3
    551  1.12.2.1   jruoho 	stw	%r3,(CI_IPKDBSAVE+CPUSAVE_SRR1)(%r4)
    552       1.1   simonb 	wrteei	0			/* disable interrupts */
    553       1.1   simonb 	isync
    554  1.12.2.1   jruoho 	stmw	%r28,CI_IPKDBSAVE(%r4)
    555      1.12     matt 	mflr	%r28
    556  1.12.2.1   jruoho 	stw	%r28,(CI_IPKDBSAVE+CPUSAVE_SRR0)(%r4)
    557      1.12     matt 	li	%r29,EXC_BPT
    558      1.12     matt 	mtlr	%r29
    559      1.12     matt 	mfcr	%r29
    560       1.1   simonb 
    561       1.1   simonb /*
    562       1.1   simonb  * Now the ipkdb trap catching code.
    563       1.1   simonb  */
    564       1.1   simonb ipkdbtrap:
    565  1.12.2.1   jruoho 	FRAME_SETUP(CI_IPKDBSAVE)
    566       1.1   simonb /* Call C trap code: */
    567  1.12.2.1   jruoho 	addi	%r3,%r1,FRAME_TF
    568       1.1   simonb 	bl	_C_LABEL(ipkdb_trap_glue)
    569      1.12     matt 	or.	%r3,%r3,%r3
    570  1.12.2.1   jruoho 	beq	trapagain
    571  1.12.2.1   jruoho 	b	trapexit
    572       1.1   simonb 
    573       1.1   simonb ipkdbfault:
    574       1.1   simonb 	ba	_ipkdbfault
    575       1.1   simonb _ipkdbfault:
    576      1.12     matt 	mfsrr0	%r3
    577      1.12     matt 	addi	%r3,%r3,4
    578      1.12     matt 	mtsrr0	%r3
    579      1.12     matt 	li	%r3,-1
    580       1.1   simonb 	rfi
    581       1.1   simonb 	ba	.	/* Protect against prefetch */
    582       1.1   simonb 
    583       1.1   simonb /*
    584       1.1   simonb  * int ipkdbfbyte(unsigned char *p)
    585       1.1   simonb  */
    586       1.1   simonb 	.globl	_C_LABEL(ipkdbfbyte)
    587       1.1   simonb _C_LABEL(ipkdbfbyte):
    588      1.12     matt 	li	%r9,EXC_DSI		/* establish new fault routine */
    589      1.12     matt 	lwz	%r5,0(%r9)
    590      1.12     matt 	lis	%r6,ipkdbfault@ha
    591      1.12     matt 	lwz	%r6,ipkdbfault@l(%r6)
    592      1.12     matt 	stw	%r6,0(%r9)
    593       1.1   simonb #ifdef	IPKDBUSERHACK
    594       1.1   simonb #ifndef PPC_IBM4XX
    595      1.12     matt 	lis	%r8,_C_LABEL(ipkdbsr)@ha
    596      1.12     matt 	lwz	%r8,_C_LABEL(ipkdbsr)@l(%r8)
    597      1.12     matt 	mtsr	USER_SR,%r8
    598       1.1   simonb 	isync
    599       1.4   simonb #endif
    600       1.1   simonb #endif
    601      1.12     matt 	dcbst	%r0,%r9			/* flush data... */
    602       1.1   simonb 	sync
    603      1.12     matt 	icbi	%r0,%r9			/* and instruction caches */
    604      1.12     matt 	lbz	%r3,0(%r3)		/* fetch data */
    605      1.12     matt 	stw	%r5,0(%r9)		/* restore previous fault handler */
    606      1.12     matt 	dcbst	%r0,%r9			/* and flush data... */
    607       1.1   simonb 	sync
    608      1.12     matt 	icbi	%r0,%r9			/* and instruction caches */
    609       1.1   simonb 	blr
    610       1.1   simonb 
    611       1.1   simonb /*
    612       1.1   simonb  * int ipkdbsbyte(unsigned char *p, int c)
    613       1.1   simonb  */
    614       1.1   simonb 	.globl	_C_LABEL(ipkdbsbyte)
    615       1.1   simonb _C_LABEL(ipkdbsbyte):
    616      1.12     matt 	li	%r9,EXC_DSI		/* establish new fault routine */
    617      1.12     matt 	lwz	%r5,0(%r9)
    618      1.12     matt 	lis	%r6,ipkdbfault@ha
    619      1.12     matt 	lwz	%r6,ipkdbfault@l(%r6)
    620      1.12     matt 	stw	%r6,0(%r9)
    621       1.1   simonb #ifdef	IPKDBUSERHACK
    622       1.1   simonb #ifndef PPC_IBM4XX
    623      1.12     matt 	lis	%r8,_C_LABEL(ipkdbsr)@ha
    624      1.12     matt 	lwz	%r8,_C_LABEL(ipkdbsr)@l(%r8)
    625      1.12     matt 	mtsr	USER_SR,%r8
    626       1.1   simonb 	isync
    627       1.4   simonb #endif
    628       1.1   simonb #endif
    629      1.12     matt 	dcbst	%r0,%r9			/* flush data... */
    630       1.1   simonb 	sync
    631      1.12     matt 	icbi	%r0,%r9			/* and instruction caches */
    632      1.12     matt 	mr	%r6,%r3
    633      1.12     matt 	xor	%r3,%r3,%r3
    634      1.12     matt 	stb	%r4,0(%r6)
    635      1.12     matt 	dcbst	%r0,%r6			/* Now do appropriate flushes
    636       1.1   simonb 					   to data... */
    637       1.1   simonb 	sync
    638      1.12     matt 	icbi	%r0,%r6			/* and instruction caches */
    639      1.12     matt 	stw	%r5,0(%r9)		/* restore previous fault handler */
    640      1.12     matt 	dcbst	%r0,%r9			/* and flush data... */
    641       1.1   simonb 	sync
    642      1.12     matt 	icbi	%r0,%r9			/* and instruction caches */
    643       1.1   simonb 	blr
    644       1.1   simonb #endif	/* IPKDB */
    645