[coreboot] New patch to review for coreboot: 6d4e711 Fix issues with x86 memcpy

Mathias Krause (minipli@googlemail.com) gerrit at coreboot.org
Sat Mar 31 17:41:11 CEST 2012

Mathias Krause (minipli at googlemail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/836


commit 6d4e71183f1238bc7e655122a5f733adc02e5088
Author: Mathias Krause <minipli at googlemail.com>
Date:   Sat Mar 31 17:23:53 2012 +0200

    Fix issues with x86 memcpy
    The x86 memcpy() implementation did not mention its implicit output
    registers ESI, EDI and ECX which might make this code miscompile when
    the compiler uses the value of EDI for the return value *after* the 'rep
    movsb' has completed. That would break the API of memcpy as this would
    return 'dst+len' instead of 'dst'.
    Fix this possible bug by removing the wrong comment and listing all
    output registers as such (using dummy stack variables that get optimized
    Also fix the prototype to match the one from <string.h>.
    Change-Id: I106422d41180c4ed876078cabb26b45e49f3fa93
    Signed-off-by: Mathias Krause <minipli at googlemail.com>
 src/arch/x86/lib/memcpy.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/arch/x86/lib/memcpy.c b/src/arch/x86/lib/memcpy.c
index de21092..f8607cf 100644
--- a/src/arch/x86/lib/memcpy.c
+++ b/src/arch/x86/lib/memcpy.c
@@ -1,13 +1,15 @@
 #include <string.h>
-void *memcpy(void *__restrict __dest,
-	     __const void *__restrict __src, size_t __n)
+void *memcpy(void *dest, const void *src, size_t n)
-	asm("cld\n"
-	    "rep\n"
-	    "movsb"
-	    :	/* no input (?) */
-	    :"S"(__src), "D"(__dest), "c"(__n)
-	);
-	return __dest;
+	unsigned long d0, d1, d2;
+	asm volatile(
+		"rep movsb"
+		: "=S"(d0), "=D"(d1), "=c"(d2)
+		: "0"(src), "1"(dest), "2"(n)
+		: "memory"
+		);
+	return dest;

More information about the coreboot mailing list