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_hardware_data
[HW_MAX_ARC_HEAP_SIZE
] = {0};
25 CHAR reactos_arc_strings
[32][256];
29 (*OS_LOADING_METHOD
)(IN OperatingSystemItem
* OperatingSystem
,
30 IN USHORT OperatingSystemVersion
);
35 USHORT OperatingSystemVersion
;
36 OS_LOADING_METHOD Load
;
37 } OSLoadingMethods
[] =
39 #ifdef FREELDR_REACTOS_SETUP
40 {"ReactOSSetup", 0 , LoadReactOSSetup
},
44 {"BootSector" , 0 , LoadAndBootBootSector
},
45 {"Drive" , 0 , LoadAndBootDrive
},
46 {"Partition" , 0 , LoadAndBootPartition
},
48 {"Linux" , 0 , LoadAndBootLinux
},
50 {"Windows" , 0 , LoadAndBootWindows
},
51 {"WindowsNT40" , _WIN32_WINNT_NT4
, LoadAndBootWindows
},
53 {"Windows2003" , _WIN32_WINNT_WS03
, LoadAndBootWindows
},
55 // {"Not found" , 0 , NULL }
58 VOID
LoadOperatingSystem(IN OperatingSystemItem
* OperatingSystem
)
61 PCSTR SectionName
= OperatingSystem
->SystemPartition
;
65 // Try to open the operating system section in the .ini file
66 if (IniOpenSection(SectionName
, &SectionId
))
68 // Try to read the boot type
69 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
73 BootType
[0] = ANSI_NULL
;
76 if (BootType
[0] == ANSI_NULL
&& SectionName
[0] != ANSI_NULL
)
78 // Try to infere the boot type value
81 if (ArcOpen((PSTR
)SectionName
, OpenReadOnly
, &FileId
) == ESUCCESS
)
84 strcpy(BootType
, "BootSector");
89 strcpy(BootType
, "Windows");
93 // Install the drive mapper according to this section drive mappings
94 #if defined(_M_IX86) && !defined(_MSC_VER)
95 DriveMapMapDrivesInSection(SectionName
);
98 // Loop through the OS loading method table and find a suitable OS to boot
99 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
101 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
103 OSLoadingMethods
[i
].Load(OperatingSystem
,
104 OSLoadingMethods
[i
].OperatingSystemVersion
);
110 ULONG
GetDefaultOperatingSystem(OperatingSystemItem
* OperatingSystemList
, ULONG OperatingSystemCount
)
112 CHAR DefaultOSText
[80];
118 if (!IniOpenSection("FreeLoader", &SectionId
))
123 DefaultOSName
= CmdLineGetDefaultOS();
124 if (NULL
== DefaultOSName
)
126 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
128 DefaultOSName
= DefaultOSText
;
132 if (NULL
!= DefaultOSName
)
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();
159 if (!IniOpenSection("FreeLoader", &SectionId
))
164 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
166 TimeOut
= atoi(TimeOutText
);
176 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
178 if (KeyPress
== KEY_F8
)
185 // We didn't handle the key
192 ULONG OperatingSystemCount
;
193 OperatingSystemItem
* OperatingSystemList
;
194 PCSTR
* OperatingSystemDisplayNames
;
195 ULONG DefaultOperatingSystem
;
197 ULONG SelectedOperatingSystem
;
200 // FIXME: if possible, only detect and register ARC devices...
203 UiMessageBoxCritical("Error when detecting hardware");
208 // Load additional SCSI driver (if any)
209 if (LoadBootDeviceDriver() != ESUCCESS
)
211 UiMessageBoxCritical("Unable to load additional boot device driver");
215 if (!IniFileInitialize())
217 UiMessageBoxCritical("Error initializing .ini file");
221 if (!IniOpenSection("FreeLoader", &SectionId
))
223 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
226 TimeOut
= GetTimeOut();
228 if (!UiInitialize(TRUE
))
230 UiMessageBoxCritical("Unable to initialize UI.");
234 OperatingSystemList
= InitOperatingSystemList(&OperatingSystemCount
);
235 if (!OperatingSystemList
)
237 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
241 if (OperatingSystemCount
== 0)
243 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
247 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemList
, OperatingSystemCount
);
250 // Create list of display names
252 OperatingSystemDisplayNames
= MmHeapAlloc(sizeof(PCSTR
) * OperatingSystemCount
);
253 if (!OperatingSystemDisplayNames
)
257 for (i
= 0; i
< OperatingSystemCount
; i
++)
259 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
263 // Find all the message box settings and run them
265 UiShowMessageBoxesInSection("FreeLoader");
270 // Redraw the backdrop
273 // Show the operating system list menu
274 if (!UiDisplayMenu("Please select the operating system to start:",
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...");