2019-05-27 08:55:01 +02:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2005-09-26 16:04:21 +10: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 08:43:35 -05:00
* Initial P o w e r P C v e r s i o n .
2005-09-26 16:04:21 +10: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 08:43:35 -05:00
* Rewritten f o r P R e P
2005-09-26 16:04:21 +10: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 08:43:35 -05: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 16:04:21 +10: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 08:43:35 -05:00
* PowerPC 8 x x m o d i f i c a t i o n s .
2005-09-26 16:04:21 +10:00
* Copyright ( c ) 1 9 9 8 - 1 9 9 9 T i V o , I n c .
2007-09-27 08:43:35 -05:00
* PowerPC 4 0 3 G C X m o d i f i c a t i o n s .
2005-09-26 16:04:21 +10: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 08:43:35 -05: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 16:04:21 +10: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 08:43:35 -05: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 16:04:21 +10: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 08:43:35 -05: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 16:04:21 +10: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 08:43:35 -05: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 16:04:21 +10:00
* /
2009-04-25 22:11:05 -04:00
# include < l i n u x / i n i t . h >
2005-09-26 16:04:21 +10:00
# include < l i n u x / t h r e a d s . h >
2020-06-08 21:32:42 -07:00
# include < l i n u x / p g t a b l e . h >
2022-11-14 23:27:44 +05:30
# include < l i n u x / l i n k a g e . h >
2005-09-26 16:04:21 +10: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 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-18 16:26:52 -05:00
# include < a s m / c a c h e . h >
2010-11-18 15:06:17 +00:00
# include < a s m / p t r a c e . h >
2016-01-13 23:33:46 -05:00
# include < a s m / e x p o r t . h >
2018-07-05 16:25:01 +00:00
# include < a s m / f e a t u r e - f i x u p s . h >
2005-09-26 16:04:21 +10: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-25 22:11:05 -04:00
_ _ HEAD
2021-11-30 13:04:50 +01:00
_ GLOBAL( _ s t e x t ) ;
_ GLOBAL( _ s t a r t ) ;
2005-09-26 16:04:21 +10: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 11:29:33 +00:00
/* Translate device tree address to physical, save in r30/r31 */
2013-12-24 15:12:04 +08:00
bl g e t _ p h y s _ a d d r
mr r30 ,r3
mr r31 ,r4
2011-07-25 11:29:33 +00: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 16:04:21 +10:00
2013-12-24 15:12:06 +08: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
2021-08-24 07:56:26 +00:00
bcl 2 0 ,3 1 ,$ + 4
2013-12-24 15:12:10 +08:00
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 15:12:06 +08:00
/ *
2021-03-15 03:34:36 +05:30
* We h a v e t h e r u n t i m e ( v i r t u a l ) a d d r e s s o f o u r b a s e .
2013-12-24 15:12:06 +08:00
* 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 15:12:10 +08: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
2022-09-19 19:01:31 +02:00
* 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 8 5 x x _ e n t r y _ m a p p i n g . S
2013-12-24 15:12:10 +08:00
* /
cmpwi r19 ,1
beq s e t _ i v o r
2013-12-24 15:12:06 +08:00
# endif
2005-09-26 16:04:21 +10: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 08:46:20 -07: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 16:04:21 +10: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
* /
2021-11-30 13:04:50 +01:00
_ GLOBAL( _ _ e a r l y _ s t a r t )
2019-09-20 17:45:40 +08:00
LOAD_ R E G _ A D D R _ P I C ( r20 , k e r n s t a r t _ v i r t _ a d d r )
lwz r20 ,0 ( r20 )
2009-01-08 08:31:20 -06:00
2010-04-04 22:19:03 +02:00
# define E N T R Y _ M A P P I N G _ B O O T _ S E T U P
2022-09-19 19:01:31 +02:00
# include " 8 5 x x _ e n t r y _ m a p p i n g . S "
2010-04-04 22:19:03 +02: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 16:04:21 +10:00
2013-12-24 15:12:10 +08:00
set_ivor :
2005-09-26 16:04:21 +10: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 06:06:11 -05:00
SET_ I V O R ( 1 5 , D e b u g C r i t ) ;
2005-09-26 16:04:21 +10: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-10 18:10:50 -06: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
2007-09-27 08:43:35 -05:00
mtspr S P R N _ M A S 4 , r2
2005-09-26 16:04:21 +10:00
# 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-08 16:41:26 -06:00
isync
2005-09-26 16:04:21 +10:00
/* clear any residual debug events */
li r2 ,- 1
mtspr S P R N _ D B S R ,r2
# endif
2008-11-19 09:35:56 -06: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 15:12:11 +08:00
LOAD_ R E G _ A D D R _ P I C ( r24 , b o o t _ c p u i d )
2010-08-31 18:24:45 -05:00
lwz r24 , 0 ( r24 )
cmpwi r24 , - 1
mfspr r24 ,S P R N _ P I R
2008-11-19 09:35:56 -06:00
bne _ _ s e c o n d a r y _ s t a r t
# endif
2005-09-26 16:04:21 +10: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-14 20:52:54 +00:00
mtspr S P R N _ S P R G _ T H R E A D ,r4
2005-09-26 16:04:21 +10: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
2022-11-27 22:49:40 +10:00
stwu r0 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ M I N _ S I Z E ( r1 )
2005-09-26 16:04:21 +10:00
2019-01-31 10:08:50 +00:00
# ifdef C O N F I G _ S M P
2019-01-31 10:09:04 +00:00
stw r24 , T A S K _ C P U ( r2 )
2019-01-31 10:08:50 +00:00
# endif
2010-08-31 18:24:45 -05:00
2005-09-26 16:04:21 +10:00
bl e a r l y _ i n i t
2019-11-29 14:26:41 +00:00
# ifdef C O N F I G _ K A S A N
bl k a s a n _ e a r l y _ i n i t
# endif
2013-12-24 15:12:06 +08:00
# ifdef C O N F I G _ R E L O C A T A B L E
2013-12-24 15:12:10 +08:00
mr r3 ,r30
mr r4 ,r31
2013-12-24 15:12:06 +08:00
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
2013-12-24 15:12:10 +08:00
mr r5 ,r23
mr r6 ,r25
2013-12-24 15:12:06 +08:00
# else
2013-12-24 15:12:10 +08:00
mr r5 ,r25
2013-12-24 15:12:06 +08:00
# endif
bl r e l o c a t e _ i n i t
# endif
2011-12-14 22:57:15 +00: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-22 04:22:34 +10: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 16:04:21 +10: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 11:29:33 +00:00
mr r3 ,r30
mr r4 ,r31
2005-09-26 16:04:21 +10: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
2019-09-20 17:45:40 +08:00
lis r3 , k e r n s t a r t _ v i r t _ a d d r @ha
lwz r4 , k e r n s t a r t _ v i r t _ a d d r @l(r3)
2005-09-26 16:04:21 +10:00
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 09:54:48 +00: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 16:04:21 +10:00
* /
# ifdef C O N F I G _ P T E _ 6 4 B I T
2011-06-28 09:54:48 +00: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 16:04:21 +10:00
# define F I N D _ P T E \
2007-09-27 08:43:35 -05:00
rlwinm r12 , r10 , 1 3 , 1 9 , 2 9 ; /* Compute pgdir/pmd offset */ \
2005-09-26 16:04:21 +10: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 09:54:48 +00:00
# endif / * H U G E P A G E * /
# else / * ! P T E _ 6 4 B I T * /
2005-09-26 16:04:21 +10: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 15:34:40 +00: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 16:04:21 +10:00
/* Machine Check Interrupt */
2005-10-01 18:43:42 +10: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 16:04:21 +10:00
/* Data Storage Interrupt */
START_ E X C E P T I O N ( D a t a S t o r a g e )
2021-03-12 12:50:38 +00:00
NORMAL_ E X C E P T I O N _ P R O L O G ( 0 x30 0 , D A T A _ S T O R A G E )
2021-01-30 23:08:17 +10: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 * /
2008-07-09 10:03:28 -05:00
stw r5 ,_ E S R ( r11 )
2021-01-30 23:08:17 +10:00
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 * /
stw r4 , _ D E A R ( r11 )
2008-07-09 10:03:28 -05:00
andis. r10 ,r5 ,( E S R _ I L K | E S R _ D L K ) @h
bne 1 f
2021-03-12 12:50:41 +00:00
prepare_ t r a n s f e r _ t o _ h a n d l e r
bl d o _ p a g e _ f a u l t
b i n t e r r u p t _ r e t u r n
2008-07-09 10:03:28 -05:00
1 :
2021-03-12 12:50:41 +00:00
prepare_ t r a n s f e r _ t o _ h a n d l e r
bl C a c h e L o c k i n g E x c e p t i o n
b i n t e r r u p t _ r e t u r n
2005-09-26 16:04:21 +10:00
/* Instruction Storage Interrupt */
INSTRUCTION_ S T O R A G E _ E X C E P T I O N
/* External Input Interrupt */
2021-03-12 12:50:42 +00: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 )
2005-09-26 16:04:21 +10: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
2021-03-12 12:50:42 +00: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 , u n k n o w n _ e x c e p t i o n )
2005-09-26 16:04:21 +10:00
# endif
/* System Call Interrupt */
START_ E X C E P T I O N ( S y s t e m C a l l )
2019-05-23 08:39:27 +00:00
SYSCALL_ E N T R Y 0 x c00 B O O K E _ I N T E R R U P T _ S Y S C A L L S P R N _ S R R 1
2005-09-26 16:04:21 +10:00
2011-03-30 22:57:33 -03:00
/* Auxiliary Processor Unavailable Interrupt */
2021-03-12 12:50:42 +00: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 , u n k n o w n _ e x c e p t i o n )
2005-09-26 16:04:21 +10:00
/* Decrementer Interrupt */
DECREMENTER_ E X C E P T I O N
/* Fixed Internal Timer Interrupt */
/* TODO: Add FIT support */
2021-03-12 12:50:42 +00: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 , u n k n o w n _ e x c e p t i o n )
2005-09-26 16:04:21 +10:00
/* Watchdog Timer Interrupt */
# ifdef C O N F I G _ B O O K E _ W D T
2011-12-20 15:34:40 +00: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 16:04:21 +10:00
# else
2011-12-20 15:34:40 +00: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 16:04:21 +10: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-14 20:52:54 +00: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-22 16:48:27 -05: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 15:34:47 +00: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-22 16:48:27 -05: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 15:34:47 +00: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
2018-12-12 16:03:06 +02:00
START_ B T B _ F L U S H _ S E C T I O N
mfspr r11 , S P R N _ S R R 1
andi. r10 ,r11 ,M S R _ P R
beq 1 f
BTB_ F L U S H ( r10 )
1 :
END_ B T B _ F L U S H _ S E C T I O N
2005-09-26 16:04:21 +10: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 13:36:52 -05:00
lis r11 , P A G E _ O F F S E T @h
2005-09-26 16:04:21 +10: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-14 20:52:54 +00:00
mfspr r11 ,S P R N _ S P R G _ T H R E A D
2005-09-26 16:04:21 +10:00
lwz r11 ,P G D I R ( r11 )
2021-10-19 09:29:31 +02:00
# ifdef C O N F I G _ P P C _ K U A P
mfspr r12 , S P R N _ M A S 1
rlwinm. r12 ,r12 ,0 ,0 x3 f f f00 0 0
beq 2 f / * K U A P f a u l t * /
# endif
2005-09-26 16:04:21 +10:00
4 :
2008-07-09 10:03:28 -05: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 15:48:42 +00: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 10:03:28 -05: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 15:48:42 +00:00
# endif
2008-07-09 10:03:28 -05:00
rlwimi r13 ,r12 ,1 1 ,2 9 ,2 9
2005-09-26 16:04:21 +10:00
FIND_ P T E
2008-07-09 10:03:28 -05:00
andc. r13 ,r13 ,r11 / * C h e c k p e r m i s s i o n * /
2005-09-26 16:04:21 +10:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
2008-07-16 16:17:08 -05:00
# ifdef C O N F I G _ S M P
2011-06-28 09:54:48 +00: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-16 16:17:08 -05: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 16:04:21 +10:00
# endif
2021-03-15 03:34:36 +05:30
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 t c h * /
2008-07-16 16:17:08 -05:00
/* Jump to common tlb load */
2005-09-26 16:04:21 +10: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-22 16:48:27 -05: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 16:04:21 +10:00
mtcr r11
2011-04-22 16:48:27 -05: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-14 20:52:54 +00:00
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
2008-07-09 10:03:28 -05:00
b D a t a S t o r a g e
2005-09-26 16:04:21 +10: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-14 20:52:54 +00: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-22 16:48:27 -05: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 15:34:47 +00: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-22 16:48:27 -05: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 15:34:47 +00: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
2018-12-12 16:03:06 +02:00
START_ B T B _ F L U S H _ S E C T I O N
mfspr r11 , S P R N _ S R R 1
andi. r10 ,r11 ,M S R _ P R
beq 1 f
BTB_ F L U S H ( r10 )
1 :
END_ B T B _ F L U S H _ S E C T I O N
2005-09-26 16:04:21 +10: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 13:36:52 -05:00
lis r11 , P A G E _ O F F S E T @h
2005-09-26 16:04:21 +10: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 16:38:34 +08: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 16:04:21 +10:00
b 4 f
/* Get the PGD for the current thread */
3 :
2009-07-14 20:52:54 +00:00
mfspr r11 ,S P R N _ S P R G _ T H R E A D
2005-09-26 16:04:21 +10:00
lwz r11 ,P G D I R ( r11 )
2021-10-19 09:29:31 +02:00
# ifdef C O N F I G _ P P C _ K U A P
mfspr r12 , S P R N _ M A S 1
rlwinm. r12 ,r12 ,0 ,0 x3 f f f00 0 0
beq 2 f / * K U A P f a u l t * /
# endif
2010-05-07 16:38:34 +08:00
/* Make up the required permissions for user code */
2009-09-01 15:48:42 +00:00
# ifdef C O N F I G _ P T E _ 6 4 B I T
2010-05-07 16:38:34 +08: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 15:48:42 +00:00
oris r13 ,r13 ,_ P A G E _ A C C E S S E D @h
# else
2009-08-18 19:00:34 +00: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 15:48:42 +00:00
# endif
2008-07-09 10:03:28 -05:00
2010-05-07 16:38:34 +08:00
4 :
2005-09-26 16:04:21 +10:00
FIND_ P T E
2008-07-09 10:03:28 -05:00
andc. r13 ,r13 ,r11 / * C h e c k p e r m i s s i o n * /
2008-07-16 16:17:08 -05: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 09:54:48 +00: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-16 16:17:08 -05:00
# else
lwz r13 ,0 ( r12 ) / * G e t u p p e r p t e b i t s * /
# endif
# endif
2021-03-15 03:34:36 +05:30
bne 2 f / * B a i l i f p e r m i s s i o n m i s m a t c h * /
2005-09-26 16:04:21 +10: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-22 16:48:27 -05: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 16:04:21 +10:00
mtcr r11
2011-04-22 16:48:27 -05: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-14 20:52:54 +00:00
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
2005-09-26 16:04:21 +10:00
b I n s t r u c t i o n S t o r a g e
2020-11-17 05:07:58 +00:00
/* Define SPE handlers for e500v2 */
2005-09-26 16:04:21 +10: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 )
2021-03-12 12:50:38 +00:00
NORMAL_ E X C E P T I O N _ P R O L O G ( 0 x20 1 0 , S P E _ U N A V A I L )
2012-03-01 09:20:19 +08: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
2021-03-12 12:50:41 +00:00
1 : prepare_ t r a n s f e r _ t o _ h a n d l e r
bl K e r n e l S P E
b i n t e r r u p t _ r e t u r n
2014-08-20 16:09:03 +03: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 )
2021-03-12 12:50:42 +00: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 , u n k n o w n _ e x c e p t i o n )
2014-08-20 16:09:03 +03:00
# endif / * C O N F I G _ S P E _ P O S S I B L E * /
2005-09-26 16:04:21 +10:00
/* SPE Floating Point Data */
# ifdef C O N F I G _ S P E
2021-03-12 12:50:40 +00:00
START_ E X C E P T I O N ( S P E F l o a t i n g P o i n t D a t a )
NORMAL_ E X C E P T I O N _ P R O L O G ( 0 x20 3 0 , S P E _ F P _ D A T A )
prepare_ t r a n s f e r _ t o _ h a n d l e r
bl S P E F l o a t i n g P o i n t E x c e p t i o n
REST_ N V G P R S ( r1 )
b i n t e r r u p t _ r e t u r n
2005-09-26 16:04:21 +10:00
/* SPE Floating Point Round */
2021-03-12 12:50:40 +00:00
START_ E X C E P T I O N ( S P E F l o a t i n g P o i n t R o u n d )
NORMAL_ E X C E P T I O N _ P R O L O G ( 0 x20 5 0 , S P E _ F P _ R O U N D )
prepare_ t r a n s f e r _ t o _ h a n d l e r
bl S P E F l o a t i n g P o i n t R o u n d E x c e p t i o n
REST_ N V G P R S ( r1 )
b i n t e r r u p t _ r e t u r n
2014-08-20 16:09:03 +03: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 )
2021-03-12 12:50:42 +00: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 , u n k n o w n _ e x c e p t i o n )
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 , u n k n o w n _ e x c e p t i o n )
2014-08-20 16:09:03 +03:00
# endif / * C O N F I G _ S P E _ P O S S I B L E * /
2005-09-26 16:04:21 +10:00
/* Performance Monitor */
2011-12-20 15:34:40 +00: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 , \
2021-03-12 12:50:42 +00:00
performance_ m o n i t o r _ e x c e p t i o n )
2005-09-26 16:04:21 +10:00
2021-03-12 12:50:42 +00: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 )
2009-02-12 13:54:53 +00:00
2011-12-20 15:34:40 +00: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 16:04:21 +10:00
/* Debug Interrupt */
2008-04-09 06:06:11 -05: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 16:04:21 +10:00
2011-12-20 15:34:47 +00: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 */
2021-03-12 12:50:42 +00:00
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 )
2011-12-20 15:34:47 +00:00
/* Embedded Hypervisor Privilege */
2021-03-12 12:50:42 +00:00
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 )
2011-12-20 15:34:47 +00:00
2013-04-29 22:18:11 +00:00
interrupt_end :
2005-09-26 16:04:21 +10: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 09:54:48 +00: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 08:43:35 -05: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 10:03:28 -05: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 13:36:52 -05: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 16:04:21 +10: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 09:54:48 +00: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
2019-01-31 10:09:04 +00:00
lwz r15 , T A S K _ C P U - T H R E A D ( r12 )
2011-06-28 09:54:48 +00:00
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 16:04:21 +10: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 09:54:48 +00:00
finish_tlb_load_cont :
2009-09-01 15:48:42 +00: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 09:54:48 +00:00
2 : mtspr S P R N _ M A S 3 , r12
2009-09-01 15:48:42 +00: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 19:00:34 +00: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 09:54:48 +00:00
mr r13 , r11
2008-07-09 10:03:28 -05: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 16:04:21 +10: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 10:03:28 -05:00
slwi r10 , r12 , 1
or r10 , r10 , r12
2021-10-19 09:29:15 +02:00
rlwinm r10 , r10 , 0 , ~ _ P A G E _ E X E C / * C l e a r S X o n u s e r p a g e s * /
2008-07-09 10:03:28 -05:00
iseleq r12 , r12 , r10
2011-06-28 09:54:48 +00: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 16:04:21 +10:00
# endif
2011-06-28 09:54:48 +00: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
tlb_write_entry :
2005-09-26 16:04:21 +10:00
tlbwe
/* Done...restore registers and get out of here. */
2011-04-22 16:48:27 -05:00
mfspr r10 , S P R N _ S P R G _ T H R E A D
2011-06-28 09:54:48 +00: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 16:04:21 +10:00
mtcr r11
2011-04-22 16:48:27 -05: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-14 20:52:54 +00:00
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
2005-09-26 16:04:21 +10: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 09:20:19 +08:00
_ GLOBAL( l o a d _ u p _ s p e )
2005-09-26 16:04:21 +10: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
/* enable use of SPE after return */
oris r9 ,r9 ,M S R _ S P E @h
2009-07-14 20:52:54 +00: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 16:04:21 +10: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-14 18:34:27 -05:00
REST_ 3 2 E V R S ( 0 ,r10 ,r5 ,T H R E A D _ E V R 0 )
2012-03-01 09:20:19 +08:00
blr
2005-09-26 16:04:21 +10: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 .
* /
2023-01-28 18:11:38 +05:30
SYM_ F U N C _ S T A R T _ L O C A L ( K e r n e l S P E )
2005-09-26 16:04:21 +10:00
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-06 22:43:55 +00:00
# ifdef C O N F I G _ P R I N T K
2005-09-26 16:04:21 +10: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 )
printk: Userspace format indexing support
We have a number of systems industry-wide that have a subset of their
functionality that works as follows:
1. Receive a message from local kmsg, serial console, or netconsole;
2. Apply a set of rules to classify the message;
3. Do something based on this classification (like scheduling a
remediation for the machine), rinse, and repeat.
As a couple of examples of places we have this implemented just inside
Facebook, although this isn't a Facebook-specific problem, we have this
inside our netconsole processing (for alarm classification), and as part
of our machine health checking. We use these messages to determine
fairly important metrics around production health, and it's important
that we get them right.
While for some kinds of issues we have counters, tracepoints, or metrics
with a stable interface which can reliably indicate the issue, in order
to react to production issues quickly we need to work with the interface
which most kernel developers naturally use when developing: printk.
Most production issues come from unexpected phenomena, and as such
usually the code in question doesn't have easily usable tracepoints or
other counters available for the specific problem being mitigated. We
have a number of lines of monitoring defence against problems in
production (host metrics, process metrics, service metrics, etc), and
where it's not feasible to reliably monitor at another level, this kind
of pragmatic netconsole monitoring is essential.
As one would expect, monitoring using printk is rather brittle for a
number of reasons -- most notably that the message might disappear
entirely in a new version of the kernel, or that the message may change
in some way that the regex or other classification methods start to
silently fail.
One factor that makes this even harder is that, under normal operation,
many of these messages are never expected to be hit. For example, there
may be a rare hardware bug which one wants to detect if it was to ever
happen again, but its recurrence is not likely or anticipated. This
precludes using something like checking whether the printk in question
was printed somewhere fleetwide recently to determine whether the
message in question is still present or not, since we don't anticipate
that it should be printed anywhere, but still need to monitor for its
future presence in the long-term.
This class of issue has happened on a number of occasions, causing
unhealthy machines with hardware issues to remain in production for
longer than ideal. As a recent example, some monitoring around
blk_update_request fell out of date and caused semi-broken machines to
remain in production for longer than would be desirable.
Searching through the codebase to find the message is also extremely
fragile, because many of the messages are further constructed beyond
their callsite (eg. btrfs_printk and other module-specific wrappers,
each with their own functionality). Even if they aren't, guessing the
format and formulation of the underlying message based on the aesthetics
of the message emitted is not a recipe for success at scale, and our
previous issues with fleetwide machine health checking demonstrate as
much.
This provides a solution to the issue of silently changed or deleted
printks: we record pointers to all printk format strings known at
compile time into a new .printk_index section, both in vmlinux and
modules. At runtime, this can then be iterated by looking at
<debugfs>/printk/index/<module>, which emits the following format, both
readable by humans and able to be parsed by machines:
$ head -1 vmlinux; shuf -n 5 vmlinux
# <level[,flags]> filename:line function "format"
<5> block/blk-settings.c:661 disk_stack_limits "%s: Warning: Device %s is misaligned\n"
<4> kernel/trace/trace.c:8296 trace_create_file "Could not create tracefs '%s' entry\n"
<6> arch/x86/kernel/hpet.c:144 _hpet_print_config "hpet: %s(%d):\n"
<6> init/do_mounts.c:605 prepare_namespace "Waiting for root device %s...\n"
<6> drivers/acpi/osl.c:1410 acpi_no_auto_serialize_setup "ACPI: auto-serialization disabled\n"
This mitigates the majority of cases where we have a highly-specific
printk which we want to match on, as we can now enumerate and check
whether the format changed or the printk callsite disappeared entirely
in userspace. This allows us to catch changes to printks we monitor
earlier and decide what to do about it before it becomes problematic.
There is no additional runtime cost for printk callers or printk itself,
and the assembly generated is exactly the same.
Signed-off-by: Chris Down <chris@chrisdown.name>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kees Cook <keescook@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Tested-by: Petr Mladek <pmladek@suse.com>
Reported-by: kernel test robot <lkp@intel.com>
Acked-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Jessica Yu <jeyu@kernel.org> # for module.{c,h}
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/e42070983637ac5e384f17fbdbe86d19c7b212a5.1623775748.git.chris@chrisdown.name
2021-06-15 17:52:53 +01:00
bl _ p r i n t k
2010-03-06 22:43:55 +00:00
# endif
2021-03-12 12:50:41 +00:00
b i n t e r r u p t _ r e t u r n
2010-03-06 22:43:55 +00:00
# ifdef C O N F I G _ P R I N T K
2005-09-26 16:04:21 +10:00
87 : .string " SPE used in kernel (task=%p, pc=%x) \n "
2010-03-06 22:43:55 +00:00
# endif
2005-09-26 16:04:21 +10:00
.align 4 , 0
2023-01-28 18:11:38 +05:30
SYM_ F U N C _ E N D ( K e r n e l S P E )
2005-09-26 16:04:21 +10:00
# endif / * C O N F I G _ S P E * /
2013-12-24 15:12:04 +08: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 )
* /
2022-11-14 23:27:44 +05:30
SYM_ F U N C _ S T A R T _ L O C A L ( g e t _ p h y s _ a d d r )
2013-12-24 15:12:04 +08:00
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
2022-11-14 23:27:44 +05:30
SYM_ F U N C _ E N D ( g e t _ p h y s _ a d d r )
2013-12-24 15:12:04 +08:00
2005-09-26 16:04:21 +10:00
/ *
* Global f u n c t i o n s
* /
2022-09-19 19:01:35 +02:00
# ifdef C O N F I G _ P P C _ E 5 0 0
2014-08-20 16:09:03 +03:00
# ifndef C O N F I G _ P P C _ E 5 0 0 M C
2009-01-08 08:31:20 -06: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 16:09:03 +03:00
# else
2009-01-08 08:31:20 -06: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 13:54:53 +00: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 18:25:31 +05:30
sync
blr
2011-12-20 15:34:47 +00:00
2012-07-09 18:25:31 +05:30
/* setup ehv ivors for */
_ GLOBAL( _ _ s e t u p _ e h v _ i v o r s )
2011-12-20 15:34:47 +00: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 08:31:20 -06:00
sync
blr
2014-08-20 16:09:03 +03:00
# endif / * C O N F I G _ P P C _ E 5 0 0 M C * /
2022-09-19 19:01:35 +02:00
# endif / * C O N F I G _ P P C _ E 5 0 0 * /
2009-01-08 08:31:20 -06:00
2005-09-26 16:04:21 +10:00
# ifdef C O N F I G _ S P E
/ *
2015-10-29 11:44:01 +11:00
* 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 )
2005-09-26 16:04:21 +10:00
*
* /
2015-10-29 11:44:01 +11:00
_ GLOBAL( _ _ g i v e u p _ s p e )
2005-09-26 16:04:21 +10:00
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-14 18:34:27 -05:00
SAVE_ 3 2 E V R S ( 0 , r4 , r3 , T H R E A D _ E V R 0 )
2007-09-27 08:43:35 -05: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 16:04:21 +10: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 08:43:35 -05: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 16:04:21 +10:00
beq 1 f
2022-11-27 22:49:32 +10:00
lwz r4 ,_ M S R - S T A C K _ I N T _ F R A M E _ R E G S ( r5 )
2005-09-26 16:04:21 +10:00
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 * /
2022-11-27 22:49:32 +10:00
stw r4 ,_ M S R - S T A C K _ I N T _ F R A M E _ R E G S ( r5 )
2005-09-26 16:04:21 +10:00
1 :
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 08:43:35 -05: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-08 16:41:26 -06:00
isync
2005-09-26 16:04:21 +10:00
mfmsr r13
ori r13 ,r13 ,M S R _ D E @l /* Enable Debug Events */
mtmsr r13
2006-02-08 16:41:26 -06:00
isync
2007-09-27 08:43:35 -05: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-08 16:41:26 -06:00
isync
2005-09-26 16:04:21 +10:00
2008-11-19 09:35:56 -06: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 15:12:11 +08: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 09:35:56 -06:00
mtctr r3
li r26 ,0 / * r26 s a f e ? * /
2013-12-24 15:12:11 +08: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 09:35:56 -06: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 15:12:11 +08: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 * /
2019-09-20 17:45:40 +08:00
lis r7 ,K E R N E L B A S E @h
ori r7 ,r7 ,K E R N E L B A S E @l
cmpw r20 ,r7 / * i f k e r n s t a r t _ v i r t _ a d d r ! = K E R N E L B A S E , r a n d o m i z e d * /
beq 2 f
li r4 ,0
2 : li r5 ,0 / * n o d e v i c e t r e e * /
2013-12-24 15:12:11 +08:00
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 09:35:56 -06:00
2019-01-17 23:25:53 +11:00
/* get current's stack and current */
2019-01-31 10:09:02 +00:00
lis r2 ,s e c o n d a r y _ c u r r e n t @ha
lwz r2 ,s e c o n d a r y _ c u r r e n t @l(r2)
2019-01-31 10:08:58 +00:00
lwz r1 ,T A S K _ S T A C K ( r2 )
2008-11-19 09:35:56 -06:00
/* stack */
2022-11-27 22:49:40 +10:00
addi r1 ,r1 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ M I N _ S I Z E
2008-11-19 09:35:56 -06:00
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-14 20:52:54 +00:00
mtspr S P R N _ S P R G _ T H R E A D ,r4
2008-11-19 09:35:56 -06:00
/* Setup the defaults for TLB entries */
2009-02-10 18:10:50 -06: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 09:35:56 -06: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
2019-09-20 17:45:38 +08:00
/ *
* Create a 6 4 M t l b b y a d d r e s s a n d e n t r y
* r3 - e n t r y
* r4 - v i r t u a l a d d r e s s
* r5 / r6 - p h y s i c a l a d d r e s s
* /
_ GLOBAL( c r e a t e _ k a s l r _ t l b _ e n t r y )
lis r7 ,0 x10 0 0 / * S e t M A S 0 ( T L B S E L ) = 1 * /
rlwimi r7 ,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 ( r6 ) * /
mtspr S P R N _ M A S 0 ,r7 / * W r i t e M A S 0 * /
lis r3 ,( M A S 1 _ V A L I D | M A S 1 _ I P R O T ) @h
ori r3 ,r3 ,( M A S 1 _ T S I Z E ( B O O K 3 E _ P A G E S Z _ 6 4 M ) ) @l
mtspr S P R N _ M A S 1 ,r3 / * W r i t e M A S 1 * /
lis r3 ,M A S 2 _ E P N _ M A S K ( B O O K 3 E _ P A G E S Z _ 6 4 M ) @h
ori r3 ,r3 ,M A S 2 _ E P N _ M A S K ( B O O K 3 E _ P A G E S Z _ 6 4 M ) @l
and r3 ,r3 ,r4
ori r3 ,r3 ,M A S 2 _ M _ I F _ N E E D E D @l
mtspr S P R N _ M A S 2 ,r3 / * W r i t e M A S 2 ( E P N ) * /
# ifdef C O N F I G _ P H Y S _ 6 4 B I T
ori r8 ,r6 ,( M A S 3 _ S W | M A S 3 _ S R | M A S 3 _ S X )
mtspr S P R N _ M A S 3 ,r8 / * W r i t e M A S 3 ( R P N ) * /
mtspr S P R N _ M A S 7 ,r5
# else
ori r8 ,r5 ,( M A S 3 _ S W | M A S 3 _ S R | M A S 3 _ S X )
mtspr S P R N _ M A S 3 ,r8 / * W r i t e M A S 3 ( R P N ) * /
# endif
tlbwe / * W r i t e T L B * /
isync
sync
blr
2019-09-20 17:45:39 +08:00
/ *
* Return t o t h e s t a r t o f t h e r e l o c a t e d k e r n e l a n d r u n a g a i n
* r3 - v i r t u a l a d d r e s s o f f d t
* r4 - e n t r y o f t h e k e r n e l
* /
_ GLOBAL( r e l o c _ k e r n e l _ e n t r y )
mfmsr r7
rlwinm r7 , r7 , 0 , ~ ( M S R _ I S | M S R _ D S )
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r7
rfi
2013-12-24 15:12:07 +08: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 */
2021-08-24 07:56:26 +00:00
bcl 2 0 ,3 1 ,$ + 4
2013-12-24 15:12:07 +08:00
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 15:12:10 +08: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 15:12:11 +08:00
* r6 - b o o t c p u
2013-12-24 15:12:07 +08:00
* /
_ GLOBAL( r e s t o r e _ t o _ a s0 )
mflr r0
2021-08-24 07:56:26 +00:00
bcl 2 0 ,3 1 ,$ + 4
2013-12-24 15:12:07 +08:00
0 : mflr r9
addi r9 ,r9 ,1 f - 0 b
2013-12-24 15:12:10 +08: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 15:12:11 +08:00
add r0 ,r0 ,r4
2013-12-24 15:12:10 +08:00
2 : mfmsr r7
2013-12-24 15:12:07 +08: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 15:12:10 +08:00
cmpwi r4 ,0
2013-12-24 15:12:11 +08: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 15:12:07 +08:00
mtlr r0
blr
2013-12-24 15:12:10 +08: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