2001-05-15 03:50:25 +00:00
|
|
|
/*
|
|
|
|
* FreeLoader
|
2003-01-19 01:04:01 +00:00
|
|
|
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
|
2001-05-15 03:50:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-05-15 03:50:25 +00:00
|
|
|
*/
|
2005-05-08 02:15:21 +00:00
|
|
|
|
2015-02-01 20:22:13 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
2002-06-06 05:58:37 +00:00
|
|
|
#include <freeldr.h>
|
2001-05-15 03:50:25 +00:00
|
|
|
|
[FREELDR] Code fixes and enhancements.
CORE-9023
FIXES:
======
- Fix parsing of the multiboot options string.
NOTE: They are not yet treated in a case-insensitive manner!
- Fix a bug in ArcOpen() so that it correctly skips the first path
separator (after the adapter-controller-peripheral ARC descriptors).
The path separator can be either a backslash or a slash (both are
allowed according to the specs); they were also already handled
correctly in other parts of the code.
- Fix DissectArcPath() so as to:
* **OPTIONALLY** (and not mandatorily!) return the path part that follows
the ARC adapter-controller-peripheral elements in the ARC path;
* make it correctly handle the (yes, optional!!) partition() part in the
ARC path, for the multi(x)disk(y)rdisk(z) cases.
ENHANCEMENTS:
=============
- Directly retrieve the default OS entry as we enumerate them and
build their list (i.e. merge the GetDefaultOperatingSystem() helper
within InitOperatingSystemList()).
- Directly use the opened 'FreeLoader' INI section via its ID in the
different functions that need it.
- Make the custom-boot and linux loaders honour the boot options they are
supposed to support (see FREELDR.INI documentation / template).
This includes the 'BootDrive' and 'BootPartition' (alternatively the ARC
'BootPath').
This also allows them to take into account the user-specified choices in the
FreeLdr custom-boot editors.
- Modify the FreeLdr custom-boot editors so as to correctly honour
the priorities of the boot options as specified in the FREELDR.INI
documentation / template.
- Use stack trick (union of structs) to reduce stack usage in the
FreeLdr custom-boot editors, because there are strings buffers that are
used in an alternate manner.
- Extract out from the editors the LoadOperatingSystem() calls, and
move it back into OptionMenuCustomBoot(), so that when this latter
function is called there is no risk of having a stack almost full.
- When building the ARC-compatible argument vector for the loaders, add
the mandatory "SystemPartition" path. This allows the loaders to NOT
call the machine-specific MachDiskGetBootPath() later on (this data is
indeed passed to them by the boot manager part of FreeLdr).
- Improve the FsOpenFile() helper so as to make it:
* return an adequate ARC_STATUS instead of a mere uninformative BOOLEAN;
* take open options, as well as a default path (optional) that would be
prepended to the file name in case the latter is a relative one.
- Make RamDiskLoadVirtualFile() return an actual descriptive ARC_STATUS
value, and make it take an optional default path (same usage as the one
in FsOpenFile() ).
+ Remove useless NTAPI .
- UiInitialize() and TuiTextToColor(), TuiTextToFillStyle(): load or
convert named settings into corresponding values using setting table and
a tight for-loop, instead of duplicating 10x the same parameter reading
logic.
- UiInitialize(): Open the "Display" INI section just once. Remove usage
of DisplayModeText[] buffer.
- UiShowMessageBoxesInSection() and UiShowMessageBoxesInArgv(): reduce
code indentation level.
ENHANCEMENTS for NT OS loader:
==============================
- Don't use MachDiskGetBootPath() but use instead the "SystemPartition"
value passed via the ARC argument vector by the boot manager
(+ validation checks). Use it as the "default path" when calling
FsOpenFile() or loading the ramdisk.
- Honour the FreeLdr-specific "Hal=" and "Kernel=" options by converting
them into NT standard "/HAL=" and "/KERNEL=" options in the boot
command line.
Note that if the latter ones are already present on the standard "Options="
option line, they would take precedence over those passed via the separate
"Hal=" and "Kernel=" FreeLdr-specific options.
Also add some documentation links to Geoff Chappell's website about
how the default HAL and KERNEL names are chosen depending on the
detected underlying platform on which the NT OS loader is running.
2019-08-30 22:49:37 +00:00
|
|
|
#include <debug.h>
|
2011-09-03 10:56:36 +00:00
|
|
|
DBG_DEFAULT_CHANNEL(WARNING);
|
|
|
|
|
2019-09-13 00:14:22 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
2019-09-17 20:24:47 +00:00
|
|
|
#define TOSTRING_(X) #X
|
|
|
|
#define TOSTRING(X) TOSTRING_(X)
|
|
|
|
|
|
|
|
const PCSTR FrLdrVersionString =
|
|
|
|
#if (FREELOADER_PATCH_VERSION == 0)
|
|
|
|
"FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION);
|
|
|
|
#else
|
|
|
|
"FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION) "." TOSTRING(FREELOADER_PATCH_VERSION);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CCHAR FrLdrBootPath[MAX_PATH] = "";
|
2019-09-13 00:14:22 +00:00
|
|
|
|
2015-02-01 20:22:13 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2010-03-08 22:04:38 +00:00
|
|
|
|
2015-12-20 02:06:40 +00:00
|
|
|
VOID __cdecl BootMain(IN PCCH CmdLine)
|
2001-05-15 03:50:25 +00:00
|
|
|
{
|
2013-05-24 12:20:13 +00:00
|
|
|
CmdLineParse(CmdLine);
|
2009-04-20 20:04:23 +00:00
|
|
|
|
2015-12-20 02:06:40 +00:00
|
|
|
/* Debugger pre-initialization */
|
[FREELDR] Code fixes and enhancements.
CORE-9023
FIXES:
======
- Fix parsing of the multiboot options string.
NOTE: They are not yet treated in a case-insensitive manner!
- Fix a bug in ArcOpen() so that it correctly skips the first path
separator (after the adapter-controller-peripheral ARC descriptors).
The path separator can be either a backslash or a slash (both are
allowed according to the specs); they were also already handled
correctly in other parts of the code.
- Fix DissectArcPath() so as to:
* **OPTIONALLY** (and not mandatorily!) return the path part that follows
the ARC adapter-controller-peripheral elements in the ARC path;
* make it correctly handle the (yes, optional!!) partition() part in the
ARC path, for the multi(x)disk(y)rdisk(z) cases.
ENHANCEMENTS:
=============
- Directly retrieve the default OS entry as we enumerate them and
build their list (i.e. merge the GetDefaultOperatingSystem() helper
within InitOperatingSystemList()).
- Directly use the opened 'FreeLoader' INI section via its ID in the
different functions that need it.
- Make the custom-boot and linux loaders honour the boot options they are
supposed to support (see FREELDR.INI documentation / template).
This includes the 'BootDrive' and 'BootPartition' (alternatively the ARC
'BootPath').
This also allows them to take into account the user-specified choices in the
FreeLdr custom-boot editors.
- Modify the FreeLdr custom-boot editors so as to correctly honour
the priorities of the boot options as specified in the FREELDR.INI
documentation / template.
- Use stack trick (union of structs) to reduce stack usage in the
FreeLdr custom-boot editors, because there are strings buffers that are
used in an alternate manner.
- Extract out from the editors the LoadOperatingSystem() calls, and
move it back into OptionMenuCustomBoot(), so that when this latter
function is called there is no risk of having a stack almost full.
- When building the ARC-compatible argument vector for the loaders, add
the mandatory "SystemPartition" path. This allows the loaders to NOT
call the machine-specific MachDiskGetBootPath() later on (this data is
indeed passed to them by the boot manager part of FreeLdr).
- Improve the FsOpenFile() helper so as to make it:
* return an adequate ARC_STATUS instead of a mere uninformative BOOLEAN;
* take open options, as well as a default path (optional) that would be
prepended to the file name in case the latter is a relative one.
- Make RamDiskLoadVirtualFile() return an actual descriptive ARC_STATUS
value, and make it take an optional default path (same usage as the one
in FsOpenFile() ).
+ Remove useless NTAPI .
- UiInitialize() and TuiTextToColor(), TuiTextToFillStyle(): load or
convert named settings into corresponding values using setting table and
a tight for-loop, instead of duplicating 10x the same parameter reading
logic.
- UiInitialize(): Open the "Display" INI section just once. Remove usage
of DisplayModeText[] buffer.
- UiShowMessageBoxesInSection() and UiShowMessageBoxesInArgv(): reduce
code indentation level.
ENHANCEMENTS for NT OS loader:
==============================
- Don't use MachDiskGetBootPath() but use instead the "SystemPartition"
value passed via the ARC argument vector by the boot manager
(+ validation checks). Use it as the "default path" when calling
FsOpenFile() or loading the ramdisk.
- Honour the FreeLdr-specific "Hal=" and "Kernel=" options by converting
them into NT standard "/HAL=" and "/KERNEL=" options in the boot
command line.
Note that if the latter ones are already present on the standard "Options="
option line, they would take precedence over those passed via the separate
"Hal=" and "Kernel=" FreeLdr-specific options.
Also add some documentation links to Geoff Chappell's website about
how the default HAL and KERNEL names are chosen depending on the
detected underlying platform on which the NT OS loader is running.
2019-08-30 22:49:37 +00:00
|
|
|
DebugInit(0);
|
2001-08-07 06:19:43 +00:00
|
|
|
|
2016-02-05 23:47:35 +00:00
|
|
|
MachInit(CmdLine);
|
|
|
|
|
2019-11-13 16:03:19 +00:00
|
|
|
TRACE("BootMain() called.\n");
|
|
|
|
|
2023-03-19 19:13:16 +00:00
|
|
|
#ifndef UEFIBOOT
|
2014-11-08 19:11:47 +00:00
|
|
|
/* Check if the CPU is new enough */
|
2016-11-12 20:53:49 +00:00
|
|
|
FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!
|
2023-03-19 19:13:16 +00:00
|
|
|
#endif
|
2014-11-08 19:05:22 +00:00
|
|
|
|
2015-12-20 02:06:40 +00:00
|
|
|
/* UI pre-initialization */
|
2013-05-24 12:20:13 +00:00
|
|
|
if (!UiInitialize(FALSE))
|
|
|
|
{
|
2015-02-05 21:24:26 +00:00
|
|
|
UiMessageBoxCritical("Unable to initialize UI.");
|
2015-02-01 20:22:13 +00:00
|
|
|
goto Quit;
|
2013-05-24 12:20:13 +00:00
|
|
|
}
|
2001-07-06 22:05:05 +00:00
|
|
|
|
2016-02-05 23:47:35 +00:00
|
|
|
/* Initialize memory manager */
|
2013-05-24 12:20:13 +00:00
|
|
|
if (!MmInitializeMemoryManager())
|
|
|
|
{
|
2015-02-05 21:24:26 +00:00
|
|
|
UiMessageBoxCritical("Unable to initialize memory manager.");
|
2015-02-01 20:22:13 +00:00
|
|
|
goto Quit;
|
2013-05-24 12:20:13 +00:00
|
|
|
}
|
2007-10-29 11:00:31 +00:00
|
|
|
|
2016-02-05 23:47:35 +00:00
|
|
|
/* Initialize I/O subsystem */
|
|
|
|
FsInit();
|
|
|
|
|
2015-01-04 16:42:37 +00:00
|
|
|
RunLoader();
|
2012-12-17 00:22:11 +00:00
|
|
|
|
2015-02-01 20:22:13 +00:00
|
|
|
Quit:
|
2013-05-24 12:20:13 +00:00
|
|
|
/* If we reach this point, something went wrong before, therefore reboot */
|
|
|
|
Reboot();
|
2001-05-15 03:50:25 +00:00
|
|
|
}
|
2011-02-10 20:26:41 +00:00
|
|
|
|
|
|
|
// We need to emulate these, because the original ones don't work in freeldr
|
2012-08-30 10:12:55 +00:00
|
|
|
// These functions are here, because they need to be in the main compilation unit
|
|
|
|
// and cannot be in a library.
|
2011-02-10 20:26:41 +00:00
|
|
|
int __cdecl wctomb(char *mbchar, wchar_t wchar)
|
|
|
|
{
|
2011-07-03 23:01:39 +00:00
|
|
|
*mbchar = (char)wchar;
|
2011-02-10 20:26:41 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-02-01 20:22:13 +00:00
|
|
|
int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
|
2011-02-10 20:26:41 +00:00
|
|
|
{
|
2011-07-03 23:01:39 +00:00
|
|
|
*wchar = (wchar_t)*mbchar;
|
2011-02-10 20:26:41 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2012-08-30 10:12:55 +00:00
|
|
|
|
|
|
|
// The wctype table is 144 KB, too much for poor freeldr
|
2015-09-15 10:35:49 +00:00
|
|
|
int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
|
2012-08-30 10:12:55 +00:00
|
|
|
{
|
|
|
|
return _isctype((char)wc, wctypeFlags);
|
|
|
|
}
|
2022-07-10 13:46:04 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4164)
|
|
|
|
#pragma function(pow)
|
|
|
|
#pragma function(log)
|
|
|
|
#pragma function(log10)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Stubs to avoid pulling in data from CRT
|
|
|
|
double pow(double x, double y)
|
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double log(double x)
|
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double log10(double x)
|
|
|
|
{
|
|
|
|
__debugbreak();
|
|
|
|
return 0.0;
|
|
|
|
}
|