]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/PrePi/PrePi.c
ArmPlatformPkg: Change the memory model for the ARM Platform components
[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
cd872e40 52 IN UINT64 StartTimeStamp\r
53 )\r
54{\r
d269095b 55 EFI_HOB_HANDOFF_INFO_TABLE** PrePiHobBase;\r
cd872e40 56 EFI_STATUS Status;\r
57 CHAR8 Buffer[100];\r
58 UINTN CharCount;\r
d269095b 59 UINTN UefiMemoryTop;\r
60 UINTN StacksSize;\r
61 UINTN StacksBase;\r
cd872e40 62\r
63 // Enable program flow prediction, if supported.\r
64 ArmEnableBranchPrediction ();\r
65\r
66 if (FixedPcdGet32(PcdVFPEnabled)) {\r
67 ArmEnableVFP();\r
68 }\r
69\r
70 // Initialize the Serial Port\r
71 SerialPortInitialize ();\r
72 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);\r
73 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
74\r
75 // Initialize the Debug Agent for Source Level Debugging\r
76 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
77 SaveAndSetDebugTimerInterrupt (TRUE);\r
78\r
79 PrePiHobBase = (EFI_HOB_HANDOFF_INFO_TABLE**)(PcdGet32 (PcdCPUCoresNonSecStackBase) + (PcdGet32 (PcdCPUCoresNonSecStackSize) / 2) - PcdGet32 (PcdHobListPtrGlobalOffset));\r
80\r
d269095b 81 UefiMemoryTop = UefiMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r
82 StacksSize = PcdGet32 (PcdCPUCoresNonSecStackSize) * PcdGet32 (PcdMPCoreMaxCores);\r
83 StacksBase = UefiMemoryTop - StacksSize;\r
84\r
85 // Declare the PI/UEFI memory region\r
cd872e40 86 *PrePiHobBase = HobConstructor (\r
87 (VOID*)UefiMemoryBase,\r
88 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
89 (VOID*)UefiMemoryBase,\r
d269095b 90 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
91 );\r
cd872e40 92\r
93 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
94 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
95 ASSERT_EFI_ERROR (Status);\r
96\r
d269095b 97 // Create the Stacks HOB (reserve the memory for all stacks)\r
98 BuildStackHob (StacksBase, StacksSize);\r
cd872e40 99\r
100 // Set the Boot Mode\r
101 SetBootMode (ArmPlatformGetBootMode ());\r
102\r
103 // Initialize Platform HOBs (CpuHob and FvHob)\r
104 Status = PlatformPeim ();\r
105 ASSERT_EFI_ERROR (Status);\r
106\r
107 BuildMemoryTypeInformationHob ();\r
108\r
d269095b 109 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL, NULL);\r
110 SaveAndSetDebugTimerInterrupt (TRUE);\r
cd872e40 111\r
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
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
149 }\r
150\r
d269095b 151 // Clean Data cache\r
152 ArmCleanInvalidateDataCache ();\r
cd872e40 153\r
d269095b 154 // Invalidate instruction cache\r
155 ArmInvalidateInstructionCache ();\r
cd872e40 156\r
157 //TODO:Drain Write Buffer\r
158\r
159 // Enable Instruction & Data caches\r
d269095b 160 ArmEnableDataCache ();\r
161 ArmEnableInstructionCache ();\r
cd872e40 162\r
163 // Write VBAR - The Vector table must be 32-byte aligned\r
d269095b 164 ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r
165 ArmWriteVBar ((UINT32)PrePiVectorTable);\r
cd872e40 166\r
d269095b 167 // If not primary Jump to Secondary Main\r
168 if (CoreId == ARM_PRIMARY_CORE) {\r
cd872e40 169 // Goto primary Main.\r
d269095b 170 PrimaryMain (UefiMemoryBase, StartTimeStamp);\r
cd872e40 171 } else {\r
172 SecondaryMain (CoreId);\r
173 }\r
174\r
175 // DXE Core should always load and never return\r
176 ASSERT (FALSE);\r
177}\r
178\r
179VOID\r
180PrePiCommonExceptionEntry (\r
181 IN UINT32 Entry,\r
182 IN UINT32 LR\r
183 )\r
184{\r
185 CHAR8 Buffer[100];\r
186 UINTN CharCount;\r
187\r
188 switch (Entry) {\r
189 case 0:\r
190 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r
191 break;\r
192 case 1:\r
193 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r
194 break;\r
195 case 2:\r
196 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r
197 break;\r
198 case 3:\r
199 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r
200 break;\r
201 case 4:\r
202 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r
203 break;\r
204 case 5:\r
205 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r
206 break;\r
207 case 6:\r
208 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r
209 break;\r
210 case 7:\r
211 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r
212 break;\r
213 default:\r
214 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r
215 break;\r
216 }\r
217 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
218 while(1);\r
219}\r