Newer
Older
AMI-Aptio-BIOS-Reversed / UsbOcUpdateDxeNeonCityFPGA / UsbOcUpdateDxeNeonCityFPGA.md
@Ajax Dong Ajax Dong 2 days ago 7 KB Init

UsbOcUpdateDxeNeonCityFPGA

Function Table

Address Name Description
_ModuleEntryPoint
IsHobListGuid
DebugPrint
DebugAssert
ReadUnaligned64
Static (Module-Level) Global Variables
Address Name Type
0xC30 gST EFI_SYSTEM_TABLE* (SystemTable)
0xC38 BootServices EFI_BOOT_SERVICES* (gBS)
0xC40 gImageHandle EFI_HANDLE (ImageHandle)
0xC48 RuntimeServices EFI_RUNTIME_SERVICES* (gRT)
0xC50 qword_C50 VOID* (mDebugProtocol)
0xC58 qword_C58 VOID* (mHobList)
0xC60 byte_C60 UINT8 (mCmosDebugLevel)
static VOID mDebugProtocol; / qword_C50 at 0xC50 */
Constant Data (in .rdata and .data sections)
These constants are embedded in the .data section of the binary. They are
referenced by absolute address in the compiled code.
EFI_GUID mDebugProtocolGuid @ 0xB40 = DEBUGLIB_PROTOCOL_GUID
EFI_GUID mUbaBoardTypeProtocolGuid @ 0xB50 = UBA_BOARD_TYPE_PROTOCOL_GUID
EFI_GUID mUsbOcConfigProtocolGuid @ 0xB60 = USBOC_CONFIG_PROTOCOL_GUID
EFI_GUID mEfiHobListGuid @ 0xB70 = HOB_LIST_GUID
The GUID halves used for the optimized comparison in IsHobListGuid() reside
in the same GUID buffer:
UINT64 mEfiHobListGuidFirstHalf (first 8 bytes of GUID at 0xB70)
UINT64 mEfiHobListGuidSecondHalf (second 8 bytes of GUID at 0xB78)
UBA_USBOC_CONFIG_DATA mUsbOcConfigData @ 0xB80
Local (Forward) Function Declarations
Function Implementations
Cache ImageHandle with assertion check.
gImageHandle = ImageHandle;
Cache SystemTable with assertion check.
gST = SystemTable;
Cache BootServices from SystemTable with assertion check.
gBS = SystemTable->BootServices;
Cache RuntimeServices from SystemTable with assertion check.
gRT = SystemTable->RuntimeServices;
Locate the HOB list from the system configuration table.
Required for HOB-based drivers that follow.
GetHobList (ImageHandle);
Print debug banner identifying this driver.
Interface = NULL;
Locate the UBA NeonCityFPGA board-type protocol.
rcx = &mUbaBoardTypeProtocolGuid (UBA protocol GUID)
rdx = NULL (no registration handle)
r8 = &Interface (output pointer)
Status = gBS->LocateProtocol (
Call the board-type protocol's RegisterUsbOcConfig function at offset 0x10.
This registers the USB OC configuration protocol for NeonCityFPGA.
rcx = Interface (This pointer)
rdx = &mUsbOcConfigProtocolGuid (USB OC config protocol GUID)
r8 = &mUsbOcConfigData ("PUSB" config data structure)
r9 = sizeof(UBA_USBOC_CONFIG_DATA) = 0x10 (16 bytes for header only)
Version + Size). The port mapping tables follow the header in the same
structure but the registration function knows the total size from the
Size field within the structure.
return ((UBA_NEONCITYFPGA_BOARD_TYPE_PROTOCOL *)Interface)->RegisterUsbOcConfig (
Return cached value if already resolved.
if (mHobList != NULL) {
Initialize HOB list pointer to NULL.
Get the number of configuration table entries from gST.
TableCount = gST->NumberOfTableEntries;
If there are entries, scan them for EFI_HOB_LIST_GUID.
if (TableCount > 0) {
Get pointer to the configuration table array.
ConfigTable = gST->ConfigurationTable;
Compare current entry's VendorGuid against EFI_HOB_LIST_GUID.
The comparison splits the 16-byte GUID into two 8-byte halves:
This matches the EFI_HOB_LIST_GUID: 7739F24C-93D7-11D4-9A3A-0090273FC14D
if (IsHobListGuid (ImageHandle, &ConfigTable[Index].VendorGuid)) {
Found the HOB list entry. Extract the VendorTable pointer.
mHobList = ConfigTable[Index].VendorTable;
HOB list GUID not found in configuration table.
Raise ASSERT_EFI_ERROR with EFI_NOT_FOUND (0x800000000000000E).
DebugPrint (EFI_NOT_FOUND, "\nASSERT_EFI_ERROR (Status = %r)\n");
If mHobList is still NULL after the search, raise another assertion.
if (mHobList == NULL) {
Compare first 8 bytes of the GUID.
The reference value is the first 8 bytes of the EFI_HOB_LIST_GUID
stored in the .data section at offset 0xB70 (mEfiHobListGuidFirstHalf).
if (ReadUnaligned64 (&mEfiHobListGuidFirstHalf) != ReadUnaligned64 (GuidPtr)) {
Compare second 8 bytes of the GUID.
GuidPtr + 8 points to the second half of the 16-byte GUID structure.
return ReadUnaligned64 (&mEfiHobListGuidSecondHalf) == ReadUnaligned64 ((UINT8 *)GuidPtr + 8);
Get the DebugLib protocol interface (cached, or resolved lazily).
DebugProtocol = GetDebugProtocol ();
Read debug level from CMOS register 0x4B.
Access RTC CMOS ports 0x70/0x71:
Port 0x70 = CMOS index/address register
Port 0x71 = CMOS data register
Read current CMOS index register value, mask off NMI enable bit (bit 7)
and certain control bits (mask 0xCB), set the register address to 0x4B.
CmosValue = IoRead8 (RTC_INDEX_PORT);
Read the debug level value from CMOS data port.
DebugLevel = IoRead8 (RTC_DATA_PORT);
Determine the debug mask based on the CMOS value.
if (DebugLevel > 3) {
For values > 3, check the cached CMOS debug level (byte_C60 at 0xC60).
If the cached level is 0, fall through to the board config check.
DebugLevel = mCmosDebugLevel;
Read board configuration from MMIO register 0xFDAF0490.
This is a platform-specific register that indicates the board type
or configuration variant.
DebugLevel *= ((volatile UINT32 *)BOARD_CONFIG_MMIO_ADDR & 2) 1;**
Calculate the debug mask from the debug level.
level - 1 must be <= 0xFD (i.e., level >= 1 and level < 0xFF).
if ((DebugLevel > 0) && ((DebugLevel - 1) <= 0xFD)) {
Level **1 -> mask = 0x80000004 (DEBUG_INIT DEBUG_INFO)**
Level >1 -> mask = 0x80000046 (multiple debug flags)
if (DebugLevel == 1) {
Check if the requested ErrorLevel is enabled by the mask.
if ((DebugMask & ErrorLevel) != 0) {
Call the DebugLib protocol's DebugPrint function.
ReturnValue = ((DEBUGLIB_PROTOCOL *)DebugProtocol)->DebugPrint (
if (mDebugProtocol != NULL) {
Allocate a small pool buffer (EfiBootServicesData = 0x1F = 31) and free it.
This is a UEFI environment validation check: if the allocation succeeds
and the buffer address is within a reasonable range (<= 0x10), proceed.
On minimal or non-UEFI environments, the allocation may behave differently.
The buffer size check validates we are in a functioning UEFI environment.
Locate the DebugLib protocol using its GUID in the .data section.

Generated by HR650X BIOS Decompilation Project