ReactOS 0.4.16-dev-2613-g9533ad7
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 (*EntryPoint)();
89 return ESUCCESS;
90}
91
93{
94 /* Load the default settings from the command-line */
96
97 /* Debugger pre-initialization */
99
101
102 TRACE("BootMain() called.\n");
103
104#ifndef UEFIBOOT
105 /* Check if the CPU is new enough */
106 FrLdrCheckCpuCompatibility(); // FIXME: Should be done inside MachInit!
107#endif
108
109 /* UI pre-initialization */
110 if (!UiInitialize(FALSE))
111 {
112 UiMessageBoxCritical("Unable to initialize UI.");
113 goto Quit;
114 }
115
116 /* Initialize memory manager */
118 {
119 UiMessageBoxCritical("Unable to initialize memory manager.");
120 goto Quit;
121 }
122
123 /* Initialize I/O subsystem */
124 FsInit();
125
126 /* Initialize the module list */
128 {
129 UiMessageBoxCritical("Unable to initialize module list.");
130 goto Quit;
131 }
132
134 {
135 UiMessageBoxCritical("Error when detecting hardware.");
136 goto Quit;
137 }
138
139 /* Launch second stage loader */
141 {
142 UiMessageBoxCritical("Unable to load second stage loader.");
143 }
144
145Quit:
146 /* If we reach this point, something went wrong before, therefore reboot */
147 Reboot();
148}
149
150// We need to emulate these, because the original ones don't work in freeldr
151// These functions are here, because they need to be in the main compilation unit
152// and cannot be in a library.
153int __cdecl wctomb(char *mbchar, wchar_t wchar)
154{
155 *mbchar = (char)wchar;
156 return 1;
157}
158
159int __cdecl mbtowc(wchar_t *wchar, const char *mbchar, size_t count)
160{
161 *wchar = (wchar_t)*mbchar;
162 return 1;
163}
164
165// The wctype table is 144 KB, too much for poor freeldr
166int __cdecl iswctype(wint_t wc, wctype_t wctypeFlags)
167{
168 return _isctype((char)wc, wctypeFlags);
169}
170
171#ifdef _MSC_VER
172#pragma warning(disable:4164)
173#pragma function(pow)
174#pragma function(log)
175#pragma function(log10)
176#endif
177
178// Stubs to avoid pulling in data from CRT
179double pow(double x, double y)
180{
181 __debugbreak();
182 return 0.0;
183}
184
185double log(double x)
186{
187 __debugbreak();
188 return 0.0;
189}
190
191double log10(double x)
192{
193 __debugbreak();
194 return 0.0;
195}
196
198{
199 return FrLdrBootPath;
200}
201
203{
204 return FrldrBootDrive;
205}
206
208{
209 return FrldrBootPartition;
210}
#define WARNING
Definition: BusLogic958.h:56
#define VOID
Definition: acefi.h:82
unsigned char BOOLEAN
Definition: actypes.h:127
void LoadSettings(void)
Definition: settings.c:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define DebugInit(DebugString)
Definition: debug.h:120
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
VOID FsInit(VOID)
Definition: fs.c:725
#define MachInitializeBootDevices()
Definition: machine.h:127
BOOLEAN MmInitializeMemoryManager(VOID)
Definition: meminit.c:336
BOOTMGRINFO BootMgrInfo
Definition: settings.c:19
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
int CDECL _isctype(int c, int type)
Definition: ctype.c:198
#define __cdecl
Definition: corecrt.h:121
unsigned short wint_t
Definition: corecrt.h:243
unsigned short wctype_t
Definition: corecrt.h:244
#define ENOENT
Definition: errno.h:25
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:207
VOID __cdecl BootMain(IN PCCH CmdLine)
Definition: freeldr.c:92
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:29
PCCHAR FrLdrGetBootPath(VOID)
Definition: freeldr.c:197
double log10(double x)
Definition: freeldr.c:191
UCHAR FrldrGetBootDrive(VOID)
Definition: freeldr.c:202
static ULONG LaunchSecondStageLoader(VOID)
Definition: freeldr.c:69
double pow(double x, double y)
Definition: freeldr.c:179
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:166
#define printf
Definition: freeldr.h:103
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
VOID FrLdrCheckCpuCompatibility(VOID)
Definition: macharm.c:65
VOID MachInit(IN PCCH CommandLine)
Definition: macharm.c:182
#define wctomb
Definition: wctomb.c:31
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
CONST CHAR * PCCH
Definition: ntbasedef.h:404
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
char CHAR
Definition: pedump.c:57
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
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
#define log(outFile, fmt,...)
Definition: util.h:15
#define mbtowc(wp, cp, len)
Definition: wchar.h:155
#define wchar_t
Definition: wchar.h:102
#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
unsigned char UCHAR
Definition: typedefs.h:53
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
UCHAR FrldrBootDrive
Definition: uefidisk.c:57
ULONG FrldrBootPartition
Definition: uefidisk.c:58
DECLSPEC_NORETURN VOID __cdecl Reboot(VOID)
Definition: uefildr.c:99
size_t const wchar_t const wchar
Definition: wcrtomb.cpp:53