]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
MdeModulePkg/MdeModulePkg.dec,.uni: Add NULL pointer detection PCD
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / X64 / DxeLoadFunc.c
... / ...
CommitLineData
1/** @file\r
2 x64-specifc functionality for DxeLoad.\r
3\r
4Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "DxeIpl.h"\r
16#include "X64/VirtualMemory.h"\r
17\r
18\r
19\r
20/**\r
21 Transfers control to DxeCore.\r
22\r
23 This function performs a CPU architecture specific operations to execute\r
24 the entry point of DxeCore with the parameters of HobList.\r
25 It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.\r
26\r
27 @param DxeCoreEntryPoint The entry point of DxeCore.\r
28 @param HobList The start of HobList passed to DxeCore.\r
29\r
30**/\r
31VOID\r
32HandOffToDxeCore (\r
33 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,\r
34 IN EFI_PEI_HOB_POINTERS HobList\r
35 )\r
36{\r
37 VOID *BaseOfStack;\r
38 VOID *TopOfStack;\r
39 EFI_STATUS Status;\r
40 UINTN PageTables;\r
41 UINT32 Index;\r
42 EFI_VECTOR_HANDOFF_INFO *VectorInfo;\r
43 EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r
44\r
45 //\r
46 // Get Vector Hand-off Info PPI and build Guided HOB\r
47 //\r
48 Status = PeiServicesLocatePpi (\r
49 &gEfiVectorHandoffInfoPpiGuid,\r
50 0,\r
51 NULL,\r
52 (VOID **)&VectorHandoffInfoPpi\r
53 );\r
54 if (Status == EFI_SUCCESS) {\r
55 DEBUG ((EFI_D_INFO, "Vector Hand-off Info PPI is gotten, GUIDed HOB is created!\n"));\r
56 VectorInfo = VectorHandoffInfoPpi->Info;\r
57 Index = 1;\r
58 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
59 VectorInfo ++;\r
60 Index ++;\r
61 }\r
62 BuildGuidDataHob (\r
63 &gEfiVectorHandoffInfoPpiGuid,\r
64 VectorHandoffInfoPpi->Info,\r
65 sizeof (EFI_VECTOR_HANDOFF_INFO) * Index\r
66 );\r
67 }\r
68\r
69 //\r
70 // Allocate 128KB for the Stack\r
71 //\r
72 BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));\r
73 ASSERT (BaseOfStack != NULL);\r
74\r
75 //\r
76 // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
77 // for safety.\r
78 //\r
79 TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);\r
80 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
81\r
82 PageTables = 0;\r
83 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {\r
84 //\r
85 // Create page table and save PageMapLevel4 to CR3\r
86 //\r
87 PageTables = CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS) (UINTN) BaseOfStack, STACK_SIZE);\r
88 } else {\r
89 //\r
90 // Set NX for stack feature also require PcdDxeIplBuildPageTables be TRUE\r
91 // for the DxeIpl and the DxeCore are both X64.\r
92 //\r
93 ASSERT (PcdGetBool (PcdSetNxForStack) == FALSE);\r
94 }\r
95 \r
96 //\r
97 // End of PEI phase signal\r
98 //\r
99 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);\r
100 ASSERT_EFI_ERROR (Status);\r
101\r
102 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {\r
103 AsmWriteCr3 (PageTables);\r
104 }\r
105\r
106 //\r
107 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
108 // \r
109 UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);\r
110\r
111 //\r
112 // Transfer the control to the entry point of DxeCore.\r
113 //\r
114 SwitchStack (\r
115 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
116 HobList.Raw,\r
117 NULL,\r
118 TopOfStack\r
119 );\r
120}\r