Migrate XTLDR modules to C++
All checks were successful
Builds / ExectOS (amd64, release) (push) Successful in 31s
Builds / ExectOS (amd64, debug) (push) Successful in 33s
Builds / ExectOS (i686, debug) (push) Successful in 29s
Builds / ExectOS (i686, release) (push) Successful in 27s

This commit is contained in:
2025-09-17 22:30:48 +02:00
parent 57fbbf820c
commit dcae0cbb91
56 changed files with 1259 additions and 1297 deletions

View File

@@ -8,8 +8,8 @@ include_directories(
# Specify list of source code files
list(APPEND XTLDR_BEEP_SOURCE
${XTLDR_BEEP_SOURCE_DIR}/beep.c
${XTLDR_BEEP_SOURCE_DIR}/globals.c)
${XTLDR_BEEP_SOURCE_DIR}/beep.cc
${XTLDR_BEEP_SOURCE_DIR}/data.cc)
# Link module executable
add_executable(beep ${XTLDR_BEEP_SOURCE})

View File

@@ -1,12 +1,12 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/beep/beep.c
* FILE: xtldr/modules/beep/beep.cc
* DESCRIPTION: XTLDR Beep Module
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <beep.h>
#include <beep.hh>
/* Beep module information */
@@ -15,6 +15,7 @@ MODULE_DESCRIPTION(L"Plays a GRUB compatible tune via PC speaker");
MODULE_LICENSE(L"GPLv3");
MODULE_VERSION(L"0.1");
/**
* Disables the PC speaker.
*
@@ -24,7 +25,7 @@ MODULE_VERSION(L"0.1");
*/
XTCDECL
VOID
BpDisableToneBeep()
Beep::DisableToneBeep()
{
UCHAR Status;
@@ -45,7 +46,7 @@ BpDisableToneBeep()
*/
XTCDECL
VOID
BpEnableToneBeep(IN UINT Pitch)
Beep::EnableToneBeep(IN UINT Pitch)
{
UINT Counter;
UCHAR Status;
@@ -72,6 +73,43 @@ BpEnableToneBeep(IN UINT Pitch)
HlWritePort8(0x61, Status | 0x03);
}
/**
* Initializes BEEP module by opening XTLDR protocol and playing the tune.
*
* @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
Beep::InitializeModule(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable)
{
EFI_STATUS Status;
PWCHAR Tune;
/* 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;
}
/* Play the tune set in the configuration */
XtLdrProtocol->Config.GetValue(L"TUNE", &Tune);
PlayTune(Tune);
/* Return success */
return STATUS_EFI_SUCCESS;
}
/**
* This routine plays a tune.
*
@@ -84,7 +122,7 @@ BpEnableToneBeep(IN UINT Pitch)
*/
XTCDECL
VOID
BpPlayTune(IN PWCHAR Arguments)
Beep::PlayTune(IN PWCHAR Arguments)
{
LONG Pitch, Duration, Tempo;
PWCHAR Argument, LastArgument;
@@ -104,28 +142,28 @@ BpPlayTune(IN PWCHAR Arguments)
if(Tempo < 0)
{
/* Set the tempo */
Tempo = BpWideStringToNumber(Argument);
Tempo = WideStringToNumber(Argument);
}
else if(Pitch < 0)
{
/* Set the pitch */
Pitch = BpWideStringToNumber(Argument);
Pitch = WideStringToNumber(Argument);
}
else
{
/* Set the duration */
Duration = BpWideStringToNumber(Argument);
Duration = WideStringToNumber(Argument);
/* Check pitch value */
if(Pitch > 0)
{
/* Emit the beep tone */
BpEnableToneBeep(Pitch);
EnableToneBeep(Pitch);
}
else
{
/* Stop emitting beep tone */
BpDisableToneBeep();
DisableToneBeep();
}
/* Wait for duration time */
@@ -141,7 +179,7 @@ BpPlayTune(IN PWCHAR Arguments)
}
/* Stop emitting beep tone */
BpDisableToneBeep();
DisableToneBeep();
}
/**
@@ -156,7 +194,7 @@ BpPlayTune(IN PWCHAR Arguments)
*/
XTCDECL
UINT
BpWideStringToNumber(IN PWCHAR String)
Beep::WideStringToNumber(IN PWCHAR String)
{
ULONG Number = 0;
@@ -195,21 +233,6 @@ EFI_STATUS
XtLdrModuleMain(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable)
{
EFI_STATUS Status;
PWCHAR Tune;
/* 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;
}
/* Play the tune set in the configuration */
XtLdrProtocol->Config.GetValue(L"TUNE", &Tune);
BpPlayTune(Tune);
/* Return success */
return STATUS_EFI_SUCCESS;
/* Initialize BEEP module */
return Beep::InitializeModule(ImageHandle, SystemTable);
}

View File

@@ -1,13 +1,13 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/beep/globals.c
* DESCRIPTION: Beep module global variables
* FILE: xtldr/modules/beep/data.cc
* DESCRIPTION: BEEP module global and static data
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include <xtblapi.h>
#include <beep.hh>
/* XTLDR protocol handler */
PXTBL_LOADER_PROTOCOL XtLdrProtocol;
PXTBL_LOADER_PROTOCOL Beep::XtLdrProtocol;

View File

@@ -1,38 +0,0 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/beep/includes/beep.h
* DESCRIPTION: XTLDR Beep Module header file
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_BEEP_BEEP_H
#define __XTLDR_BEEP_BEEP_H
#include <xtblapi.h>
#include <globals.h>
/* Beep module routines forward references */
XTCDECL
VOID
BpDisableToneBeep();
XTCDECL
VOID
BpEnableToneBeep(IN UINT Pitch);
XTCDECL
VOID
BpPlayTune(IN PWCHAR Arguments);
XTCDECL
UINT
BpWideStringToNumber(IN PWCHAR String);
XTCDECL
EFI_STATUS
XtLdrModuleMain(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable);
#endif/* __XTLDR_BEEP_BEEP_H */

View File

@@ -0,0 +1,32 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/beep/includes/beep.hh
* DESCRIPTION: XTLDR Beep Module header file
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_BEEP_BEEP_HH
#define __XTLDR_BEEP_BEEP_HH
#include <xtblapi.h>
/* BEEP module for XTLDR */
class Beep
{
private:
STATIC PXTBL_LOADER_PROTOCOL XtLdrProtocol;
public:
STATIC XTCDECL EFI_STATUS InitializeModule(IN EFI_HANDLE ImageHandle,
IN PEFI_SYSTEM_TABLE SystemTable);
STATIC XTCDECL VOID PlayTune(IN PWCHAR Arguments);
private:
STATIC XTCDECL VOID DisableToneBeep();
STATIC XTCDECL VOID EnableToneBeep(IN UINT Pitch);
STATIC XTCDECL UINT WideStringToNumber(IN PWCHAR String);
};
#endif /* __XTLDR_BEEP_BEEP_HH */

View File

@@ -1,18 +0,0 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtldr/modules/beep/includes/globals.h
* DESCRIPTION: XTLDR Beep Module global variables
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTLDR_BEEP_GLOBALS_H
#define __XTLDR_BEEP_GLOBALS_H
#include <beep.h>
/* XTLDR protocol handler */
EXTERN PXTBL_LOADER_PROTOCOL XtLdrProtocol;
#endif/* __XTLDR_BEEP_GLOBALS_H */