]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPkg/AsmMacroIoLib: Renamed 'GetCorePositionInStack' macro into 'GetCorePositionFro...
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
CommitLineData
cd872e40 1/** @file\r
2*\r
f437141a 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
cd872e40 4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include <PiPei.h>\r
16\r
17#include <Library/DebugAgentLib.h>\r
18#include <Library/PrePiLib.h>\r
cd872e40 19#include <Library/PrintLib.h>\r
20#include <Library/PeCoffGetEntryPointLib.h>\r
37573927 21#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 22#include <Library/TimerLib.h>\r
23#include <Library/PerformanceLib.h>\r
24\r
25#include <Ppi/GuidedSectionExtraction.h>\r
26#include <Guid/LzmaDecompress.h>\r
8fc38a3f 27#include <Guid/ArmGlobalVariableHob.h>\r
cd872e40 28\r
29#include "PrePi.h"\r
30#include "LzmaDecompress.h"\r
31\r
99565b88 32#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
8fc38a3f 33 ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
34\r
35// Not used when PrePi in run in XIP mode\r
36UINTN mGlobalVariableBase = 0;\r
37\r
cd872e40 38VOID\r
39PrePiCommonExceptionEntry (\r
40 IN UINT32 Entry,\r
41 IN UINT32 LR\r
42 );\r
43\r
44EFI_STATUS\r
45EFIAPI\r
46ExtractGuidedSectionLibConstructor (\r
47 VOID\r
48 );\r
49\r
50EFI_STATUS\r
51EFIAPI\r
52LzmaDecompressLibConstructor (\r
53 VOID\r
54 );\r
55\r
8fc38a3f 56VOID\r
57EFIAPI\r
58BuildGlobalVariableHob (\r
59 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r
60 IN UINT32 GlobalVariableSize\r
61 )\r
62{\r
63 ARM_HOB_GLOBAL_VARIABLE *Hob;\r
64\r
65 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
66 ASSERT(Hob != NULL);\r
67\r
68 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
69 Hob->GlobalVariableBase = GlobalVariableBase;\r
70 Hob->GlobalVariableSize = GlobalVariableSize;\r
71}\r
72\r
cd872e40 73VOID\r
74PrePiMain (\r
75 IN UINTN UefiMemoryBase,\r
c524ffbb 76 IN UINTN StacksBase,\r
77 IN UINTN GlobalVariableBase,\r
cd872e40 78 IN UINT64 StartTimeStamp\r
79 )\r
80{\r
37573927 81 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
cd872e40 82 EFI_STATUS Status;\r
83 CHAR8 Buffer[100];\r
84 UINTN CharCount;\r
d269095b 85 UINTN StacksSize;\r
cd872e40 86\r
8fc38a3f 87 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
88 ASSERT (IS_XIP() || \r
89 ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
99565b88 90 ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
8fc38a3f 91\r
cd872e40 92 // Enable program flow prediction, if supported.\r
93 ArmEnableBranchPrediction ();\r
94\r
95 if (FixedPcdGet32(PcdVFPEnabled)) {\r
96 ArmEnableVFP();\r
97 }\r
98\r
99 // Initialize the Serial Port\r
100 SerialPortInitialize ();\r
37363dff 101 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
102 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
cd872e40 103 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
104\r
105 // Initialize the Debug Agent for Source Level Debugging\r
106 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
107 SaveAndSetDebugTimerInterrupt (TRUE);\r
2ee85366 108 \r
d269095b 109 // Declare the PI/UEFI memory region\r
37573927 110 HobList = HobConstructor (\r
cd872e40 111 (VOID*)UefiMemoryBase,\r
112 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
113 (VOID*)UefiMemoryBase,\r
d269095b 114 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
115 );\r
37573927 116 PrePeiSetHobList (HobList);\r
cd872e40 117\r
118 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
119 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
120 ASSERT_EFI_ERROR (Status);\r
121\r
d269095b 122 // Create the Stacks HOB (reserve the memory for all stacks)\r
99565b88 123 if (ArmIsMpCore ()) {\r
124 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r
125 } else {\r
126 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
127 }\r
d269095b 128 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 129\r
8fc38a3f 130 // Declare the Global Variable HOB\r
131 BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r
132\r
44788bae 133 //TODO: Call CpuPei as a library\r
134 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
135\r
cd872e40 136 // Set the Boot Mode\r
137 SetBootMode (ArmPlatformGetBootMode ());\r
138\r
139 // Initialize Platform HOBs (CpuHob and FvHob)\r
140 Status = PlatformPeim ();\r
141 ASSERT_EFI_ERROR (Status);\r
142\r
cd872e40 143 // Now, the HOB List has been initialized, we can register performance information\r
144 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
145\r
146 // SEC phase needs to run library constructors by hand.\r
147 ExtractGuidedSectionLibConstructor ();\r
148 LzmaDecompressLibConstructor ();\r
149\r
150 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
151 BuildPeCoffLoaderHob ();\r
152 BuildExtractSectionHob (\r
153 &gLzmaCustomDecompressGuid,\r
154 LzmaGuidedSectionGetInfo,\r
155 LzmaGuidedSectionExtraction\r
156 );\r
157\r
158 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
159 Status = DecompressFirstFv ();\r
160 ASSERT_EFI_ERROR (Status);\r
161\r
162 // Load the DXE Core and transfer control to it\r
163 Status = LoadDxeCoreFromFv (NULL, 0);\r
164 ASSERT_EFI_ERROR (Status);\r
165}\r
166\r
167VOID\r
168CEntryPoint (\r
0787bc61 169 IN UINTN MpId,\r
c524ffbb 170 IN UINTN UefiMemoryBase,\r
171 IN UINTN StacksBase,\r
172 IN UINTN GlobalVariableBase\r
cd872e40 173 )\r
174{\r
175 UINT64 StartTimeStamp;\r
2ee85366 176 \r
f437141a 177 // Initialize the platform specific controllers\r
178 ArmPlatformInitialize (MpId);\r
179\r
0787bc61 180 if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 181 // Initialize the Timer Library to setup the Timer HW controller\r
182 TimerConstructor ();\r
183 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
184 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 185 } else {\r
186 StartTimeStamp = 0;\r
cd872e40 187 }\r
188\r
d269095b 189 // Clean Data cache\r
190 ArmCleanInvalidateDataCache ();\r
cd872e40 191\r
d269095b 192 // Invalidate instruction cache\r
193 ArmInvalidateInstructionCache ();\r
cd872e40 194\r
195 //TODO:Drain Write Buffer\r
196\r
197 // Enable Instruction & Data caches\r
d269095b 198 ArmEnableDataCache ();\r
199 ArmEnableInstructionCache ();\r
cd872e40 200\r
99565b88 201 // Define the Global Variable region when we are not running in XIP\r
202 if (!IS_XIP()) {\r
203 if (IS_PRIMARY_CORE(MpId)) {\r
204 mGlobalVariableBase = GlobalVariableBase;\r
1aa9860e 205 if (ArmIsMpCore()) {\r
b1d41be7 206 // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)\r
207 ArmCallSEV ();\r
1aa9860e 208 }\r
99565b88 209 } else {\r
b1d41be7 210 // Wait the Primay core has defined the address of the Global Variable region (event: ARM_CPU_EVENT_DEFAULT)\r
211 ArmCallWFE ();\r
99565b88 212 }\r
213 }\r
214 \r
cd872e40 215 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 216 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
217 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 218\r
d269095b 219 // If not primary Jump to Secondary Main\r
0787bc61 220 if (IS_PRIMARY_CORE(MpId)) {\r
cd872e40 221 // Goto primary Main.\r
c524ffbb 222 PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
cd872e40 223 } else {\r
0787bc61 224 SecondaryMain (MpId);\r
cd872e40 225 }\r
226\r
227 // DXE Core should always load and never return\r
228 ASSERT (FALSE);\r
229}\r
230\r
231VOID\r
232PrePiCommonExceptionEntry (\r
233 IN UINT32 Entry,\r
234 IN UINT32 LR\r
235 )\r
236{\r
237 CHAR8 Buffer[100];\r
238 UINTN CharCount;\r
239\r
240 switch (Entry) {\r
241 case 0:\r
242 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
243 break;\r
244 case 1:\r
245 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
246 break;\r
247 case 2:\r
248 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
249 break;\r
250 case 3:\r
251 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
252 break;\r
253 case 4:\r
254 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
255 break;\r
256 case 5:\r
257 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
258 break;\r
259 case 6:\r
260 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
261 break;\r
262 case 7:\r
263 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
264 break;\r
265 default:\r
266 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
267 break;\r
268 }\r
269 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
270 while(1);\r
271}\r