Initial support for xtldr modules and bootloader protocol
ci/woodpecker/push/build Pipeline failed Details

This commit is contained in:
Rafal Kupiec 2022-09-17 00:14:09 +02:00
parent 33ff15e1db
commit 109c24f389
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
11 changed files with 262 additions and 15 deletions

View File

@ -61,7 +61,7 @@ add_compiler_flags(-D__RELFILE__="&__FILE__[__FILE__[0] == '.' ? sizeof \\\"${_P
# Set the virtual disk image size (in MiB)
set_disk_image_size(128)
# Build subprojects
# Build all subprojects
add_subdirectory(bootdata)
add_subdirectory(xtldr)
add_subdirectory(xtoskrnl)

View File

@ -234,11 +234,6 @@
#define EFI_UART_IO_PROTOCOL_GUID {0xBB25CF6F, 0xF1D4, 0x11D2, {0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0xFD}}
#define EFI_UNICODE_COLLATION_PROTOCOL_GUID {0x1D85CD7F, 0xF43D, 0x11D2, {0x9A, 0x0C, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D}}
/* EFI XT protocols GUIDs */
#define EFI_XT_ELF_IMAGE_PROTOCOL_GUID {0x9B539887, 0x5854, 0x424C, {0x42, 0xFA, 0x00, 0x90, 0xC9, 0x04, 0x66, 0xA4}}
#define EFI_XT_HIVE_IMAGE_PROTOCOL_GUID {0x5A3688A2, 0x5854, 0x424C, {0xBC, 0xDF, 0x00, 0x8F, 0xAA, 0x52, 0x63, 0xD4}}
#define EFI_XT_PECOFF_IMAGE_PROTOCOL_GUID {0x85DAFF92, 0x5854, 0x424C, {0xB1, 0xBF, 0x00, 0x79, 0x39, 0xEA, 0x6E, 0xFD}}
/* Basic UEFI types */
typedef PVOID EFI_EVENT, *PEFI_EVENT;
typedef PVOID EFI_HANDLE, *PEFI_HANDLE;

View File

@ -1,3 +1,6 @@
# Build XTLDR modules
add_subdirectory(modules)
# XT Boot Loader
PROJECT(XTLDR)
@ -18,7 +21,7 @@ list(APPEND XTLDR_SOURCE
add_executable(xtldr ${XTLDR_SOURCE})
# Add linker libraries
target_link_libraries(xtldr xtoslib)
target_link_libraries(xtldr libxtos)
# Set proper binary name and install target
if(ARCH STREQUAL "i686")

39
xtldr/includes/bldefs.h Normal file
View File

@ -0,0 +1,39 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/includes/bldefs.h
* DESCRIPTION: Definitions for the XT boot loader
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_BLDEFS_H
#define __XTLDR_BLDEFS_H
#include <xtkmapi.h>
/* EFI XT boot devices */
#define XT_BOOT_DEVICE_UNKNOWN 0x00
#define XT_BOOT_DEVICE_CDROM 0x01
#define XT_BOOT_DEVICE_FLOPPY 0x02
#define XT_BOOT_DEVICE_HARDDISK 0x03
#define XT_BOOT_DEVICE_RAMDISK 0x04
/* EFI XT protocols GUIDs */
#define XT_BOOT_LOADER_PROTOCOL_GUID {0x21FF49E8, 0x5854, 0x424C, {0xE9, 0x11, 0x00, 0x86, 0xE1, 0x2C, 0xD9, 0xC1}}
#define XT_ELF_IMAGE_PROTOCOL_GUID {0x9B539887, 0x5854, 0x424C, {0x42, 0xFA, 0x00, 0x90, 0xC9, 0x04, 0x66, 0xA4}}
#define XT_HIVE_IMAGE_PROTOCOL_GUID {0x5A3688A2, 0x5854, 0x424C, {0xBC, 0xDF, 0x00, 0x8F, 0xAA, 0x52, 0x63, 0xD4}}
#define XT_PECOFF_IMAGE_PROTOCOL_GUID {0x85DAFF92, 0x5854, 0x424C, {0xB1, 0xBF, 0x00, 0x79, 0x39, 0xEA, 0x6E, 0xFD}}
/* EFI XT routines forward references */
typedef VOID (*PBL_DBG_PRINT)(IN PUINT16 Format, IN ...);
typedef VOID (*PBL_EFI_PRINT)(IN PUINT16 Format, IN ...);
/* EFI XT Boot Loader Protocol */
typedef struct _XT_BOOT_LOADER_PROTOCOL
{
PBL_DBG_PRINT DbgPrint;
PBL_EFI_PRINT EfiPrint;
} XT_BOOT_LOADER_PROTOCOL, *PXT_BOOT_LOADER_PROTOCOL;
#endif /* __XTLDR_BLDEFS_H */

View File

@ -10,19 +10,14 @@
#define __XTLDR_XTBL_H
#include <xtkmapi.h>
#include <bldefs.h>
#define XT_BOOT_DEVICE_UNKNOWN 0x00
#define XT_BOOT_DEVICE_CDROM 0x01
#define XT_BOOT_DEVICE_FLOPPY 0x02
#define XT_BOOT_DEVICE_HARDDISK 0x03
#define XT_BOOT_DEVICE_RAMDISK 0x04
/* EFI Image Handle */
EXTERN EFI_HANDLE EfiImageHandle;
/* EFI System Table */
EXTERN EFI_SYSTEM_TABLE *EfiSystemTable;
EXTERN PEFI_SYSTEM_TABLE EfiSystemTable;
/* Serial port configuration */
EXTERN CPPORT EfiSerialPort;
@ -65,6 +60,17 @@ BlGetVolumeDevicePath(IN PUCHAR SystemPath,
OUT PEFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT PUCHAR *Path);
EFI_STATUS
BlGetXtLoaderProtocol(EFI_HANDLE ImageHandle,
PEFI_SYSTEM_TABLE SystemTable,
PXT_BOOT_LOADER_PROTOCOL *LoaderProtocol);
EFI_STATUS
BlLoadEfiModules();
EFI_STATUS
BlpRegisterXtLoaderProtocol();
EFI_STATUS
BlStartXtLoader(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable);

View File

@ -0,0 +1 @@
add_subdirectory(dummy)

78
xtldr/modules/blproto.c Normal file
View File

@ -0,0 +1,78 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/blproto.c
* DESCRIPTION: EFI XTLDR protocol API
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtbl.h>
/**
* This routine locates and opens the XT boot loader protocol.
*
* @param ImageHandle
* Firmware-allocated handle that identifies the image.
*
* @param SystemTable
* Provides the EFI system table.
*
* @param LoaderProtocol
* Supplies the address where a pointer to the bootloader protocol is returned.
*
* @return This routine returns status code.
*
* @since XT 1.0
*/
EFI_STATUS
BlGetXtLoaderProtocol(EFI_HANDLE ImageHandle,
PEFI_SYSTEM_TABLE SystemTable,
PXT_BOOT_LOADER_PROTOCOL *LoaderProtocol)
{
EFI_GUID Guid = XT_BOOT_LOADER_PROTOCOL_GUID;
PEFI_HANDLE Handles = NULL;
EFI_STATUS Status;
UINT_PTR Count;
UINT Index;
/* Try to locate the handles */
Status = SystemTable->BootServices->LocateHandleBuffer(ByProtocol, &Guid, NULL, &Count, &Handles);
if(Status != STATUS_EFI_SUCCESS)
{
/* Unable to get handles */
return Status;
}
/* Check if any handles returned */
if(Count > 0)
{
/* Iterate through all given handles */
for(Index = 0; Index < Count; Index++)
{
/* Try to open protocol */
Status = SystemTable->BootServices->OpenProtocol(Handles[Index], &Guid, (PVOID *)&LoaderProtocol,
ImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL);
/* Check if successfully opened the loader protocol */
if(Status == STATUS_EFI_SUCCESS)
{
/* Protocol found */
break;
}
}
}
/* Free handles */
SystemTable->BootServices->FreePool(Handles);
/* Make sure the loaded protocol has been found */
if(LoaderProtocol == NULL)
{
/* Protocol not found */
return STATUS_EFI_NOT_FOUND;
}
/* Return success */
return STATUS_EFI_SUCCESS;
}

View File

@ -0,0 +1,26 @@
# XT Boot Loader
PROJECT(XTLDR_DUMMY)
# Specify include directories
include_directories(
${EXECTOS_SOURCE_DIR}/sdk/xtdk
${XTLDR_SOURCE_DIR}/includes)
# Specify list of source code files
list(APPEND XTLDR_DUMMY_SOURCE
${XTLDR_SOURCE_DIR}/modules/blproto.c
${XTLDR_DUMMY_SOURCE_DIR}/dummy.c)
# Link bootloader executable
add_executable(dummy ${XTLDR_DUMMY_SOURCE})
# Add linker libraries
target_link_libraries(dummy libxtos)
# Set proper binary name and install target
set_target_properties(dummy PROPERTIES SUFFIX .efi)
set_install_target(dummy efi/boot/xtldr)
# Set loader entrypoint, imagebase address, ordinals and subsystem
set_entrypoint(dummy "BlXtLoaderModuleMain")
set_subsystem(dummy efi_boot_service_driver)

View File

@ -0,0 +1,48 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/dummy/dummy.c
* DESCRIPTION: Boot loader dummy module
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtbl.h>
/* EFI Image Handle */
EFI_HANDLE EfiImageHandle;
/* EFI System Table */
PEFI_SYSTEM_TABLE EfiSystemTable;
/* EFI XT Loader Protocol */
PXT_BOOT_LOADER_PROTOCOL EfiXtLdrProtocol;
/**
* 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
*/
EFI_STATUS
BlXtLoaderModuleMain(EFI_HANDLE ImageHandle,
PEFI_SYSTEM_TABLE SystemTable)
{
/* Set the system table and image handle */
EfiImageHandle = ImageHandle;
EfiSystemTable = SystemTable;
/* Open the XTLDR protocol */
BlGetXtLoaderProtocol(ImageHandle, SystemTable, &EfiXtLdrProtocol);
/* Print message and return success */
EfiXtLdrProtocol->EfiPrint(L"XTLDR dummy module initialized\n");
return STATUS_EFI_SUCCESS;
}

View File

@ -18,6 +18,43 @@ PEFI_SYSTEM_TABLE EfiSystemTable;
/* Serial port configuration */
CPPORT EfiSerialPort;
/**
* This routine loads XTLDR EFI modules.
*
* @return This routine returns status code.
*
* @since XT 1.0
*/
EFI_STATUS
BlLoadEfiModules()
{
EFI_STATUS Status;
return STATUS_EFI_SUCCESS;
}
/**
* This routine registers XTLDR protocol for further usage by modules.
*
* @return This routine returns status code.
*
* @since XT 1.0
*/
EFI_STATUS
BlRegisterXtLoaderProtocol()
{
EFI_GUID Guid = XT_BOOT_LOADER_PROTOCOL_GUID;
XT_BOOT_LOADER_PROTOCOL LoaderProtocol;
EFI_HANDLE Handle;
/* Set all routines available via loader protocol */
LoaderProtocol.DbgPrint = BlDbgPrint;
LoaderProtocol.EfiPrint = BlEfiPrint;
/* Register loader protocol */
return EfiSystemTable->BootServices->InstallProtocolInterface(&Handle, &Guid, EFI_NATIVE_INTERFACE, &LoaderProtocol);
}
/**
* This routine is the entry point of the XT EFI boot loader.
*
@ -60,6 +97,20 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
BlDbgPrint(L"WARNING: Failed to disable watchdog timer\n");
}
/* Register loader protocol */
Status = BlRegisterXtLoaderProtocol();
if(Status != STATUS_EFI_SUCCESS)
{
/* Failed to register loader protocol */
BlDbgPrint(L"ERROR: Failed to register XTLDR loader protocol\n");
}
Status = BlLoadEfiModules();
if(Status != STATUS_EFI_SUCCESS)
{
BlDbgPrint(L"ERROR: Failed to load XTLDR modules\n");
}
/* Discover and enumerate EFI block devices */
BlEnumerateEfiBlockDevices();

View File

@ -18,7 +18,7 @@ list(APPEND XTOSKRNL_SOURCE
set_specfile(xtoskrnl.spec)
# Link static XTOS library
add_library(xtoslib ${XTOSKRNL_SOURCE})
add_library(libxtos ${XTOSKRNL_SOURCE})
# Link kernel executable
add_executable(xtoskrnl