3 Copyright (c) 2006, 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
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.
20 #include <Ipf/IpfDefines.h>
22 EXTENDED_SAL_BOOT_SERVICE_PROTOCOL
*mEsalBootService
= NULL
;
35 if (mEsalBootService
!= NULL
) {
40 // The protocol contains a function pointer, which is an indirect procedure call.
41 // An indirect procedure call goes through a plabel, and pointer to a function is
42 // a pointer to a plabel. To implement indirect procedure calls that can work in
43 // both physical and virtual mode, two plabels are required (one physical and one
44 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it
45 // away. We cache it in a module global, so we can register the vitrual version.
47 Status
= gBS
->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid
, NULL
, (VOID
**) &mEsalBootService
);
48 if (EFI_ERROR (Status
)) {
49 mEsalBootService
= NULL
;
53 Plabel
= (EFI_PLABEL
*) (UINTN
) mEsalBootService
->ExtendedSalProc
;
55 mPlabel
.EntryPoint
= Plabel
->EntryPoint
;
56 mPlabel
.GP
= Plabel
->GP
;
57 SetEsalPhysicalEntryPoint (mPlabel
.EntryPoint
, mPlabel
.GP
);
64 RegisterEsalFunction (
66 IN EFI_GUID
*ClassGuid
,
67 IN SAL_INTERNAL_EXTENDED_SAL_PROC Function
,
74 Register ESAL Class Function and it's asociated global.
75 This function is boot service only!
78 FunctionId - ID of function to register
79 ClassGuid - GUID of function class
80 Function - Function to register under ClassGuid/FunctionId pair
81 ModuleGlobal - Module global for Function.
84 EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.
88 DxeSalLibInitialize ();
89 return mEsalBootService
->AddExtendedSalProc (
101 IN EFI_GUID
*ClassGuid
,
102 IN VOID
*ModuleGlobal
,
109 Register ESAL Class and it's asociated global.
110 This function is boot service only!
113 ClassGuid - GUID of function class
114 ModuleGlobal - Module global for Function.
115 ... - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL
116 indicates the end of the list.
119 EFI_SUCCESS - All members of ClassGuid registered
125 SAL_INTERNAL_EXTENDED_SAL_PROC Function
;
127 EFI_HANDLE NewHandle
;
129 VA_START (Args
, ModuleGlobal
);
131 Status
= EFI_SUCCESS
;
132 while (!EFI_ERROR (Status
)) {
133 Function
= (SAL_INTERNAL_EXTENDED_SAL_PROC
) VA_ARG (Args
, SAL_INTERNAL_EXTENDED_SAL_PROC
);
134 if (Function
== NULL
) {
138 FunctionId
= VA_ARG (Args
, UINT64
);
140 Status
= RegisterEsalFunction (FunctionId
, ClassGuid
, Function
, ModuleGlobal
);
143 if (EFI_ERROR (Status
)) {
148 return gBS
->InstallProtocolInterface (
151 EFI_NATIVE_INTERFACE
,
159 IN EFI_GUID
*ClassGuid
,
160 IN UINT64 FunctionId
,
173 Call module that is not linked direclty to this module. This code is IP
174 relative and hides the binding issues of virtual or physical calling. The
175 function that gets dispatched has extra arguments that include the registered
176 module global and a boolean flag to indicate if the system is in virutal mode.
179 ClassGuid - GUID of function
180 FunctionId - Function in ClassGuid to call
181 Arg2 - Argument 2 ClassGuid/FunctionId defined
182 Arg3 - Argument 3 ClassGuid/FunctionId defined
183 Arg4 - Argument 4 ClassGuid/FunctionId defined
184 Arg5 - Argument 5 ClassGuid/FunctionId defined
185 Arg6 - Argument 6 ClassGuid/FunctionId defined
186 Arg7 - Argument 7 ClassGuid/FunctionId defined
187 Arg8 - Argument 8 ClassGuid/FunctionId defined
190 Status of ClassGuid/FuncitonId
194 SAL_RETURN_REGS ReturnReg
;
195 SAL_EXTENDED_SAL_PROC EsalProc
;
197 ReturnReg
= GetEsalEntryPoint ();
198 if (ReturnReg
.Status
!= EFI_SAL_SUCCESS
) {
203 // Look at the physical mode ESAL entry point to determine of the ESAL entry point has been initialized
205 if (*(UINT64
*)ReturnReg
.r9
== 0 && *(UINT64
*)(ReturnReg
.r9
+ 8) == 0) {
207 // Both the function ponter and the GP value are zero, so attempt to initialize the ESAL Entry Point
209 DxeSalLibInitialize ();
210 ReturnReg
= GetEsalEntryPoint ();
211 if (ReturnReg
.Status
!= EFI_SAL_SUCCESS
) {
214 if (*(UINT64
*)ReturnReg
.r9
== 0 && *(UINT64
*)(ReturnReg
.r9
+ 8) == 0) {
216 // The ESAL Entry Point could not be initialized
218 ReturnReg
.Status
= EFI_SAL_ERROR
;
223 if (ReturnReg
.r11
& PSR_IT_MASK
) {
225 // Virtual mode plabel to entry point
227 EsalProc
= (SAL_EXTENDED_SAL_PROC
) ReturnReg
.r10
;
230 // Physical mode plabel to entry point
232 EsalProc
= (SAL_EXTENDED_SAL_PROC
) ReturnReg
.r9
;