]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EfiCommonLib/Ia32/EfiZeroMem.S
Maintainers.txt: Remove EdkCompatibilityPkg information
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EfiCommonLib / Ia32 / EfiZeroMem.S
CommitLineData
b341712e 1#/*++\r
2#\r
4ea9375a
HT
3#Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
4#This program and the accompanying materials \r
b341712e 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#include "EfiBind.h"\r
22#---------------------------------------------------------------------------\r
23 .686: \r
24 #.MODEL flat,C\r
25 .mmx: \r
26 .code: \r
27\r
28#---------------------------------------------------------------------------\r
29.globl ASM_PFX(EfiCommonLibZeroMem)\r
30#VOID\r
31#EfiCommonLibZeroMem (\r
32# IN VOID *Buffer,\r
33# IN UINTN Count\r
34# )\r
35#/*++\r
36#\r
37#Input: VOID *Buffer - Pointer to buffer to clear\r
38# UINTN Count - Number of bytes to clear\r
39#\r
40#Output: None.\r
41#\r
42#Saves:\r
43#\r
44#Modifies:\r
45#\r
46#Description: This function is an optimized zero-memory function.\r
47#\r
48#Notes: This function tries to zero memory 8 bytes at a time. As a result, \r
49# it first picks up any misaligned bytes, then words, before getting \r
50# in the main loop that does the 8-byte clears.\r
51#\r
52#--*/\r
53ASM_PFX(EfiCommonLibZeroMem):\r
54# UINT64 MmxSave;\r
55 pushl %ebp\r
56 movl %esp, %ebp\r
57 pushl %ecx # Reserve space for local variable MmxSave\r
58 pushl %ecx\r
59 pushl %edi\r
60\r
61 movl 0xC(%ebp), %ecx # Count\r
62 movl 8(%ebp), %edi # Buffer\r
63\r
64 # Pick up misaligned start bytes (get pointer 4-byte aligned)\r
65_StartByteZero: \r
66 movl %edi, %eax\r
67 andb $3, %al # check lower 2 bits of address\r
68 testb %al, %al\r
69 je _ZeroBlocks # already aligned?\r
70 cmpl $0, %ecx\r
71 je _ZeroMemDone\r
72\r
73 # Clear the byte memory location\r
74 movb $0, (%edi)\r
75 incl %edi\r
76\r
77 # Decrement our count\r
78 decl %ecx\r
79 jmp _StartByteZero # back to top of loop\r
80\r
81_ZeroBlocks: \r
82\r
83 # Compute how many 64-byte blocks we can clear \r
84 movl %ecx, %edx\r
85 shrl $6, %ecx # convert to 64-byte count\r
86 shll $6, %ecx # convert back to bytes\r
87 subl %ecx, %edx # subtract from the original count\r
88 shrl $6, %ecx # and this is how many 64-byte blocks\r
89\r
90 # If no 64-byte blocks, then skip \r
91 cmpl $0, %ecx\r
92 je _ZeroRemaining\r
93\r
94 # Save mm0\r
95 movq %mm0, -8(%ebp) # Save mm0 to MmxSave\r
96\r
97 pxor %mm0, %mm0 # Clear mm0\r
98\r
99_B: \r
100 movq %mm0, %ds:(%edi)\r
101 movq %mm0, %ds:8(%edi)\r
102 movq %mm0, %ds:16(%edi)\r
103 movq %mm0, %ds:24(%edi)\r
104 movq %mm0, %ds:32(%edi)\r
105 movq %mm0, %ds:40(%edi)\r
106 movq %mm0, %ds:48(%edi)\r
107 movq %mm0, %ds:56(%edi)\r
108\r
109 addl $64, %edi\r
110 decl %ecx\r
111 jnz _B\r
112\r
113# Restore mm0\r
114 movq -8(%ebp), %mm0 # Restore mm0 from MmxSave\r
115 emms # Exit MMX Instruction\r
116\r
117_ZeroRemaining: \r
118 # Zero out as many DWORDS as possible\r
119 movl %edx, %ecx\r
120 shrl $2, %ecx\r
121 xorl %eax, %eax\r
122\r
123 rep\r
124 stosl\r
125\r
126 # Zero out remaining as bytes\r
127 movl %edx, %ecx\r
128 andl $03, %ecx\r
129\r
130 rep\r
131 stosb\r
132\r
133_ZeroMemDone: \r
134\r
135 popl %edi\r
136 leave\r
137 ret\r
138#EfiCommonLibZeroMem ENDP\r
139\r