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 DBG_DEFAULT_CHANNEL(WARNING
);
27 /* GLOBALS ********************************************************************/
31 (*EDIT_OS_ENTRY_PROC
)(
32 IN OUT OperatingSystemItem
* OperatingSystem
);
35 EditCustomBootReactOSSetup(
36 IN OUT OperatingSystemItem
* OperatingSystem
)
38 EditCustomBootReactOS(OperatingSystem
, TRUE
);
43 IN OUT OperatingSystemItem
* OperatingSystem
)
45 EditCustomBootReactOS(OperatingSystem
, FALSE
);
51 EDIT_OS_ENTRY_PROC EditOsEntry
;
52 ARC_ENTRY_POINT OsLoader
;
53 } OSLoadingMethods
[] =
55 {"ReactOSSetup", EditCustomBootReactOSSetup
, LoadReactOSSetup
},
58 {"Drive" , EditCustomBootDisk
, LoadAndBootDrive
},
59 {"Partition" , EditCustomBootPartition
, LoadAndBootPartition
},
60 {"BootSector" , EditCustomBootSectorFile
, LoadAndBootBootSector
},
62 {"Linux" , EditCustomBootLinux
, LoadAndBootLinux
},
63 {"WindowsNT40" , EditCustomBootNTOS
, LoadAndBootWindows
},
65 {"Windows" , EditCustomBootNTOS
, LoadAndBootWindows
},
66 {"Windows2003" , EditCustomBootNTOS
, LoadAndBootWindows
},
69 /* FUNCTIONS ******************************************************************/
72 * This function converts the list of key=value options in the given operating
73 * system section into an ARC-compatible argument vector, providing in addition
74 * the extra mandatory Software Loading Environment Variables, following the
79 IN PCSTR LoadIdentifier
,
80 IN ULONG_PTR SectionId
,
89 PCHAR SettingName
, SettingValue
;
93 ASSERT(SectionId
!= 0);
95 /* Validate the LoadIdentifier (to make tests simpler later) */
96 if (LoadIdentifier
&& !*LoadIdentifier
)
97 LoadIdentifier
= NULL
;
99 /* Count the number of operating systems in the section */
100 Count
= IniGetNumSectionItems(SectionId
);
103 * The argument vector contains the program name, the SystemPartition,
104 * the LoadIdentifier (optional), and the items in the OS section.
106 Argc
= 2 + (LoadIdentifier
? 1 : 0) + Count
;
108 /* Calculate the total size needed for the string buffer of the argument vector */
110 /* i == 0: Program name */
111 /* i == 1: SystemPartition : from where FreeLdr has been started */
112 Size
+= (strlen("SystemPartition=") + strlen(FrLdrBootPath
) + 1) * sizeof(CHAR
);
113 /* i == 2: LoadIdentifier : ASCII string that may be used to associate an identifier with a set of load parameters */
116 Size
+= (strlen("LoadIdentifier=") + strlen(LoadIdentifier
) + 1) * sizeof(CHAR
);
118 for (i
= 0; i
< Count
; ++i
)
120 Size
+= IniGetSectionSettingNameSize(SectionId
, i
); // Counts also the NULL-terminator, that we transform into the '=' sign separator.
121 Size
+= IniGetSectionSettingValueSize(SectionId
, i
); // Counts also the NULL-terminator.
123 Size
+= sizeof(ANSI_NULL
); // Final NULL-terminator.
125 /* Allocate memory to hold the argument vector: pointers and string buffer */
126 Argv
= FrLdrHeapAlloc(Argc
* sizeof(PCHAR
) + Size
, TAG_STRING
);
130 /* Initialize the argument vector: loop through the section and copy the key=value options */
131 SettingName
= (PCHAR
)((ULONG_PTR
)Argv
+ (Argc
* sizeof(PCHAR
)));
133 /* i == 0: Program name */
135 /* i == 1: SystemPartition */
137 strcpy(SettingName
, "SystemPartition=");
138 strcat(SettingName
, FrLdrBootPath
);
140 *Args
++ = SettingName
;
141 SettingName
+= (strlen(SettingName
) + 1);
143 /* i == 2: LoadIdentifier */
146 strcpy(SettingName
, "LoadIdentifier=");
147 strcat(SettingName
, LoadIdentifier
);
149 *Args
++ = SettingName
;
150 SettingName
+= (strlen(SettingName
) + 1);
152 for (i
= 0; i
< Count
; ++i
)
154 Size
= IniGetSectionSettingNameSize(SectionId
, i
);
155 SettingValue
= SettingName
+ Size
;
156 IniReadSettingByNumber(SectionId
, i
,
158 SettingValue
, IniGetSectionSettingValueSize(SectionId
, i
));
159 SettingName
[Size
- 1] = '=';
161 *Args
++ = SettingName
;
162 SettingName
+= (strlen(SettingName
) + 1);
166 /* Dump the argument vector for debugging */
167 for (i
= 0; i
< Argc
; ++i
)
169 TRACE("Argv[%lu]: '%s'\n", i
, Argv
[i
]);
177 VOID
LoadOperatingSystem(IN OperatingSystemItem
* OperatingSystem
)
179 ULONG_PTR SectionId
= OperatingSystem
->SectionId
;
185 /* The operating system section has been opened by InitOperatingSystemList() */
186 ASSERT(SectionId
!= 0);
188 /* Try to read the boot type */
189 *BootType
= ANSI_NULL
;
190 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
192 /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
196 /* Install the drive mapper according to this section drive mappings */
197 DriveMapMapDrivesInSection(SectionId
);
200 /* Find the suitable OS loader to start */
203 if (i
>= RTL_NUMBER_OF(OSLoadingMethods
))
205 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
209 /* Build the ARC-compatible argument vector */
210 Argv
= BuildArgvForOsLoader(OperatingSystem
->LoadIdentifier
, SectionId
, &Argc
);
212 return; // Unexpected failure.
214 /* Start the OS loader */
215 OSLoadingMethods
[i
].OsLoader(Argc
, Argv
, NULL
);
216 FrLdrHeapFree(Argv
, TAG_STRING
);
219 #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
221 VOID
EditOperatingSystemEntry(IN OperatingSystemItem
* OperatingSystem
)
223 ULONG_PTR SectionId
= OperatingSystem
->SectionId
;
227 /* The operating system section has been opened by InitOperatingSystemList() */
228 ASSERT(SectionId
!= 0);
230 /* Try to read the boot type */
231 *BootType
= ANSI_NULL
;
232 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
234 /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
237 /* Find the suitable OS entry editor */
240 if (i
>= RTL_NUMBER_OF(OSLoadingMethods
))
242 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
247 OSLoadingMethods
[i
].EditOsEntry(OperatingSystem
);
250 #endif // HAS_OPTION_MENU_EDIT_CMDLINE
254 IN ULONG_PTR FrLdrSectionId
)
257 CHAR TimeOutText
[20];
259 TimeOut
= CmdLineGetTimeOut();
265 if ((FrLdrSectionId
!= 0) &&
266 IniReadSettingByName(FrLdrSectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
268 TimeOut
= atoi(TimeOutText
);
275 MainBootMenuKeyPressFilter(
277 IN ULONG SelectedMenuItem
,
278 IN PVOID Context OPTIONAL
)
283 DoOptionsMenu(&((OperatingSystemItem
*)Context
)[SelectedMenuItem
]);
286 #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
288 EditOperatingSystemEntry(&((OperatingSystemItem
*)Context
)[SelectedMenuItem
]);
293 /* We didn't handle the key */
302 ULONG OperatingSystemCount
;
303 OperatingSystemItem
* OperatingSystemList
;
304 PCSTR
* OperatingSystemDisplayNames
;
305 ULONG DefaultOperatingSystem
;
306 ULONG SelectedOperatingSystem
;
309 if (!MachInitializeBootDevices())
311 UiMessageBoxCritical("Error when detecting hardware.");
316 /* Load additional SCSI driver (if any) */
317 if (LoadBootDeviceDriver() != ESUCCESS
)
319 UiMessageBoxCritical("Unable to load additional boot device drivers.");
323 if (!IniFileInitialize())
325 UiMessageBoxCritical("Error initializing .ini file.");
329 /* Open the [FreeLoader] section */
330 if (!IniOpenSection("FreeLoader", &SectionId
))
332 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
336 /* Debugger main initialization */
337 DebugInit(SectionId
);
339 /* Retrieve the default timeout */
340 TimeOut
= GetTimeOut(SectionId
);
342 /* UI main initialization */
343 if (!UiInitialize(TRUE
))
345 UiMessageBoxCritical("Unable to initialize UI.");
349 OperatingSystemList
= InitOperatingSystemList(SectionId
,
350 &OperatingSystemCount
,
351 &DefaultOperatingSystem
);
352 if (!OperatingSystemList
)
354 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
357 if (OperatingSystemCount
== 0)
359 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
363 /* Create list of display names */
364 OperatingSystemDisplayNames
= FrLdrTempAlloc(sizeof(PCSTR
) * OperatingSystemCount
, 'mNSO');
365 if (!OperatingSystemDisplayNames
)
368 for (i
= 0; i
< OperatingSystemCount
; i
++)
370 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
373 /* Find all the message box settings and run them */
374 UiShowMessageBoxesInSection(SectionId
);
378 /* Redraw the backdrop */
381 /* Show the operating system list menu */
382 if (!UiDisplayMenu("Please select the operating system to start:",
383 "For troubleshooting and advanced startup options for "
384 "ReactOS, press F8.",
386 OperatingSystemDisplayNames
,
387 OperatingSystemCount
,
388 DefaultOperatingSystem
,
390 &SelectedOperatingSystem
,
392 MainBootMenuKeyPressFilter
,
393 OperatingSystemList
))
395 UiMessageBox("Press ENTER to reboot.");
401 /* Load the chosen operating system */
402 LoadOperatingSystem(&OperatingSystemList
[SelectedOperatingSystem
]);
406 UiUnInitialize("Rebooting...");