forked from xt-sys/exectos
Initial support for xtldr modules and bootloader protocol
This commit is contained in:
1
xtldr/modules/CMakeLists.txt
Normal file
1
xtldr/modules/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory(dummy)
|
78
xtldr/modules/blproto.c
Normal file
78
xtldr/modules/blproto.c
Normal 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;
|
||||
}
|
26
xtldr/modules/dummy/CMakeLists.txt
Normal file
26
xtldr/modules/dummy/CMakeLists.txt
Normal 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)
|
48
xtldr/modules/dummy/dummy.c
Normal file
48
xtldr/modules/dummy/dummy.c
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user