]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c
[Description]
[mirror_edk2.git] / MdePkg / Library / PeiServicesTablePointerLibIdt / PeiServicesTablePointer.c
CommitLineData
bf231ea6
A
1/** @file\r
2 PEI Services Table Pointer Library for IA-32 and X64.\r
3\r
4 Copyright (c) 2006 - 2007, 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**/\r
c7d265a9 14\r
15#include "InternalPeiServicesTablePointer.h"\r
16\r
17/**\r
18 \r
19 The function returns the pointer to PeiServicee following\r
20 PI1.0.\r
21 \r
22 For IA32, the four-bytes field immediately prior to new IDT\r
23 base addres is used to save the EFI_PEI_SERVICES**.\r
24 For x64, the eight-bytes field immediately prior to new IDT\r
bf231ea6 25 base addres is used to save the EFI_PEI_SERVICES**\r
c7d265a9 26 @retval The pointer to PeiServices.\r
27\r
28**/\r
29EFI_PEI_SERVICES **\r
30EFIAPI\r
31GetPeiServicesTablePointer (\r
32 VOID\r
33 )\r
34{\r
35 EFI_PEI_SERVICES **PeiServices;\r
81c7803c 36 IA32_DESCRIPTOR Idtr;\r
37 \r
38 AsmReadIdtr (&Idtr);\r
39 PeiServices = (EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - 4));\r
c7d265a9 40 ASSERT (PeiServices != NULL);\r
41 return PeiServices;\r
42}\r
43\r
81c7803c 44/**\r
45 \r
46 The function returns the pointer to PeiServicee following\r
47 PI1.0.\r
48 \r
49 For IA32, the four-bytes field immediately prior to new IDT\r
50 base addres is used to save the EFI_PEI_SERVICES**.\r
51 For x64, the eight-bytes field immediately prior to new IDT\r
52 base addres is used to save the EFI_PEI_SERVICES**\r
53 @retval The pointer to PeiServices.\r
54\r
55**/\r
56VOID\r
57EFIAPI\r
58SetPeiServicesTablePointer (\r
59 EFI_PEI_SERVICES ** PeiServicesTablePointer\r
60 )\r
61{\r
62 IA32_DESCRIPTOR Idtr;\r
63 \r
64 AsmReadIdtr (&Idtr);\r
65 (*(UINTN*)(Idtr.Base - 4)) = (UINTN)PeiServicesTablePointer;\r
66}\r
67\r
68/**\r
69 After memory initialization in PEI phase, the IDT table in temporary memory should \r
70 be migrated to memory, and the address of PeiServicesPointer also need to be updated \r
71 immediately preceding the new IDT table.\r
72 \r
73 @param PeiServices The address of PeiServices pointer.\r
74**/\r
75VOID\r
c311f86b 76EFIAPI\r
81c7803c 77MigrateIdtTable (\r
78 IN EFI_PEI_SERVICES **PeiServices\r
79 )\r
80{\r
81 UINTN Size;\r
82 VOID *NewBase;\r
83 EFI_STATUS Status;\r
84 IA32_DESCRIPTOR Idtr;\r
85 \r
86 AsmReadIdtr (&Idtr);\r
87 \r
88 Size = sizeof(UINTN) + (Idtr.Limit + 1); \r
89 \r
90 Status = PeiServicesAllocatePool (Size, &NewBase);\r
91 ASSERT_EFI_ERROR (Status);\r
92 \r
93 CopyMem ((VOID*)((UINTN)NewBase + sizeof(UINTN)), (VOID*)Idtr.Base, (Idtr.Limit + 1));\r
94 \r
95 Idtr.Base = (UINTN)NewBase + sizeof(UINTN);\r
96 AsmWriteIdtr (&Idtr);\r
97 SetPeiServicesTablePointer(PeiServices); \r
98} \r
99\r