]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibOptPei/Ia32/CopyMem.nasm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibOptPei / Ia32 / CopyMem.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Module Name:
7 ;
8 ; CopyMem.Asm
9 ;
10 ; Abstract:
11 ;
12 ; CopyMem function
13 ;
14 ; Notes:
15 ;
16 ;------------------------------------------------------------------------------
17
18 SECTION .text
19
20 ;------------------------------------------------------------------------------
21 ; VOID *
22 ; InternalMemCopyMem (
23 ; IN VOID *Destination,
24 ; IN VOID *Source,
25 ; IN UINTN Count
26 ; )
27 ;------------------------------------------------------------------------------
28 global ASM_PFX(InternalMemCopyMem)
29 ASM_PFX(InternalMemCopyMem):
30 push esi
31 push edi
32 mov esi, [esp+16] ; esi <- Source
33 mov edi, [esp+12] ; edi <- Destination
34 mov edx, [esp+20] ; edx <- Count
35 cmp esi, edi
36 je @CopyDone
37 cmp edx, 0
38 je @CopyDone
39 lea eax, [esi + edx - 1] ; eax <- End of Source
40 cmp esi, edi
41 jae @CopyBytes
42 cmp eax, edi
43 jb @CopyBytes ; Copy backward if overlapped
44 mov esi, eax ; esi <- End of Source
45 lea edi, [edi + edx - 1] ; edi <- End of Destination
46 std
47 @CopyBytes:
48 mov ecx, edx
49 rep movsb ; Copy bytes backward
50 cld
51 @CopyDone:
52 mov eax, [esp + 12] ; eax <- Destination as return value
53 pop edi
54 pop esi
55 ret
56