]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg: Minor code changes (comments, misspellings, coding stylei, line endings)
[mirror_edk2.git] / ArmPlatformPkg / PrePi / PrePi.c
CommitLineData
cd872e40 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
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
99565b88 17#include <Library/ArmCpuLib.h>\r
cd872e40 18#include <Library/DebugAgentLib.h>\r
19#include <Library/PrePiLib.h>\r
cd872e40 20#include <Library/PrintLib.h>\r
21#include <Library/PeCoffGetEntryPointLib.h>\r
37573927 22#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 23#include <Library/TimerLib.h>\r
24#include <Library/PerformanceLib.h>\r
25\r
26#include <Ppi/GuidedSectionExtraction.h>\r
27#include <Guid/LzmaDecompress.h>\r
8fc38a3f 28#include <Guid/ArmGlobalVariableHob.h>\r
cd872e40 29\r
30#include "PrePi.h"\r
31#include "LzmaDecompress.h"\r
32\r
99565b88 33#define IS_XIP() (((UINT32)FixedPcdGet32 (PcdFdBaseAddress) > (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r
8fc38a3f 34 ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r
35\r
36// Not used when PrePi in run in XIP mode\r
37UINTN mGlobalVariableBase = 0;\r
38\r
cd872e40 39VOID\r
40PrePiCommonExceptionEntry (\r
41 IN UINT32 Entry,\r
42 IN UINT32 LR\r
43 );\r
44\r
45EFI_STATUS\r
46EFIAPI\r
47ExtractGuidedSectionLibConstructor (\r
48 VOID\r
49 );\r
50\r
51EFI_STATUS\r
52EFIAPI\r
53LzmaDecompressLibConstructor (\r
54 VOID\r
55 );\r
56\r
8fc38a3f 57VOID\r
58EFIAPI\r
59BuildGlobalVariableHob (\r
60 IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r
61 IN UINT32 GlobalVariableSize\r
62 )\r
63{\r
64 ARM_HOB_GLOBAL_VARIABLE *Hob;\r
65\r
66 Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r
67 ASSERT(Hob != NULL);\r
68\r
69 CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r
70 Hob->GlobalVariableBase = GlobalVariableBase;\r
71 Hob->GlobalVariableSize = GlobalVariableSize;\r
72}\r
73\r
cd872e40 74VOID\r
75PrePiMain (\r
76 IN UINTN UefiMemoryBase,\r
c524ffbb 77 IN UINTN StacksBase,\r
78 IN UINTN GlobalVariableBase,\r
cd872e40 79 IN UINT64 StartTimeStamp\r
80 )\r
81{\r
37573927 82 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
cd872e40 83 EFI_STATUS Status;\r
84 CHAR8 Buffer[100];\r
85 UINTN CharCount;\r
d269095b 86 UINTN StacksSize;\r
cd872e40 87\r
8fc38a3f 88 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r
89 ASSERT (IS_XIP() || \r
90 ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r
99565b88 91 ((UINT32)(FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT32)(FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r
8fc38a3f 92\r
cd872e40 93 // Enable program flow prediction, if supported.\r
94 ArmEnableBranchPrediction ();\r
95\r
96 if (FixedPcdGet32(PcdVFPEnabled)) {\r
97 ArmEnableVFP();\r
98 }\r
99\r
100 // Initialize the Serial Port\r
101 SerialPortInitialize ();\r
102 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);\r
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
0787bc61 177 if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 178 // Initialize the Timer Library to setup the Timer HW controller\r
179 TimerConstructor ();\r
180 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
181 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 182 } else {\r
183 StartTimeStamp = 0;\r
cd872e40 184 }\r
185\r
d269095b 186 // Clean Data cache\r
187 ArmCleanInvalidateDataCache ();\r
cd872e40 188\r
d269095b 189 // Invalidate instruction cache\r
190 ArmInvalidateInstructionCache ();\r
cd872e40 191\r
192 //TODO:Drain Write Buffer\r
193\r
194 // Enable Instruction & Data caches\r
d269095b 195 ArmEnableDataCache ();\r
196 ArmEnableInstructionCache ();\r
cd872e40 197\r
99565b88 198 // Define the Global Variable region when we are not running in XIP\r
199 if (!IS_XIP()) {\r
200 if (IS_PRIMARY_CORE(MpId)) {\r
201 mGlobalVariableBase = GlobalVariableBase;\r
1aa9860e 202 if (ArmIsMpCore()) {\r
203 ArmCpuSynchronizeSignal (ARM_CPU_EVENT_DEFAULT);\r
204 }\r
99565b88 205 } else {\r
1aa9860e 206 // Wait the Primay core has defined the address of the Global Variable region\r
207 ArmCpuSynchronizeWait (ARM_CPU_EVENT_DEFAULT);\r
99565b88 208 }\r
209 }\r
210 \r
cd872e40 211 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 212 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
213 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 214\r
d269095b 215 // If not primary Jump to Secondary Main\r
0787bc61 216 if (IS_PRIMARY_CORE(MpId)) {\r
cd872e40 217 // Goto primary Main.\r
c524ffbb 218 PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r
cd872e40 219 } else {\r
0787bc61 220 SecondaryMain (MpId);\r
cd872e40 221 }\r
222\r
223 // DXE Core should always load and never return\r
224 ASSERT (FALSE);\r
225}\r
226\r
227VOID\r
228PrePiCommonExceptionEntry (\r
229 IN UINT32 Entry,\r
230 IN UINT32 LR\r
231 )\r
232{\r
233 CHAR8 Buffer[100];\r
234 UINTN CharCount;\r
235\r
236 switch (Entry) {\r
237 case 0:\r
238 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
239 break;\r
240 case 1:\r
241 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
242 break;\r
243 case 2:\r
244 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
245 break;\r
246 case 3:\r
247 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
248 break;\r
249 case 4:\r
250 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
251 break;\r
252 case 5:\r
253 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
254 break;\r
255 case 6:\r
256 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
257 break;\r
258 case 7:\r
259 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
260 break;\r
261 default:\r
262 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
263 break;\r
264 }\r
265 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
266 while(1);\r
267}\r