]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointer.c
1) Update file header.
[mirror_edk2.git] / MdePkg / Library / PeiServicesTablePointerLibIdt / PeiServicesTablePointer.c
1 /** @file
2 PEI Services Table Pointer Library for IA-32 and x64.
3
4 According to PI specification, the peiservice pointer is stored prior at IDT
5 table in IA32 and x64 architecture.
6
7 Copyright (c) 2006 - 2007, Intel Corporation.<BR>
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 #include <PiPei.h>
19
20 #include <Library/BaseLib.h>
21 #include <Library/PeiServicesTablePointerLib.h>
22 #include <Library/DebugLib.h>
23
24 /**
25 The function returns the pointer to PEI services.
26
27 The function returns the pointer to PEI services.
28 It will ASSERT() if the pointer to PEI services is NULL.
29
30 @retval The pointer to PeiServices.
31
32 **/
33 CONST EFI_PEI_SERVICES **
34 EFIAPI
35 GetPeiServicesTablePointer (
36 VOID
37 )
38 {
39 CONST EFI_PEI_SERVICES **PeiServices;
40 IA32_DESCRIPTOR Idtr;
41
42 AsmReadIdtr (&Idtr);
43 PeiServices = (CONST EFI_PEI_SERVICES **) (*(UINTN*)(Idtr.Base - sizeof (UINTN)));
44 ASSERT (PeiServices != NULL);
45 return PeiServices;
46 }
47
48 /**
49 The function set the pointer of PEI services immediately preceding the IDT table
50 according to PI specification.
51
52 @param PeiServicesTablePointer The address of PeiServices pointer.
53 **/
54 VOID
55 EFIAPI
56 SetPeiServicesTablePointer (
57 IN CONST EFI_PEI_SERVICES ** PeiServicesTablePointer
58 )
59 {
60 IA32_DESCRIPTOR Idtr;
61
62 AsmReadIdtr (&Idtr);
63 (*(UINTN*)(Idtr.Base - sizeof (UINTN))) = (UINTN)PeiServicesTablePointer;
64 }
65
66