TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeHandoff.c
Go to the documentation of this file.
1
10#include "DxeIpl.h"
11
12#include <Ppi/MemoryAttribute.h>
13
25VOID
27 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
29 )
30{
31 VOID *BaseOfStack;
32 VOID *TopOfStack;
33 EFI_STATUS Status;
35
36 //
37 // Allocate 128KB for the Stack
38 //
39 BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
40 ASSERT (BaseOfStack != NULL);
41
42 if (PcdGetBool (PcdSetNxForStack)) {
43 Status = PeiServicesLocatePpi (
44 &gEdkiiMemoryAttributePpiGuid,
45 0,
46 NULL,
47 (VOID **)&MemoryPpi
48 );
49 ASSERT_EFI_ERROR (Status);
50
51 Status = MemoryPpi->SetPermissions (
52 MemoryPpi,
53 (UINTN)BaseOfStack,
54 STACK_SIZE,
55 EFI_MEMORY_XP,
56 EFI_MEMORY_XP
57 );
58 ASSERT_EFI_ERROR (Status);
59 }
60
61 //
62 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
63 // for safety.
64 //
65 TopOfStack = (VOID *)((UINTN)BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
66 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
67
68 //
69 // End of PEI phase signal
70 //
71 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);
72 ASSERT_EFI_ERROR (Status);
73
74 //
75 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
76 //
77 UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN)BaseOfStack, STACK_SIZE);
78
79 //
80 // Transfer the control to the entry point of DxeCore.
81 //
83 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
84 HobList.Raw,
85 NULL,
86 TopOfStack
87 );
88}
UINT64 UINTN
#define CPU_STACK_ALIGNMENT
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
VOID HandOffToDxeCore(IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint, IN EFI_PEI_HOB_POINTERS HobList)
Definition: DxeHandoff.c:26
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define NULL
Definition: Base.h:319
#define ALIGN_POINTER(Pointer, Alignment)
Definition: Base.h:963
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
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
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200