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