From 4acb0e774220c0705a71689b6620c976297d417c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Neusch=C3=A4fer?= Date: Fri, 27 May 2016 09:05:02 +0200 Subject: commonlib/lz4: Avoid unaligned memory access on RISC-V MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the User-Level ISA Specification v2.0: "We do not mandate atomicity for misaligned accesses so simple implementations can just use a machine trap and software handler to handle misaligned accesses." (— http://riscv.org/specifications/) Spike traps on unaligned accesses. Change-Id: Ia57786916f4076cc08513f4e331c2deec9cfa785 Signed-off-by: Jonathan Neuschäfer Reviewed-on: https://review.coreboot.org/14983 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/commonlib/lz4_wrapper.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/commonlib') diff --git a/src/commonlib/lz4_wrapper.c b/src/commonlib/lz4_wrapper.c index 772f7918f4..93fa7e8e1d 100644 --- a/src/commonlib/lz4_wrapper.c +++ b/src/commonlib/lz4_wrapper.c @@ -63,6 +63,11 @@ static void LZ4_copy8(void *dst, const void *src) : [src]"r"(src), [dst]"r"(dst) : "memory" ); #endif +#elif defined(__riscv__) + /* RISC-V implementations may trap on any unaligned access. */ + int i; + for (i = 0; i < 8; i++) + ((uint8_t *)dst)[i] = ((uint8_t *)src)[i]; #else *(uint64_t *)dst = *(const uint64_t *)src; #endif -- cgit v1.2.3