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 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 >
2014-11-07 16:13:54 +03:00
/* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
# undef f p
2005-04-17 02:20:36 +04:00
/ *
* 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 )
2014-05-29 01:52:04 +04:00
# ifndef U S E _ A L T E R N A T E _ R E S U M E _ I M P L
2005-04-17 02:20:36 +04:00
/ *
* 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 ,
2014-01-27 19:23:11 +04:00
* struct t h r e a d _ i n f o * n e x t _ t i , s32 f p _ s a v e )
2005-04-17 02:20:36 +04:00
* /
.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 )
/ *
2014-01-27 19:23:11 +04:00
* Check w h e t h e r w e n e e d t o s a v e a n y F P c o n t e x t . F P c o n t e x t i s s a v e d
* iff t h e p r o c e s s h a s u s e d t h e c o n t e x t w i t h t h e s c a l a r F P U o r t h e M S A
* ASE i n t h e c u r r e n t t i m e 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 a n d
* _ TIF_ U S E D M S A r e s p e c t i v e l y . s w i t c h _ t o w i l l h a v e s e t f p _ s a v e
* accordingly t o a n F P _ S A V E _ e n u m v a l u e .
2005-04-17 02:20:36 +04:00
* /
2014-01-27 19:23:11 +04:00
beqz a3 , 2 f
2005-04-17 02:20:36 +04:00
/ *
2014-01-27 19:23:11 +04:00
* We d o . C l e a r t h e s a v e d C U 1 b i t f o r p r e v , s u c h t h a t n e x t t i m e i t i s
* scheduled i t w i l l s t a r t i n u s e r l a n d w i t h t h e F P U d i s a b l e d . I f t h e
* task u s e s t h e F P U t h e n i t w i l l b e e n a b l e d a g a i n v i a t h e d o _ c p u t r a p .
* This a l l o w s u s t o l a z i l y r e s t o r e t h e F P c o n t e x t .
2005-04-17 02:20:36 +04:00
* /
2014-01-27 19:23:11 +04:00
PTR_ L t 3 , T A S K _ T H R E A D _ I N F O ( a0 )
2005-04-17 02:20:36 +04:00
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 )
2014-01-27 19:23:11 +04:00
/* Check whether we're saving scalar or vector context. */
bgtz a3 , 1 f
2014-07-11 19:44:29 +04:00
/* Save 128b MSA vector context + scalar FP control & status. */
2014-11-07 16:13:54 +03:00
.set push
SET_ H A R D F L O A T
2014-07-11 19:44:29 +04:00
cfc1 t 1 , f c r31
2014-01-27 19:23:11 +04:00
msa_ s a v e _ a l l a0
2014-11-07 16:13:54 +03:00
.set pop /* SET_HARDFLOAT */
2014-07-11 19:44:29 +04:00
sw t 1 , T H R E A D _ F C R 3 1 ( a0 )
2014-01-27 19:23:11 +04:00
b 2 f
1 : /* Save 32b/64b scalar FP context. */
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
2014-01-27 19:23:11 +04:00
2 :
2005-04-17 02:20:36 +04:00
2013-06-17 23:36:07 +04:00
# if d e f i n e d ( C O N F I G _ C C _ S T A C K P R O T E C T O R ) & & ! d e f i n e d ( C O N F I G _ S M P )
2013-10-07 15:14:26 +04:00
PTR_ L A t 8 , _ _ s t a c k _ c h k _ g u a r d
2013-06-17 23:36:07 +04:00
LONG_ L t 9 , T A S K _ S T A C K _ C A N A R Y ( a1 )
LONG_ S t 9 , 0 ( t 8 )
# endif
2005-04-17 02:20:36 +04:00
/ *
* 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
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
move v0 , a0
jr r a
END( r e s u m e )
2014-05-29 01:52:04 +04:00
# endif / * U S E _ A L T E R N A T E _ R E S U M E _ I M P L * /
2005-04-17 02:20:36 +04:00
/ *
* 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 )
2013-11-22 17:12:07 +04:00
# if d e f i n e d ( C O N F I G _ 6 4 B I T ) | | d e f i n e d ( C O N F I G _ C P U _ M I P S 3 2 _ R 2 )
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 )
2013-11-22 17:12:07 +04:00
# if d e f i n e d ( C O N F I G _ 6 4 B I T ) | | d e f i n e d ( C O N F I G _ C P U _ M I P S 3 2 _ R 2 )
2006-05-22 19:47:41 +04:00
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 )
2014-01-27 19:23:11 +04:00
# ifdef C O N F I G _ C P U _ H A S _ M S A
/ *
* Save a t h r e a d ' s M S A v e c t o r c o n t e x t .
* /
LEAF( _ s a v e _ m s a )
msa_ s a v e _ a l l a0
jr r a
END( _ s a v e _ m s a )
/ *
* Restore a t h r e a d ' s M S A v e c t o r c o n t e x t .
* /
LEAF( _ r e s t o r e _ m s a )
msa_ r e s t o r e _ a l l a0
jr r a
END( _ r e s t o r e _ m s a )
2014-07-30 11:53:20 +04:00
LEAF( _ i n i t _ m s a _ u p p e r )
msa_ i n i t _ a l l _ u p p e r
jr r a
END( _ i n i t _ m s a _ u p p e r )
2014-01-27 19:23:11 +04:00
# endif
2005-04-17 02:20:36 +04:00
/ *
* 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
2014-11-07 16:13:54 +03:00
.set push
SET_ H A R D F L O A T
2005-04-17 02:20:36 +04:00
LEAF( _ i n i t _ f p u )
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
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
2013-11-22 17:12:07 +04:00
# ifdef C O N F I G _ C P U _ M I P S 3 2 _ R 2
.set push
2014-11-07 16:13:54 +03:00
.set mips32r2
.set fp=64
2013-11-22 17:12:07 +04:00
sll t 0 , t 0 , 5 # i s S t a t u s . F R s e t ?
bgez t 0 , 1 f # n o : s k i p s e t t i n g u p p e r 32 b
mthc1 t 1 , $ f0
mthc1 t 1 , $ f1
mthc1 t 1 , $ f2
mthc1 t 1 , $ f3
mthc1 t 1 , $ f4
mthc1 t 1 , $ f5
mthc1 t 1 , $ f6
mthc1 t 1 , $ f7
mthc1 t 1 , $ f8
mthc1 t 1 , $ f9
mthc1 t 1 , $ f10
mthc1 t 1 , $ f11
mthc1 t 1 , $ f12
mthc1 t 1 , $ f13
mthc1 t 1 , $ f14
mthc1 t 1 , $ f15
mthc1 t 1 , $ f16
mthc1 t 1 , $ f17
mthc1 t 1 , $ f18
mthc1 t 1 , $ f19
mthc1 t 1 , $ f20
mthc1 t 1 , $ f21
mthc1 t 1 , $ f22
mthc1 t 1 , $ f23
mthc1 t 1 , $ f24
mthc1 t 1 , $ f25
mthc1 t 1 , $ f26
mthc1 t 1 , $ f27
mthc1 t 1 , $ f28
mthc1 t 1 , $ f29
mthc1 t 1 , $ f30
mthc1 t 1 , $ f31
1 : .set p o p
# endif / * C O N F I G _ C P U _ M I P S 3 2 _ R 2 * /
2005-04-17 02:20:36 +04:00
# else
2014-03-30 15:20:10 +04:00
.set arch=r4000
2005-04-17 02:20:36 +04:00
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 )
2014-11-07 16:13:54 +03:00
.set pop /* SET_HARDFLOAT */