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