2013-03-21 16:28:47 +00:00
/ *
* Based o n a r c h / a r m / l i b / b i t o p s . h
*
* Copyright ( C ) 2 0 1 3 A R M L t d .
*
* 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 v e r s i o n 2 a s
* published b y t h e F r e e S o f t w a r e F o u n d a t 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 . I f n o t , s e e < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
/ *
* x0 : bits 5 : 0 b i t o f f s e t
2013-05-07 18:02:58 +01:00
* bits 3 1 : 6 w o r d o f f s e t
2013-03-21 16:28:47 +00:00
* x1 : address
* /
.macro bitop, n a m e , i n s t r
ENTRY( \ n a m e )
2013-05-07 18:02:58 +01:00
and w3 , w0 , #63 / / G e t b i t o f f s e t
eor w0 , w0 , w3 / / C l e a r l o w b i t s
2013-03-21 16:28:47 +00:00
mov x2 , #1
add x1 , x1 , x0 , l s r #3 / / G e t w o r d o f f s e t
lsl x3 , x2 , x3 / / C r e a t e m a s k
1 : ldxr x2 , [ x1 ]
\ instr x2 , x2 , x3
stxr w0 , x2 , [ x1 ]
cbnz w0 , 1 b
ret
ENDPROC( \ n a m e )
.endm
.macro testop, n a m e , i n s t r
ENTRY( \ n a m e )
2013-05-07 18:02:58 +01:00
and w3 , w0 , #63 / / G e t b i t o f f s e t
eor w0 , w0 , w3 / / C l e a r l o w b i t s
2013-03-21 16:28:47 +00:00
mov x2 , #1
add x1 , x1 , x0 , l s r #3 / / G e t w o r d o f f s e t
lsl x4 , x2 , x3 / / C r e a t e m a s k
2013-04-30 15:58:37 +01:00
1 : ldaxr x2 , [ x1 ]
2013-03-21 16:28:47 +00:00
lsr x0 , x2 , x3 / / S a v e o l d v a l u e o f b i t
\ instr x2 , x2 , x4 / / t o g g l e b i t
2013-04-30 15:58:37 +01:00
stlxr w5 , x2 , [ x1 ]
2013-04-30 11:11:15 +01:00
cbnz w5 , 1 b
2013-03-21 16:28:47 +00:00
and x0 , x0 , #1
3 : ret
ENDPROC( \ n a m e )
.endm
/ *
* Atomic b i t o p e r a t i o n s .
* /
bitop c h a n g e _ b i t , e o r
bitop c l e a r _ b i t , b i c
bitop s e t _ b i t , o r r
testop t e s t _ a n d _ c h a n g e _ b i t , e o r
testop t e s t _ a n d _ c l e a r _ b i t , b i c
testop t e s t _ a n d _ s e t _ b i t , o r r