2009-03-27 14:25:20 +01:00
/ *
* Copyright ( C ) 2 0 0 7 - 2 0 0 9 M i c h a l S i m e k < m o n s t r @monstr.eu>
* Copyright ( C ) 2 0 0 7 - 2 0 0 9 P e t a L o g i x
* Copyright ( C ) 2 0 0 6 A t m a r k T e c h n o , I n c .
*
2009-05-26 16:30:09 +02:00
* MMU c o d e d e r i v e d f r o m a r c h / p p c / k e r n e l / h e a d _ 4 x x . S :
* 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
*
2009-03-27 14:25:20 +01:00
* This f i l e i s s u b j e c t t o t h e t e r m s a n d c o n d i t i o n s o f t h e G N U G e n e r a l P u b l i c
* License. S e e t h e f i l e " C O P Y I N G " i n t h e m a i n d i r e c t o r y o f t h i s a r c h i v e
* for m o r e d e t a i l s .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p a g e . h >
2009-05-26 16:30:09 +02:00
# ifdef C O N F I G _ M M U
# include < a s m / s e t u p . h > / * C O M M A N D _ L I N E _ S I Z E * /
# include < a s m / m m u . h >
# include < a s m / p r o c e s s o r . h >
.data
.global empty_zero_page
.align 12
empty_zero_page :
.space 4096
.global swapper_pg_dir
swapper_pg_dir :
.space 4096
# endif / * C O N F I G _ M M U * /
2009-03-27 14:25:20 +01:00
.text
ENTRY( _ s t a r t )
mfs r1 , r m s r
andi r1 , r1 , ~ 2
mts r m s r , r1
/* save fdt to kernel location */
/* r7 stores pointer to fdt blob */
beqi r7 , n o _ f d t _ a r g
or r11 , r0 , r0 / * i n c r e m m e n t * /
ori r4 , r0 , T O P H Y S ( _ f d t _ s t a r t ) / * s a v e b r a m c o n t e x t * /
ori r3 , r0 , ( 0 x40 0 0 - 4 )
_copy_fdt :
lw r12 , r7 , r11 / * r12 = r7 + r11 * /
sw r12 , r4 , r11 / * a d d r [ r4 + r11 ] = r12 * /
addik r11 , r11 , 4 / * i n c r e m e n t c o u n t i n g * /
bgtid r3 , _ c o p y _ f d t / * l o o p f o r a l l e n t r i e s * /
addik r3 , r3 , - 4 / * d e s c r e m e n t l o o p * /
no_fdt_arg :
2009-05-26 16:30:09 +02:00
# ifdef C O N F I G _ M M U
# ifndef C O N F I G _ C M D L I N E _ B O O L
/ *
* handling c o m m a n d l i n e
* copy c o m m a n d l i n e t o _ _ i n i t _ e n d . T h e r e i s s p a c e f o r s t o r i n g c o m m a n d l i n e .
* /
or r6 , r0 , r0 / * i n c r e m m e n t * /
ori r4 , r0 , _ _ i n i t _ e n d / * l o a d a d d r e s s o f c o m m a n d l i n e * /
tophys( r4 ,r4 ) / * c o n v e r t t o p h y s a d d r e s s * /
ori r3 , r0 , C O M M A N D _ L I N E _ S I Z E - 1 / * n u m b e r o f l o o p s * /
_copy_command_line :
lbu r7 , r5 , r6 / * r7 =r5 + r6 - r5 c o n t a i n p o i n t e r t o c o m m a n d l i n e * /
sb r7 , r4 , r6 / * a d d r [ r4 + r6 ] = r7 * /
addik r6 , r6 , 1 / * i n c r e m e n t c o u n t i n g * /
bgtid r3 , _ c o p y _ c o m m a n d _ l i n e / * l o o p f o r a l l e n t r i e s * /
addik r3 , r3 , - 1 / * d e s c r e m e n t l o o p * /
addik r5 , r4 , 0 / * a d d n e w s p a c e f o r c o m m a n d l i n e * /
tovirt( r5 ,r5 )
# endif / * C O N F I G _ C M D L I N E _ B O O L * /
# ifdef N O T _ C O M P I L E
/* save bram context */
or r6 , r0 , r0 / * i n c r e m m e n t * /
ori r4 , r0 , T O P H Y S ( _ b r a m _ l o a d _ s t a r t ) / * s a v e b r a m c o n t e x t * /
ori r3 , r0 , ( L M B _ S I Z E - 4 )
_copy_bram :
lw r7 , r0 , r6 / * r7 = r0 + r6 * /
sw r7 , r4 , r6 / * a d d r [ r4 + r6 ] = r7 * /
addik r6 , r6 , 4 / * i n c r e m e n t c o u n t i n g * /
bgtid r3 , _ c o p y _ b r a m / * l o o p f o r a l l e n t r i e s * /
addik r3 , r3 , - 4 / * d e s c r e m e n t l o o p * /
# endif
/* We have to turn on the MMU right away. */
/ *
* Set u p t h e i n i t i a l M M U s t a t e s o w e c a n d o t h e f i r s t l e v e l o f
* kernel i n i t i a l i z a t i o n . T h i s m a p s t h e f i r s t 1 6 M B y t e s o f m e m o r y 1 : 1
* virtual t o p h y s i c a l .
* /
nop
addik r3 , r0 , 6 3 / * I n v a l i d a t e a l l T L B e n t r i e s * /
_invalidate :
mts r t l b x , r3
mts r t l b h i , r0 / * f l u s h : e n s u r e V i s c l e a r * /
bgtid r3 , _ i n v a l i d a t e / * l o o p f o r a l l e n t r i e s * /
addik r3 , r3 , - 1
/* sync */
/ *
* We s h o u l d s t i l l b e e x e c u t i n g c o d e a t p h y s i c a l a d d r e s s a r e a
* RAM_ B A S E A D D R a t t h i s p o i n t . H o w e v e r , k e r n e l c o d e i s a t
* a v i r t u a l a d d r e s s . S o , s e t u p a T L B m a p p i n g t o c o v e r t h i s o n c e
* translation i s e n a b l e d .
* /
addik r3 ,r0 , C O N F I G _ K E R N E L _ S T A R T / * L o a d t h e k e r n e l v i r t u a l a d d r e s s * /
tophys( r4 ,r3 ) / * 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 * /
mts r p i d ,r0 / * L o a d t h e k e r n e l P I D * /
nop
bri 4
/ *
* Configure a n d l o a d t w o e n t r i e s i n t o T L B s l o t s 0 a n d 1 .
* In c a s e w e a r e p i n n i n g T L B s , t h e s e a r e r e s e r v e d i n b y t h e
* other T L B f u n c t i o n s . I f n o t r e s e r v i n g , t h e n i t d o e s n ' t
* matter w h e r e t h e y a r e l o a d e d .
* /
andi r4 ,r4 ,0 x f f f f f c00 / * M a s k o f f t h e r e a l p a g e n u m b e r * /
ori r4 ,r4 ,( T L B _ W R | T L B _ E X ) / * S e t t h e w r i t e a n d e x e c u t e b i t s * /
andi r3 ,r3 ,0 x f f f f f c00 / * 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 ,( T L B _ V A L I D | T L B _ P A G E S Z ( P A G E S Z _ 1 6 M ) )
mts r t l b x ,r0 / * T L B s l o w 0 * /
mts r t l b l o ,r4 / * L o a d t h e d a t a p o r t i o n o f t h e e n t r y * /
mts r t l b h i ,r3 / * L o a d t h e t a g p o r t i o n o f t h e e n t r y * /
addik r4 , r4 , 0 x01 0 0 0 0 0 0 / * M a p n e x t 1 6 M e n t r i e s * /
addik r3 , r3 , 0 x01 0 0 0 0 0 0
ori r6 ,r0 ,1 / * T L B s l o t 1 * /
mts r t l b x ,r6
mts r t l b l o ,r4 / * L o a d t h e d a t a p o r t i o n o f t h e e n t r y * /
mts r t l b h i ,r3 / * L o a d t h e t a g p o r t i o n o f t h e e n t r y * /
/ *
* Load a T L B e n t r y f o r L M B , s i n c e w e n e e d a c c e s s t o
* the e x c e p t i o n v e c t o r s , u s i n g a 4 k r e a l = =virtual m a p p i n g .
* /
ori r6 ,r0 ,3 / * T L B s l o t 3 * /
mts r t l b x ,r6
ori r4 ,r0 ,( T L B _ W R | T L B _ E X )
ori r3 ,r0 ,( T L B _ V A L I D | T L B _ P A G E S Z ( P A G E S Z _ 4 K ) )
mts r t l b l o ,r4 / * L o a d t h e d a t a p o r t i o n o f t h e e n t r y * /
mts r t l b h i ,r3 / * L o a d t h e t a g p o r t i o n o f t h e e n t r y * /
/ *
* We n o w h a v e t h e l o w e r 1 6 M e g o f R A M m a p p e d i n t o T L B e n t r i e s , a n d t h e
* caches r e a d y t o w o r k .
* /
turn_on_mmu :
ori r15 ,r0 ,s t a r t _ h e r e
ori r4 ,r0 ,M S R _ K E R N E L _ V M S
mts r m s r ,r4
nop
rted r15 ,0 / * e n a b l e s M M U * /
nop
start_here :
# endif / * C O N F I G _ M M U * /
2009-03-27 14:25:20 +01:00
/* Initialize small data anchors */
la r13 , r0 , _ K E R N E L _ S D A _ B A S E _
la r2 , r0 , _ K E R N E L _ S D A 2 _ B A S E _
/* Initialize stack pointer */
la r1 , r0 , i n i t _ t h r e a d _ u n i o n + T H R E A D _ S I Z E - 4
/* Initialize r31 with current task address */
la r31 , r0 , i n i t _ t a s k
/ *
* Call p l a t f o r m d e p e n d e n t i n i t i a l i z e f u n c t i o n .
* Please s e e $ ( A R C H ) / m a c h - $ ( S U B A R C H ) / s e t u p . c f o r
* the f u n c t i o n .
* /
la r8 , r0 , m a c h i n e _ e a r l y _ i n i t
brald r15 , r8
nop
2009-05-26 16:30:09 +02:00
# ifndef C O N F I G _ M M U
2009-03-27 14:25:20 +01:00
la r15 , r0 , m a c h i n e _ h a l t
braid s t a r t _ k e r n e l
nop
2009-05-26 16:30:09 +02:00
# else
/ *
* Initialize t h e M M U .
* /
bralid r15 , m m u _ i n i t
nop
/ * Go b a c k t o r u n n i n g u n m a p p e d s o w e c a n l o a d u p n e w v a l u e s
* and c h a n g e t o u s i n g o u r e x c e p t i o n v e c t o r s .
* On t h e M i c r o B l a z e , a l l w e i n v a l i d a t e t h e u s e d T L B e n t r i e s t o c l e a r
* the o l d 1 6 M b y t e T L B m a p p i n g s .
* /
ori r15 ,r0 ,T O P H Y S ( k e r n e l _ l o a d _ c o n t e x t )
ori r4 ,r0 ,M S R _ K E R N E L
mts r m s r ,r4
nop
bri 4
rted r15 ,0
nop
/* Load up the kernel context */
kernel_load_context :
# Keep e n t r y 0 a n d 1 v a l i d . E n t r y 3 m a p p e d t o L M B c a n g o a w a y .
ori r5 ,r0 ,3
mts r t l b x ,r5
nop
mts r t l b h i ,r0
nop
addi r15 , r0 , m a c h i n e _ h a l t
ori r17 , r0 , s t a r t _ k e r n e l
ori r4 , r0 , M S R _ K E R N E L _ V M S
mts r m s r , r4
nop
rted r17 , 0 / * e n a b l e M M U a n d j u m p t o s t a r t _ k e r n e l * /
nop
# endif / * C O N F I G _ M M U * /