]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/ModuleEntryPoint.S
0857024a2778d18310170be18ff3c89ab373bacd
[mirror_edk2.git] / ArmPlatformPkg / PrePi / ModuleEntryPoint.S
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 #start of the code section
20 .text
21 .align 3
22
23 #global symbols referenced by this module
24 GCC_ASM_IMPORT(CEntryPoint)
25
26 StartupAddr: .word CEntryPoint
27
28 #make _ModuleEntryPoint as global
29 GCC_ASM_EXPORT(_ModuleEntryPoint)
30
31
32 ASM_PFX(_ModuleEntryPoint):
33 // Identify CPU ID
34 mrc p15, 0, r0, c0, c0, 5
35 and r0, #0xf
36
37 _UefiMemoryBase:
38 #if FixedPcdGet32(PcdStandalone)
39 // Compute Top of System Memory
40 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
41 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
42 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
43 #else
44 // If it is not a Standalone, we must compute the top of the UEFI memory with the base of the FD
45 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r1)
46 #endif
47
48 // Compute Base of UEFI Memory
49 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r2)
50 sub r1, r1, r2 // r1 = SystemMemoryTop - PcdSystemMemoryUefiRegionSize = UefiMemoryBase
51
52 _SetupStack:
53 // Compute Base of Normal stacks for CPU Cores
54 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r2)
55 mul r3, r0, r2 // r3 = core_id * stack_size = offset from the stack base
56 sub sp, r1, r3 // r3 = UefiMemoryBase - StackOffset = TopOfStack
57
58 // Only allocate memory in top of the primary core stack
59 cmp r0, #0
60 bne _PrepareArguments
61
62 _AllocateGlobalPeiVariables:
63 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)
64 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)
65 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack
66 and r5, r4, #7
67 rsb r5, r5, #8
68 add r4, r4, r5
69 sub sp, sp, r4
70
71 _PrepareArguments:
72 // Pass the StackBase to the C Entrypoint (UefiMemoryBase - StackSize - StackOffset)
73 sub r2, r1, r2
74 sub r2, r3
75 // Move sec startup address into a data register
76 // Ensure we're jumping to FV version of the code (not boot remapped alias)
77 ldr r3, StartupAddr
78
79 // jump to PrePiCore C code
80 // r0 = core_id
81 // r1 = UefiMemoryBase
82 // r2 = StackBase
83 blx r3
84