]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesTablePointerLibMm7/PeiServicesTablePointer.c
46fe3083b96d3a2163c57cbf5282e32b79cc8a85
[mirror_edk2.git] / MdePkg / Library / PeiServicesTablePointerLibMm7 / PeiServicesTablePointer.c
1 /** @file
2 PEI Services Table Pointer Library.
3
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 Module Name: PeiServicesTablePointer.c
14
15 **/
16
17
18 #include <PiPei.h>
19
20
21 #include <Library/PeiServicesTablePointerLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/PeiServicesLib.h>
26
27 VOID
28 EFIAPI
29 SetPeiServicesTablePointer (
30 IN EFI_PEI_SERVICES **PeiServices
31 )
32 {
33 AsmWriteMm7 ((UINT64)(UINTN)PeiServices);
34 }
35
36 /**
37 The function returns the pointer to PeiServices.
38
39 The function returns the pointer to PeiServices.
40 It will ASSERT() if the pointer to PeiServices is NULL.
41
42 @retval The pointer to PeiServices.
43
44 **/
45 EFI_PEI_SERVICES **
46 EFIAPI
47 GetPeiServicesTablePointer (
48 VOID
49 )
50 {
51 EFI_PEI_SERVICES **PeiServices;
52
53 PeiServices = (EFI_PEI_SERVICES **)(UINTN)AsmReadMm7 ();
54 ASSERT (PeiServices != NULL);
55 return PeiServices;
56 }
57
58 /**
59 The constructor function caches the pointer to PEI services.
60
61 The constructor function caches the pointer to PEI services.
62 It will always return EFI_SUCCESS.
63
64 @param FfsHeader Pointer to FFS header the loaded driver.
65 @param PeiServices Pointer to the PEI services.
66
67 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 PeiServicesTablePointerLibConstructor (
73 IN EFI_PEI_FILE_HANDLE *FfsHeader,
74 IN EFI_PEI_SERVICES **PeiServices
75 )
76 {
77 AsmWriteMm7 ((UINT64)(UINTN)PeiServices);
78 return EFI_SUCCESS;
79 }
80
81 /**
82 After memory initialization in PEI phase, the IDT table in temporary memory should
83 be migrated to memory, and the address of PeiServicesPointer also need to be updated
84 immediately preceding the new IDT table.
85
86 @param PeiServices The address of PeiServices pointer.
87 **/
88 VOID
89 MigrateIdtTable (
90 IN EFI_PEI_SERVICES **PeiServices
91 )
92 {
93 UINTN Size;
94 VOID *NewBase;
95 EFI_STATUS Status;
96 IA32_DESCRIPTOR Idtr;
97
98 AsmReadIdtr (&Idtr);
99
100 Size = Idtr.Limit + 1;
101
102 Status = PeiServicesAllocatePool (Size, &NewBase);
103 ASSERT_EFI_ERROR (Status);
104
105 CopyMem (NewBase, (VOID*)Idtr.Base, Size);
106
107 Idtr.Base = (UINTN)NewBase;
108 AsmWriteIdtr (&Idtr);
109 }
110