Add initial version of ACPI module
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 32s
Builds / ExectOS (i686) (push) Successful in 26s

This commit is contained in:
Rafal Kupiec 2024-02-01 16:26:12 +01:00
parent f55bdb6274
commit 8a2e49ec60
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
8 changed files with 302 additions and 0 deletions

View File

@ -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
{

View File

@ -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}}

View File

@ -1,3 +1,4 @@
add_subdirectory(acpi)
add_subdirectory(beep)
add_subdirectory(chainldr)
add_subdirectory(dummy)

View File

@ -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)

186
xtldr/modules/acpi/acpi.c Normal file
View File

@ -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 <belliash@codingworkshop.eu.org>
*/
#include <acpi.h>
/* 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);
}

View File

@ -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 <belliash@codingworkshop.eu.org>
*/
#include <xtblapi.h>
/* ACPI Protocol */
XTBL_ACPI_PROTOCOL AcpAcpiProtocol;
/* XTLDR protocol handler */
PXTBL_LOADER_PROTOCOL XtLdrProtocol;

View File

@ -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 <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_ACPI_ACPI_H
#define __XTLDR_ACPI_ACPI_H
#include <xtblapi.h>
#include <globals.h>
/* 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 */

View File

@ -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 <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_ACPI_GLOBALS_H
#define __XTLDR_ACPI_GLOBALS_H
#include <acpi.h>
/* ACPI Protocol */
EXTERN XTBL_ACPI_PROTOCOL AcpAcpiProtocol;
/* XTLDR protocol handler */
EXTERN PXTBL_LOADER_PROTOCOL XtLdrProtocol;
#endif/* __XTLDR_ACPI_GLOBALS_H */