3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Protocol/PeCoffLoader.h>
17 #include <Guid/ExtractSection.h>
18 #include <Guid/MemoryTypeInformation.h>
19 #include <Library/PeCoffLib.h>
22 // Have to use build system to set the original value in case we are running
23 // from FLASH and globals don't work. So if you do a GetHobList() and gHobList
24 // and gHobList is NULL the PCD default values are used.
26 VOID
*gHobList
= NULL
;
31 // May want to put this into a library so you only need the PCD setings if you are using the feature?
33 BuildMemoryTypeInformationHob (
37 EFI_MEMORY_TYPE_INFORMATION Info
[10];
39 Info
[0].Type
= EfiACPIReclaimMemory
;
40 Info
[0].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory
);
41 Info
[1].Type
= EfiACPIMemoryNVS
;
42 Info
[1].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS
);
43 Info
[2].Type
= EfiReservedMemoryType
;
44 Info
[2].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiReservedMemoryType
);
45 Info
[3].Type
= EfiRuntimeServicesData
;
46 Info
[3].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData
);
47 Info
[4].Type
= EfiRuntimeServicesCode
;
48 Info
[4].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode
);
49 Info
[5].Type
= EfiBootServicesCode
;
50 Info
[5].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesCode
);
51 Info
[6].Type
= EfiBootServicesData
;
52 Info
[6].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesData
);
53 Info
[7].Type
= EfiLoaderCode
;
54 Info
[7].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderCode
);
55 Info
[8].Type
= EfiLoaderData
;
56 Info
[8].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderData
);
58 // Terminator for the list
59 Info
[9].Type
= EfiMaxMemoryType
;
60 Info
[9].NumberOfPages
= 0;
63 BuildGuidDataHob (&gEfiMemoryTypeInformationGuid
, &Info
, sizeof (Info
));
73 IN UINTN MemoryLength
,
78 EFI_HOB_HANDOFF_INFO_TABLE
*Hob
;
79 EFI_HOB_GENERIC_HEADER
*HobEnd
;
80 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
84 HobEnd
= (EFI_HOB_GENERIC_HEADER
*)(Hob
+1);
86 Hob
->Header
.HobType
= EFI_HOB_TYPE_HANDOFF
;
87 Hob
->Header
.HobLength
= sizeof(EFI_HOB_HANDOFF_INFO_TABLE
);
88 Hob
->Header
.Reserved
= 0;
90 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
91 HobEnd
->HobLength
= sizeof(EFI_HOB_GENERIC_HEADER
);
94 Hob
->Version
= EFI_HOB_HANDOFF_TABLE_VERSION
;
95 Hob
->BootMode
= BOOT_WITH_FULL_CONFIGURATION
;
97 Hob
->EfiMemoryTop
= (UINTN
)MemoryBegin
+ MemoryLength
;
98 Hob
->EfiMemoryBottom
= (UINTN
)MemoryBegin
;
99 Hob
->EfiFreeMemoryTop
= (UINTN
)StackBase
;
100 Hob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)(HobEnd
+1);
101 Hob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)HobEnd
;
105 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize
), PcdGet8 (PcdPrePiCpuIoSize
));
108 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
109 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
110 EFI_RESOURCE_ATTRIBUTE_TESTED
|
111 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
112 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
113 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
114 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
117 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
, Attributes
, (UINTN
)MemoryBegin
, MemoryLength
);
120 BuildStackHob ((UINTN
)StackBase
, Hob
->EfiMemoryTop
- (UINTN
)StackBase
);
122 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
123 // Optional feature that helps prevent EFI memory map fragmentation.
124 BuildMemoryTypeInformationHob ();
133 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
134 IN UINT64 NumberOfBytes
,
135 IN EFI_RESOURCE_ATTRIBUTE_TYPE
*ResourceAttribute
139 EFI_RESOURCE_ATTRIBUTE_TYPE Resource
;
141 BuildFvHob (PhysicalStart
, NumberOfBytes
);
143 if (ResourceAttribute
== NULL
) {
144 Resource
= (EFI_RESOURCE_ATTRIBUTE_PRESENT
|
145 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
146 EFI_RESOURCE_ATTRIBUTE_TESTED
|
147 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
);
149 Resource
= *ResourceAttribute
;
152 BuildResourceDescriptorHob (EFI_RESOURCE_FIRMWARE_DEVICE
, Resource
, PhysicalStart
, NumberOfBytes
);
160 Returns the pointer to the HOB list.
162 This function returns the pointer to first HOB in the list.
164 @return The pointer to the HOB list.
173 if (gHobList
== NULL
) {
174 return (VOID
*)(UINTN
)PcdGet32 (PcdPrePiHobBase
);
183 Updates the pointer to the HOB list.
185 @param HobList Hob list pointer to store
197 // If this code is running from ROM this could fail
199 return (gHobList
== HobList
) ? EFI_SUCCESS
: EFI_UNSUPPORTED
;
210 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
211 EFI_HOB_GENERIC_HEADER
*HobEnd
;
212 EFI_PHYSICAL_ADDRESS FreeMemory
;
215 HandOffHob
= GetHobList ();
217 HobLength
= (UINT16
)((HobLength
+ 0x7) & (~0x7));
219 FreeMemory
= HandOffHob
->EfiFreeMemoryTop
- HandOffHob
->EfiFreeMemoryBottom
;
221 if (FreeMemory
< HobLength
) {
225 Hob
= (VOID
*) (UINTN
) HandOffHob
->EfiEndOfHobList
;
226 ((EFI_HOB_GENERIC_HEADER
*) Hob
)->HobType
= HobType
;
227 ((EFI_HOB_GENERIC_HEADER
*) Hob
)->HobLength
= HobLength
;
228 ((EFI_HOB_GENERIC_HEADER
*) Hob
)->Reserved
= 0;
230 HobEnd
= (EFI_HOB_GENERIC_HEADER
*) ((UINTN
)Hob
+ HobLength
);
231 HandOffHob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;
233 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
234 HobEnd
->HobLength
= sizeof(EFI_HOB_GENERIC_HEADER
);
235 HobEnd
->Reserved
= 0;
237 HandOffHob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;
244 Returns the next instance of a HOB type from the starting HOB.
246 This function searches the first instance of a HOB type from the starting HOB pointer.
247 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
248 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
249 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
250 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
251 If HobStart is NULL, then ASSERT().
253 @param Type The HOB type to return.
254 @param HobStart The starting HOB pointer to search from.
256 @return The next instance of a HOB type from the starting HOB.
263 IN CONST VOID
*HobStart
266 EFI_PEI_HOB_POINTERS Hob
;
268 ASSERT (HobStart
!= NULL
);
270 Hob
.Raw
= (UINT8
*) HobStart
;
272 // Parse the HOB list until end of list or matching type is found.
274 while (!END_OF_HOB_LIST (Hob
)) {
275 if (Hob
.Header
->HobType
== Type
) {
278 Hob
.Raw
= GET_NEXT_HOB (Hob
);
286 Returns the first instance of a HOB type among the whole HOB list.
288 This function searches the first instance of a HOB type among the whole HOB list.
289 If there does not exist such HOB type in the HOB list, it will return NULL.
291 @param Type The HOB type to return.
293 @return The next instance of a HOB type from the starting HOB.
304 HobList
= GetHobList ();
305 return GetNextHob (Type
, HobList
);
310 This function searches the first instance of a HOB from the starting HOB pointer.
311 Such HOB should satisfy two conditions:
312 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
313 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
314 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
315 to extract the data section and its size info respectively.
316 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer
317 unconditionally: it returns HobStart back if HobStart itself meets the requirement;
318 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
319 If Guid is NULL, then ASSERT().
320 If HobStart is NULL, then ASSERT().
322 @param Guid The GUID to match with in the HOB list.
323 @param HobStart A pointer to a Guid.
325 @return The next instance of the matched GUID HOB from the starting HOB.
331 IN CONST EFI_GUID
*Guid
,
332 IN CONST VOID
*HobStart
334 EFI_PEI_HOB_POINTERS GuidHob
;
336 GuidHob
.Raw
= (UINT8
*) HobStart
;
337 while ((GuidHob
.Raw
= GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION
, GuidHob
.Raw
)) != NULL
) {
338 if (CompareGuid (Guid
, &GuidHob
.Guid
->Name
)) {
341 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
348 This function searches the first instance of a HOB among the whole HOB list.
349 Such HOB should satisfy two conditions:
350 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
351 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
352 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()
353 to extract the data section and its size info respectively.
354 If Guid is NULL, then ASSERT().
356 @param Guid The GUID to match with in the HOB list.
358 @return The first instance of the matched GUID HOB among the whole HOB list.
364 IN CONST EFI_GUID
*Guid
369 HobList
= GetHobList ();
370 return GetNextGuidHob (Guid
, HobList
);
375 Get the Boot Mode from the HOB list.
377 This function returns the system boot mode information from the
378 PHIT HOB in HOB list.
382 @return The Boot Mode.
391 EFI_PEI_HOB_POINTERS Hob
;
393 Hob
.Raw
= GetHobList ();
394 return Hob
.HandoffInformationTable
->BootMode
;
399 Get the Boot Mode from the HOB list.
401 This function returns the system boot mode information from the
402 PHIT HOB in HOB list.
406 @return The Boot Mode.
412 IN EFI_BOOT_MODE BootMode
415 EFI_PEI_HOB_POINTERS Hob
;
417 Hob
.Raw
= GetHobList ();
418 Hob
.HandoffInformationTable
->BootMode
= BootMode
;
423 Builds a HOB for a loaded PE32 module.
425 This function builds a HOB for a loaded PE32 module.
426 It can only be invoked during PEI phase;
427 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
428 If ModuleName is NULL, then ASSERT().
429 If there is no additional space for HOB creation, then ASSERT().
431 @param ModuleName The GUID File Name of the module.
432 @param MemoryAllocationModule The 64 bit physical address of the module.
433 @param ModuleLength The length of the module in bytes.
434 @param EntryPoint The 64 bit physical address of the module entry point.
440 IN CONST EFI_GUID
*ModuleName
,
441 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule
,
442 IN UINT64 ModuleLength
,
443 IN EFI_PHYSICAL_ADDRESS EntryPoint
446 EFI_HOB_MEMORY_ALLOCATION_MODULE
*Hob
;
448 ASSERT (((MemoryAllocationModule
& (EFI_PAGE_SIZE
- 1)) == 0) &&
449 ((ModuleLength
& (EFI_PAGE_SIZE
- 1)) == 0));
451 Hob
= CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE
));
453 CopyGuid (&(Hob
->MemoryAllocationHeader
.Name
), &gEfiHobMemoryAllocModuleGuid
);
454 Hob
->MemoryAllocationHeader
.MemoryBaseAddress
= MemoryAllocationModule
;
455 Hob
->MemoryAllocationHeader
.MemoryLength
= ModuleLength
;
456 Hob
->MemoryAllocationHeader
.MemoryType
= EfiBootServicesCode
;
459 // Zero the reserved space to match HOB spec
461 ZeroMem (Hob
->MemoryAllocationHeader
.Reserved
, sizeof (Hob
->MemoryAllocationHeader
.Reserved
));
463 CopyGuid (&Hob
->ModuleName
, ModuleName
);
464 Hob
->EntryPoint
= EntryPoint
;
469 Builds a HOB that describes a chunk of system memory.
471 This function builds a HOB that describes a chunk of system memory.
472 If there is no additional space for HOB creation, then ASSERT().
474 @param ResourceType The type of resource described by this HOB.
475 @param ResourceAttribute The resource attributes of the memory described by this HOB.
476 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
477 @param NumberOfBytes The length of the memory described by this HOB in bytes.
482 BuildResourceDescriptorHob (
483 IN EFI_RESOURCE_TYPE ResourceType
,
484 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
,
485 IN EFI_PHYSICAL_ADDRESS PhysicalStart
,
486 IN UINT64 NumberOfBytes
489 EFI_HOB_RESOURCE_DESCRIPTOR
*Hob
;
491 Hob
= CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, sizeof (EFI_HOB_RESOURCE_DESCRIPTOR
));
493 Hob
->ResourceType
= ResourceType
;
494 Hob
->ResourceAttribute
= ResourceAttribute
;
495 Hob
->PhysicalStart
= PhysicalStart
;
496 Hob
->ResourceLength
= NumberOfBytes
;
501 Builds a GUID HOB with a certain data length.
503 This function builds a customized HOB tagged with a GUID for identification
504 and returns the start address of GUID HOB data so that caller can fill the customized data.
505 The HOB Header and Name field is already stripped.
506 It can only be invoked during PEI phase;
507 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
508 If Guid is NULL, then ASSERT().
509 If there is no additional space for HOB creation, then ASSERT().
510 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
512 @param Guid The GUID to tag the customized HOB.
513 @param DataLength The size of the data payload for the GUID HOB.
515 @return The start address of GUID HOB data.
521 IN CONST EFI_GUID
*Guid
,
525 EFI_HOB_GUID_TYPE
*Hob
;
528 // Make sure that data length is not too long.
530 ASSERT (DataLength
<= (0xffff - sizeof (EFI_HOB_GUID_TYPE
)));
532 Hob
= CreateHob (EFI_HOB_TYPE_GUID_EXTENSION
, (UINT16
) (sizeof (EFI_HOB_GUID_TYPE
) + DataLength
));
533 CopyGuid (&Hob
->Name
, Guid
);
539 Copies a data buffer to a newly-built HOB.
541 This function builds a customized HOB tagged with a GUID for identification,
542 copies the input data to the HOB data field and returns the start address of the GUID HOB data.
543 The HOB Header and Name field is already stripped.
544 It can only be invoked during PEI phase;
545 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
546 If Guid is NULL, then ASSERT().
547 If Data is NULL and DataLength > 0, then ASSERT().
548 If there is no additional space for HOB creation, then ASSERT().
549 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().
551 @param Guid The GUID to tag the customized HOB.
552 @param Data The data to be copied into the data field of the GUID HOB.
553 @param DataLength The size of the data payload for the GUID HOB.
555 @return The start address of GUID HOB data.
561 IN CONST EFI_GUID
*Guid
,
568 ASSERT (Data
!= NULL
|| DataLength
== 0);
570 HobData
= BuildGuidHob (Guid
, DataLength
);
572 return CopyMem (HobData
, Data
, DataLength
);
577 Builds a Firmware Volume HOB.
579 This function builds a Firmware Volume HOB.
580 It can only be invoked during PEI phase;
581 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
582 If there is no additional space for HOB creation, then ASSERT().
584 @param BaseAddress The base address of the Firmware Volume.
585 @param Length The size of the Firmware Volume in bytes.
591 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
595 EFI_HOB_FIRMWARE_VOLUME
*Hob
;
597 Hob
= CreateHob (EFI_HOB_TYPE_FV
, sizeof (EFI_HOB_FIRMWARE_VOLUME
));
599 Hob
->BaseAddress
= BaseAddress
;
600 Hob
->Length
= Length
;
605 Builds a EFI_HOB_TYPE_FV2 HOB.
607 This function builds a EFI_HOB_TYPE_FV2 HOB.
608 It can only be invoked during PEI phase;
609 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
610 If there is no additional space for HOB creation, then ASSERT().
612 @param BaseAddress The base address of the Firmware Volume.
613 @param Length The size of the Firmware Volume in bytes.
614 @param FvName The name of the Firmware Volume.
615 @param FileName The name of the file.
621 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
623 IN CONST EFI_GUID
*FvName
,
624 IN CONST EFI_GUID
*FileName
627 EFI_HOB_FIRMWARE_VOLUME2
*Hob
;
629 Hob
= CreateHob (EFI_HOB_TYPE_FV2
, sizeof (EFI_HOB_FIRMWARE_VOLUME2
));
631 Hob
->BaseAddress
= BaseAddress
;
632 Hob
->Length
= Length
;
633 CopyGuid (&Hob
->FvName
, FvName
);
634 CopyGuid (&Hob
->FileName
, FileName
);
640 Builds a Capsule Volume HOB.
642 This function builds a Capsule Volume HOB.
643 It can only be invoked during PEI phase;
644 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
645 If there is no additional space for HOB creation, then ASSERT().
647 @param BaseAddress The base address of the Capsule Volume.
648 @param Length The size of the Capsule Volume in bytes.
654 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
663 Builds a HOB for the CPU.
665 This function builds a HOB for the CPU.
666 It can only be invoked during PEI phase;
667 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
668 If there is no additional space for HOB creation, then ASSERT().
670 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
671 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
677 IN UINT8 SizeOfMemorySpace
,
678 IN UINT8 SizeOfIoSpace
683 Hob
= CreateHob (EFI_HOB_TYPE_CPU
, sizeof (EFI_HOB_CPU
));
685 Hob
->SizeOfMemorySpace
= SizeOfMemorySpace
;
686 Hob
->SizeOfIoSpace
= SizeOfIoSpace
;
689 // Zero the reserved space to match HOB spec
691 ZeroMem (Hob
->Reserved
, sizeof (Hob
->Reserved
));
696 Builds a HOB for the Stack.
698 This function builds a HOB for the stack.
699 It can only be invoked during PEI phase;
700 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
701 If there is no additional space for HOB creation, then ASSERT().
703 @param BaseAddress The 64 bit physical address of the Stack.
704 @param Length The length of the stack in bytes.
710 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
714 EFI_HOB_MEMORY_ALLOCATION_STACK
*Hob
;
716 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
717 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
719 Hob
= CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK
));
721 CopyGuid (&(Hob
->AllocDescriptor
.Name
), &gEfiHobMemoryAllocStackGuid
);
722 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
723 Hob
->AllocDescriptor
.MemoryLength
= Length
;
724 Hob
->AllocDescriptor
.MemoryType
= EfiBootServicesData
;
727 // Zero the reserved space to match HOB spec
729 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
734 Update the Stack Hob if the stack has been moved
736 @param BaseAddress The 64 bit physical address of the Stack.
737 @param Length The length of the stack in bytes.
742 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
746 EFI_PEI_HOB_POINTERS Hob
;
748 Hob
.Raw
= GetHobList ();
749 while ((Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, Hob
.Raw
)) != NULL
) {
750 if (CompareGuid (&gEfiHobMemoryAllocStackGuid
, &(Hob
.MemoryAllocationStack
->AllocDescriptor
.Name
))) {
752 // Build a new memory allocation HOB with old stack info with EfiConventionalMemory type
753 // to be reclaimed by DXE core.
755 BuildMemoryAllocationHob (
756 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
,
757 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
,
758 EfiConventionalMemory
761 // Update the BSP Stack Hob to reflect the new stack info.
763 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
764 Hob
.MemoryAllocationStack
->AllocDescriptor
.MemoryLength
= Length
;
767 Hob
.Raw
= GET_NEXT_HOB (Hob
);
774 Builds a HOB for the memory allocation.
776 This function builds a HOB for the memory allocation.
777 It can only be invoked during PEI phase;
778 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
779 If there is no additional space for HOB creation, then ASSERT().
781 @param BaseAddress The 64 bit physical address of the memory.
782 @param Length The length of the memory allocation in bytes.
783 @param MemoryType Type of memory allocated by this HOB.
788 BuildMemoryAllocationHob (
789 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
791 IN EFI_MEMORY_TYPE MemoryType
794 EFI_HOB_MEMORY_ALLOCATION
*Hob
;
796 ASSERT (((BaseAddress
& (EFI_PAGE_SIZE
- 1)) == 0) &&
797 ((Length
& (EFI_PAGE_SIZE
- 1)) == 0));
799 Hob
= CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION
, sizeof (EFI_HOB_MEMORY_ALLOCATION
));
801 ZeroMem (&(Hob
->AllocDescriptor
.Name
), sizeof (EFI_GUID
));
802 Hob
->AllocDescriptor
.MemoryBaseAddress
= BaseAddress
;
803 Hob
->AllocDescriptor
.MemoryLength
= Length
;
804 Hob
->AllocDescriptor
.MemoryType
= MemoryType
;
806 // Zero the reserved space to match HOB spec
808 ZeroMem (Hob
->AllocDescriptor
.Reserved
, sizeof (Hob
->AllocDescriptor
.Reserved
));
815 BuildExtractSectionHob (
817 IN EXTRACT_GUIDED_SECTION_GET_INFO_HANDLER SectionGetInfo
,
818 IN EXTRACT_GUIDED_SECTION_DECODE_HANDLER SectionExtraction
821 EXTRACT_SECTION_DATA Data
;
823 Data
.SectionGetInfo
= SectionGetInfo
;
824 Data
.SectionExtraction
= SectionExtraction
;
825 BuildGuidDataHob (Guid
, &Data
, sizeof (Data
));
828 PE_COFF_LOADER_PROTOCOL gPeCoffProtocol
= {
829 PeCoffLoaderGetImageInfo
,
830 PeCoffLoaderLoadImage
,
831 PeCoffLoaderRelocateImage
,
832 PeCoffLoaderImageReadFromMemory
,
833 PeCoffLoaderRelocateImageForRuntime
,
834 PeCoffLoaderUnloadImage
841 BuildPeCoffLoaderHob (
847 Ptr
= &gPeCoffProtocol
;
848 BuildGuidDataHob (&gPeCoffLoaderProtocolGuid
, &Ptr
, sizeof (VOID
*));