dxemain.c

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

C
955
字号
Routine Description:

  Main entry point to DXE Core.

Arguments:

  HobStart - Pointer to the beginning of the HOB List from PEI

Returns:

  This function should never return

--*/
{
  EFI_STATUS                         Status;
  EFI_HANDLE                         DecompressHandle;
  EFI_PHYSICAL_ADDRESS               MemoryBaseAddress;
  UINT64                             MemoryLength;

#ifdef EFI_DXE_PERFORMANCE
  UINT64                             Tick;

  GetTimerValue (&Tick);
#endif


  mHobStart = HobStart;
  
  //
  // Initialize Memory Services
  //
  CoreInitializeMemoryServices (&HobStart, &MemoryBaseAddress, &MemoryLength);

  //
  // 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
  //
  gST = CoreAllocateRuntimeCopyPool (sizeof (EFI_SYSTEM_TABLE), &mEfiSystemTableTemplate);
  ASSERT (gST != NULL);

  gRT = CoreAllocateRuntimeCopyPool (sizeof (EFI_RUNTIME_SERVICES), &mEfiRuntimeServicesTableTemplate);
  ASSERT (gRT != NULL);

  gST->RuntimeServices = gRT;
  
  //
  // Start the Image Services.
  //
  Status = CoreInitializeImageServices (HobStart);
  ASSERT_EFI_ERROR (Status);

  //
  // Initialize the Global Coherency Domain Services
  //
  Status = CoreInitializeGcdServices (&HobStart, MemoryBaseAddress, MemoryLength);
  ASSERT_EFI_ERROR (Status);

  //
  // Install the DXE Services Table into the EFI System Tables's Configuration Table
  //
  Status = CoreInstallConfigurationTable (&gEfiDxeServicesTableGuid, gDS);
  ASSERT_EFI_ERROR (Status);

  //
  // Install the HOB List into the EFI System Tables's Configuration Table
  //
  Status = CoreInstallConfigurationTable (&gEfiHobListGuid, HobStart);
  ASSERT_EFI_ERROR (Status);

  //
  // Install Memory Type Information Table into the EFI System Tables's Configuration Table
  //
  Status = CoreInstallConfigurationTable (&gEfiMemoryTypeInformationGuid, &gMemoryTypeInformation);
  ASSERT_EFI_ERROR (Status);

  //
  // Initialize the ReportStatusCode with PEI version, if availible
  //
  CoreGetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **)&gStatusCode->ReportStatusCode);
#if ((TIANO_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
  gRT->ReportStatusCode = gStatusCode->ReportStatusCode;
#endif

  //
  // Report Status Code here for DXE_ENTRY_POINT once it is available
  //
  CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_ENTRY_POINT));

  //
  // Create the aligned system table pointer structure that is used by external
  // debuggers to locate the system table...  Also, install debug image info
  // configuration table.
  //
  CoreInitializeDebugImageInfoTable ();
  CoreNewDebugImageInfoEntry (
    EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
    gDxeCoreLoadedImage,
    gDxeCoreImageHandle
    );

  DEBUG_CODE (
    DEBUG ((EFI_D_INFO | EFI_D_LOAD, "HOBLIST address in DXE = 0x%08x\n", HobStart));
  )
  //
  // Initialize the Event Services
  //
  Status = CoreInitializeEventServices ();
  ASSERT_EFI_ERROR (Status);

   
  //
  // Get the Protocols that were passed in from PEI to DXE through GUIDed HOBs
  //
  // These Protocols are not architectural. This implementation is sharing code between 
  // PEI and DXE in order to save FLASH space. These Protocols could also be implemented 
  // as part of the DXE Core. However, that would also require the DXE Core to be ported 
  // each time a different CPU is used, a different Decompression algorithm is used, or a 
  // different Image type is used. By placing these Protocols in PEI, the DXE Core remains 
  // generic, and only PEI and the Arch Protocols need to be ported from Platform to Platform, 
  // and from CPU to CPU.
  //

  Status = CoreGetPeiProtocol (&gEfiDecompressProtocolGuid, &gEfiDecompress);
  if (!EFI_ERROR (Status)) {
    
    //
    // Publish the EFI Decompress protocol for use by other DXE components
    //
    
    DecompressHandle = NULL;
    Status = CoreInstallProtocolInterface (
               &DecompressHandle,
               &gEfiDecompressProtocolGuid,
               EFI_NATIVE_INTERFACE,
               gEfiDecompress
               );
    ASSERT_EFI_ERROR (Status);
  }

  Status = CoreGetPeiProtocol (&gEfiTianoDecompressProtocolGuid, &gEfiTianoDecompress);
  if (!EFI_ERROR (Status)) {
    
    //
    // Publish the Tiano Decompress protocol for use by other DXE components
    //
    
    DecompressHandle = NULL;
    Status = CoreInstallProtocolInterface (
               &DecompressHandle,
               &gEfiTianoDecompressProtocolGuid,
               EFI_NATIVE_INTERFACE,
               gEfiTianoDecompress
               );
    ASSERT_EFI_ERROR (Status);
  }
                                  
  Status = CoreGetPeiProtocol (&gEfiCustomizedDecompressProtocolGuid, &gEfiCustomizedDecompress);
  if (!EFI_ERROR (Status)) {
    
    //
    // Publish the Tiano Decompress protocol for use by other DXE components
    //    
    DecompressHandle = NULL;
    Status = CoreInstallProtocolInterface (
               &DecompressHandle,
               &gEfiCustomizedDecompressProtocolGuid,
               EFI_NATIVE_INTERFACE,
               gEfiCustomizedDecompress
               );
    ASSERT_EFI_ERROR (Status);
  }

  CoreGetPeiProtocol (&gEfiPeiFlushInstructionCacheGuid, &gEfiPeiFlushInstructionCache);

  CoreGetPeiProtocol (&gEfiPeiPeCoffLoaderGuid, &gEfiPeiPeCoffLoader);

  CoreGetPeiProtocol (&gEfiPeiTransferControlGuid, &gEfiPeiTransferControl);


  //
  // Register for the GUIDs of the Architectural Protocols, so the rest of the
  // EFI Boot Services and EFI Runtime Services tables can be filled in.
  //
  CoreNotifyOnArchProtocolInstallation ();

  //
  // Produce Firmware Volume Protocols, one for each FV in the HOB list.
  //
  Status = FwVolBlockDriverInit (gDxeCoreImageHandle, gST);
  ASSERT_EFI_ERROR (Status);

  Status = FwVolDriverInit (gDxeCoreImageHandle, gST);
  ASSERT_EFI_ERROR (Status);

  //
  // Produce the Section Extraction Protocol 
  //
  Status = InitializeSectionExtraction (gDxeCoreImageHandle, gST);
  ASSERT_EFI_ERROR (Status);


  //
  // Initialize Performance monitoring if enabled in build
  //
  PERF_ENABLE (0, gST, Tick);

  PERF_START (0,DXE_TOK, NULL, Tick) ;

  //
  // Initialize the DXE Dispatcher
  //
  PERF_START (0,L"CoreInitializeDispatcher", L"DxeMain", 0) ;
  CoreInitializeDispatcher ();
  PERF_END (0,L"CoreInitializeDispatcher", L"DxeMain", 0) ;

  //
  // Invoke the DXE Dispatcher
  //
  PERF_START (0, L"CoreDispatcher", L"DxeMain", 0);
  CoreDispatcher ();
  PERF_END (0, L"CoreDispatcher", L"DxeMain", 0);

  //
  // Display Architectural protocols that were not loaded if this is DEBUG build
  //
  DEBUG_CODE (
    CoreDisplayMissingArchProtocols ();
  )
  
  //
  // Assert if the Architectural Protocols are not present.
  //
  ASSERT_EFI_ERROR (CoreAllEfiServicesAvailable ());

  //
  // Report Status code before transfer control to BDS
  //
  CoreReportProgressCode ((EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT));

  //
  // Display any drivers that were not dispatched because dependency expression
  // evaluated to false if this is a debug build
  //
  DEBUG_CODE (
    CoreDisplayDiscoveredNotDispatched ();
  )

  //
  // Transfer control to the BDS Architectural Protocol
  //
  gBds->Entry (gBds);
  
  //
  // BDS should never return
  //
  ASSERT (FALSE);
  EFI_DEADLOOP ();
}


EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg0 (
  VOID
  )
/*++

Routine Description:

  Place holder function until all the Boot Services and Runtime Services are available

Arguments:

  None

Returns:

  EFI_NOT_AVAILABLE_YET

--*/
{
  //
  // This function should never be executed.  If it does, then the architectural protocols
  // have not been designed correctly.  The EFI_BREAKPOINT() is commented out for now until the
  // DXE Core and all the Architectural Protocols are complete.
  //

  return EFI_NOT_AVAILABLE_YET;
}

EFI_STATUS
EFIAPI
CoreEfiNotAvailableYetArg1 (
  UINTN Arg1
  )
/*++

Routine Description:

  Place holder function until all the Boot Services and Runtime Services are available

Arguments:

  Arg1        - Undefined

Returns:

  EFI_NOT_AVAILABLE_YET

--*/
{
  //
  // This function should never be executed.  If it does, then the architectural protocols
  // have not been designed correctly.  The EFI_BREAKPOINT() is commented out for now until the
  // DXE Core and all the Architectural Protocols are complete.
  //

  return EFI_NOT_AVAILABLE_YET;
}

⌨️ 快捷键说明

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