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