]> git.proxmox.com Git - mirror_edk2.git/blobdiff - DuetPkg/EfiLdr/EfiLoader.c
MdePkg/include: Add Acpi.h to DMAR table.
[mirror_edk2.git] / DuetPkg / EfiLdr / EfiLoader.c
index 382b7802a19d5186be02831646f0f88f01340e85..ac950b55fa6d70cf83a5354ee2226e18d74b93ab 100644 (file)
@@ -1,7 +1,7 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \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
@@ -22,6 +22,22 @@ Revision History:
 #include "Support.h"\r
 #include "Debug.h"\r
 #include "PeLoader.h"\r
+#include "LzmaDecompress.h"\r
+\r
+EFILDR_LOADED_IMAGE    DxeCoreImage;\r
+EFILDR_LOADED_IMAGE    DxeIplImage;\r
+\r
+VOID\r
+SystemHang (\r
+  CHAR8        *Message\r
+  )\r
+{\r
+  PrintString (\r
+    "%s## FATAL ERROR ##: Fail to load DUET images! System hang!\n",\r
+    Message\r
+    );\r
+  CpuDeadLoop();\r
+}\r
 \r
 VOID\r
 EfiLoader (\r
@@ -29,7 +45,6 @@ EfiLoader (
   )\r
 {\r
   BIOS_MEMORY_MAP       *BiosMemoryMap;    \r
-  EFILDR_HEADER         *EFILDRHeader;\r
   EFILDR_IMAGE          *EFILDRImage;\r
   EFI_MEMORY_DESCRIPTOR EfiMemoryDescriptor[EFI_MAX_MEMORY_DESCRIPTORS];\r
   EFI_STATUS            Status;\r
@@ -39,79 +54,78 @@ EfiLoader (
   UINTN                 BfvPageNumber;\r
   UINTN                 BfvBase;\r
   EFI_MAIN_ENTRYPOINT   EfiMainEntrypoint;\r
-  static EFILDRHANDOFF  Handoff;\r
-\r
-PrintHeader ('A');\r
+  EFILDRHANDOFF         Handoff;\r
+  UINTN                 Index;\r
 \r
   ClearScreen();\r
-  PrintString("EFI Loader\n");\r
-\r
-//  PrintString("&BiosMemoryMapBaseAddress = ");   \r
-//  PrintValue64 ((UINT64)(&BiosMemoryMapBaseAddress));\r
-//  PrintString("  BiosMemoryMapBaseAddress = ");   \r
-//  PrintValue(BiosMemoryMapBaseAddress);\r
-//  PrintString("\n");\r
+  \r
+  PrintHeader ('A');\r
+  \r
+  PrintString ("Enter DUET Loader...\n");\r
+  PrintString ("BiosMemoryMapBaseAddress = %x\n", (UINTN) BiosMemoryMapBaseAddress);\r
 \r
   //\r
   // Add all EfiConventionalMemory descriptors to the table.  If there are partial pages, then\r
-  // round the start address up to the next page, and round the length down to a page boundry.\r
+  // round the start address up to the next page, and round the length down to a page boundary.\r
   //\r
-  BiosMemoryMap = (BIOS_MEMORY_MAP *)(UINTN)(BiosMemoryMapBaseAddress);\r
+  BiosMemoryMap = (BIOS_MEMORY_MAP *) (UINTN) BiosMemoryMapBaseAddress;\r
   NumberOfMemoryMapEntries = 0;\r
   GenMemoryMap (&NumberOfMemoryMapEntries, EfiMemoryDescriptor, BiosMemoryMap);\r
 \r
+  PrintString ("Get %d entries of memory map!\n", NumberOfMemoryMapEntries);\r
+\r
   //\r
   // Get information on where the image is in memory\r
   //\r
-\r
-  EFILDRHeader = (EFILDR_HEADER *)(UINTN)(EFILDR_HEADER_ADDRESS);\r
   EFILDRImage  = (EFILDR_IMAGE *)(UINTN)(EFILDR_HEADER_ADDRESS + sizeof(EFILDR_HEADER));\r
 \r
-PrintHeader ('D');\r
 \r
   //\r
   // Point to the 4th image (Bfv)\r
   //\r
-    \r
   EFILDRImage += 3;\r
 \r
   //\r
   // Decompress the image\r
   //\r
-\r
-  Status = UefiDecompressGetInfo (\r
-             NULL, \r
+  PrintString (\r
+    "Decompress BFV image, Image Address = %x Offset = %x\n", \r
+    (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    (UINTN) EFILDRImage->Offset\r
+    );\r
+  Status = LzmaUefiDecompressGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              &DestinationSize, \r
              &ScratchSize\r
              );\r
+\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to get decompress information for BFV!\n");\r
   }\r
+  \r
+  PrintString ("BFV decompress: DestinationSize = %x, ScratchSize = %x\n", (UINTN) DestinationSize, (UINTN) ScratchSize);\r
+  Status =  LzmaUefiDecompress (\r
+    (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    EFILDRImage->Length,\r
+    (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, \r
+    (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)\r
+    );\r
+  \r
 \r
-  Status = TianoDecompress (\r
-             NULL, \r
-             (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
-             EFILDRImage->Length,\r
-             (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,\r
-             DestinationSize, \r
-             (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000),\r
-             ScratchSize\r
-             );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to decompress BFV!\n");\r
   }\r
 \r
   BfvPageNumber = EFI_SIZE_TO_PAGES (DestinationSize);\r
   BfvBase = (UINTN) FindSpace (BfvPageNumber, &NumberOfMemoryMapEntries, EfiMemoryDescriptor, EfiRuntimeServicesData, EFI_MEMORY_WB);\r
   if (BfvBase == 0) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to find free space to hold decompressed BFV\n");\r
   }\r
   ZeroMem ((VOID *)(UINTN)BfvBase, BfvPageNumber * EFI_PAGE_SIZE);\r
   CopyMem ((VOID *)(UINTN)BfvBase, (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS, DestinationSize);\r
 \r
-PrintHeader ('B');\r
+  PrintHeader ('B');\r
 \r
   //\r
   // Point to the 2nd image (DxeIpl)\r
@@ -122,31 +136,34 @@ PrintHeader ('B');
   //\r
   // Decompress the image\r
   //\r
+  PrintString (\r
+    "Decompress DxeIpl image, Image Address = %x Offset = %x\n", \r
+    (UINTN) (EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    (UINTN) EFILDRImage->Offset\r
+    );\r
 \r
-  Status = UefiDecompressGetInfo (\r
-             NULL, \r
+  Status = LzmaUefiDecompressGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              &DestinationSize, \r
              &ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to get decompress information for DxeIpl!\n");\r
   }\r
 \r
-  Status = TianoDecompress (\r
-             NULL, \r
+  Status = LzmaUefiDecompress (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,\r
-             DestinationSize, \r
-             (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000),\r
-             ScratchSize\r
+             (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to decompress DxeIpl image\n");\r
   }\r
 \r
+  PrintString ("Start load DxeIpl PE image\n");  \r
+\r
   //\r
   // Load and relocate the EFI PE/COFF Firmware Image \r
   //\r
@@ -157,47 +174,48 @@ PrintHeader ('B');
              EfiMemoryDescriptor\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to load and relocate DxeIpl PE image!\n");\r
   }\r
-\r
-//  PrintString("Image.NoPages = ");   \r
-//  PrintValue(Image.NoPages);\r
-//  PrintString("\n");\r
+  PrintString (\r
+    "DxeIpl PE image is successed loaded at %lx, entry=%p\n",\r
+    DxeIplImage.ImageBasePage,\r
+    DxeIplImage.EntryPoint\r
+    );\r
 \r
 PrintHeader ('C');\r
 \r
   //\r
   // Point to the 3rd image (DxeMain)\r
   //\r
-    \r
   EFILDRImage++;\r
 \r
   //\r
   // Decompress the image\r
   //\r
+  PrintString (\r
+    "Decompress DxeMain FV image, Image Address = %x Offset = %x\n",\r
+    (UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
+    (UINTN) EFILDRImage->Offset\r
+    );\r
 \r
-  Status = UefiDecompressGetInfo (\r
-             NULL, \r
+  Status = LzmaUefiDecompressGetInfo (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
              EFILDRImage->Length,\r
              &DestinationSize, \r
              &ScratchSize\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to get decompress information for DxeMain FV image!\n");\r
   }\r
 \r
-  Status = TianoDecompress (\r
-             NULL, \r
+  Status = LzmaUefiDecompress (\r
              (VOID *)(UINTN)(EFILDR_HEADER_ADDRESS + EFILDRImage->Offset),\r
-             EFILDRImage->Length,\r
+              EFILDRImage->Length,\r
              (VOID *)(UINTN)EFI_DECOMPRESSED_BUFFER_ADDRESS,\r
-             DestinationSize, \r
-             (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000),\r
-             ScratchSize\r
+             (VOID *)(UINTN)((EFI_DECOMPRESSED_BUFFER_ADDRESS + DestinationSize + 0x1000) & 0xfffff000)\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to decompress DxeMain FV image!\n");\r
   }\r
 \r
   //\r
@@ -210,30 +228,26 @@ PrintHeader ('C');
              EfiMemoryDescriptor\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    CpuDeadLoop();\r
+    SystemHang ("Failed to load/relocate DxeMain!\n");\r
   }\r
+  PrintString (\r
+    "DxeCore PE image is successed loaded at %lx, entry=%p\n",\r
+    DxeCoreImage.ImageBasePage,\r
+    DxeCoreImage.EntryPoint\r
+    );\r
 \r
 PrintHeader ('E');\r
 \r
   //\r
   // Display the table of memory descriptors.\r
   //\r
-\r
-//  PrintString("\nEFI Memory Descriptors\n");   \r
-/*\r
-  {\r
-  UINTN Index;\r
+  PrintString ("\nEFI Memory Descriptors\n");   \r
   for (Index = 0; Index < NumberOfMemoryMapEntries; Index++) {\r
-    PrintString("Type = ");   \r
-    PrintValue(EfiMemoryDescriptor[Index].Type);\r
-    PrintString("  Start = ");   \r
-    PrintValue((UINT32)(EfiMemoryDescriptor[Index].PhysicalStart));\r
-    PrintString("  NumberOfPages = ");   \r
-    PrintValue((UINT32)(EfiMemoryDescriptor[Index].NumberOfPages));\r
-    PrintString("\n");\r
-  }\r
+    PrintString (\r
+      "Type = %x Start = %08lx NumberOfPages = %08lx\n",\r
+      EfiMemoryDescriptor[Index].Type, EfiMemoryDescriptor[Index].PhysicalStart, EfiMemoryDescriptor[Index].NumberOfPages\r
+      );\r
   }\r
-*/\r
 \r
   //\r
   // Jump to EFI Firmware\r
@@ -251,7 +265,9 @@ PrintHeader ('E');
     Handoff.DxeCoreImageSize  = DxeCoreImage.NoPages * EFI_PAGE_SIZE;\r
     Handoff.DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreImage.EntryPoint;\r
 \r
-    EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT)(UINTN)DxeIplImage.EntryPoint;\r
+    PrintString ("Transfer to DxeIpl ...EntryPoint = %p\n", DxeIplImage.EntryPoint);\r
+    \r
+    EfiMainEntrypoint = (EFI_MAIN_ENTRYPOINT) DxeIplImage.EntryPoint;\r
     EfiMainEntrypoint (&Handoff);\r
   }\r
 \r
@@ -261,6 +277,18 @@ PrintHeader ('F');
   // There was a problem loading the image, so HALT the system.\r
   //\r
 \r
-  CpuDeadLoop();\r
+  SystemHang ("Failed to jump to DxeIpl!\n");\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+_ModuleEntryPoint (\r
+  UINT32    BiosMemoryMapBaseAddress\r
+  )\r
+{\r
+  SerialPortInitialize ();\r
+  EfiLoader(BiosMemoryMapBaseAddress);\r
+  return EFI_SUCCESS;\r
 }\r
 \r
+\r