[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Add 64-bit (cmpxchg8b) support to the cmpxchg() macro for x86_32.



ChangeSet 1.1551, 2005/05/25 14:07:42+01:00, kaf24@xxxxxxxxxxxxxxxxxxxx

        Add 64-bit (cmpxchg8b) support to the cmpxchg() macro for x86_32.
        Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>



 system.h |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 5 deletions(-)


diff -Nru a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h
--- a/xen/include/asm-x86/system.h      2005-05-25 10:01:33 -04:00
+++ b/xen/include/asm-x86/system.h      2005-05-25 10:01:33 -04:00
@@ -2,6 +2,7 @@
 #define __ASM_SYSTEM_H
 
 #include <xen/config.h>
+#include <xen/types.h>
 #include <asm/bitops.h>
 
 /* Clear and set 'TS' bit respectively */
@@ -70,8 +71,8 @@
  * indicated by comparing RETURN with OLD.
  */
 
-static always_inline unsigned long __cmpxchg(volatile void *ptr, unsigned long 
old,
-                                     unsigned long new, int size)
+static always_inline unsigned long __cmpxchg(
+    volatile void *ptr, unsigned long old, unsigned long new, int size)
 {
        unsigned long prev;
        switch (size) {
@@ -113,9 +114,49 @@
 }
 
 #define __HAVE_ARCH_CMPXCHG
-#define cmpxchg(ptr,o,n)\
-       ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
-                                       (unsigned long)(n),sizeof(*(ptr))))
+
+#if BITS_PER_LONG == 64
+
+#define cmpxchg(ptr,o,n)                                                \
+    ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),            \
+                                   (unsigned long)(n),sizeof(*(ptr))))
+#else
+
+static always_inline unsigned long long __cmpxchg8b(
+    volatile void *ptr, unsigned long long old, unsigned long long new)
+{
+    unsigned long long prev;
+    __asm__ __volatile__ (
+        LOCK_PREFIX "cmpxchg8b %3"
+        : "=A" (prev)
+        : "c" ((u32)(new>>32)), "b" ((u32)new),
+          "m" (*__xg((volatile void *)ptr)), "0" (old)
+        : "memory" );
+    return prev;
+}
+
+#define cmpxchg(ptr,o,n)                                \
+({                                                      \
+    __typeof__(*(ptr)) __prev;                          \
+    switch ( sizeof(*(ptr)) ) {                         \
+    case 8:                                             \
+        __prev = ((__typeof__(*(ptr)))__cmpxchg8b(      \
+            (ptr),                                      \
+            (unsigned long long)(o),                    \
+            (unsigned long long)(n)));                  \
+        break;                                          \
+    default:                                            \
+        __prev = ((__typeof__(*(ptr)))__cmpxchg(        \
+            (ptr),                                      \
+            (unsigned long)(o),                         \
+            (unsigned long)(n),                         \
+            sizeof(*(ptr))));                           \
+        break;                                          \
+    }                                                   \
+    __prev;                                             \
+})
+
+#endif
 
 
 /*

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.