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 <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/88796
Reviewed-by: Shuo Liu <shuo.liu@intel.com>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Patrick Rudolph 2025-08-16 09:21:25 +02:00 committed by Matt DeVillier
commit e37a53a2fc

View file

@ -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"