Home | History | Annotate | Download | only in Ia32
      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   EfiCopyMemRep4.c
     15 
     16 Abstract:
     17 
     18   This is the code that uses rep movsd CopyMem service
     19 
     20 --*/
     21 
     22 #include "Tiano.h"
     23 
     24 VOID
     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     _CopyDWord
     61     cmp     eax, edi
     62     jae     _CopyBackward                ; Copy backward if overlapped
     63 _CopyDWord:
     64     mov     ecx, edx
     65     and     edx, 3
     66     shr     ecx, 2
     67     rep     movsd                        ; Copy as many Dwords as possible
     68     jmp     _CopyBytes
     69 _CopyBackward:
     70     mov     esi, eax                     ; esi <- End of Source
     71     lea     edi, [edi + edx - 1]         ; edi <- End of Destination
     72     std
     73 _CopyBytes:
     74     mov     ecx, edx
     75     rep     movsb                        ; Copy bytes backward
     76     cld
     77 _CopyDone:
     78   }
     79 }
     80