]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.S
BasePrintLib: Fix Buffer Overflow issue.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibMmx / Ia32 / CopyMem.S
CommitLineData
6e3b8c47 1#------------------------------------------------------------------------------
2#
3# Copyright (c) 2006, Intel Corporation
4# All rights reserved. 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
24 .686:
25 #.MODEL flat,C
26 .xmm:
27 .code:
28
29#------------------------------------------------------------------------------
30# VOID *
31# _mem_CopyMem (
32# IN VOID *Destination,
33# IN VOID *Source,
34# IN UINTN Count
35# )
36#------------------------------------------------------------------------------
37.global _InternalMemCopyMem
38_InternalMemCopyMem:
39 push %esi
40 push %edi
41 movl 16(%esp), %esi # esi <- Source
42 movl 12(%esp), %edi # edi <- Destination
43 movl 20(%esp), %edx # edx <- Count
44 leal -1(%edi,%edx,), %eax # eax <- End of Destination
45 cmpl %edi, %esi
46 jae L0
47 cmpl %esi, %eax # Overlapped?
48 jae @CopyBackward # Copy backward if overlapped
49L0:
50 xorl %ecx, %ecx
51 subl %esi, %ecx
52 andl $7, %ecx # ecx + esi aligns on 8-byte boundary
53 jz L1
54 cmpl %edx, %ecx
55 cmova %edx, %ecx
56 subl %ecx, %edx # edx <- remaining bytes to copy
57 rep
58 movsb
59L1:
60 movl %edx, %ecx
61 andl $7, %edx
62 shrl $3, %ecx # ecx <- # of Qwords to copy
63 jz @CopyBytes
64 pushl %eax
65 pushl %eax
66 movq %mm0, (%esp) # save mm0
67L2:
68 movq (%esi), %mm0
69 movntq %mm0, (%edi)
70 addl $8, %esi
71 addl $8, %edi
72 loop L2
73 mfence
74 movq (%esp), %mm0 # restore mm0
75 popl %ecx # stack cleanup
76 popl %ecx # stack cleanup
77 jmp @CopyBytes
78@CopyBackward:
79 movl %eax, %edi # edi <- Last byte in Destination
80 leal -1(%esi,%edx,), %esi # esi <- Last byte in Source
81 std
82@CopyBytes:
83 movl %edx, %ecx
84 rep
85 movsb
86 cld
87 movl 12(%esp), %eax
4f7f1f5f 88 pop %esi
89 pop %edi
6e3b8c47 90 ret