2016-04-27 05:46:06 +08:00
|
|
|
/*
|
|
|
|
* This provides an optimized implementation of memcpy, and a simplified
|
|
|
|
* implementation of memset and memmove. These are used here because the
|
|
|
|
* standard kernel runtime versions are not yet available and we don't
|
|
|
|
* trust the gcc built-in implementations as they may do unexpected things
|
|
|
|
* (e.g. FPU ops) in the minimal decompression stub execution environment.
|
|
|
|
*/
|
2010-08-03 07:21:22 +08:00
|
|
|
#include "../string.c"
|
2014-03-19 03:26:38 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_32
|
2016-04-27 05:46:06 +08:00
|
|
|
void *memcpy(void *dest, const void *src, size_t n)
|
2014-03-19 03:26:38 +08:00
|
|
|
{
|
|
|
|
int d0, d1, d2;
|
|
|
|
asm volatile(
|
|
|
|
"rep ; movsl\n\t"
|
|
|
|
"movl %4,%%ecx\n\t"
|
|
|
|
"rep ; movsb\n\t"
|
|
|
|
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
|
|
|
|
: "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
#else
|
2016-04-27 05:46:06 +08:00
|
|
|
void *memcpy(void *dest, const void *src, size_t n)
|
2014-03-19 03:26:38 +08:00
|
|
|
{
|
|
|
|
long d0, d1, d2;
|
|
|
|
asm volatile(
|
|
|
|
"rep ; movsq\n\t"
|
|
|
|
"movq %4,%%rcx\n\t"
|
|
|
|
"rep ; movsb\n\t"
|
|
|
|
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
|
|
|
|
: "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
|
|
|
|
: "memory");
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
#endif
|
2014-03-19 03:26:40 +08:00
|
|
|
|
|
|
|
void *memset(void *s, int c, size_t n)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *ss = s;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
ss[i] = c;
|
|
|
|
return s;
|
|
|
|
}
|
2016-04-21 04:55:45 +08:00
|
|
|
|
2016-04-27 05:46:06 +08:00
|
|
|
void *memmove(void *dest, const void *src, size_t n)
|
2016-04-21 04:55:45 +08:00
|
|
|
{
|
|
|
|
unsigned char *d = dest;
|
|
|
|
const unsigned char *s = src;
|
|
|
|
|
|
|
|
if (d <= s || d - s >= n)
|
2016-04-27 05:46:06 +08:00
|
|
|
return memcpy(dest, src, n);
|
2016-04-21 04:55:45 +08:00
|
|
|
|
|
|
|
while (n-- > 0)
|
|
|
|
d[n] = s[n];
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|