summaryrefslogtreecommitdiff
path: root/payloads
diff options
context:
space:
mode:
authorJordan Crouse <jordan.crouse@amd.com>2008-08-19 16:55:05 +0000
committerStefan Reinauer <stepan@openbios.org>2008-08-19 16:55:05 +0000
commit96f57aee0ac571378ee29d1a27a24114ea10a1c3 (patch)
tree640a250289931dabeec9be41dd81b5f49f5c233e /payloads
parent0740cdaac9e7bf37492988af31f85bb7898bc327 (diff)
downloadcoreboot-96f57aee0ac571378ee29d1a27a24114ea10a1c3.tar.xz
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 <jordan.crouse@amd.com> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3519 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads')
-rw-r--r--payloads/libpayload/libc/memory.c52
1 files changed, 17 insertions, 35 deletions
diff --git a/payloads/libpayload/libc/memory.c b/payloads/libpayload/libc/memory.c
index eb9fecc94c..bf1f99b212 100644
--- a/payloads/libpayload/libc/memory.c
+++ b/payloads/libpayload/libc/memory.c
@@ -43,59 +43,41 @@ void *memset(void *s, int c, size_t n)
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 char *) dst)[i] = ((unsigned char *) src)[i];
- for (i = 0; i < n / sizeof(unsigned long); i++)
- ((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
+ n -= i;
+ src += i;
+ dst += i;
- for (j = 0; j < n % sizeof(unsigned long); j++)
- ((unsigned char *)(((unsigned long *)dst) + i))[j] =
- ((unsigned char *)(((unsigned long *)src) + i))[j];
+ 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)
{
- int i, j;
+ int i;
+ unsigned long offs;
if (src > dst)
return memcpy(dst, src, n);
- for (j = (n % sizeof(unsigned long)) - 1; j >= 0; j--)
- ((unsigned char *)((unsigned long *)dst))[j] =
- ((unsigned char *)((unsigned long *)src))[j];
+ offs = n - (n % sizeof(unsigned long));
+
+ for (i = (n % sizeof(unsigned long)) - 1; i >= 0; i--)
+ ((unsigned char *)dst)[i + offs] =
+ ((unsigned char *)src)[i + offs];
for (i = n / sizeof(unsigned long) - 1; i >= 0; i--)
((unsigned long *)dst)[i] = ((unsigned long *)src)[i];
- return (char *)src;
+ return dst;
}
/**