2 PEI Services Table Pointer Library for IA-32 and x64.
4 According to PI specification, the peiservice pointer is stored prior at IDT
5 table in IA32 and x64 architecture.
7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Library/BaseLib.h>
15 #include <Library/PeiServicesTablePointerLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/BaseMemoryLib.h>
20 Retrieves the cached value of the PEI Services Table pointer.
22 Returns the cached value of the PEI Services Table pointer in a CPU specific manner
23 as specified in the CPU binding section of the Platform Initialization Pre-EFI
24 Initialization Core Interface Specification.
26 If the cached PEI Services Table pointer is NULL, then ASSERT().
28 @return The pointer to PeiServices.
31 CONST EFI_PEI_SERVICES
**
33 GetPeiServicesTablePointer (
37 CONST EFI_PEI_SERVICES
**PeiServices
;
41 PeiServices
= (CONST EFI_PEI_SERVICES
**)(*(UINTN
*)(Idtr
.Base
- sizeof (UINTN
)));
42 ASSERT (PeiServices
!= NULL
);
47 Caches a pointer PEI Services Table.
49 Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
50 in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
51 Pre-EFI Initialization Core Interface Specification.
52 The function set the pointer of PEI services immediately preceding the IDT table
53 according to PI specification.
55 If PeiServicesTablePointer is NULL, then ASSERT().
57 @param PeiServicesTablePointer The address of PeiServices pointer.
61 SetPeiServicesTablePointer (
62 IN CONST EFI_PEI_SERVICES
**PeiServicesTablePointer
67 ASSERT (PeiServicesTablePointer
!= NULL
);
69 (*(UINTN
*)(Idtr
.Base
- sizeof (UINTN
))) = (UINTN
)PeiServicesTablePointer
;
73 Perform CPU specific actions required to migrate the PEI Services Table
74 pointer from temporary RAM to permanent RAM.
76 For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes
77 immediately preceding the Interrupt Descriptor Table (IDT) in memory.
78 For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes
79 immediately preceding the Interrupt Descriptor Table (IDT) in memory.
80 For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in
81 a dedicated CPU register. This means that there is no memory storage
82 associated with storing the PEI Services Table pointer, so no additional
83 migration actions are required for Itanium or ARM CPUs.
85 If The cached PEI Services Table pointer is NULL, then ASSERT().
86 If the permanent memory is allocated failed, then ASSERT().
90 MigratePeiServicesTablePointer (
96 EFI_PHYSICAL_ADDRESS IdtBase
;
97 CONST EFI_PEI_SERVICES
**PeiServices
;
100 // Get PEI Services Table pointer
103 PeiServices
= (CONST EFI_PEI_SERVICES
**)(*(UINTN
*)(Idtr
.Base
- sizeof (UINTN
)));
104 ASSERT (PeiServices
!= NULL
);
106 // Allocate the permanent memory.
108 Status
= (*PeiServices
)->AllocatePages (
111 EFI_SIZE_TO_PAGES (Idtr
.Limit
+ 1 + sizeof (UINTN
)),
114 ASSERT_EFI_ERROR (Status
);
116 // Idt table needs to be migrated into memory.
118 CopyMem ((VOID
*)(UINTN
)IdtBase
, (VOID
*)(Idtr
.Base
- sizeof (UINTN
)), Idtr
.Limit
+ 1 + sizeof (UINTN
));
119 Idtr
.Base
= (UINTN
)IdtBase
+ sizeof (UINTN
);
120 AsmWriteIdtr (&Idtr
);