Path: blob/main/sys/contrib/edk2/Include/Library/BaseLib.h
48383 views
/** @file1Provides string functions, linked list functions, math functions, synchronization2functions, file path functions, and CPU architecture-specific functions.34Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>5Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>6Copyright (c) Microsoft Corporation.<BR>7Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>8Portions Copyright (c) 2022, Loongson Technology Corporation Limited. All rights reserved.<BR>9Copyright (c) 2023 - 2024, Arm Limited. All rights reserved.<BR>1011SPDX-License-Identifier: BSD-2-Clause-Patent1213**/1415#ifndef __BASE_LIB__16#define __BASE_LIB__1718//19// Definitions for architecture-specific types20//21#if defined (MDE_CPU_IA32)22///23/// The IA-32 architecture context buffer used by SetJump() and LongJump().24///25typedef struct {26UINT32 Ebx;27UINT32 Esi;28UINT32 Edi;29UINT32 Ebp;30UINT32 Esp;31UINT32 Eip;32UINT32 Ssp;33} BASE_LIBRARY_JUMP_BUFFER;3435#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 43637#endif // defined (MDE_CPU_IA32)3839#if defined (MDE_CPU_X64)40///41/// The x64 architecture context buffer used by SetJump() and LongJump().42///43typedef struct {44UINT64 Rbx;45UINT64 Rsp;46UINT64 Rbp;47UINT64 Rdi;48UINT64 Rsi;49UINT64 R12;50UINT64 R13;51UINT64 R14;52UINT64 R15;53UINT64 Rip;54UINT64 MxCsr;55UINT8 XmmBuffer[160]; ///< XMM6-XMM15.56UINT64 Ssp;57} BASE_LIBRARY_JUMP_BUFFER;5859#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 86061#endif // defined (MDE_CPU_X64)6263#if defined (MDE_CPU_EBC)64///65/// The EBC context buffer used by SetJump() and LongJump().66///67typedef struct {68UINT64 R0;69UINT64 R1;70UINT64 R2;71UINT64 R3;72UINT64 IP;73} BASE_LIBRARY_JUMP_BUFFER;7475#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 87677#endif // defined (MDE_CPU_EBC)7879#if defined (MDE_CPU_ARM)8081typedef struct {82UINT32 R3; ///< A copy of R13.83UINT32 R4;84UINT32 R5;85UINT32 R6;86UINT32 R7;87UINT32 R8;88UINT32 R9;89UINT32 R10;90UINT32 R11;91UINT32 R12;92UINT32 R14;93} BASE_LIBRARY_JUMP_BUFFER;9495#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 49697#endif // defined (MDE_CPU_ARM)9899#if defined (MDE_CPU_AARCH64)100typedef struct {101// GP regs102UINT64 X19;103UINT64 X20;104UINT64 X21;105UINT64 X22;106UINT64 X23;107UINT64 X24;108UINT64 X25;109UINT64 X26;110UINT64 X27;111UINT64 X28;112UINT64 FP;113UINT64 LR;114UINT64 IP0;115116// FP regs117UINT64 D8;118UINT64 D9;119UINT64 D10;120UINT64 D11;121UINT64 D12;122UINT64 D13;123UINT64 D14;124UINT64 D15;125} BASE_LIBRARY_JUMP_BUFFER;126127#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8128129/**130Reads the current value of CNTPCT_EL0 register.131132Reads and returns the current value of CNTPCT_EL0.133This function is only available on AARCH64.134135@return The current value of CNTPCT_EL0136**/137UINT64138EFIAPI139ArmReadCntPctReg (140VOID141);142143//144// Bit shifts for the ID_AA64ISAR0_EL1 register.145//146#define ARM_ID_AA64ISAR0_EL1_AES_SHIFT (4U)147#define ARM_ID_AA64ISAR0_EL1_SHA1_SHIFT (8U)148#define ARM_ID_AA64ISAR0_EL1_SHA2_SHIFT (12U)149#define ARM_ID_AA64ISAR0_EL1_CRC32_SHIFT (16U)150#define ARM_ID_AA64ISAR0_EL1_ATOMIC_SHIFT (20U)151#define ARM_ID_AA64ISAR0_EL1_RDM_SHIFT (28U)152#define ARM_ID_AA64ISAR0_EL1_SHA3_SHIFT (32U)153#define ARM_ID_AA64ISAR0_EL1_SM3_SHIFT (36U)154#define ARM_ID_AA64ISAR0_EL1_SM4_SHIFT (40U)155#define ARM_ID_AA64ISAR0_EL1_DP_SHIFT (44U)156#define ARM_ID_AA64ISAR0_EL1_FHM_SHIFT (48U)157#define ARM_ID_AA64ISAR0_EL1_TS_SHIFT (52U)158#define ARM_ID_AA64ISAR0_EL1_TLB_SHIFT (56U)159#define ARM_ID_AA64ISAR0_EL1_RNDR_SHIFT (60U)160161//162// Bit masks for the ID_AA64ISAR0_EL1 fields.163//164#define ARM_ID_AA64ISAR0_EL1_AES_MASK (0xFU)165#define ARM_ID_AA64ISAR0_EL1_SHA1_MASK (0xFU)166#define ARM_ID_AA64ISAR0_EL1_SHA2_MASK (0xFU)167#define ARM_ID_AA64ISAR0_EL1_CRC32_MASK (0xFU)168#define ARM_ID_AA64ISAR0_EL1_ATOMIC_MASK (0xFU)169#define ARM_ID_AA64ISAR0_EL1_RDM_MASK (0xFU)170#define ARM_ID_AA64ISAR0_EL1_SHA3_MASK (0xFU)171#define ARM_ID_AA64ISAR0_EL1_SM3_MASK (0xFU)172#define ARM_ID_AA64ISAR0_EL1_SM4_MASK (0xFU)173#define ARM_ID_AA64ISAR0_EL1_DP_MASK (0xFU)174#define ARM_ID_AA64ISAR0_EL1_FHM_MASK (0xFU)175#define ARM_ID_AA64ISAR0_EL1_TS_MASK (0xFU)176#define ARM_ID_AA64ISAR0_EL1_TLB_MASK (0xFU)177#define ARM_ID_AA64ISAR0_EL1_RNDR_MASK (0xFU)178179//180// Bit masks for the ID_AA64ISAR0_EL1 field values.181//182#define ARM_ID_AA64ISAR0_EL1_AES_FEAT_AES_MASK (0x1U)183#define ARM_ID_AA64ISAR0_EL1_AES_FEAT_PMULL_MASK (0x2U)184#define ARM_ID_AA64ISAR0_EL1_SHA1_FEAT_SHA1_MASK (0x1U)185#define ARM_ID_AA64ISAR0_EL1_SHA2_FEAT_SHA256_MASK (0x1U)186#define ARM_ID_AA64ISAR0_EL1_SHA2_FEAT_SHA512_MASK (0x2U)187#define ARM_ID_AA64ISAR0_EL1_CRC32_HAVE_CRC32_MASK (0x1U)188#define ARM_ID_AA64ISAR0_EL1_ATOMIC_FEAT_LSE_MASK (0x2U)189#define ARM_ID_AA64ISAR0_EL1_RDM_FEAT_RDM_MASK (0x1U)190#define ARM_ID_AA64ISAR0_EL1_SHA3_FEAT_SHA3_MASK (0x1U)191#define ARM_ID_AA64ISAR0_EL1_SM3_FEAT_SM3_MASK (0x1U)192#define ARM_ID_AA64ISAR0_EL1_SM4_FEAT_SM4_MASK (0x1U)193#define ARM_ID_AA64ISAR0_EL1_DP_FEAT_DOTPROD_MASK (0x1U)194#define ARM_ID_AA64ISAR0_EL1_FHM_FEAT_FHM_MASK (0x1U)195#define ARM_ID_AA64ISAR0_EL1_TS_FEAT_FLAGM_MASK (0x1U)196#define ARM_ID_AA64ISAR0_EL1_TS_FEAT_FLAGM2_MASK (0x2U)197#define ARM_ID_AA64ISAR0_EL1_TLB_FEAT_TLBIOS_MASK (0x1U)198#define ARM_ID_AA64ISAR0_EL1_TLB_FEAT_TLBIRANGE_MASK (0x2U)199#define ARM_ID_AA64ISAR0_EL1_RNDR_FEAT_RNG_MASK (0x1U)200201/**202Reads the current value of ID_AA64ISAR0_EL1 register.203204Reads and returns the current value of ID_AA64ISAR0_EL1.205This function is only available on AARCH64.206207@return The current value of ID_AA64ISAR0_EL1208**/209UINT64210EFIAPI211ArmReadIdAA64Isar0Reg (212VOID213);214215#endif // defined (MDE_CPU_AARCH64)216217#if defined (MDE_CPU_RISCV64)218///219/// The RISC-V architecture context buffer used by SetJump() and LongJump().220///221typedef struct {222UINT64 RA;223UINT64 S0;224UINT64 S1;225UINT64 S2;226UINT64 S3;227UINT64 S4;228UINT64 S5;229UINT64 S6;230UINT64 S7;231UINT64 S8;232UINT64 S9;233UINT64 S10;234UINT64 S11;235UINT64 SP;236} BASE_LIBRARY_JUMP_BUFFER;237238#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8239240VOID241RiscVSetSupervisorScratch (242IN UINT64243);244245UINT64246RiscVGetSupervisorScratch (247VOID248);249250VOID251RiscVSetSupervisorStvec (252IN UINT64253);254255UINT64256RiscVGetSupervisorStvec (257VOID258);259260UINT64261RiscVGetSupervisorTrapCause (262VOID263);264265VOID266RiscVSetSupervisorAddressTranslationRegister (267IN UINT64268);269270UINT64271RiscVGetSupervisorAddressTranslationRegister (272VOID273);274275UINT64276RiscVReadTimer (277VOID278);279280VOID281RiscVSetSupervisorTimeCompareRegister (282IN UINT64283);284285VOID286RiscVEnableTimerInterrupt (287VOID288);289290VOID291RiscVDisableTimerInterrupt (292VOID293);294295VOID296RiscVClearPendingTimerInterrupt (297VOID298);299300/**301RISC-V invalidate instruction cache.302303**/304VOID305EFIAPI306RiscVInvalidateInstCacheFenceAsm (307VOID308);309310/**311RISC-V invalidate data cache.312313**/314VOID315EFIAPI316RiscVInvalidateDataCacheFenceAsm (317VOID318);319320/**321RISC-V flush cache block. Atomically perform a clean operation322followed by an invalidate operation323324**/325VOID326EFIAPI327RiscVCpuCacheFlushCmoAsm (328IN UINTN329);330331/**332Perform a write transfer to another cache or to memory if the333data in the copy of the cache block have been modified by a store334operation335336**/337VOID338EFIAPI339RiscVCpuCacheCleanCmoAsm (340IN UINTN341);342343/**344Deallocate the copy of the cache block345346**/347VOID348EFIAPI349RiscVCpuCacheInvalCmoAsm (350IN UINTN351);352353#endif // defined (MDE_CPU_RISCV64)354355#if defined (MDE_CPU_LOONGARCH64)356///357/// The LoongArch architecture context buffer used by SetJump() and LongJump()358///359typedef struct {360UINT64 S0;361UINT64 S1;362UINT64 S2;363UINT64 S3;364UINT64 S4;365UINT64 S5;366UINT64 S6;367UINT64 S7;368UINT64 S8;369UINT64 SP;370UINT64 FP;371UINT64 RA;372} BASE_LIBRARY_JUMP_BUFFER;373374#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8375376/*377* Set the exception base address for LoongArch.378*379* @param ExceptionBaseAddress The exception base address, must be aligned greater than or qeual to 4K .380*/381VOID382SetExceptionBaseAddress (383IN UINT64384);385386/*387* Set the TlbRebase address for LoongArch.388*389* @param TlbRebaseAddress The TlbRebase address, must be aligned greater than or qeual to 4K .390*/391VOID392SetTlbRebaseAddress (393IN UINT64394);395396/**397Enables local CPU interrupts.398399@param Needs to enable local interrupt bit.400**/401VOID402EnableLocalInterrupts (403IN UINT16404);405406/**407Disables local CPU interrupts.408409@param Needs to disable local interrupt bit.410**/411VOID412DisableLocalInterrupts (413IN UINT16414);415416/**417Read CPUCFG register.418419@param Index Specifies the register number of the CPUCFG to read the data.420@param Data A pointer to the variable used to store the CPUCFG register value.421**/422VOID423AsmCpucfg (424IN UINT32 Index,425OUT UINT32 *Data426);427428/**429Gets the timer count value.430431@param[] VOID432@retval timer count value.433434**/435UINTN436AsmReadStableCounter (437VOID438);439440/**441CSR read operation.442443@param[in] Select CSR read instruction select values.444445@return The return value of csrrd instruction, return -1 means no CSR instruction446is found.447**/448UINTN449CsrRead (450IN UINT16 Select451);452453/**454CSR write operation.455456@param[in] Select CSR write instruction select values.457@param[in] Value The csrwr will write the value.458459@return The return value of csrwr instruction, that is, store the old value of460the register, return -1 means no CSR instruction is found.461**/462UINTN463CsrWrite (464IN UINT16 Select,465IN UINTN Value466);467468/**469CSR exchange operation.470471@param[in] Select CSR exchange instruction select values.472@param[in] Value The csrxchg will write the value.473@param[in] Mask The csrxchg mask value.474475@return The return value of csrxchg instruction, that is, store the old value of476the register, return -1 means no CSR instruction is found.477**/478UINTN479CsrXChg (480IN UINT16 Select,481IN UINTN Value,482IN UINTN Mask483);484485/**486IO CSR read byte operation.487488@param[in] Select IO CSR read instruction select values.489490@return The return value of iocsrrd.b instruction.491492**/493UINT8494IoCsrRead8 (495IN UINTN Select496);497498/**499IO CSR read half word operation.500501@param[in] Select IO CSR read instruction select values.502503@return The return value of iocsrrd.h instruction.504505**/506UINT16507IoCsrRead16 (508IN UINTN Select509);510511/**512IO CSR read word operation.513514@param[in] Select IO CSR read instruction select values.515516@return The return value of iocsrrd.w instruction.517518**/519UINT32520IoCsrRead32 (521IN UINTN Select522);523524/**525IO CSR read double word operation. Only for LoongArch64.526527@param[in] Select IO CSR read instruction select values.528529@return The return value of iocsrrd.d instruction.530531**/532UINT64533IoCsrRead64 (534IN UINTN Select535);536537/**538IO CSR write byte operation.539540@param[in] Select IO CSR write instruction select values.541@param[in] Value The iocsrwr.b will write the value.542543@return VOID.544545**/546VOID547IoCsrWrite8 (548IN UINTN Select,549IN UINT8 Value550);551552/**553IO CSR write half word operation.554555@param[in] Select IO CSR write instruction select values.556@param[in] Value The iocsrwr.h will write the value.557558@return VOID.559560**/561VOID562IoCsrWrite16 (563IN UINTN Select,564IN UINT16 Value565);566567/**568IO CSR write word operation.569570@param[in] Select IO CSR write instruction select values.571@param[in] Value The iocsrwr.w will write the value.572573@return VOID.574575**/576VOID577IoCsrWrite32 (578IN UINTN Select,579IN UINT32 Value580);581582/**583IO CSR write double word operation. Only for LoongArch64.584585@param[in] Select IO CSR write instruction select values.586@param[in] Value The iocsrwr.d will write the value.587588@return VOID.589590**/591VOID592IoCsrWrite64 (593IN UINTN Select,594IN UINT64 Value595);596597#endif // defined (MDE_CPU_LOONGARCH64)598599//600// String Services601//602603/**604Returns the length of a Null-terminated Unicode string.605606This function is similar as strlen_s defined in C11.607608If String is not aligned on a 16-bit boundary, then ASSERT().609610@param String A pointer to a Null-terminated Unicode string.611@param MaxSize The maximum number of Destination Unicode612char, including terminating null char.613614@retval 0 If String is NULL.615@retval MaxSize If there is no null character in the first MaxSize characters of String.616@return The number of characters that percede the terminating null character.617618**/619UINTN620EFIAPI621StrnLenS (622IN CONST CHAR16 *String,623IN UINTN MaxSize624);625626/**627Returns the size of a Null-terminated Unicode string in bytes, including the628Null terminator.629630This function returns the size of the Null-terminated Unicode string631specified by String in bytes, including the Null terminator.632633If String is not aligned on a 16-bit boundary, then ASSERT().634635@param String A pointer to a Null-terminated Unicode string.636@param MaxSize The maximum number of Destination Unicode637char, including the Null terminator.638639@retval 0 If String is NULL.640@retval (sizeof (CHAR16) * (MaxSize + 1))641If there is no Null terminator in the first MaxSize characters of642String.643@return The size of the Null-terminated Unicode string in bytes, including644the Null terminator.645646**/647UINTN648EFIAPI649StrnSizeS (650IN CONST CHAR16 *String,651IN UINTN MaxSize652);653654/**655Copies the string pointed to by Source (including the terminating null char)656to the array pointed to by Destination.657658This function is similar as strcpy_s defined in C11.659660If Destination is not aligned on a 16-bit boundary, then ASSERT().661If Source is not aligned on a 16-bit boundary, then ASSERT().662663If an error is returned, then the Destination is unmodified.664665@param Destination A pointer to a Null-terminated Unicode string.666@param DestMax The maximum number of Destination Unicode667char, including terminating null char.668@param Source A pointer to a Null-terminated Unicode string.669670@retval RETURN_SUCCESS String is copied.671@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).672@retval RETURN_INVALID_PARAMETER If Destination is NULL.673If Source is NULL.674If PcdMaximumUnicodeStringLength is not zero,675and DestMax is greater than676PcdMaximumUnicodeStringLength.677If DestMax is 0.678@retval RETURN_ACCESS_DENIED If Source and Destination overlap.679**/680RETURN_STATUS681EFIAPI682StrCpyS (683OUT CHAR16 *Destination,684IN UINTN DestMax,685IN CONST CHAR16 *Source686);687688/**689Copies not more than Length successive char from the string pointed to by690Source to the array pointed to by Destination. If no null char is copied from691Source, then Destination[Length] is always set to null.692693This function is similar as strncpy_s defined in C11.694695If Length > 0 and Destination is not aligned on a 16-bit boundary, then ASSERT().696If Length > 0 and Source is not aligned on a 16-bit boundary, then ASSERT().697698If an error is returned, then the Destination is unmodified.699700@param Destination A pointer to a Null-terminated Unicode string.701@param DestMax The maximum number of Destination Unicode702char, including terminating null char.703@param Source A pointer to a Null-terminated Unicode string.704@param Length The maximum number of Unicode characters to copy.705706@retval RETURN_SUCCESS String is copied.707@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than708MIN(StrLen(Source), Length).709@retval RETURN_INVALID_PARAMETER If Destination is NULL.710If Source is NULL.711If PcdMaximumUnicodeStringLength is not zero,712and DestMax is greater than713PcdMaximumUnicodeStringLength.714If DestMax is 0.715@retval RETURN_ACCESS_DENIED If Source and Destination overlap.716**/717RETURN_STATUS718EFIAPI719StrnCpyS (720OUT CHAR16 *Destination,721IN UINTN DestMax,722IN CONST CHAR16 *Source,723IN UINTN Length724);725726/**727Appends a copy of the string pointed to by Source (including the terminating728null char) to the end of the string pointed to by Destination.729730This function is similar as strcat_s defined in C11.731732If Destination is not aligned on a 16-bit boundary, then ASSERT().733If Source is not aligned on a 16-bit boundary, then ASSERT().734735If an error is returned, then the Destination is unmodified.736737@param Destination A pointer to a Null-terminated Unicode string.738@param DestMax The maximum number of Destination Unicode739char, including terminating null char.740@param Source A pointer to a Null-terminated Unicode string.741742@retval RETURN_SUCCESS String is appended.743@retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than744StrLen(Destination).745@retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT746greater than StrLen(Source).747@retval RETURN_INVALID_PARAMETER If Destination is NULL.748If Source is NULL.749If PcdMaximumUnicodeStringLength is not zero,750and DestMax is greater than751PcdMaximumUnicodeStringLength.752If DestMax is 0.753@retval RETURN_ACCESS_DENIED If Source and Destination overlap.754**/755RETURN_STATUS756EFIAPI757StrCatS (758IN OUT CHAR16 *Destination,759IN UINTN DestMax,760IN CONST CHAR16 *Source761);762763/**764Appends not more than Length successive char from the string pointed to by765Source to the end of the string pointed to by Destination. If no null char is766copied from Source, then Destination[StrLen(Destination) + Length] is always767set to null.768769This function is similar as strncat_s defined in C11.770771If Destination is not aligned on a 16-bit boundary, then ASSERT().772If Source is not aligned on a 16-bit boundary, then ASSERT().773774If an error is returned, then the Destination is unmodified.775776@param Destination A pointer to a Null-terminated Unicode string.777@param DestMax The maximum number of Destination Unicode778char, including terminating null char.779@param Source A pointer to a Null-terminated Unicode string.780@param Length The maximum number of Unicode characters to copy.781782@retval RETURN_SUCCESS String is appended.783@retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than784StrLen(Destination).785@retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT786greater than MIN(StrLen(Source), Length).787@retval RETURN_INVALID_PARAMETER If Destination is NULL.788If Source is NULL.789If PcdMaximumUnicodeStringLength is not zero,790and DestMax is greater than791PcdMaximumUnicodeStringLength.792If DestMax is 0.793@retval RETURN_ACCESS_DENIED If Source and Destination overlap.794**/795RETURN_STATUS796EFIAPI797StrnCatS (798IN OUT CHAR16 *Destination,799IN UINTN DestMax,800IN CONST CHAR16 *Source,801IN UINTN Length802);803804/**805Convert a Null-terminated Unicode decimal string to a value of type UINTN.806807This function outputs a value of type UINTN by interpreting the contents of808the Unicode string specified by String as a decimal number. The format of the809input Unicode string String is:810811[spaces] [decimal digits].812813The valid decimal digit character is in the range [0-9]. The function will814ignore the pad space, which includes spaces or tab characters, before815[decimal digits]. The running zero in the beginning of [decimal digits] will816be ignored. Then, the function stops at the first character that is a not a817valid decimal character or a Null-terminator, whichever one comes first.818819If String is not aligned in a 16-bit boundary, then ASSERT().820821If String has no valid decimal digits in the above format, then 0 is stored822at the location pointed to by Data.823If the number represented by String exceeds the range defined by UINTN, then824MAX_UINTN is stored at the location pointed to by Data.825826If EndPointer is not NULL, a pointer to the character that stopped the scan827is stored at the location pointed to by EndPointer. If String has no valid828decimal digits right after the optional pad spaces, the value of String is829stored at the location pointed to by EndPointer.830831@param String Pointer to a Null-terminated Unicode string.832@param EndPointer Pointer to character that stops scan.833@param Data Pointer to the converted value.834835@retval RETURN_SUCCESS Value is translated from String.836@retval RETURN_INVALID_PARAMETER If String is NULL.837If Data is NULL.838If PcdMaximumUnicodeStringLength is not839zero, and String contains more than840PcdMaximumUnicodeStringLength Unicode841characters, not including the842Null-terminator.843@retval RETURN_UNSUPPORTED If the number represented by String exceeds844the range defined by UINTN.845846**/847RETURN_STATUS848EFIAPI849StrDecimalToUintnS (850IN CONST CHAR16 *String,851OUT CHAR16 **EndPointer OPTIONAL,852OUT UINTN *Data853);854855/**856Convert a Null-terminated Unicode decimal string to a value of type UINT64.857858This function outputs a value of type UINT64 by interpreting the contents of859the Unicode string specified by String as a decimal number. The format of the860input Unicode string String is:861862[spaces] [decimal digits].863864The valid decimal digit character is in the range [0-9]. The function will865ignore the pad space, which includes spaces or tab characters, before866[decimal digits]. The running zero in the beginning of [decimal digits] will867be ignored. Then, the function stops at the first character that is a not a868valid decimal character or a Null-terminator, whichever one comes first.869870If String is not aligned in a 16-bit boundary, then ASSERT().871872If String has no valid decimal digits in the above format, then 0 is stored873at the location pointed to by Data.874If the number represented by String exceeds the range defined by UINT64, then875MAX_UINT64 is stored at the location pointed to by Data.876877If EndPointer is not NULL, a pointer to the character that stopped the scan878is stored at the location pointed to by EndPointer. If String has no valid879decimal digits right after the optional pad spaces, the value of String is880stored at the location pointed to by EndPointer.881882@param String Pointer to a Null-terminated Unicode string.883@param EndPointer Pointer to character that stops scan.884@param Data Pointer to the converted value.885886@retval RETURN_SUCCESS Value is translated from String.887@retval RETURN_INVALID_PARAMETER If String is NULL.888If Data is NULL.889If PcdMaximumUnicodeStringLength is not890zero, and String contains more than891PcdMaximumUnicodeStringLength Unicode892characters, not including the893Null-terminator.894@retval RETURN_UNSUPPORTED If the number represented by String exceeds895the range defined by UINT64.896897**/898RETURN_STATUS899EFIAPI900StrDecimalToUint64S (901IN CONST CHAR16 *String,902OUT CHAR16 **EndPointer OPTIONAL,903OUT UINT64 *Data904);905906/**907Convert a Null-terminated Unicode hexadecimal string to a value of type908UINTN.909910This function outputs a value of type UINTN by interpreting the contents of911the Unicode string specified by String as a hexadecimal number. The format of912the input Unicode string String is:913914[spaces][zeros][x][hexadecimal digits].915916The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].917The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.918If "x" appears in the input string, it must be prefixed with at least one 0.919The function will ignore the pad space, which includes spaces or tab920characters, before [zeros], [x] or [hexadecimal digit]. The running zero921before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts922after [x] or the first valid hexadecimal digit. Then, the function stops at923the first character that is a not a valid hexadecimal character or NULL,924whichever one comes first.925926If String is not aligned in a 16-bit boundary, then ASSERT().927928If String has no valid hexadecimal digits in the above format, then 0 is929stored at the location pointed to by Data.930If the number represented by String exceeds the range defined by UINTN, then931MAX_UINTN is stored at the location pointed to by Data.932933If EndPointer is not NULL, a pointer to the character that stopped the scan934is stored at the location pointed to by EndPointer. If String has no valid935hexadecimal digits right after the optional pad spaces, the value of String936is stored at the location pointed to by EndPointer.937938@param String Pointer to a Null-terminated Unicode string.939@param EndPointer Pointer to character that stops scan.940@param Data Pointer to the converted value.941942@retval RETURN_SUCCESS Value is translated from String.943@retval RETURN_INVALID_PARAMETER If String is NULL.944If Data is NULL.945If PcdMaximumUnicodeStringLength is not946zero, and String contains more than947PcdMaximumUnicodeStringLength Unicode948characters, not including the949Null-terminator.950@retval RETURN_UNSUPPORTED If the number represented by String exceeds951the range defined by UINTN.952953**/954RETURN_STATUS955EFIAPI956StrHexToUintnS (957IN CONST CHAR16 *String,958OUT CHAR16 **EndPointer OPTIONAL,959OUT UINTN *Data960);961962/**963Convert a Null-terminated Unicode hexadecimal string to a value of type964UINT64.965966This function outputs a value of type UINT64 by interpreting the contents of967the Unicode string specified by String as a hexadecimal number. The format of968the input Unicode string String is:969970[spaces][zeros][x][hexadecimal digits].971972The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].973The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.974If "x" appears in the input string, it must be prefixed with at least one 0.975The function will ignore the pad space, which includes spaces or tab976characters, before [zeros], [x] or [hexadecimal digit]. The running zero977before [x] or [hexadecimal digit] will be ignored. Then, the decoding starts978after [x] or the first valid hexadecimal digit. Then, the function stops at979the first character that is a not a valid hexadecimal character or NULL,980whichever one comes first.981982If String is not aligned in a 16-bit boundary, then ASSERT().983984If String has no valid hexadecimal digits in the above format, then 0 is985stored at the location pointed to by Data.986If the number represented by String exceeds the range defined by UINT64, then987MAX_UINT64 is stored at the location pointed to by Data.988989If EndPointer is not NULL, a pointer to the character that stopped the scan990is stored at the location pointed to by EndPointer. If String has no valid991hexadecimal digits right after the optional pad spaces, the value of String992is stored at the location pointed to by EndPointer.993994@param String Pointer to a Null-terminated Unicode string.995@param EndPointer Pointer to character that stops scan.996@param Data Pointer to the converted value.997998@retval RETURN_SUCCESS Value is translated from String.999@retval RETURN_INVALID_PARAMETER If String is NULL.1000If Data is NULL.1001If PcdMaximumUnicodeStringLength is not1002zero, and String contains more than1003PcdMaximumUnicodeStringLength Unicode1004characters, not including the1005Null-terminator.1006@retval RETURN_UNSUPPORTED If the number represented by String exceeds1007the range defined by UINT64.10081009**/1010RETURN_STATUS1011EFIAPI1012StrHexToUint64S (1013IN CONST CHAR16 *String,1014OUT CHAR16 **EndPointer OPTIONAL,1015OUT UINT64 *Data1016);10171018/**1019Returns the length of a Null-terminated Ascii string.10201021This function is similar as strlen_s defined in C11.10221023@param String A pointer to a Null-terminated Ascii string.1024@param MaxSize The maximum number of Destination Ascii1025char, including terminating null char.10261027@retval 0 If String is NULL.1028@retval MaxSize If there is no null character in the first MaxSize characters of String.1029@return The number of characters that percede the terminating null character.10301031**/1032UINTN1033EFIAPI1034AsciiStrnLenS (1035IN CONST CHAR8 *String,1036IN UINTN MaxSize1037);10381039/**1040Returns the size of a Null-terminated Ascii string in bytes, including the1041Null terminator.10421043This function returns the size of the Null-terminated Ascii string specified1044by String in bytes, including the Null terminator.10451046@param String A pointer to a Null-terminated Ascii string.1047@param MaxSize The maximum number of Destination Ascii1048char, including the Null terminator.10491050@retval 0 If String is NULL.1051@retval (sizeof (CHAR8) * (MaxSize + 1))1052If there is no Null terminator in the first MaxSize characters of1053String.1054@return The size of the Null-terminated Ascii string in bytes, including the1055Null terminator.10561057**/1058UINTN1059EFIAPI1060AsciiStrnSizeS (1061IN CONST CHAR8 *String,1062IN UINTN MaxSize1063);10641065/**1066Copies the string pointed to by Source (including the terminating null char)1067to the array pointed to by Destination.10681069This function is similar as strcpy_s defined in C11.10701071If an error is returned, then the Destination is unmodified.10721073@param Destination A pointer to a Null-terminated Ascii string.1074@param DestMax The maximum number of Destination Ascii1075char, including terminating null char.1076@param Source A pointer to a Null-terminated Ascii string.10771078@retval RETURN_SUCCESS String is copied.1079@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).1080@retval RETURN_INVALID_PARAMETER If Destination is NULL.1081If Source is NULL.1082If PcdMaximumAsciiStringLength is not zero,1083and DestMax is greater than1084PcdMaximumAsciiStringLength.1085If DestMax is 0.1086@retval RETURN_ACCESS_DENIED If Source and Destination overlap.1087**/1088RETURN_STATUS1089EFIAPI1090AsciiStrCpyS (1091OUT CHAR8 *Destination,1092IN UINTN DestMax,1093IN CONST CHAR8 *Source1094);10951096/**1097Copies not more than Length successive char from the string pointed to by1098Source to the array pointed to by Destination. If no null char is copied from1099Source, then Destination[Length] is always set to null.11001101This function is similar as strncpy_s defined in C11.11021103If an error is returned, then the Destination is unmodified.11041105@param Destination A pointer to a Null-terminated Ascii string.1106@param DestMax The maximum number of Destination Ascii1107char, including terminating null char.1108@param Source A pointer to a Null-terminated Ascii string.1109@param Length The maximum number of Ascii characters to copy.11101111@retval RETURN_SUCCESS String is copied.1112@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than1113MIN(StrLen(Source), Length).1114@retval RETURN_INVALID_PARAMETER If Destination is NULL.1115If Source is NULL.1116If PcdMaximumAsciiStringLength is not zero,1117and DestMax is greater than1118PcdMaximumAsciiStringLength.1119If DestMax is 0.1120@retval RETURN_ACCESS_DENIED If Source and Destination overlap.1121**/1122RETURN_STATUS1123EFIAPI1124AsciiStrnCpyS (1125OUT CHAR8 *Destination,1126IN UINTN DestMax,1127IN CONST CHAR8 *Source,1128IN UINTN Length1129);11301131/**1132Appends a copy of the string pointed to by Source (including the terminating1133null char) to the end of the string pointed to by Destination.11341135This function is similar as strcat_s defined in C11.11361137If an error is returned, then the Destination is unmodified.11381139@param Destination A pointer to a Null-terminated Ascii string.1140@param DestMax The maximum number of Destination Ascii1141char, including terminating null char.1142@param Source A pointer to a Null-terminated Ascii string.11431144@retval RETURN_SUCCESS String is appended.1145@retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than1146StrLen(Destination).1147@retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT1148greater than StrLen(Source).1149@retval RETURN_INVALID_PARAMETER If Destination is NULL.1150If Source is NULL.1151If PcdMaximumAsciiStringLength is not zero,1152and DestMax is greater than1153PcdMaximumAsciiStringLength.1154If DestMax is 0.1155@retval RETURN_ACCESS_DENIED If Source and Destination overlap.1156**/1157RETURN_STATUS1158EFIAPI1159AsciiStrCatS (1160IN OUT CHAR8 *Destination,1161IN UINTN DestMax,1162IN CONST CHAR8 *Source1163);11641165/**1166Appends not more than Length successive char from the string pointed to by1167Source to the end of the string pointed to by Destination. If no null char is1168copied from Source, then Destination[StrLen(Destination) + Length] is always1169set to null.11701171This function is similar as strncat_s defined in C11.11721173If an error is returned, then the Destination is unmodified.11741175@param Destination A pointer to a Null-terminated Ascii string.1176@param DestMax The maximum number of Destination Ascii1177char, including terminating null char.1178@param Source A pointer to a Null-terminated Ascii string.1179@param Length The maximum number of Ascii characters to copy.11801181@retval RETURN_SUCCESS String is appended.1182@retval RETURN_BAD_BUFFER_SIZE If DestMax is NOT greater than1183StrLen(Destination).1184@retval RETURN_BUFFER_TOO_SMALL If (DestMax - StrLen(Destination)) is NOT1185greater than MIN(StrLen(Source), Length).1186@retval RETURN_INVALID_PARAMETER If Destination is NULL.1187If Source is NULL.1188If PcdMaximumAsciiStringLength is not zero,1189and DestMax is greater than1190PcdMaximumAsciiStringLength.1191If DestMax is 0.1192@retval RETURN_ACCESS_DENIED If Source and Destination overlap.1193**/1194RETURN_STATUS1195EFIAPI1196AsciiStrnCatS (1197IN OUT CHAR8 *Destination,1198IN UINTN DestMax,1199IN CONST CHAR8 *Source,1200IN UINTN Length1201);12021203/**1204Convert a Null-terminated Ascii decimal string to a value of type UINTN.12051206This function outputs a value of type UINTN by interpreting the contents of1207the Ascii string specified by String as a decimal number. The format of the1208input Ascii string String is:12091210[spaces] [decimal digits].12111212The valid decimal digit character is in the range [0-9]. The function will1213ignore the pad space, which includes spaces or tab characters, before1214[decimal digits]. The running zero in the beginning of [decimal digits] will1215be ignored. Then, the function stops at the first character that is a not a1216valid decimal character or a Null-terminator, whichever one comes first.12171218If String has no valid decimal digits in the above format, then 0 is stored1219at the location pointed to by Data.1220If the number represented by String exceeds the range defined by UINTN, then1221MAX_UINTN is stored at the location pointed to by Data.12221223If EndPointer is not NULL, a pointer to the character that stopped the scan1224is stored at the location pointed to by EndPointer. If String has no valid1225decimal digits right after the optional pad spaces, the value of String is1226stored at the location pointed to by EndPointer.12271228@param String Pointer to a Null-terminated Ascii string.1229@param EndPointer Pointer to character that stops scan.1230@param Data Pointer to the converted value.12311232@retval RETURN_SUCCESS Value is translated from String.1233@retval RETURN_INVALID_PARAMETER If String is NULL.1234If Data is NULL.1235If PcdMaximumAsciiStringLength is not zero,1236and String contains more than1237PcdMaximumAsciiStringLength Ascii1238characters, not including the1239Null-terminator.1240@retval RETURN_UNSUPPORTED If the number represented by String exceeds1241the range defined by UINTN.12421243**/1244RETURN_STATUS1245EFIAPI1246AsciiStrDecimalToUintnS (1247IN CONST CHAR8 *String,1248OUT CHAR8 **EndPointer OPTIONAL,1249OUT UINTN *Data1250);12511252/**1253Convert a Null-terminated Ascii decimal string to a value of type UINT64.12541255This function outputs a value of type UINT64 by interpreting the contents of1256the Ascii string specified by String as a decimal number. The format of the1257input Ascii string String is:12581259[spaces] [decimal digits].12601261The valid decimal digit character is in the range [0-9]. The function will1262ignore the pad space, which includes spaces or tab characters, before1263[decimal digits]. The running zero in the beginning of [decimal digits] will1264be ignored. Then, the function stops at the first character that is a not a1265valid decimal character or a Null-terminator, whichever one comes first.12661267If String has no valid decimal digits in the above format, then 0 is stored1268at the location pointed to by Data.1269If the number represented by String exceeds the range defined by UINT64, then1270MAX_UINT64 is stored at the location pointed to by Data.12711272If EndPointer is not NULL, a pointer to the character that stopped the scan1273is stored at the location pointed to by EndPointer. If String has no valid1274decimal digits right after the optional pad spaces, the value of String is1275stored at the location pointed to by EndPointer.12761277@param String Pointer to a Null-terminated Ascii string.1278@param EndPointer Pointer to character that stops scan.1279@param Data Pointer to the converted value.12801281@retval RETURN_SUCCESS Value is translated from String.1282@retval RETURN_INVALID_PARAMETER If String is NULL.1283If Data is NULL.1284If PcdMaximumAsciiStringLength is not zero,1285and String contains more than1286PcdMaximumAsciiStringLength Ascii1287characters, not including the1288Null-terminator.1289@retval RETURN_UNSUPPORTED If the number represented by String exceeds1290the range defined by UINT64.12911292**/1293RETURN_STATUS1294EFIAPI1295AsciiStrDecimalToUint64S (1296IN CONST CHAR8 *String,1297OUT CHAR8 **EndPointer OPTIONAL,1298OUT UINT64 *Data1299);13001301/**1302Convert a Null-terminated Ascii hexadecimal string to a value of type UINTN.13031304This function outputs a value of type UINTN by interpreting the contents of1305the Ascii string specified by String as a hexadecimal number. The format of1306the input Ascii string String is:13071308[spaces][zeros][x][hexadecimal digits].13091310The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].1311The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If1312"x" appears in the input string, it must be prefixed with at least one 0. The1313function will ignore the pad space, which includes spaces or tab characters,1314before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or1315[hexadecimal digits] will be ignored. Then, the decoding starts after [x] or1316the first valid hexadecimal digit. Then, the function stops at the first1317character that is a not a valid hexadecimal character or Null-terminator,1318whichever on comes first.13191320If String has no valid hexadecimal digits in the above format, then 0 is1321stored at the location pointed to by Data.1322If the number represented by String exceeds the range defined by UINTN, then1323MAX_UINTN is stored at the location pointed to by Data.13241325If EndPointer is not NULL, a pointer to the character that stopped the scan1326is stored at the location pointed to by EndPointer. If String has no valid1327hexadecimal digits right after the optional pad spaces, the value of String1328is stored at the location pointed to by EndPointer.13291330@param String Pointer to a Null-terminated Ascii string.1331@param EndPointer Pointer to character that stops scan.1332@param Data Pointer to the converted value.13331334@retval RETURN_SUCCESS Value is translated from String.1335@retval RETURN_INVALID_PARAMETER If String is NULL.1336If Data is NULL.1337If PcdMaximumAsciiStringLength is not zero,1338and String contains more than1339PcdMaximumAsciiStringLength Ascii1340characters, not including the1341Null-terminator.1342@retval RETURN_UNSUPPORTED If the number represented by String exceeds1343the range defined by UINTN.13441345**/1346RETURN_STATUS1347EFIAPI1348AsciiStrHexToUintnS (1349IN CONST CHAR8 *String,1350OUT CHAR8 **EndPointer OPTIONAL,1351OUT UINTN *Data1352);13531354/**1355Convert a Null-terminated Ascii hexadecimal string to a value of type UINT64.13561357This function outputs a value of type UINT64 by interpreting the contents of1358the Ascii string specified by String as a hexadecimal number. The format of1359the input Ascii string String is:13601361[spaces][zeros][x][hexadecimal digits].13621363The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].1364The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If1365"x" appears in the input string, it must be prefixed with at least one 0. The1366function will ignore the pad space, which includes spaces or tab characters,1367before [zeros], [x] or [hexadecimal digits]. The running zero before [x] or1368[hexadecimal digits] will be ignored. Then, the decoding starts after [x] or1369the first valid hexadecimal digit. Then, the function stops at the first1370character that is a not a valid hexadecimal character or Null-terminator,1371whichever on comes first.13721373If String has no valid hexadecimal digits in the above format, then 0 is1374stored at the location pointed to by Data.1375If the number represented by String exceeds the range defined by UINT64, then1376MAX_UINT64 is stored at the location pointed to by Data.13771378If EndPointer is not NULL, a pointer to the character that stopped the scan1379is stored at the location pointed to by EndPointer. If String has no valid1380hexadecimal digits right after the optional pad spaces, the value of String1381is stored at the location pointed to by EndPointer.13821383@param String Pointer to a Null-terminated Ascii string.1384@param EndPointer Pointer to character that stops scan.1385@param Data Pointer to the converted value.13861387@retval RETURN_SUCCESS Value is translated from String.1388@retval RETURN_INVALID_PARAMETER If String is NULL.1389If Data is NULL.1390If PcdMaximumAsciiStringLength is not zero,1391and String contains more than1392PcdMaximumAsciiStringLength Ascii1393characters, not including the1394Null-terminator.1395@retval RETURN_UNSUPPORTED If the number represented by String exceeds1396the range defined by UINT64.13971398**/1399RETURN_STATUS1400EFIAPI1401AsciiStrHexToUint64S (1402IN CONST CHAR8 *String,1403OUT CHAR8 **EndPointer OPTIONAL,1404OUT UINT64 *Data1405);14061407/**1408Returns the length of a Null-terminated Unicode string.14091410This function returns the number of Unicode characters in the Null-terminated1411Unicode string specified by String.14121413If String is NULL, then ASSERT().1414If String is not aligned on a 16-bit boundary, then ASSERT().1415If PcdMaximumUnicodeStringLength is not zero, and String contains more than1416PcdMaximumUnicodeStringLength Unicode characters not including the1417Null-terminator, then ASSERT().14181419@param String Pointer to a Null-terminated Unicode string.14201421@return The length of String.14221423**/1424UINTN1425EFIAPI1426StrLen (1427IN CONST CHAR16 *String1428);14291430/**1431Returns the size of a Null-terminated Unicode string in bytes, including the1432Null terminator.14331434This function returns the size, in bytes, of the Null-terminated Unicode string1435specified by String.14361437If String is NULL, then ASSERT().1438If String is not aligned on a 16-bit boundary, then ASSERT().1439If PcdMaximumUnicodeStringLength is not zero, and String contains more than1440PcdMaximumUnicodeStringLength Unicode characters not including the1441Null-terminator, then ASSERT().14421443@param String The pointer to a Null-terminated Unicode string.14441445@return The size of String.14461447**/1448UINTN1449EFIAPI1450StrSize (1451IN CONST CHAR16 *String1452);14531454/**1455Compares two Null-terminated Unicode strings, and returns the difference1456between the first mismatched Unicode characters.14571458This function compares the Null-terminated Unicode string FirstString to the1459Null-terminated Unicode string SecondString. If FirstString is identical to1460SecondString, then 0 is returned. Otherwise, the value returned is the first1461mismatched Unicode character in SecondString subtracted from the first1462mismatched Unicode character in FirstString.14631464If FirstString is NULL, then ASSERT().1465If FirstString is not aligned on a 16-bit boundary, then ASSERT().1466If SecondString is NULL, then ASSERT().1467If SecondString is not aligned on a 16-bit boundary, then ASSERT().1468If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more1469than PcdMaximumUnicodeStringLength Unicode characters not including the1470Null-terminator, then ASSERT().1471If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more1472than PcdMaximumUnicodeStringLength Unicode characters, not including the1473Null-terminator, then ASSERT().14741475@param FirstString The pointer to a Null-terminated Unicode string.1476@param SecondString The pointer to a Null-terminated Unicode string.14771478@retval 0 FirstString is identical to SecondString.1479@return others FirstString is not identical to SecondString.14801481**/1482INTN1483EFIAPI1484StrCmp (1485IN CONST CHAR16 *FirstString,1486IN CONST CHAR16 *SecondString1487);14881489/**1490Compares up to a specified length the contents of two Null-terminated Unicode strings,1491and returns the difference between the first mismatched Unicode characters.14921493This function compares the Null-terminated Unicode string FirstString to the1494Null-terminated Unicode string SecondString. At most, Length Unicode1495characters will be compared. If Length is 0, then 0 is returned. If1496FirstString is identical to SecondString, then 0 is returned. Otherwise, the1497value returned is the first mismatched Unicode character in SecondString1498subtracted from the first mismatched Unicode character in FirstString.14991500If Length > 0 and FirstString is NULL, then ASSERT().1501If Length > 0 and FirstString is not aligned on a 16-bit boundary, then ASSERT().1502If Length > 0 and SecondString is NULL, then ASSERT().1503If Length > 0 and SecondString is not aligned on a 16-bit boundary, then ASSERT().1504If PcdMaximumUnicodeStringLength is not zero, and Length is greater than1505PcdMaximumUnicodeStringLength, then ASSERT().1506If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more than1507PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,1508then ASSERT().1509If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more than1510PcdMaximumUnicodeStringLength Unicode characters, not including the Null-terminator,1511then ASSERT().15121513@param FirstString The pointer to a Null-terminated Unicode string.1514@param SecondString The pointer to a Null-terminated Unicode string.1515@param Length The maximum number of Unicode characters to compare.15161517@retval 0 FirstString is identical to SecondString.1518@return others FirstString is not identical to SecondString.15191520**/1521INTN1522EFIAPI1523StrnCmp (1524IN CONST CHAR16 *FirstString,1525IN CONST CHAR16 *SecondString,1526IN UINTN Length1527);15281529/**1530Returns the first occurrence of a Null-terminated Unicode sub-string1531in a Null-terminated Unicode string.15321533This function scans the contents of the Null-terminated Unicode string1534specified by String and returns the first occurrence of SearchString.1535If SearchString is not found in String, then NULL is returned. If1536the length of SearchString is zero, then String is returned.15371538If String is NULL, then ASSERT().1539If String is not aligned on a 16-bit boundary, then ASSERT().1540If SearchString is NULL, then ASSERT().1541If SearchString is not aligned on a 16-bit boundary, then ASSERT().15421543If PcdMaximumUnicodeStringLength is not zero, and SearchString1544or String contains more than PcdMaximumUnicodeStringLength Unicode1545characters, not including the Null-terminator, then ASSERT().15461547@param String The pointer to a Null-terminated Unicode string.1548@param SearchString The pointer to a Null-terminated Unicode string to search for.15491550@retval NULL If the SearchString does not appear in String.1551@return others If there is a match.15521553**/1554CHAR16 *1555EFIAPI1556StrStr (1557IN CONST CHAR16 *String,1558IN CONST CHAR16 *SearchString1559);15601561/**1562Convert a Null-terminated Unicode decimal string to a value of1563type UINTN.15641565This function returns a value of type UINTN by interpreting the contents1566of the Unicode string specified by String as a decimal number. The format1567of the input Unicode string String is:15681569[spaces] [decimal digits].15701571The valid decimal digit character is in the range [0-9]. The1572function will ignore the pad space, which includes spaces or1573tab characters, before [decimal digits]. The running zero in the1574beginning of [decimal digits] will be ignored. Then, the function1575stops at the first character that is a not a valid decimal character1576or a Null-terminator, whichever one comes first.15771578If String is NULL, then ASSERT().1579If String is not aligned in a 16-bit boundary, then ASSERT().1580If String has only pad spaces, then 0 is returned.1581If String has no pad spaces or valid decimal digits,1582then 0 is returned.1583If the number represented by String overflows according1584to the range defined by UINTN, then MAX_UINTN is returned.15851586If PcdMaximumUnicodeStringLength is not zero, and String contains1587more than PcdMaximumUnicodeStringLength Unicode characters not including1588the Null-terminator, then ASSERT().15891590@param String The pointer to a Null-terminated Unicode string.15911592@retval Value translated from String.15931594**/1595UINTN1596EFIAPI1597StrDecimalToUintn (1598IN CONST CHAR16 *String1599);16001601/**1602Convert a Null-terminated Unicode decimal string to a value of1603type UINT64.16041605This function returns a value of type UINT64 by interpreting the contents1606of the Unicode string specified by String as a decimal number. The format1607of the input Unicode string String is:16081609[spaces] [decimal digits].16101611The valid decimal digit character is in the range [0-9]. The1612function will ignore the pad space, which includes spaces or1613tab characters, before [decimal digits]. The running zero in the1614beginning of [decimal digits] will be ignored. Then, the function1615stops at the first character that is a not a valid decimal character1616or a Null-terminator, whichever one comes first.16171618If String is NULL, then ASSERT().1619If String is not aligned in a 16-bit boundary, then ASSERT().1620If String has only pad spaces, then 0 is returned.1621If String has no pad spaces or valid decimal digits,1622then 0 is returned.1623If the number represented by String overflows according1624to the range defined by UINT64, then MAX_UINT64 is returned.16251626If PcdMaximumUnicodeStringLength is not zero, and String contains1627more than PcdMaximumUnicodeStringLength Unicode characters not including1628the Null-terminator, then ASSERT().16291630@param String The pointer to a Null-terminated Unicode string.16311632@retval Value translated from String.16331634**/1635UINT641636EFIAPI1637StrDecimalToUint64 (1638IN CONST CHAR16 *String1639);16401641/**1642Convert a Null-terminated Unicode hexadecimal string to a value of type UINTN.16431644This function returns a value of type UINTN by interpreting the contents1645of the Unicode string specified by String as a hexadecimal number.1646The format of the input Unicode string String is:16471648[spaces][zeros][x][hexadecimal digits].16491650The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].1651The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.1652If "x" appears in the input string, it must be prefixed with at least one 0.1653The function will ignore the pad space, which includes spaces or tab characters,1654before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or1655[hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the1656first valid hexadecimal digit. Then, the function stops at the first character1657that is a not a valid hexadecimal character or NULL, whichever one comes first.16581659If String is NULL, then ASSERT().1660If String is not aligned in a 16-bit boundary, then ASSERT().1661If String has only pad spaces, then zero is returned.1662If String has no leading pad spaces, leading zeros or valid hexadecimal digits,1663then zero is returned.1664If the number represented by String overflows according to the range defined by1665UINTN, then MAX_UINTN is returned.16661667If PcdMaximumUnicodeStringLength is not zero, and String contains more than1668PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,1669then ASSERT().16701671@param String The pointer to a Null-terminated Unicode string.16721673@retval Value translated from String.16741675**/1676UINTN1677EFIAPI1678StrHexToUintn (1679IN CONST CHAR16 *String1680);16811682/**1683Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.16841685This function returns a value of type UINT64 by interpreting the contents1686of the Unicode string specified by String as a hexadecimal number.1687The format of the input Unicode string String is16881689[spaces][zeros][x][hexadecimal digits].16901691The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].1692The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.1693If "x" appears in the input string, it must be prefixed with at least one 0.1694The function will ignore the pad space, which includes spaces or tab characters,1695before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or1696[hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the1697first valid hexadecimal digit. Then, the function stops at the first character that is1698a not a valid hexadecimal character or NULL, whichever one comes first.16991700If String is NULL, then ASSERT().1701If String is not aligned in a 16-bit boundary, then ASSERT().1702If String has only pad spaces, then zero is returned.1703If String has no leading pad spaces, leading zeros or valid hexadecimal digits,1704then zero is returned.1705If the number represented by String overflows according to the range defined by1706UINT64, then MAX_UINT64 is returned.17071708If PcdMaximumUnicodeStringLength is not zero, and String contains more than1709PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator,1710then ASSERT().17111712@param String The pointer to a Null-terminated Unicode string.17131714@retval Value translated from String.17151716**/1717UINT641718EFIAPI1719StrHexToUint64 (1720IN CONST CHAR16 *String1721);17221723/**1724Convert a Null-terminated Unicode string to IPv6 address and prefix length.17251726This function outputs a value of type IPv6_ADDRESS and may output a value1727of type UINT8 by interpreting the contents of the Unicode string specified1728by String. The format of the input Unicode string String is as follows:17291730X:X:X:X:X:X:X:X[/P]17311732X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and1733[A-F]. X is converted to a value of type UINT16, whose low byte is stored in low1734memory address and high byte is stored in high memory address. P contains decimal1735digit characters in the range [0-9]. The running zero in the beginning of P will1736be ignored. /P is optional.17371738When /P is not in the String, the function stops at the first character that is1739not a valid hexadecimal digit character after eight X's are converted.17401741When /P is in the String, the function stops at the first character that is not1742a valid decimal digit character after P is converted.17431744"::" can be used to compress one or more groups of X when X contains only 0.1745The "::" can only appear once in the String.17461747If String is not aligned in a 16-bit boundary, then ASSERT().17481749If EndPointer is not NULL and Address is translated from String, a pointer1750to the character that stopped the scan is stored at the location pointed to1751by EndPointer.17521753@param String Pointer to a Null-terminated Unicode string.1754@param EndPointer Pointer to character that stops scan.1755@param Address Pointer to the converted IPv6 address.1756@param PrefixLength Pointer to the converted IPv6 address prefix1757length. MAX_UINT8 is returned when /P is1758not in the String.17591760@retval RETURN_SUCCESS Address is translated from String.1761@retval RETURN_INVALID_PARAMETER If String is NULL.1762If Data is NULL.1763@retval RETURN_UNSUPPORTED If X contains more than four hexadecimal1764digit characters.1765If String contains "::" and number of X1766is not less than 8.1767If P starts with character that is not a1768valid decimal digit character.1769If the decimal number converted from P1770exceeds 128.17711772**/1773RETURN_STATUS1774EFIAPI1775StrToIpv6Address (1776IN CONST CHAR16 *String,1777OUT CHAR16 **EndPointer OPTIONAL,1778OUT IPv6_ADDRESS *Address,1779OUT UINT8 *PrefixLength OPTIONAL1780);17811782/**1783Convert a Null-terminated Unicode string to IPv4 address and prefix length.17841785This function outputs a value of type IPv4_ADDRESS and may output a value1786of type UINT8 by interpreting the contents of the Unicode string specified1787by String. The format of the input Unicode string String is as follows:17881789D.D.D.D[/P]17901791D and P are decimal digit characters in the range [0-9]. The running zero in1792the beginning of D and P will be ignored. /P is optional.17931794When /P is not in the String, the function stops at the first character that is1795not a valid decimal digit character after four D's are converted.17961797When /P is in the String, the function stops at the first character that is not1798a valid decimal digit character after P is converted.17991800If String is not aligned in a 16-bit boundary, then ASSERT().18011802If EndPointer is not NULL and Address is translated from String, a pointer1803to the character that stopped the scan is stored at the location pointed to1804by EndPointer.18051806@param String Pointer to a Null-terminated Unicode string.1807@param EndPointer Pointer to character that stops scan.1808@param Address Pointer to the converted IPv4 address.1809@param PrefixLength Pointer to the converted IPv4 address prefix1810length. MAX_UINT8 is returned when /P is1811not in the String.18121813@retval RETURN_SUCCESS Address is translated from String.1814@retval RETURN_INVALID_PARAMETER If String is NULL.1815If Data is NULL.1816@retval RETURN_UNSUPPORTED If String is not in the correct format.1817If any decimal number converted from D1818exceeds 255.1819If the decimal number converted from P1820exceeds 32.18211822**/1823RETURN_STATUS1824EFIAPI1825StrToIpv4Address (1826IN CONST CHAR16 *String,1827OUT CHAR16 **EndPointer OPTIONAL,1828OUT IPv4_ADDRESS *Address,1829OUT UINT8 *PrefixLength OPTIONAL1830);18311832#define GUID_STRING_LENGTH 3618331834/**1835Convert a Null-terminated Unicode GUID string to a value of type1836EFI_GUID.18371838This function outputs a GUID value by interpreting the contents of1839the Unicode string specified by String. The format of the input1840Unicode string String consists of 36 characters, as follows:18411842aabbccdd-eeff-gghh-iijj-kkllmmnnoopp18431844The pairs aa - pp are two characters in the range [0-9], [a-f] and1845[A-F], with each pair representing a single byte hexadecimal value.18461847The mapping between String and the EFI_GUID structure is as follows:1848aa Data1[24:31]1849bb Data1[16:23]1850cc Data1[8:15]1851dd Data1[0:7]1852ee Data2[8:15]1853ff Data2[0:7]1854gg Data3[8:15]1855hh Data3[0:7]1856ii Data4[0:7]1857jj Data4[8:15]1858kk Data4[16:23]1859ll Data4[24:31]1860mm Data4[32:39]1861nn Data4[40:47]1862oo Data4[48:55]1863pp Data4[56:63]18641865If String is not aligned in a 16-bit boundary, then ASSERT().18661867@param String Pointer to a Null-terminated Unicode string.1868@param Guid Pointer to the converted GUID.18691870@retval RETURN_SUCCESS Guid is translated from String.1871@retval RETURN_INVALID_PARAMETER If String is NULL.1872If Data is NULL.1873@retval RETURN_UNSUPPORTED If String is not as the above format.18741875**/1876RETURN_STATUS1877EFIAPI1878StrToGuid (1879IN CONST CHAR16 *String,1880OUT GUID *Guid1881);18821883/**1884Convert a Null-terminated Unicode hexadecimal string to a byte array.18851886This function outputs a byte array by interpreting the contents of1887the Unicode string specified by String in hexadecimal format. The format of1888the input Unicode string String is:18891890[XX]*18911892X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].1893The function decodes every two hexadecimal digit characters as one byte. The1894decoding stops after Length of characters and outputs Buffer containing1895(Length / 2) bytes.18961897If String is not aligned in a 16-bit boundary, then ASSERT().18981899@param String Pointer to a Null-terminated Unicode string.1900@param Length The number of Unicode characters to decode.1901@param Buffer Pointer to the converted bytes array.1902@param MaxBufferSize The maximum size of Buffer.19031904@retval RETURN_SUCCESS Buffer is translated from String.1905@retval RETURN_INVALID_PARAMETER If String is NULL.1906If Data is NULL.1907If Length is not multiple of 2.1908If PcdMaximumUnicodeStringLength is not zero,1909and Length is greater than1910PcdMaximumUnicodeStringLength.1911@retval RETURN_UNSUPPORTED If Length of characters from String contain1912a character that is not valid hexadecimal1913digit characters, or a Null-terminator.1914@retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length / 2).1915**/1916RETURN_STATUS1917EFIAPI1918StrHexToBytes (1919IN CONST CHAR16 *String,1920IN UINTN Length,1921OUT UINT8 *Buffer,1922IN UINTN MaxBufferSize1923);19241925/**1926Convert a Null-terminated Unicode string to a Null-terminated1927ASCII string.19281929This function is similar to AsciiStrCpyS.19301931This function converts the content of the Unicode string Source1932to the ASCII string Destination by copying the lower 8 bits of1933each Unicode character. The function terminates the ASCII string1934Destination by appending a Null-terminator character at the end.19351936The caller is responsible to make sure Destination points to a buffer with size1937equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.19381939If any Unicode characters in Source contain non-zero value in1940the upper 8 bits, then ASSERT().19411942If Source is not aligned on a 16-bit boundary, then ASSERT().19431944If an error is returned, then the Destination is unmodified.19451946@param Source The pointer to a Null-terminated Unicode string.1947@param Destination The pointer to a Null-terminated ASCII string.1948@param DestMax The maximum number of Destination Ascii1949char, including terminating null char.19501951@retval RETURN_SUCCESS String is converted.1952@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).1953@retval RETURN_INVALID_PARAMETER If Destination is NULL.1954If Source is NULL.1955If PcdMaximumAsciiStringLength is not zero,1956and DestMax is greater than1957PcdMaximumAsciiStringLength.1958If PcdMaximumUnicodeStringLength is not zero,1959and DestMax is greater than1960PcdMaximumUnicodeStringLength.1961If DestMax is 0.1962@retval RETURN_ACCESS_DENIED If Source and Destination overlap.19631964**/1965RETURN_STATUS1966EFIAPI1967UnicodeStrToAsciiStrS (1968IN CONST CHAR16 *Source,1969OUT CHAR8 *Destination,1970IN UINTN DestMax1971);19721973/**1974Convert not more than Length successive characters from a Null-terminated1975Unicode string to a Null-terminated Ascii string. If no null char is copied1976from Source, then Destination[Length] is always set to null.19771978This function converts not more than Length successive characters from the1979Unicode string Source to the Ascii string Destination by copying the lower 81980bits of each Unicode character. The function terminates the Ascii string1981Destination by appending a Null-terminator character at the end.19821983The caller is responsible to make sure Destination points to a buffer with size1984equal or greater than ((StrLen (Source) + 1) * sizeof (CHAR8)) in bytes.19851986If any Unicode characters in Source contain non-zero value in the upper 81987bits, then ASSERT().1988If Source is not aligned on a 16-bit boundary, then ASSERT().19891990If an error is returned, then the Destination is unmodified.19911992@param Source The pointer to a Null-terminated Unicode string.1993@param Length The maximum number of Unicode characters to1994convert.1995@param Destination The pointer to a Null-terminated Ascii string.1996@param DestMax The maximum number of Destination Ascii1997char, including terminating null char.1998@param DestinationLength The number of Unicode characters converted.19992000@retval RETURN_SUCCESS String is converted.2001@retval RETURN_INVALID_PARAMETER If Destination is NULL.2002If Source is NULL.2003If DestinationLength is NULL.2004If PcdMaximumAsciiStringLength is not zero,2005and Length or DestMax is greater than2006PcdMaximumAsciiStringLength.2007If PcdMaximumUnicodeStringLength is not2008zero, and Length or DestMax is greater than2009PcdMaximumUnicodeStringLength.2010If DestMax is 0.2011@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than2012MIN(StrLen(Source), Length).2013@retval RETURN_ACCESS_DENIED If Source and Destination overlap.20142015**/2016RETURN_STATUS2017EFIAPI2018UnicodeStrnToAsciiStrS (2019IN CONST CHAR16 *Source,2020IN UINTN Length,2021OUT CHAR8 *Destination,2022IN UINTN DestMax,2023OUT UINTN *DestinationLength2024);20252026/**2027Returns the length of a Null-terminated ASCII string.20282029This function returns the number of ASCII characters in the Null-terminated2030ASCII string specified by String.20312032If Length > 0 and Destination is NULL, then ASSERT().2033If Length > 0 and Source is NULL, then ASSERT().2034If PcdMaximumAsciiStringLength is not zero and String contains more than2035PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,2036then ASSERT().20372038@param String The pointer to a Null-terminated ASCII string.20392040@return The length of String.20412042**/2043UINTN2044EFIAPI2045AsciiStrLen (2046IN CONST CHAR8 *String2047);20482049/**2050Returns the size of a Null-terminated ASCII string in bytes, including the2051Null terminator.20522053This function returns the size, in bytes, of the Null-terminated ASCII string2054specified by String.20552056If String is NULL, then ASSERT().2057If PcdMaximumAsciiStringLength is not zero and String contains more than2058PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,2059then ASSERT().20602061@param String The pointer to a Null-terminated ASCII string.20622063@return The size of String.20642065**/2066UINTN2067EFIAPI2068AsciiStrSize (2069IN CONST CHAR8 *String2070);20712072/**2073Compares two Null-terminated ASCII strings, and returns the difference2074between the first mismatched ASCII characters.20752076This function compares the Null-terminated ASCII string FirstString to the2077Null-terminated ASCII string SecondString. If FirstString is identical to2078SecondString, then 0 is returned. Otherwise, the value returned is the first2079mismatched ASCII character in SecondString subtracted from the first2080mismatched ASCII character in FirstString.20812082If FirstString is NULL, then ASSERT().2083If SecondString is NULL, then ASSERT().2084If PcdMaximumAsciiStringLength is not zero and FirstString contains more than2085PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,2086then ASSERT().2087If PcdMaximumAsciiStringLength is not zero and SecondString contains more2088than PcdMaximumAsciiStringLength ASCII characters not including the2089Null-terminator, then ASSERT().20902091@param FirstString The pointer to a Null-terminated ASCII string.2092@param SecondString The pointer to a Null-terminated ASCII string.20932094@retval ==0 FirstString is identical to SecondString.2095@retval !=0 FirstString is not identical to SecondString.20962097**/2098INTN2099EFIAPI2100AsciiStrCmp (2101IN CONST CHAR8 *FirstString,2102IN CONST CHAR8 *SecondString2103);21042105/**2106Performs a case insensitive comparison of two Null-terminated ASCII strings,2107and returns the difference between the first mismatched ASCII characters.21082109This function performs a case insensitive comparison of the Null-terminated2110ASCII string FirstString to the Null-terminated ASCII string SecondString. If2111FirstString is identical to SecondString, then 0 is returned. Otherwise, the2112value returned is the first mismatched lower case ASCII character in2113SecondString subtracted from the first mismatched lower case ASCII character2114in FirstString.21152116If FirstString is NULL, then ASSERT().2117If SecondString is NULL, then ASSERT().2118If PcdMaximumAsciiStringLength is not zero and FirstString contains more than2119PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,2120then ASSERT().2121If PcdMaximumAsciiStringLength is not zero and SecondString contains more2122than PcdMaximumAsciiStringLength ASCII characters not including the2123Null-terminator, then ASSERT().21242125@param FirstString The pointer to a Null-terminated ASCII string.2126@param SecondString The pointer to a Null-terminated ASCII string.21272128@retval ==0 FirstString is identical to SecondString using case insensitive2129comparisons.2130@retval !=0 FirstString is not identical to SecondString using case2131insensitive comparisons.21322133**/2134INTN2135EFIAPI2136AsciiStriCmp (2137IN CONST CHAR8 *FirstString,2138IN CONST CHAR8 *SecondString2139);21402141/**2142Compares two Null-terminated ASCII strings with maximum lengths, and returns2143the difference between the first mismatched ASCII characters.21442145This function compares the Null-terminated ASCII string FirstString to the2146Null-terminated ASCII string SecondString. At most, Length ASCII characters2147will be compared. If Length is 0, then 0 is returned. If FirstString is2148identical to SecondString, then 0 is returned. Otherwise, the value returned2149is the first mismatched ASCII character in SecondString subtracted from the2150first mismatched ASCII character in FirstString.21512152If Length > 0 and FirstString is NULL, then ASSERT().2153If Length > 0 and SecondString is NULL, then ASSERT().2154If PcdMaximumAsciiStringLength is not zero, and Length is greater than2155PcdMaximumAsciiStringLength, then ASSERT().2156If PcdMaximumAsciiStringLength is not zero, and FirstString contains more than2157PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,2158then ASSERT().2159If PcdMaximumAsciiStringLength is not zero, and SecondString contains more than2160PcdMaximumAsciiStringLength ASCII characters, not including the Null-terminator,2161then ASSERT().21622163@param FirstString The pointer to a Null-terminated ASCII string.2164@param SecondString The pointer to a Null-terminated ASCII string.2165@param Length The maximum number of ASCII characters for compare.21662167@retval ==0 FirstString is identical to SecondString.2168@retval !=0 FirstString is not identical to SecondString.21692170**/2171INTN2172EFIAPI2173AsciiStrnCmp (2174IN CONST CHAR8 *FirstString,2175IN CONST CHAR8 *SecondString,2176IN UINTN Length2177);21782179/**2180Returns the first occurrence of a Null-terminated ASCII sub-string2181in a Null-terminated ASCII string.21822183This function scans the contents of the ASCII string specified by String2184and returns the first occurrence of SearchString. If SearchString is not2185found in String, then NULL is returned. If the length of SearchString is zero,2186then String is returned.21872188If String is NULL, then ASSERT().2189If SearchString is NULL, then ASSERT().21902191If PcdMaximumAsciiStringLength is not zero, and SearchString or2192String contains more than PcdMaximumAsciiStringLength Unicode characters2193not including the Null-terminator, then ASSERT().21942195@param String The pointer to a Null-terminated ASCII string.2196@param SearchString The pointer to a Null-terminated ASCII string to search for.21972198@retval NULL If the SearchString does not appear in String.2199@retval others If there is a match return the first occurrence of SearchingString.2200If the length of SearchString is zero,return String.22012202**/2203CHAR8 *2204EFIAPI2205AsciiStrStr (2206IN CONST CHAR8 *String,2207IN CONST CHAR8 *SearchString2208);22092210/**2211Convert a Null-terminated ASCII decimal string to a value of type2212UINTN.22132214This function returns a value of type UINTN by interpreting the contents2215of the ASCII string String as a decimal number. The format of the input2216ASCII string String is:22172218[spaces] [decimal digits].22192220The valid decimal digit character is in the range [0-9]. The function will2221ignore the pad space, which includes spaces or tab characters, before the digits.2222The running zero in the beginning of [decimal digits] will be ignored. Then, the2223function stops at the first character that is a not a valid decimal character or2224Null-terminator, whichever on comes first.22252226If String has only pad spaces, then 0 is returned.2227If String has no pad spaces or valid decimal digits, then 0 is returned.2228If the number represented by String overflows according to the range defined by2229UINTN, then MAX_UINTN is returned.2230If String is NULL, then ASSERT().2231If PcdMaximumAsciiStringLength is not zero, and String contains more than2232PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,2233then ASSERT().22342235@param String The pointer to a Null-terminated ASCII string.22362237@retval The value translated from String.22382239**/2240UINTN2241EFIAPI2242AsciiStrDecimalToUintn (2243IN CONST CHAR8 *String2244);22452246/**2247Convert a Null-terminated ASCII decimal string to a value of type2248UINT64.22492250This function returns a value of type UINT64 by interpreting the contents2251of the ASCII string String as a decimal number. The format of the input2252ASCII string String is:22532254[spaces] [decimal digits].22552256The valid decimal digit character is in the range [0-9]. The function will2257ignore the pad space, which includes spaces or tab characters, before the digits.2258The running zero in the beginning of [decimal digits] will be ignored. Then, the2259function stops at the first character that is a not a valid decimal character or2260Null-terminator, whichever on comes first.22612262If String has only pad spaces, then 0 is returned.2263If String has no pad spaces or valid decimal digits, then 0 is returned.2264If the number represented by String overflows according to the range defined by2265UINT64, then MAX_UINT64 is returned.2266If String is NULL, then ASSERT().2267If PcdMaximumAsciiStringLength is not zero, and String contains more than2268PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator,2269then ASSERT().22702271@param String The pointer to a Null-terminated ASCII string.22722273@retval Value translated from String.22742275**/2276UINT642277EFIAPI2278AsciiStrDecimalToUint64 (2279IN CONST CHAR8 *String2280);22812282/**2283Convert a Null-terminated ASCII hexadecimal string to a value of type UINTN.22842285This function returns a value of type UINTN by interpreting the contents of2286the ASCII string String as a hexadecimal number. The format of the input ASCII2287string String is:22882289[spaces][zeros][x][hexadecimal digits].22902291The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].2292The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"2293appears in the input string, it must be prefixed with at least one 0. The function2294will ignore the pad space, which includes spaces or tab characters, before [zeros],2295[x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]2296will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal2297digit. Then, the function stops at the first character that is a not a valid2298hexadecimal character or Null-terminator, whichever on comes first.22992300If String has only pad spaces, then 0 is returned.2301If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then23020 is returned.23032304If the number represented by String overflows according to the range defined by UINTN,2305then MAX_UINTN is returned.2306If String is NULL, then ASSERT().2307If PcdMaximumAsciiStringLength is not zero,2308and String contains more than PcdMaximumAsciiStringLength ASCII characters not including2309the Null-terminator, then ASSERT().23102311@param String The pointer to a Null-terminated ASCII string.23122313@retval Value translated from String.23142315**/2316UINTN2317EFIAPI2318AsciiStrHexToUintn (2319IN CONST CHAR8 *String2320);23212322/**2323Convert a Null-terminated ASCII hexadecimal string to a value of type UINT64.23242325This function returns a value of type UINT64 by interpreting the contents of2326the ASCII string String as a hexadecimal number. The format of the input ASCII2327string String is:23282329[spaces][zeros][x][hexadecimal digits].23302331The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].2332The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix. If "x"2333appears in the input string, it must be prefixed with at least one 0. The function2334will ignore the pad space, which includes spaces or tab characters, before [zeros],2335[x] or [hexadecimal digits]. The running zero before [x] or [hexadecimal digits]2336will be ignored. Then, the decoding starts after [x] or the first valid hexadecimal2337digit. Then, the function stops at the first character that is a not a valid2338hexadecimal character or Null-terminator, whichever on comes first.23392340If String has only pad spaces, then 0 is returned.2341If String has no leading pad spaces, leading zeros or valid hexadecimal digits, then23420 is returned.23432344If the number represented by String overflows according to the range defined by UINT64,2345then MAX_UINT64 is returned.2346If String is NULL, then ASSERT().2347If PcdMaximumAsciiStringLength is not zero,2348and String contains more than PcdMaximumAsciiStringLength ASCII characters not including2349the Null-terminator, then ASSERT().23502351@param String The pointer to a Null-terminated ASCII string.23522353@retval Value translated from String.23542355**/2356UINT642357EFIAPI2358AsciiStrHexToUint64 (2359IN CONST CHAR8 *String2360);23612362/**2363Convert a Null-terminated ASCII string to IPv6 address and prefix length.23642365This function outputs a value of type IPv6_ADDRESS and may output a value2366of type UINT8 by interpreting the contents of the ASCII string specified2367by String. The format of the input ASCII string String is as follows:23682369X:X:X:X:X:X:X:X[/P]23702371X contains one to four hexadecimal digit characters in the range [0-9], [a-f] and2372[A-F]. X is converted to a value of type UINT16, whose low byte is stored in low2373memory address and high byte is stored in high memory address. P contains decimal2374digit characters in the range [0-9]. The running zero in the beginning of P will2375be ignored. /P is optional.23762377When /P is not in the String, the function stops at the first character that is2378not a valid hexadecimal digit character after eight X's are converted.23792380When /P is in the String, the function stops at the first character that is not2381a valid decimal digit character after P is converted.23822383"::" can be used to compress one or more groups of X when X contains only 0.2384The "::" can only appear once in the String.23852386If EndPointer is not NULL and Address is translated from String, a pointer2387to the character that stopped the scan is stored at the location pointed to2388by EndPointer.23892390@param String Pointer to a Null-terminated ASCII string.2391@param EndPointer Pointer to character that stops scan.2392@param Address Pointer to the converted IPv6 address.2393@param PrefixLength Pointer to the converted IPv6 address prefix2394length. MAX_UINT8 is returned when /P is2395not in the String.23962397@retval RETURN_SUCCESS Address is translated from String.2398@retval RETURN_INVALID_PARAMETER If String is NULL.2399If Data is NULL.2400@retval RETURN_UNSUPPORTED If X contains more than four hexadecimal2401digit characters.2402If String contains "::" and number of X2403is not less than 8.2404If P starts with character that is not a2405valid decimal digit character.2406If the decimal number converted from P2407exceeds 128.24082409**/2410RETURN_STATUS2411EFIAPI2412AsciiStrToIpv6Address (2413IN CONST CHAR8 *String,2414OUT CHAR8 **EndPointer OPTIONAL,2415OUT IPv6_ADDRESS *Address,2416OUT UINT8 *PrefixLength OPTIONAL2417);24182419/**2420Convert a Null-terminated ASCII string to IPv4 address and prefix length.24212422This function outputs a value of type IPv4_ADDRESS and may output a value2423of type UINT8 by interpreting the contents of the ASCII string specified2424by String. The format of the input ASCII string String is as follows:24252426D.D.D.D[/P]24272428D and P are decimal digit characters in the range [0-9]. The running zero in2429the beginning of D and P will be ignored. /P is optional.24302431When /P is not in the String, the function stops at the first character that is2432not a valid decimal digit character after four D's are converted.24332434When /P is in the String, the function stops at the first character that is not2435a valid decimal digit character after P is converted.24362437If EndPointer is not NULL and Address is translated from String, a pointer2438to the character that stopped the scan is stored at the location pointed to2439by EndPointer.24402441@param String Pointer to a Null-terminated ASCII string.2442@param EndPointer Pointer to character that stops scan.2443@param Address Pointer to the converted IPv4 address.2444@param PrefixLength Pointer to the converted IPv4 address prefix2445length. MAX_UINT8 is returned when /P is2446not in the String.24472448@retval RETURN_SUCCESS Address is translated from String.2449@retval RETURN_INVALID_PARAMETER If String is NULL.2450If Data is NULL.2451@retval RETURN_UNSUPPORTED If String is not in the correct format.2452If any decimal number converted from D2453exceeds 255.2454If the decimal number converted from P2455exceeds 32.24562457**/2458RETURN_STATUS2459EFIAPI2460AsciiStrToIpv4Address (2461IN CONST CHAR8 *String,2462OUT CHAR8 **EndPointer OPTIONAL,2463OUT IPv4_ADDRESS *Address,2464OUT UINT8 *PrefixLength OPTIONAL2465);24662467/**2468Convert a Null-terminated ASCII GUID string to a value of type2469EFI_GUID.24702471This function outputs a GUID value by interpreting the contents of2472the ASCII string specified by String. The format of the input2473ASCII string String consists of 36 characters, as follows:24742475aabbccdd-eeff-gghh-iijj-kkllmmnnoopp24762477The pairs aa - pp are two characters in the range [0-9], [a-f] and2478[A-F], with each pair representing a single byte hexadecimal value.24792480The mapping between String and the EFI_GUID structure is as follows:2481aa Data1[24:31]2482bb Data1[16:23]2483cc Data1[8:15]2484dd Data1[0:7]2485ee Data2[8:15]2486ff Data2[0:7]2487gg Data3[8:15]2488hh Data3[0:7]2489ii Data4[0:7]2490jj Data4[8:15]2491kk Data4[16:23]2492ll Data4[24:31]2493mm Data4[32:39]2494nn Data4[40:47]2495oo Data4[48:55]2496pp Data4[56:63]24972498@param String Pointer to a Null-terminated ASCII string.2499@param Guid Pointer to the converted GUID.25002501@retval RETURN_SUCCESS Guid is translated from String.2502@retval RETURN_INVALID_PARAMETER If String is NULL.2503If Data is NULL.2504@retval RETURN_UNSUPPORTED If String is not as the above format.25052506**/2507RETURN_STATUS2508EFIAPI2509AsciiStrToGuid (2510IN CONST CHAR8 *String,2511OUT GUID *Guid2512);25132514/**2515Convert a Null-terminated ASCII hexadecimal string to a byte array.25162517This function outputs a byte array by interpreting the contents of2518the ASCII string specified by String in hexadecimal format. The format of2519the input ASCII string String is:25202521[XX]*25222523X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F].2524The function decodes every two hexadecimal digit characters as one byte. The2525decoding stops after Length of characters and outputs Buffer containing2526(Length / 2) bytes.25272528@param String Pointer to a Null-terminated ASCII string.2529@param Length The number of ASCII characters to decode.2530@param Buffer Pointer to the converted bytes array.2531@param MaxBufferSize The maximum size of Buffer.25322533@retval RETURN_SUCCESS Buffer is translated from String.2534@retval RETURN_INVALID_PARAMETER If String is NULL.2535If Data is NULL.2536If Length is not multiple of 2.2537If PcdMaximumAsciiStringLength is not zero,2538and Length is greater than2539PcdMaximumAsciiStringLength.2540@retval RETURN_UNSUPPORTED If Length of characters from String contain2541a character that is not valid hexadecimal2542digit characters, or a Null-terminator.2543@retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length / 2).2544**/2545RETURN_STATUS2546EFIAPI2547AsciiStrHexToBytes (2548IN CONST CHAR8 *String,2549IN UINTN Length,2550OUT UINT8 *Buffer,2551IN UINTN MaxBufferSize2552);25532554/**2555Convert one Null-terminated ASCII string to a Null-terminated2556Unicode string.25572558This function is similar to StrCpyS.25592560This function converts the contents of the ASCII string Source to the Unicode2561string Destination. The function terminates the Unicode string Destination by2562appending a Null-terminator character at the end.25632564The caller is responsible to make sure Destination points to a buffer with size2565equal or greater than ((AsciiStrLen (Source) + 1) * sizeof (CHAR16)) in bytes.25662567If Destination is not aligned on a 16-bit boundary, then ASSERT().25682569If an error is returned, then the Destination is unmodified.25702571@param Source The pointer to a Null-terminated ASCII string.2572@param Destination The pointer to a Null-terminated Unicode string.2573@param DestMax The maximum number of Destination Unicode2574char, including terminating null char.25752576@retval RETURN_SUCCESS String is converted.2577@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than StrLen(Source).2578@retval RETURN_INVALID_PARAMETER If Destination is NULL.2579If Source is NULL.2580If PcdMaximumUnicodeStringLength is not zero,2581and DestMax is greater than2582PcdMaximumUnicodeStringLength.2583If PcdMaximumAsciiStringLength is not zero,2584and DestMax is greater than2585PcdMaximumAsciiStringLength.2586If DestMax is 0.2587@retval RETURN_ACCESS_DENIED If Source and Destination overlap.25882589**/2590RETURN_STATUS2591EFIAPI2592AsciiStrToUnicodeStrS (2593IN CONST CHAR8 *Source,2594OUT CHAR16 *Destination,2595IN UINTN DestMax2596);25972598/**2599Convert not more than Length successive characters from a Null-terminated2600Ascii string to a Null-terminated Unicode string. If no null char is copied2601from Source, then Destination[Length] is always set to null.26022603This function converts not more than Length successive characters from the2604Ascii string Source to the Unicode string Destination. The function2605terminates the Unicode string Destination by appending a Null-terminator2606character at the end.26072608The caller is responsible to make sure Destination points to a buffer with2609size not smaller than2610((MIN(AsciiStrLen(Source), Length) + 1) * sizeof (CHAR8)) in bytes.26112612If Destination is not aligned on a 16-bit boundary, then ASSERT().26132614If an error is returned, then Destination and DestinationLength are2615unmodified.26162617@param Source The pointer to a Null-terminated Ascii string.2618@param Length The maximum number of Ascii characters to convert.2619@param Destination The pointer to a Null-terminated Unicode string.2620@param DestMax The maximum number of Destination Unicode char,2621including terminating null char.2622@param DestinationLength The number of Ascii characters converted.26232624@retval RETURN_SUCCESS String is converted.2625@retval RETURN_INVALID_PARAMETER If Destination is NULL.2626If Source is NULL.2627If DestinationLength is NULL.2628If PcdMaximumUnicodeStringLength is not2629zero, and Length or DestMax is greater than2630PcdMaximumUnicodeStringLength.2631If PcdMaximumAsciiStringLength is not zero,2632and Length or DestMax is greater than2633PcdMaximumAsciiStringLength.2634If DestMax is 0.2635@retval RETURN_BUFFER_TOO_SMALL If DestMax is NOT greater than2636MIN(AsciiStrLen(Source), Length).2637@retval RETURN_ACCESS_DENIED If Source and Destination overlap.26382639**/2640RETURN_STATUS2641EFIAPI2642AsciiStrnToUnicodeStrS (2643IN CONST CHAR8 *Source,2644IN UINTN Length,2645OUT CHAR16 *Destination,2646IN UINTN DestMax,2647OUT UINTN *DestinationLength2648);26492650/**2651Convert a Unicode character to upper case only if2652it maps to a valid small-case ASCII character.26532654This internal function only deal with Unicode character2655which maps to a valid small-case ASCII character, i.e.2656L'a' to L'z'. For other Unicode character, the input character2657is returned directly.26582659@param Char The character to convert.26602661@retval LowerCharacter If the Char is with range L'a' to L'z'.2662@retval Unchanged Otherwise.26632664**/2665CHAR162666EFIAPI2667CharToUpper (2668IN CHAR16 Char2669);26702671/**2672Converts a lowercase Ascii character to upper one.26732674If Chr is lowercase Ascii character, then converts it to upper one.26752676If Value >= 0xA0, then ASSERT().2677If (Value & 0x0F) >= 0x0A, then ASSERT().26782679@param Chr one Ascii character26802681@return The uppercase value of Ascii character26822683**/2684CHAR82685EFIAPI2686AsciiCharToUpper (2687IN CHAR8 Chr2688);26892690/**2691Convert binary data to a Base64 encoded ascii string based on RFC4648.26922693Produce a Null-terminated Ascii string in the output buffer specified by Destination and DestinationSize.2694The Ascii string is produced by converting the data string specified by Source and SourceLength.26952696@param Source Input UINT8 data2697@param SourceLength Number of UINT8 bytes of data2698@param Destination Pointer to output string buffer2699@param DestinationSize Size of ascii buffer. Set to 0 to get the size needed.2700Caller is responsible for passing in buffer of DestinationSize27012702@retval RETURN_SUCCESS When ascii buffer is filled in.2703@retval RETURN_INVALID_PARAMETER If Source is NULL or DestinationSize is NULL.2704@retval RETURN_INVALID_PARAMETER If SourceLength or DestinationSize is bigger than (MAX_ADDRESS - (UINTN)Destination).2705@retval RETURN_BUFFER_TOO_SMALL If SourceLength is 0 and DestinationSize is <1.2706@retval RETURN_BUFFER_TOO_SMALL If Destination is NULL or DestinationSize is smaller than required buffersize.27072708**/2709RETURN_STATUS2710EFIAPI2711Base64Encode (2712IN CONST UINT8 *Source,2713IN UINTN SourceLength,2714OUT CHAR8 *Destination OPTIONAL,2715IN OUT UINTN *DestinationSize2716);27172718/**2719Decode Base64 ASCII encoded data to 8-bit binary representation, based on2720RFC4648.27212722Decoding occurs according to "Table 1: The Base 64 Alphabet" in RFC4648.27232724Whitespace is ignored at all positions:2725- 0x09 ('\t') horizontal tab2726- 0x0A ('\n') new line2727- 0x0B ('\v') vertical tab2728- 0x0C ('\f') form feed2729- 0x0D ('\r') carriage return2730- 0x20 (' ') space27312732The minimum amount of required padding (with ASCII 0x3D, '=') is tolerated2733and enforced at the end of the Base64 ASCII encoded data, and only there.27342735Other characters outside of the encoding alphabet cause the function to2736reject the Base64 ASCII encoded data.27372738@param[in] Source Array of CHAR8 elements containing the Base642739ASCII encoding. May be NULL if SourceSize is2740zero.27412742@param[in] SourceSize Number of CHAR8 elements in Source.27432744@param[out] Destination Array of UINT8 elements receiving the decoded27458-bit binary representation. Allocated by the2746caller. May be NULL if DestinationSize is2747zero on input. If NULL, decoding is2748performed, but the 8-bit binary2749representation is not stored. If non-NULL and2750the function returns an error, the contents2751of Destination are indeterminate.27522753@param[in,out] DestinationSize On input, the number of UINT8 elements that2754the caller allocated for Destination. On2755output, if the function returns2756RETURN_SUCCESS or RETURN_BUFFER_TOO_SMALL,2757the number of UINT8 elements that are2758required for decoding the Base64 ASCII2759representation. If the function returns a2760value different from both RETURN_SUCCESS and2761RETURN_BUFFER_TOO_SMALL, then DestinationSize2762is indeterminate on output.27632764@retval RETURN_SUCCESS SourceSize CHAR8 elements at Source have2765been decoded to on-output DestinationSize2766UINT8 elements at Destination. Note that2767RETURN_SUCCESS covers the case when2768DestinationSize is zero on input, and2769Source decodes to zero bytes (due to2770containing at most ignored whitespace).27712772@retval RETURN_BUFFER_TOO_SMALL The input value of DestinationSize is not2773large enough for decoding SourceSize CHAR82774elements at Source. The required number of2775UINT8 elements has been stored to2776DestinationSize.27772778@retval RETURN_INVALID_PARAMETER DestinationSize is NULL.27792780@retval RETURN_INVALID_PARAMETER Source is NULL, but SourceSize is not zero.27812782@retval RETURN_INVALID_PARAMETER Destination is NULL, but DestinationSize is2783not zero on input.27842785@retval RETURN_INVALID_PARAMETER Source is non-NULL, and (Source +2786SourceSize) would wrap around MAX_ADDRESS.27872788@retval RETURN_INVALID_PARAMETER Destination is non-NULL, and (Destination +2789DestinationSize) would wrap around2790MAX_ADDRESS, as specified on input.27912792@retval RETURN_INVALID_PARAMETER None of Source and Destination are NULL,2793and CHAR8[SourceSize] at Source overlaps2794UINT8[DestinationSize] at Destination, as2795specified on input.27962797@retval RETURN_INVALID_PARAMETER Invalid CHAR8 element encountered in2798Source.2799**/2800RETURN_STATUS2801EFIAPI2802Base64Decode (2803IN CONST CHAR8 *Source OPTIONAL,2804IN UINTN SourceSize,2805OUT UINT8 *Destination OPTIONAL,2806IN OUT UINTN *DestinationSize2807);28082809/**2810Converts an 8-bit value to an 8-bit BCD value.28112812Converts the 8-bit value specified by Value to BCD. The BCD value is2813returned.28142815If Value >= 100, then ASSERT().28162817@param Value The 8-bit value to convert to BCD. Range 0..99.28182819@return The BCD value.28202821**/2822UINT82823EFIAPI2824DecimalToBcd8 (2825IN UINT8 Value2826);28272828/**2829Converts an 8-bit BCD value to an 8-bit value.28302831Converts the 8-bit BCD value specified by Value to an 8-bit value. The 8-bit2832value is returned.28332834If Value >= 0xA0, then ASSERT().2835If (Value & 0x0F) >= 0x0A, then ASSERT().28362837@param Value The 8-bit BCD value to convert to an 8-bit value.28382839@return The 8-bit value is returned.28402841**/2842UINT82843EFIAPI2844BcdToDecimal8 (2845IN UINT8 Value2846);28472848//2849// File Path Manipulation Functions2850//28512852/**2853Removes the last directory or file entry in a path.28542855@param[in, out] Path The pointer to the path to modify.28562857@retval FALSE Nothing was found to remove.2858@retval TRUE A directory or file was removed.2859**/2860BOOLEAN2861EFIAPI2862PathRemoveLastItem (2863IN OUT CHAR16 *Path2864);28652866/**2867Function to clean up paths.2868- Single periods in the path are removed.2869- Double periods in the path are removed along with a single parent directory.2870- Forward slashes L'/' are converted to backward slashes L'\'.28712872This will be done inline and the existing buffer may be larger than required2873upon completion.28742875@param[in] Path The pointer to the string containing the path.28762877@return Returns Path, otherwise returns NULL to indicate that an error has occurred.2878**/2879CHAR16 *2880EFIAPI2881PathCleanUpDirectories (2882IN CHAR16 *Path2883);28842885//2886// Linked List Functions and Macros2887//28882889/**2890Initializes the head node of a doubly linked list that is declared as a2891global variable in a module.28922893Initializes the forward and backward links of a new linked list. After2894initializing a linked list with this macro, the other linked list functions2895may be used to add and remove nodes from the linked list. This macro results2896in smaller executables by initializing the linked list in the data section,2897instead if calling the InitializeListHead() function to perform the2898equivalent operation.28992900@param ListHead The head note of a list to initialize.29012902**/2903#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead) {&(ListHead), &(ListHead)}29042905/**2906Iterates over each node in a doubly linked list using each node's forward link.29072908@param Entry A pointer to a list node used as a loop cursor during iteration2909@param ListHead The head node of the doubly linked list29102911**/2912#define BASE_LIST_FOR_EACH(Entry, ListHead) \2913for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)29142915/**2916Iterates over each node in a doubly linked list using each node's forward link2917with safety against node removal.29182919This macro uses NextEntry to temporarily store the next list node so the node2920pointed to by Entry may be deleted in the current loop iteration step and2921iteration can continue from the node pointed to by NextEntry.29222923@param Entry A pointer to a list node used as a loop cursor during iteration2924@param NextEntry A pointer to a list node used to temporarily store the next node2925@param ListHead The head node of the doubly linked list29262927**/2928#define BASE_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \2929for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\2930Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)29312932/**2933Checks whether FirstEntry and SecondEntry are part of the same doubly-linked2934list.29352936If FirstEntry is NULL, then ASSERT().2937If FirstEntry->ForwardLink is NULL, then ASSERT().2938If FirstEntry->BackLink is NULL, then ASSERT().2939If SecondEntry is NULL, then ASSERT();2940If PcdMaximumLinkedListLength is not zero, and List contains more than2941PcdMaximumLinkedListLength nodes, then ASSERT().29422943@param FirstEntry A pointer to a node in a linked list.2944@param SecondEntry A pointer to the node to locate.29452946@retval TRUE SecondEntry is in the same doubly-linked list as FirstEntry.2947@retval FALSE SecondEntry isn't in the same doubly-linked list as FirstEntry,2948or FirstEntry is invalid.29492950**/2951BOOLEAN2952EFIAPI2953IsNodeInList (2954IN CONST LIST_ENTRY *FirstEntry,2955IN CONST LIST_ENTRY *SecondEntry2956);29572958/**2959Initializes the head node of a doubly linked list, and returns the pointer to2960the head node of the doubly linked list.29612962Initializes the forward and backward links of a new linked list. After2963initializing a linked list with this function, the other linked list2964functions may be used to add and remove nodes from the linked list. It is up2965to the caller of this function to allocate the memory for ListHead.29662967If ListHead is NULL, then ASSERT().29682969@param ListHead A pointer to the head node of a new doubly linked list.29702971@return ListHead29722973**/2974LIST_ENTRY *2975EFIAPI2976InitializeListHead (2977IN OUT LIST_ENTRY *ListHead2978);29792980/**2981Adds a node to the beginning of a doubly linked list, and returns the pointer2982to the head node of the doubly linked list.29832984Adds the node Entry at the beginning of the doubly linked list denoted by2985ListHead, and returns ListHead.29862987If ListHead is NULL, then ASSERT().2988If Entry is NULL, then ASSERT().2989If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or2990InitializeListHead(), then ASSERT().2991If PcdMaximumLinkedListLength is not zero, and prior to insertion the number2992of nodes in ListHead, including the ListHead node, is greater than or2993equal to PcdMaximumLinkedListLength, then ASSERT().29942995@param ListHead A pointer to the head node of a doubly linked list.2996@param Entry A pointer to a node that is to be inserted at the beginning2997of a doubly linked list.29982999@return ListHead30003001**/3002LIST_ENTRY *3003EFIAPI3004InsertHeadList (3005IN OUT LIST_ENTRY *ListHead,3006IN OUT LIST_ENTRY *Entry3007);30083009/**3010Adds a node to the end of a doubly linked list, and returns the pointer to3011the head node of the doubly linked list.30123013Adds the node Entry to the end of the doubly linked list denoted by ListHead,3014and returns ListHead.30153016If ListHead is NULL, then ASSERT().3017If Entry is NULL, then ASSERT().3018If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or3019InitializeListHead(), then ASSERT().3020If PcdMaximumLinkedListLength is not zero, and prior to insertion the number3021of nodes in ListHead, including the ListHead node, is greater than or3022equal to PcdMaximumLinkedListLength, then ASSERT().30233024@param ListHead A pointer to the head node of a doubly linked list.3025@param Entry A pointer to a node that is to be added at the end of the3026doubly linked list.30273028@return ListHead30293030**/3031LIST_ENTRY *3032EFIAPI3033InsertTailList (3034IN OUT LIST_ENTRY *ListHead,3035IN OUT LIST_ENTRY *Entry3036);30373038/**3039Retrieves the first node of a doubly linked list.30403041Returns the first node of a doubly linked list. List must have been3042initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().3043If List is empty, then List is returned.30443045If List is NULL, then ASSERT().3046If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or3047InitializeListHead(), then ASSERT().3048If PcdMaximumLinkedListLength is not zero, and the number of nodes3049in List, including the List node, is greater than or equal to3050PcdMaximumLinkedListLength, then ASSERT().30513052@param List A pointer to the head node of a doubly linked list.30533054@return The first node of a doubly linked list.3055@retval List The list is empty.30563057**/3058LIST_ENTRY *3059EFIAPI3060GetFirstNode (3061IN CONST LIST_ENTRY *List3062);30633064/**3065Retrieves the next node of a doubly linked list.30663067Returns the node of a doubly linked list that follows Node.3068List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()3069or InitializeListHead(). If List is empty, then List is returned.30703071If List is NULL, then ASSERT().3072If Node is NULL, then ASSERT().3073If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or3074InitializeListHead(), then ASSERT().3075If PcdMaximumLinkedListLength is not zero, and List contains more than3076PcdMaximumLinkedListLength nodes, then ASSERT().3077If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().30783079@param List A pointer to the head node of a doubly linked list.3080@param Node A pointer to a node in the doubly linked list.30813082@return The pointer to the next node if one exists. Otherwise List is returned.30833084**/3085LIST_ENTRY *3086EFIAPI3087GetNextNode (3088IN CONST LIST_ENTRY *List,3089IN CONST LIST_ENTRY *Node3090);30913092/**3093Retrieves the previous node of a doubly linked list.30943095Returns the node of a doubly linked list that precedes Node.3096List must have been initialized with INTIALIZE_LIST_HEAD_VARIABLE()3097or InitializeListHead(). If List is empty, then List is returned.30983099If List is NULL, then ASSERT().3100If Node is NULL, then ASSERT().3101If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or3102InitializeListHead(), then ASSERT().3103If PcdMaximumLinkedListLength is not zero, and List contains more than3104PcdMaximumLinkedListLength nodes, then ASSERT().3105If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().31063107@param List A pointer to the head node of a doubly linked list.3108@param Node A pointer to a node in the doubly linked list.31093110@return The pointer to the previous node if one exists. Otherwise List is returned.31113112**/3113LIST_ENTRY *3114EFIAPI3115GetPreviousNode (3116IN CONST LIST_ENTRY *List,3117IN CONST LIST_ENTRY *Node3118);31193120/**3121Checks to see if a doubly linked list is empty or not.31223123Checks to see if the doubly linked list is empty. If the linked list contains3124zero nodes, this function returns TRUE. Otherwise, it returns FALSE.31253126If ListHead is NULL, then ASSERT().3127If ListHead was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or3128InitializeListHead(), then ASSERT().3129If PcdMaximumLinkedListLength is not zero, and the number of nodes3130in List, including the List node, is greater than or equal to3131PcdMaximumLinkedListLength, then ASSERT().31323133@param ListHead A pointer to the head node of a doubly linked list.31343135@retval TRUE The linked list is empty.3136@retval FALSE The linked list is not empty.31373138**/3139BOOLEAN3140EFIAPI3141IsListEmpty (3142IN CONST LIST_ENTRY *ListHead3143);31443145/**3146Determines if a node in a doubly linked list is the head node of a the same3147doubly linked list. This function is typically used to terminate a loop that3148traverses all the nodes in a doubly linked list starting with the head node.31493150Returns TRUE if Node is equal to List. Returns FALSE if Node is one of the3151nodes in the doubly linked list specified by List. List must have been3152initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().31533154If List is NULL, then ASSERT().3155If Node is NULL, then ASSERT().3156If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead(),3157then ASSERT().3158If PcdMaximumLinkedListLength is not zero, and the number of nodes3159in List, including the List node, is greater than or equal to3160PcdMaximumLinkedListLength, then ASSERT().3161If PcdVerifyNodeInList is TRUE and Node is not a node in List the and Node is not equal3162to List, then ASSERT().31633164@param List A pointer to the head node of a doubly linked list.3165@param Node A pointer to a node in the doubly linked list.31663167@retval TRUE Node is the head of the doubly-linked list pointed by List.3168@retval FALSE Node is not the head of the doubly-linked list pointed by List.31693170**/3171BOOLEAN3172EFIAPI3173IsNull (3174IN CONST LIST_ENTRY *List,3175IN CONST LIST_ENTRY *Node3176);31773178/**3179Determines if a node the last node in a doubly linked list.31803181Returns TRUE if Node is the last node in the doubly linked list specified by3182List. Otherwise, FALSE is returned. List must have been initialized with3183INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().31843185If List is NULL, then ASSERT().3186If Node is NULL, then ASSERT().3187If List was not initialized with INTIALIZE_LIST_HEAD_VARIABLE() or3188InitializeListHead(), then ASSERT().3189If PcdMaximumLinkedListLength is not zero, and the number of nodes3190in List, including the List node, is greater than or equal to3191PcdMaximumLinkedListLength, then ASSERT().3192If PcdVerifyNodeInList is TRUE and Node is not a node in List, then ASSERT().31933194@param List A pointer to the head node of a doubly linked list.3195@param Node A pointer to a node in the doubly linked list.31963197@retval TRUE Node is the last node in the linked list.3198@retval FALSE Node is not the last node in the linked list.31993200**/3201BOOLEAN3202EFIAPI3203IsNodeAtEnd (3204IN CONST LIST_ENTRY *List,3205IN CONST LIST_ENTRY *Node3206);32073208/**3209Swaps the location of two nodes in a doubly linked list, and returns the3210first node after the swap.32113212If FirstEntry is identical to SecondEntry, then SecondEntry is returned.3213Otherwise, the location of the FirstEntry node is swapped with the location3214of the SecondEntry node in a doubly linked list. SecondEntry must be in the3215same double linked list as FirstEntry and that double linked list must have3216been initialized with INTIALIZE_LIST_HEAD_VARIABLE() or InitializeListHead().3217SecondEntry is returned after the nodes are swapped.32183219If FirstEntry is NULL, then ASSERT().3220If SecondEntry is NULL, then ASSERT().3221If PcdVerifyNodeInList is TRUE and SecondEntry and FirstEntry are not in the3222same linked list, then ASSERT().3223If PcdMaximumLinkedListLength is not zero, and the number of nodes in the3224linked list containing the FirstEntry and SecondEntry nodes, including3225the FirstEntry and SecondEntry nodes, is greater than or equal to3226PcdMaximumLinkedListLength, then ASSERT().32273228@param FirstEntry A pointer to a node in a linked list.3229@param SecondEntry A pointer to another node in the same linked list.32303231@return SecondEntry.32323233**/3234LIST_ENTRY *3235EFIAPI3236SwapListEntries (3237IN OUT LIST_ENTRY *FirstEntry,3238IN OUT LIST_ENTRY *SecondEntry3239);32403241/**3242Removes a node from a doubly linked list, and returns the node that follows3243the removed node.32443245Removes the node Entry from a doubly linked list. It is up to the caller of3246this function to release the memory used by this node if that is required. On3247exit, the node following Entry in the doubly linked list is returned. If3248Entry is the only node in the linked list, then the head node of the linked3249list is returned.32503251If Entry is NULL, then ASSERT().3252If Entry is the head node of an empty list, then ASSERT().3253If PcdMaximumLinkedListLength is not zero, and the number of nodes in the3254linked list containing Entry, including the Entry node, is greater than3255or equal to PcdMaximumLinkedListLength, then ASSERT().32563257@param Entry A pointer to a node in a linked list.32583259@return Entry.32603261**/3262LIST_ENTRY *3263EFIAPI3264RemoveEntryList (3265IN CONST LIST_ENTRY *Entry3266);32673268//3269// Math Services3270//32713272/**3273Prototype for comparison function for any two element types.32743275@param[in] Buffer1 The pointer to first buffer.3276@param[in] Buffer2 The pointer to second buffer.32773278@retval 0 Buffer1 equal to Buffer2.3279@return <0 Buffer1 is less than Buffer2.3280@return >0 Buffer1 is greater than Buffer2.3281**/3282typedef3283INTN3284(EFIAPI *BASE_SORT_COMPARE)(3285IN CONST VOID *Buffer1,3286IN CONST VOID *Buffer23287);32883289/**3290This function is identical to perform QuickSort,3291except that is uses the pre-allocated buffer so the in place sorting does not need to3292allocate and free buffers constantly.32933294Each element must be equal sized.32953296if BufferToSort is NULL, then ASSERT.3297if CompareFunction is NULL, then ASSERT.3298if BufferOneElement is NULL, then ASSERT.3299if ElementSize is < 1, then ASSERT.33003301if Count is < 2 then perform no action.33023303@param[in, out] BufferToSort on call a Buffer of (possibly sorted) elements3304on return a buffer of sorted elements3305@param[in] Count the number of elements in the buffer to sort3306@param[in] ElementSize Size of an element in bytes3307@param[in] CompareFunction The function to call to perform the comparison3308of any 2 elements3309@param[out] BufferOneElement Caller provided buffer whose size equals to ElementSize.3310It's used by QuickSort() for swapping in sorting.3311**/3312VOID3313EFIAPI3314QuickSort (3315IN OUT VOID *BufferToSort,3316IN CONST UINTN Count,3317IN CONST UINTN ElementSize,3318IN BASE_SORT_COMPARE CompareFunction,3319OUT VOID *BufferOneElement3320);33213322/**3323Shifts a 64-bit integer left between 0 and 63 bits. The low bits are filled3324with zeros. The shifted value is returned.33253326This function shifts the 64-bit value Operand to the left by Count bits. The3327low Count bits are set to zero. The shifted value is returned.33283329If Count is greater than 63, then ASSERT().33303331@param Operand The 64-bit operand to shift left.3332@param Count The number of bits to shift left.33333334@return Operand << Count.33353336**/3337UINT643338EFIAPI3339LShiftU64 (3340IN UINT64 Operand,3341IN UINTN Count3342);33433344/**3345Shifts a 64-bit integer right between 0 and 63 bits. This high bits are3346filled with zeros. The shifted value is returned.33473348This function shifts the 64-bit value Operand to the right by Count bits. The3349high Count bits are set to zero. The shifted value is returned.33503351If Count is greater than 63, then ASSERT().33523353@param Operand The 64-bit operand to shift right.3354@param Count The number of bits to shift right.33553356@return Operand >> Count33573358**/3359UINT643360EFIAPI3361RShiftU64 (3362IN UINT64 Operand,3363IN UINTN Count3364);33653366/**3367Shifts a 64-bit integer right between 0 and 63 bits. The high bits are filled3368with original integer's bit 63. The shifted value is returned.33693370This function shifts the 64-bit value Operand to the right by Count bits. The3371high Count bits are set to bit 63 of Operand. The shifted value is returned.33723373If Count is greater than 63, then ASSERT().33743375@param Operand The 64-bit operand to shift right.3376@param Count The number of bits to shift right.33773378@return Operand >> Count33793380**/3381UINT643382EFIAPI3383ARShiftU64 (3384IN UINT64 Operand,3385IN UINTN Count3386);33873388/**3389Rotates a 32-bit integer left between 0 and 31 bits, filling the low bits3390with the high bits that were rotated.33913392This function rotates the 32-bit value Operand to the left by Count bits. The3393low Count bits are fill with the high Count bits of Operand. The rotated3394value is returned.33953396If Count is greater than 31, then ASSERT().33973398@param Operand The 32-bit operand to rotate left.3399@param Count The number of bits to rotate left.34003401@return Operand << Count34023403**/3404UINT323405EFIAPI3406LRotU32 (3407IN UINT32 Operand,3408IN UINTN Count3409);34103411/**3412Rotates a 32-bit integer right between 0 and 31 bits, filling the high bits3413with the low bits that were rotated.34143415This function rotates the 32-bit value Operand to the right by Count bits.3416The high Count bits are fill with the low Count bits of Operand. The rotated3417value is returned.34183419If Count is greater than 31, then ASSERT().34203421@param Operand The 32-bit operand to rotate right.3422@param Count The number of bits to rotate right.34233424@return Operand >> Count34253426**/3427UINT323428EFIAPI3429RRotU32 (3430IN UINT32 Operand,3431IN UINTN Count3432);34333434/**3435Rotates a 64-bit integer left between 0 and 63 bits, filling the low bits3436with the high bits that were rotated.34373438This function rotates the 64-bit value Operand to the left by Count bits. The3439low Count bits are fill with the high Count bits of Operand. The rotated3440value is returned.34413442If Count is greater than 63, then ASSERT().34433444@param Operand The 64-bit operand to rotate left.3445@param Count The number of bits to rotate left.34463447@return Operand << Count34483449**/3450UINT643451EFIAPI3452LRotU64 (3453IN UINT64 Operand,3454IN UINTN Count3455);34563457/**3458Rotates a 64-bit integer right between 0 and 63 bits, filling the high bits3459with the high low bits that were rotated.34603461This function rotates the 64-bit value Operand to the right by Count bits.3462The high Count bits are fill with the low Count bits of Operand. The rotated3463value is returned.34643465If Count is greater than 63, then ASSERT().34663467@param Operand The 64-bit operand to rotate right.3468@param Count The number of bits to rotate right.34693470@return Operand >> Count34713472**/3473UINT643474EFIAPI3475RRotU64 (3476IN UINT64 Operand,3477IN UINTN Count3478);34793480/**3481Returns the bit position of the lowest bit set in a 32-bit value.34823483This function computes the bit position of the lowest bit set in the 32-bit3484value specified by Operand. If Operand is zero, then -1 is returned.3485Otherwise, a value between 0 and 31 is returned.34863487@param Operand The 32-bit operand to evaluate.34883489@retval 0..31 The lowest bit set in Operand was found.3490@retval -1 Operand is zero.34913492**/3493INTN3494EFIAPI3495LowBitSet32 (3496IN UINT32 Operand3497);34983499/**3500Returns the bit position of the lowest bit set in a 64-bit value.35013502This function computes the bit position of the lowest bit set in the 64-bit3503value specified by Operand. If Operand is zero, then -1 is returned.3504Otherwise, a value between 0 and 63 is returned.35053506@param Operand The 64-bit operand to evaluate.35073508@retval 0..63 The lowest bit set in Operand was found.3509@retval -1 Operand is zero.351035113512**/3513INTN3514EFIAPI3515LowBitSet64 (3516IN UINT64 Operand3517);35183519/**3520Returns the bit position of the highest bit set in a 32-bit value. Equivalent3521to log2(x).35223523This function computes the bit position of the highest bit set in the 32-bit3524value specified by Operand. If Operand is zero, then -1 is returned.3525Otherwise, a value between 0 and 31 is returned.35263527@param Operand The 32-bit operand to evaluate.35283529@retval 0..31 Position of the highest bit set in Operand if found.3530@retval -1 Operand is zero.35313532**/3533INTN3534EFIAPI3535HighBitSet32 (3536IN UINT32 Operand3537);35383539/**3540Returns the bit position of the highest bit set in a 64-bit value. Equivalent3541to log2(x).35423543This function computes the bit position of the highest bit set in the 64-bit3544value specified by Operand. If Operand is zero, then -1 is returned.3545Otherwise, a value between 0 and 63 is returned.35463547@param Operand The 64-bit operand to evaluate.35483549@retval 0..63 Position of the highest bit set in Operand if found.3550@retval -1 Operand is zero.35513552**/3553INTN3554EFIAPI3555HighBitSet64 (3556IN UINT64 Operand3557);35583559/**3560Returns the value of the highest bit set in a 32-bit value. Equivalent to35611 << log2(x).35623563This function computes the value of the highest bit set in the 32-bit value3564specified by Operand. If Operand is zero, then zero is returned.35653566@param Operand The 32-bit operand to evaluate.35673568@return 1 << HighBitSet32(Operand)3569@retval 0 Operand is zero.35703571**/3572UINT323573EFIAPI3574GetPowerOfTwo32 (3575IN UINT32 Operand3576);35773578/**3579Returns the value of the highest bit set in a 64-bit value. Equivalent to35801 << log2(x).35813582This function computes the value of the highest bit set in the 64-bit value3583specified by Operand. If Operand is zero, then zero is returned.35843585@param Operand The 64-bit operand to evaluate.35863587@return 1 << HighBitSet64(Operand)3588@retval 0 Operand is zero.35893590**/3591UINT643592EFIAPI3593GetPowerOfTwo64 (3594IN UINT64 Operand3595);35963597/**3598Switches the endianness of a 16-bit integer.35993600This function swaps the bytes in a 16-bit unsigned value to switch the value3601from little endian to big endian or vice versa. The byte swapped value is3602returned.36033604@param Value A 16-bit unsigned value.36053606@return The byte swapped Value.36073608**/3609UINT163610EFIAPI3611SwapBytes16 (3612IN UINT16 Value3613);36143615/**3616Switches the endianness of a 32-bit integer.36173618This function swaps the bytes in a 32-bit unsigned value to switch the value3619from little endian to big endian or vice versa. The byte swapped value is3620returned.36213622@param Value A 32-bit unsigned value.36233624@return The byte swapped Value.36253626**/3627UINT323628EFIAPI3629SwapBytes32 (3630IN UINT32 Value3631);36323633/**3634Switches the endianness of a 64-bit integer.36353636This function swaps the bytes in a 64-bit unsigned value to switch the value3637from little endian to big endian or vice versa. The byte swapped value is3638returned.36393640@param Value A 64-bit unsigned value.36413642@return The byte swapped Value.36433644**/3645UINT643646EFIAPI3647SwapBytes64 (3648IN UINT64 Value3649);36503651/**3652Multiples a 64-bit unsigned integer by a 32-bit unsigned integer and3653generates a 64-bit unsigned result.36543655This function multiples the 64-bit unsigned value Multiplicand by the 32-bit3656unsigned value Multiplier and generates a 64-bit unsigned result. This 64-3657bit unsigned result is returned.36583659@param Multiplicand A 64-bit unsigned value.3660@param Multiplier A 32-bit unsigned value.36613662@return Multiplicand * Multiplier36633664**/3665UINT643666EFIAPI3667MultU64x32 (3668IN UINT64 Multiplicand,3669IN UINT32 Multiplier3670);36713672/**3673Multiples a 64-bit unsigned integer by a 64-bit unsigned integer and3674generates a 64-bit unsigned result.36753676This function multiples the 64-bit unsigned value Multiplicand by the 64-bit3677unsigned value Multiplier and generates a 64-bit unsigned result. This 64-3678bit unsigned result is returned.36793680@param Multiplicand A 64-bit unsigned value.3681@param Multiplier A 64-bit unsigned value.36823683@return Multiplicand * Multiplier.36843685**/3686UINT643687EFIAPI3688MultU64x64 (3689IN UINT64 Multiplicand,3690IN UINT64 Multiplier3691);36923693/**3694Multiples a 64-bit signed integer by a 64-bit signed integer and generates a369564-bit signed result.36963697This function multiples the 64-bit signed value Multiplicand by the 64-bit3698signed value Multiplier and generates a 64-bit signed result. This 64-bit3699signed result is returned.37003701@param Multiplicand A 64-bit signed value.3702@param Multiplier A 64-bit signed value.37033704@return Multiplicand * Multiplier37053706**/3707INT643708EFIAPI3709MultS64x64 (3710IN INT64 Multiplicand,3711IN INT64 Multiplier3712);37133714/**3715Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates3716a 64-bit unsigned result.37173718This function divides the 64-bit unsigned value Dividend by the 32-bit3719unsigned value Divisor and generates a 64-bit unsigned quotient. This3720function returns the 64-bit unsigned quotient.37213722If Divisor is 0, then ASSERT().37233724@param Dividend A 64-bit unsigned value.3725@param Divisor A 32-bit unsigned value.37263727@return Dividend / Divisor.37283729**/3730UINT643731EFIAPI3732DivU64x32 (3733IN UINT64 Dividend,3734IN UINT32 Divisor3735);37363737/**3738Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates3739a 32-bit unsigned remainder.37403741This function divides the 64-bit unsigned value Dividend by the 32-bit3742unsigned value Divisor and generates a 32-bit remainder. This function3743returns the 32-bit unsigned remainder.37443745If Divisor is 0, then ASSERT().37463747@param Dividend A 64-bit unsigned value.3748@param Divisor A 32-bit unsigned value.37493750@return Dividend % Divisor.37513752**/3753UINT323754EFIAPI3755ModU64x32 (3756IN UINT64 Dividend,3757IN UINT32 Divisor3758);37593760/**3761Divides a 64-bit unsigned integer by a 32-bit unsigned integer and generates3762a 64-bit unsigned result and an optional 32-bit unsigned remainder.37633764This function divides the 64-bit unsigned value Dividend by the 32-bit3765unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder3766is not NULL, then the 32-bit unsigned remainder is returned in Remainder.3767This function returns the 64-bit unsigned quotient.37683769If Divisor is 0, then ASSERT().37703771@param Dividend A 64-bit unsigned value.3772@param Divisor A 32-bit unsigned value.3773@param Remainder A pointer to a 32-bit unsigned value. This parameter is3774optional and may be NULL.37753776@return Dividend / Divisor.37773778**/3779UINT643780EFIAPI3781DivU64x32Remainder (3782IN UINT64 Dividend,3783IN UINT32 Divisor,3784OUT UINT32 *Remainder OPTIONAL3785);37863787/**3788Divides a 64-bit unsigned integer by a 64-bit unsigned integer and generates3789a 64-bit unsigned result and an optional 64-bit unsigned remainder.37903791This function divides the 64-bit unsigned value Dividend by the 64-bit3792unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder3793is not NULL, then the 64-bit unsigned remainder is returned in Remainder.3794This function returns the 64-bit unsigned quotient.37953796If Divisor is 0, then ASSERT().37973798@param Dividend A 64-bit unsigned value.3799@param Divisor A 64-bit unsigned value.3800@param Remainder A pointer to a 64-bit unsigned value. This parameter is3801optional and may be NULL.38023803@return Dividend / Divisor.38043805**/3806UINT643807EFIAPI3808DivU64x64Remainder (3809IN UINT64 Dividend,3810IN UINT64 Divisor,3811OUT UINT64 *Remainder OPTIONAL3812);38133814/**3815Divides a 64-bit signed integer by a 64-bit signed integer and generates a381664-bit signed result and a optional 64-bit signed remainder.38173818This function divides the 64-bit signed value Dividend by the 64-bit signed3819value Divisor and generates a 64-bit signed quotient. If Remainder is not3820NULL, then the 64-bit signed remainder is returned in Remainder. This3821function returns the 64-bit signed quotient.38223823It is the caller's responsibility to not call this function with a Divisor of 0.3824If Divisor is 0, then the quotient and remainder should be assumed to be3825the largest negative integer.38263827If Divisor is 0, then ASSERT().38283829@param Dividend A 64-bit signed value.3830@param Divisor A 64-bit signed value.3831@param Remainder A pointer to a 64-bit signed value. This parameter is3832optional and may be NULL.38333834@return Dividend / Divisor.38353836**/3837INT643838EFIAPI3839DivS64x64Remainder (3840IN INT64 Dividend,3841IN INT64 Divisor,3842OUT INT64 *Remainder OPTIONAL3843);38443845/**3846Reads a 16-bit value from memory that may be unaligned.38473848This function returns the 16-bit value pointed to by Buffer. The function3849guarantees that the read operation does not produce an alignment fault.38503851If the Buffer is NULL, then ASSERT().38523853@param Buffer The pointer to a 16-bit value that may be unaligned.38543855@return The 16-bit value read from Buffer.38563857**/3858UINT163859EFIAPI3860ReadUnaligned16 (3861IN CONST UINT16 *Buffer3862);38633864/**3865Writes a 16-bit value to memory that may be unaligned.38663867This function writes the 16-bit value specified by Value to Buffer. Value is3868returned. The function guarantees that the write operation does not produce3869an alignment fault.38703871If the Buffer is NULL, then ASSERT().38723873@param Buffer The pointer to a 16-bit value that may be unaligned.3874@param Value 16-bit value to write to Buffer.38753876@return The 16-bit value to write to Buffer.38773878**/3879UINT163880EFIAPI3881WriteUnaligned16 (3882OUT UINT16 *Buffer,3883IN UINT16 Value3884);38853886/**3887Reads a 24-bit value from memory that may be unaligned.38883889This function returns the 24-bit value pointed to by Buffer. The function3890guarantees that the read operation does not produce an alignment fault.38913892If the Buffer is NULL, then ASSERT().38933894@param Buffer The pointer to a 24-bit value that may be unaligned.38953896@return The 24-bit value read from Buffer.38973898**/3899UINT323900EFIAPI3901ReadUnaligned24 (3902IN CONST UINT32 *Buffer3903);39043905/**3906Writes a 24-bit value to memory that may be unaligned.39073908This function writes the 24-bit value specified by Value to Buffer. Value is3909returned. The function guarantees that the write operation does not produce3910an alignment fault.39113912If the Buffer is NULL, then ASSERT().39133914@param Buffer The pointer to a 24-bit value that may be unaligned.3915@param Value 24-bit value to write to Buffer.39163917@return The 24-bit value to write to Buffer.39183919**/3920UINT323921EFIAPI3922WriteUnaligned24 (3923OUT UINT32 *Buffer,3924IN UINT32 Value3925);39263927/**3928Reads a 32-bit value from memory that may be unaligned.39293930This function returns the 32-bit value pointed to by Buffer. The function3931guarantees that the read operation does not produce an alignment fault.39323933If the Buffer is NULL, then ASSERT().39343935@param Buffer The pointer to a 32-bit value that may be unaligned.39363937@return The 32-bit value read from Buffer.39383939**/3940UINT323941EFIAPI3942ReadUnaligned32 (3943IN CONST UINT32 *Buffer3944);39453946/**3947Writes a 32-bit value to memory that may be unaligned.39483949This function writes the 32-bit value specified by Value to Buffer. Value is3950returned. The function guarantees that the write operation does not produce3951an alignment fault.39523953If the Buffer is NULL, then ASSERT().39543955@param Buffer The pointer to a 32-bit value that may be unaligned.3956@param Value 32-bit value to write to Buffer.39573958@return The 32-bit value to write to Buffer.39593960**/3961UINT323962EFIAPI3963WriteUnaligned32 (3964OUT UINT32 *Buffer,3965IN UINT32 Value3966);39673968/**3969Reads a 64-bit value from memory that may be unaligned.39703971This function returns the 64-bit value pointed to by Buffer. The function3972guarantees that the read operation does not produce an alignment fault.39733974If the Buffer is NULL, then ASSERT().39753976@param Buffer The pointer to a 64-bit value that may be unaligned.39773978@return The 64-bit value read from Buffer.39793980**/3981UINT643982EFIAPI3983ReadUnaligned64 (3984IN CONST UINT64 *Buffer3985);39863987/**3988Writes a 64-bit value to memory that may be unaligned.39893990This function writes the 64-bit value specified by Value to Buffer. Value is3991returned. The function guarantees that the write operation does not produce3992an alignment fault.39933994If the Buffer is NULL, then ASSERT().39953996@param Buffer The pointer to a 64-bit value that may be unaligned.3997@param Value 64-bit value to write to Buffer.39983999@return The 64-bit value to write to Buffer.40004001**/4002UINT644003EFIAPI4004WriteUnaligned64 (4005OUT UINT64 *Buffer,4006IN UINT64 Value4007);40084009//4010// Bit Field Functions4011//40124013/**4014Returns a bit field from an 8-bit value.40154016Returns the bitfield specified by the StartBit and the EndBit from Operand.40174018If 8-bit operations are not supported, then ASSERT().4019If StartBit is greater than 7, then ASSERT().4020If EndBit is greater than 7, then ASSERT().4021If EndBit is less than StartBit, then ASSERT().40224023@param Operand Operand on which to perform the bitfield operation.4024@param StartBit The ordinal of the least significant bit in the bit field.4025Range 0..7.4026@param EndBit The ordinal of the most significant bit in the bit field.4027Range 0..7.40284029@return The bit field read.40304031**/4032UINT84033EFIAPI4034BitFieldRead8 (4035IN UINT8 Operand,4036IN UINTN StartBit,4037IN UINTN EndBit4038);40394040/**4041Writes a bit field to an 8-bit value, and returns the result.40424043Writes Value to the bit field specified by the StartBit and the EndBit in4044Operand. All other bits in Operand are preserved. The new 8-bit value is4045returned.40464047If 8-bit operations are not supported, then ASSERT().4048If StartBit is greater than 7, then ASSERT().4049If EndBit is greater than 7, then ASSERT().4050If EndBit is less than StartBit, then ASSERT().4051If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().40524053@param Operand Operand on which to perform the bitfield operation.4054@param StartBit The ordinal of the least significant bit in the bit field.4055Range 0..7.4056@param EndBit The ordinal of the most significant bit in the bit field.4057Range 0..7.4058@param Value New value of the bit field.40594060@return The new 8-bit value.40614062**/4063UINT84064EFIAPI4065BitFieldWrite8 (4066IN UINT8 Operand,4067IN UINTN StartBit,4068IN UINTN EndBit,4069IN UINT8 Value4070);40714072/**4073Reads a bit field from an 8-bit value, performs a bitwise OR, and returns the4074result.40754076Performs a bitwise OR between the bit field specified by StartBit4077and EndBit in Operand and the value specified by OrData. All other bits in4078Operand are preserved. The new 8-bit value is returned.40794080If 8-bit operations are not supported, then ASSERT().4081If StartBit is greater than 7, then ASSERT().4082If EndBit is greater than 7, then ASSERT().4083If EndBit is less than StartBit, then ASSERT().4084If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().40854086@param Operand Operand on which to perform the bitfield operation.4087@param StartBit The ordinal of the least significant bit in the bit field.4088Range 0..7.4089@param EndBit The ordinal of the most significant bit in the bit field.4090Range 0..7.4091@param OrData The value to OR with the read value from the value40924093@return The new 8-bit value.40944095**/4096UINT84097EFIAPI4098BitFieldOr8 (4099IN UINT8 Operand,4100IN UINTN StartBit,4101IN UINTN EndBit,4102IN UINT8 OrData4103);41044105/**4106Reads a bit field from an 8-bit value, performs a bitwise AND, and returns4107the result.41084109Performs a bitwise AND between the bit field specified by StartBit and EndBit4110in Operand and the value specified by AndData. All other bits in Operand are4111preserved. The new 8-bit value is returned.41124113If 8-bit operations are not supported, then ASSERT().4114If StartBit is greater than 7, then ASSERT().4115If EndBit is greater than 7, then ASSERT().4116If EndBit is less than StartBit, then ASSERT().4117If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().41184119@param Operand Operand on which to perform the bitfield operation.4120@param StartBit The ordinal of the least significant bit in the bit field.4121Range 0..7.4122@param EndBit The ordinal of the most significant bit in the bit field.4123Range 0..7.4124@param AndData The value to AND with the read value from the value.41254126@return The new 8-bit value.41274128**/4129UINT84130EFIAPI4131BitFieldAnd8 (4132IN UINT8 Operand,4133IN UINTN StartBit,4134IN UINTN EndBit,4135IN UINT8 AndData4136);41374138/**4139Reads a bit field from an 8-bit value, performs a bitwise AND followed by a4140bitwise OR, and returns the result.41414142Performs a bitwise AND between the bit field specified by StartBit and EndBit4143in Operand and the value specified by AndData, followed by a bitwise4144OR with value specified by OrData. All other bits in Operand are4145preserved. The new 8-bit value is returned.41464147If 8-bit operations are not supported, then ASSERT().4148If StartBit is greater than 7, then ASSERT().4149If EndBit is greater than 7, then ASSERT().4150If EndBit is less than StartBit, then ASSERT().4151If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().4152If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().41534154@param Operand Operand on which to perform the bitfield operation.4155@param StartBit The ordinal of the least significant bit in the bit field.4156Range 0..7.4157@param EndBit The ordinal of the most significant bit in the bit field.4158Range 0..7.4159@param AndData The value to AND with the read value from the value.4160@param OrData The value to OR with the result of the AND operation.41614162@return The new 8-bit value.41634164**/4165UINT84166EFIAPI4167BitFieldAndThenOr8 (4168IN UINT8 Operand,4169IN UINTN StartBit,4170IN UINTN EndBit,4171IN UINT8 AndData,4172IN UINT8 OrData4173);41744175/**4176Returns a bit field from a 16-bit value.41774178Returns the bitfield specified by the StartBit and the EndBit from Operand.41794180If 16-bit operations are not supported, then ASSERT().4181If StartBit is greater than 15, then ASSERT().4182If EndBit is greater than 15, then ASSERT().4183If EndBit is less than StartBit, then ASSERT().41844185@param Operand Operand on which to perform the bitfield operation.4186@param StartBit The ordinal of the least significant bit in the bit field.4187Range 0..15.4188@param EndBit The ordinal of the most significant bit in the bit field.4189Range 0..15.41904191@return The bit field read.41924193**/4194UINT164195EFIAPI4196BitFieldRead16 (4197IN UINT16 Operand,4198IN UINTN StartBit,4199IN UINTN EndBit4200);42014202/**4203Writes a bit field to a 16-bit value, and returns the result.42044205Writes Value to the bit field specified by the StartBit and the EndBit in4206Operand. All other bits in Operand are preserved. The new 16-bit value is4207returned.42084209If 16-bit operations are not supported, then ASSERT().4210If StartBit is greater than 15, then ASSERT().4211If EndBit is greater than 15, then ASSERT().4212If EndBit is less than StartBit, then ASSERT().4213If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().42144215@param Operand Operand on which to perform the bitfield operation.4216@param StartBit The ordinal of the least significant bit in the bit field.4217Range 0..15.4218@param EndBit The ordinal of the most significant bit in the bit field.4219Range 0..15.4220@param Value New value of the bit field.42214222@return The new 16-bit value.42234224**/4225UINT164226EFIAPI4227BitFieldWrite16 (4228IN UINT16 Operand,4229IN UINTN StartBit,4230IN UINTN EndBit,4231IN UINT16 Value4232);42334234/**4235Reads a bit field from a 16-bit value, performs a bitwise OR, and returns the4236result.42374238Performs a bitwise OR between the bit field specified by StartBit4239and EndBit in Operand and the value specified by OrData. All other bits in4240Operand are preserved. The new 16-bit value is returned.42414242If 16-bit operations are not supported, then ASSERT().4243If StartBit is greater than 15, then ASSERT().4244If EndBit is greater than 15, then ASSERT().4245If EndBit is less than StartBit, then ASSERT().4246If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().42474248@param Operand Operand on which to perform the bitfield operation.4249@param StartBit The ordinal of the least significant bit in the bit field.4250Range 0..15.4251@param EndBit The ordinal of the most significant bit in the bit field.4252Range 0..15.4253@param OrData The value to OR with the read value from the value42544255@return The new 16-bit value.42564257**/4258UINT164259EFIAPI4260BitFieldOr16 (4261IN UINT16 Operand,4262IN UINTN StartBit,4263IN UINTN EndBit,4264IN UINT16 OrData4265);42664267/**4268Reads a bit field from a 16-bit value, performs a bitwise AND, and returns4269the result.42704271Performs a bitwise AND between the bit field specified by StartBit and EndBit4272in Operand and the value specified by AndData. All other bits in Operand are4273preserved. The new 16-bit value is returned.42744275If 16-bit operations are not supported, then ASSERT().4276If StartBit is greater than 15, then ASSERT().4277If EndBit is greater than 15, then ASSERT().4278If EndBit is less than StartBit, then ASSERT().4279If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().42804281@param Operand Operand on which to perform the bitfield operation.4282@param StartBit The ordinal of the least significant bit in the bit field.4283Range 0..15.4284@param EndBit The ordinal of the most significant bit in the bit field.4285Range 0..15.4286@param AndData The value to AND with the read value from the value42874288@return The new 16-bit value.42894290**/4291UINT164292EFIAPI4293BitFieldAnd16 (4294IN UINT16 Operand,4295IN UINTN StartBit,4296IN UINTN EndBit,4297IN UINT16 AndData4298);42994300/**4301Reads a bit field from a 16-bit value, performs a bitwise AND followed by a4302bitwise OR, and returns the result.43034304Performs a bitwise AND between the bit field specified by StartBit and EndBit4305in Operand and the value specified by AndData, followed by a bitwise4306OR with value specified by OrData. All other bits in Operand are4307preserved. The new 16-bit value is returned.43084309If 16-bit operations are not supported, then ASSERT().4310If StartBit is greater than 15, then ASSERT().4311If EndBit is greater than 15, then ASSERT().4312If EndBit is less than StartBit, then ASSERT().4313If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().4314If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().43154316@param Operand Operand on which to perform the bitfield operation.4317@param StartBit The ordinal of the least significant bit in the bit field.4318Range 0..15.4319@param EndBit The ordinal of the most significant bit in the bit field.4320Range 0..15.4321@param AndData The value to AND with the read value from the value.4322@param OrData The value to OR with the result of the AND operation.43234324@return The new 16-bit value.43254326**/4327UINT164328EFIAPI4329BitFieldAndThenOr16 (4330IN UINT16 Operand,4331IN UINTN StartBit,4332IN UINTN EndBit,4333IN UINT16 AndData,4334IN UINT16 OrData4335);43364337/**4338Returns a bit field from a 32-bit value.43394340Returns the bitfield specified by the StartBit and the EndBit from Operand.43414342If 32-bit operations are not supported, then ASSERT().4343If StartBit is greater than 31, then ASSERT().4344If EndBit is greater than 31, then ASSERT().4345If EndBit is less than StartBit, then ASSERT().43464347@param Operand Operand on which to perform the bitfield operation.4348@param StartBit The ordinal of the least significant bit in the bit field.4349Range 0..31.4350@param EndBit The ordinal of the most significant bit in the bit field.4351Range 0..31.43524353@return The bit field read.43544355**/4356UINT324357EFIAPI4358BitFieldRead32 (4359IN UINT32 Operand,4360IN UINTN StartBit,4361IN UINTN EndBit4362);43634364/**4365Writes a bit field to a 32-bit value, and returns the result.43664367Writes Value to the bit field specified by the StartBit and the EndBit in4368Operand. All other bits in Operand are preserved. The new 32-bit value is4369returned.43704371If 32-bit operations are not supported, then ASSERT().4372If StartBit is greater than 31, then ASSERT().4373If EndBit is greater than 31, then ASSERT().4374If EndBit is less than StartBit, then ASSERT().4375If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().43764377@param Operand Operand on which to perform the bitfield operation.4378@param StartBit The ordinal of the least significant bit in the bit field.4379Range 0..31.4380@param EndBit The ordinal of the most significant bit in the bit field.4381Range 0..31.4382@param Value New value of the bit field.43834384@return The new 32-bit value.43854386**/4387UINT324388EFIAPI4389BitFieldWrite32 (4390IN UINT32 Operand,4391IN UINTN StartBit,4392IN UINTN EndBit,4393IN UINT32 Value4394);43954396/**4397Reads a bit field from a 32-bit value, performs a bitwise OR, and returns the4398result.43994400Performs a bitwise OR between the bit field specified by StartBit4401and EndBit in Operand and the value specified by OrData. All other bits in4402Operand are preserved. The new 32-bit value is returned.44034404If 32-bit operations are not supported, then ASSERT().4405If StartBit is greater than 31, then ASSERT().4406If EndBit is greater than 31, then ASSERT().4407If EndBit is less than StartBit, then ASSERT().4408If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().44094410@param Operand Operand on which to perform the bitfield operation.4411@param StartBit The ordinal of the least significant bit in the bit field.4412Range 0..31.4413@param EndBit The ordinal of the most significant bit in the bit field.4414Range 0..31.4415@param OrData The value to OR with the read value from the value.44164417@return The new 32-bit value.44184419**/4420UINT324421EFIAPI4422BitFieldOr32 (4423IN UINT32 Operand,4424IN UINTN StartBit,4425IN UINTN EndBit,4426IN UINT32 OrData4427);44284429/**4430Reads a bit field from a 32-bit value, performs a bitwise AND, and returns4431the result.44324433Performs a bitwise AND between the bit field specified by StartBit and EndBit4434in Operand and the value specified by AndData. All other bits in Operand are4435preserved. The new 32-bit value is returned.44364437If 32-bit operations are not supported, then ASSERT().4438If StartBit is greater than 31, then ASSERT().4439If EndBit is greater than 31, then ASSERT().4440If EndBit is less than StartBit, then ASSERT().4441If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().44424443@param Operand Operand on which to perform the bitfield operation.4444@param StartBit The ordinal of the least significant bit in the bit field.4445Range 0..31.4446@param EndBit The ordinal of the most significant bit in the bit field.4447Range 0..31.4448@param AndData The value to AND with the read value from the value44494450@return The new 32-bit value.44514452**/4453UINT324454EFIAPI4455BitFieldAnd32 (4456IN UINT32 Operand,4457IN UINTN StartBit,4458IN UINTN EndBit,4459IN UINT32 AndData4460);44614462/**4463Reads a bit field from a 32-bit value, performs a bitwise AND followed by a4464bitwise OR, and returns the result.44654466Performs a bitwise AND between the bit field specified by StartBit and EndBit4467in Operand and the value specified by AndData, followed by a bitwise4468OR with value specified by OrData. All other bits in Operand are4469preserved. The new 32-bit value is returned.44704471If 32-bit operations are not supported, then ASSERT().4472If StartBit is greater than 31, then ASSERT().4473If EndBit is greater than 31, then ASSERT().4474If EndBit is less than StartBit, then ASSERT().4475If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().4476If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().44774478@param Operand Operand on which to perform the bitfield operation.4479@param StartBit The ordinal of the least significant bit in the bit field.4480Range 0..31.4481@param EndBit The ordinal of the most significant bit in the bit field.4482Range 0..31.4483@param AndData The value to AND with the read value from the value.4484@param OrData The value to OR with the result of the AND operation.44854486@return The new 32-bit value.44874488**/4489UINT324490EFIAPI4491BitFieldAndThenOr32 (4492IN UINT32 Operand,4493IN UINTN StartBit,4494IN UINTN EndBit,4495IN UINT32 AndData,4496IN UINT32 OrData4497);44984499/**4500Returns a bit field from a 64-bit value.45014502Returns the bitfield specified by the StartBit and the EndBit from Operand.45034504If 64-bit operations are not supported, then ASSERT().4505If StartBit is greater than 63, then ASSERT().4506If EndBit is greater than 63, then ASSERT().4507If EndBit is less than StartBit, then ASSERT().45084509@param Operand Operand on which to perform the bitfield operation.4510@param StartBit The ordinal of the least significant bit in the bit field.4511Range 0..63.4512@param EndBit The ordinal of the most significant bit in the bit field.4513Range 0..63.45144515@return The bit field read.45164517**/4518UINT644519EFIAPI4520BitFieldRead64 (4521IN UINT64 Operand,4522IN UINTN StartBit,4523IN UINTN EndBit4524);45254526/**4527Writes a bit field to a 64-bit value, and returns the result.45284529Writes Value to the bit field specified by the StartBit and the EndBit in4530Operand. All other bits in Operand are preserved. The new 64-bit value is4531returned.45324533If 64-bit operations are not supported, then ASSERT().4534If StartBit is greater than 63, then ASSERT().4535If EndBit is greater than 63, then ASSERT().4536If EndBit is less than StartBit, then ASSERT().4537If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().45384539@param Operand Operand on which to perform the bitfield operation.4540@param StartBit The ordinal of the least significant bit in the bit field.4541Range 0..63.4542@param EndBit The ordinal of the most significant bit in the bit field.4543Range 0..63.4544@param Value New value of the bit field.45454546@return The new 64-bit value.45474548**/4549UINT644550EFIAPI4551BitFieldWrite64 (4552IN UINT64 Operand,4553IN UINTN StartBit,4554IN UINTN EndBit,4555IN UINT64 Value4556);45574558/**4559Reads a bit field from a 64-bit value, performs a bitwise OR, and returns the4560result.45614562Performs a bitwise OR between the bit field specified by StartBit4563and EndBit in Operand and the value specified by OrData. All other bits in4564Operand are preserved. The new 64-bit value is returned.45654566If 64-bit operations are not supported, then ASSERT().4567If StartBit is greater than 63, then ASSERT().4568If EndBit is greater than 63, then ASSERT().4569If EndBit is less than StartBit, then ASSERT().4570If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().45714572@param Operand Operand on which to perform the bitfield operation.4573@param StartBit The ordinal of the least significant bit in the bit field.4574Range 0..63.4575@param EndBit The ordinal of the most significant bit in the bit field.4576Range 0..63.4577@param OrData The value to OR with the read value from the value45784579@return The new 64-bit value.45804581**/4582UINT644583EFIAPI4584BitFieldOr64 (4585IN UINT64 Operand,4586IN UINTN StartBit,4587IN UINTN EndBit,4588IN UINT64 OrData4589);45904591/**4592Reads a bit field from a 64-bit value, performs a bitwise AND, and returns4593the result.45944595Performs a bitwise AND between the bit field specified by StartBit and EndBit4596in Operand and the value specified by AndData. All other bits in Operand are4597preserved. The new 64-bit value is returned.45984599If 64-bit operations are not supported, then ASSERT().4600If StartBit is greater than 63, then ASSERT().4601If EndBit is greater than 63, then ASSERT().4602If EndBit is less than StartBit, then ASSERT().4603If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().46044605@param Operand Operand on which to perform the bitfield operation.4606@param StartBit The ordinal of the least significant bit in the bit field.4607Range 0..63.4608@param EndBit The ordinal of the most significant bit in the bit field.4609Range 0..63.4610@param AndData The value to AND with the read value from the value46114612@return The new 64-bit value.46134614**/4615UINT644616EFIAPI4617BitFieldAnd64 (4618IN UINT64 Operand,4619IN UINTN StartBit,4620IN UINTN EndBit,4621IN UINT64 AndData4622);46234624/**4625Reads a bit field from a 64-bit value, performs a bitwise AND followed by a4626bitwise OR, and returns the result.46274628Performs a bitwise AND between the bit field specified by StartBit and EndBit4629in Operand and the value specified by AndData, followed by a bitwise4630OR with value specified by OrData. All other bits in Operand are4631preserved. The new 64-bit value is returned.46324633If 64-bit operations are not supported, then ASSERT().4634If StartBit is greater than 63, then ASSERT().4635If EndBit is greater than 63, then ASSERT().4636If EndBit is less than StartBit, then ASSERT().4637If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().4638If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().46394640@param Operand Operand on which to perform the bitfield operation.4641@param StartBit The ordinal of the least significant bit in the bit field.4642Range 0..63.4643@param EndBit The ordinal of the most significant bit in the bit field.4644Range 0..63.4645@param AndData The value to AND with the read value from the value.4646@param OrData The value to OR with the result of the AND operation.46474648@return The new 64-bit value.46494650**/4651UINT644652EFIAPI4653BitFieldAndThenOr64 (4654IN UINT64 Operand,4655IN UINTN StartBit,4656IN UINTN EndBit,4657IN UINT64 AndData,4658IN UINT64 OrData4659);46604661/**4662Reads a bit field from a 32-bit value, counts and returns4663the number of set bits.46644665Counts the number of set bits in the bit field specified by4666StartBit and EndBit in Operand. The count is returned.46674668If StartBit is greater than 31, then ASSERT().4669If EndBit is greater than 31, then ASSERT().4670If EndBit is less than StartBit, then ASSERT().46714672@param Operand Operand on which to perform the bitfield operation.4673@param StartBit The ordinal of the least significant bit in the bit field.4674Range 0..31.4675@param EndBit The ordinal of the most significant bit in the bit field.4676Range 0..31.46774678@return The number of bits set between StartBit and EndBit.46794680**/4681UINT84682EFIAPI4683BitFieldCountOnes32 (4684IN UINT32 Operand,4685IN UINTN StartBit,4686IN UINTN EndBit4687);46884689/**4690Reads a bit field from a 64-bit value, counts and returns4691the number of set bits.46924693Counts the number of set bits in the bit field specified by4694StartBit and EndBit in Operand. The count is returned.46954696If StartBit is greater than 63, then ASSERT().4697If EndBit is greater than 63, then ASSERT().4698If EndBit is less than StartBit, then ASSERT().46994700@param Operand Operand on which to perform the bitfield operation.4701@param StartBit The ordinal of the least significant bit in the bit field.4702Range 0..63.4703@param EndBit The ordinal of the most significant bit in the bit field.4704Range 0..63.47054706@return The number of bits set between StartBit and EndBit.47074708**/4709UINT84710EFIAPI4711BitFieldCountOnes64 (4712IN UINT64 Operand,4713IN UINTN StartBit,4714IN UINTN EndBit4715);47164717//4718// Base Library Checksum Functions4719//47204721/**4722Returns the sum of all elements in a buffer in unit of UINT8.4723During calculation, the carry bits are dropped.47244725This function calculates the sum of all elements in a buffer4726in unit of UINT8. The carry bits in result of addition are dropped.4727The result is returned as UINT8. If Length is Zero, then Zero is4728returned.47294730If Buffer is NULL, then ASSERT().4731If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().47324733@param Buffer The pointer to the buffer to carry out the sum operation.4734@param Length The size, in bytes, of Buffer.47354736@return Sum The sum of Buffer with carry bits dropped during additions.47374738**/4739UINT84740EFIAPI4741CalculateSum8 (4742IN CONST UINT8 *Buffer,4743IN UINTN Length4744);47454746/**4747Returns the two's complement checksum of all elements in a buffer4748of 8-bit values.47494750This function first calculates the sum of the 8-bit values in the4751buffer specified by Buffer and Length. The carry bits in the result4752of addition are dropped. Then, the two's complement of the sum is4753returned. If Length is 0, then 0 is returned.47544755If Buffer is NULL, then ASSERT().4756If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().47574758@param Buffer The pointer to the buffer to carry out the checksum operation.4759@param Length The size, in bytes, of Buffer.47604761@return Checksum The two's complement checksum of Buffer.47624763**/4764UINT84765EFIAPI4766CalculateCheckSum8 (4767IN CONST UINT8 *Buffer,4768IN UINTN Length4769);47704771/**4772Returns the sum of all elements in a buffer of 16-bit values. During4773calculation, the carry bits are dropped.47744775This function calculates the sum of the 16-bit values in the buffer4776specified by Buffer and Length. The carry bits in result of addition are dropped.4777The 16-bit result is returned. If Length is 0, then 0 is returned.47784779If Buffer is NULL, then ASSERT().4780If Buffer is not aligned on a 16-bit boundary, then ASSERT().4781If Length is not aligned on a 16-bit boundary, then ASSERT().4782If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().47834784@param Buffer The pointer to the buffer to carry out the sum operation.4785@param Length The size, in bytes, of Buffer.47864787@return Sum The sum of Buffer with carry bits dropped during additions.47884789**/4790UINT164791EFIAPI4792CalculateSum16 (4793IN CONST UINT16 *Buffer,4794IN UINTN Length4795);47964797/**4798Returns the two's complement checksum of all elements in a buffer of479916-bit values.48004801This function first calculates the sum of the 16-bit values in the buffer4802specified by Buffer and Length. The carry bits in the result of addition4803are dropped. Then, the two's complement of the sum is returned. If Length4804is 0, then 0 is returned.48054806If Buffer is NULL, then ASSERT().4807If Buffer is not aligned on a 16-bit boundary, then ASSERT().4808If Length is not aligned on a 16-bit boundary, then ASSERT().4809If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().48104811@param Buffer The pointer to the buffer to carry out the checksum operation.4812@param Length The size, in bytes, of Buffer.48134814@return Checksum The two's complement checksum of Buffer.48154816**/4817UINT164818EFIAPI4819CalculateCheckSum16 (4820IN CONST UINT16 *Buffer,4821IN UINTN Length4822);48234824/**4825Returns the sum of all elements in a buffer of 32-bit values. During4826calculation, the carry bits are dropped.48274828This function calculates the sum of the 32-bit values in the buffer4829specified by Buffer and Length. The carry bits in result of addition are dropped.4830The 32-bit result is returned. If Length is 0, then 0 is returned.48314832If Buffer is NULL, then ASSERT().4833If Buffer is not aligned on a 32-bit boundary, then ASSERT().4834If Length is not aligned on a 32-bit boundary, then ASSERT().4835If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().48364837@param Buffer The pointer to the buffer to carry out the sum operation.4838@param Length The size, in bytes, of Buffer.48394840@return Sum The sum of Buffer with carry bits dropped during additions.48414842**/4843UINT324844EFIAPI4845CalculateSum32 (4846IN CONST UINT32 *Buffer,4847IN UINTN Length4848);48494850/**4851Returns the two's complement checksum of all elements in a buffer of485232-bit values.48534854This function first calculates the sum of the 32-bit values in the buffer4855specified by Buffer and Length. The carry bits in the result of addition4856are dropped. Then, the two's complement of the sum is returned. If Length4857is 0, then 0 is returned.48584859If Buffer is NULL, then ASSERT().4860If Buffer is not aligned on a 32-bit boundary, then ASSERT().4861If Length is not aligned on a 32-bit boundary, then ASSERT().4862If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().48634864@param Buffer The pointer to the buffer to carry out the checksum operation.4865@param Length The size, in bytes, of Buffer.48664867@return Checksum The two's complement checksum of Buffer.48684869**/4870UINT324871EFIAPI4872CalculateCheckSum32 (4873IN CONST UINT32 *Buffer,4874IN UINTN Length4875);48764877/**4878Returns the sum of all elements in a buffer of 64-bit values. During4879calculation, the carry bits are dropped.48804881This function calculates the sum of the 64-bit values in the buffer4882specified by Buffer and Length. The carry bits in result of addition are dropped.4883The 64-bit result is returned. If Length is 0, then 0 is returned.48844885If Buffer is NULL, then ASSERT().4886If Buffer is not aligned on a 64-bit boundary, then ASSERT().4887If Length is not aligned on a 64-bit boundary, then ASSERT().4888If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().48894890@param Buffer The pointer to the buffer to carry out the sum operation.4891@param Length The size, in bytes, of Buffer.48924893@return Sum The sum of Buffer with carry bits dropped during additions.48944895**/4896UINT644897EFIAPI4898CalculateSum64 (4899IN CONST UINT64 *Buffer,4900IN UINTN Length4901);49024903/**4904Returns the two's complement checksum of all elements in a buffer of490564-bit values.49064907This function first calculates the sum of the 64-bit values in the buffer4908specified by Buffer and Length. The carry bits in the result of addition4909are dropped. Then, the two's complement of the sum is returned. If Length4910is 0, then 0 is returned.49114912If Buffer is NULL, then ASSERT().4913If Buffer is not aligned on a 64-bit boundary, then ASSERT().4914If Length is not aligned on a 64-bit boundary, then ASSERT().4915If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().49164917@param Buffer The pointer to the buffer to carry out the checksum operation.4918@param Length The size, in bytes, of Buffer.49194920@return Checksum The two's complement checksum of Buffer.49214922**/4923UINT644924EFIAPI4925CalculateCheckSum64 (4926IN CONST UINT64 *Buffer,4927IN UINTN Length4928);49294930/**4931Computes and returns a 32-bit CRC for a data buffer.4932CRC32 value bases on ITU-T V.42.49334934If Buffer is NULL, then ASSERT().4935If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().49364937@param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed.4938@param[in] Length The number of bytes in the buffer Data.49394940@retval Crc32 The 32-bit CRC was computed for the data buffer.49414942**/4943UINT324944EFIAPI4945CalculateCrc32 (4946IN VOID *Buffer,4947IN UINTN Length4948);49494950/**4951Calculates the CRC16-ANSI checksum of the given buffer.49524953@param[in] Buffer Pointer to the buffer.4954@param[in] Length Length of the buffer, in bytes.4955@param[in] InitialValue Initial value of the CRC.49564957@return The CRC16-ANSI checksum.4958**/4959UINT164960EFIAPI4961CalculateCrc16Ansi (4962IN CONST VOID *Buffer,4963IN UINTN Length,4964IN UINT16 InitialValue4965);49664967//4968// Initial value for the CRC16-ANSI algorithm, when no prior checksum has been calculated.4969//4970#define CRC16ANSI_INIT 0xffff49714972/**4973Calculates the CRC32c checksum of the given buffer.49744975@param[in] Buffer Pointer to the buffer.4976@param[in] Length Length of the buffer, in bytes.4977@param[in] InitialValue Initial value of the CRC.49784979@return The CRC32c checksum.4980**/4981UINT324982EFIAPI4983CalculateCrc32c (4984IN CONST VOID *Buffer,4985IN UINTN Length,4986IN UINT32 InitialValue4987);49884989/**4990Calculates the CRC16-CCITT-FALSE checksum of the given buffer.49914992@param[in] Buffer Pointer to the buffer.4993@param[in] Length Length of the buffer, in bytes.4994@param[in] InitialValue Initial value of the CRC.49954996@return The CRC16-CCITT-FALSE checksum.4997**/4998UINT164999EFIAPI5000CalculateCrc16CcittF (5001IN CONST VOID *Buffer,5002IN UINTN Length,5003IN UINT16 InitialValue5004);50055006//5007// Base Library CPU Functions5008//50095010/**5011Function entry point used when a stack switch is requested with SwitchStack()50125013@param Context1 Context1 parameter passed into SwitchStack().5014@param Context2 Context2 parameter passed into SwitchStack().5015**/5016typedef5017VOID5018(EFIAPI *SWITCH_STACK_ENTRY_POINT)(5019IN VOID *Context1 OPTIONAL,5020IN VOID *Context2 OPTIONAL5021);50225023/**5024Used to serialize load and store operations.50255026All loads and stores that proceed calls to this function are guaranteed to be5027globally visible when this function returns.50285029**/5030VOID5031EFIAPI5032MemoryFence (5033VOID5034);50355036/**5037Saves the current CPU context that can be restored with a call to LongJump()5038and returns 0.50395040Saves the current CPU context in the buffer specified by JumpBuffer and5041returns 0. The initial call to SetJump() must always return 0. Subsequent5042calls to LongJump() cause a non-zero value to be returned by SetJump().50435044If JumpBuffer is NULL, then ASSERT().5045For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().50465047NOTE: The structure BASE_LIBRARY_JUMP_BUFFER is CPU architecture specific.5048The same structure must never be used for more than one CPU architecture context.5049For example, a BASE_LIBRARY_JUMP_BUFFER allocated by an IA-32 module must never be used from an x64 module.5050SetJump()/LongJump() is not currently supported for the EBC processor type.50515052@param JumpBuffer A pointer to CPU context buffer.50535054@retval 0 Indicates a return from SetJump().50555056**/5057RETURNS_TWICE5058UINTN5059EFIAPI5060SetJump (5061OUT BASE_LIBRARY_JUMP_BUFFER *JumpBuffer5062);50635064/**5065Restores the CPU context that was saved with SetJump().50665067Restores the CPU context from the buffer specified by JumpBuffer. This5068function never returns to the caller. Instead is resumes execution based on5069the state of JumpBuffer.50705071If JumpBuffer is NULL, then ASSERT().5072For Itanium processors, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().5073If Value is 0, then ASSERT().50745075@param JumpBuffer A pointer to CPU context buffer.5076@param Value The value to return when the SetJump() context is5077restored and must be non-zero.50785079**/5080VOID5081EFIAPI5082LongJump (5083IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,5084IN UINTN Value5085);50865087/**5088Enables CPU interrupts.50895090**/5091VOID5092EFIAPI5093EnableInterrupts (5094VOID5095);50965097/**5098Disables CPU interrupts.50995100**/5101VOID5102EFIAPI5103DisableInterrupts (5104VOID5105);51065107/**5108Disables CPU interrupts and returns the interrupt state prior to the disable5109operation.51105111@retval TRUE CPU interrupts were enabled on entry to this call.5112@retval FALSE CPU interrupts were disabled on entry to this call.51135114**/5115BOOLEAN5116EFIAPI5117SaveAndDisableInterrupts (5118VOID5119);51205121/**5122Enables CPU interrupts for the smallest window required to capture any5123pending interrupts.51245125**/5126VOID5127EFIAPI5128EnableDisableInterrupts (5129VOID5130);51315132/**5133Retrieves the current CPU interrupt state.51345135Returns TRUE if interrupts are currently enabled. Otherwise5136returns FALSE.51375138@retval TRUE CPU interrupts are enabled.5139@retval FALSE CPU interrupts are disabled.51405141**/5142BOOLEAN5143EFIAPI5144GetInterruptState (5145VOID5146);51475148/**5149Set the current CPU interrupt state.51505151Sets the current CPU interrupt state to the state specified by5152InterruptState. If InterruptState is TRUE, then interrupts are enabled. If5153InterruptState is FALSE, then interrupts are disabled. InterruptState is5154returned.51555156@param InterruptState TRUE if interrupts should enabled. FALSE if5157interrupts should be disabled.51585159@return InterruptState51605161**/5162BOOLEAN5163EFIAPI5164SetInterruptState (5165IN BOOLEAN InterruptState5166);51675168/**5169Requests CPU to pause for a short period of time.51705171Requests CPU to pause for a short period of time. Typically used in MP5172systems to prevent memory starvation while waiting for a spin lock.51735174**/5175VOID5176EFIAPI5177CpuPause (5178VOID5179);51805181/**5182Transfers control to a function starting with a new stack.51835184Transfers control to the function specified by EntryPoint using the5185new stack specified by NewStack and passing in the parameters specified5186by Context1 and Context2. Context1 and Context2 are optional and may5187be NULL. The function EntryPoint must never return. This function5188supports a variable number of arguments following the NewStack parameter.5189These additional arguments are ignored on IA-32, x64, and EBC architectures.5190Itanium processors expect one additional parameter of type VOID * that specifies5191the new backing store pointer.51925193If EntryPoint is NULL, then ASSERT().5194If NewStack is NULL, then ASSERT().51955196@param EntryPoint A pointer to function to call with the new stack.5197@param Context1 A pointer to the context to pass into the EntryPoint5198function.5199@param Context2 A pointer to the context to pass into the EntryPoint5200function.5201@param NewStack A pointer to the new stack to use for the EntryPoint5202function.5203@param ... This variable argument list is ignored for IA-32, x64, and5204EBC architectures. For Itanium processors, this variable5205argument list is expected to contain a single parameter of5206type VOID * that specifies the new backing store pointer.520752085209**/5210VOID5211EFIAPI5212SwitchStack (5213IN SWITCH_STACK_ENTRY_POINT EntryPoint,5214IN VOID *Context1 OPTIONAL,5215IN VOID *Context2 OPTIONAL,5216IN VOID *NewStack,5217...5218);52195220/**5221Generates a breakpoint on the CPU.52225223Generates a breakpoint on the CPU. The breakpoint must be implemented such5224that code can resume normal execution after the breakpoint.52255226**/5227VOID5228EFIAPI5229CpuBreakpoint (5230VOID5231);52325233/**5234Executes an infinite loop.52355236Forces the CPU to execute an infinite loop. A debugger may be used to skip5237past the loop and the code that follows the loop must execute properly. This5238implies that the infinite loop must not cause the code that follow it to be5239optimized away.52405241**/5242VOID5243EFIAPI5244CpuDeadLoop (5245VOID5246);52475248/**5249Uses as a barrier to stop speculative execution.52505251Ensures that no later instruction will execute speculatively, until all prior5252instructions have completed.52535254**/5255VOID5256EFIAPI5257SpeculationBarrier (5258VOID5259);52605261/**5262The TDCALL instruction causes a VM exit to the Intel TDX module. It is5263used to call guest-side Intel TDX functions, either local or a TD exit5264to the host VMM, as selected by Leaf.52655266@param[in] Leaf Leaf number of TDCALL instruction5267@param[in] Arg1 Arg15268@param[in] Arg2 Arg25269@param[in] Arg3 Arg35270@param[in,out] Results Returned result of the Leaf function52715272@return 0 A successful call5273@return Other See individual leaf functions5274**/5275UINTN5276EFIAPI5277TdCall (5278IN UINT64 Leaf,5279IN UINT64 Arg1,5280IN UINT64 Arg2,5281IN UINT64 Arg3,5282IN OUT VOID *Results5283);52845285/**5286TDVMALL is a leaf function 0 for TDCALL. It helps invoke services from the5287host VMM to pass/receive information.52885289@param[in] Leaf Number of sub-functions5290@param[in] Arg1 Arg15291@param[in] Arg2 Arg25292@param[in] Arg3 Arg35293@param[in] Arg4 Arg45294@param[in,out] Results Returned result of the sub-function52955296@return 0 A successful call5297@return Other See individual sub-functions52985299**/5300UINTN5301EFIAPI5302TdVmCall (5303IN UINT64 Leaf,5304IN UINT64 Arg1,5305IN UINT64 Arg2,5306IN UINT64 Arg3,5307IN UINT64 Arg4,5308IN OUT VOID *Results5309);53105311/**5312Probe if TD is enabled.53135314@return TRUE TD is enabled.5315@return FALSE TD is not enabled.5316**/5317BOOLEAN5318EFIAPI5319TdIsEnabled (5320VOID5321);53225323#if defined (MDE_CPU_X64)5324//5325// The page size for the PVALIDATE instruction5326//5327typedef enum {5328PvalidatePageSize4K = 0,5329PvalidatePageSize2MB,5330} PVALIDATE_PAGE_SIZE;53315332//5333// PVALIDATE Return Code.5334//5335#define PVALIDATE_RET_SUCCESS 05336#define PVALIDATE_RET_FAIL_INPUT 15337#define PVALIDATE_RET_SIZE_MISMATCH 653385339//5340// The PVALIDATE instruction did not make any changes to the RMP entry.5341//5342#define PVALIDATE_RET_NO_RMPUPDATE 25553435344/**5345Execute a PVALIDATE instruction to validate or to rescinds validation of a guest5346page's RMP entry.53475348The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=1.53495350The function is available on X64.53515352@param[in] PageSize The page size to use.5353@param[in] Validate If TRUE, validate the guest virtual address5354otherwise invalidate the guest virtual address.5355@param[in] Address The guest virtual address.53565357@retval PVALIDATE_RET_SUCCESS The PVALIDATE instruction succeeded, and5358updated the RMP entry.5359@retval PVALIDATE_RET_NO_RMPUPDATE The PVALIDATE instruction succeeded, but5360did not update the RMP entry.5361@return Failure code from the PVALIDATE5362instruction.5363**/5364UINT325365EFIAPI5366AsmPvalidate (5367IN PVALIDATE_PAGE_SIZE PageSize,5368IN BOOLEAN Validate,5369IN PHYSICAL_ADDRESS Address5370);53715372//5373// RDX settings for RMPADJUST5374//5375#define RMPADJUST_VMPL_MAX 35376#define RMPADJUST_VMPL_MASK 0xFF5377#define RMPADJUST_VMPL_SHIFT 05378#define RMPADJUST_PERMISSION_MASK_MASK 0xFF5379#define RMPADJUST_PERMISSION_MASK_SHIFT 85380#define RMPADJUST_VMSA_PAGE_BIT BIT1653815382/**5383Adjusts the permissions of an SEV-SNP guest page.53845385Executes a RMPADJUST instruction with the register state specified by Rax,5386Rcx, and Rdx. Returns Eax. This function is only available on X64.53875388The instruction is available only when CPUID Fn8000_001F_EAX[SNP]=1.53895390@param[in] Rax The value to load into RAX before executing the RMPADJUST5391instruction.5392@param[in] Rcx The value to load into RCX before executing the RMPADJUST5393instruction.5394@param[in] Rdx The value to load into RDX before executing the RMPADJUST5395instruction.53965397@return Eax5398**/5399UINT325400EFIAPI5401AsmRmpAdjust (5402IN UINT64 Rax,5403IN UINT64 Rcx,5404IN UINT64 Rdx5405);54065407#endif54085409#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)5410///5411/// IA32 and x64 Specific Functions.5412/// Byte packed structure for 16-bit Real Mode EFLAGS.5413///5414typedef union {5415struct {5416UINT32 CF : 1; ///< Carry Flag.5417UINT32 Reserved_0 : 1; ///< Reserved.5418UINT32 PF : 1; ///< Parity Flag.5419UINT32 Reserved_1 : 1; ///< Reserved.5420UINT32 AF : 1; ///< Auxiliary Carry Flag.5421UINT32 Reserved_2 : 1; ///< Reserved.5422UINT32 ZF : 1; ///< Zero Flag.5423UINT32 SF : 1; ///< Sign Flag.5424UINT32 TF : 1; ///< Trap Flag.5425UINT32 IF : 1; ///< Interrupt Enable Flag.5426UINT32 DF : 1; ///< Direction Flag.5427UINT32 OF : 1; ///< Overflow Flag.5428UINT32 IOPL : 2; ///< I/O Privilege Level.5429UINT32 NT : 1; ///< Nested Task.5430UINT32 Reserved_3 : 1; ///< Reserved.5431} Bits;5432UINT16 Uint16;5433} IA32_FLAGS16;54345435///5436/// Byte packed structure for EFLAGS/RFLAGS.5437/// 32-bits on IA-32.5438/// 64-bits on x64. The upper 32-bits on x64 are reserved.5439///5440typedef union {5441struct {5442UINT32 CF : 1; ///< Carry Flag.5443UINT32 Reserved_0 : 1; ///< Reserved.5444UINT32 PF : 1; ///< Parity Flag.5445UINT32 Reserved_1 : 1; ///< Reserved.5446UINT32 AF : 1; ///< Auxiliary Carry Flag.5447UINT32 Reserved_2 : 1; ///< Reserved.5448UINT32 ZF : 1; ///< Zero Flag.5449UINT32 SF : 1; ///< Sign Flag.5450UINT32 TF : 1; ///< Trap Flag.5451UINT32 IF : 1; ///< Interrupt Enable Flag.5452UINT32 DF : 1; ///< Direction Flag.5453UINT32 OF : 1; ///< Overflow Flag.5454UINT32 IOPL : 2; ///< I/O Privilege Level.5455UINT32 NT : 1; ///< Nested Task.5456UINT32 Reserved_3 : 1; ///< Reserved.5457UINT32 RF : 1; ///< Resume Flag.5458UINT32 VM : 1; ///< Virtual 8086 Mode.5459UINT32 AC : 1; ///< Alignment Check.5460UINT32 VIF : 1; ///< Virtual Interrupt Flag.5461UINT32 VIP : 1; ///< Virtual Interrupt Pending.5462UINT32 ID : 1; ///< ID Flag.5463UINT32 Reserved_4 : 10; ///< Reserved.5464} Bits;5465UINTN UintN;5466} IA32_EFLAGS32;54675468///5469/// Byte packed structure for Control Register 0 (CR0).5470/// 32-bits on IA-32.5471/// 64-bits on x64. The upper 32-bits on x64 are reserved.5472///5473typedef union {5474struct {5475UINT32 PE : 1; ///< Protection Enable.5476UINT32 MP : 1; ///< Monitor Coprocessor.5477UINT32 EM : 1; ///< Emulation.5478UINT32 TS : 1; ///< Task Switched.5479UINT32 ET : 1; ///< Extension Type.5480UINT32 NE : 1; ///< Numeric Error.5481UINT32 Reserved_0 : 10; ///< Reserved.5482UINT32 WP : 1; ///< Write Protect.5483UINT32 Reserved_1 : 1; ///< Reserved.5484UINT32 AM : 1; ///< Alignment Mask.5485UINT32 Reserved_2 : 10; ///< Reserved.5486UINT32 NW : 1; ///< Mot Write-through.5487UINT32 CD : 1; ///< Cache Disable.5488UINT32 PG : 1; ///< Paging.5489} Bits;5490UINTN UintN;5491} IA32_CR0;54925493///5494/// Byte packed structure for Control Register 4 (CR4).5495/// 32-bits on IA-32.5496/// 64-bits on x64. The upper 32-bits on x64 are reserved.5497///5498typedef union {5499struct {5500UINT32 VME : 1; ///< Virtual-8086 Mode Extensions.5501UINT32 PVI : 1; ///< Protected-Mode Virtual Interrupts.5502UINT32 TSD : 1; ///< Time Stamp Disable.5503UINT32 DE : 1; ///< Debugging Extensions.5504UINT32 PSE : 1; ///< Page Size Extensions.5505UINT32 PAE : 1; ///< Physical Address Extension.5506UINT32 MCE : 1; ///< Machine Check Enable.5507UINT32 PGE : 1; ///< Page Global Enable.5508UINT32 PCE : 1; ///< Performance Monitoring Counter5509///< Enable.5510UINT32 OSFXSR : 1; ///< Operating System Support for5511///< FXSAVE and FXRSTOR instructions5512UINT32 OSXMMEXCPT : 1; ///< Operating System Support for5513///< Unmasked SIMD Floating Point5514///< Exceptions.5515UINT32 UMIP : 1; ///< User-Mode Instruction Prevention.5516UINT32 LA57 : 1; ///< Linear Address 57bit.5517UINT32 VMXE : 1; ///< VMX Enable.5518UINT32 SMXE : 1; ///< SMX Enable.5519UINT32 Reserved_3 : 1; ///< Reserved.5520UINT32 FSGSBASE : 1; ///< FSGSBASE Enable.5521UINT32 PCIDE : 1; ///< PCID Enable.5522UINT32 OSXSAVE : 1; ///< XSAVE and Processor Extended States Enable.5523UINT32 Reserved_4 : 1; ///< Reserved.5524UINT32 SMEP : 1; ///< SMEP Enable.5525UINT32 SMAP : 1; ///< SMAP Enable.5526UINT32 PKE : 1; ///< Protection-Key Enable.5527UINT32 Reserved_5 : 9; ///< Reserved.5528} Bits;5529UINTN UintN;5530} IA32_CR4;55315532///5533/// Byte packed structure for a segment descriptor in a GDT/LDT.5534///5535typedef union {5536struct {5537UINT32 LimitLow : 16;5538UINT32 BaseLow : 16;5539UINT32 BaseMid : 8;5540UINT32 Type : 4;5541UINT32 S : 1;5542UINT32 DPL : 2;5543UINT32 P : 1;5544UINT32 LimitHigh : 4;5545UINT32 AVL : 1;5546UINT32 L : 1;5547UINT32 DB : 1;5548UINT32 G : 1;5549UINT32 BaseHigh : 8;5550} Bits;5551UINT64 Uint64;5552} IA32_SEGMENT_DESCRIPTOR;55535554///5555/// Byte packed structure for an IDTR, GDTR, LDTR descriptor.5556///5557#pragma pack (1)5558typedef struct {5559UINT16 Limit;5560UINTN Base;5561} IA32_DESCRIPTOR;5562#pragma pack ()55635564#define IA32_IDT_GATE_TYPE_TASK 0x855565#define IA32_IDT_GATE_TYPE_INTERRUPT_16 0x865566#define IA32_IDT_GATE_TYPE_TRAP_16 0x875567#define IA32_IDT_GATE_TYPE_INTERRUPT_32 0x8E5568#define IA32_IDT_GATE_TYPE_TRAP_32 0x8F55695570#define IA32_GDT_TYPE_TSS 0x95571#define IA32_GDT_ALIGNMENT 855725573#if defined (MDE_CPU_IA32)5574///5575/// Byte packed structure for an IA-32 Interrupt Gate Descriptor.5576///5577typedef union {5578struct {5579UINT32 OffsetLow : 16; ///< Offset bits 15..0.5580UINT32 Selector : 16; ///< Selector.5581UINT32 Reserved_0 : 8; ///< Reserved.5582UINT32 GateType : 8; ///< Gate Type. See #defines above.5583UINT32 OffsetHigh : 16; ///< Offset bits 31..16.5584} Bits;5585UINT64 Uint64;5586} IA32_IDT_GATE_DESCRIPTOR;55875588#pragma pack (1)5589//5590// IA32 Task-State Segment Definition5591//5592typedef struct {5593UINT16 PreviousTaskLink;5594UINT16 Reserved_2;5595UINT32 ESP0;5596UINT16 SS0;5597UINT16 Reserved_10;5598UINT32 ESP1;5599UINT16 SS1;5600UINT16 Reserved_18;5601UINT32 ESP2;5602UINT16 SS2;5603UINT16 Reserved_26;5604UINT32 CR3;5605UINT32 EIP;5606UINT32 EFLAGS;5607UINT32 EAX;5608UINT32 ECX;5609UINT32 EDX;5610UINT32 EBX;5611UINT32 ESP;5612UINT32 EBP;5613UINT32 ESI;5614UINT32 EDI;5615UINT16 ES;5616UINT16 Reserved_74;5617UINT16 CS;5618UINT16 Reserved_78;5619UINT16 SS;5620UINT16 Reserved_82;5621UINT16 DS;5622UINT16 Reserved_86;5623UINT16 FS;5624UINT16 Reserved_90;5625UINT16 GS;5626UINT16 Reserved_94;5627UINT16 LDTSegmentSelector;5628UINT16 Reserved_98;5629UINT16 T;5630UINT16 IOMapBaseAddress;5631} IA32_TASK_STATE_SEGMENT;56325633typedef union {5634struct {5635UINT32 LimitLow : 16; ///< Segment Limit 15..005636UINT32 BaseLow : 16; ///< Base Address 15..005637UINT32 BaseMid : 8; ///< Base Address 23..165638UINT32 Type : 4; ///< Type (1 0 B 1)5639UINT32 Reserved_43 : 1; ///< 05640UINT32 DPL : 2; ///< Descriptor Privilege Level5641UINT32 P : 1; ///< Segment Present5642UINT32 LimitHigh : 4; ///< Segment Limit 19..165643UINT32 AVL : 1; ///< Available for use by system software5644UINT32 Reserved_52 : 2; ///< 0 05645UINT32 G : 1; ///< Granularity5646UINT32 BaseHigh : 8; ///< Base Address 31..245647} Bits;5648UINT64 Uint64;5649} IA32_TSS_DESCRIPTOR;5650#pragma pack ()56515652#endif // defined (MDE_CPU_IA32)56535654#if defined (MDE_CPU_X64)5655///5656/// Byte packed structure for an x64 Interrupt Gate Descriptor.5657///5658typedef union {5659struct {5660UINT32 OffsetLow : 16; ///< Offset bits 15..0.5661UINT32 Selector : 16; ///< Selector.5662UINT32 Reserved_0 : 8; ///< Reserved.5663UINT32 GateType : 8; ///< Gate Type. See #defines above.5664UINT32 OffsetHigh : 16; ///< Offset bits 31..16.5665UINT32 OffsetUpper : 32; ///< Offset bits 63..32.5666UINT32 Reserved_1 : 32; ///< Reserved.5667} Bits;5668struct {5669UINT64 Uint64;5670UINT64 Uint64_1;5671} Uint128;5672} IA32_IDT_GATE_DESCRIPTOR;56735674#pragma pack (1)5675//5676// IA32 Task-State Segment Definition5677//5678typedef struct {5679UINT32 Reserved_0;5680UINT64 RSP0;5681UINT64 RSP1;5682UINT64 RSP2;5683UINT64 Reserved_28;5684UINT64 IST[7];5685UINT64 Reserved_92;5686UINT16 Reserved_100;5687UINT16 IOMapBaseAddress;5688} IA32_TASK_STATE_SEGMENT;56895690typedef union {5691struct {5692UINT32 LimitLow : 16; ///< Segment Limit 15..005693UINT32 BaseLow : 16; ///< Base Address 15..005694UINT32 BaseMidl : 8; ///< Base Address 23..165695UINT32 Type : 4; ///< Type (1 0 B 1)5696UINT32 Reserved_43 : 1; ///< 05697UINT32 DPL : 2; ///< Descriptor Privilege Level5698UINT32 P : 1; ///< Segment Present5699UINT32 LimitHigh : 4; ///< Segment Limit 19..165700UINT32 AVL : 1; ///< Available for use by system software5701UINT32 Reserved_52 : 2; ///< 0 05702UINT32 G : 1; ///< Granularity5703UINT32 BaseMidh : 8; ///< Base Address 31..245704UINT32 BaseHigh : 32; ///< Base Address 63..325705UINT32 Reserved_96 : 32; ///< Reserved5706} Bits;5707struct {5708UINT64 Uint64;5709UINT64 Uint64_1;5710} Uint128;5711} IA32_TSS_DESCRIPTOR;5712#pragma pack ()57135714#endif // defined (MDE_CPU_X64)57155716///5717/// Byte packed structure for an FP/SSE/SSE2 context.5718///5719typedef struct {5720UINT8 Buffer[512];5721} IA32_FX_BUFFER;57225723///5724/// Structures for the 16-bit real mode thunks.5725///5726typedef struct {5727UINT32 Reserved1;5728UINT32 Reserved2;5729UINT32 Reserved3;5730UINT32 Reserved4;5731UINT8 BL;5732UINT8 BH;5733UINT16 Reserved5;5734UINT8 DL;5735UINT8 DH;5736UINT16 Reserved6;5737UINT8 CL;5738UINT8 CH;5739UINT16 Reserved7;5740UINT8 AL;5741UINT8 AH;5742UINT16 Reserved8;5743} IA32_BYTE_REGS;57445745typedef struct {5746UINT16 DI;5747UINT16 Reserved1;5748UINT16 SI;5749UINT16 Reserved2;5750UINT16 BP;5751UINT16 Reserved3;5752UINT16 SP;5753UINT16 Reserved4;5754UINT16 BX;5755UINT16 Reserved5;5756UINT16 DX;5757UINT16 Reserved6;5758UINT16 CX;5759UINT16 Reserved7;5760UINT16 AX;5761UINT16 Reserved8;5762} IA32_WORD_REGS;57635764typedef struct {5765UINT32 EDI;5766UINT32 ESI;5767UINT32 EBP;5768UINT32 ESP;5769UINT32 EBX;5770UINT32 EDX;5771UINT32 ECX;5772UINT32 EAX;5773UINT16 DS;5774UINT16 ES;5775UINT16 FS;5776UINT16 GS;5777IA32_EFLAGS32 EFLAGS;5778UINT32 Eip;5779UINT16 CS;5780UINT16 SS;5781} IA32_DWORD_REGS;57825783typedef union {5784IA32_DWORD_REGS E;5785IA32_WORD_REGS X;5786IA32_BYTE_REGS H;5787} IA32_REGISTER_SET;57885789///5790/// Byte packed structure for an 16-bit real mode thunks.5791///5792typedef struct {5793IA32_REGISTER_SET *RealModeState;5794VOID *RealModeBuffer;5795UINT32 RealModeBufferSize;5796UINT32 ThunkAttributes;5797} THUNK_CONTEXT;57985799#define THUNK_ATTRIBUTE_BIG_REAL_MODE 0x000000015800#define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x000000025801#define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x0000000458025803///5804/// Type definition for representing labels in NASM source code that allow for5805/// the patching of immediate operands of IA32 and X64 instructions.5806///5807/// While the type is technically defined as a function type (note: not a5808/// pointer-to-function type), such labels in NASM source code never stand for5809/// actual functions, and identifiers declared with this function type should5810/// never be called. This is also why the EFIAPI calling convention specifier5811/// is missing from the typedef, and why the typedef does not follow the usual5812/// edk2 coding style for function (or pointer-to-function) typedefs. The VOID5813/// return type and the VOID argument list are merely artifacts.5814///5815typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (5816VOID5817);58185819/**5820Retrieves CPUID information.58215822Executes the CPUID instruction with EAX set to the value specified by Index.5823This function always returns Index.5824If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.5825If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.5826If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.5827If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.5828This function is only available on IA-32 and x64.58295830@param Index The 32-bit value to load into EAX prior to invoking the CPUID5831instruction.5832@param Eax The pointer to the 32-bit EAX value returned by the CPUID5833instruction. This is an optional parameter that may be NULL.5834@param Ebx The pointer to the 32-bit EBX value returned by the CPUID5835instruction. This is an optional parameter that may be NULL.5836@param Ecx The pointer to the 32-bit ECX value returned by the CPUID5837instruction. This is an optional parameter that may be NULL.5838@param Edx The pointer to the 32-bit EDX value returned by the CPUID5839instruction. This is an optional parameter that may be NULL.58405841@return Index.58425843**/5844UINT325845EFIAPI5846AsmCpuid (5847IN UINT32 Index,5848OUT UINT32 *Eax OPTIONAL,5849OUT UINT32 *Ebx OPTIONAL,5850OUT UINT32 *Ecx OPTIONAL,5851OUT UINT32 *Edx OPTIONAL5852);58535854/**5855Retrieves CPUID information using an extended leaf identifier.58565857Executes the CPUID instruction with EAX set to the value specified by Index5858and ECX set to the value specified by SubIndex. This function always returns5859Index. This function is only available on IA-32 and x64.58605861If Eax is not NULL, then the value of EAX after CPUID is returned in Eax.5862If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx.5863If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx.5864If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.58655866@param Index The 32-bit value to load into EAX prior to invoking the5867CPUID instruction.5868@param SubIndex The 32-bit value to load into ECX prior to invoking the5869CPUID instruction.5870@param Eax The pointer to the 32-bit EAX value returned by the CPUID5871instruction. This is an optional parameter that may be5872NULL.5873@param Ebx The pointer to the 32-bit EBX value returned by the CPUID5874instruction. This is an optional parameter that may be5875NULL.5876@param Ecx The pointer to the 32-bit ECX value returned by the CPUID5877instruction. This is an optional parameter that may be5878NULL.5879@param Edx The pointer to the 32-bit EDX value returned by the CPUID5880instruction. This is an optional parameter that may be5881NULL.58825883@return Index.58845885**/5886UINT325887EFIAPI5888AsmCpuidEx (5889IN UINT32 Index,5890IN UINT32 SubIndex,5891OUT UINT32 *Eax OPTIONAL,5892OUT UINT32 *Ebx OPTIONAL,5893OUT UINT32 *Ecx OPTIONAL,5894OUT UINT32 *Edx OPTIONAL5895);58965897/**5898Set CD bit and clear NW bit of CR0 followed by a WBINVD.58995900Disables the caches by setting the CD bit of CR0 to 1, clearing the NW bit of CR0 to 0,5901and executing a WBINVD instruction. This function is only available on IA-32 and x64.59025903**/5904VOID5905EFIAPI5906AsmDisableCache (5907VOID5908);59095910/**5911Perform a WBINVD and clear both the CD and NW bits of CR0.59125913Enables the caches by executing a WBINVD instruction and then clear both the CD and NW5914bits of CR0 to 0. This function is only available on IA-32 and x64.59155916**/5917VOID5918EFIAPI5919AsmEnableCache (5920VOID5921);59225923/**5924Returns the lower 32-bits of a Machine Specific Register(MSR).59255926Reads and returns the lower 32-bits of the MSR specified by Index.5927No parameter checking is performed on Index, and some Index values may cause5928CPU exceptions. The caller must either guarantee that Index is valid, or the5929caller must set up exception handlers to catch the exceptions. This function5930is only available on IA-32 and x64.59315932@param Index The 32-bit MSR index to read.59335934@return The lower 32 bits of the MSR identified by Index.59355936**/5937UINT325938EFIAPI5939AsmReadMsr32 (5940IN UINT32 Index5941);59425943/**5944Writes a 32-bit value to a Machine Specific Register(MSR), and returns the value.5945The upper 32-bits of the MSR are set to zero.59465947Writes the 32-bit value specified by Value to the MSR specified by Index. The5948upper 32-bits of the MSR write are set to zero. The 32-bit value written to5949the MSR is returned. No parameter checking is performed on Index or Value,5950and some of these may cause CPU exceptions. The caller must either guarantee5951that Index and Value are valid, or the caller must establish proper exception5952handlers. This function is only available on IA-32 and x64.59535954@param Index The 32-bit MSR index to write.5955@param Value The 32-bit value to write to the MSR.59565957@return Value59585959**/5960UINT325961EFIAPI5962AsmWriteMsr32 (5963IN UINT32 Index,5964IN UINT32 Value5965);59665967/**5968Reads a 64-bit MSR, performs a bitwise OR on the lower 32-bits, and5969writes the result back to the 64-bit MSR.59705971Reads the 64-bit MSR specified by Index, performs a bitwise OR5972between the lower 32-bits of the read result and the value specified by5973OrData, and writes the result to the 64-bit MSR specified by Index. The lower597432-bits of the value written to the MSR is returned. No parameter checking is5975performed on Index or OrData, and some of these may cause CPU exceptions. The5976caller must either guarantee that Index and OrData are valid, or the caller5977must establish proper exception handlers. This function is only available on5978IA-32 and x64.59795980@param Index The 32-bit MSR index to write.5981@param OrData The value to OR with the read value from the MSR.59825983@return The lower 32-bit value written to the MSR.59845985**/5986UINT325987EFIAPI5988AsmMsrOr32 (5989IN UINT32 Index,5990IN UINT32 OrData5991);59925993/**5994Reads a 64-bit MSR, performs a bitwise AND on the lower 32-bits, and writes5995the result back to the 64-bit MSR.59965997Reads the 64-bit MSR specified by Index, performs a bitwise AND between the5998lower 32-bits of the read result and the value specified by AndData, and5999writes the result to the 64-bit MSR specified by Index. The lower 32-bits of6000the value written to the MSR is returned. No parameter checking is performed6001on Index or AndData, and some of these may cause CPU exceptions. The caller6002must either guarantee that Index and AndData are valid, or the caller must6003establish proper exception handlers. This function is only available on IA-326004and x64.60056006@param Index The 32-bit MSR index to write.6007@param AndData The value to AND with the read value from the MSR.60086009@return The lower 32-bit value written to the MSR.60106011**/6012UINT326013EFIAPI6014AsmMsrAnd32 (6015IN UINT32 Index,6016IN UINT32 AndData6017);60186019/**6020Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise OR6021on the lower 32-bits, and writes the result back to the 64-bit MSR.60226023Reads the 64-bit MSR specified by Index, performs a bitwise AND between the6024lower 32-bits of the read result and the value specified by AndData6025preserving the upper 32-bits, performs a bitwise OR between the6026result of the AND operation and the value specified by OrData, and writes the6027result to the 64-bit MSR specified by Address. The lower 32-bits of the value6028written to the MSR is returned. No parameter checking is performed on Index,6029AndData, or OrData, and some of these may cause CPU exceptions. The caller6030must either guarantee that Index, AndData, and OrData are valid, or the6031caller must establish proper exception handlers. This function is only6032available on IA-32 and x64.60336034@param Index The 32-bit MSR index to write.6035@param AndData The value to AND with the read value from the MSR.6036@param OrData The value to OR with the result of the AND operation.60376038@return The lower 32-bit value written to the MSR.60396040**/6041UINT326042EFIAPI6043AsmMsrAndThenOr32 (6044IN UINT32 Index,6045IN UINT32 AndData,6046IN UINT32 OrData6047);60486049/**6050Reads a bit field of an MSR.60516052Reads the bit field in the lower 32-bits of a 64-bit MSR. The bit field is6053specified by the StartBit and the EndBit. The value of the bit field is6054returned. The caller must either guarantee that Index is valid, or the caller6055must set up exception handlers to catch the exceptions. This function is only6056available on IA-32 and x64.60576058If StartBit is greater than 31, then ASSERT().6059If EndBit is greater than 31, then ASSERT().6060If EndBit is less than StartBit, then ASSERT().60616062@param Index The 32-bit MSR index to read.6063@param StartBit The ordinal of the least significant bit in the bit field.6064Range 0..31.6065@param EndBit The ordinal of the most significant bit in the bit field.6066Range 0..31.60676068@return The bit field read from the MSR.60696070**/6071UINT326072EFIAPI6073AsmMsrBitFieldRead32 (6074IN UINT32 Index,6075IN UINTN StartBit,6076IN UINTN EndBit6077);60786079/**6080Writes a bit field to an MSR.60816082Writes Value to a bit field in the lower 32-bits of a 64-bit MSR. The bit6083field is specified by the StartBit and the EndBit. All other bits in the6084destination MSR are preserved. The lower 32-bits of the MSR written is6085returned. The caller must either guarantee that Index and the data written6086is valid, or the caller must set up exception handlers to catch the exceptions.6087This function is only available on IA-32 and x64.60886089If StartBit is greater than 31, then ASSERT().6090If EndBit is greater than 31, then ASSERT().6091If EndBit is less than StartBit, then ASSERT().6092If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().60936094@param Index The 32-bit MSR index to write.6095@param StartBit The ordinal of the least significant bit in the bit field.6096Range 0..31.6097@param EndBit The ordinal of the most significant bit in the bit field.6098Range 0..31.6099@param Value New value of the bit field.61006101@return The lower 32-bit of the value written to the MSR.61026103**/6104UINT326105EFIAPI6106AsmMsrBitFieldWrite32 (6107IN UINT32 Index,6108IN UINTN StartBit,6109IN UINTN EndBit,6110IN UINT32 Value6111);61126113/**6114Reads a bit field in a 64-bit MSR, performs a bitwise OR, and writes the6115result back to the bit field in the 64-bit MSR.61166117Reads the 64-bit MSR specified by Index, performs a bitwise OR6118between the read result and the value specified by OrData, and writes the6119result to the 64-bit MSR specified by Index. The lower 32-bits of the value6120written to the MSR are returned. Extra left bits in OrData are stripped. The6121caller must either guarantee that Index and the data written is valid, or6122the caller must set up exception handlers to catch the exceptions. This6123function is only available on IA-32 and x64.61246125If StartBit is greater than 31, then ASSERT().6126If EndBit is greater than 31, then ASSERT().6127If EndBit is less than StartBit, then ASSERT().6128If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().61296130@param Index The 32-bit MSR index to write.6131@param StartBit The ordinal of the least significant bit in the bit field.6132Range 0..31.6133@param EndBit The ordinal of the most significant bit in the bit field.6134Range 0..31.6135@param OrData The value to OR with the read value from the MSR.61366137@return The lower 32-bit of the value written to the MSR.61386139**/6140UINT326141EFIAPI6142AsmMsrBitFieldOr32 (6143IN UINT32 Index,6144IN UINTN StartBit,6145IN UINTN EndBit,6146IN UINT32 OrData6147);61486149/**6150Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the6151result back to the bit field in the 64-bit MSR.61526153Reads the 64-bit MSR specified by Index, performs a bitwise AND between the6154read result and the value specified by AndData, and writes the result to the615564-bit MSR specified by Index. The lower 32-bits of the value written to the6156MSR are returned. Extra left bits in AndData are stripped. The caller must6157either guarantee that Index and the data written is valid, or the caller must6158set up exception handlers to catch the exceptions. This function is only6159available on IA-32 and x64.61606161If StartBit is greater than 31, then ASSERT().6162If EndBit is greater than 31, then ASSERT().6163If EndBit is less than StartBit, then ASSERT().6164If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().61656166@param Index The 32-bit MSR index to write.6167@param StartBit The ordinal of the least significant bit in the bit field.6168Range 0..31.6169@param EndBit The ordinal of the most significant bit in the bit field.6170Range 0..31.6171@param AndData The value to AND with the read value from the MSR.61726173@return The lower 32-bit of the value written to the MSR.61746175**/6176UINT326177EFIAPI6178AsmMsrBitFieldAnd32 (6179IN UINT32 Index,6180IN UINTN StartBit,6181IN UINTN EndBit,6182IN UINT32 AndData6183);61846185/**6186Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a6187bitwise OR, and writes the result back to the bit field in the618864-bit MSR.61896190Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by a6191bitwise OR between the read result and the value specified by6192AndData, and writes the result to the 64-bit MSR specified by Index. The6193lower 32-bits of the value written to the MSR are returned. Extra left bits6194in both AndData and OrData are stripped. The caller must either guarantee6195that Index and the data written is valid, or the caller must set up exception6196handlers to catch the exceptions. This function is only available on IA-326197and x64.61986199If StartBit is greater than 31, then ASSERT().6200If EndBit is greater than 31, then ASSERT().6201If EndBit is less than StartBit, then ASSERT().6202If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().6203If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().62046205@param Index The 32-bit MSR index to write.6206@param StartBit The ordinal of the least significant bit in the bit field.6207Range 0..31.6208@param EndBit The ordinal of the most significant bit in the bit field.6209Range 0..31.6210@param AndData The value to AND with the read value from the MSR.6211@param OrData The value to OR with the result of the AND operation.62126213@return The lower 32-bit of the value written to the MSR.62146215**/6216UINT326217EFIAPI6218AsmMsrBitFieldAndThenOr32 (6219IN UINT32 Index,6220IN UINTN StartBit,6221IN UINTN EndBit,6222IN UINT32 AndData,6223IN UINT32 OrData6224);62256226/**6227Returns a 64-bit Machine Specific Register(MSR).62286229Reads and returns the 64-bit MSR specified by Index. No parameter checking is6230performed on Index, and some Index values may cause CPU exceptions. The6231caller must either guarantee that Index is valid, or the caller must set up6232exception handlers to catch the exceptions. This function is only available6233on IA-32 and x64.62346235@param Index The 32-bit MSR index to read.62366237@return The value of the MSR identified by Index.62386239**/6240UINT646241EFIAPI6242AsmReadMsr64 (6243IN UINT32 Index6244);62456246/**6247Writes a 64-bit value to a Machine Specific Register(MSR), and returns the6248value.62496250Writes the 64-bit value specified by Value to the MSR specified by Index. The625164-bit value written to the MSR is returned. No parameter checking is6252performed on Index or Value, and some of these may cause CPU exceptions. The6253caller must either guarantee that Index and Value are valid, or the caller6254must establish proper exception handlers. This function is only available on6255IA-32 and x64.62566257@param Index The 32-bit MSR index to write.6258@param Value The 64-bit value to write to the MSR.62596260@return Value62616262**/6263UINT646264EFIAPI6265AsmWriteMsr64 (6266IN UINT32 Index,6267IN UINT64 Value6268);62696270/**6271Reads a 64-bit MSR, performs a bitwise OR, and writes the result6272back to the 64-bit MSR.62736274Reads the 64-bit MSR specified by Index, performs a bitwise OR6275between the read result and the value specified by OrData, and writes the6276result to the 64-bit MSR specified by Index. The value written to the MSR is6277returned. No parameter checking is performed on Index or OrData, and some of6278these may cause CPU exceptions. The caller must either guarantee that Index6279and OrData are valid, or the caller must establish proper exception handlers.6280This function is only available on IA-32 and x64.62816282@param Index The 32-bit MSR index to write.6283@param OrData The value to OR with the read value from the MSR.62846285@return The value written back to the MSR.62866287**/6288UINT646289EFIAPI6290AsmMsrOr64 (6291IN UINT32 Index,6292IN UINT64 OrData6293);62946295/**6296Reads a 64-bit MSR, performs a bitwise AND, and writes the result back to the629764-bit MSR.62986299Reads the 64-bit MSR specified by Index, performs a bitwise AND between the6300read result and the value specified by OrData, and writes the result to the630164-bit MSR specified by Index. The value written to the MSR is returned. No6302parameter checking is performed on Index or OrData, and some of these may6303cause CPU exceptions. The caller must either guarantee that Index and OrData6304are valid, or the caller must establish proper exception handlers. This6305function is only available on IA-32 and x64.63066307@param Index The 32-bit MSR index to write.6308@param AndData The value to AND with the read value from the MSR.63096310@return The value written back to the MSR.63116312**/6313UINT646314EFIAPI6315AsmMsrAnd64 (6316IN UINT32 Index,6317IN UINT64 AndData6318);63196320/**6321Reads a 64-bit MSR, performs a bitwise AND followed by a bitwise6322OR, and writes the result back to the 64-bit MSR.63236324Reads the 64-bit MSR specified by Index, performs a bitwise AND between read6325result and the value specified by AndData, performs a bitwise OR6326between the result of the AND operation and the value specified by OrData,6327and writes the result to the 64-bit MSR specified by Index. The value written6328to the MSR is returned. No parameter checking is performed on Index, AndData,6329or OrData, and some of these may cause CPU exceptions. The caller must either6330guarantee that Index, AndData, and OrData are valid, or the caller must6331establish proper exception handlers. This function is only available on IA-326332and x64.63336334@param Index The 32-bit MSR index to write.6335@param AndData The value to AND with the read value from the MSR.6336@param OrData The value to OR with the result of the AND operation.63376338@return The value written back to the MSR.63396340**/6341UINT646342EFIAPI6343AsmMsrAndThenOr64 (6344IN UINT32 Index,6345IN UINT64 AndData,6346IN UINT64 OrData6347);63486349/**6350Reads a bit field of an MSR.63516352Reads the bit field in the 64-bit MSR. The bit field is specified by the6353StartBit and the EndBit. The value of the bit field is returned. The caller6354must either guarantee that Index is valid, or the caller must set up6355exception handlers to catch the exceptions. This function is only available6356on IA-32 and x64.63576358If StartBit is greater than 63, then ASSERT().6359If EndBit is greater than 63, then ASSERT().6360If EndBit is less than StartBit, then ASSERT().63616362@param Index The 32-bit MSR index to read.6363@param StartBit The ordinal of the least significant bit in the bit field.6364Range 0..63.6365@param EndBit The ordinal of the most significant bit in the bit field.6366Range 0..63.63676368@return The value read from the MSR.63696370**/6371UINT646372EFIAPI6373AsmMsrBitFieldRead64 (6374IN UINT32 Index,6375IN UINTN StartBit,6376IN UINTN EndBit6377);63786379/**6380Writes a bit field to an MSR.63816382Writes Value to a bit field in a 64-bit MSR. The bit field is specified by6383the StartBit and the EndBit. All other bits in the destination MSR are6384preserved. The MSR written is returned. The caller must either guarantee6385that Index and the data written is valid, or the caller must set up exception6386handlers to catch the exceptions. This function is only available on IA-32 and x64.63876388If StartBit is greater than 63, then ASSERT().6389If EndBit is greater than 63, then ASSERT().6390If EndBit is less than StartBit, then ASSERT().6391If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().63926393@param Index The 32-bit MSR index to write.6394@param StartBit The ordinal of the least significant bit in the bit field.6395Range 0..63.6396@param EndBit The ordinal of the most significant bit in the bit field.6397Range 0..63.6398@param Value New value of the bit field.63996400@return The value written back to the MSR.64016402**/6403UINT646404EFIAPI6405AsmMsrBitFieldWrite64 (6406IN UINT32 Index,6407IN UINTN StartBit,6408IN UINTN EndBit,6409IN UINT64 Value6410);64116412/**6413Reads a bit field in a 64-bit MSR, performs a bitwise OR, and6414writes the result back to the bit field in the 64-bit MSR.64156416Reads the 64-bit MSR specified by Index, performs a bitwise OR6417between the read result and the value specified by OrData, and writes the6418result to the 64-bit MSR specified by Index. The value written to the MSR is6419returned. Extra left bits in OrData are stripped. The caller must either6420guarantee that Index and the data written is valid, or the caller must set up6421exception handlers to catch the exceptions. This function is only available6422on IA-32 and x64.64236424If StartBit is greater than 63, then ASSERT().6425If EndBit is greater than 63, then ASSERT().6426If EndBit is less than StartBit, then ASSERT().6427If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().64286429@param Index The 32-bit MSR index to write.6430@param StartBit The ordinal of the least significant bit in the bit field.6431Range 0..63.6432@param EndBit The ordinal of the most significant bit in the bit field.6433Range 0..63.6434@param OrData The value to OR with the read value from the bit field.64356436@return The value written back to the MSR.64376438**/6439UINT646440EFIAPI6441AsmMsrBitFieldOr64 (6442IN UINT32 Index,6443IN UINTN StartBit,6444IN UINTN EndBit,6445IN UINT64 OrData6446);64476448/**6449Reads a bit field in a 64-bit MSR, performs a bitwise AND, and writes the6450result back to the bit field in the 64-bit MSR.64516452Reads the 64-bit MSR specified by Index, performs a bitwise AND between the6453read result and the value specified by AndData, and writes the result to the645464-bit MSR specified by Index. The value written to the MSR is returned.6455Extra left bits in AndData are stripped. The caller must either guarantee6456that Index and the data written is valid, or the caller must set up exception6457handlers to catch the exceptions. This function is only available on IA-326458and x64.64596460If StartBit is greater than 63, then ASSERT().6461If EndBit is greater than 63, then ASSERT().6462If EndBit is less than StartBit, then ASSERT().6463If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().64646465@param Index The 32-bit MSR index to write.6466@param StartBit The ordinal of the least significant bit in the bit field.6467Range 0..63.6468@param EndBit The ordinal of the most significant bit in the bit field.6469Range 0..63.6470@param AndData The value to AND with the read value from the bit field.64716472@return The value written back to the MSR.64736474**/6475UINT646476EFIAPI6477AsmMsrBitFieldAnd64 (6478IN UINT32 Index,6479IN UINTN StartBit,6480IN UINTN EndBit,6481IN UINT64 AndData6482);64836484/**6485Reads a bit field in a 64-bit MSR, performs a bitwise AND followed by a6486bitwise OR, and writes the result back to the bit field in the648764-bit MSR.64886489Reads the 64-bit MSR specified by Index, performs a bitwise AND followed by6490a bitwise OR between the read result and the value specified by6491AndData, and writes the result to the 64-bit MSR specified by Index. The6492value written to the MSR is returned. Extra left bits in both AndData and6493OrData are stripped. The caller must either guarantee that Index and the data6494written is valid, or the caller must set up exception handlers to catch the6495exceptions. This function is only available on IA-32 and x64.64966497If StartBit is greater than 63, then ASSERT().6498If EndBit is greater than 63, then ASSERT().6499If EndBit is less than StartBit, then ASSERT().6500If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().6501If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().65026503@param Index The 32-bit MSR index to write.6504@param StartBit The ordinal of the least significant bit in the bit field.6505Range 0..63.6506@param EndBit The ordinal of the most significant bit in the bit field.6507Range 0..63.6508@param AndData The value to AND with the read value from the bit field.6509@param OrData The value to OR with the result of the AND operation.65106511@return The value written back to the MSR.65126513**/6514UINT646515EFIAPI6516AsmMsrBitFieldAndThenOr64 (6517IN UINT32 Index,6518IN UINTN StartBit,6519IN UINTN EndBit,6520IN UINT64 AndData,6521IN UINT64 OrData6522);65236524/**6525Reads the current value of the EFLAGS register.65266527Reads and returns the current value of the EFLAGS register. This function is6528only available on IA-32 and x64. This returns a 32-bit value on IA-32 and a652964-bit value on x64.65306531@return EFLAGS on IA-32 or RFLAGS on x64.65326533**/6534UINTN6535EFIAPI6536AsmReadEflags (6537VOID6538);65396540/**6541Reads the current value of the Control Register 0 (CR0).65426543Reads and returns the current value of CR0. This function is only available6544on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6545x64.65466547@return The value of the Control Register 0 (CR0).65486549**/6550UINTN6551EFIAPI6552AsmReadCr0 (6553VOID6554);65556556/**6557Reads the current value of the Control Register 2 (CR2).65586559Reads and returns the current value of CR2. This function is only available6560on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6561x64.65626563@return The value of the Control Register 2 (CR2).65646565**/6566UINTN6567EFIAPI6568AsmReadCr2 (6569VOID6570);65716572/**6573Reads the current value of the Control Register 3 (CR3).65746575Reads and returns the current value of CR3. This function is only available6576on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6577x64.65786579@return The value of the Control Register 3 (CR3).65806581**/6582UINTN6583EFIAPI6584AsmReadCr3 (6585VOID6586);65876588/**6589Reads the current value of the Control Register 4 (CR4).65906591Reads and returns the current value of CR4. This function is only available6592on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6593x64.65946595@return The value of the Control Register 4 (CR4).65966597**/6598UINTN6599EFIAPI6600AsmReadCr4 (6601VOID6602);66036604/**6605Writes a value to Control Register 0 (CR0).66066607Writes and returns a new value to CR0. This function is only available on6608IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.66096610@param Cr0 The value to write to CR0.66116612@return The value written to CR0.66136614**/6615UINTN6616EFIAPI6617AsmWriteCr0 (6618UINTN Cr06619);66206621/**6622Writes a value to Control Register 2 (CR2).66236624Writes and returns a new value to CR2. This function is only available on6625IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.66266627@param Cr2 The value to write to CR2.66286629@return The value written to CR2.66306631**/6632UINTN6633EFIAPI6634AsmWriteCr2 (6635UINTN Cr26636);66376638/**6639Writes a value to Control Register 3 (CR3).66406641Writes and returns a new value to CR3. This function is only available on6642IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.66436644@param Cr3 The value to write to CR3.66456646@return The value written to CR3.66476648**/6649UINTN6650EFIAPI6651AsmWriteCr3 (6652UINTN Cr36653);66546655/**6656Writes a value to Control Register 4 (CR4).66576658Writes and returns a new value to CR4. This function is only available on6659IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.66606661@param Cr4 The value to write to CR4.66626663@return The value written to CR4.66646665**/6666UINTN6667EFIAPI6668AsmWriteCr4 (6669UINTN Cr46670);66716672/**6673Reads the current value of Debug Register 0 (DR0).66746675Reads and returns the current value of DR0. This function is only available6676on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6677x64.66786679@return The value of Debug Register 0 (DR0).66806681**/6682UINTN6683EFIAPI6684AsmReadDr0 (6685VOID6686);66876688/**6689Reads the current value of Debug Register 1 (DR1).66906691Reads and returns the current value of DR1. This function is only available6692on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6693x64.66946695@return The value of Debug Register 1 (DR1).66966697**/6698UINTN6699EFIAPI6700AsmReadDr1 (6701VOID6702);67036704/**6705Reads the current value of Debug Register 2 (DR2).67066707Reads and returns the current value of DR2. This function is only available6708on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6709x64.67106711@return The value of Debug Register 2 (DR2).67126713**/6714UINTN6715EFIAPI6716AsmReadDr2 (6717VOID6718);67196720/**6721Reads the current value of Debug Register 3 (DR3).67226723Reads and returns the current value of DR3. This function is only available6724on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6725x64.67266727@return The value of Debug Register 3 (DR3).67286729**/6730UINTN6731EFIAPI6732AsmReadDr3 (6733VOID6734);67356736/**6737Reads the current value of Debug Register 4 (DR4).67386739Reads and returns the current value of DR4. This function is only available6740on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6741x64.67426743@return The value of Debug Register 4 (DR4).67446745**/6746UINTN6747EFIAPI6748AsmReadDr4 (6749VOID6750);67516752/**6753Reads the current value of Debug Register 5 (DR5).67546755Reads and returns the current value of DR5. This function is only available6756on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6757x64.67586759@return The value of Debug Register 5 (DR5).67606761**/6762UINTN6763EFIAPI6764AsmReadDr5 (6765VOID6766);67676768/**6769Reads the current value of Debug Register 6 (DR6).67706771Reads and returns the current value of DR6. This function is only available6772on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6773x64.67746775@return The value of Debug Register 6 (DR6).67766777**/6778UINTN6779EFIAPI6780AsmReadDr6 (6781VOID6782);67836784/**6785Reads the current value of Debug Register 7 (DR7).67866787Reads and returns the current value of DR7. This function is only available6788on IA-32 and x64. This returns a 32-bit value on IA-32 and a 64-bit value on6789x64.67906791@return The value of Debug Register 7 (DR7).67926793**/6794UINTN6795EFIAPI6796AsmReadDr7 (6797VOID6798);67996800/**6801Writes a value to Debug Register 0 (DR0).68026803Writes and returns a new value to DR0. This function is only available on6804IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.68056806@param Dr0 The value to write to Dr0.68076808@return The value written to Debug Register 0 (DR0).68096810**/6811UINTN6812EFIAPI6813AsmWriteDr0 (6814UINTN Dr06815);68166817/**6818Writes a value to Debug Register 1 (DR1).68196820Writes and returns a new value to DR1. This function is only available on6821IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.68226823@param Dr1 The value to write to Dr1.68246825@return The value written to Debug Register 1 (DR1).68266827**/6828UINTN6829EFIAPI6830AsmWriteDr1 (6831UINTN Dr16832);68336834/**6835Writes a value to Debug Register 2 (DR2).68366837Writes and returns a new value to DR2. This function is only available on6838IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.68396840@param Dr2 The value to write to Dr2.68416842@return The value written to Debug Register 2 (DR2).68436844**/6845UINTN6846EFIAPI6847AsmWriteDr2 (6848UINTN Dr26849);68506851/**6852Writes a value to Debug Register 3 (DR3).68536854Writes and returns a new value to DR3. This function is only available on6855IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.68566857@param Dr3 The value to write to Dr3.68586859@return The value written to Debug Register 3 (DR3).68606861**/6862UINTN6863EFIAPI6864AsmWriteDr3 (6865UINTN Dr36866);68676868/**6869Writes a value to Debug Register 4 (DR4).68706871Writes and returns a new value to DR4. This function is only available on6872IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.68736874@param Dr4 The value to write to Dr4.68756876@return The value written to Debug Register 4 (DR4).68776878**/6879UINTN6880EFIAPI6881AsmWriteDr4 (6882UINTN Dr46883);68846885/**6886Writes a value to Debug Register 5 (DR5).68876888Writes and returns a new value to DR5. This function is only available on6889IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.68906891@param Dr5 The value to write to Dr5.68926893@return The value written to Debug Register 5 (DR5).68946895**/6896UINTN6897EFIAPI6898AsmWriteDr5 (6899UINTN Dr56900);69016902/**6903Writes a value to Debug Register 6 (DR6).69046905Writes and returns a new value to DR6. This function is only available on6906IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.69076908@param Dr6 The value to write to Dr6.69096910@return The value written to Debug Register 6 (DR6).69116912**/6913UINTN6914EFIAPI6915AsmWriteDr6 (6916UINTN Dr66917);69186919/**6920Writes a value to Debug Register 7 (DR7).69216922Writes and returns a new value to DR7. This function is only available on6923IA-32 and x64. This writes a 32-bit value on IA-32 and a 64-bit value on x64.69246925@param Dr7 The value to write to Dr7.69266927@return The value written to Debug Register 7 (DR7).69286929**/6930UINTN6931EFIAPI6932AsmWriteDr7 (6933UINTN Dr76934);69356936/**6937Reads the current value of Code Segment Register (CS).69386939Reads and returns the current value of CS. This function is only available on6940IA-32 and x64.69416942@return The current value of CS.69436944**/6945UINT166946EFIAPI6947AsmReadCs (6948VOID6949);69506951/**6952Reads the current value of Data Segment Register (DS).69536954Reads and returns the current value of DS. This function is only available on6955IA-32 and x64.69566957@return The current value of DS.69586959**/6960UINT166961EFIAPI6962AsmReadDs (6963VOID6964);69656966/**6967Reads the current value of Extra Segment Register (ES).69686969Reads and returns the current value of ES. This function is only available on6970IA-32 and x64.69716972@return The current value of ES.69736974**/6975UINT166976EFIAPI6977AsmReadEs (6978VOID6979);69806981/**6982Reads the current value of FS Data Segment Register (FS).69836984Reads and returns the current value of FS. This function is only available on6985IA-32 and x64.69866987@return The current value of FS.69886989**/6990UINT166991EFIAPI6992AsmReadFs (6993VOID6994);69956996/**6997Reads the current value of GS Data Segment Register (GS).69986999Reads and returns the current value of GS. This function is only available on7000IA-32 and x64.70017002@return The current value of GS.70037004**/7005UINT167006EFIAPI7007AsmReadGs (7008VOID7009);70107011/**7012Reads the current value of Stack Segment Register (SS).70137014Reads and returns the current value of SS. This function is only available on7015IA-32 and x64.70167017@return The current value of SS.70187019**/7020UINT167021EFIAPI7022AsmReadSs (7023VOID7024);70257026/**7027Reads the current value of Task Register (TR).70287029Reads and returns the current value of TR. This function is only available on7030IA-32 and x64.70317032@return The current value of TR.70337034**/7035UINT167036EFIAPI7037AsmReadTr (7038VOID7039);70407041/**7042Reads the current Global Descriptor Table Register(GDTR) descriptor.70437044Reads and returns the current GDTR descriptor and returns it in Gdtr. This7045function is only available on IA-32 and x64.70467047If Gdtr is NULL, then ASSERT().70487049@param Gdtr The pointer to a GDTR descriptor.70507051**/7052VOID7053EFIAPI7054AsmReadGdtr (7055OUT IA32_DESCRIPTOR *Gdtr7056);70577058/**7059Writes the current Global Descriptor Table Register (GDTR) descriptor.70607061Writes and the current GDTR descriptor specified by Gdtr. This function is7062only available on IA-32 and x64.70637064If Gdtr is NULL, then ASSERT().70657066@param Gdtr The pointer to a GDTR descriptor.70677068**/7069VOID7070EFIAPI7071AsmWriteGdtr (7072IN CONST IA32_DESCRIPTOR *Gdtr7073);70747075/**7076Reads the current Interrupt Descriptor Table Register(IDTR) descriptor.70777078Reads and returns the current IDTR descriptor and returns it in Idtr. This7079function is only available on IA-32 and x64.70807081If Idtr is NULL, then ASSERT().70827083@param Idtr The pointer to a IDTR descriptor.70847085**/7086VOID7087EFIAPI7088AsmReadIdtr (7089OUT IA32_DESCRIPTOR *Idtr7090);70917092/**7093Writes the current Interrupt Descriptor Table Register(IDTR) descriptor.70947095Writes the current IDTR descriptor and returns it in Idtr. This function is7096only available on IA-32 and x64.70977098If Idtr is NULL, then ASSERT().70997100@param Idtr The pointer to a IDTR descriptor.71017102**/7103VOID7104EFIAPI7105AsmWriteIdtr (7106IN CONST IA32_DESCRIPTOR *Idtr7107);71087109/**7110Reads the current Local Descriptor Table Register(LDTR) selector.71117112Reads and returns the current 16-bit LDTR descriptor value. This function is7113only available on IA-32 and x64.71147115@return The current selector of LDT.71167117**/7118UINT167119EFIAPI7120AsmReadLdtr (7121VOID7122);71237124/**7125Writes the current Local Descriptor Table Register (LDTR) selector.71267127Writes and the current LDTR descriptor specified by Ldtr. This function is7128only available on IA-32 and x64.71297130@param Ldtr 16-bit LDTR selector value.71317132**/7133VOID7134EFIAPI7135AsmWriteLdtr (7136IN UINT16 Ldtr7137);71387139/**7140Save the current floating point/SSE/SSE2 context to a buffer.71417142Saves the current floating point/SSE/SSE2 state to the buffer specified by7143Buffer. Buffer must be aligned on a 16-byte boundary. This function is only7144available on IA-32 and x64.71457146If Buffer is NULL, then ASSERT().7147If Buffer is not aligned on a 16-byte boundary, then ASSERT().71487149@param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.71507151**/7152VOID7153EFIAPI7154AsmFxSave (7155OUT IA32_FX_BUFFER *Buffer7156);71577158/**7159Restores the current floating point/SSE/SSE2 context from a buffer.71607161Restores the current floating point/SSE/SSE2 state from the buffer specified7162by Buffer. Buffer must be aligned on a 16-byte boundary. This function is7163only available on IA-32 and x64.71647165If Buffer is NULL, then ASSERT().7166If Buffer is not aligned on a 16-byte boundary, then ASSERT().7167If Buffer was not saved with AsmFxSave(), then ASSERT().71687169@param Buffer The pointer to a buffer to save the floating point/SSE/SSE2 context.71707171**/7172VOID7173EFIAPI7174AsmFxRestore (7175IN CONST IA32_FX_BUFFER *Buffer7176);71777178/**7179Reads the current value of 64-bit MMX Register #0 (MM0).71807181Reads and returns the current value of MM0. This function is only available7182on IA-32 and x64.71837184@return The current value of MM0.71857186**/7187UINT647188EFIAPI7189AsmReadMm0 (7190VOID7191);71927193/**7194Reads the current value of 64-bit MMX Register #1 (MM1).71957196Reads and returns the current value of MM1. This function is only available7197on IA-32 and x64.71987199@return The current value of MM1.72007201**/7202UINT647203EFIAPI7204AsmReadMm1 (7205VOID7206);72077208/**7209Reads the current value of 64-bit MMX Register #2 (MM2).72107211Reads and returns the current value of MM2. This function is only available7212on IA-32 and x64.72137214@return The current value of MM2.72157216**/7217UINT647218EFIAPI7219AsmReadMm2 (7220VOID7221);72227223/**7224Reads the current value of 64-bit MMX Register #3 (MM3).72257226Reads and returns the current value of MM3. This function is only available7227on IA-32 and x64.72287229@return The current value of MM3.72307231**/7232UINT647233EFIAPI7234AsmReadMm3 (7235VOID7236);72377238/**7239Reads the current value of 64-bit MMX Register #4 (MM4).72407241Reads and returns the current value of MM4. This function is only available7242on IA-32 and x64.72437244@return The current value of MM4.72457246**/7247UINT647248EFIAPI7249AsmReadMm4 (7250VOID7251);72527253/**7254Reads the current value of 64-bit MMX Register #5 (MM5).72557256Reads and returns the current value of MM5. This function is only available7257on IA-32 and x64.72587259@return The current value of MM5.72607261**/7262UINT647263EFIAPI7264AsmReadMm5 (7265VOID7266);72677268/**7269Reads the current value of 64-bit MMX Register #6 (MM6).72707271Reads and returns the current value of MM6. This function is only available7272on IA-32 and x64.72737274@return The current value of MM6.72757276**/7277UINT647278EFIAPI7279AsmReadMm6 (7280VOID7281);72827283/**7284Reads the current value of 64-bit MMX Register #7 (MM7).72857286Reads and returns the current value of MM7. This function is only available7287on IA-32 and x64.72887289@return The current value of MM7.72907291**/7292UINT647293EFIAPI7294AsmReadMm7 (7295VOID7296);72977298/**7299Writes the current value of 64-bit MMX Register #0 (MM0).73007301Writes the current value of MM0. This function is only available on IA32 and7302x64.73037304@param Value The 64-bit value to write to MM0.73057306**/7307VOID7308EFIAPI7309AsmWriteMm0 (7310IN UINT64 Value7311);73127313/**7314Writes the current value of 64-bit MMX Register #1 (MM1).73157316Writes the current value of MM1. This function is only available on IA32 and7317x64.73187319@param Value The 64-bit value to write to MM1.73207321**/7322VOID7323EFIAPI7324AsmWriteMm1 (7325IN UINT64 Value7326);73277328/**7329Writes the current value of 64-bit MMX Register #2 (MM2).73307331Writes the current value of MM2. This function is only available on IA32 and7332x64.73337334@param Value The 64-bit value to write to MM2.73357336**/7337VOID7338EFIAPI7339AsmWriteMm2 (7340IN UINT64 Value7341);73427343/**7344Writes the current value of 64-bit MMX Register #3 (MM3).73457346Writes the current value of MM3. This function is only available on IA32 and7347x64.73487349@param Value The 64-bit value to write to MM3.73507351**/7352VOID7353EFIAPI7354AsmWriteMm3 (7355IN UINT64 Value7356);73577358/**7359Writes the current value of 64-bit MMX Register #4 (MM4).73607361Writes the current value of MM4. This function is only available on IA32 and7362x64.73637364@param Value The 64-bit value to write to MM4.73657366**/7367VOID7368EFIAPI7369AsmWriteMm4 (7370IN UINT64 Value7371);73727373/**7374Writes the current value of 64-bit MMX Register #5 (MM5).73757376Writes the current value of MM5. This function is only available on IA32 and7377x64.73787379@param Value The 64-bit value to write to MM5.73807381**/7382VOID7383EFIAPI7384AsmWriteMm5 (7385IN UINT64 Value7386);73877388/**7389Writes the current value of 64-bit MMX Register #6 (MM6).73907391Writes the current value of MM6. This function is only available on IA32 and7392x64.73937394@param Value The 64-bit value to write to MM6.73957396**/7397VOID7398EFIAPI7399AsmWriteMm6 (7400IN UINT64 Value7401);74027403/**7404Writes the current value of 64-bit MMX Register #7 (MM7).74057406Writes the current value of MM7. This function is only available on IA32 and7407x64.74087409@param Value The 64-bit value to write to MM7.74107411**/7412VOID7413EFIAPI7414AsmWriteMm7 (7415IN UINT64 Value7416);74177418/**7419Reads the current value of Time Stamp Counter (TSC).74207421Reads and returns the current value of TSC. This function is only available7422on IA-32 and x64.74237424@return The current value of TSC74257426**/7427UINT647428EFIAPI7429AsmReadTsc (7430VOID7431);74327433/**7434Reads the current value of a Performance Counter (PMC).74357436Reads and returns the current value of performance counter specified by7437Index. This function is only available on IA-32 and x64.74387439@param Index The 32-bit Performance Counter index to read.74407441@return The value of the PMC specified by Index.74427443**/7444UINT647445EFIAPI7446AsmReadPmc (7447IN UINT32 Index7448);74497450/**7451Sets up a monitor buffer that is used by AsmMwait().74527453Executes a MONITOR instruction with the register state specified by Eax, Ecx7454and Edx. Returns Eax. This function is only available on IA-32 and x64.74557456@param Eax The value to load into EAX or RAX before executing the MONITOR7457instruction.7458@param Ecx The value to load into ECX or RCX before executing the MONITOR7459instruction.7460@param Edx The value to load into EDX or RDX before executing the MONITOR7461instruction.74627463@return Eax74647465**/7466UINTN7467EFIAPI7468AsmMonitor (7469IN UINTN Eax,7470IN UINTN Ecx,7471IN UINTN Edx7472);74737474/**7475Executes an MWAIT instruction.74767477Executes an MWAIT instruction with the register state specified by Eax and7478Ecx. Returns Eax. This function is only available on IA-32 and x64.74797480@param Eax The value to load into EAX or RAX before executing the MONITOR7481instruction.7482@param Ecx The value to load into ECX or RCX before executing the MONITOR7483instruction.74847485@return Eax74867487**/7488UINTN7489EFIAPI7490AsmMwait (7491IN UINTN Eax,7492IN UINTN Ecx7493);74947495/**7496Executes a WBINVD instruction.74977498Executes a WBINVD instruction. This function is only available on IA-32 and7499x64.75007501**/7502VOID7503EFIAPI7504AsmWbinvd (7505VOID7506);75077508/**7509Executes a INVD instruction.75107511Executes a INVD instruction. This function is only available on IA-32 and7512x64.75137514**/7515VOID7516EFIAPI7517AsmInvd (7518VOID7519);75207521/**7522Flushes a cache line from all the instruction and data caches within the7523coherency domain of the CPU.75247525Flushed the cache line specified by LinearAddress, and returns LinearAddress.7526This function is only available on IA-32 and x64.75277528@param LinearAddress The address of the cache line to flush. If the CPU is7529in a physical addressing mode, then LinearAddress is a7530physical address. If the CPU is in a virtual7531addressing mode, then LinearAddress is a virtual7532address.75337534@return LinearAddress.7535**/7536VOID *7537EFIAPI7538AsmFlushCacheLine (7539IN VOID *LinearAddress7540);75417542/**7543Enables the 32-bit paging mode on the CPU.75447545Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables7546must be properly initialized prior to calling this service. This function7547assumes the current execution mode is 32-bit protected mode. This function is7548only available on IA-32. After the 32-bit paging mode is enabled, control is7549transferred to the function specified by EntryPoint using the new stack7550specified by NewStack and passing in the parameters specified by Context1 and7551Context2. Context1 and Context2 are optional and may be NULL. The function7552EntryPoint must never return.75537554If the current execution mode is not 32-bit protected mode, then ASSERT().7555If EntryPoint is NULL, then ASSERT().7556If NewStack is NULL, then ASSERT().75577558There are a number of constraints that must be followed before calling this7559function:75601) Interrupts must be disabled.75612) The caller must be in 32-bit protected mode with flat descriptors. This7562means all descriptors must have a base of 0 and a limit of 4GB.75633) CR0 and CR4 must be compatible with 32-bit protected mode with flat7564descriptors.75654) CR3 must point to valid page tables that will be used once the transition7566is complete, and those page tables must guarantee that the pages for this7567function and the stack are identity mapped.75687569@param EntryPoint A pointer to function to call with the new stack after7570paging is enabled.7571@param Context1 A pointer to the context to pass into the EntryPoint7572function as the first parameter after paging is enabled.7573@param Context2 A pointer to the context to pass into the EntryPoint7574function as the second parameter after paging is enabled.7575@param NewStack A pointer to the new stack to use for the EntryPoint7576function after paging is enabled.75777578**/7579VOID7580EFIAPI7581AsmEnablePaging32 (7582IN SWITCH_STACK_ENTRY_POINT EntryPoint,7583IN VOID *Context1 OPTIONAL,7584IN VOID *Context2 OPTIONAL,7585IN VOID *NewStack7586);75877588/**7589Disables the 32-bit paging mode on the CPU.75907591Disables the 32-bit paging mode on the CPU and returns to 32-bit protected7592mode. This function assumes the current execution mode is 32-paged protected7593mode. This function is only available on IA-32. After the 32-bit paging mode7594is disabled, control is transferred to the function specified by EntryPoint7595using the new stack specified by NewStack and passing in the parameters7596specified by Context1 and Context2. Context1 and Context2 are optional and7597may be NULL. The function EntryPoint must never return.75987599If the current execution mode is not 32-bit paged mode, then ASSERT().7600If EntryPoint is NULL, then ASSERT().7601If NewStack is NULL, then ASSERT().76027603There are a number of constraints that must be followed before calling this7604function:76051) Interrupts must be disabled.76062) The caller must be in 32-bit paged mode.76073) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.76084) CR3 must point to valid page tables that guarantee that the pages for7609this function and the stack are identity mapped.76107611@param EntryPoint A pointer to function to call with the new stack after7612paging is disabled.7613@param Context1 A pointer to the context to pass into the EntryPoint7614function as the first parameter after paging is disabled.7615@param Context2 A pointer to the context to pass into the EntryPoint7616function as the second parameter after paging is7617disabled.7618@param NewStack A pointer to the new stack to use for the EntryPoint7619function after paging is disabled.76207621**/7622VOID7623EFIAPI7624AsmDisablePaging32 (7625IN SWITCH_STACK_ENTRY_POINT EntryPoint,7626IN VOID *Context1 OPTIONAL,7627IN VOID *Context2 OPTIONAL,7628IN VOID *NewStack7629);76307631/**7632Enables the 64-bit paging mode on the CPU.76337634Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables7635must be properly initialized prior to calling this service. This function7636assumes the current execution mode is 32-bit protected mode with flat7637descriptors. This function is only available on IA-32. After the 64-bit7638paging mode is enabled, control is transferred to the function specified by7639EntryPoint using the new stack specified by NewStack and passing in the7640parameters specified by Context1 and Context2. Context1 and Context2 are7641optional and may be 0. The function EntryPoint must never return.76427643If the current execution mode is not 32-bit protected mode with flat7644descriptors, then ASSERT().7645If EntryPoint is 0, then ASSERT().7646If NewStack is 0, then ASSERT().76477648@param Cs The 16-bit selector to load in the CS before EntryPoint7649is called. The descriptor in the GDT that this selector7650references must be setup for long mode.7651@param EntryPoint The 64-bit virtual address of the function to call with7652the new stack after paging is enabled.7653@param Context1 The 64-bit virtual address of the context to pass into7654the EntryPoint function as the first parameter after7655paging is enabled.7656@param Context2 The 64-bit virtual address of the context to pass into7657the EntryPoint function as the second parameter after7658paging is enabled.7659@param NewStack The 64-bit virtual address of the new stack to use for7660the EntryPoint function after paging is enabled.76617662**/7663VOID7664EFIAPI7665AsmEnablePaging64 (7666IN UINT16 Cs,7667IN UINT64 EntryPoint,7668IN UINT64 Context1 OPTIONAL,7669IN UINT64 Context2 OPTIONAL,7670IN UINT64 NewStack7671);76727673/**7674Disables the 64-bit paging mode on the CPU.76757676Disables the 64-bit paging mode on the CPU and returns to 32-bit protected7677mode. This function assumes the current execution mode is 64-paging mode.7678This function is only available on x64. After the 64-bit paging mode is7679disabled, control is transferred to the function specified by EntryPoint7680using the new stack specified by NewStack and passing in the parameters7681specified by Context1 and Context2. Context1 and Context2 are optional and7682may be 0. The function EntryPoint must never return.76837684If the current execution mode is not 64-bit paged mode, then ASSERT().7685If EntryPoint is 0, then ASSERT().7686If NewStack is 0, then ASSERT().76877688@param Cs The 16-bit selector to load in the CS before EntryPoint7689is called. The descriptor in the GDT that this selector7690references must be setup for 32-bit protected mode.7691@param EntryPoint The 64-bit virtual address of the function to call with7692the new stack after paging is disabled.7693@param Context1 The 64-bit virtual address of the context to pass into7694the EntryPoint function as the first parameter after7695paging is disabled.7696@param Context2 The 64-bit virtual address of the context to pass into7697the EntryPoint function as the second parameter after7698paging is disabled.7699@param NewStack The 64-bit virtual address of the new stack to use for7700the EntryPoint function after paging is disabled.77017702**/7703VOID7704EFIAPI7705AsmDisablePaging64 (7706IN UINT16 Cs,7707IN UINT32 EntryPoint,7708IN UINT32 Context1 OPTIONAL,7709IN UINT32 Context2 OPTIONAL,7710IN UINT32 NewStack7711);77127713//7714// 16-bit thunking services7715//77167717/**7718Retrieves the properties for 16-bit thunk functions.77197720Computes the size of the buffer and stack below 1MB required to use the7721AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This7722buffer size is returned in RealModeBufferSize, and the stack size is returned7723in ExtraStackSize. If parameters are passed to the 16-bit real mode code,7724then the actual minimum stack size is ExtraStackSize plus the maximum number7725of bytes that need to be passed to the 16-bit real mode code.77267727If RealModeBufferSize is NULL, then ASSERT().7728If ExtraStackSize is NULL, then ASSERT().77297730@param RealModeBufferSize A pointer to the size of the buffer below 1MB7731required to use the 16-bit thunk functions.7732@param ExtraStackSize A pointer to the extra size of stack below 1MB7733that the 16-bit thunk functions require for7734temporary storage in the transition to and from773516-bit real mode.77367737**/7738VOID7739EFIAPI7740AsmGetThunk16Properties (7741OUT UINT32 *RealModeBufferSize,7742OUT UINT32 *ExtraStackSize7743);77447745/**7746Prepares all structures a code required to use AsmThunk16().77477748Prepares all structures and code required to use AsmThunk16().77497750This interface is limited to be used in either physical mode or virtual modes with paging enabled where the7751virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.77527753If ThunkContext is NULL, then ASSERT().77547755@param ThunkContext A pointer to the context structure that describes the775616-bit real mode code to call.77577758**/7759VOID7760EFIAPI7761AsmPrepareThunk16 (7762IN OUT THUNK_CONTEXT *ThunkContext7763);77647765/**7766Transfers control to a 16-bit real mode entry point and returns the results.77677768Transfers control to a 16-bit real mode entry point and returns the results.7769AsmPrepareThunk16() must be called with ThunkContext before this function is used.7770This function must be called with interrupts disabled.77717772The register state from the RealModeState field of ThunkContext is restored just prior7773to calling the 16-bit real mode entry point. This includes the EFLAGS field of RealModeState,7774which is used to set the interrupt state when a 16-bit real mode entry point is called.7775Control is transferred to the 16-bit real mode entry point specified by the CS and Eip fields of RealModeState.7776The stack is initialized to the SS and ESP fields of RealModeState. Any parameters passed to7777the 16-bit real mode code must be populated by the caller at SS:ESP prior to calling this function.7778The 16-bit real mode entry point is invoked with a 16-bit CALL FAR instruction,7779so when accessing stack contents, the 16-bit real mode code must account for the 16-bit segment7780and 16-bit offset of the return address that were pushed onto the stack. The 16-bit real mode entry7781point must exit with a RETF instruction. The register state is captured into RealModeState immediately7782after the RETF instruction is executed.77837784If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,7785or any of the 16-bit real mode code makes a SW interrupt, then the caller is responsible for making sure7786the IDT at address 0 is initialized to handle any HW or SW interrupts that may occur while in 16-bit real mode.77877788If EFLAGS specifies interrupts enabled, or any of the 16-bit real mode code enables interrupts,7789then the caller is responsible for making sure the 8259 PIC is in a state compatible with 16-bit real mode.7790This includes the base vectors, the interrupt masks, and the edge/level trigger mode.77917792If THUNK_ATTRIBUTE_BIG_REAL_MODE is set in the ThunkAttributes field of ThunkContext, then the user code7793is invoked in big real mode. Otherwise, the user code is invoked in 16-bit real mode with 64KB segment limits.77947795If neither THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 nor THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in7796ThunkAttributes, then it is assumed that the user code did not enable the A20 mask, and no attempt is made to7797disable the A20 mask.77987799If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is set and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is clear in7800ThunkAttributes, then attempt to use the INT 15 service to disable the A20 mask. If this INT 15 call fails,7801then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.78027803If THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 is clear and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL is set in7804ThunkAttributes, then attempt to disable the A20 mask by directly accessing the 8042 keyboard controller I/O ports.78057806If ThunkContext is NULL, then ASSERT().7807If AsmPrepareThunk16() was not previously called with ThunkContext, then ASSERT().7808If both THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 and THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL are set in7809ThunkAttributes, then ASSERT().78107811This interface is limited to be used in either physical mode or virtual modes with paging enabled where the7812virtual to physical mappings for ThunkContext.RealModeBuffer are mapped 1:1.78137814@param ThunkContext A pointer to the context structure that describes the781516-bit real mode code to call.78167817**/7818VOID7819EFIAPI7820AsmThunk16 (7821IN OUT THUNK_CONTEXT *ThunkContext7822);78237824/**7825Prepares all structures and code for a 16-bit real mode thunk, transfers7826control to a 16-bit real mode entry point, and returns the results.78277828Prepares all structures and code for a 16-bit real mode thunk, transfers7829control to a 16-bit real mode entry point, and returns the results. If the7830caller only need to perform a single 16-bit real mode thunk, then this7831service should be used. If the caller intends to make more than one 16-bit7832real mode thunk, then it is more efficient if AsmPrepareThunk16() is called7833once and AsmThunk16() can be called for each 16-bit real mode thunk.78347835This interface is limited to be used in either physical mode or virtual modes with paging enabled where the7836virtual to physical mappings for ThunkContext.RealModeBuffer is mapped 1:1.78377838See AsmPrepareThunk16() and AsmThunk16() for the detailed description and ASSERT() conditions.78397840@param ThunkContext A pointer to the context structure that describes the784116-bit real mode code to call.78427843**/7844VOID7845EFIAPI7846AsmPrepareAndThunk16 (7847IN OUT THUNK_CONTEXT *ThunkContext7848);78497850/**7851Generates a 16-bit random number through RDRAND instruction.78527853if Rand is NULL, then ASSERT().78547855@param[out] Rand Buffer pointer to store the random result.78567857@retval TRUE RDRAND call was successful.7858@retval FALSE Failed attempts to call RDRAND.78597860**/7861BOOLEAN7862EFIAPI7863AsmRdRand16 (7864OUT UINT16 *Rand7865);78667867/**7868Generates a 32-bit random number through RDRAND instruction.78697870if Rand is NULL, then ASSERT().78717872@param[out] Rand Buffer pointer to store the random result.78737874@retval TRUE RDRAND call was successful.7875@retval FALSE Failed attempts to call RDRAND.78767877**/7878BOOLEAN7879EFIAPI7880AsmRdRand32 (7881OUT UINT32 *Rand7882);78837884/**7885Generates a 64-bit random number through RDRAND instruction.78867887if Rand is NULL, then ASSERT().78887889@param[out] Rand Buffer pointer to store the random result.78907891@retval TRUE RDRAND call was successful.7892@retval FALSE Failed attempts to call RDRAND.78937894**/7895BOOLEAN7896EFIAPI7897AsmRdRand64 (7898OUT UINT64 *Rand7899);79007901/**7902Load given selector into TR register.79037904@param[in] Selector Task segment selector7905**/7906VOID7907EFIAPI7908AsmWriteTr (7909IN UINT16 Selector7910);79117912/**7913Performs a serializing operation on all load-from-memory instructions that7914were issued prior the AsmLfence function.79157916Executes a LFENCE instruction. This function is only available on IA-32 and x64.79177918**/7919VOID7920EFIAPI7921AsmLfence (7922VOID7923);79247925/**7926Executes a XGETBV instruction79277928Executes a XGETBV instruction. This function is only available on IA-32 and7929x64.79307931@param[in] Index Extended control register index79327933@return The current value of the extended control register7934**/7935UINT647936EFIAPI7937AsmXGetBv (7938IN UINT32 Index7939);79407941/**7942Executes a XSETBV instruction to write a 64-bit value to a Extended Control7943Register(XCR), and returns the value.79447945Writes the 64-bit value specified by Value to the XCR specified by Index. The794664-bit value written to the XCR is returned. No parameter checking is7947performed on Index or Value, and some of these may cause CPU exceptions. The7948caller must either guarantee that Index and Value are valid, or the caller7949must establish proper exception handlers. This function is only available on7950IA-32 and x64.79517952@param Index The 32-bit XCR index to write.7953@param Value The 64-bit value to write to the XCR.79547955@return Value79567957**/7958UINT647959EFIAPI7960AsmXSetBv (7961IN UINT32 Index,7962IN UINT64 Value7963);79647965/**7966Executes a VMGEXIT instruction (VMMCALL with a REP prefix)79677968Executes a VMGEXIT instruction. This function is only available on IA-32 and7969x64.79707971**/7972VOID7973EFIAPI7974AsmVmgExit (7975VOID7976);79777978///7979/// The structure used to supply and return data to and from the SVSM.7980///7981typedef struct {7982VOID *Caa;7983UINT64 RaxIn;7984UINT64 RcxIn;7985UINT64 RdxIn;7986UINT64 R8In;7987UINT64 R9In;7988UINT64 RaxOut;7989UINT64 RcxOut;7990UINT64 RdxOut;7991UINT64 R8Out;7992UINT64 R9Out;7993UINT8 *CallPending;7994} SVSM_CALL_DATA;79957996/**7997Executes a VMGEXIT instruction (VMMCALL with a REP prefix) with arguments7998and return code79998000Executes a VMGEXIT instruction placing the specified arguments in the8001corresponding registers before invocation. Upon return an XCHG is done to8002atomically clear and retrieve the SVSM call pending value. The returned RAX8003register value becomes the function return code. This function is intended8004for use with an SVSM. This function is only available on IA-32 and x64.80058006@param[in,out] SvsmCallPending Pointer to the location of the SVSM call data80078008@return Value of the RAX register on return80098010**/8011UINT328012EFIAPI8013AsmVmgExitSvsm (8014IN OUT SVSM_CALL_DATA *SvsmCallData8015);80168017/**8018Patch the immediate operand of an IA32 or X64 instruction such that the byte,8019word, dword or qword operand is encoded at the end of the instruction's8020binary representation.80218022This function should be used to update object code that was compiled with8023NASM from assembly source code. Example:80248025NASM source code:80268027mov eax, strict dword 0 ; the imm32 zero operand will be patched8028ASM_PFX(gPatchCr3):8029mov cr3, eax80308031C source code:80328033X86_ASSEMBLY_PATCH_LABEL gPatchCr3;8034PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4);80358036@param[out] InstructionEnd Pointer right past the instruction to patch. The8037immediate operand to patch is expected to8038comprise the trailing bytes of the instruction.8039If InstructionEnd is closer to address 0 than8040ValueSize permits, then ASSERT().80418042@param[in] PatchValue The constant to write to the immediate operand.8043The caller is responsible for ensuring that8044PatchValue can be represented in the byte, word,8045dword or qword operand (as indicated through8046ValueSize); otherwise ASSERT().80478048@param[in] ValueSize The size of the operand in bytes; must be 1, 2,80494, or 8. ASSERT() otherwise.8050**/8051VOID8052EFIAPI8053PatchInstructionX86 (8054OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd,8055IN UINT64 PatchValue,8056IN UINTN ValueSize8057);80588059#endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)8060#endif // !defined (__BASE_LIB__)806180628063