Newer
Older
AMI-Aptio-BIOS-Reversed / PurleySktPkg / SouthClusterLbg / SiInit / Pei / SiInitPreMem / EntryDebugPerformanceTraceHub.c
@Ajax Dong Ajax Dong 2 days ago 12 KB Recovering names (cleanups)
/* Consolidated from decompiled shard files. */
/* Source: ffd7f7a1.c */
EFI_STATUS SiInitPreMemEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  int FlagBase; // eax
  int PerfStartStatus; // ecx
  void *UnusedPolicy; // ecx
  int PerfEndStatus; // ecx
  int PeiStatus; // eax
  int NotifyStatus; // eax
  int ReportStatus; // eax
  unsigned __int64 EndTsc; // [esp-Ch] [ebp-10h]

  if ( (sub_FFD9165B(1024068) & 0x80u) == 0 ) /*0xffd7f7b0*/
  {
    sub_FFD9168B(); /*0xffd7f7b2*/
    FlagBase = sub_FFD9164F(); /*0xffd7f7b7*/
    *(_BYTE *)(FlagBase + 1024068) |= 0x80u; /*0xffd7f7c3*/
  }
  DebugPrint(64, (int)"SiInitPrePolicy() Start\n"); /*0xffd7f88f*/
  TraceHubInitialize(0); /*0xffd7f898*/
  RecordPerformanceEntry(PerfStartStatus, __rdtsc()); /*0xffd7f8a3*/
  PrintPchInfo(); /*0xffd7f8a8*/
  DebugPrint(64, (int)"PchInitPrePolicy() - Start\n"); /*0xffd7f8b4*/
  PchWdtInit(); /*0xffd7f8b9*/
  InstallPchResetPpi(); /*0xffd7f8be*/
  InstallPchSpiPpi(); /*0xffd7f8c3*/
  PchInitPreMem(); /*0xffd7f8c8*/
  GpioInitEarly(); /*0xffd7f8cd*/
  DebugPrint(64, (int)"PchInitPrePolicy() - End\n"); /*0xffd7f8d9*/
  EndTsc = __rdtsc(); /*0xffd7f8e5*/
  EndPerformanceMeasurement(PerfEndStatus, EndTsc, HIDWORD(EndTsc)); /*0xffd7f8e7*/
  PeiStatus = sub_FFD8AD54(); /*0xffd7f8ec*/
  NotifyStatus = (*(int (__cdecl **)(int, void *))(*(_DWORD *)PeiStatus + 36))(PeiStatus, &unk_FFD97FEC); /*0xffd7f8f9*/
  if ( NotifyStatus < 0 ) /*0xffd7f901*/
  {
    DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", NotifyStatus); /*0xffd7f90e*/
    ReportStatus = GetReportStatusCodePpi(); /*0xffd7f916*/
    if ( ReportStatus ) /*0xffd7f91d*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatus + 4))( /*0xffd7f92e*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\SiInit\\Pei\\SiInitPreMem.c",
        155,
        "!EFI_ERROR (Status)");
  }
  DebugPrint(64, (int)"SiInitPrePolicy() - End\n"); /*0xffd7f93b*/
  return 0; /*0xffd7f947*/
}

/* Source: ffd7f97e.c */
int GetReportStatusCodePpi()
{
  int PeiServices; // eax
  _BYTE v2[4]; // [esp+0h] [ebp-8h] BYREF
  int v3; // [esp+4h] [ebp-4h] BYREF

  PeiServices = sub_FFD8AD54(); /*0xffd7f983*/
  if ( (*(int (__cdecl **)(int, void *, _DWORD, _BYTE *, int *))(*(_DWORD *)PeiServices + 32))(PeiServices, &unk_FFD97EAC, 0, v2, &v3) >= 0 ) /*0xffd7f9a2*/
    return v3; /*0xffd7f9a8*/
  else
    return 0; /*0xffd7f9a4*/
}

/* Source: ffd7f9af.c */
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 = GetReportStatusCodePpi(); /*0xffd7f9b0*/
  v3 = (int (__cdecl **)(int, int, char *))result; /*0xffd7f9b5*/
  if ( result ) /*0xffd7f9b9*/
  {
    result = sub_FFD8AD05(); /*0xffd7f9bb*/
    if ( (result & a1) != 0 ) /*0xffd7f9c6*/
      return (*v3)(a1, a2, (char *)va); /*0xffd7f9d2*/
  }
  return result; /*0xffd7f9d7*/
}

/* Source: ffd7f9d9.c */
int __fastcall ReportStatusCode(int a1, int a2, const char *Data)
{
  int result; // eax

  result = GetReportStatusCodePpi(); /*0xffd7f9df*/
  if ( result ) /*0xffd7f9e6*/
    return (*(int (__cdecl **)(int, int, const char *))(result + 4))(a1, a2, Data); /*0xffd7f9ee*/
  return result; /*0xffd7f9f4*/
}

/* Source: ffd7fa8d.c */
int __fastcall GetPerformanceLogBuffer(int *a1, int *a2)
{
  int v4; // eax
  int v5; // eax
  int v6; // eax
  int v7; // edi
  int v8; // eax
  int result; // eax
  int v10; // eax
  int v11; // eax

  if ( !a1 ) /*0xffd7fa9d*/
  {
    v4 = GetReportStatusCodePpi(); /*0xffd7fa9f*/
    if ( v4 ) /*0xffd7faa6*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffd7fab0*/
        "e:\\hs\\MdeModulePkg\\Library\\PeiPerformanceLib\\PeiPerformanceLib.c",
        57,
        "PeiPerformanceLog != ((void *) 0)");
  }
  if ( !a2 ) /*0xffd7fab8*/
  {
    v5 = GetReportStatusCodePpi(); /*0xffd7faba*/
    if ( v5 ) /*0xffd7fac1*/
      (*(void (__cdecl **)(const char *, int, const char *))(v5 + 4))( /*0xffd7facb*/
        "e:\\hs\\MdeModulePkg\\Library\\PeiPerformanceLib\\PeiPerformanceLib.c",
        58,
        "PeiPerformanceIdArray != ((void *) 0)");
  }
  v6 = sub_FFD8CE7C(&unk_FFD97F9C); /*0xffd7fad8*/
  if ( v6 ) /*0xffd7fadf*/
  {
    *a1 = v6 + 24; /*0xffd7fae9*/
    v7 = sub_FFD8CE7C(&unk_FFD97ECC); /*0xffd7faf0*/
    if ( !v7 ) /*0xffd7faf4*/
    {
      v8 = GetReportStatusCodePpi(); /*0xffd7faf6*/
      if ( v8 ) /*0xffd7fafd*/
        (*(void (__cdecl **)(const char *, int, const char *))(v8 + 4))( /*0xffd7fb07*/
          "e:\\hs\\MdeModulePkg\\Library\\PeiPerformanceLib\\PeiPerformanceLib.c",
          72,
          "GuidHob != ((void *) 0)");
    }
    result = v7 + 24; /*0xffd7fb0d*/
  }
  else
  {
    v10 = sub_FFD8CF46(&unk_FFD97F9C, 40008); /*0xffd7fb1b*/
    *a1 = v10; /*0xffd7fb22*/
    *a1 = sub_FFD8D4C8(v10, 40008); /*0xffd7fb2b*/
    v11 = sub_FFD8CF46(&unk_FFD97ECC, 4000); /*0xffd7fb39*/
    *a2 = v11; /*0xffd7fb40*/
    result = sub_FFD8D4C8(v11, 4000); /*0xffd7fb44*/
  }
  *a2 = result; /*0xffd7fb4a*/
  return result; /*0xffd7fb49*/
}

/* Source: ffd7fb51.c */
int __thiscall FindLatestPerformanceEntry(unsigned int *this)
{
  int v2; // esi
  unsigned int v3; // eax
  int v4; // ebx
  int v5; // ebp
  unsigned int v7; // [esp+8h] [ebp-4h]

  v2 = 0; /*0xffd7fb56*/
  v3 = *this; /*0xffd7fb58*/
  v7 = *this; /*0xffd7fb5a*/
  if ( *this ) /*0xffd7fb58*/
  {
    while ( 1 ) /*0xffd7fb68*/
    {
      v4 = v3 - v2 - 1; /*0xffd7fb68*/
      v5 = 40 * v4; /*0xffd7fb69*/
      if ( !*((_QWORD *)this + 5 * v4 + 5) /*0xffd7fba8*/
        && *(_UNKNOWN **)((char *)this + v5 + 8) == &unk_FFD97F8C
        && *(unsigned int *)((char *)this + v5 + 12) == (*(this + 10 * v4 + 11) | *(this + 10 * v4 + 10))
        && !sub_FFD8D0FF(7)
        && !sub_FFD8D0FF(7) )
      {
        break; /*0xffd7fba8*/
      }
      v3 = v7; /*0xffd7fbb2*/
      if ( ++v2 >= v7 ) /*0xffd7fbb9*/
        return v2; /*0xffd7fbb9*/
    }
    return v4; /*0xffd7fbbd*/
  }
  return v2; /*0xffd7fbc1*/
}

/* Source: ffd7fbc7.c */
int __cdecl RecordPerformanceEntry(int a1, __int64 a2)
{
  _DWORD *v2; // ecx
  int v3; // edx
  int v5; // edi
  int v6; // esi
  int v7; // eax
  int v8; // edx
  unsigned __int64 v9; // rax
  int v10; // [esp+8h] [ebp-8h] BYREF
  _DWORD *v11; // [esp+Ch] [ebp-4h] BYREF

  GetPerformanceLogBuffer((int *)&v11, &v10); /*0xffd7fbd4*/
  v2 = v11; /*0xffd7fbd9*/
  v3 = *v11; /*0xffd7fbdc*/
  if ( *v11 < 0x3E8u ) /*0xffd7fbe4*/
  {
    v5 = HIDWORD(a2); /*0xffd7fbfe*/
    v6 = 10 * v3; /*0xffd7fc04*/
    *v11 = v3 + 1; /*0xffd7fc07*/
    v2[v6 + 3] = 0; /*0xffd7fc0b*/
    v2[v6 + 10] = 0; /*0xffd7fc0f*/
    v2[v6 + 11] = 0; /*0xffd7fc13*/
    v7 = v10; /*0xffd7fc17*/
    v2[v6 + 2] = &unk_FFD97F8C; /*0xffd7fc1a*/
    *(_DWORD *)(v7 + 4 * v3) = 20704; /*0xffd7fc22*/
    v8 = a2; /*0xffd7fc29*/
    if ( !a2 ) /*0xffd7fc30*/
    {
      v9 = __rdtsc(); /*0xffd7fc32*/
      v5 = HIDWORD(v9); /*0xffd7fc34*/
      v8 = v9; /*0xffd7fc36*/
    }
    v2[v6 + 8] = v8; /*0xffd7fc38*/
    v2[v6 + 9] = v5; /*0xffd7fc3e*/
    return 0; /*0xffd7fc3c*/
  }
  else
  {
    DebugPrint(0x80000000, (int)"PEI performance log array out of resources\n"); /*0xffd7fbf0*/
    return -2147483639; /*0xffd7fbf7*/
  }
}

/* Source: ffd7fc48.c */
int __cdecl EndPerformanceMeasurement(int a1, unsigned __int64 a2)
{
  unsigned __int64 v2; // kr00_8
  unsigned int *v3; // ebx
  unsigned int v4; // eax
  int v6; // [esp+Ch] [ebp-4h] BYREF

  v2 = a2; /*0xffd7fc54*/
  if ( !a2 ) /*0xffd7fc59*/
    v2 = __rdtsc(); /*0xffd7fc5f*/
  GetPerformanceLogBuffer((int *)&a2 + 1, &v6); /*0xffd7fc67*/
  v3 = (unsigned int *)HIDWORD(a2); /*0xffd7fc6c*/
  v4 = sub_FFD7FB51((unsigned int *)HIDWORD(a2)); /*0xffd7fc74*/
  if ( v4 >= *v3 ) /*0xffd7fc7e*/
    return -2147483634; /*0xffd7fc80*/
  *(_QWORD *)&v3[10 * v4 + 10] = v2; /*0xffd7fc8b*/
  return 0; /*0xffd7fc94*/
}

/* Source: ffd7fc9b.c */
int SetTraceHubFwBar()
{
  int v0; // eax
  int v2; // esi
  int v3; // eax
  int v4; // [esp+4h] [ebp-4h] BYREF

  sub_FFD8C2A0(0xEFu, 0x2234u, 4, &v4); /*0xffd7fcb0*/
  if ( v4 < 0 ) /*0xffd7fcbf*/
  {
    DebugPrint(0x80000000, (int)"TraceHubBaseSet Error. DMIC.SRL is set.\n"); /*0xffd7fcc7*/
    v0 = GetReportStatusCodePpi(); /*0xffd7fcce*/
    if ( v0 ) /*0xffd7fcd5*/
      (*(void (__cdecl **)(const char *, int, const char *))(v0 + 4))( /*0xffd7fce3*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmTraceHubInitLib\\PeiDxeSmmTraceHubInitLib.c",
        64,
        "((BOOLEAN)(0==1))");
    return -2147483645; /*0xffd7fcee*/
  }
  v2 = sub_FFD8CBBA(0, 31, 7); /*0xffd7fcfd*/
  if ( (unsigned __int16)sub_FFD8CCA5((unsigned __int16 *)v2) == 0xFFFF ) /*0xffd7fd0e*/
  {
    v3 = GetReportStatusCodePpi(); /*0xffd7fd10*/
    if ( v3 ) /*0xffd7fd17*/
      (*(void (__cdecl **)(const char *, int, const char *))(v3 + 4))( /*0xffd7fd20*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmTraceHubInitLib\\PeiDxeSmmTraceHubInitLib.c",
        74,
        "((BOOLEAN)(0==1))");
    return -2147483645; /*0xffd7fd20*/
  }
  *(_DWORD *)(v2 + 112) = -32768000; /*0xffd7fd2c*/
  *(_DWORD *)(v2 + 116) = 0; /*0xffd7fd2f*/
  sub_FFD8C497(4, -32768000); /*0xffd7fd40*/
  sub_FFD8C497(4, 0); /*0xffd7fd50*/
  sub_FFD8C5F6(255, 2); /*0xffd7fd63*/
  return 0; /*0xffd7fd6d*/
}

/* Source: ffd7fd72.c */
int __fastcall TraceHubInitialize(char a1)
{
  int v2; // esi
  int result; // eax
  unsigned int v4; // [esp+Ch] [ebp-4h] BYREF

  DebugPrint(64, (int)"TraceHubInitialize() - Start\n"); /*0xffd7fd84*/
  sub_FFD8C909(&v4); /*0xffd7fd8c*/
  *(_BYTE *)(v4 + 1488) = 0; /*0xffd7fd9b*/
  v2 = sub_FFD8CBBA(0, 31, 7); /*0xffd7fdb0*/
  if ( (unsigned __int16)sub_FFD8CCA5((unsigned __int16 *)v2) == 0xFFFF ) /*0xffd7fdc1*/
    return DebugPrint(64, (int)"TraceHubInitialize() - End. TraceHub device is not present \n"); /*0xffd7fdc8*/
  if ( (*(_DWORD *)(v2 + 4) & 2) != 0 ) /*0xffd7fdd2*/
  {
    DebugPrint(64, (int)"TraceHubInitialize() - End. Early init done already \n"); /*0xffd7fdda*/
    DebugPrint(64, (int)"TraceHubInitialize() - FW_LBAR  = 0x%08x\n", *(_DWORD *)(v2 + 112)); /*0xffd7fde9*/
    DebugPrint(64, (int)"TraceHubInitialize() - MTB_LBAR = 0x%08x\n", *(_DWORD *)(v2 + 16)); /*0xffd7fdfb*/
    DebugPrint(64, (int)"TraceHubInitialize() - SW_LBAR  = 0x%08x\n", *(_DWORD *)(v2 + 24)); /*0xffd7fe0d*/
    result = MEMORY[0xFE1000E0]; /*0xffd7fe1a*/
    if ( (MEMORY[0xFE1000E0] & 0x1000000) != 0 ) /*0xffd7fe21*/
      return DebugPrint(64, (int)"TraceHubInitialize() - Trace Hub enabled due to SCRPD0.24\n"); /*0xffd7fe2c*/
  }
  else
  {
    DebugPrint(64, (int)"TraceHubInitialize() - Setting MTB_BAR\n"); /*0xffd7fe37*/
    *(_DWORD *)(v2 + 16) = -32505856; /*0xffd7fe3e*/
    *(_DWORD *)(v2 + 20) = 0; /*0xffd7fe47*/
    *(_BYTE *)(v2 + 4) |= 2u; /*0xffd7fe4f*/
    if ( (MEMORY[0xFE1000E0] & 0x1000000) != 0 || a1 ) /*0xffd7fe62*/
    {
      MEMORY[0xFE1000CC] = 357000000; /*0xffd7fe91*/
      *(_BYTE *)(v2 + 4) = 0; /*0xffd7fe9c*/
      DebugPrint(64, (int)"TraceHubInitialize() - Setting SW_BAR\n"); /*0xffd7fe9f*/
      *(_DWORD *)(v2 + 24) = -31457280; /*0xffd7fea9*/
      *(_DWORD *)(v2 + 28) = 0; /*0xffd7feb1*/
      DebugPrint(64, (int)"TraceHubInitialize() - Setting FW_BAR\n"); /*0xffd7feb8*/
      SetTraceHubFwBar(); /*0xffd7febd*/
      DebugPrint(64, (int)"TraceHubInitialize() - Enabling MSE and BME\n"); /*0xffd7fec8*/
      *(_BYTE *)(v2 + 4) |= 6u; /*0xffd7fed8*/
      DebugPrint(64, (int)"TraceHubInitialize () Assigned BARs:\n"); /*0xffd7fedb*/
      DebugPrint(64, (int)"TraceHubInitialize () FW_LBAR  = 0x%08x\n", *(_DWORD *)(v2 + 112)); /*0xffd7feea*/
      DebugPrint(64, (int)"TraceHubInitialize () MTB_LBAR = 0x%08x\n", *(_DWORD *)(v2 + 16)); /*0xffd7fefc*/
      DebugPrint(64, (int)"TraceHubInitialize () SW_LBAR  = 0x%08x\n", *(_DWORD *)(v2 + 24)); /*0xffd7ff0e*/
      return DebugPrint(64, (int)"TraceHubInitialize () - End\n"); /*0xffd7ff1c*/
    }
    else
    {
      *(_BYTE *)(v2 + 4) = 0; /*0xffd7fe6a*/
      DebugPrint(64, (int)"TraceHubInitialize() - Clearing MTB_BAR\n"); /*0xffd7fe6d*/
      *(_DWORD *)(v2 + 16) = 0; /*0xffd7fe78*/
      return DebugPrint( /*0xffd7fe7f*/
               64,
               (int)"TraceHubInitialize() - End. STT disconnected and Trace Hub requested to be disable\n");
    }
  }
  return result; /*0xffd7ff23*/
}

/* Source: ffd7f948.c */
int __thiscall InstallPpi(void *this)
{
  int v2; // eax

  v2 = sub_FFD8AD54(); /*0xffd7f94b*/
  return (*(int (__cdecl **)(int, void *))(*(_DWORD *)v2 + 24))(v2, this); /*0xffd7f959*/
}

/* Source: ffd7f95b.c */
int __fastcall NotifyPpi(int a1, int a2, int a3, int a4)
{
  int PeiServices; // eax

  PeiServices = sub_FFD8AD54(); /*0xffd7f962*/
  return (*(int (__cdecl **)(int, int, int, int, int))(*(_DWORD *)PeiServices + 32))(PeiServices, a1, a2, a3, a4); /*0xffd7f97a*/
}