]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
MdeModulePkg/DxeIpl: Implement NULL pointer detection
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / X64 / DxeLoadFunc.c
CommitLineData
96226baa 1/** @file\r
91d92e25 2 x64-specifc functionality for DxeLoad.\r
95276127 3\r
5630cdfe 4Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
95276127 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
96226baa 13**/\r
95276127 14\r
95276127 15#include "DxeIpl.h"\r
f3b33289 16#include "X64/VirtualMemory.h"\r
95276127 17\r
91d92e25 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
48557c65 25 It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.\r
91d92e25 26\r
48557c65 27 @param DxeCoreEntryPoint The entry point of DxeCore.\r
91d92e25 28 @param HobList The start of HobList passed to DxeCore.\r
91d92e25 29\r
30**/\r
95276127 31VOID\r
32HandOffToDxeCore (\r
33 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,\r
9b937a73 34 IN EFI_PEI_HOB_POINTERS HobList\r
95276127 35 )\r
36{\r
57f360f2
JF
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
9189ec20
JW
45 if (IsNullDetectionEnabled ()) {\r
46 ClearFirst4KPage (HobList.Raw);\r
47 }\r
48\r
57f360f2
JF
49 //\r
50 // Get Vector Hand-off Info PPI and build Guided HOB\r
51 //\r
52 Status = PeiServicesLocatePpi (\r
53 &gEfiVectorHandoffInfoPpiGuid,\r
54 0,\r
55 NULL,\r
56 (VOID **)&VectorHandoffInfoPpi\r
57 );\r
58 if (Status == EFI_SUCCESS) {\r
59 DEBUG ((EFI_D_INFO, "Vector Hand-off Info PPI is gotten, GUIDed HOB is created!\n"));\r
60 VectorInfo = VectorHandoffInfoPpi->Info;\r
61 Index = 1;\r
62 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
63 VectorInfo ++;\r
64 Index ++;\r
65 }\r
66 BuildGuidDataHob (\r
67 &gEfiVectorHandoffInfoPpiGuid,\r
68 VectorHandoffInfoPpi->Info,\r
69 sizeof (EFI_VECTOR_HANDOFF_INFO) * Index\r
70 );\r
71 }\r
95276127 72\r
73 //\r
74 // Allocate 128KB for the Stack\r
75 //\r
76 BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));\r
77 ASSERT (BaseOfStack != NULL);\r
78\r
79 //\r
80 // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
81 // for safety.\r
82 //\r
83 TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);\r
84 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
85\r
d042796c 86 PageTables = 0;\r
e47f0da4 87 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {\r
88 //\r
89 // Create page table and save PageMapLevel4 to CR3\r
90 //\r
5630cdfe
SZ
91 PageTables = CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS) (UINTN) BaseOfStack, STACK_SIZE);\r
92 } else {\r
93 //\r
94 // Set NX for stack feature also require PcdDxeIplBuildPageTables be TRUE\r
95 // for the DxeIpl and the DxeCore are both X64.\r
96 //\r
97 ASSERT (PcdGetBool (PcdSetNxForStack) == FALSE);\r
e47f0da4 98 }\r
99 \r
95276127 100 //\r
48557c65 101 // End of PEI phase signal\r
95276127 102 //\r
9b937a73 103 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);\r
95276127 104 ASSERT_EFI_ERROR (Status);\r
105\r
e47f0da4 106 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {\r
107 AsmWriteCr3 (PageTables);\r
108 }\r
f3b33289 109\r
30c8f861 110 //\r
111 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
112 // \r
189575e8 113 UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);\r
30c8f861 114\r
b98da1b1 115 //\r
116 // Transfer the control to the entry point of DxeCore.\r
117 //\r
95276127 118 SwitchStack (\r
119 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
120 HobList.Raw,\r
121 NULL,\r
122 TopOfStack\r
123 );\r
124}\r