Home | History | Annotate | Line # | Download | only in ibm4xx
trap_subr.S revision 1.10
      1  1.10  christos /*	$NetBSD: trap_subr.S,v 1.10 2005/12/11 12:18:42 christos 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  * Data used during primary/secondary traps/interrupts
     78   1.1    simonb  */
     79   1.1    simonb #define	tempsave	0x2e0	/* primary save area for trap handling */
     80   1.1    simonb #define	disisave	0x3e0	/* primary save area for dsi/isi traps */
     81   1.1    simonb #define	exitsave	0x4e0	/* use this so trap return does not conflict */
     82   1.1    simonb /*
     83   1.1    simonb  * XXX Interrupt and spill stacks need to be per-CPU.
     84   1.1    simonb  */
     85   1.1    simonb 
     86   1.4    simonb #define	GET_PCB(rX)	\
     87   1.1    simonb 	GET_CPUINFO(rX);	\
     88   1.1    simonb 	lwz	rX,CI_CURPCB(rX)
     89   1.1    simonb 
     90   1.1    simonb #define	STANDARD_PROLOG(savearea)	\
     91   1.1    simonb 	mtsprg	1,1;			/* save SP */ 		\
     92   1.1    simonb 	stmw	28,savearea(0);		/* free r28-r31 */	\
     93   1.1    simonb 	mflr	28;			/* save LR */		\
     94   1.1    simonb 	mfcr	29;			/* save CR */		\
     95   1.1    simonb 	mfsrr1	31; /* Test whether we already had PR set */	\
     96   1.1    simonb 	mtcr	31;						\
     97   1.1    simonb 	bc	4,17,1f;	/* branch if PSL_PR is clear */	\
     98   1.1    simonb 	GET_PCB(1);						\
     99   1.1    simonb 	addi	1,1,USPACE;	/* stack is top of user struct */ \
    100   1.1    simonb 1:
    101   1.4    simonb 
    102   1.1    simonb #define	CRITICAL_PROLOG(savearea)	\
    103   1.1    simonb 	mtsprg	1,1;			/* save SP */ 		\
    104   1.1    simonb 	stmw	28,savearea(0);		/* free r28-r31 */	\
    105   1.1    simonb 	mflr	28;			/* save LR */		\
    106   1.1    simonb 	mfcr	29;			/* save CR */		\
    107   1.1    simonb 	mfsrr2	30; /* Fake a standard trap */			\
    108   1.1    simonb 	mtsrr0	30;						\
    109   1.1    simonb 	mfsrr3	31; /* Test whether we already had PR set */	\
    110   1.1    simonb 	mtsrr1	31;						\
    111   1.1    simonb 	mtcr	31;						\
    112   1.1    simonb 	bc	4,17,1f;	/* branch if PSL_PR is clear */	\
    113   1.1    simonb 	GET_PCB(1);						\
    114   1.1    simonb 	addi	1,1,USPACE;	/* stack is top of user struct */ \
    115   1.1    simonb 1:
    116   1.1    simonb 
    117   1.1    simonb 
    118   1.4    simonb /* Standard handler saves r1,r28-31,LR,CR, sets up the stack and calls s_trap */
    119   1.1    simonb #define STANDARD_EXC_HANDLER(name)\
    120   1.1    simonb 	.globl	_C_LABEL(name ## trap),_C_LABEL(name ## size) ;	\
    121   1.1    simonb _C_LABEL(name ## trap):						\
    122   1.1    simonb 	STANDARD_PROLOG(tempsave);				\
    123   1.1    simonb 	bla	s_trap  ;					\
    124   1.1    simonb _C_LABEL(name ## size) = .-_C_LABEL(name ## trap)
    125   1.1    simonb 
    126   1.4    simonb /* Access exceptions also need DEAR and ESR saved */
    127   1.1    simonb #define ACCESS_EXC_HANDLER(name)\
    128   1.1    simonb 	.globl	_C_LABEL(name ## trap),_C_LABEL(name ## size) ;	\
    129   1.1    simonb _C_LABEL(name ## trap):						\
    130   1.1    simonb 	STANDARD_PROLOG(tempsave);				\
    131   1.1    simonb 	mfdear	30;						\
    132   1.1    simonb 	mfesr	31;						\
    133   1.1    simonb 	stmw	30,16+tempsave(0);				\
    134   1.1    simonb 	bla	s_trap  ;					\
    135   1.1    simonb _C_LABEL(name ## size) = .-_C_LABEL(name ## trap)
    136   1.1    simonb 
    137   1.1    simonb /* Maybe this should call ddb.... */
    138   1.1    simonb #define CRITICAL_EXC_HANDLER(name)\
    139   1.1    simonb 	.globl	_C_LABEL(name ## trap),_C_LABEL(name ## size) ;	\
    140   1.1    simonb _C_LABEL(name ## trap):						\
    141   1.1    simonb 	CRITICAL_PROLOG(tempsave);				\
    142   1.1    simonb 	bla	s_trap  ;					\
    143   1.1    simonb _C_LABEL(name ## size) = .-_C_LABEL(name ## trap)
    144   1.4    simonb 
    145   1.1    simonb /*
    146   1.1    simonb  * This code gets copied to all the trap vectors
    147   1.4    simonb  * (except ISI/DSI, ALI, the interrupts, and possibly the debugging
    148   1.1    simonb  * traps when using IPKDB).
    149   1.1    simonb  */
    150   1.1    simonb 	.text
    151   1.1    simonb 	STANDARD_EXC_HANDLER(default)
    152   1.1    simonb 	ACCESS_EXC_HANDLER(ali)
    153   1.1    simonb 	ACCESS_EXC_HANDLER(dsi)
    154   1.1    simonb 	ACCESS_EXC_HANDLER(isi)
    155   1.1    simonb 	STANDARD_EXC_HANDLER(debug)
    156   1.3       eeh 	CRITICAL_EXC_HANDLER(mchk)
    157   1.1    simonb 
    158   1.1    simonb /*
    159   1.1    simonb  * This one for the external interrupt handler.
    160   1.1    simonb  */
    161   1.1    simonb 	.globl	_C_LABEL(extint),_C_LABEL(extsize)
    162   1.1    simonb _C_LABEL(extint):
    163   1.1    simonb 	mtsprg	1,1			/* save SP */
    164   1.1    simonb 	stmw	28,tempsave(0)		/* free r28-r31 */
    165   1.1    simonb 	mflr	28			/* save LR */
    166   1.1    simonb 	mfcr	29			/* save CR */
    167   1.1    simonb 	mfxer	30			/* save XER */
    168   1.7      matt 	GET_CPUINFO(1)
    169   1.7      matt 	lwz	31,CI_INTRDEPTH(1)	/* were we already running on intstk? */
    170   1.1    simonb 	addic.	31,31,1
    171   1.7      matt 	stw	31,CI_INTRDEPTH(1)
    172   1.7      matt 	lwz	1,CI_INTSTK(1)		/* get intstk */
    173   1.1    simonb 	beq	1f
    174   1.1    simonb 	mfsprg	1,1			/* yes, get old SP */
    175   1.1    simonb 1:
    176   1.1    simonb 	ba	extintr
    177   1.1    simonb _C_LABEL(extsize) = .-_C_LABEL(extint)
    178   1.1    simonb 
    179   1.4    simonb 
    180   1.1    simonb #ifdef DDB
    181   1.1    simonb #define	ddbsave	0xde0		/* primary save area for DDB */
    182   1.1    simonb /*
    183   1.1    simonb  * In case of DDB we want a separate trap catcher for it
    184   1.1    simonb  */
    185   1.1    simonb 	.local	ddbstk
    186   1.1    simonb 	.comm	ddbstk,INTSTK,8		/* ddb stack */
    187   1.1    simonb 
    188   1.1    simonb 	.globl	_C_LABEL(ddblow),_C_LABEL(ddbsize)
    189   1.1    simonb _C_LABEL(ddblow):
    190   1.1    simonb 	mtsprg	1,1			/* save SP */
    191   1.1    simonb 	stmw	28,ddbsave(0)		/* free r28-r31 */
    192   1.1    simonb 	mflr	28			/* save LR */
    193   1.1    simonb 	mfcr	29			/* save CR */
    194   1.1    simonb 	lis	1,ddbstk+INTSTK@ha	/* get new SP */
    195   1.1    simonb 	addi	1,1,ddbstk+INTSTK@l
    196   1.1    simonb 	bla	ddbtrap
    197   1.1    simonb _C_LABEL(ddbsize) = .-_C_LABEL(ddblow)
    198   1.1    simonb #endif	/* DDB */
    199   1.1    simonb 
    200   1.1    simonb #ifdef IPKDB
    201   1.1    simonb #define	ipkdbsave	0xde0		/* primary save area for IPKDB */
    202   1.1    simonb /*
    203   1.1    simonb  * In case of IPKDB we want a separate trap catcher for it
    204   1.1    simonb  */
    205   1.1    simonb 
    206   1.1    simonb 	.local	ipkdbstk
    207   1.1    simonb 	.comm	ipkdbstk,INTSTK,8		/* ipkdb stack */
    208   1.1    simonb 
    209   1.1    simonb 	.globl	_C_LABEL(ipkdblow),_C_LABEL(ipkdbsize)
    210   1.1    simonb _C_LABEL(ipkdblow):
    211   1.1    simonb 	mtsprg	1,1			/* save SP */
    212   1.1    simonb 	stmw	28,ipkdbsave(0)		/* free r28-r31 */
    213   1.1    simonb 	mflr	28			/* save LR */
    214   1.1    simonb 	mfcr	29			/* save CR */
    215   1.1    simonb 	lis	1,ipkdbstk+INTSTK@ha	/* get new SP */
    216   1.1    simonb 	addi	1,1,ipkdbstk+INTSTK@l
    217   1.1    simonb 	bla	ipkdbtrap
    218   1.1    simonb _C_LABEL(ipkdbsize) = .-_C_LABEL(ipkdblow)
    219   1.1    simonb #endif	/* IPKDB */
    220   1.1    simonb 
    221   1.1    simonb #ifdef DEBUG
    222   1.1    simonb #define TRAP_IF_ZERO(r)	tweqi	r,0
    223   1.1    simonb #else
    224   1.1    simonb #define TRAP_IF_ZERO(r)
    225   1.1    simonb #endif
    226   1.4    simonb 
    227   1.1    simonb /*
    228   1.1    simonb  * FRAME_SETUP assumes:
    229   1.1    simonb  *	SPRG1		SP (1)
    230   1.1    simonb  *	savearea	r28-r31,DEAR,ESR (DEAR & ESR only for DSI traps)
    231   1.1    simonb  *	28		LR
    232   1.1    simonb  *	29		CR
    233   1.1    simonb  *	1		kernel stack
    234   1.1    simonb  *	LR		trap type
    235   1.1    simonb  *	SRR0/1		as at start of trap
    236   1.1    simonb  */
    237   1.1    simonb #define	FRAME_SETUP(savearea)						\
    238   1.1    simonb /* Have to enable translation to allow access of kernel stack: */	\
    239   1.1    simonb 	mfsrr0	30;							\
    240   1.1    simonb 	mfsrr1	31;							\
    241   1.1    simonb 	stmw	30,savearea+24(0);					\
    242   1.1    simonb 	mfpid	30;							\
    243   1.1    simonb 	li	31,KERNEL_PID;						\
    244   1.1    simonb 	mtpid	31;							\
    245   1.1    simonb 	mfmsr	31;							\
    246   1.1    simonb 	ori	31,31,(PSL_DR|PSL_IR)@l;				\
    247   1.1    simonb 	mtmsr	31;							\
    248   1.1    simonb 	isync;								\
    249   1.1    simonb 	mfsprg	31,1;							\
    250   1.1    simonb 	stwu	31,-FRAMELEN(1);					\
    251   1.1    simonb 	stw	30,FRAME_PID+8(1);					\
    252   1.1    simonb 	stw	0,FRAME_0+8(1);						\
    253   1.1    simonb 	stw	31,FRAME_1+8(1);					\
    254   1.1    simonb 	stw	28,FRAME_LR+8(1);					\
    255   1.1    simonb 	stw	29,FRAME_CR+8(1);					\
    256   1.1    simonb 	lmw	28,savearea(0);						\
    257   1.1    simonb 	stmw	2,FRAME_2+8(1);						\
    258   1.1    simonb 	lmw	28,savearea+16(0);					\
    259   1.1    simonb 	mfxer	3;							\
    260   1.1    simonb 	mfctr	4;							\
    261   1.1    simonb 	mflr	5;							\
    262   1.1    simonb 	andi.	5,5,0xff00;						\
    263   1.1    simonb 	stw	3,FRAME_XER+8(1);					\
    264   1.1    simonb 	stw	4,FRAME_CTR+8(1);					\
    265   1.1    simonb 	stw	5,FRAME_EXC+8(1);					\
    266   1.1    simonb 	stw	28,FRAME_DEAR+8(1);					\
    267   1.1    simonb 	stw	29,FRAME_ESR+8(1);					\
    268   1.1    simonb 	stw	30,FRAME_SRR0+8(1);					\
    269   1.1    simonb 	stw	31,FRAME_SRR1+8(1)
    270   1.1    simonb 
    271   1.1    simonb #define	FRAME_LEAVE(savearea)						\
    272   1.1    simonb /* Now restore regs: */							\
    273   1.1    simonb 	lwz	3,FRAME_PID+8(1);					\
    274   1.1    simonb 	lwz	4,FRAME_SRR1+8(1);					\
    275   1.1    simonb 	bl	_C_LABEL(ctx_setup);					\
    276   1.9       chs 	TRAP_IF_ZERO(3);						\
    277   1.1    simonb 	stw	3,FRAME_PID+8(1);					\
    278   1.1    simonb 	lmw	26,FRAME_LR+8(1);					\
    279   1.1    simonb 	mtlr	26;							\
    280   1.1    simonb 	mtcr	27;							\
    281   1.1    simonb 	mtxer	28;							\
    282   1.1    simonb 	mtctr	29;							\
    283   1.1    simonb 	mtsrr0	30;							\
    284   1.1    simonb 	mtsrr1	31;							\
    285   1.1    simonb 	lmw	2,FRAME_2+8(1);						\
    286   1.1    simonb 	lwz	0,FRAME_0+8(1);						\
    287   1.1    simonb 	stmw	29,savearea(0);						\
    288   1.1    simonb 	lwz	30,FRAME_PID+8(1);					\
    289   1.1    simonb 	lwz	1,FRAME_1+8(1);						\
    290   1.1    simonb 	mfmsr	31;							\
    291   1.1    simonb 	li	29,(PSL_DR|PSL_IR)@l;					\
    292   1.1    simonb 	andc	31,31,29;						\
    293   1.1    simonb 	mfcr	29;							\
    294   1.1    simonb 	mtcr	29;							\
    295   1.1    simonb 	mtmsr	31;							\
    296   1.1    simonb 	isync;								\
    297   1.9       chs 	TRAP_IF_ZERO(30);						\
    298   1.1    simonb 	mtpid	30;							\
    299   1.1    simonb 	lmw	29,savearea(0)
    300   1.1    simonb 
    301   1.1    simonb realtrap:	/* entry point after IPKDB is done with exception */
    302   1.1    simonb 	/* Test whether we already had PR set */
    303   1.4    simonb 	mfsrr1	1
    304   1.4    simonb 	mtcr	1
    305   1.4    simonb 	mfsprg	1,1			/* restore SP (might have been
    306   1.4    simonb 					   overwritten) */
    307   1.4    simonb 	bc	4,17,s_trap		/* branch if PSL_PR is false */
    308   1.7      matt 	GET_PCB(1)
    309   1.4    simonb 	addi	1,1,USPACE		/* stack is top of user struct */
    310   1.1    simonb /*
    311   1.1    simonb  * Now the common trap catching code.
    312   1.1    simonb  */
    313   1.1    simonb s_trap:
    314   1.1    simonb 	FRAME_SETUP(tempsave)
    315   1.1    simonb /* Now we can recover interrupts again: */
    316   1.1    simonb trapagain:
    317   1.1    simonb 	wrteei	1			/* Enable interrupts */
    318   1.1    simonb /* Call C trap code: */
    319   1.1    simonb 	addi	3,1,8
    320   1.1    simonb 	bl	_C_LABEL(trap)
    321   1.2    simonb 	.globl	_C_LABEL(trapexit)
    322   1.2    simonb _C_LABEL(trapexit):
    323   1.1    simonb 	/* Disable interrupts: */
    324   1.1    simonb 	wrteei	0
    325   1.1    simonb 	/* Test AST pending: */
    326   1.1    simonb 	lwz	5,FRAME_SRR1+8(1)
    327   1.1    simonb 	mtcr	5
    328   1.1    simonb 	bc	4,17,1f			/* branch if PSL_PR is false */
    329   1.1    simonb 	GET_CPUINFO(3)
    330   1.1    simonb 	lwz	4,CI_ASTPENDING(3)
    331   1.1    simonb 	andi.	4,4,1
    332   1.1    simonb 	beq	1f
    333   1.1    simonb 	li	6,EXC_AST
    334   1.1    simonb 	stw	6,FRAME_EXC+8(1)
    335   1.1    simonb 	b	trapagain
    336   1.1    simonb 1:
    337   1.1    simonb 	FRAME_LEAVE(exitsave)
    338   1.1    simonb 	rfi
    339   1.1    simonb 	ba	.	/* Protect against prefetch */
    340   1.5       chs 
    341   1.5       chs 
    342   1.5       chs 
    343   1.8      matt 	.globl	_C_LABEL(sctrap),_C_LABEL(scsize),_C_LABEL(sctrapexit)
    344   1.5       chs _C_LABEL(sctrap):
    345   1.5       chs 	STANDARD_PROLOG(tempsave);
    346   1.5       chs 	bla	s_sctrap
    347   1.5       chs _C_LABEL(scsize) = .-_C_LABEL(sctrap)
    348   1.5       chs 
    349   1.5       chs s_sctrap:
    350   1.5       chs 	FRAME_SETUP(tempsave)
    351   1.5       chs /* Now we can recover interrupts again: */
    352   1.5       chs 	wrteei	1			/* Enable interrupts */
    353   1.5       chs /* Call the appropriate syscall handler: */
    354   1.5       chs 	addi	3,1,8
    355   1.7      matt 	GET_CPUINFO(4)
    356   1.7      matt 	lwz	4,CI_CURLWP(4)
    357   1.7      matt 	lwz	4,L_PROC(4)
    358   1.7      matt 	lwz	4,P_MD_SYSCALL(4)
    359   1.5       chs 	mtctr	4
    360   1.5       chs 	bctrl
    361   1.8      matt _C_LABEL(sctrapexit):
    362   1.5       chs /* Disable interrupts: */
    363   1.5       chs 	wrteei	0
    364   1.5       chs /* Test AST pending: */
    365   1.5       chs 	lwz	5,FRAME_SRR1+8(1)
    366   1.5       chs 	mtcr	5
    367   1.5       chs 	bc	4,17,1f			/* branch if PSL_PR is false */
    368   1.5       chs 	GET_CPUINFO(3)
    369   1.5       chs 	lwz	4,CI_ASTPENDING(3)
    370   1.5       chs 	andi.	4,4,1
    371   1.5       chs 	beq	1f
    372   1.5       chs 	li	6,EXC_AST
    373   1.5       chs 	stw	6,FRAME_EXC+8(1)
    374   1.5       chs 	b	trapagain
    375   1.5       chs 1:
    376   1.5       chs 	FRAME_LEAVE(exitsave)
    377   1.5       chs 	rfi
    378   1.5       chs 	ba	.	/* Protect against prefetch */
    379   1.5       chs 
    380   1.5       chs 
    381   1.1    simonb /*
    382   1.1    simonb  * External interrupt second level handler
    383   1.1    simonb  */
    384   1.4    simonb 
    385   1.1    simonb #define	INTRENTER							\
    386   1.1    simonb /* Save non-volatile registers: */					\
    387   1.7      matt 	stwu	1,-IFRAMELEN(1);	/* temporarily */		\
    388   1.7      matt 	stw	0,IFRAME_R0(1);						\
    389   1.1    simonb 	mfsprg	0,1;			/* get original SP */		\
    390   1.7      matt 	stw	0,IFRAME_R1(1);		/* and store it */		\
    391   1.7      matt 	stw	3,IFRAME_R3(1);						\
    392   1.7      matt 	stw	4,IFRAME_R4(1);						\
    393   1.7      matt 	stw	5,IFRAME_R5(1);						\
    394   1.7      matt 	stw	6,IFRAME_R6(1);						\
    395   1.7      matt 	stw	7,IFRAME_R7(1);						\
    396   1.7      matt 	stw	8,IFRAME_R8(1);						\
    397   1.7      matt 	stw	9,IFRAME_R9(1);						\
    398   1.7      matt 	stw	10,IFRAME_R10(1);					\
    399   1.7      matt 	stw	11,IFRAME_R11(1);					\
    400   1.7      matt 	stw	12,IFRAME_R12(1);					\
    401   1.7      matt 	stw	28,IFRAME_LR(1);	/* saved LR */			\
    402   1.7      matt 	stw	29,IFRAME_CR(1);	/* saved CR */			\
    403   1.7      matt 	stw	30,IFRAME_XER(1);	/* saved XER */			\
    404   1.1    simonb 	lmw	28,tempsave(0);		/* restore r28-r31 */		\
    405   1.1    simonb 	mfctr	6;							\
    406   1.7      matt 	GET_CPUINFO(5);							\
    407   1.7      matt 	lwz	5,CI_INTRDEPTH(5);					\
    408   1.1    simonb 	mfsrr0	4;							\
    409   1.1    simonb 	mfsrr1	3;							\
    410   1.7      matt 	stw	6,IFRAME_CTR(1);					\
    411   1.7      matt 	stw	5,IFRAME_INTR_DEPTH(1);					\
    412   1.7      matt 	stw	4,IFRAME_SRR0(1);					\
    413   1.7      matt 	stw	3,IFRAME_SRR1(1);					\
    414   1.1    simonb 	mfpid	0;			/* get currect PID register */  \
    415   1.7      matt 	stw	0,IFRAME_PID(1);					\
    416   1.7      matt 	li	0,KERNEL_PID;						\
    417   1.1    simonb 	mtpid	0;							\
    418   1.1    simonb /* interrupts are recoverable here, and enable translation */		\
    419   1.1    simonb 	mfmsr	5;							\
    420   1.1    simonb 	ori	5,5,(PSL_IR|PSL_DR);					\
    421   1.1    simonb 	mtmsr	5;							\
    422   1.1    simonb 	isync
    423   1.1    simonb 
    424   1.1    simonb 	.globl	_C_LABEL(extint_call)
    425   1.1    simonb extintr:
    426   1.1    simonb 	INTRENTER
    427   1.1    simonb _C_LABEL(extint_call):
    428   1.1    simonb 	bl	_C_LABEL(extint_call)	/* to be filled in later */
    429   1.1    simonb 
    430   1.1    simonb intr_exit:
    431   1.1    simonb /* Disable interrupts (should already be disabled) and MMU here: */
    432   1.1    simonb 	wrteei	0
    433   1.1    simonb 	isync
    434   1.7      matt 	lwz	3,IFRAME_PID(1)
    435   1.7      matt 	lwz	4,IFRAME_SRR1(1)	/* Load srr1 */
    436   1.1    simonb 	bl	_C_LABEL(ctx_setup)	/* Get proper ctx */
    437   1.1    simonb 	mfmsr	5
    438   1.1    simonb 	lis	4,(PSL_EE|PSL_DR|PSL_IR)@h
    439   1.1    simonb 	ori	4,4,(PSL_EE|PSL_DR|PSL_IR)@l
    440   1.1    simonb 	andc	5,5,4
    441   1.1    simonb 	mtmsr	5
    442   1.1    simonb 	isync
    443   1.1    simonb 	mtpid	3			/* Load CTX */
    444   1.4    simonb 
    445   1.1    simonb /* restore possibly overwritten registers: */
    446   1.7      matt 	lwz	12,IFRAME_R12(1)
    447   1.7      matt 	lwz	11,IFRAME_R11(1)
    448   1.7      matt 	lwz	10,IFRAME_R10(1)
    449   1.7      matt 	lwz	9,IFRAME_R9(1)
    450   1.7      matt 	lwz	8,IFRAME_R8(1)
    451   1.7      matt 	lwz	7,IFRAME_R7(1)
    452   1.7      matt 	lwz	6,IFRAME_SRR1(1)
    453   1.7      matt 	lwz	5,IFRAME_SRR0(1)
    454   1.7      matt 	lwz	4,IFRAME_CTR(1)
    455   1.7      matt 	lwz	3,IFRAME_XER(1)
    456   1.1    simonb 	mtsrr1	6
    457   1.1    simonb 	mtsrr0	5
    458   1.1    simonb 	mtctr	4
    459   1.1    simonb 	mtxer	3
    460   1.1    simonb /* Returning to user mode? */
    461   1.7      matt 	GET_CPUINFO(5)
    462   1.7      matt 	lwz	4,CI_INTRDEPTH(5)
    463   1.7      matt 	addi	4,4,-1			/* adjust reentrancy count */
    464   1.7      matt 	stw	4,CI_INTRDEPTH(5)
    465   1.1    simonb 	mtcr	6			/* saved SRR1 */
    466   1.1    simonb 	bc	4,17,1f			/* branch if PSL_PR is false */
    467   1.1    simonb 
    468   1.7      matt 	lwz	4,CI_ASTPENDING(5)	 /* Test AST pending */
    469   1.1    simonb 	andi.	4,4,1
    470   1.1    simonb 	beq	1f
    471   1.1    simonb /* Setup for entry to realtrap: */
    472   1.1    simonb 	lwz	3,0(1)			/* get saved SP */
    473   1.1    simonb 	mtsprg	1,3
    474   1.1    simonb 	li	6,EXC_AST
    475   1.1    simonb 	stmw	28,tempsave(0)		/* establish tempsave again */
    476   1.1    simonb 	mtlr	6
    477   1.7      matt 	lwz	28,IFRAME_LR(1)		/* saved LR */
    478   1.7      matt 	lwz	29,IFRAME_CR(1)		/* saved CR */
    479   1.7      matt 	lwz	6,IFRAME_R6(1)
    480   1.7      matt 	lwz	5,IFRAME_R5(1)
    481   1.7      matt 	lwz	4,IFRAME_R4(1)
    482   1.7      matt 	lwz	3,IFRAME_R3(1)
    483   1.7      matt 	lwz	0,IFRAME_R0(1)
    484   1.1    simonb 	b	realtrap
    485   1.1    simonb 1:
    486   1.1    simonb /* Here is the normal exit of extintr: */
    487   1.7      matt 	lwz	5,IFRAME_CR(1)
    488   1.7      matt 	lwz	6,IFRAME_LR(1)
    489   1.1    simonb 	mtcr	5
    490   1.1    simonb 	mtlr	6
    491   1.7      matt 	lwz	6,IFRAME_R6(1)
    492   1.7      matt 	lwz	5,IFRAME_R5(1)
    493   1.7      matt 	lwz	4,IFRAME_R4(1)
    494   1.7      matt 	lwz	3,IFRAME_R3(1)
    495   1.7      matt 	lwz	0,IFRAME_R0(1)
    496   1.7      matt 	lwz	1,IFRAME_R1(1)
    497   1.1    simonb 	rfi
    498   1.1    simonb 	ba	.	/* Protect against prefetch */
    499   1.4    simonb 
    500   1.1    simonb /*
    501   1.1    simonb  * PIT interrupt handler.
    502   1.1    simonb  */
    503   1.1    simonb 	.align	5
    504   1.1    simonb _C_LABEL(pitint):
    505   1.1    simonb 	mtsprg	1,1			/* save SP */
    506   1.1    simonb 	stmw	28,tempsave(0)		/* free r28-r31 */
    507   1.1    simonb 	mflr	28			/* save LR */
    508   1.1    simonb 	mfcr	29			/* save CR */
    509   1.1    simonb 	mfxer	30			/* save XER */
    510   1.7      matt 	GET_CPUINFO(1)
    511   1.7      matt 	lwz	31,CI_INTRDEPTH(1)	/* were we already running on intstk? */
    512   1.1    simonb 	addic.	31,31,1
    513   1.7      matt 	stw	31,CI_INTRDEPTH(1)
    514   1.7      matt 	lwz	1,CI_INTSTK(1)		/* get intstk */
    515   1.1    simonb 	beq	1f
    516   1.1    simonb 	mfsprg	1,1			/* yes, get old SP */
    517   1.1    simonb 1:
    518   1.1    simonb 	INTRENTER
    519   1.1    simonb 	addi	3,1,8			/* intr frame */
    520   1.1    simonb 	bl	_C_LABEL(decr_intr)
    521   1.1    simonb 	b	intr_exit
    522   1.1    simonb 
    523   1.1    simonb /*
    524   1.1    simonb  * FIT interrupt handler.
    525   1.1    simonb  */
    526   1.1    simonb 	.align	5
    527   1.1    simonb fitint:
    528   1.1    simonb 	mtsprg	1,1			/* save SP */
    529   1.1    simonb 	stmw	28,tempsave(0)		/* free r28-r31 */
    530   1.1    simonb 	mflr	28			/* save LR */
    531   1.1    simonb 	mfcr	29			/* save CR */
    532   1.1    simonb 	mfxer	30			/* save XER */
    533   1.7      matt 	GET_CPUINFO(1)
    534   1.7      matt 	lwz	31,CI_INTRDEPTH(1)	/* were we already running on intstk? */
    535   1.1    simonb 	addic.	31,31,1
    536   1.7      matt 	stw	31,CI_INTRDEPTH(1)
    537   1.7      matt 	lwz	1,CI_INTSTK(1)		/* get intstk */
    538   1.1    simonb 	beq	1f
    539   1.1    simonb 	mfsprg	1,1			/* yes, get old SP */
    540   1.1    simonb 1:
    541   1.1    simonb 	INTRENTER
    542   1.1    simonb 	addi	3,1,8			/* intr frame */
    543   1.1    simonb 	bl	_C_LABEL(stat_intr)
    544   1.1    simonb 	b	intr_exit
    545   1.1    simonb 
    546   1.1    simonb #ifdef DDB
    547   1.1    simonb /*
    548   1.1    simonb  * Deliberate entry to ddbtrap
    549   1.1    simonb  */
    550   1.1    simonb 	.globl	_C_LABEL(ddb_trap)
    551   1.1    simonb _C_LABEL(ddb_trap):
    552   1.1    simonb 	mtsprg	1,1
    553   1.1    simonb 	mfmsr	3
    554   1.1    simonb 	mtsrr1	3
    555   1.1    simonb 	wrteei	0			/* disable interrupts */
    556   1.1    simonb 	isync
    557   1.1    simonb 	stmw	28,ddbsave(0)
    558   1.1    simonb 	mflr	28
    559   1.1    simonb 	li	29,EXC_BPT
    560   1.1    simonb 	mtlr	29
    561   1.1    simonb 	mfcr	29
    562   1.1    simonb 	mtsrr0	28
    563   1.1    simonb 
    564   1.1    simonb /*
    565   1.1    simonb  * Now the ddb trap catching code.
    566   1.1    simonb  */
    567   1.1    simonb ddbtrap:
    568   1.1    simonb 	FRAME_SETUP(ddbsave)
    569   1.1    simonb /* Call C trap code: */
    570   1.1    simonb 	addi	3,1,8
    571   1.1    simonb 	bl	_C_LABEL(ddb_trap_glue)
    572   1.1    simonb 	or.	3,3,3
    573   1.1    simonb 	bne	ddbleave
    574   1.1    simonb /* This wasn't for DDB, so switch to real trap: */
    575   1.1    simonb 	lwz	3,FRAME_EXC+8(1)	/* save exception */
    576   1.1    simonb 	stw	3,ddbsave+12(0)
    577   1.1    simonb 	FRAME_LEAVE(ddbsave)
    578   1.1    simonb 	mtsprg	1,1			/* prepare for entrance to realtrap */
    579   1.1    simonb 	stmw	28,tempsave(0)
    580   1.1    simonb 	mflr	28
    581   1.1    simonb 	mfcr	29
    582   1.1    simonb 	lwz	31,ddbsave+12(0)
    583   1.1    simonb 	mtlr	31
    584   1.1    simonb 	b	realtrap
    585   1.1    simonb ddbleave:
    586   1.1    simonb 	FRAME_LEAVE(ddbsave)
    587   1.1    simonb 	rfi
    588   1.1    simonb 	ba	.	/* Protect against prefetch */
    589   1.1    simonb #endif /* DDB */
    590   1.1    simonb 
    591   1.1    simonb #ifdef IPKDB
    592   1.1    simonb /*
    593   1.1    simonb  * Deliberate entry to ipkdbtrap
    594   1.1    simonb  */
    595   1.1    simonb 	.globl	_C_LABEL(ipkdb_trap)
    596   1.1    simonb _C_LABEL(ipkdb_trap):
    597   1.1    simonb 	mtsprg	1,1
    598   1.1    simonb 	mfmsr	3
    599   1.1    simonb 	mtsrr1	3
    600   1.1    simonb 	wrteei	0			/* disable interrupts */
    601   1.1    simonb 	isync
    602   1.1    simonb 	stmw	28,ipkdbsave(0)
    603   1.1    simonb 	mflr	28
    604   1.1    simonb 	li	29,EXC_BPT
    605   1.1    simonb 	mtlr	29
    606   1.1    simonb 	mfcr	29
    607   1.1    simonb 	mtsrr0	28
    608   1.1    simonb 
    609   1.1    simonb /*
    610   1.1    simonb  * Now the ipkdb trap catching code.
    611   1.1    simonb  */
    612   1.1    simonb ipkdbtrap:
    613   1.1    simonb 	FRAME_SETUP(ipkdbsave)
    614   1.1    simonb /* Call C trap code: */
    615   1.1    simonb 	addi	3,1,8
    616   1.1    simonb 	bl	_C_LABEL(ipkdb_trap_glue)
    617   1.1    simonb 	or.	3,3,3
    618   1.1    simonb 	bne	ipkdbleave
    619   1.1    simonb /* This wasn't for IPKDB, so switch to real trap: */
    620   1.1    simonb 	lwz	3,FRAME_EXC+8(1)	/* save exception */
    621   1.1    simonb 	stw	3,ipkdbsave+8(0)
    622   1.1    simonb 	FRAME_LEAVE(ipkdbsave)
    623   1.1    simonb 	mtsprg	1,1			/* prepare for entrance to realtrap */
    624   1.1    simonb 	stmw	28,tempsave(0)
    625   1.1    simonb 	mflr	28
    626   1.1    simonb 	mfcr	29
    627   1.1    simonb 	lwz	31,ipkdbsave+8(0)
    628   1.1    simonb 	mtlr	31
    629   1.1    simonb 	b	realtrap
    630   1.1    simonb ipkdbleave:
    631   1.1    simonb 	FRAME_LEAVE(ipkdbsave)
    632   1.1    simonb 	rfi
    633   1.1    simonb 	ba	.	/* Protect against prefetch */
    634   1.1    simonb 
    635   1.1    simonb ipkdbfault:
    636   1.1    simonb 	ba	_ipkdbfault
    637   1.1    simonb _ipkdbfault:
    638   1.1    simonb 	mfsrr0	3
    639   1.1    simonb 	addi	3,3,4
    640   1.1    simonb 	mtsrr0	3
    641   1.1    simonb 	li	3,-1
    642   1.1    simonb 	rfi
    643   1.1    simonb 	ba	.	/* Protect against prefetch */
    644   1.1    simonb 
    645   1.1    simonb /*
    646   1.1    simonb  * int ipkdbfbyte(unsigned char *p)
    647   1.1    simonb  */
    648   1.1    simonb 	.globl	_C_LABEL(ipkdbfbyte)
    649   1.1    simonb _C_LABEL(ipkdbfbyte):
    650   1.1    simonb 	li	9,EXC_DSI		/* establish new fault routine */
    651   1.1    simonb 	lwz	5,0(9)
    652   1.1    simonb 	lis	6,ipkdbfault@ha
    653   1.1    simonb 	lwz	6,ipkdbfault@l(6)
    654   1.1    simonb 	stw	6,0(9)
    655   1.1    simonb #ifdef	IPKDBUSERHACK
    656   1.1    simonb #ifndef PPC_IBM4XX
    657   1.1    simonb 	lis	8,_C_LABEL(ipkdbsr)@ha
    658   1.1    simonb 	lwz	8,_C_LABEL(ipkdbsr)@l(8)
    659   1.1    simonb 	mtsr	USER_SR,8
    660   1.1    simonb 	isync
    661   1.4    simonb #endif
    662   1.1    simonb #endif
    663   1.1    simonb 	dcbst	0,9			/* flush data... */
    664   1.1    simonb 	sync
    665   1.1    simonb 	icbi	0,9			/* and instruction caches */
    666   1.1    simonb 	lbz	3,0(3)			/* fetch data */
    667   1.1    simonb 	stw	5,0(9)			/* restore previous fault handler */
    668   1.1    simonb 	dcbst	0,9			/* and flush data... */
    669   1.1    simonb 	sync
    670   1.1    simonb 	icbi	0,9			/* and instruction caches */
    671   1.1    simonb 	blr
    672   1.1    simonb 
    673   1.1    simonb /*
    674   1.1    simonb  * int ipkdbsbyte(unsigned char *p, int c)
    675   1.1    simonb  */
    676   1.1    simonb 	.globl	_C_LABEL(ipkdbsbyte)
    677   1.1    simonb _C_LABEL(ipkdbsbyte):
    678   1.1    simonb 	li	9,EXC_DSI		/* establish new fault routine */
    679   1.1    simonb 	lwz	5,0(9)
    680   1.1    simonb 	lis	6,ipkdbfault@ha
    681   1.1    simonb 	lwz	6,ipkdbfault@l(6)
    682   1.1    simonb 	stw	6,0(9)
    683   1.1    simonb #ifdef	IPKDBUSERHACK
    684   1.1    simonb #ifndef PPC_IBM4XX
    685   1.1    simonb 	lis	8,_C_LABEL(ipkdbsr)@ha
    686   1.1    simonb 	lwz	8,_C_LABEL(ipkdbsr)@l(8)
    687   1.1    simonb 	mtsr	USER_SR,8
    688   1.1    simonb 	isync
    689   1.4    simonb #endif
    690   1.1    simonb #endif
    691   1.1    simonb 	dcbst	0,9			/* flush data... */
    692   1.1    simonb 	sync
    693   1.1    simonb 	icbi	0,9			/* and instruction caches */
    694   1.1    simonb 	mr	6,3
    695   1.1    simonb 	xor	3,3,3
    696   1.1    simonb 	stb	4,0(6)
    697   1.1    simonb 	dcbst	0,6			/* Now do appropriate flushes
    698   1.1    simonb 					   to data... */
    699   1.1    simonb 	sync
    700   1.1    simonb 	icbi	0,6			/* and instruction caches */
    701   1.1    simonb 	stw	5,0(9)			/* restore previous fault handler */
    702   1.1    simonb 	dcbst	0,9			/* and flush data... */
    703   1.1    simonb 	sync
    704   1.4    simonb 	icbi	0,9			/* and instruction caches */
    705   1.1    simonb 	blr
    706   1.1    simonb #endif	/* IPKDB */
    707