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 #define TOSTRING_(X) #X 30 #define TOSTRING(X) TOSTRING_(X) 31 32 const PCSTR FrLdrVersionString = 33 #if (FREELOADER_PATCH_VERSION == 0) 34 "FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION); 35 #else 36 "FreeLoader v" TOSTRING(FREELOADER_MAJOR_VERSION) "." TOSTRING(FREELOADER_MINOR_VERSION) "." TOSTRING(FREELOADER_PATCH_VERSION); 37 #endif 38 39 CCHAR FrLdrBootPath[MAX_PATH] = ""; 40 41 /* FUNCTIONS ******************************************************************/ 42 43 VOID __cdecl BootMain(IN PCCH CmdLine) 44 { 45 /* Load the default settings from the command-line */ 46 LoadSettings(CmdLine); 47 48 /* Debugger pre-initialization */ 49 DebugInit(BootMgrInfo.DebugString); 50 51 MachInit(CmdLine); 52 53 TRACE("BootMain() called.\n"); 54 55 #ifndef UEFIBOOT 56 /* Check if the CPU is new enough */ 57 FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit! 58 #endif 59 60 /* UI pre-initialization */ 61 if (!UiInitialize(FALSE)) 62 { 63 UiMessageBoxCritical("Unable to initialize UI."); 64 goto Quit; 65 } 66 67 /* Initialize memory manager */ 68 if (!MmInitializeMemoryManager()) 69 { 70 UiMessageBoxCritical("Unable to initialize memory manager."); 71 goto Quit; 72 } 73 74 /* Initialize I/O subsystem */ 75 FsInit(); 76 77 RunLoader(); 78 79 Quit: 80 /* If we reach this point, something went wrong before, therefore reboot */ 81 Reboot(); 82 } 83 84 // We need to emulate these, because the original ones don't work in freeldr 85 // These functions are here, because they need to be in the main compilation unit 86 // and cannot be in a library. 87 int __cdecl wctomb(char *mbchar, wchar_t wchar) 88 { 89 *mbchar = (char)wchar; 90 return 1; 91 } 92 93 int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count) 94 { 95 *wchar = (wchar_t)*mbchar; 96 return 1; 97 } 98 99 // The wctype table is 144 KB, too much for poor freeldr 100 int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags) 101 { 102 return _isctype((char)wc, wctypeFlags); 103 } 104 105 #ifdef _MSC_VER 106 #pragma warning(disable:4164) 107 #pragma function(pow) 108 #pragma function(log) 109 #pragma function(log10) 110 #endif 111 112 // Stubs to avoid pulling in data from CRT 113 double pow(double x, double y) 114 { 115 __debugbreak(); 116 return 0.0; 117 } 118 119 double log(double x) 120 { 121 __debugbreak(); 122 return 0.0; 123 } 124 125 double log10(double x) 126 { 127 __debugbreak(); 128 return 0.0; 129 } 130