]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
EmbeddedPkg/Ebl: Fix EBL copy file command
[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
37573927 22#include <Library/PrePiHobListPointerLib.h>\r
cd872e40 23#include <Library/TimerLib.h>\r
24#include <Library/PerformanceLib.h>\r
25\r
26#include <Ppi/GuidedSectionExtraction.h>\r
27#include <Guid/LzmaDecompress.h>\r
28\r
29#include "PrePi.h"\r
30#include "LzmaDecompress.h"\r
31\r
32VOID\r
33PrePiCommonExceptionEntry (\r
34 IN UINT32 Entry,\r
35 IN UINT32 LR\r
36 );\r
37\r
38EFI_STATUS\r
39EFIAPI\r
40ExtractGuidedSectionLibConstructor (\r
41 VOID\r
42 );\r
43\r
44EFI_STATUS\r
45EFIAPI\r
46LzmaDecompressLibConstructor (\r
47 VOID\r
48 );\r
49\r
50VOID\r
51PrePiMain (\r
52 IN UINTN UefiMemoryBase,\r
cd872e40 53 IN UINT64 StartTimeStamp\r
54 )\r
55{\r
37573927 56 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
cd872e40 57 EFI_STATUS Status;\r
58 CHAR8 Buffer[100];\r
59 UINTN CharCount;\r
d269095b 60 UINTN UefiMemoryTop;\r
61 UINTN StacksSize;\r
62 UINTN StacksBase;\r
cd872e40 63\r
64 // Enable program flow prediction, if supported.\r
65 ArmEnableBranchPrediction ();\r
66\r
67 if (FixedPcdGet32(PcdVFPEnabled)) {\r
68 ArmEnableVFP();\r
69 }\r
70\r
71 // Initialize the Serial Port\r
72 SerialPortInitialize ();\r
73 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);\r
74 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
75\r
76 // Initialize the Debug Agent for Source Level Debugging\r
77 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
78 SaveAndSetDebugTimerInterrupt (TRUE);\r
79\r
d269095b 80 UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
81 StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores);\r
82 StacksBase = UefiMemoryTop - StacksSize;\r
83\r
2ee85366 84 // Check the PcdCPUCoresNonSecStackBase match with the calculated StackBase\r
85 ASSERT (StacksBase == PcdGet32 (PcdCPUCoresNonSecStackBase));\r
86 \r
d269095b 87 // Declare the PI/UEFI memory region\r
37573927 88 HobList = HobConstructor (\r
cd872e40 89 (VOID*)UefiMemoryBase,\r
90 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
91 (VOID*)UefiMemoryBase,\r
d269095b 92 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
93 );\r
37573927 94 PrePeiSetHobList (HobList);\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