reactos/boot/freeldr/freeldr/freeldr.c
Justin Miller 150f721273
[FREELDR] Support compiling freeldr as a UEFI loader + Implement UI functions (#5171)
First batch of changes to implement a UEFI version of freeldr:
- Compile freeldr as EFI binary on top of the existing loader.
- Stub out various functions so we can create a UEFI machine-type in freeldr.
- Implement all of the video output functions so we can display a pretty freeldr BSoD :)
2023-03-19 20:13:16 +01:00

129 lines
3.2 KiB
C

/*
* FreeLoader
* Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
*
* 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.
*
* 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.
*/
/* INCLUDES *******************************************************************/
#include <freeldr.h>
#include <debug.h>
DBG_DEFAULT_CHANNEL(WARNING);
/* GLOBALS ********************************************************************/
#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] = "";
/* FUNCTIONS ******************************************************************/
VOID __cdecl BootMain(IN PCCH CmdLine)
{
CmdLineParse(CmdLine);
/* Debugger pre-initialization */
DebugInit(0);
MachInit(CmdLine);
TRACE("BootMain() called.\n");
#ifndef UEFIBOOT
/* Check if the CPU is new enough */
FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!
#endif
/* UI pre-initialization */
if (!UiInitialize(FALSE))
{
UiMessageBoxCritical("Unable to initialize UI.");
goto Quit;
}
/* Initialize memory manager */
if (!MmInitializeMemoryManager())
{
UiMessageBoxCritical("Unable to initialize memory manager.");
goto Quit;
}
/* Initialize I/O subsystem */
FsInit();
RunLoader();
Quit:
/* If we reach this point, something went wrong before, therefore reboot */
Reboot();
}
// We need to emulate these, because the original ones don't work in freeldr
// These functions are here, because they need to be in the main compilation unit
// and cannot be in a library.
int __cdecl wctomb(char *mbchar, wchar_t wchar)
{
*mbchar = (char)wchar;
return 1;
}
int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
{
*wchar = (wchar_t)*mbchar;
return 1;
}
// The wctype table is 144 KB, too much for poor freeldr
int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
{
return _isctype((char)wc, wctypeFlags);
}
#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;
}