2012-05-27 23:54:03 +04:00
/ *
* 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 of the License, or
* ( at y o u r o p t i o n ) a n y 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 .
*
* Copyright ( C ) I B M C o r p o r a t i o n , 2 0 1 2
*
* Author : Anton B l a n c h a r d < a n t o n @au.ibm.com>
* /
# include < a s m / p p c _ a s m . h >
2012-06-04 20:02:22 +04:00
# include < a s m / a s m - o f f s e t s . h >
2016-01-14 07:33:46 +03:00
# include < a s m / e x p o r t . h >
2012-06-04 20:02:22 +04:00
.section " .toc " , " aw"
PPC64_CACHES :
.tc ppc6 4 _ c a c h e s [ T C ] ,p p c64 _ c a c h e s
.section " .text "
2012-05-27 23:54:03 +04:00
/ * *
* __clear_user : - Zero a b l o c k o f m e m o r y i n u s e r s p a c e , w i t h l e s s c h e c k i n g .
* @to: Destination address, in user space.
* @n: Number of bytes to zero.
*
* Zero a b l o c k o f m e m o r y i n u s e r s p a c e . C a l l e r m u s t c h e c k
* the s p e c i f i e d b l o c k w i t h a c c e s s _ o k ( ) b e f o r e c a l l i n g t h i s f u n c t i o n .
*
* Returns n u m b e r o f b y t e s t h a t c o u l d n o t b e c l e a r e d .
* On s u c c e s s , t h i s w i l l b e z e r o .
* /
.macro err1
100 :
.section _ _ ex_ t a b l e ," a "
.align 3
.llong 1 0 0 b,. L d o _ e r r1
.previous
.endm
.macro err2
200 :
.section _ _ ex_ t a b l e ," a "
.align 3
.llong 2 0 0 b,. L d o _ e r r2
.previous
.endm
.macro err3
300 :
.section _ _ ex_ t a b l e ," a "
.align 3
.llong 3 0 0 b,. L d o _ e r r3
.previous
.endm
.Ldo_err1 :
mr r3 ,r8
.Ldo_err2 :
mtctr r4
1 :
err3 ; stb r0,0(r3)
addi r3 ,r3 ,1
addi r4 ,r4 ,- 1
bdnz 1 b
.Ldo_err3 :
mr r3 ,r4
blr
2014-06-05 02:04:39 +04:00
_ GLOBAL_ T O C ( _ _ c l e a r _ u s e r )
2012-05-27 23:54:03 +04:00
cmpdi r4 ,3 2
neg r6 ,r3
li r0 ,0
blt . L s h o r t _ c l e a r
mr r8 ,r3
mtocrf 0 x01 ,r6
clrldi r6 ,r6 ,( 6 4 - 3 )
/* Get the destination 8 byte aligned */
bf c r7 * 4 + 3 ,1 f
err1 ; stb r0,0(r3)
addi r3 ,r3 ,1
1 : bf c r7 * 4 + 2 ,2 f
err1 ; sth r0,0(r3)
addi r3 ,r3 ,2
2 : bf c r7 * 4 + 1 ,3 f
err1 ; stw r0,0(r3)
addi r3 ,r3 ,4
3 : sub r4 ,r4 ,r6
2012-06-04 20:02:22 +04:00
2012-05-27 23:54:03 +04:00
cmpdi r4 ,3 2
2012-06-04 20:02:22 +04:00
cmpdi c r1 ,r4 ,5 1 2
2012-05-27 23:54:03 +04:00
blt . L s h o r t _ c l e a r
2012-06-04 20:02:22 +04:00
bgt c r1 ,. L l o n g _ c l e a r
.Lmedium_clear :
srdi r6 ,r4 ,5
2012-05-27 23:54:03 +04:00
mtctr r6
/* Do 32 byte chunks */
4 :
err2 ; std r0,0(r3)
err2 ; std r0,8(r3)
err2 ; std r0,16(r3)
err2 ; std r0,24(r3)
addi r3 ,r3 ,3 2
addi r4 ,r4 ,- 3 2
bdnz 4 b
.Lshort_clear :
/* up to 31 bytes to go */
cmpdi r4 ,1 6
blt 6 f
err2 ; std r0,0(r3)
err2 ; std r0,8(r3)
addi r3 ,r3 ,1 6
addi r4 ,r4 ,- 1 6
/* Up to 15 bytes to go */
6 : mr r8 ,r3
clrldi r4 ,r4 ,( 6 4 - 4 )
mtocrf 0 x01 ,r4
bf c r7 * 4 + 0 ,7 f
err1 ; std r0,0(r3)
addi r3 ,r3 ,8
7 : bf c r7 * 4 + 1 ,8 f
err1 ; stw r0,0(r3)
addi r3 ,r3 ,4
8 : bf c r7 * 4 + 2 ,9 f
err1 ; sth r0,0(r3)
addi r3 ,r3 ,2
9 : bf c r7 * 4 + 3 ,1 0 f
err1 ; stb r0,0(r3)
10 : li r3 ,0
blr
2012-06-04 20:02:22 +04:00
.Llong_clear :
ld r5 ,P P C 6 4 _ C A C H E S @toc(r2)
bf c r7 * 4 + 0 ,1 1 f
err2 ; std r0,0(r3)
addi r3 ,r3 ,8
addi r4 ,r4 ,- 8
/* Destination is 16 byte aligned, need to get it cacheline aligned */
11 : lwz r7 ,D C A C H E L 1 L O G L I N E S I Z E ( r5 )
lwz r9 ,D C A C H E L 1 L I N E S I Z E ( r5 )
/ *
* With w o r s t c a s e a l i g n m e n t t h e l o n g c l e a r l o o p t a k e s a m i n i m u m
* of 1 b y t e l e s s t h a n 2 c a c h e l i n e s .
* /
sldi r10 ,r9 ,2
cmpd r4 ,r10
blt . L m e d i u m _ c l e a r
neg r6 ,r3
addi r10 ,r9 ,- 1
and. r5 ,r6 ,r10
beq 1 3 f
srdi r6 ,r5 ,4
mtctr r6
mr r8 ,r3
12 :
err1 ; std r0,0(r3)
err1 ; std r0,8(r3)
addi r3 ,r3 ,1 6
bdnz 1 2 b
sub r4 ,r4 ,r5
13 : srd r6 ,r4 ,r7
mtctr r6
mr r8 ,r3
14 :
err1 ; dcbz r0,r3
add r3 ,r3 ,r9
bdnz 1 4 b
and r4 ,r4 ,r10
cmpdi r4 ,3 2
blt . L s h o r t _ c l e a r
b . L m e d i u m _ c l e a r
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ c l e a r _ u s e r )