Quick code refactor for further modules development
ci/woodpecker/push/build Pipeline was successful Details

This commit is contained in:
Rafal Kupiec 2022-10-20 18:19:34 +02:00
parent 37a37c225f
commit 5869aa985a
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
10 changed files with 205 additions and 16 deletions

View File

@ -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 */

17
xtldr/includes/blmod.h Normal file
View File

@ -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 <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_BLMOD_H
#define __XTLDR_BLMOD_H
#include <xtkmapi.h>
#include <bldefs.h>
#include <blproto.h>
#endif /* __XTLDR_BLMOD_H */

View File

@ -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 <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_BLMOD_H
#define __XTLDR_BLMOD_H
#ifndef __XTLDR_BLPROTO_H
#define __XTLDR_BLPROTO_H
#include <xtkmapi.h>
#include <bldefs.h>
/* 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 */

View File

@ -11,6 +11,7 @@
#include <xtkmapi.h>
#include <bldefs.h>
#include <blproto.h>
/* EFI Image Handle */

View File

@ -1 +1,3 @@
add_subdirectory(dummy)
add_subdirectory(pecoff)
add_subdirectory(xtos)

View File

@ -6,8 +6,7 @@
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtbl.h>
#include <blproto.h>
#include <blmod.h>
/* EFI Image Handle */

View File

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

View File

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

View File

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

54
xtldr/modules/xtos/xtos.c Normal file
View File

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