]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiMemoryLib/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 Module Name: MemLibGeneric.c
15 The following BaseMemoryLib instances share the same version of this file:
23 #include "MemLibInternals.h"
26 Fills a target buffer with a 16-bit value, and returns the target buffer.
28 @param Buffer Pointer to the target buffer to fill.
29 @param Length Number of bytes in Buffer to fill.
30 @param Value Value with which to fill Length bytes of Buffer.
44 ((UINT16
*)Buffer
)[--Length
] = Value
;
45 } while (Length
!= 0);
50 Fills a target buffer with a 32-bit value, and returns the target buffer.
52 @param Buffer Pointer to the target buffer to fill.
53 @param Length Number of bytes in Buffer to fill.
54 @param Value Value with which to fill Length bytes of Buffer.
68 ((UINT32
*)Buffer
)[--Length
] = Value
;
69 } while (Length
!= 0);
74 Fills a target buffer with a 64-bit value, and returns the target buffer.
76 @param Buffer Pointer to the target buffer to fill.
77 @param Length Number of bytes in Buffer to fill.
78 @param Value Value with which to fill Length bytes of Buffer.
92 ((UINT64
*)Buffer
)[--Length
] = Value
;
93 } while (Length
!= 0);
98 Set Buffer to 0 for Size bytes.
100 @param Buffer Memory to set.
101 @param Size Number of bytes to set
113 return InternalMemSetMem (Buffer
, Length
, 0);
117 Compares two memory buffers of a given length.
119 @param DestinationBuffer First memory buffer
120 @param SourceBuffer Second memory buffer
121 @param Length Length of DestinationBuffer and SourceBuffer memory
122 regions to compare. Must be non-zero.
124 @retval 0 if MemOne == MemTwo
129 InternalMemCompareMem (
130 IN CONST VOID
*DestinationBuffer
,
131 IN CONST VOID
*SourceBuffer
,
136 while ((--Length
!= 0) &&
137 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
138 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
139 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
141 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
145 Scans a target buffer for an 8-bit value, and returns a pointer to the
146 matching 8-bit value in the target buffer.
148 @param Buffer Pointer to the target buffer to scan.
149 @param Length Number of bytes in Buffer to scan. Must be non-zero.
150 @param Value Value to search for in the target buffer.
152 @return Pointer to the first occurrence or NULL if not found.
157 InternalMemScanMem8 (
158 IN CONST VOID
*Buffer
,
163 CONST UINT8
*Pointer
;
166 Pointer
= (CONST UINT8
*)Buffer
;
168 if (*(Pointer
++) == Value
) {
171 } while (--Length
!= 0);
176 Scans a target buffer for a 16-bit value, and returns a pointer to the
177 matching 16-bit value in the target buffer.
179 @param Buffer Pointer to the target buffer to scan.
180 @param Length Number of bytes in Buffer to scan. Must be non-zero.
181 @param Value Value to search for in the target buffer.
183 @return Pointer to the first occurrence or NULL if not found.
188 InternalMemScanMem16 (
189 IN CONST VOID
*Buffer
,
194 CONST UINT16
*Pointer
;
197 Pointer
= (CONST UINT16
*)Buffer
;
199 if (*(Pointer
++) == Value
) {
202 } while (--Length
!= 0);
207 Scans a target buffer for a 32-bit value, and returns a pointer to the
208 matching 32-bit value in the target buffer.
210 @param Buffer Pointer to the target buffer to scan.
211 @param Length Number of bytes in Buffer to scan. Must be non-zero.
212 @param Value Value to search for in the target buffer.
214 @return Pointer to the first occurrence or NULL if not found.
219 InternalMemScanMem32 (
220 IN CONST VOID
*Buffer
,
225 CONST UINT32
*Pointer
;
228 Pointer
= (CONST UINT32
*)Buffer
;
230 if (*(Pointer
++) == Value
) {
233 } while (--Length
!= 0);
238 Scans a target buffer for a 64-bit value, and returns a pointer to the
239 matching 64-bit value in the target buffer.
241 @param Buffer Pointer to the target buffer to scan.
242 @param Length Number of bytes in Buffer to scan. Must be non-zero.
243 @param Value Value to search for in the target buffer.
245 @return Pointer to the first occurrence or NULL if not found.
250 InternalMemScanMem64 (
251 IN CONST VOID
*Buffer
,
256 CONST UINT64
*Pointer
;
259 Pointer
= (CONST UINT64
*)Buffer
;
261 if (*(Pointer
++) == Value
) {
264 } while (--Length
!= 0);