Newer
Older
AMI-Aptio-BIOS-Reversed / ServerCommonPkg / Universal / GetSec / Pei / TxtPei / TxtPei.c
@Ajax Dong Ajax Dong 2 days ago 47 KB Restructure the repo
#include "TxtPei.h"

//
// TxtPei - UEFI Module
// Total functions: 60
//

// Function: memset @ 0xffe06290 (0x15 bytes)

void *__cdecl memset(void *buf, unsigned int count, char value)
{
  memset(buf, value, count); /*0xffe0629d*/
  return buf; /*0xffe062a3*/
}


// Function: setMem32 @ 0xffe062b0 (0x1f bytes)

int __cdecl setMem32(int a1, int a2, int a3, int a4)
{
  do /*0xffe062c9*/
  {
    *(_DWORD *)(a1 + 8 * a2 - 8) = a3; /*0xffe062c1*/
    *(_DWORD *)(a1 + 8 * a2-- - 4) = a4; /*0xffe062c5*/
  }
  while ( a2 ); /*0xffe062c9*/
  return a1; /*0xffe062cd*/
}


// Function: memset32 @ 0xffe062d0 (0x15 bytes)

void *__cdecl memset32(void *buf, unsigned int count, int value)
{
  memset32(buf, value, count); /*0xffe062dd*/
  return buf; /*0xffe062e3*/
}


// Function: CopyMem @ 0xffe06370 (0x3f bytes)

char *__cdecl CopyMem(char *dst, char *src, unsigned int count)
{
  unsigned int count_1; // edx
  char *dst_1; // edi
  char *src_1; // esi

  count_1 = count; /*0xffe0637a*/
  if ( src < dst && &src[count - 1] >= dst ) /*0xffe06388*/
  {
    src_1 = &src[count - 1]; /*0xffe0639c*/
    dst_1 = &dst[count - 1]; /*0xffe0639e*/
  }
  else
  {
    count_1 = count & 3; /*0xffe0638c*/
    qmemcpy(dst, src, 4 * (count >> 2)); /*0xffe06395*/
    src_1 = &src[4 * (count >> 2)]; /*0xffe06395*/
    dst_1 = &dst[4 * (count >> 2)]; /*0xffe06395*/
  }
  qmemcpy(dst_1, src_1, count_1); /*0xffe063a5*/
  return dst; /*0xffe063ac*/
}


// Function: _ModuleEntryPoint @ 0xffe063d0 (0x46a bytes)

EFI_STATUS ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  void *v2; // ecx
  int v3; // ebp
  void *v4; // ecx
  void *v5; // ecx
  int v6; // eax
  int v7; // eax
  int v8; // eax
  EFI_STATUS result; // eax
  int v10; // eax
  int v11; // eax
  int v12; // eax
  int v13; // eax
  int v14; // eax
  int v15; // eax
  int p_this; // [esp+44h] [ebp-34h] BYREF
  int v17; // [esp+48h] [ebp-30h] BYREF
  int v18; // [esp+4Ch] [ebp-2Ch] BYREF
  int v19; // [esp+50h] [ebp-28h] BYREF
  int v20; // [esp+54h] [ebp-24h] BYREF
  int v21; // [esp+58h] [ebp-20h]
  int v22; // [esp+74h] [ebp-4h]

  if ( *(char *)(CpuIdViaPeiService(v2) + 1024068) >= 0 ) /*0xffe063e1*/
  {
    SetFeatureBit(v4); /*0xffe063e3*/
    v6 = CpuIdViaPeiService(v5); /*0xffe063e8*/
    *(_BYTE *)(v6 + 1024068) |= 0x80u; /*0xffe063f4*/
  }
  v22 = v3; /*0xffe0668f*/
  DebugPrint(64, (int)"Enter TxtPei \n"); /*0xffe066a5*/
  v7 = (*(int (__cdecl **)(EFI_SYSTEM_TABLE *, void *))(LODWORD(SystemTable->Hdr.Signature) + 36))( /*0xffe066b2*/
         SystemTable,
         &unk_FFE08CF8);
  if ( v7 < 0 ) /*0xffe066c9*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v7); /*0xffe066d2*/
    v8 = DebugPrintProtocol(); /*0xffe066da*/
    if ( v8 ) /*0xffe066e1*/
      (*(void (__cdecl **)(const char *, int, const char *))(v8 + 4))( /*0xffe066ea*/
        "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPei.c",
        442,
        "!EFI_ERROR (Status)");
  }
  result = TxtPeiInit(SystemTable, &v20); /*0xffe066f6*/
  if ( (result & 0x80000000) == 0 )
  {
    v10 = (*(int (__cdecl **)(EFI_SYSTEM_TABLE *, void *))(LODWORD(SystemTable->Hdr.Signature) + 24))( /*0xffe0670b*/
            SystemTable,
            &unk_FFE08D14);
    if ( v10 < 0 ) /*0xffe06712*/
    {
      DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v10); /*0xffe0671b*/
      v11 = DebugPrintProtocol(); /*0xffe06723*/
      if ( v11 ) /*0xffe0672a*/
        (*(void (__cdecl **)(const char *, int, const char *))(v11 + 4))( /*0xffe06733*/
          "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPei.c",
          457,
          "!EFI_ERROR (Status)");
    }
    v12 = (*(int (__cdecl **)(EFI_SYSTEM_TABLE *, void *))(LODWORD(SystemTable->Hdr.Signature) + 24))( /*0xffe06741*/
            SystemTable,
            &unk_FFE08D04);
    if ( v12 < 0 ) /*0xffe06748*/
    {
      DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v12); /*0xffe06751*/
      v13 = DebugPrintProtocol(); /*0xffe06759*/
      if ( v13 ) /*0xffe06760*/
        (*(void (__cdecl **)(const char *, int, const char *))(v13 + 4))( /*0xffe06769*/
          "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPei.c",
          463,
          "!EFI_ERROR (Status)");
    }
    CpuRegRead(&p_this, &v17, &v18, &v19); /*0xffe06782*/
    if ( (v18 & 0x40) != 0 )
    {
      if ( DwrCheck() )
      {
        DebugPrint(0x80000000, (int)"[TxtPei] WARNING: DWR detected - skip Tpm detection in TxtPei module\n");
        return -2147483645; /*0xffe067c2*/
      }
      if ( ((*(int (__cdecl **)(int, int, int, _DWORD))(v21 + 48))(v20, v21, -19660800, 0) & 1) == 0 /*0xffe067f8*/
        && ((*(int (__cdecl **)(int, int, int, _DWORD))(v21 + 48))(v20, v21, -19726328, 0) & 0x40) != 0 )
      {
        v14 = (*(int (__cdecl **)(EFI_SYSTEM_TABLE *, void *))(LODWORD(SystemTable->Hdr.Signature) + 36))( /*0xffe06802*/
                SystemTable,
                &unk_FFE08CEC);
        if ( v14 < 0 ) /*0xffe06809*/
        {
          DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v14); /*0xffe06812*/
          v15 = DebugPrintProtocol(); /*0xffe0681a*/
          if ( v15 ) /*0xffe06821*/
            (*(void (__cdecl **)(const char *, int, const char *))(v15 + 4))( /*0xffe0682a*/
              "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPei.c",
              536,
              "!EFI_ERROR (Status)");
        }
      }
    }
    else
    {
      DebugPrint(0x80000000, (int)"LtPeim Error: CPU does not support TXT\n");
    }
    return 0; /*0xffe06830*/
  }
  return result; /*0xffe06839*/
}


// Function: TxtPeiInit @ 0xffe0683a (0x12e bytes)

int __fastcall TxtPeiInit(EFI_SYSTEM_TABLE *SystemTable, _DWORD *a2)
{
  int v4; // eax
  int v5; // eax
  _WORD *v6; // eax
  _WORD *v7; // eax

  *a2 = SystemTable; /*0xffe06845*/
  a2[1] = *(_DWORD *)(LODWORD(SystemTable->Hdr.Signature) + 96); /*0xffe0684c*/
  a2[2] = *(_DWORD *)(LODWORD(SystemTable->Hdr.Signature) + 100); /*0xffe06854*/
  v4 = (*(int (__cdecl **)(EFI_SYSTEM_TABLE *, void *, _DWORD, _DWORD, _DWORD *))(LODWORD(SystemTable->Hdr.Signature) /*0xffe06865*/
                                                                                + 32))(
         SystemTable,
         &unk_FFE08C90,
         0,
         0,
         a2 + 3);
  if ( v4 < 0 ) /*0xffe06872*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v4); /*0xffe0687b*/
    v5 = DebugPrintProtocol(); /*0xffe06883*/
    if ( v5 ) /*0xffe0688a*/
      (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffe06898*/
        "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPeiLib.c",
        98,
        "!EFI_ERROR (Status)");
  }
  (*(void (__cdecl **)(EFI_SYSTEM_TABLE *, void *, _DWORD, _DWORD, _DWORD *))(LODWORD(SystemTable->Hdr.Signature) + 32))( /*0xffe068ac*/
    SystemTable,
    &unk_FFE08CB0,
    0,
    0,
    a2 + 4);
  v6 = GetNextGuidHob(&unk_FFE08C30); /*0xffe068b7*/
  if ( v6 ) /*0xffe068be*/
  {
    a2[5] = v6 + 12; /*0xffe068d5*/
  }
  else
  {
    DebugPrint(0x80000000, (int)"GUID HOB gEfiPlatformTxtDeviceMemoryGuid not found!\n"); /*0xffe068c6*/
    a2[5] = 0; /*0xffe068cd*/
  }
  v7 = GetNextGuidHob(&unk_FFE08C70); /*0xffe068dd*/
  if ( v7 ) /*0xffe068e4*/
  {
    a2[6] = v7 + 12; /*0xffe06903*/
    DebugPrint(0x80000000, (int)"PlatformTxtPolicy:\n"); /*0xffe06906*/
    DebugPrint(0x80000000, (int)"  BiosAcmAddress             - 0x%08x\n", *(_DWORD *)a2[6]); /*0xffe06919*/
    DebugPrint(0x80000000, (int)"  TxtScratchAddress          - 0x%08x\n", *(_DWORD *)(a2[6] + 48)); /*0xffe0692d*/
    DebugPrint(0x80000000, (int)"  BiosAcmPolicy              - 0x%08x\n", *(_DWORD *)(a2[6] + 56)); /*0xffe0693e*/
    TxtDebugPrintPolicy(a2); /*0xffe06948*/
    DebugPrint(0x80000000, (int)"ApVector - 0x%08x\n", *((unsigned __int8 *)a2 + 28)); /*0xffe06958*/
    return 0; /*0xffe06960*/
  }
  else
  {
    DebugPrint(0x80000000, (int)"GUID HOB gEfiPlatformTxtPolicyDataGuid not found! Error when do TxtPei Init.\n"); /*0xffe068ec*/
    return -2147483634; /*0xffe068f3*/
  }
}


// Function: LtPeiWriteMsr @ 0xffe06968 (0x21 bytes)

__int64 LtPeiWriteMsr()
{
  __writemsr(0x2E7u, 1u); /*0xffe06983*/
  return 1; /*0xffe06985*/
}


// Function: LtPeiLockMsr @ 0xffe06989 (0x53 bytes)

int __thiscall LtPeiLockMsr(_DWORD *this)
{
  int result; // eax
  unsigned __int8 v2; // [esp+Ch] [ebp-4h]

  v2 = 0; /*0xffe0699b*/
  __writemsr(0x2E7u, 1u); /*0xffe069a9*/
  result = (*(int (__cdecl **)(_DWORD, _DWORD, __int64 (*)(), _DWORD, _DWORD, _DWORD))(*(this + 4) + 8))( /*0xffe069b9*/
             *this,
             *(this + 4),
             LtPeiWriteMsr,
             v2,
             v2,
             v2);
  if ( result < 0 )
    return DebugPrint(0x80000000, (int)"Error: Not able to Lock LT MSR.  Status: %r\n", result);
  return result; /*0xffe069bf*/
}


// Function: LtPeiEnableMtrr @ 0xffe069dc (0x76 bytes)

unsigned __int8 __thiscall LtPeiEnableMtrr(_BYTE *this)
{
  int v2; // eax
  unsigned __int8 result; // al

  if ( !(__readmsr(0x8Bu) >> 32) ) /*0xffe069ef*/
  {
    v2 = DebugPrintProtocol(); /*0xffe06a0c*/
    if ( v2 ) /*0xffe06a13*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe06a24*/
        "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPeiLib.c",
        491,
        "McuRevision != 0");
  }
  result = *(this + 28); /*0xffe06a2a*/
  if ( result ) /*0xffe06a2f*/
  {
    CacheEnable(result << 12); /*0xffe06a37*/
    return (*(unsigned __int8 (__cdecl **)(_DWORD, _DWORD, int))(*((_DWORD *)this + 3) + 4))( /*0xffe06a47*/
             *(_DWORD *)this,
             *((_DWORD *)this + 3),
             40000);
  }
  return result; /*0xffe06a4d*/
}


// Function: PchIoWrite @ 0xffe06a52 (0x7d bytes)

int __cdecl PchIoWrite(_DWORD *a1)
{
  _DWORD *v1; // ecx
  _DWORD *v2; // esi
  int v3; // edi
  int result; // eax
  int v5; // eax
  int v6; // [esp+Ch] [ebp-8h] BYREF
  int v7; // [esp+10h] [ebp-4h] BYREF

  v2 = v1; /*0xffe06a59*/
  v7 = 0; /*0xffe06a61*/
  v3 = 0; /*0xffe06a67*/
  result = (*(int (__cdecl **)(_DWORD, _DWORD, int *))(*(_DWORD *)*v1 + 56))(*v1, 0, &v7); /*0xffe06a6d*/
LABEL_6:
  if ( result >= 0 ) /*0xffe06ab7*/
  {
    v6 = 0; /*0xffe06a72*/
    do /*0xffe06a7f*/
    {
      if ( (*(int (__cdecl **)(_DWORD, int, int *, int *))(*(_DWORD *)*v2 + 60))(*v2, 1, &v7, &v6) < 0 ) /*0xffe06a9f*/
      {
        v5 = *v2; /*0xffe06aa1*/
        ++v3; /*0xffe06aa7*/
        v7 = 0; /*0xffe06aa8*/
        result = (*(int (__cdecl **)(int, int, int *))(*(_DWORD *)v5 + 56))(v5, v3, &v7); /*0xffe06aaf*/
        goto LABEL_6; /*0xffe06aaf*/
      }
    }
    while ( !HobGetSize(v6, (int)&unk_FFE08D20) ); /*0xffe06a7f*/
    *a1 = v6 + 24; /*0xffe06ac4*/
    return 0; /*0xffe06ac6*/
  }
  return result; /*0xffe06ac8*/
}


// Function: TxtDebugPrintPolicy @ 0xffe06acf (0x97 bytes)

int __thiscall TxtDebugPrintPolicy(_BYTE *this)
{
  unsigned int v2; // ebx
  int v4; // eax
  int v5; // eax
  unsigned int v6; // [esp+Ch] [ebp-4h] BYREF

  *(this + 28) = 0; /*0xffe06adc*/
  if ( PchIoWrite(&v6) >= 0 ) /*0xffe06ae8*/
  {
    v2 = v6; /*0xffe06aea*/
    if ( (v6 & 0xFFF) == 0 && v6 + 0x20000 <= 0x1F000 ) /*0xffe06b02*/
    {
      *(this + 28) = v6 >> 12; /*0xffe06b09*/
      return 0; /*0xffe06b0c*/
    }
    if ( (v6 & 0xFFF) != 0 ) /*0xffe06b15*/
    {
      v4 = DebugPrintProtocol(); /*0xffe06b17*/
      if ( v4 ) /*0xffe06b1e*/
        (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffe06b2b*/
          "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPeiLib.c",
          617,
          "(ApStartup & 0xFFF) == 0");
    }
    if ( v2 < 0xFFFE0000 || v2 > 0xFFFFF000 ) /*0xffe06b3f*/
    {
      v5 = DebugPrintProtocol(); /*0xffe06b41*/
      if ( v5 ) /*0xffe06b48*/
        (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffe06b55*/
          "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPeiLib.c",
          618,
          "(ApStartup >= 0xFFFE0000) && (ApStartup <= 0xFFFFF000)");
    }
  }
  return -2147483634; /*0xffe06b60*/
}


// Function: LtPeiGetTxtVersion @ 0xffe06b66 (0x40 bytes)

int __thiscall LtPeiGetTxtVersion(int this)
{
  if ( *(_QWORD *)(*(_DWORD *)(this + 24) + 16) ) /*0xffe06b6c*/
  {
    LtPeiEnableMtrr((_BYTE *)this); /*0xffe06b74*/
    ApicWriteIcr(0xC4500u, 0); /*0xffe06b80*/
    LtPeiLibLaunchBiosAcm(this, 5); /*0xffe06b8a*/
  }
  else
  {
    DebugPrint(0x80000000, (int)"Did not call ACM. The ACM module is not enabled ...\n"); /*0xffe06b9b*/
  }
  return 0; /*0xffe06ba4*/
}


// Function: LtPeiLockConfig @ 0xffe06ba6 (0x61 bytes)

int __thiscall LtPeiLockConfig(_DWORD *this)
{
  int v2; // ecx
  int v3; // ecx

  LtPeiLibInitialize(this); /*0xffe06bab*/
  DebugPrint(64, (int)"  Restoring TXTHeapMemoryAddress = 0x%08x... \n", *(_DWORD *)(*(this + 5) + 32)); /*0xffe06bc5*/
  v2 = *(this + 5); /*0xffe06bca*/
  MEMORY[0xFED30300] = *(_DWORD *)(v2 + 32); /*0xffe06bd0*/
  MEMORY[0xFED30304] = *(_DWORD *)(v2 + 36); /*0xffe06bd5*/
  DebugPrint(64, (int)"  Restoring TXTHeapMemorySize = 0x%08x... \n", *(_DWORD *)(*(this + 5) + 40)); /*0xffe06beb*/
  v3 = *(this + 5); /*0xffe06bf0*/
  MEMORY[0xFED30308] = *(_DWORD *)(v3 + 40); /*0xffe06bf9*/
  MEMORY[0xFED3030C] = *(_DWORD *)(v3 + 44); /*0xffe06bfe*/
  return 0; /*0xffe06c03*/
}


// Function: LtPeiLibInitialize @ 0xffe06c07 (0x200 bytes)

int __usercall LtPeiLibInitialize@<eax>(_DWORD *this@<ecx>, __m64 a2@<mm3>)
{
  int v3; // eax
  int v4; // eax
  int v5; // eax
  int v6; // eax
  char v7; // bl
  unsigned int n4_3; // ecx
  char v9; // dl
  unsigned int n4_2; // ecx
  int v11; // eax
  __int16 v12; // dx
  unsigned int n4; // ecx
  unsigned __int8 v14; // al
  int v15; // esi
  int v17; // [esp-14h] [ebp-60h]
  unsigned int n4_1; // [esp+10h] [ebp-3Ch] BYREF
  int v19; // [esp+14h] [ebp-38h] BYREF
  int v20; // [esp+18h] [ebp-34h] BYREF
  char v21[4]; // [esp+1Ch] [ebp-30h] BYREF
  _BYTE buf[16]; // [esp+20h] [ebp-2Ch] BYREF
  _WORD v23[14]; // [esp+30h] [ebp-1Ch] BYREF

  HobGetType(buf, 0x10u); /*0xffe06c17*/
  v3 = (*(int (__cdecl **)(_DWORD, _DWORD, int *, char *))*(this + 4))(*this, *(this + 4), &v20, v21); /*0xffe06c2c*/
  if ( v3 < 0 ) /*0xffe06c42*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v3); /*0xffe06c4b*/
    v4 = DebugPrintProtocol(); /*0xffe06c53*/
    if ( v4 ) /*0xffe06c5a*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffe06c63*/
        "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPeiLib.c",
        790,
        "!EFI_ERROR (Status)");
  }
  (*(void (__cdecl **)(_DWORD, _DWORD, unsigned int *))(*(this + 4) + 24))(*this, *(this + 4), &n4_1); /*0xffe06c74*/
  EndOfHobCheck(&v19); /*0xffe06c7c*/
  v17 = v19 & 0x1F; /*0xffe06c88*/
  v19 = v17; /*0xffe06c90*/
  DebugPrint(64, (int)"mNumofBitShift! %d\n", v17); /*0xffe06c94*/
  v5 = (*(int (__cdecl **)(_DWORD, _DWORD, unsigned int, _WORD *))(*(this + 4) + 4))(*this, *(this + 4), n4_1, v23); /*0xffe06cab*/
  if ( v5 < 0 ) /*0xffe06cb3*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v5); /*0xffe06cbc*/
    v6 = DebugPrintProtocol(); /*0xffe06cc4*/
    if ( v6 ) /*0xffe06ccb*/
      (*(void (__cdecl **)(const char *, int, const char *))(v6 + 4))( /*0xffe06cd4*/
        "e:\\hs\\ServerCommonPkg\\Universal\\GetSec\\Pei\\TxtPeiLib.c",
        810,
        "!EFI_ERROR (Status)");
  }
  v7 = LOBYTE(v23[0]) >> v19; /*0xffe06ce6*/
  n4_3 = 0; /*0xffe06ce8*/
  n4_1 = 0; /*0xffe06cea*/
  if ( v20 != -1 ) /*0xffe06cf1*/
  {
    do /*0xffe06d4c*/
    {
      (*(void (__cdecl **)(_DWORD, _DWORD, unsigned int, _WORD *))(*(this + 4) + 4))(*this, *(this + 4), n4_3, v23); /*0xffe06cff*/
      v9 = LOBYTE(v23[0]) >> v19; /*0xffe06d0d*/
      n4_2 = n4_1; /*0xffe06d0f*/
      if ( LOBYTE(v23[0]) >> v19 != v7 ) /*0xffe06d15*/
      {
        v11 = 0; /*0xffe06d17*/
        while ( buf[4 * v11 + 1] != v9 ) /*0xffe06d1d*/
        {
          if ( buf[4 * v11] == 0xFF ) /*0xffe06d24*/
          {
            buf[4 * v11 + 1] = v9; /*0xffe06d2e*/
            v12 = v23[0]; /*0xffe06d32*/
            buf[4 * v11] = n4_2; /*0xffe06d37*/
            *(_WORD *)&buf[4 * v11 + 2] = v12; /*0xffe06d3b*/
            break; /*0xffe06d3b*/
          }
          if ( (unsigned int)++v11 >= 4 ) /*0xffe06d2a*/
            break; /*0xffe06d2a*/
        }
      }
      n4_3 = n4_2 + 1; /*0xffe06d40*/
      n4_1 = n4_3; /*0xffe06d46*/
    }
    while ( n4_3 < v20 + 1 ); /*0xffe06d4c*/
  }
  ApicWriteIcr((void *)0xC4500, 0); /*0xffe06d55*/
  DebugPrint(64, (int)"DoLockConfig for BSP\n"); /*0xffe06d63*/
  if ( *(_QWORD *)(*(this + 6) + 16) ) /*0xffe06d6d*/
    LtPeiLibLaunchBiosAcm((int)this, a2); /*0xffe06d7a*/
  DebugPrint(64, (int)"Done! \n"); /*0xffe06d86*/
  n4 = 0; /*0xffe06d8d*/
  n4_1 = 0; /*0xffe06d8f*/
  do
  {
    v14 = buf[4 * n4]; /*0xffe06d93*/
    if ( v14 == 0xFF ) /*0xffe06d99*/
      break; /*0xffe06d99*/
    DebugPrint(64, (int)"DoLockConfig for Socket: %d AP: %d\n", (unsigned __int8)buf[4 * n4 + 1] + 1, v14);
    v15 = (*(int (__cdecl **)(_DWORD, _DWORD, unsigned __int64 (__cdecl *)(int), _DWORD, _DWORD, _DWORD *))(*(this + 4) + 12))( /*0xffe06dd0*/
            *this,
            *(this + 4),
            BitFieldRead32,
            (unsigned __int8)buf[4 * n4_1],
            0,
            this);
    ApicWriteIcr((void *)0x4500, *(unsigned __int16 *)&buf[4 * n4_1 + 2]); /*0xffe06ddc*/
    DebugPrint(64, (int)"Done! \n"); /*0xffe06de3*/
    if ( v15 < 0 ) /*0xffe06ded*/
      break; /*0xffe06ded*/
    n4 = n4_1 + 1; /*0xffe06df3*/
    n4_1 = n4; /*0xffe06df4*/
  }
  while ( n4 < 4 );
  return 0; /*0xffe06dfd*/
}


// Function: BitFieldRead32 @ 0xffe06e07 (0x3a bytes)

unsigned __int64 __cdecl BitFieldRead32(int a1)
{
  int v1; // ecx
  int v2; // ecx

  IoRead8(v1, 1, 0); /*0xffe06e12*/
  v2 = a1; /*0xffe06e17*/
  if ( *(_QWORD *)(*(_DWORD *)(a1 + 24) + 16) ) /*0xffe06e20*/
    LtPeiLibLaunchBiosAcm(a1, 6); /*0xffe06e2b*/
  return IoRead8(v2, 0, 0); /*0xffe06e3f*/
}


// Function: LtPeiLibLaunchBiosAcm @ 0xffe06e41 (0x1fd bytes)

int __usercall LtPeiLibLaunchBiosAcm@<eax>(int this@<ecx>, __m64 a2@<mm3>)
{
  unsigned int v3; // esi
  unsigned __int64 v4; // rax
  unsigned int v5; // edi
  unsigned __int64 v6; // rax
  unsigned int v7; // ebx
  unsigned __int64 v8; // rax
  unsigned int v9; // ebp
  unsigned __int64 v10; // rax
  unsigned __int64 v11; // rax
  unsigned __int64 v12; // rax
  unsigned int v15; // [esp+1Ch] [ebp-10h]

  v3 = 0; /*0xffe06e4c*/
  v4 = __readmsr(0x424u); /*0xffe06e57*/
  v5 = v4; /*0xffe06e5d*/
  v6 = __readmsr(0x428u); /*0xffe06e64*/
  v7 = v6; /*0xffe06e6a*/
  v8 = __readmsr(0x42Cu); /*0xffe06e71*/
  v9 = v8; /*0xffe06e73*/
  v15 = v8 & 0xFFFFFF7F; /*0xffe06e92*/
  v10 = __readmsr(0x179u); /*0xffe06e9b*/
  if ( (v10 & 0x1000000) != 0 ) /*0xffe06ea6*/
  {
    v11 = __readmsr(0x178u); /*0xffe06ead*/
    v3 = v11; /*0xffe06eb4*/
    __writemsr(0x178u, 0); /*0xffe06ecc*/
  }
  __writemsr(0x424u, v5 & 0xFFFFFF7F); /*0xffe06eec*/
  __writemsr(0x428u, v7 & 0xFFFFFF7F); /*0xffe06f0c*/
  __writemsr(0x42Cu, v15); /*0xffe06f2c*/
  DebugPrint(0x80000000, (int)"LtPeiLibLaunchBiosAcm: BiosAcmAddress = 0x % 08x\n", **(_DWORD **)(this + 24));
  BiosAcmInvoke(a2, **(_DWORD **)(this + 24)); /*0xffe06f5a*/
  __writemsr(0x425u, 0); /*0xffe06f78*/
  __writemsr(0x429u, 0); /*0xffe06f95*/
  __writemsr(0x42Du, 0); /*0xffe06fb2*/
  __writemsr(0x424u, v5); /*0xffe06fcf*/
  __writemsr(0x428u, v7); /*0xffe06fea*/
  __writemsr(0x42Cu, v9); /*0xffe07005*/
  v12 = __readmsr(0x179u); /*0xffe07010*/
  if ( (v12 & 0x1000000) != 0 ) /*0xffe0701b*/
    __writemsr(0x178u, v3); /*0xffe07032*/
  return 0; /*0xffe07034*/
}


// Function: EndOfHobCheck @ 0xffe0703e (0x4e bytes)

int __cdecl EndOfHobCheck(_DWORD *a1)
{
  _EAX = 11; /*0xffe0705e*/
  __asm { cpuid } /*0xffe07064*/
  if ( a1 ) /*0xffe0706a*/
    *a1 = _EAX; /*0xffe0706c*/
  return 11; /*0xffe07087*/
}


// Function: IoRead8 @ 0xffe0708c (0x37 bytes)

int __cdecl IoRead8(int a1, int a2, int a3)
{
  unsigned __int64 v3; // rax
  unsigned __int64 v5; // [esp-10h] [ebp-24h]

  v5 = __readmsr(0x1Bu); /*0xffe070a5*/
  LODWORD(v3) = IoRead16(v5, SHIDWORD(v5), a2, a3); /*0xffe070a6*/
  __writemsr(0x1Bu, v3); /*0xffe070bd*/
  return v3; /*0xffe070bf*/
}


// Function: CpuRegRead @ 0xffe070c3 (0x3c bytes)

int __usercall CpuRegRead@<eax>(_DWORD *p_this@<edx>, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
  _EAX = 1; /*0xffe070d4*/
  __asm { cpuid } /*0xffe070d7*/
  if ( p_this ) /*0xffe070dd*/
    *p_this = _EAX; /*0xffe070df*/
  if ( a2 ) /*0xffe070e4*/
    *a2 = _EBX; /*0xffe070e6*/
  if ( a3 ) /*0xffe070ec*/
    *a3 = _ECX; /*0xffe070ee*/
  if ( a4 ) /*0xffe070f3*/
    *a4 = _EDX; /*0xffe070f5*/
  return 1; /*0xffe070fa*/
}


// Function: ReportStatusCode @ 0xffe070ff (0x42 bytes)

unsigned __int64 __cdecl ReportStatusCode(unsigned __int64 a1)
{
  unsigned int n0x40; // ecx
  int v2; // eax
  unsigned __int64 v3; // rax
  char n0x40_1; // [esp+0h] [ebp-4h]

  n0x40_1 = n0x40; /*0xffe07103*/
  if ( n0x40 >= 0x40 ) /*0xffe07109*/
  {
    v2 = DebugPrintProtocol(); /*0xffe0710b*/
    if ( v2 ) /*0xffe07112*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe07120*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\RShiftU64.c",
        39,
        "Count < 64");
  }
  v3 = HIDWORD(a1); /*0xffe0712b*/
  if ( (n0x40_1 & 0x20) == 0 ) /*0xffe07131*/
    v3 = a1; /*0xffe07135*/
  return v3 >> (n0x40_1 & 0x1F); /*0xffe0713d*/
}


// Function: IoWrite8 @ 0xffe07141 (0x3e bytes)

unsigned int __fastcall IoWrite8(int this, unsigned int n8, unsigned int n0xB)
{
  char n8_1; // si
  int v5; // eax

  n8_1 = n8; /*0xffe07142*/
  if ( n8 > n0xB ) /*0xffe0714b*/
  {
    v5 = DebugPrintProtocol(); /*0xffe0714d*/
    if ( v5 ) /*0xffe07154*/
      (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffe07165*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\BitField.c",
        540,
        "StartBit <= EndBit");
  }
  return (this & (unsigned int)~(-2 << n0xB)) >> n8_1; /*0xffe0717a*/
}


// Function: IoRead16 @ 0xffe0717f (0x1d bytes)

unsigned int __cdecl IoRead16(int a1, int a2, unsigned __int64 a3)
{
  int v3; // ecx

  return MmioRead16(a1, a2, v3, v3, a3); /*0xffe0719b*/
}


// Function: IoWrite16 @ 0xffe0719c (0x82 bytes)

unsigned int __cdecl IoWrite16(int a1, int a2, unsigned __int64 a3)
{
  int v3; // esi
  int v4; // eax
  int v5; // esi

  v3 = ReportStatusCode(a3) & 1; /*0xffe071b8*/
  if ( ReportStatusCode(a3) != v3 ) /*0xffe071c7*/
  {
    v4 = DebugPrintProtocol(); /*0xffe071cd*/
    if ( v4 ) /*0xffe071d4*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffe071e5*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\BitField.c",
        817,
        "RShiftU64 (OrData, EndBit - StartBit) == (RShiftU64 (OrData, EndBit - StartBit) & 1)");
  }
  v5 = ReportProgressCode((void *)8, a3); /*0xffe07202*/
  return a1 | v5 & ~(unsigned int)ReportProgressCode((void *)8, -2); /*0xffe0721a*/
}


// Function: MmioWrite16 @ 0xffe0721e (0x80 bytes)

unsigned int __cdecl MmioWrite16(int a1)
{
  __int64 v1; // rdi
  unsigned __int64 v2; // rax
  int v3; // eax
  int v4; // esi

  HIDWORD(v1) = ReportStatusCode(0) & 1; /*0xffe07234*/
  LODWORD(v1) = 0; /*0xffe07237*/
  v2 = ReportStatusCode(0); /*0xffe07239*/
  if ( __PAIR64__(v2, HIDWORD(v2)) != v1 ) /*0xffe07243*/
  {
    v3 = DebugPrintProtocol(); /*0xffe07249*/
    if ( v3 ) /*0xffe07250*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffe07261*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\BitField.c",
        869,
        "RShiftU64 (AndData, EndBit - StartBit) == (RShiftU64 (AndData, EndBit - StartBit) & 1)");
  }
  v4 = ReportProgressCode((void *)8, -1); /*0xffe0727c*/
  return a1 & ~(v4 & ~(unsigned int)ReportProgressCode((void *)8, -2)); /*0xffe0729a*/
}


// Function: MmioRead16 @ 0xffe0729e (0x27 bytes)

unsigned int __cdecl MmioRead16(int a1, int a2, int a3, int a4, unsigned __int64 a5)
{
  unsigned int v5; // eax
  int v6; // edx

  v5 = MmioWrite16(a1); /*0xffe072b1*/
  return IoWrite16(v5, v6, a5); /*0xffe072c4*/
}


// Function: ReportProgressCode @ 0xffe072c5 (0x42 bytes)

__int64 __thiscall ReportProgressCode(void *n8, __int64 a2)
{
  int v2; // eax
  __int64 v3; // rax
  char n8_1; // [esp+0h] [ebp-4h]

  n8_1 = (char)n8; /*0xffe072c9*/
  if ( (unsigned int)n8 >= 0x40 ) /*0xffe072cf*/
  {
    v2 = DebugPrintProtocol(); /*0xffe072d1*/
    if ( v2 ) /*0xffe072d8*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe072e6*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\LShiftU64.c",
        39,
        "Count < 64");
  }
  LODWORD(v3) = 0; /*0xffe072ef*/
  HIDWORD(v3) = a2; /*0xffe072f1*/
  if ( (n8_1 & 0x20) == 0 ) /*0xffe072f7*/
    v3 = a2; /*0xffe072f9*/
  return v3 << (n8_1 & 0x1F); /*0xffe07303*/
}


// Function: HobGetSize @ 0xffe07307 (0x5f bytes)

bool __fastcall HobGetSize(int this, int a2)
{
  __int64 v4; // rax
  int v5; // ebp
  __int64 v6; // rax
  int v7; // edi
  __int64 v8; // kr00_8
  __int64 v9; // rax
  int v11; // [esp+10h] [ebp-Ch]
  int v12; // [esp+14h] [ebp-8h]

  v4 = IoDelay((void *)this); /*0xffe07312*/
  v12 = HIDWORD(v4); /*0xffe07319*/
  v5 = v4; /*0xffe0731d*/
  v6 = IoDelay((void *)a2); /*0xffe0731f*/
  v11 = HIDWORD(v6); /*0xffe07327*/
  v7 = v6; /*0xffe0732b*/
  v8 = IoDelay((void *)(this + 8)); /*0xffe07339*/
  v9 = IoDelay((void *)(a2 + 8)); /*0xffe0733b*/
  return v5 == v7 && v12 == v11 && v8 == v9; /*0xffe0735e*/
}


// Function: HobGetType @ 0xffe07366 (0x41 bytes)

void *__fastcall HobGetType(void *buf, unsigned int n16)
{
  int v4; // eax

  if ( n16 - 1 > -1 - (int)buf ) /*0xffe07377*/
  {
    v4 = DebugPrintProtocol(); /*0xffe07379*/
    if ( v4 ) /*0xffe07380*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffe0738e*/
        "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\SetMemWrapper.c",
        54,
        "(Length - 1) <= (0xFFFFFFFF - (UINTN)Buffer)");
  }
  return memset(buf, n16, 255); /*0xffe073a3*/
}


// Function: HobStart @ 0xffe073a7 (0x6e bytes)

int HobStart()
{
  int v0; // eax
  int v1; // eax
  int v2; // eax
  int v3; // eax
  int v5; // [esp+4h] [ebp-4h] BYREF

  v0 = PeiServicesGet(); /*0xffe073ac*/
  v1 = (*(int (__cdecl **)(int, int *))(*(_DWORD *)v0 + 48))(v0, &v5); /*0xffe073b8*/
  if ( v1 < 0 ) /*0xffe073c4*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v1); /*0xffe073d1*/
    v2 = DebugPrintProtocol(); /*0xffe073d9*/
    if ( v2 ) /*0xffe073e0*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe073ea*/
        "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
        50,
        "!EFI_ERROR (Status)");
  }
  if ( !v5 ) /*0xffe073f4*/
  {
    v3 = DebugPrintProtocol(); /*0xffe073f6*/
    if ( v3 ) /*0xffe073fd*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffe07407*/
        "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
        51,
        "HobList != ((void *) 0)");
  }
  return v5; /*0xffe07410*/
}


// Function: HobEndCheck @ 0xffe07415 (0x45 bytes)

_WORD *__fastcall HobEndCheck(int a1, _WORD *i)
{
  _WORD *i_1; // esi
  int v3; // eax

  i_1 = i; /*0xffe07416*/
  if ( !i ) /*0xffe0741a*/
  {
    v3 = DebugPrintProtocol(); /*0xffe0741c*/
    if ( v3 ) /*0xffe07423*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffe07431*/
        "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
        82,
        "HobStart != ((void *) 0)");
  }
  while ( 1 ) /*0xffe0744a*/
  {
    if ( *i_1 == 0xFFFF ) /*0xffe07450*/
      return 0; /*0xffe07455*/
    if ( *i_1 == 4 ) /*0xffe07442*/
      break; /*0xffe07442*/
    i_1 = (_WORD *)((char *)i_1 + (unsigned __int16)i_1[1]); /*0xffe07448*/
  }
  return i_1; /*0xffe07454*/
}


// Function: GetNextGuidHob @ 0xffe0745a (0x33 bytes)

_WORD *__thiscall GetNextGuidHob(void *this)
{
  _WORD *i; // edx
  int v3; // ecx
  _WORD *v4; // eax
  _WORD *v5; // esi

  for ( i = (_WORD *)HobStart(); ; i = (_WORD *)((char *)v5 + (unsigned __int16)v5[1]) ) /*0xffe07464*/
  {
    v4 = HobEndCheck(v3, i); /*0xffe0747c*/
    v5 = v4; /*0xffe07481*/
    if ( !v4 || HobGetSize((int)this, (int)(v4 + 4)) ) /*0xffe0746d*/
      break; /*0xffe0746d*/
  }
  return v5; /*0xffe07487*/
}


// Function: DebugPrintProtocol @ 0xffe0748d (0x31 bytes)

int DebugPrintProtocol()
{
  int v0; // eax
  int v2; // [esp+0h] [ebp-8h] BYREF
  int v3; // [esp+4h] [ebp-4h] BYREF

  v0 = PeiServicesGet(); /*0xffe07492*/
  if ( (*(int (__cdecl **)(int, void *, _DWORD, int *, int *))(*(_DWORD *)v0 + 32))(v0, &unk_FFE08C50, 0, &v2, &v3) >= 0 ) /*0xffe074b1*/
    return v3; /*0xffe074b7*/
  else
    return 0; /*0xffe074b3*/
}


// Function: DebugPrint @ 0xffe074be (0x2a bytes)

int DebugPrint(int a1, int a2, ...)
{
  int result; // eax
  int (__cdecl **v3)(int, int, char *); // esi
  va_list va; // [esp+10h] [ebp+Ch] BYREF

  va_start(va, a2);
  result = DebugPrintProtocol(); /*0xffe074bf*/
  v3 = (int (__cdecl **)(int, int, char *))result; /*0xffe074c4*/
  if ( result ) /*0xffe074c8*/
  {
    result = DebugGetErrorLevel(); /*0xffe074ca*/
    if ( (result & a1) != 0 ) /*0xffe074d5*/
      return (*v3)(a1, a2, (char *)va); /*0xffe074e1*/
  }
  return result; /*0xffe074e6*/
}


// Function: PeiServicesAssert @ 0xffe074e8 (0x1e bytes)

int __fastcall PeiServicesAssert(
        int e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
        int n48,
        int PeiServices____((void__)_0))
{
  int result; // eax

  result = DebugPrintProtocol(); /*0xffe074ee*/
  if ( result ) /*0xffe074f5*/
    return (*(int (__cdecl **)(int, int, int))(result + 4))( /*0xffe074fd*/
             e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
             n48,
             PeiServices____((void__)_0));
  return result; /*0xffe07503*/
}


// Function: PeiPcdGet @ 0xffe07506 (0x58 bytes)

int __thiscall PeiPcdGet(void *this)
{
  int v1; // eax
  int v2; // eax
  int v3; // eax
  int v5; // [esp+0h] [ebp-4h] BYREF

  v1 = PeiServicesGet(); /*0xffe0750a*/
  v5 = (int)&v5; /*0xffe07512*/
  v2 = (*(int (__cdecl **)(int, void *, _DWORD, _DWORD))(*(_DWORD *)v1 + 32))(v1, &unk_FFE08CD0, 0, 0); /*0xffe0751f*/
  if ( v2 < 0 ) /*0xffe07527*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v2); /*0xffe07534*/
    v3 = DebugPrintProtocol(); /*0xffe0753c*/
    if ( v3 ) /*0xffe07543*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffe07551*/
        "e:\\hs\\MdePkg\\Library\\PeiPcdLib\\PeiPcdLib.c",
        49,
        "!EFI_ERROR (Status)");
  }
  return v5; /*0xffe0755c*/
}


// Function: ReadMsr64 @ 0xffe0757c (0x4b bytes)

unsigned int __fastcall ReadMsr64(unsigned int a1)
{
  unsigned int v1; // esi
  unsigned int n0x400000; // edi
  unsigned int v3; // ebx
  unsigned int result; // eax

  v1 = a1 >> 22; /*0xffe07589*/
  n0x400000 = a1 & 0x3FFFFF; /*0xffe0758c*/
  do /*0xffe075c0*/
  {
    v3 = n0x400000 + PsfRegisterRead((void *)0x508); /*0xffe0759a*/
    n0x400000 = 0x400000; /*0xffe0759d*/
    while ( ((v3 - PsfRegisterRead((void *)0x508)) & 0x800000) == 0 ) /*0xffe075b9*/
      _mm_pause(); /*0xffe075a4*/
    result = v1--; /*0xffe075bb*/
  }
  while ( result ); /*0xffe075c0*/
  return result; /*0xffe075c2*/
}


// Function: IoRead32 @ 0xffe075c7 (0x47 bytes)

unsigned int __fastcall IoRead32(unsigned int n0xA)
{
  unsigned __int64 v2; // rtt

  LODWORD(v2) = 3579545 * n0xA; /*0xffe075fd*/
  HIDWORD(v2) = ((3579545 * (unsigned __int64)n0xA) >> 32) % 0xF4240; /*0xffe075fd*/
  ReadMsr64(v2 / 0xF4240); /*0xffe07602*/
  return n0xA; /*0xffe07609*/
}


// Function: IoWrite32 @ 0xffe0760e (0x35 bytes)

bool __thiscall IoWrite32(void *this)
{
  unsigned int n4; // eax
  int p_this; // [esp+0h] [ebp-4h] BYREF

  p_this = (int)this; /*0xffe07611*/
  CpuRegRead(&p_this, 0, 0, 0); /*0xffe0761a*/
  n4 = IoWrite8(p_this, 8u, 0xBu); /*0xffe07627*/
  return n4 != 4 && n4 != 5; /*0xffe07641*/
}


// Function: ApicGetBaseAddr @ 0xffe07643 (0x4a bytes)

int __thiscall ApicGetBaseAddr(void *this)
{
  if ( IoWrite32(this) ) /*0xffe0764a*/
    return __readmsr(0x1Bu) & 0xFFFFF000; /*0xffe07686*/
  else
    return -18874368; /*0xffe07653*/
}


// Function: ApicWriteIcr @ 0xffe0768d (0xcc bytes)

int __fastcall ApicWriteIcr(void *a1, unsigned int n0xFF)
{
  void *v4; // ecx
  int v5; // eax
  __int16 v6; // kr00_2
  int BaseAddr; // ecx
  int v8; // edx
  __int64 v9; // rax

  if ( ApicGetBase(a1) == 1 ) /*0xffe076a2*/
  {
    if ( n0xFF > 0xFF ) /*0xffe076aa*/
    {
      v5 = DebugPrintProtocol(); /*0xffe076ac*/
      if ( v5 ) /*0xffe076b3*/
        (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffe076c4*/
          "e:\\hs\\UefiCpuPkg\\Library\\BaseXApicX2ApicLib\\BaseXApicX2ApicLib.c",
          260,
          "ApicId <= 0xff");
    }
    v6 = __readeflags(); /*0xffe076ca*/
    _disable(); /*0xffe076cc*/
    BaseAddr = ApicGetBaseAddr(v4); /*0xffe076da*/
    v8 = *(_DWORD *)(BaseAddr + 784); /*0xffe076e1*/
    while ( (*(_DWORD *)(BaseAddr + 768) & 0x1000) != 0 ) /*0xffe076ef*/
      ; /*0xffe076e7*/
    *(_DWORD *)(BaseAddr + 784) = n0xFF << 24; /*0xffe076f4*/
    *(_DWORD *)(BaseAddr + 768) = a1; /*0xffe076fa*/
    do /*0xffe07708*/
      LODWORD(v9) = *(_DWORD *)(BaseAddr + 768); /*0xffe07700*/
    while ( (v9 & 0x1000) != 0 ); /*0xffe07708*/
    *(_DWORD *)(BaseAddr + 784) = v8; /*0xffe0770e*/
    if ( (v6 & 0x200) != 0 ) /*0xffe07714*/
      _enable(); /*0xffe07716*/
    else
      _disable(); /*0xffe07719*/
  }
  else
  {
    v9 = (unsigned int)a1; /*0xffe07748*/
    __writemsr(0x830u, (unsigned int)a1); /*0xffe07750*/
  }
  return v9; /*0xffe07752*/
}


// Function: ApicGetBase @ 0xffe07759 (0x51 bytes)

int __thiscall ApicGetBase(void *this)
{
  unsigned __int64 v2; // rax
  __int16 v3; // si
  int v4; // eax

  if ( !IoWrite32(this) ) /*0xffe0775b*/
    return 1; /*0xffe07766*/
  v2 = __readmsr(0x1Bu); /*0xffe0776f*/
  v3 = v2; /*0xffe07771*/
  if ( (v2 & 0x800) == 0 ) /*0xffe07779*/
  {
    v4 = DebugPrintProtocol(); /*0xffe0777b*/
    if ( v4 ) /*0xffe07782*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffe07793*/
        "e:\\hs\\UefiCpuPkg\\Library\\BaseXApicX2ApicLib\\BaseXApicX2ApicLib.c",
        343,
        "ApicBaseMsr.Bits.EN != 0");
  }
  return ((v3 & 0x400) != 0) + 1; /*0xffe077a9*/
}


// Function: CacheEnable @ 0xffe077aa (0x91 bytes)

int __fastcall CacheEnable(unsigned int n0x100000)
{
  int v2; // eax
  int v3; // eax
  void *v4; // esi

  if ( n0x100000 >= 0x100000 ) /*0xffe077ba*/
  {
    v2 = DebugPrintProtocol(); /*0xffe077bc*/
    if ( v2 ) /*0xffe077c3*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe077d0*/
        "e:\\hs\\UefiCpuPkg\\Library\\BaseXApicX2ApicLib\\BaseXApicX2ApicLib.c",
        675,
        "StartupRoutine < 0x100000");
  }
  if ( (n0x100000 & 0xFFF) != 0 ) /*0xffe077dc*/
  {
    v3 = DebugPrintProtocol(); /*0xffe077de*/
    if ( v3 ) /*0xffe077e5*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffe077f2*/
        "e:\\hs\\UefiCpuPkg\\Library\\BaseXApicX2ApicLib\\BaseXApicX2ApicLib.c",
        676,
        "(StartupRoutine & 0xfff) == 0");
  }
  ApicWriteIcr((void *)0xC4500, 0); /*0xffe077ff*/
  IoRead32(0xAu); /*0xffe07807*/
  v4 = (void *)((n0x100000 & 0xFF000 | 0xC4600FFF) >> 12); /*0xffe0781a*/
  ApicWriteIcr(v4, 0); /*0xffe0781f*/
  IoRead32(0xC8u); /*0xffe07829*/
  return ApicWriteIcr(v4, 0); /*0xffe07837*/
}


// Function: DwrCheck @ 0xffe0783b (0x4d bytes)

bool DwrCheck()
{
  int v0; // eax
  unsigned int v2; // [esp+4h] [ebp-4h] BYREF

  v2 = 0; /*0xffe07840*/
  PsfGrantCountConfig(&v2); /*0xffe07847*/
  if ( !v2 ) /*0xffe07851*/
  {
    v0 = DebugPrintProtocol(); /*0xffe07853*/
    if ( v0 ) /*0xffe0785a*/
      (*(void (__cdecl **)(const char *, int, const char *))(v0 + 4))( /*0xffe0786b*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchPmcLib\\PchPmcLib.c",
        162,
        "PchPwrmBase != 0");
    return 0; /*0xffe0786b*/
  }
  return (*(_DWORD *)(v2 + 300) & 0x8000) != 0; /*0xffe07882*/
}


// Function: DebugGetErrorLevel @ 0xffe07888 (0x4f bytes)

int DebugGetErrorLevel()
{
  unsigned __int8 v0; // al
  char n3; // al
  char n3_1; // cl

  v0 = __inbyte(0x70u); /*0xffe0788e*/
  __outbyte(0x70u, v0 & 0x80 | 0x4A); /*0xffe07893*/
  n3 = __inbyte(0x71u); /*0xffe0789a*/
  n3_1 = n3; /*0xffe0789b*/
  if ( (unsigned __int8)n3 <= 3u ) /*0xffe078a0*/
  {
LABEL_4:
    if ( !n3_1 ) /*0xffe078bb*/
      return 0; /*0xffe078bb*/
    goto LABEL_5; /*0xffe078bb*/
  }
  n3_1 = n3; /*0xffe078a2*/
  if ( !n3 ) /*0xffe078aa*/
  {
    n3_1 = MEMORY[0xFDAF0490] & 2 | 1; /*0xffe078b6*/
    goto LABEL_4; /*0xffe078b6*/
  }
LABEL_5:
  if ( n3_1 != -1 )
    return n3_1 != 1 ? -2147483578 : -2147483644;
  return 0; /*0xffe078d3*/
}


// Function: PsfGrantCountConfig @ 0xffe078d7 (0x8e bytes)

int __thiscall PsfGrantCountConfig(unsigned int *this)
{
  int v2; // eax
  int v4; // edi
  int v5; // eax

  if ( this ) /*0xffe078de*/
  {
    v4 = PciCfgRead(); /*0xffe0791d*/
    if ( (unsigned __int16)PsfTgtConfig((unsigned __int16 *)v4) == 0xFFFF ) /*0xffe0792e*/
    {
      v5 = DebugPrintProtocol(); /*0xffe07930*/
      if ( v5 ) /*0xffe07937*/
        (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffe07948*/
          "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchCycleDecodingLib\\PchCycleDecodingLib.c",
          303,
          "((BOOLEAN)(0==1))");
      return -2147483645; /*0xffe0794e*/
    }
    else
    {
      *this = *(_DWORD *)(v4 + 72) & 0xFFFF0000; /*0xffe0795d*/
      return 0; /*0xffe0795f*/
    }
  }
  else
  {
    DebugPrint(0x80000000, (int)"PchPwrmBaseGet Error. Invalid pointer.\n"); /*0xffe078ea*/
    v2 = DebugPrintProtocol(); /*0xffe078f1*/
    if ( v2 ) /*0xffe078f8*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe07909*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchCycleDecodingLib\\PchCycleDecodingLib.c",
        293,
        "((BOOLEAN)(0==1))");
    return -2147483646; /*0xffe0790f*/
  }
}


// Function: PciCfgRead @ 0xffe07965 (0x35 bytes)

int __cdecl PciCfgRead()
{
  _DWORD v1[4]; // [esp+4h] [ebp-18h] BYREF
  int v2; // [esp+14h] [ebp-8h] BYREF

  v1[2] = 512; /*0xffe0796e*/
  v1[0] = 1024000; /*0xffe07978*/
  v1[3] = 0; /*0xffe07982*/
  v1[1] = 0; /*0xffe07988*/
  CheckFeature(0, 0, v1, &v2); /*0xffe0798b*/
  return v2; /*0xffe07996*/
}


// Function: IoDelay @ 0xffe0799a (0x2c bytes)

__int64 __thiscall IoDelay(void *this)
{
  int v2; // eax

  if ( !this ) /*0xffe0799f*/
  {
    v2 = DebugPrintProtocol(); /*0xffe079a1*/
    if ( v2 ) /*0xffe079a8*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe079b9*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
        192,
        "Buffer != ((void *) 0)");
  }
  return *(_QWORD *)this; /*0xffe079c4*/
}


// Function: PsfRegisterRead @ 0xffe079e3 (0x12 bytes)

unsigned int __thiscall PsfRegisterRead(void *n1288)
{
  unsigned __int32 v1; // eax

  v1 = PsfRegisterWrite(n1288); /*0xffe079e5*/
  return IoWrite8(v1, 0, 0x17u); /*0xffe079f4*/
}


// Function: PsfTgtConfig @ 0xffe079f5 (0x2e bytes)

int __fastcall PsfTgtConfig(unsigned __int16 *a1)
{
  int v2; // eax

  if ( ((unsigned __int8)a1 & 1) != 0 ) /*0xffe079fb*/
  {
    v2 = DebugPrintProtocol(); /*0xffe079fd*/
    if ( v2 ) /*0xffe07a04*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe07a15*/
        "e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLib.c",
        151,
        "(Address & 1) == 0");
  }
  return *a1; /*0xffe07a21*/
}


// Function: PsfRegisterWrite @ 0xffe07a53 (0x2c bytes)

unsigned __int32 __thiscall PsfRegisterWrite(void *n1288)
{
  unsigned __int16 n1288_1; // bx
  int v2; // eax

  n1288_1 = (unsigned __int16)n1288; /*0xffe07a54*/
  if ( ((unsigned __int8)n1288 & 3) != 0 ) /*0xffe07a59*/
  {
    v2 = DebugPrintProtocol(); /*0xffe07a5b*/
    if ( v2 ) /*0xffe07a62*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe07a73*/
        "e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLibMsc.c",
        193,
        "(Port & 3) == 0");
  }
  return __indword(n1288_1); /*0xffe07a7d*/
}


// Function: PeiServicesGet @ 0xffe07a7f (0x32 bytes)

int __stdcall PeiServicesGet()
{
  int v0; // esi
  _BYTE v2[8]; // [esp+4h] [ebp-8h] BYREF

  PeiGetServiceFromIdt(v2); /*0xffe07a88*/
  v0 = *(_DWORD *)(*(_DWORD *)&v2[2] - 4); /*0xffe07a90*/
  if ( !v0 ) /*0xffe07a95*/
    PeiServicesAssert( /*0xffe07aa4*/
      (int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
      48,
      (int)"PeiServices != ((void *) 0)");
  return v0; /*0xffe07aac*/
}


// Function: CheckFeature @ 0xffe07ab1 (0x1e bytes)

int *__cdecl CheckFeature(int a1, int a2, _DWORD *a3, int *a4)
{
  int v4; // ecx

  v4 = CachePagingSetup((int)a3) + (*a3 & 0xFFFFFFF); /*0xffe07ac5*/
  *a4 = v4; /*0xffe07acc*/
  return a4; /*0xffe07acb*/
}


// Function: SetFeatureBit @ 0xffe07adb (0x11 bytes)

int __thiscall SetFeatureBit(void *this)
{
  int v1; // ebx
  int v2; // eax

  v1 = CpuIdViaPeiService(this) + 1024064; /*0xffe07a24*/
  if ( (v1 & 1) != 0 ) /*0xffe07a29*/
  {
    v2 = DebugPrintProtocol(); /*0xffe07a2b*/
    if ( v2 ) /*0xffe07a32*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffe07a43*/
        "e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLib.c",
        183,
        "(Address & 1) == 0");
  }
  *(_WORD *)v1 = 1280; /*0xffe07a4e*/
  return 1280; /*0xffe07a52*/
}


// Function: PeiGetServiceFromIdt @ 0xffe07aec (0x23 bytes)

void *__thiscall PeiGetServiceFromIdt(void *this)
{
  void *this_1; // eax

  if ( !this ) /*0xffe07af2*/
    PeiServicesAssert((int)"e:\\hs\\MdePkg\\Library\\BaseLib\\X86ReadIdtr.c", 37, (int)"Idtr != ((void *) 0)"); /*0xffe07b01*/
  this_1 = this; /*0xffe07b07*/
  __sidt(this); /*0xffe07b0a*/
  return this_1; /*0xffe07b0e*/
}


// Function: CacheRegionSetup @ 0xffe07b0f (0x9b bytes)

int __cdecl CacheRegionSetup(_DWORD *a1, int n8)
{
  int Version; // [esp+Ch] [ebp-4h]

  Version = CpuGetVersion((void *)6); /*0xffe07b3f*/
  a1[1] = 16 * n8 + 16; /*0xffe07b48*/
  if ( !a1[4] && !a1[5] ) /*0xffe07b64*/
  {
    *(_DWORD *)(Version + 16) = CpuGetApicId((void *)5); /*0xffe07b89*/
    *(_DWORD *)(Version + 20) = 0; /*0xffe07ba0*/
  }
  return 0; /*0xffe07ba6*/
}


// Function: CachePagingSetup @ 0xffe07baa (0x17e bytes)

int __cdecl CachePagingSetup(int a1)
{
  int Version; // [esp+Ch] [ebp-Ch]
  int v3; // [esp+10h] [ebp-8h]
  int ApicId; // [esp+14h] [ebp-4h]

  if ( *(_DWORD *)(a1 + 12) ) /*0xffe07bbf*/
  {
    v3 = *(_DWORD *)(*(_DWORD *)(a1 + 12) + 4 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 255544); /*0xffe07cb5*/
    ApicId = *(_DWORD *)(*(_DWORD *)(a1 + 12) + 4 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 255560); /*0xffe07cd1*/
  }
  else
  {
    Version = CpuGetVersion((void *)6); /*0xffe07bd2*/
    if ( *(_DWORD *)(Version + 4) ) /*0xffe07bd8*/
    {
      v3 = *(_DWORD *)(Version + 16 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 20); /*0xffe07bf3*/
      ApicId = *(_DWORD *)(Version + 16 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 16); /*0xffe07c0b*/
    }
    else
    {
      CacheRegionSetup(dword_FFE08D30, 8); /*0xffe07c1e*/
      v3 = dword_FFE08D44[4 * (unsigned __int16)*(_DWORD *)(a1 + 4)]; /*0xffe07c39*/
      ApicId = dword_FFE08D40[4 * (unsigned __int16)*(_DWORD *)(a1 + 4)]; /*0xffe07c50*/
      if ( !ApicId && !v3 ) /*0xffe07c5d*/
      {
        ApicId = CpuGetApicId((void *)5); /*0xffe07c8a*/
        v3 = 0; /*0xffe07c97*/
      }
    }
  }
  if ( !ApicId && !v3 ) /*0xffe07cde*/
    return CpuGetApicId((void *)5); /*0xffe07d0b*/
  return ApicId; /*0xffe07d24*/
}


// Function: BiosAcmInvoke @ 0xffe07d30 (0x2b3 bytes)

void __usercall BiosAcmInvoke(__m64 a1@<mm3>, unsigned int n5)
{
  unsigned int v2; // kr00_4
  unsigned __int64 v3; // rax
  int v4; // ecx
  unsigned int v5; // ecx
  __m64 v6; // mm0
  __m64 v7; // mm2
  unsigned __int32 v8; // eax
  unsigned __int32 v9; // eax
  unsigned __int64 v10; // rax
  int v11; // ecx
  unsigned int v12; // ecx
  unsigned int v13; // ebx
  int n4096; // eax
  __m128i v15; // xmm2
  __m128i v16; // xmm0
  __m128i i; // xmm1
  unsigned int v18; // eax
  unsigned int v19; // ecx
  unsigned int v20; // edx
  unsigned int v21; // ecx
  __m128i v22; // xmm3
  unsigned __int64 v23; // rax
  int v24; // ebx
  unsigned __int64 v25; // rax
  unsigned __int32 v26; // eax
  unsigned __int64 v27; // rax
  int v28; // ebx
  unsigned int j; // ecx
  int n5_1; // ebx
  char *v31; // ebx
  _BYTE v32[8]; // [esp+0h] [ebp-10h] BYREF
  _BYTE v33[8]; // [esp+8h] [ebp-8h] BYREF
  _BYTE retaddr[8]; // [esp+14h] [ebp+4h]

  v2 = __readeflags(); /*0xffe07d36*/
  if ( *(_DWORD *)&retaddr[4] ) /*0xffe07d3c*/
  {
    if ( n5 && n5 != 5 ) /*0xffe07d4c*/
    {
      __sgdt(v33); /*0xffe07d4e*/
      __sidt(v32); /*0xffe07d52*/
      a1 = _mm_cvtsi32_si64((unsigned int)v33); /*0xffe07d59*/
      __readcr4(); /*0xffe07d69*/
      __readcr0(); /*0xffe07d6d*/
      __readmsr(0x1A0u); /*0xffe07d76*/
      v3 = __readmsr(0xFEu); /*0xffe07d7f*/
      v4 = 2 * (unsigned __int8)v3; /*0xffe07d88*/
      do /*0xffe07d9a*/
      {
        v5 = v4 + 511; /*0xffe07d8a*/
        __readmsr(v5); /*0xffe07d90*/
        v4 = v5 - 512; /*0xffe07d9a*/
      }
      while ( v4 ); /*0xffe07d9a*/
      __readmsr(0x2FFu); /*0xffe07da1*/
    }
    v6 = _mm_cvtsi32_si64(*(unsigned int *)&retaddr[4]); /*0xffe07dc9*/
    v7 = _mm_cvtsi32_si64(n5); /*0xffe07dcf*/
    v8 = __readcr4(); /*0xffe07dd2*/
    __writecr4(v8 | 0x4208); /*0xffe07dda*/
    v9 = __readcr0(); /*0xffe07ddd*/
    __writecr0(v9 & 0x9FFFFFDF | 0x40000020); /*0xffe07dea*/
    if ( _mm_cvtsi64_si32(v7) != 6 ) /*0xffe07df3*/
      __asm { invd } /*0xffe07e00*/
    __writemsr(0x2FFu, 0); /*0xffe07e0b*/
    v10 = __readmsr(0xFEu); /*0xffe07e12*/
    v11 = 2 * (unsigned __int8)v10; /*0xffe07e1b*/
    do /*0xffe07e2f*/
    {
      v12 = v11 + 511; /*0xffe07e21*/
      __writemsr(v12, 0); /*0xffe07e27*/
      v11 = v12 - 512; /*0xffe07e2f*/
    }
    while ( v11 ); /*0xffe07e2f*/
    v13 = _mm_cvtsi64_si32(v6); /*0xffe07e31*/
    n4096 = (4 * *(_DWORD *)(v13 + 24)) & 0xFFF; /*0xffe07e44*/
    if ( n4096 ) /*0xffe07e49*/
      n4096 = 4096; /*0xffe07e4b*/
    v15 = _mm_cvtsi32_si128(0); /*0xffe07e54*/
    v16 = _mm_cvtsi32_si128(((4 * *(_DWORD *)(v13 + 24)) & 0xFFFFF000) + n4096); /*0xffe07e58*/
    for ( i = _mm_cvtsi32_si128(v13); ; i = _mm_cvtsi32_si128(_mm_cvtsi128_si32(v22) + _mm_cvtsi128_si32(i)) ) /*0xffe07e5c*/
    {
      v18 = _mm_cvtsi128_si32(v16); /*0xffe07e60*/
      if ( !v18 ) /*0xffe07e66*/
        break; /*0xffe07e66*/
      _BitScanForward(&v19, _mm_cvtsi128_si32(i)); /*0xffe07e6c*/
      v20 = 1 << v19; /*0xffe07e74*/
      if ( 1 << v19 > v18 ) /*0xffe07e78*/
      {
        _BitScanReverse(&v21, v18); /*0xffe07e7a*/
        v20 = 1 << v21; /*0xffe07e82*/
      }
      v22 = _mm_cvtsi32_si128(v20); /*0xffe07e86*/
      LODWORD(v23) = ~(v20 - 1) | 0x800; /*0xffe07e8d*/
      v24 = _mm_cvtsi128_si32(v15); /*0xffe07e97*/
      HIDWORD(v23) = 15; /*0xffe07e9d*/
      __writemsr(v24 + 513, v23); /*0xffe07ea2*/
      v25 = (unsigned int)_mm_cvtsi128_si32(i); /*0xffe07ead*/
      LODWORD(v25) = v25 | 6; /*0xffe07eb1*/
      __writemsr(v24 + 512, v25); /*0xffe07eb4*/
      v16 = _mm_cvtsi32_si128(_mm_cvtsi128_si32(v16) - _mm_cvtsi128_si32(v22)); /*0xffe07ec0*/
      v15 = _mm_cvtsi32_si128(v24 + 2); /*0xffe07ecb*/
    }
    __writemsr(0x2FFu, 0x800u); /*0xffe07eeb*/
    v26 = __readcr0(); /*0xffe07eed*/
    __writecr0(v26 & 0xBFFFFFFF); /*0xffe07ef5*/
    v27 = __readmsr(0x179u); /*0xffe07efd*/
    v28 = (unsigned __int8)v27; /*0xffe07eff*/
    for ( j = 1025; ; j += 4 ) /*0xffe07f06*/
    {
      __writemsr(j, 0); /*0xffe07f0b*/
      if ( !--v28 ) /*0xffe07f0e*/
        break; /*0xffe07f0e*/
    }
    __asm { getsec } /*0xffe07f2c*/
    n5_1 = _mm_cvtsi64_si32(v7); /*0xffe07f2e*/
    if ( n5_1 && n5_1 != 5 ) /*0xffe07f3c*/
    {
      v31 = (char *)_mm_cvtsi64_si32(a1); /*0xffe07f42*/
      __lgdt(v31); /*0xffe07f45*/
      __lidt(v31 - 8); /*0xffe07f48*/
      __asm { retf } /*0xffe07f5c*/
    }
    __outbyte(0xCF9u, 0xAu); /*0xffe07fd9*/
    __outbyte(0xCF9u, 6u); /*0xffe07fe0*/
    while ( 1 ) /*0xffe07fe1*/
      ; /*0xffe07fe1*/
  }
  __writeeflags(v2); /*0xffe07fce*/
  _m_empty(); /*0xffe07fcf*/
}