]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseMemoryLib/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 share the same version of this file:
22 // Include common header file for this module.
26 #include "MemLibInternals.h"
29 Fills a target buffer with a 16-bit value, and returns the target buffer.
31 @param Buffer Pointer to the target buffer to fill.
32 @param Length Number of bytes in Buffer to fill.
33 @param Value Value with which to fill Length bytes of Buffer.
47 ((UINT16
*)Buffer
)[--Length
] = Value
;
48 } while (Length
!= 0);
53 Fills a target buffer with a 32-bit value, and returns the target buffer.
55 @param Buffer Pointer to the target buffer to fill.
56 @param Length Number of bytes in Buffer to fill.
57 @param Value Value with which to fill Length bytes of Buffer.
71 ((UINT32
*)Buffer
)[--Length
] = Value
;
72 } while (Length
!= 0);
77 Fills a target buffer with a 64-bit value, and returns the target buffer.
79 @param Buffer Pointer to the target buffer to fill.
80 @param Length Number of bytes in Buffer to fill.
81 @param Value Value with which to fill Length bytes of Buffer.
95 ((UINT64
*)Buffer
)[--Length
] = Value
;
96 } while (Length
!= 0);
101 Set Buffer to 0 for Size bytes.
103 @param Buffer Memory to set.
104 @param Length Number of bytes to set
116 return InternalMemSetMem (Buffer
, Length
, 0);
120 Compares two memory buffers of a given length.
122 @param DestinationBuffer First memory buffer
123 @param SourceBuffer Second memory buffer
124 @param Length Length of DestinationBuffer and SourceBuffer memory
125 regions to compare. Must be non-zero.
127 @retval 0 if MemOne == MemTwo
132 InternalMemCompareMem (
133 IN CONST VOID
*DestinationBuffer
,
134 IN CONST VOID
*SourceBuffer
,
138 while ((--Length
!= 0) &&
139 (*(INT8
*)DestinationBuffer
== *(INT8
*)SourceBuffer
)) {
140 DestinationBuffer
= (INT8
*)DestinationBuffer
+ 1;
141 SourceBuffer
= (INT8
*)SourceBuffer
+ 1;
143 return (INTN
)*(UINT8
*)DestinationBuffer
- (INTN
)*(UINT8
*)SourceBuffer
;
147 Scans a target buffer for an 8-bit value, and returns a pointer to the
148 matching 8-bit value in the target buffer.
150 @param Buffer Pointer to the target buffer to scan.
151 @param Length Number of bytes in Buffer to scan. Must be non-zero.
152 @param Value Value to search for in the target buffer.
154 @return Pointer to the first occurrence or NULL if not found.
159 InternalMemScanMem8 (
160 IN CONST VOID
*Buffer
,
165 CONST UINT8
*Pointer
;
167 Pointer
= (CONST UINT8
*)Buffer
;
169 if (*(Pointer
++) == Value
) {
172 } while (--Length
!= 0);
177 Scans a target buffer for a 16-bit value, and returns a pointer to the
178 matching 16-bit value in the target buffer.
180 @param Buffer Pointer to the target buffer to scan.
181 @param Length Number of bytes in Buffer to scan. Must be non-zero.
182 @param Value Value to search for in the target buffer.
184 @return Pointer to the first occurrence or NULL if not found.
189 InternalMemScanMem16 (
190 IN CONST VOID
*Buffer
,
195 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
;
227 Pointer
= (CONST UINT32
*)Buffer
;
229 if (*(Pointer
++) == Value
) {
232 } while (--Length
!= 0);
237 Scans a target buffer for a 64-bit value, and returns a pointer to the
238 matching 64-bit value in the target buffer.
240 @param Buffer Pointer to the target buffer to scan.
241 @param Length Number of bytes in Buffer to scan. Must be non-zero.
242 @param Value Value to search for in the target buffer.
244 @return Pointer to the first occurrence or NULL if not found.
249 InternalMemScanMem64 (
250 IN CONST VOID
*Buffer
,
255 CONST UINT64
*Pointer
;
257 Pointer
= (CONST UINT64
*)Buffer
;
259 if (*(Pointer
++) == Value
) {
262 } while (--Length
!= 0);