]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
Minor grammatical work--mostly adding periods. Items with ONLY period added did...
[mirror_edk2.git] / MdePkg / Library / PeiMemoryLib / MemLibGeneric.c
CommitLineData
dd51a993 1/** @file\r
2 Architecture Independent Base Memory Library Implementation.\r
3\r
1fef058f 4 The following BaseMemoryLib instances contain the same copy of this file:\r
5 BaseMemoryLib\r
6 PeiMemoryLib\r
7 UefiMemoryLib\r
8\r
19388d29
HT
9 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
10 This program and the accompanying materials\r
dd51a993 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
2fc59a00 13 http://opensource.org/licenses/bsd-license.php.\r
dd51a993 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
dd51a993 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
2fc59a00 25 @param Buffer The pointer to the target buffer to fill.\r
26 @param Length The count of 16-bit value to fill.\r
27 @param Value The value with which to fill Length bytes of Buffer.\r
dd51a993 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
2fc59a00 49 @param Buffer The pointer to the target buffer to fill.\r
50 @param Length The count of 32-bit value to fill.\r
51 @param Value The value with which to fill Length bytes of Buffer.\r
dd51a993 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
2fc59a00 73 @param Buffer The pointer to the target buffer to fill.\r
74 @param Length The count of 64-bit value to fill.\r
75 @param Value The value with which to fill Length bytes of Buffer.\r
dd51a993 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
2fc59a00 98 @param Length The number of bytes to set\r
dd51a993 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
d531bfee 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
dd51a993 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
2fc59a00 146 @param Buffer The pointer to the target buffer to scan.\r
147 @param Length The count of 8-bit value to scan. Must be non-zero.\r
148 @param Value The value to search for in the target buffer.\r
dd51a993 149\r
2fc59a00 150 @return The pointer to the first occurrence or NULL if not found.\r
dd51a993 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
165 if (*(Pointer++) == Value) {\r
166 return Pointer;\r
167 }\r
168 } while (--Length != 0);\r
169 return NULL;\r
170}\r
171\r
172/**\r
173 Scans a target buffer for a 16-bit value, and returns a pointer to the\r
174 matching 16-bit value in the target buffer.\r
175\r
2fc59a00 176 @param Buffer The pointer to the target buffer to scan.\r
177 @param Length The count of 16-bit value to scan. Must be non-zero.\r
178 @param Value The value to search for in the target buffer.\r
dd51a993 179\r
2fc59a00 180 @return The pointer to the first occurrence or NULL if not found.\r
dd51a993 181\r
182**/\r
183CONST VOID *\r
184EFIAPI\r
185InternalMemScanMem16 (\r
186 IN CONST VOID *Buffer,\r
187 IN UINTN Length,\r
188 IN UINT16 Value\r
189 )\r
190{\r
191 CONST UINT16 *Pointer;\r
192\r
193 Pointer = (CONST UINT16*)Buffer;\r
194 do {\r
195 if (*(Pointer++) == Value) {\r
196 return Pointer;\r
197 }\r
198 } while (--Length != 0);\r
199 return NULL;\r
200}\r
201\r
202/**\r
203 Scans a target buffer for a 32-bit value, and returns a pointer to the\r
204 matching 32-bit value in the target buffer.\r
205\r
2fc59a00 206 @param Buffer The pointer to the target buffer to scan.\r
207 @param Length The count of 32-bit value to scan. Must be non-zero.\r
208 @param Value The value to search for in the target buffer.\r
dd51a993 209\r
2fc59a00 210 @return The pointer to the first occurrence or NULL if not found.\r
dd51a993 211\r
212**/\r
213CONST VOID *\r
214EFIAPI\r
215InternalMemScanMem32 (\r
216 IN CONST VOID *Buffer,\r
217 IN UINTN Length,\r
218 IN UINT32 Value\r
219 )\r
220{\r
221 CONST UINT32 *Pointer;\r
222\r
223 Pointer = (CONST UINT32*)Buffer;\r
224 do {\r
225 if (*(Pointer++) == Value) {\r
226 return Pointer;\r
227 }\r
228 } while (--Length != 0);\r
229 return NULL;\r
230}\r
231\r
232/**\r
233 Scans a target buffer for a 64-bit value, and returns a pointer to the\r
234 matching 64-bit value in the target buffer.\r
235\r
2fc59a00 236 @param Buffer The pointer to the target buffer to scan.\r
237 @param Length The count of 64-bit value to scan. Must be non-zero.\r
238 @param Value The value to search for in the target buffer.\r
dd51a993 239\r
2fc59a00 240 @return The pointer to the first occurrence or NULL if not found.\r
dd51a993 241\r
242**/\r
243CONST VOID *\r
244EFIAPI\r
245InternalMemScanMem64 (\r
246 IN CONST VOID *Buffer,\r
247 IN UINTN Length,\r
248 IN UINT64 Value\r
249 )\r
250{\r
251 CONST UINT64 *Pointer;\r
252\r
253 Pointer = (CONST UINT64*)Buffer;\r
254 do {\r
255 if (*(Pointer++) == Value) {\r
256 return Pointer;\r
257 }\r
258 } while (--Length != 0);\r
259 return NULL;\r
260}\r