]>
Commit | Line | Data |
---|---|---|
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/BaseMemoryLib.h>\r | |
19 | #include <Library/PrePiLib.h>\r | |
20 | #include <Library/IoLib.h>\r | |
21 | #include <Library/PrintLib.h>\r | |
22 | #include <Library/PeCoffGetEntryPointLib.h>\r | |
23 | #include <Library/PrePiHobListPointerLib.h>\r | |
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 | #include <Guid/ArmGlobalVariableHob.h>\r | |
30 | \r | |
31 | #include "PrePi.h"\r | |
32 | #include "LzmaDecompress.h"\r | |
33 | \r | |
34 | #define IS_XIP() ((FixedPcdGet32 (PcdFdBaseAddress) > (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize))) || \\r | |
35 | ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet32 (PcdSystemMemoryBase)))\r | |
36 | \r | |
37 | // Not used when PrePi in run in XIP mode\r | |
38 | UINTN mGlobalVariableBase = 0;\r | |
39 | \r | |
40 | VOID\r | |
41 | PrePiCommonExceptionEntry (\r | |
42 | IN UINT32 Entry,\r | |
43 | IN UINT32 LR\r | |
44 | );\r | |
45 | \r | |
46 | EFI_STATUS\r | |
47 | EFIAPI\r | |
48 | ExtractGuidedSectionLibConstructor (\r | |
49 | VOID\r | |
50 | );\r | |
51 | \r | |
52 | EFI_STATUS\r | |
53 | EFIAPI\r | |
54 | LzmaDecompressLibConstructor (\r | |
55 | VOID\r | |
56 | );\r | |
57 | \r | |
58 | VOID\r | |
59 | EFIAPI\r | |
60 | BuildGlobalVariableHob (\r | |
61 | IN EFI_PHYSICAL_ADDRESS GlobalVariableBase,\r | |
62 | IN UINT32 GlobalVariableSize\r | |
63 | )\r | |
64 | {\r | |
65 | ARM_HOB_GLOBAL_VARIABLE *Hob;\r | |
66 | \r | |
67 | Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, sizeof (ARM_HOB_GLOBAL_VARIABLE));\r | |
68 | ASSERT(Hob != NULL);\r | |
69 | \r | |
70 | CopyGuid (&(Hob->Header.Name), &gArmGlobalVariableGuid);\r | |
71 | Hob->GlobalVariableBase = GlobalVariableBase;\r | |
72 | Hob->GlobalVariableSize = GlobalVariableSize;\r | |
73 | }\r | |
74 | \r | |
75 | VOID\r | |
76 | PrePiMain (\r | |
77 | IN UINTN UefiMemoryBase,\r | |
78 | IN UINTN StacksBase,\r | |
79 | IN UINTN GlobalVariableBase,\r | |
80 | IN UINT64 StartTimeStamp\r | |
81 | )\r | |
82 | {\r | |
83 | EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r | |
84 | EFI_STATUS Status;\r | |
85 | CHAR8 Buffer[100];\r | |
86 | UINTN CharCount;\r | |
87 | UINTN StacksSize;\r | |
88 | \r | |
89 | // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)\r | |
90 | ASSERT (IS_XIP() || \r | |
91 | ((FixedPcdGet32 (PcdFdBaseAddress) >= FixedPcdGet32 (PcdSystemMemoryBase)) &&\r | |
92 | ((FixedPcdGet32 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (FixedPcdGet32 (PcdSystemMemoryBase) + FixedPcdGet32 (PcdSystemMemorySize)))));\r | |
93 | \r | |
94 | // Enable program flow prediction, if supported.\r | |
95 | ArmEnableBranchPrediction ();\r | |
96 | \r | |
97 | if (FixedPcdGet32(PcdVFPEnabled)) {\r | |
98 | ArmEnableVFP();\r | |
99 | }\r | |
100 | \r | |
101 | // Initialize the Serial Port\r | |
102 | SerialPortInitialize ();\r | |
103 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware built at %a on %a\n\r",__TIME__, __DATE__);\r | |
104 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
105 | \r | |
106 | // Initialize the Debug Agent for Source Level Debugging\r | |
107 | InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r | |
108 | SaveAndSetDebugTimerInterrupt (TRUE);\r | |
109 | \r | |
110 | if (!IS_XIP()) {\r | |
111 | mGlobalVariableBase = GlobalVariableBase;\r | |
112 | }\r | |
113 | \r | |
114 | // Declare the PI/UEFI memory region\r | |
115 | HobList = HobConstructor (\r | |
116 | (VOID*)UefiMemoryBase,\r | |
117 | FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r | |
118 | (VOID*)UefiMemoryBase,\r | |
119 | (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r | |
120 | );\r | |
121 | PrePeiSetHobList (HobList);\r | |
122 | \r | |
123 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r | |
124 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
125 | ASSERT_EFI_ERROR (Status);\r | |
126 | \r | |
127 | // Create the Stacks HOB (reserve the memory for all stacks)\r | |
128 | StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize) + (FixedPcdGet32(PcdClusterCount) * 4 * FixedPcdGet32(PcdCPUCoreSecondaryStackSize));\r | |
129 | BuildStackHob (StacksBase, StacksSize);\r | |
130 | \r | |
131 | // Declare the Global Variable HOB\r | |
132 | BuildGlobalVariableHob (GlobalVariableBase, FixedPcdGet32 (PcdPeiGlobalVariableSize));\r | |
133 | \r | |
134 | //TODO: Call CpuPei as a library\r | |
135 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r | |
136 | \r | |
137 | // Set the Boot Mode\r | |
138 | SetBootMode (ArmPlatformGetBootMode ());\r | |
139 | \r | |
140 | // Initialize Platform HOBs (CpuHob and FvHob)\r | |
141 | Status = PlatformPeim ();\r | |
142 | ASSERT_EFI_ERROR (Status);\r | |
143 | \r | |
144 | BuildMemoryTypeInformationHob ();\r | |
145 | \r | |
146 | // Now, the HOB List has been initialized, we can register performance information\r | |
147 | PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r | |
148 | \r | |
149 | // SEC phase needs to run library constructors by hand.\r | |
150 | ExtractGuidedSectionLibConstructor ();\r | |
151 | LzmaDecompressLibConstructor ();\r | |
152 | \r | |
153 | // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r | |
154 | BuildPeCoffLoaderHob ();\r | |
155 | BuildExtractSectionHob (\r | |
156 | &gLzmaCustomDecompressGuid,\r | |
157 | LzmaGuidedSectionGetInfo,\r | |
158 | LzmaGuidedSectionExtraction\r | |
159 | );\r | |
160 | \r | |
161 | // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r | |
162 | Status = DecompressFirstFv ();\r | |
163 | ASSERT_EFI_ERROR (Status);\r | |
164 | \r | |
165 | // Load the DXE Core and transfer control to it\r | |
166 | Status = LoadDxeCoreFromFv (NULL, 0);\r | |
167 | ASSERT_EFI_ERROR (Status);\r | |
168 | }\r | |
169 | \r | |
170 | VOID\r | |
171 | CEntryPoint (\r | |
172 | IN UINTN MpId,\r | |
173 | IN UINTN UefiMemoryBase,\r | |
174 | IN UINTN StacksBase,\r | |
175 | IN UINTN GlobalVariableBase\r | |
176 | )\r | |
177 | {\r | |
178 | UINT64 StartTimeStamp;\r | |
179 | \r | |
180 | if (IS_PRIMARY_CORE(MpId) && PerformanceMeasurementEnabled ()) {\r | |
181 | // Initialize the Timer Library to setup the Timer HW controller\r | |
182 | TimerConstructor ();\r | |
183 | // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r | |
184 | StartTimeStamp = GetPerformanceCounter ();\r | |
185 | } else {\r | |
186 | StartTimeStamp = 0;\r | |
187 | }\r | |
188 | \r | |
189 | // Clean Data cache\r | |
190 | ArmCleanInvalidateDataCache ();\r | |
191 | \r | |
192 | // Invalidate instruction cache\r | |
193 | ArmInvalidateInstructionCache ();\r | |
194 | \r | |
195 | //TODO:Drain Write Buffer\r | |
196 | \r | |
197 | // Enable Instruction & Data caches\r | |
198 | ArmEnableDataCache ();\r | |
199 | ArmEnableInstructionCache ();\r | |
200 | \r | |
201 | // Write VBAR - The Vector table must be 32-byte aligned\r | |
202 | ASSERT (((UINT32)PrePiVectorTable & ((1 << 5)-1)) == 0);\r | |
203 | ArmWriteVBar ((UINT32)PrePiVectorTable);\r | |
204 | \r | |
205 | // If not primary Jump to Secondary Main\r | |
206 | if (IS_PRIMARY_CORE(MpId)) {\r | |
207 | // Goto primary Main.\r | |
208 | PrimaryMain (UefiMemoryBase, StacksBase, GlobalVariableBase, StartTimeStamp);\r | |
209 | } else {\r | |
210 | SecondaryMain (MpId);\r | |
211 | }\r | |
212 | \r | |
213 | // DXE Core should always load and never return\r | |
214 | ASSERT (FALSE);\r | |
215 | }\r | |
216 | \r | |
217 | VOID\r | |
218 | PrePiCommonExceptionEntry (\r | |
219 | IN UINT32 Entry,\r | |
220 | IN UINT32 LR\r | |
221 | )\r | |
222 | {\r | |
223 | CHAR8 Buffer[100];\r | |
224 | UINTN CharCount;\r | |
225 | \r | |
226 | switch (Entry) {\r | |
227 | case 0:\r | |
228 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR);\r | |
229 | break;\r | |
230 | case 1:\r | |
231 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR);\r | |
232 | break;\r | |
233 | case 2:\r | |
234 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR);\r | |
235 | break;\r | |
236 | case 3:\r | |
237 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR);\r | |
238 | break;\r | |
239 | case 4:\r | |
240 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR);\r | |
241 | break;\r | |
242 | case 5:\r | |
243 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR);\r | |
244 | break;\r | |
245 | case 6:\r | |
246 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR);\r | |
247 | break;\r | |
248 | case 7:\r | |
249 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR);\r | |
250 | break;\r | |
251 | default:\r | |
252 | CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR);\r | |
253 | break;\r | |
254 | }\r | |
255 | SerialPortWrite ((UINT8 *) Buffer, CharCount);\r | |
256 | while(1);\r | |
257 | }\r |