// Implementation of synchronization functions for ARM architecture\r
//\r
// Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r
+// Copyright (c) 2015, Linaro Limited. All rights reserved.\r
//\r
-// This program and the accompanying materials\r
-// are licensed and made available under the terms and conditions of the BSD License\r
-// which accompanies this distribution. The full text of the license may be found at\r
-// http://opensource.org/licenses/bsd-license.php\r
-//\r
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+// SPDX-License-Identifier: BSD-2-Clause-Patent\r
//\r
//\r
\r
.text\r
.align 3\r
\r
+GCC_ASM_EXPORT(InternalSyncCompareExchange16)\r
GCC_ASM_EXPORT(InternalSyncCompareExchange32)\r
GCC_ASM_EXPORT(InternalSyncCompareExchange64)\r
GCC_ASM_EXPORT(InternalSyncIncrement)\r
GCC_ASM_EXPORT(InternalSyncDecrement)\r
\r
+/**\r
+ Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
+\r
+ Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
+ specified by Value. If Value is equal to CompareValue, then Value is set to\r
+ ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
+ then Value is returned. The compare exchange operation must be performed using\r
+ MP safe mechanisms.\r
+\r
+ @param Value A pointer to the 16-bit value for the compare exchange\r
+ operation.\r
+ @param CompareValue 16-bit value used in compare operation.\r
+ @param ExchangeValue 16-bit value used in exchange operation.\r
+\r
+ @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT16\r
+//EFIAPI\r
+//InternalSyncCompareExchange16 (\r
+// IN volatile UINT16 *Value,\r
+// IN UINT16 CompareValue,\r
+// IN UINT16 ExchangeValue\r
+// )\r
+ASM_PFX(InternalSyncCompareExchange16):\r
+ dmb\r
+\r
+InternalSyncCompareExchange16Again:\r
+ ldrexh r3, [r0]\r
+ cmp r3, r1\r
+ bne InternalSyncCompareExchange16Fail\r
+\r
+InternalSyncCompareExchange16Exchange:\r
+ strexh ip, r2, [r0]\r
+ cmp ip, #0\r
+ bne InternalSyncCompareExchange16Again\r
+\r
+InternalSyncCompareExchange16Fail:\r
+ dmb\r
+ mov r0, r3\r
+ bx lr\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
cmp r2, #0\r
bne TryInternalSyncIncrement\r
dmb\r
+ mov r0, r1\r
bx lr\r
\r
/**\r
cmp r2, #0\r
bne TryInternalSyncDecrement\r
dmb\r
+ mov r0, r1\r
bx lr\r