2007-07-13 05:21:40 +02:00
|
|
|
/** @file
|
2008-12-05 04:23:13 +01:00
|
|
|
PEI Services Table Pointer Library for IA-32 and x64.
|
2007-07-13 05:21:40 +02:00
|
|
|
|
2008-09-03 10:35:20 +02:00
|
|
|
According to PI specification, the peiservice pointer is stored prior at IDT
|
|
|
|
table in IA32 and x64 architecture.
|
2007-07-13 05:21:40 +02:00
|
|
|
|
2018-06-27 15:11:33 +02:00
|
|
|
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
|
|
|
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.
|
2007-07-13 05:21:40 +02:00
|
|
|
|
|
|
|
**/
|
2007-06-22 18:22:26 +02:00
|
|
|
|
2008-09-03 10:04:48 +02:00
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/PeiServicesTablePointerLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
2013-11-15 03:04:57 +01:00
|
|
|
#include <Library/BaseMemoryLib.h>
|
2007-06-22 18:22:26 +02:00
|
|
|
|
|
|
|
/**
|
2008-12-11 07:29:24 +01:00
|
|
|
Retrieves the cached value of the PEI Services Table pointer.
|
2008-12-10 04:10:07 +01:00
|
|
|
|
2018-06-27 15:11:33 +02:00
|
|
|
Returns the cached value of the PEI Services Table pointer in a CPU specific manner
|
|
|
|
as specified in the CPU binding section of the Platform Initialization Pre-EFI
|
2008-12-11 07:29:24 +01:00
|
|
|
Initialization Core Interface Specification.
|
2018-06-27 15:11:33 +02:00
|
|
|
|
2008-12-11 07:29:24 +01:00
|
|
|
If the cached PEI Services Table pointer is NULL, then ASSERT().
|
2008-12-10 04:10:07 +01:00
|
|
|
|
2008-12-11 07:29:24 +01:00
|
|
|
@return The pointer to PeiServices.
|
2007-06-22 18:22:26 +02:00
|
|
|
|
|
|
|
**/
|
2008-10-17 10:41:06 +02:00
|
|
|
CONST EFI_PEI_SERVICES **
|
2007-06-22 18:22:26 +02:00
|
|
|
EFIAPI
|
|
|
|
GetPeiServicesTablePointer (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2008-10-17 10:41:06 +02:00
|
|
|
CONST EFI_PEI_SERVICES **PeiServices;
|
2007-10-09 10:16:53 +02:00
|
|
|
IA32_DESCRIPTOR Idtr;
|
2018-06-27 15:11:33 +02:00
|
|
|
|
2007-10-09 10:16:53 +02:00
|
|
|
AsmReadIdtr (&Idtr);
|
2008-10-17 10:41:06 +02:00
|
|
|
PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));
|
2007-06-22 18:22:26 +02:00
|
|
|
ASSERT (PeiServices != NULL);
|
|
|
|
return PeiServices;
|
|
|
|
}
|
|
|
|
|
2007-10-09 10:16:53 +02:00
|
|
|
/**
|
2018-06-27 15:11:33 +02:00
|
|
|
Caches a pointer PEI Services Table.
|
|
|
|
|
|
|
|
Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
|
|
|
|
in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
|
|
|
|
Pre-EFI Initialization Core Interface Specification.
|
2008-12-10 04:10:07 +01:00
|
|
|
The function set the pointer of PEI services immediately preceding the IDT table
|
|
|
|
according to PI specification.
|
2018-06-27 15:11:33 +02:00
|
|
|
|
2008-12-11 07:29:24 +01:00
|
|
|
If PeiServicesTablePointer is NULL, then ASSERT().
|
2018-06-27 15:11:33 +02:00
|
|
|
|
2008-12-10 04:10:07 +01:00
|
|
|
@param PeiServicesTablePointer The address of PeiServices pointer.
|
2007-10-09 10:16:53 +02:00
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
SetPeiServicesTablePointer (
|
2008-10-21 07:52:19 +02:00
|
|
|
IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer
|
2007-10-09 10:16:53 +02:00
|
|
|
)
|
|
|
|
{
|
2013-11-15 03:04:57 +01:00
|
|
|
IA32_DESCRIPTOR Idtr;
|
2018-06-27 15:11:33 +02:00
|
|
|
|
2008-12-11 07:29:24 +01:00
|
|
|
ASSERT (PeiServicesTablePointer != NULL);
|
2007-10-09 10:16:53 +02:00
|
|
|
AsmReadIdtr (&Idtr);
|
2014-01-15 03:16:57 +01:00
|
|
|
(*(UINTN*)(Idtr.Base - sizeof (UINTN))) = (UINTN)PeiServicesTablePointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-06-27 15:11:33 +02:00
|
|
|
Perform CPU specific actions required to migrate the PEI Services Table
|
2014-01-15 03:16:57 +01:00
|
|
|
pointer from temporary RAM to permanent RAM.
|
|
|
|
|
2018-06-27 15:11:33 +02:00
|
|
|
For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes
|
2014-01-15 03:16:57 +01:00
|
|
|
immediately preceding the Interrupt Descriptor Table (IDT) in memory.
|
2018-06-27 15:11:33 +02:00
|
|
|
For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes
|
2014-01-15 03:16:57 +01:00
|
|
|
immediately preceding the Interrupt Descriptor Table (IDT) in memory.
|
|
|
|
For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in
|
2018-06-27 15:11:33 +02:00
|
|
|
a dedicated CPU register. This means that there is no memory storage
|
|
|
|
associated with storing the PEI Services Table pointer, so no additional
|
2014-01-15 03:16:57 +01:00
|
|
|
migration actions are required for Itanium or ARM CPUs.
|
|
|
|
|
|
|
|
If The cached PEI Services Table pointer is NULL, then ASSERT().
|
|
|
|
If the permanent memory is allocated failed, then ASSERT().
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
MigratePeiServicesTablePointer (
|
2014-01-17 07:06:30 +01:00
|
|
|
VOID
|
2014-01-15 03:16:57 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
IA32_DESCRIPTOR Idtr;
|
|
|
|
EFI_PHYSICAL_ADDRESS IdtBase;
|
|
|
|
CONST EFI_PEI_SERVICES **PeiServices;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get PEI Services Table pointer
|
|
|
|
//
|
|
|
|
AsmReadIdtr (&Idtr);
|
|
|
|
PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));
|
|
|
|
ASSERT (PeiServices != NULL);
|
|
|
|
//
|
|
|
|
// Allocate the permanent memory.
|
|
|
|
//
|
|
|
|
Status = (*PeiServices)->AllocatePages (
|
2018-06-27 15:11:33 +02:00
|
|
|
PeiServices,
|
2014-01-15 03:16:57 +01:00
|
|
|
EfiBootServicesCode,
|
|
|
|
EFI_SIZE_TO_PAGES(Idtr.Limit + 1 + sizeof (UINTN)),
|
|
|
|
&IdtBase
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
//
|
|
|
|
// Idt table needs to be migrated into memory.
|
|
|
|
//
|
|
|
|
CopyMem ((VOID *) (UINTN) IdtBase, (VOID *) (Idtr.Base - sizeof (UINTN)), Idtr.Limit + 1 + sizeof (UINTN));
|
|
|
|
Idtr.Base = (UINTN) IdtBase + sizeof (UINTN);
|
|
|
|
AsmWriteIdtr (&Idtr);
|
2018-06-27 15:11:33 +02:00
|
|
|
|
2014-01-15 03:16:57 +01:00
|
|
|
return;
|
2007-10-09 10:16:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|