mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
[FREELDR] Factor duplicated code into a GetOSLoadingMethod() helper
This removes duplicated code present in both LoadOperatingSystem() and EditOperatingSystemEntry(). + Add SAL annotations to the related functions.
This commit is contained in:
parent
458ca7766f
commit
9ae73010c2
2 changed files with 69 additions and 62 deletions
|
@ -26,31 +26,33 @@ DBG_DEFAULT_CHANNEL(WARNING);
|
||||||
|
|
||||||
/* GLOBALS ********************************************************************/
|
/* GLOBALS ********************************************************************/
|
||||||
|
|
||||||
typedef
|
typedef VOID
|
||||||
VOID
|
|
||||||
(*EDIT_OS_ENTRY_PROC)(
|
(*EDIT_OS_ENTRY_PROC)(
|
||||||
IN OUT OperatingSystemItem* OperatingSystem);
|
_Inout_ OperatingSystemItem* OperatingSystem);
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
EditCustomBootReactOSSetup(
|
EditCustomBootReactOSSetup(
|
||||||
IN OUT OperatingSystemItem* OperatingSystem)
|
_Inout_ OperatingSystemItem* OperatingSystem)
|
||||||
{
|
{
|
||||||
EditCustomBootReactOS(OperatingSystem, TRUE);
|
EditCustomBootReactOS(OperatingSystem, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
EditCustomBootNTOS(
|
EditCustomBootNTOS(
|
||||||
IN OUT OperatingSystemItem* OperatingSystem)
|
_Inout_ OperatingSystemItem* OperatingSystem)
|
||||||
{
|
{
|
||||||
EditCustomBootReactOS(OperatingSystem, FALSE);
|
EditCustomBootReactOS(OperatingSystem, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
typedef struct _OS_LOADING_METHOD
|
||||||
{
|
{
|
||||||
PCSTR BootType;
|
PCSTR BootType;
|
||||||
EDIT_OS_ENTRY_PROC EditOsEntry;
|
EDIT_OS_ENTRY_PROC EditOsEntry;
|
||||||
ARC_ENTRY_POINT OsLoader;
|
ARC_ENTRY_POINT OsLoader;
|
||||||
} OSLoadingMethods[] =
|
} OS_LOADING_METHOD, *POS_LOADING_METHOD;
|
||||||
|
|
||||||
|
static const OS_LOADING_METHOD
|
||||||
|
OSLoadingMethods[] =
|
||||||
{
|
{
|
||||||
{"ReactOSSetup", EditCustomBootReactOSSetup, LoadReactOSSetup},
|
{"ReactOSSetup", EditCustomBootReactOSSetup, LoadReactOSSetup},
|
||||||
|
|
||||||
|
@ -71,13 +73,40 @@ static const struct
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* FUNCTIONS ******************************************************************/
|
||||||
|
|
||||||
|
static const OS_LOADING_METHOD*
|
||||||
|
GetOSLoadingMethod(
|
||||||
|
_In_ ULONG_PTR SectionId)
|
||||||
|
{
|
||||||
|
ULONG i;
|
||||||
|
CHAR BootType[80];
|
||||||
|
|
||||||
|
/* The operating system section has been opened by InitOperatingSystemList() */
|
||||||
|
ASSERT(SectionId != 0);
|
||||||
|
|
||||||
|
/* Try to read the boot type. We must have the value (it
|
||||||
|
* has been possibly added by InitOperatingSystemList()) */
|
||||||
|
*BootType = ANSI_NULL;
|
||||||
|
IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
|
||||||
|
ASSERT(*BootType);
|
||||||
|
|
||||||
|
/* Find the suitable OS loading method */
|
||||||
|
for (i = 0; ; ++i)
|
||||||
|
{
|
||||||
|
if (i >= RTL_NUMBER_OF(OSLoadingMethods))
|
||||||
|
return NULL;
|
||||||
|
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
|
||||||
|
return &OSLoadingMethods[i];
|
||||||
|
}
|
||||||
|
UNREACHABLE;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function converts the list of key=value options in the given operating
|
* This function converts the list of key=value options in the given operating
|
||||||
* system section into an ARC-compatible argument vector, providing in addition
|
* system section into an ARC-compatible argument vector, providing in addition
|
||||||
* the extra mandatory Software Loading Environment Variables, following the
|
* the extra mandatory Software Loading Environment Variables, following the
|
||||||
* ARC specification.
|
* ARC specification.
|
||||||
*/
|
*/
|
||||||
PCHAR*
|
static PCHAR*
|
||||||
BuildArgvForOsLoader(
|
BuildArgvForOsLoader(
|
||||||
IN PCSTR LoadIdentifier,
|
IN PCSTR LoadIdentifier,
|
||||||
IN ULONG_PTR SectionId,
|
IN ULONG_PTR SectionId,
|
||||||
|
@ -177,23 +206,25 @@ BuildArgvForOsLoader(
|
||||||
return Argv;
|
return Argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
|
VOID
|
||||||
|
LoadOperatingSystem(
|
||||||
|
_In_ OperatingSystemItem* OperatingSystem)
|
||||||
{
|
{
|
||||||
ULONG_PTR SectionId = OperatingSystem->SectionId;
|
ULONG_PTR SectionId = OperatingSystem->SectionId;
|
||||||
ULONG i;
|
const OS_LOADING_METHOD* OSLoadingMethod;
|
||||||
ULONG Argc;
|
ULONG Argc;
|
||||||
PCHAR* Argv;
|
PCHAR* Argv;
|
||||||
CHAR BootType[80];
|
|
||||||
|
|
||||||
/* The operating system section has been opened by InitOperatingSystemList() */
|
/* Find the suitable OS loader to start */
|
||||||
ASSERT(SectionId != 0);
|
OSLoadingMethod = GetOSLoadingMethod(SectionId);
|
||||||
|
if (!OSLoadingMethod)
|
||||||
|
return;
|
||||||
|
ASSERT(OSLoadingMethod->OsLoader);
|
||||||
|
|
||||||
/* Try to read the boot type */
|
/* Build the ARC-compatible argument vector */
|
||||||
*BootType = ANSI_NULL;
|
Argv = BuildArgvForOsLoader(OperatingSystem->LoadIdentifier, SectionId, &Argc);
|
||||||
IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
|
if (!Argv)
|
||||||
|
return; // Unexpected failure.
|
||||||
/* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
|
|
||||||
ASSERT(*BootType);
|
|
||||||
|
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
#ifndef UEFIBOOT
|
#ifndef UEFIBOOT
|
||||||
|
@ -202,56 +233,25 @@ VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Find the suitable OS loader to start */
|
|
||||||
for (i = 0; ; ++i)
|
|
||||||
{
|
|
||||||
if (i >= RTL_NUMBER_OF(OSLoadingMethods))
|
|
||||||
return;
|
|
||||||
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Build the ARC-compatible argument vector */
|
|
||||||
Argv = BuildArgvForOsLoader(OperatingSystem->LoadIdentifier, SectionId, &Argc);
|
|
||||||
if (!Argv)
|
|
||||||
return; // Unexpected failure.
|
|
||||||
|
|
||||||
/* Start the OS loader */
|
/* Start the OS loader */
|
||||||
OSLoadingMethods[i].OsLoader(Argc, Argv, NULL);
|
OSLoadingMethod->OsLoader(Argc, Argv, NULL);
|
||||||
FrLdrHeapFree(Argv, TAG_STRING);
|
FrLdrHeapFree(Argv, TAG_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
|
#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
|
||||||
|
VOID
|
||||||
VOID EditOperatingSystemEntry(IN OperatingSystemItem* OperatingSystem)
|
EditOperatingSystemEntry(
|
||||||
|
_Inout_ OperatingSystemItem* OperatingSystem)
|
||||||
{
|
{
|
||||||
ULONG_PTR SectionId = OperatingSystem->SectionId;
|
/* Find the suitable OS entry editor and open it */
|
||||||
ULONG i;
|
const OS_LOADING_METHOD* OSLoadingMethod =
|
||||||
CHAR BootType[80];
|
GetOSLoadingMethod(OperatingSystem->SectionId);
|
||||||
|
if (OSLoadingMethod)
|
||||||
/* The operating system section has been opened by InitOperatingSystemList() */
|
|
||||||
ASSERT(SectionId != 0);
|
|
||||||
|
|
||||||
/* Try to read the boot type */
|
|
||||||
*BootType = ANSI_NULL;
|
|
||||||
IniReadSettingByName(SectionId, "BootType", BootType, sizeof(BootType));
|
|
||||||
|
|
||||||
/* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
|
|
||||||
ASSERT(*BootType);
|
|
||||||
|
|
||||||
/* Find the suitable OS entry editor */
|
|
||||||
for (i = 0; ; ++i)
|
|
||||||
{
|
{
|
||||||
if (i >= RTL_NUMBER_OF(OSLoadingMethods))
|
ASSERT(OSLoadingMethod->EditOsEntry);
|
||||||
return;
|
OSLoadingMethod->EditOsEntry(OperatingSystem);
|
||||||
if (_stricmp(BootType, OSLoadingMethods[i].BootType) == 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run it */
|
|
||||||
OSLoadingMethods[i].EditOsEntry(OperatingSystem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAS_OPTION_MENU_EDIT_CMDLINE
|
#endif // HAS_OPTION_MENU_EDIT_CMDLINE
|
||||||
|
|
||||||
static LONG
|
static LONG
|
||||||
|
|
|
@ -125,10 +125,17 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VOID __cdecl BootMain(IN PCCH CmdLine);
|
VOID __cdecl BootMain(IN PCCH CmdLine);
|
||||||
VOID LoadOperatingSystem(IN OperatingSystemItem* OperatingSystem);
|
|
||||||
|
VOID
|
||||||
|
LoadOperatingSystem(
|
||||||
|
_In_ OperatingSystemItem* OperatingSystem);
|
||||||
|
|
||||||
#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
|
#ifdef HAS_OPTION_MENU_EDIT_CMDLINE
|
||||||
VOID EditOperatingSystemEntry(IN OperatingSystemItem* OperatingSystem);
|
VOID
|
||||||
|
EditOperatingSystemEntry(
|
||||||
|
_Inout_ OperatingSystemItem* OperatingSystem);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VOID RunLoader(VOID);
|
VOID RunLoader(VOID);
|
||||||
VOID FrLdrCheckCpuCompatibility(VOID);
|
VOID FrLdrCheckCpuCompatibility(VOID);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue