]>
Commit | Line | Data |
---|---|---|
cc310428 OM |
1 | // Implementation of synchronization functions for ARM architecture\r |
2 | //\r | |
3 | // Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r | |
9b89163e | 4 | // Copyright (c) 2015, Linaro Limited. All rights reserved.\r |
cc310428 OM |
5 | //\r |
6 | // This program and the accompanying materials\r | |
7 | // are licensed and made available under the terms and conditions of the BSD License\r | |
8 | // which accompanies this distribution. The full text of the license may be found at\r | |
9 | // http://opensource.org/licenses/bsd-license.php\r | |
10 | //\r | |
11 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | //\r | |
14 | //\r | |
15 | \r | |
9b89163e | 16 | EXPORT InternalSyncCompareExchange16\r |
cc310428 OM |
17 | EXPORT InternalSyncCompareExchange32\r |
18 | EXPORT InternalSyncCompareExchange64\r | |
19 | EXPORT InternalSyncIncrement\r | |
20 | EXPORT InternalSyncDecrement\r | |
21 | \r | |
22 | AREA ArmSynchronization, CODE, READONLY\r | |
23 | \r | |
9b89163e AB |
24 | /**\r |
25 | Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r | |
26 | \r | |
27 | Performs an atomic compare exchange operation on the 16-bit unsigned integer\r | |
28 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
29 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
30 | then Value is returned. The compare exchange operation must be performed using\r | |
31 | MP safe mechanisms.\r | |
32 | \r | |
33 | @param Value A pointer to the 16-bit value for the compare exchange\r | |
34 | operation.\r | |
35 | @param CompareValue 16-bit value used in compare operation.\r | |
36 | @param ExchangeValue 16-bit value used in exchange operation.\r | |
37 | \r | |
38 | @return The original *Value before exchange.\r | |
39 | \r | |
40 | **/\r | |
41 | //UINT16\r | |
42 | //EFIAPI\r | |
43 | //InternalSyncCompareExchange16 (\r | |
44 | // IN volatile UINT16 *Value,\r | |
45 | // IN UINT16 CompareValue,\r | |
46 | // IN UINT16 ExchangeValue\r | |
47 | // )\r | |
48 | InternalSyncCompareExchange16\r | |
49 | dmb\r | |
50 | \r | |
51 | InternalSyncCompareExchange16Again\r | |
52 | ldrexh r3, [r0]\r | |
53 | cmp r3, r1\r | |
54 | bne InternalSyncCompareExchange16Fail\r | |
55 | \r | |
56 | InternalSyncCompareExchange16Exchange\r | |
57 | strexh ip, r2, [r0]\r | |
58 | cmp ip, #0\r | |
59 | bne InternalSyncCompareExchange16Again\r | |
60 | \r | |
61 | InternalSyncCompareExchange16Fail\r | |
62 | dmb\r | |
63 | mov r0, r3\r | |
64 | bx lr\r | |
65 | \r | |
cc310428 OM |
66 | /**\r |
67 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
68 | \r | |
69 | Performs an atomic compare exchange operation on the 32-bit unsigned integer\r | |
70 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
71 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
72 | then Value is returned. The compare exchange operation must be performed using\r | |
73 | MP safe mechanisms.\r | |
74 | \r | |
75 | @param Value A pointer to the 32-bit value for the compare exchange\r | |
76 | operation.\r | |
77 | @param CompareValue 32-bit value used in compare operation.\r | |
78 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
79 | \r | |
80 | @return The original *Value before exchange.\r | |
81 | \r | |
82 | **/\r | |
83 | //UINT32\r | |
84 | //EFIAPI\r | |
85 | //InternalSyncCompareExchange32 (\r | |
86 | // IN volatile UINT32 *Value,\r | |
87 | // IN UINT32 CompareValue,\r | |
88 | // IN UINT32 ExchangeValue\r | |
89 | // )\r | |
90 | InternalSyncCompareExchange32\r | |
91 | dmb\r | |
92 | \r | |
93 | InternalSyncCompareExchange32Again\r | |
94 | ldrex r3, [r0]\r | |
95 | cmp r3, r1\r | |
96 | bne InternalSyncCompareExchange32Fail\r | |
97 | \r | |
98 | InternalSyncCompareExchange32Exchange\r | |
99 | strex ip, r2, [r0]\r | |
100 | cmp ip, #0\r | |
101 | bne InternalSyncCompareExchange32Again\r | |
102 | \r | |
103 | InternalSyncCompareExchange32Fail\r | |
104 | dmb\r | |
105 | mov r0, r3\r | |
106 | bx lr\r | |
107 | \r | |
108 | /**\r | |
109 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
110 | \r | |
111 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
112 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
113 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
114 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
115 | \r | |
116 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
117 | operation.\r | |
118 | @param CompareValue 64-bit value used in compare operation.\r | |
119 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
120 | \r | |
121 | @return The original *Value before exchange.\r | |
122 | \r | |
123 | **/\r | |
124 | //UINT64\r | |
125 | //EFIAPI\r | |
126 | //InternalSyncCompareExchange64 (\r | |
127 | // IN volatile UINT64 *Value, // r0\r | |
128 | // IN UINT64 CompareValue, // r2-r3\r | |
129 | // IN UINT64 ExchangeValue // stack\r | |
130 | // )\r | |
131 | InternalSyncCompareExchange64\r | |
132 | push { r4-r7 }\r | |
133 | ldrd r4, r5, [sp, #16]\r | |
134 | dmb\r | |
135 | \r | |
136 | InternalSyncCompareExchange64Again\r | |
137 | ldrexd r6, r7, [r0]\r | |
138 | cmp r6, r2\r | |
139 | cmpeq r7, r3\r | |
140 | bne InternalSyncCompareExchange64Fail\r | |
141 | \r | |
142 | InternalSyncCompareExchange64Exchange\r | |
143 | strexd ip, r4, r5, [r0]\r | |
144 | cmp ip, #0\r | |
145 | bne InternalSyncCompareExchange64Again\r | |
146 | \r | |
147 | InternalSyncCompareExchange64Fail\r | |
148 | dmb\r | |
149 | mov r0, r6\r | |
150 | mov r1, r7\r | |
151 | pop { r4-r7 }\r | |
152 | bx lr\r | |
153 | \r | |
154 | /**\r | |
155 | Performs an atomic increment of an 32-bit unsigned integer.\r | |
156 | \r | |
157 | Performs an atomic increment of the 32-bit unsigned integer specified by\r | |
158 | Value and returns the incremented value. The increment operation must be\r | |
159 | performed using MP safe mechanisms. The state of the return value is not\r | |
160 | guaranteed to be MP safe.\r | |
161 | \r | |
162 | @param Value A pointer to the 32-bit value to increment.\r | |
163 | \r | |
164 | @return The incremented value.\r | |
165 | \r | |
166 | **/\r | |
167 | //UINT32\r | |
168 | //EFIAPI\r | |
169 | //InternalSyncIncrement (\r | |
170 | // IN volatile UINT32 *Value\r | |
171 | // )\r | |
172 | InternalSyncIncrement\r | |
173 | dmb\r | |
174 | TryInternalSyncIncrement\r | |
175 | ldrex r1, [r0]\r | |
176 | add r1, r1, #1\r | |
177 | strex r2, r1, [r0]\r | |
178 | cmp r2, #0\r | |
179 | bne TryInternalSyncIncrement\r | |
180 | dmb\r | |
f61762d0 | 181 | mov r0, r1\r |
cc310428 OM |
182 | bx lr\r |
183 | \r | |
184 | /**\r | |
185 | Performs an atomic decrement of an 32-bit unsigned integer.\r | |
186 | \r | |
187 | Performs an atomic decrement of the 32-bit unsigned integer specified by\r | |
188 | Value and returns the decrement value. The decrement operation must be\r | |
189 | performed using MP safe mechanisms. The state of the return value is not\r | |
190 | guaranteed to be MP safe.\r | |
191 | \r | |
192 | @param Value A pointer to the 32-bit value to decrement.\r | |
193 | \r | |
194 | @return The decrement value.\r | |
195 | \r | |
196 | **/\r | |
197 | //UINT32\r | |
198 | //EFIAPI\r | |
199 | //InternalSyncDecrement (\r | |
200 | // IN volatile UINT32 *Value\r | |
201 | // )\r | |
202 | InternalSyncDecrement\r | |
203 | dmb\r | |
204 | TryInternalSyncDecrement\r | |
205 | ldrex r1, [r0]\r | |
206 | sub r1, r1, #1\r | |
207 | strex r2, r1, [r0]\r | |
208 | cmp r2, #0\r | |
209 | bne TryInternalSyncDecrement\r | |
210 | dmb\r | |
f61762d0 | 211 | mov r0, r1\r |
cc310428 OM |
212 | bx lr\r |
213 | \r | |
214 | END\r |