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