]>
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 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php.
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "MemLibInternals.h"
23 Fills a target buffer with a 16-bit value, and returns the target buffer.
25 @param Buffer The pointer to the target buffer to fill.
26 @param Length The count of 16-bit value to fill.
27 @param Value The value with which to fill Length bytes of Buffer.
40 for (; Length
!= 0; Length
--) {
41 ((UINT16
*)Buffer
)[Length
- 1] = Value
;
47 Fills a target buffer with a 32-bit value, and returns the target buffer.
49 @param Buffer The pointer to the target buffer to fill.
50 @param Length The count of 32-bit value to fill.
51 @param Value The value with which to fill Length bytes of Buffer.
64 for (; Length
!= 0; Length
--) {
65 ((UINT32
*)Buffer
)[Length
- 1] = Value
;
71 Fills a target buffer with a 64-bit value, and returns the target buffer.
73 @param Buffer The pointer to the target buffer to fill.
74 @param Length The count of 64-bit value to fill.
75 @param Value The value with which to fill Length bytes of Buffer.
88 for (; Length
!= 0; Length
--) {
89 ((UINT64
*)Buffer
)[Length
- 1] = Value
;
95 Set Buffer to 0 for Size bytes.
97 @param Buffer Memory to set.
98 @param Length The number of bytes to set.
110 return InternalMemSetMem (Buffer
, Length
, 0);
114 Compares two memory buffers of a given length.
116 @param DestinationBuffer The first memory buffer.
117 @param SourceBuffer The second memory buffer.
118 @param Length Length of DestinationBuffer and SourceBuffer memory
119 regions to compare. Must be non-zero.
121 @return 0 All Length bytes of the two buffers are identical.
122 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
123 mismatched byte in DestinationBuffer.
128 InternalMemCompareMem (
129 IN CONST VOID
*DestinationBuffer
,
130 IN CONST VOID
*SourceBuffer
,
134 while ((--Length
!= 0) &&
135 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
136 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
137 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
139 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
143 Scans a target buffer for an 8-bit value, and returns a pointer to the
144 matching 8-bit value in the target buffer.
146 @param Buffer The pointer to the target buffer to scan.
147 @param Length The count of 8-bit value to scan. Must be non-zero.
148 @param Value The value to search for in the target buffer.
150 @return The pointer to the first occurrence, or NULL if not found.
155 InternalMemScanMem8 (
156 IN CONST VOID
*Buffer
,
161 CONST UINT8
*Pointer
;
163 Pointer
= (CONST UINT8
*)Buffer
;
165 if (*Pointer
== Value
) {
169 } while (--Length
!= 0);
174 Scans a target buffer for a 16-bit value, and returns a pointer to the
175 matching 16-bit value in the target buffer.
177 @param Buffer The pointer to the target buffer to scan.
178 @param Length The count of 16-bit value to scan. Must be non-zero.
179 @param Value The value to search for in the target buffer.
181 @return The pointer to the first occurrence, or NULL if not found.
186 InternalMemScanMem16 (
187 IN CONST VOID
*Buffer
,
192 CONST UINT16
*Pointer
;
194 Pointer
= (CONST UINT16
*)Buffer
;
196 if (*Pointer
== Value
) {
200 } while (--Length
!= 0);
205 Scans a target buffer for a 32-bit value, and returns a pointer to the
206 matching 32-bit value in the target buffer.
208 @param Buffer The pointer to the target buffer to scan.
209 @param Length The count of 32-bit value to scan. Must be non-zero.
210 @param Value The value to search for in the target buffer.
212 @return The pointer to the first occurrence, or NULL if not found.
217 InternalMemScanMem32 (
218 IN CONST VOID
*Buffer
,
223 CONST UINT32
*Pointer
;
225 Pointer
= (CONST UINT32
*)Buffer
;
227 if (*Pointer
== Value
) {
231 } while (--Length
!= 0);
236 Scans a target buffer for a 64-bit value, and returns a pointer to the
237 matching 64-bit value in the target buffer.
239 @param Buffer The pointer to the target buffer to scan.
240 @param Length The count of 64-bit value to scan. Must be non-zero.
241 @param Value The value to search for in the target buffer.
243 @return The pointer to the first occurrence, or NULL if not found.
248 InternalMemScanMem64 (
249 IN CONST VOID
*Buffer
,
254 CONST UINT64
*Pointer
;
256 Pointer
= (CONST UINT64
*)Buffer
;
258 if (*Pointer
== Value
) {
262 } while (--Length
!= 0);
267 Checks whether the contents of a buffer are all zeros.
269 @param Buffer The pointer to the buffer to be checked.
270 @param Length The size of the buffer (in bytes) to be checked.
272 @retval TRUE Contents of the buffer are all zeros.
273 @retval FALSE Contents of the buffer are not all zeros.
278 InternalMemIsZeroBuffer (
279 IN CONST VOID
*Buffer
,
283 CONST UINT8
*BufferData
;
287 for (Index
= 0; Index
< Length
; Index
++) {
288 if (BufferData
[Index
] != 0) {