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