]>
Commit | Line | Data |
---|---|---|
cd872e40 | 1 | //\r |
5dbacdb2 | 2 | // Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r |
cd872e40 | 3 | //\r |
4 | // This program and the accompanying materials\r | |
5 | // are licensed and made available under the terms and conditions of the BSD License\r | |
6 | // which accompanies this distribution. The full text of the license may be found at\r | |
7 | // http://opensource.org/licenses/bsd-license.php\r | |
8 | //\r | |
9 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | //\r | |
12 | //\r | |
13 | \r | |
cd872e40 | 14 | #include <AutoGen.h>\r |
063ad84e | 15 | #include <Chipset/ArmV7.h>\r |
16 | \r | |
cd872e40 | 17 | INCLUDE AsmMacroIoLib.inc\r |
3402aac7 | 18 | \r |
cd872e40 | 19 | IMPORT CEntryPoint\r |
bebda7ce | 20 | IMPORT ArmPlatformIsPrimaryCore\r |
0787bc61 | 21 | IMPORT ArmReadMpidr\r |
b5a57223 | 22 | IMPORT ArmPlatformPeiBootAction\r |
695df8ba | 23 | IMPORT ArmPlatformStackSet\r |
3402aac7 | 24 | \r |
cd872e40 | 25 | EXPORT _ModuleEntryPoint\r |
5dbacdb2 | 26 | EXPORT mSystemMemoryEnd\r |
cd872e40 | 27 | \r |
28 | PRESERVE8\r | |
29 | AREA PrePiCoreEntryPoint, CODE, READONLY\r | |
3402aac7 | 30 | \r |
cd872e40 | 31 | StartupAddr DCD CEntryPoint\r |
5dbacdb2 | 32 | mSystemMemoryEnd DCQ 0\r |
cd872e40 | 33 | \r |
34 | _ModuleEntryPoint\r | |
b5a57223 | 35 | // Do early platform specific actions\r |
36 | bl ArmPlatformPeiBootAction\r | |
37 | \r | |
0787bc61 | 38 | // Get ID of this CPU in Multicore system\r |
39 | bl ArmReadMpidr\r | |
bebda7ce | 40 | // Keep a copy of the MpId register value\r |
c2d87a49 | 41 | mov r8, r0\r |
cd872e40 | 42 | \r |
d269095b | 43 | _SetSVCMode\r |
99565b88 | 44 | // Enter SVC mode, Disable FIQ and IRQ\r |
063ad84e | 45 | mov r1, #(CPSR_MODE_SVC :OR: CPSR_IRQ :OR: CPSR_FIQ)\r |
d269095b | 46 | msr CPSR_c, r1\r |
47 | \r | |
2dbcb8f0 | 48 | // Check if we can install the stack at the top of the System Memory or if we need\r |
d269095b | 49 | // to install the stacks at the bottom of the Firmware Device (case the FD is located\r |
50 | // at the top of the DRAM)\r | |
5dbacdb2 OM |
51 | _SystemMemoryEndInit\r |
52 | ldr r1, mSystemMemoryEnd\r | |
53 | \r | |
54 | // Is mSystemMemoryEnd initialized?\r | |
55 | cmp r1, #0\r | |
56 | bne _SetupStackPosition\r | |
57 | \r | |
66edb631 AB |
58 | mov32 r1, FixedPcdGet32(PcdSystemMemoryBase)\r |
59 | mov32 r2, FixedPcdGet32(PcdSystemMemorySize)\r | |
2569b068 | 60 | sub r2, r2, #1\r |
5dbacdb2 OM |
61 | add r1, r1, r2\r |
62 | // Update the global variable\r | |
63 | adr r2, mSystemMemoryEnd\r | |
64 | str r1, [r2]\r | |
65 | \r | |
66 | _SetupStackPosition\r | |
67 | // r1 = SystemMemoryTop\r | |
cd872e40 | 68 | \r |
d269095b | 69 | // Calculate Top of the Firmware Device\r |
66edb631 AB |
70 | mov32 r2, FixedPcdGet32(PcdFdBaseAddress)\r |
71 | mov32 r3, FixedPcdGet32(PcdFdSize)\r | |
2569b068 | 72 | sub r3, r3, #1\r |
7defe7b3 | 73 | add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize\r |
d269095b | 74 | \r |
75 | // UEFI Memory Size (stacks are allocated in this region)\r | |
66edb631 | 76 | mov32 r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize)\r |
d269095b | 77 | \r |
78 | //\r | |
79 | // Reserve the memory for the UEFI region (contain stacks on its top)\r | |
80 | //\r | |
81 | \r | |
82 | // Calculate how much space there is between the top of the Firmware and the Top of the System Memory\r | |
91c38d4e RC |
83 | subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop\r |
84 | bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM\r | |
85 | cmp r0, r4\r | |
86 | bge _SetupStack\r | |
d269095b | 87 | \r |
88 | // Case the top of stacks is the FdBaseAddress\r | |
91c38d4e | 89 | mov r1, r2\r |
cd872e40 | 90 | \r |
91 | _SetupStack\r | |
2dbcb8f0 | 92 | // r1 contains the top of the stack (and the UEFI Memory)\r |
d269095b | 93 | \r |
2569b068 | 94 | // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment\r |
95 | // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the\r | |
96 | // top of the memory space)\r | |
c2d87a49 | 97 | adds r9, r1, #1\r |
2569b068 | 98 | bcs _SetupOverflowStack\r |
99 | \r | |
100 | _SetupAlignedStack\r | |
c2d87a49 | 101 | mov r1, r9\r |
2569b068 | 102 | b _GetBaseUefiMemory\r |
103 | \r | |
104 | _SetupOverflowStack\r | |
105 | // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE\r | |
106 | // aligned (4KB)\r | |
66edb631 | 107 | mov32 r9, EFI_PAGE_MASK\r |
c2d87a49 OM |
108 | and r9, r9, r1\r |
109 | sub r1, r1, r9\r | |
2569b068 | 110 | \r |
111 | _GetBaseUefiMemory\r | |
d269095b | 112 | // Calculate the Base of the UEFI Memory\r |
c2d87a49 | 113 | sub r9, r1, r4\r |
cd872e40 | 114 | \r |
2dbcb8f0 | 115 | _GetStackBase\r |
1377db63 | 116 | // r1 = The top of the Mpcore Stacks\r |
2dbcb8f0 | 117 | // Stack for the primary core = PrimaryCoreStack\r |
66edb631 | 118 | mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)\r |
c2d87a49 | 119 | sub r10, r1, r2\r |
695df8ba | 120 | \r |
121 | // Stack for the secondary core = Number of Cores - 1\r | |
66edb631 | 122 | mov32 r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize)\r |
c2d87a49 | 123 | sub r10, r10, r1\r |
695df8ba | 124 | \r |
c2d87a49 | 125 | // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)\r |
91c38d4e RC |
126 | mov r0, r10\r |
127 | mov r1, r8\r | |
695df8ba | 128 | //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)\r |
66edb631 AB |
129 | mov32 r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize)\r |
130 | mov32 r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize)\r | |
91c38d4e | 131 | bl ArmPlatformStackSet\r |
2dbcb8f0 | 132 | \r |
133 | // Is it the Primary Core ?\r | |
c2d87a49 | 134 | mov r0, r8\r |
bebda7ce | 135 | bl ArmPlatformIsPrimaryCore\r |
136 | cmp r0, #1\r | |
cd872e40 | 137 | bne _PrepareArguments\r |
138 | \r | |
cd872e40 | 139 | _PrepareArguments\r |
c2d87a49 OM |
140 | mov r0, r8\r |
141 | mov r1, r9\r | |
142 | mov r2, r10\r | |
c524ffbb | 143 | \r |
cd872e40 | 144 | // Move sec startup address into a data register\r |
145 | // Ensure we're jumping to FV version of the code (not boot remapped alias)\r | |
c524ffbb | 146 | ldr r4, StartupAddr\r |
cd872e40 | 147 | \r |
d269095b | 148 | // Jump to PrePiCore C code\r |
0787bc61 | 149 | // r0 = MpId\r |
cd872e40 | 150 | // r1 = UefiMemoryBase\r |
c524ffbb | 151 | // r2 = StacksBase\r |
c524ffbb | 152 | blx r4\r |
cd872e40 | 153 | \r |
2dbcb8f0 | 154 | _NeverReturn\r |
155 | b _NeverReturn\r | |
156 | \r | |
cd872e40 | 157 | END\r |