]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BaseSynchronizationLib: Added proper support for ARM architecture
authorOlivier Martin <olivier.martin@arm.com>
Sat, 28 Feb 2015 20:31:40 +0000 (20:31 +0000)
committerlersek <lersek@Edk2>
Sat, 28 Feb 2015 20:31:40 +0000 (20:31 +0000)
This implements the following synchronization primitives for AArch64 (GCC)
and ARM (GCC & RVCT):

InternalSyncCompareExchange32
InternalSyncCompareExchange64
InternalSyncIncrement
InternalSyncDecrement

Note: these functions are implemented using the exclusive monitor,
which implies that they can only be used after the caches (and hence
the MMU) have been enabled.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16965 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.c [deleted file]
MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm [new file with mode: 0644]
MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.c [deleted file]
MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf [changed mode: 0644->0755]

diff --git a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S
new file mode 100644 (file)
index 0000000..601b004
--- /dev/null
@@ -0,0 +1,159 @@
+//  Implementation of synchronization functions for ARM architecture (AArch64)\r
+//\r
+//  Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2015, Linaro Limited. All rights reserved.\r
+//\r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+.text\r
+.align 3\r
+\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 32-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  32-bit value used in compare operation.\r
+  @param  ExchangeValue 32-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncCompareExchange32 (\r
+//  IN      volatile UINT32           *Value,\r
+//  IN      UINT32                    CompareValue,\r
+//  IN      UINT32                    ExchangeValue\r
+//  )\r
+ASM_PFX(InternalSyncCompareExchange32):\r
+  dmb     sy\r
+\r
+InternalSyncCompareExchange32Again:\r
+  ldxr    w3, [x0]\r
+  cmp     w3, w1\r
+  bne     InternalSyncCompareExchange32Fail\r
+\r
+InternalSyncCompareExchange32Exchange:\r
+  stxr    w4, w2, [x0]\r
+  cbnz    w4, InternalSyncCompareExchange32Again\r
+\r
+InternalSyncCompareExchange32Fail:\r
+  dmb     sy\r
+  mov     w0, w3\r
+  ret\r
+\r
+/**\r
+  Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  64-bit value used in compare operation.\r
+  @param  ExchangeValue 64-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT64\r
+//EFIAPI\r
+//InternalSyncCompareExchange64 (\r
+//  IN      volatile UINT64           *Value,\r
+//  IN      UINT64                    CompareValue,\r
+//  IN      UINT64                    ExchangeValue\r
+//  )\r
+ASM_PFX(InternalSyncCompareExchange64):\r
+  dmb     sy\r
+\r
+InternalSyncCompareExchange64Again:\r
+  ldxr    x3, [x0]\r
+  cmp     x3, x1\r
+  bne     InternalSyncCompareExchange64Fail\r
+\r
+InternalSyncCompareExchange64Exchange:\r
+  stxr    w4, x2, [x0]\r
+  cbnz    w4, InternalSyncCompareExchange64Again\r
+\r
+InternalSyncCompareExchange64Fail:\r
+  dmb     sy\r
+  mov     x0, x3\r
+  ret\r
+\r
+/**\r
+  Performs an atomic increment of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic increment of the 32-bit unsigned integer specified by\r
+  Value and returns the incremented value. The increment operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to increment.\r
+\r
+  @return The incremented value.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncIncrement (\r
+//  IN      volatile UINT32           *Value\r
+//  )\r
+ASM_PFX(InternalSyncIncrement):\r
+  dmb     sy\r
+TryInternalSyncIncrement:\r
+  ldxr    w1, [x0]\r
+  add     w1, w1, #1\r
+  stxr    w2, w1, [x0]\r
+  cbnz    w2, TryInternalSyncIncrement\r
+  dmb     sy\r
+  ret\r
+\r
+/**\r
+  Performs an atomic decrement of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
+  Value and returns the decrement value. The decrement operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to decrement.\r
+\r
+  @return The decrement value.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncDecrement (\r
+//  IN      volatile UINT32           *Value\r
+//  )\r
+ASM_PFX(InternalSyncDecrement):\r
+  dmb     sy\r
+TryInternalSyncDecrement:\r
+  ldxr    w1, [x0]\r
+  sub     w1, w1, #1\r
+  stxr    w2, w1, [x0]\r
+  cbnz    w2, TryInternalSyncDecrement\r
+  dmb     sy\r
+  ret\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.c b/MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.c
deleted file mode 100644 (file)
index 2e619cc..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/** @file\r
-  Implementation of synchronization functions. Still needs to be ported\r
-\r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-  Portions copyright (c) 2008 - 2009, Apple Inc. 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
-  Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
-\r
-  Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r
-                        operation.\r
-  @param  CompareValue  32-bit value used in compare operation.\r
-  @param  ExchangeValue 32-bit value used in exchange operation.\r
-\r
-  @return The original *Value before exchange.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncCompareExchange32 (\r
-  IN      volatile UINT32           *Value,\r
-  IN      UINT32                    CompareValue,\r
-  IN      UINT32                    ExchangeValue\r
-  )\r
-{\r
-  return *Value != CompareValue ? *Value :\r
-           ((*Value = ExchangeValue), CompareValue);\r
-}\r
-\r
-/**\r
-  Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
-\r
-  Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange\r
-                        operation.\r
-  @param  CompareValue  64-bit value used in compare operation.\r
-  @param  ExchangeValue 64-bit value used in exchange operation.\r
-\r
-  @return The original *Value before exchange.\r
-\r
-**/\r
-UINT64\r
-EFIAPI\r
-InternalSyncCompareExchange64 (\r
-  IN      volatile UINT64           *Value,\r
-  IN      UINT64                    CompareValue,\r
-  IN      UINT64                    ExchangeValue\r
-  )\r
-{\r
-  return *Value != CompareValue ? *Value :\r
-           ((*Value = ExchangeValue), CompareValue);\r
-}\r
-\r
-/**\r
-  Performs an atomic increment of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic increment of the 32-bit unsigned integer specified by\r
-  Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to increment.\r
-\r
-  @return The incremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncIncrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  return ++*Value;\r
-}\r
-\r
-/**\r
-  Performs an atomic decrement of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
-  Value and returns the decrement value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to decrement.\r
-\r
-  @return The decrement value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncDecrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  return --*Value;\r
-}\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S
new file mode 100644 (file)
index 0000000..0128f8f
--- /dev/null
@@ -0,0 +1,167 @@
+//  Implementation of synchronization functions for ARM architecture\r
+//\r
+//  Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r
+//\r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+.text\r
+.align 3\r
+\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 32-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  32-bit value used in compare operation.\r
+  @param  ExchangeValue 32-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncCompareExchange32 (\r
+//  IN      volatile UINT32           *Value,\r
+//  IN      UINT32                    CompareValue,\r
+//  IN      UINT32                    ExchangeValue\r
+//  )\r
+ASM_PFX(InternalSyncCompareExchange32):\r
+  dmb\r
+\r
+InternalSyncCompareExchange32Again:\r
+  ldrex   r3, [r0]\r
+  cmp     r3, r1\r
+  bne     InternalSyncCompareExchange32Fail\r
+\r
+InternalSyncCompareExchange32Exchange:\r
+  strex   ip, r2, [r0]\r
+  cmp     ip, #0\r
+  bne     InternalSyncCompareExchange32Again\r
+\r
+InternalSyncCompareExchange32Fail:\r
+  dmb\r
+  mov     r0, r3\r
+  bx      lr\r
+\r
+/**\r
+  Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  64-bit value used in compare operation.\r
+  @param  ExchangeValue 64-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT64\r
+//EFIAPI\r
+//InternalSyncCompareExchange64 (\r
+//  IN      volatile UINT64           *Value,         // r0\r
+//  IN      UINT64                    CompareValue,   // r2-r3\r
+//  IN      UINT64                    ExchangeValue   // stack\r
+//  )\r
+ASM_PFX(InternalSyncCompareExchange64):\r
+  push    { r4-r7 }\r
+  ldrd    r4, r5, [sp, #16]\r
+  dmb\r
+\r
+InternalSyncCompareExchange64Again:\r
+  ldrexd  r6, r7, [r0]\r
+  cmp     r6, r2\r
+  cmpeq   r7, r3\r
+  bne     InternalSyncCompareExchange64Fail\r
+\r
+InternalSyncCompareExchange64Exchange:\r
+  strexd  ip, r4, r5, [r0]\r
+  cmp     ip, #0\r
+  bne     InternalSyncCompareExchange64Again\r
+\r
+InternalSyncCompareExchange64Fail:\r
+  dmb\r
+  mov     r0, r6\r
+  mov     r1, r7\r
+  pop     { r4-r7 }\r
+  bx      lr\r
+\r
+/**\r
+  Performs an atomic increment of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic increment of the 32-bit unsigned integer specified by\r
+  Value and returns the incremented value. The increment operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to increment.\r
+\r
+  @return The incremented value.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncIncrement (\r
+//  IN      volatile UINT32           *Value\r
+//  )\r
+ASM_PFX(InternalSyncIncrement):\r
+  dmb\r
+TryInternalSyncIncrement:\r
+  ldrex   r1, [r0]\r
+  add     r1, r1, #1\r
+  strex   r2, r1, [r0]\r
+  cmp     r2, #0\r
+  bne     TryInternalSyncIncrement\r
+  dmb\r
+  bx      lr\r
+\r
+/**\r
+  Performs an atomic decrement of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
+  Value and returns the decrement value. The decrement operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to decrement.\r
+\r
+  @return The decrement value.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncDecrement (\r
+//  IN      volatile UINT32           *Value\r
+//  )\r
+ASM_PFX(InternalSyncDecrement):\r
+  dmb\r
+TryInternalSyncDecrement:\r
+  ldrex   r1, [r0]\r
+  sub     r1, r1, #1\r
+  strex   r2, r1, [r0]\r
+  cmp     r2, #0\r
+  bne     TryInternalSyncDecrement\r
+  dmb\r
+  bx      lr\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm
new file mode 100644 (file)
index 0000000..f9f8073
--- /dev/null
@@ -0,0 +1,168 @@
+//  Implementation of synchronization functions for ARM architecture\r
+//\r
+//  Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r
+//\r
+//  This program and the accompanying materials\r
+//  are licensed and made available under the terms and conditions of the BSD License\r
+//  which accompanies this distribution.  The full text of the license may be found at\r
+//  http://opensource.org/licenses/bsd-license.php\r
+//\r
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+//\r
+\r
+    EXPORT  InternalSyncCompareExchange32\r
+    EXPORT  InternalSyncCompareExchange64\r
+    EXPORT  InternalSyncIncrement\r
+    EXPORT  InternalSyncDecrement\r
+\r
+    AREA   ArmSynchronization, CODE, READONLY\r
+\r
+/**\r
+  Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  32-bit value used in compare operation.\r
+  @param  ExchangeValue 32-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncCompareExchange32 (\r
+//  IN      volatile UINT32           *Value,\r
+//  IN      UINT32                    CompareValue,\r
+//  IN      UINT32                    ExchangeValue\r
+//  )\r
+InternalSyncCompareExchange32\r
+  dmb\r
+\r
+InternalSyncCompareExchange32Again\r
+  ldrex   r3, [r0]\r
+  cmp     r3, r1\r
+  bne     InternalSyncCompareExchange32Fail\r
+\r
+InternalSyncCompareExchange32Exchange\r
+  strex   ip, r2, [r0]\r
+  cmp     ip, #0\r
+  bne     InternalSyncCompareExchange32Again\r
+\r
+InternalSyncCompareExchange32Fail\r
+  dmb\r
+  mov     r0, r3\r
+  bx      lr\r
+\r
+/**\r
+  Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  64-bit value used in compare operation.\r
+  @param  ExchangeValue 64-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+//UINT64\r
+//EFIAPI\r
+//InternalSyncCompareExchange64 (\r
+//  IN      volatile UINT64           *Value,         // r0\r
+//  IN      UINT64                    CompareValue,   // r2-r3\r
+//  IN      UINT64                    ExchangeValue   // stack\r
+//  )\r
+InternalSyncCompareExchange64\r
+  push    { r4-r7 }\r
+  ldrd    r4, r5, [sp, #16]\r
+  dmb\r
+\r
+InternalSyncCompareExchange64Again\r
+  ldrexd  r6, r7, [r0]\r
+  cmp     r6, r2\r
+  cmpeq   r7, r3\r
+  bne     InternalSyncCompareExchange64Fail\r
+\r
+InternalSyncCompareExchange64Exchange\r
+  strexd  ip, r4, r5, [r0]\r
+  cmp     ip, #0\r
+  bne     InternalSyncCompareExchange64Again\r
+\r
+InternalSyncCompareExchange64Fail\r
+  dmb\r
+  mov     r0, r6\r
+  mov     r1, r7\r
+  pop     { r4-r7 }\r
+  bx      lr\r
+\r
+/**\r
+  Performs an atomic increment of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic increment of the 32-bit unsigned integer specified by\r
+  Value and returns the incremented value. The increment operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to increment.\r
+\r
+  @return The incremented value.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncIncrement (\r
+//  IN      volatile UINT32           *Value\r
+//  )\r
+InternalSyncIncrement\r
+  dmb\r
+TryInternalSyncIncrement\r
+  ldrex   r1, [r0]\r
+  add     r1, r1, #1\r
+  strex   r2, r1, [r0]\r
+  cmp     r2, #0\r
+  bne     TryInternalSyncIncrement\r
+  dmb\r
+  bx      lr\r
+\r
+/**\r
+  Performs an atomic decrement of an 32-bit unsigned integer.\r
+\r
+  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
+  Value and returns the decrement value. The decrement operation must be\r
+  performed using MP safe mechanisms. The state of the return value is not\r
+  guaranteed to be MP safe.\r
+\r
+  @param  Value A pointer to the 32-bit value to decrement.\r
+\r
+  @return The decrement value.\r
+\r
+**/\r
+//UINT32\r
+//EFIAPI\r
+//InternalSyncDecrement (\r
+//  IN      volatile UINT32           *Value\r
+//  )\r
+InternalSyncDecrement\r
+  dmb\r
+TryInternalSyncDecrement\r
+  ldrex   r1, [r0]\r
+  sub     r1, r1, #1\r
+  strex   r2, r1, [r0]\r
+  cmp     r2, #0\r
+  bne     TryInternalSyncDecrement\r
+  dmb\r
+  bx      lr\r
+\r
+  END\r
diff --git a/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.c b/MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.c
deleted file mode 100644 (file)
index 9ddaa09..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/** @file\r
-  Implementation of synchronization functions. Still needs to be ported\r
-\r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-  Portions copyright (c) 2008 - 2009, Apple Inc. 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
-  Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
-\r
-  Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r
-                        operation.\r
-  @param  CompareValue  32-bit value used in compare operation.\r
-  @param  ExchangeValue 32-bit value used in exchange operation.\r
-\r
-  @return The original *Value before exchange.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncCompareExchange32 (\r
-  IN      volatile UINT32           *Value,\r
-  IN      UINT32                    CompareValue,\r
-  IN      UINT32                    ExchangeValue\r
-  )\r
-{\r
-  return *Value != CompareValue ? *Value :\r
-           ((*Value = ExchangeValue), CompareValue);\r
-}\r
-\r
-/**\r
-  Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
-\r
-  Performs an atomic compare exchange operation on the 64-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 64-bit value for the compare exchange\r
-                        operation.\r
-  @param  CompareValue  64-bit value used in compare operation.\r
-  @param  ExchangeValue 64-bit value used in exchange operation.\r
-\r
-  @return The original *Value before exchange.\r
-\r
-**/\r
-UINT64\r
-EFIAPI\r
-InternalSyncCompareExchange64 (\r
-  IN      volatile UINT64           *Value,\r
-  IN      UINT64                    CompareValue,\r
-  IN      UINT64                    ExchangeValue\r
-  )\r
-{\r
-  return *Value != CompareValue ? *Value :\r
-           ((*Value = ExchangeValue), CompareValue);\r
-}\r
-\r
-/**\r
-  Performs an atomic increment of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic increment of the 32-bit unsigned integer specified by\r
-  Value and returns the incremented value. The increment operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to increment.\r
-\r
-  @return The incremented value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncIncrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  return ++*Value;\r
-}\r
-\r
-/**\r
-  Performs an atomic decrement of an 32-bit unsigned integer.\r
-\r
-  Performs an atomic decrement of the 32-bit unsigned integer specified by\r
-  Value and returns the decrement value. The decrement operation must be\r
-  performed using MP safe mechanisms. The state of the return value is not\r
-  guaranteed to be MP safe.\r
-\r
-  @param  Value A pointer to the 32-bit value to decrement.\r
-\r
-  @return The decrement value.\r
-\r
-**/\r
-UINT32\r
-EFIAPI\r
-InternalSyncDecrement (\r
-  IN      volatile UINT32           *Value\r
-  )\r
-{\r
-  return --*Value;\r
-}\r
old mode 100644 (file)
new mode 100755 (executable)
index bf9cf67..5e3b4e6
 \r
 [Sources.ARM]\r
   Synchronization.c\r
-  Arm/Synchronization.c\r
+  Arm/Synchronization.asm       | RVCT\r
+  Arm/Synchronization.S         | GCC\r
 \r
 [Sources.AARCH64]\r
   Synchronization.c\r
-  AArch64/Synchronization.c\r
+  AArch64/Synchronization.S\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r