]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 - 2018, Intel Corporation. All rights reserved.<BR>\r
5SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include "DxeIpl.h"\r
10#include "X64/VirtualMemory.h"\r
11\r
12/**\r
13 Transfers control to DxeCore.\r
14\r
15 This function performs a CPU architecture specific operations to execute\r
16 the entry point of DxeCore with the parameters of HobList.\r
17 It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.\r
18\r
19 @param DxeCoreEntryPoint The entry point of DxeCore.\r
20 @param HobList The start of HobList passed to DxeCore.\r
21\r
22**/\r
23VOID\r
24HandOffToDxeCore (\r
25 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,\r
26 IN EFI_PEI_HOB_POINTERS HobList\r
27 )\r
28{\r
29 VOID *BaseOfStack;\r
30 VOID *TopOfStack;\r
31 EFI_STATUS Status;\r
32 UINTN PageTables;\r
33 UINT32 Index;\r
34 EFI_VECTOR_HANDOFF_INFO *VectorInfo;\r
35 EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;\r
36 VOID *GhcbBase;\r
37 UINTN GhcbSize;\r
38\r
39 //\r
40 // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.\r
41 //\r
42 if (IsNullDetectionEnabled ()) {\r
43 ClearFirst4KPage (HobList.Raw);\r
44 BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData);\r
45 }\r
46\r
47 //\r
48 // Get Vector Hand-off Info PPI and build Guided HOB\r
49 //\r
50 Status = PeiServicesLocatePpi (\r
51 &gEfiVectorHandoffInfoPpiGuid,\r
52 0,\r
53 NULL,\r
54 (VOID **)&VectorHandoffInfoPpi\r
55 );\r
56 if (Status == EFI_SUCCESS) {\r
57 DEBUG ((DEBUG_INFO, "Vector Hand-off Info PPI is gotten, GUIDed HOB is created!\n"));\r
58 VectorInfo = VectorHandoffInfoPpi->Info;\r
59 Index = 1;\r
60 while (VectorInfo->Attribute != EFI_VECTOR_HANDOFF_LAST_ENTRY) {\r
61 VectorInfo++;\r
62 Index++;\r
63 }\r
64\r
65 BuildGuidDataHob (\r
66 &gEfiVectorHandoffInfoPpiGuid,\r
67 VectorHandoffInfoPpi->Info,\r
68 sizeof (EFI_VECTOR_HANDOFF_INFO) * Index\r
69 );\r
70 }\r
71\r
72 //\r
73 // Allocate 128KB for the Stack\r
74 //\r
75 BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));\r
76 ASSERT (BaseOfStack != NULL);\r
77\r
78 //\r
79 // Compute the top of the stack we were allocated. Pre-allocate a UINTN\r
80 // for safety.\r
81 //\r
82 TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);\r
83 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);\r
84\r
85 //\r
86 // Get the address and size of the GHCB pages\r
87 //\r
88 GhcbBase = (VOID *)PcdGet64 (PcdGhcbBase);\r
89 GhcbSize = PcdGet64 (PcdGhcbSize);\r
90\r
91 PageTables = 0;\r
92 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {\r
93 //\r
94 // Create page table and save PageMapLevel4 to CR3\r
95 //\r
96 PageTables = CreateIdentityMappingPageTables (\r
97 (EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack,\r
98 STACK_SIZE,\r
99 (EFI_PHYSICAL_ADDRESS)(UINTN)GhcbBase,\r
100 GhcbSize\r
101 );\r
102 } else {\r
103 //\r
104 // Set NX for stack feature also require PcdDxeIplBuildPageTables be TRUE\r
105 // for the DxeIpl and the DxeCore are both X64.\r
106 //\r
107 ASSERT (PcdGetBool (PcdSetNxForStack) == FALSE);\r
108 ASSERT (PcdGetBool (PcdCpuStackGuard) == FALSE);\r
109 }\r
110\r
111 //\r
112 // End of PEI phase signal\r
113 //\r
114 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);\r
115 ASSERT_EFI_ERROR (Status);\r
116\r
117 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {\r
118 AsmWriteCr3 (PageTables);\r
119 }\r
120\r
121 //\r
122 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.\r
123 //\r
124 UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);\r
125\r
126 //\r
127 // Transfer the control to the entry point of DxeCore.\r
128 //\r
129 SwitchStack (\r
130 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,\r
131 HobList.Raw,\r
132 NULL,\r
133 TopOfStack\r
134 );\r
135}\r