1 ; Implementation of synchronization functions for ARM architecture (AArch64)
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
10 EXPORT InternalSyncCompareExchange16
11 EXPORT InternalSyncCompareExchange32
12 EXPORT InternalSyncCompareExchange64
13 EXPORT InternalSyncIncrement
14 EXPORT InternalSyncDecrement
15 AREA BaseSynchronizationLib_LowLevel, CODE, READONLY
18 ; Performs an atomic compare exchange operation on a 16-bit unsigned integer.
20 ; Performs an atomic compare exchange operation on the 16-bit unsigned integer
21 ; specified by Value. If Value is equal to CompareValue, then Value is set to
22 ; ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
23 ; then Value is returned. The compare exchange operation must be performed using
26 ; @param Value A pointer to the 16-bit value for the compare exchange
28 ; @param CompareValue 16-bit value used in compare operation.
29 ; @param ExchangeValue 16-bit value used in exchange operation.
31 ; @return The original *Value before exchange.
36 ;InternalSyncCompareExchange16 (
37 ; IN volatile UINT16 *Value,
38 ; IN UINT16 CompareValue,
39 ; IN UINT16 ExchangeValue
41 InternalSyncCompareExchange16
46 InternalSyncCompareExchange16Again
49 bne InternalSyncCompareExchange16Fail
51 InternalSyncCompareExchange16Exchange
53 cbnz w4, InternalSyncCompareExchange16Again
55 InternalSyncCompareExchange16Fail
61 ; Performs an atomic compare exchange operation on a 32-bit unsigned integer.
63 ; Performs an atomic compare exchange operation on the 32-bit unsigned integer
64 ; specified by Value. If Value is equal to CompareValue, then Value is set to
65 ; ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
66 ; then Value is returned. The compare exchange operation must be performed using
69 ; @param Value A pointer to the 32-bit value for the compare exchange
71 ; @param CompareValue 32-bit value used in compare operation.
72 ; @param ExchangeValue 32-bit value used in exchange operation.
74 ; @return The original *Value before exchange.
79 ;InternalSyncCompareExchange32 (
80 ; IN volatile UINT32 *Value,
81 ; IN UINT32 CompareValue,
82 ; IN UINT32 ExchangeValue
84 InternalSyncCompareExchange32
87 InternalSyncCompareExchange32Again
90 bne InternalSyncCompareExchange32Fail
92 InternalSyncCompareExchange32Exchange
94 cbnz w4, InternalSyncCompareExchange32Again
96 InternalSyncCompareExchange32Fail
102 ; Performs an atomic compare exchange operation on a 64-bit unsigned integer.
104 ; Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
105 ; by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
106 ; CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
107 ; The compare exchange operation must be performed using MP safe mechanisms.
109 ; @param Value A pointer to the 64-bit value for the compare exchange
111 ; @param CompareValue 64-bit value used in compare operation.
112 ; @param ExchangeValue 64-bit value used in exchange operation.
114 ; @return The original *Value before exchange.
119 ;InternalSyncCompareExchange64 (
120 ; IN volatile UINT64 *Value,
121 ; IN UINT64 CompareValue,
122 ; IN UINT64 ExchangeValue
124 InternalSyncCompareExchange64
127 InternalSyncCompareExchange64Again
130 bne InternalSyncCompareExchange64Fail
132 InternalSyncCompareExchange64Exchange
134 cbnz w4, InternalSyncCompareExchange64Again
136 InternalSyncCompareExchange64Fail
142 ; Performs an atomic increment of an 32-bit unsigned integer.
144 ; Performs an atomic increment of the 32-bit unsigned integer specified by
145 ; Value and returns the incremented value. The increment operation must be
146 ; performed using MP safe mechanisms. The state of the return value is not
147 ; guaranteed to be MP safe.
149 ; @param Value A pointer to the 32-bit value to increment.
151 ; @return The incremented value.
156 ;InternalSyncIncrement (
157 ; IN volatile UINT32 *Value
159 InternalSyncIncrement
161 TryInternalSyncIncrement
165 cbnz w2, TryInternalSyncIncrement
171 ; Performs an atomic decrement of an 32-bit unsigned integer.
173 ; Performs an atomic decrement of the 32-bit unsigned integer specified by
174 ; Value and returns the decrement value. The decrement operation must be
175 ; performed using MP safe mechanisms. The state of the return value is not
176 ; guaranteed to be MP safe.
178 ; @param Value A pointer to the 32-bit value to decrement.
180 ; @return The decrement value.
185 ;InternalSyncDecrement (
186 ; IN volatile UINT32 *Value
188 InternalSyncDecrement
190 TryInternalSyncDecrement
194 cbnz w2, TryInternalSyncDecrement