]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/EfiZeroMem.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Ia32 / EfiZeroMem.c
CommitLineData
3eb9473e 1/*++\r
2\r
4ea9375a
HT
3Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 EfiZeroMem.c\r
15\r
16Abstract:\r
17\r
18 This is the code that supports IA32-optimized ZeroMem service\r
19\r
20--*/\r
21\r
22#include "Tiano.h"\r
23\r
24VOID\r
25EfiCommonLibZeroMem (\r
26 IN VOID *Buffer,\r
27 IN UINTN Count\r
28 )\r
29/*++\r
30\r
31Input: VOID *Buffer - Pointer to buffer to clear\r
32 UINTN Count - Number of bytes to clear\r
33\r
34Output: None.\r
35\r
36Saves:\r
37\r
38Modifies:\r
39\r
40Description: This function is an optimized zero-memory function.\r
41\r
42Notes: This function tries to zero memory 8 bytes at a time. As a result, \r
43 it first picks up any misaligned bytes, then words, before getting \r
44 in the main loop that does the 8-byte clears.\r
45\r
46--*/\r
47{\r
48 UINT64 MmxSave;\r
49 __asm {\r
50 mov ecx, Count\r
51 mov edi, Buffer\r
52\r
53 ; Pick up misaligned start bytes (get pointer 4-byte aligned)\r
54_StartByteZero:\r
55 mov eax, edi \r
56 and al, 3 ; check lower 2 bits of address\r
57 test al, al\r
58 je _ZeroBlocks ; already aligned?\r
59 cmp ecx, 0\r
60 je _ZeroMemDone\r
61\r
62 ; Clear the byte memory location\r
63 mov BYTE PTR [edi], 0 \r
64 inc edi\r
65\r
66 ; Decrement our count\r
67 dec ecx\r
68 jmp _StartByteZero ; back to top of loop\r
69\r
70_ZeroBlocks:\r
71\r
72 ; Compute how many 64-byte blocks we can clear \r
73 mov edx, ecx\r
74 shr ecx, 6 ; convert to 64-byte count\r
75 shl ecx, 6 ; convert back to bytes\r
76 sub edx, ecx ; subtract from the original count\r
77 shr ecx, 6 ; and this is how many 64-byte blocks\r
78\r
79 ; If no 64-byte blocks, then skip \r
80 cmp ecx, 0\r
81 je _ZeroRemaining\r
82\r
83 ; Save mm0\r
84 movq MmxSave, mm0\r
85\r
86 pxor mm0, mm0 ; Clear mm0\r
87\r
88_B:\r
89 movq QWORD PTR ds:[edi], mm0\r
90 movq QWORD PTR ds:[edi+8], mm0\r
91 movq QWORD PTR ds:[edi+16], mm0\r
92 movq QWORD PTR ds:[edi+24], mm0\r
93 movq QWORD PTR ds:[edi+32], mm0\r
94 movq QWORD PTR ds:[edi+40], mm0\r
95 movq QWORD PTR ds:[edi+48], mm0\r
96 movq QWORD PTR ds:[edi+56], mm0\r
97 \r
98 add edi, 64\r
99 dec ecx\r
100 jnz _B\r
101 \r
102; Restore mm0\r
103 movq mm0, MmxSave\r
104 emms ; Exit MMX Instruction\r
105\r
106_ZeroRemaining:\r
107 ; Zero out as many DWORDS as possible\r
108 mov ecx, edx\r
109 shr ecx, 2\r
110 xor eax, eax\r
111\r
112 rep stosd\r
113\r
114 ; Zero out remaining as bytes\r
115 mov ecx, edx\r
116 and ecx, 03\r
117\r
118 rep stosb\r
119 \r
120_ZeroMemDone:\r
121 }\r
122}\r