1 | /** @file
|
---|
2 | x64-specifc functionality for DxeLoad.
|
---|
3 |
|
---|
4 | Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include <PiPei.h>
|
---|
10 | #include <Library/BaseLib.h>
|
---|
11 | #include <Library/DebugLib.h>
|
---|
12 | #include <Library/BaseMemoryLib.h>
|
---|
13 | #include <Library/MemoryAllocationLib.h>
|
---|
14 | #include <Library/PcdLib.h>
|
---|
15 | #include <Library/HobLib.h>
|
---|
16 | #include <Library/FdtLib.h>
|
---|
17 | #include "X64/VirtualMemory.h"
|
---|
18 | #include "UefiPayloadEntry.h"
|
---|
19 | #define STACK_SIZE 0x20000
|
---|
20 |
|
---|
21 | extern VOID *mHobList;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Transfers control to DxeCore.
|
---|
25 |
|
---|
26 | This function performs a CPU architecture specific operations to execute
|
---|
27 | the entry point of DxeCore with the parameters of HobList.
|
---|
28 | It also installs EFI_END_OF_PEI_PPI to signal the end of PEI phase.
|
---|
29 |
|
---|
30 | @param DxeCoreEntryPoint The entry point of DxeCore.
|
---|
31 | @param HobList The start of HobList passed to DxeCore.
|
---|
32 |
|
---|
33 | **/
|
---|
34 | VOID
|
---|
35 | HandOffToDxeCore (
|
---|
36 | IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
|
---|
37 | IN EFI_PEI_HOB_POINTERS HobList
|
---|
38 | )
|
---|
39 | {
|
---|
40 | VOID *BaseOfStack;
|
---|
41 | VOID *TopOfStack;
|
---|
42 | UINTN PageTables;
|
---|
43 | VOID *GhcbBase;
|
---|
44 | UINTN GhcbSize;
|
---|
45 |
|
---|
46 | // Initialize floating point operating environment to be compliant with UEFI spec.
|
---|
47 | InitializeFloatingPointUnits ();
|
---|
48 |
|
---|
49 | //
|
---|
50 | // Mask off all legacy 8259 interrupt sources
|
---|
51 | //
|
---|
52 | IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF);
|
---|
53 | IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF);
|
---|
54 |
|
---|
55 | //
|
---|
56 | // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.
|
---|
57 | //
|
---|
58 | if (IsNullDetectionEnabled ()) {
|
---|
59 | ClearFirst4KPage (HobList.Raw);
|
---|
60 | BuildMemoryAllocationHob (0, EFI_PAGES_TO_SIZE (1), EfiBootServicesData);
|
---|
61 | }
|
---|
62 |
|
---|
63 | //
|
---|
64 | // Allocate 128KB for the Stack
|
---|
65 | //
|
---|
66 | BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
|
---|
67 | ASSERT (BaseOfStack != NULL);
|
---|
68 |
|
---|
69 | //
|
---|
70 | // Compute the top of the stack we were allocated. Pre-allocate a UINTN
|
---|
71 | // for safety.
|
---|
72 | //
|
---|
73 | TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
|
---|
74 | TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
---|
75 |
|
---|
76 | //
|
---|
77 | // Get the address and size of the GHCB pages
|
---|
78 | //
|
---|
79 | GhcbBase = 0;
|
---|
80 | GhcbSize = 0;
|
---|
81 |
|
---|
82 | PageTables = 0;
|
---|
83 | if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {
|
---|
84 | //
|
---|
85 | // Create page table and save PageMapLevel4 to CR3
|
---|
86 | //
|
---|
87 | PageTables = CreateIdentityMappingPageTables (
|
---|
88 | (EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack,
|
---|
89 | STACK_SIZE,
|
---|
90 | (EFI_PHYSICAL_ADDRESS)(UINTN)GhcbBase,
|
---|
91 | GhcbSize
|
---|
92 | );
|
---|
93 | } else {
|
---|
94 | //
|
---|
95 | // Set NX for stack feature also require PcdDxeIplBuildPageTables be TRUE
|
---|
96 | // for the DxeIpl and the DxeCore are both X64.
|
---|
97 | //
|
---|
98 | ASSERT (PcdGetBool (PcdSetNxForStack) == FALSE);
|
---|
99 | ASSERT (PcdGetBool (PcdCpuStackGuard) == FALSE);
|
---|
100 | }
|
---|
101 |
|
---|
102 | if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {
|
---|
103 | AsmWriteCr3 (PageTables);
|
---|
104 | }
|
---|
105 |
|
---|
106 | //
|
---|
107 | // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
|
---|
108 | //
|
---|
109 | UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
|
---|
110 |
|
---|
111 | //
|
---|
112 | // Transfer the control to the entry point of DxeCore.
|
---|
113 | //
|
---|
114 | SwitchStack (
|
---|
115 | (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
|
---|
116 | HobList.Raw,
|
---|
117 | NULL,
|
---|
118 | TopOfStack
|
---|
119 | );
|
---|
120 | }
|
---|