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 /** 337 Worker function that returns a bit field from Operand. 338 339 Returns the bitfield specified by the StartBit and the EndBit from Operand. 340 341 @param Operand Operand on which to perform the bitfield operation. 342 @param StartBit The ordinal of the least significant bit in the bit field. 343 @param EndBit The ordinal of the most significant bit in the bit field. 344 345 @return The bit field read. 346 347 **/ 348 UINTN 349 EFIAPI 350 BitFieldReadUint ( 351 IN UINTN Operand, 352 IN UINTN StartBit, 353 IN UINTN EndBit 354 ); 355 356 357 /** 358 Worker function that reads a bit field from Operand, performs a bitwise OR, 359 and returns the result. 360 361 Performs a bitwise OR between the bit field specified by StartBit and EndBit 362 in Operand and the value specified by AndData. All other bits in Operand are 363 preserved. The new value is returned. 364 365 @param Operand Operand on which to perform the bitfield operation. 366 @param StartBit The ordinal of the least significant bit in the bit field. 367 @param EndBit The ordinal of the most significant bit in the bit field. 368 @param OrData The value to OR with the read value from the value 369 370 @return The new value. 371 372 **/ 373 UINTN 374 EFIAPI 375 BitFieldOrUint ( 376 IN UINTN Operand, 377 IN UINTN StartBit, 378 IN UINTN EndBit, 379 IN UINTN OrData 380 ); 381 382 383 /** 384 Worker function that reads a bit field from Operand, performs a bitwise AND, 385 and returns the result. 386 387 Performs a bitwise AND between the bit field specified by StartBit and EndBit 388 in Operand and the value specified by AndData. All other bits in Operand are 389 preserved. The new value is returned. 390 391 @param Operand Operand on which to perform the bitfield operation. 392 @param StartBit The ordinal of the least significant bit in the bit field. 393 @param EndBit The ordinal of the most significant bit in the bit field. 394 @param AndData The value to And with the read value from the value 395 396 @return The new value. 397 398 **/ 399 UINTN 400 EFIAPI 401 BitFieldAndUint ( 402 IN UINTN Operand, 403 IN UINTN StartBit, 404 IN UINTN EndBit, 405 IN UINTN AndData 406 ); 407 408 409 /** 410 Worker function that checks ASSERT condition for JumpBuffer 411 412 Checks ASSERT condition for JumpBuffer. 413 414 If JumpBuffer is NULL, then ASSERT(). 415 For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT(). 416 417 @param JumpBuffer A pointer to CPU context buffer. 418 419 **/ 420 VOID 421 EFIAPI 422 InternalAssertJumpBuffer ( 423 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer 424 ); 425 426 427 /** 428 Restores the CPU context that was saved with SetJump(). 429 430 Restores the CPU context from the buffer specified by JumpBuffer. 431 This function never returns to the caller. 432 Instead is resumes execution based on the state of JumpBuffer. 433 434 @param JumpBuffer A pointer to CPU context buffer. 435 @param Value The value to return when the SetJump() context is restored. 436 437 **/ 438 VOID 439 EFIAPI 440 InternalLongJump ( 441 IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer, 442 IN UINTN Value 443 ); 444 445 446 /** 447 Check if a Unicode character is a decimal character. 448 449 This internal function checks if a Unicode character is a 450 decimal character. The valid decimal character is from 451 L'0' to L'9'. 452 453 @param Char The character to check against. 454 455 @retval TRUE If the Char is a decmial character. 456 @retval FALSE If the Char is not a decmial character. 457 458 **/ 459 BOOLEAN 460 EFIAPI 461 InternalIsDecimalDigitCharacter ( 462 IN CHAR16 Char 463 ); 464 465 466 /** 467 Convert a Unicode character to numerical value. 468 469 This internal function only deal with Unicode character 470 which maps to a valid hexadecimal ASII character, i.e. 471 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other 472 Unicode character, the value returned does not make sense. 473 474 @param Char The character to convert. 475 476 @return The numerical value converted. 477 478 **/ 479 UINTN 480 EFIAPI 481 InternalHexCharToUintn ( 482 IN CHAR16 Char 483 ); 484 485 486 /** 487 Check if a Unicode character is a hexadecimal character. 488 489 This internal function checks if a Unicode character is a 490 decimal character. The valid hexadecimal character is 491 L'0' to L'9', L'a' to L'f', or L'A' to L'F'. 492 493 494 @param Char The character to check against. 495 496 @retval TRUE If the Char is a hexadecmial character. 497 @retval FALSE If the Char is not a hexadecmial character. 498 499 **/ 500 BOOLEAN 501 EFIAPI 502 InternalIsHexaDecimalDigitCharacter ( 503 IN CHAR16 Char 504 ); 505 506 507 /** 508 Check if a ASCII character is a decimal character. 509 510 This internal function checks if a Unicode character is a 511 decimal character. The valid decimal character is from 512 '0' to '9'. 513 514 @param Char The character to check against. 515 516 @retval TRUE If the Char is a decmial character. 517 @retval FALSE If the Char is not a decmial character. 518 519 **/ 520 BOOLEAN 521 EFIAPI 522 InternalAsciiIsDecimalDigitCharacter ( 523 IN CHAR8 Char 524 ); 525 526 527 /** 528 Check if a ASCII character is a hexadecimal character. 529 530 This internal function checks if a ASCII character is a 531 decimal character. The valid hexadecimal character is 532 L'0' to L'9', L'a' to L'f', or L'A' to L'F'. 533 534 535 @param Char The character to check against. 536 537 @retval TRUE If the Char is a hexadecmial character. 538 @retval FALSE If the Char is not a hexadecmial character. 539 540 **/ 541 BOOLEAN 542 EFIAPI 543 InternalAsciiIsHexaDecimalDigitCharacter ( 544 IN CHAR8 Char 545 ); 546 547 548 /** 549 Convert a ASCII character to numerical value. 550 551 This internal function only deal with Unicode character 552 which maps to a valid hexadecimal ASII character, i.e. 553 '0' to '9', 'a' to 'f' or 'A' to 'F'. For other 554 ASCII character, the value returned does not make sense. 555 556 @param Char The character to convert. 557 558 @return The numerical value converted. 559 560 **/ 561 UINTN 562 EFIAPI 563 InternalAsciiHexCharToUintn ( 564 IN CHAR8 Char 565 ); 566 567 568 // 569 // Ia32 and x64 specific functions 570 // 571 #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) 572 573 /** 574 Reads the current Global Descriptor Table Register(GDTR) descriptor. 575 576 Reads and returns the current GDTR descriptor and returns it in Gdtr. This 577 function is only available on IA-32 and x64. 578 579 @param Gdtr The pointer to a GDTR descriptor. 580 581 **/ 582 VOID 583 EFIAPI 584 InternalX86ReadGdtr ( 585 OUT IA32_DESCRIPTOR *Gdtr 586 ); 587 588 /** 589 Writes the current Global Descriptor Table Register (GDTR) descriptor. 590 591 Writes and the current GDTR descriptor specified by Gdtr. This function is 592 only available on IA-32 and x64. 593 594 @param Gdtr The pointer to a GDTR descriptor. 595 596 **/ 597 VOID 598 EFIAPI 599 InternalX86WriteGdtr ( 600 IN CONST IA32_DESCRIPTOR *Gdtr 601 ); 602 603 /** 604 Reads the current Interrupt Descriptor Table Register(GDTR) descriptor. 605 606 Reads and returns the current IDTR descriptor and returns it in Idtr. This 607 function is only available on IA-32 and x64. 608 609 @param Idtr The pointer to an IDTR descriptor. 610 611 **/ 612 VOID 613 EFIAPI 614 InternalX86ReadIdtr ( 615 OUT IA32_DESCRIPTOR *Idtr 616 ); 617 618 /** 619 Writes the current Interrupt Descriptor Table Register(GDTR) descriptor. 620 621 Writes the current IDTR descriptor and returns it in Idtr. This function is 622 only available on IA-32 and x64. 623 624 @param Idtr The pointer to an IDTR descriptor. 625 626 **/ 627 VOID 628 EFIAPI 629 InternalX86WriteIdtr ( 630 IN CONST IA32_DESCRIPTOR *Idtr 631 ); 632 633 /** 634 Save the current floating point/SSE/SSE2 context to a buffer. 635 636 Saves the current floating point/SSE/SSE2 state to the buffer specified by 637 Buffer. Buffer must be aligned on a 16-byte boundary. This function is only 638 available on IA-32 and x64. 639 640 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context. 641 642 **/ 643 VOID 644 EFIAPI 645 InternalX86FxSave ( 646 OUT IA32_FX_BUFFER *Buffer 647 ); 648 649 /** 650 Restores the current floating point/SSE/SSE2 context from a buffer. 651 652 Restores the current floating point/SSE/SSE2 state from the buffer specified 653 by Buffer. Buffer must be aligned on a 16-byte boundary. This function is 654 only available on IA-32 and x64. 655 656 @param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context. 657 658 **/ 659 VOID 660 EFIAPI 661 InternalX86FxRestore ( 662 IN CONST IA32_FX_BUFFER *Buffer 663 ); 664 665 /** 666 Enables the 32-bit paging mode on the CPU. 667 668 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables 669 must be properly initialized prior to calling this service. This function 670 assumes the current execution mode is 32-bit protected mode. This function is 671 only available on IA-32. After the 32-bit paging mode is enabled, control is 672 transferred to the function specified by EntryPoint using the new stack 673 specified by NewStack and passing in the parameters specified by Context1 and 674 Context2. Context1 and Context2 are optional and may be NULL. The function 675 EntryPoint must never return. 676 677 There are a number of constraints that must be followed before calling this 678 function: 679 1) Interrupts must be disabled. 680 2) The caller must be in 32-bit protected mode with flat descriptors. This 681 means all descriptors must have a base of 0 and a limit of 4GB. 682 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat 683 descriptors. 684 4) CR3 must point to valid page tables that will be used once the transition 685 is complete, and those page tables must guarantee that the pages for this 686 function and the stack are identity mapped. 687 688 @param EntryPoint A pointer to function to call with the new stack after 689 paging is enabled. 690 @param Context1 A pointer to the context to pass into the EntryPoint 691 function as the first parameter after paging is enabled. 692 @param Context2 A pointer to the context to pass into the EntryPoint 693 function as the second parameter after paging is enabled. 694 @param NewStack A pointer to the new stack to use for the EntryPoint 695 function after paging is enabled. 696 697 **/ 698 VOID 699 EFIAPI 700 InternalX86EnablePaging32 ( 701 IN SWITCH_STACK_ENTRY_POINT EntryPoint, 702 IN VOID *Context1, OPTIONAL 703 IN VOID *Context2, OPTIONAL 704 IN VOID *NewStack 705 ); 706 707 /** 708 Disables the 32-bit paging mode on the CPU. 709 710 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected 711 mode. This function assumes the current execution mode is 32-paged protected 712 mode. This function is only available on IA-32. After the 32-bit paging mode 713 is disabled, control is transferred to the function specified by EntryPoint 714 using the new stack specified by NewStack and passing in the parameters 715 specified by Context1 and Context2. Context1 and Context2 are optional and 716 may be NULL. The function EntryPoint must never return. 717 718 There are a number of constraints that must be followed before calling this 719 function: 720 1) Interrupts must be disabled. 721 2) The caller must be in 32-bit paged mode. 722 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode. 723 4) CR3 must point to valid page tables that guarantee that the pages for 724 this function and the stack are identity mapped. 725 726 @param EntryPoint A pointer to function to call with the new stack after 727 paging is disabled. 728 @param Context1 A pointer to the context to pass into the EntryPoint 729 function as the first parameter after paging is disabled. 730 @param Context2 A pointer to the context to pass into the EntryPoint 731 function as the second parameter after paging is 732 disabled. 733 @param NewStack A pointer to the new stack to use for the EntryPoint 734 function after paging is disabled. 735 736 **/ 737 VOID 738 EFIAPI 739 InternalX86DisablePaging32 ( 740 IN SWITCH_STACK_ENTRY_POINT EntryPoint, 741 IN VOID *Context1, OPTIONAL 742 IN VOID *Context2, OPTIONAL 743 IN VOID *NewStack 744 ); 745 746 /** 747 Enables the 64-bit paging mode on the CPU. 748 749 Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables 750 must be properly initialized prior to calling this service. This function 751 assumes the current execution mode is 32-bit protected mode with flat 752 descriptors. This function is only available on IA-32. After the 64-bit 753 paging mode is enabled, control is transferred to the function specified by 754 EntryPoint using the new stack specified by NewStack and passing in the 755 parameters specified by Context1 and Context2. Context1 and Context2 are 756 optional and may be 0. The function EntryPoint must never return. 757 758 @param Cs The 16-bit selector to load in the CS before EntryPoint 759 is called. The descriptor in the GDT that this selector 760 references must be setup for long mode. 761 @param EntryPoint The 64-bit virtual address of the function to call with 762 the new stack after paging is enabled. 763 @param Context1 The 64-bit virtual address of the context to pass into 764 the EntryPoint function as the first parameter after 765 paging is enabled. 766 @param Context2 The 64-bit virtual address of the context to pass into 767 the EntryPoint function as the second parameter after 768 paging is enabled. 769 @param NewStack The 64-bit virtual address of the new stack to use for 770 the EntryPoint function after paging is enabled. 771 772 **/ 773 VOID 774 EFIAPI 775 InternalX86EnablePaging64 ( 776 IN UINT16 Cs, 777 IN UINT64 EntryPoint, 778 IN UINT64 Context1, OPTIONAL 779 IN UINT64 Context2, OPTIONAL 780 IN UINT64 NewStack 781 ); 782 783 /** 784 Disables the 64-bit paging mode on the CPU. 785 786 Disables the 64-bit paging mode on the CPU and returns to 32-bit protected 787 mode. This function assumes the current execution mode is 64-paging mode. 788 This function is only available on x64. After the 64-bit paging mode is 789 disabled, control is transferred to the function specified by EntryPoint 790 using the new stack specified by NewStack and passing in the parameters 791 specified by Context1 and Context2. Context1 and Context2 are optional and 792 may be 0. The function EntryPoint must never return. 793 794 @param Cs The 16-bit selector to load in the CS before EntryPoint 795 is called. The descriptor in the GDT that this selector 796 references must be setup for 32-bit protected mode. 797 @param EntryPoint The 64-bit virtual address of the function to call with 798 the new stack after paging is disabled. 799 @param Context1 The 64-bit virtual address of the context to pass into 800 the EntryPoint function as the first parameter after 801 paging is disabled. 802 @param Context2 The 64-bit virtual address of the context to pass into 803 the EntryPoint function as the second parameter after 804 paging is disabled. 805 @param NewStack The 64-bit virtual address of the new stack to use for 806 the EntryPoint function after paging is disabled. 807 808 **/ 809 VOID 810 EFIAPI 811 InternalX86DisablePaging64 ( 812 IN UINT16 Cs, 813 IN UINT32 EntryPoint, 814 IN UINT32 Context1, OPTIONAL 815 IN UINT32 Context2, OPTIONAL 816 IN UINT32 NewStack 817 ); 818 819 /** 820 Generates a 16-bit random number through RDRAND instruction. 821 822 @param[out] Rand Buffer pointer to store the random result. 823 824 @retval TRUE RDRAND call was successful. 825 @retval FALSE Failed attempts to call RDRAND. 826 827 **/ 828 BOOLEAN 829 EFIAPI 830 InternalX86RdRand16 ( 831 OUT UINT16 *Rand 832 ); 833 834 /** 835 Generates a 32-bit random number through RDRAND instruction. 836 837 @param[out] Rand Buffer pointer to store the random result. 838 839 @retval TRUE RDRAND call was successful. 840 @retval FALSE Failed attempts to call RDRAND. 841 842 **/ 843 BOOLEAN 844 EFIAPI 845 InternalX86RdRand32 ( 846 OUT UINT32 *Rand 847 ); 848 849 /** 850 Generates a 64-bit random number through RDRAND instruction. 851 852 853 @param[out] Rand Buffer pointer to store the random result. 854 855 @retval TRUE RDRAND call was successful. 856 @retval FALSE Failed attempts to call RDRAND. 857 858 **/ 859 BOOLEAN 860 EFIAPI 861 InternalX86RdRand64 ( 862 OUT UINT64 *Rand 863 ); 864 865 #else 866 867 #endif 868 869 #endif 870