u-boot-brain/arch/riscv/lib
Bin Meng 703b84ec29 riscv: Fix memmove and optimise memcpy when misalign
At present U-Boot SPL fails to boot on SiFive Unleashed board, due
to a load address misaligned exception happens when loading the FIT
image in spl_load_simple_fit(). The exception happens in memmove()
which is called by fdt_splice_().

Commit 8f0dc4cfd1 introduces an assembly version of memmove but
it does take misalignment into account (it checks if length is a
multiple of machine word size but pointers need also be aligned).
As a result it will generate misaligned load/store for the majority
of cases and causes significant performance regression on hardware
that traps misaligned load/store and emulate them using firmware.

The current behaviour of memcpy is that it checks if both src and
dest pointers are co-aligned (aka congruent modular SZ_REG). If
aligned, it will copy data word-by-word after first aligning
pointers to word boundary. If src and dst are not co-aligned,
however, byte-wise copy will be performed.

This patch was taken from the Linux kernel patch [1], which has not
been applied at the time being. It fixes the memmove and optimises
memcpy for misaligned cases. It will first align destination pointer
to word-boundary regardless whether src and dest are co-aligned or
not. If they indeed are, then wordwise copy is performed. If they
are not co-aligned, then it will load two adjacent words from src
and use shifts to assemble a full machine word. Some additional
assembly level micro-optimisation is also performed to ensure more
instructions can be compressed (e.g. prefer a0 to t6).

With this patch, U-Boot boots again on SiFive Unleashed board.

[1] https://patchwork.kernel.org/project/linux-riscv/patch/20210216225555.4976-1-gary@garyguo.net/

Fixes: 8f0dc4cfd1 ("riscv: assembler versions of memcpy, memmove, memset")
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
2021-05-17 16:47:33 +08:00
..
andes_plic.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
asm-offsets.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
boot.c command: Remove the cmd_tbl_t typedef 2020-05-18 18:36:55 -04:00
bootm.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
cache.c common: Move some cache and MMU functions out of common.h 2019-12-02 18:23:55 -05:00
crt0_riscv_efi.S riscv: Complete efi header for RV32/64 2020-12-14 15:16:54 +08:00
elf_riscv32_efi.lds SPDX: Convert single license tags to Linux Kernel style 2018-05-29 14:44:21 +08:00
elf_riscv64_efi.lds SPDX: Convert single license tags to Linux Kernel style 2018-05-29 14:44:21 +08:00
fdt_fixup.c riscv: Fix arch_fixup_fdt always failing without /chosen 2021-05-17 16:46:33 +08:00
image.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
interrupts.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
Makefile riscv: Split SiFive CLINT support between SPL and U-Boot proper 2021-05-17 16:42:24 +08:00
memcpy.S riscv: Fix memmove and optimise memcpy when misalign 2021-05-17 16:47:33 +08:00
memmove.S riscv: Fix memmove and optimise memcpy when misalign 2021-05-17 16:47:33 +08:00
memset.S riscv: assembler versions of memcpy, memmove, memset 2021-04-08 15:37:29 +08:00
mkimage_fit_opensbi.sh riscv: add a generic FIT generator script 2019-08-26 16:07:42 +08:00
reloc_riscv_efi.c riscv: Remove unused _relocate arguments 2018-07-19 16:31:37 -04:00
reset.c Revert "riscv: Allow use of reset drivers" 2020-07-24 14:55:31 +08:00
sbi_ipi.c riscv: Clean up IPI initialization code 2020-07-01 15:01:22 +08:00
sbi.c cmd: provide command sbi 2020-08-25 09:34:47 +08:00
setjmp.S riscv: simplify longjmp 2021-04-08 15:37:29 +08:00
sifive_clint.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
smp.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00
spl.c common: Drop asm/global_data.h from common header 2021-02-02 15:33:42 -05:00