]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
2 Architecture Independent Base Memory Library Implementation.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 The following BaseMemoryLib instances contain the same copy of this file:
21 #include "MemLibInternals.h"
24 Fills a target buffer with a 16-bit value, and returns the target buffer.
26 @param Buffer Pointer to the target buffer to fill.
27 @param Length Number of bytes in Buffer to fill.
28 @param Value Value with which to fill Length bytes of Buffer.
42 ((UINT16
*)Buffer
)[--Length
] = Value
;
43 } while (Length
!= 0);
48 Fills a target buffer with a 32-bit value, and returns the target buffer.
50 @param Buffer Pointer to the target buffer to fill.
51 @param Length Number of bytes in Buffer to fill.
52 @param Value Value with which to fill Length bytes of Buffer.
66 ((UINT32
*)Buffer
)[--Length
] = Value
;
67 } while (Length
!= 0);
72 Fills a target buffer with a 64-bit value, and returns the target buffer.
74 @param Buffer Pointer to the target buffer to fill.
75 @param Length Number of bytes in Buffer to fill.
76 @param Value Value with which to fill Length bytes of Buffer.
90 ((UINT64
*)Buffer
)[--Length
] = Value
;
91 } while (Length
!= 0);
96 Set Buffer to 0 for Size bytes.
98 @param Buffer Memory to set.
99 @param Length Number of bytes to set
111 return InternalMemSetMem (Buffer
, Length
, 0);
115 Compares two memory buffers of a given length.
117 @param DestinationBuffer First memory buffer
118 @param SourceBuffer Second memory buffer
119 @param Length Length of DestinationBuffer and SourceBuffer memory
120 regions to compare. Must be non-zero.
122 @return 0 All Length bytes of the two buffers are identical.
123 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first
124 mismatched byte in DestinationBuffer.
129 InternalMemCompareMem (
130 IN CONST VOID
*DestinationBuffer
,
131 IN CONST VOID
*SourceBuffer
,
135 while ((--Length
!= 0) &&
136 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
137 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
138 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
140 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
144 Scans a target buffer for an 8-bit value, and returns a pointer to the
145 matching 8-bit value in the target buffer.
147 @param Buffer Pointer to the target buffer to scan.
148 @param Length Number of bytes in Buffer to scan. Must be non-zero.
149 @param Value Value to search for in the target buffer.
151 @return Pointer to the first occurrence or NULL if not found.
156 InternalMemScanMem8 (
157 IN CONST VOID
*Buffer
,
162 CONST UINT8
*Pointer
;
164 Pointer
= (CONST UINT8
*)Buffer
;
166 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 Pointer to the target buffer to scan.
178 @param Length Number of bytes in Buffer to scan. Must be non-zero.
179 @param Value Value to search for in the target buffer.
181 @return 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
) {
199 } 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 Pointer to the target buffer to scan.
208 @param Length Number of bytes in Buffer to scan. Must be non-zero.
209 @param Value Value to search for in the target buffer.
211 @return 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);
234 Scans a target buffer for a 64-bit value, and returns a pointer to the
235 matching 64-bit value in the target buffer.
237 @param Buffer Pointer to the target buffer to scan.
238 @param Length Number of bytes in Buffer to scan. Must be non-zero.
239 @param Value Value to search for in the target buffer.
241 @return Pointer to the first occurrence or NULL if not found.
246 InternalMemScanMem64 (
247 IN CONST VOID
*Buffer
,
252 CONST UINT64
*Pointer
;
254 Pointer
= (CONST UINT64
*)Buffer
;
256 if (*(Pointer
++) == Value
) {
259 } while (--Length
!= 0);