]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/PrePi/ModuleEntryPoint.S
ArmPlatformPkg: Change the memory model for the ARM Platform components
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.S
index 0857024a2778d18310170be18ff3c89ab373bacd..a8c779fba914249191339e5748eec46acd86cb51 100755 (executable)
 #include <Library/PcdLib.h>\r
 #include <AutoGen.h>\r
 \r
-#start of the code section\r
 .text\r
 .align 3\r
 \r
-#global symbols referenced by this module\r
+# Global symbols referenced by this module\r
 GCC_ASM_IMPORT(CEntryPoint)\r
+GCC_ASM_EXPORT(_ModuleEntryPoint)\r
 \r
 StartupAddr: .word    CEntryPoint\r
 \r
-#make _ModuleEntryPoint as global\r
-GCC_ASM_EXPORT(_ModuleEntryPoint)\r
-\r
 \r
 ASM_PFX(_ModuleEntryPoint):\r
   // Identify CPU ID\r
   mrc   p15, 0, r0, c0, c0, 5\r
   and   r0, #0xf\r
 \r
-_UefiMemoryBase:\r
-#if FixedPcdGet32(PcdStandalone)\r
+_SetSVCMode:\r
+  // Enter SVC mode\r
+  mov     r1, #0x13|0x80|0x40\r
+  msr     CPSR_c, r1\r
+\r
+// Check if we can install the size at the top of the System Memory or if we need\r
+// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
+// at the top of the DRAM)\r
+_SetupStackPosition:\r
   // Compute Top of System Memory\r
   LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)\r
   LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)\r
   add   r1, r1, r2      // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
-#else\r
-  // If it is not a Standalone, we must compute the top of the UEFI memory with the base of the FD\r
-  LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r1)\r
-#endif\r
 \r
-  // Compute Base of UEFI Memory\r
-  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r2)\r
-  sub   r1, r1, r2      // r1 = SystemMemoryTop - PcdSystemMemoryUefiRegionSize = UefiMemoryBase\r
+  // Calculate Top of the Firmware Device\r
+  LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)\r
+  LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)\r
+  add   r3, r3, r2      // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize\r
+\r
+  // UEFI Memory Size (stacks are allocated in this region)\r
+  LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
+\r
+  //\r
+  // Reserve the memory for the UEFI region (contain stacks on its top)\r
+  //\r
+\r
+  // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
+  subs r5, r1, r3              // r5 = SystemMemoryTop - FdTop\r
+  bmi  _SetupStack             // Jump if negative (FdTop > SystemMemoryTop)\r
+  cmp  r5, r4\r
+  bge  _SetupStack\r
+\r
+  // Case the top of stacks is the FdBaseAddress\r
+  mov  r1, r2\r
 \r
 _SetupStack:\r
   // Compute Base of Normal stacks for CPU Cores\r
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r2)\r
-  mul   r3, r0, r2      // r3 = core_id * stack_size = offset from the stack base\r
-  sub   sp, r1, r3      // r3 = UefiMemoryBase - StackOffset = TopOfStack\r
+  LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)\r
+  mul   r3, r0, r5      // r3 = core_id * stack_size = offset from the stack base\r
+  sub   sp, r1, r3      // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack\r
+\r
+  // Calculate the Base of the UEFI Memory\r
+  sub  r1, r1, r4\r
 \r
-  // Only allocate memory in top of the primary core stack\r
+  // Only allocate memory for global variables at top of the primary core stack\r
   cmp   r0, #0\r
   bne   _PrepareArguments\r
 \r
-_AllocateGlobalPeiVariables:\r
+_AllocateGlobalPrePiVariables:\r
   // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)\r
   LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)\r
   // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack\r
@@ -69,16 +89,12 @@ _AllocateGlobalPeiVariables:
   sub   sp, sp, r4\r
 \r
 _PrepareArguments:\r
-  // Pass the StackBase to the C Entrypoint (UefiMemoryBase - StackSize - StackOffset)\r
-  sub   r2, r1, r2\r
-  sub   r2, r3\r
   // Move sec startup address into a data register\r
   // Ensure we're jumping to FV version of the code (not boot remapped alias)\r
-  ldr   r3, StartupAddr\r
+  ldr   r2, StartupAddr\r
 \r
-  // jump to PrePiCore C code\r
+  // Jump to PrePiCore C code\r
   //    r0 = core_id\r
   //    r1 = UefiMemoryBase\r
-  //    r2 = StackBase\r
-  blx   r3\r
+  blx   r2\r
 \r