]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/XenBusDxe: Add InterlockedCompareExchange16.
authorAnthony PERARD <anthony.perard@citrix.com>
Wed, 29 Oct 2014 06:49:55 +0000 (06:49 +0000)
committerjljusten <jljusten@Edk2>
Wed, 29 Oct 2014 06:49:55 +0000 (06:49 +0000)
This patch is inspired by InterlockedCompareExchange32 from the
BaseSynchronizationLib.

The function will be used in the "OvmfPkg/XenBusDxe: Add Grant Table
functions" patch.

Change in V3:
- Implement both .S and .asm, to get rid of GCC specific asm.
- Implement 32bit part of the assembly

Change in V2:
- Add intel compilation code
  MSFT code is not compied over because I don't know how it works.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16263 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.S [new file with mode: 0644]
OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.asm [new file with mode: 0644]
OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c [new file with mode: 0644]
OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h [new file with mode: 0644]
OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.S [new file with mode: 0644]
OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.asm [new file with mode: 0644]
OvmfPkg/XenBusDxe/XenBusDxe.inf

diff --git a/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.S b/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.S
new file mode 100644 (file)
index 0000000..5306448
--- /dev/null
@@ -0,0 +1,15 @@
+# UINT16\r
+# EFIAPI\r
+# InternalSyncCompareExchange16 (\r
+#   IN      volatile UINT16           *Value,\r
+#   IN      UINT16                    CompareValue,\r
+#   IN      UINT16                    ExchangeValue\r
+#   );\r
+ASM_GLOBAL ASM_PFX(InternalSyncCompareExchange16)\r
+ASM_PFX(InternalSyncCompareExchange16):\r
+  mov 4(%esp), %ecx\r
+  mov 8(%esp), %eax\r
+  mov 12(%esp), %edx\r
+  lock\r
+  cmpxchgw %dx, (%ecx)\r
+  ret\r
diff --git a/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.asm b/OvmfPkg/XenBusDxe/Ia32/InterlockedCompareExchange16.asm
new file mode 100644 (file)
index 0000000..adcfbd0
--- /dev/null
@@ -0,0 +1,45 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006, Intel Corporation. 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
+; Module Name:\r
+;\r
+;   InterlockedCompareExchange16.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   InterlockedCompareExchange16 function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    .486\r
+    .model  flat,C\r
+    .code\r
+\r
+;------------------------------------------------------------------------------\r
+; UINT32\r
+; EFIAPI\r
+; InternalSyncCompareExchange16 (\r
+;   IN      UINT16                    *Value,\r
+;   IN      UINT16                    CompareValue,\r
+;   IN      UINT16                    ExchangeValue\r
+;   );\r
+;------------------------------------------------------------------------------\r
+InternalSyncCompareExchange16   PROC\r
+    mov     ecx, [esp + 4]\r
+    mov     eax, [esp + 8]\r
+    mov     edx, [esp + 12]\r
+    lock    cmpxchg [ecx], dx\r
+    ret\r
+InternalSyncCompareExchange16   ENDP\r
+\r
+    END\r
diff --git a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c b/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.c
new file mode 100644 (file)
index 0000000..2b0fadd
--- /dev/null
@@ -0,0 +1,33 @@
+#include <Library/DebugLib.h>\r
+#include "InterlockedCompareExchange16.h"\r
+\r
+/**\r
+  Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
+  specified by Value.  If Value is equal to CompareValue, then Value is set to\r
+  ExchangeValue and CompareValue is returned.  If Value is not equal to CompareValue,\r
+  then Value is returned.  The compare exchange operation must be performed using\r
+  MP safe mechanisms.\r
+\r
+  If Value is NULL, then ASSERT().\r
+\r
+  @param  Value         A pointer to the 16-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  16-bit value used in compare operation.\r
+  @param  ExchangeValue 16-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+InterlockedCompareExchange16 (\r
+  IN OUT  UINT16                    *Value,\r
+  IN      UINT16                    CompareValue,\r
+  IN      UINT16                    ExchangeValue\r
+  )\r
+{\r
+  ASSERT (Value != NULL);\r
+  return InternalSyncCompareExchange16 (Value, CompareValue, ExchangeValue);\r
+}\r
diff --git a/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h b/OvmfPkg/XenBusDxe/InterlockedCompareExchange16.h
new file mode 100644 (file)
index 0000000..fd3f15b
--- /dev/null
@@ -0,0 +1,38 @@
+/**\r
+  Assembly implementation of InterlockedCompareExchange16.\r
+\r
+  Look at the documentation of InterlockedCompareExchange16.\r
+**/\r
+UINT16\r
+EFIAPI\r
+InternalSyncCompareExchange16 (\r
+  IN      volatile UINT16           *Value,\r
+  IN      UINT16                    CompareValue,\r
+  IN      UINT16                    ExchangeValue\r
+  );\r
+\r
+/**\r
+  Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
+\r
+  Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
+  specified by Value.  If Value is equal to CompareValue, then Value is set to\r
+  ExchangeValue and CompareValue is returned.  If Value is not equal to CompareValue,\r
+  then Value is returned.  The compare exchange operation must be performed using\r
+  MP safe mechanisms.\r
+\r
+  If Value is NULL, then ASSERT().\r
+\r
+  @param  Value         A pointer to the 16-bit value for the compare exchange\r
+                        operation.\r
+  @param  CompareValue  16-bit value used in compare operation.\r
+  @param  ExchangeValue 16-bit value used in exchange operation.\r
+\r
+  @return The original *Value before exchange.\r
+**/\r
+UINT16\r
+EFIAPI\r
+InterlockedCompareExchange16 (\r
+  IN OUT  UINT16                    *Value,\r
+  IN      UINT16                    CompareValue,\r
+  IN      UINT16                    ExchangeValue\r
+  );\r
diff --git a/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.S b/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.S
new file mode 100644 (file)
index 0000000..23e08f3
--- /dev/null
@@ -0,0 +1,13 @@
+# UINT16\r
+# EFIAPI\r
+# InternalSyncCompareExchange16 (\r
+#   IN      volatile UINT16           *Value,\r
+#   IN      UINT16                    CompareValue,\r
+#   IN      UINT16                    ExchangeValue\r
+#   );\r
+ASM_GLOBAL ASM_PFX(InternalSyncCompareExchange16)\r
+ASM_PFX(InternalSyncCompareExchange16):\r
+  mov %edx, %eax\r
+  lock\r
+  cmpxchgw %r8w, (%rcx)\r
+  ret\r
diff --git a/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.asm b/OvmfPkg/XenBusDxe/X64/InterlockedCompareExchange16.asm
new file mode 100644 (file)
index 0000000..b23e421
--- /dev/null
@@ -0,0 +1,41 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006, Intel Corporation. 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
+; Module Name:\r
+;\r
+;   InterlockedCompareExchange16.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   InterlockedCompareExchange16 function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    .code\r
+\r
+;------------------------------------------------------------------------------\r
+; UINT16\r
+; EFIAPI\r
+; InterlockedCompareExchange16 (\r
+;   IN      UINT16                    *Value,\r
+;   IN      UINT16                    CompareValue,\r
+;   IN      UINT16                    ExchangeValue\r
+;   );\r
+;------------------------------------------------------------------------------\r
+InternalSyncCompareExchange16   PROC\r
+    mov     eax, edx\r
+    lock    cmpxchg [rcx], r8w\r
+    ret\r
+InternalSyncCompareExchange16   ENDP\r
+\r
+    END\r
index add85213c640441085e8bbce08c209bd61ec8233..4e92a204f2eb90877f80f04afaaed6238064c77a 100644 (file)
   ComponentName.h\r
   XenHypercall.c\r
   XenHypercall.h\r
+  InterlockedCompareExchange16.c\r
+  InterlockedCompareExchange16.h\r
 \r
 [Sources.IA32]\r
   Ia32/hypercall.S\r
   Ia32/hypercall.asm\r
+  Ia32/InterlockedCompareExchange16.S\r
+  Ia32/InterlockedCompareExchange16.asm\r
 \r
 [Sources.X64]\r
   X64/hypercall.S\r
   X64/hypercall.asm\r
+  X64/InterlockedCompareExchange16.S\r
+  X64/InterlockedCompareExchange16.asm\r
 \r
 [LibraryClasses]\r
   UefiDriverEntryPoint\r