]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/ModuleEntryPoint.S
ArmPlatformPkg: Change the memory model for the ARM Platform components
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.S
CommitLineData
cd872e40 1//\r
2// Copyright (c) 2011, ARM Limited. All rights reserved.\r
3//\r
4// This program and the accompanying materials\r
5// are licensed and made available under the terms and conditions of the BSD License\r
6// which accompanies this distribution. The full text of the license may be found at\r
7// http://opensource.org/licenses/bsd-license.php\r
8//\r
9// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11//\r
12//\r
13\r
14#include <AsmMacroIoLib.h>\r
15#include <Base.h>\r
16#include <Library/PcdLib.h>\r
17#include <AutoGen.h>\r
18\r
cd872e40 19.text\r
20.align 3\r
21\r
d269095b 22# Global symbols referenced by this module\r
cd872e40 23GCC_ASM_IMPORT(CEntryPoint)\r
d269095b 24GCC_ASM_EXPORT(_ModuleEntryPoint)\r
cd872e40 25\r
26StartupAddr: .word CEntryPoint\r
27\r
cd872e40 28\r
29ASM_PFX(_ModuleEntryPoint):\r
30 // Identify CPU ID\r
31 mrc p15, 0, r0, c0, c0, 5\r
32 and r0, #0xf\r
33\r
d269095b 34_SetSVCMode:\r
35 // Enter SVC mode\r
36 mov r1, #0x13|0x80|0x40\r
37 msr CPSR_c, r1\r
38\r
39// Check if we can install the size at the top of the System Memory or if we need\r
40// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
41// at the top of the DRAM)\r
42_SetupStackPosition:\r
cd872e40 43 // Compute Top of System Memory\r
44 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)\r
45 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)\r
46 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
cd872e40 47\r
d269095b 48 // Calculate Top of the Firmware Device\r
49 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)\r
50 LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)\r
51 add r3, r3, r2 // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize\r
52\r
53 // UEFI Memory Size (stacks are allocated in this region)\r
54 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
55\r
56 //\r
57 // Reserve the memory for the UEFI region (contain stacks on its top)\r
58 //\r
59\r
60 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
61 subs r5, r1, r3 // r5 = SystemMemoryTop - FdTop\r
62 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop)\r
63 cmp r5, r4\r
64 bge _SetupStack\r
65\r
66 // Case the top of stacks is the FdBaseAddress\r
67 mov r1, r2\r
cd872e40 68\r
69_SetupStack:\r
70 // Compute Base of Normal stacks for CPU Cores\r
d269095b 71 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)\r
72 mul r3, r0, r5 // r3 = core_id * stack_size = offset from the stack base\r
73 sub sp, r1, r3 // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack\r
74\r
75 // Calculate the Base of the UEFI Memory\r
76 sub r1, r1, r4\r
cd872e40 77\r
d269095b 78 // Only allocate memory for global variables at top of the primary core stack\r
cd872e40 79 cmp r0, #0\r
80 bne _PrepareArguments\r
81\r
d269095b 82_AllocateGlobalPrePiVariables:\r
cd872e40 83 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)\r
84 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)\r
85 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack\r
86 and r5, r4, #7\r
87 rsb r5, r5, #8\r
88 add r4, r4, r5\r
89 sub sp, sp, r4\r
90\r
91_PrepareArguments:\r
cd872e40 92 // Move sec startup address into a data register\r
93 // Ensure we're jumping to FV version of the code (not boot remapped alias)\r
d269095b 94 ldr r2, StartupAddr\r
cd872e40 95\r
d269095b 96 // Jump to PrePiCore C code\r
cd872e40 97 // r0 = core_id\r
98 // r1 = UefiMemoryBase\r
d269095b 99 blx r2\r
cd872e40 100\r