]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/PrePi/Arm/ModuleEntryPoint.S
ArmPlatformPkg/PrePi: fix secondary stack base
[mirror_edk2.git] / ArmPlatformPkg / PrePi / Arm / ModuleEntryPoint.S
1 //
2 // Copyright (c) 2011-2015, 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
16 #include <Chipset/ArmV7.h>
17
18 GCC_ASM_EXPORT(mSystemMemoryEnd)
19
20 ASM_FUNC(_ModuleEntryPoint)
21 // Do early platform specific actions
22 bl ASM_PFX(ArmPlatformPeiBootAction)
23
24 // Get ID of this CPU in Multicore system
25 bl ASM_PFX(ArmReadMpidr)
26 // Keep a copy of the MpId register value
27 mov r8, r0
28
29 _SetSVCMode:
30 // Enter SVC mode, Disable FIQ and IRQ
31 mov r1, #(CPSR_MODE_SVC | CPSR_IRQ | CPSR_FIQ)
32 msr CPSR_c, r1
33
34 // Check if we can install the stack at the top of the System Memory or if we need
35 // to install the stacks at the bottom of the Firmware Device (case the FD is located
36 // at the top of the DRAM)
37 _SystemMemoryEndInit:
38 ldr r1, mSystemMemoryEnd
39
40 // Is mSystemMemoryEnd initialized?
41 cmp r1, #0
42 bne _SetupStackPosition
43
44 MOV32 (r1, FixedPcdGet32(PcdSystemMemoryBase) + FixedPcdGet32(PcdSystemMemorySize) - 1)
45
46 // Update the global variable
47 adr r2, mSystemMemoryEnd
48 str r1, [r2]
49
50 _SetupStackPosition:
51 // r1 = SystemMemoryTop
52
53 // Calculate Top of the Firmware Device
54 MOV32 (r2, FixedPcdGet32(PcdFdBaseAddress))
55 MOV32 (r3, FixedPcdGet32(PcdFdSize) - 1)
56 add r3, r3, r2 // r3 = FdTop = PcdFdBaseAddress + PcdFdSize
57
58 // UEFI Memory Size (stacks are allocated in this region)
59 MOV32 (r4, FixedPcdGet32(PcdSystemMemoryUefiRegionSize))
60
61 //
62 // Reserve the memory for the UEFI region (contain stacks on its top)
63 //
64
65 // Calculate how much space there is between the top of the Firmware and the Top of the System Memory
66 subs r0, r1, r3 // r0 = SystemMemoryTop - FdTop
67 bmi _SetupStack // Jump if negative (FdTop > SystemMemoryTop). Case when the PrePi is in XIP memory outside of the DRAM
68 cmp r0, r4
69 bge _SetupStack
70
71 // Case the top of stacks is the FdBaseAddress
72 mov r1, r2
73
74 _SetupStack:
75 // r1 contains the top of the stack (and the UEFI Memory)
76
77 // Because the 'push' instruction is equivalent to 'stmdb' (decrement before), we need to increment
78 // one to the top of the stack. We check if incrementing one does not overflow (case of DRAM at the
79 // top of the memory space)
80 adds r9, r1, #1
81 bcs _SetupOverflowStack
82
83 _SetupAlignedStack:
84 mov r1, r9
85 b _GetBaseUefiMemory
86
87 _SetupOverflowStack:
88 // Case memory at the top of the address space. Ensure the top of the stack is EFI_PAGE_SIZE
89 // aligned (4KB)
90 MOV32 (r9, ~EFI_PAGE_MASK & 0xFFFFFFFF)
91 and r1, r1, r9
92
93 _GetBaseUefiMemory:
94 // Calculate the Base of the UEFI Memory
95 sub r9, r1, r4
96
97 _GetStackBase:
98 // r1 = The top of the Mpcore Stacks
99 // Stack for the primary core = PrimaryCoreStack
100 MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
101 sub r10, r1, r2
102
103 // Stack for the secondary core = Number of Cores - 1
104 MOV32 (r1, (FixedPcdGet32(PcdCoreCount) - 1) * FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
105 sub r10, r10, r1
106
107 // r10 = The base of the MpCore Stacks (primary stack & secondary stacks)
108 mov r0, r10
109 mov r1, r8
110 //ArmPlatformStackSet(StackBase, MpId, PrimaryStackSize, SecondaryStackSize)
111 MOV32 (r2, FixedPcdGet32(PcdCPUCorePrimaryStackSize))
112 MOV32 (r3, FixedPcdGet32(PcdCPUCoreSecondaryStackSize))
113 bl ASM_PFX(ArmPlatformStackSet)
114
115 // Is it the Primary Core ?
116 mov r0, r8
117 bl ASM_PFX(ArmPlatformIsPrimaryCore)
118 cmp r0, #1
119 bne _PrepareArguments
120
121 _PrepareArguments:
122 mov r0, r8
123 mov r1, r9
124 mov r2, r10
125 mov r3, sp
126
127 // Move sec startup address into a data register
128 // Ensure we're jumping to FV version of the code (not boot remapped alias)
129 ldr r4, =ASM_PFX(CEntryPoint)
130
131 // Jump to PrePiCore C code
132 // r0 = MpId
133 // r1 = UefiMemoryBase
134 // r2 = StacksBase
135 blx r4
136
137 _NeverReturn:
138 b _NeverReturn
139
140 ASM_PFX(mSystemMemoryEnd): .8byte 0