]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/BaseMemoryLibStm/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 - 2009, 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 Pointer to the target buffer to fill.
26 @param Length Count of 16-bit value to fill.
27 @param Value Value with which to fill Length bytes of Buffer.
41 ((UINT16
*)Buffer
)[--Length
] = Value
;
42 } while (Length
!= 0);
47 Fills a target buffer with a 32-bit value, and returns the target buffer.
49 @param Buffer Pointer to the target buffer to fill.
50 @param Length Count of 32-bit value to fill.
51 @param Value Value with which to fill Length bytes of Buffer.
65 ((UINT32
*)Buffer
)[--Length
] = Value
;
66 } while (Length
!= 0);
71 Fills a target buffer with a 64-bit value, and returns the target buffer.
73 @param Buffer Pointer to the target buffer to fill.
74 @param Length Count of 64-bit value to fill.
75 @param Value Value with which to fill Length bytes of Buffer.
89 ((UINT64
*)Buffer
)[--Length
] = Value
;
90 } while (Length
!= 0);
95 Set Buffer to 0 for Size bytes.
97 @param Buffer Memory to set.
98 @param Length Number of bytes to set
110 return InternalMemSetMem (Buffer
, Length
, 0);
114 Compares two memory buffers of a given length.
116 @param DestinationBuffer First memory buffer
117 @param SourceBuffer 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 Pointer to the target buffer to scan.
147 @param Length Count of 8-bit value to scan. Must be non-zero.
148 @param Value Value to search for in the target buffer.
150 @return 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 Pointer to the target buffer to scan.
178 @param Length Count of 16-bit value 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
) {
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 Pointer to the target buffer to scan.
209 @param Length Count of 32-bit value to scan. Must be non-zero.
210 @param Value Value to search for in the target buffer.
212 @return 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 Pointer to the target buffer to scan.
240 @param Length Count of 64-bit value to scan. Must be non-zero.
241 @param Value Value to search for in the target buffer.
243 @return 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);