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 .
* /
2010-04-09 22:03:37 -05:00
# include < l i n u x / i n i t . h >
2009-03-27 14:25:20 +01:00
# 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-10-15 10:57:53 -06:00
# include < l i n u x / o f _ f d t . h > / * f o r O F _ D T _ H E A D E R * /
2009-03-27 14:25:20 +01:00
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 :
2010-05-13 10:48:27 -05:00
.space PAGE_SIZE
2009-05-26 16:30:09 +02:00
.global swapper_pg_dir
swapper_pg_dir :
2010-05-13 10:48:27 -05:00
.space PAGE_SIZE
2009-05-26 16:30:09 +02:00
# endif / * C O N F I G _ M M U * /
2010-04-09 22:03:37 -05:00
_ _ HEAD
2009-03-27 14:25:20 +01:00
ENTRY( _ s t a r t )
2010-03-15 08:48:27 +01:00
# if C O N F I G _ K E R N E L _ B A S E _ A D D R = = 0
brai T O P H Y S ( r e a l _ s t a r t )
.org 0x100
real_start :
# endif
2009-03-27 14:25:20 +01:00
mfs r1 , r m s r
andi r1 , r1 , ~ 2
mts r m s r , r1
2009-07-30 14:31:23 +02:00
/ *
2011-02-04 15:24:11 +01:00
* According t o X i l i n x , m s r c l r i n s t r u c t i o n b e h a v e s l i k e ' m f s r X ,r p c '
* if t h e m s r c l r i n s t r u c t i o n i s n o t e n a b l e d . W e u s e t h i s t o d e t e c t
* if t h e o p c o d e i s a v a i l a b l e , b y i s s u i n g m s r c l r a n d t h e n t e s t i n g t h e r e s u l t .
* r8 = = 0 - m s r i n s t r u c t i o n s a r e i m p l e m e n t e d
* r8 ! = 0 - m s r i n s t r u c t i o n s a r e n o t i m p l e m e n t e d
2009-07-30 14:31:23 +02:00
* /
2011-02-04 15:24:11 +01:00
msrclr r8 , 0 / * c l e a r n o t h i n g - j u s t r e a d m s r f o r t e s t * /
cmpu r8 , r8 , r1 / * r1 m u s t c o n t a i n m s r r e g c o n t e n t * /
2009-07-30 14:31:23 +02:00
2009-06-22 14:02:09 +10:00
/ * r7 m a y p o i n t t o a n F D T , o r t h e r e m a y b e o n e l i n k e d i n .
if i t ' s i n r7 , w e ' v e g o t t o s a v e i t a w a y A S A P .
We e n s u r e r7 p o i n t s t o a v a l i d F D T , j u s t i n c a s e t h e b o o t l o a d e r
is b r o k e n o r n o n - e x i s t e n t * /
beqi r7 , n o _ f d t _ a r g / * N U L L p o i n t e r ? d o n ' t c o p y * /
2011-01-26 13:41:05 +01:00
/* Does r7 point to a valid FDT? Load HEADER magic number */
/* Run time Big/Little endian platform */
/* Save 1 as word and load byte - 0 - BIG, 1 - LITTLE */
addik r11 , r0 , 0 x1 / * B I G / L I T T L E c h e c k i n g v a l u e * /
/* __bss_start will be zeroed later - it is just temp location */
swi r11 , r0 , T O P H Y S ( _ _ b s s _ s t a r t )
lbui r11 , r0 , T O P H Y S ( _ _ b s s _ s t a r t )
beqid r11 , b i g _ e n d i a n / * D O N O T b r e a k d e l a y s t o p d e p e n d e n c y * /
lw r11 , r0 , r7 / * B i g e n d i a n l o a d i n d e l a y s l o t * /
lwr r11 , r0 , r7 / * L i t t l e e n d i a n l o a d * /
big_endian :
rsubi r11 , r11 , O F _ D T _ H E A D E R / * C h e c k F D T h e a d e r * /
2009-06-22 12:31:55 +02:00
beqi r11 , _ p r e p a r e _ c o p y _ f d t
or r7 , r0 , r0 / * c l e a r R 7 w h e n n o t v a l i d D T B * /
2009-06-22 14:02:09 +10:00
bnei r11 , n o _ f d t _ a r g / * N o - g e t o u t o f h e r e * /
2009-06-22 12:31:55 +02:00
_prepare_copy_fdt :
2009-03-27 14:25:20 +01:00
or r11 , r0 , r0 / * i n c r e m m e n t * /
2009-06-22 14:02:09 +10:00
ori r4 , r0 , T O P H Y S ( _ f d t _ s t a r t )
2009-03-27 14:25:20 +01:00
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 :
2010-03-24 11:06:23 +01:00
lbu r2 , r5 , r6 / * r2 =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 r2 , r4 , r6 / * a d d r [ r4 + r6 ] = r2 * /
2009-05-26 16:30:09 +02:00
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
2010-03-24 10:09:17 +01:00
addik r3 , r0 , M I C R O B L A Z E _ T L B _ S I Z E - 1 / * I n v a l i d a t e a l l T L B e n t r i e s * /
2009-05-26 16:30:09 +02:00
_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 */
2010-02-04 11:42:24 +01:00
/* Setup the kernel PID */
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
2009-05-26 16:30:09 +02:00
/ *
* 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 * /
/ *
* 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 .
* /
2009-07-30 14:31:23 +02:00
la r9 , r0 , m a c h i n e _ e a r l y _ i n i t
brald r15 , r9
2009-03-27 14:25:20 +01:00
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 * /