X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FPeiServicesTablePointerLibIdt%2FPeiServicesTablePointer.c;h=dac31c9985346dd634d131cffabe029ff8b57e15;hp=97abaa4aeb5889d7b2731a80a2db6cd2566d39b7;hb=9344f0921518309295da89c221d10cbead8531aa;hpb=373b5cf97cc650d2e81d4909ff5327b6ce0b6c26 diff --git a/MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c b/MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c index 97abaa4aeb..dac31c9985 100644 --- a/MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c +++ b/MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c @@ -1,101 +1,125 @@ /** @file - PEI Services Table Pointer Library for IA-32 and X64. + PEI Services Table Pointer Library for IA-32 and x64. - Copyright (c) 2006 - 2007, 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 + According to PI specification, the peiservice pointer is stored prior at IDT + table in IA32 and x64 architecture. - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent **/ -#include "InternalPeiServicesTablePointer.h" +#include + +#include +#include +#include +#include /** - - The function returns the pointer to PeiServicee following - PI1.0. - - For IA32, the four-bytes field immediately prior to new IDT - base addres is used to save the EFI_PEI_SERVICES**. - For x64, the eight-bytes field immediately prior to new IDT - base addres is used to save the EFI_PEI_SERVICES** - + Retrieves the cached value of the PEI Services Table pointer. + + 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 + Initialization Core Interface Specification. + + If the cached PEI Services Table pointer is NULL, then ASSERT(). + @return The pointer to PeiServices. **/ -EFI_PEI_SERVICES ** +CONST EFI_PEI_SERVICES ** EFIAPI GetPeiServicesTablePointer ( VOID ) { - EFI_PEI_SERVICES **PeiServices; + CONST EFI_PEI_SERVICES **PeiServices; IA32_DESCRIPTOR Idtr; - + AsmReadIdtr (&Idtr); - PeiServices = (EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - 4)); + PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN))); ASSERT (PeiServices != NULL); return PeiServices; } /** - - The function sets the pointer to PeiServicee following - PI1.0. - - For IA32, the four-bytes field immediately prior to new IDT - base addres is used to save the EFI_PEI_SERVICES**. - For x64, the eight-bytes field immediately prior to new IDT - base addres is used to save the EFI_PEI_SERVICES** - - @param PeiServicesTablePointer The pointer to PeiServices. + 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. + The function set the pointer of PEI services immediately preceding the IDT table + according to PI specification. + + If PeiServicesTablePointer is NULL, then ASSERT(). + + @param PeiServicesTablePointer The address of PeiServices pointer. **/ VOID EFIAPI SetPeiServicesTablePointer ( - EFI_PEI_SERVICES ** PeiServicesTablePointer + IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer ) { - IA32_DESCRIPTOR Idtr; - + IA32_DESCRIPTOR Idtr; + + ASSERT (PeiServicesTablePointer != NULL); AsmReadIdtr (&Idtr); - (*(UINTN*)(Idtr.Base - 4)) = (UINTN)PeiServicesTablePointer; + (*(UINTN*)(Idtr.Base - sizeof (UINTN))) = (UINTN)PeiServicesTablePointer; } /** - After memory initialization in PEI phase, the IDT table in temporary memory should - be migrated to memory, and the address of PeiServicesPointer also need to be updated - immediately preceding the new IDT table. - - @param PeiServices The address of PeiServices pointer. + Perform CPU specific actions required to migrate the PEI Services Table + pointer from temporary RAM to permanent RAM. + + For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes + immediately preceding the Interrupt Descriptor Table (IDT) in memory. + For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes + immediately preceding the Interrupt Descriptor Table (IDT) in memory. + For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in + a dedicated CPU register. This means that there is no memory storage + associated with storing the PEI Services Table pointer, so no additional + 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 -MigrateIdtTable ( - IN EFI_PEI_SERVICES **PeiServices +MigratePeiServicesTablePointer ( + VOID ) { - UINTN Size; - VOID *NewBase; - EFI_STATUS Status; - IA32_DESCRIPTOR Idtr; - + EFI_STATUS Status; + IA32_DESCRIPTOR Idtr; + EFI_PHYSICAL_ADDRESS IdtBase; + CONST EFI_PEI_SERVICES **PeiServices; + + // + // Get PEI Services Table pointer + // AsmReadIdtr (&Idtr); - - Size = sizeof(UINTN) + (Idtr.Limit + 1); - - Status = PeiServicesAllocatePool (Size, &NewBase); + PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN))); + ASSERT (PeiServices != NULL); + // + // Allocate the permanent memory. + // + Status = (*PeiServices)->AllocatePages ( + PeiServices, + EfiBootServicesCode, + EFI_SIZE_TO_PAGES(Idtr.Limit + 1 + sizeof (UINTN)), + &IdtBase + ); ASSERT_EFI_ERROR (Status); - - CopyMem ((VOID*)((UINTN)NewBase + sizeof(UINTN)), (VOID*)Idtr.Base, (Idtr.Limit + 1)); - - Idtr.Base = (UINTN)NewBase + sizeof(UINTN); + // + // 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); - SetPeiServicesTablePointer(PeiServices); -} + + return; +} +