]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c
Code Scrub the common includes in MdePkg.
[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
27 @return The pointer to PeiServices.
28
29 **/
30 EFI_PEI_SERVICES **
31 EFIAPI
32 GetPeiServicesTablePointer (
33 VOID
34 )
35 {
36 EFI_PEI_SERVICES **PeiServices;
37 IA32_DESCRIPTOR Idtr;
38
39 AsmReadIdtr (&Idtr);
40 PeiServices = (EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - 4));
41 ASSERT (PeiServices != NULL);
42 return PeiServices;
43 }
44
45 /**
46
47 The function sets the pointer to PeiServicee following
48 PI1.0.
49
50 For IA32, the four-bytes field immediately prior to new IDT
51 base addres is used to save the EFI_PEI_SERVICES**.
52 For x64, the eight-bytes field immediately prior to new IDT
53 base addres is used to save the EFI_PEI_SERVICES**
54
55 @param PeiServicesTablePointer The pointer to PeiServices.
56
57 **/
58 VOID
59 EFIAPI
60 SetPeiServicesTablePointer (
61 EFI_PEI_SERVICES ** PeiServicesTablePointer
62 )
63 {
64 IA32_DESCRIPTOR Idtr;
65
66 AsmReadIdtr (&Idtr);
67 (*(UINTN*)(Idtr.Base - 4)) = (UINTN)PeiServicesTablePointer;
68 }
69
70 /**
71 After memory initialization in PEI phase, the IDT table in temporary memory should
72 be migrated to memory, and the address of PeiServicesPointer also need to be updated
73 immediately preceding the new IDT table.
74
75 @param PeiServices The address of PeiServices pointer.
76 **/
77 VOID
78 EFIAPI
79 MigrateIdtTable (
80 IN EFI_PEI_SERVICES **PeiServices
81 )
82 {
83 UINTN Size;
84 VOID *NewBase;
85 EFI_STATUS Status;
86 IA32_DESCRIPTOR Idtr;
87
88 AsmReadIdtr (&Idtr);
89
90 Size = sizeof(UINTN) + (Idtr.Limit + 1);
91
92 Status = PeiServicesAllocatePool (Size, &NewBase);
93 ASSERT_EFI_ERROR (Status);
94
95 CopyMem ((VOID*)((UINTN)NewBase + sizeof(UINTN)), (VOID*)Idtr.Base, (Idtr.Limit + 1));
96
97 Idtr.Base = (UINTN)NewBase + sizeof(UINTN);
98 AsmWriteIdtr (&Idtr);
99 SetPeiServicesTablePointer(PeiServices);
100 }
101