]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | PEI Services Table Pointer Library for IA-32 and x64.\r | |
3 | \r | |
4 | According to PI specification, the peiservice pointer is stored prior at IDT\r | |
5 | table in IA32 and x64 architecture.\r | |
6 | \r | |
7 | Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r | |
8 | This program and the accompanying materials \r | |
9 | are licensed and made available under the terms and conditions of the BSD License \r | |
10 | which accompanies this distribution. The full text of the license may be found at \r | |
11 | http://opensource.org/licenses/bsd-license.php. \r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include <PiPei.h>\r | |
19 | \r | |
20 | #include <Library/BaseLib.h>\r | |
21 | #include <Library/PeiServicesTablePointerLib.h>\r | |
22 | #include <Library/DebugLib.h>\r | |
23 | #include <Library/BaseMemoryLib.h>\r | |
24 | #include <Ppi/TemporaryRamSupport.h>\r | |
25 | \r | |
26 | /**\r | |
27 | Retrieves the cached value of the PEI Services Table pointer.\r | |
28 | \r | |
29 | Returns the cached value of the PEI Services Table pointer in a CPU specific manner \r | |
30 | as specified in the CPU binding section of the Platform Initialization Pre-EFI \r | |
31 | Initialization Core Interface Specification.\r | |
32 | \r | |
33 | If the cached PEI Services Table pointer is NULL, then ASSERT().\r | |
34 | \r | |
35 | @return The pointer to PeiServices.\r | |
36 | \r | |
37 | **/\r | |
38 | CONST EFI_PEI_SERVICES **\r | |
39 | EFIAPI\r | |
40 | GetPeiServicesTablePointer (\r | |
41 | VOID\r | |
42 | )\r | |
43 | {\r | |
44 | CONST EFI_PEI_SERVICES **PeiServices;\r | |
45 | IA32_DESCRIPTOR Idtr;\r | |
46 | \r | |
47 | AsmReadIdtr (&Idtr);\r | |
48 | PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));\r | |
49 | ASSERT (PeiServices != NULL);\r | |
50 | return PeiServices;\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | Caches a pointer PEI Services Table. \r | |
55 | \r | |
56 | Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer \r | |
57 | in a CPU specific manner as specified in the CPU binding section of the Platform Initialization \r | |
58 | Pre-EFI Initialization Core Interface Specification. \r | |
59 | The function set the pointer of PEI services immediately preceding the IDT table\r | |
60 | according to PI specification.\r | |
61 | \r | |
62 | If PeiServicesTablePointer is NULL, then ASSERT().\r | |
63 | \r | |
64 | @param PeiServicesTablePointer The address of PeiServices pointer.\r | |
65 | **/\r | |
66 | VOID\r | |
67 | EFIAPI\r | |
68 | SetPeiServicesTablePointer (\r | |
69 | IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer\r | |
70 | )\r | |
71 | {\r | |
72 | IA32_DESCRIPTOR Idtr;\r | |
73 | EFI_PHYSICAL_ADDRESS IdtBase;\r | |
74 | EFI_STATUS Status;\r | |
75 | EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI *TemporaryRamSupportPpi;\r | |
76 | \r | |
77 | ASSERT (PeiServicesTablePointer != NULL);\r | |
78 | AsmReadIdtr (&Idtr);\r | |
79 | if ((*(UINTN*)(Idtr.Base - sizeof (UINTN))) != (UINTN)PeiServicesTablePointer) {\r | |
80 | (*(UINTN*)(Idtr.Base - sizeof (UINTN))) = (UINTN)PeiServicesTablePointer;\r | |
81 | Status = (*PeiServicesTablePointer)->LocatePpi (\r | |
82 | PeiServicesTablePointer, \r | |
83 | &gEfiTemporaryRamSupportPpiGuid, \r | |
84 | 0, \r | |
85 | NULL, \r | |
86 | (VOID**)&TemporaryRamSupportPpi\r | |
87 | );\r | |
88 | \r | |
89 | if (EFI_ERROR (Status)) {\r | |
90 | //\r | |
91 | // If TemporaryRamSupportPpi is not found, Idt table needs to be migrated into memory.\r | |
92 | //\r | |
93 | Status = (*PeiServicesTablePointer)->AllocatePages (\r | |
94 | PeiServicesTablePointer, \r | |
95 | EfiBootServicesCode,\r | |
96 | EFI_SIZE_TO_PAGES(Idtr.Limit + 1 + sizeof (UINTN)),\r | |
97 | &IdtBase\r | |
98 | );\r | |
99 | if (!EFI_ERROR (Status)) {\r | |
100 | //\r | |
101 | // Migrate Idt table\r | |
102 | //\r | |
103 | CopyMem ((VOID *) (UINTN) IdtBase, (VOID *) (Idtr.Base - sizeof (UINTN)), Idtr.Limit + 1 + sizeof (UINTN));\r | |
104 | Idtr.Base = (UINTN) IdtBase + sizeof (UINTN);\r | |
105 | AsmWriteIdtr (&Idtr);\r | |
106 | }\r | |
107 | }\r | |
108 | }\r | |
109 | }\r | |
110 | \r | |
111 | \r |