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