2005-04-17 02:20:36 +04:00
/ * $ Id : head. S ,v 1 . 7 2 0 0 3 / 0 9 / 0 1 1 7 : 5 8 : 1 9 l e t h a l E x p $
*
* arch/ s h / k e r n e l / h e a d . S
*
* Copyright ( C ) 1 9 9 9 , 2 0 0 0 N i i b e Y u t a k a & K a z K o j i m a
2010-01-18 13:33:10 +03:00
* Copyright ( C ) 2 0 1 0 M a t t F l e m i n g
2005-04-17 02:20:36 +04: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 .
*
* Head. S c o n t a i n s t h e S H e x c e p t i o n h a n d l e r s a n d s t a r t u p c o d e .
* /
2009-04-26 06:11:07 +04:00
# include < l i n u x / i n i t . h >
2005-04-17 02:20:36 +04:00
# include < l i n u x / l i n k a g e . h >
2006-09-27 13:20:16 +04:00
# include < a s m / t h r e a d _ i n f o . h >
2010-01-13 12:31:48 +03:00
# include < a s m / m m u . h >
# include < c p u / m m u _ c o n t e x t . h >
2005-04-17 02:20:36 +04:00
2006-09-27 10:00:04 +04:00
# ifdef C O N F I G _ C P U _ S H 4 A
# define S Y N C O ( ) s y n c o
# define P R E F I ( l a b e l , r e g ) \
mov. l l a b e l , r e g ; \
prefi @reg
# else
# define S Y N C O ( )
# define P R E F I ( l a b e l , r e g )
# endif
2005-04-17 02:20:36 +04:00
.section .empty_zero_page , " aw"
ENTRY( e m p t y _ z e r o _ p a g e )
.long 1 /* MOUNT_ROOT_RDONLY */
.long 0 /* RAMDISK_FLAGS */
.long 0x0200 /* ORIG_ROOT_DEV */
.long 1 /* LOADER_TYPE */
2008-05-13 12:41:46 +04:00
.long 0x00000000 /* INITRD_START */
.long 0x00000000 /* INITRD_SIZE */
2010-01-13 12:31:48 +03:00
# ifdef C O N F I G _ 3 2 B I T
2007-11-26 15:29:09 +03:00
.long 0x53453f00 + 3 2 /* "SE?" = 32 bit */
# else
.long 0x53453f00 + 2 9 /* "SE?" = 29 bit */
# endif
2006-12-12 02:53:29 +03:00
1 :
.skip PAGE_SIZE - empty_ z e r o _ p a g e - 1 b
2005-04-17 02:20:36 +04:00
2009-04-26 06:11:07 +04:00
_ _ HEAD
2007-07-20 12:40:03 +04:00
2005-04-17 02:20:36 +04:00
/ *
* Condition a t t h e e n t r y o f _ s t e x t :
*
* BSC h a s a l r e a d y b e e n i n i t i a l i z e d .
* INTC m a y o r m a y n o t b e i n i t i a l i z e d .
* VBR m a y o r m a y n o t b e i n i t i a l i z e d .
* MMU m a y o r m a y n o t b e i n i t i a l i z e d .
* Cache m a y o r m a y n o t b e i n i t i a l i z e d .
* Hardware ( i n c l u d i n g o n - c h i p m o d u l e s ) m a y o r m a y n o t b e i n i t i a l i z e d .
*
* /
ENTRY( _ s t e x t )
! Initialize S t a t u s R e g i s t e r
mov. l 1 f , r0 ! M D =1 , R B =0 , B L =0 , I M A S K =0xF
ldc r0 , s r
! Initialize g l o b a l i n t e r r u p t m a s k
2006-11-05 10:15:19 +03:00
# ifdef C O N F I G _ C P U _ H A S _ S R _ R B
2007-09-21 13:32:32 +04:00
mov #0 , r0
2005-04-17 02:20:36 +04:00
ldc r0 , r6 _ b a n k
2006-11-05 10:15:19 +03:00
# endif
2006-09-27 10:00:04 +04:00
/ *
* Prefetch i f p o s s i b l e t o r e d u c e c a c h e m i s s p e n a l t y .
*
* We d o t h i s e a r l y o n f o r S H - 4 A a s a m i c r o - o p t i m i z a t i o n ,
* as l a t e r o n w e w i l l h a v e s p e c u l a t i v e e x e c u t i o n e n a b l e d
* and t h i s w i l l b e c o m e l e s s o f a n i s s u e .
* /
PREFI( 5 f , r0 )
PREFI( 6 f , r0 )
2005-04-17 02:20:36 +04:00
!
mov. l 2 f , r0
mov r0 , r15 ! S e t i n i t i a l r15 ( s t a c k p o i n t e r )
2006-11-05 10:15:19 +03:00
# ifdef C O N F I G _ C P U _ H A S _ S R _ R B
2007-09-21 13:32:32 +04:00
mov. l 7 f , r0
2005-04-17 02:20:36 +04:00
ldc r0 , r7 _ b a n k ! . . . a n d i n i t i a l t h r e a d _ i n f o
2006-11-05 10:15:19 +03:00
# endif
2008-12-17 09:33:43 +03:00
2010-02-18 12:13:51 +03:00
# ifdef C O N F I G _ P M B
2010-01-21 09:42:58 +03:00
/ *
* Reconfigure t h e i n i t i a l P M B m a p p i n g s s e t u p b y t h e h a r d w a r e .
*
* When w e b o o t i n 3 2 - b i t M M U m o d e t h e r e a r e 2 P M B e n t r i e s a l r e a d y
* setup f o r u s .
*
* Entry V P N P P N V S Z C U B W T
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* 0 0 x8 0 0 0 0 0 0 0 0 x00 0 0 0 0 0 0 1 5 1 2 M B 1 0 1
* 1 0 xA0 0 0 0 0 0 0 0 x00 0 0 0 0 0 0 1 5 1 2 M B 0 0 0
*
* But w e r e p r o g r a m t h e m h e r e b e c a u s e w e w a n t c o m p l e t e c o n t r o l o v e r
* our a d d r e s s s p a c e a n d t h e i n i t i a l m a p p i n g s m a y n o t m a p P A G E _ O F F S E T
* to _ _ M E M O R Y _ S T A R T ( o r e v e n m a p a l l o f o u r R A M ) .
*
* Once w e ' v e s e t u p c a c h e d a n d u n c a c h e d m a p p i n g s w e c l e a r t h e r e s t o f t h e
* PMB e n t r i e s . T h i s c l e a r i n g a l s o d e a l s w i t h t h e f a c t t h a t P M B e n t r i e s
* can p e r s i s t a c r o s s r e b o o t s . T h e P M B c o u l d h a v e b e e n l e f t i n a n y s t a t e
* when t h e r e b o o t o c c u r r e d , s o t o b e s a f e w e c l e a r a l l e n t r i e s a n d s t a r t
* with w i t h a c l e a n s l a t e .
*
* The u n c a c h e d m a p p i n g i s c o n s t r u c t e d u s i n g t h e s m a l l e s t p o s s i b l e
* mapping w i t h a s i n g l e u n b u f f e r a b l e p a g e . O n l y t h e k e r n e l t e x t n e e d s t o
* be c o v e r e d v i a t h e u n c a c h e d m a p p i n g s o t h a t c e r t a i n f u n c t i o n s c a n b e
* run u n c a c h e d .
*
* Drivers a n d t h e l i k e t h a t h a v e p r e v i o u s l y a b u s e d t h e 1 : 1 i d e n t i t y
* mapping a r e u n s u p p o r t e d i n 3 2 - b i t m o d e a n d m u s t s p e c i f y t h e i r c a c h i n g
* preference w h e n p a g e t a b l e s a r e c o n s t r u c t e d .
*
* This f r e e s u p t h e P 2 s p a c e f o r m o r e n e f a r i o u s p u r p o s e s .
*
* Register u t i l i z a t i o n i s a s f o l l o w s :
*
* r0 = P M B _ D A T A d a t a f i e l d
* r1 = P M B _ D A T A a d d r e s s f i e l d
* r2 = P M B _ A D D R d a t a f i e l d
* r3 = P M B _ A D D R a d d r e s s f i e l d
* r4 = P M B _ E _ S H I F T
* r5 = r e m a i n i n g a m o u n t o f R A M t o m a p
* r6 = P M B m a p p i n g s i z e w e ' r e t r y i n g t o u s e
* r7 = c a c h e d _ t o _ u n c a c h e d
* r8 = s c r a t c h r e g i s t e r
* r9 = s c r a t c h r e g i s t e r
* r1 0 = n u m b e r o f P M B e n t r i e s w e ' v e s e t u p
2010-04-25 23:18:41 +04:00
* r1 1 = s c r a t c h r e g i s t e r
2010-01-21 09:42:58 +03:00
* /
mov. l . L M M U C R , r1 / * F l u s h t h e T L B * /
mov. l @r1, r0
or #M M U C R _ T I , r 0
mov. l r0 , @r1
mov. l . L M E M O R Y _ S I Z E , r5
mov #P M B _ E _ S H I F T , r 0
mov #0x1 , r4
shld r0 , r4
2010-01-21 08:19:41 +03:00
2010-01-21 09:42:58 +03:00
mov. l . L F I R S T _ D A T A _ E N T R Y , r0
mov. l . L P M B _ D A T A , r1
mov. l . L F I R S T _ A D D R _ E N T R Y , r2
mov. l . L P M B _ A D D R , r3
2010-02-18 12:13:51 +03:00
/ *
* First w e n e e d t o w a l k t h e P M B a n d f i g u r e o u t i f t h e r e a r e a n y
* existing m a p p i n g s t h a t m a t c h t h e i n i t i a l m a p p i n g s V P N / P P N .
* If t h e s e h a v e a l r e a d y b e e n e s t a b l i s h e d b y t h e b o o t l o a d e r , w e
* don' t b o t h e r s e t t i n g u p n e w e n t r i e s h e r e , a n d l e t t h e l a t e P M B
* initialization t a k e c a r e o f t h i n g s i n s t e a d .
*
* Note t h a t w e m a y n e e d t o c o a l e s c e a n d m e r g e e n t r i e s i n o r d e r
* to r e c l a i m m o r e a v a i l a b l e P M B s l o t s , w h i c h i s m u c h m o r e t h a n
* we w a n t t o d o a t t h i s e a r l y s t a g e .
* /
mov #0 , r10
mov #N R _ P M B _ E N T R I E S , r 9
mov r1 , r7 / * t e m p o r a r y P M B _ D A T A i t e r * /
.Lvalidate_existing_mappings :
2010-04-25 23:18:41 +04:00
mov. l . L P M B _ D A T A _ M A S K , r11
2010-02-18 12:13:51 +03:00
mov. l @r7, r8
2010-04-25 23:18:41 +04:00
and r11 , r8
2010-02-18 12:13:51 +03:00
cmp/ e q r0 , r8 / * C h e c k f o r v a l i d _ _ M E M O R Y _ S T A R T m a p p i n g s * /
bt . L p m b _ d o n e
add #1 , r10 / * I n c r e m e n t t h e l o o p c o u n t e r * /
cmp/ e q r9 , r10
bf/ s . L v a l i d a t e _ e x i s t i n g _ m a p p i n g s
add r4 , r7 / * I n c r e m e n t t o t h e n e x t P M B _ D A T A e n t r y * /
/ *
* If w e ' v e f a l l e n t h r o u g h , c o n t i n u e w i t h s e t t i n g u p t h e i n i t i a l
* mappings.
* /
mov r5 , r7 / * c a c h e d _ t o _ u n c a c h e d * /
2010-01-21 09:42:58 +03:00
mov #0 , r10
2010-02-17 10:28:00 +03:00
# ifdef C O N F I G _ U N C A C H E D _ M A P P I N G
2010-01-21 09:42:58 +03:00
/ *
* Uncached m a p p i n g
* /
mov #( P M B _ S Z _ 16 M > > 2 ) , r9
shll2 r9
mov #( P M B _ U B > > 8 ) , r8
shll8 r8
or r0 , r8
or r9 , r8
mov. l r8 , @r1
mov r2 , r8
add r7 , r8
mov. l r8 , @r3
add r4 , r1
add r4 , r3
add #1 , r10
2010-02-17 10:28:00 +03:00
# endif
2010-01-21 09:42:58 +03:00
/ *
* Iterate o v e r a l l o f t h e a v a i l a b l e s i z e s f r o m l a r g e s t t o
* smallest f o r c o n s t r u c t i n g t h e c a c h e d m a p p i n g .
* /
2010-01-21 08:19:41 +03:00
# define _ _ P M B _ I T E R _ B Y _ S I Z E ( s i z e ) \
.L # # size : \
mov #( s i z e > > 4 ) , r6 ; \
shll1 6 r6 ; \
shll8 r6 ; \
\
cmp/ h i r5 , r6 ; \
bt 9 9 9 9 f ; \
\
mov #( P M B _ S Z _ # # s i z e # # M > > 2 ) , r9 ; \
shll2 r9 ; \
\
/ * \
* Cached m a p p i n g \
* / \
mov #P M B _ C , r 8 ; \
or r0 , r8 ; \
or r9 , r8 ; \
mov. l r8 , @r1; \
mov. l r2 , @r3; \
\
/* Increment to the next PMB_DATA entry */ \
add r4 , r1 ; \
/* Increment to the next PMB_ADDR entry */ \
add r4 , r3 ; \
/* Increment number of PMB entries */ \
add #1 , r10 ; \
\
sub r6 , r5 ; \
add r6 , r0 ; \
add r6 , r2 ; \
\
bra . L ## s i z e ; \
9999 :
_ _ PMB_ I T E R _ B Y _ S I Z E ( 5 1 2 )
_ _ PMB_ I T E R _ B Y _ S I Z E ( 1 2 8 )
_ _ PMB_ I T E R _ B Y _ S I Z E ( 6 4 )
_ _ PMB_ I T E R _ B Y _ S I Z E ( 1 6 )
2010-01-18 13:33:10 +03:00
2010-02-17 10:28:00 +03:00
# ifdef C O N F I G _ U N C A C H E D _ M A P P I N G
2010-01-21 09:42:58 +03:00
/ *
2010-01-21 09:54:31 +03:00
* Now t h a t w e c a n a c c e s s i t , u p d a t e c a c h e d _ t o _ u n c a c h e d a n d
* uncached_ s i z e .
2010-01-21 09:42:58 +03:00
* /
2010-01-18 13:33:10 +03:00
mov. l . L c a c h e d _ t o _ u n c a c h e d , r0
mov. l r7 , @r0
2010-01-21 09:54:31 +03:00
mov. l . L u n c a c h e d _ s i z e , r0
mov #1 , r7
shll1 6 r7
shll8 r7
mov. l r7 , @r0
2010-02-17 10:28:00 +03:00
# endif
2010-01-21 09:54:31 +03:00
2010-01-18 13:33:10 +03:00
/ *
* Clear t h e r e m a i n i n g P M B e n t r i e s .
*
* r3 = e n t r y t o b e g i n c l e a r i n g f r o m
* r1 0 = n u m b e r o f e n t r i e s w e ' v e s e t u p s o f a r
* /
mov #0 , r1
2010-02-17 09:33:30 +03:00
mov #N R _ P M B _ E N T R I E S , r 0
2010-01-18 13:33:10 +03:00
.Lagain :
mov. l r1 , @r3 /* Clear PMB_ADDR entry */
add #1 , r10 / * I n c r e m e n t t h e l o o p c o u n t e r * /
cmp/ e q r0 , r10
bf/ s . L a g a i n
add r4 , r3 / * I n c r e m e n t t o t h e n e x t P M B _ A D D R e n t r y * /
mov. l 6 f , r0
icbi @r0
2010-02-18 12:13:51 +03:00
.Lpmb_done :
# endif / * C O N F I G _ P M B * /
2010-01-18 13:33:10 +03:00
2008-12-17 09:33:43 +03:00
# ifndef C O N F I G _ S H _ N O _ B S S _ I N I T
/ *
* Don' t c l e a r B S S i f r u n n i n g o n s l o w p l a t f o r m s s u c h a s a n R T L s i m u l a t i o n ,
* remote m e m o r y v i a S H d e b u g l i n k , e t c . F o r t h e s e t h e m e m o r y c a n b e g u a r a n t e e d
* to b e a l l z e r o o n b o o t a n y w a y .
* /
! Clear B S S a r e a
2007-09-21 13:32:32 +04:00
# ifdef C O N F I G _ S M P
mov. l 3 f , r0
cmp/ e q #0 , r0 ! s k i p c l e a r i f s e t t o z e r o
bt 1 0 f
# endif
2005-04-17 02:20:36 +04:00
mov. l 3 f , r1
add #4 , r1
mov. l 4 f , r2
mov #0 , r0
9 : cmp/ h s r2 , r1
bf/ s 9 b ! w h i l e ( r1 < r2 )
mov. l r0 ,@-r2
2006-09-27 10:00:04 +04:00
2007-09-21 13:32:32 +04:00
10 :
2008-12-17 09:33:43 +03:00
# endif
2006-09-27 10:00:04 +04:00
! Additional C P U i n i t i a l i z a t i o n
mov. l 6 f , r0
jsr @r0
nop
SYNCO( ) ! W a i t f o r p e n d i n g i n s t r u c t i o n s . .
2007-09-21 13:32:32 +04:00
2005-04-17 02:20:36 +04:00
! Start k e r n e l
mov. l 5 f , r0
jmp @r0
nop
.balign 4
2006-11-05 10:15:19 +03:00
# if d e f i n e d ( C O N F I G _ C P U _ S H 2 )
1 : .long 0x000000F0 ! IMASK=0xF
# else
2010-09-24 13:05:38 +04:00
1 : .long 0x500080F0 ! MD=1 , R B =0 , B L =1 , F D =1 , I M A S K =0xF
2006-11-05 10:15:19 +03:00
# endif
2007-09-21 13:32:32 +04:00
ENTRY( s t a c k _ s t a r t )
2006-09-27 13:20:16 +04:00
2 : .long 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
2005-04-17 02:20:36 +04:00
3 : .long _ _ b s s _ s t a r t
4 : .long _ e n d
5 : .long s t a r t _ k e r n e l
2010-04-21 07:20:42 +04:00
6 : .long c p u _ i n i t
2007-09-21 13:32:32 +04:00
7 : .long i n i t _ t h r e a d _ u n i o n
2010-01-18 13:33:10 +03:00
2010-02-18 12:13:51 +03:00
# ifdef C O N F I G _ P M B
2010-01-18 13:33:10 +03:00
.LPMB_ADDR : .long PMB_ADDR
.LPMB_DATA : .long PMB_DATA
2010-04-25 23:18:41 +04:00
.LPMB_DATA_MASK : .long PMB_PFN_MASK | PMB_ V
2010-01-18 13:33:10 +03:00
.LFIRST_ADDR_ENTRY : .long PAGE_OFFSET | PMB_ V
.LFIRST_DATA_ENTRY : .long __MEMORY_START | PMB_ V
.LMMUCR : .long MMUCR
2010-02-17 10:28:00 +03:00
.LMEMORY_SIZE : .long __MEMORY_SIZE
# ifdef C O N F I G _ U N C A C H E D _ M A P P I N G
2010-01-18 13:33:10 +03:00
.Lcached_to_uncached : .long cached_to_uncached
2010-01-21 09:54:31 +03:00
.Luncached_size : .long uncached_size
2010-02-17 10:28:00 +03:00
# endif
2010-01-18 13:33:10 +03:00
# endif