]>
Commit | Line | Data |
---|---|---|
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 | |
29 | EFI_PEI_SERVICES **\r | |
30 | EFIAPI\r | |
31 | GetPeiServicesTablePointer (\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 | |
56 | VOID\r | |
57 | EFIAPI\r | |
58 | SetPeiServicesTablePointer (\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 | |
75 | VOID\r | |
76 | MigrateIdtTable (\r | |
77 | IN EFI_PEI_SERVICES **PeiServices\r | |
78 | )\r | |
79 | {\r | |
80 | UINTN Size;\r | |
81 | VOID *NewBase;\r | |
82 | EFI_STATUS Status;\r | |
83 | IA32_DESCRIPTOR Idtr;\r | |
84 | \r | |
85 | AsmReadIdtr (&Idtr);\r | |
86 | \r | |
87 | Size = sizeof(UINTN) + (Idtr.Limit + 1); \r | |
88 | \r | |
89 | Status = PeiServicesAllocatePool (Size, &NewBase);\r | |
90 | ASSERT_EFI_ERROR (Status);\r | |
91 | \r | |
92 | CopyMem ((VOID*)((UINTN)NewBase + sizeof(UINTN)), (VOID*)Idtr.Base, (Idtr.Limit + 1));\r | |
93 | \r | |
94 | Idtr.Base = (UINTN)NewBase + sizeof(UINTN);\r | |
95 | AsmWriteIdtr (&Idtr);\r | |
96 | SetPeiServicesTablePointer(PeiServices); \r | |
97 | } \r | |
98 | \r |