peihoblib.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 545 行 · 第 1/2 页

C
545
字号
  Hob.Header->HobType = EFI_HOB_TYPE_GUID_EXTENSION;
  Length              = sizeof(EFI_HOB_GUID_TYPE) + BufferSize;
  Hob.Header->HobLength  = (UINT16)Length;
  CopyMem(&Hob.Guid->Name, Guid, sizeof(EFI_GUID));
  CopyMem(Hob.Raw + sizeof(EFI_HOB_GUID_TYPE), Buffer, BufferSize);
  Hob.Raw += Length;

  HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  Hob = BuildHobEndOfHobList(Hob.Raw);
  HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  return EFI_SUCCESS;
}

EFI_STATUS
BuildHobFvDescriptor (
  IN VOID                        *HobStart,
  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
  IN UINT64                      Length
  )
/*++

Routine Description:

  Builds a Firmware Volume HOB

Arguments:

  HobStart    - Start pointer of hob list

  BaseAddress - The base address of the Firmware Volume

  Length      - The size of the Firmware Volume in bytes

Returns:

  EFI_SUCCESS
  EFI_NOT_AVAILABLE_YET

--*/
{
  EFI_PEI_HOB_POINTERS        Hob;
  EFI_PEI_HOB_POINTERS        HandOffHob;
  
  HandOffHob.Raw = HobStart;
  Hob.Raw = (VOID*)(UINTN)(HandOffHob.HandoffInformationTable->EfiEndOfHobList);  

  Hob.Header->HobType   = EFI_HOB_TYPE_FV;
  Hob.Header->HobLength = sizeof(EFI_HOB_FIRMWARE_VOLUME);

  Hob.FirmwareVolume->BaseAddress = BaseAddress;
  Hob.FirmwareVolume->Length      = Length;

  Hob.FirmwareVolume++;

  HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  Hob = BuildHobEndOfHobList(Hob.Raw);
  HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  return EFI_SUCCESS;
}

EFI_STATUS
BuildHobCpu (
  IN VOID                        *HobStart,
  IN UINT8                       SizeOfMemorySpace,
  IN UINT8                       SizeOfIoSpace
  )
/*++

Routine Description:

  Builds a HOB for the CPU

Arguments:

  HobStart                  - Start pointer of hob list

  SizeOfMemorySpace         - Identifies the maximum 
                              physical memory addressibility of the processor.

  SizeOfIoSpace             - Identifies the maximum physical I/O addressibility 
                              of the processor.

Returns:

  EFI_SUCCESS
  EFI_NOT_AVAILABLE_YET

--*/
{
  EFI_PEI_HOB_POINTERS        Hob;
  EFI_PEI_HOB_POINTERS        HandOffHob;

  HandOffHob.Raw = HobStart;
  Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;

  Hob.Header->HobType   = EFI_HOB_TYPE_CPU;
  Hob.Header->HobLength = sizeof(EFI_HOB_CPU);

  Hob.Cpu->SizeOfMemorySpace = SizeOfMemorySpace;
  Hob.Cpu->SizeOfIoSpace     = SizeOfIoSpace;

  Hob.Cpu++;
  HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  Hob = BuildHobEndOfHobList(Hob.Raw);
  HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  return EFI_SUCCESS;
}



EFI_STATUS
BuildHobStack (
  IN VOID                        *HobStart,
  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
  IN UINT64                      Length
  )
/*++

Routine Description:

  Builds a HOB for the Stack

Arguments:

  HobStart                  - Start pointer of hob list

  BaseAddress               - The 64 bit physical address of the Stack

  Length                    - The length of the stack in bytes

Returns:

  EFI_SUCCESS
  EFI_NOT_AVAILABLE_YET

--*/
{
  EFI_PEI_HOB_POINTERS        Hob;
  EFI_PEI_HOB_POINTERS        HandOffHob;
    
  HandOffHob.Raw = HobStart;
  Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;

  Hob.Header->HobType   = EFI_HOB_TYPE_MEMORY_ALLOCATION;
  Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_STACK);

  CopyMem(&(Hob.MemoryAllocationStack->AllocDescriptor.Name), &gEfiHobMemeryAllocStackGuid, sizeof(EFI_GUID));
  (Hob.MemoryAllocationStack->AllocDescriptor).MemoryBaseAddress = BaseAddress;
  (Hob.MemoryAllocationStack->AllocDescriptor).MemoryLength      = Length;
  (Hob.MemoryAllocationStack->AllocDescriptor).MemoryType  = EfiConventionalMemory;

  Hob.MemoryAllocationStack++;
  HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  Hob = BuildHobEndOfHobList(Hob.Raw);
  HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  return EFI_SUCCESS;
}



EFI_STATUS
BuildHobBspStore (
  IN VOID                        *HobStart,
  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
  IN UINT64                      Length,
  IN EFI_MEMORY_TYPE             MemoryType
  )
/*++

Routine Description:

  Builds a HOB for the bsp store

Arguments:

  HobStart                  - Start pointer of hob list

  BaseAddress               - The 64 bit physical address of bsp store

  Length                    - The length of the bsp store in bytes
  
  MemoryType                - Memory type of the bsp store

Returns:

  EFI_SUCCESS
  EFI_NOT_AVAILABLE_YET

--*/
{
  EFI_PEI_HOB_POINTERS        Hob;
  EFI_PEI_HOB_POINTERS        HandOffHob;

  HandOffHob.Raw = HobStart;
  Hob.Raw = (VOID *)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;
  Hob.Header->HobType   = EFI_HOB_TYPE_MEMORY_ALLOCATION;
  Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_BSP_STORE);

  (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryBaseAddress = BaseAddress;
  (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryLength = Length;
  (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryType = MemoryType;
  CopyMem(&(Hob.MemoryAllocationBspStore->AllocDescriptor).Name, &gEfiHobMemeryAllocBspStoreGuid, sizeof(EFI_GUID));
  Hob.MemoryAllocationBspStore++;

  HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  Hob = BuildHobEndOfHobList(Hob.Raw);
  HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  return EFI_SUCCESS;
}


EFI_STATUS
BuildMemoryAllocationHob (
  IN VOID                        *HobStart,
  IN EFI_PHYSICAL_ADDRESS        BaseAddress,
  IN UINT64                      Length,
  IN EFI_GUID                    *Name,
  IN EFI_MEMORY_TYPE             MemoryType
  )
/*++

Routine Description:

  Builds a HOB for memory allocation

Arguments:

  HobStart                  - Start pointer of hob list

  BaseAddress               - The base address of memory allocated by this HOB.

  Length                    - The length in bytes of memory allocated by this HOB.
  
  Name                      - A GUID that defines the memory allocation region’s type and purpose, 
                              as well as other fields within the memory allocation HOB.
                              
  MemoryType                - Defines the type of memory allocated by this HOB.

Returns:

  EFI_SUCCESS
  EFI_NOT_AVAILABLE_YET

--*/
{
  EFI_PEI_HOB_POINTERS        Hob;
  EFI_PEI_HOB_POINTERS        HandOffHob;
  
    
  HandOffHob.Raw = HobStart;
  Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;

  Hob.Header->HobType   = EFI_HOB_TYPE_MEMORY_ALLOCATION;
  Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION);

  if (Name != NULL) {
    CopyMem(&(Hob.MemoryAllocation->AllocDescriptor.Name), &Name, sizeof(EFI_GUID));
  } else {
    ZeroMem(&Hob.MemoryAllocation->AllocDescriptor.Name, sizeof(EFI_GUID));
  }

  (Hob.MemoryAllocation->AllocDescriptor).MemoryBaseAddress = BaseAddress;
  (Hob.MemoryAllocation->AllocDescriptor).MemoryLength = Length;
  (Hob.MemoryAllocation->AllocDescriptor).MemoryType = MemoryType;

  Hob.MemoryAllocation++;
  HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  Hob = BuildHobEndOfHobList(Hob.Raw);
  HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
  return EFI_SUCCESS;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?