前置步骤:
- 准备
UEFI
实验环境教程:搭建edk2编译环境
UEFI
官方技术参考手册
HOB(Hand-Off Block)
是一个通用的结构体类型:MdePkg/Include/Pi/PiHob.h
///
/// Describes the format and size of the data inside the HOB.
/// All HOBs must contain this generic HOB header.
///
typedef struct {
///
/// Identifies the HOB data structure type.
///
UINT16 HobType;
///
/// The length in bytes of the HOB.
///
UINT16 HobLength;
///
/// This field must always be set to zero.
///
UINT32 Reserved;
} EFI_HOB_GENERIC_HEADER;
EFI_HOB_GENERIC_HEADER
是所有HOB
结构的通用头部,它包含了HOB
的类型、长度以及指向下一个HOB
的指针
除了通用头部,具体的HOB
数据结构根据HobType
的不同会有不同的定义
EFI_HOB_HANDOFF_INFO_TABLE
用于描述HOB
列表的起始信息,通常是第一个HOB
,用于传递PEI
到DXE
的过渡信息:MdePkg/Include/Pi/PiHob.h
///
/// Contains general state information used by the HOB producer phase.
/// This HOB must be the first one in the HOB list.
///
typedef struct {
///
/// The HOB generic header. Header.HobType = EFI_HOB_TYPE_HANDOFF.
///
EFI_HOB_GENERIC_HEADER Header;
///
/// The version number pertaining to the PHIT HOB definition.
/// This value is four bytes in length to provide an 8-byte aligned entry
/// when it is combined with the 4-byte BootMode.
///
UINT32 Version;
///
/// The system boot mode as determined during the HOB producer phase.
///
EFI_BOOT_MODE BootMode;
///
/// The highest address location of memory that is allocated for use by the HOB producer
/// phase. This address must be 4-KB aligned to meet page restrictions of UEFI.
///
EFI_PHYSICAL_ADDRESS EfiMemoryTop;
///
/// The lowest address location of memory that is allocated for use by the HOB producer phase.
///
EFI_PHYSICAL_ADDRESS EfiMemoryBottom;
///
/// The highest address location of free memory that is currently available
/// for use by the HOB producer phase.
///
EFI_PHYSICAL_ADDRESS EfiFreeMemoryTop;
///
/// The lowest address location of free memory that is available for use by the HOB producer phase.
///
EFI_PHYSICAL_ADDRESS EfiFreeMemoryBottom;
///
/// The end of the HOB list.
///
EFI_PHYSICAL_ADDRESS EfiEndOfHobList;
} EFI_HOB_HANDOFF_INFO_TABLE;
EFI_HOB_MEMORY_ALLOCATION
描述内存分配情况的HOB
,用于报告已分配的内存范围:MdePkg/Include/Pi/PiHob.h
///
/// Describes all memory ranges used during the HOB producer
/// phase that exist outside the HOB list. This HOB type
/// describes how memory is used, not the physical attributes of memory.
///
typedef struct {
///
/// The HOB generic header. Header.HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION.
///
EFI_HOB_GENERIC_HEADER Header;
///
/// An instance of the EFI_HOB_MEMORY_ALLOCATION_HEADER that describes the
/// various attributes of the logical memory allocation.
///
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor;
//
// Additional data pertaining to the "Name" Guid memory
// may go here.
//
} EFI_HOB_MEMORY_ALLOCATION;
EFI_HOB_GUID_TYPE
这是一个通用的HOB
类型,用于存储自定义数据。它由GUID
标识并携带特定数据
///
/// Allows writers of executable content in the HOB producer phase to
/// maintain and manage HOBs with specific GUID.
///
typedef struct {
///
/// The HOB generic header. Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION.
///
EFI_HOB_GENERIC_HEADER Header;
///
/// A GUID that defines the contents of this HOB.
///
EFI_GUID Name;
//
// Guid specific data goes here
//
} EFI_HOB_GUID_TYPE;
每个
HOB
元素通过EFI_HOB_GENERIC_HEADER
中的HobLength
字段进行计算,找到下一个HOB
的位置,终止HOB
为EFI_HOB_TYPE_END_OF_HOB_LIST
类型// // HobType of EFI_HOB_GENERIC_HEADER. // #define EFI_HOB_TYPE_HANDOFF 0x0001 #define EFI_HOB_TYPE_MEMORY_ALLOCATION 0x0002 #define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR 0x0003 #define EFI_HOB_TYPE_GUID_EXTENSION 0x0004 #define EFI_HOB_TYPE_FV 0x0005 #define EFI_HOB_TYPE_CPU 0x0006 #define EFI_HOB_TYPE_MEMORY_POOL 0x0007 #define EFI_HOB_TYPE_FV2 0x0009 #define EFI_HOB_TYPE_LOAD_PEIM_UNUSED 0x000A #define EFI_HOB_TYPE_UEFI_CAPSULE 0x000B #define EFI_HOB_TYPE_FV3 0x000C #define EFI_HOB_TYPE_UNUSED 0xFFFE #define EFI_HOB_TYPE_END_OF_HOB_LIST 0xFFFF
在MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
中有一段代码:
/**
Main entry point to DXE Core.
@param HobStart Pointer to the beginning of the HOB List from PEI.
@return This function should never return.
**/
VOID
EFIAPI
DxeMain (
IN VOID *HobStart // 由PEI阶段传递的HOB(Handoff Block)列表开始地址
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS MemoryBaseAddress;
UINT64 MemoryLength;
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
UINTN Index;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_VECTOR_HANDOFF_INFO *VectorInfoList;
EFI_VECTOR_HANDOFF_INFO *VectorInfo;
VOID *EntryPoint;
//
// Setup the default exception handlers
//
VectorInfoList = NULL;
GuidHob = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
//
}
此处的gEfiVectorHandoffInfoPpiGuid
位置:MdePkg/MdePkg.dec
[Ppis]
## Include/Ppi/VectorHandoffInfo.h
gEfiVectorHandoffInfoPpiGuid = { 0x3cd652b4, 0x6d33, 0x4dce, { 0x89, 0xdb, 0x83, 0xdf, 0x97, 0x66, 0xfc, 0xca }}
由此可知,gEfiVectorHandoffInfoPpiGuid
为PPI GUID
,PPI
接口头文件路径:Include/Ppi/VectorHandoffInfo.h
在MdePkg/Include/Ppi/VectorHandoffInfo.h
进行访问该PPI GUID
extern EFI_GUID gEfiVectorHandoffInfoPpiGuid;
在其中查看该PPI
接口:MdePkg/Include/Ppi/VectorHandoffInfo.h
///
/// EFI_VECTOR_HANDOFF_INFO entries that describes the interrupt and/or
/// exception vectors in use in the PEI Phase.
///
typedef struct {
//
// The interrupt or exception vector that is in use and must be preserved.
//
UINT32 VectorNumber;
//
// A bitmask that describes the attributes of the interrupt or exception vector.
//
UINT32 Attribute;
//
// The GUID identifies the party who created the entry. For the
// EFI_VECTOR_HANDOFF_DO_NOT_HOOK case, this establishes the single owner.
//
EFI_GUID Owner;
} EFI_VECTOR_HANDOFF_INFO;
///
/// Provides a description of the interrupt and/or exception vectors that
/// were established in the SEC Phase and need to persist into PEI and DXE.
///
typedef struct _EFI_PEI_VECTOR_HANDOFF_INFO_PPI {
//
// Pointer to an array of interrupt and /or exception vectors.
//
EFI_VECTOR_HANDOFF_INFO *Info;
} EFI_PEI_VECTOR_HANDOFF_INFO_PPI;
EFI_PEI_VECTOR_HANDOFF_INFO_PPI
的作用为:将向量表信息从PEI
阶段传递到DXE
阶段,用于在不同固件阶段之间传递与中断向量相关的信息