]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeMemoryLib/MemLibGeneric.c
Removed MdePkg usage of ModuleName: in file headers
[mirror_edk2.git] / MdePkg / Library / DxeMemoryLib / MemLibGeneric.c
CommitLineData
dd51a993 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
dd51a993 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#include "MemLibInternals.h"\r
22\r
23/**\r
24 Fills a target buffer with a 16-bit value, and returns the target buffer.\r
25\r
26 @param Buffer Pointer to the target buffer to fill.\r
27 @param Length Number of bytes in Buffer to fill.\r
28 @param Value Value with which to fill Length bytes of Buffer.\r
29\r
30 @return Buffer\r
31\r
32**/\r
33VOID *\r
34EFIAPI\r
35InternalMemSetMem16 (\r
36 OUT VOID *Buffer,\r
37 IN UINTN Length,\r
38 IN UINT16 Value\r
39 )\r
40{\r
41 do {\r
42 ((UINT16*)Buffer)[--Length] = Value;\r
43 } while (Length != 0);\r
44 return Buffer;\r
45}\r
46\r
47/**\r
48 Fills a target buffer with a 32-bit value, and returns the target buffer.\r
49\r
50 @param Buffer Pointer to the target buffer to fill.\r
51 @param Length Number of bytes in Buffer to fill.\r
52 @param Value Value with which to fill Length bytes of Buffer.\r
53\r
54 @return Buffer\r
55\r
56**/\r
57VOID *\r
58EFIAPI\r
59InternalMemSetMem32 (\r
60 OUT VOID *Buffer,\r
61 IN UINTN Length,\r
62 IN UINT32 Value\r
63 )\r
64{\r
65 do {\r
66 ((UINT32*)Buffer)[--Length] = Value;\r
67 } while (Length != 0);\r
68 return Buffer;\r
69}\r
70\r
71/**\r
72 Fills a target buffer with a 64-bit value, and returns the target buffer.\r
73\r
74 @param Buffer Pointer to the target buffer to fill.\r
75 @param Length Number of bytes in Buffer to fill.\r
76 @param Value Value with which to fill Length bytes of Buffer.\r
77\r
78 @return Buffer\r
79\r
80**/\r
81VOID *\r
82EFIAPI\r
83InternalMemSetMem64 (\r
84 OUT VOID *Buffer,\r
85 IN UINTN Length,\r
86 IN UINT64 Value\r
87 )\r
88{\r
89 do {\r
90 ((UINT64*)Buffer)[--Length] = Value;\r
91 } while (Length != 0);\r
92 return Buffer;\r
93}\r
94\r
95/**\r
96 Set Buffer to 0 for Size bytes.\r
97\r
98 @param Buffer Memory to set.\r
99 @param Size Number of bytes to set\r
100\r
101 @return Buffer\r
102\r
103**/\r
104VOID *\r
105EFIAPI\r
106InternalMemZeroMem (\r
107 OUT VOID *Buffer,\r
108 IN UINTN Length\r
109 )\r
110{\r
111 return InternalMemSetMem (Buffer, Length, 0);\r
112}\r
113\r
114/**\r
115 Compares two memory buffers of a given length.\r
116\r
117 @param DestinationBuffer First memory buffer\r
118 @param SourceBuffer Second memory buffer\r
119 @param Length Length of DestinationBuffer and SourceBuffer memory\r
120 regions to compare. Must be non-zero.\r
121\r
122 @retval 0 if MemOne == MemTwo\r
123\r
124**/\r
125INTN\r
126EFIAPI\r
127InternalMemCompareMem (\r
128 IN CONST VOID *DestinationBuffer,\r
129 IN CONST VOID *SourceBuffer,\r
130 IN UINTN Length\r
131 )\r
132{\r
133 while ((--Length != 0) &&\r
134 (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {\r
135 DestinationBuffer = (INT8*)DestinationBuffer + 1;\r
136 SourceBuffer = (INT8*)SourceBuffer + 1;\r
137 }\r
138 return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer;\r
139}\r
140\r
141/**\r
142 Scans a target buffer for an 8-bit value, and returns a pointer to the\r
143 matching 8-bit value in the target buffer.\r
144\r
145 @param Buffer Pointer to the target buffer to scan.\r
146 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
147 @param Value Value to search for in the target buffer.\r
148\r
149 @return Pointer to the first occurrence or NULL if not found.\r
150\r
151**/\r
152CONST VOID *\r
153EFIAPI\r
154InternalMemScanMem8 (\r
155 IN CONST VOID *Buffer,\r
156 IN UINTN Length,\r
157 IN UINT8 Value\r
158 )\r
159{\r
160 CONST UINT8 *Pointer;\r
161\r
162 Pointer = (CONST UINT8*)Buffer;\r
163 do {\r
164 if (*(Pointer++) == Value) {\r
165 return Pointer;\r
166 }\r
167 } while (--Length != 0);\r
168 return NULL;\r
169}\r
170\r
171/**\r
172 Scans a target buffer for a 16-bit value, and returns a pointer to the\r
173 matching 16-bit value in the target buffer.\r
174\r
175 @param Buffer Pointer to the target buffer to scan.\r
176 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
177 @param Value Value to search for in the target buffer.\r
178\r
179 @return Pointer to the first occurrence or NULL if not found.\r
180\r
181**/\r
182CONST VOID *\r
183EFIAPI\r
184InternalMemScanMem16 (\r
185 IN CONST VOID *Buffer,\r
186 IN UINTN Length,\r
187 IN UINT16 Value\r
188 )\r
189{\r
190 CONST UINT16 *Pointer;\r
191\r
192 Pointer = (CONST UINT16*)Buffer;\r
193 do {\r
194 if (*(Pointer++) == Value) {\r
195 return Pointer;\r
196 }\r
197 } while (--Length != 0);\r
198 return NULL;\r
199}\r
200\r
201/**\r
202 Scans a target buffer for a 32-bit value, and returns a pointer to the\r
203 matching 32-bit value in the target buffer.\r
204\r
205 @param Buffer Pointer to the target buffer to scan.\r
206 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
207 @param Value Value to search for in the target buffer.\r
208\r
209 @return Pointer to the first occurrence or NULL if not found.\r
210\r
211**/\r
212CONST VOID *\r
213EFIAPI\r
214InternalMemScanMem32 (\r
215 IN CONST VOID *Buffer,\r
216 IN UINTN Length,\r
217 IN UINT32 Value\r
218 )\r
219{\r
220 CONST UINT32 *Pointer;\r
221\r
222 Pointer = (CONST UINT32*)Buffer;\r
223 do {\r
224 if (*(Pointer++) == Value) {\r
225 return Pointer;\r
226 }\r
227 } while (--Length != 0);\r
228 return NULL;\r
229}\r
230\r
231/**\r
232 Scans a target buffer for a 64-bit value, and returns a pointer to the\r
233 matching 64-bit value in the target buffer.\r
234\r
235 @param Buffer Pointer to the target buffer to scan.\r
236 @param Length Number of bytes in Buffer to scan. Must be non-zero.\r
237 @param Value Value to search for in the target buffer.\r
238\r
239 @return Pointer to the first occurrence or NULL if not found.\r
240\r
241**/\r
242CONST VOID *\r
243EFIAPI\r
244InternalMemScanMem64 (\r
245 IN CONST VOID *Buffer,\r
246 IN UINTN Length,\r
247 IN UINT64 Value\r
248 )\r
249{\r
250 CONST UINT64 *Pointer;\r
251\r
252 Pointer = (CONST UINT64*)Buffer;\r
253 do {\r
254 if (*(Pointer++) == Value) {\r
255 return Pointer;\r
256 }\r
257 } while (--Length != 0);\r
258 return NULL;\r
259}\r