diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2018-06-07 06:00:55 -0700 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-06-11 08:54:10 +0200 |
commit | 32e8842c4005b38b643bc1215d0f1dfb9e288613 (patch) | |
tree | d1a8eb1306c5e7b92e92371844315299b2715178 /lib | |
parent | 5849fbf6f92899d4aca4ca99b6d4ba486d781ce5 (diff) | |
download | barebox-32e8842c4005b38b643bc1215d0f1dfb9e288613.tar.gz barebox-32e8842c4005b38b643bc1215d0f1dfb9e288613.tar.xz |
ARM: lib64: Make string functions aware of MMU configuration
Optimized version of memset() in memset.S if called as:
memset(foo, 0, size)
will try to explicitly zero out data cache with:
dc zva, dst
which will result in Alignement Exception (DABT) if MMU is not
enabled.
For more info see:
- C4.4.8 "DC ZVA, Data Cache Zero by VA"
- D5.2.8 "The effects of disabling a stage of address translation"
in "ARM Architecture Reference Manual. ARMv8, for ARMv8-A architecture
profile"
In similar vein, using optimized version of memcpy() could lead to a
unaligned 16-byte write (using 'stp'), which is not allowed for
Device-nGnRnE type of memory (see D5.2.8) and would liead to
Alignement Exception.
To fix both problems expose non-optimized and optimzied versions of
the function and created a wrapper to dispatch the call to either one
based on if MMU is enabled or not.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/string.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/string.c b/lib/string.c index f588933e81..717b59aa50 100644 --- a/lib/string.c +++ b/lib/string.c @@ -479,7 +479,6 @@ char *strswab(const char *s) } #endif -#ifndef __HAVE_ARCH_MEMSET /** * memset - Fill a region of memory with the given value * @s: Pointer to the start of the area. @@ -488,7 +487,7 @@ char *strswab(const char *s) * * Do not use memset() to access IO space, use memset_io() instead. */ -void * memset(void * s,int c,size_t count) +void *__default_memset(void * s,int c,size_t count) { char *xs = (char *) s; @@ -497,10 +496,12 @@ void * memset(void * s,int c,size_t count) return s; } +EXPORT_SYMBOL(__default_memset); + +#ifndef __HAVE_ARCH_MEMSET +void *memset(void *s, int c, size_t count) __alias(__default_memset); #endif -EXPORT_SYMBOL(memset); -#ifndef __HAVE_ARCH_MEMCPY /** * memcpy - Copy one area of memory to another * @dest: Where to copy to @@ -510,7 +511,7 @@ EXPORT_SYMBOL(memset); * You should not use this function to access IO space, use memcpy_toio() * or memcpy_fromio() instead. */ -void * memcpy(void * dest,const void *src,size_t count) +void *__default_memcpy(void * dest,const void *src,size_t count) { char *tmp = (char *) dest, *s = (char *) src; @@ -519,9 +520,14 @@ void * memcpy(void * dest,const void *src,size_t count) return dest; } -#endif EXPORT_SYMBOL(memcpy); +#ifndef __HAVE_ARCH_MEMCPY +void *memcpy(void * dest, const void *src, size_t count) + __alias(__default_memcpy); +#endif + + #ifndef __HAVE_ARCH_MEMMOVE /** * memmove - Copy one area of memory to another |