]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
2 Architecture Independent Base Memory Library Implementation.
4 The following BaseMemoryLib instances contain the same copy of this file:
9 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include "MemLibInternals.h"
17 Fills a target buffer with a 16-bit value, and returns the target buffer.
19 @param Buffer The pointer to the target buffer to fill.
20 @param Length The count of 16-bit value to fill.
21 @param Value The value with which to fill Length bytes of Buffer.
34 for ( ; Length
!= 0; Length
--) {
35 ((UINT16
*)Buffer
)[Length
- 1] = Value
;
42 Fills a target buffer with a 32-bit value, and returns the target buffer.
44 @param Buffer The pointer to the target buffer to fill.
45 @param Length The count of 32-bit value to fill.
46 @param Value The value with which to fill Length bytes of Buffer.
59 for ( ; Length
!= 0; Length
--) {
60 ((UINT32
*)Buffer
)[Length
- 1] = Value
;
67 Fills a target buffer with a 64-bit value, and returns the target buffer.
69 @param Buffer The pointer to the target buffer to fill.
70 @param Length The count of 64-bit value to fill.
71 @param Value The value with which to fill Length bytes of Buffer.
84 for ( ; Length
!= 0; Length
--) {
85 ((UINT64
*)Buffer
)[Length
- 1] = Value
;
92 Set Buffer to 0 for Size bytes.
94 @param Buffer Memory to set.
95 @param Length The number of bytes to set.
107 return InternalMemSetMem (Buffer
, Length
, 0);
111 Compares two memory buffers of a given length.
113 @param DestinationBuffer The first memory buffer.
114 @param SourceBuffer The second memory buffer.
115 @param Length Length of DestinationBuffer and SourceBuffer memory
116 regions to compare. Must be non-zero.
118 @return 0 All Length bytes of the two buffers are identical.
119 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
120 mismatched byte in DestinationBuffer.
125 InternalMemCompareMem (
126 IN CONST VOID
*DestinationBuffer
,
127 IN CONST VOID
*SourceBuffer
,
131 while ((--Length
!= 0) &&
132 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
))
134 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
135 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
138 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
142 Scans a target buffer for an 8-bit value, and returns a pointer to the
143 matching 8-bit value in the target buffer.
145 @param Buffer The pointer to the target buffer to scan.
146 @param Length The count of 8-bit value to scan. Must be non-zero.
147 @param Value The value to search for in the target buffer.
149 @return The pointer to the first occurrence, or NULL if not found.
154 InternalMemScanMem8 (
155 IN CONST VOID
*Buffer
,
160 CONST UINT8
*Pointer
;
162 Pointer
= (CONST UINT8
*)Buffer
;
164 if (*Pointer
== Value
) {
169 } while (--Length
!= 0);
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.
178 @param Buffer The pointer to the target buffer to scan.
179 @param Length The count of 16-bit value to scan. Must be non-zero.
180 @param Value The value to search for in the target buffer.
182 @return The pointer to the first occurrence, or NULL if not found.
187 InternalMemScanMem16 (
188 IN CONST VOID
*Buffer
,
193 CONST UINT16
*Pointer
;
195 Pointer
= (CONST UINT16
*)Buffer
;
197 if (*Pointer
== Value
) {
202 } while (--Length
!= 0);
208 Scans a target buffer for a 32-bit value, and returns a pointer to the
209 matching 32-bit value in the target buffer.
211 @param Buffer The pointer to the target buffer to scan.
212 @param Length The count of 32-bit value to scan. Must be non-zero.
213 @param Value The value to search for in the target buffer.
215 @return The pointer to the first occurrence, or NULL if not found.
220 InternalMemScanMem32 (
221 IN CONST VOID
*Buffer
,
226 CONST UINT32
*Pointer
;
228 Pointer
= (CONST UINT32
*)Buffer
;
230 if (*Pointer
== Value
) {
235 } while (--Length
!= 0);
241 Scans a target buffer for a 64-bit value, and returns a pointer to the
242 matching 64-bit value in the target buffer.
244 @param Buffer The pointer to the target buffer to scan.
245 @param Length The count of 64-bit value to scan. Must be non-zero.
246 @param Value The value to search for in the target buffer.
248 @return The pointer to the first occurrence, or NULL if not found.
253 InternalMemScanMem64 (
254 IN CONST VOID
*Buffer
,
259 CONST UINT64
*Pointer
;
261 Pointer
= (CONST UINT64
*)Buffer
;
263 if (*Pointer
== Value
) {
268 } while (--Length
!= 0);
274 Checks whether the contents of a buffer are all zeros.
276 @param Buffer The pointer to the buffer to be checked.
277 @param Length The size of the buffer (in bytes) to be checked.
279 @retval TRUE Contents of the buffer are all zeros.
280 @retval FALSE Contents of the buffer are not all zeros.
285 InternalMemIsZeroBuffer (
286 IN CONST VOID
*Buffer
,
290 CONST UINT8
*BufferData
;
294 for (Index
= 0; Index
< Length
; Index
++) {
295 if (BufferData
[Index
] != 0) {