3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
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.
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.
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.
20 /* INCLUDES *******************************************************************/
25 /* GLOBALS ********************************************************************/
29 (*OS_LOADING_METHOD
)(IN OperatingSystemItem
* OperatingSystem
,
30 IN USHORT OperatingSystemVersion
);
35 USHORT OperatingSystemVersion
;
36 OS_LOADING_METHOD Load
;
37 } OSLoadingMethods
[] =
39 {"ReactOSSetup", 0 , LoadReactOSSetup
},
42 {"BootSector" , 0 , LoadAndBootBootSector
},
43 {"Drive" , 0 , LoadAndBootDrive
},
44 {"Partition" , 0 , LoadAndBootPartition
},
46 {"Linux" , 0 , LoadAndBootLinux
},
48 {"Windows" , 0 , LoadAndBootWindows
},
49 {"WindowsNT40" , _WIN32_WINNT_NT4
, LoadAndBootWindows
},
51 {"Windows2003" , _WIN32_WINNT_WS03
, LoadAndBootWindows
},
54 /* FUNCTIONS ******************************************************************/
56 VOID
LoadOperatingSystem(IN OperatingSystemItem
* OperatingSystem
)
59 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
63 /* Try to open the operating system section in the .ini file */
64 if (IniOpenSection(SectionName
, &SectionId
))
66 /* Try to read the boot type */
67 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
71 BootType
[0] = ANSI_NULL
;
74 if (BootType
[0] == ANSI_NULL
&& SectionName
[0] != ANSI_NULL
)
76 /* Try to infer the boot type value */
79 if (ArcOpen((PSTR
)SectionName
, OpenReadOnly
, &FileId
) == ESUCCESS
)
82 strcpy(BootType
, "BootSector");
87 strcpy(BootType
, "Windows");
91 /* Install the drive mapper according to this section drive mappings */
92 #if defined(_M_IX86) && !defined(_MSC_VER)
93 DriveMapMapDrivesInSection(SectionName
);
96 /* Loop through the OS loading method table and find a suitable OS to boot */
97 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
99 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
101 OSLoadingMethods
[i
].Load(OperatingSystem
,
102 OSLoadingMethods
[i
].OperatingSystemVersion
);
108 ULONG
GetDefaultOperatingSystem(OperatingSystemItem
* OperatingSystemList
, ULONG OperatingSystemCount
)
110 CHAR DefaultOSText
[80];
116 if (!IniOpenSection("FreeLoader", &SectionId
))
119 DefaultOSName
= CmdLineGetDefaultOS();
120 if (DefaultOSName
== NULL
)
122 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
124 DefaultOSName
= DefaultOSText
;
128 if (DefaultOSName
!= NULL
)
130 for (Idx
= 0; Idx
< OperatingSystemCount
; Idx
++)
132 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
].SystemPartition
) == 0)
143 LONG
GetTimeOut(VOID
)
145 CHAR TimeOutText
[20];
149 TimeOut
= CmdLineGetTimeOut();
153 if (!IniOpenSection("FreeLoader", &SectionId
))
156 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
157 TimeOut
= atoi(TimeOutText
);
164 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
166 if (KeyPress
== KEY_F8
)
172 /* We didn't handle the key */
179 ULONG OperatingSystemCount
;
180 OperatingSystemItem
* OperatingSystemList
;
181 PCSTR
* OperatingSystemDisplayNames
;
182 ULONG DefaultOperatingSystem
;
184 ULONG SelectedOperatingSystem
;
187 if (!MachInitializeBootDevices())
189 UiMessageBoxCritical("Error when detecting hardware.");
194 /* Load additional SCSI driver (if any) */
195 if (LoadBootDeviceDriver() != ESUCCESS
)
197 UiMessageBoxCritical("Unable to load additional boot device drivers.");
201 if (!IniFileInitialize())
203 UiMessageBoxCritical("Error initializing .ini file.");
207 /* Debugger main initialization */
210 if (!IniOpenSection("FreeLoader", &SectionId
))
212 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
216 TimeOut
= GetTimeOut();
218 /* UI main initialization */
219 if (!UiInitialize(TRUE
))
221 UiMessageBoxCritical("Unable to initialize UI.");
225 OperatingSystemList
= InitOperatingSystemList(&OperatingSystemCount
);
226 if (!OperatingSystemList
)
228 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
232 if (OperatingSystemCount
== 0)
234 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
238 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemList
, OperatingSystemCount
);
240 /* Create list of display names */
241 OperatingSystemDisplayNames
= FrLdrTempAlloc(sizeof(PCSTR
) * OperatingSystemCount
, 'mNSO');
242 if (!OperatingSystemDisplayNames
)
245 for (i
= 0; i
< OperatingSystemCount
; i
++)
247 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
250 /* Find all the message box settings and run them */
251 UiShowMessageBoxesInSection("FreeLoader");
255 /* Redraw the backdrop */
258 /* Show the operating system list menu */
259 if (!UiDisplayMenu("Please select the operating system to start:",
260 "For troubleshooting and advanced startup options for "
261 "ReactOS, press F8.",
263 OperatingSystemDisplayNames
,
264 OperatingSystemCount
,
265 DefaultOperatingSystem
,
267 &SelectedOperatingSystem
,
269 MainBootMenuKeyPressFilter
))
271 UiMessageBox("Press ENTER to reboot.");
277 /* Load the chosen operating system */
278 LoadOperatingSystem(&OperatingSystemList
[SelectedOperatingSystem
]);
282 UiUnInitialize("Rebooting...");