# HardwareSignatureEntry

## Function Table

| Address | Name | Description |
|---------|------|-------------|
|  | **ModuleEntryPoint** |  |
|  | **HiiHardwareSignatureEntry** |  |
|  | **HiiProcessHardwareSignature** |  |
|  | **HiiReadHardwareConfigData** |  |
|  | **RecordHardwareChange** |  |
|  | **CheckCmosChecksumChanged** |  |
|  | **HardwareSignatureNotificationCallback** |  |
|  | **CalculatePhysicalMemorySize** |  |
|  | **GetHiiStringTable** |  |
|  | **GetHardwareConfigFromFormset** |  |
|  | **CompareGuid** |  |
|  | **DebugAssert** |  |
|  | **ReadUnaligned64** |  |
|  | **CalculateCheckSum8** |  |
|  | **QuickSort** |  |
|  | **FindHardwareFormset** |  |
| Globals | **// ===========================================================================** |  |
| Standard | **UEFI globals from library constructors.** |  |
| extern | **EFI_HANDLE             gImageHandle;** |  |
| UINT32 | **gChangeListIndex          = 0;   // 0x1D80** |  |
| 0x1D84 | **EFI_HII_DATABASE_PROTOCOL     *gHiiDatabase             = NULL;// 0x1DA8** |  |
| 0x1DB0 | **BOOLEAN                       gMemorySizeCached         = FALSE;//0x1DB8** |  |
| 0x1DC0 | **UINT8                         gHardwareStatusByte       = 0;   // 0x1DC4** |  |
| 0x1DC8 | **UINT32                        gHardwareConfigDword      = 0;   // 0x1DCC** |  |
| 0x1DD4 | **UINT32                        gFirmwareCapabilityDword  = 0;   // 0x1DD8** |  |
| 0x1DDC | **UINT32                        gChangeList[0x14];               // 0x1DE0** |  |
| 0x1E38 | **UINT32                        gMemorySizeMb             = 0;   // 0x1E3C** |  |
| Signature | **computation constants** |  |
| const | **INT32                   gHardwareSignatureMagic   = 117704678;  // 0x1E30** |  |
| 0x1E34 | **const UINT8                   gHardwareSignatureYear    = 14;         // 0x1E36 (2014)** |  |
| InternalCopyMem | **(sub_2C0)** |  |
| Implements | **memmove: handles forward/backward overlap.** |  |
| The | **decompiled code shows:** |  |
| from | **&dest[Length-1] down to dest[0].** |  |
| Length | **>> 3 chunk, then the Length & 7 remainder.** |  |
| return | **(CHAR8 *)CopyMem (DestinationBuffer, SourceBuffer, Length);** |  |
| ModuleEntryPoint | **(sub_384)** |  |
| UEFI | **library constructors initialise ImageHandle, SystemTable** |  |
| UefiBootServicesTableLib | **/ UefiRuntimeServicesTableLib).** |  |
| return | **HiiHardwareSignatureEntry (ImageHandle, NULL);** |  |
| HiiHardwareSignatureEntry | **(sub_430)** |  |
| Installs | **the HII Config Access protocol on a child handle and** |  |
| registers | **the notification callback (HardwareSignatureNotificationCallback)** |  |
| for | **the hardware-configuration formset.** |  |
| Zero | **the config-variable store (120 bytes).** |  |
| Install | **Config Access protocol on a new child handle.** |  |
| Status | **= gBS->InstallProtocolInterface (** |  |
| unk_1D58 | **EFI_NATIVE_INTERFACE** |  |
| off_1D30 | **);** |  |
| Register | **notify for HII Config Access protocol (unk_1C90)** |  |
| Status | **= gBS->RegisterProtocolNotify (** |  |
| Register | **notify again (unk_1CB0, same notification)** |  |
| HiiProcessHardwareSignature | **(sub_530)** |  |
| Dispatches | **hardware-signature processing based on "Type" opcode.** |  |
| Read | **current total physical memory (MB).** |  |
| UINT32 | **MemoryMb;** |  |
| If | **query mode (DataSize == 0 && Data == NULL), store internal.** |  |
| If | **Data provided and *Data is "close enough" to MemoryMb** |  |
| gHardwareSignatureFlags | **|= HW_SIG_FLAG_MEMORY;** |  |
| UINT8 | **StatusByte;** |  |
| UINT32 | **ConfigDword;** |  |
| UINT32 | **CapDword;** |  |
| HiiReadHardwareConfigData | **(sub_774)** |  |
| Reads | **"HardwareConfigData" UEFI variable (default 120 bytes).** |  |
| RecordHardwareChange | **(sub_7F0)** |  |
| Records | **a 32-bit change code into the array gChangeList[].** |  |
| CheckCmosChecksumChanged | **(sub_81C)** |  |
| Reads | **CMOS status and checksum to detect battery-backed config** |  |
| Locate | **the CMOS info protocol (gCmosInfoProtocolGuid).** |  |
| If | **it has 128 bytes of data, byte[127] is the status byte.** |  |
| Status | **= gBS->LocateProtocol (** |  |
| unk_1C80 | **NULL** |  |
| The | **status byte at the last position of the CMOS buffer.** |  |
| ChecksumBytes | **= *(UINT8 *)(*(UINT64 *)((UINT8 *)CmosProtocol + 8) + 127);** |  |
| Locate | **the CMOS access protocol (gCmosAccessProtocolGuid).** |  |
| Compute | **a checksum from its register-database fields.** |  |
| at | **offset +24 -> +8 -> +4/+8** |  |
| Store | **result in internal format.** |  |
| if | **(DataSize == 0)** |  |
| Internal | **query: store ChecksumBytes as 2-byte checksum.** |  |
| HardwareSignatureNotificationCallback | **(sub_B9C)** |  |
| Main | **callback.  Invoked when the hardware-configuration formset is** |  |
| Collect | **all signature components.** |  |
| HiiProcessHardwareSignature | **(2, 0, NULL);  // memory size** |  |
| status | **byte** |  |
| config | **DWORD** |  |
| CMOS | **checksum** |  |
| Read | **previous update count via RuntimeServices variable.** |  |
| VarGuid | **= &gHardwareSignatureVarGuid;       // unk_1D68** |  |
| Sort | **any recorded change codes.** |  |
| if | **(gChangeListIndex >= 2)** |  |
| Signal | **the event (complete the notification).** |  |
| Status | **= gBS->SignalEvent (gHardwareConfigVarStore);** |  |
| Find | **the hardware formset and write the updated count into storage.** |  |
| FormsetData | **= (VOID *)FindHardwareFormset (&gHardwareFormsetGuid);** |  |
| The | **update count is written at offset +8 inside the formset** |  |
| storage | **block.** |  |
| Signal | **completion on the notification event.** |  |
| CalculatePhysicalMemorySize | **(sub_F68)** |  |
| Walks | **UEFI memory map and sums physical RAM pages.** |  |
| Query | **required buffer size.** |  |
| Status | **= gBS->GetMemoryMap (** |  |
| Align | **MapSize to page boundary.** |  |
| MapSize | **= ALIGN_VALUE (MapSize + EFI_PAGE_SIZE, EFI_PAGE_SIZE);** |  |
| Walk | **descriptors and sum conventional + firmware + ACPI reclaim** |  |
| MapPtr | **= Map;** |  |
| Sum | **pages of types 0,2..4,7..8,0xA..0xB (conventional + reserved +** |  |
| ACPI | **reclaim + ACPI NVS + runtime)** |  |
| if | **(MapPtr->Type != 1 && MapPtr->Type != 5 &&** |  |
| Accumulate | **page-count bits for a packed size estimate:** |  |
| TotalPages | **+= (PhysicalStart >> 12) & (bits 0-7)** |  |
| CachePages | **+= (MapPtr->PhysicalStart >> 12) +** |  |
| Packed | **result: the sum of page bits plus CachePages.** |  |
| gMemorySizePacked | **= TotalPages + CachePages;** |  |
| GetHiiStringTable | **(sub_11A8)** |  |
| Enumerates | **HII handles and builds a table of string identifiers** |  |
| First | **call to get the number of handles.** |  |
| HandleBuffer | **= NULL;** |  |
| Enumerate | **again.** |  |
| for | **(UINTN idx = 0; idx < HandleCount; idx++)** |  |
| Open | **the HII string protocol on each handle.** |  |
| Status | **= gBS->OpenProtocol (** |  |
| Query | **string attributes (language, etc.)** |  |
| Status | **= StringProtocol->GetString (** |  |
| string | **ID** |  |
| Populate | **table entry: 10 bytes per handle.** |  |
| INTN | **EntryBase;** |  |
| GetHardwareConfigFromFormset | **(sub_13D8)** |  |
| Walks | **HII formsets matching known GUID patterns, extracts** |  |
| Implementation | **details in the accompanying .md** |  |
| Calls | **DebugAssert via the HII database protocol's DEBUG output.** |  |
| omitted | **for brevity** |  |
| Returns | **the two's complement of Buffer[0] (checksum).** |  |
| The | **decompiled logic: return -*Buffer;** |  |
| which | **is the arithmetic negation (two's complement of the first byte).** |  |
| return | **(UINT8)(-(INT8)*Buffer);** |  |
| Standard | **in-place quicksort (Hoare partition scheme).** |  |
| UINT32 | **Pivot;** |  |
| End | **of reverse-engineered representation.** |  |

---
*Generated by HR650X BIOS Decompilation Project*