TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeLoadFuncFit.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
14#include <Library/PcdLib.h>
15#include <Library/HobLib.h>
16#include <Library/FdtLib.h>
17#include <Library/PcdLib.h>
18#include "X64/VirtualMemory.h"
19#include "UefiPayloadEntry.h"
20#define STACK_SIZE 0x20000
21
22extern VOID *mHobList;
23
35VOID
37 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
39 )
40{
41 VOID *BaseOfStack;
42 VOID *TopOfStack;
43 UINTN PageTables;
44 VOID *GhcbBase;
45 UINTN GhcbSize;
46
47 // Initialize floating point operating environment to be compliant with UEFI spec.
49
50 //
51 // Mask off all legacy 8259 interrupt sources
52 //
53 IoWrite8 (LEGACY_8259_MASK_REGISTER_MASTER, 0xFF);
54 IoWrite8 (LEGACY_8259_MASK_REGISTER_SLAVE, 0xFF);
55
56 //
57 // Clear page 0 and mark it as allocated if NULL pointer detection is enabled.
58 //
60 ClearFirst4KPage (HobList.Raw);
62 }
63
64 //
65 // Allocate 128KB for the Stack
66 //
67 BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
68 ASSERT (BaseOfStack != NULL);
69
70 //
71 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
72 // for safety.
73 //
74 TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
75 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
76
77 //
78 // Get the address and size of the GHCB pages
79 //
80 GhcbBase = 0;
81 GhcbSize = 0;
82
83 PageTables = 0;
84 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {
85 //
86 // Create page table and save PageMapLevel4 to CR3
87 //
89 (EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack,
90 STACK_SIZE,
91 (EFI_PHYSICAL_ADDRESS)(UINTN)GhcbBase,
92 GhcbSize
93 );
94 } else {
95 //
96 // Set NX for stack feature also require PcdDxeIplBuildPageTables be TRUE
97 // for the DxeIpl and the DxeCore are both X64.
98 //
99 ASSERT (PcdGetBool (PcdSetNxForStack) == FALSE);
100 ASSERT (PcdGetBool (PcdCpuStackGuard) == FALSE);
101 }
102
103 if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {
104 AsmWriteCr3 (PageTables);
105 }
106
107 //
108 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
109 //
110 UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
111
112 //
113 // Transfer the control to the entry point of DxeCore.
114 //
116 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
117 HobList.Raw,
118 NULL,
119 TopOfStack
120 );
121}
122
129EFIAPI
131 IN UINTN BootloaderParameter
132 )
133{
134 return FitUplEntryPoint (BootloaderParameter);
135}
UINT64 UINTN
#define CPU_STACK_ALIGNMENT
VOID EFIAPI BuildMemoryAllocationHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN EFI_MEMORY_TYPE MemoryType)
Definition: HobLib.c:601
VOID EFIAPI SwitchStack(IN SWITCH_STACK_ENTRY_POINT EntryPoint, IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL, IN VOID *NewStack,...)
Definition: SwitchStack.c:42
VOID(EFIAPI * SWITCH_STACK_ENTRY_POINT)(IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL)
Definition: BaseLib.h:5019
EFI_STATUS EFIAPI FitUplEntryPoint(IN UINTN BootloaderParameter)
VOID HandOffToDxeCore(IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, IN EFI_PEI_HOB_POINTERS HobList)
EFI_STATUS EFIAPI _ModuleEntryPoint(IN UINTN BootloaderParameter)
UINTN EFIAPI AsmWriteCr3(UINTN Cr3)
UINT8 EFIAPI IoWrite8(IN UINTN Port, IN UINT8 Value)
Definition: IoLibArmVirt.c:200
VOID ClearFirst4KPage(IN VOID *HobStart)
Definition: VirtualMemory.c:44
UINTN CreateIdentityMappingPageTables(IN EFI_PHYSICAL_ADDRESS StackBase, IN UINTN StackSize, IN EFI_PHYSICAL_ADDRESS GhcbBase, IN UINTN GhcbSize)
BOOLEAN IsNullDetectionEnabled(VOID)
#define NULL
Definition: Base.h:319
#define ALIGN_POINTER(Pointer, Alignment)
Definition: Base.h:963
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
VOID *EFIAPI AllocatePages(IN UINTN Pages)
VOID UpdateStackHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
Definition: Hob.c:731
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
#define EFI_PAGES_TO_SIZE(Pages)
Definition: UefiBaseType.h:213
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
@ EfiBootServicesData
VOID EFIAPI InitializeFloatingPointUnits(VOID)