]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Architecture Independent Base Memory Library Implementation.\r | |
3 | \r | |
4 | The following BaseMemoryLib instances contain the same copy of this file:\r | |
5 | BaseMemoryLib\r | |
6 | PeiMemoryLib\r | |
7 | UefiMemoryLib\r | |
8 | \r | |
9 | Copyright (c) 2006 - 2009, Intel Corporation<BR>\r | |
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 | |
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 | |
25 | @param Buffer Pointer to the target buffer to fill.\r | |
26 | @param Length Count of 16-bit value to fill.\r | |
27 | @param Value Value with which to fill Length bytes of Buffer.\r | |
28 | \r | |
29 | @return Buffer\r | |
30 | \r | |
31 | **/\r | |
32 | VOID *\r | |
33 | EFIAPI\r | |
34 | InternalMemSetMem16 (\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 | |
49 | @param Buffer Pointer to the target buffer to fill.\r | |
50 | @param Length Count of 32-bit value to fill.\r | |
51 | @param Value Value with which to fill Length bytes of Buffer.\r | |
52 | \r | |
53 | @return Buffer\r | |
54 | \r | |
55 | **/\r | |
56 | VOID *\r | |
57 | EFIAPI\r | |
58 | InternalMemSetMem32 (\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 | |
73 | @param Buffer Pointer to the target buffer to fill.\r | |
74 | @param Length Count of 64-bit value to fill.\r | |
75 | @param Value Value with which to fill Length bytes of Buffer.\r | |
76 | \r | |
77 | @return Buffer\r | |
78 | \r | |
79 | **/\r | |
80 | VOID *\r | |
81 | EFIAPI\r | |
82 | InternalMemSetMem64 (\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 | |
98 | @param Length Number of bytes to set\r | |
99 | \r | |
100 | @return Buffer\r | |
101 | \r | |
102 | **/\r | |
103 | VOID *\r | |
104 | EFIAPI\r | |
105 | InternalMemZeroMem (\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 | |
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 | |
124 | \r | |
125 | **/\r | |
126 | INTN\r | |
127 | EFIAPI\r | |
128 | InternalMemCompareMem (\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 | |
146 | @param Buffer Pointer to the target buffer to scan.\r | |
147 | @param Length Count of 8-bit value to scan. Must be non-zero.\r | |
148 | @param Value Value to search for in the target buffer.\r | |
149 | \r | |
150 | @return Pointer to the first occurrence or NULL if not found.\r | |
151 | \r | |
152 | **/\r | |
153 | CONST VOID *\r | |
154 | EFIAPI\r | |
155 | InternalMemScanMem8 (\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 | |
176 | @param Buffer Pointer to the target buffer to scan.\r | |
177 | @param Length Count of 16-bit value to scan. Must be non-zero.\r | |
178 | @param Value Value to search for in the target buffer.\r | |
179 | \r | |
180 | @return Pointer to the first occurrence or NULL if not found.\r | |
181 | \r | |
182 | **/\r | |
183 | CONST VOID *\r | |
184 | EFIAPI\r | |
185 | InternalMemScanMem16 (\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 | |
206 | @param Buffer Pointer to the target buffer to scan.\r | |
207 | @param Length Count of 32-bit value to scan. Must be non-zero.\r | |
208 | @param Value Value to search for in the target buffer.\r | |
209 | \r | |
210 | @return Pointer to the first occurrence or NULL if not found.\r | |
211 | \r | |
212 | **/\r | |
213 | CONST VOID *\r | |
214 | EFIAPI\r | |
215 | InternalMemScanMem32 (\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 | |
236 | @param Buffer Pointer to the target buffer to scan.\r | |
237 | @param Length Count of 64-bit value to scan. Must be non-zero.\r | |
238 | @param Value Value to search for in the target buffer.\r | |
239 | \r | |
240 | @return Pointer to the first occurrence or NULL if not found.\r | |
241 | \r | |
242 | **/\r | |
243 | CONST VOID *\r | |
244 | EFIAPI\r | |
245 | InternalMemScanMem64 (\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 |