2009-01-08 16:46:40 -08: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 .
*
* Unified i m p l e m e n t a t i o n o f m e m c p y , m e m m o v e a n d t h e _ _ c o p y _ u s e r b a c k e n d .
*
* Copyright ( C ) 1 9 9 8 , 9 9 , 2 0 0 0 , 0 1 , 2 0 0 2 R a l f B a e c h l e ( r a l f @gnu.org)
* Copyright ( C ) 1 9 9 9 , 2 0 0 0 , 0 1 , 2 0 0 2 S i l i c o n G r a p h i c s , I n c .
* Copyright ( C ) 2 0 0 2 B r o a d c o m , I n c .
* memcpy/ c o p y _ u s e r a u t h o r : M a r k V a n d e v o o r d e
*
* Mnemonic n a m e s f o r a r g u m e n t s t o m e m c p y / _ _ c o p y _ u s e r
* /
# include < a s m / a s m . h >
# include < a s m / a s m - o f f s e t s . h >
2016-11-07 11:14:15 +00:00
# include < a s m / e x p o r t . h >
2009-01-08 16:46:40 -08:00
# include < a s m / r e g d e f . h >
# define d s t a0
# define s r c a1
# define l e n a2
/ *
* Spec
*
* memcpy c o p i e s l e n b y t e s f r o m s r c t o d s t a n d s e t s v0 t o d s t .
* It a s s u m e s t h a t
* - src a n d d s t d o n ' t o v e r l a p
* - src i s r e a d a b l e
* - dst i s w r i t a b l e
* memcpy u s e s t h e s t a n d a r d c a l l i n g c o n v e n t i o n
*
* _ _ copy_ u s e r c o p i e s u p t o l e n b y t e s f r o m s r c t o d s t a n d s e t s a2 ( l e n ) t o
* the n u m b e r o f u n c o p i e d b y t e s d u e t o a n e x c e p t i o n c a u s e d b y a r e a d o r w r i t e .
* _ _ copy_ u s e r a s s u m e s t h a t s r c a n d d s t d o n ' t o v e r l a p , a n d t h a t t h e c a l l i s
* implementing o n e o f t h e f o l l o w i n g :
* copy_ t o _ u s e r
* - src i s r e a d a b l e ( n o e x c e p t i o n s w h e n r e a d i n g s r c )
* copy_ f r o m _ u s e r
* - dst i s w r i t a b l e ( n o e x c e p t i o n s w h e n w r i t i n g d s t )
* _ _ copy_ u s e r u s e s a n o n - s t a n d a r d c a l l i n g c o n v e n t i o n ; see
* arch/ m i p s / i n c l u d e / a s m / u a c c e s s . h
*
* When a n e x c e p t i o n h a p p e n s o n a l o a d , t h e h a n d l e r m u s t
# ensure t h a t a l l o f t h e d e s t i n a t i o n b u f f e r i s o v e r w r i t t e n t o p r e v e n t
* leaking i n f o r m a t i o n t o u s e r m o d e p r o g r a m s .
* /
/ *
* Implementation
* /
/ *
* The e x c e p t i o n h a n d l e r f o r l o a d s r e q u i r e s t h a t :
* 1 - AT c o n t a i n t h e a d d r e s s o f t h e b y t e j u s t p a s t t h e e n d o f t h e s o u r c e
* of t h e c o p y ,
* 2 - src_ e n t r y < = s r c < A T , a n d
* 3 - ( dst - s r c ) = = ( d s t _ e n t r y - s r c _ e n t r y ) ,
* The _ e n t r y s u f f i x d e n o t e s v a l u e s w h e n _ _ c o p y _ u s e r w a s c a l l e d .
*
* ( 1 ) is s e t u p u p b y u a c c e s s . h a n d m a i n t a i n e d b y n o t w r i t i n g A T i n c o p y _ u s e r
* ( 2 ) is m e t b y i n c r e m e n t i n g s r c b y t h e n u m b e r o f b y t e s c o p i e d
* ( 3 ) is m e t b y n o t d o i n g l o a d s b e t w e e n a p a i r o f i n c r e m e n t s o f d s t a n d s r c
*
* The e x c e p t i o n h a n d l e r s f o r s t o r e s a d j u s t l e n ( i f n e c e s s a r y ) a n d r e t u r n .
* These h a n d l e r s d o n o t n e e d t o o v e r w r i t e a n y d a t a .
*
* For _ _ r m e m c p y a n d m e m m o v e a n e x c e p t i o n i s a l w a y s a k e r n e l b u g , t h e r e f o r e
* they' r e n o t p r o t e c t e d .
* /
# define E X C ( i n s t _ r e g ,a d d r ,h a n d l e r ) \
9 : inst_ r e g , a d d r ; \
.section _ _ ex_ t a b l e ," a " ; \
PTR 9 b , h a n d l e r ; \
.previous
/ *
* Only o n t h e 6 4 - b i t k e r n e l w e c a n m a d e u s e o f 6 4 - b i t r e g i s t e r s .
* /
# define L O A D l d
# define L O A D L l d l
# define L O A D R l d r
# define S T O R E L s d l
# define S T O R E R s d r
# define S T O R E s d
# define A D D d a d d u
# define S U B d s u b u
# define S R L d s r l
# define S R A d s r a
# define S L L d s l l
# define S L L V d s l l v
# define S R L V d s r l v
# define N B Y T E S 8
# define L O G _ N B Y T E S 3
/ *
* As w e a r e s h a r i n g c o d e b a s e w i t h t h e m i p s32 t r e e ( w h i c h u s e t h e o 3 2 A B I
* register d e f i n i t i o n s ) . W e n e e d t o r e d e f i n e t h e r e g i s t e r d e f i n i t i o n s f r o m
* the n 6 4 A B I r e g i s t e r n a m i n g t o t h e o 3 2 A B I r e g i s t e r n a m i n g .
* /
# undef t 0
# undef t 1
# undef t 2
# undef t 3
# define t 0 $ 8
# define t 1 $ 9
# define t 2 $ 1 0
# define t 3 $ 1 1
# define t 4 $ 1 2
# define t 5 $ 1 3
# define t 6 $ 1 4
# define t 7 $ 1 5
# ifdef C O N F I G _ C P U _ L I T T L E _ E N D I A N
# define L D F I R S T L O A D R
2013-01-22 12:59:30 +01:00
# define L D R E S T L O A D L
2009-01-08 16:46:40 -08:00
# define S T F I R S T S T O R E R
2013-01-22 12:59:30 +01:00
# define S T R E S T S T O R E L
2009-01-08 16:46:40 -08:00
# define S H I F T _ D I S C A R D S L L V
# else
# define L D F I R S T L O A D L
2013-01-22 12:59:30 +01:00
# define L D R E S T L O A D R
2009-01-08 16:46:40 -08:00
# define S T F I R S T S T O R E L
2013-01-22 12:59:30 +01:00
# define S T R E S T S T O R E R
2009-01-08 16:46:40 -08:00
# define S H I F T _ D I S C A R D S R L V
# endif
# define F I R S T ( u n i t ) ( ( u n i t ) * N B Y T E S )
# define R E S T ( u n i t ) ( F I R S T ( u n i t ) + N B Y T E S - 1 )
# define U N I T ( u n i t ) F I R S T ( u n i t )
# define A D D R M A S K ( N B Y T E S - 1 )
.text
.set noreorder
.set noat
/ *
* A c o m b i n e d m e m c p y / _ _ c o p y _ u s e r
* _ _ copy_ u s e r s e t s l e n t o 0 f o r s u c c e s s ; else to an upper bound of
* the n u m b e r o f u n c o p i e d b y t e s .
* memcpy s e t s v0 t o d s t .
* /
.align 5
LEAF( m e m c p y ) / * a0 =dst a1 =src a2 =len * /
2016-11-07 11:14:15 +00:00
EXPORT_ S Y M B O L ( m e m c p y )
2009-01-08 16:46:40 -08:00
move v0 , d s t / * r e t u r n v a l u e * /
__memcpy :
2021-04-08 23:48:46 +02:00
FEXPORT( _ _ r a w _ c o p y _ f r o m _ u s e r )
EXPORT_ S Y M B O L ( _ _ r a w _ c o p y _ f r o m _ u s e r )
FEXPORT( _ _ r a w _ c o p y _ t o _ u s e r )
EXPORT_ S Y M B O L ( _ _ r a w _ c o p y _ t o _ u s e r )
FEXPORT( _ _ r a w _ c o p y _ i n _ u s e r )
EXPORT_ S Y M B O L ( _ _ r a w _ c o p y _ i n _ u s e r )
2009-01-08 16:46:40 -08:00
/ *
* Note : dst & s r c m a y b e u n a l i g n e d , l e n m a y b e 0
* Temps
* /
#
# Octeon d o e s n ' t c a r e i f t h e d e s t i n a t i o n i s u n a l i g n e d . T h e h a r d w a r e
# can f i x i t f a s t e r t h a n w e c a n s p e c i a l c a s e t h e a s s e m b l y .
#
pref 0 , 0 ( s r c )
sltu t 0 , l e n , N B Y T E S # C h e c k i f < 1 w o r d
bnez t 0 , c o p y _ b y t e s _ c h e c k l e n
and t 0 , s r c , A D D R M A S K # C h e c k i f s r c u n a l i g n e d
bnez t 0 , s r c _ u n a l i g n e d
sltu t 0 , l e n , 4 * N B Y T E S # C h e c k i f < 4 w o r d s
bnez t 0 , l e s s _ t h a n _ 4 u n i t s
sltu t 0 , l e n , 8 * N B Y T E S # C h e c k i f < 8 w o r d s
bnez t 0 , l e s s _ t h a n _ 8 u n i t s
sltu t 0 , l e n , 1 6 * N B Y T E S # C h e c k i f < 16 w o r d s
bnez t 0 , c l e a n u p _ b o t h _ a l i g n e d
sltu t 0 , l e n , 1 2 8 + 1 # C h e c k i f l e n < 129
bnez t 0 , 1 f # S k i p p r e f e t c h i f l e n i s t o o s h o r t
sltu t 0 , l e n , 2 5 6 + 1 # C h e c k i f l e n < 257
bnez t 0 , 1 f # S k i p p r e f e t c h i f l e n i s t o o s h o r t
pref 0 , 1 2 8 ( s r c ) # W e m u s t n o t p r e f e t c h i n v a l i d a d d r e s s e s
#
# This i s w h e r e w e l o o p i f t h e r e i s m o r e t h a n 1 2 8 b y t e s l e f t
2 : pref 0 , 2 5 6 ( s r c ) # W e m u s t n o t p r e f e t c h i n v a l i d a d d r e s s e s
#
# This i s w h e r e w e l o o p i f w e c a n ' t p r e f e t c h a n y m o r e
1 :
EXC( L O A D t 0 , U N I T ( 0 ) ( s r c ) , l _ e x c )
EXC( L O A D t 1 , U N I T ( 1 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 2 , U N I T ( 2 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 3 , U N I T ( 3 ) ( s r c ) , l _ e x c _ c o p y )
SUB l e n , l e n , 1 6 * N B Y T E S
EXC( S T O R E t 0 , U N I T ( 0 ) ( d s t ) , s _ e x c _ p16 u )
EXC( S T O R E t 1 , U N I T ( 1 ) ( d s t ) , s _ e x c _ p15 u )
EXC( S T O R E t 2 , U N I T ( 2 ) ( d s t ) , s _ e x c _ p14 u )
EXC( S T O R E t 3 , U N I T ( 3 ) ( d s t ) , s _ e x c _ p13 u )
EXC( L O A D t 0 , U N I T ( 4 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 1 , U N I T ( 5 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 2 , U N I T ( 6 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 3 , U N I T ( 7 ) ( s r c ) , l _ e x c _ c o p y )
EXC( S T O R E t 0 , U N I T ( 4 ) ( d s t ) , s _ e x c _ p12 u )
EXC( S T O R E t 1 , U N I T ( 5 ) ( d s t ) , s _ e x c _ p11 u )
EXC( S T O R E t 2 , U N I T ( 6 ) ( d s t ) , s _ e x c _ p10 u )
ADD s r c , s r c , 1 6 * N B Y T E S
EXC( S T O R E t 3 , U N I T ( 7 ) ( d s t ) , s _ e x c _ p9 u )
ADD d s t , d s t , 1 6 * N B Y T E S
2017-01-09 16:52:28 +00:00
EXC( L O A D t 0 , U N I T ( - 8 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
EXC( L O A D t 1 , U N I T ( - 7 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
EXC( L O A D t 2 , U N I T ( - 6 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
EXC( L O A D t 3 , U N I T ( - 5 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
2009-01-08 16:46:40 -08:00
EXC( S T O R E t 0 , U N I T ( - 8 ) ( d s t ) , s _ e x c _ p8 u )
EXC( S T O R E t 1 , U N I T ( - 7 ) ( d s t ) , s _ e x c _ p7 u )
EXC( S T O R E t 2 , U N I T ( - 6 ) ( d s t ) , s _ e x c _ p6 u )
EXC( S T O R E t 3 , U N I T ( - 5 ) ( d s t ) , s _ e x c _ p5 u )
2017-01-09 16:52:28 +00:00
EXC( L O A D t 0 , U N I T ( - 4 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
EXC( L O A D t 1 , U N I T ( - 3 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
EXC( L O A D t 2 , U N I T ( - 2 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
EXC( L O A D t 3 , U N I T ( - 1 ) ( s r c ) , l _ e x c _ c o p y _ r e w i n d16 )
2009-01-08 16:46:40 -08:00
EXC( S T O R E t 0 , U N I T ( - 4 ) ( d s t ) , s _ e x c _ p4 u )
EXC( S T O R E t 1 , U N I T ( - 3 ) ( d s t ) , s _ e x c _ p3 u )
EXC( S T O R E t 2 , U N I T ( - 2 ) ( d s t ) , s _ e x c _ p2 u )
EXC( S T O R E t 3 , U N I T ( - 1 ) ( d s t ) , s _ e x c _ p1 u )
sltu t 0 , l e n , 2 5 6 + 1 # S e e i f w e c a n p r e f e t c h m o r e
beqz t 0 , 2 b
sltu t 0 , l e n , 1 2 8 # S e e i f w e c a n l o o p m o r e t i m e
beqz t 0 , 1 b
nop
#
# Jump h e r e i f t h e r e a r e l e s s t h a n 1 6 * N B Y T E S l e f t .
#
cleanup_both_aligned :
beqz l e n , d o n e
sltu t 0 , l e n , 8 * N B Y T E S
bnez t 0 , l e s s _ t h a n _ 8 u n i t s
nop
EXC( L O A D t 0 , U N I T ( 0 ) ( s r c ) , l _ e x c )
EXC( L O A D t 1 , U N I T ( 1 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 2 , U N I T ( 2 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 3 , U N I T ( 3 ) ( s r c ) , l _ e x c _ c o p y )
SUB l e n , l e n , 8 * N B Y T E S
EXC( S T O R E t 0 , U N I T ( 0 ) ( d s t ) , s _ e x c _ p8 u )
EXC( S T O R E t 1 , U N I T ( 1 ) ( d s t ) , s _ e x c _ p7 u )
EXC( S T O R E t 2 , U N I T ( 2 ) ( d s t ) , s _ e x c _ p6 u )
EXC( S T O R E t 3 , U N I T ( 3 ) ( d s t ) , s _ e x c _ p5 u )
EXC( L O A D t 0 , U N I T ( 4 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 1 , U N I T ( 5 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 2 , U N I T ( 6 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 3 , U N I T ( 7 ) ( s r c ) , l _ e x c _ c o p y )
EXC( S T O R E t 0 , U N I T ( 4 ) ( d s t ) , s _ e x c _ p4 u )
EXC( S T O R E t 1 , U N I T ( 5 ) ( d s t ) , s _ e x c _ p3 u )
EXC( S T O R E t 2 , U N I T ( 6 ) ( d s t ) , s _ e x c _ p2 u )
EXC( S T O R E t 3 , U N I T ( 7 ) ( d s t ) , s _ e x c _ p1 u )
ADD s r c , s r c , 8 * N B Y T E S
beqz l e n , d o n e
ADD d s t , d s t , 8 * N B Y T E S
#
# Jump h e r e i f t h e r e a r e l e s s t h a n 8 * N B Y T E S l e f t .
#
less_than_8units :
sltu t 0 , l e n , 4 * N B Y T E S
bnez t 0 , l e s s _ t h a n _ 4 u n i t s
nop
EXC( L O A D t 0 , U N I T ( 0 ) ( s r c ) , l _ e x c )
EXC( L O A D t 1 , U N I T ( 1 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 2 , U N I T ( 2 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L O A D t 3 , U N I T ( 3 ) ( s r c ) , l _ e x c _ c o p y )
SUB l e n , l e n , 4 * N B Y T E S
EXC( S T O R E t 0 , U N I T ( 0 ) ( d s t ) , s _ e x c _ p4 u )
EXC( S T O R E t 1 , U N I T ( 1 ) ( d s t ) , s _ e x c _ p3 u )
EXC( S T O R E t 2 , U N I T ( 2 ) ( d s t ) , s _ e x c _ p2 u )
EXC( S T O R E t 3 , U N I T ( 3 ) ( d s t ) , s _ e x c _ p1 u )
ADD s r c , s r c , 4 * N B Y T E S
beqz l e n , d o n e
ADD d s t , d s t , 4 * N B Y T E S
#
# Jump h e r e i f t h e r e a r e l e s s t h a n 4 * N B Y T E S l e f t . T h i s m e a n s
# we m a y n e e d t o c o p y u p t o 3 N B Y T E S w o r d s .
#
less_than_4units :
sltu t 0 , l e n , 1 * N B Y T E S
bnez t 0 , c o p y _ b y t e s _ c h e c k l e n
nop
#
# 1 ) Copy N B Y T E S , t h e n c h e c k l e n g t h a g a i n
#
EXC( L O A D t 0 , 0 ( s r c ) , l _ e x c )
SUB l e n , l e n , N B Y T E S
sltu t 1 , l e n , 8
EXC( S T O R E t 0 , 0 ( d s t ) , s _ e x c _ p1 u )
ADD s r c , s r c , N B Y T E S
bnez t 1 , c o p y _ b y t e s _ c h e c k l e n
ADD d s t , d s t , N B Y T E S
#
# 2 ) Copy N B Y T E S , t h e n c h e c k l e n g t h a g a i n
#
EXC( L O A D t 0 , 0 ( s r c ) , l _ e x c )
SUB l e n , l e n , N B Y T E S
sltu t 1 , l e n , 8
EXC( S T O R E t 0 , 0 ( d s t ) , s _ e x c _ p1 u )
ADD s r c , s r c , N B Y T E S
bnez t 1 , c o p y _ b y t e s _ c h e c k l e n
ADD d s t , d s t , N B Y T E S
#
# 3 ) Copy N B Y T E S , t h e n c h e c k l e n g t h a g a i n
#
EXC( L O A D t 0 , 0 ( s r c ) , l _ e x c )
SUB l e n , l e n , N B Y T E S
ADD s r c , s r c , N B Y T E S
ADD d s t , d s t , N B Y T E S
b c o p y _ b y t e s _ c h e c k l e n
EXC( S T O R E t 0 , - 8 ( d s t ) , s _ e x c _ p1 u )
src_unaligned :
# define r e m t 8
2013-01-22 12:59:30 +01:00
SRL t 0 , l e n , L O G _ N B Y T E S + 2 # + 2 f o r 4 u n i t s / i t e r
2009-01-08 16:46:40 -08:00
beqz t 0 , c l e a n u p _ s r c _ u n a l i g n e d
2013-01-22 12:59:30 +01:00
and r e m , l e n , ( 4 * N B Y T E S - 1 ) # r e m = l e n % 4 * N B Y T E S
2009-01-08 16:46:40 -08:00
1 :
/ *
* Avoid c o n s e c u t i v e L D * ' s t o t h e s a m e r e g i s t e r s i n c e s o m e m i p s
* implementations c a n ' t i s s u e t h e m i n t h e s a m e c y c l e .
* It' s O K t o l o a d F I R S T ( N + 1 ) b e f o r e R E S T ( N ) b e c a u s e t h e t w o a d d r e s s e s
* are t o t h e s a m e u n i t ( u n l e s s s r c i s a l i g n e d , b u t i t ' s n o t ) .
* /
2013-01-22 12:59:30 +01:00
EXC( L D F I R S T t 0 , F I R S T ( 0 ) ( s r c ) , l _ e x c )
EXC( L D F I R S T t 1 , F I R S T ( 1 ) ( s r c ) , l _ e x c _ c o p y )
SUB l e n , l e n , 4 * N B Y T E S
2009-01-08 16:46:40 -08:00
EXC( L D R E S T t 0 , R E S T ( 0 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L D R E S T t 1 , R E S T ( 1 ) ( s r c ) , l _ e x c _ c o p y )
2013-01-22 12:59:30 +01:00
EXC( L D F I R S T t 2 , F I R S T ( 2 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L D F I R S T t 3 , F I R S T ( 3 ) ( s r c ) , l _ e x c _ c o p y )
2009-01-08 16:46:40 -08:00
EXC( L D R E S T t 2 , R E S T ( 2 ) ( s r c ) , l _ e x c _ c o p y )
EXC( L D R E S T t 3 , R E S T ( 3 ) ( s r c ) , l _ e x c _ c o p y )
ADD s r c , s r c , 4 * N B Y T E S
EXC( S T O R E t 0 , U N I T ( 0 ) ( d s t ) , s _ e x c _ p4 u )
EXC( S T O R E t 1 , U N I T ( 1 ) ( d s t ) , s _ e x c _ p3 u )
EXC( S T O R E t 2 , U N I T ( 2 ) ( d s t ) , s _ e x c _ p2 u )
EXC( S T O R E t 3 , U N I T ( 3 ) ( d s t ) , s _ e x c _ p1 u )
bne l e n , r e m , 1 b
ADD d s t , d s t , 4 * N B Y T E S
cleanup_src_unaligned :
beqz l e n , d o n e
and r e m , l e n , N B Y T E S - 1 # r e m = l e n % N B Y T E S
beq r e m , l e n , c o p y _ b y t e s
nop
1 :
EXC( L D F I R S T t 0 , F I R S T ( 0 ) ( s r c ) , l _ e x c )
EXC( L D R E S T t 0 , R E S T ( 0 ) ( s r c ) , l _ e x c _ c o p y )
SUB l e n , l e n , N B Y T E S
EXC( S T O R E t 0 , 0 ( d s t ) , s _ e x c _ p1 u )
ADD s r c , s r c , N B Y T E S
bne l e n , r e m , 1 b
ADD d s t , d s t , N B Y T E S
copy_bytes_checklen :
beqz l e n , d o n e
nop
copy_bytes :
/* 0 < len < NBYTES */
# define C O P Y _ B Y T E ( N ) \
EXC( l b t 0 , N ( s r c ) , l _ e x c ) ; \
SUB l e n , l e n , 1 ; \
beqz l e n , d o n e ; \
EXC( s b t 0 , N ( d s t ) , s _ e x c _ p1 )
COPY_ B Y T E ( 0 )
COPY_ B Y T E ( 1 )
COPY_ B Y T E ( 2 )
COPY_ B Y T E ( 3 )
COPY_ B Y T E ( 4 )
COPY_ B Y T E ( 5 )
EXC( l b t 0 , N B Y T E S - 2 ( s r c ) , l _ e x c )
SUB l e n , l e n , 1
jr r a
EXC( s b t 0 , N B Y T E S - 2 ( d s t ) , s _ e x c _ p1 )
done :
jr r a
nop
END( m e m c p y )
2017-01-09 16:52:28 +00:00
l_exc_copy_rewind16 :
/* Rewind src and dst by 16*NBYTES for l_exc_copy */
SUB s r c , s r c , 1 6 * N B Y T E S
SUB d s t , d s t , 1 6 * N B Y T E S
2009-01-08 16:46:40 -08:00
l_exc_copy :
/ *
* Copy b y t e s f r o m s r c u n t i l f a u l t i n g l o a d a d d r e s s ( o r u n t i l a
* lb f a u l t s )
*
* When r e a c h e d b y a f a u l t i n g L D F I R S T / L D R E S T , T H R E A D _ B U A D D R ( $ 2 8 )
* may b e m o r e t h a n a b y t e b e y o n d t h e l a s t a d d r e s s .
* Hence, t h e l b b e l o w m a y g e t a n e x c e p t i o n .
*
* Assumes s r c < T H R E A D _ B U A D D R ( $ 2 8 )
* /
LOAD t 0 , T I _ T A S K ( $ 2 8 )
LOAD t 0 , T H R E A D _ B U A D D R ( t 0 )
1 :
EXC( l b t 1 , 0 ( s r c ) , l _ e x c )
ADD s r c , s r c , 1
sb t 1 , 0 ( d s t ) # c a n ' t f a u l t - - w e ' r e c o p y _ f r o m _ u s e r
bne s r c , t 0 , 1 b
ADD d s t , d s t , 1
l_exc :
LOAD t 0 , T I _ T A S K ( $ 2 8 )
LOAD t 0 , T H R E A D _ B U A D D R ( t 0 ) # t 0 i s j u s t p a s t l a s t g o o d a d d r e s s
SUB l e n , A T , t 0 # l e n n u m b e r o f u n c o p i e d b y t e s
2017-03-20 12:03:16 -04:00
jr r a
2009-01-08 16:46:40 -08:00
nop
# define S E X C ( n ) \
s_ e x c _ p ## n # # u : \
jr r a ; \
ADD l e n , l e n , n * N B Y T E S
SEXC( 1 6 )
SEXC( 1 5 )
SEXC( 1 4 )
SEXC( 1 3 )
SEXC( 1 2 )
SEXC( 1 1 )
SEXC( 1 0 )
SEXC( 9 )
SEXC( 8 )
SEXC( 7 )
SEXC( 6 )
SEXC( 5 )
SEXC( 4 )
SEXC( 3 )
SEXC( 2 )
SEXC( 1 )
s_exc_p1 :
jr r a
ADD l e n , l e n , 1
s_exc :
jr r a
nop
.align 5
LEAF( m e m m o v e )
2016-11-07 11:14:15 +00:00
EXPORT_ S Y M B O L ( m e m m o v e )
2009-01-08 16:46:40 -08:00
ADD t 0 , a0 , a2
ADD t 1 , a1 , a2
sltu t 0 , a1 , t 0 # d s t + l e n < = s r c - > m e m c p y
sltu t 1 , a0 , t 1 # d s t > = s r c + l e n - > m e m c p y
and t 0 , t 1
beqz t 0 , _ _ m e m c p y
move v0 , a0 / * r e t u r n v a l u e * /
beqz a2 , r _ o u t
END( m e m m o v e )
/* fall through to __rmemcpy */
LEAF( _ _ r m e m c p y ) / * a0 =dst a1 =src a2 =len * /
sltu t 0 , a1 , a0
beqz t 0 , r _ e n d _ b y t e s _ u p # s r c > = d s t
nop
ADD a0 , a2 # d s t = d s t + l e n
ADD a1 , a2 # s r c = s r c + l e n
r_end_bytes :
lb t 0 , - 1 ( a1 )
SUB a2 , a2 , 0 x1
sb t 0 , - 1 ( a0 )
SUB a1 , a1 , 0 x1
bnez a2 , r _ e n d _ b y t e s
SUB a0 , a0 , 0 x1
r_out :
jr r a
move a2 , z e r o
r_end_bytes_up :
lb t 0 , ( a1 )
SUB a2 , a2 , 0 x1
sb t 0 , ( a0 )
ADD a1 , a1 , 0 x1
bnez a2 , r _ e n d _ b y t e s _ u p
ADD a0 , a0 , 0 x1
jr r a
move a2 , z e r o
END( _ _ r m e m c p y )