UEFI(2):PPI和HOB列表(PEI->DXE)

打印 上一主题 下一主题

主题 548|帖子 548|积分 1654

前置步调:


  • 准备UEFI实验环境教程:搭建edk2编译环境
  • UEFI官方技术参考手册
HOB(Hand-Off Block)是一个通用的布局体类型:MdePkg/Include/Pi/PiHob.h
  1. ///
  2. /// Describes the format and size of the data inside the HOB.
  3. /// All HOBs must contain this generic HOB header.
  4. ///
  5. typedef struct {
  6.   ///
  7.   /// Identifies the HOB data structure type.
  8.   ///
  9.   UINT16    HobType;
  10.   ///
  11.   /// The length in bytes of the HOB.
  12.   ///
  13.   UINT16    HobLength;
  14.   ///
  15.   /// This field must always be set to zero.
  16.   ///
  17.   UINT32    Reserved;
  18. } 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
  1. ///
  2. /// Contains general state information used by the HOB producer phase.
  3. /// This HOB must be the first one in the HOB list.
  4. ///
  5. typedef struct {
  6.   ///
  7.   /// The HOB generic header. Header.HobType = EFI_HOB_TYPE_HANDOFF.
  8.   ///
  9.   EFI_HOB_GENERIC_HEADER    Header;
  10.   ///
  11.   /// The version number pertaining to the PHIT HOB definition.
  12.   /// This value is four bytes in length to provide an 8-byte aligned entry
  13.   /// when it is combined with the 4-byte BootMode.
  14.   ///
  15.   UINT32                    Version;
  16.   ///
  17.   /// The system boot mode as determined during the HOB producer phase.
  18.   ///
  19.   EFI_BOOT_MODE             BootMode;
  20.   ///
  21.   /// The highest address location of memory that is allocated for use by the HOB producer
  22.   /// phase. This address must be 4-KB aligned to meet page restrictions of UEFI.
  23.   ///
  24.   EFI_PHYSICAL_ADDRESS      EfiMemoryTop;
  25.   ///
  26.   /// The lowest address location of memory that is allocated for use by the HOB producer phase.
  27.   ///
  28.   EFI_PHYSICAL_ADDRESS      EfiMemoryBottom;
  29.   ///
  30.   /// The highest address location of free memory that is currently available
  31.   /// for use by the HOB producer phase.
  32.   ///
  33.   EFI_PHYSICAL_ADDRESS      EfiFreeMemoryTop;
  34.   ///
  35.   /// The lowest address location of free memory that is available for use by the HOB producer phase.
  36.   ///
  37.   EFI_PHYSICAL_ADDRESS      EfiFreeMemoryBottom;
  38.   ///
  39.   /// The end of the HOB list.
  40.   ///
  41.   EFI_PHYSICAL_ADDRESS      EfiEndOfHobList;
  42. } EFI_HOB_HANDOFF_INFO_TABLE;
复制代码
EFI_HOB_MEMORY_ALLOCATION
描述内存分配环境的HOB,用于报告已分配的内存范围:MdePkg/Include/Pi/PiHob.h
  1. ///
  2. /// Describes all memory ranges used during the HOB producer
  3. /// phase that exist outside the HOB list. This HOB type
  4. /// describes how memory is used, not the physical attributes of memory.
  5. ///
  6. typedef struct {
  7.   ///
  8.   /// The HOB generic header. Header.HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION.
  9.   ///
  10.   EFI_HOB_GENERIC_HEADER              Header;
  11.   ///
  12.   /// An instance of the EFI_HOB_MEMORY_ALLOCATION_HEADER that describes the
  13.   /// various attributes of the logical memory allocation.
  14.   ///
  15.   EFI_HOB_MEMORY_ALLOCATION_HEADER    AllocDescriptor;
  16.   //
  17.   // Additional data pertaining to the "Name" Guid memory
  18.   // may go here.
  19.   //
  20. } EFI_HOB_MEMORY_ALLOCATION;
复制代码
EFI_HOB_GUID_TYPE
这是一个通用的HOB类型,用于存储自定义数据。它由GUID标识并携带特定数据
  1. ///
  2. /// Allows writers of executable content in the HOB producer phase to
  3. /// maintain and manage HOBs with specific GUID.
  4. ///
  5. typedef struct {
  6.   ///
  7.   /// The HOB generic header. Header.HobType = EFI_HOB_TYPE_GUID_EXTENSION.
  8.   ///
  9.   EFI_HOB_GENERIC_HEADER    Header;
  10.   ///
  11.   /// A GUID that defines the contents of this HOB.
  12.   ///
  13.   EFI_GUID                  Name;
  14.   //
  15.   // Guid specific data goes here
  16.   //
  17. } EFI_HOB_GUID_TYPE;
复制代码
  每个HOB元素通过EFI_HOB_GENERIC_HEADER中的HobLength字段举行计算,找到下一个HOB的位置,停止HOB为EFI_HOB_TYPE_END_OF_HOB_LIST类型
  1. //
  2. // HobType of EFI_HOB_GENERIC_HEADER.
  3. //
  4. #define EFI_HOB_TYPE_HANDOFF              0x0001
  5. #define EFI_HOB_TYPE_MEMORY_ALLOCATION    0x0002
  6. #define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR  0x0003
  7. #define EFI_HOB_TYPE_GUID_EXTENSION       0x0004
  8. #define EFI_HOB_TYPE_FV                   0x0005
  9. #define EFI_HOB_TYPE_CPU                  0x0006
  10. #define EFI_HOB_TYPE_MEMORY_POOL          0x0007
  11. #define EFI_HOB_TYPE_FV2                  0x0009
  12. #define EFI_HOB_TYPE_LOAD_PEIM_UNUSED     0x000A
  13. #define EFI_HOB_TYPE_UEFI_CAPSULE         0x000B
  14. #define EFI_HOB_TYPE_FV3                  0x000C
  15. #define EFI_HOB_TYPE_UNUSED               0xFFFE
  16. #define EFI_HOB_TYPE_END_OF_HOB_LIST      0xFFFF
复制代码
在MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c中有一段代码:
  1. /**
  2.   Main entry point to DXE Core.
  3.   @param  HobStart               Pointer to the beginning of the HOB List from PEI.
  4.   @return This function should never return.
  5. **/
  6. VOID
  7. EFIAPI
  8. DxeMain (
  9.   IN  VOID  *HobStart // 由PEI阶段传递的HOB(Handoff Block)列表开始地址
  10.   )
  11. {
  12.   EFI_STATUS                    Status;
  13.   EFI_PHYSICAL_ADDRESS          MemoryBaseAddress;
  14.   UINT64                        MemoryLength;
  15.   PE_COFF_LOADER_IMAGE_CONTEXT  ImageContext;
  16.   UINTN                         Index;
  17.   EFI_HOB_GUID_TYPE             *GuidHob;
  18.   EFI_VECTOR_HANDOFF_INFO       *VectorInfoList;
  19.   EFI_VECTOR_HANDOFF_INFO       *VectorInfo;
  20.   VOID                          *EntryPoint;
  21.   //
  22.   // Setup the default exception handlers
  23.   //
  24.   VectorInfoList = NULL;
  25.   GuidHob        = GetNextGuidHob (&gEfiVectorHandoffInfoPpiGuid, HobStart);
  26. //
  27. }
复制代码
此处的gEfiVectorHandoffInfoPpiGuid位置:MdePkg/MdePkg.dec
  1. [Ppis]
  2.   ## Include/Ppi/VectorHandoffInfo.h
  3.   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
  1. extern EFI_GUID  gEfiVectorHandoffInfoPpiGuid;
复制代码
在其中检察该PPI接口:MdePkg/Include/Ppi/VectorHandoffInfo.h
  1. ///
  2. /// EFI_VECTOR_HANDOFF_INFO entries that describes the interrupt and/or
  3. /// exception vectors in use in the PEI Phase.
  4. ///
  5. typedef struct {
  6.   //
  7.   // The interrupt or exception vector that is in use and must be preserved.
  8.   //
  9.   UINT32      VectorNumber;
  10.   //
  11.   // A bitmask that describes the attributes of the interrupt or exception vector.
  12.   //
  13.   UINT32      Attribute;
  14.   //
  15.   // The GUID identifies the party who created the entry. For the
  16.   // EFI_VECTOR_HANDOFF_DO_NOT_HOOK case, this establishes the single owner.
  17.   //
  18.   EFI_GUID    Owner;
  19. } EFI_VECTOR_HANDOFF_INFO;
  20. ///
  21. /// Provides a description of the interrupt and/or exception vectors that
  22. /// were established in the SEC Phase and need to persist into PEI and DXE.
  23. ///
  24. typedef struct _EFI_PEI_VECTOR_HANDOFF_INFO_PPI {
  25.   //
  26.   // Pointer to an array of interrupt and /or exception vectors.
  27.   //
  28.   EFI_VECTOR_HANDOFF_INFO    *Info;
  29. } EFI_PEI_VECTOR_HANDOFF_INFO_PPI;
复制代码
EFI_PEI_VECTOR_HANDOFF_INFO_PPI的作用为:将向量表信息从PEI阶段传递到DXE阶段,用于在差别固件阶段之间传递与中断向量干系的信息

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

泉缘泉

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表