2005-09-26 10:04:21 +04:00
/ *
* Copyright ( c ) 1 9 9 5 - 1 9 9 6 G a r y T h o m a s < g d t @linuxppc.org>
* Initial P o w e r P C v e r s i o n .
* Copyright ( c ) 1 9 9 6 C o r t D o u g a n < c o r t @cs.nmt.edu>
* Rewritten f o r P R e P
* Copyright ( c ) 1 9 9 6 P a u l M a c k e r r a s < p a u l u s @cs.anu.edu.au>
* Low- l e v e l e x c e p t i o n h a n d e r s , M M U s u p p o r t , a n d r e w r i t e .
* Copyright ( c ) 1 9 9 7 D a n M a l e k < d m a l e k @jlc.net>
* PowerPC 8 x x m o d i f i c a t i o n s .
* Copyright ( c ) 1 9 9 8 - 1 9 9 9 T i V o , I n c .
* PowerPC 4 0 3 G C X m o d i f i c a t i o n s .
* Copyright ( c ) 1 9 9 9 G r a n t E r i c k s o n < g r a n t @lcse.umn.edu>
* PowerPC 4 0 3 G C X / 4 0 5 G P m o d i f i c a t i o n s .
* Copyright 2 0 0 0 M o n t a V i s t a S o f t w a r e I n c .
* PPC4 0 5 m o d i f i c a t i o n s
* PowerPC 4 0 3 G C X / 4 0 5 G P m o d i f i c a t i o n s .
* Author : MontaVista S o f t w a r e , I n c .
* frank_ r o w a n d @mvista.com or source@mvista.com
* debbie_ c h u @mvista.com
*
*
* Module n a m e : h e a d _ 4 x x . S
*
* Description :
* Kernel e x e c u t i o n e n t r y p o i n t c o d e .
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or
* modify i t u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
*
* /
2009-04-26 06:11:05 +04:00
# include < l i n u x / i n i t . h >
2005-09-26 10:04:21 +04:00
# include < a s m / p r o c e s s o r . h >
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / p g t a b l e . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
2010-11-18 18:06:17 +03:00
# include < a s m / p t r a c e . h >
2005-09-26 10:04:21 +04:00
/ * As w i t h t h e o t h e r P o w e r P C p o r t s , i t i s e x p e c t e d t h a t w h e n c o d e
* execution b e g i n s h e r e , t h e f o l l o w i n g r e g i s t e r s c o n t a i n v a l i d , y e t
* optional, i n f o r m a t i o n :
*
* r3 - B o a r d i n f o s t r u c t u r e p o i n t e r ( D R A M , f r e q u e n c y , M A C a d d r e s s , e t c . )
* r4 - S t a r t i n g a d d r e s s o f t h e i n i t R A M d i s k
* r5 - E n d i n g a d d r e s s o f t h e i n i t R A M d i s k
* r6 - S t a r t o f k e r n e l c o m m a n d l i n e s t r i n g ( e . g . " m e m =96m " )
* r7 - E n d o f k e r n e l c o m m a n d l i n e s t r i n g
*
* This i s a l l g o i n g t o c h a n g e R S N w h e n w e a d d b i _ r e c s . . . . . . . - - D a n
* /
2009-04-26 06:11:05 +04:00
_ _ HEAD
2007-09-14 00:42:35 +04:00
_ ENTRY( _ s t e x t ) ;
_ ENTRY( _ s t a r t ) ;
2005-09-26 10:04:21 +04:00
2011-07-25 15:29:33 +04:00
mr r31 ,r3 / * s a v e d e v i c e t r e e p t r * /
2005-09-26 10:04:21 +04:00
/ * We h a v e t o t u r n o n t h e M M U r i g h t a w a y s o w e g e t c a c h e m o d e s
* set c o r r e c t l y .
* /
bl i n i t i a l _ m m u
/ * We n o w h a v e t h e l o w e r 1 6 M e g m a p p e d i n t o T L B e n t r i e s , a n d t h e c a c h e s
* ready t o w o r k .
* /
turn_on_mmu :
lis r0 ,M S R _ K E R N E L @h
ori r0 ,r0 ,M S R _ K E R N E L @l
mtspr S P R N _ S R R 1 ,r0
lis r0 ,s t a r t _ h e r e @h
ori r0 ,r0 ,s t a r t _ h e r e @l
mtspr S P R N _ S R R 0 ,r0
SYNC
rfi / * e n a b l e s M M U * /
b . / * p r e v e n t p r e f e t c h p a s t r f i * /
/ *
* This a r e a i s u s e d f o r t e m p o r a r i l y s a v i n g r e g i s t e r s d u r i n g t h e
* critical e x c e p t i o n p r o l o g .
* /
. = 0 xc0
crit_save :
2007-09-14 00:42:35 +04:00
_ ENTRY( c r i t _ r10 )
2005-09-26 10:04:21 +04:00
.space 4
2007-09-14 00:42:35 +04:00
_ ENTRY( c r i t _ r11 )
2005-09-26 10:04:21 +04:00
.space 4
2008-04-30 14:23:21 +04:00
_ ENTRY( c r i t _ s r r0 )
.space 4
_ ENTRY( c r i t _ s r r1 )
.space 4
_ ENTRY( s a v e d _ k s p _ l i m i t )
.space 4
2005-09-26 10:04:21 +04:00
/ *
* Exception v e c t o r e n t r y c o d e . T h i s c o d e r u n s w i t h a d d r e s s t r a n s l a t i o n
2009-07-15 00:52:54 +04:00
* turned o f f ( i . e . u s i n g p h y s i c a l a d d r e s s e s ) . W e a s s u m e S P R G _ T H R E A D h a s
* the p h y s i c a l a d d r e s s o f t h e c u r r e n t t a s k t h r e a d _ s t r u c t .
2005-09-26 10:04:21 +04:00
* Note t h a t w e h a v e t o h a v e d e c r e m e n t e d r1 b e f o r e w e w r i t e t o a n y f i e l d s
* of t h e e x c e p t i o n f r a m e , s i n c e a c r i t i c a l i n t e r r u p t c o u l d o c c u r a t a n y
* time, a n d i t w i l l w r i t e t o t h e a r e a i m m e d i a t e l y b e l o w t h e c u r r e n t r1 .
* /
# define N O R M A L _ E X C E P T I O N _ P R O L O G \
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 0 ,r10 ; /* save two registers to work with */\
mtspr S P R N _ S P R G _ S C R A T C H 1 ,r11 ; \
mtspr S P R N _ S P R G _ S C R A T C H 2 ,r1 ; \
2005-09-26 10:04:21 +04:00
mfcr r10 ; /* save CR in r10 for now */\
mfspr r11 ,S P R N _ S R R 1 ; /* check whether user or kernel */\
andi. r11 ,r11 ,M S R _ P R ; \
beq 1 f ; \
2009-07-15 00:52:54 +04:00
mfspr r1 ,S P R N _ S P R G _ T H R E A D ; /* if from user, start at top of */\
2005-09-26 10:04:21 +04:00
lwz r1 ,T H R E A D _ I N F O - T H R E A D ( r1 ) ; /* this thread's kernel stack */\
addi r1 ,r1 ,T H R E A D _ S I Z E ; \
1 : subi r1 ,r1 ,I N T _ F R A M E _ S I Z E ; /* Allocate an exception frame */\
tophys( r11 ,r1 ) ; \
stw r10 ,_ C C R ( r11 ) ; /* save various registers */\
stw r12 ,G P R 1 2 ( r11 ) ; \
stw r9 ,G P R 9 ( r11 ) ; \
2009-07-15 00:52:54 +04:00
mfspr r10 ,S P R N _ S P R G _ S C R A T C H 0 ; \
2005-09-26 10:04:21 +04:00
stw r10 ,G P R 1 0 ( r11 ) ; \
2009-07-15 00:52:54 +04:00
mfspr r12 ,S P R N _ S P R G _ S C R A T C H 1 ; \
2005-09-26 10:04:21 +04:00
stw r12 ,G P R 1 1 ( r11 ) ; \
mflr r10 ; \
stw r10 ,_ L I N K ( r11 ) ; \
2009-07-15 00:52:54 +04:00
mfspr r10 ,S P R N _ S P R G _ S C R A T C H 2 ; \
2005-09-26 10:04:21 +04:00
mfspr r12 ,S P R N _ S R R 0 ; \
stw r10 ,G P R 1 ( r11 ) ; \
mfspr r9 ,S P R N _ S R R 1 ; \
stw r10 ,0 ( r11 ) ; \
rlwinm r9 ,r9 ,0 ,1 4 ,1 2 ; /* clear MSR_WE (necessary?) */\
stw r0 ,G P R 0 ( r11 ) ; \
SAVE_ 4 G P R S ( 3 , r11 ) ; \
SAVE_ 2 G P R S ( 7 , r11 )
/ *
* Exception p r o l o g f o r c r i t i c a l e x c e p t i o n s . T h i s i s a l i t t l e d i f f e r e n t
* from t h e n o r m a l e x c e p t i o n p r o l o g a b o v e s i n c e a c r i t i c a l e x c e p t i o n
* can p o t e n t i a l l y o c c u r a t a n y p o i n t d u r i n g n o r m a l e x c e p t i o n p r o c e s s i n g .
* Thus w e c a n n o t u s e t h e s a m e S P R G r e g i s t e r s a s t h e n o r m a l p r o l o g a b o v e .
* Instead w e u s e a c o u p l e o f w o r d s o f m e m o r y a t l o w p h y s i c a l a d d r e s s e s .
* This i s O K s i n c e w e d o n ' t s u p p o r t S M P o n t h e s e p r o c e s s o r s .
* /
# define C R I T I C A L _ E X C E P T I O N _ P R O L O G \
stw r10 ,c r i t _ r10 @l(0); /* save two registers to work with */\
stw r11 ,c r i t _ r11 @l(0); \
mfcr r10 ; /* save CR in r10 for now */\
mfspr r11 ,S P R N _ S R R 3 ; /* check whether user or kernel */\
andi. r11 ,r11 ,M S R _ P R ; \
2008-04-30 12:49:55 +04:00
lis r11 ,c r i t i r q _ c t x @ha; \
tophys( r11 ,r11 ) ; \
lwz r11 ,c r i t i r q _ c t x @l(r11); \
2005-09-26 10:04:21 +04:00
beq 1 f ; \
/* COMING FROM USER MODE */ \
2009-07-15 00:52:54 +04:00
mfspr r11 ,S P R N _ S P R G _ T H R E A D ; /* if from user, start at top of */\
2005-09-26 10:04:21 +04:00
lwz r11 ,T H R E A D _ I N F O - T H R E A D ( r11 ) ; /* this thread's kernel stack */\
2008-04-30 12:49:55 +04:00
1 : addi r11 ,r11 ,T H R E A D _ S I Z E - I N T _ F R A M E _ S I Z E ; /* Alloc an excpt frm */\
2005-09-26 10:04:21 +04:00
tophys( r11 ,r11 ) ; \
stw r10 ,_ C C R ( r11 ) ; /* save various registers */\
stw r12 ,G P R 1 2 ( r11 ) ; \
stw r9 ,G P R 9 ( r11 ) ; \
mflr r10 ; \
stw r10 ,_ L I N K ( r11 ) ; \
mfspr r12 ,S P R N _ D E A R ; /* save DEAR and ESR in the frame */\
stw r12 ,_ D E A R ( r11 ) ; /* since they may have had stuff */\
mfspr r9 ,S P R N _ E S R ; /* in them at the point where the */\
stw r9 ,_ E S R ( r11 ) ; /* exception was taken */\
mfspr r12 ,S P R N _ S R R 2 ; \
stw r1 ,G P R 1 ( r11 ) ; \
mfspr r9 ,S P R N _ S R R 3 ; \
stw r1 ,0 ( r11 ) ; \
tovirt( r1 ,r11 ) ; \
rlwinm r9 ,r9 ,0 ,1 4 ,1 2 ; /* clear MSR_WE (necessary?) */\
stw r0 ,G P R 0 ( r11 ) ; \
SAVE_ 4 G P R S ( 3 , r11 ) ; \
SAVE_ 2 G P R S ( 7 , r11 )
/ *
* State a t t h i s p o i n t :
* r9 s a v e d i n s t a c k f r a m e , n o w s a v e d S R R 3 & ~ M S R _ W E
* r1 0 s a v e d i n c r i t _ r10 a n d i n s t a c k f r a m e , t r a s h e d
* r1 1 s a v e d i n c r i t _ r11 a n d i n s t a c k f r a m e ,
* now p h y s s t a c k / e x c e p t i o n f r a m e p o i n t e r
* r1 2 s a v e d i n s t a c k f r a m e , n o w s a v e d S R R 2
* CR s a v e d i n s t a c k f r a m e , C R 0 . E Q = ! S R R 3 . P R
* LR, D E A R , E S R i n s t a c k f r a m e
* r1 s a v e d i n s t a c k f r a m e , n o w v i r t s t a c k / e x c f r a m e p o i n t e r
* r0 , r3 - r8 s a v e d i n s t a c k f r a m e
* /
/ *
* Exception v e c t o r s .
* /
# define S T A R T _ E X C E P T I O N ( n , l a b e l ) \
. = n; \
label :
# define E X C E P T I O N ( n , l a b e l , h d l r , x f e r ) \
START_ E X C E P T I O N ( n , l a b e l ) ; \
NORMAL_ E X C E P T I O N _ P R O L O G ; \
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D ; \
xfer( n , h d l r )
# define C R I T I C A L _ E X C E P T I O N ( n , l a b e l , h d l r ) \
START_ E X C E P T I O N ( n , l a b e l ) ; \
CRITICAL_ E X C E P T I O N _ P R O L O G ; \
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D ; \
EXC_ X F E R _ T E M P L A T E ( h d l r , n + 2 , ( M S R _ K E R N E L & ~ ( M S R _ M E | M S R _ D E | M S R _ C E ) ) , \
NOCOPY, c r i t _ t r a n s f e r _ t o _ h a n d l e r , \
ret_ f r o m _ c r i t _ e x c )
# define E X C _ X F E R _ T E M P L A T E ( h d l r , t r a p , m s r , c o p y e e , t f e r , r e t ) \
li r10 ,t r a p ; \
2005-10-28 16:45:25 +04:00
stw r10 ,_ T R A P ( r11 ) ; \
2005-09-26 10:04:21 +04:00
lis r10 ,m s r @h; \
ori r10 ,r10 ,m s r @l; \
copyee( r10 , r9 ) ; \
bl t f e r ; \
.long hdlr; \
.long ret
# define C O P Y _ E E ( d , s ) r l w i m i d ,s ,0 ,1 6 ,1 6
# define N O C O P Y ( d , s )
# define E X C _ X F E R _ S T D ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( h d l r , n , M S R _ K E R N E L , N O C O P Y , t r a n s f e r _ t o _ h a n d l e r _ f u l l , \
ret_ f r o m _ e x c e p t _ f u l l )
# define E X C _ X F E R _ L I T E ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( h d l r , n + 1 , M S R _ K E R N E L , N O C O P Y , t r a n s f e r _ t o _ h a n d l e r , \
ret_ f r o m _ e x c e p t )
# define E X C _ X F E R _ E E ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( h d l r , n , M S R _ K E R N E L , C O P Y _ E E , t r a n s f e r _ t o _ h a n d l e r _ f u l l , \
ret_ f r o m _ e x c e p t _ f u l l )
# define E X C _ X F E R _ E E _ L I T E ( n , h d l r ) \
EXC_ X F E R _ T E M P L A T E ( h d l r , n + 1 , M S R _ K E R N E L , C O P Y _ E E , t r a n s f e r _ t o _ h a n d l e r , \
ret_ f r o m _ e x c e p t )
/ *
* 0 x0 1 0 0 - C r i t i c a l I n t e r r u p t E x c e p t i o n
* /
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x01 0 0 , C r i t i c a l I n t e r r u p t , u n k n o w n _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/ *
* 0 x0 2 0 0 - M a c h i n e C h e c k E x c e p t i o n
* /
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x02 0 0 , M a c h i n e C h e c k , m a c h i n e _ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/ *
* 0 x0 3 0 0 - D a t a S t o r a g e E x c e p t i o n
* This h a p p e n s f o r j u s t a f e w r e a s o n s . U 0 s e t ( b u t w e d o n ' t d o t h a t ) ,
* or z o n e p r o t e c t i o n f a u l t ( u s e r v i o l a t i o n , w r i t e t o p r o t e c t e d p a g e ) .
* If t h i s i s j u s t a n u p d a t e o f m o d i f i e d s t a t u s , w e d o t h a t q u i c k l y
* and e x i t . O t h e r w i s e , w e c a l l h e a v y w i g h t f u n c t i o n s t o d o t h e w o r k .
* /
START_ E X C E P T I O N ( 0 x03 0 0 , D a t a S t o r a g e )
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 0 , r10 / * S a v e s o m e w o r k i n g r e g i s t e r s * /
mtspr S P R N _ S P R G _ S C R A T C H 1 , r11
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ 4 0 3 G C X
stw r12 , 0 ( r0 )
stw r9 , 4 ( r0 )
mfcr r11
mfspr r12 , S P R N _ P I D
stw r11 , 8 ( r0 )
stw r12 , 1 2 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 3 , r12
mtspr S P R N _ S P R G _ S C R A T C H 4 , r9
2005-09-26 10:04:21 +04:00
mfcr r11
mfspr r12 , S P R N _ P I D
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 6 , r11
mtspr S P R N _ S P R G _ S C R A T C H 5 , r12
2005-09-26 10:04:21 +04:00
# endif
/ * First, c h e c k i f i t w a s a z o n e f a u l t ( w h i c h m e a n s a u s e r
* tried t o a c c e s s a k e r n e l o r r e a d - p r o t e c t e d p a g e - a l w a y s
* a S E G V ) . A l l o t h e r f a u l t s h e r e m u s t b e s t o r e s , s o n o
* need t o c h e c k E S R _ D S T a s w e l l . * /
mfspr r10 , S P R N _ E S R
andis. r10 , r10 , E S R _ D I Z @h
bne 2 f
mfspr r10 , S P R N _ D E A R / * G e t f a u l t i n g a d d r e s s * /
/ * If w e a r e f a u l t i n g a k e r n e l a d d r e s s , w e h a v e t o u s e t h e
* kernel p a g e t a b l e s .
* /
2007-10-11 22:36:52 +04:00
lis r11 , P A G E _ O F F S E T @h
2005-09-26 10:04:21 +04:00
cmplw r10 , r11
blt+ 3 f
lis r11 , s w a p p e r _ p g _ d i r @h
ori r11 , r11 , s w a p p e r _ p g _ d i r @l
li r9 , 0
mtspr S P R N _ P I D , r9 / * T L B w i l l h a v e 0 T I D * /
b 4 f
/ * Get t h e P G D f o r t h e c u r r e n t t h r e a d .
* /
3 :
2009-07-15 00:52:54 +04:00
mfspr r11 ,S P R N _ S P R G _ T H R E A D
2005-09-26 10:04:21 +04:00
lwz r11 ,P G D I R ( r11 )
4 :
tophys( r11 , r11 )
rlwimi r11 , r10 , 1 2 , 2 0 , 2 9 / * C r e a t e L 1 ( p g d i r / p m d ) a d d r e s s * /
lwz r11 , 0 ( r11 ) / * G e t L 1 e n t r y * /
rlwinm. r12 , r11 , 0 , 0 , 1 9 / * E x t r a c t L 2 ( p t e ) b a s e a d d r e s s * /
beq 2 f / * B a i l i f n o t a b l e * /
rlwimi r12 , r10 , 2 2 , 2 0 , 2 9 / * C o m p u t e P T E a d d r e s s * /
lwz r11 , 0 ( r12 ) / * G e t L i n u x P T E * /
andi. r9 , r11 , _ P A G E _ R W / * I s i t w r i t e a b l e ? * /
beq 2 f / * B a i l i f n o t * /
/ * Update ' c h a n g e d ' .
* /
ori r11 , r11 , _ P A G E _ D I R T Y | _ P A G E _ A C C E S S E D | _ P A G E _ H W W R I T E
stw r11 , 0 ( r12 ) / * U p d a t e L i n u x p a g e t a b l e * /
/ * Most o f t h e L i n u x P T E i s r e a d y t o l o a d i n t o t h e T L B L O .
* We s e t Z S E L , w h e r e o n l y t h e L S - b i t d e t e r m i n e s u s e r a c c e s s .
* We s e t e x e c u t e , b e c a u s e w e d o n ' t h a v e t h e g r a n u l a r i t y t o
* properly s e t t h i s a t t h e p a g e l e v e l ( L i n u x p r o b l e m ) .
* If s h a r e d i s s e t , w e c a u s e a z e r o P I D - > T I D l o a d .
* Many o f t h e s e b i t s a r e s o f t w a r e o n l y . B i t s w e d o n ' t s e t
* here w e ( p r o p e r l y s h o u l d ) a s s u m e h a v e t h e a p p r o p r i a t e v a l u e .
* /
li r12 , 0 x0 c e 2
andc r11 , r11 , r12 / * M a k e s u r e 2 0 , 2 1 a r e z e r o * /
/ * find t h e T L B i n d e x t h a t c a u s e d t h e f a u l t . I t h a s t o b e h e r e .
* /
tlbsx r9 , 0 , r10
tlbwe r11 , r9 , T L B _ D A T A / * L o a d T L B L O * /
/ * Done. . . r e s t o r e r e g i s t e r s a n d g e t o u t o f h e r e .
* /
# ifdef C O N F I G _ 4 0 3 G C X
lwz r12 , 1 2 ( r0 )
lwz r11 , 8 ( r0 )
mtspr S P R N _ P I D , r12
mtcr r11
lwz r9 , 4 ( r0 )
lwz r12 , 0 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mfspr r12 , S P R N _ S P R G _ S C R A T C H 5
mfspr r11 , S P R N _ S P R G _ S C R A T C H 6
2005-09-26 10:04:21 +04:00
mtspr S P R N _ P I D , r12
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r9 , S P R N _ S P R G _ S C R A T C H 4
mfspr r12 , S P R N _ S P R G _ S C R A T C H 3
2005-09-26 10:04:21 +04:00
# endif
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ S C R A T C H 0
2005-09-26 10:04:21 +04:00
PPC4 0 5 _ E R R 7 7 _ S Y N C
rfi / * S h o u l d s y n c s h a d o w T L B s * /
b . / * p r e v e n t p r e f e t c h p a s t r f i * /
2 :
/ * The b a i l o u t . R e s t o r e r e g i s t e r s t o p r e - e x c e p t i o n c o n d i t i o n s
* and c a l l t h e h e a v y w e i g h t s t o h e l p u s o u t .
* /
# ifdef C O N F I G _ 4 0 3 G C X
lwz r12 , 1 2 ( r0 )
lwz r11 , 8 ( r0 )
mtspr S P R N _ P I D , r12
mtcr r11
lwz r9 , 4 ( r0 )
lwz r12 , 0 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mfspr r12 , S P R N _ S P R G _ S C R A T C H 5
mfspr r11 , S P R N _ S P R G _ S C R A T C H 6
2005-09-26 10:04:21 +04:00
mtspr S P R N _ P I D , r12
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r9 , S P R N _ S P R G _ S C R A T C H 4
mfspr r12 , S P R N _ S P R G _ S C R A T C H 3
2005-09-26 10:04:21 +04:00
# endif
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ S C R A T C H 0
2005-09-26 10:04:21 +04:00
b D a t a A c c e s s
/ *
* 0 x0 4 0 0 - I n s t r u c t i o n S t o r a g e E x c e p t i o n
* This i s c a u s e d b y a f e t c h f r o m n o n - e x e c u t e o r g u a r d e d p a g e s .
* /
START_ E X C E P T I O N ( 0 x04 0 0 , I n s t r u c t i o n A c c e s s )
NORMAL_ E X C E P T I O N _ P R O L O G
mr r4 ,r12 / * P a s s S R R 0 a s a r g 2 * /
li r5 ,0 / * P a s s z e r o a s a r g 3 * /
2012-03-07 09:48:45 +04:00
EXC_ X F E R _ L I T E ( 0 x40 0 , h a n d l e _ p a g e _ f a u l t )
2005-09-26 10:04:21 +04:00
/* 0x0500 - External Interrupt Exception */
EXCEPTION( 0 x05 0 0 , H a r d w a r e I n t e r r u p t , d o _ I R Q , E X C _ X F E R _ L I T E )
/* 0x0600 - Alignment Exception */
START_ E X C E P T I O N ( 0 x06 0 0 , A l i g n m e n t )
NORMAL_ E X C E P T I O N _ P R O L O G
mfspr r4 ,S P R N _ D E A R / * G r a b t h e D E A R a n d s a v e i t * /
stw r4 ,_ D E A R ( r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2005-10-01 12:43:42 +04:00
EXC_ X F E R _ E E ( 0 x60 0 , a l i g n m e n t _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/* 0x0700 - Program Exception */
START_ E X C E P T I O N ( 0 x07 0 0 , P r o g r a m C h e c k )
NORMAL_ E X C E P T I O N _ P R O L O G
mfspr r4 ,S P R N _ E S R / * G r a b t h e E S R a n d s a v e i t * /
stw r4 ,_ E S R ( r11 )
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2005-10-01 12:43:42 +04:00
EXC_ X F E R _ S T D ( 0 x70 0 , p r o g r a m _ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x08 0 0 , T r a p _ 0 8 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x09 0 0 , T r a p _ 0 9 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x0 A 0 0 , T r a p _ 0 A , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x0 B 0 0 , T r a p _ 0 B , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/* 0x0C00 - System Call Exception */
START_ E X C E P T I O N ( 0 x0 C 0 0 , S y s t e m C a l l )
NORMAL_ E X C E P T I O N _ P R O L O G
EXC_ X F E R _ E E _ L I T E ( 0 x c00 , D o S y s c a l l )
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x0 D 0 0 , T r a p _ 0 D , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x0 E 0 0 , T r a p _ 0 E , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x0 F 0 0 , T r a p _ 0 F , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/* 0x1000 - Programmable Interval Timer (PIT) Exception */
START_ E X C E P T I O N ( 0 x10 0 0 , D e c r e m e n t e r )
NORMAL_ E X C E P T I O N _ P R O L O G
lis r0 ,T S R _ P I S @h
mtspr S P R N _ T S R ,r0 / * C l e a r t h e P I T e x c e p t i o n * /
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
EXC_ X F E R _ L I T E ( 0 x10 0 0 , t i m e r _ i n t e r r u p t )
# if 0
/ * NOTE :
* FIT a n d W D T h a n d l e r s a r e n o t i m p l e m e n t e d y e t .
* /
/ * 0 x1 0 1 0 - F i x e d I n t e r v a l T i m e r ( F I T ) E x c e p t i o n
* /
2005-10-01 12:43:42 +04:00
STND_ E X C E P T I O N ( 0 x10 1 0 , F I T E x c e p t i o n , u n k n o w n _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/ * 0 x1 0 2 0 - W a t c h d o g T i m e r ( W D T ) E x c e p t i o n
* /
# ifdef C O N F I G _ B O O K E _ W D T
CRITICAL_ E X C E P T I O N ( 0 x10 2 0 , W D T E x c e p t i o n , W a t c h d o g E x c e p t i o n )
# else
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x10 2 0 , W D T E x c e p t i o n , u n k n o w n _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
# endif
# endif
/ * 0 x1 1 0 0 - D a t a T L B M i s s E x c e p t i o n
* As t h e n a m e i m p l i e s , t r a n s l a t i o n i s n o t i n t h e M M U , s o s e a r c h t h e
* page t a b l e s a n d f i x i t . T h e o n l y p u r p o s e o f t h i s f u n c t i o n i s t o
* load T L B e n t r i e s f r o m t h e p a g e t a b l e i f t h e y e x i s t .
* /
START_ E X C E P T I O N ( 0 x11 0 0 , D T L B M i s s )
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 0 , r10 / * S a v e s o m e w o r k i n g r e g i s t e r s * /
mtspr S P R N _ S P R G _ S C R A T C H 1 , r11
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ 4 0 3 G C X
stw r12 , 0 ( r0 )
stw r9 , 4 ( r0 )
mfcr r11
mfspr r12 , S P R N _ P I D
stw r11 , 8 ( r0 )
stw r12 , 1 2 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 3 , r12
mtspr S P R N _ S P R G _ S C R A T C H 4 , r9
2005-09-26 10:04:21 +04:00
mfcr r11
mfspr r12 , S P R N _ P I D
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 6 , r11
mtspr S P R N _ S P R G _ S C R A T C H 5 , r12
2005-09-26 10:04:21 +04:00
# endif
mfspr r10 , S P R N _ D E A R / * G e t f a u l t i n g a d d r e s s * /
/ * If w e a r e f a u l t i n g a k e r n e l a d d r e s s , w e h a v e t o u s e t h e
* kernel p a g e t a b l e s .
* /
2007-10-11 22:36:52 +04:00
lis r11 , P A G E _ O F F S E T @h
2005-09-26 10:04:21 +04:00
cmplw r10 , r11
blt+ 3 f
lis r11 , s w a p p e r _ p g _ d i r @h
ori r11 , r11 , s w a p p e r _ p g _ d i r @l
li r9 , 0
mtspr S P R N _ P I D , r9 / * T L B w i l l h a v e 0 T I D * /
b 4 f
/ * Get t h e P G D f o r t h e c u r r e n t t h r e a d .
* /
3 :
2009-07-15 00:52:54 +04:00
mfspr r11 ,S P R N _ S P R G _ T H R E A D
2005-09-26 10:04:21 +04:00
lwz r11 ,P G D I R ( r11 )
4 :
tophys( r11 , r11 )
rlwimi r11 , r10 , 1 2 , 2 0 , 2 9 / * C r e a t e L 1 ( p g d i r / p m d ) a d d r e s s * /
lwz r12 , 0 ( r11 ) / * G e t L 1 e n t r y * /
andi. r9 , r12 , _ P M D _ P R E S E N T / * C h e c k i f i t p o i n t s t o a P T E p a g e * /
beq 2 f / * B a i l i f n o t a b l e * /
rlwimi r12 , r10 , 2 2 , 2 0 , 2 9 / * C o m p u t e P T E a d d r e s s * /
lwz r11 , 0 ( r12 ) / * G e t L i n u x P T E * /
andi. r9 , r11 , _ P A G E _ P R E S E N T
beq 5 f
ori r11 , r11 , _ P A G E _ A C C E S S E D
stw r11 , 0 ( r12 )
/ * Create T L B t a g . T h i s i s t h e f a u l t i n g a d d r e s s p l u s a s t a t i c
* set o f b i t s . T h e s e a r e s i z e , v a l i d , E , U 0 .
* /
li r12 , 0 x00 c0
rlwimi r10 , r12 , 0 , 2 0 , 3 1
b f i n i s h _ t l b _ l o a d
2 : /* Check for possible large-page pmd entry */
rlwinm. r9 , r12 , 2 , 2 2 , 2 4
beq 5 f
/ * Create T L B t a g . T h i s i s t h e f a u l t i n g a d d r e s s , p l u s a s t a t i c
* set o f b i t s ( v a l i d , E , U 0 ) p l u s t h e s i z e f r o m t h e P M D .
* /
ori r9 , r9 , 0 x40
rlwimi r10 , r9 , 0 , 2 0 , 3 1
mr r11 , r12
b f i n i s h _ t l b _ l o a d
5 :
/ * The b a i l o u t . R e s t o r e r e g i s t e r s t o p r e - e x c e p t i o n c o n d i t i o n s
* and c a l l t h e h e a v y w e i g h t s t o h e l p u s o u t .
* /
# ifdef C O N F I G _ 4 0 3 G C X
lwz r12 , 1 2 ( r0 )
lwz r11 , 8 ( r0 )
mtspr S P R N _ P I D , r12
mtcr r11
lwz r9 , 4 ( r0 )
lwz r12 , 0 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mfspr r12 , S P R N _ S P R G _ S C R A T C H 5
mfspr r11 , S P R N _ S P R G _ S C R A T C H 6
2005-09-26 10:04:21 +04:00
mtspr S P R N _ P I D , r12
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r9 , S P R N _ S P R G _ S C R A T C H 4
mfspr r12 , S P R N _ S P R G _ S C R A T C H 3
2005-09-26 10:04:21 +04:00
# endif
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ S C R A T C H 0
2005-09-26 10:04:21 +04:00
b D a t a A c c e s s
/ * 0 x1 2 0 0 - I n s t r u c t i o n T L B M i s s E x c e p t i o n
* Nearly t h e s a m e a s a b o v e , e x c e p t w e g e t o u r i n f o r m a t i o n f r o m d i f f e r e n t
* registers a n d b a i l o u t t o a d i f f e r e n t p o i n t .
* /
START_ E X C E P T I O N ( 0 x12 0 0 , I T L B M i s s )
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 0 , r10 / * S a v e s o m e w o r k i n g r e g i s t e r s * /
mtspr S P R N _ S P R G _ S C R A T C H 1 , r11
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ 4 0 3 G C X
stw r12 , 0 ( r0 )
stw r9 , 4 ( r0 )
mfcr r11
mfspr r12 , S P R N _ P I D
stw r11 , 8 ( r0 )
stw r12 , 1 2 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 3 , r12
mtspr S P R N _ S P R G _ S C R A T C H 4 , r9
2005-09-26 10:04:21 +04:00
mfcr r11
mfspr r12 , S P R N _ P I D
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ S C R A T C H 6 , r11
mtspr S P R N _ S P R G _ S C R A T C H 5 , r12
2005-09-26 10:04:21 +04:00
# endif
mfspr r10 , S P R N _ S R R 0 / * G e t f a u l t i n g a d d r e s s * /
/ * If w e a r e f a u l t i n g a k e r n e l a d d r e s s , w e h a v e t o u s e t h e
* kernel p a g e t a b l e s .
* /
2007-10-11 22:36:52 +04:00
lis r11 , P A G E _ O F F S E T @h
2005-09-26 10:04:21 +04:00
cmplw r10 , r11
blt+ 3 f
lis r11 , s w a p p e r _ p g _ d i r @h
ori r11 , r11 , s w a p p e r _ p g _ d i r @l
li r9 , 0
mtspr S P R N _ P I D , r9 / * T L B w i l l h a v e 0 T I D * /
b 4 f
/ * Get t h e P G D f o r t h e c u r r e n t t h r e a d .
* /
3 :
2009-07-15 00:52:54 +04:00
mfspr r11 ,S P R N _ S P R G _ T H R E A D
2005-09-26 10:04:21 +04:00
lwz r11 ,P G D I R ( r11 )
4 :
tophys( r11 , r11 )
rlwimi r11 , r10 , 1 2 , 2 0 , 2 9 / * C r e a t e L 1 ( p g d i r / p m d ) a d d r e s s * /
lwz r12 , 0 ( r11 ) / * G e t L 1 e n t r y * /
andi. r9 , r12 , _ P M D _ P R E S E N T / * C h e c k i f i t p o i n t s t o a P T E p a g e * /
beq 2 f / * B a i l i f n o t a b l e * /
rlwimi r12 , r10 , 2 2 , 2 0 , 2 9 / * C o m p u t e P T E a d d r e s s * /
lwz r11 , 0 ( r12 ) / * G e t L i n u x P T E * /
andi. r9 , r11 , _ P A G E _ P R E S E N T
beq 5 f
ori r11 , r11 , _ P A G E _ A C C E S S E D
stw r11 , 0 ( r12 )
/ * Create T L B t a g . T h i s i s t h e f a u l t i n g a d d r e s s p l u s a s t a t i c
* set o f b i t s . T h e s e a r e s i z e , v a l i d , E , U 0 .
* /
li r12 , 0 x00 c0
rlwimi r10 , r12 , 0 , 2 0 , 3 1
b f i n i s h _ t l b _ l o a d
2 : /* Check for possible large-page pmd entry */
rlwinm. r9 , r12 , 2 , 2 2 , 2 4
beq 5 f
/ * Create T L B t a g . T h i s i s t h e f a u l t i n g a d d r e s s , p l u s a s t a t i c
* set o f b i t s ( v a l i d , E , U 0 ) p l u s t h e s i z e f r o m t h e P M D .
* /
ori r9 , r9 , 0 x40
rlwimi r10 , r9 , 0 , 2 0 , 3 1
mr r11 , r12
b f i n i s h _ t l b _ l o a d
5 :
/ * The b a i l o u t . R e s t o r e r e g i s t e r s t o p r e - e x c e p t i o n c o n d i t i o n s
* and c a l l t h e h e a v y w e i g h t s t o h e l p u s o u t .
* /
# ifdef C O N F I G _ 4 0 3 G C X
lwz r12 , 1 2 ( r0 )
lwz r11 , 8 ( r0 )
mtspr S P R N _ P I D , r12
mtcr r11
lwz r9 , 4 ( r0 )
lwz r12 , 0 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mfspr r12 , S P R N _ S P R G _ S C R A T C H 5
mfspr r11 , S P R N _ S P R G _ S C R A T C H 6
2005-09-26 10:04:21 +04:00
mtspr S P R N _ P I D , r12
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r9 , S P R N _ S P R G _ S C R A T C H 4
mfspr r12 , S P R N _ S P R G _ S C R A T C H 3
2005-09-26 10:04:21 +04:00
# endif
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ S C R A T C H 0
2005-09-26 10:04:21 +04:00
b I n s t r u c t i o n A c c e s s
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x13 0 0 , T r a p _ 1 3 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x14 0 0 , T r a p _ 1 4 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x15 0 0 , T r a p _ 1 5 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x16 0 0 , T r a p _ 1 6 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ I B M 4 0 5 _ E R R 5 1
/* 405GP errata 51 */
START_ E X C E P T I O N ( 0 x17 0 0 , T r a p _ 1 7 )
b D T L B M i s s
# else
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x17 0 0 , T r a p _ 1 7 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
# endif
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x18 0 0 , T r a p _ 1 8 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x19 0 0 , T r a p _ 1 9 , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 A 0 0 , T r a p _ 1 A , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 B 0 0 , T r a p _ 1 B , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 C 0 0 , T r a p _ 1 C , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 D 0 0 , T r a p _ 1 D , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 E 0 0 , T r a p _ 1 E , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x1 F 0 0 , T r a p _ 1 F , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/ * Check f o r a s i n g l e s t e p d e b u g e x c e p t i o n w h i l e i n a n e x c e p t i o n
* handler b e f o r e s t a t e h a s b e e n s a v e d . T h i s i s t o c a t c h t h e c a s e
* where a n i n s t r u c t i o n t h a t w e a r e t r y i n g t o s i n g l e s t e p c a u s e s
* an e x c e p t i o n ( e g I T L B / D T L B m i s s ) a n d t h u s t h e f i r s t i n s t r u c t i o n o f
* the e x c e p t i o n h a n d l e r g e n e r a t e s a s i n g l e s t e p d e b u g e x c e p t i o n .
*
* If w e g e t a d e b u g t r a p o n t h e f i r s t i n s t r u c t i o n o f a n e x c e p t i o n h a n d l e r ,
* we r e s e t t h e M S R _ D E i n t h e _ e x c e p t i o n h a n d l e r ' s _ M S R ( t h e d e b u g t r a p i s
* a c r i t i c a l e x c e p t i o n , s o w e a r e u s i n g S P R N _ C S R R 1 t o m a n i p u l a t e t h e M S R ) .
* The e x c e p t i o n h a n d l e r w a s h a n d l i n g a n o n - c r i t i c a l i n t e r r u p t , s o i t w i l l
* save ( a n d l a t e r r e s t o r e ) t h e M S R v i a S P R N _ S R R 1 , w h i c h w i l l s t i l l h a v e
* the M S R _ D E b i t s e t .
* /
/* 0x2000 - Debug Exception */
START_ E X C E P T I O N ( 0 x20 0 0 , D e b u g T r a p )
CRITICAL_ E X C E P T I O N _ P R O L O G
/ *
* If t h i s i s a s i n g l e s t e p o r b r a n c h - t a k e n e x c e p t i o n i n a n
* exception e n t r y s e q u e n c e , i t w a s p r o b a b l y m e a n t t o a p p l y t o
* the c o d e w h e r e t h e e x c e p t i o n o c c u r r e d ( s i n c e e x c e p t i o n e n t r y
* doesn' t t u r n o f f D E a u t o m a t i c a l l y ) . W e s i m u l a t e t h e e f f e c t
* of t u r n i n g o f f D E o n e n t r y t o a n e x c e p t i o n h a n d l e r b y t u r n i n g
* off D E i n t h e S R R 3 v a l u e a n d c l e a r i n g t h e d e b u g s t a t u s .
* /
mfspr r10 ,S P R N _ D B S R / * c h e c k s i n g l e - s t e p / b r a n c h t a k e n * /
andis. r10 ,r10 ,D B S R _ I C @h
beq+ 2 f
andi. r10 ,r9 ,M S R _ I R | M S R _ P R / * c h e c k s u p e r v i s o r + M M U o f f * /
beq 1 f / * b r a n c h a n d f i x i t u p * /
mfspr r10 ,S P R N _ S R R 2 / * F a u l t i n g i n s t r u c t i o n a d d r e s s * /
cmplwi r10 ,0 x21 0 0
bgt+ 2 f / * a d d r e s s a b o v e e x c e p t i o n v e c t o r s * /
/* here it looks like we got an inappropriate debug exception. */
1 : rlwinm r9 ,r9 ,0 ,~ M S R _ D E / * c l e a r D E i n t h e S R R 3 v a l u e * /
lis r10 ,D B S R _ I C @h /* clear the IC event */
mtspr S P R N _ D B S R ,r10
/* restore state and get out */
lwz r10 ,_ C C R ( r11 )
lwz r0 ,G P R 0 ( r11 )
lwz r1 ,G P R 1 ( r11 )
mtcrf 0 x80 ,r10
mtspr S P R N _ S R R 2 ,r12
mtspr S P R N _ S R R 3 ,r9
lwz r9 ,G P R 9 ( r11 )
lwz r12 ,G P R 1 2 ( r11 )
lwz r10 ,c r i t _ r10 @l(0)
lwz r11 ,c r i t _ r11 @l(0)
PPC4 0 5 _ E R R 7 7 _ S Y N C
rfci
b .
/* continue normal handling for a critical exception... */
2 : mfspr r4 ,S P R N _ D B S R
addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
EXC_ X F E R _ T E M P L A T E ( D e b u g E x c e p t i o n , 0 x20 0 2 , \
( MSR_ K E R N E L & ~ ( M S R _ M E | M S R _ D E | M S R _ C E ) ) , \
NOCOPY, c r i t _ t r a n s f e r _ t o _ h a n d l e r , r e t _ f r o m _ c r i t _ e x c )
/ *
* The o t h e r D a t a T L B e x c e p t i o n s b a i l o u t t o t h i s p o i n t
* if t h e y c a n ' t r e s o l v e t h e l i g h t w e i g h t T L B f a u l t .
* /
DataAccess :
NORMAL_ E X C E P T I O N _ P R O L O G
mfspr r5 ,S P R N _ E S R / * G r a b t h e E S R , s a v e i t , p a s s a r g 3 * /
stw r5 ,_ E S R ( r11 )
mfspr r4 ,S P R N _ D E A R / * G r a b t h e D E A R , s a v e i t , p a s s a r g 2 * /
2012-03-07 09:48:45 +04:00
EXC_ X F E R _ L I T E ( 0 x30 0 , h a n d l e _ p a g e _ f a u l t )
2005-09-26 10:04:21 +04:00
/ * Other P o w e r P C p r o c e s s o r s , n a m e l y t h o s e d e r i v e d f r o m t h e 6 x x - s e r i e s
* have v e c t o r s f r o m 0 x21 0 0 t h r o u g h 0 x2 F 0 0 d e f i n e d , b u t m a r k e d a s r e s e r v e d .
* However, f o r t h e 4 x x - s e r i e s p r o c e s s o r s t h e s e a r e n e i t h e r d e f i n e d n o r
* reserved.
* /
/ * Damn, I c a m e u p o n e i n s t r u c t i o n t o o m a n y t o f i t i n t o t h e
* exception s p a c e : - ) . B o t h t h e i n s t r u c t i o n a n d d a t a T L B
* miss g e t t o t h i s p o i n t t o l o a d t h e T L B .
* r1 0 - T L B _ T A G v a l u e
* r1 1 - L i n u x P T E
2011-03-31 05:57:33 +04:00
* r1 2 , r9 - a v a i l a b l e t o u s e
2005-09-26 10:04:21 +04:00
* PID - l o a d e d w i t h p r o p e r v a l u e w h e n w e g e t h e r e
* Upon e x i t , w e r e l o a d e v e r y t h i n g a n d R F I .
* Actually, i t w i l l f i t n o w , b u t o h w e l l . . . . . a c o m m o n p l a c e
* to l o a d t h e T L B .
* /
tlb_4xx_index :
.long 0
finish_tlb_load :
/ * load t h e n e x t a v a i l a b l e T L B i n d e x .
* /
lwz r9 , t l b _ 4 x x _ i n d e x @l(0)
addi r9 , r9 , 1
2007-08-20 16:28:48 +04:00
andi. r9 , r9 , ( P P C 4 0 X _ T L B _ S I Z E - 1 )
2005-09-26 10:04:21 +04:00
stw r9 , t l b _ 4 x x _ i n d e x @l(0)
6 :
/ *
* Clear o u t t h e s o f t w a r e - o n l y b i t s i n t h e P T E t o g e n e r a t e t h e
* TLB_ D A T A v a l u e . T h e s e a r e t h e b o t t o m 2 b i t s o f t h e R P M , t h e
* top 3 b i t s o f t h e z o n e f i e l d , a n d M .
* /
li r12 , 0 x0 c e 2
andc r11 , r11 , r12
tlbwe r11 , r9 , T L B _ D A T A / * L o a d T L B L O * /
tlbwe r10 , r9 , T L B _ T A G / * L o a d T L B H I * /
/ * Done. . . r e s t o r e r e g i s t e r s a n d g e t o u t o f h e r e .
* /
# ifdef C O N F I G _ 4 0 3 G C X
lwz r12 , 1 2 ( r0 )
lwz r11 , 8 ( r0 )
mtspr S P R N _ P I D , r12
mtcr r11
lwz r9 , 4 ( r0 )
lwz r12 , 0 ( r0 )
# else
2009-07-15 00:52:54 +04:00
mfspr r12 , S P R N _ S P R G _ S C R A T C H 5
mfspr r11 , S P R N _ S P R G _ S C R A T C H 6
2005-09-26 10:04:21 +04:00
mtspr S P R N _ P I D , r12
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r9 , S P R N _ S P R G _ S C R A T C H 4
mfspr r12 , S P R N _ S P R G _ S C R A T C H 3
2005-09-26 10:04:21 +04:00
# endif
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ S C R A T C H 0
2005-09-26 10:04:21 +04:00
PPC4 0 5 _ E R R 7 7 _ S Y N C
rfi / * S h o u l d s y n c s h a d o w T L B s * /
b . / * p r e v e n t p r e f e t c h p a s t r f i * /
/ * extern v o i d g i v e u p _ f p u ( s t r u c t t a s k _ s t r u c t * p r e v )
*
* The P o w e r P C 4 x x f a m i l y o f p r o c e s s o r s d o n o t h a v e a n F P U , s o t h i s j u s t
* returns.
* /
2007-09-14 00:42:35 +04:00
_ ENTRY( g i v e u p _ f p u )
2005-09-26 10:04:21 +04:00
blr
/ * This i s w h e r e t h e m a i n k e r n e l c o d e s t a r t s .
* /
start_here :
/* ptr to current */
lis r2 ,i n i t _ t a s k @h
ori r2 ,r2 ,i n i t _ t a s k @l
/* ptr to phys current thread */
tophys( r4 ,r2 )
addi r4 ,r4 ,T H R E A D / * i n i t t a s k ' s T H R E A D * /
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ T H R E A D ,r4
2005-09-26 10:04:21 +04:00
/* stack */
lis r1 ,i n i t _ t h r e a d _ u n i o n @ha
addi r1 ,r1 ,i n i t _ t h r e a d _ u n i o n @l
li r0 ,0
stwu r0 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ O V E R H E A D ( r1 )
bl e a r l y _ i n i t / * W e h a v e t o d o t h i s w i t h M M U o n * /
/ *
* Decide w h a t s o r t o f m a c h i n e t h i s i s a n d i n i t i a l i z e t h e M M U .
* /
2011-07-25 15:29:33 +04:00
li r3 ,0
mr r4 ,r31
2005-09-26 10:04:21 +04:00
bl m a c h i n e _ i n i t
bl M M U _ i n i t
/ * Go b a c k t o r u n n i n g u n m a p p e d s o w e c a n l o a d u p n e w v a l u e s
* and c h a n g e t o u s i n g o u r e x c e p t i o n v e c t o r s .
* On t h e 4 x x , a l l w e h a v e t o d o i s i n v a l i d a t e t h e T L B t o c l e a r
* the o l d 1 6 M b y t e T L B m a p p i n g s .
* /
lis r4 ,2 f @h
ori r4 ,r4 ,2 f @l
tophys( r4 ,r4 )
lis r3 ,( M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R ) ) @h
ori r3 ,r3 ,( M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R ) ) @l
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r3
rfi
b . / * p r e v e n t p r e f e t c h p a s t r f i * /
/* Load up the kernel context */
2 :
sync / * F l u s h t o m e m o r y b e f o r e c h a n g i n g T L B * /
tlbia
isync / * F l u s h s h a d o w T L B s * /
/ * set u p t h e P T E p o i n t e r s f o r t h e A b a t r o n b d i G D B .
* /
lis r6 , s w a p p e r _ p g _ d i r @h
ori r6 , r6 , s w a p p e r _ p g _ d i r @l
lis r5 , a b a t r o n _ p t e p t r s @h
ori r5 , r5 , a b a t r o n _ p t e p t r s @l
stw r5 , 0 x f0 ( r0 ) / * M u s t m a t c h y o u r A b a t r o n c o n f i g f i l e * /
tophys( r5 ,r5 )
stw r6 , 0 ( r5 )
/* Now turn on the MMU for real! */
lis r4 ,M S R _ K E R N E L @h
ori r4 ,r4 ,M S R _ K E R N E L @l
lis r3 ,s t a r t _ k e r n e l @h
ori r3 ,r3 ,s t a r t _ k e r n e l @l
mtspr S P R N _ S R R 0 ,r3
mtspr S P R N _ S R R 1 ,r4
rfi / * e n a b l e M M U a n d j u m p t o s t a r t _ k e r n e l * /
b . / * p r e v e n t p r e f e t c h p a s t r f i * /
/ * Set u p t h e i n i t i a l M M U s t a t e s o w e c a n d o t h e f i r s t l e v e l o f
* kernel i n i t i a l i z a t i o n . T h i s m a p s t h e f i r s t 1 6 M B y t e s o f m e m o r y 1 : 1
* virtual t o p h y s i c a l a n d m o r e i m p o r t a n t l y s e t s t h e c a c h e m o d e .
* /
initial_mmu :
tlbia / * I n v a l i d a t e a l l T L B e n t r i e s * /
isync
/ * We s h o u l d s t i l l b e e x e c u t i n g c o d e a t p h y s i c a l a d d r e s s 0 x00 0 0 x x x x
* at t h i s p o i n t . H o w e v e r , s t a r t _ h e r e i s a t v i r t u a l a d d r e s s
* 0 xC0 0 0 x x x x . S o , s e t u p a T L B m a p p i n g t o c o v e r t h i s o n c e
* translation i s e n a b l e d .
* /
lis r3 ,K E R N E L B A S E @h /* Load the kernel virtual address */
ori r3 ,r3 ,K E R N E L B A S E @l
tophys( r4 ,r3 ) / * L o a d t h e k e r n e l p h y s i c a l a d d r e s s * /
iccci r0 ,r3 / * I n v a l i d a t e t h e i - c a c h e b e f o r e u s e * /
/ * Load t h e k e r n e l P I D .
* /
li r0 ,0
mtspr S P R N _ P I D ,r0
sync
2010-07-07 02:39:02 +04:00
/* Configure and load one entry into TLB slots 63 */
2005-09-26 10:04:21 +04:00
clrrwi r4 ,r4 ,1 0 / * M a s k o f f t h e r e a l p a g e n u m b e r * /
ori r4 ,r4 ,( T L B _ W R | T L B _ E X ) / * S e t t h e w r i t e a n d e x e c u t e b i t s * /
clrrwi r3 ,r3 ,1 0 / * M a s k o f f t h e e f f e c t i v e p a g e n u m b e r * /
ori r3 ,r3 ,( T L B _ V A L I D | T L B _ P A G E S Z ( P A G E S Z _ 1 6 M ) )
li r0 ,6 3 / * T L B s l o t 6 3 * /
tlbwe r4 ,r0 ,T L B _ D A T A / * L o a d t h e d a t a p o r t i o n o f t h e e n t r y * /
tlbwe r3 ,r0 ,T L B _ T A G / * L o a d t h e t a g p o r t i o n o f t h e e n t r y * /
# if d e f i n e d ( C O N F I G _ S E R I A L _ T E X T _ D E B U G ) & & d e f i n e d ( S E R I A L _ D E B U G _ I O _ B A S E )
/ * Load a T L B e n t r y f o r t h e U A R T , s o t h a t p p c4 x x _ p r o g r e s s ( ) c a n u s e
* the U A R T s n i c e a n d e a r l y . W e u s e a 4 k r e a l = =virtual m a p p i n g . * /
lis r3 ,S E R I A L _ D E B U G _ I O _ B A S E @h
ori r3 ,r3 ,S E R I A L _ D E B U G _ I O _ B A S E @l
mr r4 ,r3
clrrwi r4 ,r4 ,1 2
ori r4 ,r4 ,( T L B _ W R | T L B _ I | T L B _ M | T L B _ G )
clrrwi r3 ,r3 ,1 2
ori r3 ,r3 ,( T L B _ V A L I D | T L B _ P A G E S Z ( P A G E S Z _ 4 K ) )
li r0 ,0 / * T L B s l o t 0 * /
tlbwe r4 ,r0 ,T L B _ D A T A
tlbwe r3 ,r0 ,T L B _ T A G
# endif / * C O N F I G _ S E R I A L _ D E B U G _ T E X T & & S E R I A L _ D E B U G _ I O _ B A S E * /
isync
/ * Establish t h e e x c e p t i o n v e c t o r b a s e
* /
lis r4 ,K E R N E L B A S E @h /* EVPR only uses the high 16-bits */
tophys( r0 ,r4 ) / * U s e t h e p h y s i c a l a d d r e s s * /
mtspr S P R N _ E V P R ,r0
blr
_ GLOBAL( a b o r t )
mfspr r13 ,S P R N _ D B C R 0
oris r13 ,r13 ,D B C R 0 _ R S T _ S Y S T E M @h
mtspr S P R N _ D B C R 0 ,r13
_ GLOBAL( s e t _ c o n t e x t )
# ifdef C O N F I G _ B D I _ S W I T C H
/ * Context s w i t c h t h e P T E p o i n t e r f o r t h e A b a t r o n B D I 2 0 0 0 .
* The P G D I R i s t h e s e c o n d p a r a m e t e r .
* /
lis r5 , K E R N E L B A S E @h
lwz r5 , 0 x f0 ( r5 )
stw r4 , 0 x4 ( r5 )
# endif
sync
mtspr S P R N _ P I D ,r3
isync / * N e e d a n i s y n c t o f l u s h s h a d o w * /
/* TLBs after changing PID */
blr
/ * We p u t a f e w t h i n g s h e r e t h a t h a v e t o b e p a g e - a l i g n e d . T h i s s t u f f
* goes a t t h e b e g i n n i n g o f t h e d a t a s e g m e n t , w h i c h i s p a g e - a l i g n e d .
* /
.data
2005-10-12 08:54:00 +04:00
.align 12
.globl sdata
sdata :
.globl empty_zero_page
empty_zero_page :
2005-09-26 10:04:21 +04:00
.space 4096
2005-10-12 08:54:00 +04:00
.globl swapper_pg_dir
swapper_pg_dir :
2007-12-06 22:11:04 +03:00
.space PGD_TABLE_SIZE
2005-09-26 10:04:21 +04:00
/ * Room f o r t w o P T E p o i n t e r s , u s u a l l y t h e k e r n e l a n d c u r r e n t u s e r p o i n t e r s
* to t h e i r r e s p e c t i v e r o o t p a g e t a b l e .
* /
abatron_pteptrs :
.space 8