diff --git a/xtldr/includes/bldefs.h b/xtldr/includes/bldefs.h index 655eca4..d003ed5 100644 --- a/xtldr/includes/bldefs.h +++ b/xtldr/includes/bldefs.h @@ -25,15 +25,13 @@ #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 protocols GUIDs */ +#define XT_CHAIN_BOOT_PROTOCOL_GUID {0xC4D19201, 0x5854, 0x424C, {0x3C, 0x01, 0x00, 0x64, 0x90, 0x11, 0x9E, 0xA1}} +#define XT_LINUX_BOOT_PROTOCOL_GUID {0x6B2A9841, 0x5854, 0x424C, {0x93, 0x71, 0x00, 0x3C, 0x34, 0x9B, 0x11, 0x91}} +#define XT_WINNT_BOOT_PROTOCOL_GUID {0x98A80819, 0x5854, 0x424C, {0x37, 0x17, 0x00, 0x2A, 0x55, 0xA3, 0x09, 0xDC}} +#define XT_XTOS_BOOT_PROTOCOL_GUID {0xFF8AD077, 0x5854, 0x424C, {0xA1, 0x77, 0x00, 0x92, 0xEF, 0x1C, 0x09, 0xDC}} -/* 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; +/* Structures forward references */ +typedef struct _XT_BOOT_LOADER_PROTOCOL XT_BOOT_LOADER_PROTOCOL, *PXT_BOOT_LOADER_PROTOCOL; #endif /* __XTLDR_BLDEFS_H */ diff --git a/xtldr/includes/blmod.h b/xtldr/includes/blmod.h new file mode 100644 index 0000000..65c3b0a --- /dev/null +++ b/xtldr/includes/blmod.h @@ -0,0 +1,17 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/includes/blmod.h + * DESCRIPTION: Top level header for XTLDR modules + * DEVELOPERS: Rafal Kupiec + */ + +#ifndef __XTLDR_BLMOD_H +#define __XTLDR_BLMOD_H + +#include +#include +#include + + +#endif /* __XTLDR_BLMOD_H */ diff --git a/xtldr/includes/blproto.h b/xtldr/includes/blproto.h index d65b4b4..0a66144 100644 --- a/xtldr/includes/blproto.h +++ b/xtldr/includes/blproto.h @@ -1,18 +1,30 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtldr/includes/blmod.h - * DESCRIPTION: XTLDR modules support + * FILE: xtldr/includes/blproto.h + * DESCRIPTION: XTLDR boot loader protocol support * DEVELOPERS: Rafal Kupiec */ -#ifndef __XTLDR_BLMOD_H -#define __XTLDR_BLMOD_H +#ifndef __XTLDR_BLPROTO_H +#define __XTLDR_BLPROTO_H #include #include +/* Loader protocol routine pointers */ +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; + +/* Loader protocol related routines forward references */ EFI_STATUS BlGetXtLoaderProtocol(PXT_BOOT_LOADER_PROTOCOL *LdrProtocol); @@ -20,4 +32,4 @@ EFI_STATUS BlLoadXtProtocol(PVOID *ProtocolHandler, PEFI_GUID ProtocolGuid); -#endif /* __XTLDR_BLMOD_H */ +#endif /* __XTLDR_BLPROTO_H */ diff --git a/xtldr/includes/xtbl.h b/xtldr/includes/xtbl.h index ca29c30..83f9bca 100644 --- a/xtldr/includes/xtbl.h +++ b/xtldr/includes/xtbl.h @@ -11,6 +11,7 @@ #include #include +#include /* EFI Image Handle */ diff --git a/xtldr/modules/CMakeLists.txt b/xtldr/modules/CMakeLists.txt index c65186e..03752af 100644 --- a/xtldr/modules/CMakeLists.txt +++ b/xtldr/modules/CMakeLists.txt @@ -1 +1,3 @@ add_subdirectory(dummy) +add_subdirectory(pecoff) +add_subdirectory(xtos) diff --git a/xtldr/modules/dummy/dummy.c b/xtldr/modules/dummy/dummy.c index 3d0bb93..240ef20 100644 --- a/xtldr/modules/dummy/dummy.c +++ b/xtldr/modules/dummy/dummy.c @@ -6,8 +6,7 @@ * DEVELOPERS: Rafal Kupiec */ -#include -#include +#include /* EFI Image Handle */ diff --git a/xtldr/modules/pecoff/CMakeLists.txt b/xtldr/modules/pecoff/CMakeLists.txt new file mode 100644 index 0000000..aed8c80 --- /dev/null +++ b/xtldr/modules/pecoff/CMakeLists.txt @@ -0,0 +1,26 @@ +# XT Boot Loader +PROJECT(XTLDR_PECOFF) + +# Specify include directories +include_directories( + ${EXECTOS_SOURCE_DIR}/sdk/xtdk + ${XTLDR_SOURCE_DIR}/includes) + +# Specify list of source code files +list(APPEND XTLDR_PECOFF_SOURCE + ${XTLDR_SOURCE_DIR}/blproto.c + ${XTLDR_PECOFF_SOURCE_DIR}/pecoff.c) + +# Link bootloader executable +add_executable(pecoff ${XTLDR_PECOFF_SOURCE}) + +# Add linker libraries +target_link_libraries(pecoff libxtos) + +# Set proper binary name and install target +set_target_properties(pecoff PROPERTIES SUFFIX .efi) +set_install_target(pecoff efi/boot/xtldr) + +# Set loader entrypoint, imagebase address, ordinals and subsystem +set_entrypoint(pecoff "BlXtLdrModuleMain") +set_subsystem(pecoff efi_boot_service_driver) diff --git a/xtldr/modules/pecoff/pecoff.c b/xtldr/modules/pecoff/pecoff.c new file mode 100644 index 0000000..2559ea0 --- /dev/null +++ b/xtldr/modules/pecoff/pecoff.c @@ -0,0 +1,54 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modules/pecoff/pecoff.c + * DESCRIPTION: PE/COFF executable file format support + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/* 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 +BlXtLdrModuleMain(EFI_HANDLE ImageHandle, + PEFI_SYSTEM_TABLE SystemTable) +{ + EFI_STATUS Status; + + /* Set the system table and image handle */ + EfiImageHandle = ImageHandle; + EfiSystemTable = SystemTable; + + /* Open the XTLDR protocol */ + Status = BlGetXtLoaderProtocol(&EfiXtLdrProtocol); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to open loader protocol */ + return STATUS_EFI_PROTOCOL_ERROR; + } + + /* Return success */ + return STATUS_EFI_SUCCESS; +} diff --git a/xtldr/modules/xtos/CMakeLists.txt b/xtldr/modules/xtos/CMakeLists.txt new file mode 100644 index 0000000..83cd62e --- /dev/null +++ b/xtldr/modules/xtos/CMakeLists.txt @@ -0,0 +1,26 @@ +# XT Boot Loader +PROJECT(XTLDR_XTOS) + +# Specify include directories +include_directories( + ${EXECTOS_SOURCE_DIR}/sdk/xtdk + ${XTLDR_SOURCE_DIR}/includes) + +# Specify list of source code files +list(APPEND XTLDR_XTOS_SOURCE + ${XTLDR_SOURCE_DIR}/blproto.c + ${XTLDR_XTOS_SOURCE_DIR}/xtos.c) + +# Link bootloader executable +add_executable(xtos ${XTLDR_XTOS_SOURCE}) + +# Add linker libraries +target_link_libraries(xtos libxtos) + +# Set proper binary name and install target +set_target_properties(xtos PROPERTIES SUFFIX .efi) +set_install_target(xtos efi/boot/xtldr) + +# Set loader entrypoint, imagebase address, ordinals and subsystem +set_entrypoint(xtos "BlXtLdrModuleMain") +set_subsystem(xtos efi_boot_service_driver) diff --git a/xtldr/modules/xtos/xtos.c b/xtldr/modules/xtos/xtos.c new file mode 100644 index 0000000..4fcd8a5 --- /dev/null +++ b/xtldr/modules/xtos/xtos.c @@ -0,0 +1,54 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtldr/modules/xtos/xtos.c + * DESCRIPTION: XTOS boot protocol support + * DEVELOPERS: Rafal Kupiec + */ + +#include + + +/* 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 +BlXtLdrModuleMain(EFI_HANDLE ImageHandle, + PEFI_SYSTEM_TABLE SystemTable) +{ + EFI_STATUS Status; + + /* Set the system table and image handle */ + EfiImageHandle = ImageHandle; + EfiSystemTable = SystemTable; + + /* Open the XTLDR protocol */ + Status = BlGetXtLoaderProtocol(&EfiXtLdrProtocol); + if(Status != STATUS_EFI_SUCCESS) + { + /* Failed to open loader protocol */ + return STATUS_EFI_PROTOCOL_ERROR; + } + + /* Return success */ + return STATUS_EFI_SUCCESS; +}