]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c
42f4e1b637503b54eb5614e822f5eb1d6a480b68
[mirror_edk2.git] / MdePkg / Library / PeiServicesTablePointerLibIdt / PeiServicesTablePointer.c
1 /** @file
2 PEI Services Table Pointer Library for IA-32 and X64.
3
4 Copyright (c) 2006 - 2007, Intel Corporation.<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "InternalPeiServicesTablePointer.h"
16
17 /**
18
19 The function returns the pointer to PeiServicee following
20 PI1.0.
21
22 For IA32, the four-bytes field immediately prior to new IDT
23 base addres is used to save the EFI_PEI_SERVICES**.
24 For x64, the eight-bytes field immediately prior to new IDT
25 base addres is used to save the EFI_PEI_SERVICES**
26 @retval The pointer to PeiServices.
27
28 **/
29 EFI_PEI_SERVICES **
30 EFIAPI
31 GetPeiServicesTablePointer (
32 VOID
33 )
34 {
35 EFI_PEI_SERVICES **PeiServices;
36 IA32_DESCRIPTOR Idtr;
37
38 AsmReadIdtr (&Idtr);
39 PeiServices = (EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - 4));
40 ASSERT (PeiServices != NULL);
41 return PeiServices;
42 }
43
44 /**
45
46 The function returns the pointer to PeiServicee following
47 PI1.0.
48
49 For IA32, the four-bytes field immediately prior to new IDT
50 base addres is used to save the EFI_PEI_SERVICES**.
51 For x64, the eight-bytes field immediately prior to new IDT
52 base addres is used to save the EFI_PEI_SERVICES**
53 @retval The pointer to PeiServices.
54
55 **/
56 VOID
57 EFIAPI
58 SetPeiServicesTablePointer (
59 EFI_PEI_SERVICES ** PeiServicesTablePointer
60 )
61 {
62 IA32_DESCRIPTOR Idtr;
63
64 AsmReadIdtr (&Idtr);
65 (*(UINTN*)(Idtr.Base - 4)) = (UINTN)PeiServicesTablePointer;
66 }
67
68 /**
69 After memory initialization in PEI phase, the IDT table in temporary memory should
70 be migrated to memory, and the address of PeiServicesPointer also need to be updated
71 immediately preceding the new IDT table.
72
73 @param PeiServices The address of PeiServices pointer.
74 **/
75 VOID
76 EFIAPI
77 MigrateIdtTable (
78 IN EFI_PEI_SERVICES **PeiServices
79 )
80 {
81 UINTN Size;
82 VOID *NewBase;
83 EFI_STATUS Status;
84 IA32_DESCRIPTOR Idtr;
85
86 AsmReadIdtr (&Idtr);
87
88 Size = sizeof(UINTN) + (Idtr.Limit + 1);
89
90 Status = PeiServicesAllocatePool (Size, &NewBase);
91 ASSERT_EFI_ERROR (Status);
92
93 CopyMem ((VOID*)((UINTN)NewBase + sizeof(UINTN)), (VOID*)Idtr.Base, (Idtr.Limit + 1));
94
95 Idtr.Base = (UINTN)NewBase + sizeof(UINTN);
96 AsmWriteIdtr (&Idtr);
97 SetPeiServicesTablePointer(PeiServices);
98 }
99