]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/AArch64/ModuleEntryPoint.S
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPlatformPkg / PrePi / AArch64 / ModuleEntryPoint.S
1 //
2 // Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.<BR>
3 //
4 // SPDX-License-Identifier: BSD-2-Clause-Patent
5 //
6 //
7
8 #include <AsmMacroIoLibV8.h>
9
10 ASM_FUNC(_ModuleEntryPoint)
11 // Do early platform specific actions
12 bl ASM_PFX(ArmPlatformPeiBootAction)
13
14 // Get ID of this CPU in multi-core system
15 bl ASM_PFX(ArmReadMpidr)
16 // Keep a copy of the MpId register value
17 mov x10, x0
18
19 _SetSVCMode:
20 // Check if we can install the stack at the top of the System Memory or if we need
21 // to install the stacks at the bottom of the Firmware Device (case the FD is located
22 // at the top of the DRAM)
23 _SystemMemoryEndInit:
24 ldr x1, mSystemMemoryEnd
25
26 _SetupStackPosition:
27 // r1 = SystemMemoryTop
28
29 // Calculate Top of the Firmware Device
30 MOV64 (x2, FixedPcdGet64(PcdFdBaseAddress))
31 MOV32 (x3, FixedPcdGet32(PcdFdSize) - 1)
32 sub x3, x3, #1
33 add x3, x3, x2 // x3 = FdTop = PcdFdBaseAddress + PcdFdSize
34
35 // UEFI Memory Size (stacks are allocated in this region)
36 MOV32 (x4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
37
38 //
39 // Reserve the memory for the UEFI region (contain stacks on its top)
40 //
41
42 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
43 subs x0, x1, x3 // x0 = SystemMemoryTop - FdTop
44 b.mi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
45 cmp x0, x4
46 b.ge _SetupStack
47
48 // Case the top of stacks is the FdBaseAddress
49 mov x1, x2
50
51 _SetupStack:
52 // x1 contains the top of the stack (and the UEFI Memory)
53
54 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
55 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
56 // top of the memory space)
57 adds x11, x1, #1
58 b.cs _SetupOverflowStack
59
60 _SetupAlignedStack:
61 mov x1, x11
62 b _GetBaseUefiMemory
63
64 _SetupOverflowStack:
65 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
66 // aligned (4KB)
67 and x1, x1, ~EFI_PAGE_MASK
68
69 _GetBaseUefiMemory:
70 // Calculate the Base of the UEFI Memory
71 sub x11, x1, x4
72
73 _GetStackBase:
74 // r1 = The top of the Mpcore Stacks
75 // Stack for the primary core = PrimaryCoreStack
76 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
77 sub x12, x1, x2
78
79 // Stack for the secondary core = Number of Cores - 1
80 MOV32 (x1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
81 sub x12, x12, x1
82
83 // x12 = The base of the MpCore Stacks (primary stack & secondary stacks)
84 mov x0, x12
85 mov x1, x10
86 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
87 MOV32 (x2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
88 MOV32 (x3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
89 bl ASM_PFX(ArmPlatformStackSet)
90
91 // Is it the Primary Core ?
92 mov x0, x10
93 bl ASM_PFX(ArmPlatformIsPrimaryCore)
94 cmp x0, #1
95 bne _PrepareArguments
96
97 _PrepareArguments:
98 mov x0, x10
99 mov x1, x11
100 mov x2, x12
101
102 // Move sec startup address into a data register
103 // Ensure we're jumping to FV version of the code (not boot remapped alias)
104 ldr x4, =ASM_PFX(CEntryPoint)
105
106 // Set the frame pointer to NULL so any backtraces terminate here
107 mov x29, xzr
108
109 // Jump to PrePiCore C code
110 // x0 = MpId
111 // x1 = UefiMemoryBase
112 // x2 = StacksBase
113 blr x4
114
115 _NeverReturn:
116 b _NeverReturn