X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FInclude%2FLibrary%2FBaseLib.h;h=eb2899f8524e7a8e1856d68f0c25ced58c4253fb;hp=11e9c74b58eb8b5f4adc71648f639ea956658dfd;hb=8596c140907ebfeabf62427686280666a4e04893;hpb=47595ac0b96aaa18246ac1be4a238893dd0aa0fe diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 11e9c74b58..eb2899f852 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -1119,7 +1119,7 @@ StrnCpy ( IN CONST CHAR16 *Source, IN UINTN Length ); -#endif +#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES) /** Returns the length of a Null-terminated Unicode string. @@ -1338,7 +1338,7 @@ StrnCat ( IN CONST CHAR16 *Source, IN UINTN Length ); -#endif +#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES) /** Returns the first occurrence of a Null-terminated Unicode sub-string @@ -1811,7 +1811,7 @@ UnicodeStrToAsciiStr ( OUT CHAR8 *Destination ); -#endif +#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES) /** Convert a Null-terminated Unicode string to a Null-terminated @@ -1985,7 +1985,7 @@ AsciiStrnCpy ( IN CONST CHAR8 *Source, IN UINTN Length ); -#endif +#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES) /** Returns the length of a Null-terminated ASCII string. @@ -2229,7 +2229,7 @@ AsciiStrnCat ( IN CONST CHAR8 *Source, IN UINTN Length ); -#endif +#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES) /** Returns the first occurrence of a Null-terminated ASCII sub-string @@ -2670,7 +2670,7 @@ AsciiStrToUnicodeStr ( OUT CHAR16 *Destination ); -#endif +#endif // !defined (DISABLE_NEW_DEPRECATED_INTERFACES) /** Convert one Null-terminated ASCII string to a Null-terminated @@ -4903,6 +4903,7 @@ MemoryFence ( @retval 0 Indicates a return from SetJump(). **/ +RETURNS_TWICE UINTN EFIAPI SetJump ( @@ -6494,7 +6495,7 @@ AsmPalCall ( IN UINT64 Arg3, IN UINT64 Arg4 ); -#endif +#endif // defined (MDE_CPU_IPF) #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) /// @@ -6672,41 +6673,41 @@ typedef union { typedef struct { UINT16 PreviousTaskLink; UINT16 Reserved_2; - UINT32 Esp0; - UINT16 Ss0; + UINT32 ESP0; + UINT16 SS0; UINT16 Reserved_10; - UINT32 Esp1; - UINT16 Ss1; + UINT32 ESP1; + UINT16 SS1; UINT16 Reserved_18; - UINT32 Esp2; - UINT16 Ss2; + UINT32 ESP2; + UINT16 SS2; UINT16 Reserved_26; - UINT32 Cr3; - UINT32 Eip; - UINT32 Eflags; - UINT32 Eax; - UINT32 Ecx; - UINT32 Edx; - UINT32 Ebx; - UINT32 Esp; - UINT32 Ebp; - UINT32 Esi; - UINT32 Edi; - UINT16 Es; + UINT32 CR3; + UINT32 EIP; + UINT32 EFLAGS; + UINT32 EAX; + UINT32 ECX; + UINT32 EDX; + UINT32 EBX; + UINT32 ESP; + UINT32 EBP; + UINT32 ESI; + UINT32 EDI; + UINT16 ES; UINT16 Reserved_74; - UINT16 Cs; + UINT16 CS; UINT16 Reserved_78; - UINT16 Ss; + UINT16 SS; UINT16 Reserved_82; - UINT16 Ds; + UINT16 DS; UINT16 Reserved_86; - UINT16 Fs; + UINT16 FS; UINT16 Reserved_90; - UINT16 Gs; + UINT16 GS; UINT16 Reserved_94; UINT16 LDTSegmentSelector; UINT16 Reserved_98; - UINT16 Tflag; + UINT16 T; UINT16 IOMapBaseAddress; } IA32_TASK_STATE_SEGMENT; @@ -6717,19 +6718,19 @@ typedef union { UINT32 BaseMid:8; ///< Base Address 23..16 UINT32 Type:4; ///< Type (1 0 B 1) UINT32 Reserved_43:1; ///< 0 - UINT32 Dpl:2; ///< Descriptor Privilege Level - UINT32 Present:1; ///< Segment Present + UINT32 DPL:2; ///< Descriptor Privilege Level + UINT32 P:1; ///< Segment Present UINT32 LimitHigh:4; ///< Segment Limit 19..16 - UINT32 Avl:1; ///< Available for use by system software + UINT32 AVL:1; ///< Available for use by system software UINT32 Reserved_52:2; ///< 0 0 - UINT32 Granularity:1; ///< Granularity + UINT32 G:1; ///< Granularity UINT32 BaseHigh:8; ///< Base Address 31..24 } Bits; UINT64 Uint64; } IA32_TSS_DESCRIPTOR; #pragma pack () -#endif +#endif // defined (MDE_CPU_IA32) #if defined (MDE_CPU_X64) /// @@ -6757,11 +6758,11 @@ typedef union { // typedef struct { UINT32 Reserved_0; - UINT64 Rsp0; - UINT64 Rsp1; - UINT64 Rsp2; + UINT64 RSP0; + UINT64 RSP1; + UINT64 RSP2; UINT64 Reserved_28; - UINT64 Ist[7]; + UINT64 IST[7]; UINT64 Reserved_92; UINT16 Reserved_100; UINT16 IOMapBaseAddress; @@ -6774,12 +6775,12 @@ typedef union { UINT32 BaseMidl:8; ///< Base Address 23..16 UINT32 Type:4; ///< Type (1 0 B 1) UINT32 Reserved_43:1; ///< 0 - UINT32 Dpl:2; ///< Descriptor Privilege Level - UINT32 Present:1; ///< Segment Present + UINT32 DPL:2; ///< Descriptor Privilege Level + UINT32 P:1; ///< Segment Present UINT32 LimitHigh:4; ///< Segment Limit 19..16 - UINT32 Avl:1; ///< Available for use by system software + UINT32 AVL:1; ///< Available for use by system software UINT32 Reserved_52:2; ///< 0 0 - UINT32 Granularity:1; ///< Granularity + UINT32 G:1; ///< Granularity UINT32 BaseMidh:8; ///< Base Address 31..24 UINT32 BaseHigh:32; ///< Base Address 63..32 UINT32 Reserved_96:32; ///< Reserved @@ -6791,7 +6792,7 @@ typedef union { } IA32_TSS_DESCRIPTOR; #pragma pack () -#endif +#endif // defined (MDE_CPU_X64) /// /// Byte packed structure for an FP/SSE/SSE2 context. @@ -6880,6 +6881,20 @@ typedef struct { #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15 0x00000002 #define THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL 0x00000004 +/// +/// Type definition for representing labels in NASM source code that allow for +/// the patching of immediate operands of IA32 and X64 instructions. +/// +/// While the type is technically defined as a function type (note: not a +/// pointer-to-function type), such labels in NASM source code never stand for +/// actual functions, and identifiers declared with this function type should +/// never be called. This is also why the EFIAPI calling convention specifier +/// is missing from the typedef, and why the typedef does not follow the usual +/// edk2 coding style for function (or pointer-to-function) typedefs. The VOID +/// return type and the VOID argument list are merely artifacts. +/// +typedef VOID (X86_ASSEMBLY_PATCH_LABEL) (VOID); + /** Retrieves CPUID information. @@ -9067,7 +9082,47 @@ AsmWriteTr ( IN UINT16 Selector ); -#endif -#endif +/** + Patch the immediate operand of an IA32 or X64 instruction such that the byte, + word, dword or qword operand is encoded at the end of the instruction's + binary representation. + + This function should be used to update object code that was compiled with + NASM from assembly source code. Example: + + NASM source code: + mov eax, strict dword 0 ; the imm32 zero operand will be patched + ASM_PFX(gPatchCr3): + mov cr3, eax + + C source code: + + X86_ASSEMBLY_PATCH_LABEL gPatchCr3; + PatchInstructionX86 (gPatchCr3, AsmReadCr3 (), 4); + + @param[out] InstructionEnd Pointer right past the instruction to patch. The + immediate operand to patch is expected to + comprise the trailing bytes of the instruction. + If InstructionEnd is closer to address 0 than + ValueSize permits, then ASSERT(). + + @param[in] PatchValue The constant to write to the immediate operand. + The caller is responsible for ensuring that + PatchValue can be represented in the byte, word, + dword or qword operand (as indicated through + ValueSize); otherwise ASSERT(). + + @param[in] ValueSize The size of the operand in bytes; must be 1, 2, + 4, or 8. ASSERT() otherwise. +**/ +VOID +EFIAPI +PatchInstructionX86 ( + OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd, + IN UINT64 PatchValue, + IN UINTN ValueSize + ); +#endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) +#endif // !defined (__BASE_LIB__)