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 // 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.
19 GCC_ASM_EXPORT(InternalSyncCompareExchange16)
20 GCC_ASM_EXPORT(InternalSyncCompareExchange32)
21 GCC_ASM_EXPORT(InternalSyncCompareExchange64)
22 GCC_ASM_EXPORT(InternalSyncIncrement)
23 GCC_ASM_EXPORT(InternalSyncDecrement)
26 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
28 Performs an atomic compare exchange operation on the 16-bit unsigned integer
29 specified by Value. If Value is equal to CompareValue, then Value is set to
30 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
31 then Value is returned. The compare exchange operation must be performed using
34 @param Value A pointer to the 16-bit value for the compare exchange
36 @param CompareValue 16-bit value used in compare operation.
37 @param ExchangeValue 16-bit value used in exchange operation.
39 @return The original *Value before exchange.
44 //InternalSyncCompareExchange16 (
45 // IN volatile UINT16 *Value,
46 // IN UINT16 CompareValue,
47 // IN UINT16 ExchangeValue
49 ASM_PFX(InternalSyncCompareExchange16):
54 InternalSyncCompareExchange16Again:
57 bne InternalSyncCompareExchange16Fail
59 InternalSyncCompareExchange16Exchange:
61 cbnz w4, InternalSyncCompareExchange16Again
63 InternalSyncCompareExchange16Fail:
69 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
71 Performs an atomic compare exchange operation on the 32-bit unsigned integer
72 specified by Value. If Value is equal to CompareValue, then Value is set to
73 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
74 then Value is returned. The compare exchange operation must be performed using
77 @param Value A pointer to the 32-bit value for the compare exchange
79 @param CompareValue 32-bit value used in compare operation.
80 @param ExchangeValue 32-bit value used in exchange operation.
82 @return The original *Value before exchange.
87 //InternalSyncCompareExchange32 (
88 // IN volatile UINT32 *Value,
89 // IN UINT32 CompareValue,
90 // IN UINT32 ExchangeValue
92 ASM_PFX(InternalSyncCompareExchange32):
95 InternalSyncCompareExchange32Again:
98 bne InternalSyncCompareExchange32Fail
100 InternalSyncCompareExchange32Exchange:
102 cbnz w4, InternalSyncCompareExchange32Again
104 InternalSyncCompareExchange32Fail:
110 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
112 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
113 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
114 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
115 The compare exchange operation must be performed using MP safe mechanisms.
117 @param Value A pointer to the 64-bit value for the compare exchange
119 @param CompareValue 64-bit value used in compare operation.
120 @param ExchangeValue 64-bit value used in exchange operation.
122 @return The original *Value before exchange.
127 //InternalSyncCompareExchange64 (
128 // IN volatile UINT64 *Value,
129 // IN UINT64 CompareValue,
130 // IN UINT64 ExchangeValue
132 ASM_PFX(InternalSyncCompareExchange64):
135 InternalSyncCompareExchange64Again:
138 bne InternalSyncCompareExchange64Fail
140 InternalSyncCompareExchange64Exchange:
142 cbnz w4, InternalSyncCompareExchange64Again
144 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:
173 cbnz w2, TryInternalSyncIncrement
179 Performs an atomic decrement of an 32-bit unsigned integer.
181 Performs an atomic decrement of the 32-bit unsigned integer specified by
182 Value and returns the decrement value. The decrement operation must be
183 performed using MP safe mechanisms. The state of the return value is not
184 guaranteed to be MP safe.
186 @param Value A pointer to the 32-bit value to decrement.
188 @return The decrement value.
193 //InternalSyncDecrement (
194 // IN volatile UINT32 *Value
196 ASM_PFX(InternalSyncDecrement):
198 TryInternalSyncDecrement:
202 cbnz w2, TryInternalSyncDecrement