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