+++ /dev/null
-/** @file\r
-\r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
- DxeInit.c\r
-\r
-Abstract:\r
-\r
-Revision History:\r
-\r
-**/\r
-\r
-#include "DxeIpl.h"\r
-\r
-#include "LegacyTable.h"\r
-#include "HobGeneration.h"\r
-#include "PpisNeededByDxeCore.h"\r
-#include "Debug.h"\r
-\r
-/*\r
---------------------------------------------------------\r
- Memory Map: (XX=32,64)\r
---------------------------------------------------------\r
-0x0\r
- IVT\r
-0x400\r
- BDA\r
-0x500\r
-\r
-0x7C00\r
- BootSector\r
-0x10000\r
- EfiLdr (relocate by efiXX.COM)\r
-0x15000\r
- Efivar.bin (Load by StartXX.COM)\r
-0x20000\r
- StartXX.COM (E820 table, Temporary GDT, Temporary IDT)\r
-0x21000\r
- EfiXX.COM (Temporary Interrupt Handler)\r
-0x22000\r
- EfiLdr.efi + DxeIpl.Z + DxeMain.Z + BFV.Z\r
-0x86000\r
- MemoryFreeUnder1M (For legacy driver DMA)\r
-0x90000\r
- Temporary 4G PageTable for X64 (6 page)\r
-0x9F800\r
- EBDA\r
-0xA0000\r
- VGA\r
-0xC0000\r
- OPROM\r
-0xE0000\r
- FIRMEWARE\r
-0x100000 (1M)\r
- Temporary Stack (1M)\r
-0x200000\r
-\r
-MemoryAbove1MB.PhysicalStart <-----------------------------------------------------+\r
- ... |\r
- ... |\r
- <- Phit.EfiMemoryBottom -------------------+ |\r
- HOB | |\r
- <- Phit.EfiFreeMemoryBottom | |\r
- | MemoryFreeAbove1MB.ResourceLength\r
- <- Phit.EfiFreeMemoryTop ------+ | |\r
- MemoryDescriptor (For ACPINVS, ACPIReclaim) | 4M = CONSUMED_MEMORY |\r
- | | |\r
- Permament 4G PageTable for IA32 or MemoryAllocation | |\r
- Permament 64G PageTable for X64 | | |\r
- <------------------------------+ | |\r
- Permament Stack (0x20 Pages = 128K) | |\r
- <- Phit.EfiMemoryTop ----------+-----------+---------------+\r
- NvFV (64K) |\r
- MMIO\r
- FtwFV (128K) | \r
- <----------------------------------------------------------+<---------+\r
- DxeCore | |\r
- DxeCore |\r
- DxeIpl | Allocated in EfiLdr\r
- <----------------------------------------------------------+ |\r
- BFV MMIO |\r
- <- Top of Free Memory reported by E820 --------------------+<---------+\r
- ACPINVS or\r
- ACPIReclaim or\r
- Reserved\r
- <- Memory Top on RealMemory\r
-\r
-0x100000000 (4G)\r
-\r
-MemoryFreeAbove4G.Physicalstart <--------------------------------------------------+\r
- |\r
- |\r
- MemoryFreeAbove4GB.ResourceLength\r
- |\r
- |\r
- <--------------------------------------------------+\r
-*/\r
-\r
-VOID\r
-EnterDxeMain (\r
- IN VOID *StackTop,\r
- IN VOID *DxeCoreEntryPoint,\r
- IN VOID *Hob,\r
- IN VOID *PageTable\r
- );\r
-\r
-VOID\r
-DxeInit (\r
- IN EFILDRHANDOFF *Handoff\r
- )\r
-/*++\r
-\r
- Routine Description:\r
-\r
- This is the entry point after this code has been loaded into memory. \r
-\r
-Arguments:\r
-\r
-\r
-Returns:\r
-\r
- Calls into EFI Firmware\r
-\r
---*/\r
-{\r
- VOID *StackTop;\r
- VOID *StackBottom;\r
- VOID *PageTableBase;\r
- VOID *MemoryTopOnDescriptor;\r
- VOID *MemoryDescriptor;\r
- VOID *NvStorageBase;\r
- EFILDRHANDOFF HandoffCopy;\r
-\r
- CopyMem ((VOID*) &HandoffCopy, (VOID*) Handoff, sizeof (EFILDRHANDOFF));\r
- Handoff = &HandoffCopy;\r
-\r
- ClearScreen();\r
-\r
- PrintString (\r
- "Enter DxeIpl ...\n"\r
- "Handoff:\n"\r
- "Handoff.BfvBase = %p, BfvLength = %x\n"\r
- "Handoff.DxeIplImageBase = %p, DxeIplImageSize = %x\n"\r
- "Handoff.DxeCoreImageBase = %p, DxeCoreImageSize = %x\n",\r
- Handoff->BfvBase, Handoff->BfvSize,\r
- Handoff->DxeIplImageBase, Handoff->DxeIplImageSize,\r
- Handoff->DxeCoreImageBase, Handoff->DxeCoreImageSize\r
- );\r
-\r
- //\r
- // Hob Generation Guild line:\r
- // * Don't report FV as physical memory\r
- // * MemoryAllocation Hob should only cover physical memory\r
- // * Use ResourceDescriptor Hob to report physical memory or Firmware Device and they shouldn't be overlapped\r
- PrintString ("Prepare Cpu HOB information ...\n");\r
- PrepareHobCpu ();\r
-\r
- //\r
- // 1. BFV\r
- //\r
- PrintString ("Prepare BFV HOB information ...\n");\r
- PrepareHobBfv (Handoff->BfvBase, Handoff->BfvSize);\r
-\r
- //\r
- // 2. Updates Memory information, and get the top free address under 4GB\r
- //\r
- PrintString ("Prepare Memory HOB information ...\n");\r
- MemoryTopOnDescriptor = PrepareHobMemory (Handoff->MemDescCount, Handoff->MemDesc);\r
- \r
- //\r
- // 3. Put [NV], [Stack], [PageTable], [MemDesc], [HOB] just below the [top free address under 4GB]\r
- //\r
- \r
- // 3.1 NV data\r
- PrintString ("Prepare NV Storage information ...\n");\r
- NvStorageBase = PrepareHobNvStorage (MemoryTopOnDescriptor);\r
- PrintString ("NV Storage Base = %p\n", NvStorageBase);\r
- // 3.2 Stack\r
- StackTop = NvStorageBase;\r
- StackBottom = PrepareHobStack (StackTop);\r
- PrintString ("Stack Top=0x%x, Stack Bottom=0x%x\n", StackTop, StackBottom);\r
- // 3.3 Page Table\r
- PageTableBase = PreparePageTable (StackBottom, gHob->Cpu.SizeOfMemorySpace);\r
- // 3.4 MemDesc (will be used in PlatformBds)\r
- MemoryDescriptor = PrepareHobMemoryDescriptor (PageTableBase, Handoff->MemDescCount, Handoff->MemDesc);\r
- // 3.5 Copy the Hob itself to EfiMemoryBottom, and update the PHIT Hob\r
- PrepareHobPhit (StackTop, MemoryDescriptor);\r
-\r
- //\r
- // 4. Register the memory occupied by DxeCore and DxeIpl together as DxeCore\r
- //\r
- PrintString ("Prepare DxeCore memory Hob ...\n");\r
- PrepareHobDxeCore (\r
- Handoff->DxeCoreEntryPoint,\r
- (EFI_PHYSICAL_ADDRESS)(UINTN)Handoff->DxeCoreImageBase,\r
- (UINTN)Handoff->DxeIplImageBase + (UINTN)Handoff->DxeIplImageSize - (UINTN)Handoff->DxeCoreImageBase\r
- );\r
-\r
- PrepareHobLegacyTable (gHob);\r
- \r
- PreparePpisNeededByDxeCore (gHob);\r
-\r
- CompleteHobGeneration ();\r
-\r
- //\r
- // Print Hob Info\r
- //\r
- ClearScreen();\r
- PrintString (\r
- "HobStart = %p\n"\r
- "Memory Top = %lx, Bottom = %lx\n"\r
- "Free Memory Top = %lx, Bottom = %lx\n"\r
- "NvStorageFvb = %lx, Length = %lx\n"\r
- "BfvResource = %lx, Length = %lx\n"\r
- "NvStorageFvResource = %lx, Length = %lx\n"\r
- "NvStorage = %lx, Length = %lx\n"\r
- "NvFtwFvResource = %lx, Length = %lx\n"\r
- "NvFtwWorking = %lx, Length = %lx\n"\r
- "NvFtwSpare = %lx, Length = %lx\n"\r
- "Stack = %lx, StackLength = %lx\n"\r
- "PageTable = %p\n"\r
- "MemoryFreeUnder1MB = %lx, MemoryFreeUnder1MBLength = %lx\n"\r
- "MemoryAbove1MB = %lx, MemoryAbove1MBLength = %lx\n"\r
- "MemoryAbove4GB = %lx, MemoryAbove4GBLength = %lx\n"\r
- "DxeCore = %lx, DxeCoreLength = %lx\n"\r
- "MemoryAllocation = %lx, MemoryLength = %lx\n"\r
- "$",\r
- gHob,\r
- gHob->Phit.EfiMemoryTop, gHob->Phit.EfiMemoryBottom,\r
- gHob->Phit.EfiFreeMemoryTop, gHob->Phit.EfiFreeMemoryBottom,\r
- gHob->NvStorageFvb.FvbInfo.Entries[0].Base, gHob->NvFtwFvb.FvbInfo.Entries[0].Length,\r
- gHob->BfvResource.PhysicalStart, gHob->BfvResource.ResourceLength,\r
- gHob->NvStorageFvResource.PhysicalStart, gHob->NvStorageFvResource.ResourceLength,\r
- gHob->NvStorage.FvbInfo.Entries[0].Base, gHob->NvStorage.FvbInfo.Entries[0].Length,\r
- gHob->NvFtwFvResource.PhysicalStart, gHob->NvFtwFvResource.ResourceLength,\r
- gHob->NvFtwWorking.FvbInfo.Entries[0].Base, gHob->NvFtwWorking.FvbInfo.Entries[0].Length,\r
- gHob->NvFtwSpare.FvbInfo.Entries[0].Base, gHob->NvFtwSpare.FvbInfo.Entries[0].Length,\r
- gHob->Stack.AllocDescriptor.MemoryBaseAddress, gHob->Stack.AllocDescriptor.MemoryLength,\r
- PageTableBase,\r
- gHob->MemoryFreeUnder1MB.PhysicalStart, gHob->MemoryFreeUnder1MB.ResourceLength,\r
- gHob->MemoryAbove1MB.PhysicalStart, gHob->MemoryAbove1MB.ResourceLength,\r
- gHob->MemoryAbove4GB.PhysicalStart, gHob->MemoryAbove4GB.ResourceLength,\r
- gHob->DxeCore.MemoryAllocationHeader.MemoryBaseAddress, gHob->DxeCore.MemoryAllocationHeader.MemoryLength,\r
- gHob->MemoryAllocation.AllocDescriptor.MemoryBaseAddress, gHob->MemoryAllocation.AllocDescriptor.MemoryLength\r
- );\r
-\r
- ClearScreen();\r
- PrintString (\r
- "\n\n\n\n\n\n\n\n\n\n"\r
- " WELCOME TO EFI WORLD!\n"\r
- );\r
- \r
- EnterDxeMain (StackTop, Handoff->DxeCoreEntryPoint, gHob, PageTableBase);\r
- PrintString ("Fail to enter DXE main!\n");\r
- \r
- //\r
- // Should never get here\r
- //\r
- CpuDeadLoop ();\r
-}\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-_ModuleEntryPoint (\r
- IN EFILDRHANDOFF *Handoff\r
- )\r
-{\r
- DxeInit(Handoff);\r
- return EFI_SUCCESS;\r
-}\r