]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLibRepStr/Ia32/CopyMem.nasm
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibRepStr / 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 lea eax, [esi + edx - 1] ; eax <- End of Source
36 cmp esi, edi
37 jae .0
38 cmp eax, edi
39 jae @CopyBackward ; Copy backward if overlapped
40 .0:
41 mov ecx, edx
42 and edx, 3
43 shr ecx, 2
44 rep movsd ; Copy as many Dwords as possible
45 jmp @CopyBytes
46 @CopyBackward:
47 mov esi, eax ; esi <- End of Source
48 lea edi, [edi + edx - 1] ; edi <- End of Destination
49 std
50 @CopyBytes:
51 mov ecx, edx
52 rep movsb ; Copy bytes backward
53 cld
54 mov eax, [esp + 12] ; eax <- Destination as return value
55 pop edi
56 pop esi
57 ret
58