]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/BaseMemoryLibStm/MemLibGeneric.c
BeagleBoardPkg: remove dependency on ArmPkg/BaseMemoryLibStm
[mirror_edk2.git] / ArmPkg / Library / BaseMemoryLibStm / MemLibGeneric.c
CommitLineData
d39eb83c 1/** @file\r
2 Architecture Independent Base Memory Library Implementation.\r
3\r
4 The following BaseMemoryLib instances contain the same copy of this file:\r
5 BaseMemoryLib\r
6 PeiMemoryLib\r
7 UefiMemoryLib\r
8\r
d6ebcab7
HT
9 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
10 This program and the accompanying materials\r
d39eb83c 11 are licensed and made available under the terms and conditions of the BSD License\r
12 which accompanies this distribution. The full text of the license may be found at\r
13 http://opensource.org/licenses/bsd-license.php\r
14\r
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20#include "MemLibInternals.h"\r
21\r
22/**\r
23 Fills a target buffer with a 16-bit value, and returns the target buffer.\r
24\r
25 @param Buffer Pointer to the target buffer to fill.\r
26 @param Length Count of 16-bit value to fill.\r
27 @param Value Value with which to fill Length bytes of Buffer.\r
28\r
29 @return Buffer\r
30\r
31**/\r
32VOID *\r
33EFIAPI\r
34InternalMemSetMem16 (\r
35 OUT VOID *Buffer,\r
36 IN UINTN Length,\r
37 IN UINT16 Value\r
38 )\r
39{\r
40 do {\r
41 ((UINT16*)Buffer)[--Length] = Value;\r
42 } while (Length != 0);\r
43 return Buffer;\r
44}\r
45\r
46/**\r
47 Fills a target buffer with a 32-bit value, and returns the target buffer.\r
48\r
49 @param Buffer Pointer to the target buffer to fill.\r
50 @param Length Count of 32-bit value to fill.\r
51 @param Value Value with which to fill Length bytes of Buffer.\r
52\r
53 @return Buffer\r
54\r
55**/\r
56VOID *\r
57EFIAPI\r
58InternalMemSetMem32 (\r
59 OUT VOID *Buffer,\r
60 IN UINTN Length,\r
61 IN UINT32 Value\r
62 )\r
63{\r
64 do {\r
65 ((UINT32*)Buffer)[--Length] = Value;\r
66 } while (Length != 0);\r
67 return Buffer;\r
68}\r
69\r
70/**\r
71 Fills a target buffer with a 64-bit value, and returns the target buffer.\r
72\r
73 @param Buffer Pointer to the target buffer to fill.\r
74 @param Length Count of 64-bit value to fill.\r
75 @param Value Value with which to fill Length bytes of Buffer.\r
76\r
77 @return Buffer\r
78\r
79**/\r
80VOID *\r
81EFIAPI\r
82InternalMemSetMem64 (\r
83 OUT VOID *Buffer,\r
84 IN UINTN Length,\r
85 IN UINT64 Value\r
86 )\r
87{\r
88 do {\r
89 ((UINT64*)Buffer)[--Length] = Value;\r
90 } while (Length != 0);\r
91 return Buffer;\r
92}\r
93\r
94/**\r
95 Set Buffer to 0 for Size bytes.\r
96\r
97 @param Buffer Memory to set.\r
98 @param Length Number of bytes to set\r
99\r
100 @return Buffer\r
101\r
102**/\r
103VOID *\r
104EFIAPI\r
105InternalMemZeroMem (\r
106 OUT VOID *Buffer,\r
107 IN UINTN Length\r
108 )\r
109{\r
110 return InternalMemSetMem (Buffer, Length, 0);\r
111}\r
112\r
113/**\r
114 Compares two memory buffers of a given length.\r
115\r
116 @param DestinationBuffer First memory buffer\r
117 @param SourceBuffer Second memory buffer\r
118 @param Length Length of DestinationBuffer and SourceBuffer memory\r
119 regions to compare. Must be non-zero.\r
120\r
121 @return 0 All Length bytes of the two buffers are identical.\r
122 @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first\r
123 mismatched byte in DestinationBuffer.\r
124\r
125**/\r
126INTN\r
127EFIAPI\r
128InternalMemCompareMem (\r
129 IN CONST VOID *DestinationBuffer,\r
130 IN CONST VOID *SourceBuffer,\r
131 IN UINTN Length\r
132 )\r
133{\r
134 while ((--Length != 0) &&\r
135 (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {\r
136 DestinationBuffer = (INT8*)DestinationBuffer + 1;\r
137 SourceBuffer = (INT8*)SourceBuffer + 1;\r
138 }\r
139 return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer;\r
140}\r
141\r
142/**\r
143 Scans a target buffer for an 8-bit value, and returns a pointer to the\r
144 matching 8-bit value in the target buffer.\r
145\r
146 @param Buffer Pointer to the target buffer to scan.\r
147 @param Length Count of 8-bit value to scan. Must be non-zero.\r
148 @param Value Value to search for in the target buffer.\r
149\r
150 @return Pointer to the first occurrence or NULL if not found.\r
151\r
152**/\r
153CONST VOID *\r
154EFIAPI\r
155InternalMemScanMem8 (\r
156 IN CONST VOID *Buffer,\r
157 IN UINTN Length,\r
158 IN UINT8 Value\r
159 )\r
160{\r
161 CONST UINT8 *Pointer;\r
162\r
163 Pointer = (CONST UINT8*)Buffer;\r
164 do {\r
80d31397 165 if (*Pointer == Value) {\r
d39eb83c 166 return Pointer;\r
167 }\r
80d31397 168 Pointer++;\r
d39eb83c 169 } while (--Length != 0);\r
170 return NULL;\r
171}\r
172\r
173/**\r
174 Scans a target buffer for a 16-bit value, and returns a pointer to the\r
175 matching 16-bit value in the target buffer.\r
176\r
177 @param Buffer Pointer to the target buffer to scan.\r
178 @param Length Count of 16-bit value to scan. Must be non-zero.\r
179 @param Value Value to search for in the target buffer.\r
180\r
181 @return Pointer to the first occurrence or NULL if not found.\r
182\r
183**/\r
184CONST VOID *\r
185EFIAPI\r
186InternalMemScanMem16 (\r
187 IN CONST VOID *Buffer,\r
188 IN UINTN Length,\r
189 IN UINT16 Value\r
190 )\r
191{\r
192 CONST UINT16 *Pointer;\r
193\r
194 Pointer = (CONST UINT16*)Buffer;\r
195 do {\r
80d31397 196 if (*Pointer == Value) {\r
d39eb83c 197 return Pointer;\r
198 }\r
80d31397 199 Pointer++;\r
d39eb83c 200 } while (--Length != 0);\r
201 return NULL;\r
202}\r
203\r
204/**\r
205 Scans a target buffer for a 32-bit value, and returns a pointer to the\r
206 matching 32-bit value in the target buffer.\r
207\r
208 @param Buffer Pointer to the target buffer to scan.\r
209 @param Length Count of 32-bit value to scan. Must be non-zero.\r
210 @param Value Value to search for in the target buffer.\r
211\r
212 @return Pointer to the first occurrence or NULL if not found.\r
213\r
214**/\r
215CONST VOID *\r
216EFIAPI\r
217InternalMemScanMem32 (\r
218 IN CONST VOID *Buffer,\r
219 IN UINTN Length,\r
220 IN UINT32 Value\r
221 )\r
222{\r
223 CONST UINT32 *Pointer;\r
224\r
225 Pointer = (CONST UINT32*)Buffer;\r
226 do {\r
80d31397 227 if (*Pointer == Value) {\r
d39eb83c 228 return Pointer;\r
229 }\r
80d31397 230 Pointer++;\r
d39eb83c 231 } while (--Length != 0);\r
232 return NULL;\r
233}\r
234\r
235/**\r
236 Scans a target buffer for a 64-bit value, and returns a pointer to the\r
237 matching 64-bit value in the target buffer.\r
238\r
239 @param Buffer Pointer to the target buffer to scan.\r
240 @param Length Count of 64-bit value to scan. Must be non-zero.\r
241 @param Value Value to search for in the target buffer.\r
242\r
243 @return Pointer to the first occurrence or NULL if not found.\r
244\r
245**/\r
246CONST VOID *\r
247EFIAPI\r
248InternalMemScanMem64 (\r
249 IN CONST VOID *Buffer,\r
250 IN UINTN Length,\r
251 IN UINT64 Value\r
252 )\r
253{\r
254 CONST UINT64 *Pointer;\r
255\r
256 Pointer = (CONST UINT64*)Buffer;\r
257 do {\r
80d31397 258 if (*Pointer == Value) {\r
d39eb83c 259 return Pointer;\r
260 }\r
80d31397 261 Pointer++;\r
d39eb83c 262 } while (--Length != 0);\r
263 return NULL;\r
264}\r
0b09c212
AB
265\r
266/**\r
267 Checks whether the contents of a buffer are all zeros.\r
268\r
269 @param Buffer The pointer to the buffer to be checked.\r
270 @param Length The size of the buffer (in bytes) to be checked.\r
271\r
272 @retval TRUE Contents of the buffer are all zeros.\r
273 @retval FALSE Contents of the buffer are not all zeros.\r
274\r
275**/\r
276BOOLEAN\r
277EFIAPI\r
278InternalMemIsZeroBuffer (\r
279 IN CONST VOID *Buffer,\r
280 IN UINTN Length\r
281 )\r
282{\r
283 CONST UINT8 *BufferData;\r
284 UINTN Index;\r
285\r
286 BufferData = Buffer;\r
287 for (Index = 0; Index < Length; Index++) {\r
288 if (BufferData[Index] != 0) {\r
289 return FALSE;\r
290 }\r
291 }\r
292 return TRUE;\r
293}\r