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 // SPDX-License-Identifier: BSD-2-Clause-Patent
13 GCC_ASM_EXPORT(InternalSyncCompareExchange16)
14 GCC_ASM_EXPORT(InternalSyncCompareExchange32)
15 GCC_ASM_EXPORT(InternalSyncCompareExchange64)
16 GCC_ASM_EXPORT(InternalSyncIncrement)
17 GCC_ASM_EXPORT(InternalSyncDecrement)
20 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
22 Performs an atomic compare exchange operation on the 16-bit unsigned integer
23 specified by Value. If Value is equal to CompareValue, then Value is set to
24 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
25 then Value is returned. The compare exchange operation must be performed using
28 @param Value A pointer to the 16-bit value for the compare exchange
30 @param CompareValue 16-bit value used in compare operation.
31 @param ExchangeValue 16-bit value used in exchange operation.
33 @return The original *Value before exchange.
38 //InternalSyncCompareExchange16 (
39 // IN volatile UINT16 *Value,
40 // IN UINT16 CompareValue,
41 // IN UINT16 ExchangeValue
43 ASM_PFX(InternalSyncCompareExchange16):
46 InternalSyncCompareExchange16Again:
49 bne InternalSyncCompareExchange16Fail
51 InternalSyncCompareExchange16Exchange:
54 bne InternalSyncCompareExchange16Again
56 InternalSyncCompareExchange16Fail:
62 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
64 Performs an atomic compare exchange operation on the 32-bit unsigned integer
65 specified by Value. If Value is equal to CompareValue, then Value is set to
66 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
67 then Value is returned. The compare exchange operation must be performed using
70 @param Value A pointer to the 32-bit value for the compare exchange
72 @param CompareValue 32-bit value used in compare operation.
73 @param ExchangeValue 32-bit value used in exchange operation.
75 @return The original *Value before exchange.
80 //InternalSyncCompareExchange32 (
81 // IN volatile UINT32 *Value,
82 // IN UINT32 CompareValue,
83 // IN UINT32 ExchangeValue
85 ASM_PFX(InternalSyncCompareExchange32):
88 InternalSyncCompareExchange32Again:
91 bne InternalSyncCompareExchange32Fail
93 InternalSyncCompareExchange32Exchange:
96 bne InternalSyncCompareExchange32Again
98 InternalSyncCompareExchange32Fail:
104 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
106 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
107 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
108 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
109 The compare exchange operation must be performed using MP safe mechanisms.
111 @param Value A pointer to the 64-bit value for the compare exchange
113 @param CompareValue 64-bit value used in compare operation.
114 @param ExchangeValue 64-bit value used in exchange operation.
116 @return The original *Value before exchange.
121 //InternalSyncCompareExchange64 (
122 // IN volatile UINT64 *Value, // r0
123 // IN UINT64 CompareValue, // r2-r3
124 // IN UINT64 ExchangeValue // stack
126 ASM_PFX(InternalSyncCompareExchange64):
128 ldrd r4, r5, [sp, #16]
131 InternalSyncCompareExchange64Again:
135 bne InternalSyncCompareExchange64Fail
137 InternalSyncCompareExchange64Exchange:
138 strexd ip, r4, r5, [r0]
140 bne InternalSyncCompareExchange64Again
142 InternalSyncCompareExchange64Fail:
150 Performs an atomic increment of an 32-bit unsigned integer.
152 Performs an atomic increment of the 32-bit unsigned integer specified by
153 Value and returns the incremented value. The increment operation must be
154 performed using MP safe mechanisms. The state of the return value is not
155 guaranteed to be MP safe.
157 @param Value A pointer to the 32-bit value to increment.
159 @return The incremented value.
164 //InternalSyncIncrement (
165 // IN volatile UINT32 *Value
167 ASM_PFX(InternalSyncIncrement):
169 TryInternalSyncIncrement:
174 bne TryInternalSyncIncrement
180 Performs an atomic decrement of an 32-bit unsigned integer.
182 Performs an atomic decrement of the 32-bit unsigned integer specified by
183 Value and returns the decrement value. The decrement operation must be
184 performed using MP safe mechanisms. The state of the return value is not
185 guaranteed to be MP safe.
187 @param Value A pointer to the 32-bit value to decrement.
189 @return The decrement value.
194 //InternalSyncDecrement (
195 // IN volatile UINT32 *Value
197 ASM_PFX(InternalSyncDecrement):
199 TryInternalSyncDecrement:
204 bne TryInternalSyncDecrement