-#------------------------------------------------------------------------------
-#
-# Copyright (c) 2006, Intel Corporation
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-# Module Name:
-#
-# CopyMem.asm
-#
-# Abstract:
-#
-# CopyMem function
-#
-# Notes:
-#
-#------------------------------------------------------------------------------
-
- .686:
- #.MODEL flat,C
- .xmm:
- .code:
-
-#------------------------------------------------------------------------------
-# VOID *
-# _mem_CopyMem (
-# IN VOID *Destination,
-# IN VOID *Source,
-# IN UINTN Count
-# )
-#------------------------------------------------------------------------------
-.global _InternalMemCopyMem
-_InternalMemCopyMem:
- push %esi
- push %edi
- movl 16(%esp), %esi # esi <- Source
- movl 12(%esp), %edi # edi <- Destination
- movl 20(%esp), %edx # edx <- Count
- leal -1(%edi,%edx,), %eax # eax <- End of Destination
- cmpl %edi, %esi
- jae L0
- cmpl %esi, %eax # Overlapped?
- jae @CopyBackward # Copy backward if overlapped
-L0:
- xorl %ecx, %ecx
- subl %esi, %ecx
- andl $7, %ecx # ecx + esi aligns on 8-byte boundary
- jz L1
- cmpl %edx, %ecx
- cmova %edx, %ecx
- subl %ecx, %edx # edx <- remaining bytes to copy
- rep
- movsb
-L1:
- movl %edx, %ecx
- andl $7, %edx
- shrl $3, %ecx # ecx <- # of Qwords to copy
- jz @CopyBytes
- pushl %eax
- pushl %eax
- movq %mm0, (%esp) # save mm0
-L2:
- movq (%esi), %mm0
- movntq %mm0, (%edi)
- addl $8, %esi
- addl $8, %edi
- loop L2
- mfence
- movq (%esp), %mm0 # restore mm0
- popl %ecx # stack cleanup
- popl %ecx # stack cleanup
- jmp @CopyBytes
-@CopyBackward:
- movl %eax, %edi # edi <- Last byte in Destination
- leal -1(%esi,%edx,), %esi # esi <- Last byte in Source
- std
-@CopyBytes:
- movl %edx, %ecx
- rep
- movsb
- cld
- movl 12(%esp), %eax
- pop %esi
- pop %edi
- ret
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+# Module Name:\r
+#\r
+# CopyMem.asm\r
+#\r
+# Abstract:\r
+#\r
+# CopyMem function\r
+#\r
+# Notes:\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+ASM_GLOBAL ASM_PFX(InternalMemCopyMem)\r
+\r
+#------------------------------------------------------------------------------\r
+# VOID *\r
+# EFIAPI\r
+# InternalMemCopyMem (\r
+# IN VOID *Destination,\r
+# IN VOID *Source,\r
+# IN UINTN Count\r
+# );\r
+#------------------------------------------------------------------------------\r
+ASM_PFX(InternalMemCopyMem):\r
+ push %esi\r
+ push %edi\r
+ movl 16(%esp), %esi # esi <- Source\r
+ movl 12(%esp), %edi # edi <- Destination\r
+ movl 20(%esp), %edx # edx <- Count\r
+ leal -1(%esi,%edx,), %eax # eax <- End of Source\r
+ cmpl %edi, %esi\r
+ jae L0\r
+ cmpl %edi, %eax # Overlapped?\r
+ jae L_CopyBackward # Copy backward if overlapped\r
+L0:\r
+ xorl %ecx, %ecx\r
+ subl %esi, %ecx\r
+ andl $7, %ecx # ecx + esi aligns on 8-byte boundary\r
+ jz L1\r
+ cmpl %edx, %ecx\r
+ cmova %edx, %ecx\r
+ subl %ecx, %edx # edx <- remaining bytes to copy\r
+ rep\r
+ movsb\r
+L1:\r
+ movl %edx, %ecx\r
+ andl $7, %edx\r
+ shrl $3, %ecx # ecx <- # of Qwords to copy\r
+ jz L_CopyBytes\r
+ pushl %eax\r
+ pushl %eax\r
+ movq %mm0, (%esp) # save mm0\r
+L2:\r
+ movq (%esi), %mm0\r
+ movq %mm0, (%edi)\r
+ addl $8, %esi\r
+ addl $8, %edi\r
+ loop L2\r
+ movq (%esp), %mm0 # restore mm0\r
+ popl %ecx # stack cleanup\r
+ popl %ecx # stack cleanup\r
+ jmp L_CopyBytes\r
+L_CopyBackward:\r
+ movl %eax, %esi # esi <- Last byte in Source\r
+ leal -1(%edi,%edx,), %edi # edi <- Last byte in Destination\r
+ std\r
+L_CopyBytes:\r
+ movl %edx, %ecx\r
+ rep\r
+ movsb\r
+ cld\r
+ movl 12(%esp), %eax\r
+ pop %edi\r
+ pop %esi\r
+ ret\r