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