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