TianoCore EDK2 master
Loading...
Searching...
No Matches
UnitTestHostBaseLib.h File Reference

Go to the source code of this file.

Data Structures

struct  UNIT_TEST_HOST_BASE_LIB_COMMON
 
struct  UNIT_TEST_HOST_BASE_LIB_X86
 
struct  UNIT_TEST_HOST_BASE_LIB
 

Typedefs

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_VOID) (VOID)
 
typedef BOOLEAN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_READ_BOOLEAN) (VOID)
 
typedef UINT16(EFIAPI * UNIT_TEST_HOST_BASE_LIB_READ_UINT16) (VOID)
 
typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_READ_UINTN) (VOID)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_WRITE_UINT16) (IN UINT16 Value)
 
typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_WRITE_UINTN) (IN UINTN Value)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_READ_IA32_DESCRIPTOR) (OUT IA32_DESCRIPTOR *Ia32Descriptor)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_WRITE_IA32_DESCRIPTOR) (IN CONST IA32_DESCRIPTOR *Ia32Descriptor)
 
typedef UINT32(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_CPUID) (IN UINT32 Index, OUT UINT32 *Eax OPTIONAL, OUT UINT32 *Ebx OPTIONAL, OUT UINT32 *Ecx OPTIONAL, OUT UINT32 *Edx OPTIONAL)
 
typedef UINT32(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_CPUID_EX) (IN UINT32 Index, IN UINT32 SubIndex, OUT UINT32 *Eax OPTIONAL, OUT UINT32 *Ebx OPTIONAL, OUT UINT32 *Ecx OPTIONAL, OUT UINT32 *Edx OPTIONAL)
 
typedef UINT64(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_READ_MSR_64) (IN UINT32 Index)
 
typedef UINT64(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_WRITE_MSR_64) (IN UINT32 Index, IN UINT64 Value)
 
typedef UINT64(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_READ_PMC) (IN UINT32 Index)
 
typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_MONITOR) (IN UINTN Eax, IN UINTN Ecx, IN UINTN Edx)
 
typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_MWAIT) (IN UINTN Eax, IN UINTN Ecx)
 
typedef VOID *(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_FLUSH_CACHE_LINE) (IN VOID *LinearAddress)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_PAGING_32) (IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL, IN VOID *NewStack)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_ENABLE_PAGING_64) (IN UINT16 Cs, IN UINT64 EntryPoint, IN UINT64 Context1 OPTIONAL, IN UINT64 Context2 OPTIONAL, IN UINT64 NewStack)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_DISABLE_PAGING_64) (IN UINT16 Cs, IN UINT32 EntryPoint, IN UINT32 Context1 OPTIONAL, IN UINT32 Context2 OPTIONAL, IN UINT32 NewStack)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_GET_THUNK_16_PROPERTIES) (OUT UINT32 *RealModeBufferSize, OUT UINT32 *ExtraStackSize)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_THUNK_16) (IN OUT THUNK_CONTEXT *ThunkContext)
 
typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_PATCH_INSTRUCTION_X86) (OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd, IN UINT64 PatchValue, IN UINTN ValueSize)
 

Variables

UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib
 

Detailed Description

Unit Test Host BaseLib hooks.

Copyright (c) 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file UnitTestHostBaseLib.h.

Typedef Documentation

◆ UNIT_TEST_HOST_BASE_LIB_ASM_CPUID

typedef UINT32(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_CPUID) (IN UINT32 Index, OUT UINT32 *Eax OPTIONAL, OUT UINT32 *Ebx OPTIONAL, OUT UINT32 *Ecx OPTIONAL, OUT UINT32 *Edx OPTIONAL)

Retrieves CPUID information.

Executes the CPUID instruction with EAX set to the value specified by Index. This function always returns Index. If Eax is not NULL, then the value of EAX after CPUID is returned in Eax. If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx. If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx. If Edx is not NULL, then the value of EDX after CPUID is returned in Edx. This function is only available on IA-32 and x64.

Parameters
IndexThe 32-bit value to load into EAX prior to invoking the CPUID instruction.
EaxThe pointer to the 32-bit EAX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
EbxThe pointer to the 32-bit EBX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
EcxThe pointer to the 32-bit ECX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
EdxThe pointer to the 32-bit EDX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
Returns
Index.

Definition at line 128 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_CPUID_EX

typedef UINT32(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_CPUID_EX) (IN UINT32 Index, IN UINT32 SubIndex, OUT UINT32 *Eax OPTIONAL, OUT UINT32 *Ebx OPTIONAL, OUT UINT32 *Ecx OPTIONAL, OUT UINT32 *Edx OPTIONAL)

Retrieves CPUID information using an extended leaf identifier.

Executes the CPUID instruction with EAX set to the value specified by Index and ECX set to the value specified by SubIndex. This function always returns Index. This function is only available on IA-32 and x64.

If Eax is not NULL, then the value of EAX after CPUID is returned in Eax. If Ebx is not NULL, then the value of EBX after CPUID is returned in Ebx. If Ecx is not NULL, then the value of ECX after CPUID is returned in Ecx. If Edx is not NULL, then the value of EDX after CPUID is returned in Edx.

Parameters
IndexThe 32-bit value to load into EAX prior to invoking the CPUID instruction.
SubIndexThe 32-bit value to load into ECX prior to invoking the CPUID instruction.
EaxThe pointer to the 32-bit EAX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
EbxThe pointer to the 32-bit EBX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
EcxThe pointer to the 32-bit ECX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
EdxThe pointer to the 32-bit EDX value returned by the CPUID instruction. This is an optional parameter that may be NULL.
Returns
Index.

Definition at line 170 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_DISABLE_PAGING_64

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_DISABLE_PAGING_64) (IN UINT16 Cs, IN UINT32 EntryPoint, IN UINT32 Context1 OPTIONAL, IN UINT32 Context2 OPTIONAL, IN UINT32 NewStack)

Disables the 64-bit paging mode on the CPU.

Disables the 64-bit paging mode on the CPU and returns to 32-bit protected mode. This function assumes the current execution mode is 64-paging mode. This function is only available on x64. After the 64-bit paging mode is disabled, control is transferred to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and may be 0. The function EntryPoint must never return.

If the current execution mode is not 64-bit paged mode, then ASSERT(). If EntryPoint is 0, then ASSERT(). If NewStack is 0, then ASSERT().

Parameters
CsThe 16-bit selector to load in the CS before EntryPoint is called. The descriptor in the GDT that this selector references must be setup for 32-bit protected mode.
EntryPointThe 64-bit virtual address of the function to call with the new stack after paging is disabled.
Context1The 64-bit virtual address of the context to pass into the EntryPoint function as the first parameter after paging is disabled.
Context2The 64-bit virtual address of the context to pass into the EntryPoint function as the second parameter after paging is disabled.
NewStackThe 64-bit virtual address of the new stack to use for the EntryPoint function after paging is disabled.

Definition at line 402 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_ENABLE_PAGING_64

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_ENABLE_PAGING_64) (IN UINT16 Cs, IN UINT64 EntryPoint, IN UINT64 Context1 OPTIONAL, IN UINT64 Context2 OPTIONAL, IN UINT64 NewStack)

Enables the 64-bit paging mode on the CPU.

Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables must be properly initialized prior to calling this service. This function assumes the current execution mode is 32-bit protected mode with flat descriptors. This function is only available on IA-32. After the 64-bit paging mode is enabled, control is transferred to the function specified by EntryPoint using the new stack specified by NewStack and passing in the parameters specified by Context1 and Context2. Context1 and Context2 are optional and may be 0. The function EntryPoint must never return.

If the current execution mode is not 32-bit protected mode with flat descriptors, then ASSERT(). If EntryPoint is 0, then ASSERT(). If NewStack is 0, then ASSERT().

Parameters
CsThe 16-bit selector to load in the CS before EntryPoint is called. The descriptor in the GDT that this selector references must be setup for long mode.
EntryPointThe 64-bit virtual address of the function to call with the new stack after paging is enabled.
Context1The 64-bit virtual address of the context to pass into the EntryPoint function as the first parameter after paging is enabled.
Context2The 64-bit virtual address of the context to pass into the EntryPoint function as the second parameter after paging is enabled.
NewStackThe 64-bit virtual address of the new stack to use for the EntryPoint function after paging is enabled.

Definition at line 362 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_FLUSH_CACHE_LINE

typedef VOID *(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_FLUSH_CACHE_LINE) (IN VOID *LinearAddress)

Flushes a cache line from all the instruction and data caches within the coherency domain of the CPU.

Flushed the cache line specified by LinearAddress, and returns LinearAddress. This function is only available on IA-32 and x64.

Parameters
LinearAddressThe address of the cache line to flush. If the CPU is in a physical addressing mode, then LinearAddress is a physical address. If the CPU is in a virtual addressing mode, then LinearAddress is a virtual address.
Returns
LinearAddress.

Definition at line 302 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_GET_THUNK_16_PROPERTIES

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_GET_THUNK_16_PROPERTIES) (OUT UINT32 *RealModeBufferSize, OUT UINT32 *ExtraStackSize)

Retrieves the properties for 16-bit thunk functions.

Computes the size of the buffer and stack below 1MB required to use the AsmPrepareThunk16(), AsmThunk16() and AsmPrepareAndThunk16() functions. This buffer size is returned in RealModeBufferSize, and the stack size is returned in ExtraStackSize. If parameters are passed to the 16-bit real mode code, then the actual minimum stack size is ExtraStackSize plus the maximum number of bytes that need to be passed to the 16-bit real mode code.

If RealModeBufferSize is NULL, then ASSERT(). If ExtraStackSize is NULL, then ASSERT().

Parameters
RealModeBufferSizeA pointer to the size of the buffer below 1MB required to use the 16-bit thunk functions.
ExtraStackSizeA pointer to the extra size of stack below 1MB that the 16-bit thunk functions require for temporary storage in the transition to and from 16-bit real mode.

Definition at line 433 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_MONITOR

typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_MONITOR) (IN UINTN Eax, IN UINTN Ecx, IN UINTN Edx)

Sets up a monitor buffer that is used by AsmMwait().

Executes a MONITOR instruction with the register state specified by Eax, Ecx and Edx. Returns Eax. This function is only available on IA-32 and x64.

Parameters
EaxThe value to load into EAX or RAX before executing the MONITOR instruction.
EcxThe value to load into ECX or RCX before executing the MONITOR instruction.
EdxThe value to load into EDX or RDX before executing the MONITOR instruction.
Returns
Eax

Definition at line 258 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_MWAIT

typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_MWAIT) (IN UINTN Eax, IN UINTN Ecx)

Executes an MWAIT instruction.

Executes an MWAIT instruction with the register state specified by Eax and Ecx. Returns Eax. This function is only available on IA-32 and x64.

Parameters
EaxThe value to load into EAX or RAX before executing the MONITOR instruction.
EcxThe value to load into ECX or RCX before executing the MONITOR instruction.
Returns
Eax

Definition at line 280 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_PAGING_32

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_PAGING_32) (IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL, IN VOID *NewStack)

Prototype of service that enables ot disables 32-bit paging modes.

Parameters
EntryPointA pointer to function to call with the new stack after paging is enabled.
Context1A pointer to the context to pass into the EntryPoint function as the first parameter after paging is enabled.
Context2A pointer to the context to pass into the EntryPoint function as the second parameter after paging is enabled.
NewStackA pointer to the new stack to use for the EntryPoint function after paging is enabled.

Definition at line 321 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_PATCH_INSTRUCTION_X86

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_PATCH_INSTRUCTION_X86) (OUT X86_ASSEMBLY_PATCH_LABEL *InstructionEnd, IN UINT64 PatchValue, IN UINTN ValueSize)

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);

Parameters
[out]InstructionEndPointer 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().
[in]PatchValueThe 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().
[in]ValueSizeThe size of the operand in bytes; must be 1, 2, 4, or 8. ASSERT() otherwise.

Definition at line 487 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_READ_IA32_DESCRIPTOR

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_READ_IA32_DESCRIPTOR) (OUT IA32_DESCRIPTOR *Ia32Descriptor)

Prototype of service that reads and returns an IA32_DESCRIPTOR.

Parameters
[out]Ia32DescriptorPointer to the descriptor read.

Definition at line 86 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_READ_MSR_64

typedef UINT64(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_READ_MSR_64) (IN UINT32 Index)

Returns a 64-bit Machine Specific Register(MSR).

Reads and returns the 64-bit MSR specified by Index. No parameter checking is performed on Index, and some Index values may cause CPU exceptions. The caller must either guarantee that Index is valid, or the caller must set up exception handlers to catch the exceptions. This function is only available on IA-32 and x64.

Parameters
IndexThe 32-bit MSR index to read.
Returns
The value of the MSR identified by Index.

Definition at line 195 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_READ_PMC

typedef UINT64(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_READ_PMC) (IN UINT32 Index)

Reads the current value of a Performance Counter (PMC).

Reads and returns the current value of performance counter specified by Index. This function is only available on IA-32 and x64.

Parameters
IndexThe 32-bit Performance Counter index to read.
Returns
The value of the PMC specified by Index.

Definition at line 236 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_THUNK_16

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_THUNK_16) (IN OUT THUNK_CONTEXT *ThunkContext)

Prototype of services that operates on a THUNK_CONTEXT structure.

Parameters
ThunkContextA pointer to the context structure that describes the 16-bit real mode code to call.

Definition at line 447 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_WRITE_IA32_DESCRIPTOR

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_WRITE_IA32_DESCRIPTOR) (IN CONST IA32_DESCRIPTOR *Ia32Descriptor)

Prototype of service that writes an IA32_DESCRIPTOR.

Parameters
[in]Ia32DescriptorPointer to the descriptor to write.

Definition at line 97 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_ASM_WRITE_MSR_64

typedef UINT64(EFIAPI * UNIT_TEST_HOST_BASE_LIB_ASM_WRITE_MSR_64) (IN UINT32 Index, IN UINT64 Value)

Writes a 64-bit value to a Machine Specific Register(MSR), and returns the value.

Writes the 64-bit value specified by Value to the MSR specified by Index. The 64-bit value written to the MSR is returned. No parameter checking is performed on Index or Value, and some of these may cause CPU exceptions. The caller must either guarantee that Index and Value are valid, or the caller must establish proper exception handlers. This function is only available on IA-32 and x64.

Parameters
IndexThe 32-bit MSR index to write.
ValueThe 64-bit value to write to the MSR.
Returns
Value

Definition at line 218 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_READ_BOOLEAN

typedef BOOLEAN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_READ_BOOLEAN) (VOID)

Prototype of service that reads and returns a BOOLEAN value.

Returns
The value read.

Definition at line 27 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_READ_UINT16

typedef UINT16(EFIAPI * UNIT_TEST_HOST_BASE_LIB_READ_UINT16) (VOID)

Prototype of service that reads and returns a UINT16 value.

Returns
The value read.

Definition at line 38 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_READ_UINTN

typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_READ_UINTN) (VOID)

Prototype of service that reads and returns a UINTN value.

Returns
The value read.

Definition at line 49 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_VOID

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_VOID) (VOID)

Prototype of service with no parameters and no return value.

Definition at line 16 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_WRITE_UINT16

typedef VOID(EFIAPI * UNIT_TEST_HOST_BASE_LIB_WRITE_UINT16) (IN UINT16 Value)

Prototype of service that writes and returns a UINT16 value.

Parameters
[in]ValueThe value to write.
Returns
The value written.

Definition at line 62 of file UnitTestHostBaseLib.h.

◆ UNIT_TEST_HOST_BASE_LIB_WRITE_UINTN

typedef UINTN(EFIAPI * UNIT_TEST_HOST_BASE_LIB_WRITE_UINTN) (IN UINTN Value)

Prototype of service that writes and returns a UINTN value.

Parameters
[in]ValueThe value to write.
Returns
The value written.

Definition at line 75 of file UnitTestHostBaseLib.h.

Variable Documentation

◆ gUnitTestHostBaseLib

UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib
extern

Structure of hook functions for BaseLib functions that can not be used from a host application. A simple emulation of these function is provided by default. A specific unit test can provide its own implementation for any of these functions.

Definition at line 2995 of file X86UnitTestHost.c.