/*
*SmmAccessPei.c - Decompiled source for SmmAccessPei.efi
*
*Copyright (c) HR650X BIOS Decompilation Project
*/
#include "SmmAccessPei.h"
char *InternalCopyMemBackwards(char *dst, char *src, unsigned int count)
{
unsigned int count_1; // edx char *dst_1; // edi char *src_1; // esi count_1 = count; /*0xffd6bee6*/
if ( src < dst && &src[count - 1] >= dst ) /*0xffd6bef4*/
{
src_1 = &src[count - 1]; /*0xffd6bf08*/
dst_1 = &dst[count - 1]; /*0xffd6bf0a*/
}
else
{
count_1 = count & 3; /*0xffd6bef8*/
qmemcpy(dst, src, 4 * (count >> 2)); /*0xffd6bf01*/
src_1 = &src[4 * (count >> 2)]; /*0xffd6bf01*/
dst_1 = &dst[4 * (count >> 2)]; /*0xffd6bf01*/
}
qmemcpy(dst_1, src_1, count_1); /*0xffd6bf11*/
return dst; /*0xffd6bf18*/
}
void *SetMem(void *buf, unsigned int count, char value)
{
memset(buf, value, count); /*0xffd6bf49*/
return buf; /*0xffd6bf4f*/
}
int SetMem32Loop(int a1, int a2, int a3, int a4)
{
do /*0xffd6bf75*/
{
*(_DWORD *)(a1 + 8 *a2 - 8) = a3; /*0xffd6bf6d*/
*(_DWORD *)(a1 + 8 *a2-- - 4) = a4; /*0xffd6bf71*/
}
while ( a2 ); /*0xffd6bf75*/
return a1; /*0xffd6bf79*/
}
void *SetMem32(void *buf, unsigned int count, int value)
{
memset32(buf, value, count); /*0xffd6bf89*/
return buf; /*0xffd6bf8f*/
}
EFI_STATUS SmmAccessPeiEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
int SmmAccessPrivate; // ebp int Status; // eax _DWORD *PpiList; // edi int Status2; // eax _WORD *SystemBootHob; // esi int Status3; // eax _WORD *SmramHob; // ebx int Status4; // eax int DebugInterface; // eax unsigned int NumRegions; // eax _DWORD *DestDesc; // ecx unsigned int RegionIndex; // ebx int *SrcDesc; // edx int TempDesc; // eax int PpiStatus; // eax int DbgStatus; // eax int TsegSize; // ebx int TsegBase; // edi int IedSize; // esi unsigned int SavedNumRegions; // [esp+0h] [ebp-Ch]
_WORD *SavedSmramHob; // [esp+4h] [ebp-8h]
SmmAccessPrivate = AllocatePool((void *)0xA8); /*0xffd6c18b*/
if ( SmmAccessPrivate )
{
PpiList = (_DWORD *)AllocatePool((void *)0xC); /*0xffd6c1c2*/
if ( PpiList )
{
*(_DWORD *)SmmAccessPrivate = 1634562921; /*0xffd6c1f6*/
SystemBootHob = GetNextGuidHob(gEfiSystemNvDataHobGuid); /*0xffd6c202*/
if ( SystemBootHob )
{
SmramHob = GetNextGuidHob(gEfiSmmSmramMemoryGuid); /*0xffd6c23b*/
SavedSmramHob = SmramHob; /*0xffd6c23d*/
if ( SmramHob )
{
if ( *((_DWORD *)SystemBootHob + 6) > 4u ) /*0xffd6c271*/
{
DebugInterface = GetDebugInterface(); /*0xffd6c273*/
if ( DebugInterface ) /*0xffd6c27a*/
(*(void ( **)(const char *, int, const char *))(DebugInterface + 4))( /*0xffd6c28b*/
"e:\\hs\\PurleySktPkg\\Smm\\SmmAccessPei\\SmmAccessPei.c",
325,
"DescriptorBlock->NumberOfSmmReservedRegions <= 4");
}
NumRegions = 0; /*0xffd6c291*/
if ( *((_DWORD *)SystemBootHob + 6) ) /*0xffd6c293*/
{
DestDesc = (_DWORD *)(SmmAccessPrivate + 40); /*0xffd6c298*/
RegionIndex = 0; /*0xffd6c29b*/
SrcDesc = (int *)(SystemBootHob + 20); /*0xffd6c29d*/
do /*0xffd6c2d8*/
{
++RegionIndex; /*0xffd6c2a3*/
*(DestDesc - 2) = *(SrcDesc - 2); /*0xffd6c2a4*/
*(DestDesc - 1) = *(SrcDesc - 1); /*0xffd6c2aa*/
TempDesc = *SrcDesc; /*0xffd6c2ad*/
SrcDesc += 8; /*0xffd6c2af*/
*DestDesc = TempDesc; /*0xffd6c2b2*/
DestDesc += 8; /*0xffd6c2b4*/
*(DestDesc - 7) = *(SrcDesc - 7); /*0xffd6c2ba*/
*(DestDesc - 6) = *(SrcDesc - 6); /*0xffd6c2c0*/
*(DestDesc - 5) = *(SrcDesc - 5); /*0xffd6c2c6*/
*(DestDesc - 4) = *(SrcDesc - 4); /*0xffd6c2cc*/
*(DestDesc - 3) = *(SrcDesc - 3); /*0xffd6c2d2*/
}
while ( RegionIndex < *((_DWORD *)SystemBootHob + 6) ); /*0xffd6c2d8*/
SavedNumRegions = RegionIndex; /*0xffd6c2da*/
SmramHob = SavedSmramHob; /*0xffd6c2de*/
NumRegions = SavedNumRegions; /*0xffd6c2e2*/
}
*(_DWORD *)(SmmAccessPrivate + 28) = NumRegions; /*0xffd6c2ea*/
*(_DWORD *)(SmmAccessPrivate + 8) = &loc_FFD6BF9A; /*0xffd6c2f0*/
*(_DWORD *)(SmmAccessPrivate + 12) = &loc_FFD6C010; /*0xffd6c2f6*/
*(_DWORD *)(SmmAccessPrivate + 16) = &loc_FFD6C0B4; /*0xffd6c2fd*/
*(_DWORD *)(SmmAccessPrivate + 20) = &loc_FFD6C11A; /*0xffd6c304*/
*(_WORD *)(SmmAccessPrivate + 24) = 0; /*0xffd6c30b*/
*PpiList = -2147483632; /*0xffd6c311*/
PpiList[1] = &gEfiPeiSmmAccessPpiGuid; /*0xffd6c317*/
PpiList[2] = SmmAccessPrivate + 8; /*0xffd6c31e*/
PpiStatus = (*(int ( **)(EFI_SYSTEM_TABLE *, _DWORD *))(LODWORD(SystemTable->Hdr.Signature) + 24))( /*0xffd6c325*/
SystemTable,
PpiList);
if ( PpiStatus < 0 ) /*0xffd6c331*/
{
DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", PpiStatus); /*0xffd6c33a*/
DbgStatus = GetDebugInterface(); /*0xffd6c342*/
if ( DbgStatus ) /*0xffd6c349*/
(*(void ( **)(const char *, int, const char *))(DbgStatus + 4))( /*0xffd6c35a*/
"e:\\hs\\PurleySktPkg\\Smm\\SmmAccessPei\\SmmAccessPei.c",
346,
"!EFI_ERROR (Status)");
}
TsegSize = *((_DWORD *)SmramHob + 74); /*0xffd6c363*/
TsegBase = *(_DWORD *)(32 * *(_DWORD *)(SmmAccessPrivate + 28) + SmmAccessPrivate); /*0xffd6c36c*/
DebugPrint(0x80000000, "TSEG Base: %08X\n", TsegBase);
DebugPrint(0x80000000, "TSEG Size: %08X\n", TsegSize);
IedSize = *((_DWORD *)SavedSmramHob + 75); /*0xffd6c391*/
DebugPrint(
0x80000000,
"IED Base: %08X\n",
TsegBase + *(_DWORD *)(32 * *(_DWORD *)(SmmAccessPrivate + 28) + SmmAccessPrivate + 16));
DebugPrint(0x80000000, "IED Size: %08X\n", IedSize);
DebugPrint(
0x80000000,
"SMM Base: %08X\n",
*(_DWORD *)(32 * *(_DWORD *)(SmmAccessPrivate + 28) + SmmAccessPrivate));
DebugPrint(
0x80000000,
"SMM Size: %08X\n",
*(_DWORD *)(32 * *(_DWORD *)(SmmAccessPrivate + 28) + SmmAccessPrivate + 16));
*(_BYTE *)(SmmAccessPrivate + 160) = TsegSize; /*0xffd6c3e6*/
return 0; /*0xffd6c3ec*/
}
else
{
Status4 = GetDebugInterface(); /*0xffd6c245*/
if ( Status4 ) /*0xffd6c24c*/
(*(void ( **)(const char *, int, const char *))(Status4 + 4))( /*0xffd6c25d*/
"e:\\hs\\PurleySktPkg\\Smm\\SmmAccessPei\\SmmAccessPei.c",
316,
"GuidHob != ((void *) 0)");
return -2147483634; /*0xffd6c263*/
}
}
else
{
Status3 = GetDebugInterface(); /*0xffd6c208*/
if ( Status3 ) /*0xffd6c20f*/
(*(void ( **)(const char *, int, const char *))(Status3 + 4))( /*0xffd6c220*/
"e:\\hs\\PurleySktPkg\\Smm\\SmmAccessPei\\SmmAccessPei.c",
307,
"GuidHob != ((void *) 0)");
return -2147483634; /*0xffd6c226*/
}
}
else
{
Status2 = GetDebugInterface(); /*0xffd6c1c8*/
if ( Status2 ) /*0xffd6c1cf*/
(*(void ( **)(const char *, int, const char *))(Status2 + 4))( /*0xffd6c1e0*/
"e:\\hs\\PurleySktPkg\\Smm\\SmmAccessPei\\SmmAccessPei.c",
293,
"PpiList");
return -2147483639; /*0xffd6c1e6*/
}
}
else
{
Status = GetDebugInterface(); /*0xffd6c191*/
if ( Status ) /*0xffd6c198*/
(*(void ( **)(const char *, int, const char *))(Status + 4))( /*0xffd6c1a9*/
"e:\\hs\\PurleySktPkg\\Smm\\SmmAccessPei\\SmmAccessPei.c",
287,
"SmmAccessPrivate");
return -2147483639; /*0xffd6c1af*/
}
}
int GetFirstHob()
{
int PeiServicesTable; // eax int Status; // eax int DebugInterface; // eax int Status2; // eax int HobList; // [esp+4h] [ebp-4h] BYREF PeiServicesTable = GetPeiServicesTable(); /*0xffd6c3fb*/
Status = (*(int ( **)(int, int *))(*(_DWORD *)PeiServicesTable + 48))(PeiServicesTable, &HobList); /*0xffd6c407*/
if ( Status < 0 ) /*0xffd6c413*/
{
DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffd6c420*/
DebugInterface = GetDebugInterface(); /*0xffd6c428*/
if ( DebugInterface ) /*0xffd6c42f*/
(*(void ( **)(const char *, int, const char *))(DebugInterface + 4))( /*0xffd6c439*/
"e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
50,
"!EFI_ERROR (Status)");
}
if ( !HobList ) /*0xffd6c443*/
{
Status2 = GetDebugInterface(); /*0xffd6c445*/
if ( Status2 ) /*0xffd6c44c*/
(*(void ( **)(const char *, int, const char *))(Status2 + 4))( /*0xffd6c456*/
"e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
51,
"HobList != ((void *) 0)");
}
return HobList; /*0xffd6c45f*/
}
_WORD *GetNextHobByType(int Type, _WORD *HobStart)
{
_WORD *HobEntry; // esi int DebugInterface; // eax HobEntry = HobStart; /*0xffd6c465*/
if ( !HobStart ) /*0xffd6c469*/
{
DebugInterface = GetDebugInterface(); /*0xffd6c46b*/
if ( DebugInterface ) /*0xffd6c472*/
(*(void ( **)(const char *, int, const char *))(DebugInterface + 4))( /*0xffd6c480*/
"e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
82,
"HobStart != ((void *) 0)");
}
while ( 1 ) /*0xffd6c499*/
{
if ( *HobEntry == 0xFFFF ) /*0xffd6c49f*/
return 0; /*0xffd6c4a4*/
if ( *HobEntry == 4 ) /*0xffd6c491*/
break; /*0xffd6c491*/
HobEntry = (_WORD *)((char *)HobEntry + (unsigned __int16)HobEntry[1]); /*0xffd6c497*/
}
return HobEntry; /*0xffd6c4a3*/
}
_WORD *__thiscall GetNextGuidHob(char *this)
{
_WORD *HobStart; // edx int Guid; // ecx _WORD *HobEntry; // eax _WORD *CurrHob; // esi for ( HobStart = (_WORD *)GetFirstHob(); ; HobStart = (_WORD *)((char *)CurrHob + (unsigned __int16)CurrHob[1]) ) /*0xffd6c4b8*/
{
HobEntry = GetNextHobByType(Guid, HobStart); /*0xffd6c4d0*/
CurrHob = HobEntry; /*0xffd6c4d5*/
if ( !HobEntry || CompareGuid(this, (int)(HobEntry + 4)) ) /*0xffd6c4c1*/
break; /*0xffd6c4c1*/
}
return CurrHob; /*0xffd6c4db*/
}
int GetDebugInterface()
{
int PeiServicesTable; // eax _BYTE Interface[4]; // [esp+0h] [ebp-8h] BYREF int DebugInstance; // [esp+4h] [ebp-4h] BYREF PeiServicesTable = GetPeiServicesTable(); /*0xffd6c4e8*/
if ( (*(int ( **)(int, void *, _DWORD, _BYTE *, int *))(*(_DWORD *)PeiServicesTable + 32))( /*0xffd6c507*/
PeiServicesTable,
&unk_FFD6CC1C,
0,
Interface,
&DebugInstance) >= 0 )
return DebugInstance; /*0xffd6c50d*/
else return 0; /*0xffd6c509*/
}
int DebugPrint(int a1, const char *a2, ...)
{
int result; // eax int ( **v3)(int, const char *, char *); // esi va_list va; // [esp+10h] [ebp+Ch] BYREF va_start(va, a2);
result = GetDebugInterface(); /*0xffd6c515*/
v3 = (int ( **)(int, const char *, char *))result; /*0xffd6c51a*/
if ( result ) /*0xffd6c51e*/
{
result = GetDebugErrorLevel(); /*0xffd6c520*/
if ( (result & a1) != 0 ) /*0xffd6c52b*/
return (*v3)(a1, a2, (char *)va); /*0xffd6c537*/
}
return result; /*0xffd6c53c*/
}
int DebugAssert(
int e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
int n48,
int PeiServices____((void__)_0))
{
int result; // eax result = GetDebugInterface(); /*0xffd6c544*/
if ( result ) /*0xffd6c54b*/
return (*(int ( **)(int, int, int))(result + 4))( /*0xffd6c553*/
e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
n48,
PeiServices____((void__)_0));
return result; /*0xffd6c559*/
}
int __thiscall AllocatePool(void *n168)
{
int PeiServicesTable; // eax int Result; // [esp+4h] [ebp-4h] BYREF PeiServicesTable = GetPeiServicesTable(); /*0xffd6c563*/
if ( (*(int ( **)(int, void *, int *))(*(_DWORD *)PeiServicesTable + 76))(PeiServicesTable, n168, &Result) >= 0 ) /*0xffd6c579*/
return Result; /*0xffd6c57f*/
else return 0; /*0xffd6c57b*/
}
char *CopyMem(char *dst, char *src, unsigned int count)
{
char *Result; // eax int DebugInterface; // eax int DbgInterface; // eax Result = dst; /*0xffd6c58e*/
if ( count ) /*0xffd6c595*/
{
if ( count - 1 > ~(unsigned int)dst ) /*0xffd6c59f*/
{
DebugInterface = GetDebugInterface(); /*0xffd6c5a1*/
if ( DebugInterface ) /*0xffd6c5a8*/
(*(void ( **)(const char *, int, const char *))(DebugInterface + 4))( /*0xffd6c5b6*/
"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
56,
"(Length - 1) <= (0xFFFFFFFF - (UINTN)DestinationBuffer)");
}
if ( count - 1 > ~(unsigned int)src ) /*0xffd6c5c3*/
{
DbgInterface = GetDebugInterface(); /*0xffd6c5c5*/
if ( DbgInterface ) /*0xffd6c5cc*/
(*(void ( **)(const char *, int, const char *))(DbgInterface + 4))( /*0xffd6c5da*/
"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
57,
"(Length - 1) <= (0xFFFFFFFF - (UINTN)SourceBuffer)");
}
if ( dst == src ) /*0xffd6c5e2*/
return dst; /*0xffd6c5e4*/
else return InternalCopyMemBackwards(dst, src, count); /*0xffd6c5eb*/
}
return Result; /*0xffd6c5f3*/
}
bool CompareGuid(char *this, int a2)
{
__int64 Guid1Data; // rax int Guid1LowVal; // ebp __int64 Guid2Data; // rax int Guid2LowVal; // edi __int64 Guid1Tail; // kr00_8 __int64 Guid2Tail; // rax int Guid2High2; // [esp+10h] [ebp-Ch]
int Guid1High; // [esp+14h] [ebp-8h]
Guid1Data = ReadUnaligned64(this); /*0xffd6c602*/
Guid1High = HIDWORD(Guid1Data); /*0xffd6c609*/
Guid1LowVal = Guid1Data; /*0xffd6c60d*/
Guid2Data = ReadUnaligned64((void *)a2); /*0xffd6c60f*/
Guid2High2 = HIDWORD(Guid2Data); /*0xffd6c617*/
Guid2LowVal = Guid2Data; /*0xffd6c61b*/
Guid1Tail = ReadUnaligned64(this + 8); /*0xffd6c629*/
Guid2Tail = ReadUnaligned64((void *)(a2 + 8)); /*0xffd6c62b*/
return Guid1LowVal == Guid2LowVal && Guid1High == Guid2High2 && Guid1Tail == Guid2Tail; /*0xffd6c64e*/
}
int GetDebugErrorLevel()
{
unsigned __int8 CmosData; // al char DbgLevelRaw; // al char DbgLevel; // cl CmosData = __inbyte(0x70u); /*0xffd6c65c*/
__outbyte(0x70u, CmosData & 0x80 | 0x4A); /*0xffd6c661*/
DbgLevelRaw = __inbyte(0x71u); /*0xffd6c668*/
DbgLevel = DbgLevelRaw; /*0xffd6c669*/
if ( (unsigned __int8)DbgLevelRaw <= 3u ) /*0xffd6c66e*/
{
LABEL_4:
if ( !DbgLevel ) /*0xffd6c689*/
return 0; /*0xffd6c689*/
goto LABEL_5; /*0xffd6c689*/
}
DbgLevel = n3; /*0xffd6c670*/
if ( !n3 ) /*0xffd6c678*/
{
DbgLevel = MEMORY[0xFDAF0490] & 2 | 1; /*0xffd6c684*/
goto LABEL_4; /*0xffd6c684*/
}
LABEL_5:
if ( DbgLevel != -1 )
return DbgLevel != 1 ? -2147483578 : -2147483644;
return 0; /*0xffd6c6a1*/
}
__int64 __thiscall ReadUnaligned64(void *this)
{
int DebugInterface; // eax if ( !this ) /*0xffd6c6aa*/
{
DebugInterface = GetDebugInterface(); /*0xffd6c6ac*/
if ( DebugInterface ) /*0xffd6c6b3*/
(*(void ( **)(const char *, int, const char *))(DebugInterface + 4))( /*0xffd6c6c4*/
"e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
192,
"Buffer != ((void *) 0)");
}
return *(_QWORD *)this; /*0xffd6c6cf*/
}
int GetPeiServicesTable()
{
int PeiServices; // esi _BYTE Idtr[2]; // [esp+4h] [ebp-8h] BYREF int IdtrBase; // [esp+6h] [ebp-6h]
ReadIdtr(Idtr); /*0xffd6c6da*/
PeiServices = *(_DWORD *)(IdtrBase - 4); /*0xffd6c6e2*/
if ( !PeiServices ) /*0xffd6c6e7*/
DebugAssert( /*0xffd6c6f6*/
(int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
48,
(int)"PeiServices != ((void *) 0)");
return PeiServices; /*0xffd6c6fe*/
}
void *__thiscall ReadIdtr(void *this)
{
void *this_1; // eax if ( !this ) /*0xffd6c709*/
DebugAssert((int)"e:\\hs\\MdePkg\\Library\\BaseLib\\X86ReadIdtr.c", 37, (int)"Idtr != ((void *) 0)"); /*0xffd6c718*/
this_1 = this; /*0xffd6c71e*/
__sidt(this); /*0xffd6c721*/
return this_1; /*0xffd6c725*/
}