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 /* Loop through the OS loading method table and find a suitable OS to boot */
201 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
203 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
205 Argv
= BuildArgvForOsLoader(OperatingSystem
->LoadIdentifier
, SectionId
, &Argc
);
208 OSLoadingMethods
[i
].OsLoader(Argc
, Argv
, NULL
);
209 FrLdrHeapFree(Argv
, TAG_STRING
);
216 #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
218 VOID
EditOperatingSystemEntry(IN OperatingSystemItem
* OperatingSystem
)
220 ULONG_PTR SectionId
= OperatingSystem
->SectionId
;
224 /* The operating system section has been opened by InitOperatingSystemList() */
225 ASSERT(SectionId
!= 0);
227 /* Try to read the boot type */
228 *BootType
= ANSI_NULL
;
229 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
231 /* We must have the "BootType" value (it has been possibly added by InitOperatingSystemList()) */
234 /* Loop through the OS loading method table and find a suitable OS entry editor */
235 for (i
= 0; i
< sizeof(OSLoadingMethods
) / sizeof(OSLoadingMethods
[0]); ++i
)
237 if (_stricmp(BootType
, OSLoadingMethods
[i
].BootType
) == 0)
239 OSLoadingMethods
[i
].EditOsEntry(OperatingSystem
);
245 #endif // HAS_OPTION_MENU_EDIT_CMDLINE
249 IN ULONG_PTR FrLdrSectionId
)
252 CHAR TimeOutText
[20];
254 TimeOut
= CmdLineGetTimeOut();
260 if ((FrLdrSectionId
!= 0) &&
261 IniReadSettingByName(FrLdrSectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
263 TimeOut
= atoi(TimeOutText
);
270 MainBootMenuKeyPressFilter(
272 IN ULONG SelectedMenuItem
,
273 IN PVOID Context OPTIONAL
)
278 DoOptionsMenu(&((OperatingSystemItem
*)Context
)[SelectedMenuItem
]);
281 #ifdef HAS_OPTION_MENU_EDIT_CMDLINE
283 EditOperatingSystemEntry(&((OperatingSystemItem
*)Context
)[SelectedMenuItem
]);
288 /* We didn't handle the key */
297 ULONG OperatingSystemCount
;
298 OperatingSystemItem
* OperatingSystemList
;
299 PCSTR
* OperatingSystemDisplayNames
;
300 ULONG DefaultOperatingSystem
;
301 ULONG SelectedOperatingSystem
;
304 if (!MachInitializeBootDevices())
306 UiMessageBoxCritical("Error when detecting hardware.");
311 /* Load additional SCSI driver (if any) */
312 if (LoadBootDeviceDriver() != ESUCCESS
)
314 UiMessageBoxCritical("Unable to load additional boot device drivers.");
318 if (!IniFileInitialize())
320 UiMessageBoxCritical("Error initializing .ini file.");
324 /* Open the [FreeLoader] section */
325 if (!IniOpenSection("FreeLoader", &SectionId
))
327 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
331 /* Debugger main initialization */
332 DebugInit(SectionId
);
334 /* Retrieve the default timeout */
335 TimeOut
= GetTimeOut(SectionId
);
337 /* UI main initialization */
338 if (!UiInitialize(TRUE
))
340 UiMessageBoxCritical("Unable to initialize UI.");
344 OperatingSystemList
= InitOperatingSystemList(SectionId
,
345 &OperatingSystemCount
,
346 &DefaultOperatingSystem
);
347 if (!OperatingSystemList
)
349 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
352 if (OperatingSystemCount
== 0)
354 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
358 /* Create list of display names */
359 OperatingSystemDisplayNames
= FrLdrTempAlloc(sizeof(PCSTR
) * OperatingSystemCount
, 'mNSO');
360 if (!OperatingSystemDisplayNames
)
363 for (i
= 0; i
< OperatingSystemCount
; i
++)
365 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
368 /* Find all the message box settings and run them */
369 UiShowMessageBoxesInSection(SectionId
);
373 /* Redraw the backdrop */
376 /* Show the operating system list menu */
377 if (!UiDisplayMenu("Please select the operating system to start:",
378 "For troubleshooting and advanced startup options for "
379 "ReactOS, press F8.",
381 OperatingSystemDisplayNames
,
382 OperatingSystemCount
,
383 DefaultOperatingSystem
,
385 &SelectedOperatingSystem
,
387 MainBootMenuKeyPressFilter
,
388 OperatingSystemList
))
390 UiMessageBox("Press ENTER to reboot.");
396 /* Load the chosen operating system */
397 LoadOperatingSystem(&OperatingSystemList
[SelectedOperatingSystem
]);
401 UiUnInitialize("Rebooting...");