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