1 // Implementation of synchronization functions for ARM architecture
3 // Copyright (c) 2012-2015, ARM Limited. All rights reserved.
4 // Copyright (c) 2015, Linaro Limited. All rights reserved.
6 // This program and the accompanying materials
7 // are licensed and made available under the terms and conditions of the BSD License
8 // which accompanies this distribution. The full text of the license may be found at
9 // http://opensource.org/licenses/bsd-license.php
11 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 EXPORT InternalSyncCompareExchange16
17 EXPORT InternalSyncCompareExchange32
18 EXPORT InternalSyncCompareExchange64
19 EXPORT InternalSyncIncrement
20 EXPORT InternalSyncDecrement
22 AREA ArmSynchronization, CODE, READONLY
25 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
27 Performs an atomic compare exchange operation on the 16-bit unsigned integer
28 specified by Value. If Value is equal to CompareValue, then Value is set to
29 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
30 then Value is returned. The compare exchange operation must be performed using
33 @param Value A pointer to the 16-bit value for the compare exchange
35 @param CompareValue 16-bit value used in compare operation.
36 @param ExchangeValue 16-bit value used in exchange operation.
38 @return The original *Value before exchange.
43 //InternalSyncCompareExchange16 (
44 // IN volatile UINT16 *Value,
45 // IN UINT16 CompareValue,
46 // IN UINT16 ExchangeValue
48 InternalSyncCompareExchange16
51 InternalSyncCompareExchange16Again
54 bne InternalSyncCompareExchange16Fail
56 InternalSyncCompareExchange16Exchange
59 bne InternalSyncCompareExchange16Again
61 InternalSyncCompareExchange16Fail
67 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
69 Performs an atomic compare exchange operation on the 32-bit unsigned integer
70 specified by Value. If Value is equal to CompareValue, then Value is set to
71 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
72 then Value is returned. The compare exchange operation must be performed using
75 @param Value A pointer to the 32-bit value for the compare exchange
77 @param CompareValue 32-bit value used in compare operation.
78 @param ExchangeValue 32-bit value used in exchange operation.
80 @return The original *Value before exchange.
85 //InternalSyncCompareExchange32 (
86 // IN volatile UINT32 *Value,
87 // IN UINT32 CompareValue,
88 // IN UINT32 ExchangeValue
90 InternalSyncCompareExchange32
93 InternalSyncCompareExchange32Again
96 bne InternalSyncCompareExchange32Fail
98 InternalSyncCompareExchange32Exchange
101 bne InternalSyncCompareExchange32Again
103 InternalSyncCompareExchange32Fail
109 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
111 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
112 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
113 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
114 The compare exchange operation must be performed using MP safe mechanisms.
116 @param Value A pointer to the 64-bit value for the compare exchange
118 @param CompareValue 64-bit value used in compare operation.
119 @param ExchangeValue 64-bit value used in exchange operation.
121 @return The original *Value before exchange.
126 //InternalSyncCompareExchange64 (
127 // IN volatile UINT64 *Value, // r0
128 // IN UINT64 CompareValue, // r2-r3
129 // IN UINT64 ExchangeValue // stack
131 InternalSyncCompareExchange64
133 ldrd r4, r5, [sp, #16]
136 InternalSyncCompareExchange64Again
140 bne InternalSyncCompareExchange64Fail
142 InternalSyncCompareExchange64Exchange
143 strexd ip, r4, r5, [r0]
145 bne InternalSyncCompareExchange64Again
147 InternalSyncCompareExchange64Fail
155 Performs an atomic increment of an 32-bit unsigned integer.
157 Performs an atomic increment of the 32-bit unsigned integer specified by
158 Value and returns the incremented value. The increment operation must be
159 performed using MP safe mechanisms. The state of the return value is not
160 guaranteed to be MP safe.
162 @param Value A pointer to the 32-bit value to increment.
164 @return The incremented value.
169 //InternalSyncIncrement (
170 // IN volatile UINT32 *Value
172 InternalSyncIncrement
174 TryInternalSyncIncrement
179 bne TryInternalSyncIncrement
185 Performs an atomic decrement of an 32-bit unsigned integer.
187 Performs an atomic decrement of the 32-bit unsigned integer specified by
188 Value and returns the decrement value. The decrement operation must be
189 performed using MP safe mechanisms. The state of the return value is not
190 guaranteed to be MP safe.
192 @param Value A pointer to the 32-bit value to decrement.
194 @return The decrement value.
199 //InternalSyncDecrement (
200 // IN volatile UINT32 *Value
202 InternalSyncDecrement
204 TryInternalSyncDecrement
209 bne TryInternalSyncDecrement