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 .
*
* Copyright ( C ) 1 9 9 4 , 1 9 9 5 W a l d o r f E l e c t r o n i c s
* Written b y R a l f B a e c h l e a n d A n d r e a s B u s s e
2006-07-07 17:07:18 +04:00
* Copyright ( C ) 1 9 9 4 - 9 9 , 2 0 0 3 , 0 6 R a l f B a e c h l e
2005-04-17 02:20:36 +04:00
* Copyright ( C ) 1 9 9 6 P a u l M . A n t o i n e
* Modified f o r D E C S t a t i o n a n d h e n c e R 3 0 0 0 s u p p o r t b y P a u l M . A n t o i n e
* Further m o d i f i c a t i o n s b y D a v i d S . M i l l e r a n d H a r a l d K o e r f g e n
* Copyright ( C ) 1 9 9 9 S i l i c o n G r a p h i c s , I n c .
* Kevin K i s s e l l , k e v i n k @mips.com and Carsten Langgaard, carstenl@mips.com
* Copyright ( C ) 2 0 0 0 M I P S T e c h n o l o g i e s , I n c . A l l r i g h t s r e s e r v e d .
* /
# include < l i n u x / i n i t . h >
# include < l i n u x / t h r e a d s . h >
2007-06-15 01:55:31 +04:00
# include < a s m / a d d r s p a c e . h >
2005-04-17 02:20:36 +04:00
# include < a s m / a s m . h >
2006-04-05 12:45:45 +04:00
# include < a s m / a s m m a c r o . h >
2006-07-07 17:07:18 +04:00
# include < a s m / i r q f l a g s . h >
2005-04-17 02:20:36 +04:00
# include < a s m / r e g d e f . h >
# include < a s m / p a g e . h >
2008-10-04 01:43:38 +04:00
# include < a s m / p g t a b l e - b i t s . h >
2005-04-17 02:20:36 +04:00
# include < a s m / m i p s r e g s . h >
# include < a s m / s t a c k f r a m e . h >
2005-07-14 13:42:32 +04:00
# include < k e r n e l - e n t r y - i n i t . h >
2005-04-17 02:20:36 +04:00
/ *
* inputs a r e t h e t e x t n a s i d i n t 1 , d a t a n a s i d i n t 2 .
* /
.macro MAPPED_KERNEL_SETUP_TLB
# ifdef C O N F I G _ M A P P E D _ K E R N E L
/ *
* This n e e d s t o r e a d t h e n a s i d - a s s u m e 0 f o r n o w .
* Drop i n 0 x f f f f f f f f c00 0 0 0 0 0 i n t l b h i , 0 + V G i n t l b l o _ 0 ,
* 0 + DVG i n t l b l o _ 1 .
* /
dli t 0 , 0 x f f f f f f f f c00 0 0 0 0 0
dmtc0 t 0 , C P 0 _ E N T R Y H I
li t 0 , 0 x1 c00 0 # O f f s e t o f t e x t i n t o n o d e m e m o r y
dsll t 1 , N A S I D _ S H F T # S h i f t t e x t n a s i d i n t o p l a c e
dsll t 2 , N A S I D _ S H F T # S a m e f o r d a t a n a s i d
or t 1 , t 1 , t 0 # P h y s i c a l l o a d a d d r e s s o f k e r n e l t e x t
or t 2 , t 2 , t 0 # P h y s i c a l l o a d a d d r e s s o f k e r n e l d a t a
dsrl t 1 , 1 2 # 4 K p f n
dsrl t 2 , 1 2 # 4 K p f n
dsll t 1 , 6 # G e t p f n i n t o p l a c e
dsll t 2 , 6 # G e t p f n i n t o p l a c e
li t 0 , ( ( _ P A G E _ G L O B A L | _ P A G E _ V A L I D | _ C A C H E _ C A C H A B L E _ C O W ) > > 6 )
or t 0 , t 0 , t 1
mtc0 t 0 , C P 0 _ E N T R Y L O 0 # p h y s a d d r , V G , c a c h e x l w r
li t 0 , ( ( _ P A G E _ G L O B A L | _ P A G E _ V A L I D | _ P A G E _ D I R T Y | _ C A C H E _ C A C H A B L E _ C O W ) > > 6 )
or t 0 , t 0 , t 2
mtc0 t 0 , C P 0 _ E N T R Y L O 1 # p h y s a d d r , D V G , c a c h e x l w r
li t 0 , 0 x1 f f e 0 0 0 # M A P P E D _ K E R N _ T L B M A S K , T L B P G M A S K _ 16 M
mtc0 t 0 , C P 0 _ P A G E M A S K
li t 0 , 0 # K M A P _ I N X
mtc0 t 0 , C P 0 _ I N D E X
li t 0 , 1
mtc0 t 0 , C P 0 _ W I R E D
tlbwi
# else
mtc0 z e r o , C P 0 _ W I R E D
# endif
.endm
/ *
* For t h e m o m e n t d i s a b l e i n t e r r u p t s , m a r k t h e k e r n e l m o d e a n d
* set S T 0 _ K X s o t h a t t h e C P U d o e s n o t s p i t f i r e w h e n u s i n g
* 6 4 - bit a d d r e s s e s . A f u l l i n i t i a l i z a t i o n o f t h e C P U ' s s t a t u s
* register i s d o n e l a t e r i n p e r _ c p u _ t r a p _ i n i t ( ) .
* /
.macro setup_c0_status set c l r
.set push
2006-04-05 12:45:45 +04:00
# ifdef C O N F I G _ M I P S _ M T _ S M T C
/ *
* For S M T C , w e n e e d t o s e t p r i v i l e g e a n d d i s a b l e i n t e r r u p t s o n l y f o r
* the c u r r e n t T C , u s i n g t h e T C S t a t u s r e g i s t e r .
* /
mfc0 t 0 , C P 0 _ T C S T A T U S
/* Fortunately CU 0 is in the same place in both registers */
/* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
li t 1 , S T 0 _ C U 0 | 0 x08 0 0 1 c00
or t 0 , t 1
/* Clear TKSU, leave IXMT */
xori t 0 , 0 x00 0 0 1 8 0 0
mtc0 t 0 , C P 0 _ T C S T A T U S
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
/* We need to leave the global IE bit set, but clear EXL...*/
mfc0 t 0 , C P 0 _ S T A T U S
or t 0 , S T 0 _ C U 0 | S T 0 _ E X L | S T 0 _ E R L | \ s e t | \ c l r
xor t 0 , S T 0 _ E X L | S T 0 _ E R L | \ c l r
mtc0 t 0 , C P 0 _ S T A T U S
# else
2005-04-17 02:20:36 +04:00
mfc0 t 0 , C P 0 _ S T A T U S
or t 0 , S T 0 _ C U 0 | \ s e t | 0 x1 f | \ c l r
xor t 0 , 0 x1 f | \ c l r
mtc0 t 0 , C P 0 _ S T A T U S
.set noreorder
sll z e r o ,3 # e h b
2006-04-05 12:45:45 +04:00
# endif
2005-04-17 02:20:36 +04:00
.set pop
.endm
.macro setup_c0_status_pri
2005-09-04 02:56:16 +04:00
# ifdef C O N F I G _ 6 4 B I T
2005-04-17 02:20:36 +04:00
setup_ c0 _ s t a t u s S T 0 _ K X 0
# else
setup_ c0 _ s t a t u s 0 0
# endif
.endm
.macro setup_c0_status_sec
2005-09-04 02:56:16 +04:00
# ifdef C O N F I G _ 6 4 B I T
2005-04-17 02:20:36 +04:00
setup_ c0 _ s t a t u s S T 0 _ K X S T 0 _ B E V
# else
setup_ c0 _ s t a t u s 0 S T 0 _ B E V
# endif
.endm
2007-06-15 01:55:31 +04:00
# ifndef C O N F I G _ N O _ E X C E P T _ F I L L
2005-04-17 02:20:36 +04:00
/ *
* Reserved s p a c e f o r e x c e p t i o n h a n d l e r s .
* Necessary f o r m a c h i n e s w h i c h l i n k t h e i r k e r n e l s a t K S E G 0 .
* /
.fill 0x400
2007-06-15 01:55:31 +04:00
# endif
2005-04-17 02:20:36 +04:00
EXPORT( _ s t e x t )
2007-10-16 23:05:18 +04:00
# ifdef C O N F I G _ B O O T _ R A W
2005-07-11 15:53:44 +04:00
/ *
* Give u s a f i g h t i n g c h a n c e o f r u n n i n g i f e x e c u t i o n b e i n g s a t t h e
* kernel l o a d a d d r e s s . T h i s i s n e e d e d b e c a u s e t h i s p l a t f o r m d o e s
* not h a v e a E L F l o a d e r y e t .
* /
2008-01-07 18:09:50 +03:00
FEXPORT( _ _ k e r n e l _ e n t r y )
j k e r n e l _ e n t r y
2007-07-10 20:32:56 +04:00
# endif
2005-04-17 02:20:36 +04:00
2008-01-30 15:14:59 +03:00
_ _ REF
2007-10-16 23:05:18 +04:00
2005-04-17 02:20:36 +04:00
NESTED( k e r n e l _ e n t r y , 1 6 , s p ) # k e r n e l e n t r y p o i n t
2005-07-14 13:42:32 +04:00
kernel_ e n t r y _ s e t u p # c p u s p e c i f i c s e t u p
setup_ c0 _ s t a t u s _ p r i
2005-04-17 02:20:36 +04:00
2007-09-13 22:23:48 +04:00
/ * We m i g h t n o t g e t l a u n c h e d a t t h e a d d r e s s t h e k e r n e l i s l i n k e d t o ,
so w e j u m p t h e r e . * /
PTR_ L A t 0 , 0 f
jr t 0
0 :
2005-04-17 02:20:36 +04:00
2006-04-05 12:45:45 +04:00
# ifdef C O N F I G _ M I P S _ M T _ S M T C
/ *
* In S M T C k e r n e l , " C L I " i s t h r e a d - s p e c i f i c , i n T C S t a t u s .
* We s t i l l n e e d t o e n a b l e i n t e r r u p t s g l o b a l l y i n S t a t u s ,
* and c l e a r E X L / E R L .
*
* TCContext i s u s e d t o t r a c k i n t e r r u p t l e v e l s u n d e r
* service i n S M T C k e r n e l . C l e a r f o r b o o t T C b e f o r e
* allowing a n y i n t e r r u p t s .
* /
mtc0 z e r o , C P 0 _ T C C O N T E X T
mfc0 t 0 , C P 0 _ S T A T U S
ori t 0 , t 0 , 0 x f f1 f
xori t 0 , t 0 , 0 x00 1 e
mtc0 t 0 , C P 0 _ S T A T U S
# endif / * C O N F I G _ M I P S _ M T _ S M T C * /
2005-04-17 02:20:36 +04:00
PTR_ L A t 0 , _ _ b s s _ s t a r t # c l e a r . b s s
LONG_ S z e r o , ( t 0 )
PTR_ L A t 1 , _ _ b s s _ s t o p - L O N G S I Z E
1 :
PTR_ A D D I U t 0 , L O N G S I Z E
LONG_ S z e r o , ( t 0 )
bne t 0 , t 1 , 1 b
LONG_ S a0 , f w _ a r g 0 # f i r m w a r e a r g u m e n t s
LONG_ S a1 , f w _ a r g 1
LONG_ S a2 , f w _ a r g 2
LONG_ S a3 , f w _ a r g 3
2005-04-01 18:07:13 +04:00
MTC0 z e r o , C P 0 _ C O N T E X T # c l e a r c o n t e x t r e g i s t e r
2005-04-17 02:20:36 +04:00
PTR_ L A $ 2 8 , i n i t _ t h r e a d _ u n i o n
2009-07-08 21:07:50 +04:00
/* Set the SP after an empty pt_regs. */
PTR_ L I s p , _ T H R E A D _ S I Z E - 3 2 - P T _ S I Z E
2006-10-24 05:29:01 +04:00
PTR_ A D D U s p , $ 2 8
2009-10-14 01:23:28 +04:00
back_ t o _ b a c k _ c0 _ h a z a r d
2005-04-17 02:20:36 +04:00
set_ s a v e d _ s p s p , t 0 , t 1
PTR_ S U B U s p , 4 * S Z R E G # i n i t s t a c k p o i n t e r
j s t a r t _ k e r n e l
END( k e r n e l _ e n t r y )
2008-03-08 12:56:28 +03:00
_ _ CPUINIT
2005-07-11 15:53:44 +04:00
2005-04-17 02:20:36 +04:00
# ifdef C O N F I G _ S M P
/ *
* SMP s l a v e c p u s e n t r y p o i n t . B o a r d s p e c i f i c c o d e f o r b o o t s t r a p c a l l s t h i s
* function a f t e r s e t t i n g u p t h e s t a c k a n d g p r e g i s t e r s .
* /
NESTED( s m p _ b o o t s t r a p , 1 6 , s p )
2006-04-05 12:45:45 +04:00
# ifdef C O N F I G _ M I P S _ M T _ S M T C
/ *
* Read- m o d i f y - w r i t e s o f S t a t u s m u s t b e a t o m i c , a n d t h i s
* is o n e c a s e w h e r e C L I i s i n v o k e d w i t h o u t E X L b e i n g
* necessarily s e t . T h e C L I a n d s e t u p _ c0 _ s t a t u s w i l l
* in f a c t b e r e d u n d a n t f o r a l l b u t t h e f i r s t T C o f
* each V P E b e i n g b o o t e d .
* /
DMT 1 0 # d m t t 2 / * t 0 , t 1 a r e u s e d b y C L I a n d s e t u p _ c0 _ s t a t u s ( ) * /
jal m i p s _ i h b
# endif / * C O N F I G _ M I P S _ M T _ S M T C * /
2005-04-17 02:20:36 +04:00
setup_ c0 _ s t a t u s _ s e c
2005-07-14 13:42:32 +04:00
smp_ s l a v e _ s e t u p
2006-04-05 12:45:45 +04:00
# ifdef C O N F I G _ M I P S _ M T _ S M T C
andi t 2 , t 2 , V P E C O N T R O L _ T E
beqz t 2 , 2 f
EMT # e m t
2 :
# endif / * C O N F I G _ M I P S _ M T _ S M T C * /
2005-04-17 02:20:36 +04:00
j s t a r t _ s e c o n d a r y
END( s m p _ b o o t s t r a p )
# endif / * C O N F I G _ S M P * /
_ _ FINIT