Newer
Older
AMI-Aptio-BIOS-Reversed / PeiCore / PeiCore.c
@Ajax Dong Ajax Dong 2 days ago 8 KB Init
/*
 *PeiCore - Decompiled PeiCore
 *Source: Auto-generated from IDA Pro decompilation
 *
 *Decompiled from port 13364
 */

#include "PeiCore.h"

/*
 *InternalMemCopyMem at 0xffc0370c
 */
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; /*0xffc03716*/
 if ( src < dst && &src[count - 1] >= dst ) /*0xffc03724*/
 {
 src_1 = &src[count - 1]; /*0xffc03738*/
 dst_1 = &dst[count - 1]; /*0xffc0373a*/
 }
 else
 {
 count_1 = count & 3; /*0xffc03728*/
 qmemcpy(dst, src, 4 * (count >> 2)); /*0xffc03731*/
 src_1 = &src[4 * (count >> 2)]; /*0xffc03731*/
 dst_1 = &dst[4 * (count >> 2)]; /*0xffc03731*/
 }
 qmemcpy(dst_1, src_1, count_1); /*0xffc03741*/
 return dst; /*0xffc03748*/
}

/*
 *InternalMemZeroMem at 0xffc0374c
 */
void *InternalMemZeroMem(void *buf, unsigned int count)
{
 memset(buf, 0, count); /*0xffc03763*/
 return buf; /*0xffc0376a*/
}

/*
 *InternalMemSetMem at 0xffc0376c
 */
void *InternalMemSetMem(void *buf, unsigned int count, char value)
{
 memset(buf, value, count); /*0xffc03779*/
 return buf; /*0xffc0377f*/
}

/*
 *InternalFillPointerPair at 0xffc0378c
 */
int InternalFillPointerPair(int Result, int Ptr, int Temp, int Temp)
{
 do /*0xffc037a5*/
 {
 *(_DWORD *)(Result + 8 *Ptr - 8) = Temp; /*0xffc0379d*/
 *(_DWORD *)(Result + 8 *Ptr-- - 4) = Temp; /*0xffc037a1*/
 }
 while ( Ptr ); /*0xffc037a5*/
 return Result; /*0xffc037a9*/
}

/*
 *PeiServicesGetBootMode at 0xffc037ac
 */
void *PeiServicesGetBootMode(void *buf, unsigned int count, int value)
{
 memset32(buf, value, count); /*0xffc037b9*/
 return buf; /*0xffc037bf*/
}

/*
 *_ModuleEntryPoint at 0xffc03848
 */
EFI_STATUS __noreturn ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
 PeiDispatcher((char *)ImageHandle, SystemTable, 0); /*0xffc03856*/
}

/*
 *PeiInitializeMemory at 0xffc0387a
 */
void __thiscall __noreturn PeiInitializeMemory(void *this)
{
 PciCfgWriteAndHalt(this); /*0xffc0387b*/
}

/*
 *PeiInitializeFv at 0xffc038a4
 */
int __thiscall PeiInitializeFv(_DWORD *this)
{
 int FvHandle; // eax int Status; // eax int Status; // edx int Status; // ecx int LoadStatus; // eax int v6; // edx int v7; // ecx int v9; // [esp-4h] [ebp-28h]
 int v10; // [esp+14h] [ebp-10h] BYREF int v11; // [esp+18h] [ebp-Ch] BYREF int Result; // [esp+1Ch] [ebp-8h] BYREF FvHandle = *(this + 9); /*0xffc038a7*/
 v10 = 0; /*0xffc038ae*/
 Status = (*(int ( **)(_DWORD, int, _DWORD, int *))(*(_DWORD *)(FvHandle + 4) + 4))( /*0xffc038c1*/
 *(_DWORD *)(FvHandle + 4),
 4,
 *(_DWORD *)(FvHandle + 8),
 &v10);
 if ( Status < 0 ) /*0xffc038dd*/
 {
 DebugPrint(Status, Status, 0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffc038e2*/
 AssertPrint((unsigned int)"e:\\hs\\MdeModulePkg\\Core\\Pei\\PeiMain\\PeiMain.c", 0x88u, (int)"!EFI_ERROR (Status)"); /*0xffc038f2*/
 Status = v9; /*0xffc038f7*/
 }
 GetPeiServices(Status, Status); /*0xffc038f8*/
 LoadStatus = PeiLoadFileAndPrint(v10, 2, (int)&Result, (int)&v11); /*0xffc0390d*/
 if ( LoadStatus < 0 ) /*0xffc03917*/
 {
 DebugPrint(v6, v7, 0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", LoadStatus); /*0xffc0391c*/
 AssertPrint((unsigned int)"e:\\hs\\MdeModulePkg\\Core\\Pei\\PeiMain\\PeiMain.c", 0x94u, (int)"!EFI_ERROR (Status)"); /*0xffc0392c*/
 }
 return Result + (char *)PeiDispatcher - (char *)ModuleEntryPoint; /*0xffc03932*/
}

/*
 *PeiDispatcher at 0xffc03948
 */
void __noreturn PeiDispatcher(char *ImageHandle, EFI_SYSTEM_TABLE *SystemTable, char *src)
{
 bool v3; // zf int Delta; // eax unsigned int Index; // edx int v6; // eax unsigned int i; // edx int v8; // eax void *PeiServices; // ecx int SavedAuthStatus; // esi int SavedFvHandle; // edi void *v12; // ecx int FvInfoPpi; // [esp+18h] [ebp-2C0h] BYREF _DWORD PpiDescriptor[6]; // [esp+1Ch] [ebp-2BCh] BYREF char FvInfo[96]; // [esp+70h] [ebp-268h] BYREF int AuthStatus; // [esp+D0h] [ebp-208h]
 int FvHandle; // [esp+D4h] [ebp-204h]
 char HobData[36]; // [esp+2B4h] [ebp-24h] BYREF if ( src ) /*0xffc03966*/
 {
 if ( !*((_DWORD *)src + 74) ) /*0xffc03997*/
 {
 v3 = src[260] == 0; /*0xffc039a4*/
 *((_DWORD *)src + 1) = src + 88; /*0xffc039ae*/
 *((_DWORD *)src + 20) = src + 184; /*0xffc039b7*/
 Delta = *((_DWORD *)src + 64); /*0xffc039ba*/
 if ( v3 ) /*0xffc039c0*/
 {
 *((_DWORD *)src + 18) -= Delta; /*0xffc03a08*/
 *((_DWORD *)src + 10) -= Delta; /*0xffc03a0b*/
 *((_DWORD *)src + 12) -= Delta; /*0xffc03a0e*/
 *((_DWORD *)src + 7) -= Delta; /*0xffc03a11*/
 *((_DWORD *)src + 9) -= Delta; /*0xffc03a14*/
 for ( i = 0; i < 0xE0; i += 28 ) /*0xffc03a17*/
 {
 *(_DWORD *)(i + *((_DWORD *)src + 9) + 12) -= *((_DWORD *)src + 64); /*0xffc03a22*/
 *(_DWORD *)(i + *((_DWORD *)src + 9) + 16) -= *((_DWORD *)src + 64); /*0xffc03a2f*/
 }
 v8 = *((_DWORD *)src + 64); /*0xffc03a3a*/
 *((_DWORD *)src + 147) -= v8; /*0xffc03a40*/
 *((_DWORD *)src + 146) -= v8; /*0xffc03a46*/
 }
 else
 {
 *((_DWORD *)src + 18) += Delta; /*0xffc039c2*/
 *((_DWORD *)src + 10) += Delta; /*0xffc039c5*/
 *((_DWORD *)src + 12) += Delta; /*0xffc039c8*/
 *((_DWORD *)src + 7) += Delta; /*0xffc039cb*/
 *((_DWORD *)src + 9) += Delta; /*0xffc039ce*/
 for ( Index = 0; Index < 0xE0; Index += 28 ) /*0xffc039d1*/
 {
 *(_DWORD *)(Index + *((_DWORD *)src + 9) + 12) += *((_DWORD *)src + 64); /*0xffc039dc*/
 *(_DWORD *)(Index + *((_DWORD *)src + 9) + 16) += *((_DWORD *)src + 64); /*0xffc039e9*/
 }
 v6 = *((_DWORD *)src + 64); /*0xffc039f4*/
 *((_DWORD *)src + 147) += v6; /*0xffc039fa*/
 *((_DWORD *)src + 146) += v6; /*0xffc03a00*/
 }
 PeiServicesLocatePpi((_DWORD *)src + 1); /*0xffc03a4f*/
 PeiInitializeMemory(PeiServices); /*0xffc03a54*/
 }
 CopyMem(HobData, ImageHandle, 0x24u); /*0xffc03b35*/
 CopyMem((char *)&FvInfoPpi, src, 0x298u); /*0xffc03b52*/
 SavedAuthStatus = AuthStatus; /*0xffc03b57*/
 SavedFvHandle = FvHandle; /*0xffc03b62*/
 CopyMem( /*0xffc03b77*/
 FvInfo,
 ::src, // "PEI SERV<"
 0x88u);
 AuthStatus = SavedAuthStatus; /*0xffc03b7c*/
 FvHandle = SavedFvHandle; /*0xffc03b88*/
 }
 else
 {
 ZeroMem((int)&FvInfoPpi, 0x298u); /*0xffc03971*/
 FvInfoPpi = 1130980688; /*0xffc0397f*/
 CopyMem( /*0xffc0398d*/
 FvInfo,
 ::src, // "PEI SERV<"
 0x88u);
 }
 PpiDescriptor[0] = FvInfo; /*0xffc03b9a*/
 PeiServicesLocatePpi(PpiDescriptor); /*0xffc03b9e*/
 PeiInitializeMemory(v12); /*0xffc03ba3*/
}

/*
 *FvInternalGetHandle at 0xffc04028
 */
int FvInternalGetHandle(unsigned int CurrentStartAddress, int Temp)
{
 int Temp; // edx int Temp; // ecx int Temp; // edx int PeiServicesPtr; // ecx unsigned int FvCount; // esi int LoopOffset; // ebx unsigned int FvCount_2; // edx unsigned int FvCount_3; // edi int FvTable; // ebp int LoopOffset_1; // ecx unsigned int CurrentStartAddress_1; // eax unsigned int CurrentStartAddress_2; // ebp int Temp; // [esp-4h] [ebp-18h]
 int FvTable_1; // [esp+4h] [ebp-10h]
 int SavedPeiServices; // [esp+8h] [ebp-Ch]
 unsigned int FvCount_1; // [esp+10h] [ebp-4h]

 if ( *(_DWORD *)(GetPeiServices(CurrentStartAddress, Temp) - 4) == 1130980688 ) /*0xffc0403a*/
 {
 PeiServicesPtr = GetPeiServices(Temp, Temp) - 4; /*0xffc04063*/
 }
 else
 {
 AssertPrint(0xFFC0C5D8, 0xDEu, -4143612); /*0xffc0404b*/
 PeiServicesPtr = GetPeiServices(Temp, Temp); /*0xffc04056*/
 }
 SavedPeiServices = PeiServicesPtr; /*0xffc04058*/
 FvCount = *(_DWORD *)(PeiServicesPtr + 32); /*0xffc0406c*/
 LoopOffset = 0; /*0xffc0406f*/
 FvCount_1 = FvCount; /*0xffc04071*/
 FvCount_2 = FvCount; /*0xffc04075*/
 FvCount_3 = 0; /*0xffc04078*/
 if ( FvCount ) /*0xffc0407c*/
 {
 FvTable = *(_DWORD *)(PeiServicesPtr + 36); /*0xffc04082*/
 FvTable_1 = FvTable; /*0xffc04085*/
 LoopOffset_1 = 28 *FvCount; /*0xffc0408d*/
 CurrentStartAddress_1 = CurrentStartAddress; /*0xffc0408f*/
 do /*0xffc040e3*/
 {
 CurrentStartAddress_2 = *(_DWORD *)(LoopOffset + FvTable); /*0xffc04093*/
 if ( CurrentStartAddress_1 > CurrentStartAddress_2 ) /*0xffc04098*/
 {
 FvCount = FvCount_1; /*0xffc040b2*/
 CurrentStartAddress_1 = CurrentStartAddress; /*0xffc040b6*/
 if ( CurrentStartAddress <= *(_QWORD *)(CurrentStartAddress_2 + 32) /*0xffc040c2*/
 + (unsigned __int64)CurrentStartAddress_2
 - 1 )
 {
 if ( FvCount_2 == FvCount_1 /*0xffc040d3*/
 || (CurrentStartAddress_1 = CurrentStartAddress,
 *(_DWORD *)(LoopOffset_1 + FvTable_1) < CurrentStartAddress_2) )
 {
 LoopOffset_1 = LoopOffset; /*0xffc040d5*/
 FvCount_2 = FvCount_3; /*0xffc040d7*/
 }
 }
 }
 FvTable = FvTable_1; /*0xffc040d9*/
 ++FvCount_3; /*0xffc040dd*/
 LoopOffset += 28; /*0xffc040de*/
 }
 while ( FvCount_3 < FvCount ); /*0xffc040e3*/
 PeiServicesPtr = SavedPeiServices; /*0xffc040e5*/
 }
 if ( FvCount_2 >= FvCount ) /*0xffc040ef*/
 return 0; /*0xffc040f9*/
 else return *(_DWORD *)(PeiServicesPtr + 36) + 28 *FvCount_2; /*0xffc040f4*/
}