diff options
author | Mitchell Horne <mhorne@FreeBSD.org> | 2020-06-03 18:44:51 +0000 |
---|---|---|
committer | Mitchell Horne <mhorne@FreeBSD.org> | 2020-06-03 18:44:51 +0000 |
commit | 4a14dfcc1110b35118d5be8054fecf59ffb83032 (patch) | |
tree | 8bf1574ccba91c926acbe0a05d32482ba8825e26 /MdePkg/Library/BaseSynchronizationLib | |
parent | 0499b37cea9ca98acfe36368e521ad36b7783f2d (diff) | |
download | src-vendor/edk2.tar.gz src-vendor/edk2.zip |
Import edk2-stable202005vendor/edk2/ca407c7246bf405da6d9b1b9d93e5e7f17b4b1f9vendor/edk2
As with the previous import, only the MdePkg subdirectory has been
brought in. The line-endings were also converted using:
% find . -type f | xargs -n 1 sed -I.BAK -e `printf "s/\r//g"`
% find . -name \*.BAK | xargs rm
Notes
Notes:
svn path=/vendor/edk2/dist/; revision=361765
svn path=/vendor/edk2/ca407c7246bf405da6d9b1b9d93e5e7f17b4b1f9/; revision=361766; tag=vendor/edk2/ca407c7246bf405da6d9b1b9d93e5e7f17b4b1f9
Diffstat (limited to 'MdePkg/Library/BaseSynchronizationLib')
50 files changed, 444 insertions, 1100 deletions
diff --git a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S index 2edd526605c6..8c9f39f21615 100644 --- a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S +++ b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S @@ -3,13 +3,7 @@ // Copyright (c) 2012-2015, ARM Limited. All rights reserved. // Copyright (c) 2015, Linaro Limited. All rights reserved. // -// 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent // // diff --git a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.asm b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.asm new file mode 100644 index 000000000000..8209947f80df --- /dev/null +++ b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.asm @@ -0,0 +1,199 @@ +; Implementation of synchronization functions for ARM architecture (AArch64) +; +; Copyright (c) 2012-2015, ARM Limited. All rights reserved. +; Copyright (c) 2015, Linaro Limited. All rights reserved. +; +; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; + + EXPORT InternalSyncCompareExchange16 + EXPORT InternalSyncCompareExchange32 + EXPORT InternalSyncCompareExchange64 + EXPORT InternalSyncIncrement + EXPORT InternalSyncDecrement + AREA BaseSynchronizationLib_LowLevel, CODE, READONLY + +;/** +; 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 volatile UINT16 *Value, +; IN UINT16 CompareValue, +; IN UINT16 ExchangeValue +; ) +InternalSyncCompareExchange16 + uxth w1, w1 + uxth w2, w2 + dmb sy + +InternalSyncCompareExchange16Again + ldxrh w3, [x0] + cmp w3, w1 + bne InternalSyncCompareExchange16Fail + +InternalSyncCompareExchange16Exchange + stxrh w4, w2, [x0] + cbnz w4, InternalSyncCompareExchange16Again + +InternalSyncCompareExchange16Fail + dmb sy + mov w0, w3 + ret + +;/** +; Performs an atomic compare exchange operation on a 32-bit unsigned integer. +; +; Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange +; operation. +; @param CompareValue 32-bit value used in compare operation. +; @param ExchangeValue 32-bit value used in exchange operation. +; +; @return The original *Value before exchange. +; +;**/ +;UINT32 +;EFIAPI +;InternalSyncCompareExchange32 ( +; IN volatile UINT32 *Value, +; IN UINT32 CompareValue, +; IN UINT32 ExchangeValue +; ) +InternalSyncCompareExchange32 + dmb sy + +InternalSyncCompareExchange32Again + ldxr w3, [x0] + cmp w3, w1 + bne InternalSyncCompareExchange32Fail + +InternalSyncCompareExchange32Exchange + stxr w4, w2, [x0] + cbnz w4, InternalSyncCompareExchange32Again + +InternalSyncCompareExchange32Fail + dmb sy + mov w0, w3 + ret + +;/** +; Performs an atomic compare exchange operation on a 64-bit unsigned integer. +; +; Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange +; operation. +; @param CompareValue 64-bit value used in compare operation. +; @param ExchangeValue 64-bit value used in exchange operation. +; +; @return The original *Value before exchange. +; +;**/ +;UINT64 +;EFIAPI +;InternalSyncCompareExchange64 ( +; IN volatile UINT64 *Value, +; IN UINT64 CompareValue, +; IN UINT64 ExchangeValue +; ) +InternalSyncCompareExchange64 + dmb sy + +InternalSyncCompareExchange64Again + ldxr x3, [x0] + cmp x3, x1 + bne InternalSyncCompareExchange64Fail + +InternalSyncCompareExchange64Exchange + stxr w4, x2, [x0] + cbnz w4, InternalSyncCompareExchange64Again + +InternalSyncCompareExchange64Fail + dmb sy + mov x0, x3 + ret + +;/** +; Performs an atomic increment of an 32-bit unsigned integer. +; +; Performs an atomic increment of the 32-bit unsigned integer specified by +; Value and returns the incremented value. The increment operation must be +; performed using MP safe mechanisms. The state of the return value is not +; guaranteed to be MP safe. +; +; @param Value A pointer to the 32-bit value to increment. +; +; @return The incremented value. +; +;**/ +;UINT32 +;EFIAPI +;InternalSyncIncrement ( +; IN volatile UINT32 *Value +; ) +InternalSyncIncrement + dmb sy +TryInternalSyncIncrement + ldxr w1, [x0] + add w1, w1, #1 + stxr w2, w1, [x0] + cbnz w2, TryInternalSyncIncrement + mov w0, w1 + dmb sy + ret + +;/** +; Performs an atomic decrement of an 32-bit unsigned integer. +; +; Performs an atomic decrement of the 32-bit unsigned integer specified by +; Value and returns the decrement value. The decrement operation must be +; performed using MP safe mechanisms. The state of the return value is not +; guaranteed to be MP safe. +; +; @param Value A pointer to the 32-bit value to decrement. +; +; @return The decrement value. +; +;**/ +;UINT32 +;EFIAPI +;InternalSyncDecrement ( +; IN volatile UINT32 *Value +; ) +InternalSyncDecrement + dmb sy +TryInternalSyncDecrement + ldxr w1, [x0] + sub w1, w1, #1 + stxr w2, w1, [x0] + cbnz w2, TryInternalSyncDecrement + mov w0, w1 + dmb sy + ret + + END diff --git a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S index b63feba411a9..64b24831c95d 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S +++ b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S @@ -3,13 +3,7 @@ // Copyright (c) 2012-2015, ARM Limited. All rights reserved. // Copyright (c) 2015, Linaro Limited. All rights reserved. // -// 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent // // diff --git a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm index fac8794971ef..62e53a0ddec1 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm +++ b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm @@ -3,13 +3,7 @@ // Copyright (c) 2012-2015, ARM Limited. All rights reserved. // Copyright (c) 2015, Linaro Limited. All rights reserved. // -// 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent // // diff --git a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf index 25898e7fe317..327bef039381 100755 --- a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf +++ b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf @@ -1,15 +1,11 @@ ## @file # Base Synchronization Library implementation. # -# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> +# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. 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. +# SPDX-License-Identifier: BSD-2-Clause-Patent # # ## @@ -24,30 +20,25 @@ LIBRARY_CLASS = SynchronizationLib # -# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM AARCH64 +# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64 # [Sources] BaseSynchronizationLibInternals.h [Sources.IA32] Ia32/InternalGetSpinLockProperties.c | MSFT - Ia32/InterlockedCompareExchange64.c | MSFT - Ia32/InterlockedCompareExchange32.c | MSFT + Ia32/InterlockedCompareExchange64.c | MSFT + Ia32/InterlockedCompareExchange32.c | MSFT Ia32/InterlockedCompareExchange16.c | MSFT - Ia32/InterlockedDecrement.c | MSFT - Ia32/InterlockedIncrement.c | MSFT - SynchronizationMsc.c | MSFT + InterlockedIncrementMsc.c | MSFT + InterlockedDecrementMsc.c | MSFT + SynchronizationMsc.c | MSFT Ia32/InterlockedCompareExchange64.nasm| INTEL - Ia32/InterlockedCompareExchange64.asm | INTEL Ia32/InterlockedCompareExchange32.nasm| INTEL - Ia32/InterlockedCompareExchange32.asm | INTEL Ia32/InterlockedCompareExchange16.nasm| INTEL - Ia32/InterlockedCompareExchange16.asm | INTEL Ia32/InterlockedDecrement.nasm| INTEL - Ia32/InterlockedDecrement.asm | INTEL Ia32/InterlockedIncrement.nasm| INTEL - Ia32/InterlockedIncrement.asm | INTEL Synchronization.c | INTEL Ia32/InternalGetSpinLockProperties.c | GCC @@ -59,40 +50,20 @@ X64/InterlockedCompareExchange64.c | MSFT X64/InterlockedCompareExchange32.c | MSFT X64/InterlockedCompareExchange16.c | MSFT - + InterlockedIncrementMsc.c | MSFT + InterlockedDecrementMsc.c | MSFT + SynchronizationMsc.c | MSFT + X64/InterlockedCompareExchange64.nasm| INTEL - X64/InterlockedCompareExchange64.asm | INTEL X64/InterlockedCompareExchange32.nasm| INTEL - X64/InterlockedCompareExchange32.asm | INTEL X64/InterlockedCompareExchange16.nasm| INTEL - X64/InterlockedCompareExchange16.asm | INTEL - - X64/InterlockedDecrement.c | MSFT - X64/InterlockedIncrement.c | MSFT - SynchronizationMsc.c | MSFT - - X64/InterlockedDecrement.nasm| INTEL - X64/InterlockedDecrement.asm | INTEL - X64/InterlockedIncrement.nasm| INTEL - X64/InterlockedIncrement.asm | INTEL - Synchronization.c | INTEL + X64/InterlockedDecrement.nasm | INTEL + X64/InterlockedIncrement.nasm | INTEL + Synchronization.c | INTEL Ia32/InternalGetSpinLockProperties.c | GCC X64/GccInline.c | GCC - SynchronizationGcc.c | GCC - -[Sources.IPF] - Ipf/Synchronization.c - Ipf/InterlockedCompareExchange64.s - Ipf/InterlockedCompareExchange32.s - Ipf/InterlockedCompareExchange16.s - - Ipf/InternalGetSpinLockProperties.c | MSFT - Ipf/InternalGetSpinLockProperties.c | GCC - - Synchronization.c | INTEL - SynchronizationMsc.c | MSFT - SynchronizationGcc.c | GCC + SynchronizationGcc.c | GCC [Sources.EBC] Synchronization.c @@ -105,7 +76,12 @@ [Sources.AARCH64] Synchronization.c - AArch64/Synchronization.S + AArch64/Synchronization.S | GCC + AArch64/Synchronization.asm | MSFT + +[Sources.RISCV64] + Synchronization.c + RiscV64/Synchronization.S [Packages] MdePkg/MdePkg.dec diff --git a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.uni b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.uni index e12e05f76a7a..69ba795d4deb 100644 --- a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.uni +++ b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.uni @@ -6,12 +6,7 @@ // Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR> // Portions copyright (c) 2008 - 2009, Apple Inc. 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. +// SPDX-License-Identifier: BSD-2-Clause-Patent // // **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLibInternals.h b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLibInternals.h index 74625e036d6c..c24701e6bf77 100644 --- a/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLibInternals.h +++ b/MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLibInternals.h @@ -1,14 +1,8 @@ /** @file Declaration of internal functions in BaseSynchronizationLib. - Copyright (c) 2006 - 2016, Intel Corporation. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -27,8 +21,7 @@ Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to increment. @@ -47,8 +40,7 @@ InternalSyncIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decrement value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to decrement. @@ -143,7 +135,7 @@ InternalSyncCompareExchange64 ( requirements for optimal spin lock performance. @return The architecture specific spin lock alignment. - + **/ UINTN InternalGetSpinLockProperties ( diff --git a/MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c b/MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c index 54d2eebefd7b..0c8e4f506b34 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c +++ b/MdePkg/Library/BaseSynchronizationLib/Ebc/Synchronization.c @@ -1,14 +1,8 @@ /** @file Implementation of synchronization functions on EBC. - Copyright (c) 2006 - 2010, Intel Corporation. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -77,9 +71,9 @@ InternalSyncCompareExchange32 ( /** Performs an atomic compare exchange operation on a 64-bit unsigned integer. - Performs an atomic compare exchange operation on the 64-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. + Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c index d1003ab53886..7c9f16738859 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c @@ -1,15 +1,9 @@ /** @file GCC inline implementation of BaseSynchronizationLib processor specific functions. - - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> - Portions copyright (c) 2008 - 2009, Apple Inc. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -20,8 +14,7 @@ Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to increment. @@ -37,18 +30,18 @@ InternalSyncIncrement ( UINT32 Result; __asm__ __volatile__ ( + "movl $1, %%eax \n\t" "lock \n\t" - "incl %2 \n\t" - "movl %2, %%eax " - : "=a" (Result), // %0 - "=m" (*Value) // %1 - : "m" (*Value) // %2 + "xadd %%eax, %1 \n\t" + "inc %%eax \n\t" + : "=&a" (Result), // %0 + "+m" (*Value) // %1 + : // no inputs that aren't also outputs : "memory", "cc" ); - - return Result; + return Result; } @@ -57,8 +50,7 @@ InternalSyncIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to decrement. @@ -72,21 +64,23 @@ InternalSyncDecrement ( ) { UINT32 Result; - + __asm__ __volatile__ ( - "lock \n\t" - "decl %2 \n\t" - "movl %2, %%eax " - : "=a" (Result), // %0 - "=m" (*Value) // %1 - : "m" (*Value) // %2 + "movl $-1, %%eax \n\t" + "lock \n\t" + "xadd %%eax, %1 \n\t" + "dec %%eax \n\t" + : "=&a" (Result), // %0 + "+m" (*Value) // %1 + : // no inputs that aren't also outputs : "memory", "cc" ); - + return Result; } + /** Performs an atomic compare exchange operation on a 16-bit unsigned integer. @@ -113,15 +107,12 @@ InternalSyncCompareExchange16 ( IN UINT16 ExchangeValue ) { - __asm__ __volatile__ ( - " \n\t" "lock \n\t" - "cmpxchgw %1, %2 \n\t" - : "=a" (CompareValue) - : "q" (ExchangeValue), - "m" (*Value), - "0" (CompareValue) + "cmpxchgw %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "q" (ExchangeValue) // %2 : "memory", "cc" ); @@ -129,6 +120,7 @@ InternalSyncCompareExchange16 ( return CompareValue; } + /** Performs an atomic compare exchange operation on a 32-bit unsigned integer. @@ -155,15 +147,12 @@ InternalSyncCompareExchange32 ( IN UINT32 ExchangeValue ) { - __asm__ __volatile__ ( - " \n\t" "lock \n\t" - "cmpxchgl %1, %2 \n\t" - : "=a" (CompareValue) // %0 - : "q" (ExchangeValue), // %1 - "m" (*Value), // %2 - "0" (CompareValue) // %4 + "cmpxchgl %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "q" (ExchangeValue) // %2 : "memory", "cc" ); @@ -171,6 +160,7 @@ InternalSyncCompareExchange32 ( return CompareValue; } + /** Performs an atomic compare exchange operation on a 64-bit unsigned integer. @@ -197,19 +187,15 @@ InternalSyncCompareExchange64 ( ) { __asm__ __volatile__ ( - " \n\t" - "push %%ebx \n\t" - "movl %2,%%ebx \n\t" "lock \n\t" "cmpxchg8b (%1) \n\t" - "pop %%ebx \n\t" : "+A" (CompareValue) // %0 : "S" (Value), // %1 - "r" ((UINT32) ExchangeValue), // %2 + "b" ((UINT32) ExchangeValue), // %2 "c" ((UINT32) (ExchangeValue >> 32)) // %3 : "memory", "cc" ); - + return CompareValue; } diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.asm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.asm deleted file mode 100644 index 688d467f9c32..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.asm +++ /dev/null @@ -1,46 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, 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 volatile 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 diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c index 81a890ad9d2b..6680a551f109 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.c @@ -3,13 +3,7 @@ Copyright (c) 2006 - 2016, 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.nasm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.nasm index 5beeede74f88..487b6cbab2c4 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange16.nasm @@ -2,13 +2,7 @@ ; ; Copyright (c) 2006 - 2016, 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.asm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.asm deleted file mode 100644 index 97cc56cf34b9..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.asm +++ /dev/null @@ -1,45 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedCompareExchange32.Asm -; -; Abstract: -; -; InterlockedCompareExchange32 function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .486 - .model flat,C - .code - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncCompareExchange32 ( -; IN volatile UINT32 *Value, -; IN UINT32 CompareValue, -; IN UINT32 ExchangeValue -; ); -;------------------------------------------------------------------------------ -InternalSyncCompareExchange32 PROC - mov ecx, [esp + 4] - mov eax, [esp + 8] - mov edx, [esp + 12] - lock cmpxchg [ecx], edx - ret -InternalSyncCompareExchange32 ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.c index 3dd737bf6784..21b02095bcdb 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.c +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.c @@ -2,13 +2,7 @@ InterlockedCompareExchange32 function Copyright (c) 2006 - 2016, Intel Corporation. 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.nasm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.nasm index 62cbb11502ca..945bdce69fe0 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange32.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.asm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.asm deleted file mode 100644 index d7faaf20f614..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.asm +++ /dev/null @@ -1,47 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedCompareExchange64.Asm -; -; Abstract: -; -; InterlockedCompareExchange64 function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .586P - .model flat,C - .code - -;------------------------------------------------------------------------------ -; UINT64 -; EFIAPI -; InternalSyncCompareExchange64 ( -; IN volatile UINT64 *Value, -; IN UINT64 CompareValue, -; IN UINT64 ExchangeValue -; ); -;------------------------------------------------------------------------------ -InternalSyncCompareExchange64 PROC USES esi ebx - mov esi, [esp + 12] - mov eax, [esp + 16] - mov edx, [esp + 20] - mov ebx, [esp + 24] - mov ecx, [esp + 28] - lock cmpxchg8b qword ptr [esi] - ret -InternalSyncCompareExchange64 ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.c index 68c527434135..9c0572ce31e7 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.c +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.c @@ -2,13 +2,7 @@ InterlockedCompareExchange64 function Copyright (c) 2006 - 2016, Intel Corporation. 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.nasm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.nasm index c55d55c3ef22..44e8b5e27acf 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedCompareExchange64.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.asm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.asm deleted file mode 100644 index e86375eb2cb2..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.asm +++ /dev/null @@ -1,42 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedDecrement.Asm -; -; Abstract: -; -; InterlockedDecrement function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .386 - .model flat,C - .code - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncDecrement ( -; IN volatile UINT32 *Value -; ); -;------------------------------------------------------------------------------ -InternalSyncDecrement PROC - mov eax, [esp + 4] - lock dec dword ptr [eax] - mov eax, [eax] - ret -InternalSyncDecrement ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.c deleted file mode 100644 index 5bb3371916b2..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.c +++ /dev/null @@ -1,42 +0,0 @@ -/** @file - InterlockedDecrement function - - Copyright (c) 2006 - 2016, Intel Corporation. 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 decrement of an 32-bit unsigned integer. - - Performs an atomic decrement of the 32-bit unsigned integer specified by - Value and returns the decrement value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. - - @param Value A pointer to the 32-bit value to decrement. - - @return The decrement value. - -**/ -UINT32 -EFIAPI -InternalSyncDecrement ( - IN volatile UINT32 *Value - ) -{ - _asm { - mov eax, Value - lock dec dword ptr [eax] - mov eax, [eax] - } -} diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.nasm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.nasm index 951f207bd7b4..21d81e5aff8c 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedDecrement.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; -; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; @@ -32,8 +26,8 @@ ;------------------------------------------------------------------------------ global ASM_PFX(InternalSyncDecrement) ASM_PFX(InternalSyncDecrement): - mov eax, [esp + 4] - lock dec dword [eax] - mov eax, [eax] + mov ecx, [esp + 4] + mov eax, 0FFFFFFFFh + lock xadd dword [ecx], eax + dec eax ret - diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.asm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.asm deleted file mode 100644 index 0a0b3905ff92..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.asm +++ /dev/null @@ -1,42 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedIncrement.Asm -; -; Abstract: -; -; InterlockedIncrement function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .386 - .model flat,C - .code - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncIncrement ( -; IN volatile UINT32 *Value -; ); -;------------------------------------------------------------------------------ -InternalSyncIncrement PROC - mov eax, [esp + 4] - lock inc dword ptr [eax] - mov eax, [eax] - ret -InternalSyncIncrement ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.c deleted file mode 100644 index 789082a1a562..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.c +++ /dev/null @@ -1,43 +0,0 @@ -/** @file - InterLockedIncrement function - - Copyright (c) 2006 - 2016, Intel Corporation. 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 increment of an 32-bit unsigned integer. - - Performs an atomic increment of the 32-bit unsigned integer specified by - Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. - - @param Value A pointer to the 32-bit value to increment. - - @return The incremented value. - -**/ -UINT32 -EFIAPI -InternalSyncIncrement ( - IN volatile UINT32 *Value - ) -{ - _asm { - mov eax, Value - lock inc dword ptr [eax] - mov eax, [eax] - } -} - diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.nasm b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.nasm index 78e444ad02c3..d441915310a1 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InterlockedIncrement.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; @@ -32,8 +26,9 @@ ;------------------------------------------------------------------------------ global ASM_PFX(InternalSyncIncrement) ASM_PFX(InternalSyncIncrement): - mov eax, [esp + 4] - lock inc dword [eax] - mov eax, [eax] + mov ecx, [esp + 4] + mov eax, 1 + lock xadd dword [ecx], eax + inc eax ret diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c index ea3cd38f3e38..7b0de3dc5f31 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c +++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/InternalGetSpinLockProperties.c @@ -1,14 +1,8 @@ /** @file Internal function to get spin lock alignment. - Copyright (c) 2016, Intel Corporation. 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. + Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -19,7 +13,7 @@ requirements for optimal spin lock performance. @return The architecture specific spin lock alignment. - + **/ UINTN InternalGetSpinLockProperties ( @@ -48,7 +42,7 @@ InternalGetSpinLockProperties ( if (FamilyId == 0x0f) { // // In processors based on Intel NetBurst microarchitecture, use two cache lines - // + // ModelId = ModelId | ((RegEax >> 12) & 0xf0); if (ModelId <= 0x04 || ModelId == 0x06) { CacheLineSize *= 2; diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.c b/MdePkg/Library/BaseSynchronizationLib/InterlockedDecrementMsc.c index af0193cb6321..eef8783ca82f 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.c +++ b/MdePkg/Library/BaseSynchronizationLib/InterlockedDecrementMsc.c @@ -1,14 +1,8 @@ /** @file InterlockedDecrement function - Copyright (c) 2006 - 2016, Intel Corporation. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -41,6 +35,6 @@ InternalSyncDecrement ( IN volatile UINT32 *Value ) { - return _InterlockedDecrement ((long *)(UINTN)(Value)); + return _InterlockedDecrement ((long *)(Value)); } diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.c b/MdePkg/Library/BaseSynchronizationLib/InterlockedIncrementMsc.c index 2a3498a585ab..ebd9349cca90 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.c +++ b/MdePkg/Library/BaseSynchronizationLib/InterlockedIncrementMsc.c @@ -1,14 +1,8 @@ /** @file InterLockedIncrement function - Copyright (c) 2006 - 2016, Intel Corporation. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -41,6 +35,6 @@ InternalSyncIncrement ( IN volatile UINT32 *Value ) { - return _InterlockedIncrement ((long *)(UINTN)(Value)); + return _InterlockedIncrement ((long *)(Value)); } diff --git a/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange16.s b/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange16.s deleted file mode 100644 index 1e56942a98cb..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange16.s +++ /dev/null @@ -1,30 +0,0 @@ -/// @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 diff --git a/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange32.s b/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange32.s deleted file mode 100644 index ddcf036162f6..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange32.s +++ /dev/null @@ -1,29 +0,0 @@ -/// @file -/// Contains an implementation of InterlockedCompareExchange32 on Itanium- -/// based architecture. -/// -/// Copyright (c) 2006 - 2008, Intel Corporation. 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: InterlockedCompareExchange32.s -/// -/// - -.auto -.text - -.proc InternalSyncCompareExchange32 -.type InternalSyncCompareExchange32, @function -InternalSyncCompareExchange32:: - zxt4 r33 = r33 - mov ar.ccv = r33 - cmpxchg4.rel r8 = [r32], r34 - mf - br.ret.sptk.many b0 -.endp InternalSyncCompareExchange32 diff --git a/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange64.s b/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange64.s deleted file mode 100644 index d25372809cb1..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ipf/InterlockedCompareExchange64.s +++ /dev/null @@ -1,28 +0,0 @@ -/// @file -/// Contains an implementation of InterlockedCompareExchange64 on Itanium- -/// based architecture. -/// -/// Copyright (c) 2006 - 2008, Intel Corporation. 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: InterlockedCompareExchange64.s -/// -/// - -.auto -.text - -.proc InternalSyncCompareExchange64 -.type InternalSyncCompareExchange64, @function -InternalSyncCompareExchange64:: - mov ar.ccv = r33 - cmpxchg8.rel r8 = [r32], r34 - mf - br.ret.sptk.many b0 -.endp InternalSyncCompareExchange64 diff --git a/MdePkg/Library/BaseSynchronizationLib/Ipf/InternalGetSpinLockProperties.c b/MdePkg/Library/BaseSynchronizationLib/Ipf/InternalGetSpinLockProperties.c deleted file mode 100644 index d75114bf46d4..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ipf/InternalGetSpinLockProperties.c +++ /dev/null @@ -1,29 +0,0 @@ -/** @file - Internal function to get spin lock alignment. - - Copyright (c) 2016, Intel Corporation. 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. - -**/ - -/** - Internal function to retrieve the architecture specific spin lock alignment - requirements for optimal spin lock performance. - - @return The architecture specific spin lock alignment. - -**/ -UINTN -InternalGetSpinLockProperties ( - VOID - ) -{ - return 32; -} - diff --git a/MdePkg/Library/BaseSynchronizationLib/Ipf/Synchronization.c b/MdePkg/Library/BaseSynchronizationLib/Ipf/Synchronization.c deleted file mode 100644 index 72b07b2d4e1d..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/Ipf/Synchronization.c +++ /dev/null @@ -1,77 +0,0 @@ -/** @file - Implementation of synchronization functions on Itanium. - - Copyright (c) 2006 - 2010, Intel Corporation. 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. - -**/ - -#include "BaseSynchronizationLibInternals.h" - -/** - Performs an atomic increment of an 32-bit unsigned integer. - - Performs an atomic increment of the 32-bit unsigned integer specified by - Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. - - @param Value A pointer to the 32-bit value to increment. - - @return The incremented value. - -**/ -UINT32 -EFIAPI -InternalSyncIncrement ( - IN volatile UINT32 *Value - ) -{ - UINT32 OriginalValue; - - do { - OriginalValue = *Value; - } while (OriginalValue != InternalSyncCompareExchange32 ( - Value, - OriginalValue, - OriginalValue + 1 - )); - return OriginalValue + 1; -} - -/** - Performs an atomic decrement of an 32-bit unsigned integer. - - Performs an atomic decrement of the 32-bit unsigned integer specified by - Value and returns the decrement value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. - - @param Value A pointer to the 32-bit value to decrement. - - @return The decrement value. - -**/ -UINT32 -EFIAPI -InternalSyncDecrement ( - IN volatile UINT32 *Value - ) -{ - UINT32 OriginalValue; - - do { - OriginalValue = *Value; - } while (OriginalValue != InternalSyncCompareExchange32 ( - Value, - OriginalValue, - OriginalValue - 1 - )); - return OriginalValue - 1; -} diff --git a/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S b/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S new file mode 100644 index 000000000000..116b7d073603 --- /dev/null +++ b/MdePkg/Library/BaseSynchronizationLib/RiscV64/Synchronization.S @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// +// RISC-V synchronization functions. +// +// Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR> +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//------------------------------------------------------------------------------ +#include <Base.h> + +.data + +.text +.align 3 + +.global ASM_PFX(InternalSyncCompareExchange32) +.global ASM_PFX(InternalSyncCompareExchange64) +.global ASM_PFX(InternalSyncIncrement) +.global ASM_PFX(InternalSyncDecrement) + +// +// ompare and xchange a 32-bit value. +// +// @param a0 : Pointer to 32-bit value. +// @param a1 : Compare value. +// @param a2 : Exchange value. +// +ASM_PFX (InternalSyncCompareExchange32): + lr.w a3, (a0) // Load the value from a0 and make + // the reservation of address. + bne a3, a1, exit + sc.w a3, a2, (a0) // Write the value back to the address. + mv a3, a1 +exit: + mv a0, a3 + ret + +.global ASM_PFX(InternalSyncCompareExchange64) + +// +// Compare and xchange a 64-bit value. +// +// @param a0 : Pointer to 64-bit value. +// @param a1 : Compare value. +// @param a2 : Exchange value. +// +ASM_PFX (SyncCompareExchange64): + lr.d a3, (a0) // Load the value from a0 and make + // the reservation of address. + bne a3, a1, exit + sc.d a3, a2, (a0) // Write the value back to the address. + mv a3, a1 +exit2: + mv a0, a3 + ret + +// +// Performs an atomic increment of an 32-bit unsigned integer. +// +// @param a0 : Pointer to 32-bit value. +// +ASM_PFX (InternalSyncIncrement): + li a1, 1 + amoadd.w a2, a1, (a0) + mv a0, a2 + ret + +// +// Performs an atomic decrement of an 32-bit unsigned integer. +// +// @param a0 : Pointer to 32-bit value. +// +ASM_PFX (InternalSyncDecrement): + li a1, -1 + amoadd.w a2, a1, (a0) + mv a0, a2 + ret diff --git a/MdePkg/Library/BaseSynchronizationLib/Synchronization.c b/MdePkg/Library/BaseSynchronizationLib/Synchronization.c index 5b020b33f7de..8ea2843c7f8d 100644 --- a/MdePkg/Library/BaseSynchronizationLib/Synchronization.c +++ b/MdePkg/Library/BaseSynchronizationLib/Synchronization.c @@ -1,14 +1,8 @@ /** @file Implementation of synchronization functions. - Copyright (c) 2006 - 2016, Intel Corporation. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -22,7 +16,7 @@ optimal spin lock performance. This function retrieves the spin lock alignment requirements for optimal - performance on a given CPU architecture. The spin lock alignment is byte alignment. + performance on a given CPU architecture. The spin lock alignment is byte alignment. It must be a power of two and is returned by this function. If there are no alignment requirements, then 1 must be returned. The spin lock synchronization functions must function correctly if the spin lock size and alignment values @@ -231,8 +225,7 @@ ReleaseSpinLock ( Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). @@ -256,8 +249,7 @@ InterlockedIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c index 009341a9b02d..5ea87c17bdaf 100644 --- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c +++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationGcc.c @@ -1,22 +1,16 @@ /** @file Implementation of synchronization functions. - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> Portions copyright (c) 2008 - 2009, Apple Inc. 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "BaseSynchronizationLibInternals.h" // -// GCC inline assembly for Read Write Barrier +// GCC inline assembly for Read Write Barrier // #define _ReadWriteBarrier() do { __asm__ __volatile__ ("": : : "memory"); } while(0) @@ -28,7 +22,7 @@ optimal spin lock performance. This function retrieves the spin lock alignment requirements for optimal - performance on a given CPU architecture. The spin lock alignment is byte alignment. + performance on a given CPU architecture. The spin lock alignment is byte alignment. It must be a power of two and is returned by this function. If there are no alignment requirements, then 1 must be returned. The spin lock synchronization functions must function correctly if the spin lock size and alignment values @@ -191,7 +185,7 @@ AcquireSpinLockOrFail ( { SPIN_LOCK LockValue; VOID *Result; - + ASSERT (SpinLock != NULL); LockValue = *SpinLock; @@ -247,8 +241,7 @@ ReleaseSpinLock ( Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). @@ -272,8 +265,7 @@ InterlockedIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). diff --git a/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c b/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c index c9ecdf6f483c..3e136576f0c2 100644 --- a/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c +++ b/MdePkg/Library/BaseSynchronizationLib/SynchronizationMsc.c @@ -1,14 +1,8 @@ /** @file Implementation of synchronization functions. - Copyright (c) 2006 - 2016, Intel Corporation. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -30,7 +24,7 @@ void _ReadWriteBarrier (void); optimal spin lock performance. This function retrieves the spin lock alignment requirements for optimal - performance on a given CPU architecture. The spin lock alignment is byte alignment. + performance on a given CPU architecture. The spin lock alignment is byte alignment. It must be a power of two and is returned by this function. If there are no alignment requirements, then 1 must be returned. The spin lock synchronization functions must function correctly if the spin lock size and alignment values @@ -193,7 +187,7 @@ AcquireSpinLockOrFail ( { SPIN_LOCK LockValue; VOID *Result; - + ASSERT (SpinLock != NULL); LockValue = *SpinLock; @@ -249,8 +243,7 @@ ReleaseSpinLock ( Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). @@ -274,8 +267,7 @@ InterlockedIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. If Value is NULL, then ASSERT(). diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c b/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c index 5b1635a98043..ee9d6a4a32fc 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c +++ b/MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c @@ -1,28 +1,20 @@ /** @file GCC inline implementation of BaseSynchronizationLib processor specific functions. - - Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> - Portions copyright (c) 2008 - 2009, Apple Inc. 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. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> + Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ - /** Performs an atomic increment of an 32-bit unsigned integer. Performs an atomic increment of the 32-bit unsigned integer specified by Value and returns the incremented value. The increment operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to increment. @@ -38,17 +30,18 @@ InternalSyncIncrement ( UINT32 Result; __asm__ __volatile__ ( + "movl $1, %%eax \n\t" "lock \n\t" - "incl %2 \n\t" - "mov %2, %%eax " - : "=a" (Result), // %0 - "=m" (*Value) // %1 - : "m" (*Value) // %2 + "xadd %%eax, %1 \n\t" + "inc %%eax \n\t" + : "=&a" (Result), // %0 + "+m" (*Value) // %1 + : // no inputs that aren't also outputs : "memory", "cc" ); - - return Result; + + return Result; } @@ -57,8 +50,7 @@ InternalSyncIncrement ( Performs an atomic decrement of the 32-bit unsigned integer specified by Value and returns the decremented value. The decrement operation must be - performed using MP safe mechanisms. The state of the return value is not - guaranteed to be MP safe. + performed using MP safe mechanisms. @param Value A pointer to the 32-bit value to decrement. @@ -72,18 +64,19 @@ InternalSyncDecrement ( ) { UINT32 Result; - + __asm__ __volatile__ ( - "lock \n\t" - "decl %2 \n\t" - "mov %2, %%eax " - : "=a" (Result), // %0 - "=m" (*Value) // %1 - : "m" (*Value) // %2 + "movl $-1, %%eax \n\t" + "lock \n\t" + "xadd %%eax, %1 \n\t" + "dec %%eax \n\t" + : "=&a" (Result), // %0 + "+m" (*Value) // %1 + : // no inputs that aren't also outputs : "memory", "cc" ); - + return Result; } @@ -114,16 +107,12 @@ InternalSyncCompareExchange16 ( IN UINT16 ExchangeValue ) { - - __asm__ __volatile__ ( "lock \n\t" - "cmpxchgw %3, %1 " - : "=a" (CompareValue), - "=m" (*Value) - : "a" (CompareValue), - "r" (ExchangeValue), - "m" (*Value) + "cmpxchgw %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "r" (ExchangeValue) // %2 : "memory", "cc" ); @@ -158,20 +147,16 @@ InternalSyncCompareExchange32 ( IN UINT32 ExchangeValue ) { - - __asm__ __volatile__ ( "lock \n\t" - "cmpxchgl %3, %1 " - : "=a" (CompareValue), // %0 - "=m" (*Value) // %1 - : "a" (CompareValue), // %2 - "r" (ExchangeValue), // %3 - "m" (*Value) + "cmpxchgl %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "r" (ExchangeValue) // %2 : "memory", "cc" ); - + return CompareValue; } @@ -201,20 +186,15 @@ InternalSyncCompareExchange64 ( IN UINT64 ExchangeValue ) { - __asm__ __volatile__ ( "lock \n\t" - "cmpxchgq %3, %1 " - : "=a" (CompareValue), // %0 - "=m" (*Value) // %1 - : "a" (CompareValue), // %2 - "r" (ExchangeValue), // %3 - "m" (*Value) + "cmpxchgq %2, %1 \n\t" + : "+a" (CompareValue), // %0 + "+m" (*Value) // %1 + : "r" (ExchangeValue) // %2 : "memory", "cc" ); - + return CompareValue; } - - diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.asm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.asm deleted file mode 100644 index 219527d585c1..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.asm +++ /dev/null @@ -1,42 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, 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 -; InternalSyncCompareExchange16 ( -; IN volatile UINT16 *Value, -; IN UINT16 CompareValue, -; IN UINT16 ExchangeValue -; ); -;------------------------------------------------------------------------------ -InternalSyncCompareExchange16 PROC - mov ax, dx - lock cmpxchg [rcx], r8w - ret -InternalSyncCompareExchange16 ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.c b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.c index d51d6e361061..ab8e5031fadd 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.c +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.c @@ -3,13 +3,7 @@ Copyright (c) 2006 - 2016, 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.nasm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.nasm index b9ef3d4f9def..6c00f62ca9f1 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange16.nasm @@ -2,13 +2,7 @@ ; ; Copyright (c) 2006 - 2016, 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.asm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.asm deleted file mode 100644 index 86a3c2ad0f93..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.asm +++ /dev/null @@ -1,41 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedCompareExchange32.Asm -; -; Abstract: -; -; InterlockedCompareExchange32 function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .code - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncCompareExchange32 ( -; IN volatile UINT32 *Value, -; IN UINT32 CompareValue, -; IN UINT32 ExchangeValue -; ); -;------------------------------------------------------------------------------ -InternalSyncCompareExchange32 PROC - mov eax, edx - lock cmpxchg [rcx], r8d - ret -InternalSyncCompareExchange32 ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.c b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.c index b275d679c055..0b7212cabe40 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.c +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.c @@ -2,13 +2,7 @@ InterlockedCompareExchange32 function Copyright (c) 2006 - 2016, Intel Corporation. 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.nasm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.nasm index e199ef95fe8c..b659fa6fdfd1 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange32.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.asm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.asm deleted file mode 100644 index e3a85d6fa76f..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.asm +++ /dev/null @@ -1,41 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedCompareExchange64.Asm -; -; Abstract: -; -; InterlockedCompareExchange64 function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .code - -;------------------------------------------------------------------------------ -; UINT64 -; EFIAPI -; InternalSyncCompareExchange64 ( -; IN volatile UINT64 *Value, -; IN UINT64 CompareValue, -; IN UINT64 ExchangeValue -; ); -;------------------------------------------------------------------------------ -InternalSyncCompareExchange64 PROC - mov rax, rdx - lock cmpxchg [rcx], r8 - ret -InternalSyncCompareExchange64 ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.c b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.c index c7b6daac9315..f737b63028f5 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.c +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.c @@ -2,13 +2,7 @@ InterlockedCompareExchange64 function Copyright (c) 2006 - 2016, Intel Corporation. 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. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.nasm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.nasm index e78de535d965..91194da2d810 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedCompareExchange64.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.asm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.asm deleted file mode 100644 index 7d6f02c63b0c..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.asm +++ /dev/null @@ -1,39 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedDecrement.Asm -; -; Abstract: -; -; InterlockedDecrement function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .code - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncDecrement ( -; IN volatile UINT32 *Value -; ); -;------------------------------------------------------------------------------ -InternalSyncDecrement PROC - lock dec dword ptr [rcx] - mov eax, [rcx] - ret -InternalSyncDecrement ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.nasm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.nasm index 0325fdf93e90..d36d9b0073b7 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedDecrement.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; -; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; @@ -33,7 +27,7 @@ ;------------------------------------------------------------------------------ global ASM_PFX(InternalSyncDecrement) ASM_PFX(InternalSyncDecrement): - lock dec dword [rcx] - mov eax, [rcx] + mov eax, 0FFFFFFFFh + lock xadd dword [rcx], eax + dec eax ret - diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.asm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.asm deleted file mode 100644 index bbbc95df0c36..000000000000 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.asm +++ /dev/null @@ -1,39 +0,0 @@ -;------------------------------------------------------------------------------ -; -; Copyright (c) 2006 - 2016, Intel Corporation. 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: -; -; InterlockedIncrement.Asm -; -; Abstract: -; -; InterlockedIncrement function -; -; Notes: -; -;------------------------------------------------------------------------------ - - .code - -;------------------------------------------------------------------------------ -; UINT32 -; EFIAPI -; InternalSyncIncrement ( -; IN volatile UINT32 *Value -; ); -;------------------------------------------------------------------------------ -InternalSyncIncrement PROC - lock inc dword ptr [rcx] - mov eax, [rcx] - ret -InternalSyncIncrement ENDP - - END diff --git a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.nasm b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.nasm index c960cb451196..fd046958b9ff 100644 --- a/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.nasm +++ b/MdePkg/Library/BaseSynchronizationLib/X64/InterlockedIncrement.nasm @@ -1,13 +1,7 @@ ;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, Intel Corporation. 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. +; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; @@ -33,7 +27,8 @@ ;------------------------------------------------------------------------------ global ASM_PFX(InternalSyncIncrement) ASM_PFX(InternalSyncIncrement): - lock inc dword [rcx] - mov eax, [rcx] + mov eax, 1 + lock xadd dword [rcx], eax + inc eax ret |