Migrate XTLDR modules to C++
This commit is contained in:
@@ -8,8 +8,8 @@ include_directories(
|
||||
|
||||
# Specify list of source code files
|
||||
list(APPEND XTLDR_CHAINLDR_SOURCE
|
||||
${XTLDR_CHAINLDR_SOURCE_DIR}/chainldr.c
|
||||
${XTLDR_CHAINLDR_SOURCE_DIR}/globals.c)
|
||||
${XTLDR_CHAINLDR_SOURCE_DIR}/chainldr.cc
|
||||
${XTLDR_CHAINLDR_SOURCE_DIR}/data.cc)
|
||||
|
||||
# Link module executable
|
||||
add_executable(chainldr ${XTLDR_CHAINLDR_SOURCE})
|
||||
|
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtldr/modules/chainldr/chainldr.c
|
||||
* FILE: xtldr/modules/chainldr/chainldr.cc
|
||||
* DESCRIPTION: XTLDR Chain Loader
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <chainldr.h>
|
||||
#include <chainldr.hh>
|
||||
|
||||
|
||||
/* ChainLoader module information */
|
||||
@@ -15,6 +15,7 @@ MODULE_DESCRIPTION(L"XTLDR Chain Loader");
|
||||
MODULE_LICENSE(L"GPLv3");
|
||||
MODULE_VERSION(L"0.1");
|
||||
|
||||
|
||||
/**
|
||||
* Chainloads another boot loader.
|
||||
*
|
||||
@@ -27,7 +28,7 @@ MODULE_VERSION(L"0.1");
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
ChBootSystem(IN PXTBL_BOOT_PARAMETERS Parameters)
|
||||
ChainLoader::BootSystem(IN PXTBL_BOOT_PARAMETERS Parameters)
|
||||
{
|
||||
EFI_GUID LIPGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
|
||||
EFI_MEMMAP_DEVICE_PATH MemoryDevicePath[2];
|
||||
@@ -66,14 +67,14 @@ ChBootSystem(IN PXTBL_BOOT_PARAMETERS Parameters)
|
||||
XtLdrProtocol->Debug.Print(L"ERROR: Unable to open system boot directory (Status Code: 0x%zX)\n", Status);
|
||||
|
||||
/* Close volume and return error code */
|
||||
XtLdrProtocol->Disk.CloseVolume(DiskHandle);
|
||||
XtLdrProtocol->Disk.CloseVolume(&DiskHandle);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* Read EFI image file from disk and close both directory and EFI volume */
|
||||
Status = XtLdrProtocol->Disk.ReadFile(BootDir, Parameters->KernelFile, &LoaderData, &LoaderSize);
|
||||
BootDir->Close(BootDir);
|
||||
XtLdrProtocol->Disk.CloseVolume(DiskHandle);
|
||||
XtLdrProtocol->Disk.CloseVolume(&DiskHandle);
|
||||
|
||||
/* Setup device path for EFI image */
|
||||
MemoryDevicePath[0].Header.Length[0] = sizeof(EFI_MEMMAP_DEVICE_PATH);
|
||||
@@ -123,6 +124,45 @@ ChBootSystem(IN PXTBL_BOOT_PARAMETERS Parameters)
|
||||
return XtLdrProtocol->Util.StartEfiImage(LoaderHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes CHAINLDR module by opening XTLDR protocol and installing CHAINLOADER protocol.
|
||||
*
|
||||
* @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
|
||||
ChainLoader::InitializeModule(IN EFI_HANDLE ImageHandle,
|
||||
IN PEFI_SYSTEM_TABLE SystemTable)
|
||||
{
|
||||
EFI_GUID Guid = XT_CHAIN_BOOT_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 ChainLoader boot protocol */
|
||||
BootProtocol.BootSystem = BootSystem;
|
||||
|
||||
/* Register XTOS boot protocol */
|
||||
XtLdrProtocol->Boot.RegisterProtocol(L"CHAINLOADER", &Guid);
|
||||
|
||||
/* Install XTOS protocol */
|
||||
return XtLdrProtocol->Protocol.Install(&BootProtocol, &Guid);
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine is the entry point of the XT EFI boot loader module.
|
||||
*
|
||||
@@ -141,23 +181,6 @@ EFI_STATUS
|
||||
XtLdrModuleMain(IN EFI_HANDLE ImageHandle,
|
||||
IN PEFI_SYSTEM_TABLE SystemTable)
|
||||
{
|
||||
EFI_GUID Guid = XT_CHAIN_BOOT_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 ChainLoader boot protocol */
|
||||
ChpBootProtocol.BootSystem = ChBootSystem;
|
||||
|
||||
/* Register XTOS boot protocol */
|
||||
XtLdrProtocol->Boot.RegisterProtocol(L"CHAINLOADER", &Guid);
|
||||
|
||||
/* Install XTOS protocol */
|
||||
return XtLdrProtocol->Protocol.Install(&ChpBootProtocol, &Guid);
|
||||
/* Initialize CHAINLDR module */
|
||||
return ChainLoader::InitializeModule(ImageHandle, SystemTable);
|
||||
}
|
@@ -1,16 +1,16 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtldr/modules/chainldr/globals.c
|
||||
* DESCRIPTION: XTLDR Chain Loader global variables
|
||||
* FILE: xtldr/modules/chainldr/data.cc
|
||||
* DESCRIPTION: CHAINLDR module global and static data
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#include <xtblapi.h>
|
||||
#include <chainldr.hh>
|
||||
|
||||
|
||||
/* ChainLoader Boot Protocol */
|
||||
XTBL_BOOT_PROTOCOL ChpBootProtocol;
|
||||
XTBL_BOOT_PROTOCOL ChainLoader::BootProtocol;
|
||||
|
||||
/* XTLDR protocol handler */
|
||||
PXTBL_LOADER_PROTOCOL XtLdrProtocol;
|
||||
PXTBL_LOADER_PROTOCOL ChainLoader::XtLdrProtocol;
|
@@ -1,26 +0,0 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtldr/modules/chainldr/includes/chainldr.h
|
||||
* DESCRIPTION: XTLDR Chain Loader header file
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#ifndef __XTLDR_CHAINLDR_CHAINLDR_H
|
||||
#define __XTLDR_CHAINLDR_CHAINLDR_H
|
||||
|
||||
#include <xtblapi.h>
|
||||
#include <globals.h>
|
||||
|
||||
|
||||
/* ChainLoader module routines forward references */
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
ChBootSystem(IN PXTBL_BOOT_PARAMETERS Parameters);
|
||||
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
XtLdrModuleMain(IN EFI_HANDLE ImageHandle,
|
||||
IN PEFI_SYSTEM_TABLE SystemTable);
|
||||
|
||||
#endif/* __XTLDR_CHAINLDR_CHAINLDR_H */
|
28
xtldr/modules/chainldr/includes/chainldr.hh
Normal file
28
xtldr/modules/chainldr/includes/chainldr.hh
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtldr/modules/chainldr/includes/chainldr.hh
|
||||
* DESCRIPTION: XTLDR Chain Loader header file
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#ifndef __XTLDR_CHAINLDR_CHAINLDR_HH
|
||||
#define __XTLDR_CHAINLDR_CHAINLDR_HH
|
||||
|
||||
#include <xtblapi.h>
|
||||
|
||||
|
||||
/* CHAINLDR module for XTLDR */
|
||||
class ChainLoader
|
||||
{
|
||||
private:
|
||||
STATIC XTBL_BOOT_PROTOCOL BootProtocol;
|
||||
STATIC PXTBL_LOADER_PROTOCOL XtLdrProtocol;
|
||||
|
||||
public:
|
||||
STATIC XTCDECL EFI_STATUS BootSystem(IN PXTBL_BOOT_PARAMETERS Parameters);
|
||||
STATIC XTCDECL EFI_STATUS InitializeModule(IN EFI_HANDLE ImageHandle,
|
||||
IN PEFI_SYSTEM_TABLE SystemTable);
|
||||
};
|
||||
|
||||
#endif /* __XTLDR_CHAINLDR_CHAINLDR_HH */
|
@@ -1,21 +0,0 @@
|
||||
/**
|
||||
* PROJECT: ExectOS
|
||||
* COPYRIGHT: See COPYING.md in the top level directory
|
||||
* FILE: xtldr/modules/chainldr/includes/globals.h
|
||||
* DESCRIPTION: XTLDR Chain Loader global variables
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
|
||||
#ifndef __XTLDR_CHAINLDR_GLOBALS_H
|
||||
#define __XTLDR_CHAINLDR_GLOBALS_H
|
||||
|
||||
#include <chainldr.h>
|
||||
|
||||
|
||||
/* ChainLoader Boot Protocol */
|
||||
EXTERN XTBL_BOOT_PROTOCOL ChpBootProtocol;
|
||||
|
||||
/* XTLDR protocol handler */
|
||||
EXTERN PXTBL_LOADER_PROTOCOL XtLdrProtocol;
|
||||
|
||||
#endif/* __XTLDR_CHAINLDR_GLOBALS_H */
|
Reference in New Issue
Block a user