diff --git a/sdk/xtdk/bltypes.h b/sdk/xtdk/bltypes.h index 21b8fa0..6b386e0 100644 --- a/sdk/xtdk/bltypes.h +++ b/sdk/xtdk/bltypes.h @@ -40,6 +40,9 @@ #define XTBL_TUI_MAX_DIALOG_WIDTH 100 /* Boot Loader protocol routine pointers */ +typedef EFI_STATUS (*PBL_ACPI_GET_ACPI_TABLE)(OUT PVOID *AcpiTable); +typedef EFI_STATUS (*PBL_ACPI_GET_RSDP_TABLE)(OUT PVOID *AcpiTable); +typedef EFI_STATUS (*PBL_ACPI_GET_XSDP_TABLE)(OUT PVOID *AcpiTable); typedef EFI_STATUS (*PBL_ALLOCATE_PAGES)(IN ULONGLONG Size, OUT PEFI_PHYSICAL_ADDRESS Memory); typedef EFI_STATUS (*PBL_ALLOCATE_POOL)(IN UINT_PTR Size, OUT PVOID *Memory); typedef VOID (*PBL_BOOTMENU_INITIALIZE_OS_LIST)(OUT PXTBL_BOOTMENU_ITEM MenuEntries, OUT PULONG EntriesCount, OUT PULONG DefaultId); @@ -249,6 +252,14 @@ typedef struct _XTBL_FRAMEBUFFER_INFORMATION } PixelInformation; } XTBL_FRAMEBUFFER_INFORMATION, *PXTBL_FRAMEBUFFER_INFORMATION; +/* XTLDR ACPI protocol structure */ +typedef struct _XTBL_ACPI_PROTOCOL +{ + PBL_ACPI_GET_ACPI_TABLE GetAcpiTable; + PBL_ACPI_GET_RSDP_TABLE GetRsdpTable; + PBL_ACPI_GET_XSDP_TABLE GetXsdpTable; +} XTBL_ACPI_PROTOCOL, *PXTBL_ACPI_PROTOCOL; + /* XTLDR Boot protocol structure */ typedef struct _XTBL_BOOT_PROTOCOL { diff --git a/sdk/xtdk/xtguid.h b/sdk/xtdk/xtguid.h index 0a4074e..fdcc35b 100644 --- a/sdk/xtdk/xtguid.h +++ b/sdk/xtdk/xtguid.h @@ -11,6 +11,7 @@ /* EFI XT protocols GUIDs */ +#define XT_ACPI_PROTOCOL_GUID {0x58544F53, 0x5854, 0x4357, {0x00, 0x00, 0x41, 0x43, 0x50, 0x49, 0x50, 0x54}} #define XT_BOOT_LOADER_PROTOCOL_GUID {0x58544F53, 0x5854, 0x4357, {0x00, 0x42, 0x4F, 0x4F, 0x54, 0x4C, 0x50, 0x54}} #define XT_ELF_IMAGE_PROTOCOL_GUID {0x58544F53, 0x5854, 0x4357, {0x45, 0x4C, 0x46, 0x49, 0x4D, 0x47, 0x50, 0x54}} #define XT_FRAMEBUFFER_PROTOCOL_GUID {0x58544F53, 0x5854, 0x4357, {0x00, 0x00, 0x46, 0x42, 0x55, 0x46, 0x50, 0x54}} diff --git a/xtldr/modules/CMakeLists.txt b/xtldr/modules/CMakeLists.txt index 59a10d7..f8b21fb 100644 --- a/xtldr/modules/CMakeLists.txt +++ b/xtldr/modules/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(acpi) add_subdirectory(beep) add_subdirectory(chainldr) add_subdirectory(dummy) diff --git a/xtldr/modules/acpi/CMakeLists.txt b/xtldr/modules/acpi/CMakeLists.txt new file mode 100644 index 0000000..a388176 --- /dev/null +++ b/xtldr/modules/acpi/CMakeLists.txt @@ -0,0 +1,27 @@ +# XT Boot Loader ACPI Support Module +PROJECT(XTLDR_ACPI) + +# Specify include directories +include_directories( + ${EXECTOS_SOURCE_DIR}/sdk/xtdk + ${XTLDR_ACPI_SOURCE_DIR}/includes) + +# Specify list of source code files +list(APPEND XTLDR_ACPI_SOURCE + ${XTLDR_ACPI_SOURCE_DIR}/acpi.c + ${XTLDR_ACPI_SOURCE_DIR}/globals.c) + +# Link module executable +add_executable(acpi ${XTLDR_ACPI_SOURCE}) + +# Add linker libraries +target_link_libraries(acpi libxtldr) + +# Set proper binary name and install target +set_target_properties(acpi PROPERTIES SUFFIX .efi) +set_install_target(acpi efi/boot/xtldr/modules) + +# Set module entrypoint and subsystem +set_entrypoint(acpi "XtLdrModuleMain") +set_linker_map(acpi TRUE) +set_subsystem(acpi efi_boot_service_driver) diff --git a/xtldr/modules/acpi/acpi.c b/xtldr/modules/acpi/acpi.c new file mode 100644 index 0000000..3462220 --- /dev/null +++ b/xtldr/modules/acpi/acpi.c @@ -0,0 +1,186 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modules/acpi/acpi.c + * DESCRIPTION: XTLDR ACPI Support Module + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/* Dummy module information */ +XTBL_MODINFO = L"ACPI support"; + +/** + * Attempts to get XSDP. If it is not found or checksum mismatch, it will try to get RSDP instead. + * + * @param AcpiTable + * Suplies a pointer to memory area where XSDP or RSRP address will be stored. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +AcGetAcpiTable(OUT PVOID *AcpiTable) +{ + PVOID Rsdp; + + /* Try to get XSDP (ACPI 2.0) from system configuration tables */ + if(AcGetXsdpTable(&Rsdp) == STATUS_EFI_SUCCESS) + { + /* XSDP found, return success */ + *AcpiTable = Rsdp; + return STATUS_EFI_SUCCESS; + } + + /* Try to get RSDP (ACPI 1.0) from system configuration tables */ + if(AcGetRsdpTable(&Rsdp) == STATUS_EFI_SUCCESS) + { + /* RSDP found, return success */ + *AcpiTable = Rsdp; + return STATUS_EFI_SUCCESS; + } + + /* Neither XSDP nor RSDP found */ + return STATUS_EFI_NOT_FOUND; +} + +/** + * Gets RSDP (ACPI 1.0) from EFI system configuration + * + * @param AcpiTable + * Suplies a pointer to memory area where RSDP address will be stored. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +AcGetRsdpTable(OUT PVOID *AcpiTable) +{ + EFI_GUID AcpiGuid = EFI_CONFIG_TABLE_ACPI_TABLE_GUID; + EFI_STATUS Status; + PVOID RsdpTable; + + /* Get RSDP (ACPI 1.0) table from system configuration tables */ + Status = XtLdrProtocol->Util.GetConfigurationTable(&AcpiGuid, &RsdpTable); + if(Status != STATUS_EFI_SUCCESS || AcpChecksumTable(RsdpTable, 20) != 0) + { + /* RSDP not found or checksum mismatch */ + *AcpiTable = NULL; + return STATUS_EFI_NOT_FOUND; + } + + /* RSDP found, return success */ + *AcpiTable = RsdpTable; + return STATUS_EFI_SUCCESS; +} + +/** + * Gets XSDP (ACPI 2.0) from EFI system configuration + * + * @param AcpiTable + * Suplies a pointer to memory area where XSDP address will be stored. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +AcGetXsdpTable(OUT PVOID *AcpiTable) +{ + EFI_GUID AcpiGuid = EFI_CONFIG_TABLE_ACPI20_TABLE_GUID; + EFI_STATUS Status; + PVOID XsdpTable; + + /* Get XSDP (ACPI 2.0) from system configuration tables */ + Status = XtLdrProtocol->Util.GetConfigurationTable(&AcpiGuid, &XsdpTable); + if(Status != STATUS_EFI_SUCCESS || AcpChecksumTable(XsdpTable, 36) != 0) + { + /* XSDP not found or checksum mismatch */ + *AcpiTable = NULL; + return STATUS_EFI_NOT_FOUND; + } + + /* XSDP found, return success */ + *AcpiTable = XsdpTable; + return STATUS_EFI_SUCCESS; +} + +/** + * Checksums a given ACPI table. + * + * @param Buffer + * Supplies a pointer to the table to checksum. + * + * @param Size + * Supplies the size of the table, in bytes. + * + * @return This routine returns the calculated checksum. + */ +XTCDECL +UCHAR +AcpChecksumTable(IN PVOID Buffer, + IN UINT_PTR Size) +{ + PUCHAR Pointer; + UCHAR Sum; + + /* Initialize variables */ + Sum = 0; + Pointer = Buffer; + + /* Calculate checksum of given table */ + while(Size != 0) + { + Sum = (UCHAR)(Sum + *Pointer); + Pointer += 1; + Size -= 1; + } + + /* Return calculated checksum */ + return Sum; +} + +/** + * This routine is the entry point of the XT EFI boot loader module. + * + * @param ImageHandle + * Firmware-allocated handle that identifies the image. + * + * @param SystemTable + * Provides the EFI system table. + * + * @return This routine returns status code. + * + * @since XT 1.0 + */ +XTCDECL +EFI_STATUS +XtLdrModuleMain(IN EFI_HANDLE ImageHandle, + IN PEFI_SYSTEM_TABLE SystemTable) +{ + EFI_GUID Guid = XT_ACPI_PROTOCOL_GUID; + EFI_STATUS Status; + + /* Open the XTLDR protocol */ + Status = BlGetXtLdrProtocol(SystemTable, ImageHandle, &XtLdrProtocol); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to open the protocol, return error */ + return STATUS_EFI_PROTOCOL_ERROR; + } + + /* Set routines available via ACPI protocol */ + AcpAcpiProtocol.GetAcpiTable = AcGetAcpiTable; + AcpAcpiProtocol.GetRsdpTable = AcGetRsdpTable; + AcpAcpiProtocol.GetXsdpTable = AcGetXsdpTable; + + /* Install ACPI protocol */ + return XtLdrProtocol->Protocol.Install(&AcpAcpiProtocol, &Guid); +} diff --git a/xtldr/modules/acpi/globals.c b/xtldr/modules/acpi/globals.c new file mode 100644 index 0000000..abfd269 --- /dev/null +++ b/xtldr/modules/acpi/globals.c @@ -0,0 +1,16 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modules/acpi/globals.c + * DESCRIPTION: ACPI module global variables + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/* ACPI Protocol */ +XTBL_ACPI_PROTOCOL AcpAcpiProtocol; + +/* XTLDR protocol handler */ +PXTBL_LOADER_PROTOCOL XtLdrProtocol; diff --git a/xtldr/modules/acpi/includes/acpi.h b/xtldr/modules/acpi/includes/acpi.h new file mode 100644 index 0000000..3a10d0a --- /dev/null +++ b/xtldr/modules/acpi/includes/acpi.h @@ -0,0 +1,39 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modules/acpi/includes/acpi.h + * DESCRIPTION: XTLDR ACPI module header file + * DEVELOPERS: Rafal Kupiec + */ + +#ifndef __XTLDR_ACPI_ACPI_H +#define __XTLDR_ACPI_ACPI_H + +#include +#include + + +/* ACPI module routines forward references */ +XTCDECL +EFI_STATUS +AcGetAcpiTable(OUT PVOID *AcpiTable); + +XTCDECL +EFI_STATUS +AcGetRsdpTable(OUT PVOID *AcpiTable); + +XTCDECL +EFI_STATUS +AcGetXsdpTable(OUT PVOID *AcpiTable); + +XTCDECL +UCHAR +AcpChecksumTable(IN PVOID Buffer, + IN UINT_PTR Size); + +XTCDECL +EFI_STATUS +XtLdrModuleMain(IN EFI_HANDLE ImageHandle, + IN PEFI_SYSTEM_TABLE SystemTable); + +#endif/* __XTLDR_ACPI_ACPI_H */ diff --git a/xtldr/modules/acpi/includes/globals.h b/xtldr/modules/acpi/includes/globals.h new file mode 100644 index 0000000..417b26d --- /dev/null +++ b/xtldr/modules/acpi/includes/globals.h @@ -0,0 +1,21 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modules/acpi/includes/globals.h + * DESCRIPTION: ACPI Module global variables + * DEVELOPERS: Rafal Kupiec + */ + +#ifndef __XTLDR_ACPI_GLOBALS_H +#define __XTLDR_ACPI_GLOBALS_H + +#include + + +/* ACPI Protocol */ +EXTERN XTBL_ACPI_PROTOCOL AcpAcpiProtocol; + +/* XTLDR protocol handler */ +EXTERN PXTBL_LOADER_PROTOCOL XtLdrProtocol; + +#endif/* __XTLDR_ACPI_GLOBALS_H */