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