]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg/PrePi: Add support for PrePi module
[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
138 if ((CoreId == 0) && PerformanceMeasurementEnabled ()) {\r
139 // Initialize the Timer Library to setup the Timer HW controller\r
140 TimerConstructor ();\r
141 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
142 StartTimeStamp = GetPerformanceCounter ();\r
143 }\r
144\r
145 //Clean Data cache\r
146 ArmCleanInvalidateDataCache();\r
147\r
148 //Invalidate instruction cache\r
149 ArmInvalidateInstructionCache();\r
150\r
151 //TODO:Drain Write Buffer\r
152\r
153 // Enable Instruction & Data caches\r
154 ArmEnableDataCache();\r
155 ArmEnableInstructionCache();\r
156\r
157 // Write VBAR - The Vector table must be 32-byte aligned\r
158 ASSERT(((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
159 ArmWriteVBar((UINT32)PrePiVectorTable);\r
160\r
161 //If not primary Jump to Secondary Main\r
162 if(0 == CoreId) {\r
163 // Goto primary Main.\r
164 PrimaryMain (UefiMemoryBase, StackBase, StartTimeStamp);\r
165 } else {\r
166 SecondaryMain (CoreId);\r
167 }\r
168\r
169 // DXE Core should always load and never return\r
170 ASSERT (FALSE);\r
171}\r
172\r
173VOID\r
174PrePiCommonExceptionEntry (\r
175 IN UINT32 Entry,\r
176 IN UINT32 LR\r
177 )\r
178{\r
179 CHAR8 Buffer[100];\r
180 UINTN CharCount;\r
181\r
182 switch (Entry) {\r
183 case 0:\r
184 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
185 break;\r
186 case 1:\r
187 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
188 break;\r
189 case 2:\r
190 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
191 break;\r
192 case 3:\r
193 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
194 break;\r
195 case 4:\r
196 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
197 break;\r
198 case 5:\r
199 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
200 break;\r
201 case 6:\r
202 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
203 break;\r
204 case 7:\r
205 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
206 break;\r
207 default:\r
208 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
209 break;\r
210 }\r
211 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
212 while(1);\r
213}\r