|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 07/18] OvmfPkg/XenbusDxe: Add InterlockedCompareExchange16.
This is a copy of InterlockedCompareExchange32 from the
BaseSynchronizationLib.
The function will be used in the next patch.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
OvmfPkg/XenbusDxe/InterlockedCompareExchange16.h | 7 ++++
.../XenbusDxe/X64/InterlockedCompareExchange16.c | 41 ++++++++++++++++++++++
OvmfPkg/XenbusDxe/XenbusDxe.inf | 2 ++
3 files changed, 50 insertions(+)
create mode 100644 OvmfPkg/XenbusDxe/InterlockedCompareExchange16.h
create mode 100644 OvmfPkg/XenbusDxe/X64/InterlockedCompareExchange16.c
diff --git a/OvmfPkg/XenbusDxe/InterlockedCompareExchange16.h
b/OvmfPkg/XenbusDxe/InterlockedCompareExchange16.h
new file mode 100644
index 0000000..55f61a8
--- /dev/null
+++ b/OvmfPkg/XenbusDxe/InterlockedCompareExchange16.h
@@ -0,0 +1,7 @@
+UINT16
+EFIAPI
+InterlockedCompareExchange16 (
+ IN OUT volatile UINT16 *Value,
+ IN UINT16 CompareValue,
+ IN UINT16 ExchangeValue
+ );
diff --git a/OvmfPkg/XenbusDxe/X64/InterlockedCompareExchange16.c
b/OvmfPkg/XenbusDxe/X64/InterlockedCompareExchange16.c
new file mode 100644
index 0000000..64962ba
--- /dev/null
+++ b/OvmfPkg/XenbusDxe/X64/InterlockedCompareExchange16.c
@@ -0,0 +1,41 @@
+// Took from BaseSynchronizationLib, and replaced 32 by 16
+/**
+ 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
+InterlockedCompareExchange16 (
+ IN OUT volatile UINT16 *Value,
+ IN UINT16 CompareValue,
+ IN UINT16 ExchangeValue
+ )
+{
+ __asm__ __volatile__ (
+ "lock \n\t"
+ "cmpxchgw %3, %1 "
+ : "=a" (CompareValue), // %0
+ "=m" (*Value) // %1
+ : "a" (CompareValue), // %2
+ "r" (ExchangeValue), // %3
+ "m" (*Value)
+ : "memory",
+ "cc"
+ );
+
+ return CompareValue;
+}
diff --git a/OvmfPkg/XenbusDxe/XenbusDxe.inf b/OvmfPkg/XenbusDxe/XenbusDxe.inf
index 1a6b131..8f58821 100644
--- a/OvmfPkg/XenbusDxe/XenbusDxe.inf
+++ b/OvmfPkg/XenbusDxe/XenbusDxe.inf
@@ -33,10 +33,12 @@
ComponentName.h
XenHypercall.c
XenHypercall.h
+ InterlockedCompareExchange16.h
[Sources.X64]
X64/hypercall.S
X64/hypercall.asm
+ X64/InterlockedCompareExchange16.c | GCC
[LibraryClasses]
UefiDriverEntryPoint
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |