This atomically test and clear a bit.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Anthony PERARD <anthony.per...@citrix.com>

---
Change in V2:
- Adding .asm version
- Comment the function
---
 OvmfPkg/XenBusDxe/X64/TestAndClearBit.S   | 13 +++++++++++++
 OvmfPkg/XenBusDxe/X64/TestAndClearBit.asm | 16 ++++++++++++++++
 OvmfPkg/XenBusDxe/XenBusDxe.h             | 19 +++++++++++++++++++
 OvmfPkg/XenBusDxe/XenBusDxe.inf           |  2 ++
 4 files changed, 50 insertions(+)
 create mode 100644 OvmfPkg/XenBusDxe/X64/TestAndClearBit.S
 create mode 100644 OvmfPkg/XenBusDxe/X64/TestAndClearBit.asm

diff --git a/OvmfPkg/XenBusDxe/X64/TestAndClearBit.S 
b/OvmfPkg/XenBusDxe/X64/TestAndClearBit.S
new file mode 100644
index 0000000..cd9c5ed
--- /dev/null
+++ b/OvmfPkg/XenBusDxe/X64/TestAndClearBit.S
@@ -0,0 +1,13 @@
+
+# INT32
+# EFIAPI
+# TestAndClearBit (
+#   IN  INT32 Bit,                // rcx
+#   IN  volatile VOID* Address    // rdx
+#   );
+ASM_GLOBAL ASM_PFX(TestAndClearBit)
+ASM_PFX(TestAndClearBit):
+  lock
+  btrl %ecx, (%rdx)
+  sbbl %eax, %eax
+  ret
diff --git a/OvmfPkg/XenBusDxe/X64/TestAndClearBit.asm 
b/OvmfPkg/XenBusDxe/X64/TestAndClearBit.asm
new file mode 100644
index 0000000..c7fc83d
--- /dev/null
+++ b/OvmfPkg/XenBusDxe/X64/TestAndClearBit.asm
@@ -0,0 +1,16 @@
+.code
+
+; INT32
+; EFIAPI
+; TestAndClearBit (
+;   IN  INT32 Bit,                // rcx
+;   IN  volatile VOID* Address    // rdx
+;   );
+TestAndClearBit PROC
+  lock
+  btr [rdx], ecx
+  sbb eax, eax
+  ret
+TestAndClearBit ENDP
+
+END
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.h b/OvmfPkg/XenBusDxe/XenBusDxe.h
index 878e7c5..d690914 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.h
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.h
@@ -113,4 +113,23 @@ struct _XENBUS_DEVICE {
   shared_info_t                 *SharedInfo;
 };
 
+/*
+ * Helpers
+ */
+
+/**
+  Atomically test and clear a bit.
+
+  @param Bit      Bit index to test in *Address
+  @param Address  The Address to the buffer that contain the bit to test.
+
+  @return Value of the Bit before it was cleared.
+**/
+INT32
+EFIAPI
+TestAndClearBit (
+  IN INT32 Bit,
+  IN volatile VOID *Address
+  );
+
 #endif
diff --git a/OvmfPkg/XenBusDxe/XenBusDxe.inf b/OvmfPkg/XenBusDxe/XenBusDxe.inf
index 13623bd..e8f362a 100644
--- a/OvmfPkg/XenBusDxe/XenBusDxe.inf
+++ b/OvmfPkg/XenBusDxe/XenBusDxe.inf
@@ -45,6 +45,8 @@
   X64/InterlockedCompareExchange16.c | GCC
   X64/InterlockedCompareExchange16.asm | INTEL
   InterlockedCompareExchange16Intel.c | INTEL
+  X64/TestAndClearBit.S
+  X64/TestAndClearBit.asm
 
 [LibraryClasses]
   UefiDriverEntryPoint
-- 
Anthony PERARD


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to