]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibMmx/Ia32/CopyMem.asm
Added more error check on validation to let result be more exact.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibMmx / Ia32 / CopyMem.asm
CommitLineData
6e3b8c47 1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2006, Intel Corporation\r
4; All rights reserved. This program and the accompanying materials\r
5; are licensed and made available under the terms and conditions of the BSD License\r
6; which accompanies this distribution. The full text of the license may be found at\r
7; http://opensource.org/licenses/bsd-license.php\r
8;\r
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11;\r
12; Module Name:\r
13;\r
14; CopyMem.asm\r
15;\r
16; Abstract:\r
17;\r
18; CopyMem function\r
19;\r
20; Notes:\r
21;\r
22;------------------------------------------------------------------------------\r
23\r
24 .686\r
25 .model flat,C\r
26 .xmm\r
27 .code\r
28\r
29;------------------------------------------------------------------------------\r
30; VOID *\r
31; _mem_CopyMem (\r
32; IN VOID *Destination,\r
33; IN VOID *Source,\r
34; IN UINTN Count\r
35; )\r
36;------------------------------------------------------------------------------\r
37InternalMemCopyMem PROC USES esi edi\r
38 mov esi, [esp + 16] ; esi <- Source\r
39 mov edi, [esp + 12] ; edi <- Destination\r
40 mov edx, [esp + 20] ; edx <- Count\r
41 lea eax, [edi + edx - 1] ; eax <- End of Destination\r
42 cmp esi, edi\r
43 jae @F\r
44 cmp eax, esi ; Overlapped?\r
45 jae @CopyBackward ; Copy backward if overlapped\r
46@@:\r
47 xor ecx, ecx\r
48 sub ecx, esi\r
49 and ecx, 7 ; ecx + esi aligns on 8-byte boundary\r
50 jz @F\r
51 cmp ecx, edx\r
52 cmova ecx, edx\r
53 sub edx, ecx ; edx <- remaining bytes to copy\r
54 rep movsb\r
55@@:\r
56 mov ecx, edx\r
57 and edx, 7\r
58 shr ecx, 3 ; ecx <- # of Qwords to copy\r
59 jz @CopyBytes\r
60 push eax\r
61 push eax\r
62 movq [esp], mm0 ; save mm0\r
63@@:\r
64 movq mm0, [esi]\r
65 movntq [edi], mm0\r
66 add esi, 8\r
67 add edi, 8\r
68 loop @B\r
69 mfence\r
70 movq mm0, [esp] ; restore mm0\r
71 pop ecx ; stack cleanup\r
72 pop ecx ; stack cleanup\r
73 jmp @CopyBytes\r
74@CopyBackward:\r
75 mov edi, eax ; edi <- Last byte in Destination\r
76 lea esi, [esi + edx - 1] ; esi <- Last byte in Source\r
77 std\r
78@CopyBytes:\r
79 mov ecx, edx\r
80 rep movsb\r
81 cld\r
82 mov eax, [esp + 12]\r
83 ret\r
84InternalMemCopyMem ENDP\r
85\r
86 END\r