]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Arm / Synchronization.S
index 0128f8f016bdd7085d3bc23f29a108f7fb5e7ad8..607a1697b2d5289cef9c8ef7a32b9af9d738529c 100644 (file)
@@ -1,25 +1,63 @@
 //  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
@@ -135,6 +173,7 @@ TryInternalSyncIncrement:
   cmp     r2, #0\r
   bne     TryInternalSyncIncrement\r
   dmb\r
+  mov     r0, r1\r
   bx      lr\r
 \r
 /**\r
@@ -164,4 +203,5 @@ TryInternalSyncDecrement:
   cmp     r2, #0\r
   bne     TryInternalSyncDecrement\r
   dmb\r
+  mov     r0, r1\r
   bx      lr\r