]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
Create X64 mode page tables in memory even when PEI is already X64
[mirror_edk2.git] / MdeModulePkg / Core / DxeIplPeim / X64 / DxeLoadFunc.c
1 /** @file
2 x64-specifc functionality for DxeLoad.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "DxeIpl.h"
16 #include "X64/VirtualMemory.h"
17
18
19
20 /**
21 Transfers control to DxeCore.
22
23 This function performs a CPU architecture specific operations to execute
24 the entry point of DxeCore with the parameters of HobList.
25 It also intalls EFI_END_OF_PEI_PPI to signal the end of PEI phase.
26
27 @param DxeCoreEntryPoint The entrypoint of DxeCore.
28 @param HobList The start of HobList passed to DxeCore.
29
30 **/
31 VOID
32 HandOffToDxeCore (
33 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
34 IN EFI_PEI_HOB_POINTERS HobList
35 )
36 {
37 VOID *BaseOfStack;
38 VOID *TopOfStack;
39 EFI_STATUS Status;
40 UINTN PageTables;
41
42 //
43 // Allocate 128KB for the Stack
44 //
45 BaseOfStack = AllocatePages (EFI_SIZE_TO_PAGES (STACK_SIZE));
46 ASSERT (BaseOfStack != NULL);
47
48 //
49 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
50 // for safety.
51 //
52 TopOfStack = (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT);
53 TopOfStack = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
54
55 //
56 // Create page table and save PageMapLevel4 to CR3
57 //
58 PageTables = CreateIdentityMappingPageTables ();
59
60 //
61 // End of PEI phase singal
62 //
63 Status = PeiServicesInstallPpi (&gEndOfPeiSignalPpi);
64 ASSERT_EFI_ERROR (Status);
65
66 AsmWriteCr3 (PageTables);
67
68 //
69 // Update the contents of BSP stack HOB to reflect the real stack info passed to DxeCore.
70 //
71 UpdateStackHob ((EFI_PHYSICAL_ADDRESS)(UINTN) BaseOfStack, STACK_SIZE);
72
73 //
74 // Transfer the control to the entry point of DxeCore.
75 //
76 SwitchStack (
77 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
78 HobList.Raw,
79 NULL,
80 TopOfStack
81 );
82 }