2005-09-26 10:04:21 +04:00
/ *
* Kernel e x e c u t i o n e n t r y p o i n t c o d e .
*
* 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>
2007-09-27 17:43:35 +04:00
* Initial P o w e r P C v e r s i o n .
2005-09-26 10:04:21 +04:00
* Copyright ( c ) 1 9 9 6 C o r t D o u g a n < c o r t @cs.nmt.edu>
2007-09-27 17:43:35 +04:00
* Rewritten f o r P R e P
2005-09-26 10:04:21 +04:00
* 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>
2007-09-27 17:43:35 +04:00
* 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 .
2005-09-26 10:04:21 +04:00
* Copyright ( c ) 1 9 9 7 D a n M a l e k < d m a l e k @jlc.net>
2007-09-27 17:43:35 +04:00
* PowerPC 8 x x m o d i f i c a t i o n s .
2005-09-26 10:04:21 +04:00
* Copyright ( c ) 1 9 9 8 - 1 9 9 9 T i V o , I n c .
2007-09-27 17:43:35 +04:00
* PowerPC 4 0 3 G C X m o d i f i c a t i o n s .
2005-09-26 10:04:21 +04:00
* 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>
2007-09-27 17:43:35 +04:00
* 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 .
2005-09-26 10:04:21 +04:00
* 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
2007-09-27 17:43:35 +04:00
* 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
2005-09-26 10:04:21 +04:00
* Copyright 2 0 0 2 - 2 0 0 4 M o n t a V i s t a S o f t w a r e , I n c .
2007-09-27 17:43:35 +04:00
* PowerPC 4 4 x s u p p o r t , M a t t P o r t e r < m p o r t e r @kernel.crashing.org>
2005-09-26 10:04:21 +04:00
* Copyright 2 0 0 4 F r e e s c a l e S e m i c o n d u c t o r , I n c
2007-09-27 17:43:35 +04:00
* PowerPC e 5 0 0 m o d i f i c a t i o n s , K u m a r G a l a < g a l a k @kernel.crashing.org>
2005-09-26 10:04:21 +04:00
*
* 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 it
* under 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 a s p u b l i s h e d b y t h e
* Free S o f t w a r e F o u n d a t i o n ; either version 2 of the License, or (at your
* option) 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 < l i n u x / t h r e a d s . h >
# 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 >
2008-06-19 01:26:52 +04:00
# include < a s m / c a c h e . 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
# include " h e a d _ b o o k e . h "
/ * 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 =128 " )
* 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
*
* /
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
/ *
* Reserve a w o r d a t a f i x e d l o c a t i o n t o s t o r e t h e a d d r e s s
* of a b a t r o n _ p t e p t r s
* /
nop
2011-07-25 15:29:33 +04:00
/* Translate device tree address to physical, save in r30/r31 */
2013-12-24 11:12:04 +04:00
bl g e t _ p h y s _ a d d r
mr r30 ,r3
mr r31 ,r4
2011-07-25 15:29:33 +04:00
li r25 ,0 / * p h y s k e r n e l s t a r t ( l o w ) * /
li r24 ,0 / * C P U n u m b e r * /
li r23 ,0 / * p h y s k e r n e l s t a r t ( h i g h ) * /
2005-09-26 10:04:21 +04:00
2013-12-24 11:12:06 +04:00
# ifdef C O N F I G _ R E L O C A T A B L E
LOAD_ R E G _ A D D R _ P I C ( r3 , _ s t e x t ) / * G e t o u r c u r r e n t r u n t i m e b a s e * /
/* Translate _stext address to physical, save in r23/r25 */
bl g e t _ p h y s _ a d d r
mr r23 ,r3
mr r25 ,r4
2013-12-24 11:12:10 +04:00
bl 0 f
0 : mflr r8
addis r3 ,r8 ,( i s _ s e c o n d _ r e l o c - 0 b ) @ha
lwz r19 ,( i s _ s e c o n d _ r e l o c - 0 b ) @l(r3)
/* Check if this is the second relocation. */
cmpwi r19 ,1
bne 1 f
/ *
* For t h e s e c o n d r e l o c a t i o n , w e a l r e a d y g e t t h e r e a l m e m s t a r t _ a d d r
* from d e v i c e t r e e . S o w e w i l l m a p P A G E _ O F F S E T t o m e m s t a r t _ a d d r ,
* then t h e v i r t u a l a d d r e s s o f s t a r t k e r n e l s h o u l d b e :
* PAGE_ O F F S E T + ( k e r n s t a r t _ a d d r - m e m s t a r t _ a d d r )
* Since t h e o f f s e t b e t w e e n k e r n s t a r t _ a d d r a n d m e m s t a r t _ a d d r s h o u l d
* never b e b e y o n d 1 G , s o w e c a n j u s t u s e t h e l o w e r 3 2 b i t o f t h e m
* for t h e c a l c u l a t i o n .
* /
lis r3 ,P A G E _ O F F S E T @h
addis r4 ,r8 ,( k e r n s t a r t _ a d d r - 0 b ) @ha
addi r4 ,r4 ,( k e r n s t a r t _ a d d r - 0 b ) @l
lwz r5 ,4 ( r4 )
addis r6 ,r8 ,( m e m s t a r t _ a d d r - 0 b ) @ha
addi r6 ,r6 ,( m e m s t a r t _ a d d r - 0 b ) @l
lwz r7 ,4 ( r6 )
subf r5 ,r7 ,r5
add r3 ,r3 ,r5
b 2 f
1 :
2013-12-24 11:12:06 +04:00
/ *
* We h a v e t h e r u n t i m e ( v i r u t a l ) a d d r e s s o f o u r b a s e .
* We c a l c u l a t e o u r s h i f t o f o f f s e t f r o m a 6 4 M p a g e .
* We c o u l d m a p t h e 6 4 M p a g e w e b e l o n g t o a t P A G E _ O F F S E T a n d
* get g o i n g f r o m t h e r e .
* /
lis r4 ,K E R N E L B A S E @h
ori r4 ,r4 ,K E R N E L B A S E @l
rlwinm r6 ,r25 ,0 ,0 x3 f f f f f f / * r6 = P H Y S _ S T A R T % 6 4 M * /
rlwinm r5 ,r4 ,0 ,0 x3 f f f f f f / * r5 = K E R N E L B A S E % 6 4 M * /
subf r3 ,r5 ,r6 / * r3 = r6 - r5 * /
add r3 ,r4 ,r3 / * R e q u i r e d V i r t u a l A d d r e s s * /
2013-12-24 11:12:10 +04:00
2 : bl r e l o c a t e
/ *
* For t h e s e c o n d r e l o c a t i o n , w e a l r e a d y s e t t h e r i g h t t l b e n t r i e s
* for t h e k e r n e l s p a c e , s o s k i p t h e c o d e i n f s l _ b o o k e _ e n t r y _ m a p p i n g . S
* /
cmpwi r19 ,1
beq s e t _ i v o r
2013-12-24 11:12:06 +04:00
# endif
2005-09-26 10:04:21 +04:00
/ * We t r y t o n o t m a k e a n y a s s u m p t i o n s a b o u t h o w t h e b o o t l o a d e r
* setup o r u s e d t h e T L B s . W e i n v a l i d a t e a l l m a p p i n g s f r o m t h e
* boot l o a d e r a n d l o a d a s i n g l e e n t r y i n T L B 1 [ 0 ] t o m a p t h e
2007-11-22 18:46:20 +03:00
* first 6 4 M o f k e r n e l m e m o r y . A n y b o o t i n f o p a s s e d f r o m t h e
* bootloader n e e d s t o l i v e i n t h i s f i r s t 6 4 M .
2005-09-26 10:04:21 +04:00
*
* Requirement o n b o o t l o a d e r :
* - The p a g e w e ' r e e x e c u t i n g i n n e e d s t o r e s i d e i n T L B 1 a n d
* have I P R O T =1 . I f n o t a n i n v a l i d a t e b r o a d c a s t c o u l d
* evict t h e e n t r y w e ' r e c u r r e n t l y e x e c u t i n g i n .
*
* r3 = I n d e x o f T L B 1 w e r e e x e c u t i n g i n
* r4 = C u r r e n t M S R [ I S ]
* r5 = I n d e x o f T L B 1 t e m p m a p p i n g
*
* Later i n m a p i n _ r a m w e w i l l c o r r e c t l y m a p l o w m e m , a n d r e s i z e T L B 1 [ 0 ]
* if n e e d e d
* /
2008-11-19 18:35:56 +03:00
_ ENTRY( _ _ e a r l y _ s t a r t )
2009-01-08 17:31:20 +03:00
2010-04-05 00:19:03 +04:00
# define E N T R Y _ M A P P I N G _ B O O T _ S E T U P
2010-04-05 00:19:02 +04:00
# include " f s l _ b o o k e _ e n t r y _ m a p p i n g . S "
2010-04-05 00:19:03 +04:00
# undef E N T R Y _ M A P P I N G _ B O O T _ S E T U P
2005-09-26 10:04:21 +04:00
2013-12-24 11:12:10 +04:00
set_ivor :
2005-09-26 10:04:21 +04:00
/* Establish the interrupt vector offsets */
SET_ I V O R ( 0 , C r i t i c a l I n p u t ) ;
SET_ I V O R ( 1 , M a c h i n e C h e c k ) ;
SET_ I V O R ( 2 , D a t a S t o r a g e ) ;
SET_ I V O R ( 3 , I n s t r u c t i o n S t o r a g e ) ;
SET_ I V O R ( 4 , E x t e r n a l I n p u t ) ;
SET_ I V O R ( 5 , A l i g n m e n t ) ;
SET_ I V O R ( 6 , P r o g r a m ) ;
SET_ I V O R ( 7 , F l o a t i n g P o i n t U n a v a i l a b l e ) ;
SET_ I V O R ( 8 , S y s t e m C a l l ) ;
SET_ I V O R ( 9 , A u x i l l a r y P r o c e s s o r U n a v a i l a b l e ) ;
SET_ I V O R ( 1 0 , D e c r e m e n t e r ) ;
SET_ I V O R ( 1 1 , F i x e d I n t e r v a l T i m e r ) ;
SET_ I V O R ( 1 2 , W a t c h d o g T i m e r ) ;
SET_ I V O R ( 1 3 , D a t a T L B E r r o r ) ;
SET_ I V O R ( 1 4 , I n s t r u c t i o n T L B E r r o r ) ;
2008-04-09 15:06:11 +04:00
SET_ I V O R ( 1 5 , D e b u g C r i t ) ;
2005-09-26 10:04:21 +04:00
/* Establish the interrupt vector base */
lis r4 ,i n t e r r u p t _ b a s e @h /* IVPR only uses the high 16-bits */
mtspr S P R N _ I V P R ,r4
/* Setup the defaults for TLB entries */
2009-02-11 03:10:50 +03:00
li r2 ,( M A S 4 _ T S I Z E D ( B O O K 3 E _ P A G E S Z _ 4 K ) ) @l
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ E 2 0 0
oris r2 ,r2 ,M A S 4 _ T L B S E L D ( 1 ) @h
# endif
2007-09-27 17:43:35 +04:00
mtspr S P R N _ M A S 4 , r2
2005-09-26 10:04:21 +04:00
# if 0
/* Enable DOZE */
mfspr r2 ,S P R N _ H I D 0
oris r2 ,r2 ,H I D 0 _ D O Z E @h
mtspr S P R N _ H I D 0 , r2
# endif
# if ! d e f i n e d ( C O N F I G _ B D I _ S W I T C H )
/ *
* The A b a t r o n B D I J T A G d e b u g g e r d o e s n o t t o l e r a t e o t h e r s
* mucking w i t h t h e d e b u g r e g i s t e r s .
* /
lis r2 ,D B C R 0 _ I D M @h
mtspr S P R N _ D B C R 0 ,r2
2006-02-09 01:41:26 +03:00
isync
2005-09-26 10:04:21 +04:00
/* clear any residual debug events */
li r2 ,- 1
mtspr S P R N _ D B S R ,r2
# endif
2008-11-19 18:35:56 +03:00
# ifdef C O N F I G _ S M P
/ * Check t o s e e i f w e ' r e t h e s e c o n d p r o c e s s o r , a n d j u m p
* to t h e s e c o n d a r y _ s t a r t c o d e i f s o
* /
2013-12-24 11:12:11 +04:00
LOAD_ R E G _ A D D R _ P I C ( r24 , b o o t _ c p u i d )
2010-09-01 03:24:45 +04:00
lwz r24 , 0 ( r24 )
cmpwi r24 , - 1
mfspr r24 ,S P R N _ P I R
2008-11-19 18:35:56 +03:00
bne _ _ s e c o n d a r y _ s t a r t
# endif
2005-09-26 10:04:21 +04:00
/ *
* 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 .
* /
/* 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 current thread */
addi r4 ,r2 ,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 @h
ori 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 )
2012-07-05 08:41:35 +04:00
CURRENT_ T H R E A D _ I N F O ( r22 , r1 )
2010-09-01 03:24:45 +04:00
stw r24 , T I _ C P U ( r22 )
2005-09-26 10:04:21 +04:00
bl e a r l y _ i n i t
2013-12-24 11:12:06 +04:00
# ifdef C O N F I G _ R E L O C A T A B L E
2013-12-24 11:12:10 +04:00
mr r3 ,r30
mr r4 ,r31
2013-12-24 11:12:06 +04:00
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
2013-12-24 11:12:10 +04:00
mr r5 ,r23
mr r6 ,r25
2013-12-24 11:12:06 +04:00
# else
2013-12-24 11:12:10 +04:00
mr r5 ,r25
2013-12-24 11:12:06 +04:00
# endif
bl r e l o c a t e _ i n i t
# endif
2011-12-15 02:57:15 +04:00
# ifdef C O N F I G _ D Y N A M I C _ M E M S T A R T
2008-04-21 22:22:34 +04:00
lis r3 ,k e r n s t a r t _ a d d r @ha
la r3 ,k e r n s t a r t _ a d d r @l(r3)
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
stw r23 ,0 ( r3 )
stw r25 ,4 ( r3 )
# else
stw r25 ,0 ( r3 )
# endif
# endif
2005-09-26 10:04:21 +04:00
/ *
* 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
mr r3 ,r30
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
/* Setup PTE pointers for the Abatron bdiGDB */
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
lis r4 , K E R N E L B A S E @h
ori r4 , r4 , K E R N E L B A S E @l
stw r5 , 0 ( r4 ) / * S a v e a b a t r o n _ p t e p t r s a t a f i x e d l o c a t i o n * /
stw r6 , 0 ( r5 )
/* Let's move on */
lis r4 ,s t a r t _ k e r n e l @h
ori r4 ,r4 ,s t a r t _ k e r n e l @l
lis r3 ,M S R _ K E R N E L @h
ori r3 ,r3 ,M S R _ K E R N E L @l
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r3
rfi / * c h a n g e c o n t e x t a n d j u m p t o s t a r t _ k e r n e l * /
/ * Macros t o h i d e t h e P T E s i z e d i f f e r e n c e s
*
* FIND_ P T E - - w a l k s t h e p a g e t a b l e s g i v e n E A & p g d i r p o i n t e r
* r1 0 - - E A o f f a u l t
* r1 1 - - P G D I R p o i n t e r
* r1 2 - - f r e e
* label 2 : i s t h e b a i l o u t c a s e
*
* if w e f i n d t h e p t e ( f a l l t h r o u g h ) :
* r1 1 i s l o w p t e w o r d
* r1 2 i s p o i n t e r t o t h e p t e
2011-06-28 13:54:48 +04:00
* r1 0 i s t h e p s h i f t f r o m t h e P G D , i f w e ' r e a h u g e p a g e
2005-09-26 10:04:21 +04:00
* /
# ifdef C O N F I G _ P T E _ 6 4 B I T
2011-06-28 13:54:48 +04:00
# ifdef C O N F I G _ H U G E T L B _ P A G E
# define F I N D _ P T E \
rlwinm r12 , r10 , 1 3 , 1 9 , 2 9 ; /* Compute pgdir/pmd offset */ \
lwzx r11 , r12 , r11 ; /* Get pgd/pmd entry */ \
rlwinm. r12 , r11 , 0 , 0 , 2 0 ; /* Extract pt base address */ \
blt 1 0 0 0 f ; /* Normal non-huge page */ \
beq 2 f ; /* Bail if no table */ \
oris r11 , r11 , P D _ H U G E @h; /* Put back address bit */ \
andi. r10 , r11 , H U G E P D _ S H I F T _ M A S K @l; /* extract size field */ \
xor r12 , r10 , r11 ; /* drop size bits from pointer */ \
b 1 0 0 1 f ; \
1000 : rlwimi r12 , r10 , 2 3 , 2 0 , 2 8 ; /* Compute pte address */ \
li r10 , 0 ; /* clear r10 */ \
1001 : lwz r11 , 4 ( r12 ) ; /* Get pte entry */
# else
2005-09-26 10:04:21 +04:00
# define F I N D _ P T E \
2007-09-27 17:43:35 +04:00
rlwinm r12 , r10 , 1 3 , 1 9 , 2 9 ; /* Compute pgdir/pmd offset */ \
2005-09-26 10:04:21 +04:00
lwzx r11 , r12 , r11 ; /* Get pgd/pmd entry */ \
rlwinm. r12 , r11 , 0 , 0 , 2 0 ; /* Extract pt base address */ \
beq 2 f ; /* Bail if no table */ \
rlwimi r12 , r10 , 2 3 , 2 0 , 2 8 ; /* Compute pte address */ \
lwz r11 , 4 ( r12 ) ; /* Get pte entry */
2011-06-28 13:54:48 +04:00
# endif / * H U G E P A G E * /
# else / * ! P T E _ 6 4 B I T * /
2005-09-26 10:04:21 +04:00
# define F I N D _ P T E \
rlwimi r11 , r10 , 1 2 , 2 0 , 2 9 ; /* Create L1 (pgdir/pmd) address */ \
lwz r11 , 0 ( r11 ) ; /* Get L1 entry */ \
rlwinm. r12 , r11 , 0 , 0 , 1 9 ; /* Extract L2 (pte) base address */ \
beq 2 f ; /* Bail if no table */ \
rlwimi r12 , r10 , 2 2 , 2 0 , 2 9 ; /* Compute PTE address */ \
lwz r11 , 0 ( r12 ) ; /* Get Linux PTE */
# endif
/ *
* Interrupt v e c t o r e n t r y c o d e
*
* The B o o k E M M U s a r e a l w a y s o n s o w e d o n ' t n e e d t o h a n d l e
* interrupts i n r e a l m o d e a s w i t h p r e v i o u s P P C p r o c e s s o r s . I n
* this c a s e w e h a n d l e i n t e r r u p t s i n t h e k e r n e l v i r t u a l a d d r e s s
* space.
*
* Interrupt v e c t o r s a r e d y n a m i c a l l y p l a c e d r e l a t i v e t o t h e
* interrupt p r e f i x a s d e t e r m i n e d b y t h e a d d r e s s o f i n t e r r u p t _ b a s e .
* The i n t e r r u p t v e c t o r s o f f s e t s a r e p r o g r a m m e d u s i n g t h e l a b e l s
* for e a c h i n t e r r u p t v e c t o r e n t r y .
*
* Interrupt v e c t o r s m u s t b e a l i g n e d o n a 1 6 b y t e b o u n d a r y .
* We a l i g n o n a 3 2 b y t e c a c h e l i n e b o u n d a r y f o r g o o d m e a s u r e .
* /
interrupt_base :
/* Critical Input Interrupt */
2011-12-20 19:34:40 +04:00
CRITICAL_ E X C E P T I O N ( 0 x01 0 0 , C R I T I C A L , C r i t i c a l I n p u 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
/* Machine Check Interrupt */
# ifdef C O N F I G _ E 2 0 0
/* no RFMCI, MCSRRs on E200 */
2011-12-20 19:34:40 +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 , \
machine_ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
# else
2005-10-01 12:43:42 +04:00
MCHECK_ 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
# endif
/* Data Storage Interrupt */
START_ E X C E P T I O N ( D a t a S t o r a g e )
2011-12-20 19:34:40 +04:00
NORMAL_ E X C E P T I O N _ P R O L O G ( D A T A _ S T O R A G E )
2008-07-09 19:03:28 +04:00
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 * /
andis. r10 ,r5 ,( E S R _ I L K | E S R _ D L K ) @h
bne 1 f
2012-03-07 09:48:45 +04:00
EXC_ X F E R _ L I T E ( 0 x03 0 0 , h a n d l e _ p a g e _ f a u l t )
2008-07-09 19:03:28 +04:00
1 :
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 _ E E _ L I T E ( 0 x03 0 0 , C a c h e L o c k i n g E x c e p t i o n )
2005-09-26 10:04:21 +04:00
/* Instruction Storage Interrupt */
INSTRUCTION_ S T O R A G E _ E X C E P T I O N
/* External Input Interrupt */
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x05 0 0 , E X T E R N A L , E x t e r n a l I n p u t , d o _ I R Q , E X C _ X F E R _ L I T E )
2005-09-26 10:04:21 +04:00
/* Alignment Interrupt */
ALIGNMENT_ E X C E P T I O N
/* Program Interrupt */
PROGRAM_ E X C E P T I O N
/* Floating Point Unavailable Interrupt */
# ifdef C O N F I G _ P P C _ F P U
FP_ U N A V A I L A B L E _ E X C E P T I O N
# else
# ifdef C O N F I G _ E 2 0 0
/* E200 treats 'normal' floating point instructions as FP Unavail exception */
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x08 0 0 , F P _ U N A V A I L , F l o a t i n g P o i n t U n a v a i l a b l e , \
program_ c h e c k _ 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
# else
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x08 0 0 , F P _ U N A V A I L , F l o a t i n g P o i n t U n a v a i l a b l e , \
unknown_ 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
# endif
/* System Call Interrupt */
START_ E X C E P T I O N ( S y s t e m C a l l )
2011-12-20 19:34:40 +04:00
NORMAL_ E X C E P T I O N _ P R O L O G ( S Y S C A L L )
2005-09-26 10:04:21 +04:00
EXC_ X F E R _ E E _ L I T E ( 0 x0 c00 , D o S y s c a l l )
2011-03-31 05:57:33 +04:00
/* Auxiliary Processor Unavailable Interrupt */
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x29 0 0 , A P _ U N A V A I L , A u x i l l a r y P r o c e s s o r U n a v a i l a b l e , \
unknown_ 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
/* Decrementer Interrupt */
DECREMENTER_ E X C E P T I O N
/* Fixed Internal Timer Interrupt */
/* TODO: Add FIT support */
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x31 0 0 , F I T , F i x e d I n t e r v a l T i m e r , \
unknown_ 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
/* Watchdog Timer Interrupt */
# ifdef C O N F I G _ B O O K E _ W D T
2011-12-20 19:34:40 +04:00
CRITICAL_ E X C E P T I O N ( 0 x32 0 0 , W A T C H D O G , W a t c h d o g T i m e r , W a t c h d o g E x c e p t i o n )
2005-09-26 10:04:21 +04:00
# else
2011-12-20 19:34:40 +04:00
CRITICAL_ E X C E P T I O N ( 0 x32 0 0 , W A T C H D O G , W a t c h d o g T i m e r , 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
/* Data TLB Error Interrupt */
START_ E X C E P T I O N ( D a t a T L B E r r o r )
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ W 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 * /
2011-04-23 01:48:27 +04:00
mfspr r10 , S P R N _ S P R G _ T H R E A D
stw r11 , T H R E A D _ N O R M S A V E ( 0 ) ( r10 )
2011-12-20 19:34:47 +04:00
# ifdef C O N F I G _ K V M _ B O O K E _ H V
BEGIN_ F T R _ S E C T I O N
mfspr r11 , S P R N _ S R R 1
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ E M B _ H V )
# endif
2011-04-23 01:48:27 +04:00
stw r12 , T H R E A D _ N O R M S A V E ( 1 ) ( r10 )
stw r13 , T H R E A D _ N O R M S A V E ( 2 ) ( r10 )
mfcr r13
stw r13 , T H R E A D _ N O R M S A V E ( 3 ) ( r10 )
2011-12-20 19:34:47 +04:00
DO_ K V M B O O K E _ I N T E R R U P T _ D T L B _ M I S S S P R N _ S R R 1
2005-09-26 10:04:21 +04:00
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 5 , r10 , r11
blt 5 , 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
mfspr r12 ,S P R N _ M A S 1 / * S e t T I D t o 0 * /
rlwinm r12 ,r12 ,0 ,1 6 ,1
mtspr S P R N _ M A S 1 ,r12
b 4 f
/* Get the PGD for the current thread */
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 :
2008-07-09 19:03:28 +04:00
/ * Mask o f r e q u i r e d p e r m i s s i o n b i t s . N o t e t h a t w h i l e w e
* do c o p y E S R : S T t o _ P A G E _ R W p o s i t i o n a s t r y i n g t o w r i t e
* to a n R O p a g e i s p r e t t y c o m m o n , w e d o n ' t d o i t w i t h
* _ PAGE_ D I R T Y . W e c o u l d d o i t , b u t i t ' s a f a i r l y r a r e
* event s o I ' d r a t h e r t a k e t h e o v e r h e a d w h e n i t h a p p e n s
* rather t h a n a d d i n g a n i n s t r u c t i o n h e r e . W e s h o u l d m e a s u r e
* whether t h e w h o l e t h i n g i s w o r t h i t i n t h e f i r s t p l a c e
* as w e c o u l d a v o i d l o a d i n g S P R N _ E S R c o m p l e t e l y i n t h e f i r s t
* place. . .
*
* TODO : Is i t w o r t h d o i n g t h a t m f s p r & r l w i m i i n t h e f i r s t
* place o r c a n w e s a v e a c o u p l e o f i n s t r u c t i o n s h e r e ?
* /
mfspr r12 ,S P R N _ E S R
2009-09-01 19:48:42 +04:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
li r13 ,_ P A G E _ P R E S E N T
oris r13 ,r13 ,_ P A G E _ A C C E S S E D @h
# else
2008-07-09 19:03:28 +04:00
li r13 ,_ P A G E _ P R E S E N T | _ P A G E _ A C C E S S E D
2009-09-01 19:48:42 +04:00
# endif
2008-07-09 19:03:28 +04:00
rlwimi r13 ,r12 ,1 1 ,2 9 ,2 9
2005-09-26 10:04:21 +04:00
FIND_ P T E
2008-07-09 19:03:28 +04:00
andc. r13 ,r13 ,r11 / * C h e c k p e r m i s s i o n * /
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
2008-07-17 01:17:08 +04:00
# ifdef C O N F I G _ S M P
2011-06-28 13:54:48 +04:00
subf r13 ,r11 ,r12 / * c r e a t e f a l s e d a t a d e p * /
lwzx r13 ,r11 ,r13 / * G e t u p p e r p t e b i t s * /
2008-07-17 01:17:08 +04:00
# else
lwz r13 ,0 ( r12 ) / * G e t u p p e r p t e b i t s * /
# endif
2005-09-26 10:04:21 +04:00
# endif
2008-07-17 01:17:08 +04:00
bne 2 f / * B a i l i f p e r m i s s i o n / v a l i d m i s m a c h * /
/* Jump to common tlb load */
2005-09-26 10:04:21 +04:00
b f i n i s h _ t l b _ l o a d
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 .
* /
2011-04-23 01:48:27 +04:00
mfspr r10 , S P R N _ S P R G _ T H R E A D
lwz r11 , T H R E A D _ N O R M S A V E ( 3 ) ( r10 )
2005-09-26 10:04:21 +04:00
mtcr r11
2011-04-23 01:48:27 +04:00
lwz r13 , T H R E A D _ N O R M S A V E ( 2 ) ( r10 )
lwz r12 , T H R E A D _ N O R M S A V E ( 1 ) ( r10 )
lwz r11 , T H R E A D _ N O R M S A V E ( 0 ) ( r10 )
2009-07-15 00:52:54 +04:00
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
2008-07-09 19:03:28 +04:00
b D a t a S t o r a g e
2005-09-26 10:04:21 +04:00
/* Instruction TLB Error Interrupt */
/ *
* 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
* information f r o m d i f f e r e n t r e g i s t e r s a n d b a i l o u t
* to 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 ( I n s t r u c t i o n T L B E r r o r )
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ W 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 * /
2011-04-23 01:48:27 +04:00
mfspr r10 , S P R N _ S P R G _ T H R E A D
stw r11 , T H R E A D _ N O R M S A V E ( 0 ) ( r10 )
2011-12-20 19:34:47 +04:00
# ifdef C O N F I G _ K V M _ B O O K E _ H V
BEGIN_ F T R _ S E C T I O N
mfspr r11 , S P R N _ S R R 1
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ E M B _ H V )
# endif
2011-04-23 01:48:27 +04:00
stw r12 , T H R E A D _ N O R M S A V E ( 1 ) ( r10 )
stw r13 , T H R E A D _ N O R M S A V E ( 2 ) ( r10 )
mfcr r13
stw r13 , T H R E A D _ N O R M S A V E ( 3 ) ( r10 )
2011-12-20 19:34:47 +04:00
DO_ K V M B O O K E _ I N T E R R U P T _ I T L B _ M I S S S P R N _ S R R 1
2005-09-26 10:04:21 +04:00
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 5 , r10 , r11
blt 5 , 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
mfspr r12 ,S P R N _ M A S 1 / * S e t T I D t o 0 * /
rlwinm r12 ,r12 ,0 ,1 6 ,1
mtspr S P R N _ M A S 1 ,r12
2010-05-07 12:38:34 +04:00
/* Make up the required permissions for kernel code */
# ifdef C O N F I G _ P T E _ 6 4 B I T
li r13 ,_ P A G E _ P R E S E N T | _ P A G E _ B A P _ S X
oris r13 ,r13 ,_ P A G E _ A C C E S S E D @h
# else
li r13 ,_ P A G E _ P R E S E N T | _ P A G E _ A C C E S S E D | _ P A G E _ E X E C
# endif
2005-09-26 10:04:21 +04:00
b 4 f
/* Get the PGD for the current thread */
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 )
2010-05-07 12:38:34 +04:00
/* Make up the required permissions for user code */
2009-09-01 19:48:42 +04:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
2010-05-07 12:38:34 +04:00
li r13 ,_ P A G E _ P R E S E N T | _ P A G E _ B A P _ U X
2009-09-01 19:48:42 +04:00
oris r13 ,r13 ,_ P A G E _ A C C E S S E D @h
# else
2009-08-18 23:00:34 +04:00
li r13 ,_ P A G E _ P R E S E N T | _ P A G E _ A C C E S S E D | _ P A G E _ E X E C
2009-09-01 19:48:42 +04:00
# endif
2008-07-09 19:03:28 +04:00
2010-05-07 12:38:34 +04:00
4 :
2005-09-26 10:04:21 +04:00
FIND_ P T E
2008-07-09 19:03:28 +04:00
andc. r13 ,r13 ,r11 / * C h e c k p e r m i s s i o n * /
2008-07-17 01:17:08 +04:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
# ifdef C O N F I G _ S M P
2011-06-28 13:54:48 +04:00
subf r13 ,r11 ,r12 / * c r e a t e f a l s e d a t a d e p * /
lwzx r13 ,r11 ,r13 / * G e t u p p e r p t e b i t s * /
2008-07-17 01:17:08 +04:00
# else
lwz r13 ,0 ( r12 ) / * G e t u p p e r p t e b i t s * /
# endif
# endif
2008-07-09 19:03:28 +04:00
bne 2 f / * B a i l i f p e r m i s s i o n m i s m a c h * /
2005-09-26 10:04:21 +04:00
/* Jump to common TLB load point */
b f i n i s h _ t l b _ l o a d
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 .
* /
2011-04-23 01:48:27 +04:00
mfspr r10 , S P R N _ S P R G _ T H R E A D
lwz r11 , T H R E A D _ N O R M S A V E ( 3 ) ( r10 )
2005-09-26 10:04:21 +04:00
mtcr r11
2011-04-23 01:48:27 +04:00
lwz r13 , T H R E A D _ N O R M S A V E ( 2 ) ( r10 )
lwz r12 , T H R E A D _ N O R M S A V E ( 1 ) ( r10 )
lwz r11 , T H R E A D _ N O R M S A V E ( 0 ) ( r10 )
2009-07-15 00:52:54 +04:00
mfspr r10 , S P R N _ S P R G _ R 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 S t o r a g e
2014-08-20 17:09:03 +04:00
/* Define SPE handlers for e200 and e500v2 */
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ S P E
/* SPE Unavailable */
START_ E X C E P T I O N ( S P E U n a v a i l a b l e )
2014-08-20 17:09:04 +04:00
NORMAL_ E X C E P T I O N _ P R O L O G ( S P E _ U N A V A I L )
2012-03-01 05:20:19 +04:00
beq 1 f
bl l o a d _ u p _ s p e
b f a s t _ e x c e p t i o n _ r e t u r n
1 : addi r3 ,r1 ,S T A C K _ F R A M E _ O V E R H E A D
2005-09-26 10:04:21 +04:00
EXC_ X F E R _ E E _ L I T E ( 0 x20 1 0 , K e r n e l S P E )
2014-08-20 17:09:03 +04:00
# elif d e f i n e d ( C O N F I G _ S P E _ P O S S I B L E )
2014-08-20 17:09:04 +04:00
EXCEPTION( 0 x20 2 0 , S P E _ U N A V A I L , S P E U n a v a i l a b l e , \
2011-12-20 19:34:40 +04:00
unknown_ e x c e p t i o n , E X C _ X F E R _ E E )
2014-08-20 17:09:03 +04:00
# endif / * C O N F I G _ S P E _ P O S S I B L E * /
2005-09-26 10:04:21 +04:00
/* SPE Floating Point Data */
# ifdef C O N F I G _ S P E
2014-08-20 17:09:04 +04:00
EXCEPTION( 0 x20 3 0 , S P E _ F P _ D A T A , S P E F l o a t i n g P o i n t D a t a ,
2013-07-01 19:35:31 +04:00
SPEFloatingPointException, E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/* SPE Floating Point Round */
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x20 5 0 , S P E _ F P _ R O U N D , S P E F l o a t i n g P o i n t R o u n d , \
SPEFloatingPointRoundException, E X C _ X F E R _ E E )
2014-08-20 17:09:03 +04:00
# elif d e f i n e d ( C O N F I G _ S P E _ P O S S I B L E )
2014-08-20 17:09:04 +04:00
EXCEPTION( 0 x20 4 0 , S P E _ F P _ D A T A , S P E F l o a t i n g P o i n t D a t a ,
2011-12-20 19:34:40 +04:00
unknown_ e x c e p t i o n , E X C _ X F E R _ E E )
EXCEPTION( 0 x20 5 0 , S P E _ F P _ R O U N D , S P E F l o a t i n g P o i n t R o u n d , \
unknown_ e x c e p t i o n , E X C _ X F E R _ E E )
2014-08-20 17:09:03 +04:00
# endif / * C O N F I G _ S P E _ P O S S I B L E * /
2005-09-26 10:04:21 +04:00
/* Performance Monitor */
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x20 6 0 , P E R F O R M A N C E _ M O N I T O R , P e r f o r m a n c e M o n i t o r , \
performance_ m o n i t o r _ 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
2011-12-20 19:34:40 +04:00
EXCEPTION( 0 x20 7 0 , D O O R B E L L , D o o r b e l l , d o o r b e l l _ e x c e p t i o n , E X C _ X F E R _ S T D )
2009-02-12 16:54:53 +03:00
2011-12-20 19:34:40 +04:00
CRITICAL_ E X C E P T I O N ( 0 x20 8 0 , D O O R B E L L _ C R I T I C A L , \
CriticalDoorbell, u n k n o w n _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/* Debug Interrupt */
2008-04-09 15:06:11 +04:00
DEBUG_ D E B U G _ E X C E P T I O N
DEBUG_ C R I T _ E X C E P T I O N
2005-09-26 10:04:21 +04:00
2011-12-20 19:34:47 +04:00
GUEST_ D O O R B E L L _ E X C E P T I O N
CRITICAL_ E X C E P T I O N ( 0 , G U E S T _ D B E L L _ C R I T , C r i t i c a l G u e s t D o o r b e l l , \
unknown_ e x c e p t i o n )
/* Hypercall */
EXCEPTION( 0 , H V _ S Y S C A L L , H y p e r c a l l , 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 )
/* Embedded Hypervisor Privilege */
EXCEPTION( 0 , H V _ P R I V , E h v p r i v , 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 )
2013-04-30 02:18:11 +04:00
interrupt_end :
2005-09-26 10:04:21 +04:00
/ *
* Local f u n c t i o n s
* /
/ *
* Both t h e i n s t r u c t i o n a n d d a t a T L B m i s s g e t t o t h i s
* point t o l o a d t h e T L B .
2011-06-28 13:54:48 +04:00
* r1 0 - t s i z e e n c o d i n g ( i f H U G E T L B _ P A G E ) o r a v a i l a b l e t o u s e
2007-09-27 17:43:35 +04:00
* r1 1 - T L B ( i n f o f r o m L i n u x P T E )
2008-07-09 19:03:28 +04:00
* r1 2 - a v a i l a b l e t o u s e
* r1 3 - u p p e r b i t s o f P T E ( i f P T E _ 6 4 B I T ) o r a v a i l a b l e t o u s e
2007-10-11 22:36:52 +04:00
* CR5 - r e s u l t s o f a d d r > = P A G E _ O F F S E T
2005-09-26 10:04:21 +04:00
* MAS0 , M A S 1 - 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
* MAS2 , M A S 3 - w i l l n e e d a d d i t i o n a l i n f o f r o m L i n u x P T 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 .
* /
finish_tlb_load :
2011-06-28 13:54:48 +04:00
# ifdef C O N F I G _ H U G E T L B _ P A G E
cmpwi 6 , r10 , 0 / * c h e c k f o r h u g e p a g e * /
beq 6 , f i n i s h _ t l b _ l o a d _ c o n t / * ! h u g e * /
/* Alas, we need more scratch registers for hugepages */
mfspr r12 , S P R N _ S P R G _ T H R E A D
stw r14 , T H R E A D _ N O R M S A V E ( 4 ) ( r12 )
stw r15 , T H R E A D _ N O R M S A V E ( 5 ) ( r12 )
stw r16 , T H R E A D _ N O R M S A V E ( 6 ) ( r12 )
stw r17 , T H R E A D _ N O R M S A V E ( 7 ) ( r12 )
/* Get the next_tlbcam_idx percpu var */
# ifdef C O N F I G _ S M P
lwz r12 , T H R E A D _ I N F O - T H R E A D ( r12 )
lwz r15 , T I _ C P U ( r12 )
lis r14 , _ _ p e r _ c p u _ o f f s e t @h
ori r14 , r14 , _ _ p e r _ c p u _ o f f s e t @l
rlwinm r15 , r15 , 2 , 0 , 2 9
lwzx r16 , r14 , r15
# else
li r16 , 0
# endif
lis r17 , n e x t _ t l b c a m _ i d x @h
ori r17 , r17 , n e x t _ t l b c a m _ i d x @l
add r17 , r17 , r16 / * r17 = * n e x t _ t l b c a m _ i d x * /
lwz r15 , 0 ( r17 ) / * r15 = n e x t _ t l b c a m _ i d x * /
lis r14 , M A S 0 _ T L B S E L ( 1 ) @h /* select TLB1 (TLBCAM) */
rlwimi r14 , r15 , 1 6 , 4 , 1 5 / * n e x t _ t l b c a m _ i d x e n t r y * /
mtspr S P R N _ M A S 0 , r14
/* Extract TLB1CFG(NENTRY) */
mfspr r16 , S P R N _ T L B 1 C F G
andi. r16 , r16 , 0 x f f f
/* Update next_tlbcam_idx, wrapping when necessary */
addi r15 , r15 , 1
cmpw r15 , r16
blt 1 0 0 f
lis r14 , t l b c a m _ i n d e x @h
ori r14 , r14 , t l b c a m _ i n d e x @l
lwz r15 , 0 ( r14 )
100 : stw r15 , 0 ( r17 )
/ *
* Calc M A S 1 _ T S I Z E f r o m r10 ( w h i c h h a s p s h i f t e n c o d e d )
* tlb_ e n c = ( p s h i f t - 1 0 ) .
* /
subi r15 , r10 , 1 0
mfspr r16 , S P R N _ M A S 1
rlwimi r16 , r15 , 7 , 2 0 , 2 4
mtspr S P R N _ M A S 1 , r16
/* copy the pshift for use later */
mr r14 , r10
/* fall through */
# endif / * C O N F I G _ H U G E T L B _ P A G E * /
2005-09-26 10:04:21 +04:00
/ *
* 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 ) .
* 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 .
* /
2011-06-28 13:54:48 +04:00
finish_tlb_load_cont :
2009-09-01 19:48:42 +04:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
rlwinm r12 , r11 , 3 2 - 2 , 2 6 , 3 1 / * M o v e i n p e r m b i t s * /
andi. r10 , r11 , _ P A G E _ D I R T Y
bne 1 f
li r10 , M A S 3 _ S W | M A S 3 _ U W
andc r12 , r12 , r10
1 : rlwimi r12 , r13 , 2 0 , 0 , 1 1 / * g r a b R P N [ 3 2 : 4 3 ] * /
rlwimi r12 , r11 , 2 0 , 1 2 , 1 9 / * g r a b R P N [ 4 4 : 5 1 ] * /
2011-06-28 13:54:48 +04:00
2 : mtspr S P R N _ M A S 3 , r12
2009-09-01 19:48:42 +04:00
BEGIN_ M M U _ F T R _ S E C T I O N
srwi r10 , r13 , 1 2 / * g r a b R P N [ 1 2 : 3 1 ] * /
mtspr S P R N _ M A S 7 , r10
END_ M M U _ F T R _ S E C T I O N _ I F S E T ( M M U _ F T R _ B I G _ P H Y S )
# else
2009-08-18 23:00:34 +04:00
li r10 , ( _ P A G E _ E X E C | _ P A G E _ P R E S E N T )
2011-06-28 13:54:48 +04:00
mr r13 , r11
2008-07-09 19:03:28 +04:00
rlwimi r10 , r11 , 3 1 , 2 9 , 2 9 / * e x t r a c t _ P A G E _ D I R T Y i n t o S W * /
and r12 , r11 , r10
2005-09-26 10:04:21 +04:00
andi. r10 , r11 , _ P A G E _ U S E R / * T e s t f o r _ P A G E _ U S E R * /
2008-07-09 19:03:28 +04:00
slwi r10 , r12 , 1
or r10 , r10 , r12
iseleq r12 , r12 , r10
2011-06-28 13:54:48 +04:00
rlwimi r13 , r12 , 0 , 2 0 , 3 1 / * G e t R P N f r o m P T E , m e r g e w / p e r m s * /
mtspr S P R N _ M A S 3 , r13
2005-09-26 10:04:21 +04:00
# endif
2011-06-28 13:54:48 +04:00
mfspr r12 , S P R N _ M A S 2
# ifdef C O N F I G _ P T E _ 6 4 B I T
rlwimi r12 , r11 , 3 2 - 1 9 , 2 7 , 3 1 / * e x t r a c t W I M G E f r o m p t e * /
# else
rlwimi r12 , r11 , 2 6 , 2 7 , 3 1 / * e x t r a c t W I M G E f r o m p t e * /
# endif
# ifdef C O N F I G _ H U G E T L B _ P A G E
beq 6 , 3 f / * d o n ' t m a s k i f p a g e i s n ' t h u g e * /
li r13 , 1
slw r13 , r13 , r14
subi r13 , r13 , 1
rlwinm r13 , r13 , 0 , 0 , 1 9 / * b o t t o m b i t s u s e d f o r W I M G E / e t c * /
andc r12 , r12 , r13 / * m a s k o f f e a b i t s w i t h i n t h e p a g e * /
# endif
3 : mtspr S P R N _ M A S 2 , r12
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ E 2 0 0
/* Round robin TLB1 entries assignment */
mfspr r12 , S P R N _ M A S 0
/* Extract TLB1CFG(NENTRY) */
mfspr r11 , S P R N _ T L B 1 C F G
andi. r11 , r11 , 0 x f f f
/* Extract MAS0(NV) */
andi. r13 , r12 , 0 x f f f
addi r13 , r13 , 1
cmpw 0 , r13 , r11
addi r12 , r12 , 1
/* check if we need to wrap */
blt 7 f
/* wrap back to first free tlbcam entry */
lis r13 , t l b c a m _ i n d e x @ha
lwz r13 , t l b c a m _ i n d e x @l(r13)
rlwimi r12 , r13 , 0 , 2 0 , 3 1
7 :
2007-09-27 17:43:35 +04:00
mtspr S P R N _ M A S 0 ,r12
2005-09-26 10:04:21 +04:00
# endif / * C O N F I G _ E 2 0 0 * /
2011-06-28 13:54:48 +04:00
tlb_write_entry :
2005-09-26 10:04:21 +04:00
tlbwe
/* Done...restore registers and get out of here. */
2011-04-23 01:48:27 +04:00
mfspr r10 , S P R N _ S P R G _ T H R E A D
2011-06-28 13:54:48 +04:00
# ifdef C O N F I G _ H U G E T L B _ P A G E
beq 6 , 8 f / * s k i p r e s t o r e f o r 4 k p a g e f a u l t s * /
lwz r14 , T H R E A D _ N O R M S A V E ( 4 ) ( r10 )
lwz r15 , T H R E A D _ N O R M S A V E ( 5 ) ( r10 )
lwz r16 , T H R E A D _ N O R M S A V E ( 6 ) ( r10 )
lwz r17 , T H R E A D _ N O R M S A V E ( 7 ) ( r10 )
# endif
8 : lwz r11 , T H R E A D _ N O R M S A V E ( 3 ) ( r10 )
2005-09-26 10:04:21 +04:00
mtcr r11
2011-04-23 01:48:27 +04:00
lwz r13 , T H R E A D _ N O R M S A V E ( 2 ) ( r10 )
lwz r12 , T H R E A D _ N O R M S A V E ( 1 ) ( r10 )
lwz r11 , T H R E A D _ N O R M S A V E ( 0 ) ( r10 )
2009-07-15 00:52:54 +04:00
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
2005-09-26 10:04:21 +04:00
rfi / * F o r c e c o n t e x t c h a n g e * /
# ifdef C O N F I G _ S P E
/ * Note t h a t t h e S P E s u p p o r t i s c l o s e l y m o d e l e d a f t e r t h e A l t i V e c
* support. C h a n g e s t o o n e a r e l i k e l y t o b e a p p l i c a b l e t o t h e
* other! * /
2012-03-01 05:20:19 +04:00
_ GLOBAL( l o a d _ u p _ s p e )
2005-09-26 10:04:21 +04:00
/ *
* Disable S P E f o r t h e t a s k w h i c h h a d S P E p r e v i o u s l y ,
* and s a v e i t s S P E r e g i s t e r s i n i t s t h r e a d _ s t r u c t .
* Enables S P E f o r u s e i n t h e k e r n e l o n r e t u r n .
* On S M P w e k n o w t h e S P E u n i t s a r e f r e e , s i n c e w e g i v e i t u p e v e r y
* switch. - - K u m a r
* /
mfmsr r5
oris r5 ,r5 ,M S R _ S P E @h
mtmsr r5 / * e n a b l e u s e o f S P E n o w * /
isync
/ *
* For S M P , w e d o n ' t d o l a z y S P E s w i t c h i n g b e c a u s e i t j u s t g e t s t o o
* horrendously c o m p l e x , e s p e c i a l l y w h e n a t a s k s w i t c h e s f r o m o n e C P U
* to a n o t h e r . I n s t e a d w e c a l l g i v e u p _ s p e i n s w i t c h _ t o .
* /
# ifndef C O N F I G _ S M P
lis r3 ,l a s t _ t a s k _ u s e d _ s p e @ha
lwz r4 ,l a s t _ t a s k _ u s e d _ s p e @l(r3)
cmpi 0 ,r4 ,0
beq 1 f
addi r4 ,r4 ,T H R E A D / * w a n t T H R E A D o f l a s t _ t a s k _ u s e d _ s p e * /
2011-06-15 03:34:27 +04:00
SAVE_ 3 2 E V R S ( 0 ,r10 ,r4 ,T H R E A D _ E V R 0 )
2007-09-27 17:43:35 +04:00
evxor e v r10 , e v r10 , e v r10 / * c l e a r o u t e v r10 * /
2005-09-26 10:04:21 +04:00
evmwumiaa e v r10 , e v r10 , e v r10 / * e v r10 < - A C C = 0 * 0 + A C C * /
li r5 ,T H R E A D _ A C C
2007-09-27 17:43:35 +04:00
evstddx e v r10 , r4 , r5 / * s a v e o f f a c c u m u l a t o r * /
2005-09-26 10:04:21 +04:00
lwz r5 ,P T _ R E G S ( r4 )
lwz r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
lis r10 ,M S R _ S P E @h
andc r4 ,r4 ,r10 / * d i s a b l e S P E f o r p r e v i o u s t a s k * /
stw r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
1 :
2007-09-27 17:43:35 +04:00
# endif / * ! C O N F I G _ S M P * /
2005-09-26 10:04:21 +04:00
/* enable use of SPE after return */
oris r9 ,r9 ,M S R _ S P E @h
2009-07-15 00:52:54 +04:00
mfspr r5 ,S P R N _ S P R G _ T H R E A D / * c u r r e n t t a s k ' s T H R E A D ( p h y s ) * /
2005-09-26 10:04:21 +04:00
li r4 ,1
li r10 ,T H R E A D _ A C C
stw r4 ,T H R E A D _ U S E D _ S P E ( r5 )
evlddx e v r4 ,r10 ,r5
evmra e v r4 ,e v r4
2011-06-15 03:34:27 +04:00
REST_ 3 2 E V R S ( 0 ,r10 ,r5 ,T H R E A D _ E V R 0 )
2005-09-26 10:04:21 +04:00
# ifndef C O N F I G _ S M P
subi r4 ,r5 ,T H R E A D
stw r4 ,l a s t _ t a s k _ u s e d _ s p e @l(r3)
2007-09-27 17:43:35 +04:00
# endif / * ! C O N F I G _ S M P * /
2012-03-01 05:20:19 +04:00
blr
2005-09-26 10:04:21 +04:00
/ *
* SPE u n a v a i l a b l e t r a p f r o m k e r n e l - p r i n t a m e s s a g e , b u t l e t
* the t a s k u s e S P E i n t h e k e r n e l u n t i l i t r e t u r n s t o u s e r m o d e .
* /
KernelSPE :
lwz r3 ,_ M S R ( r1 )
oris r3 ,r3 ,M S R _ S P E @h
stw r3 ,_ M S R ( r1 ) / * e n a b l e u s e o f S P E a f t e r r e t u r n * /
2010-03-07 01:43:55 +03:00
# ifdef C O N F I G _ P R I N T K
2005-09-26 10:04:21 +04:00
lis r3 ,8 7 f @h
ori r3 ,r3 ,8 7 f @l
mr r4 ,r2 / * c u r r e n t * /
lwz r5 ,_ N I P ( r1 )
bl p r i n t k
2010-03-07 01:43:55 +03:00
# endif
2005-09-26 10:04:21 +04:00
b r e t _ f r o m _ e x c e p t
2010-03-07 01:43:55 +03:00
# ifdef C O N F I G _ P R I N T K
2005-09-26 10:04:21 +04:00
87 : .string " SPE used in kernel (task=%p, pc=%x) \n "
2010-03-07 01:43:55 +03:00
# endif
2005-09-26 10:04:21 +04:00
.align 4 , 0
# endif / * C O N F I G _ S P E * /
2013-12-24 11:12:04 +04:00
/ *
* Translate t h e e f f e c a d d r i n r3 t o p h y s a d d r . T h e p h y s a d d r w i l l b e p u t
* into r3 ( h i g h e r 3 2 b i t ) a n d r4 ( l o w e r 3 2 b i t )
* /
get_phys_addr :
mfmsr r8
mfspr r9 ,S P R N _ P I D
rlwinm r9 ,r9 ,1 6 ,0 x3 f f f00 0 0 / * t u r n P I D i n t o M A S 6 [ S P I D ] * /
rlwimi r9 ,r8 ,2 8 ,0 x00 0 0 0 0 0 1 / * t u r n M S R [ D S ] i n t o M A S 6 [ S A S ] * /
mtspr S P R N _ M A S 6 ,r9
tlbsx 0 ,r3 / * m u s t s u c c e e d * /
mfspr r8 ,S P R N _ M A S 1
mfspr r12 ,S P R N _ M A S 3
rlwinm r9 ,r8 ,2 5 ,0 x1 f / * r9 = l o g 2 ( p a g e s i z e ) * /
li r10 ,1 0 2 4
slw r10 ,r10 ,r9 / * r10 = p a g e s i z e * /
addi r10 ,r10 ,- 1
and r11 ,r3 ,r10 / * r11 = p a g e o f f s e t * /
andc r4 ,r12 ,r10 / * r4 = p a g e b a s e * /
or r4 ,r4 ,r11 / * r4 = d e v t r e e p h y s a d d r * /
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
mfspr r3 ,S P R N _ M A S 7
# endif
blr
2005-09-26 10:04:21 +04:00
/ *
* Global f u n c t i o n s
* /
2014-08-20 17:09:03 +04:00
# ifdef C O N F I G _ E 2 0 0
2009-01-08 17:31:20 +03:00
/* Adjust or setup IVORs for e200 */
_ GLOBAL( _ _ s e t u p _ e 2 0 0 _ i v o r s )
li r3 ,D e b u g D e b u g @l
mtspr S P R N _ I V O R 1 5 ,r3
li r3 ,S P E U n a v a i l a b l e @l
mtspr S P R N _ I V O R 3 2 ,r3
li r3 ,S P E F l o a t i n g P o i n t D a t a @l
mtspr S P R N _ I V O R 3 3 ,r3
li r3 ,S P E F l o a t i n g P o i n t R o u n d @l
mtspr S P R N _ I V O R 3 4 ,r3
sync
blr
2014-08-20 17:09:03 +04:00
# endif
2009-01-08 17:31:20 +03:00
2014-08-20 17:09:03 +04:00
# ifdef C O N F I G _ E 5 0 0
# ifndef C O N F I G _ P P C _ E 5 0 0 M C
2009-01-08 17:31:20 +03:00
/* Adjust or setup IVORs for e500v1/v2 */
_ GLOBAL( _ _ s e t u p _ e 5 0 0 _ i v o r s )
li r3 ,D e b u g C r i t @l
mtspr S P R N _ I V O R 1 5 ,r3
li r3 ,S P E U n a v a i l a b l e @l
mtspr S P R N _ I V O R 3 2 ,r3
li r3 ,S P E F l o a t i n g P o i n t D a t a @l
mtspr S P R N _ I V O R 3 3 ,r3
li r3 ,S P E F l o a t i n g P o i n t R o u n d @l
mtspr S P R N _ I V O R 3 4 ,r3
li r3 ,P e r f o r m a n c e M o n i t o r @l
mtspr S P R N _ I V O R 3 5 ,r3
sync
blr
2014-08-20 17:09:03 +04:00
# else
2009-01-08 17:31:20 +03:00
/* Adjust or setup IVORs for e500mc */
_ GLOBAL( _ _ s e t u p _ e 5 0 0 m c _ i v o r s )
li r3 ,D e b u g D e b u g @l
mtspr S P R N _ I V O R 1 5 ,r3
li r3 ,P e r f o r m a n c e M o n i t o r @l
mtspr S P R N _ I V O R 3 5 ,r3
li r3 ,D o o r b e l l @l
mtspr S P R N _ I V O R 3 6 ,r3
2009-02-12 16:54:53 +03:00
li r3 ,C r i t i c a l D o o r b e l l @l
mtspr S P R N _ I V O R 3 7 ,r3
2012-07-09 16:55:31 +04:00
sync
blr
2011-12-20 19:34:47 +04:00
2012-07-09 16:55:31 +04:00
/* setup ehv ivors for */
_ GLOBAL( _ _ s e t u p _ e h v _ i v o r s )
2011-12-20 19:34:47 +04:00
li r3 ,G u e s t D o o r b e l l @l
mtspr S P R N _ I V O R 3 8 ,r3
li r3 ,C r i t i c a l G u e s t D o o r b e l l @l
mtspr S P R N _ I V O R 3 9 ,r3
li r3 ,H y p e r c a l l @l
mtspr S P R N _ I V O R 4 0 ,r3
li r3 ,E h v p r i v @l
mtspr S P R N _ I V O R 4 1 ,r3
2009-01-08 17:31:20 +03:00
sync
blr
2014-08-20 17:09:03 +04:00
# endif / * C O N F I G _ P P C _ E 5 0 0 M C * /
# endif / * C O N F I G _ E 5 0 0 * /
2009-01-08 17:31:20 +03:00
2005-09-26 10:04:21 +04:00
# ifdef C O N F I G _ S P E
/ *
* extern v o i d g i v e u p _ s p e ( s t r u c t t a s k _ s t r u c t * p r e v )
*
* /
_ GLOBAL( g i v e u p _ s p e )
mfmsr r5
oris r5 ,r5 ,M S R _ S P E @h
mtmsr r5 / * e n a b l e u s e o f S P E n o w * /
isync
cmpi 0 ,r3 ,0
beqlr- / * i f n o p r e v i o u s o w n e r , d o n e * /
addi r3 ,r3 ,T H R E A D / * w a n t T H R E A D o f t a s k * /
lwz r5 ,P T _ R E G S ( r3 )
cmpi 0 ,r5 ,0
2011-06-15 03:34:27 +04:00
SAVE_ 3 2 E V R S ( 0 , r4 , r3 , T H R E A D _ E V R 0 )
2007-09-27 17:43:35 +04:00
evxor e v r6 , e v r6 , e v r6 / * c l e a r o u t e v r6 * /
2005-09-26 10:04:21 +04:00
evmwumiaa e v r6 , e v r6 , e v r6 / * e v r6 < - A C C = 0 * 0 + A C C * /
li r4 ,T H R E A D _ A C C
2007-09-27 17:43:35 +04:00
evstddx e v r6 , r4 , r3 / * s a v e o f f a c c u m u l a t o r * /
2005-09-26 10:04:21 +04:00
beq 1 f
lwz r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
lis r3 ,M S R _ S P E @h
andc r4 ,r4 ,r3 / * d i s a b l e S P E f o r p r e v i o u s t a s k * /
stw r4 ,_ M S R - S T A C K _ F R A M E _ O V E R H E A D ( r5 )
1 :
# ifndef C O N F I G _ S M P
li r5 ,0
lis r4 ,l a s t _ t a s k _ u s e d _ s p e @ha
stw r5 ,l a s t _ t a s k _ u s e d _ s p e @l(r4)
2007-09-27 17:43:35 +04:00
# endif / * ! C O N F I G _ S M P * /
2005-09-26 10:04:21 +04:00
blr
# endif / * C O N F I G _ S P E * /
/ *
* extern v o i d a b o r t ( v o i d )
*
* At p r e s e n t , t h i s r o u t i n e j u s t a p p l i e s a s y s t e m r e s e t .
* /
_ GLOBAL( a b o r t )
li r13 ,0
2007-09-27 17:43:35 +04:00
mtspr S P R N _ D B C R 0 ,r13 / * d i s a b l e a l l d e b u g e v e n t s * /
2006-02-09 01:41:26 +03:00
isync
2005-09-26 10:04:21 +04:00
mfmsr r13
ori r13 ,r13 ,M S R _ D E @l /* Enable Debug Events */
mtmsr r13
2006-02-09 01:41:26 +03:00
isync
2007-09-27 17:43:35 +04:00
mfspr r13 ,S P R N _ D B C R 0
lis r13 ,( D B C R 0 _ I D M | D B C R 0 _ R S T _ C H I P ) @h
mtspr S P R N _ D B C R 0 ,r13
2006-02-09 01:41:26 +03:00
isync
2005-09-26 10:04:21 +04:00
_ 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 , 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 r4 , 0 x4 ( r5 )
# endif
mtspr S P R N _ P I D ,r3
isync / * F o r c e c o n t e x t c h a n g e * /
blr
2008-06-19 01:26:52 +04:00
_ GLOBAL( f l u s h _ d c a c h e _ L 1 )
mfspr r3 ,S P R N _ L 1 C F G 0
rlwinm r5 ,r3 ,9 ,3 / * E x t r a c t c a c h e b l o c k s i z e * /
twlgti r5 ,1 / * O n l y 3 2 a n d 6 4 b y t e c a c h e b l o c k s
* are c u r r e n t l y d e f i n e d .
* /
li r4 ,3 2
subfic r6 ,r5 ,2 / * r6 = l o g 2 ( 1 K i B / c a c h e b l o c k s i z e ) -
* log2 ( n u m b e r o f w a y s )
* /
slw r5 ,r4 ,r5 / * r5 = c a c h e b l o c k s i z e * /
rlwinm r7 ,r3 ,0 ,0 x f f / * E x t r a c t n u m b e r o f K i B i n t h e c a c h e * /
mulli r7 ,r7 ,1 3 / * A n 8 - w a y c a c h e w i l l r e q u i r e 1 3
* loads p e r s e t .
* /
slw r7 ,r7 ,r6
/* save off HID0 and set DCFA */
mfspr r8 ,S P R N _ H I D 0
ori r9 ,r8 ,H I D 0 _ D C F A @l
mtspr S P R N _ H I D 0 ,r9
isync
lis r4 ,K E R N E L B A S E @h
mtctr r7
1 : lwz r3 ,0 ( r4 ) / * L o a d . . . * /
add r4 ,r4 ,r5
bdnz 1 b
msync
lis r4 ,K E R N E L B A S E @h
mtctr r7
1 : dcbf 0 ,r4 / * . . . a n d f l u s h . * /
add r4 ,r4 ,r5
bdnz 1 b
/* restore HID0 */
mtspr S P R N _ H I D 0 ,r8
isync
blr
2012-07-20 16:42:36 +04:00
/* Flush L1 d-cache, invalidate and disable d-cache and i-cache */
_ GLOBAL( _ _ f l u s h _ d i s a b l e _ L 1 )
mflr r10
bl f l u s h _ d c a c h e _ L 1 / * F l u s h L 1 d - c a c h e * /
mtlr r10
mfspr r4 , S P R N _ L 1 C S R 0 / * I n v a l i d a t e a n d d i s a b l e d - c a c h e * /
li r5 , 2
rlwimi r4 , r5 , 0 , 3
msync
isync
mtspr S P R N _ L 1 C S R 0 , r4
isync
1 : mfspr r4 , S P R N _ L 1 C S R 0 / * W a i t f o r t h e i n v a l i d a t e t o f i n i s h * /
andi. r4 , r4 , 2
bne 1 b
mfspr r4 , S P R N _ L 1 C S R 1 / * I n v a l i d a t e a n d d i s a b l e i - c a c h e * /
li r5 , 2
rlwimi r4 , r5 , 0 , 3
mtspr S P R N _ L 1 C S R 1 , r4
isync
blr
2008-11-19 18:35:56 +03:00
# ifdef C O N F I G _ S M P
/* When we get here, r24 needs to hold the CPU # */
.globl __secondary_start
__secondary_start :
2013-12-24 11:12:11 +04:00
LOAD_ R E G _ A D D R _ P I C ( r3 , t l b c a m _ i n d e x )
lwz r3 ,0 ( r3 )
2008-11-19 18:35:56 +03:00
mtctr r3
li r26 ,0 / * r26 s a f e ? * /
2013-12-24 11:12:11 +04:00
bl s w i t c h _ t o _ a s1
mr r27 ,r3 / * t l b e n t r y * /
2008-11-19 18:35:56 +03:00
/* Load each CAM entry */
1 : mr r3 ,r26
bl l o a d c a m _ e n t r y
addi r26 ,r26 ,1
bdnz 1 b
2013-12-24 11:12:11 +04:00
mr r3 ,r27 / * t l b e n t r y * /
LOAD_ R E G _ A D D R _ P I C ( r4 , m e m s t a r t _ a d d r )
lwz r4 ,0 ( r4 )
mr r5 ,r25 / * p h y s k e r n e l s t a r t * /
rlwinm r5 ,r5 ,0 ,~ 0 x3 f f f f f f / * a l i g n e d 6 4 M * /
subf r4 ,r5 ,r4 / * m e m s t a r t _ a d d r - p h y s k e r n e l s t a r t * /
li r5 ,0 / * n o d e v i c e t r e e * /
li r6 ,0 / * n o t b o o t c p u * /
bl r e s t o r e _ t o _ a s0
lis r3 ,_ _ s e c o n d a r y _ h o l d _ a c k n o w l e d g e @h
ori r3 ,r3 ,_ _ s e c o n d a r y _ h o l d _ a c k n o w l e d g e @l
stw r24 ,0 ( r3 )
li r3 ,0
mr r4 ,r24 / * W h y ? * /
bl c a l l _ s e t u p _ c p u
2008-11-19 18:35:56 +03:00
/* get current_thread_info and current */
lis r1 ,s e c o n d a r y _ t i @ha
lwz r1 ,s e c o n d a r y _ t i @l(r1)
lwz r2 ,T I _ T A S K ( r1 )
/* stack */
addi r1 ,r1 ,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
li r0 ,0
stw r0 ,0 ( r1 )
/* ptr to current thread */
addi r4 ,r2 ,T H R E A D / * a d d r e s s o f o u r t h r e a d _ s t r u c t * /
2009-07-15 00:52:54 +04:00
mtspr S P R N _ S P R G _ T H R E A D ,r4
2008-11-19 18:35:56 +03:00
/* Setup the defaults for TLB entries */
2009-02-11 03:10:50 +03:00
li r4 ,( M A S 4 _ T S I Z E D ( B O O K 3 E _ P A G E S Z _ 4 K ) ) @l
2008-11-19 18:35:56 +03:00
mtspr S P R N _ M A S 4 ,r4
/* Jump to start_secondary */
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 _ s e c o n d a r y @h
ori r3 ,r3 ,s t a r t _ s e c o n d a r y @l
mtspr S P R N _ S R R 0 ,r3
mtspr S P R N _ S R R 1 ,r4
sync
rfi
sync
.globl __secondary_hold_acknowledge
__secondary_hold_acknowledge :
.long - 1
# endif
2013-12-24 11:12:07 +04:00
/ *
* Create a t l b e n t r y w i t h t h e s a m e e f f e c t i v e a n d p h y s i c a l a d d r e s s a s
* the t l b e n t r y u s e d b y t h e c u r r e n t r u n n i n g c o d e . B u t s e t t h e T S t o 1 .
* Then s w i t c h t o t h e a d d r e s s s p a c e 1 . I t w i l l r e t u r n w i t h t h e r3 s e t t o
* the E S E L o f t h e n e w c r e a t e d t l b .
* /
_ GLOBAL( s w i t c h _ t o _ a s1 )
mflr r5
/* Find a entry not used */
mfspr r3 ,S P R N _ T L B 1 C F G
andi. r3 ,r3 ,0 x f f f
mfspr r4 ,S P R N _ P I D
rlwinm r4 ,r4 ,1 6 ,0 x3 f f f00 0 0 / * t u r n P I D i n t o M A S 6 [ S P I D ] * /
mtspr S P R N _ M A S 6 ,r4
1 : lis r4 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
addi r3 ,r3 ,- 1
rlwimi r4 ,r3 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r3 ) * /
mtspr S P R N _ M A S 0 ,r4
tlbre
mfspr r4 ,S P R N _ M A S 1
andis. r4 ,r4 ,M A S 1 _ V A L I D @h
bne 1 b
/* Get the tlb entry used by the current running code */
bl 0 f
0 : mflr r4
tlbsx 0 ,r4
mfspr r4 ,S P R N _ M A S 1
ori r4 ,r4 ,M A S 1 _ T S / * S e t t h e T S = 1 * /
mtspr S P R N _ M A S 1 ,r4
mfspr r4 ,S P R N _ M A S 0
rlwinm r4 ,r4 ,0 ,~ M A S 0 _ E S E L _ M A S K
rlwimi r4 ,r3 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r3 ) * /
mtspr S P R N _ M A S 0 ,r4
tlbwe
isync
sync
mfmsr r4
ori r4 ,r4 ,M S R _ I S | M S R _ D S
mtspr S P R N _ S R R 0 ,r5
mtspr S P R N _ S R R 1 ,r4
sync
rfi
/ *
* Restore t o t h e a d d r e s s s p a c e 0 a n d a l s o i n v a l i d a t e t h e t l b e n t r y c r e a t e d
* by s w i t c h _ t o _ a s1 .
2013-12-24 11:12:10 +04:00
* r3 - t h e t l b e n t r y w h i c h s h o u l d b e i n v a l i d a t e d
* r4 - _ _ p a ( P A G E _ O F F S E T i n A S 1 ) - _ _ p a ( P A G E _ O F F S E T i n A S 0 )
* r5 - d e v i c e t r e e v i r t u a l a d d r e s s . I f r4 i s 0 , r5 i s i g n o r e d .
2013-12-24 11:12:11 +04:00
* r6 - b o o t c p u
2013-12-24 11:12:07 +04:00
* /
_ GLOBAL( r e s t o r e _ t o _ a s0 )
mflr r0
bl 0 f
0 : mflr r9
addi r9 ,r9 ,1 f - 0 b
2013-12-24 11:12:10 +04:00
/ *
* We m a y m a p t h e P A G E _ O F F S E T i n A S 0 t o a d i f f e r e n t p h y s i c a l a d d r e s s ,
* so w e n e e d c a l c u l a t e t h e r i g h t j u m p a n d d e v i c e t r e e a d d r e s s b a s e d
* on t h e o f f s e t p a s s e d b y r4 .
* /
add r9 ,r9 ,r4
add r5 ,r5 ,r4
2013-12-24 11:12:11 +04:00
add r0 ,r0 ,r4
2013-12-24 11:12:10 +04:00
2 : mfmsr r7
2013-12-24 11:12:07 +04:00
li r8 ,( M S R _ I S | M S R _ D S )
andc r7 ,r7 ,r8
mtspr S P R N _ S R R 0 ,r9
mtspr S P R N _ S R R 1 ,r7
sync
rfi
/* Invalidate the temporary tlb entry for AS1 */
1 : lis r9 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r9 ,r3 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r3 ) * /
mtspr S P R N _ M A S 0 ,r9
tlbre
mfspr r9 ,S P R N _ M A S 1
rlwinm r9 ,r9 ,0 ,2 ,3 1 / * C l e a r M A S 1 V a l i d a n d I P P R O T * /
mtspr S P R N _ M A S 1 ,r9
tlbwe
isync
2013-12-24 11:12:10 +04:00
cmpwi r4 ,0
2013-12-24 11:12:11 +04:00
cmpwi c r1 ,r6 ,0
cror e q ,4 * c r1 + e q ,e q
bne 3 f / * o f f s e t ! = 0 & & i s _ b o o t _ c p u * /
2013-12-24 11:12:07 +04:00
mtlr r0
blr
2013-12-24 11:12:10 +04:00
/ *
* The P A G E _ O F F S E T w i l l m a p t o a d i f f e r e n t p h y s i c a l a d d r e s s ,
* jump t o _ s t a r t t o d o a n o t h e r r e l o c a t i o n a g a i n .
* /
3 : mr r3 ,r5
bl _ s t a r t
2005-09-26 10:04:21 +04:00
/ *
* 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