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