]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Pei/PeiLib/Ia32/PeiServicePointer.c
updated to use the term “temporary memory” but not CAR
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Pei / PeiLib / Ia32 / PeiServicePointer.c
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2004 - 2007, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 PeiServicePointer.c\r
15\r
16Abstract:\r
17\r
18--*/\r
19\r
20#include "Tiano.h"\r
21#include "PeiApi.h"\r
22#include "PeiLib.h"\r
23\r
24#if (PI_SPECIFICATION_VERSION >= 0x00010000)\r
25\r
26#ifdef EFI_NT_EMULATOR\r
27EFI_PEI_SERVICES **gPeiServices;\r
28#endif\r
29\r
30\r
31VOID\r
32SetPeiServicesTablePointer (\r
33 IN EFI_PEI_SERVICES **PeiServices\r
34 )\r
35/*++\r
36\r
37Routine Description:\r
38\r
39 Save PeiService pointer so that it can be retrieved anywhere.\r
40\r
41Arguments:\r
42\r
43 PeiServices - The direct pointer to PeiServiceTable.\r
44 PhyscialAddress - The physcial address of variable PeiServices.\r
45 \r
46Returns:\r
47 NONE\r
48 \r
49--*/ \r
50{\r
51\r
52#ifdef EFI_NT_EMULATOR\r
53\r
54 //\r
55 // For NT32, set EFI_PEI_SERVICES** to global variable.\r
56 //\r
57 gPeiServices = PeiServices;\r
58#else\r
59\r
60 //\r
61 // For X86 processor,the EFI_PEI_SERVICES** is stored in the \r
62 // 4 bytes immediately preceding the Interrupt Descriptor Table.\r
63 //\r
64 UINTN IdtBaseAddress;\r
65 IdtBaseAddress = (UINTN)ReadIdtBase();\r
66 *(UINTN*)(IdtBaseAddress - 4) = (UINTN)PeiServices;\r
67\r
68#endif \r
69}\r
70\r
71\r
72EFI_PEI_SERVICES **\r
73GetPeiServicesTablePointer ( \r
74 VOID\r
75 )\r
76/*++\r
77\r
78Routine Description:\r
79\r
80 Get PeiService pointer.\r
81\r
82Arguments:\r
83\r
84 NONE.\r
85 \r
86Returns:\r
87 The direct pointer to PeiServiceTable.\r
88 \r
89--*/ \r
90{\r
91 EFI_PEI_SERVICES **PeiServices;\r
92\r
93#ifdef EFI_NT_EMULATOR\r
94\r
95 //\r
96 // For NT32, set EFI_PEI_SERVICES** to global variable.\r
97 //\r
98 PeiServices = gPeiServices;\r
99#else\r
100\r
101 //\r
102 // For X86 processor,the EFI_PEI_SERVICES** is stored in the \r
103 // 4 bytes immediately preceding the Interrupt Descriptor Table.\r
104 //\r
105 UINTN IdtBaseAddress;\r
106 IdtBaseAddress = (UINTN)ReadIdtBase();\r
107 PeiServices = (EFI_PEI_SERVICES **)(UINTN)(*(UINTN*)(IdtBaseAddress - 4));\r
108#endif\r
109 return PeiServices;\r
110}\r
111\r
112\r
113VOID\r
114MigrateIdtTable (\r
115 IN EFI_PEI_SERVICES **PeiServices\r
116 )\r
117/*++\r
118\r
119Routine Description:\r
120\r
121 Migrate IDT from CAR to real memory where preceded with 4 bytes for\r
122 storing PeiService pointer.\r
123\r
124Arguments:\r
125\r
126 PeiServices - The direct pointer to PeiServiceTable.\r
127 \r
128Returns:\r
129\r
130 NONE.\r
131 \r
132--*/ \r
133{\r
134#ifndef EFI_NT_EMULATOR\r
135 UINT16 IdtEntrySize;\r
136 UINTN OldIdtBase;\r
137 UINTN Size;\r
138 VOID *NewIdtBase;\r
139 EFI_STATUS Status;\r
140 \r
141 IdtEntrySize = ReadIdtLimit();\r
142 OldIdtBase = ReadIdtBase();\r
143 Size = sizeof(PEI_IDT_TABLE) + (IdtEntrySize + 1); \r
144 Status = (*PeiServices)->AllocatePool (PeiServices, Size, &NewIdtBase);\r
145 ASSERT_PEI_ERROR (PeiServices, Status);\r
146 (*PeiServices)->CopyMem ((VOID*)((UINTN)NewIdtBase + sizeof(PEI_IDT_TABLE)), (VOID*)OldIdtBase, (IdtEntrySize + 1));\r
147 SetIdtBase(((UINTN)NewIdtBase + sizeof(PEI_IDT_TABLE)), IdtEntrySize);\r
148 SetPeiServicesTablePointer(PeiServices);\r
149#endif\r
150}\r
151\r
152#endif\r