]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLib / MemLibGeneric.c
1 /** @file
2 Architecture Independent Base Memory Library Implementation.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 The following BaseMemoryLib instances share the same version of this file:
14
15 BaseMemoryLib
16 PeiMemoryLib
17 DxeMemoryLib
18
19 **/
20
21
22
23
24 #include "MemLibInternals.h"
25
26 /**
27 Fills a target buffer with a 16-bit value, and returns the target buffer.
28
29 @param Buffer Pointer to the target buffer to fill.
30 @param Length Number of bytes in Buffer to fill.
31 @param Value Value with which to fill Length bytes of Buffer.
32
33 @return Buffer
34
35 **/
36 VOID *
37 EFIAPI
38 InternalMemSetMem16 (
39 OUT VOID *Buffer,
40 IN UINTN Length,
41 IN UINT16 Value
42 )
43 {
44 do {
45 ((UINT16*)Buffer)[--Length] = Value;
46 } while (Length != 0);
47 return Buffer;
48 }
49
50 /**
51 Fills a target buffer with a 32-bit value, and returns the target buffer.
52
53 @param Buffer Pointer to the target buffer to fill.
54 @param Length Number of bytes in Buffer to fill.
55 @param Value Value with which to fill Length bytes of Buffer.
56
57 @return Buffer
58
59 **/
60 VOID *
61 EFIAPI
62 InternalMemSetMem32 (
63 OUT VOID *Buffer,
64 IN UINTN Length,
65 IN UINT32 Value
66 )
67 {
68 do {
69 ((UINT32*)Buffer)[--Length] = Value;
70 } while (Length != 0);
71 return Buffer;
72 }
73
74 /**
75 Fills a target buffer with a 64-bit value, and returns the target buffer.
76
77 @param Buffer Pointer to the target buffer to fill.
78 @param Length Number of bytes in Buffer to fill.
79 @param Value Value with which to fill Length bytes of Buffer.
80
81 @return Buffer
82
83 **/
84 VOID *
85 EFIAPI
86 InternalMemSetMem64 (
87 OUT VOID *Buffer,
88 IN UINTN Length,
89 IN UINT64 Value
90 )
91 {
92 do {
93 ((UINT64*)Buffer)[--Length] = Value;
94 } while (Length != 0);
95 return Buffer;
96 }
97
98 /**
99 Set Buffer to 0 for Size bytes.
100
101 @param Buffer Memory to set.
102 @param Length Number of bytes to set
103
104 @return Buffer
105
106 **/
107 VOID *
108 EFIAPI
109 InternalMemZeroMem (
110 OUT VOID *Buffer,
111 IN UINTN Length
112 )
113 {
114 return InternalMemSetMem (Buffer, Length, 0);
115 }
116
117 /**
118 Compares two memory buffers of a given length.
119
120 @param DestinationBuffer First memory buffer
121 @param SourceBuffer Second memory buffer
122 @param Length Length of DestinationBuffer and SourceBuffer memory
123 regions to compare. Must be non-zero.
124
125 @retval 0 if MemOne == MemTwo
126
127 **/
128 INTN
129 EFIAPI
130 InternalMemCompareMem (
131 IN CONST VOID *DestinationBuffer,
132 IN CONST VOID *SourceBuffer,
133 IN UINTN Length
134 )
135 {
136 while ((--Length != 0) &&
137 (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {
138 DestinationBuffer = (INT8*)DestinationBuffer + 1;
139 SourceBuffer = (INT8*)SourceBuffer + 1;
140 }
141 return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer;
142 }
143
144 /**
145 Scans a target buffer for an 8-bit value, and returns a pointer to the
146 matching 8-bit value in the target buffer.
147
148 @param Buffer Pointer to the target buffer to scan.
149 @param Length Number of bytes in Buffer to scan. Must be non-zero.
150 @param Value Value to search for in the target buffer.
151
152 @return Pointer to the first occurrence or NULL if not found.
153
154 **/
155 CONST VOID *
156 EFIAPI
157 InternalMemScanMem8 (
158 IN CONST VOID *Buffer,
159 IN UINTN Length,
160 IN UINT8 Value
161 )
162 {
163 CONST UINT8 *Pointer;
164
165 Pointer = (CONST UINT8*)Buffer;
166 do {
167 if (*(Pointer++) == Value) {
168 return Pointer;
169 }
170 } while (--Length != 0);
171 return NULL;
172 }
173
174 /**
175 Scans a target buffer for a 16-bit value, and returns a pointer to the
176 matching 16-bit value in the target buffer.
177
178 @param Buffer Pointer to the target buffer to scan.
179 @param Length Number of bytes in Buffer to scan. Must be non-zero.
180 @param Value Value to search for in the target buffer.
181
182 @return Pointer to the first occurrence or NULL if not found.
183
184 **/
185 CONST VOID *
186 EFIAPI
187 InternalMemScanMem16 (
188 IN CONST VOID *Buffer,
189 IN UINTN Length,
190 IN UINT16 Value
191 )
192 {
193 CONST UINT16 *Pointer;
194
195 Pointer = (CONST UINT16*)Buffer;
196 do {
197 if (*(Pointer++) == Value) {
198 return Pointer;
199 }
200 } while (--Length != 0);
201 return NULL;
202 }
203
204 /**
205 Scans a target buffer for a 32-bit value, and returns a pointer to the
206 matching 32-bit value in the target buffer.
207
208 @param Buffer Pointer to the target buffer to scan.
209 @param Length Number of bytes in Buffer to scan. Must be non-zero.
210 @param Value Value to search for in the target buffer.
211
212 @return Pointer to the first occurrence or NULL if not found.
213
214 **/
215 CONST VOID *
216 EFIAPI
217 InternalMemScanMem32 (
218 IN CONST VOID *Buffer,
219 IN UINTN Length,
220 IN UINT32 Value
221 )
222 {
223 CONST UINT32 *Pointer;
224
225 Pointer = (CONST UINT32*)Buffer;
226 do {
227 if (*(Pointer++) == Value) {
228 return Pointer;
229 }
230 } while (--Length != 0);
231 return NULL;
232 }
233
234 /**
235 Scans a target buffer for a 64-bit value, and returns a pointer to the
236 matching 64-bit value in the target buffer.
237
238 @param Buffer Pointer to the target buffer to scan.
239 @param Length Number of bytes in Buffer to scan. Must be non-zero.
240 @param Value Value to search for in the target buffer.
241
242 @return Pointer to the first occurrence or NULL if not found.
243
244 **/
245 CONST VOID *
246 EFIAPI
247 InternalMemScanMem64 (
248 IN CONST VOID *Buffer,
249 IN UINTN Length,
250 IN UINT64 Value
251 )
252 {
253 CONST UINT64 *Pointer;
254
255 Pointer = (CONST UINT64*)Buffer;
256 do {
257 if (*(Pointer++) == Value) {
258 return Pointer;
259 }
260 } while (--Length != 0);
261 return NULL;
262 }