2005-04-16 15:20:36 -07:00
/ *
* User S p a c e A c c e s s R o u t i n e s
*
* Copyright ( C ) 2 0 0 0 - 2 0 0 2 H e w l e t t - P a c k a r d ( J o h n M a r v i n )
* Copyright ( C ) 2 0 0 0 R i c h a r d H i r s t < r h i r s t w i t h p a r i s c - l i n u x . o r g >
* Copyright ( C ) 2 0 0 1 M a t t h i e u D e l a h a y e < d e l a h a y m a t e s i e e . f r >
* Copyright ( C ) 2 0 0 3 R a n d o l p h C h u n g < t a u s q w i t h p a r i s c - l i n u x . o r g >
*
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify
* it u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e a s p u b l i s h e d b y
* the F r e e S o f t w a r e F o u n d a t i o n ; either version 2, or (at your option)
* any l a t e r v e r s i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* along w i t h t h i s p r o g r a m ; if not, write to the Free Software
* Foundation, I n c . , 5 9 T e m p l e P l a c e , S u i t e 3 3 0 , B o s t o n , M A 0 2 1 1 1 - 1 3 0 7 U S A
* /
/ *
* These r o u t i n e s s t i l l h a v e p l e n t y o f r o o m f o r o p t i m i z a t i o n
* ( word & d o u b l e w o r d l o a d / s t o r e , d u a l i s s u e , s t o r e h i n t s , e t c . ) .
* /
/ *
* The f o l l o w i n g r o u t i n e s a s s u m e t h a t s p a c e r e g i s t e r 3 ( s r3 ) c o n t a i n s
* the s p a c e i d a s s o c i a t e d w i t h t h e c u r r e n t u s e r s a d d r e s s s p a c e .
* /
2008-05-22 14:36:31 -04:00
.text
2005-04-16 15:20:36 -07:00
# include < a s m / a s s e m b l y . h >
# include < a s m / e r r n o . h >
2007-01-28 14:52:57 +01:00
# include < l i n u x / l i n k a g e . h >
2005-04-16 15:20:36 -07:00
/ *
* get_ s r g e t s t h e a p p r o p r i a t e s p a c e v a l u e i n t o
* sr1 f o r k e r n e l / u s e r s p a c e a c c e s s , d e p e n d i n g
* on t h e f l a g s t o r e d i n t h e t a s k s t r u c t u r e .
* /
.macro get_sr
mfctl % c r30 ,% r1
ldw T I _ S E G M E N T ( % r1 ) ,% r22
mfsp % s r3 ,% r1
or,< > % r22 ,% r0 ,% r0
copy % r0 ,% r1
mtsp % r1 ,% s r1
.endm
.macro fixup_branch lbl
ldil L % \ l b l , % r1
ldo R % \ l b l ( % r1 ) , % r1
bv % r0 ( % r1 )
.endm
/ *
* long l s t r n c p y _ f r o m _ u s e r ( c h a r * d s t , c o n s t c h a r * s r c , l o n g n )
*
* Returns - E F A U L T i f e x c e p t i o n b e f o r e t e r m i n a t o r ,
* N i f t h e e n t i r e b u f f e r f i l l e d ,
* otherwise s t r l e n ( i . e . e x c l u d e s z e r o b y t e )
* /
2007-01-28 14:52:57 +01:00
ENTRY( l s t r n c p y _ f r o m _ u s e r )
2005-04-16 15:20:36 -07:00
.proc
.callinfo NO_CALLS
.entry
comib,= 0 ,% r24 ,$ l s f u _ d o n e
copy % r24 ,% r23
get_ s r
1 : ldbs,m a 1 ( % s r1 ,% r25 ) ,% r1
$ lsfu_loop :
stbs,m a % r1 ,1 ( % r26 )
comib,= ,n 0 ,% r1 ,$ l s f u _ d o n e
addib,< > ,n - 1 ,% r24 ,$ l s f u _ l o o p
2 : ldbs,m a 1 ( % s r1 ,% r25 ) ,% r1
$ lsfu_done :
sub % r23 ,% r24 ,% r28
$ lsfu_exit :
bv % r0 ( % r2 )
nop
.exit
2007-01-28 14:52:57 +01:00
ENDPROC( l s t r n c p y _ f r o m _ u s e r )
2005-04-16 15:20:36 -07:00
.section .fixup , " ax"
3 : fixup_ b r a n c h $ l s f u _ e x i t
ldi - E F A U L T ,% r28
.previous
.section _ _ ex_ t a b l e ," a w "
2007-01-28 14:52:57 +01:00
ASM_ U L O N G _ I N S N 1 b ,3 b
ASM_ U L O N G _ I N S N 2 b ,3 b
2005-04-16 15:20:36 -07:00
.previous
.procend
/ *
* unsigned l o n g l c l e a r _ u s e r ( v o i d * t o , u n s i g n e d l o n g n )
*
* Returns 0 f o r s u c c e s s .
* otherwise, r e t u r n s n u m b e r o f b y t e s n o t t r a n s f e r r e d .
* /
2007-01-28 14:52:57 +01:00
ENTRY( l c l e a r _ u s e r )
2005-04-16 15:20:36 -07:00
.proc
.callinfo NO_CALLS
.entry
comib,= ,n 0 ,% r25 ,$ l c l u _ d o n e
get_ s r
$ lclu_loop :
addib,< > - 1 ,% r25 ,$ l c l u _ l o o p
1 : stbs,m a % r0 ,1 ( % s r1 ,% r26 )
$ lclu_done :
bv % r0 ( % r2 )
copy % r25 ,% r28
.exit
2007-01-28 14:52:57 +01:00
ENDPROC( l c l e a r _ u s e r )
2005-04-16 15:20:36 -07:00
.section .fixup , " ax"
2 : fixup_ b r a n c h $ l c l u _ d o n e
ldo 1 ( % r25 ) ,% r25
.previous
.section _ _ ex_ t a b l e ," a w "
2007-01-28 14:52:57 +01:00
ASM_ U L O N G _ I N S N 1 b ,2 b
2005-04-16 15:20:36 -07:00
.previous
.procend
/ *
* long l s t r n l e n _ u s e r ( c h a r * s , l o n g n )
*
* Returns 0 i f e x c e p t i o n b e f o r e z e r o b y t e o r r e a c h i n g N ,
* N+ 1 i f N w o u l d b e e x c e e d e d ,
* else s t r l e n + 1 ( i . e . i n c l u d e s z e r o b y t e ) .
* /
2007-01-28 14:52:57 +01:00
ENTRY( l s t r n l e n _ u s e r )
2005-04-16 15:20:36 -07:00
.proc
.callinfo NO_CALLS
.entry
comib,= 0 ,% r25 ,$ l s l e n _ n z e r o
copy % r26 ,% r24
get_ s r
1 : ldbs,m a 1 ( % s r1 ,% r26 ) ,% r1
$ lslen_loop :
comib,= ,n 0 ,% r1 ,$ l s l e n _ d o n e
addib,< > - 1 ,% r25 ,$ l s l e n _ l o o p
2 : ldbs,m a 1 ( % s r1 ,% r26 ) ,% r1
$ lslen_done :
bv % r0 ( % r2 )
sub % r26 ,% r24 ,% r28
.exit
$ lslen_nzero :
b $ l s l e n _ d o n e
ldo 1 ( % r26 ) ,% r26 / * s p e c i a l c a s e f o r N = = 0 * /
2007-01-28 14:52:57 +01:00
ENDPROC( l s t r n l e n _ u s e r )
2005-04-16 15:20:36 -07:00
.section .fixup , " ax"
3 : fixup_ b r a n c h $ l s l e n _ d o n e
copy % r24 ,% r26 / * r e s e t r26 s o 0 i s r e t u r n e d o n f a u l t * /
.previous
.section _ _ ex_ t a b l e ," a w "
2007-01-28 14:52:57 +01:00
ASM_ U L O N G _ I N S N 1 b ,3 b
ASM_ U L O N G _ I N S N 2 b ,3 b
2005-04-16 15:20:36 -07:00
.previous
.procend
.end