);\r
\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
+ If Value is NULL, then ASSERT().\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
+UINT16\r
+EFIAPI\r
+InterlockedCompareExchange16 (\r
+ IN OUT UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ );\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\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
+ uxth w1, w1\r
+ uxth w2, w2\r
+ dmb sy\r
+\r
+InternalSyncCompareExchange16Again:\r
+ ldxrh w3, [x0]\r
+ cmp w3, w1\r
+ bne InternalSyncCompareExchange16Fail\r
+\r
+InternalSyncCompareExchange16Exchange:\r
+ stxrh w4, w2, [x0]\r
+ cbnz w4, InternalSyncCompareExchange16Again\r
+\r
+InternalSyncCompareExchange16Fail:\r
+ dmb sy\r
+ mov w0, w3\r
+ ret\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
// 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
.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
// 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
//\r
//\r
\r
+ EXPORT InternalSyncCompareExchange16\r
EXPORT InternalSyncCompareExchange32\r
EXPORT InternalSyncCompareExchange64\r
EXPORT InternalSyncIncrement\r
\r
AREA ArmSynchronization, CODE, READONLY\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
+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
[Sources.IA32]\r
Ia32/InterlockedCompareExchange64.c | MSFT \r
Ia32/InterlockedCompareExchange32.c | MSFT \r
+ Ia32/InterlockedCompareExchange16.c | MSFT\r
Ia32/InterlockedDecrement.c | MSFT \r
Ia32/InterlockedIncrement.c | MSFT \r
SynchronizationMsc.c | MSFT\r
\r
Ia32/InterlockedCompareExchange64.asm | INTEL \r
Ia32/InterlockedCompareExchange32.asm | INTEL \r
+ Ia32/InterlockedCompareExchange16.asm | INTEL\r
Ia32/InterlockedDecrement.asm | INTEL \r
Ia32/InterlockedIncrement.asm | INTEL \r
Synchronization.c | INTEL\r
[Sources.X64]\r
X64/InterlockedCompareExchange64.c | MSFT\r
X64/InterlockedCompareExchange32.c | MSFT\r
+ X64/InterlockedCompareExchange16.c | MSFT\r
\r
X64/InterlockedCompareExchange64.asm | INTEL\r
X64/InterlockedCompareExchange32.asm | INTEL\r
+ X64/InterlockedCompareExchange16.asm | INTEL\r
\r
X64/InterlockedDecrement.c | MSFT \r
X64/InterlockedIncrement.c | MSFT \r
Ipf/Synchronization.c\r
Ipf/InterlockedCompareExchange64.s\r
Ipf/InterlockedCompareExchange32.s\r
+ Ipf/InterlockedCompareExchange16.s\r
\r
Synchronization.c | INTEL \r
SynchronizationMsc.c | MSFT \r
);\r
\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 A 16-bit value used in compare operation.\r
+ @param ExchangeValue A 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
+\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
\r
**/\r
\r
+/**\r
+ Performs an atomic compare exchange operation on a 16-bit\r
+ unsigned integer.\r
+\r
+ Performs an atomic compare exchange operation on the 16-bit\r
+ unsigned integer specified by Value. If Value is equal to\r
+ CompareValue, then Value is set to ExchangeValue and\r
+ CompareValue is returned. If Value is not equal to\r
+ CompareValue, then Value is returned. The compare exchange\r
+ operation must be performed using MP safe mechanisms.\r
+\r
+ @param Value A pointer to the 16-bit value for the\r
+ compare exchange 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
+{\r
+ return *Value != CompareValue ? *Value :\r
+ ((*Value = ExchangeValue), CompareValue);\r
+}\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit\r
unsigned integer.\r
return Result;\r
}\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
+\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 OUT volatile UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ )\r
+{\r
+\r
+ __asm__ __volatile__ (\r
+ " \n\t"\r
+ "lock \n\t"\r
+ "cmpxchgw %1, %2 \n\t"\r
+ : "=a" (CompareValue)\r
+ : "q" (ExchangeValue),\r
+ "m" (*Value),\r
+ "0" (CompareValue)\r
+ : "memory",\r
+ "cc"\r
+ );\r
+\r
+ return CompareValue;\r
+}\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
--- /dev/null
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
+; Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution. The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+; InterlockedCompareExchange16.Asm
+;
+; Abstract:
+;
+; InterlockedCompareExchange16 function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .486
+ .model flat,C
+ .code
+
+;------------------------------------------------------------------------------
+; UINT16
+; EFIAPI
+; InternalSyncCompareExchange16 (
+; IN UINT16 *Value,
+; IN UINT16 CompareValue,
+; IN UINT16 ExchangeValue
+; );
+;------------------------------------------------------------------------------
+InternalSyncCompareExchange16 PROC
+ mov ecx, [esp + 4]
+ mov ax, [esp + 8]
+ mov dx, [esp + 12]
+ lock cmpxchg [ecx], dx
+ ret
+InternalSyncCompareExchange16 ENDP
+
+ END
--- /dev/null
+/** @file
+ InterlockedCompareExchange16 function
+
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+
+
+
+/**
+ Performs an atomic compare exchange operation on a 16-bit unsigned integer.
+
+ Performs an atomic compare exchange operation on the 16-bit unsigned integer
+ specified by Value. If Value is equal to CompareValue, then Value is set to
+ ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
+ then Value is returned. The compare exchange operation must be performed using
+ MP safe mechanisms.
+
+ @param Value A pointer to the 16-bit value for the compare exchange
+ operation.
+ @param CompareValue 16-bit value used in compare operation.
+ @param ExchangeValue 16-bit value used in exchange operation.
+
+ @return The original *Value before exchange.
+
+**/
+UINT16
+EFIAPI
+InternalSyncCompareExchange16 (
+ IN UINT16 *Value,
+ IN UINT16 CompareValue,
+ IN UINT16 ExchangeValue
+ )
+{
+ _asm {
+ mov ecx, Value
+ mov ax, CompareValue
+ mov dx, ExchangeValue
+ lock cmpxchg [ecx], dx
+ }
+}
+
--- /dev/null
+/// @file
+/// Contains an implementation of InterlockedCompareExchange16 on Itanium-
+/// based architecture.
+///
+/// Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
+/// Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+/// This program and the accompanying materials
+/// are licensed and made available under the terms and conditions of the BSD License
+/// which accompanies this distribution. The full text of the license may be found at
+/// http://opensource.org/licenses/bsd-license.php.
+///
+/// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+/// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+///
+/// Module Name: InterlockedCompareExchange16.s
+///
+///
+
+.auto
+.text
+
+.proc InternalSyncCompareExchange16
+.type InternalSyncCompareExchange16, @function
+InternalSyncCompareExchange16::
+ zxt2 r33 = r33
+ mov ar.ccv = r33
+ cmpxchg2.rel r8 = [r32], r34
+ mf
+ br.ret.sptk.many b0
+.endp InternalSyncCompareExchange16
return InternalSyncDecrement (Value);\r
}\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
+ If Value is NULL, then ASSERT().\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
+InterlockedCompareExchange16 (\r
+ IN OUT UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ )\r
+{\r
+ ASSERT (Value != NULL);\r
+ return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue);\r
+}\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
return InternalSyncDecrement (Value);\r
}\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
+ If Value is NULL, then ASSERT().\r
+\r
+ @param Value A pointer to the 16-bit value for the compare exchange\r
+ operation.\r
+ @param CompareValue A 16-bit value used in compare operation.\r
+ @param ExchangeValue A 16-bit value used in exchange operation.\r
+\r
+ @return The original *Value before exchange.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+InterlockedCompareExchange16 (\r
+ IN OUT UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ )\r
+{\r
+ ASSERT (Value != NULL);\r
+ return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue);\r
+}\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
return InternalSyncDecrement (Value);\r
}\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
+ If Value is NULL, then ASSERT().\r
+\r
+ @param Value A pointer to the 16-bit value for the compare exchange\r
+ operation.\r
+ @param CompareValue A 16-bit value used in a compare operation.\r
+ @param ExchangeValue A 16-bit value used in an exchange operation.\r
+\r
+ @return The original *Value before exchange.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+InterlockedCompareExchange16 (\r
+ IN OUT UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ )\r
+{\r
+ ASSERT (Value != NULL);\r
+ return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue);\r
+}\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
}\r
\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
+\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 OUT volatile UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ )\r
+{\r
+\r
+\r
+ __asm__ __volatile__ (\r
+ "lock \n\t"\r
+ "cmpxchgw %3, %1 "\r
+ : "=a" (CompareValue),\r
+ "=m" (*Value)\r
+ : "a" (CompareValue),\r
+ "r" (ExchangeValue),\r
+ "m" (*Value)\r
+ : "memory",\r
+ "cc"\r
+ );\r
+\r
+ return CompareValue;\r
+}\r
+\r
+\r
/**\r
Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
\r
--- /dev/null
+;------------------------------------------------------------------------------
+;
+; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
+; Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>
+; This program and the accompanying materials
+; are licensed and made available under the terms and conditions of the BSD License
+; which accompanies this distribution. The full text of the license may be found at
+; http://opensource.org/licenses/bsd-license.php.
+;
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+;
+; Module Name:
+;
+; InterlockedCompareExchange16.Asm
+;
+; Abstract:
+;
+; InterlockedCompareExchange16 function
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+ .code
+
+;------------------------------------------------------------------------------
+; UINT16
+; EFIAPI
+; InterlockedCompareExchange16 (
+; IN UINT16 *Value,
+; IN UINT16 CompareValue,
+; IN UINT16 ExchangeValue
+; );
+;------------------------------------------------------------------------------
+InternalSyncCompareExchange16 PROC
+ mov ax, dx
+ lock cmpxchg [rcx], r8w
+ ret
+InternalSyncCompareExchange16 ENDP
+
+ END
--- /dev/null
+/** @file\r
+ InterlockedCompareExchange16 function\r
+\r
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2015, Linaro Ltd. All rights reserved.<BR>\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
+\r
+**/\r
+\r
+/**\r
+ Microsoft Visual Studio 7.1 Function Prototypes for I/O Intrinsics.\r
+**/\r
+\r
+__int16 _InterlockedCompareExchange16(\r
+ __int16 volatile * Destination,\r
+ __int16 Exchange,\r
+ __int16 Comperand\r
+);\r
+\r
+#pragma intrinsic(_InterlockedCompareExchange16)\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 specified\r
+ by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
+ CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r
+ The compare exchange operation must be performed using 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 UINT16 *Value,\r
+ IN UINT16 CompareValue,\r
+ IN UINT16 ExchangeValue\r
+ )\r
+{\r
+ return _InterlockedCompareExchange16 (Value, ExchangeValue, CompareValue);\r
+}\r
+\r