]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseMemoryLib/Ebc/MemLibGeneric.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / BaseMemoryLib / Ebc / MemLibGeneric.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 MemLibGeneric.c
16
17 Abstract:
18
19 Architecture Independent Base Memory Library Implementation.
20
21 --*/
22
23 #include "BaseMemoryLibInternal.h"
24
25 /**
26 Fills a target buffer with a 16-bit value, and returns the target buffer.
27
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.
31
32 @return Buffer
33
34 **/
35 VOID *
36 EFIAPI
37 InternalMemSetMem16 (
38 OUT VOID *Buffer,
39 IN UINTN Length,
40 IN UINT16 Value
41 )
42 {
43 do {
44 ((UINT16*)Buffer)[--Length] = Value;
45 } while (Length != 0);
46 return Buffer;
47 }
48
49 /**
50 Fills a target buffer with a 32-bit value, and returns the target buffer.
51
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.
55
56 @return Buffer
57
58 **/
59 VOID *
60 EFIAPI
61 InternalMemSetMem32 (
62 OUT VOID *Buffer,
63 IN UINTN Length,
64 IN UINT32 Value
65 )
66 {
67 do {
68 ((UINT32*)Buffer)[--Length] = Value;
69 } while (Length != 0);
70 return Buffer;
71 }
72
73 /**
74 Fills a target buffer with a 64-bit value, and returns the target buffer.
75
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.
79
80 @return Buffer
81
82 **/
83 VOID *
84 EFIAPI
85 InternalMemSetMem64 (
86 OUT VOID *Buffer,
87 IN UINTN Length,
88 IN UINT64 Value
89 )
90 {
91 do {
92 ((UINT64*)Buffer)[--Length] = Value;
93 } while (Length != 0);
94 return Buffer;
95 }
96
97 /**
98 Set Buffer to 0 for Size bytes.
99
100 @param Buffer Memory to set.
101 @param Size Number of bytes to set
102
103 @return Buffer
104
105 **/
106 VOID *
107 EFIAPI
108 InternalMemZeroMem (
109 OUT VOID *Buffer,
110 IN UINTN Length
111 )
112 {
113 return InternalMemSetMem (Buffer, Length, 0);
114 }
115
116 /**
117 Compares two memory buffers of a given length.
118
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.
123
124 @retval 0 if MemOne == MemTwo
125
126 **/
127 INTN
128 EFIAPI
129 InternalMemCompareMem (
130 IN CONST VOID *DestinationBuffer,
131 IN CONST VOID *SourceBuffer,
132 IN UINTN Length
133 )
134 {
135 while ((--Length != 0) &&
136 (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {
137 DestinationBuffer = (INT8*)DestinationBuffer + 1;
138 SourceBuffer = (INT8*)SourceBuffer + 1;
139 }
140 return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer;
141 }
142
143 /**
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.
146
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.
150
151 @return Pointer to the first occurrence or NULL if not found.
152
153 **/
154 CONST VOID *
155 EFIAPI
156 InternalMemScanMem8 (
157 IN CONST VOID *Buffer,
158 IN UINTN Length,
159 IN UINT8 Value
160 )
161 {
162 CONST UINT8 *Pointer;
163
164 Pointer = (CONST UINT8*)Buffer;
165 do {
166 if (*(Pointer++) == Value) {
167 return Pointer;
168 }
169 } while (--Length != 0);
170 return NULL;
171 }
172
173 /**
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.
176
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.
180
181 @return Pointer to the first occurrence or NULL if not found.
182
183 **/
184 CONST VOID *
185 EFIAPI
186 InternalMemScanMem16 (
187 IN CONST VOID *Buffer,
188 IN UINTN Length,
189 IN UINT16 Value
190 )
191 {
192 CONST UINT16 *Pointer;
193
194 Pointer = (CONST UINT16*)Buffer;
195 do {
196 if (*(Pointer++) == Value) {
197 return Pointer;
198 }
199 } while (--Length != 0);
200 return NULL;
201 }
202
203 /**
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.
206
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.
210
211 @return Pointer to the first occurrence or NULL if not found.
212
213 **/
214 CONST VOID *
215 EFIAPI
216 InternalMemScanMem32 (
217 IN CONST VOID *Buffer,
218 IN UINTN Length,
219 IN UINT32 Value
220 )
221 {
222 CONST UINT32 *Pointer;
223
224 Pointer = (CONST UINT32*)Buffer;
225 do {
226 if (*(Pointer++) == Value) {
227 return Pointer;
228 }
229 } while (--Length != 0);
230 return NULL;
231 }
232
233 /**
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.
236
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.
240
241 @return Pointer to the first occurrence or NULL if not found.
242
243 **/
244 CONST VOID *
245 EFIAPI
246 InternalMemScanMem64 (
247 IN CONST VOID *Buffer,
248 IN UINTN Length,
249 IN UINT64 Value
250 )
251 {
252 CONST UINT64 *Pointer;
253
254 Pointer = (CONST UINT64*)Buffer;
255 do {
256 if (*(Pointer++) == Value) {
257 return Pointer;
258 }
259 } while (--Length != 0);
260 return NULL;
261 }