Newer
Older
AMI-Aptio-BIOS-Reversed / SoftSkuStatus / SoftSkuStatus.c
@Ajax Dong Ajax Dong 2 days ago 24 KB Init
/**
 * SoftSkuStatus.c
 * Module: SoftSkuStatus.efi (Index 0100)
 * Description: Soft SKU Status DXE driver
 *
 * This driver detects Soft SKU (Software Socket/Processor Licensing)
 * compliance on multi-socket systems. It reads MSR-based capability
 * and license registers per socket, stores them into UEFI variables
 * ("SocketCapability", "SocketLicense"), and manages the
 * "ForceProvisioning" variable. It also optionally enables Memory
 * Tiering via a one-shot timer callback.
 *
 * Image: HR650X BIOS
 * MD5:   2519efca5e22904120ee8a4b00cf75b5
 * Arch:  X64
 * Base:  0x0, Size: 0x17c0
 */

#include "SoftSkuStatus.h"

/* ----------------------------------------------------------------
 * Global Variables
 * ---------------------------------------------------------------- */

/* Auto-generated global data section variables */
UINT64 qword_15C0;      /* CPU config entry count */
UINT64 qword_15C8;      /* CPU config protocol interface */
UINT64 qword_15F0;      /* Debug print protocol */
UINT64 qword_15F8;      /* PCD protocol */
UINT64 qword_1600;      /* DXE Services Table (gDS) */
UINT64 qword_1608;      /* MM PCI Base protocol (mPciUsra) */
UINT64 qword_1610;      /* HOB list (mHobList) */
UINT64 qword_1618;      /* PCD token for socket capability */
UINT64 qword_1628;      /* CPU config library config context buffer */
UINT64 qword_1638;      /* Socket capability bitmask */
UINT64 qword_1640;      /* Allocated socket data buffer base */
UINT8  byte_15B0;       /* Memory tiering enabled flag */
UINT16 word_1580;        /* SocketCapability variable name storage */
UINT16 word_15AA;        /* SocketLicense variable name storage */

/* ----------------------------------------------------------------
 * Module Entry Point
 * ---------------------------------------------------------------- */

/**
 * _ModuleEntryPoint (0x344)
 * UEFI module entry point.
 */
EFI_STATUS
EFIAPI
ModuleEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
{
  SoftSkuEntry(ImageHandle, SystemTable);
  return SoftSkuMain(0, 0);
}

/* ----------------------------------------------------------------
 * UefiBootServicesTableLib Initialization (sub_358)
 * ---------------------------------------------------------------- */

/**
 * SoftSkuEntry (0x358)
 *
 * Main initialization routine. Sets up:
 *   - Global ImageHandle / SystemTable / BootServices / RuntimeServices
 *   - DXE Services Table (gDS) via configuration table lookup
 *   - MM PCI Base protocol (mPciUsra)
 *   - HOB list (mHobList)
 *   - PCD protocol and socket capability/license token lookups
 */
__int64
SoftSkuEntry (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  )
{
  UINT64      Status;
  UINT64      DxeServicesStatus;
  EFI_STATUS  EfiStatus;
  __int64     PcdProtocolInstance;

  /* Stash globals for library consumers */
  gImageHandle = ImageHandle;
  if (!ImageHandle) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      51,
      (__int64)"gImageHandle != ((void *) 0)");
  }

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

  gBootServices = SystemTable->BootServices;
  if (!gBootServices) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      63,
      (__int64)"gBS != ((void *) 0)");
  }

  gRuntimeServices = SystemTable->RuntimeServices;
  if (!gRuntimeServices) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiRuntimeServicesTableLib\\UefiRuntimeServicesTableLib.c",
      47,
      (__int64)"gRT != ((void *) 0)");
  }

  /* Locate DXE Services Table (gDS) via configuration table GUID */
  Status = GetConfigurationTable((__int64)&gEfiDxeServicesTableGuid, &qword_1600);
  if (Status < 0) {
    DebugPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", Status);
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\DxeServicesTableLib\\DxeServicesTableLib.c",
      64,
      (__int64)"!EFI_ERROR (Status)");
  }
  if (!qword_1600) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\DxeServicesTableLib\\DxeServicesTableLib.c",
      65,
      (__int64)"gDS != ((void *) 0)");
  }

  /* Validate DXE Services Table status from AutoGen */
  if (DxeServicesStatus < 0) {
    DebugPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", DxeServicesStatus);
    AssertBreak(
      (__int64)"e:\\hs\\Build\\HR6N0XMLK\\DEBUG_VS2015\\X64\\PurleySktPkg\\Dxe\\SoftSkuDxe\\SoftSkuDxe\\DEBUG\\AutoGen.c",
      354,
      (__int64)"!EFI_ERROR (Status)");
  }

  /* Locate MM PCI Base protocol (mPciUsra) */
  if (!qword_1608) {
    EfiStatus = gBootServices->LocateProtocol(
                  &gMmPciBaseProtocolGuid, NULL, &qword_1608);
    if (EFI_ERROR(EfiStatus)) {
      DebugPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", EfiStatus);
      AssertBreak(
        (__int64)"e:\\hs\\CpRcPkg\\Library\\DxeMmPciBaseLib\\DxeMmPciBaseLib.c",
        52,
        (__int64)"!EFI_ERROR (Status)");
    }
    if (!qword_1608) {
      AssertBreak(
        (__int64)"e:\\hs\\CpRcPkg\\Library\\DxeMmPciBaseLib\\DxeMmPciBaseLib.c",
        53,
        (__int64)"mPciUsra != ((void *) 0)");
    }
  }

  /* Initialize HOB list */
  GetHobList();

  /*
   * Get PCD protocol and look up PCD tokens for:
   *   Token 5  -> Socket Capability (stored in qword_1618)
   *   Token 151 -> Socket License    (stored in qword_1628)
   */
  PcdProtocolInstance = GetPcdProtocol();
  qword_1618 = ((__int64 (*)(__int64))(*(UINT64 *)(PcdProtocolInstance + 32)))(5);
  qword_1628 = ((__int64 (*)(__int64))(*(UINT64 *)(PcdProtocolInstance + 32)))(151);

  return qword_1628;
}

/* ----------------------------------------------------------------
 * SoftSkuMain (sub_900)
 * ---------------------------------------------------------------- */

/**
 * SoftSkuMain (0x900)
 *
 * Main Soft SKU detection and provisioning logic.
 *
 * Steps:
 *   1. Gets PCD token 12 and determines if the CPU is Soft SKU compliant.
 *   2. If non-compliant (CPU stepping < 9, or socket type == 4, or no
 *      socket capability bitmask), logs "No Soft Sku compliant" and returns.
 *   3. Reads "ForceProvisioning" UEFI variable. If set, clears it
 *      (re-provisioning) and logs "ForProvisioning Cleared".
 *   4. Registers MemoryTieringNotifier as a 512ms timer callback.
 *   5. Allocates socket buffers (capability/license via BootServices).
 *   6. Applies CPU configuration (reads MSR data per socket).
 *   7. Frees allocated socket buffers.
 */
__int64
SoftSkuMain (
  __int64 Param1,
  __int64 Param2
  )
{
  UINT64    PcdProtocolInstance;
  __int64   CpuConfigLibBase;
  UINTN     SocketCount;
  UINT64    ForceProvisioningSize;
  UINT64    ForceProvisioningValue;
  EFI_GUID  VendorGuid;
  VOID     *TimerEvent;
  UINTN     Index;

  /*
   * Reconstruct Param1/Param2 as shadowed params
   * (placed here to match original function signature).
   */
  UINT64 n8  = (UINT64)Param1;
  UINT64 v8  = (UINT64)Param2;

  TimerEvent       = NULL;
  SocketCount      = 0;
  ForceProvisioningSize = 0;

  /* Get PCD protocol and look up CPU configuration base */
  PcdProtocolInstance = GetPcdProtocol();
  CpuConfigLibBase = ((__int64 (*)(__int64))(*(UINT64 *)(PcdProtocolInstance + 32)))(12);

  /* Locate CPU Config Library protocol */
  if (EFI_ERROR(gBootServices->LocateProtocol(
        &gCpuConfigLibProtocolGuid, NULL, &gCpuConfigLibProtocol))) {
    goto Done;
  }

  /* Check Soft SKU compliance */
  if (*(UINT8 *)(CpuConfigLibBase + 246424) >= 9 &&
      (*(UINT8 *)(qword_1618 + 252) != 4) &&
      *(UINT64 *)(CpuConfigLibBase + 112)) {

    /* Get socket capability bitmask */
    qword_1638 = *(UINT64 *)(CpuConfigLibBase + 112);

    /* Locate CPU Config protocol and get entry count */
    ForceProvisioningSize = 8;
    if (!EFI_ERROR(gBootServices->LocateProtocol(
            &gCpuConfigProtocolGuid, NULL, &qword_15C8)) &&
        !EFI_ERROR(((__int64 (*)(__int64, VOID *, UINT64 *))qword_15C8)(
            qword_15C8, &gCpuConfigProtocolInitGuid, &qword_15C0))) {

      /* Read "ForceProvisioning" UEFI variable */
      gRuntimeServices->GetVariable(
        L"ForceProvisioning", &VendorGuid, NULL,
        &ForceProvisioningSize, &ForceProvisioningValue);

      if (ForceProvisioningValue) {
        /* Clear Force Provisioning flag */
        ForceProvisioningValue = 0;
        gRuntimeServices->SetVariable(
          L"ForceProvisioning", &VendorGuid,
          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
          ForceProvisioningSize, &ForceProvisioningValue);
        DebugPrint(64, "ForProvisioning Cleared\n");
      }

      /* Register 512ms timer callback for memory tiering */
      gBootServices->CreateEvent(
        EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
        MemoryTieringNotifier, NULL, &TimerEvent);
      gBootServices->SetTimer(TimerEvent, TimerPeriodic, 50000); /* 512ms ~= 50ms * 10 */

      /* Allocate and populate socket capability/license buffers */
      AllocateSocketBuffers();

      /* Apply CPU configuration to each socket */
      SoftSkuApplyConfiguration();

      /* Free allocated socket buffers */
      for (Index = 0; Index < 4; Index++) {
        gBootServices->FreePool(*(VOID **)(Index * 8 + qword_1640 + 8));
        gBootServices->FreePool(*(VOID **)(Index * 8 + qword_1640 + 40));
      }
      gBootServices->FreePool((VOID *)qword_1640);
    }
  } else {
    DebugPrint(64, "No Soft Sku compliant\n");
  }

Done:
  return 0;
}

/* ----------------------------------------------------------------
 * Memory Tiering Notifier (sub_8C0)
 * ---------------------------------------------------------------- */

/**
 * MemoryTieringNotifier (0x8C0)
 *
 * Timer notification callback that runs once per boot.
 * Reads PCD token 183 and writes the value to BMC command port 0xB2,
 * then logs "Memory Tiering Enabled" via DebugPrint.
 */
VOID
MemoryTieringNotifier (
  VOID
  )
{
  __int64 PcdProtocolInstance;

  if (!byte_15B0) {
    PcdProtocolInstance = GetPcdProtocol();
    __outbyte(0xB2, ((__int64 (*)(__int64))(*(UINT64 *)(PcdProtocolInstance + 8)))(183));
    byte_15B0 = 1;
    DebugPrint(64, "Memory Tiering Enabled\n");
  }
}

/* ----------------------------------------------------------------
 * SoftSkuApplyConfiguration (sub_5F8)
 * ---------------------------------------------------------------- */

/**
 * SoftSkuApplyConfiguration (0x5F8)
 *
 * Iterates over CPU config context entries. For each processor:
 *   - Validates the config context buffer (mCpuConfigLibConfigContextBuffer).
 *   - Reads the socket ID and capability bitmask.
 *   - Calls ReadSocketLicense and/or ReadSocketCapability based on
 *     the socket capability flags.
 *   - Sets "SocketCapability" and "SocketLicense" UEFI variables.
 */
__int64
SoftSkuApplyConfiguration (
  VOID
  )
{
  INT32   PreviousSocketId;
  EFI_STATUS Status;
  UINT64  EntryIndex;
  UINT64  CpuConfigSize;
  UINT64  CpuConfigBuffer;
  UINT32  SocketId;
  UINTN   SocketCapabilityFlag;
  UINT32  CapabilityFlagByte;

  PreviousSocketId = -1;
  Status = ((__int64 (*)(UINT64, UINT64 *))qword_15C8)(qword_15C8, &CpuConfigSize);
  if (Status < 0) {
    return Status;
  }

  EntryIndex = 0;
  if (qword_15C0) {
    do {
      if (!qword_1628) {
        AssertBreak(
          (__int64)"e:\\hs\\PurleySktPkg\\Override\\IA32FamilyCpuPkg\\Library\\CpuConfigLib\\CpuConfig.c",
          482,
          (__int64)"mCpuConfigLibConfigContextBuffer != ((void *) 0)");
      }

      CpuConfigBuffer = qword_1640;
      SocketId = *(UINT32 *)(*(UINT64 *)(qword_1628 + 16) + EntryIndex * 1088 + 48);
      *(UINT8 *)qword_1640 = (UINT8)SocketId;

      if ((UINT8)SocketId != (UINT8)PreviousSocketId) {
        CapabilityFlagByte = (UINT8)(1 << SocketId);
        PreviousSocketId = (UINT8)SocketId;

        if (CapabilityFlagByte & qword_1638) {
          SocketCapabilityFlag = (UINT8)CapabilityFlagByte;

          if (CpuConfigSize == EntryIndex) {
            /* Same CPU - direct MSR read */
            if (CapabilityFlagByte & 0xFF) {
              ReadSocketLicense((UINT8 *)qword_1640);
            }
            if (SocketCapabilityFlag) {
              ReadSocketCapability((UINT8 *)qword_1640);
            }
          } else {
            /* Cross-CPU - use protocol callback */
            if (CapabilityFlagByte & 0xFF) {
              ((VOID (*)(UINT64, VOID (*)(UINT8 *), UINT64, UINTN, UINTN, UINT64, UINTN))(*(UINT64 *)(qword_15C8 + 24)))(
                qword_15C8, ReadSocketLicense, EntryIndex, 0, 0, qword_1640, 0);
            }
            if (SocketCapabilityFlag) {
              ((VOID (*)(UINT64, VOID (*)(UINT8 *), UINT64, UINTN, UINTN, UINT64, UINTN))(*(UINT64 *)(qword_15C8 + 24)))(
                qword_15C8, ReadSocketCapability, EntryIndex, 0, 0, qword_1640, 0);
            }
          }

          /* Store SocketCapability variable */
          word_15AA = (UINT8)SocketId + 48;
          word_1580 = (UINT8)SocketId + 48;

          gRuntimeServices->SetVariable(
            L"SocketCapability", &gSoftSkuVendorGuid,
            EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
            192,
            *(VOID **)(qword_1640 + 8 * SocketId + 40));

          gRuntimeServices->SetVariable(
            L"SocketLicense", &gSoftSkuVendorGuid,
            EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
            7,
            NULL);

          /* Note: original code reads the variable, does not actually
           * write the license data (second SetVariable with size 7 may
           * be a delete or read-check). The license data is set via
           * the capability variable path. */
        }
      }

      EntryIndex++;
    } while (EntryIndex < qword_15C0);
  }

  return Status;
}

/* ----------------------------------------------------------------
 * AllocateSocketBuffers (sub_7D8)
 * ---------------------------------------------------------------- */

/**
 * AllocateSocketBuffers (0x7D8)
 *
 * Allocates buffers for socket capability and license data via BootServices.
 * For each of the 4 sockets, allocates:
 *   - 128 bytes for capability data
 *   - 192 bytes for license data
 * Fills them with 0xFF (all bits set, "not provisioned" sentinel).
 */
__int64
AllocateSocketBuffers (
  VOID
  )
{
  EFI_STATUS Status;
  UINTN      SocketIndex;

  /* Allocate the base buffer array for 4 socket entries */
  Status = gBootServices->AllocatePool(
             EfiBootServicesData, 72, &qword_1640);
  if (EFI_ERROR(Status)) {
    return Status;
  }

  SocketIndex = 0;
  while (1) {
    /* Allocate capability buffer (128 bytes) */
    Status = gBootServices->AllocatePool(
               EfiBootServicesData, 128,
               (VOID **)(qword_1640 + 8 + 8 * SocketIndex));
    if (EFI_ERROR(Status)) {
      break;
    }

    /* Fill capability buffer with 0xFF */
    gBootServices->SetMem(
      *(VOID **)(qword_1640 + 8 * SocketIndex + 8),
      128,
      0xFF);

    /* Allocate license buffer (192 bytes) */
    Status = gBootServices->AllocatePool(
               EfiBootServicesData, 192,
               (VOID **)(qword_1640 + 40 + 8 * SocketIndex));
    if (EFI_ERROR(Status)) {
      break;
    }

    /* Fill license buffer with 0xFF */
    gBootServices->SetMem(
      *(VOID **)(qword_1640 + 8 * SocketIndex + 40),
      192,
      0xFF);

    SocketIndex++;
    if (SocketIndex >= 4) {
      return Status;
    }
  }

  return Status;
}

/* ----------------------------------------------------------------
 * MSR Read Functions
 * ---------------------------------------------------------------- */

/**
 * ReadSocketCapability (0x540)
 *
 * Reads 48 capability MSR registers (indices 8..8+47).
 * For MSR index 0xD1 = 6 (base setup), then reads 48 values
 * from MSR 0xD0 with indices 8..55.
 *
 * Input buffer layout at *a1:
 *   [0]   = socket ID
 *   [8*ID + 40] -> pointer to license data buffer
 *
 * Writes results as DWORD array to the buffer pointer.
 */
UINT64
ReadSocketCapability (
  UINT8 *Buffer
  )
{
  UINTN   Index;
  UINT32 *CapabilityData;
  UINT64  MsrValue;

  __writemsr(0xD1, 6);
  CapabilityData = *(UINT32 **)&Buffer[8 * *Buffer + 40];

  for (Index = 0; Index < 48; Index++) {
    __writemsr(0xD1, (Index << 8) | 8);
    MsrValue = __readmsr(0xD0);
    *CapabilityData++ = (UINT32)MsrValue;
  }

  return MsrValue;
}

/**
 * ReadSocketLicense (0x59C)
 *
 * Reads 32 license MSR registers (indices 9..9+31).
 * For MSR index 0xD1 = 6 (base setup), then reads 32 values
 * from MSR 0xD0 with indices 9..40.
 *
 * Input buffer layout at *a1:
 *   [0]   = socket ID
 *   [8*ID + 8] -> pointer to capability data buffer
 *
 * Writes results as DWORD array to the buffer pointer.
 */
UINT64
ReadSocketLicense (
  UINT8 *Buffer
  )
{
  UINTN   Index;
  UINT32 *LicenseData;
  UINT64  MsrValue;

  __writemsr(0xD1, 6);
  LicenseData = *(UINT32 **)&Buffer[8 * *Buffer + 8];

  for (Index = 0; Index < 32; Index++) {
    __writemsr(0xD1, (Index << 8) | 9);
    MsrValue = __readmsr(0xD0);
    *LicenseData++ = (UINT32)MsrValue;
  }

  return MsrValue;
}

/* ----------------------------------------------------------------
 * Debug Print (sub_B6C)
 * ---------------------------------------------------------------- */

/**
 * DebugPrint (0xB6C)
 *
 * Conditional debug/log output. Resolves the debug print protocol,
 * checks the CMOS debug level register, and filters output based
 * on the error level mask.
 */
CHAR8
DebugPrint (
  __int64 ErrorLevel,
  const CHAR8 *Format,
  ...
  )
{
  __int64 DebugProtocol;
  UINT64  LevelMask;
  UINT8   DebugLevel;
  UINT8   AdjustedLevel;
  UINT8   Port70;
  UINT8   Port71;

  DebugProtocol = GetDebugProtocol();
  LevelMask = 0;

  if (DebugProtocol) {
    /* Read CMOS debug level from port 0x70/0x71, index 0x4B */
    Port70 = __inbyte(0x70);
    __outbyte(0x70, Port70 & 0x80 | 0x4B);
    Port71 = __inbyte(0x71);

    AdjustedLevel = Port71;
    if (Port71 > 3) {
      AdjustedLevel = Port71;
      if (!Port71) {
        /* Fallback to fixed address check */
        AdjustedLevel = (*(UINT8 *)0xFDAF0490 & 2) | 1;
      }
    }

    if ((UINT8)(AdjustedLevel - 1) <= 0xFD) {
      /* Level >= 1 and <= 0xFF */
      LevelMask = 2147483718LL;  /* EFI_D_ERROR | EFI_D_WARN */
      if (AdjustedLevel == 1) {
        LevelMask = 2147483652LL;  /* EFI_D_ERROR only */
      }
    }

    if (LevelMask & ErrorLevel) {
      return ((CHAR8 (*)(__int64, const CHAR8 *, ...))DebugProtocol)(
               ErrorLevel, Format, VA_START(Format));
    }
  }

  return (CHAR8)DebugProtocol;
}

/* ----------------------------------------------------------------
 * AssertBreak (sub_BF4)
 * ---------------------------------------------------------------- */

/**
 * AssertBreak (0xBF4)
 *
 * ASSERT implementation. If a debug protocol is available,
 * calls its assertion handler with file/line/expression info.
 */
__int64
AssertBreak (
  __int64 FileName,
  __int64 LineNumber,
  __int64 Expression
  )
{
  __int64 DebugProtocol;

  DebugProtocol = GetDebugProtocol();
  if (DebugProtocol) {
    return ((__int64 (*)(__int64, __int64, __int64))(DebugProtocol + 8))(
             FileName, LineNumber, Expression);
  }

  return DebugProtocol;
}

/* ----------------------------------------------------------------
 * GetDebugProtocol (sub_AEC)
 * ---------------------------------------------------------------- */

/**
 * GetDebugProtocol (0xAEC)
 *
 * Lazily resolves the debug print protocol handle.
 * Checks TPL first; if TPL <= 16, locates the protocol.
 * Returns NULL on failure.
 */
__int64
GetDebugProtocol (
  VOID
  )
{
  EFI_TPL  CurrentTpl;

  if (qword_15F0) {
    return qword_15F0;
  }

  CurrentTpl = gBootServices->RaiseTPL(TPL_HIGH_LEVEL);
  gBootServices->RestoreTPL(CurrentTpl);

  if (CurrentTpl <= 16) {
    if (EFI_ERROR(gBootServices->LocateProtocol(
            &gDebugPrintProtocolGuid, NULL, &qword_15F0))) {
      qword_15F0 = 0;
    }
    return qword_15F0;
  }

  return 0;
}

/* ----------------------------------------------------------------
 * GetPcdProtocol (sub_C34)
 * ---------------------------------------------------------------- */

/**
 * GetPcdProtocol (0xC34)
 *
 * Lazily resolves the PCD protocol pointer.
 * If resolution fails, triggers an ASSERT.
 */
__int64
GetPcdProtocol (
  VOID
  )
{
  EFI_STATUS Status;

  if (qword_15F8) {
    return qword_15F8;
  }

  Status = gBootServices->LocateProtocol(
             &gPcdProtocolGuid, NULL, &qword_15F8);
  if (EFI_ERROR(Status)) {
    DebugPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", Status);
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\DxePcdLib\\DxePcdLib.c",
      78,
      (__int64)"!EFI_ERROR (Status)");
  }

  if (!qword_15F8) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\DxePcdLib\\DxePcdLib.c",
      79,
      (__int64)"mPcd != ((void *) 0)");
  }

  return qword_15F8;
}

/* ----------------------------------------------------------------
 * GetCpuConfigLibProtocol (sub_AEC variant)
 * ---------------------------------------------------------------- */

/**
 * GetCpuConfigLibProtocol (0x??)
 *
 * Lazily resolves the CPU Config Library protocol.
 * Used by SoftSkuEntry to initialize the config context buffer.
 */
__int64
GetCpuConfigLibProtocol (
  VOID
  )
{
  return qword_15C8;
}

/* ----------------------------------------------------------------
 * GetConfigurationTable (sub_CC0)
 * ---------------------------------------------------------------- */

/**
 * GetConfigurationTable (0xCC0)
 *
 * Scans the SystemTable's configuration table array for a matching GUID.
 * Returns the table pointer in *Table and EFI_SUCCESS (0) on success,
 * or EFI_NOT_FOUND (0x800000000000000E) if not found.
 */
UINT64
GetConfigurationTable (
  __int64 TableGuid,
  __int64 *Table
  )
{
  UINTN  Index;
  UINT64 TableCount;

  if (!TableGuid) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c",
      97,
      (__int64)"TableGuid != ((void *) 0)");
  }

  if (!Table) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c",
      98,
      (__int64)"Table != ((void *) 0)");
  }

  *Table = 0;

  TableCount = gSystemTable->NumberOfTableEntries;
  if (!TableCount) {
    return EFI_NOT_FOUND;
  }

  for (Index = 0; ; Index++) {
    if (CompareGuid(TableGuid,
          (__int64)&gSystemTable->ConfigurationTable[Index].VendorGuid)) {
      *Table = (__int64)gSystemTable->ConfigurationTable[Index].VendorTable;
      return EFI_SUCCESS;
    }
    if ((UINT64)(Index + 1) >= TableCount) {
      return EFI_NOT_FOUND;
    }
  }
}

/* ----------------------------------------------------------------
 * GetHobList (sub_D84)
 * ---------------------------------------------------------------- */

/**
 * GetHobList (0xD84)
 *
 * Lazily resolves the HOB list pointer from the configuration table.
 */
__int64
GetHobList (
  VOID
  )
{
  __int64 Status;

  if (qword_1610) {
    return qword_1610;
  }

  Status = GetConfigurationTable((__int64)&gEfiHobListGuid, &qword_1610);
  if (Status < 0) {
    DebugPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", Status);
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c",
      54,
      (__int64)"!EFI_ERROR (Status)");
  }

  if (!qword_1610) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c",
      55,
      (__int64)"mHobList != ((void *) 0)");
  }

  return qword_1610;
}

/* ----------------------------------------------------------------
 * CompareGuid (sub_E08)
 * ---------------------------------------------------------------- */

/**
 * CompareGuid (0xE08)
 *
 * Compares two GUIDs by reading the first two QWORDs from each.
 * Both GUID1 and GUID2 may be unaligned.
 */
BOOLEAN
CompareGuid (
  __int64 Guid1,
  __int64 Guid2
  )
{
  UINT64 A0, A1, B0, B1;

  A0 = ReadUnaligned64((VOID *)Guid1);
  B0 = ReadUnaligned64((VOID *)Guid2);
  A1 = ReadUnaligned64((VOID *)(Guid1 + 8));
  B1 = ReadUnaligned64((VOID *)(Guid2 + 8));

  return (A0 == B0) && (A1 == B1);
}

/* ----------------------------------------------------------------
 * ReadUnaligned64 (sub_E70)
 * ---------------------------------------------------------------- */

/**
 * ReadUnaligned64 (0xE70)
 *
 * Reads a UINT64 from a potentially unaligned pointer.
 * The original binary uses a simple QWORD dereference without
 * an explicit unaligned access helper - this wrapper documents
 * the intent.
 */
UINT64
ReadUnaligned64 (
  VOID *Buffer
  )
{
  if (!Buffer) {
    AssertBreak(
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
      192,
      (__int64)"Buffer != ((void *) 0)");
  }

  return *(UINT64 *)Buffer;
}