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