]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Introduce locked bt* operations
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 4 Jul 2017 16:51:03 +0000 (16:51 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 6 Jul 2017 15:52:18 +0000 (16:52 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/include/arch/bitops.h [new file with mode: 0644]
include/xtf.h
include/xtf/bitops.h [new file with mode: 0644]

diff --git a/arch/x86/include/arch/bitops.h b/arch/x86/include/arch/bitops.h
new file mode 100644 (file)
index 0000000..25844b2
--- /dev/null
@@ -0,0 +1,77 @@
+/**
+ * @file arch/x86/include/arch/bitops.h
+ *
+ * Low level bit operations.
+ */
+#ifndef XTF_X86_BITOPS_H
+#define XTF_X86_BITOPS_H
+
+#include <xtf/lib.h>
+
+static inline bool test_bit(unsigned int bit, const void *addr)
+{
+    bool old;
+
+    asm volatile ("bt %[bit], %[ptr];"
+                  ASM_FLAG_OUT(, "sbb %[old], %[old];")
+                  : [old] ASM_FLAG_OUT("=@ccc", "=r") (old)
+                  : [ptr] "m" (*(char *)addr),
+                    [bit] "Ir" (bit)
+                  : "memory");
+
+    return old;
+}
+
+static inline bool test_and_set_bit(unsigned int bit, volatile void *addr)
+{
+    bool old;
+
+    asm volatile ("lock; bts %[bit], %[ptr];"
+                  ASM_FLAG_OUT(, "sbb %[old], %[old];")
+                  : [old] ASM_FLAG_OUT("=@ccc", "=r") (old),
+                    [ptr] "+m" (*(char *)addr)
+                  : [bit] "Ir" (bit)
+                  : "memory");
+
+    return old;
+}
+
+static inline bool test_and_change_bit(unsigned int bit, volatile void *addr)
+{
+    bool old;
+
+    asm volatile ("lock; btc %[bit], %[ptr];"
+                  ASM_FLAG_OUT(, "sbb %[old], %[old];")
+                  : [old] ASM_FLAG_OUT("=@ccc", "=r") (old),
+                    [ptr] "+m" (*(char *)addr)
+                  : [bit] "Ir" (bit)
+                  : "memory");
+
+    return old;
+}
+
+static inline bool test_and_clear_bit(unsigned int bit, volatile void *addr)
+{
+    bool old;
+
+    asm volatile ("lock; btr %[bit], %[ptr];"
+                  ASM_FLAG_OUT(, "sbb %[old], %[old];")
+                  : [old] ASM_FLAG_OUT("=@ccc", "=r") (old),
+                    [ptr] "+m" (*(char *)addr)
+                  : [bit] "Ir" (bit)
+                  : "memory");
+
+    return old;
+}
+
+#endif /* XTF_X86_BITOPS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index b05aa89ef1df778bd1f21c4b296a9d8b0cbf4aaf..134819aaf2226883adca1e7247218eed4de435ca 100644 (file)
@@ -19,6 +19,7 @@
 #include <xtf/test.h>
 
 /* Optional functionality */
+#include <xtf/bitops.h>
 #include <xtf/exlog.h>
 #include <xtf/hypercall.h>
 #include <xtf/traps.h>
diff --git a/include/xtf/bitops.h b/include/xtf/bitops.h
new file mode 100644 (file)
index 0000000..68a24b7
--- /dev/null
@@ -0,0 +1,21 @@
+/**
+ * @file include/xtf/bitops.h
+ *
+ * Low level bit operations.
+ */
+#ifndef XTF_BITOPS_H
+#define XTF_BITOPS_H
+
+#include <arch/bitops.h>
+
+#endif /* XTF_BITOPS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */