29.8 UEFI Driver Entry Point

The entry point to an EBC compiled image is a function is always called EfiStart(). This is the function that is shown as the entry point in the PE/COFF image that is produced by an EBC compile/link operation. The EfiStart() function performs the EBC runtime initialization that may vary from one UEFI Driver to another. At the end of the EBC runtime initialization, the function EfiMain() is called. The EDK II build system and libraries take care of these details, so a UEFI Driver implementation never contains functions with these names. In fact, the symbols EfiStart() and EfiMain() must be considered reserved, and cannot be used as function names or variable names in any UEFI driver implementation that is compiled for EBC.

The INF file for a UEFI Driver declares the C entry point in the [Defines] section in a define called ENTRY_POINT. All UEFI Drivers are linked to the EDK II library instance from the MdePkg called UefiDriverEntryPoint, and the UefiDriverEntryPoint library instance is responsible for calling the library constructors for all the libraries that a UEFI Driver is using either directly or indirectly. Once all the library constructors have been called, control is transferred to the ENTRY_POINT function defined in the INF file. This is where the C sources for a UEFI Driver implementation begin and the driver specific initialization is performed.

The sequence of calls in a UEFI Driver entry point compiled for EBC is as follows:

  • EfiStart() - PE/COFF entry point that performs the required EBC runtime initialization. Calls EfiMain().

  • EfiMain() - Calls _ModuleEntryPoint()

  • _ModuleEntryPoint() - Calls EDK II library constructors. Calls ENTRY_POINT function defined in INF file.

  • ENTRY_POINT function - Performs UEFI Driver specific initialization.

Knowledge of this specific sequence of calls is not typically required by a UEFI Driver developer because it is very rare for anything to go wrong in EfiStart(), EfiMain() or _ModuleEntryPoint() functions. However, if a UEFI Driver compiled for EBC is being debugged, it is important to know that these extra actions do occur between the entry point of the PE/COFF image and the first line of C source code in the UEFI Driver implementation.