2009-05-26 16:30:23 +02:00
/ *
* Copyright ( C ) 2 0 0 9 M i c h a l S i m e k < m o n s t r @monstr.eu>
* Copyright ( C ) 2 0 0 9 P e t a L o g i x
* Copyright ( C ) 2 0 0 7 L y n u x W o r k s , I n c .
*
* 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 .
* /
# include < l i n u x / e r r n o . h >
# include < l i n u x / l i n k a g e . h >
/ *
* int _ _ s t r n c p y _ u s e r ( c h a r * t o , c h a r * f r o m , i n t l e n ) ;
*
* Returns :
* - EFAULT f o r a n e x c e p t i o n
* len i f w e h i t t h e b u f f e r l i m i t
* bytes c o p i e d
* /
.text
.globl _ _ strncpy_ u s e r ;
2010-03-23 08:09:32 +01:00
.type _ _ strncpy_ u s e r , @function
2009-05-26 16:30:23 +02:00
.align 4 ;
__strncpy_user :
/ *
* r5 - t o
* r6 - f r o m
* r7 - l e n
* r3 - t e m p c o u n t
* r4 - t e m p v a l
* /
addik r3 ,r7 ,0 / * t e m p _ c o u n t = l e n * /
beqi r3 ,3 f
1 :
lbu r4 ,r6 ,r0
sb r4 ,r5 ,r0
addik r3 ,r3 ,- 1
beqi r3 ,2 f / * b r e a k o n l e n * /
addik r5 ,r5 ,1
bneid r4 ,1 b
addik r6 ,r6 ,1 / * d e l a y s l o t * /
addik r3 ,r3 ,1 / * u n d o " t e m p _ c o u n t - - " * /
2 :
rsubk r3 ,r3 ,r7 / * t e m p _ c o u n t = l e n - t e m p _ c o u n t * /
3 :
rtsd r15 ,8
nop
2010-03-23 08:09:32 +01:00
.size _ _ strncpy_ u s e r , . - _ _ s t r n c p y _ u s e r
2009-05-26 16:30:23 +02:00
.section .fixup , " ax"
.align 2
4 :
brid 3 b
addik r3 ,r0 , - E F A U L T
.section _ _ ex_ t a b l e , " a "
.word 1 b,4 b
/ *
* int _ _ s t r n l e n _ u s e r ( c h a r _ _ u s e r * s t r , i n t m a x l e n ) ;
*
* Returns :
* 0 on e r r o r
* maxlen + 1 i f n o N U L b y t e f o u n d w i t h i n m a x l e n b y t e s
* size o f t h e s t r i n g ( i n c l u d i n g N U L b y t e )
* /
.text
.globl _ _ strnlen_ u s e r ;
2010-03-23 08:09:32 +01:00
.type _ _ strnlen_ u s e r , @function
2009-05-26 16:30:23 +02:00
.align 4 ;
__strnlen_user :
addik r3 ,r6 ,0
beqi r3 ,3 f
1 :
lbu r4 ,r5 ,r0
beqid r4 ,2 f / * b r e a k o n N U L * /
addik r3 ,r3 ,- 1 / * d e l a y s l o t * /
bneid r3 ,1 b
addik r5 ,r5 ,1 / * d e l a y s l o t * /
addik r3 ,r3 ,- 1 / * f o r b r e a k o n l e n * /
2 :
rsubk r3 ,r3 ,r6
3 :
rtsd r15 ,8
nop
2010-03-23 08:09:32 +01:00
.size _ _ strnlen_ u s e r , . - _ _ s t r n l e n _ u s e r
2009-05-26 16:30:23 +02:00
.section .fixup , " ax"
4 :
brid 3 b
addk r3 ,r0 ,r0
.section _ _ ex_ t a b l e ," a "
.word 1 b,4 b
/ *
* int _ _ c o p y _ t o f r o m _ u s e r ( c h a r * t o , c h a r * f r o m , i n t l e n )
* Return :
* 0 on s u c c e s s
* number o f n o t c o p i e d b y t e s o n e r r o r
* /
.text
.globl _ _ copy_ t o f r o m _ u s e r ;
2010-03-23 08:09:32 +01:00
.type _ _ copy_ t o f r o m _ u s e r , @function
2009-05-26 16:30:23 +02:00
.align 4 ;
__copy_tofrom_user :
/ *
* r5 - t o
* r6 - f r o m
* r7 , r3 - c o u n t
* r4 - t e m p v a l
* /
2010-03-22 20:31:26 +01:00
beqid r7 , 3 f / * z e r o s i z e i s n o t l i k e l y * /
andi r3 , r7 , 0 x3 / * f i l t e r a d d c o u n t * /
bneid r3 , 4 f / * i f i s o d d v a l u e t h e n b y t e c o p y i n g * /
or r3 , r5 , r6 / * f i n d i f i s a n y t o / f r o m u n a l i g n e d * /
andi r3 , r3 , 0 x3 / * m a s k u n a l i g n e d * /
bneid r3 , 1 f / * i t i s u n a l i g n e d - > t h e n j u m p * /
or r3 , r0 , r0
/* at least one 4 byte copy */
5 : lw r4 , r6 , r3
6 : sw r4 , r5 , r3
addik r7 , r7 , - 4
bneid r7 , 5 b
addik r3 , r3 , 4
addik r3 , r7 , 0
rtsd r15 , 8
nop
4 : or r3 , r0 , r0
1 : lbu r4 ,r6 ,r3
2 : sb r4 ,r5 ,r3
addik r7 ,r7 ,- 1
bneid r7 ,1 b
addik r3 ,r3 ,1 / * d e l a y s l o t * /
2009-05-26 16:30:23 +02:00
3 :
2010-03-22 20:31:26 +01:00
addik r3 ,r7 ,0
2009-05-26 16:30:23 +02:00
rtsd r15 ,8
nop
2010-03-23 08:09:32 +01:00
.size _ _ copy_ t o f r o m _ u s e r , . - _ _ c o p y _ t o f r o m _ u s e r
2009-05-26 16:30:23 +02:00
.section _ _ ex_ t a b l e ," a "
2010-03-22 20:31:26 +01:00
.word 1 b,3 b ,2 b ,3 b ,5 b ,3 b ,6 b ,3 b