]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseMemoryLibSse2/MemLibWrapper.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / BaseMemoryLibSse2 / MemLibWrapper.c
CommitLineData
878ddf1f 1/** @file\r
2 Wrapper functions for Base Memory Library.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 Module Name: MemLibWrapper.c\r
14\r
15 The following BaseMemoryLib instances share the same version of this file:\r
16\r
17 BaseMemoryLib\r
18 BaseMemoryLibMmx\r
19 BaseMemoryLibSse2\r
20 BaseMemoryLibRepStr\r
21 PeiMemoryLib\r
22 UefiMemoryLib\r
23\r
24**/\r
25\r
26/**\r
27 Copy Length bytes from Source to Destination.\r
28\r
29 @param Destination Target of copy\r
30 @param Source Place to copy from\r
31 @param Length Number of bytes to copy\r
32\r
33 @return Destination\r
34\r
35**/\r
36VOID *\r
37EFIAPI\r
38InternalMemCopyMem (\r
39 OUT VOID *DestinationBuffer,\r
40 IN CONST VOID *SourceBuffer,\r
41 IN UINTN Length\r
42 );\r
43\r
44/**\r
45 Set Buffer to Value for Size bytes.\r
46\r
47 @param Buffer Memory to set.\r
48 @param Size Number of bytes to set\r
49 @param Value Value of the set operation.\r
50\r
51 @return Buffer\r
52\r
53**/\r
54VOID *\r
55EFIAPI\r
56InternalMemSetMem (\r
57 OUT VOID *Buffer,\r
58 IN UINTN Length,\r
59 IN UINT8 Value\r
60 );\r
61\r
62/**\r
63 Fills a target buffer with a 16-bit value, and returns the target buffer.\r
64\r
65 @param Buffer Pointer to the target buffer to fill.\r
66 @param Length Number of bytes in Buffer to fill.\r
67 @param Value Value with which to fill Length bytes of Buffer.\r
68\r
69 @return Buffer\r
70\r
71**/\r
72VOID *\r
73EFIAPI\r
74InternalMemSetMem16 (\r
75 OUT VOID *Buffer,\r
76 IN UINTN Length,\r
77 IN UINT16 Value\r
78 );\r
79\r
80/**\r
81 Fills a target buffer with a 32-bit value, and returns the target buffer.\r
82\r
83 @param Buffer Pointer to the target buffer to fill.\r
84 @param Length Number of bytes in Buffer to fill.\r
85 @param Value Value with which to fill Length bytes of Buffer.\r
86\r
87 @return Buffer\r
88\r
89**/\r
90VOID *\r
91EFIAPI\r
92InternalMemSetMem32 (\r
93 OUT VOID *Buffer,\r
94 IN UINTN Length,\r
95 IN UINT32 Value\r
96 );\r
97\r
98/**\r
99 Fills a target buffer with a 64-bit value, and returns the target buffer.\r
100\r
101 @param Buffer Pointer to the target buffer to fill.\r
102 @param Length Number of bytes in Buffer to fill.\r
103 @param Value Value with which to fill Length bytes of Buffer.\r
104\r
105 @return Buffer\r
106\r
107**/\r
108VOID *\r
109EFIAPI\r
110InternalMemSetMem64 (\r
111 OUT VOID *Buffer,\r
112 IN UINTN Length,\r
113 IN UINT64 Value\r
114 );\r
115\r
116/**\r
117 Set Buffer to 0 for Size bytes.\r
118\r
119 @param Buffer Memory to set.\r
120 @param Size Number of bytes to set\r
121\r
122 @return Buffer\r
123\r
124**/\r
125VOID *\r
126EFIAPI\r
127InternalMemZeroMem (\r
128 OUT VOID *Buffer,\r
129 IN UINTN Length\r
130 );\r
131\r
132/**\r
133 Compares two memory buffers of a given length.\r
134\r
135 @param DestinationBuffer First memory buffer\r
136 @param SourceBuffer Second memory buffer\r
137 @param Length Length of DestinationBuffer and SourceBuffer memory\r
138 regions to compare. Must be non-zero.\r
139\r
140 @retval 0 if MemOne == MemTwo\r
141\r
142**/\r
143INTN\r
144EFIAPI\r
145InternalMemCompareMem (\r
146 IN CONST VOID *DestinationBuffer,\r
147 IN CONST VOID *SourceBuffer,\r
148 IN UINTN Length\r
149 );\r
150\r
151/**\r
152 Scans a target buffer for an 8-bit value, and returns a pointer to the\r
153 matching 8-bit value in the target buffer.\r
154\r
155 @param Buffer Pointer to the target buffer to scan.\r
156 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
157 @param Value Value to search for in the target buffer.\r
158\r
159 @return Pointer to the first occurrence or NULL if not found.\r
160\r
161**/\r
162CONST VOID *\r
163EFIAPI\r
164InternalMemScanMem8 (\r
165 IN CONST VOID *Buffer,\r
166 IN UINTN Length,\r
167 IN UINT8 Value\r
168 );\r
169\r
170/**\r
171 Scans a target buffer for a 16-bit value, and returns a pointer to the\r
172 matching 16-bit value in the target buffer.\r
173\r
174 @param Buffer Pointer to the target buffer to scan.\r
175 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
176 @param Value Value to search for in the target buffer.\r
177\r
178 @return Pointer to the first occurrence or NULL if not found.\r
179\r
180**/\r
181CONST VOID *\r
182EFIAPI\r
183InternalMemScanMem16 (\r
184 IN CONST VOID *Buffer,\r
185 IN UINTN Length,\r
186 IN UINT16 Value\r
187 );\r
188\r
189/**\r
190 Scans a target buffer for a 32-bit value, and returns a pointer to the\r
191 matching 32-bit value in the target buffer.\r
192\r
193 @param Buffer Pointer to the target buffer to scan.\r
194 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
195 @param Value Value to search for in the target buffer.\r
196\r
197 @return Pointer to the first occurrence or NULL if not found.\r
198\r
199**/\r
200CONST VOID *\r
201EFIAPI\r
202InternalMemScanMem32 (\r
203 IN CONST VOID *Buffer,\r
204 IN UINTN Length,\r
205 IN UINT32 Value\r
206 );\r
207\r
208/**\r
209 Scans a target buffer for a 64-bit value, and returns a pointer to the\r
210 matching 64-bit value in the target buffer.\r
211\r
212 @param Buffer Pointer to the target buffer to scan.\r
213 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
214 @param Value Value to search for in the target buffer.\r
215\r
216 @return Pointer to the first occurrence or NULL if not found.\r
217\r
218**/\r
219CONST VOID *\r
220EFIAPI\r
221InternalMemScanMem64 (\r
222 IN CONST VOID *Buffer,\r
223 IN UINTN Length,\r
224 IN UINT64 Value\r
225 );\r
226\r
227/**\r
228 Copy Length bytes from Source to Destination.\r
229\r
230 This function copies Length bytes from SourceBuffer to DestinationBuffer, and\r
231 returns DestinationBuffer. The implementation must be reentrant, and it must\r
232 handle the case where SourceBuffer overlaps DestinationBuffer.\r
233\r
234 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
235 ASSERT().\r
236 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
237\r
238 @param Destination Target of copy\r
239 @param Source Place to copy from\r
240 @param Length Number of bytes to copy\r
241\r
242 @return Destination\r
243\r
244**/\r
245VOID *\r
246EFIAPI\r
247CopyMem (\r
248 OUT VOID *Destination,\r
249 IN CONST VOID *Source,\r
250 IN UINTN Length\r
251 )\r
252{\r
253 ASSERT (Length <= MAX_ADDRESS - (UINTN)Destination + 1);\r
254 ASSERT (Length <= MAX_ADDRESS - (UINTN)Source + 1);\r
255 return InternalMemCopyMem (Destination, Source, Length);\r
256}\r
257\r
258/**\r
259 Set Buffer to Value for Size bytes.\r
260\r
261 This function fills Length bytes of Buffer with Value, and returns Buffer.\r
262\r
263 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
264\r
265 @param Buffer Memory to set.\r
266 @param Size Number of bytes to set\r
267 @param Value Value of the set operation.\r
268\r
269 @return Buffer\r
270\r
271**/\r
272VOID *\r
273EFIAPI\r
274SetMem (\r
275 IN VOID *Buffer,\r
276 IN UINTN Size,\r
277 IN UINT8 Value\r
278 )\r
279{\r
280 ASSERT (Size <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
281 return InternalMemSetMem (Buffer, Size, Value);\r
282}\r
283\r
284/**\r
285 Fills a target buffer with a 16-bit value, and returns the target buffer.\r
286\r
287 This function fills Length bytes of Buffer with the 16-bit value specified by\r
288 Value, and returns Buffer. Value is repeated every 16-bits in for Length\r
289 bytes of Buffer.\r
290\r
291 If Buffer is NULL and Length > 0, then ASSERT().\r
292 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
293 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
294 If Length is not aligned on a 16-bit boundary, then ASSERT().\r
295\r
296 @param Buffer Pointer to the target buffer to fill.\r
297 @param Length Number of bytes in Buffer to fill.\r
298 @param Value Value with which to fill Length bytes of Buffer.\r
299\r
300 @return Buffer\r
301\r
302**/\r
303VOID *\r
304EFIAPI\r
305SetMem16 (\r
306 OUT VOID *Buffer,\r
307 IN UINTN Length,\r
308 IN UINT16 Value\r
309 )\r
310{\r
311 ASSERT (Buffer != NULL);\r
312 ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
313 ASSERT ((((UINTN)Buffer) & 1) != 0);\r
314 ASSERT ((Length & 1) != 0);\r
315\r
316 if ((Length /= sizeof (Value)) == 0) {\r
317 return Buffer;\r
318 }\r
319 return InternalMemSetMem16 (Buffer, Length, Value);\r
320}\r
321\r
322/**\r
323 Fills a target buffer with a 32-bit value, and returns the target buffer.\r
324\r
325 This function fills Length bytes of Buffer with the 32-bit value specified by\r
326 Value, and returns Buffer. Value is repeated every 32-bits in for Length\r
327 bytes of Buffer.\r
328\r
329 If Buffer is NULL and Length > 0, then ASSERT().\r
330 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
331 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
332 If Length is not aligned on a 32-bit boundary, then ASSERT().\r
333\r
334 @param Buffer Pointer to the target buffer to fill.\r
335 @param Length Number of bytes in Buffer to fill.\r
336 @param Value Value with which to fill Length bytes of Buffer.\r
337\r
338 @return Buffer\r
339\r
340**/\r
341VOID *\r
342EFIAPI\r
343SetMem32 (\r
344 OUT VOID *Buffer,\r
345 IN UINTN Length,\r
346 IN UINT32 Value\r
347 )\r
348{\r
349 ASSERT (Buffer != NULL);\r
350 ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
351 ASSERT ((((UINTN)Buffer) & 1) != 0);\r
352 ASSERT ((Length & 1) != 0);\r
353\r
354 if ((Length /= sizeof (Value)) == 0) {\r
355 return Buffer;\r
356 }\r
357 return InternalMemSetMem32 (Buffer, Length, Value);\r
358}\r
359\r
360/**\r
361 Fills a target buffer with a 64-bit value, and returns the target buffer.\r
362\r
363 This function fills Length bytes of Buffer with the 64-bit value specified by\r
364 Value, and returns Buffer. Value is repeated every 64-bits in for Length\r
365 bytes of Buffer.\r
366\r
367 If Buffer is NULL and Length > 0, then ASSERT().\r
368 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
369 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
370 If Length is not aligned on a 64-bit boundary, then ASSERT().\r
371\r
372 @param Buffer Pointer to the target buffer to fill.\r
373 @param Length Number of bytes in Buffer to fill.\r
374 @param Value Value with which to fill Length bytes of Buffer.\r
375\r
376 @return Buffer\r
377\r
378**/\r
379VOID *\r
380EFIAPI\r
381SetMem64 (\r
382 OUT VOID *Buffer,\r
383 IN UINTN Length,\r
384 IN UINT64 Value\r
385 )\r
386{\r
387 ASSERT (Buffer != NULL);\r
388 ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1);\r
389 ASSERT ((((UINTN)Buffer) & 1) != 0);\r
390 ASSERT ((Length & 1) != 0);\r
391\r
392 if ((Length /= sizeof (Value)) == 0) {\r
393 return Buffer;\r
394 }\r
395 return InternalMemSetMem64 (Buffer, Length, Value);\r
396}\r
397\r
398/**\r
399 Set Buffer to 0 for Size bytes.\r
400\r
401 This function fills Length bytes of Buffer with zeros, and returns Buffer.\r
402\r
403 If Buffer is NULL and Length > 0, then ASSERT().\r
404 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
405\r
406 @param Buffer Memory to set.\r
407 @param Size Number of bytes to set\r
408\r
409 @return Buffer\r
410\r
411**/\r
412VOID *\r
413EFIAPI\r
414ZeroMem (\r
415 IN VOID *Buffer,\r
416 IN UINTN Size\r
417 )\r
418{\r
419 ASSERT (Buffer != NULL);\r
420 return InternalMemSetMem (Buffer, Size, 0);\r
421}\r
422\r
423/**\r
424 Compares two memory buffers of a given length.\r
425\r
426 This function compares Length bytes of SourceBuffer to Length bytes of\r
427 DestinationBuffer. If all Length bytes of the two buffers are identical, then\r
428 0 is returned. Otherwise, the value returned is the first mismatched byte in\r
429 SourceBuffer subtracted from the first mismatched byte in DestinationBuffer.\r
430\r
431 If DestinationBuffer is NULL and Length > 0, then ASSERT().\r
432 If SourceBuffer is NULL and Length > 0, then ASSERT().\r
433 If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then\r
434 ASSERT().\r
435 If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT().\r
436\r
437 @param DestinationBuffer First memory buffer\r
438 @param SourceBuffer Second memory buffer\r
439 @param Length Length of DestinationBuffer and SourceBuffer memory\r
440 regions to compare\r
441\r
442 @retval 0 if DestinationBuffer == SourceBuffer\r
443 @retval Non-zero if DestinationBuffer != SourceBuffer\r
444\r
445**/\r
446INTN\r
447EFIAPI\r
448CompareMem (\r
449 IN CONST VOID *DestinationBuffer,\r
450 IN CONST VOID *SourceBuffer,\r
451 IN UINTN Length\r
452 )\r
453{\r
454 ASSERT (DestinationBuffer != NULL);\r
455 ASSERT (SourceBuffer != NULL);\r
456 ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1);\r
457 ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1);\r
458 if (Length == 0) {\r
459 return 0;\r
460 }\r
461 return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length);\r
462}\r
463\r
464/**\r
465 Scans a target buffer for an 8-bit value, and returns a pointer to the\r
466 matching 8-bit value in the target buffer.\r
467\r
468 This function searches target the buffer specified by Buffer and Length from\r
469 the lowest address to the highest address for an 8-bit value that matches\r
470 Value. If a match is found, then a pointer to the matching byte in the target\r
471 buffer is returned. If no match is found, then NULL is returned. If Length is\r
472 0, then NULL is returned.\r
473\r
474 If Buffer is NULL, then ASSERT().\r
475 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
476\r
477 @param Buffer Pointer to the target buffer to scan.\r
478 @param Length Number of bytes in Buffer to scan.\r
479 @param Value Value to search for in the target buffer.\r
480\r
481 @return Pointer to the first occurrence or NULL if not found.\r
482 @retval NULL if Length == 0 or Value was not found.\r
483\r
484**/\r
485VOID *\r
486EFIAPI\r
487ScanMem8 (\r
488 IN CONST VOID *Buffer,\r
489 IN UINTN Length,\r
490 IN UINT8 Value\r
491 )\r
492{\r
493 ASSERT (Buffer != NULL);\r
494 ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
495\r
496 if ((Length /= sizeof (Value)) == 0) {\r
497 return NULL;\r
498 }\r
499 return (VOID*)InternalMemScanMem8 (Buffer, Length, Value);\r
500}\r
501\r
502/**\r
503 Scans a target buffer for a 16-bit value, and returns a pointer to the\r
504 matching 16-bit value in the target buffer.\r
505\r
506 This function searches target the buffer specified by Buffer and Length from\r
507 the lowest address to the highest address at 16-bit increments for a 16-bit\r
508 value that matches Value. If a match is found, then a pointer to the matching\r
509 value in the target buffer is returned. If no match is found, then NULL is\r
510 returned. If Length is 0, then NULL is returned.\r
511\r
512 If Buffer is NULL, then ASSERT().\r
513 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
514 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
515\r
516 @param Buffer Pointer to the target buffer to scan.\r
517 @param Length Number of bytes in Buffer to scan.\r
518 @param Value Value to search for in the target buffer.\r
519\r
520 @return Pointer to the first occurrence.\r
521 @retval NULL if Length == 0 or Value was not found.\r
522\r
523**/\r
524VOID *\r
525EFIAPI\r
526ScanMem16 (\r
527 IN CONST VOID *Buffer,\r
528 IN UINTN Length,\r
529 IN UINT16 Value\r
530 )\r
531{\r
532 ASSERT (Buffer != NULL);\r
533 ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
534 ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
535\r
536 if ((Length /= sizeof (Value)) == 0) {\r
537 return NULL;\r
538 }\r
539 return (VOID*)InternalMemScanMem16 (Buffer, Length, Value);\r
540}\r
541\r
542/**\r
543 Scans a target buffer for a 32-bit value, and returns a pointer to the\r
544 matching 32-bit value in the target buffer.\r
545\r
546 This function searches target the buffer specified by Buffer and Length from\r
547 the lowest address to the highest address at 32-bit increments for a 32-bit\r
548 value that matches Value. If a match is found, then a pointer to the matching\r
549 value in the target buffer is returned. If no match is found, then NULL is\r
550 returned. If Length is 0, then NULL is returned.\r
551\r
552 If Buffer is NULL, then ASSERT().\r
553 If Buffer is not aligned on a 32-bit boundary, then ASSERT().\r
554 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
555\r
556 @param Buffer Pointer to the target buffer to scan.\r
557 @param Length Number of bytes in Buffer to scan.\r
558 @param Value Value to search for in the target buffer.\r
559\r
560 @return Pointer to the first occurrence or NULL if not found.\r
561 @retval NULL if Length == 0 or Value was not found.\r
562\r
563**/\r
564VOID *\r
565EFIAPI\r
566ScanMem32 (\r
567 IN CONST VOID *Buffer,\r
568 IN UINTN Length,\r
569 IN UINT32 Value\r
570 )\r
571{\r
572 ASSERT (Buffer != NULL);\r
573 ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
574 ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
575\r
576 if ((Length /= sizeof (Value)) == 0) {\r
577 return NULL;\r
578 }\r
579 return (VOID*)InternalMemScanMem32 (Buffer, Length, Value);\r
580}\r
581\r
582/**\r
583 Scans a target buffer for a 64-bit value, and returns a pointer to the\r
584 matching 64-bit value in the target buffer.\r
585\r
586 This function searches target the buffer specified by Buffer and Length from\r
587 the lowest address to the highest address at 64-bit increments for a 64-bit\r
588 value that matches Value. If a match is found, then a pointer to the matching\r
589 value in the target buffer is returned. If no match is found, then NULL is\r
590 returned. If Length is 0, then NULL is returned.\r
591\r
592 If Buffer is NULL, then ASSERT().\r
593 If Buffer is not aligned on a 64-bit boundary, then ASSERT().\r
594 If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
595\r
596 @param Buffer Pointer to the target buffer to scan.\r
597 @param Length Number of bytes in Buffer to scan.\r
598 @param Value Value to search for in the target buffer.\r
599\r
600 @return Pointer to the first occurrence or NULL if not found.\r
601 @retval NULL if Length == 0 or Value was not found.\r
602\r
603**/\r
604VOID *\r
605EFIAPI\r
606ScanMem64 (\r
607 IN CONST VOID *Buffer,\r
608 IN UINTN Length,\r
609 IN UINT64 Value\r
610 )\r
611{\r
612 ASSERT (Buffer != NULL);\r
613 ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0);\r
614 ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1);\r
615\r
616 if ((Length /= sizeof (Value)) == 0) {\r
617 return NULL;\r
618 }\r
619 return (VOID*)InternalMemScanMem64 (Buffer, Length, Value);\r
620}\r