]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[libc] Fix and externalise memswap()
authorMichael Brown <mcb30@ipxe.org>
Mon, 5 Nov 2012 00:58:20 +0000 (00:58 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 12 Nov 2012 16:58:49 +0000 (16:58 +0000)
Make memswap() behave correctly if called with a length of zero.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/core/x86_string.c
src/arch/x86/include/bits/string.h

index 69c73f7042b2871a8ee804e08e4322376d765acf..d48347c962a9bece82c1368e0a4909592edb0329 100644 (file)
@@ -105,6 +105,34 @@ void * __memmove ( void *dest, const void *src, size_t len ) {
        }
 }
 
+/**
+ * Swap memory areas
+ *
+ * @v dest             Destination address
+ * @v src              Source address
+ * @v len              Length
+ * @ret dest           Destination address
+ */
+void * memswap ( void *dest, void *src, size_t len ) {
+       size_t discard_c;
+       int discard;
+
+       __asm__ __volatile__ ( "\n1:\n\t"
+                              "dec %2\n\t"
+                              "js 2f\n\t"
+                              "movb (%0,%2), %b3\n\t"
+                              "xchgb (%1,%2), %b3\n\t"
+                              "movb %b3, (%0,%2)\n\t"
+                              "jmp 1b\n\t"
+                              "2:\n\t"
+                              : "=r" ( src ), "=r" ( dest ),
+                                "=&c" ( discard_c ), "=&q" ( discard )
+                              : "0" ( src ), "1" ( dest ), "2" ( len )
+                              : "memory" );
+
+       return dest;
+}
+
 /**
  * Calculate length of string
  *
index 249dd543878cc41104bba7733c90db46f325217b..4d44c722f8b7d2336f2475e37d905d7fccfa1db2 100644 (file)
@@ -213,21 +213,8 @@ static inline void * memset ( void *dest, int fill, size_t len ) {
 }
 
 #define __HAVE_ARCH_MEMSWAP
-static inline void * memswap(void *dest, void *src, size_t n)
-{
-long d0, d1, d2, d3;
-__asm__ __volatile__(
-       "\n1:\t"
-       "movb (%2),%%al\n\t"
-       "xchgb (%1),%%al\n\t"
-       "inc %1\n\t"
-       "stosb\n\t"
-       "loop 1b"
-       : "=&c" (d0), "=&S" (d1), "=&D" (d2), "=&a" (d3)
-       : "0" (n), "1" (src), "2" (dest)
-       : "memory" );
-return dest;
-}
+
+extern void * memswap ( void *dest, void *src, size_t len );
 
 #define __HAVE_ARCH_STRNCMP