]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/PrePi/PrePi.c
Arm Packages: Fix builds for XCODE32 toolchain
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
index c4060d9b6369543482edd7c7f54cd94f38aebb66..8eab7645a5c33146c6ca2178f7282590dd049b4d 100755 (executable)
 \r
 #include <Ppi/GuidedSectionExtraction.h>\r
 #include <Guid/LzmaDecompress.h>\r
+#include <Guid/ArmGlobalVariableHob.h>\r
 \r
 #include "PrePi.h"\r
 #include "LzmaDecompress.h"\r
 \r
+#define IS_XIP() ((FixedPcdGet32 (PcdFdBaseAddress) > (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
+                  ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
+\r
+// Not used when PrePi in run in XIP mode\r
+UINTN mGlobalVariableBase = 0;\r
+\r
 VOID\r
 PrePiCommonExceptionEntry (\r
   IN UINT32 Entry,\r
@@ -48,9 +55,28 @@ LzmaDecompressLibConstructor (
   VOID\r
   );\r
 \r
+VOID\r
+EFIAPI\r
+BuildGlobalVariableHob (\r
+  IN EFI_PHYSICAL_ADDRESS         GlobalVariableBase,\r
+  IN UINT32                       GlobalVariableSize\r
+  )\r
+{\r
+  ARM_HOB_GLOBAL_VARIABLE  *Hob;\r
+\r
+  Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
+  ASSERT(Hob != NULL);\r
+\r
+  CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
+  Hob->GlobalVariableBase = GlobalVariableBase;\r
+  Hob->GlobalVariableSize = GlobalVariableSize;\r
+}\r
+\r
 VOID\r
 PrePiMain (\r
   IN  UINTN                     UefiMemoryBase,\r
+  IN  UINTN                     StacksBase,\r
+  IN  UINTN                     GlobalVariableBase,\r
   IN  UINT64                    StartTimeStamp\r
   )\r
 {\r
@@ -58,9 +84,12 @@ PrePiMain (
   EFI_STATUS                    Status;\r
   CHAR8                         Buffer[100];\r
   UINTN                         CharCount;\r
-  UINTN                         UefiMemoryTop;\r
   UINTN                         StacksSize;\r
-  UINTN                         StacksBase;\r
+\r
+  // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
+  ASSERT (IS_XIP() || \r
+          ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
+           ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
 \r
   // Enable program flow prediction, if supported.\r
   ArmEnableBranchPrediction ();\r
@@ -78,12 +107,9 @@ PrePiMain (
   InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
   SaveAndSetDebugTimerInterrupt (TRUE);\r
 \r
-  UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
-  StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores);\r
-  StacksBase = UefiMemoryTop - StacksSize;\r
-\r
-  // Check the PcdCPUCoresNonSecStackBase match with the calculated StackBase\r
-  ASSERT (StacksBase == PcdGet32 (PcdCPUCoresNonSecStackBase));\r
+  if (!IS_XIP()) {\r
+    mGlobalVariableBase = GlobalVariableBase;\r
+  }\r
   \r
   // Declare the PI/UEFI memory region\r
   HobList = HobConstructor (\r
@@ -99,8 +125,15 @@ PrePiMain (
   ASSERT_EFI_ERROR (Status);\r
 \r
   // Create the Stacks HOB (reserve the memory for all stacks)\r
+  StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
   BuildStackHob (StacksBase, StacksSize);\r
 \r
+  // Declare the Global Variable HOB\r
+  BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r
+\r
+  //TODO: Call CpuPei as a library\r
+  BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
+\r
   // Set the Boot Mode\r
   SetBootMode (ArmPlatformGetBootMode ());\r
 \r
@@ -136,13 +169,15 @@ PrePiMain (
 \r
 VOID\r
 CEntryPoint (\r
-  IN  UINTN                     CoreId,\r
-  IN  UINTN                     UefiMemoryBase\r
+  IN  UINTN                     MpId,\r
+  IN  UINTN                     UefiMemoryBase,\r
+  IN  UINTN                     StacksBase,\r
+  IN  UINTN                     GlobalVariableBase\r
   )\r
 {\r
   UINT64   StartTimeStamp;\r
  \r
-  if ((CoreId == ARM_PRIMARY_CORE) && PerformanceMeasurementEnabled ()) {\r
+  if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
     // Initialize the Timer Library to setup the Timer HW controller\r
     TimerConstructor ();\r
     // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
@@ -168,11 +203,11 @@ CEntryPoint (
   ArmWriteVBar ((UINT32)PrePiVectorTable);\r
 \r
   // If not primary Jump to Secondary Main\r
-  if (CoreId == ARM_PRIMARY_CORE) {\r
+  if (IS_PRIMARY_CORE(MpId)) {\r
     // Goto primary Main.\r
-    PrimaryMain (UefiMemoryBase, StartTimeStamp);\r
+    PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
   } else {\r
-    SecondaryMain (CoreId);\r
+    SecondaryMain (MpId);\r
   }\r
 \r
   // DXE Core should always load and never return\r