xref: /reactos/boot/freeldr/freeldr/freeldr.c (revision 0d8e2658)
1 /*
2  *  FreeLoader
3  *  Copyright (C) 1998-2003  Brian Palmer  <brianp@sginet.com>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /* INCLUDES *******************************************************************/
21 
22 #include <freeldr.h>
23 
24 #include <debug.h>
25 DBG_DEFAULT_CHANNEL(WARNING);
26 
27 /* GLOBALS ********************************************************************/
28 
29 CCHAR FrLdrBootPath[MAX_PATH] = "";
30 
31 /* FUNCTIONS ******************************************************************/
32 
33 VOID __cdecl BootMain(IN PCCH CmdLine)
34 {
35     /* Load the default settings from the command-line */
36     LoadSettings(CmdLine);
37 
38     /* Debugger pre-initialization */
39     DebugInit(BootMgrInfo.DebugString);
40 
41     MachInit(CmdLine);
42 
43     TRACE("BootMain() called.\n");
44 
45 #ifndef UEFIBOOT
46     /* Check if the CPU is new enough */
47     FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!
48 #endif
49 
50     /* UI pre-initialization */
51     if (!UiInitialize(FALSE))
52     {
53         UiMessageBoxCritical("Unable to initialize UI.");
54         goto Quit;
55     }
56 
57     /* Initialize memory manager */
58     if (!MmInitializeMemoryManager())
59     {
60         UiMessageBoxCritical("Unable to initialize memory manager.");
61         goto Quit;
62     }
63 
64     /* Initialize I/O subsystem */
65     FsInit();
66 
67     RunLoader();
68 
69 Quit:
70     /* If we reach this point, something went wrong before, therefore reboot */
71     Reboot();
72 }
73 
74 // We need to emulate these, because the original ones don't work in freeldr
75 // These functions are here, because they need to be in the main compilation unit
76 // and cannot be in a library.
77 int __cdecl wctomb(char *mbchar, wchar_t wchar)
78 {
79     *mbchar = (char)wchar;
80     return 1;
81 }
82 
83 int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
84 {
85     *wchar = (wchar_t)*mbchar;
86     return 1;
87 }
88 
89 // The wctype table is 144 KB, too much for poor freeldr
90 int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
91 {
92     return _isctype((char)wc, wctypeFlags);
93 }
94 
95 #ifdef _MSC_VER
96 #pragma warning(disable:4164)
97 #pragma function(pow)
98 #pragma function(log)
99 #pragma function(log10)
100 #endif
101 
102 // Stubs to avoid pulling in data from CRT
103 double pow(double x, double y)
104 {
105     __debugbreak();
106     return 0.0;
107 }
108 
109 double log(double x)
110 {
111     __debugbreak();
112     return 0.0;
113 }
114 
115 double log10(double x)
116 {
117     __debugbreak();
118     return 0.0;
119 }
120