2005-04-17 02:20:36 +04:00
/ *
2007-11-28 14:19:38 +03:00
* arch/ s h / k e r n e l / h e a d _ 6 4 . S
2005-04-17 02:20:36 +04:00
*
* Copyright ( C ) 2 0 0 0 , 2 0 0 1 P a o l o A l b e r e l l i
* Copyright ( C ) 2 0 0 3 , 2 0 0 4 P a u l M u n d t
*
2007-11-28 14:19:38 +03: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 .
2005-04-17 02:20:36 +04:00
* /
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 < a s m / p a g e . h >
# include < a s m / c a c h e . h >
# include < a s m / t l b . h >
2008-07-29 03:09:44 +04:00
# include < c p u / r e g i s t e r s . h >
# include < c p u / m m u _ c o n t e x t . h >
2005-04-17 02:20:36 +04:00
# include < a s m / t h r e a d _ i n f o . h >
/ *
* MMU d e f i n e s : T L B b o u n d a r i e s .
* /
# define M M U I R _ F I R S T I T L B _ F I X E D
# define M M U I R _ E N D I T L B _ L A S T _ V A R _ U N R E S T R I C T E D + T L B _ S T E P
# define M M U I R _ S T E P T L B _ S T E P
# define M M U D R _ F I R S T D T L B _ F I X E D
# define M M U D R _ E N D D T L B _ L A S T _ V A R _ U N R E S T R I C T E D + T L B _ S T E P
# define M M U D R _ S T E P T L B _ S T E P
2007-11-21 09:34:33 +03:00
/* Safety check : CONFIG_PAGE_OFFSET has to be a multiple of 512Mb */
# if ( C O N F I G _ P A G E _ O F F S E T & ( ( 1 U L < < 2 9 ) - 1 ) )
# error " C O N F I G _ P A G E _ O F F S E T m u s t b e a m u l t i p l e o f 5 1 2 M b "
2005-04-17 02:20:36 +04:00
# endif
/ *
* MMU d e f i n e s : F i x e d T L B s .
* /
/* Deal safely with the case where the base of RAM is not 512Mb aligned */
# define A L I G N _ 5 1 2 M _ M A S K ( 0 x f f f f f f f f e 0 0 0 0 0 0 0 )
2007-11-21 09:34:33 +03:00
# define A L I G N E D _ E F F E C T I V E ( ( C O N F I G _ P A G E _ O F F S E T + C O N F I G _ M E M O R Y _ S T A R T ) & A L I G N _ 5 1 2 M _ M A S K )
2005-04-17 02:20:36 +04:00
# define A L I G N E D _ P H Y S I C A L ( C O N F I G _ M E M O R Y _ S T A R T & A L I G N _ 5 1 2 M _ M A S K )
# define M M U I R _ T E X T _ H ( 0 x00 0 0 0 0 0 0 0 0 0 0 0 0 0 3 | A L I G N E D _ E F F E C T I V E )
/* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
# define M M U I R _ T E X T _ L ( 0 x00 0 0 0 0 0 0 0 0 0 0 0 0 9 a | A L I G N E D _ P H Y S I C A L )
/* 512 Mb, Cacheable, Write-back, execute, Not User, Ph. Add. */
# define M M U D R _ C A C H E D _ H 0 x00 0 0 0 0 0 0 0 0 0 0 0 0 0 3 | A L I G N E D _ E F F E C T I V E
/* Enabled, Shared, ASID 0, Eff. Add. 0xA0000000 */
# define M M U D R _ C A C H E D _ L 0 x00 0 0 0 0 0 0 0 0 0 0 0 1 5 a | A L I G N E D _ P H Y S I C A L
/* 512 Mb, Cacheable, Write-back, read/write, Not User, Ph. Add. */
2007-11-21 10:04:12 +03:00
# ifdef C O N F I G _ C A C H E _ O F F
2005-04-17 02:20:36 +04:00
# define I C C R 0 _ I N I T _ V A L I C C R 0 _ O F F / * I C A C H E o f f * /
# else
# define I C C R 0 _ I N I T _ V A L I C C R 0 _ O N | I C C R 0 _ I C I / * I C E + I C I * /
# endif
# define I C C R 1 _ I N I T _ V A L I C C R 1 _ N O L O C K / * N o l o c k i n g * /
2007-11-21 10:04:12 +03:00
# if d e f i n e d ( C O N F I G _ C A C H E _ O F F )
2005-04-17 02:20:36 +04:00
# define O C C R 0 _ I N I T _ V A L O C C R 0 _ O F F / * D - c a c h e : o f f * /
2007-11-21 10:04:12 +03:00
# elif d e f i n e d ( C O N F I G _ C A C H E _ W R I T E T H R O U G H )
2005-04-17 02:20:36 +04:00
# define O C C R 0 _ I N I T _ V A L O C C R 0 _ O N | O C C R 0 _ O C I | O C C R 0 _ W T / * D - c a c h e : o n , * /
/* WT, invalidate */
2007-11-21 10:04:12 +03:00
# elif d e f i n e d ( C O N F I G _ C A C H E _ W R I T E B A C K )
2005-04-17 02:20:36 +04:00
# define O C C R 0 _ I N I T _ V A L O C C R 0 _ O N | O C C R 0 _ O C I | O C C R 0 _ W B / * D - c a c h e : o n , * /
/* WB, invalidate */
# else
2007-11-21 10:04:12 +03:00
# error p r e p r o c e s s o r f l a g C O N F I G _ C A C H E _ . . . n o t r e c o g n i z e d !
2005-04-17 02:20:36 +04:00
# endif
# define O C C R 1 _ I N I T _ V A L O C C R 1 _ N O L O C K / * N o l o c k i n g * /
.section .empty_zero_page , " aw"
.global empty_zero_page
empty_zero_page :
.long 1 /* MOUNT_ROOT_RDONLY */
.long 0 /* RAMDISK_FLAGS */
.long 0x0200 /* ORIG_ROOT_DEV */
.long 1 /* LOADER_TYPE */
.long 0x00800000 /* INITRD_START */
.long 0x00800000 /* INITRD_SIZE */
.long 0
.text
.balign 4 0 9 6 , 0 , 4 0 9 6
.section .data , " aw"
.balign PAGE_SIZE
.section .data , " aw"
.balign PAGE_SIZE
2007-11-19 13:08:49 +03:00
.global mmu_pdtp_cache
mmu_pdtp_cache :
2005-04-17 02:20:36 +04:00
.space PAGE_ S I Z E , 0
.global empty_bad_page
empty_bad_page :
.space PAGE_ S I Z E , 0
.global empty_bad_pte_table
empty_bad_pte_table :
.space PAGE_ S I Z E , 0
.global fpu_in_use
fpu_in_use : .quad 0
2009-04-26 06:11:07 +04:00
_ _ HEAD
2005-04-17 02:20:36 +04:00
.balign L1_CACHE_BYTES
/ *
* Condition a t t h e e n t r y o f _ _ s t e x t :
* . Reset s t a t e :
* . SR. F D = 1 ( F P U d i s a b l e d )
* . SR. B L = 1 ( E x c e p t i o n s d i s a b l e d )
* . SR. M D = 1 ( P r i v i l e g e d M o d e )
* . SR. M M U = 0 ( M M U D i s a b l e d )
* . SR. C D = 0 ( C T C U s e r V i s i b l e )
* . SR. I M A S K = U n d e f i n e d ( I n t e r r u p t M a s k )
*
* Operations s u p p o s e d t o b e p e r f o r m e d b y _ _ s t e x t :
* . prevent s p e c u l a t i v e f e t c h o n t o d e v i c e m e m o r y w h i l e M M U i s o f f
* . reflect a s m u c h a s p o s s i b l e S H 5 A B I ( r15 , r26 , r27 , r18 )
* . first, s a v e C P U s t a t e a n d s e t i t t o s o m e t h i n g h a r m l e s s
* . any C P U d e t e c t i o n a n d / o r e n d i a n n e s s s e t t i n g s ( ? )
* . initialize E M I / L M I ( b u t n o t T M U / R T C / I N T C / S C I F ) : T B D
* . set i n i t i a l T L B e n t r i e s f o r c a c h e d a n d u n c a c h e d r e g i o n s
* ( no f i n e g r a n u l a r i t y p a g i n g )
* . set i n i t i a l c a c h e s t a t e
* . enable M M U a n d c a c h e s
* . set C P U t o a c o n s i s t e n t s t a t e
* . registers ( i n c l u d i n g s t a c k p o i n t e r a n d c u r r e n t / K C R 0 )
* . NOT e x p e c t i n g t o s e t E x c e p t i o n h a n d l i n g n o r V B R / R E S V E C / D C R
* at t h i s s t a g e . T h i s i s a l l t o l a t e r L i n u x i n i t i a l i z a t i o n s t e p s .
* . initialize F P U
* . clear B S S
* . jump i n t o s t a r t _ k e r n e l ( )
* . be p r e p a r e d t o h o p e l e s s s t a r t _ k e r n e l ( ) r e t u r n s .
*
* /
.global _stext
_stext :
/ *
* Prevent s p e c u l a t i v e f e t c h o n d e v i c e m e m o r y d u e t o
* uninitialized t a r g e t r e g i s t e r s .
* /
ptabs/ u Z E R O , t r0
ptabs/ u Z E R O , t r1
ptabs/ u Z E R O , t r2
ptabs/ u Z E R O , t r3
ptabs/ u Z E R O , t r4
ptabs/ u Z E R O , t r5
ptabs/ u Z E R O , t r6
ptabs/ u Z E R O , t r7
synci
/ *
* Read/ S e t C P U s t a t e . A f t e r t h i s b l o c k :
* r2 9 = I n i t i a l S R
* /
getcon S R , r29
movi S R _ H A R M L E S S , r20
putcon r20 , S R
/ *
* Initialize E M I / L M I . T o B e D o n e .
* /
/ *
* CPU d e t e c t i o n a n d / o r e n d i a n n e s s s e t t i n g s ( ? ) . T o B e D o n e .
* Pure P I C c o d e h e r e , p l e a s e ! J u s t s a v e s t a t e i n t o r30 .
* After t h i s b l o c k :
* r3 0 = C P U t y p e / P l a t f o r m E n d i a n n e s s
* /
/ *
* Set i n i t i a l T L B e n t r i e s f o r c a c h e d a n d u n c a c h e d r e g i o n s .
* Note : PTA/ B L I N K i s P I C c o d e , P T A B S / B L I N K i s n ' t !
* /
/* Clear ITLBs */
pta c l e a r _ I T L B , t r1
movi M M U I R _ F I R S T , r21
movi M M U I R _ E N D , r22
clear_ITLB :
putcfg r21 , 0 , Z E R O / * C l e a r M M U I R [ n ] . P T E H . V * /
addi r21 , M M U I R _ S T E P , r21
bne r21 , r22 , t r1
/* Clear DTLBs */
pta c l e a r _ D T L B , t r1
movi M M U D R _ F I R S T , r21
movi M M U D R _ E N D , r22
clear_DTLB :
putcfg r21 , 0 , Z E R O / * C l e a r M M U D R [ n ] . P T E H . V * /
addi r21 , M M U D R _ S T E P , r21
bne r21 , r22 , t r1
/* Map one big (512Mb) page for ITLB */
movi M M U I R _ F I R S T , r21
movi M M U I R _ T E X T _ L , r22 / * P T E L f i r s t * /
add. l r22 , r63 , r22 / * S i g n e x t e n d * /
putcfg r21 , 1 , r22 / * S e t M M U I R [ 0 ] . P T E L * /
movi M M U I R _ T E X T _ H , r22 / * P T E H l a s t * /
add. l r22 , r63 , r22 / * S i g n e x t e n d * /
putcfg r21 , 0 , r22 / * S e t M M U I R [ 0 ] . P T E H * /
/* Map one big CACHED (512Mb) page for DTLB */
movi M M U D R _ F I R S T , r21
movi M M U D R _ C A C H E D _ L , r22 / * P T E L f i r s t * /
add. l r22 , r63 , r22 / * S i g n e x t e n d * /
putcfg r21 , 1 , r22 / * S e t M M U D R [ 0 ] . P T E L * /
movi M M U D R _ C A C H E D _ H , r22 / * P T E H l a s t * /
add. l r22 , r63 , r22 / * S i g n e x t e n d * /
putcfg r21 , 0 , r22 / * S e t M M U D R [ 0 ] . P T E H * /
/ *
* Setup a D T L B t r a n s l a t i o n f o r S C I F p h y s .
* /
addi r21 , M M U D R _ S T E P , r21
movi 0 x0 a03 , r22 / * S C I F p h y s * /
shori 0 x01 4 8 , r22
putcfg r21 , 1 , r22 / * P T E L f i r s t * /
movi 0 x f a03 , r22 / * 0 x f a03 0 0 0 0 , f i x e d S C I F v i r t * /
shori 0 x00 0 3 , r22
putcfg r21 , 0 , r22 / * P T E H l a s t * /
/ *
* Set c a c h e b e h a v i o u r s .
* /
/* ICache */
movi I C C R _ B A S E , r21
movi I C C R 0 _ I N I T _ V A L , r22
movi I C C R 1 _ I N I T _ V A L , r23
putcfg r21 , I C C R _ R E G 0 , r22
putcfg r21 , I C C R _ R E G 1 , r23
/* OCache */
movi O C C R _ B A S E , r21
movi O C C R 0 _ I N I T _ V A L , r22
movi O C C R 1 _ I N I T _ V A L , r23
putcfg r21 , O C C R _ R E G 0 , r22
putcfg r21 , O C C R _ R E G 1 , r23
/ *
* Enable C a c h e s a n d M M U . D o t h e f i r s t n o n - P I C j u m p .
* Now h e a d . S g l o b a l v a r i a b l e s , c o n s t a n t s a n d e x t e r n s
* can b e u s e d .
* /
getcon S R , r21
movi S R _ E N A B L E _ M M U , r22
or r21 , r22 , r21
putcon r21 , S S R
movi h y p e r s p a c e , r22
ori r22 , 1 , r22 / * M a k e i t S H m e d i a , n o t r e q u i r e d b u t . . * /
putcon r22 , S P C
synco
rte / * A n d n o w g o i n t o t h e h y p e r s p a c e . . . * /
hyperspace : /* ... that's the next instruction ! */
/ *
* Set C P U t o a c o n s i s t e n t s t a t e .
* r3 1 = F P U s u p p o r t f l a g
* tr0 / t r7 i n u s e . O t h e r s g i v e a c h a n c e t o l o o p s o m e w h e r e s a f e
* /
movi s t a r t _ k e r n e l , r32
ori r32 , 1 , r32
ptabs r32 , t r0 / * r32 = _ s t a r t _ k e r n e l a d d r e s s * /
pta/ u h o p e l e s s , t r1
pta/ u h o p e l e s s , t r2
pta/ u h o p e l e s s , t r3
pta/ u h o p e l e s s , t r4
pta/ u h o p e l e s s , t r5
pta/ u h o p e l e s s , t r6
pta/ u h o p e l e s s , t r7
gettr t r1 , r28 / * r28 = h o p e l e s s a d d r e s s * /
/* Set initial stack pointer */
movi i n i t _ t h r e a d _ u n i o n , S P
putcon S P , K C R 0 / * S e t c u r r e n t t o i n i t _ t a s k * /
movi T H R E A D _ S I Z E , r22 / * P o i n t t o t h e e n d * /
add S P , r22 , S P
/ *
* Initialize F P U .
* Keep F P U f l a g i n r31 . A f t e r t h i s b l o c k :
* r3 1 = F P U f l a g
* /
movi f p u _ i n _ u s e , r31 / * T e m p o r a r y * /
# ifdef C O N F I G _ S H _ F P U
getcon S R , r21
movi S R _ E N A B L E _ F P U , r22
and r21 , r22 , r22
putcon r22 , S R / * T r y t o e n a b l e * /
getcon S R , r22
xor r21 , r22 , r21
shlri r21 , 1 5 , r21 / * S u p p o s e d l y 0 / 1 * /
st. q r31 , 0 , r21 / * S e t f p u _ i n _ u s e * /
# else
movi 0 , r21
st. q r31 , 0 , r21 / * S e t f p u _ i n _ u s e * /
# endif
or r21 , Z E R O , r31 / * S e t F P U f l a g a t l a s t * /
# 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
* /
pta c l e a r _ q u a d , t r1
movi _ _ b s s _ s t a r t , r22
movi _ e n d , r23
clear_quad :
st. q r22 , 0 , Z E R O
addi r22 , 8 , r22
bne r22 , r23 , t r1 / * B o t h q u a d a l i g n e d , s e e v m l i n u x . l d s . S * /
# endif
pta/ u h o p e l e s s , t r1
/* Say bye to head.S but be prepared to wrongly get back ... */
blink t r0 , L I N K
/* If we ever get back here through LINK/tr1-tr7 */
pta/ u h o p e l e s s , t r7
hopeless :
/ *
* Something' s b a d l y w r o n g h e r e . L o o p e n d l e s s l y ,
* there' s n o t h i n g m o r e w e c a n d o a b o u t i t .
*
* Note o n h o p e l e s s : i t c a n b e j u m p e d i n t o i n v a r i a b l y
* before o r a f t e r j u m p i n g i n t o h y p e r s p a c e . T h e o n l y
* requirement i s t o b e P I C c a l l e d ( P T A ) b e f o r e a n d
* any w a y ( P T A / P T A B S ) a f t e r . A c c o r d i n g t o V i r t u a l
* to P h y s i c a l m a p p i n g a s i m u l a t o r / e m u l a t o r c a n e a s i l y
* tell w h e r e w e c a m e h e r e f r o m j u s t l o o k i n g a t h o p e l e s s
* ( PC) a d d r e s s .
*
* For d e b u g g i n g p u r p o s e s :
* ( r2 8 ) h o p e l e s s / l o o p a d d r e s s
* ( r2 9 ) O r i g i n a l S R
* ( r3 0 ) C P U t y p e / P l a t f o r m e n d i a n n e s s
* ( r3 1 ) F P U S u p p o r t
* ( r3 2 ) _ s t a r t _ k e r n e l a d d r e s s
* /
blink t r7 , Z E R O