接下来的代码在 \mdemodulepkg\core\dxe\dxemain\DxeMain.c。我们依旧是按照 Debug Log 的顺序研究。
//
// Initialize Memory Services
//
CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);
这个函数位于\mdemodulepkg\core\dxe\gcd\Gcd.c,初始化内存服务。
/**
External function. Initializes memory services based on the memory
descriptor HOBs. This function is responsible for priming the memory
map, so memory allocations and resource allocations can be made.
The first part of this function can not depend on any memory services
until at least one memory descriptor is provided to the memory services.
@param HobStart The start address of the HOB.
@param MemoryBaseAddress Start address of memory region found to init DXE
core.
@param MemoryLength Length of memory region found to init DXE core.
@retval EFI_SUCCESS Memory services successfully initialized.
**/
EFI_STATUS
CoreInitializeMemoryServices (
IN VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *MemoryBaseAddress,
OUT UINT64 *MemoryLength
)
CoreInitializeMemoryServices:
BaseAddress - 0x3F59000 Length - 0x3CA7000
MinimalMemorySizeNeeded - 0x320000
(这里看起来有一个能够运行的最小内存的要求,具体怎么来的还不清楚)
接下来回到 DxeMain 中继续运行,接下来开始创建最重要的2个Table:System_Table 和 Runtime_Services
//
// Allocate the EFI System Table and EFI Runtime Service Table from EfiRuntimeServicesData
// Use the templates to initialize the contents of the EFI System Table and EFI Runtime Services Table
//
gDxeCoreST = AllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
ASSERT (gDxeCoreST != NULL);
gDxeCoreRT = AllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
ASSERT (gDxeCoreRT != NULL);
gDxeCoreST->RuntimeServices = gDxeCoreRT;
InstallProtocolInterface: 5B1B31A1-9562-11D2-8E3F-00A0C969723B 7EC57F8
## Include/Protocol/LoadedImage.h
gEfiLoadedImageProtocolGuid = { 0x5B1B31A1, 0x9562, 0x11D2, { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B }}
//
// Start the Image Services.
//
Status = CoreInitializeImageServices (HobStart);
ASSERT_EFI_ERROR (Status);
\mdemodulepkg\core\dxe\image\Image.c
/**
Add the Image Services to EFI Boot Services Table and install the protocol
interfaces for this image.
@param HobStart The HOB to initialize
@return Status code.
**/
EFI_STATUS
CoreInitializeImageServices (
IN VOID *HobStart
)
其中:
//
// Install the protocol interfaces for this image
//
Status = CoreInstallProtocolInterface (
&Image->Handle,
&gEfiLoadedImageProtocolGuid,
EFI_NATIVE_INTERFACE,
&Image->Info
);
ASSERT_EFI_ERROR (Status);
ProtectUefiImage (&Image->Info, Image->LoadedImageDevicePath);
在\mdemodulepkg\core\dxe\misc\MemoryProtection.c 文件中:
ProtectUefiImageCommon - 0x7EC57F8
- 0x0000000007EA3000 - 0x0000000000027000
(不清楚这个函数的左右,看介绍好像是用于加载 PE 格式,然后设置对应的代码为”Execute Only”)。
接下来返回 DxeMain 中继续:
//
// Log MemoryBaseAddress and MemoryLength again (from
// CoreInitializeMemoryServices()), now that library constructors have
// executed.
//
DEBUG ((DEBUG_INFO, "%a: MemoryBaseAddress=0x%Lx MemoryLength=0x%Lx\n",
__FUNCTION__, MemoryBaseAddress, MemoryLength));
DxeMain: MemoryBaseAddress=0x3F59000 MemoryLength=0x3CA7000
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "HOBLIST address in DXE = 0x%p\n", HobStart));
HOBLIST address in DXE = 0x78EA018
\MdePkg\MdePkg.dec
## Include/Protocol/Decompress.h
gEfiDecompressProtocolGuid = { 0xD8117CFE, 0x94A6, 0x11D4, { 0x9A, 0x3A, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }}
## Include/Protocol/FirmwareVolumeBlock.h
gEfiFirmwareVolumeBlockProtocolGuid = { 0x8f644fa9, 0xe850, 0x4db1, {0x9c, 0xe2, 0xb, 0x44, 0x69, 0x8e, 0x8d, 0xa4 } }
## Include/Protocol/DevicePath.h
gEfiDevicePathProtocolGuid = { 0x09576E91, 0x6D3F, 0x11D2, { 0x8E, 0x39, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B }}
## Include/Protocol/FirmwareVolume2.h
gEfiFirmwareVolume2ProtocolGuid = { 0x220e73b6, 0x6bdb, 0x4413, { 0x84, 0x5, 0xb9, 0x74, 0xb1, 0x8, 0x61, 0x9a } }
比较特别的是:
InstallProtocolInterface: D8117CFE-94A6-11D4-9A3A-0090273FC14D 7EC5080
InstallProtocolInterface: 8F644FA9-E850-4DB1-9CE2-0B44698E8DA4 78E6CB0
InstallProtocolInterface: 09576E91-6D3F-11D2-8E39-00A0C969723B 78E6D98
InstallProtocolInterface: 220E73B6-6BDB-4413-8405-B974B108619A 78E6630
InstallProtocolInterface: EE4E5898-3914-4259-9D6E-DC7BD79403CF 7EC5D10
最后一个定义在\OvmfPkg\OvmfPkgX64.fdf:
FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
#
# These firmware volumes will have files placed in them uncompressed,
# and then both firmware volumes will be compressed in a single
# compression operation in order to achieve better overall compression.
#
SECTION FV_IMAGE = PEIFV
SECTION FV_IMAGE = DXEFV
}
}
代码在\mdemodulepkg\core\dxe\sectionextraction\CoreSectionExtraction.c
/**
Entry point of the section extraction code. Initializes an instance of the
section extraction interface and installs it on a new handle.
@param ImageHandle A handle for the image that is initializing this driver
@param SystemTable A pointer to the EFI system table
@retval EFI_SUCCESS Driver initialized successfully
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
**/
EFI_STATUS
EFIAPI
InitializeSectionExtraction (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
(感觉是将 PEI 和 DXE打包在一起)