From e37a53a2fc9faa944aa3a224cf942d0c89bf9414 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Sat, 16 Aug 2025 09:21:25 +0200 Subject: [PATCH] arch/x86/memcpy: Fix undefined behaviour Clear DF flag before invoking MOVS instruction to make sure it increments %esi/%edi on each mov. Change-Id: I209f50dec2003ea9846e5958d3e77b8979f338df Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/88796 Reviewed-by: Shuo Liu Reviewed-by: Paul Menzel Reviewed-by: Angel Pons Tested-by: build bot (Jenkins) --- src/arch/x86/memcpy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/arch/x86/memcpy.c b/src/arch/x86/memcpy.c index 9da2a7512e..3b5a64d163 100644 --- a/src/arch/x86/memcpy.c +++ b/src/arch/x86/memcpy.c @@ -16,6 +16,7 @@ void *memcpy(void *dest, const void *src, size_t n) #if ENV_X86_64 asm volatile( + "cld\n\t" "rep ; movsq\n\t" "mov %4,%%rcx\n\t" "rep ; movsb\n\t" @@ -25,6 +26,7 @@ void *memcpy(void *dest, const void *src, size_t n) ); #else asm volatile( + "cld\n\t" "rep ; movsl\n\t" "movl %4,%%ecx\n\t" "rep ; movsb\n\t"