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.
15 EXPORT InternalSyncCompareExchange32
16 EXPORT InternalSyncCompareExchange64
17 EXPORT InternalSyncIncrement
18 EXPORT InternalSyncDecrement
20 AREA ArmSynchronization, CODE, READONLY
23 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
25 Performs an atomic compare exchange operation on the 32-bit unsigned integer
26 specified by Value. If Value is equal to CompareValue, then Value is set to
27 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
28 then Value is returned. The compare exchange operation must be performed using
31 @param Value A pointer to the 32-bit value for the compare exchange
33 @param CompareValue 32-bit value used in compare operation.
34 @param ExchangeValue 32-bit value used in exchange operation.
36 @return The original *Value before exchange.
41 //InternalSyncCompareExchange32 (
42 // IN volatile UINT32 *Value,
43 // IN UINT32 CompareValue,
44 // IN UINT32 ExchangeValue
46 InternalSyncCompareExchange32
49 InternalSyncCompareExchange32Again
52 bne InternalSyncCompareExchange32Fail
54 InternalSyncCompareExchange32Exchange
57 bne InternalSyncCompareExchange32Again
59 InternalSyncCompareExchange32Fail
65 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
67 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
68 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
69 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
70 The compare exchange operation must be performed using MP safe mechanisms.
72 @param Value A pointer to the 64-bit value for the compare exchange
74 @param CompareValue 64-bit value used in compare operation.
75 @param ExchangeValue 64-bit value used in exchange operation.
77 @return The original *Value before exchange.
82 //InternalSyncCompareExchange64 (
83 // IN volatile UINT64 *Value, // r0
84 // IN UINT64 CompareValue, // r2-r3
85 // IN UINT64 ExchangeValue // stack
87 InternalSyncCompareExchange64
89 ldrd r4, r5, [sp, #16]
92 InternalSyncCompareExchange64Again
96 bne InternalSyncCompareExchange64Fail
98 InternalSyncCompareExchange64Exchange
99 strexd ip, r4, r5, [r0]
101 bne InternalSyncCompareExchange64Again
103 InternalSyncCompareExchange64Fail
111 Performs an atomic increment of an 32-bit unsigned integer.
113 Performs an atomic increment of the 32-bit unsigned integer specified by
114 Value and returns the incremented value. The increment operation must be
115 performed using MP safe mechanisms. The state of the return value is not
116 guaranteed to be MP safe.
118 @param Value A pointer to the 32-bit value to increment.
120 @return The incremented value.
125 //InternalSyncIncrement (
126 // IN volatile UINT32 *Value
128 InternalSyncIncrement
130 TryInternalSyncIncrement
135 bne TryInternalSyncIncrement
140 Performs an atomic decrement of an 32-bit unsigned integer.
142 Performs an atomic decrement of the 32-bit unsigned integer specified by
143 Value and returns the decrement value. The decrement operation must be
144 performed using MP safe mechanisms. The state of the return value is not
145 guaranteed to be MP safe.
147 @param Value A pointer to the 32-bit value to decrement.
149 @return The decrement value.
154 //InternalSyncDecrement (
155 // IN volatile UINT32 *Value
157 InternalSyncDecrement
159 TryInternalSyncDecrement
164 bne TryInternalSyncDecrement