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