]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/ModuleEntryPoint.asm
ArmPlatformPkg: Introduce Primary core macros
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.asm
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
19 INCLUDE AsmMacroIoLib.inc\r
20 \r
21 IMPORT CEntryPoint\r
0787bc61 22 IMPORT ArmReadMpidr\r
cd872e40 23 EXPORT _ModuleEntryPoint\r
24\r
25 PRESERVE8\r
26 AREA PrePiCoreEntryPoint, CODE, READONLY\r
27 \r
28StartupAddr DCD CEntryPoint\r
29\r
30_ModuleEntryPoint\r
0787bc61 31 // Get ID of this CPU in Multicore system\r
32 bl ArmReadMpidr\r
33 LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCoreMask), r1)\r
34 and r5, r0, r1\r
cd872e40 35\r
d269095b 36_SetSVCMode\r
37 // Enter SVC mode\r
38 mov r1, #0x13|0x80|0x40\r
39 msr CPSR_c, r1\r
40\r
41// Check if we can install the size at the top of the System Memory or if we need\r
42// to install the stacks at the bottom of the Firmware Device (case the FD is located\r
43// at the top of the DRAM)\r
44_SetupStackPosition\r
cd872e40 45 // Compute Top of System Memory\r
46 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)\r
47 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)\r
48 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize\r
cd872e40 49\r
d269095b 50 // Calculate Top of the Firmware Device\r
51 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r2)\r
52 LoadConstantToReg (FixedPcdGet32(PcdNormalFdSize), r3)\r
53 add r3, r3, r2 // r4 = FdTop = PcdNormalFdBaseAddress + PcdNormalFdSize\r
54\r
55 // UEFI Memory Size (stacks are allocated in this region)\r
56 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r4)\r
57\r
58 //\r
59 // Reserve the memory for the UEFI region (contain stacks on its top)\r
60 //\r
61\r
62 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r
63 subs r5, r1, r3 // r5 = SystemMemoryTop - FdTop\r
64 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop)\r
65 cmp r5, r4\r
66 bge _SetupStack\r
67\r
68 // Case the top of stacks is the FdBaseAddress\r
69 mov r1, r2\r
cd872e40 70\r
71_SetupStack\r
72 // Compute Base of Normal stacks for CPU Cores\r
d269095b 73 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r5)\r
74 mul r3, r0, r5 // r3 = core_id * stack_size = offset from the stack base\r
75 sub sp, r1, r3 // r3 = (SystemMemoryTop|FdBaseAddress) - StackOffset = TopOfStack\r
76\r
77 // Calculate the Base of the UEFI Memory\r
78 sub r1, r1, r4\r
cd872e40 79\r
d269095b 80 // Only allocate memory for global variables at top of the primary core stack\r
cd872e40 81 cmp r0, #0\r
82 bne _PrepareArguments\r
83\r
84_AllocateGlobalPrePiVariables\r
85 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)\r
86 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)\r
87 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack\r
88 and r5, r4, #7\r
89 rsb r5, r5, #8\r
90 add r4, r4, r5\r
91 sub sp, sp, r4\r
92\r
93_PrepareArguments\r
cd872e40 94 // Move sec startup address into a data register\r
95 // Ensure we're jumping to FV version of the code (not boot remapped alias)\r
d269095b 96 ldr r2, StartupAddr\r
cd872e40 97\r
d269095b 98 // Jump to PrePiCore C code\r
0787bc61 99 // r0 = MpId\r
cd872e40 100 // r1 = UefiMemoryBase\r
d269095b 101 blx r2\r
cd872e40 102\r
103 END\r