]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
Add PeiCore module for enabling NT32Pkg, please attention this PeiCore does follows...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
CommitLineData
192f6d4c 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PeiMain.c\r
15\r
16Abstract:\r
17\r
18 Pei Core Main Entry Point\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
24//\r
25// Include common header file for this module.\r
26//\r
27#include "CommonHeader.h"\r
28\r
29#include <PeiMain.h>\r
30\r
31//\r
32//CAR is filled with this initial value during SEC phase\r
33//\r
34#define INIT_CAR_VALUE 0x5AA55AA5\r
35\r
36static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
37 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
38 &gEfiPeiMemoryDiscoveredPpiGuid,\r
39 NULL\r
40};\r
41\r
42//\r
43// Pei Core Module Variables\r
44//\r
45//\r
46static EFI_PEI_SERVICES mPS = {\r
47 {\r
48 PEI_SERVICES_SIGNATURE,\r
49 PEI_SERVICES_REVISION,\r
50 sizeof (EFI_PEI_SERVICES),\r
51 0,\r
52 0\r
53 },\r
54 PeiInstallPpi,\r
55 PeiReInstallPpi,\r
56 PeiLocatePpi,\r
57 PeiNotifyPpi,\r
58\r
59 PeiGetBootMode,\r
60 PeiSetBootMode,\r
61\r
62 PeiGetHobList,\r
63 PeiCreateHob,\r
64\r
65 PeiFvFindNextVolume,\r
66 PeiFfsFindNextFile,\r
67 PeiFfsFindSectionData,\r
68\r
69 PeiInstallPeiMemory,\r
70 PeiAllocatePages,\r
71 PeiAllocatePool,\r
72 (EFI_PEI_COPY_MEM)CopyMem,\r
73 (EFI_PEI_SET_MEM)SetMem,\r
74\r
75 PeiReportStatusCode,\r
76\r
77 PeiResetSystem\r
78};\r
79\r
80EFI_STATUS\r
81EFIAPI\r
82PeiCore (\r
83 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r
84 IN VOID *Data\r
85 )\r
86/*++\r
87\r
88Routine Description:\r
89\r
90 The entry routine to Pei Core, invoked by PeiMain during transition\r
91 from SEC to PEI. After switching stack in the PEI core, it will restart\r
92 with the old core data.\r
93\r
94Arguments:\r
95\r
96 PeiStartupDescriptor - Information and services provided by SEC phase.\r
97 OldCoreData - Pointer to old core data that is used to initialize the\r
98 core's data areas.\r
99\r
100Returns:\r
101\r
102 This function never returns\r
103 EFI_NOT_FOUND - Never reach\r
104\r
105--*/\r
106{\r
107 PEI_CORE_INSTANCE PrivateData;\r
108 EFI_STATUS Status;\r
109 PEI_CORE_TEMP_POINTERS TempPtr;\r
110 PEI_CORE_DISPATCH_DATA *DispatchData;\r
111 UINT64 mTick;\r
112 PEI_CORE_INSTANCE *OldCoreData;\r
113\r
114 mTick = 0;\r
115 OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
116\r
117 if (PerformanceMeasurementEnabled()) {\r
118 if (OldCoreData == NULL) {\r
119 mTick = GetPerformanceCounter ();\r
120 }\r
121 }\r
122\r
123 //\r
124 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
125 // the 63-bit of address is set to 1.\r
126 //\r
127 SWITCH_TO_CACHE_MODE (OldCoreData);\r
128\r
129 if (OldCoreData != NULL) {\r
130 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
131 } else {\r
132 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
133 }\r
134\r
135 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
136 PrivateData.PS = &mPS;\r
137\r
138 //\r
139 // Initialize libraries that the PeiCore is linked against\r
140 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?\r
141 //\r
142 ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
143\r
144 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);\r
145\r
146 InitializePpiServices (&PrivateData.PS, OldCoreData);\r
147\r
148 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
149\r
150 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);\r
151\r
152 if (OldCoreData != NULL) {\r
153\r
154 PERF_END (NULL,"PreMem", NULL, 0);\r
155 PERF_START (NULL,"PostMem", NULL, 0);\r
156\r
157 //\r
158 // The following code dumps out interesting cache as RAM usage information\r
159 // so we can keep tabs on how the cache as RAM is being utilized. The\r
160 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled\r
161 // on a debug build.\r
162 //\r
163 DEBUG_CODE_BEGIN ();\r
164 UINTN *StackPointer;\r
165 UINTN StackValue;\r
166\r
167 StackValue = INIT_CAR_VALUE;\r
168 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
169 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
170 && StackValue == INIT_CAR_VALUE;\r
171 StackPointer++) {\r
172 StackValue = *StackPointer;\r
173 }\r
174\r
175 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
176 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r
177 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
178 ));\r
179 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r
180 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
181 (UINTN) OldCoreData->HobList.Raw)\r
182 ));\r
183 DEBUG_CODE_END ();\r
184\r
185 //\r
186 // Alert any listeners that there is permanent memory available\r
187 //\r
188 \r
189 PERF_START (NULL,"DisMem", NULL, 0);\r
190 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
191 PERF_END (NULL,"DisMem", NULL, 0);\r
192\r
193 } else {\r
194\r
195 //\r
196 // Report Status Code EFI_SW_PC_INIT\r
197 //\r
198 REPORT_STATUS_CODE (\r
199 EFI_PROGRESS_CODE,\r
200 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r
201 );\r
202\r
203 PERF_START (NULL,"PEI", NULL, mTick);\r
204 //\r
205 // If first pass, start performance measurement.\r
206 //\r
207 PERF_START (NULL,"PreMem", NULL, mTick);\r
208\r
209 //\r
210 // If SEC provided any PPI services to PEI, install them.\r
211 //\r
212 if (PeiStartupDescriptor->DispatchTable != NULL) {\r
213 Status = PeiServicesInstallPpi (PeiStartupDescriptor->DispatchTable);\r
214 ASSERT_EFI_ERROR (Status);\r
215 }\r
216 }\r
217\r
218 DispatchData = &PrivateData.DispatchData;\r
219\r
220 //\r
221 // Call PEIM dispatcher\r
222 //\r
223 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);\r
224\r
225 //\r
226 // Check if InstallPeiMemory service was called.\r
227 //\r
228 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
229\r
230 PERF_END (NULL, "PostMem", NULL, 0);\r
231\r
232 Status = PeiServicesLocatePpi (\r
233 &gEfiDxeIplPpiGuid,\r
234 0,\r
235 NULL,\r
236 (VOID **)&TempPtr.DxeIpl\r
237 );\r
238 ASSERT_EFI_ERROR (Status);\r
239\r
240 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
241 Status = TempPtr.DxeIpl->Entry (\r
242 TempPtr.DxeIpl,\r
243 &PrivateData.PS,\r
244 PrivateData.HobList\r
245 );\r
246\r
247 ASSERT_EFI_ERROR (Status);\r
248\r
249 return EFI_NOT_FOUND;\r
250}\r
251\r