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.
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):
52 InternalSyncCompareExchange16Again:
55 bne InternalSyncCompareExchange16Fail
57 InternalSyncCompareExchange16Exchange:
60 bne InternalSyncCompareExchange16Again
62 InternalSyncCompareExchange16Fail:
68 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
70 Performs an atomic compare exchange operation on the 32-bit unsigned integer
71 specified by Value. If Value is equal to CompareValue, then Value is set to
72 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
73 then Value is returned. The compare exchange operation must be performed using
76 @param Value A pointer to the 32-bit value for the compare exchange
78 @param CompareValue 32-bit value used in compare operation.
79 @param ExchangeValue 32-bit value used in exchange operation.
81 @return The original *Value before exchange.
86 //InternalSyncCompareExchange32 (
87 // IN volatile UINT32 *Value,
88 // IN UINT32 CompareValue,
89 // IN UINT32 ExchangeValue
91 ASM_PFX(InternalSyncCompareExchange32):
94 InternalSyncCompareExchange32Again:
97 bne InternalSyncCompareExchange32Fail
99 InternalSyncCompareExchange32Exchange:
102 bne 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, // r0
129 // IN UINT64 CompareValue, // r2-r3
130 // IN UINT64 ExchangeValue // stack
132 ASM_PFX(InternalSyncCompareExchange64):
134 ldrd r4, r5, [sp, #16]
137 InternalSyncCompareExchange64Again:
141 bne InternalSyncCompareExchange64Fail
143 InternalSyncCompareExchange64Exchange:
144 strexd ip, r4, r5, [r0]
146 bne InternalSyncCompareExchange64Again
148 InternalSyncCompareExchange64Fail:
156 Performs an atomic increment of an 32-bit unsigned integer.
158 Performs an atomic increment of the 32-bit unsigned integer specified by
159 Value and returns the incremented value. The increment operation must be
160 performed using MP safe mechanisms. The state of the return value is not
161 guaranteed to be MP safe.
163 @param Value A pointer to the 32-bit value to increment.
165 @return The incremented value.
170 //InternalSyncIncrement (
171 // IN volatile UINT32 *Value
173 ASM_PFX(InternalSyncIncrement):
175 TryInternalSyncIncrement:
180 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 ASM_PFX(InternalSyncDecrement):
204 TryInternalSyncDecrement:
209 bne TryInternalSyncDecrement