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