]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Bit field functions of BaseLib.\r | |
3 | \r | |
94952554 | 4 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
bb817c56 | 5 | This program and the accompanying materials\r |
e1f414b6 | 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 | |
127010dd | 8 | http://opensource.org/licenses/bsd-license.php.\r |
e1f414b6 | 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 | |
e1f414b6 | 13 | **/\r |
14 | \r | |
e1f414b6 | 15 | #include "BaseLibInternals.h"\r |
16 | \r | |
17 | /**\r | |
2fc60b70 | 18 | Worker function that returns a bit field from Operand.\r |
e1f414b6 | 19 | \r |
20 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
21 | \r | |
22 | @param Operand Operand on which to perform the bitfield operation.\r | |
23 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
24 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
25 | \r | |
26 | @return The bit field read.\r | |
27 | \r | |
28 | **/\r | |
28ca72bc | 29 | UINTN\r |
38bbd3d9 | 30 | EFIAPI\r |
80151e53 | 31 | InternalBaseLibBitFieldReadUint (\r |
28ca72bc | 32 | IN UINTN Operand,\r |
e1f414b6 | 33 | IN UINTN StartBit,\r |
34 | IN UINTN EndBit\r | |
35 | )\r | |
36 | {\r | |
37 | //\r | |
28ca72bc | 38 | // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r |
e1f414b6 | 39 | // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.\r |
40 | //\r | |
28ca72bc | 41 | return (Operand & ~((UINTN)-2 << EndBit)) >> StartBit;\r |
e1f414b6 | 42 | }\r |
43 | \r | |
44 | /**\r | |
2fc60b70 | 45 | Worker function that reads a bit field from Operand, performs a bitwise OR,\r |
e1f414b6 | 46 | and returns the result.\r |
47 | \r | |
48 | Performs a bitwise OR between the bit field specified by StartBit and EndBit\r | |
49 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
50 | preserved. The new value is returned.\r | |
51 | \r | |
94952554 LG |
52 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
53 | \r | |
e1f414b6 | 54 | @param Operand Operand on which to perform the bitfield operation.\r |
55 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
56 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
127010dd | 57 | @param OrData The value to OR with the read value from the value.\r |
e1f414b6 | 58 | \r |
59 | @return The new value.\r | |
60 | \r | |
61 | **/\r | |
28ca72bc | 62 | UINTN\r |
38bbd3d9 | 63 | EFIAPI\r |
80151e53 | 64 | InternalBaseLibBitFieldOrUint (\r |
28ca72bc | 65 | IN UINTN Operand,\r |
e1f414b6 | 66 | IN UINTN StartBit,\r |
67 | IN UINTN EndBit,\r | |
28ca72bc | 68 | IN UINTN OrData\r |
e1f414b6 | 69 | )\r |
70 | {\r | |
94952554 LG |
71 | //\r |
72 | // Higher bits in OrData those are not used must be zero. \r | |
73 | //\r | |
74 | ASSERT ((OrData >> (EndBit - StartBit + 1)) == 0);\r | |
75 | \r | |
e1f414b6 | 76 | //\r |
28ca72bc | 77 | // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r |
e1f414b6 | 78 | // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.\r |
79 | //\r | |
28ca72bc | 80 | return Operand | ((OrData << StartBit) & ~((UINTN) -2 << EndBit));\r |
e1f414b6 | 81 | }\r |
82 | \r | |
83 | /**\r | |
2fc60b70 | 84 | Worker function that reads a bit field from Operand, performs a bitwise AND,\r |
e1f414b6 | 85 | and returns the result.\r |
86 | \r | |
87 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
88 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
89 | preserved. The new value is returned.\r | |
90 | \r | |
94952554 LG |
91 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
92 | \r | |
e1f414b6 | 93 | @param Operand Operand on which to perform the bitfield operation.\r |
94 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
95 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
127010dd | 96 | @param AndData The value to And with the read value from the value.\r |
e1f414b6 | 97 | \r |
98 | @return The new value.\r | |
99 | \r | |
100 | **/\r | |
28ca72bc | 101 | UINTN\r |
38bbd3d9 | 102 | EFIAPI\r |
80151e53 | 103 | InternalBaseLibBitFieldAndUint (\r |
28ca72bc | 104 | IN UINTN Operand,\r |
e1f414b6 | 105 | IN UINTN StartBit,\r |
106 | IN UINTN EndBit,\r | |
28ca72bc | 107 | IN UINTN AndData\r |
e1f414b6 | 108 | )\r |
109 | {\r | |
94952554 LG |
110 | //\r |
111 | // Higher bits in AndData those are not used must be zero. \r | |
112 | //\r | |
113 | ASSERT ((AndData >> (EndBit - StartBit + 1)) == 0);\r | |
114 | \r | |
e1f414b6 | 115 | //\r |
28ca72bc | 116 | // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit]\r |
e1f414b6 | 117 | // are 1's while bit[EndBit + 1] thru the most significant bit are 0's.\r |
118 | //\r | |
28ca72bc | 119 | return Operand & ~((~AndData << StartBit) & ~((UINTN)-2 << EndBit));\r |
e1f414b6 | 120 | }\r |
121 | \r | |
122 | /**\r | |
123 | Returns a bit field from an 8-bit value.\r | |
124 | \r | |
125 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
126 | \r | |
127 | If 8-bit operations are not supported, then ASSERT().\r | |
128 | If StartBit is greater than 7, then ASSERT().\r | |
129 | If EndBit is greater than 7, then ASSERT().\r | |
130 | If EndBit is less than StartBit, then ASSERT().\r | |
131 | \r | |
132 | @param Operand Operand on which to perform the bitfield operation.\r | |
133 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
134 | Range 0..7.\r | |
135 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
136 | Range 0..7.\r | |
137 | \r | |
138 | @return The bit field read.\r | |
139 | \r | |
140 | **/\r | |
141 | UINT8\r | |
142 | EFIAPI\r | |
143 | BitFieldRead8 (\r | |
144 | IN UINT8 Operand,\r | |
145 | IN UINTN StartBit,\r | |
146 | IN UINTN EndBit\r | |
147 | )\r | |
148 | {\r | |
5385a579 | 149 | ASSERT (EndBit < 8);\r |
e1f414b6 | 150 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 151 | return (UINT8)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);\r |
e1f414b6 | 152 | }\r |
153 | \r | |
154 | /**\r | |
155 | Writes a bit field to an 8-bit value, and returns the result.\r | |
156 | \r | |
157 | Writes Value to the bit field specified by the StartBit and the EndBit in\r | |
158 | Operand. All other bits in Operand are preserved. The new 8-bit value is\r | |
159 | returned.\r | |
160 | \r | |
161 | If 8-bit operations are not supported, then ASSERT().\r | |
162 | If StartBit is greater than 7, then ASSERT().\r | |
163 | If EndBit is greater than 7, then ASSERT().\r | |
164 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 165 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 166 | \r |
167 | @param Operand Operand on which to perform the bitfield operation.\r | |
168 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
169 | Range 0..7.\r | |
170 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
171 | Range 0..7.\r | |
2fc59a00 | 172 | @param Value The new value of the bit field.\r |
e1f414b6 | 173 | \r |
174 | @return The new 8-bit value.\r | |
175 | \r | |
176 | **/\r | |
177 | UINT8\r | |
178 | EFIAPI\r | |
179 | BitFieldWrite8 (\r | |
180 | IN UINT8 Operand,\r | |
181 | IN UINTN StartBit,\r | |
182 | IN UINTN EndBit,\r | |
183 | IN UINT8 Value\r | |
184 | )\r | |
185 | {\r | |
5385a579 | 186 | ASSERT (EndBit < 8);\r |
e1f414b6 | 187 | ASSERT (StartBit <= EndBit);\r |
188 | return BitFieldAndThenOr8 (Operand, StartBit, EndBit, 0, Value);\r | |
189 | }\r | |
190 | \r | |
191 | /**\r | |
192 | Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the\r | |
193 | result.\r | |
194 | \r | |
62991af2 | 195 | Performs a bitwise OR between the bit field specified by StartBit\r |
e1f414b6 | 196 | and EndBit in Operand and the value specified by OrData. All other bits in\r |
197 | Operand are preserved. The new 8-bit value is returned.\r | |
198 | \r | |
199 | If 8-bit operations are not supported, then ASSERT().\r | |
200 | If StartBit is greater than 7, then ASSERT().\r | |
201 | If EndBit is greater than 7, then ASSERT().\r | |
202 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 203 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 204 | \r |
205 | @param Operand Operand on which to perform the bitfield operation.\r | |
206 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
207 | Range 0..7.\r | |
208 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
209 | Range 0..7.\r | |
127010dd | 210 | @param OrData The value to OR with the read value from the value.\r |
e1f414b6 | 211 | \r |
212 | @return The new 8-bit value.\r | |
213 | \r | |
214 | **/\r | |
215 | UINT8\r | |
216 | EFIAPI\r | |
217 | BitFieldOr8 (\r | |
218 | IN UINT8 Operand,\r | |
219 | IN UINTN StartBit,\r | |
220 | IN UINTN EndBit,\r | |
221 | IN UINT8 OrData\r | |
222 | )\r | |
223 | {\r | |
5385a579 | 224 | ASSERT (EndBit < 8);\r |
e1f414b6 | 225 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 226 | return (UINT8)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);\r |
e1f414b6 | 227 | }\r |
228 | \r | |
229 | /**\r | |
230 | Reads a bit field from an 8-bit value, performs a bitwise AND, and returns\r | |
231 | the result.\r | |
232 | \r | |
233 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
234 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
235 | preserved. The new 8-bit value is returned.\r | |
236 | \r | |
237 | If 8-bit operations are not supported, then ASSERT().\r | |
238 | If StartBit is greater than 7, then ASSERT().\r | |
239 | If EndBit is greater than 7, then ASSERT().\r | |
240 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 241 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 242 | \r |
243 | @param Operand Operand on which to perform the bitfield operation.\r | |
244 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
245 | Range 0..7.\r | |
246 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
247 | Range 0..7.\r | |
248 | @param AndData The value to AND with the read value from the value.\r | |
249 | \r | |
250 | @return The new 8-bit value.\r | |
251 | \r | |
252 | **/\r | |
253 | UINT8\r | |
254 | EFIAPI\r | |
255 | BitFieldAnd8 (\r | |
256 | IN UINT8 Operand,\r | |
257 | IN UINTN StartBit,\r | |
258 | IN UINTN EndBit,\r | |
259 | IN UINT8 AndData\r | |
260 | )\r | |
261 | {\r | |
5385a579 | 262 | ASSERT (EndBit < 8);\r |
e1f414b6 | 263 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 264 | return (UINT8)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);\r |
e1f414b6 | 265 | }\r |
266 | \r | |
267 | /**\r | |
268 | Reads a bit field from an 8-bit value, performs a bitwise AND followed by a\r | |
269 | bitwise OR, and returns the result.\r | |
270 | \r | |
271 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
62991af2 | 272 | in Operand and the value specified by AndData, followed by a bitwise \r |
273 | OR with value specified by OrData. All other bits in Operand are\r | |
e1f414b6 | 274 | preserved. The new 8-bit value is returned.\r |
275 | \r | |
276 | If 8-bit operations are not supported, then ASSERT().\r | |
277 | If StartBit is greater than 7, then ASSERT().\r | |
278 | If EndBit is greater than 7, then ASSERT().\r | |
279 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 LG |
280 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
281 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
e1f414b6 | 282 | \r |
283 | @param Operand Operand on which to perform the bitfield operation.\r | |
284 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
285 | Range 0..7.\r | |
286 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
287 | Range 0..7.\r | |
288 | @param AndData The value to AND with the read value from the value.\r | |
289 | @param OrData The value to OR with the result of the AND operation.\r | |
290 | \r | |
291 | @return The new 8-bit value.\r | |
292 | \r | |
293 | **/\r | |
294 | UINT8\r | |
295 | EFIAPI\r | |
296 | BitFieldAndThenOr8 (\r | |
297 | IN UINT8 Operand,\r | |
298 | IN UINTN StartBit,\r | |
299 | IN UINTN EndBit,\r | |
300 | IN UINT8 AndData,\r | |
301 | IN UINT8 OrData\r | |
302 | )\r | |
303 | {\r | |
5385a579 | 304 | ASSERT (EndBit < 8);\r |
e1f414b6 | 305 | ASSERT (StartBit <= EndBit);\r |
306 | return BitFieldOr8 (\r | |
307 | BitFieldAnd8 (Operand, StartBit, EndBit, AndData),\r | |
308 | StartBit,\r | |
309 | EndBit,\r | |
310 | OrData\r | |
311 | );\r | |
312 | }\r | |
313 | \r | |
314 | /**\r | |
315 | Returns a bit field from a 16-bit value.\r | |
316 | \r | |
317 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
318 | \r | |
319 | If 16-bit operations are not supported, then ASSERT().\r | |
320 | If StartBit is greater than 15, then ASSERT().\r | |
321 | If EndBit is greater than 15, then ASSERT().\r | |
322 | If EndBit is less than StartBit, then ASSERT().\r | |
323 | \r | |
324 | @param Operand Operand on which to perform the bitfield operation.\r | |
325 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
326 | Range 0..15.\r | |
327 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
328 | Range 0..15.\r | |
329 | \r | |
330 | @return The bit field read.\r | |
331 | \r | |
332 | **/\r | |
333 | UINT16\r | |
334 | EFIAPI\r | |
335 | BitFieldRead16 (\r | |
336 | IN UINT16 Operand,\r | |
337 | IN UINTN StartBit,\r | |
338 | IN UINTN EndBit\r | |
339 | )\r | |
340 | {\r | |
5385a579 | 341 | ASSERT (EndBit < 16);\r |
e1f414b6 | 342 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 343 | return (UINT16)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);\r |
e1f414b6 | 344 | }\r |
345 | \r | |
346 | /**\r | |
347 | Writes a bit field to a 16-bit value, and returns the result.\r | |
348 | \r | |
349 | Writes Value to the bit field specified by the StartBit and the EndBit in\r | |
350 | Operand. All other bits in Operand are preserved. The new 16-bit value is\r | |
351 | returned.\r | |
352 | \r | |
353 | If 16-bit operations are not supported, then ASSERT().\r | |
354 | If StartBit is greater than 15, then ASSERT().\r | |
355 | If EndBit is greater than 15, then ASSERT().\r | |
356 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 357 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 358 | \r |
359 | @param Operand Operand on which to perform the bitfield operation.\r | |
360 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
361 | Range 0..15.\r | |
362 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
363 | Range 0..15.\r | |
2fc59a00 | 364 | @param Value The new value of the bit field.\r |
e1f414b6 | 365 | \r |
366 | @return The new 16-bit value.\r | |
367 | \r | |
368 | **/\r | |
369 | UINT16\r | |
370 | EFIAPI\r | |
371 | BitFieldWrite16 (\r | |
372 | IN UINT16 Operand,\r | |
373 | IN UINTN StartBit,\r | |
374 | IN UINTN EndBit,\r | |
375 | IN UINT16 Value\r | |
376 | )\r | |
377 | {\r | |
5385a579 | 378 | ASSERT (EndBit < 16);\r |
e1f414b6 | 379 | ASSERT (StartBit <= EndBit);\r |
380 | return BitFieldAndThenOr16 (Operand, StartBit, EndBit, 0, Value);\r | |
381 | }\r | |
382 | \r | |
383 | /**\r | |
384 | Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the\r | |
385 | result.\r | |
386 | \r | |
62991af2 | 387 | Performs a bitwise OR between the bit field specified by StartBit\r |
e1f414b6 | 388 | and EndBit in Operand and the value specified by OrData. All other bits in\r |
389 | Operand are preserved. The new 16-bit value is returned.\r | |
390 | \r | |
391 | If 16-bit operations are not supported, then ASSERT().\r | |
392 | If StartBit is greater than 15, then ASSERT().\r | |
393 | If EndBit is greater than 15, then ASSERT().\r | |
394 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 395 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 396 | \r |
397 | @param Operand Operand on which to perform the bitfield operation.\r | |
398 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
399 | Range 0..15.\r | |
400 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
401 | Range 0..15.\r | |
127010dd | 402 | @param OrData The value to OR with the read value from the value.\r |
e1f414b6 | 403 | \r |
404 | @return The new 16-bit value.\r | |
405 | \r | |
406 | **/\r | |
407 | UINT16\r | |
408 | EFIAPI\r | |
409 | BitFieldOr16 (\r | |
410 | IN UINT16 Operand,\r | |
411 | IN UINTN StartBit,\r | |
412 | IN UINTN EndBit,\r | |
413 | IN UINT16 OrData\r | |
414 | )\r | |
415 | {\r | |
5385a579 | 416 | ASSERT (EndBit < 16);\r |
e1f414b6 | 417 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 418 | return (UINT16)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);\r |
e1f414b6 | 419 | }\r |
420 | \r | |
421 | /**\r | |
422 | Reads a bit field from a 16-bit value, performs a bitwise AND, and returns\r | |
423 | the result.\r | |
424 | \r | |
425 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
426 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
427 | preserved. The new 16-bit value is returned.\r | |
428 | \r | |
429 | If 16-bit operations are not supported, then ASSERT().\r | |
430 | If StartBit is greater than 15, then ASSERT().\r | |
431 | If EndBit is greater than 15, then ASSERT().\r | |
432 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 433 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 434 | \r |
435 | @param Operand Operand on which to perform the bitfield operation.\r | |
436 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
437 | Range 0..15.\r | |
438 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
439 | Range 0..15.\r | |
127010dd | 440 | @param AndData The value to AND with the read value from the value.\r |
e1f414b6 | 441 | \r |
442 | @return The new 16-bit value.\r | |
443 | \r | |
444 | **/\r | |
445 | UINT16\r | |
446 | EFIAPI\r | |
447 | BitFieldAnd16 (\r | |
448 | IN UINT16 Operand,\r | |
449 | IN UINTN StartBit,\r | |
450 | IN UINTN EndBit,\r | |
451 | IN UINT16 AndData\r | |
452 | )\r | |
453 | {\r | |
5385a579 | 454 | ASSERT (EndBit < 16);\r |
e1f414b6 | 455 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 456 | return (UINT16)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);\r |
e1f414b6 | 457 | }\r |
458 | \r | |
459 | /**\r | |
460 | Reads a bit field from a 16-bit value, performs a bitwise AND followed by a\r | |
461 | bitwise OR, and returns the result.\r | |
462 | \r | |
463 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
62991af2 | 464 | in Operand and the value specified by AndData, followed by a bitwise \r |
465 | OR with value specified by OrData. All other bits in Operand are\r | |
e1f414b6 | 466 | preserved. The new 16-bit value is returned.\r |
467 | \r | |
468 | If 16-bit operations are not supported, then ASSERT().\r | |
469 | If StartBit is greater than 15, then ASSERT().\r | |
470 | If EndBit is greater than 15, then ASSERT().\r | |
471 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 LG |
472 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
473 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
e1f414b6 | 474 | \r |
475 | @param Operand Operand on which to perform the bitfield operation.\r | |
476 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
477 | Range 0..15.\r | |
478 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
479 | Range 0..15.\r | |
480 | @param AndData The value to AND with the read value from the value.\r | |
481 | @param OrData The value to OR with the result of the AND operation.\r | |
482 | \r | |
483 | @return The new 16-bit value.\r | |
484 | \r | |
485 | **/\r | |
486 | UINT16\r | |
487 | EFIAPI\r | |
488 | BitFieldAndThenOr16 (\r | |
489 | IN UINT16 Operand,\r | |
490 | IN UINTN StartBit,\r | |
491 | IN UINTN EndBit,\r | |
492 | IN UINT16 AndData,\r | |
493 | IN UINT16 OrData\r | |
494 | )\r | |
495 | {\r | |
5385a579 | 496 | ASSERT (EndBit < 16);\r |
e1f414b6 | 497 | ASSERT (StartBit <= EndBit);\r |
498 | return BitFieldOr16 (\r | |
499 | BitFieldAnd16 (Operand, StartBit, EndBit, AndData),\r | |
500 | StartBit,\r | |
501 | EndBit,\r | |
502 | OrData\r | |
503 | );\r | |
504 | }\r | |
505 | \r | |
506 | /**\r | |
507 | Returns a bit field from a 32-bit value.\r | |
508 | \r | |
509 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
510 | \r | |
511 | If 32-bit operations are not supported, then ASSERT().\r | |
512 | If StartBit is greater than 31, then ASSERT().\r | |
513 | If EndBit is greater than 31, then ASSERT().\r | |
514 | If EndBit is less than StartBit, then ASSERT().\r | |
515 | \r | |
516 | @param Operand Operand on which to perform the bitfield operation.\r | |
517 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
518 | Range 0..31.\r | |
519 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
520 | Range 0..31.\r | |
521 | \r | |
522 | @return The bit field read.\r | |
523 | \r | |
524 | **/\r | |
525 | UINT32\r | |
526 | EFIAPI\r | |
527 | BitFieldRead32 (\r | |
528 | IN UINT32 Operand,\r | |
529 | IN UINTN StartBit,\r | |
530 | IN UINTN EndBit\r | |
531 | )\r | |
532 | {\r | |
5385a579 | 533 | ASSERT (EndBit < 32);\r |
e1f414b6 | 534 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 535 | return (UINT32)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit);\r |
e1f414b6 | 536 | }\r |
537 | \r | |
538 | /**\r | |
539 | Writes a bit field to a 32-bit value, and returns the result.\r | |
540 | \r | |
541 | Writes Value to the bit field specified by the StartBit and the EndBit in\r | |
542 | Operand. All other bits in Operand are preserved. The new 32-bit value is\r | |
543 | returned.\r | |
544 | \r | |
545 | If 32-bit operations are not supported, then ASSERT().\r | |
546 | If StartBit is greater than 31, then ASSERT().\r | |
547 | If EndBit is greater than 31, then ASSERT().\r | |
548 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 549 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 550 | \r |
551 | @param Operand Operand on which to perform the bitfield operation.\r | |
552 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
553 | Range 0..31.\r | |
554 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
555 | Range 0..31.\r | |
2fc59a00 | 556 | @param Value The new value of the bit field.\r |
e1f414b6 | 557 | \r |
558 | @return The new 32-bit value.\r | |
559 | \r | |
560 | **/\r | |
561 | UINT32\r | |
562 | EFIAPI\r | |
563 | BitFieldWrite32 (\r | |
564 | IN UINT32 Operand,\r | |
565 | IN UINTN StartBit,\r | |
566 | IN UINTN EndBit,\r | |
567 | IN UINT32 Value\r | |
568 | )\r | |
569 | {\r | |
5385a579 | 570 | ASSERT (EndBit < 32);\r |
e1f414b6 | 571 | ASSERT (StartBit <= EndBit);\r |
572 | return BitFieldAndThenOr32 (Operand, StartBit, EndBit, 0, Value);\r | |
573 | }\r | |
574 | \r | |
575 | /**\r | |
576 | Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the\r | |
577 | result.\r | |
578 | \r | |
62991af2 | 579 | Performs a bitwise OR between the bit field specified by StartBit\r |
e1f414b6 | 580 | and EndBit in Operand and the value specified by OrData. All other bits in\r |
581 | Operand are preserved. The new 32-bit value is returned.\r | |
582 | \r | |
583 | If 32-bit operations are not supported, then ASSERT().\r | |
584 | If StartBit is greater than 31, then ASSERT().\r | |
585 | If EndBit is greater than 31, then ASSERT().\r | |
586 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 587 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 588 | \r |
589 | @param Operand Operand on which to perform the bitfield operation.\r | |
590 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
591 | Range 0..31.\r | |
592 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
593 | Range 0..31.\r | |
127010dd | 594 | @param OrData The value to OR with the read value from the value.\r |
e1f414b6 | 595 | \r |
596 | @return The new 32-bit value.\r | |
597 | \r | |
598 | **/\r | |
599 | UINT32\r | |
600 | EFIAPI\r | |
601 | BitFieldOr32 (\r | |
602 | IN UINT32 Operand,\r | |
603 | IN UINTN StartBit,\r | |
604 | IN UINTN EndBit,\r | |
605 | IN UINT32 OrData\r | |
606 | )\r | |
607 | {\r | |
5385a579 | 608 | ASSERT (EndBit < 32);\r |
e1f414b6 | 609 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 610 | return (UINT32)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, OrData);\r |
e1f414b6 | 611 | }\r |
612 | \r | |
613 | /**\r | |
614 | Reads a bit field from a 32-bit value, performs a bitwise AND, and returns\r | |
615 | the result.\r | |
616 | \r | |
617 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
618 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
619 | preserved. The new 32-bit value is returned.\r | |
620 | \r | |
621 | If 32-bit operations are not supported, then ASSERT().\r | |
622 | If StartBit is greater than 31, then ASSERT().\r | |
623 | If EndBit is greater than 31, then ASSERT().\r | |
624 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 625 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 626 | \r |
627 | @param Operand Operand on which to perform the bitfield operation.\r | |
628 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
629 | Range 0..31.\r | |
630 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
631 | Range 0..31.\r | |
127010dd | 632 | @param AndData The value to AND with the read value from the value.\r |
e1f414b6 | 633 | \r |
634 | @return The new 32-bit value.\r | |
635 | \r | |
636 | **/\r | |
637 | UINT32\r | |
638 | EFIAPI\r | |
639 | BitFieldAnd32 (\r | |
640 | IN UINT32 Operand,\r | |
641 | IN UINTN StartBit,\r | |
642 | IN UINTN EndBit,\r | |
643 | IN UINT32 AndData\r | |
644 | )\r | |
645 | {\r | |
5385a579 | 646 | ASSERT (EndBit < 32);\r |
e1f414b6 | 647 | ASSERT (StartBit <= EndBit);\r |
80151e53 | 648 | return (UINT32)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit, AndData);\r |
e1f414b6 | 649 | }\r |
650 | \r | |
651 | /**\r | |
652 | Reads a bit field from a 32-bit value, performs a bitwise AND followed by a\r | |
653 | bitwise OR, and returns the result.\r | |
654 | \r | |
655 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
62991af2 | 656 | in Operand and the value specified by AndData, followed by a bitwise \r |
657 | OR with value specified by OrData. All other bits in Operand are\r | |
e1f414b6 | 658 | preserved. The new 32-bit value is returned.\r |
659 | \r | |
660 | If 32-bit operations are not supported, then ASSERT().\r | |
661 | If StartBit is greater than 31, then ASSERT().\r | |
662 | If EndBit is greater than 31, then ASSERT().\r | |
663 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 LG |
664 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
665 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
e1f414b6 | 666 | \r |
667 | @param Operand Operand on which to perform the bitfield operation.\r | |
668 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
669 | Range 0..31.\r | |
670 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
671 | Range 0..31.\r | |
672 | @param AndData The value to AND with the read value from the value.\r | |
673 | @param OrData The value to OR with the result of the AND operation.\r | |
674 | \r | |
675 | @return The new 32-bit value.\r | |
676 | \r | |
677 | **/\r | |
678 | UINT32\r | |
679 | EFIAPI\r | |
680 | BitFieldAndThenOr32 (\r | |
681 | IN UINT32 Operand,\r | |
682 | IN UINTN StartBit,\r | |
683 | IN UINTN EndBit,\r | |
684 | IN UINT32 AndData,\r | |
685 | IN UINT32 OrData\r | |
686 | )\r | |
687 | {\r | |
5385a579 | 688 | ASSERT (EndBit < 32);\r |
e1f414b6 | 689 | ASSERT (StartBit <= EndBit);\r |
690 | return BitFieldOr32 (\r | |
691 | BitFieldAnd32 (Operand, StartBit, EndBit, AndData),\r | |
692 | StartBit,\r | |
693 | EndBit,\r | |
694 | OrData\r | |
695 | );\r | |
696 | }\r | |
697 | \r | |
698 | /**\r | |
699 | Returns a bit field from a 64-bit value.\r | |
700 | \r | |
701 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
702 | \r | |
703 | If 64-bit operations are not supported, then ASSERT().\r | |
704 | If StartBit is greater than 63, then ASSERT().\r | |
705 | If EndBit is greater than 63, then ASSERT().\r | |
706 | If EndBit is less than StartBit, then ASSERT().\r | |
707 | \r | |
708 | @param Operand Operand on which to perform the bitfield operation.\r | |
709 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
710 | Range 0..63.\r | |
711 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
712 | Range 0..63.\r | |
713 | \r | |
714 | @return The bit field read.\r | |
715 | \r | |
716 | **/\r | |
717 | UINT64\r | |
718 | EFIAPI\r | |
719 | BitFieldRead64 (\r | |
720 | IN UINT64 Operand,\r | |
721 | IN UINTN StartBit,\r | |
722 | IN UINTN EndBit\r | |
723 | )\r | |
724 | {\r | |
5385a579 | 725 | ASSERT (EndBit < 64);\r |
e1f414b6 | 726 | ASSERT (StartBit <= EndBit);\r |
727 | return RShiftU64 (Operand & ~LShiftU64 ((UINT64)-2, EndBit), StartBit);\r | |
728 | }\r | |
729 | \r | |
730 | /**\r | |
731 | Writes a bit field to a 64-bit value, and returns the result.\r | |
732 | \r | |
733 | Writes Value to the bit field specified by the StartBit and the EndBit in\r | |
734 | Operand. All other bits in Operand are preserved. The new 64-bit value is\r | |
735 | returned.\r | |
736 | \r | |
737 | If 64-bit operations are not supported, then ASSERT().\r | |
738 | If StartBit is greater than 63, then ASSERT().\r | |
739 | If EndBit is greater than 63, then ASSERT().\r | |
740 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 741 | If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 742 | \r |
743 | @param Operand Operand on which to perform the bitfield operation.\r | |
744 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
745 | Range 0..63.\r | |
746 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
747 | Range 0..63.\r | |
2fc59a00 | 748 | @param Value The new value of the bit field.\r |
e1f414b6 | 749 | \r |
750 | @return The new 64-bit value.\r | |
751 | \r | |
752 | **/\r | |
753 | UINT64\r | |
754 | EFIAPI\r | |
755 | BitFieldWrite64 (\r | |
756 | IN UINT64 Operand,\r | |
757 | IN UINTN StartBit,\r | |
758 | IN UINTN EndBit,\r | |
759 | IN UINT64 Value\r | |
760 | )\r | |
761 | {\r | |
5385a579 | 762 | ASSERT (EndBit < 64);\r |
e1f414b6 | 763 | ASSERT (StartBit <= EndBit);\r |
764 | return BitFieldAndThenOr64 (Operand, StartBit, EndBit, 0, Value);\r | |
765 | }\r | |
766 | \r | |
767 | /**\r | |
768 | Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the\r | |
769 | result.\r | |
770 | \r | |
62991af2 | 771 | Performs a bitwise OR between the bit field specified by StartBit\r |
e1f414b6 | 772 | and EndBit in Operand and the value specified by OrData. All other bits in\r |
773 | Operand are preserved. The new 64-bit value is returned.\r | |
774 | \r | |
775 | If 64-bit operations are not supported, then ASSERT().\r | |
776 | If StartBit is greater than 63, then ASSERT().\r | |
777 | If EndBit is greater than 63, then ASSERT().\r | |
778 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 779 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 780 | \r |
781 | @param Operand Operand on which to perform the bitfield operation.\r | |
782 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
783 | Range 0..63.\r | |
784 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
785 | Range 0..63.\r | |
786 | @param OrData The value to OR with the read value from the value\r | |
787 | \r | |
788 | @return The new 64-bit value.\r | |
789 | \r | |
790 | **/\r | |
791 | UINT64\r | |
792 | EFIAPI\r | |
793 | BitFieldOr64 (\r | |
794 | IN UINT64 Operand,\r | |
795 | IN UINTN StartBit,\r | |
796 | IN UINTN EndBit,\r | |
797 | IN UINT64 OrData\r | |
798 | )\r | |
799 | {\r | |
800 | UINT64 Value1;\r | |
801 | UINT64 Value2;\r | |
802 | \r | |
5385a579 | 803 | ASSERT (EndBit < 64);\r |
e1f414b6 | 804 | ASSERT (StartBit <= EndBit);\r |
94952554 | 805 | ASSERT (RShiftU64 (OrData, EndBit - StartBit + 1) == 0);\r |
e1f414b6 | 806 | \r |
807 | Value1 = LShiftU64 (OrData, StartBit);\r | |
808 | Value2 = LShiftU64 ((UINT64) - 2, EndBit);\r | |
809 | \r | |
810 | return Operand | (Value1 & ~Value2);\r | |
811 | }\r | |
812 | \r | |
813 | /**\r | |
814 | Reads a bit field from a 64-bit value, performs a bitwise AND, and returns\r | |
815 | the result.\r | |
816 | \r | |
817 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
818 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
819 | preserved. The new 64-bit value is returned.\r | |
820 | \r | |
821 | If 64-bit operations are not supported, then ASSERT().\r | |
822 | If StartBit is greater than 63, then ASSERT().\r | |
823 | If EndBit is greater than 63, then ASSERT().\r | |
824 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 | 825 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
e1f414b6 | 826 | \r |
827 | @param Operand Operand on which to perform the bitfield operation.\r | |
828 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
829 | Range 0..63.\r | |
830 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
831 | Range 0..63.\r | |
127010dd | 832 | @param AndData The value to AND with the read value from the value.\r |
e1f414b6 | 833 | \r |
834 | @return The new 64-bit value.\r | |
835 | \r | |
836 | **/\r | |
837 | UINT64\r | |
838 | EFIAPI\r | |
839 | BitFieldAnd64 (\r | |
840 | IN UINT64 Operand,\r | |
841 | IN UINTN StartBit,\r | |
842 | IN UINTN EndBit,\r | |
843 | IN UINT64 AndData\r | |
844 | )\r | |
845 | {\r | |
846 | UINT64 Value1;\r | |
847 | UINT64 Value2;\r | |
848 | \r | |
5385a579 | 849 | ASSERT (EndBit < 64);\r |
e1f414b6 | 850 | ASSERT (StartBit <= EndBit);\r |
94952554 | 851 | ASSERT (RShiftU64 (AndData, EndBit - StartBit + 1) == 0);\r |
e1f414b6 | 852 | \r |
853 | Value1 = LShiftU64 (~AndData, StartBit);\r | |
854 | Value2 = LShiftU64 ((UINT64)-2, EndBit);\r | |
855 | \r | |
856 | return Operand & ~(Value1 & ~Value2);\r | |
857 | }\r | |
858 | \r | |
859 | /**\r | |
860 | Reads a bit field from a 64-bit value, performs a bitwise AND followed by a\r | |
861 | bitwise OR, and returns the result.\r | |
862 | \r | |
863 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
62991af2 | 864 | in Operand and the value specified by AndData, followed by a bitwise \r |
865 | OR with value specified by OrData. All other bits in Operand are\r | |
e1f414b6 | 866 | preserved. The new 64-bit value is returned.\r |
867 | \r | |
868 | If 64-bit operations are not supported, then ASSERT().\r | |
869 | If StartBit is greater than 63, then ASSERT().\r | |
870 | If EndBit is greater than 63, then ASSERT().\r | |
871 | If EndBit is less than StartBit, then ASSERT().\r | |
94952554 LG |
872 | If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r |
873 | If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r | |
e1f414b6 | 874 | \r |
875 | @param Operand Operand on which to perform the bitfield operation.\r | |
876 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
877 | Range 0..63.\r | |
878 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
879 | Range 0..63.\r | |
880 | @param AndData The value to AND with the read value from the value.\r | |
881 | @param OrData The value to OR with the result of the AND operation.\r | |
882 | \r | |
883 | @return The new 64-bit value.\r | |
884 | \r | |
885 | **/\r | |
886 | UINT64\r | |
887 | EFIAPI\r | |
888 | BitFieldAndThenOr64 (\r | |
889 | IN UINT64 Operand,\r | |
890 | IN UINTN StartBit,\r | |
891 | IN UINTN EndBit,\r | |
892 | IN UINT64 AndData,\r | |
893 | IN UINT64 OrData\r | |
894 | )\r | |
895 | {\r | |
5385a579 | 896 | ASSERT (EndBit < 64);\r |
e1f414b6 | 897 | ASSERT (StartBit <= EndBit);\r |
898 | return BitFieldOr64 (\r | |
899 | BitFieldAnd64 (Operand, StartBit, EndBit, AndData),\r | |
900 | StartBit,\r | |
901 | EndBit,\r | |
902 | OrData\r | |
903 | );\r | |
904 | }\r |