#include <efi.h>
#include <libsmbios.h>
#define print_variable(SystemTable, base, value) \
kputs(SystemTable, L"" #value ": "); print_##base(SystemTable, value); kputc(SystemTable, L'\n')
void swap(CHAR16 *a, CHAR16 *b) {
CHAR16 temp = *a;
*a = *b;
*b = temp;
}
CHAR16 kgetc(EFI_SYSTEM_TABLE *SystemTable) {
EFI_INPUT_KEY key;
SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, NULL);
SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &key);
if(key.UnicodeChar == '\r') key.UnicodeChar = '\n';
return key.UnicodeChar;
}
void kputc(EFI_SYSTEM_TABLE *SystemTable, CHAR16 c) {
if(c == L'\n') kputc(SystemTable, L'\r');
CHAR16 str[2] = {c, '\0'};
SystemTable->ConOut->OutputString(SystemTable->ConOut, str);
}
void kputs(EFI_SYSTEM_TABLE *SystemTable, const CHAR16 *str) {
for(UINTN i = 0; str[i]; ++i) {
kputc(SystemTable, str[i]);
}
}
void number(CHAR16 *buff, UINTN value, UINTN base) {
static const CHAR16 table[16] = L"0123456789abcdef";
if(base > 16) base = 16;
CHAR16 *p = buff;
do {
*p++ = table[value % base];
value /= base;
} while(value);
*p = L'\0';
UINTN count = p - buff;
for(UINTN i = 0; i < count / 2; ++i) {
swap(&buff[i], &buff[count - i - 1]);
}
}
void print_dec(EFI_SYSTEM_TABLE *SystemTable, UINTN value) {
CHAR16 buff[128]; number(buff, value, 10); kputs(SystemTable, buff);
}
void print_hex(EFI_SYSTEM_TABLE *SystemTable, UINTN value) {
CHAR16 buff[128]; number(buff, value, 16); kputs(SystemTable, buff);
}
/*
typedef struct {
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8 Data4[8];
} EFI_GUID;
*/
BOOLEAN compare_guid(const EFI_GUID *a, const EFI_GUID *b) {
if(a->Data1 != b->Data1) return FALSE;
if(a->Data2 != b->Data2) return FALSE;
if(a->Data3 != b->Data3) return FALSE;
for(UINTN i = 0; i < 8; ++i) {
if(a->Data4[i] != b->Data4[i]) return FALSE;
}
return TRUE;
}
void print_guid(EFI_SYSTEM_TABLE *SystemTable, const EFI_GUID *guid) {
const UINT8 *base = (const UINT8 *)guid;
kputc(SystemTable, L'{');
BOOLEAN flag = FALSE;
for(UINTN i = 0; i < 16; ++i) {
if(flag) kputs(SystemTable, L", ");
flag = TRUE;
print_hex(SystemTable, base[i]);
}
kputc(SystemTable, L'}');
}
UINT8 *print_smbios_string(EFI_SYSTEM_TABLE *SystemTable, UINT8 *str) {
if(!*str) ++str;
for(UINTN i = 1; ; ++i) {
if(!*str) break;
print_dec(SystemTable, i);
kputs(SystemTable, L": ");
while(*str) kputc(SystemTable, *str++);
kputc(SystemTable, L'\n');
++str;
}
return str + 1;
}
void print_smbios_header(EFI_SYSTEM_TABLE *SystemTable, const SMBIOS_HEADER *hdr) {
print_variable(SystemTable, hex, hdr->Type);
print_variable(SystemTable, hex, hdr->Length);
print_variable(SystemTable, hex, *(UINT16 *)&hdr->Handle);
}
void *bios_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
SMBIOS_TYPE0 *st0 = base;
kputc(SystemTable, L'\n');
print_smbios_header(SystemTable, &st0->Hdr);
print_variable(SystemTable, hex, st0->Vendor);
print_variable(SystemTable, hex, st0->BiosVersion);
print_variable(SystemTable, hex, *(UINT16 *)&st0->BiosSegment);
print_variable(SystemTable, hex, st0->BiosReleaseDate);
print_variable(SystemTable, hex, st0->BiosSize);
print_variable(SystemTable, hex, st0->BiosCharacteristics[0]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[1]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[2]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[3]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[4]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[5]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[6]);
print_variable(SystemTable, hex, st0->BiosCharacteristics[7]);
return print_smbios_string(SystemTable, base + st0->Hdr.Length);
}
void *system_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
SMBIOS_TYPE1 *st1 = base;
kputc(SystemTable, L'\n');
print_smbios_header(SystemTable, &st1->Hdr);
print_variable(SystemTable, hex, st1->Manufacturer);
print_variable(SystemTable, hex, st1->ProductName);
print_variable(SystemTable, hex, st1->Version);
print_variable(SystemTable, hex, st1->SerialNumber);
print_guid(SystemTable, &st1->Uuid); kputc(SystemTable, L'\n');
print_variable(SystemTable, hex, st1->WakeUpType);
return print_smbios_string(SystemTable, base + st1->Hdr.Length);
}
void *baseboard_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
SMBIOS_TYPE2 *st2 = base;
kputc(SystemTable, L'\n');
print_smbios_header(SystemTable, &st2->Hdr);
print_variable(SystemTable, hex, st2->Manufacturer);
print_variable(SystemTable, hex, st2->ProductName);
print_variable(SystemTable, hex, st2->Version);
print_variable(SystemTable, hex, st2->SerialNumber);
return print_smbios_string(SystemTable, base + st2->Hdr.Length);
}
void *system_enclosure(EFI_SYSTEM_TABLE *SystemTable, void *base) {
SMBIOS_TYPE3 *st3 = base;
kputc(SystemTable, L'\n');
print_smbios_header(SystemTable, &st3->Hdr);
print_variable(SystemTable, hex, st3->Manufacturer);
print_variable(SystemTable, hex, st3->Type);
print_variable(SystemTable, hex, st3->Version);
print_variable(SystemTable, hex, st3->SerialNumber);
print_variable(SystemTable, hex, st3->AssetTag);
print_variable(SystemTable, hex, st3->BootupState);
print_variable(SystemTable, hex, st3->PowerSupplyState);
print_variable(SystemTable, hex, st3->ThermalState);
print_variable(SystemTable, hex, st3->SecurityStatus);
print_variable(SystemTable, hex, *(UINT32 *)&st3->OemDefined);
return print_smbios_string(SystemTable, base + st3->Hdr.Length);
}
void *processor_information(EFI_SYSTEM_TABLE *SystemTable, void *base) {
SMBIOS_TYPE4 *st4 = base;
kputc(SystemTable, L'\n');
print_smbios_header(SystemTable, &st4->Hdr);
print_variable(SystemTable, hex, st4->Socket);
print_variable(SystemTable, hex, st4->ProcessorType);
print_variable(SystemTable, hex, st4->ProcessorFamily);
print_variable(SystemTable, hex, st4->ProcessorId[0]);
print_variable(SystemTable, hex, st4->ProcessorId[1]);
print_variable(SystemTable, hex, st4->ProcessorId[2]);
print_variable(SystemTable, hex, st4->ProcessorId[3]);
print_variable(SystemTable, hex, st4->ProcessorId[4]);
print_variable(SystemTable, hex, st4->ProcessorId[5]);
print_variable(SystemTable, hex, st4->ProcessorId[6]);
print_variable(SystemTable, hex, st4->ProcessorId[7]);
print_variable(SystemTable, hex, st4->ProcessorVersion);
print_variable(SystemTable, hex, st4->Voltage);
print_variable(SystemTable, hex, *(UINT16 *)&st4->ExternalClock);
print_variable(SystemTable, hex, *(UINT16 *)&st4->MaxSpeed);
print_variable(SystemTable, hex, *(UINT16 *)&st4->CurrentSpeed);
print_variable(SystemTable, hex, st4->Status);
print_variable(SystemTable, hex, st4->ProcessorUpgrade);
print_variable(SystemTable, hex, *(UINT16 *)&st4->L1CacheHandle);
print_variable(SystemTable, hex, *(UINT16 *)&st4->L2CacheHandle);
print_variable(SystemTable, hex, *(UINT16 *)&st4->L3CacheHandle);
return print_smbios_string(SystemTable, base + st4->Hdr.Length);
}
void *unknown_type(EFI_SYSTEM_TABLE *SystemTable, void *base) {
SMBIOS_HEADER *hdr = base;
kputc(SystemTable, L'\n');
print_smbios_header(SystemTable, hdr);
return print_smbios_string(SystemTable, base + hdr->Length);
}
void info_eps(EFI_SYSTEM_TABLE *SystemTable) {
EFI_GUID smbios_guid = SMBIOS_TABLE_GUID;
EFI_GUID smbios3_guid = SMBIOS3_TABLE_GUID;
EFI_GUID mps_guid = MPS_TABLE_GUID;
EFI_GUID acpi_guid = ACPI_TABLE_GUID;
EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID;
EFI_GUID sal_system_guid = SAL_SYSTEM_TABLE_GUID;
EFI_GUID dtb_guid = EFI_DTB_TABLE_GUID;
SMBIOS_STRUCTURE_TABLE *smbios_header = NULL;
for(UINTN i = 0; i < SystemTable->NumberOfTableEntries; ++i) {
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &smbios_guid)) {
kputs(SystemTable, L"SMBIOS_TABLE_GUID: ");
smbios_header = SystemTable->ConfigurationTable[i].VendorTable;
}
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &smbios3_guid)) kputs(SystemTable, L"SMBIOS3_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &mps_guid)) kputs(SystemTable, L"MPS_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &acpi_guid)) kputs(SystemTable, L"ACPI_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &acpi20_guid)) kputs(SystemTable, L"ACPI_20_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &sal_system_guid)) kputs(SystemTable, L"SAL_SYSTEM_TABLE_GUID: ");
if(compare_guid(&SystemTable->ConfigurationTable[i].VendorGuid, &dtb_guid)) kputs(SystemTable, L"EFI_DTB_TABLE_GUID: ");
print_guid(SystemTable, &SystemTable->ConfigurationTable[i].VendorGuid); kputc(SystemTable, L'\n');
}
if(!smbios_header) return;
kputs(SystemTable, L"AnchorString: "");
kputc(SystemTable, smbios_header->AnchorString[0]);
kputc(SystemTable, smbios_header->AnchorString[1]);
kputc(SystemTable, smbios_header->AnchorString[2]);
kputc(SystemTable, smbios_header->AnchorString[3]);
kputs(SystemTable, L""\n");
print_variable(SystemTable, hex, smbios_header->EntryPointStructureChecksum);
print_variable(SystemTable, hex, smbios_header->EntryPointLength);
print_variable(SystemTable, hex, smbios_header->MajorVersion);
print_variable(SystemTable, hex, smbios_header->MinorVersion);
print_variable(SystemTable, hex, smbios_header->MaxStructureSize);
print_variable(SystemTable, hex, smbios_header->EntryPointRevision);
print_variable(SystemTable, hex, smbios_header->IntermediateChecksum);
print_variable(SystemTable, hex, smbios_header->TableLength);
print_variable(SystemTable, hex, smbios_header->TableAddress);
print_variable(SystemTable, hex, smbios_header->NumberOfSmbiosStructures);
print_variable(SystemTable, hex, smbios_header->SmbiosBcdRevision);
kputs(SystemTable, L"IntermediateAnchorString: "");
kputc(SystemTable, smbios_header->IntermediateAnchorString[0]);
kputc(SystemTable, smbios_header->IntermediateAnchorString[1]);
kputc(SystemTable, smbios_header->IntermediateAnchorString[2]);
kputc(SystemTable, smbios_header->IntermediateAnchorString[3]);
kputc(SystemTable, smbios_header->IntermediateAnchorString[4]);
kputs(SystemTable, L""\n");
print_variable(SystemTable, hex, smbios_header->FormattedArea[0]);
print_variable(SystemTable, hex, smbios_header->FormattedArea[1]);
print_variable(SystemTable, hex, smbios_header->FormattedArea[2]);
print_variable(SystemTable, hex, smbios_header->FormattedArea[3]);
print_variable(SystemTable, hex, smbios_header->FormattedArea[4]);
UINT8 *next = (UINT8 *)(UINT64)smbios_header->TableAddress;
for(UINTN i = 0; i < smbios_header->NumberOfSmbiosStructures; ++i) {
switch(*next) {
case 0: next = bios_information(SystemTable, next); break;
case 1: next = system_information(SystemTable, next); break;
case 2: next = baseboard_information(SystemTable, next); break;
case 3: next = system_enclosure(SystemTable, next); break;
case 4: next = processor_information(SystemTable, next); break;
default: next = unknown_type(SystemTable, next);
}
kgetc(SystemTable);
}
}
EFI_STATUS EFIAPI efi_main(EFI_HANDLE *ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
info_eps(SystemTable);
kgetc(SystemTable);
return EFI_SUCCESS;
}