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