memcpy was slightly more complex then it should have been.
This simplifies things, but still retains the unsigned long
copy where appropriate to take advantage of our 32 bit
machines.

Signed-off-by: Jordan Crouse <[EMAIL PROTECTED]>
-- 
Jordan Crouse
Systems Software  Development Engineer 
Advanced Micro Devices, Inc.
libpayload:  Fix the memcpy functions 

There was a bit of confusion in the memcpy functions - we could simplify
things slightly without having to revert to 8 bit copies on a 32 bit
system.

Signed-off-by: Jordan Crouse <[EMAIL PROTECTED]>
Index: libpayload/libc/memory.c
===================================================================
--- libpayload.orig/libc/memory.c	2008-08-13 10:57:55.000000000 -0600
+++ libpayload/libc/memory.c	2008-08-13 11:05:10.000000000 -0600
@@ -43,42 +43,18 @@
 	return s;
 }
 
-struct along {
-	unsigned long n;
-} __attribute__ ((packed));
-
-static void *unaligned_memcpy(void *dst, const void *src, size_t n)
-{
-	int i, j;
-	struct along *adst = dst;
-	const struct along *asrc = src;
-
-	for (i = 0; i < n / sizeof(unsigned long); i++)
-		adst[i].n = asrc[i].n;
-
-	for (j = 0; j < n % sizeof(unsigned long); j++)
-		((unsigned char *)(((unsigned long *)dst) + i))[j] =
-		    ((unsigned char *)(((unsigned long *)src) + i))[j];
-
-	return (char *)src;
-}
-
 void *memcpy(void *dst, const void *src, size_t n)
 {
-	int i, j;
+	int i;
 
-	if (((long)dst & (sizeof(long) - 1))
-	    || ((long)src & (sizeof(long) - 1)))
-		return unaligned_memcpy(dst, src, n);
-
-	for (i = 0; i < n / sizeof(unsigned long); i++)
-		((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
+	for(i = 0; i < n % sizeof(unsigned long); i++)
+		((unsigned char *) dst)[i] = ((unsigned char *) src)[i];
 
-	for (j = 0; j < n % sizeof(unsigned long); j++)
-		((unsigned char *)(((unsigned long *)dst) + i))[j] =
-		    ((unsigned char *)(((unsigned long *)src) + i))[j];
+	n -= i;
+	for(i = 0; i < n / sizeof(unsigned long); i++)
+		((unsigned long *) dst)[i] = ((unsigned long *) src[i]);
 
-	return (char *)src;
+	return dst;
 }
 
 void *memmove(void *dst, const void *src, size_t n)
@@ -95,7 +71,7 @@
 	for (i = n / sizeof(unsigned long) - 1; i >= 0; i--)
 		((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
 
-	return (char *)src;
+	return (char *) dst;
 }
 
 /**
--
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to