Newer
Older
AMI-Aptio-BIOS-Reversed / AmiModulePkg / CSM / Aint13 / Aint13.c
/** @file
  Aint13.c -- Aint13

  Auto-converted from IDA decompiler output.
  Functions: 1 (recovered API surface only; recovery/cleanup pass).

Copyright (c) HR650X BIOS Decompilation Project
**/

#include "Aint13.h"

typedef EFI_STATUS (EFIAPI *AINT13_INIT_FUNCTION)(VOID);

//
// Placeholder-address aliases preserved for recovery notes.
//
#define byte_2149 mAint13InitDone
#define n8_2148  mAint13DiskCount
#define qword_2140 mInt13VectorTableBase
#define qword_2150 mPciIoCached
#define dword_21C0 mPciMmrAddress
#define qword_21B8 mPciWindowBase
#define qword_21C8 mAtapiMbrReadBuffer
#define qword_21D0 mInt13WorkBuffer
#define unk_21E0 mAint13DriveIdMap
#define qword_2180 mDebugProtocol
#define qword_2188 mCachedHobList

// Recovered module-scope state used by the decompiled entry path.
STATIC EFI_HANDLE        mImageHandle;
STATIC EFI_SYSTEM_TABLE *mSystemTable         = NULL;
STATIC EFI_BOOT_SERVICES *mBootServices        = NULL;
STATIC EFI_RUNTIME_SERVICES *mRuntimeServices  = NULL;

STATIC BOOLEAN           mAint13InitDone     = FALSE;
STATIC UINT8             mAint13DiskCount    = 0;
STATIC UINT8             mAint13DriveIdMap[24] = { 0 }; // 8 entries x 3 bytes
STATIC AINT13_INIT_FUNCTION mAint13ProtocolThunk = Aint13ProtocolThunkEntry;
STATIC UINT64            mInt13VectorTableBase = 0;
STATIC VOID             *mPciIoCached        = NULL;
STATIC UINT32            mPciMmrAddress      = 0;
STATIC UINT64            mPciWindowBase      = 0;
STATIC VOID             *mAtapiMbrReadBuffer = NULL;
STATIC VOID             *mInt13WorkBuffer    = NULL;

STATIC VOID      *mCachedHobList            = NULL;

STATIC VOID *mDebugProtocol              = NULL;
STATIC VOID *mAint13ChipsetProtocol      = NULL;
STATIC VOID *mAint13AuxProtocol          = NULL;

// Module protocol GUID recovered from local docs.
STATIC EFI_GUID mAint13ProtocolGuid = {
  0x6780532, 0x7613, 0x4DD3, { 0x9E, 0xD7, 0x3D, 0x9B, 0xE3, 0xA7, 0xDA, 0x63 }
};

// Recovered helper signatures (reconstruction).
//
// Subsystem split note:
// - AInt13Csp.c hosts the chipset-specific INT13h register programming path.
// - This file contains entry-point wiring and shared INT13h scaffolding helpers.
EFI_STATUS EFIAPI
Aint13DebugAssert(
  IN CHAR8 *FileName,
  IN UINTN LineNumber,
  IN CHAR8 *Description
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13InitializeModuleState(
  VOID
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13HandlePciIo(
  IN VOID *PciIo
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13InstallDiskInfo(
  IN VOID *DiskInfo
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13ProtocolThunkEntry(
  VOID
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13ChipsetInt13RegisterThunk(
  VOID
  )
{
  return EFI_UNSUPPORTED;
}

EFI_STATUS EFIAPI
Aint13BuildDriveIdentity(
  IN UINT8 *DeviceId,
  IN UINT8 Channel,
  IN VOID  *AtaIdentify,
  IN UINTN AtaIdentifySize,
  IN BOOLEAN Atapi
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13ComputeDriveGeometryFromIdentify(
  IN UINT8 *IdentifyData,
  OUT VOID *GeometryOut
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13ComputeChsGeometryFromMbr(
  IN UINT8 *MbRBuffer,
  IN UINTN BufferSize,
  OUT VOID *ChsOut
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13ComputeGeometryFromLba(
  IN UINT64 LbaSectors,
  OUT VOID  *GeometryOut
  )
{
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13RefreshBbsTable(
  VOID
  )
{
  return EFI_SUCCESS;
}

VOID EFIAPI
Aint13DebugPrint(
  IN CHAR8 *Format,
  ...
  )
{
  (VOID)Format;
}

UINT32 EFIAPI
Aint13GetBbsBootPriority(
  VOID
  )
{
  return 0;
}

BOOLEAN EFIAPI
Aint13CompareGuid(
  IN CONST EFI_GUID *Left,
  IN CONST EFI_GUID *Right
  )
{
  if (Left == NULL || Right == NULL) {
    return FALSE;
  }

  return (Left->Data1 == Right->Data1) &&
         (Left->Data2 == Right->Data2) &&
         (Left->Data3 == Right->Data3) &&
         (Left->Data4[0] == Right->Data4[0]) &&
         (Left->Data4[1] == Right->Data4[1]) &&
         (Left->Data4[2] == Right->Data4[2]) &&
         (Left->Data4[3] == Right->Data4[3]) &&
         (Left->Data4[4] == Right->Data4[4]) &&
         (Left->Data4[5] == Right->Data4[5]) &&
         (Left->Data4[6] == Right->Data4[6]) &&
         (Left->Data4[7] == Right->Data4[7]);
}

UINT64 EFIAPI
Aint13ReadUnaligned64(
  IN VOID *Address
  )
{
  return *(UINT64 *)Address;
}

EFI_STATUS EFIAPI
Aint13TimerNotify(
  IN EFI_EVENT Event,
  IN VOID     *Context
  )
{
  (VOID)Event;
  (VOID)Context;
  return EFI_SUCCESS;
}

EFI_STATUS EFIAPI
Aint13EnumeratePciIoList(
  IN VOID *PciIoList
  )
{
  (VOID)PciIoList;
  return EFI_SUCCESS;
}

// Function: _ModuleEntryPoint
EFI_STATUS EFIAPI
_ModuleEntryPoint(
  EFI_HANDLE        ImageHandle,
  EFI_SYSTEM_TABLE *SystemTable
  )
{
  EFI_BOOT_SERVICES    *BootServices;
  EFI_RUNTIME_SERVICES *RuntimeServices;
  EFI_HANDLE           ImageHandle_1;
  EFI_STATUS           Status;

  mImageHandle = ImageHandle;
  if (!mImageHandle) {
    Aint13DebugAssert("e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c", 51, "gImageHandle != ((void *) 0)");
  }

  mSystemTable = SystemTable;
  if (!mSystemTable) {
    Aint13DebugAssert("e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c", 57, "gST != ((void *) 0)");
  }

  mBootServices = mSystemTable->BootServices;
  if (!mBootServices) {
    Aint13DebugAssert("e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c", 63, "gBS != ((void *) 0)");
  }

  mRuntimeServices = mSystemTable->RuntimeServices;
  if (!mRuntimeServices) {
    Aint13DebugAssert("e:\\hs\\MdePkg\\Library\\UefiRuntimeServicesTableLib\\UefiRuntimeServicesTableLib.c", 47, "gRT != ((void *) 0)");
  }

  Aint13InitializeModuleState();
  ImageHandle_1 = ImageHandle;

  BootServices   = mBootServices;
  RuntimeServices = mRuntimeServices;
  (VOID)BootServices;
  (VOID)RuntimeServices;
  mAint13ProtocolThunk = Aint13ProtocolThunkEntry;

  Status = ((EFI_STATUS (*)(EFI_HANDLE *, VOID *, UINT32, VOID *))
            mBootServices->InstallProtocolInterface)(
              &ImageHandle_1,
              &mAint13ProtocolGuid,
              0,
              (VOID *)mAint13ProtocolThunk);

  return Status;
}

// Legacy decompiler symbol kept as a compatibility alias in recovery trees.
EFI_STATUS EFIAPI
ModuleEntryPoint(
  EFI_HANDLE        ImageHandle,
  EFI_SYSTEM_TABLE *SystemTable
  )
{
  return _ModuleEntryPoint(ImageHandle, SystemTable);
}