]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg: Introduce Primary core macros
[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
cd872e40 54 IN UINT64 StartTimeStamp\r
55 )\r
56{\r
37573927 57 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
cd872e40 58 EFI_STATUS Status;\r
59 CHAR8 Buffer[100];\r
60 UINTN CharCount;\r
d269095b 61 UINTN UefiMemoryTop;\r
62 UINTN StacksSize;\r
63 UINTN StacksBase;\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
80\r
d269095b 81 UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
82 StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores);\r
83 StacksBase = UefiMemoryTop - StacksSize;\r
84\r
2ee85366 85 // Check the PcdCPUCoresNonSecStackBase match with the calculated StackBase\r
86 ASSERT (StacksBase == PcdGet32 (PcdCPUCoresNonSecStackBase));\r
87 \r
d269095b 88 // Declare the PI/UEFI memory region\r
37573927 89 HobList = HobConstructor (\r
cd872e40 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
37573927 95 PrePeiSetHobList (HobList);\r
cd872e40 96\r
97 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
98 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
99 ASSERT_EFI_ERROR (Status);\r
100\r
d269095b 101 // Create the Stacks HOB (reserve the memory for all stacks)\r
102 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 103\r
104 // Set the Boot Mode\r
105 SetBootMode (ArmPlatformGetBootMode ());\r
106\r
107 // Initialize Platform HOBs (CpuHob and FvHob)\r
108 Status = PlatformPeim ();\r
109 ASSERT_EFI_ERROR (Status);\r
110\r
111 BuildMemoryTypeInformationHob ();\r
112\r
cd872e40 113 // Now, the HOB List has been initialized, we can register performance information\r
114 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
115\r
116 // SEC phase needs to run library constructors by hand.\r
117 ExtractGuidedSectionLibConstructor ();\r
118 LzmaDecompressLibConstructor ();\r
119\r
120 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
121 BuildPeCoffLoaderHob ();\r
122 BuildExtractSectionHob (\r
123 &gLzmaCustomDecompressGuid,\r
124 LzmaGuidedSectionGetInfo,\r
125 LzmaGuidedSectionExtraction\r
126 );\r
127\r
128 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
129 Status = DecompressFirstFv ();\r
130 ASSERT_EFI_ERROR (Status);\r
131\r
132 // Load the DXE Core and transfer control to it\r
133 Status = LoadDxeCoreFromFv (NULL, 0);\r
134 ASSERT_EFI_ERROR (Status);\r
135}\r
136\r
137VOID\r
138CEntryPoint (\r
0787bc61 139 IN UINTN MpId,\r
d269095b 140 IN UINTN UefiMemoryBase\r
cd872e40 141 )\r
142{\r
143 UINT64 StartTimeStamp;\r
2ee85366 144 \r
0787bc61 145 if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r
cd872e40 146 // Initialize the Timer Library to setup the Timer HW controller\r
147 TimerConstructor ();\r
148 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
149 StartTimeStamp = GetPerformanceCounter ();\r
2ee85366 150 } else {\r
151 StartTimeStamp = 0;\r
cd872e40 152 }\r
153\r
d269095b 154 // Clean Data cache\r
155 ArmCleanInvalidateDataCache ();\r
cd872e40 156\r
d269095b 157 // Invalidate instruction cache\r
158 ArmInvalidateInstructionCache ();\r
cd872e40 159\r
160 //TODO:Drain Write Buffer\r
161\r
162 // Enable Instruction & Data caches\r
d269095b 163 ArmEnableDataCache ();\r
164 ArmEnableInstructionCache ();\r
cd872e40 165\r
166 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 167 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
168 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 169\r
d269095b 170 // If not primary Jump to Secondary Main\r
0787bc61 171 if (IS_PRIMARY_CORE(MpId)) {\r
cd872e40 172 // Goto primary Main.\r
d269095b 173 PrimaryMain (UefiMemoryBase, StartTimeStamp);\r
cd872e40 174 } else {\r
0787bc61 175 SecondaryMain (MpId);\r
cd872e40 176 }\r
177\r
178 // DXE Core should always load and never return\r
179 ASSERT (FALSE);\r
180}\r
181\r
182VOID\r
183PrePiCommonExceptionEntry (\r
184 IN UINT32 Entry,\r
185 IN UINT32 LR\r
186 )\r
187{\r
188 CHAR8 Buffer[100];\r
189 UINTN CharCount;\r
190\r
191 switch (Entry) {\r
192 case 0:\r
193 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
194 break;\r
195 case 1:\r
196 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
197 break;\r
198 case 2:\r
199 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
200 break;\r
201 case 3:\r
202 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
203 break;\r
204 case 4:\r
205 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
206 break;\r
207 case 5:\r
208 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
209 break;\r
210 case 6:\r
211 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
212 break;\r
213 case 7:\r
214 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
215 break;\r
216 default:\r
217 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
218 break;\r
219 }\r
220 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
221 while(1);\r
222}\r