]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/bfin/bfin_fixed_code.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / bfin / bfin_fixed_code.h
1 /* Atomic instructions for userspace.
2  *
3  * The actual implementations can be found in the kernel.
4  *
5  * Copyright (c) 2008 Analog Devices, Inc.
6  *
7  * Licensed under the LGPL v2.1.
8  */
9
10 #ifndef __BFIN_FIXED_CODE_H__
11 #define __BFIN_FIXED_CODE_H__
12
13 #include <stdint.h>
14
15 #include <asm/fixed_code.h>
16
17 #ifndef __ASSEMBLY__
18
19 static inline
20 uint32_t bfin_atomic_xchg32(uint32_t *__bfin_ptr, uint32_t __bfin_newval)
21 {
22         uint32_t __bfin_ret;
23         /* Input:    P0: memory address to use
24          *           R1: value to store
25          * Output:   R0: old contents of the memory address
26          */
27         __asm__ __volatile__(
28                 "CALL (%[__bfin_func])"
29                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
30                 : [__bfin_func] "a" (ATOMIC_XCHG32), "q1" (__bfin_newval),
31                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
32                 : "RETS", "memory"
33         );
34         return __bfin_ret;
35 }
36
37 static inline
38 uint32_t bfin_atomic_cas32(uint32_t *__bfin_ptr, uint32_t __bfin_exp, uint32_t __bfin_newval)
39 {
40         uint32_t __bfin_ret;
41         /* Input:    P0: memory address to use
42          *           R1: compare value
43          *           R2: new value to store
44          * Output:   R0: old contents of the memory address
45          */
46         __asm__ __volatile__(
47                 "CALL (%[__bfin_func])"
48                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
49                 : [__bfin_func] "a" (ATOMIC_CAS32), "q1" (__bfin_exp), "q2" (__bfin_newval),
50                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
51                 : "RETS", "memory"
52         );
53         return __bfin_ret;
54 }
55
56 static inline
57 uint32_t bfin_atomic_add32(uint32_t *__bfin_ptr, uint32_t __bfin_inc)
58 {
59         uint32_t __bfin_ret;
60         /* Input:    P0: memory address to use
61          *           R0: value to add
62          * Output:   R0: new contents of the memory address
63          *           R1: previous contents of the memory address
64          */
65         __asm__ __volatile__(
66                 "CALL (%[__bfin_func])"
67                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
68                 : [__bfin_func] "a" (ATOMIC_ADD32), "q0" (__bfin_inc),
69                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
70                 : "R1", "RETS", "memory"
71         );
72         return __bfin_ret;
73 }
74 #define bfin_atomic_inc32(ptr) bfin_atomic_add32(ptr, 1)
75
76 static inline
77 uint32_t bfin_atomic_sub32(uint32_t *__bfin_ptr, uint32_t __bfin_dec)
78 {
79         uint32_t __bfin_ret;
80         /* Input:    P0: memory address to use
81          *           R0: value to subtract
82          * Output:   R0: new contents of the memory address
83          *           R1: previous contents of the memory address
84          */
85         __asm__ __volatile__(
86                 "CALL (%[__bfin_func])"
87                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
88                 : [__bfin_func] "a" (ATOMIC_SUB32), "q0" (__bfin_dec),
89                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
90                 : "R1", "RETS", "memory"
91         );
92         return __bfin_ret;
93 }
94 #define bfin_atomic_dec32(ptr)        bfin_atomic_sub32(ptr, 1)
95
96 static inline
97 uint32_t bfin_atomic_ior32(uint32_t *__bfin_ptr, uint32_t __bfin_ior)
98 {
99         uint32_t __bfin_ret;
100         /* Input:    P0: memory address to use
101          *           R0: value to ior
102          * Output:   R0: new contents of the memory address
103          *           R1: previous contents of the memory address
104          */
105         __asm__ __volatile__(
106                 "CALL (%[__bfin_func])"
107                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
108                 : [__bfin_func] "a" (ATOMIC_IOR32), "q0" (__bfin_ior),
109                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
110                 : "R1", "RETS", "memory"
111         );
112         return __bfin_ret;
113 }
114
115 static inline
116 uint32_t bfin_atomic_and32(uint32_t *__bfin_ptr, uint32_t __bfin_and)
117 {
118         uint32_t __bfin_ret;
119         /* Input:    P0: memory address to use
120          *           R0: value to and
121          * Output:   R0: new contents of the memory address
122          *           R1: previous contents of the memory address
123          */
124         __asm__ __volatile__(
125                 "CALL (%[__bfin_func])"
126                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
127                 : [__bfin_func] "a" (ATOMIC_AND32), "q0" (__bfin_and),
128                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
129                 : "R1", "RETS", "memory"
130         );
131         return __bfin_ret;
132 }
133
134 static inline
135 uint32_t bfin_atomic_xor32(uint32_t *__bfin_ptr, uint32_t __bfin_xor)
136 {
137         uint32_t __bfin_ret;
138         /* Input:    P0: memory address to use
139          *           R0: value to xor
140          * Output:   R0: new contents of the memory address
141          *           R1: previous contents of the memory address
142          */
143         __asm__ __volatile__(
144                 "CALL (%[__bfin_func])"
145                 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
146                 : [__bfin_func] "a" (ATOMIC_XOR32), "q0" (__bfin_xor),
147                   "qA" (__bfin_ptr), "m" (*__bfin_ptr)
148                 : "R1", "RETS", "memory"
149         );
150         return __bfin_ret;
151 }
152
153 #endif
154
155 #endif