Newer
Older
AMI-Aptio-BIOS-Reversed / AmiModulePkg / AHCI / AhciSmm / AhciSmm.c
/** @file
  AhciSmm.c -- AhciSmm

  Recovered naming surface from local module notes:
  AhciSmm.md / README.md

  Copyright (c) HR650X BIOS Decompilation Project
**/

#include "AhciSmm.h"

//
// Global storage recovered from AhciSmm.md "State Management" section
//
EFI_HANDLE            gImageHandle = NULL;             // 0x2E80
EFI_SYSTEM_TABLE      *gST = NULL;                    // 0x2E70
EFI_BOOT_SERVICES     *gBS = NULL;                    // 0x2E78
EFI_RUNTIME_SERVICES  *gRT = NULL;                    // 0x2E88
EFI_SMM_SYSTEM_TABLE2 *gSmst = NULL;                  // 0x2E90
VOID                  *mPcd = NULL;                   // 0x2EA0
VOID                  *gSmmCpuIo2Protocol = NULL;      // 0x2EB0
UINT8                 mSmmMode = 0;                   // 0x2EB8
VOID                  *gSmmServicesTableBase2 = NULL;  // 0x2EE8
VOID                  *gSmmChildProtocol = NULL;       // 0x2EC0
VOID                  *gDxeProtocol = NULL;            // 0x2ED8
VOID                  *gSmiHandlerProtocol = NULL;     // 0x2ED0
VOID                  *gDxeSmiHandlerProtocol = NULL;  // 0x2EF0
UINT8                 gSmmProtocolReady = 0;          // 0x2EC8
VOID                  *gBuf = NULL;                    // 0x2E68
UINT64                gAhciSavedPxClb = 0;            // 0x3010
UINT64                gAhciSavedPxFb = 0;             // 0x3018
UINTN                 gAhciReturnStatus = 0;           // 0x3008
UINT8                 gPortCompletionInProgress = 0;   // 0x2E60
UINT8                 gSoftResetInProgress = 0;        // 0x2E61
UINT32                gSmiCallbackHandle = 0;          // 0x3020
VOID                  *gAhciCommandTable = NULL;       // 0x3028
VOID                  *gAhciReceiveArea = NULL;        // 0x3030
VOID                  *gAhciCommandList = NULL;        // 0x3038

//
// Dispatch handler slots recovered from AhciSmm.md
//
AHCI_SMM_HANDLER pAhciPortInitHandler = NULL;         // 0x3070
AHCI_SMM_HANDLER pAhciDmaCommandHandler = NULL;       // 0x3078
AHCI_SMM_HANDLER pAhciPioDataInHandler = NULL;        // 0x3080
AHCI_SMM_HANDLER pAhciSoftwareResetHandler = NULL;    // 0x3088 (AhciAtapiSoftwareResetHandler)
AHCI_SMM_HANDLER pAhciNonDataCommandHandler = NULL;   // 0x3090 (AhciAtaNonDataCommandHandler)
AHCI_SMM_HANDLER pAhciFisReceiveHandler = NULL;       // 0x3098 (AhciFisReceiveCompletionHandler)
AHCI_SMM_HANDLER pAhciSoftResetHandler = NULL;        // 0x30A0 (AhciPortSoftResetThunk)

EFI_STATUS
EFIAPI
AhciSmmPreInit(
  VOID
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS
EFIAPI
AhciSmmRegisterSmiHandlers(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  return EFI_SUCCESS;
}

//
// Function: _ModuleEntryPoint (0x470)
// UEFI/SMM driver entry point. Initializes globals then executes main
// SMM dispatch/registration flow.
//
EFI_STATUS
EFIAPI
_ModuleEntryPoint(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  AhciSmmPreInit();
  return AhciSmmRegisterSmiHandlers(ImageHandle, SystemTable);
}

//
// Compatibility entry point expected by existing module lists.
//
EFI_STATUS
EFIAPI
ModuleEntryPoint(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  return _ModuleEntryPoint(ImageHandle, SystemTable);
}