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