Newer
Older
AMI-Aptio-BIOS-Reversed / MePolicyInitPei / MePolicyInitPei.c
@Ajax Dong Ajax Dong 2 days ago 37 KB Init
/*
 *MePolicyInitPei.c
 *MePolicyInitPei PEI module decompiled from IDA
 */

#include "MePolicyInitPei.h"

// InternalMemSetMem @ 0xffde505c void *InternalMemSetMem(void *buf, unsigned int count, char value)
{
 memset(buf, value, count); /*0xffde5069*/
 return buf; /*0xffde506f*/
}

// InternalMemCopyMem @ 0xffde507c char *InternalMemCopyMem(char *dst, char *src, unsigned int count)
{
 unsigned int count_1; // edx char *dst_1; // edi char *src_1; // esi count_1 = count; /*0xffde5086*/
 if ( src < dst && &src[count - 1] >= dst ) /*0xffde5094*/
 {
 src_1 = &src[count - 1]; /*0xffde50a8*/
 dst_1 = &dst[count - 1]; /*0xffde50aa*/
 }
 else
 {
 count_1 = count & 3; /*0xffde5098*/
 qmemcpy(dst, src, 4 * (count >> 2)); /*0xffde50a1*/
 src_1 = &src[4 * (count >> 2)]; /*0xffde50a1*/
 dst_1 = &dst[4 * (count >> 2)]; /*0xffde50a1*/
 }
 qmemcpy(dst_1, src_1, count_1); /*0xffde50b1*/
 return dst; /*0xffde50b8*/
}

// InternalMemZeroMem @ 0xffde50bc void *InternalMemZeroMem(void *buf, unsigned int count)
{
 memset(buf, 0, count); /*0xffde50d3*/
 return buf; /*0xffde50da*/
}

// InternalMemSetMem32_Worker @ 0xffde50dc int InternalMemSetMem32_Worker(int a1, int a2, int a3, int a4)
{
 do /*0xffde50f5*/
 {
 *(_DWORD *)(a1 + 8 *a2 - 8) = a3; /*0xffde50ed*/
 *(_DWORD *)(a1 + 8 *a2-- - 4) = a4; /*0xffde50f1*/
 }
 while ( a2 ); /*0xffde50f5*/
 return a1; /*0xffde50f9*/
}

// InternalMemSetMem32 @ 0xffde50fc void *InternalMemSetMem32(void *buf, unsigned int count, int value)
{
 memset32(buf, value, count); /*0xffde5109*/
 return buf; /*0xffde510f*/
}

// MePolicyInitPeiEntryPoint @ 0xffde5111 EFI_STATUS MePolicyInitPeiEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
 EFI_PEI_SERVICES **ZeroedPool; // eax EFI_PEI_SERVICES **ZeroedPool_1; // edi int DebugLibInstance; // eax int ErrorLevel; // eax signed __int32 Buffer; // eax int updated; // eax signed __int32 Status; // eax EFI_STATUS Status; // edi int ErrorLevel; // eax DebugPrintWorker(64, (int)"[ME Policy] MePolicyInitPeiEntryPoint\n"); /*0xffde5127*/
 ZeroedPool = (EFI_PEI_SERVICES **)AllocateZeroedPool(0x14u); /*0xffde5131*/
 ZeroedPool_1 = ZeroedPool; /*0xffde5136*/
 if ( ZeroedPool )
 {
 *ZeroedPool = (EFI_PEI_SERVICES *)1; /*0xffde518d*/
 InitMePolicyDefaults(ZeroedPool + 1); /*0xffde5193*/
 Buffer = InstallMePolicyPpi(ZeroedPool_1); /*0xffde519a*/
 if ( Buffer < 0 )
 DebugPrintWorker(0x80000000, (int)"[ME Policy] ERROR: Cannot install ME Policy PPI (%r)\n", Buffer);
 updated = UpdateMePolicyFromMeVariable(ZeroedPool_1); /*0xffde51b9*/
 if ( updated < 0 )
 DebugPrintWorker(0x80000000, (int)"[ME Policy] ERROR: ME Policy update failed (%r)\n", updated);
 }
 else
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde5141*/
 if ( DebugLibInstance ) /*0xffde5148*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde5156*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\AMT\\Library\\PeiMePolicyLib\\PeiMePolicyLib.c",
 47,
 "((BOOLEAN)(0==1))");
 DebugPrintWorker(0x80000000, (int)"[ME Policy] ERROR: Cannot create ME Policy PPI (%r)\n", -2147483639);
 ErrorLevel = GetDebugLibInstance(); /*0xffde5174*/
 if ( ErrorLevel ) /*0xffde517b*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffde5185*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\Pei\\MePolicyInitPei.c",
 74,
 "MePolicyPpi != ((void *) 0)");
 }
 Status = InstallSpsPolicyPpi((EFI_PEI_SERVICES **)SystemTable); /*0xffde51d3*/
 Status = Status; /*0xffde51d8*/
 if ( Status < 0 ) /*0xffde51dc*/
 {
 DebugPrintWorker(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffde51e5*/
 ErrorLevel = GetDebugLibInstance(); /*0xffde51ed*/
 if ( ErrorLevel ) /*0xffde51f4*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffde51fe*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\Pei\\MePolicyInitPei.c",
 120,
 "!EFI_ERROR (Status)");
 }
 DumpAllMePolicies(); /*0xffde5204*/
 return Status; /*0xffde520f*/
}

// GetDebugLibInstance @ 0xffde5210 int GetDebugLibInstance()
{
 int PeiServicesTable; // eax int v2; // [esp+0h] [ebp-8h] BYREF int Result; // [esp+4h] [ebp-4h] BYREF PeiServicesTable = GetPeiServicesTable(); /*0xffde5215*/
 if ( (*(int ( **)(int, void *, _DWORD, int *, int *))(*(_DWORD *)PeiServicesTable + 32))( /*0xffde5234*/
 PeiServicesTable,
 &unk_FFDE79BC,
 0,
 &v2,
 &Result) >= 0 )
 return Result; /*0xffde523a*/
 else return 0; /*0xffde5236*/
}

// DebugPrintWorker @ 0xffde5241 int DebugPrintWorker(int a1, int a2, ...)
{
 int result; // eax int ( **v3)(int, int, char *); // esi va_list va; // [esp+10h] [ebp+Ch] BYREF va_start(va, a2);
 result = GetDebugLibInstance(); /*0xffde5242*/
 v3 = (int ( **)(int, int, char *))result; /*0xffde5247*/
 if ( result ) /*0xffde524b*/
 {
 result = DetectMeType(); /*0xffde524d*/
 if ( (result & a1) != 0 ) /*0xffde5258*/
 return (*v3)(a1, a2, (char *)va); /*0xffde5264*/
 }
 return result; /*0xffde5269*/
}

// DebugAssertWorker @ 0xffde526b int DebugAssertWorker(
 int e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
 int n48,
 int PeiServices____((void__)_0))
{
 int result; // eax result = GetDebugLibInstance(); /*0xffde5271*/
 if ( result ) /*0xffde5278*/
 return (*(int ( **)(int, int, int))(result + 4))( /*0xffde5280*/
 e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
 n48,
 PeiServices____((void__)_0));
 return result; /*0xffde5286*/
}

// InstallMePolicyPpi @ 0xffde5289 EFI_STATUS __thiscall InstallMePolicyPpi(EFI_PEI_SERVICES **PeiServices)
{
 _DWORD *MePolicyData; // eax _DWORD *MePolicyData_1; // esi int Status; // eax int PeiServicesTable; // eax int Status; // eax EFI_STATUS Status; // esi int DebugLib; // eax MePolicyData = AllocateZeroedPool(0xCu); /*0xffde5290*/
 MePolicyData_1 = MePolicyData; /*0xffde5295*/
 if ( MePolicyData ) /*0xffde5299*/
 {
 *MePolicyData = -2147483632; /*0xffde52bd*/
 MePolicyData[1] = &unk_FFDE79FC; /*0xffde52c3*/
 MePolicyData[2] = PeiServices; /*0xffde52ca*/
 PeiServicesTable = GetPeiServicesTable(); /*0xffde52cd*/
 Status = (*(int ( **)(int, _DWORD *))(*(_DWORD *)PeiServicesTable + 24))(PeiServicesTable, MePolicyData_1); /*0xffde52d6*/
 Status = Status; /*0xffde52d9*/
 if ( Status < 0 ) /*0xffde52df*/
 {
 DebugPrintWorker(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffde52fc*/
 DebugLib = GetDebugLibInstance(); /*0xffde5304*/
 if ( DebugLib ) /*0xffde530b*/
 (*(void ( **)(const char *, int, const char *))(DebugLib + 4))( /*0xffde5319*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\AMT\\Library\\PeiMePolicyLib\\PeiMePolicyLib.c",
 102,
 "!EFI_ERROR (Status)");
 }
 else
 {
 DebugPrintWorker(64, (int)"[ME] ME Policy PPI Installed\n"); /*0xffde52e8*/
 }
 return Status; /*0xffde531f*/
 }
 else
 {
 Status = GetDebugLibInstance(); /*0xffde529b*/
 if ( Status ) /*0xffde52a2*/
 (*(void ( **)(const char *, int, const char *))(Status + 4))( /*0xffde52b0*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\AMT\\Library\\PeiMePolicyLib\\PeiMePolicyLib.c",
 83,
 "((BOOLEAN)(0==1))");
 return -2147483639; /*0xffde52b6*/
 }
}

// DumpSpsConfigPolicy @ 0xffde5324 int DumpSpsConfigPolicy(int SpsPolicy, int a2)
{
 DebugPrintWorker(64, (int)"SPS Config Revision : %d\n", *(_DWORD *)a2);
 DebugPrintWorker(64, (int)" SpsAltitude : 0x%x\n", *(unsigned __int16 *)(a2 + 4));
 DebugPrintWorker(64, (int)" SpsMctpBusOwner : 0x%x\n", *(unsigned __int16 *)(a2 + 6));
 DebugPrintWorker(64, (int)" PreDidMeResetEnabled : 0x%x\n", *(_DWORD *)(a2 + 8) & 1);
 DebugPrintWorker(64, (int)" Heci1HideInMe : %d\n", (*(_DWORD *)(a2 + 8) >> 1) & 3);
 DebugPrintWorker(64, (int)" Heci2HideInMe : %d\n", (*(_DWORD *)(a2 + 8) >> 3) & 3);
 DebugPrintWorker(64, (int)" Heci3HideInMe : %d\n", (*(_DWORD *)(a2 + 8) >> 5) & 3);
 DebugPrintWorker(64, (int)" NmPwrOptBoot : %d\n", *(_DWORD *)(a2 + 12) & 1);
 DebugPrintWorker(64, (int)" NmCores2Disable : %d\n", (*(_DWORD *)(a2 + 12) >> 1) & 0x7F);
 DebugPrintWorker(64, (int)" MeHmrfpoEnableEnabled : %d\n", (*(_DWORD *)(a2 + 16) >> 9) & 1);
 DebugPrintWorker(64, (int)" MeHmrfpoLockEnabled : %d\n", (*(_DWORD *)(a2 + 16) >> 8) & 1);
 DebugPrintWorker(64, (int)" NmPwrOptBootOverride : %d\n", (*(_DWORD *)(a2 + 16) >> 15) & 1);
 DebugPrintWorker(64, (int)" NmCores2DisableOverride : %d\n", *(_WORD *)(a2 + 18) & 1);
 DebugPrintWorker(64, (int)" NmPowerMsmtOverride : %d\n", (*(_DWORD *)(a2 + 16) >> 17) & 1);
 DebugPrintWorker(64, (int)" NmPowerMsmtSupport : %d\n", (*(_DWORD *)(a2 + 16) >> 18) & 1);
 DebugPrintWorker(64, (int)" NmHwChangeOverride : %d\n", (*(_DWORD *)(a2 + 16) >> 19) & 1);
 DebugPrintWorker(64, (int)" NmHwChangeStatus : %d\n", (*(_DWORD *)(a2 + 16) >> 20) & 1);
 DebugPrintWorker(64, (int)" NmPtuLoadOverride : %d\n", (*(_DWORD *)(a2 + 16) >> 21) & 1);
 DebugPrintWorker(64, (int)" MeGrLockEnabled : %d\n", (*(_DWORD *)(a2 + 16) >> 10) & 1);
 DebugPrintWorker(64, (int)" MeGrPromotionEnabled : %d\n", (*(_DWORD *)(a2 + 16) >> 11) & 1);
 return DebugPrintWorker(64, (int)" BreakRtcEnabled : %d\n", (*(_DWORD *)(a2 + 16) >> 12) & 1);
}

// DumpAllMePolicies @ 0xffde54ce EFI_STATUS DumpAllMePolicies()
{
 int PeiServices; // eax int MeStatus; // eax int SpsStatus; // eax int ErrorLevel; // eax int SpsPolicy; // ecx _DWORD *PpiOutput; // [esp+Ch] [ebp-4h] BYREF DebugPrintWorker(64, (int)"\n---------------------- MePolicyPpi Dump Begin -----------------\n"); /*0xffde54de*/
 PeiServices = GetPeiServicesTable(); /*0xffde54e3*/
 MeStatus = (*(int ( **)(int, void *, _DWORD, _DWORD, _DWORD **))(*(_DWORD *)PeiServices + 32))( /*0xffde54f8*/
 PeiServices,
 &unk_FFDE79FC,
 0,
 0,
 &PpiOutput);
 if ( MeStatus >= 0 )
 DumpMePolicyPpi(PpiOutput); /*0xffde551b*/
 else DebugPrintWorker(0x80000000, (int)"[SPS] ERROR: ME Policy PPI not found (%r)\n", MeStatus);
 DebugPrintWorker(64, (int)"\n---------------------- MePolicyPpi Dump End -------------------\n"); /*0xffde5526*/
 DebugPrintWorker(64, (int)"\n---------------------- SpsPolicyPpi Dump Begin ----------------\n"); /*0xffde5531*/
 SpsStatus = GetPeiServicesTable(); /*0xffde5536*/
 ErrorLevel = (*(int ( **)(int, void *, _DWORD, _DWORD, _DWORD **))(*(_DWORD *)SpsStatus + 32))( /*0xffde5549*/
 SpsStatus,
 &unk_FFDE7A0C,
 0,
 0,
 &PpiOutput);
 if ( ErrorLevel >= 0 )
 {
 DebugPrintWorker(64, (int)"SPS Policy PPI Revision : %d\n", *PpiOutput);
 DumpSpsConfigPolicy(SpsPolicy, (int)(PpiOutput + 1)); /*0xffde557d*/
 }
 else
 {
 DebugPrintWorker(0x80000000, (int)"[SPS] ERROR: SPS policy PPI not found (%r)\n", ErrorLevel);
 }
 return DebugPrintWorker(64, (int)"\n---------------------- SpsPolicyPpi Dump End ------------------\n"); /*0xffde558f*/
}

// InstallSpsPolicyPpi @ 0xffde5596 EFI_STATUS __thiscall InstallSpsPolicyPpi(EFI_PEI_SERVICES **PeiServices)
{
 _DWORD *SpsPolicy; // esi int Status; // eax EFI_PEI_PPI_DESCRIPTOR *SpsPpiDesc; // eax const EFI_PEI_PPI_DESCRIPTOR *SpsPpiDesc_1; // edi int DebugLibInstance; // eax unsigned int ConfigFlags; // eax signed __int32 Status; // esi int DebugLib; // eax DebugPrintWorker(64, (int)"[SPS Policy] SPS Policy init\n"); /*0xffde55a1*/
 SpsPolicy = AllocateZeroedPool(0x18u); /*0xffde55b0*/
 if ( SpsPolicy )
 {
 SpsPpiDesc = (EFI_PEI_PPI_DESCRIPTOR *)AllocateZeroedPool(0xCu); /*0xffde55df*/
 SpsPpiDesc_1 = SpsPpiDesc; /*0xffde55e4*/
 if ( SpsPpiDesc )
 {
 SpsPpiDesc->Flags = -2147483632; /*0xffde560f*/
 SpsPpiDesc->Guid = (EFI_GUID *)&unk_FFDE7A0C; /*0xffde5617*/
 *SpsPolicy = 1; /*0xffde561f*/
 SpsPolicy[3] &= 0xFFFFFF80; /*0xffde5623*/
 SpsPolicy[4] &= 0xFFFFFF00; /*0xffde5627*/
 SpsPolicy[1] = 1; /*0xffde562e*/
 *((_BYTE *)SpsPolicy + 20) = 2; /*0xffde5631*/
 ConfigFlags = SpsPolicy[5] & 0xFFC005FF; /*0xffde5638*/
 SpsPolicy[2] = 0x8000; /*0xffde563d*/
 SpsPolicy[5] = ConfigFlags | 0x500; /*0xffde5649*/
 UpdateSpsPolicyFromMeVariable((int)SpsPolicy); /*0xffde564c*/
 SpsPpiDesc_1->Ppi = SpsPolicy; /*0xffde5651*/
 Status = (*PeiServices)->InstallPpi((const EFI_PEI_SERVICES **)PeiServices, SpsPpiDesc_1); /*0xffde565b*/
 DebugPrintWorker(64, (int)"[SPS Policy] SPS Policy PPI Installed (Status: %r)\n", Status);
 if ( Status < 0 ) /*0xffde566f*/
 {
 DebugPrintWorker(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffde567c*/
 DebugLib = GetDebugLibInstance(); /*0xffde5684*/
 if ( DebugLib ) /*0xffde568b*/
 (*(void ( **)(const char *, int, const char *))(DebugLib + 4))( /*0xffde569c*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\Library\\PeiSpsPolicy\\MeSpsPolicyInit.c",
 149,
 "!EFI_ERROR (Status)");
 }
 return Status; /*0xffde56a2*/
 }
 else
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde55ea*/
 if ( DebugLibInstance ) /*0xffde55f1*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde55ff*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\Library\\PeiSpsPolicy\\MeSpsPolicyInit.c",
 116,
 "SpsPolicyPpiDesc != ((void *) 0)");
 return -2147483639; /*0xffde5605*/
 }
 }
 else
 {
 Status = GetDebugLibInstance(); /*0xffde55b6*/
 if ( Status ) /*0xffde55bd*/
 (*(void ( **)(const char *, int, const char *))(Status + 4))( /*0xffde55cb*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\Library\\PeiSpsPolicy\\MeSpsPolicyInit.c",
 110,
 "SpsPolicyPpi != ((void *) 0)");
 return -2147483639; /*0xffde55d1*/
 }
}

// UpdateSpsPolicyFromMeVariable @ 0xffde56a8 int __thiscall UpdateSpsPolicyFromMeVariable(int this)
{
 int MeVariableData; // eax int MeVariableData_1; // edx int v5; // eax char v6; // cl _BYTE v7[104]; // [esp+4h] [ebp-68h] BYREF MeVariableData = GetMeVariableData(this, (int)v7); /*0xffde56b4*/
 MeVariableData_1 = MeVariableData; /*0xffde56b9*/
 if ( MeVariableData >= 0 )
 {
 v5 = (*(_DWORD *)(this + 12) ^ v7[28]) & 1; /*0xffde5702*/
 *(_DWORD *)(this + 16) = *(_DWORD *)(this + 16) & 0xFFFFFF00 | v7[34] & 1 | (2 * (v7[35] & 0x7F)); /*0xffde5704*/
 *(_DWORD *)(this + 12) ^= v5; /*0xffde5707*/
 v6 = v7[50]; /*0xffde570d*/
 *(_BYTE *)(this + 20) = v7[36]; /*0xffde5711*/
 *(_DWORD *)(this + 20) = *(_DWORD *)(this + 20) & 0xFFC000FF /*0xffde57a7*/
 | ((v7[37] & 1
 | (2
 * (v7[38] & 1
 | (2
 * (v7[39] & 1
 | (2
 * (v7[40] & 1
 | (2
 * (v7[41] & 1
 | (2
 * (v7[42] & 1
 | (2
 * (v7[43] & 1
 | (2
 * (v7[44] & 1
 | (2
 * (v7[45] & 1
 | (2
 * (v7[46] & 1
 | (2
 * (v7[47] & 1 | (2 * (v7[48] & 1 | (2 * (v7[49] & 1 | (2 * (v6 & 1))))))))))))))))))))))))))) << 8);
 return MeVariableData_1; /*0xffde57a5*/
 }
 else
 {
 DebugPrintWorker(0x80000000, (int)"[SPS Policy] ERROR: ME Variable not found (%r)\n", MeVariableData);
 return -2147483634; /*0xffde56d2*/
 }
}

// UpdateMePolicyFromMeVariable @ 0xffde57b0 int __thiscall UpdateMePolicyFromMeVariable(_DWORD *this)
{
 int MeVariableData; // eax int MeVariableData_1; // esi int Table; // edx int Table; // eax int n2_1; // edx int Table; // eax int n2_2; // edx int Table; // eax int n2_3; // edx int Table; // eax int n2_4; // edx bool Table; // al int v15; // ecx unsigned int v16; // edx int v17; // eax int v18; // ecx _BYTE Ptr[104]; // [esp+8h] [ebp-68h] BYREF MeVariableData = GetMeVariableData((int)this, (int)Ptr); /*0xffde57bd*/
 MeVariableData_1 = MeVariableData; /*0xffde57c2*/
 if ( MeVariableData >= 0 )
 {
 Table = Ptr[12]; /*0xffde57f0*/
 *(this + 2) = ((Ptr[8] & 1) << 10) | *(this + 2) & 0xFFFFFA01 | (2 *Ptr[9]) & 0xFBFF; /*0xffde580a*/
 Table = AutoConfigDeviceSetting(0, Table); /*0xffde5810*/
 n2_1 = Ptr[13]; /*0xffde5815*/
 *(this + 2) ^= (*(this + 2) ^ (Table << 14)) & 0xC000; /*0xffde5826*/
 Table = AutoConfigDeviceSetting(1, n2_1); /*0xffde5829*/
 n2_2 = Ptr[14]; /*0xffde582e*/
 *(this + 2) ^= (*(this + 2) ^ (Table << 16)) & 0x30000; /*0xffde583d*/
 Table = AutoConfigDeviceSetting(4, n2_2); /*0xffde5843*/
 n2_3 = Ptr[15]; /*0xffde5848*/
 *(this + 2) ^= (*(this + 2) ^ (Table << 18)) & 0xC0000; /*0xffde5857*/
 Table = AutoConfigDeviceSetting(2, n2_3); /*0xffde585d*/
 n2_4 = Ptr[16]; /*0xffde5862*/
 *(this + 2) ^= (*(this + 2) ^ (Table << 20)) & 0x300000; /*0xffde5871*/
 Table = AutoConfigDeviceSetting(3, n2_4); /*0xffde5877*/
 v15 = Ptr[20] << 29; /*0xffde5899*/
 v16 = *(this + 2) & 0xFC3FFFFF | ((Table & 3 | (4 * (Ptr[18] & 1 | (2 * (Ptr[10] & 1))))) << 22); /*0xffde58a7*/
 v17 = Ptr[17] & 1; /*0xffde58ad*/
 *(this + 2) = v16; /*0xffde58af*/
 v18 = *(this + 3) & 0x7FFFFFF8 | Ptr[11] & 3 | (4 * (v17 | v15)); /*0xffde58c8*/
 LOBYTE(v17) = Ptr[22]; /*0xffde58ca*/
 *(this + 3) = v18; /*0xffde58ce*/
 *(this + 4) = *(this + 4) & 0xFFFFFFEC | Ptr[21] & 1 | (2 * (v17 & 1 | (8 * (Ptr[19] & 1)))); /*0xffde58f2*/
 return 0; /*0xffde58f0*/
 }
 else
 {
 DebugPrintWorker(
 0x80000000,
 (int)"[ME] ERROR: Cannot find ME RC Variable, policy update failed (%r)\n",
 MeVariableData);
 return MeVariableData_1; /*0xffde57db*/
 }
}

// DetectMeType @ 0xffde58fb int DetectMeType()
{
 unsigned __int8 v0; // al char Result; // al char n3_1; // cl v0 = __inbyte(0x70u); /*0xffde5901*/
 __outbyte(0x70u, v0 & 0x80 | 0x4A); /*0xffde5906*/
 Result = __inbyte(0x71u); /*0xffde590d*/
 n3_1 = Result; /*0xffde590e*/
 if ( (unsigned __int8)Result <= 3u ) /*0xffde5913*/
 {
LABEL_4:
 if ( !n3_1 ) /*0xffde592e*/
 return 0; /*0xffde592e*/
 goto LABEL_5; /*0xffde592e*/
 }
 n3_1 = Result; /*0xffde5915*/
 if ( !Result ) /*0xffde591d*/
 {
 n3_1 = MEMORY[0xFDAF0490] & 2 | 1; /*0xffde5929*/
 goto LABEL_4; /*0xffde5929*/
 }
LABEL_5:
 if ( n3_1 != -1 )
 return n3_1 != 1 ? -2147483578 : -2147483644;
 return 0; /*0xffde5946*/
}

// AllocatePages @ 0xffde594a void *__thiscall AllocatePages(UINTN Pages)
{
 int PeiServices; // eax void *Result; // [esp+4h] [ebp-4h] BYREF PeiServices = GetPeiServicesTable(); /*0xffde5951*/
 if ( (*(int ( **)(int, UINTN, void **))(*(_DWORD *)PeiServices + 76))(PeiServices, Pages, &Result) >= 0 ) /*0xffde5967*/
 return Result; /*0xffde596d*/
 else return 0; /*0xffde5969*/
}

// AllocateZeroedPool @ 0xffde5974 void *__thiscall AllocateZeroedPool(UINTN Size)
{
 void *Buffer; // eax UINTN Size_1; // edx UINTN Size_2; // edi void *Buffer_1; // esi int DebugLib; // eax Buffer = AllocatePages(Size); /*0xffde5977*/
 if ( Buffer ) /*0xffde597e*/
 {
 Size_1 = Size; /*0xffde5980*/
 Size_2 = Size; /*0xffde598e*/
 Buffer_1 = Buffer; /*0xffde5990*/
 if ( Size_1 ) /*0xffde5994*/
 {
 if ( Size_2 > -(int)Buffer ) /*0xffde59c1*/
 {
 DebugLib = GetDebugLibInstance(); /*0xffde59c3*/
 if ( DebugLib ) /*0xffde59ca*/
 (*(void ( **)(const char *, int, const char *))(DebugLib + 4))( /*0xffde59d4*/
 "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
 54,
 "Length <= (0xFFFFFFFF - (UINTN)Buffer + 1)");
 }
 return InternalMemZeroMem(Buffer_1, Size_2); /*0xffde59dc*/
 }
 }
 return Buffer; /*0xffde598a*/
}

// CompareGuid @ 0xffde59e7 bool CompareGuid(int a1, int a2)
{
 __int64 Unaligned64; // rax int Unaligned64_1; // ebp __int64 Unaligned64_3; // rax int Unaligned64_2; // edi __int64 v8; // kr00_8 __int64 v9; // rax int v11; // [esp+10h] [ebp-Ch]
 int v12; // [esp+14h] [ebp-8h]

 Unaligned64 = ReadUnaligned64((void *)a1); /*0xffde59f2*/
 v12 = HIDWORD(Unaligned64); /*0xffde59f9*/
 Unaligned64_1 = Unaligned64; /*0xffde59fd*/
 Unaligned64_3 = ReadUnaligned64((void *)a2); /*0xffde59ff*/
 v11 = HIDWORD(Unaligned64_3); /*0xffde5a07*/
 Unaligned64_2 = Unaligned64_3; /*0xffde5a0b*/
 v8 = ReadUnaligned64((void *)(a1 + 8)); /*0xffde5a19*/
 v9 = ReadUnaligned64((void *)(a2 + 8)); /*0xffde5a1b*/
 return Unaligned64_1 == Unaligned64_2 && v12 == v11 && v8 == v9; /*0xffde5a3e*/
}

// FindMatchingGuidIndex @ 0xffde5a46 int FindMatchingGuidIndex()
{
 int Index; // esi int *v1; // eax Index = 0; /*0xffde5a4e*/
 if ( off_FFDE7A9C ) /*0xffde5a56*/
 {
 v1 = (int *)&off_FFDE7A9C; /*0xffde5a58*/
 do /*0xffde5a77*/
 {
 if ( CompareGuid(*v1, (int)&unk_FFDE799C) ) /*0xffde5a64*/
 break; /*0xffde5a6b*/
 ++Index; /*0xffde5a6d*/
 v1 = (int *)(&off_FFDE7A9C + 3 *Index); /*0xffde5a71*/
 }
 while ( *v1 ); /*0xffde5a77*/
 }
 if ( *(&off_FFDE7A9C + 3 *Index) ) /*0xffde5a7f*/
 return Index; /*0xffde5a8d*/
 else return -1; /*0xffde5a88*/
}

// GetMeVariableData @ 0xffde5a94 int GetMeVariableData(int this, int a2)
{
 int MatchingGuidIndex; // edi int PeiServicesTable; // eax int ( **v6)(_DWORD, __int16 *, _DWORD, _DWORD, char *, int); // [esp+8h] [ebp-4h] BYREF if ( !a2 ) /*0xffde5a9e*/
 return -2147483646; /*0xffde5aef*/
 MatchingGuidIndex = FindMatchingGuidIndex(); /*0xffde5aa5*/
 if ( MatchingGuidIndex == -1 ) /*0xffde5aaa*/
 return -2147483634; /*0xffde5aac*/
 PeiServicesTable = GetPeiServicesTable(); /*0xffde5ab3*/
 (*(void ( **)(int, void *, _DWORD, _DWORD, int ( ***)(_DWORD, __int16 *, _DWORD, _DWORD, char *, int)))(*(_DWORD *)PeiServicesTable + 32))( /*0xffde5ac8*/
 PeiServicesTable,
 &unk_FFDE79AC,
 0,
 0,
 &v6);
 // "SocketIioConfig"
 return (*v6)( /*0xffde5af4*/
 v6,
 (&off_FFDE7AA0)[3 *MatchingGuidIndex],
 *(&off_FFDE7A9C + 3 *MatchingGuidIndex),
 0,
 (char *)&unk_FFDE7AA4 + 12 *MatchingGuidIndex,
 a2);
}

// InitMePolicyDefaults @ 0xffde5afa int __thiscall InitMePolicyDefaults(_DWORD *this)
{
 unsigned int v2; // eax v2 = *(this + 1) & 0xFFFFC401; /*0xffde5b07*/
 *this = 1; /*0xffde5b0c*/
 *(this + 1) = v2 | 0x401; /*0xffde5b19*/
 *(this + 1) ^= (*(this + 1) ^ (AutoConfigDeviceSetting(0, 2) << 14)) & 0xC000; /*0xffde5b31*/
 *(this + 1) ^= (*(this + 1) ^ (AutoConfigDeviceSetting(1, 2) << 16)) & 0x30000; /*0xffde5b46*/
 *(this + 1) ^= (*(this + 1) ^ (AutoConfigDeviceSetting(4, 2) << 18)) & 0xC0000; /*0xffde5b60*/
 *(this + 1) ^= (*(this + 1) ^ (AutoConfigDeviceSetting(2, 2) << 20)) & 0x300000; /*0xffde5b75*/
 *(this + 1) = *(this + 1) & 0xFF3FFFFF | ((AutoConfigDeviceSetting(3, 2) & 3 | 0xC) << 22); /*0xffde5b95*/
 *(this + 2) = *(this + 2) & 0x7FFFFFF8 | 2; /*0xffde5ba2*/
 *(this + 3) = *(this + 3) & 0xFFFFFFE0 | 0x12; /*0xffde5bae*/
 return 0; /*0xffde5bb3*/
}

// DumpMeConfigPolicy @ 0xffde5bb6 int __thiscall DumpMeConfigPolicy(_DWORD *this)
{
 int DebugLibInstance; // eax DebugPrintWorker(64, (int)"ME Config Revision : %d\n", *this);
 if ( *this != 1 ) /*0xffde5bd4*/
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde5bd6*/
 if ( DebugLibInstance ) /*0xffde5bdd*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde5beb*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\Library\\MeConfigLib\\MeConfigLib.c",
 121,
 "pMeConfig->Revision == 1");
 }
 DebugPrintWorker(64, (int)" HeciTimeouts : %d\n", *(this + 1) & 1);
 DebugPrintWorker(64, (int)" DidInitStat : 0x%X\n", (unsigned __int8)(*(this + 1) >> 1));
 DebugPrintWorker(64, (int)" DisableCpuReplacedPolling: %d\n", (*(this + 1) >> 9) & 1);
 DebugPrintWorker(64, (int)" DisableHeciRetry : %d\n", (*(this + 1) >> 11) & 1);
 DebugPrintWorker(64, (int)" DisableMessageCheck : %d\n", (*(this + 1) >> 12) & 1);
 DebugPrintWorker(64, (int)" SkipMbpHob : %d\n", (*(this + 1) >> 13) & 1);
 DebugPrintWorker(64, (int)" HeciCommunication1 : %d\n", (unsigned __int8)HIBYTE(*((_WORD *)this + 2)) >> 6);
 DebugPrintWorker(64, (int)" HeciCommunication2 : %d\n", *((_WORD *)this + 3) & 3);
 DebugPrintWorker(64, (int)" HeciCommunication3 : %d\n", (*(this + 1) >> 18) & 3);
 DebugPrintWorker(64, (int)" KtDeviceEnable : %d\n", (*(this + 1) >> 22) & 3);
 DebugPrintWorker(64, (int)" IderDeviceEnable : %d\n", (*(this + 1) >> 20) & 3);
 DebugPrintWorker(64, (int)" HostResetNotification : %d\n", *((_BYTE *)this + 7) & 1);
 DebugPrintWorker(64, (int)" HsioMessaging : %d\n", (*(this + 1) >> 25) & 1);
 DebugPrintWorker(64, (int)" EndOfPostMessage : %d\n", *(this + 2) & 3);
 DebugPrintWorker(64, (int)" DisableD0I3SettingForHeci: %d\n", (*(this + 2) >> 2) & 1);
 DebugPrintWorker(64, (int)" MeFwDownGrade : %d\n", *(this + 2) >> 31);
 DebugPrintWorker(64, (int)" MeLocalFwUpdEnabled : %d\n", *(this + 3) & 1);
 DebugPrintWorker(64, (int)" OsPtpAware : %d\n", (*(this + 3) >> 1) & 1);
 DebugPrintWorker(64, (int)" HidePttFromOS : %d\n", (*(this + 3) >> 2) & 1);
 return DebugPrintWorker(64, (int)" MeJhiSupport : %d\n", (*(this + 3) >> 3) & 1);
}

// AutoConfigDeviceSetting @ 0xffde5d85 BOOL AutoConfigDeviceSetting(int n4, int n2)
{
 int n2_1; // esi int Table; // [esp-4h] [ebp-14h]

 n2_1 = n2; /*0xffde5d8e*/
 if ( n2 != 2 ) /*0xffde5d96*/
 {
 DebugPrintWorker(64, (int)"[ME Policy] Not Auto-configuration (%d) passed for device %d\n", n2, n4); /*0xffde5da1*/
 return n2_1; /*0xffde5dab*/
 }
 if ( GetOnBoardMeType() == 15 ) /*0xffde5db5*/
 return 1; /*0xffde5dba*/
 if ( n4 )
 {
 n2_1 = 1; /*0xffde5dcb*/
 if ( n4 == 1 ) /*0xffde5dce*/
 {
 if ( GetOnBoardMeType() == 1 ) /*0xffde5e2f*/
 {
 if ( GetOnBoardMeType() == 1 && *(_DWORD *)(ReadPchPciConfig(22, 1) + 64) >= 0x80000000 ) /*0xffde5e4c*/
 return n2_1; /*0xffde5e4c*/
 return 0; /*0xffde5e4c*/
 }
 goto LABEL_12; /*0xffde5e2f*/
 }
 if ( n4 <= 1 )
 {
LABEL_17:
 DebugPrintWorker(2, (int)"[ME Policy] WARNING: Auto-configuration passed for unrecognised device %d\n", n4);
 return 0; /*0xffde5e14*/
 }
 if ( n4 > 3 ) /*0xffde5dd5*/
 {
 if ( n4 == 4 ) /*0xffde5dda*/
 {
 if ( GetOnBoardMeType() == 1 ) /*0xffde5de3*/
 return n2_1; /*0xffde5de3*/
 goto LABEL_12; /*0xffde5de3*/
 }
 goto LABEL_17; /*0xffde5dda*/
 }
 if ( GetOnBoardMeType() == 1 ) /*0xffde5e1c*/
 return 0; /*0xffde5e1c*/
LABEL_12:
 if ( GetOnBoardMeType() != 255 )
 {
 Table = *(_DWORD *)(ReadPchPciConfig(22, 0) + 64); /*0xffde5dfc*/
 DebugPrintWorker(2, (int)"[ME Policy] WARNING: Unexpected ME type (MEFS1: %08X)\n", Table);
 }
 return 0; /*0xffde5e04*/
 }
 n2_1 = 1; /*0xffde5e5a*/
 if ( GetOnBoardMeType() == 1 ) /*0xffde5e5d*/
 return n2_1; /*0xffde5e5d*/
 if ( GetOnBoardMeType() != 255 ) /*0xffde5e6a*/
 goto LABEL_12; /*0xffde5e6a*/
 return (*(_DWORD *)(ReadPchPciConfig(22, 0) + 64) & 0xF0000) == 458752; /*0xffde5e0e*/
}

// DumpMePolicyPpi @ 0xffde5e92 int __thiscall DumpMePolicyPpi(_DWORD *this)
{
 int DebugLibInstance; // eax DebugPrintWorker(64, (int)"\n---------------------- ME Policy PPI Begin ----------------------\n"); /*0xffde5e9c*/
 DebugPrintWorker(64, (int)"ME Policy PPI Revision : %d\n", *this);
 if ( *this != 1 ) /*0xffde5eb5*/
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde5eb7*/
 if ( DebugLibInstance ) /*0xffde5ebe*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde5ecc*/
 "e:\\hs\\PurleyPlatPkg\\Me\\Policy\\AMT\\Library\\PeiMePolicyLib\\MePrintPolicy.c",
 44,
 "MePolicyPpi->Revision == 1");
 }
 DumpMeConfigPolicy(this + 1); /*0xffde5ed5*/
 return DebugPrintWorker(64, (int)"\n---------------------- ME Policy PPI End ------------------------\n"); /*0xffde5ee8*/
}

// IoRead16 @ 0xffde5eea int IoRead16(unsigned __int16 *a1)
{
 int DebugLibInstance; // eax if ( ((unsigned __int8)a1 & 1) != 0 ) /*0xffde5ef0*/
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde5ef2*/
 if ( DebugLibInstance ) /*0xffde5ef9*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde5f0a*/
 "e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLib.c",
 151,
 "(Address & 1) == 0");
 }
 return *a1; /*0xffde5f16*/
}

// ReadUnaligned64 @ 0xffde5f18 __int64 __thiscall ReadUnaligned64(void *this)
{
 int DebugLibInstance; // eax if ( !this ) /*0xffde5f1d*/
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde5f1f*/
 if ( DebugLibInstance ) /*0xffde5f26*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde5f37*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
 192,
 "Buffer != ((void *) 0)");
 }
 return *(_QWORD *)this; /*0xffde5f42*/
}

// GetPeiServicesTable @ 0xffde5f44 int GetPeiServicesTable()
{
 int Result; // esi _BYTE v2[8]; // [esp+4h] [ebp-8h] BYREF ReadIdtr(v2); /*0xffde5f4d*/
 Result = *(_DWORD *)(*(_DWORD *)&v2[2] - 4); /*0xffde5f55*/
 if ( !Result ) /*0xffde5f5a*/
 DebugAssertWorker( /*0xffde5f69*/
 (int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
 48,
 (int)"PeiServices != ((void *) 0)");
 return Result; /*0xffde5f71*/
}

// ReadPchPciConfig @ 0xffde5f76 int __usercall ReadPchPciConfig@<eax>(char a1@<dl>, int a2)
{
 _DWORD v3[5]; // [esp+0h] [ebp-14h] BYREF v3[2] = 512; /*0xffde5f8a*/
 v3[0] = (a2 & 7 | (8 * (a1 & 0x1F))) << 12; /*0xffde5f9a*/
 v3[3] = 0; /*0xffde5fa0*/
 v3[1] = 0; /*0xffde5fa6*/
 PciReadBufferToPhysAddr(0, 0, v3, &a2); /*0xffde5fa9*/
 return a2; /*0xffde5fb4*/
}

// GetMeFs1FromHob @ 0xffde5fb8 int __thiscall GetMeFs1FromHob(void *this)
{
 int this_1; // esi _WORD *MeFwHobGuid; // eax int DebugLibInstance; // eax this_1 = -1; /*0xffde5fbd*/
 MeFwHobGuid = FindMeFwHobGuid(); /*0xffde5fc0*/
 if ( !MeFwHobGuid ) /*0xffde5fc7*/
 goto LABEL_7; /*0xffde5fc7*/
 if ( *((_DWORD *)MeFwHobGuid + 7) )
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde5fd4*/
 if ( !DebugLibInstance )
 {
LABEL_7:
 DebugPrintWorker(0x80000000, (int)"HECI: GetMeFs1FromHob() Can't read correctly MeFwHob info\n");
 this_1 = (int)this; /*0xffde6005*/
 goto LABEL_8; /*0xffde6005*/
 }
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde5fe9*/
 "e:\\hs\\PurleySktPkg\\Me\\Heci\\Library\\MeTypeLib\\MeTypeLib.c",
 67,
 "MeFwHob->Group[0].FunNumber == HECI1_DEVICE");
 }
 else
 {
 this_1 = *((_DWORD *)MeFwHobGuid + 8); /*0xffde5fcf*/
 }
 if ( this_1 == -1 ) /*0xffde5ff2*/
 goto LABEL_7; /*0xffde5ff2*/
LABEL_8:
 DebugPrintWorker(64, (int)"HECI: GetMeFs1FromHob() returns MEFS1 = %d\n", this_1);
 return this_1; /*0xffde6019*/
}

// GetOnBoardMeType @ 0xffde601d int GetOnBoardMeType()
{
 int Result; // edi int DebugLibInstance; // eax unsigned int MeFs1FromHob; // esi unsigned int Table; // ebx int PchPciConfig; // eax unsigned int v6; // [esp+10h] [ebp-4h] BYREF Result = 0; /*0xffde6022*/
 v6 = 0; /*0xffde6028*/
 PchPwrmBaseGet(&v6); /*0xffde602c*/
 if ( v6 )
 {
 if ( (*(_DWORD *)(v6 + 300) & 0x8000) != 0 )
 {
 DebugPrintWorker(64, (int)"HECI: GetOnBoardMeType() for DWR flow return Dfx type\n");
 return 15; /*0xffde60b2*/
 }
 }
 else
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde6039*/
 if ( DebugLibInstance ) /*0xffde6040*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde6051*/
 "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchPmcLib\\PchPmcLib.c",
 162,
 "PchPwrmBase != 0");
 }
 MeFs1FromHob = *(_DWORD *)(ReadPchPciConfig(22, 0) + 64); /*0xffde6064*/
 if ( MeFs1FromHob == -1 )
 {
 MeFs1FromHob = GetMeFs1FromHob((void *)0xFFFFFFFF); /*0xffde6070*/
 DebugPrintWorker(64, (int)"HECI: GetOnBoardMeType() reads Hfs info from HOB = %d\n", MeFs1FromHob);
 }
 if ( (MeFs1FromHob & 0xF) != 0xF )
 {
 if ( (MeFs1FromHob & 0xF) == 4 ) /*0xffde60b7*/
 return 255; /*0xffde60be*/
 Table = HIWORD(MeFs1FromHob) & 0xF; /*0xffde60c5*/
 DebugPrintWorker(64, (int)"HECI: MeOperationMode = %d\n", Table);
 if ( Table > 1 )
 {
 if ( Table == 2 ) /*0xffde60df*/
 return 255; /*0xffde60df*/
 if ( Table > 5 )
 {
 if ( Table != 7 )
 {
 if ( Table == 15 ) /*0xffde60ef*/
 return 1; /*0xffde60f3*/
 DebugPrintWorker(0x80000000, (int)"HECI: ME type not recognized (MEFS1: 0x%08X)\n", MeFs1FromHob);
 PchPciConfig = ReadPchPciConfig(22, 0); /*0xffde610e*/
 DebugPrintWorker(
 0x80000000,
 (int)" (MEFS2: 0x%08X)\n",
 *(_DWORD *)(PchPciConfig + 72));
 return Result; /*0xffde60f4*/
 }
 return 255; /*0xffde60eb*/
 }
 }
 return 2; /*0xffde612a*/
 }
 return 15; /*0xffde612d*/
}

// PciReadBufferToPhysAddr @ 0xffde6133 int *PciReadBufferToPhysAddr(int a1, int a2, _DWORD *a3, int *a4)
{
 int Device; // ecx Device = PciExpressReadPhysAddr((int)a3) + (*a3 & 0xFFFFFFF); /*0xffde6147*/
 *a4 = Device; /*0xffde614e*/
 return a4; /*0xffde614d*/
}

// GetPcdPeiServicesPtr @ 0xffde6151 void *__thiscall GetPcdPeiServicesPtr(void *this)
{
 int PeiServicesTable; // eax int Status; // eax int DebugLibInstance; // eax void *this_1; // [esp+0h] [ebp-4h]

 this_1 = this; /*0xffde6154*/
 PeiServicesTable = GetPeiServicesTable(); /*0xffde6155*/
 Status = (*(int (__stdcall **)(int))(*(_DWORD *)PeiServicesTable + 32))(PeiServicesTable); /*0xffde616a*/
 if ( Status < 0 ) /*0xffde6172*/
 {
 DebugPrintWorker(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffde617f*/
 DebugLibInstance = GetDebugLibInstance(); /*0xffde6187*/
 if ( DebugLibInstance ) /*0xffde618e*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde619c*/
 "e:\\hs\\MdePkg\\Library\\PeiPcdLib\\PeiPcdLib.c",
 49,
 "!EFI_ERROR (Status)");
 }
 return this_1; /*0xffde61a7*/
}

// PcdGet32 @ 0xffde61a9 int __thiscall PcdGet32(void *this)
{
 int ( **PcdPeiServicesPtr)(void *); // eax PcdPeiServicesPtr = (int ( **)(void *))GetPcdPeiServicesPtr(this); /*0xffde61ac*/
 return PcdPeiServicesPtr[4](this); /*0xffde61b6*/
}

// PcdGet64 @ 0xffde61b8 int __thiscall PcdGet64(void *this)
{
 int ( **PcdPeiServicesPtr)(void *); // eax PcdPeiServicesPtr = (int ( **)(void *))GetPcdPeiServicesPtr(this); /*0xffde61bb*/
 return PcdPeiServicesPtr[5](this); /*0xffde61c5*/
}

// ReadIdtr @ 0xffde61c7 void *__thiscall ReadIdtr(void *this)
{
 void *this_1; // eax if ( !this ) /*0xffde61cd*/
 DebugAssertWorker((int)"e:\\hs\\MdePkg\\Library\\BaseLib\\X86ReadIdtr.c", 37, (int)"Idtr != ((void *) 0)"); /*0xffde61dc*/
 this_1 = this; /*0xffde61e2*/
 __sidt(this); /*0xffde61e5*/
 return this_1; /*0xffde61e9*/
}

// GetHobList @ 0xffde61ea int GetHobList()
{
 int PeiServicesTable; // eax int Status; // eax int DebugLibInstance; // eax int ErrorLevel; // eax int Result; // [esp+4h] [ebp-4h] BYREF PeiServicesTable = GetPeiServicesTable(); /*0xffde61ef*/
 Status = (*(int ( **)(int, int *))(*(_DWORD *)PeiServicesTable + 48))(PeiServicesTable, &Result); /*0xffde61fb*/
 if ( Status < 0 ) /*0xffde6207*/
 {
 DebugPrintWorker(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffde6214*/
 DebugLibInstance = GetDebugLibInstance(); /*0xffde621c*/
 if ( DebugLibInstance ) /*0xffde6223*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde622d*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 50,
 "!EFI_ERROR (Status)");
 }
 if ( !Result ) /*0xffde6237*/
 {
 ErrorLevel = GetDebugLibInstance(); /*0xffde6239*/
 if ( ErrorLevel ) /*0xffde6240*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffde624a*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 51,
 "HobList != ((void *) 0)");
 }
 return Result; /*0xffde6253*/
}

// GetNextHobByType @ 0xffde6258 _WORD *GetNextHobByType(int a1, _WORD *i)
{
 _WORD *i_1; // esi int DebugLibInstance; // eax i_1 = i; /*0xffde6259*/
 if ( !i ) /*0xffde625d*/
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde625f*/
 if ( DebugLibInstance ) /*0xffde6266*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde6274*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 82,
 "HobStart != ((void *) 0)");
 }
 while ( 1 ) /*0xffde628d*/
 {
 if ( *i_1 == 0xFFFF ) /*0xffde6293*/
 return 0; /*0xffde6298*/
 if ( *i_1 == 4 ) /*0xffde6285*/
 break; /*0xffde6285*/
 i_1 = (_WORD *)((char *)i_1 + (unsigned __int16)i_1[1]); /*0xffde628b*/
 }
 return i_1; /*0xffde6297*/
}

// FindMeFwHobGuid @ 0xffde629d _WORD *FindMeFwHobGuid()
{
 _WORD *i; // edx int v1; // ecx _WORD *NextHobByType; // eax _WORD *NextHobByType_1; // esi for ( i = (_WORD *)GetHobList(); ; i = (_WORD *)((char *)NextHobByType_1 + (unsigned __int16)NextHobByType_1[1]) ) /*0xffde62a3*/
 {
 NextHobByType = GetNextHobByType(v1, i); /*0xffde62be*/
 NextHobByType_1 = NextHobByType; /*0xffde62c3*/
 if ( !NextHobByType || CompareGuid((int)&unk_FFDE7A1C, (int)(NextHobByType + 4)) ) /*0xffde62af*/
 break; /*0xffde62af*/
 }
 return NextHobByType_1; /*0xffde62cb*/
}

// PchPwrmBaseGet @ 0xffde62cd int __thiscall PchPwrmBaseGet(unsigned int *this)
{
 int ErrorLevel; // eax int PchPciConfig; // edi int DebugLibInstance; // eax if ( this ) /*0xffde62d4*/
 {
 PchPciConfig = ReadPchPciConfig(31, 2); /*0xffde6317*/
 if ( (unsigned __int16)IoRead16((unsigned __int16 *)PchPciConfig) == 0xFFFF ) /*0xffde6328*/
 {
 DebugLibInstance = GetDebugLibInstance(); /*0xffde632a*/
 if ( DebugLibInstance ) /*0xffde6331*/
 (*(void ( **)(const char *, int, const char *))(DebugLibInstance + 4))( /*0xffde6342*/
 "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchCycleDecodingLib\\PchCycleDecodingLib.c",
 303,
 "((BOOLEAN)(0==1))");
 return -2147483645; /*0xffde6348*/
 }
 else
 {
 *this = *(_DWORD *)(PchPciConfig + 72) & 0xFFFF0000; /*0xffde6357*/
 return 0; /*0xffde6359*/
 }
 }
 else
 {
 DebugPrintWorker(0x80000000, (int)"PchPwrmBaseGet Error. Invalid pointer.\n"); /*0xffde62e0*/
 ErrorLevel = GetDebugLibInstance(); /*0xffde62e7*/
 if ( ErrorLevel ) /*0xffde62ee*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffde62ff*/
 "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchCycleDecodingLib\\PchCycleDecodingLib.c",
 293,
 "((BOOLEAN)(0==1))");
 return -2147483646; /*0xffde6305*/
 }
}

// InitPciExpressReg @ 0xffde635f int InitPciExpressReg(_DWORD *a1, int n8)
{
 int v3; // [esp+Ch] [ebp-4h]

 v3 = PcdGet64((void *)6); /*0xffde638f*/
 a1[1] = 16 *n8 + 16; /*0xffde6398*/
 if ( !a1[4] && !a1[5] ) /*0xffde63b4*/
 {
 *(_DWORD *)(v3 + 16) = PcdGet32((void *)5); /*0xffde63d9*/
 *(_DWORD *)(v3 + 20) = 0; /*0xffde63f0*/
 }
 return 0; /*0xffde63f6*/
}

// PciExpressReadPhysAddr @ 0xffde63fa int PciExpressReadPhysAddr(int a1)
{
 int v2; // [esp+Ch] [ebp-Ch]
 int v3; // [esp+10h] [ebp-8h]
 int Result; // [esp+14h] [ebp-4h]

 if ( *(_DWORD *)(a1 + 12) ) /*0xffde640f*/
 {
 v3 = *(_DWORD *)(*(_DWORD *)(a1 + 12) + 4 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 255544); /*0xffde6505*/
 Result = *(_DWORD *)(*(_DWORD *)(a1 + 12) + 4 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 255560); /*0xffde6521*/
 }
 else
 {
 v2 = PcdGet64((void *)6); /*0xffde6422*/
 if ( *(_DWORD *)(v2 + 4) ) /*0xffde6428*/
 {
 v3 = *(_DWORD *)(v2 + 16 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 20); /*0xffde6443*/
 Result = *(_DWORD *)(v2 + 16 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 16); /*0xffde645b*/
 }
 else
 {
 InitPciExpressReg(dword_FFDE7B20, 8); /*0xffde646e*/
 v3 = dword_FFDE7B34[4 * (unsigned __int16)*(_DWORD *)(a1 + 4)]; /*0xffde6489*/
 Result = dword_FFDE7B30[4 * (unsigned __int16)*(_DWORD *)(a1 + 4)]; /*0xffde64a0*/
 if ( !Result && !v3 ) /*0xffde64ad*/
 {
 Result = PcdGet32((void *)5); /*0xffde64da*/
 v3 = 0; /*0xffde64e7*/
 }
 }
 }
 if ( !Result && !v3 ) /*0xffde652e*/
 return PcdGet32((void *)5); /*0xffde655b*/
 return Result; /*0xffde6574*/
}