]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiSalLib/UefiSalLib.c
e41cc0d980cb2458b12d11aece7b0eb9f87f695c
[mirror_edk2.git] / MdePkg / Library / UefiSalLib / UefiSalLib.c
1 /** @file
2 SAL Library implementation built upon UEFI.
3
4 Copyright (c) 2007 - 2008, Intel Corporation All rights
5 reserved. This program and the accompanying materials are
6 licensed and made available under the terms and conditions of
7 the BSD License which accompanies this distribution. The full
8 text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <PiDxe.h>
17 #include <IndustryStandard/Sal.h>
18
19 #include <Library/SalLib.h>
20 #include <Library/UefiLib.h>
21 #include <Library/DebugLib.h>
22
23 #include <Guid/SalSystemTable.h>
24
25 EFI_PLABEL mPlabel;
26 SAL_PROC mSalProcEntry;
27
28 /**
29 Makes a SAL procedure call.
30
31 This is a wrapper function to make a SAL procedure call.
32 No parameter checking is performed on the 8 input parameters,
33 but there are some common rules that the caller should follow
34 when making a SAL call. Any address passed to SAL as buffers
35 for return parameters must be 8-byte aligned. Unaligned
36 addresses may cause undefined results. For those parameters
37 defined as reserved or some fields defined as reserved must be
38 zero filled or the invalid argument return value may be returned
39 or undefined result may occur during the execution of the procedure.
40 This function is only available on IPF.
41
42 @param Index The SAL procedure Index number
43 @param Arg2 The 2nd parameter for SAL procedure calls
44 @param Arg3 The 3rd parameter for SAL procedure calls
45 @param Arg4 The 4th parameter for SAL procedure calls
46 @param Arg5 The 5th parameter for SAL procedure calls
47 @param Arg6 The 6th parameter for SAL procedure calls
48 @param Arg7 The 7th parameter for SAL procedure calls
49 @param Arg8 The 8th parameter for SAL procedure calls
50
51 @return SAL returned registers.
52
53 **/
54 SAL_RETURN_REGS
55 EFIAPI
56 SalCall (
57 IN UINT64 Index,
58 IN UINT64 Arg2,
59 IN UINT64 Arg3,
60 IN UINT64 Arg4,
61 IN UINT64 Arg5,
62 IN UINT64 Arg6,
63 IN UINT64 Arg7,
64 IN UINT64 Arg8
65 )
66 {
67 //
68 // mSalProcEntry is initialized in library constructor as SAL entry.
69 //
70 return mSalProcEntry(
71 Index,
72 Arg2,
73 Arg3,
74 Arg4,
75 Arg5,
76 Arg6,
77 Arg7,
78 Arg8
79 );
80
81 }
82
83 /**
84 The constructor function of UEFI SAL Lib.
85
86 The constructor function looks up the SAL System Table in the EFI System Configuration
87 Table. Once the SAL System Table is found, the SAL Entry Point in the SAL System Table
88 will be derived and stored inot a global variable for library usage.
89 It will ASSERT() if the SAL System Table cannot be found or the data in the SAL System
90 Table is not the valid data.
91
92 @param ImageHandle The firmware allocated handle for the EFI image.
93 @param SystemTable A pointer to the EFI System Table.
94
95 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
96
97 **/
98 EFI_STATUS
99 EFIAPI
100 UefiSalLibConstructor (
101 IN EFI_HANDLE ImageHandle,
102 IN EFI_SYSTEM_TABLE *SystemTable
103 )
104 {
105 EFI_STATUS Status;
106 SAL_ST_ENTRY_POINT_DESCRIPTOR *SalStEntryDes;
107 SAL_SYSTEM_TABLE_HEADER *SalSystemTable;
108
109 Status = EfiGetSystemConfigurationTable (
110 &gEfiSalSystemTableGuid,
111 (VOID **) &SalSystemTable
112 );
113
114 ASSERT_EFI_ERROR (Status);
115
116 //
117 // Move the SAL System Table point to the first Entry
118 // Due to the SAL Entry is in ascending order with the Entry type,
119 // the type 0 Entry should be the first if exist.
120 //
121 SalStEntryDes = (SAL_ST_ENTRY_POINT_DESCRIPTOR *)(SalSystemTable + 1);
122
123 //
124 // Assure the SAL ENTRY Type is 0
125 //
126 ASSERT (SalStEntryDes->Type == EFI_SAL_ST_ENTRY_POINT);
127
128 mPlabel.EntryPoint = SalStEntryDes->SalProcEntry;
129 mPlabel.GP = SalStEntryDes->SalGlobalDataPointer;
130 //
131 // Make sure the EntryPoint has the real value
132 //
133 ASSERT ((mPlabel.EntryPoint != 0) && (mPlabel.GP != 0));
134
135 mSalProcEntry = (SAL_PROC)((UINT64)&(mPlabel.EntryPoint));
136
137 return EFI_SUCCESS;
138 }