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 , 1 9 9 6 , 1 9 9 8 , 1 9 9 9 , 2 0 0 2 , 2 0 0 3 R a l f B a e c h l e
2011-04-05 01:15:29 +04:00
* Copyright ( C ) 1 9 9 6 D a v i d S . M i l l e r ( d a v e m @davemloft.net)
2005-04-17 02:20:36 +04:00
* Copyright ( C ) 1 9 9 4 , 1 9 9 5 , 1 9 9 6 , b y A n d r e a s B u s s e
* Copyright ( C ) 1 9 9 9 S i l i c o n G r a p h i c s , I n c .
* 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 .
* written b y C a r s t e n L a n g g a a r d , c a r s t e n l @mips.com
* /
# include < a s m / a s m . h >
# include < a s m / c a c h e c t l . h >
# include < a s m / f p r e g d e f . h >
# include < a s m / m i p s r e g s . h >
2005-09-10 00:32:31 +04:00
# include < a s m / a s m - o f f s e t s . h >
2005-04-17 02:20:36 +04:00
# include < a s m / p a g e . h >
# include < a s m / p g t a b l e - b i t s . h >
# include < a s m / r e g d e f . h >
# include < a s m / s t a c k f r a m e . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / a s m m a c r o . h >
/ *
* Offset t o t h e c u r r e n t p r o c e s s s t a t u s f l a g s , t h e f i r s t 3 2 b y t e s o f t h e
* stack a r e n o t u s e d .
* /
# define S T _ O F F ( _ T H R E A D _ S I Z E - 3 2 - P T _ S I Z E + P T _ S T A T U S )
/ *
* FPU c o n t e x t i s s a v e d i f f t h e p r o c e s s h a s u s e d i t ' s F P U i n t h e c u r r e n t
* time s l i c e a s i n d i c a t e d b y _ T I F _ U S E D F P U . I n a n y c a s e , t h e C U 1 b i t f o r u s e r
2005-09-04 02:56:17 +04:00
* space S T A T U S r e g i s t e r s h o u l d b e 0 , s o t h a t a p r o c e s s * a l w a y s * s t a r t s i t s
2005-04-17 02:20:36 +04:00
* userland w i t h F P U d i s a b l e d a f t e r e a c h c o n t e x t s w i t c h .
*
* FPU w i l l b e e n a b l e d a s s o o n a s t h e p r o c e s s a c c e s s e s F P U a g a i n , t h r o u g h
* do_ c p u ( ) t r a p .
* /
/ *
* task_ s t r u c t * r e s u m e ( t a s k _ s t r u c t * p r e v , t a s k _ s t r u c t * n e x t ,
* struct t h r e a d _ i n f o * n e x t _ t i )
* /
.align 5
LEAF( r e s u m e )
2007-04-13 21:37:26 +04:00
mfc0 t 1 , C P 0 _ S T A T U S
LONG_ S t 1 , T H R E A D _ S T A T U S ( a0 )
2005-04-17 02:20:36 +04:00
cpu_ s a v e _ n o n s c r a t c h a0
LONG_ S r a , T H R E A D _ R E G 3 1 ( a0 )
/ *
* check i f w e n e e d t o s a v e F P U r e g i s t e r s
* /
PTR_ L t 3 , T A S K _ T H R E A D _ I N F O ( a0 )
LONG_ L t 0 , T I _ F L A G S ( t 3 )
li t 1 , _ T I F _ U S E D F P U
2007-04-13 21:37:26 +04:00
and t 2 , t 0 , t 1
beqz t 2 , 1 f
2005-04-17 02:20:36 +04:00
nor t 1 , z e r o , t 1
and t 0 , t 0 , t 1
LONG_ S t 0 , T I _ F L A G S ( t 3 )
/ *
* clear s a v e d u s e r s t a c k C U 1 b i t
* /
LONG_ L t 0 , S T _ O F F ( t 3 )
li t 1 , ~ S T 0 _ C U 1
and t 0 , t 0 , t 1
LONG_ S t 0 , S T _ O F F ( t 3 )
2006-05-22 19:47:41 +04:00
fpu_ s a v e _ d o u b l e a0 t 0 t 1 # c 0 _ s t a t u s p a s s e d i n t 0
# clobbers t 1
2005-04-17 02:20:36 +04:00
1 :
/ *
* The o r d e r o f r e s t o r i n g t h e r e g i s t e r s t a k e s c a r e o f t h e r a c e
* updating $ 2 8 , $ 2 9 a n d k e r n e l s p w i t h o u t d i s a b l i n g i n t s .
* /
move $ 2 8 , a2
cpu_ r e s t o r e _ n o n s c r a t c h a1
2007-07-11 11:32:21 +04:00
PTR_ A D D U t 0 , $ 2 8 , _ T H R E A D _ S I Z E - 3 2
2005-04-17 02:20:36 +04:00
set_ s a v e d _ s p t 0 , t 1 , t 2
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-modify-writes of Status must be atomic on a VPE */
mfc0 t 2 , C P 0 _ T C S T A T U S
ori t 1 , t 2 , T C S T A T U S _ I X M T
mtc0 t 1 , C P 0 _ T C S T A T U S
andi t 2 , t 2 , T C S T A T U S _ I X M T
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
DMT 8 # d m t t 0
move t 1 ,r a
jal m i p s _ i h b
move r a ,t 1
# 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
mfc0 t 1 , C P 0 _ S T A T U S / * D o w e r e a l l y n e e d t h i s ? * /
li a3 , 0 x f f01
and t 1 , a3
LONG_ L a2 , T H R E A D _ S T A T U S ( a1 )
nor a3 , $ 0 , a3
and a2 , a3
or a2 , t 1
mtc0 a2 , C P 0 _ S T A T U S
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
2006-06-04 01:40:15 +04:00
_ ehb
2006-04-05 12:45:45 +04:00
andi t 0 , t 0 , V P E C O N T R O L _ T E
beqz t 0 , 1 f
emt
1 :
mfc0 t 1 , C P 0 _ T C S T A T U S
xori t 1 , t 1 , T C S T A T U S _ I X M T
or t 1 , t 1 , t 2
mtc0 t 1 , 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
# 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
move v0 , a0
jr r a
END( r e s u m e )
/ *
* Save a t h r e a d ' s f p c o n t e x t .
* /
LEAF( _ s a v e _ f p )
2005-09-04 02:56:16 +04:00
# ifdef C O N F I G _ 6 4 B I T
2006-05-22 19:47:41 +04:00
mfc0 t 0 , C P 0 _ S T A T U S
2005-04-17 02:20:36 +04:00
# endif
2006-05-22 19:47:41 +04:00
fpu_ s a v e _ d o u b l e a0 t 0 t 1 # c l o b b e r s t 1
2005-04-17 02:20:36 +04:00
jr r a
END( _ s a v e _ f p )
/ *
* Restore a t h r e a d ' s f p c o n t e x t .
* /
LEAF( _ r e s t o r e _ f p )
2006-05-22 19:47:41 +04:00
# ifdef C O N F I G _ 6 4 B I T
mfc0 t 0 , C P 0 _ S T A T U S
# endif
fpu_ r e s t o r e _ d o u b l e a0 t 0 t 1 # c l o b b e r s t 1
2005-04-17 02:20:36 +04:00
jr r a
END( _ r e s t o r e _ f p )
/ *
* Load t h e F P U w i t h s i g n a l l i n g N A N S . T h i s b i t p a t t e r n w e ' r e u s i n g h a s
* the p r o p e r t y t h a t n o m a t t e r w h e t h e r c o n s i d e r e d a s s i n g l e o r a s d o u b l e
* precision r e p r e s e n t s s i g n a l i n g N A N S .
*
* We i n i t i a l i z e f c r31 t o r o u n d i n g t o n e a r e s t , n o e x c e p t i o n s .
* /
# define F P U _ D E F A U L T 0 x00 0 0 0 0 0 0
LEAF( _ i n i t _ f p u )
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
/* Rather than manipulate per-VPE Status, set per-TC bit in TCStatus */
mfc0 t 0 , C P 0 _ T C S T A T U S
/* Bit position is the same for Status, TCStatus */
li t 1 , S T 0 _ C U 1
or t 0 , t 1
mtc0 t 0 , C P 0 _ T C S T A T U S
# else / * N o r m a l M I P S C U 1 e n a b l e * /
2005-04-17 02:20:36 +04:00
mfc0 t 0 , C P 0 _ S T A T U S
li t 1 , S T 0 _ C U 1
or t 0 , t 1
mtc0 t 0 , C P 0 _ S T A T U S
2006-04-05 12:45:45 +04:00
# endif / * C O N F I G _ M I P S _ M T _ S M T C * /
2007-05-18 00:36:55 +04:00
enable_ f p u _ h a z a r d
2005-04-17 02:20:36 +04:00
li t 1 , F P U _ D E F A U L T
ctc1 t 1 , f c r31
li t 1 , - 1 # S N a N
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
sll t 0 , t 0 , 5
bgez t 0 , 1 f # 16 / 3 2 r e g i s t e r m o d e ?
dmtc1 t 1 , $ f1
dmtc1 t 1 , $ f3
dmtc1 t 1 , $ f5
dmtc1 t 1 , $ f7
dmtc1 t 1 , $ f9
dmtc1 t 1 , $ f11
dmtc1 t 1 , $ f13
dmtc1 t 1 , $ f15
dmtc1 t 1 , $ f17
dmtc1 t 1 , $ f19
dmtc1 t 1 , $ f21
dmtc1 t 1 , $ f23
dmtc1 t 1 , $ f25
dmtc1 t 1 , $ f27
dmtc1 t 1 , $ f29
dmtc1 t 1 , $ f31
1 :
# endif
2005-09-04 02:56:17 +04:00
2005-04-17 02:20:36 +04:00
# ifdef C O N F I G _ C P U _ M I P S 3 2
mtc1 t 1 , $ f0
mtc1 t 1 , $ f1
mtc1 t 1 , $ f2
mtc1 t 1 , $ f3
mtc1 t 1 , $ f4
mtc1 t 1 , $ f5
mtc1 t 1 , $ f6
mtc1 t 1 , $ f7
mtc1 t 1 , $ f8
mtc1 t 1 , $ f9
mtc1 t 1 , $ f10
mtc1 t 1 , $ f11
mtc1 t 1 , $ f12
mtc1 t 1 , $ f13
mtc1 t 1 , $ f14
mtc1 t 1 , $ f15
mtc1 t 1 , $ f16
mtc1 t 1 , $ f17
mtc1 t 1 , $ f18
mtc1 t 1 , $ f19
mtc1 t 1 , $ f20
mtc1 t 1 , $ f21
mtc1 t 1 , $ f22
mtc1 t 1 , $ f23
mtc1 t 1 , $ f24
mtc1 t 1 , $ f25
mtc1 t 1 , $ f26
mtc1 t 1 , $ f27
mtc1 t 1 , $ f28
mtc1 t 1 , $ f29
mtc1 t 1 , $ f30
mtc1 t 1 , $ f31
# else
.set mips3
dmtc1 t 1 , $ f0
dmtc1 t 1 , $ f2
dmtc1 t 1 , $ f4
dmtc1 t 1 , $ f6
dmtc1 t 1 , $ f8
dmtc1 t 1 , $ f10
dmtc1 t 1 , $ f12
dmtc1 t 1 , $ f14
dmtc1 t 1 , $ f16
dmtc1 t 1 , $ f18
dmtc1 t 1 , $ f20
dmtc1 t 1 , $ f22
dmtc1 t 1 , $ f24
dmtc1 t 1 , $ f26
dmtc1 t 1 , $ f28
dmtc1 t 1 , $ f30
# endif
jr r a
END( _ i n i t _ f p u )