1 | /** @file
|
---|
2 | Declaration of internal functions in BaseLib.
|
---|
3 |
|
---|
4 | Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #ifndef __BASE_LIB_INTERNALS__
|
---|
10 | #define __BASE_LIB_INTERNALS__
|
---|
11 |
|
---|
12 | #include <Base.h>
|
---|
13 | #include <Library/BaseLib.h>
|
---|
14 | #include <Library/BaseMemoryLib.h>
|
---|
15 | #include <Library/DebugLib.h>
|
---|
16 | #include <Library/PcdLib.h>
|
---|
17 |
|
---|
18 | //
|
---|
19 | // Math functions
|
---|
20 | //
|
---|
21 |
|
---|
22 | /**
|
---|
23 | Shifts a 64-bit integer left between 0 and 63 bits. The low bits
|
---|
24 | are filled with zeros. The shifted value is returned.
|
---|
25 |
|
---|
26 | This function shifts the 64-bit value Operand to the left by Count bits. The
|
---|
27 | low Count bits are set to zero. The shifted value is returned.
|
---|
28 |
|
---|
29 | @param Operand The 64-bit operand to shift left.
|
---|
30 | @param Count The number of bits to shift left.
|
---|
31 |
|
---|
32 | @return Operand << Count
|
---|
33 |
|
---|
34 | **/
|
---|
35 | UINT64
|
---|
36 | EFIAPI
|
---|
37 | InternalMathLShiftU64 (
|
---|
38 | IN UINT64 Operand,
|
---|
39 | IN UINTN Count
|
---|
40 | );
|
---|
41 |
|
---|
42 | /**
|
---|
43 | Shifts a 64-bit integer right between 0 and 63 bits. The high bits
|
---|
44 | are filled with zeros. The shifted value is returned.
|
---|
45 |
|
---|
46 | This function shifts the 64-bit value Operand to the right by Count bits. The
|
---|
47 | high Count bits are set to zero. The shifted value is returned.
|
---|
48 |
|
---|
49 | @param Operand The 64-bit operand to shift right.
|
---|
50 | @param Count The number of bits to shift right.
|
---|
51 |
|
---|
52 | @return Operand >> Count
|
---|
53 |
|
---|
54 | **/
|
---|
55 | UINT64
|
---|
56 | EFIAPI
|
---|
57 | InternalMathRShiftU64 (
|
---|
58 | IN UINT64 Operand,
|
---|
59 | IN UINTN Count
|
---|
60 | );
|
---|
61 |
|
---|
62 | /**
|
---|
63 | Shifts a 64-bit integer right between 0 and 63 bits. The high bits
|
---|
64 | are filled with original integer's bit 63. The shifted value is returned.
|
---|
65 |
|
---|
66 | This function shifts the 64-bit value Operand to the right by Count bits. The
|
---|
67 | high Count bits are set to bit 63 of Operand. The shifted value is returned.
|
---|
68 |
|
---|
69 | @param Operand The 64-bit operand to shift right.
|
---|
70 | @param Count The number of bits to shift right.
|
---|
71 |
|
---|
72 | @return Operand arithmetically shifted right by Count
|
---|
73 |
|
---|
74 | **/
|
---|
75 | UINT64
|
---|
76 | EFIAPI
|
---|
77 | InternalMathARShiftU64 (
|
---|
78 | IN UINT64 Operand,
|
---|
79 | IN UINTN Count
|
---|
80 | );
|
---|
81 |
|
---|
82 | /**
|
---|
83 | Rotates a 64-bit integer left between 0 and 63 bits, filling
|
---|
84 | the low bits with the high bits that were rotated.
|
---|
85 |
|
---|
86 | This function rotates the 64-bit value Operand to the left by Count bits. The
|
---|
87 | low Count bits are filled with the high Count bits of Operand. The rotated
|
---|
88 | value is returned.
|
---|
89 |
|
---|
90 | @param Operand The 64-bit operand to rotate left.
|
---|
91 | @param Count The number of bits to rotate left.
|
---|
92 |
|
---|
93 | @return Operand <<< Count
|
---|
94 |
|
---|
95 | **/
|
---|
96 | UINT64
|
---|
97 | EFIAPI
|
---|
98 | InternalMathLRotU64 (
|
---|
99 | IN UINT64 Operand,
|
---|
100 | IN UINTN Count
|
---|
101 | );
|
---|
102 |
|
---|
103 | /**
|
---|
104 | Rotates a 64-bit integer right between 0 and 63 bits, filling
|
---|
105 | the high bits with the high low bits that were rotated.
|
---|
106 |
|
---|
107 | This function rotates the 64-bit value Operand to the right by Count bits.
|
---|
108 | The high Count bits are filled with the low Count bits of Operand. The rotated
|
---|
109 | value is returned.
|
---|
110 |
|
---|
111 | @param Operand The 64-bit operand to rotate right.
|
---|
112 | @param Count The number of bits to rotate right.
|
---|
113 |
|
---|
114 | @return Operand >>> Count
|
---|
115 |
|
---|
116 | **/
|
---|
117 | UINT64
|
---|
118 | EFIAPI
|
---|
119 | InternalMathRRotU64 (
|
---|
120 | IN UINT64 Operand,
|
---|
121 | IN UINTN Count
|
---|
122 | );
|
---|
123 |
|
---|
124 | /**
|
---|
125 | Switches the endianess of a 64-bit integer.
|
---|
126 |
|
---|
127 | This function swaps the bytes in a 64-bit unsigned value to switch the value
|
---|
128 | from little endian to big endian or vice versa. The byte swapped value is
|
---|
129 | returned.
|
---|
130 |
|
---|
131 | @param Operand A 64-bit unsigned value.
|
---|
132 |
|
---|
133 | @return The byte swapped Operand.
|
---|
134 |
|
---|
135 | **/
|
---|
136 | UINT64
|
---|
137 | EFIAPI
|
---|
138 | InternalMathSwapBytes64 (
|
---|
139 | IN UINT64 Operand
|
---|
140 | );
|
---|
141 |
|
---|
142 | /**
|
---|
143 | Multiplies a 64-bit unsigned integer by a 32-bit unsigned integer
|
---|
144 | and generates a 64-bit unsigned result.
|
---|
145 |
|
---|
146 | This function multiplies the 64-bit unsigned value Multiplicand by the 32-bit
|
---|
147 | unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
|
---|
148 | bit unsigned result is returned.
|
---|
149 |
|
---|
150 | @param Multiplicand A 64-bit unsigned value.
|
---|
151 | @param Multiplier A 32-bit unsigned value.
|
---|
152 |
|
---|
153 | @return Multiplicand * Multiplier
|
---|
154 |
|
---|
155 | **/
|
---|
156 | UINT64
|
---|
157 | EFIAPI
|
---|
158 | InternalMathMultU64x32 (
|
---|
159 | IN UINT64 Multiplicand,
|
---|
160 | IN UINT32 Multiplier
|
---|
161 | );
|
---|
162 |
|
---|
163 | /**
|
---|
164 | Multiplies a 64-bit unsigned integer by a 64-bit unsigned integer
|
---|
165 | and generates a 64-bit unsigned result.
|
---|
166 |
|
---|
167 | This function multiples the 64-bit unsigned value Multiplicand by the 64-bit
|
---|
168 | unsigned value Multiplier and generates a 64-bit unsigned result. This 64-
|
---|
169 | bit unsigned result is returned.
|
---|
170 |
|
---|
171 | @param Multiplicand A 64-bit unsigned value.
|
---|
172 | @param Multiplier A 64-bit unsigned value.
|
---|
173 |
|
---|
174 | @return Multiplicand * Multiplier
|
---|
175 |
|
---|
176 | **/
|
---|
177 | UINT64
|
---|
178 | EFIAPI
|
---|
179 | InternalMathMultU64x64 (
|
---|
180 | IN UINT64 Multiplicand,
|
---|
181 | IN UINT64 Multiplier
|
---|
182 | );
|
---|
183 |
|
---|
184 | /**
|
---|
185 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and
|
---|
186 | generates a 64-bit unsigned result.
|
---|
187 |
|
---|
188 | This function divides the 64-bit unsigned value Dividend by the 32-bit
|
---|
189 | unsigned value Divisor and generates a 64-bit unsigned quotient. This
|
---|
190 | function returns the 64-bit unsigned quotient.
|
---|
191 |
|
---|
192 | @param Dividend A 64-bit unsigned value.
|
---|
193 | @param Divisor A 32-bit unsigned value.
|
---|
194 |
|
---|
195 | @return Dividend / Divisor
|
---|
196 |
|
---|
197 | **/
|
---|
198 | UINT64
|
---|
199 | EFIAPI
|
---|
200 | InternalMathDivU64x32 (
|
---|
201 | IN UINT64 Dividend,
|
---|
202 | IN UINT32 Divisor
|
---|
203 | );
|
---|
204 |
|
---|
205 | /**
|
---|
206 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and
|
---|
207 | generates a 32-bit unsigned remainder.
|
---|
208 |
|
---|
209 | This function divides the 64-bit unsigned value Dividend by the 32-bit
|
---|
210 | unsigned value Divisor and generates a 32-bit remainder. This function
|
---|
211 | returns the 32-bit unsigned remainder.
|
---|
212 |
|
---|
213 | @param Dividend A 64-bit unsigned value.
|
---|
214 | @param Divisor A 32-bit unsigned value.
|
---|
215 |
|
---|
216 | @return Dividend % Divisor
|
---|
217 |
|
---|
218 | **/
|
---|
219 | UINT32
|
---|
220 | EFIAPI
|
---|
221 | InternalMathModU64x32 (
|
---|
222 | IN UINT64 Dividend,
|
---|
223 | IN UINT32 Divisor
|
---|
224 | );
|
---|
225 |
|
---|
226 | /**
|
---|
227 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and
|
---|
228 | generates a 64-bit unsigned result and an optional 32-bit unsigned remainder.
|
---|
229 |
|
---|
230 | This function divides the 64-bit unsigned value Dividend by the 32-bit
|
---|
231 | unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
|
---|
232 | is not NULL, then the 32-bit unsigned remainder is returned in Remainder.
|
---|
233 | This function returns the 64-bit unsigned quotient.
|
---|
234 |
|
---|
235 | @param Dividend A 64-bit unsigned value.
|
---|
236 | @param Divisor A 32-bit unsigned value.
|
---|
237 | @param Remainder A pointer to a 32-bit unsigned value. This parameter is
|
---|
238 | optional and may be NULL.
|
---|
239 |
|
---|
240 | @return Dividend / Divisor
|
---|
241 |
|
---|
242 | **/
|
---|
243 | UINT64
|
---|
244 | EFIAPI
|
---|
245 | InternalMathDivRemU64x32 (
|
---|
246 | IN UINT64 Dividend,
|
---|
247 | IN UINT32 Divisor,
|
---|
248 | OUT UINT32 *Remainder OPTIONAL
|
---|
249 | );
|
---|
250 |
|
---|
251 | /**
|
---|
252 | Divides a 64-bit unsigned integer by a 64-bit unsigned integer and
|
---|
253 | generates a 64-bit unsigned result and an optional 64-bit unsigned remainder.
|
---|
254 |
|
---|
255 | This function divides the 64-bit unsigned value Dividend by the 64-bit
|
---|
256 | unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder
|
---|
257 | is not NULL, then the 64-bit unsigned remainder is returned in Remainder.
|
---|
258 | This function returns the 64-bit unsigned quotient.
|
---|
259 |
|
---|
260 | @param Dividend A 64-bit unsigned value.
|
---|
261 | @param Divisor A 64-bit unsigned value.
|
---|
262 | @param Remainder A pointer to a 64-bit unsigned value. This parameter is
|
---|
263 | optional and may be NULL.
|
---|
264 |
|
---|
265 | @return Dividend / Divisor
|
---|
266 |
|
---|
267 | **/
|
---|
268 | UINT64
|
---|
269 | EFIAPI
|
---|
270 | InternalMathDivRemU64x64 (
|
---|
271 | IN UINT64 Dividend,
|
---|
272 | IN UINT64 Divisor,
|
---|
273 | OUT UINT64 *Remainder OPTIONAL
|
---|
274 | );
|
---|
275 |
|
---|
276 | /**
|
---|
277 | Divides a 64-bit signed integer by a 64-bit signed integer and
|
---|
278 | generates a 64-bit signed result and an optional 64-bit signed remainder.
|
---|
279 |
|
---|
280 | This function divides the 64-bit signed value Dividend by the 64-bit
|
---|
281 | signed value Divisor and generates a 64-bit signed quotient. If Remainder
|
---|
282 | is not NULL, then the 64-bit signed remainder is returned in Remainder.
|
---|
283 | This function returns the 64-bit signed quotient.
|
---|
284 |
|
---|
285 | @param Dividend A 64-bit signed value.
|
---|
286 | @param Divisor A 64-bit signed value.
|
---|
287 | @param Remainder A pointer to a 64-bit signed value. This parameter is
|
---|
288 | optional and may be NULL.
|
---|
289 |
|
---|
290 | @return Dividend / Divisor
|
---|
291 |
|
---|
292 | **/
|
---|
293 | INT64
|
---|
294 | EFIAPI
|
---|
295 | InternalMathDivRemS64x64 (
|
---|
296 | IN INT64 Dividend,
|
---|
297 | IN INT64 Divisor,
|
---|
298 | OUT INT64 *Remainder OPTIONAL
|
---|
299 | );
|
---|
300 |
|
---|
301 | /**
|
---|
302 | Transfers control to a function starting with a new stack.
|
---|
303 |
|
---|
304 | Transfers control to the function specified by EntryPoint using the
|
---|
305 | new stack specified by NewStack and passing in the parameters specified
|
---|
306 | by Context1 and Context2. Context1 and Context2 are optional and may
|
---|
307 | be NULL. The function EntryPoint must never return.
|
---|
308 | Marker will be ignored on IA-32, x64, and EBC.
|
---|
309 | IPF CPUs expect one additional parameter of type VOID * that specifies
|
---|
310 | the new backing store pointer.
|
---|
311 |
|
---|
312 | If EntryPoint is NULL, then ASSERT().
|
---|
313 | If NewStack is NULL, then ASSERT().
|
---|
314 |
|
---|
315 | @param EntryPoint A pointer to function to call with the new stack.
|
---|
316 | @param Context1 A pointer to the context to pass into the EntryPoint
|
---|
317 | function.
|
---|
318 | @param Context2 A pointer to the context to pass into the EntryPoint
|
---|
319 | function.
|
---|
320 | @param NewStack A pointer to the new stack to use for the EntryPoint
|
---|
321 | function.
|
---|
322 | @param Marker VA_LIST marker for the variable argument list.
|
---|
323 |
|
---|
324 | **/
|
---|
325 | VOID
|
---|
326 | EFIAPI
|
---|
327 | InternalSwitchStack (
|
---|
328 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,
|
---|
329 | IN VOID *Context1 OPTIONAL,
|
---|
330 | IN VOID *Context2 OPTIONAL,
|
---|
331 | IN VOID *NewStack,
|
---|
332 | IN VA_LIST Marker
|
---|
333 | );
|
---|
334 |
|
---|
335 | /**
|
---|
336 | Worker function that returns a bit field from Operand.
|
---|
337 |
|
---|
338 | Returns the bitfield specified by the StartBit and the EndBit from Operand.
|
---|
339 |
|
---|
340 | @param Operand Operand on which to perform the bitfield operation.
|
---|
341 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
342 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
343 |
|
---|
344 | @return The bit field read.
|
---|
345 |
|
---|
346 | **/
|
---|
347 | UINTN
|
---|
348 | EFIAPI
|
---|
349 | BitFieldReadUint (
|
---|
350 | IN UINTN Operand,
|
---|
351 | IN UINTN StartBit,
|
---|
352 | IN UINTN EndBit
|
---|
353 | );
|
---|
354 |
|
---|
355 | /**
|
---|
356 | Worker function that reads a bit field from Operand, performs a bitwise OR,
|
---|
357 | and returns the result.
|
---|
358 |
|
---|
359 | Performs a bitwise OR between the bit field specified by StartBit and EndBit
|
---|
360 | in Operand and the value specified by AndData. All other bits in Operand are
|
---|
361 | preserved. The new value is returned.
|
---|
362 |
|
---|
363 | @param Operand Operand on which to perform the bitfield operation.
|
---|
364 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
365 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
366 | @param OrData The value to OR with the read value from the value
|
---|
367 |
|
---|
368 | @return The new value.
|
---|
369 |
|
---|
370 | **/
|
---|
371 | UINTN
|
---|
372 | EFIAPI
|
---|
373 | BitFieldOrUint (
|
---|
374 | IN UINTN Operand,
|
---|
375 | IN UINTN StartBit,
|
---|
376 | IN UINTN EndBit,
|
---|
377 | IN UINTN OrData
|
---|
378 | );
|
---|
379 |
|
---|
380 | /**
|
---|
381 | Worker function that reads a bit field from Operand, performs a bitwise AND,
|
---|
382 | and returns the result.
|
---|
383 |
|
---|
384 | Performs a bitwise AND between the bit field specified by StartBit and EndBit
|
---|
385 | in Operand and the value specified by AndData. All other bits in Operand are
|
---|
386 | preserved. The new value is returned.
|
---|
387 |
|
---|
388 | @param Operand Operand on which to perform the bitfield operation.
|
---|
389 | @param StartBit The ordinal of the least significant bit in the bit field.
|
---|
390 | @param EndBit The ordinal of the most significant bit in the bit field.
|
---|
391 | @param AndData The value to And with the read value from the value
|
---|
392 |
|
---|
393 | @return The new value.
|
---|
394 |
|
---|
395 | **/
|
---|
396 | UINTN
|
---|
397 | EFIAPI
|
---|
398 | BitFieldAndUint (
|
---|
399 | IN UINTN Operand,
|
---|
400 | IN UINTN StartBit,
|
---|
401 | IN UINTN EndBit,
|
---|
402 | IN UINTN AndData
|
---|
403 | );
|
---|
404 |
|
---|
405 | /**
|
---|
406 | Worker function that checks ASSERT condition for JumpBuffer
|
---|
407 |
|
---|
408 | Checks ASSERT condition for JumpBuffer.
|
---|
409 |
|
---|
410 | If JumpBuffer is NULL, then ASSERT().
|
---|
411 | For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().
|
---|
412 |
|
---|
413 | @param JumpBuffer A pointer to CPU context buffer.
|
---|
414 |
|
---|
415 | **/
|
---|
416 | VOID
|
---|
417 | EFIAPI
|
---|
418 | InternalAssertJumpBuffer (
|
---|
419 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer
|
---|
420 | );
|
---|
421 |
|
---|
422 | /**
|
---|
423 | Restores the CPU context that was saved with SetJump().
|
---|
424 |
|
---|
425 | Restores the CPU context from the buffer specified by JumpBuffer.
|
---|
426 | This function never returns to the caller.
|
---|
427 | Instead is resumes execution based on the state of JumpBuffer.
|
---|
428 |
|
---|
429 | @param JumpBuffer A pointer to CPU context buffer.
|
---|
430 | @param Value The value to return when the SetJump() context is restored.
|
---|
431 |
|
---|
432 | **/
|
---|
433 | VOID
|
---|
434 | EFIAPI
|
---|
435 | InternalLongJump (
|
---|
436 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,
|
---|
437 | IN UINTN Value
|
---|
438 | );
|
---|
439 |
|
---|
440 | /**
|
---|
441 | Check if a Unicode character is a decimal character.
|
---|
442 |
|
---|
443 | This internal function checks if a Unicode character is a
|
---|
444 | decimal character. The valid decimal character is from
|
---|
445 | L'0' to L'9'.
|
---|
446 |
|
---|
447 | @param Char The character to check against.
|
---|
448 |
|
---|
449 | @retval TRUE If the Char is a decmial character.
|
---|
450 | @retval FALSE If the Char is not a decmial character.
|
---|
451 |
|
---|
452 | **/
|
---|
453 | BOOLEAN
|
---|
454 | EFIAPI
|
---|
455 | InternalIsDecimalDigitCharacter (
|
---|
456 | IN CHAR16 Char
|
---|
457 | );
|
---|
458 |
|
---|
459 | /**
|
---|
460 | Convert a Unicode character to numerical value.
|
---|
461 |
|
---|
462 | This internal function only deal with Unicode character
|
---|
463 | which maps to a valid hexadecimal ASII character, i.e.
|
---|
464 | L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
|
---|
465 | Unicode character, the value returned does not make sense.
|
---|
466 |
|
---|
467 | @param Char The character to convert.
|
---|
468 |
|
---|
469 | @return The numerical value converted.
|
---|
470 |
|
---|
471 | **/
|
---|
472 | UINTN
|
---|
473 | EFIAPI
|
---|
474 | InternalHexCharToUintn (
|
---|
475 | IN CHAR16 Char
|
---|
476 | );
|
---|
477 |
|
---|
478 | /**
|
---|
479 | Check if a Unicode character is a hexadecimal character.
|
---|
480 |
|
---|
481 | This internal function checks if a Unicode character is a
|
---|
482 | decimal character. The valid hexadecimal character is
|
---|
483 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
|
---|
484 |
|
---|
485 |
|
---|
486 | @param Char The character to check against.
|
---|
487 |
|
---|
488 | @retval TRUE If the Char is a hexadecmial character.
|
---|
489 | @retval FALSE If the Char is not a hexadecmial character.
|
---|
490 |
|
---|
491 | **/
|
---|
492 | BOOLEAN
|
---|
493 | EFIAPI
|
---|
494 | InternalIsHexaDecimalDigitCharacter (
|
---|
495 | IN CHAR16 Char
|
---|
496 | );
|
---|
497 |
|
---|
498 | /**
|
---|
499 | Check if a ASCII character is a decimal character.
|
---|
500 |
|
---|
501 | This internal function checks if a Unicode character is a
|
---|
502 | decimal character. The valid decimal character is from
|
---|
503 | '0' to '9'.
|
---|
504 |
|
---|
505 | @param Char The character to check against.
|
---|
506 |
|
---|
507 | @retval TRUE If the Char is a decmial character.
|
---|
508 | @retval FALSE If the Char is not a decmial character.
|
---|
509 |
|
---|
510 | **/
|
---|
511 | BOOLEAN
|
---|
512 | EFIAPI
|
---|
513 | InternalAsciiIsDecimalDigitCharacter (
|
---|
514 | IN CHAR8 Char
|
---|
515 | );
|
---|
516 |
|
---|
517 | /**
|
---|
518 | Check if a ASCII character is a hexadecimal character.
|
---|
519 |
|
---|
520 | This internal function checks if a ASCII character is a
|
---|
521 | decimal character. The valid hexadecimal character is
|
---|
522 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
|
---|
523 |
|
---|
524 |
|
---|
525 | @param Char The character to check against.
|
---|
526 |
|
---|
527 | @retval TRUE If the Char is a hexadecmial character.
|
---|
528 | @retval FALSE If the Char is not a hexadecmial character.
|
---|
529 |
|
---|
530 | **/
|
---|
531 | BOOLEAN
|
---|
532 | EFIAPI
|
---|
533 | InternalAsciiIsHexaDecimalDigitCharacter (
|
---|
534 | IN CHAR8 Char
|
---|
535 | );
|
---|
536 |
|
---|
537 | /**
|
---|
538 | Convert a ASCII character to numerical value.
|
---|
539 |
|
---|
540 | This internal function only deal with Unicode character
|
---|
541 | which maps to a valid hexadecimal ASII character, i.e.
|
---|
542 | '0' to '9', 'a' to 'f' or 'A' to 'F'. For other
|
---|
543 | ASCII character, the value returned does not make sense.
|
---|
544 |
|
---|
545 | @param Char The character to convert.
|
---|
546 |
|
---|
547 | @return The numerical value converted.
|
---|
548 |
|
---|
549 | **/
|
---|
550 | UINTN
|
---|
551 | EFIAPI
|
---|
552 | InternalAsciiHexCharToUintn (
|
---|
553 | IN CHAR8 Char
|
---|
554 | );
|
---|
555 |
|
---|
556 | //
|
---|
557 | // Ia32 and x64 specific functions
|
---|
558 | //
|
---|
559 | #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
|
---|
560 |
|
---|
561 | /**
|
---|
562 | Reads the current Global Descriptor Table Register(GDTR) descriptor.
|
---|
563 |
|
---|
564 | Reads and returns the current GDTR descriptor and returns it in Gdtr. This
|
---|
565 | function is only available on IA-32 and x64.
|
---|
566 |
|
---|
567 | @param Gdtr The pointer to a GDTR descriptor.
|
---|
568 |
|
---|
569 | **/
|
---|
570 | VOID
|
---|
571 | EFIAPI
|
---|
572 | InternalX86ReadGdtr (
|
---|
573 | OUT IA32_DESCRIPTOR *Gdtr
|
---|
574 | );
|
---|
575 |
|
---|
576 | /**
|
---|
577 | Writes the current Global Descriptor Table Register (GDTR) descriptor.
|
---|
578 |
|
---|
579 | Writes and the current GDTR descriptor specified by Gdtr. This function is
|
---|
580 | only available on IA-32 and x64.
|
---|
581 |
|
---|
582 | @param Gdtr The pointer to a GDTR descriptor.
|
---|
583 |
|
---|
584 | **/
|
---|
585 | VOID
|
---|
586 | EFIAPI
|
---|
587 | InternalX86WriteGdtr (
|
---|
588 | IN CONST IA32_DESCRIPTOR *Gdtr
|
---|
589 | );
|
---|
590 |
|
---|
591 | /**
|
---|
592 | Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.
|
---|
593 |
|
---|
594 | Reads and returns the current IDTR descriptor and returns it in Idtr. This
|
---|
595 | function is only available on IA-32 and x64.
|
---|
596 |
|
---|
597 | @param Idtr The pointer to an IDTR descriptor.
|
---|
598 |
|
---|
599 | **/
|
---|
600 | VOID
|
---|
601 | EFIAPI
|
---|
602 | InternalX86ReadIdtr (
|
---|
603 | OUT IA32_DESCRIPTOR *Idtr
|
---|
604 | );
|
---|
605 |
|
---|
606 | /**
|
---|
607 | Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.
|
---|
608 |
|
---|
609 | Writes the current IDTR descriptor and returns it in Idtr. This function is
|
---|
610 | only available on IA-32 and x64.
|
---|
611 |
|
---|
612 | @param Idtr The pointer to an IDTR descriptor.
|
---|
613 |
|
---|
614 | **/
|
---|
615 | VOID
|
---|
616 | EFIAPI
|
---|
617 | InternalX86WriteIdtr (
|
---|
618 | IN CONST IA32_DESCRIPTOR *Idtr
|
---|
619 | );
|
---|
620 |
|
---|
621 | /**
|
---|
622 | Save the current floating point/SSE/SSE2 context to a buffer.
|
---|
623 |
|
---|
624 | Saves the current floating point/SSE/SSE2 state to the buffer specified by
|
---|
625 | Buffer. Buffer must be aligned on a 16-byte boundary. This function is only
|
---|
626 | available on IA-32 and x64.
|
---|
627 |
|
---|
628 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
|
---|
629 |
|
---|
630 | **/
|
---|
631 | VOID
|
---|
632 | EFIAPI
|
---|
633 | InternalX86FxSave (
|
---|
634 | OUT IA32_FX_BUFFER *Buffer
|
---|
635 | );
|
---|
636 |
|
---|
637 | /**
|
---|
638 | Restores the current floating point/SSE/SSE2 context from a buffer.
|
---|
639 |
|
---|
640 | Restores the current floating point/SSE/SSE2 state from the buffer specified
|
---|
641 | by Buffer. Buffer must be aligned on a 16-byte boundary. This function is
|
---|
642 | only available on IA-32 and x64.
|
---|
643 |
|
---|
644 | @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.
|
---|
645 |
|
---|
646 | **/
|
---|
647 | VOID
|
---|
648 | EFIAPI
|
---|
649 | InternalX86FxRestore (
|
---|
650 | IN CONST IA32_FX_BUFFER *Buffer
|
---|
651 | );
|
---|
652 |
|
---|
653 | /**
|
---|
654 | Enables the 32-bit paging mode on the CPU.
|
---|
655 |
|
---|
656 | Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
|
---|
657 | must be properly initialized prior to calling this service. This function
|
---|
658 | assumes the current execution mode is 32-bit protected mode. This function is
|
---|
659 | only available on IA-32. After the 32-bit paging mode is enabled, control is
|
---|
660 | transferred to the function specified by EntryPoint using the new stack
|
---|
661 | specified by NewStack and passing in the parameters specified by Context1 and
|
---|
662 | Context2. Context1 and Context2 are optional and may be NULL. The function
|
---|
663 | EntryPoint must never return.
|
---|
664 |
|
---|
665 | There are a number of constraints that must be followed before calling this
|
---|
666 | function:
|
---|
667 | 1) Interrupts must be disabled.
|
---|
668 | 2) The caller must be in 32-bit protected mode with flat descriptors. This
|
---|
669 | means all descriptors must have a base of 0 and a limit of 4GB.
|
---|
670 | 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
|
---|
671 | descriptors.
|
---|
672 | 4) CR3 must point to valid page tables that will be used once the transition
|
---|
673 | is complete, and those page tables must guarantee that the pages for this
|
---|
674 | function and the stack are identity mapped.
|
---|
675 |
|
---|
676 | @param EntryPoint A pointer to function to call with the new stack after
|
---|
677 | paging is enabled.
|
---|
678 | @param Context1 A pointer to the context to pass into the EntryPoint
|
---|
679 | function as the first parameter after paging is enabled.
|
---|
680 | @param Context2 A pointer to the context to pass into the EntryPoint
|
---|
681 | function as the second parameter after paging is enabled.
|
---|
682 | @param NewStack A pointer to the new stack to use for the EntryPoint
|
---|
683 | function after paging is enabled.
|
---|
684 |
|
---|
685 | **/
|
---|
686 | VOID
|
---|
687 | EFIAPI
|
---|
688 | InternalX86EnablePaging32 (
|
---|
689 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,
|
---|
690 | IN VOID *Context1 OPTIONAL,
|
---|
691 | IN VOID *Context2 OPTIONAL,
|
---|
692 | IN VOID *NewStack
|
---|
693 | );
|
---|
694 |
|
---|
695 | /**
|
---|
696 | Disables the 32-bit paging mode on the CPU.
|
---|
697 |
|
---|
698 | Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
|
---|
699 | mode. This function assumes the current execution mode is 32-paged protected
|
---|
700 | mode. This function is only available on IA-32. After the 32-bit paging mode
|
---|
701 | is disabled, control is transferred to the function specified by EntryPoint
|
---|
702 | using the new stack specified by NewStack and passing in the parameters
|
---|
703 | specified by Context1 and Context2. Context1 and Context2 are optional and
|
---|
704 | may be NULL. The function EntryPoint must never return.
|
---|
705 |
|
---|
706 | There are a number of constraints that must be followed before calling this
|
---|
707 | function:
|
---|
708 | 1) Interrupts must be disabled.
|
---|
709 | 2) The caller must be in 32-bit paged mode.
|
---|
710 | 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
|
---|
711 | 4) CR3 must point to valid page tables that guarantee that the pages for
|
---|
712 | this function and the stack are identity mapped.
|
---|
713 |
|
---|
714 | @param EntryPoint A pointer to function to call with the new stack after
|
---|
715 | paging is disabled.
|
---|
716 | @param Context1 A pointer to the context to pass into the EntryPoint
|
---|
717 | function as the first parameter after paging is disabled.
|
---|
718 | @param Context2 A pointer to the context to pass into the EntryPoint
|
---|
719 | function as the second parameter after paging is
|
---|
720 | disabled.
|
---|
721 | @param NewStack A pointer to the new stack to use for the EntryPoint
|
---|
722 | function after paging is disabled.
|
---|
723 |
|
---|
724 | **/
|
---|
725 | VOID
|
---|
726 | EFIAPI
|
---|
727 | InternalX86DisablePaging32 (
|
---|
728 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,
|
---|
729 | IN VOID *Context1 OPTIONAL,
|
---|
730 | IN VOID *Context2 OPTIONAL,
|
---|
731 | IN VOID *NewStack
|
---|
732 | );
|
---|
733 |
|
---|
734 | /**
|
---|
735 | Enables the 64-bit paging mode on the CPU.
|
---|
736 |
|
---|
737 | Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
|
---|
738 | must be properly initialized prior to calling this service. This function
|
---|
739 | assumes the current execution mode is 32-bit protected mode with flat
|
---|
740 | descriptors. This function is only available on IA-32. After the 64-bit
|
---|
741 | paging mode is enabled, control is transferred to the function specified by
|
---|
742 | EntryPoint using the new stack specified by NewStack and passing in the
|
---|
743 | parameters specified by Context1 and Context2. Context1 and Context2 are
|
---|
744 | optional and may be 0. The function EntryPoint must never return.
|
---|
745 |
|
---|
746 | @param Cs The 16-bit selector to load in the CS before EntryPoint
|
---|
747 | is called. The descriptor in the GDT that this selector
|
---|
748 | references must be setup for long mode.
|
---|
749 | @param EntryPoint The 64-bit virtual address of the function to call with
|
---|
750 | the new stack after paging is enabled.
|
---|
751 | @param Context1 The 64-bit virtual address of the context to pass into
|
---|
752 | the EntryPoint function as the first parameter after
|
---|
753 | paging is enabled.
|
---|
754 | @param Context2 The 64-bit virtual address of the context to pass into
|
---|
755 | the EntryPoint function as the second parameter after
|
---|
756 | paging is enabled.
|
---|
757 | @param NewStack The 64-bit virtual address of the new stack to use for
|
---|
758 | the EntryPoint function after paging is enabled.
|
---|
759 |
|
---|
760 | **/
|
---|
761 | VOID
|
---|
762 | EFIAPI
|
---|
763 | InternalX86EnablePaging64 (
|
---|
764 | IN UINT16 Cs,
|
---|
765 | IN UINT64 EntryPoint,
|
---|
766 | IN UINT64 Context1 OPTIONAL,
|
---|
767 | IN UINT64 Context2 OPTIONAL,
|
---|
768 | IN UINT64 NewStack
|
---|
769 | );
|
---|
770 |
|
---|
771 | /**
|
---|
772 | Disables the 64-bit paging mode on the CPU.
|
---|
773 |
|
---|
774 | Disables the 64-bit paging mode on the CPU and returns to 32-bit protected
|
---|
775 | mode. This function assumes the current execution mode is 64-paging mode.
|
---|
776 | This function is only available on x64. After the 64-bit paging mode is
|
---|
777 | disabled, control is transferred to the function specified by EntryPoint
|
---|
778 | using the new stack specified by NewStack and passing in the parameters
|
---|
779 | specified by Context1 and Context2. Context1 and Context2 are optional and
|
---|
780 | may be 0. The function EntryPoint must never return.
|
---|
781 |
|
---|
782 | @param Cs The 16-bit selector to load in the CS before EntryPoint
|
---|
783 | is called. The descriptor in the GDT that this selector
|
---|
784 | references must be setup for 32-bit protected mode.
|
---|
785 | @param EntryPoint The 64-bit virtual address of the function to call with
|
---|
786 | the new stack after paging is disabled.
|
---|
787 | @param Context1 The 64-bit virtual address of the context to pass into
|
---|
788 | the EntryPoint function as the first parameter after
|
---|
789 | paging is disabled.
|
---|
790 | @param Context2 The 64-bit virtual address of the context to pass into
|
---|
791 | the EntryPoint function as the second parameter after
|
---|
792 | paging is disabled.
|
---|
793 | @param NewStack The 64-bit virtual address of the new stack to use for
|
---|
794 | the EntryPoint function after paging is disabled.
|
---|
795 |
|
---|
796 | **/
|
---|
797 | VOID
|
---|
798 | EFIAPI
|
---|
799 | InternalX86DisablePaging64 (
|
---|
800 | IN UINT16 Cs,
|
---|
801 | IN UINT32 EntryPoint,
|
---|
802 | IN UINT32 Context1 OPTIONAL,
|
---|
803 | IN UINT32 Context2 OPTIONAL,
|
---|
804 | IN UINT32 NewStack
|
---|
805 | );
|
---|
806 |
|
---|
807 | /**
|
---|
808 | Generates a 16-bit random number through RDRAND instruction.
|
---|
809 |
|
---|
810 | @param[out] Rand Buffer pointer to store the random result.
|
---|
811 |
|
---|
812 | @retval TRUE RDRAND call was successful.
|
---|
813 | @retval FALSE Failed attempts to call RDRAND.
|
---|
814 |
|
---|
815 | **/
|
---|
816 | BOOLEAN
|
---|
817 | EFIAPI
|
---|
818 | InternalX86RdRand16 (
|
---|
819 | OUT UINT16 *Rand
|
---|
820 | );
|
---|
821 |
|
---|
822 | /**
|
---|
823 | Generates a 32-bit random number through RDRAND instruction.
|
---|
824 |
|
---|
825 | @param[out] Rand Buffer pointer to store the random result.
|
---|
826 |
|
---|
827 | @retval TRUE RDRAND call was successful.
|
---|
828 | @retval FALSE Failed attempts to call RDRAND.
|
---|
829 |
|
---|
830 | **/
|
---|
831 | BOOLEAN
|
---|
832 | EFIAPI
|
---|
833 | InternalX86RdRand32 (
|
---|
834 | OUT UINT32 *Rand
|
---|
835 | );
|
---|
836 |
|
---|
837 | /**
|
---|
838 | Generates a 64-bit random number through RDRAND instruction.
|
---|
839 |
|
---|
840 |
|
---|
841 | @param[out] Rand Buffer pointer to store the random result.
|
---|
842 |
|
---|
843 | @retval TRUE RDRAND call was successful.
|
---|
844 | @retval FALSE Failed attempts to call RDRAND.
|
---|
845 |
|
---|
846 | **/
|
---|
847 | BOOLEAN
|
---|
848 | EFIAPI
|
---|
849 | InternalX86RdRand64 (
|
---|
850 | OUT UINT64 *Rand
|
---|
851 | );
|
---|
852 |
|
---|
853 | #else
|
---|
854 |
|
---|
855 | #endif
|
---|
856 |
|
---|
857 | #endif
|
---|