]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiMemoryLib/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 The 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
) {
167 } while (--Length
!= 0);
173 Scans a target buffer for a 16-bit value, and returns a pointer to the
174 matching 16-bit value in the target buffer.
176 @param Buffer The pointer to the target buffer to scan.
177 @param Length The count of 16-bit value to scan. Must be non-zero.
178 @param Value The value to search for in the target buffer.
180 @return The pointer to the first occurrence or NULL if not found.
185 InternalMemScanMem16 (
186 IN CONST VOID
*Buffer
,
191 CONST UINT16
*Pointer
;
193 Pointer
= (CONST UINT16
*)Buffer
;
195 if (*(Pointer
++) == Value
) {
198 } while (--Length
!= 0);
204 Scans a target buffer for a 32-bit value, and returns a pointer to the
205 matching 32-bit value in the target buffer.
207 @param Buffer The pointer to the target buffer to scan.
208 @param Length The count of 32-bit value to scan. Must be non-zero.
209 @param Value The value to search for in the target buffer.
211 @return The pointer to the first occurrence or NULL if not found.
216 InternalMemScanMem32 (
217 IN CONST VOID
*Buffer
,
222 CONST UINT32
*Pointer
;
224 Pointer
= (CONST UINT32
*)Buffer
;
226 if (*(Pointer
++) == Value
) {
229 } while (--Length
!= 0);
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.
238 @param Buffer The pointer to the target buffer to scan.
239 @param Length The count of 64-bit value to scan. Must be non-zero.
240 @param Value The value to search for in the target buffer.
242 @return The pointer to the first occurrence or NULL if not found.
247 InternalMemScanMem64 (
248 IN CONST VOID
*Buffer
,
253 CONST UINT64
*Pointer
;
255 Pointer
= (CONST UINT64
*)Buffer
;
257 if (*(Pointer
++) == Value
) {
260 } while (--Length
!= 0);
266 Checks whether the contents of a buffer are all zeros.
268 @param Buffer The pointer to the buffer to be checked.
269 @param Length The size of the buffer (in bytes) to be checked.
271 @retval TRUE Contents of the buffer are all zeros.
272 @retval FALSE Contents of the buffer are not all zeros.
277 InternalMemIsZeroBuffer (
278 IN CONST VOID
*Buffer
,
282 CONST UINT8
*BufferData
;
286 for (Index
= 0; Index
< Length
; Index
++) {
287 if (BufferData
[Index
] != 0) {