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