diff --git a/xtldr/CMakeLists.txt b/xtldr/CMakeLists.txt index 2fb4317..c3c6d57 100644 --- a/xtldr/CMakeLists.txt +++ b/xtldr/CMakeLists.txt @@ -14,6 +14,7 @@ list(APPEND XTLDR_SOURCE ${XTLDR_SOURCE_DIR}/console.c ${XTLDR_SOURCE_DIR}/efiutil.c ${XTLDR_SOURCE_DIR}/string.c + ${XTLDR_SOURCE_DIR}/system.c ${XTLDR_SOURCE_DIR}/volume.c ${XTLDR_SOURCE_DIR}/xtldr.c) diff --git a/xtldr/efiutil.c b/xtldr/efiutil.c index c030649..3f06c72 100644 --- a/xtldr/efiutil.c +++ b/xtldr/efiutil.c @@ -162,38 +162,6 @@ BlDbgPrint(IN PUINT16 Format, } } -/** - * This routine checks whether SecureBoot is enabled or not. - * - * @return Numeric representation of SecureBoot status (0 = Disabled, >0 = Enabled, <0 SetupMode). - * - * @since XT 1.0 - */ -INT_PTR -BlEfiGetSecureBootStatus() -{ - EFI_GUID VarGuid = EFI_GLOBAL_VARIABLE_GUID; - INT_PTR SecureBootStatus = 0; - UCHAR VarValue = 0; - UINT_PTR Size; - - Size = sizeof(VarValue); - if(EfiSystemTable->RuntimeServices->GetVariable(L"SecureBoot", &VarGuid, - NULL, &Size, &VarValue) == STATUS_EFI_SUCCESS) - { - SecureBootStatus = (INT_PTR)VarValue; - - if((EfiSystemTable->RuntimeServices->GetVariable(L"SetupMode", &VarGuid, - NULL, &Size, &VarValue) == STATUS_EFI_SUCCESS) && VarValue != 0) - { - SecureBootStatus = -1; - } - } - - /* Return SecureBoot status */ - return SecureBootStatus; -} - /** * This routine allocates a pool memory. * diff --git a/xtldr/system.c b/xtldr/system.c new file mode 100644 index 0000000..0d7e1d3 --- /dev/null +++ b/xtldr/system.c @@ -0,0 +1,75 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/system.c + * DESCRIPTION: EFI system information + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/** + * This routine checks whether SecureBoot is enabled or not. + * + * @return Numeric representation of SecureBoot status (0 = Disabled, >0 = Enabled, <0 SetupMode). + * + * @since XT 1.0 + */ +INT_PTR +BlEfiGetSecureBootStatus() +{ + EFI_GUID VarGuid = EFI_GLOBAL_VARIABLE_GUID; + INT_PTR SecureBootStatus = 0; + UCHAR VarValue = 0; + UINT_PTR Size; + + Size = sizeof(VarValue); + if(EfiSystemTable->RuntimeServices->GetVariable(L"SecureBoot", &VarGuid, + NULL, &Size, &VarValue) == STATUS_EFI_SUCCESS) + { + SecureBootStatus = (INT_PTR)VarValue; + + if((EfiSystemTable->RuntimeServices->GetVariable(L"SetupMode", &VarGuid, + NULL, &Size, &VarValue) == STATUS_EFI_SUCCESS) && VarValue != 0) + { + SecureBootStatus = -1; + } + } + + /* Return SecureBoot status */ + return SecureBootStatus; +} + +/** + * Read system configuration from a specified table. + * + * @param TableGuid + * Supplies a pointer to the GUID to search for. + * + * @param Table + * Supplies a pointer that will point to the configuration table. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +EFI_STATUS +BlEfiGetSystemConfigurationTable(IN PEFI_GUID TableGuid, + OUT PVOID *Table) +{ + SIZE_T Size = sizeof(EFI_GUID); + UINT_PTR Index; + + for(Index = 0; Index < EfiSystemTable->NumberOfTableEntries; Index++) + { + if(RtlCompareMemory((PVOID)&EfiSystemTable->ConfigurationTable[Index].VendorGuid, TableGuid, Size) == Size) + { + *Table = EfiSystemTable->ConfigurationTable[Index].VendorTable; + return STATUS_EFI_SUCCESS; + } + } + + /* Table not found */ + return STATUS_EFI_NOT_FOUND; +}