2005-04-16 15:20:36 -07:00
/*****************************************************************************/
/ *
* head. S - - c o m m o n s t a r t u p c o d e f o r C o l d F i r e C P U s .
*
2011-10-14 15:35:37 +10:00
* ( C) C o p y r i g h t 1 9 9 9 - 2 0 1 1 , G r e g U n g e r e r < g e r g @snapgear.com>.
2005-04-16 15:20:36 -07:00
* /
/*****************************************************************************/
# include < l i n u x / l i n k a g e . h >
2008-07-11 15:29:36 +10:00
# include < l i n u x / i n i t . h >
2005-04-16 15:20:36 -07:00
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / c o l d f i r e . h >
# include < a s m / m c f s i m . h >
2011-10-14 15:35:37 +10:00
# include < a s m / m c f m m u . h >
2010-10-07 14:08:55 +01:00
# include < a s m / t h r e a d _ i n f o . h >
2005-04-16 15:20:36 -07:00
/*****************************************************************************/
/ *
2006-06-26 16:33:09 +10:00
* If w e d o n ' t h a v e a f i x e d m e m o r y s i z e , t h e n l e t s b u i l d i n c o d e
2011-03-30 22:57:33 -03:00
* to a u t o d e t e c t t h e D R A M s i z e . O b v i o u s l y t h i s i s t h e p r e f e r r e d
2006-06-26 16:33:09 +10:00
* method, a n d s h o u l d w o r k f o r m o s t b o a r d s . I t w o n ' t w o r k f o r t h o s e
* that d o n o t h a v e t h e i r R A M s t a r t i n g a t a d d r e s s 0 , a n d i t o n l y
* works o n S D R A M ( n o t b o a r d s f i t t e d w i t h S R A M ) .
2005-04-16 15:20:36 -07:00
* /
2006-06-26 16:33:09 +10:00
# if C O N F I G _ R A M S I Z E ! = 0
2005-04-16 15:20:36 -07:00
.macro GET_MEM_SIZE
2006-06-26 16:33:09 +10:00
movel #C O N F I G _ R A M S I Z E , % d 0 / * h a r d c o d e d m e m o r y s i z e * /
2005-04-16 15:20:36 -07:00
.endm
# elif d e f i n e d ( C O N F I G _ M 5 2 0 6 ) | | d e f i n e d ( C O N F I G _ M 5 2 0 6 e ) | | \
2012-06-05 08:23:08 -07:00
defined( C O N F I G _ M 5 2 4 9 ) | | d e f i n e d ( C O N F I G _ M 5 2 5 x ) | | \
defined( C O N F I G _ M 5 2 7 x ) | | d e f i n e d ( C O N F I G _ M 5 2 8 x ) | | \
defined( C O N F I G _ M 5 3 0 7 ) | | d e f i n e d ( C O N F I G _ M 5 4 0 7 )
2005-04-16 15:20:36 -07:00
/ *
* Not a l l t h e s e d e v i c e s h a v e e x a c t l y t h e s a m e D R A M c o n t r o l l e r ,
* but t h e D C M R r e g i s t e r i s v i r t u a l l y i d e n t i c a l - g i v e o r t a k e
* a c o u p l e o f b i t s . T h e o n l y e x c e p t i o n i s t h e 5 2 7 2 d e v i c e s , t h e i r
* DRAM c o n t r o l l e r i s q u i t e d i f f e r e n t .
* /
.macro GET_MEM_SIZE
2011-03-06 23:01:46 +10:00
movel M C F S I M _ D M R 0 ,% d0 / * g e t m a s k f o r 1 s t b a n k * /
2005-04-16 15:20:36 -07:00
btst #0 ,% d0 / * c h e c k i f r e g i o n e n a b l e d * /
beq 1 f
andl #0xfffc0000 ,% d0
beq 1 f
addl #0x00040000 ,% d0 / * c o n v e r t m a s k t o s i z e * /
1 :
2011-03-06 23:01:46 +10:00
movel M C F S I M _ D M R 1 ,% d1 / * g e t m a s k f o r 2 n d b a n k * /
2005-04-16 15:20:36 -07:00
btst #0 ,% d1 / * c h e c k i f r e g i o n e n a b l e d * /
beq 2 f
2011-03-06 23:01:46 +10:00
andl #0xfffc0000 ,% d1
2005-04-16 15:20:36 -07:00
beq 2 f
addl #0x00040000 ,% d1
addl % d1 ,% d0 / * t o t a l m e m s i z e i n d0 * /
2 :
.endm
# elif d e f i n e d ( C O N F I G _ M 5 2 7 2 )
.macro GET_MEM_SIZE
2012-09-14 15:36:02 +10:00
movel M C F S I M _ C S O R 7 ,% d0 / * g e t S D R A M a d d r e s s m a s k * /
2005-04-16 15:20:36 -07:00
andil #0xfffff000 ,% d0 / * m a s k o u t c h i p s e l e c t o p t i o n s * /
negl % d0 / * n e g a t e b i t s * /
.endm
2006-12-04 17:27:29 +10:00
# elif d e f i n e d ( C O N F I G _ M 5 2 0 x )
.macro GET_MEM_SIZE
clrl % d0
2011-03-05 23:50:37 +10:00
movel M C F S I M _ S D C S 0 , % d2 / * G e t S D R A M c h i p s e l e c t 0 c o n f i g * /
2006-12-04 17:27:29 +10:00
andl #0x1f , % d2 / * G e t o n l y t h e c h i p s e l e c t s i z e * /
beq 3 f / * C h e c k i f i t i s e n a b l e d * /
addql #1 , % d2 / * F o r m e x p o n e n t * /
moveql #1 , % d0
lsll % d2 , % d0 / * 2 ^ e x p o n e n t * /
3 :
2011-03-05 23:50:37 +10:00
movel M C F S I M _ S D C S 1 , % d2 / * G e t S D R A M c h i p s e l e c t 1 c o n f i g * /
2006-12-04 17:27:29 +10:00
andl #0x1f , % d2 / * G e t o n l y t h e c h i p s e l e c t s i z e * /
beq 4 f / * C h e c k i f i t i s e n a b l e d * /
addql #1 , % d2 / * F o r m e x p o n e n t * /
moveql #1 , % d1
lsll % d2 , % d1 / * 2 ^ e x p o n e n t * /
addl % d1 , % d0 / * T o t a l s i z e o f S D R A M i n d0 * /
4 :
.endm
2005-04-16 15:20:36 -07:00
# else
2006-06-26 16:33:09 +10:00
# error " E R R O R : I d o n ' t k n o w h o w t o p r o b e y o u r b o a r d s m e m o r y s i z e ? "
2005-04-16 15:20:36 -07:00
# endif
/*****************************************************************************/
/ *
* Boards a n d p l a t f o r m s c a n d o s p e c i f i c e a r l y h a r d w a r e s e t u p i f
* they n e e d t o . M o s t d o n ' t n e e d t h i s , d e f i n e a w a y i f n o t r e q u i r e d .
* /
# ifndef P L A T F O R M _ S E T U P
# define P L A T F O R M _ S E T U P
# endif
/*****************************************************************************/
.global _start
.global _rambase
.global _ramvec
.global _ramstart
.global _ramend
2009-09-18 13:49:36 -04:00
# if d e f i n e d ( C O N F I G _ U B O O T )
.global _init_sp
# endif
2005-04-16 15:20:36 -07:00
/*****************************************************************************/
.data
/ *
* During s t a r t u p w e s t o r e a w a y t h e R A M s e t u p . T h e s e a r e n o t i n t h e
* bss, s i n c e t h e i r v a l u e s a r e d e t e r m i n e d a n d w r i t t e n b e f o r e t h e b s s
* has b e e n c l e a r e d .
* /
_rambase :
.long 0
_ramvec :
.long 0
_ramstart :
.long 0
_ramend :
.long 0
2009-09-18 13:49:36 -04:00
# if d e f i n e d ( C O N F I G _ U B O O T )
_init_sp :
.long 0
# endif
2005-04-16 15:20:36 -07:00
/*****************************************************************************/
2008-07-11 15:29:36 +10:00
_ _ HEAD
2005-04-16 15:20:36 -07:00
2011-10-14 15:35:37 +10:00
# ifdef C O N F I G _ M M U
_start0 :
jmp _ s t a r t
.global kernel_pg_dir
.equ kernel_ p g _ d i r ,_ s t a r t 0
.equ . , _ start0 + 0 x10 0 0
# endif
2005-04-16 15:20:36 -07:00
/ *
* This i s t h e c o d e s f i r s t e n t r y p o i n t . T h i s i s w h e r e i t a l l
* begins. . .
* /
_start :
nop / * f i l l e r * /
movew #0x2700 , % s r / * n o i n t e r r u p t s * /
2011-11-15 15:26:28 +10:00
movel #C A C H E _ I N I T , % d 0 / * d i s a b l e c a c h e * /
movec % d0 ,% C A C R
nop
2009-09-18 13:49:36 -04:00
# if d e f i n e d ( C O N F I G _ U B O O T )
movel % s p ,_ i n i t _ s p / * s a v e i n i t i a l s t a c k p o i n t e r * /
# endif
2011-11-23 14:46:36 +10:00
# ifdef C O N F I G _ M B A R
movel #C O N F I G _ M B A R + 1 ,% d0 / * c o n f i g u r e d M B A R a d d r e s s * /
movec % d0 ,% M B A R / * s e t i t * /
# endif
2005-04-16 15:20:36 -07:00
/ *
* Do a n y p l a t f o r m o r b o a r d s p e c i f i c s e t u p n o w . M o s t b o a r d s
* don' t n e e d a n y t h i n g . T h o s e e x c e p t i o n s a r e d e f i n e t h i s i n
* their b o a r d s p e c i f i c i n c l u d e s .
* /
PLATFORM_ S E T U P
/ *
* Create b a s i c m e m o r y c o n f i g u r a t i o n . S e t V B R a c c o r d i n g l y ,
* and s i z e m e m o r y .
* /
2006-06-26 16:33:09 +10:00
movel #C O N F I G _ V E C T O R B A S E , % a 7
2005-04-16 15:20:36 -07:00
movec % a7 ,% V B R / * s e t v e c t o r s a d d r * /
movel % a7 ,_ r a m v e c
2006-06-26 16:33:09 +10:00
movel #C O N F I G _ R A M B A S E , % a 7 / * m a r k t h e b a s e o f R A M * /
2005-04-16 15:20:36 -07:00
movel % a7 ,_ r a m b a s e
GET_ M E M _ S I Z E / * m a c r o c o d e d e t e r m i n e s s i z e * /
2005-09-02 10:42:52 +10:00
addl % a7 ,% d0
2005-04-16 15:20:36 -07:00
movel % d0 ,_ r a m e n d / * s e t e n d r a m a d d r * /
/ *
* Now t h a t w e k n o w w h a t t h e m e m o r y i s , l e t s e n a b l e c a c h e
2010-11-09 13:35:55 +10:00
* and g e t t h i n g s m o v i n g . T h i s i s C o l d f i r e C P U s p e c i f i c . N o t
* all v e r s i o n c o r e s h a v e i d e n t i c a l c a c h e r e g i s t e r s e t u p . B u t
* it i s v e r y s i m i l a r . D e f i n e t h e e x a c t s e t t i n g s i n t h e h e a d e r s
* then t h e c o d e h e r e i s t h e s a m e f o r a l l .
2005-04-16 15:20:36 -07:00
* /
2010-11-09 13:35:55 +10:00
movel #A C R 0 _ M O D E ,% d0 / * s e t R A M r e g i o n f o r c a c h i n g * /
movec % d0 ,% A C R 0
movel #A C R 1 _ M O D E ,% d0 / * a n y t h i n g e l s e t o c a c h e ? * /
movec % d0 ,% A C R 1
# ifdef A C R 2 _ M O D E
movel #A C R 2 _ M O D E ,% d0
movec % d0 ,% A C R 2
movel #A C R 3 _ M O D E ,% d0
movec % d0 ,% A C R 3
# endif
movel #C A C H E _ M O D E , % d 0 / * e n a b l e c a c h e * /
movec % d0 ,% C A C R
nop
2005-04-16 15:20:36 -07:00
2011-10-14 15:35:37 +10:00
# ifdef C O N F I G _ M M U
/ *
* Identity m a p p i n g f o r t h e k e r n e l r e g i o n .
* /
movel #( M M U B A S E + 1 ) ,% d0 / * e n a b l e M M U B A R r e g i s t e r s * /
movec % d0 ,% M M U B A R
movel #M M U O R _ C A , % d 0 / * c l e a r T L B e n t r i e s * /
movel % d0 ,M M U O R
movel #0 ,% d0 / * s e t A S I D t o 0 * /
movec % d0 ,% a s i d
movel #M M U C R _ E N , % d 0 / * E n a b l e t h e i d e n t i t y m a p * /
movel % d0 ,M M U C R
nop / * s y n c i - p i p e l i n e * /
movel #_ v s t a r t , % a 0 / * j u m p t o " v i r t u a l " s p a c e * /
jmp % a0 @
_vstart :
# endif / * C O N F I G _ M M U * /
2005-04-16 15:20:36 -07:00
# ifdef C O N F I G _ R O M F S _ F S
/ *
* Move R O M f i l e s y s t e m a b o v e b s s : - )
* /
2012-05-31 21:46:03 +02:00
lea _ _ b s s _ s t a r t ,% a0 / * g e t s t a r t o f b s s * /
lea _ _ b s s _ s t o p ,% a1 / * s e t u p d e s t i n a t i o n * /
2005-04-16 15:20:36 -07:00
movel % a0 ,% a2 / * c o p y o f b s s s t a r t * /
movel 8 ( % a0 ) ,% d0 / * g e t s i z e o f R O M F S * /
addql #8 ,% d0 / * a l l o w f o r r o u n d i n g * /
andl #0xfffffffc , % d0 / * w h o l e w o r d s * /
addl % d0 ,% a0 / * c o p y f r o m e n d * /
addl % d0 ,% a1 / * c o p y f r o m e n d * /
movel % a1 ,_ r a m s t a r t / * s e t s t a r t o f r a m * /
_copy_romfs :
movel - ( % a0 ) ,% d0 / * c o p y d w o r d * /
movel % d0 ,- ( % a1 )
cmpl % a0 ,% a2 / * c h e c k i f a t e n d * /
bne _ c o p y _ r o m f s
# else / * C O N F I G _ R O M F S _ F S * /
2012-05-31 21:46:03 +02:00
lea _ _ b s s _ s t o p ,% a1
2005-04-16 15:20:36 -07:00
movel % a1 ,_ r a m s t a r t
# endif / * C O N F I G _ R O M F S _ F S * /
/ *
* Zero o u t t h e b s s r e g i o n .
* /
2012-05-31 21:46:03 +02:00
lea _ _ b s s _ s t a r t ,% a0 / * g e t s t a r t o f b s s * /
lea _ _ b s s _ s t o p ,% a1 / * g e t e n d o f b s s * /
2005-04-16 15:20:36 -07:00
clrl % d0 / * s e t v a l u e * /
_clear_bss :
movel % d0 ,( % a0 ) + / * c l e a r e a c h w o r d * /
cmpl % a0 ,% a1 / * c h e c k i f a t e n d * /
bne _ c l e a r _ b s s
/ *
* Load t h e c u r r e n t t a s k p o i n t e r a n d s t a c k .
* /
lea i n i t _ t h r e a d _ u n i o n ,% a0
lea T H R E A D _ S I Z E ( % a0 ) ,% s p
2011-10-14 15:35:37 +10:00
# ifdef C O N F I G _ M M U
.global m68k_cputype
.global m68k_mmutype
.global m68k_fputype
.global m68k_machtype
movel #C P U _ C O L D F I R E , % d 0
movel % d0 ,m 6 8 k _ c p u t y p e / * M a r k u s a s a C o l d F i r e * /
movel #M M U _ C O L D F I R E , % d 0
movel % d0 ,m 6 8 k _ m m u t y p e
movel #F P U _ C O L D F I R E , % d 0
movel % d0 ,m 6 8 k _ f p u t y p e
2016-08-25 23:10:59 +10:00
movel #M A C H I N E , % d 0
movel % d0 ,m 6 8 k _ m a c h t y p e / * M a r k m a c h i n e t y p e * /
2011-10-14 15:35:37 +10:00
lea i n i t _ t a s k ,% a2 / * S e t " c u r r e n t " i n i t t a s k * /
# endif
2005-04-16 15:20:36 -07:00
/ *
2016-05-21 13:57:20 +02:00
* Assembler s t a r t u p d o n e , s t a r t c o d e p r o p e r .
2005-04-16 15:20:36 -07:00
* /
jsr s t a r t _ k e r n e l / * s t a r t L i n u x k e r n e l * /
_exit :
jmp _ e x i t / * s h o u l d n e v e r g e t h e r e * /
/*****************************************************************************/