init.c
来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 730 行 · 第 1/2 页
C
730 行
//
// Connect all EFI 1.1 drivers to get banner out to all consoles.
//
POST_CODE(0x18);
ConnectAll();
EFIFirmwareBanner();
PlPrintLogonBanner();
Print (L"This image %HMainEntry%N is at address %08x\n", (UINTN)MainEntry);
//
// Create an event to be signalled when ExitBootServices occurs
//
POST_CODE(0x19);
Status = BS->CreateEvent(
EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_NOTIFY,
PlExitBootServices,
NULL,
&Event
);
ASSERT (!EFI_ERROR(Status));
#ifdef EFI_BOOTSHELL
PlInitializeInternalLoad();
#endif
POST_CODE(0x1a);
PlInitializeLegacyBoot();
POST_CODE(0x1b);
//
// loop thru boot manager and boot maintenance until a boot
// option is selected
//
while (TRUE) {
//
// The platform code is ready to boot the machine. Pass control
// to the boot manager
//
LOAD_INTERNAL_DRIVER(
FW,
IMAGE_SUBSYSTEM_EFI_APPLICATION,
L"bootmgr",
InitializeBootManager
);
//
// If we return from above, means that no boot choices were found
// or boot maintenance chosen. hence invoke boot maintenance menu
//
LOAD_INTERNAL_DRIVER(
FW,
IMAGE_SUBSYSTEM_EFI_APPLICATION,
L"bmaint",
InitializeBootMaintenance
);
}
}
#ifdef EFI_BOOTSHELL
//
// Global Data
//
STATIC BOOLEAN ShellToolsLoaded = FALSE;
VOID
PlStartShell (
VOID
)
{
if (ShellToolsLoaded == FALSE) {
PlLoadShellTools();
PlLoadShellDebugTools();
PlLoadShellAdditionalTools();
ShellToolsLoaded = TRUE;
}
PlLoadShell();
}
#endif
STATIC
VOID
PlInitializeTables (
)
/*++
Routine Description:
Initialization function called to obtain and update any
global table information or entry points that are in:
SystemTable
SystemTable->BootServices
SystemTAble->RuntimeServices
Arguments:
None
Returns:
Tables set and updated
--*/
{
//
// Initialize the platform table
//
PlTable.EmulateLoad = NULL;
PlTable.IdleLoop = PlIdleLoop;
PlTable.SetInterruptState = PlSetInterruptState;
PlTable.FlushCache = RtPlCacheFlush;
PlTable.SetVirtualAddressMap = RtPlSetVirtualAddressMap;
PlTable.SI_HandoffState = NULL;
PlTable.EI_ReturnState = NULL;
//
// Call the EFI FW's entry point and get back the initial
// Firwmare and SystemTable
//
EFIEntryPoint (&PlTable, &FW, &ST);
BS = ST->BootServices;
RT = ST->RuntimeServices;
//
// Update / provide any entries in the boot services table
// The core EFI firmware does not provide the following
// entries in the boot services table:
// Stal
//
BS->Stall = RtPlStall;
BS->SetWatchdogTimer = PlSetWatchdogTimer;
//
// Update / provide any entries in the runtime service table.
// The core EFI firmware does not provide the following
// entries in the runtime services table:
RT->ResetSystem = RtPlResetSystem;
RT->GetTime = RtPlGetTime;
RT->SetTime = RtPlSetTime;
RT->GetWakeupTime = RtPlGetWakeupTime;
RT->SetWakeupTime = RtPlSetWakeupTime;
ST->NumberOfTableEntries = 0;
ST->ConfigurationTable = NULL;
//
// Done with table initializations
//
}
STATIC
VOID
PlInstallMemoryMap (
IN UINTN NoDesc,
IN EFI_MEMORY_DESCRIPTOR *Desc
)
/*++
Routine Description:
Called to initialize the memory map descriptors for
the system's memory map.
N.B. The FW requires that the first call be of type
"ConventialMemory".
N.B. The FW requires that page 0 in the map is not
not ConventialMemory. (Note the emulator can work
around this by reporting page 0 as BootServicesData
memory if needed. The page is then not used at
Boot Services time, but it available in the memory
map for later use)
Arguments:
NoDesc - Number of desc in Desc
Desc - The passed in memory map
Returns:
Memory map descriptors added
--*/
{
UINTN Index, BestIndex;
UINT64 BestSize;
//
// Find the largest available free memory descriptor
// and add it first
//
BestIndex = NoDesc;
BestSize = 0;
for (Index=0; Index < NoDesc; Index += 1) {
if (Desc[Index].Type == EfiConventionalMemory &&
Desc[Index].NumberOfPages > BestSize) {
BestIndex = Index;
BestSize = Desc[Index].NumberOfPages;
}
}
ASSERT (BestIndex < NoDesc);
FW->AddMemoryDescriptor (
Desc[BestIndex].Type,
Desc[BestIndex].PhysicalStart,
Desc[BestIndex].NumberOfPages,
Desc[BestIndex].Attribute
);
//
// Now add all remaining information to the memory map
//
for (Index=0; Index < NoDesc; Index += 1) {
if (Index != BestIndex) {
FW->AddMemoryDescriptor (
Desc[Index].Type,
Desc[Index].PhysicalStart,
Desc[Index].NumberOfPages,
Desc[Index].Attribute
);
}
}
}
STATIC
VOID
PlInstallBaseDevices (
)
/*++
Routine Description:
Add handles to the base devices here. In particular
the console devices, internal nvram device(s), and
the timer tick handler.
Variable store support is not enabled at this time.
(The firware needs the nvram & system volume devices
to enable such support)
Arguments:
None
Returns:
Base device handles added
--*/
{
EFI_DEVICE_PATH *DevicePath;
EFI_HANDLE Handle;
EFI_STATUS Status;
BS->InstallConfigurationTable(&AcpiTableGuid, FindAcpiRsdPtr());
BS->InstallConfigurationTable(&MpsTableGuid, FindMPSPtr());
BS->InstallConfigurationTable(&SMBIOSTableGuid, FindSMBIOSPtr());
//
//
// First add a device(s) to handle device_io request
// (this is done since the next devices may need to access
// their IO space)
//
// On a PC there's only global IO, and the firwmare is
// nice enough to provide us with a driver that does just
// that... add it
PlInstallDefaultIoDevice (
BiosRootDevicePath,
0x0000000000000000, // Force non cachable access
0x0000000000000000
);
//
// Set up the GlobalIoFncs global to point to global memory/io/pci space
//
DevicePath = BiosRootDevicePath;
Status = BS->LocateDevicePath (&DeviceIoProtocol, &DevicePath, &Handle);
if (!EFI_ERROR(Status)) {
Status = BS->HandleProtocol (Handle, &DeviceIoProtocol, &GlobalIoFncs);
}
ASSERT (!EFI_ERROR(Status));
//
// Initialize to PCI Root Bus List
//
InitializePciRootBusList (&PciRootBusList);
//
// Install the Unicode string device. This device supports
// case insensitive comparisons of Unicode strings.
//
PlInitializeUnicodeStringDevice();
}
STATIC
VOID
PlIdleLoop (
IN BOOLEAN Polling
)
{
}
STATIC
VOID
PlExitBootServices (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Signal handlers for ExitBootServices event
Arguments:
Event type
Context fo the event
Returns:
--*/
{
//
// Cancel Timer
//
PlDisableTimerInterrupt();
//
// Clear non-runtime pointer
//
PlTable.EmulateLoad = NULL;
PlTable.IdleLoop = NULL;
PlTable.SetInterruptState = NULL;
// EFI f/w takes care of boot service's table
}
STATIC
VOID
InitTickHandler(
VOID
)
{
PlCalibrateCpuFreq();
InstallInterruptHandler(PlGetVectorFromIrq (0), SystemTimerHandler);
PlEnableTimerInterrupt();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?