]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/PrePi/ModuleEntryPoint.asm
ArmPkg/ArmCpuLib: Replaced complex functions ArmCpuSynchronizeWait & ArmCpuSynchroniz...
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.asm
index 2c798d09d7b853062cb2ed057628e015365575ca..1e1938c8f3b5d1596f42db6456038a27c069a420 100644 (file)
@@ -1,5 +1,5 @@
 //\r
-//  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+//  Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
 //\r
 //  This program and the accompanying materials\r
 //  are licensed and made available under the terms and conditions of the BSD License\r
@@ -20,7 +20,7 @@
   \r
   IMPORT  CEntryPoint\r
   IMPORT  ArmReadMpidr\r
-  IMPORT  ArmIsMPCore\r
+  IMPORT  ArmIsMpCore\r
   EXPORT  _ModuleEntryPoint\r
 \r
   PRESERVE8\r
@@ -35,7 +35,7 @@ _ModuleEntryPoint
   and   r5, r0, r1\r
 \r
 _SetSVCMode\r
-  // Enter SVC mode\r
+  // Enter SVC mode, Disable FIQ and IRQ\r
   mov     r1, #0x13|0x80|0x40\r
   msr     CPSR_c, r1\r
 \r
@@ -46,12 +46,14 @@ _SetupStackPosition
   // Compute Top of System Memory\r
   LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)\r
   LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)\r
+  sub   r2, r2, #1\r
   add   r1, r1, r2      // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
 \r
   // Calculate Top of the Firmware Device\r
   LoadConstantToReg (FixedPcdGet32(PcdFdBaseAddress), r2)\r
   LoadConstantToReg (FixedPcdGet32(PcdFdSize), r3)\r
-  add   r3, r3, r2      // r4 = FdTop = PcdFdBaseAddress + PcdFdSize\r
+  sub   r3, r3, #1\r
+  add   r3, r3, r2      // r3 = FdTop = PcdFdBaseAddress + PcdFdSize\r
 \r
   // UEFI Memory Size (stacks are allocated in this region)\r
   LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
@@ -72,21 +74,41 @@ _SetupStackPosition
 _SetupStack\r
   // r1 contains the top of the stack (and the UEFI Memory)\r
 \r
+  // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment\r
+  // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the\r
+  // top of the memory space)\r
+  adds  r6, r1, #1\r
+  bcs   _SetupOverflowStack\r
+\r
+_SetupAlignedStack\r
+  mov   r1, r6\r
+  b     _GetBaseUefiMemory\r
+\r
+_SetupOverflowStack\r
+  // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r
+  // aligned (4KB)\r
+  LoadConstantToReg (EFI_PAGE_MASK, r6)\r
+  and   r6, r6, r1\r
+  sub   r1, r1, r6\r
+\r
+_GetBaseUefiMemory\r
   // Calculate the Base of the UEFI Memory\r
   sub   r6, r1, r4\r
 \r
 _GetStackBase\r
   // Compute Base of Normal stacks for CPU Cores\r
   // Is it MpCore system\r
-  bl    ArmIsMPCore\r
+  bl    ArmIsMpCore\r
   cmp   r0, #0\r
   // Case it is not an MP Core system. Just setup the primary core\r
   beq   _SetupUnicoreStack\r
 \r
 _GetStackBaseMpCore\r
+  // r1 = The top of the Mpcore Stacks\r
   // Stack for the primary core = PrimaryCoreStack\r
   LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)\r
   sub   r7, r1, r2\r
+\r
   // Stack for the secondary core = Number of Cluster * (4 Core per cluster) * SecondaryStackSize\r
   LoadConstantToReg (FixedPcdGet32(PcdClusterCount), r2)\r
   lsl   r2, r2, #2\r
@@ -94,16 +116,20 @@ _GetStackBaseMpCore
   mul   r2, r2, r3\r
   sub   r7, r7, r2\r
 \r
-  // The top of the Mpcore Stacks is in r1\r
-  // The base of the MpCore Stacks is in r7\r
+  // The base of the secondary Stacks = Top of Primary stack\r
+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r2)\r
+  add   r1, r7, r2\r
+\r
+  // r7 = The base of the MpCore Stacks (primary stack + cluster_count * 4 * secondary stacks)\r
+  // r1 = The base of the secondary Stacks = Top of the Primary stack\r
 \r
   // Is it the Primary Core ?\r
   LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), r4)\r
-  cmp   r0, r4\r
+  cmp   r5, r4\r
   beq   _SetupPrimaryCoreStack\r
 \r
 _SetupSecondaryCoreStack\r
-  // Base of the stack for the secondary cores is in r7\r
+  // r1 = The base of the secondary Stacks\r
 \r
   // Get the position of the cores (ClusterId * 4) + CoreId\r
   GetCorePositionInStack(r0, r5, r4)\r
@@ -111,53 +137,46 @@ _SetupSecondaryCoreStack
   add   r0, r0, #1\r
   // Get the offset for the Secondary Stack\r
   mul   r0, r0, r3\r
-  add   sp, r7, r0\r
+  add   sp, r1, r0\r
 \r
   bne   _PrepareArguments\r
 \r
 _SetupPrimaryCoreStack\r
-  // The top of the Mpcore Stacks is in r1\r
+  // r1 = Top of the primary stack\r
   LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
+  b     _PreparePrimaryStack\r
 \r
+_SetupUnicoreStack\r
+  // The top of the Unicore Stack is in r1\r
+  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
+  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r3)\r
+\r
+  // Calculate the bottom of the primary stack (StackBase)\r
+  sub   r7, r1, r3\r
+\r
+_PreparePrimaryStack\r
   // The reserved space for global variable must be 8-bytes aligned for pushing\r
   // 64-bit variable on the stack\r
   SetPrimaryStack (r1, r2, r3)\r
 \r
-_SetGlobals\r
-  // Set all the PrePi global variables to 0\r
+_PrepareArguments\r
+  mov   r0, r5\r
+  mov   r1, r6\r
+  mov   r2, r7\r
   mov   r3, sp\r
-  mov   r2, #0x0\r
-_InitGlobals\r
-  str   r2, [r3], #4\r
-  cmp   r3, r1\r
-  blt   _InitGlobals\r
 \r
-\r
-_PrepareArguments\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   r2, StartupAddr\r
+  ldr   r4, StartupAddr\r
 \r
   // Jump to PrePiCore C code\r
   //    r0 = MpId\r
   //    r1 = UefiMemoryBase\r
-  blx   r2\r
+  //    r2 = StacksBase\r
+  //    r3 = GlobalVariableBase\r
+  blx   r4\r
 \r
 _NeverReturn\r
   b _NeverReturn\r
 \r
-_SetupUnicoreStack\r
-  // The top of the Unicore Stack is in r1\r
-  LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r2)\r
-  LoadConstantToReg (FixedPcdGet32(PcdCPUCorePrimaryStackSize), r3)\r
-\r
-  // Calculate the bottom of the primary stack (StackBase)\r
-  sub   r7, r1, r3\r
-\r
-  // The reserved space for global variable must be 8-bytes aligned for pushing\r
-  // 64-bit variable on the stack\r
-  SetPrimaryStack (r1, r2, r3)\r
-\r
-  b _SetGlobals\r
-\r
   END\r