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