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 *******************************************************************/
24 /* GLOBALS ********************************************************************/
26 // ARC Disk Information
27 ARC_DISK_SIGNATURE reactos_arc_disk_info
[32];
28 ULONG reactos_disk_count
= 0;
29 CHAR reactos_arc_strings
[32][256];
33 (*OS_LOADING_METHOD
)(IN OperatingSystemItem
* OperatingSystem
,
34 IN USHORT OperatingSystemVersion
);
39 USHORT OperatingSystemVersion
;
40 OS_LOADING_METHOD Load
;
41 } OSLoadingMethods
[] =
43 {"ReactOSSetup", 0 , LoadReactOSSetup
},
46 {"BootSector" , 0 , LoadAndBootBootSector
},
47 {"Drive" , 0 , LoadAndBootDrive
},
48 {"Partition" , 0 , LoadAndBootPartition
},
50 {"Linux" , 0 , LoadAndBootLinux
},
52 {"Windows" , 0 , LoadAndBootWindows
},
53 {"WindowsNT40" , _WIN32_WINNT_NT4
, LoadAndBootWindows
},
55 {"Windows2003" , _WIN32_WINNT_WS03
, LoadAndBootWindows
},
58 /* FUNCTIONS ******************************************************************/
60 VOID
LoadOperatingSystem(IN OperatingSystemItem
* OperatingSystem
)
63 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
67 /* Try to open the operating system section in the .ini file */
68 if (IniOpenSection(SectionName
, &SectionId
))
70 /* Try to read the boot type */
71 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
75 BootType
[0] = ANSI_NULL
;
78 if (BootType
[0] == ANSI_NULL
&& SectionName
[0] != ANSI_NULL
)
80 /* Try to infere the boot type value */
83 if (ArcOpen((PSTR
)SectionName
, OpenReadOnly
, &FileId
) == ESUCCESS
)
86 strcpy(BootType
, "BootSector");
91 strcpy(BootType
, "Windows");
95 /* Install the drive mapper according to this section drive mappings */
96 #if defined(_M_IX86) && !defined(_MSC_VER)
97 DriveMapMapDrivesInSection(SectionName
);
100 /* Loop through the OS loading method table and find a suitable OS to boot */
101 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
103 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
105 OSLoadingMethods
[i
].Load(OperatingSystem
,
106 OSLoadingMethods
[i
].OperatingSystemVersion
);
112 ULONG
GetDefaultOperatingSystem(OperatingSystemItem
* OperatingSystemList
, ULONG OperatingSystemCount
)
114 CHAR DefaultOSText
[80];
120 if (!IniOpenSection("FreeLoader", &SectionId
))
123 DefaultOSName
= CmdLineGetDefaultOS();
124 if (DefaultOSName
== NULL
)
126 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
128 DefaultOSName
= DefaultOSText
;
132 if (DefaultOSName
!= NULL
)
134 for (Idx
= 0; Idx
<OperatingSystemCount
; Idx
++)
136 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
].SystemPartition
) == 0)
147 LONG
GetTimeOut(VOID
)
149 CHAR TimeOutText
[20];
153 TimeOut
= CmdLineGetTimeOut();
157 if (!IniOpenSection("FreeLoader", &SectionId
))
160 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
161 TimeOut
= atoi(TimeOutText
);
168 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
170 if (KeyPress
== KEY_F8
)
176 /* We didn't handle the key */
183 ULONG OperatingSystemCount
;
184 OperatingSystemItem
* OperatingSystemList
;
185 PCSTR
* OperatingSystemDisplayNames
;
186 ULONG DefaultOperatingSystem
;
188 ULONG SelectedOperatingSystem
;
191 if (!MachInitializeBootDevices())
193 UiMessageBoxCritical("Error when detecting hardware.");
198 /* Load additional SCSI driver (if any) */
199 if (LoadBootDeviceDriver() != ESUCCESS
)
201 UiMessageBoxCritical("Unable to load additional boot device drivers.");
205 if (!IniFileInitialize())
207 UiMessageBoxCritical("Error initializing .ini file.");
211 if (!IniOpenSection("FreeLoader", &SectionId
))
213 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
217 TimeOut
= GetTimeOut();
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...");