]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/BaseMemoryLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / BaseMemoryLib.h
CommitLineData
fb3df220 1/** @file\r
d80b2f71 2 Provides copy memory, fill memory, zero memory, and GUID functions.\r
9095d37b
LG
3\r
4 The Base Memory Library provides optimized implementations for common memory-based operations.\r
5 These functions should be used in place of coding your own loops to do equivalent common functions.\r
6 This allows optimized library implementations to help increase performance.\r
7\r
8Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 9SPDX-License-Identifier: BSD-2-Clause-Patent\r
fb3df220 10\r
fb3df220 11**/\r
12\r
13#ifndef __BASE_MEMORY_LIB__\r
14#define __BASE_MEMORY_LIB__\r
15\r
16/**\r
17 Copies a source buffer to a destination buffer, and returns the destination buffer.\r
18\r
19 This function copies Length bytes from SourceBuffer to DestinationBuffer, and returns\r
20 DestinationBuffer. The implementation must be reentrant, and it must handle the case\r
21 where SourceBuffer overlaps DestinationBuffer.\r
9095d37b 22\r
8693ca5d 23 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r
24 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
fb3df220 25\r
af2dc6a7 26 @param DestinationBuffer The pointer to the destination buffer of the memory copy.\r
27 @param SourceBuffer The pointer to the source buffer of the memory copy.\r
28 @param Length The number of bytes to copy from SourceBuffer to DestinationBuffer.\r
fb3df220 29\r
30 @return DestinationBuffer.\r
31\r
32**/\r
33VOID *\r
34EFIAPI\r
35CopyMem (\r
36 OUT VOID *DestinationBuffer,\r
37 IN CONST VOID *SourceBuffer,\r
38 IN UINTN Length\r
39 );\r
40\r
41/**\r
42 Fills a target buffer with a byte value, and returns the target buffer.\r
43\r
44 This function fills Length bytes of Buffer with Value, and returns Buffer.\r
9095d37b 45\r
cc4e0485 46 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 47\r
af2dc6a7 48 @param Buffer The memory to set.\r
49 @param Length The number of bytes to set.\r
50 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 51\r
52 @return Buffer.\r
53\r
54**/\r
55VOID *\r
56EFIAPI\r
57SetMem (\r
58 OUT VOID *Buffer,\r
59 IN UINTN Length,\r
60 IN UINT8 Value\r
61 );\r
62\r
63/**\r
64 Fills a target buffer with a 16-bit value, and returns the target buffer.\r
65\r
66 This function fills Length bytes of Buffer with the 16-bit value specified by\r
67 Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
68 bytes of Buffer.\r
69\r
70 If Length > 0 and Buffer is NULL, then ASSERT().\r
71 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
72 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
73 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
74\r
af2dc6a7 75 @param Buffer The pointer to the target buffer to fill.\r
76 @param Length The number of bytes in Buffer to fill.\r
77 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 78\r
79 @return Buffer.\r
80\r
81**/\r
82VOID *\r
83EFIAPI\r
84SetMem16 (\r
85 OUT VOID *Buffer,\r
86 IN UINTN Length,\r
87 IN UINT16 Value\r
88 );\r
89\r
90/**\r
91 Fills a target buffer with a 32-bit value, and returns the target buffer.\r
92\r
93 This function fills Length bytes of Buffer with the 32-bit value specified by\r
94 Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
95 bytes of Buffer.\r
96\r
97 If Length > 0 and Buffer is NULL, then ASSERT().\r
98 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
99 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
100 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
101\r
af2dc6a7 102 @param Buffer The pointer to the target buffer to fill.\r
103 @param Length The number of bytes in Buffer to fill.\r
104 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 105\r
106 @return Buffer.\r
107\r
108**/\r
109VOID *\r
110EFIAPI\r
111SetMem32 (\r
112 OUT VOID *Buffer,\r
113 IN UINTN Length,\r
114 IN UINT32 Value\r
115 );\r
116\r
117/**\r
118 Fills a target buffer with a 64-bit value, and returns the target buffer.\r
119\r
120 This function fills Length bytes of Buffer with the 64-bit value specified by\r
121 Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
122 bytes of Buffer.\r
123\r
124 If Length > 0 and Buffer is NULL, then ASSERT().\r
125 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
126 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
127 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
128\r
af2dc6a7 129 @param Buffer The pointer to the target buffer to fill.\r
130 @param Length The number of bytes in Buffer to fill.\r
131 @param Value The value with which to fill Length bytes of Buffer.\r
fb3df220 132\r
133 @return Buffer.\r
134\r
135**/\r
136VOID *\r
137EFIAPI\r
138SetMem64 (\r
139 OUT VOID *Buffer,\r
140 IN UINTN Length,\r
141 IN UINT64 Value\r
142 );\r
143\r
f7753a96 144/**\r
145 Fills a target buffer with a value that is size UINTN, and returns the target buffer.\r
146\r
147 This function fills Length bytes of Buffer with the UINTN sized value specified by\r
148 Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length\r
149 bytes of Buffer.\r
150\r
151 If Length > 0 and Buffer is NULL, then ASSERT().\r
152 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
153 If Buffer is not aligned on a UINTN boundary, then ASSERT().\r
154 If Length is not aligned on a UINTN boundary, then ASSERT().\r
155\r
af2dc6a7 156 @param Buffer The pointer to the target buffer to fill.\r
157 @param Length The number of bytes in Buffer to fill.\r
158 @param Value The value with which to fill Length bytes of Buffer.\r
f7753a96 159\r
160 @return Buffer.\r
161\r
162**/\r
163VOID *\r
164EFIAPI\r
165SetMemN (\r
166 OUT VOID *Buffer,\r
167 IN UINTN Length,\r
168 IN UINTN Value\r
169 );\r
170\r
fb3df220 171/**\r
172 Fills a target buffer with zeros, and returns the target buffer.\r
173\r
174 This function fills Length bytes of Buffer with zeros, and returns Buffer.\r
9095d37b 175\r
fb3df220 176 If Length > 0 and Buffer is NULL, then ASSERT().\r
cc4e0485 177 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 178\r
af2dc6a7 179 @param Buffer The pointer to the target buffer to fill with zeros.\r
180 @param Length The number of bytes in Buffer to fill with zeros.\r
fb3df220 181\r
182 @return Buffer.\r
183\r
184**/\r
185VOID *\r
186EFIAPI\r
187ZeroMem (\r
188 OUT VOID *Buffer,\r
189 IN UINTN Length\r
190 );\r
191\r
192/**\r
193 Compares the contents of two buffers.\r
194\r
195 This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer.\r
196 If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the\r
197 value returned is the first mismatched byte in SourceBuffer subtracted from the first\r
198 mismatched byte in DestinationBuffer.\r
9095d37b 199\r
2bfb6009
LG
200 If Length > 0 and DestinationBuffer is NULL, then ASSERT().\r
201 If Length > 0 and SourceBuffer is NULL, then ASSERT().\r
8693ca5d 202 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT().\r
203 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
fb3df220 204\r
af2dc6a7 205 @param DestinationBuffer The pointer to the destination buffer to compare.\r
206 @param SourceBuffer The pointer to the source buffer to compare.\r
207 @param Length The number of bytes to compare.\r
fb3df220 208\r
209 @return 0 All Length bytes of the two buffers are identical.\r
210 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first\r
211 mismatched byte in DestinationBuffer.\r
9095d37b 212\r
fb3df220 213**/\r
214INTN\r
215EFIAPI\r
216CompareMem (\r
217 IN CONST VOID *DestinationBuffer,\r
218 IN CONST VOID *SourceBuffer,\r
219 IN UINTN Length\r
220 );\r
221\r
222/**\r
223 Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value\r
224 in the target buffer.\r
225\r
226 This function searches target the buffer specified by Buffer and Length from the lowest\r
227 address to the highest address for an 8-bit value that matches Value. If a match is found,\r
228 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
229 then NULL is returned. If Length is 0, then NULL is returned.\r
9095d37b 230\r
fb3df220 231 If Length > 0 and Buffer is NULL, then ASSERT().\r
cc4e0485 232 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 233\r
af2dc6a7 234 @param Buffer The pointer to the target buffer to scan.\r
235 @param Length The number of bytes in Buffer to scan.\r
236 @param Value The value to search for in the target buffer.\r
fb3df220 237\r
af2dc6a7 238 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 239\r
240**/\r
241VOID *\r
242EFIAPI\r
243ScanMem8 (\r
244 IN CONST VOID *Buffer,\r
245 IN UINTN Length,\r
246 IN UINT8 Value\r
247 );\r
248\r
249/**\r
250 Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value\r
251 in the target buffer.\r
252\r
253 This function searches target the buffer specified by Buffer and Length from the lowest\r
254 address to the highest address for a 16-bit value that matches Value. If a match is found,\r
255 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
256 then NULL is returned. If Length is 0, then NULL is returned.\r
9095d37b 257\r
fb3df220 258 If Length > 0 and Buffer is NULL, then ASSERT().\r
259 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
260 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
cc4e0485 261 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 262\r
af2dc6a7 263 @param Buffer The pointer to the target buffer to scan.\r
264 @param Length The number of bytes in Buffer to scan.\r
265 @param Value The value to search for in the target buffer.\r
fb3df220 266\r
af2dc6a7 267 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 268\r
269**/\r
270VOID *\r
271EFIAPI\r
272ScanMem16 (\r
273 IN CONST VOID *Buffer,\r
274 IN UINTN Length,\r
275 IN UINT16 Value\r
276 );\r
277\r
278/**\r
279 Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value\r
280 in the target buffer.\r
281\r
282 This function searches target the buffer specified by Buffer and Length from the lowest\r
283 address to the highest address for a 32-bit value that matches Value. If a match is found,\r
284 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
285 then NULL is returned. If Length is 0, then NULL is returned.\r
9095d37b 286\r
fb3df220 287 If Length > 0 and Buffer is NULL, then ASSERT().\r
288 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
289 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
cc4e0485 290 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 291\r
af2dc6a7 292 @param Buffer The pointer to the target buffer to scan.\r
293 @param Length The number of bytes in Buffer to scan.\r
294 @param Value The value to search for in the target buffer.\r
fb3df220 295\r
af2dc6a7 296 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 297\r
298**/\r
299VOID *\r
300EFIAPI\r
301ScanMem32 (\r
302 IN CONST VOID *Buffer,\r
303 IN UINTN Length,\r
304 IN UINT32 Value\r
305 );\r
306\r
307/**\r
308 Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value\r
309 in the target buffer.\r
310\r
311 This function searches target the buffer specified by Buffer and Length from the lowest\r
312 address to the highest address for a 64-bit value that matches Value. If a match is found,\r
313 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
314 then NULL is returned. If Length is 0, then NULL is returned.\r
9095d37b 315\r
fb3df220 316 If Length > 0 and Buffer is NULL, then ASSERT().\r
317 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
318 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
cc4e0485 319 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 320\r
af2dc6a7 321 @param Buffer The pointer to the target buffer to scan.\r
322 @param Length The number of bytes in Buffer to scan.\r
323 @param Value The value to search for in the target buffer.\r
fb3df220 324\r
af2dc6a7 325 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
fb3df220 326\r
327**/\r
328VOID *\r
329EFIAPI\r
330ScanMem64 (\r
331 IN CONST VOID *Buffer,\r
332 IN UINTN Length,\r
333 IN UINT64 Value\r
334 );\r
335\r
f7753a96 336/**\r
9095d37b 337 Scans a target buffer for a UINTN sized value, and returns a pointer to the matching\r
f7753a96 338 UINTN sized value in the target buffer.\r
339\r
340 This function searches target the buffer specified by Buffer and Length from the lowest\r
341 address to the highest address for a UINTN sized value that matches Value. If a match is found,\r
342 then a pointer to the matching byte in the target buffer is returned. If no match is found,\r
343 then NULL is returned. If Length is 0, then NULL is returned.\r
9095d37b 344\r
f7753a96 345 If Length > 0 and Buffer is NULL, then ASSERT().\r
346 If Buffer is not aligned on a UINTN boundary, then ASSERT().\r
347 If Length is not aligned on a UINTN boundary, then ASSERT().\r
348 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
349\r
af2dc6a7 350 @param Buffer The pointer to the target buffer to scan.\r
351 @param Length The number of bytes in Buffer to scan.\r
352 @param Value The value to search for in the target buffer.\r
f7753a96 353\r
af2dc6a7 354 @return A pointer to the matching byte in the target buffer, otherwise NULL.\r
f7753a96 355\r
356**/\r
357VOID *\r
358EFIAPI\r
359ScanMemN (\r
360 IN CONST VOID *Buffer,\r
361 IN UINTN Length,\r
362 IN UINTN Value\r
363 );\r
9095d37b 364\r
fb3df220 365/**\r
366 Copies a source GUID to a destination GUID.\r
367\r
368 This function copies the contents of the 128-bit GUID specified by SourceGuid to\r
369 DestinationGuid, and returns DestinationGuid.\r
9095d37b 370\r
fb3df220 371 If DestinationGuid is NULL, then ASSERT().\r
372 If SourceGuid is NULL, then ASSERT().\r
373\r
af2dc6a7 374 @param DestinationGuid The pointer to the destination GUID.\r
375 @param SourceGuid The pointer to the source GUID.\r
fb3df220 376\r
377 @return DestinationGuid.\r
378\r
379**/\r
380GUID *\r
381EFIAPI\r
382CopyGuid (\r
383 OUT GUID *DestinationGuid,\r
384 IN CONST GUID *SourceGuid\r
385 );\r
386\r
387/**\r
388 Compares two GUIDs.\r
389\r
390 This function compares Guid1 to Guid2. If the GUIDs are identical then TRUE is returned.\r
391 If there are any bit differences in the two GUIDs, then FALSE is returned.\r
9095d37b 392\r
fb3df220 393 If Guid1 is NULL, then ASSERT().\r
394 If Guid2 is NULL, then ASSERT().\r
395\r
396 @param Guid1 A pointer to a 128 bit GUID.\r
397 @param Guid2 A pointer to a 128 bit GUID.\r
398\r
399 @retval TRUE Guid1 and Guid2 are identical.\r
400 @retval FALSE Guid1 and Guid2 are not identical.\r
401\r
402**/\r
403BOOLEAN\r
404EFIAPI\r
405CompareGuid (\r
406 IN CONST GUID *Guid1,\r
407 IN CONST GUID *Guid2\r
408 );\r
409\r
410/**\r
411 Scans a target buffer for a GUID, and returns a pointer to the matching GUID\r
412 in the target buffer.\r
413\r
414 This function searches target the buffer specified by Buffer and Length from\r
415 the lowest address to the highest address at 128-bit increments for the 128-bit\r
416 GUID value that matches Guid. If a match is found, then a pointer to the matching\r
417 GUID in the target buffer is returned. If no match is found, then NULL is returned.\r
418 If Length is 0, then NULL is returned.\r
9095d37b 419\r
fb3df220 420 If Length > 0 and Buffer is NULL, then ASSERT().\r
421 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
422 If Length is not aligned on a 128-bit boundary, then ASSERT().\r
cc4e0485 423 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
fb3df220 424\r
af2dc6a7 425 @param Buffer The pointer to the target buffer to scan.\r
426 @param Length The number of bytes in Buffer to scan.\r
427 @param Guid The value to search for in the target buffer.\r
fb3df220 428\r
af2dc6a7 429 @return A pointer to the matching Guid in the target buffer, otherwise NULL.\r
fb3df220 430\r
431**/\r
432VOID *\r
433EFIAPI\r
434ScanGuid (\r
435 IN CONST VOID *Buffer,\r
436 IN UINTN Length,\r
437 IN CONST GUID *Guid\r
438 );\r
439\r
313831d9
HW
440/**\r
441 Checks if the given GUID is a zero GUID.\r
442\r
443 This function checks whether the given GUID is a zero GUID. If the GUID is\r
444 identical to a zero GUID then TRUE is returned. Otherwise, FALSE is returned.\r
445\r
446 If Guid is NULL, then ASSERT().\r
447\r
448 @param Guid The pointer to a 128 bit GUID.\r
449\r
450 @retval TRUE Guid is a zero GUID.\r
451 @retval FALSE Guid is not a zero GUID.\r
452\r
453**/\r
454BOOLEAN\r
455EFIAPI\r
456IsZeroGuid (\r
457 IN CONST GUID *Guid\r
458 );\r
459\r
1944b02b
HW
460/**\r
461 Checks if the contents of a buffer are all zeros.\r
462\r
463 This function checks whether the contents of a buffer are all zeros. If the\r
464 contents are all zeros, return TRUE. Otherwise, return FALSE.\r
465\r
466 If Length > 0 and Buffer is NULL, then ASSERT().\r
467 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
468\r
469 @param Buffer The pointer to the buffer to be checked.\r
470 @param Length The size of the buffer (in bytes) to be checked.\r
471\r
472 @retval TRUE Contents of the buffer are all zeros.\r
473 @retval FALSE Contents of the buffer are not all zeros.\r
474\r
475**/\r
476BOOLEAN\r
477EFIAPI\r
478IsZeroBuffer (\r
479 IN CONST VOID *Buffer,\r
480 IN UINTN Length\r
481 );\r
482\r
fb3df220 483#endif\r