]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiMemoryLib/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 The 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 The 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
) {
162 } while (--Length
!= 0);
167 Scans a target buffer for a 16-bit value, and returns a pointer to the
168 matching 16-bit value in the target buffer.
170 @param Buffer The pointer to the target buffer to scan.
171 @param Length The count of 16-bit value to scan. Must be non-zero.
172 @param Value The value to search for in the target buffer.
174 @return The pointer to the first occurrence, or NULL if not found.
179 InternalMemScanMem16 (
180 IN CONST VOID
*Buffer
,
185 CONST UINT16
*Pointer
;
187 Pointer
= (CONST UINT16
*)Buffer
;
189 if (*(Pointer
++) == Value
) {
192 } while (--Length
!= 0);
197 Scans a target buffer for a 32-bit value, and returns a pointer to the
198 matching 32-bit value in the target buffer.
200 @param Buffer The pointer to the target buffer to scan.
201 @param Length The count of 32-bit value to scan. Must be non-zero.
202 @param Value The value to search for in the target buffer.
204 @return The pointer to the first occurrence, or NULL if not found.
209 InternalMemScanMem32 (
210 IN CONST VOID
*Buffer
,
215 CONST UINT32
*Pointer
;
217 Pointer
= (CONST UINT32
*)Buffer
;
219 if (*(Pointer
++) == Value
) {
222 } while (--Length
!= 0);
227 Scans a target buffer for a 64-bit value, and returns a pointer to the
228 matching 64-bit value in the target buffer.
230 @param Buffer The pointer to the target buffer to scan.
231 @param Length The count of 64-bit value to scan. Must be non-zero.
232 @param Value The value to search for in the target buffer.
234 @return The pointer to the first occurrence, or NULL if not found.
239 InternalMemScanMem64 (
240 IN CONST VOID
*Buffer
,
245 CONST UINT64
*Pointer
;
247 Pointer
= (CONST UINT64
*)Buffer
;
249 if (*(Pointer
++) == Value
) {
252 } while (--Length
!= 0);
257 Checks whether the contents of a buffer are all zeros.
259 @param Buffer The pointer to the buffer to be checked.
260 @param Length The size of the buffer (in bytes) to be checked.
262 @retval TRUE Contents of the buffer are all zeros.
263 @retval FALSE Contents of the buffer are not all zeros.
268 InternalMemIsZeroBuffer (
269 IN CONST VOID
*Buffer
,
273 CONST UINT8
*BufferData
;
277 for (Index
= 0; Index
< Length
; Index
++) {
278 if (BufferData
[Index
] != 0) {