]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPkg: Fix ARMGCC build
[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
17#include <Library/DebugAgentLib.h>\r
18#include <Library/PrePiLib.h>\r
19#include <Library/IoLib.h>\r
20#include <Library/PrintLib.h>\r
21#include <Library/PeCoffGetEntryPointLib.h>\r
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
27\r
28#include "PrePi.h"\r
29#include "LzmaDecompress.h"\r
30\r
31VOID\r
32PrePiCommonExceptionEntry (\r
33 IN UINT32 Entry,\r
34 IN UINT32 LR\r
35 );\r
36\r
37EFI_STATUS\r
38EFIAPI\r
39ExtractGuidedSectionLibConstructor (\r
40 VOID\r
41 );\r
42\r
43EFI_STATUS\r
44EFIAPI\r
45LzmaDecompressLibConstructor (\r
46 VOID\r
47 );\r
48\r
49VOID\r
50PrePiMain (\r
51 IN UINTN UefiMemoryBase,\r
cd872e40 52 IN UINT64 StartTimeStamp\r
53 )\r
54{\r
d269095b 55 EFI_HOB_HANDOFF_INFO_TABLE** PrePiHobBase;\r
cd872e40 56 EFI_STATUS Status;\r
57 CHAR8 Buffer[100];\r
58 UINTN CharCount;\r
d269095b 59 UINTN UefiMemoryTop;\r
60 UINTN StacksSize;\r
61 UINTN StacksBase;\r
cd872e40 62\r
63 // Enable program flow prediction, if supported.\r
64 ArmEnableBranchPrediction ();\r
65\r
66 if (FixedPcdGet32(PcdVFPEnabled)) {\r
67 ArmEnableVFP();\r
68 }\r
69\r
70 // Initialize the Serial Port\r
71 SerialPortInitialize ();\r
72 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);\r
73 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
74\r
75 // Initialize the Debug Agent for Source Level Debugging\r
76 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
77 SaveAndSetDebugTimerInterrupt (TRUE);\r
78\r
d269095b 79 UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
80 StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores);\r
81 StacksBase = UefiMemoryTop - StacksSize;\r
82\r
2ee85366 83 // Check the PcdCPUCoresNonSecStackBase match with the calculated StackBase\r
84 ASSERT (StacksBase == PcdGet32 (PcdCPUCoresNonSecStackBase));\r
85 \r
86 PrePiHobBase = (EFI_HOB_HANDOFF_INFO_TABLE**)(PcdGet32 (PcdCPUCoresNonSecStackBase) + (PcdGet32 (PcdCPUCoresNonSecStackSize) / 2) - PcdGet32 (PcdHobListPtrGlobalOffset));\r
87\r
d269095b 88 // Declare the PI/UEFI memory region\r
cd872e40 89 *PrePiHobBase = HobConstructor (\r
90 (VOID*)UefiMemoryBase,\r
91 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
92 (VOID*)UefiMemoryBase,\r
d269095b 93 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
94 );\r
cd872e40 95\r
96 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
97 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
98 ASSERT_EFI_ERROR (Status);\r
99\r
d269095b 100 // Create the Stacks HOB (reserve the memory for all stacks)\r
101 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 102\r
103 // Set the Boot Mode\r
104 SetBootMode (ArmPlatformGetBootMode ());\r
105\r
106 // Initialize Platform HOBs (CpuHob and FvHob)\r
107 Status = PlatformPeim ();\r
108 ASSERT_EFI_ERROR (Status);\r
109\r
110 BuildMemoryTypeInformationHob ();\r
111\r
cd872e40 112 // Now, the HOB List has been initialized, we can register performance information\r
113 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
114\r
115 // SEC phase needs to run library constructors by hand.\r
116 ExtractGuidedSectionLibConstructor ();\r
117 LzmaDecompressLibConstructor ();\r
118\r
119 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
120 BuildPeCoffLoaderHob ();\r
121 BuildExtractSectionHob (\r
122 &gLzmaCustomDecompressGuid,\r
123 LzmaGuidedSectionGetInfo,\r
124 LzmaGuidedSectionExtraction\r
125 );\r
126\r
127 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
128 Status = DecompressFirstFv ();\r
129 ASSERT_EFI_ERROR (Status);\r
130\r
131 // Load the DXE Core and transfer control to it\r
132 Status = LoadDxeCoreFromFv (NULL, 0);\r
133 ASSERT_EFI_ERROR (Status);\r
134}\r
135\r
136VOID\r
137CEntryPoint (\r
138 IN UINTN CoreId,\r
d269095b 139 IN UINTN UefiMemoryBase\r
cd872e40 140 )\r
141{\r
142 UINT64 StartTimeStamp;\r
2ee85366 143 \r
d269095b 144 if ((CoreId == ARM_PRIMARY_CORE) && PerformanceMeasurementEnabled ()) {\r
cd872e40 145 // Initialize the Timer Library to setup the Timer HW controller\r
146 TimerConstructor ();\r
147 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
148 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 149 } else {\r
150 StartTimeStamp = 0;\r
cd872e40 151 }\r
152\r
d269095b 153 // Clean Data cache\r
154 ArmCleanInvalidateDataCache ();\r
cd872e40 155\r
d269095b 156 // Invalidate instruction cache\r
157 ArmInvalidateInstructionCache ();\r
cd872e40 158\r
159 //TODO:Drain Write Buffer\r
160\r
161 // Enable Instruction & Data caches\r
d269095b 162 ArmEnableDataCache ();\r
163 ArmEnableInstructionCache ();\r
cd872e40 164\r
165 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 166 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
167 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 168\r
d269095b 169 // If not primary Jump to Secondary Main\r
170 if (CoreId == ARM_PRIMARY_CORE) {\r
cd872e40 171 // Goto primary Main.\r
d269095b 172 PrimaryMain (UefiMemoryBase, StartTimeStamp);\r
cd872e40 173 } else {\r
174 SecondaryMain (CoreId);\r
175 }\r
176\r
177 // DXE Core should always load and never return\r
178 ASSERT (FALSE);\r
179}\r
180\r
181VOID\r
182PrePiCommonExceptionEntry (\r
183 IN UINT32 Entry,\r
184 IN UINT32 LR\r
185 )\r
186{\r
187 CHAR8 Buffer[100];\r
188 UINTN CharCount;\r
189\r
190 switch (Entry) {\r
191 case 0:\r
192 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
193 break;\r
194 case 1:\r
195 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
196 break;\r
197 case 2:\r
198 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
199 break;\r
200 case 3:\r
201 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
202 break;\r
203 case 4:\r
204 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
205 break;\r
206 case 5:\r
207 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
208 break;\r
209 case 6:\r
210 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
211 break;\r
212 case 7:\r
213 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
214 break;\r
215 default:\r
216 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
217 break;\r
218 }\r
219 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
220 while(1);\r
221}\r