]>
Commit | Line | Data |
---|---|---|
bf231ea6 | 1 | /** @file\r |
030cd1a2 | 2 | PEI Services Table Pointer Library for IA-32 and x64.\r |
bf231ea6 | 3 | \r |
ce02b0b9 | 4 | According to PI specification, the peiservice pointer is stored prior at IDT\r |
5 | table in IA32 and x64 architecture.\r | |
bf231ea6 | 6 | \r |
9095d37b | 7 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 8 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
bf231ea6 A |
9 | \r |
10 | **/\r | |
c7d265a9 | 11 | \r |
5dd39dc6 | 12 | #include <PiPei.h>\r |
13 | \r | |
14 | #include <Library/BaseLib.h>\r | |
15 | #include <Library/PeiServicesTablePointerLib.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
fcfd5fb0 | 17 | #include <Library/BaseMemoryLib.h>\r |
c7d265a9 | 18 | \r |
19 | /**\r | |
4b8157f9 | 20 | Retrieves the cached value of the PEI Services Table pointer.\r |
f38fdc74 | 21 | \r |
9095d37b LG |
22 | Returns the cached value of the PEI Services Table pointer in a CPU specific manner\r |
23 | as specified in the CPU binding section of the Platform Initialization Pre-EFI\r | |
4b8157f9 | 24 | Initialization Core Interface Specification.\r |
9095d37b | 25 | \r |
4b8157f9 | 26 | If the cached PEI Services Table pointer is NULL, then ASSERT().\r |
f38fdc74 | 27 | \r |
4b8157f9 | 28 | @return The pointer to PeiServices.\r |
c7d265a9 | 29 | \r |
30 | **/\r | |
5240b97c | 31 | CONST EFI_PEI_SERVICES **\r |
c7d265a9 | 32 | EFIAPI\r |
33 | GetPeiServicesTablePointer (\r | |
34 | VOID\r | |
35 | )\r | |
36 | {\r | |
5240b97c | 37 | CONST EFI_PEI_SERVICES **PeiServices;\r |
81c7803c | 38 | IA32_DESCRIPTOR Idtr;\r |
9095d37b | 39 | \r |
81c7803c | 40 | AsmReadIdtr (&Idtr);\r |
5240b97c | 41 | PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));\r |
c7d265a9 | 42 | ASSERT (PeiServices != NULL);\r |
43 | return PeiServices;\r | |
44 | }\r | |
45 | \r | |
81c7803c | 46 | /**\r |
9095d37b LG |
47 | Caches a pointer PEI Services Table.\r |
48 | \r | |
49 | Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer\r | |
50 | in a CPU specific manner as specified in the CPU binding section of the Platform Initialization\r | |
51 | Pre-EFI Initialization Core Interface Specification.\r | |
f38fdc74 | 52 | The function set the pointer of PEI services immediately preceding the IDT table\r |
53 | according to PI specification.\r | |
9095d37b | 54 | \r |
4b8157f9 | 55 | If PeiServicesTablePointer is NULL, then ASSERT().\r |
9095d37b | 56 | \r |
f38fdc74 | 57 | @param PeiServicesTablePointer The address of PeiServices pointer.\r |
81c7803c | 58 | **/\r |
59 | VOID\r | |
60 | EFIAPI\r | |
61 | SetPeiServicesTablePointer (\r | |
a86fda43 | 62 | IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer\r |
81c7803c | 63 | )\r |
64 | {\r | |
fcfd5fb0 | 65 | IA32_DESCRIPTOR Idtr;\r |
9095d37b | 66 | \r |
4b8157f9 | 67 | ASSERT (PeiServicesTablePointer != NULL);\r |
81c7803c | 68 | AsmReadIdtr (&Idtr);\r |
ffdb421c LG |
69 | (*(UINTN*)(Idtr.Base - sizeof (UINTN))) = (UINTN)PeiServicesTablePointer;\r |
70 | }\r | |
71 | \r | |
72 | /**\r | |
9095d37b | 73 | Perform CPU specific actions required to migrate the PEI Services Table\r |
ffdb421c LG |
74 | pointer from temporary RAM to permanent RAM.\r |
75 | \r | |
9095d37b | 76 | For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes\r |
ffdb421c | 77 | immediately preceding the Interrupt Descriptor Table (IDT) in memory.\r |
9095d37b | 78 | For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes\r |
ffdb421c LG |
79 | immediately preceding the Interrupt Descriptor Table (IDT) in memory.\r |
80 | For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in\r | |
9095d37b LG |
81 | a dedicated CPU register. This means that there is no memory storage\r |
82 | associated with storing the PEI Services Table pointer, so no additional\r | |
ffdb421c LG |
83 | migration actions are required for Itanium or ARM CPUs.\r |
84 | \r | |
85 | If The cached PEI Services Table pointer is NULL, then ASSERT().\r | |
86 | If the permanent memory is allocated failed, then ASSERT().\r | |
87 | **/\r | |
88 | VOID\r | |
89 | EFIAPI\r | |
90 | MigratePeiServicesTablePointer (\r | |
8a835340 | 91 | VOID\r |
ffdb421c LG |
92 | )\r |
93 | {\r | |
94 | EFI_STATUS Status;\r | |
95 | IA32_DESCRIPTOR Idtr;\r | |
96 | EFI_PHYSICAL_ADDRESS IdtBase;\r | |
97 | CONST EFI_PEI_SERVICES **PeiServices;\r | |
98 | \r | |
99 | //\r | |
100 | // Get PEI Services Table pointer\r | |
101 | //\r | |
102 | AsmReadIdtr (&Idtr);\r | |
103 | PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));\r | |
104 | ASSERT (PeiServices != NULL);\r | |
105 | //\r | |
106 | // Allocate the permanent memory.\r | |
107 | //\r | |
108 | Status = (*PeiServices)->AllocatePages (\r | |
9095d37b | 109 | PeiServices,\r |
ffdb421c LG |
110 | EfiBootServicesCode,\r |
111 | EFI_SIZE_TO_PAGES(Idtr.Limit + 1 + sizeof (UINTN)),\r | |
112 | &IdtBase\r | |
113 | );\r | |
114 | ASSERT_EFI_ERROR (Status);\r | |
115 | //\r | |
116 | // Idt table needs to be migrated into memory.\r | |
117 | //\r | |
118 | CopyMem ((VOID *) (UINTN) IdtBase, (VOID *) (Idtr.Base - sizeof (UINTN)), Idtr.Limit + 1 + sizeof (UINTN));\r | |
119 | Idtr.Base = (UINTN) IdtBase + sizeof (UINTN);\r | |
120 | AsmWriteIdtr (&Idtr);\r | |
9095d37b | 121 | \r |
ffdb421c | 122 | return;\r |
81c7803c | 123 | }\r |
124 | \r | |
81c7803c | 125 | \r |