]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/ModuleEntryPoint.asm
52690f8ecd9ceb7b352b68ae23e1972cc562db41
[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 _UefiMemoryBase
35 #if FixedPcdGet32(PcdStandalone)
36 // Compute Top of System Memory
37 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryBase), r1)
38 LoadConstantToReg (FixedPcdGet32(PcdSystemMemorySize), r2)
39 add r1, r1, r2 // r1 = SystemMemoryTop = PcdSystemMemoryBase + PcdSystemMemorySize
40 #else
41 // If it is not a Standalone, we must compute the top of the UEFI memory with the base of the FD
42 LoadConstantToReg (FixedPcdGet32(PcdNormalFdBaseAddress), r1)
43 #endif
44
45 // Compute Base of UEFI Memory
46 LoadConstantToReg (FixedPcdGet32(PcdSystemMemoryUefiRegionSize), r2)
47 sub r1, r1, r2 // r1 = SystemMemoryTop - PcdSystemMemoryUefiRegionSize = UefiMemoryBase
48
49 _SetupStack
50 // Compute Base of Normal stacks for CPU Cores
51 LoadConstantToReg (FixedPcdGet32(PcdCPUCoresNonSecStackSize), r2)
52 mul r3, r0, r2 // r3 = core_id * stack_size = offset from the stack base
53 sub sp, r1, r3 // r3 = UefiMemoryBase - StackOffset = TopOfStack
54
55 // Only allocate memory in top of the primary core stack
56 cmp r0, #0
57 bne _PrepareArguments
58
59 _AllocateGlobalPrePiVariables
60 // Reserve top of the stack for Global PEI Variables (eg: PeiServicesTablePointer)
61 LoadConstantToReg (FixedPcdGet32(PcdPeiGlobalVariableSize), r4)
62 // The reserved place must be 8-bytes aligned for pushing 64-bit variable on the stack
63 and r5, r4, #7
64 rsb r5, r5, #8
65 add r4, r4, r5
66 sub sp, sp, r4
67
68 _PrepareArguments
69 // Pass the StackBase to the C Entrypoint (UefiMemoryBase - StackSize - StackOffset)
70 sub r2, r1, r2
71 sub r2, r3
72 // Move sec startup address into a data register
73 // Ensure we're jumping to FV version of the code (not boot remapped alias)
74 ldr r3, StartupAddr
75
76 // jump to PrePiCore C code
77 // r0 = core_id
78 // r1 = UefiMemoryBase
79 // r2 = StackBase
80 blx r3
81
82 END