2008-02-08 15:19:31 +03:00
/ * Boot e n t r y p o i n t f o r M N 1 0 3 0 0 k e r n e l
*
* Copyright ( C ) 2 0 0 5 R e d H a t , I n c . A l l R i g h t s R e s e r v e d .
* Written b y D a v i d H o w e l l s ( d h o w e l l s @redhat.com)
*
* 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 i t u n d e r 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 c e
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n c e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
* /
2009-04-26 06:11:04 +04:00
# include < l i n u x / i n i t . h >
2008-02-08 15:19:31 +03:00
# include < l i n u x / t h r e a d s . h >
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / s e r i a l _ r e g . 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 >
# include < a s m / p g t a b l e . h >
# include < a s m / f r a m e . i n c >
# include < a s m / p a r a m . h >
2009-04-10 17:33:48 +04:00
# include < u n i t / s e r i a l . h >
2010-10-27 20:28:55 +04:00
# ifdef C O N F I G _ S M P
# include < a s m / s m p . h >
# include < a s m / i n t c t l - r e g s . h >
# include < a s m / c p u - r e g s . h >
# include < p r o c / s m p - r e g s . h >
# endif / * C O N F I G _ S M P * /
2008-02-08 15:19:31 +03:00
2009-04-26 06:11:04 +04:00
_ _ HEAD
2008-02-08 15:19:31 +03:00
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# bootloader e n t r y p o i n t
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
.globl _start
.type _ start,@function
_start :
2010-10-27 20:28:55 +04:00
# ifdef C O N F I G _ S M P
#
# If t h i s i s a s e c o n d a r y C P U ( A P ) , t h e n d e a l w i t h t h a t e l s e w h e r e
#
mov ( C P U I D ) ,d3
and C P U I D _ M A S K ,d3
bne s t a r t u p _ s e c o n d a r y
#
# We' r e d e a l i n g w i t h t h e p r i m a r y C P U ( B P ) h e r e , t h e n .
# Keep B P ' s D 0 ,D 1 ,D 2 r e g i s t e r f o r b o o t c h e c k .
#
# Set u p t h e B o o t I P I f o r e a c h s e c o n d a r y C P U
mov 0 x1 ,a0
loop_set_secondary_icr :
mov a0 ,a1
asl C R O S S _ I C R _ C P U _ S H I F T ,a1
add C R O S S _ G x I C R ( S M P _ B O O T _ I R Q ,0 ) ,a1
movhu ( a1 ) ,d3
or G x I C R _ E N A B L E | G x I C R _ L E V E L _ 0 ,d3
movhu d3 ,( a1 )
movhu ( a1 ) ,d3 # f l u s h
inc a0
cmp N R _ C P U S ,a0
bne l o o p _ s e t _ s e c o n d a r y _ i c r
# endif / * C O N F I G _ S M P * /
2008-02-08 15:19:31 +03:00
# save c o m m a n d l i n e p o i n t e r
mov d0 ,a3
# preload t h e P G D p o i n t e r r e g i s t e r
mov s w a p p e r _ p g _ d i r ,d0
mov d0 ,( P T B R )
2010-10-27 20:28:55 +04:00
clr d0
movbu d0 ,( P I D R )
2008-02-08 15:19:31 +03:00
# turn o n t h e T L B s
mov M M U C T R _ I I V | M M U C T R _ D I V ,d0
mov d0 ,( M M U C T R )
2010-10-27 20:28:55 +04:00
# ifdef C O N F I G _ A M 3 4 _ 2
mov M M U C T R _ I T E | M M U C T R _ D T E | M M U C T R _ C E | M M U C T R _ W T E ,d0
# else
2008-02-08 15:19:31 +03:00
mov M M U C T R _ I T E | M M U C T R _ D T E | M M U C T R _ C E ,d0
2010-10-27 20:28:55 +04:00
# endif
2008-02-08 15:19:31 +03:00
mov d0 ,( M M U C T R )
# turn o n A M 3 3 v2 e x c e p t i o n h a n d l i n g m o d e a n d s e t t h e t r a p t a b l e b a s e
movhu ( C P U P ) ,d0
or C P U P _ E X M _ A M 3 3 V 2 ,d0
movhu d0 ,( C P U P )
mov C O N F I G _ I N T E R R U P T _ V E C T O R _ B A S E ,d0
mov d0 ,( T B R )
# invalidate a n d e n a b l e b o t h o f t h e c a c h e s
2010-10-27 20:28:55 +04:00
# ifdef C O N F I G _ S M P
mov E C H C T R ,a0
clr d0
mov d0 ,( a0 )
# endif
2008-02-08 15:19:31 +03:00
mov C H C T R ,a0
clr d0
movhu d0 ,( a0 ) # t u r n o f f f i r s t
mov C H C T R _ I C I N V | C H C T R _ D C I N V ,d0
movhu d0 ,( a0 )
setlb
mov ( a0 ) ,d0
btst C H C T R _ I C B U S Y | C H C T R _ D C B U S Y ,d0 # w a i t t i l l n o t b u s y
lne
2010-10-27 20:28:42 +04:00
# ifdef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ E N A B L E D
2008-02-08 15:19:31 +03:00
# ifdef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ W B A C K
# ifndef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ W B A C K _ N O W R A L L O C
mov C H C T R _ I C E N | C H C T R _ D C E N | C H C T R _ D C W T M D _ W R B A C K ,d0
# else
mov C H C T R _ I C E N | C H C T R _ D C E N | C H C T R _ D C W T M D _ W R B A C K | C H C T R _ D C A L M D ,d0
2010-10-27 20:28:42 +04:00
# endif / * N O W R A L L O C * /
2008-02-08 15:19:31 +03:00
# else
mov C H C T R _ I C E N | C H C T R _ D C E N | C H C T R _ D C W T M D _ W R T H R O U G H ,d0
# endif / * W B A C K * /
movhu d0 ,( a0 ) # e n a b l e
2010-10-27 20:28:42 +04:00
# endif / * E N A B L E D * /
2008-02-08 15:19:31 +03:00
# turn o n R T S o n t h e d e b u g s e r i a l p o r t i f a p p l i c a b l e
# ifdef C O N F I G _ M N 1 0 3 0 0 _ U N I T _ A S B 2 3 0 5
bset U A R T _ M C R _ R T S ,( A S B 2 3 0 5 _ D E B U G _ M C R )
# endif
# clear t h e B S S a r e a
mov _ _ b s s _ s t a r t ,a0
mov _ _ b s s _ s t o p ,a1
clr d0
bssclear :
cmp a1 ,a0
bge b s s c l e a r _ e n d
mov d0 ,( a0 )
inc4 a0
bra b s s c l e a r
bssclear_end :
# retrieve t h e p a r a m e t e r s ( i n c l u d i n g c o m m a n d l i n e ) b e f o r e w e o v e r w r i t e
# them
cmp 0 x a b a d c a f e ,d1
bne _ _ n o _ p a r a m e t e r s
__copy_parameters :
mov r e d b o o t _ c o m m a n d _ l i n e ,a0
mov a0 ,a1
add C O M M A N D _ L I N E _ S I Z E ,a1
1 :
movbu ( a3 ) ,d0
inc a3
movbu d0 ,( a0 )
inc a0
cmp a1 ,a0
blt 1 b
mov r e d b o o t _ p l a t f o r m _ n a m e ,a0
mov a0 ,a1
add C O M M A N D _ L I N E _ S I Z E ,a1
mov d2 ,a3
1 :
movbu ( a3 ) ,d0
inc a3
movbu d0 ,( a0 )
inc a0
cmp a1 ,a0
blt 1 b
__no_parameters :
# set u p t h e r e g i s t e r s w i t h r e c o g n i s a b l e r u b b i s h i n t h e m
mov 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 - 1 2 ,s p
mov 0 x e a01 e a e a ,d0
mov d0 ,( 4 ,s p ) # E P S W s a v e a r e a
mov 0 x e a02 e a e a ,d0
mov d0 ,( 8 ,s p ) # P C s a v e a r e a
mov 0 x e b00 6 0 e d ,d0
mov d0 ,m d r
mov 0 x e b00 6 1 e d ,d0
mov d0 ,m d r q
mov 0 x e b00 6 2 e d ,d0
mov d0 ,m c r h
mov 0 x e b00 6 3 e d ,d0
mov d0 ,m c r l
mov 0 x e b00 6 4 e d ,d0
mov d0 ,m c v f
mov 0 x e d00 6 5 e d ,a3
mov a3 ,u s p
mov 0 x e d00 e 0 e d ,e 0
mov 0 x e d00 e 1 e d ,e 1
mov 0 x e d00 e 2 e d ,e 2
mov 0 x e d00 e 3 e d ,e 3
mov 0 x e d00 e 4 e d ,e 4
mov 0 x e d00 e 5 e d ,e 5
mov 0 x e d00 e 6 e d ,e 6
mov 0 x e d00 e 7 e d ,e 7
mov 0 x e d00 d0 e d ,d0
mov 0 x e d00 d1 e d ,d1
mov 0 x e d00 d2 e d ,d2
mov 0 x e d00 d3 e d ,d3
mov 0 x e d00 a0 e d ,a0
mov 0 x e d00 a1 e d ,a1
mov 0 x e d00 a2 e d ,a2
mov 0 ,a3
# set u p t h e i n i t i a l k e r n e l s t a c k
SAVE_ A L L
mov 0 x f f f f f f f f ,d0
mov d0 ,( R E G _ O R I G _ D 0 ,f p )
# put d i f f e r e n t r e c o g n i s a b l e r u b b i s h i n t h e r e g s
mov 0 x f b00 6 0 e d ,d0
mov d0 ,m d r
mov 0 x f b00 6 1 e d ,d0
mov d0 ,m d r q
mov 0 x f b00 6 2 e d ,d0
mov d0 ,m c r h
mov 0 x f b00 6 3 e d ,d0
mov d0 ,m c r l
mov 0 x f b00 6 4 e d ,d0
mov d0 ,m c v f
mov 0 x f d00 6 5 e d ,a0
mov a0 ,u s p
mov 0 x f d00 e 0 e d ,e 0
mov 0 x f d00 e 1 e d ,e 1
mov 0 x f d00 e 2 e d ,e 2
mov 0 x f d00 e 3 e d ,e 3
mov 0 x f d00 e 4 e d ,e 4
mov 0 x f d00 e 5 e d ,e 5
mov 0 x f d00 e 6 e d ,e 6
mov 0 x f d00 e 7 e d ,e 7
mov 0 x f d00 d0 e d ,d0
mov 0 x f d00 d1 e d ,d1
mov 0 x f d00 d2 e d ,d2
mov 0 x f d00 d3 e d ,d3
mov 0 x f d00 a0 e d ,a0
mov 0 x f d00 a1 e d ,a1
mov 0 x f d00 a2 e d ,a2
# we m a y b e h o l d i n g c u r r e n t i n E 2
# ifdef C O N F I G _ M N 1 0 3 0 0 _ C U R R E N T _ I N _ E 2
mov i n i t _ t a s k ,e 2
# endif
# initialise t h e p r o c e s s o r a n d t h e u n i t
call p r o c e s s o r _ i n i t [ ] ,0
call u n i t _ i n i t [ ] ,0
2010-10-27 20:28:55 +04:00
# ifdef C O N F I G _ S M P
# mark t h e p r i m a r y C P U i n c p u _ b o o t _ m a p
mov c p u _ b o o t _ m a p ,a0
mov 0 x1 ,d0
mov d0 ,( a0 )
# signal e a c h s e c o n d a r y C P U t o b e g i n b o o t i n g
mov 0 x1 ,d2 # C P U I D
loop_request_boot_secondary :
mov d2 ,a0
# send S M P _ B O O T _ I P I t o s e c o n d a r y C P U
asl C R O S S _ I C R _ C P U _ S H I F T ,a0
add C R O S S _ G x I C R ( S M P _ B O O T _ I R Q ,0 ) ,a0
movhu ( a0 ) ,d0
or G x I C R _ R E Q U E S T | G x I C R _ D E T E C T ,d0
movhu d0 ,( a0 )
movhu ( a0 ) ,d0 # f l u s h
# wait u p t o 1 0 0 m s f o r A P ' s I P I t o b e r e c e i v e d
clr d3
wait_on_secondary_boot :
mov D E L A Y _ T I M E _ B O O T _ I P I ,d0
call _ _ d e l a y [ ] ,0
inc d3
mov c p u _ b o o t _ m a p ,a0
mov ( a0 ) ,d0
lsr d2 ,d0
btst 0 x1 ,d0
bne 1 f
cmp T I M E _ O U T _ C O U N T _ B O O T _ I P I ,d3
bne w a i t _ o n _ s e c o n d a r y _ b o o t
1 :
inc d2
cmp N R _ C P U S ,d2
bne l o o p _ r e q u e s t _ b o o t _ s e c o n d a r y
# endif / * C O N F I G _ S M P * /
2008-02-08 15:19:31 +03:00
# ifdef C O N F I G _ G D B S T U B
call g d b s t u b _ i n i t [ ] ,0
# ifdef C O N F I G _ G D B S T U B _ I M M E D I A T E
.globl __gdbstub_pause
__gdbstub_pause :
bra _ _ g d b s t u b _ p a u s e
# endif
# endif
jmp s t a r t _ k e r n e l
2010-10-27 20:28:55 +04:00
.size _ start,. - _ s t a r t
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Secondary C P U b o o t p o i n t
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# ifdef C O N F I G _ S M P
startup_secondary :
# preload t h e P G D p o i n t e r r e g i s t e r
mov s w a p p e r _ p g _ d i r ,d0
mov d0 ,( P T B R )
clr d0
movbu d0 ,( P I D R )
# turn o n t h e T L B s
mov M M U C T R _ I I V | M M U C T R _ D I V ,d0
mov d0 ,( M M U C T R )
# ifdef C O N F I G _ A M 3 4 _ 2
mov M M U C T R _ I T E | M M U C T R _ D T E | M M U C T R _ C E | M M U C T R _ W T E ,d0
# else
mov M M U C T R _ I T E | M M U C T R _ D T E | M M U C T R _ C E ,d0
# endif
mov d0 ,( M M U C T R )
# turn o n A M 3 3 v2 e x c e p t i o n h a n d l i n g m o d e a n d s e t t h e t r a p t a b l e b a s e
movhu ( C P U P ) ,d0
or C P U P _ E X M _ A M 3 3 V 2 ,d0
movhu d0 ,( C P U P )
# set t h e i n t e r r u p t v e c t o r t a b l e
mov C O N F I G _ I N T E R R U P T _ V E C T O R _ B A S E ,d0
mov d0 ,( T B R )
# invalidate a n d e n a b l e b o t h o f t h e c a c h e s
mov E C H C T R ,a0
clr d0
mov d0 ,( a0 )
mov C H C T R ,a0
clr d0
movhu d0 ,( a0 ) # t u r n o f f f i r s t
mov C H C T R _ I C I N V | C H C T R _ D C I N V ,d0
movhu d0 ,( a0 )
setlb
mov ( a0 ) ,d0
btst C H C T R _ I C B U S Y | C H C T R _ D C B U S Y ,d0 # w a i t t i l l n o t b u s y ( u s e C P U l o o p b u f f e r )
lne
# ifdef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ E N A B L E D
# ifdef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ W B A C K
# ifndef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ W B A C K _ N O W R A L L O C
mov C H C T R _ I C E N | C H C T R _ D C E N | C H C T R _ D C W T M D _ W R B A C K ,d0
# else
mov C H C T R _ I C E N | C H C T R _ D C E N | C H C T R _ D C W T M D _ W R B A C K | C H C T R _ D C A L M D ,d0
# endif / * ! N O W R A L L O C * /
# else
mov C H C T R _ I C E N | C H C T R _ D C E N | C H C T R _ D C W T M D _ W R T H R O U G H ,d0
# endif / * W B A C K * /
movhu d0 ,( a0 ) # e n a b l e
# endif / * E N A B L E D * /
# Clear t h e b o o t I P I i n t e r r u p t f o r t h i s C P U
movhu ( G x I C R ( S M P _ B O O T _ I R Q ) ) ,d0
and ~ G x I C R _ R E Q U E S T ,d0
movhu d0 ,( G x I C R ( S M P _ B O O T _ I R Q ) )
movhu ( G x I C R ( S M P _ B O O T _ I R Q ) ) ,d0 # f l u s h
/* get stack */
mov C O N F I G _ I N T E R R U P T _ V E C T O R _ B A S E + C O N F I G _ B O O T _ S T A C K _ O F F S E T ,a0
mov ( C P U I D ) ,d0
and C P U I D _ M A S K ,d0
mulu C O N F I G _ B O O T _ S T A C K _ S I Z E ,d0
sub d0 ,a0
mov a0 ,s p
# init i n t e r r u p t f o r A P
call s m p _ p r e p a r e _ c p u _ i n i t [ ] ,0
# mark t h i s s e c o n d a r y C P U i n c p u _ b o o t _ m a p
mov ( C P U I D ) ,d0
mov 0 x1 ,d1
asl d0 ,d1
mov c p u _ b o o t _ m a p ,a0
bset d1 ,( a0 )
or E P S W _ I E | E P S W _ I M _ 1 ,e p s w # p e r m i t l e v e l 0 i n t e r r u p t s
nop
nop
# ifdef C O N F I G _ M N 1 0 3 0 0 _ C A C H E _ W B A C K
# flush t h e l o c a l c a c h e i f i t ' s i n w r i t e b a c k m o d e
call m n 1 0 3 0 0 _ l o c a l _ d c a c h e _ f l u s h _ i n v [ ] ,0
setlb
mov ( C H C T R ) ,d0
btst C H C T R _ D C B U S Y ,d0 # w a i t t i l l n o t b u s y ( u s e C P U l o o p b u f f e r )
lne
# endif
# now s l e e p w a i t i n g f o r f u r t h e r i n s t r u c t i o n s
secondary_sleep :
mov C P U M _ S L E E P ,d0
movhu d0 ,( C P U M )
nop
nop
bra s e c o n d a r y _ s l e e p
.size startup_ s e c o n d a r y ,. - s t a r t u p _ s e c o n d a r y
# endif / * C O N F I G _ S M P * /
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
#
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2008-02-08 15:19:31 +03:00
ENTRY( _ _ h e a d _ e n d )
/ *
* This i s i n i t i a l i z e d t o d i s a l l o w a l l a c c e s s t o t h e l o w 2 G r e g i o n
* - the h i g h 2 G r e g i o n i s m a n a g e d d i r e c t l y b y t h e M M U
* - range 0 x70 0 0 0 0 0 0 - 0 x7 C 0 0 0 0 0 0 a r e i n i t i a l i s e d f o r u s e b y V M A L L O C
* /
.section .bss
.balign PAGE_SIZE
ENTRY( s w a p p e r _ p g _ d i r )
.space PTRS_ P E R _ P G D * 4
/ *
* The p a g e t a b l e s a r e i n i t i a l i z e d t o o n l y 8 M B h e r e - t h e f i n a l p a g e
* tables a r e s e t u p l a t e r d e p e n d i n g o n m e m o r y s i z e .
* /
.balign PAGE_SIZE
ENTRY( e m p t y _ z e r o _ p a g e )
.space PAGE_SIZE
.balign PAGE_SIZE
ENTRY( e m p t y _ b a d _ p a g e )
.space PAGE_SIZE
.balign PAGE_SIZE
ENTRY( e m p t y _ b a d _ p t e _ t a b l e )
.space PAGE_SIZE
.balign PAGE_SIZE
ENTRY( l a r g e _ p a g e _ t a b l e )
.space PAGE_SIZE
.balign PAGE_SIZE
ENTRY( k e r n e l _ v m a l l o c _ p t e s )
.space ( ( VMALLOC_ E N D - V M A L L O C _ S T A R T ) / P A G E _ S I Z E ) * 4