Partially move global variables into classes
This commit is contained in:
182
xtldr/config.cc
182
xtldr/config.cc
@@ -136,10 +136,10 @@ Configuration::GetEditableOptions(OUT PCWSTR **OptionsArray,
|
||||
ULONG Count = 0;
|
||||
|
||||
/* Return a pointer to the global array of editable options */
|
||||
*OptionsArray = BlpEditableConfigOptions;
|
||||
*OptionsArray = EditableConfigOptions;
|
||||
|
||||
/* Calculate the number of elements in the array */
|
||||
while(BlpEditableConfigOptions[Count])
|
||||
while(EditableConfigOptions[Count])
|
||||
{
|
||||
Count++;
|
||||
}
|
||||
@@ -176,8 +176,8 @@ Configuration::GetValue(IN PCWSTR ConfigName,
|
||||
KeyLength = RTL::WideString::WideStringLength(ConfigName, 0);
|
||||
|
||||
/* Iterate through config entries */
|
||||
ConfigListEntry = BlpConfig.Flink;
|
||||
while(ConfigListEntry != &BlpConfig)
|
||||
ConfigListEntry = Config.Flink;
|
||||
while(ConfigListEntry != &Config)
|
||||
{
|
||||
/* Get config entry */
|
||||
ConfigEntry = CONTAIN_RECORD(ConfigListEntry, XTBL_CONFIG_ENTRY, Flink);
|
||||
@@ -212,6 +212,164 @@ Configuration::GetValue(IN PCWSTR ConfigName,
|
||||
return STATUS_EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a list of operating systems for XTLDR boot menu.
|
||||
*
|
||||
* @param MenuEntries
|
||||
* Supplies a pointer to memory area where operating systems list will be stored.
|
||||
*
|
||||
* @param EntriesCount
|
||||
* Supplies a pointer to memory area where number of menu entries will be stored.
|
||||
*
|
||||
* @param DefaultId
|
||||
* Supplies a pointer to memory area where ID of default menu entry will be stored.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
Configuration::InitializeBootMenuList(IN ULONG MaxNameLength,
|
||||
OUT PXTBL_BOOTMENU_ITEM *MenuEntries,
|
||||
OUT PULONG EntriesCount,
|
||||
OUT PULONG DefaultId)
|
||||
{
|
||||
EFI_GUID VendorGuid = XT_BOOT_LOADER_PROTOCOL_GUID;
|
||||
PWCHAR DefaultMenuEntry, LastBooted, MenuEntryName, VisibleName;
|
||||
PLIST_ENTRY MenuEntrySectionList, MenuEntryList;
|
||||
PXTBL_CONFIG_SECTION MenuEntrySection;
|
||||
PXTBL_CONFIG_ENTRY MenuEntryOption;
|
||||
ULONG DefaultOS, NameLength,NumberOfEntries;
|
||||
PXTBL_BOOTMENU_ITEM OsList;
|
||||
EFI_STATUS Status;
|
||||
|
||||
/* Set default values */
|
||||
DefaultOS = 0;
|
||||
NumberOfEntries = 0;
|
||||
|
||||
/* Get default menu entry from configuration */
|
||||
Configuration::GetValue(L"DEFAULT", &DefaultMenuEntry);
|
||||
|
||||
/* Check if configuration allows to use last booted OS */
|
||||
if(Configuration::GetBooleanValue(L"KEEPLASTBOOT"))
|
||||
{
|
||||
/* Attempt to get last booted Operating System from NVRAM */
|
||||
Status = EfiUtils::GetEfiVariable(&VendorGuid, L"XtLdrLastBootOS", (PVOID*)&LastBooted);
|
||||
if(Status == STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Set default menu entry to last booted OS */
|
||||
DefaultMenuEntry = LastBooted;
|
||||
}
|
||||
}
|
||||
|
||||
/* Iterate through menu items to get a total number of entries */
|
||||
MenuEntrySectionList = BootMenuList->Flink;
|
||||
while(MenuEntrySectionList != BootMenuList)
|
||||
{
|
||||
/* Increase number of menu entries, and simply get next item */
|
||||
NumberOfEntries++;
|
||||
MenuEntrySectionList = MenuEntrySectionList->Flink;
|
||||
}
|
||||
|
||||
/* Allocate memory for the OS list depending on the item count */
|
||||
Status = Memory::AllocatePool(NumberOfEntries * sizeof(XTBL_BOOTMENU_ITEM), (PVOID*)&OsList);
|
||||
if(Status != STATUS_EFI_SUCCESS || !OsList)
|
||||
{
|
||||
/* Memory allocation failure */
|
||||
return STATUS_EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
/* Reset counter and iterate through all menu items once again */
|
||||
NumberOfEntries = 0;
|
||||
MenuEntrySectionList = BootMenuList->Flink;
|
||||
while(MenuEntrySectionList != BootMenuList)
|
||||
{
|
||||
/* NULLify menu entry name */
|
||||
MenuEntryName = NULLPTR;
|
||||
|
||||
/* Get menu section */
|
||||
MenuEntrySection = CONTAIN_RECORD(MenuEntrySectionList, XTBL_CONFIG_SECTION, Flink);
|
||||
|
||||
/* Check if this is the default menu entry */
|
||||
if((RTL::WideString::WideStringLength(MenuEntrySection->SectionName, 0) == RTL::WideString::WideStringLength(DefaultMenuEntry, 0)) &&
|
||||
(RTL::WideString::CompareWideStringInsensitive(MenuEntrySection->SectionName, DefaultMenuEntry, 0) == 0))
|
||||
{
|
||||
/* Set default OS ID */
|
||||
DefaultOS = NumberOfEntries;
|
||||
}
|
||||
|
||||
/* Iterate through all entry parameters */
|
||||
MenuEntryList = MenuEntrySection->Options.Flink;
|
||||
while(MenuEntryList != &MenuEntrySection->Options)
|
||||
{
|
||||
/* Get menu entry parameter */
|
||||
MenuEntryOption = CONTAIN_RECORD(MenuEntryList, XTBL_CONFIG_ENTRY, Flink);
|
||||
|
||||
/* Check if this is the menu entry display name */
|
||||
if(RTL::WideString::CompareWideStringInsensitive(MenuEntryOption->Name, L"SYSTEMNAME", 0) == 0)
|
||||
{
|
||||
/* Set menu entry display name */
|
||||
MenuEntryName = MenuEntryOption->Value;
|
||||
}
|
||||
|
||||
/* Get next parameter for this menu entry */
|
||||
MenuEntryList = MenuEntryList->Flink;
|
||||
}
|
||||
|
||||
/* Add OS to the boot menu list */
|
||||
OsList[NumberOfEntries].FullName = MenuEntryName;
|
||||
OsList[NumberOfEntries].ShortName = MenuEntrySection->SectionName;
|
||||
OsList[NumberOfEntries].Options = &MenuEntrySection->Options;
|
||||
|
||||
/* Check if the menu entry name fits the maximum length */
|
||||
NameLength = RTL::WideString::WideStringLength(MenuEntryName, 0);
|
||||
if(NameLength > MaxNameLength)
|
||||
{
|
||||
/* Menu entry name is too long, allocate memory for shorter name visible in the boot menu */
|
||||
Status = Memory::AllocatePool((MaxNameLength + 1) * sizeof(WCHAR), (PVOID*)&VisibleName);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Memory allocation failure */
|
||||
return STATUS_EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
/* Copy shorter name and append "..." at the end */
|
||||
RTL::Memory::CopyMemory(VisibleName, MenuEntryName, (MaxNameLength - 3) * sizeof(WCHAR));
|
||||
RTL::Memory::CopyMemory(VisibleName + MaxNameLength - 3, L"...", 3 * sizeof(WCHAR));
|
||||
VisibleName[MaxNameLength] = L'\0';
|
||||
|
||||
/* Set visible menu entry name */
|
||||
OsList[NumberOfEntries].EntryName = VisibleName;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Menu entry name fits the maximum length, use it as is */
|
||||
OsList[NumberOfEntries].EntryName = MenuEntryName;
|
||||
}
|
||||
|
||||
/* Get next menu entry */
|
||||
MenuEntrySectionList = MenuEntrySectionList->Flink;
|
||||
NumberOfEntries++;
|
||||
}
|
||||
|
||||
/* Set return values */
|
||||
*DefaultId = DefaultOS;
|
||||
*EntriesCount = NumberOfEntries;
|
||||
*MenuEntries = OsList;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
XTCDECL
|
||||
VOID
|
||||
Configuration::InitializeConfiguration()
|
||||
{
|
||||
/* Initialize XTLDR configuration linked lists */
|
||||
RTL::LinkedList::InitializeListHead(&Config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and parses XTLDR configuration file.
|
||||
*
|
||||
@@ -228,7 +386,7 @@ Configuration::LoadConfiguration()
|
||||
PCHAR ConfigData;
|
||||
|
||||
/* Initialize configuration pointer */
|
||||
RTL::LinkedList::InitializeListHead(&BlpConfigSections);
|
||||
RTL::LinkedList::InitializeListHead(&ConfigSections);
|
||||
|
||||
/* Read data from configuration file */
|
||||
Status = ReadConfigFile(XTBL_LOADER_DIRECTORY_PATH, L"XTLDR.INI", &ConfigData);
|
||||
@@ -247,7 +405,7 @@ Configuration::LoadConfiguration()
|
||||
}
|
||||
|
||||
/* Parse configuration data */
|
||||
Status = ParseConfigFile(ConfigData, &BlpConfigSections);
|
||||
Status = ParseConfigFile(ConfigData, &ConfigSections);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to parse configuration */
|
||||
@@ -256,8 +414,8 @@ Configuration::LoadConfiguration()
|
||||
}
|
||||
|
||||
/* Iterate through config sections */
|
||||
SectionListEntry = BlpConfigSections.Flink;
|
||||
while(SectionListEntry != &BlpConfigSections)
|
||||
SectionListEntry = ConfigSections.Flink;
|
||||
while(SectionListEntry != &ConfigSections)
|
||||
{
|
||||
/* Get config section */
|
||||
PXTBL_CONFIG_SECTION Section = CONTAIN_RECORD(SectionListEntry, XTBL_CONFIG_SECTION, Flink);
|
||||
@@ -278,7 +436,7 @@ Configuration::LoadConfiguration()
|
||||
}
|
||||
|
||||
/* Update boot menu OS list */
|
||||
BlpMenuList = &BlpConfigSections;
|
||||
BootMenuList = &ConfigSections;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
@@ -800,8 +958,8 @@ Configuration::SetValue(IN PCWSTR ConfigName,
|
||||
Length = RTL::WideString::WideStringLength(ConfigName, 0);
|
||||
|
||||
/* Iterate through config entries */
|
||||
ConfigListEntry = BlpConfig.Flink;
|
||||
while(ConfigListEntry != &BlpConfig)
|
||||
ConfigListEntry = Config.Flink;
|
||||
while(ConfigListEntry != &Config)
|
||||
{
|
||||
/* Get config entry */
|
||||
ConfigEntry = CONTAIN_RECORD(ConfigListEntry, XTBL_CONFIG_ENTRY, Flink);
|
||||
@@ -877,7 +1035,7 @@ Configuration::UpdateConfiguration(IN PLIST_ENTRY NewConfig)
|
||||
{
|
||||
/* Remove new config entry from input list and put it into global config list */
|
||||
RTL::LinkedList::RemoveEntryList(&ConfigEntry->Flink);
|
||||
RTL::LinkedList::InsertTailList(&BlpConfig, &ConfigEntry->Flink);
|
||||
RTL::LinkedList::InsertTailList(&Config, &ConfigEntry->Flink);
|
||||
}
|
||||
|
||||
/* Move to the next new config entry */
|
||||
|
@@ -277,7 +277,7 @@ Debug::InitializeSerialPort(IN ULONG PortNumber,
|
||||
}
|
||||
|
||||
/* Set custom port address based on the port number and print debug message */
|
||||
PortAddress = BlComPortList[PortNumber - 1];
|
||||
PortAddress = ComPortList[PortNumber - 1];
|
||||
Console::Print(L"Initializing serial console at port COM%d\n", PortNumber);
|
||||
}
|
||||
else
|
||||
|
@@ -9,43 +9,44 @@
|
||||
#include <xtldr.hh>
|
||||
|
||||
|
||||
/* XT Boot Loader registered boot protocol list */
|
||||
LIST_ENTRY BlpBootProtocols;
|
||||
|
||||
/* XT Boot Loader serial ports list */
|
||||
ULONG BlComPortList[COMPORT_COUNT] = COMPORT_ADDRESS;
|
||||
/* XT Boot Loader menu list */
|
||||
PLIST_ENTRY Configuration::BootMenuList = NULLPTR;
|
||||
|
||||
/* XT Boot Loader configuration list */
|
||||
LIST_ENTRY BlpConfig;
|
||||
LIST_ENTRY Configuration::Config;
|
||||
|
||||
/* XT Boot Loader loaded configuration */
|
||||
LIST_ENTRY BlpConfigSections;
|
||||
LIST_ENTRY Configuration::ConfigSections;
|
||||
|
||||
/* List of user-editable boot options */
|
||||
PCWSTR BlpEditableConfigOptions[] = {
|
||||
PCWSTR Configuration::EditableConfigOptions[] = {
|
||||
L"BootModules", L"SystemType", L"SystemPath",
|
||||
L"KernelFile", L"InitrdFile", L"HalFile",
|
||||
L"Parameters", NULLPTR
|
||||
};
|
||||
|
||||
/* XT Boot Loader serial ports list */
|
||||
ULONG Debug::ComPortList[COMPORT_COUNT] = COMPORT_ADDRESS;
|
||||
|
||||
/* XT Boot Loader registered boot protocol list */
|
||||
LIST_ENTRY Protocol::BootProtocols;
|
||||
|
||||
/* XT Boot Loader protocol */
|
||||
XTBL_LOADER_PROTOCOL BlpLdrProtocol;
|
||||
XTBL_LOADER_PROTOCOL Protocol::LoaderProtocol;
|
||||
|
||||
/* XT Boot Loader loaded modules list */
|
||||
LIST_ENTRY BlpLoadedModules;
|
||||
LIST_ENTRY Protocol::LoadedModules;
|
||||
|
||||
/* List of available block devices */
|
||||
LIST_ENTRY Volume::EfiBlockDevices;
|
||||
|
||||
|
||||
/* XT Boot Loader menu list */
|
||||
PLIST_ENTRY BlpMenuList = NULLPTR;
|
||||
|
||||
/* XT Boot Loader status data */
|
||||
XTBL_STATUS BlpStatus = {0};
|
||||
|
||||
/* List of available block devices */
|
||||
LIST_ENTRY EfiBlockDevices;
|
||||
|
||||
/* EFI Image Handle */
|
||||
EFI_HANDLE EfiImageHandle;
|
||||
|
||||
/* EFI System Table */
|
||||
PEFI_SYSTEM_TABLE EfiSystemTable;
|
||||
|
||||
|
@@ -25,6 +25,12 @@ class BootUtils
|
||||
|
||||
class Configuration
|
||||
{
|
||||
private:
|
||||
STATIC PLIST_ENTRY BootMenuList;
|
||||
STATIC LIST_ENTRY Config;
|
||||
STATIC LIST_ENTRY ConfigSections;
|
||||
STATIC PCWSTR EditableConfigOptions[];
|
||||
|
||||
public:
|
||||
STATIC XTCDECL BOOLEAN GetBooleanValue(IN PCWSTR ConfigName);
|
||||
STATIC XTCDECL EFI_STATUS GetBootOptionValue(IN PLIST_ENTRY Options,
|
||||
@@ -34,6 +40,11 @@ class Configuration
|
||||
OUT PULONG OptionsCount);
|
||||
STATIC XTCDECL EFI_STATUS GetValue(IN PCWSTR ConfigName,
|
||||
OUT PWCHAR *ConfigValue);
|
||||
STATIC XTCDECL EFI_STATUS InitializeBootMenuList(IN ULONG MaxNameLength,
|
||||
OUT PXTBL_BOOTMENU_ITEM *MenuEntries,
|
||||
OUT PULONG EntriesCount,
|
||||
OUT PULONG DefaultId);
|
||||
STATIC XTCDECL VOID InitializeConfiguration();
|
||||
STATIC XTCDECL EFI_STATUS LoadConfiguration();
|
||||
STATIC XTCDECL EFI_STATUS ParseCommandLine();
|
||||
STATIC XTCDECL EFI_STATUS SetBootOptionValue(IN PLIST_ENTRY Options,
|
||||
@@ -77,17 +88,20 @@ class Console
|
||||
|
||||
class Debug
|
||||
{
|
||||
private:
|
||||
STATIC ULONG ComPortList[COMPORT_COUNT];
|
||||
|
||||
public:
|
||||
STATIC XTCDECL EFI_STATUS InitializeDebugConsole();
|
||||
STATIC XTCDECL VOID Print(IN PCWSTR Format,
|
||||
IN ...);
|
||||
STATIC XTCDECL XTSTATUS PutChar(IN WCHAR Character);
|
||||
|
||||
private:
|
||||
STATIC XTCDECL EFI_STATUS ActivateSerialIOController();
|
||||
STATIC XTCDECL EFI_STATUS InitializeSerialPort(IN ULONG PortNumber,
|
||||
IN ULONG PortAddress,
|
||||
IN ULONG BaudRate);
|
||||
private:
|
||||
STATIC XTCDECL EFI_STATUS ActivateSerialIOController();
|
||||
STATIC XTCDECL EFI_STATUS InitializeSerialPort(IN ULONG PortNumber,
|
||||
IN ULONG PortAddress,
|
||||
IN ULONG BaudRate);
|
||||
};
|
||||
|
||||
class EfiUtils
|
||||
@@ -173,6 +187,11 @@ class Memory
|
||||
|
||||
class Protocol
|
||||
{
|
||||
private:
|
||||
STATIC LIST_ENTRY BootProtocols;
|
||||
STATIC XTBL_LOADER_PROTOCOL LoaderProtocol;
|
||||
STATIC LIST_ENTRY LoadedModules;
|
||||
|
||||
public:
|
||||
STATIC XTCDECL EFI_STATUS CloseProtocol(IN PEFI_HANDLE Handle,
|
||||
IN PEFI_GUID ProtocolGuid);
|
||||
@@ -181,6 +200,7 @@ class Protocol
|
||||
STATIC XTCDECL PLIST_ENTRY GetModulesList();
|
||||
STATIC XTCDECL EFI_STATUS InstallProtocol(IN PVOID Interface,
|
||||
IN PEFI_GUID Guid);
|
||||
STATIC XTCDECL VOID InitializeProtocol();
|
||||
STATIC XTCDECL EFI_STATUS InvokeBootProtocol(IN PWCHAR ShortName,
|
||||
IN PLIST_ENTRY OptionsList);
|
||||
STATIC XTCDECL EFI_STATUS LoadModule(IN PWCHAR ModuleName);
|
||||
@@ -265,6 +285,9 @@ class TextUi
|
||||
|
||||
class Volume
|
||||
{
|
||||
private:
|
||||
STATIC LIST_ENTRY EfiBlockDevices;
|
||||
|
||||
public:
|
||||
STATIC XTCDECL EFI_STATUS CloseVolume(IN PEFI_HANDLE VolumeHandle);
|
||||
STATIC XTCDECL EFI_STATUS EnumerateBlockDevices();
|
||||
@@ -306,10 +329,6 @@ class XtLoader
|
||||
{
|
||||
public:
|
||||
STATIC XTCDECL VOID InitializeBootLoader();
|
||||
STATIC XTCDECL EFI_STATUS InitializeBootMenuList(IN ULONG MaxNameLength,
|
||||
OUT PXTBL_BOOTMENU_ITEM *MenuEntries,
|
||||
OUT PULONG EntriesCount,
|
||||
OUT PULONG DefaultId);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -51,8 +51,8 @@ Protocol::FindBootProtocol(IN PCWSTR SystemType,
|
||||
PXTBL_KNOWN_BOOT_PROTOCOL ProtocolEntry;
|
||||
PLIST_ENTRY ProtocolListEntry;
|
||||
|
||||
ProtocolListEntry = BlpBootProtocols.Flink;
|
||||
while(ProtocolListEntry != &BlpBootProtocols)
|
||||
ProtocolListEntry = BootProtocols.Flink;
|
||||
while(ProtocolListEntry != &BootProtocols)
|
||||
{
|
||||
/* Get boot protocol entry */
|
||||
ProtocolEntry = CONTAIN_RECORD(ProtocolListEntry, XTBL_KNOWN_BOOT_PROTOCOL, Flink);
|
||||
@@ -87,7 +87,16 @@ PLIST_ENTRY
|
||||
Protocol::GetModulesList()
|
||||
{
|
||||
/* Return a pointer to a list of all loaded modules */
|
||||
return &BlpLoadedModules;
|
||||
return &LoadedModules;
|
||||
}
|
||||
|
||||
XTCDECL
|
||||
VOID
|
||||
Protocol::InitializeProtocol()
|
||||
{
|
||||
/* Initialize list of loaded modules and boot protocols */
|
||||
RTL::LinkedList::InitializeListHead(&BootProtocols);
|
||||
RTL::LinkedList::InitializeListHead(&LoadedModules);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,8 +306,8 @@ Protocol::LoadModule(IN PWCHAR ModuleName)
|
||||
EFI_STATUS Status;
|
||||
PVOID ModuleData;
|
||||
|
||||
ModuleListEntry = BlpLoadedModules.Flink;
|
||||
while(ModuleListEntry != &BlpLoadedModules)
|
||||
ModuleListEntry = LoadedModules.Flink;
|
||||
while(ModuleListEntry != &LoadedModules)
|
||||
{
|
||||
/* Get module information */
|
||||
ModuleInfo = CONTAIN_RECORD(ModuleListEntry, XTBL_MODULE_INFO, Flink);
|
||||
@@ -509,7 +518,7 @@ Protocol::LoadModule(IN PWCHAR ModuleName)
|
||||
}
|
||||
|
||||
/* Add module to the list of loaded modules */
|
||||
RTL::LinkedList::InsertTailList(&BlpLoadedModules, &ModuleInfo->Flink);
|
||||
RTL::LinkedList::InsertTailList(&LoadedModules, &ModuleInfo->Flink);
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
@@ -719,8 +728,8 @@ Protocol::RegisterBootProtocol(IN PCWSTR SystemType,
|
||||
PLIST_ENTRY ProtocolListEntry;
|
||||
EFI_STATUS Status;
|
||||
|
||||
ProtocolListEntry = BlpBootProtocols.Flink;
|
||||
while(ProtocolListEntry != &BlpBootProtocols)
|
||||
ProtocolListEntry = BootProtocols.Flink;
|
||||
while(ProtocolListEntry != &BootProtocols)
|
||||
{
|
||||
/* Get boot protocol entry */
|
||||
ProtocolEntry = CONTAIN_RECORD(ProtocolListEntry, XTBL_KNOWN_BOOT_PROTOCOL, Flink);
|
||||
@@ -747,7 +756,7 @@ Protocol::RegisterBootProtocol(IN PCWSTR SystemType,
|
||||
/* Set protocol properties and add it to the list */
|
||||
ProtocolEntry->SystemType = (PWCHAR)SystemType;
|
||||
ProtocolEntry->Guid = *BootProtocolGuid;
|
||||
RTL::LinkedList::InsertTailList(&BlpBootProtocols, &ProtocolEntry->Flink);
|
||||
RTL::LinkedList::InsertTailList(&BootProtocols, &ProtocolEntry->Flink);
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
@@ -1014,103 +1023,103 @@ Protocol::InstallXtLoaderProtocol()
|
||||
EFI_GUID Guid = XT_BOOT_LOADER_PROTOCOL_GUID;
|
||||
|
||||
/* Set all routines available via loader protocol */
|
||||
BlpLdrProtocol.Boot.FindProtocol = FindBootProtocol;
|
||||
BlpLdrProtocol.Boot.InitializeMenuList = XtLoader::InitializeBootMenuList;
|
||||
BlpLdrProtocol.Boot.InvokeProtocol = InvokeBootProtocol;
|
||||
BlpLdrProtocol.Boot.RegisterMenu = RegisterBootMenu;
|
||||
BlpLdrProtocol.Boot.RegisterProtocol = RegisterBootProtocol;
|
||||
BlpLdrProtocol.BootUtils.GetBooleanParameter = BootUtils::GetBooleanParameter;
|
||||
BlpLdrProtocol.BootUtils.GetTrampolineInformation = AR::ProcSup::GetTrampolineInformation;
|
||||
BlpLdrProtocol.Config.GetBooleanValue = Configuration::GetBooleanValue;
|
||||
BlpLdrProtocol.Config.GetBootOptionValue = Configuration::GetBootOptionValue;
|
||||
BlpLdrProtocol.Config.GetEditableOptions = Configuration::GetEditableOptions;
|
||||
BlpLdrProtocol.Config.GetValue = Configuration::GetValue;
|
||||
BlpLdrProtocol.Config.SetBootOptionValue = Configuration::SetBootOptionValue;
|
||||
BlpLdrProtocol.Console.ClearLine = Console::ClearLine;
|
||||
BlpLdrProtocol.Console.ClearScreen = Console::ClearScreen;
|
||||
BlpLdrProtocol.Console.DisableCursor = Console::DisableCursor;
|
||||
BlpLdrProtocol.Console.EnableCursor = Console::EnableCursor;
|
||||
BlpLdrProtocol.Console.Print = Console::Print;
|
||||
BlpLdrProtocol.Console.QueryMode = Console::QueryMode;
|
||||
BlpLdrProtocol.Console.ReadKeyStroke = Console::ReadKeyStroke;
|
||||
BlpLdrProtocol.Console.ResetInputBuffer = Console::ResetInputBuffer;
|
||||
BlpLdrProtocol.Console.SetAttributes = Console::SetAttributes;
|
||||
BlpLdrProtocol.Console.SetCursorPosition = Console::SetCursorPosition;
|
||||
BlpLdrProtocol.Console.Write = Console::Write;
|
||||
BlpLdrProtocol.Cpu.CpuId = AR::CpuFunc::CpuId;
|
||||
BlpLdrProtocol.Cpu.ReadControlRegister = AR::CpuFunc::ReadControlRegister;
|
||||
BlpLdrProtocol.Cpu.ReadModelSpecificRegister = AR::CpuFunc::ReadModelSpecificRegister;
|
||||
BlpLdrProtocol.Cpu.WriteControlRegister = AR::CpuFunc::WriteControlRegister;
|
||||
BlpLdrProtocol.Debug.Print = Debug::Print;
|
||||
BlpLdrProtocol.Disk.CloseVolume = Volume::CloseVolume;
|
||||
BlpLdrProtocol.Disk.OpenVolume = Volume::OpenVolume;
|
||||
BlpLdrProtocol.Disk.ReadFile = Volume::ReadFile;
|
||||
BlpLdrProtocol.IoPort.Read8 = HL::IoPort::ReadPort8;
|
||||
BlpLdrProtocol.IoPort.Read16 = HL::IoPort::ReadPort16;
|
||||
BlpLdrProtocol.IoPort.Read32 = HL::IoPort::ReadPort32;
|
||||
BlpLdrProtocol.IoPort.Write8 = HL::IoPort::WritePort8;
|
||||
BlpLdrProtocol.IoPort.Write16 = HL::IoPort::WritePort16;
|
||||
BlpLdrProtocol.IoPort.Write32 = HL::IoPort::WritePort32;
|
||||
BlpLdrProtocol.LinkedList.InitializeHead = RTL::LinkedList::InitializeListHead;
|
||||
BlpLdrProtocol.LinkedList.InsertHead = RTL::LinkedList::InsertHeadList;
|
||||
BlpLdrProtocol.LinkedList.InsertTail = RTL::LinkedList::InsertTailList;
|
||||
BlpLdrProtocol.LinkedList.RemoveEntry = RTL::LinkedList::RemoveEntryList;
|
||||
BlpLdrProtocol.Memory.AllocatePages = Memory::AllocatePages;
|
||||
BlpLdrProtocol.Memory.AllocatePool = Memory::AllocatePool;
|
||||
BlpLdrProtocol.Memory.BuildPageMap = Memory::BuildPageMap;
|
||||
BlpLdrProtocol.Memory.CompareMemory = RTL::Memory::CompareMemory;
|
||||
BlpLdrProtocol.Memory.CopyMemory = RTL::Memory::CopyMemory;
|
||||
BlpLdrProtocol.Memory.FreePages = Memory::FreePages;
|
||||
BlpLdrProtocol.Memory.FreePool = Memory::FreePool;
|
||||
BlpLdrProtocol.Memory.GetMappingsCount = Memory::GetMappingsCount;
|
||||
BlpLdrProtocol.Memory.GetMemoryMap = Memory::GetMemoryMap;
|
||||
BlpLdrProtocol.Memory.GetVirtualAddress = Memory::GetVirtualAddress;
|
||||
BlpLdrProtocol.Memory.InitializePageMap = Memory::InitializePageMap;
|
||||
BlpLdrProtocol.Memory.MapEfiMemory = Memory::MapEfiMemory;
|
||||
BlpLdrProtocol.Memory.MapPage = Memory::MapPage;
|
||||
BlpLdrProtocol.Memory.MapVirtualMemory = Memory::MapVirtualMemory;
|
||||
BlpLdrProtocol.Memory.MoveMemory = RTL::Memory::MoveMemory;
|
||||
BlpLdrProtocol.Memory.PhysicalAddressToVirtual = Memory::PhysicalAddressToVirtual;
|
||||
BlpLdrProtocol.Memory.PhysicalListToVirtual = Memory::PhysicalListToVirtual;
|
||||
BlpLdrProtocol.Memory.SetMemory = RTL::Memory::SetMemory;
|
||||
BlpLdrProtocol.Memory.ZeroMemory = RTL::Memory::ZeroMemory;
|
||||
BlpLdrProtocol.Protocol.Close = CloseProtocol;
|
||||
BlpLdrProtocol.Protocol.GetModulesList = GetModulesList;
|
||||
BlpLdrProtocol.Protocol.Install = InstallProtocol;
|
||||
BlpLdrProtocol.Protocol.LocateHandles = LocateProtocolHandles;
|
||||
BlpLdrProtocol.Protocol.Open = OpenProtocol;
|
||||
BlpLdrProtocol.Protocol.OpenHandle = OpenProtocolHandle;
|
||||
BlpLdrProtocol.String.Compare = RTL::String::CompareString;
|
||||
BlpLdrProtocol.String.Length = RTL::String::StringLength;
|
||||
BlpLdrProtocol.String.ToWideString = RTL::String::StringToWideString;
|
||||
BlpLdrProtocol.String.Trim = RTL::String::TrimString;
|
||||
BlpLdrProtocol.Tui.DisplayErrorDialog = TextUi::DisplayErrorDialog;
|
||||
BlpLdrProtocol.Tui.DisplayInfoDialog = TextUi::DisplayInfoDialog;
|
||||
BlpLdrProtocol.Tui.DisplayInputDialog = TextUi::DisplayInputDialog;
|
||||
BlpLdrProtocol.Tui.DisplayProgressDialog = TextUi::DisplayProgressDialog;
|
||||
BlpLdrProtocol.Tui.UpdateProgressBar = TextUi::UpdateProgressBar;
|
||||
BlpLdrProtocol.Utils.EnterFirmwareSetup = EfiUtils::EnterFirmwareSetup;
|
||||
BlpLdrProtocol.Utils.ExitBootServices = EfiUtils::ExitBootServices;
|
||||
BlpLdrProtocol.Utils.GetConfigurationTable = EfiUtils::GetConfigurationTable;
|
||||
BlpLdrProtocol.Utils.GetEfiVariable = EfiUtils::GetEfiVariable;
|
||||
BlpLdrProtocol.Utils.GetRandomValue = EfiUtils::GetRandomValue;
|
||||
BlpLdrProtocol.Utils.GetSecureBootStatus = EfiUtils::GetSecureBootStatus;
|
||||
BlpLdrProtocol.Utils.InitializeEntropy = EfiUtils::InitializeEntropy;
|
||||
BlpLdrProtocol.Utils.LoadEfiImage = EfiUtils::LoadEfiImage;
|
||||
BlpLdrProtocol.Utils.RebootSystem = EfiUtils::RebootSystem;
|
||||
BlpLdrProtocol.Utils.SetEfiVariable = EfiUtils::SetEfiVariable;
|
||||
BlpLdrProtocol.Utils.ShutdownSystem = EfiUtils::ShutdownSystem;
|
||||
BlpLdrProtocol.Utils.SleepExecution = EfiUtils::SleepExecution;
|
||||
BlpLdrProtocol.Utils.StartEfiImage = EfiUtils::StartEfiImage;
|
||||
BlpLdrProtocol.Utils.WaitForEfiEvent = EfiUtils::WaitForEfiEvent;
|
||||
BlpLdrProtocol.WideString.Compare = RTL::WideString::CompareWideString;
|
||||
BlpLdrProtocol.WideString.CompareInsensitive = RTL::WideString::CompareWideStringInsensitive;
|
||||
BlpLdrProtocol.WideString.Concatenate = RTL::WideString::ConcatenateWideString;
|
||||
BlpLdrProtocol.WideString.Format = RTL::WideString::FormatWideString;
|
||||
BlpLdrProtocol.WideString.Length = RTL::WideString::WideStringLength;
|
||||
BlpLdrProtocol.WideString.Tokenize = RTL::WideString::TokenizeWideString;
|
||||
LoaderProtocol.Boot.FindProtocol = FindBootProtocol;
|
||||
LoaderProtocol.Boot.InitializeMenuList = Configuration::InitializeBootMenuList;
|
||||
LoaderProtocol.Boot.InvokeProtocol = InvokeBootProtocol;
|
||||
LoaderProtocol.Boot.RegisterMenu = RegisterBootMenu;
|
||||
LoaderProtocol.Boot.RegisterProtocol = RegisterBootProtocol;
|
||||
LoaderProtocol.BootUtils.GetBooleanParameter = BootUtils::GetBooleanParameter;
|
||||
LoaderProtocol.BootUtils.GetTrampolineInformation = AR::ProcSup::GetTrampolineInformation;
|
||||
LoaderProtocol.Config.GetBooleanValue = Configuration::GetBooleanValue;
|
||||
LoaderProtocol.Config.GetBootOptionValue = Configuration::GetBootOptionValue;
|
||||
LoaderProtocol.Config.GetEditableOptions = Configuration::GetEditableOptions;
|
||||
LoaderProtocol.Config.GetValue = Configuration::GetValue;
|
||||
LoaderProtocol.Config.SetBootOptionValue = Configuration::SetBootOptionValue;
|
||||
LoaderProtocol.Console.ClearLine = Console::ClearLine;
|
||||
LoaderProtocol.Console.ClearScreen = Console::ClearScreen;
|
||||
LoaderProtocol.Console.DisableCursor = Console::DisableCursor;
|
||||
LoaderProtocol.Console.EnableCursor = Console::EnableCursor;
|
||||
LoaderProtocol.Console.Print = Console::Print;
|
||||
LoaderProtocol.Console.QueryMode = Console::QueryMode;
|
||||
LoaderProtocol.Console.ReadKeyStroke = Console::ReadKeyStroke;
|
||||
LoaderProtocol.Console.ResetInputBuffer = Console::ResetInputBuffer;
|
||||
LoaderProtocol.Console.SetAttributes = Console::SetAttributes;
|
||||
LoaderProtocol.Console.SetCursorPosition = Console::SetCursorPosition;
|
||||
LoaderProtocol.Console.Write = Console::Write;
|
||||
LoaderProtocol.Cpu.CpuId = AR::CpuFunc::CpuId;
|
||||
LoaderProtocol.Cpu.ReadControlRegister = AR::CpuFunc::ReadControlRegister;
|
||||
LoaderProtocol.Cpu.ReadModelSpecificRegister = AR::CpuFunc::ReadModelSpecificRegister;
|
||||
LoaderProtocol.Cpu.WriteControlRegister = AR::CpuFunc::WriteControlRegister;
|
||||
LoaderProtocol.Debug.Print = Debug::Print;
|
||||
LoaderProtocol.Disk.CloseVolume = Volume::CloseVolume;
|
||||
LoaderProtocol.Disk.OpenVolume = Volume::OpenVolume;
|
||||
LoaderProtocol.Disk.ReadFile = Volume::ReadFile;
|
||||
LoaderProtocol.IoPort.Read8 = HL::IoPort::ReadPort8;
|
||||
LoaderProtocol.IoPort.Read16 = HL::IoPort::ReadPort16;
|
||||
LoaderProtocol.IoPort.Read32 = HL::IoPort::ReadPort32;
|
||||
LoaderProtocol.IoPort.Write8 = HL::IoPort::WritePort8;
|
||||
LoaderProtocol.IoPort.Write16 = HL::IoPort::WritePort16;
|
||||
LoaderProtocol.IoPort.Write32 = HL::IoPort::WritePort32;
|
||||
LoaderProtocol.LinkedList.InitializeHead = RTL::LinkedList::InitializeListHead;
|
||||
LoaderProtocol.LinkedList.InsertHead = RTL::LinkedList::InsertHeadList;
|
||||
LoaderProtocol.LinkedList.InsertTail = RTL::LinkedList::InsertTailList;
|
||||
LoaderProtocol.LinkedList.RemoveEntry = RTL::LinkedList::RemoveEntryList;
|
||||
LoaderProtocol.Memory.AllocatePages = Memory::AllocatePages;
|
||||
LoaderProtocol.Memory.AllocatePool = Memory::AllocatePool;
|
||||
LoaderProtocol.Memory.BuildPageMap = Memory::BuildPageMap;
|
||||
LoaderProtocol.Memory.CompareMemory = RTL::Memory::CompareMemory;
|
||||
LoaderProtocol.Memory.CopyMemory = RTL::Memory::CopyMemory;
|
||||
LoaderProtocol.Memory.FreePages = Memory::FreePages;
|
||||
LoaderProtocol.Memory.FreePool = Memory::FreePool;
|
||||
LoaderProtocol.Memory.GetMappingsCount = Memory::GetMappingsCount;
|
||||
LoaderProtocol.Memory.GetMemoryMap = Memory::GetMemoryMap;
|
||||
LoaderProtocol.Memory.GetVirtualAddress = Memory::GetVirtualAddress;
|
||||
LoaderProtocol.Memory.InitializePageMap = Memory::InitializePageMap;
|
||||
LoaderProtocol.Memory.MapEfiMemory = Memory::MapEfiMemory;
|
||||
LoaderProtocol.Memory.MapPage = Memory::MapPage;
|
||||
LoaderProtocol.Memory.MapVirtualMemory = Memory::MapVirtualMemory;
|
||||
LoaderProtocol.Memory.MoveMemory = RTL::Memory::MoveMemory;
|
||||
LoaderProtocol.Memory.PhysicalAddressToVirtual = Memory::PhysicalAddressToVirtual;
|
||||
LoaderProtocol.Memory.PhysicalListToVirtual = Memory::PhysicalListToVirtual;
|
||||
LoaderProtocol.Memory.SetMemory = RTL::Memory::SetMemory;
|
||||
LoaderProtocol.Memory.ZeroMemory = RTL::Memory::ZeroMemory;
|
||||
LoaderProtocol.Protocol.Close = CloseProtocol;
|
||||
LoaderProtocol.Protocol.GetModulesList = GetModulesList;
|
||||
LoaderProtocol.Protocol.Install = InstallProtocol;
|
||||
LoaderProtocol.Protocol.LocateHandles = LocateProtocolHandles;
|
||||
LoaderProtocol.Protocol.Open = OpenProtocol;
|
||||
LoaderProtocol.Protocol.OpenHandle = OpenProtocolHandle;
|
||||
LoaderProtocol.String.Compare = RTL::String::CompareString;
|
||||
LoaderProtocol.String.Length = RTL::String::StringLength;
|
||||
LoaderProtocol.String.ToWideString = RTL::String::StringToWideString;
|
||||
LoaderProtocol.String.Trim = RTL::String::TrimString;
|
||||
LoaderProtocol.Tui.DisplayErrorDialog = TextUi::DisplayErrorDialog;
|
||||
LoaderProtocol.Tui.DisplayInfoDialog = TextUi::DisplayInfoDialog;
|
||||
LoaderProtocol.Tui.DisplayInputDialog = TextUi::DisplayInputDialog;
|
||||
LoaderProtocol.Tui.DisplayProgressDialog = TextUi::DisplayProgressDialog;
|
||||
LoaderProtocol.Tui.UpdateProgressBar = TextUi::UpdateProgressBar;
|
||||
LoaderProtocol.Utils.EnterFirmwareSetup = EfiUtils::EnterFirmwareSetup;
|
||||
LoaderProtocol.Utils.ExitBootServices = EfiUtils::ExitBootServices;
|
||||
LoaderProtocol.Utils.GetConfigurationTable = EfiUtils::GetConfigurationTable;
|
||||
LoaderProtocol.Utils.GetEfiVariable = EfiUtils::GetEfiVariable;
|
||||
LoaderProtocol.Utils.GetRandomValue = EfiUtils::GetRandomValue;
|
||||
LoaderProtocol.Utils.GetSecureBootStatus = EfiUtils::GetSecureBootStatus;
|
||||
LoaderProtocol.Utils.InitializeEntropy = EfiUtils::InitializeEntropy;
|
||||
LoaderProtocol.Utils.LoadEfiImage = EfiUtils::LoadEfiImage;
|
||||
LoaderProtocol.Utils.RebootSystem = EfiUtils::RebootSystem;
|
||||
LoaderProtocol.Utils.SetEfiVariable = EfiUtils::SetEfiVariable;
|
||||
LoaderProtocol.Utils.ShutdownSystem = EfiUtils::ShutdownSystem;
|
||||
LoaderProtocol.Utils.SleepExecution = EfiUtils::SleepExecution;
|
||||
LoaderProtocol.Utils.StartEfiImage = EfiUtils::StartEfiImage;
|
||||
LoaderProtocol.Utils.WaitForEfiEvent = EfiUtils::WaitForEfiEvent;
|
||||
LoaderProtocol.WideString.Compare = RTL::WideString::CompareWideString;
|
||||
LoaderProtocol.WideString.CompareInsensitive = RTL::WideString::CompareWideStringInsensitive;
|
||||
LoaderProtocol.WideString.Concatenate = RTL::WideString::ConcatenateWideString;
|
||||
LoaderProtocol.WideString.Format = RTL::WideString::FormatWideString;
|
||||
LoaderProtocol.WideString.Length = RTL::WideString::WideStringLength;
|
||||
LoaderProtocol.WideString.Tokenize = RTL::WideString::TokenizeWideString;
|
||||
|
||||
/* Register XTLDR loader protocol */
|
||||
Debug::Print(L"Registering XT loader protocol\n");
|
||||
return InstallProtocol(&BlpLdrProtocol, &Guid);
|
||||
return InstallProtocol(&LoaderProtocol, &Guid);
|
||||
}
|
||||
|
@@ -159,7 +159,7 @@ TextUi::DisplayBootMenu()
|
||||
|
||||
/* Initialize boot menu list */
|
||||
TopVisibleEntry = 0;
|
||||
Status = XtLoader::InitializeBootMenuList(Handle.Width - 4, &MenuEntries, &NumberOfEntries, &HighligtedEntryId);
|
||||
Status = Configuration::InitializeBootMenuList(Handle.Width - 4, &MenuEntries, &NumberOfEntries, &HighligtedEntryId);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Failed to initialize boot menu list, exit into XTLDR shell */
|
||||
|
159
xtldr/xtldr.cc
159
xtldr/xtldr.cc
@@ -34,10 +34,11 @@ XtLoader::InitializeBootLoader()
|
||||
/* Print XTLDR version */
|
||||
Console::Print(L"XTLDR boot loader v%s\n", XTOS_VERSION);
|
||||
|
||||
/* Initialize XTLDR configuration linked lists */
|
||||
RTL::LinkedList::InitializeListHead(&BlpBootProtocols);
|
||||
RTL::LinkedList::InitializeListHead(&BlpConfig);
|
||||
RTL::LinkedList::InitializeListHead(&BlpLoadedModules);
|
||||
/* Initialize XTLDR protocol */
|
||||
Protocol::InitializeProtocol();
|
||||
|
||||
/* Initialize XTLDR configuration */
|
||||
Configuration::InitializeConfiguration();
|
||||
|
||||
/* Store SecureBoot status */
|
||||
BlpStatus.SecureBoot = EfiUtils::GetSecureBootStatus();
|
||||
@@ -74,156 +75,6 @@ XtLoader::InitializeBootLoader()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a list of operating systems for XTLDR boot menu.
|
||||
*
|
||||
* @param MenuEntries
|
||||
* Supplies a pointer to memory area where operating systems list will be stored.
|
||||
*
|
||||
* @param EntriesCount
|
||||
* Supplies a pointer to memory area where number of menu entries will be stored.
|
||||
*
|
||||
* @param DefaultId
|
||||
* Supplies a pointer to memory area where ID of default menu entry will be stored.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
EFI_STATUS
|
||||
XtLoader::InitializeBootMenuList(IN ULONG MaxNameLength,
|
||||
OUT PXTBL_BOOTMENU_ITEM *MenuEntries,
|
||||
OUT PULONG EntriesCount,
|
||||
OUT PULONG DefaultId)
|
||||
{
|
||||
EFI_GUID VendorGuid = XT_BOOT_LOADER_PROTOCOL_GUID;
|
||||
PWCHAR DefaultMenuEntry, LastBooted, MenuEntryName, VisibleName;
|
||||
PLIST_ENTRY MenuEntrySectionList, MenuEntryList;
|
||||
PXTBL_CONFIG_SECTION MenuEntrySection;
|
||||
PXTBL_CONFIG_ENTRY MenuEntryOption;
|
||||
ULONG DefaultOS, NameLength,NumberOfEntries;
|
||||
PXTBL_BOOTMENU_ITEM OsList;
|
||||
EFI_STATUS Status;
|
||||
|
||||
/* Set default values */
|
||||
DefaultOS = 0;
|
||||
NumberOfEntries = 0;
|
||||
|
||||
/* Get default menu entry from configuration */
|
||||
Configuration::GetValue(L"DEFAULT", &DefaultMenuEntry);
|
||||
|
||||
/* Check if configuration allows to use last booted OS */
|
||||
if(Configuration::GetBooleanValue(L"KEEPLASTBOOT"))
|
||||
{
|
||||
/* Attempt to get last booted Operating System from NVRAM */
|
||||
Status = EfiUtils::GetEfiVariable(&VendorGuid, L"XtLdrLastBootOS", (PVOID*)&LastBooted);
|
||||
if(Status == STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Set default menu entry to last booted OS */
|
||||
DefaultMenuEntry = LastBooted;
|
||||
}
|
||||
}
|
||||
|
||||
/* Iterate through menu items to get a total number of entries */
|
||||
MenuEntrySectionList = BlpMenuList->Flink;
|
||||
while(MenuEntrySectionList != BlpMenuList)
|
||||
{
|
||||
/* Increase number of menu entries, and simply get next item */
|
||||
NumberOfEntries++;
|
||||
MenuEntrySectionList = MenuEntrySectionList->Flink;
|
||||
}
|
||||
|
||||
/* Allocate memory for the OS list depending on the item count */
|
||||
Status = Memory::AllocatePool(NumberOfEntries * sizeof(XTBL_BOOTMENU_ITEM), (PVOID*)&OsList);
|
||||
if(Status != STATUS_EFI_SUCCESS || !OsList)
|
||||
{
|
||||
/* Memory allocation failure */
|
||||
return STATUS_EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
/* Reset counter and iterate through all menu items once again */
|
||||
NumberOfEntries = 0;
|
||||
MenuEntrySectionList = BlpMenuList->Flink;
|
||||
while(MenuEntrySectionList != BlpMenuList)
|
||||
{
|
||||
/* NULLify menu entry name */
|
||||
MenuEntryName = NULLPTR;
|
||||
|
||||
/* Get menu section */
|
||||
MenuEntrySection = CONTAIN_RECORD(MenuEntrySectionList, XTBL_CONFIG_SECTION, Flink);
|
||||
|
||||
/* Check if this is the default menu entry */
|
||||
if((RTL::WideString::WideStringLength(MenuEntrySection->SectionName, 0) == RTL::WideString::WideStringLength(DefaultMenuEntry, 0)) &&
|
||||
(RTL::WideString::CompareWideStringInsensitive(MenuEntrySection->SectionName, DefaultMenuEntry, 0) == 0))
|
||||
{
|
||||
/* Set default OS ID */
|
||||
DefaultOS = NumberOfEntries;
|
||||
}
|
||||
|
||||
/* Iterate through all entry parameters */
|
||||
MenuEntryList = MenuEntrySection->Options.Flink;
|
||||
while(MenuEntryList != &MenuEntrySection->Options)
|
||||
{
|
||||
/* Get menu entry parameter */
|
||||
MenuEntryOption = CONTAIN_RECORD(MenuEntryList, XTBL_CONFIG_ENTRY, Flink);
|
||||
|
||||
/* Check if this is the menu entry display name */
|
||||
if(RTL::WideString::CompareWideStringInsensitive(MenuEntryOption->Name, L"SYSTEMNAME", 0) == 0)
|
||||
{
|
||||
/* Set menu entry display name */
|
||||
MenuEntryName = MenuEntryOption->Value;
|
||||
}
|
||||
|
||||
/* Get next parameter for this menu entry */
|
||||
MenuEntryList = MenuEntryList->Flink;
|
||||
}
|
||||
|
||||
/* Add OS to the boot menu list */
|
||||
OsList[NumberOfEntries].FullName = MenuEntryName;
|
||||
OsList[NumberOfEntries].ShortName = MenuEntrySection->SectionName;
|
||||
OsList[NumberOfEntries].Options = &MenuEntrySection->Options;
|
||||
|
||||
/* Check if the menu entry name fits the maximum length */
|
||||
NameLength = RTL::WideString::WideStringLength(MenuEntryName, 0);
|
||||
if(NameLength > MaxNameLength)
|
||||
{
|
||||
/* Menu entry name is too long, allocate memory for shorter name visible in the boot menu */
|
||||
Status = Memory::AllocatePool((MaxNameLength + 1) * sizeof(WCHAR), (PVOID*)&VisibleName);
|
||||
if(Status != STATUS_EFI_SUCCESS)
|
||||
{
|
||||
/* Memory allocation failure */
|
||||
return STATUS_EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
/* Copy shorter name and append "..." at the end */
|
||||
RTL::Memory::CopyMemory(VisibleName, MenuEntryName, (MaxNameLength - 3) * sizeof(WCHAR));
|
||||
RTL::Memory::CopyMemory(VisibleName + MaxNameLength - 3, L"...", 3 * sizeof(WCHAR));
|
||||
VisibleName[MaxNameLength] = L'\0';
|
||||
|
||||
/* Set visible menu entry name */
|
||||
OsList[NumberOfEntries].EntryName = VisibleName;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Menu entry name fits the maximum length, use it as is */
|
||||
OsList[NumberOfEntries].EntryName = MenuEntryName;
|
||||
}
|
||||
|
||||
/* Get next menu entry */
|
||||
MenuEntrySectionList = MenuEntrySectionList->Flink;
|
||||
NumberOfEntries++;
|
||||
}
|
||||
|
||||
/* Set return values */
|
||||
*DefaultId = DefaultOS;
|
||||
*EntriesCount = NumberOfEntries;
|
||||
*MenuEntries = OsList;
|
||||
|
||||
/* Return success */
|
||||
return STATUS_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine is the entry point of the XT EFI boot loader.
|
||||
*
|
||||
|
Reference in New Issue
Block a user