1 /*++
2 
3 Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution.  The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8 
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 
12 Module Name:
13 
14   EfiCopyMemRep1.c
15 
16 Abstract:
17 
18   This is the code that uses rep movsb CopyMem service
19 
20 --*/
21 
22 #include "Tiano.h"
23 
24 VOID
EfiCommonLibCopyMem(IN VOID * Destination,IN VOID * Source,IN UINTN Count)25 EfiCommonLibCopyMem (
26   IN VOID   *Destination,
27   IN VOID   *Source,
28   IN UINTN  Count
29   )
30 /*++
31 
32 Routine Description:
33 
34   Copy Length bytes from Source to Destination.
35 
36 Arguments:
37 
38   Destination - Target of copy
39 
40   Source      - Place to copy from
41 
42   Length      - Number of bytes to copy
43 
44 Returns:
45 
46   None
47 
48 --*/
49 {
50   __asm {
51     mov     esi, Source                  ; esi <- Source
52     mov     edi, Destination             ; edi <- Destination
53     mov     edx, Count                   ; edx <- Count
54     cmp     esi, edi
55     je      _CopyDone
56     cmp     edx, 0
57     je      _CopyDone
58     lea     eax, [esi + edx - 1]         ; eax <- End of Source
59     cmp     esi, edi
60     jae     _CopyBytes
61     cmp     eax, edi
62     jb      _CopyBytes                   ; Copy backward if overlapped
63     mov     esi, eax                     ; esi <- End of Source
64     lea     edi, [edi + edx - 1]         ; edi <- End of Destination
65     std
66 _CopyBytes:
67     mov     ecx, edx
68     rep     movsb                        ; Copy bytes backward
69     cld
70 _CopyDone:
71   }
72 }
73 
74