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 .
* /
# 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 >
# 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
*
* /
2007-09-14 00:42:35 +04:00
.section .text .head , " ax"
_ 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
/ *
* Save p a r a m e t e r s w e a r e p a s s e d
* /
mr r31 ,r3
mr r30 ,r4
mr r29 ,r5
mr r28 ,r6
mr r27 ,r7
li r24 ,0 / * C P U n u m b e r * /
/ *
* Set u p t h e i n i t i a l M M U s t a t e
*
* 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 .
* /
2007-04-30 08:06:25 +04:00
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
2005-09-26 10:04:21 +04:00
/* 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 :
2007-05-08 06:59:31 +04:00
# 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. */
2005-09-26 10:04:21 +04:00
/* pageid fields */
2007-05-08 06:59:31 +04:00
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
2005-09-26 10:04:21 +04:00
/* xlat fields */
2007-05-08 06:59:31 +04:00
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
2005-09-26 10:04:21 +04:00
/* attrib fields */
2007-05-08 06:59:31 +04:00
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 * /
2005-09-26 10:04:21 +04:00
2007-05-08 06:59:31 +04:00
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
2005-09-26 10:04:21 +04:00
/* Force context change */
isync
2007-05-08 06:59:31 +04:00
# endif / * C O N F I G _ P P C _ E A R L Y _ D E B U G _ 4 4 x * /
2005-09-26 10:04:21 +04:00
/* Establish the interrupt vector offsets */
SET_ I V O R ( 0 , C r i t i c a l I n p u t ) ;
SET_ I V O R ( 1 , M a c h i n e C h e c k ) ;
SET_ I V O R ( 2 , D a t a S t o r a g e ) ;
SET_ I V O R ( 3 , I n s t r u c t i o n S t o r a g e ) ;
SET_ I V O R ( 4 , E x t e r n a l I n p u t ) ;
SET_ I V O R ( 5 , A l i g n m e n t ) ;
SET_ I V O R ( 6 , P r o g r a m ) ;
SET_ I V O R ( 7 , F l o a t i n g P o i n t U n a v a i l a b l e ) ;
SET_ I V O R ( 8 , S y s t e m C a l l ) ;
SET_ I V O R ( 9 , A u x i l l a r y P r o c e s s o r U n a v a i l a b l e ) ;
SET_ I V O R ( 1 0 , D e c r e m e n t e r ) ;
SET_ I V O R ( 1 1 , F i x e d I n t e r v a l T i m e r ) ;
SET_ I V O R ( 1 2 , W a t c h d o g T i m e r ) ;
SET_ I V O R ( 1 3 , D a t a T L B E r r o r ) ;
SET_ I V O R ( 1 4 , I n s t r u c t i o n T L B E r r o r ) ;
SET_ I V O R ( 1 5 , D e b u g ) ;
/* 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
/ *
* 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 * /
mtspr S P R N _ S P R G 3 ,r4
/* 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
/ *
* 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 .
* /
mr r3 ,r31
mr r4 ,r30
mr r5 ,r29
mr r6 ,r28
mr r7 ,r27
bl m a c h i n e _ i n i t
bl M M U _ i n i t
/* Setup PTE pointers for the Abatron bdiGDB */
lis r6 , s w a p p e r _ p g _ d i r @h
ori r6 , r6 , s w a p p e r _ p g _ d i r @l
lis r5 , a b a t r o n _ p t e p t r s @h
ori r5 , r5 , a b a t r o n _ p t e p t r s @l
lis r4 , K E R N E L B A S E @h
ori r4 , r4 , K E R N E L B A S E @l
stw r5 , 0 ( r4 ) / * S a v e a b a t r o n _ p t e p t r s a t a f i x e d l o c a t i o n * /
stw r6 , 0 ( r5 )
/* Let's move on */
lis r4 ,s t a r t _ k e r n e l @h
ori r4 ,r4 ,s t a r t _ k e r n e l @l
lis r3 ,M S R _ K E R N E L @h
ori r3 ,r3 ,M S R _ K E R N E L @l
mtspr S P R N _ S R R 0 ,r4
mtspr S P R N _ S R R 1 ,r3
rfi / * c h a n g e c o n t e x t a n d j u m p t o s t a r t _ k e r n e l * /
/ *
* 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 */
# ifdef C O N F I G _ 4 4 0 A
2005-10-01 12:43:42 +04:00
MCHECK_ E X C E P T I O N ( 0 x02 0 0 , M a c h i n e C h e c k , m a c h i n e _ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
# else
2005-10-01 12:43:42 +04:00
CRITICAL_ E X C E P T I O N ( 0 x02 0 0 , M a c h i n e C h e c k , m a c h i n e _ c h e c k _ e x c e p t i o n )
2005-09-26 10:04:21 +04:00
# endif
/* Data Storage Interrupt */
START_ E X C E P T I O N ( D a t a S t o r a g e )
mtspr S P R N _ S P R G 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 1 , r11
mtspr S P R N _ S P R G 4 W , r12
mtspr S P R N _ S P R G 5 W , r13
mfcr r11
mtspr S P R N _ S P R G 7 W , r11
/ *
* Check i f i t w a s a s t o r e f a u l t , i f n o t t h e n b a i l
* because a u s e r t r i e d t o a c c e s s a k e r n e l o r
* read- p r o t e c t e d p a g e . O t h e r w i s e , g e t t h e
* offending a d d r e s s a n d h a n d l e i t .
* /
mfspr r10 , S P R N _ E S R
andis. r10 , r10 , E S R _ S T @h
beq 2 f
mfspr r10 , S P R N _ D E A R / * G e t f a u l t i n g a d d r e s s * /
/ * If w e a r e f a u l t i n g a k e r n e l a d d r e s s , w e h a v e t o u s e t h e
* kernel p a g e t a b l e s .
* /
2007-10-11 22:36:52 +04:00
lis r11 , P A G E _ O F F S E T @h
2005-09-26 10:04:21 +04:00
cmplw r10 , r11
blt+ 3 f
lis r11 , s w a p p e r _ p g _ d i r @h
ori r11 , r11 , s w a p p e r _ p g _ d i r @l
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 :
mfspr r11 ,S P R N _ S P R G 3
lwz r11 ,P G D I R ( r11 )
/* Load PID into MMUCR TID */
mfspr r12 ,S P R N _ M M U C R / * G e t 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
rlwinm r12 , r10 , 1 3 , 1 9 , 2 9 / * C o m p u t e p g d i r / p m d o f f s e t * /
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 * /
rlwimi r12 , r10 , 2 3 , 2 0 , 2 8 / * C o m p u t e p t e a d d r e s s * /
lwz r11 , 4 ( r12 ) / * G e t p t e e n t r y * /
andi. r13 , r11 , _ P A G E _ R W / * I s i t w r i t e a b l e ? * /
beq 2 f / * B a i l i f n o t * /
/ * Update ' c h a n g e d ' .
* /
ori r11 , r11 , _ P A G E _ D I R T Y | _ P A G E _ A C C E S S E D | _ P A G E _ H W W R I T E
stw r11 , 4 ( r12 ) / * U p d a t e L i n u x p a g e t a b l e * /
li r13 , P P C 4 4 x _ T L B _ S R @l /* Set SR */
rlwimi r13 , r11 , 2 9 , 2 9 , 2 9 / * S X = _ P A G E _ H W E X E C * /
rlwimi r13 , r11 , 0 , 3 0 , 3 0 / * S W = _ P A G E _ R W * /
rlwimi r13 , r11 , 2 9 , 2 8 , 2 8 / * U R = _ P A G E _ U S E R * /
rlwimi r12 , r11 , 3 1 , 2 6 , 2 6 / * ( _ P A G E _ U S E R > > 1 ) - > r12 * /
rlwimi r12 , r11 , 2 9 , 3 0 , 3 0 / * ( _ P A G E _ U S E R > > 3 ) - > r12 * /
and r12 , r12 , r11 / * H W E X E C / R W & U S E R * /
rlwimi r13 , r12 , 0 , 2 6 , 2 6 / * U X = H W E X E C & U S E R * /
rlwimi r13 , r12 , 3 , 2 7 , 2 7 / * U W = R W & U S E R * /
rlwimi r11 ,r13 ,0 ,2 6 ,3 1 / * I n s e r t s t a t i c p e r m s * /
rlwinm r11 ,r11 ,0 ,2 0 ,1 5 / * C l e a r U 0 - U 3 * /
/* find the TLB index that caused the fault. It has to be here. */
tlbsx r10 , 0 , r10
tlbwe r11 , r10 , 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 * /
/ * 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 7 R
mtcr r11
mfspr r13 , S P R N _ S P R G 5 R
mfspr r12 , S P R N _ S P R G 4 R
mfspr r11 , S P R N _ S P R G 1
mfspr r10 , S P R N _ S P R G 0
rfi / * F o r c e c o n t e x t c h a n g e * /
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 7 R
mtcr r11
mfspr r13 , S P R N _ S P R G 5 R
mfspr r12 , S P R N _ S P R G 4 R
mfspr r11 , S P R N _ S P R G 1
mfspr r10 , S P R N _ S P R G 0
b d a t a _ a c c e s s
/* Instruction Storage Interrupt */
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 )
/* Auxillary 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 */
START_ E X C E P T I O N ( D a t a T L B E r r o r )
mtspr S P R N _ S P R G 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 1 , r11
mtspr S P R N _ S P R G 4 W , r12
mtspr S P R N _ S P R G 5 W , r13
mfcr r11
mtspr S P R N _ S P R G 7 W , 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 .
* /
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 :
mfspr r11 ,S P R N _ S P R G 3
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
rlwinm r12 , r10 , 1 3 , 1 9 , 2 9 / * C o m p u t e p g d i r / p m d o f f s e t * /
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 * /
rlwimi r12 , r10 , 2 3 , 2 0 , 2 8 / * C o m p u t e p t e a d d r e s s * /
lwz r11 , 4 ( r12 ) / * G e t p t e e n t r y * /
andi. r13 , r11 , _ P A G E _ P R E S E N T / * I s t h e p a g e p r e s e n t ? * /
beq 2 f / * B a i l i f n o t p r e s e n t * /
ori r11 , r11 , _ P A G E _ A C C E S S E D
stw r11 , 4 ( r12 )
/* Jump to common tlb load */
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 .
* /
mfspr r11 , S P R N _ S P R G 7 R
mtcr r11
mfspr r13 , S P R N _ S P R G 5 R
mfspr r12 , S P R N _ S P R G 4 R
mfspr r11 , S P R N _ S P R G 1
mfspr r10 , S P R N _ S P R G 0
b d a t a _ a c c e s s
/* 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 )
mtspr S P R N _ S P R G 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 1 , r11
mtspr S P R N _ S P R G 4 W , r12
mtspr S P R N _ S P R G 5 W , r13
mfcr r11
mtspr S P R N _ S P R G 7 W , 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 .
* /
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 :
mfspr r11 ,S P R N _ S P R G 3
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
rlwinm r12 , r10 , 1 3 , 1 9 , 2 9 / * C o m p u t e p g d i r / p m d o f f s e t * /
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 * /
rlwimi r12 , r10 , 2 3 , 2 0 , 2 8 / * C o m p u t e p t e a d d r e s s * /
lwz r11 , 4 ( r12 ) / * G e t p t e e n t r y * /
andi. r13 , r11 , _ P A G E _ P R E S E N T / * I s t h e p a g e p r e s e n t ? * /
beq 2 f / * B a i l i f n o t p r e s e n t * /
ori r11 , r11 , _ P A G E _ A C C E S S E D
stw r11 , 4 ( r12 )
/* 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 .
* /
mfspr r11 , S P R N _ S P R G 7 R
mtcr r11
mfspr r13 , S P R N _ S P R G 5 R
mfspr r12 , S P R N _ S P R G 4 R
mfspr r11 , S P R N _ S P R G 1
mfspr r10 , S P R N _ S P R G 0
b I n s t r u c t i o n S t o r a g e
/* Debug Interrupt */
DEBUG_ E X C E P T I O N
/ *
* Local f u n c t i o n s
* /
/ *
* Data T L B e x c e p t i o n s w i l l b a i l o u t t o t h i s p o i n t
* if t h e y c a n ' t r e s o l v e t h e l i g h t w e i g h t T L B f a u l t .
* /
data_access :
NORMAL_ E X C E P T I O N _ P R O L O G
mfspr r5 ,S P R N _ E S R / * G r a b t h e E S R , s a v e i t , p a s s a r g 3 * /
stw r5 ,_ E S R ( r11 )
mfspr r4 ,S P R N _ D E A R / * G r a b t h e D E A R , s a v e i t , p a s s a r g 2 * /
EXC_ X F E R _ E E _ L I T E ( 0 x03 0 0 , h a n d l e _ p a g e _ f a u l t )
/ *
* 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
* r1 1 - a v a i l a b l e t o u s e
* r1 2 - P o i n t e r t o t h e 6 4 - b i t P T E
* r1 3 - a v a i l a b l 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 :
/ *
* We s e t e x e c u t e , b e c a u s e w e d o n ' t h a v e t h e g r a n u l a r i t y t o
* properly s e t t h i s a t t h e p a g e l e v e l ( L i n u x p r o b l e m ) .
* If s h a r e d i s s e t , w e c a u s e a z e r o P I D - > T I D l o a d .
* Many o f t h e s e b i t s a r e s o f t w a r e o n l y . B i t s w e d o n ' t s e t
* here w e ( p r o p e r l y s h o u l d ) a s s u m e h a v e t h e a p p r o p r i a t e v a l u e .
* /
/* Load the next available TLB index */
lis r13 , t l b _ 4 4 x _ i n d e x @ha
lwz r13 , t l b _ 4 4 x _ i n d e x @l(r13)
/* Load the TLB high watermark */
lis r11 , t l b _ 4 4 x _ h w a t e r @ha
lwz r11 , t l b _ 4 4 x _ h w a t e r @l(r11)
/* Increment, rollover, and store TLB index */
addi r13 , r13 , 1
cmpw 0 , r13 , r11 / * r e s e r v e e n t r i e s * /
ble 7 f
li r13 , 0
7 :
/* Store the next available TLB index */
lis r11 , t l b _ 4 4 x _ i n d e x @ha
stw r13 , t l b _ 4 4 x _ i n d e x @l(r11)
lwz r11 , 0 ( r12 ) / * G e t M S w o r d o f P T E * /
lwz r12 , 4 ( r12 ) / * G e t L S w o r d o f P T E * /
rlwimi r11 , r12 , 0 , 0 , 1 9 / * I n s e r t R P N * /
tlbwe r11 , r13 , P P C 4 4 x _ T L B _ X L A T / * W r i t e X L A T * /
/ *
* Create P A G E I D . T h i s i s t h e f a u l t i n g a d d r e s s ,
* page s i z e , a n d v a l i d f l a g .
* /
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 _ 4 K
rlwimi r10 , r11 , 0 , 2 0 , 3 1 / * I n s e r t v a l i d a n d p a g e s i z e * /
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 * /
li r10 , P P C 4 4 x _ T L B _ S R @l /* Set SR */
rlwimi r10 , r12 , 0 , 3 0 , 3 0 / * S e t S W = _ P A G E _ R W * /
rlwimi r10 , r12 , 2 9 , 2 9 , 2 9 / * S X = _ P A G E _ H W E X E C * /
rlwimi r10 , r12 , 2 9 , 2 8 , 2 8 / * U R = _ P A G E _ U S E R * /
rlwimi r11 , r12 , 3 1 , 2 6 , 2 6 / * ( _ P A G E _ U S E R > > 1 ) - > r12 * /
and r11 , r12 , r11 / * H W E X E C & U S E R * /
rlwimi r10 , r11 , 0 , 2 6 , 2 6 / * U X = H W E X E C & U S E R * /
rlwimi r12 , r10 , 0 , 2 6 , 3 1 / * I n s e r t s t a t i c p e r m s * /
rlwinm r12 , r12 , 0 , 2 0 , 1 5 / * C l e a r U 0 - U 3 * /
tlbwe r12 , 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 * /
/ * 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 7 R
mtcr r11
mfspr r13 , S P R N _ S P R G 5 R
mfspr r12 , S P R N _ S P R G 4 R
mfspr r11 , S P R N _ S P R G 1
mfspr r10 , S P R N _ S P R G 0
rfi / * F o r c e c o n t e x t c h a n g e * /
/ *
* Global f u n c t i o n s
* /
/ *
* 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
/ *
* We p u t a f e w t h i n g s h e r e t h a t h a v e t o b e p a g e - a l i g n e d . T h i s s t u f f
* goes a t t h e b e g i n n i n g o f t h e d a t a s e g m e n t , w h i c h i s p a g e - a l i g n e d .
* /
.data
2005-10-12 08:54:00 +04:00
.align 12
.globl sdata
sdata :
.globl empty_zero_page
empty_zero_page :
2005-09-26 10:04:21 +04:00
.space 4096
/ *
* 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
/ * Reserved 4 k f o r t h e c r i t i c a l e x c e p t i o n s t a c k & 4 k f o r t h e m a c h i n e
* check s t a c k p e r C P U f o r k e r n e l m o d e e x c e p t i o n s * /
.section .bss
.align 12
exception_stack_bottom :
.space BOOKE_EXCEPTION_STACK_SIZE
2005-10-12 08:54:00 +04:00
.globl exception_stack_top
exception_stack_top :
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