1. 程式人生 > >uefi bios pei 階段最重要的一個數據結構(結構體)

uefi bios pei 階段最重要的一個數據結構(結構體)

在PEI階段,全域性變數大概有這麼幾個: gPs  PEI Service 結構的實現,包括所有的PEI 服務的函式指標。比如學見的PeiInstallPPi, PeiCreateHob, PeiSetSystem. 

其次就是PrivateData, 這個是今天我們要討論的問題,其型別為 PEI_CORE_INSTANCE.

具體就是長這個樣子:

 struct _PEI_CORE_INSTANCE {
  184   UINTN                              Signature;
  185   
  189   EFI_PEI_SERVICES                   *Ps;
  190   PEI_PPI_DATABASE                   PpiData;
  191   
  195   UINTN                              FvCount;
  196   
  201   PEI_CORE_FV_HANDLE                 *Fv;
  202 
  207   PEI_CORE_UNKNOW_FORMAT_FV_INFO     *UnknownFvInfo;
  208   UINTN                              UnknownFvInfoCount;
  209   
  213   EFI_PEI_FILE_HANDLE                *CurrentFvFileHandles;
  214   UINTN                              AprioriCount;
  215   UINTN                              CurrentPeimFvCount;
  216   UINTN                              CurrentPeimCount;
  217   EFI_PEI_FILE_HANDLE                CurrentFileHandle;
  218   BOOLEAN                            PeimNeedingDispatch;
  219   BOOLEAN                            PeimDispatchOnThisPass;
  220   BOOLEAN                            PeimDispatcherReenter;
  221   EFI_PEI_HOB_POINTERS               HobList;
  222   BOOLEAN                            SwitchStackSignal;
  223   BOOLEAN                            PeiMemoryInstalled;
  224   VOID                               *CpuIo;
  225   EFI_PEI_SECURITY2_PPI              *PrivateSecurityPpi;
  226   EFI_PEI_SERVICES                   ServiceTableShadow;
  227   EFI_PEI_PPI_DESCRIPTOR             *XipLoadFile;
  228   EFI_PHYSICAL_ADDRESS               PhysicalMemoryBegin;
  229   UINT64                             PhysicalMemoryLength;
  230   EFI_PHYSICAL_ADDRESS               FreePhysicalMemoryTop;
  231   UINTN                              HeapOffset;
  232   BOOLEAN                            HeapOffsetPositive;
  233   UINTN                              StackOffset;
  234   BOOLEAN                            StackOffsetPositive;
  235   PEICORE_FUNCTION_POINTER           ShadowedPeiCore;
  236   CACHE_SECTION_DATA                 CacheSection;
  237   //
  238   // For Loading modules at fixed address feature to cache the top address below which the 
  239   // Runtime code, boot time code and PEI memory will be placed. Please note that the offset between this field 
  240   // and  Ps should not be changed since maybe user could get this top address by using the offet to Ps. 
  241   //
  242   EFI_PHYSICAL_ADDRESS               LoadModuleAtFixAddressTopAddress;
  243   //
  244   // The field is define for Loading modules at fixed address feature to tracker the PEI code
  245   // memory range usage. It is a bit mapped array in which every bit indicates the correspoding memory page
  246   // available or not. 
  247   //
  248   UINT64                            *PeiCodeMemoryRangeUsageBitMap;
  249   //
  250   // This field points to the shadowed image read function
  251   //
  252   PE_COFF_LOADER_READ_FILE          ShadowedImageRead;
  253 
  254   //
  255   // Pointer to the temp buffer with the PcdPeiCoreMaxPeimPerFv + 1 number of entries.
  256   //
  257   EFI_PEI_FILE_HANDLE               *FileHandles;
  258   //
  259   // Pointer to the temp buffer with the PcdPeiCoreMaxPeimPerFv number of entries.
  260   //
  261   EFI_GUID                          *FileGuid;
  262 
  263   //
  264   // Temp Memory Range is not covered by PeiTempMem and Stack.
  265   // Those Memory Range will be migrated into phisical memory. 
  266   //
  267   HOLE_MEMORY_DATA                  HoleData[HOLE_MAX_NUMBER];
  268 };

PrivateData 我們通常叫做PeiMain的內部資料結構,維護執行PEI階段所有需要的資料資訊,包括PEI 服務, FV 資料空間,PEI 模組的dispatch 狀態, 可使用的記憶體空間等等,由於pei 早期沒有記憶體可用,PeiMain定義了一個該資料的區域性變數,把其儲存在PeiMain入口函式的棧上,而PeiMain 的入口函式在整個PEI 階段並不會退出,所以棧上的資料可作為全域性資料使用,但是全域性變數的地址需要函式引數在不同的函式之間傳遞。

PEI_CORE_FV_HANDLE 資料結構

此資料結構用來記錄一個PeiMain 識別的FV空間的資料資訊,包括其起始位置,資料格式解析的PPI, 自己的控制代碼以及所包含的每個PEI模組的派遣狀態和每個檔案的控制代碼,

它的真實樣子是這樣的:

 typedef struct {
  110   EFI_FIRMWARE_VOLUME_HEADER          *FvHeader;
  111   EFI_PEI_FIRMWARE_VOLUME_PPI         *FvPpi;
  112   EFI_PEI_FV_HANDLE                   FvHandle;
  113   //
  114   // Ponter to the buffer with the PcdPeiCoreMaxPeimPerFv number of Entries.
  115   //
  116   UINT8                               *PeimState;
  117   //
  118   // Ponter to the buffer with the PcdPeiCoreMaxPeimPerFv number of Entries.
  119   //
  120   EFI_PEI_FILE_HANDLE                 *FvFileHandles;
  121   BOOLEAN                             ScanFv;
  122   UINT32                              AuthenticationStatus;
  123 } PEI_CORE_FV_HANDLE;