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