]>
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
;
41 Fills a target buffer with a 32-bit value, and returns the target buffer.
43 @param Buffer The pointer to the target buffer to fill.
44 @param Length The count of 32-bit value to fill.
45 @param Value The value with which to fill Length bytes of Buffer.
58 for (; Length
!= 0; Length
--) {
59 ((UINT32
*)Buffer
)[Length
- 1] = Value
;
65 Fills a target buffer with a 64-bit value, and returns the target buffer.
67 @param Buffer The pointer to the target buffer to fill.
68 @param Length The count of 64-bit value to fill.
69 @param Value The value with which to fill Length bytes of Buffer.
82 for (; Length
!= 0; Length
--) {
83 ((UINT64
*)Buffer
)[Length
- 1] = Value
;
89 Set Buffer to 0 for Size bytes.
91 @param Buffer Memory to set.
92 @param Length The number of bytes to set.
104 return InternalMemSetMem (Buffer
, Length
, 0);
108 Compares two memory buffers of a given length.
110 @param DestinationBuffer The first memory buffer.
111 @param SourceBuffer The second memory buffer.
112 @param Length Length of DestinationBuffer and SourceBuffer memory
113 regions to compare. Must be non-zero.
115 @return 0 All Length bytes of the two buffers are identical.
116 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
117 mismatched byte in DestinationBuffer.
122 InternalMemCompareMem (
123 IN CONST VOID
*DestinationBuffer
,
124 IN CONST VOID
*SourceBuffer
,
128 while ((--Length
!= 0) &&
129 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
130 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
131 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
133 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
137 Scans a target buffer for an 8-bit value, and returns a pointer to the
138 matching 8-bit value in the target buffer.
140 @param Buffer The pointer to the target buffer to scan.
141 @param Length The count of 8-bit value to scan. Must be non-zero.
142 @param Value The value to search for in the target buffer.
144 @return The pointer to the first occurrence, or NULL if not found.
149 InternalMemScanMem8 (
150 IN CONST VOID
*Buffer
,
155 CONST UINT8
*Pointer
;
157 Pointer
= (CONST UINT8
*)Buffer
;
159 if (*Pointer
== Value
) {
163 } while (--Length
!= 0);
168 Scans a target buffer for a 16-bit value, and returns a pointer to the
169 matching 16-bit value in the target buffer.
171 @param Buffer The pointer to the target buffer to scan.
172 @param Length The count of 16-bit value to scan. Must be non-zero.
173 @param Value The value to search for in the target buffer.
175 @return The pointer to the first occurrence, or NULL if not found.
180 InternalMemScanMem16 (
181 IN CONST VOID
*Buffer
,
186 CONST UINT16
*Pointer
;
188 Pointer
= (CONST UINT16
*)Buffer
;
190 if (*Pointer
== Value
) {
194 } while (--Length
!= 0);
199 Scans a target buffer for a 32-bit value, and returns a pointer to the
200 matching 32-bit value in the target buffer.
202 @param Buffer The pointer to the target buffer to scan.
203 @param Length The count of 32-bit value to scan. Must be non-zero.
204 @param Value The value to search for in the target buffer.
206 @return The pointer to the first occurrence, or NULL if not found.
211 InternalMemScanMem32 (
212 IN CONST VOID
*Buffer
,
217 CONST UINT32
*Pointer
;
219 Pointer
= (CONST UINT32
*)Buffer
;
221 if (*Pointer
== Value
) {
225 } while (--Length
!= 0);
230 Scans a target buffer for a 64-bit value, and returns a pointer to the
231 matching 64-bit value in the target buffer.
233 @param Buffer The pointer to the target buffer to scan.
234 @param Length The count of 64-bit value to scan. Must be non-zero.
235 @param Value The value to search for in the target buffer.
237 @return The pointer to the first occurrence, or NULL if not found.
242 InternalMemScanMem64 (
243 IN CONST VOID
*Buffer
,
248 CONST UINT64
*Pointer
;
250 Pointer
= (CONST UINT64
*)Buffer
;
252 if (*Pointer
== Value
) {
256 } while (--Length
!= 0);
261 Checks whether the contents of a buffer are all zeros.
263 @param Buffer The pointer to the buffer to be checked.
264 @param Length The size of the buffer (in bytes) to be checked.
266 @retval TRUE Contents of the buffer are all zeros.
267 @retval FALSE Contents of the buffer are not all zeros.
272 InternalMemIsZeroBuffer (
273 IN CONST VOID
*Buffer
,
277 CONST UINT8
*BufferData
;
281 for (Index
= 0; Index
< Length
; Index
++) {
282 if (BufferData
[Index
] != 0) {