]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
• Set the default value of PcdDxeIplSwitchToLongMode to TRUE.
[mirror_edk2.git] / EdkModulePkg / Core / DxeIplPeim / Ia32 / DxeLoadFunc.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 DxeLoadFunc.c
15
16 Abstract:
17
18 Ia32-specifc functionality for DxeLoad.
19
20 --*/
21
22 #include "DxeIpl.h"
23
24 VOID
25 HandOffToDxeCore (
26 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
27 IN EFI_PEI_HOB_POINTERS HobList
28 )
29 {
30 EFI_STATUS Status;
31 EFI_PHYSICAL_ADDRESS BaseOfStack;
32 EFI_PHYSICAL_ADDRESS TopOfStack;
33 EFI_PHYSICAL_ADDRESS PageTables;
34
35 Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);
36 ASSERT_EFI_ERROR (Status);
37
38 if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {
39 //
40 // Compute the top of the stack we were allocated, which is used to load X64 dxe core.
41 // Pre-allocate a 32 bytes which confroms to x64 calling convention.
42 //
43 // The first four parameters to a function are passed in rcx, rdx, r8 and r9.
44 // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the
45 // register parameters is reserved on the stack, in case the called function
46 // wants to spill them; this is important if the function is variadic.
47 //
48 TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;
49
50 //
51 // X64 Calling Conventions requires that the stack must be aligned to 16 bytes
52 //
53 TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);
54 //
55 // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA
56 // memory, it may be corrupted when copying FV to high-end memory
57 //
58 LoadGo64Gdt();
59 //
60 // Limit to 36 bits of addressing for debug. Should get it from CPU
61 //
62 PageTables = CreateIdentityMappingPageTables (36);
63 //
64 // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.
65 // Call x64 drivers passing in single argument, a pointer to the HOBs.
66 //
67 ActivateLongMode (
68 PageTables,
69 (EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw),
70 TopOfStack,
71 0x00000000,
72 DxeCoreEntryPoint
73 );
74 } else {
75 //
76 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
77 // for safety.
78 //
79 TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;
80 TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
81
82 SwitchStack (
83 (SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
84 HobList.Raw,
85 NULL,
86 (VOID *) (UINTN) TopOfStack
87 );
88 }
89 }