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.
22 ARC_DISK_SIGNATURE reactos_arc_disk_info
[32]; // ARC Disk Information
23 ULONG reactos_disk_count
= 0;
24 CHAR reactos_arc_strings
[32][256];
28 (*OS_LOADING_METHOD
)(IN OperatingSystemItem
* OperatingSystem
,
29 IN USHORT OperatingSystemVersion
);
34 USHORT OperatingSystemVersion
;
35 OS_LOADING_METHOD Load
;
36 } OSLoadingMethods
[] =
38 #ifdef FREELDR_REACTOS_SETUP
39 {"ReactOSSetup", 0 , LoadReactOSSetup
},
43 {"BootSector" , 0 , LoadAndBootBootSector
},
44 {"Drive" , 0 , LoadAndBootDrive
},
45 {"Partition" , 0 , LoadAndBootPartition
},
47 {"Linux" , 0 , LoadAndBootLinux
},
49 {"Windows" , 0 , LoadAndBootWindows
},
50 {"WindowsNT40" , _WIN32_WINNT_NT4
, LoadAndBootWindows
},
52 {"Windows2003" , _WIN32_WINNT_WS03
, LoadAndBootWindows
},
54 // {"Not found" , 0 , NULL }
57 VOID
LoadOperatingSystem(IN OperatingSystemItem
* OperatingSystem
)
60 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
64 // Try to open the operating system section in the .ini file
65 if (IniOpenSection(SectionName
, &SectionId
))
67 // Try to read the boot type
68 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
72 BootType
[0] = ANSI_NULL
;
75 if (BootType
[0] == ANSI_NULL
&& SectionName
[0] != ANSI_NULL
)
77 // Try to infere the boot type value
80 if (ArcOpen((PSTR
)SectionName
, OpenReadOnly
, &FileId
) == ESUCCESS
)
83 strcpy(BootType
, "BootSector");
88 strcpy(BootType
, "Windows");
92 // Install the drive mapper according to this section drive mappings
93 #if defined(_M_IX86) && !defined(_MSC_VER)
94 DriveMapMapDrivesInSection(SectionName
);
97 // Loop through the OS loading method table and find a suitable OS to boot
98 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
100 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
102 OSLoadingMethods
[i
].Load(OperatingSystem
,
103 OSLoadingMethods
[i
].OperatingSystemVersion
);
109 ULONG
GetDefaultOperatingSystem(OperatingSystemItem
* OperatingSystemList
, ULONG OperatingSystemCount
)
111 CHAR DefaultOSText
[80];
117 if (!IniOpenSection("FreeLoader", &SectionId
))
122 DefaultOSName
= CmdLineGetDefaultOS();
123 if (NULL
== DefaultOSName
)
125 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
127 DefaultOSName
= DefaultOSText
;
131 if (NULL
!= DefaultOSName
)
133 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
135 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
].SystemPartition
) == 0)
146 LONG
GetTimeOut(VOID
)
148 CHAR TimeOutText
[20];
152 TimeOut
= CmdLineGetTimeOut();
158 if (!IniOpenSection("FreeLoader", &SectionId
))
163 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
165 TimeOut
= atoi(TimeOutText
);
175 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
177 if (KeyPress
== KEY_F8
)
184 // We didn't handle the key
191 ULONG OperatingSystemCount
;
192 OperatingSystemItem
* OperatingSystemList
;
193 PCSTR
* OperatingSystemDisplayNames
;
194 ULONG DefaultOperatingSystem
;
196 ULONG SelectedOperatingSystem
;
199 if (!MachInitializeBootDevices())
201 UiMessageBoxCritical("Error when detecting hardware");
206 // Load additional SCSI driver (if any)
207 if (LoadBootDeviceDriver() != ESUCCESS
)
209 UiMessageBoxCritical("Unable to load additional boot device driver");
213 if (!IniFileInitialize())
215 UiMessageBoxCritical("Error initializing .ini file");
219 if (!IniOpenSection("FreeLoader", &SectionId
))
221 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
224 TimeOut
= GetTimeOut();
226 if (!UiInitialize(TRUE
))
228 UiMessageBoxCritical("Unable to initialize UI.");
232 OperatingSystemList
= InitOperatingSystemList(&OperatingSystemCount
);
233 if (!OperatingSystemList
)
235 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
239 if (OperatingSystemCount
== 0)
241 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
245 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemList
, OperatingSystemCount
);
248 // Create list of display names
250 OperatingSystemDisplayNames
= FrLdrTempAlloc(sizeof(PCSTR
) * OperatingSystemCount
, 'mNSO');
251 if (!OperatingSystemDisplayNames
)
255 for (i
= 0; i
< OperatingSystemCount
; i
++)
257 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
261 // Find all the message box settings and run them
263 UiShowMessageBoxesInSection("FreeLoader");
267 // Redraw the backdrop
270 // Show the operating system list menu
271 if (!UiDisplayMenu("Please select the operating system to start:",
272 "For troubleshooting and advanced startup options for "
273 "ReactOS, press F8.",
275 OperatingSystemDisplayNames
,
276 OperatingSystemCount
,
277 DefaultOperatingSystem
,
279 &SelectedOperatingSystem
,
281 MainBootMenuKeyPressFilter
))
283 UiMessageBox("Press ENTER to reboot.");
289 // Load the chosen operating system
290 LoadOperatingSystem(&OperatingSystemList
[SelectedOperatingSystem
]);
294 UiUnInitialize("Rebooting...");