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