Newer
Older
AMI-Aptio-BIOS-Reversed / Build / GuidArtifacts / C9352CC3-A354-44E5-8776-B2ED8DD781EC / C9352CC3-A354-44E5-8776-B2ED8DD781EC.c
@Ajax Dong Ajax Dong 2 days ago 8 KB Full restructure
/*
 *C9352CC3-A354-44E5-8776-B2ED8DD781EC.c
 *Intel RSTe (Rapid Storage Technology enterprise) RAID Configuration Manager
 *UEFI DXE Driver
 *
 *Decompiled pseudocode - key renamed functions
 *IDA Port: 13367
 */

/* =========================================================================
 *ModuleEntryPoint (0x65F8)
 * =========================================================================
 *Entry point called by UEFI DXE core.
 *Initializes the driver, allocates protocol instance, installs protocol.
 */
EFI_STATUS EFIAPI ModuleEntryPoint (
 IN EFI_HANDLE ImageHandle,
 IN EFI_SYSTEM_TABLE *SystemTable
 )
{
 RST_PROTOCOL *Protocol;
 EFI_STATUS Status;

 RstDxeInit (ImageHandle, SystemTable);
 RstDebugInit (0);

 Protocol = RstAllocateProtocol (680, &unk_24A89);
 if (Protocol != NULL) {
 RstConstructProtocolInterface (Protocol, ImageHandle);
 Protocol->Signature = &off_244D0;
 } else {
 Protocol = NULL;
 }

 Status = Protocol->EntryPoint (Protocol); /*offset +16 from vtable */
 return Status;
}

/* =========================================================================
 *RstDxeInit (0x90E4)
 * =========================================================================
 *EFI initialization. Saves system table pointers globally.
 *Source: EfiInit.cpp
 */
__int64 RstDxeInit (
 IN EFI_HANDLE ImageHandle,
 IN EFI_SYSTEM_TABLE *SystemTable
 )
{
 gST = SystemTable;

 if (RstIsDebugEnabled () && gST == NULL) {
 RstAssertFail ("EfiInit.cpp", 26, "gST != 0");
 }

 gBS = SystemTable->BootServices;
 gRT = SystemTable->RuntimeServices;

 if (RstIsDebugEnabled () && gBS == NULL) {
 RstAssertFail ("EfiInit.cpp", 29, "gBS != 0");
 }

 if (RstIsDebugEnabled () && gRT == NULL) {
 RstAssertFail ("EfiInit.cpp", 30, "gRT != 0");
 }

 if (RstIsLogEnabled ()) {
 RstDebugPrint (64, "efiDxeInitialize: Started\n");
 }

 return RstDriverBindingStart (ImageHandle, SystemTable);
}

/* =========================================================================
 *RstDriverBindingStart (0xA208)
 * =========================================================================
 *Driver binding start. Dispatches to AHCI controller enumeration.
 */
__int64 RstDriverBindingStart (
 IN EFI_HANDLE ImageHandle,
 IN EFI_SYSTEM_TABLE *SystemTable
 )
{
 sub_2AD0 ();
 sub_2A94 (ImageHandle, SystemTable);
 return 0;
}

/* =========================================================================
 *RstConstructProtocolInterface (0x7178)
 * =========================================================================
 *Main protocol instance constructor. Sets up all function pointers
 *for the RST RAID Configuration protocol, HII language strings,
 *and calls RstHiiInit to register HII packages.
 */
__int64 RstConstructProtocolInterface (
 RST_PROTOCOL *Protocol,
 EFI_HANDLE ImageHandle
 )
{
 CHAR8 *Language;
 CHAR8 *Language2;

 Protocol->Signature = &off_24830; /*initial vtable */
 Protocol->Field_298 = 0; /*offset 664 */
 Protocol->Field_2A0 = 0; /*offset 672 */
 Protocol->Field_278 = 0; /*offset 632 */
 Protocol->Field_270 = ImageHandle; /*offset 624 */

 gController = Protocol; /*qword_34A28 */

 Protocol->Field_290 = 0; /*offset 656 */
 Protocol->Field_220 = 11; /*offset 544 */
 Protocol->Field_268 = 8; /*offset 616 */
 Protocol->Field_208 = RstDxeUnload; /*offset 520 */
 Protocol->Field_26C = (UINT32)&loc_2000A; /*offset 620 */
 Protocol->Field_210 = RstUninstallProtocols; /*offset 528 */

 /*HII language block at Protocol+8 */
 Protocol->HiiUnregister = RstUnregisterHii; /* +8+528 */
 Protocol->HiiDefaultLanguage = Protocol->HiiSupportedLanguages; /* +8+544/+8+552 */
 Protocol->HiiGetString = RstGetHiiString; /* +8+560 */
 Protocol->HiiSetString = RstSetHiiString; /* +8+568 */
 Language = &off_28610[0]; /* "en-US" */
 Protocol->HiiLanguage = Language; /* +8+576 */
 Protocol->HiiGetStringDefault = RstGetHiiStringDefault; /* +8+584 */
 Protocol->HiiNewString = RstNewString; /* +8+592 */
 Language2 = &off_28618[0]; /* "eng" */
 Protocol->HiiPlatformLanguage = Language2; /* +8+600 */

 RstZeroMem (&Protocol->HiiBlock, 0, 512); /*zero HII block */

 /* ---------- Protocol API function pointers ---------- */
 Protocol->GetArrayCount = RstGetArrayCount; /* +24 */
 Protocol->Version = 16; /* +8 */
 Protocol->GetDiskInfo = RstGetDiskInfo; /* +32 */
 Protocol->BlockSize = 512; /* +12 */
 Protocol->GetDiskDetail = RstGetDiskDetail; /* +40 */
 Protocol->CreateArray = RstCreateArray; /* +48 */
 Protocol->GetDiskState = RstGetDiskState; /* +56 */
 Protocol->IsDiskOnline = RstIsDiskOnline; /* +64 */
 Protocol->GetVolumeInfo = RstGetVolumeInfo; /* +72 */
 Protocol->SetDiskState = RstSetDiskState; /* +80 */
 Protocol->DeleteArray = RstDeleteArray; /* +88 */
 Protocol->GetFirmwareVersion = RstGetFirmwareVersion; /* +96 */
 Protocol->ResetFirmwareFlag = RstResetFirmwareFlag; /* +104 */
 Protocol->SubmitArrayOp = RstSubmitArrayOperation; /* +112 */
 Protocol->ClearDiskFault = RstClearDiskFault; /* +120 */
 Protocol->DeleteVolume = RstDeleteVolume; /* +128 */
 Protocol->IsVolumeSpanning = RstIsVolumeSpanning; /* +136 */
 Protocol->FindVolumeByRaidLevel = RstFindVolumeByRaidLevel; /* +144 */
 Protocol->GetVolumeMinCapacity = RstGetVolumeMinCapacity; /* +152 */
 Protocol->AddDiskToVolume = RstAddDiskToVolume; /* +168 */
 Protocol->StartDiskOperation = RstStartDiskOperation; /* +176 */
 Protocol->StopDiskOperation = RstStopDiskOperation; /* +184 */
 Protocol->GetArrayCountThunk = RstGetArrayCountThunk; /* +192 */
 Protocol->GetControllerCount = RstGetControllerCount; /* +200 */
 Protocol->GetActiveDiskCount = RstGetActiveDiskCount; /* +208 */
 Protocol->IsAllDisksReady = RstIsAllDisksReady; /* +216 */
 Protocol->SetDiskLedState = RstSetDiskLedState; /* +160 */
 Protocol->ForceDiskOffline = RstForceDiskOffline; /* +224 */
 Protocol->GetControllerCap = RstGetControllerCapability; /* +232 */
 Protocol->GetControllerCapThunk = RstGetControllerCapThunk; /* +240 */
 Protocol->GetDiskSerialNumber = RstGetDiskSerialNumber; /* +248 */
 Protocol->VolumeReadWrite = RstVolumeReadWrite; /* +256 */
 Protocol->StartVolumeExpansion = RstStartVolumeExpansion; /* +488 */
 Protocol->SetVolumeMetadata = RstSetVolumeMetadata; /* +472 */
 Protocol->GetNextOsDiskNumber = RstGetNextOsDiskNumber; /* +480 */
 Protocol->IsVolumeJournaling = RstIsVolumeJournaling; /* +496 */
 Protocol->DoesVolumeMatchLevel = RstDoesVolumeMatchLevel; /* +504 */
 Protocol->GetMainController = RstGetMainController; /* +336 */

 RstHiiInit ();
 return (__int64)Protocol;
}

/* =========================================================================
 *RstGetArrayCount (0xCCDC)
 * =========================================================================
 *Returns the number of arrays managed by the controller.
 *Reads from controller object at offset 128.
 */
__int16 RstGetArrayCount (
 VOID
 )
{
 return *(_WORD *)(*(_QWORD *)(gController2 + 88) + 128);
}

/* =========================================================================
 *RstGetDiskInfo (0xCF50)
 * =========================================================================
 *Returns disk information (type, block size, RAID state).
 *Fills a 32-byte RST_DISK_INFO structure.
 */
__int64 RstGetDiskInfo (
 UINT16 DiskId,
 RST_DISK_INFO *DiskInfo
 )
{
 UINT64 DiskDesc;
 UINT8 NumMembers;

 if (gController2 == NULL) return RST_ERROR_RANGE;
 DiskDesc = RstFindDiskInArray (*(_QWORD *)(gController2 + 88), DiskId);
 if (DiskDesc == NULL || DiskInfo == NULL) return RST_ERROR_RANGE;

 RstZeroMem (DiskInfo, 0, sizeof(RST_DISK_INFO));
 DiskInfo->Size = sizeof(RST_DISK_INFO);
 DiskInfo->BlockSize = RstGetDiskBlockSize (DiskDesc);
 DiskInfo->DiskType = *(UINT8 *)(DiskDesc + 20);
 NumMembers = 2;
 if (*(UINT8 *)(DiskDesc + 96) < 2) NumMembers = *(UINT8 *)(DiskDesc + 96);
 DiskInfo->Rsvd0 = NumMembers;
 DiskInfo->Reserved0 = (UINT32)RstGetDiskType (DiskDesc);
 DiskInfo->Rsvd1 = (UINT32)RstGetDiskRaidState (DiskDesc);

 return RST_SUCCESS;
}

/* =========================================================================
 *RstGetDiskDetail (0xEF78)
 * =========================================================================
 *Returns detailed disk information (176-byte structure).
 *Includes serial number, capacity, status, link speed, etc.
 */
__int64 RstGetDiskDetail (
 UINT16 DiskId,
 RST_DISK_DETAIL *DiskDetail
 )
{
 UINT64 ArrayDesc;
 UINT64 DiskDesc;
 UINT64 DiskObj;

 if (DiskDetail == NULL) return RST_ERROR_NODISK;
 if (gController2 == NULL) return RST_ERROR_NODISK;

 ArrayDesc = *(_QWORD *)(gController2 + 88);
 if (ArrayDesc == NULL) return RST_ERROR_NODISK;

 DiskDesc = RstFindDiskById (ArrayDesc + 16, DiskId);
 if (DiskDesc == NULL) return RST_ERROR_NODISK;

 DiskObj = *(_QWORD *)(DiskDesc + 48);
 if (DiskObj == NULL) return RST_ERROR_NODISK;

 RstZeroMem (DiskDetail, 0, 176);
 DiskDetail->Size = 176;

 RstCopyMem (DiskDetail->SerialNumber, DiskDesc + 18, 16);
 DiskDetail->DiskSize = *(_QWORD *)(DiskObj + 88);
 DiskDetail->Rsvd8 = RstGetDiskBlockCount (DiskObj);
 DiskDetail->Rsvd2 = *(_DWORD *)(DiskObj + 136);
 DiskDetail->Reserved0 = *(UINT8 *)(DiskDesc + 58);
 /* ... additional fields filled ... */

 RstFillDiskDetailExt (DiskDetail);
 RstCalcDiskCapacity (DiskDetail, DiskId);

 return RST_SUCCESS;
}