1 // Implementation of synchronization functions for ARM architecture
3 // Copyright (c) 2012-2015, ARM Limited. All rights reserved.
5 // This program and the accompanying materials
6 // are licensed and made available under the terms and conditions of the BSD License
7 // which accompanies this distribution. The full text of the license may be found at
8 // http://opensource.org/licenses/bsd-license.php
10 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 GCC_ASM_EXPORT(InternalSyncCompareExchange32)
19 GCC_ASM_EXPORT(InternalSyncCompareExchange64)
20 GCC_ASM_EXPORT(InternalSyncIncrement)
21 GCC_ASM_EXPORT(InternalSyncDecrement)
24 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
26 Performs an atomic compare exchange operation on the 32-bit unsigned integer
27 specified by Value. If Value is equal to CompareValue, then Value is set to
28 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
29 then Value is returned. The compare exchange operation must be performed using
32 @param Value A pointer to the 32-bit value for the compare exchange
34 @param CompareValue 32-bit value used in compare operation.
35 @param ExchangeValue 32-bit value used in exchange operation.
37 @return The original *Value before exchange.
42 //InternalSyncCompareExchange32 (
43 // IN volatile UINT32 *Value,
44 // IN UINT32 CompareValue,
45 // IN UINT32 ExchangeValue
47 ASM_PFX(InternalSyncCompareExchange32):
50 InternalSyncCompareExchange32Again:
53 bne InternalSyncCompareExchange32Fail
55 InternalSyncCompareExchange32Exchange:
58 bne InternalSyncCompareExchange32Again
60 InternalSyncCompareExchange32Fail:
66 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
68 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
69 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
70 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
71 The compare exchange operation must be performed using MP safe mechanisms.
73 @param Value A pointer to the 64-bit value for the compare exchange
75 @param CompareValue 64-bit value used in compare operation.
76 @param ExchangeValue 64-bit value used in exchange operation.
78 @return The original *Value before exchange.
83 //InternalSyncCompareExchange64 (
84 // IN volatile UINT64 *Value, // r0
85 // IN UINT64 CompareValue, // r2-r3
86 // IN UINT64 ExchangeValue // stack
88 ASM_PFX(InternalSyncCompareExchange64):
90 ldrd r4, r5, [sp, #16]
93 InternalSyncCompareExchange64Again:
97 bne InternalSyncCompareExchange64Fail
99 InternalSyncCompareExchange64Exchange:
100 strexd ip, r4, r5, [r0]
102 bne InternalSyncCompareExchange64Again
104 InternalSyncCompareExchange64Fail:
112 Performs an atomic increment of an 32-bit unsigned integer.
114 Performs an atomic increment of the 32-bit unsigned integer specified by
115 Value and returns the incremented value. The increment operation must be
116 performed using MP safe mechanisms. The state of the return value is not
117 guaranteed to be MP safe.
119 @param Value A pointer to the 32-bit value to increment.
121 @return The incremented value.
126 //InternalSyncIncrement (
127 // IN volatile UINT32 *Value
129 ASM_PFX(InternalSyncIncrement):
131 TryInternalSyncIncrement:
136 bne TryInternalSyncIncrement
141 Performs an atomic decrement of an 32-bit unsigned integer.
143 Performs an atomic decrement of the 32-bit unsigned integer specified by
144 Value and returns the decrement value. The decrement operation must be
145 performed using MP safe mechanisms. The state of the return value is not
146 guaranteed to be MP safe.
148 @param Value A pointer to the 32-bit value to decrement.
150 @return The decrement value.
155 //InternalSyncDecrement (
156 // IN volatile UINT32 *Value
158 ASM_PFX(InternalSyncDecrement):
160 TryInternalSyncDecrement:
165 bne TryInternalSyncDecrement