1#------------------------------------------------------------------------------ 2# 3# Copyright (c) 2006, 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# CopyMem.asm 15# 16# Abstract: 17# 18# CopyMem function 19# 20# Notes: 21# 22#------------------------------------------------------------------------------ 23 24ASM_GLOBAL ASM_PFX(InternalMemCopyMem) 25 26#------------------------------------------------------------------------------ 27# VOID * 28# EFIAPI 29# InternalMemCopyMem ( 30# IN VOID *Destination, 31# IN VOID *Source, 32# IN UINTN Count 33# ); 34#------------------------------------------------------------------------------ 35ASM_PFX(InternalMemCopyMem): 36 push %esi 37 push %edi 38 movl 16(%esp), %esi # esi <- Source 39 movl 12(%esp), %edi # edi <- Destination 40 movl 20(%esp), %edx # edx <- Count 41 leal -1(%esi,%edx,), %eax # eax <- End of Source 42 cmpl %edi, %esi 43 jae L0 44 cmpl %edi, %eax # Overlapped? 45 jae L_CopyBackward # Copy backward if overlapped 46L0: 47 xorl %ecx, %ecx 48 subl %esi, %ecx 49 andl $7, %ecx # ecx + esi aligns on 8-byte boundary 50 jz L1 51 cmpl %edx, %ecx 52 cmova %edx, %ecx 53 subl %ecx, %edx # edx <- remaining bytes to copy 54 rep 55 movsb 56L1: 57 movl %edx, %ecx 58 andl $7, %edx 59 shrl $3, %ecx # ecx <- # of Qwords to copy 60 jz L_CopyBytes 61 pushl %eax 62 pushl %eax 63 movq %mm0, (%esp) # save mm0 64L2: 65 movq (%esi), %mm0 66 movq %mm0, (%edi) 67 addl $8, %esi 68 addl $8, %edi 69 loop L2 70 movq (%esp), %mm0 # restore mm0 71 popl %ecx # stack cleanup 72 popl %ecx # stack cleanup 73 jmp L_CopyBytes 74L_CopyBackward: 75 movl %eax, %esi # esi <- Last byte in Source 76 leal -1(%edi,%edx,), %edi # edi <- Last byte in Destination 77 std 78L_CopyBytes: 79 movl %edx, %ecx 80 rep 81 movsb 82 cld 83 movl 12(%esp), %eax 84 pop %edi 85 pop %esi 86 ret 87