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>
* Initial P o w e r P C v e r s i o n .
* Copyright ( c ) 1 9 9 6 C o r t D o u g a n < c o r t @cs.nmt.edu>
* Rewritten f o r P R e P
* Copyright ( c ) 1 9 9 6 P a u l M a c k e r r a s < p a u l u s @cs.anu.edu.au>
* Low- l e v e l e x c e p t i o n h a n d e r s , M M U s u p p o r t , a n d r e w r i t e .
* Copyright ( c ) 1 9 9 7 D a n M a l e k < d m a l e k @jlc.net>
* PowerPC 8 x x m o d i f i c a t i o n s .
* Copyright ( c ) 1 9 9 8 - 1 9 9 9 T i V o , I n c .
* PowerPC 4 0 3 G C X m o d i f i c a t i o n s .
* Copyright ( c ) 1 9 9 9 G r a n t E r i c k s o n < g r a n t @lcse.umn.edu>
* PowerPC 4 0 3 G C X / 4 0 5 G P m o d i f i c a t i o n s .
* Copyright 2 0 0 0 M o n t a V i s t a S o f t w a r e I n c .
* PPC4 0 5 m o d i f i c a t i o n s
* PowerPC 4 0 3 G C X / 4 0 5 G P m o d i f i c a t i o n s .
* Author : MontaVista S o f t w a r e , I n c .
* frank_ r o w a n d @mvista.com or source@mvista.com
* debbie_ c h u @mvista.com
* Copyright 2 0 0 2 - 2 0 0 5 M o n t a V i s t a S o f t w a r e , I n c .
* 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>
*
* 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 < a s m / p r o c e s s o r . h >
# include < a s m / p a g e . h >
# include < a s m / m m u . h >
# include < a s m / p g t a b l e . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
2010-11-18 18:06:17 +03:00
# include < a s m / p t r a c e . h >
2010-03-05 13:43:12 +03:00
# include < a s m / s y n c h . 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
mr r31 ,r3 / * s a v e d e v i c e t r e e p t r * /
2005-09-26 10:04:21 +04:00
li r24 ,0 / * C P U n u m b e r * /
2010-03-05 13:43:07 +03:00
bl i n i t _ c p u _ s t a t e
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 )
bl e a r l y _ i n i t
2011-07-04 22:36:57 +04:00
# ifdef C O N F I G _ R E L O C A T A B L E
/ *
* r2 5 w i l l c o n t a i n R P N / E R P N f o r t h e s t a r t a d d r e s s o f m e m o r y
*
* Add t h e d i f f e r e n c e b e t w e e n K E R N E L B A S E a n d P A G E _ O F F S E T t o t h e
* start o f p h y s i c a l m e m o r y t o g e t k e r n s t a r t _ a d d r .
* /
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)
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
lis r5 ,P A G E _ O F F S E T @h
ori r5 ,r5 ,P A G E _ O F F S E T @l
subf r4 ,r5 ,r4
rlwinm r6 ,r25 ,0 ,2 8 ,3 1 / * E R P N * /
rlwinm r7 ,r25 ,0 ,0 ,3 / * R P N - a s s u m i n g 2 5 6 M B p a g e s i z e * /
add r7 ,r7 ,r4
stw r6 ,0 ( r3 )
stw r7 ,4 ( r3 )
# 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
li r3 ,0
mr r4 ,r31
2005-09-26 10:04:21 +04:00
bl m a c h i n e _ i n i t
bl M M U _ i n i t
/* 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 )
2010-08-18 10:44:23 +04:00
/* Clear the Machine Check Syndrome Register */
li r0 ,0
mtspr S P R N _ M C S R ,r0
2005-09-26 10:04:21 +04:00
/* 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 * /
/ *
* 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 */
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x01 0 0 , C r i t i c a l I n 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 */
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x02 0 0 , M a c h i n e C h e c k , m a c h i n e _ c h e c k _ e x c e p t i o n )
2007-12-21 07:39:21 +03:00
MCHECK_ E X C E P T I O N ( 0 x02 1 0 , M a c h i n e C h e c k A , m a c h i n e _ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
/* Data Storage Interrupt */
2008-07-08 09:54:40 +04:00
DATA_ S T O R A G E _ E X C E P T I O N
2005-09-26 10:04:21 +04:00
2008-07-08 09:54:40 +04:00
/* Instruction Storage Interrupt */
2005-09-26 10:04:21 +04:00
INSTRUCTION_ S T O R A G E _ E X C E P T I O N
/* External Input Interrupt */
EXCEPTION( 0 x05 0 0 , 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 )
/* 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
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x20 1 0 , 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 , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04: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 )
NORMAL_ E X C E P T I O N _ P R O L O G
EXC_ X F E R _ E E _ L I T E ( 0 x0 c00 , D o S y s c a l l )
2011-03-31 05:57:33 +04:00
/* Auxiliary Processor Unavailable Interrupt */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x20 2 0 , 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 , 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 */
2005-10-01 12:43:42 +04:00
EXCEPTION( 0 x10 1 0 , 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 , E X C _ X F E R _ E E )
2005-09-26 10:04:21 +04:00
/* Watchdog Timer Interrupt */
/* TODO: Add watchdog support */
# ifdef C O N F I G _ B O O K E _ W D T
CRITICAL_ E X C E P T I O N ( 0 x10 2 0 , W 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 )
# else
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x10 2 0 , 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 */
2010-03-05 13:43:12 +03:00
START_ E X C E P T I O N ( D a t a T L B E r r o r44 x )
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 * /
mtspr S P R N _ S P R G _ W S C R A T C H 1 , r11
mtspr S P R N _ S P R G _ W S C R A T C H 2 , r12
mtspr S P R N _ S P R G _ W S C R A T C H 3 , r13
2005-09-26 10:04:21 +04:00
mfcr r11
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 4 , r11
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 r10 , r11
blt+ 3 f
lis r11 , s w a p p e r _ p g _ d i r @h
ori r11 , r11 , s w a p p e r _ p g _ d i r @l
mfspr r12 ,S P R N _ M M U C R
rlwinm r12 ,r12 ,0 ,0 ,2 3 / * C l e a r T I D * /
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 )
/* Load PID into MMUCR TID */
mfspr r12 ,S P R N _ M M U C R
mfspr r13 ,S P R N _ P I D / * G e t P I D * /
rlwimi r12 ,r13 ,0 ,2 4 ,3 1 / * S e t T I D * /
4 :
mtspr S P R N _ M M U C R ,r12
2008-07-08 09:54:40 +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
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
rlwimi r13 ,r12 ,1 0 ,3 0 ,3 0
/* Load the PTE */
2008-12-11 04:55:41 +03:00
/* Compute pgdir/pmd offset */
rlwinm r12 , r10 , P P C 4 4 x _ P G D _ O F F _ S H I F T , P P C 4 4 x _ P G D _ O F F _ M A S K _ B I T , 2 9
2005-09-26 10:04:21 +04:00
lwzx r11 , r12 , r11 / * G e t p g d / p m d e n t r y * /
rlwinm. r12 , r11 , 0 , 0 , 2 0 / * E x t r a c t p t b a s e a d d r e s s * /
beq 2 f / * B a i l i f n o t a b l e * /
2008-12-11 04:55:41 +03:00
/* Compute pte address */
rlwimi r12 , r10 , P P C 4 4 x _ P T E _ A D D _ S H I F T , P P C 4 4 x _ P T E _ A D D _ M A S K _ B I T , 2 8
2008-07-08 09:54:40 +04:00
lwz r11 , 0 ( r12 ) / * G e t h i g h w o r d o f p t e e n t r y * /
lwz r12 , 4 ( r12 ) / * G e t l o w w o r d o f p t e e n t r y * /
2005-09-26 10:04:21 +04:00
2008-07-08 09:54:40 +04:00
lis r10 ,t l b _ 4 4 x _ i n d e x @ha
andc. r13 ,r13 ,r12 / * C h e c k p e r m i s s i o n * /
/* Load the next available TLB index */
lwz r13 ,t l b _ 4 4 x _ i n d e x @l(r10)
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 * /
/* Increment, rollover, and store TLB index */
addi r13 ,r13 ,1
/* Compare with watermark (instruction gets patched) */
.globl tlb_44x_patch_hwater_D
tlb_44x_patch_hwater_D :
cmpwi 0 ,r13 ,1 / * r e s e r v e e n t r i e s * /
ble 5 f
li r13 ,0
5 :
/* Store the next available TLB index */
stw r13 ,t l b _ 4 4 x _ i n d e x @l(r10)
/* Re-load the faulting address */
mfspr r10 ,S P R N _ D E A R
2005-09-26 10:04:21 +04:00
/* Jump to common tlb load */
2010-03-05 13:43:12 +03:00
b f i n i s h _ t l b _ l o a d _ 4 4 x
2005-09-26 10:04:21 +04:00
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 .
* /
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 4
2005-09-26 10:04:21 +04:00
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r13 , S P R N _ S P R G _ R S C R A T C H 3
mfspr r12 , S P R N _ S P R G _ R S C R A T C H 2
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
2008-07-08 09:54:40 +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 .
* /
2010-03-05 13:43:12 +03:00
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 r44 x )
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 * /
mtspr S P R N _ S P R G _ W S C R A T C H 1 , r11
mtspr S P R N _ S P R G _ W S C R A T C H 2 , r12
mtspr S P R N _ S P R G _ W S C R A T C H 3 , r13
2005-09-26 10:04:21 +04:00
mfcr r11
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 4 , r11
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 r10 , r11
blt+ 3 f
lis r11 , s w a p p e r _ p g _ d i r @h
ori r11 , r11 , s w a p p e r _ p g _ d i r @l
mfspr r12 ,S P R N _ M M U C R
rlwinm r12 ,r12 ,0 ,0 ,2 3 / * C l e a r T I D * /
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 )
/* Load PID into MMUCR TID */
mfspr r12 ,S P R N _ M M U C R
mfspr r13 ,S P R N _ P I D / * G e t P I D * /
rlwimi r12 ,r13 ,0 ,2 4 ,3 1 / * S e t T I D * /
4 :
mtspr S P R N _ M M U C R ,r12
2008-07-08 09:54:40 +04:00
/* Make up the required permissions */
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
2008-07-08 09:54:40 +04:00
2008-12-11 04:55:41 +03:00
/* Compute pgdir/pmd offset */
rlwinm r12 , r10 , P P C 4 4 x _ P G D _ O F F _ S H I F T , P P C 4 4 x _ P G D _ O F F _ M A S K _ B I T , 2 9
2005-09-26 10:04:21 +04:00
lwzx r11 , r12 , r11 / * G e t p g d / p m d e n t r y * /
rlwinm. r12 , r11 , 0 , 0 , 2 0 / * E x t r a c t p t b a s e a d d r e s s * /
beq 2 f / * B a i l i f n o t a b l e * /
2008-12-11 04:55:41 +03:00
/* Compute pte address */
rlwimi r12 , r10 , P P C 4 4 x _ P T E _ A D D _ S H I F T , P P C 4 4 x _ P T E _ A D D _ M A S K _ B I T , 2 8
2008-07-08 09:54:40 +04:00
lwz r11 , 0 ( r12 ) / * G e t h i g h w o r d o f p t e e n t r y * /
lwz r12 , 4 ( r12 ) / * G e t l o w w o r d o f p t e e n t r y * /
2005-09-26 10:04:21 +04:00
2008-07-08 09:54:40 +04:00
lis r10 ,t l b _ 4 4 x _ i n d e x @ha
andc. r13 ,r13 ,r12 / * C h e c k p e r m i s s i o n * /
/* Load the next available TLB index */
lwz r13 ,t l b _ 4 4 x _ i n d e x @l(r10)
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 * /
/* Increment, rollover, and store TLB index */
addi r13 ,r13 ,1
/* Compare with watermark (instruction gets patched) */
.globl tlb_44x_patch_hwater_I
tlb_44x_patch_hwater_I :
cmpwi 0 ,r13 ,1 / * r e s e r v e e n t r i e s * /
ble 5 f
li r13 ,0
5 :
/* Store the next available TLB index */
stw r13 ,t l b _ 4 4 x _ i n d e x @l(r10)
/* Re-load the faulting address */
mfspr r10 ,S P R N _ S R R 0
2005-09-26 10:04:21 +04:00
/* Jump to common TLB load point */
2010-03-05 13:43:12 +03:00
b f i n i s h _ t l b _ l o a d _ 4 4 x
2005-09-26 10:04:21 +04:00
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 .
* /
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 4
2005-09-26 10:04:21 +04:00
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r13 , S P R N _ S P R G _ R S C R A T C H 3
mfspr r12 , S P R N _ S P R G _ R S C R A T C H 2
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 1
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
/ *
* 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 .
* r1 0 - E A o f f a u l t
2008-07-08 09:54:40 +04:00
* r1 1 - P T E h i g h w o r d v a l u e
* r1 2 - P T E l o w w o r d v a l u e
* r1 3 - T L B i n d e x
2005-09-26 10:04:21 +04:00
* MMUCR - l o a d e d w i t h p r o p e r v a l u e w h e n w e g e t h e r e
* Upon e x i t , w e r e l o a d e v e r y t h i n g a n d R F I .
* /
2010-03-05 13:43:12 +03:00
finish_tlb_load_44x :
2008-07-08 09:54:40 +04:00
/* Combine RPN & ERPN an write WS 0 */
2008-12-11 04:55:41 +03:00
rlwimi r11 ,r12 ,0 ,0 ,3 1 - P A G E _ S H I F T
2008-07-08 09:54:40 +04:00
tlbwe r11 ,r13 ,P P C 4 4 x _ T L B _ X L A T
2005-09-26 10:04:21 +04:00
/ *
2008-07-08 09:54:40 +04:00
* Create W S 1 . T h i s i s t h e f a u l t i n g a d d r e s s ( E P N ) ,
2005-09-26 10:04:21 +04:00
* page s i z e , a n d v a l i d f l a g .
* /
2008-12-11 04:55:41 +03:00
li r11 ,P P C 4 4 x _ T L B _ V A L I D | P P C 4 4 x _ T L B E _ S I Z E
/* Insert valid and page size */
rlwimi r10 ,r11 ,0 ,P P C 4 4 x _ P T E _ A D D _ M A S K _ B I T ,3 1
2008-07-08 09:54:40 +04:00
tlbwe r10 ,r13 ,P P C 4 4 x _ T L B _ P A G E I D / * W r i t e P A G E I D * /
/* And WS 2 */
li r10 ,0 x f85 / * M a s k t o a p p l y f r o m P T E * /
rlwimi r10 ,r12 ,2 9 ,3 0 ,3 0 / * D I R T Y - > S W p o s i t i o n * /
and r11 ,r12 ,r10 / * M a s k P T E b i t s t o k e e p * /
andi. r10 ,r12 ,_ P A G E _ U S E R / * U s e r p a g e ? * /
beq 1 f / * n o p e , l e a v e U b i t s e m p t y * /
rlwimi r11 ,r11 ,3 ,2 6 ,2 8 / * y e s , c o p y S b i t s t o U * /
1 : tlbwe r11 ,r13 ,P P C 4 4 x _ T L B _ A T T R I B / * W r i t e A T T R I B * /
2005-09-26 10:04:21 +04:00
/ * Done. . . r e s t o r e r e g i s t e r s a n d g e t o u t o f h e r e .
* /
2009-07-15 00:52:54 +04:00
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 4
2005-09-26 10:04:21 +04:00
mtcr r11
2009-07-15 00:52:54 +04:00
mfspr r13 , S P R N _ S P R G _ R S C R A T C H 3
mfspr r12 , S P R N _ S P R G _ R S C R A T C H 2
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 1
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 * /
2010-03-05 13:43:12 +03:00
/ * TLB e r r o r i n t e r r u p t s f o r 4 7 6
* /
# ifdef C O N F I G _ P P C _ 4 7 x
START_ E X C E P T I O N ( D a t a T L B E r r o r47 x )
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 * /
mtspr S P R N _ S P R G _ W S C R A T C H 1 ,r11
mtspr S P R N _ S P R G _ W S C R A T C H 2 ,r12
mtspr S P R N _ S P R G _ W S C R A T C H 3 ,r13
mfcr r11
mtspr S P R N _ S P R G _ W S C R A T C H 4 ,r11
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 .
* /
lis r11 ,P A G E _ O F F S E T @h
cmplw c r0 ,r10 ,r11
blt+ 3 f
lis r11 ,s w a p p e r _ p g _ d i r @h
ori r11 ,r11 , s w a p p e r _ p g _ d i r @l
li r12 ,0 / * M M U C R = 0 * /
b 4 f
/* Get the PGD for the current thread and setup MMUCR */
3 : mfspr r11 ,S P R N _ S P R G 3
lwz r11 ,P G D I R ( r11 )
mfspr r12 ,S P R N _ P I D / * G e t P I D * /
4 : mtspr S P R N _ M M U C R ,r12 / * S e t M M U C R * /
/ * 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
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
rlwimi r13 ,r12 ,1 0 ,3 0 ,3 0
/* Load the PTE */
/* Compute pgdir/pmd offset */
rlwinm r12 ,r10 ,P P C 4 4 x _ P G D _ O F F _ S H I F T ,P P C 4 4 x _ P G D _ O F F _ M A S K _ B I T ,2 9
lwzx r11 ,r12 ,r11 / * G e t p g d / p m d e n t r y * /
/* Word 0 is EPN,V,TS,DSIZ */
li r12 ,P P C 4 7 x _ T L B 0 _ V A L I D | P P C 4 7 x _ T L B E _ S I Z E
rlwimi r10 ,r12 ,0 ,3 2 - P A G E _ S H I F T ,3 1 / * I n s e r t v a l i d a n d p a g e s i z e * /
li r12 ,0
tlbwe r10 ,r12 ,0
/ * XXX c a n w e d o b e t t e r ? N e e d t o m a k e s u r e t l b w e h a s e s t a b l i s h e d
* latch V b i t i n M M U C R 0 b e f o r e t h e P T E i s l o a d e d f u r t h e r d o w n * /
# ifdef C O N F I G _ S M P
isync
# endif
rlwinm. r12 ,r11 ,0 ,0 ,2 0 / * E x t r a c t p t b a s e a d d r e s s * /
/* Compute pte address */
rlwimi r12 ,r10 ,P P C 4 4 x _ P T E _ A D D _ S H I F T ,P P C 4 4 x _ P T E _ A D D _ M A S K _ B I T ,2 8
beq 2 f / * B a i l i f n o t a b l e * /
lwz r11 ,0 ( r12 ) / * G e t h i g h w o r d o f p t e e n t r y * /
/ * XXX c a n w e d o b e t t e r ? m a y b e i n s e r t a k n o w n 0 b i t f r o m r11 i n t o t h e
* bottom o f r12 t o c r e a t e a d a t a d e p e n d e n c y . . . W e c a n a l s o u s e r10
* as d e s t i n a t i o n n o w a d a y s
* /
# ifdef C O N F I G _ S M P
lwsync
# endif
lwz r12 ,4 ( r12 ) / * G e t l o w w o r d o f p t e e n t r y * /
andc. r13 ,r13 ,r12 / * C h e c k p e r m i s s i o n * /
/* Jump to common tlb load */
beq f i n i s h _ t l b _ l o a d _ 4 7 x
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 .
* /
mfspr r11 ,S P R N _ S P R G _ R S C R A T C H 4
mtcr r11
mfspr r13 ,S P R N _ S P R G _ R S C R A T C H 3
mfspr r12 ,S P R N _ S P R G _ R S C R A T C H 2
mfspr r11 ,S P R N _ S P R G _ R S C R A T C H 1
mfspr r10 ,S P R N _ S P R G _ R S C R A T C H 0
b D a t a S t o r a g e
/* 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 r47 x )
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 * /
mtspr S P R N _ S P R G _ W S C R A T C H 1 ,r11
mtspr S P R N _ S P R G _ W S C R A T C H 2 ,r12
mtspr S P R N _ S P R G _ W S C R A T C H 3 ,r13
mfcr r11
mtspr S P R N _ S P R G _ W S C R A T C H 4 ,r11
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 .
* /
lis r11 ,P A G E _ O F F S E T @h
cmplw c r0 ,r10 ,r11
blt+ 3 f
lis r11 ,s w a p p e r _ p g _ d i r @h
ori r11 ,r11 , s w a p p e r _ p g _ d i r @l
li r12 ,0 / * M M U C R = 0 * /
b 4 f
/* Get the PGD for the current thread and setup MMUCR */
3 : mfspr r11 ,S P R N _ S P R G _ T H R E A D
lwz r11 ,P G D I R ( r11 )
mfspr r12 ,S P R N _ P I D / * G e t P I D * /
4 : mtspr S P R N _ M M U C R ,r12 / * S e t M M U C R * /
/* Make up the required permissions */
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
/* Load PTE */
/* Compute pgdir/pmd offset */
rlwinm r12 ,r10 ,P P C 4 4 x _ P G D _ O F F _ S H I F T ,P P C 4 4 x _ P G D _ O F F _ M A S K _ B I T ,2 9
lwzx r11 ,r12 ,r11 / * G e t p g d / p m d e n t r y * /
/* Word 0 is EPN,V,TS,DSIZ */
li r12 ,P P C 4 7 x _ T L B 0 _ V A L I D | P P C 4 7 x _ T L B E _ S I Z E
rlwimi r10 ,r12 ,0 ,3 2 - P A G E _ S H I F T ,3 1 / * I n s e r t v a l i d a n d p a g e s i z e * /
li r12 ,0
tlbwe r10 ,r12 ,0
/ * XXX c a n w e d o b e t t e r ? N e e d t o m a k e s u r e t l b w e h a s e s t a b l i s h e d
* latch V b i t i n M M U C R 0 b e f o r e t h e P T E i s l o a d e d f u r t h e r d o w n * /
# ifdef C O N F I G _ S M P
isync
# endif
rlwinm. r12 ,r11 ,0 ,0 ,2 0 / * E x t r a c t p t b a s e a d d r e s s * /
/* Compute pte address */
rlwimi r12 ,r10 ,P P C 4 4 x _ P T E _ A D D _ S H I F T ,P P C 4 4 x _ P T E _ A D D _ M A S K _ B I T ,2 8
beq 2 f / * B a i l i f n o t a b l e * /
lwz r11 ,0 ( r12 ) / * G e t h i g h w o r d o f p t e e n t r y * /
/ * XXX c a n w e d o b e t t e r ? m a y b e i n s e r t a k n o w n 0 b i t f r o m r11 i n t o t h e
* bottom o f r12 t o c r e a t e a d a t a d e p e n d e n c y . . . W e c a n a l s o u s e r10
* as d e s t i n a t i o n n o w a d a y s
* /
# ifdef C O N F I G _ S M P
lwsync
# endif
lwz r12 ,4 ( r12 ) / * G e t l o w w o r d o f p t e e n t r y * /
andc. r13 ,r13 ,r12 / * C h e c k p e r m i s s i o n * /
/* Jump to common TLB load point */
beq f i n i s h _ t l b _ l o a d _ 4 7 x
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 .
* /
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 4
mtcr r11
mfspr r13 , S P R N _ S P R G _ R S C R A T C H 3
mfspr r12 , S P R N _ S P R G _ R S C R A T C H 2
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
b I n s t r u c t i o n S t o r a g e
/ *
* 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 .
* r1 0 - f r e e t o u s e
* r1 1 - P T E h i g h w o r d v a l u e
* r1 2 - P T E l o w w o r d v a l u e
* r1 3 - f r e e t o u s e
* MMUCR - l o a d e d w i t h p r o p e r v a l u e w h e n w e g e t h e r e
* Upon e x i t , w e r e l o a d e v e r y t h i n g a n d R F I .
* /
finish_tlb_load_47x :
/* Combine RPN & ERPN an write WS 1 */
rlwimi r11 ,r12 ,0 ,0 ,3 1 - P A G E _ S H I F T
tlbwe r11 ,r13 ,1
/* And make up word 2 */
li r10 ,0 x f85 / * M a s k t o a p p l y f r o m P T E * /
rlwimi r10 ,r12 ,2 9 ,3 0 ,3 0 / * D I R T Y - > S W p o s i t i o n * /
and r11 ,r12 ,r10 / * M a s k P T E b i t s t o k e e p * /
andi. r10 ,r12 ,_ P A G E _ U S E R / * U s e r p a g e ? * /
beq 1 f / * n o p e , l e a v e U b i t s e m p t y * /
rlwimi r11 ,r11 ,3 ,2 6 ,2 8 / * y e s , c o p y S b i t s t o U * /
1 : tlbwe r11 ,r13 ,2
/ * Done. . . r e s t o r e r e g i s t e r s a n d g e t o u t o f h e r e .
* /
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 4
mtcr r11
mfspr r13 , S P R N _ S P R G _ R S C R A T C H 3
mfspr r12 , S P R N _ S P R G _ R S C R A T C H 2
mfspr r11 , S P R N _ S P R G _ R S C R A T C H 1
mfspr r10 , S P R N _ S P R G _ R S C R A T C H 0
rfi
# endif / * C O N F I G _ P P C _ 4 7 x * /
/* Debug Interrupt */
/ *
* This s t a t e m e n t n e e d s t o e x i s t a t t h e e n d o f t h e I V P R
* definition j u s t i n c a s e y o u e n d u p t a k i n g a d e b u g
* exception w i t h i n a n o t h e r 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
/ *
* Global f u n c t i o n s
* /
2007-12-21 07:39:21 +03:00
/ *
* Adjust t h e m a c h i n e c h e c k I V O R o n 4 4 0 A c o r e s
* /
_ GLOBAL( _ _ f i x u p _ 4 4 0 A _ m c h e c k )
li r3 ,M a c h i n e C h e c k A @l
mtspr S P R N _ I V O R 1 ,r3
sync
blr
2005-09-26 10:04:21 +04:00
/ *
* extern v o i d g i v e u p _ a l t i v e c ( s t r u c t t a s k _ s t r u c t * p r e v )
*
* The 4 4 x c o r e d o e s n o t h a v e a n A l t i V e c u n i t .
* /
_ GLOBAL( g i v e u p _ a l t i v e c )
blr
/ *
* extern v o i d g i v e u p _ f p u ( s t r u c t t a s k _ s t r u c t * p r e v )
*
* The 4 4 x c o r e d o e s n o t h a v e a n F P U .
* /
# ifndef C O N F I G _ P P C _ F P U
_ GLOBAL( g i v e u p _ f p u )
blr
# endif
_ 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
2010-03-05 13:43:07 +03:00
/ *
* Init C P U s t a t e . T h i s i s c a l l e d a t b o o t t i m e o r f o r s e c o n d a r y C P U s
* to s e t u p i n i t i a l T L B e n t r i e s , s e t u p I V O R s , e t c . . .
2010-03-05 13:43:12 +03:00
*
2010-03-05 13:43:07 +03:00
* /
_ GLOBAL( i n i t _ c p u _ s t a t e )
mflr r22
2010-03-05 13:43:12 +03:00
# ifdef C O N F I G _ P P C _ 4 7 x
/* We use the PVR to differenciate 44x cores from 476 */
mfspr r3 ,S P R N _ P V R
srwi r3 ,r3 ,1 6
2011-12-01 01:39:23 +04:00
cmplwi c r0 ,r3 ,P V R _ 4 7 6 F P E @h
beq h e a d _ s t a r t _ 4 7 x
2010-03-05 13:43:12 +03:00
cmplwi c r0 ,r3 ,P V R _ 4 7 6 @h
beq h e a d _ s t a r t _ 4 7 x
2010-03-05 13:45:54 +03:00
cmplwi c r0 ,r3 ,P V R _ 4 7 6 _ I S S @h
beq h e a d _ s t a r t _ 4 7 x
2010-03-05 13:43:12 +03:00
# endif / * C O N F I G _ P P C _ 4 7 x * /
2010-03-05 13:43:07 +03:00
/ *
* In c a s e t h e f i r m w a r e d i d n ' t d o i t , w e a p p l y s o m e w o r k a r o u n d s
* that a r e g o o d f o r a l l 4 4 0 c o r e v a r i a n t s h e r e
* /
mfspr r3 ,S P R N _ C C R 0
rlwinm r3 ,r3 ,0 ,0 ,2 7 / * d i s a b l e i c a c h e p r e f e t c h * /
isync
mtspr S P R N _ C C R 0 ,r3
isync
sync
/ *
2010-03-05 13:43:12 +03:00
* Set u p t h e i n i t i a l M M U s t a t e f o r 4 4 x
2010-03-05 13:43:07 +03:00
*
* We a r e s t i l l e x e c u t i n g c o d e a t t h e v i r t u a l a d d r e s s
* mappings s e t b y t h e f i r m w a r e f o r t h e b a s e o f R A M .
*
* We f i r s t i n v a l i d a t e a l l T L B e n t r i e s b u t t h e o n e
* we a r e r u n n i n g f r o m . W e t h e n l o a d t h e K E R N E L B A S E
* mappings s o w e c a n b e g i n t o u s e k e r n e l a d d r e s s e s
* natively a n d s o t h e i n t e r r u p t v e c t o r l o c a t i o n s a r e
* permanently p i n n e d ( n e c e s s a r y s i n c e B o o k E
* implementations a l w a y s h a v e t r a n s l a t i o n e n a b l e d ) .
*
* TODO : Use t h e k n o w n T L B e n t r y w e a r e r u n n i n g f r o m t o
* determine w h i c h p h y s i c a l r e g i o n w e a r e l o c a t e d
* in. T h i s c a n b e u s e d t o d e t e r m i n e w h e r e i n R A M
* ( on a s h a r e d C P U s y s t e m ) o r P C I m e m o r y s p a c e
* ( on a D R A M l e s s s y s t e m ) w e a r e l o c a t e d .
* For n o w , w e a s s u m e a p e r f e c t w o r l d w h i c h m e a n s
* we a r e l o c a t e d a t t h e b a s e o f D R A M ( p h y s i c a l 0 ) .
* /
/ *
* Search T L B f o r e n t r y t h a t w e a r e c u r r e n t l y u s i n g .
* Invalidate a l l e n t r i e s b u t t h e o n e w e a r e u s i n g .
* /
/* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
mfspr r3 ,S P R N _ P I D / * G e t P I D * /
mfmsr r4 / * G e t M S R * /
andi. r4 ,r4 ,M S R _ I S @l /* TS=1? */
beq w m m u c r / * I f n o t , l e a v e S T S =0 * /
oris r3 ,r3 ,P P C 4 4 x _ M M U C R _ S T S @h /* Set STS=1 */
wmmucr : mtspr S P R N _ M M U C R ,r3 / * P u t M M U C R * /
sync
bl i n v s t r / * F i n d o u r a d d r e s s * /
invstr : mflr r5 / * M a k e i t a c c e s s i b l e * /
tlbsx r23 ,0 ,r5 / * F i n d e n t r y w e a r e i n * /
li r4 ,0 / * S t a r t a t T L B e n t r y 0 * /
li r3 ,0 / * S e t P A G E I D i n v a l v a l u e * /
1 : cmpw r23 ,r4 / * I s t h i s o u r e n t r y ? * /
beq s k p i n v / * I f s o , s k i p t h e i n v a l * /
tlbwe r3 ,r4 ,P P C 4 4 x _ T L B _ P A G E I D / * I f n o t , i n v a l t h e e n t r y * /
skpinv : addi r4 ,r4 ,1 / * I n c r e m e n t * /
cmpwi r4 ,6 4 / * A r e w e d o n e ? * /
bne 1 b / * I f n o t , r e p e a t * /
isync / * I f s o , c o n t e x t c h a n g e * /
/ *
* Configure a n d l o a d p i n n e d e n t r y i n t o T L B s l o t 6 3 .
* /
lis r3 ,P A G E _ O F F S E T @h
ori r3 ,r3 ,P A G E _ O F F S E T @l
/* Kernel is at the base of RAM */
li r4 , 0 / * L o a d t h e k e r n e l p h y s i c a l a d d r e s s * /
/* Load the kernel PID = 0 */
li r0 ,0
mtspr S P R N _ P I D ,r0
sync
/* Initialize MMUCR */
li r5 ,0
mtspr S P R N _ M M U C R ,r5
sync
/* pageid fields */
clrrwi r3 ,r3 ,1 0 / * M a s k o f f t h e e f f e c t i v e p a g e n u m b e r * /
ori r3 ,r3 ,P P C 4 4 x _ T L B _ V A L I D | P P C 4 4 x _ T L B _ 2 5 6 M
/* xlat fields */
clrrwi r4 ,r4 ,1 0 / * M a s k o f f t h e r e a l p a g e n u m b e r * /
/* ERPN is 0 for first 4GB page */
/* attrib fields */
/* Added guarded bit to protect against speculative loads/stores */
li r5 ,0
ori r5 ,r5 ,( P P C 4 4 x _ T L B _ S W | P P C 4 4 x _ T L B _ S R | P P C 4 4 x _ T L B _ S X | P P C 4 4 x _ T L B _ G )
li r0 ,6 3 / * T L B s l o t 6 3 * /
tlbwe r3 ,r0 ,P P C 4 4 x _ T L B _ P A G E I D / * L o a d t h e p a g e i d f i e l d s * /
tlbwe r4 ,r0 ,P P C 4 4 x _ T L B _ X L A T / * L o a d t h e t r a n s l a t i o n f i e l d s * /
tlbwe r5 ,r0 ,P P C 4 4 x _ T L B _ A T T R I B / * L o a d t h e a t t r i b / a c c e s s f i e l d s * /
/* Force context change */
mfmsr r0
mtspr S P R N _ S R R 1 , r0
lis r0 ,3 f @h
ori r0 ,r0 ,3 f @l
mtspr S P R N _ S R R 0 ,r0
sync
rfi
/* If necessary, invalidate original entry we used */
3 : cmpwi r23 ,6 3
beq 4 f
li r6 ,0
tlbwe r6 ,r23 ,P P C 4 4 x _ T L B _ P A G E I D
isync
4 :
# ifdef C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x
/* Add UART mapping for early debug. */
/* pageid fields */
lis r3 ,P P C 4 4 x _ E A R L Y _ D E B U G _ V I R T A D D R @h
ori r3 ,r3 ,P P C 4 4 x _ T L B _ V A L I D | P P C 4 4 x _ T L B _ T S | P P C 4 4 x _ T L B _ 6 4 K
/* xlat fields */
lis r4 ,C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x _ P H Y S L O W @h
ori r4 ,r4 ,C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x _ P H Y S H I G H
/* attrib fields */
li r5 ,( P P C 4 4 x _ T L B _ S W | P P C 4 4 x _ T L B _ S R | P P C 4 4 x _ T L B _ I | P P C 4 4 x _ T L B _ G )
li r0 ,6 2 / * T L B s l o t 0 * /
tlbwe r3 ,r0 ,P P C 4 4 x _ T L B _ P A G E I D
tlbwe r4 ,r0 ,P P C 4 4 x _ T L B _ X L A T
tlbwe r5 ,r0 ,P P C 4 4 x _ T L B _ A T T R I B
/* Force context change */
isync
# endif / * C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x * /
/* 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 ) ;
2010-03-05 13:43:12 +03:00
SET_ I V O R ( 1 3 , D a t a T L B E r r o r44 x ) ;
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 r44 x ) ;
2010-03-05 13:43:07 +03:00
SET_ I V O R ( 1 5 , D e b u g C r i t ) ;
2010-03-05 13:43:12 +03:00
b h e a d _ s t a r t _ c o m m o n
# ifdef C O N F I G _ P P C _ 4 7 x
# ifdef C O N F I G _ S M P
/* Entry point for secondary 47x processors */
_ GLOBAL( s t a r t _ s e c o n d a r y _ 4 7 x )
mr r24 ,r3 / * C P U n u m b e r * /
bl i n i t _ c p u _ s t a t e
/ * Now w e n e e d t o b o l t t h e r e s t o f k e r n e l m e m o r y w h i c h
* is d o n e i n C c o d e . W e m u s t b e c a r e f u l b e c a u s e o u r t a s k
* struct o r o u r s t a c k c a n ( a n d w i l l p r o b a b l y ) b e o u t
* of r e a c h o f t h e i n i t i a l 2 5 6 M T L B e n t r y , s o w e u s e a
* small t e m p o r a r y s t a c k i n . b s s f o r t h a t . T h i s w o r k s
* because o n l y o n e C P U a t a t i m e c a n b e i n t h i s c o d e
* /
lis r1 ,t e m p _ b o o t _ s t a c k @h
ori r1 ,r1 ,t e m p _ b o o t _ s t a c k @l
addi r1 ,r1 ,1 0 2 4 - 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 )
bl m m u _ i n i t _ s e c o n d a r y
/* Now we can get our task struct and real stack pointer */
/* 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 )
/* Current stack pointer */
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 )
/* Kernel stack for exception entry in SPRG3 */
addi r4 ,r2 ,T H R E A D / * i n i t t a s k ' s T H R E A D * /
mtspr S P R N _ S P R G 3 ,r4
b s t a r t _ s e c o n d a r y
# endif / * C O N F I G _ S M P * /
/ *
* Set u p t h e i n i t i a l M M U s t a t e f o r 4 4 x
*
* We a r e s t i l l e x e c u t i n g c o d e a t t h e v i r t u a l a d d r e s s
* mappings s e t b y t h e f i r m w a r e f o r t h e b a s e o f R A M .
* /
head_start_47x :
/* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
mfspr r3 ,S P R N _ P I D / * G e t P I D * /
mfmsr r4 / * G e t M S R * /
andi. r4 ,r4 ,M S R _ I S @l /* TS=1? */
beq 1 f / * I f n o t , l e a v e S T S =0 * /
oris r3 ,r3 ,P P C 4 7 x _ M M U C R _ S T S @h /* Set STS=1 */
1 : mtspr S P R N _ M M U C R ,r3 / * P u t M M U C R * /
sync
/* Find the entry we are running from */
bl 1 f
1 : mflr r23
tlbsx r23 ,0 ,r23
tlbre r24 ,r23 ,0
tlbre r25 ,r23 ,1
tlbre r26 ,r23 ,2
/ *
* Cleanup t i m e
* /
/* Initialize MMUCR */
li r5 ,0
mtspr S P R N _ M M U C R ,r5
sync
clear_all_utlb_entries :
# ; Set initial values.
addis r3 ,0 ,0 x80 0 0
addi r4 ,0 ,0
addi r5 ,0 ,0
b c l e a r _ u t l b _ e n t r y
# ; Align the loop to speed things up.
.align 6
clear_utlb_entry :
tlbwe r4 ,r3 ,0
tlbwe r5 ,r3 ,1
tlbwe r5 ,r3 ,2
addis r3 ,r3 ,0 x20 0 0
cmpwi r3 ,0
bne c l e a r _ u t l b _ e n t r y
addis r3 ,0 ,0 x80 0 0
addis r4 ,r4 ,0 x10 0
cmpwi r4 ,0
bne c l e a r _ u t l b _ e n t r y
# ; Restore original entry.
oris r23 ,r23 ,0 x80 0 0 / * s p e c i f y t h e w a y * /
tlbwe r24 ,r23 ,0
tlbwe r25 ,r23 ,1
tlbwe r26 ,r23 ,2
/ *
* Configure a n d l o a d p i n n e d e n t r y i n t o T L B f o r t h e k e r n e l c o r e
* /
lis r3 ,P A G E _ O F F S E T @h
ori r3 ,r3 ,P A G E _ O F F S E T @l
/* Load the kernel PID = 0 */
li r0 ,0
mtspr S P R N _ P I D ,r0
sync
/* Word 0 */
clrrwi r3 ,r3 ,1 2 / * M a s k o f f t h e e f f e c t i v e p a g e n u m b e r * /
ori r3 ,r3 ,P P C 4 7 x _ T L B 0 _ V A L I D | P P C 4 7 x _ T L B 0 _ 2 5 6 M
2011-07-04 22:36:57 +04:00
/* Word 1 - use r25. RPN is the same as the original entry */
2010-03-05 13:43:12 +03:00
/* Word 2 */
li r5 ,0
ori r5 ,r5 ,P P C 4 7 x _ T L B 2 _ S _ R W X
# ifdef C O N F I G _ S M P
ori r5 ,r5 ,P P C 4 7 x _ T L B 2 _ M
# endif
/* We write to way 0 and bolted 0 */
lis r0 ,0 x88 0 0
tlbwe r3 ,r0 ,0
2011-07-04 22:36:57 +04:00
tlbwe r25 ,r0 ,1
2010-03-05 13:43:12 +03:00
tlbwe r5 ,r0 ,2
/ *
* Configure S S P C R , I S P C R a n d U S P C R f o r n o w t o s e a r c h e v e r y t h i n g , w e c a n f i x
* them u p l a t e r
* /
LOAD_ R E G _ I M M E D I A T E ( r3 , 0 x9 a b c d e f0 )
mtspr S P R N _ S S P C R ,r3
mtspr S P R N _ U S P C R ,r3
LOAD_ R E G _ I M M E D I A T E ( r3 , 0 x12 3 4 5 6 7 0 )
mtspr S P R N _ I S P C R ,r3
/* Force context change */
mfmsr r0
mtspr S P R N _ S R R 1 , r0
lis r0 ,3 f @h
ori r0 ,r0 ,3 f @l
mtspr S P R N _ S R R 0 ,r0
sync
rfi
/* Invalidate original entry we used */
3 :
rlwinm r24 ,r24 ,0 ,2 1 ,1 9 / * c l e a r t h e " v a l i d " b i t * /
tlbwe r24 ,r23 ,0
addi r24 ,0 ,0
tlbwe r24 ,r23 ,1
tlbwe r24 ,r23 ,2
isync / * C l e a r o u t t h e s h a d o w T L B e n t r i e s * /
# ifdef C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x
/* Add UART mapping for early debug. */
/* Word 0 */
lis r3 ,P P C 4 4 x _ E A R L Y _ D E B U G _ V I R T A D D R @h
ori r3 ,r3 ,P P C 4 7 x _ T L B 0 _ V A L I D | P P C 4 7 x _ T L B 0 _ T S | P P C 4 7 x _ T L B 0 _ 1 M
/* Word 1 */
lis r4 ,C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x _ P H Y S L O W @h
ori r4 ,r4 ,C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x _ P H Y S H I G H
/* Word 2 */
li r5 ,( P P C 4 7 x _ T L B 2 _ S _ R W | P P C 4 7 x _ T L B 2 _ I M G )
/ * Bolted i n w a y 0 , b o l t s l o t 5 , w e - h o p e - w e d o n ' t h i t t h e s a m e
* congruence c l a s s a s t h e k e r n e l , w e n e e d t o m a k e s u r e o f i t a t
* some p o i n t
* /
lis r0 ,0 x8 d00
tlbwe r3 ,r0 ,0
tlbwe r4 ,r0 ,1
tlbwe r5 ,r0 ,2
/* Force context change */
isync
# endif / * C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x * /
/* 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 A ) ;
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 r47 x ) ;
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 r47 x ) ;
SET_ I V O R ( 1 5 , D e b u g C r i t ) ;
/ * We c o n f i g u r e i c b i t o i n v a l i d a t e 1 2 8 b y t e s a t a t i m e s i n c e t h e
* current 3 2 - b i t k e r n e l c o d e i s n ' t t o o h a p p y w i t h i c a c h e ! = d c a c h e
* block s i z e
* /
mfspr r3 ,S P R N _ C C R 0
oris r3 ,r3 ,0 x00 2 0
mtspr S P R N _ C C R 0 ,r3
isync
# endif / * C O N F I G _ P P C _ 4 7 x * /
/ *
* Here w e a r e b a c k t o c o d e t h a t i s c o m m o n b e t w e e n 4 4 x a n d 4 7 x
*
* We p r o c e e d t o f u r t h e r k e r n e l i n i t i a l i z a t i o n a n d r e t u r n t o t h e
* main k e r n e l e n t r y
* /
head_start_common :
2010-03-05 13:43:07 +03: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
2011-07-04 22:36:57 +04:00
/ *
* If t h e k e r n e l w a s l o a d e d a t a n o n - z e r o 2 5 6 M B p a g e , w e n e e d t o
* mask o f f t h e m o s t s i g n i f i c a n t 4 b i t s t o g e t t h e r e l a t i v e a d d r e s s
* from t h e s t a r t o f p h y s i c a l m e m o r y
* /
rlwinm r22 ,r22 ,0 ,4 ,3 1
addis r22 ,r22 ,P A G E _ O F F S E T @h
2010-03-05 13:43:07 +03:00
mtlr r22
2010-03-05 13:43:12 +03:00
isync
2010-03-05 13:43:07 +03:00
blr
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
2008-12-11 04:55:41 +03:00
.align PAGE_SHIFT
2005-10-12 08:54:00 +04:00
.globl sdata
sdata :
.globl empty_zero_page
empty_zero_page :
2008-12-11 04:55:41 +03:00
.space PAGE_SIZE
2005-09-26 10:04:21 +04:00
/ *
* To s u p p o r t > 3 2 - b i t p h y s i c a l a d d r e s s e s , w e u s e a n 8 K B p g d i r .
* /
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
2010-03-05 13:43:12 +03:00
# ifdef C O N F I G _ S M P
.align 12
temp_boot_stack :
.space 1024
# endif / * C O N F I G _ S M P * /