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
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.
18 Ia32-specifc functionality for DxeLoad.
23 // Include common header file for this module.
25 #include "CommonHeader.h"
28 #include "VirtualMemory.h"
31 // Global Descriptor Table (GDT)
33 GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT gGdtEntries
[] = {
34 /* selector { Global Segment Descriptor } */
35 /* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor
36 /* 0x08 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor
37 /* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor
38 /* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor
39 /* 0x20 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor
40 /* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor
41 /* 0x30 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor
42 /* 0x38 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor
43 /* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor
49 GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt
= {
50 sizeof (gGdtEntries
) - 1,
56 IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint
,
57 IN EFI_PEI_HOB_POINTERS HobList
,
58 IN EFI_PEI_PPI_DESCRIPTOR
*EndOfPeiSignal
62 EFI_PHYSICAL_ADDRESS BaseOfStack
;
63 EFI_PHYSICAL_ADDRESS TopOfStack
;
66 Status
= PeiServicesAllocatePages (EfiBootServicesData
, EFI_SIZE_TO_PAGES (STACK_SIZE
), &BaseOfStack
);
67 ASSERT_EFI_ERROR (Status
);
69 if (FeaturePcdGet(PcdDxeIplSwitchToLongMode
)) {
71 // Compute the top of the stack we were allocated, which is used to load X64 dxe core.
72 // Pre-allocate a 32 bytes which confroms to x64 calling convention.
74 // The first four parameters to a function are passed in rcx, rdx, r8 and r9.
75 // Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the
76 // register parameters is reserved on the stack, in case the called function
77 // wants to spill them; this is important if the function is variadic.
79 TopOfStack
= BaseOfStack
+ EFI_SIZE_TO_PAGES (STACK_SIZE
) * EFI_PAGE_SIZE
- 32;
82 // X64 Calling Conventions requires that the stack must be aligned to 16 bytes
84 TopOfStack
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ALIGN_POINTER (TopOfStack
, 16);
87 // Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA
88 // memory, it may be corrupted when copying FV to high-end memory
92 // Create page table and save PageMapLevel4 to CR3
94 PageTables
= CreateIdentityMappingPageTables ();
97 // End of PEI phase singal
99 Status
= PeiServicesInstallPpi (EndOfPeiSignal
);
100 ASSERT_EFI_ERROR (Status
);
102 AsmWriteCr3 (PageTables
);
104 // Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.
105 // Call x64 drivers passing in single argument, a pointer to the HOBs.
110 (EFI_PHYSICAL_ADDRESS
)(UINTN
)(HobList
.Raw
),
116 // Compute the top of the stack we were allocated. Pre-allocate a UINTN
119 TopOfStack
= BaseOfStack
+ EFI_SIZE_TO_PAGES (STACK_SIZE
) * EFI_PAGE_SIZE
- CPU_STACK_ALIGNMENT
;
120 TopOfStack
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) ALIGN_POINTER (TopOfStack
, CPU_STACK_ALIGNMENT
);
123 // End of PEI phase singal
125 Status
= PeiServicesInstallPpi (EndOfPeiSignal
);
126 ASSERT_EFI_ERROR (Status
);
129 (SWITCH_STACK_ENTRY_POINT
)(UINTN
)DxeCoreEntryPoint
,
132 (VOID
*) (UINTN
) TopOfStack