]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/EfiZeroMem.asm
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Ia32 / EfiZeroMem.asm
CommitLineData
478db76b 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; EfiZeroMem.c\r
15;\r
16;Abstract:\r
17;\r
18; This is the code that supports IA32-optimized ZeroMem service\r
19;\r
20;--*/\r
21;---------------------------------------------------------------------------\r
22 .686\r
23 .model flat,C\r
24 .mmx\r
25 .code\r
26\r
27;---------------------------------------------------------------------------\r
28;VOID\r
29;EfiCommonLibZeroMem (\r
30; IN VOID *Buffer,\r
31; IN UINTN Count\r
32; )\r
33;/*++\r
34;\r
35;Input: VOID *Buffer - Pointer to buffer to clear\r
36; UINTN Count - Number of bytes to clear\r
37;\r
38;Output: None.\r
39;\r
40;Saves:\r
41;\r
42;Modifies:\r
43;\r
44;Description: This function is an optimized zero-memory function.\r
45;\r
46;Notes: This function tries to zero memory 8 bytes at a time. As a result, \r
47; it first picks up any misaligned bytes, then words, before getting \r
48; in the main loop that does the 8-byte clears.\r
49;\r
50;--*/\r
51EfiCommonLibZeroMem PROC\r
52; UINT64 MmxSave;\r
53 push ebp\r
54 mov ebp, esp\r
55 push ecx ; Reserve space for local variable MmxSave\r
56 push ecx\r
57 push edi\r
58 \r
59 mov ecx, [ebp + 0Ch] ; Count\r
60 mov edi, [ebp + 8]; Buffer\r
61\r
62 ; Pick up misaligned start bytes (get pointer 4-byte aligned)\r
63_StartByteZero:\r
64 mov eax, edi \r
65 and al, 3 ; check lower 2 bits of address\r
66 test al, al\r
67 je _ZeroBlocks ; already aligned?\r
68 cmp ecx, 0\r
69 je _ZeroMemDone\r
70\r
71 ; Clear the byte memory location\r
72 mov BYTE PTR [edi], 0 \r
73 inc edi\r
74\r
75 ; Decrement our count\r
76 dec ecx\r
77 jmp _StartByteZero ; back to top of loop\r
78\r
79_ZeroBlocks:\r
80\r
81 ; Compute how many 64-byte blocks we can clear \r
82 mov edx, ecx\r
83 shr ecx, 6 ; convert to 64-byte count\r
84 shl ecx, 6 ; convert back to bytes\r
85 sub edx, ecx ; subtract from the original count\r
86 shr ecx, 6 ; and this is how many 64-byte blocks\r
87\r
88 ; If no 64-byte blocks, then skip \r
89 cmp ecx, 0\r
90 je _ZeroRemaining\r
91\r
92 ; Save mm0\r
93 movq [ebp - 8], mm0 ; Save mm0 to MmxSave\r
94\r
95 pxor mm0, mm0 ; Clear mm0\r
96\r
97_B:\r
98 movq QWORD PTR ds:[edi], mm0\r
99 movq QWORD PTR ds:[edi+8], mm0\r
100 movq QWORD PTR ds:[edi+16], mm0\r
101 movq QWORD PTR ds:[edi+24], mm0\r
102 movq QWORD PTR ds:[edi+32], mm0\r
103 movq QWORD PTR ds:[edi+40], mm0\r
104 movq QWORD PTR ds:[edi+48], mm0\r
105 movq QWORD PTR ds:[edi+56], mm0\r
106 \r
107 add edi, 64\r
108 dec ecx\r
109 jnz _B\r
110 \r
111; Restore mm0\r
112 movq mm0, [ebp - 8] ; Restore mm0 from MmxSave\r
113 emms ; Exit MMX Instruction\r
114\r
115_ZeroRemaining:\r
116 ; Zero out as many DWORDS as possible\r
117 mov ecx, edx\r
118 shr ecx, 2\r
119 xor eax, eax\r
120\r
121 rep stosd\r
122\r
123 ; Zero out remaining as bytes\r
124 mov ecx, edx\r
125 and ecx, 03\r
126\r
127 rep stosb\r
128 \r
129_ZeroMemDone:\r
130\r
131 pop edi\r
132 leave\r
133 ret\r
134EfiCommonLibZeroMem ENDP \r
135 END\r