ReactOS 0.4.16-dev-974-g5022a45
freeldr.c
Go to the documentation of this file.
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>
26
27/* GLOBALS ********************************************************************/
28
30
31/* FUNCTIONS ******************************************************************/
32
33static
36 _In_ PCSTR RosloadPath,
37 _Out_ PVOID* ImageBase,
38 _Out_ PLDR_DATA_TABLE_ENTRY* DataTableEntry)
39{
40 CHAR FullPath[MAX_PATH];
42
43 /* Create full rosload.exe path */
44 RtlStringCbPrintfA(FullPath,
45 sizeof(FullPath),
46 "%s\\%s",
48 RosloadPath);
49
50 TRACE("Loading second stage loader '%s'\n", FullPath);
51
52 /* Load rosload.exe as a bootloader image. The base name is "scsiport.sys",
53 because it exports ScsiPort* functions for ntbootdd.sys */
54 Success = PeLdrLoadBootImage(FullPath,
55 "scsiport.sys",
56 ImageBase,
57 DataTableEntry);
58 if (!Success)
59 {
60 WARN("Failed to load second stage loader '%s'\n", FullPath);
61 return FALSE;
62 }
63
64 return TRUE;
65}
66
67static
70{
71 PLDR_DATA_TABLE_ENTRY RosloadDTE;
72 PVOID ImageBase;
73 LONG (*EntryPoint)(VOID);
74
75 /* Load the second stage loader */
76 if (!LoadRosload("rosload.exe", &ImageBase, &RosloadDTE))
77 {
78 /* Try in loader directory */
79 if (!LoadRosload("loader\\rosload.exe", &ImageBase, &RosloadDTE))
80 {
81 return ENOENT;
82 }
83 }
84
85 /* Call the entrypoint */
86 printf("Launching rosload.exe...\n");
87 EntryPoint = VaToPa(RosloadDTE->EntryPoint);
88 return (*EntryPoint)();
89}
90
92{
93 /* Load the default settings from the command-line */
95
96 /* Debugger pre-initialization */
98
100
101 TRACE("BootMain() called.\n");
102
103#ifndef UEFIBOOT
104 /* Check if the CPU is new enough */
105 FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!
106#endif
107
108 /* UI pre-initialization */
109 if (!UiInitialize(FALSE))
110 {
111 UiMessageBoxCritical("Unable to initialize UI.");
112 goto Quit;
113 }
114
115 /* Initialize memory manager */
117 {
118 UiMessageBoxCritical("Unable to initialize memory manager.");
119 goto Quit;
120 }
121
122 /* Initialize I/O subsystem */
123 FsInit();
124
125 /* Initialize the module list */
127 {
128 UiMessageBoxCritical("Unable to initialize module list.");
129 goto Quit;
130 }
131
133 {
134 UiMessageBoxCritical("Error when detecting hardware.");
135 goto Quit;
136 }
137
138 /* Launch second stage loader */
140 {
141 UiMessageBoxCritical("Unable to load second stage loader.");
142 }
143
144Quit:
145 /* If we reach this point, something went wrong before, therefore reboot */
146 Reboot();
147}
148
149// We need to emulate these, because the original ones don't work in freeldr
150// These functions are here, because they need to be in the main compilation unit
151// and cannot be in a library.
152int __cdecl wctomb(char *mbchar, wchar_t wchar)
153{
154 *mbchar = (char)wchar;
155 return 1;
156}
157
158int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
159{
160 *wchar = (wchar_t)*mbchar;
161 return 1;
162}
163
164// The wctype table is 144 KB, too much for poor freeldr
165int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
166{
167 return _isctype((char)wc, wctypeFlags);
168}
169
170#ifdef _MSC_VER
171#pragma warning(disable:4164)
172#pragma function(pow)
173#pragma function(log)
174#pragma function(log10)
175#endif
176
177// Stubs to avoid pulling in data from CRT
178double pow(double x, double y)
179{
180 __debugbreak();
181 return 0.0;
182}
183
184double log(double x)
185{
186 __debugbreak();
187 return 0.0;
188}
189
190double log10(double x)
191{
192 __debugbreak();
193 return 0.0;
194}
195
197{
198 return FrLdrBootPath;
199}
200
202{
203 return FrldrBootDrive;
204}
205
207{
208 return FrldrBootPartition;
209}
#define WARNING
Definition: BusLogic958.h:56
unsigned char BOOLEAN
int wint_t
Definition: _apple.h:38
#define ENOENT
Definition: acclib.h:79
#define __cdecl
Definition: accygwin.h:79
#define VOID
Definition: acefi.h:82
void LoadSettings(void)
Definition: settings.c:53
#define WARN(fmt,...)
Definition: precomp.h:61
@ Reboot
Definition: bl.h:891
#define DebugInit(DebugString)
Definition: debug.h:120
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
VOID FsInit(VOID)
Definition: fs.c:646
#define MachInitializeBootDevices()
Definition: machine.h:127
BOOLEAN MmInitializeMemoryManager(VOID)
Definition: meminit.c:336
BOOTMGRINFO BootMgrInfo
Definition: settings.c:18
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
BOOLEAN UiInitialize(BOOLEAN ShowUi)
Definition: ui.c:92
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
static const WCHAR CmdLine[]
Definition: install.c:48
unsigned char
Definition: typeof.h:29
@ Success
Definition: eventcreate.c:712
ULONG FrldrGetBootPartition(VOID)
Definition: freeldr.c:206
VOID __cdecl BootMain(IN PCCH CmdLine)
Definition: freeldr.c:91
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:29
PCCHAR FrLdrGetBootPath(VOID)
Definition: freeldr.c:196
double log10(double x)
Definition: freeldr.c:190
UCHAR FrldrGetBootDrive(VOID)
Definition: freeldr.c:201
static ULONG LaunchSecondStageLoader(VOID)
Definition: freeldr.c:69
double pow(double x, double y)
Definition: freeldr.c:178
static BOOLEAN LoadRosload(_In_ PCSTR RosloadPath, _Out_ PVOID *ImageBase, _Out_ PLDR_DATA_TABLE_ENTRY *DataTableEntry)
Definition: freeldr.c:35
int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
Definition: freeldr.c:165
#define printf
Definition: freeldr.h:97
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
_Check_return_ _CRTIMP int __cdecl _isctype(_In_ int _C, _In_ int _Type)
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
VOID FrLdrCheckCpuCompatibility(VOID)
Definition: macharm.c:65
VOID MachInit(IN PCCH CommandLine)
Definition: macharm.c:182
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
CONST CHAR * PCCH
Definition: ntbasedef.h:400
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
long LONG
Definition: pedump.c:60
BOOLEAN PeLdrLoadBootImage(_In_ PCSTR FilePath, _In_ PCSTR BaseDllName, _Out_ PVOID *ImageBase, _Out_ PLDR_DATA_TABLE_ENTRY *DataTableEntry)
Definition: peloader.c:1052
BOOLEAN PeLdrInitializeModuleList(VOID)
Definition: peloader.c:525
@ ESUCCESS
Definition: arc.h:32
#define log(outFile, fmt,...)
Definition: util.h:15
#define TRACE(s)
Definition: solgame.cpp:4
PCSTR DebugString
Definition: settings.h:12
Definition: btrfs_drv.h:1876
PVOID EntryPoint
Definition: ntddk_ex.h:203
#define wctomb(cp, wc)
Definition: wchar.h:161
#define mbtowc(wp, cp, len)
Definition: wchar.h:155
#define wchar_t
Definition: wchar.h:102
const char * PCSTR
Definition: typedefs.h:52
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
char CCHAR
Definition: typedefs.h:51
unsigned short wctype_t
Definition: corecrt.h:617
UCHAR FrldrBootDrive
Definition: uefidisk.c:47
ULONG FrldrBootPartition
Definition: uefidisk.c:48
size_t const wchar_t const wchar
Definition: wcrtomb.cpp:53
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175