2006-04-22 00:54:32 +02:00
|
|
|
/*++
|
|
|
|
|
2006-08-21 04:53:29 +02:00
|
|
|
Copyright (c) 2006, Intel Corporation
|
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2006-04-22 00:54:32 +02:00
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
DxeLoadFunc.c
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
Ia32-specifc functionality for DxeLoad.
|
|
|
|
|
|
|
|
--*/
|
|
|
|
|
2006-11-27 11:14:02 +01:00
|
|
|
#include "DxeIpl.h"
|
2006-11-29 02:49:26 +01:00
|
|
|
#include "VirtualMemory.h"
|
|
|
|
|
2006-12-22 04:13:56 +01:00
|
|
|
//
|
2006-11-29 02:49:26 +01:00
|
|
|
// Global Descriptor Table (GDT)
|
|
|
|
//
|
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT gGdtEntries [] = {
|
|
|
|
/* selector { Global Segment Descriptor } */
|
2006-11-30 20:03:58 +01:00
|
|
|
/* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor
|
|
|
|
/* 0x08 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor
|
|
|
|
/* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor
|
|
|
|
/* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor
|
|
|
|
/* 0x20 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor
|
|
|
|
/* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor
|
|
|
|
/* 0x30 */ {{0xffff, 0, 0, 0x2, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor
|
|
|
|
/* 0x38 */ {{0xffff, 0, 0, 0xa, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor
|
|
|
|
/* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor
|
2006-11-29 02:49:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// IA32 Gdt register
|
|
|
|
//
|
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt = {
|
|
|
|
sizeof (gGdtEntries) - 1,
|
|
|
|
(UINTN) gGdtEntries
|
|
|
|
};
|
2006-04-22 00:54:32 +02:00
|
|
|
|
2006-08-21 04:53:29 +02:00
|
|
|
VOID
|
2006-11-28 08:59:59 +01:00
|
|
|
HandOffToDxeCore (
|
|
|
|
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
|
2006-12-22 04:13:56 +01:00
|
|
|
IN EFI_PEI_HOB_POINTERS HobList,
|
|
|
|
IN EFI_PEI_PPI_DESCRIPTOR *EndOfPeiSignal
|
2006-08-21 04:53:29 +02:00
|
|
|
)
|
|
|
|
{
|
2006-11-28 08:59:59 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PHYSICAL_ADDRESS BaseOfStack;
|
|
|
|
EFI_PHYSICAL_ADDRESS TopOfStack;
|
2006-11-29 02:49:26 +01:00
|
|
|
UINTN PageTables;
|
2006-11-28 08:59:59 +01:00
|
|
|
|
|
|
|
Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
if (FeaturePcdGet(PcdDxeIplSwitchToLongMode)) {
|
|
|
|
//
|
|
|
|
// Compute the top of the stack we were allocated, which is used to load X64 dxe core.
|
|
|
|
// Pre-allocate a 32 bytes which confroms to x64 calling convention.
|
|
|
|
//
|
|
|
|
// The first four parameters to a function are passed in rcx, rdx, r8 and r9.
|
|
|
|
// Any further parameters are pushed on the stack. Furthermore, space (4 * 8bytes) for the
|
|
|
|
// register parameters is reserved on the stack, in case the called function
|
|
|
|
// wants to spill them; this is important if the function is variadic.
|
|
|
|
//
|
|
|
|
TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - 32;
|
|
|
|
|
|
|
|
//
|
|
|
|
// X64 Calling Conventions requires that the stack must be aligned to 16 bytes
|
|
|
|
//
|
|
|
|
TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, 16);
|
2006-11-29 02:49:26 +01:00
|
|
|
|
2006-11-28 08:59:59 +01:00
|
|
|
//
|
|
|
|
// Load the GDT of Go64. Since the GDT of 32-bit Tiano locates in the BS_DATA
|
|
|
|
// memory, it may be corrupted when copying FV to high-end memory
|
|
|
|
//
|
2006-11-29 02:49:26 +01:00
|
|
|
AsmWriteGdtr (&gGdt);
|
2006-11-28 08:59:59 +01:00
|
|
|
//
|
2006-11-29 02:49:26 +01:00
|
|
|
// Create page table and save PageMapLevel4 to CR3
|
2006-11-28 08:59:59 +01:00
|
|
|
//
|
2006-11-29 02:49:26 +01:00
|
|
|
PageTables = CreateIdentityMappingPageTables ();
|
2006-12-22 04:13:56 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// End of PEI phase singal
|
|
|
|
//
|
|
|
|
Status = PeiServicesInstallPpi (EndOfPeiSignal);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2006-11-29 02:49:26 +01:00
|
|
|
AsmWriteCr3 (PageTables);
|
|
|
|
//
|
2006-11-28 08:59:59 +01:00
|
|
|
// Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.
|
|
|
|
// Call x64 drivers passing in single argument, a pointer to the HOBs.
|
2006-11-29 02:49:26 +01:00
|
|
|
//
|
|
|
|
AsmEnablePaging64 (
|
|
|
|
SYS_CODE64_SEL,
|
|
|
|
DxeCoreEntryPoint,
|
|
|
|
(EFI_PHYSICAL_ADDRESS)(UINTN)(HobList.Raw),
|
|
|
|
0,
|
|
|
|
TopOfStack
|
2006-11-28 08:59:59 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Compute the top of the stack we were allocated. Pre-allocate a UINTN
|
|
|
|
// for safety.
|
|
|
|
//
|
|
|
|
TopOfStack = BaseOfStack + EFI_SIZE_TO_PAGES (STACK_SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT;
|
|
|
|
TopOfStack = (EFI_PHYSICAL_ADDRESS) (UINTN) ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
|
|
|
|
|
2006-12-22 04:13:56 +01:00
|
|
|
//
|
|
|
|
// End of PEI phase singal
|
|
|
|
//
|
|
|
|
Status = PeiServicesInstallPpi (EndOfPeiSignal);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
2006-11-28 08:59:59 +01:00
|
|
|
SwitchStack (
|
|
|
|
(SWITCH_STACK_ENTRY_POINT)(UINTN)DxeCoreEntryPoint,
|
|
|
|
HobList.Raw,
|
|
|
|
NULL,
|
|
|
|
(VOID *) (UINTN) TopOfStack
|
|
|
|
);
|
|
|
|
}
|
2006-08-21 04:53:29 +02:00
|
|
|
}
|
2006-11-29 02:49:26 +01:00
|
|
|
|