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

RomLayoutDxe

Function Table

Address Name Description
_ModuleEntryPoint
IsHobListGuid
DebugPrint
DebugAssert
ReturnNotFound
ReadUnaligned64
Static (Module-Level) Global Variables
Cached pointer to the DebugLib protocol interface.
Initialized lazily by GetDebugProtocol(). Located via gBS->LocateProtocol()
against the DebugLib protocol GUID stored at unk_B40 in the data section.
STATIC VOID *mDebugProtocol; // qword_BB8 at 0xBB8
Cached pointer to the HOB list.
Initialized lazily by GetHobList() by searching the system configuration
table for the EFI_HOB_LIST_GUID entry.
STATIC VOID *mHobList; // qword_BC0 at 0xBC0
Cached CMOS debug level byte (n3 at 0xBC8).
Read from CMOS register 0x4B during debug output filtering.
STATIC UINT8 mCmosDebugLevel; // n3 at 0xBC8
Constant Data (in .data section)
These are located in the .data section of the binary. They are referenced
by absolute address in the compiled code and are provided here for reference.
EFI_GUID mDebugProtocolGuid @ 0xB40 = 36232936-0E76-31C8-A13A-3AF2FC1C3932
EFI_GUID mUbaBoardTypeProtocolGuid @ 0xB50 = E03E0D46-5263-4845-B0A4-58D57B3177E2
EFI_GUID mEfiHobListGuid @ 0xB60 = 7739F24C-93D7-11D4-9A3A-0090273FC14D
EFI_GUID mUbaSetupConfigGuid @ 0xB70 = CD1F9574-DD03-4196-96AD-4965146F9665
UBA_SETUP_CONFIG_DATA mSetupConfigData @ 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.
This is required for HOB-based drivers that follow.
GetHobList (ImageHandle);
Print debug banner indicating this driver is executing.
Interface = NULL;
Locate the UBA NeonCityFPGA board-type protocol.
Status = gBS->LocateProtocol (
Call the board-type protocol's RegisterSetupConfig function at offset 0x10.
This registers the setup configuration protocol for NeonCityFPGA.
return ((UBA_NEONCITYFPGA_BOARD_TYPE_PROTOCOL *)Interface)->RegisterSetupConfig (
Return cached value if already resolved.
if (mHobList != NULL) {
Initialize HOB list pointer to NULL.
Get the number of configuration table entries.
gST + 0x68 = SystemTable->NumberOfTableEntries
TableCount = gST->NumberOfTableEntries;
If there are entries, scan them for EFI_HOB_LIST_GUID.
if (TableCount > 0) {
Get pointer to the configuration table array.
gST + 0x70 = SystemTable->ConfigurationTable
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.
Each configuration table entry is 0x18 bytes:
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.
These are at unk_B60 in the .data section (offset 0xB60).
if (ReadUnaligned64 (&mEfiHobListGuidFirstHalf) != ReadUnaligned64 (GuidPtr)) {
Compare second 8 bytes of the GUID.
These are at unk_B68 in the .data section (offset 0xB68).
In the context of the SystemTable configuration table array, each entry
is 24 bytes: 16 for GUID + 8 for pointer.
return ReadUnaligned64 (&mEfiHobListGuidSecondHalf) == ReadUnaligned64 ((UINT8 *)GuidPtr + 8);
Get the DebugLib protocol interface (cached).
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
Step 1: Read current CMOS index register value.
Step 2: Mask off bits to preserve NMI enable (bit 7 = 0x80)
and set the register address to 0x4B.
and al, 0xCB means:
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.
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.
The low byte is read: bit 1 indicates some board variant
and **bit 0 is always set. Result = (register & 2) 1.**
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)
to enter the mask calculation block.
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 output function.
Protocol interface layout:
The output function takes:
rcx = ErrorLevel
rdx = Format string
r8 = VA_LIST (variable arguments)
ReturnValue = ((DEBUGLIB_PROTOCOL *)DebugProtocol)->DebugPrint (
if (mDebugProtocol != NULL) {
Allocate a small pool buffer (EfiBootServicesData = 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 suggests we are in a valid UEFI environment with
properly functioning boot services.
Locate the DebugLib protocol.
Stored at 0xB40

Generated by HR650X BIOS Decompilation Project