// Module: SetupConfigUpdateDxeLightningRidgeEXRP
// File: SetupConfigUpdateDxeLightningRidgeEXRP.efi
// Index: 0353
// Architecture: 64-bit
// Image size: 0xca0
// MD5: 8a04ce3470603a4b54e50906d7e1a244
// SHA256: e892a606dd1d280dbac24ec3f648453700176c5fe7b1cd1ae213e549028c4802
//
// This DXE driver registers a UBA setup config update callback for
// Lightning Ridge EXRP platform.
//

//-------------------------------------------------------------------------
// Forward declarations
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// _ModuleEntryPoint @ 0x390 (size: 0xfa)
//-------------------------------------------------------------------------
EFI_STATUS ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
 EFI_STATUS result; // rax __int64 Status; // [rsp+30h] [rbp+8h] BYREF

 ::ImageHandle = ImageHandle; /*0x396*/
 if ( !ImageHandle ) /*0x3a3*/
 DebugAssert( /*0x3b6*/
 "e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
 0x33u,
 "gImageHandle != ((void *) 0)");
 ::SystemTable = SystemTable; /*0x3bb*/
 if ( !SystemTable ) /*0x3c5*/
 DebugAssert( /*0x3d8*/
 "e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
 0x39u,
 "gST != ((void *) 0)");
 BootServices = SystemTable->BootServices; /*0x3e1*/
 if ( !BootServices ) /*0x3eb*/
 DebugAssert( /*0x3fe*/
 "e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
 0x3Fu,
 "gBS != ((void *) 0)");
 RuntimeServices = (__int64)SystemTable->RuntimeServices; /*0x407*/
 if ( !RuntimeServices ) /*0x411*/
 DebugAssert( /*0x424*/
 "e:\\hs\\MdePkg\\Library\\UefiRuntimeServicesTableLib\\UefiRuntimeServicesTableLib.c",
 0x2Fu,
 "gRT != ((void *) 0)");
 HobListInitFromProtocol(ImageHandle); /*0x429*/
 Status = 0; /*0x42e*/
 PlatformDebugPrint(0x80000000LL, "UBA:SETUPConfigUpdate-TypeLightningRidgeEXRP\n"); /*0x440*/
 result = ((__int64 ( *)(void *, _QWORD, __int64 *))BootServices->LocateProtocol)(&unk_B50, 0, &Status); /*0x45a*/
 if ( (result & 0x8000000000000000uLL) == 0LL ) /*0x463*/
 return (*(EFI_STATUS ( **)(__int64, void *, void *, __int64))(Status + 16))(Status, &unk_B70, &unk_B80, 24); /*0x481*/
 return result; /*0x484*/
}

//-------------------------------------------------------------------------
// HobListStubGetUnsupported @ 0x48c (size: 0xb)
//-------------------------------------------------------------------------
unsigned __int64 HobListStubGetUnsupported()
{
 return 0x800000000000000EuLL; /*0x496*/
}

//-------------------------------------------------------------------------
// GetHobList @ 0x498 (size: 0x7f)
//-------------------------------------------------------------------------
void *GetHobList()
{
 void *result; // rax unsigned __int64 n0x10; // rbx __int64 Protocol; // rax void *Result; // rcx result = (void *)qword_BB8; /*0x4a2*/
 if ( !qword_BB8 ) /*0x4ae*/
 {
 n0x10 = ((__int64 ( *)(__int64))BootServices->RaiseTPL)(31); /*0x4c7*/
 ((void ( *)(unsigned __int64))BootServices->RestoreTPL)(n0x10); /*0x4ca*/
 if ( n0x10 <= 0x10 ) /*0x4d1*/
 {
 Protocol = ((__int64 ( *)(void *, _QWORD, EFI_HANDLE *))BootServices->LocateProtocol)(&unk_B40, 0, &qword_BB8); /*0x4ee*/
 Result = (void *)qword_BB8; /*0x4f4*/
 if ( Protocol < 0 ) /*0x4fe*/
 Result = 0; /*0x4fe*/
 qword_BB8 = (EFI_HANDLE)Result; /*0x502*/
 return Result; /*0x509*/
 }
 else
 {
 return 0; /*0x4d3*/
 }
 }
 return result; /*0x511*/
}

//-------------------------------------------------------------------------
// PlatformDebugPrint @ 0x518 (size: 0x88)
//-------------------------------------------------------------------------
char PlatformDebugPrint(__int64 a1, char *UBA:SETUPConfigUpdate_TypeLightningRidgeEXRP_n, ...)
{
 char ( **HobList)(__int64, char *, __int64 *); // rax __int64 v4; // r8 char ( **HobList_1)(__int64, char *, __int64 *); // r9 unsigned __int8 v6; // al char n3_1; // al char Table; // cl va_list va; // [rsp+40h] [rbp+18h] BYREF va_start(va, UBA:SETUPConfigUpdate_TypeLightningRidgeEXRP_n);
 HobList = (char ( **)(__int64, char *, __int64 *))GetHobList(); /*0x52f*/
 v4 = 0; /*0x534*/
 HobList_1 = HobList; /*0x537*/
 if ( HobList ) /*0x53d*/
 {
 v6 = __inbyte(0x70u); /*0x543*/
 __outbyte(0x70u, v6 & 0x80 | 0x4B); /*0x548*/
 n3_1 = __inbyte(0x71u); /*0x54d*/
 Table = n3_1; /*0x54e*/
 if ( (unsigned __int8)n3_1 > 3u ) /*0x554*/
 {
 Table = Table; /*0x556*/
 if ( !Table ) /*0x55e*/
 Table = MEMORY[0xFDAF0490] & 2 | 1; /*0x56a*/
 }
 LOBYTE(HobList) = Table - 1; /*0x56e*/
 if ( (unsigned __int8)(Table - 1) <= 0xFDu ) /*0x572*/
 {
 LOBYTE(HobList) = 4; /*0x576*/
 v4 = 2147483718LL; /*0x57b*/
 if ( Table == 1 ) /*0x581*/
 v4 = 2147483652LL; /*0x581*/
 }
 if ( (v4 & a1) != 0 ) /*0x588*/
 LOBYTE(HobList) = (*HobList_1)(a1, UBA:SETUPConfigUpdate_TypeLightningRidgeEXRP_n, (__int64 *)va); /*0x597*/
 }
 return (char)HobList; /*0x59a*/
}

//-------------------------------------------------------------------------
// DebugAssert @ 0x5a0 (size: 0x3e)
//-------------------------------------------------------------------------
void DebugAssert(const CHAR8 *FileName, UINTN LineNumber, const CHAR8 *Description)
{
 void ( **HobList)(const CHAR8 *, UINTN, const CHAR8 *); // rax HobList = (void ( **)(const CHAR8 *, UINTN, const CHAR8 *))GetHobList(); /*0x5b8*/
 if ( HobList ) /*0x5c0*/
 HobList[1](FileName, LineNumber, Description); /*0x5cb*/
}

//-------------------------------------------------------------------------
// HobListInitFromProtocol @ 0x5e0 (size: 0xd6)
//-------------------------------------------------------------------------
void *HobListInitFromProtocol(const GUID *ImageHandle)
{
 void *VendorTable; // rax EFI_SYSTEM_TABLE *SystemTable; // rdi UINTN NumberOfTableEntries; // rbx __int64 Index; // rsi VendorTable = (void *)VendorTable; /*0x5ef*/
 if ( !VendorTable ) /*0x5f9*/
 {
 SystemTable = SystemTable; /*0x5ff*/
 NumberOfTableEntries = 0; /*0x606*/
 VendorTable = 0; /*0x608*/
 if ( SystemTable->NumberOfTableEntries ) /*0x60f*/
 {
 Index = 0; /*0x615*/
 while ( !CompareGuid(ImageHandle, (const GUID *)&SystemTable->ConfigurationTable[Index]) ) /*0x625*/
 {
 ++NumberOfTableEntries; /*0x627*/
 ++Index; /*0x62a*/
 if ( NumberOfTableEntries >= SystemTable->NumberOfTableEntries ) /*0x632*/
 goto LABEL_6; /*0x632*/
 }
 VendorTable = SystemTable->ConfigurationTable[NumberOfTableEntries].VendorTable; /*0x6a8*/
 VendorTable = (__int64)VendorTable; /*0x6ad*/
 }
 else
 {
LABEL_6:
 PlatformDebugPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", 0x800000000000000EuLL); /*0x634*/
 DebugAssert("e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c", 0x36u, "!EFI_ERROR (Status)"); /*0x662*/
 VendorTable = (void *)VendorTable; /*0x667*/
 }
 if ( !VendorTable ) /*0x671*/
 {
 DebugAssert("e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c", 0x37u, "mHobList != ((void *) 0)"); /*0x684*/
 return (void *)VendorTable; /*0x689*/
 }
 }
 return VendorTable; /*0x69a*/
}

//-------------------------------------------------------------------------
// CompareGuid @ 0x6b8 (size: 0x6e)
//-------------------------------------------------------------------------
BOOLEAN CompareGuid(const GUID *Guid1, const GUID *Guid2)
{
 UINT64 Unaligned64; // rdi UINT64 Unaligned64_1; // rbx UINT64 Protocol; // rbp UINT64 Protocol; // rax Unaligned64 = ReadUnaligned64(&Guid2__0); /*0x6de*/
 Unaligned64_1 = ReadUnaligned64((const UINT64 *)&Guid2->Data1); /*0x6ed*/
 Protocol = ReadUnaligned64(&Guid2_); /*0x6f9*/
 Protocol = ReadUnaligned64((const UINT64 *)Guid2->Data4); /*0x6fc*/
 return Unaligned64 == Unaligned64_1 && Protocol == Protocol; /*0x720*/
}

//-------------------------------------------------------------------------
// ReadUnaligned64 @ 0x728 (size: 0x2f)
//-------------------------------------------------------------------------
UINT64 ReadUnaligned64(const UINT64 *Buffer)
{
 if ( !Buffer ) /*0x734*/
 DebugAssert("e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c", 0xC0u, "Buffer != ((void *) 0)"); /*0x749*/
 return *Buffer; /*0x751*/
}
