blob: 1574c9c929e12c5c5909e39551756016368c5924 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 .text
19 .align
20
21 .global android_atomic_write
Doug Kwan09279902009-12-03 17:20:58 -080022 .type android_atomic_write, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023
24 .global android_atomic_inc
Doug Kwan09279902009-12-03 17:20:58 -080025 .type android_atomic_inc, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080026 .global android_atomic_dec
Doug Kwan09279902009-12-03 17:20:58 -080027 .type android_atomic_dec, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080028
29 .global android_atomic_add
Doug Kwan09279902009-12-03 17:20:58 -080030 .type android_atomic_add, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080031 .global android_atomic_and
Doug Kwan09279902009-12-03 17:20:58 -080032 .type android_atomic_and, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080033 .global android_atomic_or
Doug Kwan09279902009-12-03 17:20:58 -080034 .type android_atomic_or, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080035
36 .global android_atomic_swap
Doug Kwan09279902009-12-03 17:20:58 -080037 .type android_atomic_swap, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080038
39 .global android_atomic_cmpxchg
Doug Kwan09279902009-12-03 17:20:58 -080040 .type android_atomic_cmpxchg, %function
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080041
42
43
44/* FIXME: On SMP systems memory barriers may be needed */
45#warning "this file is not safe with SMP systems"
46
47
48/*
49 * ----------------------------------------------------------------------------
50 * android_atomic_write
51 * input: r0=value, r1=address
52 * output: void
53 */
54
55android_atomic_write:
Mathias Agopianca5e0bc2009-09-03 14:49:58 -070056 str r0, [r1]
57 bx lr;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080058
59/*
60 * ----------------------------------------------------------------------------
61 * android_atomic_inc
62 * input: r0 = address
63 * output: r0 = old value
64 */
65
66android_atomic_inc:
67 mov r12, r0
681: ldrex r0, [r12]
69 add r2, r0, #1
70 strex r1, r2, [r12]
71 cmp r1, #0
72 bxeq lr
73 b 1b
74
75/*
76 * ----------------------------------------------------------------------------
77 * android_atomic_dec
78 * input: r0=address
79 * output: r0 = old value
80 */
81
82android_atomic_dec:
83 mov r12, r0
841: ldrex r0, [r12]
85 sub r2, r0, #1
86 strex r1, r2, [r12]
87 cmp r1, #0
88 bxeq lr
89 b 1b
90
91
92/*
93 * ----------------------------------------------------------------------------
94 * android_atomic_add
95 * input: r0=value, r1=address
96 * output: r0 = old value
97 */
98
99android_atomic_add:
100 mov r12, r0
1011: ldrex r0, [r1]
102 add r2, r0, r12
103 strex r3, r2, [r1]
104 cmp r3, #0
105 bxeq lr
106 b 1b
107
108/*
109 * ----------------------------------------------------------------------------
110 * android_atomic_and
111 * input: r0=value, r1=address
112 * output: r0 = old value
113 */
114
115android_atomic_and:
116 mov r12, r0
1171: ldrex r0, [r1]
118 and r2, r0, r12
119 strex r3, r2, [r1]
120 cmp r3, #0
121 bxeq lr
122 b 1b
123
124
125/*
126 * ----------------------------------------------------------------------------
127 * android_atomic_or
128 * input: r0=value, r1=address
129 * output: r0 = old value
130 */
131
132android_atomic_or:
133 mov r12, r0
1341: ldrex r0, [r1]
135 orr r2, r0, r12
136 strex r3, r2, [r1]
137 cmp r3, #0
138 bxeq lr
139 b 1b
140
141/*
142 * ----------------------------------------------------------------------------
143 * android_atomic_swap
144 * input: r0=value, r1=address
145 * output: r0 = old value
146 */
147
148android_atomic_swap:
149 swp r0, r0, [r1]
150 bx lr
151
152/*
153 * ----------------------------------------------------------------------------
154 * android_atomic_cmpxchg
155 * input: r0=oldvalue, r1=newvalue, r2=address
156 * output: r0 = 0 (xchg done) or non-zero (xchg not done)
157 */
158
159android_atomic_cmpxchg:
160 mov r12, r1
161 ldrex r3, [r2]
162 eors r0, r0, r3
163 strexeq r0, r12, [r2]
164 bx lr
165
166
167
168/*
169 * ----------------------------------------------------------------------------
170 * android_atomic_cmpxchg_64
171 * input: r0-r1=oldvalue, r2-r3=newvalue, arg4 (on stack)=address
172 * output: r0 = 0 (xchg done) or non-zero (xchg not done)
173 */
174/* TODO: NEED IMPLEMENTATION FOR THIS ARCHITECTURE */