Newer
Older
AMI-Aptio-BIOS-Reversed / PurleySktPkg / SouthClusterLbg / SiInit / Pei / SiInitPreMem / PchPreMemInit.c
@Ajax Dong Ajax Dong 2 days ago 38 KB Recovering names (cleanups)
/* Consolidated from decompiled shard files. */
/* Source: ffd80210.c */
int PchFabricErrorCheck()
{
  int v0; // eax
  int v1; // eax
  unsigned __int8 *v2; // esi
  int v3; // edi
  unsigned int i; // ebp
  unsigned int v5; // ecx
  unsigned int v6; // edx
  unsigned int v7; // ebx
  unsigned __int8 v8; // cl
  unsigned int v9; // ebx
  int v10; // ebx
  unsigned int v11; // eax
  int result; // eax
  int v13; // [esp+0h] [ebp-24h] BYREF
  int v14; // [esp+4h] [ebp-20h]
  int v15; // [esp+8h] [ebp-1Ch]
  _DWORD *v16; // [esp+Ch] [ebp-18h] BYREF
  int n10; // [esp+10h] [ebp-14h]
  int v18; // [esp+14h] [ebp-10h] BYREF
  int v19; // [esp+18h] [ebp-Ch] BYREF
  unsigned int v20; // [esp+1Ch] [ebp-8h]
  unsigned int v21; // [esp+20h] [ebp-4h]

  v13 = 0; /*0xffd80213*/
  v0 = GetPeiServicesPtr(); /*0xffd80217*/
  if ( (*(int (__cdecl **)(int, int, _DWORD **))(*(_DWORD *)v0 + 76))(v0, 4, &v16) ) /*0xffd80226*/
  {
    v1 = GetReportStatusCodePpi(); /*0xffd80230*/
    if ( v1 ) /*0xffd80237*/
      (*(void (__cdecl **)(const char *, int, const char *))(v1 + 4))( /*0xffd80248*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchInitPreMem.c",
        456,
        "Status == 0");
  }
  *v16 = 0; /*0xffd80255*/
  v2 = (unsigned __int8 *)&unk_FFD980CC; /*0xffd80258*/
  v15 = 0; /*0xffd8025d*/
  n10 = 10; /*0xffd80263*/
  do
  {
    v3 = 0; /*0xffd8026b*/
    for ( i = 0; i < 0xC00; i += 512 )
    {
      v5 = 0; /*0xffd80272*/
      v6 = i + *((_DWORD *)v2 + 2); /*0xffd80274*/
      v14 = 0; /*0xffd80276*/
      v21 = v6; /*0xffd8027a*/
      if ( v2[v3 + 1] )
      {
        while ( 1 ) /*0xffd80288*/
        {
          v7 = v5; /*0xffd80288*/
          v8 = *v2; /*0xffd8028e*/
          v9 = v6 + 32 * v7; /*0xffd80294*/
          v20 = v9; /*0xffd8029b*/
          sub_FFD8C2A0(v8, v9, 4, &v18); /*0xffd8029f*/
          sub_FFD8C2A0(*v2, v9, 4, &v19); /*0xffd802b0*/
          v10 = v18; /*0xffd802b5*/
          if ( v18 == v19 ) /*0xffd802c0*/
          {
            v13 = v18; /*0xffd802dd*/
          }
          else
          {
            sub_FFD8C2A0(*v2, v20, 4, &v13); /*0xffd802d0*/
            v10 = v13; /*0xffd802d5*/
          }
          if ( v10 ) /*0xffd802e3*/
            break; /*0xffd802e3*/
          v11 = v2[v3 + 1]; /*0xffd802e9*/
          v5 = v14 + 1; /*0xffd802ee*/
          v6 = v21; /*0xffd802ef*/
          v14 = v5; /*0xffd802f3*/
          if ( v5 >= v11 ) /*0xffd802f9*/
            goto LABEL_14; /*0xffd802f9*/
        }
        *v16 |= (v10 & 7) << v15; /*0xffd80311*/
        DebugPrint(0x80000000, (int)"ERROR: Internal fabric error detected!! ");
        DebugPrint( /*0xffd80331*/
          0x80000000,
          (int)"PSF PID:0x%x, RSx/PortGroup:0x%x, Port:0x%x, Channel:0, error bits:0x%x\n",
          *v2,
          v3,
          v14,
          v10);
      }
LABEL_14:
      ++v3; /*0xffd8033f*/
    }
    v15 += 3; /*0xffd8034c*/
    v2 += 12; /*0xffd80351*/
    --n10; /*0xffd80354*/
  }
  while ( n10 );
  result = sub_FFD8CFB4(&unk_FFD97F6C, 4); /*0xffd8036a*/
  if ( !result ) /*0xffd80376*/
  {
    result = GetReportStatusCodePpi(); /*0xffd80378*/
    if ( result ) /*0xffd8037f*/
      return (*(int (__cdecl **)(const char *, int, const char *))(result + 4))( /*0xffd80390*/
               "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchInitPreMem.c",
               504,
               "HobPtr != 0");
  }
  return result; /*0xffd80396*/
}

/* Source: ffd8040b.c */
int __thiscall PchDwrPolicyCheck(_BYTE *this)
{
  int v3; // [esp+8h] [ebp-8h] BYREF

  sub_FFD8C578(-983041, 0); /*0xffd80425*/
  if ( (*(this + 3504) & 1) != 0 ) /*0xffd80434*/
  {
    sub_FFD8C578(-1, 16); /*0xffd8047a*/
LABEL_6:
    MEMORY[0xFE0005D0] = 0x80000000; /*0xffd80481*/
    return sub_FFD8C578(-1, 1); /*0xffd80481*/
  }
  if ( (*(this + 3504) & 2) != 0 ) /*0xffd8043d*/
  {
    sub_FFD8C2A0(0xB8u, 4u, 4, &v3); /*0xffd8044a*/
    if ( (v3 & 0x600) != 0 ) /*0xffd8045d*/
      goto LABEL_6; /*0xffd8045d*/
  }
  sub_FFD8C578(-17, 1); /*0xffd80468*/
  return sub_FFD8C578(-1, 1); /*0xffd8049b*/
}

/* Source: ffd804a1.c */
int __thiscall PchMiscInit(_BYTE *this)
{
  int v2; // eax

  if ( (unsigned __int8)sub_FFD8D59A() )
  {
    DebugPrint(64, (int)"DWR: PchMiscInit() End\n");
  }
  else
  {
    sub_FFD8BE68(); /*0xffd804c0*/
    v2 = sub_FFD8CBBA(0, 31, 2); /*0xffd804ce*/
    *(_DWORD *)(v2 + 172) &= ~0x100000u; /*0xffd804e5*/
    if ( *(this + 1) ) /*0xffd804f0*/
      sub_FFD8C5F6(255, 8); /*0xffd80506*/
    else
      sub_FFD8C5F6(247, 0); /*0xffd804fd*/
    sub_FFD8C578(-1793, 8207); /*0xffd80521*/
    sub_FFD8C578(-1, 0x80000000); /*0xffd80535*/
    sub_FFD8C5F6(223, 0); /*0xffd80556*/
  }
  return 0; /*0xffd8055d*/
}

/* Source: ffd80563.c */
int __thiscall PchProgramSvidSid(int this)
{
  int v2; // ebx
  unsigned int v3; // esi

  v2 = sub_FFD8CBBA(0, 31, 1); /*0xffd80574*/
  if ( (*(_DWORD *)(this + 2727) & 2) != 0 ) /*0xffd8057f*/
    sub_FFD8CCD3( /*0xffd805aa*/
      v2 + 112,
      (*(_DWORD *)(this + 2727) >> 21) & 7
    | (unsigned __int16)(8 * ((32 * *(unsigned __int8 *)(this + 2728)) | HIWORD(*(_DWORD *)(this + 2727)) & 0x1F)));
  v3 = *(_DWORD *)(this + 2731); /*0xffd805af*/
  if ( !v3 ) /*0xffd805b7*/
    v3 = -19922944; /*0xffd805b9*/
  *(_BYTE *)(v2 + 96) = *(_BYTE *)(v2 + 96) & 0xFC | (v3 >> 12) & 3 | 0x80; /*0xffd805d0*/
  if ( (*(_BYTE *)(this + 2727) & 1) != 0 ) /*0xffd805dd*/
    *(_DWORD *)(v3 + 16) |= 1u; /*0xffd805e5*/
  sub_FFD8CF04(v3, 0); /*0xffd805ed*/
  return sub_FFD8D005(v3, 0); /*0xffd805ff*/
}

/* Source: ffd80603.c */
int __thiscall ProgramSvidSid(int this)
{
  unsigned __int8 n0x2C; // bl
  int v3; // ecx
  unsigned __int16 *v4; // edi
  unsigned __int8 v6; // [esp+Fh] [ebp-1h]

  DebugPrint(64, (int)"ProgramSvidSid() Start\n"); /*0xffd80613*/
  sub_FFD8BE68(); /*0xffd8061a*/
  if ( (unsigned __int8)sub_FFD8D59A() )
  {
    DebugPrint(64, (int)"DWR: ProgramSvidSid() End\n");
  }
  else
  {
    n0x2C = 0; /*0xffd8062f*/
    if ( *(_WORD *)(this + 8) || *(_WORD *)(this + 10) ) /*0xffd80637*/
    {
      do /*0xffd80693*/
      {
        v3 = 3 * n0x2C; /*0xffd80640*/
        v6 = byte_FFD97FFE[v3]; /*0xffd80658*/
        v4 = (unsigned __int16 *)sub_FFD8CBBA(0, byte_FFD97FFC[v3], byte_FFD97FFD[v3]); /*0xffd80667*/
        if ( (unsigned __int16)sub_FFD8CCA5(v4) == 0x8086 ) /*0xffd80678*/
          *(_DWORD *)((char *)v4 + v6) = *(_DWORD *)(this + 8); /*0xffd8068b*/
        ++n0x2C; /*0xffd8068e*/
      }
      while ( n0x2C < 0x2Cu ); /*0xffd80693*/
    }
    DebugPrint(64, (int)"ProgramSvidSid() End\n"); /*0xffd8069c*/
  }
  return 0; /*0xffd806a3*/
}

/* Source: ffd806ac.c */
int __thiscall PchOnPolicyInstalled(char *this)
{
  char *this_1; // ebx
  unsigned int v2; // ebp
  int v3; // eax
  unsigned int n3; // esi
  unsigned int v5; // edi
  _DWORD *v6; // ebx
  int v7; // edx
  int v10; // [esp+18h] [ebp-Ch]
  int v11; // [esp+1Ch] [ebp-8h]
  int v12; // [esp+20h] [ebp-4h]

  v10 = 0; /*0xffd806b9*/
  this_1 = this; /*0xffd806ba*/
  v11 = 0; /*0xffd806c0*/
  v12 = 0; /*0xffd806c1*/
  v2 = (unsigned __int8)sub_FFD8BFFD(); /*0xffd806c7*/
  if ( (v2 & 0xFFFFFFF8) > 0x18 ) /*0xffd806d2*/
  {
    v3 = GetReportStatusCodePpi(); /*0xffd806d4*/
    if ( v3 ) /*0xffd806db*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffd806ec*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchInitPreMem.c",
        958,
        "(MaxPciePortNum / 8) <= 3");
  }
  n3 = 0; /*0xffd806f2*/
  v5 = 0; /*0xffd806f4*/
  if ( v2 ) /*0xffd806f8*/
  {
    v6 = this_1 + 28; /*0xffd806fa*/
    do /*0xffd8072a*/
    {
      if ( (*v6 & 0x800) != 0 ) /*0xffd80705*/
        v7 = (unsigned __int16)*v6 >> 12; /*0xffd8070a*/
      else
        v7 = 0; /*0xffd8070f*/
      v6 += 25; /*0xffd8071e*/
      *(&v10 + (v5 >> 3)) |= v7 << (4 * (v5 & 7)); /*0xffd80723*/
      ++v5; /*0xffd80727*/
    }
    while ( v5 < v2 ); /*0xffd8072a*/
    this_1 = this; /*0xffd8072c*/
  }
  v12 |= (*(_DWORD *)(this_1 + 2755) & 0xFFFFFF80) << 21; /*0xffd80747*/
  DebugPrint(64, (int)"DRCRM: 0x%08x 0x%08x 0x%08x\n", v10, v11, v12);
  do /*0xffd80779*/
    sub_FFD8C497(4, *(&v10 + n3++)); /*0xffd8076e*/
  while ( n3 < 3 ); /*0xffd80779*/
  return sub_FFD8C578(-1, -2147254272); /*0xffd8078e*/
}

/* Source: ffd80796.c */
// positive sp value has been detected, the output may be wrong!
int __thiscall XhciUsb3Tune(int this)
{
  int v2; // ebx
  int v3; // esi
  int v4; // ebp
  int v5; // eax
  int v6; // eax
  int v7; // eax
  int v8; // eax
  int v9; // eax
  int v10; // eax
  int v11; // eax
  int v12; // eax
  bool v13; // zf
  char v14; // bl
  _BYTE *v15; // eax
  int n3; // ecx
  int v17; // edx
  int v18; // eax
  int v19; // edx
  int v20; // eax
  int v21; // eax
  int v22; // eax
  int v23; // eax
  int v24; // eax
  int v25; // eax
  int v26; // eax
  int v27; // eax
  int v28; // ecx
  _DWORD v30[3]; // [esp+4h] [ebp-14h] BYREF
  int v31; // [esp+10h] [ebp-8h] BYREF

  DebugPrint(64, (int)"PchOnPolicyInstalled() - Start\
"); /*0xffd807ab*/
  v2 = sub_FFD8CBBA(0, 31, 0); /*0xffd807c1*/
  v3 = sub_FFD8CBBA(0, 31, 2); /*0xffd807d5*/
  v4 = sub_FFD8CBBA(0, 31, 5); /*0xffd807e1*/
  v5 = sub_FFD8C632(*(_WORD *)(this + 2)); /*0xffd807e3*/
  if ( v5 < 0 ) /*0xffd807ea*/
  {
    DebugPrint(0x8000... [6904 chars total]

/* Source: ffd80ba6.c */
int __thiscall PchEarlyDisabledDeviceHandling(int *this)
{
  int v2; // esi
  int v3; // edi
  int v4; // ebx
  int v5; // ebp
  int n2_1; // ebx
  int v7; // ebx
  __int16 v8; // si
  int v9; // ebx
  int v10; // eax
  int v11; // eax
  int v12; // eax
  int v14; // [esp+10h] [ebp-54h] BYREF
  int v15; // [esp+14h] [ebp-50h] BYREF
  int v16; // [esp+18h] [ebp-4Ch] BYREF
  int n2; // [esp+1Ch] [ebp-48h]
  int v18; // [esp+20h] [ebp-44h] BYREF
  int v19; // [esp+24h] [ebp-40h] BYREF
  int v20; // [esp+28h] [ebp-3Ch] BYREF
  int v21; // [esp+2Ch] [ebp-38h] BYREF
  int v22; // [esp+30h] [ebp-34h]
  int v23; // [esp+34h] [ebp-30h] BYREF
  int n704654080; // [esp+38h] [ebp-2Ch]
  int n671099136; // [esp+3Ch] [ebp-28h]
  int n637544192; // [esp+40h] [ebp-24h]
  int n603989248; // [esp+44h] [ebp-20h]
  int n570434304; // [esp+48h] [ebp-1Ch]
  int n536879360; // [esp+4Ch] [ebp-18h]
  int n637544192_1; // [esp+50h] [ebp-14h]
  int n603989248_1; // [esp+54h] [ebp-10h]
  int n570434304_1; // [esp+58h] [ebp-Ch]
  i... [12460 chars total]

/* Source: ffd813d1.c */
int __thiscall PchEarlyInit(int *this)
{
  int v2; // eax
  int v3; // edi
  unsigned __int8 v4; // al
  unsigned __int8 v5; // al
  unsigned __int8 v6; // al
  unsigned __int8 v7; // al

  DebugPrint(64, (int)"PchEarlyInit() - Start\
"); /*0xffd813df*/
  sub_FFD82723(); /*0xffd813e4*/
  sub_FFD81769(); /*0xffd813e9*/
  sub_FFD8C497(2, 1); /*0xffd813fc*/
  sub_FFD8C5F6(255, 3); /*0xffd81414*/
  sub_FFD8C578(-2, 0); /*0xffd81425*/
  v2 = sub_FFD8CBBA(0, 31, 1); /*0xffd81431*/
  *(_DWORD *)(v2 + 128) = 0; /*0xffd8143b*/
  *(_DWORD *)(v2 + 132) = 0; /*0xffd81441*/
  *(_DWORD *)(v2 + 136) = 0; /*0xffd81447*/
  *(_DWORD *)(v2 + 140) = 0; /*0xffd8144d*/
  *(_DWORD *)(v2 + 144) = 0; /*0xffd81453*/
  *(_DWORD *)(v2 + 148) = 61440; /*0xffd81459*/
  *(_DWORD *)(v2 + 152) = 16; /*0xffd81463*/
  *(_DWORD *)(v2 + 156) = 0; /*0xffd8146d*/
  *(_BYTE *)(v2 + 244) |= 1u; /*0xffd8147d*/
  v3 = sub_FFD8CBBA(0, 31, 2); /*0xffd8148d*/
  if ( (*(_BYTE *)(v3 + 164) & 4) != 0 ) /*0xffd81499*/
  {
    __outbyte(0x74u, 0xAu); /*0xffd814a3*/
    v4 = __inbyte(0x74u); /*0xffd814a4*/
    __outbyte(0x75u, v4 & 0x8F | 0x60); /*0xffd814af*/
    __outbyte(0x74u, 0xBu); /*0xffd814b5*/
    v5 = __inbyte(0x75u); /*0xffd814b9*/
    __outbyte(0x75u, v5 | 0x80); /*0xffd814bc*/
    __outbyte(0x74u, 0xAu); /*0xffd814c2*/
    v6 = __inbyte(0x75u); /*0xffd814c6*/
    __outbyte(0x75u, v6 & 0x8F | 0x20); /*0xffd814cb*/
    __outbyte(0x74u, 0xBu); /*0xffd814d1*/
    v7 = __inbyte(0x75u); /*0xffd814d5*/
    __outbyte(0x75u, v7 & 0x7F); /*0xffd814d8*/
  }
  *(this + 4) = 16; /*0xffd814d9*/
  *(_DWORD *)(v3 + 172) &= ~0x100000u; /*0xffd814ed*/
  *(this + 53) = 0; /*0xffd814f3*/
  *(this + 61) = 0; /*0xffd814f9*/
  PchEarlyDisabledDeviceHandling(this); /*0xffd814ff*/
  sub_FFD905CC(); /*0xffd81504*/
  sub_FFD8C497(4, 0); /*0xffd81518*/
  sub_FFD8C497(4, 18875648); /*0xffd8152c*/
  sub_FFD8C497(4, 0); /*0xffd81539*/
  sub_FFD8C497(4, 18875648); /*0xffd81545*/
  return DebugPrint(64, (int)"PchEarlyInit() - End\
"); /*0xffd81559*/
}

/* Source: ffd8155f.c */
int PchInitPreMem()
{
  int v0; // eax
  int v1; // esi
  int v2; // eax
  int v3; // eax
  int v4; // esi
  int v5; // eax
  int *v7; // [esp+10h] [ebp-4h] BYREF

  DebugPrint(64, (int)"PchInitPreMem() - Start\
"); /*0xffd8156b*/
  if ( !(unsigned __int8)sub_FFD8BDC8() ) /*0xffd81572*/
  {
    DebugPrint(0x80000000, (int)"PCH SKU is not supported due to no proper PCH LPC found!\
"); /*0xffd8158b*/
    v0 = GetReportStatusCodePpi(); /*0xffd81592*/
    if ( v0 ) /*0xffd81599*/
      (*(void (__cdecl **)(const char *, int, const char *))(v0 + 4))( /*0xffd815a6*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchInitPreMem.c",
        1948,
        "((BOOLEAN)(0==1))");
  }
  v1 = sub_FFD8CBBA(0, 31, 1); /*0xffd815b8*/
  if ( (*(_DWORD *)(v1 + 16) & 0xFF000000) == 0 ) /*0xffd815c4*/
  {
    DebugPrint(64, (int)"SBREG should be programmed before here\
"); /*0xffd815cd*/
    *(_DWORD *)(v1 + 16) = -50331648; /*0xffd815d2*/
    *(_BYTE *)(v1 + 4) |= 2u; /*0xffd815e0*/
  }
  sub_FFD8C632(0x500u); /*0xffd815e8*/
  sub_FFD8C80A(); /*0xffd815ed*/
  sub_FFD8C99B(); /*0xffd815f2*/
  sub_FFD8C909((unsigned int *)&v7); /*0xffd815fb*/
  DebugPrint(64, (int)"PCH PWRM Base needs to be programmed before here\
"); /*0xffd81607*/
  if ( !v7 ) /*0xffd81613*/
  {
    v2 = GetReportStatusCodePpi(); /*0xffd81615*/
    if ( v2 ) /*0xffd8161c*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffd81629*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchInitPreMem.c",
        1993,
        "PchPwrmBase != 0");
  }
  if ( (unsigned __int8)sub_FFD8D59A() )
  {
    DebugPrint(0x80000000, (int)"DWR: DWR detected - install PPI\
");
    if ( InstallPpi(&unk_FFD98084) >= 0 )
      DebugPrint(0x80000000, (int)"DWR: DWR PPI has been installed\
");
    else
      DebugPrint(0x80000000, (int)"ERROR: Can't install DWR PPI\
");
  }
  PchFabricErrorCheck(); /*0xffd81667*/
  PchEarlyInit(v7); /*0xffd81670*/
  v3 = InstallPpi(&unk_FFD980AC); /*0xffd8167a*/
  v4 = v3; /*0xffd8167f*/
  if ( v3 < 0 ) /*0xffd81683*/
  {
    DebugPrint(0x80000000, (int)"\
ASSERT_EFI_ERROR (Status = %r)\
", v3); /*0xffd8168c*/
    v5 = GetReportStatusCodePpi(); /*0xffd81694*/
    if ( v5 ) /*0xffd8169b*/
      (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffd816a8*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchInitPreMem.c",
        2007,
        "!EFI_ERROR (Status)");
  }
  DebugPrint(64, (int)"PchInitPreMem() - End\
"); /*0xffd816b5*/
  return v4; /*0xffd816bc*/
}

/* Source: ffd816c4.c */
int PrintPchInfo()
{
  int v0; // esi
  int v1; // ecx
  __int16 v2; // ax
  double v4; // [esp-4h] [ebp-34h]
  double v5; // [esp-4h] [ebp-34h]
  double v6; // [esp-4h] [ebp-34h]
  _BYTE v7[32]; // [esp+Ch] [ebp-24h] BYREF
  int p_n32; // [esp+2Ch] [ebp-4h] BYREF

  v0 = sub_FFD8CBBA(0, 31, 0); /*0xffd816db*/
  p_n32 = 32; /*0xffd816e3*/
  sub_FFD8BE68(); /*0xffd816e6*/
  sub_FFD8C111(&p_n32); /*0xffd816f1*/
  LODWORD(v4) = v7; /*0xffd816fa*/
  DebugPrint(64, (int)"PCH Series   : %a\
", v4);
  p_n32 = 32; /*0xffd8170a*/
  sub_FFD8BB3A(v1); /*0xffd81712*/
  sub_FFD8C06D(&p_n32); /*0xffd8171d*/
  LODWORD(v5) = v7; /*0xffd81726*/
  DebugPrint(64, (int)"PCH Stepping : %a\
", v5);
  p_n32 = 32; /*0xffd81736*/
  v2 = sub_FFD8CCA5((unsigned __int16 *)(v0 + 2)); /*0xffd81740*/
  sub_FFD8C1B5(v2, v7, &p_n32); /*0xffd8174a*/
  LODWORD(v6) = v7; /*0xffd81753*/
  return DebugPrint(64, (int)"PCH SKU      : %a\
", v6);
}

/* Source: ffd821b8.c */
int __fastcall sub_FFD821B8(int a1, char a2, int a3, unsigned __int8 n2)
{
  unsigned __int8 n2_1; // bh
  char v5; // bl
  int v7; // edi
  int v8; // eax
  __int16 v9; // si
  int v10; // edx
  unsigned __int8 v11; // bl
  char v12; // al
  char v13; // al
  char n2_2; // [esp+11h] [ebp-3h] BYREF
  char v16; // [esp+12h] [ebp-2h]
  char v17; // [esp+13h] [ebp-1h] BYREF

  n2_1 = n2; /*0xffd821ba*/
  v5 = 0; /*0xffd821be*/
  v16 = a2; /*0xffd821c0*/
  if ( n2 == 1 )
  {
    DebugPrint(64, (int)"EarlyConfigurePchHSata() - First Controller - Start\
"); /*0xffd821d5*/
    v7 = sub_FFD8CBBA(0, 23, 0); /*0xffd821e9*/
    sub_FFD8C019(); /*0xffd821eb*/
  }
  else
  {
    if ( n2 != 2 )
    {
      DebugPrint(0x80000000, (int)"Error: Invalid SATA controller!\
");
      return -2147483646; /*0xffd8244e*/
    }
    DebugPrint(64, (int)"EarlyConfigurePchHSata() - Second Controller - Start\
"); /*0xffd82202*/
    v7 = sub_FFD8CBBA(0, 17, 5); /*0xffd82216*/
  }
  v8 = sub_FFD8CBBA(0, 31, 0); /*0xffd8221f*/
  v9 = sub_FFD8CCA5((unsigned __int16 *)(v8 + 2)); /*0xffd8222d*/
  if ( !(unsigned __int8)sub_FFD8D58A() ) /*0xffd82230*/
  {
    if ( n2_1 == 1 ) /*0xffd8223c*/
      v5 = sub_FFD81814(); /*0xffd82243*/
    if ( n2_1 != 2 ) /*0xffd82248*/
      goto LABEL_14; /*0xffd82248*/
    v11 = 0; /*0xffd8224a*/
    while ( 1 ) /*0xffd82253*/
    {
      sub_FFD8E7BA(v11, &n2); /*0xffd82253*/
      sub_FFD8E062(n2, &v17, &n2_2); /*0xffd82266*/
      if ( n2_2 == 2 ) /*0xffd82271*/
        break; /*0xffd82271*/
      if ( ++v11 >= 6u ) /*0xffd82278*/
      {
        v5 = 0; /*0xffd8227a*/
        goto LABEL_14; /*0xffd8227c*/
      }
    }
  }
  v5 = 1; /*0xffd8227e*/
LABEL_14:
  if ( (*(_BYTE *)a1 & 1) != 0 && (v5 || *(_DWORD *)(a1 + 4)) ) /*0xffd8228e*/
  {
    *(_BYTE *)(v7 + 160) = -104; /*0xffd82298*/
    *(_DWORD *)(v7 + 164) = *(_DWORD *)(v7 + 164) & 0xFFFFFE00 | 0x183; /*0xffd822ad*/
    *(_BYTE *)(v7 + 160) = -104; /*0xffd822b3*/
    *(_DWORD *)(v7 + 164) |= 0x8000u; /*0xffd822c5*/
    *(_BYTE *)(v7 + 160) = -92; /*0xffd822cb*/
    *(_DWORD *)(v7 + 164) |= 0x40u; /*0xffd822db*/
    if ( v9 == -24254 /*0xffd8237d*/
      || v9 == -24253
      || v9 == -24252
      || v9 == -24251
      || v9 == -24250
      || v9 == -24249
      || v9 == -24248
      || v9 == -24256
      || v9 == -24255
      || v9 == -24243
      || v9 == -24242
      || v9 == -24241
      || v9 == -25280
      || v9 == -25279
      || v9 == -25278
      || v9 == -25277
      || v9 == -25274
      || v9 == -25272 )
    {
      *(_BYTE *)(v7 + 160) = -100; /*0xffd8237f*/
      *(_DWORD *)(v7 + 164) |= 0x400000u; /*0xffd82391*/
    }
    *(_BYTE *)(v7 + 160) = -100; /*0xffd82397*/
    *(_DWORD *)(v7 + 164) = *(_DWORD *)(v7 + 164) & 0xDF63E013 | 0x209C0224; /*0xffd823ae*/
    if ( n2_1 == 1 ) /*0xffd823b7*/
    {
      *(_BYTE *)(v7 + 160) = -100; /*0xffd823b9*/
      *(_DWORD *)(v7 + 164) |= 0x40000000u; /*0xffd823cb*/
    }
    v12 = *(_BYTE *)(v7 + 156) | 0x20; /*0xffd823d7*/
    if ( *(_DWORD *)(a1 + 4) == 1 ) /*0xffd823dd*/
    {
      if ( (*(_BYTE *)(a1 + 76) & 1) != 0 ) /*0xffd823e5*/
        v12 = *(_BYTE *)(v7 + 156) & 0x1F | 0xA0; /*0xffd823e7*/
      else
        v12 = *(_BYTE *)(v7 + 156) & 0x1F | 0x60; /*0xffd823eb*/
    }
    if ( v16 ) /*0xffd823f2*/
      v13 = v12 & 0xE1 | 6; /*0xffd823f6*/
    else
      v13 = v12 & 0xE8 | 0x10; /*0xffd823fc*/
    *(_BYTE *)(v7 + 156) = v13 & 0xF8 | 6; /*0xffd8240d*/
    sub_FFD8CC4F(v7 + 148, 255); /*0xffd82413*/
    sub_FFD7FA46(2u); /*0xffd8241b*/
    DebugPrint(64, (int)"EarlyConfigurePchHSata() End\
"); /*0xffd82427*/
    return 0; /*0xffd8242c*/
  }
  else
  {
    LOBYTE(v10) = n2_1; /*0xffd82434*/
    sub_FFD81FF5(a3, v10); /*0xffd82436*/
    return 0; /*0xffd8243b*/
  }
}

/* Source: ffd8245b.c */
int __cdecl sub_FFD8245B(int n2)
{
  int v1; // ecx
  int v2; // ebx
  int v3; // edi
  int v4; // esi
  unsigned int n6; // ebp
  int v6; // eax
  unsigned __int8 n6_1; // cl
  int v8; // eax

  v2 = 0; /*0xffd82460*/
  v3 = v1; /*0xffd8246c*/
  if ( (_BYTE)n2 == 1 ) /*0xffd8246e*/
  {
    DebugPrint(64, (int)"ConfigurePchHSata() - First Controller - Start\
"); /*0xffd82477*/
    v4 = sub_FFD8CBBA(0, 23, 0); /*0xffd8248a*/
    n6 = (unsigned __int8)sub_FFD8C019(); /*0xffd82491*/
  }
  else
  {
    DebugPrint(64, (int)"ConfigurePchHSata() - Second Controller - Start\
"); /*0xffd8249d*/
    v4 = sub_FFD8CBBA(0, 17, 5); /*0xffd824b1*/
    n6 = 6; /*0xffd824b5*/
  }
  v6 = sub_FFD8CBBA(0, 31, 0); /*0xffd824bc*/
  sub_FFD8CCA5((unsigned __int16 *)(v6 + 2)); /*0xffd824c5*/
  sub_FFD81B92(n2); /*0xffd824d4*/
  if ( (*(_BYTE *)v3 & 8) != 0 ) /*0xffd824dd*/
  {
    n6_1 = 0; /*0xffd824e3*/
    if ( n6 ) /*0xffd824e7*/
    {
      v8 = 0; /*0xffd824e9*/
      do /*0xffd82506*/
      {
        if ( (*(_BYTE *)(v3 + 8 * v8 + 12) & 1) != 0 && (*(_DWORD *)(v3 + 8 * v8 + 12) & 0x40000A) != 0 ) /*0xffd824fa*/
          v2 |= 1 << v8; /*0xffd824fc*/
        v8 = ++n6_1; /*0xffd82501*/
      }
      while ( n6_1 < n6 ); /*0xffd82506*/
    }
    *(_BYTE *)(v4 + 160) = -112; /*0xffd82508*/
    *(_DWORD *)(v4 + 164) |= (unsigned __int8)~(_BYTE)v2; /*0xffd82521*/
    *(_BYTE *)(v4 + 160) = 0x80; /*0xffd8252c*/
    *(_DWORD *)(v4 + 164) |= v2 << 16; /*0xffd8253b*/
    *(_BYTE *)(v4 + 160) = -116; /*0xffd82541*/
    *(_DWORD *)(v4 + 164) |= 0xFF00FFu; /*0xffd82550*/
    *(_BYTE *)(v4 + 160) = -96; /*0xffd82556*/
    *(_DWORD *)(v4 + 164) = *(_DWORD *)(v4 + 164) & 0xFF037FFF | 0x588000; /*0xffd8256d*/
    *(_BYTE *)(v4 + 160) = -124; /*0xffd82573*/
    *(_DWORD *)(v4 + 164) |= 0xFF00FFu; /*0xffd82582*/
    *(_BYTE *)(v4 + 160) = -92; /*0xffd82588*/
    *(_DWORD *)(v4 + 164) |= 0x4000u; /*0xffd8259a*/
    *(_BYTE *)(v4 + 160) = -52; /*0xffd825a0*/
    *(_DWORD *)(v4 + 164) = -2009296895; /*0xffd825a7*/
    *(_BYTE *)(v4 + 160) = -48; /*0xffd825b1*/
    *(_DWORD *)(v4 + 164) = *(_DWORD *)(v4 + 164) & 0xFFFF0000 | 0x8828; /*0xffd825c8*/
    *(_BYTE *)(v4 + 160) = -56; /*0xffd825ce*/
    *(_DWORD *)(v4 + 164) |= 8u; /*0xffd825de*/
    *(_BYTE *)(v4 + 160) = -56; /*0xffd825e4*/
    *(_DWORD *)(v4 + 164) |= 1u; /*0xffd825f4*/
    *(_BYTE *)(v4 + 160) = -56; /*0xffd825fa*/
    *(_DWORD *)(v4 + 164) |= 2u; /*0xffd8260a*/
  }
  *(_BYTE *)(v4 + 160) = -88; /*0xffd82610*/
  *(_DWORD *)(v4 + 164) &= 0xFFF0FFFF; /*0xffd82622*/
  *(_BYTE *)(v4 + 160) = -44; /*0xffd82628*/
  *(_DWORD *)(v4 + 164) = *(_DWORD *)(v4 + 164) & 0xC0C0E0E0 | 0x2C1E1108; /*0xffd8263f*/
  *(_BYTE *)(v4 + 158) &= ~1u; /*0xffd8264d*/
  if ( *(_DWORD *)(v3 + 4) == 1 ) /*0xffd82657*/
    *(_BYTE *)(v4 + 158) |= 1u; /*0xffd82661*/
  if ( (_BYTE)n2 == 1 ) /*0xffd8266c*/
    return DebugPrint(64, (int)"ConfigurePchHSata() - First Controller - End\
"); /*0xffd82673*/
  else
    return DebugPrint(64, (int)"ConfigurePchHSata() - Second Controller - End\
"); /*0xffd8267c*/
}

/* Source: ffd826ae.c */
bool __fastcall sub_FFD826AE(int a1, int a2, char a3)
{
  int v5; // eax
  int v6; // ecx
  int n17; // [esp+Ch] [ebp-10h] BYREF
  int v9; // [esp+10h] [ebp-Ch]
  int v10; // [esp+14h] [ebp-8h] BYREF
  char n2; // [esp+1Bh] [ebp-1h]

  v5 = sub_FFD8AD54(); /*0xffd826bb*/
  (*(void (__cdecl **)(int, int *))(*(_DWORD *)v5 + 40))(v5, &n17); /*0xffd826c7*/
  n2 = *(_BYTE *)(100 * a2 + a1 + 5); /*0xffd826d6*/
  sub_FFD8D75C(&v10); /*0xffd826dd*/
  v6 = sub_FFD8CBBA(0, v9, v10); /*0xffd826f3*/
  return (!n2 || n2 == 2) && n17 == 17 && (*(_BYTE *)(v6 + 76) & 0xFu) >= 3 && a3 == 1; /*0xffd8271c*/
}

/* Source: ffd83186.c */
int __thiscall sub_FFD83186(char *this)
{
  int v2; // eax
  int v3; // eax
  int v4; // eax
  int v5; // eax
  int v6; // esi
  double v8; // [esp-4h] [ebp-20h]
  int v9; // [esp+14h] [ebp-8h] BYREF

  v2 = sub_FFD8D75C(&v9); /*0xffd8319f*/
  if ( v2 < 0 ) /*0xffd831b1*/
  {
    DebugPrint(0x80000000, (int)"\
ASSERT_EFI_ERROR (Status = %r)\
", v2); /*0xffd831be*/
    v3 = GetReportStatusCodePpi(); /*0xffd831c6*/
    if ( v3 ) /*0xffd831cd*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffd831d6*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchRootPorts.c",
        1132,
        "!EFI_ERROR (Status)");
  }
  v4 = sub_FFD9041E(&v9); /*0xffd831e8*/
  if ( v4 < 0 ) /*0xffd831f0*/
  {
    DebugPrint(0x80000000, (int)"\
ASSERT_EFI_ERROR (Status = %r)\
", v4); /*0xffd831fd*/
    v5 = GetReportStatusCodePpi(); /*0xffd83205*/
    if ( v5 ) /*0xffd8320c*/
      (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffd83215*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchRootPorts.c",
        1135,
        "!EFI_ERROR (Status)");
  }
  v6 = (unsigned __int16)v9 >> 14; /*0xffd83225*/
  LODWORD(v8) = off_FFD93F7C[v6]; // "4x1" /*0xffd83228*/
  DebugPrint(64, (int)"PCIe SP%c is %a\
", this + 65, v8); /*0xffd83237*/
  return v6; /*0xffd83241*/
}

/* Source: ffd85246.c */
int __fastcall sub_FFD85246(int a1, int a2, int a3)
{
  int n15000_6; // edi
  int v5; // ebx
  int n15000_5; // esi
  unsigned __int8 v7; // al
  int v8; // ebp
  _DWORD *n15000_8; // ebp
  int v10; // edi
  int v11; // esi
  unsigned __int8 v12; // al
  int v13; // edi
  unsigned int v14; // eax
  int v15; // ecx
  unsigned __int8 v16; // al
  int v17; // esi
  int v18; // eax
  bool v19; // zf
  unsigned __int16 *i; // ecx
  int v21; // ecx
  _WORD *n15000_7; // esi
  int v23; // edi
  int v24; // edx
  int v25; // ebx
  int v26; // esi
  int v27; // eax
  int j; // ebx
  int n15000_3; // edi
  int v30; // eax
  unsigned int j_1; // ecx
  int v32; // esi
  unsigned int v33; // edx
  int v34; // edx
  char *v35; // edi
  int v36; // ecx
  char v37; // al
  int v38; // ebx
  int v39; // edi
  int v40; // esi
  int n15000_4; // edx
  unsigned int v42; // ecx
  int v43; // eax
  int v44; // eax
  unsigned __int8 v46; // [esp+10h] [ebp-48h]
  unsigned __int8 v47; // [esp+11h] [ebp-47h]
 ... [11197 chars total]

/* Source: ffd85f37.c */
int sub_FFD85F37()
{
  int v0; // eax
  int v1; // eax
  int v2; // esi
  int v3; // eax
  _DWORD v5[2]; // [esp+8h] [ebp-8h] BYREF

  v0 = GetPeiServicesPtr(); /*0xffd85f3e*/
  v1 = (*(int (__cdecl **)(int, void *, _DWORD, _DWORD, _DWORD *))(*(_DWORD *)v0 + 32))(v0, &unk_FFD97EEC, 0, 0, v5); /*0xffd85f53*/
  v2 = v1; /*0xffd85f56*/
  if ( v1 < 0 )
  {
    DebugPrint(0x80000000, (int)"ERROR: DWR Can't find PCH Policy (Status: %r)\n", v1);
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v2); /*0xffd85f78*/
    v3 = GetReportStatusCodePpi(); /*0xffd85f80*/
    if ( v3 ) /*0xffd85f88*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffd85f99*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchRootPorts.c",
        4100,
        "!EFI_ERROR (Status)");
    v5[1] = 0; /*0xffd85f9f*/
    while ( 1 ) /*0xffd85fa2*/
      ; /*0xffd85fa2*/
  }
  return (unsigned __int8)(*(_DWORD *)(v5[0] + 2975) >> 18); /*0xffd85faa*/
}

/* Source: ffd86e4d.c */
int __usercall sub_FFD86E37@<eax>(int a1@<edx>, int a2@<ecx>, int a3, int a4, int a5, int a6, int a7, ...)
{
  int v7; // ebx
  unsigned int n8_3; // esi
  unsigned int v9; // edi
  unsigned __int8 *v10; // ebx
  unsigned __int8 n8; // al
  int n8_4; // ebp
  int v13; // eax
  unsigned int n8_1; // ecx
  _DWORD *v15; // edx
  int v16; // eax
  unsigned int v17; // edi
  unsigned __int8 *v18; // ebp
  unsigned __int8 n8_2; // al
  int n8_5; // ebx
  int v21; // eax
  _DWORD *v22; // ecx
  int result; // eax
  unsigned int retaddr; // [esp+5Ch] [ebp+0h]
  int v27; // [esp+74h] [ebp+18h] BYREF
  va_list va; // [esp+74h] [ebp+18h]
  int v29; // [esp+78h] [ebp+1Ch]
  int v30; // [esp+7Ch] [ebp+20h]
  int v31; // [esp+80h] [ebp+24h]
  int v32; // [esp+84h] [ebp+28h]
  int v33; // [esp+88h] [ebp+2Ch]
  int v34; // [esp+8Ch] [ebp+30h]
  int v35; // [esp+90h] [ebp+34h]
  va_list va1; // [esp+94h] [ebp+38h] BYREF

  va_start(va1, a7);
  va_start(va, a7);
  v27 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v29 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v30 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v31 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v32 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v33 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v34 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v35 = va_arg(va1, _DWORD); /*0xffd86e37*/
  v7 = a2; /*0xffd86e3e*/
  sub_FFD8D4C8(va1, retaddr); /*0xffd86e4f*/
  sub_FFD8D4C8((int *)va, retaddr); /*0xffd86e5b*/
  sub_FFD8BF54(); /*0xffd86e60*/
  n8_3 = 0; /*0xffd86e65*/
  v9 = 0; /*0xffd86e67*/
  if ( (unsigned __int8)sub_FFD8C051() ) /*0xffd86e69*/
  {
    v10 = (unsigned __int8 *)(v7 + 264); /*0xffd86e72*/
    do /*0xffd86ebd*/
    {
      n8 = *v10; /*0xffd86e78*/
      if ( *v10 != 8 ) /*0xffd86e7c*/
      {
        n8_4 = n8; /*0xffd86e7e*/
        if ( n8 >= 8u ) /*0xffd86e84*/
        {
          v13 = GetReportStatusCodePpi(); /*0xffd86e86*/
          if ( v13 ) /*0xffd86e8d*/
            (*(void (**)(void))(v13 + 4))(); /*0xffd86e9e*/
        }
        *((int *)va + n8_4) |= 1 << v9; /*0xffd86eab*/
      }
      ++v9; /*0xffd86eaf*/
      v10 += 16; /*0xffd86eb0*/
    }
    while ( v9 < (unsigned __int8)sub_FFD8C051() ); /*0xffd86ebd*/
    v7 = a2; /*0xffd86ebf*/
  }
  n8_1 = 0; /*0xffd86ec7*/
  v15 = (_DWORD *)(a1 + 208); /*0xffd86ec9*/
  do /*0xffd86edc*/
  {
    v16 = *((int *)va + n8_1++); /*0xffd86ecf*/
    *v15++ = v16; /*0xffd86ed4*/
  }
  while ( n8_1 < 8 ); /*0xffd86edc*/
  v17 = 0; /*0xffd86ede*/
  v18 = (unsigned __int8 *)(v7 + 8); /*0xffd86ee0*/
  while ( (unsigned int)(sub_FFD8BE68() - 1) <= 1 && v17 < retaddr ) /*0xffd86efb*/
  {
    n8_2 = *v18; /*0xffd86efd*/
    if ( *v18 != 8 ) /*0xffd86f02*/
    {
      n8_5 = n8_2; /*0xffd86f04*/
      if ( n8_2 >= 8u ) /*0xffd86f0a*/
      {
        v21 = GetReportStatusCodePpi(); /*0xffd86f0c*/
        if ( v21 ) /*0xffd86f13*/
          (*(void (**)(void))(v21 + 4))(); /*0xffd86f24*/
      }
      va1[n8_5] = (void *)((unsigned int)va1[n8_5] | (1 << v17)); /*0xffd86f31*/
    }
    ++v17; /*0xffd86f35*/
    v18 += 16; /*0xffd86f36*/
  }
  v22 = (_DWORD *)(a1 + 176); /*0xffd86f3f*/
  do /*0xffd86f52*/
  {
    result = (int)va1[n8_3++]; /*0xffd86f45*/
    *v22++ = result; /*0xffd86f4a*/
  }
  while ( n8_3 < 8 ); /*0xffd86f52*/
  return result; /*0xffd86f54*/
}

/* Source: ffd879ed.c */
int __thiscall sub_FFD879ED(_DWORD *this)
{
  unsigned __int8 i; // bl
  int v3; // ecx
  int v5; // [esp-4h] [ebp-20h]
  unsigned __int8 v6; // [esp+11h] [ebp-Bh]
  char v7; // [esp+12h] [ebp-Ah] BYREF
  char v8; // [esp+13h] [ebp-9h] BYREF
  _BYTE v9[2]; // [esp+14h] [ebp-8h] BYREF

  DebugPrint(64, (int)"XhciUsb3Tune() Start\n"); /*0xffd879fd*/
  for ( i = 0; i < (unsigned __int8)sub_FFD8C051(); ++i ) /*0xffd87a06*/
  {
    if ( (*(_BYTE *)(this + 4 * i + 67) & 0x81) != 0 ) /*0xffd87a22*/
    {
      sub_FFD8E3BE(); /*0xffd87a2c*/
      sub_FFD8E062(v6, &v8, &v7); /*0xffd87a41*/
      v3 = v5; /*0xffd87a4b*/
      if ( v7 == 1 ) /*0xffd87a4c*/
      {
        LOBYTE(v3) = v6; /*0xffd87a56*/
        sub_FFD8EBC8(v3, v9); /*0xffd87a58*/
        if ( (*(this + 4 * i + 67) & 1) != 0 ) /*0xffd87a6e*/
          sub_FFD8C578(-4128769, (*(this + 4 * i + 67) & 0x7E) << 15); /*0xffd87a85*/
        if ( (*(this + 4 * i + 67) & 0x80u) != 0 ) /*0xffd87a95*/
          sub_FFD8C578(-4128769, (*(this + 4 * i + 67) & 0x3F00) << 8); /*0xffd87aae*/
        sub_FFD8C578(-3, 0); /*0xffd87ac9*/
        sub_FFD8C578(-1, 2); /*0xffd87ad6*/
      }
    }
  }
  return DebugPrint(64, (int)"XhciUsb3Tune() End\n"); /*0xffd87afb*/
}

/* Source: ffd87d42.c */
int InstallPchSpiPpi()
{
  int v0; // eax
  int v1; // eax
  _DWORD *v2; // edi
  int v4; // eax
  int v5; // esi
  int v6; // eax

  DebugPrint(64, (int)"InstallPchSpi() Start\n"); /*0xffd87d4c*/
  v0 = sub_FFD8CBBA(0, 31, 5); /*0xffd87d58*/
  *(_DWORD *)(v0 + 16) = -33488896; /*0xffd87d60*/
  *(_DWORD *)(v0 + 4) |= 2u; /*0xffd87d6d*/
  v1 = sub_FFD8ADB0(104); /*0xffd87d73*/
  v2 = (_DWORD *)v1; /*0xffd87d78*/
  if ( !v1 ) /*0xffd87d7c*/
    return -2147483639; /*0xffd87d7e*/
  sub_FFD8F09A((_DWORD *)(v1 + 12)); /*0xffd87d88*/
  *v2 = -2147483632; /*0xffd87d90*/
  v2[1] = &unk_FFD97EBC; /*0xffd87d98*/
  v2[2] = v2 + 5; /*0xffd87d9f*/
  v4 = InstallPpi(v2); /*0xffd87da2*/
  v5 = v4; /*0xffd87da7*/
  if ( v4 < 0 ) /*0xffd87dab*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v4); /*0xffd87db8*/
    v6 = GetReportStatusCodePpi(); /*0xffd87dc0*/
    if ( v6 ) /*0xffd87dc7*/
      (*(void (__cdecl **)(const char *, int, const char *))(v6 + 4))( /*0xffd87dd8*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchSpi.c",
        130,
        "!EFI_ERROR (Status)");
  }
  DebugPrint(64, (int)"SPI PPI Installed\n"); /*0xffd87de5*/
  DebugPrint(64, (int)"InstallPchSpi() End\n"); /*0xffd87df1*/
  return v5; /*0xffd87dfb*/
}

/* Source: ffd87dff.c */
int __thiscall ConfigureLpcOnPolicy(_BYTE *this)
{
  int result; // eax
  int v3; // esi
  int n128; // ecx
  _DWORD v5[4]; // [esp+8h] [ebp-10h] BYREF

  result = DebugPrint(64, (int)"ConfigureLpcOnPolicy()\n"); /*0xffd87e0f*/
  if ( (*(this + 3514) & 1) == 0 ) /*0xffd87e1d*/
  {
    DebugPrint(64, (int)"Disable EnhancePort8xhDecoding\n"); /*0xffd87e26*/
    sub_FFD8D48A(v5, 16); /*0xffd87e33*/
    result = sub_FFD8CA98(v5); /*0xffd87e3b*/
    v3 = 0; /*0xffd87e40*/
    while ( 1 ) /*0xffd87e42*/
    {
      n128 = v5[v3]; /*0xffd87e42*/
      if ( (_WORD)n128 == 128 && (n128 & 0x7FFF0000) == 0x100000 ) /*0xffd87e59*/
        break; /*0xffd87e59*/
      if ( (unsigned int)++v3 >= 4 ) /*0xffd87e5f*/
        return result; /*0xffd87e5f*/
    }
    *(_DWORD *)(sub_FFD8CBBA(0, 31, 0) + 4 * v3 + 132) = 0; /*0xffd87e83*/
    return sub_FFD8C497(4, 0); /*0xffd87e8d*/
  }
  return result; /*0xffd87e94*/
}

/* Source: ffd87e99.c */
bool PchWdtIsUnexpectedReset()
{
  int v0; // esi
  int n5120; // eax
  bool result; // al
  unsigned __int16 v3; // [esp+4h] [ebp-4h] BYREF

  sub_FFD8C76F(&v3); /*0xffd87ea1*/
  v0 = v3; /*0xffd87ea6*/
  result = 0; /*0xffd87ee2*/
  if ( (sub_FFD8CD06(v3) & 0x8000u) != 0 ) /*0xffd87eb9*/
  {
    n5120 = sub_FFD8CD06(v0 + 4) & 0x1C00; /*0xffd87ed0*/
    if ( (_WORD)n5120 == 5120 || (_WORD)n5120 == 6144 ) /*0xffd87ee0*/
      return 1; /*0xffd87eb9*/
  }
  return result; /*0xffd87ee8*/
}

/* Source: ffd87eed.c */
int PchWdtInit()
{
  int v0; // eax
  int v1; // ebx
  __int16 v2; // bp
  int v3; // eax
  int result; // eax
  char v5; // cl
  _DWORD *v6; // edi
  unsigned int v7; // ebx
  unsigned int v8; // ebx
  int v9; // eax
  int v10; // eax
  int v11; // esi
  int v12; // eax
  int v13; // [esp+14h] [ebp-8h] BYREF
  int v14; // [esp+18h] [ebp-4h]

  v0 = sub_FFD8EEB6(); /*0xffd87ef4*/
  v1 = sub_FFD8CD6B(v0); /*0xffd87f00*/
  DebugPrint(64, (int)"(WDT) Readback = 0x%08x\n", v1); /*0xffd87f0a*/
  if ( (v1 & 0x4000) != 0 ) /*0xffd87f18*/
  {
    LOBYTE(v14) = 1; /*0xffd87f1c*/
    v2 = (v1 & 0x3FF) + 1; /*0xffd87f27*/
  }
  else
  {
    v14 = 0; /*0xffd87f2e*/
    v2 = 0; /*0xffd87f32*/
  }
  v3 = sub_FFD8AD54(); /*0xffd87f34*/
  result = (*(int (__cdecl **)(int, int, int, int *))(*(_DWORD *)v3 + 52))(v3, 4, 28, &v13); /*0xffd87f45*/
  if ( result >= 0 ) /*0xffd87f4d*/
  {
    v5 = v14; /*0xffd87f5c*/
    v6 = (_DWORD *)(v13 + 8); /*0xffd87f60*/
    *(_DWORD *)(v13 + 8) = unk_FFD97F0C; /*0xffd87f63*/
    *++v6 = unk_FFD97F10; /*0xffd87f64*/
    *++v6 = unk_FFD97F14; /*0xffd87f65*/
    v6[1] = unk_FFD97F18; /*0xffd87f66*/
    *(_BYTE *)(v13 + 26) = v5; /*0xffd87f75*/
    *(_WORD *)(v13 + 24) = v2; /*0xffd87f7c*/
    if ( (v1 & 0x3000000) != 0 ) /*0xffd87f82*/
    {
      DebugPrint(0x80000000, (int)"(WDT) Expiration detected.\n", v1); /*0xffd87f8b*/
      v7 = v1 & 0xFC3FFFFF | 0x3800000; /*0xffd87f99*/
    }
    else
    {
      if ( (v1 & 0x400000) == 0 || PchWdtIsUnexpectedReset() ) /*0xffd87fa9*/
      {
        DebugPrint(64, (int)"(WDT) Status OK.\n", v1); /*0xffd87fcf*/
        v8 = v1 & 0xFF7FFFFF; /*0xffd87fd7*/
      }
      else
      {
        DebugPrint(0x80000000, (int)"(WDT) Unexpected reset detected and ignored.\n"); /*0xffd87fb8*/
        v8 = v1 & 0xFF3FFFFF; /*0xffd87fbf*/
      }
      v7 = v8 | 0x3000000; /*0xffd87fdd*/
    }
    v9 = sub_FFD8EEB6(); /*0xffd87fdf*/
    sub_FFD8CD97(v9, v7); /*0xffd87fe8*/
    InstallPpi(&unk_FFD9816C); /*0xffd87ff2*/
    v10 = InstallPpi(&unk_FFD98144); /*0xffd87ffc*/
    v11 = v10; /*0xffd88001*/
    if ( v10 < 0 ) /*0xffd88005*/
    {
      DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v10); /*0xffd8800e*/
      v12 = GetReportStatusCodePpi(); /*0xffd88016*/
      if ( v12 ) /*0xffd8801d*/
        (*(void (__cdecl **)(const char *, int, const char *))(v12 + 4))( /*0xffd8802e*/
          "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\Wdt.c",
          216,
          "!EFI_ERROR (Status)");
    }
    return v11; /*0xffd88034*/
  }
  return result; /*0xffd88036*/
}

/* Source: ffd880d2.c */
int InstallPchResetPpi()
{
  int v0; // eax
  _DWORD *v1; // edi
  int v2; // eax
  int v3; // eax
  _DWORD *v4; // esi
  _DWORD *v5; // eax
  int v6; // eax
  int v7; // esi
  int v8; // eax
  int v10; // eax

  DebugPrint(64, (int)"InstallPchReset() Start\n"); /*0xffd880de*/
  v0 = sub_FFD8ADB0(40); /*0xffd880e8*/
  v1 = (_DWORD *)v0; /*0xffd880ed*/
  if ( !v0 ) /*0xffd880f1*/
    return -2147483639; /*0xffd881e7*/
  sub_FFD90233(v0 + 12); /*0xffd880fc*/
  v1[5] = PchResetInitCallback; /*0xffd88106*/
  *v1 = -2147483632; /*0xffd8810c*/
  v1[1] = &unk_FFD97FAC; /*0xffd88112*/
  v1[2] = v1 + 5; /*0xffd88119*/
  v2 = InstallPpi(v1); /*0xffd8811c*/
  if ( v2 < 0 ) /*0xffd88132*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v2); /*0xffd8813b*/
    v3 = GetReportStatusCodePpi(); /*0xffd88143*/
    if ( v3 ) /*0xffd8814a*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffd88153*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchReset.c",
        132,
        "!EFI_ERROR (Status)");
  }
  v4 = (_DWORD *)sub_FFD8ADB0(12); /*0xffd88164*/
  v5 = (_DWORD *)sub_FFD8ADB0(4); /*0xffd88166*/
  if ( !v4 || !v5 ) /*0xffd88171*/
  {
    v10 = GetReportStatusCodePpi(); /*0xffd881cd*/
    if ( v10 ) /*0xffd881d4*/
      (*(void (__cdecl **)(const char *, int, const char *))(v10 + 4))( /*0xffd881e1*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchReset.c",
        139,
        "((BOOLEAN)(0==1))");
    return -2147483639; /*0xffd881e1*/
  }
  *v5 = PchResetCallback2; /*0xffd88173*/
  *v4 = -2147483632; /*0xffd8817b*/
  v4[1] = &unk_FFD97F2C; /*0xffd88181*/
  v4[2] = v5; /*0xffd88188*/
  v6 = InstallPpi(v4); /*0xffd8818b*/
  v7 = v6; /*0xffd88190*/
  if ( v6 < 0 ) /*0xffd88194*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v6); /*0xffd8819d*/
    v8 = GetReportStatusCodePpi(); /*0xffd881a5*/
    if ( v8 ) /*0xffd881ac*/
      (*(void (__cdecl **)(const char *, int, const char *))(v8 + 4))( /*0xffd881b5*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiPchInitLib\\PchReset.c",
        153,
        "!EFI_ERROR (Status)");
  }
  DebugPrint(64, (int)"InstallPchReset() End\n"); /*0xffd881c2*/
  return v7; /*0xffd881ec*/
}

/* Source: ffd8ad54.c */
EFI_PEI_SERVICES **GetPeiServicesPtr()
{
  int v0; // esi
  int __return_address; // [esp+0h] [ebp-Ch]
  int v3; // [esp+6h] [ebp-6h]

  sub_FFD8D30B(__return_address); /*0xffd8ad5d*/
  v0 = *(_DWORD *)(v3 - 4); /*0xffd8ad65*/
  if ( !v0 ) /*0xffd8ad6a*/
    ReportStatusCode( /*0xffd8ad79*/
      (int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
      48,
      "PeiServices != ((void *) 0)");
  return v0; /*0xffd8ad81*/
}