• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
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
22
23    .global android_atomic_inc
24    .global android_atomic_dec
25
26    .global android_atomic_add
27    .global android_atomic_and
28    .global android_atomic_or
29
30    .global android_atomic_swap
31
32    .global android_atomic_cmpxchg
33
34
35
36/* FIXME: On SMP systems memory barriers may be needed */
37#warning  "this file is not safe with SMP systems"
38
39
40/*
41 * ----------------------------------------------------------------------------
42 * android_atomic_write
43 * input: r0=value, r1=address
44 * output: void
45 */
46
47android_atomic_write:
48    str     r0, [r1]
49    bx      lr;
50
51/*
52 * ----------------------------------------------------------------------------
53 * android_atomic_inc
54 * input: r0 = address
55 * output: r0 = old value
56 */
57
58android_atomic_inc:
59    mov     r12, r0
601:  ldrex   r0, [r12]
61    add     r2, r0, #1
62    strex   r1, r2, [r12]
63    cmp     r1, #0
64    bxeq    lr
65    b       1b
66
67/*
68 * ----------------------------------------------------------------------------
69 * android_atomic_dec
70 * input: r0=address
71 * output: r0 = old value
72 */
73
74android_atomic_dec:
75    mov     r12, r0
761:  ldrex   r0, [r12]
77    sub     r2, r0, #1
78    strex   r1, r2, [r12]
79    cmp     r1, #0
80    bxeq    lr
81    b       1b
82
83
84/*
85 * ----------------------------------------------------------------------------
86 * android_atomic_add
87 * input: r0=value, r1=address
88 * output: r0 = old value
89 */
90
91android_atomic_add:
92    mov     r12, r0
931:  ldrex   r0, [r1]
94    add     r2, r0, r12
95    strex   r3, r2, [r1]
96    cmp     r3, #0
97    bxeq    lr
98    b       1b
99
100/*
101 * ----------------------------------------------------------------------------
102 * android_atomic_and
103 * input: r0=value, r1=address
104 * output: r0 = old value
105 */
106
107android_atomic_and:
108    mov     r12, r0
1091:  ldrex   r0, [r1]
110    and     r2, r0, r12
111    strex   r3, r2, [r1]
112    cmp     r3, #0
113    bxeq    lr
114    b       1b
115
116
117/*
118 * ----------------------------------------------------------------------------
119 * android_atomic_or
120 * input: r0=value, r1=address
121 * output: r0 = old value
122 */
123
124android_atomic_or:
125    mov     r12, r0
1261:  ldrex   r0, [r1]
127    orr     r2, r0, r12
128    strex   r3, r2, [r1]
129    cmp     r3, #0
130    bxeq    lr
131    b       1b
132
133/*
134 * ----------------------------------------------------------------------------
135 * android_atomic_swap
136 * input: r0=value, r1=address
137 * output: r0 = old value
138 */
139
140android_atomic_swap:
141    swp     r0, r0, [r1]
142    bx      lr
143
144/*
145 * ----------------------------------------------------------------------------
146 * android_atomic_cmpxchg
147 * input: r0=oldvalue, r1=newvalue, r2=address
148 * output: r0 = 0 (xchg done) or non-zero (xchg not done)
149 */
150
151android_atomic_cmpxchg:
152    mov     r12, r1
153    ldrex   r3, [r2]
154    eors    r0, r0, r3
155    strexeq r0, r12, [r2]
156    bx      lr
157
158
159
160/*
161 * ----------------------------------------------------------------------------
162 * android_atomic_cmpxchg_64
163 * input: r0-r1=oldvalue, r2-r3=newvalue, arg4 (on stack)=address
164 * output: r0 = 0 (xchg done) or non-zero (xchg not done)
165 */
166/* TODO: NEED IMPLEMENTATION FOR THIS ARCHITECTURE */
167