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