2005-09-26 10:04:21 +04:00
/ *
* PowerPC v e r s i o n
* 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)
* Rewritten b y C o r t D o u g a n ( c o r t @cs.nmt.edu) for PReP
* Copyright ( C ) 1 9 9 6 C o r t D o u g a n < c o r t @cs.nmt.edu>
* Low- l e v e l e x c e p t i o n h a n d l e r s a n d M M U s u p p o r t
* rewritten b y P a u l M a c k e r r a s .
* Copyright ( C ) 1 9 9 6 P a u l M a c k e r r a s .
* MPC8 x x m o d i f i c a t i o n s b y D a n M a l e k
* Copyright ( C ) 1 9 9 7 D a n M a l e k ( d m a l e k @jlc.net).
*
* This f i l e c o n t a i n s l o w - l e v e l s u p p o r t a n d s e t u p f o r P o w e r P C 8 x x
* embedded p r o c e s s o r s , i n c l u d i n g t r a p a n d i n t e r r u p t d i s p a t c h .
*
* 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 / c a c h e . 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
/* Macro to make the code more readable. */
# ifdef C O N F I G _ 8 x x _ C P U 6
# define D O _ 8 x x _ C P U 6 ( v a l , r e g ) \
li r e g , v a l ; \
stw r e g , 1 2 ( r0 ) ; \
lwz r e g , 1 2 ( r0 ) ;
# else
# define D O _ 8 x x _ C P U 6 ( v a l , r e g )
# endif
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
/ * MPC8 x x
* This p o r t w a s d o n e o n a n M B X b o a r d w i t h a n 8 6 0 . R i g h t n o w I o n l y
* support a n E L F c o m p r e s s e d ( z I m a g e ) b o o t f r o m E P P C - B u g b e c a u s e t h e
* code t h e r e l o a d s u p s o m e r e g i s t e r s b e f o r e c a l l i n g u s :
* r3 : ptr t o b o a r d i n f o d a t a
* r4 : initrd_ s t a r t o r i f n o i n i t r d t h e n 0
* r5 : initrd_ e n d - u n u s e d i f r4 i s 0
* r6 : Start o f c o m m a n d l i n e s t r i n g
* r7 : End o f c o m m a n d l i n e s t r i n g
*
* I d e c i d e d t o u s e c o n d i t i o n a l c o m p i l a t i o n i n s t e a d o f c h e c k i n g P V R a n d
* adding m o r e p r o c e s s o r s p e c i f i c b r a n c h e s a r o u n d c o d e I d o n ' t n e e d .
* Since t h i s i s a n e m b e d d e d p r o c e s s o r , I a l s o a p p r e c i a t e a n y m e m o r y
* savings I c a n g e t .
*
* The M P C 8 x x d o e s n o t h a v e a n y B A T s , b u t i t s u p p o r t s l a r g e p a g e s i z e s .
* We f i r s t i n i t i a l i z e t h e M M U t o s u p p o r t 8 M b y t e p a g e s , t h e n l o a d o n e
* entry i n t o e a c h o f t h e i n s t r u c t i o n a n d d a t a T L B s t o m a p t h e f i r s t
* 8 M 1 : 1 . I a l s o m a p p e d a n a d d i t i o n a l I / O s p a c e 1 : 1 s o w e c a n g e t t o
* the " i n t e r n a l " p r o c e s s o r r e g i s t e r s b e f o r e M M U _ i n i t i s c a l l e d .
*
* The T L B c o d e c u r r e n t l y c o n t a i n s a m a j o r h a c k . S i n c e I u s e t h e c o n d i t i o n
* code r e g i s t e r , I h a v e t o s a v e a n d r e s t o r e i t . I a m o u t o f r e g i s t e r s , s o
* I j u s t s t o r e i t i n m e m o r y l o c a t i o n 0 ( t h e T L B h a n d l e r s a r e n o t r e e n t r a n t ) .
* To a v o i d m a k i n g a n y d e c i s i o n s , I n e e d t o u s e t h e " s e g m e n t " v a l i d b i t
* in t h e f i r s t l e v e l t a b l e , b u t t h a t w o u l d r e q u i r e m a n y c h a n g e s t o t h e
* Linux p a g e d i r e c t o r y / t a b l e f u n c t i o n s t h a t I d o n ' t w a n t t o d o r i g h t n o w .
*
* - - Dan
* /
.globl __start
__start :
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 8 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 :
mfmsr r0
ori r0 ,r0 ,M S R _ D R | M S R _ I R
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 * /
/ *
* Exception 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
* 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 .
* We a s s u m e s p r g 3 h a s t h e 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
* task' s t h r e a d _ s t r u c t .
* /
# define 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 ; \
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
mfcr r10 ; \
EXCEPTION_ P R O L O G _ 1 ; \
EXCEPTION_ P R O L O G _ 2
# define E X C E P T I O N _ P R O L O G _ 1 \
mfspr r11 ,S P R N _ S R R 1 ; /* check whether user or kernel */ \
andi. r11 ,r11 ,M S R _ P R ; \
tophys( r11 ,r1 ) ; /* use tophys(r1) if kernel */ \
beq 1 f ; \
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 ,T H R E A D _ I N F O - T H R E A D ( r11 ) ; \
addi r11 ,r11 ,T H R E A D _ S I Z E ; \
tophys( r11 ,r11 ) ; \
1 : subi r11 ,r11 ,I N T _ F R A M E _ S I Z E / * a l l o c e x c . f r a m e * /
# define E X C E P T I O N _ P R O L O G _ 2 \
CLR_ T O P 3 2 ( r11 ) ; \
stw r10 ,_ C C R ( r11 ) ; /* save 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 ) ; \
mfspr r12 ,S P R N _ S R R 0 ; \
mfspr r9 ,S P R N _ S R R 1 ; \
stw r1 ,G P R 1 ( r11 ) ; \
stw r1 ,0 ( r11 ) ; \
tovirt( r1 ,r11 ) ; /* set new kernel sp */ \
li r10 ,M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R ) ; /* can take exceptions */ \
MTMSRD( r10 ) ; /* (except for mach check in rtas) */ \
stw r0 ,G P R 0 ( r11 ) ; \
SAVE_ 4 G P R S ( 3 , r11 ) ; \
SAVE_ 2 G P R S ( 7 , r11 )
/ *
* Note : code w h i c h f o l l o w s t h i s u s e s c r0 . e q ( s e t i f f r o m k e r n e l ) ,
* r1 1 , r12 ( S R R 0 ) , a n d r9 ( S R R 1 ) .
*
* Note2 : once w e h a v e s e t r1 w e a r e i n a p o s i t i o n t o t a k e e x c e p t i o n s
* again, a n d w e c o u l d t h u s s e t M S R : R I a t t h a t p o i n t .
* /
/ *
* Exception v e c t o r s .
* /
# define E X C E P T I O N ( n , l a b e l , h d l r , x f e r ) \
. = n; \
label : \
EXCEPTION_ 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 E X C _ X F E R _ T E M P L A T E ( n , h d l r , t r a p , 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
li r10 ,M S R _ K E R N E L ; \
copyee( r10 , r9 ) ; \
bl t f e r ; \
i## n : \
.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 ( n , h d l r , n , 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 ( n , h d l r , n + 1 , 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 ( n , h d l r , n , 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 ( n , h d l r , n + 1 , 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 )
/* System reset */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x10 0 , R e s e t , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ S T D )
2005-09-26 10:04:21 +04:00
/* Machine check */
. = 0 x2 0 0
MachineCheck :
EXCEPTION_ P R O L O G
mfspr r4 ,S P R N _ D A R
stw r4 ,_ D A R ( r11 )
2009-11-20 03:21:04 +03:00
li r5 ,0 x00 f0
mtspr S P R N _ D A R ,r5 / * T a g D A R , t o b e u s e d i n D T L B E r r o r * /
2005-09-26 10:04:21 +04:00
mfspr r5 ,S P R N _ D S I S R
stw r5 ,_ D S I 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 x20 0 , 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
/ * Data a c c e s s e x c e p t i o n .
* This i s " n e v e r g e n e r a t e d " b y t h e M P C 8 x x . W e j u m p t o i t f o r o t h e r
* translation e r r o r s .
* /
. = 0 x3 0 0
DataAccess :
EXCEPTION_ P R O L O G
mfspr r10 ,S P R N _ D S I S R
stw r10 ,_ D S I S R ( r11 )
mr r5 ,r10
mfspr r4 ,S P R N _ D A R
2009-11-20 03:21:04 +03:00
li r10 ,0 x00 f0
mtspr S P R N _ D A R ,r10 / * T a g D A R , t o b e u s e d i n D T L B E r r o r * /
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
/ * Instruction a c c e s s e x c e p t i o n .
* This i s " n e v e r g e n e r a t e d " b y t h e M P C 8 x x . W e j u m p t o i t f o r o t h e r
* translation e r r o r s .
* /
. = 0 x4 0 0
InstructionAccess :
EXCEPTION_ P R O L O G
mr r4 ,r12
mr r5 ,r9
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
/* External interrupt */
EXCEPTION( 0 x50 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 )
/* Alignment exception */
. = 0 x6 0 0
Alignment :
EXCEPTION_ P R O L O G
mfspr r4 ,S P R N _ D A R
stw r4 ,_ D A R ( r11 )
2009-11-20 03:21:04 +03:00
li r5 ,0 x00 f0
mtspr S P R N _ D A R ,r5 / * T a g D A R , t o b e u s e d i n D T L B E r r o r * /
2005-09-26 10:04:21 +04:00
mfspr r5 ,S P R N _ D S I S R
stw r5 ,_ D S I 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 _ 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
/* Program check exception */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x70 0 , P r o g r a m C h e c k , p r o g r a m _ c h e c k _ e x c e p t i o n , E X C _ X F E R _ S T D )
2005-09-26 10:04:21 +04:00
/ * No F P U o n M P C 8 x x . T h i s e x c e p t i o n i s n o t s u p p o s e d t o h a p p e n .
* /
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x80 0 , F P U n a v a i l a b l e , u n k n o w n _ e x c e p t i o n , E X C _ X F E R _ S T D )
2005-09-26 10:04:21 +04:00
/* Decrementer */
EXCEPTION( 0 x90 0 , D e c r e m e n t e r , t i m e r _ i n t e r r u p t , E X C _ X F E R _ L I T E )
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x a00 , 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 x b00 , 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
/* System call */
. = 0 xc0 0
SystemCall :
EXCEPTION_ 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 )
/* Single step - not used on 601 */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x d00 , S i n g l e S t e p , s i n g l e _ s t e p _ e x c e p t i o n , E X C _ X F E R _ S T D )
EXCEPTION( 0 x 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 x f00 , 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
/ * On t h e M P C 8 x x , t h i s i s a s o f t w a r e e m u l a t i o n i n t e r r u p t . I t o c c u r s
* for a l l u n i m p l e m e n t e d a n d i l l e g a l i n s t r u c t i o n s .
* /
EXCEPTION( 0 x10 0 0 , S o f t E m u , S o f t w a r e E m u l a t i o n , E X C _ X F E R _ S T D )
. = 0 x1 1 0 0
/ *
* For t h e M P C 8 x x , t h i s i s a s o f t w a r e t a b l e w a l k t o l o a d t h e i n s t r u c t i o n
* TLB. I t i s m o d e l l e d a f t e r t h e e x a m p l e i n t h e M o t o r o l a m a n u a l . T h e t a s k
* switch l o a d s t h e M _ T W B r e g i s t e r w i t h t h e p o i n t e r t o t h e f i r s t l e v e l t a b l e .
* If w e d i s c o v e r t h e r e i s n o s e c o n d l e v e l t a b l e ( v a l u e i s z e r o ) o r i f t h e r e
* is a n i n v a l i d p t e , w e l o a d t h a t i n t o t h e T L B , w h i c h c a u s e s a n o t h e r f a u l t
* into t h e T L B E r r o r i n t e r r u p t w h e r e w e c a n h a n d l e s u c h p r o b l e m s .
* We h a v e t o u s e t h e M D _ x x x r e g i s t e r s f o r t h e t a b l e w a l k b e c a u s e t h e
* equivalent M I _ x x x r e g i s t e r s o n l y p e r f o r m t h e a t t r i b u t e f u n c t i o n s .
* /
InstructionTLBMiss :
# ifdef C O N F I G _ 8 x x _ C P U 6
stw r3 , 8 ( r0 )
# endif
DO_ 8 x x _ C P U 6 ( 0 x3 f80 , r3 )
mtspr S P R N _ M _ T W , r10 / * S a v e a c o u p l e o f w o r k i n g r e g i s t e r s * /
mfcr r10
2010-03-02 08:37:12 +03:00
# ifdef C O N F I G _ 8 x x _ C P U 6
2005-09-26 10:04:21 +04:00
stw r10 , 0 ( r0 )
stw r11 , 4 ( r0 )
2010-03-02 08:37:12 +03:00
# else
mtspr S P R N _ D A R , r10
mtspr S P R N _ S P R G 2 , r11
# endif
2005-09-26 10:04:21 +04:00
mfspr r10 , S P R N _ S R R 0 / * G e t e f f e c t i v e a d d r e s s o f f a u l t * /
2007-06-25 23:50:41 +04:00
# ifdef C O N F I G _ 8 x x _ C P U 1 5
addi r11 , r10 , 0 x10 0 0
tlbie r11
addi r11 , r10 , - 0 x10 0 0
tlbie r11
# endif
2005-09-26 10:04:21 +04:00
DO_ 8 x x _ C P U 6 ( 0 x37 8 0 , r3 )
mtspr S P R N _ M D _ E P N , r10 / * H a v e t o u s e M D _ E P N f o r w a l k , M I _ E P N c a n ' t * /
mfspr r10 , S P R N _ M _ T W B / * G e t l e v e l 1 t a b l e e n t r y 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 .
* /
2010-03-02 08:37:10 +03:00
# ifdef C O N F I G _ M O D U L E S
/ * Only m o d u l e s w i l l c a u s e I T L B M i s s e s a s w e a l w a y s
* pin t h e f i r s t 8 M B o f k e r n e l m e m o r y * /
2005-09-26 10:04:21 +04:00
andi. r11 , r10 , 0 x08 0 0 / * A d d r e s s > = 0 x80 0 0 0 0 0 0 * /
beq 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
rlwimi r10 , r11 , 0 , 2 , 1 9
3 :
2010-03-02 08:37:10 +03:00
# endif
2005-09-26 10:04:21 +04:00
lwz r11 , 0 ( r10 ) / * G e t t h e l e v e l 1 e n t r y * /
rlwinm. r10 , r11 ,0 ,0 ,1 9 / * E x t r a c t p a g e d e s c r i p t o r p a g e a d d r e s s * /
beq 2 f / * I f z e r o , d o n ' t t r y t o f i n d a p t e * /
/ * We h a v e a p t e t a b l e , s o l o a d t h e M I _ T W C w i t h t h e a t t r i b u t e s
* for t h i s " s e g m e n t . "
* /
ori r11 ,r11 ,1 / * S e t v a l i d b i t * /
DO_ 8 x x _ C P U 6 ( 0 x2 b80 , r3 )
mtspr S P R N _ M I _ T W C , r11 / * S e t s e g m e n t a t t r i b u t e s * /
DO_ 8 x x _ C P U 6 ( 0 x3 b80 , r3 )
mtspr S P R N _ M D _ T W C , r11 / * L o a d p t e t a b l e b a s e a d d r e s s * /
mfspr r11 , S P R N _ M D _ T W C / * . . . . a n d g e t t h e p t e a d d r e s s * /
lwz r10 , 0 ( r11 ) / * G e t t h e p t e * /
2010-03-02 08:37:11 +03:00
# ifdef C O N F I G _ S W A P
2009-11-20 03:21:03 +03:00
andi. r11 , r10 , _ P A G E _ A C C E S S E D | _ P A G E _ P R E S E N T
cmpwi c r0 , r11 , _ P A G E _ A C C E S S E D | _ P A G E _ P R E S E N T
bne- c r0 , 2 f
2010-03-02 08:37:11 +03:00
# endif
2005-09-26 10:04:21 +04:00
/ * The L i n u x P T E w o n ' t g o e x a c t l y i n t o t h e M M U T L B .
2010-03-02 08:37:09 +03:00
* Software i n d i c a t o r b i t s 2 1 a n d 2 8 m u s t b e c l e a r .
2005-09-26 10:04:21 +04:00
* Software i n d i c a t o r b i t s 2 4 , 2 5 , 2 6 , a n d 2 7 m u s t b e
* set. A l l o t h e r L i n u x P T E b i t s c o n t r o l t h e b e h a v i o r
* of t h e M M U .
* /
2009-11-20 03:21:03 +03:00
li r11 , 0 x00 f0
2010-03-02 08:37:09 +03:00
rlwimi r10 , r11 , 0 , 0 x07 f8 / * S e t 2 4 - 2 7 , c l e a r 2 1 - 2 3 ,2 8 * /
2005-09-26 10:04:21 +04:00
DO_ 8 x x _ C P U 6 ( 0 x2 d80 , r3 )
mtspr S P R N _ M I _ R P N , r10 / * U p d a t e T L B e n t r y * /
2010-03-02 08:37:12 +03:00
/* Restore registers */
# ifndef C O N F I G _ 8 x x _ C P U 6
mfspr r10 , S P R N _ D A R
mtcr r10
mtspr S P R N _ D A R , r11 / * T a g D A R * /
mfspr r11 , S P R N _ S P R G 2
# else
2005-09-26 10:04:21 +04:00
lwz r11 , 0 ( r0 )
mtcr r11
lwz r11 , 4 ( r0 )
lwz r3 , 8 ( r0 )
# endif
2010-03-02 08:37:12 +03:00
mfspr r10 , S P R N _ M _ T W
2005-09-26 10:04:21 +04:00
rfi
2009-11-20 03:21:03 +03:00
2 :
mfspr r11 , S P R N _ S R R 1
/ * clear a l l e r r o r b i t s a s T L B M i s s
* sets a f e w u n c o n d i t i o n a l l y
* /
rlwinm r11 , r11 , 0 , 0 x f f f f
mtspr S P R N _ S R R 1 , r11
2010-03-02 08:37:12 +03:00
/* Restore registers */
# ifndef C O N F I G _ 8 x x _ C P U 6
mfspr r10 , S P R N _ D A R
mtcr r10
li r11 , 0 x00 f0
mtspr S P R N _ D A R , r11 / * T a g D A R * /
mfspr r11 , S P R N _ S P R G 2
# else
2009-11-20 03:21:03 +03:00
lwz r11 , 0 ( r0 )
mtcr r11
lwz r11 , 4 ( r0 )
lwz r3 , 8 ( r0 )
# endif
2010-03-02 08:37:12 +03:00
mfspr r10 , S P R N _ M _ T W
2009-11-20 03:21:03 +03:00
b I n s t r u c t i o n A c c e s s
2005-09-26 10:04:21 +04:00
. = 0 x1 2 0 0
DataStoreTLBMiss :
# ifdef C O N F I G _ 8 x x _ C P U 6
stw r3 , 8 ( r0 )
# endif
DO_ 8 x x _ C P U 6 ( 0 x3 f80 , r3 )
mtspr S P R N _ M _ T W , r10 / * S a v e a c o u p l e o f w o r k i n g r e g i s t e r s * /
mfcr r10
2010-03-02 08:37:12 +03:00
# ifdef C O N F I G _ 8 x x _ C P U 6
2005-09-26 10:04:21 +04:00
stw r10 , 0 ( r0 )
stw r11 , 4 ( r0 )
2010-03-02 08:37:12 +03:00
# else
mtspr S P R N _ D A R , r10
mtspr S P R N _ S P R G 2 , r11
# endif
2005-09-26 10:04:21 +04:00
mfspr r10 , S P R N _ M _ T W B / * G e t l e v e l 1 t a b l e e n t r y 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 .
* /
andi. r11 , r10 , 0 x08 0 0
beq 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
rlwimi r10 , r11 , 0 , 2 , 1 9
3 :
lwz r11 , 0 ( r10 ) / * G e t t h e l e v e l 1 e n t r y * /
rlwinm. r10 , r11 ,0 ,0 ,1 9 / * E x t r a c t p a g e d e s c r i p t o r p a g e a d d r e s s * /
beq 2 f / * I f z e r o , d o n ' t t r y t o f i n d a p t e * /
/ * We h a v e a p t e t a b l e , s o l o a d f e t c h t h e p t e f r o m t h e t a b l e .
* /
ori r11 , r11 , 1 / * S e t v a l i d b i t i n p h y s i c a l L 2 p a g e * /
DO_ 8 x x _ C P U 6 ( 0 x3 b80 , r3 )
mtspr S P R N _ M D _ T W C , r11 / * L o a d p t e t a b l e b a s e a d d r e s s * /
mfspr r10 , S P R N _ M D _ T W C / * . . . . a n d g e t t h e p t e a d d r e s s * /
lwz r10 , 0 ( r10 ) / * G e t t h e p t e * /
/ * Insert t h e G u a r d e d f l a g i n t o t h e T W C f r o m t h e L i n u x P T E .
* It i s b i t 2 7 o f b o t h t h e L i n u x P T E a n d t h e T W C ( a t l e a s t
* I g o t t h a t r i g h t : - ) . I t w i l l b e b e t t e r w h e n w e c a n p u t
* this i n t o t h e L i n u x p g d / p m d a n d l o a d i t i n t h e o p e r a t i o n
* above.
* /
rlwimi r11 , r10 , 0 , 2 7 , 2 7
2009-11-20 03:21:08 +03:00
/ * Insert t h e W r i t e T h r u f l a g i n t o t h e T W C f r o m t h e L i n u x P T E .
* It i s b i t 2 5 i n t h e L i n u x P T E a n d b i t 3 0 i n t h e T W C
* /
rlwimi r11 , r10 , 3 2 - 5 , 3 0 , 3 0
2005-09-26 10:04:21 +04:00
DO_ 8 x x _ C P U 6 ( 0 x3 b80 , r3 )
mtspr S P R N _ M D _ T W C , r11
2009-11-20 03:21:03 +03:00
/ * Both _ P A G E _ A C C E S S E D a n d _ P A G E _ P R E S E N T h a s t o b e s e t .
* We a l s o n e e d t o k n o w i f t h e i n s n i s a l o a d / s t o r e , s o :
* Clear _ P A G E _ P R E S E N T a n d l o a d t h a t w h i c h w i l l
* trap i n t o D T L B E r r o r w i t h s t o r e b i t s e t a c c o r d i n l y .
* /
/ * PRESENT=0x1 , A C C E S S E D =0x20
* r1 1 = ( ( r10 & P R E S E N T ) & ( ( r10 & A C C E S S E D ) > > 5 ) ) ;
* r1 0 = ( r10 & ~ P R E S E N T ) | r11 ;
* /
2010-03-02 08:37:11 +03:00
# ifdef C O N F I G _ S W A P
2009-11-20 03:21:11 +03:00
rlwinm r11 , r10 , 3 2 - 5 , _ P A G E _ P R E S E N T
2009-11-20 03:21:03 +03:00
and r11 , r11 , r10
2009-11-20 03:21:11 +03:00
rlwimi r10 , r11 , 0 , _ P A G E _ P R E S E N T
2010-03-02 08:37:11 +03:00
# endif
2009-11-20 03:21:03 +03:00
/* Honour kernel RO, User NA */
2009-11-20 03:21:11 +03:00
/* 0x200 == Extended encoding, bit 22 */
2010-03-02 08:37:09 +03:00
rlwimi r10 , r10 , 3 2 - 2 , 0 x20 0 / * C o p y U S E R t o b i t 2 2 , 0 x20 0 * /
2009-11-20 03:21:11 +03:00
/* r11 = (r10 & _PAGE_RW) >> 1 */
rlwinm r11 , r10 , 3 2 - 1 , 0 x20 0
or r10 , r11 , r10
/* invert RW and 0x200 bits */
xori r10 , r10 , _ P A G E _ R W | 0 x20 0
2005-09-26 10:04:21 +04:00
/ * The L i n u x P T E w o n ' t g o e x a c t l y i n t o t h e M M U T L B .
2009-11-20 03:21:03 +03:00
* Software i n d i c a t o r b i t s 2 2 a n d 2 8 m u s t b e c l e a r .
2005-09-26 10:04:21 +04:00
* Software i n d i c a t o r b i t s 2 4 , 2 5 , 2 6 , a n d 2 7 m u s t b e
* set. A l l o t h e r L i n u x P T E b i t s c o n t r o l t h e b e h a v i o r
* of t h e M M U .
* /
2 : li r11 , 0 x00 f0
rlwimi r10 , r11 , 0 , 2 4 , 2 8 / * S e t 2 4 - 2 7 , c l e a r 2 8 * /
DO_ 8 x x _ C P U 6 ( 0 x3 d80 , r3 )
mtspr S P R N _ M D _ R P N , r10 / * U p d a t e T L B e n t r y * /
2010-03-02 08:37:12 +03:00
/* Restore registers */
# ifndef C O N F I G _ 8 x x _ C P U 6
mfspr r10 , S P R N _ D A R
mtcr r10
mtspr S P R N _ D A R , r11 / * T a g D A R * /
mfspr r11 , S P R N _ S P R G 2
# else
mtspr S P R N _ D A R , r11 / * T a g D A R * /
2005-09-26 10:04:21 +04:00
lwz r11 , 0 ( r0 )
mtcr r11
lwz r11 , 4 ( r0 )
lwz r3 , 8 ( r0 )
# endif
2010-03-02 08:37:12 +03:00
mfspr r10 , S P R N _ M _ T W
2005-09-26 10:04:21 +04:00
rfi
/ * This i s a n i n s t r u c t i o n T L B e r r o r o n t h e M P C 8 x x . T h i s c o u l d b e d u e
* to m a n y r e a s o n s , s u c h a s e x e c u t i n g g u a r d e d m e m o r y o r i l l e g a l i n s t r u c t i o n
* addresses. T h e r e i s n o t h i n g t o d o b u t h a n d l e a b i g t i m e e r r o r f a u l t .
* /
. = 0 x1 3 0 0
InstructionTLBError :
b I n s t r u c t i o n A c c e s s
/ * This i s t h e d a t a T L B e r r o r o n t h e M P C 8 x x . T h i s c o u l d b e d u e t o
* many r e a s o n s , i n c l u d i n g a d i r t y u p d a t e t o a p t e . W e c a n c a t c h t h a t
* one h e r e , b u t a n y t h i n g e l s e i s a n e r r o r . F i r s t , w e t r a c k d o w n t h e
* Linux p t e . I f i t i s v a l i d , w r i t e a c c e s s i s a l l o w e d , b u t t h e
* page d i r t y b i t i s n o t s e t , w e w i l l s e t i t a n d r e l o a d t h e T L B . F o r
* any o t h e r c a s e , w e b a i l o u t t o a h i g h e r l e v e l f u n c t i o n t h a t c a n
* handle i t .
* /
. = 0 x1 4 0 0
DataTLBError :
# ifdef C O N F I G _ 8 x x _ C P U 6
stw r3 , 8 ( r0 )
# endif
DO_ 8 x x _ C P U 6 ( 0 x3 f80 , r3 )
mtspr S P R N _ M _ T W , r10 / * S a v e a c o u p l e o f w o r k i n g r e g i s t e r s * /
mfcr r10
stw r10 , 0 ( r0 )
stw r11 , 4 ( r0 )
2009-11-20 03:21:04 +03:00
mfspr r10 , S P R N _ D A R
cmpwi c r0 , r10 , 0 x00 f0
2009-11-20 03:21:06 +03:00
beq- F i x u p D A R / * m u s t b e a b u g g y d c b X , i c b i i n s n . * /
DARFixed : /* Return from dcbx instruction bug workaround, r10 holds value of DAR */
2005-09-26 10:04:21 +04:00
mfspr r10 , S P R N _ M _ T W / * R e s t o r e r e g i s t e r s * /
lwz r11 , 0 ( r0 )
mtcr r11
lwz r11 , 4 ( r0 )
# ifdef C O N F I G _ 8 x x _ C P U 6
lwz r3 , 8 ( r0 )
# endif
b D a t a A c c e s s
2005-10-01 12:43:42 +04:00
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 )
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 )
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 a00 , 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 b00 , 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 )
2005-09-26 10:04:21 +04:00
/ * On t h e M P C 8 x x , t h e s e n e x t f o u r t r a p s a r e u s e d f o r d e v e l o p m e n t
* support o f b r e a k p o i n t s a n d s u c h . S o m e d a y I w i l l g e t a r o u n d t o
* using t h e m .
* /
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x1 c00 , 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 d00 , 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 f00 , 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
. = 0 x2 0 0 0
2009-11-20 03:21:06 +03:00
/ * This i s t h e p r o c e d u r e t o c a l c u l a t e t h e d a t a E A f o r b u g g y d c b x ,d c b i i n s t r u c t i o n s
* by d e c o d i n g t h e r e g i s t e r s u s e d b y t h e d c b x i n s t r u c t i o n a n d a d d i n g t h e m .
* DAR i s s e t t o t h e c a l c u l a t e d a d d r e s s a n d r10 a l s o h o l d s t h e E A o n e x i t .
* /
/* define if you don't want to use self modifying code */
# define N O _ S E L F _ M O D I F Y I N G _ C O D E
FixupDAR : /* Entry point for dcbx workaround. */
/* fetch instruction from memory. */
mfspr r10 , S P R N _ S R R 0
2010-01-08 09:46:26 +03:00
andis. r11 , r10 , 0 x80 0 0 / * A d d r e s s > = 0 x80 0 0 0 0 0 0 * /
2009-11-20 03:21:06 +03:00
DO_ 8 x x _ C P U 6 ( 0 x37 8 0 , r3 )
mtspr S P R N _ M D _ E P N , r10
mfspr r11 , S P R N _ M _ T W B / * G e t l e v e l 1 t a b l e e n t r y a d d r e s s * /
2010-01-08 09:46:26 +03:00
beq- 3 f / * B r a n c h i f u s e r s p a c e * /
2009-11-20 03:21:06 +03:00
lis r11 , ( s w a p p e r _ p g _ d i r - P A G E _ O F F S E T ) @h
ori r11 , r11 , ( s w a p p e r _ p g _ d i r - P A G E _ O F F S E T ) @l
rlwimi r11 , r10 , 3 2 - 2 0 , 0 x f f c / * r11 = r11 & ~ 0 x f f c | ( r10 > > 2 0 ) & 0 x f f c * /
3 : lwz r11 , 0 ( r11 ) / * G e t t h e l e v e l 1 e n t r y * /
DO_ 8 x x _ C P U 6 ( 0 x3 b80 , r3 )
mtspr S P R N _ M D _ T W C , r11 / * L o a d p t e t a b l e b a s e a d d r e s s * /
mfspr r11 , S P R N _ M D _ T W C / * . . . . a n d g e t t h e p t e a d d r e s s * /
lwz r11 , 0 ( r11 ) / * G e t t h e p t e * /
/* concat physical page address(r11) and page offset(r10) */
rlwimi r11 , r10 , 0 , 2 0 , 3 1
lwz r11 ,0 ( r11 )
/* Check if it really is a dcbx instruction. */
/ * dcbt a n d d c b t s t d o e s n o t g e n e r a t e D T L B M i s s e s / E r r o r s ,
* no n e e d t o i n c l u d e t h e m h e r e * /
srwi r10 , r11 , 2 6 / * c h e c k i f m a j o r O P c o d e i s 3 1 * /
cmpwi c r0 , r10 , 3 1
bne- 1 4 1 f
rlwinm r10 , r11 , 0 , 2 1 , 3 0
cmpwi c r0 , r10 , 2 0 2 8 / * I s d c b z ? * /
beq+ 1 4 2 f
cmpwi c r0 , r10 , 9 4 0 / * I s d c b i ? * /
beq+ 1 4 2 f
cmpwi c r0 , r10 , 1 0 8 / * I s d c b s t ? * /
beq+ 1 4 4 f / * F i x u p s t o r e b i t ! * /
cmpwi c r0 , r10 , 1 7 2 / * I s d c b f ? * /
beq+ 1 4 2 f
cmpwi c r0 , r10 , 1 9 6 4 / * I s i c b i ? * /
beq+ 1 4 2 f
141 : mfspr r10 , S P R N _ D A R / * r10 m u s t h o l d D A R a t e x i t * /
b D A R F i x e d / * N o p e , g o b a c k t o n o r m a l T L B p r o c e s s i n g * /
144 : mfspr r10 , S P R N _ D S I S R
rlwinm r10 , r10 ,0 ,7 ,5 / * C l e a r s t o r e b i t f o r b u g g y d c b s t i n s n * /
mtspr S P R N _ D S I S R , r10
142 : /* continue, it was a dcbx, dcbi instruction. */
# ifdef C O N F I G _ 8 x x _ C P U 6
lwz r3 , 8 ( r0 ) / * r e s t o r e r3 f r o m m e m o r y * /
# endif
# ifndef N O _ S E L F _ M O D I F Y I N G _ C O D E
andis. r10 ,r11 ,0 x1 f / * t e s t i f r e g R A i s r0 * /
li r10 ,m o d i f i e d _ i n s t r @l
dcbtst r0 ,r10 / * t o u c h f o r s t o r e * /
rlwinm r11 ,r11 ,0 ,0 ,2 0 / * Z e r o l o w e r 1 0 b i t s * /
oris r11 ,r11 ,6 4 0 / * T r a n s f o r m i n s t r . t o a " a d d r10 ,R A ,R B " * /
ori r11 ,r11 ,5 3 2
stw r11 ,0 ( r10 ) / * s t o r e a d d / a n d i n s t r u c t i o n * /
dcbf 0 ,r10 / * f l u s h n e w i n s t r . t o m e m o r y . * /
icbi 0 ,r10 / * i n v a l i d a t e i n s t r . c a c h e l i n e * /
lwz r11 , 4 ( r0 ) / * r e s t o r e r11 f r o m m e m o r y * /
mfspr r10 , S P R N _ M _ T W / * r e s t o r e r10 f r o m M _ T W * /
isync / * W a i t u n t i l n e w i n s t r i s l o a d e d f r o m m e m o r y * /
modified_instr :
.space 4 /* this is where the add instr. is stored */
bne+ 1 4 3 f
subf r10 ,r0 ,r10 / * r10 =r10 - r0 , o n l y i f r e g R A i s r0 * /
143 : mtdar r10 / * s t o r e f a u l t i n g E A i n D A R * /
b D A R F i x e d / * G o b a c k t o n o r m a l T L B h a n d l i n g * /
# else
mfctr r10
mtdar r10 / * s a v e c t r r e g i n D A R * /
rlwinm r10 , r11 , 2 4 , 2 4 , 2 8 / * o f f s e t i n t o j u m p t a b l e f o r r e g R B * /
addi r10 , r10 , 1 5 0 f @l /* add start of table */
mtctr r10 / * l o a d c t r w i t h j u m p a d d r e s s * /
xor r10 , r10 , r10 / * s u m s t a r t s a t z e r o * /
bctr / * j u m p i n t o t a b l e * /
150 :
add r10 , r10 , r0 ;b 151f
add r10 , r10 , r1 ;b 151f
add r10 , r10 , r2 ;b 151f
add r10 , r10 , r3 ;b 151f
add r10 , r10 , r4 ;b 151f
add r10 , r10 , r5 ;b 151f
add r10 , r10 , r6 ;b 151f
add r10 , r10 , r7 ;b 151f
add r10 , r10 , r8 ;b 151f
add r10 , r10 , r9 ;b 151f
mtctr r11 ;b 154f /* r10 needs special handling */
mtctr r11 ;b 153f /* r11 needs special handling */
add r10 , r10 , r12 ;b 151f
add r10 , r10 , r13 ;b 151f
add r10 , r10 , r14 ;b 151f
add r10 , r10 , r15 ;b 151f
add r10 , r10 , r16 ;b 151f
add r10 , r10 , r17 ;b 151f
add r10 , r10 , r18 ;b 151f
add r10 , r10 , r19 ;b 151f
add r10 , r10 , r20 ;b 151f
add r10 , r10 , r21 ;b 151f
add r10 , r10 , r22 ;b 151f
add r10 , r10 , r23 ;b 151f
add r10 , r10 , r24 ;b 151f
add r10 , r10 , r25 ;b 151f
add r10 , r10 , r26 ;b 151f
add r10 , r10 , r27 ;b 151f
add r10 , r10 , r28 ;b 151f
add r10 , r10 , r29 ;b 151f
add r10 , r10 , r30 ;b 151f
add r10 , r10 , r31
151 :
rlwinm. r11 ,r11 ,1 9 ,2 4 ,2 8 / * o f f s e t i n t o j u m p t a b l e f o r r e g R A * /
beq 1 5 2 f / * i f r e g R A i s z e r o , d o n ' t a d d i t * /
addi r11 , r11 , 1 5 0 b @l /* add start of table */
mtctr r11 / * l o a d c t r w i t h j u m p a d d r e s s * /
rlwinm r11 ,r11 ,0 ,1 6 ,1 0 / * m a k e s u r e w e d o n ' t e x e c u t e t h i s m o r e t h a n o n c e * /
bctr / * j u m p i n t o t a b l e * /
152 :
mfdar r11
mtctr r11 / * r e s t o r e c t r r e g f r o m D A R * /
mtdar r10 / * s a v e f a u l t E A t o D A R * /
b D A R F i x e d / * G o b a c k t o n o r m a l T L B h a n d l i n g * /
/* special handling for r10,r11 since these are modified already */
153 : lwz r11 , 4 ( r0 ) / * l o a d r11 f r o m m e m o r y * /
b 1 5 5 f
154 : mfspr r11 , S P R N _ M _ T W / * l o a d r10 f r o m M _ T W * /
155 : add r10 , r10 , r11 / * a d d i t * /
mfctr r11 / * r e s t o r e r11 * /
b 1 5 1 b
# endif
2005-09-26 10:04:21 +04:00
.globl giveup_fpu
giveup_fpu :
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 8 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 8 M b y t e T L B m a p p i n g s a n d l o a d t h e p a g e t a b l e b a s e r e g i s t e r .
* /
/ * The r i g h t w a y t o d o t h i s w o u l d b e t o t r a c k i t d o w n t h r o u g h
* init' s T H R E A D l i k e t h e c o n t e x t s w i t c h c o d e d o e s , b u t t h i s i s
* easier. . . . . . u n t i l s o m e o n e c h a n g e s i n i t ' s s t a t i c s t r u c t u r e s .
* /
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
tophys( r6 ,r6 )
# ifdef C O N F I G _ 8 x x _ C P U 6
lis r4 , c p u 6 _ e r r a t a _ w o r d @h
ori r4 , r4 , c p u 6 _ e r r a t a _ w o r d @l
li r3 , 0 x39 8 0
stw r3 , 1 2 ( r4 )
lwz r3 , 1 2 ( r4 )
# endif
mtspr S P R N _ M _ T W B , r6
lis r4 ,2 f @h
ori r4 ,r4 ,2 f @l
tophys( r4 ,r4 )
li r3 ,M S R _ K E R N E L & ~ ( M S R _ I R | M S R _ D R )
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r3
rfi
/* Load up the kernel context */
2 :
SYNC / * F o r c e a l l P T E u p d a t e s t o f i n i s h * /
tlbia / * C l e a r a l l T L B e n t r i e s * /
sync / * w a i t f o r t l b i a / t l b i e t o f i n i s h * /
TLBSYNC / * . . . o n a l l C P U 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 .
* /
tovirt( r6 ,r6 )
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! */
li r4 ,M S R _ K E R N E 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 * /
/ * 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 8 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 l s o , s e t t h e c a c h e m o d e s i n c e t h a t i s d e f i n e d
* by T L B e n t r i e s a n d p e r f o r m a n y a d d i t i o n a l m a p p i n g ( l i k e o f t h e I M M R ) .
* If c o n f i g u r e d t o p i n s o m e T L B s , w e p i n t h e f i r s t 8 M b y t e s o f k e r n e l ,
* 2 4 Mbytes o f d a t a , a n d t h e 8 M I M M R s p a c e . A n y t h i n g n o t c o v e r e d b y
* these m a p p i n g s i s m a p p e d b y p a g e t a b l e s .
* /
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 * /
2009-12-29 08:10:58 +03:00
/ * Always p i n t h e f i r s t 8 M B I T L B t o p r e v e n t I T L B
misses w h i l e m u c k i n g a r o u n d w i t h S R R 0 / S R R 1 i n a s m
* /
2005-09-26 10:04:21 +04:00
lis r8 , M I _ R S V 4 I @h
ori r8 , r8 , 0 x1 c00
2009-12-29 08:10:58 +03:00
2005-09-26 10:04:21 +04:00
mtspr S P R N _ M I _ C T R , r8 / * S e t i n s t r u c t i o n M M U c o n t r o l * /
# ifdef C O N F I G _ P I N _ T L B
lis r10 , ( M D _ R S V 4 I | M D _ R E S E T V A L ) @h
ori r10 , r10 , 0 x1 c00
mr r8 , r10
# else
lis r10 , M D _ R E S E T V A L @h
# endif
# ifndef C O N F I G _ 8 x x _ C O P Y B A C K
oris r10 , r10 , M D _ W T D E F @h
# endif
mtspr S P R N _ M D _ C T R , r10 / * S e t d a t a T L B c o n t r o l * /
/ * Now m a p t h e l o w e r 8 M e g i n t o t h e T L B s . F o r t h i s q u i c k h a c k ,
* we c a n l o a d t h e i n s t r u c t i o n a n d d a t a T L B r e g i s t e r s w i t h t h e
* same v a l u e s .
* /
lis r8 , K E R N E L B A S E @h /* Create vaddr for TLB */
ori r8 , r8 , M I _ E V A L I D / * M a r k i t v a l i d * /
mtspr S P R N _ M I _ E P N , r8
mtspr S P R N _ M D _ E P N , r8
li r8 , M I _ P S 8 M E G / * S e t 8 M b y t e p a g e * /
ori r8 , r8 , M I _ S V A L I D / * M a k e i t v a l i d * /
mtspr S P R N _ M I _ T W C , r8
mtspr S P R N _ M D _ T W C , r8
li r8 , M I _ B O O T I N I T / * C r e a t e R P N f o r a d d r e s s 0 * /
mtspr S P R N _ M I _ R P N , r8 / * S t o r e T L B e n t r y * /
mtspr S P R N _ M D _ R P N , r8
lis r8 , M I _ K p @h /* Set the protection mode */
mtspr S P R N _ M I _ A P , r8
mtspr S P R N _ M D _ A P , r8
/ * Map a n o t h e r 8 M B y t e a t t h e I M M R t o g e t t h e p r o c e s s o r
* internal r e g i s t e r s ( a m o n g o t h e r t h i n g s ) .
* /
# ifdef C O N F I G _ P I N _ T L B
addi r10 , r10 , 0 x01 0 0
mtspr S P R N _ M D _ C T R , r10
# endif
mfspr r9 , 6 3 8 / * G e t c u r r e n t I M M R * /
andis. r9 , r9 , 0 x f f80 / * G e t 8 M b y t e b o u n d a r y * /
mr r8 , r9 / * C r e a t e v a d d r f o r T L B * /
ori r8 , r8 , M D _ E V A L I D / * M a r k i t v a l i d * /
mtspr S P R N _ M D _ E P N , r8
li r8 , M D _ P S 8 M E G / * S e t 8 M b y t e p a g e * /
ori r8 , r8 , M D _ S V A L I D / * M a k e i t v a l i d * /
mtspr S P R N _ M D _ T W C , r8
mr r8 , r9 / * C r e a t e p a d d r f o r T L B * /
ori r8 , r8 , M I _ B O O T I N I T | 0 x2 / * I n h i b i t c a c h e - - C o r t * /
mtspr S P R N _ M D _ R P N , r8
# ifdef C O N F I G _ P I N _ T L B
/ * Map t w o m o r e 8 M k e r n e l d a t a p a g e s .
* /
addi r10 , r10 , 0 x01 0 0
mtspr S P R N _ M D _ C T R , r10
lis r8 , K E R N E L B A S E @h /* Create vaddr for TLB */
addis r8 , r8 , 0 x00 8 0 / * A d d 8 M * /
ori r8 , r8 , M I _ E V A L I D / * M a r k i t v a l i d * /
mtspr S P R N _ M D _ E P N , r8
li r9 , M I _ P S 8 M E G / * S e t 8 M b y t e p a g e * /
ori r9 , r9 , M I _ S V A L I D / * M a k e i t v a l i d * /
mtspr S P R N _ M D _ T W C , r9
li r11 , M I _ B O O T I N I T / * C r e a t e R P N f o r a d d r e s s 0 * /
addis r11 , r11 , 0 x00 8 0 / * A d d 8 M * /
2007-07-16 20:28:18 +04:00
mtspr S P R N _ M D _ R P N , r11
2005-09-26 10:04:21 +04:00
addis r8 , r8 , 0 x00 8 0 / * A d d 8 M * /
mtspr S P R N _ M D _ E P N , r8
mtspr S P R N _ M D _ T W C , r9
addis r11 , r11 , 0 x00 8 0 / * A d d 8 M * /
2007-07-16 20:28:18 +04:00
mtspr S P R N _ M D _ R P N , r11
2005-09-26 10:04:21 +04:00
# endif
/ * Since t h e c a c h e i s e n a b l e d a c c o r d i n g t o t h e i n f o r m a t i o n w e
* just l o a d e d i n t o t h e T L B , i n v a l i d a t e a n d e n a b l e t h e c a c h e s h e r e .
* We s h o u l d p r o b a b l y c h e c k / s e t o t h e r m o d e s . . . . l a t e r .
* /
lis r8 , I D C _ I N V A L L @h
mtspr S P R N _ I C _ C S T , r8
mtspr S P R N _ D C _ C S T , r8
lis r8 , I D C _ E N A B L E @h
mtspr S P R N _ I C _ C S T , r8
# ifdef C O N F I G _ 8 x x _ C O P Y B A C K
mtspr S P R N _ D C _ C S T , r8
# else
/ * For a d e b u g o p t i o n , I l e f t t h i s h e r e t o e a s i l y e n a b l e
* the w r i t e t h r o u g h c a c h e m o d e
* /
lis r8 , D C _ S F W T @h
mtspr S P R N _ D C _ C S T , r8
lis r8 , I D C _ E N A B L E @h
mtspr S P R N _ D C _ C S T , r8
# endif
blr
/ *
* Set u p t o u s e a g i v e n M M U c o n t e x t .
* r3 i s c o n t e x t n u m b e r , r4 i s P G D p o i n t e r .
*
* We p l a c e t h e p h y s i c a l a d d r e s s o f t h e n e w t a s k p a g e d i r e c t o r y l o a d e d
* into t h e M M U b a s e r e g i s t e r , a n d s e t t h e A S I D c o m p a r e r e g i s t e r w i t h
* the n e w " c o n t e x t . "
* /
_ 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 p a s s e d a s s e c o n d a r g u m e n t .
* /
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
# ifdef C O N F I G _ 8 x x _ C P U 6
lis r6 , c p u 6 _ e r r a t a _ w o r d @h
ori r6 , r6 , c p u 6 _ e r r a t a _ w o r d @l
tophys ( r4 , r4 )
li r7 , 0 x39 8 0
stw r7 , 1 2 ( r6 )
lwz r7 , 1 2 ( r6 )
mtspr S P R N _ M _ T W B , r4 / * U p d a t e M M U b a s e a d d r e s s * /
li r7 , 0 x33 8 0
stw r7 , 1 2 ( r6 )
lwz r7 , 1 2 ( r6 )
mtspr S P R N _ M _ C A S I D , r3 / * U p d a t e c o n t e x t * /
# else
mtspr S P R N _ M _ C A S I D ,r3 / * U p d a t e c o n t e x t * /
tophys ( r4 , r4 )
mtspr S P R N _ M _ T W B , r4 / * a n d p g d * /
# endif
SYNC
blr
# ifdef C O N F I G _ 8 x x _ C P U 6
/ * It' s h e r e b e c a u s e i t i s u n i q u e t o t h e 8 x x .
* It i s i m p o r t a n t w e g e t c a l l e d w i t h i n t e r r u p t s d i s a b l e d . I u s e d t o
* do t h a t , b u t i t a p p e a r s t h a t a l l c o d e t h a t c a l l s t h i s a l r e a d y h a d
* interrupt d i s a b l e d .
* /
.globl set_dec_cpu6
set_dec_cpu6 :
lis r7 , c p u 6 _ e r r a t a _ w o r d @h
ori r7 , r7 , c p u 6 _ e r r a t a _ w o r d @l
li r4 , 0 x2 c00
stw r4 , 8 ( r7 )
lwz r4 , 8 ( r7 )
mtspr 2 2 , r3 / * U p d a t e D e c r e m e n t e r * /
SYNC
blr
# endif
/ *
* 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 .
* This s t u f f g o e s 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 ,
* which i s p a g e - a l i g n e d .
* /
.data
.globl sdata
sdata :
.globl empty_zero_page
empty_zero_page :
.space 4096
.globl swapper_pg_dir
swapper_pg_dir :
.space 4096
/ * Room f o r t w o P T E t a b l e p o i n 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
* pointer t o 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 ( p g d i r ) .
* /
abatron_pteptrs :
.space 8
# ifdef C O N F I G _ 8 x x _ C P U 6
.globl cpu6_errata_word
cpu6_errata_word :
.space 16
# endif