]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/Library/PeiCoreServicesTablePointerLib/PeiServicesTablePointer.c
Add InOsEmuPkg. Like UnixPkg and Nt32Pkg, but EFI code can be common and does not...
[mirror_edk2.git] / InOsEmuPkg / Library / PeiCoreServicesTablePointerLib / PeiServicesTablePointer.c
1 /** @file
2 PEI Services Table Pointer Library for PEI Core.
3
4 This library is used for PEI Core which does executed from flash device directly but
5 executed in memory. When the PEI Core does a Set of the PEI Service table pointer
6 a PPI is reinstalled so that PEIMs can update the copy of the PEI Services table
7 they have cached.
8
9 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
10 Portiions copyrigth (c) 2011, Apple Inc. All rights reserved.
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php.
15
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18
19 **/
20
21 #include <PiPei.h>
22 #include <Library/PeiServicesTablePointerLib.h>
23 #include <Library/DebugLib.h>
24
25 #include <Ppi/EmuPeiServicesTableUpdate.h>
26
27
28 CONST EFI_PEI_SERVICES **gPeiServices = NULL;
29
30 /**
31 Caches a pointer PEI Services Table.
32
33 Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
34 in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
35 Pre-EFI Initialization Core Interface Specification.
36
37 If PeiServicesTablePointer is NULL, then ASSERT().
38
39 @param PeiServicesTablePointer The address of PeiServices pointer.
40 **/
41 VOID
42 EFIAPI
43 SetPeiServicesTablePointer (
44 IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer
45 )
46 {
47 EFI_STATUS Status;
48 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
49 VOID *NotUsed;
50
51 gPeiServices = PeiServicesTablePointer;
52
53 Status = (*PeiServicesTablePointer)->LocatePpi (
54 PeiServicesTablePointer,
55 &gEmuPeiServicesTableUpdatePpiGuid, // GUID
56 0, // INSTANCE
57 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
58 &NotUsed // PPI
59 );
60 if (!EFI_ERROR (Status)) {
61 //
62 // Standard PI Mechanism is to use negative offset from IDT.
63 // We can't do that in the emulator, so we make up a constant location
64 // that every one can use. The first try may fail as the PEI Core is still
65 // initializing its self, but that is OK.
66 //
67
68 // Reinstall PPI to consumers know to update PEI Services pointer
69 Status = (*PeiServicesTablePointer)->ReInstallPpi (
70 PeiServicesTablePointer,
71 PpiDescriptor,
72 PpiDescriptor
73 );
74
75 }
76
77 }
78
79 /**
80 Retrieves the cached value of the PEI Services Table pointer.
81
82 Returns the cached value of the PEI Services Table pointer in a CPU specific manner
83 as specified in the CPU binding section of the Platform Initialization Pre-EFI
84 Initialization Core Interface Specification.
85
86 If the cached PEI Services Table pointer is NULL, then ASSERT().
87
88 @return The pointer to PeiServices.
89
90 **/
91 CONST EFI_PEI_SERVICES **
92 EFIAPI
93 GetPeiServicesTablePointer (
94 VOID
95 )
96 {
97 ASSERT (gPeiServices != NULL);
98 ASSERT (*gPeiServices != NULL);
99 return gPeiServices;
100 }
101
102