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 /arch/arm/lib64 | |
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 'arch/arm/lib64')
-rw-r--r-- | arch/arm/lib64/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/lib64/memcpy.S | 6 | ||||
-rw-r--r-- | arch/arm/lib64/memset.S | 4 | ||||
-rw-r--r-- | arch/arm/lib64/string.c | 22 |
4 files changed, 28 insertions, 6 deletions
diff --git a/arch/arm/lib64/Makefile b/arch/arm/lib64/Makefile index 77647128a5..4c0019fabe 100644 --- a/arch/arm/lib64/Makefile +++ b/arch/arm/lib64/Makefile @@ -2,7 +2,7 @@ obj-y += stacktrace.o obj-$(CONFIG_ARM_LINUX) += armlinux.o obj-y += div0.o obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS) += memcpy.o -obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS) += memset.o +obj-$(CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS) += memset.o string.o extra-y += barebox.lds obj-pbl-y += runtime-offset.o diff --git a/arch/arm/lib64/memcpy.S b/arch/arm/lib64/memcpy.S index cfed3191c5..a70e96ca29 100644 --- a/arch/arm/lib64/memcpy.S +++ b/arch/arm/lib64/memcpy.S @@ -67,8 +67,8 @@ stp \ptr, \regB, [\regC], \val .endm - .weak memcpy -ENTRY(memcpy) + .weak __arch_memcpy +ENTRY(__arch_memcpy) #include "copy_template.S" ret -ENDPROC(memcpy) +ENDPROC(__arch_memcpy) diff --git a/arch/arm/lib64/memset.S b/arch/arm/lib64/memset.S index 380a54097e..d17bcc6125 100644 --- a/arch/arm/lib64/memset.S +++ b/arch/arm/lib64/memset.S @@ -54,7 +54,7 @@ tmp3w .req w9 tmp3 .req x9 .weak memset -ENTRY(memset) +ENTRY(__arch_memset) mov dst, dstin /* Preserve return value. */ and A_lw, val, #255 orr A_lw, A_lw, A_lw, lsl #8 @@ -212,4 +212,4 @@ ENTRY(memset) ands count, count, zva_bits_x b.ne .Ltail_maybe_long ret -ENDPROC(memset) +ENDPROC(__arch_memset) diff --git a/arch/arm/lib64/string.c b/arch/arm/lib64/string.c new file mode 100644 index 0000000000..cb26331527 --- /dev/null +++ b/arch/arm/lib64/string.c @@ -0,0 +1,22 @@ +#include <common.h> +#include <asm/system.h> +#include <string.h> + +void *__arch_memset(void *dst, int c, __kernel_size_t size); +void *__arch_memcpy(void * dest, const void *src, size_t count); + +void *memset(void *dst, int c, __kernel_size_t size) +{ + if (likely(get_cr() & CR_M)) + return __arch_memset(dst, c, size); + + return __default_memset(dst, c, size); +} + +void *memcpy(void * dest, const void *src, size_t count) +{ + if (likely(get_cr() & CR_M)) + return __arch_memcpy(dest, src, count); + + return __default_memcpy(dest, src, count); +}
\ No newline at end of file |