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