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

[Xen-devel] [XTF] [PATCH v2] lib.c: added unsigned 64bits division for 32 bits arch



this is a simple implementation of unsigned 64bits divisions
for 32 bits archs.

Signed-off-by: Paul Semel <semelpaul@xxxxxxxxx>
---
 arch/x86/include/arch/lib.h |  2 ++
 arch/x86/lib.c              | 37 +++++++++++++++++++++++++++++++++++++
 build/files.mk              |  1 +
 3 files changed, 40 insertions(+)
 create mode 100644 arch/x86/lib.c

diff --git a/arch/x86/include/arch/lib.h b/arch/x86/include/arch/lib.h
index 0045902..e077b12 100644
--- a/arch/x86/include/arch/lib.h
+++ b/arch/x86/include/arch/lib.h
@@ -374,6 +374,8 @@ static inline void write_xcr0(uint64_t xcr0)
     xsetbv(0, xcr0);
 }
 
+uint32_t __udiv64_32(uint64_t *n, uint32_t base);
+
 #endif /* XTF_X86_LIB_H */
 
 /*
diff --git a/arch/x86/lib.c b/arch/x86/lib.c
new file mode 100644
index 0000000..46a5353
--- /dev/null
+++ b/arch/x86/lib.c
@@ -0,0 +1,37 @@
+/**
+ * @file arch/x86/decode.c
+ *
+ * Helper routines for decoding x86 architectural state.
+ */
+#include <xtf/lib.h>
+#include <xtf/libc.h>
+
+uint32_t __udiv64_32(uint64_t *n, uint32_t base)
+{
+    uint32_t rem;
+    uint32_t *n_32 = (uint32_t *)n;
+    uint32_t high = n_32[1];
+
+    n_32[1] = 0;
+    if ( high >= base )
+    {
+        n_32[1] = high / base;
+        high %= base;
+    }
+
+    asm("divl %[base]"
+            : "=a" (n_32[0]), "=d" (rem)
+            : [base] "rm" (base), "0" (n_32[0]), "1" (high));
+
+    return rem;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/build/files.mk b/build/files.mk
index 46b42d6..284ce6e 100644
--- a/build/files.mk
+++ b/build/files.mk
@@ -18,6 +18,7 @@ obj-perarch += $(ROOT)/common/setup.o
 obj-perarch += $(ROOT)/common/xenbus.o
 
 obj-perenv += $(ROOT)/arch/x86/decode.o
+obj-perenv += $(ROOT)/arch/x86/lib.o
 obj-perenv += $(ROOT)/arch/x86/desc.o
 obj-perenv += $(ROOT)/arch/x86/extable.o
 obj-perenv += $(ROOT)/arch/x86/grant_table.o
-- 
2.16.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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